[MOAB-dev] r3604 - in MOAB/trunk: . itaps/igeom itaps/imesh src src/io src/io/mhdf/include src/io/moab src/moab src/oldinc src/parallel src/parallel/moab test test/dual test/h5file test/io test/obb test/oldinc test/parallel test/perf tools tools/dagmc tools/mbchaco tools/mbcoupler tools/mbperf tools/mbzoltan tools/mcnpmit tools/qvdual tools/refiner

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Mar 12 15:30:44 CST 2010


Author: kraftche
Date: 2010-03-12 15:30:42 -0600 (Fri, 12 Mar 2010)
New Revision: 3604

Added:
   MOAB/trunk/src/AdaptiveKDTree.cpp
   MOAB/trunk/src/AffineXform.cpp
   MOAB/trunk/src/AffineXform.hpp
   MOAB/trunk/src/AxisBox.cpp
   MOAB/trunk/src/AxisBox.hpp
   MOAB/trunk/src/BSPTree.cpp
   MOAB/trunk/src/CartVect.cpp
   MOAB/trunk/src/Core.cpp
   MOAB/trunk/src/Error.hpp
   MOAB/trunk/src/Factory.cpp
   MOAB/trunk/src/GeomUtil.cpp
   MOAB/trunk/src/Internals.hpp
   MOAB/trunk/src/MBEntityType.h
   MOAB/trunk/src/Matrix3.cpp
   MOAB/trunk/src/Matrix3.hpp
   MOAB/trunk/src/MeshSet.cpp
   MOAB/trunk/src/MeshSet.hpp
   MOAB/trunk/src/OrientedBox.cpp
   MOAB/trunk/src/OrientedBox.hpp
   MOAB/trunk/src/OrientedBoxTreeTool.cpp
   MOAB/trunk/src/Range.cpp
   MOAB/trunk/src/RangeSeqIntersectIter.cpp
   MOAB/trunk/src/RangeSeqIntersectIter.hpp
   MOAB/trunk/src/ReadUtil.cpp
   MOAB/trunk/src/ReadUtil.hpp
   MOAB/trunk/src/ReaderWriterSet.cpp
   MOAB/trunk/src/Skinner.cpp
   MOAB/trunk/src/SysUtil.cpp
   MOAB/trunk/src/SysUtil.hpp
   MOAB/trunk/src/Util.cpp
   MOAB/trunk/src/WriteUtil.cpp
   MOAB/trunk/src/WriteUtil.hpp
   MOAB/trunk/src/moab/AdaptiveKDTree.hpp
   MOAB/trunk/src/moab/BSPTree.hpp
   MOAB/trunk/src/moab/CartVect.hpp
   MOAB/trunk/src/moab/Core.hpp
   MOAB/trunk/src/moab/EntityHandle.hpp.in
   MOAB/trunk/src/moab/EntityType.hpp
   MOAB/trunk/src/moab/Forward.hpp
   MOAB/trunk/src/moab/GeomUtil.hpp
   MOAB/trunk/src/moab/Interface.hpp
   MOAB/trunk/src/moab/OrientedBoxTreeTool.hpp
   MOAB/trunk/src/moab/Range.hpp
   MOAB/trunk/src/moab/ReadUtilIface.hpp
   MOAB/trunk/src/moab/ReaderIface.hpp
   MOAB/trunk/src/moab/ReaderWriterSet.hpp
   MOAB/trunk/src/moab/Skinner.hpp
   MOAB/trunk/src/moab/Types.hpp
   MOAB/trunk/src/moab/UnknownInterface.hpp
   MOAB/trunk/src/moab/Util.hpp
   MOAB/trunk/src/moab/Version.h.in
   MOAB/trunk/src/moab/WriteUtilIface.hpp
   MOAB/trunk/src/moab/WriterIface.hpp
   MOAB/trunk/src/oldinc/
   MOAB/trunk/src/oldinc/MBAdaptiveKDTree.hpp
   MOAB/trunk/src/oldinc/MBBSPTree.hpp
   MOAB/trunk/src/oldinc/MBCore.hpp
   MOAB/trunk/src/oldinc/MBEntityHandle.h
   MOAB/trunk/src/oldinc/MBForward.hpp
   MOAB/trunk/src/oldinc/MBGeomUtil.hpp
   MOAB/trunk/src/oldinc/MBInterface.hpp
   MOAB/trunk/src/oldinc/MBOrientedBoxTreeTool.hpp
   MOAB/trunk/src/oldinc/MBParallelComm.hpp
   MOAB/trunk/src/oldinc/MBParallelData.hpp
   MOAB/trunk/src/oldinc/MBProcConfig.hpp
   MOAB/trunk/src/oldinc/MBRange.hpp
   MOAB/trunk/src/oldinc/MBReadUtilIface.hpp
   MOAB/trunk/src/oldinc/MBReaderIface.hpp
   MOAB/trunk/src/oldinc/MBReaderWriterSet.hpp
   MOAB/trunk/src/oldinc/MBSkinner.hpp
   MOAB/trunk/src/oldinc/MBTypes.h
   MOAB/trunk/src/oldinc/MBUnknownInterface.hpp
   MOAB/trunk/src/oldinc/MBUtil.hpp
   MOAB/trunk/src/oldinc/MBVersion.h
   MOAB/trunk/src/oldinc/MBWriteUtilIface.hpp
   MOAB/trunk/src/oldinc/MBWriterIface.hpp
   MOAB/trunk/src/oldinc/MBmpi.h
   MOAB/trunk/src/oldinc/Makefile.am
   MOAB/trunk/src/parallel/ParallelComm.cpp
   MOAB/trunk/src/parallel/ParallelData.cpp
   MOAB/trunk/src/parallel/ProcConfig.cpp
   MOAB/trunk/src/parallel/moab/ParallelComm.hpp
   MOAB/trunk/src/parallel/moab/ParallelData.hpp
   MOAB/trunk/src/parallel/moab/ProcConfig.hpp
   MOAB/trunk/src/parallel/moab_mpi.h
   MOAB/trunk/src/parallel/moab_mpi_config.h.in
   MOAB/trunk/test/oldinc/
   MOAB/trunk/test/oldinc/Makefile.am
   MOAB/trunk/test/oldinc/test_oldinc.cpp
   MOAB/trunk/tools/mbcoupler/Coupler.cpp
   MOAB/trunk/tools/mbcoupler/Coupler.hpp
   MOAB/trunk/tools/mbcoupler/ElemUtil.cpp
   MOAB/trunk/tools/mbcoupler/ElemUtil.hpp
   MOAB/trunk/tools/refiner/EdgeSizeEvaluator.cpp
   MOAB/trunk/tools/refiner/EdgeSizeEvaluator.hpp
   MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.cpp
   MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.hpp
   MOAB/trunk/tools/refiner/EntityRefiner.cpp
   MOAB/trunk/tools/refiner/EntityRefiner.hpp
   MOAB/trunk/tools/refiner/MeshOutputFunctor.cpp
   MOAB/trunk/tools/refiner/MeshOutputFunctor.hpp
   MOAB/trunk/tools/refiner/MeshRefiner.cpp
   MOAB/trunk/tools/refiner/MeshRefiner.hpp
   MOAB/trunk/tools/refiner/ProcessSet.cpp
   MOAB/trunk/tools/refiner/ProcessSet.hpp
   MOAB/trunk/tools/refiner/Refiner.cpp
   MOAB/trunk/tools/refiner/RefinerTagManager.cpp
   MOAB/trunk/tools/refiner/RefinerTagManager.hpp
   MOAB/trunk/tools/refiner/SimplexTemplateRefiner.cpp
   MOAB/trunk/tools/refiner/SimplexTemplateRefiner.hpp
   MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.cpp
   MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.hpp
   MOAB/trunk/tools/refiner/SplitVertices.cpp
   MOAB/trunk/tools/refiner/SplitVertices.hpp
   MOAB/trunk/tools/sphere_decomp.cpp
Removed:
   MOAB/trunk/src/MBAdaptiveKDTree.cpp
   MOAB/trunk/src/MBAffineXform.cpp
   MOAB/trunk/src/MBAffineXform.hpp
   MOAB/trunk/src/MBAxisBox.cpp
   MOAB/trunk/src/MBAxisBox.hpp
   MOAB/trunk/src/MBBSPTree.cpp
   MOAB/trunk/src/MBCartVect.cpp
   MOAB/trunk/src/MBCartVect.hpp
   MOAB/trunk/src/MBCore.cpp
   MOAB/trunk/src/MBFactory.cpp
   MOAB/trunk/src/MBGeomUtil.cpp
   MOAB/trunk/src/MBInternals.hpp
   MOAB/trunk/src/MBMatrix3.cpp
   MOAB/trunk/src/MBMatrix3.hpp
   MOAB/trunk/src/MBMeshSet.cpp
   MOAB/trunk/src/MBMeshSet.hpp
   MOAB/trunk/src/MBOrientedBox.cpp
   MOAB/trunk/src/MBOrientedBox.hpp
   MOAB/trunk/src/MBOrientedBoxTreeTool.cpp
   MOAB/trunk/src/MBRange.cpp
   MOAB/trunk/src/MBRangeSeqIntersectIter.cpp
   MOAB/trunk/src/MBRangeSeqIntersectIter.hpp
   MOAB/trunk/src/MBReadUtil.cpp
   MOAB/trunk/src/MBReadUtil.hpp
   MOAB/trunk/src/MBReaderWriterSet.cpp
   MOAB/trunk/src/MBSkinner.cpp
   MOAB/trunk/src/MBSysUtil.cpp
   MOAB/trunk/src/MBSysUtil.hpp
   MOAB/trunk/src/MBUtil.cpp
   MOAB/trunk/src/MBWriteUtil.cpp
   MOAB/trunk/src/MBWriteUtil.hpp
   MOAB/trunk/src/moab/MBAdaptiveKDTree.hpp
   MOAB/trunk/src/moab/MBBSPTree.hpp
   MOAB/trunk/src/moab/MBCore.hpp
   MOAB/trunk/src/moab/MBEntityHandle.h.in
   MOAB/trunk/src/moab/MBEntityType.h
   MOAB/trunk/src/moab/MBError.hpp
   MOAB/trunk/src/moab/MBForward.hpp
   MOAB/trunk/src/moab/MBGeomUtil.hpp
   MOAB/trunk/src/moab/MBInterface.hpp
   MOAB/trunk/src/moab/MBOrientedBoxTreeTool.hpp
   MOAB/trunk/src/moab/MBRange.hpp
   MOAB/trunk/src/moab/MBReadUtilIface.hpp
   MOAB/trunk/src/moab/MBReaderIface.hpp
   MOAB/trunk/src/moab/MBReaderWriterSet.hpp
   MOAB/trunk/src/moab/MBSkinner.hpp
   MOAB/trunk/src/moab/MBTypes.h
   MOAB/trunk/src/moab/MBUnknownInterface.hpp
   MOAB/trunk/src/moab/MBUtil.hpp
   MOAB/trunk/src/moab/MBVersion.h.in
   MOAB/trunk/src/moab/MBWriteUtilIface.hpp
   MOAB/trunk/src/moab/MBWriterIface.hpp
   MOAB/trunk/src/parallel/MBParallelComm.cpp
   MOAB/trunk/src/parallel/MBParallelData.cpp
   MOAB/trunk/src/parallel/MBProcConfig.cpp
   MOAB/trunk/src/parallel/moab/MBParallelComm.hpp
   MOAB/trunk/src/parallel/moab/MBParallelData.hpp
   MOAB/trunk/src/parallel/moab/MBProcConfig.hpp
   MOAB/trunk/src/parallel/moab/MBmpi.h
   MOAB/trunk/src/parallel/moab/MBmpi_config.h.in
   MOAB/trunk/tools/iGeom/
   MOAB/trunk/tools/iMesh/
   MOAB/trunk/tools/main.cpp
   MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
   MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
   MOAB/trunk/tools/mbcoupler/MBElemUtil.cpp
   MOAB/trunk/tools/mbcoupler/MBElemUtil.hpp
   MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.cpp
   MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.hpp
   MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.cpp
   MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.hpp
   MOAB/trunk/tools/refiner/MBEntityRefiner.cpp
   MOAB/trunk/tools/refiner/MBEntityRefiner.hpp
   MOAB/trunk/tools/refiner/MBMeshOutputFunctor.cpp
   MOAB/trunk/tools/refiner/MBMeshOutputFunctor.hpp
   MOAB/trunk/tools/refiner/MBMeshRefiner.cpp
   MOAB/trunk/tools/refiner/MBMeshRefiner.hpp
   MOAB/trunk/tools/refiner/MBProcessSet.cpp
   MOAB/trunk/tools/refiner/MBProcessSet.hpp
   MOAB/trunk/tools/refiner/MBRefiner.cpp
   MOAB/trunk/tools/refiner/MBRefinerTagManager.cpp
   MOAB/trunk/tools/refiner/MBRefinerTagManager.hpp
   MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.cpp
   MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.hpp
   MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.cpp
   MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.hpp
   MOAB/trunk/tools/refiner/MBSplitVertices.cpp
   MOAB/trunk/tools/refiner/MBSplitVertices.hpp
Modified:
   MOAB/trunk/configure.ac
   MOAB/trunk/itaps/igeom/GeomTopoUtil.cpp
   MOAB/trunk/itaps/igeom/GeomTopoUtil.hpp
   MOAB/trunk/itaps/igeom/Makefile.am
   MOAB/trunk/itaps/igeom/iGeom_MOAB.cpp
   MOAB/trunk/itaps/igeom/iGeom_MOAB.hpp
   MOAB/trunk/itaps/imesh/Makefile.am
   MOAB/trunk/itaps/imesh/iMeshP.h
   MOAB/trunk/itaps/imesh/iMeshP_MOAB.cpp
   MOAB/trunk/itaps/imesh/iMeshP_unit_tests.cpp
   MOAB/trunk/itaps/imesh/iMesh_MOAB.cpp
   MOAB/trunk/itaps/imesh/iMesh_MOAB.hpp
   MOAB/trunk/itaps/imesh/partest.cpp
   MOAB/trunk/itaps/imesh/testc_cbind.c
   MOAB/trunk/src/AEntityFactory.cpp
   MOAB/trunk/src/AEntityFactory.hpp
   MOAB/trunk/src/BSPTreePoly.cpp
   MOAB/trunk/src/BitTagServer.cpp
   MOAB/trunk/src/BitTagServer.hpp
   MOAB/trunk/src/CMakeLists.txt
   MOAB/trunk/src/DualTool.cpp
   MOAB/trunk/src/ElementSequence.hpp
   MOAB/trunk/src/EntitySequence.cpp
   MOAB/trunk/src/EntitySequence.hpp
   MOAB/trunk/src/FileOptions.cpp
   MOAB/trunk/src/FileOptions.hpp
   MOAB/trunk/src/GeomTopoTool.cpp
   MOAB/trunk/src/HigherOrderFactory.cpp
   MOAB/trunk/src/HomXform.cpp
   MOAB/trunk/src/MBCN.cpp
   MOAB/trunk/src/MBCNArrays.hpp
   MOAB/trunk/src/Makefile.am
   MOAB/trunk/src/MeshSetSequence.cpp
   MOAB/trunk/src/MeshSetSequence.hpp
   MOAB/trunk/src/MeshTopoUtil.cpp
   MOAB/trunk/src/PolyElementSeq.cpp
   MOAB/trunk/src/PolyElementSeq.hpp
   MOAB/trunk/src/ScdElementData.cpp
   MOAB/trunk/src/ScdElementData.hpp
   MOAB/trunk/src/ScdVertexData.cpp
   MOAB/trunk/src/ScdVertexData.hpp
   MOAB/trunk/src/SequenceData.cpp
   MOAB/trunk/src/SequenceData.hpp
   MOAB/trunk/src/SequenceManager.cpp
   MOAB/trunk/src/SequenceManager.hpp
   MOAB/trunk/src/SparseTagCollection.cpp
   MOAB/trunk/src/SparseTagCollection.hpp
   MOAB/trunk/src/SparseTagSuperCollection.cpp
   MOAB/trunk/src/SparseTagSuperCollection.hpp
   MOAB/trunk/src/StructuredElementSeq.cpp
   MOAB/trunk/src/StructuredElementSeq.hpp
   MOAB/trunk/src/SweptElementData.cpp
   MOAB/trunk/src/SweptElementData.hpp
   MOAB/trunk/src/SweptElementSeq.cpp
   MOAB/trunk/src/SweptElementSeq.hpp
   MOAB/trunk/src/SweptVertexData.cpp
   MOAB/trunk/src/SweptVertexData.hpp
   MOAB/trunk/src/TagCompare.hpp
   MOAB/trunk/src/TagInfo.cpp
   MOAB/trunk/src/TagInfo.hpp
   MOAB/trunk/src/TagServer.cpp
   MOAB/trunk/src/TagServer.hpp
   MOAB/trunk/src/TypeSequenceManager.cpp
   MOAB/trunk/src/TypeSequenceManager.hpp
   MOAB/trunk/src/UnstructuredElemSeq.cpp
   MOAB/trunk/src/UnstructuredElemSeq.hpp
   MOAB/trunk/src/VarLenTag.hpp
   MOAB/trunk/src/VertexSequence.cpp
   MOAB/trunk/src/VertexSequence.hpp
   MOAB/trunk/src/io/CMakeLists.txt
   MOAB/trunk/src/io/ExoIIUtil.cpp
   MOAB/trunk/src/io/ExoIIUtil.hpp
   MOAB/trunk/src/io/FileTokenizer.cpp
   MOAB/trunk/src/io/FileTokenizer.hpp
   MOAB/trunk/src/io/GmshUtil.cpp
   MOAB/trunk/src/io/GmshUtil.hpp
   MOAB/trunk/src/io/Makefile.am
   MOAB/trunk/src/io/ReadABAQUS.cpp
   MOAB/trunk/src/io/ReadABAQUS.hpp
   MOAB/trunk/src/io/ReadCCMIO.cpp
   MOAB/trunk/src/io/ReadCCMIO.hpp
   MOAB/trunk/src/io/ReadCGM.cpp
   MOAB/trunk/src/io/ReadCGM.hpp
   MOAB/trunk/src/io/ReadGmsh.cpp
   MOAB/trunk/src/io/ReadGmsh.hpp
   MOAB/trunk/src/io/ReadHDF5.cpp
   MOAB/trunk/src/io/ReadHDF5.hpp
   MOAB/trunk/src/io/ReadIDEAS.cpp
   MOAB/trunk/src/io/ReadIDEAS.hpp
   MOAB/trunk/src/io/ReadMCNP5.cpp
   MOAB/trunk/src/io/ReadMCNP5.hpp
   MOAB/trunk/src/io/ReadNASTRAN.cpp
   MOAB/trunk/src/io/ReadNASTRAN.hpp
   MOAB/trunk/src/io/ReadNCDF.cpp
   MOAB/trunk/src/io/ReadNCDF.hpp
   MOAB/trunk/src/io/ReadSTL.cpp
   MOAB/trunk/src/io/ReadSTL.hpp
   MOAB/trunk/src/io/ReadSmf.cpp
   MOAB/trunk/src/io/ReadSmf.hpp
   MOAB/trunk/src/io/ReadSms.cpp
   MOAB/trunk/src/io/ReadSms.hpp
   MOAB/trunk/src/io/ReadTetGen.cpp
   MOAB/trunk/src/io/ReadTetGen.hpp
   MOAB/trunk/src/io/ReadVtk.cpp
   MOAB/trunk/src/io/ReadVtk.hpp
   MOAB/trunk/src/io/SMF_State.cpp
   MOAB/trunk/src/io/SMF_State.hpp
   MOAB/trunk/src/io/Tqdcfr.cpp
   MOAB/trunk/src/io/Tqdcfr.hpp
   MOAB/trunk/src/io/VtkUtil.cpp
   MOAB/trunk/src/io/VtkUtil.hpp
   MOAB/trunk/src/io/WriteAns.cpp
   MOAB/trunk/src/io/WriteAns.hpp
   MOAB/trunk/src/io/WriteCCMIO.cpp
   MOAB/trunk/src/io/WriteCCMIO.hpp
   MOAB/trunk/src/io/WriteGMV.cpp
   MOAB/trunk/src/io/WriteGMV.hpp
   MOAB/trunk/src/io/WriteGmsh.cpp
   MOAB/trunk/src/io/WriteGmsh.hpp
   MOAB/trunk/src/io/WriteHDF5.cpp
   MOAB/trunk/src/io/WriteHDF5.hpp
   MOAB/trunk/src/io/WriteNCDF.cpp
   MOAB/trunk/src/io/WriteNCDF.hpp
   MOAB/trunk/src/io/WriteSLAC.cpp
   MOAB/trunk/src/io/WriteSLAC.hpp
   MOAB/trunk/src/io/WriteSTL.cpp
   MOAB/trunk/src/io/WriteSTL.hpp
   MOAB/trunk/src/io/WriteSmf.cpp
   MOAB/trunk/src/io/WriteSmf.hpp
   MOAB/trunk/src/io/WriteTemplate.cpp
   MOAB/trunk/src/io/WriteTemplate.hpp
   MOAB/trunk/src/io/WriteVtk.cpp
   MOAB/trunk/src/io/WriteVtk.hpp
   MOAB/trunk/src/io/exodus_order.h
   MOAB/trunk/src/io/mhdf/include/mhdf.h
   MOAB/trunk/src/io/moab/ExoIIInterface.hpp
   MOAB/trunk/src/io/patran_order.h
   MOAB/trunk/src/moab/BSPTreePoly.hpp
   MOAB/trunk/src/moab/DualTool.hpp
   MOAB/trunk/src/moab/GeomTopoTool.hpp
   MOAB/trunk/src/moab/HigherOrderFactory.hpp
   MOAB/trunk/src/moab/HomXform.hpp
   MOAB/trunk/src/moab/MBCN.hpp
   MOAB/trunk/src/moab/MeshTopoUtil.hpp
   MOAB/trunk/src/moab/RangeMap.hpp
   MOAB/trunk/src/parallel/CMakeLists.txt
   MOAB/trunk/src/parallel/Makefile.am
   MOAB/trunk/src/parallel/ReadParallel.cpp
   MOAB/trunk/src/parallel/ReadParallel.hpp
   MOAB/trunk/src/parallel/WriteHDF5Parallel.cpp
   MOAB/trunk/src/parallel/WriteHDF5Parallel.hpp
   MOAB/trunk/src/parallel/crystal.c
   MOAB/trunk/src/parallel/fcrystal.c
   MOAB/trunk/src/parallel/gs.c
   MOAB/trunk/src/parallel/transfer.c
   MOAB/trunk/test/CMakeLists.txt
   MOAB/trunk/test/GeomUtilTests.cpp
   MOAB/trunk/test/MBTest.cpp
   MOAB/trunk/test/Makefile.am
   MOAB/trunk/test/OBBTest.cpp
   MOAB/trunk/test/TagTest.cpp
   MOAB/trunk/test/TestTypeSequenceManager.cpp
   MOAB/trunk/test/TestUtil.hpp
   MOAB/trunk/test/Test_MBMeshSet.cpp
   MOAB/trunk/test/VarLenTagTest.cpp
   MOAB/trunk/test/adaptive_kd_tree_tests.cpp
   MOAB/trunk/test/bsp_tree_poly_test.cpp
   MOAB/trunk/test/bsp_tree_test.cpp
   MOAB/trunk/test/dual/Makefile.am
   MOAB/trunk/test/dual/dual_test.cpp
   MOAB/trunk/test/h5file/Makefile.am
   MOAB/trunk/test/h5file/h5file_test.cpp
   MOAB/trunk/test/h5file/h5legacy.cpp
   MOAB/trunk/test/h5file/h5partial.cpp
   MOAB/trunk/test/h5file/h5regression.cpp
   MOAB/trunk/test/h5file/h5sets_test.cpp
   MOAB/trunk/test/h5file/h5varlen.cpp
   MOAB/trunk/test/internals_test.cpp
   MOAB/trunk/test/io/CMakeLists.txt
   MOAB/trunk/test/io/Makefile.am
   MOAB/trunk/test/io/VtkTest.cpp
   MOAB/trunk/test/io/cub_file_test.cc
   MOAB/trunk/test/io/exodus_test.cc
   MOAB/trunk/test/io/gmsh_test.cc
   MOAB/trunk/test/io/nastran_test.cc
   MOAB/trunk/test/io/stl_test.cc
   MOAB/trunk/test/io/test_exo.cpp
   MOAB/trunk/test/io/test_rms.cpp
   MOAB/trunk/test/kd_tree_test.cpp
   MOAB/trunk/test/kd_tree_time.cpp
   MOAB/trunk/test/kd_tree_tool.cpp
   MOAB/trunk/test/mbcn_test.cc
   MOAB/trunk/test/merge_test.cpp
   MOAB/trunk/test/obb/Makefile.am
   MOAB/trunk/test/obb/obb_test.cpp
   MOAB/trunk/test/obb/obb_time.cpp
   MOAB/trunk/test/obb/obb_tree_tool.cpp
   MOAB/trunk/test/parallel/Makefile.am
   MOAB/trunk/test/parallel/mbparallelcomm_test.cpp
   MOAB/trunk/test/parallel/mhdf_parallel.c
   MOAB/trunk/test/parallel/parallel_hdf5_test.cc
   MOAB/trunk/test/parallel/parallel_unit_tests.cpp
   MOAB/trunk/test/parallel/parallel_write_test.cc
   MOAB/trunk/test/parallel/pcomm_serial.cpp
   MOAB/trunk/test/parallel/pcomm_unit.cpp
   MOAB/trunk/test/parallel/scdtest.cpp
   MOAB/trunk/test/parallel/uber_parallel_test.cpp
   MOAB/trunk/test/perf/Makefile.am
   MOAB/trunk/test/perf/adj_time.cpp
   MOAB/trunk/test/perf/cubit_perf.cpp
   MOAB/trunk/test/perf/perf.cpp
   MOAB/trunk/test/perf/point_in_elem.cpp
   MOAB/trunk/test/perf/seqperf.cpp
   MOAB/trunk/test/scdseq_test.cpp
   MOAB/trunk/test/scdseq_timing.cpp
   MOAB/trunk/test/test_adj.cpp
   MOAB/trunk/tools/Makefile.am
   MOAB/trunk/tools/SphereDecomp.cpp
   MOAB/trunk/tools/SphereDecomp.hpp
   MOAB/trunk/tools/convert.cpp
   MOAB/trunk/tools/dagmc/CMakeLists.txt
   MOAB/trunk/tools/dagmc/DagMC.cpp
   MOAB/trunk/tools/dagmc/DagMC.hpp
   MOAB/trunk/tools/dagmc/Makefile.am
   MOAB/trunk/tools/dagmc/cub2h5m.cc
   MOAB/trunk/tools/dagmc/cubfile.c
   MOAB/trunk/tools/dagmc/main.cc
   MOAB/trunk/tools/dagmc/pt_vol_test.cc
   MOAB/trunk/tools/dagmc/quads_to_tris.cpp
   MOAB/trunk/tools/dagmc/quads_to_tris.hpp
   MOAB/trunk/tools/dagmc/quads_to_tris_driver.cpp
   MOAB/trunk/tools/dagmc/ray_fire_test.cc
   MOAB/trunk/tools/dagmc/test_geom.cc
   MOAB/trunk/tools/depth.cpp
   MOAB/trunk/tools/gsets.cc
   MOAB/trunk/tools/makeops.cpp
   MOAB/trunk/tools/mbchaco/ComputePartition.cpp
   MOAB/trunk/tools/mbchaco/ComputePartition.hpp
   MOAB/trunk/tools/mbchaco/Makefile.am
   MOAB/trunk/tools/mbcoupler/CMakeLists.txt
   MOAB/trunk/tools/mbcoupler/ElemUtilTest.cpp
   MOAB/trunk/tools/mbcoupler/Makefile.am
   MOAB/trunk/tools/mbcoupler/addfield.cpp
   MOAB/trunk/tools/mbcoupler/findpt_test.cpp
   MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp
   MOAB/trunk/tools/mbperf/Makefile.am
   MOAB/trunk/tools/mbperf/cubit_perf.cpp
   MOAB/trunk/tools/mbperf/mbperf.cpp
   MOAB/trunk/tools/mbzoltan/MBZoltan.cpp
   MOAB/trunk/tools/mbzoltan/MBZoltan.hpp
   MOAB/trunk/tools/mbzoltan/Makefile.am
   MOAB/trunk/tools/mbzoltan/main.cpp
   MOAB/trunk/tools/mcnpmit/Makefile.am
   MOAB/trunk/tools/mcnpmit/main.cpp
   MOAB/trunk/tools/mcnpmit/mcnpmit.cpp
   MOAB/trunk/tools/mcnpmit/mcnpmit.hpp
   MOAB/trunk/tools/measure.cpp
   MOAB/trunk/tools/measure.hpp
   MOAB/trunk/tools/parse.cpp
   MOAB/trunk/tools/parse.hpp
   MOAB/trunk/tools/propagate_tags.cpp
   MOAB/trunk/tools/qvdual/CropTool.cpp
   MOAB/trunk/tools/qvdual/DrawDual.cpp
   MOAB/trunk/tools/qvdual/DrawDual.hpp
   MOAB/trunk/tools/qvdual/Makefile.am
   MOAB/trunk/tools/qvdual/uiQVDual.ui.h
   MOAB/trunk/tools/refiner/CMakeLists.txt
   MOAB/trunk/tools/refiner/test_mesh_refiner.cpp
   MOAB/trunk/tools/size.cpp
   MOAB/trunk/tools/skin.cpp
   MOAB/trunk/tools/surfplot.cpp
Log:
big namespace change

Modified: MOAB/trunk/configure.ac
===================================================================
--- MOAB/trunk/configure.ac	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/configure.ac	2010-03-12 21:30:42 UTC (rev 3604)
@@ -45,6 +45,16 @@
 
 
 ################################################################################
+#                           No-Namepsace (3.0) Headers
+################################################################################
+AC_ARG_ENABLE([old-headers],
+ [AC_HELP_STRING([--disable-old-headers],
+     [Do not install no-namespace headers for compatability with MOAB 3.0 API])],
+ [OLD_HEADERS=$enableval],[OLD_HEADERS=yes])
+AM_CONDITIONAL([OLD_HEADERS],[test "xyes" = "x$OLD_HEADERS"])
+
+
+################################################################################
 #                              HANDLE SIZE
 ################################################################################
 AC_CHECK_HEADER([inttypes.h], [AC_DEFINE(MOAB_HAVE_INTTYPES_H,  [], [MOAB qualified HAVE_INTTYPES_H]) ])
@@ -56,7 +66,7 @@
 AC_CHECK_SIZEOF(void *)
 SIZEOF_VOID_P=$ac_cv_sizeof_void_p
 AC_ARG_ENABLE([64bit-handles],
-  [AC_HELP_STRING([--enable-64bit-handles],[Force MBEntityHandle to be 64 bits])],
+  [AC_HELP_STRING([--enable-64bit-handles],[Force EntityHandle to be 64 bits])],
   [AC_CHECK_TYPE([uint64_t],
     [AC_DEFINE(MOAB_FORCE_64_BIT_HANDLES,[],[Use int64_t for handles])
      SIZEOF_MBENTITYHANDLE=8
@@ -64,7 +74,7 @@
     [AC_MSG_ERROR([Platform does not have uint64_t. Cannot force 64-bit handles])])
 ])
 AC_ARG_ENABLE([32bit-handles],
-  [AC_HELP_STRING([--enable-32bit-handles],[Force MBEntityHandle to be 32 bits])],
+  [AC_HELP_STRING([--enable-32bit-handles],[Force EntityHandle to be 32 bits])],
   [AC_CHECK_TYPE([uint32_t],
     [AC_DEFINE(MOAB_FORCE_32_BIT_HANDLES,[],[Use int32_t for handles])
      SIZEOF_MBENTITYHANDLE=4
@@ -149,12 +159,12 @@
 # after configuring the compilers so that we know what size of 
 # various types are.
 
-AC_MSG_CHECKING([size of MBEntityHandle])
+AC_MSG_CHECKING([size of EntityHandle])
 AC_MSG_RESULT([$SIZEOF_MBENTITYHANDLE])
 ITAPS_VALID_HANDLE_SIZE=yes
 if test $SIZEOF_VOID_P -ne $SIZEOF_MBENTITYHANDLE; then
   ITAPS_VALID_HANDLE_SIZE=no
-  AC_MSG_WARN([Cannot build iMesh or iGeom API because sizeof(MBEntityHandle) != sizeof(void*)])
+  AC_MSG_WARN([Cannot build iMesh or iGeom API because sizeof(EntityHandle) != sizeof(void*)])
   if test "x$FORCE_IMESH" = "xno"; then
     ENABLE_imesh=no
   fi
@@ -168,7 +178,7 @@
 AM_CONDITIONAL([ENABLE_imesh],[test "xyes" = "x$ENABLE_imesh"])
 if test "x$ENABLE_imesh" = "xyes"; then
   if test "x$ITAPS_VALID_HANDLE_SIZE" != "xyes"; then
-    AC_MSG_ERROR([Cannot build iMesh API with sizeof(MBEntityHandle) != sizeof(void*)])
+    AC_MSG_ERROR([Cannot build iMesh API with sizeof(EntityHandle) != sizeof(void*)])
   fi
 fi
 
@@ -177,7 +187,7 @@
 AM_CONDITIONAL([ENABLE_igeom],[test "xyes" = "x$ENABLE_igeom"])
 if test "x$ENABLE_igeom" = "xyes"; then
   if test "x$ITAPS_VALID_HANDLE_SIZE" != "xyes"; then
-    AC_MSG_ERROR([Cannot build iGeom API with sizeof(MBEntityHandle) != sizeof(void*)])
+    AC_MSG_ERROR([Cannot build iGeom API with sizeof(EntityHandle) != sizeof(void*)])
   fi
 fi
 
@@ -235,7 +245,7 @@
 FATHOM_CONFIG_MPI_EXEC
 test "xyes" != "x$WITH_MPI" || AM_CPPFLAGS="$AM_CPPFLAGS -DUSE_MPI"
 AM_CONDITIONAL(USE_MPI, [test "xno" != "x$WITH_MPI"])
-# Used to generate MBmpi.h
+# Used to generate moab_mpi.h
 if test "xyes" = "x$MPI_CXX_HELP_NEEDED"; then
   AC_DEFINE( [MB_MPI_CXX_CONFLICT], [1], 
     [MPICH_IGNORE_CXX_SEEK is not sufficient to avoid conflicts] )
@@ -1001,9 +1011,9 @@
 
 AC_ARG_VAR([FC], [FORTRAN compiler command])
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_HEADERS([src/moab/MBVersion.h 
-                   src/moab/MBEntityHandle.h 
-                   src/parallel/moab/MBmpi_config.h
+AC_CONFIG_HEADERS([src/moab/Version.h
+                   src/moab/EntityHandle.hpp
+                   src/parallel/moab_mpi_config.h
                    src/FCDefs.h])
 AC_CONFIG_FILES([Makefile 
                  moab.make                  
@@ -1011,6 +1021,7 @@
                  src/io/Makefile
                  src/io/mhdf/Makefile
                  src/parallel/Makefile
+                 src/oldinc/Makefile
                  test/Makefile
                  test/h5file/Makefile
                  test/dual/Makefile
@@ -1018,6 +1029,7 @@
                  test/perf/Makefile
                  test/io/Makefile
                  test/parallel/Makefile
+                 test/oldinc/Makefile
                  itaps/Makefile
                  itaps/imesh/Makefile
                  itaps/imesh/iMesh-Defs.inc

Modified: MOAB/trunk/itaps/igeom/GeomTopoUtil.cpp
===================================================================
--- MOAB/trunk/itaps/igeom/GeomTopoUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/igeom/GeomTopoUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,11 +14,11 @@
  */
 
 #include "GeomTopoUtil.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInterface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 #include <assert.h>
 #include <iostream>
 
@@ -31,20 +31,20 @@
 // be listed for both the forward and reverse slots.
 const char GEOM_SENSE_TAG_NAME[] = "GEOM_SENSE_2";
 
-MBErrorCode GeomTopoUtil::set_sense( MBEntityHandle surface,
-                                     MBEntityHandle volume,
+ErrorCode GeomTopoUtil::set_sense( EntityHandle surface,
+                                     EntityHandle volume,
                                      bool forward )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (!sense2Tag) {
-    rval = mdbImpl->tag_create( GEOM_SENSE_TAG_NAME, 2*sizeof(MBEntityHandle), 
+    rval = mdbImpl->tag_create( GEOM_SENSE_TAG_NAME, 2*sizeof(EntityHandle), 
                            MB_TAG_SPARSE, MB_TYPE_HANDLE, 
                            sense2Tag, 0, true );
     if (MB_SUCCESS != rval)
       return rval;
   }
   
-  MBEntityHandle sense_data[2] = {0,0};
+  EntityHandle sense_data[2] = {0,0};
   rval = mdbImpl->tag_get_data( sense2Tag, &surface, 1, sense_data );
   if (MB_TAG_NOT_FOUND != rval && MB_SUCCESS != rval)
     return MB_FAILURE;
@@ -58,11 +58,11 @@
   return mdbImpl->tag_set_data( sense2Tag, &surface, 1, sense_data );
 }
 
-MBErrorCode GeomTopoUtil::get_sense( MBEntityHandle surface,
-                                     MBEntityHandle volume,
+ErrorCode GeomTopoUtil::get_sense( EntityHandle surface,
+                                     EntityHandle volume,
                                      bool& forward )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (!sense2Tag) {
     rval = mdbImpl->tag_get_handle( GEOM_SENSE_TAG_NAME, sense2Tag );
     if (MB_SUCCESS != rval) {
@@ -71,7 +71,7 @@
     }
   }
   
-  MBEntityHandle sense_data[2] = {0,0};
+  EntityHandle sense_data[2] = {0,0};
   rval = mdbImpl->tag_get_data( sense2Tag, &surface, 1, sense_data );
   if (MB_SUCCESS != rval)
     return rval;
@@ -86,16 +86,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode GeomTopoUtil::find_geomsets(MBRange *ranges) 
+ErrorCode GeomTopoUtil::find_geomsets(Range *ranges) 
 {
-  MBTag geom_tag;
-  MBErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
+  Tag geom_tag;
+  ErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
                                            MB_TAG_SPARSE, geom_tag, NULL);
   if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
     return result;
   
     // get all sets with this tag
-  MBRange geom_sets;
+  Range geom_sets;
   result = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &geom_tag, NULL, 1,
                                                  geom_sets);
   if (MB_SUCCESS != result || geom_sets.empty()) 
@@ -113,7 +113,7 @@
 }
   
     //! Restore parent/child links between GEOM_TOPO mesh sets
-MBErrorCode GeomTopoUtil::restore_topology() 
+ErrorCode GeomTopoUtil::restore_topology() 
 {
   
     // look for geometric topology sets and restore parent/child links between them
@@ -125,26 +125,26 @@
     //     add it to list of parents
     //   . make parent/child links with parents
 
-  MBRange entities[4];
+  Range entities[4];
   result = find_geomsets(entities);
   if (MB_SUCCESS != result)
     return result;
 
-  std::vector<MBEntityHandle> parents;
-  MBRange tmp_parents;
+  std::vector<EntityHandle> parents;
+  Range tmp_parents;
   
     // loop over dimensions
   for (int dim = 2; dim >= 0; dim--) {
       // mark entities of next higher dimension with their owners; regenerate tag
       // each dimension so prev dim's tag data goes away
-    MBTag owner_tag;
-    MBEntityHandle dum_val = 0;
-    result = mdbImpl->tag_create("__owner_tag", sizeof(MBEntityHandle), MB_TAG_DENSE,
+    Tag owner_tag;
+    EntityHandle dum_val = 0;
+    result = mdbImpl->tag_create("__owner_tag", sizeof(EntityHandle), MB_TAG_DENSE,
                                  MB_TYPE_HANDLE, owner_tag, &dum_val);
     if (MB_SUCCESS != result) continue;
-    MBRange dp1ents;
-    std::vector<MBEntityHandle> owners;
-    for (MBRange::iterator rit = entities[dim+1].begin(); rit != entities[dim+1].end(); rit++) {
+    Range dp1ents;
+    std::vector<EntityHandle> owners;
+    for (Range::iterator rit = entities[dim+1].begin(); rit != entities[dim+1].end(); rit++) {
       dp1ents.clear();
       result = mdbImpl->get_entities_by_dimension(*rit, dim+1, dp1ents);
       if (MB_SUCCESS != result) continue;
@@ -154,9 +154,9 @@
       if (MB_SUCCESS != result) continue;
     }
     
-    for (MBRange::iterator d_it = entities[dim].begin(); 
+    for (Range::iterator d_it = entities[dim].begin(); 
          d_it != entities[dim].end(); d_it++) {
-      MBRange dents;
+      Range dents;
       result = mdbImpl->get_entities_by_dimension(*d_it, dim, dents);
       if (MB_SUCCESS != result) continue;
       if (dents.empty()) continue;
@@ -175,8 +175,8 @@
       
         // compress to a range to remove duplicates
       tmp_parents.clear();
-      std::copy(parents.begin(), parents.end(), mb_range_inserter(tmp_parents));
-      for (MBRange::iterator pit = tmp_parents.begin(); pit != tmp_parents.end(); pit++) {
+      std::copy(parents.begin(), parents.end(), range_inserter(tmp_parents));
+      for (Range::iterator pit = tmp_parents.begin(); pit != tmp_parents.end(); pit++) {
         result = mdbImpl->add_parent_child(*pit, *d_it);
         if (MB_SUCCESS != result) return result;
       }
@@ -184,7 +184,7 @@
         // store surface senses
       if (dim != 2) 
         continue;
-      const MBEntityHandle *conn3, *conn2;
+      const EntityHandle *conn3, *conn2;
       int len3, len2, err, num, sense, offset;
       for (size_t i = 0; i < parents.size(); ++i) {
         result = mdbImpl->get_connectivity( dp1ents[i], conn3, len3, true );
@@ -217,10 +217,10 @@
   return result;
 }
 
-MBErrorCode GeomTopoUtil::separate_by_dimension(const MBRange &geom_sets,
-                                                 MBRange *entities, MBTag geom_tag) 
+ErrorCode GeomTopoUtil::separate_by_dimension(const Range &geom_sets,
+                                                 Range *entities, Tag geom_tag) 
 {
-  MBErrorCode result;
+  ErrorCode result;
   
   if (0 == geom_tag) {
     
@@ -235,7 +235,7 @@
   if (MB_SUCCESS != result)
     return result;
 
-  MBRange::const_iterator git;
+  Range::const_iterator git;
   std::vector<int>::iterator iit;
   
   for (git = geom_sets.begin(), iit = tag_vals.begin(); git != geom_sets.end(); 
@@ -251,15 +251,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode GeomTopoUtil::construct_vertex_ranges(const MBRange &geom_sets,
-                                                   const MBTag verts_tag) 
+ErrorCode GeomTopoUtil::construct_vertex_ranges(const Range &geom_sets,
+                                                   const Tag verts_tag) 
 {
     // construct the vertex range for each entity and put on that tag
-  MBRange *temp_verts, temp_elems;
-  MBErrorCode result = MB_SUCCESS;
-  for (MBRange::const_iterator it = geom_sets.begin(); it != geom_sets.end(); it++) {
+  Range *temp_verts, temp_elems;
+  ErrorCode result = MB_SUCCESS;
+  for (Range::const_iterator it = geom_sets.begin(); it != geom_sets.end(); it++) {
       // make the new range
-    temp_verts = new MBRange();
+    temp_verts = new Range();
     assert(NULL != temp_verts);
     temp_elems.clear();
     
@@ -270,7 +270,7 @@
     
       // get all the verts of those elements; use get_adjacencies 'cuz it handles ranges better
     result = mdbImpl->get_adjacencies(temp_elems, 0, false, *temp_verts,
-                                      MBInterface::UNION);
+                                      Interface::UNION);
     if (MB_SUCCESS != result) 
       return result;
 

Modified: MOAB/trunk/itaps/igeom/GeomTopoUtil.hpp
===================================================================
--- MOAB/trunk/itaps/igeom/GeomTopoUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/igeom/GeomTopoUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -18,47 +18,49 @@
 #ifndef GEOM_TOPO_UTIL_HPP
 #define GEOM_TOPO_UTIL_HPP
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
 
+using namespace moab;
+
 class GeomTopoUtil
 {
 public:
-  GeomTopoUtil(MBInterface *impl, bool find_geoments = false);
+  GeomTopoUtil(Interface *impl, bool find_geoments = false);
   ~GeomTopoUtil() {}
   
     //! Restore parent/child links between GEOM_TOPO mesh sets
-  MBErrorCode restore_topology();
+  ErrorCode restore_topology();
   
     //! Store sense of surface relative to volume.
     //!\return MB_MULTIPLE_ENTITIES_FOUND if surface already has a forward volume.
     //!        MB_SUCCESS if successful
     //!        otherwise whatever internal error code occured.
-  MBErrorCode set_sense( MBEntityHandle surface,
-                         MBEntityHandle volume,
+  ErrorCode set_sense( EntityHandle surface,
+                         EntityHandle volume,
                          bool forward );
 
-  MBErrorCode get_sense( MBEntityHandle surface,
-                         MBEntityHandle volume,
+  ErrorCode get_sense( EntityHandle surface,
+                         EntityHandle volume,
                          bool& forward );
 
-  MBErrorCode find_geomsets(MBRange *ranges = NULL);
+  ErrorCode find_geomsets(Range *ranges = NULL);
 
 private:
-  MBInterface *mdbImpl;
-  MBTag sense2Tag;
-  MBRange geomRanges[4];
+  Interface *mdbImpl;
+  Tag sense2Tag;
+  Range geomRanges[4];
   
     //! compute vertices inclusive and put on tag on sets in geom_sets
-  MBErrorCode construct_vertex_ranges(const MBRange &geom_sets,
-                                       const MBTag verts_tag);
+  ErrorCode construct_vertex_ranges(const Range &geom_sets,
+                                       const Tag verts_tag);
   
     //! given a range of geom topology sets, separate by dimension
-  MBErrorCode separate_by_dimension(const MBRange &geom_sets,
-                                     MBRange *entities, MBTag geom_tag = 0);
+  ErrorCode separate_by_dimension(const Range &geom_sets,
+                                     Range *entities, Tag geom_tag = 0);
 };
 
-inline GeomTopoUtil::GeomTopoUtil(MBInterface *impl, 
+inline GeomTopoUtil::GeomTopoUtil(Interface *impl, 
                                   bool find_geoments) 
         : mdbImpl(impl), sense2Tag(0) 
 {

Modified: MOAB/trunk/itaps/igeom/Makefile.am
===================================================================
--- MOAB/trunk/itaps/igeom/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/igeom/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,8 +3,6 @@
 AM_CPPFLAGS = -DSRCDIR=$(srcdir) \
               -I$(top_srcdir)/src \
               -I$(top_builddir)/src \
-              -I$(top_srcdir)/src/moab \
-              -I$(top_builddir)/src/moab \
               -I.. -I$(srcdir)/.. \
               -I$(top_srcdir)/itaps/imesh \
               -I$(top_builddir)/itaps/imesh 

Modified: MOAB/trunk/itaps/igeom/iGeom_MOAB.cpp
===================================================================
--- MOAB/trunk/itaps/igeom/iGeom_MOAB.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/igeom/iGeom_MOAB.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,24 +2,26 @@
 #include <map>
 #include "iGeom_MOAB.hpp"
 #include "iMesh.h"
-#include "MBInterface.hpp"
-#include "GeomTopoTool.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
-#include "MBCartVect.hpp"
+#include "moab/Interface.hpp"
+#include "moab/GeomTopoTool.hpp"
+#include "OrientedBox.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
+#include "moab/CartVect.hpp"
 #include <stdlib.h>
 #include <cstring>
 
+using namespace moab;
+
 iBase_Error iGeom_LAST_ERROR;
 bool i_created = false; // if interface is created
 bool t_created = false;
-MBRange _my_gsets[4];
+Range _my_gsets[4];
 GeomTopoTool* _my_geomTopoTool = NULL;
 
 bool debug_igeom = false;
 
 #define COPY_RANGE(r, vec) {                      \
-    MBEntityHandle *tmp_ptr = reinterpret_cast<MBEntityHandle*>(vec);	\
+    EntityHandle *tmp_ptr = reinterpret_cast<EntityHandle*>(vec);	\
     std::copy(r.begin(), r.end(), tmp_ptr);}
 
 static inline void
@@ -27,9 +29,9 @@
 
 static void
 iGeom_get_adjacent_entities(iGeom_Instance instance,
-			    const MBEntityHandle from, 
+			    const EntityHandle from, 
 			    const int to_dim,
-			    MBRange &adj_ents, int* err);
+			    Range &adj_ents, int* err);
 
 double get_edge_length(double* p1, double* p2);
 
@@ -57,9 +59,9 @@
                     int* err,
                     int options_len ) 
 {
-  if (*instance_out && !(reinterpret_cast<MBInterface*>(instance_out))) {
+  if (*instance_out && !(reinterpret_cast<Interface*>(instance_out))) {
     *err = iBase_INVALID_ENTITY_TYPE;
-    ERRORR("Passed in instance must be an MBInterface*.");
+    ERRORR("Passed in instance must be an Interface*.");
   }
 
   // make a new imesh instance
@@ -94,9 +96,9 @@
              name_len, options_len);
   ERRORR("Failure to load geometry.");
   
-  // keep mesh-based geometries in MBRange
+  // keep mesh-based geometries in Range
   GETGTT(instance);
-  MBErrorCode rval = _my_geomTopoTool->find_geomsets(_my_gsets);
+  ErrorCode rval = _my_geomTopoTool->find_geomsets(_my_gsets);
   MBERRORR("Failure to keep geometry list.");
 
   if (debug_igeom) {
@@ -192,7 +194,7 @@
   }
   else {
     *entity_handles_size = 0;
-    MBRange total_range;
+    Range total_range;
     for (i = 0; i < 4; i++) {
       total_range.merge(_my_gsets[i]);
     }
@@ -268,8 +270,8 @@
                       int* adj_entities_size,
                       int* err ) 
 {
-  MBRange adjs;
-  MBEntityHandle this_ent = MBH_cast(entity_handle);
+  Range adjs;
+  EntityHandle this_ent = MBH_cast(entity_handle);
 
   // get adjacent
   iGeom_get_adjacent_entities(instance, this_ent, to_dimension,
@@ -298,7 +300,7 @@
                       int* err ) 
 {
   // check offset array size
-  MBRange temp_range, total_range;
+  Range temp_range, total_range;
   CHECK_SIZE(*offset, *offset_allocated, entity_handles_size + 1, int, NULL);
   *offset_size = entity_handles_size + 1;
   
@@ -333,12 +335,12 @@
                          int* adjacent_entities_size,
                          int* err )
 {
-  MBRange to_ents, bridge_ents, tmp_ents;
+  Range to_ents, bridge_ents, tmp_ents;
   iGeom_get_adjacent_entities(instance, MBH_cast(entity_handle), bridge_dimension, bridge_ents, err);
   ERRORR("Failed to get adjacent entities in iGeom_getEnt2ndAdj.");
   
-  MBRange::iterator iter, jter, kter, end_jter;
-  MBRange::iterator end_iter = bridge_ents.end();
+  Range::iterator iter, jter, kter, end_jter;
+  Range::iterator end_iter = bridge_ents.end();
   for (iter = bridge_ents.begin(); iter != end_iter; iter++) {
     iGeom_get_adjacent_entities(instance, *iter, to_dimension, tmp_ents, err);
     ERRORR("Failed to get adjacent entities in iGeom_getEnt2ndAdj.");
@@ -373,7 +375,7 @@
                          int* err )
 {
   CHECK_SIZE(*offset, *offset_allocated, entity_handles_size + 1, int, NULL);
-  MBRange bridge_range, temp_range, entity_range, total_range;
+  Range bridge_range, temp_range, entity_range, total_range;
    
   for (int i = 0; i < entity_handles_size; ++i) {
     bridge_range.clear();
@@ -382,8 +384,8 @@
 				order_adjacent_key, bridge_range, err);
     ERRORR("Failed to get adjacent entities in iGeom_getArr2ndAdj.");
 
-    MBRange::iterator iter, jter, end_jter;
-    MBRange::iterator end_iter = bridge_range.end();
+    Range::iterator iter, jter, end_jter;
+    Range::iterator end_iter = bridge_range.end();
     for (iter = bridge_range.begin(); iter != end_iter; iter++) {
       temp_range.clear();
       iGeom_get_adjacent_entities(instance, *iter,
@@ -422,8 +424,8 @@
   iGeom_getEntType(instance, entity_handle2, &type2, err);
   ERRORR("Failed to get entity type in iGeom_isEntAdj.");
 
-  MBErrorCode rval;
-  MBRange adjs;
+  ErrorCode rval;
+  Range adjs;
   if (type1 < type2) {
     rval = MBI->get_parent_meshsets(MBH_cast(entity_handle1), adjs, type2 - type1);
     MBERRORR("Failed to get parent meshsets in iGeom_isEntAdj.");
@@ -500,7 +502,7 @@
                             double* on_z,
                             int* err )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int type;
   iGeom_getEntType(instance, entity_handle, &type, err);
   ERRORR("Failed to get entity type.");
@@ -527,7 +529,7 @@
     
     double point[3] = {near_x, near_y, near_z};
     double point_out[3];
-    MBEntityHandle root, facet_out;
+    EntityHandle root, facet_out;
     rval = _my_geomTopoTool->get_root(MBH_cast(entity_handle), root);
     MBERRORR("Failed to get tree root in iGeom_getEntClosestPt.");
     rval = _my_geomTopoTool->obb_tree()->closest_to_location(point, root,
@@ -600,17 +602,17 @@
   // get closest location and facet
   double point[3] = {x, y, z};
   double point_out[3];
-  MBEntityHandle root, facet_out;
+  EntityHandle root, facet_out;
   _my_geomTopoTool->get_root(MBH_cast(entity_handle), root);
-  MBErrorCode rval = _my_geomTopoTool->obb_tree()->closest_to_location(point, root,
+  ErrorCode rval = _my_geomTopoTool->obb_tree()->closest_to_location(point, root,
 							   point_out,
 							   facet_out);
   MBERRORR("Failed to get closest location in iGeom_getEntNrmlXYZ.");
 
   // get facet normal
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
-  MBCartVect coords[3], normal;
+  CartVect coords[3], normal;
   rval = MBI->get_connectivity(facet_out, conn, len);
   MBERRORR("Failed to get triangle connectivity in iGeom_getEntNrmlXYZ.");
   if (len != 3) RETURN(iBase_FAILURE);
@@ -737,9 +739,9 @@
   // get closest location and facet
   double point[3] = {x, y, z};
   double point_out[3];
-  MBEntityHandle root, facet_out;
+  EntityHandle root, facet_out;
   _my_geomTopoTool->get_root(MBH_cast(entity_handle), root);
-  MBErrorCode rval = _my_geomTopoTool->obb_tree()->closest_to_location(point, root,
+  ErrorCode rval = _my_geomTopoTool->obb_tree()->closest_to_location(point, root,
 								       point_out,
 								       facet_out);
   MBERRORR("Failed to get closest location in iGeom_getEntNrmlPlXYZ.");
@@ -750,9 +752,9 @@
   *pt_z = point_out[2];
 
   // get facet normal
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
-  MBCartVect coords[3], normal;
+  CartVect coords[3], normal;
   rval = MBI->get_connectivity(facet_out, conn, len);
   MBERRORR("Failed to get triangle connectivity in iGeom_getEntNrmlPlXYZ.");
   if (len != 3) RETURN(iBase_FAILURE);
@@ -906,7 +908,7 @@
                            double* max_z,
                            int* err )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int type;
   iGeom_getEntType(instance, entity_handle, &type, err);
   ERRORR("Failed to get entity type.");
@@ -931,14 +933,14 @@
       t_created = true;
     }
     
-    MBEntityHandle root;
-    MBOrientedBox box;
+    EntityHandle root;
+    OrientedBox box;
     rval = _my_geomTopoTool->get_root(MBH_cast(entity_handle), root);
     MBERRORR("Failed to get tree root in iGeom_getEntBoundBox.");
     rval = _my_geomTopoTool->obb_tree()->box(root, box);
     MBERRORR("Failed to get closest point in iGeom_getEntBoundBox.");
     
-    MBCartVect min, max;
+    CartVect min, max;
     min = box.center - box.length[0]*box.axis[0] - box.length[1]*box.axis[1]
       - box.length[2]*box.axis[2];
     max = box.center + box.length[0]*box.axis[0] + box.length[1]*box.axis[1]
@@ -1220,7 +1222,7 @@
       
       // calculate sum of area of triangles
       double* p;
-      MBCartVect coords[3];
+      CartVect coords[3];
       for (int j = 0; j < tris_size; j++) {
 	for (int k = 0; k < 3; k++) {
 	  p = coords[k].array();
@@ -1785,7 +1787,7 @@
 
 void iGeom_deleteAll(iGeom_Instance instance, int* err )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   for (int i = 0; i < 4; i++) {
     rval = MBI->delete_entities(_my_gsets[i]);
     MBERRORR("Failed to delete entities in iGeom_deleteAll.");
@@ -1803,14 +1805,14 @@
   iGeom_getEntType(instance, entity_handle, &type, err);
   ERRORR("Failed to get entity type in iGeom_deleteEnt.");
 
-  MBRange::iterator iter = _my_gsets[type].find(MBH_cast(entity_handle));
+  Range::iterator iter = _my_gsets[type].find(MBH_cast(entity_handle));
   if (iter == _my_gsets[type].end()) {
     RETURN(iBase_INVALID_ENTITY_HANDLE);
   }
   _my_gsets[type].erase(iter);
 
-  MBEntityHandle this_entity = MBH_cast(entity_handle);
-  MBErrorCode rval = MBI->delete_entities(&this_entity, 1);
+  EntityHandle this_entity = MBH_cast(entity_handle);
+  ErrorCode rval = MBI->delete_entities(&this_entity, 1);
   MBERRORR("Failed to delete entity.");
 }
 
@@ -2623,10 +2625,10 @@
 
 static void
 iGeom_get_adjacent_entities(iGeom_Instance instance,
-			    const MBEntityHandle from, 
+			    const EntityHandle from, 
 			    const int to_dim,
-			    MBRange &adjs,
-			    //std::vector<MBEntityHandle>& adjs,
+			    Range &adjs,
+			    //std::vector<EntityHandle>& adjs,
 			    int* err)
 {
   int this_dim = -1;
@@ -2651,7 +2653,7 @@
     RETURN(iBase_FAILURE);
   }
   
-  MBErrorCode rval;
+  ErrorCode rval;
   adjs.clear();
   if (to_dim > this_dim) {
     int number;

Modified: MOAB/trunk/itaps/igeom/iGeom_MOAB.hpp
===================================================================
--- MOAB/trunk/itaps/igeom/iGeom_MOAB.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/igeom/iGeom_MOAB.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,40 +2,40 @@
 #define IGEOM_MOAB_HPP
 
 #include "iGeom.h"
-#include "MBForward.hpp"
+#include "moab/Forward.hpp"
 
-class GeomTopoTool;
+namespace moab { class GeomTopoTool; }
 
 /* map from MB's entity type to TSTT's entity type */
-extern const iBase_EntityType tstt_type_table[MBMAXTYPE+1];
+extern const iBase_EntityType tstt_type_table[moab::MBMAXTYPE+1];
 
 /* map to MB's entity type from TSTT's entity topology */
-extern const MBEntityType mb_topology_table[MBMAXTYPE+1];
+extern const moab::EntityType mb_topology_table[moab::MBMAXTYPE+1];
 
 /* map from TSTT's tag types to MOAB's */
-extern const MBDataType mb_data_type_table[4];
+extern const moab::DataType mb_data_type_table[4];
 
 /* map from MOAB's tag types to tstt's */
-extern const iBase_TagValueType tstt_data_type_table[MB_MAX_DATA_TYPE+1];
+extern const iBase_TagValueType tstt_data_type_table[moab::MB_MAX_DATA_TYPE+1];
 
 /* map from MOAB's MBErrorCode to tstt's */
-extern "C" const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
+extern "C" const iBase_ErrorType iBase_ERROR_MAP[moab::MB_FAILURE+1];
 
 /* Create ITAPS iterator */
-iGeom_EntityIterator create_itaps_iterator( MBRange& swap_range,
+iGeom_EntityIterator create_itaps_iterator( moab::Range& swap_range,
                                             int array_size = 1 ); 
 
 /* Define macro for quick reference to MBInterface instance */
-static inline MBInterface* MBI_cast( iGeom_Instance i )  
-  { return reinterpret_cast<MBInterface*>(i); }         
+static inline moab::Interface* MBI_cast( iGeom_Instance i )  
+  { return reinterpret_cast<moab::Interface*>(i); }         
 #define MBI MBI_cast(instance)
 
-/* Define macro for quick reference to MBInterface instance */
-static inline MBEntityHandle MBH_cast( iBase_EntityHandle h )  
-  { return reinterpret_cast<MBEntityHandle>(h); }         
+/* Define macro for quick reference to moab::Interface instance */
+static inline moab::EntityHandle MBH_cast( iBase_EntityHandle h )  
+  { return reinterpret_cast<moab::EntityHandle>(h); }         
 
 #define GETGTT(a) {if (_my_geomTopoTool == NULL) _my_geomTopoTool =	\
-	new GeomTopoTool(reinterpret_cast<MBInterface*>(a));}
+	new GeomTopoTool(reinterpret_cast<moab::Interface*>(a));}
 
 /* Most recently returned error code */
 //extern "C" iBase_Error iGeom_LAST_ERROR;

Modified: MOAB/trunk/itaps/imesh/Makefile.am
===================================================================
--- MOAB/trunk/itaps/imesh/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,9 +3,7 @@
 AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
                -I$(srcdir)/.. \
                -I$(top_srcdir)/src \
-               -I$(top_builddir)/src \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_builddir)/src/moab 
+               -I$(top_builddir)/src  
 
 # stuff for c test program
 check_PROGRAMS = testc_cbind

Modified: MOAB/trunk/itaps/imesh/iMeshP.h
===================================================================
--- MOAB/trunk/itaps/imesh/iMeshP.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/iMeshP.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,7 +4,7 @@
 
 #include "iMesh.h"
 #include "iMeshP_protos.h"
-#include "MBmpi.h"
+#include "moab_mpi.h"
 
 #ifdef __cplusplus
 extern "C" {

Modified: MOAB/trunk/itaps/imesh/iMeshP_MOAB.cpp
===================================================================
--- MOAB/trunk/itaps/imesh/iMeshP_MOAB.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/iMeshP_MOAB.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,24 +1,27 @@
 #include "iMeshP.h"
 #include "iMesh_MOAB.hpp"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "FileOptions.hpp"
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
 
 #define IS_BUILDING_MB
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #undef IS_BUILDING_MB
 
 #include <assert.h>
 #include <sstream>
 
 #ifdef USE_MPI    
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #endif
 
+using namespace moab;
+
+
 /********************* Error Handling **************************/
 
 #define FIXME printf("Warning: function has incomplete implementation: %s\n", __func__ )
@@ -42,74 +45,74 @@
 T itaps_cast( S h )
 { return h; }
 // verify size and do reinterpret cast
-template <typename T> inline T itaps_cast_internal_( MBEntityHandle h )
+template <typename T> inline T itaps_cast_internal_( EntityHandle h )
 {
-  assert(sizeof(T) >= sizeof(MBEntityHandle));
+  assert(sizeof(T) >= sizeof(EntityHandle));
   return reinterpret_cast<T>(h);
 }
 // verify size and do reinterpret cast
-template <typename T> inline MBEntityHandle* itaps_cast_ptr_( T* h )
+template <typename T> inline EntityHandle* itaps_cast_ptr_( T* h )
 {
-  assert(sizeof(T) == sizeof(MBEntityHandle));
-  return reinterpret_cast<MBEntityHandle*>(h);
+  assert(sizeof(T) == sizeof(EntityHandle));
+  return reinterpret_cast<EntityHandle*>(h);
 }
 // verify size and do reinterpret cast
-template <typename T> inline const MBEntityHandle* itaps_cast_const_ptr_( const T* h )
+template <typename T> inline const EntityHandle* itaps_cast_const_ptr_( const T* h )
 {
-  assert(sizeof(T) == sizeof(MBEntityHandle));
-  return reinterpret_cast<const MBEntityHandle*>(h);
+  assert(sizeof(T) == sizeof(EntityHandle));
+  return reinterpret_cast<const EntityHandle*>(h);
 }
 // verify set-type handle before cast
-template <typename T> inline T itaps_set_cast_( MBEntityHandle h )
+template <typename T> inline T itaps_set_cast_( EntityHandle h )
 {
   assert(TYPE_FROM_HANDLE(h) == MBENTITYSET);
   return itaps_cast_internal_<T>(h);
 }
 
-// define conversion routines between itaps handle and MBEntityHandle types
+// define conversion routines between itaps handle and EntityHandle types
 #define DECLARE_ALLOWED_ITAPS_CONVERSION( ITAPS_HANDLE_TYPE ) \
   template <> inline \
   ITAPS_HANDLE_TYPE \
-  itaps_cast<ITAPS_HANDLE_TYPE,MBEntityHandle>( MBEntityHandle h ) \
+  itaps_cast<ITAPS_HANDLE_TYPE,EntityHandle>( EntityHandle h ) \
   { return itaps_cast_internal_<ITAPS_HANDLE_TYPE>(h); } \
   \
   template <> inline \
-  MBEntityHandle \
-  itaps_cast<MBEntityHandle,ITAPS_HANDLE_TYPE>( ITAPS_HANDLE_TYPE handle ) \
-  { return reinterpret_cast<MBEntityHandle>(handle); } \
+  EntityHandle \
+  itaps_cast<EntityHandle,ITAPS_HANDLE_TYPE>( ITAPS_HANDLE_TYPE handle ) \
+  { return reinterpret_cast<EntityHandle>(handle); } \
   \
   template <> inline \
-  MBEntityHandle* \
-  itaps_cast<MBEntityHandle*,ITAPS_HANDLE_TYPE*>( ITAPS_HANDLE_TYPE* ptr ) \
+  EntityHandle* \
+  itaps_cast<EntityHandle*,ITAPS_HANDLE_TYPE*>( ITAPS_HANDLE_TYPE* ptr ) \
   { return itaps_cast_ptr_(ptr); } \
   \
   template <> inline \
-  const MBEntityHandle* \
-  itaps_cast<const MBEntityHandle*,const ITAPS_HANDLE_TYPE*>( const ITAPS_HANDLE_TYPE* ptr ) \
+  const EntityHandle* \
+  itaps_cast<const EntityHandle*,const ITAPS_HANDLE_TYPE*>( const ITAPS_HANDLE_TYPE* ptr ) \
   { return itaps_cast_const_ptr_(ptr); }
 
 
-// define conversion routines between itaps handle and MBEntityHandle types
-// but limit to MBEntityHandle for MBENTITYSET type.
+// define conversion routines between itaps handle and EntityHandle types
+// but limit to EntityHandle for MBENTITYSET type.
 #define DECLARE_ALLOWED_ITAPS_SET_CONVERSION( ITAPS_HANDLE_TYPE ) \
   template <> inline \
   ITAPS_HANDLE_TYPE \
-  itaps_cast<ITAPS_HANDLE_TYPE,MBEntityHandle>( MBEntityHandle h ) \
+  itaps_cast<ITAPS_HANDLE_TYPE,EntityHandle>( EntityHandle h ) \
   { return itaps_set_cast_<ITAPS_HANDLE_TYPE>(h); } \
   \
   template <> inline \
-  MBEntityHandle \
-  itaps_cast<MBEntityHandle,ITAPS_HANDLE_TYPE>( ITAPS_HANDLE_TYPE handle ) \
-  { return reinterpret_cast<MBEntityHandle>(handle); } \
+  EntityHandle \
+  itaps_cast<EntityHandle,ITAPS_HANDLE_TYPE>( ITAPS_HANDLE_TYPE handle ) \
+  { return reinterpret_cast<EntityHandle>(handle); } \
   \
   template <> inline \
-  MBEntityHandle* \
-  itaps_cast<MBEntityHandle*,ITAPS_HANDLE_TYPE*>( ITAPS_HANDLE_TYPE* ptr ) \
+  EntityHandle* \
+  itaps_cast<EntityHandle*,ITAPS_HANDLE_TYPE*>( ITAPS_HANDLE_TYPE* ptr ) \
   { return itaps_cast_ptr_(ptr); } \
   \
   template <> inline \
-  const MBEntityHandle* \
-  itaps_cast<const MBEntityHandle*,const ITAPS_HANDLE_TYPE*>( const ITAPS_HANDLE_TYPE* ptr ) \
+  const EntityHandle* \
+  itaps_cast<const EntityHandle*,const ITAPS_HANDLE_TYPE*>( const ITAPS_HANDLE_TYPE* ptr ) \
   { return itaps_cast_const_ptr_(ptr); }
 
 DECLARE_ALLOWED_ITAPS_SET_CONVERSION( iMeshP_PartitionHandle )
@@ -119,38 +122,38 @@
 
 
 template <> inline
-MBTag itaps_cast<MBTag,iBase_TagHandle>( iBase_TagHandle h )
-  { return reinterpret_cast<MBTag>(h); }
+Tag itaps_cast<Tag,iBase_TagHandle>( iBase_TagHandle h )
+  { return reinterpret_cast<Tag>(h); }
 template <> inline
-iBase_TagHandle itaps_cast<iBase_TagHandle,MBTag>( MBTag h )
+iBase_TagHandle itaps_cast<iBase_TagHandle,Tag>( Tag h )
   { return reinterpret_cast<iBase_TagHandle>(h); }
 
 
 #endif
 
-#define PCOMM MBParallelComm::get_pcomm( MBI, itaps_cast<MBEntityHandle>(partition_handle) )
+#define PCOMM ParallelComm::get_pcomm( MBI, itaps_cast<EntityHandle>(partition_handle) )
 
-// Need a different function name for MBTag because (currently)
-// both MBTag and iBase_EntityHandle are void**.
-iBase_TagHandle itaps_tag_cast( MBTag t )
+// Need a different function name for Tag because (currently)
+// both Tag and iBase_EntityHandle are void**.
+iBase_TagHandle itaps_tag_cast( Tag t )
 { 
-  assert(sizeof(iBase_TagHandle) >= sizeof(MBTag)); 
+  assert(sizeof(iBase_TagHandle) >= sizeof(Tag)); 
   return reinterpret_cast<iBase_TagHandle>(t);
 }
 
 /********************* ITAPS arrays **************************/
 
-// Handle returning MBRange in ITAPS array (do ALLOCATE_ARRAY and copy).
-#define MBRANGE_TO_ITAPS_ARRAY( RANGE, NAME ) do { \
+// Handle returning Range in ITAPS array (do ALLOCATE_ARRAY and copy).
+#define RANGE_TO_ITAPS_ARRAY( RANGE, NAME ) do { \
   ALLOC_CHECK_ARRAY_NOFAIL( NAME, (RANGE).size() ); \
-  std::copy( (RANGE).begin(), (RANGE).end(), itaps_cast<MBEntityHandle*>(*(NAME)) ); \
+  std::copy( (RANGE).begin(), (RANGE).end(), itaps_cast<EntityHandle*>(*(NAME)) ); \
   } while (false)
 
 
-static inline MBErrorCode get_entities( MBInterface* iface,
-                                        MBEntityHandle set,
+static inline ErrorCode get_entities( Interface* iface,
+                                        EntityHandle set,
                                         int type, int topology, 
-                                        MBRange& entities )
+                                        Range& entities )
 {
   if (topology != iMesh_ALL_TOPOLOGIES)
     return iface->get_entities_by_type( set, mb_topology_table[topology], entities );
@@ -160,16 +163,16 @@
     return iface->get_entities_by_handle( set, entities );
 }
 
-static inline MBErrorCode remove_not_owned( MBParallelComm* pcomm, MBRange& ents )
+static inline ErrorCode remove_not_owned( ParallelComm* pcomm, Range& ents )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   std::vector<unsigned char> pstatus(ents.size());
   rval = pcomm->get_moab()->tag_get_data(pcomm->pstatus_tag(), ents, &pstatus[0]);
   if (MB_SUCCESS != rval)
     return rval;
     
-  MBRange::iterator i = ents.begin();
+  Range::iterator i = ents.begin();
   std::vector<unsigned char>::const_iterator j;
   for (j = pstatus.begin(); j != pstatus.end(); ++j) {
     if (*j & PSTATUS_NOT_OWNED)
@@ -181,9 +184,9 @@
   return MB_SUCCESS;
 }
 
-static inline MBErrorCode count_owned( MBParallelComm* pcomm, const MBRange& ents, int& n )
+static inline ErrorCode count_owned( ParallelComm* pcomm, const Range& ents, int& n )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   n = 0;
   
   std::vector<unsigned char> pstatus(ents.size());
@@ -204,24 +207,24 @@
                                     iBase_EntitySetHandle set2,
                                     int type,
                                     int topo,
-                                    MBRange& result,
+                                    Range& result,
                                     int* err )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   if (!set1) {
-    rval = get_entities( MBI, itaps_cast<MBEntityHandle>(set2), type, topo, result );
+    rval = get_entities( MBI, itaps_cast<EntityHandle>(set2), type, topo, result );
     CHKERR(rval,"Invalid Part handle");
   }
   else if (!set2) {
-    rval = get_entities( MBI, itaps_cast<MBEntityHandle>(set1), type, topo, result );
+    rval = get_entities( MBI, itaps_cast<EntityHandle>(set1), type, topo, result );
     CHKERR(rval,"Invalid set handle");
   }
   else {
-    MBRange r1, r2;
-    rval = get_entities( MBI, itaps_cast<MBEntityHandle>(set1), type, topo, r1 );
+    Range r1, r2;
+    rval = get_entities( MBI, itaps_cast<EntityHandle>(set1), type, topo, r1 );
     CHKERR(rval,"Invalid Part handle");
-    rval = get_entities( MBI, itaps_cast<MBEntityHandle>(set2), type, topo, r2 );
+    rval = get_entities( MBI, itaps_cast<EntityHandle>(set2), type, topo, r2 );
     CHKERR(rval,"Invalid set handle");
     result.merge( intersect( r1, r2) );
   }
@@ -244,8 +247,8 @@
 {
   *partition_handle = 0;
 
-  MBTag prtn_tag;
-  MBErrorCode rval = MBI->tag_create( PARALLEL_PARITIONING_TAG_NAME, 
+  Tag prtn_tag;
+  ErrorCode rval = MBI->tag_create( PARALLEL_PARITIONING_TAG_NAME, 
                                       sizeof(int), 
                                       MB_TAG_SPARSE,
                                       MB_TYPE_INTEGER, 
@@ -253,9 +256,9 @@
                                       0, 
                                       true ); CHKERR(rval,"tag creation failed");
   
-  MBEntityHandle handle;
+  EntityHandle handle;
   rval = MBI->create_meshset( MESHSET_SET, handle ); CHKERR(rval,"set creation failed");
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, handle, &communicator );
+  ParallelComm* pcomm = ParallelComm::get_pcomm( MBI, handle, &communicator );
   if (!pcomm) {
     MBI->delete_entities( &handle, 1 );
     RETURN(iBase_FAILURE);
@@ -269,11 +272,11 @@
                                  iMeshP_PartitionHandle partition_handle,
                                  int *err)
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (pcomm)
     delete pcomm;
-  MBEntityHandle handle = itaps_cast<MBEntityHandle>(partition_handle);
-  MBErrorCode rval = MBI->delete_entities( &handle, 1 ); CHKERR(rval,"entity deletion failed");
+  EntityHandle handle = itaps_cast<EntityHandle>(partition_handle);
+  ErrorCode rval = MBI->delete_entities( &handle, 1 ); CHKERR(rval,"entity deletion failed");
   RETURN (iBase_SUCCESS);
 }
 
@@ -309,12 +312,12 @@
             int *part_ids_size,
             int *err)
 {
-  MBErrorCode rval;
-  MBParallelComm* pcomm = PCOMM;
+  ErrorCode rval;
+  ParallelComm* pcomm = PCOMM;
   ALLOC_CHECK_ARRAY( part_ids, part_handles_size );
   for (int i = 0; i < part_handles_size; ++i) {
     int id;
-    rval = pcomm->get_part_id( itaps_cast<MBEntityHandle>(part_handles[i]), id );
+    rval = pcomm->get_part_id( itaps_cast<EntityHandle>(part_handles[i]), id );
     (*part_ids)[i] = id;
     CHKERR(rval,"error getting part id");
   }
@@ -332,11 +335,11 @@
             int *part_handles_size,
             int *err)
 {
-  MBErrorCode rval;
-  MBParallelComm* pcomm = PCOMM;
+  ErrorCode rval;
+  ParallelComm* pcomm = PCOMM;
   ALLOC_CHECK_ARRAY( part_handles, part_ids_size );
   for (int i = 0; i < part_ids_size; ++i) {
-    MBEntityHandle handle;
+    EntityHandle handle;
     rval = pcomm->get_part_handle( part_ids[i], handle );
     CHKERR(rval,"error getting part handle");
     (*part_handles)[i] = itaps_cast<iMeshP_PartHandle>(handle);
@@ -350,7 +353,7 @@
                               MPI_Comm* communicator_out,
                               int* err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     RETURN (iBase_FAILURE);
   *communicator_out = pcomm->proc_config().proc_comm();
@@ -361,10 +364,10 @@
                               iMeshP_PartitionHandle partition_handle,
                               int* err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
-  MBErrorCode rval = pcomm->collective_sync_partition();
+  ErrorCode rval = pcomm->collective_sync_partition();
   CHKERR(rval,"collective sync failed");
   RETURN(iBase_SUCCESS);
 }
@@ -373,11 +376,11 @@
                               int* num_partitions_out,
                               int* err )
 {
-  std::vector<MBParallelComm*> pcomms;
-  MBErrorCode rval = MBParallelComm::get_all_pcomm( MBI, pcomms );
+  std::vector<ParallelComm*> pcomms;
+  ErrorCode rval = ParallelComm::get_all_pcomm( MBI, pcomms );
   CHKERR(rval,"Internal error retreiving PComms");
   
-  std::vector<MBParallelComm*>::iterator i;
+  std::vector<ParallelComm*>::iterator i;
   *num_partitions_out = 0;
   for (i = pcomms.begin(); i != pcomms.end(); ++i)
     if ((*i)->get_partitioning())
@@ -392,11 +395,11 @@
                            int *partition_handle_size, 
                            int *err )
 {
-  std::vector<MBParallelComm*> pcomms;
-  MBErrorCode rval = MBParallelComm::get_all_pcomm( MBI, pcomms );
+  std::vector<ParallelComm*> pcomms;
+  ErrorCode rval = ParallelComm::get_all_pcomm( MBI, pcomms );
   CHKERR(rval,"Internal error retreiving PComms");
   
-  std::vector<MBParallelComm*>::iterator i;
+  std::vector<ParallelComm*>::iterator i;
   int count = 0;
   for (i = pcomms.begin(); i != pcomms.end(); ++i)
     if ((*i)->get_partitioning())
@@ -417,11 +420,11 @@
                                int *num_global_part, 
                                int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBErrorCode rval = pcomm->get_global_part_count( *num_global_part );
+  ErrorCode rval = pcomm->get_global_part_count( *num_global_part );
   CHKERR (rval,"PComm::get_global_part_count failed");
   RETURN(iBase_SUCCESS);
 }
@@ -431,7 +434,7 @@
                           int *num_local_part, 
                           int *err)
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
   
@@ -446,11 +449,11 @@
                            int *part_handles_size,
                            int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBRANGE_TO_ITAPS_ARRAY( pcomm->partition_sets(), part_handles );
+  RANGE_TO_ITAPS_ARRAY( pcomm->partition_sets(), part_handles );
   RETURN (iBase_SUCCESS);
 }
 
@@ -474,12 +477,12 @@
                               int *rank_size,
                               int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
   ALLOC_CHECK_ARRAY( rank, part_ids_size );
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   for (int i = 0; i < part_ids_size; ++i) {
     rval = pcomm->get_part_owner( part_ids[i], (*rank)[i] );
     CHKERR(rval,"PComm::get_part_owner failed");
@@ -495,13 +498,13 @@
                              int *num_type, 
                              int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBRange entities;
-  MBErrorCode rval = get_entities( MBI,
-                                   itaps_cast<MBEntityHandle>(entity_set_handle),
+  Range entities;
+  ErrorCode rval = get_entities( MBI,
+                                   itaps_cast<EntityHandle>(entity_set_handle),
                                    entity_type,
                                    iMesh_ALL_TOPOLOGIES,
                                    entities );
@@ -526,13 +529,13 @@
                              int *num_topo, 
                              int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBRange entities;
-  MBErrorCode rval = get_entities( MBI,
-                                   itaps_cast<MBEntityHandle>(entity_set_handle),
+  Range entities;
+  ErrorCode rval = get_entities( MBI,
+                                   itaps_cast<EntityHandle>(entity_set_handle),
                                    iBase_ALL_TYPES,
                                    entity_topology,
                                    entities );
@@ -555,12 +558,12 @@
                         iMeshP_PartHandle *part_handle,
                         int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBEntityHandle h;
-  MBErrorCode rval = pcomm->create_part( h );
+  EntityHandle h;
+  ErrorCode rval = pcomm->create_part( h );
   CHKERR(rval,"Part creation failed");
   *part_handle = itaps_cast<iMeshP_PartHandle>(h);
 }
@@ -570,11 +573,11 @@
                          iMeshP_PartHandle part_handle,
                          int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm)
     ERROR (iBase_FAILURE,"No PComm");
   
-  MBErrorCode rval = pcomm->destroy_part( itaps_cast<MBEntityHandle>(part_handle) );
+  ErrorCode rval = pcomm->destroy_part( itaps_cast<EntityHandle>(part_handle) );
   CHKERR(rval,"Part destruction failed");
   RETURN(iBase_SUCCESS);
 }
@@ -603,16 +606,16 @@
                                 int *num_part_nbors_size,
                                 int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   ALLOC_CHECK_ARRAY( num_part_nbors, part_handles_size );
   
   int n, neighbors[MAX_SHARING_PROCS];
-  MBErrorCode rval;
+  ErrorCode rval;
   for (int i = 0; i < part_handles_size; ++i) {
-    MBEntityHandle h = itaps_cast<MBEntityHandle>(part_handles[i]);
+    EntityHandle h = itaps_cast<EntityHandle>(part_handles[i]);
     rval = pcomm->get_part_neighbor_ids( h, neighbors, n ); 
     CHKERR(rval,"error getting neighbor ids");
     (*num_part_nbors)[i] = n;
@@ -654,7 +657,7 @@
                              int *nbor_part_ids_size,
                              int *err ) 
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
@@ -662,9 +665,9 @@
   
   std::vector<int> all_neighbors;
   int n, pnbor[MAX_SHARING_PROCS];
-  MBErrorCode rval;
+  ErrorCode rval;
   for (int i = 0; i < part_handles_size; ++i) {
-    MBEntityHandle h = itaps_cast<MBEntityHandle>(part_handles[i]);
+    EntityHandle h = itaps_cast<EntityHandle>(part_handles[i]);
     rval = pcomm->get_part_neighbor_ids( h, pnbor, n ); 
     CHKERR(rval,"error getting neighbor ids");
     (*num_part_nbors)[i] = n;
@@ -678,23 +681,23 @@
   RETURN(iBase_SUCCESS);
 }
 
-static MBErrorCode get_boundary_entities( MBParallelComm* pcomm,
-                                   MBEntityHandle part_handle,
+static ErrorCode get_boundary_entities( ParallelComm* pcomm,
+                                   EntityHandle part_handle,
                                    int entity_type,
                                    int entity_topology,
                                    int adj_part_id,
-                                   MBRange& entities_out)
+                                   Range& entities_out)
 {
   int* adj_part_id_ptr = (adj_part_id == iMeshP_ALL_PARTS) ? 0 : &adj_part_id;
   
-  MBRange iface_sets;
-  MBErrorCode rval = pcomm->get_interface_sets( 
-                         itaps_cast<MBEntityHandle>(part_handle),
+  Range iface_sets;
+  ErrorCode rval = pcomm->get_interface_sets( 
+                         itaps_cast<EntityHandle>(part_handle),
                          iface_sets, adj_part_id_ptr ); 
   if (MB_SUCCESS != rval)
     return rval;
   
-  for (MBRange::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
+  for (Range::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
     rval = get_entities( pcomm->get_moab(), *i, entity_type, entity_topology, entities_out );
     if (MB_SUCCESS != rval)
       return rval;
@@ -712,9 +715,9 @@
                                 int *num_entities, 
                                 int *err )
 {
-  MBRange entities;
-  MBErrorCode rval = get_boundary_entities( PCOMM,
-                                            itaps_cast<MBEntityHandle>(part_handle),
+  Range entities;
+  ErrorCode rval = get_boundary_entities( PCOMM,
+                                            itaps_cast<EntityHandle>(part_handle),
                                             entity_type,
                                             entity_topology,
                                             target_part_id,
@@ -735,15 +738,15 @@
                              int *entity_handles_size,
                              int *err )
 {
-  MBRange entities;
-  MBErrorCode rval = get_boundary_entities( PCOMM,
-                                            itaps_cast<MBEntityHandle>(part_handle),
+  Range entities;
+  ErrorCode rval = get_boundary_entities( PCOMM,
+                                            itaps_cast<EntityHandle>(part_handle),
                                             entity_type,
                                             entity_topology,
                                             target_part_id,
                                             entities );
   CHKERR(rval,"failed to get boundary entities");
-  MBRANGE_TO_ITAPS_ARRAY( entities, entity_handles );
+  RANGE_TO_ITAPS_ARRAY( entities, entity_handles );
   RETURN(iBase_SUCCESS);
 }
 
@@ -756,9 +759,9 @@
                                  iMesh_EntityIterator* entity_iterator,
                                  int* err )
 {
-  MBRange entities;
-  MBErrorCode rval = get_boundary_entities( PCOMM,
-                                            itaps_cast<MBEntityHandle>(part_handle),
+  Range entities;
+  ErrorCode rval = get_boundary_entities( PCOMM,
+                                            itaps_cast<EntityHandle>(part_handle),
                                             entity_type,
                                             entity_topology,
                                             nbor_part_id,
@@ -778,9 +781,9 @@
                                     iMesh_EntityArrIterator* entity_iterator,
                                     int* err )
 {
-  MBRange entities;
-  MBErrorCode rval = get_boundary_entities( PCOMM,
-                                            itaps_cast<MBEntityHandle>(part_handle),
+  Range entities;
+  ErrorCode rval = get_boundary_entities( PCOMM,
+                                            itaps_cast<EntityHandle>(part_handle),
                                             entity_type,
                                             entity_topology,
                                             nbor_part_id,
@@ -800,7 +803,7 @@
                           int *num_type,
                           int *err )
 {
-  MBRange r;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle, 
                           entity_type, iMesh_ALL_TOPOLOGIES, r, err );
   *num_type = r.size();
@@ -814,7 +817,7 @@
                           int *num_topo,
                           int *err )
 {
-  MBRange r;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle, 
                           iBase_ALL_TYPES, entity_topology, r, err );
   *num_topo = r.size();
@@ -977,13 +980,13 @@
                          int* entity_handles_size,
                          int *err )
 {
-  MBRange r;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle, 
                           entity_type, entity_topology, r, err );
   if (iBase_SUCCESS != *err)
     return;
   
-  MBRANGE_TO_ITAPS_ARRAY( r, entity_handles );
+  RANGE_TO_ITAPS_ARRAY( r, entity_handles );
   RETURN(iBase_SUCCESS);
 }
 
@@ -1005,8 +1008,8 @@
                             int* in_entity_set_size,
                             int *err )
 {
-  MBErrorCode rval;
-  MBRange r;
+  ErrorCode rval;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle,
                            entity_type_requestor, entity_topology_requestor,
                            r, err );
@@ -1014,11 +1017,11 @@
     return;
   
     // count adjacencies
-  std::vector<MBEntityHandle> tmp_storage;
+  std::vector<EntityHandle> tmp_storage;
   int num_adj = 0;
   int num_conn;
-  const MBEntityHandle* conn_ptr;
-  for (MBRange::iterator i = r.begin(); i != r.end(); ++i)  {
+  const EntityHandle* conn_ptr;
+  for (Range::iterator i = r.begin(); i != r.end(); ++i)  {
     if (entity_type_requested || TYPE_FROM_HANDLE(*i) == MBPOLYHEDRON) {
       tmp_storage.clear();
       rval = MBI->get_adjacencies( &*i, 1, entity_type_requested, false, tmp_storage );
@@ -1037,14 +1040,14 @@
   ALLOC_CHECK_ARRAY( offset, r.size() );
   int arr_pos = 0;
   int* offset_iter = *offset;
-  for (MBRange::iterator i = r.begin(); i != r.end(); ++i)  {
+  for (Range::iterator i = r.begin(); i != r.end(); ++i)  {
     *offset_iter = arr_pos; 
     ++offset_iter;
 
     tmp_storage.clear();
     rval = MBI->get_adjacencies( &*i, 1, entity_type_requested, false, tmp_storage );
     CHKERR(rval,"get_adjacencies failed");
-    for (std::vector<MBEntityHandle>::iterator j = tmp_storage.begin(); j != tmp_storage.end(); ++j) {
+    for (std::vector<EntityHandle>::iterator j = tmp_storage.begin(); j != tmp_storage.end(); ++j) {
       (*adj_entity_handles)[arr_pos] = itaps_cast<iBase_EntityHandle>(*j);
       ++arr_pos;
     }
@@ -1075,7 +1078,7 @@
                          iMesh_EntityIterator* entity_iterator,
                          int *err )
 {
-  MBRange r;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle,
                            requested_entity_type, requested_entity_topology,
                            r, err );
@@ -1096,7 +1099,7 @@
                             iMesh_EntityArrIterator* entArr_iterator,
                             int *err )
 {
-  MBRange r;
+  Range r;
   set_intersection_query( instance, part_handle, entity_set_handle,
                            requested_entity_type, requested_entity_topology,
                            r, err );
@@ -1127,15 +1130,15 @@
                                 int *part_ids_size,
                                 int* err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
   
   int id;
   ALLOC_CHECK_ARRAY( part_ids, entity_handles_size );
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   for (int i = 0; i < entity_handles_size; ++i) {
-    MBEntityHandle h = itaps_cast<MBEntityHandle>(entity_handles[i]);
+    EntityHandle h = itaps_cast<EntityHandle>(entity_handles[i]);
     rval = pcomm->get_owning_part( h, id );
     (*part_ids)[i] = id;
     CHKERR(rval,"Failet get part owner");
@@ -1168,13 +1171,13 @@
                            int* is_owner_size,
                            int *err )
 {
-  MBErrorCode rval;
-  MBParallelComm* pcomm = PCOMM;
+  ErrorCode rval;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
   
   int id;
-  rval = pcomm->get_part_id( itaps_cast<MBEntityHandle>(part_handle), id );
+  rval = pcomm->get_part_id( itaps_cast<EntityHandle>(part_handle), id );
   CHKERR(rval,"error getting part id");
   
   ALLOC_CHECK_ARRAY( is_owner, entity_handles_size );
@@ -1182,7 +1185,7 @@
   
   int owner;
   for (int i = 0; i < entity_handles_size; ++i) {
-    rval = pcomm->get_owner( itaps_cast<MBEntityHandle>(entity_handles[i]), owner );
+    rval = pcomm->get_owner( itaps_cast<EntityHandle>(entity_handles[i]), owner );
     CHKERR(rval,"error getting owner");
     (*is_owner)[i] = (owner == id);
   }
@@ -1215,13 +1218,13 @@
                             /*inout*/ int* par_status_size, 
                             int *err) 
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   std::vector<unsigned char> pstatus(entity_handles_size);
-  MBErrorCode result = MBI->tag_get_data(pcomm->pstatus_tag(), 
-                                         itaps_cast<const MBEntityHandle*>(entity_handles), 
+  ErrorCode result = MBI->tag_get_data(pcomm->pstatus_tag(), 
+                                         itaps_cast<const EntityHandle*>(entity_handles), 
                                          entity_handles_size,
                                          &pstatus[0]); 
   CHKERR(result,"error getting pstatus_tag");
@@ -1246,15 +1249,15 @@
                           int *num_copies_ent,
                           int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   int ids[MAX_SHARING_PROCS];
-  MBErrorCode rval = pcomm->get_sharing_parts( 
-                              itaps_cast<MBEntityHandle>(entity_handle),
+  ErrorCode rval = pcomm->get_sharing_parts( 
+                              itaps_cast<EntityHandle>(entity_handle),
                               ids, *num_copies_ent );
-  CHKERR(rval,"MBParallelComm::get_sharing_parts failed");
+  CHKERR(rval,"ParallelComm::get_sharing_parts failed");
   RETURN(iBase_SUCCESS);
 }
 
@@ -1266,15 +1269,15 @@
                           int *part_ids_size,
                           int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   int ids[MAX_SHARING_PROCS], num_ids;
-  MBErrorCode rval = pcomm->get_sharing_parts( 
-                              itaps_cast<MBEntityHandle>(entity_handle),
+  ErrorCode rval = pcomm->get_sharing_parts( 
+                              itaps_cast<EntityHandle>(entity_handle),
                               ids, num_ids ); 
-  CHKERR(rval,"MBParallelComm::get_sharing_parts failed");
+  CHKERR(rval,"ParallelComm::get_sharing_parts failed");
   ALLOC_CHECK_ARRAY_NOFAIL( part_ids, num_ids );
   std::copy( ids, ids+num_ids, *part_ids );
   RETURN (iBase_SUCCESS);
@@ -1293,16 +1296,16 @@
                        int *copies_entity_handles_size, 
                        int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   int ids[MAX_SHARING_PROCS], num_ids;
-  MBEntityHandle handles[MAX_SHARING_PROCS];
-  MBErrorCode rval = pcomm->get_sharing_parts( 
-                              itaps_cast<MBEntityHandle>(entity_handle),
+  EntityHandle handles[MAX_SHARING_PROCS];
+  ErrorCode rval = pcomm->get_sharing_parts( 
+                              itaps_cast<EntityHandle>(entity_handle),
                               ids, num_ids, handles ); 
-  CHKERR(rval,"MBParallelComm::get_sharing_parts failed");
+  CHKERR(rval,"ParallelComm::get_sharing_parts failed");
   ALLOC_CHECK_ARRAY_NOFAIL( part_ids, num_ids );
   ALLOC_CHECK_ARRAY_NOFAIL( copies_entity_handles, num_ids );
   for (int i = 0; i < num_ids; ++i) {
@@ -1319,16 +1322,16 @@
                            iBase_EntityHandle* copy_entity_handle,
                            int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   int ids[MAX_SHARING_PROCS], num_ids;
-  MBEntityHandle handles[MAX_SHARING_PROCS];
-  MBErrorCode rval = pcomm->get_sharing_parts( 
-                              itaps_cast<MBEntityHandle>(entity_handle),
+  EntityHandle handles[MAX_SHARING_PROCS];
+  ErrorCode rval = pcomm->get_sharing_parts( 
+                              itaps_cast<EntityHandle>(entity_handle),
                               ids, num_ids, handles ); 
-  CHKERR(rval,"MBParallelComm::get_sharing_parts failed");
+  CHKERR(rval,"ParallelComm::get_sharing_parts failed");
   int idx = std::find( ids, ids+num_ids, part_id ) - ids;
   if (idx == num_ids)
     RETURN (iBase_FAILURE);
@@ -1345,14 +1348,14 @@
                           iBase_EntityHandle *owner_entity_handle,
                           int *err )
 { 
-  MBParallelComm* pcomm = PCOMM;
+  ParallelComm* pcomm = PCOMM;
   if (!pcomm) 
     ERROR (iBase_FAILURE,"No PComm");
 
   int id;
-  MBEntityHandle h;
-  MBErrorCode rval = pcomm->get_owning_part( 
-                          itaps_cast<MBEntityHandle>(entity_handle),
+  EntityHandle h;
+  ErrorCode rval = pcomm->get_owning_part( 
+                          itaps_cast<EntityHandle>(entity_handle),
                           id, &h );  
   CHKERR(rval,"Failed to get owner");
   *owner_part_id = id;
@@ -1456,10 +1459,10 @@
                          int *err )
 {
   FIXME; // for now we only sync vertex coordinates
-         // need to update MBParallelComm::update_shared_mesh to fix this
+         // need to update ParallelComm::update_shared_mesh to fix this
   
-  MBParallelComm* pcomm = PCOMM;
-  MBErrorCode rval = pcomm->update_shared_mesh();
+  ParallelComm* pcomm = PCOMM;
+  ErrorCode rval = pcomm->update_shared_mesh();
   CHKERR(rval,"update failed");
   RETURN (iBase_SUCCESS);
 }
@@ -1472,8 +1475,8 @@
                       int entity_topo,
                       int *err )
 {
-  MBParallelComm* pcomm = PCOMM;
-  MBDimensionPair types;
+  ParallelComm* pcomm = PCOMM;
+  DimensionPair types;
   if (entity_topo != iMesh_ALL_TOPOLOGIES)
     types.first = types.second = mb_topology_table[entity_topo];
   else if (entity_type != iBase_ALL_TYPES)
@@ -1484,14 +1487,14 @@
     --types.second; 
   }
   
-  std::vector<MBTag> src_tags(1, itaps_cast<MBTag>(source_tag));
-  std::vector<MBTag> dst_tags(1, itaps_cast<MBTag>(dest_tag));
+  std::vector<Tag> src_tags(1, itaps_cast<Tag>(source_tag));
+  std::vector<Tag> dst_tags(1, itaps_cast<Tag>(dest_tag));
   
-  MBErrorCode rval;
-  MBRange entities;
-  for (MBEntityType t = types.first; t <= types.second; ++t) {
+  ErrorCode rval;
+  Range entities;
+  for (EntityType t = types.first; t <= types.second; ++t) {
     rval = MBI->get_entities_by_type_and_tag( 0, t, &src_tags[0], 0, 1, 
-                                              entities, MBInterface::UNION );
+                                              entities, Interface::UNION );
     CHKERR(rval,"error getting entities to push");
   }
   
@@ -1509,14 +1512,14 @@
                          int *err )
 {
 
-  MBRange range;
-  const MBEntityHandle* ents = itaps_cast<const MBEntityHandle*>(entities);
-  std::copy( ents, ents+entities_size, mb_range_inserter(range) );
+  Range range;
+  const EntityHandle* ents = itaps_cast<const EntityHandle*>(entities);
+  std::copy( ents, ents+entities_size, range_inserter(range) );
   
-  std::vector<MBTag> src_tags(1, itaps_cast<MBTag>(source_tag));
-  std::vector<MBTag> dst_tags(1, itaps_cast<MBTag>(dest_tag));
-  MBParallelComm* pcomm = PCOMM;
-  MBErrorCode rval = pcomm->exchange_tags( src_tags, dst_tags, range );
+  std::vector<Tag> src_tags(1, itaps_cast<Tag>(source_tag));
+  std::vector<Tag> dst_tags(1, itaps_cast<Tag>(dest_tag));
+  ParallelComm* pcomm = PCOMM;
+  ErrorCode rval = pcomm->exchange_tags( src_tags, dst_tags, range );
   CHKERR(rval,"tag data communication failed");
   RETURN (iBase_SUCCESS);
 }
@@ -1553,8 +1556,8 @@
     FIXME; RETURN(iBase_NOT_SUPPORTED);
   }
   
-  MBParallelComm* pcomm = PCOMM;
-  MBErrorCode rval;
+  ParallelComm* pcomm = PCOMM;
+  ErrorCode rval;
   rval = pcomm->exchange_ghost_cells( ghost_dim, bridge_dim, num_layers, true );
   CHKERR(rval,"ghost exchange failed");
   RETURN(iBase_SUCCESS);
@@ -1637,21 +1640,21 @@
                   int name_len,
                   int options_len )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // create partition set if user didn't give us one.
-  MBEntityHandle partitioning;
+  EntityHandle partitioning;
   if (partition) {
-    partitioning = itaps_cast<MBEntityHandle>(partition);
+    partitioning = itaps_cast<EntityHandle>(partition);
   }
   else {
     rval = MBI->create_meshset( MESHSET_SET, partitioning );
     CHKERR(rval,"failed to create meshset");
   }
   
-    // get MBParallelComm for partition
+    // get ParallelComm for partition
   MPI_Comm default_comm = MPI_COMM_WORLD;
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, partitioning, &default_comm );
+  ParallelComm* pcomm = ParallelComm::get_pcomm( MBI, partitioning, &default_comm );
   if (!pcomm) {
     RETURN (iBase_FAILURE);
   }
@@ -1683,9 +1686,9 @@
                   const int name_len,
                   int options_len )
 {
-  MBEntityHandle set;
-  set = entity_set_handle ? itaps_cast<MBEntityHandle>(entity_set_handle)
-                          : itaps_cast<MBEntityHandle>(partition);
+  EntityHandle set;
+  set = entity_set_handle ? itaps_cast<EntityHandle>(entity_set_handle)
+                          : itaps_cast<EntityHandle>(partition);
   iMesh_save( instance, itaps_cast<iBase_EntitySetHandle>(set), 
               name, options, err, name_len, options_len );
 
@@ -1706,14 +1709,14 @@
                              /*out*/   int *part_handles_size, 
                              int *err) 
   {
-    MBEntityHandle p = itaps_cast<MBEntityHandle>(partition_handle);
-    MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, p);
+    EntityHandle p = itaps_cast<EntityHandle>(partition_handle);
+    ParallelComm *pc = ParallelComm::get_pcomm(MBI, p);
     if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
 
-    MBRange part_sets;
+    Range part_sets;
   
     ALLOC_CHECK_ARRAY_NOFAIL( part_handles, pc->partition_sets().size() );
-    MBRange::iterator rit;
+    Range::iterator rit;
     int i;
     for (i = 0, rit = pc->partition_sets().begin(); 
          rit != pc->partition_sets().end(); rit++, i++)
@@ -1731,8 +1734,8 @@
                                 /*out*/   int *part_handles_size, 
                                 int *err) 
   {
-    MBEntityHandle p = itaps_cast<MBEntityHandle>(partition_handle);
-    MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, p);
+    EntityHandle p = itaps_cast<EntityHandle>(partition_handle);
+    ParallelComm *pc = ParallelComm::get_pcomm(MBI, p);
     if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
 
     if (rank[0] != (int)pc->proc_config().proc_rank() || rank_size > 1) {

Modified: MOAB/trunk/itaps/imesh/iMeshP_unit_tests.cpp
===================================================================
--- MOAB/trunk/itaps/imesh/iMeshP_unit_tests.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/iMeshP_unit_tests.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,5 +1,5 @@
 #include "iMeshP.h"
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include <iostream>
 #include <algorithm>
 #include <vector>

Modified: MOAB/trunk/itaps/imesh/iMesh_MOAB.cpp
===================================================================
--- MOAB/trunk/itaps/imesh/iMesh_MOAB.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/iMesh_MOAB.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,16 +1,16 @@
 #include "iMesh_extensions.h"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "FileOptions.hpp"
 #include "iMesh_MOAB.hpp"
 #define IS_BUILDING_MB
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #undef IS_BUILDING_MB
 
 #ifdef USE_MPI    
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #endif
 
 #include <iostream>
@@ -30,34 +30,34 @@
 
 MBiMesh::~MBiMesh() {}
 
-MBErrorCode MBiMesh::delete_mesh() {
+ErrorCode MBiMesh::delete_mesh() {
   haveDeletedEntities = true;
-  return MBCore::delete_mesh();
+  return Core::delete_mesh();
 }
 
-MBErrorCode MBiMesh::delete_entities( const MBEntityHandle* a, const int n )
+ErrorCode MBiMesh::delete_entities( const EntityHandle* a, const int n )
 {
   if (n > 0)
     haveDeletedEntities = true;
-  return MBCore::delete_entities( a, n );
+  return Core::delete_entities( a, n );
 }
 
-MBErrorCode MBiMesh::delete_entities( const MBRange& r )
+ErrorCode MBiMesh::delete_entities( const Range& r )
 {
   if (!r.empty())
     haveDeletedEntities = true;
-  return MBCore::delete_entities( r );
+  return Core::delete_entities( r );
 }
 
-MBErrorCode create_int_ents(MBInterface *instance,
-                            MBRange &from_ents,
-                            const MBEntityHandle* in_set = 0);
-#define HANDLE_ARRAY_PTR(array) reinterpret_cast<MBEntityHandle*>(array)
-#define CONST_HANDLE_ARRAY_PTR(array) reinterpret_cast<const MBEntityHandle*>(array)
-#define TAG_HANDLE(handle) reinterpret_cast<MBTag>(handle)
-#define CONST_TAG_HANDLE(handle) static_cast<const MBTag>(handle)
-#define ENTITY_HANDLE(handle) reinterpret_cast<MBEntityHandle>(handle)
-#define CONST_ENTITY_HANDLE(handle) reinterpret_cast<const MBEntityHandle>(handle)
+ErrorCode create_int_ents(Interface *instance,
+                            Range &from_ents,
+                            const EntityHandle* in_set = 0);
+#define HANDLE_ARRAY_PTR(array) reinterpret_cast<EntityHandle*>(array)
+#define CONST_HANDLE_ARRAY_PTR(array) reinterpret_cast<const EntityHandle*>(array)
+#define TAG_HANDLE(handle) reinterpret_cast<Tag>(handle)
+#define CONST_TAG_HANDLE(handle) static_cast<const Tag>(handle)
+#define ENTITY_HANDLE(handle) reinterpret_cast<EntityHandle>(handle)
+#define CONST_ENTITY_HANDLE(handle) reinterpret_cast<const EntityHandle>(handle)
 #define RANGE_ITERATOR(it) reinterpret_cast<RangeIterator*>(it)
 #define CAST_TO_VOID(ptr) reinterpret_cast<void*>(ptr)
 
@@ -98,7 +98,7 @@
 };
 
 // map to MB's entity type from TSTT's entity topology
-const MBEntityType mb_topology_table[] =
+const EntityType mb_topology_table[] =
 {
   MBVERTEX,
   MBEDGE,
@@ -115,7 +115,7 @@
 };
 
 // map from TSTT's tag types to MOAB's
-const MBDataType mb_data_type_table[] = 
+const DataType mb_data_type_table[] = 
 {
   MB_TYPE_INTEGER,
   MB_TYPE_DOUBLE ,
@@ -155,12 +155,12 @@
 
 struct RangeIterator
 {
-  MBRange iteratorRange;
-  MBRange::iterator currentPos;
+  Range iteratorRange;
+  Range::iterator currentPos;
   int requestedSize;
 };
 
-iMesh_EntityIterator create_itaps_iterator( MBRange& range, int array_size )
+iMesh_EntityIterator create_itaps_iterator( Range& range, int array_size )
 {
   RangeIterator* iter = new RangeIterator;
   if (iter) {
@@ -177,11 +177,11 @@
 
   void eatwhitespace(std::string &this_string);
 
-  MBErrorCode iMesh_tag_set_vertices(iMesh_Instance instance,
-                                     MBEntityHandle in_set, 
+  ErrorCode iMesh_tag_set_vertices(iMesh_Instance instance,
+                                     EntityHandle in_set, 
                                      const int req_dimension, 
-                                     const MBEntityType req_type,
-                                     MBTag &tag, MBRange &req_entities, 
+                                     const EntityType req_type,
+                                     Tag &tag, Range &req_entities, 
                                      int &num_verts, int *err);
 
   iBase_Error iMesh_LAST_ERROR;
@@ -226,9 +226,9 @@
     eatwhitespace(tmp_options);
     FileOptions opts((std::string(";") + tmp_options).c_str());
 
-    MBInterface* core;
+    Interface* core;
 
-    MBErrorCode result = opts.get_null_option("PARALLEL");
+    ErrorCode result = opts.get_null_option("PARALLEL");
     if (MB_SUCCESS == result) {
 #ifdef USE_MPI    
       int flag = 1;
@@ -278,14 +278,14 @@
     eatwhitespace(tmp_options);
     std::string opts = ";"; opts += tmp_options;
   
-    MBRange orig_ents;
-    MBErrorCode result = MBI->get_entities_by_handle( 0, orig_ents );
+    Range orig_ents;
+    ErrorCode result = MBI->get_entities_by_handle( 0, orig_ents );
     CHKERR(result,"Internal error");
   
-    const MBEntityHandle* file_set = 0;
+    const EntityHandle* file_set = 0;
     if (handle != 0 /*root_set*/) {
       const iBase_EntitySetHandle* ptr = &handle;
-      file_set = reinterpret_cast<const MBEntityHandle*>(ptr);
+      file_set = reinterpret_cast<const EntityHandle*>(ptr);
     }
   
     result = MBI->load_file(tmp_filename.c_str(), file_set, opts.c_str());
@@ -294,7 +294,7 @@
 
       // create interior edges/faces if requested
     if (MBimesh->AdjTable[5] || MBimesh->AdjTable[10]) {
-      MBRange set_ents;
+      Range set_ents;
       result = MBI->get_entities_by_handle(0, set_ents);
       CHKERR(result,"");
       set_ents = subtract( set_ents, orig_ents );
@@ -317,8 +317,8 @@
     eatwhitespace(tmp_options);
     std::string opts = ";"; opts += tmp_options;
 
-    MBEntityHandle set = ENTITY_HANDLE(handle);
-    MBErrorCode result = MBI->write_file(tmp_filename.c_str(), NULL, opts.c_str(),
+    EntityHandle set = ENTITY_HANDLE(handle);
+    ErrorCode result = MBI->write_file(tmp_filename.c_str(), NULL, opts.c_str(),
                                          &set, 1);
 
     CHKERR(result, "iMesh_save:ERROR saving a mesh.");
@@ -344,7 +344,7 @@
   void iMesh_setGeometricDimension(iMesh_Instance instance,
                                    int geom_dim, int *err)
   {
-    MBErrorCode rval = MBI->set_dimension(geom_dim);
+    ErrorCode rval = MBI->set_dimension(geom_dim);
     CHKERR(rval,"iMesh_setGeometricDimension: failed");
   }
 
@@ -439,7 +439,7 @@
   
       // now get all the coordinates
       // coords will come back interleaved by default
-    MBErrorCode result;
+    ErrorCode result;
     if (storage_order == iBase_INTERLEAVED) {
       result = MBI->get_coords(CONST_HANDLE_ARRAY_PTR(vertex_handles), 
                                vertex_handles_size, *coords);
@@ -479,11 +479,11 @@
                              /*out*/ iMesh_EntityArrIterator* entArr_iterator,
                              int *err) 
   {
-    MBEntityType req_type = mb_topology_table[requested_entity_topology];
+    EntityType req_type = mb_topology_table[requested_entity_topology];
     int req_dimension = (req_type == MBMAXTYPE ? (int) requested_entity_type : -1);
-    MBRange range;
+    Range range;
   
-    MBErrorCode result;
+    ErrorCode result;
     if (requested_entity_type == iBase_ALL_TYPES &&
         requested_entity_topology == iMesh_ALL_TOPOLOGIES)
       result = MBI->get_entities_by_handle( ENTITY_HANDLE(entity_set_handle),
@@ -608,21 +608,21 @@
                           /*inout*/ int* offset_allocated,
                           /*out*/ int* offset_size, int *err) 
   {
-    MBErrorCode result = MB_SUCCESS;
+    ErrorCode result = MB_SUCCESS;
 
     ALLOC_CHECK_ARRAY(offset, entity_handles_size+1);
   
-    const MBEntityHandle* entity_iter = (const MBEntityHandle*)entity_handles;
-    const MBEntityHandle* const entity_end = entity_iter + entity_handles_size;
+    const EntityHandle* entity_iter = (const EntityHandle*)entity_handles;
+    const EntityHandle* const entity_end = entity_iter + entity_handles_size;
     int* off_iter = *offset;
     int prev_off = 0;
   
-    std::vector<MBEntityHandle> conn_storage;
-    std::vector<MBEntityHandle> adj_ents;
-    const MBEntityHandle *connect;
+    std::vector<EntityHandle> conn_storage;
+    std::vector<EntityHandle> adj_ents;
+    const EntityHandle *connect;
     int num_connect;
     
-    MBEntityHandle* array; // ptr to working array of result handles
+    EntityHandle* array; // ptr to working array of result handles
     int array_alloc;       // allocated size of 'array'
     const bool allocated_array = !*adjacentEntityHandles_allocated || !*adjacentEntityHandles;
     if (allocated_array) {
@@ -630,7 +630,7 @@
       array_alloc = 0;
     }
     else {
-      array = reinterpret_cast<MBEntityHandle*>(*adjacentEntityHandles);
+      array = reinterpret_cast<EntityHandle*>(*adjacentEntityHandles);
       array_alloc = *adjacentEntityHandles_allocated;
     }
     
@@ -653,7 +653,7 @@
         for (int dim = 0; dim < 4; ++dim) {
           if (MBCN::Dimension(TYPE_FROM_HANDLE(*entity_iter)) == dim)
             continue;
-          result = MBI->get_adjacencies( entity_iter, 1, dim, false, adj_ents, MBInterface::UNION );
+          result = MBI->get_adjacencies( entity_iter, 1, dim, false, adj_ents, Interface::UNION );
           if (MB_SUCCESS != result) {
             if (allocated_array)
               free(array);
@@ -690,7 +690,7 @@
           array_alloc = entity_handles_size * num_connect;
         else
           array_alloc = std::max(array_alloc*2, prev_off+num_connect);  
-        array = (MBEntityHandle*)realloc( array, array_alloc*sizeof(MBEntityHandle) );
+        array = (EntityHandle*)realloc( array, array_alloc*sizeof(EntityHandle) );
         if (!array) {
           RETURN(iBase_MEMORY_ALLOCATION_FAILED);
         }
@@ -730,23 +730,23 @@
                               int* offset_size,
                               int* err )
   {
-    MBErrorCode result = MB_SUCCESS;
+    ErrorCode result = MB_SUCCESS;
 
     ALLOC_CHECK_ARRAY(offset, entity_handles_size+1 );
   
-    const MBEntityHandle* entity_iter = (const MBEntityHandle*)entity_handles;
-    const MBEntityHandle* const entity_end = entity_iter + entity_handles_size;
+    const EntityHandle* entity_iter = (const EntityHandle*)entity_handles;
+    const EntityHandle* const entity_end = entity_iter + entity_handles_size;
     int* off_iter = *offset;
     int prev_off = 0;
   
-    std::vector<MBEntityHandle> all_adj_ents;
+    std::vector<EntityHandle> all_adj_ents;
     MeshTopoUtil mtu(MBI);
     
     for ( ; entity_iter != entity_end; ++entity_iter)
     {
       *off_iter = prev_off;
       off_iter++;
-      MBRange adj_ents;
+      Range adj_ents;
 
       result = mtu.get_bridge_adjacencies( *entity_iter,
                                            order_adjacent_key,
@@ -760,7 +760,7 @@
 
     ALLOC_CHECK_ARRAY_NOFAIL(adj_entity_handles, all_adj_ents.size() );
     memcpy(*adj_entity_handles, &all_adj_ents[0], 
-           sizeof(MBEntityHandle)*all_adj_ents.size() );
+           sizeof(EntityHandle)*all_adj_ents.size() );
 
     KEEP_ARRAY(offset);
     RETURN(iBase_SUCCESS);
@@ -915,8 +915,8 @@
                           /*out*/ iBase_EntitySetHandle* entity_set_created, int *err) 
   {
       // create the entity set
-    MBEntityHandle meshset;
-    MBErrorCode result;
+    EntityHandle meshset;
+    ErrorCode result;
 
     if (isList)
       result = MBI->create_meshset(MESHSET_ORDERED, meshset);
@@ -933,8 +933,8 @@
   void iMesh_destroyEntSet (iMesh_Instance instance,
                             /*in*/ iBase_EntitySetHandle entity_set, int *err) 
   {
-    MBEntityHandle set = ENTITY_HANDLE(entity_set);
-    MBErrorCode result = MBI->delete_entities(&set, 1);
+    EntityHandle set = ENTITY_HANDLE(entity_set);
+    ErrorCode result = MBI->delete_entities(&set, 1);
     CHKERR(result, "iMesh_destroyEntSet: couldn't delete the set.");
 
     RETURN(iBase_SUCCESS);
@@ -945,7 +945,7 @@
                      int *is_list, int *err) 
   {
     unsigned int options;
-    MBErrorCode result = MBI->get_meshset_options(ENTITY_HANDLE(entity_set), options);
+    ErrorCode result = MBI->get_meshset_options(ENTITY_HANDLE(entity_set), options);
     CHKERR(result,"iMesh_isList: couldn't query set.");
     if (options & MESHSET_ORDERED)
       *is_list = true;
@@ -959,7 +959,7 @@
                            /*in*/ const int num_hops,
                            int *num_sets, int *err) 
   {
-    MBErrorCode rval = MBI->num_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
+    ErrorCode rval = MBI->num_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
                                                     num_sets,
                                                     std::max(0,num_hops) );
     CHKERR(rval, "iMesh_entitysetGetNumberEntitySets:ERROR getting number of entitysets.");
@@ -974,14 +974,14 @@
                         /*inout*/ int* contained_entset_handles_allocated,
                         /*inout*/ int* contained_entset_handles_size, int *err) 
   {
-    std::vector<MBEntityHandle> sets;
-    MBErrorCode rval = MBI->get_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
+    std::vector<EntityHandle> sets;
+    ErrorCode rval = MBI->get_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
                                                     sets, 
                                                     std::max( num_hops, 0 ) );
     CHKERR(rval, "iMesh_entitysetGetEntitySets: problem getting entities by type.");
     ALLOC_CHECK_ARRAY_NOFAIL(contained_entset_handles, sets.size() );
 
-    std::copy( sets.begin(), sets.end(), (MBEntityHandle*)*contained_entset_handles );
+    std::copy( sets.begin(), sets.end(), (EntityHandle*)*contained_entset_handles );
     *contained_entset_handles_size = sets.size();
     RETURN(iBase_SUCCESS);
   }
@@ -992,8 +992,8 @@
                             /*in*/ iBase_EntitySetHandle entity_set, 
                             int *err)
   {
-    const MBEntityHandle *ents = CONST_HANDLE_ARRAY_PTR(entity_handles);
-    MBErrorCode result = MBI->add_entities(ENTITY_HANDLE(entity_set),
+    const EntityHandle *ents = CONST_HANDLE_ARRAY_PTR(entity_handles);
+    ErrorCode result = MBI->add_entities(ENTITY_HANDLE(entity_set),
                                            ents, entity_handles_size);
 
     CHKERR(result,"iMesh_addEntArrToSet:ERROR adding entities in EntitySet.");
@@ -1012,9 +1012,9 @@
                               /*in*/ int entity_handles_size,
                               /*in*/ iBase_EntitySetHandle entity_set, int *err)
   {
-    const MBEntityHandle *ents = CONST_HANDLE_ARRAY_PTR(entity_handles);
+    const EntityHandle *ents = CONST_HANDLE_ARRAY_PTR(entity_handles);
 
-    MBErrorCode result = MBI->remove_entities
+    ErrorCode result = MBI->remove_entities
       (ENTITY_HANDLE(entity_set), ents, entity_handles_size);
   
     CHKERR(result,"iMesh_rmvEntArrFromSet:ERROR removing entities in EntitySet.");
@@ -1034,8 +1034,8 @@
                        /*in*/ iBase_EntitySetHandle entity_set_handle,
                        int *err)
   {
-    MBEntityHandle to_add = ENTITY_HANDLE(entity_set_to_add);
-    MBErrorCode result = MBI->add_entities(ENTITY_HANDLE(entity_set_handle), &to_add, 1);
+    EntityHandle to_add = ENTITY_HANDLE(entity_set_to_add);
+    ErrorCode result = MBI->add_entities(ENTITY_HANDLE(entity_set_handle), &to_add, 1);
 
     CHKERR(result,"iMesh_addEntSet:ERROR adding entitysets.");
     RETURN(iBase_SUCCESS);
@@ -1046,8 +1046,8 @@
                        /*in*/ iBase_EntitySetHandle entity_set_handle, 
                        int *err)
   {
-    MBEntityHandle to_remove = ENTITY_HANDLE(entity_set_to_remove);
-    MBErrorCode result = MBI->remove_entities
+    EntityHandle to_remove = ENTITY_HANDLE(entity_set_to_remove);
+    ErrorCode result = MBI->remove_entities
       (ENTITY_HANDLE(entity_set_handle), &to_remove, 1);
   
     CHKERR(result,"iMesh_rmvEntSet:ERROR removing entitysets in EntitySet.");
@@ -1075,13 +1075,13 @@
                            /*out*/ int* err )
 
   {
-    MBEntityHandle set = ENTITY_HANDLE(containing_set);
+    EntityHandle set = ENTITY_HANDLE(containing_set);
     ALLOC_CHECK_ARRAY_NOFAIL(is_contained, num_entity_handles);
     *is_contained_size = num_entity_handles;
     
     if (containing_set) {
       for (int i = 0; i < num_entity_handles; ++i) {
-        MBEntityHandle h = ENTITY_HANDLE(entity_handles[i]);
+        EntityHandle h = ENTITY_HANDLE(entity_handles[i]);
         (*is_contained)[i] = MBI->contains_entities( set, &h, 1 );
       }
     }
@@ -1106,7 +1106,7 @@
                          /*inout*/ iBase_EntitySetHandle child_entity_set, 
                          int *err) 
   {
-    MBErrorCode result = MBI->add_parent_child
+    ErrorCode result = MBI->add_parent_child
       (ENTITY_HANDLE(parent_entity_set),
        ENTITY_HANDLE(child_entity_set));
 
@@ -1119,7 +1119,7 @@
                          /*inout*/ iBase_EntitySetHandle child_entity_set, 
                          int *err)
   {
-    MBErrorCode result = MBI->remove_parent_child
+    ErrorCode result = MBI->remove_parent_child
       (ENTITY_HANDLE(parent_entity_set),
        ENTITY_HANDLE(child_entity_set));
   
@@ -1132,9 +1132,9 @@
                        /*in*/ const iBase_EntitySetHandle child_entity_set,
                        int *is_child, int *err)
   {
-    std::vector<MBEntityHandle> children;
+    std::vector<EntityHandle> children;
 
-    MBErrorCode result = MBI->get_child_meshsets
+    ErrorCode result = MBI->get_child_meshsets
       (ENTITY_HANDLE(parent_entity_set), children);
 
     CHKERR(result,"iMesh_isChildOf: ERROR IsParentChildRelated failed.");
@@ -1155,7 +1155,7 @@
                         int *num_child, int *err)
   {
     *num_child = 0;
-    MBErrorCode result = MBI->num_child_meshsets
+    ErrorCode result = MBI->num_child_meshsets
       (ENTITY_HANDLE(entity_set), num_child, num_hops);
 
     CHKERR(result,"iMesh_getNumChld: ERROR GetNumChildren failed.");
@@ -1169,7 +1169,7 @@
                         int *num_parent, int *err)
   {
     *num_parent = 0;
-    MBErrorCode result = MBI->num_parent_meshsets
+    ErrorCode result = MBI->num_parent_meshsets
       (ENTITY_HANDLE(entity_set), num_parent, num_hops);
 
     CHKERR(result,"iMesh_getNumPrnt: ERROR GetNumParents failed.");
@@ -1183,17 +1183,17 @@
                       /*out*/ int* entity_set_handles_allocated,
                       /*out*/ int* entity_set_handles_size, int *err) 
   {
-    std::vector<MBEntityHandle> children;
+    std::vector<EntityHandle> children;
 
-    MBErrorCode result = MBI->get_child_meshsets
+    ErrorCode result = MBI->get_child_meshsets
       (ENTITY_HANDLE(from_entity_set), children, num_hops);
 
     CHKERR(result,"ERROR getChildren failed.");
     ALLOC_CHECK_ARRAY_NOFAIL(entity_set_handles, children.size());
 
-    MBEntityHandle *ents = HANDLE_ARRAY_PTR(*entity_set_handles);
+    EntityHandle *ents = HANDLE_ARRAY_PTR(*entity_set_handles);
       // use a memcpy for efficiency
-    memcpy(ents, &children[0], children.size()*sizeof(MBEntityHandle));
+    memcpy(ents, &children[0], children.size()*sizeof(EntityHandle));
 
     RETURN(iBase_SUCCESS);
   }
@@ -1205,18 +1205,18 @@
                       /*out*/ int* entity_set_handles_allocated,
                       /*out*/ int* entity_set_handles_size, int *err) 
   {
-    std::vector<MBEntityHandle> parents;
+    std::vector<EntityHandle> parents;
 
-    MBErrorCode result = MBI->get_parent_meshsets
+    ErrorCode result = MBI->get_parent_meshsets
       (ENTITY_HANDLE(from_entity_set), parents, num_hops);
 
     CHKERR(result,"ERROR getParents failed.");
 
     ALLOC_CHECK_ARRAY_NOFAIL(entity_set_handles, parents.size());
 
-    MBEntityHandle *ents = HANDLE_ARRAY_PTR(*entity_set_handles);
+    EntityHandle *ents = HANDLE_ARRAY_PTR(*entity_set_handles);
       // use a memcpy for efficiency
-    memcpy(ents, &parents[0], parents.size()*sizeof(MBEntityHandle));
+    memcpy(ents, &parents[0], parents.size()*sizeof(EntityHandle));
 
     RETURN(iBase_SUCCESS);
   }
@@ -1228,13 +1228,13 @@
                               /*in*/ const double* new_coords,
                               /*in*/ const int new_coords_size, int *err) 
   {
-    MBErrorCode result = MB_SUCCESS, tmp_result;
+    ErrorCode result = MB_SUCCESS, tmp_result;
     if (storage_order == iBase_INTERLEAVED) {
       result = MBI->set_coords(CONST_HANDLE_ARRAY_PTR(vertex_handles),
                                vertex_handles_size, new_coords);
     }
     else {
-      const MBEntityHandle *verts = CONST_HANDLE_ARRAY_PTR(vertex_handles);
+      const EntityHandle *verts = CONST_HANDLE_ARRAY_PTR(vertex_handles);
       double dummy[3];
       for (int i = 0; i < vertex_handles_size; i++) {
         dummy[0] = new_coords[i]; dummy[1] = new_coords[vertex_handles_size+i]; 
@@ -1266,10 +1266,10 @@
     ALLOC_CHECK_ARRAY(new_vertex_handles, num_verts);
   
       // make the entities
-    MBEntityHandle *new_verts = HANDLE_ARRAY_PTR(*new_vertex_handles);
+    EntityHandle *new_verts = HANDLE_ARRAY_PTR(*new_vertex_handles);
   
     for (int i = 0; i < num_verts; i++) {
-      MBErrorCode result = MBI->create_vertex(&new_coords[3*i], new_verts[i]);
+      ErrorCode result = MBI->create_vertex(&new_coords[3*i], new_verts[i]);
       CHKERR(result, "iMesh_createVtxArr: couldn't create vertex.");
     }  
 
@@ -1289,9 +1289,9 @@
                           /*out*/ int* status_size, int *err) 
   {
       // for now, throw an error if lower order entity handles aren't vertices
-    MBEntityType this_type = mb_topology_table[new_entity_topology];
+    EntityType this_type = mb_topology_table[new_entity_topology];
     int num_ents = 0, num_verts;
-    const MBEntityHandle *lower_ents;
+    const EntityHandle *lower_ents;
     if (MBVERTEX != this_type) {
       num_verts = MBCN::VerticesPerEntity(this_type);
       num_ents = lower_order_entity_handles_size / num_verts;
@@ -1317,9 +1317,9 @@
     ALLOC_CHECK_ARRAY_NOFAIL(status, num_ents);
   
       // make the entities
-    MBEntityHandle *new_ents = HANDLE_ARRAY_PTR(*new_entity_handles);
+    EntityHandle *new_ents = HANDLE_ARRAY_PTR(*new_entity_handles);
 
-    MBErrorCode tmp_result, result = MB_SUCCESS;
+    ErrorCode tmp_result, result = MB_SUCCESS;
   
     for (int i = 0; i < num_ents; i++) {
       tmp_result = MBI->create_element(this_type, lower_ents, num_verts,
@@ -1340,10 +1340,10 @@
     *status_size = num_ents;
  
     if (MBimesh->AdjTable[5] || MBimesh->AdjTable[10]) {
-      MBRange set_ents;
+      Range set_ents;
       std::copy(HANDLE_ARRAY_PTR(*new_entity_handles), 
                 HANDLE_ARRAY_PTR(*new_entity_handles)+*new_entity_handles_size,
-                mb_range_inserter(set_ents));
+                range_inserter(set_ents));
       result = create_int_ents(MBI, set_ents);
       CHKERR(result,"");
     }
@@ -1359,7 +1359,7 @@
       RETURN(iBase_SUCCESS);
     }
 
-    MBErrorCode result = MBI->delete_entities(CONST_HANDLE_ARRAY_PTR(entity_handles),
+    ErrorCode result = MBI->delete_entities(CONST_HANDLE_ARRAY_PTR(entity_handles),
                                               entity_handles_size);
     CHKERR(result, "iMesh_deleteEntArr: trouble deleting entities.");
 
@@ -1374,7 +1374,7 @@
                        int *err,
                        const int tag_name_size)
   {
-    MBTag new_tag;
+    Tag new_tag;
     int this_size = tag_size;
 
     std::string tmp_tagname(tag_name);
@@ -1394,7 +1394,7 @@
         break;
     }
       
-    MBErrorCode result = MBI->tag_create(tmp_tagname.c_str(), this_size,
+    ErrorCode result = MBI->tag_create(tmp_tagname.c_str(), this_size,
                                          MB_TAG_SPARSE, 
                                          mb_data_type_table[tag_type],
                                          new_tag,
@@ -1422,12 +1422,12 @@
   {
       // might need to check if it's used first
     if (false == forced) {
-      MBRange ents;
-      MBErrorCode result;
-      MBTag this_tag = TAG_HANDLE(tag_handle);
-      for (MBEntityType this_type = MBVERTEX; this_type != MBMAXTYPE; this_type++) {
+      Range ents;
+      ErrorCode result;
+      Tag this_tag = TAG_HANDLE(tag_handle);
+      for (EntityType this_type = MBVERTEX; this_type != MBMAXTYPE; this_type++) {
         result = MBI->get_entities_by_type_and_tag(0, this_type, &this_tag, NULL, 1, 
-                                                   ents, MBInterface::UNION);
+                                                   ents, Interface::UNION);
         CHKERR(result,"iMesh_destroyTag: problem finding tag.");
         if (!ents.empty()) {
           ERROR(iBase_FAILURE, "iMesh_destroyTag: forced=false and entities"
@@ -1443,7 +1443,7 @@
     }
   
       // ok, good to go - either forced or no entities with this tag
-    MBErrorCode result = MBI->tag_delete(TAG_HANDLE(tag_handle));
+    ErrorCode result = MBI->tag_delete(TAG_HANDLE(tag_handle));
     if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result)
       ERROR(result, "iMesh_destroyTag: problem deleting tag.");
 
@@ -1456,7 +1456,7 @@
                         int out_data_len)
   {
     static ::std::string name;
-    MBErrorCode result = MBI->tag_get_name(TAG_HANDLE(tag_handle), name);
+    ErrorCode result = MBI->tag_get_name(TAG_HANDLE(tag_handle), name);
     CHKERR(result, "iMesh_getTagName: problem getting name.");
 
     strncpy(out_data, name.c_str(), out_data_len);
@@ -1467,8 +1467,8 @@
                          /*in*/ const iBase_TagHandle tag_handle,
                          int *value_type, int *err) 
   {
-    MBDataType this_type;
-    MBErrorCode result = MBI->tag_get_data_type(TAG_HANDLE(tag_handle),
+    DataType this_type;
+    ErrorCode result = MBI->tag_get_data_type(TAG_HANDLE(tag_handle),
                                                 this_type);
     CHKERR(result, "iMesh_getTagType: problem getting type.");
 
@@ -1480,10 +1480,10 @@
                               /*in*/ const iBase_TagHandle tag_handle,
                               int *tag_size_val, int *err)
   {
-    MBErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_val);
+    ErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_val);
     CHKERR(result, "iMesh_getTagSize: problem getting size.");
     
-    MBDataType this_type;
+    DataType this_type;
     result = MBI->tag_get_data_type(TAG_HANDLE(tag_handle), this_type);
     CHKERR(result, "iMesh_getTagSize: problem getting type.");
  
@@ -1495,7 +1495,7 @@
         *tag_size_val /= sizeof(double);
         break;
       case MB_TYPE_HANDLE:
-        *tag_size_val /= sizeof(MBEntityHandle);
+        *tag_size_val /= sizeof(EntityHandle);
         break;
       case MB_TYPE_OPAQUE:
       case MB_TYPE_BIT:
@@ -1509,7 +1509,7 @@
                              /*in*/ const iBase_TagHandle tag_handle,
                              int *tag_size_bytes, int *err)
   {
-    MBErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_bytes);
+    ErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_bytes);
     CHKERR(result, "iMesh_getTagSize: problem getting size.");
     RETURN(iBase_SUCCESS);
   }
@@ -1519,7 +1519,7 @@
                           iBase_TagHandle *tag_handle, int *err,
                           const int tag_name_len)
   {
-    MBErrorCode result = MBI->tag_get_handle(tag_name, (MBTag&)*tag_handle);
+    ErrorCode result = MBI->tag_get_handle(tag_name, (Tag&)*tag_handle);
     
     if (MB_SUCCESS != result) {
       std::string msg("iMesh_getTagHandle: problem getting handle for tag named '");
@@ -1537,14 +1537,14 @@
                             /*in*/ const char* tag_value,
                             /*in*/ const int , int *err) 
   {
-    MBErrorCode result;
+    ErrorCode result;
 
     if (entity_set_handle == 0)
         // set the tag data on this entity set
       result = MBI->tag_set_data(TAG_HANDLE(tag_handle),
                                  NULL, 0, tag_value);
     else {
-      MBEntityHandle set = ENTITY_HANDLE(entity_set_handle);
+      EntityHandle set = ENTITY_HANDLE(entity_set_handle);
       result = MBI->tag_set_data(TAG_HANDLE(tag_handle), &set, 1, tag_value);
     }
     
@@ -1600,11 +1600,11 @@
                             /*inout*/ int* tag_value_allocated,
                             /*inout*/ int* tag_value_size, int *err) 
   {
-    MBEntityHandle eh = ENTITY_HANDLE(entity_set_handle);
-    MBTag tag = TAG_HANDLE(tag_handle);
+    EntityHandle eh = ENTITY_HANDLE(entity_set_handle);
+    Tag tag = TAG_HANDLE(tag_handle);
 
     int tag_size;
-    MBErrorCode result = MBI->tag_get_size(tag, tag_size);
+    ErrorCode result = MBI->tag_get_size(tag, tag_size);
     CHKERR(result, "iMesh_getEntSetData: couldn't get tag size.");
  
     ALLOC_CHECK_TAG_ARRAY(tag_value, tag_size);
@@ -1658,7 +1658,7 @@
                               iBase_EntityHandle *out_data, int *err) 
   {
     char *tag_ptr = reinterpret_cast<char*>(out_data);
-    int tag_size = sizeof(MBEntityHandle);
+    int tag_size = sizeof(EntityHandle);
     iMesh_getEntSetData(instance, entity_set, tag_handle, &tag_ptr, 
                         &tag_size, &tag_size, err);
   }
@@ -1669,15 +1669,15 @@
                                /*out*/ int* tag_handles_allocated,
                                /*out*/ int* tag_handles_size, int *err) 
   {
-    MBEntityHandle eh = ENTITY_HANDLE(entity_set_handle);
-    std::vector<MBTag> all_tags;
+    EntityHandle eh = ENTITY_HANDLE(entity_set_handle);
+    std::vector<Tag> all_tags;
   
-    MBErrorCode result = MBI->tag_get_tags_on_entity(eh, all_tags);
+    ErrorCode result = MBI->tag_get_tags_on_entity(eh, all_tags);
     CHKERR(result, "iMesh_entitysetGetAllTagHandles failed.");
  
       // now put those tag handles into sidl array
     ALLOC_CHECK_ARRAY_NOFAIL(tag_handles, all_tags.size());
-    memcpy(*tag_handles, &all_tags[0], all_tags.size()*sizeof(MBTag));
+    memcpy(*tag_handles, &all_tags[0], all_tags.size()*sizeof(Tag));
 
     *tag_handles_size = (int) all_tags.size();
     RETURN(iBase_SUCCESS);
@@ -1692,8 +1692,8 @@
       iMesh_getRootSet(instance, &entity_set_handle, &success);
       CHKERR(success,"getRootSet failed");
     }
-    MBEntityHandle set = ENTITY_HANDLE(entity_set_handle);
-    MBErrorCode result = MBI->tag_delete_data(TAG_HANDLE(tag_handle), &set, 1);
+    EntityHandle set = ENTITY_HANDLE(entity_set_handle);
+    ErrorCode result = MBI->tag_delete_data(TAG_HANDLE(tag_handle), &set, 1);
   
       // don't check return; this tag may have never been set on the entity set
     RETURN(iBase_ERROR_MAP[result]);
@@ -1734,11 +1734,11 @@
             "iMesh_createEnt: need more than zero lower order entities.");
     }
 
-      // call MB directly to allow creation of higher-order entities
+      // call  directly to allow creation of higher-order entities
       // directly from connectivity
-    MBEntityType this_type = mb_topology_table[new_entity_topology];
-    MBEntityHandle tmp_ent;
-    MBErrorCode result = MBI->create_element(this_type,
+    EntityType this_type = mb_topology_table[new_entity_topology];
+    EntityHandle tmp_ent;
+    ErrorCode result = MBI->create_element(this_type,
                                              CONST_HANDLE_ARRAY_PTR(lower_order_entity_handles), 
                                              lower_order_entity_handles_size, 
                                              tmp_ent);
@@ -1751,7 +1751,7 @@
     *err = *status;
 
     if (MB_SUCCESS == result && (MBimesh->AdjTable[5] || MBimesh->AdjTable[10])) {
-      MBRange set_ents;
+      Range set_ents;
       set_ents.insert( tmp_ent );
       create_int_ents(MBI, set_ents);
     }
@@ -1771,10 +1771,10 @@
                          /*inout*/int* tag_values_allocated,
                          /*out*/ int* tag_values_size, int *err) 
   {
-    const MBEntityHandle *ents = reinterpret_cast<const MBEntityHandle *>(entity_handles);
-    MBTag tag = TAG_HANDLE(tag_handle);
+    const EntityHandle *ents = reinterpret_cast<const EntityHandle *>(entity_handles);
+    Tag tag = TAG_HANDLE(tag_handle);
     int tag_size;
-    MBErrorCode result = MBI->tag_get_size(tag, tag_size);
+    ErrorCode result = MBI->tag_get_size(tag, tag_size);
     if (MB_SUCCESS != result) {
       int nerr=-1; char tagn[64], msg[256];
       iMesh_getTagName(instance, tag_handle, tagn, &nerr, sizeof(tagn));
@@ -1897,7 +1897,7 @@
       RETURN(iBase_SUCCESS);
     }
 
-    MBErrorCode result = MBI->tag_set_data(TAG_HANDLE(tag_handle), 
+    ErrorCode result = MBI->tag_set_data(TAG_HANDLE(tag_handle), 
                                            CONST_HANDLE_ARRAY_PTR(entity_handles),
                                            entity_handles_size,
                                            tag_values);
@@ -1962,7 +1962,7 @@
                         /*in*/ const int entity_handles_size,
                         /*in*/ const iBase_TagHandle tag_handle, int *err) 
   {
-    MBErrorCode result = MBI->tag_delete_data(TAG_HANDLE(tag_handle),
+    ErrorCode result = MBI->tag_delete_data(TAG_HANDLE(tag_handle),
                                               CONST_HANDLE_ARRAY_PTR(entity_handles),
                                               entity_handles_size);
   
@@ -2088,14 +2088,14 @@
                          /*inout*/ int* tag_handles_allocated,
                          /*out*/ int* tag_handles_size, int *err) 
   {
-    std::vector<MBTag> all_tags;
+    std::vector<Tag> all_tags;
   
-    MBErrorCode result = MBI->tag_get_tags_on_entity(ENTITY_HANDLE(entity_handle), all_tags);
+    ErrorCode result = MBI->tag_get_tags_on_entity(ENTITY_HANDLE(entity_handle), all_tags);
     CHKERR(result, "iMesh_getAllTags failed.");
     
       // now put those tag handles into sidl array
     ALLOC_CHECK_ARRAY_NOFAIL(tag_handles, all_tags.size());
-    memcpy(*tag_handles, &all_tags[0], all_tags.size()*sizeof(MBTag));
+    memcpy(*tag_handles, &all_tags[0], all_tags.size()*sizeof(Tag));
     *tag_handles_size = all_tags.size();
 
     RETURN(iBase_SUCCESS);
@@ -2225,10 +2225,10 @@
                       /*in*/ const iBase_EntitySetHandle entity_set_2,
                       /*out*/ iBase_EntitySetHandle* result_entity_set, int *err)
   {
-    MBEntityHandle temp_set;
-    MBEntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
+    EntityHandle temp_set;
+    EntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
       set2 = ENTITY_HANDLE(entity_set_2);
-    MBErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
+    ErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
     if (MB_SUCCESS == result) result = MBI->unite_meshset(temp_set, set1);
     if (MB_SUCCESS == result) result = MBI->subtract_meshset(temp_set, set2);
 
@@ -2244,10 +2244,10 @@
                        /*in*/ const iBase_EntitySetHandle entity_set_2,
                        /*out*/ iBase_EntitySetHandle* result_entity_set, int *err)
   {
-    MBEntityHandle temp_set;
-    MBEntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
+    EntityHandle temp_set;
+    EntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
       set2 = ENTITY_HANDLE(entity_set_2);
-    MBErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
+    ErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
     if (MB_SUCCESS == result) result = MBI->unite_meshset(temp_set, set1);
     if (MB_SUCCESS == result) result = MBI->intersect_meshset(temp_set, set2);
 
@@ -2263,10 +2263,10 @@
                    /*in*/ const iBase_EntitySetHandle entity_set_2,
                    /*out*/ iBase_EntitySetHandle* result_entity_set, int *err)
   {  
-    MBEntityHandle temp_set;
-    MBEntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
+    EntityHandle temp_set;
+    EntityHandle set1 = ENTITY_HANDLE(entity_set_1), 
       set2 = ENTITY_HANDLE(entity_set_2);
-    MBErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
+    ErrorCode result = MBI->create_meshset(MESHSET_SET, temp_set);
     if (MB_SUCCESS == result) result = MBI->unite_meshset(temp_set, set1);
     if (MB_SUCCESS == result) result = MBI->unite_meshset(temp_set, set2);
 
@@ -2290,8 +2290,8 @@
     bool use_top = false;
     bool use_type = false;
       // initialize just to get rid of compiler warning
-    MBEntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
-    std::vector<MBEntityHandle> out_entities;
+    EntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
+    std::vector<EntityHandle> out_entities;
  
     if (entity_topology >= iMesh_POINT
         && entity_topology < iMesh_ALL_TOPOLOGIES) {
@@ -2306,8 +2306,8 @@
             "iMesh_getEntities:ERROR not valid entity type or topology");
     }
 
-    MBEntityHandle handle = ENTITY_HANDLE(entity_set_handle);
-    MBErrorCode result;
+    EntityHandle handle = ENTITY_HANDLE(entity_set_handle);
+    ErrorCode result;
 
     if (use_top) {
       if (entity_topology == iMesh_SEPTAHEDRON)
@@ -2323,7 +2323,7 @@
     CHKERR(result,"iMesh_GetEntities:ERROR getting entities.");
 
       // remove entity sets from the result list
-    std::vector<MBEntityHandle>::iterator iter, end_iter;
+    std::vector<EntityHandle>::iterator iter, end_iter;
     if (iBase_ALL_TYPES == entity_type && iMesh_ALL_TOPOLOGIES == entity_topology) {
       for (iter = out_entities.begin(); iter != out_entities.end() && 
            TYPE_FROM_HANDLE(*iter) != MBENTITYSET; ++iter);
@@ -2373,7 +2373,7 @@
                              /*out*/ int *err) 
   {
     *num_type = 0;
-    MBErrorCode result;
+    ErrorCode result;
     if (entity_type == iBase_ALL_TYPES) {
       result = MBI->get_number_entities_by_handle
         (ENTITY_HANDLE(entity_set_handle), *num_type, recursive);
@@ -2423,7 +2423,7 @@
     }
 
     *num_topo = 0;
-    MBErrorCode result;
+    ErrorCode result;
     if (iMesh_ALL_TOPOLOGIES == entity_topology) {
       result = MBI->get_number_entities_by_handle(ENTITY_HANDLE(entity_set_handle),
                                                   *num_topo, recursive);
@@ -2482,8 +2482,8 @@
     bool use_top = false;
     bool use_type = false;
       // initialize just to get rid of compiler warning
-    MBEntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
-    MBRange out_entities;
+    EntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
+    Range out_entities;
  
     if (entity_topology >= iMesh_POINT
         && entity_topology < iMesh_ALL_TOPOLOGIES) {
@@ -2498,43 +2498,43 @@
                          "iMesh_getEntities:ERROR not valid entity type or topology");
    }
 
-    MBEntityHandle handle = ENTITY_HANDLE(entity_set_handle);
-    MBErrorCode result = MB_SUCCESS;
+    EntityHandle handle = ENTITY_HANDLE(entity_set_handle);
+    ErrorCode result = MB_SUCCESS;
 
     if (use_top) {
       if (entity_topology == iMesh_SEPTAHEDRON)
         result = MB_SUCCESS;  // MOAB doesn't do septahedrons, so there are never any.
       else
-        result = MBI->get_entities_by_type_and_tag(handle, type, (MBTag*)tag_handles, 
+        result = MBI->get_entities_by_type_and_tag(handle, type, (Tag*)tag_handles, 
                                                    (const void* const *)tag_vals,
                                                    num_tags_vals, out_entities, 
-                                                   MBInterface::INTERSECT, recursive);
+                                                   Interface::INTERSECT, recursive);
     }
     else if (use_type && entity_type != iBase_ALL_TYPES) {
         // need to loop over all types of this dimension
-      for (MBEntityType tp = MBCN::TypeDimensionMap[entity_type].first;
+      for (EntityType tp = MBCN::TypeDimensionMap[entity_type].first;
            tp <= MBCN::TypeDimensionMap[entity_type].second; tp++) {
-        MBRange tmp_range;
-        MBErrorCode tmp_result = MBI->get_entities_by_type_and_tag(handle, type, (MBTag*)tag_handles, 
+        Range tmp_range;
+        ErrorCode tmp_result = MBI->get_entities_by_type_and_tag(handle, type, (Tag*)tag_handles, 
                                                                    (const void* const *)tag_vals,
                                                                    num_tags_vals, tmp_range, 
-                                                                   MBInterface::INTERSECT, recursive);
+                                                                   Interface::INTERSECT, recursive);
         if (MB_SUCCESS != tmp_result) result = tmp_result;
         else out_entities.merge(tmp_range);
       }
     }
     else 
-      result = MBI->get_entities_by_type_and_tag(handle, type, (MBTag*)tag_handles, 
+      result = MBI->get_entities_by_type_and_tag(handle, type, (Tag*)tag_handles, 
                                                  (const void* const *)tag_vals,
                                                  num_tags_vals, out_entities,
-                                                 MBInterface::INTERSECT, recursive);
+                                                 Interface::INTERSECT, recursive);
 
     CHKERR(result,"iMesh_GetEntities:ERROR getting entities.");
 
     ALLOC_CHECK_ARRAY_NOFAIL(entity_handles, out_entities.size());
   
-    MBRange::iterator iter = out_entities.begin();
-    MBRange::iterator end_iter = out_entities.end();
+    Range::iterator iter = out_entities.begin();
+    Range::iterator end_iter = out_entities.end();
     int k = 0;
 
       // filter out entity sets here
@@ -2565,20 +2565,20 @@
                                  /*out*/ int* set_handles_size,
                                  /*out*/ int *err)
   {
-    MBRange out_entities;
+    Range out_entities;
  
-    MBEntityHandle handle = ENTITY_HANDLE(entity_set_handle);
-    MBErrorCode result;
+    EntityHandle handle = ENTITY_HANDLE(entity_set_handle);
+    ErrorCode result;
 
-    result = MBI->get_entities_by_type_and_tag(handle, MBENTITYSET, (MBTag*)tag_handles, 
+    result = MBI->get_entities_by_type_and_tag(handle, MBENTITYSET, (Tag*)tag_handles, 
                                                (const void* const *)tag_vals,
                                                num_tags_vals, out_entities, 
-                                               MBInterface::INTERSECT, recursive);
+                                               Interface::INTERSECT, recursive);
     CHKERR(result,"ERROR getting entities.");
 
     ALLOC_CHECK_ARRAY_NOFAIL(set_handles, out_entities.size());
                
-    std::copy(out_entities.begin(), out_entities.end(), ((MBEntityHandle*) *set_handles));
+    std::copy(out_entities.begin(), out_entities.end(), ((EntityHandle*) *set_handles));
 
     RETURN(iBase_SUCCESS);
   }
@@ -2597,19 +2597,19 @@
 } // extern "C"
 #endif
 
-MBErrorCode iMesh_tag_set_vertices(iMesh_Instance instance,
-                                   MBEntityHandle in_set, 
+ErrorCode iMesh_tag_set_vertices(iMesh_Instance instance,
+                                   EntityHandle in_set, 
                                    const int req_dimension, 
-                                   const MBEntityType req_type,
-                                   MBTag &tag, MBRange &req_entities, 
+                                   const EntityType req_type,
+                                   Tag &tag, Range &req_entities, 
                                    int &num_verts, int *err) 
 {
     // get all the entities then vertices
-  MBRange vertices, entities;
+  Range vertices, entities;
   entities.clear();
-  MBErrorCode result = MBI->get_entities_by_handle(in_set, entities, false);
+  ErrorCode result = MBI->get_entities_by_handle(in_set, entities, false);
   if (MB_SUCCESS != result) {
-    std::string msg("MBMesh::tag_set_vertices: getting entities didn't succeed., with error type: ");
+    std::string msg("Mesh::tag_set_vertices: getting entities didn't succeed., with error type: ");
     msg += MBI->get_error_string(result);
     iMesh_processError(iBase_ERROR_MAP[result], msg.c_str());
     *err = iBase_ERROR_MAP[result];
@@ -2622,9 +2622,9 @@
 
     // get vertices
   result = MBI->get_adjacencies(entities, 0, false, vertices,
-                                MBInterface::UNION);
+                                Interface::UNION);
   if (MB_SUCCESS != result) {
-    std::string msg("MBMesh::tag_set_vertices: getting vertices didn't succeed., with error type: ");
+    std::string msg("Mesh::tag_set_vertices: getting vertices didn't succeed., with error type: ");
     msg += MBI->get_error_string(result);
     iMesh_processError(iBase_ERROR_MAP[result], msg.c_str());
     *err = iBase_ERROR_MAP[result];
@@ -2644,7 +2644,7 @@
     }
   }
   
-  MBRange::iterator vit;
+  Range::iterator vit;
   for (vit = vertices.begin(), i = 0; vit != vertices.end(); vit++, i++) {
     result = MBI->tag_set_data(tag, &(*vit), 1, &i);
     if (MB_SUCCESS != result) {
@@ -2658,10 +2658,10 @@
 
     // winnow the list for entities of the desired type and/or topology
   num_verts = 0;
-  MBRange::iterator ent_it;
-  MBEntityType this_type;
-  std::vector<MBEntityHandle> connect_v;
-  const MBEntityHandle *connect;
+  Range::iterator ent_it;
+  EntityType this_type;
+  std::vector<EntityHandle> connect_v;
+  const EntityHandle *connect;
   int num_connect;
   for (ent_it = entities.begin(); ent_it != entities.end(); ent_it++) {
     this_type = MBI->type_from_handle(*ent_it);
@@ -2677,18 +2677,18 @@
   return result;
 }
 
-MBErrorCode create_int_ents(MBInterface *instance,
-                            MBRange &from_ents,
-                            const MBEntityHandle* in_set) 
+ErrorCode create_int_ents(Interface *instance,
+                            Range &from_ents,
+                            const EntityHandle* in_set) 
 {
   MBiMesh* mbimesh = dynamic_cast<MBiMesh*>(instance);
   assert(mbimesh->AdjTable[10] || mbimesh->AdjTable[5]);
-  MBRange int_ents;
-  MBErrorCode result;
+  Range int_ents;
+  ErrorCode result;
   
   if (mbimesh->AdjTable[10]) {
     result = instance->get_adjacencies(from_ents, 2, true, int_ents,
-                                  MBInterface::UNION);
+                                  Interface::UNION);
     if (MB_SUCCESS != result) return result;
     unsigned int old_size = from_ents.size();
     from_ents.merge(int_ents);
@@ -2701,7 +2701,7 @@
   if (mbimesh->AdjTable[5]) {
     int_ents.clear();
     result = instance->get_adjacencies(from_ents, 1, true, int_ents,
-                                  MBInterface::UNION);
+                                  Interface::UNION);
     if (MB_SUCCESS != result) return result;
     unsigned int old_size = from_ents.size();
     from_ents.merge(int_ents);

Modified: MOAB/trunk/itaps/imesh/iMesh_MOAB.hpp
===================================================================
--- MOAB/trunk/itaps/imesh/iMesh_MOAB.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/iMesh_MOAB.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,10 +2,12 @@
 #define IMESH_MOAB_HPP
 
 #include "iMesh.h"
-#include "MBForward.hpp"
+#include "moab/Forward.hpp"
 #include <cstring>
 #include <cstdlib>
 
+using namespace moab;
+
 /* map from MB's entity type to TSTT's entity topology */
 extern const iMesh_EntityTopology tstt_topology_table[MBMAXTYPE+1];
 
@@ -13,24 +15,24 @@
 extern const iBase_EntityType tstt_type_table[MBMAXTYPE+1];
 
 /* map to MB's entity type from TSTT's entity topology */
-extern const MBEntityType mb_topology_table[MBMAXTYPE+1];
+extern const EntityType mb_topology_table[MBMAXTYPE+1];
 
 /* map from TSTT's tag types to MOAB's */
-extern const MBDataType mb_data_type_table[4];
+extern const DataType mb_data_type_table[4];
 
 /* map from MOAB's tag types to tstt's */
 extern const iBase_TagValueType tstt_data_type_table[MB_MAX_DATA_TYPE+1];
 
-/* map from MOAB's MBErrorCode to tstt's */
+/* map from MOAB's ErrorCode to tstt's */
 extern "C" const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
 
 /* Create ITAPS iterator */
-iMesh_EntityIterator create_itaps_iterator( MBRange& swap_range,
+iMesh_EntityIterator create_itaps_iterator( Range& swap_range,
                                             int array_size = 1 ); 
 
-/* Define macro for quick reference to MBInterface instance */
-static inline MBInterface* MBI_cast( iMesh_Instance i )  
-  { return reinterpret_cast<MBInterface*>(i); }         
+/* Define macro for quick reference to Interface instance */
+static inline Interface* MBI_cast( iMesh_Instance i )  
+  { return reinterpret_cast<Interface*>(i); }         
 #define MBI MBI_cast(instance)
 
 /* Most recently returned error code */
@@ -40,9 +42,9 @@
                       iMesh_LAST_ERROR.description[0] = '\0'; \
                       return;} while(false)
 
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 
-class MBiMesh : public MBCore
+class MBiMesh : public Core
 {
 private:
   bool haveDeletedEntities;
@@ -57,9 +59,9 @@
     return result;
   }
 
-  virtual MBErrorCode delete_mesh();
-  virtual MBErrorCode delete_entities( const MBEntityHandle*, const int );
-  virtual MBErrorCode delete_entities( const MBRange& );
+  virtual ErrorCode delete_mesh();
+  virtual ErrorCode delete_entities( const EntityHandle*, const int );
+  virtual ErrorCode delete_entities( const Range& );
   int AdjTable[16];
 };
 
@@ -78,9 +80,9 @@
 #define ERROR(CODE,MSG) do { *err = iMesh_setLastError( MBI, (CODE), (MSG) ); return; } while(false)
 #define IBASE_ERROR(CODE,MSG) do { *err = iMesh_processError( (CODE), (MSG) ); return; } while(false)
 
-static inline int iMesh_setLastError( MBInterface*, int code, const char* msg )
+static inline int iMesh_setLastError( Interface*, int code, const char* msg )
   { return iMesh_processError( code, msg ); }  
-static inline int iMesh_setLastError( MBInterface* mbi, MBErrorCode code, const char* msg )
+static inline int iMesh_setLastError( Interface* mbi, ErrorCode code, const char* msg )
   { 
     std::string message(msg);
     message += "  (MOAB Error Code: ";
@@ -94,7 +96,7 @@
 
 static inline bool iMesh_isError(int code)
   { return (iBase_SUCCESS != code); }
-static inline bool iMesh_isError(MBErrorCode code)
+static inline bool iMesh_isError(ErrorCode code)
   { return (MB_SUCCESS != code); }
 
 

Modified: MOAB/trunk/itaps/imesh/partest.cpp
===================================================================
--- MOAB/trunk/itaps/imesh/partest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/partest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
 #include <iostream>
 #include <stdio.h>
 #include <string.h>
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include "iMesh.h"
 
 

Modified: MOAB/trunk/itaps/imesh/testc_cbind.c
===================================================================
--- MOAB/trunk/itaps/imesh/testc_cbind.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/itaps/imesh/testc_cbind.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -60,7 +60,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include "iMesh.h"
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
 
 

Modified: MOAB/trunk/src/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/src/AEntityFactory.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/AEntityFactory.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,27 +16,29 @@
 
 
 #include "AEntityFactory.hpp"
-#include "MBInternals.hpp"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBError.hpp"
-#include "MBCN.hpp"
-#include "MeshTopoUtil.hpp"
+#include "Internals.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "Error.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "EntitySequence.hpp"
 #include "SequenceData.hpp"
 #include "SequenceManager.hpp"
-#include "MBRangeSeqIntersectIter.hpp"
+#include "RangeSeqIntersectIter.hpp"
 
 #include <assert.h>
 #include <algorithm>
 #include <set>
 
-MBErrorCode AEntityFactory::get_vertices( MBEntityHandle h,
-                                          const MBEntityHandle*& vect_out,
+namespace moab {
+
+ErrorCode AEntityFactory::get_vertices( EntityHandle h,
+                                          const EntityHandle*& vect_out,
                                           int& count_out,
-                                          std::vector<MBEntityHandle>& storage )
+                                          std::vector<EntityHandle>& storage )
 {
-  MBErrorCode result;
+  ErrorCode result;
   if (MBPOLYHEDRON == TYPE_FROM_HANDLE(h)) {
     storage.clear();
     result = thisMB->get_adjacencies( &h, 1, 0, false, storage );
@@ -49,7 +51,7 @@
   return result;
 }
 
-AEntityFactory::AEntityFactory(MBCore *mdb) 
+AEntityFactory::AEntityFactory(Core *mdb) 
 {
   assert(NULL != mdb);
   thisMB = mdb;
@@ -60,19 +62,19 @@
 AEntityFactory::~AEntityFactory()
 {
   // clean up all the adjacency information that was created
-  MBEntityType ent_type;
+  EntityType ent_type;
 
   // iterate through each element type
   for (ent_type = MBVERTEX; ent_type != MBENTITYSET; ent_type++) {
     TypeSequenceManager::iterator i;
     TypeSequenceManager& seqman = thisMB->sequence_manager()->entity_map( ent_type );
     for (i = seqman.begin(); i != seqman.end(); ++i) {
-      std::vector<MBEntityHandle>** adj_list = (*i)->data()->get_adjacency_data();
+      std::vector<EntityHandle>** adj_list = (*i)->data()->get_adjacency_data();
       if (!adj_list)
         continue;
       adj_list += (*i)->start_handle() - (*i)->data()->start_handle();
       
-      for (MBEntityID j = 0; j < (*i)->size(); ++j) {
+      for (EntityID j = 0; j < (*i)->size(); ++j) {
         delete adj_list[j];
         adj_list[j] = 0;
       }
@@ -85,14 +87,14 @@
 //! is true and no entity is found, one is created; if create_adjacency_option
 //! is >= 0, adjacencies from entities of that dimension to each target_entity
 //! are created (this function uses AEntityFactory::get_element for each element)
-MBErrorCode AEntityFactory::get_elements(MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_elements(EntityHandle source_entity,
                                           const unsigned int target_dimension,
-                                          std::vector<MBEntityHandle> &target_entities,
+                                          std::vector<EntityHandle> &target_entities,
                                           const bool create_if_missing,
                                           const int create_adjacency_option)
 {
   // check for trivial case first
-  const MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
+  const EntityType source_type = TYPE_FROM_HANDLE(source_entity);
   const unsigned source_dimension = MBCN::Dimension(source_type);
 
   if (source_type >= MBENTITYSET || target_dimension < 1 || target_dimension > 3) {
@@ -103,7 +105,7 @@
     return MB_SUCCESS;
   }
 
-  MBErrorCode result;
+  ErrorCode result;
   if(mVertElemAdj == false) {
     result = create_vert_elem_adjacencies();
     if (MB_SUCCESS != result) return result;
@@ -128,39 +130,39 @@
   return result;
 }
 
-MBErrorCode AEntityFactory::get_polyhedron_vertices(const MBEntityHandle source_entity, 
-                                                    std::vector<MBEntityHandle> &target_entities) 
+ErrorCode AEntityFactory::get_polyhedron_vertices(const EntityHandle source_entity, 
+                                                    std::vector<EntityHandle> &target_entities) 
 {
     // get the connectivity array pointer
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode result = thisMB->get_connectivity(source_entity, connect, num_connect);
+  ErrorCode result = thisMB->get_connectivity(source_entity, connect, num_connect);
   if (MB_SUCCESS != result) return result;
   
     // now get the union of those polygons' vertices
   result = thisMB->get_adjacencies(connect, num_connect, 0, false, target_entities, 
-                                   MBInterface::UNION);
+                                   Interface::UNION);
   return result;
 }
 
-MBErrorCode AEntityFactory::get_associated_meshsets( MBEntityHandle source_entity, 
-                                                      std::vector<MBEntityHandle> &target_entities )
+ErrorCode AEntityFactory::get_associated_meshsets( EntityHandle source_entity, 
+                                                      std::vector<EntityHandle> &target_entities )
 {
 
-  MBErrorCode result;
+  ErrorCode result;
   
-  const MBEntityHandle* adj_vec;
+  const EntityHandle* adj_vec;
   int num_adj;
   result = get_adjacencies( source_entity, adj_vec, num_adj );
   if(result != MB_SUCCESS || adj_vec == NULL)
     return result;
 
   // find the meshsets in this vector 
-  MBDimensionPair dim_pair = MBCN::TypeDimensionMap[4];
+  DimensionPair dim_pair = MBCN::TypeDimensionMap[4];
   int dum;
-  const MBEntityHandle* start_ent =
+  const EntityHandle* start_ent =
     std::lower_bound(adj_vec, adj_vec+num_adj, CREATE_HANDLE(dim_pair.first, MB_START_ID, dum));
-  const MBEntityHandle* end_ent =
+  const EntityHandle* end_ent =
     std::lower_bound(start_ent, adj_vec+num_adj, CREATE_HANDLE(dim_pair.second, MB_END_ID, dum));
 
   // copy the the meshsets 
@@ -177,19 +179,19 @@
 //! is >= 0, adjacencies from entities of that dimension to target_entity
 //! are created (only create_adjacency_option=0 is supported right now,
 //! so that never creates other ancillary entities)
-MBErrorCode AEntityFactory::get_element(const MBEntityHandle *vertex_list,
+ErrorCode AEntityFactory::get_element(const EntityHandle *vertex_list,
                                          const int vertex_list_size,
-                                         const MBEntityType target_type,
-                                         MBEntityHandle &target_entity,
+                                         const EntityType target_type,
+                                         EntityHandle &target_entity,
                                          const bool create_if_missing,
-                                         const MBEntityHandle source_entity,
+                                         const EntityHandle source_entity,
                                          const int /*create_adjacency_option*/) 
 {
 
   // look over nodes to see if this entity already exists
   target_entity = 0;
-  MBErrorCode result;
-  const MBEntityHandle *i_adj, *end_adj;
+  ErrorCode result;
+  const EntityHandle *i_adj, *end_adj;
 
   target_entity = 0;
   
@@ -198,7 +200,7 @@
     create_vert_elem_adjacencies();
   
   // get the adjacency list
-  const MBEntityHandle* adj_vec;
+  const EntityHandle* adj_vec;
   int num_adj;
   result = get_adjacencies( vertex_list[0], adj_vec, num_adj );
   if(result != MB_SUCCESS || adj_vec == NULL)
@@ -208,7 +210,7 @@
   int dum;
 
     // use a fixed-size array, for speed; there should never be more than 5 equivalent entities
-  MBEntityHandle temp_vec[15];
+  EntityHandle temp_vec[15];
   int temp_vec_size = 0;
   
   i_adj = std::lower_bound(adj_vec, adj_vec+num_adj, CREATE_HANDLE(target_type, MB_START_ID, dum));
@@ -246,7 +248,7 @@
       // multiple entities found - look for direct adjacencies
     if (0 != source_entity) {
       
-      const MBEntityHandle *adj_vec, *adj_iter;
+      const EntityHandle *adj_vec, *adj_iter;
       int num_adjs;
       for (dum = 0; dum < temp_vec_size; dum++) {
         result = get_adjacencies(temp_vec[dum], adj_vec, num_adjs);
@@ -284,14 +286,14 @@
   return result;
 }
 
-bool AEntityFactory::entities_equivalent(const MBEntityHandle this_entity, 
-                                         const MBEntityHandle *vertex_list, 
+bool AEntityFactory::entities_equivalent(const EntityHandle this_entity, 
+                                         const EntityHandle *vertex_list, 
                                          const int vertex_list_size,
-                                         const MBEntityType target_type) 
+                                         const EntityType target_type) 
 {
     // compare vertices of this_entity with those in the list, returning true if they
     // represent the same element
-  MBEntityType this_type = TYPE_FROM_HANDLE(this_entity);
+  EntityType this_type = TYPE_FROM_HANDLE(this_entity);
   
   if (this_type != target_type) 
     return false;
@@ -300,16 +302,16 @@
     return false;
   
     // need to compare the actual vertices
-  const MBEntityHandle *this_vertices;
+  const EntityHandle *this_vertices;
   int num_this_vertices;
-  std::vector<MBEntityHandle> storage;
+  std::vector<EntityHandle> storage;
   thisMB->get_connectivity(this_entity, this_vertices, num_this_vertices, false, &storage);
   
   // see if we can get one node id to match
   assert(vertex_list_size > 0);
   int num_corner_verts = ((this_type == MBPOLYGON || this_type == MBPOLYHEDRON) ?
                           num_this_vertices : MBCN::VerticesPerEntity(target_type));
-  const MBEntityHandle *iter = 
+  const EntityHandle *iter = 
     std::find(this_vertices, (this_vertices+num_corner_verts), vertex_list[0]);
   if(iter == (this_vertices+num_corner_verts))
     return false;
@@ -362,24 +364,24 @@
 //! in reverse too
 //! NOTE: this function is defined even though we may only be implementing
 //! vertex-based up-adjacencies
-MBErrorCode AEntityFactory::add_adjacency(MBEntityHandle from_ent,
-                                           MBEntityHandle to_ent,
+ErrorCode AEntityFactory::add_adjacency(EntityHandle from_ent,
+                                           EntityHandle to_ent,
                                            const bool both_ways) 
 {
-  MBEntityType to_type = TYPE_FROM_HANDLE(to_ent);
+  EntityType to_type = TYPE_FROM_HANDLE(to_ent);
 
   if (to_type == MBVERTEX) 
     return MB_ALREADY_ALLOCATED;
   
   
   
-  MBAdjacencyVector *adj_list_ptr = NULL;
-  MBErrorCode result = get_adjacencies( from_ent, adj_list_ptr, true );
+  AdjacencyVector *adj_list_ptr = NULL;
+  ErrorCode result = get_adjacencies( from_ent, adj_list_ptr, true );
   if (MB_SUCCESS != result) 
     return result;
 
     // get an iterator to the right spot in this sorted vector
-  MBAdjacencyVector::iterator adj_iter;
+  AdjacencyVector::iterator adj_iter;
   if (!adj_list_ptr->empty()) 
   {
     adj_iter = std::lower_bound(adj_list_ptr->begin(), adj_list_ptr->end(),
@@ -401,16 +403,16 @@
 }
 
 //! remove an adjacency from from the base_entity.
-MBErrorCode AEntityFactory::remove_adjacency(MBEntityHandle base_entity,
-                              MBEntityHandle adj_to_remove)
+ErrorCode AEntityFactory::remove_adjacency(EntityHandle base_entity,
+                              EntityHandle adj_to_remove)
 {
-  MBErrorCode result;
+  ErrorCode result;
 
   if (TYPE_FROM_HANDLE(base_entity) == MBENTITYSET) 
     return thisMB->remove_entities(base_entity, &adj_to_remove, 1);
 
   // get the adjacency tag
-  MBAdjacencyVector *adj_list = NULL;
+  AdjacencyVector *adj_list = NULL;
   result = get_adjacencies( base_entity, adj_list );
   if (adj_list == NULL || MB_SUCCESS != result)
     return result;
@@ -424,11 +426,11 @@
 }
 
 //! remove all adjacencies from from the base_entity.
-MBErrorCode AEntityFactory::remove_all_adjacencies(MBEntityHandle base_entity,
+ErrorCode AEntityFactory::remove_all_adjacencies(EntityHandle base_entity,
                                                    const bool delete_adj_list)
 {
-  MBErrorCode result;
-  MBEntityType base_type = TYPE_FROM_HANDLE(base_entity);
+  ErrorCode result;
+  EntityType base_type = TYPE_FROM_HANDLE(base_entity);
 
   if (base_type == MBENTITYSET) 
     return thisMB->clear_meshset(&base_entity, 1);
@@ -439,9 +441,9 @@
     // to the vertex and of higher dimension than this
     // element for downward adjacencies to this element.
   if (vert_elem_adjacencies() && base_type != MBVERTEX) {
-    MBEntityHandle const *connvect = 0, *adjvect = 0;
+    EntityHandle const *connvect = 0, *adjvect = 0;
     int numconn = 0, numadj = 0;
-    std::vector<MBEntityHandle> connstorage;
+    std::vector<EntityHandle> connstorage;
     result = get_vertices( base_entity, connvect, numconn, connstorage );
     if (MB_SUCCESS != result) 
       return result;
@@ -467,14 +469,14 @@
   }
   
   // get the adjacency tag
-  MBAdjacencyVector *adj_list = 0;
+  AdjacencyVector *adj_list = 0;
   result = get_adjacencies( base_entity, adj_list );
   if (MB_SUCCESS != result || !adj_list)
     return result;
   
   
     // check adjacent entities for references back to this entity
-  for (MBAdjacencyVector::reverse_iterator it = adj_list->rbegin(); it != adj_list->rend(); ++it) 
+  for (AdjacencyVector::reverse_iterator it = adj_list->rbegin(); it != adj_list->rend(); ++it) 
     remove_adjacency( *it, base_entity );
   
   if (delete_adj_list)
@@ -485,18 +487,18 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::create_vert_elem_adjacencies()
+ErrorCode AEntityFactory::create_vert_elem_adjacencies()
 {
 
   mVertElemAdj = true;
 
-  MBEntityType ent_type;
-  MBRange::iterator i_range;
-  const MBEntityHandle *connectivity;
-  std::vector<MBEntityHandle> aux_connect;
+  EntityType ent_type;
+  Range::iterator i_range;
+  const EntityHandle *connectivity;
+  std::vector<EntityHandle> aux_connect;
   int number_nodes;
-  MBErrorCode result;
-  MBRange handle_range;
+  ErrorCode result;
+  Range handle_range;
   
   // 1. over all element types, for each element, create vertex-element adjacencies
   for (ent_type = MBEDGE; ent_type != MBENTITYSET; ent_type++) 
@@ -525,12 +527,12 @@
 }
 
 
-MBErrorCode AEntityFactory::get_adjacencies(MBEntityHandle entity,
-                                            const MBEntityHandle *&adjacent_entities,
+ErrorCode AEntityFactory::get_adjacencies(EntityHandle entity,
+                                            const EntityHandle *&adjacent_entities,
                                             int &num_entities) const
 {
-  MBAdjacencyVector const* vec_ptr = 0;
-  MBErrorCode result = get_adjacency_ptr( entity, vec_ptr );
+  AdjacencyVector const* vec_ptr = 0;
+  ErrorCode result = get_adjacency_ptr( entity, vec_ptr );
   if (MB_SUCCESS != result || !vec_ptr) {
     adjacent_entities = 0;
     num_entities = 0;
@@ -542,11 +544,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::get_adjacencies(MBEntityHandle entity,
-                                            std::vector<MBEntityHandle>& adjacent_entities) const
+ErrorCode AEntityFactory::get_adjacencies(EntityHandle entity,
+                                            std::vector<EntityHandle>& adjacent_entities) const
 {
-  MBAdjacencyVector const* vec_ptr = 0;
-  MBErrorCode result = get_adjacency_ptr( entity, vec_ptr );
+  AdjacencyVector const* vec_ptr = 0;
+  ErrorCode result = get_adjacency_ptr( entity, vec_ptr );
   if (MB_SUCCESS != result || !vec_ptr) {
     adjacent_entities.clear();
     return result;
@@ -556,14 +558,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::get_adjacencies( MBEntityHandle entity,
-                                             std::vector<MBEntityHandle>*& adj_vec,
+ErrorCode AEntityFactory::get_adjacencies( EntityHandle entity,
+                                             std::vector<EntityHandle>*& adj_vec,
                                              bool create )
 {
   adj_vec = 0;
-  MBErrorCode result = get_adjacency_ptr( entity, adj_vec );
+  ErrorCode result = get_adjacency_ptr( entity, adj_vec );
   if (MB_SUCCESS == result && !adj_vec && create) {
-    adj_vec = new MBAdjacencyVector;
+    adj_vec = new AdjacencyVector;
     result = set_adjacency_ptr( entity, adj_vec );
     if (MB_SUCCESS != result) {
       delete adj_vec;
@@ -573,15 +575,15 @@
   return result;
 }
 
-MBErrorCode AEntityFactory::get_adjacencies( const MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_adjacencies( const EntityHandle source_entity,
                                              const unsigned int target_dimension,
                                              bool create_if_missing,
-                                             std::vector<MBEntityHandle> &target_entities )
+                                             std::vector<EntityHandle> &target_entities )
 {
-  const MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
+  const EntityType source_type = TYPE_FROM_HANDLE(source_entity);
   const unsigned source_dimension = MBCN::Dimension(source_type);
 
-  MBErrorCode result;
+  ErrorCode result;
   if (target_dimension == 4) { //get meshsets 'source' is in
     result = get_associated_meshsets( source_entity, target_entities ); 
   }
@@ -622,20 +624,20 @@
 }
 
 
-MBErrorCode AEntityFactory::notify_create_entity(const MBEntityHandle entity, 
-                                                 const MBEntityHandle *node_array,
+ErrorCode AEntityFactory::notify_create_entity(const EntityHandle entity, 
+                                                 const EntityHandle *node_array,
                                                  const int number_nodes)
 {
-  MBErrorCode result = MB_SUCCESS, tmp_result;
+  ErrorCode result = MB_SUCCESS, tmp_result;
   if( vert_elem_adjacencies())
   {
     //iterate through nodes and add adjacency information
     if (TYPE_FROM_HANDLE(entity) == MBPOLYHEDRON) {
         // polyhedron - get real vertex connectivity
-      std::vector<MBEntityHandle> verts;
+      std::vector<EntityHandle> verts;
       tmp_result = get_adjacencies(entity, 0, false, verts);
       if (MB_SUCCESS != tmp_result) return tmp_result;
-      for (std::vector<MBEntityHandle>::iterator vit = verts.begin(); 
+      for (std::vector<EntityHandle>::iterator vit = verts.begin(); 
            vit != verts.end(); vit++) 
       {
         tmp_result = add_adjacency(*vit, entity);
@@ -654,22 +656,22 @@
   return result;
 }
 
-MBErrorCode AEntityFactory::get_zero_to_n_elements(MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_zero_to_n_elements(EntityHandle source_entity,
                             const unsigned int target_dimension,
-                            std::vector<MBEntityHandle> &target_entities,
+                            std::vector<EntityHandle> &target_entities,
                             const bool create_if_missing,
                             const int /*create_adjacency_option = -1*/)
 {
-  MBAdjacencyVector::iterator start_ent, end_ent;
+  AdjacencyVector::iterator start_ent, end_ent;
 
   // get the adjacency vector
-  MBAdjacencyVector *adj_vec = NULL;
-  MBErrorCode result = get_adjacencies( source_entity, adj_vec );
+  AdjacencyVector *adj_vec = NULL;
+  ErrorCode result = get_adjacencies( source_entity, adj_vec );
   if(result != MB_SUCCESS || adj_vec == NULL)
     return result;
   
   if (target_dimension < 3 && create_if_missing) {
-      std::vector<MBEntityHandle> tmp_ents;
+      std::vector<EntityHandle> tmp_ents;
       
       start_ent = std::lower_bound(adj_vec->begin(), adj_vec->end(), 
                          FIRST_HANDLE(MBCN::TypeDimensionMap[target_dimension+1].first));
@@ -677,7 +679,7 @@
       end_ent = std::lower_bound(start_ent, adj_vec->end(), 
                          LAST_HANDLE(MBCN::TypeDimensionMap[3].second));
       
-      std::vector<MBEntityHandle> elems(start_ent, end_ent);
+      std::vector<EntityHandle> elems(start_ent, end_ent);
  
       // make target_dimension elements from all adjacient higher-dimension elements
       for(start_ent = elems.begin(); start_ent != elems.end(); ++start_ent)
@@ -687,21 +689,21 @@
       }
   }
     
-  MBDimensionPair dim_pair = MBCN::TypeDimensionMap[target_dimension];
+  DimensionPair dim_pair = MBCN::TypeDimensionMap[target_dimension];
   start_ent = std::lower_bound(adj_vec->begin(), adj_vec->end(), FIRST_HANDLE(dim_pair.first ));
   end_ent   = std::lower_bound(start_ent,        adj_vec->end(), LAST_HANDLE (dim_pair.second));
   target_entities.insert( target_entities.end(), start_ent, end_ent );
   return MB_SUCCESS;  
 }
 
-MBErrorCode AEntityFactory::get_down_adjacency_elements(MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_down_adjacency_elements(EntityHandle source_entity,
                                                          const unsigned int target_dimension,
-                                                         std::vector<MBEntityHandle> &target_entities,
+                                                         std::vector<EntityHandle> &target_entities,
                                                          const bool create_if_missing,
                                                          const int create_adjacency_option)
 {
 
-  MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
+  EntityType source_type = TYPE_FROM_HANDLE(source_entity);
 
   if (source_type == MBPOLYHEDRON ||
       source_type == MBPOLYGON) 
@@ -710,16 +712,16 @@
                                             create_adjacency_option);
   
     // make this a fixed size to avoid cost of working with STL vectors
-  MBEntityHandle vertex_array[27];
-  MBErrorCode temp_result;
+  EntityHandle vertex_array[27];
+  ErrorCode temp_result;
 
-  const MBEntityHandle *vertices;
+  const EntityHandle *vertices;
   int num_verts;
   
     // I know there are already vertex adjacencies for this - call
     // another function to get them
-  std::vector<MBEntityHandle> storage;
-  MBErrorCode result = thisMB->get_connectivity(source_entity, vertices, num_verts, false, &storage);
+  std::vector<EntityHandle> storage;
+  ErrorCode result = thisMB->get_connectivity(source_entity, vertices, num_verts, false, &storage);
   if (MB_SUCCESS != result) return result;
 
   int has_mid_nodes[4];
@@ -765,7 +767,7 @@
       vertex_array[verts_per_sub++] = vertices[tmp_index];
     }
 
-    MBEntityHandle tmp_target = 0;
+    EntityHandle tmp_target = 0;
     temp_result = get_element(vertex_array, verts_per_sub,
                               cmap.target_type[j], tmp_target, 
                               create_if_missing, source_entity, create_adjacency_option);
@@ -780,25 +782,25 @@
   return result;
 }
 
-MBErrorCode AEntityFactory::get_down_adjacency_elements_poly(MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_down_adjacency_elements_poly(EntityHandle source_entity,
                                                              const unsigned int target_dimension,
-                                                             std::vector<MBEntityHandle> &target_entities,
+                                                             std::vector<EntityHandle> &target_entities,
                                                              const bool /*create_if_missing*/,
                                                              const int /*create_adjacency_option*/)
 {
 
-  MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
+  EntityType source_type = TYPE_FROM_HANDLE(source_entity);
 
   if (!(source_type == MBPOLYHEDRON && target_dimension > 0 && target_dimension < 3) &&
       (!source_type == MBPOLYGON && target_dimension == 1)) 
     return MB_TYPE_OUT_OF_RANGE;
   
     // make this a fixed size to avoid cost of working with STL vectors
-  std::vector<MBEntityHandle> vertex_array;
+  std::vector<EntityHandle> vertex_array;
 
     // I know there are already vertex adjacencies for this - call
     // another function to get them
-  MBErrorCode result = get_adjacencies(source_entity, 0, false, vertex_array);
+  ErrorCode result = get_adjacencies(source_entity, 0, false, vertex_array);
   if (MB_SUCCESS != result) return result;
 
   if (target_dimension == 0) {
@@ -806,13 +808,13 @@
     return MB_SUCCESS;
   }
 
-  MBErrorCode tmp_result;
+  ErrorCode tmp_result;
   if (source_type == MBPOLYGON) {
     result = MB_SUCCESS;
       // put the first vertex on the end so we have a ring
     vertex_array.push_back(*vertex_array.begin());
     for (unsigned int i = 0; i < vertex_array.size()-1; i++) {
-      MBRange vrange, adj_edges;
+      Range vrange, adj_edges;
       vrange.insert(vertex_array[i]);
       vrange.insert(vertex_array[i+1]);
       tmp_result = thisMB->get_adjacencies(vrange, 1, false, adj_edges);
@@ -824,9 +826,9 @@
       else if (adj_edges.size() != 0) {
           // multiple ones - need to check for explicit adjacencies
         unsigned int start_sz = target_entities.size();
-        const MBEntityHandle *explicit_adjs;
+        const EntityHandle *explicit_adjs;
         int num_exp;
-        for (MBRange::iterator rit = adj_edges.begin(); rit != adj_edges.end(); rit++) {
+        for (Range::iterator rit = adj_edges.begin(); rit != adj_edges.end(); rit++) {
           this->get_adjacencies(*rit, explicit_adjs, num_exp);
           if (NULL != explicit_adjs &&
               std::find(explicit_adjs, explicit_adjs+num_exp, source_entity) != 
@@ -847,11 +849,11 @@
       result = thisMB->get_connectivity(&source_entity, 1, target_entities);
     }
     else {
-      std::vector<MBEntityHandle> dum_vec;
+      std::vector<EntityHandle> dum_vec;
       result = thisMB->get_connectivity(&source_entity, 1, dum_vec);
       if (MB_SUCCESS != result) return result;
       result = thisMB->get_adjacencies(&dum_vec[0], dum_vec.size(), 1, false,
-                                       target_entities, MBInterface::UNION);
+                                       target_entities, Interface::UNION);
       return result;
     }
   }
@@ -887,30 +889,30 @@
 }
       
 
-MBErrorCode AEntityFactory::get_up_adjacency_elements( 
-                                   MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_up_adjacency_elements( 
+                                   EntityHandle source_entity,
                                    const unsigned int target_dimension,
-                                   std::vector<MBEntityHandle>& target_entities,
+                                   std::vector<EntityHandle>& target_entities,
                                    const bool create_if_missing,
                                    const int option )
 {
-  MBErrorCode rval;
-  const std::vector<MBEntityHandle> *vtx_adj, *vtx2_adj;
-  std::vector<MBEntityHandle> duplicates;
+  ErrorCode rval;
+  const std::vector<EntityHandle> *vtx_adj, *vtx2_adj;
+  std::vector<EntityHandle> duplicates;
   
     // Handle ranges
   const size_t in_size = target_entities.size();
-  const MBEntityType src_type = TYPE_FROM_HANDLE(source_entity);
-  MBDimensionPair target_types = MBCN::TypeDimensionMap[target_dimension];
-  const MBEntityHandle src_beg_handle = CREATE_HANDLE( src_type, 0 );
-  const MBEntityHandle src_end_handle = CREATE_HANDLE( src_type+1, 0 );
-  const MBEntityHandle tgt_beg_handle = CREATE_HANDLE( target_types.first, 0 );
-  const MBEntityHandle tgt_end_handle = CREATE_HANDLE( target_types.second+1, 0 );
+  const EntityType src_type = TYPE_FROM_HANDLE(source_entity);
+  DimensionPair target_types = MBCN::TypeDimensionMap[target_dimension];
+  const EntityHandle src_beg_handle = CREATE_HANDLE( src_type, 0 );
+  const EntityHandle src_end_handle = CREATE_HANDLE( src_type+1, 0 );
+  const EntityHandle tgt_beg_handle = CREATE_HANDLE( target_types.first, 0 );
+  const EntityHandle tgt_end_handle = CREATE_HANDLE( target_types.second+1, 0 );
   
     // get vertices
   assert(TYPE_FROM_HANDLE(source_entity) != MBPOLYHEDRON); // can't go up from a region
-  std::vector<MBEntityHandle> conn_storage;
-  const MBEntityHandle* conn;
+  std::vector<EntityHandle> conn_storage;
+  const EntityHandle* conn;
   int conn_len;
   rval = thisMB->get_connectivity( source_entity, conn, conn_len, true, &conn_storage );
   if (MB_SUCCESS != rval)
@@ -928,7 +930,7 @@
         return rval;
       assert(vtx_adj != NULL); // should contain at least source_entity
 
-      std::vector<MBEntityHandle> tmp2, tmp(*vtx_adj); // copy in case adjacency vector is changed
+      std::vector<EntityHandle> tmp2, tmp(*vtx_adj); // copy in case adjacency vector is changed
       for (size_t j = 0; j < tmp.size(); ++j) {
         if (MBCN::Dimension(TYPE_FROM_HANDLE(tmp[j])) <= (int)target_dimension)
           continue;
@@ -956,14 +958,14 @@
 
     // Put intersect of all entities except source entity with
     // the same type as the source entity in 'duplicates'
-  std::vector<MBEntityHandle>::const_iterator it1, it2, end1, end2;
+  std::vector<EntityHandle>::const_iterator it1, it2, end1, end2;
   it1 = std::lower_bound( vtx_adj->begin(), vtx_adj->end(), src_beg_handle );
   it2 = std::lower_bound( vtx2_adj->begin(), vtx2_adj->end(), src_beg_handle );
   end1 = std::lower_bound( it1, vtx_adj->end(), src_end_handle );
   end2 = std::lower_bound( it2, vtx2_adj->end(), src_end_handle );
   assert(end1 != it1); // should at least contain source entity
   duplicates.resize( end1 - it1 - 1 );
-  std::vector<MBEntityHandle>::iterator ins = duplicates.begin();
+  std::vector<EntityHandle>::iterator ins = duplicates.begin();
   for (; it1 != end1; ++it1) {
     if (*it1 != source_entity) {
       *ins = *it1;
@@ -1004,7 +1006,7 @@
     // connects candidate target entity to an entity equivalent
     // to the source entity, then assume that source entity is *not*
     // adjacent
-  const std::vector<MBEntityHandle>* adj_ptr;
+  const std::vector<EntityHandle>* adj_ptr;
     // check adjacencies from duplicate entities to candidate targets
   for (size_t i = 0; i < duplicates.size(); ++i) {
     rval = get_adjacency_ptr( duplicates[i], adj_ptr );
@@ -1014,7 +1016,7 @@
       continue;
     
     for (size_t j = 0; j < adj_ptr->size(); ++j) {
-      std::vector<MBEntityHandle>::iterator k = 
+      std::vector<EntityHandle>::iterator k = 
         std::find( target_entities.begin()+in_size, target_entities.end(), (*adj_ptr)[j] );
       if (k != target_entities.end())
         target_entities.erase(k);
@@ -1037,7 +1039,7 @@
     
     size_t j;
     for (j = 0; j < adj_ptr->size(); ++j) {
-      const std::vector<MBEntityHandle>* adj_ptr2;
+      const std::vector<EntityHandle>* adj_ptr2;
       rval = get_adjacency_ptr( (*adj_ptr)[j], adj_ptr2 );
       if (MB_SUCCESS != rval)
         return rval;
@@ -1045,7 +1047,7 @@
         continue;
       
       for (size_t k = 0; k < adj_ptr2->size(); ++k) {
-        std::vector<MBEntityHandle>::iterator it;
+        std::vector<EntityHandle>::iterator it;
         it = std::find( target_entities.begin()+in_size, target_entities.end(), (*adj_ptr2)[k] );
         if (it != target_entities.end()) { 
           target_entities.erase(it);
@@ -1059,18 +1061,18 @@
   return MB_SUCCESS;
 }
 #else
-MBErrorCode AEntityFactory::get_up_adjacency_elements(MBEntityHandle source_entity,
+ErrorCode AEntityFactory::get_up_adjacency_elements(EntityHandle source_entity,
                                                        const unsigned int target_dimension,
-                                                       std::vector<MBEntityHandle> &target_entities,
+                                                       std::vector<EntityHandle> &target_entities,
                                                        const bool create_if_missing,
                                                        const int /*create_adjacency_option = -1*/)
 {
 
-  MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
+  EntityType source_type = TYPE_FROM_HANDLE(source_entity);
 
-  const MBEntityHandle *source_vertices;
+  const EntityHandle *source_vertices;
   int num_source_vertices;
-  std::vector<MBEntityHandle> conn_storage;
+  std::vector<EntityHandle> conn_storage;
   
     // check to see whether there are any equivalent entities (same verts, different entity);
     // do this by calling get_element with a 0 source_entity, and look for a MB_MULTIPLE_ENTITIES_FOUND
@@ -1078,20 +1080,20 @@
 
     // NOTE: we only want corner vertices here, and for the code below which also uses
     // source_vertices
-  MBErrorCode result = 
+  ErrorCode result = 
     thisMB->get_connectivity(source_entity, source_vertices, num_source_vertices, true, &conn_storage);
   if (MB_SUCCESS != result) return result;
-  MBEntityHandle temp_entity;
+  EntityHandle temp_entity;
   result = get_element(source_vertices, num_source_vertices,
                        source_type, temp_entity,
                        false, 0);
 
   bool equiv_entities = (result == MB_MULTIPLE_ENTITIES_FOUND) ? true : false;
   
-  std::vector<MBEntityHandle> tmp_vec;
+  std::vector<EntityHandle> tmp_vec;
   if (!equiv_entities) {
       // get elems adjacent to each node
-    std::vector< std::vector<MBEntityHandle> > elems(num_source_vertices);
+    std::vector< std::vector<EntityHandle> > elems(num_source_vertices);
     int i;
     for(i=0; i < num_source_vertices; i++)
     {
@@ -1110,7 +1112,7 @@
       
         // intersection between first list and ith list, put result in tmp
       std::set_intersection(elems[0].begin(), elems[0].end(), elems[i].begin(), elems[i].end(),
-                            std::back_insert_iterator< std::vector<MBEntityHandle> >(tmp_vec));
+                            std::back_insert_iterator< std::vector<EntityHandle> >(tmp_vec));
         // tmp has elems[0] contents and elems[0] contents has tmp's contents
         // so that elems[0] always has the intersection of previous operations
       elems[0].swap(tmp_vec);
@@ -1127,9 +1129,9 @@
     if (MB_SUCCESS != result) return result;
     
       // now filter according to whether each is adjacent to the polygon
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
-    std::vector<MBEntityHandle> storage;
+    std::vector<EntityHandle> storage;
     for (unsigned int i = 0; i < tmp_vec.size(); i++) {
       result = thisMB->get_connectivity(tmp_vec[i], connect, num_connect, false, &storage);
       if (MB_SUCCESS != result) return result;
@@ -1142,7 +1144,7 @@
       // else get up-adjacencies directly; code copied from get_zero_to_n_elements
 
       // get the adjacency vector
-    MBAdjacencyVector *adj_vec = NULL;
+    AdjacencyVector *adj_vec = NULL;
     result = get_adjacencies( source_entity, adj_vec );
                     
     if(result != MB_SUCCESS)
@@ -1150,15 +1152,15 @@
     else if (adj_vec == NULL)
       return MB_SUCCESS;
 
-    MBDimensionPair dim_pair_dp1 = MBCN::TypeDimensionMap[MBCN::Dimension(source_type)+1],
+    DimensionPair dim_pair_dp1 = MBCN::TypeDimensionMap[MBCN::Dimension(source_type)+1],
       dim_pair_td = MBCN::TypeDimensionMap[target_dimension];
     int dum;
 
-    MBRange tmp_ents, target_ents;
+    Range tmp_ents, target_ents;
 
       // get iterators for start handle of source_dim+1 and target_dim, and end handle
       // of target_dim
-    MBAdjacencyVector::iterator 
+    AdjacencyVector::iterator 
       start_ent_dp1 = std::lower_bound(adj_vec->begin(), adj_vec->end(), 
                                        CREATE_HANDLE(dim_pair_dp1.first, MB_START_ID, dum)),
        
@@ -1170,13 +1172,13 @@
 
       // get the adjacencies for source_dim+1 to target_dim-1, and the adjacencies from
       // those to target_dim
-    std::copy(start_ent_dp1, start_ent_td, mb_range_inserter(tmp_ents));
-    MBErrorCode result = thisMB->get_adjacencies(tmp_ents, target_dimension, false,
-                                                 target_ents, MBInterface::UNION);
+    std::copy(start_ent_dp1, start_ent_td, range_inserter(tmp_ents));
+    ErrorCode result = thisMB->get_adjacencies(tmp_ents, target_dimension, false,
+                                                 target_ents, Interface::UNION);
     if (MB_SUCCESS != result) return result;
     
       // now copy the explicit adjacencies to target_dimension
-    std::copy(start_ent_td, end_ent_td, mb_range_inserter(target_ents));
+    std::copy(start_ent_td, end_ent_td, range_inserter(target_ents));
     
       // now insert the whole thing into the argument vector
     target_entities.insert( target_entities.end(), target_ents.begin(), target_ents.end() );
@@ -1187,17 +1189,17 @@
 #endif
 
 
-MBErrorCode AEntityFactory::notify_change_connectivity(MBEntityHandle entity, 
-                                                        const MBEntityHandle* old_array, 
-                                                        const MBEntityHandle* new_array, 
+ErrorCode AEntityFactory::notify_change_connectivity(EntityHandle entity, 
+                                                        const EntityHandle* old_array, 
+                                                        const EntityHandle* new_array, 
                                                         int number_verts)
 {
-  MBEntityType source_type = TYPE_FROM_HANDLE(entity);
+  EntityType source_type = TYPE_FROM_HANDLE(entity);
   if (source_type == MBPOLYHEDRON || source_type == MBPOLYGON)
     return MB_NOT_IMPLEMENTED;
 
   // find out which ones to add and which to remove
-  std::vector<MBEntityHandle> old_verts, new_verts;
+  std::vector<EntityHandle> old_verts, new_verts;
   int i;
   for (i = 0; i < number_verts; i++) {
     if (old_array[i] != new_array[i]) {
@@ -1206,11 +1208,11 @@
     }
   }
 
-  MBErrorCode result;
+  ErrorCode result;
   
   if (mVertElemAdj == true) {
       // update the vertex-entity adjacencies
-    std::vector<MBEntityHandle>::iterator adj_iter;
+    std::vector<EntityHandle>::iterator adj_iter;
     for (adj_iter = old_verts.begin(); adj_iter != old_verts.end(); adj_iter++) {
       if (std::find(new_verts.begin(), new_verts.end(), *adj_iter) == new_verts.end()) {
         result = remove_adjacency(*adj_iter, entity);
@@ -1229,10 +1231,10 @@
 }
 
     //! return true if 2 entities are explicitly adjacent
-bool AEntityFactory::explicitly_adjacent(const MBEntityHandle ent1,
-                                         const MBEntityHandle ent2) 
+bool AEntityFactory::explicitly_adjacent(const EntityHandle ent1,
+                                         const EntityHandle ent2) 
 {
-  const MBEntityHandle *explicit_adjs;
+  const EntityHandle *explicit_adjs;
   int num_exp;
   get_adjacencies(ent1, explicit_adjs, num_exp);
   if (std::find(explicit_adjs, explicit_adjs+num_exp, ent2) != explicit_adjs+num_exp)
@@ -1241,11 +1243,11 @@
     return false;
 }
 
-MBErrorCode AEntityFactory::merge_adjust_adjacencies(MBEntityHandle entity_to_keep,
-                                                     MBEntityHandle entity_to_remove) 
+ErrorCode AEntityFactory::merge_adjust_adjacencies(EntityHandle entity_to_keep,
+                                                     EntityHandle entity_to_remove) 
 {
   int ent_dim = MBCN::Dimension(TYPE_FROM_HANDLE(entity_to_keep));
-  MBErrorCode result;
+  ErrorCode result;
   
     // check for newly-formed equivalent entities, and create explicit adjacencies
     // to distinguish them; this must be done before connectivity of higher-dimensional
@@ -1257,12 +1259,12 @@
   
     // check adjacencies TO removed entity
   for (int dim = 1; dim < ent_dim; dim++) {
-    MBRange adjs;
+    Range adjs;
     result = thisMB->get_adjacencies(&entity_to_remove, 1, dim, false, adjs);
     if(result != MB_SUCCESS)
       return result;
       // for any explicit ones, make them adjacent to keeper
-    for (MBRange::iterator rit = adjs.begin(); rit != adjs.end(); rit++) {
+    for (Range::iterator rit = adjs.begin(); rit != adjs.end(); rit++) {
       if (this->explicitly_adjacent(*rit, entity_to_remove)) {
         result = this->add_adjacency(*rit, entity_to_keep);
         if(result != MB_SUCCESS) return result;
@@ -1271,7 +1273,7 @@
   }
 
     // check adjacencies FROM removed entity
-  std::vector<MBEntityHandle> conn, adjs;
+  std::vector<EntityHandle> conn, adjs;
   result = this->get_adjacencies(entity_to_remove, adjs);
   if(result != MB_SUCCESS)
     return result;
@@ -1311,39 +1313,39 @@
 
 // check for equivalent entities that may be formed when merging two entities, and
 // create explicit adjacencies accordingly
-MBErrorCode AEntityFactory::check_equiv_entities(MBEntityHandle entity_to_keep,
-                                                 MBEntityHandle entity_to_remove) 
+ErrorCode AEntityFactory::check_equiv_entities(EntityHandle entity_to_keep,
+                                                 EntityHandle entity_to_remove) 
 {
   if (thisMB->dimension_from_handle(entity_to_keep) > 0) return MB_SUCCESS;
 
     // get all the adjacencies for both entities for all dimensions > 0
-  MBRange adjs_keep, adjs_remove;
-  MBErrorCode result;
+  Range adjs_keep, adjs_remove;
+  ErrorCode result;
   
   for (int dim = 1; dim <= 3; dim++) {
     result = thisMB->get_adjacencies(&entity_to_keep, 1, dim, false, adjs_keep,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
     result = thisMB->get_adjacencies(&entity_to_remove, 1, dim, false, adjs_remove,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
   }
 
     // now look for equiv entities which will be formed
     // algorithm:
     // for each entity adjacent to removed entity:
-  MBEntityHandle two_ents[2];
-  for (MBRange::iterator rit_rm = adjs_remove.begin(); rit_rm != adjs_remove.end(); rit_rm++) {
+  EntityHandle two_ents[2];
+  for (Range::iterator rit_rm = adjs_remove.begin(); rit_rm != adjs_remove.end(); rit_rm++) {
     two_ents[0] = *rit_rm;
     
       // - for each entity of same dimension adjacent to kept entity:
-    for (MBRange::iterator rit_kp = adjs_keep.begin(); rit_kp != adjs_keep.end(); rit_kp++) {
+    for (Range::iterator rit_kp = adjs_keep.begin(); rit_kp != adjs_keep.end(); rit_kp++) {
       if (TYPE_FROM_HANDLE(*rit_kp) != TYPE_FROM_HANDLE(*rit_rm)) continue;
       
-      MBRange all_verts;
+      Range all_verts;
       two_ents[1] = *rit_kp;
       //   . get union of adjacent vertices to two entities
-      result = thisMB->get_adjacencies(two_ents, 2, 0, false, all_verts, MBInterface::UNION);
+      result = thisMB->get_adjacencies(two_ents, 2, 0, false, all_verts, Interface::UNION);
       if (MB_SUCCESS != result) return result;
 
       assert(all_verts.find(entity_to_keep) != all_verts.end() && 
@@ -1366,18 +1368,18 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::create_explicit_adjs(MBEntityHandle this_ent) 
+ErrorCode AEntityFactory::create_explicit_adjs(EntityHandle this_ent) 
 {
     //     - get adjacent entities of next higher dimension
-  MBRange all_adjs;
-  MBErrorCode result;
+  Range all_adjs;
+  ErrorCode result;
   result = thisMB->get_adjacencies(&this_ent, 1, 
                                    thisMB->dimension_from_handle(this_ent)+1, 
-                                   true, all_adjs, MBInterface::UNION);
+                                   true, all_adjs, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   
     //     - create explicit adjacency to these entities
-  for (MBRange::iterator rit = all_adjs.begin(); rit != all_adjs.end(); rit++) {
+  for (Range::iterator rit = all_adjs.begin(); rit != all_adjs.end(); rit++) {
     result = add_adjacency(this_ent, *rit);
     if (MB_SUCCESS != result) return result;
   }
@@ -1385,13 +1387,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::get_adjacency_ptr( MBEntityHandle entity, 
-                                               std::vector<MBEntityHandle>*& ptr )
+ErrorCode AEntityFactory::get_adjacency_ptr( EntityHandle entity, 
+                                               std::vector<EntityHandle>*& ptr )
 {
   ptr = 0;
   
   EntitySequence* seq;
-  MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+  ErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
   if (MB_SUCCESS != rval || !seq->data()->get_adjacency_data())
     return rval;
   
@@ -1399,13 +1401,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode AEntityFactory::get_adjacency_ptr( MBEntityHandle entity, 
-                                               const std::vector<MBEntityHandle>*& ptr ) const
+ErrorCode AEntityFactory::get_adjacency_ptr( EntityHandle entity, 
+                                               const std::vector<EntityHandle>*& ptr ) const
 {
   ptr = 0;
   
   EntitySequence* seq;
-  MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+  ErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
   if (MB_SUCCESS != rval || !seq->data()->get_adjacency_data())
     return rval;
   
@@ -1414,19 +1416,19 @@
 }
 
 
-MBErrorCode AEntityFactory::set_adjacency_ptr( MBEntityHandle entity, 
-                                               std::vector<MBEntityHandle>* ptr )
+ErrorCode AEntityFactory::set_adjacency_ptr( EntityHandle entity, 
+                                               std::vector<EntityHandle>* ptr )
 {
   EntitySequence* seq;
-  MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+  ErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
   if (MB_SUCCESS != rval)
     return rval;
     
   if (!seq->data()->get_adjacency_data() && !seq->data()->allocate_adjacency_data())
     return MB_MEMORY_ALLOCATION_FAILED;
   
-  const MBEntityHandle index = entity - seq->data()->start_handle();
-  std::vector<MBEntityHandle>*& ref = seq->data()->get_adjacency_data()[index];
+  const EntityHandle index = entity - seq->data()->start_handle();
+  std::vector<EntityHandle>*& ref = seq->data()->get_adjacency_data()[index];
   delete ref;
   ref = ptr;
   return MB_SUCCESS;
@@ -1440,7 +1442,7 @@
 
   // iterate through each element type
   SequenceData* prev_data = 0;
-  for (MBEntityType t = MBVERTEX; t != MBENTITYSET; t++) {
+  for (EntityType t = MBVERTEX; t != MBENTITYSET; t++) {
     TypeSequenceManager::iterator i;
     TypeSequenceManager& seqman = thisMB->sequence_manager()->entity_map( t );
     for (i = seqman.begin(); i != seqman.end(); ++i) {
@@ -1449,14 +1451,14 @@
       
       if (prev_data != (*i)->data()) {
         prev_data = (*i)->data();
-        memory_total += prev_data->size() * sizeof(MBAdjacencyVector);
+        memory_total += prev_data->size() * sizeof(AdjacencyVector);
       }
       
-      const MBAdjacencyVector* vec;
-      for (MBEntityHandle h = (*i)->start_handle(); h <= (*i)->end_handle(); ++h) {
+      const AdjacencyVector* vec;
+      for (EntityHandle h = (*i)->start_handle(); h <= (*i)->end_handle(); ++h) {
         get_adjacency_ptr( h, vec );
         if (vec) 
-          entity_total += vec->capacity() * sizeof(MBEntityHandle) * sizeof(MBAdjacencyVector);
+          entity_total += vec->capacity() * sizeof(EntityHandle) * sizeof(AdjacencyVector);
       }
     }
   }
@@ -1465,34 +1467,34 @@
 }
   
     
-MBErrorCode AEntityFactory::get_memory_use( const MBRange& ents_in,
+ErrorCode AEntityFactory::get_memory_use( const Range& ents_in,
                                        unsigned long& min_per_ent,
                                        unsigned long& amortized )
 {
   min_per_ent = amortized = 0;
-  MBRangeSeqIntersectIter iter( thisMB->sequence_manager() );
-  MBErrorCode rval = iter.init( ents_in.begin(), ents_in.end() );
+  RangeSeqIntersectIter iter( thisMB->sequence_manager() );
+  ErrorCode rval = iter.init( ents_in.begin(), ents_in.end() );
   if (MB_SUCCESS != rval)
     return rval;
   
   do {
-    MBAdjacencyVector** array = iter.get_sequence()->data()->get_adjacency_data();
+    AdjacencyVector** array = iter.get_sequence()->data()->get_adjacency_data();
     if (!array)
       continue;
 
-    MBEntityID count = iter.get_end_handle() - iter.get_start_handle() + 1;
-    MBEntityID data_occ = thisMB->sequence_manager()
+    EntityID count = iter.get_end_handle() - iter.get_start_handle() + 1;
+    EntityID data_occ = thisMB->sequence_manager()
                                 ->entity_map( iter.get_sequence()->type() )
                                  .get_occupied_size( iter.get_sequence()->data() );
     
-    amortized += sizeof(MBAdjacencyVector*) 
+    amortized += sizeof(AdjacencyVector*) 
                  * iter.get_sequence()->data()->size()
                  * count / data_occ;
                  
     array += iter.get_start_handle() - iter.get_sequence()->data()->start_handle();
-    for (MBEntityID i = 0; i < count; ++i) {
+    for (EntityID i = 0; i < count; ++i) {
       if (array[i]) 
-        min_per_ent += sizeof(MBEntityHandle) * array[i]->capacity() + sizeof(MBAdjacencyVector);
+        min_per_ent += sizeof(EntityHandle) * array[i]->capacity() + sizeof(AdjacencyVector);
     }
   } while (MB_SUCCESS == (rval = iter.step()));
   
@@ -1500,3 +1502,4 @@
   return (rval == MB_FAILURE) ? MB_SUCCESS : rval;
 }   
   
+} // namespace moab

Modified: MOAB/trunk/src/AEntityFactory.hpp
===================================================================
--- MOAB/trunk/src/AEntityFactory.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/AEntityFactory.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -20,19 +20,21 @@
 #error "AEntityFactory.hpp isn't supposed to be included into an application"
 #endif
 
-#include "MBForward.hpp"
+#include "moab/Forward.hpp"
 #include <vector>
 
-typedef std::vector<MBEntityHandle> MBAdjacencyVector;
-class MBCore;
+namespace moab {
 
+typedef std::vector<EntityHandle> AdjacencyVector;
+class Core;
+
 //! class AEntityFactory
 class AEntityFactory 
 {
 public:
 
-  //! require an MBInterface object in order to access tags on that interface
-  AEntityFactory(MBCore *mdb);
+  //! require an Interface object in order to access tags on that interface
+  AEntityFactory(Core *mdb);
 
   //! destructor
   ~AEntityFactory();
@@ -41,16 +43,16 @@
 //! in reverse too
 //! NOTE: this function is defined even though we may only be implementing
 //! vertex-based up-adjacencies
-  MBErrorCode add_adjacency(MBEntityHandle from_ent,
-                             MBEntityHandle to_ent,
+  ErrorCode add_adjacency(EntityHandle from_ent,
+                             EntityHandle to_ent,
                              const bool both_ways = false);
 
 //! remove an adjacency from from the base_entity.
-  MBErrorCode remove_adjacency(MBEntityHandle base_entity,
-                                MBEntityHandle adjacency_to_remove);
+  ErrorCode remove_adjacency(EntityHandle base_entity,
+                                EntityHandle adjacency_to_remove);
 
 //! remove all adjacencies from from the base_entity.
-  MBErrorCode remove_all_adjacencies(MBEntityHandle base_entity,
+  ErrorCode remove_all_adjacencies(EntityHandle base_entity,
                                      const bool delete_adj_list = false);
 
 /**\brief Get adjacencies for a single source entity.
@@ -73,20 +75,20 @@
  *                        entities of that dimension to each target_entity are created 
  *                        (this function uses AEntityFactory::get_element for each element)
  */
-  MBErrorCode get_elements(MBEntityHandle source_entity,
+  ErrorCode get_elements(EntityHandle source_entity,
                             const unsigned int target_dimension,
-                            std::vector<MBEntityHandle> &target_entities,
+                            std::vector<EntityHandle> &target_entities,
                             const bool create_if_missing,
                             const int create_adjacency_option = -1);
 
     //! get the vertices for a polyhedron (special implementation because for polyhedra
     //! connectivity array stores faces)
-  MBErrorCode get_polyhedron_vertices(const MBEntityHandle source_entity, 
-                                      std::vector<MBEntityHandle> &target_entities);
+  ErrorCode get_polyhedron_vertices(const EntityHandle source_entity, 
+                                      std::vector<EntityHandle> &target_entities);
   
 //! get the meshsets that are in source_entitiy's adjacency vector
-  MBErrorCode get_associated_meshsets( MBEntityHandle source_entity, 
-                                        std::vector<MBEntityHandle> &target_entities );
+  ErrorCode get_associated_meshsets( EntityHandle source_entity, 
+                                        std::vector<EntityHandle> &target_entities );
 
 //! get the element defined by the vertices in vertex_list, of the
 //! type target_type, passing back in target_entity; if create_if_missing
@@ -96,12 +98,12 @@
 //! so that never creates other ancillary entities); explicitly require
 //! the vertex_list_size for consistency, even though we could probably get
 //! it from target_type
-  MBErrorCode get_element(const MBEntityHandle *vertex_list,
+  ErrorCode get_element(const EntityHandle *vertex_list,
                            const int vertex_list_size,
-                           const MBEntityType target_type,
-                           MBEntityHandle &target_entity,
+                           const EntityType target_type,
+                           EntityHandle &target_entity,
                            const bool create_if_missing,
-                           const MBEntityHandle source_entity = 0,
+                           const EntityHandle source_entity = 0,
                            const int create_adjacency_option = -1);
 
   /**\brief Get adjacent entities
@@ -112,120 +114,120 @@
    *\param adjacent_entities The resulting adjacent entities are appended to this 
    *                         list.
    */
-  MBErrorCode get_adjacencies(const MBEntityHandle entity,
+  ErrorCode get_adjacencies(const EntityHandle entity,
                                const unsigned int to_dimension,
                                bool create_if_missing,
-                               std::vector<MBEntityHandle> &adjacent_entities);
+                               std::vector<EntityHandle> &adjacent_entities);
 
     //! return const array * for adjacencies
-  MBErrorCode get_adjacencies(MBEntityHandle entity,
-                               const MBEntityHandle *&adjacent_entities,
+  ErrorCode get_adjacencies(EntityHandle entity,
+                               const EntityHandle *&adjacent_entities,
                                int &num_entities) const;
                                
-  MBErrorCode get_adjacencies( MBEntityHandle entity,
-                               std::vector<MBEntityHandle>*& adj_vec_ptr_out,
+  ErrorCode get_adjacencies( EntityHandle entity,
+                               std::vector<EntityHandle>*& adj_vec_ptr_out,
                                bool create_if_missing = false );
   
   //! returns the entities in sorted order
-  MBErrorCode get_adjacencies(MBEntityHandle entity,
-                               std::vector<MBEntityHandle>& adjacent_entities) const;
+  ErrorCode get_adjacencies(EntityHandle entity,
+                               std::vector<EntityHandle>& adjacent_entities) const;
   
 
   //! creates vertex to element adjacency information
-  MBErrorCode create_vert_elem_adjacencies();
+  ErrorCode create_vert_elem_adjacencies();
 
   //! returns whether vertex to element adjacencies are being stored
   bool vert_elem_adjacencies() const { return mVertElemAdj; }
 
   //! calling code notifying this that an entity is getting deleted
-  MBErrorCode notify_delete_entity(MBEntityHandle entity);
+  ErrorCode notify_delete_entity(EntityHandle entity);
 
   //! calling code notifying this that to update connectivity of 'entity' 
-  MBErrorCode notify_create_entity(const MBEntityHandle entity, 
-                                    const MBEntityHandle *node_array,
+  ErrorCode notify_create_entity(const EntityHandle entity, 
+                                    const EntityHandle *node_array,
                                     const int number_nodes);
 
   //! calling code notifying that an entity changed its connectivity
-  MBErrorCode notify_change_connectivity(MBEntityHandle entity, 
-                                          const MBEntityHandle* old_array,
-                                          const MBEntityHandle* new_array, int number_nodes);
+  ErrorCode notify_change_connectivity(EntityHandle entity, 
+                                          const EntityHandle* old_array,
+                                          const EntityHandle* new_array, int number_nodes);
 
     //! return true if 2 entities are explicitly adjacent
-  bool explicitly_adjacent(const MBEntityHandle ent1,
-                           const MBEntityHandle ent2);
+  bool explicitly_adjacent(const EntityHandle ent1,
+                           const EntityHandle ent2);
 
     //! in preparation for merging two entities, adjust adjacencies so that
     //! entity_to_keep will be adjacent to the "right" entities after merge
     //! (also checks for potential formation of equivalent entities and 
     //! creates explicit adjacencies accordingly)
-  MBErrorCode merge_adjust_adjacencies(MBEntityHandle entity_to_keep,
-                                       MBEntityHandle entity_to_remove);
+  ErrorCode merge_adjust_adjacencies(EntityHandle entity_to_keep,
+                                       EntityHandle entity_to_remove);
   
   void get_memory_use( unsigned long& total_entity_storage,
                        unsigned long& total_storage );
-  MBErrorCode get_memory_use( const MBRange& entities,
+  ErrorCode get_memory_use( const Range& entities,
                               unsigned long& total_entity_storage,
                               unsigned long& total_amortized_storage );
   
 private:
 
-  MBErrorCode get_adjacency_ptr( MBEntityHandle, std::vector<MBEntityHandle>*& );
-  MBErrorCode get_adjacency_ptr( MBEntityHandle, const std::vector<MBEntityHandle>*& ) const;
-  MBErrorCode set_adjacency_ptr( MBEntityHandle, std::vector<MBEntityHandle>* );
+  ErrorCode get_adjacency_ptr( EntityHandle, std::vector<EntityHandle>*& );
+  ErrorCode get_adjacency_ptr( EntityHandle, const std::vector<EntityHandle>*& ) const;
+  ErrorCode set_adjacency_ptr( EntityHandle, std::vector<EntityHandle>* );
   
-  MBErrorCode get_vertices( MBEntityHandle h,
-                            const MBEntityHandle*& vect_out,
+  ErrorCode get_vertices( EntityHandle h,
+                            const EntityHandle*& vect_out,
                             int& count_out,
-                            std::vector<MBEntityHandle>& storage );
+                            std::vector<EntityHandle>& storage );
 
   //! private constructor to prevent the construction of a default one
   AEntityFactory();
 
   //! interface associated with this tool
-  MBCore *thisMB;
+  Core *thisMB;
 
   //! whether vertex to element adjacencies are begin done
   bool mVertElemAdj;
   
   //! compare vertex_list to the vertices in this_entity, 
   //!  and return true if they contain the same vertices
-  bool entities_equivalent(const MBEntityHandle this_entity, 
-                           const MBEntityHandle *vertex_list, 
+  bool entities_equivalent(const EntityHandle this_entity, 
+                           const EntityHandle *vertex_list, 
                            const int vertex_list_size,
-                           const MBEntityType target_type);
+                           const EntityType target_type);
 
-  MBErrorCode get_zero_to_n_elements(MBEntityHandle source_entity,
+  ErrorCode get_zero_to_n_elements(EntityHandle source_entity,
                             const unsigned int target_dimension,
-                            std::vector<MBEntityHandle> &target_entities,
+                            std::vector<EntityHandle> &target_entities,
                             const bool create_if_missing,
                             const int create_adjacency_option = -1);
 
-  MBErrorCode get_down_adjacency_elements(MBEntityHandle source_entity,
+  ErrorCode get_down_adjacency_elements(EntityHandle source_entity,
                             const unsigned int target_dimension,
-                            std::vector<MBEntityHandle> &target_entities,
+                            std::vector<EntityHandle> &target_entities,
                             const bool create_if_missing,
                             const int create_adjacency_option = -1);
 
-  MBErrorCode get_down_adjacency_elements_poly(MBEntityHandle source_entity,
+  ErrorCode get_down_adjacency_elements_poly(EntityHandle source_entity,
                                                const unsigned int target_dimension,
-                                               std::vector<MBEntityHandle> &target_entities,
+                                               std::vector<EntityHandle> &target_entities,
                                                const bool create_if_missing,
                                                const int create_adjacency_option = -1);
 
-  MBErrorCode get_up_adjacency_elements(MBEntityHandle source_entity,
+  ErrorCode get_up_adjacency_elements(EntityHandle source_entity,
                             const unsigned int target_dimension,
-                            std::vector<MBEntityHandle> &target_entities,
+                            std::vector<EntityHandle> &target_entities,
                             const bool create_if_missing,
                             const int create_adjacency_option = -1);
 
     //! check for equivalent entities that may be formed when merging two entities, and
     //! create explicit adjacencies accordingly
-  MBErrorCode check_equiv_entities(MBEntityHandle entity_to_keep,
-                                   MBEntityHandle entity_to_remove);
+  ErrorCode check_equiv_entities(EntityHandle entity_to_keep,
+                                   EntityHandle entity_to_remove);
   
     //! create explicit adjacencies between this_ent and all adjacent entities of higher
     //! dimension
-  MBErrorCode create_explicit_adjs(MBEntityHandle this_ent);
+  ErrorCode create_explicit_adjs(EntityHandle this_ent);
   
 };
 
@@ -233,11 +235,12 @@
    calling code is notifying this that an entity is going to be deleted
    from the database
 */
-inline MBErrorCode AEntityFactory::notify_delete_entity(MBEntityHandle entity)
+inline ErrorCode AEntityFactory::notify_delete_entity(EntityHandle entity)
 {
   // remove any references to this entity from other entities
   return remove_all_adjacencies(entity, true);
 }
+  
+} // namespace moab
 
-
 #endif

Copied: MOAB/trunk/src/AdaptiveKDTree.cpp (from rev 3583, MOAB/trunk/src/MBAdaptiveKDTree.cpp)
===================================================================
--- MOAB/trunk/src/AdaptiveKDTree.cpp	                        (rev 0)
+++ MOAB/trunk/src/AdaptiveKDTree.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,2122 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file AdaptiveKDTree.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2007-04-1
+ */
+
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/Interface.hpp"
+#include "moab/GeomUtil.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+
+#include <assert.h>
+#include <algorithm>
+#include <limits>
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#  include <float.h>
+#  define finite(A) _finite(A)
+#endif
+
+namespace moab {
+
+AdaptiveKDTree::Settings::Settings()
+  : maxEntPerLeaf(6), 
+    maxTreeDepth(30),
+    candidateSplitsPerDir(3),
+    candidatePlaneSet(SUBDIVISION_SNAP),
+    minBoxWidth( 1e-10 )
+  {}
+
+
+#define MB_AD_KD_TREE_DEFAULT_TAG_NAME "AKDTree"
+
+// If defined, use single tag for both axis and location of split plane
+#define MB_AD_KD_TREE_USE_SINGLE_TAG 
+
+// No effect if MB_AD_KD_TREE_USE_SINGLE_TAG is not defined.
+// If defined, store plane axis as double so tag has consistent
+// type (doubles for both location and axis).  If not defined,
+// store struct Plane as opaque.
+#define MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG
+
+#if defined(MB_AD_KD_TREE_USE_SINGLE_TAG) && defined(HDF5_FILE)
+  /* include our MPI header before any HDF5 because otherwise
+     it will get included indirectly by HDF5 */
+# ifdef USE_MPI
+#  include "moab_mpi.h"
+# endif 
+# include <H5Tpublic.h>
+#endif
+
+#define MAKE_TAG( NAME, STORAGE, TYPE, COUNT, HANDLE, DEFAULT ) \
+  if (MB_SUCCESS != make_tag( moab(), \
+                              (NAME), \
+                              (STORAGE), \
+                              (TYPE), \
+                              (COUNT), \
+                              (DEFAULT), \
+                              (HANDLE), \
+                              ctl )) { \
+    planeTag = axisTag = rootTag = (Tag)-1; \
+    return; \
+  }
+
+static ErrorCode make_tag( Interface* iface,
+                             std::string name,
+                             TagType storage, 
+                             DataType type,
+                             int count,
+                             void* default_val,
+                             Tag& tag_handle,
+                             std::vector<Tag>& created_tags )
+{
+  int size;
+  switch (type) {
+    case MB_TYPE_DOUBLE:  size = sizeof(double);         break;
+    case MB_TYPE_INTEGER: size = sizeof(int);            break;
+    case MB_TYPE_OPAQUE:  size = 1;                      break;
+    case MB_TYPE_HANDLE:  size = sizeof(EntityHandle); break;
+    default: return MB_FAILURE;
+  }
+  size *= count;
+  
+  ErrorCode rval = iface->tag_create( name.c_str(),
+                                        size,
+                                        storage,
+                                        type,
+                                        tag_handle,
+                                        default_val,
+                                        false );
+  if (MB_SUCCESS == rval) 
+    created_tags.push_back( tag_handle );
+  else if (MB_ALREADY_ALLOCATED == rval)
+    rval = iface->tag_create( name.c_str(),
+                              size,
+                              MB_TAG_DENSE,
+                              type,
+                              tag_handle,
+                              default_val,
+                              true );
+
+  if (MB_SUCCESS != rval)
+    while( !created_tags.empty() ) {
+      iface->tag_delete( created_tags.back() );
+      created_tags.pop_back();
+    }
+  
+  return rval;
+}
+
+AdaptiveKDTree::AdaptiveKDTree( Interface* mb, const char* tagname, unsigned set_flags )
+  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(false)
+{ init(tagname); }
+
+AdaptiveKDTree::AdaptiveKDTree( Interface* mb, bool clean_up, const char* tagname, unsigned set_flags )
+  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(clean_up)
+{ init(tagname); }
+
+void AdaptiveKDTree::init( const char* tagname_in )
+{
+  const char* tagname = tagname_in ? tagname_in : MB_AD_KD_TREE_DEFAULT_TAG_NAME;
+  std::vector<Tag> ctl;
+
+#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
+    // create two tags, one for axis direction and one for axis coordinate
+  std::string n1(tagname), n2(tagname);
+  n1 += "_coord";
+  n2 += "_norm";
+  MAKE_TAG( n1, MB_TAG_DENSE, MB_TYPE_DOUBLE, 1, planeTag, 0 )
+  MAKE_TAG( n2, MB_TAG_DENSE, MB_TYPE_INT,    1, axisTag,  0 )
+
+#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
+    // create tag to hold two doubles, one for location and one for axis
+  MAKE_TAG( tagname, MB_TAG_DENSE, MB_TYPE_DOUBLE, 2, planeTag, 0 )
+#else
+    // create opaque tag to hold struct Plane
+  MAKE_TAG( tagname, MB_TAG_DENSE, MB_TYPE_OPAQUE, sizeof(Plane), planeTag, 0 )
+
+#ifdef HDF5_FILE  
+    // create a mesh tag holding the HDF5 type for a struct Plane
+  Tag type_tag;
+  std::string type_tag_name = "__hdf5_tag_type_";
+  type_tag_name += tagname;
+  MAKE_TAG( type_tag_name, MB_TAG_MESH), MB_TYPE_OPAQUE, sizeof(hid_t), type_tag, 0 )
+    // create HDF5 type object describing struct Plane
+  Plane p;
+  hid_t handle = H5Tcreate( H5T_COMPOUND, sizeof(Plane) );
+  H5Tinsert( handle, "coord", &(p.coord) - &p, H5T_NATIVE_DOUBLE );
+  H5Tinsert( handle, "norm", &(p.axis) - &p, H5T_NATIVE_INT );
+  mbInstance->tag_set_data( type_tag, 0, 0, &handle );
+#endif
+#endif
+
+  std::string root_name(tagname);
+  root_name += "_box";
+  MAKE_TAG( root_name, MB_TAG_SPARSE, MB_TYPE_DOUBLE, 6, rootTag, 0 )
+}
+
+ErrorCode AdaptiveKDTree::get_split_plane( EntityHandle entity,
+                                               Plane& plane )
+{
+#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
+  ErrorCode r1, r2;
+  r1 = moab()->tag_get_data( planeTag, &entity, 1, &plane.coord );
+  r2 = moab()->tag_get_data( axisTag , &entity, 1, &plane.norm  );
+  return MB_SUCCESS == r1 ? r2 : r1;
+#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
+  double values[2];
+  ErrorCode rval = moab()->tag_get_data( planeTag, &entity, 1, values );
+  plane.coord = values[0];
+  plane.norm = (int)values[1];
+  return rval;
+#else
+  return moab()->tag_get_data( planeTag, &entity, 1, &plane );
+#endif
+}
+
+AdaptiveKDTree::~AdaptiveKDTree()
+{
+  if (!cleanUpTrees)
+    return;
+    
+  while (!createdTrees.empty()) {
+    EntityHandle tree = createdTrees.back();
+      // make sure this is a tree (rather than some other, stale handle)
+    const void* data_ptr = 0;
+    ErrorCode rval = moab()->tag_get_data( rootTag, &tree, 1, &data_ptr );
+    if (MB_SUCCESS == rval)
+      rval = delete_tree( tree );
+    if (MB_SUCCESS != rval)
+      createdTrees.pop_back();
+  }
+}
+
+ErrorCode AdaptiveKDTree::set_split_plane( EntityHandle entity, 
+                                               const Plane& plane )
+{
+#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
+  ErrorCode r1, r2;
+  r1 = moab()->tag_set_data( planeTag, &entity, 1, &plane.coord );
+  r2 = moab()->tag_set_data( axisTag , &entity, 1, &plane.norm  );
+  return MB_SUCCESS == r1 ? r2 : r1;
+#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
+  double values[2] = { plane.coord, plane.norm };
+  return moab()->tag_set_data( planeTag, &entity, 1, values );
+#else
+  return moab()->tag_set_data( planeTag, &entity, 1, &plane );
+#endif
+}
+
+
+ErrorCode AdaptiveKDTree::set_tree_box( EntityHandle root_handle,
+                                            const double box_min[3],
+                                            const double box_max[3] )
+{
+  const double box[6] = { box_min[0], box_min[1], box_min[2],
+                          box_max[0], box_max[1], box_max[2] };
+  return moab()->tag_set_data( rootTag, &root_handle, 1, box );
+}
+
+ErrorCode AdaptiveKDTree::get_tree_box( EntityHandle root_handle,
+                                            double box_min_out[3],
+                                            double box_max_out[3] )
+{
+  double box[6];
+  ErrorCode rval = moab()->tag_get_data( rootTag, &root_handle, 1, box );
+  box_min_out[0] = box[0]; box_min_out[1] = box[1]; box_min_out[2] = box[2];
+  box_max_out[0] = box[3]; box_max_out[1] = box[4]; box_max_out[2] = box[5];
+  return rval;
+}
+
+
+ErrorCode AdaptiveKDTree::create_tree( const double box_min[3],
+                                           const double box_max[3],
+                                           EntityHandle& root_handle )
+{
+  ErrorCode rval = moab()->create_meshset( meshSetFlags, root_handle );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = set_tree_box( root_handle, box_min, box_max );
+  if (MB_SUCCESS != rval) {
+    moab()->delete_entities( &root_handle, 1 );
+    root_handle = 0;
+    return rval;
+  }
+  
+  createdTrees.push_back( root_handle );
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTree::delete_tree( EntityHandle root_handle )
+{
+  ErrorCode rval;
+  
+  std::vector<EntityHandle> children, dead_sets, current_sets;
+  createdTrees.erase( 
+        std::remove( createdTrees.begin(), createdTrees.end(), root_handle ),
+        createdTrees.end() );
+  
+  current_sets.push_back( root_handle );
+  while (!current_sets.empty()) {
+    EntityHandle set = current_sets.back();
+    current_sets.pop_back();
+    dead_sets.push_back( set );
+    rval = moab()->get_child_meshsets( set, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+    std::copy( children.begin(), children.end(), std::back_inserter(current_sets) );
+    children.clear();
+  }
+  
+  rval = moab()->tag_delete_data( rootTag, &root_handle, 1 );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  return moab()->delete_entities( &dead_sets[0], dead_sets.size() );
+}
+
+ErrorCode AdaptiveKDTree::find_all_trees( Range& results )
+{
+  return moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, 
+                                               &rootTag, 0, 1,
+                                               results );
+}
+
+ErrorCode AdaptiveKDTree::get_tree_iterator( EntityHandle root,
+                                                 AdaptiveKDTreeIter& iter )
+{
+  double box[6];
+  ErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, box );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  return get_sub_tree_iterator( root, box, box+3, iter );
+}
+
+ErrorCode AdaptiveKDTree::get_last_iterator( EntityHandle root,
+                                                 AdaptiveKDTreeIter& iter )
+{
+  double box[6];
+  ErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, box );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  return iter.initialize( this, root, box, box+3, AdaptiveKDTreeIter::RIGHT );
+}
+
+ErrorCode AdaptiveKDTree::get_sub_tree_iterator( EntityHandle root,
+                                                     const double min[3], 
+                                                     const double max[3],
+                                                     AdaptiveKDTreeIter& result ) 
+{
+  return result.initialize( this, root, min, max, AdaptiveKDTreeIter::LEFT );
+}
+
+ErrorCode AdaptiveKDTree::split_leaf( AdaptiveKDTreeIter& leaf,
+                                          Plane plane,
+                                          EntityHandle& left,
+                                          EntityHandle& right )
+{
+  ErrorCode rval;
+  
+  rval = moab()->create_meshset( meshSetFlags, left );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = moab()->create_meshset( meshSetFlags, right );
+  if (MB_SUCCESS != rval) {
+    moab()->delete_entities( &left, 1 );
+    return rval;
+  }
+  
+  if (MB_SUCCESS != set_split_plane( leaf.handle(), plane ) ||
+      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), left ) ||
+      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), right) ||
+      MB_SUCCESS != leaf.step_to_first_leaf(AdaptiveKDTreeIter::LEFT)) {
+    EntityHandle children[] = { left, right };
+    moab()->delete_entities( children, 2 );
+    return MB_FAILURE;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTree::split_leaf( AdaptiveKDTreeIter& leaf,
+                                          Plane plane )
+{
+  EntityHandle left, right;
+  return split_leaf( leaf, plane, left, right );
+}
+
+ErrorCode AdaptiveKDTree::split_leaf( AdaptiveKDTreeIter& leaf, 
+                                          Plane plane,
+                                          const Range& left_entities,
+                                          const Range& right_entities )
+{
+  EntityHandle left, right, parent = leaf.handle();
+  ErrorCode rval = split_leaf( leaf, plane, left, right );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (MB_SUCCESS == moab()->add_entities( left, left_entities ) &&
+      MB_SUCCESS == moab()->add_entities(right,right_entities ) &&
+      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
+    return MB_SUCCESS;
+  
+  moab()->remove_child_meshset( parent, left );
+  moab()->remove_child_meshset( parent, right );
+  EntityHandle children[] = { left, right };
+  moab()->delete_entities( children, 2 );
+  return MB_FAILURE;
+}
+
+ErrorCode AdaptiveKDTree::split_leaf( AdaptiveKDTreeIter& leaf, 
+                                          Plane plane,
+                                          const std::vector<EntityHandle>& left_entities,
+                                          const std::vector<EntityHandle>& right_entities )
+{
+  EntityHandle left, right, parent = leaf.handle();
+  ErrorCode rval = split_leaf( leaf, plane, left, right );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (MB_SUCCESS == moab()->add_entities( left, &left_entities[0], left_entities.size() ) &&
+      MB_SUCCESS == moab()->add_entities(right,&right_entities[0],right_entities.size() ) &&
+      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
+    return MB_SUCCESS;
+  
+  moab()->remove_child_meshset( parent, left );
+  moab()->remove_child_meshset( parent, right );
+  EntityHandle children[] = { left, right };
+  moab()->delete_entities( children, 2 );
+  return MB_FAILURE;
+}
+
+ErrorCode AdaptiveKDTree::merge_leaf( AdaptiveKDTreeIter& iter )
+{
+  ErrorCode rval;
+  if (iter.depth() == 1) // at root
+    return MB_FAILURE;
+  
+    // Move iter to parent
+  
+  AdaptiveKDTreeIter::StackObj node = iter.mStack.back();
+  iter.mStack.pop_back();
+  
+  iter.childVect.clear();
+  rval = moab()->get_child_meshsets( iter.mStack.back().entity, iter.childVect );
+  if (MB_SUCCESS != rval)
+    return rval;
+  Plane plane;
+  rval = get_split_plane( iter.mStack.back().entity, plane );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  int child_idx = iter.childVect[0] == node.entity ? 0 : 1;
+  assert(iter.childVect[child_idx] == node.entity);
+  iter.mBox[1-child_idx][plane.norm] = node.coord;
+  
+
+    // Get all entities from children and put them in parent
+  EntityHandle parent = iter.handle();
+  moab()->remove_child_meshset( parent, iter.childVect[0] );
+  moab()->remove_child_meshset( parent, iter.childVect[1] );
+  std::vector<EntityHandle> stack( iter.childVect );
+  
+  Range range;
+  while (!stack.empty()) {
+    EntityHandle h = stack.back();
+    stack.pop_back();
+    range.clear();
+    rval = moab()->get_entities_by_handle( h, range );
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = moab()->add_entities( parent, range );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    iter.childVect.clear();
+    moab()->get_child_meshsets( h, iter.childVect );
+    if (!iter.childVect.empty()) {
+     moab()->remove_child_meshset( h, iter.childVect[0] );
+     moab()->remove_child_meshset( h, iter.childVect[1] );
+     stack.push_back( iter.childVect[0] );
+     stack.push_back( iter.childVect[1] );
+    }
+  
+    rval = moab()->delete_entities( &h, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+  
+
+ErrorCode AdaptiveKDTreeIter::initialize( AdaptiveKDTree* tool,
+                                              EntityHandle root,
+                                              const double box_min[3],
+                                              const double box_max[3],
+                                              Direction direction )
+{
+  mStack.clear();
+  treeTool = tool;
+  mBox[BMIN][0] = box_min[0];
+  mBox[BMIN][1] = box_min[1];
+  mBox[BMIN][2] = box_min[2];
+  mBox[BMAX][0] = box_max[0];
+  mBox[BMAX][1] = box_max[1];
+  mBox[BMAX][2] = box_max[2];
+  mStack.push_back( StackObj(root,0) );
+  return step_to_first_leaf( direction );
+}
+
+ErrorCode AdaptiveKDTreeIter::step_to_first_leaf( Direction direction )
+{
+  ErrorCode rval;
+  AdaptiveKDTree::Plane plane;
+  const Direction opposite = static_cast<Direction>(1-direction);
+  
+  for (;;) {
+    childVect.clear();
+    rval = treeTool->moab()->get_child_meshsets( mStack.back().entity, childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (childVect.empty()) // leaf
+      break;
+  
+    rval = treeTool->get_split_plane( mStack.back().entity, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+  
+    mStack.push_back( StackObj(childVect[direction],mBox[opposite][plane.norm]) );
+    mBox[opposite][plane.norm] = plane.coord;
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTreeIter::step( Direction direction )
+{
+  StackObj node, parent;
+  ErrorCode rval;
+  AdaptiveKDTree::Plane plane;
+  const Direction opposite = static_cast<Direction>(1-direction);
+  
+    // If stack is empty, then either this iterator is uninitialized
+    // or we reached the end of the iteration (and return 
+    // MB_ENTITY_NOT_FOUND) already.
+  if (mStack.empty())
+    return MB_FAILURE;
+    
+    // Pop the current node from the stack.
+    // The stack should then contain the parent of the current node.
+    // If the stack is empty after this pop, then we've reached the end.
+  node = mStack.back();
+  mStack.pop_back();
+  
+  while(!mStack.empty()) {
+      // Get data for parent entity
+    parent = mStack.back();
+    childVect.clear();
+    rval = treeTool->moab()->get_child_meshsets( parent.entity, childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = treeTool->get_split_plane( parent.entity, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+      // If we're at the left child
+    if (childVect[opposite] == node.entity) {
+        // change from box of left child to box of parent
+      mBox[direction][plane.norm] = node.coord;
+        // push right child on stack
+      node.entity = childVect[direction];
+      node.coord = mBox[opposite][plane.norm];
+      mStack.push_back( node );
+        // change from box of parent to box of right child
+      mBox[opposite][plane.norm] = plane.coord;
+        // descend to left-most leaf of the right child
+      return step_to_first_leaf(opposite);
+    }
+    
+      // The current node is the right child of the parent,
+      // continue up the tree.
+    assert( childVect[direction] == node.entity );
+    mBox[opposite][plane.norm] = node.coord;
+    node = parent;
+    mStack.pop_back();
+  }
+  
+  return MB_ENTITY_NOT_FOUND;
+}
+
+ErrorCode AdaptiveKDTreeIter::get_neighbors( 
+                      AdaptiveKDTree::Axis norm, bool neg,
+                      std::vector<AdaptiveKDTreeIter>& results,
+                      double epsilon ) const
+{
+  StackObj node, parent;
+  ErrorCode rval;
+  AdaptiveKDTree::Plane plane;
+  int child_idx;
+  
+    // Find tree node at which the specified side of the box
+    // for this node was created.
+  AdaptiveKDTreeIter iter( *this ); // temporary iterator (don't modifiy *this)
+  node = iter.mStack.back();
+  iter.mStack.pop_back();
+  for (;;) {
+      // reached the root - original node was on boundary (no neighbors)
+    if (iter.mStack.empty())
+      return MB_SUCCESS;
+    
+      // get parent node data
+    parent = iter.mStack.back();
+    iter.childVect.clear();
+    rval = treeTool->moab()->get_child_meshsets( parent.entity, iter.childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = treeTool->get_split_plane( parent.entity, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    child_idx = iter.childVect[0] == node.entity ? 0 : 1;
+    assert(iter.childVect[child_idx] == node.entity);
+    
+      // if we found the split plane for the desired side
+      // push neighbor on stack and stop
+    if (plane.norm == norm && (int)neg == child_idx) {
+        // change from box of previous child to box of parent
+      iter.mBox[1-child_idx][plane.norm] = node.coord;
+        // push other child of parent onto stack
+      node.entity = iter.childVect[1-child_idx];
+      node.coord = iter.mBox[child_idx][plane.norm];
+      iter.mStack.push_back( node );
+        // change from parent box to box of new child
+      iter.mBox[child_idx][plane.norm] = plane.coord;
+      break;
+    }
+    
+      // continue up the tree
+    iter.mBox[1-child_idx][plane.norm] = node.coord;
+    node = parent;
+    iter.mStack.pop_back();
+  }
+
+    // now move down tree, searching for adjacent boxes
+  std::vector<AdaptiveKDTreeIter> list;
+    // loop over all potential paths to neighbors (until list is empty)
+  for (;;) {
+      // follow a single path to a leaf, append any other potential
+      // paths to neighbors to 'list'
+    node = iter.mStack.back();
+    for (;;) { 
+      iter.childVect.clear();
+      rval = treeTool->moab()->get_child_meshsets( node.entity, iter.childVect );
+      if (MB_SUCCESS != rval)
+        return rval;
+        
+        // if leaf
+      if (iter.childVect.empty()) {
+        results.push_back( iter );
+        break; 
+      }
+      
+      rval = treeTool->get_split_plane( node.entity, plane );
+      if (MB_SUCCESS != rval)
+        return rval;
+     
+        // if split parallel to side
+      if (plane.norm == norm) {
+          // continue with whichever child is on the correct side of the split
+        node.entity = iter.childVect[neg];
+        node.coord = iter.mBox[1-neg][plane.norm];
+        iter.mStack.push_back( node );
+        iter.mBox[1-neg][plane.norm] = plane.coord;
+      }
+        // if left child is adjacent
+      else if (this->mBox[BMIN][plane.norm] - plane.coord <= epsilon) {
+          // if right child is also adjacent, add to list
+        if (plane.coord - this->mBox[BMAX][plane.norm] <= epsilon) {
+          list.push_back( iter );
+          list.back().mStack.push_back( StackObj( iter.childVect[1], iter.mBox[BMIN][plane.norm] ) );
+          list.back().mBox[BMIN][plane.norm] = plane.coord;
+        }
+          // continue with left child
+        node.entity = iter.childVect[0];
+        node.coord = iter.mBox[BMAX][plane.norm];
+        iter.mStack.push_back( node );
+        iter.mBox[BMAX][plane.norm] = plane.coord;
+      }
+        // right child is adjacent
+      else {
+          // if left child is not adjacent, right must be or something
+          // is really messed up.
+        assert(plane.coord - this->mBox[BMAX][plane.norm] <= epsilon);
+           // continue with left child
+        node.entity = iter.childVect[1];
+        node.coord = iter.mBox[BMIN][plane.norm];
+        iter.mStack.push_back( node );
+        iter.mBox[BMIN][plane.norm] = plane.coord;
+      }
+    }
+    
+    if (list.empty())
+      break;
+    
+    iter = list.back();
+    list.pop_back();
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTreeIter::sibling_side( 
+                            AdaptiveKDTree::Axis& axis_out,
+                            bool& neg_out ) const
+{
+  if (mStack.size() < 2) // at tree root
+    return MB_ENTITY_NOT_FOUND;
+  
+  EntityHandle parent = mStack[mStack.size()-2].entity;
+  AdaptiveKDTree::Plane plane;
+  ErrorCode rval = tool()->get_split_plane( parent, plane );
+  if (MB_SUCCESS != rval)
+    return MB_FAILURE;
+    
+  childVect.clear();
+  rval = tool()->moab()->get_child_meshsets( parent, childVect );
+  if (MB_SUCCESS != rval || childVect.size() != 2)
+    return MB_FAILURE;
+  
+  axis_out = static_cast<AdaptiveKDTree::Axis>(plane.norm);
+  neg_out = (childVect[1] == handle());
+  assert(childVect[neg_out] == handle());
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTreeIter::get_parent_split_plane( AdaptiveKDTree::Plane& plane ) const
+{
+  if (mStack.size() < 2) // at tree root
+    return MB_ENTITY_NOT_FOUND;
+  
+  EntityHandle parent = mStack[mStack.size()-2].entity;
+  return tool()->get_split_plane( parent, plane );
+}
+
+
+bool AdaptiveKDTreeIter::is_sibling( const AdaptiveKDTreeIter& other_leaf ) const
+{
+  const size_t s = mStack.size();
+  return (s > 1) && (s == other_leaf.mStack.size()) &&
+         (other_leaf.mStack[s-2].entity == mStack[s-2].entity) &&
+         other_leaf.handle() != handle();
+}
+
+bool AdaptiveKDTreeIter::is_sibling( EntityHandle other_leaf ) const
+{
+  if (mStack.size() < 2 || other_leaf == handle())
+    return false;
+  EntityHandle parent = mStack[mStack.size()-2].entity;
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
+  if (MB_SUCCESS != rval || childVect.size() != 2) {
+    assert(false);
+    return false;
+  }
+  return childVect[0] == other_leaf || childVect[1] == other_leaf;
+}
+
+bool AdaptiveKDTreeIter::sibling_is_forward() const
+{
+  if (mStack.size() < 2) // if root
+    return false;
+  EntityHandle parent = mStack[mStack.size()-2].entity;
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
+  if (MB_SUCCESS != rval || childVect.size() != 2) {
+    assert(false);
+    return false;
+  }
+  return childVect[0] == handle();
+}  
+
+bool AdaptiveKDTreeIter::intersect_ray( const double ray_point[3],
+                                          const double ray_vect[3],
+                                          double& t_enter, 
+                                          double& t_exit ) const
+{
+  return GeomUtil::ray_box_intersect( CartVect(box_min()),
+                                        CartVect(box_max()),
+                                        CartVect(ray_point),
+                                        CartVect(ray_vect),
+                                        t_enter, t_exit );
+}
+
+static ErrorCode intersect_children_with_elems(
+                                        AdaptiveKDTree* tool,
+                                        const Range& elems,
+                                        AdaptiveKDTree::Plane plane,
+                                        double eps,
+                                        CartVect box_min,
+                                        CartVect box_max,
+                                        Range& left_tris,
+                                        Range& right_tris,
+                                        Range& both_tris,
+                                        double& metric_value )
+{
+  left_tris.clear();
+  right_tris.clear();
+  both_tris.clear();
+  CartVect coords[16];
+  Interface *const moab = tool->moab();
+  
+    // get extents of boxes for left and right sides
+  CartVect right_min( box_min ), left_max( box_max );
+  right_min[plane.norm] = left_max[plane.norm] = plane.coord;
+  const CartVect left_cen = 0.5*(left_max + box_min);
+  const CartVect left_dim = 0.5*(left_max - box_min);
+  const CartVect right_cen = 0.5*(box_max + right_min);
+  const CartVect right_dim = 0.5*(box_max - right_min);
+  const CartVect dim = box_max - box_min;
+  
+  
+    // test each entity
+  ErrorCode rval;
+  int count, count2;
+  const EntityHandle* conn, *conn2;
+  
+  const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
+  const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
+  const Range::const_iterator set_begin = elems.lower_bound( MBENTITYSET, poly_begin );
+  Range::iterator left_ins = left_tris.begin();
+  Range::iterator right_ins = right_tris.begin();
+  Range::iterator both_ins = both_tris.begin();
+  Range::const_iterator i;
+  
+    // vertices
+  for (i = elems.begin(); i != elem_begin; ++i) {
+    rval = moab->get_coords( &*i, 1, coords[0].array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    bool lo = false, ro = false;
+    if (coords[0][plane.norm] <= plane.coord)
+      lo = true;
+    if (coords[0][plane.norm] >= plane.coord)
+      ro = true;
+
+    if (lo && ro)
+      both_ins = both_tris.insert( both_ins, *i, *i );
+    else if (lo)
+      left_ins = left_tris.insert( left_ins, *i, *i );
+    else // if (ro)
+      right_ins = right_tris.insert( right_ins, *i, *i );
+  }
+  
+    // non-polyhedron elements
+  for (i = elem_begin; i != poly_begin; ++i) {
+    rval = moab->get_connectivity( *i, conn, count, true );
+    if (MB_SUCCESS != rval) 
+      return rval;
+    if (count > (int)(sizeof(coords)/sizeof(coords[0])))
+      return MB_FAILURE;
+    rval = moab->get_coords( &conn[0], count, coords[0].array() );
+    if (MB_SUCCESS != rval) return rval;
+    
+    bool lo = false, ro = false;
+    for (int j = 0; j < count; ++j) {
+      if (coords[j][plane.norm] <= plane.coord)
+        lo = true;
+      if (coords[j][plane.norm] >= plane.coord)
+        ro = true;
+    }
+    
+      // Triangle must be in at least one leaf.  If test against plain
+      // identified that leaf, then we're done.  If triangle is on both
+      // sides of plane, do more precise test to ensure that it is really
+      // in both.
+    if (lo && ro) {
+      lo = GeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen, left_dim );
+      ro = GeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim );
+      double tol = std::numeric_limits<double>::epsilon();
+        // didn't intersect either - tolerance issue
+      while (!lo && !ro && tol < eps) {
+        lo = GeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen,left_dim+tol*dim );
+        ro = GeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim+tol*dim );
+        tol *= 10.0;
+      }
+    }
+    if (lo && ro)
+      both_ins = both_tris.insert( both_ins, *i, *i );
+    else if (lo)
+      left_ins = left_tris.insert( left_ins, *i, *i );
+    else if (ro)
+      right_ins = right_tris.insert( right_ins, *i, *i );
+  }
+  
+    // polyhedra
+  for (i = poly_begin; i != set_begin; ++i) {
+    rval = moab->get_connectivity( *i, conn, count, true );
+    if (MB_SUCCESS != rval) 
+      return rval;
+      
+      // just check the bounding box of the polyhedron
+    bool lo = false, ro = false;
+    for (int j = 0; j < count; ++j) {
+      rval = moab->get_connectivity( conn[j], conn2, count2, true );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      for (int k = 0; k < count2; ++k) {
+        rval = moab->get_coords( conn2 + k, 1, coords[0].array() );
+        if (MB_SUCCESS != rval)
+          return rval;
+        if (coords[0][plane.norm] <= plane.coord)
+          lo = true;
+        if (coords[0][plane.norm] >= plane.coord)
+          ro = true;
+      }
+    }
+    
+    if (lo && ro)
+      both_ins = both_tris.insert( both_ins, *i, *i );
+    else if (lo)
+      left_ins = left_tris.insert( left_ins, *i, *i );
+    else if (ro)
+      right_ins = right_tris.insert( right_ins, *i, *i );
+  }
+  
+    // sets
+  CartVect tmin, tmax;
+  for (i = set_begin; i != elems.end(); ++i) {
+    rval = tool->get_tree_box( *i, tmin.array(), tmax.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    bool lo = false, ro = false;
+    if (tmin[plane.norm] <= plane.coord)
+      lo = true;
+    if (tmax[plane.norm] >= plane.coord)
+      ro = true;
+
+    if (lo && ro)
+      both_ins = both_tris.insert( both_ins, *i, *i );
+    else if (lo)
+      left_ins = left_tris.insert( left_ins, *i, *i );
+    else // if (ro)
+      right_ins = right_tris.insert( right_ins, *i, *i );
+  }
+  
+  
+  CartVect box_dim = box_max - box_min;
+  double area_left = left_dim[0]*left_dim[1] + left_dim[1]*left_dim[2] + left_dim[2]*left_dim[0];
+  double area_right = right_dim[0]*right_dim[1] + right_dim[1]*right_dim[2] + right_dim[2]*right_dim[0];
+  double area_both = box_dim[0]*box_dim[1] + box_dim[1]*box_dim[2] + box_dim[2]*box_dim[0];
+  metric_value = (area_left * left_tris.size() + area_right * right_tris.size()) / area_both + both_tris.size();
+  return MB_SUCCESS;
+}
+
+static ErrorCode best_subdivision_plane( int num_planes,
+                                           const AdaptiveKDTreeIter& iter,
+                                           Range& best_left,
+                                           Range& best_right,
+                                           Range& best_both,
+                                           AdaptiveKDTree::Plane& best_plane,
+                                           double eps )
+{
+  double metric_val = std::numeric_limits<unsigned>::max();
+  
+  ErrorCode r;
+  const CartVect box_min(iter.box_min());
+  const CartVect box_max(iter.box_max());
+  const CartVect diff(box_max - box_min);
+  
+  Range entities;
+  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
+  if (MB_SUCCESS != r)
+    return r;
+  const size_t p_count = entities.size();
+  
+  for (int axis = 0; axis < 3; ++axis) {
+    int plane_count = num_planes;
+    if ((num_planes+1)*eps >= diff[axis])
+      plane_count = (int)(diff[axis] / eps) - 1;
+  
+    for (int p = 1; p <= plane_count; ++p) {
+      AdaptiveKDTree::Plane plane = { box_min[axis] + (p/(1.0+plane_count)) * diff[axis], axis };
+      Range left, right, both;
+      double val;
+      r = intersect_children_with_elems( iter.tool(),
+                                         entities, plane, eps,
+                                         box_min, box_max,
+                                         left, right, both, 
+                                         val );
+      if (MB_SUCCESS != r)
+        return r;
+      const size_t diff = p_count - both.size();
+      if (left.size() == diff || right.size() == diff)
+        continue;
+      
+      if (val >= metric_val)
+        continue;
+      
+      metric_val = val;
+      best_plane = plane;
+      best_left.swap(left);
+      best_right.swap(right);
+      best_both.swap(both);
+    }
+  }
+      
+  return MB_SUCCESS;
+}
+
+
+static ErrorCode best_subdivision_snap_plane( int num_planes,
+                                           const AdaptiveKDTreeIter& iter,
+                                           Range& best_left,
+                                           Range& best_right,
+                                           Range& best_both,
+                                           AdaptiveKDTree::Plane& best_plane,
+                                           std::vector<double>& tmp_data,
+                                           double eps )
+{
+  double metric_val = std::numeric_limits<unsigned>::max();
+  
+  ErrorCode r;
+  const CartVect box_min(iter.box_min());
+  const CartVect box_max(iter.box_max());
+  const CartVect diff(box_max - box_min);
+  const CartVect tol(eps*diff);
+  
+  Range entities, vertices;
+  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
+  if (MB_SUCCESS != r)
+    return r;
+  const size_t p_count = entities.size();
+  r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, Interface::UNION );
+  if (MB_SUCCESS != r)
+    return r;
+
+  tmp_data.resize( vertices.size() );
+  for (int axis = 0; axis < 3; ++axis) {
+    int plane_count = num_planes;
+    if ((num_planes+1)*eps >= diff[axis])
+      plane_count = (int)(diff[axis] / eps) - 1;
+
+    double *ptrs[] = { 0, 0, 0 };
+    ptrs[axis] = &tmp_data[0];
+    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
+    if (MB_SUCCESS != r)
+      return r;
+  
+    for (int p = 1; p <= plane_count; ++p) {
+      double coord = box_min[axis] + (p/(1.0+plane_count)) * diff[axis];
+      double closest_coord = tmp_data[0];
+      for (unsigned i = 1; i < tmp_data.size(); ++i) 
+        if (fabs(coord-tmp_data[i]) < fabs(coord-closest_coord))
+          closest_coord = tmp_data[i];
+      if (closest_coord - box_min[axis] <= eps || box_max[axis] - closest_coord <= eps)
+        continue;
+          
+      AdaptiveKDTree::Plane plane = { closest_coord, axis };
+      Range left, right, both;
+      double val;
+      r = intersect_children_with_elems( iter.tool(),
+                                         entities, plane, eps,
+                                         box_min, box_max,
+                                         left, right, both, 
+                                         val );
+      if (MB_SUCCESS != r)
+        return r;
+      const size_t d = p_count - both.size();
+      if (left.size() == d || right.size() == d)
+        continue;
+      
+      if (val >= metric_val)
+        continue;
+      
+      metric_val = val;
+      best_plane = plane;
+      best_left.swap(left);
+      best_right.swap(right);
+      best_both.swap(both);
+    }
+  }
+     
+  return MB_SUCCESS;
+}
+
+static ErrorCode best_vertex_median_plane( int num_planes,
+                                           const AdaptiveKDTreeIter& iter,
+                                           Range& best_left,
+                                           Range& best_right,
+                                           Range& best_both,
+                                           AdaptiveKDTree::Plane& best_plane,
+                                           std::vector<double>& coords,
+                                           double eps)
+{
+  double metric_val = std::numeric_limits<unsigned>::max();
+  
+  ErrorCode r;
+  const CartVect box_min(iter.box_min());
+  const CartVect box_max(iter.box_max());
+  
+  Range entities, vertices;
+  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
+  if (MB_SUCCESS != r)
+    return r;
+  const size_t p_count = entities.size();
+  r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, Interface::UNION );
+  if (MB_SUCCESS != r)
+    return r;
+
+  coords.resize( vertices.size() );
+  for (int axis = 0; axis < 3; ++axis) {
+    if (box_max[axis] - box_min[axis] <= 2*eps)
+      continue;
+  
+    double *ptrs[] = { 0, 0, 0 };
+    ptrs[axis] = &coords[0];
+    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
+    if (MB_SUCCESS != r)
+      return r;
+  
+    std::sort( coords.begin(), coords.end() );
+    std::vector<double>::iterator citer;
+    citer = std::upper_bound( coords.begin(), coords.end(), box_min[axis] + eps );
+    const size_t count = std::upper_bound( citer, coords.end(), box_max[axis] - eps ) - citer;
+    size_t step;
+    int np = num_planes;
+    if (count < 2*(size_t)num_planes) {
+      step = 1; np = count - 1;
+    }
+    else {
+      step = count / (num_planes + 1);
+    }
+  
+    for (int p = 1; p <= np; ++p) {
+      
+      citer += step;
+      AdaptiveKDTree::Plane plane = { *citer, axis };
+      Range left, right, both;
+      double val;
+      r = intersect_children_with_elems( iter.tool(),
+                                         entities, plane, eps,
+                                         box_min, box_max,
+                                         left, right, both, 
+                                         val );
+      if (MB_SUCCESS != r)
+        return r;
+      const size_t diff = p_count - both.size();
+      if (left.size() == diff || right.size() == diff)
+        continue;
+      
+      if (val >= metric_val)
+        continue;
+      
+      metric_val = val;
+      best_plane = plane;
+      best_left.swap(left);
+      best_right.swap(right);
+      best_both.swap(both);
+    }
+  }
+      
+  return MB_SUCCESS;
+}
+
+
+static ErrorCode best_vertex_sample_plane( int num_planes,
+                                           const AdaptiveKDTreeIter& iter,
+                                           Range& best_left,
+                                           Range& best_right,
+                                           Range& best_both,
+                                           AdaptiveKDTree::Plane& best_plane,
+                                           std::vector<double>& coords,
+                                           std::vector<EntityHandle>& indices,
+                                           double eps )
+{
+  const size_t random_elem_threshold = 20*num_planes;
+  double metric_val = std::numeric_limits<unsigned>::max();
+  
+  ErrorCode r;
+  const CartVect box_min(iter.box_min());
+  const CartVect box_max(iter.box_max());
+  
+  Range entities, vertices;
+  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
+  if (MB_SUCCESS != r)
+    return r;
+    
+    // We are selecting random vertex coordinates to use for candidate split
+    // planes.  So if element list is large, begin by selecting random elements.
+  const size_t p_count = entities.size();
+  coords.resize( 3*num_planes );
+  if (p_count < random_elem_threshold) {
+    r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, Interface::UNION );
+    if (MB_SUCCESS != r)
+      return r;
+  }
+  else {
+    indices.resize(random_elem_threshold);
+    const int num_rand = p_count / RAND_MAX + 1;
+    for (size_t j = 0; j < random_elem_threshold; ++j) {
+      size_t rnd = rand();
+      for (int i = num_rand; i > 1; --i)
+        rnd *= rand();
+      rnd %= p_count;
+      indices[j] = entities[rnd];
+    }
+    r = iter.tool()->moab()->get_adjacencies( &indices[0], random_elem_threshold, 0, false, vertices, Interface::UNION );
+    if (MB_SUCCESS != r)
+      return r;
+  }
+
+  coords.resize( vertices.size() );
+  for (int axis = 0; axis < 3; ++axis) {
+    if (box_max[axis] - box_min[axis] <= 2*eps)
+      continue;
+  
+    double *ptrs[] = { 0, 0, 0 };
+    ptrs[axis] = &coords[0];
+    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
+    if (MB_SUCCESS != r)
+      return r;
+      
+    size_t num_valid_coords = 0;
+    for (size_t i = 0; i < coords.size(); ++i) 
+      if (coords[i] > box_min[axis]+eps && coords[i] < box_max[axis]-eps)
+        ++num_valid_coords;
+      
+    if (2*(size_t)num_planes > num_valid_coords) {
+      indices.clear();
+      for (size_t i = 0; i < coords.size(); ++i) 
+        if (coords[i] > box_min[axis]+eps && coords[i] < box_max[axis]-eps)
+          indices.push_back( i );
+    }
+    else {
+      indices.resize( num_planes );
+        // make sure random indices are sufficient to cover entire range
+      const int num_rand = coords.size() / RAND_MAX + 1;
+      for (int j = 0; j < num_planes; ++j)
+      {
+        size_t rnd;
+        do { 
+          rnd = rand();
+          for (int i = num_rand; i > 1; --i)
+            rnd *= rand();
+          rnd %= coords.size();
+        } while (coords[rnd] <= box_min[axis]+eps || coords[rnd] >= box_max[axis]-eps);
+        indices[j] = rnd;
+      }
+    }
+  
+    for (unsigned p = 0; p < indices.size(); ++p) {
+      
+      AdaptiveKDTree::Plane plane = { coords[indices[p]], axis };
+      Range left, right, both;
+      double val;
+      r = intersect_children_with_elems( iter.tool(),
+                                         entities, plane, eps,
+                                         box_min, box_max,
+                                         left, right, both, 
+                                         val );
+      if (MB_SUCCESS != r)
+        return r;
+      const size_t diff = p_count - both.size();
+      if (left.size() == diff || right.size() == diff)
+        continue;
+      
+      if (val >= metric_val)
+        continue;
+      
+      metric_val = val;
+      best_plane = plane;
+      best_left.swap(left);
+      best_right.swap(right);
+      best_both.swap(both);
+    }
+  }
+      
+  return MB_SUCCESS;
+}
+
+static inline void box_accum( const CartVect& point,
+                              CartVect& bmin,
+                              CartVect& bmax )
+{
+  for (unsigned j = 0; j < 3; ++j) {
+    if (point[j] < bmin[j])
+      bmin[j] = point[j];
+    if (point[j] > bmax[j])
+      bmax[j] = point[j];
+  }
+}
+
+ErrorCode AdaptiveKDTree::bounding_box( const Range& elems,
+                                            double box_min[3],
+                                            double box_max[3] )
+{
+  ErrorCode rval;
+  CartVect bmin(HUGE_VAL), bmax(-HUGE_VAL);
+  CartVect coords;
+  EntityHandle const *conn, *conn2;
+  int len, len2;
+  Range::const_iterator i;
+  
+    // vertices
+  const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
+  for (i = elems.begin(); i != elem_begin; ++i) {
+    rval = moab()->get_coords( &*i, 1, coords.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    box_accum( coords, bmin, bmax );
+  }
+
+    // elements with vertex-handle connectivity list
+  const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
+  for (i = elem_begin; i != poly_begin; ++i) {
+    rval = moab()->get_connectivity( *i, conn, len, true );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    for (int j = 0; j < len; ++j) {
+      rval = moab()->get_coords( conn+j, 1, coords.array() );
+      if (MB_SUCCESS != rval)
+        return rval;
+      box_accum( coords, bmin, bmax );
+    }
+  }
+  
+    // polyhedra
+  const Range::const_iterator set_begin  = elems.lower_bound( MBENTITYSET, poly_begin );
+  for (i = poly_begin; i != set_begin; ++i) {
+    rval = moab()->get_connectivity( *i, conn, len, true );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    for (int j = 0; j < len; ++j) {
+      rval = moab()->get_connectivity( conn[j], conn2, len2 );
+      for (int k = 0; k < len2; ++k) {
+        rval = moab()->get_coords( conn2+k, 1, coords.array() );
+        if (MB_SUCCESS != rval)
+          return rval;
+        box_accum( coords, bmin, bmax );
+      }
+    }
+  }
+  
+    // sets
+  CartVect tmin, tmax;
+  for (i = set_begin; i != elems.end(); ++i) {
+    rval = get_tree_box( *i, tmin.array(), tmax.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+      
+    for (int j = 0; j < 3; ++j) {
+      if (tmin[j] < bmin[j])
+        bmin[j] = tmin[j];
+      if (tmax[j] > bmax[j])
+        bmax[j] = tmax[j];
+    }
+  }
+  
+  bmin.get( box_min );
+  bmax.get( box_max );
+  return MB_SUCCESS;
+}
+
+
+ErrorCode AdaptiveKDTree::build_tree( const Range& elems,
+                                          EntityHandle& root_set_out,
+                                          const Settings* settings_ptr )
+{
+  ErrorCode rval;
+  Settings settings;
+  if (settings_ptr)
+    settings = *settings_ptr;
+  if (settings.maxEntPerLeaf < 1)
+    settings.maxEntPerLeaf = 1;
+  if (settings.maxTreeDepth < 1)
+    settings.maxTreeDepth = std::numeric_limits<unsigned>::max();
+  if (settings.candidateSplitsPerDir < 1)
+    settings.candidateSplitsPerDir = 1;
+  
+    // calculate bounding box of elements
+  CartVect bmin, bmax;
+  rval = bounding_box( elems, bmin.array(), bmax.array() );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // create tree root
+  rval = create_tree( bmin.array(), bmax.array(), root_set_out );
+  if (MB_SUCCESS != rval)
+    return rval;
+  rval = moab()->add_entities( root_set_out, elems );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  AdaptiveKDTreeIter iter;
+  iter.initialize( this, root_set_out, bmin.array(), bmax.array(), AdaptiveKDTreeIter::LEFT );
+  
+  std::vector<double> tmp_data;
+  std::vector<EntityHandle> tmp_data2;
+  for (;;) {
+  
+    int pcount;
+    rval = moab()->get_number_entities_by_handle( iter.handle(), pcount );
+    if (MB_SUCCESS != rval)
+      break;
+
+    const size_t p_count = pcount;
+    Range best_left, best_right, best_both;
+    Plane best_plane = { HUGE_VAL, -1 };
+    if (p_count > settings.maxEntPerLeaf && iter.depth() < settings.maxTreeDepth) {
+      switch (settings.candidatePlaneSet) {
+        case AdaptiveKDTree::SUBDIVISION:
+          rval = best_subdivision_plane( settings.candidateSplitsPerDir, 
+                                               iter, 
+                                               best_left, 
+                                               best_right, 
+                                               best_both, 
+                                               best_plane, 
+                                               settings.minBoxWidth );
+          break;
+        case AdaptiveKDTree::SUBDIVISION_SNAP:
+          rval = best_subdivision_snap_plane( settings.candidateSplitsPerDir, 
+                                               iter, 
+                                               best_left, 
+                                               best_right, 
+                                               best_both, 
+                                               best_plane, 
+                                               tmp_data, 
+                                               settings.minBoxWidth );
+          break;
+        case AdaptiveKDTree::VERTEX_MEDIAN:
+          rval = best_vertex_median_plane( settings.candidateSplitsPerDir, 
+                                               iter, 
+                                               best_left, 
+                                               best_right, 
+                                               best_both, 
+                                               best_plane, 
+                                               tmp_data, 
+                                               settings.minBoxWidth );
+          break;
+        case AdaptiveKDTree::VERTEX_SAMPLE:
+          rval = best_vertex_sample_plane( settings.candidateSplitsPerDir, 
+                                               iter, 
+                                               best_left, 
+                                               best_right, 
+                                               best_both, 
+                                               best_plane, 
+                                               tmp_data, 
+                                               tmp_data2,
+                                               settings.minBoxWidth );
+          break;
+        default:
+          rval = MB_FAILURE;
+      }
+    
+      if (MB_SUCCESS != rval)
+        return rval;
+    }
+    
+    if (best_plane.norm >= 0) {
+      best_left.merge( best_both );
+      best_right.merge( best_both );
+      rval = split_leaf( iter, best_plane,  best_left, best_right );
+      if (MB_SUCCESS != rval)
+        return rval;
+    }
+    else {
+      rval = iter.step();
+      if (MB_ENTITY_NOT_FOUND == rval) 
+        return MB_SUCCESS;  // at end
+      else if (MB_SUCCESS != rval)
+        break;
+    }
+  }
+  
+  delete_tree( root_set_out );
+  return rval;
+}
+
+ErrorCode AdaptiveKDTree::leaf_containing_point( EntityHandle tree_root,
+                                                     const double point[3],
+                                                     EntityHandle& leaf_out )
+{
+  std::vector<EntityHandle> children;
+  Plane plane;
+  EntityHandle node = tree_root;
+  ErrorCode rval = moab()->get_child_meshsets( node, children );
+  if (MB_SUCCESS != rval)
+    return rval;
+  while (!children.empty()) {
+    rval = get_split_plane( node, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+      
+    const double d = point[plane.norm] - plane.coord;
+    node = children[(d > 0.0)];
+    
+    children.clear();
+    rval = moab()->get_child_meshsets( node, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  leaf_out = node;
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTree::leaf_containing_point( EntityHandle root,
+                                                     const double point[3],
+                                                     AdaptiveKDTreeIter& result )
+{
+    // get bounding box of tree
+  ErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, result.mBox );
+  if (MB_SUCCESS != rval)
+    return rval;
+    
+    // test that point is inside tree
+  if (point[0] < result.box_min()[0] || point[0] > result.box_max()[0] ||
+      point[1] < result.box_min()[1] || point[1] > result.box_max()[1] ||
+      point[2] < result.box_min()[2] || point[2] > result.box_max()[2])
+    return MB_ENTITY_NOT_FOUND;  
+
+    // initialize iterator at tree root
+  result.treeTool = this;
+  result.mStack.clear();
+  result.mStack.push_back( AdaptiveKDTreeIter::StackObj(root,0) );
+    
+    // loop until we reach a leaf
+  AdaptiveKDTree::Plane plane;
+  for(;;) {
+      // get children
+    result.childVect.clear();
+    rval = moab()->get_child_meshsets( result.handle(), result.childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+      
+      // if no children, then at leaf (done)
+    if (result.childVect.empty())
+      break;
+
+      // get split plane
+    rval = get_split_plane( result.handle(), plane );
+    if (MB_SUCCESS != rval) 
+      return rval;
+    
+      // step iterator to appropriate child
+      // idx: 0->left, 1->right
+    const int idx = (point[plane.norm] > plane.coord);
+    result.mStack.push_back( AdaptiveKDTreeIter::StackObj( result.childVect[idx], 
+                                                             result.mBox[1-idx][plane.norm] ) );
+    result.mBox[1-idx][plane.norm] = plane.coord;
+  }
+    
+  return MB_SUCCESS;
+}
+
+struct NodeDistance {
+  EntityHandle handle;
+  CartVect dist; // from_point - closest_point_on_box
+};
+
+ErrorCode AdaptiveKDTree::leaves_within_distance( EntityHandle tree_root,
+                                                      const double from_point[3],
+                                                      const double distance,
+                                                      std::vector<EntityHandle>& result_list )
+{
+  const double dist_sqr = distance * distance;
+  const CartVect from(from_point);
+  std::vector<NodeDistance> list;     // list of subtrees to traverse
+    // pre-allocate space for default max tree depth
+  Settings tmp_settings;
+  list.reserve( tmp_settings.maxTreeDepth );
+
+    // misc temporary values
+  Plane plane;
+  NodeDistance node; 
+  ErrorCode rval;
+  std::vector<EntityHandle> children;
+  
+    // Get distance from input position to bounding box of tree
+    // (zero if inside box)
+  double min[3], max[3];
+  rval = get_tree_box( tree_root, min, max );
+    // if bounding box is not available (e.g. not starting from true root)
+    // just start with zero.  Less efficient, but will work.
+  node.dist = CartVect(0.0);
+  if (MB_SUCCESS == rval) {
+    for (int i = 0; i < 3; ++i) {
+      if (from_point[i] < min[i])
+        node.dist[i] = min[i] - from_point[i];
+      else if (from_point[i] > max[i])
+        node.dist[i] = from_point[i] - max[i];
+    }
+    if (node.dist % node.dist > dist_sqr)
+      return MB_SUCCESS;
+  }
+  
+    // begin with root in list  
+  node.handle = tree_root;
+  list.push_back( node );
+  
+  while( !list.empty() ) {
+
+    node = list.back();
+    list.pop_back();
+      
+      // If leaf node, test contained triangles
+    children.clear();
+    rval = moab()->get_child_meshsets( node.handle, children );
+    if (children.empty()) {
+      result_list.push_back( node.handle );
+      continue;
+    }
+      
+      // If not leaf node, add children to working list
+    rval = get_split_plane( node.handle, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    const double d = from[plane.norm] - plane.coord;
+    
+      // right of plane?
+    if (d > 0) {
+      node.handle = children[1];
+      list.push_back( node );
+        // if the split plane is close to the input point, add
+        // the left child also (we'll check the exact distance
+        /// when we pop it from the list.)
+      if (d <= distance) {
+        node.dist[plane.norm] = d;
+        if (node.dist % node.dist <= dist_sqr) {
+          node.handle = children[0];
+          list.push_back( node );
+        }
+      }
+    }
+      // left of plane
+    else {
+      node.handle = children[0];
+      list.push_back( node );
+        // if the split plane is close to the input point, add
+        // the right child also (we'll check the exact distance
+        /// when we pop it from the list.)
+      if (-d <= distance) {
+        node.dist[plane.norm] = -d;
+        if (node.dist % node.dist <= dist_sqr) {
+          node.handle = children[1];
+          list.push_back( node );
+        }
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+static ErrorCode closest_to_triangles( Interface* moab,
+                                         const Range& tris,
+                                         const CartVect& from,
+                                         double& shortest_dist_sqr,
+                                         CartVect& closest_pt,
+                                         EntityHandle& closest_tri )
+{
+  ErrorCode rval;
+  CartVect pos, diff, verts[3];
+  const EntityHandle* conn;
+  int len;
+      
+  for (Range::iterator i = tris.begin(); i != tris.end(); ++i) {
+    rval = moab->get_connectivity( *i, conn, len );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    rval = moab->get_coords( conn, 3, verts[0].array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    GeomUtil::closest_location_on_tri( from, verts, pos );
+    diff = pos - from;
+    double dist_sqr = diff % diff;
+    if (dist_sqr < shortest_dist_sqr) {
+        // new closest location
+      shortest_dist_sqr = dist_sqr;
+      closest_pt = pos;
+      closest_tri = *i;
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+static ErrorCode closest_to_triangles( Interface* moab,
+                                         EntityHandle set_handle,
+                                         const CartVect& from,
+                                         double& shortest_dist_sqr,
+                                         CartVect& closest_pt,
+                                         EntityHandle& closest_tri )
+{
+  ErrorCode rval;
+  Range tris;
+  
+  rval = moab->get_entities_by_type( set_handle, MBTRI, tris );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  return closest_to_triangles( moab, tris, from, shortest_dist_sqr, closest_pt, closest_tri );
+}
+
+ErrorCode AdaptiveKDTree::find_close_triangle( EntityHandle root,
+                                                   const double from[3],
+                                                   double pt[3],
+                                                   EntityHandle& triangle )
+{
+  ErrorCode rval;
+  Range tris;
+  Plane split;
+  std::vector<EntityHandle> stack;
+  std::vector<EntityHandle> children(2);
+  stack.reserve(30);
+  stack.push_back( root );
+  
+  while (!stack.empty()) {
+    EntityHandle node = stack.back();
+    stack.pop_back();
+    
+    for (;;) {  // loop until we find a leaf
+    
+      children.clear();
+      rval = moab()->get_child_meshsets( node, children );
+      if (MB_SUCCESS != rval)
+        return rval;
+        
+        // loop termination criterion
+      if (children.empty())
+        break;
+      
+        // if not a leaf, get split plane
+      rval = get_split_plane( node, split );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+        // continue down the side that contains the point,
+        // and push the other side onto the stack in case
+        // we need to check it later.
+      int rs = split.right_side( from );
+      node = children[rs];
+      stack.push_back( children[1-rs] );
+    }
+    
+      // We should now be at a leaf.  
+      // If it has some triangles, we're done.
+      // If not, continue searching for another leaf.
+    tris.clear();
+    rval = moab()->get_entities_by_type( node, MBTRI, tris );
+    if (!tris.empty()) {
+      double dist_sqr = HUGE_VAL;
+      CartVect point(pt);
+      rval = closest_to_triangles( moab(), tris, CartVect(from), dist_sqr, point, triangle );
+      point.get(pt);
+      return rval;
+    }
+  }
+  
+    // If we got here, then we traversed the entire tree 
+    // and all the leaves were empty.
+  return MB_ENTITY_NOT_FOUND;
+}
+
+/** Find the triangles in a set that are closer to the input
+ *  position than any triangles in the 'closest_tris' list.
+ *
+ *  closest_tris is assumed to contain a list of triangles for 
+ *  which the first is the closest known triangle to the input 
+ *  position and the first entry in 'closest_pts' is the closest
+ *  location on that triangle.  Any other values in the lists must
+ *  be other triangles for which the closest point is within the
+ *  input tolernace of the closest closest point.  This function
+ *  will update the lists as appropriate if any closer triangles
+ *  or triangles within the tolerance of the current closest location
+ *  are found.  The fisrt entry is maintaned as the closest of the
+ *  list of triangles.
+ */
+/*
+static ErrorCode closest_to_triangles( Interface* moab,
+                                         EntityHandle set_handle,
+                                         double tolerance,
+                                         const CartVect& from,
+                                         std::vector<EntityHandle>& closest_tris,
+                                         std::vector<CartVect>& closest_pts )
+{
+  ErrorCode rval;
+  Range tris;
+  CartVect pos, diff, verts[3];
+  const EntityHandle* conn;
+  int len;
+  double shortest_dist_sqr = HUGE_VAL;
+  if (!closest_pts.empty()) {
+    diff = from - closest_pts.front();
+    shortest_dist_sqr = diff % diff;
+  }
+  
+  rval = moab->get_entities_by_type( set_handle, MBTRI, tris );
+  if (MB_SUCCESS != rval)
+    return rval;
+      
+  for (Range::iterator i = tris.begin(); i != tris.end(); ++i) {
+    rval = moab->get_connectivity( *i, conn, len );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    rval = moab->get_coords( conn, 3, verts[0].array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    GeomUtil::closest_location_on_tri( from, verts, pos );
+    diff = pos - from;
+    double dist_sqr = diff % diff;
+    if (dist_sqr < shortest_dist_sqr) {
+        // new closest location
+      shortest_dist_sqr = dist_sqr;
+
+      if (closest_pts.empty()) {
+        closest_tris.push_back( *i );
+        closest_pts.push_back( pos );
+      }
+        // if have a previous closest location
+      else {
+          // if previous closest is more than 2*tolerance away
+          // from new closest, then nothing in the list can
+          // be within tolerance of new closest point.
+        diff = pos - closest_pts.front();
+        dist_sqr = diff % diff;
+        if (dist_sqr > 4.0 * tolerance * tolerance) {
+          closest_tris.clear();
+          closest_pts.clear();
+          closest_tris.push_back( *i );
+          closest_pts.push_back( pos );
+        }
+          // otherwise need to remove any triangles that are
+          // not within tolerance of the new closest point.
+        else {
+          unsigned r = 0, w = 0;
+          for (r = 0; r < closest_pts.size(); ++r) {
+            diff = pos - closest_pts[r];
+            if (diff % diff <= tolerance*tolerance) {
+              closest_pts[w] = closest_pts[r];
+              closest_tris[w] = closest_tris[r];
+              ++w;
+            }
+          }
+          closest_pts.resize( w + 1 );
+          closest_tris.resize( w + 1 );
+            // always put the closest one in the front
+          if (w > 0) {
+            closest_pts.back() = closest_pts.front();
+            closest_tris.back() = closest_tris.front();
+          }
+          closest_pts.front() = pos;
+          closest_tris.front() = *i;
+        }
+      }
+    }
+    else {
+        // If within tolerance of old closest triangle,
+        // add this one to the list.
+      diff = closest_pts.front() - pos;
+      if (diff % diff <= tolerance*tolerance) {
+        closest_pts.push_back( pos );
+        closest_tris.push_back( *i );
+      }
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+*/
+
+ErrorCode AdaptiveKDTree::closest_triangle( EntityHandle tree_root,
+                                 const double from_coords[3],
+                                 double closest_point_out[3],
+                                 EntityHandle& triangle_out )
+{
+  ErrorCode rval;
+  double shortest_dist_sqr = HUGE_VAL;
+  std::vector<EntityHandle> leaves;
+  const CartVect from(from_coords);
+  CartVect closest_pt;
+  
+    // Find the leaf containing the input point
+    // This search does not take into account any bounding box for the
+    // tree, so it always returns one leaf.
+  rval = find_close_triangle( tree_root, from_coords, closest_pt.array(), triangle_out );
+  if (MB_SUCCESS != rval) return rval;
+  
+    // Find any other leaves for which the bounding box is within
+    // the same distance from the input point as the current closest
+    // point is.
+  CartVect diff = closest_pt - from;
+  rval = leaves_within_distance( tree_root, from_coords, 
+                                 sqrt(diff%diff), leaves );
+  if (MB_SUCCESS != rval) return rval;
+
+    // Check any close leaves to see if they contain triangles that
+    // are as close to or closer than the current closest triangle(s).
+  for (unsigned i = 0; i < leaves.size(); ++i) {
+    rval = closest_to_triangles( moab(), leaves[i], from, shortest_dist_sqr, 
+                                 closest_pt, triangle_out );
+    if (MB_SUCCESS != rval) return rval;
+  }
+  
+    // pass back resulting position
+  closest_pt.get( closest_point_out );
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTree::sphere_intersect_triangles( 
+                                   EntityHandle tree_root,
+                                   const double center[3],
+                                   double radius,
+                                   std::vector<EntityHandle>& triangles )
+{
+  ErrorCode rval;
+  std::vector<EntityHandle> leaves;
+  const CartVect from(center);
+  CartVect closest_pt;
+  const EntityHandle* conn;
+  CartVect coords[3];
+  int conn_len;
+
+    // get leaves of tree that intersect sphere
+  rval = leaves_within_distance( tree_root, center, radius, leaves );
+  if (MB_SUCCESS != rval) return rval;
+  
+    // search each leaf for triangles intersecting sphere
+  for (unsigned i = 0; i < leaves.size(); ++i) {
+    Range tris;
+    rval = moab()->get_entities_by_type( leaves[i], MBTRI, tris );
+    if (MB_SUCCESS != rval) return rval;
+    
+    for (Range::iterator j = tris.begin(); j != tris.end(); ++j) {
+      rval = moab()->get_connectivity( *j, conn, conn_len );
+      if (MB_SUCCESS != rval) return rval;
+      rval = moab()->get_coords( conn, 3, coords[0].array() );
+      if (MB_SUCCESS != rval) return rval;
+      GeomUtil::closest_location_on_tri( from, coords, closest_pt );
+      closest_pt -= from;
+      if ((closest_pt % closest_pt) <= (radius*radius)) 
+        triangles.push_back( *j );
+    }
+  }
+  
+    // remove duplicates from triangle list
+  std::sort( triangles.begin(), triangles.end() );
+  triangles.erase( std::unique( triangles.begin(), triangles.end() ), triangles.end() );
+  return MB_SUCCESS;
+}
+  
+      
+
+struct NodeSeg {
+  NodeSeg( EntityHandle h, double b, double e )
+    : handle(h), beg(b), end(e) {}
+  EntityHandle handle;
+  double beg, end;
+};
+
+ErrorCode AdaptiveKDTree::ray_intersect_triangles( EntityHandle root,
+                                                 const double tol,
+                                                 const double ray_dir_in[3],
+                                                 const double ray_pt_in[3],
+                                                 std::vector<EntityHandle>& tris_out,
+                                                 std::vector<double>& dists_out,
+                                                 int max_ints,
+                                                 double ray_end )
+{
+  ErrorCode rval;
+  double ray_beg = 0.0;
+  if (ray_end < 0.0)
+    ray_end = HUGE_VAL;
+  
+    // if root has bounding box, trim ray to that box
+  CartVect bmin, bmax, tvec(tol);
+  const CartVect ray_pt( ray_pt_in ), ray_dir( ray_dir_in );
+  rval = get_tree_box( root, bmin.array(), bmax.array() );
+  if (MB_SUCCESS == rval) {
+    if (!GeomUtil::segment_box_intersect( bmin-tvec, bmax+tvec, ray_pt, ray_dir, ray_beg, ray_end ))
+      return MB_SUCCESS; // ray misses entire tree.
+  }
+  
+  Range tris;
+  Range::iterator iter;
+  CartVect tri_coords[3];
+  const EntityHandle* tri_conn;
+  int conn_len;
+  double tri_t;
+  
+  Plane plane;
+  std::vector<EntityHandle> children;
+  std::vector<NodeSeg> list;
+  NodeSeg seg(root, ray_beg, ray_end);
+  list.push_back( seg );
+  
+  while (!list.empty()) {
+    seg = list.back();
+    list.pop_back();
+    
+      // If we are limited to a certain number of intersections
+      // (max_ints != 0), then ray_end will contain the distance
+      // to the furthest intersection we have so far.  If the
+      // tree node is further than that, skip it.
+    if (seg.beg > ray_end) 
+      continue;
+
+      // Check if at a leaf 
+    children.clear();
+    rval = moab()->get_child_meshsets( seg.handle, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (children.empty()) { // leaf
+
+      tris.clear();
+      rval = moab()->get_entities_by_type( seg.handle, MBTRI, tris );
+      if (MB_SUCCESS != rval)
+        return rval;
+    
+      for (iter = tris.begin(); iter != tris.end(); ++iter) {
+        rval = moab()->get_connectivity( *iter, tri_conn, conn_len );
+        if (MB_SUCCESS != rval) return rval;
+        rval = moab()->get_coords( tri_conn, 3, tri_coords[0].array() );
+        if (MB_SUCCESS != rval) return rval;
+        
+        if (GeomUtil::ray_tri_intersect( tri_coords, ray_pt, ray_dir, tol, tri_t, &ray_end )) {
+          if (!max_ints) {
+            if (std::find(tris_out.begin(),tris_out.end(),*iter) == tris_out.end()) {
+              tris_out.push_back( *iter );
+              dists_out.push_back( tri_t );
+            }
+          } 
+          else if (tri_t < ray_end) {
+            if (std::find(tris_out.begin(),tris_out.end(),*iter) == tris_out.end()) {
+              if (tris_out.size() < (unsigned)max_ints) {
+                tris_out.resize( tris_out.size() + 1 );
+                dists_out.resize( dists_out.size() + 1 );
+              }
+              int w = tris_out.size() - 1;
+              for (; w > 0 && tri_t < dists_out[w-1]; --w) {
+                tris_out[w] = tris_out[w-1];
+                dists_out[w] = dists_out[w-1];
+              }
+              tris_out[w] = *iter;
+              dists_out[w] = tri_t;
+              ray_end = dists_out.back();
+            }
+          }
+        }
+      }
+
+      continue;
+    }
+    
+    rval = get_split_plane( seg.handle, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    const double t = (plane.coord - ray_pt[plane.norm]) / ray_dir[plane.norm];
+    if (!finite(t)) {         // ray parallel to plane
+      if (ray_pt[plane.norm] - tol <= plane.coord)
+        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
+      if (ray_pt[plane.norm] + tol >= plane.coord)
+        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
+    }
+    else if (ray_dir[plane.norm] < 0.0) {
+      if (seg.beg > t) {      // segment left of plane
+        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
+//        if (plane.coord - ray_pt[plane.norm] + ray_dir[plane.norm] * seg.beg < tol)
+//          list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
+      }
+      else if (seg.end < t) { // segment right of plane
+        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
+//        if (ray_pt[plane.norm] + ray_dir[plane.norm] * seg.end - plane.coord < tol)
+//          list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
+      }
+      else {                  // segment crosses plane
+        list.push_back( NodeSeg( children[1], seg.beg, t ) );
+        list.push_back( NodeSeg( children[0], t, seg.end ) );
+      }
+    }
+    else {
+      if (seg.beg > t) {      // segment right of plane
+        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
+//        if (ray_pt[plane.norm] + ray_dir[plane.norm] * seg.beg - plane.coord < tol)
+//          list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
+      }
+      else if (seg.end < t) { // segment left of plane
+        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
+//        if (plane.coord - ray_pt[plane.norm] + ray_dir[plane.norm] * seg.end < tol)
+//          list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
+      }
+      else {                  // segment crosses plane
+        list.push_back( NodeSeg( children[0], seg.beg, t ) );
+        list.push_back( NodeSeg( children[1], t, seg.end ) );
+      }
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode AdaptiveKDTree::depth( EntityHandle root, 
+                                     unsigned int& min_depth,
+                                     unsigned int& max_depth )
+{
+  AdaptiveKDTreeIter iter;
+  get_tree_iterator( root, iter );
+  iter.step_to_first_leaf(AdaptiveKDTreeIter::LEFT);
+  min_depth = max_depth = iter.depth();
+  while (MB_SUCCESS == iter.step()) {
+    if (iter.depth() > max_depth)
+      max_depth = iter.depth();
+    else if (iter.depth() < min_depth)
+      min_depth = iter.depth();
+  }
+  
+  return MB_SUCCESS;
+}
+          
+ErrorCode AdaptiveKDTree::get_info(EntityHandle root,
+                                       double min[3], double max[3], 
+                                       unsigned int &dep) 
+{
+  ErrorCode result = get_tree_box(root, min, max);
+  if (MB_SUCCESS != result) return result;
+  
+  unsigned min_depth;
+  return depth( root, min_depth, dep );
+}
+
+} // namespace moab

Copied: MOAB/trunk/src/AffineXform.cpp (from rev 3583, MOAB/trunk/src/MBAffineXform.cpp)
===================================================================
--- MOAB/trunk/src/AffineXform.cpp	                        (rev 0)
+++ MOAB/trunk/src/AffineXform.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,450 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class AffineXform
+ * \brief Define an affine transformatino
+ * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ * \date August, 2006
+ */
+
+#include "AffineXform.hpp"
+#include "moab/Interface.hpp"
+#include <assert.h>
+
+#ifndef TEST
+
+namespace moab {
+
+const char* const AFFINE_XFORM_TAG_NAME = "AFFINE_TRANSFORM";
+
+ErrorCode AffineXform::get_tag( Tag& tag_out,
+                                    Interface* interface,
+                                    const char* tagname )
+{
+  assert( sizeof(AffineXform) == 12*sizeof(double) );
+  
+  if (!tagname)
+    tagname = AFFINE_XFORM_TAG_NAME;
+ 
+  ErrorCode rval;
+  
+  rval = interface->tag_get_handle( tagname, tag_out );
+  
+  if (MB_TAG_NOT_FOUND == rval) 
+    return interface->tag_create( tagname, 
+                                  sizeof(AffineXform),
+                                  MB_TAG_DENSE,
+                                  MB_TYPE_DOUBLE,
+                                  tag_out,
+                                  0 );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  int size;
+  rval = interface->tag_get_size( tag_out, size );
+  if (MB_SUCCESS != rval || size != sizeof(AffineXform))
+    return MB_FAILURE;
+  
+  DataType type;
+  rval = interface->tag_get_data_type( tag_out, type );
+  if (MB_SUCCESS != rval || type != MB_TYPE_DOUBLE)
+    return MB_FAILURE;
+  
+  return MB_SUCCESS;
+}
+  
+} // namespace moab
+
+
+#else // ******************* Unit Test code ***********************
+
+using namespace moab;
+
+#include <iostream>
+#define ASSERT_VECTORS_EQUAL(A, B) assert_vectors_equal( (A), (B), #A, #B, __LINE__ )
+#define ASSERT_DOUBLES_EQUAL(A, B) assert_doubles_equal( (A), (B), #A, #B, __LINE__ )
+#define ASSERT(B) assert_bool( (B), #B, __LINE__ )
+
+const double TOL = 1e-6;
+
+int error_count = 0;
+
+void assert_vectors_equal( const CartVect& a, const CartVect& b, 
+                           const char* sa, const char* sb,
+                           int lineno )
+{
+  if (fabs(a[0] - b[0]) > TOL ||
+      fabs(a[1] - b[1]) > TOL ||
+      fabs(a[2] - b[2]) > TOL) {
+    std::cerr << "Assertion failed at line " << lineno << std::endl
+              << "\t" << sa << " == " << sb << std::endl
+              << "\t[" << a[0] << ", " << a[1] << ", " << a[2] << "] == ["
+              << b[0] << ", " << b[1] << ", " << b[2] << "]" << std::endl;
+    ++error_count;
+  }
+}
+
+void assert_doubles_equal( double a, double b, const char* sa, const char* sb, int lineno )
+{
+  if (fabs(a - b) > TOL) {
+    std::cerr << "Assertion failed at line " << lineno << std::endl
+              << "\t" << sa << " == " << sb << std::endl
+              << "\t" << a << " == " << b << std::endl;
+    ++error_count;
+  }
+}
+
+void assert_bool( bool b, const char* sb, int lineno )
+{
+  if (!b) {
+    std::cerr << "Assertion failed at line " << lineno << std::endl
+              << "\t" << sb << std::endl;
+    ++error_count;
+  }
+}
+
+
+const CartVect point1( 0.0, 0.0, 0.0 ), point2( 3.5, 1000, -200 );
+const CartVect vect1( 0.0, 0.0, -100.0 ), vect2( 1.0, 0.0, 1.0 );
+
+
+void test_none()
+{
+    // default xform should do nothing.
+  CartVect output;
+  AffineXform none;
+  none.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 );
+  none.xform_point( point2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point2 );
+  none.xform_vector( vect1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, vect1 );
+  none.xform_vector( vect2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, vect2 );
+}
+
+void test_translation()
+{
+  CartVect offset( 1.0, 2.0, 3.0 );
+  CartVect output;
+  
+  AffineXform move = AffineXform::translation( offset.array() );
+  
+  // test that points are moved by offset
+  move.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 + offset );
+  move.xform_point( point2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point2 + offset );
+  
+  // vectors should not be changed by a translation
+  move.xform_vector( vect1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, vect1 );
+  move.xform_vector( vect2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, vect2 );
+}
+
+void test_rotation()
+{
+  CartVect output;
+  
+  // rotate 90 degress about Z axis
+  
+  AffineXform rot = AffineXform::rotation( M_PI/2.0, CartVect(0,0,1).array() );
+  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
+  
+  rot.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
+  
+  CartVect expectedz( -point2[1], point2[0], point2[2] ); // in first quadrant
+  rot.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, expectedz );
+  
+  rot.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, vect1 );
+  
+  rot.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect( 0, 1, 1 ) );
+  
+  // rotate 90 degress about Y axis
+  
+  rot = AffineXform::rotation( M_PI/2.0, CartVect(0,1,0).array() );
+  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
+  
+  rot.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
+  
+  CartVect expectedy( point2[2], point2[1], -point2[0] ); // in second quadrant
+  rot.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, expectedy );
+  
+  rot.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(-100,0,0) );
+  
+  rot.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect( 1, 0, -1 ) );
+  
+  // rotate 90 degress about X axis
+  
+  rot = AffineXform::rotation( M_PI/2.0, CartVect(1,0,0).array() );
+  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
+  
+  rot.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
+  
+  CartVect expectedx( point2[0], -point2[2], point2[1] ); // in third quadrant
+  rot.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, expectedx );
+  
+  rot.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(0,100,0) );
+  
+  rot.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect( 1, -1, 0 ) );
+  
+  // rotate 180 degrees about vector in XY plane
+  
+  rot = AffineXform::rotation( M_PI, CartVect( 1, 1, 0 ).array() );
+  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
+  
+  rot.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
+  
+  rot.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect( point2[1], point2[0], -point2[2] ) );
+  
+  rot.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, -vect1 ); // vector is in xy plane
+  
+  rot.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect( 0, 1, -1 ) );
+}
+
+CartVect refl( const CartVect& vect, const CartVect& norm )
+{
+  CartVect n(norm);
+  n.normalize();
+  double d = vect % n;
+  return vect - 2 * d * n;
+}
+
+void test_reflection()
+{
+  CartVect output;
+  
+  // reflect about XY plane
+  AffineXform ref = AffineXform::reflection( CartVect( 0, 0, 1 ).array() );
+  ASSERT_DOUBLES_EQUAL( ref.matrix().determinant(), -1.0 );
+  ref.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 );
+  ref.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(point2[0],point2[1],-point2[2]) );
+  ref.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, -vect1 );
+  ref.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(1,0,-1) );
+  
+  // reflect about arbitrary palne
+  CartVect norm( 3, 2, 1 );
+  ref = AffineXform::reflection( norm.array() );
+  ASSERT_DOUBLES_EQUAL( ref.matrix().determinant(), -1.0 );
+  ref.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, point1 );
+  ref.xform_point( point2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
+  ASSERT_VECTORS_EQUAL( output, refl(point2,norm) );
+  ref.xform_vector( vect1.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
+  ASSERT_VECTORS_EQUAL( output, refl(vect1,norm) );
+  ref.xform_vector( vect2.array(), output.array() );
+  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
+  ASSERT_VECTORS_EQUAL( output, refl(vect2,norm) );
+}
+
+void test_scale()
+{
+  CartVect output;
+  
+  //scale in X only
+  AffineXform scale = AffineXform::scale( CartVect(2,1,1).array() );
+  scale.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(2*point1[0],point1[1],point1[2]) );
+  scale.xform_point( point2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(2*point2[0],point2[1],point2[2]) );
+  scale.xform_vector( vect1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(2*vect1[0],vect1[1],vect1[2]) );
+  scale.xform_vector( vect2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, CartVect(2*vect2[0],vect2[1],vect2[2]) );
+  
+  // scale in all
+  scale = AffineXform::scale( CartVect(0.5,0.5,0.5).array() );
+  scale.xform_point( point1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, 0.5*point1 );
+  scale.xform_point( point2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, 0.5*point2 );
+  scale.xform_vector( vect1.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, 0.5*vect1 );
+  scale.xform_vector( vect2.array(), output.array() );
+  ASSERT_VECTORS_EQUAL( output, 0.5*vect2 );
+}
+
+void test_accumulate()
+{
+  CartVect indiv, accum;
+  
+  // build an group of transforms.  make sure translation is somewhere in the middle
+  AffineXform move, scal, rot1, rot2, refl;
+  move = AffineXform::translation( CartVect( 5, -5, 1 ).array() );
+  scal = AffineXform::scale( CartVect( 1, 0.5, 2 ).array() );
+  rot1 = AffineXform::rotation( M_PI/3, CartVect( 0.5, 0.5, 1 ).array() );
+  rot2 = AffineXform::rotation( M_PI/4, CartVect( 1.0, 0.0, 0.0 ).array() );
+  refl = AffineXform::reflection( CartVect( -1, -1, 0 ).array() );
+  AffineXform accu;
+  accu.accumulate( scal );
+  accu.accumulate( rot1 );
+  accu.accumulate( move );
+  accu.accumulate( refl );
+  accu.accumulate( rot2 );
+  
+  accu.xform_point( point1.array(), accum.array() );
+  scal.xform_point( point1.array(), indiv.array() );
+  rot1.xform_point( indiv.array() );
+  move.xform_point( indiv.array() );
+  refl.xform_point( indiv.array() );
+  rot2.xform_point( indiv.array() );
+  ASSERT_VECTORS_EQUAL( accum, indiv );
+  
+  accu.xform_point( point2.array(), accum.array() );
+  scal.xform_point( point2.array(), indiv.array() );
+  rot1.xform_point( indiv.array() );
+  move.xform_point( indiv.array() );
+  refl.xform_point( indiv.array() );
+  rot2.xform_point( indiv.array() );
+  ASSERT_VECTORS_EQUAL( accum, indiv );
+  
+  accu.xform_vector( vect1.array(), accum.array() );
+  scal.xform_vector( vect1.array(), indiv.array() );
+  rot1.xform_vector( indiv.array() );
+  move.xform_vector( indiv.array() );
+  refl.xform_vector( indiv.array() );
+  rot2.xform_vector( indiv.array() );
+  ASSERT_VECTORS_EQUAL( accum, indiv );
+  
+  accu.xform_vector( vect2.array(), accum.array() );
+  scal.xform_vector( vect2.array(), indiv.array() );
+  rot1.xform_vector( indiv.array() );
+  move.xform_vector( indiv.array() );
+  refl.xform_vector( indiv.array() );
+  rot2.xform_vector( indiv.array() );
+  ASSERT_VECTORS_EQUAL( accum, indiv );
+}
+
+void test_inversion() {
+  CartVect result;
+  
+  // build an group of transforms.  make sure translation is somewhere in the middle
+  AffineXform move, scal, rot1, rot2, refl;
+  move = AffineXform::translation( CartVect( 5, -5, 1 ).array() );
+  scal = AffineXform::scale( CartVect( 1, 0.5, 2 ).array() );
+  rot1 = AffineXform::rotation( M_PI/3, CartVect( 0.5, 0.5, 1 ).array() );
+  rot2 = AffineXform::rotation( M_PI/4, CartVect( 1.0, 0.0, 0.0 ).array() );
+  refl = AffineXform::reflection( CartVect( -1, -1, 0 ).array() );
+  AffineXform acc;
+  acc.accumulate( scal );
+  acc.accumulate( rot1 );
+  acc.accumulate( move );
+  acc.accumulate( refl );
+  acc.accumulate( rot2 );
+  
+  AffineXform inv = acc.inverse();
+  
+  acc.xform_point( point1.array(), result.array() );
+  inv.xform_point( result.array() );
+  ASSERT_VECTORS_EQUAL( point1, result );
+  
+  acc.xform_point( point2.array(), result.array() );
+  inv.xform_point( result.array() );
+  ASSERT_VECTORS_EQUAL( point2, result );
+  
+  acc.xform_vector( vect1.array(), result.array() );
+  inv.xform_vector( result.array() );
+  ASSERT_VECTORS_EQUAL( vect1, result );
+  
+  acc.xform_vector( vect2.array(), result.array() );
+  inv.xform_vector( result.array() );
+  ASSERT_VECTORS_EQUAL( vect2, result );
+}
+  
+void test_is_reflection()
+{
+  AffineXform refl1, refl2, scale;
+  refl1 = AffineXform::reflection( CartVect( -1, -1, 0).array() );
+  refl2 = AffineXform::reflection( CartVect(  1,  0, 0).array() );
+  scale = AffineXform::scale( CartVect( -1, 1, 1 ).array() );
+  
+  ASSERT( refl1.reflection() );
+  ASSERT( refl2.reflection() );
+  ASSERT( scale.reflection() );
+  
+  AffineXform inv1, inv2, inv3;
+  inv1 = refl1.inverse();
+  inv2 = refl2.inverse();
+  inv3 = scale.inverse();
+  
+  ASSERT( inv1.reflection() );
+  ASSERT( inv2.reflection() );
+  ASSERT( inv3.reflection() );
+  
+  refl1.accumulate( refl2 );
+  refl2.accumulate( scale );
+  ASSERT( ! refl1.reflection() );
+  ASSERT( ! refl2.reflection() );
+  
+  AffineXform rot, mov;
+  rot = AffineXform::rotation( M_PI/4, CartVect(1,1,1).array() );
+  mov = AffineXform::translation( CartVect(-5,6,7).array() );
+  ASSERT( !rot.reflection() );
+  ASSERT( !mov.reflection() );
+}
+
+int main()
+{
+  test_none();
+  test_translation();
+  test_rotation();
+  test_reflection();
+  test_scale();
+  test_accumulate();
+  test_inversion();
+  test_is_reflection();
+  return error_count;
+}
+
+#endif  // #ifdef TEST

Copied: MOAB/trunk/src/AffineXform.hpp (from rev 3583, MOAB/trunk/src/MBAffineXform.hpp)
===================================================================
--- MOAB/trunk/src/AffineXform.hpp	                        (rev 0)
+++ MOAB/trunk/src/AffineXform.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,194 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class AffineXform
+ * \brief Define an affine transformatino
+ * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ * \date August, 2006
+ */
+
+#ifndef MOAB_AFFINE_XFORM_HPP
+#define MOAB_AFFINE_XFORM_HPP
+
+#include "moab/Forward.hpp"
+#include "moab/CartVect.hpp"
+#include "Matrix3.hpp"
+
+namespace moab {
+
+class AffineXform
+{
+  public:
+  
+    inline AffineXform();
+    
+    inline AffineXform( const double* three_by_three, 
+                          const double* translation );
+                          
+    inline AffineXform( const Matrix3& mat, const CartVect& off );
+    
+    /** move */
+    static inline AffineXform translation( const double* vector );
+    /** rotate about axis through origin */
+    static inline AffineXform rotation( double radians, const double* axis );
+    /** reflect about plane through origin */
+    static inline AffineXform reflection( const double* plane_normal );
+    /** scale about origin */
+    static inline AffineXform scale( const double* fractions );
+    
+    /** incorporate the passed transform into this one */
+    inline void accumulate( const AffineXform& other );
+    
+    /** apply transform to a point */
+    inline void xform_point( const double* input, double* output ) const;
+    /** apply transform to a point */
+    inline void xform_point( double* in_out ) const;
+    
+    /** apply transform to a vector */
+    inline void xform_vector( const double* input, double* output ) const;
+    /** apply transform to a vector */
+    inline void xform_vector( double* in_out ) const;
+    
+    /** get transform that is the inverse of this transform */
+    AffineXform inverse() const;
+    
+    /** get a tag that can be used to store an instance of this class */
+    static ErrorCode get_tag( Tag& tag_handle_out,
+                                Interface* moab,
+                                const char* tagname = 0 );
+    
+    /** get 3x3 matrix portion of transform */
+    const Matrix3& matrix() const { return mMatrix; }
+    /** get translation portion of transform */
+    const CartVect& offset() const { return mOffset; }
+    
+    /** Is this transform a reflection 
+     *
+     * A relfecting transform will require the reversal of the
+     * order of edges in a loop, etc. because it produces a 
+     * mirror-image of the input geometry.  This method tests
+     * if this is such a transform.  A reflection may be created
+     * with by an explicit transform, scaling with a negative
+     * scale factor, etc.  If multiple transforms are combined
+     * such that the transform is no longer a reflection (e.g. 
+     * two reflections that are effectively a rotation), this method
+     * will return false.
+     */
+    inline bool reflection() const;
+
+  private:
+  
+    Matrix3 mMatrix;
+    CartVect mOffset;
+};
+
+inline AffineXform::AffineXform()
+  : mMatrix(1.0), mOffset(0.0) 
+  {}
+
+inline AffineXform::AffineXform( const double* three_by_three, 
+                                     const double* translation )
+ : mMatrix(three_by_three), mOffset(translation)
+ {}
+
+inline AffineXform::AffineXform( const Matrix3& mat, const CartVect& off )
+  : mMatrix(mat), mOffset(off)
+  {}
+
+inline AffineXform AffineXform::translation( const double* vector )
+{
+  return AffineXform( Matrix3(1.0), CartVect(vector) );
+}
+
+inline AffineXform AffineXform::rotation( double angle, const double* axis )
+{
+  CartVect a(axis);
+  a.normalize();
+
+  const double c = cos(angle);
+  const double s = sin(angle);
+  const Matrix3 m1(    c,   -a[2]*s, a[1]*s,
+                       a[2]*s,   c,   -a[0]*s,
+                      -a[1]*s, a[0]*s,   c    );
+  return AffineXform( m1 + (1.0-c)*outer_product( a, a ), CartVect(0.0) );
+}
+
+inline AffineXform AffineXform::reflection( const double* plane_normal )
+{
+  double i = plane_normal[0];
+  double j = plane_normal[1];
+  double k = plane_normal[2];
+  Matrix3 m( j*j+k*k-i*i,    -2.0*i*j,    -2.0*i*k,
+                  -2.0*i*j, i*i+k*k-j*j,    -2.0*j*k,
+                  -2.0*i*k,    -2.0*j*k, i*i+j*j-k*k );
+  m *= 1.0 / (i*i + j*j + k*k); //normalize
+  return AffineXform( m, CartVect(0.0) );
+}
+
+inline AffineXform AffineXform::scale( const double* f )
+{
+  return AffineXform( Matrix3( CartVect(f) ), CartVect( 0.0 ) );
+}
+
+inline void AffineXform::accumulate( const AffineXform& other )
+{
+  mMatrix = other.mMatrix * mMatrix;
+  other.xform_point( mOffset.array() );
+}
+
+inline void AffineXform::xform_point( const double* input, double* output ) const
+{
+  xform_vector( input, output );
+  output[0] += mOffset[0];
+  output[1] += mOffset[1];
+  output[2] += mOffset[2];
+}
+
+inline void AffineXform::xform_point( double* in_out ) const
+{
+  xform_vector( in_out );
+  in_out[0] += mOffset[0];
+  in_out[1] += mOffset[1];
+  in_out[2] += mOffset[2];
+} 
+
+inline void AffineXform::xform_vector( const double* input, double* output ) const
+{
+  output[0] = input[0]*mMatrix[0][0] + input[1]*mMatrix[0][1] + input[2]*mMatrix[0][2];
+  output[1] = input[0]*mMatrix[1][0] + input[1]*mMatrix[1][1] + input[2]*mMatrix[1][2];
+  output[2] = input[0]*mMatrix[2][0] + input[1]*mMatrix[2][1] + input[2]*mMatrix[2][2];
+}
+
+inline void AffineXform::xform_vector( double* in_out ) const
+{
+  double input[] = { in_out[0], in_out[1], in_out[2] };
+  xform_vector( input, in_out );
+}
+
+inline AffineXform AffineXform::inverse() const
+{
+  Matrix3 m = mMatrix.inverse();
+  return AffineXform( m, m * -mOffset );
+}
+
+inline bool AffineXform::reflection() const
+{
+  return mMatrix.determinant() < 0.0;
+}
+  
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/AxisBox.cpp (from rev 3583, MOAB/trunk/src/MBAxisBox.cpp)
===================================================================
--- MOAB/trunk/src/AxisBox.cpp	                        (rev 0)
+++ MOAB/trunk/src/AxisBox.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,110 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \brief Class representing axis-aligned bounding box
+ * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ * \date August, 2006
+ */
+
+
+#include "AxisBox.hpp"
+#include "moab/Range.hpp"
+#include <assert.h>
+
+namespace moab {
+
+const char* const AXIS_BOX_TAG_NAME = "AXIS_BOX";
+
+
+ErrorCode AxisBox::get_tag( Tag& tag_out,
+                                Interface* interface,
+                                const char* tagname )
+{
+  assert( sizeof(AxisBox) == 6*sizeof(double) );
+  
+  if (!tagname)
+    tagname = AXIS_BOX_TAG_NAME;
+ 
+  ErrorCode rval;
+  
+  rval = interface->tag_get_handle( tagname, tag_out );
+  
+  if (MB_TAG_NOT_FOUND == rval) 
+    return interface->tag_create( tagname, 
+                                  sizeof(AxisBox),
+                                  MB_TAG_DENSE,
+                                  MB_TYPE_DOUBLE,
+                                  tag_out,
+                                  0 );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  int size;
+  rval = interface->tag_get_size( tag_out, size );
+  if (MB_SUCCESS != rval || size != sizeof(AxisBox))
+    return MB_FAILURE;
+  
+  DataType type;
+  rval = interface->tag_get_data_type( tag_out, type );
+  if (MB_SUCCESS != rval || type != MB_TYPE_DOUBLE)
+    return MB_FAILURE;
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode AxisBox::calculate( AxisBox& box,
+                                  EntityHandle set,
+                                  Interface* interface )
+{
+  Range range;
+  ErrorCode rval = interface->get_entities_by_handle( set, range );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  return calculate( box, range, interface );
+}
+
+ErrorCode AxisBox::calculate( AxisBox& box,
+                                  const Range& entities,
+                                  Interface* interface )
+{
+  ErrorCode rval;
+  Range vertices;
+  Range elements;
+  
+  elements.merge( entities.upper_bound(MBVERTEX), entities.lower_bound(MBENTITYSET) );
+  rval = interface->get_adjacencies( elements, 0, false, vertices );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  vertices.merge( entities.begin(), entities.upper_bound(MBVERTEX) );
+  
+  std::vector<double> coords( 3*vertices.size() );
+  rval = interface->get_coords( vertices, &coords[0] );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  box = AxisBox();
+  std::vector<double>::const_iterator i = coords.begin();
+  for (; i != coords.end(); i += 3)
+    box |= &*i;
+  
+  return MB_SUCCESS;
+}
+  
+} // namespace moab
+
+

Copied: MOAB/trunk/src/AxisBox.hpp (from rev 3583, MOAB/trunk/src/MBAxisBox.hpp)
===================================================================
--- MOAB/trunk/src/AxisBox.hpp	                        (rev 0)
+++ MOAB/trunk/src/AxisBox.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,251 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class AxisBox
+ * \brief Class representing axis-aligned bounding box
+ * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ * \date August, 2006
+ */
+
+#ifndef MB_AXIS_BOX_HPP
+#define MB_AXIS_BOX_HPP
+
+#include <limits>
+#include "moab/Interface.hpp"
+
+namespace moab {
+
+class AxisBox {
+  public:
+  
+    inline AxisBox();
+    
+    inline AxisBox( const double* min, const double* max );
+    
+    inline AxisBox( const double* point );
+    
+    static ErrorCode get_tag( Tag& tag_handle_out,
+                                Interface* interface,
+                                const char* tag_name = 0 );
+    
+    /** Calculate a box bounding the entities contained in the passed set */
+    static ErrorCode calculate( AxisBox& box_out,
+                                  EntityHandle set,
+                                  Interface* interface );
+                                      
+    /** Calculate a box bounding the vertices/elements in the passed Range */
+    static ErrorCode calculate( AxisBox& box_out,
+                                  const Range& elements,
+                                  Interface* interface );
+                                  
+    /** intersect */
+    inline AxisBox& operator &=( const AxisBox& other );
+
+    /** unite */
+    inline AxisBox& operator |=( const AxisBox& other );
+    
+    /** unite */
+    inline AxisBox& operator |=( const double* point );
+    
+    inline const double* minimum() const { return minVect; }
+    
+    inline const double* maximum() const { return maxVect; }
+    
+    inline double* minimum() { return minVect; }
+    
+    inline double* maximum() { return maxVect; }
+    
+    inline void center( double* center_out ) const;
+    
+    inline void diagonal( double* diagonal_out ) const;
+    
+    /**\brief Check if two boxes intersect.
+     *
+     * Check if two boxes are within the specified tolerance of
+     * each other.  If tolerance is less than zero, then boxes must
+     * overlap by at least the magnitude of the tolerance to be
+     * considered intersecting.
+     */
+    inline bool intersects( const AxisBox& other, 
+                            double tolerance ) const;
+  
+    /**\brief Check if box contains point
+     *
+     * Check if a position is in or on the box, within the specified tolerance
+     */
+    inline bool intersects( const double* point,
+                            double tolerance ) const;
+    
+    /**\brief Check that box is valid
+     *
+     * Check that box is defined (contains at least a single point.)
+     */
+    inline bool valid() const;
+                      
+    /**\brief Find closest position on/within box to input position.
+     * 
+     * Find the closest position in the solid box to the input position.
+     * If the input position is on or within the box, then the output
+     * position will be the same as the input position.  If the input
+     * position is outside the box, the outside position will be the
+     * closest point on the box boundary to the input position.
+     */
+     inline void closest_position_within_box( const double* input_position,
+                                    double* output_position ) const;
+                            
+  private:
+  
+    double minVect[3], maxVect[3];
+};
+
+/** intersect */
+inline AxisBox operator&( const AxisBox& a, const AxisBox& b )
+  { return AxisBox(a) &= b; }
+
+/** unite */
+inline AxisBox operator|( const AxisBox& a, const AxisBox& b )
+  { return AxisBox(a) |= b; }
+
+/** intersects */
+inline bool operator||( const AxisBox& a, const AxisBox& b )
+{
+  return a.minimum()[0] <= b.maximum()[0]
+      && a.minimum()[1] <= b.maximum()[1]
+      && a.minimum()[2] <= b.maximum()[2]
+      && a.maximum()[0] >= b.minimum()[0]
+      && a.maximum()[1] >= b.minimum()[1]
+      && a.maximum()[2] >= b.minimum()[2];
+}
+
+
+inline AxisBox::AxisBox()
+{
+  minVect[0] = minVect[1] = minVect[2] =  std::numeric_limits<double>::max();
+  maxVect[0] = maxVect[1] = maxVect[2] = -std::numeric_limits<double>::max();
+}
+
+inline AxisBox::AxisBox( const double* min, const double* max )
+{   
+  minVect[0] = min[0];
+  minVect[1] = min[1];
+  minVect[2] = min[2];
+  maxVect[0] = max[0];
+  maxVect[1] = max[1];
+  maxVect[2] = max[2];
+}
+
+inline AxisBox::AxisBox( const double* point )
+{
+  minVect[0] = maxVect[0] = point[0];
+  minVect[1] = maxVect[1] = point[1];
+  minVect[2] = maxVect[2] = point[2];
+}
+                                  
+inline AxisBox& AxisBox::operator &=( const AxisBox& other )
+{
+  for (int i = 0; i < 3; ++i) {
+    if (minVect[i] < other.minVect[i])
+      minVect[i] = other.minVect[i];
+    if (maxVect[i] > other.maxVect[i])
+      maxVect[i] = other.maxVect[i];
+  }
+  return *this;
+}
+
+inline AxisBox& AxisBox::operator |=( const AxisBox& other )
+{
+  for (int i = 0; i < 3; ++i) {
+    if (minVect[i] > other.minVect[i])
+      minVect[i] = other.minVect[i];
+    if (maxVect[i] < other.maxVect[i])
+      maxVect[i] = other.maxVect[i];
+  }
+  return *this;
+}
+
+inline AxisBox& AxisBox::operator |=( const double* point )
+{
+  for (int i = 0; i < 3; ++i) {
+    if (minVect[i] > point[i])
+      minVect[i] = point[i];
+    if (maxVect[i] < point[i])
+      maxVect[i] = point[i];
+  }
+  return *this;
+}
+    
+inline void AxisBox::center( double* center_out ) const
+{
+  center_out[0] = 0.5 * (minVect[0] + maxVect[0]);
+  center_out[1] = 0.5 * (minVect[1] + maxVect[1]);
+  center_out[2] = 0.5 * (minVect[2] + maxVect[2]);
+}
+    
+inline void AxisBox::diagonal( double* diagonal_out ) const
+{
+  diagonal_out[0] = maxVect[0] - minVect[0];
+  diagonal_out[1] = maxVect[1] - minVect[1];
+  diagonal_out[2] = maxVect[2] - minVect[2];
+}
+
+inline bool AxisBox::intersects( const AxisBox& other, 
+                                   double tolerance ) const
+{
+  return minVect[0] - other.maxVect[0] <= tolerance &&
+         minVect[1] - other.maxVect[1] <= tolerance &&
+         minVect[2] - other.maxVect[2] <= tolerance &&
+         other.minVect[0] - maxVect[0] <= tolerance &&
+         other.minVect[1] - maxVect[1] <= tolerance &&
+         other.minVect[2] - maxVect[2] <= tolerance;
+}
+  
+inline bool AxisBox::intersects( const double* point,
+                                   double tolerance ) const
+{
+  return minVect[0] - point[0] <= tolerance &&
+         minVect[1] - point[1] <= tolerance &&
+         minVect[2] - point[2] <= tolerance &&
+         maxVect[0] - point[0] <= tolerance &&
+         maxVect[1] - point[1] <= tolerance &&
+         maxVect[2] - point[2] <= tolerance;
+}
+
+
+inline bool AxisBox::valid() const
+{
+  return minVect[0] <= maxVect[0]
+      && minVect[1] <= maxVect[1]
+      && minVect[2] <= maxVect[2];
+}
+
+inline void AxisBox::closest_position_within_box( 
+                                    const double* input_position,
+                                    double* output_position ) const
+{
+  for (int i = 0; i < 3; ++i) {
+    if (input_position[i] < minVect[i])
+      output_position[i] = minVect[i];
+    else if (input_position[i] > maxVect[i])
+      output_position[i] = maxVect[i];
+    else
+      output_position[i] = input_position[i];
+  }
+}
+  
+} // namespace moab
+
+#endif
+

Copied: MOAB/trunk/src/BSPTree.cpp (from rev 3583, MOAB/trunk/src/MBBSPTree.cpp)
===================================================================
--- MOAB/trunk/src/BSPTree.cpp	                        (rev 0)
+++ MOAB/trunk/src/BSPTree.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1456 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2008 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file BSPTree.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2008-05-13
+ */
+
+#include "moab/BSPTree.hpp"
+#include "moab/GeomUtil.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+#include "moab/BSPTreePoly.hpp"
+
+#include <assert.h>
+#include <string.h>
+#include <algorithm>
+#include <limits>
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#  include <float.h>
+#  define finite(A) _finite(A)
+#elif defined(HAVE_IEEEFP_H)
+#  include <ieeefp.h>
+#endif
+
+#define MB_BSP_TREE_DEFAULT_TAG_NAME "BSPTree"
+
+namespace moab {
+
+static void corners_from_box( const double box_min[3],
+                              const double box_max[3],
+                              double corners[8][3] )
+{
+  const double* ranges[] = { box_min, box_max };
+  for (int z = 0; z < 2; ++z) {
+    corners[4*z  ][0] = box_min[0];
+    corners[4*z  ][1] = box_min[1];
+    corners[4*z  ][2] = ranges[z][2];
+
+    corners[4*z+1][0] = box_max[0];
+    corners[4*z+1][1] = box_min[1];
+    corners[4*z+1][2] = ranges[z][2];
+
+    corners[4*z+2][0] = box_max[0];
+    corners[4*z+2][1] = box_max[1];
+    corners[4*z+2][2] = ranges[z][2];
+
+    corners[4*z+3][0] = box_min[0];
+    corners[4*z+3][1] = box_max[1];
+    corners[4*z+3][2] = ranges[z][2];
+  }
+}
+
+// assume box has planar sides
+// test if point is contained in box
+static bool point_in_box( const double corners[8][3],
+                          const double point[3] )
+{
+  const unsigned side_verts[6][3] = { { 0, 3, 1 },
+                                      { 4, 5, 7 },
+                                      { 0, 1, 4 },
+                                      { 1, 2, 5 },
+                                      { 2, 3, 6 },
+                                      { 3, 0, 7 } };
+    // If we assume planar sides, then the box is the intersection
+    // of 6 half-spaces defined by the planes of the sides.
+  const CartVect pt(point);
+  for (unsigned s = 0; s < 6; ++s) {
+    CartVect v0( corners[side_verts[s][0]] );
+    CartVect v1( corners[side_verts[s][1]] );
+    CartVect v2( corners[side_verts[s][2]] );
+    CartVect N = (v1 - v0) * (v2 - v0);
+    if ((v0 - pt) % N < 0)
+      return false;
+  }
+  return true;
+}
+
+void BSPTree::Plane::set( const double pt1[3], const double pt2[3], const double pt3[3] )
+{
+  const double v1[] = { pt2[0] - pt1[0], pt2[1] - pt1[1], pt2[2] - pt1[2] };
+  const double v2[] = { pt3[0] - pt1[0], pt3[1] - pt1[1], pt3[2] - pt1[2] };
+  const double norm[] = { v1[1]*v2[2] - v1[2]*v2[1],
+                          v1[2]*v2[0] - v1[0]*v2[2],
+                          v1[0]*v2[1] - v1[1]*v2[0] };
+  set( norm, pt1 );
+}
+
+ErrorCode BSPTree::init_tags( const char* tagname )
+{
+  if (!tagname) 
+    tagname = MB_BSP_TREE_DEFAULT_TAG_NAME;
+  
+  std::string rootname(tagname);
+  rootname += "_box";
+  
+  ErrorCode rval = moab()->tag_create( tagname, 4*sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, planeTag, 0, true );
+  if (MB_SUCCESS != rval)
+    planeTag = 0;
+  else
+    rval = moab()->tag_create( rootname.c_str(), 24*sizeof(double), MB_TAG_SPARSE, MB_TYPE_DOUBLE, rootTag, 0, true );
+  if (MB_SUCCESS != rval)
+    rootTag = 0;
+  return rval;
+}
+
+BSPTree::BSPTree( Interface* mb, 
+                      const char* tagname, 
+                      unsigned set_flags )
+  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(false)
+{ init_tags( tagname ); }
+
+BSPTree::BSPTree( Interface* mb, 
+                      bool destroy_created_trees,
+                      const char* tagname, 
+                      unsigned set_flags )
+  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(destroy_created_trees)
+{ init_tags( tagname ); }
+
+BSPTree::~BSPTree()
+{
+  if (!cleanUpTrees)
+    return;
+    
+  while (!createdTrees.empty()) {
+    EntityHandle tree = createdTrees.back();
+      // make sure this is a tree (rather than some other, stale handle)
+    const void* data_ptr = 0;
+    ErrorCode rval = moab()->tag_get_data( rootTag, &tree, 1, &data_ptr );
+    if (MB_SUCCESS == rval)
+      rval = delete_tree( tree );
+    if (MB_SUCCESS != rval)
+      createdTrees.pop_back();
+  }
+}
+
+ErrorCode BSPTree::set_split_plane( EntityHandle node, const Plane& p )
+{ 
+    // check for unit-length normal
+  const double lensqr = p.norm[0]*p.norm[0] 
+                      + p.norm[1]*p.norm[1] 
+                      + p.norm[2]*p.norm[2];
+  if (fabs(lensqr - 1.0) < std::numeric_limits<double>::epsilon())
+    return moab()->tag_set_data( planeTag, &node, 1, &p ); 
+    
+  const double inv_len = 1.0/sqrt(lensqr);
+  Plane p2(p);
+  p2.norm[0] *= inv_len;
+  p2.norm[1] *= inv_len;
+  p2.norm[2] *= inv_len;
+  p2.coeff   *= inv_len;
+  
+    // check for zero-length normal
+  if (!finite(p2.norm[0]+p2.norm[1]+p2.norm[2]+p2.coeff))
+    return MB_FAILURE;
+
+    // store plane
+  return moab()->tag_set_data( planeTag, &node, 1, &p2 ); 
+}
+
+ErrorCode BSPTree::set_tree_box( EntityHandle root_handle,
+                                     const double box_min[3],
+                                     const double box_max[3] )
+{
+  double corners[8][3];
+  corners_from_box( box_min, box_max, corners );
+  return set_tree_box( root_handle, corners );
+}
+
+ErrorCode BSPTree::set_tree_box( EntityHandle root_handle,
+                                     const double corners[8][3] )
+{
+  return moab()->tag_set_data( rootTag, &root_handle, 1, corners );
+}
+
+ErrorCode BSPTree::get_tree_box( EntityHandle root_handle,
+                                     double corners[8][3] )
+{
+  return moab()->tag_get_data( rootTag, &root_handle, 1, corners );
+}
+
+ErrorCode BSPTree::get_tree_box( EntityHandle root_handle,
+                                     double corners[24] )
+{
+  return moab()->tag_get_data( rootTag, &root_handle, 1, corners );
+}
+
+ErrorCode BSPTree::create_tree( EntityHandle& root_handle )
+{
+  const double min[3] = { -HUGE_VAL, -HUGE_VAL, -HUGE_VAL };
+  const double max[3] = {  HUGE_VAL,  HUGE_VAL,  HUGE_VAL };
+  return create_tree( min, max, root_handle );
+}
+
+ErrorCode BSPTree::create_tree( const double corners[8][3],
+                                    EntityHandle& root_handle )
+{
+  ErrorCode rval = moab()->create_meshset( meshSetFlags, root_handle );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = set_tree_box( root_handle, corners );
+  if (MB_SUCCESS != rval) {
+    moab()->delete_entities( &root_handle, 1 );
+    root_handle = 0;
+    return rval;
+  }
+  
+  createdTrees.push_back( root_handle );
+  return MB_SUCCESS;
+}
+                                    
+
+ErrorCode BSPTree::create_tree( const double box_min[3],
+                                    const double box_max[3],
+                                    EntityHandle& root_handle )
+{
+  double corners[8][3];
+  corners_from_box( box_min, box_max, corners );
+  return create_tree( corners, root_handle );
+}
+
+ErrorCode BSPTree::delete_tree( EntityHandle root_handle )
+{
+  ErrorCode rval;
+  
+  std::vector<EntityHandle> children, dead_sets, current_sets;
+  current_sets.push_back( root_handle );
+  while (!current_sets.empty()) {
+    EntityHandle set = current_sets.back();
+    current_sets.pop_back();
+    dead_sets.push_back( set );
+    rval = moab()->get_child_meshsets( set, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+    std::copy( children.begin(), children.end(), std::back_inserter(current_sets) );
+    children.clear();
+  }
+  
+  rval = moab()->tag_delete_data( rootTag, &root_handle, 1 );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  createdTrees.erase(
+    std::remove( createdTrees.begin(), createdTrees.end(), root_handle ),
+    createdTrees.end() );
+  return moab()->delete_entities( &dead_sets[0], dead_sets.size() );
+}
+
+ErrorCode BSPTree::find_all_trees( Range& results )
+{
+  return moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, 
+                                               &rootTag, 0, 1,
+                                               results );
+}
+
+ErrorCode BSPTree::get_tree_iterator( EntityHandle root,
+                                          BSPTreeIter& iter )
+{
+  ErrorCode rval = iter.initialize( this, root );
+  if (MB_SUCCESS != rval)
+    return rval;
+  return iter.step_to_first_leaf( BSPTreeIter::LEFT );
+}
+
+ErrorCode BSPTree::get_tree_end_iterator( EntityHandle root,
+                                          BSPTreeIter& iter )
+{
+  ErrorCode rval = iter.initialize( this, root );
+  if (MB_SUCCESS != rval)
+    return rval;
+  return iter.step_to_first_leaf( BSPTreeIter::RIGHT );
+}
+
+ErrorCode BSPTree::split_leaf( BSPTreeIter& leaf,
+                                   Plane plane,
+                                   EntityHandle& left,
+                                   EntityHandle& right )
+{
+  ErrorCode rval;
+  
+  rval = moab()->create_meshset( meshSetFlags, left );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = moab()->create_meshset( meshSetFlags, right );
+  if (MB_SUCCESS != rval) {
+    moab()->delete_entities( &left, 1 );
+    return rval;
+  }
+  
+  if (MB_SUCCESS != set_split_plane( leaf.handle(), plane ) ||
+      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), left ) ||
+      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), right) ||
+      MB_SUCCESS != leaf.step_to_first_leaf(BSPTreeIter::LEFT)) {
+    EntityHandle children[] = { left, right };
+    moab()->delete_entities( children, 2 );
+    return MB_FAILURE;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTree::split_leaf( BSPTreeIter& leaf, Plane plane )
+{
+  EntityHandle left, right;
+  return split_leaf( leaf, plane, left, right );
+}
+
+ErrorCode BSPTree::split_leaf( BSPTreeIter& leaf, 
+                                   Plane plane,
+                                   const Range& left_entities,
+                                   const Range& right_entities )
+{
+  EntityHandle left, right, parent = leaf.handle();
+  ErrorCode rval = split_leaf( leaf, plane, left, right );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (MB_SUCCESS == moab()->add_entities( left, left_entities ) &&
+      MB_SUCCESS == moab()->add_entities(right,right_entities ) &&
+      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
+    return MB_SUCCESS;
+  
+  moab()->remove_child_meshset( parent, left );
+  moab()->remove_child_meshset( parent, right );
+  EntityHandle children[] = { left, right };
+  moab()->delete_entities( children, 2 );
+  return MB_FAILURE;
+}
+
+ErrorCode BSPTree::split_leaf( BSPTreeIter& leaf, Plane plane,
+                                   const std::vector<EntityHandle>& left_entities,
+                                   const std::vector<EntityHandle>& right_entities )
+{
+  EntityHandle left, right, parent = leaf.handle();
+  ErrorCode rval = split_leaf( leaf, plane, left, right );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (MB_SUCCESS == moab()->add_entities( left, &left_entities[0], left_entities.size() ) &&
+      MB_SUCCESS == moab()->add_entities(right,&right_entities[0],right_entities.size() ) &&
+      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
+    return MB_SUCCESS;
+  
+  moab()->remove_child_meshset( parent, left );
+  moab()->remove_child_meshset( parent, right );
+  EntityHandle children[] = { left, right };
+  moab()->delete_entities( children, 2 );
+  return MB_FAILURE;
+}
+
+ErrorCode BSPTree::merge_leaf( BSPTreeIter& iter )
+{
+  ErrorCode rval;
+  if (iter.depth() == 1) // at root
+    return MB_FAILURE;
+  
+    // Move iter to parent
+  iter.up();
+
+    // Get sets to merge
+  EntityHandle parent = iter.handle();
+  iter.childVect.clear();
+  rval = moab()->get_child_meshsets( parent, iter.childVect );
+  if (MB_SUCCESS != rval)
+    return rval;
+    
+    // Remove child links
+  moab()->remove_child_meshset( parent, iter.childVect[0] );
+  moab()->remove_child_meshset( parent, iter.childVect[1] );
+  std::vector<EntityHandle> stack( iter.childVect );
+  
+    // Get all entities from children and put them in parent
+  Range range;
+  while (!stack.empty()) {
+    EntityHandle h = stack.back();
+    stack.pop_back();
+    range.clear();
+    rval = moab()->get_entities_by_handle( h, range );
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = moab()->add_entities( parent, range );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    iter.childVect.clear();
+    moab()->get_child_meshsets( h, iter.childVect );
+    if (!iter.childVect.empty()) {
+     moab()->remove_child_meshset( h, iter.childVect[0] );
+     moab()->remove_child_meshset( h, iter.childVect[1] );
+     stack.push_back( iter.childVect[0] );
+     stack.push_back( iter.childVect[1] );
+    }
+  
+    rval = moab()->delete_entities( &h, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+  
+
+ErrorCode BSPTreeIter::initialize( BSPTree* tool,
+                                       EntityHandle root,
+                                       const double* point )
+{
+  treeTool = tool;
+  mStack.clear();
+  mStack.push_back( root );
+  return MB_SUCCESS;
+}
+
+
+ErrorCode BSPTreeIter::step_to_first_leaf( Direction direction )
+{
+  ErrorCode rval;
+  for (;;) {
+    childVect.clear();
+    rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (childVect.empty()) // leaf
+      break;
+  
+    mStack.push_back( childVect[direction] );
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeIter::step( Direction direction )
+{
+  EntityHandle node, parent;
+  ErrorCode rval;
+  const Direction opposite = static_cast<Direction>(1-direction);
+  
+    // If stack is empty, then either this iterator is uninitialized
+    // or we reached the end of the iteration (and return 
+    // MB_ENTITY_NOT_FOUND) already.
+  if (mStack.empty())
+    return MB_FAILURE;
+    
+    // Pop the current node from the stack.
+    // The stack should then contain the parent of the current node.
+    // If the stack is empty after this pop, then we've reached the end.
+  node = mStack.back();
+  mStack.pop_back();
+  
+  while(!mStack.empty()) {
+      // Get data for parent entity
+    parent = mStack.back();
+    childVect.clear();
+    rval = tool()->moab()->get_child_meshsets( parent, childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+      // If we're at the left child
+    if (childVect[opposite] == node) {
+        // push right child on stack
+      mStack.push_back( childVect[direction] );
+        // descend to left-most leaf of the right child
+      return step_to_first_leaf(opposite);
+    }
+    
+      // The current node is the right child of the parent,
+      // continue up the tree.
+    assert( childVect[direction] == node );
+    node = parent;
+    mStack.pop_back();
+  }
+  
+  return MB_ENTITY_NOT_FOUND;
+}
+
+ErrorCode BSPTreeIter::up() 
+{
+  if (mStack.size() < 2)
+    return MB_ENTITY_NOT_FOUND;
+  mStack.pop_back();
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeIter::down( const BSPTree::Plane& plane, Direction dir ) 
+{
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
+  if (MB_SUCCESS != rval)
+    return rval;
+  if (childVect.empty())
+    return MB_ENTITY_NOT_FOUND;
+  
+  mStack.push_back( childVect[dir] );
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeIter::get_parent_split_plane( BSPTree::Plane& plane ) const
+{
+  if (mStack.size() < 2) // at tree root
+    return MB_ENTITY_NOT_FOUND;
+  
+  EntityHandle parent = mStack[mStack.size()-2];
+  return tool()->get_split_plane( parent, plane );
+}
+
+double BSPTreeIter::volume() const
+{
+  BSPTreePoly polyhedron;
+  ErrorCode rval = calculate_polyhedron( polyhedron );
+  return MB_SUCCESS == rval ? polyhedron.volume() : -1.0;
+}
+
+bool BSPTreeIter::is_sibling( const BSPTreeIter& other_leaf ) const
+{
+  const size_t s = mStack.size();
+  return (s > 1) && (s == other_leaf.mStack.size()) &&
+         (other_leaf.mStack[s-2] == mStack[s-2]) &&
+         other_leaf.handle() != handle();
+}
+
+bool BSPTreeIter::is_sibling( EntityHandle other_leaf ) const
+{
+  if (mStack.size() < 2 || other_leaf == handle())
+    return false;
+  EntityHandle parent = mStack[mStack.size()-2];
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
+  if (MB_SUCCESS != rval || childVect.size() != 2) {
+    assert(false);
+    return false;
+  }
+  return childVect[0] == other_leaf || childVect[1] == other_leaf;
+}
+
+bool BSPTreeIter::sibling_is_forward() const
+{
+  if (mStack.size() < 2) // if root
+    return false;
+  EntityHandle parent = mStack[mStack.size()-2];
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
+  if (MB_SUCCESS != rval || childVect.size() != 2) {
+    assert(false);
+    return false;
+  }
+  return childVect[0] == handle();
+}  
+
+ErrorCode BSPTreeIter::calculate_polyhedron( BSPTreePoly& poly_out ) const
+{
+  ErrorCode rval;
+  
+  assert( sizeof(CartVect) == 3*sizeof(double) );
+  CartVect corners[8];
+  rval = treeTool->get_tree_box( mStack.front(), corners[0].array() );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = poly_out.set( corners );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  BSPTree::Plane plane;
+  std::vector<EntityHandle>::const_iterator i = mStack.begin();
+  std::vector<EntityHandle>::const_iterator here = mStack.end() - 1;
+  while (i != here) {
+    rval = treeTool->get_split_plane( *i, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    childVect.clear();
+    rval = treeTool->moab()->get_child_meshsets( *i, childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (childVect.size() != 2)
+      return MB_FAILURE;
+      
+    ++i;
+    if (childVect[1] == *i)
+      plane.flip();
+    
+    CartVect norm( plane.norm );
+    poly_out.cut_polyhedron( norm, plane.coeff );
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::initialize( BSPTree* tool_ptr,
+                                          EntityHandle root,
+                                          const double* point )
+{
+  ErrorCode rval = BSPTreeIter::initialize( tool_ptr, root );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  tool()->get_tree_box( root, leafCoords );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  if (point && !point_in_box( leafCoords, point ))
+    return MB_ENTITY_NOT_FOUND;
+
+  stackData.resize(1);
+  return MB_SUCCESS;
+}
+
+BSPTreeBoxIter::SideBits
+BSPTreeBoxIter::side_above_plane( const double hex_coords[8][3],
+                                    const BSPTree::Plane& plane )
+{
+  unsigned result  = 0;
+  for (unsigned i = 0; i < 8u; ++i) 
+    result |= plane.above(hex_coords[i]) << i;
+  return (BSPTreeBoxIter::SideBits)result;
+}
+
+BSPTreeBoxIter::SideBits
+BSPTreeBoxIter::side_on_plane( const double hex_coords[8][3],
+                                 const BSPTree::Plane& plane )
+{
+  unsigned result  = 0;
+  for (unsigned i = 0; i < 8u; ++i) {
+    bool on = plane.distance(hex_coords[i]) <= BSPTree::epsilon();
+    result |= on << i;
+  }
+  return (BSPTreeBoxIter::SideBits)result;
+}
+
+static inline void copy_coords( const double src[3], double dest[3] )
+{
+  dest[0] = src[0];
+  dest[1] = src[1];
+  dest[2] = src[2];
+}
+
+ErrorCode BSPTreeBoxIter::face_corners( const SideBits face,
+                                            const double hex_corners[8][3],
+                                            double face_corners[4][3] )
+{
+  switch (face) {
+    case BSPTreeBoxIter::B0154:
+      copy_coords( hex_corners[0], face_corners[0] );
+      copy_coords( hex_corners[1], face_corners[1] );
+      copy_coords( hex_corners[5], face_corners[2] );
+      copy_coords( hex_corners[4], face_corners[3] );
+      break;
+    case BSPTreeBoxIter::B1265:
+      copy_coords( hex_corners[1], face_corners[0] );
+      copy_coords( hex_corners[2], face_corners[1] );
+      copy_coords( hex_corners[6], face_corners[2] );
+      copy_coords( hex_corners[5], face_corners[3] );
+      break;
+    case BSPTreeBoxIter::B2376:
+      copy_coords( hex_corners[2], face_corners[0] );
+      copy_coords( hex_corners[3], face_corners[1] );
+      copy_coords( hex_corners[7], face_corners[2] );
+      copy_coords( hex_corners[6], face_corners[3] );
+      break;
+    case BSPTreeBoxIter::B3047:
+      copy_coords( hex_corners[3], face_corners[0] );
+      copy_coords( hex_corners[0], face_corners[1] );
+      copy_coords( hex_corners[4], face_corners[2] );
+      copy_coords( hex_corners[7], face_corners[3] );
+      break;
+    case BSPTreeBoxIter::B3210:
+      copy_coords( hex_corners[3], face_corners[0] );
+      copy_coords( hex_corners[2], face_corners[1] );
+      copy_coords( hex_corners[1], face_corners[2] );
+      copy_coords( hex_corners[0], face_corners[3] );
+      break;
+    case BSPTreeBoxIter::B4567:
+      copy_coords( hex_corners[4], face_corners[0] );
+      copy_coords( hex_corners[5], face_corners[1] );
+      copy_coords( hex_corners[6], face_corners[2] );
+      copy_coords( hex_corners[7], face_corners[3] );
+      break;
+    default:
+      return MB_FAILURE; // child is not a box
+  }
+  
+  return MB_SUCCESS;
+
+}
+
+/** \brief Clip an edge using a plane
+ *
+ * Given an edge from keep_end_coords to cut_end_coords,
+ * cut the edge using the passed plane, such that cut_end_coords
+ * is updated with a new location on the plane, and old_coords_out
+ * contains the original value of cut_end_coords.
+ */
+static inline
+void plane_cut_edge( double old_coords_out[3],
+                     const double keep_end_coords[3],
+                     double cut_end_coords[3],
+                     const BSPTree::Plane& plane )
+{
+  const CartVect start( keep_end_coords ), end( cut_end_coords );
+  const CartVect norm( plane.norm );
+  CartVect xsect_point;
+  
+  const CartVect m = end - start;
+  const double t = -(norm % start + plane.coeff) / (norm % m);
+  assert( t > 0.0 && t < 1.0 );
+  xsect_point = start + t * m;
+  
+  end.get( old_coords_out );
+  xsect_point.get( cut_end_coords );
+}
+
+/** Given the corners of a hexahedron in corners_input and a 
+ *  plane, cut the hex with the plane, updating corners_input
+ *  and storing the original,cut-off side of the hex in cut_face_out.
+ *
+ *  The portion of the hex below the plane is retained.  cut_face_out
+ *  will contain the side of the hex that is entirely above the plane.
+ *\return MB_FAILURE if plane/hex intersection is not a quadrilateral.
+ */
+static ErrorCode plane_cut_box( double cut_face_out[4][3],
+                                  double corners_inout[8][3],
+                                  const BSPTree::Plane& plane )
+{
+  switch (BSPTreeBoxIter::side_above_plane( corners_inout, plane )) {
+    case BSPTreeBoxIter::B0154:
+      plane_cut_edge( cut_face_out[0], corners_inout[3], corners_inout[0], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[2], corners_inout[1], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[6], corners_inout[5], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[7], corners_inout[4], plane );
+      break;
+    case BSPTreeBoxIter::B1265:
+      plane_cut_edge( cut_face_out[0], corners_inout[0], corners_inout[1], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[3], corners_inout[2], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[7], corners_inout[6], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[4], corners_inout[5], plane );
+      break;
+    case BSPTreeBoxIter::B2376:
+      plane_cut_edge( cut_face_out[0], corners_inout[1], corners_inout[2], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[0], corners_inout[3], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[4], corners_inout[7], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[5], corners_inout[6], plane );
+      break;
+    case BSPTreeBoxIter::B3047:
+      plane_cut_edge( cut_face_out[0], corners_inout[2], corners_inout[3], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[1], corners_inout[0], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[5], corners_inout[4], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[6], corners_inout[7], plane );
+      break;
+    case BSPTreeBoxIter::B3210:
+      plane_cut_edge( cut_face_out[0], corners_inout[7], corners_inout[3], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[6], corners_inout[2], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[5], corners_inout[1], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[4], corners_inout[0], plane );
+      break;
+    case BSPTreeBoxIter::B4567:
+      plane_cut_edge( cut_face_out[0], corners_inout[0], corners_inout[4], plane );
+      plane_cut_edge( cut_face_out[1], corners_inout[1], corners_inout[5], plane );
+      plane_cut_edge( cut_face_out[2], corners_inout[2], corners_inout[6], plane );
+      plane_cut_edge( cut_face_out[3], corners_inout[3], corners_inout[7], plane );
+      break;
+    default:
+      return MB_FAILURE; // child is not a box
+  }
+  
+  return MB_SUCCESS;
+}
+
+static inline
+void copy_coords( double dest[3], const double source[3] )
+{
+  dest[0] = source[0];
+  dest[1] = source[1];
+  dest[2] = source[2];
+}
+
+/** reverse of plane_cut_box */
+static inline
+ErrorCode plane_uncut_box( const double cut_face_in[4][3],
+                             double corners_inout[8][3],
+                             const BSPTree::Plane& plane )
+{
+  switch (BSPTreeBoxIter::side_on_plane( corners_inout, plane )) {
+    case BSPTreeBoxIter::B0154:
+      copy_coords( corners_inout[0], cut_face_in[0] );
+      copy_coords( corners_inout[1], cut_face_in[1] );
+      copy_coords( corners_inout[5], cut_face_in[2] );
+      copy_coords( corners_inout[4], cut_face_in[3] );
+      break;
+    case BSPTreeBoxIter::B1265:
+      copy_coords( corners_inout[1], cut_face_in[0] );
+      copy_coords( corners_inout[2], cut_face_in[1] );
+      copy_coords( corners_inout[6], cut_face_in[2] );
+      copy_coords( corners_inout[5], cut_face_in[3] );
+      break;
+    case BSPTreeBoxIter::B2376:
+      copy_coords( corners_inout[2], cut_face_in[0] );
+      copy_coords( corners_inout[3], cut_face_in[1] );
+      copy_coords( corners_inout[7], cut_face_in[2] );
+      copy_coords( corners_inout[6], cut_face_in[3] );
+      break;
+    case BSPTreeBoxIter::B3047:
+      copy_coords( corners_inout[3], cut_face_in[0] );
+      copy_coords( corners_inout[0], cut_face_in[1] );
+      copy_coords( corners_inout[4], cut_face_in[2] );
+      copy_coords( corners_inout[7], cut_face_in[3] );
+      break;
+    case BSPTreeBoxIter::B3210:
+      copy_coords( corners_inout[3], cut_face_in[0] );
+      copy_coords( corners_inout[2], cut_face_in[1] );
+      copy_coords( corners_inout[1], cut_face_in[2] );
+      copy_coords( corners_inout[0], cut_face_in[3] );
+      break;
+    case BSPTreeBoxIter::B4567:
+      copy_coords( corners_inout[4], cut_face_in[0] );
+      copy_coords( corners_inout[5], cut_face_in[1] );
+      copy_coords( corners_inout[6], cut_face_in[2] );
+      copy_coords( corners_inout[7], cut_face_in[3] );
+      break;
+    default:
+      return MB_FAILURE; // child is not a box
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::step_to_first_leaf( Direction direction )
+{
+  ErrorCode rval;
+  BSPTree::Plane plane;
+  Corners clipped_corners;
+  
+  for (;;) {
+    childVect.clear();
+    rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (childVect.empty()) // leaf
+      break;
+  
+    rval = tool()->get_split_plane( mStack.back(), plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    if (direction == RIGHT)
+      plane.flip();
+    rval = plane_cut_box( clipped_corners.coords, leafCoords, plane );
+    if (MB_SUCCESS != rval)
+      return rval; 
+    mStack.push_back( childVect[direction] );
+    stackData.push_back( clipped_corners );
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::up()
+{
+  ErrorCode rval;
+  if (mStack.size() == 1)
+    return MB_ENTITY_NOT_FOUND;
+  
+  EntityHandle node = mStack.back();
+  Corners clipped_face = stackData.back();
+  mStack.pop_back();
+  stackData.pop_back();
+  
+  BSPTree::Plane plane;
+  rval = tool()->get_split_plane( mStack.back(), plane );
+  if (MB_SUCCESS != rval) {
+    mStack.push_back( node );
+    stackData.push_back( clipped_face );
+    return rval;
+  }
+  
+  rval = plane_uncut_box( clipped_face.coords, leafCoords, plane );
+  if (MB_SUCCESS != rval) {
+    mStack.push_back( node );
+    stackData.push_back( clipped_face );
+    return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::down( const BSPTree::Plane& plane_ref, Direction direction )
+{
+  childVect.clear();
+  ErrorCode rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
+  if (MB_SUCCESS != rval)
+    return rval;
+  if (childVect.empty())
+    return MB_ENTITY_NOT_FOUND;
+  
+  BSPTree::Plane plane(plane_ref);
+  if (direction == RIGHT)
+    plane.flip();
+  
+  Corners clipped_face;
+  rval = plane_cut_box( clipped_face.coords, leafCoords, plane );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  mStack.push_back( childVect[direction] );
+  stackData.push_back( clipped_face );
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::step( Direction direction )
+{
+  EntityHandle node, parent;
+  Corners clipped_face;
+  ErrorCode rval;
+  BSPTree::Plane plane;
+  const Direction opposite = static_cast<Direction>(1-direction);
+  
+    // If stack is empty, then either this iterator is uninitialized
+    // or we reached the end of the iteration (and return 
+    // MB_ENTITY_NOT_FOUND) already.
+  if (mStack.empty())
+    return MB_FAILURE;
+    
+    // Pop the current node from the stack.
+    // The stack should then contain the parent of the current node.
+    // If the stack is empty after this pop, then we've reached the end.
+  node = mStack.back();
+  mStack.pop_back();
+  clipped_face = stackData.back();
+  stackData.pop_back();
+  
+  while(!mStack.empty()) {
+      // Get data for parent entity
+    parent = mStack.back();
+    childVect.clear();
+    rval = tool()->moab()->get_child_meshsets( parent, childVect );
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = tool()->get_split_plane( parent, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (direction == LEFT)
+      plane.flip();
+    
+      // If we're at the left child
+    if (childVect[opposite] == node) {
+        // change from box of left child to box of parent
+      plane_uncut_box( clipped_face.coords, leafCoords, plane );
+        // change from box of parent to box of right child
+      plane.flip();
+      plane_cut_box( clipped_face.coords, leafCoords, plane );
+        // push right child on stack
+      mStack.push_back( childVect[direction] );
+      stackData.push_back( clipped_face );
+        // descend to left-most leaf of the right child
+      return step_to_first_leaf(opposite);
+    }
+    
+      // The current node is the right child of the parent,
+      // continue up the tree.
+    assert( childVect[direction] == node );
+    plane.flip();
+    plane_uncut_box( clipped_face.coords, leafCoords, plane );
+    node = parent;
+    clipped_face = stackData.back();
+    mStack.pop_back();
+    stackData.pop_back();
+  }
+  
+  return MB_ENTITY_NOT_FOUND;
+}
+
+ErrorCode BSPTreeBoxIter::get_box_corners( double coords[8][3] ) const
+{
+  memcpy( coords, leafCoords, 24*sizeof(double) );
+  return MB_SUCCESS;
+}
+
+// result = a - b
+static void subtr( double result[3], const double a[3], const double b[3] )
+{
+  result[0] = a[0] - b[0];
+  result[1] = a[1] - b[1];
+  result[2] = a[2] - b[2];
+}
+
+// result = a + b + c + d
+static void sum( double result[3], 
+                 const double a[3], 
+                 const double b[3],
+                 const double c[3],
+                 const double d[3] )
+{
+  result[0] = a[0] + b[0] + c[0] + d[0];
+  result[1] = a[1] + b[1] + c[1] + d[1];
+  result[2] = a[2] + b[2] + c[2] + d[2];
+}
+
+// result = a cross b
+static void cross( double result[3], const double a[3], const double b[3] )
+{
+  result[0] = a[1]*b[2] - a[2]*b[1];
+  result[1] = a[2]*b[0] - a[0]*b[2];
+  result[2] = a[0]*b[1] - a[1]*b[0];
+}
+
+static double dot( const double a[3], const double b[3] )
+{
+  return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
+}
+
+double BSPTreeBoxIter::volume() const
+{
+    // have planar sides, so use mid-face tripple product
+  double f1[3], f2[3], f3[3], f4[3], f5[3], f6[3];
+  sum( f1, leafCoords[0], leafCoords[1], leafCoords[4], leafCoords[5] );
+  sum( f2, leafCoords[1], leafCoords[2], leafCoords[5], leafCoords[6] );
+  sum( f3, leafCoords[2], leafCoords[3], leafCoords[6], leafCoords[7] );
+  sum( f4, leafCoords[0], leafCoords[3], leafCoords[4], leafCoords[7] );
+  sum( f5, leafCoords[0], leafCoords[1], leafCoords[2], leafCoords[3] );
+  sum( f6, leafCoords[4], leafCoords[5], leafCoords[6], leafCoords[7] );
+  double v13[3], v24[3], v65[3];
+  subtr( v13, f1, f3 );
+  subtr( v24, f2, f4 );
+  subtr( v65, f6, f5 );
+  double cr[3];
+  cross( cr, v13, v24 );
+  return (1./64) * dot( cr, v65 );
+}
+
+BSPTreeBoxIter::XSect 
+BSPTreeBoxIter::splits( const BSPTree::Plane& plane ) const
+{
+  // test each corner relative to the plane
+  unsigned result  = 0;
+  for (unsigned i = 0; i < 8u; ++i) {
+    double d = plane.signed_distance( leafCoords[i] );
+      // if corner is on plane, than intersection 
+      // will result in a degenerate hex
+    if (fabs(d) < BSPTree::epsilon())
+      return NONHEX;
+      // if mark vertices above plane
+    if (d > 0.0)
+      result |= 1<<i;
+  }
+  
+  switch (result) {
+      // if all vertices or no vertices above plane,
+      // then plane doesn't intersect
+    case 0:
+    case 0xFF:
+      return MISS;
+  
+      // if there are four vertices above the plane
+      // and they compose a single face of the hex,
+      // then the cut will result in two hexes
+    case B0154:
+    case B1265:
+    case B2376:
+    case B3047:
+    case B3210:
+    case B4567:
+      return SPLIT;
+      
+      // otherwise intersects, but split would not result
+      // in two hexahedrons
+    default:
+      return NONHEX;
+  }
+}
+
+bool BSPTreeBoxIter::intersects( const BSPTree::Plane& plane ) const
+{
+  // test each corner relative to the plane
+  unsigned count  = 0;
+  for (unsigned i = 0; i < 8u; ++i) 
+    count += plane.above( leafCoords[i] );
+  return count > 0 && count < 8u;
+}
+
+ErrorCode BSPTreeBoxIter::sibling_side( SideBits& side_out ) const
+{
+  if (mStack.size() < 2) // at tree root
+    return MB_ENTITY_NOT_FOUND;
+  
+  EntityHandle parent = mStack[mStack.size()-2];
+  BSPTree::Plane plane;
+  ErrorCode rval = tool()->get_split_plane( parent, plane );
+  if (MB_SUCCESS != rval)
+    return MB_FAILURE;
+  
+  side_out = side_on_plane( leafCoords, plane );
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::get_neighbors( 
+                      SideBits side,
+                      std::vector<BSPTreeBoxIter>& results,
+                      double epsilon ) const
+{
+  EntityHandle handle;
+  BSPTree::Plane plane;
+  ErrorCode rval;
+  int n;
+   
+  Corners face;
+  rval = face_corners( side, leafCoords, face.coords );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // Move up tree until we find the split that created the specified side.
+    // Push the sibling at that level onto the iterator stack as
+    // all neighbors will be rooted at that node.
+  BSPTreeBoxIter iter( *this ); // temporary iterator (don't modifiy *this)
+  for (;;) {
+    handle = iter.handle();
+  
+    rval = iter.up();
+    if (MB_SUCCESS != rval) // reached root - no neighbors on that side
+      return (rval == MB_ENTITY_NOT_FOUND) ? MB_SUCCESS : rval;
+    
+    iter.childVect.clear();
+    rval = tool()->moab()->get_child_meshsets( iter.handle(), iter.childVect );
+    if (MB_SUCCESS!= rval)
+      return rval;
+    
+    rval = tool()->get_split_plane( iter.handle(), plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+    SideBits s = side_above_plane( iter.leafCoords, plane );
+
+    if (handle == iter.childVect[0] && s == side) {
+      rval = iter.down( plane, RIGHT );
+      if (MB_SUCCESS != rval)
+        return rval;
+      break;
+    }
+    else if (handle == iter.childVect[1] && opposite_face(s) == side) {
+      rval = iter.down( plane, LEFT );
+      if (MB_SUCCESS != rval)
+        return rval;
+      break;
+    }
+  }
+
+    // now move down tree, searching for adjacent boxes
+  std::vector<BSPTreeBoxIter> list;
+    // loop over all potential paths to neighbors (until list is empty)
+  for (;;) {
+      // follow a single path to a leaf, append any other potential
+      // paths to neighbors to 'list'
+    for (;;) { 
+      rval = tool()->moab()->num_child_meshsets( iter.handle(), &n );
+      if (MB_SUCCESS != rval)
+        return rval;
+        
+        // if leaf
+      if (!n) {
+        results.push_back( iter );
+        break; 
+      }
+      
+      rval = tool()->get_split_plane( iter.handle(), plane );
+      if (MB_SUCCESS != rval)
+        return rval;
+     
+      bool some_above = false, some_below = false;
+      for (int i = 0; i < 4; ++i) {
+        double signed_d = plane.signed_distance( face.coords[i] );
+        if (signed_d > -epsilon)
+          some_above = true;
+        if (signed_d < epsilon)
+          some_below = true;
+      }
+     
+      if (some_above && some_below) {
+        list.push_back( iter );
+        list.back().down( plane, RIGHT );
+        iter.down( plane, LEFT );
+      }
+      else if (some_above) {
+        iter.down( plane, RIGHT );
+      }
+      else if (some_below) {
+        iter.down( plane, LEFT );
+      }
+      else {
+        // tolerance issue -- epsilon to small? 2D box?
+        return MB_FAILURE;
+      }
+    }
+    
+    if (list.empty())
+      break;
+    
+    iter = list.back();
+    list.pop_back();
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTreeBoxIter::calculate_polyhedron( BSPTreePoly& poly_out ) const
+{
+  const CartVect* ptr = reinterpret_cast<const CartVect*>(leafCoords);
+  return poly_out.set( ptr );
+}
+
+ErrorCode BSPTree::leaf_containing_point( EntityHandle tree_root,
+                                              const double point[3],
+                                              EntityHandle& leaf_out )
+{
+  std::vector<EntityHandle> children;
+  Plane plane;
+  EntityHandle node = tree_root;
+  ErrorCode rval = moab()->get_child_meshsets( node, children );
+  if (MB_SUCCESS != rval)
+    return rval;
+  while (!children.empty()) {
+    rval = get_split_plane( node, plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+      
+    node = children[plane.above(point)];
+    children.clear();
+    rval = moab()->get_child_meshsets( node, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  leaf_out = node;
+  return MB_SUCCESS;
+}
+
+ErrorCode BSPTree::leaf_containing_point( EntityHandle root,
+                                              const double point[3],
+                                              BSPTreeIter& iter )
+{
+  ErrorCode rval;
+  
+  rval = iter.initialize( this, root, point );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  for (;;) {
+    iter.childVect.clear();
+    rval = moab()->get_child_meshsets( iter.handle(), iter.childVect );
+    if (MB_SUCCESS != rval || iter.childVect.empty())
+      return rval;
+
+    Plane plane;
+    rval = get_split_plane( iter.handle(), plane );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    rval = iter.down( plane, (BSPTreeIter::Direction)(plane.above( point )) );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+}
+
+
+
+template <typename PlaneIter> static inline
+bool ray_intersect_halfspaces( const CartVect& ray_pt,
+                               const CartVect& ray_dir,
+                               const PlaneIter& begin, 
+                               const PlaneIter& end,
+                               double& t_enter, 
+                               double& t_exit )
+{
+  const double epsilon = 1e-12;
+
+    // begin with inifinite ray
+  t_enter = 0.0;
+  t_exit  = std::numeric_limits<double>::infinity();
+
+    // cut ray such that we keep only the portion contained
+    // in each halfspace
+  for (PlaneIter i = begin; i != end; ++i) {
+    CartVect norm( i->norm );
+    double coeff = i->coeff;
+    double den = norm % ray_dir;
+    if (fabs(den) < epsilon) { // ray is parallel to plane
+      if (i->above( ray_pt.array() ))
+        return false; // ray entirely outside half-space
+    }
+    else {
+      double t_xsect = (-coeff - (norm % ray_pt)) / den;
+        // keep portion of ray/segment below plane
+      if (den > 0) {
+        if (t_xsect < t_exit)
+          t_exit = t_xsect;
+      }
+      else {
+        if (t_xsect > t_enter)
+          t_enter = t_xsect;
+      }
+    }
+  }
+  
+  return t_exit >= t_enter;
+}
+                               
+class BoxPlaneIter {
+      int faceNum;
+      BSPTree::Plane facePlanes[6];
+  
+  public:  
+    BoxPlaneIter( const double coords[8][3] );
+    BoxPlaneIter( ) : faceNum(6) {} // initialize to 'end'
+    const BSPTree::Plane* operator->() const
+      { return facePlanes + faceNum; }
+    bool operator==( const BoxPlaneIter& other ) const
+      { return faceNum == other.faceNum; }
+    bool operator!=( const BoxPlaneIter& other ) const
+      { return faceNum != other.faceNum; }
+    BoxPlaneIter& operator++()
+      { ++faceNum; return *this; }
+};
+
+static const int box_face_corners[6][4] = { { 0, 1, 5, 4 },
+                                            { 1, 2, 6, 5 },
+                                            { 2, 3, 7, 6 },
+                                            { 3, 0, 4, 7 },
+                                            { 3, 2, 1, 0 },
+                                            { 4, 5, 6, 7 } };
+ 
+BoxPlaneIter::BoxPlaneIter( const double coords[8][3] )
+  : faceNum(0)
+{
+    // NOTE:  In the case of a BSP tree, all sides of the
+    //        leaf will planar.
+  assert( sizeof(CartVect) == sizeof(coords[0]) );
+  const CartVect* corners = reinterpret_cast<const CartVect*>(coords);
+  for (int i = 0; i < 6; ++i) {
+    const int* indices = box_face_corners[i];
+    CartVect v1 = corners[indices[1]] - corners[indices[0]];
+    CartVect v2 = corners[indices[3]] - corners[indices[0]];
+    CartVect n = v1 * v2;
+    facePlanes[i] = BSPTree::Plane( n.array(), -(n % corners[indices[2]]) );
+  }
+}
+
+
+bool BSPTreeBoxIter::intersect_ray( const double ray_point[3],
+                                      const double ray_vect[3],
+                                      double& t_enter, double& t_exit ) const
+{
+  BoxPlaneIter iter( this->leafCoords ), end;
+  return ray_intersect_halfspaces( CartVect(ray_point),
+                                   CartVect(ray_vect),
+                                   iter, end,
+                                   t_enter, t_exit );
+}
+
+class BSPTreePlaneIter {
+    BSPTree* toolPtr;
+    const EntityHandle* const pathToRoot;
+    int pathPos;
+    BSPTree::Plane tmpPlane;
+    std::vector<EntityHandle> tmpChildren;
+  public:
+    BSPTreePlaneIter( BSPTree* tool, const EntityHandle* path, int path_len )
+      : toolPtr(tool), pathToRoot(path), pathPos(path_len-1)
+      { operator++(); }
+    BSPTreePlaneIter() // initialize to 'end'
+      : toolPtr(0), pathToRoot(0), pathPos(-1) {}
+  
+    const BSPTree::Plane* operator->() const
+      { return &tmpPlane; }
+    bool operator==( const BSPTreePlaneIter& other ) const
+      { return pathPos == other.pathPos; }
+    bool operator!=( const BSPTreePlaneIter& other ) const
+      { return pathPos != other.pathPos; }
+    BSPTreePlaneIter& operator++();
+};
+
+BSPTreePlaneIter& BSPTreePlaneIter::operator++()
+{
+  if (--pathPos < 0)
+    return *this;
+
+  EntityHandle prev = pathToRoot[pathPos+1];
+  EntityHandle curr = pathToRoot[pathPos];
+  
+  ErrorCode rval = toolPtr->get_split_plane( curr, tmpPlane );
+  if (MB_SUCCESS != rval) {
+    assert(false);
+    pathPos = 0;
+    return *this;
+  }
+  
+  tmpChildren.clear();
+  rval = toolPtr->moab()->get_child_meshsets( curr, tmpChildren );
+  if (MB_SUCCESS != rval || tmpChildren.size() != 2) {
+    assert(false);
+    pathPos = 0;
+    return *this;
+  }
+  
+  if (tmpChildren[1] == prev) 
+    tmpPlane.flip();
+  return *this;
+}
+
+
+bool BSPTreeIter::intersect_ray( const double ray_point[3],
+                                   const double ray_vect[3],
+                                   double& t_enter, double& t_exit ) const
+{
+    // intersect with half-spaces defining tree
+  BSPTreePlaneIter iter1( tool(), &mStack[0], mStack.size() ), end1;
+  if (!ray_intersect_halfspaces( CartVect(ray_point),
+                                 CartVect(ray_vect),
+                                 iter1, end1,
+                                 t_enter, t_exit ))
+    return false;
+  
+
+    // itersect with box bounding entire tree
+  double corners[8][3];
+  ErrorCode rval = tool()->get_tree_box( mStack.front(), corners );
+  if (MB_SUCCESS != rval) {
+    assert(false); 
+    return false;
+  }
+  
+  BoxPlaneIter iter2( corners ), end2;
+  double t2_enter, t2_exit;
+  if (!ray_intersect_halfspaces( CartVect(ray_point),
+                                 CartVect(ray_vect),
+                                 iter2, end2,
+                                 t2_enter, t2_exit ))
+    return false;
+  
+    // if intersect both box and halfspaces, check that
+    // two intersections overlap
+  if (t_enter < t2_enter)
+    t_enter = t2_enter;
+  if (t_exit > t2_exit)
+    t_exit = t2_exit;
+  return t_enter <= t_exit;
+}
+  
+} // namespace moab

Modified: MOAB/trunk/src/BSPTreePoly.cpp
===================================================================
--- MOAB/trunk/src/BSPTreePoly.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/BSPTreePoly.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,13 +1,15 @@
-#include "MBCartVect.hpp"
-#include "BSPTreePoly.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/BSPTreePoly.hpp"
 #include <assert.h>
 #include <stdlib.h>
 #include <set>
 
 #undef DEBUG_IDS
 
-struct BSPTreePoly::Vertex : public MBCartVect {
-  Vertex( const MBCartVect& v ) : MBCartVect(v), usePtr(0) 
+namespace moab {
+
+struct BSPTreePoly::Vertex : public CartVect {
+  Vertex( const CartVect& v ) : CartVect(v), usePtr(0) 
 #ifdef DEBUG_IDS
   , id(nextID++)
 #endif  
@@ -339,7 +341,7 @@
   }
 }
 
-MBErrorCode BSPTreePoly::set( const MBCartVect hex_corners[8] )
+ErrorCode BSPTreePoly::set( const CartVect hex_corners[8] )
 {
   clear();
   
@@ -410,7 +412,7 @@
 }
 
 void BSPTreePoly::get_vertices( const Face* face,
-                                 std::vector<MBCartVect>& vertices ) const
+                                 std::vector<CartVect>& vertices ) const
 {
   vertices.clear();
   if (!face || !face->usePtr)
@@ -425,11 +427,11 @@
 
 double BSPTreePoly::Face::signed_volume() const
 {
-  MBCartVect sum(0.0);
-  const MBCartVect* base = usePtr->start();
-  MBCartVect d1 = (*usePtr->end() - *base);
+  CartVect sum(0.0);
+  const CartVect* base = usePtr->start();
+  CartVect d1 = (*usePtr->end() - *base);
   for (EdgeUse* coedge = usePtr->nextPtr; coedge != usePtr; coedge = coedge->nextPtr) {
-    MBCartVect d2 = (*coedge->end() - *base);
+    CartVect d2 = (*coedge->end() - *base);
     sum += d1 * d2;
     d1 = d2;
   }
@@ -534,7 +536,7 @@
 }
 
 
-bool BSPTreePoly::cut_polyhedron( const MBCartVect& plane_normal,
+bool BSPTreePoly::cut_polyhedron( const CartVect& plane_normal,
                                    double plane_coeff )
 {
   const double EPSILON = 1e-6; // points this close are considered coincident
@@ -586,7 +588,7 @@
 
       if ((end->markVal == ABOVE && start->markVal == BELOW) ||
           (end->markVal == BELOW && start->markVal == ABOVE)) {
-        MBCartVect dir = *end - *start;
+        CartVect dir = *end - *start;
         double t = -(plane_normal % *start + plane_coeff) / (dir % plane_normal);
         Vertex* new_vtx = new Vertex( *start + t*dir );
         new_vtx->markVal = ON;
@@ -797,7 +799,7 @@
   return true;
 }
 
-bool BSPTreePoly::is_point_contained( const MBCartVect& point ) const
+bool BSPTreePoly::is_point_contained( const CartVect& point ) const
 {
   if (!faceList) // empty (zero-dimension) polyhedron
     return false;
@@ -813,7 +815,7 @@
     if (pt3 == pt1) // degenerate
       continue;
 
-    MBCartVect norm = (*pt3 - *pt2) * (*pt1 - *pt2);
+    CartVect norm = (*pt3 - *pt2) * (*pt1 - *pt2);
     double coeff = -(norm % *pt2);
     if (norm % point > -coeff) // if above plane
       return false;
@@ -821,3 +823,5 @@
   
   return true;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/BitTagServer.cpp
===================================================================
--- MOAB/trunk/src/BitTagServer.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/BitTagServer.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,14 +1,16 @@
 #include "BitTagServer.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
 #include <stdlib.h>
 #include <string.h>
 
+namespace moab {
+
 void BitPage::search( unsigned char value, int offset, int count, 
-                      int per_ent, MBRange& results, MBEntityHandle start ) const
+                      int per_ent, Range& results, EntityHandle start ) const
 {
   const int end = offset + count;
-  MBRange::iterator hint = results.begin();
+  Range::iterator hint = results.begin();
   while (offset != end) {
     if (get_bits( offset, per_ent ) == value)
       hint = results.insert( hint, start );
@@ -32,7 +34,7 @@
   memset( byteArray, init_val, BitTag::PageSize );
 }
 
-MBErrorCode BitTagServer::reserve_tag_id( int num_bits, MBTagId tag_id )
+ErrorCode BitTagServer::reserve_tag_id( int num_bits, TagId tag_id )
 {
   if (tag_id > tagList.size())
     tagList.resize( tag_id );
@@ -42,7 +44,7 @@
   return tagList[tag_id-1].reserve( num_bits );
 }
 
-MBErrorCode BitTagServer::release_tag_id( MBTagId tag_id )
+ErrorCode BitTagServer::release_tag_id( TagId tag_id )
 {
   if (tag_id > tagList.size() && !tagList[tag_id-1].in_use())
     return MB_TAG_NOT_FOUND;
@@ -57,16 +59,16 @@
     i->reset_data();
 }
 
-MBErrorCode BitTagServer::get_tags( MBEntityHandle entity,  
-                                    std::vector<MBTag> &tags ) const
+ErrorCode BitTagServer::get_tags( EntityHandle entity,  
+                                    std::vector<Tag> &tags ) const
 {
   for (size_t i = 0; i < tagList.size(); ++i)
     if (tagList[i].in_use())
-      tags.push_back( (MBTag)(i+1) );
+      tags.push_back( (Tag)(i+1) );
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::reserve( unsigned bits )
+ErrorCode BitTag::reserve( unsigned bits )
 {
   if (in_use() || bits > 8)
     return MB_FAILURE;
@@ -93,7 +95,7 @@
 
 void BitTag::reset_data()
 {
-  for (MBEntityType t = (MBEntityType)0; t != MBMAXTYPE; ++t) {
+  for (EntityType t = (EntityType)0; t != MBMAXTYPE; ++t) {
     for (size_t i = 0; i < pageList[t].size(); ++i)
       delete pageList[t][i];
     pageList[t].clear();
@@ -106,12 +108,12 @@
   inUse = false;
 }
 
-MBErrorCode BitTag::get_bits( const MBEntityHandle* handles, 
+ErrorCode BitTag::get_bits( const EntityHandle* handles, 
                               int num_handles, 
                               unsigned char* data,
                               const unsigned char* default_value ) const
 {
-  MBEntityType type;
+  EntityType type;
   size_t page;
   int offset;
   unsigned char def = default_value ? *default_value : 0;
@@ -125,12 +127,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::set_bits( const MBEntityHandle* handles, 
+ErrorCode BitTag::set_bits( const EntityHandle* handles, 
                               int num_handles, 
                               const unsigned char* data,
                               const unsigned char* default_value )
 {
-  MBEntityType type;
+  EntityType type;
   size_t page;
   int offset;
   for (int i = 0; i < num_handles; ++i) {
@@ -145,11 +147,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::clear_bits( const MBEntityHandle* handles, 
+ErrorCode BitTag::clear_bits( const EntityHandle* handles, 
                                 int num_handles, 
                                 const unsigned char* default_value )
 {
-  MBEntityType type;
+  EntityType type;
   size_t page;
   int offset;
   const unsigned char val = default_value ? *default_value : 0;
@@ -161,16 +163,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_bits( const MBRange& handles, 
+ErrorCode BitTag::get_bits( const Range& handles, 
                               unsigned char* data,
                               const unsigned char* default_value ) const
 {
-  MBEntityType type;
-  MBEntityID count;
+  EntityType type;
+  EntityID count;
   size_t page;
   int offset, per_page = ents_per_page();
   unsigned char def = default_value ? *default_value : 0;
-  MBRange::const_pair_iterator i;
+  Range::const_pair_iterator i;
   for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
     unpack( i->first, type, page, offset );
     assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
@@ -182,7 +184,7 @@
     }
     
     while (count) {
-      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
+      size_t pcount = std::min( (EntityID)(per_page - offset), count );
       if (pageList[type][page])
         pageList[type][page]->get_bits( offset, pcount, storedBitsPerEntity, data );
       else
@@ -196,16 +198,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::set_bits( const MBRange& handles, 
+ErrorCode BitTag::set_bits( const Range& handles, 
                               const unsigned char* data, 
                               const unsigned char* default_value )
 {
-  MBEntityType type;
-  MBEntityID count;
+  EntityType type;
+  EntityID count;
   size_t page;
   int offset, per_page = ents_per_page();
   unsigned char def = default_value ? *default_value : 0;
-  MBRange::const_pair_iterator i;
+  Range::const_pair_iterator i;
   for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
     unpack( i->first, type, page, offset );
     assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
@@ -217,7 +219,7 @@
       if (!pageList[type][page])
         pageList[type][page] = new BitPage( storedBitsPerEntity, def );
 
-      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
+      size_t pcount = std::min( (EntityID)(per_page - offset), count );
       pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, data );
       data += pcount;
       count -= pcount; 
@@ -228,22 +230,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::clear_bits( const MBRange& handles, 
+ErrorCode BitTag::clear_bits( const Range& handles, 
                                 const unsigned char* default_value )
 {
-  MBEntityType type;
-  MBEntityID count;
+  EntityType type;
+  EntityID count;
   size_t page;
   int offset, per_page = ents_per_page();
   unsigned char val = default_value ? *default_value : 0;
-  MBRange::const_pair_iterator i;
+  Range::const_pair_iterator i;
   for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
     unpack( i->first, type, page, offset );
     assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
     count = i->second - i->first + 1;
     
     while (count) {
-      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
+      size_t pcount = std::min( (EntityID)(per_page - offset), count );
       if (page < pageList[type].size() && pageList[type][page])
         pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, val );
       count -= pcount; 
@@ -254,10 +256,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_entities( MBRange& entities ) const
+ErrorCode BitTag::get_entities( Range& entities ) const
 {
-  MBErrorCode rval = MB_SUCCESS;
-  MBEntityType type = MBMAXTYPE;
+  ErrorCode rval = MB_SUCCESS;
+  EntityType type = MBMAXTYPE;
   while (type--) {
     rval = get_entities( type, entities );
     if (MB_SUCCESS != rval)
@@ -267,15 +269,15 @@
 }
     
 
-MBErrorCode BitTag::get_entities( MBEntityType type, MBRange& entities ) const
+ErrorCode BitTag::get_entities( EntityType type, Range& entities ) const
 {
   const int per_page = ents_per_page();
-  MBRange::iterator hint = entities.begin();
+  Range::iterator hint = entities.begin();
   for (size_t i = 0; i < pageList[type].size(); ++i) {
     if (pageList[type][i]) {
-      MBEntityID id = i * per_page;
-      MBEntityHandle h = CREATE_HANDLE( type, id );
-      MBEntityHandle last = h + per_page - 1;
+      EntityID id = i * per_page;
+      EntityHandle h = CREATE_HANDLE( type, id );
+      EntityHandle last = h + per_page - 1;
         // never zero ID
       if (!id) ++h;
       hint = entities.insert( h, last );
@@ -284,16 +286,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_entities( const MBRange& range, 
-                                  MBEntityType in_type,
-                                  MBRange& entities ) const
+ErrorCode BitTag::get_entities( const Range& range, 
+                                  EntityType in_type,
+                                  Range& entities ) const
 {
-  MBEntityType type;
-  MBEntityID count;
+  EntityType type;
+  EntityID count;
   size_t page;
   int offset, per_page = ents_per_page();
-  MBRange::const_iterator j, i = range.lower_bound( in_type );
-  MBEntityHandle h;
+  Range::const_iterator j, i = range.lower_bound( in_type );
+  EntityHandle h;
   while (i != range.end()) {
     h = *i;
     unpack( h, type, page, offset );
@@ -304,7 +306,7 @@
     count = *i - h + 1;
     ++i;
     while (count > 0) {
-      MBEntityID pcount = std::min( count, (MBEntityID)(per_page - offset) );
+      EntityID pcount = std::min( count, (EntityID)(per_page - offset) );
       if (page < pageList[type].size() && pageList[type][page]) 
         entities.insert( h, h+pcount-1 );
     
@@ -318,15 +320,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_entities_with_bits( MBEntityType type, 
-                                            MBRange& entities,
+ErrorCode BitTag::get_entities_with_bits( EntityType type, 
+                                            Range& entities,
                                             unsigned char bits ) const
 {
   const int per_page = ents_per_page();
   for (size_t i = 0; i < pageList[type].size(); ++i) {
     if (pageList[type][i]) {
-      MBEntityID id = i * per_page;
-      MBEntityHandle h = CREATE_HANDLE( type, id );
+      EntityID id = i * per_page;
+      EntityHandle h = CREATE_HANDLE( type, id );
       int off = !i; // never zero ID
       pageList[type][i]->search( bits, off, per_page-off, storedBitsPerEntity, 
                                  entities, h+off );
@@ -335,17 +337,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_entities_with_bits( const MBRange &range,
-                                            MBEntityType in_type, 
-                                            MBRange& entities,
+ErrorCode BitTag::get_entities_with_bits( const Range &range,
+                                            EntityType in_type, 
+                                            Range& entities,
                                             unsigned char bits ) const
 {
-  MBEntityType type;
-  MBEntityID count;
+  EntityType type;
+  EntityID count;
   size_t page;
   int offset, per_page = ents_per_page();
-  MBRange::const_iterator j, i = range.lower_bound( in_type );
-  MBEntityHandle h;
+  Range::const_iterator j, i = range.lower_bound( in_type );
+  EntityHandle h;
   while (i != range.end()) {
     h = *i;
     unpack( h, type, page, offset );
@@ -356,7 +358,7 @@
     count = *i - h + 1;
     ++i;
     while (count > 0) {
-      MBEntityID pcount = std::min( count, (MBEntityID)(per_page - offset) );
+      EntityID pcount = std::min( count, (EntityID)(per_page - offset) );
       if (page < pageList[type].size() && pageList[type][page]) 
         pageList[type][page]->search( bits, offset, pcount, 
                                       storedBitsPerEntity,
@@ -372,7 +374,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_number_entities( MBEntityType type,
+ErrorCode BitTag::get_number_entities( EntityType type,
                                          int& num_entities ) const
 {
   const int per_page = ents_per_page();
@@ -387,21 +389,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode BitTag::get_number_entities( const MBRange &range,
-                                         MBEntityType type,
+ErrorCode BitTag::get_number_entities( const Range &range,
+                                         EntityType type,
                                          int& num_entities ) const
 {
-  MBRange tmp;
-  MBErrorCode result = get_entities( range, type, tmp );
+  Range tmp;
+  ErrorCode result = get_entities( range, type, tmp );
   num_entities = tmp.size();
   return result;
 }
 
-MBErrorCode BitTag::get_memory_use( unsigned long& total,
+ErrorCode BitTag::get_memory_use( unsigned long& total,
                                     unsigned long& per_entity ) const
 {
   per_entity = (storedBitsPerEntity > 4); // cannot return fraction of bytes, so round
-  for (MBEntityType t = (MBEntityType)0; t < MBMAXTYPE; ++t) {
+  for (EntityType t = (EntityType)0; t < MBMAXTYPE; ++t) {
     total += pageList[t].capacity() * sizeof(BitPage*);
     for (size_t i = 0; i < pageList[t].size(); ++i)
       if (pageList[t][i])
@@ -409,3 +411,5 @@
   }
   return MB_SUCCESS;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/BitTagServer.hpp
===================================================================
--- MOAB/trunk/src/BitTagServer.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/BitTagServer.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,13 +1,15 @@
 #ifndef BIT_TAG_SERVER_HPP
 #define BIT_TAG_SERVER_HPP
 
-#include "MBTypes.h"
-#include "MBInternals.hpp"
+#include "moab/Types.hpp"
+#include "Internals.hpp"
 #include <algorithm>
 #include <vector>
 #include <assert.h>
 
-class MBRange;
+namespace moab {
+
+class Range;
 class BitTag;
 class BitPage;
 
@@ -29,103 +31,103 @@
      * Returns MB_TAG_NOT_FOUND if ID is already in use.
      *\param num_bits Number of bits in each per-entity tag value
      */
-  MBErrorCode reserve_tag_id( int num_bits, MBTagId tag_id );
+  ErrorCode reserve_tag_id( int num_bits, TagId tag_id );
 
     /**\brief Deallocate tag
      *
      * Mask specified tag id as unused and release any memory
      * associated with the tag.
      */
-  MBErrorCode release_tag_id( MBTagId tag_id );
+  ErrorCode release_tag_id( TagId tag_id );
 
     /**\brief Get tag values for an array of entity handles */
-  MBErrorCode get_bits( MBTagId tag_id, 
-                        const MBEntityHandle* handles, 
+  ErrorCode get_bits( TagId tag_id, 
+                        const EntityHandle* handles, 
                         int num_handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const;
     /**\brief Get tag values for a range of entity handles */
-  MBErrorCode get_bits( MBTagId tag_id, 
-                        const MBRange& handles, 
+  ErrorCode get_bits( TagId tag_id, 
+                        const Range& handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const;
 
     /**\brief Set tag values for an array of entity handles */
-  MBErrorCode set_bits( MBTagId tag_id, 
-                        const MBEntityHandle* handles, 
+  ErrorCode set_bits( TagId tag_id, 
+                        const EntityHandle* handles, 
                         int num_handles,
                         const unsigned char* data, 
                         const unsigned char* default_value );
     /**\brief Set tag values for a range of entity handles */
-  MBErrorCode set_bits( MBTagId tag_id, 
-                        const MBRange& handles, 
+  ErrorCode set_bits( TagId tag_id, 
+                        const Range& handles, 
                         const unsigned char* data, 
                         const unsigned char* default_value );
 
     /**\brief Clear tag values for an array of entity handles */
-  MBErrorCode clear_bits( MBTagId tag_id, 
-                          const MBEntityHandle* handles, 
+  ErrorCode clear_bits( TagId tag_id, 
+                          const EntityHandle* handles, 
                           int num_handles,
                           const unsigned char* default_value );
     /**\brief Clear tag values for a range of entity handles */
-  MBErrorCode clear_bits( MBTagId tag_id, 
-                          const MBRange& handles, 
+  ErrorCode clear_bits( TagId tag_id, 
+                          const Range& handles, 
                           const unsigned char* default_value );
     
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( MBTagId tag_id, 
-                            MBRange& entities ) const;
+  ErrorCode get_entities( TagId tag_id, 
+                            Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( MBTagId tag_id, 
-                            MBEntityType type, 
-                            MBRange& entities ) const;
+  ErrorCode get_entities( TagId tag_id, 
+                            EntityType type, 
+                            Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag of the specified value is stored */
-  MBErrorCode get_entities_with_tag_value( MBTagId tag_id, 
-                                           MBEntityType type, 
-                                           MBRange& entities,
+  ErrorCode get_entities_with_tag_value( TagId tag_id, 
+                                           EntityType type, 
+                                           Range& entities,
                                            unsigned char bits ) const;
 
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( const MBRange &range,
-                            MBTagId tag_id, 
-                            MBEntityType type, 
-                            MBRange& entities ) const;
+  ErrorCode get_entities( const Range &range,
+                            TagId tag_id, 
+                            EntityType type, 
+                            Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag of the specified value is stored */
-  MBErrorCode get_entities_with_tag_value( const MBRange &range,
-                                           MBTagId tag_id, 
-                                           MBEntityType type, 
-                                           MBRange& entities,
+  ErrorCode get_entities_with_tag_value( const Range &range,
+                                           TagId tag_id, 
+                                           EntityType type, 
+                                           Range& entities,
                                            unsigned char bits ) const;
 
     //! get all tags defined on an entity
-  MBErrorCode get_tags( MBEntityHandle entity,
-                        std::vector<MBTag> &tags ) const;
+  ErrorCode get_tags( EntityHandle entity,
+                        std::vector<Tag> &tags ) const;
 
     /**\brief Get number of entities for which an explicit tag value is stored */
-  MBErrorCode get_number_entities( MBTagId tag_id, 
-                                   MBEntityType type,
+  ErrorCode get_number_entities( TagId tag_id, 
+                                   EntityType type,
                                    int& num_entities ) const;
   
     /**\brief Get number of entities for which an explicit tag value is stored */
-  MBErrorCode get_number_entities( const MBRange &range,
-                                   MBTagId tag_id, 
-                                   MBEntityType type,
+  ErrorCode get_number_entities( const Range &range,
+                                   TagId tag_id, 
+                                   EntityType type,
                                    int& num_entities ) const;
   
-  MBErrorCode get_memory_use( MBTagId tag,
+  ErrorCode get_memory_use( TagId tag,
                               unsigned long& total,
                               unsigned long& per_entity ) const;
 
 private:
   
     /**\brief Get BitTag instance for specified tag ID, or NULL if none */
-  inline BitTag* get_tag( MBTagId id );
+  inline BitTag* get_tag( TagId id );
   
     /**\brief Get BitTag instance for specified tag ID, or NULL if none */
-  inline const BitTag* get_tag( MBTagId id ) const;
+  inline const BitTag* get_tag( TagId id ) const;
   
     /**\brief Array of BitTag instances, indexed by (tag id - 1) */
   std::vector<BitTag> tagList;
@@ -149,67 +151,67 @@
     { const_cast<BitTag&>(other).swap(*this); return *this; }
     
     /**\brief Get tag values for an array of entity handles */
-  MBErrorCode get_bits( const MBEntityHandle* handles, 
+  ErrorCode get_bits( const EntityHandle* handles, 
                         int num_handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const;
     /**\brief Get tag values for a range of entity handles */
-  MBErrorCode get_bits( const MBRange& handles, 
+  ErrorCode get_bits( const Range& handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const;
 
     /**\brief Set tag values for an array of entity handles */
-  MBErrorCode set_bits( const MBEntityHandle* handles, 
+  ErrorCode set_bits( const EntityHandle* handles, 
                         int num_handles,
                         const unsigned char* data, 
                         const unsigned char* default_value );
     /**\brief Set tag values for a range of entity handles */
-  MBErrorCode set_bits( const MBRange& handles, 
+  ErrorCode set_bits( const Range& handles, 
                         const unsigned char* data, 
                         const unsigned char* default_value );
 
     /**\brief Clear tag values for an array of entity handles */
-  MBErrorCode clear_bits( const MBEntityHandle* handles, 
+  ErrorCode clear_bits( const EntityHandle* handles, 
                           int num_handles,
                           const unsigned char* default_value );
     /**\brief Clear tag values for a range of entity handles */
-  MBErrorCode clear_bits( const MBRange& handles, 
+  ErrorCode clear_bits( const Range& handles, 
                           const unsigned char* default_value );
     
 
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( MBRange& entities ) const;
+  ErrorCode get_entities( Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( MBEntityType type, 
-                            MBRange& entities ) const;
+  ErrorCode get_entities( EntityType type, 
+                            Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag value is stored */
-  MBErrorCode get_entities( const MBRange &range,
-                            MBEntityType type, 
-                            MBRange& entities ) const;
+  ErrorCode get_entities( const Range &range,
+                            EntityType type, 
+                            Range& entities ) const;
 
     /**\brief Get entities for which an explicit tag of the specified value is stored */
-  MBErrorCode get_entities_with_bits( MBEntityType type, 
-                                      MBRange& entities,
+  ErrorCode get_entities_with_bits( EntityType type, 
+                                      Range& entities,
                                       unsigned char bits ) const;
 
     /**\brief Get entities for which an explicit tag of the specified value is stored */
-  MBErrorCode get_entities_with_bits( const MBRange &range,
-                                      MBEntityType type, 
-                                      MBRange& entities,
+  ErrorCode get_entities_with_bits( const Range &range,
+                                      EntityType type, 
+                                      Range& entities,
                                       unsigned char bits ) const;
 
     /**\brief Get number of entities for which an explicit tag value is stored */
-  MBErrorCode get_number_entities( MBEntityType type,
+  ErrorCode get_number_entities( EntityType type,
                                    int& num_entities ) const;
   
     /**\brief Get number of entities for which an explicit tag value is stored */
-  MBErrorCode get_number_entities( const MBRange &range,
-                                   MBEntityType type,
+  ErrorCode get_number_entities( const Range &range,
+                                   EntityType type,
                                    int& num_entities ) const;
   
-  MBErrorCode get_memory_use( unsigned long& total,
+  ErrorCode get_memory_use( unsigned long& total,
                               unsigned long& per_entity ) const;
                               
   enum { Ln2PageSize = 12,              //!< Constant: log2(PageSize)
@@ -241,7 +243,7 @@
      *         implementation is free to allocate more than the
      *         requested number of bits for each entity
      */
-  MBErrorCode reserve( unsigned int bits_per_entity );
+  ErrorCode reserve( unsigned int bits_per_entity );
   
     /**\brief Helper function for destructive assignment */
   void swap( BitTag& other ) {
@@ -249,7 +251,7 @@
     std::swap( storedBitsPerEntity, other.storedBitsPerEntity );
     std::swap( requestedBitsPerEntity, other.requestedBitsPerEntity );
     std::swap( pageShift, other.pageShift );
-    for (MBEntityType t = (MBEntityType)0; t != MBMAXTYPE; ++t)
+    for (EntityType t = (EntityType)0; t != MBMAXTYPE; ++t)
       pageList[t].swap( other.pageList[t] );
   }
 
@@ -267,7 +269,7 @@
    *\param page   Output: index into pageList[type]
    *\param offset Output: index into pageList[type][page]
    */
-  void unpack( MBEntityHandle h, MBEntityType& type, size_t& page, int& offset ) const
+  void unpack( EntityHandle h, EntityType& type, size_t& page, int& offset ) const
     { 
       type = TYPE_FROM_HANDLE(h);
       h = ID_FROM_HANDLE(h);
@@ -377,7 +379,7 @@
   /**\brief Search stored values for specified value.
    *
    * Find the offsets n in the data at which the specified value occurs,
-   * and for each one insert 'start + n' into the passed MBRange.
+   * and for each one insert 'start + n' into the passed Range.
    *\param value   The value to look for
    *\param offset  The offset at which to begin searching
    *\param count   The number of values to search
@@ -387,7 +389,7 @@
    *               tag value stored at 'offset'
    */
   void search( unsigned char value, int offset, int count, 
-               int bits_per_ent, MBRange& results, MBEntityHandle start ) const;
+               int bits_per_ent, Range& results, EntityHandle start ) const;
 
 private:
 
@@ -439,15 +441,15 @@
 }
 
   
-inline BitTag* BitTagServer::get_tag( MBTagId id )
+inline BitTag* BitTagServer::get_tag( TagId id )
   { return id-1 >= tagList.size() || !tagList[id-1].in_use() ? 0 : &tagList[id-1]; }
   
-inline const BitTag* BitTagServer::get_tag( MBTagId id ) const
+inline const BitTag* BitTagServer::get_tag( TagId id ) const
   { return id-1 >= tagList.size() || !tagList[id-1].in_use() ? 0 : &tagList[id-1]; }
 
-inline MBErrorCode 
-BitTagServer::get_bits( MBTagId tag_id, 
-                        const MBEntityHandle* handles, 
+inline ErrorCode 
+BitTagServer::get_bits( TagId tag_id, 
+                        const EntityHandle* handles, 
                         int num_handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const
@@ -458,9 +460,9 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_bits( MBTagId tag_id, 
-                        const MBRange& handles, 
+inline ErrorCode 
+BitTagServer::get_bits( TagId tag_id, 
+                        const Range& handles, 
                         unsigned char* data,
                         const unsigned char* default_value ) const
 {
@@ -470,9 +472,9 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::set_bits( MBTagId tag_id, 
-                        const MBEntityHandle* handles, 
+inline ErrorCode 
+BitTagServer::set_bits( TagId tag_id, 
+                        const EntityHandle* handles, 
                         int num_handles,
                         const unsigned char* data, 
                         const unsigned char* default_value )
@@ -482,9 +484,9 @@
   else
     return MB_TAG_NOT_FOUND;
 }
-inline MBErrorCode 
-BitTagServer::set_bits( MBTagId tag_id, 
-                        const MBRange& handles, 
+inline ErrorCode 
+BitTagServer::set_bits( TagId tag_id, 
+                        const Range& handles, 
                         const unsigned char* data, 
                         const unsigned char* default_value )
 {
@@ -494,9 +496,9 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::clear_bits( MBTagId tag_id, 
-                          const MBEntityHandle* handles, 
+inline ErrorCode 
+BitTagServer::clear_bits( TagId tag_id, 
+                          const EntityHandle* handles, 
                           int num_handles,
                           const unsigned char* default_value )
 {
@@ -505,9 +507,9 @@
   else
     return MB_TAG_NOT_FOUND;
 }
-inline MBErrorCode 
-BitTagServer::clear_bits( MBTagId tag_id, 
-                          const MBRange& handles, 
+inline ErrorCode 
+BitTagServer::clear_bits( TagId tag_id, 
+                          const Range& handles, 
                           const unsigned char* default_value )
 {
   if (BitTag* ptr = get_tag(tag_id))
@@ -517,8 +519,8 @@
 }
     
 
-inline MBErrorCode 
-BitTagServer::get_entities( MBTagId tag_id, MBRange& entities ) const
+inline ErrorCode 
+BitTagServer::get_entities( TagId tag_id, Range& entities ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
     return ptr->get_entities( entities );
@@ -526,10 +528,10 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_entities( MBTagId tag_id, 
-                            MBEntityType type, 
-                            MBRange& entities ) const
+inline ErrorCode 
+BitTagServer::get_entities( TagId tag_id, 
+                            EntityType type, 
+                            Range& entities ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
     return ptr->get_entities( type, entities );
@@ -537,10 +539,10 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_entities_with_tag_value( MBTagId tag_id, 
-                                           MBEntityType type, 
-                                           MBRange& entities,
+inline ErrorCode 
+BitTagServer::get_entities_with_tag_value( TagId tag_id, 
+                                           EntityType type, 
+                                           Range& entities,
                                            unsigned char bits ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
@@ -549,11 +551,11 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_entities( const MBRange &range,
-                            MBTagId tag_id, 
-                            MBEntityType type, 
-                            MBRange& entities ) const
+inline ErrorCode 
+BitTagServer::get_entities( const Range &range,
+                            TagId tag_id, 
+                            EntityType type, 
+                            Range& entities ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
     return ptr->get_entities( range, type, entities );
@@ -561,11 +563,11 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_entities_with_tag_value( const MBRange &range,
-                                           MBTagId tag_id, 
-                                           MBEntityType type, 
-                                           MBRange& entities,
+inline ErrorCode 
+BitTagServer::get_entities_with_tag_value( const Range &range,
+                                           TagId tag_id, 
+                                           EntityType type, 
+                                           Range& entities,
                                            unsigned char bits ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
@@ -574,9 +576,9 @@
     return MB_TAG_NOT_FOUND;
 }
 
-inline MBErrorCode 
-BitTagServer::get_number_entities( const MBTagId tag_id, 
-                                   const MBEntityType type,
+inline ErrorCode 
+BitTagServer::get_number_entities( const TagId tag_id, 
+                                   const EntityType type,
                                    int& num_entities ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
@@ -585,10 +587,10 @@
     return MB_TAG_NOT_FOUND;
 }
   
-inline MBErrorCode 
-BitTagServer::get_number_entities( const MBRange &range,
-                                   const MBTagId tag_id, 
-                                   const MBEntityType type,
+inline ErrorCode 
+BitTagServer::get_number_entities( const Range &range,
+                                   const TagId tag_id, 
+                                   const EntityType type,
                                    int& num_entities ) const
 {
   if (const BitTag* ptr = get_tag(tag_id))
@@ -597,18 +599,20 @@
     return MB_TAG_NOT_FOUND;
 }
   
-inline MBErrorCode 
-BitTagServer::get_memory_use( MBTagId tag,
+inline ErrorCode 
+BitTagServer::get_memory_use( TagId tag,
                               unsigned long& total,
                               unsigned long& per_entity ) const
 {
   if (const BitTag* ptr = get_tag(tag)) {
-    MBErrorCode result = ptr->get_memory_use( total, per_entity );
+    ErrorCode result = ptr->get_memory_use( total, per_entity );
     total += sizeof(*this);
     return result;
   }
   else
     return MB_TAG_NOT_FOUND;
 }
+  
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/CMakeLists.txt
===================================================================
--- MOAB/trunk/src/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -10,27 +10,27 @@
     GeomTopoTool.cpp
     HigherOrderFactory.cpp
     HomXform.cpp
-    MBAdaptiveKDTree.cpp
-    MBAffineXform.cpp
-    MBAxisBox.cpp
-    MBBSPTree.cpp
-    MBCN.cpp
-    MBCartVect.cpp
-    MBMatrix3.cpp
-    MBCore.cpp
-    MBFactory.cpp
-    MBGeomUtil.cpp
-    MBMeshSet.cpp
-    MBOrientedBox.cpp
-    MBOrientedBoxTreeTool.cpp
-    MBRange.cpp
-    MBRangeSeqIntersectIter.cpp
-    MBReadUtil.cpp
-    MBReaderWriterSet.cpp
-    MBSkinner.cpp
-    MBSysUtil.cpp
-    MBUtil.cpp
-    MBWriteUtil.cpp
+    AdaptiveKDTree.cpp
+    AffineXform.cpp
+    AxisBox.cpp
+    BSPTree.cpp
+    CN.cpp
+    CartVect.cpp
+    Matrix3.cpp
+    Core.cpp
+    Factory.cpp
+    GeomUtil.cpp
+    MeshSet.cpp
+    OrientedBox.cpp
+    OrientedBoxTreeTool.cpp
+    Range.cpp
+    RangeSeqIntersectIter.cpp
+    ReadUtil.cpp
+    ReaderWriterSet.cpp
+    Skinner.cpp
+    SysUtil.cpp
+    Util.cpp
+    WriteUtil.cpp
     MeshSetSequence.cpp
     MeshTopoUtil.cpp
     PolyElementSeq.cpp
@@ -55,10 +55,6 @@
     ${MOAB_BINARY_DIR}/src
     ${MOAB_SOURCE_DIR}/src/io
     ${MOAB_BINARY_DIR}/src/io
-    ${MOAB_SOURCE_DIR}/src/moab
-    ${MOAB_BINARY_DIR}/src/moab
-    ${MOAB_SOURCE_DIR}/src/io/moab
-    ${MOAB_BINARY_DIR}/src/io/moab
   )
 
   if ( MOAB_USE_MPI )

Copied: MOAB/trunk/src/CartVect.cpp (from rev 3583, MOAB/trunk/src/MBCartVect.cpp)
===================================================================
--- MOAB/trunk/src/CartVect.cpp	                        (rev 0)
+++ MOAB/trunk/src/CartVect.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,24 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#include "moab/CartVect.hpp"
+#include <ostream>
+
+namespace moab {
+
+std::ostream& operator<<( std::ostream& s, const CartVect& v )
+  { return s << '[' << v[0] << ' ' << v[1] << ' ' << v[2] << ']'; }
+  
+} // namespace moab

Copied: MOAB/trunk/src/Core.cpp (from rev 3583, MOAB/trunk/src/MBCore.cpp)
===================================================================
--- MOAB/trunk/src/Core.cpp	                        (rev 0)
+++ MOAB/trunk/src/Core.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,3547 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifdef WIN32
+// turn off warnings that say they debugging identifier has been truncated
+// this warning comes up when using some STL containers
+#pragma warning(disable : 4786)
+#endif
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <string>
+#include <algorithm>
+#include "moab/Version.h"
+#include "moab/Core.hpp"
+#include "TagServer.hpp"
+#include "MeshSetSequence.hpp"
+#include "ElementSequence.hpp"
+#include "VertexSequence.hpp"
+#include "assert.h"
+#include "AEntityFactory.hpp"
+#include "ReadUtil.hpp"
+#include "WriteUtil.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/HigherOrderFactory.hpp"
+#include "SequenceManager.hpp"
+#include "Error.hpp"
+#include "moab/ReaderWriterSet.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/WriterIface.hpp"
+
+#ifdef USE_MPI
+/* Leave ParallelComm.hpp before mpi.h or MPICH2 will fail
+ * because its C++ headers do not like SEEK_* macros.
+ */
+#include "moab/ParallelComm.hpp"
+#include "moab_mpi.h"
+#include "ReadParallel.hpp"
+#endif
+
+#ifdef HDF5_FILE
+#  include "WriteHDF5.hpp"
+   typedef moab::WriteHDF5 DefaultWriter;
+#elif defined(NETCDF_FILE)
+#  include "WriteNCDF.hpp"
+   typedef moab::WriteNCDF DefaultWriter;
+#else
+#  include "WriteVtk.hpp"
+   typedef moab::WriteVtk DefaultWriter;
+#endif
+#include "moab/MBTagConventions.hpp"
+#include "ExoIIUtil.hpp"
+#include "EntitySequence.hpp"
+#include "FileOptions.hpp"
+#ifdef LINUX
+# include <dlfcn.h>
+# include <dirent.h>
+#endif
+
+
+#ifdef XPCOM_MB
+#include "nsMemory.h"
+#endif
+
+namespace moab {
+
+using namespace std;
+
+static inline const MeshSet* get_mesh_set( const SequenceManager* sm,
+                                             EntityHandle h )
+{
+  const EntitySequence* seq;
+  if (MBENTITYSET != TYPE_FROM_HANDLE(h) || MB_SUCCESS != sm->find( h, seq ))
+    return 0;
+  return reinterpret_cast<const MeshSetSequence*>(seq)->get_set(h);
+}
+
+static inline MeshSet* get_mesh_set( SequenceManager* sm,
+                                       EntityHandle h )
+{
+  EntitySequence* seq;
+  if (MBENTITYSET != TYPE_FROM_HANDLE(h) || MB_SUCCESS != sm->find( h, seq ))
+    return 0;
+  return reinterpret_cast<MeshSetSequence*>(seq)->get_set(h);
+}
+
+//! Constructor
+Core::Core()
+{
+#ifdef XPCOM_MB
+  NS_INIT_ISUPPORTS();
+#endif
+
+  if (initialize() != MB_SUCCESS)
+  {
+    printf("Error initializing moab::Core\n");
+    exit(1);
+  }
+}
+
+
+//! Constructor
+Core::Core( int , int  ) 
+{
+  std::cerr << "Using depricated construtor: Core::Core(rank,size)" << std::endl;
+
+#ifdef XPCOM_MB
+  NS_INIT_ISUPPORTS();
+#endif
+
+  if (initialize() != MB_SUCCESS)
+  {
+    printf("Error initializing moab::Core\n");
+    exit(1);
+  }
+}
+
+//! destructor
+Core::~Core()
+{
+  if(mMBWriteUtil)
+    delete mMBWriteUtil;
+  if(mMBReadUtil) 
+    delete mMBReadUtil;
+  
+  mMBWriteUtil = NULL;
+  mMBReadUtil = NULL;
+
+  deinitialize();
+}
+
+
+ErrorCode Core::initialize()
+{
+  geometricDimension = 3;
+  materialTag      = 0;
+  neumannBCTag     = 0;
+  dirichletBCTag   = 0;
+  geomDimensionTag = 0;
+  globalIdTag      = 0;
+  
+  sequenceManager = new SequenceManager;
+  if (!sequenceManager)
+    return MB_MEMORY_ALLOCATION_FAILED;
+
+  tagServer = new TagServer( sequenceManager );
+  if (!tagServer)
+    return MB_MEMORY_ALLOCATION_FAILED;
+
+  aEntityFactory = new AEntityFactory(this);
+  if (!aEntityFactory)
+    return MB_MEMORY_ALLOCATION_FAILED;
+
+  mError = new Error;
+
+  mMBWriteUtil = NULL;
+  mMBReadUtil = NULL;
+    
+    // Readers and writers try to get pointers to above utils.
+    // Do this after pointers are initialized. (Pointers should
+    // really be initialized in constructor to avoid this kind
+    // of thing -- j.kraftcheck.)
+  readerWriterSet = new ReaderWriterSet( this, mError );
+  if (!readerWriterSet)
+    return MB_MEMORY_ALLOCATION_FAILED;
+  
+  material_tag();
+  neumannBC_tag();
+  dirichletBC_tag();
+  geom_dimension_tag();
+  globalId_tag();
+
+  return MB_SUCCESS;
+}
+
+EntityHandle Core::get_root_set() 
+{
+  return 0;
+}
+
+void Core::deinitialize()
+{
+
+#ifdef USE_MPI    
+  std::vector<ParallelComm*> pc_list;
+  ParallelComm::get_all_pcomm(this, pc_list);
+  for (std::vector<ParallelComm*>::iterator vit = pc_list.begin();
+       vit != pc_list.end(); vit++) 
+    delete *vit;
+#endif
+  
+  if (aEntityFactory)
+    delete aEntityFactory;
+
+  aEntityFactory = 0;
+
+  if (tagServer)
+    delete tagServer;
+
+  tagServer = 0;
+  
+  if (sequenceManager)
+    delete sequenceManager;
+
+  sequenceManager = 0;
+  
+  delete readerWriterSet;
+  readerWriterSet = 0;
+
+  if(mError)
+    delete mError;
+  mError = 0;
+}
+
+ErrorCode Core::query_interface(const std::string& iface_name, void** iface)
+{
+  if(iface_name == "ReadUtilIface")
+  {
+    if(mMBReadUtil)
+      *iface = (ReadUtilIface*)mMBReadUtil;
+    else
+      *iface = (ReadUtilIface*)(mMBReadUtil = new ReadUtil(this, mError));
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "WriteUtilIface")
+  {
+    if(mMBWriteUtil)
+      *iface = (WriteUtilIface*)mMBWriteUtil;
+    else
+      *iface = (WriteUtilIface*)(mMBWriteUtil = new WriteUtil(this, mError));
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "ReaderWriterSet")
+  {
+    *iface = reader_writer_set();
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "ExoIIInterface")
+  {
+    *iface = (void*)(ExoIIInterface*) new ExoIIUtil(this);
+    return MB_SUCCESS;
+  }
+  return MB_FAILURE;
+}
+
+
+ErrorCode Core::release_interface(const std::string& iface_name, void* iface)
+{
+  if(iface == NULL)
+    return MB_FAILURE;
+
+  if(iface_name == "ReadUtilIface")
+  {
+      // Is it possible to crash here?  We should fail gracefully instead.
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "WriteUtilIface")
+  {
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "ReaderWriterSet")
+  {
+    return MB_SUCCESS;
+  }
+  else if(iface_name == "ExoIIInterface")
+  {
+    delete (ExoIIInterface*)iface;
+    return MB_SUCCESS;
+  }
+  
+  return MB_FAILURE;
+}
+
+
+#ifdef XPCOM_MB
+// provides basic implementation of nsISupports methods
+NS_IMPL_ISUPPORTS1_CI(Core, Interface);
+#endif
+
+int Core::QueryInterface(const MBuuid& uuid, UnknownInterface** iface)
+{
+  *iface = 0;
+  if(uuid == IDD_MBUnknown)
+    *iface = this;
+  if(uuid == IDD_MBCore)
+    *iface = this;
+  else
+    return 0;
+  return 1;
+}
+
+float Core::impl_version( std::string *version_string )
+{
+  if (version_string)
+    *version_string = MB_VERSION_STRING;
+  
+  return MB_VERSION_MAJOR + MB_VERSION_MINOR / 100.0f;
+}
+
+//! get the type from a handle, returns type
+EntityType Core::type_from_handle(const EntityHandle handle) const
+{
+  return TYPE_FROM_HANDLE(handle);
+}
+  
+//! get the id from a handle, returns id
+EntityID Core::id_from_handle(const EntityHandle handle) const
+{
+  return ID_FROM_HANDLE(handle);
+}
+
+//! get a handle from an id and type
+ErrorCode Core::handle_from_id( const EntityType type, 
+                                    const EntityID id, 
+                                    EntityHandle& handle) const
+{
+  int err;
+  handle = CREATE_HANDLE(type, id, err);
+
+    //check to see if handle exists 
+  const EntitySequence *dummy_seq = 0;
+  ErrorCode error_code = sequence_manager()->find(handle, dummy_seq);
+  return error_code; 
+}
+
+int Core::dimension_from_handle(const EntityHandle handle) const
+{
+  return MBCN::Dimension(TYPE_FROM_HANDLE(handle));
+}
+
+//! load mesh from data in file
+//! NOTE: if there is mesh already present, the new mesh will be added
+ErrorCode  Core::load_mesh( const char *file_name,
+                                const int* block_id_list,
+                                const int num_blocks )
+{
+  const char* name = block_id_list ? MATERIAL_SET_TAG_NAME : 0;
+  return load_file( file_name, 0, 0, name, block_id_list, num_blocks );
+}
+
+ErrorCode Core::load_file( const char* file_name,
+                               const EntityHandle* file_set,
+                               const char* options,
+                               const char* set_tag_name,
+                               const int* set_tag_vals,
+                               int num_set_tag_vals )
+{
+  FileOptions opts(options);
+  ErrorCode rval;
+  ReaderIface::IDTag t = { set_tag_name, set_tag_vals, num_set_tag_vals, 0, 0 };
+  
+    // if reading in parallel, call a different reader
+  std::string parallel_opt;
+  rval = opts.get_option( "PARALLEL", parallel_opt);
+  if (MB_SUCCESS == rval) {
+#ifdef USE_MPI    
+    ParallelComm* pcomm = 0;
+    int pcomm_id;
+    rval = opts.get_int_option( "PCOMM", pcomm_id );
+    if (rval == MB_SUCCESS) {
+      pcomm = ParallelComm::get_pcomm( this, pcomm_id );
+      if (!pcomm)
+        return MB_ENTITY_NOT_FOUND;
+    }
+    else if (rval != MB_ENTITY_NOT_FOUND) 
+      return rval;
+    if (set_tag_name && num_set_tag_vals) 
+      rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts, &t, 1 );
+    else
+      rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts );
+#else
+    mError->set_last_error( "PARALLEL option not valid, this instance"
+                            " compiled for serial execution.\n" );
+    return MB_NOT_IMPLEMENTED;
+#endif
+  }
+  else {
+    if (set_tag_name && num_set_tag_vals) 
+      rval = serial_load_file( file_name, file_set, opts, &t, 1 );
+    else 
+      rval = serial_load_file( file_name, file_set, opts );
+  }
+  
+  if (MB_SUCCESS == rval && !opts.all_seen()) {
+    std::string bad_opt;
+    if (MB_SUCCESS == opts.get_unseen_option( bad_opt ))
+      mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
+    else
+      mError->set_last_error( "Unrecognized option." );
+    rval = MB_UNHANDLED_OPTION;
+  }
+  
+  return rval;
+}
+
+void Core::clean_up_failed_read( const Range& initial_ents,
+                                   std::vector<Tag> initial_tags )
+{
+  Range new_ents;
+  get_entities_by_handle( 0, new_ents );
+  new_ents = subtract( new_ents, initial_ents );
+  delete_entities( new_ents );
+
+  std::vector<Tag> all_tags, new_tags;
+  tag_get_tags( all_tags );
+  std::sort( initial_tags.begin(), initial_tags.end() );
+  std::sort( all_tags.begin(), all_tags.end() );
+  std::set_difference( all_tags.begin(), all_tags.end(),
+                       initial_tags.begin(), initial_tags.end(),
+                       std::back_inserter( new_tags ) );
+  while (!new_tags.empty()) {
+    tag_delete( new_tags.back() );
+    new_tags.pop_back();
+  }
+}
+
+ErrorCode Core::serial_load_file( const char* file_name,
+                                      const EntityHandle* file_set,
+                                      const FileOptions& opts,
+                                      const ReaderIface::IDTag* subsets,
+                                      int num_sets,
+                                      const Tag* id_tag  )
+{
+  if (num_sets < 0)
+    return MB_INDEX_OUT_OF_RANGE;
+  
+  ErrorCode rval = MB_FAILURE;
+  const ReaderWriterSet* set = reader_writer_set();
+
+  
+  Range initial_ents;
+  rval = get_entities_by_handle( 0, initial_ents );
+  if (MB_SUCCESS != rval)
+    return rval;
+    
+  std::vector<Tag> initial_tags;
+  rval = tag_get_tags( initial_tags );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+    // otherwise try using the file extension to select a reader
+  ReaderIface* reader = set->get_file_extension_reader( file_name );
+  if (reader)
+  {
+    rval = reader->load_file( file_name, file_set, opts, subsets, num_sets, id_tag );
+    delete reader;
+  }
+  else
+  {  
+      // Try all the readers
+    ReaderWriterSet::iterator iter;
+    for (iter = set->begin(); iter != set->end(); ++iter)
+    {
+      ReaderIface* reader = iter->make_reader( this );
+      if (NULL != reader)
+      {
+        rval = reader->load_file( file_name, file_set, opts, subsets, num_sets, id_tag );
+        delete reader;
+        if (MB_SUCCESS == rval)
+          break;
+        clean_up_failed_read( initial_ents, initial_tags );
+      }
+    }
+  }
+  
+  if (MB_SUCCESS != rval) {
+    clean_up_failed_read( initial_ents, initial_tags );
+  }
+  else if (file_set) {
+    Range new_ents;
+    get_entities_by_handle( 0, new_ents );
+    new_ents = subtract( new_ents, initial_ents );
+    rval = add_entities( *file_set, new_ents );
+  }
+  
+  return rval; 
+}
+
+ErrorCode Core::serial_read_tag( const char* file_name,
+                                     const char* tag_name,
+                                     const FileOptions& opts,
+                                     std::vector<int>& vals,
+                                     const ReaderIface::IDTag* subsets,
+                                     int num_sets )
+{
+  if (num_sets < 0)
+    return MB_INDEX_OUT_OF_RANGE;
+  
+  ErrorCode rval = MB_FAILURE;
+  const ReaderWriterSet* set = reader_writer_set();
+
+    // otherwise try using the file extension to select a reader
+  ReaderIface* reader = set->get_file_extension_reader( file_name );
+  if (reader)
+  {
+    rval = reader->read_tag_values( file_name, tag_name, opts, vals, subsets, num_sets );
+    delete reader;
+  }
+  else
+  {  
+      // Try all the readers
+    ReaderWriterSet::iterator iter;
+    for (iter = set->begin(); iter != set->end(); ++iter)
+    {
+      ReaderIface* reader = iter->make_reader( this );
+      if (NULL != reader)
+      {
+        rval = reader->read_tag_values( file_name, tag_name, opts, vals, subsets, num_sets );
+        delete reader;
+        if (MB_SUCCESS == rval)
+          break;
+      }
+    }
+  }
+  
+  return rval; 
+}
+
+ErrorCode  Core::write_mesh(const char *file_name,
+                                  const EntityHandle *output_list,
+                                  const int num_sets)
+{
+  return write_file( file_name, 0, 0, output_list, num_sets );
+}
+
+ErrorCode Core::write_file( const char* file_name,
+                                const char* file_type,
+                                const char* options,
+                                const EntityHandle* output_sets,
+                                int num_output_sets,
+                                const Tag* tag_list,
+                                int num_tags )
+{
+  Range range;
+  std::copy( output_sets, output_sets+num_output_sets, range_inserter(range) );
+  return write_file( file_name, file_type, options, range, tag_list, num_tags );
+}
+
+ErrorCode Core::write_file( const char* file_name,
+                                const char* file_type,
+                                const char* options_string,
+                                const Range& output_sets,
+                                const Tag* tag_list,
+                                int num_tags )
+{
+    // convert range to vector
+  std::vector<EntityHandle> list( output_sets.size() );
+  std::copy( output_sets.begin(), output_sets.end(), list.begin() );
+  
+    // parse some options
+  FileOptions opts( options_string );
+  ErrorCode rval;
+  
+  rval = opts.get_null_option( "CREATE" );
+  if (rval == MB_TYPE_OUT_OF_RANGE) {
+    mError->set_last_error( "Unexpected value for CREATE option\n" );
+    return MB_FAILURE;
+  }
+  bool overwrite = (rval == MB_ENTITY_NOT_FOUND);
+
+    // Get the file writer
+  ReaderWriterSet::iterator i;
+  if (file_type) {
+    i = reader_writer_set()->handler_by_name( file_type );
+    if (i == reader_writer_set()->end()) {
+      mError->set_last_error( "Unknown file type: %s\n", file_type );
+      return MB_NOT_IMPLEMENTED;
+    }
+  }
+  else {
+    std::string ext = ReaderWriterSet::extension_from_filename( file_name );
+    i = reader_writer_set()->handler_from_extension( ext );
+  }
+  
+  WriterIface* writer;
+  if (i == reader_writer_set()->end())
+    writer = new DefaultWriter(this);
+  else
+    writer = i->make_writer( this );
+  
+  if (!writer) {
+    mError->set_last_error( "File format supported for reading only.\n" );
+    return MB_NOT_IMPLEMENTED;
+  }
+  
+    // write the file
+  std::vector<std::string> qa_records;
+  const EntityHandle* list_ptr = list.empty() ? (EntityHandle*)0 : &list[0];
+  rval = writer->write_file(file_name, overwrite, opts, list_ptr, list.size(), qa_records,
+                            tag_list, num_tags );
+  delete writer;
+  
+  if (MB_SUCCESS == rval && !opts.all_seen()) {
+    std::string bad_opt;
+    if (MB_SUCCESS == opts.get_unseen_option( bad_opt ))
+      mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
+    else
+      mError->set_last_error( "Unrecognized option." );
+    rval = MB_UNHANDLED_OPTION;
+  }
+
+  return rval;
+}
+   
+  
+
+//! deletes all mesh entities from this datastore
+ErrorCode Core::delete_mesh()
+{
+
+  ErrorCode result = MB_SUCCESS;
+
+    // perform all deinitialization procedures to clean up
+  if (aEntityFactory)
+    delete aEntityFactory;
+  aEntityFactory = new AEntityFactory(this);
+
+  tagServer->reset_all_data();
+  
+  sequenceManager->clear();
+
+  return result;
+}
+
+  //! get overall geometric dimension
+ErrorCode Core::get_dimension(int &dim) const
+{
+  dim = geometricDimension;
+  return MB_SUCCESS;
+}
+
+  //! set overall geometric dimension
+  /** Returns error if setting to 3 dimensions, mesh has been created, and 
+   *  there are only 2 dimensions on that mesh
+   */
+ErrorCode Core::set_dimension(const int dim) 
+{
+    // check to see if current dimension is smaller
+  if (geometricDimension < dim) 
+  {
+      // need to check the number of entities 
+    int num;
+    /*ErrorCode result = */ get_number_entities_by_dimension(0, geometricDimension, num);
+    
+      // test written to be more readable but possibly less efficient
+      //if (MB_SUCCESS != result) return MB_FAILURE;
+      //else if (0 != num && dim == 2 && ycoordTag == 0) return MB_FAILURE;
+      //else if (0 != num && dim == 3 && (ycoordTag == 0 || zcoordTag == 0)) return MB_FAILURE;
+      //TODO -- replace this with not using xcoordTag, etc...
+  }
+    
+    // if we got here, it's ok to set dimension
+  geometricDimension = dim;
+  return MB_SUCCESS;
+}
+
+  //! get blocked vertex coordinates for all vertices
+  /** Blocked = all x, then all y, etc. 
+   */
+ErrorCode Core::get_vertex_coordinates(std::vector<double> &coords) const
+{
+    // INEFFICIENT implementation for now, until we get blocked tag access
+  Range vertices;
+  ErrorCode result = get_entities_by_type(0, MBVERTEX, vertices);
+  if (MB_SUCCESS != result) return result;
+  
+    // the least we can do is resize the vector and only go through the 
+    // vertex list once
+  int num_verts = vertices.size();
+  int vec_pos = 0;
+  double xyz[3];
+  coords.resize(geometricDimension*num_verts);
+  for (Range::iterator it = vertices.begin(); it != vertices.end(); it++) 
+  {
+    result = get_coords(&(*it), 1, xyz);
+    if (MB_SUCCESS != result) return result;
+
+    coords[vec_pos] = xyz[0];
+    coords[num_verts+vec_pos] = xyz[1];
+    coords[2*num_verts+vec_pos] = xyz[2];
+
+    vec_pos++;
+  }
+  
+  return result;
+}
+
+ErrorCode  Core::get_coords(const Range& entities, double *coords) const
+{
+  const TypeSequenceManager& vert_data = sequence_manager()->entity_map( MBVERTEX );
+  TypeSequenceManager::const_iterator seq_iter;
+  
+  Range::const_pair_iterator i = entities.const_pair_begin();
+  EntityHandle first = i->first;
+  while (i != entities.const_pair_end()) {
+    
+    seq_iter = vert_data.lower_bound( first );
+    if (seq_iter == vert_data.end() || first < (*seq_iter)->start_handle())
+      return MB_ENTITY_NOT_FOUND;
+    const VertexSequence* vseq = reinterpret_cast<const VertexSequence*>(*seq_iter);
+
+    EntityID offset = first - vseq->start_handle();
+    EntityID count;
+    if (i->second <= vseq->end_handle()) {
+      count = i->second - first + 1;
+      ++i;
+      if (i != entities.const_pair_end())
+        first = i->first;
+    }
+    else {
+      count = vseq->end_handle() - first + 1;
+      first = vseq->end_handle()+1;
+    }
+    
+    double const *x, *y, *z;
+    ErrorCode rval = vseq->get_coordinate_arrays( x, y, z );
+    if (MB_SUCCESS != rval)
+      return rval;
+    x += offset;
+    y += offset;
+    z += offset;
+    for (EntityID j = 0; j < count; ++j) {
+      *coords = *x; ++coords; ++x;
+      *coords = *y; ++coords; ++y;
+      *coords = *z; ++coords; ++z;
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+/**\author Jason Kraftcheck <kraftche at cae.wisc.edu> - 2007-5-15 */
+ErrorCode Core::get_coords( const Range& entities, 
+                                double *x_coords,
+                                double *y_coords,
+                                double *z_coords ) const
+{
+  const TypeSequenceManager& vert_data = sequence_manager()->entity_map( MBVERTEX );
+  TypeSequenceManager::const_iterator seq_iter;
+  
+  Range::const_pair_iterator i = entities.const_pair_begin();
+  EntityHandle first = i->first;
+  while (i != entities.const_pair_end()) {
+    
+    seq_iter = vert_data.lower_bound( first );
+    if (seq_iter == vert_data.end() || first < (*seq_iter)->start_handle())
+      return MB_ENTITY_NOT_FOUND;
+    const VertexSequence* vseq = reinterpret_cast<const VertexSequence*>(*seq_iter);
+
+    EntityID offset = first - vseq->start_handle();
+    EntityID count;
+    if (i->second <= vseq->end_handle()) {
+      count = i->second - first + 1;
+      ++i;
+      if (i != entities.const_pair_end())
+        first = i->first;
+    }
+    else {
+      count = vseq->end_handle() - first + 1;
+      first = vseq->end_handle()+1;
+    }
+    
+    double const *x, *y, *z;
+    ErrorCode rval = vseq->get_coordinate_arrays( x, y, z );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (x_coords) {
+      memcpy( x_coords, x + offset, count * sizeof(double ) );
+      x_coords += count;
+    }
+    if (y_coords) {
+      memcpy( y_coords, y + offset, count * sizeof(double ) );
+      y_coords += count;
+    }
+    if (z_coords) {
+      memcpy( z_coords, z + offset, count * sizeof(double ) );
+      z_coords += count;
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode  Core::get_coords(const EntityHandle* entities, 
+                                  const int num_entities, 
+                                  double *coords) const
+{
+  const EntitySequence* seq;
+  const VertexSequence* vseq;
+  const EntityHandle* const end = entities + num_entities;
+  const EntityHandle* iter = entities;
+  
+  seq = sequence_manager()->get_last_accessed_sequence( MBVERTEX );
+  if (!seq) // no vertices
+    return num_entities ? MB_ENTITY_NOT_FOUND : MB_SUCCESS;
+  vseq = static_cast<const VertexSequence*>(seq);
+  
+  while (iter != end) {
+    if (vseq->start_handle() > *iter || vseq->end_handle() < *iter) {
+      if (TYPE_FROM_HANDLE(*iter) != MBVERTEX)
+        return MB_TYPE_OUT_OF_RANGE;
+        
+      if (MB_SUCCESS != sequence_manager()->find(*iter, seq))
+        return MB_ENTITY_NOT_FOUND;
+      vseq = static_cast<const VertexSequence*>(seq);
+    }
+    
+    vseq->get_coordinates( *iter, coords );
+    coords += 3;
+    ++iter;
+  } 
+
+  return MB_SUCCESS; 
+}
+
+
+ErrorCode  Core::get_coords(const EntityHandle entity_handle, 
+                                  const double *& x, const double *& y, const double *& z) const
+{
+
+  ErrorCode status = MB_TYPE_OUT_OF_RANGE;
+
+  if ( TYPE_FROM_HANDLE(entity_handle) == MBVERTEX )
+  {
+    const EntitySequence* seq = 0;
+    status = sequence_manager()->find(entity_handle, seq);
+
+    if (seq == 0 || status != MB_SUCCESS)
+      return MB_ENTITY_NOT_FOUND;
+
+    status = static_cast<const VertexSequence*>(seq)->get_coordinates_ref(entity_handle, 
+                                                                          x, y, z);
+
+  }
+
+  return status; 
+
+}
+
+//! set the coordinate information for this handle if it is of type Vertex
+//! otherwise, return an error
+ErrorCode  Core::set_coords( const EntityHandle *entity_handles, 
+                                 const int num_entities, 
+                                 const double *coords)
+{
+
+  ErrorCode status = MB_SUCCESS;
+
+  int i, j = 0;
+
+  for (i = 0; i < num_entities; i++) {
+    if ( TYPE_FROM_HANDLE(entity_handles[i]) == MBVERTEX )
+    {
+      EntitySequence* seq = 0;
+      status = sequence_manager()->find(entity_handles[i], seq);
+
+      if (seq != 0 && status == MB_SUCCESS) {
+        status = static_cast<VertexSequence*>(seq)->set_coordinates(entity_handles[i], coords[j], coords[j+1], coords[j+2]);
+        j += 3;
+      }
+    }
+    else if (status == MB_SUCCESS)
+      status = MB_TYPE_OUT_OF_RANGE;
+  }
+
+  return status; 
+
+}
+
+//! set the coordinate information for this handle if it is of type Vertex
+//! otherwise, return an error
+ErrorCode  Core::set_coords(Range entity_handles, const double *coords)
+{
+
+  ErrorCode status = MB_SUCCESS;
+
+  int j = 0;
+
+  for (Range::iterator rit = entity_handles.begin(); rit != entity_handles.end(); rit++) {
+    if ( TYPE_FROM_HANDLE(*rit) == MBVERTEX )
+    {
+      EntitySequence* seq = 0;
+      status = sequence_manager()->find(*rit, seq);
+
+      if (seq != 0 && status == MB_SUCCESS) {
+        status = static_cast<VertexSequence*>(seq)->set_coordinates(*rit, coords[j], coords[j+1], coords[j+2]);
+        j += 3;
+      }
+    }
+    else if (status == MB_SUCCESS)
+      status = MB_TYPE_OUT_OF_RANGE;
+  }
+
+  return status; 
+
+}
+
+  //! get global connectivity array for specified entity type
+  /**  Assumes just vertices, no higher order nodes
+   */
+ErrorCode Core::get_connectivity_by_type(const EntityType type, 
+                                               std::vector<EntityHandle> &connect) const
+{
+    // inefficient implementation until we get blocked tag access
+  
+    // get the range of entities of this type
+  Range this_range;
+  ErrorCode result = get_entities_by_type(0, type, this_range);
+  
+  int num_ents = this_range.size();
+  connect.reserve(num_ents*MBCN::VerticesPerEntity(type));
+  
+    // now loop over these entities, getting connectivity for each
+  for (Range::iterator this_it = this_range.begin(); 
+       this_it != this_range.end();
+       this_it++)
+  {
+    const EntityHandle *connect_vec;
+    result = get_connectivity(*this_it, connect_vec, num_ents, true);
+    if (MB_SUCCESS != result) 
+      return result;
+    connect.insert(connect.end(), &connect_vec[0], &connect_vec[num_ents]); 
+  }
+  
+  return MB_SUCCESS;
+}
+  
+
+//! get the connectivity for element /handles.  For non-element handles, return an error
+ErrorCode  Core::get_connectivity(const EntityHandle *entity_handles, 
+                                      const int num_handles,
+                                      Range &connectivity,
+                                      bool topological_connectivity) const
+{
+  std::vector<EntityHandle> tmp_connect;
+  ErrorCode result = get_connectivity(entity_handles, num_handles, tmp_connect,
+                                        topological_connectivity);
+  if (MB_SUCCESS != result) return result;
+  
+  std::sort( tmp_connect.begin(), tmp_connect.end() );
+  std::copy(tmp_connect.rbegin(), tmp_connect.rend(), range_inserter(connectivity));
+  return result;
+}
+
+//! get the connectivity for element /handles.  For non-element handles, return an error
+ErrorCode  Core::get_connectivity(const EntityHandle *entity_handles, 
+                                      const int num_handles,
+                                      std::vector<EntityHandle> &connectivity,
+                                      bool topological_connectivity) const
+{
+  connectivity.clear(); // this seems wrong as compared to other API functions,
+                        // but changing it breaks lost of code, so I'm leaving
+                        // it in.  - j.kraftcheck 2009-11-06
+  
+  ErrorCode rval;
+  std::vector<EntityHandle> tmp_storage; // used only for structured mesh
+  const EntityHandle* conn;
+  int len;
+  for (int i = 0; i < num_handles; ++i) {
+    rval = get_connectivity( entity_handles[i], conn, len, topological_connectivity, &tmp_storage );
+    if (MB_SUCCESS != rval)
+      return rval;
+    connectivity.insert( connectivity.end(), conn, conn + len );
+  }
+  return MB_SUCCESS;
+}
+
+//! get the connectivity for element handles.  For non-element handles, return an error
+ErrorCode Core::get_connectivity(const EntityHandle entity_handle, 
+                                     const EntityHandle*& connectivity,
+                                     int& number_nodes,
+                                     bool topological_connectivity,
+                                     std::vector<EntityHandle>* storage) const
+{
+  ErrorCode status;
+
+    // Make sure the entity should have a connectivity.
+  EntityType type = TYPE_FROM_HANDLE(entity_handle);
+  
+    // WARNING: This is very dependent on the ordering of the EntityType enum
+  if(type < MBVERTEX || type >= MBENTITYSET)
+    return MB_TYPE_OUT_OF_RANGE;
+
+  else if (type == MBVERTEX) {
+    return MB_FAILURE;
+  }
+  
+  const EntitySequence* seq = 0;
+
+    // We know that connectivity is stored in an EntitySequence so jump straight
+    // to the entity sequence
+  status = sequence_manager()->find(entity_handle, seq);
+  if (seq == 0 || status != MB_SUCCESS) 
+    return MB_ENTITY_NOT_FOUND;
+
+  return static_cast<const ElementSequence*>(seq)->get_connectivity(entity_handle, 
+                                                              connectivity,
+                                                              number_nodes,
+                                                              topological_connectivity,
+                                                              storage);
+}
+
+//! set the connectivity for element handles.  For non-element handles, return an error
+ErrorCode  Core::set_connectivity(const EntityHandle entity_handle, 
+                                      EntityHandle *connect,
+                                      const int num_connect)
+{
+  ErrorCode status = MB_FAILURE;
+
+    // Make sure the entity should have a connectivity.
+    // WARNING: This is very dependent on the ordering of the EntityType enum
+  EntityType type = TYPE_FROM_HANDLE(entity_handle);
+  
+  EntitySequence* seq = 0;
+
+  if (type < MBVERTEX || type > MBENTITYSET)
+    return MB_TYPE_OUT_OF_RANGE;
+  
+  status = sequence_manager()->find(entity_handle, seq);
+  if (seq == 0 || status != MB_SUCCESS)
+    return (status != MB_SUCCESS ? status : MB_ENTITY_NOT_FOUND);
+
+  const EntityHandle* old_conn;
+  int len;
+  status = static_cast<ElementSequence*>(seq)->get_connectivity(entity_handle, old_conn, len);
+  if (status != MB_SUCCESS) return status;
+
+  aEntityFactory->notify_change_connectivity(
+    entity_handle, old_conn, connect, num_connect);
+  
+  status = static_cast<ElementSequence*>(seq)->set_connectivity(entity_handle, 
+                                                                connect, num_connect);
+  if (status != MB_SUCCESS) 
+    aEntityFactory->notify_change_connectivity(
+      entity_handle, connect, old_conn, num_connect);
+
+  return status;
+}
+
+
+template <typename ITER> static inline
+ErrorCode get_adjacencies_union( Core* gMB,
+                                   ITER begin, ITER end,
+                                   int to_dimension,
+                                   bool create_if_missing,
+                                   Range& adj_entities )
+{ 
+  const size_t DEFAULT_MAX_BLOCKS_SIZE = 4000;
+  const size_t MAX_OUTER_ITERATIONS = 100;
+
+  std::vector<EntityHandle> temp_vec, storage;
+  std::vector<EntityHandle>::const_iterator ti;
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  ITER i = begin;
+  Range::iterator ins;
+  const EntityHandle* conn;
+  int conn_len;
+
+    // Just copy any vertices from the input range into the output
+  size_t remaining = end - begin;
+  assert(begin + remaining == end);
+  
+    // How many entities to work with at once? 2000 or so shouldn't require
+    // too much memory, but don't iterate in outer loop more than a
+    // 1000 times (make it bigger if many input entiites.) 
+  const size_t block_size = std::max( DEFAULT_MAX_BLOCKS_SIZE, remaining/MAX_OUTER_ITERATIONS );
+  while (remaining > 0) {
+    const size_t count = remaining > block_size ? block_size : remaining;
+    remaining -= count;
+    temp_vec.clear();
+    for (size_t j = 0; j < count; ++i, ++j) {
+      if (MBCN::Dimension(TYPE_FROM_HANDLE(*i)) == to_dimension) {
+        temp_vec.push_back(*i);
+      }
+      else if (to_dimension == 0 && TYPE_FROM_HANDLE(*i) != MBPOLYHEDRON) {
+        tmp_result = gMB->get_connectivity( *i, conn, conn_len, false, &storage );
+        if (MB_SUCCESS != tmp_result) {
+          result = tmp_result;
+          continue;
+        }
+        temp_vec.insert( temp_vec.end(), conn, conn + conn_len );
+      }
+      else {
+        tmp_result = gMB->a_entity_factory()->get_adjacencies( *i, to_dimension, 
+                                                   create_if_missing, temp_vec);
+      }
+    }
+
+    std::sort( temp_vec.begin(), temp_vec.end() );
+    ins = adj_entities.begin();
+    ti = temp_vec.begin();
+    while (ti != temp_vec.end()) {
+      EntityHandle first = *ti;
+      EntityHandle second = *ti;
+      for (++ti; ti != temp_vec.end() && (*ti - second <= 1); ++ti)
+        second = *ti;
+      ins = adj_entities.insert( ins, first, second );
+    }
+  }
+  return result;
+}
+
+template <typename ITER> static inline
+ErrorCode get_adjacencies_intersection( Core* mb,
+                             ITER begin, ITER end,
+                             const int to_dimension,
+                             const bool create_if_missing,
+                             std::vector<EntityHandle>& adj_entities )
+{
+  const size_t SORT_THRESHOLD = 200;
+  std::vector<EntityHandle> temp_vec;
+  std::vector<EntityHandle>::iterator adj_it, w_it;
+  ErrorCode result = MB_SUCCESS;
+  
+  if (begin == end) {
+    adj_entities.clear(); // intersection
+    return MB_SUCCESS;
+  }
+  
+    // First iteration is a special case if input list is empty.
+    // Rather than returning nothing (intersecting with empty
+    // input list), we begin with the adjacencies for the first entity.
+  if (adj_entities.empty()) {
+    EntityType type = TYPE_FROM_HANDLE(*begin);
+    if (to_dimension == MBCN::Dimension(type)) 
+      adj_entities.push_back(*begin); 
+    else if(to_dimension == 0 && type != MBPOLYHEDRON)
+      result = mb->get_connectivity(&(*begin), 1, adj_entities);
+    else
+      result = mb->a_entity_factory()->get_adjacencies(*begin, to_dimension, 
+                                                   create_if_missing, adj_entities);
+    if (MB_SUCCESS != result)
+      return result;
+    ++begin;
+  }
+
+  for (ITER from_it = begin; from_it != end; from_it++) 
+  {
+      // running results kept in adj_entities; clear temp_vec, which is working space
+    temp_vec.clear();
+
+      // get the next set of adjacencies
+    EntityType type = TYPE_FROM_HANDLE(*from_it);
+    if (to_dimension == MBCN::Dimension(type)) 
+      temp_vec.push_back(*from_it); 
+    else if(to_dimension == 0 && type != MBPOLYHEDRON)
+      result = mb->get_connectivity(&(*from_it), 1, temp_vec);
+    else
+      result = mb->a_entity_factory()->get_adjacencies(*from_it, to_dimension, 
+                                                   create_if_missing, temp_vec);
+    if (MB_SUCCESS != result)
+      return result;
+  
+      // otherwise intersect with the current set of results
+    w_it = adj_it = adj_entities.begin();
+    if (temp_vec.size()*adj_entities.size() < SORT_THRESHOLD) {
+      for (; adj_it != adj_entities.end(); ++adj_it)
+        if (std::find(temp_vec.begin(), temp_vec.end(), *adj_it) != temp_vec.end())
+          { *w_it = *adj_it; ++w_it; }
+    }
+    else {
+      std::sort( temp_vec.begin(), temp_vec.end() );
+      for (; adj_it != adj_entities.end(); ++adj_it)
+        if (std::binary_search(temp_vec.begin(), temp_vec.end(), *adj_it))
+          { *w_it = *adj_it; ++w_it; }
+    }
+    adj_entities.erase( w_it, adj_entities.end() );
+    
+      // we're intersecting, so if there are no more results, we're done
+    if (adj_entities.empty())
+      break;
+  }
+
+  return MB_SUCCESS;
+}
+
+template <typename ITER> static inline
+ErrorCode get_adjacencies_intersection( Core* mb,
+                             ITER begin, ITER end,
+                             const int to_dimension,
+                             const bool create_if_missing,
+                             Range& adj_entities )
+{
+  std::vector<EntityHandle> results;
+  ErrorCode rval = get_adjacencies_intersection( mb, begin, end, to_dimension, 
+                                                   create_if_missing, results );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (adj_entities.empty()) {
+    std::copy( results.begin(), results.end(), range_inserter(adj_entities) );
+    return MB_SUCCESS;
+  }
+  
+  Range::iterator it = adj_entities.begin();
+  while (it != adj_entities.end()) {
+    if (std::find( results.begin(), results.end(), *it) == results.end())
+      it = adj_entities.erase( it );
+    else
+      ++it;
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::get_adjacencies( const EntityHandle *from_entities,
+                                     const int num_entities,
+                                     const int to_dimension,
+                                     const bool create_if_missing,
+                                     std::vector<EntityHandle> &adj_entities,
+                                     const int operation_type )
+{
+  if (operation_type == Interface::INTERSECT)
+    return get_adjacencies_intersection( this, from_entities, from_entities+num_entities, 
+                                         to_dimension, create_if_missing, adj_entities );
+  else if (operation_type != Interface::UNION)
+    return MB_FAILURE;
+    
+    // do union
+  ErrorCode result;
+  std::vector<EntityHandle> tmp_storage;
+  const EntityHandle* conn;
+  int len;
+  for (int i = 0; i < num_entities; ++i) {
+    if(to_dimension == 0 && TYPE_FROM_HANDLE(from_entities[0]) != MBPOLYHEDRON) {
+      result = get_connectivity(from_entities[i], conn, len, false, &tmp_storage);
+      adj_entities.insert( adj_entities.end(), conn, conn+len );
+      if (MB_SUCCESS != result)
+        return result;
+    }
+    else {
+      result = aEntityFactory->get_adjacencies(from_entities[i], to_dimension, 
+                                               create_if_missing, adj_entities);
+      if (MB_SUCCESS != result)
+        return result;
+    }
+  }
+  std::sort( adj_entities.begin(), adj_entities.end() );
+  adj_entities.erase( std::unique( adj_entities.begin(), adj_entities.end() ), adj_entities.end() );
+ 
+  return MB_SUCCESS;
+}
+
+
+ErrorCode Core::get_adjacencies( const EntityHandle *from_entities,
+                                     const int num_entities,
+                                     const int to_dimension,
+                                     const bool create_if_missing,
+                                     Range &adj_entities,
+                                     const int operation_type )
+{
+  if (operation_type == Interface::INTERSECT)
+    return get_adjacencies_intersection( this, from_entities, from_entities + num_entities,
+                                         to_dimension, create_if_missing, adj_entities );
+  else if (operation_type == Interface::UNION)
+    return get_adjacencies_union( this, from_entities, from_entities + num_entities,
+                                  to_dimension, create_if_missing, adj_entities );
+  else
+    return MB_FAILURE;
+}
+
+ErrorCode Core::get_connectivity( const Range& from_entities,
+                                      Range& adj_entities,
+                                      bool corners_only ) const
+{
+  const size_t DEFAULT_MAX_BLOCKS_SIZE = 4000;
+  const size_t MAX_OUTER_ITERATIONS = 100;
+
+  std::vector<EntityHandle> temp_vec, storage;
+  std::vector<EntityHandle>::const_iterator ti;
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  Range::const_iterator i = from_entities.begin();
+  Range::iterator ins;
+  const EntityHandle* conn;
+  int conn_len;
+
+    // Just copy any vertices from the input range into the output
+  size_t remaining = from_entities.size();
+  for (; i != from_entities.end() && TYPE_FROM_HANDLE(*i) == MBVERTEX; ++i) 
+    --remaining;
+  adj_entities.merge( from_entities.begin(), i );
+  
+    // How many entities to work with at once? 2000 or so shouldn't require
+    // too much memory, but don't iterate in outer loop more than a
+    // 1000 times (make it bigger if many input entiites.) 
+  const size_t block_size = std::max( DEFAULT_MAX_BLOCKS_SIZE, remaining/MAX_OUTER_ITERATIONS );
+  while (remaining > 0) {
+    const size_t count = remaining > block_size ? block_size : remaining;
+    remaining -= count;
+    temp_vec.clear();
+    for (size_t j = 0; j < count; ++i, ++j) {
+      tmp_result = get_connectivity( *i, conn, conn_len, corners_only, &storage );
+      if (MB_SUCCESS != tmp_result) {
+        result = tmp_result;
+        continue;
+      }
+
+      const size_t oldsize = temp_vec.size();
+      temp_vec.resize( oldsize + conn_len );
+      memcpy( &temp_vec[oldsize], conn, sizeof(EntityHandle)*conn_len );
+    }
+
+    std::sort( temp_vec.begin(), temp_vec.end() );
+    ins = adj_entities.begin();
+    ti = temp_vec.begin();
+    while (ti != temp_vec.end()) {
+      EntityHandle first = *ti;
+      EntityHandle second = *ti;
+      for (++ti; ti != temp_vec.end() && (*ti - second <= 1); ++ti)
+        second = *ti;
+      ins = adj_entities.insert( ins, first, second );
+    }
+  }
+  return result;
+}
+
+ErrorCode Core::get_vertices( const Range& from_entities,
+                                  Range& vertices )
+{
+  Range range;
+  ErrorCode rval = get_connectivity( from_entities, range );
+  
+    // If input contained polyhedra, connectivity will contain faces.
+    // Get vertices from faces.
+  if (MB_SUCCESS == rval && !range.all_of_dimension(0)) {
+    Range::iterator it = range.upper_bound(MBVERTEX);
+    Range polygons;
+    polygons.merge( it, range.end() );
+    range.erase( it, range.end() );
+    rval = get_connectivity( polygons, range );
+  }
+  
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (vertices.empty())
+    vertices.swap( range );
+  else  
+    vertices.merge( range );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::get_adjacencies(const Range &from_entities,
+                                      const int to_dimension,
+                                      const bool create_if_missing,
+                                      Range &adj_entities,
+                                      const int operation_type)
+{
+  if (operation_type == Interface::INTERSECT)
+    return get_adjacencies_intersection( this, from_entities.begin(), from_entities.end(),
+                                         to_dimension, create_if_missing, adj_entities );
+  else if (operation_type != Interface::UNION)
+    return MB_FAILURE;
+  else if (to_dimension == 0)
+    return get_vertices( from_entities, adj_entities );
+  else
+    return get_adjacencies_union( this, from_entities.begin(), from_entities.end(),
+                                  to_dimension, create_if_missing, adj_entities );
+}
+
+
+ErrorCode Core::add_adjacencies(const EntityHandle entity_handle, 
+                                    const EntityHandle *adjacencies,
+                                    const int num_handles,
+                                    bool both_ways)
+{
+  ErrorCode result = MB_SUCCESS, temp_result;
+  
+  for (const EntityHandle *it = adjacencies; 
+       it != adjacencies+num_handles; it++) {
+    temp_result = aEntityFactory->add_adjacency(entity_handle, *it, both_ways);
+    if (MB_SUCCESS != temp_result) result = temp_result;
+  }
+
+  return result;
+}
+
+ErrorCode Core::add_adjacencies(const EntityHandle entity_handle, 
+                                    Range &adjacencies,
+                                    bool both_ways)
+{
+  ErrorCode result = MB_SUCCESS, temp_result;
+  
+  for (Range::iterator rit = adjacencies.begin(); rit != adjacencies.end(); rit++) {
+    temp_result = aEntityFactory->add_adjacency(entity_handle, *rit, both_ways);
+    if (MB_SUCCESS != temp_result) result = temp_result;
+  }
+
+  return result;
+}
+
+ErrorCode Core::remove_adjacencies(const EntityHandle entity_handle,
+                                       const EntityHandle *adjacencies,
+                                       const int num_handles)
+{
+  ErrorCode result = MB_SUCCESS, temp_result;
+  
+  for (const EntityHandle *it = adjacencies; 
+       it != adjacencies+num_handles; it++) {
+    temp_result = aEntityFactory->remove_adjacency(entity_handle, *it);
+    if (MB_SUCCESS != temp_result) result = temp_result;
+    temp_result = aEntityFactory->remove_adjacency(*it, entity_handle);
+    if (MB_SUCCESS != temp_result) result = temp_result;
+  }
+
+  return result;
+}
+
+ErrorCode Core::get_entities_by_dimension(const EntityHandle meshset,
+                                                const int dimension, 
+                                                Range &entities,
+                                                const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
+  }
+  else if (dimension > 3) {
+    sequence_manager()->get_entities( MBENTITYSET, entities );
+    result = MB_SUCCESS;
+  } 
+  else {
+    for (EntityType this_type = MBCN::TypeDimensionMap[dimension].first;
+         this_type <= MBCN::TypeDimensionMap[dimension].second;
+         this_type++) {
+      sequence_manager()->get_entities( this_type, entities );
+    }
+  }
+
+  return result;
+}
+
+ErrorCode Core::get_entities_by_dimension(const EntityHandle meshset,
+                                                const int dimension, 
+                                                std::vector<EntityHandle> &entities,
+                                                const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
+  }
+  else if (dimension > 3) {
+    sequence_manager()->get_entities( MBENTITYSET, entities );
+    result = MB_SUCCESS;
+  } 
+  else {
+    for (EntityType this_type = MBCN::TypeDimensionMap[dimension].first;
+         this_type <= MBCN::TypeDimensionMap[dimension].second;
+         this_type++) {
+      sequence_manager()->get_entities( this_type, entities );
+    }
+  }
+
+  return result;
+}
+
+ErrorCode Core::get_entities_by_type( const EntityHandle meshset,
+                                          const EntityType type, 
+                                          Range &entities,
+                                          const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
+  }  
+  else {
+    sequence_manager()->get_entities( type, entities );
+    result = MB_SUCCESS;
+  }
+
+  return result;
+}
+
+ErrorCode Core::get_entities_by_type( const EntityHandle meshset,
+                                          const EntityType type, 
+                                          std::vector<EntityHandle> &entities,
+                                          const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
+  }  
+  else {
+    sequence_manager()->get_entities( type, entities );
+    result = MB_SUCCESS;
+  }
+
+  return result;
+}
+
+ErrorCode Core::get_entities_by_type_and_tag(const EntityHandle meshset,
+                                                   const EntityType type,
+                                                   const Tag *tags,
+                                                   const void* const* values,
+                                                   const int num_tags,
+                                                   Range &entities,
+                                                   const int condition,
+                                                   const bool recursive) const
+{
+  if (recursive && type == MBENTITYSET)  // will never return anything
+    return MB_TYPE_OUT_OF_RANGE;
+
+  ErrorCode result;
+  Range tmp_range;
+
+  result = get_entities_by_type( meshset, type, tmp_range, recursive );
+  if (MB_SUCCESS != result)
+    return result;
+
+    // if range is empty, return right away; if intersecting condition, 
+    // empty the list too
+  if (tmp_range.empty()) {
+    if (Interface::INTERSECT == condition) entities.clear();
+    return MB_SUCCESS;
+  }
+  else if (!entities.empty() && Interface::INTERSECT == condition) {
+    entities = intersect( entities, tmp_range);
+    if (entities.empty()) return MB_SUCCESS;
+    tmp_range = entities;
+  }
+    
+  result = tagServer->get_entities_with_tag_values(tmp_range, type, 
+                                                   tags, values, num_tags, 
+                                                   entities, condition); 
+  
+  return result;
+}
+
+ErrorCode Core::get_entities_by_handle(const EntityHandle meshset,
+                                             Range &entities,
+                                             const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_entities( sequence_manager(), meshset, entities, recursive );
+  }  
+  else {
+    // iterate backards so range insertion is quicker
+    for (EntityType type = MBENTITYSET; type >= MBVERTEX; --type)
+      sequence_manager()->get_entities( type, entities );
+  }
+
+  return result;
+}
+
+
+ErrorCode Core::get_entities_by_handle(const EntityHandle meshset,
+                                   std::vector<EntityHandle> &entities,
+                                   const bool recursive) const
+{
+  ErrorCode result;
+  if (recursive || !meshset) {
+    Range tmp_range;
+    result = get_entities_by_handle( meshset, tmp_range, recursive);
+    size_t offset = entities.size();
+    entities.resize( offset + tmp_range.size() );
+    std::copy( tmp_range.begin(), tmp_range.end(), entities.begin() + offset );
+  }
+  else {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_entities( meshset, entities );
+  }  
+  return result;
+}
+
+  //! get # entities of a given dimension
+ErrorCode Core::get_number_entities_by_dimension(const EntityHandle meshset,
+                                                       const int dim, 
+                                                       int &number,
+                                                       const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+ 
+  if (!meshset) {
+    number = 0;
+    for (EntityType this_type = MBCN::TypeDimensionMap[dim].first;
+         this_type <= MBCN::TypeDimensionMap[dim].second;
+         this_type++) {
+      number += sequence_manager()->get_number_entities( this_type );
+    }
+  }
+  else {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->num_dimension( sequence_manager(), meshset, dim, number, recursive );
+  }  
+  
+  return result;
+}
+
+//! returns the number of entities with a given type and tag
+ErrorCode Core::get_number_entities_by_type(const EntityHandle meshset,
+                                                  const EntityType type, 
+                                                  int& num_ent,
+                                                  const bool recursive) const
+{
+  ErrorCode result = MB_SUCCESS;
+
+  if (recursive && type == MBENTITYSET)  // will never return anything
+    return MB_TYPE_OUT_OF_RANGE;
+  
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->num_type( sequence_manager(), meshset, type, num_ent, recursive );
+  }
+  else {
+    num_ent = sequence_manager()->get_number_entities( type );
+  }
+  
+  return result;
+}
+
+ErrorCode Core::get_number_entities_by_type_and_tag(const EntityHandle meshset,
+                                                          const EntityType type,
+                                                          const Tag *tag_handles,
+                                                          const void* const* values,
+                                                          const int num_tags,
+                                                          int &num_entities,
+                                                          const bool recursive) const
+{
+  Range dum_ents;
+  ErrorCode result = get_entities_by_type_and_tag(meshset, type, tag_handles, values, num_tags, 
+                                                     dum_ents, recursive);
+  num_entities = dum_ents.size();
+  return result;
+}
+
+ErrorCode Core::get_number_entities_by_handle(const EntityHandle meshset,
+                                          int& num_ent,
+                                          const bool recursive) const
+{
+  ErrorCode result;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    return mseq->num_entities( sequence_manager(), meshset, num_ent, recursive );
+  }
+
+  num_ent = 0;
+  for (EntityType this_type = MBVERTEX;
+       this_type < MBMAXTYPE;
+       this_type++) {
+    int dummy = 0;
+    result = get_number_entities_by_type(0, this_type, dummy);
+    if (result != MB_SUCCESS) {
+      num_ent = 0;
+      return result;
+    }
+    num_ent += dummy;
+  }
+
+  return MB_SUCCESS;
+}
+
+//! return the tag data for a given EntityHandle and Tag
+ErrorCode  Core::tag_get_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities,
+                                    void *tag_data) const
+{
+  if (NULL == entity_handles && 0 == num_entities) {
+    return tagServer->get_mesh_data(tag_handle, tag_data);
+  }
+
+  else return tagServer->get_data(tag_handle, entity_handles, num_entities, tag_data);
+}
+
+//! return the tag data for a given EntityHandle and Tag
+ErrorCode  Core::tag_get_data(const Tag tag_handle, 
+                                    const Range& entity_handles,
+                                    void *tag_data) const
+{
+  return tagServer->get_data(tag_handle, entity_handles, tag_data);
+}
+
+//! set the data  for given EntityHandles and Tag
+ErrorCode  Core::tag_set_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities,
+                                    const void *tag_data)
+{
+  if (NULL == entity_handles && 0 == num_entities)
+    return tagServer->set_mesh_data(tag_handle, tag_data);
+
+  return tagServer->set_data(tag_handle, entity_handles, num_entities, tag_data);
+}
+
+//! set the data  for given EntityHandles and Tag
+ErrorCode  Core::tag_set_data(const Tag tag_handle, 
+                                    const Range& entity_handles, 
+                                    const void *tag_data)
+{
+  return tagServer->set_data(tag_handle, entity_handles, tag_data);
+}
+
+
+//! return the tag data for a given EntityHandle and Tag
+ErrorCode  Core::tag_get_data( const Tag tag_handle, 
+                                   const EntityHandle* entity_handles, 
+                                   const int num_entities,
+                                   const void** tag_data,
+                                   int* tag_sizes ) const
+{
+  if (NULL == entity_handles && 0 == num_entities) {
+    int size;
+    return tagServer->get_mesh_data(tag_handle, tag_data[0], tag_sizes ? tag_sizes[0] : size );
+  }
+
+  else return tagServer->get_data(tag_handle, entity_handles, num_entities, tag_data, tag_sizes);
+}
+
+//! return the tag data for a given EntityHandle and Tag
+ErrorCode  Core::tag_get_data( const Tag tag_handle, 
+                                   const Range& entity_handles,
+                                   const void** tag_data,
+                                   int* tag_sizes ) const
+{
+  return tagServer->get_data(tag_handle, entity_handles, tag_data, tag_sizes );
+}
+
+//! set the data  for given EntityHandles and Tag
+ErrorCode  Core::tag_set_data( const Tag tag_handle, 
+                                   const EntityHandle* entity_handles, 
+                                   const int num_entities,
+                                   void const* const* tag_data,
+                                   const int* tag_sizes )
+{
+  if (NULL == entity_handles && 0 == num_entities)
+    return tagServer->set_mesh_data(tag_handle, tag_data[0], tag_sizes ? tag_sizes[0] : 0);
+
+  return tagServer->set_data(tag_handle, entity_handles, num_entities, tag_data, tag_sizes);
+}
+
+//! set the data  for given EntityHandles and Tag
+ErrorCode  Core::tag_set_data( const Tag tag_handle, 
+                                   const Range& entity_handles, 
+                                   void const* const* tag_data,
+                                   const int* tag_sizes )
+{
+  return tagServer->set_data(tag_handle, entity_handles, tag_data, tag_sizes);
+}
+
+//! adds a sparse tag for this specific EntityHandle/tag_name combination
+ErrorCode Core::tag_create(const char *tag_name,
+                                 const int tag_size, 
+                                 const TagType tag_type,
+                                 Tag &tag_handle, 
+                                 const void *default_value)
+{
+  DataType data_type = (tag_type == MB_TAG_BIT) ? MB_TYPE_BIT : MB_TYPE_OPAQUE;
+  return tag_create( tag_name, tag_size, tag_type, data_type, tag_handle, default_value, false );
+}
+
+ErrorCode Core::tag_create( const char* name,
+                                const int size,
+                                const TagType storage,
+                                const DataType data,
+                                Tag& handle,
+                                const void* def_val,
+                                bool use_existing )
+{
+    // This API cannot be used for creating variable-length tags with a 
+    // default value, because there is no argument for the length of
+    // the default value.
+  if (def_val && MB_VARIABLE_LENGTH == size)
+    return MB_VARIABLE_DATA_LENGTH;
+  
+  ErrorCode rval = tagServer->add_tag( name, size, storage, data, handle, def_val );
+
+    // If it is okay to use an existing tag of the same name, check that it 
+    // matches the input values.  NOTE: we don't check the storage type for 
+    // the tag because the choice of dense vs. sparse is a matter of optimi-
+    // zation, not correctness.  Bit tags require a redundant MB_TYPE_BIT 
+    // for the data type, so we catch those when we check the data type.
+  if (rval == MB_ALREADY_ALLOCATED && use_existing) {
+    handle = tagServer->get_handle( name );
+    const TagInfo* info = tagServer->get_tag_info( handle );
+    if (info->get_size() == size &&  info->get_data_type() == data)  {
+        // If we were not passed a default value, the caller is presumably
+        // OK with an arbitrary default value, so its OK if there is one
+        // set for the tag.
+      if (!def_val)
+        rval = MB_SUCCESS;
+        // If caller specified a default value, there MUST be an existing one
+        // that matches.  We could just set a default value for the tag, but
+        // given the dense tag representation, it isn't feasible to change
+        // the default value once the tag has been created.  For now, don't 
+        // bother because there isn't any mechanism to set it for sparse tags 
+        // anyway.
+      else if (info->default_value() && !memcmp(info->default_value(), def_val, size))
+        rval = MB_SUCCESS;
+    }
+  }
+
+  return rval;
+}
+
+ErrorCode Core::tag_create_variable_length( const char* name,
+                                                TagType storage,
+                                                DataType data,
+                                                Tag& handle,
+                                                const void* def_val,
+                                                int def_val_size )
+{
+  return tagServer->add_tag( name, MB_VARIABLE_LENGTH, storage, data, handle, def_val, def_val_size );
+}
+
+//! removes the tag from the entity
+ErrorCode  Core::tag_delete_data(const Tag tag_handle, 
+                                       const EntityHandle *entity_handles,
+                                       const int num_handles)
+{
+  ErrorCode status = MB_SUCCESS, temp_status;
+  for (int i = 0; i < num_handles; i++) {
+    if (0 == entity_handles[i])
+      temp_status = tagServer->remove_mesh_data(tag_handle);
+    else
+      temp_status = tagServer->remove_data(tag_handle, entity_handles[i]);
+    if (temp_status != MB_SUCCESS) status = temp_status;
+  }
+
+  return status;
+}
+
+//! removes the tag from the entity
+ErrorCode  Core::tag_delete_data(const Tag tag_handle, 
+                                     const Range &entity_handles)
+{
+  ErrorCode status = MB_SUCCESS, temp_status;
+  for (Range::const_iterator it = entity_handles.begin(); it != entity_handles.end(); it++) {
+    temp_status = tagServer->remove_data(tag_handle, *it);
+    if (temp_status != MB_SUCCESS) status = temp_status;
+  }
+
+  return status;
+}
+
+//! removes the tag from MB
+ErrorCode  Core::tag_delete(Tag tag_handle)
+{
+  return tag_server()->remove_tag(tag_handle);
+}
+
+//! gets the tag name string for the tag_handle
+ErrorCode  Core::tag_get_name(const Tag tag_handle, 
+                                    std::string& tag_name) const
+{
+  const TagInfo* tag_info = tagServer->get_tag_info( tag_handle );
+  if(!tag_info)
+    return MB_TAG_NOT_FOUND;
+  
+  tag_name = tag_info->get_name();
+  return MB_SUCCESS;
+
+}
+
+//! gets tag handle from its name.
+//! the type must be specified because the same name is valid for multiple types
+ErrorCode  Core::tag_get_handle(const char *tag_name, 
+                                      Tag &tag_handle) const
+{
+  ErrorCode status = MB_TAG_NOT_FOUND;
+
+  tag_handle = tagServer->get_handle( tag_name );
+  
+  if (tag_handle != 0)
+  {
+    status = MB_SUCCESS;
+  }
+
+  return status;
+}
+
+  //! get size of tag in bytes
+ErrorCode Core::tag_get_size(const Tag tag_handle, int &tag_size) const
+{
+  const TagInfo* tag_info = tagServer->get_tag_info( tag_handle );
+  if(!tag_info)
+    return MB_TAG_NOT_FOUND;
+  
+  tag_size = tag_info->get_size();
+  return MB_VARIABLE_LENGTH == tag_size ? MB_VARIABLE_DATA_LENGTH : MB_SUCCESS;
+}
+
+ErrorCode Core::tag_get_data_type( const Tag handle, 
+                                       DataType& type ) const
+{
+  const TagInfo* info = tagServer->get_tag_info( handle );
+  if (!info)
+    return MB_TAG_NOT_FOUND;
+  
+  type = info->get_data_type();
+  return MB_SUCCESS;
+}
+
+  //! get default value of the tag
+ErrorCode Core::tag_get_default_value(const Tag tag_handle, void *def_value) const
+{
+  int size;
+  return tagServer->get_default_data( tag_handle, def_value, size );
+}
+
+ErrorCode Core::tag_get_default_value( Tag tag, const void*& ptr, int& size ) const
+{
+  return tagServer->get_default_data_ref( tag, ptr, size );
+}
+
+  //! get type of tag (sparse, dense, etc.; 0 = dense, 1 = sparse, 2 = bit, 3 = static)
+ErrorCode Core::tag_get_type(const Tag tag_handle, TagType &tag_type) const
+{
+  tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
+  return tag_type < MB_TAG_LAST+1 ? MB_SUCCESS : MB_TAG_NOT_FOUND;
+}
+
+  //! get handles for all tags defined
+ErrorCode Core::tag_get_tags(std::vector<Tag> &tag_handles) const
+{
+  return tagServer->get_tags(tag_handles);
+}
+
+  //! Get handles for all tags defined on this entity
+ErrorCode Core::tag_get_tags_on_entity(const EntityHandle entity,
+                                            std::vector<Tag> &tag_handles) const 
+{
+  if (0 == entity)
+    return tagServer->get_mesh_tags(tag_handles);
+  else return tagServer->get_tags(entity, tag_handles);
+}
+
+Tag Core::material_tag()
+{
+  if (0 == materialTag)
+    tagServer->add_tag(MATERIAL_SET_TAG_NAME, sizeof(int), 
+                       MB_TAG_SPARSE, MB_TYPE_INTEGER, materialTag);
+  return materialTag;
+}
+
+Tag Core::neumannBC_tag()
+{
+  if (0 == neumannBCTag)
+    tagServer->add_tag(NEUMANN_SET_TAG_NAME, sizeof(int), 
+                       MB_TAG_SPARSE, MB_TYPE_INTEGER, neumannBCTag);
+  return neumannBCTag;
+}
+
+Tag Core::dirichletBC_tag()
+{
+  if (0 == dirichletBCTag)
+    tagServer->add_tag(DIRICHLET_SET_TAG_NAME, sizeof(int), 
+                       MB_TAG_SPARSE, MB_TYPE_INTEGER, dirichletBCTag);
+  return dirichletBCTag;
+}
+
+Tag Core::globalId_tag()
+{
+  if (0 == globalIdTag)
+    tagServer->add_tag(GLOBAL_ID_TAG_NAME, sizeof(int), 
+                       MB_TAG_DENSE, MB_TYPE_INTEGER, globalIdTag);
+  return globalIdTag;
+}
+
+Tag Core::geom_dimension_tag()
+{
+  if (0 == geomDimensionTag)
+    tagServer->add_tag(GEOM_DIMENSION_TAG_NAME, sizeof(int), 
+                       MB_TAG_SPARSE, MB_TYPE_INTEGER, geomDimensionTag);
+  return geomDimensionTag;
+}
+
+//! creates an element based on the type and connectivity.  returns a handle and error code
+ErrorCode Core::create_element(const EntityType type, 
+                                   const EntityHandle *connectivity,
+                                   const int num_nodes, 
+                                   EntityHandle &handle)
+{
+    // make sure we have enough vertices for this entity type
+  if(num_nodes < MBCN::VerticesPerEntity(type))
+    return MB_FAILURE;
+  
+  ErrorCode status = sequence_manager()->create_element(type, connectivity, num_nodes, handle);
+  if (MB_SUCCESS == status)
+    status = aEntityFactory->notify_create_entity( handle, connectivity, num_nodes); 
+
+  return status;
+}  
+
+//! creates a vertex based on coordinates, returns a handle and error code
+ErrorCode Core::create_vertex(const double coords[3], EntityHandle &handle )
+{
+    // get an available vertex handle
+  return sequence_manager()->create_vertex( coords, handle );
+}
+
+ErrorCode Core::create_vertices(const double *coordinates, 
+                                    const int nverts,
+                                    Range &entity_handles ) 
+{
+    // Create vertices
+  void* tmp_ptr;
+  ErrorCode result = this->query_interface("ReadUtilIface", &tmp_ptr );
+  if (MB_SUCCESS != result) return result;
+  ReadUtilIface *read_iface = reinterpret_cast<ReadUtilIface*>(tmp_ptr);
+  
+  std::vector<double*> arrays;
+  EntityHandle start_handle_out = 0;
+  result = read_iface->get_node_arrays( 3, nverts, MB_START_ID, 
+                                        start_handle_out, arrays);
+  if (MB_SUCCESS != result) return result;
+  for (int i = 0; i < nverts; i++) {
+    arrays[0][i] = coordinates[3*i];
+    arrays[1][i] = coordinates[3*i+1];
+    arrays[2][i] = coordinates[3*i+2];
+  }
+
+  entity_handles.clear();
+  entity_handles.insert(start_handle_out, start_handle_out+nverts-1);
+  
+  return MB_SUCCESS;
+}
+
+
+//! merges two  entities
+ErrorCode Core::merge_entities( EntityHandle entity_to_keep, 
+                                      EntityHandle entity_to_remove,
+                                      bool auto_merge,
+                                      bool delete_removed_entity)
+{
+  if (auto_merge) return MB_FAILURE;
+  
+    // The two entities to merge must be of the same type
+  EntityType type_to_keep = TYPE_FROM_HANDLE(entity_to_keep);
+
+  if (type_to_keep != TYPE_FROM_HANDLE(entity_to_remove))
+    return MB_TYPE_OUT_OF_RANGE;
+
+    // Make sure both entities exist before trying to merge.
+  EntitySequence* seq = 0;
+  ErrorCode result, status;
+  status = sequence_manager()->find(entity_to_keep, seq);
+  if(seq == 0 || status != MB_SUCCESS)
+    return MB_ENTITY_NOT_FOUND;
+  status = sequence_manager()->find(entity_to_remove, seq);
+  if(seq == 0 || status != MB_SUCCESS)
+    return MB_ENTITY_NOT_FOUND;
+  
+    // If auto_merge is not set, all sub-entities should
+    // be merged if the entities are to be merged.
+  int ent_dim = MBCN::Dimension(type_to_keep);
+  if(ent_dim > 0)
+  {
+    std::vector<EntityHandle> conn, conn2;
+
+    result = get_connectivity(&entity_to_keep, 1, conn);
+    if(result != MB_SUCCESS)
+      return result;
+    result = get_connectivity(&entity_to_remove, 1, conn2);
+    if(result != MB_SUCCESS)
+      return result;
+
+      // Check to see if we can merge before pulling adjacencies.
+    int dum1, dum2;
+    if(!auto_merge && 
+       (conn.size() != conn2.size() ||
+        !MBCN::ConnectivityMatch(&conn[0], &conn2[0], conn.size(), dum1, dum2)))
+      return MB_FAILURE;
+  }
+
+  result = aEntityFactory->merge_adjust_adjacencies(entity_to_keep, entity_to_remove);
+  
+  if (MB_SUCCESS == result && delete_removed_entity) 
+    result = delete_entities(&entity_to_remove, 1);
+
+  return result;
+}
+
+
+//! deletes an entity range
+ErrorCode Core::delete_entities(const Range &range)
+{
+  ErrorCode result = MB_SUCCESS, temp_result;
+  
+  for (Range::const_reverse_iterator rit = range.rbegin(); rit != range.rend(); rit++) {
+    
+      // tell AEntityFactory that this element is going away
+    temp_result = aEntityFactory->notify_delete_entity(*rit);
+    if (MB_SUCCESS != temp_result) {
+      result = temp_result;
+      continue;
+    }
+
+      // reset and/or clean out data associated with this entity handle
+    temp_result = tagServer->reset_data(*rit);
+    if (MB_SUCCESS != temp_result) {
+      result = temp_result;
+      continue;
+    }
+
+    if (TYPE_FROM_HANDLE(*rit) == MBENTITYSET) {
+      if (MeshSet* ptr = get_mesh_set( sequence_manager(), *rit )) {
+        int j, count;
+        const EntityHandle* rel;
+        ptr->clear( *rit, a_entity_factory() );
+        rel = ptr->get_parents( count );
+        for (j = 0; j < count; ++j)
+          remove_child_meshset( rel[j], *rit );
+        rel = ptr->get_children( count );
+        for (j = 0; j < count; ++j)
+          remove_parent_meshset( rel[j], *rit );
+      }
+    }
+
+      // now delete the entity
+    temp_result = sequence_manager()->delete_entity(*rit);
+    if (MB_SUCCESS != temp_result) {
+      result = temp_result;
+      continue;
+    }
+  }
+
+  return result;
+}
+
+
+//! deletes an entity vector
+ErrorCode Core::delete_entities(const EntityHandle *entities,
+                                    const int num_entities)
+{
+  Range range;
+  std::copy(entities, entities+num_entities, range_inserter(range));
+  return delete_entities(range);
+}
+
+ErrorCode Core::list_entities(const EntityHandle *entities,
+                                    const int num_entities) const
+{
+  Range temp_range;
+  ErrorCode result = MB_SUCCESS;
+  if (NULL == entities && num_entities <= 0) {
+      // just list the numbers of each entity type
+    int num_ents;
+    std::cout << std::endl;
+    std::cout << "Number of entities per type: " << std::endl;
+    for (EntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
+      result = get_number_entities_by_type(0, this_type, num_ents);
+      std::cout << MBCN::EntityTypeName(this_type) << ": " << num_ents << std::endl;
+    }
+    std::cout << std::endl;
+
+      // if negative num_entities, list the set hierarchy too
+    if (0 > num_entities) {
+      Range sets;
+      result = this->get_entities_by_type(0, MBENTITYSET, sets);
+      if (MB_SUCCESS != result) return result;
+      for (Range::iterator rit = sets.begin(); rit != sets.end(); rit++) {
+        this->print(*rit, "", false);
+        result = this->get_number_entities_by_handle(*rit, num_ents);
+        std::cout << "(" << num_ents << " total entities)" << std::endl;
+      }
+    }
+    
+    return MB_SUCCESS;
+  }
+      
+  else if (NULL == entities) {
+
+      // list all entities of all types
+    std::cout << std::endl;
+    for (EntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
+      result = get_entities_by_type(0, this_type, temp_range);
+    }
+
+    return list_entities(temp_range);
+  }
+
+  else {
+    ErrorCode tmp_result;
+    for (int i = 0; i < num_entities; i++) {
+      EntityType this_type = TYPE_FROM_HANDLE(entities[i]);
+      std::cout << MBCN::EntityTypeName(this_type) << " " 
+                << ID_FROM_HANDLE(entities[i]) << ":" << endl;
+
+      tmp_result = (const_cast<Core*>(this))->list_entity(entities[i]);
+      if (MB_SUCCESS != tmp_result) result = tmp_result;
+    }
+  }
+
+  return result;
+}
+
+ErrorCode Core::list_entities(const Range &temp_range) const
+{
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  
+  for (Range::const_iterator rit = temp_range.begin(); rit != temp_range.end(); rit++) {
+    EntityType this_type = TYPE_FROM_HANDLE(*rit);
+    std::cout << MBCN::EntityTypeName(this_type) << " " << ID_FROM_HANDLE(*rit) << ":" << endl;
+
+    tmp_result = (const_cast<Core*>(this))->list_entity(*rit);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+    
+  return result;
+}
+  
+ErrorCode Core::list_entity(const EntityHandle entity) const
+{
+  ErrorCode result;
+  HandleVec adj_vec;
+
+  if (!is_valid(entity)) {
+    std::cout << "(invalid)" << std::endl;
+    return MB_SUCCESS;
+  }
+
+  if (0 != globalIdTag) {
+    int dum;
+    result = tag_get_data(globalIdTag, &entity, 1, &dum);
+    if (MB_SUCCESS == result)
+      std::cout << "Global id = " << dum << std::endl;
+  }
+  
+    // list entity
+  EntityType this_type = TYPE_FROM_HANDLE(entity);
+  if (this_type == MBVERTEX) {
+    double coords[3];
+    result = get_coords(&(entity), 1, coords);
+    if (MB_SUCCESS != result) return result;
+    std::cout << "Coordinates: (" << coords[0] << ", " << coords[1] << ", " << coords[2] 
+              << ")" << std::endl;
+  }
+  else if (this_type == MBENTITYSET)
+    this->print(entity, "");
+    
+  std::cout << "  Adjacencies:" << std::endl;
+  bool some = false;
+  int multiple = 0;
+  for (int dim = 0; dim <= 3; dim++) {
+    if (dim == MBCN::Dimension(this_type)) continue;
+    adj_vec.clear();
+      // use const_cast here 'cuz we're in a const function and we're passing 'false' for
+      // create_if_missing, so we know we won't change anything
+    result = (const_cast<Core*>(this))->get_adjacencies(&(entity), 1, dim, false, adj_vec);
+    if (MB_FAILURE == result) continue;
+    for (HandleVec::iterator adj_it = adj_vec.begin(); adj_it != adj_vec.end(); adj_it++) {
+      if (adj_it != adj_vec.begin()) std::cout << ", ";
+      else std::cout << "   ";
+      std::cout << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*adj_it)) << " " << ID_FROM_HANDLE(*adj_it);
+    }
+    if (!adj_vec.empty()) {
+      std::cout << std::endl;
+      some = true;
+    }
+    if (MB_MULTIPLE_ENTITIES_FOUND == result)
+      multiple += dim;
+  }
+  if (!some) std::cout << "(none)" << std::endl;
+  const EntityHandle *explicit_adjs;
+  int num_exp;
+  aEntityFactory->get_adjacencies(entity, explicit_adjs, num_exp);
+  if (NULL != explicit_adjs && 0 != num_exp) {
+    std::cout << "  Explicit adjacencies: ";
+    for (int i = 0; i < num_exp; i++) {
+      if (i != 0) std::cout << ", ";
+      std::cout << MBCN::EntityTypeName(TYPE_FROM_HANDLE(explicit_adjs[i])) << " " 
+                << ID_FROM_HANDLE(explicit_adjs[i]);
+    }
+    std::cout << std::endl;
+  }
+  if (multiple != 0)
+    std::cout << "   (MULTIPLE = " << multiple << ")" << std::endl;
+
+  std::cout << std::endl;
+
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::convert_entities( const EntityHandle meshset, 
+                                        const bool mid_side, const bool mid_face, const bool mid_volume,
+                                        Interface::HONodeAddedRemoved* function_object )
+{
+  HigherOrderFactory fact(this, function_object);
+  return fact.convert(meshset, mid_side, mid_face, mid_volume);
+}
+
+  //! function to get the side number given two elements; returns
+  //! MB_FAILURE if child not related to parent; does *not* create adjacencies
+  //! between parent and child
+ErrorCode Core::side_number(const EntityHandle parent,
+                                  const EntityHandle child,
+                                  int &side_number,
+                                  int &sense,
+                                  int &offset) const
+{
+    // get the connectivity of parent and child
+  const EntityHandle *parent_conn, *child_conn;
+  int num_parent_vertices, num_child_vertices;
+  ErrorCode result = get_connectivity(parent, parent_conn, num_parent_vertices, true);
+  if (MB_NOT_IMPLEMENTED == result) {
+    static std::vector<EntityHandle> tmp_connect(MBCN::MAX_NODES_PER_ELEMENT);
+    result = get_connectivity(parent, parent_conn, num_parent_vertices, true, &tmp_connect);
+  }
+  if (MB_SUCCESS != result) return result;
+
+  if (TYPE_FROM_HANDLE(child) == MBVERTEX) {
+    int child_index = std::find(parent_conn, parent_conn+num_parent_vertices,
+                                child) - parent_conn;
+    if (child_index == num_parent_vertices) {
+      side_number = -1;
+      sense = 0;
+      return MB_SUCCESS;
+    }
+    else {
+      side_number = child_index;
+      sense = 1; 
+      return MB_SUCCESS;
+    }
+  }
+    
+  result = get_connectivity(child, child_conn, num_child_vertices, true);
+  if (MB_SUCCESS != result) return result;
+
+    // call handle vector-based function
+  if (TYPE_FROM_HANDLE(parent) != MBPOLYGON &&
+      TYPE_FROM_HANDLE(parent) != MBPOLYHEDRON) {
+
+      // find indices into parent_conn for each entry in child_conn
+    int child_conn_indices[10];
+    assert((unsigned)num_child_vertices <= sizeof(child_conn_indices)/sizeof(child_conn_indices[0]));
+    for (int i = 0; i < num_child_vertices; ++i) {
+      child_conn_indices[i] = std::find( parent_conn,
+        parent_conn + num_parent_vertices, child_conn[i] ) - parent_conn;
+      if (child_conn_indices[i] >= num_parent_vertices) {
+        side_number = -1;
+        return MB_SUCCESS;
+      }
+    }
+    
+    int temp_result = MBCN::SideNumber(TYPE_FROM_HANDLE(parent),
+                                       child_conn_indices, num_child_vertices, 
+                                       MBCN::Dimension(TYPE_FROM_HANDLE(child)), 
+                                       side_number, sense, offset);
+    return (0 == temp_result ? MB_SUCCESS : MB_FAILURE);
+  }
+  else if (TYPE_FROM_HANDLE(parent) == MBPOLYGON) {
+      // find location of 1st vertex
+    const EntityHandle *first_v = std::find(parent_conn, parent_conn+num_parent_vertices,
+                                              child_conn[0]);
+    if (first_v == parent_conn+num_parent_vertices) return MB_ENTITY_NOT_FOUND;
+    side_number = first_v - parent_conn;
+    offset = side_number;
+    if (TYPE_FROM_HANDLE(child) == MBVERTEX) {
+      sense = 0;
+      return MB_SUCCESS;
+    }
+    else if (TYPE_FROM_HANDLE(child) == MBPOLYGON) {
+      bool match = MBCN::ConnectivityMatch(parent_conn, child_conn,
+                                           num_parent_vertices,
+                                           sense, offset);
+      side_number = 0;
+      if (match) return MB_SUCCESS;
+      else return MB_ENTITY_NOT_FOUND;
+    }
+    else if (TYPE_FROM_HANDLE(child) == MBEDGE) {
+      if (parent_conn[(side_number+1)%num_parent_vertices] == child_conn[1])
+        sense = 1;
+      else if (parent_conn[(side_number+num_parent_vertices-1)%num_parent_vertices] ==
+               child_conn[1])
+        sense = -1;
+      return MB_SUCCESS;
+    }
+  }
+  
+  return MB_FAILURE;
+}
+
+  //! given an entity and the connectivity and type of one of its subfacets, find the
+  //! high order node on that subfacet, if any
+ErrorCode Core::high_order_node(const EntityHandle parent_handle,
+                                      const EntityHandle *subfacet_conn,
+                                      const EntityType subfacet_type,
+                                      EntityHandle &high_order_node) const
+{
+  high_order_node = 0;
+
+  EntityType parent_type = TYPE_FROM_HANDLE(parent_handle);
+
+    // get the parent's connectivity
+  const EntityHandle *parent_conn;
+  int num_parent_vertices;
+  ErrorCode result = get_connectivity(parent_handle, parent_conn, 
+                                         num_parent_vertices, false);
+  if (result != MB_SUCCESS) return result;
+
+    // find whether this entity has ho nodes
+  int mid_nodes[4];
+  MBCN::HasMidNodes(parent_type, num_parent_vertices, mid_nodes);
+
+    // check whether this entity has mid nodes on this dimension subfacet; 
+    // use dimension-1 because vertices don't have mid nodes
+  if (!mid_nodes[MBCN::Dimension(subfacet_type)]) return MB_SUCCESS;
+
+    // ok, we have mid nodes; now must compute expected index in connectivity array; 
+    // ho nodes stored for edges, faces then entity
+
+    // offset starts with # corner vertices
+  int offset = MBCN::VerticesPerEntity(parent_type);
+  int i;
+
+  for (i = 0; i < MBCN::Dimension(subfacet_type)-1; i++)
+      // for each dimension lower than that of the subfacet we're looking for, 
+      // if this entity has midnodes in that dimension, increment offset by # 
+      // of subfacets of that dimension; use dimension-1 in loop because 
+      // canon numbering table only has 2 positions, for edges and faces;
+    if (mid_nodes[i+1]) offset += MBCN::mConnectivityMap[parent_type][i].num_sub_elements;
+
+    // now add the index of this subfacet; only need to if it's not the highest dimension
+  if (subfacet_type != parent_type) {
+
+      // find indices into parent_conn for each entry in child_conn
+    unsigned subfacet_size = MBCN::VerticesPerEntity(subfacet_type);
+    int subfacet_indices[10];
+    assert(subfacet_size <= sizeof(subfacet_indices)/sizeof(subfacet_indices[0]));
+    for (unsigned i = 0; i < subfacet_size; ++i) {
+      subfacet_indices[i] = std::find( parent_conn,
+        parent_conn + num_parent_vertices, subfacet_conn[i] ) - parent_conn;
+      if (subfacet_indices[i] >= num_parent_vertices) {
+        return MB_FAILURE;
+      }
+    }
+
+    int dum, side_no, temp_offset;
+    int temp_result = 
+      MBCN::SideNumber(  parent_type, subfacet_indices, 
+                         subfacet_size, subfacet_type,
+                         side_no, dum, temp_offset);
+    if(temp_result != 0) return MB_FAILURE;
+
+    offset += side_no;
+  }
+
+    // offset shouldn't be off the end of the connectivity vector
+  if (offset >= num_parent_vertices) return MB_INDEX_OUT_OF_RANGE;
+
+  high_order_node = parent_conn[offset];
+
+  return MB_SUCCESS;
+}
+
+  //! given an entity and a target dimension & side number, get that entity
+ErrorCode Core::side_element(const EntityHandle source_entity,
+                                   const int dim, 
+                                   const int side_number,
+                                   EntityHandle &target_entity) const
+{
+    // get a handle on the connectivity
+  const EntityHandle *verts;
+  int num_verts;
+  ErrorCode result = get_connectivity(source_entity, verts, num_verts);
+  if (MB_SUCCESS != result) return result;
+
+    // special case for vertices
+  if (dim == 0) {
+    if (side_number < num_verts) {
+      target_entity = verts[side_number];
+      return MB_SUCCESS;
+    }
+    
+    else return MB_INDEX_OUT_OF_RANGE;
+  }
+  
+    // get the vertices comprising the target entity
+  Range side_verts, target_ents;
+  const EntityType source_type = TYPE_FROM_HANDLE(source_entity);
+    // first get the indices
+  std::vector<int> vertex_indices;
+
+  int temp_result = 
+    MBCN::AdjacentSubEntities(source_type, &side_number, 1, dim, 0, vertex_indices);
+  if (0 != temp_result) return MB_FAILURE;
+    // now get the actual vertices
+  for (unsigned int i = 0; i < vertex_indices.size(); i++)
+    side_verts.insert(verts[vertex_indices[i]]);
+  
+    // now look for an entity of the correct type
+    // use const_cast here 'cuz we're in a const function and we're passing 'false' for
+    // create_if_missing, so we know we won't change anything
+  result = (const_cast<Core*>(this))->get_adjacencies(side_verts, dim, false, target_ents);
+  if (MB_SUCCESS != result && MB_MULTIPLE_ENTITIES_FOUND != result) return result;
+  
+  if (!target_ents.empty() &&
+      TYPE_FROM_HANDLE(*(target_ents.begin())) != MBVERTEX &&
+      TYPE_FROM_HANDLE(*(target_ents.begin())) != 
+      MBCN::mConnectivityMap[source_type][dim-1].target_type[side_number])
+    return MB_ENTITY_NOT_FOUND;
+
+  if (!target_ents.empty()) target_entity = *(target_ents.begin());
+  
+  return result;
+}
+
+//-------------------------Set Functions---------------------//
+
+ErrorCode Core::create_meshset(const unsigned int options, 
+                                   EntityHandle &ms_handle,
+                                   int )
+{
+  return sequence_manager()->create_mesh_set( options, ms_handle );
+}
+
+ErrorCode Core::get_meshset_options( const EntityHandle ms_handle, 
+                                          unsigned int& options) const
+{
+  const MeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
+  if (!set)
+    return MB_ENTITY_NOT_FOUND;
+  
+  options = set->flags();
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::set_meshset_options( const EntityHandle ms_handle, 
+                                         const unsigned int options)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
+  if (!set)
+    return MB_ENTITY_NOT_FOUND;
+  
+  return set->set_flags(options, ms_handle, a_entity_factory());
+}
+
+
+ErrorCode Core::clear_meshset( const EntityHandle *ms_handles,
+                                    const int num_meshsets)
+{
+  ErrorCode result = MB_SUCCESS;
+  for (int i = 0; i < num_meshsets; ++i) {
+    MeshSet* set = get_mesh_set( sequence_manager(), ms_handles[i]);
+    if (set)
+      set->clear(ms_handles[i], a_entity_factory());
+    else
+      result = MB_ENTITY_NOT_FOUND;
+  }
+
+  return result;
+}
+
+ErrorCode Core::clear_meshset(const Range &ms_handles)
+{
+  ErrorCode result = MB_SUCCESS;
+  for (Range::iterator i = ms_handles.begin(); i != ms_handles.end(); ++i) {
+    MeshSet* set = get_mesh_set( sequence_manager(), *i);
+    if (set)
+      set->clear(*i, a_entity_factory());
+    else
+      result = MB_ENTITY_NOT_FOUND;
+  }
+
+  return result;
+}
+
+ErrorCode Core::subtract_meshset(EntityHandle meshset1, const EntityHandle meshset2)
+{ 
+  MeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
+  MeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
+  if (!set1 || !set2)
+    return MB_ENTITY_NOT_FOUND;
+  
+  return set1->subtract( set2, meshset1, a_entity_factory() );
+}
+
+
+ErrorCode Core::intersect_meshset(EntityHandle meshset1, const EntityHandle meshset2)
+{
+  MeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
+  MeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
+  if (!set1 || !set2)
+    return MB_ENTITY_NOT_FOUND;
+  
+  return set1->intersect( set2, meshset1, a_entity_factory() );
+}
+
+ErrorCode Core::unite_meshset(EntityHandle meshset1, const EntityHandle meshset2)
+{
+  MeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
+  MeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
+  if (!set1 || !set2)
+    return MB_ENTITY_NOT_FOUND;
+  
+  return set1->unite( set2, meshset1, a_entity_factory() );
+}
+
+ErrorCode Core::add_entities(EntityHandle meshset, 
+                                   const Range &entities)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->add_entities( entities, meshset, a_entity_factory() );
+  else
+    return MB_ENTITY_NOT_FOUND;
+}
+
+ErrorCode Core::add_entities(EntityHandle meshset, 
+                                   const EntityHandle *entities,
+                                   const int num_entities)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->add_entities( entities, num_entities, meshset, a_entity_factory() );
+  else
+    return MB_ENTITY_NOT_FOUND;
+}
+
+
+//! remove a range of entities from a meshset
+ErrorCode Core::remove_entities(EntityHandle meshset, 
+                                      const Range &entities)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->remove_entities( entities, meshset, a_entity_factory() );
+  else
+    return MB_ENTITY_NOT_FOUND;
+}
+
+//! remove a vector of entities from a meshset
+ErrorCode Core::remove_entities( EntityHandle meshset, 
+                                       const EntityHandle *entities,
+                                       const int num_entities)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->remove_entities( entities, num_entities, meshset, a_entity_factory() );
+  else
+    return MB_ENTITY_NOT_FOUND;
+}
+
+    //! return true if all entities are contained in set
+bool Core::contains_entities(EntityHandle meshset, 
+                               const EntityHandle *entities,
+                               int num_entities, 
+                               const int operation_type)
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->contains_entities(entities, num_entities, operation_type);
+  else
+    return false;
+}
+
+// replace entities in a meshset
+ErrorCode Core::replace_entities(EntityHandle meshset, 
+                                     const EntityHandle *old_entities,
+                                     const EntityHandle *new_entities,
+                                     int num_entities) 
+{
+  MeshSet* set = get_mesh_set( sequence_manager(), meshset );
+  if (set)
+    return set->replace_entities( meshset, old_entities, new_entities, 
+                                  num_entities, a_entity_factory());
+  else
+    return MB_ENTITY_NOT_FOUND;
+}
+
+ErrorCode Core::get_parent_meshsets(const EntityHandle meshset,
+                                          std::vector<EntityHandle> &parents,
+                                          const int num_hops) const
+{
+  if (0 == meshset) return MB_SUCCESS;
+
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->get_parents( sequence_manager(), meshset, parents, num_hops );
+}
+
+ErrorCode Core::get_parent_meshsets(const EntityHandle meshset,
+                                        Range &parents,
+                                          const int num_hops) const
+{
+  if (0 == meshset) return MB_SUCCESS;
+
+  std::vector<EntityHandle> parent_vec;
+  ErrorCode result = get_parent_meshsets(meshset, parent_vec, num_hops);
+  if (MB_SUCCESS != result) return result;
+  std::sort( parent_vec.begin(), parent_vec.end() );
+  std::copy(parent_vec.rbegin(), parent_vec.rend(), range_inserter(parents));
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::get_child_meshsets(const EntityHandle meshset,
+                                         std::vector<EntityHandle> &children,
+                                         const int num_hops) const
+{
+  if (0 == meshset) return MB_SUCCESS;
+
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->get_children( sequence_manager(), meshset, children, num_hops );
+}
+
+ErrorCode Core::get_child_meshsets(const EntityHandle meshset,
+                                        Range &children,
+                                          const int num_hops) const
+{
+  if (0 == meshset) return MB_SUCCESS;
+
+  std::vector<EntityHandle> child_vec;
+  ErrorCode result = get_child_meshsets(meshset, child_vec, num_hops);
+  if (MB_SUCCESS != result) return result;
+  std::sort( child_vec.begin(), child_vec.end() );
+  std::copy(child_vec.rbegin(), child_vec.rend(), range_inserter(children));
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::get_contained_meshsets( const EntityHandle meshset,
+                                            std::vector<EntityHandle> &children,
+                                            const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_entities_by_type( meshset, MBENTITYSET, children );
+  }
+
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->get_contained_sets( sequence_manager(), meshset, children, num_hops );
+}
+
+ErrorCode Core::get_contained_meshsets( const EntityHandle meshset,
+                                            Range &children,
+                                            const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_entities_by_type( meshset, MBENTITYSET, children );
+  }
+
+  std::vector<EntityHandle> child_vec;
+  ErrorCode result = get_contained_meshsets(meshset, child_vec, num_hops);
+  if (MB_SUCCESS != result) return result;
+  std::sort( child_vec.begin(), child_vec.end() );
+  std::copy(child_vec.rbegin(), child_vec.rend(), range_inserter(children));
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::num_parent_meshsets(const EntityHandle meshset, int* number,
+                                        const int num_hops) const
+{
+  if (0 == meshset) {
+    *number = 0;
+    return MB_SUCCESS;
+  }
+
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->num_parents( sequence_manager(), meshset, *number, num_hops );
+}
+
+ErrorCode Core::num_child_meshsets(const EntityHandle meshset, int* number,
+                                       const int num_hops) const
+{
+  if (0 == meshset) {
+    *number = 0;
+    return MB_SUCCESS;
+  }
+  
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->num_children( sequence_manager(), meshset, *number, num_hops );
+}
+
+ErrorCode Core::num_contained_meshsets(const EntityHandle meshset, int* number,
+                                       const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_number_entities_by_type( 0, MBENTITYSET, *number );
+  }
+  
+  const EntitySequence *seq;
+  ErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->num_contained_sets( sequence_manager(), meshset, *number, num_hops );
+}
+
+
+ErrorCode Core::add_parent_meshset( EntityHandle meshset, 
+                                        const EntityHandle parent_meshset)
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  MeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent_meshset );
+  if (!set_ptr || !parent_ptr)
+    return MB_ENTITY_NOT_FOUND;
+
+  set_ptr->add_parent( parent_meshset );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::add_parent_meshsets( EntityHandle meshset, 
+                                         const EntityHandle* parents,
+                                         int count )
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  if (!set_ptr)
+    return MB_ENTITY_NOT_FOUND;
+
+  for (int i = 0; i < count; ++i)
+    if (!get_mesh_set( sequence_manager(), parents[i] ))
+      return MB_ENTITY_NOT_FOUND;
+    
+  for (int i = 0; i < count; ++i)
+    set_ptr->add_parent( parents[i] );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::add_child_meshset(EntityHandle meshset, 
+                                        const EntityHandle child_meshset)
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  MeshSet* child_ptr = get_mesh_set( sequence_manager(), child_meshset );
+  if (!set_ptr || !child_ptr)
+    return MB_ENTITY_NOT_FOUND;
+
+  set_ptr->add_child( child_meshset );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::add_child_meshsets( EntityHandle meshset, 
+                                        const EntityHandle* children,
+                                        int count )
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  if (!set_ptr)
+    return MB_ENTITY_NOT_FOUND;
+
+  for (int i = 0; i < count; ++i)
+    if (!get_mesh_set( sequence_manager(), children[i] ))
+      return MB_ENTITY_NOT_FOUND;
+    
+  for (int i = 0; i < count; ++i)
+    set_ptr->add_child( children[i] );
+  return MB_SUCCESS;
+}
+
+
+ErrorCode Core::add_parent_child(EntityHandle parent, 
+                                       EntityHandle child)
+{
+  MeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent );
+  MeshSet* child_ptr = get_mesh_set( sequence_manager(), child );
+  if (!parent_ptr || !child_ptr)
+    return MB_ENTITY_NOT_FOUND;
+  
+  parent_ptr->add_child( child );
+  child_ptr->add_parent( parent );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::remove_parent_child(EntityHandle parent, 
+                                          EntityHandle child)
+{
+  MeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent );
+  MeshSet* child_ptr = get_mesh_set( sequence_manager(), child );
+  if (!parent_ptr || !child_ptr)
+    return MB_ENTITY_NOT_FOUND;
+  
+  parent_ptr->remove_child( child );
+  child_ptr->remove_parent( parent );
+  return MB_SUCCESS;
+}
+
+
+ErrorCode Core::remove_parent_meshset(EntityHandle meshset, 
+                                            const EntityHandle parent_meshset)
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  if (!set_ptr)
+    return MB_ENTITY_NOT_FOUND;
+  set_ptr->remove_parent( parent_meshset );
+  return MB_SUCCESS;
+}
+
+ErrorCode Core::remove_child_meshset(EntityHandle meshset, 
+                                           const EntityHandle child_meshset)
+{
+  MeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
+  if (!set_ptr)
+    return MB_ENTITY_NOT_FOUND;
+  set_ptr->remove_child( child_meshset );
+  return MB_SUCCESS;
+}
+
+
+ErrorCode Core::get_last_error(std::string& info) const
+{
+  return mError->get_last_error(info);
+}
+
+std::string Core::get_error_string(const ErrorCode code) const 
+{
+  static const char* errorStrings[MB_FAILURE+1] = {
+    "MB_SUCCESS",
+    "MB_INDEX_OUT_OF_RANGE",
+    "MB_TYPE_OUT_OF_RANGE",
+    "MB_MEMORY_ALLOCATION_FAILED",
+    "MB_ENTITY_NOT_FOUND",
+    "MB_MULTIPLE_ENTITIES_FOUND",
+    "MB_TAG_NOT_FOUND",
+    "MB_FILE_DOES_NOT_EXIST",
+    "MB_FILE_WRITE_ERROR",
+    "MB_NOT_IMPLEMENTED",
+    "MB_ALREADY_ALLOCATED",
+    "MB_VARIABLE_DATA_LENGTH",
+    "MB_INVALID_SIZE",
+    "MB_UNSUPPORTED_OPERATION",
+    "MB_UNHANDLED_OPTION",
+    "MB_FAILURE",
+  };
+
+  return errorStrings[code];
+}
+
+void Core::print(const EntityHandle ms_handle, const char *prefix,
+                   bool first_call) const
+{
+    // get the entities
+  Range entities;
+  
+  if (0 != ms_handle) {
+    get_entities_by_handle( ms_handle, entities );
+    if (!first_call)
+      std::cout << prefix << "MBENTITYSET " << ID_FROM_HANDLE(ms_handle) 
+                << std::endl;
+  }
+  else {
+    get_entities_by_dimension(0, 3, entities);
+    if (entities.empty()) get_entities_by_dimension(0, 2, entities);
+    if (entities.empty()) get_entities_by_dimension(0, 1, entities);
+    get_entities_by_dimension(0, 0, entities);
+    get_entities_by_type(0, MBENTITYSET, entities);
+    std::cout << prefix << "--: " << std::endl;
+  }
+    
+  std::string indent_prefix = prefix;
+  indent_prefix += "  ";
+  entities.print(indent_prefix.c_str());
+
+  if (!first_call || !ms_handle) return;
+  
+    // print parent/children
+  Range temp;
+  this->get_parent_meshsets(ms_handle, temp);
+  std::cout << "  Parent sets: ";
+  if (temp.empty()) std::cout << "(none)" << std::endl;
+  else {
+    for (Range::iterator rit = temp.begin(); rit != temp.end(); rit++) {
+      if (rit != temp.begin()) std::cout << ", ";
+      std::cout << ID_FROM_HANDLE(*rit);
+    }
+    std::cout << std::endl;
+  }
+
+  temp.clear();
+  this->get_child_meshsets(ms_handle, temp);
+  std::cout << "  Child sets: ";
+  if (temp.empty()) std::cout << "(none)" << std::endl;
+  else {
+    for (Range::iterator rit = temp.begin(); rit != temp.end(); rit++) {
+      if (rit != temp.begin()) std::cout << ", ";
+      std::cout << ID_FROM_HANDLE(*rit);
+    }
+    std::cout << std::endl;
+  }
+
+    // print all sparse tags
+  std::vector<Tag> set_tags;
+  ErrorCode result = this->tag_get_tags_on_entity(ms_handle, set_tags);
+  std::cout << indent_prefix << "Sparse tags:" << std::endl;
+  indent_prefix += "  ";
+  
+  for (std::vector<Tag>::iterator vit = set_tags.begin(); 
+       vit != set_tags.end(); vit++) {
+    TagType this_type;
+    result = this->tag_get_type(*vit, this_type);
+    if (MB_SUCCESS != result || MB_TAG_SPARSE != this_type) continue;
+    DataType this_data_type;
+    result = this->tag_get_data_type(*vit, this_data_type);
+    int this_size;
+    result = this->tag_get_size(*vit, this_size);
+    if (MB_SUCCESS != result || (int) sizeof(double) < this_size) continue;
+      // use double since this is largest single-valued tag
+    double dbl_val;
+    int int_val;
+    EntityHandle hdl_val;
+    std::string tag_name;
+    result = this->tag_get_name(*vit, tag_name);
+    if (MB_SUCCESS != result) continue;
+    switch (this_data_type) {
+      case MB_TYPE_INTEGER:
+        result = this->tag_get_data(*vit, &ms_handle, 1, &int_val);
+        if (MB_SUCCESS != result) continue;
+        std::cout << indent_prefix << tag_name << " = " << int_val << std::endl;
+        break;
+      case MB_TYPE_DOUBLE:
+        result = this->tag_get_data(*vit, &ms_handle, 1, &dbl_val);
+        if (MB_SUCCESS != result) continue;
+        std::cout << indent_prefix << tag_name << " = " << dbl_val << std::endl;
+        break;
+      case MB_TYPE_HANDLE:
+        result = this->tag_get_data(*vit, &ms_handle, 1, &hdl_val);
+        if (MB_SUCCESS != result) continue;
+        std::cout << indent_prefix << tag_name << " = " << hdl_val << std::endl;
+        break;
+      case MB_TYPE_BIT:
+      case MB_TYPE_OPAQUE:
+        break;
+    }
+  }
+}
+
+ErrorCode Core::check_adjacencies() 
+{
+    // run through all entities, checking adjacencies and reverse-evaluating them
+  Range all_ents;
+  ErrorCode result = get_entities_by_handle(0, all_ents);
+  if (MB_SUCCESS != result) return result;
+  
+  ErrorCode tmp_result;
+  for (Range::iterator rit = all_ents.begin(); rit != all_ents.end(); rit++) {
+    tmp_result = check_adjacencies(&(*rit), 1);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  
+  return result;
+}
+
+ErrorCode Core::check_adjacencies(const EntityHandle *ents, int num_ents) 
+{
+
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  std::ostringstream oss;
+  
+  for (int i = 0; i < num_ents; i++) {
+    EntityHandle this_ent = ents[i];
+    std::ostringstream ent_str;
+    ent_str << MBCN::EntityTypeName(TYPE_FROM_HANDLE(this_ent)) << " "
+            << ID_FROM_HANDLE(this_ent) << ": ";
+    int this_dim = dimension_from_handle(this_ent);
+
+    if (!is_valid(this_ent)) {
+      std::cerr << ent_str.str()
+                << "Not a valid entity." << std::endl;
+      result = MB_FAILURE;
+    }
+
+    else {
+      if (TYPE_FROM_HANDLE(this_ent) == MBENTITYSET) continue;
+      
+        // get adjacencies for this entity
+      Range adjs;
+      for (int dim = 0; dim <= 3; dim++) {
+        if (dim == this_dim) continue;
+        tmp_result = get_adjacencies(&this_ent, 1, dim, false, adjs, Interface::UNION);
+        if (MB_SUCCESS != tmp_result) {
+          oss << ent_str.str()
+              << "Failed to get adjacencies for dimension " << dim << "." << std::endl;
+          result = tmp_result;
+        }
+      }
+      if (!oss.str().empty()) {
+        std::cerr << oss.str();
+        oss.str("");
+      }
+
+        // now check and reverse-evaluate them
+      for (Range::iterator rit = adjs.begin(); rit != adjs.end(); rit++) {
+        EntitySequence* seq = 0;
+        tmp_result = sequence_manager()->find(*rit, seq);
+        if(seq == 0 || tmp_result != MB_SUCCESS) {
+          oss << ent_str.str() << 
+            "Adjacent entity " << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
+              << ID_FROM_HANDLE(*rit) << " is invalid." << std::endl;
+          result = tmp_result;
+        }
+        else {
+          Range rev_adjs;
+          tmp_result = get_adjacencies(&(*rit), 1, this_dim, false, rev_adjs);
+          if (MB_SUCCESS != tmp_result) {
+            oss << ent_str.str() 
+                << "Failed to get reverse adjacency from " 
+                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
+                << ID_FROM_HANDLE(*rit);
+            if (MB_MULTIPLE_ENTITIES_FOUND == tmp_result)
+              oss << " (MULTIPLE)" << std::endl;
+            else oss << " (" << tmp_result << ")" << std::endl;
+            result = tmp_result;
+          }
+          else if (rev_adjs.find(this_ent) == rev_adjs.end()) {
+            oss << ent_str.str() 
+                << "Failed to find adjacency to this entity from " 
+                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
+                << ID_FROM_HANDLE(*rit) << "." << std::endl;
+            result = tmp_result;
+          }
+        }
+        if (!oss.str().empty()) {
+          std::cerr << oss.str();
+          oss.str("");
+        }
+      }
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+bool Core::is_valid(const EntityHandle this_ent) const
+{
+  const EntitySequence* seq = 0;
+  ErrorCode result = sequence_manager()->find(this_ent, seq);
+  return seq != 0 && result == MB_SUCCESS;
+}
+
+static unsigned long get_num_entities_with_tag( TagServer* ts, 
+                                                Tag tag,
+                                                const Range& entities )
+{
+  if (entities.empty())
+    return 0;
+  
+  int tmp;
+  unsigned long total = 0;
+  EntityType t = TYPE_FROM_HANDLE( entities.front() );
+  EntityType e = TYPE_FROM_HANDLE( entities.back() );
+  ++e;
+  for (; t != e; ++t) {
+    tmp = 0;
+    if (MB_SUCCESS == ts->get_number_entities( entities, tag, t, tmp ))
+      total += tmp;
+  }
+  
+  return total;
+}
+
+void Core::estimated_memory_use_internal( const Range* ents,
+                                  unsigned long* total_storage,
+                                  unsigned long* total_amortized_storage,
+                                  unsigned long* entity_storage,
+                                  unsigned long* amortized_entity_storage,
+                                  unsigned long* adjacency_storage,
+                                  unsigned long* amortized_adjacency_storage,
+                                  const Tag* tag_array,
+                                  unsigned num_tags,
+                                  unsigned long* tag_storage,
+                                  unsigned long* amortized_tag_storage )
+{
+    // Figure out which values we need to calulate
+  unsigned long i_entity_storage,    ia_entity_storage, 
+                i_adjacency_storage, ia_adjacency_storage, 
+                i_tag_storage,       ia_tag_storage;
+  unsigned long *total_tag_storage = 0, 
+                *amortized_total_tag_storage =0;
+  if (!tag_array) {
+    total_tag_storage = tag_storage;
+    amortized_total_tag_storage = amortized_tag_storage;
+  }
+  if (total_storage || total_amortized_storage) {
+    if (!entity_storage)
+      entity_storage = &i_entity_storage;
+    if (!amortized_entity_storage)
+      amortized_entity_storage = &ia_entity_storage;
+    if (!adjacency_storage)
+      adjacency_storage = &i_adjacency_storage;
+    if (!amortized_adjacency_storage)
+      amortized_adjacency_storage = &ia_adjacency_storage;
+  }
+  else {
+    if (entity_storage || amortized_entity_storage) {
+      if (!amortized_entity_storage)
+        amortized_entity_storage = &ia_entity_storage;
+      else if (!entity_storage)
+        entity_storage = &i_entity_storage;
+    }
+    if (adjacency_storage || amortized_adjacency_storage) {
+      if (!amortized_adjacency_storage)
+        amortized_adjacency_storage = &ia_adjacency_storage;
+      else if (!adjacency_storage)
+        adjacency_storage = &i_adjacency_storage;
+    }
+  }
+  if (!total_tag_storage && total_storage)
+    total_tag_storage = &i_tag_storage;
+  if (!amortized_total_tag_storage && total_amortized_storage)
+    amortized_total_tag_storage = &ia_tag_storage;
+    
+    // get entity storage
+  if (amortized_entity_storage) {
+    if (ents)
+      sequenceManager->get_memory_use( *ents, *entity_storage, *amortized_entity_storage );
+    else
+      sequenceManager->get_memory_use( *entity_storage, *amortized_entity_storage );
+  }
+  
+    // get adjacency storage
+  if (amortized_adjacency_storage) {
+    if (ents)
+      aEntityFactory->get_memory_use( *ents, *adjacency_storage, *amortized_adjacency_storage );
+    else
+      aEntityFactory->get_memory_use( *adjacency_storage, *amortized_adjacency_storage );
+  }
+  
+    // get storage for requested list of tags
+  if (tag_array) {
+    for (unsigned i = 0; i < num_tags; ++i) {
+      unsigned long total, per_ent, count;
+      tagServer->get_memory_use( tag_array[i], total, per_ent );
+      
+      if (ents) {
+        count = get_num_entities_with_tag( tagServer, tag_array[i], *ents );
+        if (tag_storage)
+          tag_storage[i] = count * per_ent;
+        if (amortized_tag_storage) {
+          tagServer->get_number_entities( tag_array[i], per_ent );
+          if (per_ent)
+            amortized_tag_storage[i] = (unsigned long)((double)total * count / per_ent);
+        }
+      }
+      else {
+        if (tag_storage) {
+          tagServer->get_number_entities( tag_array[i], count );
+          tag_storage[i] = count * per_ent;
+        }
+        if (amortized_tag_storage)
+          amortized_tag_storage[i] = total;
+      }
+    }
+  }
+  
+    // get storage for all tags
+  if (total_tag_storage || amortized_total_tag_storage) {
+    if (amortized_total_tag_storage)
+      *amortized_total_tag_storage = 0;
+    if (total_tag_storage)
+      *total_tag_storage =0;
+      
+    std::vector<Tag> tags;
+    tag_get_tags( tags );
+    for (unsigned i = 0; i < tags.size(); ++i) {
+      unsigned long total, per_ent, count;
+      tagServer->get_memory_use( tags[i], total, per_ent );
+      
+      if (ents) {
+        count = get_num_entities_with_tag( tagServer, tags[i], *ents );
+        if (total_tag_storage)
+          *total_tag_storage += count * per_ent;
+        if (amortized_total_tag_storage) {
+          tagServer->get_number_entities( tags[i], per_ent );
+          if (per_ent)
+            *amortized_total_tag_storage += (unsigned long)((double)total * count / per_ent);
+        }
+      }
+      else {
+        if (total_tag_storage) {
+          tagServer->get_number_entities( tags[i], count );
+          *total_tag_storage += count * per_ent;
+        }
+        if (amortized_total_tag_storage)
+          *amortized_total_tag_storage += total;
+      }
+    }
+  }
+  
+    // calculate totals
+  if (total_storage)
+    *total_storage = *entity_storage + *adjacency_storage + *total_tag_storage;
+  
+  if (total_amortized_storage)
+    *total_amortized_storage = *amortized_entity_storage 
+                             + *amortized_adjacency_storage
+                             + *amortized_total_tag_storage;
+}
+
+
+void  Core::estimated_memory_use( const EntityHandle* ent_array,
+                                    unsigned long num_ents,
+                                    unsigned long* total_storage,
+                                    unsigned long* total_amortized_storage,
+                                    unsigned long* entity_storage,
+                                    unsigned long* amortized_entity_storage,
+                                    unsigned long* adjacency_storage,
+                                    unsigned long* amortized_adjacency_storage,
+                                    const Tag* tag_array,
+                                    unsigned num_tags,
+                                    unsigned long* tag_storage,
+                                    unsigned long* amortized_tag_storage ) 
+{
+  Range range;
+  
+    // If non-empty entity list, call range version of function
+  if (ent_array) {
+    if (num_ents > 20) {
+      std::vector<EntityHandle> list(num_ents);
+      std::copy(ent_array, ent_array+num_ents, list.begin());
+      std::sort( list.begin(), list.end() );
+      Range::iterator j = range.begin();
+      for (std::vector<EntityHandle>::reverse_iterator i = list.rbegin(); i != list.rend(); ++i)
+        j = range.insert( j, *i, *i );
+    }
+    else {
+      std::copy( ent_array, ent_array + num_ents, range_inserter(range) );
+    }
+  }
+  
+  estimated_memory_use_internal( ent_array ? &range : 0,
+                         total_storage,     total_amortized_storage,
+                         entity_storage,    amortized_entity_storage,
+                         adjacency_storage, amortized_adjacency_storage,
+                         tag_array,         num_tags,
+                         tag_storage,       amortized_tag_storage );
+}
+
+void Core::estimated_memory_use( const Range& ents,
+                                   unsigned long* total_storage,
+                                   unsigned long* total_amortized_storage,
+                                   unsigned long* entity_storage,
+                                   unsigned long* amortized_entity_storage,
+                                   unsigned long* adjacency_storage,
+                                   unsigned long* amortized_adjacency_storage,
+                                   const Tag* tag_array,
+                                   unsigned num_tags,
+                                   unsigned long* tag_storage,
+                                   unsigned long* amortized_tag_storage )
+{
+  estimated_memory_use_internal( &ents,
+                         total_storage,     total_amortized_storage,
+                         entity_storage,    amortized_entity_storage,
+                         adjacency_storage, amortized_adjacency_storage,
+                         tag_array,         num_tags,
+                         tag_storage,       amortized_tag_storage );
+}
+
+void Core::print_database() const
+{
+  ErrorCode rval;
+  TypeSequenceManager::const_iterator i;
+  const TypeSequenceManager& verts = sequence_manager()->entity_map(MBVERTEX);
+  if (!verts.empty())
+    printf("  Vertex ID  X        Y        Z        Adjacencies   \n"     
+           "  ---------- -------- -------- -------- -----------...\n");
+  const EntityHandle* adj;
+  int nadj;
+  for (i = verts.begin(); i != verts.end(); ++i) {
+    const VertexSequence* seq = static_cast<const VertexSequence* >(*i);
+    printf("(Sequence [%d,%d] in SequenceData [%d,%d])\n",
+      (int)ID_FROM_HANDLE(seq->start_handle()),
+      (int)ID_FROM_HANDLE(seq->end_handle()),
+      (int)ID_FROM_HANDLE(seq->data()->start_handle()),
+      (int)ID_FROM_HANDLE(seq->data()->end_handle()));
+    
+    double c[3];
+    for (EntityHandle h = seq->start_handle(); h <= seq->end_handle(); ++h) {
+      rval = seq->get_coordinates( h, c );
+      if (MB_SUCCESS == rval)
+        printf("  %10d %8g %8g %8g", (int)ID_FROM_HANDLE(h), c[0], c[1], c[2] );
+      else
+        printf("  %10d <       ERROR %4d       >", (int)ID_FROM_HANDLE(h), (int)rval );
+ 
+      rval = a_entity_factory()->get_adjacencies( h, adj, nadj );
+      if (MB_SUCCESS != rval) {
+        printf(" <ERROR %d>\n", (int)rval );
+        continue;
+      }
+      EntityType pt = MBMAXTYPE;
+      for (int j = 0; j < nadj; ++j) {
+        if (TYPE_FROM_HANDLE(adj[j]) != pt) {
+          pt = TYPE_FROM_HANDLE(adj[j]);
+          printf("  %s", pt >= MBMAXTYPE ? "INVALID TYPE" : MBCN::EntityTypeName(pt) );
+        }
+        printf(" %d", (int)ID_FROM_HANDLE(adj[j]));
+      }
+      printf("\n");
+    }
+  }
+  
+  for (EntityType t = MBEDGE; t < MBENTITYSET; ++t) {
+    const TypeSequenceManager& elems = sequence_manager()->entity_map(t);
+    if (elems.empty())
+      continue;
+    
+    int clen = 0;
+    for (i = elems.begin(); i != elems.end(); ++i) {
+      int n = static_cast<const ElementSequence*>(*i)->nodes_per_element();
+      if (n > clen)
+        clen = n;
+    }
+
+    clen *= 5;
+    if (clen < (int)strlen("Connectivity"))
+      clen = strlen("Connectivity");
+    std::vector<char> dashes( clen, '-' );
+    dashes.push_back( '\0' );
+    printf( "  %7s ID %-*s Adjacencies\n", MBCN::EntityTypeName(t), clen, "Connectivity" );
+    printf( "  ---------- %s -----------...\n", &dashes[0] );
+    
+    std::vector<EntityHandle> storage;
+    const EntityHandle* conn;
+    int nconn;
+    for (i = elems.begin(); i != elems.end(); ++i) {
+      const ElementSequence* seq = static_cast<const ElementSequence*>(*i);
+      printf("(Sequence [%d,%d] in SequenceData [%d,%d])\n",
+        (int)ID_FROM_HANDLE(seq->start_handle()),
+        (int)ID_FROM_HANDLE(seq->end_handle()),
+        (int)ID_FROM_HANDLE(seq->data()->start_handle()),
+        (int)ID_FROM_HANDLE(seq->data()->end_handle()));
+      
+      for (EntityHandle h = seq->start_handle(); h <= seq->end_handle(); ++h) {
+        printf( "  %10d", (int)ID_FROM_HANDLE(h) );
+        rval = get_connectivity( h, conn, nconn, false, &storage );
+        if (MB_SUCCESS != rval) 
+          printf( "  <ERROR %2d>%*s", (int)rval, clen-10, "" );
+        else {
+          for (int j = 0; j < nconn; ++j)
+            printf(" %4d", (int)ID_FROM_HANDLE(conn[j]));
+          printf("%*s", clen - 5*nconn, "" );
+        }
+        
+        rval = a_entity_factory()->get_adjacencies( h, adj, nadj );
+        if (MB_SUCCESS != rval) {
+          printf(" <ERROR %d>\n", (int)rval );
+          continue;
+        }
+        EntityType pt = MBMAXTYPE;
+        for (int j = 0; j < nadj; ++j) {
+          if (TYPE_FROM_HANDLE(adj[j]) != pt) {
+            pt = TYPE_FROM_HANDLE(adj[j]);
+            printf("  %s", pt >= MBMAXTYPE ? "INVALID TYPE" : MBCN::EntityTypeName(pt) );
+          }
+          printf(" %d", (int)ID_FROM_HANDLE(adj[j]));
+        }
+        printf("\n");
+      }
+    }
+  }
+}
+
+ErrorCode Core::create_scd_sequence(const HomCoord & coord_min,
+					const HomCoord &  coord_max,
+					EntityType  type,
+					EntityID  start_id_hint,
+					EntityHandle &  first_handle_out,
+					EntitySequence *&  sequence_out )
+{
+  return sequence_manager()->create_scd_sequence(coord_min, coord_max, type,
+						 start_id_hint, 
+						 first_handle_out,
+						 sequence_out);
+}
+
+ErrorCode Core::add_vsequence(EntitySequence *    vert_seq,
+				  EntitySequence *  elem_seq,
+				  const HomCoord &  p1,
+				  const HomCoord &  q1,
+				  const HomCoord &  p2,
+				  const HomCoord &  q2,
+				  const HomCoord &  p3,
+				  const HomCoord &  q3,
+				  bool  bb_input,
+				  const HomCoord *  bb_min,
+				  const HomCoord *  bb_max )
+{
+  return sequence_manager()->add_vsequence(vert_seq, elem_seq, 
+					   p1, q1, p2, q2, p3, q3,
+					   bb_input, bb_min, bb_max);
+
+}
+  
+} // namespace moab

Modified: MOAB/trunk/src/DualTool.cpp
===================================================================
--- MOAB/trunk/src/DualTool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/DualTool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,17 +13,17 @@
  * 
  */
 
-#include "DualTool.hpp"
-#include "MBRange.hpp"
-// using MBCore for call to check_adjacencies
-#include "MBCore.hpp"
-#include "MBInternals.hpp"
-#include "MBTagConventions.hpp"
-#include "MBSkinner.hpp"
-#include "MBCore.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/DualTool.hpp"
+#include "moab/Range.hpp"
+// using Core for call to check_adjacencies
+#include "moab/Core.hpp"
+#include "Internals.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Skinner.hpp"
+#include "moab/Core.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "AEntityFactory.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 #include <string>
 #include <algorithm>
 #include <iostream>
@@ -31,8 +31,10 @@
 #include <assert.h>
 
 #define RR if (MB_SUCCESS != result) return result
-#define SWAP(a,b) {MBEntityHandle tmp_ent = a; a = b; b = tmp_ent;}
+#define SWAP(a,b) {EntityHandle tmp_ent = a; a = b; b = tmp_ent;}
 
+namespace moab {
+
 bool debug = false;
 bool debug_ap = false;
 
@@ -56,17 +58,17 @@
 
 //const int DualTool::GP_SIZE = 20;
 
-DualTool::DualTool(MBInterface *impl) 
+DualTool::DualTool(Interface *impl) 
     : mbImpl(impl)
 {
-  MBEntityHandle dum_handle = 0;
+  EntityHandle dum_handle = 0;
 
-  MBErrorCode result = mbImpl->tag_create(DUAL_SURFACE_TAG_NAME, sizeof(MBEntityHandle), 
+  ErrorCode result = mbImpl->tag_create(DUAL_SURFACE_TAG_NAME, sizeof(EntityHandle), 
                                           MB_TAG_SPARSE, 
                                           dualSurfaceTag, &dum_handle);
   assert(MB_ALREADY_ALLOCATED == result || MB_SUCCESS == result);
   
-  result = mbImpl->tag_create(DUAL_CURVE_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_SPARSE, 
+  result = mbImpl->tag_create(DUAL_CURVE_TAG_NAME, sizeof(EntityHandle), MB_TAG_SPARSE, 
                               dualCurveTag, &dum_handle);
   assert(MB_ALREADY_ALLOCATED == result || MB_SUCCESS == result);
   
@@ -75,11 +77,11 @@
                               isDualCellTag, &dummy);
   assert(MB_ALREADY_ALLOCATED == result || MB_SUCCESS == result);
 
-  result = mbImpl->tag_create(DUAL_ENTITY_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_DENSE, 
+  result = mbImpl->tag_create(DUAL_ENTITY_TAG_NAME, sizeof(EntityHandle), MB_TAG_DENSE, 
                               dualEntityTag, &dum_handle);
   assert(MB_ALREADY_ALLOCATED == result || MB_SUCCESS == result);
 
-  result = mbImpl->tag_create(EXTRA_DUAL_ENTITY_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_SPARSE, 
+  result = mbImpl->tag_create(EXTRA_DUAL_ENTITY_TAG_NAME, sizeof(EntityHandle), MB_TAG_SPARSE, 
                               extraDualEntityTag, &dum_handle);
   assert(MB_ALREADY_ALLOCATED == result || MB_SUCCESS == result);
   
@@ -106,15 +108,15 @@
 {}
 
   //! construct the dual entities for the entire mesh
-MBErrorCode DualTool::construct_dual(MBEntityHandle *entities, 
+ErrorCode DualTool::construct_dual(EntityHandle *entities, 
                                      const int num_entities) 
 {
     // allocate a dual entity for each primal entity in the mesh, starting
     // with highest dimension and working downward; do each dimension in a separate code
     // block, since they're all handled slightly differently
   
-  MBRange regions, faces, edges, vertices;
-  MBErrorCode result;
+  Range regions, faces, edges, vertices;
+  ErrorCode result;
 
   if (NULL == entities || 0 == num_entities) {
     
@@ -141,7 +143,7 @@
     result = mbImpl->tag_get_data(globalId_tag(), regions, &gid_vec[0]);
     if (MB_SUCCESS != result) return result;
     maxHexId = -1;
-    MBRange::iterator rit;
+    Range::iterator rit;
     unsigned int i;
     for (rit = regions.begin(), i = 0; rit != regions.end(); rit++, i++) {
       if (gid_vec[i] > maxHexId && mbImpl->type_from_handle(*rit) == MBHEX)
@@ -151,42 +153,42 @@
   else {
       // get entities of various dimensions adjacent to these
     result = mbImpl->get_adjacencies(entities, num_entities, 0, true, vertices, 
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
     result = mbImpl->get_adjacencies(entities, num_entities, 1, true, edges,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
     result = mbImpl->get_adjacencies(entities, num_entities, 2, true, faces,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
     result = mbImpl->get_adjacencies(entities, num_entities, 3, true, regions,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
   
   }
   
-  MBRange dual_verts;
+  Range dual_verts;
   result = construct_dual_vertices(regions, dual_verts);
   if (MB_SUCCESS != result || dual_verts.size() != regions.size()) return result;
   if (debug)
     std::cout << "Constructed " << dual_verts.size() << " dual vertices." << std::endl;
 
     // don't really need dual edges, but construct 'em anyway
-  MBRange dual_edges;
+  Range dual_edges;
   result = construct_dual_edges(faces, dual_edges);
   if (MB_SUCCESS != result || dual_edges.size() != faces.size()) return result;
   if (debug)
     std::cout << "Constructed " << dual_edges.size() << " dual edges." << std::endl;
 
     // construct dual faces
-  MBRange dual_faces;
+  Range dual_faces;
   result = construct_dual_faces(edges, dual_faces);
   if (MB_SUCCESS != result || dual_faces.size() != edges.size()) return result;
   if (debug)
     std::cout << "Constructed " << dual_faces.size() << " dual faces." << std::endl;
 
     // construct dual cells
-  MBRange dual_cells;
+  Range dual_cells;
   result = construct_dual_cells(vertices, dual_cells);
   if (MB_SUCCESS != result || dual_cells.size() != vertices.size()) return result;
   if (debug)
@@ -195,8 +197,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::construct_dual_vertices(const MBRange &all_regions,
-                                              MBRange &dual_ents) 
+ErrorCode DualTool::construct_dual_vertices(const Range &all_regions,
+                                              Range &dual_ents) 
 {
   if (all_regions.empty()) return MB_SUCCESS;
   
@@ -204,10 +206,10 @@
   assert(3 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_regions.begin())) &&
          3 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_regions.rbegin())));
   
-  MBRange::const_iterator rit;
-  MBEntityHandle dual_ent;
-  MBErrorCode tmp_result = MB_SUCCESS;
-  MBErrorCode result = MB_SUCCESS;
+  Range::const_iterator rit;
+  EntityHandle dual_ent;
+  ErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
   for (rit = all_regions.begin(); rit != all_regions.end(); rit++) {
     if (tmp_result != MB_SUCCESS) result = tmp_result;
@@ -230,15 +232,15 @@
   return result;
 }
 
-MBErrorCode DualTool::construct_dual_vertex(MBEntityHandle entity, 
-                                            MBEntityHandle &dual_ent, 
+ErrorCode DualTool::construct_dual_vertex(EntityHandle entity, 
+                                            EntityHandle &dual_ent, 
                                             const bool extra,
                                             const bool add_graphics_pt)
 {
     // no dual entity; construct one; first need the avg coordinates
   unsigned int is_dual = 0x1;
   double avg_pos[3];
-  MBErrorCode result = MeshTopoUtil(mbImpl).get_average_position(entity, avg_pos);
+  ErrorCode result = MeshTopoUtil(mbImpl).get_average_position(entity, avg_pos);
   if (MB_SUCCESS != result) return result;
     
     // now construct the new dual entity
@@ -266,12 +268,12 @@
   return result;
 }
 
-MBErrorCode DualTool::add_graphics_point(MBEntityHandle entity,
+ErrorCode DualTool::add_graphics_point(EntityHandle entity,
                                          double *avg_pos) 
 {
     // add a graphics pt, placed at the same position as the vertex
   double my_pos[3];
-  MBErrorCode result;
+  ErrorCode result;
   
   if (NULL == avg_pos) {
     result = MeshTopoUtil(mbImpl).get_average_position(entity, my_pos);
@@ -286,8 +288,8 @@
   return result;
 }
 
-MBErrorCode DualTool::construct_dual_edges(const MBRange &all_faces,
-                                           MBRange &dual_ents) 
+ErrorCode DualTool::construct_dual_edges(const Range &all_faces,
+                                           Range &dual_ents) 
 {
   if (all_faces.empty()) return MB_SUCCESS;
   
@@ -295,11 +297,11 @@
   assert(2 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_faces.begin())) &&
          2 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_faces.rbegin())));
   
-  MBRange::const_iterator rit;
-  MBEntityHandle dual_ent;
+  Range::const_iterator rit;
+  EntityHandle dual_ent;
   unsigned int is_dual = 0x1;
-  MBErrorCode tmp_result = MB_SUCCESS;
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
   for (rit = all_faces.begin(); rit != all_faces.end(); rit++) {
     if (tmp_result != MB_SUCCESS) result = tmp_result;
@@ -311,12 +313,12 @@
     }
     
       // no dual entity; construct one; get the bounding regions
-    std::vector<MBEntityHandle> in_ents, out_ents;
+    std::vector<EntityHandle> in_ents, out_ents;
     tmp_result = mbImpl->get_adjacencies(&(*rit), 1, 3, false, out_ents);
     if (MB_SUCCESS != tmp_result || out_ents.empty()) continue;
 
       // get the dual vertices
-    std::vector<MBEntityHandle> dual_verts(out_ents.size());
+    std::vector<EntityHandle> dual_verts(out_ents.size());
     tmp_result = mbImpl->tag_get_data(dualEntity_tag(), &out_ents[0], out_ents.size(), 
                                       &dual_verts[0]);
     if (MB_SUCCESS != tmp_result) continue;
@@ -368,8 +370,8 @@
   return result;
 }
 
-MBErrorCode DualTool::construct_dual_faces(const MBRange &all_edges,
-                                           MBRange &dual_ents) 
+ErrorCode DualTool::construct_dual_faces(const Range &all_edges,
+                                           Range &dual_ents) 
 {
   if (all_edges.empty()) return MB_SUCCESS;
   
@@ -377,12 +379,12 @@
   assert(1 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_edges.begin())) &&
          1 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_edges.rbegin())));
   
-  MBRange::const_iterator rit;
-  MBEntityHandle dual_ent;
+  Range::const_iterator rit;
+  EntityHandle dual_ent;
   unsigned int is_dual = 0x1;
-  MBErrorCode tmp_result = MB_SUCCESS;
-  MBErrorCode result = MB_SUCCESS;
-  MBRange equiv_edges;
+  ErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
+  Range equiv_edges;
 #define TRC if (MB_SUCCESS != tmp_result) {result = tmp_result; continue;}
   for (rit = all_edges.begin(); rit != all_edges.end(); rit++) {
     
@@ -394,7 +396,7 @@
     
       // no dual entity; construct one; get the dual vertices bounding the edge in radial order,
       // then construct the dual face
-    std::vector<MBEntityHandle> rad_dverts;
+    std::vector<EntityHandle> rad_dverts;
     bool bdy_edge;
     tmp_result = get_radial_dverts(*rit, rad_dverts, bdy_edge);TRC
     if (rad_dverts.empty()) continue;
@@ -416,7 +418,7 @@
     if (bdy_edge) {
       
         // add a new dual edge betw last 2 verts
-      MBEntityHandle new_edge;
+      EntityHandle new_edge;
       tmp_result = mbImpl->create_element(MBEDGE, &rad_dverts[rad_dverts.size()-2], 
                                           2, new_edge);TRC
       tmp_result = mbImpl->tag_set_data(isDualCell_tag(), &new_edge, 1, &is_dual);TRC
@@ -436,7 +438,7 @@
     }
 
       // check to see whether we have equiv entities; if we find any, save for later fixup
-    MBRange dum_edges, dum_poly(dual_ent, dual_ent);
+    Range dum_edges, dum_poly(dual_ent, dual_ent);
     tmp_result = mbImpl->get_adjacencies(dum_poly, 1, false, dum_edges);
     if (MB_MULTIPLE_ENTITIES_FOUND == tmp_result) {
         // we do - need to add adjacencies to disambiguate; use the primal
@@ -450,41 +452,41 @@
   return result;
 }
 
-MBErrorCode DualTool::check_dual_equiv_edges(MBRange &dual_edges)
+ErrorCode DualTool::check_dual_equiv_edges(Range &dual_edges)
 {
     // fix equivalent dual edges (i.e. edges whose vertices define multiple edges)
     // by explicitly adding adjacencies to containing polygons; adjacent polygons
     // found by going through primal
-  MBErrorCode tmp_result, result = MB_SUCCESS;
+  ErrorCode tmp_result, result = MB_SUCCESS;
 
-  MBRange all_dedges(dual_edges);
+  Range all_dedges(dual_edges);
     // first, go through all dual edges and find equivalent edges (by looking for
     // up-adjacent edges on the vertices of each edge)
-  for (MBRange::iterator rit = dual_edges.begin(); rit != dual_edges.end(); rit++) {
-    MBRange connect, dum_range(*rit, *rit);
+  for (Range::iterator rit = dual_edges.begin(); rit != dual_edges.end(); rit++) {
+    Range connect, dum_range(*rit, *rit);
     tmp_result = mbImpl->get_adjacencies(dum_range, 0, false, connect);
     if (MB_SUCCESS != tmp_result) continue;
-    tmp_result = mbImpl->get_adjacencies(connect, 1, false, all_dedges, MBInterface::UNION);
+    tmp_result = mbImpl->get_adjacencies(connect, 1, false, all_dedges, Interface::UNION);
     if (MB_SUCCESS != tmp_result) continue;
   }
 
     // save a copy for checking later
-  MBRange save_all_2cells;
+  Range save_all_2cells;
 
     // go through each edge
   while (!all_dedges.empty()) {
-    MBEntityHandle this_edge = *all_dedges.begin();
+    EntityHandle this_edge = *all_dedges.begin();
     all_dedges.erase(all_dedges.begin());
     
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
     result = mbImpl->get_connectivity(this_edge, connect, num_connect);
     if (MB_SUCCESS != result) continue;
 
-    MBRange dum_edges, verts;
+    Range dum_edges, verts;
     verts.insert(connect[0]);
     verts.insert(connect[1]);
-    MBErrorCode tmp_result = mbImpl->get_adjacencies(verts, 1, false, dum_edges);
+    ErrorCode tmp_result = mbImpl->get_adjacencies(verts, 1, false, dum_edges);
     if (MB_SUCCESS != tmp_result) {
       result = tmp_result;
       continue;
@@ -496,7 +498,7 @@
     
       // ok, have an equiv entity - fix by looking through primal
       // pre-get the primal of these
-    MBEntityHandle dedge_quad;
+    EntityHandle dedge_quad;
     tmp_result = mbImpl->tag_get_data(dualEntity_tag(), &this_edge, 1, &dedge_quad);
     if (MB_SUCCESS != tmp_result) {
       result = tmp_result;
@@ -506,14 +508,14 @@
     if (MBQUAD == mbImpl->type_from_handle(dedge_quad)) {
       
         // get the primal edges adj to quad
-      MBRange dum_quad_range(dedge_quad, dedge_quad), adj_pedges;
+      Range dum_quad_range(dedge_quad, dedge_quad), adj_pedges;
       tmp_result = mbImpl->get_adjacencies(dum_quad_range, 1, false, adj_pedges);
       if (MB_SUCCESS != tmp_result) {
         result = tmp_result;
         continue;
       }
         // get the dual 2cells corresponding to those pedges
-      std::vector<MBEntityHandle> dcells;
+      std::vector<EntityHandle> dcells;
       dcells.resize(adj_pedges.size());
       tmp_result = mbImpl->tag_get_data(dualEntity_tag(), adj_pedges, &dcells[0]);
       if (MB_SUCCESS != tmp_result) {
@@ -521,7 +523,7 @@
         continue;
       }
         // now add explicit adjacencies from the dedge to those dcells
-      std::vector<MBEntityHandle>::iterator vit;
+      std::vector<EntityHandle>::iterator vit;
       for (vit = dcells.begin(); vit != dcells.end(); vit++) {
         save_all_2cells.insert(*vit);
         
@@ -532,9 +534,9 @@
           continue;
         }
           // check that there are really adjacencies and *vit is in them
-        const MBEntityHandle *adjs;
+        const EntityHandle *adjs;
         int num_adjs;
-        tmp_result = reinterpret_cast<MBCore*>(mbImpl)->a_entity_factory()->
+        tmp_result = reinterpret_cast<Core*>(mbImpl)->a_entity_factory()->
           get_adjacencies(this_edge, adjs, num_adjs);
         if (NULL == adjs || std::find(adjs, adjs+num_adjs, *vit) == adjs+num_adjs)
           std::cout << "Add_adjacencies failed in construct_dual_faces." << std::endl;
@@ -543,7 +545,7 @@
     else {
         // else, have a dual edge representing a bdy edge - tie directly to
         // dual entity if its dual entity
-      MBEntityHandle bdy_dcell;
+      EntityHandle bdy_dcell;
       tmp_result = mbImpl->tag_get_data(dualEntity_tag(), &dedge_quad, 1, &bdy_dcell); TRC
       assert(MBPOLYGON == mbImpl->type_from_handle(bdy_dcell));
       
@@ -557,9 +559,9 @@
   
 
     // sanity check - look for adj edges again, and check for equiv entities
-  for (MBRange::iterator vit = save_all_2cells.begin(); 
+  for (Range::iterator vit = save_all_2cells.begin(); 
        vit != save_all_2cells.end(); vit++) {
-    MBRange adj_edges, dum_quad_range;
+    Range adj_edges, dum_quad_range;
     dum_quad_range.insert(*vit);
     assert(MBPOLYGON == mbImpl->type_from_handle(*vit));
     tmp_result = mbImpl->get_adjacencies(dum_quad_range, 1, false, adj_edges);
@@ -573,8 +575,8 @@
   return result;
 }
 
-MBErrorCode DualTool::construct_dual_cells(const MBRange &all_verts,
-                                           MBRange &dual_ents) 
+ErrorCode DualTool::construct_dual_cells(const Range &all_verts,
+                                           Range &dual_ents) 
 {
   if (all_verts.empty()) return MB_SUCCESS;
   
@@ -582,12 +584,12 @@
   assert(0 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_verts.begin())) &&
          0 == MBCN::Dimension(TYPE_FROM_HANDLE(*all_verts.rbegin())));
   
-  MBRange::const_iterator rit;
-  MBEntityHandle dual_ent;
+  Range::const_iterator rit;
+  EntityHandle dual_ent;
   unsigned int is_dual = 0x1;
-  MBErrorCode tmp_result = MB_SUCCESS;
-  MBErrorCode result = MB_SUCCESS;
-  std::vector<MBEntityHandle> edges, dfaces;
+  ErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
+  std::vector<EntityHandle> edges, dfaces;
   
   for (rit = all_verts.begin(); rit != all_verts.end(); rit++) {
     if (tmp_result != MB_SUCCESS) result = tmp_result;
@@ -632,14 +634,14 @@
 
   //! given an edge handle, return a list of dual vertices in radial order 
   //! around the edge
-MBErrorCode DualTool::get_radial_dverts(const MBEntityHandle edge,
-                                        std::vector<MBEntityHandle> &rad_dverts,
+ErrorCode DualTool::get_radial_dverts(const EntityHandle edge,
+                                        std::vector<EntityHandle> &rad_dverts,
                                         bool &bdy_edge) 
 {
   rad_dverts.clear();
   
-  std::vector<MBEntityHandle> rad_faces, rad_ents;
-  MBErrorCode result = MeshTopoUtil(mbImpl).star_entities(edge, rad_faces, bdy_edge, 0, 
+  std::vector<EntityHandle> rad_faces, rad_ents;
+  ErrorCode result = MeshTopoUtil(mbImpl).star_entities(edge, rad_faces, bdy_edge, 0, 
                                                           &rad_ents);
   if (MB_SUCCESS != result) return result;
 
@@ -651,7 +653,7 @@
   
   rad_dverts.resize(rad_ents.size());
   for (unsigned int i = 0; i < rad_ents.size(); i++) {
-    MBEntityHandle dual_ent;
+    EntityHandle dual_ent;
     result = mbImpl->tag_get_data(dualEntity_tag(), &rad_ents[i], 1,
                                   &dual_ent);
     if (!bdy_edge || i < rad_ents.size()-2) rad_dverts[i] = dual_ent;
@@ -660,14 +662,14 @@
       assert(mbImpl->type_from_handle(dual_ent) == MBEDGE);
     
         // get connectivity of that edge
-      const MBEntityHandle *connect;
+      const EntityHandle *connect;
       int num_connect;
       result = mbImpl->get_connectivity(dual_ent, connect, num_connect);
       if (MB_SUCCESS != result) return result;
     
         // we want the one that's not already on the list; reuse last_face
       int last_hex = (i == rad_ents.size()-1 ? 0 : i-1);
-      MBEntityHandle last_face = (connect[0] == rad_dverts[last_hex] ? connect[1] : connect[0]);
+      EntityHandle last_face = (connect[0] == rad_dverts[last_hex] ? connect[1] : connect[0]);
       rad_dverts[i] = last_face;
     }
   }
@@ -676,21 +678,21 @@
 }
 
   //! construct the dual entities for a hex mesh, including dual surfaces & curves
-MBErrorCode DualTool::construct_hex_dual(MBRange &entities) 
+ErrorCode DualTool::construct_hex_dual(Range &entities) 
 {
-  std::vector<MBEntityHandle> evec;
+  std::vector<EntityHandle> evec;
   std::copy(entities.begin(), entities.end(), std::back_inserter(evec));
   return construct_hex_dual(&evec[0], evec.size());
 }
   
   //! construct the dual entities for a hex mesh, including dual surfaces & curves
-MBErrorCode DualTool::construct_hex_dual(MBEntityHandle *entities,
+ErrorCode DualTool::construct_hex_dual(EntityHandle *entities,
                                          const int num_entities) 
 {
     // really quite simple: 
 
     // construct the dual...
-  MBErrorCode result = construct_dual(entities, num_entities);
+  ErrorCode result = construct_dual(entities, num_entities);
   if (MB_SUCCESS != result) {
     std::cerr << "Error constructing dual entities for primal entities." << std::endl;
     return result;
@@ -724,21 +726,21 @@
 }
 
   //! get the cells of the dual
-MBErrorCode DualTool::get_dual_entities(const int dim, 
-                                        MBEntityHandle *entities, 
+ErrorCode DualTool::get_dual_entities(const int dim, 
+                                        EntityHandle *entities, 
                                         const int num_entities, 
-                                        MBRange &dual_ents) 
+                                        Range &dual_ents) 
 {
   if (0 == isDualCell_tag()) return MB_SUCCESS;
   if (0 > dim || 3 < dim) return MB_INDEX_OUT_OF_RANGE;
 
   unsigned int dum = 0x1;
   const void *dum_ptr = &dum;
-  static MBEntityType dual_type[] = {MBVERTEX, MBEDGE, MBPOLYGON, MBPOLYHEDRON};
+  static EntityType dual_type[] = {MBVERTEX, MBEDGE, MBPOLYGON, MBPOLYHEDRON};
 
-  MBRange dim_ents;
+  Range dim_ents;
   
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == entities || 0 == num_entities) {
       // just get all the dual entities of this dimension
@@ -749,32 +751,32 @@
   else {
       // else look for specific dual entities
     result = mbImpl->get_adjacencies(entities, num_entities, 3-dim, false,
-                                     dim_ents, MBInterface::UNION);
+                                     dim_ents, Interface::UNION);
     if (MB_SUCCESS != result) return result;
-    std::vector<MBEntityHandle> dual_ents_vec(dim_ents.size());
+    std::vector<EntityHandle> dual_ents_vec(dim_ents.size());
     result = mbImpl->tag_get_data(dualEntity_tag(), dim_ents, &dual_ents_vec[0]);
     if (MB_SUCCESS != result) return result;
     std::copy(dual_ents_vec.begin(), dual_ents_vec.end(), 
-              mb_range_inserter(dual_ents));
+              range_inserter(dual_ents));
   }
   
   return result;
 }
 
   //! get the faces of the dual
-MBErrorCode DualTool::get_dual_entities(const int dim, 
-                                        MBEntityHandle *entities, 
+ErrorCode DualTool::get_dual_entities(const int dim, 
+                                        EntityHandle *entities, 
                                         const int num_entities, 
-                                        std::vector<MBEntityHandle> &dual_ents) 
+                                        std::vector<EntityHandle> &dual_ents) 
 {
-  MBRange tmp_range;
-  MBErrorCode result = get_dual_entities(dim, entities, num_entities, tmp_range);
+  Range tmp_range;
+  ErrorCode result = get_dual_entities(dim, entities, num_entities, tmp_range);
   if (MB_SUCCESS != result)
     return result;
 
     // dual_ents.insert(dual_ents.end(), tmp_range.begin(), tmp_range.end());
   dual_ents.reserve(dual_ents.size() + tmp_range.size());
-  for (MBRange::const_iterator it = tmp_range.begin();
+  for (Range::const_iterator it = tmp_range.begin();
        it != tmp_range.end();
        ++it)
   {
@@ -783,13 +785,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::get_dual_hyperplanes(const MBInterface *impl, const int dim, 
-                                           MBRange &dual_ents) 
+ErrorCode DualTool::get_dual_hyperplanes(const Interface *impl, const int dim, 
+                                           Range &dual_ents) 
 {
   if (dim != 1 && dim != 2) return MB_INDEX_OUT_OF_RANGE;
 
-  MBTag dual_tag;
-  MBErrorCode result;
+  Tag dual_tag;
+  ErrorCode result;
   
   if (dim == 1)
     result = impl->tag_get_handle(DUAL_CURVE_TAG_NAME, dual_tag );
@@ -798,13 +800,13 @@
 
   if (MB_SUCCESS == result)
     result = impl->get_entities_by_type_and_tag(0, MBENTITYSET, &dual_tag, NULL, 1, dual_ents,
-                                                MBInterface::UNION);
+                                                Interface::UNION);
       
   return result;
 }
 
-MBErrorCode DualTool::construct_dual_hyperplanes(const int dim, 
-                                                 MBEntityHandle *entities, 
+ErrorCode DualTool::construct_dual_hyperplanes(const int dim, 
+                                                 EntityHandle *entities, 
                                                  const int num_entities) 
 {
     // this function traverses dual faces of input dimension, constructing
@@ -825,17 +827,17 @@
     return MB_FAILURE;
   
     // get tag name for this dimension hyperplane
-  MBTag gid_tag;
+  Tag gid_tag;
   int dum = -1;
-  MBErrorCode result = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, gid_tag);
+  ErrorCode result = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, gid_tag);
   if (MB_SUCCESS != result) result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, 4, 
                                                         MB_TAG_DENSE, gid_tag, &dum);
 
-  MBTag hp_tag = (1 == dim ? dualCurve_tag() : dualSurface_tag());
+  Tag hp_tag = (1 == dim ? dualCurve_tag() : dualSurface_tag());
   
     // two stacks: one completely untreated entities, and the other untreated 
     // entities on the current dual hyperplane
-  std::vector<MBEntityHandle> tot_untreated;
+  std::vector<EntityHandle> tot_untreated;
   
     // put dual entities of this dimension on the untreated list
   result = get_dual_entities(dim, entities, num_entities, tot_untreated);
@@ -843,9 +845,9 @@
     return result;
   
     // main part of traversal loop
-  MBEntityHandle this_ent;
-  MBEntityHandle this_hp;
-  std::vector<MBEntityHandle> parents;
+  EntityHandle this_ent;
+  EntityHandle this_hp;
+  std::vector<EntityHandle> parents;
 
   while (!tot_untreated.empty()) {
     if (debug && dim == 2 /*(tot_untreated.size()%report == 0)*/)
@@ -856,7 +858,7 @@
     if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) 
       return result;
 
-      // test for this entity having a hyperplane assignment already
+      // d for this entity having a hyperplane assignment already
     else if (this_hp != 0)
       continue;
 
@@ -878,19 +880,19 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::traverse_hyperplane(const MBTag hp_tag, 
-                                          MBEntityHandle &this_hp, 
-                                          MBEntityHandle this_ent) 
+ErrorCode DualTool::traverse_hyperplane(const Tag hp_tag, 
+                                          EntityHandle &this_hp, 
+                                          EntityHandle this_ent) 
 {
-  MBRange tmp_star, star, tmp_range, new_hyperplane_ents;
-  std::vector<MBEntityHandle> hp_untreated;
+  Range tmp_star, star, tmp_range, new_hyperplane_ents;
+  std::vector<EntityHandle> hp_untreated;
   int dim = mbImpl->dimension_from_handle(this_ent);
   MeshTopoUtil mtu(mbImpl);
   this_hp = 0;
-  MBErrorCode result;
+  ErrorCode result;
   
   unsigned short mark_val = 0x0;
-  MBTag mark_tag;
+  Tag mark_tag;
   result = mbImpl->tag_get_handle("__hyperplane_mark", mark_tag);
   if (MB_SUCCESS != result) {
     result = mbImpl->tag_create("__hyperplane_mark", 1, 
@@ -901,7 +903,7 @@
   mark_val = 0x1;
   
   while (0 != this_ent) {
-    MBEntityHandle tmp_hp = get_dual_hyperplane(this_ent);
+    EntityHandle tmp_hp = get_dual_hyperplane(this_ent);
     if (0 == this_hp && 0 != tmp_hp) this_hp = tmp_hp;
     
     if (0 == tmp_hp) new_hyperplane_ents.insert(this_ent);
@@ -918,7 +920,7 @@
     result = mtu.get_bridge_adjacencies(this_ent, dim+1, dim, tmp_star); RR;
     tmp_range = subtract( star, tmp_star);
     
-    for (MBRange::iterator rit = tmp_range.begin(); rit != tmp_range.end(); rit++) {
+    for (Range::iterator rit = tmp_range.begin(); rit != tmp_range.end(); rit++) {
       if (new_hyperplane_ents.find(*rit) != new_hyperplane_ents.end()) continue;
       
         // check for tag first, 'cuz it's probably faster than checking adjacencies
@@ -960,10 +962,10 @@
     }
     if (dim == 2) std::cout << "edges:" << std::endl;
     else std::cout << "quads:" << std::endl;
-    std::vector<MBEntityHandle> pents(new_hyperplane_ents.size());
+    std::vector<EntityHandle> pents(new_hyperplane_ents.size());
     result = mbImpl->tag_get_data(dualEntity_tag(), new_hyperplane_ents,
                                   &pents[0]); RR;
-    for (std::vector<MBEntityHandle>::iterator vit = pents.begin(); 
+    for (std::vector<EntityHandle>::iterator vit = pents.begin(); 
          vit != pents.end(); vit++) {
       if (vit != pents.begin()) std::cout << ", ";
       std::cout << mbImpl->id_from_handle(*vit);
@@ -986,7 +988,7 @@
   }
 
     // set the hp_val for entities which didn't have one before
-  std::vector<MBEntityHandle> hp_tags(new_hyperplane_ents.size());
+  std::vector<EntityHandle> hp_tags(new_hyperplane_ents.size());
   std::fill(hp_tags.begin(), hp_tags.end(), this_hp);
   result = mbImpl->tag_set_data(hp_tag, new_hyperplane_ents, &hp_tags[0]);
   if (MB_SUCCESS != result) 
@@ -1003,19 +1005,19 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::order_chord(MBEntityHandle chord_set) 
+ErrorCode DualTool::order_chord(EntityHandle chord_set) 
 {
     // re-order the 1cells in the set so they are in order along the chord
     // start by finding the vertex dual to a quad
-  MBRange verts, one_cells;
-  MBErrorCode result = mbImpl->get_entities_by_dimension(chord_set, 1, one_cells); 
+  Range verts, one_cells;
+  ErrorCode result = mbImpl->get_entities_by_dimension(chord_set, 1, one_cells); 
   if (MB_SUCCESS != result || one_cells.empty()) return MB_FAILURE;
   
-  result = mbImpl->get_adjacencies(one_cells, 0, false, verts, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(one_cells, 0, false, verts, Interface::UNION);
   if (MB_SUCCESS != result || verts.empty()) return MB_FAILURE;
   
-  MBEntityHandle last_vert = 0;
-  for (MBRange::iterator rit = verts.begin(); rit != verts.end(); rit++) {
+  EntityHandle last_vert = 0;
+  for (Range::iterator rit = verts.begin(); rit != verts.end(); rit++) {
     if (TYPE_FROM_HANDLE(get_dual_entity(*rit)) == MBQUAD) {
       last_vert = *rit;
       break;
@@ -1025,12 +1027,12 @@
   if (0 == last_vert) last_vert = *verts.begin();
   
     // now, skip from vertex to vertex, building a list of 1cells
-  std::vector<MBEntityHandle> ordered_1cells;
-  MBEntityHandle last_1cell = 0;
-  MBRange dum1, dum2;
-  const MBEntityHandle *connect;
+  std::vector<EntityHandle> ordered_1cells;
+  EntityHandle last_1cell = 0;
+  Range dum1, dum2;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode tmp_result = MB_SUCCESS;
   while(ordered_1cells.size() != one_cells.size()) {
     dum1 = one_cells;
     result = mbImpl->get_adjacencies(&last_vert, 1, 1, false, dum1);
@@ -1057,11 +1059,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::construct_new_hyperplane(const int dim,
-                                               MBEntityHandle &new_hyperplane,
+ErrorCode DualTool::construct_new_hyperplane(const int dim,
+                                               EntityHandle &new_hyperplane,
                                                int &id) 
 {
-  MBErrorCode result;
+  ErrorCode result;
   if (1 == dim)
     result = mbImpl->create_meshset((MESHSET_ORDERED | MESHSET_TRACK_OWNER), 
                                     new_hyperplane);
@@ -1071,7 +1073,7 @@
   if (MB_SUCCESS != result) return result;
 
   if (-1 == id) {
-    MBRange all_hyperplanes;
+    Range all_hyperplanes;
     result = get_dual_hyperplanes(mbImpl, dim, all_hyperplanes); RR;
     std::vector<int> gids(all_hyperplanes.size());
     result = mbImpl->tag_get_data(globalIdTag, all_hyperplanes, &gids[0]); RR;
@@ -1082,7 +1084,7 @@
   }
     
   result = mbImpl->tag_set_data(globalId_tag(), &new_hyperplane, 1, &id); RR;
-  MBTag hp_tag = (1 == dim ? dualCurve_tag() : dualSurface_tag());
+  Tag hp_tag = (1 == dim ? dualCurve_tag() : dualSurface_tag());
   result = mbImpl->tag_set_data(hp_tag, &new_hyperplane, 1, &new_hyperplane);
 
     // assign a category name to these sets
@@ -1094,18 +1096,18 @@
   return result;
 }
 
-bool DualTool::check_1d_loop_edge(MBEntityHandle this_ent) 
+bool DualTool::check_1d_loop_edge(EntityHandle this_ent) 
 {
     // make sure it's an edge
   if (MBEDGE != mbImpl->type_from_handle(this_ent)) return false;
 
     // also has to be a dual entity
   unsigned int dum;
-  MBErrorCode result = mbImpl->tag_get_data(isDualCell_tag(), &this_ent, 1, &dum);
+  ErrorCode result = mbImpl->tag_get_data(isDualCell_tag(), &this_ent, 1, &dum);
   if (MB_SUCCESS != result || dum != 0x1) return false;
   
-  const MBEntityHandle *verts;
-  MBEntityHandle vert_tags[2];
+  const EntityHandle *verts;
+  EntityHandle vert_tags[2];
   int num_verts;
   result = mbImpl->get_connectivity(this_ent, verts, num_verts);
   if (MB_SUCCESS != result) return false;
@@ -1118,21 +1120,21 @@
   else return true;
 }
 
-MBErrorCode DualTool::construct_hp_parent_child() 
+ErrorCode DualTool::construct_hp_parent_child() 
 {
-  MBRange dual_surfs, dual_cells, dual_edges;
-  MBErrorCode result = this->get_dual_hyperplanes(mbImpl, 2, dual_surfs);
+  Range dual_surfs, dual_cells, dual_edges;
+  ErrorCode result = this->get_dual_hyperplanes(mbImpl, 2, dual_surfs);
   if (MB_SUCCESS != result || dual_surfs.empty()) return result;
-  std::vector<MBEntityHandle> dual_curve_sets;
+  std::vector<EntityHandle> dual_curve_sets;
   
-  for (MBRange::iterator surf_it = dual_surfs.begin(); surf_it != dual_surfs.end();
+  for (Range::iterator surf_it = dual_surfs.begin(); surf_it != dual_surfs.end();
        surf_it++) {
       // get all the cells, edges in those cells, and chords for those edges
     dual_cells.clear();
     result = mbImpl->get_entities_by_handle(*surf_it, dual_cells);
     if (MB_SUCCESS != result) return result;
     dual_edges.clear();
-    result = mbImpl->get_adjacencies(dual_cells, 1, false, dual_edges, MBInterface::UNION);
+    result = mbImpl->get_adjacencies(dual_cells, 1, false, dual_edges, Interface::UNION);
     if (MB_SUCCESS != result) return result;
     dual_curve_sets.reserve(dual_edges.size());
     result = mbImpl->tag_get_data(dualCurve_tag(), dual_edges, &dual_curve_sets[0]);
@@ -1144,7 +1146,7 @@
       if (dual_curve_sets[i] != 0) dual_cells.insert(dual_curve_sets[i]);
     
       // now connect up this dual surf with all the 1d ones
-    for (MBRange::iterator rit = dual_cells.begin(); rit != dual_cells.end(); rit++) {
+    for (Range::iterator rit = dual_cells.begin(); rit != dual_cells.end(); rit++) {
       result = mbImpl->add_parent_child(*surf_it, *rit);
       if (MB_SUCCESS != result) return result;
     }
@@ -1153,7 +1155,7 @@
   return MB_SUCCESS;
 }
     
-MBErrorCode DualTool::get_graphics_points(MBEntityHandle dual_ent,
+ErrorCode DualTool::get_graphics_points(EntityHandle dual_ent,
                                           std::vector<int> &npts,
                                           std::vector<GraphicsPoint> &points) 
 {
@@ -1163,7 +1165,7 @@
     // get the graphics points comprising the given entity
   GraphicsPoint gp_array[DualTool::GP_SIZE];
 
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
     // switch based on topological dimension
   switch (mbImpl->dimension_from_handle(dual_ent)) {
@@ -1178,7 +1180,7 @@
 
     case 1:
         // get my graphics point then those of my vertices
-      const MBEntityHandle *connect;
+      const EntityHandle *connect;
       int num_connect;
       result = mbImpl->get_connectivity(dual_ent, connect, num_connect);
       if (MB_SUCCESS != result) break;
@@ -1206,18 +1208,18 @@
   return result;
 }
 
-MBErrorCode DualTool::get_cell_points(MBEntityHandle dual_ent,
+ErrorCode DualTool::get_cell_points(EntityHandle dual_ent,
                                       std::vector<int> &npts,
                                       std::vector<GraphicsPoint> &points) 
 {
   assert(MBPOLYGON == mbImpl->type_from_handle(dual_ent));
   
     // get the 1cells in this 2cell
-  MBRange one_cells;
+  Range one_cells;
   
-  MBRange tc_range; tc_range.insert(dual_ent);
-  MBErrorCode result = mbImpl->get_adjacencies(tc_range, 1, false, one_cells, 
-                                               MBInterface::UNION); RR;
+  Range tc_range; tc_range.insert(dual_ent);
+  ErrorCode result = mbImpl->get_adjacencies(tc_range, 1, false, one_cells, 
+                                               Interface::UNION); RR;
 
   int num_edges = one_cells.size();
   std::vector<GraphicsPoint> dum_gps(num_edges+1);
@@ -1228,8 +1230,8 @@
   result = mbImpl->tag_get_data(dualGraphicsPoint_tag(), &dual_ent, 1,
                                 &(dum_gps[num_edges])); RR;
 
-  MBRange::iterator eit;
-  const MBEntityHandle *connect;
+  Range::iterator eit;
+  const EntityHandle *connect;
   int num_connect;
   GraphicsPoint vert_gps[2];
   int i;
@@ -1255,27 +1257,27 @@
   return result;
 }
 
-MBErrorCode DualTool::get_graphics_points(const MBRange &in_range,
+ErrorCode DualTool::get_graphics_points(const Range &in_range,
                                           std::vector<GraphicsPoint> &points,
                                           const bool assign_ids,
                                           const int start_id) 
 {
     // return graphics points on dual entities in in_range or in entities
     // in sets in in_range
-  MBErrorCode result;
+  ErrorCode result;
 
     // for each dual hyperplane set:
-  MBRange::const_iterator rit;
+  Range::const_iterator rit;
   
-  MBRange two_cells, all_cells;
+  Range two_cells, all_cells;
   for (rit = in_range.begin(); rit != in_range.end(); rit++) {
       // for each entity:
     two_cells.clear();
-    MBEntityType this_type = mbImpl->type_from_handle(*rit);
+    EntityType this_type = mbImpl->type_from_handle(*rit);
     if (MBENTITYSET == this_type) {
       result = mbImpl->get_entities_by_handle(*rit, two_cells); RR;
     
-      std::copy(two_cells.begin(), two_cells.end(), mb_range_inserter(all_cells));
+      std::copy(two_cells.begin(), two_cells.end(), range_inserter(all_cells));
     }
     
     else {
@@ -1285,9 +1287,9 @@
     }
 
     result = mbImpl->get_adjacencies(two_cells, 0, false, all_cells, 
-                                     MBInterface::UNION); RR;
+                                     Interface::UNION); RR;
     result = mbImpl->get_adjacencies(two_cells, 1, false, all_cells, 
-                                     MBInterface::UNION); RR;
+                                     Interface::UNION); RR;
   }
       
       // get graphics points
@@ -1310,9 +1312,9 @@
   return result;
 }
 
-MBEntityHandle DualTool::next_loop_vertex(const MBEntityHandle last_v,
-                                          const MBEntityHandle this_v,
-                                          const MBEntityHandle dual_surf)
+EntityHandle DualTool::next_loop_vertex(const EntityHandle last_v,
+                                          const EntityHandle this_v,
+                                          const EntityHandle dual_surf)
 {
     // given two vertices, find the next one on the loop; if one is a dual
     // surface, then just choose either one for that surface
@@ -1322,13 +1324,13 @@
 
     // get the connected vertices
   MeshTopoUtil tpu(mbImpl);
-  MBRange other_verts;
-  MBErrorCode result = tpu.get_bridge_adjacencies(this_v, 1, 0, other_verts);
+  Range other_verts;
+  ErrorCode result = tpu.get_bridge_adjacencies(this_v, 1, 0, other_verts);
   if (MB_SUCCESS != result || other_verts.empty()) return 0;
   
     //if (mbImpl->type_from_handle(last_v) == MBENTITYSET) {
       // dual surface, choose either; first get a 2cell on this surface
-  MBRange tcells, tcells2, verts;
+  Range tcells, tcells2, verts;
   result = mbImpl->get_entities_by_type(dual_surf, MBPOLYGON, tcells);
   if (MB_SUCCESS != result || tcells.empty()) return 0;
 
@@ -1343,14 +1345,14 @@
   result = mbImpl->get_adjacencies(tcells, 0, false, verts);
   if (MB_SUCCESS != result || verts.empty()) return 0;
   
-  MBRange tmp_verts = subtract( other_verts, verts);
+  Range tmp_verts = subtract( other_verts, verts);
   other_verts.swap(tmp_verts);
   if (0 != last_v) other_verts.erase(last_v);
 
     // now get intersection of remaining vertices and 2 2cells vertices
     // look at each one successively; should find one, maybe not on both
   tmp_verts = other_verts;
-  MBRange tmp_faces(*tcells.begin(), *tcells.begin());
+  Range tmp_faces(*tcells.begin(), *tcells.begin());
   result = mbImpl->get_adjacencies(tmp_faces, 0, false, tmp_verts);
   if (MB_SUCCESS == result && !tmp_verts.empty()) return *tmp_verts.begin();
   tmp_faces.clear();
@@ -1362,15 +1364,15 @@
   return 0;
 }
 
-MBEntityHandle DualTool::get_dual_hyperplane(const MBEntityHandle ncell) 
+EntityHandle DualTool::get_dual_hyperplane(const EntityHandle ncell) 
 {
     // get the sheet or chord it's in
-  std::vector<MBEntityHandle> adj_sets;
-  MBErrorCode result = mbImpl->get_adjacencies(&ncell, 1, 4, false, adj_sets);
+  std::vector<EntityHandle> adj_sets;
+  ErrorCode result = mbImpl->get_adjacencies(&ncell, 1, 4, false, adj_sets);
   if (MB_SUCCESS != result) return 0;
     
-  MBEntityHandle dum_set;
-  for (std::vector<MBEntityHandle>::iterator vit = adj_sets.begin(); 
+  EntityHandle dum_set;
+  for (std::vector<EntityHandle>::iterator vit = adj_sets.begin(); 
        vit != adj_sets.end(); vit++) {
     if (mbImpl->tag_get_data(dualCurve_tag(), &(*vit), 1, &dum_set) != MB_TAG_NOT_FOUND ||
         mbImpl->tag_get_data(dualSurface_tag(), &(*vit), 1, &dum_set) != MB_TAG_NOT_FOUND)
@@ -1381,8 +1383,8 @@
 }
 
     //! set the dual surface or curve for an entity
-MBErrorCode DualTool::set_dual_surface_or_curve(MBEntityHandle entity, 
-                                                const MBEntityHandle dual_hyperplane,
+ErrorCode DualTool::set_dual_surface_or_curve(EntityHandle entity, 
+                                                const EntityHandle dual_hyperplane,
                                                 const int dual_entity_dimension)
 {
   if (1 == dual_entity_dimension)
@@ -1396,33 +1398,33 @@
 }
 
 //! return the corresponding dual entity
-MBEntityHandle DualTool::get_dual_entity(const MBEntityHandle this_ent) const
+EntityHandle DualTool::get_dual_entity(const EntityHandle this_ent) const
 {
-  MBEntityHandle dual_ent;
-  MBErrorCode result = mbImpl->tag_get_data(dualEntity_tag(), &this_ent, 1, &dual_ent);
+  EntityHandle dual_ent;
+  ErrorCode result = mbImpl->tag_get_data(dualEntity_tag(), &this_ent, 1, &dual_ent);
   if (MB_SUCCESS != result || MB_TAG_NOT_FOUND == result) return 0;
   else return dual_ent;
 }
 
 //! return the corresponding dual entity
-MBEntityHandle DualTool::get_extra_dual_entity(const MBEntityHandle this_ent) 
+EntityHandle DualTool::get_extra_dual_entity(const EntityHandle this_ent) 
 {
-  MBEntityHandle dual_ent;
-  MBErrorCode result = mbImpl->tag_get_data(extraDualEntity_tag(), &this_ent, 1, &dual_ent);
+  EntityHandle dual_ent;
+  ErrorCode result = mbImpl->tag_get_data(extraDualEntity_tag(), &this_ent, 1, &dual_ent);
   if (MB_SUCCESS != result || MB_TAG_NOT_FOUND == result) return 0;
   else return dual_ent;
 }
 
-MBErrorCode DualTool::atomic_pillow(MBEntityHandle odedge, MBEntityHandle &quad1,
-                                    MBEntityHandle &quad2) 
+ErrorCode DualTool::atomic_pillow(EntityHandle odedge, EntityHandle &quad1,
+                                    EntityHandle &quad2) 
 {
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
   if (debug_ap) {
-    MBRange sets;
-    MBTag ms_tag;
+    Range sets;
+    Tag ms_tag;
     
-    MBErrorCode result = mbImpl->tag_get_handle("MATERIAL_SET", ms_tag);
+    ErrorCode result = mbImpl->tag_get_handle("MATERIAL_SET", ms_tag);
     if (MB_SUCCESS == result) {
       result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &ms_tag, NULL,
                                                     1, sets);
@@ -1443,10 +1445,10 @@
     // those 2cells (going to delete the 2cells, therefore need to delete the 3cells
     // that depend on those too)
   MeshTopoUtil mtu(mbImpl);
-  MBRange star_cells, tmp_cells;
-  MBErrorCode result = mbImpl->get_adjacencies(&odedge, 1, 2, false, star_cells); RR;
+  Range star_cells, tmp_cells;
+  ErrorCode result = mbImpl->get_adjacencies(&odedge, 1, 2, false, star_cells); RR;
   result = mbImpl->get_adjacencies(star_cells, 3, false, tmp_cells,
-                                   MBInterface::UNION); RR;
+                                   Interface::UNION); RR;
   star_cells.merge(tmp_cells);
   star_cells.insert(odedge);
   
@@ -1454,7 +1456,7 @@
   result = delete_dual_entities(star_cells); RR;
 
     // now change the quad to an ap
-  std::vector<MBEntityHandle> verts;
+  std::vector<EntityHandle> verts;
   result = mbImpl->get_connectivity(&quad1, 1, verts); RR;
   
     // get average position of vertices
@@ -1480,7 +1482,7 @@
   }
 
     // get the hexes connected to the quad
-  MBRange hexes;
+  Range hexes;
   result = mbImpl->get_adjacencies(&quad1, 1, 3, false, hexes); RR;
   assert(hexes.size() <= 2);
   
@@ -1493,7 +1495,7 @@
   
     // create the new, inner quad, and make it explicitly adjacent to 1st hex;
     // make the connectivity of this quad same as the original one
-  std::vector<MBEntityHandle> tmp_verts;
+  std::vector<EntityHandle> tmp_verts;
   std::copy(verts.begin(), verts.end(), std::back_inserter(tmp_verts));
   
   result = mbImpl->create_element(MBQUAD, &tmp_verts[0], 4, quad2); RR;
@@ -1504,7 +1506,7 @@
   std::reverse(verts.begin()+4, verts.end());
 
     // now make two inner hexes; note connectivity array is flipped for the two hexes
-  MBEntityHandle new_hexes[2];
+  EntityHandle new_hexes[2];
   result = mbImpl->create_element(MBHEX, &verts[0], 8, new_hexes[0]); RR;
   result = mbImpl->create_element(MBHEX, &tmp_verts[0], 8, new_hexes[1]); RR;
 
@@ -1517,14 +1519,14 @@
   result = mbImpl->add_adjacencies(quad1, &new_hexes[0], 1, false); RR;
   result = mbImpl->add_adjacencies(quad2, &new_hexes[1], 1, false); RR;
 
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // now update the dual
   result = construct_hex_dual(&new_hexes[0], 2); RR;
 
     // get the new dual surface, by getting one of the edges between the center
     // and outer vertex rings
-  MBRange new_edge;
+  Range new_edge;
   verts[1] = verts[4];
   result = mbImpl->get_adjacencies(&verts[0], 2, 1, false, new_edge);
   if (MB_SUCCESS != result || new_edge.size() != 1) return result;
@@ -1533,32 +1535,32 @@
 }
 
   //! effect reverse atomic pillow operation
-MBErrorCode DualTool::rev_atomic_pillow(MBEntityHandle pillow, MBRange &chords) 
+ErrorCode DualTool::rev_atomic_pillow(EntityHandle pillow, Range &chords) 
 {
     // get the dual entities associated with elements in the pillow; go through
     // the elements instead of the pillow sheet so you get all of them, not just
     // the ones on the sheet
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
   std::cout << "-AP("; print_cell(pillow); std::cout << ")" << std::endl;
 
-  MBRange dverts;
-  MBErrorCode result = get_dual_entities(pillow, NULL, NULL,
+  Range dverts;
+  ErrorCode result = get_dual_entities(pillow, NULL, NULL,
                                          &dverts, NULL, NULL);
   if (MB_SUCCESS != result) return result;
   assert(2 == dverts.size());
   
-  MBEntityHandle hexes[2];
+  EntityHandle hexes[2];
   result = mbImpl->tag_get_data(dualEntity_tag(), dverts, hexes); RR;
   assert(hexes[0] != 0 && hexes[1] != 0);
 
-  std::vector<MBEntityHandle> dcells[4];
-  MBRange pcells[4];
-  std::copy(hexes, hexes+2, mb_range_inserter(pcells[3]));
+  std::vector<EntityHandle> dcells[4];
+  Range pcells[4];
+  std::copy(hexes, hexes+2, range_inserter(pcells[3]));
   std::copy(dverts.begin(), dverts.end(), std::back_inserter(dcells[0]));
   for (int dim = 0; dim <= 2; dim++) {
     result = mbImpl->get_adjacencies(hexes, 2, dim, false, pcells[dim], 
-                                     MBInterface::UNION); RR;
+                                     Interface::UNION); RR;
     dcells[3-dim].resize(pcells[dim].size());
     result = mbImpl->tag_get_data(dualEntity_tag(), pcells[dim], &dcells[3-dim][0]); RR;
   }
@@ -1576,19 +1578,19 @@
 
     // delete the primal entities inserted by the ap; be careful to get the right
     // faces, edges and vertices
-  MBRange del_faces, del_edges, del_verts, tmp_faces, tmp_verts;
+  Range del_faces, del_edges, del_verts, tmp_faces, tmp_verts;
     // faces are the shared 5 and the 1 other one with greater handle (which
     // we know will be later in the range)
   result = mbImpl->get_adjacencies(hexes, 2, 2, false, del_faces); RR;
   assert(5 == del_faces.size());
-  std::copy(pcells[2].begin(), pcells[2].end(), mb_range_inserter(tmp_faces));
+  std::copy(pcells[2].begin(), pcells[2].end(), range_inserter(tmp_faces));
   tmp_faces = subtract( tmp_faces, del_faces);
   del_faces.insert(*tmp_faces.rbegin());
   result = mbImpl->get_adjacencies(tmp_faces, 0, false, tmp_verts); RR;
-  std::copy(pcells[0].begin(), pcells[0].end(), mb_range_inserter(del_verts));
+  std::copy(pcells[0].begin(), pcells[0].end(), range_inserter(del_verts));
   del_verts = subtract( del_verts, tmp_verts);
   assert(4 == del_verts.size());
-  result = mbImpl->get_adjacencies(del_verts, 1, false, del_edges, MBInterface::UNION); RR;
+  result = mbImpl->get_adjacencies(del_verts, 1, false, del_edges, Interface::UNION); RR;
   assert(8 == del_edges.size());
   
   result = mbImpl->delete_entities(hexes, 2); RR;
@@ -1596,42 +1598,42 @@
   result = mbImpl->delete_entities(del_edges); RR;
   result = mbImpl->delete_entities(del_verts); RR;
 
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // recompute the dual for the hexes on either side of the quad affected
     // by the ap removal
-  MBRange tmp_hexes;
-  result = mbImpl->get_adjacencies(tmp_verts, 3, false, tmp_hexes, MBInterface::UNION); RR;
+  Range tmp_hexes;
+  result = mbImpl->get_adjacencies(tmp_verts, 3, false, tmp_hexes, Interface::UNION); RR;
   result = construct_hex_dual(tmp_hexes); RR;
 
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::delete_dual_entities(MBEntityHandle *entities,
+ErrorCode DualTool::delete_dual_entities(EntityHandle *entities,
                                            int num_entities) 
 {
-  MBRange tmp_ents;
-  std::copy(entities, entities+num_entities, mb_range_inserter(tmp_ents));
+  Range tmp_ents;
+  std::copy(entities, entities+num_entities, range_inserter(tmp_ents));
   return delete_dual_entities(tmp_ents);
 }
   
-MBErrorCode DualTool::delete_dual_entities(MBRange &entities) 
+ErrorCode DualTool::delete_dual_entities(Range &entities) 
 {
   if (entities.empty()) return delete_whole_dual();
   
-  MBEntityHandle null_entity = 0;
-  MBErrorCode result;
-  MBRange ents_to_delete;
+  EntityHandle null_entity = 0;
+  ErrorCode result;
+  Range ents_to_delete;
   
   while (!entities.empty()) {
-    MBEntityHandle this_entity = entities.pop_back();
+    EntityHandle this_entity = entities.pop_back();
     
       // reset the primal's dual entity
-    MBEntityHandle primal = get_dual_entity(this_entity);
+    EntityHandle primal = get_dual_entity(this_entity);
     if (get_dual_entity(primal) == this_entity) {
       result = mbImpl->tag_set_data(dualEntity_tag(), &primal, 1, &null_entity); RR;
     }
-    MBEntityHandle extra = get_extra_dual_entity(primal);
+    EntityHandle extra = get_extra_dual_entity(primal);
     if (0 != extra) {
       result = mbImpl->tag_set_data(extraDualEntity_tag(), &primal, 1, &null_entity); RR;
     }
@@ -1641,9 +1643,9 @@
       // check for extra dual entities
     if (mbImpl->type_from_handle(this_entity) == MBPOLYGON) {
       // for 2cell, might be a loop edge
-      MBRange loop_edges;
+      Range loop_edges;
       result = mbImpl->get_adjacencies(&this_entity, 1, 1, false, loop_edges);
-      for (MBRange::iterator rit = loop_edges.begin(); rit != loop_edges.end(); rit++)
+      for (Range::iterator rit = loop_edges.begin(); rit != loop_edges.end(); rit++)
         if (check_1d_loop_edge(*rit)) entities.insert(*rit);
     }
     else if (extra && extra != this_entity)
@@ -1656,14 +1658,14 @@
   return mbImpl->delete_entities(ents_to_delete);
 }
 
-void DualTool::print_cell(MBEntityHandle cell) 
+void DualTool::print_cell(EntityHandle cell) 
 {
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode result = mbImpl->get_connectivity(cell, connect, num_connect);
+  ErrorCode result = mbImpl->get_connectivity(cell, connect, num_connect);
   if (MB_SUCCESS != result) return;
   bool first = true;
-  MBEntityHandle primals[20];
+  EntityHandle primals[20];
   std::vector<int> ids;
   
   assert(num_connect < 20);
@@ -1673,7 +1675,7 @@
                              num_connect, &ids[0]);
   for (int i = 0; i < num_connect; i++) {
     if (!first) std::cout << "-";
-    MBEntityType this_type = mbImpl->type_from_handle(primals[i]);
+    EntityType this_type = mbImpl->type_from_handle(primals[i]);
     if (this_type == MBHEX) std::cout << "h";
     else if (this_type == MBQUAD) std::cout << "f";
     else std::cout << "u";
@@ -1685,9 +1687,9 @@
   }
 }
 
-MBErrorCode DualTool::face_open_collapse(MBEntityHandle ocl, MBEntityHandle ocr) 
+ErrorCode DualTool::face_open_collapse(EntityHandle ocl, EntityHandle ocr) 
 {
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
   MeshTopoUtil mtu(mbImpl);
 
@@ -1695,14 +1697,14 @@
   std::cout << ")" << std::endl;
 
     // get the primal entities we're dealing with
-  MBEntityHandle split_quads[2] = {0}, 
+  EntityHandle split_quads[2] = {0}, 
     split_edges[3] = {0}, split_nodes[2] = {0}, other_edges[6] = {0}, other_nodes[6] = {0};
-  MBRange hexes;
-  MBErrorCode result = foc_get_ents(ocl, ocr, split_quads, split_edges, split_nodes,
+  Range hexes;
+  ErrorCode result = foc_get_ents(ocl, ocr, split_quads, split_edges, split_nodes,
                                     hexes, other_edges, other_nodes); RR;
 
     // get star entities around edges, separated into halves
-  std::vector<MBEntityHandle> star_dp1[2], star_dp2[2];
+  std::vector<EntityHandle> star_dp1[2], star_dp2[2];
   result = foc_get_stars(split_quads, split_edges, star_dp1, star_dp2); RR;
 
   if (MBQUAD != mbImpl->type_from_handle(split_quads[0]) ||
@@ -1712,7 +1714,7 @@
   result = foc_delete_dual(split_quads, split_edges, hexes);
   if (MB_SUCCESS != result) return result;
 
-  MBEntityHandle new_quads[2], new_edges[3], new_nodes[2];
+  EntityHandle new_quads[2], new_edges[3], new_nodes[2];
   result = split_pair_nonmanifold(split_quads, split_edges, split_nodes, 
                                   star_dp1, star_dp2,
                                   other_edges, other_nodes, 
@@ -1720,7 +1722,7 @@
   if (MB_SUCCESS != result) return result;
 
     // now merge entities, the C of foc
-  MBEntityHandle keepit, deleteit;
+  EntityHandle keepit, deleteit;
 #define MIN(a,b) (a < b ? a : b)  
 #define MAX(a,b) (a > b ? a : b)  
 #define KEEP_DELETE(a,b,c,d) {c = MIN(a,b); d = MAX(a,b);}
@@ -1747,7 +1749,7 @@
   
   result = mbImpl->merge_entities(new_quads[0], new_quads[1], false, true); RR;
   
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // reconstruct dual
   result = construct_hex_dual(hexes); 
@@ -1757,14 +1759,14 @@
   
 }
 
-MBErrorCode DualTool::foc_get_ents(MBEntityHandle ocl, 
-                                   MBEntityHandle ocr, 
-                                   MBEntityHandle *split_quads, 
-                                   MBEntityHandle *split_edges, 
-                                   MBEntityHandle *split_nodes, 
-                                   MBRange &hexes, 
-                                   MBEntityHandle *other_edges, 
-                                   MBEntityHandle *other_nodes)
+ErrorCode DualTool::foc_get_ents(EntityHandle ocl, 
+                                   EntityHandle ocr, 
+                                   EntityHandle *split_quads, 
+                                   EntityHandle *split_edges, 
+                                   EntityHandle *split_nodes, 
+                                   Range &hexes, 
+                                   EntityHandle *other_edges, 
+                                   EntityHandle *other_nodes)
 {
     // get the entities used for foc; ocl and ocr are dual 1-cells 
     // representing quads to be split; returned from this function:
@@ -1790,8 +1792,8 @@
       MBQUAD != mbImpl->type_from_handle(split_quads[1]))
     return MB_TYPE_OUT_OF_RANGE;
 
-  MBRange common_edges;
-  MBErrorCode result = mbImpl->get_adjacencies(split_quads, 2, 1, false, 
+  Range common_edges;
+  ErrorCode result = mbImpl->get_adjacencies(split_quads, 2, 1, false, 
                                                common_edges);
   if (MB_SUCCESS != result) return result;
   
@@ -1804,7 +1806,7 @@
   if (common_edges.size() == 3) {
       // find other (non-shared) edges
     for (int i = 0; i < 2; i++) {
-      MBRange tmp_edges;
+      Range tmp_edges;
       result = mbImpl->get_adjacencies(&split_quads[i], 1, 1, false, 
                                        tmp_edges);
       if (MB_SUCCESS != result) return result;
@@ -1857,7 +1859,7 @@
     }
   }
   else {
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
     result = mbImpl->get_connectivity(split_edges[0], connect, num_connect);
     if (MB_SUCCESS != result) return result;
@@ -1869,7 +1871,7 @@
     for (int i = 0; i < 2; i++) {
         // get the other edge on the split quad adj to node 0 on the split edge, by getting
         // edges adj to split quad and node and removing split edge; that's other_edge[i]
-      MBRange tmp_range1, tmp_range2;
+      Range tmp_range1, tmp_range2;
       tmp_range1.insert(connect[0]);
       tmp_range1.insert(split_quads[i]);
       result = mbImpl->get_adjacencies(tmp_range1, 1, false, tmp_range2);
@@ -1893,7 +1895,7 @@
   }
 
   result = mbImpl->get_adjacencies(split_edges, common_edges.size(), 3, false, 
-                                   hexes, MBInterface::UNION);
+                                   hexes, Interface::UNION);
   if (MB_SUCCESS != result) return result;
 
   assert("split node not in other_nodes" &&
@@ -1916,22 +1918,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::split_pair_nonmanifold(MBEntityHandle *split_quads,
-                                             MBEntityHandle *split_edges,
-                                             MBEntityHandle *split_nodes,
-                                             std::vector<MBEntityHandle> *star_dp1,
-                                             std::vector<MBEntityHandle> *star_dp2,
-                                             MBEntityHandle *other_edges,
-                                             MBEntityHandle *other_nodes,
-                                             MBEntityHandle *new_quads,
-                                             MBEntityHandle *new_edges,
-                                             MBEntityHandle *new_nodes)
+ErrorCode DualTool::split_pair_nonmanifold(EntityHandle *split_quads,
+                                             EntityHandle *split_edges,
+                                             EntityHandle *split_nodes,
+                                             std::vector<EntityHandle> *star_dp1,
+                                             std::vector<EntityHandle> *star_dp2,
+                                             EntityHandle *other_edges,
+                                             EntityHandle *other_nodes,
+                                             EntityHandle *new_quads,
+                                             EntityHandle *new_edges,
+                                             EntityHandle *new_nodes)
 {
 
     // if there's a bdy in the star around the shared edge(s), get the quads on that
     // bdy so we know which edges to merge after the split-nonmanifold
   MeshTopoUtil mtu(mbImpl);
-  MBErrorCode result;
+  ErrorCode result;
 
     // get which star the split faces are in, and choose the other one
   int new_side = -1;
@@ -1949,8 +1951,8 @@
       // get a hex in star_dp2[new_side] that's adj to this split quad, to tell 
       // mtu which one the new quad should go with; there should be at least one,
       // if we have any hexes connected to the split quad
-    MBEntityHandle gowith_hex = 0;
-    for (std::vector<MBEntityHandle>::iterator vit = star_dp2[new_side].begin();
+    EntityHandle gowith_hex = 0;
+    for (std::vector<EntityHandle>::iterator vit = star_dp2[new_side].begin();
          vit != star_dp2[new_side].end(); vit++) {
       if (mtu.common_entity(*vit, split_quads[i], 2)) {
         gowith_hex = *vit;
@@ -1967,10 +1969,10 @@
     // make ranges of faces which need to be explicitly adj to old, new
     // edge; faces come from stars and new_quads (which weren't in the stars);
     // new_quads go with side j, which does not have split quads
-  MBRange tmp_addl_faces[2], addl_faces[2];
+  Range tmp_addl_faces[2], addl_faces[2];
   for (int i = 0; i < 2; i++) {
     std::copy(star_dp1[i].begin(), star_dp1[i].end(), 
-            mb_range_inserter(tmp_addl_faces[i]));
+            range_inserter(tmp_addl_faces[i]));
     tmp_addl_faces[new_side].insert(new_quads[i]);
   }
 #ifndef NDEBUG
@@ -2019,7 +2021,7 @@
     
       // if we're splitting multiple edges, there might be other edges that have the split
       // node; also need to know which side they're on
-    MBRange tmp_addl_edges[2];
+    Range tmp_addl_edges[2];
     result = foc_get_addl_ents(star_dp1, star_dp2, split_edges, 
                                split_nodes[j], tmp_addl_edges); RR;
 
@@ -2033,17 +2035,17 @@
 
       // same for star faces and hexes
     for (int i = 0; i < 2; i++) {
-      std::copy(star_dp1[i].begin(), star_dp1[i].end(), mb_range_inserter(tmp_addl_edges[i]));
-      std::copy(star_dp2[i].begin(), star_dp2[i].end(), mb_range_inserter(tmp_addl_edges[i]));
+      std::copy(star_dp1[i].begin(), star_dp1[i].end(), range_inserter(tmp_addl_edges[i]));
+      std::copy(star_dp2[i].begin(), star_dp2[i].end(), range_inserter(tmp_addl_edges[i]));
     }
 
       // finally, new quads
     for (int i = 0; i < 2; i++) tmp_addl_edges[new_side].insert(new_quads[i]);
 
       // filter the entities, keeping only the ones adjacent to this node
-    MBRange addl_edges[2];
+    Range addl_edges[2];
     for (int i = 0; i < 2; i++) {
-      for (MBRange::reverse_iterator rit = tmp_addl_edges[i].rbegin(); 
+      for (Range::reverse_iterator rit = tmp_addl_edges[i].rbegin(); 
            rit != tmp_addl_edges[i].rend(); rit++) {
         if (mtu.common_entity(*rit, split_nodes[j], 0)) addl_edges[i].insert(*rit);
       }
@@ -2057,11 +2059,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::foc_get_addl_ents(std::vector<MBEntityHandle> *star_dp1, 
-                                        std::vector<MBEntityHandle> *star_dp2, 
-                                        MBEntityHandle *split_edges,
-                                        MBEntityHandle split_node,
-                                        MBRange *addl_ents) 
+ErrorCode DualTool::foc_get_addl_ents(std::vector<EntityHandle> *star_dp1, 
+                                        std::vector<EntityHandle> *star_dp2, 
+                                        EntityHandle *split_edges,
+                                        EntityHandle split_node,
+                                        Range *addl_ents) 
 {
     // if we're splitting 2 edges, there might be other edges that have the split
     // node; also need to know which side they're on
@@ -2072,15 +2074,15 @@
     // - R3 = R1 & R2 (edges connected to split_node & adj to a star face)
     // - R3 -= split_edges (take split edges off addl_ents)
 
-  MBRange R2;
+  Range R2;
   MeshTopoUtil mtu(mbImpl);
-  MBErrorCode result = mbImpl->get_adjacencies(&split_node, 1, 1, false, R2); RR;
-  MBRange::iterator rit;
+  ErrorCode result = mbImpl->get_adjacencies(&split_node, 1, 1, false, R2); RR;
+  Range::iterator rit;
 
   for (int i = 0; i < 2; i++) {
-    MBRange R1, R3;
+    Range R1, R3;
     result = mbImpl->get_adjacencies(&star_dp1[i][0], star_dp1[i].size(), 1, false, 
-                                     R1, MBInterface::UNION); RR;
+                                     R1, Interface::UNION); RR;
     R3 = intersect( R1, R2);
     for (int j = 0; j < 3; j++)
       if (split_edges[j]) R3.erase(split_edges[j]);
@@ -2090,17 +2092,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::foc_get_stars(MBEntityHandle *split_quads,
-                                    MBEntityHandle *split_edges,
-                                    std::vector<MBEntityHandle> *star_dp1,
-                                    std::vector<MBEntityHandle> *star_dp2) 
+ErrorCode DualTool::foc_get_stars(EntityHandle *split_quads,
+                                    EntityHandle *split_edges,
+                                    std::vector<EntityHandle> *star_dp1,
+                                    std::vector<EntityHandle> *star_dp2) 
 {
   bool on_bdy = false, on_bdy_tmp;
-  MBErrorCode result;
+  ErrorCode result;
   MeshTopoUtil mtu(mbImpl);
   
     // get the star around the split_edge
-  std::vector<MBEntityHandle> qstar, hstar;
+  std::vector<EntityHandle> qstar, hstar;
   unsigned int qpos = 0;
   
   for (int i = 0; i < 3; i++) {
@@ -2108,7 +2110,7 @@
     
       // get the star around this split edge
     unsigned int qpos_tmp = 0;
-    std::vector<MBEntityHandle> qstar_tmp, hstar_tmp;
+    std::vector<EntityHandle> qstar_tmp, hstar_tmp;
     result = mtu.star_entities(split_edges[i], qstar_tmp, on_bdy_tmp, 0,
                              &hstar_tmp); RR;
       // if we're on the bdy, add a null to the hex star too
@@ -2236,22 +2238,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::foc_delete_dual(MBEntityHandle *split_quads,
-                                      MBEntityHandle *split_edges,
-                                      MBRange &hexes) 
+ErrorCode DualTool::foc_delete_dual(EntityHandle *split_quads,
+                                      EntityHandle *split_edges,
+                                      Range &hexes) 
 {
     // special delete dual procedure, because in some cases we need to delete
     // a sheet too since it'll get merged into another
 
     // figure out whether we'll need to delete a sheet
-  MBEntityHandle sheet1, sheet2 = 0;
+  EntityHandle sheet1, sheet2 = 0;
   sheet1 = get_dual_hyperplane(get_dual_entity(split_edges[0]));
   if (split_edges[1]) sheet1 = get_dual_hyperplane(get_dual_entity(split_edges[1]));
-  MBEntityHandle chordl = get_dual_hyperplane(get_dual_entity(split_quads[0]));
-  MBEntityHandle chordr = get_dual_hyperplane(get_dual_entity(split_quads[1]));
+  EntityHandle chordl = get_dual_hyperplane(get_dual_entity(split_quads[0]));
+  EntityHandle chordr = get_dual_hyperplane(get_dual_entity(split_quads[1]));
   assert(0 != sheet1 && 0 != chordl && 0 != chordr);
-  MBRange parentsl, parentsr;
-  MBErrorCode result = mbImpl->get_parent_meshsets(chordl, parentsl);
+  Range parentsl, parentsr;
+  ErrorCode result = mbImpl->get_parent_meshsets(chordl, parentsl);
   if (MB_SUCCESS != result) return result;
   result = mbImpl->get_parent_meshsets(chordr, parentsr);
   if (MB_SUCCESS != result) return result;
@@ -2261,37 +2263,37 @@
 
     // before deciding which one to delete, collect the other cells which must
     // be deleted, and all the chords/sheets they're on
-  MBRange adj_ents, dual_ents, cells1or2;
+  Range adj_ents, dual_ents, cells1or2;
   for (int i = 0; i < 3; i++) {
-    result = mbImpl->get_adjacencies(hexes, i, false, adj_ents, MBInterface::UNION);
+    result = mbImpl->get_adjacencies(hexes, i, false, adj_ents, Interface::UNION);
     if (MB_SUCCESS != result) return result;
   }
 
     // cache any adjacent hexes, for rebuilding the dual later
-  result = mbImpl->get_adjacencies(adj_ents, 3, false, hexes, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(adj_ents, 3, false, hexes, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   
-  for (MBRange::iterator rit = adj_ents.begin(); rit != adj_ents.end(); rit++) {
-    MBEntityHandle this_ent = get_dual_entity(*rit);
+  for (Range::iterator rit = adj_ents.begin(); rit != adj_ents.end(); rit++) {
+    EntityHandle this_ent = get_dual_entity(*rit);
     dual_ents.insert(this_ent);
     int dim = mbImpl->dimension_from_handle(this_ent);
     if (1 == dim || 2 == dim) cells1or2.insert(this_ent);
   }
 
-  MBRange dual_hps;
-  for (MBRange::iterator rit = cells1or2.begin(); rit != cells1or2.end(); rit++)
+  Range dual_hps;
+  for (Range::iterator rit = cells1or2.begin(); rit != cells1or2.end(); rit++)
     dual_hps.insert(get_dual_hyperplane(*rit));
 
   result = delete_dual_entities(dual_ents);
   if (MB_SUCCESS != result) return result;
 
     // now decide which sheet to delete (to be merged into the other)
-  MBEntityHandle sheet_delete = 0;
+  EntityHandle sheet_delete = 0;
   if (is_blind(*parentsl.begin())) sheet_delete = *parentsl.begin();
   else if (is_blind(*parentsr.begin())) sheet_delete = *parentsr.begin();
   else {
       // neither is blind, take the one with fewer cells
-    MBRange tmp_ents;
+    Range tmp_ents;
     int numl, numr;
     result = mbImpl->get_number_entities_by_handle(*parentsl.begin(), numl);
     if (MB_SUCCESS != result) return result;
@@ -2302,8 +2304,8 @@
   assert(0 != sheet_delete);
   
     // after deleting cells, check for empty chords & sheets, and delete those too
-  for (MBRange::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
-    MBRange tmp_ents;
+  for (Range::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
+    Range tmp_ents;
     result = mbImpl->get_entities_by_handle(*rit, tmp_ents);
     if (MB_SUCCESS != result) return result;
     if (tmp_ents.empty()) {
@@ -2319,9 +2321,9 @@
 
     // now just to be safe, add the hexes bridge-adjacent across vertices
     // to the hexes we already have
-  MBRange tmp_hexes;
+  Range tmp_hexes;
   MeshTopoUtil mtu(mbImpl);
-  for (MBRange::iterator rit = hexes.begin(); rit != hexes.end(); rit++) {
+  for (Range::iterator rit = hexes.begin(); rit != hexes.end(); rit++) {
     result = mtu.get_bridge_adjacencies(*rit, 0, 3, tmp_hexes);
     if (MB_SUCCESS != result) return result;
   }
@@ -2331,22 +2333,22 @@
 }
 
 //! returns true if all vertices are dual to hexes (not faces)
-bool DualTool::is_blind(const MBEntityHandle chord_or_sheet) 
+bool DualTool::is_blind(const EntityHandle chord_or_sheet) 
 {
     // must be an entity set
   if (TYPE_FROM_HANDLE(chord_or_sheet) != MBENTITYSET) return false;
   
     // get the vertices
-  MBRange verts, ents;
-  MBErrorCode result = mbImpl->get_entities_by_handle(chord_or_sheet, ents); 
+  Range verts, ents;
+  ErrorCode result = mbImpl->get_entities_by_handle(chord_or_sheet, ents); 
   if (MB_SUCCESS != result || ents.empty()) return false;
   
-  result = mbImpl->get_adjacencies(ents, 0, false, verts, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(ents, 0, false, verts, Interface::UNION);
   if (MB_SUCCESS != result || verts.empty()) return false;
   
-  for (MBRange::iterator rit = verts.begin(); rit != verts.end(); rit++) {
+  for (Range::iterator rit = verts.begin(); rit != verts.end(); rit++) {
       // get dual entity for this vertex
-    MBEntityHandle dual_ent = get_dual_entity(*rit);
+    EntityHandle dual_ent = get_dual_entity(*rit);
     if (0 == dual_ent) continue;
     if (TYPE_FROM_HANDLE(dual_ent) == MBQUAD) return false;
   }
@@ -2357,17 +2359,17 @@
 
   //! given a 1-cell and a chord, return the neighboring vertices on the
   //! chord, in the same order as the 1-cell's vertices
-MBErrorCode DualTool::get_opposite_verts(const MBEntityHandle middle_edge, 
-                                         const MBEntityHandle chord, 
-                                         MBEntityHandle *verts) 
+ErrorCode DualTool::get_opposite_verts(const EntityHandle middle_edge, 
+                                         const EntityHandle chord, 
+                                         EntityHandle *verts) 
 {
     // get the edges on the chord, in order, and move to middle_edge
-  std::vector<MBEntityHandle> chord_edges;
-  const MBEntityHandle *connect;
+  std::vector<EntityHandle> chord_edges;
+  const EntityHandle *connect;
   int num_connect;
   
-  MBErrorCode result = mbImpl->get_entities_by_handle(chord, chord_edges); RR;
-  std::vector<MBEntityHandle>::iterator vit = std::find(chord_edges.begin(), chord_edges.end(),
+  ErrorCode result = mbImpl->get_entities_by_handle(chord, chord_edges); RR;
+  std::vector<EntityHandle>::iterator vit = std::find(chord_edges.begin(), chord_edges.end(),
                                                         middle_edge);
   result = mbImpl->get_connectivity(middle_edge, connect, num_connect); RR;
 
@@ -2391,7 +2393,7 @@
   if (vit == chord_edges.begin())
     vit = chord_edges.end() - 1;
   else vit--;
-  MBRange dum_connect, middle_connect;
+  Range dum_connect, middle_connect;
   result = mbImpl->get_connectivity(&middle_edge, 1, middle_connect); RR;
   result = mbImpl->get_connectivity(&(*vit), 1, dum_connect); RR;
   dum_connect = subtract( dum_connect, middle_connect);
@@ -2421,7 +2423,7 @@
     // if verts[0] and 1st vertex of 1cell don't have common edge, switch verts
   MeshTopoUtil mtu(mbImpl);
   if (0 == mtu.common_entity(verts[0], connect[0], 1)) {
-    MBEntityHandle dum_h = verts[0];
+    EntityHandle dum_h = verts[0];
     verts[0] = verts[1];
     verts[1] = dum_h;
   }
@@ -2434,14 +2436,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::get_dual_entities(const MBEntityHandle dual_ent,
-                                        MBRange *dcells,
-                                        MBRange *dedges,
-                                        MBRange *dverts,
-                                        MBRange *dverts_loop,
-                                        MBRange *dedges_loop)
+ErrorCode DualTool::get_dual_entities(const EntityHandle dual_ent,
+                                        Range *dcells,
+                                        Range *dedges,
+                                        Range *dverts,
+                                        Range *dverts_loop,
+                                        Range *dedges_loop)
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
 
   if (NULL != dcells) {
     result = mbImpl->get_entities_by_type(dual_ent, MBPOLYGON, *dcells);
@@ -2450,7 +2452,7 @@
   
   if (NULL != dedges) {
     if (NULL != dcells)
-      result = mbImpl->get_adjacencies(*dcells, 1, false, *dedges, MBInterface::UNION);
+      result = mbImpl->get_adjacencies(*dcells, 1, false, *dedges, Interface::UNION);
     else 
       result = mbImpl->get_entities_by_type(dual_ent, MBEDGE, *dedges);
 
@@ -2459,24 +2461,24 @@
 
   if (NULL != dverts) {
     if (NULL != dcells)
-      result = mbImpl->get_adjacencies(*dcells, 0, false, *dverts, MBInterface::UNION);
+      result = mbImpl->get_adjacencies(*dcells, 0, false, *dverts, Interface::UNION);
     else if (NULL != dedges)
-      result = mbImpl->get_adjacencies(*dedges, 0, false, *dverts, MBInterface::UNION);
+      result = mbImpl->get_adjacencies(*dedges, 0, false, *dverts, Interface::UNION);
     else {
-      MBRange all_ents;
+      Range all_ents;
       result = mbImpl->get_entities_by_handle(dual_ent, all_ents); RR;
-      result = mbImpl->get_adjacencies(all_ents, 0, false, *dverts, MBInterface::UNION);
+      result = mbImpl->get_adjacencies(all_ents, 0, false, *dverts, Interface::UNION);
     }
 
     if (MB_SUCCESS != result) return result;
   }
 
   if (NULL != dverts_loop && NULL != dverts) {
-    static std::vector<MBEntityHandle> dual_ents;
+    static std::vector<EntityHandle> dual_ents;
     dual_ents.reserve(dverts->size());
     result = mbImpl->tag_get_data(dualEntity_tag(), *dverts, &dual_ents[0]);
     if (MB_SUCCESS != result) return result;
-    MBRange::iterator rit;
+    Range::iterator rit;
     unsigned int i;
     for (rit = dverts->begin(), i = 0; rit != dverts->end(); rit++, i++)
       if (0 != dual_ents[i] && mbImpl->type_from_handle(dual_ents[i]) == MBQUAD)
@@ -2484,11 +2486,11 @@
   }
   
   if (NULL != dedges_loop && NULL != dedges) {
-    static std::vector<MBEntityHandle> dual_ents;
+    static std::vector<EntityHandle> dual_ents;
     dual_ents.reserve(dedges->size());
     result = mbImpl->tag_get_data(dualEntity_tag(), *dedges, &dual_ents[0]);
     if (MB_SUCCESS != result) return result;
-    MBRange::iterator rit;
+    Range::iterator rit;
     unsigned int i;
     for (rit = dedges->begin(), i = 0; rit != dedges->end(); rit++, i++)
       if (0 != dual_ents[i] && mbImpl->type_from_handle(dual_ents[i]) == MBEDGE)
@@ -2498,11 +2500,11 @@
   return result;
 }
 
-MBErrorCode DualTool::list_entities(const MBEntityHandle *entities,
+ErrorCode DualTool::list_entities(const EntityHandle *entities,
                                     const int num_entities) const
 {
-  MBRange temp_range;
-  MBErrorCode result;
+  Range temp_range;
+  ErrorCode result;
   if (NULL == entities && 0 == num_entities) 
     return mbImpl->list_entities(entities, num_entities);
   
@@ -2510,28 +2512,28 @@
 
       // list all entities of all types
     std::cout << std::endl;
-    for (MBEntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
+    for (EntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
       result = mbImpl->get_entities_by_type(0, this_type, temp_range);
     }
   }
   
   else {
-    std::copy(entities, entities+num_entities, mb_range_inserter(temp_range));
+    std::copy(entities, entities+num_entities, range_inserter(temp_range));
   }
 
   return list_entities(temp_range);
 }
   
-MBErrorCode DualTool::list_entities(const MBRange &entities) const
+ErrorCode DualTool::list_entities(const Range &entities) const
 {
-    // now print each entity, listing the dual information first then calling MBInterface to do
+    // now print each entity, listing the dual information first then calling Interface to do
     // the rest
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  for (MBRange::const_iterator iter = entities.begin(); iter != entities.end(); iter++) {
-    MBEntityType this_type = TYPE_FROM_HANDLE(*iter);
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  for (Range::const_iterator iter = entities.begin(); iter != entities.end(); iter++) {
+    EntityType this_type = TYPE_FROM_HANDLE(*iter);
     std::cout << MBCN::EntityTypeName(this_type) << " " << ID_FROM_HANDLE(*iter) << ":" << std::endl;
 
-    MBEntityHandle dual_ent = get_dual_entity(*iter);
+    EntityHandle dual_ent = get_dual_entity(*iter);
     if (0 != dual_ent) {
       std::cout << "Dual to " 
                 << MBCN::EntityTypeName(mbImpl->type_from_handle(dual_ent)) << " "
@@ -2539,7 +2541,7 @@
     }
 
     if (TYPE_FROM_HANDLE(*iter) == MBENTITYSET) {
-      MBEntityHandle chord = 0, sheet = 0;
+      EntityHandle chord = 0, sheet = 0;
       int id;
       result = mbImpl->tag_get_data(dualCurve_tag(), &(*iter), 1, &chord);
       result = mbImpl->tag_get_data(dualSurface_tag(), &(*iter), 1, &sheet);
@@ -2558,21 +2560,21 @@
   return result;
 }
 
-MBErrorCode DualTool::face_shrink(MBEntityHandle odedge) 
+ErrorCode DualTool::face_shrink(EntityHandle odedge) 
 {
     // some preliminary checking
   if (mbImpl->type_from_handle(odedge) != MBEDGE) return MB_TYPE_OUT_OF_RANGE;
 
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
   
   std::cout << "FS("; print_cell(odedge); std::cout << ")" << std::endl;
 
-  MBEntityHandle quads[4], hexes[2];
-  std::vector<MBEntityHandle> connects[4], side_quads[2];
+  EntityHandle quads[4], hexes[2];
+  std::vector<EntityHandle> connects[4], side_quads[2];
 
     // get the quads along the chord through the 2 hexes, and the vertices 
     // for those quads
-  MBErrorCode result = fs_get_quads(odedge, quads, hexes, connects);
+  ErrorCode result = fs_get_quads(odedge, quads, hexes, connects);
   if (MB_SUCCESS != result) return result;
   
     // flip/rotate connect arrays so they align & are same sense
@@ -2585,26 +2587,26 @@
   
     // ok, done with setup; now delete dual entities affected by this operation,
     // which is all the entities adjacent to vertices of dual edge
-  MBRange adj_verts, adj_edges, dual_ents, cells1or2;
+  Range adj_verts, adj_edges, dual_ents, cells1or2;
   MeshTopoUtil mtu(mbImpl);
   result = mtu.get_bridge_adjacencies(odedge, 0, 1, adj_edges);
   if (MB_SUCCESS != result) return result;
   result = mbImpl->get_adjacencies(adj_edges, 0, false, adj_verts, 
-                                   MBInterface::UNION);
+                                   Interface::UNION);
   if (MB_SUCCESS != result) return result;
   for (int i = 1; i <= 3; i++) {
     result = mbImpl->get_adjacencies(adj_verts, i, false, dual_ents, 
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
   }
 
     // before deleting dual, grab the 1- and 2-cells
-  for (MBRange::iterator rit = dual_ents.begin(); rit != dual_ents.end(); rit++) {
+  for (Range::iterator rit = dual_ents.begin(); rit != dual_ents.end(); rit++) {
     int dim = mbImpl->dimension_from_handle(*rit);
     if (1 == dim || 2 == dim) cells1or2.insert(*rit);
   }
-  MBRange dual_hps;
-  for (MBRange::iterator rit = cells1or2.begin(); rit != cells1or2.end(); rit++)
+  Range dual_hps;
+  for (Range::iterator rit = cells1or2.begin(); rit != cells1or2.end(); rit++)
     dual_hps.insert(get_dual_hyperplane(*rit));
   
   dual_ents.insert(odedge);
@@ -2612,8 +2614,8 @@
   if (MB_SUCCESS != result) return result;
   
     // after deleting cells, check for empty chords & sheets, and delete those too
-  for (MBRange::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
-    MBRange tmp_ents;
+  for (Range::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
+    Range tmp_ents;
     result = mbImpl->get_entities_by_handle(*rit, tmp_ents);
     if (MB_SUCCESS != result) return result;
     if (tmp_ents.empty()) {
@@ -2652,7 +2654,7 @@
   }
   
     // ok, now have the 4 connectivity arrays for 4 quads; construct hexes
-  MBEntityHandle hconnect[8], new_hexes[4];
+  EntityHandle hconnect[8], new_hexes[4];
   int new_hex_ids[4];
   
   for (int i = 0; i < 4; i++) {
@@ -2722,10 +2724,10 @@
   result = mbImpl->tag_set_data(globalId_tag(), hexes, 2, tmp_ids);
   if (MB_SUCCESS != result) return result;
   
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // now update the dual
-  MBRange tmph;
+  Range tmph;
   result = mtu.get_bridge_adjacencies(hexes[0], 0, 3, tmph);
   if (MB_SUCCESS != result) return result;
   result = mtu.get_bridge_adjacencies(hexes[1], 0, 3, tmph);
@@ -2737,20 +2739,20 @@
   return result;
 }
 
-MBErrorCode DualTool:: fs_get_quad_loops(MBEntityHandle *hexes, 
-                                         std::vector<MBEntityHandle> *connects, 
-                                         std::vector<MBEntityHandle> *side_quads) 
+ErrorCode DualTool:: fs_get_quad_loops(EntityHandle *hexes, 
+                                         std::vector<EntityHandle> *connects, 
+                                         std::vector<EntityHandle> *side_quads) 
 {
   for (int i = 0; i < 4; i++) {
     for (int j = 0; j < 2; j++) {
-      MBRange adj_ents, dum_quads;
+      Range adj_ents, dum_quads;
       adj_ents.insert(hexes[j]);
       adj_ents.insert(connects[j][i]);
       adj_ents.insert(connects[j][(i+1)%4]);
       adj_ents.insert(connects[j+1][i]);
       adj_ents.insert(connects[j+1][(i+1)%4]);
     
-      MBErrorCode result = mbImpl->get_adjacencies(adj_ents, 2, false, dum_quads);
+      ErrorCode result = mbImpl->get_adjacencies(adj_ents, 2, false, dum_quads);
       if (MB_SUCCESS != result) return result;
       assert(1 == dum_quads.size());
       side_quads[j].push_back(*dum_quads.begin());
@@ -2760,19 +2762,19 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode DualTool::fs_check_quad_sense(MBEntityHandle hex0,
-                                          MBEntityHandle quad0,
-                                          std::vector<MBEntityHandle> *connects) 
+ErrorCode DualTool::fs_check_quad_sense(EntityHandle hex0,
+                                          EntityHandle quad0,
+                                          std::vector<EntityHandle> *connects) 
 {
     // check sense of 0th quad wrt hex; since sense is out of element,
     // switch if quad is NOT reversed wrt hex
   int dum1, dum2, sense = 0;
-  MBErrorCode result = mbImpl->side_number(hex0, quad0, dum1, sense, dum2);
+  ErrorCode result = mbImpl->side_number(hex0, quad0, dum1, sense, dum2);
   if (MB_SUCCESS != result) return result;
   assert(0 != sense);
   if (1 == sense) {
       // just switch sense of this one; others will get switched next
-    MBEntityHandle dum = connects[0][0];
+    EntityHandle dum = connects[0][0];
     connects[0][0] = connects[0][2];
     connects[0][2] = dum;
   }
@@ -2794,7 +2796,7 @@
   assert(index0 != -1 && sense0 != 0);
   
   if (sense0 == -1) {
-    MBEntityHandle dumh = connects[1][0];
+    EntityHandle dumh = connects[1][0];
     connects[1][0] = connects[1][2];
     connects[1][2] = dumh;
     if (index0%2 == 0)
@@ -2802,7 +2804,7 @@
   }
 
   if (index0 != 0) {
-    std::vector<MBEntityHandle> tmpc;
+    std::vector<EntityHandle> tmpc;
     for (int i = 0; i < 4; i++)
       tmpc.push_back(connects[1][(index0+i)%4]);
     connects[1].swap(tmpc);
@@ -2822,7 +2824,7 @@
   assert(index2 != -1 && sense2 != 0);
 
   if (sense2 == -1) {
-    MBEntityHandle dumh = connects[2][0];
+    EntityHandle dumh = connects[2][0];
     connects[2][0] = connects[2][2];
     connects[2][2] = dumh;
     if (index2%2 == 0)
@@ -2830,7 +2832,7 @@
   }
 
   if (index2 != 0) {
-    std::vector<MBEntityHandle> tmpc;
+    std::vector<EntityHandle> tmpc;
     for (int i = 0; i < 4; i++)
       tmpc.push_back(connects[2][(index2+i)%4]);
     connects[2].swap(tmpc);
@@ -2840,21 +2842,21 @@
 }
 
   //! effect reverse face shrink operation
-MBErrorCode DualTool::rev_face_shrink(MBEntityHandle odedge) 
+ErrorCode DualTool::rev_face_shrink(EntityHandle odedge) 
 {
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // some preliminary checking
   if (mbImpl->type_from_handle(odedge) != MBEDGE) return MB_TYPE_OUT_OF_RANGE;
   
   std::cout << "-FS("; print_cell(odedge); std::cout << ")" << std::endl;
 
-  MBEntityHandle quads[4], hexes[2];
-  std::vector<MBEntityHandle> connects[4], side_quads[2];
+  EntityHandle quads[4], hexes[2];
+  std::vector<EntityHandle> connects[4], side_quads[2];
 
     // get three quads (shared quad & 2 end quads), hexes, and quad
     // connects
-  MBErrorCode result = fs_get_quads(odedge, quads, hexes, connects);
+  ErrorCode result = fs_get_quads(odedge, quads, hexes, connects);
   if (MB_SUCCESS != result) return result;
   
     // adjust sense & rotation so they're aligned, together & wrt first
@@ -2869,12 +2871,12 @@
     return result;
   }
 
-  MBRange adj_ents, outer_hexes, all_adjs;
+  Range adj_ents, outer_hexes, all_adjs;
 
     // first get the entities connected to interior 4 verts
   for (int i = 1; i <= 3; i++) {
     result = mbImpl->get_adjacencies(&connects[1][0], 4, i, false, adj_ents,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
   }
   
@@ -2882,19 +2884,19 @@
     // entities deleted
   for (int i = 0; i < 3; i++) {
     result = mbImpl->get_adjacencies(adj_ents, i, false, all_adjs,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
   }
 
     // get the dual entities and delete them
-  MBRange dual_ents, dual_hps;
-  for (MBRange::iterator rit = all_adjs.begin(); rit != all_adjs.end(); rit++) {
-    MBEntityHandle this_ent = get_dual_entity(*rit);
+  Range dual_ents, dual_hps;
+  for (Range::iterator rit = all_adjs.begin(); rit != all_adjs.end(); rit++) {
+    EntityHandle this_ent = get_dual_entity(*rit);
     dual_ents.insert(this_ent);
   }
     
     // before deleting dual, grab the 1- and 2-cells
-  for (MBRange::iterator rit = dual_ents.begin(); rit != dual_ents.end(); rit++) {
+  for (Range::iterator rit = dual_ents.begin(); rit != dual_ents.end(); rit++) {
     int dim = mbImpl->dimension_from_handle(*rit);
     if (1 == dim || 2 == dim) dual_hps.insert(get_dual_hyperplane(*rit));
   }
@@ -2903,8 +2905,8 @@
   if (MB_SUCCESS != result) return result;
   
     // after deleting cells, check for empty chords & sheets, and delete those too
-  for (MBRange::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
-    MBRange tmp_ents;
+  for (Range::iterator rit = dual_hps.begin(); rit != dual_hps.end(); rit++) {
+    Range tmp_ents;
     result = mbImpl->get_entities_by_handle(*rit, tmp_ents);
     if (MB_SUCCESS != result) return result;
     if (tmp_ents.empty()) {
@@ -2917,23 +2919,23 @@
     // if there is a quad there, need to add explicit adjs to any adj hexes, since
     // by definition there'll be another quad on those vertices
   bool need_explicit = false;
-  MBRange adj_quads;
+  Range adj_quads;
   result = mbImpl->get_adjacencies(&connects[3][0], 4, 2, false, adj_quads);
   if (MB_MULTIPLE_ENTITIES_FOUND == result || !adj_quads.empty()) {
       // there's already a quad for these 4 vertices; by definition,
       // we'll be creating equivalent entities, so that original quad
       // needs explicit adj's to its bounding elements
     need_explicit = true;
-    for (MBRange::iterator rit = adj_quads.begin(); rit != adj_quads.end(); 
+    for (Range::iterator rit = adj_quads.begin(); rit != adj_quads.end(); 
          rit++) {
-      MBRange adj_hexes;
+      Range adj_hexes;
       result = mbImpl->get_adjacencies(&(*rit), 1, 3, false, adj_hexes); RR;
       result = mbImpl->add_adjacencies(*rit, adj_hexes, false); RR;
     }
   }
     
     // re-connect the two hexes
-  std::vector<MBEntityHandle> new_connect;
+  std::vector<EntityHandle> new_connect;
   std::copy(connects[3].begin(), connects[3].end(), std::back_inserter(new_connect));
   std::copy(connects[2].begin(), connects[2].end(), std::back_inserter(new_connect));
   result = mbImpl->set_connectivity(hexes[0], &new_connect[0], 8);
@@ -2965,13 +2967,13 @@
   result = mbImpl->delete_entities(adj_ents);
   if (MB_SUCCESS != result) return result;
 
-  MBEntityHandle new_quad;
+  EntityHandle new_quad;
   result = mbImpl->create_element(MBQUAD, &connects[3][0], 4, new_quad); RR;
   if (need_explicit) {
     result = mbImpl->add_adjacencies(new_quad, hexes, 2, false); RR;
   }
   
-  if (debug_ap) ((MBCore*)mbImpl)->check_adjacencies();
+  if (debug_ap) ((Core*)mbImpl)->check_adjacencies();
 
     // now update the dual
   result = construct_hex_dual(hexes, 2);
@@ -2980,8 +2982,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::fsr_get_fourth_quad(std::vector<MBEntityHandle> *connects,
-                                          std::vector<MBEntityHandle> *side_quads) 
+ErrorCode DualTool::fsr_get_fourth_quad(std::vector<EntityHandle> *connects,
+                                          std::vector<EntityHandle> *side_quads) 
 {
     // given the first three quad connectivities in ordered vectors, get the fourth,
     // where the fourth is really the 4 vertices originally shared by the 2 hexes
@@ -2989,9 +2991,9 @@
 
     // vertex on 4th quad is in quad adj to other 3 verts
   for (int i = 0; i < 4; i++) {
-    MBRange start_verts, tmp_verts, quads;
+    Range start_verts, tmp_verts, quads;
     for (int j = 0; j < 3; j++) start_verts.insert(connects[j][i]);
-    MBErrorCode result = mbImpl->get_adjacencies(start_verts, 2, false, quads);
+    ErrorCode result = mbImpl->get_adjacencies(start_verts, 2, false, quads);
     if (MB_SUCCESS != result) return result;
     assert(quads.size() == 1);
     result = mbImpl->get_adjacencies(&(*quads.begin()), 1, 0, false, tmp_verts); RR;
@@ -3002,11 +3004,11 @@
     
     // now get the side quads
   for (int i = 0; i < 4; i++) {
-    MBRange dum_ents, hexes;
+    Range dum_ents, hexes;
     dum_ents.insert(connects[1][i]);
     dum_ents.insert(connects[1][(i+1)%4]);
     dum_ents.insert(connects[3][i]);
-    MBErrorCode result = mbImpl->get_adjacencies(dum_ents, 3, false, hexes);
+    ErrorCode result = mbImpl->get_adjacencies(dum_ents, 3, false, hexes);
     if (MB_SUCCESS != result) return result;
     assert(1 == hexes.size());
     
@@ -3033,20 +3035,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::fs_get_quads(MBEntityHandle odedge, 
-                                   MBEntityHandle *quads,
-                                   MBEntityHandle *hexes,
-                                   std::vector<MBEntityHandle> *connects) 
+ErrorCode DualTool::fs_get_quads(EntityHandle odedge, 
+                                   EntityHandle *quads,
+                                   EntityHandle *hexes,
+                                   std::vector<EntityHandle> *connects) 
 {
     // need to get the three quads along the chord
-  MBEntityHandle chord = get_dual_hyperplane(odedge);
+  EntityHandle chord = get_dual_hyperplane(odedge);
   if (0 == chord) return MB_FAILURE;
   
-  std::vector<MBEntityHandle> edges;
-  MBErrorCode result = mbImpl->get_entities_by_handle(chord, edges);
+  std::vector<EntityHandle> edges;
+  ErrorCode result = mbImpl->get_entities_by_handle(chord, edges);
   if (MB_FAILURE == result) return result;
   
-  std::vector<MBEntityHandle>::iterator vit = std::find(edges.begin(), edges.end(), odedge);
+  std::vector<EntityHandle>::iterator vit = std::find(edges.begin(), edges.end(), odedge);
     // shouldn't be first or last edge on chord
   if (vit == edges.end() || *edges.begin() == *vit || *edges.rbegin() == *vit)
     return MB_FAILURE;
@@ -3060,7 +3062,7 @@
     if (MB_SUCCESS != result) return result;
   }
   
-  MBRange tmph;
+  Range tmph;
   result = mbImpl->get_adjacencies(quads, 2, 3, false, tmph);
   if (MB_SUCCESS != result) return result;
   assert(tmph.size() == 1);
@@ -3075,29 +3077,29 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::delete_whole_dual() 
+ErrorCode DualTool::delete_whole_dual() 
 {
     // delete dual hyperplanes
-  MBRange dual_surfs, dual_curves;
-  MBErrorCode result = this->get_dual_hyperplanes(mbImpl, 2, dual_surfs); RR;
+  Range dual_surfs, dual_curves;
+  ErrorCode result = this->get_dual_hyperplanes(mbImpl, 2, dual_surfs); RR;
   result = mbImpl->delete_entities(dual_surfs); RR;
   result = this->get_dual_hyperplanes(mbImpl, 1, dual_curves); RR;
   result = mbImpl->delete_entities(dual_curves); RR;
   
     // gather up all dual entities
-  MBRange dual_ents;
+  Range dual_ents;
   result = mbImpl->get_entities_by_type_and_tag(0, MBVERTEX, &isDualCellTag, NULL, 1, dual_ents,
-                                                MBInterface::UNION); RR;
+                                                Interface::UNION); RR;
   result = mbImpl->get_entities_by_type_and_tag(0, MBEDGE, &isDualCellTag, NULL, 1, dual_ents,
-                                                MBInterface::UNION); RR;
+                                                Interface::UNION); RR;
   result = mbImpl->get_entities_by_type_and_tag(0, MBPOLYGON, &isDualCellTag, NULL, 1, dual_ents,
-                                                MBInterface::UNION); RR;
+                                                Interface::UNION); RR;
   result = mbImpl->get_entities_by_type_and_tag(0, MBPOLYHEDRON, &isDualCellTag, NULL, 1, dual_ents,
-                                                MBInterface::UNION); RR;
+                                                Interface::UNION); RR;
 
     // delete them, in reverse order of dimension
-  MBErrorCode tmp_result;
-  for (MBRange::reverse_iterator rit = dual_ents.rbegin(); rit != dual_ents.rend(); rit++) {
+  ErrorCode tmp_result;
+  for (Range::reverse_iterator rit = dual_ents.rbegin(); rit != dual_ents.rend(); rit++) {
     tmp_result = mbImpl->delete_entities(&(*rit), 1);
     if (MB_SUCCESS != tmp_result) result = tmp_result;
   }
@@ -3128,32 +3130,32 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DualTool::check_dual_adjs() 
+ErrorCode DualTool::check_dual_adjs() 
 {
     // check primal-dual correspondence
 
     // get the primal entities
-  MBRange pents[4];
-  MBErrorCode result = mbImpl->get_entities_by_type(0, MBHEX, pents[3]); RR;
+  Range pents[4];
+  ErrorCode result = mbImpl->get_entities_by_type(0, MBHEX, pents[3]); RR;
   for (int i = 2; i >= 0; i--) {
     result = mbImpl->get_adjacencies(pents[3], 2, false, pents[2], 
-                                     MBInterface::UNION); RR;
+                                     Interface::UNION); RR;
   }
   
     // for each primal entity of dimension pd
 #define PRENT(ent) MBCN::EntityTypeName(TYPE_FROM_HANDLE(ent)) << " " \
         << ID_FROM_HANDLE(ent) 
-  MBErrorCode overall_result = MB_SUCCESS;
+  ErrorCode overall_result = MB_SUCCESS;
   for (int pd = 1; pd <= 3; pd++) {
-    for (MBRange::iterator prit = pents[pd].begin(); prit != pents[pd].end(); prit++) {
+    for (Range::iterator prit = pents[pd].begin(); prit != pents[pd].end(); prit++) {
         // get corresponding dual entity of dimension dd = 3-pd
-      MBEntityHandle dual_ent = get_dual_entity(*prit);
+      EntityHandle dual_ent = get_dual_entity(*prit);
       if (0 == dual_ent) 
         std::cerr << "Problem getting dual entity for " << PRENT(*prit) << std::endl;
       
         // for each sub dimension sd = 0..pd-1
       for (int sd = 0; sd < pd; sd++) {
-        MBRange R1, R2, R3;
+        Range R1, R2, R3;
           //   R1 = entities bounding primal entity of dim sd
         result = mbImpl->get_adjacencies(&(*prit), 1, sd, false, R1); RR;
         
@@ -3168,8 +3170,8 @@
         }
         
           // for each entity in R1, get its dual and look for it in R2
-        for (MBRange::iterator r1it = R1.begin(); r1it != R1.end(); r1it++) {
-          MBEntityHandle tmp_dual = get_dual_entity(*r1it);
+        for (Range::iterator r1it = R1.begin(); r1it != R1.end(); r1it++) {
+          EntityHandle tmp_dual = get_dual_entity(*r1it);
           if (R2.find(tmp_dual) == R2.end()) {
             std::cerr << PRENT(*prit) << ": adj entity " << PRENT(*r1it)
                       << " isn't adjacent in dual." << std::endl;
@@ -3177,8 +3179,8 @@
           }
         }
           // ditto for R2
-        for (MBRange::iterator r2it = R2.begin(); r2it != R2.end(); r2it++) {
-          MBEntityHandle tmp_prim = get_dual_entity(*r2it);
+        for (Range::iterator r2it = R2.begin(); r2it != R2.end(); r2it++) {
+          EntityHandle tmp_prim = get_dual_entity(*r2it);
           if (R1.find(tmp_prim) == R1.end()) {
             std::cerr << PRENT(*prit) << ": adj entity " << PRENT(*r2it)
                       << " isn't adjacent in primal." << std::endl;
@@ -3191,3 +3193,5 @@
 
   return overall_result;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/ElementSequence.hpp
===================================================================
--- MOAB/trunk/src/ElementSequence.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/ElementSequence.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,14 +3,16 @@
 
 #include "EntitySequence.hpp"
 #include "SequenceData.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 
+namespace moab {
+
 class ElementSequence : public EntitySequence
 {
 public:
   
-  ElementSequence( MBEntityHandle start,
-                   MBEntityID count,
+  ElementSequence( EntityHandle start,
+                   EntityID count,
                    unsigned int nodes_per_element,
                    SequenceData* data )
     : EntitySequence( start, count, data ), 
@@ -21,24 +23,24 @@
   
   inline unsigned int nodes_per_element() const { return nodesPerElement; }
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool topological = false ) const = 0;
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topological = false,
-                                        std::vector<MBEntityHandle>* storage = 0
+                                        std::vector<EntityHandle>* storage = 0
                                        ) const = 0;
 
-  virtual MBErrorCode set_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const* connect,
+  virtual ErrorCode set_connectivity( EntityHandle handle,
+                                        EntityHandle const* connect,
                                         int connect_length ) = 0;
 
-  inline MBEntityHandle const* get_connectivity_array() const;
+  inline EntityHandle const* get_connectivity_array() const;
   
-  virtual MBEntityHandle* get_connectivity_array() = 0;
+  virtual EntityHandle* get_connectivity_array() = 0;
   
   inline bool has_mid_edge_nodes() const;
   inline bool has_mid_face_nodes() const;
@@ -46,7 +48,7 @@
 
 protected:
 
-  ElementSequence( ElementSequence& split_from, MBEntityHandle here )
+  ElementSequence( ElementSequence& split_from, EntityHandle here )
     : EntitySequence( split_from, here ),
       nodesPerElement( split_from.nodesPerElement )
     {}
@@ -56,7 +58,7 @@
   unsigned nodesPerElement;
 };
 
-inline MBEntityHandle const*
+inline EntityHandle const*
 ElementSequence::get_connectivity_array() const
   { return const_cast<ElementSequence*>(this)->get_connectivity_array(); }
 
@@ -72,4 +74,6 @@
 ElementSequence::has_mid_volume_nodes() const
   { return MBCN::HasMidRegionNodes( type(), nodes_per_element() ); }
   
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/EntitySequence.cpp
===================================================================
--- MOAB/trunk/src/EntitySequence.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/EntitySequence.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,8 @@
 #include "EntitySequence.hpp"
 #include "SequenceData.hpp"
 
+namespace moab {
+
 bool EntitySequence::using_entire_data() const 
 {
   return start_handle() == data()->start_handle()
@@ -10,9 +12,9 @@
 int EntitySequence::values_per_entity() const
   { return 0; }
 
-MBErrorCode EntitySequence::pop_back( MBEntityID count )
+ErrorCode EntitySequence::pop_back( EntityID count )
 {
-  MBEntityHandle new_end = endHandle - count;
+  EntityHandle new_end = endHandle - count;
   if (new_end < startHandle)
     return MB_FAILURE;
   
@@ -20,9 +22,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode EntitySequence::pop_front( MBEntityID count )
+ErrorCode EntitySequence::pop_front( EntityID count )
 {
-  MBEntityHandle new_start = startHandle + count;
+  EntityHandle new_start = startHandle + count;
   if (new_start > endHandle)
     return MB_FAILURE;
   
@@ -31,9 +33,9 @@
 }
 
 
-MBErrorCode EntitySequence::prepend_entities( MBEntityID count )
+ErrorCode EntitySequence::prepend_entities( EntityID count )
 {
-  MBEntityHandle new_start = startHandle - count;
+  EntityHandle new_start = startHandle - count;
   if (new_start < data()->start_handle())
     return MB_FAILURE;
   
@@ -41,9 +43,9 @@
   return MB_SUCCESS;
 }
  
-MBErrorCode EntitySequence::append_entities( MBEntityID count )
+ErrorCode EntitySequence::append_entities( EntityID count )
 {
-  MBEntityHandle new_end = endHandle + count;
+  EntityHandle new_end = endHandle + count;
   if (new_end > data()->end_handle())
     return MB_FAILURE;
   
@@ -51,7 +53,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode EntitySequence::merge( EntitySequence& other )
+ErrorCode EntitySequence::merge( EntitySequence& other )
 {
   if (sequenceData != other.sequenceData)
     return MB_FAILURE;
@@ -68,6 +70,8 @@
   return MB_SUCCESS;
 }
 
-unsigned long EntitySequence::get_per_entity_memory_use( MBEntityHandle,
-                                                         MBEntityHandle ) const
+unsigned long EntitySequence::get_per_entity_memory_use( EntityHandle,
+                                                         EntityHandle ) const
   { return 0; }
+  
+} // namespace moab

Modified: MOAB/trunk/src/EntitySequence.hpp
===================================================================
--- MOAB/trunk/src/EntitySequence.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/EntitySequence.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,22 +1,24 @@
 #ifndef ENTITY_SEQUENCE_HPP
 #define ENTITY_SEQUENCE_HPP
 
-#include "MBTypes.h"
-#include "MBInternals.hpp"
+#include "moab/Types.hpp"
+#include "Internals.hpp"
 
+namespace moab {
+
 class SequenceData;
 
 class EntitySequence {
 private:
-  MBEntityHandle startHandle, endHandle;
+  EntityHandle startHandle, endHandle;
   SequenceData* sequenceData;
 
 protected:
 
-  EntitySequence( MBEntityHandle h )
+  EntitySequence( EntityHandle h )
     : startHandle(h), endHandle(h) {}
 
-  EntitySequence( EntitySequence& split_from, MBEntityHandle here )
+  EntitySequence( EntitySequence& split_from, EntityHandle here )
     : startHandle( here ),
       endHandle( split_from.endHandle ),
       sequenceData( split_from.sequenceData )
@@ -24,29 +26,29 @@
     split_from.endHandle = here - 1;
   }
 
-  SequenceData* create_data_subset( MBEntityHandle start_handle,
-                                    MBEntityHandle end_handle,
+  SequenceData* create_data_subset( EntityHandle start_handle,
+                                    EntityHandle end_handle,
                                     int num_sequence_arrays,
                                     unsigned const* bytes_per_element ) const;
 
-  MBErrorCode prepend_entities( MBEntityID count );
-  MBErrorCode append_entities( MBEntityID count );
+  ErrorCode prepend_entities( EntityID count );
+  ErrorCode append_entities( EntityID count );
 
 public:
 
-  EntitySequence( MBEntityHandle start, MBEntityID count, SequenceData* data )
+  EntitySequence( EntityHandle start, EntityID count, SequenceData* data )
     : startHandle(start), endHandle( start + count - 1 ), sequenceData( data )
     {}
 
   virtual ~EntitySequence() {}
 
-  MBEntityType type() const
+  EntityType type() const
     { return TYPE_FROM_HANDLE(start_handle()); }
 
-  MBEntityHandle start_handle() const
+  EntityHandle start_handle() const
     { return startHandle; }
   
-  MBEntityHandle end_handle() const
+  EntityHandle end_handle() const
     { return endHandle; }
   
   SequenceData* data() const
@@ -55,7 +57,7 @@
   void data( SequenceData* ptr )
     { sequenceData = ptr; }
   
-  MBEntityID size() const
+  EntityID size() const
     { return endHandle - startHandle + 1; }
     
     /**\brief True if SequenceData has no holes and is used only 
@@ -78,20 +80,20 @@
      *\param here New sequences should be [start_handle(),here) & [here,end_handle()]
      *\return New sequence containing [here,end_handle()]
      */
-  virtual EntitySequence* split( MBEntityHandle here ) = 0;
+  virtual EntitySequence* split( EntityHandle here ) = 0;
 
     /**\brief Merge this sequence with another
      *
      * Combine two adjacent sequences.  Sequence handle blocks must be
      * consective and sequences must share a common SequenceData.
      */
-  virtual MBErrorCode merge( EntitySequence& other );
+  virtual ErrorCode merge( EntitySequence& other );
   
     /**\brief Erase entities in range: (end_handle()-count, end_handle()] */
-  virtual MBErrorCode pop_back( MBEntityID count );
+  virtual ErrorCode pop_back( EntityID count );
   
     /**\brief Erase entities in range: [start_handle(), start_handle()+count) */
-  virtual MBErrorCode pop_front( MBEntityID count );
+  virtual ErrorCode pop_front( EntityID count );
   
     /**\brief Create a new SequenceData that is a copy of a subset of 
     *         the one referenced by this sequence.
@@ -100,8 +102,8 @@
     * SequenceData referenced by this EntitySequence.  Do not make any
     * changes to this EntitySequence or the current SequenceData.
     */
-  virtual SequenceData* create_data_subset( MBEntityHandle start_handle,
-                                            MBEntityHandle end_handle ) const = 0;
+  virtual SequenceData* create_data_subset( EntityHandle start_handle,
+                                            EntityHandle end_handle ) const = 0;
 
     /**\brief Get memory characteristcs that are the same for all entities
      *
@@ -119,8 +121,10 @@
      *\return Any per-entity memory use not accounted for in the results
      *        of get_const_memory_use.
      */
-  virtual unsigned long get_per_entity_memory_use( MBEntityHandle first,
-                                                   MBEntityHandle last ) const;
+  virtual unsigned long get_per_entity_memory_use( EntityHandle first,
+                                                   EntityHandle last ) const;
 };
+  
+} // namespace moab
 
 #endif

Copied: MOAB/trunk/src/Error.hpp (from rev 3583, MOAB/trunk/src/moab/MBError.hpp)
===================================================================
--- MOAB/trunk/src/Error.hpp	                        (rev 0)
+++ MOAB/trunk/src/Error.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,108 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+/*  
+ *
+ *  File:      Error.hpp
+ *
+ *  Purpose:   To keep track of detail information about errors that occur
+ *             in MB.
+ *
+ *  Date:      9-26-2002
+ *
+ *  Author:    Clinton Stimpson
+ *
+ */
+
+
+
+#ifndef MOAB_ERROR_HPP
+#define MOAB_ERROR_HPP
+
+#ifndef IS_BUILDING_MB
+#error "Error.hpp isn't supposed to be included into an application"
+#endif
+
+#include <string>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "moab/Types.hpp"
+
+#ifdef WIN32
+#define VSNPRINTF _vsnprintf
+#else
+#define VSNPRINTF vsnprintf
+#endif
+
+namespace moab {
+
+class Error
+{
+  //! string to hold the last error that occurred in MB
+  std::string mLastError;
+
+public:
+
+  Error() {}
+  ~Error(){}
+
+  ErrorCode set_last_error(const std::string& error) 
+  { 
+    mLastError = error; 
+    return MB_SUCCESS; 
+  }
+
+  inline ErrorCode set_last_error(const char* fmt, ...)
+#ifdef __GNUC__
+__attribute__((format(printf,2,3)))
+#endif
+  ;
+  
+  ErrorCode set_last_error( const char* fmt, va_list args )
+  {
+    char text[1024];
+    VSNPRINTF( text, sizeof(text), fmt, args );
+    mLastError = text;
+    return MB_SUCCESS;
+  }
+
+  ErrorCode get_last_error(std::string& error) const
+  { 
+    error = mLastError; 
+    return MB_SUCCESS;
+  }
+
+};
+
+inline ErrorCode Error::set_last_error(const char* fmt, ...)
+{
+  ErrorCode result = MB_FAILURE;
+  if (fmt)
+  {
+    va_list args;
+    va_start( args, fmt );
+    result = set_last_error( fmt, args );
+    va_end( args );
+  }
+  return result;
+}
+
+} // namespace moab 
+
+#endif
+
+

Copied: MOAB/trunk/src/Factory.cpp (from rev 3583, MOAB/trunk/src/MBFactory.cpp)
===================================================================
--- MOAB/trunk/src/Factory.cpp	                        (rev 0)
+++ MOAB/trunk/src/Factory.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,163 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifdef WIN32
+#ifdef _DEBUG
+// turn off warnings that say they debugging identifier has been truncated
+// this warning comes up when using some STL containers
+#pragma warning(disable : 4786)
+#endif
+#endif
+
+#include "moab/Core.hpp"
+
+#ifdef XPCOM_MB
+
+#include "nsIGenericFactory.h"
+
+// define constructor function for Core
+NS_GENERIC_FACTORY_CONSTRUCTOR(moab::Core)
+
+// support for nsIClassInfo
+NS_DECL_CLASSINFO(moab::Core)
+
+static const nsModuleComponentInfo components[] =
+{
+  { "MOAB Interface", CORE_CID, CORE_CONTRACTID, CoreConstructor,
+    NULL /* NULL if you dont need one */,
+    NULL /* NULL if you dont need one */,
+    NULL /* no factory destructor */,
+    NS_CI_INTERFACE_GETTER_NAME(moab::Core),
+    NULL /* no language helper */,
+    &NS_CLASSINFO_NAME(moab::Core),
+    0
+  }
+};
+
+// implement NSGetModule()
+NS_IMPL_NSGETMODULE(moab::Core, components);
+
+#endif
+
+#ifndef WIN32
+  #define MB_EXPORT extern "C"
+#else
+  #define MB_EXPORT extern "C" __declspec(dllexport)
+#endif
+
+#include <list>
+
+namespace moab {
+
+class ComponentFactory : public UnknownInterface
+{
+public:
+   ComponentFactory(){};
+   virtual ~ComponentFactory(){};
+   // returns the interface requested from an object
+   virtual int QueryInterface( const MBuuid&,
+         UnknownInterface** );
+   // keep track of the objects this component factory creates
+   static std::list<UnknownInterface*> objects_in_use;
+};
+
+// the list that keeps track of all the interfaces generated by this server
+std::list<UnknownInterface*> ComponentFactory::objects_in_use;
+
+
+// this QueryInterface function is supposed to create an instance of the object
+// that contains the interface requested
+//
+// note: the object is not the same as the interface, therefore
+// we ask the object for the interface that was requested
+//
+
+int ComponentFactory::QueryInterface( const MBuuid& uuid, UnknownInterface** iface )
+{
+   // this is an unknown interface that was requested
+   // if wanted, we could provide a default interface
+   // if IDD_MBUnknown is specified
+   if(uuid == IDD_MBUnknown)
+      return 0;
+   // IDD_MBVerde interface was requested
+   // create an Verde object and have it return the interface
+   // requested
+   else if(uuid == IDD_MBCore)
+   {
+      Core* mdb = new Core;
+      // if the object does not contain the interface requested, delete the object
+      if(!mdb->QueryInterface(uuid, iface))
+      {
+         delete mdb;
+         return 0;
+      }
+      return 1;
+   }
+   else
+      return 0;
+
+}
+
+// returns the interface version
+MB_EXPORT const char* Version()
+{
+   return MB_INTERFACE_VERSION;
+}
+
+
+// Initialize function is accessed by the MBClient when asking for interfaces
+MB_EXPORT void GetInterface(MBuuid& interface_requested, UnknownInterface** iface)
+{
+   // create an instance of our component factory
+   ComponentFactory server;
+   // ask the component factory to give us the interface we want
+   server.QueryInterface(interface_requested, iface);
+   // if the interface existed, put it on our list
+   if(iface && *iface)
+      ComponentFactory::objects_in_use.push_front(*iface);
+}
+
+
+// DeInitialize function is accessed by the MBClient when disconnecting from this library
+// this will clean everything up prior to a disconnection
+// from this library
+MB_EXPORT void DeInitialize()
+{
+   // delete all instances of objects
+   while(ComponentFactory::objects_in_use.size())
+   {
+      UnknownInterface* iface =
+         ComponentFactory::objects_in_use.front();
+      ComponentFactory::objects_in_use.pop_front();
+      if(iface)
+         delete iface;
+   }
+}
+
+// ReleaseInterface function is accessed by the MBClient when deleting an interface
+
+// ReleaseInterface will delete this interface
+MB_EXPORT void ReleaseInterface(UnknownInterface* iface)
+{
+   if(!iface)
+      return;
+   // remove this object from our list and delete it
+   ComponentFactory::objects_in_use.remove(iface);
+   delete iface;
+}
+  
+} // namespace moab
+
+

Modified: MOAB/trunk/src/FileOptions.cpp
===================================================================
--- MOAB/trunk/src/FileOptions.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/FileOptions.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,6 +25,8 @@
 #include <string.h>
 #include <algorithm>
 
+namespace moab {
+
 const char DEFAULT_SEPARATOR = ';';
 
 static inline bool strempty( const char* s ) { return !*s; }
@@ -100,19 +102,19 @@
   free( mData );
 }
 
-MBErrorCode FileOptions::get_null_option( const char* name ) const
+ErrorCode FileOptions::get_null_option( const char* name ) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   return strempty(s) ? MB_SUCCESS : MB_TYPE_OUT_OF_RANGE;
 }
 
-MBErrorCode FileOptions::get_int_option( const char* name, int& value ) const
+ErrorCode FileOptions::get_int_option( const char* name, int& value ) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -134,11 +136,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_ints_option( const char* name, 
+ErrorCode FileOptions::get_ints_option( const char* name, 
                                           std::vector<int>& values) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -179,10 +181,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_real_option ( const char* name, double& value ) const
+ErrorCode FileOptions::get_real_option ( const char* name, double& value ) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -199,10 +201,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_str_option( const char* name, std::string& value ) const
+ErrorCode FileOptions::get_str_option( const char* name, std::string& value ) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   if (strempty(s))
@@ -211,10 +213,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_option( const char* name, std::string& value ) const
+ErrorCode FileOptions::get_option( const char* name, std::string& value ) const
 {
   const char* s;
-  MBErrorCode rval = get_option( name, s );
+  ErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -222,7 +224,7 @@
   return MB_SUCCESS;
 }  
 
-MBErrorCode FileOptions::get_option( const char* name, const char*& value ) const
+ErrorCode FileOptions::get_option( const char* name, const char*& value ) const
 {
   std::vector<const char*>::const_iterator i;
   for (i = mOptions.begin(); i != mOptions.end(); ++i) {
@@ -242,7 +244,7 @@
   return MB_ENTITY_NOT_FOUND;
 }
 
-MBErrorCode FileOptions::match_option( const char* name, 
+ErrorCode FileOptions::match_option( const char* name, 
                                        const char* value ) const
 {
   int idx;
@@ -250,12 +252,12 @@
   return match_option( name, array, idx );
 }
 
-MBErrorCode FileOptions::match_option( const char* name, 
+ErrorCode FileOptions::match_option( const char* name, 
                                        const char* const* values, 
                                        int& index ) const
 {
   const char* optval;
-  MBErrorCode rval = get_option( name, optval );
+  ErrorCode rval = get_option( name, optval );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -292,7 +294,7 @@
   return std::find( mSeen.begin(), mSeen.end(), false ) == mSeen.end();
 }
 
-MBErrorCode FileOptions::get_unseen_option( std::string& name ) const
+ErrorCode FileOptions::get_unseen_option( std::string& name ) const
 {
   std::vector<bool>::iterator i = std::find( mSeen.begin(), mSeen.end(), false );
   if (i == mSeen.end()) {
@@ -305,9 +307,13 @@
   name = end ? std::string(opt, end-opt) : std::string(opt);
   return MB_SUCCESS;
 }
+  
+} // namespace moab
 
 #ifdef TEST
 
+using namespace moab;
+
 #include <iostream>
 
 #define CHECK(A) \
@@ -329,7 +335,7 @@
   std::string s;
   int i;
   double d;
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // test basic get_option method without deleting entry
   rval = tool.get_option( "STR1", s );

Modified: MOAB/trunk/src/FileOptions.hpp
===================================================================
--- MOAB/trunk/src/FileOptions.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/FileOptions.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -23,13 +23,15 @@
 
 #include <string>
 #include <vector>
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 
+namespace moab {
+
 /**\brief Parse options string passed to file IO routines
  *
  * This is a utility class used by file-IO-related code to 
- * parse the options string passed to MBCore::load_file and
- * MBCore::write_file
+ * parse the options string passed to Core::load_file and
+ * Core::write_file
  */
 class FileOptions {
 public:
@@ -55,7 +57,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but has value
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  MBErrorCode get_null_option( const char* name ) const;
+  ErrorCode get_null_option( const char* name ) const;
   
   /**\brief Check for option with an integer value.
    *
@@ -66,7 +68,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but does not have an integer value
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  MBErrorCode get_int_option( const char* name, int& value ) const;
+  ErrorCode get_int_option( const char* name, int& value ) const;
   
   /**\brief Check for option with a double value.
    *
@@ -77,7 +79,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but does not have a double value
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  MBErrorCode get_real_option( const char* name, double& value ) const;
+  ErrorCode get_real_option( const char* name, double& value ) const;
   
   /**\brief Check for option with any value.
    *
@@ -88,7 +90,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but does not have a value
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  MBErrorCode get_str_option( const char* name, std::string& value ) const;
+  ErrorCode get_str_option( const char* name, std::string& value ) const;
   
   /**\brief Check for option 
    *
@@ -97,7 +99,7 @@
    *\param value The option value, or an empty string if no value.
    *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
    */
-  MBErrorCode get_option( const char* name, std::string& value ) const;
+  ErrorCode get_option( const char* name, std::string& value ) const;
   
   /**\brief Check the string value of an option
    *
@@ -111,7 +113,7 @@
    *        MB_ENTITY_NOT_FOUND if the option was not specified
    *        MB_FAILURE if the option value is not in the input <code>values</code> array.
    */
-  MBErrorCode match_option( const char* name, const char* const* values, int& index ) const;
+  ErrorCode match_option( const char* name, const char* const* values, int& index ) const;
   
   /**\brief Check if an option matches a string value
    *
@@ -122,7 +124,7 @@
    *        MB_ENTITY_NOT_FOUND if the option was not specified
    *        MB_FAILURE if the option value doesn't match the passed string/
    */
-  MBErrorCode match_option( const char* name, const char* value ) const;
+  ErrorCode match_option( const char* name, const char* value ) const;
   
   /**\brief Check for option for which the value is a list of ints
    *
@@ -137,7 +139,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but does not contain an ID list
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  MBErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
+  ErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
   
   /** number of options */
   inline unsigned size() const 
@@ -154,7 +156,7 @@
   bool all_seen() const;
   
   /** Get first unseen option */
-  MBErrorCode get_unseen_option( std::string& value ) const;
+  ErrorCode get_unseen_option( std::string& value ) const;
   
 private:
   
@@ -165,7 +167,7 @@
    *\param value The option value, or an empty string if no value.
    *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
    */
-  MBErrorCode get_option( const char* name, const char*& value) const;
+  ErrorCode get_option( const char* name, const char*& value) const;
 
   char* mData;
   std::vector<const char*> mOptions;
@@ -174,6 +176,8 @@
     /** Case-insensitive compare of name with option value. */
   static bool compare( const char* name, const char* option );
 };
+  
+} // namespace moab
 
 #endif
 

Modified: MOAB/trunk/src/GeomTopoTool.cpp
===================================================================
--- MOAB/trunk/src/GeomTopoTool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/GeomTopoTool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,15 +13,17 @@
  * 
  */
 
-#include "GeomTopoTool.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInterface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/GeomTopoTool.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 #include <assert.h>
 #include <iostream>
 
+namespace moab {
+
 // Tag name used for saving sense of faces in volumes.
 // We assume that the surface occurs in at most two volumes.
 // Code will error out if more than two volumes per surface.
@@ -31,20 +33,20 @@
 // be listed for both the forward and reverse slots.
 const char GEOM_SENSE_TAG_NAME[] = "GEOM_SENSE_2";
 
-MBErrorCode GeomTopoTool::set_sense( MBEntityHandle surface,
-                                     MBEntityHandle volume,
+ErrorCode GeomTopoTool::set_sense( EntityHandle surface,
+                                     EntityHandle volume,
                                      bool forward )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (!sense2Tag) {
-    rval = mdbImpl->tag_create( GEOM_SENSE_TAG_NAME, 2*sizeof(MBEntityHandle), 
+    rval = mdbImpl->tag_create( GEOM_SENSE_TAG_NAME, 2*sizeof(EntityHandle), 
                            MB_TAG_SPARSE, MB_TYPE_HANDLE, 
                            sense2Tag, 0, true );
     if (MB_SUCCESS != rval)
       return rval;
   }
   
-  MBEntityHandle sense_data[2] = {0,0};
+  EntityHandle sense_data[2] = {0,0};
   rval = mdbImpl->tag_get_data( sense2Tag, &surface, 1, sense_data );
   if (MB_TAG_NOT_FOUND != rval && MB_SUCCESS != rval)
     return MB_FAILURE;
@@ -58,11 +60,11 @@
   return mdbImpl->tag_set_data( sense2Tag, &surface, 1, sense_data );
 }
 
-MBErrorCode GeomTopoTool::get_sense( MBEntityHandle surface,
-                                     MBEntityHandle volume,
+ErrorCode GeomTopoTool::get_sense( EntityHandle surface,
+                                     EntityHandle volume,
                                      bool& forward )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (!sense2Tag) {
     rval = mdbImpl->tag_get_handle( GEOM_SENSE_TAG_NAME, sense2Tag );
     if (MB_SUCCESS != rval) {
@@ -71,7 +73,7 @@
     }
   }
   
-  MBEntityHandle sense_data[2] = {0,0};
+  EntityHandle sense_data[2] = {0,0};
   rval = mdbImpl->tag_get_data( sense2Tag, &surface, 1, sense_data );
   if (MB_SUCCESS != rval)
     return rval;
@@ -86,16 +88,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode GeomTopoTool::find_geomsets(MBRange *ranges) 
+ErrorCode GeomTopoTool::find_geomsets(Range *ranges) 
 {
-  //MBTag geom_tag;
-  MBErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
+  //Tag geom_tag;
+  ErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
                                            MB_TAG_SPARSE, geomTag, NULL);
   if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
     return result;
   
     // get all sets with this tag
-  MBRange geom_sets;
+  Range geom_sets;
   result = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &geomTag, NULL, 1,
                                                  geom_sets);
   if (MB_SUCCESS != result || geom_sets.empty()) 
@@ -112,13 +114,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode GeomTopoTool::construct_obb_trees()
+ErrorCode GeomTopoTool::construct_obb_trees()
 {
   // get all surfaces and volumes
-  MBRange surfs, vols;
+  Range surfs, vols;
   const int three = 3;
   const void* const three_val[] = {&three};
-  MBErrorCode rval = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &geomTag, 
+  ErrorCode rval = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &geomTag, 
 							   three_val, 1, vols);
   if (MB_SUCCESS != rval) return rval;
 
@@ -143,10 +145,10 @@
   }
 
   // for surface
-  MBEntityHandle root;
+  EntityHandle root;
   rootSets.resize(surfs.size() + vols.size());
-  for (MBRange::iterator i = surfs.begin(); i != surfs.end(); ++i) {
-    MBRange tris;
+  for (Range::iterator i = surfs.begin(); i != surfs.end(); ++i) {
+    Range tris;
     rval = mdbImpl->get_entities_by_dimension( *i, 2, tris );
     if (MB_SUCCESS != rval) return rval;
     
@@ -164,15 +166,15 @@
   }
   
   // for volumes
-  for (MBRange::iterator i = vols.begin(); i != vols.end(); ++i) {
+  for (Range::iterator i = vols.begin(); i != vols.end(); ++i) {
     // get all surfaces in volume
-    MBRange tmp_surfs;
+    Range tmp_surfs;
     rval = mdbImpl->get_child_meshsets( *i, tmp_surfs );
     if (MB_SUCCESS != rval) return rval;
     
     // get OBB trees for each surface
-    MBRange trees;
-    for (MBRange::iterator j = tmp_surfs.begin();  j != tmp_surfs.end(); ++j) {
+    Range trees;
+    for (Range::iterator j = tmp_surfs.begin();  j != tmp_surfs.end(); ++j) {
       rval = get_root(*j, root);
       if (MB_SUCCESS != rval || !root) return MB_FAILURE;
       trees.insert( root );
@@ -189,7 +191,7 @@
 } 
   
     //! Restore parent/child links between GEOM_TOPO mesh sets
-MBErrorCode GeomTopoTool::restore_topology() 
+ErrorCode GeomTopoTool::restore_topology() 
 {
   
     // look for geometric topology sets and restore parent/child links between them
@@ -202,39 +204,39 @@
     //   . make parent/child links with parents
 
     // get the geom topology tag
-  MBTag geom_tag;
-  MBErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
+  Tag geom_tag;
+  ErrorCode result = mdbImpl->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
                                             MB_TAG_SPARSE, geom_tag, NULL);
   if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
     return result;
   
     // get all sets with this tag
-  MBRange geom_sets;
+  Range geom_sets;
   result = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &geom_tag, NULL, 1,
                                                 geom_sets);
   if (MB_SUCCESS != result || geom_sets.empty()) 
     return result;
 
-  MBRange entities[4];
+  Range entities[4];
   result = separate_by_dimension(geom_sets, entities, geom_tag);
   if (MB_SUCCESS != result)
     return result;
 
-  std::vector<MBEntityHandle> parents;
-  MBRange tmp_parents;
+  std::vector<EntityHandle> parents;
+  Range tmp_parents;
   
     // loop over dimensions
   for (int dim = 2; dim >= 0; dim--) {
       // mark entities of next higher dimension with their owners; regenerate tag
       // each dimension so prev dim's tag data goes away
-    MBTag owner_tag;
-    MBEntityHandle dum_val = 0;
-    result = mdbImpl->tag_create("__owner_tag", sizeof(MBEntityHandle), MB_TAG_DENSE,
+    Tag owner_tag;
+    EntityHandle dum_val = 0;
+    result = mdbImpl->tag_create("__owner_tag", sizeof(EntityHandle), MB_TAG_DENSE,
                                  MB_TYPE_HANDLE, owner_tag, &dum_val);
     if (MB_SUCCESS != result) continue;
-    MBRange dp1ents;
-    std::vector<MBEntityHandle> owners;
-    for (MBRange::iterator rit = entities[dim+1].begin(); rit != entities[dim+1].end(); rit++) {
+    Range dp1ents;
+    std::vector<EntityHandle> owners;
+    for (Range::iterator rit = entities[dim+1].begin(); rit != entities[dim+1].end(); rit++) {
       dp1ents.clear();
       result = mdbImpl->get_entities_by_dimension(*rit, dim+1, dp1ents);
       if (MB_SUCCESS != result) continue;
@@ -244,9 +246,9 @@
       if (MB_SUCCESS != result) continue;
     }
     
-    for (MBRange::iterator d_it = entities[dim].begin(); 
+    for (Range::iterator d_it = entities[dim].begin(); 
          d_it != entities[dim].end(); d_it++) {
-      MBRange dents;
+      Range dents;
       result = mdbImpl->get_entities_by_dimension(*d_it, dim, dents);
       if (MB_SUCCESS != result) continue;
       if (dents.empty()) continue;
@@ -265,8 +267,8 @@
       
         // compress to a range to remove duplicates
       tmp_parents.clear();
-      std::copy(parents.begin(), parents.end(), mb_range_inserter(tmp_parents));
-      for (MBRange::iterator pit = tmp_parents.begin(); pit != tmp_parents.end(); pit++) {
+      std::copy(parents.begin(), parents.end(), range_inserter(tmp_parents));
+      for (Range::iterator pit = tmp_parents.begin(); pit != tmp_parents.end(); pit++) {
         result = mdbImpl->add_parent_child(*pit, *d_it);
         if (MB_SUCCESS != result) return result;
       }
@@ -274,7 +276,7 @@
         // store surface senses
       if (dim != 2) 
         continue;
-      const MBEntityHandle *conn3, *conn2;
+      const EntityHandle *conn3, *conn2;
       int len3, len2, err, num, sense, offset;
       for (size_t i = 0; i < parents.size(); ++i) {
         result = mdbImpl->get_connectivity( dp1ents[i], conn3, len3, true );
@@ -307,10 +309,10 @@
   return result;
 }
 
-MBErrorCode GeomTopoTool::separate_by_dimension(const MBRange &geom_sets,
-                                                 MBRange *entities, MBTag geom_tag) 
+ErrorCode GeomTopoTool::separate_by_dimension(const Range &geom_sets,
+                                                 Range *entities, Tag geom_tag) 
 {
-  MBErrorCode result;
+  ErrorCode result;
   
   if (0 == geom_tag) {
     
@@ -325,7 +327,7 @@
   if (MB_SUCCESS != result)
     return result;
 
-  MBRange::const_iterator git;
+  Range::const_iterator git;
   std::vector<int>::iterator iit;
   
   for (git = geom_sets.begin(), iit = tag_vals.begin(); git != geom_sets.end(); 
@@ -341,15 +343,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode GeomTopoTool::construct_vertex_ranges(const MBRange &geom_sets,
-                                                   const MBTag verts_tag) 
+ErrorCode GeomTopoTool::construct_vertex_ranges(const Range &geom_sets,
+                                                   const Tag verts_tag) 
 {
     // construct the vertex range for each entity and put on that tag
-  MBRange *temp_verts, temp_elems;
-  MBErrorCode result = MB_SUCCESS;
-  for (MBRange::const_iterator it = geom_sets.begin(); it != geom_sets.end(); it++) {
+  Range *temp_verts, temp_elems;
+  ErrorCode result = MB_SUCCESS;
+  for (Range::const_iterator it = geom_sets.begin(); it != geom_sets.end(); it++) {
       // make the new range
-    temp_verts = new MBRange();
+    temp_verts = new Range();
     assert(NULL != temp_verts);
     temp_elems.clear();
     
@@ -360,7 +362,7 @@
     
       // get all the verts of those elements; use get_adjacencies 'cuz it handles ranges better
     result = mdbImpl->get_adjacencies(temp_elems, 0, false, *temp_verts,
-                                      MBInterface::UNION);
+                                      Interface::UNION);
     if (MB_SUCCESS != result) 
       return result;
 
@@ -373,5 +375,7 @@
   
   return result;
 }
- 
   
+} // namespace moab
+
+  

Copied: MOAB/trunk/src/GeomUtil.cpp (from rev 3583, MOAB/trunk/src/MBGeomUtil.cpp)
===================================================================
--- MOAB/trunk/src/GeomUtil.cpp	                        (rev 0)
+++ MOAB/trunk/src/GeomUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1304 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file Geometry.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-27
+ */
+
+#include "moab/CartVect.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/GeomUtil.hpp"
+#include "Matrix3.hpp"
+#include <cmath>
+#include <algorithm>
+#include <assert.h>
+#include <iostream>
+#include <limits>
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#  include <float.h>
+#  define finite(A) _finite(A)
+#endif
+
+namespace moab {
+
+namespace GeomUtil {
+
+static inline 
+void min_max_3( double a, double b, double c, double& min, double& max )
+{
+  if (a < b) {
+    if (a < c) {
+      min = a;
+      max = b > c ? b : c;
+    }
+    else {
+      min = c;
+      max = b;
+    }
+  }
+  else if (b < c) {
+    min = b;
+    max = a > c ? a : c;
+  }
+  else {
+    min = c;
+    max = a;
+  }
+}
+
+static inline
+double dot_abs( const CartVect& u, const CartVect& v )
+  { return fabs(u[0]*v[0]) + fabs(u[1]*v[1]) + fabs(u[2]*v[2]); }
+
+bool segment_box_intersect( CartVect box_min,
+                            CartVect box_max,
+                            const CartVect& seg_pt,
+                            const CartVect& seg_unit_dir,
+                            double& seg_start, double& seg_end )
+{
+    // translate so that seg_pt is at origin
+  box_min -= seg_pt;
+  box_max -= seg_pt;
+  
+  for (unsigned i = 0; i < 3; ++i) {  // X, Y, and Z slabs
+
+      // intersect line with slab planes
+    const double t_min = box_min[i] / seg_unit_dir[i];
+    const double t_max = box_max[i] / seg_unit_dir[i];
+    
+      // check if line is parallel to planes
+    if (!finite(t_min)) {
+      if (box_min[i] > 0.0 || box_max[i] < 0.0)
+        return false; 
+      continue;
+    }
+
+    if (seg_unit_dir[i] < 0) {
+      if (t_min < seg_end) 
+        seg_end = t_min;
+      if (t_max > seg_start)
+        seg_start = t_max;
+    }
+    else { // seg_unit_dir[i] > 0
+      if (t_min > seg_start)
+        seg_start = t_min; 
+      if (t_max < seg_end)
+        seg_end = t_max;
+    }
+  }
+
+  return seg_start <= seg_end;
+}
+
+
+/* Impelementation copied from cgmMC ray_tri_contact (overlap.C) */
+bool ray_tri_intersect( const CartVect vertices[3],
+                        const CartVect& b,
+                        const CartVect& v,
+                        double /*tolerance*/,
+                        double& t_out,
+                        const double* ray_length)
+{
+  const CartVect p0 = vertices[0] - vertices[1]; // abc
+  const CartVect p1 = vertices[0] - vertices[2]; // def
+                                                   // ghi<-v
+  const CartVect p = vertices[0] - b;            // jkl
+  const CartVect c = p1 * v;                     // eiMinushf,gfMinusdi,dhMinuseg
+  const double mP = p0 % c;
+  const double betaP = p % c;
+  if (mP > 0) {
+    if (betaP < 0)
+      return false;
+  }
+  else if (mP < 0) {
+    if (betaP > 0)
+      return false;
+  }
+  else {
+    return false;
+  }
+  
+  const CartVect d = p0 * p; // jcMinusal,blMinuskc,akMinusjb
+  double gammaP = v % d;
+  if (mP > 0) {
+    if (gammaP < 0 || betaP + gammaP > mP)
+      return false;
+  }
+  else if (betaP + gammaP < mP || gammaP > 0)
+    return false;
+  
+  const double tP = p1 % d;
+  const double m = 1.0 / mP;
+  const double beta = betaP * m;
+  const double gamma = gammaP * m;
+  const double t = -tP * m;
+  if (ray_length && t > *ray_length)
+    return false;
+  
+  if (beta < 0 || gamma < 0 ||
+      beta + gamma > 1 ||
+      t < 0.0)
+    return false;
+  
+  t_out = t;
+  return true;
+}
+
+bool ray_box_intersect( const CartVect& box_min,
+                        const CartVect& box_max,
+                        const CartVect& ray_pt,
+                        const CartVect& ray_dir,
+                        double& t_enter, double& t_exit )
+{
+  const double epsilon = 1e-12;
+  double t1, t2;
+
+  // Use 'slabs' method from 13.6.1 of Akenine-Moller
+  t_enter = 0.0;
+  t_exit  = std::numeric_limits<double>::infinity();
+  
+  // Intersect with each pair of axis-aligned planes bounding
+  // opposite faces of the leaf box
+  bool ray_is_valid = false; // is ray direction vector zero?
+  for (int axis = 0; axis < 3; ++axis) {
+    if (fabs(ray_dir[axis]) < epsilon) { // ray parallel to planes
+      if (ray_pt[axis] >= box_min[axis] &&
+          ray_pt[axis] <= box_max[axis])
+        continue;
+      else
+        return false;
+    }
+      
+      // find t values at which ray intersects each plane
+    ray_is_valid = true;
+    t1 = (box_min[axis] - ray_pt[axis]) / ray_dir[axis];
+    t2 = (box_max[axis] - ray_pt[axis]) / ray_dir[axis];
+    
+      // t_enter = max( t_enter_x, t_enter_y, t_enter_z )
+      // t_exit  = min( t_exit_x, t_exit_y, t_exit_z )
+      //   where
+      // t_enter_x = min( t1_x, t2_x );
+      // t_exit_x  = max( t1_x, t2_x )
+    if (t1 < t2) {
+      if (t_enter < t1)
+        t_enter = t1;
+      if (t_exit > t2)
+        t_exit = t2;
+    }
+    else {
+      if (t_enter < t2)
+        t_enter = t2;
+      if (t_exit > t1)
+        t_exit = t1;
+    }
+  }
+  
+  return ray_is_valid && (t_enter <= t_exit);
+}
+
+
+bool box_plane_overlap( const CartVect& normal,
+                        double d,
+                        CartVect min,
+                        CartVect max )
+{
+  if (normal[0] < 0.0)
+    std::swap( min[0], max[0] );
+  if (normal[1] < 0.0)
+    std::swap( min[1], max[1] );
+  if (normal[2] < 0.0)
+    std::swap( min[2], max[2] );
+  
+  return (normal % min <= -d) && (normal % max >= -d);
+}
+
+
+#define CHECK_RANGE( A, B, R ) \
+  if ((A) < (B)) { \
+    if ((A) > (R) || (B) < -(R)) \
+      return false; \
+  } \
+  else if ((B) > (R) || (A) < -(R)) \
+    return false
+
+/* Adapted from: http://jgt.akpeters.com/papers/AkenineMoller01/tribox.html
+ * Use separating axis theorem to test for overlap between triangle
+ * and axis-aligned box.
+ *
+ * Test for overlap in these directions:
+ * 1) {x,y,z}-directions 
+ * 2) normal of triangle
+ * 3) crossprod of triangle edge with {x,y,z}-direction
+ */
+bool box_tri_overlap( const CartVect vertices[3],
+                      const CartVect& box_center,
+                      const CartVect& box_dims )
+{
+    // translate everthing such that box is centered at origin
+  const CartVect v0( vertices[0] - box_center );
+  const CartVect v1( vertices[1] - box_center );
+  const CartVect v2( vertices[2] - box_center );
+
+  // do case 1) tests
+  if (v0[0] > box_dims[0] && v1[0] > box_dims[0] && v2[0] > box_dims[0])
+    return false;
+  if (v0[1] > box_dims[1] && v1[1] > box_dims[1] && v2[1] > box_dims[1])
+    return false;
+  if (v0[2] > box_dims[2] && v1[2] > box_dims[2] && v2[2] > box_dims[2])
+    return false;
+  if (v0[0] < -box_dims[0] && v1[0] < -box_dims[0] && v2[0] < -box_dims[0])
+    return false;
+  if (v0[1] < -box_dims[1] && v1[1] < -box_dims[1] && v2[1] < -box_dims[1])
+    return false;
+  if (v0[2] < -box_dims[2] && v1[2] < -box_dims[2] && v2[2] < -box_dims[2])
+    return false;
+  
+    // compute triangle edge vectors
+  const CartVect e0( vertices[1] - vertices[0] );
+  const CartVect e1( vertices[2] - vertices[1] );
+  const CartVect e2( vertices[0] - vertices[2] );
+  
+    // do case 3) tests 
+  double fex, fey, fez, p0, p1, p2, rad;
+  fex = fabs(e0[0]);
+  fey = fabs(e0[1]);
+  fez = fabs(e0[2]);
+  
+  p0 = e0[2]*v0[1] - e0[1]*v0[2];
+  p2 = e0[2]*v2[1] - e0[1]*v2[2];
+  rad = fez * box_dims[1] + fey * box_dims[2];
+  CHECK_RANGE( p0, p2, rad );
+  
+  p0 = -e0[2]*v0[0] + e0[0]*v0[2];
+  p2 = -e0[2]*v2[0] + e0[0]*v2[2];
+  rad = fez * box_dims[0] + fex * box_dims[2];
+  CHECK_RANGE( p0, p2, rad );
+    
+  p1 = e0[1]*v1[0] - e0[0]*v1[1];
+  p2 = e0[1]*v2[0] - e0[0]*v2[1];
+  rad = fey * box_dims[0] + fex * box_dims[1];
+  CHECK_RANGE( p1, p2, rad );
+  
+  fex = fabs(e1[0]);
+  fey = fabs(e1[1]);
+  fez = fabs(e1[2]);
+  
+  p0 = e1[2]*v0[1] - e1[1]*v0[2];
+  p2 = e1[2]*v2[1] - e1[1]*v2[2];
+  rad = fez * box_dims[1] + fey * box_dims[2];
+  CHECK_RANGE( p0, p2, rad );
+  
+  p0 = -e1[2]*v0[0] + e1[0]*v0[2];
+  p2 = -e1[2]*v2[0] + e1[0]*v2[2];
+  rad = fez * box_dims[0] + fex * box_dims[2];
+  CHECK_RANGE( p0, p2, rad );
+  
+  p0 = e1[1]*v0[0] - e1[0]*v0[1];
+  p1 = e1[1]*v1[0] - e1[0]*v1[1];
+  rad = fey * box_dims[0] + fex * box_dims[1];
+  CHECK_RANGE( p0, p1, rad );
+  
+  fex = fabs(e2[0]);
+  fey = fabs(e2[1]);
+  fez = fabs(e2[2]);
+  
+  p0 = e2[2]*v0[1] - e2[1]*v0[2];
+  p1 = e2[2]*v1[1] - e2[1]*v1[2];
+  rad = fez * box_dims[1] + fey * box_dims[2];
+  CHECK_RANGE( p0, p1, rad );
+  
+  p0 = -e2[2]*v0[0] + e2[0]*v0[2];
+  p1 = -e2[2]*v1[0] + e2[0]*v1[2];
+  rad = fez * box_dims[0] + fex * box_dims[2];
+  CHECK_RANGE( p0, p1, rad );
+  
+  p1 = e2[1]*v1[0] - e2[0]*v1[1];
+  p2 = e2[1]*v2[0] - e2[0]*v2[1];
+  rad = fey * box_dims[0] + fex * box_dims[1];
+  CHECK_RANGE( p1, p2, rad );
+  
+  // do case 2) test
+  CartVect n = e0 * e1;
+  return box_plane_overlap( n, -(n % v0), -box_dims, box_dims );
+}
+  
+
+bool box_tri_overlap( const CartVect  triangle_corners[3],
+                      const CartVect& box_min_corner,
+                      const CartVect& box_max_corner,
+                      double            tolerance )
+{
+  const CartVect box_center = 0.5 * (box_max_corner + box_min_corner);
+  const CartVect box_hf_dim = 0.5 * (box_max_corner - box_min_corner);
+  return box_tri_overlap( triangle_corners,
+                          box_center,
+                          box_hf_dim + CartVect(tolerance) );
+} 
+
+bool box_elem_overlap( const CartVect *elem_corners,
+                       EntityType elem_type,
+                       const CartVect& center,
+                       const CartVect& dims )
+{
+
+  switch (elem_type) {
+    case MBTRI:
+      return box_tri_overlap( elem_corners, center, dims );
+    case MBTET:
+      return box_tet_overlap( elem_corners, center, dims );
+    case MBHEX:
+      return box_hex_overlap( elem_corners, center, dims );
+    case MBPOLYGON:
+    case MBPOLYHEDRON:
+      assert(false);
+      return false;
+    default:
+      return box_linear_elem_overlap( elem_corners, elem_type, center, dims );
+  }
+}
+
+static inline CartVect quad_norm( const CartVect& v1,
+                                    const CartVect& v2,
+                                    const CartVect& v3,
+                                    const CartVect& v4 )
+{ return (-v1+v2+v3-v4) * (-v1-v2+v3+v4); }
+
+static inline CartVect tri_norm( const CartVect& v1,
+                                   const CartVect& v2,
+                                   const CartVect& v3 )
+{ return (v2-v1) * (v3-v1); }
+
+
+bool box_linear_elem_overlap( const CartVect *elem_corners,
+                              EntityType type,
+                              const CartVect& box_center,
+                              const CartVect& box_halfdims )
+{
+  CartVect corners[8];
+  const unsigned num_corner = MBCN::VerticesPerEntity( type );
+  assert( num_corner <= sizeof(corners)/sizeof(corners[0]) );
+  for (unsigned i = 0; i < num_corner; ++i)
+    corners[i] = elem_corners[i] - box_center;
+  return box_linear_elem_overlap( corners, type, box_halfdims );
+}
+        
+
+bool box_linear_elem_overlap( const CartVect *elem_corners,
+                              EntityType type,
+                              const CartVect& dims )
+{
+    // Do Separating Axis Theorem:
+    // If the element and the box overlap, then the 1D projections
+    // onto at least one of the axes in the following three sets
+    // must overlap (assuming convex polyhedral element).
+    // 1) The normals of the faces of the box (the principal axes)
+    // 2) The crossproduct of each element edge with each box edge
+    //    (crossproduct of each edge with each principal axis)
+    // 3) The normals of the faces of the element
+
+  unsigned i, e, f;             // loop counters
+  double dot, cross[2], tmp;
+  CartVect norm;
+  int indices[4]; // element edge/face vertex indices
+  
+    // test box face normals (principal axes)
+  const unsigned num_corner = MBCN::VerticesPerEntity( type );
+  int not_less[3] = { num_corner, num_corner, num_corner }; 
+  int not_greater[3] = { num_corner, num_corner, num_corner };
+  int not_inside;
+  for (i = 0; i < num_corner; ++i) { // for each element corner
+    not_inside = 3;
+    
+    if (elem_corners[i][0] < -dims[0])
+      --not_less[0];
+    else if (elem_corners[i][0] > dims[0])
+      --not_greater[0];
+    else
+      --not_inside;
+      
+    if (elem_corners[i][1] < -dims[1])
+      --not_less[1];
+    else if (elem_corners[i][1] > dims[1])
+      --not_greater[1];
+    else
+      --not_inside;
+      
+    if (elem_corners[i][2] < -dims[2])
+      --not_less[2];
+    else if (elem_corners[i][2] > dims[2])
+      --not_greater[2];
+    else
+      --not_inside;
+    
+    if (!not_inside)
+      return true;
+  }
+    // If all points less than min_x of box, then
+    // not_less[0] == 0, and therfore
+    // the following product is zero.
+  if (not_greater[0] * not_greater[1] * not_greater[2] * 
+         not_less[0] *    not_less[1] *    not_less[2] == 0)
+    return false;
+ 
+    // Test edge-edge crossproducts
+    
+    // Edge directions for box are principal axis, so 
+    // for each element edge, check along the cross-product
+    // of that edge with each of the tree principal axes.
+  const unsigned num_edge = MBCN::NumSubEntities( type, 1 );
+  for (e = 0; e < num_edge; ++e) { // for each element edge
+      // get which element vertices bound the edge
+    MBCN::SubEntityVertexIndices( type, 1, e, indices );
+
+      // X-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = elem_corners[indices[0]][2] - elem_corners[indices[1]][2];
+    cross[1] = elem_corners[indices[1]][1] - elem_corners[indices[0]][1];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[1]) + fabs(cross[1] * dims[2]);
+      not_less[0] = not_greater[0] = num_corner - 1;
+      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
+        tmp = cross[0] * elem_corners[i][1] + cross[1] * elem_corners[i][2];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+
+      // Y-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = elem_corners[indices[0]][0] - elem_corners[indices[1]][0];
+    cross[1] = elem_corners[indices[1]][2] - elem_corners[indices[0]][2];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[2]) + fabs(cross[1] * dims[0]);
+      not_less[0] = not_greater[0] = num_corner - 1;
+      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
+        tmp = cross[0] * elem_corners[i][2] + cross[1] * elem_corners[i][0];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+
+      // Z-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = elem_corners[indices[0]][1] - elem_corners[indices[1]][1];
+    cross[1] = elem_corners[indices[1]][0] - elem_corners[indices[0]][0];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[0]) + fabs(cross[1] * dims[1]);
+      not_less[0] = not_greater[0] = num_corner - 1;
+      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
+        tmp = cross[0] * elem_corners[i][0] + cross[1] * elem_corners[i][1];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+  }
+  
+  
+    // test element face normals
+  const unsigned num_face = MBCN::NumSubEntities( type, 2 );
+  for (f = 0; f < num_face; ++f) {
+    MBCN::SubEntityVertexIndices( type, 2, f, indices );
+    switch (MBCN::SubEntityType( type, 2, f )) {
+      case MBTRI:
+        norm = tri_norm( elem_corners[indices[0]], 
+                         elem_corners[indices[1]], 
+                         elem_corners[indices[2]] );
+        break;
+      case MBQUAD:
+        norm = quad_norm( elem_corners[indices[0]], 
+                          elem_corners[indices[1]], 
+                          elem_corners[indices[2]], 
+                          elem_corners[indices[3]] );
+        break;
+      default:
+        assert(false);
+        continue;
+    }
+    
+    dot = dot_abs(norm, dims);
+    
+    // for each element vertex
+    not_less[0] = not_greater[0] = num_corner;
+    for (i = 0; i < num_corner; ++i) { 
+      tmp = norm % elem_corners[i];
+      not_less[0] -= (tmp < -dot);
+      not_greater[0] -= (tmp > dot);
+    }
+
+    if (not_less[0] * not_greater[0] == 0)
+      return false;
+  }
+
+    // Overlap on all tested axes.
+  return true;
+}
+ 
+
+bool box_hex_overlap( const CartVect *elem_corners,
+                      const CartVect& center,
+                      const CartVect& dims )
+{
+    // Do Separating Axis Theorem:
+    // If the element and the box overlap, then the 1D projections
+    // onto at least one of the axes in the following three sets
+    // must overlap (assuming convex polyhedral element).
+    // 1) The normals of the faces of the box (the principal axes)
+    // 2) The crossproduct of each element edge with each box edge
+    //    (crossproduct of each edge with each principal axis)
+    // 3) The normals of the faces of the element
+
+  unsigned i, e, f;             // loop counters
+  double dot, cross[2], tmp;
+  CartVect norm;
+  const CartVect corners[8] = { elem_corners[0] - center,
+                                  elem_corners[1] - center,
+                                  elem_corners[2] - center,
+                                  elem_corners[3] - center,
+                                  elem_corners[4] - center,
+                                  elem_corners[5] - center,
+                                  elem_corners[6] - center,
+                                  elem_corners[7] - center };
+  
+    // test box face normals (principal axes)
+  int not_less[3] = { 8, 8, 8 }; 
+  int not_greater[3] = { 8, 8, 8 };
+  int not_inside;
+  for (i = 0; i < 8; ++i) { // for each element corner
+    not_inside = 3;
+    
+    if (corners[i][0] < -dims[0])
+      --not_less[0];
+    else if (corners[i][0] > dims[0])
+      --not_greater[0];
+    else
+      --not_inside;
+      
+    if (corners[i][1] < -dims[1])
+      --not_less[1];
+    else if (corners[i][1] > dims[1])
+      --not_greater[1];
+    else
+      --not_inside;
+      
+    if (corners[i][2] < -dims[2])
+      --not_less[2];
+    else if (corners[i][2] > dims[2])
+      --not_greater[2];
+    else
+      --not_inside;
+    
+    if (!not_inside)
+      return true;
+  }
+    // If all points less than min_x of box, then
+    // not_less[0] == 0, and therfore
+    // the following product is zero.
+  if (not_greater[0] * not_greater[1] * not_greater[2] * 
+         not_less[0] *    not_less[1] *    not_less[2] == 0)
+    return false;
+ 
+    // Test edge-edge crossproducts
+  const unsigned edges[12][2] = { { 0, 1 }, { 0, 4 }, { 0, 3 },
+                                  { 2, 3 }, { 2, 1 }, { 2, 6 },
+                                  { 5, 6 }, { 5, 1 }, { 5, 4 },
+                                  { 7, 4 }, { 7, 3 }, { 7, 6 } };
+                             
+    // Edge directions for box are principal axis, so 
+    // for each element edge, check along the cross-product
+    // of that edge with each of the tree principal axes.
+  for (e = 0; e < 12; ++e) { // for each element edge
+      // get which element vertices bound the edge
+    const CartVect& v0 = corners[ edges[e][0] ];
+    const CartVect& v1 = corners[ edges[e][1] ];
+
+      // X-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = v0[2] - v1[2];
+    cross[1] = v1[1] - v0[1];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[1]) + fabs(cross[1] * dims[2]);
+      not_less[0] = not_greater[0] = 7;
+      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
+        tmp = cross[0] * corners[i][1] + cross[1] * corners[i][2];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+
+      // Y-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = v0[0] - v1[0];
+    cross[1] = v1[2] - v0[2];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[2]) + fabs(cross[1] * dims[0]);
+      not_less[0] = not_greater[0] = 7;
+      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
+        tmp = cross[0] * corners[i][2] + cross[1] * corners[i][0];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+
+      // Z-Axis
+
+      // calculate crossproduct: axis x (v1 - v0),
+      // where v1 and v0 are edge vertices.
+    cross[0] = v0[1] - v1[1];
+    cross[1] = v1[0] - v0[0];
+      // skip if parallel
+    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
+      dot = fabs(cross[0] * dims[0]) + fabs(cross[1] * dims[1]);
+      not_less[0] = not_greater[0] = 7;
+      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
+        tmp = cross[0] * corners[i][0] + cross[1] * corners[i][1];
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
+      }
+
+      if (not_less[0] * not_greater[0] == 0)
+        return false;
+    }
+  }
+  
+  
+    // test element face normals
+  const unsigned faces[6][4] = { { 0, 1, 2, 3 },
+                                 { 0, 1, 5, 4 },
+                                 { 1, 2, 6, 5 },
+                                 { 2, 6, 7, 3 },
+                                 { 3, 7, 4, 0 },
+                                 { 7, 4, 5, 6 } };
+  for (f = 0; f < 6; ++f) {
+    norm = quad_norm( corners[faces[f][0]], 
+                      corners[faces[f][1]], 
+                      corners[faces[f][2]], 
+                      corners[faces[f][3]] );
+    
+    dot = dot_abs(norm, dims);
+   
+    // for each element vertex
+    not_less[0] = not_greater[0] = 8;
+    for (i = 0; i < 8; ++i) { 
+      tmp = norm % corners[i];
+      not_less[0] -= (tmp < -dot);
+      not_greater[0] -= (tmp > dot);
+    }
+
+    if (not_less[0] * not_greater[0] == 0)
+      return false;
+  }
+
+    // Overlap on all tested axes.
+  return true;
+}
+
+static inline 
+bool box_tet_overlap_edge( const CartVect& dims,
+                           const CartVect& edge,
+                           const CartVect& ve,
+                           const CartVect& v1,
+                           const CartVect& v2 )
+{
+  double dot, dot1, dot2, dot3, min, max;
+  
+    // edge x X
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[2]) * dims[1] + fabs(edge[1]) * dims[2];
+    dot1 = edge[2] * ve[1] - edge[1] * ve[2];
+    dot2 = edge[2] * v1[1] - edge[1] * v1[2];
+    dot3 = edge[2] * v2[1] - edge[1] * v2[2];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+  
+    // edge x Y
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[2]) * dims[0] + fabs(edge[0]) * dims[2];
+    dot1 = -edge[2] * ve[0] + edge[0] * ve[2];
+    dot2 = -edge[2] * v1[0] + edge[0] * v1[2];
+    dot3 = -edge[2] * v2[0] + edge[0] * v2[2];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+  
+    // edge x Z
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[1]) * dims[0] + fabs(edge[0]) * dims[1];
+    dot1 = edge[1] * ve[0] - edge[0] * ve[1];
+    dot2 = edge[1] * v1[0] - edge[0] * v1[1];
+    dot3 = edge[1] * v2[0] - edge[0] * v2[1];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+
+  return true;
+}
+
+bool box_tet_overlap( const CartVect *corners_in,
+                      const CartVect& center,
+                      const CartVect& dims )
+{
+    // Do Separating Axis Theorem:
+    // If the element and the box overlap, then the 1D projections
+    // onto at least one of the axes in the following three sets
+    // must overlap (assuming convex polyhedral element).
+    // 1) The normals of the faces of the box (the principal axes)
+    // 2) The crossproduct of each element edge with each box edge
+    //    (crossproduct of each edge with each principal axis)
+    // 3) The normals of the faces of the element
+
+    // Translate problem such that box center is at origin.
+  const CartVect corners[4] = { corners_in[0] - center,
+                                  corners_in[1] - center,
+                                  corners_in[2] - center,
+                                  corners_in[3] - center };
+
+    // 0) Check if any vertex is within the box
+  if (fabs(corners[0][0]) <= dims[0] &&
+      fabs(corners[0][1]) <= dims[1] &&
+      fabs(corners[0][2]) <= dims[2])
+    return true;
+  if (fabs(corners[1][0]) <= dims[0] &&
+      fabs(corners[1][1]) <= dims[1] &&
+      fabs(corners[1][2]) <= dims[2])
+    return true;
+  if (fabs(corners[2][0]) <= dims[0] &&
+      fabs(corners[2][1]) <= dims[1] &&
+      fabs(corners[2][2]) <= dims[2])
+    return true;
+  if (fabs(corners[3][0]) <= dims[0] &&
+      fabs(corners[3][1]) <= dims[1] &&
+      fabs(corners[3][2]) <= dims[2])
+    return true;
+  
+
+    // 1) Check for overlap on each principal axis (box face normal)
+    // X
+  if (corners[0][0] < -dims[0] &&
+      corners[1][0] < -dims[0] &&
+      corners[2][0] < -dims[0] &&
+      corners[3][0] < -dims[0])
+    return false;
+  if (corners[0][0] >  dims[0] &&
+      corners[1][0] >  dims[0] &&
+      corners[2][0] >  dims[0] &&
+      corners[3][0] >  dims[0])
+    return false;
+    // Y
+  if (corners[0][1] < -dims[1] &&
+      corners[1][1] < -dims[1] &&
+      corners[2][1] < -dims[1] &&
+      corners[3][1] < -dims[1])
+    return false;
+  if (corners[0][1] >  dims[1] &&
+      corners[1][1] >  dims[1] &&
+      corners[2][1] >  dims[1] &&
+      corners[3][1] >  dims[1])
+    return false;
+    // Z
+  if (corners[0][2] < -dims[2] &&
+      corners[1][2] < -dims[2] &&
+      corners[2][2] < -dims[2] &&
+      corners[3][2] < -dims[2])
+    return false;
+  if (corners[0][2] >  dims[2] &&
+      corners[1][2] >  dims[2] &&
+      corners[2][2] >  dims[2] &&
+      corners[3][2] >  dims[2])
+    return false;
+ 
+    // 3) test element face normals
+  CartVect norm;
+  double dot, dot1, dot2;
+  
+  const CartVect v01 = corners[1] - corners[0];
+  const CartVect v02 = corners[2] - corners[0];
+  norm = v01 * v02;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[3];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  const CartVect v03 = corners[3] - corners[0];
+  norm = v03 * v01;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[2];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  norm = v02 * v03;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[1];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  const CartVect v12 = corners[2] - corners[1];
+  const CartVect v13 = corners[3] - corners[1];
+  norm = v13 * v12;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[1];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+
+    // 2) test edge-edge cross products
+    
+  const CartVect v23 = corners[3] - corners[2];
+  return box_tet_overlap_edge( dims, v01, corners[0], corners[2], corners[3] )
+      && box_tet_overlap_edge( dims, v02, corners[0], corners[1], corners[3] )
+      && box_tet_overlap_edge( dims, v03, corners[0], corners[1], corners[2] )
+      && box_tet_overlap_edge( dims, v12, corners[1], corners[0], corners[3] )
+      && box_tet_overlap_edge( dims, v13, corners[1], corners[0], corners[2] )
+      && box_tet_overlap_edge( dims, v23, corners[2], corners[0], corners[1] );
+}
+    
+
+
+
+//from: http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf#search=%22closest%20point%20on%20triangle%22
+/*       t
+ *   \(2)^
+ *    \  |
+ *     \ |
+ *      \|
+ *       \
+ *       |\
+ *       | \
+ *       |  \  (1)
+ *  (3)  tv  \
+ *       |    \
+ *       | (0) \
+ *       |      \
+ *-------+---sv--\----> s
+ *       |        \ (6)
+ *  (4)  |   (5)   \
+ */
+// Worst case is either 61 flops and 5 compares or 53 flops and 6 compares,
+// depending on relative costs.  For all paths that do not return one of the
+// corner vertices, exactly one of the flops is a divide.
+void closest_location_on_tri( const CartVect& location,
+                              const CartVect* vertices,
+                              CartVect& closest_out )
+{                                                     // ops      comparisons
+  const CartVect sv( vertices[1] - vertices[0] );   // +3 = 3
+  const CartVect tv( vertices[2] - vertices[0] );   // +3 = 6
+  const CartVect pv( vertices[0] - location );      // +3 = 9
+  const double ss = sv % sv;                          // +5 = 14
+  const double st = sv % tv;                          // +5 = 19
+  const double tt = tv % tv;                          // +5 = 24
+  const double sp = sv % pv;                          // +5 = 29
+  const double tp = tv % pv;                          // +5 = 34
+  const double det = ss*tt - st*st;                   // +3 = 37
+  double s = st*tp - tt*sp;                           // +3 = 40
+  double t = st*sp - ss*tp;                           // +3 = 43
+  if (s+t < det) {                                    // +1 = 44, +1 = 1
+    if (s < 0) {                                      //          +1 = 2
+      if (t < 0) {                                    //          +1 = 3
+        // region 4
+        if (sp < 0) {                                 //          +1 = 4
+          if (-sp > ss)                               //          +1 = 5
+            closest_out = vertices[1];                //      44       5
+          else
+            closest_out = vertices[0] - (sp/ss) * sv; // +7 = 51,      5
+        }
+        else if (tp < 0) {                            //          +1 = 5
+          if (-tp > tt)                               //          +1 = 6
+            closest_out = vertices[2];                //      44,      6
+          else
+            closest_out = vertices[0] - (tp/tt) * tv; // +7 = 51,      6
+        }
+        else {
+          closest_out = vertices[0];                  //      44,      5
+        }
+      }
+      else {
+        // region 3
+        if (tp >= 0)                                  //          +1 = 4
+          closest_out = vertices[0];                  //      44,      4
+        else if (-tp >= tt)                           //          +1 = 5
+          closest_out = vertices[2];                  //      44,      5
+        else
+          closest_out = vertices[0] - (tp/tt) * tv;   // +7 = 51,      5
+      }
+    }
+    else if (t < 0) {                                 //          +1 = 3
+      // region 5;
+      if (sp >= 0.0)                                  //          +1 = 4
+        closest_out = vertices[0];                    //      44,      4
+      else if (-sp >= ss)                             //          +1 = 5
+        closest_out = vertices[1];                    //      44       5
+      else
+        closest_out = vertices[0] - (sp/ss) * sv;     // +7 = 51,      5
+    }
+    else {
+      // region 0
+      const double inv_det = 1.0 / det;               // +1 = 45
+      s *= inv_det;                                   // +1 = 46
+      t *= inv_det;                                   // +1 = 47
+      closest_out = vertices[0] + s*sv + t*tv;        //+12 = 59,      3  
+    }
+  }
+  else {
+    if (s < 0) {                                      //          +1 = 2
+      // region 2
+      s = st + sp;                                    // +1 = 45
+      t = tt + tp;                                    // +1 = 46
+      if (t > s) {                                    //          +1 = 3
+        const double num = t - s;                     // +1 = 47
+        const double den = ss - 2*st + tt;            // +3 = 50
+        if (num > den)                                //          +1 = 4
+          closest_out = vertices[1];                  //      50,      4
+        else {
+          s = num/den;                                // +1 = 51
+          t = 1 - s;                                  // +1 = 52
+          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      4
+        }
+      }
+      else if (t <= 0)                                //          +1 = 4
+        closest_out = vertices[2];                    //      46,      4
+      else if (tp >= 0)                               //          +1 = 5
+        closest_out = vertices[0];                    //      46,      5
+      else
+        closest_out = vertices[0] - (tp/tt) * tv;     // +7 = 53,      5
+    }
+    else if (t < 0) {                                 //          +1 = 3
+      // region 6
+      t = st + tp;                                    // +1 = 45
+      s = ss + sp;                                    // +1 = 46
+      if (s > t) {                                    //          +1 = 4
+        const double num = t - s;                     // +1 = 47
+        const double den = tt - 2*st + ss;            // +3 = 50
+        if (num > den)                                //          +1 = 5
+          closest_out = vertices[2];                  //      50,      5
+        else {
+          t = num/den;                                // +1 = 51
+          s = 1 - t;                                  // +1 = 52
+          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      5
+        }
+      }
+      else if (s <= 0)                                //          +1 = 5
+        closest_out = vertices[1];                    //      46,      5
+      else if (sp >= 0)                               //          +1 = 6
+        closest_out = vertices[0];                    //      46,      6
+      else
+        closest_out = vertices[0] - (sp/ss) * sv;     // +7 = 53,      6
+    }
+    else {
+      // region 1
+      const double num = tt + tp - st - sp;           // +3 = 47
+      if (num <= 0) {                                 //          +1 = 4
+        closest_out = vertices[2];                    //      47,      4
+      }
+      else {
+        const double den = ss - 2*st + tt;            // +3 = 50
+        if (num >= den)                               //          +1 = 5
+          closest_out = vertices[1];                  //      50,      5
+        else {
+          s = num/den;                                // +1 = 51
+          t = 1 - s;                                  // +1 = 52
+          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      5
+        }
+      }
+    }
+  }
+}
+
+void closest_location_on_tri( const CartVect& location,
+                              const CartVect* vertices,
+                              double tolerance,
+                              CartVect& closest_out,
+                              int& closest_topo )
+{
+  const double tsqr = tolerance*tolerance;
+  int i;
+  CartVect pv[3], ev, ep;
+  double t;
+
+  closest_location_on_tri( location, vertices, closest_out );
+  
+  for (i = 0; i < 3; ++i) {
+    pv[i] = vertices[i] - closest_out;
+    if ((pv[i] % pv[i]) <= tsqr) {
+      closest_topo = i;
+      return;
+    }
+  }
+  
+  for (i = 0; i < 3; ++i) {
+    ev = vertices[(i+1)%3] - vertices[i];
+    t = (ev % pv[i]) / (ev % ev);
+    ep = closest_out - (vertices[i] + t * ev);
+    if ((ep % ep) <= tsqr) {
+      closest_topo = i+3;
+      return;
+    }
+  }
+  
+  closest_topo = 6;
+}
+ 
+    
+// We assume polygon is *convex*, but *not* planar.
+void closest_location_on_polygon( const CartVect& location,
+                                  const CartVect* vertices,
+                                  int num_vertices,
+                                  CartVect& closest_out )
+{
+  const int n = num_vertices;
+  CartVect d, p, v;
+  double shortest_sqr, dist_sqr, t_closest, t;
+  int i, e;
+  
+    // Find closest edge of polygon.
+  e = n - 1;
+  v = vertices[0] - vertices[e];
+  t_closest = (v % (location - vertices[e])) / (v % v);
+  if (t_closest < 0.0)
+    d = location - vertices[e];
+  else if (t_closest > 1.0)
+    d = location - vertices[0];
+  else 
+    d = location - vertices[e] - t_closest * v;
+  shortest_sqr = d % d;
+  for (i = 0; i < n - 1; ++i) {
+    v = vertices[i+1] - vertices[i];
+    t = (v % (location - vertices[i])) / (v % v);
+    if (t < 0.0)
+      d = location - vertices[i];
+    else if (t > 1.0)
+      d = location - vertices[i+1];
+    else
+      d = location - vertices[i] - t * v;
+    dist_sqr = d % d;
+    if (dist_sqr < shortest_sqr) {
+      e = i;
+      shortest_sqr = dist_sqr;
+      t_closest = t;
+    }
+  }
+  
+    // If we are beyond the bounds of the edge, then
+    // the point is outside and closest to a vertex
+  if (t_closest <= 0.0) {
+    closest_out = vertices[e];
+    return;
+  }
+  else if (t_closest >= 1.0) {
+    closest_out = vertices[(e+1)%n];
+    return;
+  }
+  
+    // Now check which side of the edge we are one
+  const CartVect v0 = vertices[e] - vertices[(e+n-1)%n];
+  const CartVect v1 = vertices[(e+1)%n] - vertices[e];
+  const CartVect v2 = vertices[(e+2)%n] - vertices[(e+1)%n];
+  const CartVect norm = (1.0 - t_closest) * (v0 * v1) + t_closest * (v1 * v2);
+    // if on outside of edge, result is closest point on edge
+  if ((norm % ((vertices[e] - location) * v1)) <= 0.0) { 
+    closest_out = vertices[e] + t_closest * v1;
+    return;
+  }
+  
+    // Inside.  Project to plane defined by point and normal at
+    // closest edge
+  const double D = -(norm % (vertices[e] + t_closest * v1));
+  closest_out = (location - (norm % location + D) * norm)/(norm % norm);
+}
+
+void closest_location_on_box( const CartVect& min,
+                              const CartVect& max,
+                              const CartVect& point,
+                              CartVect& closest )
+{
+  closest[0] = point[0] < min[0] ? min[0] : point[0] > max[0] ? max[0] : point[0];
+  closest[1] = point[1] < min[1] ? min[1] : point[1] > max[1] ? max[1] : point[1];
+  closest[2] = point[2] < min[2] ? min[2] : point[2] > max[2] ? max[2] : point[2];
+}
+
+bool box_point_overlap( const CartVect& box_min_corner,
+                        const CartVect& box_max_corner,
+                        const CartVect& point,
+                        double tolerance )
+{
+  CartVect closest;
+  closest_location_on_box( box_min_corner, box_max_corner, point, closest );
+  closest -= point;
+  return closest % closest < tolerance * tolerance;
+}
+
+
+/**\brief Class representing a 3-D mapping function (e.g. shape function for volume element) */
+class VolMap {
+  public:
+      /**\brief Return $\vec \xi$ corresponding to logical center of element */
+    virtual CartVect center_xi() const = 0;
+      /**\brief Evaluate mapping function (calculate $\vec x = F($\vec \xi)$ )*/
+    virtual CartVect evaluate( const CartVect& xi ) const = 0;
+      /**\brief Evaluate Jacobian of mapping function */
+    virtual Matrix3 jacobian( const CartVect& xi ) const = 0;
+      /**\brief Evaluate inverse of mapping function (calculate $\vec \xi = F^-1($\vec x)$ )*/
+    bool solve_inverse( const CartVect& x, CartVect& xi, double tol ) const ;
+};
+
+bool VolMap::solve_inverse( const CartVect& x, CartVect& xi, double tol ) const
+{
+  const double error_tol_sqr = tol*tol;
+  double det;
+  xi = center_xi();
+  CartVect delta = evaluate(xi) - x;
+  Matrix3 J;
+  while (delta % delta > error_tol_sqr) {
+    J = jacobian(xi);
+    det = J.determinant();
+    if (det < std::numeric_limits<double>::epsilon())
+      return false;
+    xi -= J.inverse(1.0/det) * delta;
+    delta = evaluate( xi ) - x;
+  }
+  return true;
+}
+
+/**\brief Shape function for trilinear hexahedron */
+class LinearHexMap : public VolMap {
+  public:
+    LinearHexMap( const CartVect* corner_coords ) : corners(corner_coords) {}
+    virtual CartVect center_xi() const;
+    virtual CartVect evaluate( const CartVect& xi ) const;
+    virtual Matrix3 jacobian( const CartVect& xi ) const;
+  private:
+    const CartVect* corners;
+    static const double corner_xi[8][3];
+};
+
+const double LinearHexMap::corner_xi[8][3] = { { -1, -1, -1 },
+                                               {  1, -1, -1 },
+                                               {  1,  1, -1 },
+                                               { -1,  1, -1 },
+                                               { -1, -1,  1 },
+                                               {  1, -1,  1 },
+                                               {  1,  1,  1 },
+                                               { -1,  1,  1 } };
+CartVect LinearHexMap::center_xi() const
+  { return CartVect(0.0); }
+
+CartVect LinearHexMap::evaluate( const CartVect& xi ) const
+{
+  CartVect x(0.0);
+  for (unsigned i = 0; i < 8; ++i) {
+    const double N_i = (1 + xi[0]*corner_xi[i][0])
+                     * (1 + xi[1]*corner_xi[i][1])
+                     * (1 + xi[2]*corner_xi[i][2]);
+    x += N_i * corners[i];
+  }
+  x *= 0.125;
+  return x;
+}
+
+Matrix3 LinearHexMap::jacobian( const CartVect& xi ) const
+{
+  Matrix3 J(0.0);
+  for (unsigned i = 0; i < 8; ++i) {
+    const double   xi_p = 1 + xi[0]*corner_xi[i][0];
+    const double  eta_p = 1 + xi[1]*corner_xi[i][1];
+    const double zeta_p = 1 + xi[2]*corner_xi[i][2];
+    const double dNi_dxi   = corner_xi[i][0] * eta_p * zeta_p;
+    const double dNi_deta  = corner_xi[i][1] *  xi_p * zeta_p;
+    const double dNi_dzeta = corner_xi[i][2] *  xi_p *  eta_p;
+    J(0,0) += dNi_dxi   * corners[i][0];
+    J(1,0) += dNi_dxi   * corners[i][1];
+    J(2,0) += dNi_dxi   * corners[i][2];
+    J(0,1) += dNi_deta  * corners[i][0];
+    J(1,1) += dNi_deta  * corners[i][1];
+    J(2,1) += dNi_deta  * corners[i][2];
+    J(0,2) += dNi_dzeta * corners[i][0];
+    J(1,2) += dNi_dzeta * corners[i][1];
+    J(2,2) += dNi_dzeta * corners[i][2];
+  }
+  return J *= 0.125;
+}
+
+bool nat_coords_trilinear_hex( const CartVect* corner_coords,
+                               const CartVect& x,
+                               CartVect& xi,
+                               double tol )
+{
+  return LinearHexMap( corner_coords ).solve_inverse( x, xi, tol );
+}
+
+
+bool point_in_trilinear_hex(const CartVect *hex, 
+                            const CartVect& xyz,
+                            double etol) 
+{
+  CartVect xi;
+  return nat_coords_trilinear_hex( hex, xyz, xi, etol )
+      && fabs(xi[0])-1 < etol 
+      && fabs(xi[1])-1 < etol 
+      && fabs(xi[2])-1 < etol;
+}
+
+
+
+} // namespace GeomUtil
+  
+} // namespace moab
+

Modified: MOAB/trunk/src/HigherOrderFactory.cpp
===================================================================
--- MOAB/trunk/src/HigherOrderFactory.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/HigherOrderFactory.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -22,19 +22,21 @@
 #endif
 #endif
 
-#include "HigherOrderFactory.hpp"
+#include "moab/HigherOrderFactory.hpp"
 #include "SequenceManager.hpp"
 #include "UnstructuredElemSeq.hpp"
 #include "VertexSequence.hpp"
 #include "AEntityFactory.hpp"
-#include "MBCore.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBCN.hpp"
 #include <assert.h>
 #include <algorithm>
 
+namespace moab {
+
 using namespace std;
 
-HigherOrderFactory::HigherOrderFactory(MBCore* MB, MBInterface::HONodeAddedRemoved* function_object) 
+HigherOrderFactory::HigherOrderFactory(Core* MB, Interface::HONodeAddedRemoved* function_object) 
   : mMB(MB), mHONodeAddedRemoved(function_object)
 {
   initialize_map();
@@ -48,7 +50,7 @@
  // if(mMapInitialized)
   //  return;
 
-  for(MBEntityType i=MBVERTEX; i<MBMAXTYPE; i++)
+  for(EntityType i=MBVERTEX; i<MBMAXTYPE; i++)
   {
     const MBCN::ConnMap& canon_map = MBCN::mConnectivityMap[i][0];
     unsigned char (&this_map)[8][8] = mNodeMap[i];
@@ -67,17 +69,17 @@
 }
 
 
-MBErrorCode HigherOrderFactory::convert( const MBEntityHandle meshset, 
+ErrorCode HigherOrderFactory::convert( const EntityHandle meshset, 
                                          const bool mid_edge_nodes, 
                                          const bool mid_face_nodes, 
                                          const bool mid_volume_nodes )
 {
-  MBRange entities;
+  Range entities;
   mMB->get_entities_by_handle(meshset, entities, true);
   return convert( entities, mid_edge_nodes, mid_face_nodes, mid_volume_nodes );
 }
 
-MBErrorCode HigherOrderFactory::convert( const MBRange& entities,
+ErrorCode HigherOrderFactory::convert( const Range& entities,
                                          const bool mid_edge_nodes, 
                                          const bool mid_face_nodes, 
                                          const bool mid_volume_nodes )
@@ -92,14 +94,14 @@
   // and where, if necessary, to split them
 
   SequenceManager* seq_manager = mMB->sequence_manager();
-  MBRange::const_pair_iterator p_iter;
+  Range::const_pair_iterator p_iter;
   for (p_iter = entities.const_pair_begin(); p_iter != entities.const_pair_end(); ++p_iter) {
     
-    MBEntityHandle h = p_iter->first;
+    EntityHandle h = p_iter->first;
     while (h <= p_iter->second) {
       
       EntitySequence* seq;
-      MBErrorCode rval = seq_manager->find( h, seq );
+      ErrorCode rval = seq_manager->find( h, seq );
       if (MB_SUCCESS != rval)
         return rval;
       
@@ -111,7 +113,7 @@
       if (NULL == elemseq->get_connectivity_array())
         return MB_NOT_IMPLEMENTED;
       
-      MBEntityHandle last = p_iter->second;
+      EntityHandle last = p_iter->second;
       if (last > seq->end_handle())
         last = seq->end_handle();
       
@@ -130,15 +132,15 @@
 } 
 
 
-MBErrorCode HigherOrderFactory::convert_sequence( ElementSequence* seq, 
-                                                  MBEntityHandle start,
-                                                  MBEntityHandle end,
+ErrorCode HigherOrderFactory::convert_sequence( ElementSequence* seq, 
+                                                  EntityHandle start,
+                                                  EntityHandle end,
                                                   bool mid_edge_nodes, 
                                                   bool mid_face_nodes, 
                                                   bool mid_volume_nodes)
 {
 
-  MBErrorCode status = MB_SUCCESS;
+  ErrorCode status = MB_SUCCESS;
 
   // lets make sure parameters are ok before we continue
   switch (seq->type()) {
@@ -168,7 +170,7 @@
   if (nodes_per_elem == seq->nodes_per_element())
     return MB_SUCCESS;
   
-  MBTag deletable_nodes;
+  Tag deletable_nodes;
   status = mMB->tag_create("", 1, MB_TAG_BIT, deletable_nodes, NULL);
   if (MB_SUCCESS != status)
     return status;
@@ -202,14 +204,14 @@
     return status;
 
   // gather nodes that were marked
-  MBRange nodes;
+  Range nodes;
   mMB->get_entities_by_type_and_tag(0, MBVERTEX, &deletable_nodes, NULL, 1, nodes);
 
-  MBEntityHandle low_meshset;
+  EntityHandle low_meshset;
   int dum;
   low_meshset = CREATE_HANDLE(MBENTITYSET, 0, dum);
   
-  for(MBRange::iterator iter = nodes.begin(); iter != nodes.end(); ++iter)
+  for(Range::iterator iter = nodes.begin(); iter != nodes.end(); ++iter)
   {
     unsigned char marked = 0;
     mMB->tag_get_data(deletable_nodes, &(*iter), 1, &marked);
@@ -257,9 +259,9 @@
 }
 
 
-MBErrorCode HigherOrderFactory::add_mid_volume_nodes(ElementSequence* seq)
+ErrorCode HigherOrderFactory::add_mid_volume_nodes(ElementSequence* seq)
 {
-  MBEntityType this_type = seq->type();
+  EntityType this_type = seq->type();
   SequenceManager* seq_manager = mMB->sequence_manager();
 
   // find out where in the connectivity list to add these new mid volume nodes
@@ -271,10 +273,10 @@
   new_node_index += edge_factor * MBCN::mConnectivityMap[this_type][0].num_sub_elements;
   new_node_index += face_factor * MBCN::mConnectivityMap[this_type][1].num_sub_elements;
 
-  MBEntityHandle* element = seq->get_connectivity_array();
-  MBEntityHandle curr_handle = seq->start_handle();
+  EntityHandle* element = seq->get_connectivity_array();
+  EntityHandle curr_handle = seq->start_handle();
   int nodes_per_element = seq->nodes_per_element();
-  MBEntityHandle* end_element = element + nodes_per_element * (seq->size());
+  EntityHandle* end_element = element + nodes_per_element * (seq->size());
 
   // iterate over the elements
   for(; element < end_element; element+=nodes_per_element)
@@ -309,9 +311,9 @@
 }
 
 
-MBErrorCode HigherOrderFactory::add_mid_face_nodes(ElementSequence* seq)
+ErrorCode HigherOrderFactory::add_mid_face_nodes(ElementSequence* seq)
 {
-  MBEntityType this_type = seq->type();
+  EntityType this_type = seq->type();
   SequenceManager* seq_manager = mMB->sequence_manager();
   int num_vertices = MBCN::VerticesPerEntity(this_type);
   int num_edges = MBCN::mConnectivityMap[this_type][0].num_sub_elements;
@@ -320,13 +322,13 @@
 
   const MBCN::ConnMap& entity_faces = MBCN::mConnectivityMap[this_type][1];
 
-  MBEntityHandle* element = seq->get_connectivity_array();
-  MBEntityHandle curr_handle = seq->start_handle();
+  EntityHandle* element = seq->get_connectivity_array();
+  EntityHandle curr_handle = seq->start_handle();
   int nodes_per_element = seq->nodes_per_element();
-  MBEntityHandle* end_element = element + nodes_per_element * (seq->size());
+  EntityHandle* end_element = element + nodes_per_element * (seq->size());
 
-  MBEntityHandle tmp_face_conn[4];  // max face nodes = 4
-  std::vector<MBEntityHandle> adjacent_entities(4);
+  EntityHandle tmp_face_conn[4];  // max face nodes = 4
+  std::vector<EntityHandle> adjacent_entities(4);
 
   double tmp_coords[3];
   
@@ -348,7 +350,7 @@
       else
         tmp_face_conn[3] = 0;
 
-      MBEntityHandle already_made_node = center_node_exist(tmp_face_conn, adjacent_entities);
+      EntityHandle already_made_node = center_node_exist(tmp_face_conn, adjacent_entities);
       
       if(already_made_node)
       {
@@ -390,10 +392,10 @@
 }
 
 
-MBErrorCode HigherOrderFactory::add_mid_edge_nodes(ElementSequence* seq)
+ErrorCode HigherOrderFactory::add_mid_edge_nodes(ElementSequence* seq)
 {
   // for each node, need to see if it was already created.
-  MBEntityType this_type = seq->type();
+  EntityType this_type = seq->type();
   SequenceManager* seq_manager = mMB->sequence_manager();
 
   // offset by number of corner nodes
@@ -402,13 +404,13 @@
 
   const MBCN::ConnMap& entity_edges = MBCN::mConnectivityMap[this_type][0];
   
-  MBEntityHandle* element = seq->get_connectivity_array();
-  MBEntityHandle curr_handle = seq->start_handle();
+  EntityHandle* element = seq->get_connectivity_array();
+  EntityHandle curr_handle = seq->start_handle();
   int nodes_per_element = seq->nodes_per_element();
-  MBEntityHandle* end_element = element + nodes_per_element * (seq->size());
+  EntityHandle* end_element = element + nodes_per_element * (seq->size());
 
-  MBEntityHandle tmp_edge_conn[2];
-  std::vector<MBEntityHandle> adjacent_entities(32);
+  EntityHandle tmp_edge_conn[2];
+  std::vector<EntityHandle> adjacent_entities(32);
 
   double tmp_coords[3];
 
@@ -425,7 +427,7 @@
       tmp_edge_conn[0] = element[entity_edges.conn[i][0]];
       tmp_edge_conn[1] = element[entity_edges.conn[i][1]];
 
-      MBEntityHandle already_made_node = center_node_exist(tmp_edge_conn[0], tmp_edge_conn[1],
+      EntityHandle already_made_node = center_node_exist(tmp_edge_conn[0], tmp_edge_conn[1],
           adjacent_entities);
       
       if(already_made_node)
@@ -465,12 +467,12 @@
   return MB_SUCCESS;
 }
 
-MBEntityHandle HigherOrderFactory::center_node_exist( MBEntityHandle corner1, 
-    MBEntityHandle corner2, std::vector<MBEntityHandle>& adj_entities)
+EntityHandle HigherOrderFactory::center_node_exist( EntityHandle corner1, 
+    EntityHandle corner2, std::vector<EntityHandle>& adj_entities)
 {
   AEntityFactory* a_fact = mMB->a_entity_factory();
-  std::vector<MBEntityHandle> adj_corner1(32);
-  std::vector<MBEntityHandle> adj_corner2(32);
+  std::vector<EntityHandle> adj_corner1(32);
+  std::vector<EntityHandle> adj_corner2(32);
 
   // create needed vertex adjacencies
   if (!a_fact->vert_elem_adjacencies())
@@ -484,16 +486,16 @@
   // these are the entities adjacent to both nodes
   adj_entities.clear();
   std::set_intersection(adj_corner1.begin(), adj_corner1.end(), adj_corner2.begin(),
-      adj_corner2.end(), std::back_inserter<std::vector<MBEntityHandle> >(adj_entities));
+      adj_corner2.end(), std::back_inserter<std::vector<EntityHandle> >(adj_entities));
 
 
   // iterate of the entities to find a mid node
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int conn_size = 0;
-  for(std::vector<MBEntityHandle>::iterator iter = adj_entities.begin();
+  for(std::vector<EntityHandle>::iterator iter = adj_entities.begin();
       iter != adj_entities.end(); )
   {
-    MBEntityType this_type = TYPE_FROM_HANDLE(*iter);
+    EntityType this_type = TYPE_FROM_HANDLE(*iter);
     if (this_type == MBENTITYSET) {
       ++iter;
       continue;
@@ -522,11 +524,11 @@
 
 }
 
-MBEntityHandle HigherOrderFactory::center_node_exist( MBEntityHandle corners[4], 
-    std::vector<MBEntityHandle>& adj_entities)
+EntityHandle HigherOrderFactory::center_node_exist( EntityHandle corners[4], 
+    std::vector<EntityHandle>& adj_entities)
 {
   AEntityFactory* a_fact = mMB->a_entity_factory();
-  std::vector<MBEntityHandle> adj_corner[4];
+  std::vector<EntityHandle> adj_corner[4];
   int num_nodes = corners[3] == 0 ? 3 : 4;
   int i = 0;
 
@@ -543,19 +545,19 @@
   {
     adj_entities.clear();
     std::set_intersection(adj_corner[i-1].begin(), adj_corner[i-1].end(), adj_corner[i].begin(),
-      adj_corner[i].end(), std::back_inserter<std::vector<MBEntityHandle> >(adj_entities));
+      adj_corner[i].end(), std::back_inserter<std::vector<EntityHandle> >(adj_entities));
     adj_corner[i].swap(adj_entities);
   }
   adj_entities.swap(adj_corner[i-1]);
   
 
   // iterate of the entities to find a mid node
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int conn_size = 0;
-  for(std::vector<MBEntityHandle>::iterator iter = adj_entities.begin();
+  for(std::vector<EntityHandle>::iterator iter = adj_entities.begin();
       iter != adj_entities.end(); )
   {
-    MBEntityType this_type = TYPE_FROM_HANDLE(*iter);
+    EntityType this_type = TYPE_FROM_HANDLE(*iter);
     if (this_type == MBENTITYSET) {
       ++iter;
       continue;
@@ -618,9 +620,9 @@
 
 }
 
-bool HigherOrderFactory::add_center_node(MBEntityType this_type, MBEntityHandle* element_conn, 
-    int conn_size, MBEntityHandle corner_node1, MBEntityHandle corner_node2, 
-    MBEntityHandle center_node)
+bool HigherOrderFactory::add_center_node(EntityType this_type, EntityHandle* element_conn, 
+    int conn_size, EntityHandle corner_node1, EntityHandle corner_node2, 
+    EntityHandle center_node)
 {
   int first_node = std::find(element_conn, element_conn+conn_size, corner_node1) - element_conn;
   int second_node = std::find(element_conn, element_conn+conn_size, corner_node2) - element_conn;
@@ -631,14 +633,14 @@
   return true;
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::copy_corner_nodes( ElementSequence* src, ElementSequence* dst )
 {
   unsigned num_corners = MBCN::VerticesPerEntity( src->type() );
   return copy_nodes( src, dst, num_corners, 0, 0 );
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::copy_mid_edge_nodes( ElementSequence* src, ElementSequence* dst )
 {
   if (!src->has_mid_edge_nodes() || !dst->has_mid_edge_nodes())
@@ -649,7 +651,7 @@
   return copy_nodes( src, dst, num_edges, num_corners, num_corners );
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::copy_mid_face_nodes( ElementSequence* src, ElementSequence* dst )
 {
   if (!src->has_mid_face_nodes() || !dst->has_mid_face_nodes())
@@ -666,7 +668,7 @@
 }
 
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::copy_mid_volume_nodes( ElementSequence* src, ElementSequence* dst )
 {
   if (!src->has_mid_volume_nodes() || !dst->has_mid_volume_nodes())
@@ -685,7 +687,7 @@
   return copy_nodes( src, dst, 1, src_offset, dst_offset );
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::copy_nodes( ElementSequence* src,
                                 ElementSequence* dst,
                                 unsigned nodes_per_elem,
@@ -697,8 +699,8 @@
 
   unsigned src_stride = src->nodes_per_element();
   unsigned dst_stride = dst->nodes_per_element();
-  MBEntityHandle* src_conn = src->get_connectivity_array();
-  MBEntityHandle* dst_conn = dst->get_connectivity_array();
+  EntityHandle* src_conn = src->get_connectivity_array();
+  EntityHandle* dst_conn = dst->get_connectivity_array();
   if (!src_conn || !dst_conn)
     return MB_FAILURE;
   
@@ -707,8 +709,8 @@
     return MB_FAILURE;
   
   src_conn += (dst->start_handle() - src->start_handle()) * src_stride;
-  MBEntityID count = dst->size();
-  for (MBEntityID i = 0; i < count; ++i) {
+  EntityID count = dst->size();
+  for (EntityID i = 0; i < count; ++i) {
     for (unsigned j = 0; j < nodes_per_elem; ++j)
       dst_conn[j+dst_offset] = src_conn[j+src_offset];
     src_conn += src_stride; 
@@ -718,11 +720,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::remove_mid_edge_nodes( ElementSequence* seq, 
-                                           MBEntityHandle start,
-                                           MBEntityHandle end,
-                                           MBTag deletable_nodes )
+                                           EntityHandle start,
+                                           EntityHandle end,
+                                           Tag deletable_nodes )
 {
   int count;
   int offset;
@@ -739,11 +741,11 @@
 }
 
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::remove_mid_face_nodes( ElementSequence* seq, 
-                                           MBEntityHandle start,
-                                           MBEntityHandle end,
-                                           MBTag deletable_nodes )
+                                           EntityHandle start,
+                                           EntityHandle end,
+                                           Tag deletable_nodes )
 {
   int count;
   if (MBCN::Dimension(seq->type()) == 2)
@@ -757,11 +759,11 @@
   return remove_ho_nodes( seq, start, end, count, offset, deletable_nodes );
 }
 
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::remove_mid_volume_nodes( ElementSequence* seq, 
-                                             MBEntityHandle start,
-                                             MBEntityHandle end,
-                                             MBTag deletable_nodes )
+                                             EntityHandle start,
+                                             EntityHandle end,
+                                             Tag deletable_nodes )
 {
   int offset = MBCN::VerticesPerEntity( seq->type() );
   if (seq->has_mid_edge_nodes())
@@ -790,26 +792,26 @@
  * version 2.1 of the License, or (at your option) any later version.
  * 
  */
-MBErrorCode 
+ErrorCode 
 HigherOrderFactory::remove_ho_nodes( ElementSequence* seq,
-                                     MBEntityHandle start,
-                                     MBEntityHandle end,
+                                     EntityHandle start,
+                                     EntityHandle end,
                                      int nodes_per_elem,
                                      int elem_conn_offset,
-                                     MBTag deletable_nodes )
+                                     Tag deletable_nodes )
 {
   if (start < seq->start_handle() || end > seq->end_handle())
     return MB_ENTITY_NOT_FOUND;
-  MBEntityHandle* array = seq->get_connectivity_array();
+  EntityHandle* array = seq->get_connectivity_array();
   if (!array)
     return MB_NOT_IMPLEMENTED;
    
-  std::set<MBEntityHandle> nodes_processed;
-  for (MBEntityHandle i = start; i <= end; ++i) {  // for each element
+  std::set<EntityHandle> nodes_processed;
+  for (EntityHandle i = start; i <= end; ++i) {  // for each element
     for (int j = 0; j < nodes_per_elem; ++j) {  // for each HO node to remove
-      const MBEntityID elem = (i - seq->start_handle()); // element index
+      const EntityID elem = (i - seq->start_handle()); // element index
       const int conn_idx = j + elem_conn_offset;
-      const MBEntityID index = elem * seq->nodes_per_element() + conn_idx;
+      const EntityID index = elem * seq->nodes_per_element() + conn_idx;
       if (array[index] && nodes_processed.insert( array[index] ).second) {
         if (tag_for_deletion( i, conn_idx, seq )) {
           unsigned char bit = 0x1;
@@ -823,12 +825,12 @@
 }
 
 bool
-HigherOrderFactory::tag_for_deletion( MBEntityHandle parent_handle,
+HigherOrderFactory::tag_for_deletion( EntityHandle parent_handle,
                                       int conn_index,
                                       ElementSequence* seq )
 {
   //get type of this sequence
-  MBEntityType this_type = seq->type();
+  EntityType this_type = seq->type();
 
   //get dimension of 'parent' element
   int this_dimension = mMB->dimension_from_handle( parent_handle );
@@ -846,19 +848,19 @@
 
   //could be a mid-volume/face/edge node on a hex/face/edge respectively
   //if so...delete it bc/ no one else owns it too
-  std::vector<MBEntityHandle> connectivity;
+  std::vector<EntityHandle> connectivity;
   if( dimension == this_dimension && side_number == 0 )
     delete_node = true;
   else //the node could also be on a lower order entity of 'tmp_entity' 
   {
     //get 'side' of 'parent_handle' that node is on 
-    MBEntityHandle target_entity = 0;
+    EntityHandle target_entity = 0;
     mMB->side_element( parent_handle, dimension, side_number, target_entity );
 
     if( target_entity )
     {
       AEntityFactory *a_fact = mMB->a_entity_factory();
-      MBEntityHandle low_meshset;
+      EntityHandle low_meshset;
       int dum;
       low_meshset = CREATE_HANDLE(MBENTITYSET, 0, dum);
 
@@ -867,12 +869,12 @@
       mMB->get_connectivity(&( target_entity), 1, connectivity, true  );
 
       //for each node, get all common adjacencies of nodes in 'parent_handle' 
-      std::vector<MBEntityHandle> adj_list_1, adj_list_2, adj_entities;
+      std::vector<EntityHandle> adj_list_1, adj_list_2, adj_entities;
       a_fact->get_adjacencies(connectivity[0], adj_list_1);
 
       // remove meshsets
       adj_list_1.erase(std::remove_if(adj_list_1.begin(), adj_list_1.end(), 
-           std::bind2nd(std::greater<MBEntityHandle>(),low_meshset)), adj_list_1.end());
+           std::bind2nd(std::greater<EntityHandle>(),low_meshset)), adj_list_1.end());
 
       size_t i; 
       for( i=1; i<connectivity.size(); i++)
@@ -882,13 +884,13 @@
 
         // remove meshsets
         adj_list_2.erase(std::remove_if(adj_list_2.begin(), adj_list_2.end(), 
-             std::bind2nd(std::greater<MBEntityHandle>(),low_meshset)), adj_list_2.end());
+             std::bind2nd(std::greater<EntityHandle>(),low_meshset)), adj_list_2.end());
        
         //intersect the 2 lists 
         adj_entities.clear();
         std::set_intersection(adj_list_1.begin(), adj_list_1.end(), 
                               adj_list_2.begin(), adj_list_2.end(), 
-                              std::back_inserter< std::vector<MBEntityHandle> >(adj_entities));
+                              std::back_inserter< std::vector<EntityHandle> >(adj_entities));
         adj_list_1.clear();
         adj_list_1 = adj_entities;
       } 
@@ -914,3 +916,6 @@
 
   return delete_node;
 }
+  
+} // namespace moab
+

Modified: MOAB/trunk/src/HomXform.cpp
===================================================================
--- MOAB/trunk/src/HomXform.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/HomXform.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,9 +13,11 @@
  * 
  */
 
-#include "HomXform.hpp"
-#include "assert.h"
+#include "moab/HomXform.hpp"
+#include <assert.h>
 
+namespace moab {
+
 HomCoord HomCoord::unitv[3] = {HomCoord(1,0,0), HomCoord(0,1,0), HomCoord(0,0,1)};
 HomCoord HomCoord::IDENTITY(1, 1, 1);
 
@@ -126,9 +128,14 @@
          (q2 == p2 * *this) &&
          (q3 == p3 * *this));
 }
+  
+} // namespace moab
 
+
 #ifdef TEST
 
+using namespace moab;
+
 #include <iostream>
 
 // unit test for the HomCoord and HomXform classes

Copied: MOAB/trunk/src/Internals.hpp (from rev 3583, MOAB/trunk/src/MBInternals.hpp)
===================================================================
--- MOAB/trunk/src/Internals.hpp	                        (rev 0)
+++ MOAB/trunk/src/Internals.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,123 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+#ifndef MB_INTERNALS_HPP
+#define MB_INTERNALS_HPP
+
+#ifdef WIN32
+#pragma warning(disable : 4786)
+#endif
+
+#ifndef IS_BUILDING_MB
+#error "Internals.hpp isn't supposed to be included into an application"
+#endif
+
+#include "moab/Types.hpp"
+#include <assert.h>
+
+namespace moab {
+
+/*! Define EntityHandle for both 32 bit and 64 bit systems.
+ *  The decision to use 64 bit handles must be made at compile time.
+ *  \bug we should probably have an Int64 typedef
+ *
+ *  EntityHandle format:
+ *  0xXYYYYYYY  (assuming a 32-bit handle.  Top 4 bits reserved on a 64 bit system)
+ *  X - reserved for entity type.  This system can only handle 15 different types
+ *  Y - Entity id space.  Max id is over 200M
+ *
+ *  Note that for specialized databases (such as all hex) 16 bits are not
+ *  required for the entity type and the id space can be increased to over 2B.
+ */
+#define MB_TYPE_WIDTH 4
+#define MB_ID_WIDTH (8*sizeof(EntityHandle)-MB_TYPE_WIDTH)
+#define MB_TYPE_MASK ((EntityHandle)0xF << MB_ID_WIDTH)
+//             2^MB_TYPE_WIDTH-1 ------^
+
+#define MB_START_ID ((EntityID)1)        //!< All entity id's currently start at 1
+#define MB_END_ID ((EntityID)MB_ID_MASK) //!< Last id is the complement of the MASK
+#define MB_ID_MASK (~MB_TYPE_MASK)
+
+//! Given a type and an id create a handle.  
+inline EntityHandle CREATE_HANDLE(const unsigned type, const EntityID id, int& err) 
+{
+  err = 0; //< Assume that there is a real error value defined somewhere
+
+  if (id > MB_END_ID || type > MBMAXTYPE)
+  {
+    err = 1;   //< Assume that there is a real error value defined somewhere
+    return 1;  //<You've got to return something.  What do you return?
+  }
+  
+  return (((EntityHandle)type) << MB_ID_WIDTH)|id;
+}
+
+inline EntityHandle CREATE_HANDLE( const unsigned type, const EntityID id )
+{
+  assert( id <= MB_END_ID && type <= MBMAXTYPE );
+  return (((EntityHandle)type) << MB_ID_WIDTH)|id;
+}
+
+inline EntityHandle FIRST_HANDLE( unsigned type )
+  { return (((EntityHandle)type) << MB_ID_WIDTH)|MB_START_ID; }
+
+inline EntityHandle LAST_HANDLE( unsigned type )
+  { return ((EntityHandle)(type+1) << MB_ID_WIDTH) - 1; }
+
+//! Get the entity id out of the handle.
+inline EntityID ID_FROM_HANDLE (EntityHandle handle)
+{
+  return (handle & MB_ID_MASK);
+}
+
+//! Get the type out of the handle.  Can do a simple shift because
+//! handles are unsigned (therefore shifting fills with zero's)
+inline EntityType TYPE_FROM_HANDLE(EntityHandle handle) 
+{
+  return static_cast<EntityType> (handle >> MB_ID_WIDTH);
+}
+
+typedef unsigned long TagId;
+
+/* Tag format
+ * 0xXXZZZZZZ  ( 32 bits total )
+ * Z - reserved for internal sub-tag id
+ * X - reserved for internal properties & lookup speed
+ */
+#define MB_TAG_PROP_WIDTH 2
+#define MB_TAG_SHIFT_WIDTH (8*sizeof(TagId)-MB_TAG_PROP_WIDTH)
+#define MB_TAG_PROP_MASK (~((TagId)0x3 << MB_TAG_SHIFT_WIDTH))
+//        2^MB_TAG_PROP_WIDTH-1 ------^
+
+inline unsigned long ID_FROM_TAG_HANDLE(Tag tag_handle) 
+{
+  return static_cast<TagId>( (TagId)tag_handle & MB_TAG_PROP_MASK );
+}
+
+inline TagType PROP_FROM_TAG_HANDLE(Tag tag_handle)
+{
+  return static_cast<TagType>( (TagId)tag_handle >> MB_TAG_SHIFT_WIDTH );
+}
+
+inline Tag TAG_HANDLE_FROM_ID(TagId tag_id, TagType prop) 
+{
+//  assert( tag_id <= MB_TAG_PROP_MASK );
+  return reinterpret_cast<Tag>( ((TagId)prop)<<MB_TAG_SHIFT_WIDTH | tag_id );
+}  
+
+} // namespace moab
+
+#endif

Deleted: MOAB/trunk/src/MBAdaptiveKDTree.cpp
===================================================================
--- MOAB/trunk/src/MBAdaptiveKDTree.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBAdaptiveKDTree.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,2119 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBAdaptiveKDTree.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2007-04-1
- */
-
-#include "MBAdaptiveKDTree.hpp"
-#include "MBInterface.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-
-#include <assert.h>
-#include <algorithm>
-#include <limits>
-
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#  include <float.h>
-#  define finite(A) _finite(A)
-#endif
-
-MBAdaptiveKDTree::Settings::Settings()
-  : maxEntPerLeaf(6), 
-    maxTreeDepth(30),
-    candidateSplitsPerDir(3),
-    candidatePlaneSet(SUBDIVISION_SNAP),
-    minBoxWidth( 1e-10 )
-  {}
-
-
-#define MB_AD_KD_TREE_DEFAULT_TAG_NAME "AKDTree"
-
-// If defined, use single tag for both axis and location of split plane
-#define MB_AD_KD_TREE_USE_SINGLE_TAG 
-
-// No effect if MB_AD_KD_TREE_USE_SINGLE_TAG is not defined.
-// If defined, store plane axis as double so tag has consistent
-// type (doubles for both location and axis).  If not defined,
-// store struct Plane as opaque.
-#define MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG
-
-#if defined(MB_AD_KD_TREE_USE_SINGLE_TAG) && defined(HDF5_FILE)
-  /* include our MPI header before any HDF5 because otherwise
-     it will get included indirectly by HDF5 */
-# ifdef USE_MPI
-#  include "MBmpi.h"
-# endif 
-# include <H5Tpublic.h>
-#endif
-
-#define MAKE_TAG( NAME, STORAGE, TYPE, COUNT, HANDLE, DEFAULT ) \
-  if (MB_SUCCESS != make_tag( moab(), \
-                              (NAME), \
-                              (STORAGE), \
-                              (TYPE), \
-                              (COUNT), \
-                              (DEFAULT), \
-                              (HANDLE), \
-                              ctl )) { \
-    planeTag = axisTag = rootTag = (MBTag)-1; \
-    return; \
-  }
-
-static MBErrorCode make_tag( MBInterface* iface,
-                             std::string name,
-                             MBTagType storage, 
-                             MBDataType type,
-                             int count,
-                             void* default_val,
-                             MBTag& tag_handle,
-                             std::vector<MBTag>& created_tags )
-{
-  int size;
-  switch (type) {
-    case MB_TYPE_DOUBLE:  size = sizeof(double);         break;
-    case MB_TYPE_INTEGER: size = sizeof(int);            break;
-    case MB_TYPE_OPAQUE:  size = 1;                      break;
-    case MB_TYPE_HANDLE:  size = sizeof(MBEntityHandle); break;
-    default: return MB_FAILURE;
-  }
-  size *= count;
-  
-  MBErrorCode rval = iface->tag_create( name.c_str(),
-                                        size,
-                                        storage,
-                                        type,
-                                        tag_handle,
-                                        default_val,
-                                        false );
-  if (MB_SUCCESS == rval) 
-    created_tags.push_back( tag_handle );
-  else if (MB_ALREADY_ALLOCATED == rval)
-    rval = iface->tag_create( name.c_str(),
-                              size,
-                              MB_TAG_DENSE,
-                              type,
-                              tag_handle,
-                              default_val,
-                              true );
-
-  if (MB_SUCCESS != rval)
-    while( !created_tags.empty() ) {
-      iface->tag_delete( created_tags.back() );
-      created_tags.pop_back();
-    }
-  
-  return rval;
-}
-
-MBAdaptiveKDTree::MBAdaptiveKDTree( MBInterface* mb, const char* tagname, unsigned set_flags )
-  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(false)
-{ init(tagname); }
-
-MBAdaptiveKDTree::MBAdaptiveKDTree( MBInterface* mb, bool clean_up, const char* tagname, unsigned set_flags )
-  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(clean_up)
-{ init(tagname); }
-
-void MBAdaptiveKDTree::init( const char* tagname_in )
-{
-  const char* tagname = tagname_in ? tagname_in : MB_AD_KD_TREE_DEFAULT_TAG_NAME;
-  std::vector<MBTag> ctl;
-
-#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
-    // create two tags, one for axis direction and one for axis coordinate
-  std::string n1(tagname), n2(tagname);
-  n1 += "_coord";
-  n2 += "_norm";
-  MAKE_TAG( n1, MB_TAG_DENSE, MB_TYPE_DOUBLE, 1, planeTag, 0 )
-  MAKE_TAG( n2, MB_TAG_DENSE, MB_TYPE_INT,    1, axisTag,  0 )
-
-#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
-    // create tag to hold two doubles, one for location and one for axis
-  MAKE_TAG( tagname, MB_TAG_DENSE, MB_TYPE_DOUBLE, 2, planeTag, 0 )
-#else
-    // create opaque tag to hold struct Plane
-  MAKE_TAG( tagname, MB_TAG_DENSE, MB_TYPE_OPAQUE, sizeof(Plane), planeTag, 0 )
-
-#ifdef HDF5_FILE  
-    // create a mesh tag holding the HDF5 type for a struct Plane
-  MBTag type_tag;
-  std::string type_tag_name = "__hdf5_tag_type_";
-  type_tag_name += tagname;
-  MAKE_TAG( type_tag_name, MB_TAG_MESH), MB_TYPE_OPAQUE, sizeof(hid_t), type_tag, 0 )
-    // create HDF5 type object describing struct Plane
-  Plane p;
-  hid_t handle = H5Tcreate( H5T_COMPOUND, sizeof(Plane) );
-  H5Tinsert( handle, "coord", &(p.coord) - &p, H5T_NATIVE_DOUBLE );
-  H5Tinsert( handle, "norm", &(p.axis) - &p, H5T_NATIVE_INT );
-  mbInstance->tag_set_data( type_tag, 0, 0, &handle );
-#endif
-#endif
-
-  std::string root_name(tagname);
-  root_name += "_box";
-  MAKE_TAG( root_name, MB_TAG_SPARSE, MB_TYPE_DOUBLE, 6, rootTag, 0 )
-}
-
-MBErrorCode MBAdaptiveKDTree::get_split_plane( MBEntityHandle entity,
-                                               Plane& plane )
-{
-#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
-  MBErrorCode r1, r2;
-  r1 = moab()->tag_get_data( planeTag, &entity, 1, &plane.coord );
-  r2 = moab()->tag_get_data( axisTag , &entity, 1, &plane.norm  );
-  return MB_SUCCESS == r1 ? r2 : r1;
-#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
-  double values[2];
-  MBErrorCode rval = moab()->tag_get_data( planeTag, &entity, 1, values );
-  plane.coord = values[0];
-  plane.norm = (int)values[1];
-  return rval;
-#else
-  return moab()->tag_get_data( planeTag, &entity, 1, &plane );
-#endif
-}
-
-MBAdaptiveKDTree::~MBAdaptiveKDTree()
-{
-  if (!cleanUpTrees)
-    return;
-    
-  while (!createdTrees.empty()) {
-    MBEntityHandle tree = createdTrees.back();
-      // make sure this is a tree (rather than some other, stale handle)
-    const void* data_ptr = 0;
-    MBErrorCode rval = moab()->tag_get_data( rootTag, &tree, 1, &data_ptr );
-    if (MB_SUCCESS == rval)
-      rval = delete_tree( tree );
-    if (MB_SUCCESS != rval)
-      createdTrees.pop_back();
-  }
-}
-
-MBErrorCode MBAdaptiveKDTree::set_split_plane( MBEntityHandle entity, 
-                                               const Plane& plane )
-{
-#ifndef MB_AD_KD_TREE_USE_SINGLE_TAG
-  MBErrorCode r1, r2;
-  r1 = moab()->tag_set_data( planeTag, &entity, 1, &plane.coord );
-  r2 = moab()->tag_set_data( axisTag , &entity, 1, &plane.norm  );
-  return MB_SUCCESS == r1 ? r2 : r1;
-#elif defined(MB_AD_KD_TREE_USE_TWO_DOUBLE_TAG)
-  double values[2] = { plane.coord, plane.norm };
-  return moab()->tag_set_data( planeTag, &entity, 1, values );
-#else
-  return moab()->tag_set_data( planeTag, &entity, 1, &plane );
-#endif
-}
-
-
-MBErrorCode MBAdaptiveKDTree::set_tree_box( MBEntityHandle root_handle,
-                                            const double box_min[3],
-                                            const double box_max[3] )
-{
-  const double box[6] = { box_min[0], box_min[1], box_min[2],
-                          box_max[0], box_max[1], box_max[2] };
-  return moab()->tag_set_data( rootTag, &root_handle, 1, box );
-}
-
-MBErrorCode MBAdaptiveKDTree::get_tree_box( MBEntityHandle root_handle,
-                                            double box_min_out[3],
-                                            double box_max_out[3] )
-{
-  double box[6];
-  MBErrorCode rval = moab()->tag_get_data( rootTag, &root_handle, 1, box );
-  box_min_out[0] = box[0]; box_min_out[1] = box[1]; box_min_out[2] = box[2];
-  box_max_out[0] = box[3]; box_max_out[1] = box[4]; box_max_out[2] = box[5];
-  return rval;
-}
-
-
-MBErrorCode MBAdaptiveKDTree::create_tree( const double box_min[3],
-                                           const double box_max[3],
-                                           MBEntityHandle& root_handle )
-{
-  MBErrorCode rval = moab()->create_meshset( meshSetFlags, root_handle );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = set_tree_box( root_handle, box_min, box_max );
-  if (MB_SUCCESS != rval) {
-    moab()->delete_entities( &root_handle, 1 );
-    root_handle = 0;
-    return rval;
-  }
-  
-  createdTrees.push_back( root_handle );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTree::delete_tree( MBEntityHandle root_handle )
-{
-  MBErrorCode rval;
-  
-  std::vector<MBEntityHandle> children, dead_sets, current_sets;
-  createdTrees.erase( 
-        std::remove( createdTrees.begin(), createdTrees.end(), root_handle ),
-        createdTrees.end() );
-  
-  current_sets.push_back( root_handle );
-  while (!current_sets.empty()) {
-    MBEntityHandle set = current_sets.back();
-    current_sets.pop_back();
-    dead_sets.push_back( set );
-    rval = moab()->get_child_meshsets( set, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-    std::copy( children.begin(), children.end(), std::back_inserter(current_sets) );
-    children.clear();
-  }
-  
-  rval = moab()->tag_delete_data( rootTag, &root_handle, 1 );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  return moab()->delete_entities( &dead_sets[0], dead_sets.size() );
-}
-
-MBErrorCode MBAdaptiveKDTree::find_all_trees( MBRange& results )
-{
-  return moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, 
-                                               &rootTag, 0, 1,
-                                               results );
-}
-
-MBErrorCode MBAdaptiveKDTree::get_tree_iterator( MBEntityHandle root,
-                                                 MBAdaptiveKDTreeIter& iter )
-{
-  double box[6];
-  MBErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, box );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  return get_sub_tree_iterator( root, box, box+3, iter );
-}
-
-MBErrorCode MBAdaptiveKDTree::get_last_iterator( MBEntityHandle root,
-                                                 MBAdaptiveKDTreeIter& iter )
-{
-  double box[6];
-  MBErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, box );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  return iter.initialize( this, root, box, box+3, MBAdaptiveKDTreeIter::RIGHT );
-}
-
-MBErrorCode MBAdaptiveKDTree::get_sub_tree_iterator( MBEntityHandle root,
-                                                     const double min[3], 
-                                                     const double max[3],
-                                                     MBAdaptiveKDTreeIter& result ) 
-{
-  return result.initialize( this, root, min, max, MBAdaptiveKDTreeIter::LEFT );
-}
-
-MBErrorCode MBAdaptiveKDTree::split_leaf( MBAdaptiveKDTreeIter& leaf,
-                                          Plane plane,
-                                          MBEntityHandle& left,
-                                          MBEntityHandle& right )
-{
-  MBErrorCode rval;
-  
-  rval = moab()->create_meshset( meshSetFlags, left );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = moab()->create_meshset( meshSetFlags, right );
-  if (MB_SUCCESS != rval) {
-    moab()->delete_entities( &left, 1 );
-    return rval;
-  }
-  
-  if (MB_SUCCESS != set_split_plane( leaf.handle(), plane ) ||
-      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), left ) ||
-      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), right) ||
-      MB_SUCCESS != leaf.step_to_first_leaf(MBAdaptiveKDTreeIter::LEFT)) {
-    MBEntityHandle children[] = { left, right };
-    moab()->delete_entities( children, 2 );
-    return MB_FAILURE;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTree::split_leaf( MBAdaptiveKDTreeIter& leaf,
-                                          Plane plane )
-{
-  MBEntityHandle left, right;
-  return split_leaf( leaf, plane, left, right );
-}
-
-MBErrorCode MBAdaptiveKDTree::split_leaf( MBAdaptiveKDTreeIter& leaf, 
-                                          Plane plane,
-                                          const MBRange& left_entities,
-                                          const MBRange& right_entities )
-{
-  MBEntityHandle left, right, parent = leaf.handle();
-  MBErrorCode rval = split_leaf( leaf, plane, left, right );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (MB_SUCCESS == moab()->add_entities( left, left_entities ) &&
-      MB_SUCCESS == moab()->add_entities(right,right_entities ) &&
-      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
-    return MB_SUCCESS;
-  
-  moab()->remove_child_meshset( parent, left );
-  moab()->remove_child_meshset( parent, right );
-  MBEntityHandle children[] = { left, right };
-  moab()->delete_entities( children, 2 );
-  return MB_FAILURE;
-}
-
-MBErrorCode MBAdaptiveKDTree::split_leaf( MBAdaptiveKDTreeIter& leaf, 
-                                          Plane plane,
-                                          const std::vector<MBEntityHandle>& left_entities,
-                                          const std::vector<MBEntityHandle>& right_entities )
-{
-  MBEntityHandle left, right, parent = leaf.handle();
-  MBErrorCode rval = split_leaf( leaf, plane, left, right );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (MB_SUCCESS == moab()->add_entities( left, &left_entities[0], left_entities.size() ) &&
-      MB_SUCCESS == moab()->add_entities(right,&right_entities[0],right_entities.size() ) &&
-      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
-    return MB_SUCCESS;
-  
-  moab()->remove_child_meshset( parent, left );
-  moab()->remove_child_meshset( parent, right );
-  MBEntityHandle children[] = { left, right };
-  moab()->delete_entities( children, 2 );
-  return MB_FAILURE;
-}
-
-MBErrorCode MBAdaptiveKDTree::merge_leaf( MBAdaptiveKDTreeIter& iter )
-{
-  MBErrorCode rval;
-  if (iter.depth() == 1) // at root
-    return MB_FAILURE;
-  
-    // Move iter to parent
-  
-  MBAdaptiveKDTreeIter::StackObj node = iter.mStack.back();
-  iter.mStack.pop_back();
-  
-  iter.childVect.clear();
-  rval = moab()->get_child_meshsets( iter.mStack.back().entity, iter.childVect );
-  if (MB_SUCCESS != rval)
-    return rval;
-  Plane plane;
-  rval = get_split_plane( iter.mStack.back().entity, plane );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  int child_idx = iter.childVect[0] == node.entity ? 0 : 1;
-  assert(iter.childVect[child_idx] == node.entity);
-  iter.mBox[1-child_idx][plane.norm] = node.coord;
-  
-
-    // Get all entities from children and put them in parent
-  MBEntityHandle parent = iter.handle();
-  moab()->remove_child_meshset( parent, iter.childVect[0] );
-  moab()->remove_child_meshset( parent, iter.childVect[1] );
-  std::vector<MBEntityHandle> stack( iter.childVect );
-  
-  MBRange range;
-  while (!stack.empty()) {
-    MBEntityHandle h = stack.back();
-    stack.pop_back();
-    range.clear();
-    rval = moab()->get_entities_by_handle( h, range );
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = moab()->add_entities( parent, range );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    iter.childVect.clear();
-    moab()->get_child_meshsets( h, iter.childVect );
-    if (!iter.childVect.empty()) {
-     moab()->remove_child_meshset( h, iter.childVect[0] );
-     moab()->remove_child_meshset( h, iter.childVect[1] );
-     stack.push_back( iter.childVect[0] );
-     stack.push_back( iter.childVect[1] );
-    }
-  
-    rval = moab()->delete_entities( &h, 1 );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-
-  
-
-MBErrorCode MBAdaptiveKDTreeIter::initialize( MBAdaptiveKDTree* tool,
-                                              MBEntityHandle root,
-                                              const double box_min[3],
-                                              const double box_max[3],
-                                              Direction direction )
-{
-  mStack.clear();
-  treeTool = tool;
-  mBox[BMIN][0] = box_min[0];
-  mBox[BMIN][1] = box_min[1];
-  mBox[BMIN][2] = box_min[2];
-  mBox[BMAX][0] = box_max[0];
-  mBox[BMAX][1] = box_max[1];
-  mBox[BMAX][2] = box_max[2];
-  mStack.push_back( StackObj(root,0) );
-  return step_to_first_leaf( direction );
-}
-
-MBErrorCode MBAdaptiveKDTreeIter::step_to_first_leaf( Direction direction )
-{
-  MBErrorCode rval;
-  MBAdaptiveKDTree::Plane plane;
-  const Direction opposite = static_cast<Direction>(1-direction);
-  
-  for (;;) {
-    childVect.clear();
-    rval = treeTool->moab()->get_child_meshsets( mStack.back().entity, childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (childVect.empty()) // leaf
-      break;
-  
-    rval = treeTool->get_split_plane( mStack.back().entity, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-  
-    mStack.push_back( StackObj(childVect[direction],mBox[opposite][plane.norm]) );
-    mBox[opposite][plane.norm] = plane.coord;
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTreeIter::step( Direction direction )
-{
-  StackObj node, parent;
-  MBErrorCode rval;
-  MBAdaptiveKDTree::Plane plane;
-  const Direction opposite = static_cast<Direction>(1-direction);
-  
-    // If stack is empty, then either this iterator is uninitialized
-    // or we reached the end of the iteration (and return 
-    // MB_ENTITY_NOT_FOUND) already.
-  if (mStack.empty())
-    return MB_FAILURE;
-    
-    // Pop the current node from the stack.
-    // The stack should then contain the parent of the current node.
-    // If the stack is empty after this pop, then we've reached the end.
-  node = mStack.back();
-  mStack.pop_back();
-  
-  while(!mStack.empty()) {
-      // Get data for parent entity
-    parent = mStack.back();
-    childVect.clear();
-    rval = treeTool->moab()->get_child_meshsets( parent.entity, childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = treeTool->get_split_plane( parent.entity, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-      // If we're at the left child
-    if (childVect[opposite] == node.entity) {
-        // change from box of left child to box of parent
-      mBox[direction][plane.norm] = node.coord;
-        // push right child on stack
-      node.entity = childVect[direction];
-      node.coord = mBox[opposite][plane.norm];
-      mStack.push_back( node );
-        // change from box of parent to box of right child
-      mBox[opposite][plane.norm] = plane.coord;
-        // descend to left-most leaf of the right child
-      return step_to_first_leaf(opposite);
-    }
-    
-      // The current node is the right child of the parent,
-      // continue up the tree.
-    assert( childVect[direction] == node.entity );
-    mBox[opposite][plane.norm] = node.coord;
-    node = parent;
-    mStack.pop_back();
-  }
-  
-  return MB_ENTITY_NOT_FOUND;
-}
-
-MBErrorCode MBAdaptiveKDTreeIter::get_neighbors( 
-                      MBAdaptiveKDTree::Axis norm, bool neg,
-                      std::vector<MBAdaptiveKDTreeIter>& results,
-                      double epsilon ) const
-{
-  StackObj node, parent;
-  MBErrorCode rval;
-  MBAdaptiveKDTree::Plane plane;
-  int child_idx;
-  
-    // Find tree node at which the specified side of the box
-    // for this node was created.
-  MBAdaptiveKDTreeIter iter( *this ); // temporary iterator (don't modifiy *this)
-  node = iter.mStack.back();
-  iter.mStack.pop_back();
-  for (;;) {
-      // reached the root - original node was on boundary (no neighbors)
-    if (iter.mStack.empty())
-      return MB_SUCCESS;
-    
-      // get parent node data
-    parent = iter.mStack.back();
-    iter.childVect.clear();
-    rval = treeTool->moab()->get_child_meshsets( parent.entity, iter.childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = treeTool->get_split_plane( parent.entity, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    child_idx = iter.childVect[0] == node.entity ? 0 : 1;
-    assert(iter.childVect[child_idx] == node.entity);
-    
-      // if we found the split plane for the desired side
-      // push neighbor on stack and stop
-    if (plane.norm == norm && (int)neg == child_idx) {
-        // change from box of previous child to box of parent
-      iter.mBox[1-child_idx][plane.norm] = node.coord;
-        // push other child of parent onto stack
-      node.entity = iter.childVect[1-child_idx];
-      node.coord = iter.mBox[child_idx][plane.norm];
-      iter.mStack.push_back( node );
-        // change from parent box to box of new child
-      iter.mBox[child_idx][plane.norm] = plane.coord;
-      break;
-    }
-    
-      // continue up the tree
-    iter.mBox[1-child_idx][plane.norm] = node.coord;
-    node = parent;
-    iter.mStack.pop_back();
-  }
-
-    // now move down tree, searching for adjacent boxes
-  std::vector<MBAdaptiveKDTreeIter> list;
-    // loop over all potential paths to neighbors (until list is empty)
-  for (;;) {
-      // follow a single path to a leaf, append any other potential
-      // paths to neighbors to 'list'
-    node = iter.mStack.back();
-    for (;;) { 
-      iter.childVect.clear();
-      rval = treeTool->moab()->get_child_meshsets( node.entity, iter.childVect );
-      if (MB_SUCCESS != rval)
-        return rval;
-        
-        // if leaf
-      if (iter.childVect.empty()) {
-        results.push_back( iter );
-        break; 
-      }
-      
-      rval = treeTool->get_split_plane( node.entity, plane );
-      if (MB_SUCCESS != rval)
-        return rval;
-     
-        // if split parallel to side
-      if (plane.norm == norm) {
-          // continue with whichever child is on the correct side of the split
-        node.entity = iter.childVect[neg];
-        node.coord = iter.mBox[1-neg][plane.norm];
-        iter.mStack.push_back( node );
-        iter.mBox[1-neg][plane.norm] = plane.coord;
-      }
-        // if left child is adjacent
-      else if (this->mBox[BMIN][plane.norm] - plane.coord <= epsilon) {
-          // if right child is also adjacent, add to list
-        if (plane.coord - this->mBox[BMAX][plane.norm] <= epsilon) {
-          list.push_back( iter );
-          list.back().mStack.push_back( StackObj( iter.childVect[1], iter.mBox[BMIN][plane.norm] ) );
-          list.back().mBox[BMIN][plane.norm] = plane.coord;
-        }
-          // continue with left child
-        node.entity = iter.childVect[0];
-        node.coord = iter.mBox[BMAX][plane.norm];
-        iter.mStack.push_back( node );
-        iter.mBox[BMAX][plane.norm] = plane.coord;
-      }
-        // right child is adjacent
-      else {
-          // if left child is not adjacent, right must be or something
-          // is really messed up.
-        assert(plane.coord - this->mBox[BMAX][plane.norm] <= epsilon);
-           // continue with left child
-        node.entity = iter.childVect[1];
-        node.coord = iter.mBox[BMIN][plane.norm];
-        iter.mStack.push_back( node );
-        iter.mBox[BMIN][plane.norm] = plane.coord;
-      }
-    }
-    
-    if (list.empty())
-      break;
-    
-    iter = list.back();
-    list.pop_back();
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTreeIter::sibling_side( 
-                            MBAdaptiveKDTree::Axis& axis_out,
-                            bool& neg_out ) const
-{
-  if (mStack.size() < 2) // at tree root
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBEntityHandle parent = mStack[mStack.size()-2].entity;
-  MBAdaptiveKDTree::Plane plane;
-  MBErrorCode rval = tool()->get_split_plane( parent, plane );
-  if (MB_SUCCESS != rval)
-    return MB_FAILURE;
-    
-  childVect.clear();
-  rval = tool()->moab()->get_child_meshsets( parent, childVect );
-  if (MB_SUCCESS != rval || childVect.size() != 2)
-    return MB_FAILURE;
-  
-  axis_out = static_cast<MBAdaptiveKDTree::Axis>(plane.norm);
-  neg_out = (childVect[1] == handle());
-  assert(childVect[neg_out] == handle());
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTreeIter::get_parent_split_plane( MBAdaptiveKDTree::Plane& plane ) const
-{
-  if (mStack.size() < 2) // at tree root
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBEntityHandle parent = mStack[mStack.size()-2].entity;
-  return tool()->get_split_plane( parent, plane );
-}
-
-
-bool MBAdaptiveKDTreeIter::is_sibling( const MBAdaptiveKDTreeIter& other_leaf ) const
-{
-  const size_t s = mStack.size();
-  return (s > 1) && (s == other_leaf.mStack.size()) &&
-         (other_leaf.mStack[s-2].entity == mStack[s-2].entity) &&
-         other_leaf.handle() != handle();
-}
-
-bool MBAdaptiveKDTreeIter::is_sibling( MBEntityHandle other_leaf ) const
-{
-  if (mStack.size() < 2 || other_leaf == handle())
-    return false;
-  MBEntityHandle parent = mStack[mStack.size()-2].entity;
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
-  if (MB_SUCCESS != rval || childVect.size() != 2) {
-    assert(false);
-    return false;
-  }
-  return childVect[0] == other_leaf || childVect[1] == other_leaf;
-}
-
-bool MBAdaptiveKDTreeIter::sibling_is_forward() const
-{
-  if (mStack.size() < 2) // if root
-    return false;
-  MBEntityHandle parent = mStack[mStack.size()-2].entity;
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
-  if (MB_SUCCESS != rval || childVect.size() != 2) {
-    assert(false);
-    return false;
-  }
-  return childVect[0] == handle();
-}  
-
-bool MBAdaptiveKDTreeIter::intersect_ray( const double ray_point[3],
-                                          const double ray_vect[3],
-                                          double& t_enter, 
-                                          double& t_exit ) const
-{
-  return MBGeomUtil::ray_box_intersect( MBCartVect(box_min()),
-                                        MBCartVect(box_max()),
-                                        MBCartVect(ray_point),
-                                        MBCartVect(ray_vect),
-                                        t_enter, t_exit );
-}
-
-static MBErrorCode intersect_children_with_elems(
-                                        MBAdaptiveKDTree* tool,
-                                        const MBRange& elems,
-                                        MBAdaptiveKDTree::Plane plane,
-                                        double eps,
-                                        MBCartVect box_min,
-                                        MBCartVect box_max,
-                                        MBRange& left_tris,
-                                        MBRange& right_tris,
-                                        MBRange& both_tris,
-                                        double& metric_value )
-{
-  left_tris.clear();
-  right_tris.clear();
-  both_tris.clear();
-  MBCartVect coords[16];
-  MBInterface *const moab = tool->moab();
-  
-    // get extents of boxes for left and right sides
-  MBCartVect right_min( box_min ), left_max( box_max );
-  right_min[plane.norm] = left_max[plane.norm] = plane.coord;
-  const MBCartVect left_cen = 0.5*(left_max + box_min);
-  const MBCartVect left_dim = 0.5*(left_max - box_min);
-  const MBCartVect right_cen = 0.5*(box_max + right_min);
-  const MBCartVect right_dim = 0.5*(box_max - right_min);
-  const MBCartVect dim = box_max - box_min;
-  
-  
-    // test each entity
-  MBErrorCode rval;
-  int count, count2;
-  const MBEntityHandle* conn, *conn2;
-  
-  const MBRange::const_iterator elem_begin = elems.lower_bound( MBEDGE );
-  const MBRange::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
-  const MBRange::const_iterator set_begin = elems.lower_bound( MBENTITYSET, poly_begin );
-  MBRange::iterator left_ins = left_tris.begin();
-  MBRange::iterator right_ins = right_tris.begin();
-  MBRange::iterator both_ins = both_tris.begin();
-  MBRange::const_iterator i;
-  
-    // vertices
-  for (i = elems.begin(); i != elem_begin; ++i) {
-    rval = moab->get_coords( &*i, 1, coords[0].array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    bool lo = false, ro = false;
-    if (coords[0][plane.norm] <= plane.coord)
-      lo = true;
-    if (coords[0][plane.norm] >= plane.coord)
-      ro = true;
-
-    if (lo && ro)
-      both_ins = both_tris.insert( both_ins, *i, *i );
-    else if (lo)
-      left_ins = left_tris.insert( left_ins, *i, *i );
-    else // if (ro)
-      right_ins = right_tris.insert( right_ins, *i, *i );
-  }
-  
-    // non-polyhedron elements
-  for (i = elem_begin; i != poly_begin; ++i) {
-    rval = moab->get_connectivity( *i, conn, count, true );
-    if (MB_SUCCESS != rval) 
-      return rval;
-    if (count > (int)(sizeof(coords)/sizeof(coords[0])))
-      return MB_FAILURE;
-    rval = moab->get_coords( &conn[0], count, coords[0].array() );
-    if (MB_SUCCESS != rval) return rval;
-    
-    bool lo = false, ro = false;
-    for (int j = 0; j < count; ++j) {
-      if (coords[j][plane.norm] <= plane.coord)
-        lo = true;
-      if (coords[j][plane.norm] >= plane.coord)
-        ro = true;
-    }
-    
-      // Triangle must be in at least one leaf.  If test against plain
-      // identified that leaf, then we're done.  If triangle is on both
-      // sides of plane, do more precise test to ensure that it is really
-      // in both.
-    if (lo && ro) {
-      lo = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen, left_dim );
-      ro = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim );
-      double tol = std::numeric_limits<double>::epsilon();
-        // didn't intersect either - tolerance issue
-      while (!lo && !ro && tol < eps) {
-        lo = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen,left_dim+tol*dim );
-        ro = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim+tol*dim );
-        tol *= 10.0;
-      }
-    }
-    if (lo && ro)
-      both_ins = both_tris.insert( both_ins, *i, *i );
-    else if (lo)
-      left_ins = left_tris.insert( left_ins, *i, *i );
-    else if (ro)
-      right_ins = right_tris.insert( right_ins, *i, *i );
-  }
-  
-    // polyhedra
-  for (i = poly_begin; i != set_begin; ++i) {
-    rval = moab->get_connectivity( *i, conn, count, true );
-    if (MB_SUCCESS != rval) 
-      return rval;
-      
-      // just check the bounding box of the polyhedron
-    bool lo = false, ro = false;
-    for (int j = 0; j < count; ++j) {
-      rval = moab->get_connectivity( conn[j], conn2, count2, true );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      for (int k = 0; k < count2; ++k) {
-        rval = moab->get_coords( conn2 + k, 1, coords[0].array() );
-        if (MB_SUCCESS != rval)
-          return rval;
-        if (coords[0][plane.norm] <= plane.coord)
-          lo = true;
-        if (coords[0][plane.norm] >= plane.coord)
-          ro = true;
-      }
-    }
-    
-    if (lo && ro)
-      both_ins = both_tris.insert( both_ins, *i, *i );
-    else if (lo)
-      left_ins = left_tris.insert( left_ins, *i, *i );
-    else if (ro)
-      right_ins = right_tris.insert( right_ins, *i, *i );
-  }
-  
-    // sets
-  MBCartVect tmin, tmax;
-  for (i = set_begin; i != elems.end(); ++i) {
-    rval = tool->get_tree_box( *i, tmin.array(), tmax.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    bool lo = false, ro = false;
-    if (tmin[plane.norm] <= plane.coord)
-      lo = true;
-    if (tmax[plane.norm] >= plane.coord)
-      ro = true;
-
-    if (lo && ro)
-      both_ins = both_tris.insert( both_ins, *i, *i );
-    else if (lo)
-      left_ins = left_tris.insert( left_ins, *i, *i );
-    else // if (ro)
-      right_ins = right_tris.insert( right_ins, *i, *i );
-  }
-  
-  
-  MBCartVect box_dim = box_max - box_min;
-  double area_left = left_dim[0]*left_dim[1] + left_dim[1]*left_dim[2] + left_dim[2]*left_dim[0];
-  double area_right = right_dim[0]*right_dim[1] + right_dim[1]*right_dim[2] + right_dim[2]*right_dim[0];
-  double area_both = box_dim[0]*box_dim[1] + box_dim[1]*box_dim[2] + box_dim[2]*box_dim[0];
-  metric_value = (area_left * left_tris.size() + area_right * right_tris.size()) / area_both + both_tris.size();
-  return MB_SUCCESS;
-}
-
-static MBErrorCode best_subdivision_plane( int num_planes,
-                                           const MBAdaptiveKDTreeIter& iter,
-                                           MBRange& best_left,
-                                           MBRange& best_right,
-                                           MBRange& best_both,
-                                           MBAdaptiveKDTree::Plane& best_plane,
-                                           double eps )
-{
-  double metric_val = std::numeric_limits<unsigned>::max();
-  
-  MBErrorCode r;
-  const MBCartVect box_min(iter.box_min());
-  const MBCartVect box_max(iter.box_max());
-  const MBCartVect diff(box_max - box_min);
-  
-  MBRange entities;
-  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
-  if (MB_SUCCESS != r)
-    return r;
-  const size_t p_count = entities.size();
-  
-  for (int axis = 0; axis < 3; ++axis) {
-    int plane_count = num_planes;
-    if ((num_planes+1)*eps >= diff[axis])
-      plane_count = (int)(diff[axis] / eps) - 1;
-  
-    for (int p = 1; p <= plane_count; ++p) {
-      MBAdaptiveKDTree::Plane plane = { box_min[axis] + (p/(1.0+plane_count)) * diff[axis], axis };
-      MBRange left, right, both;
-      double val;
-      r = intersect_children_with_elems( iter.tool(),
-                                         entities, plane, eps,
-                                         box_min, box_max,
-                                         left, right, both, 
-                                         val );
-      if (MB_SUCCESS != r)
-        return r;
-      const size_t diff = p_count - both.size();
-      if (left.size() == diff || right.size() == diff)
-        continue;
-      
-      if (val >= metric_val)
-        continue;
-      
-      metric_val = val;
-      best_plane = plane;
-      best_left.swap(left);
-      best_right.swap(right);
-      best_both.swap(both);
-    }
-  }
-      
-  return MB_SUCCESS;
-}
-
-
-static MBErrorCode best_subdivision_snap_plane( int num_planes,
-                                           const MBAdaptiveKDTreeIter& iter,
-                                           MBRange& best_left,
-                                           MBRange& best_right,
-                                           MBRange& best_both,
-                                           MBAdaptiveKDTree::Plane& best_plane,
-                                           std::vector<double>& tmp_data,
-                                           double eps )
-{
-  double metric_val = std::numeric_limits<unsigned>::max();
-  
-  MBErrorCode r;
-  const MBCartVect box_min(iter.box_min());
-  const MBCartVect box_max(iter.box_max());
-  const MBCartVect diff(box_max - box_min);
-  const MBCartVect tol(eps*diff);
-  
-  MBRange entities, vertices;
-  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
-  if (MB_SUCCESS != r)
-    return r;
-  const size_t p_count = entities.size();
-  r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, MBInterface::UNION );
-  if (MB_SUCCESS != r)
-    return r;
-
-  tmp_data.resize( vertices.size() );
-  for (int axis = 0; axis < 3; ++axis) {
-    int plane_count = num_planes;
-    if ((num_planes+1)*eps >= diff[axis])
-      plane_count = (int)(diff[axis] / eps) - 1;
-
-    double *ptrs[] = { 0, 0, 0 };
-    ptrs[axis] = &tmp_data[0];
-    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
-    if (MB_SUCCESS != r)
-      return r;
-  
-    for (int p = 1; p <= plane_count; ++p) {
-      double coord = box_min[axis] + (p/(1.0+plane_count)) * diff[axis];
-      double closest_coord = tmp_data[0];
-      for (unsigned i = 1; i < tmp_data.size(); ++i) 
-        if (fabs(coord-tmp_data[i]) < fabs(coord-closest_coord))
-          closest_coord = tmp_data[i];
-      if (closest_coord - box_min[axis] <= eps || box_max[axis] - closest_coord <= eps)
-        continue;
-          
-      MBAdaptiveKDTree::Plane plane = { closest_coord, axis };
-      MBRange left, right, both;
-      double val;
-      r = intersect_children_with_elems( iter.tool(),
-                                         entities, plane, eps,
-                                         box_min, box_max,
-                                         left, right, both, 
-                                         val );
-      if (MB_SUCCESS != r)
-        return r;
-      const size_t d = p_count - both.size();
-      if (left.size() == d || right.size() == d)
-        continue;
-      
-      if (val >= metric_val)
-        continue;
-      
-      metric_val = val;
-      best_plane = plane;
-      best_left.swap(left);
-      best_right.swap(right);
-      best_both.swap(both);
-    }
-  }
-     
-  return MB_SUCCESS;
-}
-
-static MBErrorCode best_vertex_median_plane( int num_planes,
-                                           const MBAdaptiveKDTreeIter& iter,
-                                           MBRange& best_left,
-                                           MBRange& best_right,
-                                           MBRange& best_both,
-                                           MBAdaptiveKDTree::Plane& best_plane,
-                                           std::vector<double>& coords,
-                                           double eps)
-{
-  double metric_val = std::numeric_limits<unsigned>::max();
-  
-  MBErrorCode r;
-  const MBCartVect box_min(iter.box_min());
-  const MBCartVect box_max(iter.box_max());
-  
-  MBRange entities, vertices;
-  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
-  if (MB_SUCCESS != r)
-    return r;
-  const size_t p_count = entities.size();
-  r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, MBInterface::UNION );
-  if (MB_SUCCESS != r)
-    return r;
-
-  coords.resize( vertices.size() );
-  for (int axis = 0; axis < 3; ++axis) {
-    if (box_max[axis] - box_min[axis] <= 2*eps)
-      continue;
-  
-    double *ptrs[] = { 0, 0, 0 };
-    ptrs[axis] = &coords[0];
-    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
-    if (MB_SUCCESS != r)
-      return r;
-  
-    std::sort( coords.begin(), coords.end() );
-    std::vector<double>::iterator citer;
-    citer = std::upper_bound( coords.begin(), coords.end(), box_min[axis] + eps );
-    const size_t count = std::upper_bound( citer, coords.end(), box_max[axis] - eps ) - citer;
-    size_t step;
-    int np = num_planes;
-    if (count < 2*(size_t)num_planes) {
-      step = 1; np = count - 1;
-    }
-    else {
-      step = count / (num_planes + 1);
-    }
-  
-    for (int p = 1; p <= np; ++p) {
-      
-      citer += step;
-      MBAdaptiveKDTree::Plane plane = { *citer, axis };
-      MBRange left, right, both;
-      double val;
-      r = intersect_children_with_elems( iter.tool(),
-                                         entities, plane, eps,
-                                         box_min, box_max,
-                                         left, right, both, 
-                                         val );
-      if (MB_SUCCESS != r)
-        return r;
-      const size_t diff = p_count - both.size();
-      if (left.size() == diff || right.size() == diff)
-        continue;
-      
-      if (val >= metric_val)
-        continue;
-      
-      metric_val = val;
-      best_plane = plane;
-      best_left.swap(left);
-      best_right.swap(right);
-      best_both.swap(both);
-    }
-  }
-      
-  return MB_SUCCESS;
-}
-
-
-static MBErrorCode best_vertex_sample_plane( int num_planes,
-                                           const MBAdaptiveKDTreeIter& iter,
-                                           MBRange& best_left,
-                                           MBRange& best_right,
-                                           MBRange& best_both,
-                                           MBAdaptiveKDTree::Plane& best_plane,
-                                           std::vector<double>& coords,
-                                           std::vector<MBEntityHandle>& indices,
-                                           double eps )
-{
-  const size_t random_elem_threshold = 20*num_planes;
-  double metric_val = std::numeric_limits<unsigned>::max();
-  
-  MBErrorCode r;
-  const MBCartVect box_min(iter.box_min());
-  const MBCartVect box_max(iter.box_max());
-  
-  MBRange entities, vertices;
-  r = iter.tool()->moab()->get_entities_by_handle( iter.handle(), entities );
-  if (MB_SUCCESS != r)
-    return r;
-    
-    // We are selecting random vertex coordinates to use for candidate split
-    // planes.  So if element list is large, begin by selecting random elements.
-  const size_t p_count = entities.size();
-  coords.resize( 3*num_planes );
-  if (p_count < random_elem_threshold) {
-    r = iter.tool()->moab()->get_adjacencies( entities, 0, false, vertices, MBInterface::UNION );
-    if (MB_SUCCESS != r)
-      return r;
-  }
-  else {
-    indices.resize(random_elem_threshold);
-    const int num_rand = p_count / RAND_MAX + 1;
-    for (size_t j = 0; j < random_elem_threshold; ++j) {
-      size_t rnd = rand();
-      for (int i = num_rand; i > 1; --i)
-        rnd *= rand();
-      rnd %= p_count;
-      indices[j] = entities[rnd];
-    }
-    r = iter.tool()->moab()->get_adjacencies( &indices[0], random_elem_threshold, 0, false, vertices, MBInterface::UNION );
-    if (MB_SUCCESS != r)
-      return r;
-  }
-
-  coords.resize( vertices.size() );
-  for (int axis = 0; axis < 3; ++axis) {
-    if (box_max[axis] - box_min[axis] <= 2*eps)
-      continue;
-  
-    double *ptrs[] = { 0, 0, 0 };
-    ptrs[axis] = &coords[0];
-    r = iter.tool()->moab()->get_coords( vertices, ptrs[0], ptrs[1], ptrs[2] );
-    if (MB_SUCCESS != r)
-      return r;
-      
-    size_t num_valid_coords = 0;
-    for (size_t i = 0; i < coords.size(); ++i) 
-      if (coords[i] > box_min[axis]+eps && coords[i] < box_max[axis]-eps)
-        ++num_valid_coords;
-      
-    if (2*(size_t)num_planes > num_valid_coords) {
-      indices.clear();
-      for (size_t i = 0; i < coords.size(); ++i) 
-        if (coords[i] > box_min[axis]+eps && coords[i] < box_max[axis]-eps)
-          indices.push_back( i );
-    }
-    else {
-      indices.resize( num_planes );
-        // make sure random indices are sufficient to cover entire range
-      const int num_rand = coords.size() / RAND_MAX + 1;
-      for (int j = 0; j < num_planes; ++j)
-      {
-        size_t rnd;
-        do { 
-          rnd = rand();
-          for (int i = num_rand; i > 1; --i)
-            rnd *= rand();
-          rnd %= coords.size();
-        } while (coords[rnd] <= box_min[axis]+eps || coords[rnd] >= box_max[axis]-eps);
-        indices[j] = rnd;
-      }
-    }
-  
-    for (unsigned p = 0; p < indices.size(); ++p) {
-      
-      MBAdaptiveKDTree::Plane plane = { coords[indices[p]], axis };
-      MBRange left, right, both;
-      double val;
-      r = intersect_children_with_elems( iter.tool(),
-                                         entities, plane, eps,
-                                         box_min, box_max,
-                                         left, right, both, 
-                                         val );
-      if (MB_SUCCESS != r)
-        return r;
-      const size_t diff = p_count - both.size();
-      if (left.size() == diff || right.size() == diff)
-        continue;
-      
-      if (val >= metric_val)
-        continue;
-      
-      metric_val = val;
-      best_plane = plane;
-      best_left.swap(left);
-      best_right.swap(right);
-      best_both.swap(both);
-    }
-  }
-      
-  return MB_SUCCESS;
-}
-
-static inline void box_accum( const MBCartVect& point,
-                              MBCartVect& bmin,
-                              MBCartVect& bmax )
-{
-  for (unsigned j = 0; j < 3; ++j) {
-    if (point[j] < bmin[j])
-      bmin[j] = point[j];
-    if (point[j] > bmax[j])
-      bmax[j] = point[j];
-  }
-}
-
-MBErrorCode MBAdaptiveKDTree::bounding_box( const MBRange& elems,
-                                            double box_min[3],
-                                            double box_max[3] )
-{
-  MBErrorCode rval;
-  MBCartVect bmin(HUGE_VAL), bmax(-HUGE_VAL);
-  MBCartVect coords;
-  MBEntityHandle const *conn, *conn2;
-  int len, len2;
-  MBRange::const_iterator i;
-  
-    // vertices
-  const MBRange::const_iterator elem_begin = elems.lower_bound( MBEDGE );
-  for (i = elems.begin(); i != elem_begin; ++i) {
-    rval = moab()->get_coords( &*i, 1, coords.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    box_accum( coords, bmin, bmax );
-  }
-
-    // elements with vertex-handle connectivity list
-  const MBRange::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
-  for (i = elem_begin; i != poly_begin; ++i) {
-    rval = moab()->get_connectivity( *i, conn, len, true );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    for (int j = 0; j < len; ++j) {
-      rval = moab()->get_coords( conn+j, 1, coords.array() );
-      if (MB_SUCCESS != rval)
-        return rval;
-      box_accum( coords, bmin, bmax );
-    }
-  }
-  
-    // polyhedra
-  const MBRange::const_iterator set_begin  = elems.lower_bound( MBENTITYSET, poly_begin );
-  for (i = poly_begin; i != set_begin; ++i) {
-    rval = moab()->get_connectivity( *i, conn, len, true );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    for (int j = 0; j < len; ++j) {
-      rval = moab()->get_connectivity( conn[j], conn2, len2 );
-      for (int k = 0; k < len2; ++k) {
-        rval = moab()->get_coords( conn2+k, 1, coords.array() );
-        if (MB_SUCCESS != rval)
-          return rval;
-        box_accum( coords, bmin, bmax );
-      }
-    }
-  }
-  
-    // sets
-  MBCartVect tmin, tmax;
-  for (i = set_begin; i != elems.end(); ++i) {
-    rval = get_tree_box( *i, tmin.array(), tmax.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-      
-    for (int j = 0; j < 3; ++j) {
-      if (tmin[j] < bmin[j])
-        bmin[j] = tmin[j];
-      if (tmax[j] > bmax[j])
-        bmax[j] = tmax[j];
-    }
-  }
-  
-  bmin.get( box_min );
-  bmax.get( box_max );
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBAdaptiveKDTree::build_tree( const MBRange& elems,
-                                          MBEntityHandle& root_set_out,
-                                          const Settings* settings_ptr )
-{
-  MBErrorCode rval;
-  Settings settings;
-  if (settings_ptr)
-    settings = *settings_ptr;
-  if (settings.maxEntPerLeaf < 1)
-    settings.maxEntPerLeaf = 1;
-  if (settings.maxTreeDepth < 1)
-    settings.maxTreeDepth = std::numeric_limits<unsigned>::max();
-  if (settings.candidateSplitsPerDir < 1)
-    settings.candidateSplitsPerDir = 1;
-  
-    // calculate bounding box of elements
-  MBCartVect bmin, bmax;
-  rval = bounding_box( elems, bmin.array(), bmax.array() );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // create tree root
-  rval = create_tree( bmin.array(), bmax.array(), root_set_out );
-  if (MB_SUCCESS != rval)
-    return rval;
-  rval = moab()->add_entities( root_set_out, elems );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  MBAdaptiveKDTreeIter iter;
-  iter.initialize( this, root_set_out, bmin.array(), bmax.array(), MBAdaptiveKDTreeIter::LEFT );
-  
-  std::vector<double> tmp_data;
-  std::vector<MBEntityHandle> tmp_data2;
-  for (;;) {
-  
-    int pcount;
-    rval = moab()->get_number_entities_by_handle( iter.handle(), pcount );
-    if (MB_SUCCESS != rval)
-      break;
-
-    const size_t p_count = pcount;
-    MBRange best_left, best_right, best_both;
-    Plane best_plane = { HUGE_VAL, -1 };
-    if (p_count > settings.maxEntPerLeaf && iter.depth() < settings.maxTreeDepth) {
-      switch (settings.candidatePlaneSet) {
-        case MBAdaptiveKDTree::SUBDIVISION:
-          rval = best_subdivision_plane( settings.candidateSplitsPerDir, 
-                                               iter, 
-                                               best_left, 
-                                               best_right, 
-                                               best_both, 
-                                               best_plane, 
-                                               settings.minBoxWidth );
-          break;
-        case MBAdaptiveKDTree::SUBDIVISION_SNAP:
-          rval = best_subdivision_snap_plane( settings.candidateSplitsPerDir, 
-                                               iter, 
-                                               best_left, 
-                                               best_right, 
-                                               best_both, 
-                                               best_plane, 
-                                               tmp_data, 
-                                               settings.minBoxWidth );
-          break;
-        case MBAdaptiveKDTree::VERTEX_MEDIAN:
-          rval = best_vertex_median_plane( settings.candidateSplitsPerDir, 
-                                               iter, 
-                                               best_left, 
-                                               best_right, 
-                                               best_both, 
-                                               best_plane, 
-                                               tmp_data, 
-                                               settings.minBoxWidth );
-          break;
-        case MBAdaptiveKDTree::VERTEX_SAMPLE:
-          rval = best_vertex_sample_plane( settings.candidateSplitsPerDir, 
-                                               iter, 
-                                               best_left, 
-                                               best_right, 
-                                               best_both, 
-                                               best_plane, 
-                                               tmp_data, 
-                                               tmp_data2,
-                                               settings.minBoxWidth );
-          break;
-        default:
-          rval = MB_FAILURE;
-      }
-    
-      if (MB_SUCCESS != rval)
-        return rval;
-    }
-    
-    if (best_plane.norm >= 0) {
-      best_left.merge( best_both );
-      best_right.merge( best_both );
-      rval = split_leaf( iter, best_plane,  best_left, best_right );
-      if (MB_SUCCESS != rval)
-        return rval;
-    }
-    else {
-      rval = iter.step();
-      if (MB_ENTITY_NOT_FOUND == rval) 
-        return MB_SUCCESS;  // at end
-      else if (MB_SUCCESS != rval)
-        break;
-    }
-  }
-  
-  delete_tree( root_set_out );
-  return rval;
-}
-
-MBErrorCode MBAdaptiveKDTree::leaf_containing_point( MBEntityHandle tree_root,
-                                                     const double point[3],
-                                                     MBEntityHandle& leaf_out )
-{
-  std::vector<MBEntityHandle> children;
-  Plane plane;
-  MBEntityHandle node = tree_root;
-  MBErrorCode rval = moab()->get_child_meshsets( node, children );
-  if (MB_SUCCESS != rval)
-    return rval;
-  while (!children.empty()) {
-    rval = get_split_plane( node, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-      
-    const double d = point[plane.norm] - plane.coord;
-    node = children[(d > 0.0)];
-    
-    children.clear();
-    rval = moab()->get_child_meshsets( node, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  leaf_out = node;
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTree::leaf_containing_point( MBEntityHandle root,
-                                                     const double point[3],
-                                                     MBAdaptiveKDTreeIter& result )
-{
-    // get bounding box of tree
-  MBErrorCode rval = moab()->tag_get_data( rootTag, &root, 1, result.mBox );
-  if (MB_SUCCESS != rval)
-    return rval;
-    
-    // test that point is inside tree
-  if (point[0] < result.box_min()[0] || point[0] > result.box_max()[0] ||
-      point[1] < result.box_min()[1] || point[1] > result.box_max()[1] ||
-      point[2] < result.box_min()[2] || point[2] > result.box_max()[2])
-    return MB_ENTITY_NOT_FOUND;  
-
-    // initialize iterator at tree root
-  result.treeTool = this;
-  result.mStack.clear();
-  result.mStack.push_back( MBAdaptiveKDTreeIter::StackObj(root,0) );
-    
-    // loop until we reach a leaf
-  MBAdaptiveKDTree::Plane plane;
-  for(;;) {
-      // get children
-    result.childVect.clear();
-    rval = moab()->get_child_meshsets( result.handle(), result.childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-      
-      // if no children, then at leaf (done)
-    if (result.childVect.empty())
-      break;
-
-      // get split plane
-    rval = get_split_plane( result.handle(), plane );
-    if (MB_SUCCESS != rval) 
-      return rval;
-    
-      // step iterator to appropriate child
-      // idx: 0->left, 1->right
-    const int idx = (point[plane.norm] > plane.coord);
-    result.mStack.push_back( MBAdaptiveKDTreeIter::StackObj( result.childVect[idx], 
-                                                             result.mBox[1-idx][plane.norm] ) );
-    result.mBox[1-idx][plane.norm] = plane.coord;
-  }
-    
-  return MB_SUCCESS;
-}
-
-struct NodeDistance {
-  MBEntityHandle handle;
-  MBCartVect dist; // from_point - closest_point_on_box
-};
-
-MBErrorCode MBAdaptiveKDTree::leaves_within_distance( MBEntityHandle tree_root,
-                                                      const double from_point[3],
-                                                      const double distance,
-                                                      std::vector<MBEntityHandle>& result_list )
-{
-  const double dist_sqr = distance * distance;
-  const MBCartVect from(from_point);
-  std::vector<NodeDistance> list;     // list of subtrees to traverse
-    // pre-allocate space for default max tree depth
-  Settings tmp_settings;
-  list.reserve( tmp_settings.maxTreeDepth );
-
-    // misc temporary values
-  Plane plane;
-  NodeDistance node; 
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> children;
-  
-    // Get distance from input position to bounding box of tree
-    // (zero if inside box)
-  double min[3], max[3];
-  rval = get_tree_box( tree_root, min, max );
-    // if bounding box is not available (e.g. not starting from true root)
-    // just start with zero.  Less efficient, but will work.
-  node.dist = MBCartVect(0.0);
-  if (MB_SUCCESS == rval) {
-    for (int i = 0; i < 3; ++i) {
-      if (from_point[i] < min[i])
-        node.dist[i] = min[i] - from_point[i];
-      else if (from_point[i] > max[i])
-        node.dist[i] = from_point[i] - max[i];
-    }
-    if (node.dist % node.dist > dist_sqr)
-      return MB_SUCCESS;
-  }
-  
-    // begin with root in list  
-  node.handle = tree_root;
-  list.push_back( node );
-  
-  while( !list.empty() ) {
-
-    node = list.back();
-    list.pop_back();
-      
-      // If leaf node, test contained triangles
-    children.clear();
-    rval = moab()->get_child_meshsets( node.handle, children );
-    if (children.empty()) {
-      result_list.push_back( node.handle );
-      continue;
-    }
-      
-      // If not leaf node, add children to working list
-    rval = get_split_plane( node.handle, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    const double d = from[plane.norm] - plane.coord;
-    
-      // right of plane?
-    if (d > 0) {
-      node.handle = children[1];
-      list.push_back( node );
-        // if the split plane is close to the input point, add
-        // the left child also (we'll check the exact distance
-        /// when we pop it from the list.)
-      if (d <= distance) {
-        node.dist[plane.norm] = d;
-        if (node.dist % node.dist <= dist_sqr) {
-          node.handle = children[0];
-          list.push_back( node );
-        }
-      }
-    }
-      // left of plane
-    else {
-      node.handle = children[0];
-      list.push_back( node );
-        // if the split plane is close to the input point, add
-        // the right child also (we'll check the exact distance
-        /// when we pop it from the list.)
-      if (-d <= distance) {
-        node.dist[plane.norm] = -d;
-        if (node.dist % node.dist <= dist_sqr) {
-          node.handle = children[1];
-          list.push_back( node );
-        }
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-static MBErrorCode closest_to_triangles( MBInterface* moab,
-                                         const MBRange& tris,
-                                         const MBCartVect& from,
-                                         double& shortest_dist_sqr,
-                                         MBCartVect& closest_pt,
-                                         MBEntityHandle& closest_tri )
-{
-  MBErrorCode rval;
-  MBCartVect pos, diff, verts[3];
-  const MBEntityHandle* conn;
-  int len;
-      
-  for (MBRange::iterator i = tris.begin(); i != tris.end(); ++i) {
-    rval = moab->get_connectivity( *i, conn, len );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    rval = moab->get_coords( conn, 3, verts[0].array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    MBGeomUtil::closest_location_on_tri( from, verts, pos );
-    diff = pos - from;
-    double dist_sqr = diff % diff;
-    if (dist_sqr < shortest_dist_sqr) {
-        // new closest location
-      shortest_dist_sqr = dist_sqr;
-      closest_pt = pos;
-      closest_tri = *i;
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-static MBErrorCode closest_to_triangles( MBInterface* moab,
-                                         MBEntityHandle set_handle,
-                                         const MBCartVect& from,
-                                         double& shortest_dist_sqr,
-                                         MBCartVect& closest_pt,
-                                         MBEntityHandle& closest_tri )
-{
-  MBErrorCode rval;
-  MBRange tris;
-  
-  rval = moab->get_entities_by_type( set_handle, MBTRI, tris );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-  return closest_to_triangles( moab, tris, from, shortest_dist_sqr, closest_pt, closest_tri );
-}
-
-MBErrorCode MBAdaptiveKDTree::find_close_triangle( MBEntityHandle root,
-                                                   const double from[3],
-                                                   double pt[3],
-                                                   MBEntityHandle& triangle )
-{
-  MBErrorCode rval;
-  MBRange tris;
-  Plane split;
-  std::vector<MBEntityHandle> stack;
-  std::vector<MBEntityHandle> children(2);
-  stack.reserve(30);
-  stack.push_back( root );
-  
-  while (!stack.empty()) {
-    MBEntityHandle node = stack.back();
-    stack.pop_back();
-    
-    for (;;) {  // loop until we find a leaf
-    
-      children.clear();
-      rval = moab()->get_child_meshsets( node, children );
-      if (MB_SUCCESS != rval)
-        return rval;
-        
-        // loop termination criterion
-      if (children.empty())
-        break;
-      
-        // if not a leaf, get split plane
-      rval = get_split_plane( node, split );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-        // continue down the side that contains the point,
-        // and push the other side onto the stack in case
-        // we need to check it later.
-      int rs = split.right_side( from );
-      node = children[rs];
-      stack.push_back( children[1-rs] );
-    }
-    
-      // We should now be at a leaf.  
-      // If it has some triangles, we're done.
-      // If not, continue searching for another leaf.
-    tris.clear();
-    rval = moab()->get_entities_by_type( node, MBTRI, tris );
-    if (!tris.empty()) {
-      double dist_sqr = HUGE_VAL;
-      MBCartVect point(pt);
-      rval = closest_to_triangles( moab(), tris, MBCartVect(from), dist_sqr, point, triangle );
-      point.get(pt);
-      return rval;
-    }
-  }
-  
-    // If we got here, then we traversed the entire tree 
-    // and all the leaves were empty.
-  return MB_ENTITY_NOT_FOUND;
-}
-
-/** Find the triangles in a set that are closer to the input
- *  position than any triangles in the 'closest_tris' list.
- *
- *  closest_tris is assumed to contain a list of triangles for 
- *  which the first is the closest known triangle to the input 
- *  position and the first entry in 'closest_pts' is the closest
- *  location on that triangle.  Any other values in the lists must
- *  be other triangles for which the closest point is within the
- *  input tolernace of the closest closest point.  This function
- *  will update the lists as appropriate if any closer triangles
- *  or triangles within the tolerance of the current closest location
- *  are found.  The fisrt entry is maintaned as the closest of the
- *  list of triangles.
- */
-/*
-static MBErrorCode closest_to_triangles( MBInterface* moab,
-                                         MBEntityHandle set_handle,
-                                         double tolerance,
-                                         const MBCartVect& from,
-                                         std::vector<MBEntityHandle>& closest_tris,
-                                         std::vector<MBCartVect>& closest_pts )
-{
-  MBErrorCode rval;
-  MBRange tris;
-  MBCartVect pos, diff, verts[3];
-  const MBEntityHandle* conn;
-  int len;
-  double shortest_dist_sqr = HUGE_VAL;
-  if (!closest_pts.empty()) {
-    diff = from - closest_pts.front();
-    shortest_dist_sqr = diff % diff;
-  }
-  
-  rval = moab->get_entities_by_type( set_handle, MBTRI, tris );
-  if (MB_SUCCESS != rval)
-    return rval;
-      
-  for (MBRange::iterator i = tris.begin(); i != tris.end(); ++i) {
-    rval = moab->get_connectivity( *i, conn, len );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    rval = moab->get_coords( conn, 3, verts[0].array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    MBGeomUtil::closest_location_on_tri( from, verts, pos );
-    diff = pos - from;
-    double dist_sqr = diff % diff;
-    if (dist_sqr < shortest_dist_sqr) {
-        // new closest location
-      shortest_dist_sqr = dist_sqr;
-
-      if (closest_pts.empty()) {
-        closest_tris.push_back( *i );
-        closest_pts.push_back( pos );
-      }
-        // if have a previous closest location
-      else {
-          // if previous closest is more than 2*tolerance away
-          // from new closest, then nothing in the list can
-          // be within tolerance of new closest point.
-        diff = pos - closest_pts.front();
-        dist_sqr = diff % diff;
-        if (dist_sqr > 4.0 * tolerance * tolerance) {
-          closest_tris.clear();
-          closest_pts.clear();
-          closest_tris.push_back( *i );
-          closest_pts.push_back( pos );
-        }
-          // otherwise need to remove any triangles that are
-          // not within tolerance of the new closest point.
-        else {
-          unsigned r = 0, w = 0;
-          for (r = 0; r < closest_pts.size(); ++r) {
-            diff = pos - closest_pts[r];
-            if (diff % diff <= tolerance*tolerance) {
-              closest_pts[w] = closest_pts[r];
-              closest_tris[w] = closest_tris[r];
-              ++w;
-            }
-          }
-          closest_pts.resize( w + 1 );
-          closest_tris.resize( w + 1 );
-            // always put the closest one in the front
-          if (w > 0) {
-            closest_pts.back() = closest_pts.front();
-            closest_tris.back() = closest_tris.front();
-          }
-          closest_pts.front() = pos;
-          closest_tris.front() = *i;
-        }
-      }
-    }
-    else {
-        // If within tolerance of old closest triangle,
-        // add this one to the list.
-      diff = closest_pts.front() - pos;
-      if (diff % diff <= tolerance*tolerance) {
-        closest_pts.push_back( pos );
-        closest_tris.push_back( *i );
-      }
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-*/
-
-MBErrorCode MBAdaptiveKDTree::closest_triangle( MBEntityHandle tree_root,
-                                 const double from_coords[3],
-                                 double closest_point_out[3],
-                                 MBEntityHandle& triangle_out )
-{
-  MBErrorCode rval;
-  double shortest_dist_sqr = HUGE_VAL;
-  std::vector<MBEntityHandle> leaves;
-  const MBCartVect from(from_coords);
-  MBCartVect closest_pt;
-  
-    // Find the leaf containing the input point
-    // This search does not take into account any bounding box for the
-    // tree, so it always returns one leaf.
-  rval = find_close_triangle( tree_root, from_coords, closest_pt.array(), triangle_out );
-  if (MB_SUCCESS != rval) return rval;
-  
-    // Find any other leaves for which the bounding box is within
-    // the same distance from the input point as the current closest
-    // point is.
-  MBCartVect diff = closest_pt - from;
-  rval = leaves_within_distance( tree_root, from_coords, 
-                                 sqrt(diff%diff), leaves );
-  if (MB_SUCCESS != rval) return rval;
-
-    // Check any close leaves to see if they contain triangles that
-    // are as close to or closer than the current closest triangle(s).
-  for (unsigned i = 0; i < leaves.size(); ++i) {
-    rval = closest_to_triangles( moab(), leaves[i], from, shortest_dist_sqr, 
-                                 closest_pt, triangle_out );
-    if (MB_SUCCESS != rval) return rval;
-  }
-  
-    // pass back resulting position
-  closest_pt.get( closest_point_out );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTree::sphere_intersect_triangles( 
-                                   MBEntityHandle tree_root,
-                                   const double center[3],
-                                   double radius,
-                                   std::vector<MBEntityHandle>& triangles )
-{
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> leaves;
-  const MBCartVect from(center);
-  MBCartVect closest_pt;
-  const MBEntityHandle* conn;
-  MBCartVect coords[3];
-  int conn_len;
-
-    // get leaves of tree that intersect sphere
-  rval = leaves_within_distance( tree_root, center, radius, leaves );
-  if (MB_SUCCESS != rval) return rval;
-  
-    // search each leaf for triangles intersecting sphere
-  for (unsigned i = 0; i < leaves.size(); ++i) {
-    MBRange tris;
-    rval = moab()->get_entities_by_type( leaves[i], MBTRI, tris );
-    if (MB_SUCCESS != rval) return rval;
-    
-    for (MBRange::iterator j = tris.begin(); j != tris.end(); ++j) {
-      rval = moab()->get_connectivity( *j, conn, conn_len );
-      if (MB_SUCCESS != rval) return rval;
-      rval = moab()->get_coords( conn, 3, coords[0].array() );
-      if (MB_SUCCESS != rval) return rval;
-      MBGeomUtil::closest_location_on_tri( from, coords, closest_pt );
-      closest_pt -= from;
-      if ((closest_pt % closest_pt) <= (radius*radius)) 
-        triangles.push_back( *j );
-    }
-  }
-  
-    // remove duplicates from triangle list
-  std::sort( triangles.begin(), triangles.end() );
-  triangles.erase( std::unique( triangles.begin(), triangles.end() ), triangles.end() );
-  return MB_SUCCESS;
-}
-  
-      
-
-struct NodeSeg {
-  NodeSeg( MBEntityHandle h, double b, double e )
-    : handle(h), beg(b), end(e) {}
-  MBEntityHandle handle;
-  double beg, end;
-};
-
-MBErrorCode MBAdaptiveKDTree::ray_intersect_triangles( MBEntityHandle root,
-                                                 const double tol,
-                                                 const double ray_dir_in[3],
-                                                 const double ray_pt_in[3],
-                                                 std::vector<MBEntityHandle>& tris_out,
-                                                 std::vector<double>& dists_out,
-                                                 int max_ints,
-                                                 double ray_end )
-{
-  MBErrorCode rval;
-  double ray_beg = 0.0;
-  if (ray_end < 0.0)
-    ray_end = HUGE_VAL;
-  
-    // if root has bounding box, trim ray to that box
-  MBCartVect bmin, bmax, tvec(tol);
-  const MBCartVect ray_pt( ray_pt_in ), ray_dir( ray_dir_in );
-  rval = get_tree_box( root, bmin.array(), bmax.array() );
-  if (MB_SUCCESS == rval) {
-    if (!MBGeomUtil::segment_box_intersect( bmin-tvec, bmax+tvec, ray_pt, ray_dir, ray_beg, ray_end ))
-      return MB_SUCCESS; // ray misses entire tree.
-  }
-  
-  MBRange tris;
-  MBRange::iterator iter;
-  MBCartVect tri_coords[3];
-  const MBEntityHandle* tri_conn;
-  int conn_len;
-  double tri_t;
-  
-  Plane plane;
-  std::vector<MBEntityHandle> children;
-  std::vector<NodeSeg> list;
-  NodeSeg seg(root, ray_beg, ray_end);
-  list.push_back( seg );
-  
-  while (!list.empty()) {
-    seg = list.back();
-    list.pop_back();
-    
-      // If we are limited to a certain number of intersections
-      // (max_ints != 0), then ray_end will contain the distance
-      // to the furthest intersection we have so far.  If the
-      // tree node is further than that, skip it.
-    if (seg.beg > ray_end) 
-      continue;
-
-      // Check if at a leaf 
-    children.clear();
-    rval = moab()->get_child_meshsets( seg.handle, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (children.empty()) { // leaf
-
-      tris.clear();
-      rval = moab()->get_entities_by_type( seg.handle, MBTRI, tris );
-      if (MB_SUCCESS != rval)
-        return rval;
-    
-      for (iter = tris.begin(); iter != tris.end(); ++iter) {
-        rval = moab()->get_connectivity( *iter, tri_conn, conn_len );
-        if (MB_SUCCESS != rval) return rval;
-        rval = moab()->get_coords( tri_conn, 3, tri_coords[0].array() );
-        if (MB_SUCCESS != rval) return rval;
-        
-        if (MBGeomUtil::ray_tri_intersect( tri_coords, ray_pt, ray_dir, tol, tri_t, &ray_end )) {
-          if (!max_ints) {
-            if (std::find(tris_out.begin(),tris_out.end(),*iter) == tris_out.end()) {
-              tris_out.push_back( *iter );
-              dists_out.push_back( tri_t );
-            }
-          } 
-          else if (tri_t < ray_end) {
-            if (std::find(tris_out.begin(),tris_out.end(),*iter) == tris_out.end()) {
-              if (tris_out.size() < (unsigned)max_ints) {
-                tris_out.resize( tris_out.size() + 1 );
-                dists_out.resize( dists_out.size() + 1 );
-              }
-              int w = tris_out.size() - 1;
-              for (; w > 0 && tri_t < dists_out[w-1]; --w) {
-                tris_out[w] = tris_out[w-1];
-                dists_out[w] = dists_out[w-1];
-              }
-              tris_out[w] = *iter;
-              dists_out[w] = tri_t;
-              ray_end = dists_out.back();
-            }
-          }
-        }
-      }
-
-      continue;
-    }
-    
-    rval = get_split_plane( seg.handle, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    const double t = (plane.coord - ray_pt[plane.norm]) / ray_dir[plane.norm];
-    if (!finite(t)) {         // ray parallel to plane
-      if (ray_pt[plane.norm] - tol <= plane.coord)
-        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
-      if (ray_pt[plane.norm] + tol >= plane.coord)
-        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
-    }
-    else if (ray_dir[plane.norm] < 0.0) {
-      if (seg.beg > t) {      // segment left of plane
-        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
-//        if (plane.coord - ray_pt[plane.norm] + ray_dir[plane.norm] * seg.beg < tol)
-//          list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
-      }
-      else if (seg.end < t) { // segment right of plane
-        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
-//        if (ray_pt[plane.norm] + ray_dir[plane.norm] * seg.end - plane.coord < tol)
-//          list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
-      }
-      else {                  // segment crosses plane
-        list.push_back( NodeSeg( children[1], seg.beg, t ) );
-        list.push_back( NodeSeg( children[0], t, seg.end ) );
-      }
-    }
-    else {
-      if (seg.beg > t) {      // segment right of plane
-        list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
-//        if (ray_pt[plane.norm] + ray_dir[plane.norm] * seg.beg - plane.coord < tol)
-//          list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
-      }
-      else if (seg.end < t) { // segment left of plane
-        list.push_back( NodeSeg( children[0], seg.beg, seg.end ) );
-//        if (plane.coord - ray_pt[plane.norm] + ray_dir[plane.norm] * seg.end < tol)
-//          list.push_back( NodeSeg( children[1], seg.beg, seg.end ) );
-      }
-      else {                  // segment crosses plane
-        list.push_back( NodeSeg( children[0], seg.beg, t ) );
-        list.push_back( NodeSeg( children[1], t, seg.end ) );
-      }
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAdaptiveKDTree::depth( MBEntityHandle root, 
-                                     unsigned int& min_depth,
-                                     unsigned int& max_depth )
-{
-  MBAdaptiveKDTreeIter iter;
-  get_tree_iterator( root, iter );
-  iter.step_to_first_leaf(MBAdaptiveKDTreeIter::LEFT);
-  min_depth = max_depth = iter.depth();
-  while (MB_SUCCESS == iter.step()) {
-    if (iter.depth() > max_depth)
-      max_depth = iter.depth();
-    else if (iter.depth() < min_depth)
-      min_depth = iter.depth();
-  }
-  
-  return MB_SUCCESS;
-}
-          
-MBErrorCode MBAdaptiveKDTree::get_info(MBEntityHandle root,
-                                       double min[3], double max[3], 
-                                       unsigned int &dep) 
-{
-  MBErrorCode result = get_tree_box(root, min, max);
-  if (MB_SUCCESS != result) return result;
-  
-  unsigned min_depth;
-  return depth( root, min_depth, dep );
-}
-

Deleted: MOAB/trunk/src/MBAffineXform.cpp
===================================================================
--- MOAB/trunk/src/MBAffineXform.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBAffineXform.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,443 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBAffineXform
- * \brief Define an affine transformatino
- * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
- * \date August, 2006
- */
-
-#include "MBAffineXform.hpp"
-#include "MBInterface.hpp"
-#include <assert.h>
-
-#ifndef TEST
-
-const char* const AFFINE_XFORM_TAG_NAME = "AFFINE_TRANSFORM";
-
-MBErrorCode MBAffineXform::get_tag( MBTag& tag_out,
-                                    MBInterface* interface,
-                                    const char* tagname )
-{
-  assert( sizeof(MBAffineXform) == 12*sizeof(double) );
-  
-  if (!tagname)
-    tagname = AFFINE_XFORM_TAG_NAME;
- 
-  MBErrorCode rval;
-  
-  rval = interface->tag_get_handle( tagname, tag_out );
-  
-  if (MB_TAG_NOT_FOUND == rval) 
-    return interface->tag_create( tagname, 
-                                  sizeof(MBAffineXform),
-                                  MB_TAG_DENSE,
-                                  MB_TYPE_DOUBLE,
-                                  tag_out,
-                                  0 );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  int size;
-  rval = interface->tag_get_size( tag_out, size );
-  if (MB_SUCCESS != rval || size != sizeof(MBAffineXform))
-    return MB_FAILURE;
-  
-  MBDataType type;
-  rval = interface->tag_get_data_type( tag_out, type );
-  if (MB_SUCCESS != rval || type != MB_TYPE_DOUBLE)
-    return MB_FAILURE;
-  
-  return MB_SUCCESS;
-}
-
-#else // ******************* Unit Test code ***********************
-
-#include <iostream>
-#define ASSERT_VECTORS_EQUAL(A, B) assert_vectors_equal( (A), (B), #A, #B, __LINE__ )
-#define ASSERT_DOUBLES_EQUAL(A, B) assert_doubles_equal( (A), (B), #A, #B, __LINE__ )
-#define ASSERT(B) assert_bool( (B), #B, __LINE__ )
-
-const double TOL = 1e-6;
-
-int error_count = 0;
-
-void assert_vectors_equal( const MBCartVect& a, const MBCartVect& b, 
-                           const char* sa, const char* sb,
-                           int lineno )
-{
-  if (fabs(a[0] - b[0]) > TOL ||
-      fabs(a[1] - b[1]) > TOL ||
-      fabs(a[2] - b[2]) > TOL) {
-    std::cerr << "Assertion failed at line " << lineno << std::endl
-              << "\t" << sa << " == " << sb << std::endl
-              << "\t[" << a[0] << ", " << a[1] << ", " << a[2] << "] == ["
-              << b[0] << ", " << b[1] << ", " << b[2] << "]" << std::endl;
-    ++error_count;
-  }
-}
-
-void assert_doubles_equal( double a, double b, const char* sa, const char* sb, int lineno )
-{
-  if (fabs(a - b) > TOL) {
-    std::cerr << "Assertion failed at line " << lineno << std::endl
-              << "\t" << sa << " == " << sb << std::endl
-              << "\t" << a << " == " << b << std::endl;
-    ++error_count;
-  }
-}
-
-void assert_bool( bool b, const char* sb, int lineno )
-{
-  if (!b) {
-    std::cerr << "Assertion failed at line " << lineno << std::endl
-              << "\t" << sb << std::endl;
-    ++error_count;
-  }
-}
-
-
-const MBCartVect point1( 0.0, 0.0, 0.0 ), point2( 3.5, 1000, -200 );
-const MBCartVect vect1( 0.0, 0.0, -100.0 ), vect2( 1.0, 0.0, 1.0 );
-
-
-void test_none()
-{
-    // default xform should do nothing.
-  MBCartVect output;
-  MBAffineXform none;
-  none.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 );
-  none.xform_point( point2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point2 );
-  none.xform_vector( vect1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, vect1 );
-  none.xform_vector( vect2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, vect2 );
-}
-
-void test_translation()
-{
-  MBCartVect offset( 1.0, 2.0, 3.0 );
-  MBCartVect output;
-  
-  MBAffineXform move = MBAffineXform::translation( offset.array() );
-  
-  // test that points are moved by offset
-  move.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 + offset );
-  move.xform_point( point2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point2 + offset );
-  
-  // vectors should not be changed by a translation
-  move.xform_vector( vect1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, vect1 );
-  move.xform_vector( vect2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, vect2 );
-}
-
-void test_rotation()
-{
-  MBCartVect output;
-  
-  // rotate 90 degress about Z axis
-  
-  MBAffineXform rot = MBAffineXform::rotation( M_PI/2.0, MBCartVect(0,0,1).array() );
-  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
-  
-  rot.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
-  
-  MBCartVect expectedz( -point2[1], point2[0], point2[2] ); // in first quadrant
-  rot.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, expectedz );
-  
-  rot.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, vect1 );
-  
-  rot.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect( 0, 1, 1 ) );
-  
-  // rotate 90 degress about Y axis
-  
-  rot = MBAffineXform::rotation( M_PI/2.0, MBCartVect(0,1,0).array() );
-  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
-  
-  rot.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
-  
-  MBCartVect expectedy( point2[2], point2[1], -point2[0] ); // in second quadrant
-  rot.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, expectedy );
-  
-  rot.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(-100,0,0) );
-  
-  rot.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect( 1, 0, -1 ) );
-  
-  // rotate 90 degress about X axis
-  
-  rot = MBAffineXform::rotation( M_PI/2.0, MBCartVect(1,0,0).array() );
-  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
-  
-  rot.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
-  
-  MBCartVect expectedx( point2[0], -point2[2], point2[1] ); // in third quadrant
-  rot.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, expectedx );
-  
-  rot.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(0,100,0) );
-  
-  rot.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect( 1, -1, 0 ) );
-  
-  // rotate 180 degrees about vector in XY plane
-  
-  rot = MBAffineXform::rotation( M_PI, MBCartVect( 1, 1, 0 ).array() );
-  ASSERT_DOUBLES_EQUAL( rot.matrix().determinant(), 1.0 );
-  
-  rot.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 ); // origin not affected by transform
-  
-  rot.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect( point2[1], point2[0], -point2[2] ) );
-  
-  rot.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, -vect1 ); // vector is in xy plane
-  
-  rot.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect( 0, 1, -1 ) );
-}
-
-MBCartVect refl( const MBCartVect& vect, const MBCartVect& norm )
-{
-  MBCartVect n(norm);
-  n.normalize();
-  double d = vect % n;
-  return vect - 2 * d * n;
-}
-
-void test_reflection()
-{
-  MBCartVect output;
-  
-  // reflect about XY plane
-  MBAffineXform ref = MBAffineXform::reflection( MBCartVect( 0, 0, 1 ).array() );
-  ASSERT_DOUBLES_EQUAL( ref.matrix().determinant(), -1.0 );
-  ref.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 );
-  ref.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(point2[0],point2[1],-point2[2]) );
-  ref.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, -vect1 );
-  ref.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(1,0,-1) );
-  
-  // reflect about arbitrary palne
-  MBCartVect norm( 3, 2, 1 );
-  ref = MBAffineXform::reflection( norm.array() );
-  ASSERT_DOUBLES_EQUAL( ref.matrix().determinant(), -1.0 );
-  ref.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, point1 );
-  ref.xform_point( point2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), point2.length() );
-  ASSERT_VECTORS_EQUAL( output, refl(point2,norm) );
-  ref.xform_vector( vect1.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect1.length() );
-  ASSERT_VECTORS_EQUAL( output, refl(vect1,norm) );
-  ref.xform_vector( vect2.array(), output.array() );
-  ASSERT_DOUBLES_EQUAL( output.length(), vect2.length() );
-  ASSERT_VECTORS_EQUAL( output, refl(vect2,norm) );
-}
-
-void test_scale()
-{
-  MBCartVect output;
-  
-  //scale in X only
-  MBAffineXform scale = MBAffineXform::scale( MBCartVect(2,1,1).array() );
-  scale.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(2*point1[0],point1[1],point1[2]) );
-  scale.xform_point( point2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(2*point2[0],point2[1],point2[2]) );
-  scale.xform_vector( vect1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(2*vect1[0],vect1[1],vect1[2]) );
-  scale.xform_vector( vect2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, MBCartVect(2*vect2[0],vect2[1],vect2[2]) );
-  
-  // scale in all
-  scale = MBAffineXform::scale( MBCartVect(0.5,0.5,0.5).array() );
-  scale.xform_point( point1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, 0.5*point1 );
-  scale.xform_point( point2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, 0.5*point2 );
-  scale.xform_vector( vect1.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, 0.5*vect1 );
-  scale.xform_vector( vect2.array(), output.array() );
-  ASSERT_VECTORS_EQUAL( output, 0.5*vect2 );
-}
-
-void test_accumulate()
-{
-  MBCartVect indiv, accum;
-  
-  // build an group of transforms.  make sure translation is somewhere in the middle
-  MBAffineXform move, scal, rot1, rot2, refl;
-  move = MBAffineXform::translation( MBCartVect( 5, -5, 1 ).array() );
-  scal = MBAffineXform::scale( MBCartVect( 1, 0.5, 2 ).array() );
-  rot1 = MBAffineXform::rotation( M_PI/3, MBCartVect( 0.5, 0.5, 1 ).array() );
-  rot2 = MBAffineXform::rotation( M_PI/4, MBCartVect( 1.0, 0.0, 0.0 ).array() );
-  refl = MBAffineXform::reflection( MBCartVect( -1, -1, 0 ).array() );
-  MBAffineXform accu;
-  accu.accumulate( scal );
-  accu.accumulate( rot1 );
-  accu.accumulate( move );
-  accu.accumulate( refl );
-  accu.accumulate( rot2 );
-  
-  accu.xform_point( point1.array(), accum.array() );
-  scal.xform_point( point1.array(), indiv.array() );
-  rot1.xform_point( indiv.array() );
-  move.xform_point( indiv.array() );
-  refl.xform_point( indiv.array() );
-  rot2.xform_point( indiv.array() );
-  ASSERT_VECTORS_EQUAL( accum, indiv );
-  
-  accu.xform_point( point2.array(), accum.array() );
-  scal.xform_point( point2.array(), indiv.array() );
-  rot1.xform_point( indiv.array() );
-  move.xform_point( indiv.array() );
-  refl.xform_point( indiv.array() );
-  rot2.xform_point( indiv.array() );
-  ASSERT_VECTORS_EQUAL( accum, indiv );
-  
-  accu.xform_vector( vect1.array(), accum.array() );
-  scal.xform_vector( vect1.array(), indiv.array() );
-  rot1.xform_vector( indiv.array() );
-  move.xform_vector( indiv.array() );
-  refl.xform_vector( indiv.array() );
-  rot2.xform_vector( indiv.array() );
-  ASSERT_VECTORS_EQUAL( accum, indiv );
-  
-  accu.xform_vector( vect2.array(), accum.array() );
-  scal.xform_vector( vect2.array(), indiv.array() );
-  rot1.xform_vector( indiv.array() );
-  move.xform_vector( indiv.array() );
-  refl.xform_vector( indiv.array() );
-  rot2.xform_vector( indiv.array() );
-  ASSERT_VECTORS_EQUAL( accum, indiv );
-}
-
-void test_inversion() {
-  MBCartVect result;
-  
-  // build an group of transforms.  make sure translation is somewhere in the middle
-  MBAffineXform move, scal, rot1, rot2, refl;
-  move = MBAffineXform::translation( MBCartVect( 5, -5, 1 ).array() );
-  scal = MBAffineXform::scale( MBCartVect( 1, 0.5, 2 ).array() );
-  rot1 = MBAffineXform::rotation( M_PI/3, MBCartVect( 0.5, 0.5, 1 ).array() );
-  rot2 = MBAffineXform::rotation( M_PI/4, MBCartVect( 1.0, 0.0, 0.0 ).array() );
-  refl = MBAffineXform::reflection( MBCartVect( -1, -1, 0 ).array() );
-  MBAffineXform acc;
-  acc.accumulate( scal );
-  acc.accumulate( rot1 );
-  acc.accumulate( move );
-  acc.accumulate( refl );
-  acc.accumulate( rot2 );
-  
-  MBAffineXform inv = acc.inverse();
-  
-  acc.xform_point( point1.array(), result.array() );
-  inv.xform_point( result.array() );
-  ASSERT_VECTORS_EQUAL( point1, result );
-  
-  acc.xform_point( point2.array(), result.array() );
-  inv.xform_point( result.array() );
-  ASSERT_VECTORS_EQUAL( point2, result );
-  
-  acc.xform_vector( vect1.array(), result.array() );
-  inv.xform_vector( result.array() );
-  ASSERT_VECTORS_EQUAL( vect1, result );
-  
-  acc.xform_vector( vect2.array(), result.array() );
-  inv.xform_vector( result.array() );
-  ASSERT_VECTORS_EQUAL( vect2, result );
-}
-  
-void test_is_reflection()
-{
-  MBAffineXform refl1, refl2, scale;
-  refl1 = MBAffineXform::reflection( MBCartVect( -1, -1, 0).array() );
-  refl2 = MBAffineXform::reflection( MBCartVect(  1,  0, 0).array() );
-  scale = MBAffineXform::scale( MBCartVect( -1, 1, 1 ).array() );
-  
-  ASSERT( refl1.reflection() );
-  ASSERT( refl2.reflection() );
-  ASSERT( scale.reflection() );
-  
-  MBAffineXform inv1, inv2, inv3;
-  inv1 = refl1.inverse();
-  inv2 = refl2.inverse();
-  inv3 = scale.inverse();
-  
-  ASSERT( inv1.reflection() );
-  ASSERT( inv2.reflection() );
-  ASSERT( inv3.reflection() );
-  
-  refl1.accumulate( refl2 );
-  refl2.accumulate( scale );
-  ASSERT( ! refl1.reflection() );
-  ASSERT( ! refl2.reflection() );
-  
-  MBAffineXform rot, mov;
-  rot = MBAffineXform::rotation( M_PI/4, MBCartVect(1,1,1).array() );
-  mov = MBAffineXform::translation( MBCartVect(-5,6,7).array() );
-  ASSERT( !rot.reflection() );
-  ASSERT( !mov.reflection() );
-}
-
-int main()
-{
-  test_none();
-  test_translation();
-  test_rotation();
-  test_reflection();
-  test_scale();
-  test_accumulate();
-  test_inversion();
-  test_is_reflection();
-  return error_count;
-}
-
-#endif  // #ifdef TEST

Deleted: MOAB/trunk/src/MBAffineXform.hpp
===================================================================
--- MOAB/trunk/src/MBAffineXform.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBAffineXform.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,189 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBAffineXform
- * \brief Define an affine transformatino
- * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
- * \date August, 2006
- */
-
-#ifndef MB_AFFINE_XFORM_HPP
-#define MB_AFFINE_XFORM_HPP
-
-#include "MBForward.hpp"
-#include "MBCartVect.hpp"
-#include "MBMatrix3.hpp"
-
-class MBAffineXform
-{
-  public:
-  
-    inline MBAffineXform();
-    
-    inline MBAffineXform( const double* three_by_three, 
-                          const double* translation );
-                          
-    inline MBAffineXform( const MBMatrix3& mat, const MBCartVect& off );
-    
-    /** move */
-    static inline MBAffineXform translation( const double* vector );
-    /** rotate about axis through origin */
-    static inline MBAffineXform rotation( double radians, const double* axis );
-    /** reflect about plane through origin */
-    static inline MBAffineXform reflection( const double* plane_normal );
-    /** scale about origin */
-    static inline MBAffineXform scale( const double* fractions );
-    
-    /** incorporate the passed transform into this one */
-    inline void accumulate( const MBAffineXform& other );
-    
-    /** apply transform to a point */
-    inline void xform_point( const double* input, double* output ) const;
-    /** apply transform to a point */
-    inline void xform_point( double* in_out ) const;
-    
-    /** apply transform to a vector */
-    inline void xform_vector( const double* input, double* output ) const;
-    /** apply transform to a vector */
-    inline void xform_vector( double* in_out ) const;
-    
-    /** get transform that is the inverse of this transform */
-    MBAffineXform inverse() const;
-    
-    /** get a tag that can be used to store an instance of this class */
-    static MBErrorCode get_tag( MBTag& tag_handle_out,
-                                MBInterface* moab,
-                                const char* tagname = 0 );
-    
-    /** get 3x3 matrix portion of transform */
-    const MBMatrix3& matrix() const { return mMatrix; }
-    /** get translation portion of transform */
-    const MBCartVect& offset() const { return mOffset; }
-    
-    /** Is this transform a reflection 
-     *
-     * A relfecting transform will require the reversal of the
-     * order of edges in a loop, etc. because it produces a 
-     * mirror-image of the input geometry.  This method tests
-     * if this is such a transform.  A reflection may be created
-     * with by an explicit transform, scaling with a negative
-     * scale factor, etc.  If multiple transforms are combined
-     * such that the transform is no longer a reflection (e.g. 
-     * two reflections that are effectively a rotation), this method
-     * will return false.
-     */
-    inline bool reflection() const;
-
-  private:
-  
-    MBMatrix3 mMatrix;
-    MBCartVect mOffset;
-};
-
-inline MBAffineXform::MBAffineXform()
-  : mMatrix(1.0), mOffset(0.0) 
-  {}
-
-inline MBAffineXform::MBAffineXform( const double* three_by_three, 
-                                     const double* translation )
- : mMatrix(three_by_three), mOffset(translation)
- {}
-
-inline MBAffineXform::MBAffineXform( const MBMatrix3& mat, const MBCartVect& off )
-  : mMatrix(mat), mOffset(off)
-  {}
-
-inline MBAffineXform MBAffineXform::translation( const double* vector )
-{
-  return MBAffineXform( MBMatrix3(1.0), MBCartVect(vector) );
-}
-
-inline MBAffineXform MBAffineXform::rotation( double angle, const double* axis )
-{
-  MBCartVect a(axis);
-  a.normalize();
-
-  const double c = cos(angle);
-  const double s = sin(angle);
-  const MBMatrix3 m1(    c,   -a[2]*s, a[1]*s,
-                       a[2]*s,   c,   -a[0]*s,
-                      -a[1]*s, a[0]*s,   c    );
-  return MBAffineXform( m1 + (1.0-c)*outer_product( a, a ), MBCartVect(0.0) );
-}
-
-inline MBAffineXform MBAffineXform::reflection( const double* plane_normal )
-{
-  double i = plane_normal[0];
-  double j = plane_normal[1];
-  double k = plane_normal[2];
-  MBMatrix3 m( j*j+k*k-i*i,    -2.0*i*j,    -2.0*i*k,
-                  -2.0*i*j, i*i+k*k-j*j,    -2.0*j*k,
-                  -2.0*i*k,    -2.0*j*k, i*i+j*j-k*k );
-  m *= 1.0 / (i*i + j*j + k*k); //normalize
-  return MBAffineXform( m, MBCartVect(0.0) );
-}
-
-inline MBAffineXform MBAffineXform::scale( const double* f )
-{
-  return MBAffineXform( MBMatrix3( MBCartVect(f) ), MBCartVect( 0.0 ) );
-}
-
-inline void MBAffineXform::accumulate( const MBAffineXform& other )
-{
-  mMatrix = other.mMatrix * mMatrix;
-  other.xform_point( mOffset.array() );
-}
-
-inline void MBAffineXform::xform_point( const double* input, double* output ) const
-{
-  xform_vector( input, output );
-  output[0] += mOffset[0];
-  output[1] += mOffset[1];
-  output[2] += mOffset[2];
-}
-
-inline void MBAffineXform::xform_point( double* in_out ) const
-{
-  xform_vector( in_out );
-  in_out[0] += mOffset[0];
-  in_out[1] += mOffset[1];
-  in_out[2] += mOffset[2];
-} 
-
-inline void MBAffineXform::xform_vector( const double* input, double* output ) const
-{
-  output[0] = input[0]*mMatrix[0][0] + input[1]*mMatrix[0][1] + input[2]*mMatrix[0][2];
-  output[1] = input[0]*mMatrix[1][0] + input[1]*mMatrix[1][1] + input[2]*mMatrix[1][2];
-  output[2] = input[0]*mMatrix[2][0] + input[1]*mMatrix[2][1] + input[2]*mMatrix[2][2];
-}
-
-inline void MBAffineXform::xform_vector( double* in_out ) const
-{
-  double input[] = { in_out[0], in_out[1], in_out[2] };
-  xform_vector( input, in_out );
-}
-
-inline MBAffineXform MBAffineXform::inverse() const
-{
-  MBMatrix3 m = mMatrix.inverse();
-  return MBAffineXform( m, m * -mOffset );
-}
-
-inline bool MBAffineXform::reflection() const
-{
-  return mMatrix.determinant() < 0.0;
-}
-#endif

Deleted: MOAB/trunk/src/MBAxisBox.cpp
===================================================================
--- MOAB/trunk/src/MBAxisBox.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBAxisBox.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,107 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \brief Class representing axis-aligned bounding box
- * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
- * \date August, 2006
- */
-
-const char* const AXIS_BOX_TAG_NAME = "AXIS_BOX";
-
-
-#include "MBAxisBox.hpp"
-#include "MBRange.hpp"
-#include <assert.h>
-
-
-MBErrorCode MBAxisBox::get_tag( MBTag& tag_out,
-                                MBInterface* interface,
-                                const char* tagname )
-{
-  assert( sizeof(MBAxisBox) == 6*sizeof(double) );
-  
-  if (!tagname)
-    tagname = AXIS_BOX_TAG_NAME;
- 
-  MBErrorCode rval;
-  
-  rval = interface->tag_get_handle( tagname, tag_out );
-  
-  if (MB_TAG_NOT_FOUND == rval) 
-    return interface->tag_create( tagname, 
-                                  sizeof(MBAxisBox),
-                                  MB_TAG_DENSE,
-                                  MB_TYPE_DOUBLE,
-                                  tag_out,
-                                  0 );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  int size;
-  rval = interface->tag_get_size( tag_out, size );
-  if (MB_SUCCESS != rval || size != sizeof(MBAxisBox))
-    return MB_FAILURE;
-  
-  MBDataType type;
-  rval = interface->tag_get_data_type( tag_out, type );
-  if (MB_SUCCESS != rval || type != MB_TYPE_DOUBLE)
-    return MB_FAILURE;
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBAxisBox::calculate( MBAxisBox& box,
-                                  MBEntityHandle set,
-                                  MBInterface* interface )
-{
-  MBRange range;
-  MBErrorCode rval = interface->get_entities_by_handle( set, range );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  return calculate( box, range, interface );
-}
-
-MBErrorCode MBAxisBox::calculate( MBAxisBox& box,
-                                  const MBRange& entities,
-                                  MBInterface* interface )
-{
-  MBErrorCode rval;
-  MBRange vertices;
-  MBRange elements;
-  
-  elements.merge( entities.upper_bound(MBVERTEX), entities.lower_bound(MBENTITYSET) );
-  rval = interface->get_adjacencies( elements, 0, false, vertices );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  vertices.merge( entities.begin(), entities.upper_bound(MBVERTEX) );
-  
-  std::vector<double> coords( 3*vertices.size() );
-  rval = interface->get_coords( vertices, &coords[0] );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  box = MBAxisBox();
-  std::vector<double>::const_iterator i = coords.begin();
-  for (; i != coords.end(); i += 3)
-    box |= &*i;
-  
-  return MB_SUCCESS;
-}
-
-
-  

Deleted: MOAB/trunk/src/MBAxisBox.hpp
===================================================================
--- MOAB/trunk/src/MBAxisBox.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBAxisBox.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,247 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBAxisBox
- * \brief Class representing axis-aligned bounding box
- * \author Jason Kraftcheck (kraftche at cae.wisc.edu)
- * \date August, 2006
- */
-
-#ifndef MB_AXIS_BOX_HPP
-#define MB_AXIS_BOX_HPP
-
-#include <limits>
-#include "MBInterface.hpp"
-
-class MBAxisBox {
-  public:
-  
-    inline MBAxisBox();
-    
-    inline MBAxisBox( const double* min, const double* max );
-    
-    inline MBAxisBox( const double* point );
-    
-    static MBErrorCode get_tag( MBTag& tag_handle_out,
-                                MBInterface* interface,
-                                const char* tag_name = 0 );
-    
-    /** Calculate a box bounding the entities contained in the passed set */
-    static MBErrorCode calculate( MBAxisBox& box_out,
-                                  MBEntityHandle set,
-                                  MBInterface* interface );
-                                      
-    /** Calculate a box bounding the vertices/elements in the passed MBRange */
-    static MBErrorCode calculate( MBAxisBox& box_out,
-                                  const MBRange& elements,
-                                  MBInterface* interface );
-                                  
-    /** intersect */
-    inline MBAxisBox& operator &=( const MBAxisBox& other );
-
-    /** unite */
-    inline MBAxisBox& operator |=( const MBAxisBox& other );
-    
-    /** unite */
-    inline MBAxisBox& operator |=( const double* point );
-    
-    inline const double* minimum() const { return minVect; }
-    
-    inline const double* maximum() const { return maxVect; }
-    
-    inline double* minimum() { return minVect; }
-    
-    inline double* maximum() { return maxVect; }
-    
-    inline void center( double* center_out ) const;
-    
-    inline void diagonal( double* diagonal_out ) const;
-    
-    /**\brief Check if two boxes intersect.
-     *
-     * Check if two boxes are within the specified tolerance of
-     * each other.  If tolerance is less than zero, then boxes must
-     * overlap by at least the magnitude of the tolerance to be
-     * considered intersecting.
-     */
-    inline bool intersects( const MBAxisBox& other, 
-                            double tolerance ) const;
-  
-    /**\brief Check if box contains point
-     *
-     * Check if a position is in or on the box, within the specified tolerance
-     */
-    inline bool intersects( const double* point,
-                            double tolerance ) const;
-    
-    /**\brief Check that box is valid
-     *
-     * Check that box is defined (contains at least a single point.)
-     */
-    inline bool valid() const;
-                      
-    /**\brief Find closest position on/within box to input position.
-     * 
-     * Find the closest position in the solid box to the input position.
-     * If the input position is on or within the box, then the output
-     * position will be the same as the input position.  If the input
-     * position is outside the box, the outside position will be the
-     * closest point on the box boundary to the input position.
-     */
-     inline void closest_position_within_box( const double* input_position,
-                                    double* output_position ) const;
-                            
-  private:
-  
-    double minVect[3], maxVect[3];
-};
-
-/** intersect */
-inline MBAxisBox operator&( const MBAxisBox& a, const MBAxisBox& b )
-  { return MBAxisBox(a) &= b; }
-
-/** unite */
-inline MBAxisBox operator|( const MBAxisBox& a, const MBAxisBox& b )
-  { return MBAxisBox(a) |= b; }
-
-/** intersects */
-inline bool operator||( const MBAxisBox& a, const MBAxisBox& b )
-{
-  return a.minimum()[0] <= b.maximum()[0]
-      && a.minimum()[1] <= b.maximum()[1]
-      && a.minimum()[2] <= b.maximum()[2]
-      && a.maximum()[0] >= b.minimum()[0]
-      && a.maximum()[1] >= b.minimum()[1]
-      && a.maximum()[2] >= b.minimum()[2];
-}
-
-
-inline MBAxisBox::MBAxisBox()
-{
-  minVect[0] = minVect[1] = minVect[2] =  std::numeric_limits<double>::max();
-  maxVect[0] = maxVect[1] = maxVect[2] = -std::numeric_limits<double>::max();
-}
-
-inline MBAxisBox::MBAxisBox( const double* min, const double* max )
-{   
-  minVect[0] = min[0];
-  minVect[1] = min[1];
-  minVect[2] = min[2];
-  maxVect[0] = max[0];
-  maxVect[1] = max[1];
-  maxVect[2] = max[2];
-}
-
-inline MBAxisBox::MBAxisBox( const double* point )
-{
-  minVect[0] = maxVect[0] = point[0];
-  minVect[1] = maxVect[1] = point[1];
-  minVect[2] = maxVect[2] = point[2];
-}
-                                  
-inline MBAxisBox& MBAxisBox::operator &=( const MBAxisBox& other )
-{
-  for (int i = 0; i < 3; ++i) {
-    if (minVect[i] < other.minVect[i])
-      minVect[i] = other.minVect[i];
-    if (maxVect[i] > other.maxVect[i])
-      maxVect[i] = other.maxVect[i];
-  }
-  return *this;
-}
-
-inline MBAxisBox& MBAxisBox::operator |=( const MBAxisBox& other )
-{
-  for (int i = 0; i < 3; ++i) {
-    if (minVect[i] > other.minVect[i])
-      minVect[i] = other.minVect[i];
-    if (maxVect[i] < other.maxVect[i])
-      maxVect[i] = other.maxVect[i];
-  }
-  return *this;
-}
-
-inline MBAxisBox& MBAxisBox::operator |=( const double* point )
-{
-  for (int i = 0; i < 3; ++i) {
-    if (minVect[i] > point[i])
-      minVect[i] = point[i];
-    if (maxVect[i] < point[i])
-      maxVect[i] = point[i];
-  }
-  return *this;
-}
-    
-inline void MBAxisBox::center( double* center_out ) const
-{
-  center_out[0] = 0.5 * (minVect[0] + maxVect[0]);
-  center_out[1] = 0.5 * (minVect[1] + maxVect[1]);
-  center_out[2] = 0.5 * (minVect[2] + maxVect[2]);
-}
-    
-inline void MBAxisBox::diagonal( double* diagonal_out ) const
-{
-  diagonal_out[0] = maxVect[0] - minVect[0];
-  diagonal_out[1] = maxVect[1] - minVect[1];
-  diagonal_out[2] = maxVect[2] - minVect[2];
-}
-
-inline bool MBAxisBox::intersects( const MBAxisBox& other, 
-                                   double tolerance ) const
-{
-  return minVect[0] - other.maxVect[0] <= tolerance &&
-         minVect[1] - other.maxVect[1] <= tolerance &&
-         minVect[2] - other.maxVect[2] <= tolerance &&
-         other.minVect[0] - maxVect[0] <= tolerance &&
-         other.minVect[1] - maxVect[1] <= tolerance &&
-         other.minVect[2] - maxVect[2] <= tolerance;
-}
-  
-inline bool MBAxisBox::intersects( const double* point,
-                                   double tolerance ) const
-{
-  return minVect[0] - point[0] <= tolerance &&
-         minVect[1] - point[1] <= tolerance &&
-         minVect[2] - point[2] <= tolerance &&
-         maxVect[0] - point[0] <= tolerance &&
-         maxVect[1] - point[1] <= tolerance &&
-         maxVect[2] - point[2] <= tolerance;
-}
-
-
-inline bool MBAxisBox::valid() const
-{
-  return minVect[0] <= maxVect[0]
-      && minVect[1] <= maxVect[1]
-      && minVect[2] <= maxVect[2];
-}
-
-inline void MBAxisBox::closest_position_within_box( 
-                                    const double* input_position,
-                                    double* output_position ) const
-{
-  for (int i = 0; i < 3; ++i) {
-    if (input_position[i] < minVect[i])
-      output_position[i] = minVect[i];
-    else if (input_position[i] > maxVect[i])
-      output_position[i] = maxVect[i];
-    else
-      output_position[i] = input_position[i];
-  }
-}
-
-#endif
-

Deleted: MOAB/trunk/src/MBBSPTree.cpp
===================================================================
--- MOAB/trunk/src/MBBSPTree.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBBSPTree.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1452 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2008 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBBSPTree.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2008-05-13
- */
-
-#include "MBBSPTree.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-#include "BSPTreePoly.hpp"
-
-#include <assert.h>
-#include <string.h>
-#include <algorithm>
-#include <limits>
-
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#  include <float.h>
-#  define finite(A) _finite(A)
-#elif defined(HAVE_IEEEFP_H)
-#  include <ieeefp.h>
-#endif
-
-#define MB_BSP_TREE_DEFAULT_TAG_NAME "BSPTree"
-
-static void corners_from_box( const double box_min[3],
-                              const double box_max[3],
-                              double corners[8][3] )
-{
-  const double* ranges[] = { box_min, box_max };
-  for (int z = 0; z < 2; ++z) {
-    corners[4*z  ][0] = box_min[0];
-    corners[4*z  ][1] = box_min[1];
-    corners[4*z  ][2] = ranges[z][2];
-
-    corners[4*z+1][0] = box_max[0];
-    corners[4*z+1][1] = box_min[1];
-    corners[4*z+1][2] = ranges[z][2];
-
-    corners[4*z+2][0] = box_max[0];
-    corners[4*z+2][1] = box_max[1];
-    corners[4*z+2][2] = ranges[z][2];
-
-    corners[4*z+3][0] = box_min[0];
-    corners[4*z+3][1] = box_max[1];
-    corners[4*z+3][2] = ranges[z][2];
-  }
-}
-
-// assume box has planar sides
-// test if point is contained in box
-static bool point_in_box( const double corners[8][3],
-                          const double point[3] )
-{
-  const unsigned side_verts[6][3] = { { 0, 3, 1 },
-                                      { 4, 5, 7 },
-                                      { 0, 1, 4 },
-                                      { 1, 2, 5 },
-                                      { 2, 3, 6 },
-                                      { 3, 0, 7 } };
-    // If we assume planar sides, then the box is the intersection
-    // of 6 half-spaces defined by the planes of the sides.
-  const MBCartVect pt(point);
-  for (unsigned s = 0; s < 6; ++s) {
-    MBCartVect v0( corners[side_verts[s][0]] );
-    MBCartVect v1( corners[side_verts[s][1]] );
-    MBCartVect v2( corners[side_verts[s][2]] );
-    MBCartVect N = (v1 - v0) * (v2 - v0);
-    if ((v0 - pt) % N < 0)
-      return false;
-  }
-  return true;
-}
-
-void MBBSPTree::Plane::set( const double pt1[3], const double pt2[3], const double pt3[3] )
-{
-  const double v1[] = { pt2[0] - pt1[0], pt2[1] - pt1[1], pt2[2] - pt1[2] };
-  const double v2[] = { pt3[0] - pt1[0], pt3[1] - pt1[1], pt3[2] - pt1[2] };
-  const double norm[] = { v1[1]*v2[2] - v1[2]*v2[1],
-                          v1[2]*v2[0] - v1[0]*v2[2],
-                          v1[0]*v2[1] - v1[1]*v2[0] };
-  set( norm, pt1 );
-}
-
-MBErrorCode MBBSPTree::init_tags( const char* tagname )
-{
-  if (!tagname) 
-    tagname = MB_BSP_TREE_DEFAULT_TAG_NAME;
-  
-  std::string rootname(tagname);
-  rootname += "_box";
-  
-  MBErrorCode rval = moab()->tag_create( tagname, 4*sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, planeTag, 0, true );
-  if (MB_SUCCESS != rval)
-    planeTag = 0;
-  else
-    rval = moab()->tag_create( rootname.c_str(), 24*sizeof(double), MB_TAG_SPARSE, MB_TYPE_DOUBLE, rootTag, 0, true );
-  if (MB_SUCCESS != rval)
-    rootTag = 0;
-  return rval;
-}
-
-MBBSPTree::MBBSPTree( MBInterface* mb, 
-                      const char* tagname, 
-                      unsigned set_flags )
-  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(false)
-{ init_tags( tagname ); }
-
-MBBSPTree::MBBSPTree( MBInterface* mb, 
-                      bool destroy_created_trees,
-                      const char* tagname, 
-                      unsigned set_flags )
-  : mbInstance(mb), meshSetFlags(set_flags), cleanUpTrees(destroy_created_trees)
-{ init_tags( tagname ); }
-
-MBBSPTree::~MBBSPTree()
-{
-  if (!cleanUpTrees)
-    return;
-    
-  while (!createdTrees.empty()) {
-    MBEntityHandle tree = createdTrees.back();
-      // make sure this is a tree (rather than some other, stale handle)
-    const void* data_ptr = 0;
-    MBErrorCode rval = moab()->tag_get_data( rootTag, &tree, 1, &data_ptr );
-    if (MB_SUCCESS == rval)
-      rval = delete_tree( tree );
-    if (MB_SUCCESS != rval)
-      createdTrees.pop_back();
-  }
-}
-
-MBErrorCode MBBSPTree::set_split_plane( MBEntityHandle node, const Plane& p )
-{ 
-    // check for unit-length normal
-  const double lensqr = p.norm[0]*p.norm[0] 
-                      + p.norm[1]*p.norm[1] 
-                      + p.norm[2]*p.norm[2];
-  if (fabs(lensqr - 1.0) < std::numeric_limits<double>::epsilon())
-    return moab()->tag_set_data( planeTag, &node, 1, &p ); 
-    
-  const double inv_len = 1.0/sqrt(lensqr);
-  Plane p2(p);
-  p2.norm[0] *= inv_len;
-  p2.norm[1] *= inv_len;
-  p2.norm[2] *= inv_len;
-  p2.coeff   *= inv_len;
-  
-    // check for zero-length normal
-  if (!finite(p2.norm[0]+p2.norm[1]+p2.norm[2]+p2.coeff))
-    return MB_FAILURE;
-
-    // store plane
-  return moab()->tag_set_data( planeTag, &node, 1, &p2 ); 
-}
-
-MBErrorCode MBBSPTree::set_tree_box( MBEntityHandle root_handle,
-                                     const double box_min[3],
-                                     const double box_max[3] )
-{
-  double corners[8][3];
-  corners_from_box( box_min, box_max, corners );
-  return set_tree_box( root_handle, corners );
-}
-
-MBErrorCode MBBSPTree::set_tree_box( MBEntityHandle root_handle,
-                                     const double corners[8][3] )
-{
-  return moab()->tag_set_data( rootTag, &root_handle, 1, corners );
-}
-
-MBErrorCode MBBSPTree::get_tree_box( MBEntityHandle root_handle,
-                                     double corners[8][3] )
-{
-  return moab()->tag_get_data( rootTag, &root_handle, 1, corners );
-}
-
-MBErrorCode MBBSPTree::get_tree_box( MBEntityHandle root_handle,
-                                     double corners[24] )
-{
-  return moab()->tag_get_data( rootTag, &root_handle, 1, corners );
-}
-
-MBErrorCode MBBSPTree::create_tree( MBEntityHandle& root_handle )
-{
-  const double min[3] = { -HUGE_VAL, -HUGE_VAL, -HUGE_VAL };
-  const double max[3] = {  HUGE_VAL,  HUGE_VAL,  HUGE_VAL };
-  return create_tree( min, max, root_handle );
-}
-
-MBErrorCode MBBSPTree::create_tree( const double corners[8][3],
-                                    MBEntityHandle& root_handle )
-{
-  MBErrorCode rval = moab()->create_meshset( meshSetFlags, root_handle );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = set_tree_box( root_handle, corners );
-  if (MB_SUCCESS != rval) {
-    moab()->delete_entities( &root_handle, 1 );
-    root_handle = 0;
-    return rval;
-  }
-  
-  createdTrees.push_back( root_handle );
-  return MB_SUCCESS;
-}
-                                    
-
-MBErrorCode MBBSPTree::create_tree( const double box_min[3],
-                                    const double box_max[3],
-                                    MBEntityHandle& root_handle )
-{
-  double corners[8][3];
-  corners_from_box( box_min, box_max, corners );
-  return create_tree( corners, root_handle );
-}
-
-MBErrorCode MBBSPTree::delete_tree( MBEntityHandle root_handle )
-{
-  MBErrorCode rval;
-  
-  std::vector<MBEntityHandle> children, dead_sets, current_sets;
-  current_sets.push_back( root_handle );
-  while (!current_sets.empty()) {
-    MBEntityHandle set = current_sets.back();
-    current_sets.pop_back();
-    dead_sets.push_back( set );
-    rval = moab()->get_child_meshsets( set, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-    std::copy( children.begin(), children.end(), std::back_inserter(current_sets) );
-    children.clear();
-  }
-  
-  rval = moab()->tag_delete_data( rootTag, &root_handle, 1 );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  createdTrees.erase(
-    std::remove( createdTrees.begin(), createdTrees.end(), root_handle ),
-    createdTrees.end() );
-  return moab()->delete_entities( &dead_sets[0], dead_sets.size() );
-}
-
-MBErrorCode MBBSPTree::find_all_trees( MBRange& results )
-{
-  return moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, 
-                                               &rootTag, 0, 1,
-                                               results );
-}
-
-MBErrorCode MBBSPTree::get_tree_iterator( MBEntityHandle root,
-                                          MBBSPTreeIter& iter )
-{
-  MBErrorCode rval = iter.initialize( this, root );
-  if (MB_SUCCESS != rval)
-    return rval;
-  return iter.step_to_first_leaf( MBBSPTreeIter::LEFT );
-}
-
-MBErrorCode MBBSPTree::get_tree_end_iterator( MBEntityHandle root,
-                                          MBBSPTreeIter& iter )
-{
-  MBErrorCode rval = iter.initialize( this, root );
-  if (MB_SUCCESS != rval)
-    return rval;
-  return iter.step_to_first_leaf( MBBSPTreeIter::RIGHT );
-}
-
-MBErrorCode MBBSPTree::split_leaf( MBBSPTreeIter& leaf,
-                                   Plane plane,
-                                   MBEntityHandle& left,
-                                   MBEntityHandle& right )
-{
-  MBErrorCode rval;
-  
-  rval = moab()->create_meshset( meshSetFlags, left );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = moab()->create_meshset( meshSetFlags, right );
-  if (MB_SUCCESS != rval) {
-    moab()->delete_entities( &left, 1 );
-    return rval;
-  }
-  
-  if (MB_SUCCESS != set_split_plane( leaf.handle(), plane ) ||
-      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), left ) ||
-      MB_SUCCESS != moab()->add_child_meshset( leaf.handle(), right) ||
-      MB_SUCCESS != leaf.step_to_first_leaf(MBBSPTreeIter::LEFT)) {
-    MBEntityHandle children[] = { left, right };
-    moab()->delete_entities( children, 2 );
-    return MB_FAILURE;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTree::split_leaf( MBBSPTreeIter& leaf, Plane plane )
-{
-  MBEntityHandle left, right;
-  return split_leaf( leaf, plane, left, right );
-}
-
-MBErrorCode MBBSPTree::split_leaf( MBBSPTreeIter& leaf, 
-                                   Plane plane,
-                                   const MBRange& left_entities,
-                                   const MBRange& right_entities )
-{
-  MBEntityHandle left, right, parent = leaf.handle();
-  MBErrorCode rval = split_leaf( leaf, plane, left, right );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (MB_SUCCESS == moab()->add_entities( left, left_entities ) &&
-      MB_SUCCESS == moab()->add_entities(right,right_entities ) &&
-      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
-    return MB_SUCCESS;
-  
-  moab()->remove_child_meshset( parent, left );
-  moab()->remove_child_meshset( parent, right );
-  MBEntityHandle children[] = { left, right };
-  moab()->delete_entities( children, 2 );
-  return MB_FAILURE;
-}
-
-MBErrorCode MBBSPTree::split_leaf( MBBSPTreeIter& leaf, Plane plane,
-                                   const std::vector<MBEntityHandle>& left_entities,
-                                   const std::vector<MBEntityHandle>& right_entities )
-{
-  MBEntityHandle left, right, parent = leaf.handle();
-  MBErrorCode rval = split_leaf( leaf, plane, left, right );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (MB_SUCCESS == moab()->add_entities( left, &left_entities[0], left_entities.size() ) &&
-      MB_SUCCESS == moab()->add_entities(right,&right_entities[0],right_entities.size() ) &&
-      MB_SUCCESS == moab()->clear_meshset( &parent, 1 ))
-    return MB_SUCCESS;
-  
-  moab()->remove_child_meshset( parent, left );
-  moab()->remove_child_meshset( parent, right );
-  MBEntityHandle children[] = { left, right };
-  moab()->delete_entities( children, 2 );
-  return MB_FAILURE;
-}
-
-MBErrorCode MBBSPTree::merge_leaf( MBBSPTreeIter& iter )
-{
-  MBErrorCode rval;
-  if (iter.depth() == 1) // at root
-    return MB_FAILURE;
-  
-    // Move iter to parent
-  iter.up();
-
-    // Get sets to merge
-  MBEntityHandle parent = iter.handle();
-  iter.childVect.clear();
-  rval = moab()->get_child_meshsets( parent, iter.childVect );
-  if (MB_SUCCESS != rval)
-    return rval;
-    
-    // Remove child links
-  moab()->remove_child_meshset( parent, iter.childVect[0] );
-  moab()->remove_child_meshset( parent, iter.childVect[1] );
-  std::vector<MBEntityHandle> stack( iter.childVect );
-  
-    // Get all entities from children and put them in parent
-  MBRange range;
-  while (!stack.empty()) {
-    MBEntityHandle h = stack.back();
-    stack.pop_back();
-    range.clear();
-    rval = moab()->get_entities_by_handle( h, range );
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = moab()->add_entities( parent, range );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    iter.childVect.clear();
-    moab()->get_child_meshsets( h, iter.childVect );
-    if (!iter.childVect.empty()) {
-     moab()->remove_child_meshset( h, iter.childVect[0] );
-     moab()->remove_child_meshset( h, iter.childVect[1] );
-     stack.push_back( iter.childVect[0] );
-     stack.push_back( iter.childVect[1] );
-    }
-  
-    rval = moab()->delete_entities( &h, 1 );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-
-  
-
-MBErrorCode MBBSPTreeIter::initialize( MBBSPTree* tool,
-                                       MBEntityHandle root,
-                                       const double* point )
-{
-  treeTool = tool;
-  mStack.clear();
-  mStack.push_back( root );
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBBSPTreeIter::step_to_first_leaf( Direction direction )
-{
-  MBErrorCode rval;
-  for (;;) {
-    childVect.clear();
-    rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (childVect.empty()) // leaf
-      break;
-  
-    mStack.push_back( childVect[direction] );
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeIter::step( Direction direction )
-{
-  MBEntityHandle node, parent;
-  MBErrorCode rval;
-  const Direction opposite = static_cast<Direction>(1-direction);
-  
-    // If stack is empty, then either this iterator is uninitialized
-    // or we reached the end of the iteration (and return 
-    // MB_ENTITY_NOT_FOUND) already.
-  if (mStack.empty())
-    return MB_FAILURE;
-    
-    // Pop the current node from the stack.
-    // The stack should then contain the parent of the current node.
-    // If the stack is empty after this pop, then we've reached the end.
-  node = mStack.back();
-  mStack.pop_back();
-  
-  while(!mStack.empty()) {
-      // Get data for parent entity
-    parent = mStack.back();
-    childVect.clear();
-    rval = tool()->moab()->get_child_meshsets( parent, childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-      // If we're at the left child
-    if (childVect[opposite] == node) {
-        // push right child on stack
-      mStack.push_back( childVect[direction] );
-        // descend to left-most leaf of the right child
-      return step_to_first_leaf(opposite);
-    }
-    
-      // The current node is the right child of the parent,
-      // continue up the tree.
-    assert( childVect[direction] == node );
-    node = parent;
-    mStack.pop_back();
-  }
-  
-  return MB_ENTITY_NOT_FOUND;
-}
-
-MBErrorCode MBBSPTreeIter::up() 
-{
-  if (mStack.size() < 2)
-    return MB_ENTITY_NOT_FOUND;
-  mStack.pop_back();
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeIter::down( const MBBSPTree::Plane& plane, Direction dir ) 
-{
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
-  if (MB_SUCCESS != rval)
-    return rval;
-  if (childVect.empty())
-    return MB_ENTITY_NOT_FOUND;
-  
-  mStack.push_back( childVect[dir] );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeIter::get_parent_split_plane( MBBSPTree::Plane& plane ) const
-{
-  if (mStack.size() < 2) // at tree root
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBEntityHandle parent = mStack[mStack.size()-2];
-  return tool()->get_split_plane( parent, plane );
-}
-
-double MBBSPTreeIter::volume() const
-{
-  BSPTreePoly polyhedron;
-  MBErrorCode rval = calculate_polyhedron( polyhedron );
-  return MB_SUCCESS == rval ? polyhedron.volume() : -1.0;
-}
-
-bool MBBSPTreeIter::is_sibling( const MBBSPTreeIter& other_leaf ) const
-{
-  const size_t s = mStack.size();
-  return (s > 1) && (s == other_leaf.mStack.size()) &&
-         (other_leaf.mStack[s-2] == mStack[s-2]) &&
-         other_leaf.handle() != handle();
-}
-
-bool MBBSPTreeIter::is_sibling( MBEntityHandle other_leaf ) const
-{
-  if (mStack.size() < 2 || other_leaf == handle())
-    return false;
-  MBEntityHandle parent = mStack[mStack.size()-2];
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
-  if (MB_SUCCESS != rval || childVect.size() != 2) {
-    assert(false);
-    return false;
-  }
-  return childVect[0] == other_leaf || childVect[1] == other_leaf;
-}
-
-bool MBBSPTreeIter::sibling_is_forward() const
-{
-  if (mStack.size() < 2) // if root
-    return false;
-  MBEntityHandle parent = mStack[mStack.size()-2];
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( parent, childVect );
-  if (MB_SUCCESS != rval || childVect.size() != 2) {
-    assert(false);
-    return false;
-  }
-  return childVect[0] == handle();
-}  
-
-MBErrorCode MBBSPTreeIter::calculate_polyhedron( BSPTreePoly& poly_out ) const
-{
-  MBErrorCode rval;
-  
-  assert( sizeof(MBCartVect) == 3*sizeof(double) );
-  MBCartVect corners[8];
-  rval = treeTool->get_tree_box( mStack.front(), corners[0].array() );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = poly_out.set( corners );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  MBBSPTree::Plane plane;
-  std::vector<MBEntityHandle>::const_iterator i = mStack.begin();
-  std::vector<MBEntityHandle>::const_iterator here = mStack.end() - 1;
-  while (i != here) {
-    rval = treeTool->get_split_plane( *i, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    childVect.clear();
-    rval = treeTool->moab()->get_child_meshsets( *i, childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (childVect.size() != 2)
-      return MB_FAILURE;
-      
-    ++i;
-    if (childVect[1] == *i)
-      plane.flip();
-    
-    MBCartVect norm( plane.norm );
-    poly_out.cut_polyhedron( norm, plane.coeff );
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::initialize( MBBSPTree* tool_ptr,
-                                          MBEntityHandle root,
-                                          const double* point )
-{
-  MBErrorCode rval = MBBSPTreeIter::initialize( tool_ptr, root );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  tool()->get_tree_box( root, leafCoords );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-  if (point && !point_in_box( leafCoords, point ))
-    return MB_ENTITY_NOT_FOUND;
-
-  stackData.resize(1);
-  return MB_SUCCESS;
-}
-
-MBBSPTreeBoxIter::SideBits
-MBBSPTreeBoxIter::side_above_plane( const double hex_coords[8][3],
-                                    const MBBSPTree::Plane& plane )
-{
-  unsigned result  = 0;
-  for (unsigned i = 0; i < 8u; ++i) 
-    result |= plane.above(hex_coords[i]) << i;
-  return (MBBSPTreeBoxIter::SideBits)result;
-}
-
-MBBSPTreeBoxIter::SideBits
-MBBSPTreeBoxIter::side_on_plane( const double hex_coords[8][3],
-                                 const MBBSPTree::Plane& plane )
-{
-  unsigned result  = 0;
-  for (unsigned i = 0; i < 8u; ++i) {
-    bool on = plane.distance(hex_coords[i]) <= MBBSPTree::epsilon();
-    result |= on << i;
-  }
-  return (MBBSPTreeBoxIter::SideBits)result;
-}
-
-static inline void copy_coords( const double src[3], double dest[3] )
-{
-  dest[0] = src[0];
-  dest[1] = src[1];
-  dest[2] = src[2];
-}
-
-MBErrorCode MBBSPTreeBoxIter::face_corners( const SideBits face,
-                                            const double hex_corners[8][3],
-                                            double face_corners[4][3] )
-{
-  switch (face) {
-    case MBBSPTreeBoxIter::B0154:
-      copy_coords( hex_corners[0], face_corners[0] );
-      copy_coords( hex_corners[1], face_corners[1] );
-      copy_coords( hex_corners[5], face_corners[2] );
-      copy_coords( hex_corners[4], face_corners[3] );
-      break;
-    case MBBSPTreeBoxIter::B1265:
-      copy_coords( hex_corners[1], face_corners[0] );
-      copy_coords( hex_corners[2], face_corners[1] );
-      copy_coords( hex_corners[6], face_corners[2] );
-      copy_coords( hex_corners[5], face_corners[3] );
-      break;
-    case MBBSPTreeBoxIter::B2376:
-      copy_coords( hex_corners[2], face_corners[0] );
-      copy_coords( hex_corners[3], face_corners[1] );
-      copy_coords( hex_corners[7], face_corners[2] );
-      copy_coords( hex_corners[6], face_corners[3] );
-      break;
-    case MBBSPTreeBoxIter::B3047:
-      copy_coords( hex_corners[3], face_corners[0] );
-      copy_coords( hex_corners[0], face_corners[1] );
-      copy_coords( hex_corners[4], face_corners[2] );
-      copy_coords( hex_corners[7], face_corners[3] );
-      break;
-    case MBBSPTreeBoxIter::B3210:
-      copy_coords( hex_corners[3], face_corners[0] );
-      copy_coords( hex_corners[2], face_corners[1] );
-      copy_coords( hex_corners[1], face_corners[2] );
-      copy_coords( hex_corners[0], face_corners[3] );
-      break;
-    case MBBSPTreeBoxIter::B4567:
-      copy_coords( hex_corners[4], face_corners[0] );
-      copy_coords( hex_corners[5], face_corners[1] );
-      copy_coords( hex_corners[6], face_corners[2] );
-      copy_coords( hex_corners[7], face_corners[3] );
-      break;
-    default:
-      return MB_FAILURE; // child is not a box
-  }
-  
-  return MB_SUCCESS;
-
-}
-
-/** \brief Clip an edge using a plane
- *
- * Given an edge from keep_end_coords to cut_end_coords,
- * cut the edge using the passed plane, such that cut_end_coords
- * is updated with a new location on the plane, and old_coords_out
- * contains the original value of cut_end_coords.
- */
-static inline
-void plane_cut_edge( double old_coords_out[3],
-                     const double keep_end_coords[3],
-                     double cut_end_coords[3],
-                     const MBBSPTree::Plane& plane )
-{
-  const MBCartVect start( keep_end_coords ), end( cut_end_coords );
-  const MBCartVect norm( plane.norm );
-  MBCartVect xsect_point;
-  
-  const MBCartVect m = end - start;
-  const double t = -(norm % start + plane.coeff) / (norm % m);
-  assert( t > 0.0 && t < 1.0 );
-  xsect_point = start + t * m;
-  
-  end.get( old_coords_out );
-  xsect_point.get( cut_end_coords );
-}
-
-/** Given the corners of a hexahedron in corners_input and a 
- *  plane, cut the hex with the plane, updating corners_input
- *  and storing the original,cut-off side of the hex in cut_face_out.
- *
- *  The portion of the hex below the plane is retained.  cut_face_out
- *  will contain the side of the hex that is entirely above the plane.
- *\return MB_FAILURE if plane/hex intersection is not a quadrilateral.
- */
-static MBErrorCode plane_cut_box( double cut_face_out[4][3],
-                                  double corners_inout[8][3],
-                                  const MBBSPTree::Plane& plane )
-{
-  switch (MBBSPTreeBoxIter::side_above_plane( corners_inout, plane )) {
-    case MBBSPTreeBoxIter::B0154:
-      plane_cut_edge( cut_face_out[0], corners_inout[3], corners_inout[0], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[2], corners_inout[1], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[6], corners_inout[5], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[7], corners_inout[4], plane );
-      break;
-    case MBBSPTreeBoxIter::B1265:
-      plane_cut_edge( cut_face_out[0], corners_inout[0], corners_inout[1], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[3], corners_inout[2], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[7], corners_inout[6], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[4], corners_inout[5], plane );
-      break;
-    case MBBSPTreeBoxIter::B2376:
-      plane_cut_edge( cut_face_out[0], corners_inout[1], corners_inout[2], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[0], corners_inout[3], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[4], corners_inout[7], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[5], corners_inout[6], plane );
-      break;
-    case MBBSPTreeBoxIter::B3047:
-      plane_cut_edge( cut_face_out[0], corners_inout[2], corners_inout[3], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[1], corners_inout[0], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[5], corners_inout[4], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[6], corners_inout[7], plane );
-      break;
-    case MBBSPTreeBoxIter::B3210:
-      plane_cut_edge( cut_face_out[0], corners_inout[7], corners_inout[3], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[6], corners_inout[2], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[5], corners_inout[1], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[4], corners_inout[0], plane );
-      break;
-    case MBBSPTreeBoxIter::B4567:
-      plane_cut_edge( cut_face_out[0], corners_inout[0], corners_inout[4], plane );
-      plane_cut_edge( cut_face_out[1], corners_inout[1], corners_inout[5], plane );
-      plane_cut_edge( cut_face_out[2], corners_inout[2], corners_inout[6], plane );
-      plane_cut_edge( cut_face_out[3], corners_inout[3], corners_inout[7], plane );
-      break;
-    default:
-      return MB_FAILURE; // child is not a box
-  }
-  
-  return MB_SUCCESS;
-}
-
-static inline
-void copy_coords( double dest[3], const double source[3] )
-{
-  dest[0] = source[0];
-  dest[1] = source[1];
-  dest[2] = source[2];
-}
-
-/** reverse of plane_cut_box */
-static inline
-MBErrorCode plane_uncut_box( const double cut_face_in[4][3],
-                             double corners_inout[8][3],
-                             const MBBSPTree::Plane& plane )
-{
-  switch (MBBSPTreeBoxIter::side_on_plane( corners_inout, plane )) {
-    case MBBSPTreeBoxIter::B0154:
-      copy_coords( corners_inout[0], cut_face_in[0] );
-      copy_coords( corners_inout[1], cut_face_in[1] );
-      copy_coords( corners_inout[5], cut_face_in[2] );
-      copy_coords( corners_inout[4], cut_face_in[3] );
-      break;
-    case MBBSPTreeBoxIter::B1265:
-      copy_coords( corners_inout[1], cut_face_in[0] );
-      copy_coords( corners_inout[2], cut_face_in[1] );
-      copy_coords( corners_inout[6], cut_face_in[2] );
-      copy_coords( corners_inout[5], cut_face_in[3] );
-      break;
-    case MBBSPTreeBoxIter::B2376:
-      copy_coords( corners_inout[2], cut_face_in[0] );
-      copy_coords( corners_inout[3], cut_face_in[1] );
-      copy_coords( corners_inout[7], cut_face_in[2] );
-      copy_coords( corners_inout[6], cut_face_in[3] );
-      break;
-    case MBBSPTreeBoxIter::B3047:
-      copy_coords( corners_inout[3], cut_face_in[0] );
-      copy_coords( corners_inout[0], cut_face_in[1] );
-      copy_coords( corners_inout[4], cut_face_in[2] );
-      copy_coords( corners_inout[7], cut_face_in[3] );
-      break;
-    case MBBSPTreeBoxIter::B3210:
-      copy_coords( corners_inout[3], cut_face_in[0] );
-      copy_coords( corners_inout[2], cut_face_in[1] );
-      copy_coords( corners_inout[1], cut_face_in[2] );
-      copy_coords( corners_inout[0], cut_face_in[3] );
-      break;
-    case MBBSPTreeBoxIter::B4567:
-      copy_coords( corners_inout[4], cut_face_in[0] );
-      copy_coords( corners_inout[5], cut_face_in[1] );
-      copy_coords( corners_inout[6], cut_face_in[2] );
-      copy_coords( corners_inout[7], cut_face_in[3] );
-      break;
-    default:
-      return MB_FAILURE; // child is not a box
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::step_to_first_leaf( Direction direction )
-{
-  MBErrorCode rval;
-  MBBSPTree::Plane plane;
-  Corners clipped_corners;
-  
-  for (;;) {
-    childVect.clear();
-    rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (childVect.empty()) // leaf
-      break;
-  
-    rval = tool()->get_split_plane( mStack.back(), plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    if (direction == RIGHT)
-      plane.flip();
-    rval = plane_cut_box( clipped_corners.coords, leafCoords, plane );
-    if (MB_SUCCESS != rval)
-      return rval; 
-    mStack.push_back( childVect[direction] );
-    stackData.push_back( clipped_corners );
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::up()
-{
-  MBErrorCode rval;
-  if (mStack.size() == 1)
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBEntityHandle node = mStack.back();
-  Corners clipped_face = stackData.back();
-  mStack.pop_back();
-  stackData.pop_back();
-  
-  MBBSPTree::Plane plane;
-  rval = tool()->get_split_plane( mStack.back(), plane );
-  if (MB_SUCCESS != rval) {
-    mStack.push_back( node );
-    stackData.push_back( clipped_face );
-    return rval;
-  }
-  
-  rval = plane_uncut_box( clipped_face.coords, leafCoords, plane );
-  if (MB_SUCCESS != rval) {
-    mStack.push_back( node );
-    stackData.push_back( clipped_face );
-    return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::down( const MBBSPTree::Plane& plane_ref, Direction direction )
-{
-  childVect.clear();
-  MBErrorCode rval = tool()->moab()->get_child_meshsets( mStack.back(), childVect );
-  if (MB_SUCCESS != rval)
-    return rval;
-  if (childVect.empty())
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBBSPTree::Plane plane(plane_ref);
-  if (direction == RIGHT)
-    plane.flip();
-  
-  Corners clipped_face;
-  rval = plane_cut_box( clipped_face.coords, leafCoords, plane );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  mStack.push_back( childVect[direction] );
-  stackData.push_back( clipped_face );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::step( Direction direction )
-{
-  MBEntityHandle node, parent;
-  Corners clipped_face;
-  MBErrorCode rval;
-  MBBSPTree::Plane plane;
-  const Direction opposite = static_cast<Direction>(1-direction);
-  
-    // If stack is empty, then either this iterator is uninitialized
-    // or we reached the end of the iteration (and return 
-    // MB_ENTITY_NOT_FOUND) already.
-  if (mStack.empty())
-    return MB_FAILURE;
-    
-    // Pop the current node from the stack.
-    // The stack should then contain the parent of the current node.
-    // If the stack is empty after this pop, then we've reached the end.
-  node = mStack.back();
-  mStack.pop_back();
-  clipped_face = stackData.back();
-  stackData.pop_back();
-  
-  while(!mStack.empty()) {
-      // Get data for parent entity
-    parent = mStack.back();
-    childVect.clear();
-    rval = tool()->moab()->get_child_meshsets( parent, childVect );
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = tool()->get_split_plane( parent, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (direction == LEFT)
-      plane.flip();
-    
-      // If we're at the left child
-    if (childVect[opposite] == node) {
-        // change from box of left child to box of parent
-      plane_uncut_box( clipped_face.coords, leafCoords, plane );
-        // change from box of parent to box of right child
-      plane.flip();
-      plane_cut_box( clipped_face.coords, leafCoords, plane );
-        // push right child on stack
-      mStack.push_back( childVect[direction] );
-      stackData.push_back( clipped_face );
-        // descend to left-most leaf of the right child
-      return step_to_first_leaf(opposite);
-    }
-    
-      // The current node is the right child of the parent,
-      // continue up the tree.
-    assert( childVect[direction] == node );
-    plane.flip();
-    plane_uncut_box( clipped_face.coords, leafCoords, plane );
-    node = parent;
-    clipped_face = stackData.back();
-    mStack.pop_back();
-    stackData.pop_back();
-  }
-  
-  return MB_ENTITY_NOT_FOUND;
-}
-
-MBErrorCode MBBSPTreeBoxIter::get_box_corners( double coords[8][3] ) const
-{
-  memcpy( coords, leafCoords, 24*sizeof(double) );
-  return MB_SUCCESS;
-}
-
-// result = a - b
-static void subtr( double result[3], const double a[3], const double b[3] )
-{
-  result[0] = a[0] - b[0];
-  result[1] = a[1] - b[1];
-  result[2] = a[2] - b[2];
-}
-
-// result = a + b + c + d
-static void sum( double result[3], 
-                 const double a[3], 
-                 const double b[3],
-                 const double c[3],
-                 const double d[3] )
-{
-  result[0] = a[0] + b[0] + c[0] + d[0];
-  result[1] = a[1] + b[1] + c[1] + d[1];
-  result[2] = a[2] + b[2] + c[2] + d[2];
-}
-
-// result = a cross b
-static void cross( double result[3], const double a[3], const double b[3] )
-{
-  result[0] = a[1]*b[2] - a[2]*b[1];
-  result[1] = a[2]*b[0] - a[0]*b[2];
-  result[2] = a[0]*b[1] - a[1]*b[0];
-}
-
-static double dot( const double a[3], const double b[3] )
-{
-  return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
-}
-
-double MBBSPTreeBoxIter::volume() const
-{
-    // have planar sides, so use mid-face tripple product
-  double f1[3], f2[3], f3[3], f4[3], f5[3], f6[3];
-  sum( f1, leafCoords[0], leafCoords[1], leafCoords[4], leafCoords[5] );
-  sum( f2, leafCoords[1], leafCoords[2], leafCoords[5], leafCoords[6] );
-  sum( f3, leafCoords[2], leafCoords[3], leafCoords[6], leafCoords[7] );
-  sum( f4, leafCoords[0], leafCoords[3], leafCoords[4], leafCoords[7] );
-  sum( f5, leafCoords[0], leafCoords[1], leafCoords[2], leafCoords[3] );
-  sum( f6, leafCoords[4], leafCoords[5], leafCoords[6], leafCoords[7] );
-  double v13[3], v24[3], v65[3];
-  subtr( v13, f1, f3 );
-  subtr( v24, f2, f4 );
-  subtr( v65, f6, f5 );
-  double cr[3];
-  cross( cr, v13, v24 );
-  return (1./64) * dot( cr, v65 );
-}
-
-MBBSPTreeBoxIter::XSect 
-MBBSPTreeBoxIter::splits( const MBBSPTree::Plane& plane ) const
-{
-  // test each corner relative to the plane
-  unsigned result  = 0;
-  for (unsigned i = 0; i < 8u; ++i) {
-    double d = plane.signed_distance( leafCoords[i] );
-      // if corner is on plane, than intersection 
-      // will result in a degenerate hex
-    if (fabs(d) < MBBSPTree::epsilon())
-      return NONHEX;
-      // if mark vertices above plane
-    if (d > 0.0)
-      result |= 1<<i;
-  }
-  
-  switch (result) {
-      // if all vertices or no vertices above plane,
-      // then plane doesn't intersect
-    case 0:
-    case 0xFF:
-      return MISS;
-  
-      // if there are four vertices above the plane
-      // and they compose a single face of the hex,
-      // then the cut will result in two hexes
-    case B0154:
-    case B1265:
-    case B2376:
-    case B3047:
-    case B3210:
-    case B4567:
-      return SPLIT;
-      
-      // otherwise intersects, but split would not result
-      // in two hexahedrons
-    default:
-      return NONHEX;
-  }
-}
-
-bool MBBSPTreeBoxIter::intersects( const MBBSPTree::Plane& plane ) const
-{
-  // test each corner relative to the plane
-  unsigned count  = 0;
-  for (unsigned i = 0; i < 8u; ++i) 
-    count += plane.above( leafCoords[i] );
-  return count > 0 && count < 8u;
-}
-
-MBErrorCode MBBSPTreeBoxIter::sibling_side( SideBits& side_out ) const
-{
-  if (mStack.size() < 2) // at tree root
-    return MB_ENTITY_NOT_FOUND;
-  
-  MBEntityHandle parent = mStack[mStack.size()-2];
-  MBBSPTree::Plane plane;
-  MBErrorCode rval = tool()->get_split_plane( parent, plane );
-  if (MB_SUCCESS != rval)
-    return MB_FAILURE;
-  
-  side_out = side_on_plane( leafCoords, plane );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::get_neighbors( 
-                      SideBits side,
-                      std::vector<MBBSPTreeBoxIter>& results,
-                      double epsilon ) const
-{
-  MBEntityHandle handle;
-  MBBSPTree::Plane plane;
-  MBErrorCode rval;
-  int n;
-   
-  Corners face;
-  rval = face_corners( side, leafCoords, face.coords );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // Move up tree until we find the split that created the specified side.
-    // Push the sibling at that level onto the iterator stack as
-    // all neighbors will be rooted at that node.
-  MBBSPTreeBoxIter iter( *this ); // temporary iterator (don't modifiy *this)
-  for (;;) {
-    handle = iter.handle();
-  
-    rval = iter.up();
-    if (MB_SUCCESS != rval) // reached root - no neighbors on that side
-      return (rval == MB_ENTITY_NOT_FOUND) ? MB_SUCCESS : rval;
-    
-    iter.childVect.clear();
-    rval = tool()->moab()->get_child_meshsets( iter.handle(), iter.childVect );
-    if (MB_SUCCESS!= rval)
-      return rval;
-    
-    rval = tool()->get_split_plane( iter.handle(), plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-    SideBits s = side_above_plane( iter.leafCoords, plane );
-
-    if (handle == iter.childVect[0] && s == side) {
-      rval = iter.down( plane, RIGHT );
-      if (MB_SUCCESS != rval)
-        return rval;
-      break;
-    }
-    else if (handle == iter.childVect[1] && opposite_face(s) == side) {
-      rval = iter.down( plane, LEFT );
-      if (MB_SUCCESS != rval)
-        return rval;
-      break;
-    }
-  }
-
-    // now move down tree, searching for adjacent boxes
-  std::vector<MBBSPTreeBoxIter> list;
-    // loop over all potential paths to neighbors (until list is empty)
-  for (;;) {
-      // follow a single path to a leaf, append any other potential
-      // paths to neighbors to 'list'
-    for (;;) { 
-      rval = tool()->moab()->num_child_meshsets( iter.handle(), &n );
-      if (MB_SUCCESS != rval)
-        return rval;
-        
-        // if leaf
-      if (!n) {
-        results.push_back( iter );
-        break; 
-      }
-      
-      rval = tool()->get_split_plane( iter.handle(), plane );
-      if (MB_SUCCESS != rval)
-        return rval;
-     
-      bool some_above = false, some_below = false;
-      for (int i = 0; i < 4; ++i) {
-        double signed_d = plane.signed_distance( face.coords[i] );
-        if (signed_d > -epsilon)
-          some_above = true;
-        if (signed_d < epsilon)
-          some_below = true;
-      }
-     
-      if (some_above && some_below) {
-        list.push_back( iter );
-        list.back().down( plane, RIGHT );
-        iter.down( plane, LEFT );
-      }
-      else if (some_above) {
-        iter.down( plane, RIGHT );
-      }
-      else if (some_below) {
-        iter.down( plane, LEFT );
-      }
-      else {
-        // tolerance issue -- epsilon to small? 2D box?
-        return MB_FAILURE;
-      }
-    }
-    
-    if (list.empty())
-      break;
-    
-    iter = list.back();
-    list.pop_back();
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTreeBoxIter::calculate_polyhedron( BSPTreePoly& poly_out ) const
-{
-  const MBCartVect* ptr = reinterpret_cast<const MBCartVect*>(leafCoords);
-  return poly_out.set( ptr );
-}
-
-MBErrorCode MBBSPTree::leaf_containing_point( MBEntityHandle tree_root,
-                                              const double point[3],
-                                              MBEntityHandle& leaf_out )
-{
-  std::vector<MBEntityHandle> children;
-  Plane plane;
-  MBEntityHandle node = tree_root;
-  MBErrorCode rval = moab()->get_child_meshsets( node, children );
-  if (MB_SUCCESS != rval)
-    return rval;
-  while (!children.empty()) {
-    rval = get_split_plane( node, plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-      
-    node = children[plane.above(point)];
-    children.clear();
-    rval = moab()->get_child_meshsets( node, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  leaf_out = node;
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBBSPTree::leaf_containing_point( MBEntityHandle root,
-                                              const double point[3],
-                                              MBBSPTreeIter& iter )
-{
-  MBErrorCode rval;
-  
-  rval = iter.initialize( this, root, point );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  for (;;) {
-    iter.childVect.clear();
-    rval = moab()->get_child_meshsets( iter.handle(), iter.childVect );
-    if (MB_SUCCESS != rval || iter.childVect.empty())
-      return rval;
-
-    Plane plane;
-    rval = get_split_plane( iter.handle(), plane );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    rval = iter.down( plane, (MBBSPTreeIter::Direction)(plane.above( point )) );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-}
-
-
-
-template <typename PlaneIter> static inline
-bool ray_intersect_halfspaces( const MBCartVect& ray_pt,
-                               const MBCartVect& ray_dir,
-                               const PlaneIter& begin, 
-                               const PlaneIter& end,
-                               double& t_enter, 
-                               double& t_exit )
-{
-  const double epsilon = 1e-12;
-
-    // begin with inifinite ray
-  t_enter = 0.0;
-  t_exit  = std::numeric_limits<double>::infinity();
-
-    // cut ray such that we keep only the portion contained
-    // in each halfspace
-  for (PlaneIter i = begin; i != end; ++i) {
-    MBCartVect norm( i->norm );
-    double coeff = i->coeff;
-    double den = norm % ray_dir;
-    if (fabs(den) < epsilon) { // ray is parallel to plane
-      if (i->above( ray_pt.array() ))
-        return false; // ray entirely outside half-space
-    }
-    else {
-      double t_xsect = (-coeff - (norm % ray_pt)) / den;
-        // keep portion of ray/segment below plane
-      if (den > 0) {
-        if (t_xsect < t_exit)
-          t_exit = t_xsect;
-      }
-      else {
-        if (t_xsect > t_enter)
-          t_enter = t_xsect;
-      }
-    }
-  }
-  
-  return t_exit >= t_enter;
-}
-                               
-class BoxPlaneIter {
-      int faceNum;
-      MBBSPTree::Plane facePlanes[6];
-  
-  public:  
-    BoxPlaneIter( const double coords[8][3] );
-    BoxPlaneIter( ) : faceNum(6) {} // initialize to 'end'
-    const MBBSPTree::Plane* operator->() const
-      { return facePlanes + faceNum; }
-    bool operator==( const BoxPlaneIter& other ) const
-      { return faceNum == other.faceNum; }
-    bool operator!=( const BoxPlaneIter& other ) const
-      { return faceNum != other.faceNum; }
-    BoxPlaneIter& operator++()
-      { ++faceNum; return *this; }
-};
-
-static const int box_face_corners[6][4] = { { 0, 1, 5, 4 },
-                                            { 1, 2, 6, 5 },
-                                            { 2, 3, 7, 6 },
-                                            { 3, 0, 4, 7 },
-                                            { 3, 2, 1, 0 },
-                                            { 4, 5, 6, 7 } };
- 
-BoxPlaneIter::BoxPlaneIter( const double coords[8][3] )
-  : faceNum(0)
-{
-    // NOTE:  In the case of a BSP tree, all sides of the
-    //        leaf will planar.
-  assert( sizeof(MBCartVect) == sizeof(coords[0]) );
-  const MBCartVect* corners = reinterpret_cast<const MBCartVect*>(coords);
-  for (int i = 0; i < 6; ++i) {
-    const int* indices = box_face_corners[i];
-    MBCartVect v1 = corners[indices[1]] - corners[indices[0]];
-    MBCartVect v2 = corners[indices[3]] - corners[indices[0]];
-    MBCartVect n = v1 * v2;
-    facePlanes[i] = MBBSPTree::Plane( n.array(), -(n % corners[indices[2]]) );
-  }
-}
-
-
-bool MBBSPTreeBoxIter::intersect_ray( const double ray_point[3],
-                                      const double ray_vect[3],
-                                      double& t_enter, double& t_exit ) const
-{
-  BoxPlaneIter iter( this->leafCoords ), end;
-  return ray_intersect_halfspaces( MBCartVect(ray_point),
-                                   MBCartVect(ray_vect),
-                                   iter, end,
-                                   t_enter, t_exit );
-}
-
-class BSPTreePlaneIter {
-    MBBSPTree* toolPtr;
-    const MBEntityHandle* const pathToRoot;
-    int pathPos;
-    MBBSPTree::Plane tmpPlane;
-    std::vector<MBEntityHandle> tmpChildren;
-  public:
-    BSPTreePlaneIter( MBBSPTree* tool, const MBEntityHandle* path, int path_len )
-      : toolPtr(tool), pathToRoot(path), pathPos(path_len-1)
-      { operator++(); }
-    BSPTreePlaneIter() // initialize to 'end'
-      : toolPtr(0), pathToRoot(0), pathPos(-1) {}
-  
-    const MBBSPTree::Plane* operator->() const
-      { return &tmpPlane; }
-    bool operator==( const BSPTreePlaneIter& other ) const
-      { return pathPos == other.pathPos; }
-    bool operator!=( const BSPTreePlaneIter& other ) const
-      { return pathPos != other.pathPos; }
-    BSPTreePlaneIter& operator++();
-};
-
-BSPTreePlaneIter& BSPTreePlaneIter::operator++()
-{
-  if (--pathPos < 0)
-    return *this;
-
-  MBEntityHandle prev = pathToRoot[pathPos+1];
-  MBEntityHandle curr = pathToRoot[pathPos];
-  
-  MBErrorCode rval = toolPtr->get_split_plane( curr, tmpPlane );
-  if (MB_SUCCESS != rval) {
-    assert(false);
-    pathPos = 0;
-    return *this;
-  }
-  
-  tmpChildren.clear();
-  rval = toolPtr->moab()->get_child_meshsets( curr, tmpChildren );
-  if (MB_SUCCESS != rval || tmpChildren.size() != 2) {
-    assert(false);
-    pathPos = 0;
-    return *this;
-  }
-  
-  if (tmpChildren[1] == prev) 
-    tmpPlane.flip();
-  return *this;
-}
-
-
-bool MBBSPTreeIter::intersect_ray( const double ray_point[3],
-                                   const double ray_vect[3],
-                                   double& t_enter, double& t_exit ) const
-{
-    // intersect with half-spaces defining tree
-  BSPTreePlaneIter iter1( tool(), &mStack[0], mStack.size() ), end1;
-  if (!ray_intersect_halfspaces( MBCartVect(ray_point),
-                                 MBCartVect(ray_vect),
-                                 iter1, end1,
-                                 t_enter, t_exit ))
-    return false;
-  
-
-    // itersect with box bounding entire tree
-  double corners[8][3];
-  MBErrorCode rval = tool()->get_tree_box( mStack.front(), corners );
-  if (MB_SUCCESS != rval) {
-    assert(false); 
-    return false;
-  }
-  
-  BoxPlaneIter iter2( corners ), end2;
-  double t2_enter, t2_exit;
-  if (!ray_intersect_halfspaces( MBCartVect(ray_point),
-                                 MBCartVect(ray_vect),
-                                 iter2, end2,
-                                 t2_enter, t2_exit ))
-    return false;
-  
-    // if intersect both box and halfspaces, check that
-    // two intersections overlap
-  if (t_enter < t2_enter)
-    t_enter = t2_enter;
-  if (t_exit > t2_exit)
-    t_exit = t2_exit;
-  return t_enter <= t_exit;
-}

Modified: MOAB/trunk/src/MBCN.cpp
===================================================================
--- MOAB/trunk/src/MBCN.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBCN.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,12 +13,14 @@
  * 
  */
 
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 #include "MBCNArrays.hpp"
 #include "MBCN.h"
 #include <assert.h>
 #include <string.h>
 
+namespace moab {
+
 const char *MBCN::entityTypeNames[] = {
     "Vertex",
     "Edge",
@@ -37,14 +39,14 @@
 
 short int MBCN::numberBasis = 0;
 
-const MBDimensionPair MBCN::TypeDimensionMap[] = 
+const DimensionPair MBCN::TypeDimensionMap[] = 
 {
-    MBDimensionPair(MBVERTEX,   MBVERTEX), 
-    MBDimensionPair(MBEDGE,     MBEDGE), 
-    MBDimensionPair(MBTRI,     MBPOLYGON),
-    MBDimensionPair(MBTET,     MBPOLYHEDRON),
-    MBDimensionPair(MBENTITYSET, MBENTITYSET), 
-    MBDimensionPair(MBMAXTYPE, MBMAXTYPE)
+    DimensionPair(MBVERTEX,   MBVERTEX), 
+    DimensionPair(MBEDGE,     MBEDGE), 
+    DimensionPair(MBTRI,     MBPOLYGON),
+    DimensionPair(MBTET,     MBPOLYHEDRON),
+    DimensionPair(MBENTITYSET, MBENTITYSET), 
+    DimensionPair(MBMAXTYPE, MBMAXTYPE)
 };
 
 short MBCN::increasingInts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
@@ -60,9 +62,9 @@
 }
 
 //! return a type for the given name
-MBEntityType MBCN::EntityTypeFromName(const char *name)
+EntityType MBCN::EntityTypeFromName(const char *name)
 {
-  for (MBEntityType i = MBVERTEX; i < MBMAXTYPE; i++) {
+  for (EntityType i = MBVERTEX; i < MBMAXTYPE; i++) {
     if (0 == strcmp(name, entityTypeNames[i]))
       return i;
   }
@@ -70,11 +72,11 @@
   return MBMAXTYPE;
 }
 
-void MBCN::SubEntityNodeIndices( const MBEntityType this_topo, 
+void MBCN::SubEntityNodeIndices( const EntityType this_topo, 
                                  const int num_nodes,
                                  const int sub_dimension,
                                  const int sub_index,
-                                 MBEntityType& subentity_topo,
+                                 EntityType& subentity_topo,
                                  int& num_sub_entity_nodes,
                                  int sub_entity_conn[] )
 {
@@ -101,7 +103,7 @@
     
     const short num_mid = NumSubEntities( subentity_topo, dim );
     for (int i = 0; i < num_mid; ++i) {
-      const MBEntityType sub_sub_topo = SubEntityType( subentity_topo, dim, i );
+      const EntityType sub_sub_topo = SubEntityType( subentity_topo, dim, i );
       const int sub_sub_num_vert = VerticesPerEntity( sub_sub_topo );
       SubEntityVertexIndices( subentity_topo, dim, i, sub_sub_corners );
 
@@ -122,7 +124,7 @@
 //! \param sub_entity_conn Connectivity of sub-entity, based on parent_conn and canonical
 //!           ordering for parent_type
 //! \param num_sub_vertices Number of vertices in sub-entity
-void MBCN::SubEntityConn(const void *parent_conn, const MBEntityType parent_type,
+void MBCN::SubEntityConn(const void *parent_conn, const EntityType parent_type,
                          const int sub_dimension,
                          const int sub_index,
                          void *sub_entity_conn, int &num_sub_vertices) 
@@ -139,7 +141,7 @@
 }
 
 //! given an entity and a target dimension & side number, get that entity
-short int MBCN::AdjacentSubEntities(const MBEntityType this_type,
+short int MBCN::AdjacentSubEntities(const EntityType this_type,
                               const int *source_indices,
                               const int num_source_indices,
                               const int source_dim,
@@ -217,7 +219,7 @@
 
 template <typename T> 
 short int side_number(const T *parent_conn, 
-                const MBEntityType parent_type,
+                const EntityType parent_type,
                 const T *child_conn,
                 const int child_num_verts,
                 const int child_dim,
@@ -239,7 +241,7 @@
                     child_dim, side_no, sense, offset);
 }
 
-short int MBCN::SideNumber(const MBEntityType parent_type, const int *parent_conn, 
+short int MBCN::SideNumber(const EntityType parent_type, const int *parent_conn, 
                      const int *child_conn, const int child_num_verts,
                      const int child_dim,
                      int &side_no, int &sense, int &offset) 
@@ -248,7 +250,7 @@
                      child_dim, side_no, sense, offset);
 }
 
-short int MBCN::SideNumber(const MBEntityType parent_type, const unsigned int *parent_conn, 
+short int MBCN::SideNumber(const EntityType parent_type, const unsigned int *parent_conn, 
                      const unsigned int *child_conn, const int child_num_verts,
                      const int child_dim,
                      int &side_no, int &sense, int &offset)
@@ -256,7 +258,7 @@
   return side_number(parent_conn, parent_type, child_conn, child_num_verts,
                      child_dim, side_no, sense, offset);
 }
-short int MBCN::SideNumber(const MBEntityType parent_type, const long *parent_conn, 
+short int MBCN::SideNumber(const EntityType parent_type, const long *parent_conn, 
                      const long *child_conn, const int child_num_verts,
                      const int child_dim,
                      int &side_no, int &sense, int &offset)
@@ -264,7 +266,7 @@
   return side_number(parent_conn, parent_type, child_conn, child_num_verts,
                      child_dim, side_no, sense, offset);
 }
-short int MBCN::SideNumber(const MBEntityType parent_type, const unsigned long *parent_conn, 
+short int MBCN::SideNumber(const EntityType parent_type, const unsigned long *parent_conn, 
                      const unsigned long *child_conn, const int child_num_verts,
                      const int child_dim,
                      int &side_no, int &sense, int &offset)
@@ -272,7 +274,7 @@
   return side_number(parent_conn, parent_type, child_conn, child_num_verts,
                      child_dim, side_no, sense, offset);
 }
-short int MBCN::SideNumber(const MBEntityType parent_type, void * const *parent_conn, 
+short int MBCN::SideNumber(const EntityType parent_type, void * const *parent_conn, 
                      void * const *child_conn, const int child_num_verts,
                      const int child_dim,
                      int &side_no, int &sense, int &offset)
@@ -281,7 +283,7 @@
                      child_dim, side_no, sense, offset);
 }
 
-short int MBCN::SideNumber( const MBEntityType parent_type,
+short int MBCN::SideNumber( const EntityType parent_type,
                       const int *child_conn_indices,
                       const int child_num_verts,
                       const int child_dim,
@@ -351,7 +353,7 @@
   //! \param child_index The index of the child element
   //! \param opposite_index The index of the opposite element
   //! \return status Returns 0 if successful, -1 if not
-short int MBCN::OppositeSide(const MBEntityType parent_type,
+short int MBCN::OppositeSide(const EntityType parent_type,
                        const int child_index,
                        const int child_dim,
                        int &opposite_index,
@@ -557,7 +559,7 @@
 
   //! for an entity of this type and a specified subfacet (dimension and index), return
   //! the index of the higher order node for that entity in this entity's connectivity array
-short int MBCN::HONodeIndex(const MBEntityType this_type, const int num_verts,
+short int MBCN::HONodeIndex(const EntityType this_type, const int num_verts,
                       const int subfacet_dim, const int subfacet_index) 
 {
   int i;
@@ -593,7 +595,7 @@
   //! and index of the sub-entity that the vertex resolves.  If it does not resolve a
   //! sub-entity, either because it's a corner node or it's not in the element, -1 is
   //! returned in both return values
-void MBCN::HONodeParent( MBEntityType elem_type,
+void MBCN::HONodeParent( EntityType elem_type,
                          int num_verts, 
                          int ho_index,
                          int& parent_dim,
@@ -633,6 +635,12 @@
   }
 }
 
+} // namespace moab
+
+
+using moab::MBCN;
+using moab::EntityType;
+
   //! get the basis of the numbering system
 void MBCN_GetBasis(int *rval) {*rval = MBCN::GetBasis();}
   
@@ -642,7 +650,7 @@
   //! return the string type name for this type
 void MBCN_EntityTypeName(const int this_type, char *rval, int rval_len) 
 {
-  const char *rval_tmp = MBCN::EntityTypeName((MBEntityType)this_type);
+  const char *rval_tmp = MBCN::EntityTypeName((EntityType)this_type);
   int rval_len_tmp = strlen(rval_tmp);
   rval_len_tmp = (rval_len_tmp < rval_len ? rval_len_tmp : rval_len);
   strncpy(rval, rval_tmp, rval_len_tmp);
@@ -657,19 +665,19 @@
   //! return the topological entity dimension
 void MBCN_Dimension(const int t, int *rval) 
 {
-  *rval = MBCN::Dimension((MBEntityType)t);
+  *rval = MBCN::Dimension((EntityType)t);
 }
 
   //! return the number of (corner) vertices contained in the specified type.  
 void MBCN_VerticesPerEntity(const int t, int *rval) 
 {
-  *rval = MBCN::VerticesPerEntity((MBEntityType)t);
+  *rval = MBCN::VerticesPerEntity((EntityType)t);
 }
   
   //! return the number of sub-entities bounding the entity.
 void MBCN_NumSubEntities(const int t, const int d, int *rval) 
 {
-  *rval = MBCN::NumSubEntities((MBEntityType)t, d);
+  *rval = MBCN::NumSubEntities((EntityType)t, d);
 }
 
   //! return the type of a particular sub-entity.
@@ -683,7 +691,7 @@
 
 {
   
-  *rval = MBCN::SubEntityType((MBEntityType)this_type, sub_dimension, index);
+  *rval = MBCN::SubEntityType((EntityType)this_type, sub_dimension, index);
 
 }
 
@@ -698,7 +706,7 @@
                                  const int sub_index,
                                  int sub_entity_conn[]) 
 {
-  MBCN::SubEntityVertexIndices((MBEntityType)this_type, sub_dimension, 
+  MBCN::SubEntityVertexIndices((EntityType)this_type, sub_dimension, 
                                sub_index, sub_entity_conn);
 }
 
@@ -735,7 +743,7 @@
                               const int operation_type, int *rval) 
 {
   std::vector<int> tmp_index_list;
-  *rval = MBCN::AdjacentSubEntities((MBEntityType)this_type, source_indices, 
+  *rval = MBCN::AdjacentSubEntities((EntityType)this_type, source_indices, 
                                     num_source_indices, source_dim, target_dim, 
                                     tmp_index_list, operation_type);
   std::copy(tmp_index_list.begin(), tmp_index_list.end(), index_list);
@@ -757,52 +765,52 @@
                      const int child_dim,
                      int *side_no, int *sense, int *offset) 
 {
-  MBCN::SideNumber((MBEntityType)parent_type, child_conn_indices, child_num_verts, child_dim,
+  MBCN::SideNumber((EntityType)parent_type, child_conn_indices, child_num_verts, child_dim,
                    *side_no, *sense, *offset);
 }
 
-void MBCN_SideNumberInt(const int *parent_conn, const MBEntityType parent_type,
+void MBCN_SideNumberInt(const int *parent_conn, const EntityType parent_type,
                         const int *child_conn, const int child_num_verts,
                         const int child_dim,
                         int *side_no, int *sense, int *offset) 
 {
-  side_number(parent_conn, parent_type, child_conn, child_num_verts, 
+  moab::side_number(parent_conn, parent_type, child_conn, child_num_verts, 
               child_dim, *side_no, *sense, *offset);
 }
 
-void MBCN_SideNumberUint(const unsigned int *parent_conn, const MBEntityType parent_type,
+void MBCN_SideNumberUint(const unsigned int *parent_conn, const EntityType parent_type,
                          const unsigned int *child_conn, const int child_num_verts,
                          const int child_dim,
                          int *side_no, int *sense, int *offset)
 {
-  side_number(parent_conn, parent_type, child_conn, child_num_verts, 
+  moab::side_number(parent_conn, parent_type, child_conn, child_num_verts, 
               child_dim, *side_no, *sense, *offset);
 }
 
-void MBCN_SideNumberLong(const long *parent_conn, const MBEntityType parent_type,
+void MBCN_SideNumberLong(const long *parent_conn, const EntityType parent_type,
                          const long *child_conn, const int child_num_verts,
                          const int child_dim,
                          int *side_no, int *sense, int *offset)
 {
-  side_number(parent_conn, parent_type, child_conn, child_num_verts, 
+  moab::side_number(parent_conn, parent_type, child_conn, child_num_verts, 
               child_dim, *side_no, *sense, *offset);
 }
 
-void MBCN_SideNumberUlong(const unsigned long *parent_conn, const MBEntityType parent_type,
+void MBCN_SideNumberUlong(const unsigned long *parent_conn, const EntityType parent_type,
                           const unsigned long *child_conn, const int child_num_verts,
                           const int child_dim,
                           int *side_no, int *sense, int *offset)
 {
-  side_number(parent_conn, parent_type, child_conn, child_num_verts, 
+  moab::side_number(parent_conn, parent_type, child_conn, child_num_verts, 
               child_dim, *side_no, *sense, *offset);
 }
 
-void MBCN_SideNumberVoid(void * const *parent_conn, const MBEntityType parent_type,
+void MBCN_SideNumberVoid(void * const *parent_conn, const EntityType parent_type,
                          void * const *child_conn, const int child_num_verts,
                          const int child_dim,
                          int *side_no, int *sense, int *offset)
 {
-  side_number(parent_conn, parent_type, child_conn, child_num_verts, 
+  moab::side_number(parent_conn, parent_type, child_conn, child_num_verts, 
               child_dim, *side_no, *sense, *offset);
 }
 
@@ -825,7 +833,7 @@
                        int *opposite_index,
                        int *opposite_dim, int *rval) 
 {
-  *rval = MBCN::OppositeSide((MBEntityType)parent_type, child_index, child_dim, 
+  *rval = MBCN::OppositeSide((EntityType)parent_type, child_index, child_dim, 
                              *opposite_index, *opposite_dim);
 }
 
@@ -889,7 +897,7 @@
 void MBCN_HasMidEdgeNodes(const int this_type, 
                           const int num_verts, int *rval) 
 {
-  *rval = MBCN::HasMidEdgeNodes((MBEntityType)this_type, num_verts);
+  *rval = MBCN::HasMidEdgeNodes((EntityType)this_type, num_verts);
 }
 
   //! true if entities of a given type and number of nodes indicates mid face nodes are present.
@@ -900,7 +908,7 @@
 void MBCN_HasMidFaceNodes(const int this_type, 
                           const int num_verts, int *rval) 
 {
-  *rval = MBCN::HasMidFaceNodes((MBEntityType)this_type, num_verts);
+  *rval = MBCN::HasMidFaceNodes((EntityType)this_type, num_verts);
 }
 
   //! true if entities of a given type and number of nodes indicates mid region nodes are present.
@@ -911,7 +919,7 @@
 void MBCN_HasMidRegionNodes(const int this_type, 
                             const int num_verts, int *rval) 
 {
-  *rval = MBCN::HasMidRegionNodes((MBEntityType)this_type, num_verts);
+  *rval = MBCN::HasMidRegionNodes((EntityType)this_type, num_verts);
 }
 
   //! true if entities of a given type and number of nodes indicates mid edge/face/region nodes 
@@ -924,7 +932,7 @@
                       const int num_verts, 
                       int mid_nodes[4]) 
 {
-  return MBCN::HasMidNodes((MBEntityType)this_type, num_verts, mid_nodes);
+  return MBCN::HasMidNodes((EntityType)this_type, num_verts, mid_nodes);
 }
 
   //! given data about an element and a vertex in that element, return the dimension
@@ -942,7 +950,7 @@
                         int *parent_dim, 
                         int *parent_index ) 
 {
-  return MBCN::HONodeParent((MBEntityType)elem_type, num_nodes, ho_node_index, 
+  return MBCN::HONodeParent((EntityType)elem_type, num_nodes, ho_node_index, 
                             *parent_dim, *parent_index);
 }
 
@@ -959,12 +967,14 @@
 
 {
   
-  *rval = MBCN::HONodeIndex((MBEntityType)this_type, num_verts, subfacet_dim, subfacet_index);
+  *rval = MBCN::HONodeIndex((EntityType)this_type, num_verts, subfacet_dim, subfacet_index);
 
 }
 
+namespace moab {
+
 template <typename T> 
-inline int permute_this(MBEntityType t,
+inline int permute_this(EntityType t,
                         const int dim,
                         T* conn,
                         const int indices_per_ent,
@@ -986,7 +996,7 @@
 }
 
 template <typename T> 
-inline int rev_permute_this(MBEntityType t,
+inline int rev_permute_this(EntityType t,
                             const int dim,
                             T* conn,
                             const int indices_per_ent,
@@ -1008,30 +1018,32 @@
 }
 
 //! Permute this vector
-inline int MBCN::permuteThis(const MBEntityType t, const int dim, int *pvec, 
+inline int MBCN::permuteThis(const EntityType t, const int dim, int *pvec, 
                              const int num_indices, const int num_entries) 
 {return permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::permuteThis(const MBEntityType t, const int dim, unsigned int *pvec, 
+inline int MBCN::permuteThis(const EntityType t, const int dim, unsigned int *pvec, 
                              const int num_indices, const int num_entries) 
 {return permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::permuteThis(const MBEntityType t, const int dim, long *pvec, 
+inline int MBCN::permuteThis(const EntityType t, const int dim, long *pvec, 
                              const int num_indices, const int num_entries) 
 {return permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::permuteThis(const MBEntityType t, const int dim, void **pvec, 
+inline int MBCN::permuteThis(const EntityType t, const int dim, void **pvec, 
                              const int num_indices, const int num_entries) 
 {return permute_this(t, dim, pvec, num_indices, num_entries);}
 
 //! Reverse permute this vector
-inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, int *pvec, 
+inline int MBCN::revPermuteThis(const EntityType t, const int dim, int *pvec, 
                              const int num_indices, const int num_entries) 
 {return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, unsigned int *pvec, 
+inline int MBCN::revPermuteThis(const EntityType t, const int dim, unsigned int *pvec, 
                              const int num_indices, const int num_entries) 
 {return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, long *pvec, 
+inline int MBCN::revPermuteThis(const EntityType t, const int dim, long *pvec, 
                              const int num_indices, const int num_entries) 
 {return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
-inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, void **pvec, 
+inline int MBCN::revPermuteThis(const EntityType t, const int dim, void **pvec, 
                              const int num_indices, const int num_entries) 
 {return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
 
+  
+} // namespace moab

Modified: MOAB/trunk/src/MBCNArrays.hpp
===================================================================
--- MOAB/trunk/src/MBCNArrays.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBCNArrays.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,6 +15,10 @@
 
 #ifndef MBCN_ARRAYS_HPP
 #define MBCN_ARRAYS_HPP
+
+
+namespace moab {
+
 const MBCN::ConnMap MBCN::mConnectivityMap[MBMAXTYPE][3] =
 {
     // vertex-edge
@@ -717,4 +721,8 @@
 // set
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
   };
+  
+  
+} // namespace moab
+
 #endif

Deleted: MOAB/trunk/src/MBCartVect.cpp
===================================================================
--- MOAB/trunk/src/MBCartVect.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBCartVect.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,20 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#include "MBCartVect.hpp"
-#include <ostream>
-
-std::ostream& operator<<( std::ostream& s, const MBCartVect& v )
-  { return s << '[' << v[0] << ' ' << v[1] << ' ' << v[2] << ']'; }

Deleted: MOAB/trunk/src/MBCartVect.hpp
===================================================================
--- MOAB/trunk/src/MBCartVect.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBCartVect.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,157 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBCartVect
- * \brief Cartesian Vector
- * \author Jason Kraftcheck
- * \date July, 2006
- */
-
-#ifndef MB_CART_VECT_HPP
-#define MB_CART_VECT_HPP
-
-#include <cmath>
-#include <iosfwd>
-
-class MBCartVect
-{
-  private:
-    double d[3];
-  
-  public:
-    
-    inline MBCartVect() 
-      { }
-      /**Initialze all three values to same scalar (typically zero)*/
-    explicit inline MBCartVect( double v ) 
-      { d[0] = d[1] = d[2] = v; }
-    inline MBCartVect( double i, double j, double k )
-      { d[0] = i; d[1] = j; d[2] = k; }
-      /**Initialze from array*/
-    explicit inline MBCartVect( const double a[3] )
-      { d[0] = a[0]; d[1] = a[1]; d[2] = a[2]; }
-    inline MBCartVect& operator=( const double v[3] )
-      { d[0]= v[0]; d[1] = v[1]; d[2] = v[2]; return *this; }
-    
-    inline double& operator[]( unsigned i )
-      { return d[i]; }
-    inline double operator[]( unsigned i ) const
-      { return d[i]; }
-    
-    inline MBCartVect& operator+=( const MBCartVect& v )
-      { d[0] += v.d[0]; d[1] += v.d[1]; d[2] += v.d[2]; return *this; }
-    inline MBCartVect& operator-=( const MBCartVect& v )
-      { d[0] -= v.d[0]; d[1] -= v.d[1]; d[2] -= v.d[2]; return *this; }
-      /** Assign cross product to this */
-    inline MBCartVect& operator*=( const MBCartVect& v );
-
-    inline MBCartVect& operator+=( double s )
-      { d[0] += s; d[1] += s; d[2] += s; return *this; }
-    inline MBCartVect& operator-=( double s )
-      { d[0] -= s; d[1] -= s; d[2] -= s; return *this; }
-    inline MBCartVect& operator*=( double s )
-      { d[0] *= s; d[1] *= s; d[2] *= s; return *this; }
-    inline MBCartVect& operator/=( double s )
-      { d[0] /= s; d[1] /= s; d[2] /= s; return *this; }
-    
-    inline double length() const; //!< vector length
-    
-    inline double length_squared() const;
-    
-    inline void normalize(); //!< make unit length
-    
-    inline void flip(); //!< flip direction
-    
-      /** per-element scalar multiply (this[0] *= v[0], this[1] *= v[1], ...) */
-    inline void scale( const MBCartVect& v )
-      { d[0] *= v.d[0]; d[1] *= v.d[1]; d[2] *= v.d[2]; }
-    
-      // get pointer to array of three doubles
-    inline double* array()
-      { return d; }
-    inline const double* array() const
-      { return d; }
-      
-      /** initialize array from this */
-    inline void get( double v[3] ) const
-      { v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
-};
-
-inline MBCartVect operator+( const MBCartVect& u, const MBCartVect& v )
-  { return MBCartVect( u[0] + v[0], u[1] + v[1], u[2] + v[2] ); }
-
-inline MBCartVect operator-( const MBCartVect& u, const MBCartVect& v )
-  { return MBCartVect( u[0] - v[0], u[1] - v[1], u[2] - v[2] ); }
-
-/** cross product */
-inline MBCartVect operator*( const MBCartVect& u, const MBCartVect& v )
-{
-  return MBCartVect( u[1] * v[2] - u[2] * v[1],
-                     u[2] * v[0] - u[0] * v[2],
-                     u[0] * v[1] - u[1] * v[0] );
-}
-
-//! Dot product
-inline double operator%( const MBCartVect& u, const MBCartVect& v )
-  { return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]; }
-
-inline MBCartVect& MBCartVect::operator*=( const MBCartVect& v )
-  { return *this = *this * v; }
-
-inline double MBCartVect::length() const
-  { return std::sqrt( *this % *this ); }
-
-inline double MBCartVect::length_squared() const
-  { return d[0]*d[0] + d[1]*d[1] + d[2]*d[2]; }
-
-inline void MBCartVect::normalize()
-  { *this /= length(); }
-
-inline void MBCartVect::flip()
-  { d[0] = -d[0]; d[1] = -d[1]; d[2] = -d[2]; }
-
-//! Interior angle between two vectors
-inline double angle( const MBCartVect& u, const MBCartVect& v )
-  { return std::acos( (u % v) / std::sqrt((u % u) * (v % v)) ); }
-
-inline MBCartVect operator-( const MBCartVect& v )
-  { return MBCartVect( -v[0], -v[1], -v[2] ); }
-inline MBCartVect operator+( const MBCartVect& v, double s ) 
-  { return MBCartVect( v[0] + s, v[1] + s, v[2] + s ); }
-inline MBCartVect operator-( const MBCartVect& v, double s )
-  { return MBCartVect( v[0] - s, v[1] - s, v[2] - s ); }
-inline MBCartVect operator*( const MBCartVect& v, double s )
-  { return MBCartVect( v[0] * s, v[1] * s, v[2] * s ); }
-inline MBCartVect operator/( const MBCartVect& v, double s )
-  { return MBCartVect( v[0] / s, v[1] / s, v[2] / s ); }
-inline MBCartVect operator+( double s, const MBCartVect& v )
-  { return MBCartVect( v[0] + s, v[1] + s, v[2] + s ); }
-inline MBCartVect operator-( double s, const MBCartVect& v )
-  { return MBCartVect( v[0] - s, v[1] - s, v[2] - s ); }
-inline MBCartVect operator*( double s, const MBCartVect& v )
-  { return MBCartVect( v[0] * s, v[1] * s, v[2] * s ); }
-
-//! Get unit vector in same direction 
-inline MBCartVect unit( const MBCartVect& v )
-{
-  const double len = v.length();
-  return MBCartVect( v[0] / len, v[1] / len, v[2] / len ); 
-}
-
-    
-std::ostream& operator<<( std::ostream& s, const MBCartVect& v );
-
-#endif

Deleted: MOAB/trunk/src/MBCore.cpp
===================================================================
--- MOAB/trunk/src/MBCore.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBCore.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,3543 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifdef WIN32
-// turn off warnings that say they debugging identifier has been truncated
-// this warning comes up when using some STL containers
-#pragma warning(disable : 4786)
-#endif
-
-#include <iostream>
-#include <sstream>
-#include <vector>
-#include <string>
-#include <algorithm>
-#include "MBVersion.h"
-#include "MBCore.hpp"
-#include "TagServer.hpp"
-#include "MeshSetSequence.hpp"
-#include "ElementSequence.hpp"
-#include "VertexSequence.hpp"
-#include "assert.h"
-#include "AEntityFactory.hpp"
-#include "MBReadUtil.hpp"
-#include "MBWriteUtil.hpp"
-#include "MBCN.hpp"
-#include "HigherOrderFactory.hpp"
-#include "SequenceManager.hpp"
-#include "MBError.hpp"
-#include "MBReaderWriterSet.hpp"
-#include "MBReaderIface.hpp"
-#include "MBWriterIface.hpp"
-
-#ifdef USE_MPI
-/* Leave MBParallelComm.hpp before mpi.h or MPICH2 will fail
- * because its C++ headers do not like SEEK_* macros.
- */
-#include "MBParallelComm.hpp"
-#include "MBmpi.h"
-#include "ReadParallel.hpp"
-#endif
-
-#ifdef HDF5_FILE
-#  include "WriteHDF5.hpp"
-   typedef WriteHDF5 DefaultWriter;
-#elif defined(NETCDF_FILE)
-#  include "WriteNCDF.hpp"
-   typedef WriteNCDF DefaultWriter;
-#else
-#  include "WriteVtk.hpp"
-   typedef WriteVtk DefaultWriter;
-#endif
-#include "MBTagConventions.hpp"
-#include "ExoIIUtil.hpp"
-#include "EntitySequence.hpp"
-#include "FileOptions.hpp"
-#ifdef LINUX
-# include <dlfcn.h>
-# include <dirent.h>
-#endif
-
-
-#ifdef XPCOM_MB
-#include "nsMemory.h"
-#endif
-
-using namespace std;
-
-static inline const MBMeshSet* get_mesh_set( const SequenceManager* sm,
-                                             MBEntityHandle h )
-{
-  const EntitySequence* seq;
-  if (MBENTITYSET != TYPE_FROM_HANDLE(h) || MB_SUCCESS != sm->find( h, seq ))
-    return 0;
-  return reinterpret_cast<const MeshSetSequence*>(seq)->get_set(h);
-}
-
-static inline MBMeshSet* get_mesh_set( SequenceManager* sm,
-                                       MBEntityHandle h )
-{
-  EntitySequence* seq;
-  if (MBENTITYSET != TYPE_FROM_HANDLE(h) || MB_SUCCESS != sm->find( h, seq ))
-    return 0;
-  return reinterpret_cast<MeshSetSequence*>(seq)->get_set(h);
-}
-
-//! Constructor
-MBCore::MBCore()
-{
-#ifdef XPCOM_MB
-  NS_INIT_ISUPPORTS();
-#endif
-
-  if (initialize() != MB_SUCCESS)
-  {
-    printf("Error initializing MB\n");
-    exit(1);
-  }
-}
-
-
-//! Constructor
-MBCore::MBCore( int , int  ) 
-{
-  std::cerr << "Using depricated construtor: MBCore::MBCore(rank,size)" << std::endl;
-
-#ifdef XPCOM_MB
-  NS_INIT_ISUPPORTS();
-#endif
-
-  if (initialize() != MB_SUCCESS)
-  {
-    printf("Error initializing MB\n");
-    exit(1);
-  }
-}
-
-//! destructor
-MBCore::~MBCore()
-{
-  if(mMBWriteUtil)
-    delete mMBWriteUtil;
-  if(mMBReadUtil) 
-    delete mMBReadUtil;
-  
-  mMBWriteUtil = NULL;
-  mMBReadUtil = NULL;
-
-  deinitialize();
-}
-
-
-MBErrorCode MBCore::initialize()
-{
-  geometricDimension = 3;
-  materialTag      = 0;
-  neumannBCTag     = 0;
-  dirichletBCTag   = 0;
-  geomDimensionTag = 0;
-  globalIdTag      = 0;
-  
-  sequenceManager = new SequenceManager;
-  if (!sequenceManager)
-    return MB_MEMORY_ALLOCATION_FAILED;
-
-  tagServer = new TagServer( sequenceManager );
-  if (!tagServer)
-    return MB_MEMORY_ALLOCATION_FAILED;
-
-  aEntityFactory = new AEntityFactory(this);
-  if (!aEntityFactory)
-    return MB_MEMORY_ALLOCATION_FAILED;
-
-  mError = new MBError;
-
-  mMBWriteUtil = NULL;
-  mMBReadUtil = NULL;
-    
-    // Readers and writers try to get pointers to above utils.
-    // Do this after pointers are initialized. (Pointers should
-    // really be initialized in constructor to avoid this kind
-    // of thing -- j.kraftcheck.)
-  readerWriterSet = new MBReaderWriterSet( this, mError );
-  if (!readerWriterSet)
-    return MB_MEMORY_ALLOCATION_FAILED;
-  
-  material_tag();
-  neumannBC_tag();
-  dirichletBC_tag();
-  geom_dimension_tag();
-  globalId_tag();
-
-  return MB_SUCCESS;
-}
-
-MBEntityHandle MBCore::get_root_set() 
-{
-  return 0;
-}
-
-void MBCore::deinitialize()
-{
-
-#ifdef USE_MPI    
-  std::vector<MBParallelComm*> pc_list;
-  MBParallelComm::get_all_pcomm(this, pc_list);
-  for (std::vector<MBParallelComm*>::iterator vit = pc_list.begin();
-       vit != pc_list.end(); vit++) 
-    delete *vit;
-#endif
-  
-  if (aEntityFactory)
-    delete aEntityFactory;
-
-  aEntityFactory = 0;
-
-  if (tagServer)
-    delete tagServer;
-
-  tagServer = 0;
-  
-  if (sequenceManager)
-    delete sequenceManager;
-
-  sequenceManager = 0;
-  
-  delete readerWriterSet;
-  readerWriterSet = 0;
-
-  if(mError)
-    delete mError;
-  mError = 0;
-}
-
-MBErrorCode MBCore::query_interface(const std::string& iface_name, void** iface)
-{
-  if(iface_name == "MBReadUtilIface")
-  {
-    if(mMBReadUtil)
-      *iface = (MBReadUtilIface*)mMBReadUtil;
-    else
-      *iface = (MBReadUtilIface*)(mMBReadUtil = new MBReadUtil(this, mError));
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "MBWriteUtilIface")
-  {
-    if(mMBWriteUtil)
-      *iface = (MBWriteUtilIface*)mMBWriteUtil;
-    else
-      *iface = (MBWriteUtilIface*)(mMBWriteUtil = new MBWriteUtil(this, mError));
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "MBReaderWriterSet")
-  {
-    *iface = reader_writer_set();
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "ExoIIInterface")
-  {
-    *iface = (void*)(ExoIIInterface*) new ExoIIUtil(this);
-    return MB_SUCCESS;
-  }
-  return MB_FAILURE;
-}
-
-
-MBErrorCode MBCore::release_interface(const std::string& iface_name, void* iface)
-{
-  if(iface == NULL)
-    return MB_FAILURE;
-
-  if(iface_name == "MBReadUtilIface")
-  {
-      // Is it possible to crash here?  We should fail gracefully instead.
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "MBWriteUtilIface")
-  {
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "MBReaderWriterSet")
-  {
-    return MB_SUCCESS;
-  }
-  else if(iface_name == "ExoIIInterface")
-  {
-    delete (ExoIIInterface*)iface;
-    return MB_SUCCESS;
-  }
-  
-  return MB_FAILURE;
-}
-
-
-#ifdef XPCOM_MB
-// provides basic implementation of nsISupports methods
-NS_IMPL_ISUPPORTS1_CI(MBCore, MBInterface);
-#endif
-
-int MBCore::QueryInterface(const MBuuid& uuid, MBUnknownInterface** iface)
-{
-  *iface = 0;
-  if(uuid == IDD_MBUnknown)
-    *iface = this;
-  if(uuid == IDD_MBCore)
-    *iface = this;
-  else
-    return 0;
-  return 1;
-}
-
-float MBCore::impl_version( std::string *version_string )
-{
-  if (version_string)
-    *version_string = MB_VERSION_STRING;
-  
-  return MB_VERSION_MAJOR + MB_VERSION_MINOR / 100.0f;
-}
-
-//! get the type from a handle, returns type
-MBEntityType MBCore::type_from_handle(const MBEntityHandle handle) const
-{
-  return TYPE_FROM_HANDLE(handle);
-}
-  
-//! get the id from a handle, returns id
-MBEntityID MBCore::id_from_handle(const MBEntityHandle handle) const
-{
-  return ID_FROM_HANDLE(handle);
-}
-
-//! get a handle from an id and type
-MBErrorCode MBCore::handle_from_id( const MBEntityType type, 
-                                    const MBEntityID id, 
-                                    MBEntityHandle& handle) const
-{
-  int err;
-  handle = CREATE_HANDLE(type, id, err);
-
-    //check to see if handle exists 
-  const EntitySequence *dummy_seq = 0;
-  MBErrorCode error_code = sequence_manager()->find(handle, dummy_seq);
-  return error_code; 
-}
-
-int MBCore::dimension_from_handle(const MBEntityHandle handle) const
-{
-  return MBCN::Dimension(TYPE_FROM_HANDLE(handle));
-}
-
-//! load mesh from data in file
-//! NOTE: if there is mesh already present, the new mesh will be added
-MBErrorCode  MBCore::load_mesh( const char *file_name,
-                                const int* block_id_list,
-                                const int num_blocks )
-{
-  const char* name = block_id_list ? MATERIAL_SET_TAG_NAME : 0;
-  return load_file( file_name, 0, 0, name, block_id_list, num_blocks );
-}
-
-MBErrorCode MBCore::load_file( const char* file_name,
-                               const MBEntityHandle* file_set,
-                               const char* options,
-                               const char* set_tag_name,
-                               const int* set_tag_vals,
-                               int num_set_tag_vals )
-{
-  FileOptions opts(options);
-  MBErrorCode rval;
-  MBReaderIface::IDTag t = { set_tag_name, set_tag_vals, num_set_tag_vals, 0, 0 };
-  
-    // if reading in parallel, call a different reader
-  std::string parallel_opt;
-  rval = opts.get_option( "PARALLEL", parallel_opt);
-  if (MB_SUCCESS == rval) {
-#ifdef USE_MPI    
-    MBParallelComm* pcomm = 0;
-    int pcomm_id;
-    rval = opts.get_int_option( "PCOMM", pcomm_id );
-    if (rval == MB_SUCCESS) {
-      pcomm = MBParallelComm::get_pcomm( this, pcomm_id );
-      if (!pcomm)
-        return MB_ENTITY_NOT_FOUND;
-    }
-    else if (rval != MB_ENTITY_NOT_FOUND) 
-      return rval;
-    if (set_tag_name && num_set_tag_vals) 
-      rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts, &t, 1 );
-    else
-      rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts );
-#else
-    mError->set_last_error( "PARALLEL option not valid, this instance"
-                            " compiled for serial execution.\n" );
-    return MB_NOT_IMPLEMENTED;
-#endif
-  }
-  else {
-    if (set_tag_name && num_set_tag_vals) 
-      rval = serial_load_file( file_name, file_set, opts, &t, 1 );
-    else 
-      rval = serial_load_file( file_name, file_set, opts );
-  }
-  
-  if (MB_SUCCESS == rval && !opts.all_seen()) {
-    std::string bad_opt;
-    if (MB_SUCCESS == opts.get_unseen_option( bad_opt ))
-      mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
-    else
-      mError->set_last_error( "Unrecognized option." );
-    rval = MB_UNHANDLED_OPTION;
-  }
-  
-  return rval;
-}
-
-void MBCore::clean_up_failed_read( const MBRange& initial_ents,
-                                   std::vector<MBTag> initial_tags )
-{
-  MBRange new_ents;
-  get_entities_by_handle( 0, new_ents );
-  new_ents = subtract( new_ents, initial_ents );
-  delete_entities( new_ents );
-
-  std::vector<MBTag> all_tags, new_tags;
-  tag_get_tags( all_tags );
-  std::sort( initial_tags.begin(), initial_tags.end() );
-  std::sort( all_tags.begin(), all_tags.end() );
-  std::set_difference( all_tags.begin(), all_tags.end(),
-                       initial_tags.begin(), initial_tags.end(),
-                       std::back_inserter( new_tags ) );
-  while (!new_tags.empty()) {
-    tag_delete( new_tags.back() );
-    new_tags.pop_back();
-  }
-}
-
-MBErrorCode MBCore::serial_load_file( const char* file_name,
-                                      const MBEntityHandle* file_set,
-                                      const FileOptions& opts,
-                                      const MBReaderIface::IDTag* subsets,
-                                      int num_sets,
-                                      const MBTag* id_tag  )
-{
-  if (num_sets < 0)
-    return MB_INDEX_OUT_OF_RANGE;
-  
-  MBErrorCode rval = MB_FAILURE;
-  const MBReaderWriterSet* set = reader_writer_set();
-
-  
-  MBRange initial_ents;
-  rval = get_entities_by_handle( 0, initial_ents );
-  if (MB_SUCCESS != rval)
-    return rval;
-    
-  std::vector<MBTag> initial_tags;
-  rval = tag_get_tags( initial_tags );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-    // otherwise try using the file extension to select a reader
-  MBReaderIface* reader = set->get_file_extension_reader( file_name );
-  if (reader)
-  {
-    rval = reader->load_file( file_name, file_set, opts, subsets, num_sets, id_tag );
-    delete reader;
-  }
-  else
-  {  
-      // Try all the readers
-    MBReaderWriterSet::iterator iter;
-    for (iter = set->begin(); iter != set->end(); ++iter)
-    {
-      MBReaderIface* reader = iter->make_reader( this );
-      if (NULL != reader)
-      {
-        rval = reader->load_file( file_name, file_set, opts, subsets, num_sets, id_tag );
-        delete reader;
-        if (MB_SUCCESS == rval)
-          break;
-        clean_up_failed_read( initial_ents, initial_tags );
-      }
-    }
-  }
-  
-  if (MB_SUCCESS != rval) {
-    clean_up_failed_read( initial_ents, initial_tags );
-  }
-  else if (file_set) {
-    MBRange new_ents;
-    get_entities_by_handle( 0, new_ents );
-    new_ents = subtract( new_ents, initial_ents );
-    rval = add_entities( *file_set, new_ents );
-  }
-  
-  return rval; 
-}
-
-MBErrorCode MBCore::serial_read_tag( const char* file_name,
-                                     const char* tag_name,
-                                     const FileOptions& opts,
-                                     std::vector<int>& vals,
-                                     const MBReaderIface::IDTag* subsets,
-                                     int num_sets )
-{
-  if (num_sets < 0)
-    return MB_INDEX_OUT_OF_RANGE;
-  
-  MBErrorCode rval = MB_FAILURE;
-  const MBReaderWriterSet* set = reader_writer_set();
-
-    // otherwise try using the file extension to select a reader
-  MBReaderIface* reader = set->get_file_extension_reader( file_name );
-  if (reader)
-  {
-    rval = reader->read_tag_values( file_name, tag_name, opts, vals, subsets, num_sets );
-    delete reader;
-  }
-  else
-  {  
-      // Try all the readers
-    MBReaderWriterSet::iterator iter;
-    for (iter = set->begin(); iter != set->end(); ++iter)
-    {
-      MBReaderIface* reader = iter->make_reader( this );
-      if (NULL != reader)
-      {
-        rval = reader->read_tag_values( file_name, tag_name, opts, vals, subsets, num_sets );
-        delete reader;
-        if (MB_SUCCESS == rval)
-          break;
-      }
-    }
-  }
-  
-  return rval; 
-}
-
-MBErrorCode  MBCore::write_mesh(const char *file_name,
-                                  const MBEntityHandle *output_list,
-                                  const int num_sets)
-{
-  return write_file( file_name, 0, 0, output_list, num_sets );
-}
-
-MBErrorCode MBCore::write_file( const char* file_name,
-                                const char* file_type,
-                                const char* options,
-                                const MBEntityHandle* output_sets,
-                                int num_output_sets,
-                                const MBTag* tag_list,
-                                int num_tags )
-{
-  MBRange range;
-  std::copy( output_sets, output_sets+num_output_sets, mb_range_inserter(range) );
-  return write_file( file_name, file_type, options, range, tag_list, num_tags );
-}
-
-MBErrorCode MBCore::write_file( const char* file_name,
-                                const char* file_type,
-                                const char* options_string,
-                                const MBRange& output_sets,
-                                const MBTag* tag_list,
-                                int num_tags )
-{
-    // convert range to vector
-  std::vector<MBEntityHandle> list( output_sets.size() );
-  std::copy( output_sets.begin(), output_sets.end(), list.begin() );
-  
-    // parse some options
-  FileOptions opts( options_string );
-  MBErrorCode rval;
-  
-  rval = opts.get_null_option( "CREATE" );
-  if (rval == MB_TYPE_OUT_OF_RANGE) {
-    mError->set_last_error( "Unexpected value for CREATE option\n" );
-    return MB_FAILURE;
-  }
-  bool overwrite = (rval == MB_ENTITY_NOT_FOUND);
-
-    // Get the file writer
-  MBReaderWriterSet::iterator i;
-  if (file_type) {
-    i = reader_writer_set()->handler_by_name( file_type );
-    if (i == reader_writer_set()->end()) {
-      mError->set_last_error( "Unknown file type: %s\n", file_type );
-      return MB_NOT_IMPLEMENTED;
-    }
-  }
-  else {
-    std::string ext = MBReaderWriterSet::extension_from_filename( file_name );
-    i = reader_writer_set()->handler_from_extension( ext );
-  }
-  
-  MBWriterIface* writer;
-  if (i == reader_writer_set()->end())
-    writer = new DefaultWriter(this);
-  else
-    writer = i->make_writer( this );
-  
-  if (!writer) {
-    mError->set_last_error( "File format supported for reading only.\n" );
-    return MB_NOT_IMPLEMENTED;
-  }
-  
-    // write the file
-  std::vector<std::string> qa_records;
-  const MBEntityHandle* list_ptr = list.empty() ? (MBEntityHandle*)0 : &list[0];
-  rval = writer->write_file(file_name, overwrite, opts, list_ptr, list.size(), qa_records,
-                            tag_list, num_tags );
-  delete writer;
-  
-  if (MB_SUCCESS == rval && !opts.all_seen()) {
-    std::string bad_opt;
-    if (MB_SUCCESS == opts.get_unseen_option( bad_opt ))
-      mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
-    else
-      mError->set_last_error( "Unrecognized option." );
-    rval = MB_UNHANDLED_OPTION;
-  }
-
-  return rval;
-}
-   
-  
-
-//! deletes all mesh entities from this datastore
-MBErrorCode MBCore::delete_mesh()
-{
-
-  MBErrorCode result = MB_SUCCESS;
-
-    // perform all deinitialization procedures to clean up
-  if (aEntityFactory)
-    delete aEntityFactory;
-  aEntityFactory = new AEntityFactory(this);
-
-  tagServer->reset_all_data();
-  
-  sequenceManager->clear();
-
-  return result;
-}
-
-  //! get overall geometric dimension
-MBErrorCode MBCore::get_dimension(int &dim) const
-{
-  dim = geometricDimension;
-  return MB_SUCCESS;
-}
-
-  //! set overall geometric dimension
-  /** Returns error if setting to 3 dimensions, mesh has been created, and 
-   *  there are only 2 dimensions on that mesh
-   */
-MBErrorCode MBCore::set_dimension(const int dim) 
-{
-    // check to see if current dimension is smaller
-  if (geometricDimension < dim) 
-  {
-      // need to check the number of entities 
-    int num;
-    /*MBErrorCode result = */ get_number_entities_by_dimension(0, geometricDimension, num);
-    
-      // test written to be more readable but possibly less efficient
-      //if (MB_SUCCESS != result) return MB_FAILURE;
-      //else if (0 != num && dim == 2 && ycoordTag == 0) return MB_FAILURE;
-      //else if (0 != num && dim == 3 && (ycoordTag == 0 || zcoordTag == 0)) return MB_FAILURE;
-      //TODO -- replace this with not using xcoordTag, etc...
-  }
-    
-    // if we got here, it's ok to set dimension
-  geometricDimension = dim;
-  return MB_SUCCESS;
-}
-
-  //! get blocked vertex coordinates for all vertices
-  /** Blocked = all x, then all y, etc. 
-   */
-MBErrorCode MBCore::get_vertex_coordinates(std::vector<double> &coords) const
-{
-    // INEFFICIENT implementation for now, until we get blocked tag access
-  MBRange vertices;
-  MBErrorCode result = get_entities_by_type(0, MBVERTEX, vertices);
-  if (MB_SUCCESS != result) return result;
-  
-    // the least we can do is resize the vector and only go through the 
-    // vertex list once
-  int num_verts = vertices.size();
-  int vec_pos = 0;
-  double xyz[3];
-  coords.resize(geometricDimension*num_verts);
-  for (MBRange::iterator it = vertices.begin(); it != vertices.end(); it++) 
-  {
-    result = get_coords(&(*it), 1, xyz);
-    if (MB_SUCCESS != result) return result;
-
-    coords[vec_pos] = xyz[0];
-    coords[num_verts+vec_pos] = xyz[1];
-    coords[2*num_verts+vec_pos] = xyz[2];
-
-    vec_pos++;
-  }
-  
-  return result;
-}
-
-MBErrorCode  MBCore::get_coords(const MBRange& entities, double *coords) const
-{
-  const TypeSequenceManager& vert_data = sequence_manager()->entity_map( MBVERTEX );
-  TypeSequenceManager::const_iterator seq_iter;
-  
-  MBRange::const_pair_iterator i = entities.const_pair_begin();
-  MBEntityHandle first = i->first;
-  while (i != entities.const_pair_end()) {
-    
-    seq_iter = vert_data.lower_bound( first );
-    if (seq_iter == vert_data.end() || first < (*seq_iter)->start_handle())
-      return MB_ENTITY_NOT_FOUND;
-    const VertexSequence* vseq = reinterpret_cast<const VertexSequence*>(*seq_iter);
-
-    MBEntityID offset = first - vseq->start_handle();
-    MBEntityID count;
-    if (i->second <= vseq->end_handle()) {
-      count = i->second - first + 1;
-      ++i;
-      if (i != entities.const_pair_end())
-        first = i->first;
-    }
-    else {
-      count = vseq->end_handle() - first + 1;
-      first = vseq->end_handle()+1;
-    }
-    
-    double const *x, *y, *z;
-    MBErrorCode rval = vseq->get_coordinate_arrays( x, y, z );
-    if (MB_SUCCESS != rval)
-      return rval;
-    x += offset;
-    y += offset;
-    z += offset;
-    for (MBEntityID j = 0; j < count; ++j) {
-      *coords = *x; ++coords; ++x;
-      *coords = *y; ++coords; ++y;
-      *coords = *z; ++coords; ++z;
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-/**\author Jason Kraftcheck <kraftche at cae.wisc.edu> - 2007-5-15 */
-MBErrorCode MBCore::get_coords( const MBRange& entities, 
-                                double *x_coords,
-                                double *y_coords,
-                                double *z_coords ) const
-{
-  const TypeSequenceManager& vert_data = sequence_manager()->entity_map( MBVERTEX );
-  TypeSequenceManager::const_iterator seq_iter;
-  
-  MBRange::const_pair_iterator i = entities.const_pair_begin();
-  MBEntityHandle first = i->first;
-  while (i != entities.const_pair_end()) {
-    
-    seq_iter = vert_data.lower_bound( first );
-    if (seq_iter == vert_data.end() || first < (*seq_iter)->start_handle())
-      return MB_ENTITY_NOT_FOUND;
-    const VertexSequence* vseq = reinterpret_cast<const VertexSequence*>(*seq_iter);
-
-    MBEntityID offset = first - vseq->start_handle();
-    MBEntityID count;
-    if (i->second <= vseq->end_handle()) {
-      count = i->second - first + 1;
-      ++i;
-      if (i != entities.const_pair_end())
-        first = i->first;
-    }
-    else {
-      count = vseq->end_handle() - first + 1;
-      first = vseq->end_handle()+1;
-    }
-    
-    double const *x, *y, *z;
-    MBErrorCode rval = vseq->get_coordinate_arrays( x, y, z );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (x_coords) {
-      memcpy( x_coords, x + offset, count * sizeof(double ) );
-      x_coords += count;
-    }
-    if (y_coords) {
-      memcpy( y_coords, y + offset, count * sizeof(double ) );
-      y_coords += count;
-    }
-    if (z_coords) {
-      memcpy( z_coords, z + offset, count * sizeof(double ) );
-      z_coords += count;
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode  MBCore::get_coords(const MBEntityHandle* entities, 
-                                  const int num_entities, 
-                                  double *coords) const
-{
-  const EntitySequence* seq;
-  const VertexSequence* vseq;
-  const MBEntityHandle* const end = entities + num_entities;
-  const MBEntityHandle* iter = entities;
-  
-  seq = sequence_manager()->get_last_accessed_sequence( MBVERTEX );
-  if (!seq) // no vertices
-    return num_entities ? MB_ENTITY_NOT_FOUND : MB_SUCCESS;
-  vseq = static_cast<const VertexSequence*>(seq);
-  
-  while (iter != end) {
-    if (vseq->start_handle() > *iter || vseq->end_handle() < *iter) {
-      if (TYPE_FROM_HANDLE(*iter) != MBVERTEX)
-        return MB_TYPE_OUT_OF_RANGE;
-        
-      if (MB_SUCCESS != sequence_manager()->find(*iter, seq))
-        return MB_ENTITY_NOT_FOUND;
-      vseq = static_cast<const VertexSequence*>(seq);
-    }
-    
-    vseq->get_coordinates( *iter, coords );
-    coords += 3;
-    ++iter;
-  } 
-
-  return MB_SUCCESS; 
-}
-
-
-MBErrorCode  MBCore::get_coords(const MBEntityHandle entity_handle, 
-                                  const double *& x, const double *& y, const double *& z) const
-{
-
-  MBErrorCode status = MB_TYPE_OUT_OF_RANGE;
-
-  if ( TYPE_FROM_HANDLE(entity_handle) == MBVERTEX )
-  {
-    const EntitySequence* seq = 0;
-    status = sequence_manager()->find(entity_handle, seq);
-
-    if (seq == 0 || status != MB_SUCCESS)
-      return MB_ENTITY_NOT_FOUND;
-
-    status = static_cast<const VertexSequence*>(seq)->get_coordinates_ref(entity_handle, 
-                                                                          x, y, z);
-
-  }
-
-  return status; 
-
-}
-
-//! set the coordinate information for this handle if it is of type Vertex
-//! otherwise, return an error
-MBErrorCode  MBCore::set_coords( const MBEntityHandle *entity_handles, 
-                                 const int num_entities, 
-                                 const double *coords)
-{
-
-  MBErrorCode status = MB_SUCCESS;
-
-  int i, j = 0;
-
-  for (i = 0; i < num_entities; i++) {
-    if ( TYPE_FROM_HANDLE(entity_handles[i]) == MBVERTEX )
-    {
-      EntitySequence* seq = 0;
-      status = sequence_manager()->find(entity_handles[i], seq);
-
-      if (seq != 0 && status == MB_SUCCESS) {
-        status = static_cast<VertexSequence*>(seq)->set_coordinates(entity_handles[i], coords[j], coords[j+1], coords[j+2]);
-        j += 3;
-      }
-    }
-    else if (status == MB_SUCCESS)
-      status = MB_TYPE_OUT_OF_RANGE;
-  }
-
-  return status; 
-
-}
-
-//! set the coordinate information for this handle if it is of type Vertex
-//! otherwise, return an error
-MBErrorCode  MBCore::set_coords(MBRange entity_handles, const double *coords)
-{
-
-  MBErrorCode status = MB_SUCCESS;
-
-  int j = 0;
-
-  for (MBRange::iterator rit = entity_handles.begin(); rit != entity_handles.end(); rit++) {
-    if ( TYPE_FROM_HANDLE(*rit) == MBVERTEX )
-    {
-      EntitySequence* seq = 0;
-      status = sequence_manager()->find(*rit, seq);
-
-      if (seq != 0 && status == MB_SUCCESS) {
-        status = static_cast<VertexSequence*>(seq)->set_coordinates(*rit, coords[j], coords[j+1], coords[j+2]);
-        j += 3;
-      }
-    }
-    else if (status == MB_SUCCESS)
-      status = MB_TYPE_OUT_OF_RANGE;
-  }
-
-  return status; 
-
-}
-
-  //! get global connectivity array for specified entity type
-  /**  Assumes just vertices, no higher order nodes
-   */
-MBErrorCode MBCore::get_connectivity_by_type(const MBEntityType type, 
-                                               std::vector<MBEntityHandle> &connect) const
-{
-    // inefficient implementation until we get blocked tag access
-  
-    // get the range of entities of this type
-  MBRange this_range;
-  MBErrorCode result = get_entities_by_type(0, type, this_range);
-  
-  int num_ents = this_range.size();
-  connect.reserve(num_ents*MBCN::VerticesPerEntity(type));
-  
-    // now loop over these entities, getting connectivity for each
-  for (MBRange::iterator this_it = this_range.begin(); 
-       this_it != this_range.end();
-       this_it++)
-  {
-    const MBEntityHandle *connect_vec;
-    result = get_connectivity(*this_it, connect_vec, num_ents, true);
-    if (MB_SUCCESS != result) 
-      return result;
-    connect.insert(connect.end(), &connect_vec[0], &connect_vec[num_ents]); 
-  }
-  
-  return MB_SUCCESS;
-}
-  
-
-//! get the connectivity for element /handles.  For non-element handles, return an error
-MBErrorCode  MBCore::get_connectivity(const MBEntityHandle *entity_handles, 
-                                      const int num_handles,
-                                      MBRange &connectivity,
-                                      bool topological_connectivity) const
-{
-  std::vector<MBEntityHandle> tmp_connect;
-  MBErrorCode result = get_connectivity(entity_handles, num_handles, tmp_connect,
-                                        topological_connectivity);
-  if (MB_SUCCESS != result) return result;
-  
-  std::sort( tmp_connect.begin(), tmp_connect.end() );
-  std::copy(tmp_connect.rbegin(), tmp_connect.rend(), mb_range_inserter(connectivity));
-  return result;
-}
-
-//! get the connectivity for element /handles.  For non-element handles, return an error
-MBErrorCode  MBCore::get_connectivity(const MBEntityHandle *entity_handles, 
-                                      const int num_handles,
-                                      std::vector<MBEntityHandle> &connectivity,
-                                      bool topological_connectivity) const
-{
-  connectivity.clear(); // this seems wrong as compared to other API functions,
-                        // but changing it breaks lost of code, so I'm leaving
-                        // it in.  - j.kraftcheck 2009-11-06
-  
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> tmp_storage; // used only for structured mesh
-  const MBEntityHandle* conn;
-  int len;
-  for (int i = 0; i < num_handles; ++i) {
-    rval = get_connectivity( entity_handles[i], conn, len, topological_connectivity, &tmp_storage );
-    if (MB_SUCCESS != rval)
-      return rval;
-    connectivity.insert( connectivity.end(), conn, conn + len );
-  }
-  return MB_SUCCESS;
-}
-
-//! get the connectivity for element handles.  For non-element handles, return an error
-MBErrorCode MBCore::get_connectivity(const MBEntityHandle entity_handle, 
-                                     const MBEntityHandle*& connectivity,
-                                     int& number_nodes,
-                                     bool topological_connectivity,
-                                     std::vector<MBEntityHandle>* storage) const
-{
-  MBErrorCode status;
-
-    // Make sure the entity should have a connectivity.
-  MBEntityType type = TYPE_FROM_HANDLE(entity_handle);
-  
-    // WARNING: This is very dependent on the ordering of the MBEntityType enum
-  if(type < MBVERTEX || type >= MBENTITYSET)
-    return MB_TYPE_OUT_OF_RANGE;
-
-  else if (type == MBVERTEX) {
-    return MB_FAILURE;
-  }
-  
-  const EntitySequence* seq = 0;
-
-    // We know that connectivity is stored in an EntitySequence so jump straight
-    // to the entity sequence
-  status = sequence_manager()->find(entity_handle, seq);
-  if (seq == 0 || status != MB_SUCCESS) 
-    return MB_ENTITY_NOT_FOUND;
-
-  return static_cast<const ElementSequence*>(seq)->get_connectivity(entity_handle, 
-                                                              connectivity,
-                                                              number_nodes,
-                                                              topological_connectivity,
-                                                              storage);
-}
-
-//! set the connectivity for element handles.  For non-element handles, return an error
-MBErrorCode  MBCore::set_connectivity(const MBEntityHandle entity_handle, 
-                                      MBEntityHandle *connect,
-                                      const int num_connect)
-{
-  MBErrorCode status = MB_FAILURE;
-
-    // Make sure the entity should have a connectivity.
-    // WARNING: This is very dependent on the ordering of the MBEntityType enum
-  MBEntityType type = TYPE_FROM_HANDLE(entity_handle);
-  
-  EntitySequence* seq = 0;
-
-  if (type < MBVERTEX || type > MBENTITYSET)
-    return MB_TYPE_OUT_OF_RANGE;
-  
-  status = sequence_manager()->find(entity_handle, seq);
-  if (seq == 0 || status != MB_SUCCESS)
-    return (status != MB_SUCCESS ? status : MB_ENTITY_NOT_FOUND);
-
-  const MBEntityHandle* old_conn;
-  int len;
-  status = static_cast<ElementSequence*>(seq)->get_connectivity(entity_handle, old_conn, len);
-  if (status != MB_SUCCESS) return status;
-
-  aEntityFactory->notify_change_connectivity(
-    entity_handle, old_conn, connect, num_connect);
-  
-  status = static_cast<ElementSequence*>(seq)->set_connectivity(entity_handle, 
-                                                                connect, num_connect);
-  if (status != MB_SUCCESS) 
-    aEntityFactory->notify_change_connectivity(
-      entity_handle, connect, old_conn, num_connect);
-
-  return status;
-}
-
-
-template <typename ITER> static inline
-MBErrorCode get_adjacencies_union( MBCore* gMB,
-                                   ITER begin, ITER end,
-                                   int to_dimension,
-                                   bool create_if_missing,
-                                   MBRange& adj_entities )
-{ 
-  const size_t DEFAULT_MAX_BLOCKS_SIZE = 4000;
-  const size_t MAX_OUTER_ITERATIONS = 100;
-
-  std::vector<MBEntityHandle> temp_vec, storage;
-  std::vector<MBEntityHandle>::const_iterator ti;
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  ITER i = begin;
-  MBRange::iterator ins;
-  const MBEntityHandle* conn;
-  int conn_len;
-
-    // Just copy any vertices from the input range into the output
-  size_t remaining = end - begin;
-  assert(begin + remaining == end);
-  
-    // How many entities to work with at once? 2000 or so shouldn't require
-    // too much memory, but don't iterate in outer loop more than a
-    // 1000 times (make it bigger if many input entiites.) 
-  const size_t block_size = std::max( DEFAULT_MAX_BLOCKS_SIZE, remaining/MAX_OUTER_ITERATIONS );
-  while (remaining > 0) {
-    const size_t count = remaining > block_size ? block_size : remaining;
-    remaining -= count;
-    temp_vec.clear();
-    for (size_t j = 0; j < count; ++i, ++j) {
-      if (MBCN::Dimension(TYPE_FROM_HANDLE(*i)) == to_dimension) {
-        temp_vec.push_back(*i);
-      }
-      else if (to_dimension == 0 && TYPE_FROM_HANDLE(*i) != MBPOLYHEDRON) {
-        tmp_result = gMB->get_connectivity( *i, conn, conn_len, false, &storage );
-        if (MB_SUCCESS != tmp_result) {
-          result = tmp_result;
-          continue;
-        }
-        temp_vec.insert( temp_vec.end(), conn, conn + conn_len );
-      }
-      else {
-        tmp_result = gMB->a_entity_factory()->get_adjacencies( *i, to_dimension, 
-                                                   create_if_missing, temp_vec);
-      }
-    }
-
-    std::sort( temp_vec.begin(), temp_vec.end() );
-    ins = adj_entities.begin();
-    ti = temp_vec.begin();
-    while (ti != temp_vec.end()) {
-      MBEntityHandle first = *ti;
-      MBEntityHandle second = *ti;
-      for (++ti; ti != temp_vec.end() && (*ti - second <= 1); ++ti)
-        second = *ti;
-      ins = adj_entities.insert( ins, first, second );
-    }
-  }
-  return result;
-}
-
-template <typename ITER> static inline
-MBErrorCode get_adjacencies_intersection( MBCore* mb,
-                             ITER begin, ITER end,
-                             const int to_dimension,
-                             const bool create_if_missing,
-                             std::vector<MBEntityHandle>& adj_entities )
-{
-  const size_t SORT_THRESHOLD = 200;
-  std::vector<MBEntityHandle> temp_vec;
-  std::vector<MBEntityHandle>::iterator adj_it, w_it;
-  MBErrorCode result = MB_SUCCESS;
-  
-  if (begin == end) {
-    adj_entities.clear(); // intersection
-    return MB_SUCCESS;
-  }
-  
-    // First iteration is a special case if input list is empty.
-    // Rather than returning nothing (intersecting with empty
-    // input list), we begin with the adjacencies for the first entity.
-  if (adj_entities.empty()) {
-    MBEntityType type = TYPE_FROM_HANDLE(*begin);
-    if (to_dimension == MBCN::Dimension(type)) 
-      adj_entities.push_back(*begin); 
-    else if(to_dimension == 0 && type != MBPOLYHEDRON)
-      result = mb->get_connectivity(&(*begin), 1, adj_entities);
-    else
-      result = mb->a_entity_factory()->get_adjacencies(*begin, to_dimension, 
-                                                   create_if_missing, adj_entities);
-    if (MB_SUCCESS != result)
-      return result;
-    ++begin;
-  }
-
-  for (ITER from_it = begin; from_it != end; from_it++) 
-  {
-      // running results kept in adj_entities; clear temp_vec, which is working space
-    temp_vec.clear();
-
-      // get the next set of adjacencies
-    MBEntityType type = TYPE_FROM_HANDLE(*from_it);
-    if (to_dimension == MBCN::Dimension(type)) 
-      temp_vec.push_back(*from_it); 
-    else if(to_dimension == 0 && type != MBPOLYHEDRON)
-      result = mb->get_connectivity(&(*from_it), 1, temp_vec);
-    else
-      result = mb->a_entity_factory()->get_adjacencies(*from_it, to_dimension, 
-                                                   create_if_missing, temp_vec);
-    if (MB_SUCCESS != result)
-      return result;
-  
-      // otherwise intersect with the current set of results
-    w_it = adj_it = adj_entities.begin();
-    if (temp_vec.size()*adj_entities.size() < SORT_THRESHOLD) {
-      for (; adj_it != adj_entities.end(); ++adj_it)
-        if (std::find(temp_vec.begin(), temp_vec.end(), *adj_it) != temp_vec.end())
-          { *w_it = *adj_it; ++w_it; }
-    }
-    else {
-      std::sort( temp_vec.begin(), temp_vec.end() );
-      for (; adj_it != adj_entities.end(); ++adj_it)
-        if (std::binary_search(temp_vec.begin(), temp_vec.end(), *adj_it))
-          { *w_it = *adj_it; ++w_it; }
-    }
-    adj_entities.erase( w_it, adj_entities.end() );
-    
-      // we're intersecting, so if there are no more results, we're done
-    if (adj_entities.empty())
-      break;
-  }
-
-  return MB_SUCCESS;
-}
-
-template <typename ITER> static inline
-MBErrorCode get_adjacencies_intersection( MBCore* mb,
-                             ITER begin, ITER end,
-                             const int to_dimension,
-                             const bool create_if_missing,
-                             MBRange& adj_entities )
-{
-  std::vector<MBEntityHandle> results;
-  MBErrorCode rval = get_adjacencies_intersection( mb, begin, end, to_dimension, 
-                                                   create_if_missing, results );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (adj_entities.empty()) {
-    std::copy( results.begin(), results.end(), mb_range_inserter(adj_entities) );
-    return MB_SUCCESS;
-  }
-  
-  MBRange::iterator it = adj_entities.begin();
-  while (it != adj_entities.end()) {
-    if (std::find( results.begin(), results.end(), *it) == results.end())
-      it = adj_entities.erase( it );
-    else
-      ++it;
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::get_adjacencies( const MBEntityHandle *from_entities,
-                                     const int num_entities,
-                                     const int to_dimension,
-                                     const bool create_if_missing,
-                                     std::vector<MBEntityHandle> &adj_entities,
-                                     const int operation_type )
-{
-  if (operation_type == MBInterface::INTERSECT)
-    return get_adjacencies_intersection( this, from_entities, from_entities+num_entities, 
-                                         to_dimension, create_if_missing, adj_entities );
-  else if (operation_type != MBInterface::UNION)
-    return MB_FAILURE;
-    
-    // do union
-  MBErrorCode result;
-  std::vector<MBEntityHandle> tmp_storage;
-  const MBEntityHandle* conn;
-  int len;
-  for (int i = 0; i < num_entities; ++i) {
-    if(to_dimension == 0 && TYPE_FROM_HANDLE(from_entities[0]) != MBPOLYHEDRON) {
-      result = get_connectivity(from_entities[i], conn, len, false, &tmp_storage);
-      adj_entities.insert( adj_entities.end(), conn, conn+len );
-      if (MB_SUCCESS != result)
-        return result;
-    }
-    else {
-      result = aEntityFactory->get_adjacencies(from_entities[i], to_dimension, 
-                                               create_if_missing, adj_entities);
-      if (MB_SUCCESS != result)
-        return result;
-    }
-  }
-  std::sort( adj_entities.begin(), adj_entities.end() );
-  adj_entities.erase( std::unique( adj_entities.begin(), adj_entities.end() ), adj_entities.end() );
- 
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBCore::get_adjacencies( const MBEntityHandle *from_entities,
-                                     const int num_entities,
-                                     const int to_dimension,
-                                     const bool create_if_missing,
-                                     MBRange &adj_entities,
-                                     const int operation_type )
-{
-  if (operation_type == MBInterface::INTERSECT)
-    return get_adjacencies_intersection( this, from_entities, from_entities + num_entities,
-                                         to_dimension, create_if_missing, adj_entities );
-  else if (operation_type == MBInterface::UNION)
-    return get_adjacencies_union( this, from_entities, from_entities + num_entities,
-                                  to_dimension, create_if_missing, adj_entities );
-  else
-    return MB_FAILURE;
-}
-
-MBErrorCode MBCore::get_connectivity( const MBRange& from_entities,
-                                      MBRange& adj_entities,
-                                      bool corners_only ) const
-{
-  const size_t DEFAULT_MAX_BLOCKS_SIZE = 4000;
-  const size_t MAX_OUTER_ITERATIONS = 100;
-
-  std::vector<MBEntityHandle> temp_vec, storage;
-  std::vector<MBEntityHandle>::const_iterator ti;
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  MBRange::const_iterator i = from_entities.begin();
-  MBRange::iterator ins;
-  const MBEntityHandle* conn;
-  int conn_len;
-
-    // Just copy any vertices from the input range into the output
-  size_t remaining = from_entities.size();
-  for (; i != from_entities.end() && TYPE_FROM_HANDLE(*i) == MBVERTEX; ++i) 
-    --remaining;
-  adj_entities.merge( from_entities.begin(), i );
-  
-    // How many entities to work with at once? 2000 or so shouldn't require
-    // too much memory, but don't iterate in outer loop more than a
-    // 1000 times (make it bigger if many input entiites.) 
-  const size_t block_size = std::max( DEFAULT_MAX_BLOCKS_SIZE, remaining/MAX_OUTER_ITERATIONS );
-  while (remaining > 0) {
-    const size_t count = remaining > block_size ? block_size : remaining;
-    remaining -= count;
-    temp_vec.clear();
-    for (size_t j = 0; j < count; ++i, ++j) {
-      tmp_result = get_connectivity( *i, conn, conn_len, corners_only, &storage );
-      if (MB_SUCCESS != tmp_result) {
-        result = tmp_result;
-        continue;
-      }
-
-      const size_t oldsize = temp_vec.size();
-      temp_vec.resize( oldsize + conn_len );
-      memcpy( &temp_vec[oldsize], conn, sizeof(MBEntityHandle)*conn_len );
-    }
-
-    std::sort( temp_vec.begin(), temp_vec.end() );
-    ins = adj_entities.begin();
-    ti = temp_vec.begin();
-    while (ti != temp_vec.end()) {
-      MBEntityHandle first = *ti;
-      MBEntityHandle second = *ti;
-      for (++ti; ti != temp_vec.end() && (*ti - second <= 1); ++ti)
-        second = *ti;
-      ins = adj_entities.insert( ins, first, second );
-    }
-  }
-  return result;
-}
-
-MBErrorCode MBCore::get_vertices( const MBRange& from_entities,
-                                  MBRange& vertices )
-{
-  MBRange range;
-  MBErrorCode rval = get_connectivity( from_entities, range );
-  
-    // If input contained polyhedra, connectivity will contain faces.
-    // Get vertices from faces.
-  if (MB_SUCCESS == rval && !range.all_of_dimension(0)) {
-    MBRange::iterator it = range.upper_bound(MBVERTEX);
-    MBRange polygons;
-    polygons.merge( it, range.end() );
-    range.erase( it, range.end() );
-    rval = get_connectivity( polygons, range );
-  }
-  
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (vertices.empty())
-    vertices.swap( range );
-  else  
-    vertices.merge( range );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::get_adjacencies(const MBRange &from_entities,
-                                      const int to_dimension,
-                                      const bool create_if_missing,
-                                      MBRange &adj_entities,
-                                      const int operation_type)
-{
-  if (operation_type == MBInterface::INTERSECT)
-    return get_adjacencies_intersection( this, from_entities.begin(), from_entities.end(),
-                                         to_dimension, create_if_missing, adj_entities );
-  else if (operation_type != MBInterface::UNION)
-    return MB_FAILURE;
-  else if (to_dimension == 0)
-    return get_vertices( from_entities, adj_entities );
-  else
-    return get_adjacencies_union( this, from_entities.begin(), from_entities.end(),
-                                  to_dimension, create_if_missing, adj_entities );
-}
-
-
-MBErrorCode MBCore::add_adjacencies(const MBEntityHandle entity_handle, 
-                                    const MBEntityHandle *adjacencies,
-                                    const int num_handles,
-                                    bool both_ways)
-{
-  MBErrorCode result = MB_SUCCESS, temp_result;
-  
-  for (const MBEntityHandle *it = adjacencies; 
-       it != adjacencies+num_handles; it++) {
-    temp_result = aEntityFactory->add_adjacency(entity_handle, *it, both_ways);
-    if (MB_SUCCESS != temp_result) result = temp_result;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::add_adjacencies(const MBEntityHandle entity_handle, 
-                                    MBRange &adjacencies,
-                                    bool both_ways)
-{
-  MBErrorCode result = MB_SUCCESS, temp_result;
-  
-  for (MBRange::iterator rit = adjacencies.begin(); rit != adjacencies.end(); rit++) {
-    temp_result = aEntityFactory->add_adjacency(entity_handle, *rit, both_ways);
-    if (MB_SUCCESS != temp_result) result = temp_result;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::remove_adjacencies(const MBEntityHandle entity_handle,
-                                       const MBEntityHandle *adjacencies,
-                                       const int num_handles)
-{
-  MBErrorCode result = MB_SUCCESS, temp_result;
-  
-  for (const MBEntityHandle *it = adjacencies; 
-       it != adjacencies+num_handles; it++) {
-    temp_result = aEntityFactory->remove_adjacency(entity_handle, *it);
-    if (MB_SUCCESS != temp_result) result = temp_result;
-    temp_result = aEntityFactory->remove_adjacency(*it, entity_handle);
-    if (MB_SUCCESS != temp_result) result = temp_result;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_dimension(const MBEntityHandle meshset,
-                                                const int dimension, 
-                                                MBRange &entities,
-                                                const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
-  }
-  else if (dimension > 3) {
-    sequence_manager()->get_entities( MBENTITYSET, entities );
-    result = MB_SUCCESS;
-  } 
-  else {
-    for (MBEntityType this_type = MBCN::TypeDimensionMap[dimension].first;
-         this_type <= MBCN::TypeDimensionMap[dimension].second;
-         this_type++) {
-      sequence_manager()->get_entities( this_type, entities );
-    }
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_dimension(const MBEntityHandle meshset,
-                                                const int dimension, 
-                                                std::vector<MBEntityHandle> &entities,
-                                                const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
-  }
-  else if (dimension > 3) {
-    sequence_manager()->get_entities( MBENTITYSET, entities );
-    result = MB_SUCCESS;
-  } 
-  else {
-    for (MBEntityType this_type = MBCN::TypeDimensionMap[dimension].first;
-         this_type <= MBCN::TypeDimensionMap[dimension].second;
-         this_type++) {
-      sequence_manager()->get_entities( this_type, entities );
-    }
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_type( const MBEntityHandle meshset,
-                                          const MBEntityType type, 
-                                          MBRange &entities,
-                                          const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
-  }  
-  else {
-    sequence_manager()->get_entities( type, entities );
-    result = MB_SUCCESS;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_type( const MBEntityHandle meshset,
-                                          const MBEntityType type, 
-                                          std::vector<MBEntityHandle> &entities,
-                                          const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
-  }  
-  else {
-    sequence_manager()->get_entities( type, entities );
-    result = MB_SUCCESS;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                   const MBEntityType type,
-                                                   const MBTag *tags,
-                                                   const void* const* values,
-                                                   const int num_tags,
-                                                   MBRange &entities,
-                                                   const int condition,
-                                                   const bool recursive) const
-{
-  if (recursive && type == MBENTITYSET)  // will never return anything
-    return MB_TYPE_OUT_OF_RANGE;
-
-  MBErrorCode result;
-  MBRange tmp_range;
-
-  result = get_entities_by_type( meshset, type, tmp_range, recursive );
-  if (MB_SUCCESS != result)
-    return result;
-
-    // if range is empty, return right away; if intersecting condition, 
-    // empty the list too
-  if (tmp_range.empty()) {
-    if (MBInterface::INTERSECT == condition) entities.clear();
-    return MB_SUCCESS;
-  }
-  else if (!entities.empty() && MBInterface::INTERSECT == condition) {
-    entities = intersect( entities, tmp_range);
-    if (entities.empty()) return MB_SUCCESS;
-    tmp_range = entities;
-  }
-    
-  result = tagServer->get_entities_with_tag_values(tmp_range, type, 
-                                                   tags, values, num_tags, 
-                                                   entities, condition); 
-  
-  return result;
-}
-
-MBErrorCode MBCore::get_entities_by_handle(const MBEntityHandle meshset,
-                                             MBRange &entities,
-                                             const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_entities( sequence_manager(), meshset, entities, recursive );
-  }  
-  else {
-    // iterate backards so range insertion is quicker
-    for (MBEntityType type = MBENTITYSET; type >= MBVERTEX; --type)
-      sequence_manager()->get_entities( type, entities );
-  }
-
-  return result;
-}
-
-
-MBErrorCode MBCore::get_entities_by_handle(const MBEntityHandle meshset,
-                                   std::vector<MBEntityHandle> &entities,
-                                   const bool recursive) const
-{
-  MBErrorCode result;
-  if (recursive || !meshset) {
-    MBRange tmp_range;
-    result = get_entities_by_handle( meshset, tmp_range, recursive);
-    size_t offset = entities.size();
-    entities.resize( offset + tmp_range.size() );
-    std::copy( tmp_range.begin(), tmp_range.end(), entities.begin() + offset );
-  }
-  else {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->get_entities( meshset, entities );
-  }  
-  return result;
-}
-
-  //! get # entities of a given dimension
-MBErrorCode MBCore::get_number_entities_by_dimension(const MBEntityHandle meshset,
-                                                       const int dim, 
-                                                       int &number,
-                                                       const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
- 
-  if (!meshset) {
-    number = 0;
-    for (MBEntityType this_type = MBCN::TypeDimensionMap[dim].first;
-         this_type <= MBCN::TypeDimensionMap[dim].second;
-         this_type++) {
-      number += sequence_manager()->get_number_entities( this_type );
-    }
-  }
-  else {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->num_dimension( sequence_manager(), meshset, dim, number, recursive );
-  }  
-  
-  return result;
-}
-
-//! returns the number of entities with a given type and tag
-MBErrorCode MBCore::get_number_entities_by_type(const MBEntityHandle meshset,
-                                                  const MBEntityType type, 
-                                                  int& num_ent,
-                                                  const bool recursive) const
-{
-  MBErrorCode result = MB_SUCCESS;
-
-  if (recursive && type == MBENTITYSET)  // will never return anything
-    return MB_TYPE_OUT_OF_RANGE;
-  
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    result = mseq->num_type( sequence_manager(), meshset, type, num_ent, recursive );
-  }
-  else {
-    num_ent = sequence_manager()->get_number_entities( type );
-  }
-  
-  return result;
-}
-
-MBErrorCode MBCore::get_number_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                          const MBEntityType type,
-                                                          const MBTag *tag_handles,
-                                                          const void* const* values,
-                                                          const int num_tags,
-                                                          int &num_entities,
-                                                          const bool recursive) const
-{
-  MBRange dum_ents;
-  MBErrorCode result = get_entities_by_type_and_tag(meshset, type, tag_handles, values, num_tags, 
-                                                     dum_ents, recursive);
-  num_entities = dum_ents.size();
-  return result;
-}
-
-MBErrorCode MBCore::get_number_entities_by_handle(const MBEntityHandle meshset,
-                                          int& num_ent,
-                                          const bool recursive) const
-{
-  MBErrorCode result;
-  if (meshset) {
-    const EntitySequence* seq;
-    result = sequence_manager()->find( meshset, seq );
-    if (MB_SUCCESS != result)
-      return result;
-    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    return mseq->num_entities( sequence_manager(), meshset, num_ent, recursive );
-  }
-
-  num_ent = 0;
-  for (MBEntityType this_type = MBVERTEX;
-       this_type < MBMAXTYPE;
-       this_type++) {
-    int dummy = 0;
-    result = get_number_entities_by_type(0, this_type, dummy);
-    if (result != MB_SUCCESS) {
-      num_ent = 0;
-      return result;
-    }
-    num_ent += dummy;
-  }
-
-  return MB_SUCCESS;
-}
-
-//! return the tag data for a given EntityHandle and MBTag
-MBErrorCode  MBCore::tag_get_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities,
-                                    void *tag_data) const
-{
-  if (NULL == entity_handles && 0 == num_entities) {
-    return tagServer->get_mesh_data(tag_handle, tag_data);
-  }
-
-  else return tagServer->get_data(tag_handle, entity_handles, num_entities, tag_data);
-}
-
-//! return the tag data for a given EntityHandle and MBTag
-MBErrorCode  MBCore::tag_get_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles,
-                                    void *tag_data) const
-{
-  return tagServer->get_data(tag_handle, entity_handles, tag_data);
-}
-
-//! set the data  for given EntityHandles and MBTag
-MBErrorCode  MBCore::tag_set_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities,
-                                    const void *tag_data)
-{
-  if (NULL == entity_handles && 0 == num_entities)
-    return tagServer->set_mesh_data(tag_handle, tag_data);
-
-  return tagServer->set_data(tag_handle, entity_handles, num_entities, tag_data);
-}
-
-//! set the data  for given EntityHandles and MBTag
-MBErrorCode  MBCore::tag_set_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles, 
-                                    const void *tag_data)
-{
-  return tagServer->set_data(tag_handle, entity_handles, tag_data);
-}
-
-
-//! return the tag data for a given EntityHandle and MBTag
-MBErrorCode  MBCore::tag_get_data( const MBTag tag_handle, 
-                                   const MBEntityHandle* entity_handles, 
-                                   const int num_entities,
-                                   const void** tag_data,
-                                   int* tag_sizes ) const
-{
-  if (NULL == entity_handles && 0 == num_entities) {
-    int size;
-    return tagServer->get_mesh_data(tag_handle, tag_data[0], tag_sizes ? tag_sizes[0] : size );
-  }
-
-  else return tagServer->get_data(tag_handle, entity_handles, num_entities, tag_data, tag_sizes);
-}
-
-//! return the tag data for a given EntityHandle and MBTag
-MBErrorCode  MBCore::tag_get_data( const MBTag tag_handle, 
-                                   const MBRange& entity_handles,
-                                   const void** tag_data,
-                                   int* tag_sizes ) const
-{
-  return tagServer->get_data(tag_handle, entity_handles, tag_data, tag_sizes );
-}
-
-//! set the data  for given EntityHandles and MBTag
-MBErrorCode  MBCore::tag_set_data( const MBTag tag_handle, 
-                                   const MBEntityHandle* entity_handles, 
-                                   const int num_entities,
-                                   void const* const* tag_data,
-                                   const int* tag_sizes )
-{
-  if (NULL == entity_handles && 0 == num_entities)
-    return tagServer->set_mesh_data(tag_handle, tag_data[0], tag_sizes ? tag_sizes[0] : 0);
-
-  return tagServer->set_data(tag_handle, entity_handles, num_entities, tag_data, tag_sizes);
-}
-
-//! set the data  for given EntityHandles and MBTag
-MBErrorCode  MBCore::tag_set_data( const MBTag tag_handle, 
-                                   const MBRange& entity_handles, 
-                                   void const* const* tag_data,
-                                   const int* tag_sizes )
-{
-  return tagServer->set_data(tag_handle, entity_handles, tag_data, tag_sizes);
-}
-
-//! adds a sparse tag for this specific EntityHandle/tag_name combination
-MBErrorCode MBCore::tag_create(const char *tag_name,
-                                 const int tag_size, 
-                                 const MBTagType tag_type,
-                                 MBTag &tag_handle, 
-                                 const void *default_value)
-{
-  MBDataType data_type = (tag_type == MB_TAG_BIT) ? MB_TYPE_BIT : MB_TYPE_OPAQUE;
-  return tag_create( tag_name, tag_size, tag_type, data_type, tag_handle, default_value, false );
-}
-
-MBErrorCode MBCore::tag_create( const char* name,
-                                const int size,
-                                const MBTagType storage,
-                                const MBDataType data,
-                                MBTag& handle,
-                                const void* def_val,
-                                bool use_existing )
-{
-    // This API cannot be used for creating variable-length tags with a 
-    // default value, because there is no argument for the length of
-    // the default value.
-  if (def_val && MB_VARIABLE_LENGTH == size)
-    return MB_VARIABLE_DATA_LENGTH;
-  
-  MBErrorCode rval = tagServer->add_tag( name, size, storage, data, handle, def_val );
-
-    // If it is okay to use an existing tag of the same name, check that it 
-    // matches the input values.  NOTE: we don't check the storage type for 
-    // the tag because the choice of dense vs. sparse is a matter of optimi-
-    // zation, not correctness.  Bit tags require a redundant MB_TYPE_BIT 
-    // for the data type, so we catch those when we check the data type.
-  if (rval == MB_ALREADY_ALLOCATED && use_existing) {
-    handle = tagServer->get_handle( name );
-    const TagInfo* info = tagServer->get_tag_info( handle );
-    if (info->get_size() == size &&  info->get_data_type() == data)  {
-        // If we were not passed a default value, the caller is presumably
-        // OK with an arbitrary default value, so its OK if there is one
-        // set for the tag.
-      if (!def_val)
-        rval = MB_SUCCESS;
-        // If caller specified a default value, there MUST be an existing one
-        // that matches.  We could just set a default value for the tag, but
-        // given the dense tag representation, it isn't feasible to change
-        // the default value once the tag has been created.  For now, don't 
-        // bother because there isn't any mechanism to set it for sparse tags 
-        // anyway.
-      else if (info->default_value() && !memcmp(info->default_value(), def_val, size))
-        rval = MB_SUCCESS;
-    }
-  }
-
-  return rval;
-}
-
-MBErrorCode MBCore::tag_create_variable_length( const char* name,
-                                                MBTagType storage,
-                                                MBDataType data,
-                                                MBTag& handle,
-                                                const void* def_val,
-                                                int def_val_size )
-{
-  return tagServer->add_tag( name, MB_VARIABLE_LENGTH, storage, data, handle, def_val, def_val_size );
-}
-
-//! removes the tag from the entity
-MBErrorCode  MBCore::tag_delete_data(const MBTag tag_handle, 
-                                       const MBEntityHandle *entity_handles,
-                                       const int num_handles)
-{
-  MBErrorCode status = MB_SUCCESS, temp_status;
-  for (int i = 0; i < num_handles; i++) {
-    if (0 == entity_handles[i])
-      temp_status = tagServer->remove_mesh_data(tag_handle);
-    else
-      temp_status = tagServer->remove_data(tag_handle, entity_handles[i]);
-    if (temp_status != MB_SUCCESS) status = temp_status;
-  }
-
-  return status;
-}
-
-//! removes the tag from the entity
-MBErrorCode  MBCore::tag_delete_data(const MBTag tag_handle, 
-                                     const MBRange &entity_handles)
-{
-  MBErrorCode status = MB_SUCCESS, temp_status;
-  for (MBRange::const_iterator it = entity_handles.begin(); it != entity_handles.end(); it++) {
-    temp_status = tagServer->remove_data(tag_handle, *it);
-    if (temp_status != MB_SUCCESS) status = temp_status;
-  }
-
-  return status;
-}
-
-//! removes the tag from MB
-MBErrorCode  MBCore::tag_delete(MBTag tag_handle)
-{
-  return tag_server()->remove_tag(tag_handle);
-}
-
-//! gets the tag name string for the tag_handle
-MBErrorCode  MBCore::tag_get_name(const MBTag tag_handle, 
-                                    std::string& tag_name) const
-{
-  const TagInfo* tag_info = tagServer->get_tag_info( tag_handle );
-  if(!tag_info)
-    return MB_TAG_NOT_FOUND;
-  
-  tag_name = tag_info->get_name();
-  return MB_SUCCESS;
-
-}
-
-//! gets tag handle from its name.
-//! the type must be specified because the same name is valid for multiple types
-MBErrorCode  MBCore::tag_get_handle(const char *tag_name, 
-                                      MBTag &tag_handle) const
-{
-  MBErrorCode status = MB_TAG_NOT_FOUND;
-
-  tag_handle = tagServer->get_handle( tag_name );
-  
-  if (tag_handle != 0)
-  {
-    status = MB_SUCCESS;
-  }
-
-  return status;
-}
-
-  //! get size of tag in bytes
-MBErrorCode MBCore::tag_get_size(const MBTag tag_handle, int &tag_size) const
-{
-  const TagInfo* tag_info = tagServer->get_tag_info( tag_handle );
-  if(!tag_info)
-    return MB_TAG_NOT_FOUND;
-  
-  tag_size = tag_info->get_size();
-  return MB_VARIABLE_LENGTH == tag_size ? MB_VARIABLE_DATA_LENGTH : MB_SUCCESS;
-}
-
-MBErrorCode MBCore::tag_get_data_type( const MBTag handle, 
-                                       MBDataType& type ) const
-{
-  const TagInfo* info = tagServer->get_tag_info( handle );
-  if (!info)
-    return MB_TAG_NOT_FOUND;
-  
-  type = info->get_data_type();
-  return MB_SUCCESS;
-}
-
-  //! get default value of the tag
-MBErrorCode MBCore::tag_get_default_value(const MBTag tag_handle, void *def_value) const
-{
-  int size;
-  return tagServer->get_default_data( tag_handle, def_value, size );
-}
-
-MBErrorCode MBCore::tag_get_default_value( MBTag tag, const void*& ptr, int& size ) const
-{
-  return tagServer->get_default_data_ref( tag, ptr, size );
-}
-
-  //! get type of tag (sparse, dense, etc.; 0 = dense, 1 = sparse, 2 = bit, 3 = static)
-MBErrorCode MBCore::tag_get_type(const MBTag tag_handle, MBTagType &tag_type) const
-{
-  tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
-  return tag_type < MB_TAG_LAST+1 ? MB_SUCCESS : MB_TAG_NOT_FOUND;
-}
-
-  //! get handles for all tags defined
-MBErrorCode MBCore::tag_get_tags(std::vector<MBTag> &tag_handles) const
-{
-  return tagServer->get_tags(tag_handles);
-}
-
-  //! Get handles for all tags defined on this entity
-MBErrorCode MBCore::tag_get_tags_on_entity(const MBEntityHandle entity,
-                                            std::vector<MBTag> &tag_handles) const 
-{
-  if (0 == entity)
-    return tagServer->get_mesh_tags(tag_handles);
-  else return tagServer->get_tags(entity, tag_handles);
-}
-
-MBTag MBCore::material_tag()
-{
-  if (0 == materialTag)
-    tagServer->add_tag(MATERIAL_SET_TAG_NAME, sizeof(int), 
-                       MB_TAG_SPARSE, MB_TYPE_INTEGER, materialTag);
-  return materialTag;
-}
-
-MBTag MBCore::neumannBC_tag()
-{
-  if (0 == neumannBCTag)
-    tagServer->add_tag(NEUMANN_SET_TAG_NAME, sizeof(int), 
-                       MB_TAG_SPARSE, MB_TYPE_INTEGER, neumannBCTag);
-  return neumannBCTag;
-}
-
-MBTag MBCore::dirichletBC_tag()
-{
-  if (0 == dirichletBCTag)
-    tagServer->add_tag(DIRICHLET_SET_TAG_NAME, sizeof(int), 
-                       MB_TAG_SPARSE, MB_TYPE_INTEGER, dirichletBCTag);
-  return dirichletBCTag;
-}
-
-MBTag MBCore::globalId_tag()
-{
-  if (0 == globalIdTag)
-    tagServer->add_tag(GLOBAL_ID_TAG_NAME, sizeof(int), 
-                       MB_TAG_DENSE, MB_TYPE_INTEGER, globalIdTag);
-  return globalIdTag;
-}
-
-MBTag MBCore::geom_dimension_tag()
-{
-  if (0 == geomDimensionTag)
-    tagServer->add_tag(GEOM_DIMENSION_TAG_NAME, sizeof(int), 
-                       MB_TAG_SPARSE, MB_TYPE_INTEGER, geomDimensionTag);
-  return geomDimensionTag;
-}
-
-//! creates an element based on the type and connectivity.  returns a handle and error code
-MBErrorCode MBCore::create_element(const MBEntityType type, 
-                                   const MBEntityHandle *connectivity,
-                                   const int num_nodes, 
-                                   MBEntityHandle &handle)
-{
-    // make sure we have enough vertices for this entity type
-  if(num_nodes < MBCN::VerticesPerEntity(type))
-    return MB_FAILURE;
-  
-  MBErrorCode status = sequence_manager()->create_element(type, connectivity, num_nodes, handle);
-  if (MB_SUCCESS == status)
-    status = aEntityFactory->notify_create_entity( handle, connectivity, num_nodes); 
-
-  return status;
-}  
-
-//! creates a vertex based on coordinates, returns a handle and error code
-MBErrorCode MBCore::create_vertex(const double coords[3], MBEntityHandle &handle )
-{
-    // get an available vertex handle
-  return sequence_manager()->create_vertex( coords, handle );
-}
-
-MBErrorCode MBCore::create_vertices(const double *coordinates, 
-                                    const int nverts,
-                                    MBRange &entity_handles ) 
-{
-    // Create vertices
-  void* tmp_ptr;
-  MBErrorCode result = this->query_interface("MBReadUtilIface", &tmp_ptr );
-  if (MB_SUCCESS != result) return result;
-  MBReadUtilIface *read_iface = reinterpret_cast<MBReadUtilIface*>(tmp_ptr);
-  
-  std::vector<double*> arrays;
-  MBEntityHandle start_handle_out = 0;
-  result = read_iface->get_node_arrays( 3, nverts, MB_START_ID, 
-                                        start_handle_out, arrays);
-  if (MB_SUCCESS != result) return result;
-  for (int i = 0; i < nverts; i++) {
-    arrays[0][i] = coordinates[3*i];
-    arrays[1][i] = coordinates[3*i+1];
-    arrays[2][i] = coordinates[3*i+2];
-  }
-
-  entity_handles.clear();
-  entity_handles.insert(start_handle_out, start_handle_out+nverts-1);
-  
-  return MB_SUCCESS;
-}
-
-
-//! merges two  entities
-MBErrorCode MBCore::merge_entities( MBEntityHandle entity_to_keep, 
-                                      MBEntityHandle entity_to_remove,
-                                      bool auto_merge,
-                                      bool delete_removed_entity)
-{
-  if (auto_merge) return MB_FAILURE;
-  
-    // The two entities to merge must be of the same type
-  MBEntityType type_to_keep = TYPE_FROM_HANDLE(entity_to_keep);
-
-  if (type_to_keep != TYPE_FROM_HANDLE(entity_to_remove))
-    return MB_TYPE_OUT_OF_RANGE;
-
-    // Make sure both entities exist before trying to merge.
-  EntitySequence* seq = 0;
-  MBErrorCode result, status;
-  status = sequence_manager()->find(entity_to_keep, seq);
-  if(seq == 0 || status != MB_SUCCESS)
-    return MB_ENTITY_NOT_FOUND;
-  status = sequence_manager()->find(entity_to_remove, seq);
-  if(seq == 0 || status != MB_SUCCESS)
-    return MB_ENTITY_NOT_FOUND;
-  
-    // If auto_merge is not set, all sub-entities should
-    // be merged if the entities are to be merged.
-  int ent_dim = MBCN::Dimension(type_to_keep);
-  if(ent_dim > 0)
-  {
-    std::vector<MBEntityHandle> conn, conn2;
-
-    result = get_connectivity(&entity_to_keep, 1, conn);
-    if(result != MB_SUCCESS)
-      return result;
-    result = get_connectivity(&entity_to_remove, 1, conn2);
-    if(result != MB_SUCCESS)
-      return result;
-
-      // Check to see if we can merge before pulling adjacencies.
-    int dum1, dum2;
-    if(!auto_merge && 
-       (conn.size() != conn2.size() ||
-        !MBCN::ConnectivityMatch(&conn[0], &conn2[0], conn.size(), dum1, dum2)))
-      return MB_FAILURE;
-  }
-
-  result = aEntityFactory->merge_adjust_adjacencies(entity_to_keep, entity_to_remove);
-  
-  if (MB_SUCCESS == result && delete_removed_entity) 
-    result = delete_entities(&entity_to_remove, 1);
-
-  return result;
-}
-
-
-//! deletes an entity range
-MBErrorCode MBCore::delete_entities(const MBRange &range)
-{
-  MBErrorCode result = MB_SUCCESS, temp_result;
-  
-  for (MBRange::const_reverse_iterator rit = range.rbegin(); rit != range.rend(); rit++) {
-    
-      // tell AEntityFactory that this element is going away
-    temp_result = aEntityFactory->notify_delete_entity(*rit);
-    if (MB_SUCCESS != temp_result) {
-      result = temp_result;
-      continue;
-    }
-
-      // reset and/or clean out data associated with this entity handle
-    temp_result = tagServer->reset_data(*rit);
-    if (MB_SUCCESS != temp_result) {
-      result = temp_result;
-      continue;
-    }
-
-    if (TYPE_FROM_HANDLE(*rit) == MBENTITYSET) {
-      if (MBMeshSet* ptr = get_mesh_set( sequence_manager(), *rit )) {
-        int j, count;
-        const MBEntityHandle* rel;
-        ptr->clear( *rit, a_entity_factory() );
-        rel = ptr->get_parents( count );
-        for (j = 0; j < count; ++j)
-          remove_child_meshset( rel[j], *rit );
-        rel = ptr->get_children( count );
-        for (j = 0; j < count; ++j)
-          remove_parent_meshset( rel[j], *rit );
-      }
-    }
-
-      // now delete the entity
-    temp_result = sequence_manager()->delete_entity(*rit);
-    if (MB_SUCCESS != temp_result) {
-      result = temp_result;
-      continue;
-    }
-  }
-
-  return result;
-}
-
-
-//! deletes an entity vector
-MBErrorCode MBCore::delete_entities(const MBEntityHandle *entities,
-                                    const int num_entities)
-{
-  MBRange range;
-  std::copy(entities, entities+num_entities, mb_range_inserter(range));
-  return delete_entities(range);
-}
-
-MBErrorCode MBCore::list_entities(const MBEntityHandle *entities,
-                                    const int num_entities) const
-{
-  MBRange temp_range;
-  MBErrorCode result = MB_SUCCESS;
-  if (NULL == entities && num_entities <= 0) {
-      // just list the numbers of each entity type
-    int num_ents;
-    std::cout << std::endl;
-    std::cout << "Number of entities per type: " << std::endl;
-    for (MBEntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
-      result = get_number_entities_by_type(0, this_type, num_ents);
-      std::cout << MBCN::EntityTypeName(this_type) << ": " << num_ents << std::endl;
-    }
-    std::cout << std::endl;
-
-      // if negative num_entities, list the set hierarchy too
-    if (0 > num_entities) {
-      MBRange sets;
-      result = this->get_entities_by_type(0, MBENTITYSET, sets);
-      if (MB_SUCCESS != result) return result;
-      for (MBRange::iterator rit = sets.begin(); rit != sets.end(); rit++) {
-        this->print(*rit, "", false);
-        result = this->get_number_entities_by_handle(*rit, num_ents);
-        std::cout << "(" << num_ents << " total entities)" << std::endl;
-      }
-    }
-    
-    return MB_SUCCESS;
-  }
-      
-  else if (NULL == entities) {
-
-      // list all entities of all types
-    std::cout << std::endl;
-    for (MBEntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++) {
-      result = get_entities_by_type(0, this_type, temp_range);
-    }
-
-    return list_entities(temp_range);
-  }
-
-  else {
-    MBErrorCode tmp_result;
-    for (int i = 0; i < num_entities; i++) {
-      MBEntityType this_type = TYPE_FROM_HANDLE(entities[i]);
-      std::cout << MBCN::EntityTypeName(this_type) << " " 
-                << ID_FROM_HANDLE(entities[i]) << ":" << endl;
-
-      tmp_result = (const_cast<MBCore*>(this))->list_entity(entities[i]);
-      if (MB_SUCCESS != tmp_result) result = tmp_result;
-    }
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::list_entities(const MBRange &temp_range) const
-{
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  
-  for (MBRange::const_iterator rit = temp_range.begin(); rit != temp_range.end(); rit++) {
-    MBEntityType this_type = TYPE_FROM_HANDLE(*rit);
-    std::cout << MBCN::EntityTypeName(this_type) << " " << ID_FROM_HANDLE(*rit) << ":" << endl;
-
-    tmp_result = (const_cast<MBCore*>(this))->list_entity(*rit);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-    
-  return result;
-}
-  
-MBErrorCode MBCore::list_entity(const MBEntityHandle entity) const
-{
-  MBErrorCode result;
-  MBHandleVec adj_vec;
-
-  if (!is_valid(entity)) {
-    std::cout << "(invalid)" << std::endl;
-    return MB_SUCCESS;
-  }
-
-  if (0 != globalIdTag) {
-    int dum;
-    result = tag_get_data(globalIdTag, &entity, 1, &dum);
-    if (MB_SUCCESS == result)
-      std::cout << "Global id = " << dum << std::endl;
-  }
-  
-    // list entity
-  MBEntityType this_type = TYPE_FROM_HANDLE(entity);
-  if (this_type == MBVERTEX) {
-    double coords[3];
-    result = get_coords(&(entity), 1, coords);
-    if (MB_SUCCESS != result) return result;
-    std::cout << "Coordinates: (" << coords[0] << ", " << coords[1] << ", " << coords[2] 
-              << ")" << std::endl;
-  }
-  else if (this_type == MBENTITYSET)
-    this->print(entity, "");
-    
-  std::cout << "  Adjacencies:" << std::endl;
-  bool some = false;
-  int multiple = 0;
-  for (int dim = 0; dim <= 3; dim++) {
-    if (dim == MBCN::Dimension(this_type)) continue;
-    adj_vec.clear();
-      // use const_cast here 'cuz we're in a const function and we're passing 'false' for
-      // create_if_missing, so we know we won't change anything
-    result = (const_cast<MBCore*>(this))->get_adjacencies(&(entity), 1, dim, false, adj_vec);
-    if (MB_FAILURE == result) continue;
-    for (MBHandleVec::iterator adj_it = adj_vec.begin(); adj_it != adj_vec.end(); adj_it++) {
-      if (adj_it != adj_vec.begin()) std::cout << ", ";
-      else std::cout << "   ";
-      std::cout << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*adj_it)) << " " << ID_FROM_HANDLE(*adj_it);
-    }
-    if (!adj_vec.empty()) {
-      std::cout << std::endl;
-      some = true;
-    }
-    if (MB_MULTIPLE_ENTITIES_FOUND == result)
-      multiple += dim;
-  }
-  if (!some) std::cout << "(none)" << std::endl;
-  const MBEntityHandle *explicit_adjs;
-  int num_exp;
-  aEntityFactory->get_adjacencies(entity, explicit_adjs, num_exp);
-  if (NULL != explicit_adjs && 0 != num_exp) {
-    std::cout << "  Explicit adjacencies: ";
-    for (int i = 0; i < num_exp; i++) {
-      if (i != 0) std::cout << ", ";
-      std::cout << MBCN::EntityTypeName(TYPE_FROM_HANDLE(explicit_adjs[i])) << " " 
-                << ID_FROM_HANDLE(explicit_adjs[i]);
-    }
-    std::cout << std::endl;
-  }
-  if (multiple != 0)
-    std::cout << "   (MULTIPLE = " << multiple << ")" << std::endl;
-
-  std::cout << std::endl;
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::convert_entities( const MBEntityHandle meshset, 
-                                        const bool mid_side, const bool mid_face, const bool mid_volume,
-                                        MBInterface::HONodeAddedRemoved* function_object )
-{
-  HigherOrderFactory fact(this, function_object);
-  return fact.convert(meshset, mid_side, mid_face, mid_volume);
-}
-
-  //! function to get the side number given two elements; returns
-  //! MB_FAILURE if child not related to parent; does *not* create adjacencies
-  //! between parent and child
-MBErrorCode MBCore::side_number(const MBEntityHandle parent,
-                                  const MBEntityHandle child,
-                                  int &side_number,
-                                  int &sense,
-                                  int &offset) const
-{
-    // get the connectivity of parent and child
-  const MBEntityHandle *parent_conn, *child_conn;
-  int num_parent_vertices, num_child_vertices;
-  MBErrorCode result = get_connectivity(parent, parent_conn, num_parent_vertices, true);
-  if (MB_NOT_IMPLEMENTED == result) {
-    static std::vector<MBEntityHandle> tmp_connect(MBCN::MAX_NODES_PER_ELEMENT);
-    result = get_connectivity(parent, parent_conn, num_parent_vertices, true, &tmp_connect);
-  }
-  if (MB_SUCCESS != result) return result;
-
-  if (TYPE_FROM_HANDLE(child) == MBVERTEX) {
-    int child_index = std::find(parent_conn, parent_conn+num_parent_vertices,
-                                child) - parent_conn;
-    if (child_index == num_parent_vertices) {
-      side_number = -1;
-      sense = 0;
-      return MB_SUCCESS;
-    }
-    else {
-      side_number = child_index;
-      sense = 1; 
-      return MB_SUCCESS;
-    }
-  }
-    
-  result = get_connectivity(child, child_conn, num_child_vertices, true);
-  if (MB_SUCCESS != result) return result;
-
-    // call handle vector-based function
-  if (TYPE_FROM_HANDLE(parent) != MBPOLYGON &&
-      TYPE_FROM_HANDLE(parent) != MBPOLYHEDRON) {
-
-      // find indices into parent_conn for each entry in child_conn
-    int child_conn_indices[10];
-    assert((unsigned)num_child_vertices <= sizeof(child_conn_indices)/sizeof(child_conn_indices[0]));
-    for (int i = 0; i < num_child_vertices; ++i) {
-      child_conn_indices[i] = std::find( parent_conn,
-        parent_conn + num_parent_vertices, child_conn[i] ) - parent_conn;
-      if (child_conn_indices[i] >= num_parent_vertices) {
-        side_number = -1;
-        return MB_SUCCESS;
-      }
-    }
-    
-    int temp_result = MBCN::SideNumber(TYPE_FROM_HANDLE(parent),
-                                       child_conn_indices, num_child_vertices, 
-                                       MBCN::Dimension(TYPE_FROM_HANDLE(child)), 
-                                       side_number, sense, offset);
-    return (0 == temp_result ? MB_SUCCESS : MB_FAILURE);
-  }
-  else if (TYPE_FROM_HANDLE(parent) == MBPOLYGON) {
-      // find location of 1st vertex
-    const MBEntityHandle *first_v = std::find(parent_conn, parent_conn+num_parent_vertices,
-                                              child_conn[0]);
-    if (first_v == parent_conn+num_parent_vertices) return MB_ENTITY_NOT_FOUND;
-    side_number = first_v - parent_conn;
-    offset = side_number;
-    if (TYPE_FROM_HANDLE(child) == MBVERTEX) {
-      sense = 0;
-      return MB_SUCCESS;
-    }
-    else if (TYPE_FROM_HANDLE(child) == MBPOLYGON) {
-      bool match = MBCN::ConnectivityMatch(parent_conn, child_conn,
-                                           num_parent_vertices,
-                                           sense, offset);
-      side_number = 0;
-      if (match) return MB_SUCCESS;
-      else return MB_ENTITY_NOT_FOUND;
-    }
-    else if (TYPE_FROM_HANDLE(child) == MBEDGE) {
-      if (parent_conn[(side_number+1)%num_parent_vertices] == child_conn[1])
-        sense = 1;
-      else if (parent_conn[(side_number+num_parent_vertices-1)%num_parent_vertices] ==
-               child_conn[1])
-        sense = -1;
-      return MB_SUCCESS;
-    }
-  }
-  
-  return MB_FAILURE;
-}
-
-  //! given an entity and the connectivity and type of one of its subfacets, find the
-  //! high order node on that subfacet, if any
-MBErrorCode MBCore::high_order_node(const MBEntityHandle parent_handle,
-                                      const MBEntityHandle *subfacet_conn,
-                                      const MBEntityType subfacet_type,
-                                      MBEntityHandle &high_order_node) const
-{
-  high_order_node = 0;
-
-  MBEntityType parent_type = TYPE_FROM_HANDLE(parent_handle);
-
-    // get the parent's connectivity
-  const MBEntityHandle *parent_conn;
-  int num_parent_vertices;
-  MBErrorCode result = get_connectivity(parent_handle, parent_conn, 
-                                         num_parent_vertices, false);
-  if (result != MB_SUCCESS) return result;
-
-    // find whether this entity has ho nodes
-  int mid_nodes[4];
-  MBCN::HasMidNodes(parent_type, num_parent_vertices, mid_nodes);
-
-    // check whether this entity has mid nodes on this dimension subfacet; 
-    // use dimension-1 because vertices don't have mid nodes
-  if (!mid_nodes[MBCN::Dimension(subfacet_type)]) return MB_SUCCESS;
-
-    // ok, we have mid nodes; now must compute expected index in connectivity array; 
-    // ho nodes stored for edges, faces then entity
-
-    // offset starts with # corner vertices
-  int offset = MBCN::VerticesPerEntity(parent_type);
-  int i;
-
-  for (i = 0; i < MBCN::Dimension(subfacet_type)-1; i++)
-      // for each dimension lower than that of the subfacet we're looking for, 
-      // if this entity has midnodes in that dimension, increment offset by # 
-      // of subfacets of that dimension; use dimension-1 in loop because 
-      // canon numbering table only has 2 positions, for edges and faces;
-    if (mid_nodes[i+1]) offset += MBCN::mConnectivityMap[parent_type][i].num_sub_elements;
-
-    // now add the index of this subfacet; only need to if it's not the highest dimension
-  if (subfacet_type != parent_type) {
-
-      // find indices into parent_conn for each entry in child_conn
-    unsigned subfacet_size = MBCN::VerticesPerEntity(subfacet_type);
-    int subfacet_indices[10];
-    assert(subfacet_size <= sizeof(subfacet_indices)/sizeof(subfacet_indices[0]));
-    for (unsigned i = 0; i < subfacet_size; ++i) {
-      subfacet_indices[i] = std::find( parent_conn,
-        parent_conn + num_parent_vertices, subfacet_conn[i] ) - parent_conn;
-      if (subfacet_indices[i] >= num_parent_vertices) {
-        return MB_FAILURE;
-      }
-    }
-
-    int dum, side_no, temp_offset;
-    int temp_result = 
-      MBCN::SideNumber(  parent_type, subfacet_indices, 
-                         subfacet_size, subfacet_type,
-                         side_no, dum, temp_offset);
-    if(temp_result != 0) return MB_FAILURE;
-
-    offset += side_no;
-  }
-
-    // offset shouldn't be off the end of the connectivity vector
-  if (offset >= num_parent_vertices) return MB_INDEX_OUT_OF_RANGE;
-
-  high_order_node = parent_conn[offset];
-
-  return MB_SUCCESS;
-}
-
-  //! given an entity and a target dimension & side number, get that entity
-MBErrorCode MBCore::side_element(const MBEntityHandle source_entity,
-                                   const int dim, 
-                                   const int side_number,
-                                   MBEntityHandle &target_entity) const
-{
-    // get a handle on the connectivity
-  const MBEntityHandle *verts;
-  int num_verts;
-  MBErrorCode result = get_connectivity(source_entity, verts, num_verts);
-  if (MB_SUCCESS != result) return result;
-
-    // special case for vertices
-  if (dim == 0) {
-    if (side_number < num_verts) {
-      target_entity = verts[side_number];
-      return MB_SUCCESS;
-    }
-    
-    else return MB_INDEX_OUT_OF_RANGE;
-  }
-  
-    // get the vertices comprising the target entity
-  MBRange side_verts, target_ents;
-  const MBEntityType source_type = TYPE_FROM_HANDLE(source_entity);
-    // first get the indices
-  std::vector<int> vertex_indices;
-
-  int temp_result = 
-    MBCN::AdjacentSubEntities(source_type, &side_number, 1, dim, 0, vertex_indices);
-  if (0 != temp_result) return MB_FAILURE;
-    // now get the actual vertices
-  for (unsigned int i = 0; i < vertex_indices.size(); i++)
-    side_verts.insert(verts[vertex_indices[i]]);
-  
-    // now look for an entity of the correct type
-    // use const_cast here 'cuz we're in a const function and we're passing 'false' for
-    // create_if_missing, so we know we won't change anything
-  result = (const_cast<MBCore*>(this))->get_adjacencies(side_verts, dim, false, target_ents);
-  if (MB_SUCCESS != result && MB_MULTIPLE_ENTITIES_FOUND != result) return result;
-  
-  if (!target_ents.empty() &&
-      TYPE_FROM_HANDLE(*(target_ents.begin())) != MBVERTEX &&
-      TYPE_FROM_HANDLE(*(target_ents.begin())) != 
-      MBCN::mConnectivityMap[source_type][dim-1].target_type[side_number])
-    return MB_ENTITY_NOT_FOUND;
-
-  if (!target_ents.empty()) target_entity = *(target_ents.begin());
-  
-  return result;
-}
-
-//-------------------------MBSet Functions---------------------//
-
-MBErrorCode MBCore::create_meshset(const unsigned int options, 
-                                   MBEntityHandle &ms_handle,
-                                   int )
-{
-  return sequence_manager()->create_mesh_set( options, ms_handle );
-}
-
-MBErrorCode MBCore::get_meshset_options( const MBEntityHandle ms_handle, 
-                                          unsigned int& options) const
-{
-  const MBMeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
-  if (!set)
-    return MB_ENTITY_NOT_FOUND;
-  
-  options = set->flags();
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::set_meshset_options( const MBEntityHandle ms_handle, 
-                                         const unsigned int options)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
-  if (!set)
-    return MB_ENTITY_NOT_FOUND;
-  
-  return set->set_flags(options, ms_handle, a_entity_factory());
-}
-
-
-MBErrorCode MBCore::clear_meshset( const MBEntityHandle *ms_handles,
-                                    const int num_meshsets)
-{
-  MBErrorCode result = MB_SUCCESS;
-  for (int i = 0; i < num_meshsets; ++i) {
-    MBMeshSet* set = get_mesh_set( sequence_manager(), ms_handles[i]);
-    if (set)
-      set->clear(ms_handles[i], a_entity_factory());
-    else
-      result = MB_ENTITY_NOT_FOUND;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::clear_meshset(const MBRange &ms_handles)
-{
-  MBErrorCode result = MB_SUCCESS;
-  for (MBRange::iterator i = ms_handles.begin(); i != ms_handles.end(); ++i) {
-    MBMeshSet* set = get_mesh_set( sequence_manager(), *i);
-    if (set)
-      set->clear(*i, a_entity_factory());
-    else
-      result = MB_ENTITY_NOT_FOUND;
-  }
-
-  return result;
-}
-
-MBErrorCode MBCore::subtract_meshset(MBEntityHandle meshset1, const MBEntityHandle meshset2)
-{ 
-  MBMeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
-  MBMeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
-  if (!set1 || !set2)
-    return MB_ENTITY_NOT_FOUND;
-  
-  return set1->subtract( set2, meshset1, a_entity_factory() );
-}
-
-
-MBErrorCode MBCore::intersect_meshset(MBEntityHandle meshset1, const MBEntityHandle meshset2)
-{
-  MBMeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
-  MBMeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
-  if (!set1 || !set2)
-    return MB_ENTITY_NOT_FOUND;
-  
-  return set1->intersect( set2, meshset1, a_entity_factory() );
-}
-
-MBErrorCode MBCore::unite_meshset(MBEntityHandle meshset1, const MBEntityHandle meshset2)
-{
-  MBMeshSet *set1 = get_mesh_set( sequence_manager(), meshset1 );
-  MBMeshSet *set2 = get_mesh_set( sequence_manager(), meshset2 );
-  if (!set1 || !set2)
-    return MB_ENTITY_NOT_FOUND;
-  
-  return set1->unite( set2, meshset1, a_entity_factory() );
-}
-
-MBErrorCode MBCore::add_entities(MBEntityHandle meshset, 
-                                   const MBRange &entities)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->add_entities( entities, meshset, a_entity_factory() );
-  else
-    return MB_ENTITY_NOT_FOUND;
-}
-
-MBErrorCode MBCore::add_entities(MBEntityHandle meshset, 
-                                   const MBEntityHandle *entities,
-                                   const int num_entities)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->add_entities( entities, num_entities, meshset, a_entity_factory() );
-  else
-    return MB_ENTITY_NOT_FOUND;
-}
-
-
-//! remove a range of entities from a meshset
-MBErrorCode MBCore::remove_entities(MBEntityHandle meshset, 
-                                      const MBRange &entities)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->remove_entities( entities, meshset, a_entity_factory() );
-  else
-    return MB_ENTITY_NOT_FOUND;
-}
-
-//! remove a vector of entities from a meshset
-MBErrorCode MBCore::remove_entities( MBEntityHandle meshset, 
-                                       const MBEntityHandle *entities,
-                                       const int num_entities)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->remove_entities( entities, num_entities, meshset, a_entity_factory() );
-  else
-    return MB_ENTITY_NOT_FOUND;
-}
-
-    //! return true if all entities are contained in set
-bool MBCore::contains_entities(MBEntityHandle meshset, 
-                               const MBEntityHandle *entities,
-                               int num_entities, 
-                               const int operation_type)
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->contains_entities(entities, num_entities, operation_type);
-  else
-    return false;
-}
-
-// replace entities in a meshset
-MBErrorCode MBCore::replace_entities(MBEntityHandle meshset, 
-                                     const MBEntityHandle *old_entities,
-                                     const MBEntityHandle *new_entities,
-                                     int num_entities) 
-{
-  MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
-  if (set)
-    return set->replace_entities( meshset, old_entities, new_entities, 
-                                  num_entities, a_entity_factory());
-  else
-    return MB_ENTITY_NOT_FOUND;
-}
-
-MBErrorCode MBCore::get_parent_meshsets(const MBEntityHandle meshset,
-                                          std::vector<MBEntityHandle> &parents,
-                                          const int num_hops) const
-{
-  if (0 == meshset) return MB_SUCCESS;
-
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->get_parents( sequence_manager(), meshset, parents, num_hops );
-}
-
-MBErrorCode MBCore::get_parent_meshsets(const MBEntityHandle meshset,
-                                        MBRange &parents,
-                                          const int num_hops) const
-{
-  if (0 == meshset) return MB_SUCCESS;
-
-  std::vector<MBEntityHandle> parent_vec;
-  MBErrorCode result = get_parent_meshsets(meshset, parent_vec, num_hops);
-  if (MB_SUCCESS != result) return result;
-  std::sort( parent_vec.begin(), parent_vec.end() );
-  std::copy(parent_vec.rbegin(), parent_vec.rend(), mb_range_inserter(parents));
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::get_child_meshsets(const MBEntityHandle meshset,
-                                         std::vector<MBEntityHandle> &children,
-                                         const int num_hops) const
-{
-  if (0 == meshset) return MB_SUCCESS;
-
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->get_children( sequence_manager(), meshset, children, num_hops );
-}
-
-MBErrorCode MBCore::get_child_meshsets(const MBEntityHandle meshset,
-                                        MBRange &children,
-                                          const int num_hops) const
-{
-  if (0 == meshset) return MB_SUCCESS;
-
-  std::vector<MBEntityHandle> child_vec;
-  MBErrorCode result = get_child_meshsets(meshset, child_vec, num_hops);
-  if (MB_SUCCESS != result) return result;
-  std::sort( child_vec.begin(), child_vec.end() );
-  std::copy(child_vec.rbegin(), child_vec.rend(), mb_range_inserter(children));
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::get_contained_meshsets( const MBEntityHandle meshset,
-                                            std::vector<MBEntityHandle> &children,
-                                            const int num_hops) const
-{
-  if (0 == meshset) {
-    return get_entities_by_type( meshset, MBENTITYSET, children );
-  }
-
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->get_contained_sets( sequence_manager(), meshset, children, num_hops );
-}
-
-MBErrorCode MBCore::get_contained_meshsets( const MBEntityHandle meshset,
-                                            MBRange &children,
-                                            const int num_hops) const
-{
-  if (0 == meshset) {
-    return get_entities_by_type( meshset, MBENTITYSET, children );
-  }
-
-  std::vector<MBEntityHandle> child_vec;
-  MBErrorCode result = get_contained_meshsets(meshset, child_vec, num_hops);
-  if (MB_SUCCESS != result) return result;
-  std::sort( child_vec.begin(), child_vec.end() );
-  std::copy(child_vec.rbegin(), child_vec.rend(), mb_range_inserter(children));
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::num_parent_meshsets(const MBEntityHandle meshset, int* number,
-                                        const int num_hops) const
-{
-  if (0 == meshset) {
-    *number = 0;
-    return MB_SUCCESS;
-  }
-
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->num_parents( sequence_manager(), meshset, *number, num_hops );
-}
-
-MBErrorCode MBCore::num_child_meshsets(const MBEntityHandle meshset, int* number,
-                                       const int num_hops) const
-{
-  if (0 == meshset) {
-    *number = 0;
-    return MB_SUCCESS;
-  }
-  
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->num_children( sequence_manager(), meshset, *number, num_hops );
-}
-
-MBErrorCode MBCore::num_contained_meshsets(const MBEntityHandle meshset, int* number,
-                                       const int num_hops) const
-{
-  if (0 == meshset) {
-    return get_number_entities_by_type( 0, MBENTITYSET, *number );
-  }
-  
-  const EntitySequence *seq;
-  MBErrorCode rval = sequence_manager()->find( meshset, seq );
-  if (MB_SUCCESS != rval)
-    return MB_ENTITY_NOT_FOUND;
-  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-
-  return mseq->num_contained_sets( sequence_manager(), meshset, *number, num_hops );
-}
-
-
-MBErrorCode MBCore::add_parent_meshset( MBEntityHandle meshset, 
-                                        const MBEntityHandle parent_meshset)
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  MBMeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent_meshset );
-  if (!set_ptr || !parent_ptr)
-    return MB_ENTITY_NOT_FOUND;
-
-  set_ptr->add_parent( parent_meshset );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::add_parent_meshsets( MBEntityHandle meshset, 
-                                         const MBEntityHandle* parents,
-                                         int count )
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  if (!set_ptr)
-    return MB_ENTITY_NOT_FOUND;
-
-  for (int i = 0; i < count; ++i)
-    if (!get_mesh_set( sequence_manager(), parents[i] ))
-      return MB_ENTITY_NOT_FOUND;
-    
-  for (int i = 0; i < count; ++i)
-    set_ptr->add_parent( parents[i] );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::add_child_meshset(MBEntityHandle meshset, 
-                                        const MBEntityHandle child_meshset)
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  MBMeshSet* child_ptr = get_mesh_set( sequence_manager(), child_meshset );
-  if (!set_ptr || !child_ptr)
-    return MB_ENTITY_NOT_FOUND;
-
-  set_ptr->add_child( child_meshset );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::add_child_meshsets( MBEntityHandle meshset, 
-                                        const MBEntityHandle* children,
-                                        int count )
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  if (!set_ptr)
-    return MB_ENTITY_NOT_FOUND;
-
-  for (int i = 0; i < count; ++i)
-    if (!get_mesh_set( sequence_manager(), children[i] ))
-      return MB_ENTITY_NOT_FOUND;
-    
-  for (int i = 0; i < count; ++i)
-    set_ptr->add_child( children[i] );
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBCore::add_parent_child(MBEntityHandle parent, 
-                                       MBEntityHandle child)
-{
-  MBMeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent );
-  MBMeshSet* child_ptr = get_mesh_set( sequence_manager(), child );
-  if (!parent_ptr || !child_ptr)
-    return MB_ENTITY_NOT_FOUND;
-  
-  parent_ptr->add_child( child );
-  child_ptr->add_parent( parent );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::remove_parent_child(MBEntityHandle parent, 
-                                          MBEntityHandle child)
-{
-  MBMeshSet* parent_ptr = get_mesh_set( sequence_manager(), parent );
-  MBMeshSet* child_ptr = get_mesh_set( sequence_manager(), child );
-  if (!parent_ptr || !child_ptr)
-    return MB_ENTITY_NOT_FOUND;
-  
-  parent_ptr->remove_child( child );
-  child_ptr->remove_parent( parent );
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBCore::remove_parent_meshset(MBEntityHandle meshset, 
-                                            const MBEntityHandle parent_meshset)
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  if (!set_ptr)
-    return MB_ENTITY_NOT_FOUND;
-  set_ptr->remove_parent( parent_meshset );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCore::remove_child_meshset(MBEntityHandle meshset, 
-                                           const MBEntityHandle child_meshset)
-{
-  MBMeshSet* set_ptr = get_mesh_set( sequence_manager(), meshset );
-  if (!set_ptr)
-    return MB_ENTITY_NOT_FOUND;
-  set_ptr->remove_child( child_meshset );
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBCore::get_last_error(std::string& info) const
-{
-  return mError->get_last_error(info);
-}
-
-std::string MBCore::get_error_string(const MBErrorCode code) const 
-{
-  static const char* errorStrings[MB_FAILURE+1] = {
-    "MB_SUCCESS",
-    "MB_INDEX_OUT_OF_RANGE",
-    "MB_TYPE_OUT_OF_RANGE",
-    "MB_MEMORY_ALLOCATION_FAILED",
-    "MB_ENTITY_NOT_FOUND",
-    "MB_MULTIPLE_ENTITIES_FOUND",
-    "MB_TAG_NOT_FOUND",
-    "MB_FILE_DOES_NOT_EXIST",
-    "MB_FILE_WRITE_ERROR",
-    "MB_NOT_IMPLEMENTED",
-    "MB_ALREADY_ALLOCATED",
-    "MB_VARIABLE_DATA_LENGTH",
-    "MB_INVALID_SIZE",
-    "MB_UNSUPPORTED_OPERATION",
-    "MB_UNHANDLED_OPTION",
-    "MB_FAILURE",
-  };
-
-  return errorStrings[code];
-}
-
-void MBCore::print(const MBEntityHandle ms_handle, const char *prefix,
-                   bool first_call) const
-{
-    // get the entities
-  MBRange entities;
-  
-  if (0 != ms_handle) {
-    get_entities_by_handle( ms_handle, entities );
-    if (!first_call)
-      std::cout << prefix << "MBENTITYSET " << ID_FROM_HANDLE(ms_handle) 
-                << std::endl;
-  }
-  else {
-    get_entities_by_dimension(0, 3, entities);
-    if (entities.empty()) get_entities_by_dimension(0, 2, entities);
-    if (entities.empty()) get_entities_by_dimension(0, 1, entities);
-    get_entities_by_dimension(0, 0, entities);
-    get_entities_by_type(0, MBENTITYSET, entities);
-    std::cout << prefix << "--MB: " << std::endl;
-  }
-    
-  std::string indent_prefix = prefix;
-  indent_prefix += "  ";
-  entities.print(indent_prefix.c_str());
-
-  if (!first_call || !ms_handle) return;
-  
-    // print parent/children
-  MBRange temp;
-  this->get_parent_meshsets(ms_handle, temp);
-  std::cout << "  Parent sets: ";
-  if (temp.empty()) std::cout << "(none)" << std::endl;
-  else {
-    for (MBRange::iterator rit = temp.begin(); rit != temp.end(); rit++) {
-      if (rit != temp.begin()) std::cout << ", ";
-      std::cout << ID_FROM_HANDLE(*rit);
-    }
-    std::cout << std::endl;
-  }
-
-  temp.clear();
-  this->get_child_meshsets(ms_handle, temp);
-  std::cout << "  Child sets: ";
-  if (temp.empty()) std::cout << "(none)" << std::endl;
-  else {
-    for (MBRange::iterator rit = temp.begin(); rit != temp.end(); rit++) {
-      if (rit != temp.begin()) std::cout << ", ";
-      std::cout << ID_FROM_HANDLE(*rit);
-    }
-    std::cout << std::endl;
-  }
-
-    // print all sparse tags
-  std::vector<MBTag> set_tags;
-  MBErrorCode result = this->tag_get_tags_on_entity(ms_handle, set_tags);
-  std::cout << indent_prefix << "Sparse tags:" << std::endl;
-  indent_prefix += "  ";
-  
-  for (std::vector<MBTag>::iterator vit = set_tags.begin(); 
-       vit != set_tags.end(); vit++) {
-    MBTagType this_type;
-    result = this->tag_get_type(*vit, this_type);
-    if (MB_SUCCESS != result || MB_TAG_SPARSE != this_type) continue;
-    MBDataType this_data_type;
-    result = this->tag_get_data_type(*vit, this_data_type);
-    int this_size;
-    result = this->tag_get_size(*vit, this_size);
-    if (MB_SUCCESS != result || (int) sizeof(double) < this_size) continue;
-      // use double since this is largest single-valued tag
-    double dbl_val;
-    int int_val;
-    MBEntityHandle hdl_val;
-    std::string tag_name;
-    result = this->tag_get_name(*vit, tag_name);
-    if (MB_SUCCESS != result) continue;
-    switch (this_data_type) {
-      case MB_TYPE_INTEGER:
-        result = this->tag_get_data(*vit, &ms_handle, 1, &int_val);
-        if (MB_SUCCESS != result) continue;
-        std::cout << indent_prefix << tag_name << " = " << int_val << std::endl;
-        break;
-      case MB_TYPE_DOUBLE:
-        result = this->tag_get_data(*vit, &ms_handle, 1, &dbl_val);
-        if (MB_SUCCESS != result) continue;
-        std::cout << indent_prefix << tag_name << " = " << dbl_val << std::endl;
-        break;
-      case MB_TYPE_HANDLE:
-        result = this->tag_get_data(*vit, &ms_handle, 1, &hdl_val);
-        if (MB_SUCCESS != result) continue;
-        std::cout << indent_prefix << tag_name << " = " << hdl_val << std::endl;
-        break;
-      case MB_TYPE_BIT:
-      case MB_TYPE_OPAQUE:
-        break;
-    }
-  }
-}
-
-MBErrorCode MBCore::check_adjacencies() 
-{
-    // run through all entities, checking adjacencies and reverse-evaluating them
-  MBRange all_ents;
-  MBErrorCode result = get_entities_by_handle(0, all_ents);
-  if (MB_SUCCESS != result) return result;
-  
-  MBErrorCode tmp_result;
-  for (MBRange::iterator rit = all_ents.begin(); rit != all_ents.end(); rit++) {
-    tmp_result = check_adjacencies(&(*rit), 1);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  
-  return result;
-}
-
-MBErrorCode MBCore::check_adjacencies(const MBEntityHandle *ents, int num_ents) 
-{
-
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  std::ostringstream oss;
-  
-  for (int i = 0; i < num_ents; i++) {
-    MBEntityHandle this_ent = ents[i];
-    std::ostringstream ent_str;
-    ent_str << MBCN::EntityTypeName(TYPE_FROM_HANDLE(this_ent)) << " "
-            << ID_FROM_HANDLE(this_ent) << ": ";
-    int this_dim = dimension_from_handle(this_ent);
-
-    if (!is_valid(this_ent)) {
-      std::cerr << ent_str.str()
-                << "Not a valid entity." << std::endl;
-      result = MB_FAILURE;
-    }
-
-    else {
-      if (TYPE_FROM_HANDLE(this_ent) == MBENTITYSET) continue;
-      
-        // get adjacencies for this entity
-      MBRange adjs;
-      for (int dim = 0; dim <= 3; dim++) {
-        if (dim == this_dim) continue;
-        tmp_result = get_adjacencies(&this_ent, 1, dim, false, adjs, MBInterface::UNION);
-        if (MB_SUCCESS != tmp_result) {
-          oss << ent_str.str()
-              << "Failed to get adjacencies for dimension " << dim << "." << std::endl;
-          result = tmp_result;
-        }
-      }
-      if (!oss.str().empty()) {
-        std::cerr << oss.str();
-        oss.str("");
-      }
-
-        // now check and reverse-evaluate them
-      for (MBRange::iterator rit = adjs.begin(); rit != adjs.end(); rit++) {
-        EntitySequence* seq = 0;
-        tmp_result = sequence_manager()->find(*rit, seq);
-        if(seq == 0 || tmp_result != MB_SUCCESS) {
-          oss << ent_str.str() << 
-            "Adjacent entity " << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
-              << ID_FROM_HANDLE(*rit) << " is invalid." << std::endl;
-          result = tmp_result;
-        }
-        else {
-          MBRange rev_adjs;
-          tmp_result = get_adjacencies(&(*rit), 1, this_dim, false, rev_adjs);
-          if (MB_SUCCESS != tmp_result) {
-            oss << ent_str.str() 
-                << "Failed to get reverse adjacency from " 
-                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
-                << ID_FROM_HANDLE(*rit);
-            if (MB_MULTIPLE_ENTITIES_FOUND == tmp_result)
-              oss << " (MULTIPLE)" << std::endl;
-            else oss << " (" << tmp_result << ")" << std::endl;
-            result = tmp_result;
-          }
-          else if (rev_adjs.find(this_ent) == rev_adjs.end()) {
-            oss << ent_str.str() 
-                << "Failed to find adjacency to this entity from " 
-                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*rit)) << " "
-                << ID_FROM_HANDLE(*rit) << "." << std::endl;
-            result = tmp_result;
-          }
-        }
-        if (!oss.str().empty()) {
-          std::cerr << oss.str();
-          oss.str("");
-        }
-      }
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-bool MBCore::is_valid(const MBEntityHandle this_ent) const
-{
-  const EntitySequence* seq = 0;
-  MBErrorCode result = sequence_manager()->find(this_ent, seq);
-  return seq != 0 && result == MB_SUCCESS;
-}
-
-static unsigned long get_num_entities_with_tag( TagServer* ts, 
-                                                MBTag tag,
-                                                const MBRange& entities )
-{
-  if (entities.empty())
-    return 0;
-  
-  int tmp;
-  unsigned long total = 0;
-  MBEntityType t = TYPE_FROM_HANDLE( entities.front() );
-  MBEntityType e = TYPE_FROM_HANDLE( entities.back() );
-  ++e;
-  for (; t != e; ++t) {
-    tmp = 0;
-    if (MB_SUCCESS == ts->get_number_entities( entities, tag, t, tmp ))
-      total += tmp;
-  }
-  
-  return total;
-}
-
-void MBCore::estimated_memory_use_internal( const MBRange* ents,
-                                  unsigned long* total_storage,
-                                  unsigned long* total_amortized_storage,
-                                  unsigned long* entity_storage,
-                                  unsigned long* amortized_entity_storage,
-                                  unsigned long* adjacency_storage,
-                                  unsigned long* amortized_adjacency_storage,
-                                  const MBTag* tag_array,
-                                  unsigned num_tags,
-                                  unsigned long* tag_storage,
-                                  unsigned long* amortized_tag_storage )
-{
-    // Figure out which values we need to calulate
-  unsigned long i_entity_storage,    ia_entity_storage, 
-                i_adjacency_storage, ia_adjacency_storage, 
-                i_tag_storage,       ia_tag_storage;
-  unsigned long *total_tag_storage = 0, 
-                *amortized_total_tag_storage =0;
-  if (!tag_array) {
-    total_tag_storage = tag_storage;
-    amortized_total_tag_storage = amortized_tag_storage;
-  }
-  if (total_storage || total_amortized_storage) {
-    if (!entity_storage)
-      entity_storage = &i_entity_storage;
-    if (!amortized_entity_storage)
-      amortized_entity_storage = &ia_entity_storage;
-    if (!adjacency_storage)
-      adjacency_storage = &i_adjacency_storage;
-    if (!amortized_adjacency_storage)
-      amortized_adjacency_storage = &ia_adjacency_storage;
-  }
-  else {
-    if (entity_storage || amortized_entity_storage) {
-      if (!amortized_entity_storage)
-        amortized_entity_storage = &ia_entity_storage;
-      else if (!entity_storage)
-        entity_storage = &i_entity_storage;
-    }
-    if (adjacency_storage || amortized_adjacency_storage) {
-      if (!amortized_adjacency_storage)
-        amortized_adjacency_storage = &ia_adjacency_storage;
-      else if (!adjacency_storage)
-        adjacency_storage = &i_adjacency_storage;
-    }
-  }
-  if (!total_tag_storage && total_storage)
-    total_tag_storage = &i_tag_storage;
-  if (!amortized_total_tag_storage && total_amortized_storage)
-    amortized_total_tag_storage = &ia_tag_storage;
-    
-    // get entity storage
-  if (amortized_entity_storage) {
-    if (ents)
-      sequenceManager->get_memory_use( *ents, *entity_storage, *amortized_entity_storage );
-    else
-      sequenceManager->get_memory_use( *entity_storage, *amortized_entity_storage );
-  }
-  
-    // get adjacency storage
-  if (amortized_adjacency_storage) {
-    if (ents)
-      aEntityFactory->get_memory_use( *ents, *adjacency_storage, *amortized_adjacency_storage );
-    else
-      aEntityFactory->get_memory_use( *adjacency_storage, *amortized_adjacency_storage );
-  }
-  
-    // get storage for requested list of tags
-  if (tag_array) {
-    for (unsigned i = 0; i < num_tags; ++i) {
-      unsigned long total, per_ent, count;
-      tagServer->get_memory_use( tag_array[i], total, per_ent );
-      
-      if (ents) {
-        count = get_num_entities_with_tag( tagServer, tag_array[i], *ents );
-        if (tag_storage)
-          tag_storage[i] = count * per_ent;
-        if (amortized_tag_storage) {
-          tagServer->get_number_entities( tag_array[i], per_ent );
-          if (per_ent)
-            amortized_tag_storage[i] = (unsigned long)((double)total * count / per_ent);
-        }
-      }
-      else {
-        if (tag_storage) {
-          tagServer->get_number_entities( tag_array[i], count );
-          tag_storage[i] = count * per_ent;
-        }
-        if (amortized_tag_storage)
-          amortized_tag_storage[i] = total;
-      }
-    }
-  }
-  
-    // get storage for all tags
-  if (total_tag_storage || amortized_total_tag_storage) {
-    if (amortized_total_tag_storage)
-      *amortized_total_tag_storage = 0;
-    if (total_tag_storage)
-      *total_tag_storage =0;
-      
-    std::vector<MBTag> tags;
-    tag_get_tags( tags );
-    for (unsigned i = 0; i < tags.size(); ++i) {
-      unsigned long total, per_ent, count;
-      tagServer->get_memory_use( tags[i], total, per_ent );
-      
-      if (ents) {
-        count = get_num_entities_with_tag( tagServer, tags[i], *ents );
-        if (total_tag_storage)
-          *total_tag_storage += count * per_ent;
-        if (amortized_total_tag_storage) {
-          tagServer->get_number_entities( tags[i], per_ent );
-          if (per_ent)
-            *amortized_total_tag_storage += (unsigned long)((double)total * count / per_ent);
-        }
-      }
-      else {
-        if (total_tag_storage) {
-          tagServer->get_number_entities( tags[i], count );
-          *total_tag_storage += count * per_ent;
-        }
-        if (amortized_total_tag_storage)
-          *amortized_total_tag_storage += total;
-      }
-    }
-  }
-  
-    // calculate totals
-  if (total_storage)
-    *total_storage = *entity_storage + *adjacency_storage + *total_tag_storage;
-  
-  if (total_amortized_storage)
-    *total_amortized_storage = *amortized_entity_storage 
-                             + *amortized_adjacency_storage
-                             + *amortized_total_tag_storage;
-}
-
-
-void  MBCore::estimated_memory_use( const MBEntityHandle* ent_array,
-                                    unsigned long num_ents,
-                                    unsigned long* total_storage,
-                                    unsigned long* total_amortized_storage,
-                                    unsigned long* entity_storage,
-                                    unsigned long* amortized_entity_storage,
-                                    unsigned long* adjacency_storage,
-                                    unsigned long* amortized_adjacency_storage,
-                                    const MBTag* tag_array,
-                                    unsigned num_tags,
-                                    unsigned long* tag_storage,
-                                    unsigned long* amortized_tag_storage ) 
-{
-  MBRange range;
-  
-    // If non-empty entity list, call range version of function
-  if (ent_array) {
-    if (num_ents > 20) {
-      std::vector<MBEntityHandle> list(num_ents);
-      std::copy(ent_array, ent_array+num_ents, list.begin());
-      std::sort( list.begin(), list.end() );
-      MBRange::iterator j = range.begin();
-      for (std::vector<MBEntityHandle>::reverse_iterator i = list.rbegin(); i != list.rend(); ++i)
-        j = range.insert( j, *i, *i );
-    }
-    else {
-      std::copy( ent_array, ent_array + num_ents, mb_range_inserter(range) );
-    }
-  }
-  
-  estimated_memory_use_internal( ent_array ? &range : 0,
-                         total_storage,     total_amortized_storage,
-                         entity_storage,    amortized_entity_storage,
-                         adjacency_storage, amortized_adjacency_storage,
-                         tag_array,         num_tags,
-                         tag_storage,       amortized_tag_storage );
-}
-
-void MBCore::estimated_memory_use( const MBRange& ents,
-                                   unsigned long* total_storage,
-                                   unsigned long* total_amortized_storage,
-                                   unsigned long* entity_storage,
-                                   unsigned long* amortized_entity_storage,
-                                   unsigned long* adjacency_storage,
-                                   unsigned long* amortized_adjacency_storage,
-                                   const MBTag* tag_array,
-                                   unsigned num_tags,
-                                   unsigned long* tag_storage,
-                                   unsigned long* amortized_tag_storage )
-{
-  estimated_memory_use_internal( &ents,
-                         total_storage,     total_amortized_storage,
-                         entity_storage,    amortized_entity_storage,
-                         adjacency_storage, amortized_adjacency_storage,
-                         tag_array,         num_tags,
-                         tag_storage,       amortized_tag_storage );
-}
-
-void MBCore::print_database() const
-{
-  MBErrorCode rval;
-  TypeSequenceManager::const_iterator i;
-  const TypeSequenceManager& verts = sequence_manager()->entity_map(MBVERTEX);
-  if (!verts.empty())
-    printf("  Vertex ID  X        Y        Z        Adjacencies   \n"     
-           "  ---------- -------- -------- -------- -----------...\n");
-  const MBEntityHandle* adj;
-  int nadj;
-  for (i = verts.begin(); i != verts.end(); ++i) {
-    const VertexSequence* seq = static_cast<const VertexSequence* >(*i);
-    printf("(Sequence [%d,%d] in SequenceData [%d,%d])\n",
-      (int)ID_FROM_HANDLE(seq->start_handle()),
-      (int)ID_FROM_HANDLE(seq->end_handle()),
-      (int)ID_FROM_HANDLE(seq->data()->start_handle()),
-      (int)ID_FROM_HANDLE(seq->data()->end_handle()));
-    
-    double c[3];
-    for (MBEntityHandle h = seq->start_handle(); h <= seq->end_handle(); ++h) {
-      rval = seq->get_coordinates( h, c );
-      if (MB_SUCCESS == rval)
-        printf("  %10d %8g %8g %8g", (int)ID_FROM_HANDLE(h), c[0], c[1], c[2] );
-      else
-        printf("  %10d <       ERROR %4d       >", (int)ID_FROM_HANDLE(h), (int)rval );
- 
-      rval = a_entity_factory()->get_adjacencies( h, adj, nadj );
-      if (MB_SUCCESS != rval) {
-        printf(" <ERROR %d>\n", (int)rval );
-        continue;
-      }
-      MBEntityType pt = MBMAXTYPE;
-      for (int j = 0; j < nadj; ++j) {
-        if (TYPE_FROM_HANDLE(adj[j]) != pt) {
-          pt = TYPE_FROM_HANDLE(adj[j]);
-          printf("  %s", pt >= MBMAXTYPE ? "INVALID TYPE" : MBCN::EntityTypeName(pt) );
-        }
-        printf(" %d", (int)ID_FROM_HANDLE(adj[j]));
-      }
-      printf("\n");
-    }
-  }
-  
-  for (MBEntityType t = MBEDGE; t < MBENTITYSET; ++t) {
-    const TypeSequenceManager& elems = sequence_manager()->entity_map(t);
-    if (elems.empty())
-      continue;
-    
-    int clen = 0;
-    for (i = elems.begin(); i != elems.end(); ++i) {
-      int n = static_cast<const ElementSequence*>(*i)->nodes_per_element();
-      if (n > clen)
-        clen = n;
-    }
-
-    clen *= 5;
-    if (clen < (int)strlen("Connectivity"))
-      clen = strlen("Connectivity");
-    std::vector<char> dashes( clen, '-' );
-    dashes.push_back( '\0' );
-    printf( "  %7s ID %-*s Adjacencies\n", MBCN::EntityTypeName(t), clen, "Connectivity" );
-    printf( "  ---------- %s -----------...\n", &dashes[0] );
-    
-    std::vector<MBEntityHandle> storage;
-    const MBEntityHandle* conn;
-    int nconn;
-    for (i = elems.begin(); i != elems.end(); ++i) {
-      const ElementSequence* seq = static_cast<const ElementSequence*>(*i);
-      printf("(Sequence [%d,%d] in SequenceData [%d,%d])\n",
-        (int)ID_FROM_HANDLE(seq->start_handle()),
-        (int)ID_FROM_HANDLE(seq->end_handle()),
-        (int)ID_FROM_HANDLE(seq->data()->start_handle()),
-        (int)ID_FROM_HANDLE(seq->data()->end_handle()));
-      
-      for (MBEntityHandle h = seq->start_handle(); h <= seq->end_handle(); ++h) {
-        printf( "  %10d", (int)ID_FROM_HANDLE(h) );
-        rval = get_connectivity( h, conn, nconn, false, &storage );
-        if (MB_SUCCESS != rval) 
-          printf( "  <ERROR %2d>%*s", (int)rval, clen-10, "" );
-        else {
-          for (int j = 0; j < nconn; ++j)
-            printf(" %4d", (int)ID_FROM_HANDLE(conn[j]));
-          printf("%*s", clen - 5*nconn, "" );
-        }
-        
-        rval = a_entity_factory()->get_adjacencies( h, adj, nadj );
-        if (MB_SUCCESS != rval) {
-          printf(" <ERROR %d>\n", (int)rval );
-          continue;
-        }
-        MBEntityType pt = MBMAXTYPE;
-        for (int j = 0; j < nadj; ++j) {
-          if (TYPE_FROM_HANDLE(adj[j]) != pt) {
-            pt = TYPE_FROM_HANDLE(adj[j]);
-            printf("  %s", pt >= MBMAXTYPE ? "INVALID TYPE" : MBCN::EntityTypeName(pt) );
-          }
-          printf(" %d", (int)ID_FROM_HANDLE(adj[j]));
-        }
-        printf("\n");
-      }
-    }
-  }
-}
-
-MBErrorCode MBCore::create_scd_sequence(const HomCoord & coord_min,
-					const HomCoord &  coord_max,
-					MBEntityType  type,
-					MBEntityID  start_id_hint,
-					MBEntityHandle &  first_handle_out,
-					EntitySequence *&  sequence_out )
-{
-  return sequence_manager()->create_scd_sequence(coord_min, coord_max, type,
-						 start_id_hint, 
-						 first_handle_out,
-						 sequence_out);
-}
-
-MBErrorCode MBCore::add_vsequence(EntitySequence *    vert_seq,
-				  EntitySequence *  elem_seq,
-				  const HomCoord &  p1,
-				  const HomCoord &  q1,
-				  const HomCoord &  p2,
-				  const HomCoord &  q2,
-				  const HomCoord &  p3,
-				  const HomCoord &  q3,
-				  bool  bb_input,
-				  const HomCoord *  bb_min,
-				  const HomCoord *  bb_max )
-{
-  return sequence_manager()->add_vsequence(vert_seq, elem_seq, 
-					   p1, q1, p2, q2, p3, q3,
-					   bb_input, bb_min, bb_max);
-
-}

Copied: MOAB/trunk/src/MBEntityType.h (from rev 3583, MOAB/trunk/src/moab/MBEntityType.h)
===================================================================
--- MOAB/trunk/src/MBEntityType.h	                        (rev 0)
+++ MOAB/trunk/src/MBEntityType.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,86 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifndef MB_ENTITY_TYPE_H
+#define MB_ENTITY_TYPE_H
+
+#ifndef MOAB_ENTITY_TYPE_NAME
+#  define MOAB_ENTITY_TYPE_NAME MBEntityType
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! Entity types defined in MOAB and MBCN
+ *  The ordering here must ensure that all element types are 
+ *  grouped together and all elements of similar dimension are
+ *  grouped together.
+ */
+typedef enum 
+{
+  MBVERTEX = 0, /**< Mesh Vertex AKA node */
+  MBEDGE,       /**< Mesh Edge */
+  MBTRI,        /**< Triangular element (including shells) */
+  MBQUAD,       /**< Quadrilateral element (including shells) */
+  MBPOLYGON,    /**< Polygon */
+  MBTET,        /**< Tetrahedral element */
+  MBPYRAMID,    /**< Pyramid element (where are the face ids for this defined?) */
+  MBPRISM,      /**< Wedge element (Exodus has one, Cubit doesn't. Does Mesh need it?) */
+  MBKNIFE,      /**< Knife element */
+  MBHEX,        /**< Hexahedral element */
+  MBPOLYHEDRON, /**< Polyhedron */
+  MBENTITYSET,    /**< MeshSet */
+  MBMAXTYPE  /**< Just a place keeper - must be the # of entities, for array */
+    /**< dimensioning purposes  */
+} MOAB_ENTITY_TYPE_NAME;
+
+#ifdef __cplusplus
+} /* extern "C" */
+
+
+/** prefix increment operator for MBEntityType */
+inline MOAB_ENTITY_TYPE_NAME & operator++(MOAB_ENTITY_TYPE_NAME &type)
+{
+  return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type+1);
+}
+
+/** postfix increment operator for MBEntityType */
+inline MOAB_ENTITY_TYPE_NAME operator++(MOAB_ENTITY_TYPE_NAME &type, int)
+{
+  MOAB_ENTITY_TYPE_NAME oldval = type;
+  ++type;
+  return oldval;
+}
+
+/** prefix increment operator for MBEntityType */
+inline MOAB_ENTITY_TYPE_NAME & operator--(MOAB_ENTITY_TYPE_NAME &type)
+{
+  return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type-1);
+}
+
+/** postfix increment operator for MBEntityType */
+inline MOAB_ENTITY_TYPE_NAME operator--(MOAB_ENTITY_TYPE_NAME &type, int)
+{
+  MOAB_ENTITY_TYPE_NAME oldval = type;
+  --type;
+  return oldval;
+}
+
+#endif
+
+#undef MOAB_ENTITY_TYPE_NAME
+
+#endif

Deleted: MOAB/trunk/src/MBFactory.cpp
===================================================================
--- MOAB/trunk/src/MBFactory.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBFactory.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,163 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifdef WIN32
-#ifdef _DEBUG
-// turn off warnings that say they debugging identifier has been truncated
-// this warning comes up when using some STL containers
-#pragma warning(disable : 4786)
-#endif
-#endif
-
-#include "MBCore.hpp"
-
-#ifdef XPCOM_MB
-
-#include "nsIGenericFactory.h"
-
-// define constructor function for MBCore
-NS_GENERIC_FACTORY_CONSTRUCTOR(MBCore)
-
-// support for nsIClassInfo
-NS_DECL_CLASSINFO(MBCore)
-
-static const nsModuleComponentInfo components[] =
-{
-  { "MB Interface", MBCORE_CID, MBCORE_CONTRACTID, MBCoreConstructor,
-    NULL /* NULL if you dont need one */,
-    NULL /* NULL if you dont need one */,
-    NULL /* no factory destructor */,
-    NS_CI_INTERFACE_GETTER_NAME(MBCore),
-    NULL /* no language helper */,
-    &NS_CLASSINFO_NAME(MBCore),
-    0
-  }
-};
-
-// implement NSGetModule()
-NS_IMPL_NSGETMODULE(MBCore, components);
-
-#endif
-
-
-
-#ifndef WIN32
-  #define MB_EXPORT extern "C"
-#else
-  #define MB_EXPORT extern "C" __declspec(dllexport)
-#endif
-
-#include <list>
-
-class MBComponentFactory : public MBUnknownInterface
-{
-public:
-   MBComponentFactory(){};
-   virtual ~MBComponentFactory(){};
-   // returns the interface requested from an object
-   virtual int QueryInterface( const MBuuid&,
-         MBUnknownInterface** );
-   // keep track of the objects this component factory creates
-   static std::list<MBUnknownInterface*> objects_in_use;
-};
-
-// the list that keeps track of all the interfaces generated by this server
-std::list<MBUnknownInterface*> MBComponentFactory::objects_in_use;
-
-
-// this QueryInterface function is supposed to create an instance of the object
-// that contains the interface requested
-//
-// note: the object is not the same as the interface, therefore
-// we ask the object for the interface that was requested
-//
-
-int MBComponentFactory::QueryInterface( const MBuuid& uuid, MBUnknownInterface** iface )
-{
-   // this is an unknown interface that was requested
-   // if wanted, we could provide a default interface
-   // if IDD_MBUnknown is specified
-   if(uuid == IDD_MBUnknown)
-      return 0;
-   // IDD_MBVerde interface was requested
-   // create an MBVerde object and have it return the interface
-   // requested
-   else if(uuid == IDD_MBCore)
-   {
-      MBCore* mdb = new MBCore;
-      // if the object does not contain the interface requested, delete the object
-      if(!mdb->QueryInterface(uuid, iface))
-      {
-         delete mdb;
-         return 0;
-      }
-      return 1;
-   }
-   else
-      return 0;
-
-}
-
-// returns the interface version
-MB_EXPORT const char* Version()
-{
-   return MB_INTERFACE_VERSION;
-}
-
-
-// Initialize function is accessed by the MBClient when asking for interfaces
-MB_EXPORT void GetInterface(MBuuid& interface_requested, MBUnknownInterface** iface)
-{
-   // create an instance of our component factory
-   MBComponentFactory server;
-   // ask the component factory to give us the interface we want
-   server.QueryInterface(interface_requested, iface);
-   // if the interface existed, put it on our list
-   if(iface && *iface)
-      MBComponentFactory::objects_in_use.push_front(*iface);
-}
-
-
-// DeInitialize function is accessed by the MBClient when disconnecting from this library
-// this will clean everything up prior to a disconnection
-// from this library
-MB_EXPORT void DeInitialize()
-{
-   // delete all instances of objects
-   while(MBComponentFactory::objects_in_use.size())
-   {
-      MBUnknownInterface* iface =
-         MBComponentFactory::objects_in_use.front();
-      MBComponentFactory::objects_in_use.pop_front();
-      if(iface)
-         delete iface;
-   }
-}
-
-// ReleaseInterface function is accessed by the MBClient when deleting an interface
-
-// ReleaseInterface will delete this interface
-MB_EXPORT void ReleaseInterface(MBUnknownInterface* iface)
-{
-   if(!iface)
-      return;
-   // remove this object from our list and delete it
-   MBComponentFactory::objects_in_use.remove(iface);
-   delete iface;
-}
-
-
-
-

Deleted: MOAB/trunk/src/MBGeomUtil.cpp
===================================================================
--- MOAB/trunk/src/MBGeomUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBGeomUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1299 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBGeometry.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-27
- */
-
-#include "MBCartVect.hpp"
-#include "MBCN.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBMatrix3.hpp"
-#include <cmath>
-#include <algorithm>
-#include <assert.h>
-#include <iostream>
-#include <limits>
-
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#  include <float.h>
-#  define finite(A) _finite(A)
-#endif
-
-namespace MBGeomUtil {
-
-static inline 
-void min_max_3( double a, double b, double c, double& min, double& max )
-{
-  if (a < b) {
-    if (a < c) {
-      min = a;
-      max = b > c ? b : c;
-    }
-    else {
-      min = c;
-      max = b;
-    }
-  }
-  else if (b < c) {
-    min = b;
-    max = a > c ? a : c;
-  }
-  else {
-    min = c;
-    max = a;
-  }
-}
-
-static inline
-double dot_abs( const MBCartVect& u, const MBCartVect& v )
-  { return fabs(u[0]*v[0]) + fabs(u[1]*v[1]) + fabs(u[2]*v[2]); }
-
-bool segment_box_intersect( MBCartVect box_min,
-                            MBCartVect box_max,
-                            const MBCartVect& seg_pt,
-                            const MBCartVect& seg_unit_dir,
-                            double& seg_start, double& seg_end )
-{
-    // translate so that seg_pt is at origin
-  box_min -= seg_pt;
-  box_max -= seg_pt;
-  
-  for (unsigned i = 0; i < 3; ++i) {  // X, Y, and Z slabs
-
-      // intersect line with slab planes
-    const double t_min = box_min[i] / seg_unit_dir[i];
-    const double t_max = box_max[i] / seg_unit_dir[i];
-    
-      // check if line is parallel to planes
-    if (!finite(t_min)) {
-      if (box_min[i] > 0.0 || box_max[i] < 0.0)
-        return false; 
-      continue;
-    }
-
-    if (seg_unit_dir[i] < 0) {
-      if (t_min < seg_end) 
-        seg_end = t_min;
-      if (t_max > seg_start)
-        seg_start = t_max;
-    }
-    else { // seg_unit_dir[i] > 0
-      if (t_min > seg_start)
-        seg_start = t_min; 
-      if (t_max < seg_end)
-        seg_end = t_max;
-    }
-  }
-
-  return seg_start <= seg_end;
-}
-
-
-/* Impelementation copied from cgmMC ray_tri_contact (overlap.C) */
-bool ray_tri_intersect( const MBCartVect vertices[3],
-                        const MBCartVect& b,
-                        const MBCartVect& v,
-                        double /*tolerance*/,
-                        double& t_out,
-                        const double* ray_length)
-{
-  const MBCartVect p0 = vertices[0] - vertices[1]; // abc
-  const MBCartVect p1 = vertices[0] - vertices[2]; // def
-                                                   // ghi<-v
-  const MBCartVect p = vertices[0] - b;            // jkl
-  const MBCartVect c = p1 * v;                     // eiMinushf,gfMinusdi,dhMinuseg
-  const double mP = p0 % c;
-  const double betaP = p % c;
-  if (mP > 0) {
-    if (betaP < 0)
-      return false;
-  }
-  else if (mP < 0) {
-    if (betaP > 0)
-      return false;
-  }
-  else {
-    return false;
-  }
-  
-  const MBCartVect d = p0 * p; // jcMinusal,blMinuskc,akMinusjb
-  double gammaP = v % d;
-  if (mP > 0) {
-    if (gammaP < 0 || betaP + gammaP > mP)
-      return false;
-  }
-  else if (betaP + gammaP < mP || gammaP > 0)
-    return false;
-  
-  const double tP = p1 % d;
-  const double m = 1.0 / mP;
-  const double beta = betaP * m;
-  const double gamma = gammaP * m;
-  const double t = -tP * m;
-  if (ray_length && t > *ray_length)
-    return false;
-  
-  if (beta < 0 || gamma < 0 ||
-      beta + gamma > 1 ||
-      t < 0.0)
-    return false;
-  
-  t_out = t;
-  return true;
-}
-
-bool ray_box_intersect( const MBCartVect& box_min,
-                        const MBCartVect& box_max,
-                        const MBCartVect& ray_pt,
-                        const MBCartVect& ray_dir,
-                        double& t_enter, double& t_exit )
-{
-  const double epsilon = 1e-12;
-  double t1, t2;
-
-  // Use 'slabs' method from 13.6.1 of Akenine-Moller
-  t_enter = 0.0;
-  t_exit  = std::numeric_limits<double>::infinity();
-  
-  // Intersect with each pair of axis-aligned planes bounding
-  // opposite faces of the leaf box
-  bool ray_is_valid = false; // is ray direction vector zero?
-  for (int axis = 0; axis < 3; ++axis) {
-    if (fabs(ray_dir[axis]) < epsilon) { // ray parallel to planes
-      if (ray_pt[axis] >= box_min[axis] &&
-          ray_pt[axis] <= box_max[axis])
-        continue;
-      else
-        return false;
-    }
-      
-      // find t values at which ray intersects each plane
-    ray_is_valid = true;
-    t1 = (box_min[axis] - ray_pt[axis]) / ray_dir[axis];
-    t2 = (box_max[axis] - ray_pt[axis]) / ray_dir[axis];
-    
-      // t_enter = max( t_enter_x, t_enter_y, t_enter_z )
-      // t_exit  = min( t_exit_x, t_exit_y, t_exit_z )
-      //   where
-      // t_enter_x = min( t1_x, t2_x );
-      // t_exit_x  = max( t1_x, t2_x )
-    if (t1 < t2) {
-      if (t_enter < t1)
-        t_enter = t1;
-      if (t_exit > t2)
-        t_exit = t2;
-    }
-    else {
-      if (t_enter < t2)
-        t_enter = t2;
-      if (t_exit > t1)
-        t_exit = t1;
-    }
-  }
-  
-  return ray_is_valid && (t_enter <= t_exit);
-}
-
-
-bool box_plane_overlap( const MBCartVect& normal,
-                        double d,
-                        MBCartVect min,
-                        MBCartVect max )
-{
-  if (normal[0] < 0.0)
-    std::swap( min[0], max[0] );
-  if (normal[1] < 0.0)
-    std::swap( min[1], max[1] );
-  if (normal[2] < 0.0)
-    std::swap( min[2], max[2] );
-  
-  return (normal % min <= -d) && (normal % max >= -d);
-}
-
-
-#define CHECK_RANGE( A, B, R ) \
-  if ((A) < (B)) { \
-    if ((A) > (R) || (B) < -(R)) \
-      return false; \
-  } \
-  else if ((B) > (R) || (A) < -(R)) \
-    return false
-
-/* Adapted from: http://jgt.akpeters.com/papers/AkenineMoller01/tribox.html
- * Use separating axis theorem to test for overlap between triangle
- * and axis-aligned box.
- *
- * Test for overlap in these directions:
- * 1) {x,y,z}-directions 
- * 2) normal of triangle
- * 3) crossprod of triangle edge with {x,y,z}-direction
- */
-bool box_tri_overlap( const MBCartVect vertices[3],
-                      const MBCartVect& box_center,
-                      const MBCartVect& box_dims )
-{
-    // translate everthing such that box is centered at origin
-  const MBCartVect v0( vertices[0] - box_center );
-  const MBCartVect v1( vertices[1] - box_center );
-  const MBCartVect v2( vertices[2] - box_center );
-
-  // do case 1) tests
-  if (v0[0] > box_dims[0] && v1[0] > box_dims[0] && v2[0] > box_dims[0])
-    return false;
-  if (v0[1] > box_dims[1] && v1[1] > box_dims[1] && v2[1] > box_dims[1])
-    return false;
-  if (v0[2] > box_dims[2] && v1[2] > box_dims[2] && v2[2] > box_dims[2])
-    return false;
-  if (v0[0] < -box_dims[0] && v1[0] < -box_dims[0] && v2[0] < -box_dims[0])
-    return false;
-  if (v0[1] < -box_dims[1] && v1[1] < -box_dims[1] && v2[1] < -box_dims[1])
-    return false;
-  if (v0[2] < -box_dims[2] && v1[2] < -box_dims[2] && v2[2] < -box_dims[2])
-    return false;
-  
-    // compute triangle edge vectors
-  const MBCartVect e0( vertices[1] - vertices[0] );
-  const MBCartVect e1( vertices[2] - vertices[1] );
-  const MBCartVect e2( vertices[0] - vertices[2] );
-  
-    // do case 3) tests 
-  double fex, fey, fez, p0, p1, p2, rad;
-  fex = fabs(e0[0]);
-  fey = fabs(e0[1]);
-  fez = fabs(e0[2]);
-  
-  p0 = e0[2]*v0[1] - e0[1]*v0[2];
-  p2 = e0[2]*v2[1] - e0[1]*v2[2];
-  rad = fez * box_dims[1] + fey * box_dims[2];
-  CHECK_RANGE( p0, p2, rad );
-  
-  p0 = -e0[2]*v0[0] + e0[0]*v0[2];
-  p2 = -e0[2]*v2[0] + e0[0]*v2[2];
-  rad = fez * box_dims[0] + fex * box_dims[2];
-  CHECK_RANGE( p0, p2, rad );
-    
-  p1 = e0[1]*v1[0] - e0[0]*v1[1];
-  p2 = e0[1]*v2[0] - e0[0]*v2[1];
-  rad = fey * box_dims[0] + fex * box_dims[1];
-  CHECK_RANGE( p1, p2, rad );
-  
-  fex = fabs(e1[0]);
-  fey = fabs(e1[1]);
-  fez = fabs(e1[2]);
-  
-  p0 = e1[2]*v0[1] - e1[1]*v0[2];
-  p2 = e1[2]*v2[1] - e1[1]*v2[2];
-  rad = fez * box_dims[1] + fey * box_dims[2];
-  CHECK_RANGE( p0, p2, rad );
-  
-  p0 = -e1[2]*v0[0] + e1[0]*v0[2];
-  p2 = -e1[2]*v2[0] + e1[0]*v2[2];
-  rad = fez * box_dims[0] + fex * box_dims[2];
-  CHECK_RANGE( p0, p2, rad );
-  
-  p0 = e1[1]*v0[0] - e1[0]*v0[1];
-  p1 = e1[1]*v1[0] - e1[0]*v1[1];
-  rad = fey * box_dims[0] + fex * box_dims[1];
-  CHECK_RANGE( p0, p1, rad );
-  
-  fex = fabs(e2[0]);
-  fey = fabs(e2[1]);
-  fez = fabs(e2[2]);
-  
-  p0 = e2[2]*v0[1] - e2[1]*v0[2];
-  p1 = e2[2]*v1[1] - e2[1]*v1[2];
-  rad = fez * box_dims[1] + fey * box_dims[2];
-  CHECK_RANGE( p0, p1, rad );
-  
-  p0 = -e2[2]*v0[0] + e2[0]*v0[2];
-  p1 = -e2[2]*v1[0] + e2[0]*v1[2];
-  rad = fez * box_dims[0] + fex * box_dims[2];
-  CHECK_RANGE( p0, p1, rad );
-  
-  p1 = e2[1]*v1[0] - e2[0]*v1[1];
-  p2 = e2[1]*v2[0] - e2[0]*v2[1];
-  rad = fey * box_dims[0] + fex * box_dims[1];
-  CHECK_RANGE( p1, p2, rad );
-  
-  // do case 2) test
-  MBCartVect n = e0 * e1;
-  return box_plane_overlap( n, -(n % v0), -box_dims, box_dims );
-}
-  
-
-bool box_tri_overlap( const MBCartVect  triangle_corners[3],
-                      const MBCartVect& box_min_corner,
-                      const MBCartVect& box_max_corner,
-                      double            tolerance )
-{
-  const MBCartVect box_center = 0.5 * (box_max_corner + box_min_corner);
-  const MBCartVect box_hf_dim = 0.5 * (box_max_corner - box_min_corner);
-  return box_tri_overlap( triangle_corners,
-                          box_center,
-                          box_hf_dim + MBCartVect(tolerance) );
-} 
-
-bool box_elem_overlap( const MBCartVect *elem_corners,
-                       MBEntityType elem_type,
-                       const MBCartVect& center,
-                       const MBCartVect& dims )
-{
-
-  switch (elem_type) {
-    case MBTRI:
-      return box_tri_overlap( elem_corners, center, dims );
-    case MBTET:
-      return box_tet_overlap( elem_corners, center, dims );
-    case MBHEX:
-      return box_hex_overlap( elem_corners, center, dims );
-    case MBPOLYGON:
-    case MBPOLYHEDRON:
-      assert(false);
-      return false;
-    default:
-      return box_linear_elem_overlap( elem_corners, elem_type, center, dims );
-  }
-}
-
-static inline MBCartVect quad_norm( const MBCartVect& v1,
-                                    const MBCartVect& v2,
-                                    const MBCartVect& v3,
-                                    const MBCartVect& v4 )
-{ return (-v1+v2+v3-v4) * (-v1-v2+v3+v4); }
-
-static inline MBCartVect tri_norm( const MBCartVect& v1,
-                                   const MBCartVect& v2,
-                                   const MBCartVect& v3 )
-{ return (v2-v1) * (v3-v1); }
-
-
-bool box_linear_elem_overlap( const MBCartVect *elem_corners,
-                              MBEntityType type,
-                              const MBCartVect& box_center,
-                              const MBCartVect& box_halfdims )
-{
-  MBCartVect corners[8];
-  const unsigned num_corner = MBCN::VerticesPerEntity( type );
-  assert( num_corner <= sizeof(corners)/sizeof(corners[0]) );
-  for (unsigned i = 0; i < num_corner; ++i)
-    corners[i] = elem_corners[i] - box_center;
-  return box_linear_elem_overlap( corners, type, box_halfdims );
-}
-        
-
-bool box_linear_elem_overlap( const MBCartVect *elem_corners,
-                              MBEntityType type,
-                              const MBCartVect& dims )
-{
-    // Do Separating Axis Theorem:
-    // If the element and the box overlap, then the 1D projections
-    // onto at least one of the axes in the following three sets
-    // must overlap (assuming convex polyhedral element).
-    // 1) The normals of the faces of the box (the principal axes)
-    // 2) The crossproduct of each element edge with each box edge
-    //    (crossproduct of each edge with each principal axis)
-    // 3) The normals of the faces of the element
-
-  unsigned i, e, f;             // loop counters
-  double dot, cross[2], tmp;
-  MBCartVect norm;
-  int indices[4]; // element edge/face vertex indices
-  
-    // test box face normals (principal axes)
-  const unsigned num_corner = MBCN::VerticesPerEntity( type );
-  int not_less[3] = { num_corner, num_corner, num_corner }; 
-  int not_greater[3] = { num_corner, num_corner, num_corner };
-  int not_inside;
-  for (i = 0; i < num_corner; ++i) { // for each element corner
-    not_inside = 3;
-    
-    if (elem_corners[i][0] < -dims[0])
-      --not_less[0];
-    else if (elem_corners[i][0] > dims[0])
-      --not_greater[0];
-    else
-      --not_inside;
-      
-    if (elem_corners[i][1] < -dims[1])
-      --not_less[1];
-    else if (elem_corners[i][1] > dims[1])
-      --not_greater[1];
-    else
-      --not_inside;
-      
-    if (elem_corners[i][2] < -dims[2])
-      --not_less[2];
-    else if (elem_corners[i][2] > dims[2])
-      --not_greater[2];
-    else
-      --not_inside;
-    
-    if (!not_inside)
-      return true;
-  }
-    // If all points less than min_x of box, then
-    // not_less[0] == 0, and therfore
-    // the following product is zero.
-  if (not_greater[0] * not_greater[1] * not_greater[2] * 
-         not_less[0] *    not_less[1] *    not_less[2] == 0)
-    return false;
- 
-    // Test edge-edge crossproducts
-    
-    // Edge directions for box are principal axis, so 
-    // for each element edge, check along the cross-product
-    // of that edge with each of the tree principal axes.
-  const unsigned num_edge = MBCN::NumSubEntities( type, 1 );
-  for (e = 0; e < num_edge; ++e) { // for each element edge
-      // get which element vertices bound the edge
-    MBCN::SubEntityVertexIndices( type, 1, e, indices );
-
-      // X-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = elem_corners[indices[0]][2] - elem_corners[indices[1]][2];
-    cross[1] = elem_corners[indices[1]][1] - elem_corners[indices[0]][1];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[1]) + fabs(cross[1] * dims[2]);
-      not_less[0] = not_greater[0] = num_corner - 1;
-      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
-        tmp = cross[0] * elem_corners[i][1] + cross[1] * elem_corners[i][2];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-
-      // Y-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = elem_corners[indices[0]][0] - elem_corners[indices[1]][0];
-    cross[1] = elem_corners[indices[1]][2] - elem_corners[indices[0]][2];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[2]) + fabs(cross[1] * dims[0]);
-      not_less[0] = not_greater[0] = num_corner - 1;
-      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
-        tmp = cross[0] * elem_corners[i][2] + cross[1] * elem_corners[i][0];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-
-      // Z-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = elem_corners[indices[0]][1] - elem_corners[indices[1]][1];
-    cross[1] = elem_corners[indices[1]][0] - elem_corners[indices[0]][0];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[0]) + fabs(cross[1] * dims[1]);
-      not_less[0] = not_greater[0] = num_corner - 1;
-      for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
-        tmp = cross[0] * elem_corners[i][0] + cross[1] * elem_corners[i][1];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-  }
-  
-  
-    // test element face normals
-  const unsigned num_face = MBCN::NumSubEntities( type, 2 );
-  for (f = 0; f < num_face; ++f) {
-    MBCN::SubEntityVertexIndices( type, 2, f, indices );
-    switch (MBCN::SubEntityType( type, 2, f )) {
-      case MBTRI:
-        norm = tri_norm( elem_corners[indices[0]], 
-                         elem_corners[indices[1]], 
-                         elem_corners[indices[2]] );
-        break;
-      case MBQUAD:
-        norm = quad_norm( elem_corners[indices[0]], 
-                          elem_corners[indices[1]], 
-                          elem_corners[indices[2]], 
-                          elem_corners[indices[3]] );
-        break;
-      default:
-        assert(false);
-        continue;
-    }
-    
-    dot = dot_abs(norm, dims);
-    
-    // for each element vertex
-    not_less[0] = not_greater[0] = num_corner;
-    for (i = 0; i < num_corner; ++i) { 
-      tmp = norm % elem_corners[i];
-      not_less[0] -= (tmp < -dot);
-      not_greater[0] -= (tmp > dot);
-    }
-
-    if (not_less[0] * not_greater[0] == 0)
-      return false;
-  }
-
-    // Overlap on all tested axes.
-  return true;
-}
- 
-
-bool box_hex_overlap( const MBCartVect *elem_corners,
-                      const MBCartVect& center,
-                      const MBCartVect& dims )
-{
-    // Do Separating Axis Theorem:
-    // If the element and the box overlap, then the 1D projections
-    // onto at least one of the axes in the following three sets
-    // must overlap (assuming convex polyhedral element).
-    // 1) The normals of the faces of the box (the principal axes)
-    // 2) The crossproduct of each element edge with each box edge
-    //    (crossproduct of each edge with each principal axis)
-    // 3) The normals of the faces of the element
-
-  unsigned i, e, f;             // loop counters
-  double dot, cross[2], tmp;
-  MBCartVect norm;
-  const MBCartVect corners[8] = { elem_corners[0] - center,
-                                  elem_corners[1] - center,
-                                  elem_corners[2] - center,
-                                  elem_corners[3] - center,
-                                  elem_corners[4] - center,
-                                  elem_corners[5] - center,
-                                  elem_corners[6] - center,
-                                  elem_corners[7] - center };
-  
-    // test box face normals (principal axes)
-  int not_less[3] = { 8, 8, 8 }; 
-  int not_greater[3] = { 8, 8, 8 };
-  int not_inside;
-  for (i = 0; i < 8; ++i) { // for each element corner
-    not_inside = 3;
-    
-    if (corners[i][0] < -dims[0])
-      --not_less[0];
-    else if (corners[i][0] > dims[0])
-      --not_greater[0];
-    else
-      --not_inside;
-      
-    if (corners[i][1] < -dims[1])
-      --not_less[1];
-    else if (corners[i][1] > dims[1])
-      --not_greater[1];
-    else
-      --not_inside;
-      
-    if (corners[i][2] < -dims[2])
-      --not_less[2];
-    else if (corners[i][2] > dims[2])
-      --not_greater[2];
-    else
-      --not_inside;
-    
-    if (!not_inside)
-      return true;
-  }
-    // If all points less than min_x of box, then
-    // not_less[0] == 0, and therfore
-    // the following product is zero.
-  if (not_greater[0] * not_greater[1] * not_greater[2] * 
-         not_less[0] *    not_less[1] *    not_less[2] == 0)
-    return false;
- 
-    // Test edge-edge crossproducts
-  const unsigned edges[12][2] = { { 0, 1 }, { 0, 4 }, { 0, 3 },
-                                  { 2, 3 }, { 2, 1 }, { 2, 6 },
-                                  { 5, 6 }, { 5, 1 }, { 5, 4 },
-                                  { 7, 4 }, { 7, 3 }, { 7, 6 } };
-                             
-    // Edge directions for box are principal axis, so 
-    // for each element edge, check along the cross-product
-    // of that edge with each of the tree principal axes.
-  for (e = 0; e < 12; ++e) { // for each element edge
-      // get which element vertices bound the edge
-    const MBCartVect& v0 = corners[ edges[e][0] ];
-    const MBCartVect& v1 = corners[ edges[e][1] ];
-
-      // X-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = v0[2] - v1[2];
-    cross[1] = v1[1] - v0[1];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[1]) + fabs(cross[1] * dims[2]);
-      not_less[0] = not_greater[0] = 7;
-      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
-        tmp = cross[0] * corners[i][1] + cross[1] * corners[i][2];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-
-      // Y-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = v0[0] - v1[0];
-    cross[1] = v1[2] - v0[2];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[2]) + fabs(cross[1] * dims[0]);
-      not_less[0] = not_greater[0] = 7;
-      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
-        tmp = cross[0] * corners[i][2] + cross[1] * corners[i][0];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-
-      // Z-Axis
-
-      // calculate crossproduct: axis x (v1 - v0),
-      // where v1 and v0 are edge vertices.
-    cross[0] = v0[1] - v1[1];
-    cross[1] = v1[0] - v0[0];
-      // skip if parallel
-    if ((cross[0]*cross[0] + cross[1]*cross[1]) >= std::numeric_limits<double>::epsilon()) {
-      dot = fabs(cross[0] * dims[0]) + fabs(cross[1] * dims[1]);
-      not_less[0] = not_greater[0] = 7;
-      for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
-        tmp = cross[0] * corners[i][0] + cross[1] * corners[i][1];
-        not_less[0] -= (tmp < -dot);
-        not_greater[0] -= (tmp > dot);
-      }
-
-      if (not_less[0] * not_greater[0] == 0)
-        return false;
-    }
-  }
-  
-  
-    // test element face normals
-  const unsigned faces[6][4] = { { 0, 1, 2, 3 },
-                                 { 0, 1, 5, 4 },
-                                 { 1, 2, 6, 5 },
-                                 { 2, 6, 7, 3 },
-                                 { 3, 7, 4, 0 },
-                                 { 7, 4, 5, 6 } };
-  for (f = 0; f < 6; ++f) {
-    norm = quad_norm( corners[faces[f][0]], 
-                      corners[faces[f][1]], 
-                      corners[faces[f][2]], 
-                      corners[faces[f][3]] );
-    
-    dot = dot_abs(norm, dims);
-   
-    // for each element vertex
-    not_less[0] = not_greater[0] = 8;
-    for (i = 0; i < 8; ++i) { 
-      tmp = norm % corners[i];
-      not_less[0] -= (tmp < -dot);
-      not_greater[0] -= (tmp > dot);
-    }
-
-    if (not_less[0] * not_greater[0] == 0)
-      return false;
-  }
-
-    // Overlap on all tested axes.
-  return true;
-}
-
-static inline 
-bool box_tet_overlap_edge( const MBCartVect& dims,
-                           const MBCartVect& edge,
-                           const MBCartVect& ve,
-                           const MBCartVect& v1,
-                           const MBCartVect& v2 )
-{
-  double dot, dot1, dot2, dot3, min, max;
-  
-    // edge x X
-  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
-    dot = fabs(edge[2]) * dims[1] + fabs(edge[1]) * dims[2];
-    dot1 = edge[2] * ve[1] - edge[1] * ve[2];
-    dot2 = edge[2] * v1[1] - edge[1] * v1[2];
-    dot3 = edge[2] * v2[1] - edge[1] * v2[2];
-    min_max_3( dot1, dot2, dot3, min, max );
-    if (max < -dot || min > dot)
-      return false;
-  }
-  
-    // edge x Y
-  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
-    dot = fabs(edge[2]) * dims[0] + fabs(edge[0]) * dims[2];
-    dot1 = -edge[2] * ve[0] + edge[0] * ve[2];
-    dot2 = -edge[2] * v1[0] + edge[0] * v1[2];
-    dot3 = -edge[2] * v2[0] + edge[0] * v2[2];
-    min_max_3( dot1, dot2, dot3, min, max );
-    if (max < -dot || min > dot)
-      return false;
-  }
-  
-    // edge x Z
-  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
-    dot = fabs(edge[1]) * dims[0] + fabs(edge[0]) * dims[1];
-    dot1 = edge[1] * ve[0] - edge[0] * ve[1];
-    dot2 = edge[1] * v1[0] - edge[0] * v1[1];
-    dot3 = edge[1] * v2[0] - edge[0] * v2[1];
-    min_max_3( dot1, dot2, dot3, min, max );
-    if (max < -dot || min > dot)
-      return false;
-  }
-
-  return true;
-}
-
-bool box_tet_overlap( const MBCartVect *corners_in,
-                      const MBCartVect& center,
-                      const MBCartVect& dims )
-{
-    // Do Separating Axis Theorem:
-    // If the element and the box overlap, then the 1D projections
-    // onto at least one of the axes in the following three sets
-    // must overlap (assuming convex polyhedral element).
-    // 1) The normals of the faces of the box (the principal axes)
-    // 2) The crossproduct of each element edge with each box edge
-    //    (crossproduct of each edge with each principal axis)
-    // 3) The normals of the faces of the element
-
-    // Translate problem such that box center is at origin.
-  const MBCartVect corners[4] = { corners_in[0] - center,
-                                  corners_in[1] - center,
-                                  corners_in[2] - center,
-                                  corners_in[3] - center };
-
-    // 0) Check if any vertex is within the box
-  if (fabs(corners[0][0]) <= dims[0] &&
-      fabs(corners[0][1]) <= dims[1] &&
-      fabs(corners[0][2]) <= dims[2])
-    return true;
-  if (fabs(corners[1][0]) <= dims[0] &&
-      fabs(corners[1][1]) <= dims[1] &&
-      fabs(corners[1][2]) <= dims[2])
-    return true;
-  if (fabs(corners[2][0]) <= dims[0] &&
-      fabs(corners[2][1]) <= dims[1] &&
-      fabs(corners[2][2]) <= dims[2])
-    return true;
-  if (fabs(corners[3][0]) <= dims[0] &&
-      fabs(corners[3][1]) <= dims[1] &&
-      fabs(corners[3][2]) <= dims[2])
-    return true;
-  
-
-    // 1) Check for overlap on each principal axis (box face normal)
-    // X
-  if (corners[0][0] < -dims[0] &&
-      corners[1][0] < -dims[0] &&
-      corners[2][0] < -dims[0] &&
-      corners[3][0] < -dims[0])
-    return false;
-  if (corners[0][0] >  dims[0] &&
-      corners[1][0] >  dims[0] &&
-      corners[2][0] >  dims[0] &&
-      corners[3][0] >  dims[0])
-    return false;
-    // Y
-  if (corners[0][1] < -dims[1] &&
-      corners[1][1] < -dims[1] &&
-      corners[2][1] < -dims[1] &&
-      corners[3][1] < -dims[1])
-    return false;
-  if (corners[0][1] >  dims[1] &&
-      corners[1][1] >  dims[1] &&
-      corners[2][1] >  dims[1] &&
-      corners[3][1] >  dims[1])
-    return false;
-    // Z
-  if (corners[0][2] < -dims[2] &&
-      corners[1][2] < -dims[2] &&
-      corners[2][2] < -dims[2] &&
-      corners[3][2] < -dims[2])
-    return false;
-  if (corners[0][2] >  dims[2] &&
-      corners[1][2] >  dims[2] &&
-      corners[2][2] >  dims[2] &&
-      corners[3][2] >  dims[2])
-    return false;
- 
-    // 3) test element face normals
-  MBCartVect norm;
-  double dot, dot1, dot2;
-  
-  const MBCartVect v01 = corners[1] - corners[0];
-  const MBCartVect v02 = corners[2] - corners[0];
-  norm = v01 * v02;
-  dot = dot_abs(norm, dims);
-  dot1 = norm % corners[0];
-  dot2 = norm % corners[3];
-  if (dot1 > dot2)
-    std::swap(dot1, dot2);
-  if (dot2 < -dot || dot1 > dot)
-    return false;
-  
-  const MBCartVect v03 = corners[3] - corners[0];
-  norm = v03 * v01;
-  dot = dot_abs(norm, dims);
-  dot1 = norm % corners[0];
-  dot2 = norm % corners[2];
-  if (dot1 > dot2)
-    std::swap(dot1, dot2);
-  if (dot2 < -dot || dot1 > dot)
-    return false;
-  
-  norm = v02 * v03;
-  dot = dot_abs(norm, dims);
-  dot1 = norm % corners[0];
-  dot2 = norm % corners[1];
-  if (dot1 > dot2)
-    std::swap(dot1, dot2);
-  if (dot2 < -dot || dot1 > dot)
-    return false;
-  
-  const MBCartVect v12 = corners[2] - corners[1];
-  const MBCartVect v13 = corners[3] - corners[1];
-  norm = v13 * v12;
-  dot = dot_abs(norm, dims);
-  dot1 = norm % corners[0];
-  dot2 = norm % corners[1];
-  if (dot1 > dot2)
-    std::swap(dot1, dot2);
-  if (dot2 < -dot || dot1 > dot)
-    return false;
-  
-
-    // 2) test edge-edge cross products
-    
-  const MBCartVect v23 = corners[3] - corners[2];
-  return box_tet_overlap_edge( dims, v01, corners[0], corners[2], corners[3] )
-      && box_tet_overlap_edge( dims, v02, corners[0], corners[1], corners[3] )
-      && box_tet_overlap_edge( dims, v03, corners[0], corners[1], corners[2] )
-      && box_tet_overlap_edge( dims, v12, corners[1], corners[0], corners[3] )
-      && box_tet_overlap_edge( dims, v13, corners[1], corners[0], corners[2] )
-      && box_tet_overlap_edge( dims, v23, corners[2], corners[0], corners[1] );
-}
-    
-
-
-
-//from: http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf#search=%22closest%20point%20on%20triangle%22
-/*       t
- *   \(2)^
- *    \  |
- *     \ |
- *      \|
- *       \
- *       |\
- *       | \
- *       |  \  (1)
- *  (3)  tv  \
- *       |    \
- *       | (0) \
- *       |      \
- *-------+---sv--\----> s
- *       |        \ (6)
- *  (4)  |   (5)   \
- */
-// Worst case is either 61 flops and 5 compares or 53 flops and 6 compares,
-// depending on relative costs.  For all paths that do not return one of the
-// corner vertices, exactly one of the flops is a divide.
-void closest_location_on_tri( const MBCartVect& location,
-                              const MBCartVect* vertices,
-                              MBCartVect& closest_out )
-{                                                     // ops      comparisons
-  const MBCartVect sv( vertices[1] - vertices[0] );   // +3 = 3
-  const MBCartVect tv( vertices[2] - vertices[0] );   // +3 = 6
-  const MBCartVect pv( vertices[0] - location );      // +3 = 9
-  const double ss = sv % sv;                          // +5 = 14
-  const double st = sv % tv;                          // +5 = 19
-  const double tt = tv % tv;                          // +5 = 24
-  const double sp = sv % pv;                          // +5 = 29
-  const double tp = tv % pv;                          // +5 = 34
-  const double det = ss*tt - st*st;                   // +3 = 37
-  double s = st*tp - tt*sp;                           // +3 = 40
-  double t = st*sp - ss*tp;                           // +3 = 43
-  if (s+t < det) {                                    // +1 = 44, +1 = 1
-    if (s < 0) {                                      //          +1 = 2
-      if (t < 0) {                                    //          +1 = 3
-        // region 4
-        if (sp < 0) {                                 //          +1 = 4
-          if (-sp > ss)                               //          +1 = 5
-            closest_out = vertices[1];                //      44       5
-          else
-            closest_out = vertices[0] - (sp/ss) * sv; // +7 = 51,      5
-        }
-        else if (tp < 0) {                            //          +1 = 5
-          if (-tp > tt)                               //          +1 = 6
-            closest_out = vertices[2];                //      44,      6
-          else
-            closest_out = vertices[0] - (tp/tt) * tv; // +7 = 51,      6
-        }
-        else {
-          closest_out = vertices[0];                  //      44,      5
-        }
-      }
-      else {
-        // region 3
-        if (tp >= 0)                                  //          +1 = 4
-          closest_out = vertices[0];                  //      44,      4
-        else if (-tp >= tt)                           //          +1 = 5
-          closest_out = vertices[2];                  //      44,      5
-        else
-          closest_out = vertices[0] - (tp/tt) * tv;   // +7 = 51,      5
-      }
-    }
-    else if (t < 0) {                                 //          +1 = 3
-      // region 5;
-      if (sp >= 0.0)                                  //          +1 = 4
-        closest_out = vertices[0];                    //      44,      4
-      else if (-sp >= ss)                             //          +1 = 5
-        closest_out = vertices[1];                    //      44       5
-      else
-        closest_out = vertices[0] - (sp/ss) * sv;     // +7 = 51,      5
-    }
-    else {
-      // region 0
-      const double inv_det = 1.0 / det;               // +1 = 45
-      s *= inv_det;                                   // +1 = 46
-      t *= inv_det;                                   // +1 = 47
-      closest_out = vertices[0] + s*sv + t*tv;        //+12 = 59,      3  
-    }
-  }
-  else {
-    if (s < 0) {                                      //          +1 = 2
-      // region 2
-      s = st + sp;                                    // +1 = 45
-      t = tt + tp;                                    // +1 = 46
-      if (t > s) {                                    //          +1 = 3
-        const double num = t - s;                     // +1 = 47
-        const double den = ss - 2*st + tt;            // +3 = 50
-        if (num > den)                                //          +1 = 4
-          closest_out = vertices[1];                  //      50,      4
-        else {
-          s = num/den;                                // +1 = 51
-          t = 1 - s;                                  // +1 = 52
-          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      4
-        }
-      }
-      else if (t <= 0)                                //          +1 = 4
-        closest_out = vertices[2];                    //      46,      4
-      else if (tp >= 0)                               //          +1 = 5
-        closest_out = vertices[0];                    //      46,      5
-      else
-        closest_out = vertices[0] - (tp/tt) * tv;     // +7 = 53,      5
-    }
-    else if (t < 0) {                                 //          +1 = 3
-      // region 6
-      t = st + tp;                                    // +1 = 45
-      s = ss + sp;                                    // +1 = 46
-      if (s > t) {                                    //          +1 = 4
-        const double num = t - s;                     // +1 = 47
-        const double den = tt - 2*st + ss;            // +3 = 50
-        if (num > den)                                //          +1 = 5
-          closest_out = vertices[2];                  //      50,      5
-        else {
-          t = num/den;                                // +1 = 51
-          s = 1 - t;                                  // +1 = 52
-          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      5
-        }
-      }
-      else if (s <= 0)                                //          +1 = 5
-        closest_out = vertices[1];                    //      46,      5
-      else if (sp >= 0)                               //          +1 = 6
-        closest_out = vertices[0];                    //      46,      6
-      else
-        closest_out = vertices[0] - (sp/ss) * sv;     // +7 = 53,      6
-    }
-    else {
-      // region 1
-      const double num = tt + tp - st - sp;           // +3 = 47
-      if (num <= 0) {                                 //          +1 = 4
-        closest_out = vertices[2];                    //      47,      4
-      }
-      else {
-        const double den = ss - 2*st + tt;            // +3 = 50
-        if (num >= den)                               //          +1 = 5
-          closest_out = vertices[1];                  //      50,      5
-        else {
-          s = num/den;                                // +1 = 51
-          t = 1 - s;                                  // +1 = 52
-          closest_out = s*vertices[1] + t*vertices[2];// +9 = 61,      5
-        }
-      }
-    }
-  }
-}
-
-void closest_location_on_tri( const MBCartVect& location,
-                              const MBCartVect* vertices,
-                              double tolerance,
-                              MBCartVect& closest_out,
-                              int& closest_topo )
-{
-  const double tsqr = tolerance*tolerance;
-  int i;
-  MBCartVect pv[3], ev, ep;
-  double t;
-
-  closest_location_on_tri( location, vertices, closest_out );
-  
-  for (i = 0; i < 3; ++i) {
-    pv[i] = vertices[i] - closest_out;
-    if ((pv[i] % pv[i]) <= tsqr) {
-      closest_topo = i;
-      return;
-    }
-  }
-  
-  for (i = 0; i < 3; ++i) {
-    ev = vertices[(i+1)%3] - vertices[i];
-    t = (ev % pv[i]) / (ev % ev);
-    ep = closest_out - (vertices[i] + t * ev);
-    if ((ep % ep) <= tsqr) {
-      closest_topo = i+3;
-      return;
-    }
-  }
-  
-  closest_topo = 6;
-}
- 
-    
-// We assume polygon is *convex*, but *not* planar.
-void closest_location_on_polygon( const MBCartVect& location,
-                                  const MBCartVect* vertices,
-                                  int num_vertices,
-                                  MBCartVect& closest_out )
-{
-  const int n = num_vertices;
-  MBCartVect d, p, v;
-  double shortest_sqr, dist_sqr, t_closest, t;
-  int i, e;
-  
-    // Find closest edge of polygon.
-  e = n - 1;
-  v = vertices[0] - vertices[e];
-  t_closest = (v % (location - vertices[e])) / (v % v);
-  if (t_closest < 0.0)
-    d = location - vertices[e];
-  else if (t_closest > 1.0)
-    d = location - vertices[0];
-  else 
-    d = location - vertices[e] - t_closest * v;
-  shortest_sqr = d % d;
-  for (i = 0; i < n - 1; ++i) {
-    v = vertices[i+1] - vertices[i];
-    t = (v % (location - vertices[i])) / (v % v);
-    if (t < 0.0)
-      d = location - vertices[i];
-    else if (t > 1.0)
-      d = location - vertices[i+1];
-    else
-      d = location - vertices[i] - t * v;
-    dist_sqr = d % d;
-    if (dist_sqr < shortest_sqr) {
-      e = i;
-      shortest_sqr = dist_sqr;
-      t_closest = t;
-    }
-  }
-  
-    // If we are beyond the bounds of the edge, then
-    // the point is outside and closest to a vertex
-  if (t_closest <= 0.0) {
-    closest_out = vertices[e];
-    return;
-  }
-  else if (t_closest >= 1.0) {
-    closest_out = vertices[(e+1)%n];
-    return;
-  }
-  
-    // Now check which side of the edge we are one
-  const MBCartVect v0 = vertices[e] - vertices[(e+n-1)%n];
-  const MBCartVect v1 = vertices[(e+1)%n] - vertices[e];
-  const MBCartVect v2 = vertices[(e+2)%n] - vertices[(e+1)%n];
-  const MBCartVect norm = (1.0 - t_closest) * (v0 * v1) + t_closest * (v1 * v2);
-    // if on outside of edge, result is closest point on edge
-  if ((norm % ((vertices[e] - location) * v1)) <= 0.0) { 
-    closest_out = vertices[e] + t_closest * v1;
-    return;
-  }
-  
-    // Inside.  Project to plane defined by point and normal at
-    // closest edge
-  const double D = -(norm % (vertices[e] + t_closest * v1));
-  closest_out = (location - (norm % location + D) * norm)/(norm % norm);
-}
-
-void closest_location_on_box( const MBCartVect& min,
-                              const MBCartVect& max,
-                              const MBCartVect& point,
-                              MBCartVect& closest )
-{
-  closest[0] = point[0] < min[0] ? min[0] : point[0] > max[0] ? max[0] : point[0];
-  closest[1] = point[1] < min[1] ? min[1] : point[1] > max[1] ? max[1] : point[1];
-  closest[2] = point[2] < min[2] ? min[2] : point[2] > max[2] ? max[2] : point[2];
-}
-
-bool box_point_overlap( const MBCartVect& box_min_corner,
-                        const MBCartVect& box_max_corner,
-                        const MBCartVect& point,
-                        double tolerance )
-{
-  MBCartVect closest;
-  closest_location_on_box( box_min_corner, box_max_corner, point, closest );
-  closest -= point;
-  return closest % closest < tolerance * tolerance;
-}
-
-
-/**\brief Class representing a 3-D mapping function (e.g. shape function for volume element) */
-class VolMap {
-  public:
-      /**\brief Return $\vec \xi$ corresponding to logical center of element */
-    virtual MBCartVect center_xi() const = 0;
-      /**\brief Evaluate mapping function (calculate $\vec x = F($\vec \xi)$ )*/
-    virtual MBCartVect evaluate( const MBCartVect& xi ) const = 0;
-      /**\brief Evaluate Jacobian of mapping function */
-    virtual MBMatrix3 jacobian( const MBCartVect& xi ) const = 0;
-      /**\brief Evaluate inverse of mapping function (calculate $\vec \xi = F^-1($\vec x)$ )*/
-    bool solve_inverse( const MBCartVect& x, MBCartVect& xi, double tol ) const ;
-};
-
-bool VolMap::solve_inverse( const MBCartVect& x, MBCartVect& xi, double tol ) const
-{
-  const double error_tol_sqr = tol*tol;
-  double det;
-  xi = center_xi();
-  MBCartVect delta = evaluate(xi) - x;
-  MBMatrix3 J;
-  while (delta % delta > error_tol_sqr) {
-    J = jacobian(xi);
-    det = J.determinant();
-    if (det < std::numeric_limits<double>::epsilon())
-      return false;
-    xi -= J.inverse(1.0/det) * delta;
-    delta = evaluate( xi ) - x;
-  }
-  return true;
-}
-
-/**\brief Shape function for trilinear hexahedron */
-class LinearHexMap : public VolMap {
-  public:
-    LinearHexMap( const MBCartVect* corner_coords ) : corners(corner_coords) {}
-    virtual MBCartVect center_xi() const;
-    virtual MBCartVect evaluate( const MBCartVect& xi ) const;
-    virtual MBMatrix3 jacobian( const MBCartVect& xi ) const;
-  private:
-    const MBCartVect* corners;
-    static const double corner_xi[8][3];
-};
-
-const double LinearHexMap::corner_xi[8][3] = { { -1, -1, -1 },
-                                               {  1, -1, -1 },
-                                               {  1,  1, -1 },
-                                               { -1,  1, -1 },
-                                               { -1, -1,  1 },
-                                               {  1, -1,  1 },
-                                               {  1,  1,  1 },
-                                               { -1,  1,  1 } };
-MBCartVect LinearHexMap::center_xi() const
-  { return MBCartVect(0.0); }
-
-MBCartVect LinearHexMap::evaluate( const MBCartVect& xi ) const
-{
-  MBCartVect x(0.0);
-  for (unsigned i = 0; i < 8; ++i) {
-    const double N_i = (1 + xi[0]*corner_xi[i][0])
-                     * (1 + xi[1]*corner_xi[i][1])
-                     * (1 + xi[2]*corner_xi[i][2]);
-    x += N_i * corners[i];
-  }
-  x *= 0.125;
-  return x;
-}
-
-MBMatrix3 LinearHexMap::jacobian( const MBCartVect& xi ) const
-{
-  MBMatrix3 J(0.0);
-  for (unsigned i = 0; i < 8; ++i) {
-    const double   xi_p = 1 + xi[0]*corner_xi[i][0];
-    const double  eta_p = 1 + xi[1]*corner_xi[i][1];
-    const double zeta_p = 1 + xi[2]*corner_xi[i][2];
-    const double dNi_dxi   = corner_xi[i][0] * eta_p * zeta_p;
-    const double dNi_deta  = corner_xi[i][1] *  xi_p * zeta_p;
-    const double dNi_dzeta = corner_xi[i][2] *  xi_p *  eta_p;
-    J(0,0) += dNi_dxi   * corners[i][0];
-    J(1,0) += dNi_dxi   * corners[i][1];
-    J(2,0) += dNi_dxi   * corners[i][2];
-    J(0,1) += dNi_deta  * corners[i][0];
-    J(1,1) += dNi_deta  * corners[i][1];
-    J(2,1) += dNi_deta  * corners[i][2];
-    J(0,2) += dNi_dzeta * corners[i][0];
-    J(1,2) += dNi_dzeta * corners[i][1];
-    J(2,2) += dNi_dzeta * corners[i][2];
-  }
-  return J *= 0.125;
-}
-
-bool nat_coords_trilinear_hex( const MBCartVect* corner_coords,
-                               const MBCartVect& x,
-                               MBCartVect& xi,
-                               double tol )
-{
-  return LinearHexMap( corner_coords ).solve_inverse( x, xi, tol );
-}
-
-
-bool point_in_trilinear_hex(const MBCartVect *hex, 
-                            const MBCartVect& xyz,
-                            double etol) 
-{
-  MBCartVect xi;
-  return nat_coords_trilinear_hex( hex, xyz, xi, etol )
-      && fabs(xi[0])-1 < etol 
-      && fabs(xi[1])-1 < etol 
-      && fabs(xi[2])-1 < etol;
-}
-
-
-
-} // namespace MBGeoemtry

Deleted: MOAB/trunk/src/MBInternals.hpp
===================================================================
--- MOAB/trunk/src/MBInternals.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBInternals.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,119 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-#ifndef MB_INTERNALS_HPP
-#define MB_INTERNALS_HPP
-
-#ifdef WIN32
-#pragma warning(disable : 4786)
-#endif
-
-#ifndef IS_BUILDING_MB
-#error "MBInternals.hpp isn't supposed to be included into an application"
-#endif
-
-#include "MBTypes.h"
-#include <assert.h>
-
-/*! Define MBEntityHandle for both 32 bit and 64 bit systems.
- *  The decision to use 64 bit handles must be made at compile time.
- *  \bug we should probably have an Int64 typedef
- *
- *  MBEntityHandle format:
- *  0xXYYYYYYY  (assuming a 32-bit handle.  Top 4 bits reserved on a 64 bit system)
- *  X - reserved for entity type.  This system can only handle 15 different types
- *  Y - Entity id space.  Max id is over 200M
- *
- *  Note that for specialized databases (such as all hex) 16 bits are not
- *  required for the entity type and the id space can be increased to over 2B.
- */
-#define MB_TYPE_WIDTH 4
-#define MB_ID_WIDTH (8*sizeof(MBEntityHandle)-MB_TYPE_WIDTH)
-#define MB_TYPE_MASK ((MBEntityHandle)0xF << MB_ID_WIDTH)
-//             2^MB_TYPE_WIDTH-1 ------^
-
-#define MB_START_ID ((MBEntityID)1)        //!< All entity id's currently start at 1
-#define MB_END_ID ((MBEntityID)MB_ID_MASK) //!< Last id is the complement of the MASK
-#define MB_ID_MASK (~MB_TYPE_MASK)
-
-//! Given a type and an id create a handle.  
-inline MBEntityHandle CREATE_HANDLE(const unsigned type, const MBEntityID id, int& err) 
-{
-  err = 0; //< Assume that there is a real error value defined somewhere
-
-  if (id > MB_END_ID || type > MBMAXTYPE)
-  {
-    err = 1;   //< Assume that there is a real error value defined somewhere
-    return 1;  //<You've got to return something.  What do you return?
-  }
-  
-  return (((MBEntityHandle)type) << MB_ID_WIDTH)|id;
-}
-
-inline MBEntityHandle CREATE_HANDLE( const unsigned type, const MBEntityID id )
-{
-  assert( id <= MB_END_ID && type <= MBMAXTYPE );
-  return (((MBEntityHandle)type) << MB_ID_WIDTH)|id;
-}
-
-inline MBEntityHandle FIRST_HANDLE( unsigned type )
-  { return (((MBEntityHandle)type) << MB_ID_WIDTH)|MB_START_ID; }
-
-inline MBEntityHandle LAST_HANDLE( unsigned type )
-  { return ((MBEntityHandle)(type+1) << MB_ID_WIDTH) - 1; }
-
-//! Get the entity id out of the handle.
-inline MBEntityID ID_FROM_HANDLE (MBEntityHandle handle)
-{
-  return (handle & MB_ID_MASK);
-}
-
-//! Get the type out of the handle.  Can do a simple shift because
-//! handles are unsigned (therefore shifting fills with zero's)
-inline MBEntityType TYPE_FROM_HANDLE(MBEntityHandle handle) 
-{
-  return static_cast<MBEntityType> (handle >> MB_ID_WIDTH);
-}
-
-typedef unsigned long MBTagId;
-
-/* MBTag format
- * 0xXXZZZZZZ  ( 32 bits total )
- * Z - reserved for internal sub-tag id
- * X - reserved for internal properties & lookup speed
- */
-#define MB_TAG_PROP_WIDTH 2
-#define MB_TAG_SHIFT_WIDTH (8*sizeof(MBTagId)-MB_TAG_PROP_WIDTH)
-#define MB_TAG_PROP_MASK (~((MBTagId)0x3 << MB_TAG_SHIFT_WIDTH))
-//        2^MB_TAG_PROP_WIDTH-1 ------^
-
-inline unsigned long ID_FROM_TAG_HANDLE(MBTag tag_handle) 
-{
-  return static_cast<MBTagId>( (MBTagId)tag_handle & MB_TAG_PROP_MASK );
-}
-
-inline MBTagType PROP_FROM_TAG_HANDLE(MBTag tag_handle)
-{
-  return static_cast<MBTagType>( (MBTagId)tag_handle >> MB_TAG_SHIFT_WIDTH );
-}
-
-inline MBTag TAG_HANDLE_FROM_ID(MBTagId tag_id, MBTagType prop) 
-{
-//  assert( tag_id <= MB_TAG_PROP_MASK );
-  return reinterpret_cast<MBTag>( ((MBTagId)prop)<<MB_TAG_SHIFT_WIDTH | tag_id );
-}
-
-#endif

Deleted: MOAB/trunk/src/MBMatrix3.cpp
===================================================================
--- MOAB/trunk/src/MBMatrix3.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBMatrix3.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,224 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBMatrix3.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#include "MBMatrix3.hpp"
-#include <math.h>
-#include <iostream>
-
-// Copied from "Visualization Toolkit"
-//  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
-//  All rights reserved.
-//  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
-//
-// Jacobi iteration for the solution of eigenvectors/eigenvalues of a nxn
-// real symmetric matrix. Square nxn matrix a; size of matrix in n;
-// output eigenvalues in w; and output eigenvectors in v. Resulting
-// eigenvalues/vectors are sorted in decreasing order; eigenvectors are
-// normalized.
-#define VTK_ROTATE(a,i,j,k,l) g=a[i][j];h=a[k][l];a[i][j]=g-s*(h+g*tau);\
-        a[k][l]=h+s*(g-h*tau)
-MBErrorCode EigenDecomp( const MBMatrix3& a_in, 
-                         double w[3],
-                         MBCartVect v[3] )
-{
-  const int MAX_ROTATIONS = 20;
-  const double one_ninth = 1./9;
-  int i, j, k, iq, ip, numPos;
-  double tresh, theta, tau, t, sm, s, h, g, c, tmp;
-  double b[3], z[3];
-  MBMatrix3 a(a_in);
-
-  // initialize
-  for (ip=0; ip<3; ip++) 
-    {
-    for (iq=0; iq<3; iq++)
-      {
-      v[ip][iq] = 0.0;
-      }
-    v[ip][ip] = 1.0;
-    }
-  for (ip=0; ip<3; ip++) 
-    {
-    b[ip] = w[ip] = a[ip][ip];
-    z[ip] = 0.0;
-    }
-
-  // begin rotation sequence
-  for (i=0; i<MAX_ROTATIONS; i++) 
-    {
-    sm = 0.0;
-    for (ip=0; ip<2; ip++) 
-      {
-      for (iq=ip+1; iq<3; iq++)
-        {
-        sm += fabs(a[ip][iq]);
-        }
-      }
-    if (sm == 0.0)
-      {
-      break;
-      }
-
-    if (i < 3)                                // first 3 sweeps
-      {
-      tresh = 0.2*sm*one_ninth;
-      }
-    else
-      {
-      tresh = 0.0;
-      }
-
-    for (ip=0; ip<2; ip++) 
-      {
-      for (iq=ip+1; iq<3; iq++) 
-        {
-        g = 100.0*fabs(a[ip][iq]);
-
-        // after 4 sweeps
-        if (i > 3 && (fabs(w[ip])+g) == fabs(w[ip])
-        && (fabs(w[iq])+g) == fabs(w[iq]))
-          {
-          a[ip][iq] = 0.0;
-          }
-        else if (fabs(a[ip][iq]) > tresh) 
-          {
-          h = w[iq] - w[ip];
-          if ( (fabs(h)+g) == fabs(h))
-            {
-            t = (a[ip][iq]) / h;
-            }
-          else 
-            {
-            theta = 0.5*h / (a[ip][iq]);
-            t = 1.0 / (fabs(theta)+sqrt(1.0+theta*theta));
-            if (theta < 0.0)
-              {
-              t = -t;
-              }
-            }
-          c = 1.0 / sqrt(1+t*t);
-          s = t*c;
-          tau = s/(1.0+c);
-          h = t*a[ip][iq];
-          z[ip] -= h;
-          z[iq] += h;
-          w[ip] -= h;
-          w[iq] += h;
-          a[ip][iq]=0.0;
-
-          // ip already shifted left by 1 unit
-          for (j = 0;j <= ip-1;j++) 
-            {
-            VTK_ROTATE(a,j,ip,j,iq);
-            }
-          // ip and iq already shifted left by 1 unit
-          for (j = ip+1;j <= iq-1;j++) 
-            {
-            VTK_ROTATE(a,ip,j,j,iq);
-            }
-          // iq already shifted left by 1 unit
-          for (j=iq+1; j<3; j++) 
-            {
-            VTK_ROTATE(a,ip,j,iq,j);
-            }
-          for (j=0; j<3; j++) 
-            {
-            VTK_ROTATE(v,j,ip,j,iq);
-            }
-          }
-        }
-      }
-
-    for (ip=0; ip<3; ip++) 
-      {
-      b[ip] += z[ip];
-      w[ip] = b[ip];
-      z[ip] = 0.0;
-      }
-    }
-
-  //// this is NEVER called
-  if ( i >= MAX_ROTATIONS )
-    {
-      std::cerr << "MBMatrix3D: Error extracting eigenfunctions" << std::endl;
-      return MB_FAILURE;
-    }
-
-  // sort eigenfunctions                 these changes do not affect accuracy 
-  for (j=0; j<2; j++)                  // boundary incorrect
-    {
-    k = j;
-    tmp = w[k];
-    for (i=j+1; i<3; i++)                // boundary incorrect, shifted already
-      {
-      if (w[i] >= tmp)                   // why exchage if same?
-        {
-        k = i;
-        tmp = w[k];
-        }
-      }
-    if (k != j) 
-      {
-      w[k] = w[j];
-      w[j] = tmp;
-      for (i=0; i<3; i++) 
-        {
-        tmp = v[i][j];
-        v[i][j] = v[i][k];
-        v[i][k] = tmp;
-        }
-      }
-    }
-  // insure eigenvector consistency (i.e., Jacobi can compute vectors that
-  // are negative of one another (.707,.707,0) and (-.707,-.707,0). This can
-  // reek havoc in hyperstreamline/other stuff. We will select the most
-  // positive eigenvector.
-  int ceil_half_n = (3 >> 1) + (3 & 1);
-  for (j=0; j<3; j++)
-    {
-    for (numPos=0, i=0; i<3; i++)
-      {
-      if ( v[i][j] >= 0.0 )
-        {
-        numPos++;
-        }
-      }
-//    if ( numPos < ceil(double(n)/double(2.0)) )
-    if ( numPos < ceil_half_n)
-      {
-      for(i=0; i<3; i++)
-        {
-        v[i][j] *= -1.0;
-        }
-      }
-    }
-
-  return MB_SUCCESS;
-}
-
-
-std::ostream& operator<<( std::ostream& s, const MBMatrix3& m )
-{
-  return s <<  "| " << m(0,0) << " " << m(0,1) << " " << m(0,2) 
-           << " | " << m(1,0) << " " << m(1,1) << " " << m(1,2) 
-           << " | " << m(2,0) << " " << m(2,1) << " " << m(2,2) 
-           << " |" ;
-}
-

Deleted: MOAB/trunk/src/MBMatrix3.hpp
===================================================================
--- MOAB/trunk/src/MBMatrix3.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBMatrix3.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,285 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBMatrix3.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#ifndef MB_MATRIX_3_HPP
-#define MB_MATRIX_3_HPP
-
-#include "MBCartVect.hpp"
-#include "MBTypes.h"
-#include <iosfwd>
-#include <limits>
-
-#ifdef _MSC_VER
-# define finite _finite
-#endif
-
-class MBMatrix3 
-{
-  double d[9];
-public:
-
-  inline MBMatrix3() 
-    {}
-  
-  inline MBMatrix3( double diagonal )
-    { 
-      d[0] = d[4] = d[8] = diagonal;
-      d[1] = d[2] = d[3] = 0;
-      d[5] = d[6] = d[7] = 0;
-    }
-    
-  inline MBMatrix3( const MBCartVect& diagonal )
-    { 
-      d[0] = diagonal[0];
-      d[4] = diagonal[1],
-      d[8] = diagonal[2];
-      d[1] = d[2] = d[3] = 0;
-      d[5] = d[6] = d[7] = 0;
-    }
-  
-  
-  inline MBMatrix3( const MBCartVect& row0,
-                    const MBCartVect& row1,
-                    const MBCartVect& row2 )
-    {
-      row0.get( d );
-      row1.get( d+3 );
-      row2.get( d+6 );
-    }
-  
-  inline MBMatrix3( const double* v )
-    { 
-      d[0] = v[0]; d[1] = v[1]; d[2] = v[2];
-      d[3] = v[3]; d[4] = v[4]; d[5] = v[5]; 
-      d[6] = v[6]; d[7] = v[7]; d[8] = v[8];
-    }
-  
-  inline MBMatrix3( double v00, double v01, double v02,
-                    double v10, double v11, double v12,
-                    double v20, double v21, double v22 )
-    {
-      d[0] = v00; d[1] = v01; d[2] = v02;
-      d[3] = v10; d[4] = v11; d[5] = v12;
-      d[6] = v20; d[7] = v21; d[8] = v22;
-    }
-  
-  inline MBMatrix3( const MBMatrix3& m )
-    {
-      d[0] = m.d[0]; d[1] = m.d[1]; d[2] = m.d[2];
-      d[3] = m.d[3]; d[4] = m.d[4]; d[5] = m.d[5];
-      d[6] = m.d[6]; d[7] = m.d[7]; d[8] = m.d[8];
-    }
-   
-  inline MBMatrix3& operator=( const MBMatrix3& m )
-    {
-      d[0] = m.d[0]; d[1] = m.d[1]; d[2] = m.d[2];
-      d[3] = m.d[3]; d[4] = m.d[4]; d[5] = m.d[5];
-      d[6] = m.d[6]; d[7] = m.d[7]; d[8] = m.d[8];
-      return *this;
-    }
-  
-  inline MBMatrix3& operator=( const double* v )
-    { 
-      d[0] = v[0]; d[1] = v[1]; d[2] = v[2];
-      d[3] = v[3]; d[4] = v[4]; d[5] = v[5]; 
-      d[6] = v[6]; d[7] = v[7]; d[8] = v[8];
-      return *this;
-    }
-
-  inline double* operator[]( unsigned i )
-    { return d + 3*i; }
-  inline const double* operator[]( unsigned i ) const
-    { return d + 3*i; }
-  inline double& operator()(unsigned r, unsigned c)
-    { return d[3*r+c]; }
-  inline double operator()(unsigned r, unsigned c) const
-    { return d[3*r+c]; }
-  
-  inline MBMatrix3& operator+=( const MBMatrix3& m )
-    {
-      d[0] += m.d[0]; d[1] += m.d[1]; d[2] += m.d[2];
-      d[3] += m.d[3]; d[4] += m.d[4]; d[5] += m.d[5];
-      d[6] += m.d[6]; d[7] += m.d[7]; d[8] += m.d[8];
-      return *this;
-    }
-  
-  inline MBMatrix3& operator-=( const MBMatrix3& m )
-    {
-      d[0] -= m.d[0]; d[1] -= m.d[1]; d[2] -= m.d[2];
-      d[3] -= m.d[3]; d[4] -= m.d[4]; d[5] -= m.d[5];
-      d[6] -= m.d[6]; d[7] -= m.d[7]; d[8] -= m.d[8];
-      return *this;
-    }
-  
-  inline MBMatrix3& operator*=( double s )
-    {
-      d[0] *= s; d[1] *= s; d[2] *= s;
-      d[3] *= s; d[4] *= s; d[5] *= s;
-      d[6] *= s; d[7] *= s; d[8] *= s;
-      return *this;
-    }
-  
-  inline MBMatrix3& operator/=( double s )
-    {
-      d[0] /= s; d[1] /= s; d[2] /= s;
-      d[3] /= s; d[4] /= s; d[5] /= s;
-      d[6] /= s; d[7] /= s; d[8] /= s;
-      return *this;
-    }
-  
-  inline MBMatrix3& operator*=( const MBMatrix3& m );
-  
-  inline double determinant() const;
-  
-  inline MBMatrix3 inverse() const;
-  
-    // invert matrix without re-calculating the
-    // reciprocal of the determinant.
-  inline MBMatrix3 inverse( double inverse_det ) const;
-  
-  inline bool positive_definite() const;
-  inline bool positive_definite( double& determinant_out ) const;
-  
-  inline MBMatrix3 transpose() const;
-  
-  inline bool invert();
-  
-    // Calculate determinant of 2x2 submatrix composed of the
-    // elements not in the passed row or column.
-  inline double subdet( int r, int c ) const;
-};
-
-inline MBMatrix3 operator+( const MBMatrix3& a, const MBMatrix3& b )
-  { return MBMatrix3(a) += b; }
-
-inline MBMatrix3 operator-( const MBMatrix3& a, const MBMatrix3& b )
-  { return MBMatrix3(a) -= b; }
-
-inline MBMatrix3 operator*( const MBMatrix3& a, const MBMatrix3& b )
-{
-  return MBMatrix3( a(0,0) * b(0,0) + a(0,1) * b(1,0) + a(0,2) * b(2,0),
-                    a(0,0) * b(0,1) + a(0,1) * b(1,1) + a(0,2) * b(2,1),
-                    a(0,0) * b(0,2) + a(0,1) * b(1,2) + a(0,2) * b(2,2),
-                    a(1,0) * b(0,0) + a(1,1) * b(1,0) + a(1,2) * b(2,0),
-                    a(1,0) * b(0,1) + a(1,1) * b(1,1) + a(1,2) * b(2,1),
-                    a(1,0) * b(0,2) + a(1,1) * b(1,2) + a(1,2) * b(2,2),
-                    a(2,0) * b(0,0) + a(2,1) * b(1,0) + a(2,2) * b(2,0),
-                    a(2,0) * b(0,1) + a(2,1) * b(1,1) + a(2,2) * b(2,1),
-                    a(2,0) * b(0,2) + a(2,1) * b(1,2) + a(2,2) * b(2,2) );
-}
-
-inline MBMatrix3& MBMatrix3::operator*=( const MBMatrix3& m )
-  { return *this = MBMatrix3(*this) * m; }
-
-inline MBMatrix3 outer_product( const MBCartVect& u,
-                                const MBCartVect& v )
-{
-  return MBMatrix3( u[0] * v[0], u[0] * v[1], u[0] * v[2],
-                    u[1] * v[0], u[1] * v[1], u[1] * v[2],
-                    u[2] * v[0], u[2] * v[1], u[2] * v[2] );
-}
-
-inline MBCartVect operator*( const MBCartVect& v, const MBMatrix3& m )
-{
-  return MBCartVect( v[0] * m(0,0) + v[1] * m(1,0) + v[2] * m(2,0),
-                     v[0] * m(0,1) + v[1] * m(1,1) + v[2] * m(2,1),
-                     v[0] * m(0,2) + v[1] * m(1,2) + v[2] * m(2,2) );
-}
-
-inline MBCartVect operator*( const MBMatrix3& m, const MBCartVect& v )
-{
-  return MBCartVect( v[0] * m(0,0) + v[1] * m(0,1) + v[2] * m(0,2),
-                     v[0] * m(1,0) + v[1] * m(1,1) + v[2] * m(1,2),
-                     v[0] * m(2,0) + v[1] * m(2,1) + v[2] * m(2,2) );
-} 
-
-inline double MBMatrix3::determinant() const
-{
-  return d[0] * d[4] * d[8] 
-       + d[1] * d[5] * d[6]
-       + d[2] * d[3] * d[7]
-       - d[0] * d[5] * d[7]
-       - d[1] * d[3] * d[8]
-       - d[2] * d[4] * d[6];
-}
-
-inline bool MBMatrix3::positive_definite( double& det ) const
-{
-  double subdet6 = d[1]*d[5]-d[2]*d[4];
-  double subdet7 = d[2]*d[3]-d[0]*d[5];
-  double subdet8 = d[0]*d[4]-d[1]*d[3];
-  det = d[6]*subdet6 + d[7]*subdet7 + d[8]*subdet8;
-  return d[0] > 0 && subdet8 > 0 && det > 0;
-}
-
-inline bool MBMatrix3::positive_definite() const
-{
-  double d;
-  return positive_definite(d);
-}
-
-inline MBMatrix3 MBMatrix3::inverse( double i ) const
-{
-  return MBMatrix3( i * (d[4] * d[8] - d[5] * d[7]),
-                    i * (d[2] * d[7] - d[8] * d[1]),
-                    i * (d[1] * d[5] - d[4] * d[2]),
-                    i * (d[5] * d[6] - d[8] * d[3]),
-                    i * (d[0] * d[8] - d[6] * d[2]),
-                    i * (d[2] * d[3] - d[5] * d[0]),
-                    i * (d[3] * d[7] - d[6] * d[4]),
-                    i * (d[1] * d[6] - d[7] * d[0]),
-                    i * (d[0] * d[4] - d[3] * d[1]) );
-}  
-
-inline MBMatrix3 MBMatrix3::inverse() const
-{
-  return inverse( 1.0 / determinant() );
-}
-
-inline bool MBMatrix3::invert()
-{
-  double i = 1.0 / determinant();
-  if (!finite(i) || fabs(i) < std::numeric_limits<double>::epsilon())
-    return false;
-  *this = inverse( i );
-  return true;
-}
-
-inline MBMatrix3 MBMatrix3::transpose() const
-{
-  return MBMatrix3( d[0], d[3], d[6],
-                    d[1], d[4], d[7],
-                    d[2], d[5], d[8] );
-}
-
-inline double MBMatrix3::subdet( int r, int c ) const
-{
-  const int r1 = (r+1)%3, r2 = (r+2)%3;
-  const int c1 = (c+1)%3, c2 = (c+2)%3;
-  return d[3*r1+c1]*d[3*r2+c2] - d[3*r1+c2]*d[3*r2+c1];
-}
-                         
-MBErrorCode EigenDecomp( const MBMatrix3& a, 
-                         double Eigenvalues[3],
-                         MBCartVect Eigenvectors[3] );
-
-std::ostream& operator<<( std::ostream&, const MBMatrix3& );
-
-#endif

Deleted: MOAB/trunk/src/MBMeshSet.cpp
===================================================================
--- MOAB/trunk/src/MBMeshSet.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBMeshSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1127 +0,0 @@
-#ifdef WIN32
-#ifdef _DEBUG
-// turn off warnings that say they debugging identifier has been truncated
-// this warning comes up when using some STL containers
-#pragma warning(disable : 4786)
-#endif
-#endif
-
-#include "MBMeshSet.hpp"
-#include "AEntityFactory.hpp"
-
-
-/*****************************************************************************************
- *                          Helper Function Declarations                                 *
- *****************************************************************************************/
-
-/**\brief Insert into parent/child list */
-static inline 
-MBMeshSet::Count insert_in_vector( const MBMeshSet::Count count, 
-                                   MBMeshSet::CompactList& list,
-                                   const MBEntityHandle h,
-                                   int &result );
-
-/**\brief Remvoe from parent/child list */
-static inline
-MBMeshSet::Count remove_from_vector( const MBMeshSet::Count count, 
-                                     MBMeshSet::CompactList& list,
-                                     const MBEntityHandle h,
-                                     int &result );
-
-
-/**\brief Resize MBMeshSet::CompactList.  Returns pointer to storage */
-static MBEntityHandle* resize_compact_list( MBMeshSet::Count& count,
-                                            MBMeshSet::CompactList& clist,
-                                            size_t new_list_size );
-/**\brief Methods to insert/remove range-based data from contents list.
- *        Templatized to operate on both MBRange and set-based MBMeshSets.
- */
-template <typename pair_iter_t> class range_tool
-{
-public:
-  /** Insert range-based data into range-based MBMeshSet */
-  inline static MBErrorCode ranged_insert_entities( MBMeshSet::Count& count, 
-                                                    MBMeshSet::CompactList& clist, 
-                                                    pair_iter_t begin, 
-                                                    pair_iter_t end, 
-                                                    MBEntityHandle my_handle, 
-                                                    AEntityFactory* adj );
-  
-  /** Remove range-based data from range-based MBMeshSet */
-  inline static MBErrorCode ranged_remove_entities( MBMeshSet::Count& count, 
-                                                    MBMeshSet::CompactList& clist, 
-                                                    pair_iter_t begin, 
-                                                    pair_iter_t end, 
-                                                    MBEntityHandle my_handle, 
-                                                    AEntityFactory* adj );
-
-  /** Insert range-based data into list-based MBMeshSet */
-  inline static MBErrorCode vector_insert_entities( MBMeshSet::Count& count, 
-                                                    MBMeshSet::CompactList& clist, 
-                                                    pair_iter_t begin, 
-                                                    pair_iter_t end, 
-                                                    MBEntityHandle my_handle, 
-                                                    AEntityFactory* adj );
-};
-
-/** Remove MBRange of handles fromr vector-based MBMeshSet */
-static MBErrorCode vector_remove_range( MBMeshSet::Count& count, 
-                                        MBMeshSet::CompactList& clist, 
-                                        const MBRange& range, 
-                                        MBEntityHandle my_handle, 
-                                        AEntityFactory* adj );
-
-/** Remove range-based MBMeshSet contents from vector-based MBMeshSet */
-static MBErrorCode vector_remove_ranges( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* pair_list,
-                                         size_t num_pairs,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj );
-
-/** Remove unsorted array of handles from vector-based MBMeshSet */
-static MBErrorCode vector_remove_vector( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* vect,
-                                         size_t vect_size,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj );
-
-/** Insert unsorted array of handles into vector-based MBMeshSet */
-static MBErrorCode vector_insert_vector( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* vect,
-                                         size_t vect_size,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj );
-
-/** Convert unsorted array of handles into array of ranged [begin,end] pairs */
-static void convert_to_ranges( const MBEntityHandle* vect_in, size_t vect_in_len,
-                               std::vector<MBEntityHandle>& vect_out );
-
-
-/*****************************************************************************************
- *                             Parent/Child Operations                                   *
- *****************************************************************************************/
-
-static inline 
-MBMeshSet::Count insert_in_vector( const MBMeshSet::Count count, 
-                                MBMeshSet::CompactList& list,
-                                const MBEntityHandle h,
-                                int &result )
-{
-  switch (count) {
-    case MBMeshSet::ZERO:
-      list.hnd[0] = h;
-      result = true;
-      return MBMeshSet::ONE;
-    case MBMeshSet::ONE:
-      if (list.hnd[0] == h) {
-        result = false;
-        return MBMeshSet::ONE;
-      }
-      else {
-        result = true;
-        list.hnd[1] = h;
-        return MBMeshSet::TWO;
-      }
-    case MBMeshSet::TWO:
-      if (list.hnd[0] == h || list.hnd[1] == h) {
-        result = false;
-        return MBMeshSet::TWO;
-      }
-      else {
-        MBEntityHandle* ptr = (MBEntityHandle*)malloc(3*sizeof(MBEntityHandle));
-        ptr[0] = list.hnd[0];
-        ptr[1] = list.hnd[1];
-        ptr[2] = h;
-        list.ptr[0] = ptr;
-        list.ptr[1] = ptr + 3;
-        result = true;
-        return MBMeshSet::MANY;
-      }
-    case MBMeshSet::MANY:
-      if (std::find( list.ptr[0], list.ptr[1], h ) != list.ptr[1]) {
-        result = false;
-      }
-      else {
-        int size = list.ptr[1] - list.ptr[0];
-        list.ptr[0] = (MBEntityHandle*)realloc( list.ptr[0], (size+1)*sizeof(MBEntityHandle) );
-        list.ptr[0][size] = h;
-        list.ptr[1] = list.ptr[0] + size + 1;
-        result = true;
-      }
-      return MBMeshSet::MANY;
-  }
-
-  return MBMeshSet::ZERO;
-}
-
-static inline
-MBMeshSet::Count remove_from_vector( const MBMeshSet::Count count, 
-                                  MBMeshSet::CompactList& list,
-                                  const MBEntityHandle h,
-                                  int &result )
-{
-  switch (count) {
-    case MBMeshSet::ZERO:
-      result = false;
-      return MBMeshSet::ZERO;
-    case MBMeshSet::ONE:
-      if (h == list.hnd[0]) {
-        result = true;
-        return MBMeshSet::ZERO;
-      }
-      else {
-        result = false;
-        return MBMeshSet::ONE;
-      }
-    case MBMeshSet::TWO:
-      if (h == list.hnd[0]) {
-        list.hnd[0] = list.hnd[1];
-        result = true;
-        return MBMeshSet::ONE;
-      } 
-      else if (h == list.hnd[1]) {
-        result = true;
-        return MBMeshSet::ONE;
-      }
-      else {
-        result = false;
-        return MBMeshSet::TWO;
-      }
-    case MBMeshSet::MANY: {
-      MBEntityHandle *i, *j, *p;
-      i = std::find( list.ptr[0], list.ptr[1], h );
-      if (i == list.ptr[1]) {
-        result = false;
-        return MBMeshSet::MANY;
-      }
-      
-      result = true;
-      p = list.ptr[1] - 1;
-      while (i != p) {
-        j = i + 1;
-        *i = *j;
-        i = j;
-      }
-      int size = p - list.ptr[0];
-      if (size == 2) {
-        p = list.ptr[0];
-        list.hnd[0] = p[0];
-        list.hnd[1] = p[1];
-        free( p );
-        return MBMeshSet::TWO;
-      }
-      else {
-        list.ptr[0] = (MBEntityHandle*)realloc( list.ptr[0], size*sizeof(MBEntityHandle) );
-        list.ptr[1] = list.ptr[0] + size;
-        return MBMeshSet::MANY;
-      }
-    }
-  }
-
-  return MBMeshSet::ZERO;
-}
-
-
-int MBMeshSet::add_parent( MBEntityHandle parent )
-{ 
-  int result = 0;
-  mParentCount = insert_in_vector( (Count)mParentCount, parentMeshSets, parent, result );
-  return result;
-}
-int MBMeshSet::add_child( MBEntityHandle child )
-{ 
-  int result = 0;
-  mChildCount = insert_in_vector( (Count)mChildCount, childMeshSets, child, result );
-  return result;
-}
-
-int MBMeshSet::remove_parent( MBEntityHandle parent )
-{ 
-  int result = 0;
-  mParentCount = remove_from_vector( (Count)mParentCount, parentMeshSets, parent, result );
-  return result;
-}
-int MBMeshSet::remove_child( MBEntityHandle child )
-{ 
-  int result = 0;
-  mChildCount = remove_from_vector( (Count)mChildCount, childMeshSets, child, result );
-  return result;
-}
-
-
-/*****************************************************************************************
- *                          Flag Conversion Operations                                   *
- *****************************************************************************************/
-
-MBErrorCode MBMeshSet::convert( unsigned flags, MBEntityHandle my_handle, AEntityFactory* adj )
-{
-  MBErrorCode rval = MB_SUCCESS;
-  if ((mFlags & MESHSET_TRACK_OWNER) && !(flags & MESHSET_TRACK_OWNER))
-    rval = remove_adjacencies( my_handle, adj );
-  else if (!(mFlags & MESHSET_TRACK_OWNER) && (flags & MESHSET_TRACK_OWNER))
-    rval = create_adjacencies( my_handle, adj );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-  if (!(mFlags & MESHSET_ORDERED) && (flags & MESHSET_ORDERED)) {
-    size_t datalen;
-    MBEntityHandle* data = get_contents(datalen);
-    if (datalen) {
-      std::vector<MBEntityHandle> list( datalen );
-      memcpy( &list[0], data, datalen*sizeof(MBEntityHandle) );
-      int num_ents = num_entities();
-      Count count = (Count)mContentCount;
-      data = resize_compact_list( count, contentList, num_ents );
-      mContentCount = count;
-      assert( list.size() % 2 == 0 );
-      std::vector<MBEntityHandle>::iterator i = list.begin();
-      while (i != list.end()) {
-        MBEntityHandle h = *i; ++i;
-        MBEntityHandle e = *i; ++i;
-        for (; h <= e; ++h) {
-          *data = h; 
-          ++data;
-        }
-      }
-    }
-  }
-  else if ((mFlags & MESHSET_ORDERED) && !(flags & MESHSET_ORDERED)) {
-    size_t datalen;
-    MBEntityHandle* data = get_contents(datalen);
-    if (datalen) {
-      std::vector<MBEntityHandle> ranges;
-      convert_to_ranges( data, datalen, ranges );
-      Count count = (Count)mContentCount;
-      data = resize_compact_list( count, contentList, ranges.size() );
-      mContentCount = count;
-      memcpy( data, &ranges[0], ranges.size()*sizeof(MBEntityHandle) );
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBMeshSet::create_adjacencies( MBEntityHandle my_handle, AEntityFactory* adj )
-{
-  MBErrorCode rval = MB_SUCCESS;;
-  size_t count;
-  const MBEntityHandle *const ptr = get_contents( count );
-  const MBEntityHandle *const end = ptr + count;
-  if (vector_based()) {
-    for (const MBEntityHandle* i = ptr; i != end; ++i) {
-      rval = adj->add_adjacency( *i, my_handle, false );
-      if (MB_SUCCESS != rval) {
-        for (const MBEntityHandle* j = ptr; j != i; ++j) 
-          adj->remove_adjacency( *j, my_handle );
-        return rval;
-      }
-    }
-  }
-  else {
-    assert( 0 == count % 2 );
-    for (const MBEntityHandle* i = ptr; i != end; i += 2) {
-      for (MBEntityHandle h = i[0]; h <= i[1]; ++h) {
-        rval = adj->add_adjacency( h, my_handle, false );
-        if (MB_SUCCESS != rval) {
-          for (MBEntityHandle j = i[0]; j < h; ++j)
-            adj->remove_adjacency( j, my_handle );
-          for (const MBEntityHandle* j = ptr; j != i; j += 2)
-            for (MBEntityHandle k = j[0]; k <= j[1]; ++k)
-              adj->remove_adjacency( k, my_handle );
-          return rval;
-        }
-      }
-    }
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBMeshSet::remove_adjacencies( MBEntityHandle my_handle, AEntityFactory* adj )
-{
-  size_t count;
-  const MBEntityHandle *const ptr = get_contents( count );
-  const MBEntityHandle *const end = ptr + count;
-  if (vector_based()) {
-    for (const MBEntityHandle* i = ptr; i != end; ++i)
-      adj->remove_adjacency( *i, my_handle );
-  }
-  else {
-    assert( 0 == count % 2 );
-    for (const MBEntityHandle* i = ptr; i != end; i += 2)
-      for (MBEntityHandle h = i[0]; h <= i[1]; ++h)
-        adj->remove_adjacency( h, my_handle );
-  }
-  return MB_SUCCESS;
-}
-
-
-/*****************************************************************************************
- *                          Contents Modifiction Methods                                 *
- *****************************************************************************************/
-
-static MBEntityHandle* resize_compact_list( MBMeshSet::Count& count,
-                                            MBMeshSet::CompactList& clist,
-                                            size_t new_list_size )
-{
-  if (count <= 2) {
-    if (new_list_size <= 2) {
-      count = (MBMeshSet::Count)new_list_size;
-      return clist.hnd;
-    }
-    else {
-      MBEntityHandle* list = (MBEntityHandle*)malloc( new_list_size*sizeof(MBEntityHandle) );
-      list[0] = clist.hnd[0];
-      list[1] = clist.hnd[1];
-      clist.ptr[0] = list;
-      clist.ptr[1] = list + new_list_size;
-      count = MBMeshSet::MANY;
-      return list;
-    }
-  }
-  else if (new_list_size > 2) {
-    if (new_list_size > (size_t)(clist.ptr[1] - clist.ptr[0]))
-      clist.ptr[0] = (MBEntityHandle*)realloc( clist.ptr[0], new_list_size*sizeof(MBEntityHandle) );
-    clist.ptr[1] = clist.ptr[0] + new_list_size;
-    count = MBMeshSet::MANY;
-    return clist.ptr[0];
-  }
-  else {
-    MBEntityHandle* list = clist.ptr[0];
-    clist.hnd[0] = list[0];
-    clist.hnd[1] = list[1];
-    free(list);
-    count = (MBMeshSet::Count)new_list_size;
-    return clist.hnd;
-  }
-}
-
-template <typename pair_iter_t> inline MBErrorCode
-range_tool<pair_iter_t>::ranged_insert_entities( MBMeshSet::Count& count, 
-                                                 MBMeshSet::CompactList& clist, 
-                                                 pair_iter_t begin, 
-                                                 pair_iter_t end, 
-                                                 MBEntityHandle my_handle, 
-                                                 AEntityFactory* adj )
-{
-    //first pass:
-    // 1) merge existing ranges 
-    // 2) count number of new ranges that must be inserted
-  ptrdiff_t insert_count = 0;
-  MBEntityHandle *list;
-  size_t list_size;
-  if (count < MBMeshSet::MANY) {
-    list = clist.hnd;
-    list_size = count;
-  }
-  else {
-    list = clist.ptr[0];
-    list_size = clist.ptr[1] - clist.ptr[0];
-  }
-
-  MBEntityHandle* list_write = list;
-  MBEntityHandle *const list_end = list + list_size, *list_read = list;
-  pair_iter_t i = begin;
-  
-  while(i != end) {
-    
-      // if there are holes in the current array, shuffle blocks 
-      // down until we find the next block to merge with or insert before
-    if (list_read != list_write) {
-      while (list_read != list_end && i->second + 1 < list_read[0]) {
-      	list_write[0] = list_read[0];
-        list_write[1] = list_read[1];
-        list_write += 2;
-        list_read += 2;
-      }
-    }
-      // otherwise do a binary search
-    else {
-      list_write = std::lower_bound( list_write, list_end, i->first - 1 );
-      	// if in middle of range block (odd index), back up to start of block
-      list_write -= (list_write - list)%2;
-      list_read = list_write;
-    }
-    
-      // handle any straight insertions of range blocks
-    for ( ; i != end && (list_read == list_end || i->second+1 < list_read[0]); ++i) {
-        // If we haven't removed any range pairs, we don't have space to
-        // insert here.  Defer the insertion until later.
-      if (list_read == list_write) {
-        ++insert_count;
-      }
-      else {
-        if (adj) 
-          for (MBEntityHandle j = i->first; j <= i->second; ++j)
-            adj->add_adjacency( j, my_handle, false );
-
-        list_write[0] = i->first;
-        list_write[1] = i->second;
-        list_write += 2;
-      }
-    }
-    if (i == end)
-      break;
-    
-      // check if we need to prepend to the current range block
-    if (i->first >= list_read[0]) 
-      list_write[0] = list_read[0];
-    else {
-      if (adj)
-        for (MBEntityHandle h = i->first; h < list_read[0]; ++h)
-          adj->add_adjacency( h, my_handle, false );
-      list_write[0] = i->first;
-    }
-    list_write[1] = list_read[1];
-    list_read += 2;
-    
-      // discard any input blocks already in the set
-    for (; i != end && i->second <= list_write[1]; ++i);
-    if (i == end || i->first > list_write[1]+1) {
-      list_write += 2;
-      continue;
-    }
-    
-      // merge subsequent blocks in meshset
-    for (;list_read != list_end && list_read[0]+1 <= i->second; list_read += 2) {
-      if (adj)
-      	for (MBEntityHandle h = list_write[1]+1; h < list_read[0]; ++h)
-      	  adj->add_adjacency( h, my_handle, false );
-      list_write[1] = list_read[1];
-    }
-    
-      // check if we need to append to current meshset block
-    if (i->second > list_write[1]) {
-      if (adj)
-      	for (MBEntityHandle h = list_write[1]+1; h <= i->second; ++h)
-      	  adj->add_adjacency( h, my_handle, false );
-      list_write[1] = i->second;
-    }
-    
-    ++i;
-    list_write += 2;
-  }
-
-    // shuffle down entries to fill holes
-  if (list_read == list_write) 
-    list_read = list_write = list_end;
-  else while(list_read < list_end) {
-    list_write[0] = list_read[0];
-    list_write[1] = list_read[1];
-    list_read += 2;
-    list_write += 2;
-  }
-
-    // adjust allocated array size
-  const size_t occupied_size = list_write - list;
-  const size_t new_list_size = occupied_size + 2*insert_count;
-  list = resize_compact_list( count, clist, new_list_size );
-    // done?
-  if (!insert_count)
-    return MB_SUCCESS;
-
-    // Second pass: insert non-mergable range pairs
-    // All range pairs in the input are either completely disjoint from
-    // the ones in the mesh set and must be inserted or are entirely contained
-    // within range pair in the mesh set.
-  assert( begin != end ); // can't have items to insert if given empty input list
-  pair_iter_t ri = end; --ri;
-  list_write = list + new_list_size - 2;
-  list_read = list + occupied_size - 2;
-  for ( ; list_write >= list; list_write -= 2 ) {
-    if (list_read >= list) {
-      while (ri->first >= list_read[0] && ri->second <= list_read[1]) {
-        assert(ri != begin);
-        --ri;
-      }
-    
-      if (list_read[0] > ri->second) {
-        list_write[0] = list_read[0];
-        list_write[1] = list_read[1];
-        list_read -= 2;
-        continue;
-      }
-    }
-    
-    assert( insert_count > 0 );
-    if (adj) 
-      for (MBEntityHandle j = ri->first; j <= ri->second; ++j) 
-        adj->add_adjacency( j, my_handle, false );
-    list_write[0] = ri->first;
-    list_write[1] = ri->second;
-
-      // don't have reverse iterator, so check before decrement
-      // if insert_count isn't zero, must be more in range
-    if (0 == --insert_count) {
-      assert( list_read == list_write-2 );
-      break;
-    }
-    else {
-      --ri;
-    }
-  }
-
-  assert(!insert_count);
-  return MB_SUCCESS;
-}
-  
-template <typename pair_iter_t> inline MBErrorCode
-range_tool<pair_iter_t>::ranged_remove_entities( MBMeshSet::Count& count, 
-                                                 MBMeshSet::CompactList& clist, 
-                                                 pair_iter_t begin, 
-                                                 pair_iter_t end, 
-                                                 MBEntityHandle my_handle, 
-                                                 AEntityFactory* adj )
-{
-    //first pass:
-    // 1) remove (from) existing ranges 
-    // 2) count number of ranges that must be split
-  ptrdiff_t split_count = 0;
-  MBEntityHandle *list;
-  size_t list_size;
-  if (count < MBMeshSet::MANY) {
-    list = clist.hnd;
-    list_size = count;
-  }
-  else {
-    list = clist.ptr[0];
-    list_size = clist.ptr[1] - clist.ptr[0];
-  }
-
-  MBEntityHandle* list_write = list;
-  MBEntityHandle *const list_end = list + list_size, *list_read = list;
-  pair_iter_t i = begin;
-  
-  while(list_read != list_end && i != end) {
-    
-    while (i != end && i->second < list_read[0])
-      ++i;
-    if (i == end)
-      break;
-    
-      // if there are holes in the current array, shuffle blocks 
-      // down until we find the next block to remove
-    if (list_read != list_write) {
-      while (list_read != list_end && i->second < list_read[0]) {
-      	list_write[0] = list_read[0];
-        list_write[1] = list_read[1];
-        list_write += 2;
-        list_read += 2;
-      }
-    }
-      // otherwise do a binary search
-    else {
-      list_write = std::lower_bound( list_write, list_end, i->first );
-      	// if in middle of range block (odd index), back up to start of block
-      list_write -= (list_write - list)%2;
-      list_read = list_write;
-    }
-    
-      // if everything remaning is past end of set contents...
-    if (list_read == list_end) 
-      break;
-      
-      // skip any remove pairs that aren't in the list
-    if (i->second < list_read[0]) {
-      ++i;
-      continue;
-    }
-    
-      // Begin by assuming that we will keep the entire block
-    list_write[0] = list_read[0];
-    list_write[1] = list_read[1];
-    list_read += 2;
-    
-    for (; i != end && i->first <= list_write[1]; ++i) {
-      if (i->first <= list_write[0]) {
-          // remove whole block
-        if (i->second >= list_write[1]) {
-          if (adj)
-            for (MBEntityHandle h = list_write[0]; h <= list_write[1]; ++h)
-              adj->remove_adjacency( h, my_handle );
-          list_write -= 2;
-          break;
-        }
-          // remove from start of block
-        else if (i->second >= list_write[0]) {
-          if (adj)
-            for (MBEntityHandle h = list_write[0]; h <= i->second; ++h)
-              adj->remove_adjacency( h, my_handle );
-          list_write[0] = i->second + 1;
-        }
-      }
-      else if (i->first <= list_write[1]) {
-          // remove from end of block
-        if (i->second >= list_write[1]) {
-          if (adj)
-            for (MBEntityHandle h = i->first; h <= list_write[1]; ++h)
-              adj->remove_adjacency( h, my_handle );
-          list_write[1] = i->first - 1;
-          //list_write += 2;
-          break;
-        }
-          // split block
-        else {
-          if (adj)
-            for (MBEntityHandle h = i->first; h <= i->second; ++h)
-              adj->remove_adjacency( h, my_handle );
-
-          if (list_read - list_write <= 2) {
-            ++split_count;
-            continue;
-          }
-          else {
-            list_write[3] = list_write[1];
-            list_write[1] = i->first - 1;
-            list_write[2] = i->second + 1;
-            list_write += 2;
-          }
-        }
-      }
-    }
-    list_write += 2;
-  }
-
-    // shuffle down entries to fill holes
-  if (list_read == list_write) 
-    list_read = list_write = list_end;
-  else 
-    while(list_read < list_end) {
-      list_write[0] = list_read[0];
-      list_write[1] = list_read[1];
-      list_read += 2;
-      list_write += 2;
-    }
-
-    // adjust allocated array size
-  const size_t occupied_size = list_write - list;
-  const size_t new_list_size = occupied_size + 2*split_count;
-  list = resize_compact_list( count, clist, new_list_size );
-    // done?
-  if (!split_count)
-    return MB_SUCCESS;
-
-    // Second pass: split range pairs
-    // All range pairs in the input are either already removed or
-    // require one of the existing range pairs to be split
-  assert( begin != end ); // can't have ranges to split if given empty input list
-  pair_iter_t ri = end; --ri;
-  list_write = list + new_list_size - 2;
-  list_read = list + occupied_size - 2;
-  for ( ; list_write >= list; list_write -= 2 ) {
-    if (list_read >= list) {
-      while (ri->second > list_read[1]) {
-        assert(ri != begin);
-        --ri;
-      }
-    
-      if (list_read[0] > ri->second) {
-        list_write[0] = list_read[0];
-        list_write[1] = list_read[1];
-        list_read -= 2;
-        continue;
-      }
-    }
-    
-    assert( split_count > 0 );
-    list_write[0] = ri->second + 1;
-    list_write[1] = list_read[1];
-    list_read[1] = ri->first - 1;
-
-      // don't have reverse iterator, so check before decrement
-      // if insert_count isn't zero, must be more in range
-    if (0 == --split_count) {
-      assert( list_read == list_write-2 );
-      break;
-    }
-    else {
-      --ri;
-    }
-  }
-
-  assert(!split_count);
-  return MB_SUCCESS;
-}
-
-
-template <typename pair_iter_t> inline MBErrorCode
-range_tool<pair_iter_t>::vector_insert_entities( MBMeshSet::Count& count, 
-                                                 MBMeshSet::CompactList& clist, 
-                                                 pair_iter_t begin, 
-                                                 pair_iter_t end, 
-                                                 MBEntityHandle my_handle, 
-                                                 AEntityFactory* adj )
-{
-  const size_t init_size = count < MBMeshSet::MANY ? count : clist.ptr[1] - clist.ptr[0];
-  size_t add_size = 0;
-  for (pair_iter_t i = begin; i != end; ++i)
-    add_size += i->second - i->first + 1;
-  MBEntityHandle* list = resize_compact_list( count, clist, init_size + add_size );
-  MBEntityHandle* li = list + init_size;
-
-  for (pair_iter_t i = begin; i != end; ++i) {
-    for (MBEntityHandle h = i->first; h <= i->second; ++h) {
-      if (adj)
-        adj->add_adjacency( h, my_handle, false );
-      *li = h;
-      ++li;
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-static MBErrorCode vector_remove_range( MBMeshSet::Count& count, 
-                                        MBMeshSet::CompactList& clist, 
-                                        const MBRange& range, 
-                                        MBEntityHandle my_handle, 
-                                        AEntityFactory* adj )
-{
-  MBEntityHandle *list;
-  size_t list_size;
-  if (count < MBMeshSet::MANY) {
-    list = clist.hnd;
-    list_size = count;
-  }
-  else {
-    list = clist.ptr[0];
-    list_size = clist.ptr[1] - clist.ptr[0];
-  }
-
-  const MBEntityHandle * const list_end = list + list_size;
-  MBEntityHandle* list_write = list;
-  for (const MBEntityHandle* list_read = list; list_read != list_end; ++list_read) {
-    if (range.find(*list_read) == range.end()) { // keep
-      *list_write = *list_read;
-      ++list_write;
-    }
-    else if (adj) {    
-      adj->remove_adjacency( *list_read, my_handle );
-    }
-  }
-
-  resize_compact_list( count, clist, list_write - list );
-  return MB_SUCCESS;
-}
-
-static MBErrorCode vector_remove_ranges( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* pair_list,
-                                         size_t num_pairs,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj )
-{
-  MBEntityHandle *list;
-  size_t list_size;
-  if (count < MBMeshSet::MANY) {
-    list = clist.hnd;
-    list_size = count;
-  }
-  else {
-    list = clist.ptr[0];
-    list_size = clist.ptr[1] - clist.ptr[0];
-  }
-
-  const MBEntityHandle *const list_end = list + list_size, 
-                       *const input_end = pair_list + 2*num_pairs;
-  MBEntityHandle* list_write = list;
-  for (const MBEntityHandle* list_read = list; list_read != list_end; ++list_read) {
-    const MBEntityHandle* ptr = std::lower_bound( pair_list, input_end, *list_read );
-    if ((ptr != input_end && (*ptr == *list_read || (ptr - pair_list)%2)) && // if in delete list
-        std::find(list_read+1, list_end, *list_read) == list_end) { // and is last occurance in list 
-        // only remove adj if no previous occurance
-      if (adj && std::find(list, list_write, *list_read) == list_write)
-        adj->remove_adjacency( *list_read, my_handle );
-    }
-    else {
-      *list_write = *list_read;
-      ++list_write;
-    }
-  }
-
-  resize_compact_list( count, clist, list_write - list );
-  return MB_SUCCESS;
-}
-
-static MBErrorCode vector_remove_vector( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* vect,
-                                         size_t vect_size,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj )
-{
-  MBEntityHandle *list;
-  size_t list_size;
-  if (count < MBMeshSet::MANY) {
-    list = clist.hnd;
-    list_size = count;
-  }
-  else {
-    list = clist.ptr[0];
-    list_size = clist.ptr[1] - clist.ptr[0];
-  }
-
-  const MBEntityHandle *const list_end = list + list_size, 
-                       *const input_end = vect + vect_size;
-  MBEntityHandle* list_write = list;
-  for (const MBEntityHandle* list_read = list; list_read != list_end; ++list_read) {
-    if (std::find(vect, input_end, *list_read) != input_end && // if in delete list
-        std::find(list_read+1, list_end, *list_read) == list_end) { // and is last occurance in list 
-        // only remove adj if no previous occurance?
-      if (adj ) // && std::find(list, list_write, *list_read) == list_write)
-        adj->remove_adjacency( *list_read, my_handle );
-    }
-    else {
-      *list_write = *list_read;
-      ++list_write;
-    }
-  }
-
-  resize_compact_list( count, clist, list_write - list );
-  return MB_SUCCESS;
-}
-
-static MBErrorCode vector_insert_vector( MBMeshSet::Count& count, 
-                                         MBMeshSet::CompactList& clist, 
-                                         const MBEntityHandle* vect,
-                                         size_t vect_size,
-                                         MBEntityHandle my_handle, 
-                                         AEntityFactory* adj )
-{
-  const size_t orig_size = count < MBMeshSet::MANY ? count : clist.ptr[1] - clist.ptr[0];
-  MBEntityHandle* list = resize_compact_list( count, clist, orig_size + vect_size );
-  if (adj) 
-    for (size_t i = 0; i < vect_size; ++i)
-      adj->add_adjacency( vect[i], my_handle, false );
-  memcpy( list+orig_size, vect, sizeof(MBEntityHandle)*vect_size );
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBMeshSet::insert_entity_ranges( const MBEntityHandle* range_vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  typedef const std::pair<MBEntityHandle,MBEntityHandle>* pair_vect_t;
-  pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(range_vect);
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  MBErrorCode rval;
-  if (!vector_based())
-    rval = range_tool<pair_vect_t>::ranged_insert_entities( count, contentList,  pair_vect, 
-                                             pair_vect + len/2, my_h, tracking() ? adj : 0 );
-  else
-    rval = range_tool<pair_vect_t>::vector_insert_entities( count, contentList,  pair_vect, 
-                                             pair_vect + len/2, my_h, tracking() ? adj : 0 );
-  mContentCount = count;
-  return rval;
-}
-
-MBErrorCode MBMeshSet::insert_entity_ranges( const MBRange& range, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  MBErrorCode rval;
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  if (!vector_based())
-    rval = range_tool<MBRange::const_pair_iterator>::ranged_insert_entities( count, 
-                             contentList, range.const_pair_begin(), range.const_pair_end(), 
-                             my_h, tracking() ? adj : 0 );
-  else
-    rval = range_tool<MBRange::const_pair_iterator>::vector_insert_entities( count, 
-                             contentList, range.const_pair_begin(), range.const_pair_end(), 
-                             my_h, tracking() ? adj : 0 );
-  mContentCount = count;
-  return rval;
-}
-
-MBErrorCode MBMeshSet::remove_entity_ranges( const MBEntityHandle* range_vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  MBErrorCode rval;
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  if (vector_based()) 
-    rval = vector_remove_ranges( count, contentList, range_vect, len/2, my_h, 
-                                 tracking() ? adj : 0 );
-  else {
-    typedef const std::pair<MBEntityHandle,MBEntityHandle>* pair_vect_t;
-    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(range_vect);
-    rval = range_tool<pair_vect_t>::ranged_remove_entities( count, contentList, pair_vect, 
-                                           pair_vect + len/2, my_h, tracking() ? adj : 0 );
-  }
-  mContentCount = count;
-  return rval;
-}
-
-MBErrorCode MBMeshSet::remove_entity_ranges( const MBRange& range, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  MBErrorCode rval;
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  if (vector_based()) 
-    rval = vector_remove_range( count, contentList, range, my_h, tracking() ? adj : 0 );
-  else 
-    rval = range_tool<MBRange::const_pair_iterator>::ranged_remove_entities( count, 
-                         contentList, range.const_pair_begin(), range.const_pair_end(), 
-                         my_h, tracking() ? adj : 0 );
-  mContentCount = count;
-  return rval;
-}
-
-
-MBErrorCode MBMeshSet::intersect( const MBMeshSet* other, MBEntityHandle my_handle, AEntityFactory* adj )
-{
-  MBErrorCode rval;
-  if (!vector_based() && !other->vector_based()) {
-    size_t other_count = 0;
-    const MBEntityHandle* other_vect = other->get_contents( other_count );
-    if (!other_count)
-      return clear( my_handle, adj );
-    assert(0 == other_count%2);
-    
-    std::vector<MBEntityHandle> compliment;
-    compliment.reserve( other_count + 4 );
-    if (*other_vect > 0) {
-      compliment.push_back( 0 );
-      compliment.push_back( *other_vect - 1 );
-    }
-    ++other_vect;
-    const MBEntityHandle *const other_end = other_vect + other_count - 2;
-    for (; other_vect < other_end; other_vect += 2) {
-      compliment.push_back( other_vect[0] + 1 );
-      compliment.push_back( other_vect[1] - 1 );
-    }
-    if (*other_vect < ~(MBEntityHandle)0) {
-      compliment.push_back( *other_vect + 1 );
-      compliment.push_back( ~(MBEntityHandle)0 );
-    }
-    
-    return remove_entity_ranges( &compliment[0], compliment.size(), my_handle, adj );
-  }
-  else {
-    MBRange my_ents, other_ents;
-    rval = get_entities(my_ents);
-    if (MB_SUCCESS != rval)
-      return rval;
-    rval = other->get_entities(other_ents);
-    return remove_entities( ::subtract(my_ents, other_ents), my_handle, adj );
-  }
-}
-
-static void convert_to_ranges( const MBEntityHandle* vect_in, size_t vect_in_len,
-                               std::vector<MBEntityHandle>& vect_out )
-{
-  vect_out.reserve( 2*vect_in_len );
-  vect_out.resize( vect_in_len );
-  std::copy( vect_in, vect_in+vect_in_len, vect_out.begin() );
-  std::sort( vect_out.begin(), vect_out.end() );
-  vect_out.erase( std::unique( vect_out.begin(), vect_out.end() ), vect_out.end() );
-
-    // duplicate all entries
-  vect_out.resize( vect_out.size() * 2 );
-  for (long i = vect_out.size() - 1; i >= 0; --i) 
-    vect_out[i] = vect_out[i/2];
-   
-    // compact adjacent ranges
-  std::vector<MBEntityHandle>::iterator r = vect_out.begin(), w = vect_out.begin();
-  while (r != vect_out.end()) {
-    *w = *r;
-    ++w; 
-    ++r;
-    *w = *r;
-    ++r;
-    
-    while (r != vect_out.end() && *w + 1 == *r) {
-      ++r;
-      *w = *r;
-      ++r;
-    }
-    ++w;
-  }
-  
-    // remove extra space
-  vect_out.erase( w, vect_out.end() );
-}
-
-MBErrorCode MBMeshSet::insert_entity_vector( const MBEntityHandle* vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  MBErrorCode rval;
-  if (vector_based())
-    rval = vector_insert_vector( count, contentList, vect, len, my_h, tracking() ? adj : 0 );
-  else {
-    std::vector<MBEntityHandle> rangevect;
-    convert_to_ranges( vect, len, rangevect );
-    typedef const std::pair<MBEntityHandle,MBEntityHandle>* pair_vect_t;
-    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(&rangevect[0]);
-    rval = range_tool<pair_vect_t>::ranged_insert_entities( count, contentList, pair_vect, 
-                                 pair_vect + rangevect.size()/2, my_h, tracking() ? adj : 0 );
-  }
-  mContentCount = count;
-  return rval;
-}
-
-MBErrorCode MBMeshSet::remove_entity_vector( const MBEntityHandle* vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj )
-{
-  MBMeshSet::Count count = static_cast<MBMeshSet::Count>(mContentCount);
-  MBErrorCode rval;
-  if (vector_based())
-    rval = vector_remove_vector( count, contentList, vect, len, my_h, tracking() ? adj : 0 );
-  else {
-    std::vector<MBEntityHandle> rangevect;
-    convert_to_ranges( vect, len, rangevect );
-    typedef const std::pair<MBEntityHandle,MBEntityHandle>* pair_vect_t;
-    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(&rangevect[0]);
-    rval = range_tool<pair_vect_t>::ranged_remove_entities( count, contentList, pair_vect, 
-                                pair_vect + rangevect.size()/2, my_h, tracking() ? adj : 0 );
-  }
-  mContentCount = count;
-  return rval;
-}
-
-
-
-MBErrorCode MBMeshSet::replace_entities( MBEntityHandle my_handle,
-                                         const MBEntityHandle* old_entities,
-                                         const MBEntityHandle* new_entities,
-                                         size_t num_entities,
-                                         AEntityFactory* adjfact )
-{
-  if (vector_based()) {
-    MBErrorCode result = MB_SUCCESS;
-    size_t count;
-    MBEntityHandle* vect = get_contents( count );
-    MBEntityHandle* const vect_end = vect+count;
-    for (size_t i = 0; i < num_entities; ++i) {
-      MBEntityHandle* p = std::find( vect, vect_end, old_entities[i] );
-      if (p == vect_end) {
-        result = MB_ENTITY_NOT_FOUND;
-      }
-      else do {
-        if (tracking()) {
-          adjfact->remove_adjacency( *p, my_handle );
-          adjfact->add_adjacency( new_entities[i], my_handle, false );
-        }
-        *p = new_entities[i];
-        p = std::find( p+1, vect_end, old_entities[i] );
-      } while (p != vect_end);
-    }
-    return result;
-  }
-  else {
-    MBErrorCode r1 = remove_entities( old_entities, num_entities, my_handle, adjfact );
-    MBErrorCode r2 = add_entities( new_entities, num_entities, my_handle, adjfact );
-    return (MB_SUCCESS == r2) ? r1 : r2;
-  }
-}
-
-
-/*****************************************************************************************
- *                                  Misc. Methods                                        *
- *****************************************************************************************/
-
-unsigned long MBMeshSet::get_memory_use() const
-{
-  unsigned long result = 0;
-  if (mParentCount == MANY)
-    result += parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
-  if (mChildCount == MANY)
-    result += childMeshSets.ptr[1] - childMeshSets.ptr[0];
-  if (mContentCount == MANY)
-    result += contentList.ptr[1] - contentList.ptr[0];
-  return sizeof(MBEntityHandle)*result;
-}

Deleted: MOAB/trunk/src/MBMeshSet.hpp
===================================================================
--- MOAB/trunk/src/MBMeshSet.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBMeshSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,795 +0,0 @@
-#ifndef MB_MESHSET_HPP
-#define MB_MESHSET_HPP
-
-#ifndef IS_BUILDING_MB
-#error "MB_MeshSet.hpp isn't supposed to be included into an application"
-#endif
-
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-
-#include <assert.h>
-#include <vector>
-#include <algorithm>
-#include <iterator>
-
-class AEntityFactory;
-
-/** \brief Class to implement entity set functionality 
-  * \author Jason Kraftcheck <kraftche at cae.wisc.edu>
-  */
-class MBMeshSet
-{
-public:
-
-  //! create an empty meshset
-  inline MBMeshSet();
-  inline MBMeshSet(unsigned flags);
-
-  //! destructor
-  inline ~MBMeshSet();
-  
-  inline MBErrorCode set_flags( unsigned flags, MBEntityHandle my_handle, AEntityFactory* adjacencies );
-    
-
-    //! get all children pointed to by this meshset
-  inline const MBEntityHandle* get_children( int& count_out ) const ;
-
-    //! get all parents pointed to by this meshset
-  inline const MBEntityHandle* get_parents( int& count_out ) const;
-
-    //! return the number of children pointed to by this meshset
-  inline int num_children() const ;
-    
-    //! return the number of parents pointed to by this meshset
-  inline int num_parents() const;
-
-    //! add a parent to this meshset; returns true if parent was added, 0 if it was
-    //! already a parent of this meshset
-  int add_parent(MBEntityHandle parent);
-    
-    //! add a child to this meshset; returns true if child was added, 0 if it was
-    //! already a child of this meshset
-  int add_child(MBEntityHandle child);
-    
-    //! remove a parent from this meshset; returns true if parent was removed, 0 if it was
-    //! not a parent of this meshset
-  int remove_parent(MBEntityHandle parent);
-    
-    //! remove a child from this meshset; returns true if child was removed, 0 if it was
-    //! not a child of this meshset
-  int remove_child(MBEntityHandle child);
-
-  unsigned flags() const { return mFlags; }
-  //! returns whether entities of meshsets know this meshset 
-  int tracking()     const { return mFlags & MESHSET_TRACK_OWNER; }
-  int set()          const { return mFlags & MESHSET_SET; }
-  int ordered()      const { return mFlags & MESHSET_ORDERED; }
-  int vector_based() const { return ordered(); }
-
-    //! replace one entity with another in the set (contents and parent/child
-    //! lists); returns whether it was replaced or not
-  MBErrorCode replace_entities(MBEntityHandle my_handle, 
-                               const MBEntityHandle *old_entities, 
-                               const MBEntityHandle *new_entities,
-                               size_t num_entities,
-                               AEntityFactory* mAdjFact);
-  
-    /** Clear *contents* of set (not parents or children) */
-  inline MBErrorCode clear( MBEntityHandle myhandle, AEntityFactory* adjacencies );
-  
-    /** Clear all set lists (contents, parents, and children) */
-  inline MBErrorCode clear_all( MBEntityHandle myhandle, AEntityFactory* adjacencies );
-
-    /** Get contents data array.  NOTE: this may not contain what you expect if not vector_based */
-  inline const MBEntityHandle* get_contents( size_t& count_out ) const;
-    /** Get contents data array.  NOTE: this may not contain what you expect if not vector_based */
-  inline MBEntityHandle* get_contents( size_t& count_out );
-
-    /** Get entities contained in set */
-  inline MBErrorCode get_entities(std::vector<MBEntityHandle>& entities) const;
-
-    /** Get entities contained in set */
-  inline MBErrorCode get_entities( MBRange& entities ) const;
-  
-    //! get all entities in this MeshSet with the specified type
-  inline MBErrorCode get_entities_by_type(MBEntityType entity_type, std::vector<MBEntityHandle> &entity_list) const;
-  
-  inline MBErrorCode get_entities_by_type( MBEntityType type, MBRange& entity_list) const;
-    
-    //! return the number of entities with the given type contained in this meshset
-  inline unsigned int num_entities_by_type(MBEntityType type) const;
-      
-  inline MBErrorCode get_entities_by_dimension( int dimension, std::vector<MBEntityHandle> &entity_list) const;
-
-  inline MBErrorCode get_entities_by_dimension( int dimension, MBRange& entity_list) const;
-  
-    //! return the number of entities with the given type contained in this meshset
-  inline unsigned int num_entities_by_dimension(int dimension) const;
-      
-  inline MBErrorCode get_non_set_entities( MBRange& range ) const;
-
-  /** Test of meshset contains some or all of passed entities
-   *
-   *\param entities Array of entities
-   *\param num_entities Length of array of entities.
-   *\param op - MBInterface::UNION     : Test if set contains any of the input entities
-   *          - MBInterface::INTERSECT : Test if set contains all of the input entities
-   */
-  inline bool contains_entities(const MBEntityHandle *entities, int num_entities, const int op) const;
-
-  
-  //! subtract/intersect/unite meshset_2 from/with/into meshset_1; modifies meshset_1
-  inline MBErrorCode subtract(const MBMeshSet *meshset_2,
-                               MBEntityHandle my_handle,
-                               AEntityFactory* adjacencies);
-
-  MBErrorCode intersect(const MBMeshSet *meshset_2,
-                                MBEntityHandle my_handle,
-                                AEntityFactory* adjacencies);
-
-  inline MBErrorCode unite(const MBMeshSet *meshset_2,
-                            MBEntityHandle my_handle,
-                            AEntityFactory* adjacencies);
-
-  //! add these entities to this meshset
-  inline MBErrorCode add_entities(const MBEntityHandle *entity_handles,
-                                   const int num_entities,
-                                   MBEntityHandle my_handle,
-                                   AEntityFactory* adjacencies);
-    
-    //! add these entities to this meshset
-  inline MBErrorCode add_entities(const MBRange &entities,
-                                   MBEntityHandle my_handle,
-                                   AEntityFactory* adjacencies);
-    
-    //! add these entities to this meshset
-  inline MBErrorCode remove_entities(const MBRange& entities,
-                                      MBEntityHandle my_handle,
-                                      AEntityFactory* adjacencies);
-    
-   
-    //! remove these entities from this meshset
-  inline MBErrorCode remove_entities(const MBEntityHandle *entities,
-                                      const int num_entities,
-                                      MBEntityHandle my_handle,
-                                      AEntityFactory* adjacencies);
-
-    //! return the number of entities contained in this meshset
-  inline unsigned int num_entities() const;
-  
-  inline bool empty() const { return mContentCount == ZERO; }
-  
-  unsigned long get_memory_use() const;
-
-protected:
-  
-  /** Convert for changing flag values */
-  MBErrorCode convert( unsigned flags, MBEntityHandle my_handle, AEntityFactory* adj );
-
-  /** Add explicit adjacencies from all contained entities to this (i.e. convert to tracking) */
-  MBErrorCode create_adjacencies( MBEntityHandle myhandle, AEntityFactory* adjacencies );
-
-  /** Remvoe explicit adjacencies from all contained entities to this (i.e. convert from tracking) */
-  MBErrorCode remove_adjacencies( MBEntityHandle myhandle, AEntityFactory* adjacencies );
-
-  /** Insert vector of handles into MBMeshSet */
-  MBErrorCode insert_entity_vector( const MBEntityHandle* vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj );
- 
-  /** Insert vector of handle range pairs into MBMeshSet */
-  MBErrorCode insert_entity_ranges( const MBEntityHandle* range_vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj );
-
-  /** Insert MBRange of handles into MBMeshSet */
-  MBErrorCode insert_entity_ranges( const MBRange& range, MBEntityHandle my_h, AEntityFactory* adj );
-
-  /** Remove vector of handles from MBMeshSet */
-  MBErrorCode remove_entity_vector( const MBEntityHandle* vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj );
-
-  /** Remove vector of handle range pairs from MBMeshSet */
-  MBErrorCode remove_entity_ranges( const MBEntityHandle* range_vect, size_t len, MBEntityHandle my_h, AEntityFactory* adj );
-
-  /** Remove MBRange of handles from MBMeshSet */
-  MBErrorCode remove_entity_ranges( const MBRange& range, MBEntityHandle my_h, AEntityFactory* adj );
-
-public:  
-    //! Possible values of mParentCount and mChildCount
-  enum Count { ZERO=0, ONE=1, TWO=2, MANY=3 };
-    //! If the number of entities is less than 3, store
-    //! the handles directly in the hnd member.  Otherwise
-    //! use the ptr member to hold the beginning and end
-    //! of a dynamically allocated array.
-  union CompactList {
-    MBEntityHandle hnd[2];  //!< Two handles
-    MBEntityHandle* ptr[2]; //!< begin and end pointers for array
-  };
-
-private:
-  //!Meshset propery flags
-  unsigned char mFlags;
-  //! If less than MANY, the number of parents stored inline in
-  //! parentMeshSets.hnd.  If MANY, then parentMeshSets.ptr contains
-  //! array begin and end pointers for a dynamically allocated array
-  //! of parent handles.
-  unsigned mParentCount : 2;
-  //! If less than MANY, the number of children stored inline in
-  //! childMeshSets.hnd.  If MANY, then childMeshSets.ptr contains
-  //! array begin and end pointers for a dynamically allocated array
-  //! of child handles.
-  unsigned mChildCount : 2;
-  //! If less than MANY, the number of children stored inline in
-  //! contentList.hnd.  If MANY, then contentList.ptr contains
-  //! array begin and end pointers for a dynamically allocated array..
-  unsigned mContentCount : 2;
-  //! Storage for data lists
-  CompactList parentMeshSets, childMeshSets, contentList;
-
-public:
-    /** get dimension of enity */
-  static inline int DIM_FROM_HANDLE( MBEntityHandle h )
-    { return MBCN::Dimension( TYPE_FROM_HANDLE( h ) ); }
-  
-    /** Get smallest possible handle with specified dimension (first handle for first type of dimension) */
-  static inline MBEntityHandle FIRST_OF_DIM( int dim )
-    { return FIRST_HANDLE( MBCN::TypeDimensionMap[dim].first ); }
-  
-    /** Get largest possible handle with specified dimension (largest handle for last type of dimension) */
-  static inline MBEntityHandle LAST_OF_DIM( int dim )
-    { return LAST_HANDLE( MBCN::TypeDimensionMap[dim].second ); }
-
-    /** functor: test if handle is not of type */
-  struct not_type_test {
-      inline not_type_test( MBEntityType type ) : mType(type) {}
-      inline bool operator()( MBEntityHandle handle )
-        { return TYPE_FROM_HANDLE(handle) != mType; }
-      MBEntityType mType;
-  };
-
-    /** functor: test if handle is of type */
-  struct type_test {
-      inline type_test( MBEntityType type ) : mType(type) {}
-      inline bool operator()( MBEntityHandle handle )
-        { return TYPE_FROM_HANDLE(handle) == mType; }
-      MBEntityType mType;
-  };
-
-    /** functor: test if handle is not of dimension */
-  struct not_dim_test {
-      inline not_dim_test( int dimension ) : mDim(dimension) {}
-      inline bool operator()( MBEntityHandle handle ) const
-        { return DIM_FROM_HANDLE(handle) != mDim; }
-      int mDim;
-  };
-
-    /** functor: test if handle is of dimension */
-  struct dim_test {
-      inline dim_test( int dimension ) : mDim(dimension) {}
-      inline bool operator()( MBEntityHandle handle ) const
-        { return DIM_FROM_HANDLE(handle) == mDim; }
-      int mDim;
-  };
-  
-    /** Iterate over range of handles.  That is, given [first_handle,last_handle],
-     *  step through all contained values.
-     */
-  struct hdl_iter {
-    MBEntityHandle h;
-    hdl_iter( MBEntityHandle val ) : h(val) {}
-    hdl_iter& operator++() { ++h; return *this; }
-    hdl_iter& operator--() { --h; return *this; }
-    hdl_iter operator++(int) { return hdl_iter(h++); }
-    hdl_iter operator--(int) { return hdl_iter(h--); }
-    hdl_iter& operator+=(size_t s) { h += s; return *this; }
-    hdl_iter& operator-=(size_t s) { h -= s; return *this; }
-    MBEntityHandle operator*() const { return h; }
-    bool operator==(hdl_iter other) const { return h == other.h; }
-    bool operator!=(hdl_iter other) const { return h != other.h; }
-    bool operator< (hdl_iter other) const { return h <  other.h; }
-    bool operator> (hdl_iter other) const { return h >  other.h; }
-    bool operator<=(hdl_iter other) const { return h <= other.h; }
-    bool operator>=(hdl_iter other) const { return h >= other.h; }
-    
-    struct iterator_category : public std::random_access_iterator_tag { };
-    typedef MBEntityID difference_type;
-    typedef MBEntityHandle value_type;
-    typedef MBEntityHandle* pointer;
-    typedef MBEntityHandle& reference;
-  };
-  
-};
-
-inline MBMeshSet::hdl_iter::difference_type
- operator-( const MBMeshSet::hdl_iter a, const MBMeshSet::hdl_iter b )
-  { return (MBMeshSet::hdl_iter::difference_type)a.h 
-         - (MBMeshSet::hdl_iter::difference_type)b.h; }
-
-
-  //! create an empty meshset
-MBMeshSet::MBMeshSet()
-  : mFlags(0), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
-{ }
-
-  //! create an empty meshset
-MBMeshSet::MBMeshSet(unsigned flags)
-  : mFlags(flags), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
-{ }
-
-  //! destructor
-MBMeshSet::~MBMeshSet() 
-{
-  if (mChildCount == MANY)
-    free( childMeshSets.ptr[0] );
-  if (mParentCount == MANY)
-    free( parentMeshSets.ptr[0] );
-  if (mContentCount == MANY)
-    free( contentList.ptr[0] );
-  mChildCount = mParentCount = mContentCount = ZERO;
-}
-  
-MBErrorCode MBMeshSet::set_flags( unsigned flags, MBEntityHandle my_handle, AEntityFactory* adjacencies ) 
-{
-  if(ZERO != mContentCount) {
-    MBErrorCode result = convert(flags, my_handle, adjacencies);
-    if(MB_SUCCESS != result) return result;
-  }
-  mFlags = flags;
-  return MB_SUCCESS;
-}
-    
-
-//! get all children pointed to by this meshset
-const MBEntityHandle* MBMeshSet::get_children( int& count_out ) const 
-{ 
-  count_out = mChildCount;
-  if (count_out < MANY)
-    return childMeshSets.hnd;
-
-  count_out = childMeshSets.ptr[1] - childMeshSets.ptr[0];
-  return childMeshSets.ptr[0];
-}
-
-//! get all parents pointed to by this meshset
-const MBEntityHandle* MBMeshSet::get_parents( int& count_out ) const
-{ 
-  count_out = mParentCount;
-  if (count_out < MANY)
-    return parentMeshSets.hnd;
-
-  count_out = parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
-  return parentMeshSets.ptr[0];
-}
-
-//! return the number of children pointed to by this meshset
-int MBMeshSet::num_children() const 
-{
-  if (mChildCount < MANY)
-    return mChildCount;
-  else
-    return childMeshSets.ptr[1] - childMeshSets.ptr[0];
-}
-
-//! return the number of parents pointed to by this meshset
-int MBMeshSet::num_parents() const
-{
-  if (mParentCount < MANY)
-    return mParentCount;
-  else
-    return parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
-}
-  
-inline MBErrorCode MBMeshSet::clear( MBEntityHandle myhandle, AEntityFactory* adjacencies )
-{ 
-  if (tracking())
-    remove_adjacencies( myhandle, adjacencies );
-  if (mContentCount == MANY)
-    free( contentList.ptr[0] );
-  mContentCount = ZERO;
-  return MB_SUCCESS;
-}
-  
-inline MBErrorCode MBMeshSet::clear_all( MBEntityHandle myhandle, AEntityFactory* adjacencies )
-{ 
-  MBErrorCode rval = clear( myhandle, adjacencies );
-  if (mChildCount == MANY)
-    free( childMeshSets.ptr[0] );
-  mChildCount = ZERO;
-  if (mParentCount == MANY)
-    free( parentMeshSets.ptr[0] );
-  mParentCount = ZERO;
-  return rval;
-}
-
-inline const MBEntityHandle* MBMeshSet::get_contents( size_t& count_out ) const
-{
-  if (mContentCount == MANY) {
-    count_out = contentList.ptr[1] - contentList.ptr[0];
-    return contentList.ptr[0];
-  }
-  else {
-    count_out = mContentCount;
-    return contentList.hnd;
-  }
-}
-
-inline MBEntityHandle* MBMeshSet::get_contents( size_t& count_out )
-{
-  if (mContentCount == MANY) {
-    count_out = contentList.ptr[1] - contentList.ptr[0];
-    return contentList.ptr[0];
-  }
-  else {
-    count_out = mContentCount;
-    return contentList.hnd;
-  }
-}
-
-inline MBErrorCode MBMeshSet::get_entities(std::vector<MBEntityHandle>& entities) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    size_t old_size = entities.size();
-    entities.resize( count+old_size );
-    std::copy( ptr, ptr+count, entities.begin()+old_size );
-  }
-  else {
-    assert(count%2 == 0);
-    for (size_t i = 0; i < count; i += 2) 
-      std::copy( hdl_iter(ptr[i]), hdl_iter(ptr[i+1]+1), std::back_inserter(entities) );
-  }
-  return MB_SUCCESS;
-} 
-
-inline MBErrorCode MBMeshSet::get_entities(MBRange& entities) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::copy( ptr, ptr+count, mb_range_inserter(entities) );
-  }
-  else {
-    assert(count%2 == 0);
-    MBRange::iterator in = entities.begin();
-    for (size_t i = 0; i < count; i += 2) 
-      in = entities.insert( in, ptr[i], ptr[i+1] );
-  }
-  return MB_SUCCESS;
-} 
-
-
-  //! get all entities in this MeshSet with the specified type
-inline MBErrorCode MBMeshSet::get_entities_by_type(MBEntityType type,
-                                                   std::vector<MBEntityHandle> &entity_list
-                                                   ) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::remove_copy_if( ptr, ptr+count, 
-                         std::back_inserter( entity_list ),
-                         not_type_test(type) );
-  }
-  else {
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
-    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
-      if (idx % 2) { // only part of first block is of type
-        std::copy( hdl_iter(FIRST_HANDLE(type)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
-          std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
-        else {
-          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
-            std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_HANDLE(type)), std::back_inserter( entity_list ) );
-          break;
-        }
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-
-inline MBErrorCode MBMeshSet::get_entities_by_type( MBEntityType type,
-                                                    MBRange& entity_list) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::remove_copy_if( ptr, ptr+count, 
-                         mb_range_inserter( entity_list ),
-                         not_type_test(type) );
-  }
-  else {
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
-    MBRange::iterator in = entity_list.begin();
-    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
-      if (idx % 2) { // only part of first block is of type
-        in = entity_list.insert( in, FIRST_HANDLE(type), ptr[idx] );
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
-          in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
-        else {
-          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
-            entity_list.insert( in, ptr[idx], LAST_HANDLE(type) );
-          break;
-        }
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-  //! return the number of entities with the given type contained in this meshset
-inline unsigned int MBMeshSet::num_entities_by_type(MBEntityType type) const
-{
-  unsigned int result;
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    #ifndef __SUNPRO_CC
-      result = std::count_if( ptr, ptr+count, type_test(type) );
-    #else
-      std::count_if( ptr, ptr+count, type_test(type), result );
-    #endif
-  }
-  else {
-    result = 0;
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
-    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
-      if (idx % 2) { // only part of first block is of type
-        result += ptr[idx] - FIRST_HANDLE(type) + 1;
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
-          result += ptr[idx+1] - ptr[idx] + 1;
-        else {
-          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
-            result += LAST_HANDLE(type) - ptr[idx] + 1;
-          break;
-        }
-      }
-    }
-  }
-
-  return result;
-}
-
-inline MBErrorCode MBMeshSet::get_entities_by_dimension( int dimension,
-                                                         std::vector<MBEntityHandle> &entity_list
-                                                         ) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::remove_copy_if( ptr, ptr+count, 
-                         std::back_inserter( entity_list ),
-                         not_dim_test(dimension) );
-  }
-  else {
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
-    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
-      if (idx % 2) { // only part of first block is of type
-        std::copy( hdl_iter(FIRST_OF_DIM(dimension)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
-          std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
-        else {
-          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
-            std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_OF_DIM(dimension)), std::back_inserter( entity_list ) );
-          break;
-        }
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-
-inline MBErrorCode MBMeshSet::get_entities_by_dimension( int dimension,
-                                                         MBRange& entity_list) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::remove_copy_if( ptr, ptr+count, 
-                         mb_range_inserter( entity_list ),
-                         not_dim_test(dimension) );
-  }
-  else {
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
-    MBRange::iterator in = entity_list.begin();
-    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
-      if (idx % 2) { // only part of first block is of type
-        in = entity_list.insert( in, FIRST_OF_DIM(dimension), ptr[idx] );
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
-          in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
-        else {
-          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
-            entity_list.insert( in, ptr[idx], LAST_OF_DIM(dimension) );
-          break;
-        }
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-  //! return the number of entities with the given type contained in this meshset
-inline unsigned int MBMeshSet::num_entities_by_dimension(int dimension) const
-{
-  unsigned int result;
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    #ifndef __SUNPRO_CC
-      result = std::count_if( ptr, ptr+count, dim_test(dimension) );
-    #else
-      std::count_if( ptr, ptr+count, dim_test(dimension), result );
-    #endif
-  }
-  else {
-    result = 0;
-    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
-    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
-      if (idx % 2) { // only part of first block is of type
-        result += ptr[idx] - FIRST_OF_DIM(dimension) + 1;
-        ++idx;
-      }
-      for (; idx < count; idx += 2) {
-        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
-          result += ptr[idx+1] - ptr[idx] + 1;
-        else {
-          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
-            result += LAST_OF_DIM(dimension) - ptr[idx] + 1;
-          break;
-        }
-      }
-    }
-  }
-
-  return result;
-}
-
-inline MBErrorCode MBMeshSet::get_non_set_entities( MBRange& range ) const
-{
-  size_t count;
-  const MBEntityHandle* ptr = get_contents( count );
-  if (vector_based()) {
-    std::remove_copy_if( ptr, ptr+count, 
-                         mb_range_inserter( range ),
-                         type_test(MBENTITYSET) );
-  }
-  else {
-    MBRange::iterator in = range.begin();
-    for (size_t idx = 0; idx < count; idx += 2) {
-      if (TYPE_FROM_HANDLE(ptr[idx+1]) != MBENTITYSET)
-        in = range.insert( ptr[idx], ptr[idx+1] );
-      else {
-        if (TYPE_FROM_HANDLE(ptr[idx]) != MBENTITYSET)
-          range.insert( ptr[idx], LAST_HANDLE( MBENTITYSET - 1 ) );
-        break;
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-inline bool MBMeshSet::contains_entities(const MBEntityHandle *entities, 
-                                         int num_entities,
-                                         const int op) const
-{
-  size_t count;
-  const MBEntityHandle* const ptr = get_contents( count );
-  const MBEntityHandle* const end = ptr + count;
-  size_t found_count = 0;
-  if (vector_based()) {
-    for (int i = 0; i < num_entities; ++i)
-      if (std::find( ptr, end, entities[i] ) < end)
-        ++found_count; 
-  }
-  else {
-    assert(0 == count % 2);
-    for (int i = 0; i < num_entities; ++i) {
-      const unsigned long idx = std::lower_bound( ptr, end, entities[i] ) - ptr;
-      if (idx < count && (idx%2 != 0 || ptr[idx] == entities[i]))
-        ++found_count;
-    }
-  }
-
-  return found_count >= ((MBInterface::INTERSECT == op) ? (unsigned)num_entities : 1u);
-}
-
-
-
-//! subtract/intersect/unite meshset_2 from/with/into meshset_1; modifies meshset_1
-inline MBErrorCode MBMeshSet::subtract(const MBMeshSet *meshset_2,
-                                       MBEntityHandle my_handle,
-                                       AEntityFactory* adjacencies)
-{
-  size_t count;
-  const MBEntityHandle* const ptr = meshset_2->get_contents( count );
-  if (meshset_2->vector_based()) 
-    return remove_entity_vector( ptr, count, my_handle, adjacencies );
-  else
-    return remove_entity_ranges( ptr, count, my_handle, adjacencies );
-}
-
-inline MBErrorCode MBMeshSet::unite(const MBMeshSet *meshset_2,
-                                    MBEntityHandle my_handle,
-                                    AEntityFactory* adjacencies)
-{
-  size_t count;
-  const MBEntityHandle* const ptr = meshset_2->get_contents( count );
-  if (meshset_2->vector_based()) 
-    return insert_entity_vector( ptr, count, my_handle, adjacencies );
-  else
-    return insert_entity_ranges( ptr, count, my_handle, adjacencies );
-}
-
-//! add these entities to this meshset
-inline MBErrorCode MBMeshSet::add_entities(const MBEntityHandle *entity_handles,
-                                           const int num_entities,
-                                           MBEntityHandle my_handle,
-                                           AEntityFactory* adjacencies)
-{
-  return insert_entity_vector( entity_handles, num_entities, my_handle, adjacencies );
-}
-
-  //! add these entities to this meshset
-inline MBErrorCode MBMeshSet::add_entities(const MBRange &entities,
-                                           MBEntityHandle my_handle,
-                                           AEntityFactory* adjacencies)
-{
-  return insert_entity_ranges( entities, my_handle, adjacencies );
-}
-
-  //! add these entities to this meshset
-inline MBErrorCode MBMeshSet::remove_entities(const MBRange& entities,
-                                              MBEntityHandle my_handle,
-                                              AEntityFactory* adjacencies)
-{
-  return remove_entity_ranges(  entities, my_handle, adjacencies );
-}
-
-
-  //! remove these entities from this meshset
-inline MBErrorCode MBMeshSet::remove_entities(const MBEntityHandle *entities,
-                                              const int num_entities,
-                                              MBEntityHandle my_handle,
-                                              AEntityFactory* adjacencies)
-{
-  return remove_entity_vector( entities, num_entities, my_handle, adjacencies );
-}
-
-  //! return the number of entities contained in this meshset
-unsigned int MBMeshSet::num_entities() const
-{
-  size_t count;
-  const MBEntityHandle* list = get_contents( count );
-  if (vector_based())
-    return count;
-  
-  int result = 0;
-  const MBEntityHandle *const end = list + count;
-  for (; list < end; list += 2)
-    result += list[1] - list[0] + 1;
-  return result;
-}
-
-#endif

Deleted: MOAB/trunk/src/MBOrientedBox.cpp
===================================================================
--- MOAB/trunk/src/MBOrientedBox.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBOrientedBox.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,655 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/* 
- * The algorithms for the calculation of the oriented box from a
- * set of points or a set of cells was copied from the implemenation
- " in the "Visualization Toolkit".  J.K. - 2006-07-19
- *
- * Program:   Visualization Toolkit
- * Module:    $RCSfile$
- *
- * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
- * All rights reserved.
- * See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
- */
-
-/**\file MBOrientedBox.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#include "MBInterface.hpp"
-#include "MBCN.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBRange.hpp"
-#include "MBMatrix3.hpp"
-#include <ostream>
-#include <assert.h>
-#include <limits>
-
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#  include <float.h>
-#  define finite(A) _finite(A)
-#endif
- 
-std::ostream& operator<<( std::ostream& s, const MBOrientedBox& b )
-{
-  return s << b.center 
-           << " + " 
-           << b.axis[0] 
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-           << ":" << b.length[0] 
-#endif
-           << " x " 
-           << b.axis[1] 
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-           << ":" << b.length[1] 
-#endif
-           << " x " 
-           << b.axis[2]
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-           << ":" << b.length[2] 
-#endif
-            ;
-}
-
-/**\brief Find closest point on line
- *
- * Find the point on the line for which a line trough the 
- * input point \a p and the result position is orthogonal to
- * the input line.
- * \param p  The point for which to find the perpendicular
- * \param b  A point on the line
- * \param m  The direction of the line
- * \return   The location on the line specified as 't' in the
- *           formula t * m + b
- */
-static double point_perp( const MBCartVect& p,   // closest to this point
-                          const MBCartVect& b,   // point on line
-                          const MBCartVect& m )  // line direction
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  double t = (m % (p - b));
-#else
-  double t = (m % (p - b)) / (m % m);
-#endif
-  return finite(t) ? t : 0.0;
-}
-
-MBOrientedBox::MBOrientedBox( const MBCartVect axes[3], const MBCartVect& mid )
-  : center(mid)
-{
-    // re-order axes by length
-  MBCartVect len( axes[0].length(), axes[1].length(), axes[2].length() );
-  axis[0] = axes[0];
-  axis[1] = axes[1];
-  axis[2] = axes[2];
-  
-  if (len[2] < len[1])
-  {
-    if (len[2] < len[0]) {
-      std::swap( len[0], len[2] );
-      std::swap( axis[0], axis[2] );
-    }
-  }
-  else if (len[1] < len[0]) {
-    std::swap( len[0], len[1] );
-    std::swap( axis[0], axis[1] );
-  }
-  if (len[1] > len[2]) {
-    std::swap( len[1], len[2] );
-    std::swap( axis[1], axis[2] );
-  }
-  
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  this->length = len;
-  if (len[0] > 0.0)
-    axis[0] /= len[0];
-  if (len[1] > 0.0)
-    axis[1] /= len[1];
-  if (len[2] > 0.0)
-    axis[2] /= len[2];
-#endif
-
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  radius = len.length();
-#endif
-}
-
-MBErrorCode MBOrientedBox::tag_handle( MBTag& handle_out,
-                                       MBInterface* instance,
-                                       const char* name,
-                                       bool create )
-{
-    // We're going to assume this when mapping the MBOrientedBox
-    // to tag data, so assert it.  
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  const size_t rad_size = sizeof(double);
-#else
-  const size_t rad_size = 0;
-#endif
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  const size_t SIZE = rad_size + 15 * sizeof(double);
-#else
-  const size_t SIZE = rad_size + 12 * sizeof(double);
-#endif
-  assert( sizeof(MBOrientedBox) == SIZE );
-  
-  MBErrorCode rval = instance->tag_get_handle( name, handle_out );
-  if (rval == MB_TAG_NOT_FOUND)
-  {
-    rval = instance->tag_create( name, 
-                                 SIZE,
-                                 MB_TAG_DENSE,
-                                 MB_TYPE_DOUBLE,
-                                 handle_out,
-                                 0 );
-  }
-  else if (rval == MB_SUCCESS)
-  {
-    MBDataType type;
-    rval = instance->tag_get_data_type( handle_out, type );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    int size;
-    rval = instance->tag_get_size( handle_out, size );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    if (type != MB_TYPE_DOUBLE && type != MB_TYPE_OPAQUE)
-      return MB_FAILURE;
-    if ((unsigned)size != SIZE)
-      return MB_FAILURE;
-  }
-  
-  return rval;
-}
-
-/**\brief Common code for box calculation
- *
- * Given the orientation of the box and an approximate center,
- * calculate the exact center and extents of the box.
- * 
- *\param result.center  As input, the approximate center of the box.
- *                      As output, the exact center of the box.
- *\param result.axes    As input, directions of principal axes corresponding
- *                      to the orientation of the box.  Axes are assumed to
- *                      be unit-length on input.  Output will include extents
- *                      of box.
- *\param points  The set of points the box should contain.
- */
-static MBErrorCode box_from_axes( MBOrientedBox& result,
-                                  MBInterface* instance,
-                                  const MBRange& points )
-{ 
-  MBErrorCode rval;
-  
-    // project points onto axes to get box extents
-  MBCartVect min(std::numeric_limits<double>::max()), 
-             max(-std::numeric_limits<double>::max());
-  for (MBRange::iterator i = points.begin(); i != points.end(); ++i)
-  {
-    MBCartVect coords;
-    rval = instance->get_coords( &*i, 1, coords.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    for (int d = 0; d < 3; ++d)
-    {
-      double t = point_perp( coords, result.center, result.axis[d] );
-      if (t < min[d])
-        min[d] = t;
-      if (t > max[d])
-        max[d] = t;
-    }
-  }
-  
-    // We now have a box defined by three orthogonal line segments
-    // that intersect at the center of the box.  Each line segment
-    // is defined as result.center + t * result.axis[i], where the
-    // range of t is [min[i], max[i]].
-  
-    // Calculate new center
-  MBCartVect mid = 0.5 * (min + max);
-  result.center += mid[0] * result.axis[0] +
-                   mid[1] * result.axis[1] +
-                   mid[2] * result.axis[2];
-  
-    // reorder axes by length
-  MBCartVect range = 0.5 * (max - min);
-  if (range[2] < range[1])
-  {
-    if (range[2] < range[0]) {
-      std::swap( range[0], range[2] );
-      std::swap( result.axis[0], result.axis[2] );
-    }
-  }
-  else if (range[1] < range[0]) {
-    std::swap( range[0], range[1] );
-    std::swap( result.axis[0], result.axis[1] );
-  }
-  if (range[1] > range[2]) {
-    std::swap( range[1], range[2] );
-    std::swap( result.axis[1], result.axis[2] );
-  }
-
-    // scale axis to encompass all points, divide in half
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  result.length = range;
-#else
-  result.axis[0] *= range[0];
-  result.axis[1] *= range[1];
-  result.axis[2] *= range[2];
-#endif
-
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  result.radius = range.length();
-#endif
-
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBOrientedBox::compute_from_vertices( MBOrientedBox& result,
-                                                  MBInterface* instance,
-                                                  const MBRange& vertices )
-{
-  const MBRange::iterator begin = vertices.lower_bound( MBVERTEX );
-  const MBRange::iterator end = vertices.upper_bound( MBVERTEX );
-  size_t count = 0;
-  
-    // compute mean
-  MBCartVect v;
-  result.center = MBCartVect( 0, 0, 0 );
-  for (MBRange::iterator i = begin; i != end; ++i)
-  {
-    MBErrorCode rval = instance->get_coords( &*i, 1, v.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    result.center += v;
-    ++count;
-  }
-  result.center /= count;
-  
-    // compute covariance matrix
-  MBMatrix3 a( 0.0 );
-  for (MBRange::iterator i = begin; i != end; ++i)
-  {
-    MBErrorCode rval = instance->get_coords( &*i, 1, v.array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-  
-    v -= result.center;
-    a += outer_product( v, v );
-  }
-  a /= count;
-
-    // Get axes (Eigenvectors) from covariance matrix
-  double lambda[3];
-  EigenDecomp( a, lambda, result.axis );
-  
-    // Calculate center and extents of box given orientation defined by axes
-  return box_from_axes( result, instance, vertices );
-}
-
-MBErrorCode MBOrientedBox::covariance_data_from_tris( CovarienceData& result,
-                                                 MBInterface* instance,
-                                                 const MBRange& elements )
-{
-  MBErrorCode rval;
-  const MBRange::iterator begin = elements.lower_bound( MBCN::TypeDimensionMap[2].first );
-  const MBRange::iterator end = elements.lower_bound( MBCN::TypeDimensionMap[3].first );
-  
-    // compute mean and moments
-  result.matrix = MBMatrix3(0.0);
-  result.center = MBCartVect(0.0);
-  result.area = 0.0;
-  for (MBRange::iterator i = begin; i != end; ++i)
-  {
-    const MBEntityHandle* conn;
-    int conn_len;
-    rval = instance->get_connectivity( *i, conn, conn_len );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-      // for each triangle in the 2-D cell
-    for (int j = 2; j < conn_len; ++j)
-    {
-      MBEntityHandle vertices[3] = { conn[0], conn[j-1], conn[j] };
-      MBCartVect coords[3];
-      rval = instance->get_coords( vertices, 3, coords[0].array() );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-        // edge vectors
-      const MBCartVect edge0 = coords[1] - coords[0];
-      const MBCartVect edge1 = coords[2] - coords[0];
-      const MBCartVect centroid = (coords[0] + coords[1] + coords[2]) / 3;
-      const double tri_area2 = (edge0 * edge1).length();
-      result.area += tri_area2;
-      result.center += tri_area2 * centroid;
-      
-      result.matrix += tri_area2 * (9 * outer_product( centroid,  centroid  ) +
-                                    outer_product( coords[0], coords[0] ) +
-                                    outer_product( coords[1], coords[1] ) +
-                                    outer_product( coords[2], coords[2] ));
-    } // for each triangle
-  } // for each element
-
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBOrientedBox::compute_from_2d_cells( MBOrientedBox& result,
-                                                  MBInterface* instance,
-                                                  const MBRange& elements )
-{
-    // Get orientation data from elements
-  CovarienceData data;
-  MBErrorCode rval = covariance_data_from_tris( data, instance, elements );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // get vertices from elements
-  MBRange points;
-  rval = instance->get_adjacencies( elements, 0, false, points, MBInterface::UNION );
-  if (MB_SUCCESS != rval)
-    return rval;
-    
-    // Calculate box given points and orientation data
-  return compute_from_covariance_data( result, instance, data, points );
-}
-
-MBErrorCode MBOrientedBox::compute_from_covariance_data(
-                                                MBOrientedBox& result,
-                                                MBInterface* instance,
-                                                CovarienceData& data,
-                                                const MBRange& vertices )
-{
-  if (data.area <= 0.0) {
-    MBCartVect axis[3] = { MBCartVect(0.), MBCartVect(0.), MBCartVect(0.) };
-    result = MBOrientedBox( axis, MBCartVect(0.) );
-    return MB_SUCCESS;
-  }
-
-    // get center from sum
-  result.center = data.center / data.area;
-
-    // get covariance matrix from moments
-  data.matrix /= 12 * data.area;
-  data.matrix -= outer_product( result.center, result.center );
-
-    // get axes (Eigenvectors) from covariance matrix
-  double lamda[3];
-  EigenDecomp( data.matrix, lamda, result.axis );
-
-    // We now have only the axes.  Calculate proper center
-    // and extents for enclosed points.
-  return box_from_axes( result, instance, vertices );
-}      
-
-bool MBOrientedBox::contained( const MBCartVect& point, double tol ) const
-{
-  MBCartVect from_center = point - center;
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return fabs(from_center % axis[0]) - length[0] <= tol &&
-         fabs(from_center % axis[1]) - length[1] <= tol &&
-         fabs(from_center % axis[2]) - length[2] <= tol ;
-#else
-  for (int i = 0; i < 3; ++i) {
-    double length = axis[i].length();
-    if (fabs(from_center % axis[i]) - length*length > length*tol)
-      return false;
-  }
-  return true;
-#endif
-}
-
-MBErrorCode MBOrientedBox::compute_from_covariance_data( MBOrientedBox& result,
-                                                MBInterface* moab_instance,
-                                                const CovarienceData* data,
-                                                unsigned data_length,
-                                                const MBRange& vertices )
-{
-    // Sum input CovarienceData structures
-  CovarienceData data_sum( MBMatrix3(0.0), MBCartVect(0.0), 0.0 );
-  for (const CovarienceData* const end = data+data_length; data != end; ++data) {
-    data_sum.matrix += data->matrix;
-    data_sum.center += data->center;
-    data_sum.area += data->area;
-  }
-    // Compute box from sum of structs
-  return compute_from_covariance_data( result, moab_instance, data_sum, vertices );
-}
-
-
-
-//bool MBOrientedBox::contained( const MBOrientedBox& box, double tol ) const
-//{
-//  for (int i = -1; i < 2; i += 2) 
-//  {
-//    for (int j = -1; j < 2; j += 2) 
-//    {
-//      for (int k = -1; k < 2; k += 2) 
-//      {
-//        MBCartVect corner( center );
-//#ifdef MB_ORIENTED_BOX_UNIT_VECTORS
-//        corner += i * box.length[0] * box.axis[0];
-//        corner += j * box.length[1] * box.axis[1];
-//        corner += k * box.length[2] * box.axis[2];
-//#else
-//        corner += i * box.axis[0];
-//        corner += j * box.axis[1];
-//        corner += k * box.axis[2];
-//#endif
-//        if (!contained( corner, tol ))
-//          return false;
-//      }
-//    }
-//  }
-//  return true;
-//}
-
-
-/* This implementation copied from cgmMC (overlap.C).
- * Original author:  Tim Taugtes?
- */
-bool MBOrientedBox::intersect_ray( const MBCartVect& b,
-                                   const MBCartVect& m,
-                                   double reps,
-                                   const double* len ) const
-{
-    // test distance from box center to line
-  const MBCartVect cx = center - b;
-  double dist_s = cx % m;
-  double dist_sq = cx % cx - (dist_s*dist_s);
-  double max_diagsq = outer_radius_squared(reps);
-  
-    // if greater than the longest diagonal, we don't hit
-  if (dist_sq > max_diagsq)
-    return false;
-
-  // If the closest possible hit is farther than len, we don't want the hit.
-  // Problem: the previous method was wrong because max_diagsq will be greater
-  // than max_diag if max_diag>1 but less than max_diag if max_diag<1.
-  // Be careful with absolute value, squaring distances, and subtracting squared
-  // distances.
-  if (len) {
-    const double temp = fabs(dist_s) - *len;
-    if(0.0<temp && temp*temp>max_diagsq) return false;
-  } 
-
-    // if smaller than shortest diagonal, we do hit
-  if (dist_sq < inner_radius_squared(reps) && dist_s >= 0.0)
-    return true;
-    
-    // get transpose of axes
-    // Note: if axes were stored as a matrix, could skip
-    // transpose and just switch order of operands in
-    // matrix-vector multiplies below. - J.K.
-  //MBMatrix3 B( axis[0][0], axis[1][0], axis[2][0],
-  //             axis[0][1], axis[1][1], axis[2][1],
-  //             axis[0][2], axis[1][2], axis[2][2] );
-  MBMatrix3 B( axis[0][0], axis[0][1], axis[0][2],
-               axis[1][0], axis[1][1], axis[1][2],
-               axis[2][0], axis[2][1], axis[2][2] );
-  //MBCartVect T = B * -center;
-  
-    // transform ray to box coordintae system
-  //MBCartVect par_pos = T + B * b;
-  MBCartVect par_pos = B * (b - center);
-  MBCartVect par_dir = B * m;
-  
-    //fast rejection test
-  const double half_x = length[0] + reps;
-  if ((par_pos[0] >  half_x && par_dir[0] >= 0) ||
-      (par_pos[0] < -half_x && par_dir[0] <= 0))
-    return false;
-  
-  const double half_y = length[1] + reps;
-  if ((par_pos[1] >  half_y && par_dir[1] >= 0) ||
-      (par_pos[1] < -half_y && par_dir[1] <= 0))
-    return false;
-    
-  const double half_z = length[2] + reps;
-  if ((par_pos[2] >  half_z && par_dir[2] >= 0) ||
-      (par_pos[2] < -half_z && par_dir[2] <= 0))
-    return false;
-  
-    // test if point is inside
-  if (par_pos[0] <= half_x && par_pos[0] >= -half_x &&
-      par_pos[1] <= half_y && par_pos[1] >= -half_y &&
-      par_pos[2] <= half_z && par_pos[2] >= -half_z)
-    return true;
-
-    //test two xy plane
-  if ((half_z - par_pos[2]) * par_dir[2] >= 0 &&
-      fabs(par_dir[0] * (half_z - par_pos[2]) + par_dir[2] * par_pos[0]) 
-        <= fabs(par_dir[2] * half_x) && 
-      fabs(par_dir[1] * (half_z - par_pos[2]) + par_dir[2] * par_pos[1]) 
-        <= fabs(par_dir[2] * half_y)) 
-    return true;
-  if ((-half_z - par_pos[2]) * par_dir[2] >= 0 &&
-      fabs(par_dir[0] * (-half_z - par_pos[2]) + par_dir[2] * par_pos[0]) 
-        <= fabs(par_dir[2] * half_x) && 
-      fabs(par_dir[1] * (-half_z - par_pos[2]) + par_dir[2] * par_pos[1]) 
-        <= fabs(par_dir[2] * half_y))
-    return true;
-
-    //test two xz plane
-  if ((half_y - par_pos[1]) * par_dir[1] >= 0 &&
-      fabs(par_dir[0] * (half_y - par_pos[1]) + par_dir[1] * par_pos[0]) 
-        <= fabs(par_dir[1] * half_x) && 
-      fabs(par_dir[2] * (half_y - par_pos[1]) + par_dir[1] * par_pos[2]) 
-        <= fabs(par_dir[1] * half_z))
-    return true;
-  if ((-half_y - par_pos[1]) * par_dir[1] >= 0 &&
-      fabs(par_dir[0] * (-half_y - par_pos[1]) + par_dir[1] * par_pos[0]) 
-        <= fabs(par_dir[1] * half_x)  && 
-      fabs(par_dir[2] * (-half_y - par_pos[1]) + par_dir[1] * par_pos[2])
-        <= fabs(par_dir[1] * half_z))
-    return true;
-
-    //test two yz plane
-  if ((half_x - par_pos[0]) * par_dir[0] >= 0 &&
-      fabs(par_dir[1] * (half_x - par_pos[0]) + par_dir[0] * par_pos[1]) 
-        <= fabs(par_dir[0] * half_y) &&
-      fabs(par_dir[2] * (half_x - par_pos[0]) + par_dir[0] * par_pos[2]) 
-        <= fabs(par_dir[0] * half_z))
-    return true;
-  if ((-half_x - par_pos[0]) * par_dir[0] >= 0 &&
-      fabs(par_dir[1] * (-half_x - par_pos[0]) + par_dir[0] * par_pos[1])
-        <= fabs(par_dir[0] * half_y) &&
-      fabs(par_dir[2] * (-half_x - par_pos[0]) + par_dir[0] * par_pos[2]) 
-        <= fabs(par_dir[0] * half_z))
-    return true;
-
-  return false;
-}
-
-MBErrorCode MBOrientedBox::make_hex( MBEntityHandle& hex, MBInterface* instance )
-{
-  MBErrorCode rval;
-  int signs[8][3] = { { -1, -1, -1 },
-                      {  1, -1, -1 },
-                      {  1,  1, -1 },
-                      { -1,  1, -1 },
-                      { -1, -1,  1 },
-                      {  1, -1,  1 },
-                      {  1,  1,  1 },
-                      { -1,  1,  1 } };
-                      
-  std::vector<MBEntityHandle> vertices;
-  for (int i = 0; i < 8; ++i)
-  {
-    MBCartVect coords(center);
-    for (int j = 0; j < 3; ++j)
-      coords += signs[i][j] * axis[j];
-    MBEntityHandle handle;
-    rval = instance->create_vertex( coords.array(), handle );
-    if (MB_SUCCESS != rval) {
-      instance->delete_entities( &vertices[0], vertices.size() );
-      return rval;
-    }
-    vertices.push_back( handle );
-  }
-  
-  rval = instance->create_element( MBHEX, &vertices[0], vertices.size(), hex );
-  if (MB_SUCCESS != rval) {
-    instance->delete_entities( &vertices[0], vertices.size() );
-    return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-  
-void MBOrientedBox::closest_location_in_box( 
-                                    const MBCartVect& input_position,
-                                    MBCartVect& output_position ) const
-{
-    // get coordinates on box axes
-  const MBCartVect from_center = input_position - center;
-
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  MBCartVect local( from_center % axis[0],
-                    from_center % axis[1],
-                    from_center % axis[2] );
-
-  for (int i = 0; i < 3; ++i) {
-    if (local[i] < -length[i])
-      local[i] = -length[i];
-    else if (local[i] > length[i])
-      local[i] =  length[i];
-  }
-#else
-  MBCartVect local( (from_center % axis[0]) / (axis[0] % axis[0]),
-                    (from_center % axis[1]) / (axis[1] % axis[1]),
-                    (from_center % axis[2]) / (axis[2] % axis[2]) );
-
-  for (int i = 0; i < 3; ++i) {
-    if (local[i] < -1.0)
-      local[i] = -1.0;
-    else if (local[i] > 1.0)
-      local[i] = 1.0;
-  }
-#endif
-
-  output_position = center
-                  + local[0] * axis[0] 
-                  + local[1] * axis[1]
-                  + local[2] * axis[2];
-}

Deleted: MOAB/trunk/src/MBOrientedBox.hpp
===================================================================
--- MOAB/trunk/src/MBOrientedBox.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBOrientedBox.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,243 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBOrientedBox.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#ifndef MB_ORIENTED_BOX_HPP
-#define MB_ORIENTED_BOX_HPP
-
-#include "MBForward.hpp"
-#include "MBCartVect.hpp"
-#include "MBMatrix3.hpp"
-
-#include <iosfwd>
-
-#define MB_ORIENTED_BOX_UNIT_VECTORS 1
-#define MB_ORIENTED_BOX_OUTER_RADIUS 1
-
-class MBRange;
-
-
-/**\brief Oriented bounding box
- */
-class MBOrientedBox
-{
-public:
-  MBCartVect center;  //!< Box center
-  MBCartVect axis[3]; //!< Box axes, unit vectors sorted by extent of box along axis
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  MBCartVect length;  //!< distance from center to plane along each axis
-#endif
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  double radius;      //!< outer radius (1/2 diagonal length) of box
-#endif
-
-  inline MBOrientedBox() {}
-
-  MBOrientedBox( const MBCartVect axis[3], const MBCartVect& center );
-
-  inline double inner_radius() const; //!< radius of inscribed sphere
-  inline double outer_radius() const; //!< radius of circumscribed sphere
-  inline double outer_radius_squared(const double reps) const; //!< square of (radius+at least epsilon) of circumsphere
-  inline double inner_radius_squared(const double reps) const; //!< square of (radius-epsilon) of inscribed sphere
-  inline double volume() const;               //!< volume of box
-  inline MBCartVect dimensions() const;       //!< number of dimensions for which box is not flat
-  inline double area() const;                 //!< largest side area
-  inline MBCartVect scaled_axis( int index ) const; //!< get vector in direction of axis, from box center to face
-  
-  /** Test if point is contained in box */
-  bool contained( const MBCartVect& point, double tolerance ) const;
-  
-  //bool contained( const MBOrientedBox& other, double tolerance ) const;
-  
-  /**\brief get tag handle for storing oriented box
-   *
-   * Get the handle for the tag with the specified name and
-   * check that the tag is appropriate for storing instances
-   * of MBOrientedBox.  The resulting tag may be used to store
-   * instances of MBOrientedBox directly.
-   *
-   *\param handle_out  The TagHandle, passed back to caller
-   *\param name        The tag name
-   *\param create      If true, tag will be created if it does not exist
-   */
-  static MBErrorCode tag_handle( MBTag& handle_out,
-                                 MBInterface* instance, 
-                                 const char* name,
-                                 bool create = true );
-
-  /**\brief Calculate an oriented box from a set of vertices */
-  static MBErrorCode compute_from_vertices( MBOrientedBox& result,
-                                            MBInterface* instance,
-                                            const MBRange& vertices );
-                                  
-  /**\brief Calculate an oriented box from a set of 2D elements */
-  static MBErrorCode compute_from_2d_cells( MBOrientedBox& result,
-                                            MBInterface* instance,
-                                            const MBRange& elements );
-
-    /** Structure to hold temporary accumulated triangle data for
-     *  caculating box orietation.  See box_from_covariance_data
-     *  to see how this is used to calculate the final covariance matrix
-     *  and resulting box orientation.
-     */
-  struct CovarienceData {
-    CovarienceData() {}
-    CovarienceData( const MBMatrix3& m, const MBCartVect& c, double a)
-      : matrix(m), center(c), area(a) {}
-    MBMatrix3 matrix;    //!< Running sum for covariance matrix
-    MBCartVect center;   //!< Sum of triangle centroids weighted by 2*triangle area
-    double area;         //!< 2x the sum of the triangle areas
-  };
-  
-    /** Calculate a CovarienceData struct from a list of triangles */
-  static MBErrorCode covariance_data_from_tris( CovarienceData& result,
-                                                MBInterface* moab_instance,
-                                                const MBRange& elements );
-  
-    /** Calculate an MBOrientedBox given an arrray of CovarienceData and 
-     *  the list  of vertices the box is to bound.
-     */
-  static MBErrorCode compute_from_covariance_data( MBOrientedBox& result,
-                                          MBInterface* moab_instance,
-                                          const CovarienceData* orient_array,
-                                          unsigned orient_array_length,
-                                          const MBRange& vertices );
-  
-    /** Test for intersection of a ray (or line segment) with this box
-     *\param ray_start_point The base point of the ray
-     *\param ray_unit_direction The direction of the ray (must be unit length)
-     *\param distance_tolerance Tolerance to use in intersection checks
-     *\param segment_length Optional length of ray
-     */
-  bool intersect_ray( const MBCartVect& ray_start_point,
-                      const MBCartVect& ray_unit_direction,
-                      double distance_tolerance,
-                      const double* segment_length = 0 ) const;
-                      
-    /**\brief Find closest position on/within box to input position.
-     * 
-     * Find the closest position in the solid box to the input position.
-     * If the input position is on or within the box, then the output
-     * position will be the same as the input position.  If the input
-     * position is outside the box, the outside position will be the
-     * closest point on the box boundary to the input position.
-     */
-  void closest_location_in_box( const MBCartVect& input_position,
-                                MBCartVect& output_position ) const;
-                      
-    //! Construct a hexahedral element with the same shape as this box.
-  MBErrorCode make_hex( MBEntityHandle& hex, MBInterface* instance );
-                                    
-  
-    /** Calculate an MBOrientedBox given a CovarienceData struct and
-     *  the list of points the box is to bound.
-     */
-  static MBErrorCode compute_from_covariance_data( MBOrientedBox& result,
-                                          MBInterface* moab_instance,
-                                          CovarienceData& orientation_data,
-                                          const MBRange& vertices );
-};
-
-std::ostream& operator<<( std::ostream&, const MBOrientedBox& );
-
-double MBOrientedBox::inner_radius() const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return length[0];
-#else
-  return axis[0].length();
-#endif
-}
-
-double MBOrientedBox::outer_radius() const
-{
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  return radius;
-#elif MB_ORIENTED_BOX_UNIT_VECTORS
-  return length.length();
-#else
-  return (axis[0] + axis[1] + axis[2]).length();
-#endif
-}
-
-// Add at least epsilon to the radius, before squaring it.
-double MBOrientedBox::outer_radius_squared(const double reps) const
-{
-#if MB_ORIENTED_BOX_OUTER_RADIUS
-  return (radius+reps)*(radius+reps);
-#elif MB_ORIENTED_BOX_UNIT_VECTORS
-  MBCartVect tmp(length[0]+reps,length[1]+reps,length[2]+reps);
-  return tmp % tmp;
-#else
-  MBCartVect half_diag = axis[0] + axis[1] + axis[2];
-  half_diag += MBCartVect(reps,reps,reps);
-  return half_diag % half_diag;
-#endif
-}
-
-// Subtract epsilon from the length of the shortest axis, before squaring it.
-double MBOrientedBox::inner_radius_squared(const double reps) const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return (length[0]-reps) * (length[0]-reps);
-#else
-  MBCartVect tmp = axis[0];
-  tmp -= MBCartVect(reps,reps,reps);
-  return (tmp % tmp);
-#endif
-}
-
-double MBOrientedBox::volume() const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return 8 * length[0] * length[1] * length[2];
-#else
-  return fabs(8 * axis[0] % (axis[1] * axis[2]));
-#endif
-}
-
-MBCartVect MBOrientedBox::dimensions() const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return 2.0 * length;
-#else
-  return 2.0 * MBCartVect( axis[0].length(), axis[1].length(), axis[2].length() );
-#endif
-}
-
-double MBOrientedBox::area() const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return 4 * length[1] * length[2];
-#else
-  return 4 * (axis[1] * axis[2]).length();
-#endif
-}
-
-MBCartVect MBOrientedBox::scaled_axis( int index ) const
-{
-#if MB_ORIENTED_BOX_UNIT_VECTORS
-  return length[index] * axis[index];
-#else
-  return axis[index];
-#endif
-}
-
-
-#endif

Deleted: MOAB/trunk/src/MBOrientedBoxTreeTool.cpp
===================================================================
--- MOAB/trunk/src/MBOrientedBoxTreeTool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBOrientedBoxTreeTool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1962 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBOrientedBox.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBTagConventions.hpp"
-#include <iostream>
-#include <iomanip>
-#include <algorithm>
-#include <limits>
-#include <assert.h>
-#include <math.h>
-
-//#define MB_OBB_USE_VECTOR_QUERIES
-//#define MB_OBB_USE_TYPE_QUERIES
-
-#if defined(MB_OBB_USE_VECTOR_QUERIES) && defined(MB_OBB_USE_TYPE_QUERIES)
-# undef MB_OBB_USE_TYPE_QUERIES
-#endif
-
-const char DEFAULT_TAG_NAME[] = "OBB";
-
-MBOrientedBoxTreeTool::Op::~Op() {}
-
-MBOrientedBoxTreeTool::MBOrientedBoxTreeTool( MBInterface* i,
-                                              const char* tag_name,
-                                              bool destroy_created_trees )
-  : instance( i ), cleanUpTrees(destroy_created_trees)
-{
-  if (!tag_name)
-    tag_name = DEFAULT_TAG_NAME;
-  MBErrorCode rval = MBOrientedBox::tag_handle( tagHandle, instance, tag_name, true );
-  if (MB_SUCCESS != rval)
-    tagHandle = 0;
-}
-
-MBOrientedBoxTreeTool::~MBOrientedBoxTreeTool()
-{
-  if (!cleanUpTrees)
-    return;
-    
-  while (!createdTrees.empty()) {
-    MBEntityHandle tree = createdTrees.back();
-      // make sure this is a tree (rather than some other, stale handle)
-    const void* data_ptr = 0;
-    MBErrorCode rval = instance->tag_get_data( tagHandle, &tree, 1, &data_ptr );
-    if (MB_SUCCESS == rval)
-      rval = delete_tree( tree );
-    if (MB_SUCCESS != rval)
-      createdTrees.pop_back();
-  }
-}
-
-MBOrientedBoxTreeTool::Settings::Settings() 
-  : max_leaf_entities( 8 ),
-    max_depth( 0 ),
-    worst_split_ratio( 0.95 ),
-    best_split_ratio( 0.4 ),
-    set_options( MESHSET_SET )
-  {}
-
-bool MBOrientedBoxTreeTool::Settings::valid() const
-{
-  return max_leaf_entities > 0 
-      && max_depth >= 0
-      && worst_split_ratio <= 1.0
-      && best_split_ratio >= 0.0
-      && worst_split_ratio >= best_split_ratio
-      ;
-}
-
-
-/********************** Simple Tree Access Methods ****************************/
-
-
-MBErrorCode MBOrientedBoxTreeTool::box( MBEntityHandle set, MBOrientedBox& obb )
-{
-  return instance->tag_get_data( tagHandle, &set, 1, &obb );
-}
-
-MBErrorCode MBOrientedBoxTreeTool::box( MBEntityHandle set,
-                                        double center[3],
-                                        double axis1[3],
-                                        double axis2[3],
-                                        double axis3[3] )
-{
-  MBOrientedBox obb;
-  MBErrorCode rval = this->box( set, obb );
-  obb.center.get( center );
-  obb.scaled_axis(0).get( axis1 );
-  obb.scaled_axis(1).get( axis2 );
-  obb.scaled_axis(2).get( axis3 );
-  return rval;
-}
-
-
-/********************** Tree Construction Code ****************************/
-
-
-struct MBOrientedBoxTreeTool::SetData {
-  MBEntityHandle handle;
-  MBOrientedBox::CovarienceData box_data;
-  //MBRange vertices;
-};
-
-
-MBErrorCode MBOrientedBoxTreeTool::build( const MBRange& entities,
-                                          MBEntityHandle& set_handle_out,
-                                          const Settings* settings )
-{
-  if (!entities.all_of_dimension(2))
-    return MB_TYPE_OUT_OF_RANGE;
-  if (settings && !settings->valid())
-    return MB_FAILURE;
-    
-  return build_tree( entities, set_handle_out, 0, 
-                     settings ? *settings : Settings() );
-}
-
-MBErrorCode MBOrientedBoxTreeTool::join_trees( const MBRange& sets,
-                                               MBEntityHandle& set_handle_out,
-                                               const Settings* settings )
-{
-  if (!sets.all_of_type(MBENTITYSET))
-    return MB_TYPE_OUT_OF_RANGE;
-  if (settings && !settings->valid())
-    return MB_FAILURE;
-  
-    // Build initial set data list.
-  std::list<SetData> data;
-  for (MBRange::const_iterator i = sets.begin(); i != sets.end(); ++i) {
-    MBRange elements;
-    MBErrorCode rval = instance->get_entities_by_dimension( *i, 2, elements, true );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (elements.empty())
-      continue;
-    
-    data.push_back( SetData() );
-    SetData& set_data = data.back();
-    set_data.handle = *i;
-    rval = MBOrientedBox::covariance_data_from_tris( set_data.box_data, instance, elements );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-
-  MBErrorCode result = build_sets( data, set_handle_out, 0, 
-                          settings ? *settings : Settings() );
-  if (MB_SUCCESS != result)
-    return result;
-  
-  for (MBRange::reverse_iterator i = sets.rbegin(); i != sets.rend(); ++i) {
-    createdTrees.erase(
-      std::remove( createdTrees.begin(), createdTrees.end(), *i ), 
-      createdTrees.end() );
-  }
-  createdTrees.push_back( set_handle_out );
-  return MB_SUCCESS;
-}
-  
-
-/**\brief Split triangles by which side of a plane they are on
- *
- * Given a plane specified as a bisecting plane normal to one
- * of the axes of a box, split triangles based on which side
- * of the plane they are on.
- *\param instance   MOAB instance
- *\param box        The oriented box containing all the entities
- *\param axis       The axis for which the split plane is orthogonal
- *\param left_list  Output, entities to the left of the plane
- *\param right_list Output, entities to the right of the plane
- *\param num_intersecting Output, number entities intersecting plane
- */
-static MBErrorCode split_box( MBInterface* instance, 
-                              const MBOrientedBox& box, 
-                              int axis, 
-                              const MBRange& entities, 
-                              MBRange& left_list, 
-                              MBRange& right_list )
-{
-  MBErrorCode rval;
-  left_list.clear();
-  right_list.clear();
-
-  std::vector<MBCartVect> coords;
-  for (MBRange::reverse_iterator i = entities.rbegin(); i != entities.rend(); ++i) {
-    const MBEntityHandle *conn;
-    int conn_len;
-    rval = instance->get_connectivity( *i, conn, conn_len );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    coords.resize( conn_len );
-    rval = instance->get_coords( conn, conn_len, coords[0].array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    MBCartVect centroid(0.0);
-    for (int j = 0; j < conn_len; ++j)
-      centroid += coords[j];
-    centroid /= conn_len;
-    
-    if ((box.axis[axis] % (centroid - box.center)) < 0.0)
-      left_list.insert( *i );
-    else
-      right_list.insert( *i );
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBOrientedBoxTreeTool::build_tree( const MBRange& entities,
-                                               MBEntityHandle& set,
-                                               int depth,
-                                               const Settings& settings )
-{
-  MBOrientedBox box;
-  MBErrorCode rval;
-  
-  if (entities.empty()) {
-    MBCartVect axis[3] = { MBCartVect(0.), MBCartVect(0.), MBCartVect(0.) };
-    box = MBOrientedBox( axis, MBCartVect(0.) );
-  }
-  else {
-    rval = MBOrientedBox::compute_from_2d_cells( box, instance, entities );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-    // create an entity set for the tree node
-  rval = instance->create_meshset( settings.set_options, set );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = instance->tag_set_data( tagHandle, &set, 1, &box );
-  if (MB_SUCCESS != rval) 
-    { delete_tree( set ); return rval; }
-  
-    // check if should create children
-  bool leaf = true;
-  ++depth;
-  if ((!settings.max_depth || depth < settings.max_depth) && 
-      entities.size() > (unsigned)settings.max_leaf_entities) {
-      // try splitting with planes normal to each axis of the box
-      // until we find an acceptable split
-    double best_ratio = settings.worst_split_ratio; // worst case ratio
-    MBRange best_left_list, best_right_list;
-      // Axes are sorted from shortest to longest, so search backwards
-    for (int axis = 2; best_ratio > settings.best_split_ratio && axis >= 0; --axis) {
-      MBRange left_list, right_list;
-
-      rval = split_box( instance, box, axis, entities, left_list, right_list );
-      if (MB_SUCCESS != rval) 
-        { delete_tree( set ); return rval; }
-        
-      double ratio = fabs((double)right_list.size() - left_list.size()) / entities.size();
-      
-      if (ratio < best_ratio) {
-        best_ratio = ratio;
-        best_left_list.swap( left_list );
-        best_right_list.swap( right_list );
-      }
-    }
-    
-      // create children
-    if (!best_left_list.empty())
-    {
-      MBEntityHandle child = 0;
-      
-      rval = build_tree( best_left_list, child, depth, settings );
-      if (MB_SUCCESS != rval)
-        { delete_tree( set ); return rval; }
-      rval = instance->add_child_meshset( set, child );
-      if (MB_SUCCESS != rval)
-        { delete_tree( set ); delete_tree( child ); return rval; }
-      
-      rval = build_tree( best_right_list, child, depth, settings );
-      if (MB_SUCCESS != rval)
-        { delete_tree( set ); return rval; }
-      rval = instance->add_child_meshset( set, child );
-      if (MB_SUCCESS != rval)
-        { delete_tree( set ); delete_tree( child ); return rval; }
-      
-      leaf = false;
-    }
-  }
-  
-  if (leaf)
-  {
-    rval = instance->add_entities( set, entities );
-    if (MB_SUCCESS != rval) 
-      { delete_tree( set ); return rval; }
-  }
-  
-  createdTrees.push_back( set );
-  return MB_SUCCESS;
-}
-
-
-static MBErrorCode split_sets( MBInterface* , 
-                               const MBOrientedBox& box, 
-                               int axis, 
-                               const std::list<MBOrientedBoxTreeTool::SetData>& sets,
-                               std::list<MBOrientedBoxTreeTool::SetData>& left,
-                               std::list<MBOrientedBoxTreeTool::SetData>& right )
-{
-  left.clear();
-  right.clear();
-
-  std::list<MBOrientedBoxTreeTool::SetData>::const_iterator i;
-  for (i = sets.begin(); i != sets.end(); ++i) {
-    MBCartVect centroid(i->box_data.center / i->box_data.area);
-    if ((box.axis[axis] % (centroid - box.center)) < 0.0)
-      left.push_back( *i );
-    else
-      right.push_back( *i );
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBOrientedBoxTreeTool::build_sets( std::list<SetData>& sets,
-                                               MBEntityHandle& node_set,
-                                               int depth,
-                                               const Settings& settings )
-{
-  MBErrorCode rval;
-  int count = sets.size();
-  if (0 == count)
-    return MB_FAILURE;
-  
-    // calculate box
-  MBOrientedBox box;
-
-  // make vector go out of scope when done, so memory is released
-  { 
-    MBRange elems;
-    std::vector<MBOrientedBox::CovarienceData> data(sets.size());
-    data.clear();
-    for (std::list<SetData>::iterator i = sets.begin(); i != sets.end(); ++i) {
-      data.push_back( i->box_data );
-      rval = instance->get_entities_by_dimension( i->handle, 2, elems, true );
-      if (MB_SUCCESS != rval)
-        return rval;
-    }
-    
-    MBRange points;
-    rval = instance->get_adjacencies( elems, 0, false, points, MBInterface::UNION );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    rval = MBOrientedBox::compute_from_covariance_data( box, instance, &data[0], data.size(), points );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-    // If only one set in list...
-  if (count == 1) {
-    node_set = sets.front().handle;
-    return instance->tag_set_data( tagHandle, &node_set, 1, &box );
-  }
-  
-    // create an entity set for the tree node
-  rval = instance->create_meshset( settings.set_options, node_set );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = instance->tag_set_data( tagHandle, &node_set, 1, &box );
-  if (MB_SUCCESS != rval) 
-    { delete_tree( node_set ); return rval; }
-  
-  double best_ratio = 2.0; 
-  std::list<SetData> best_left_list, best_right_list;
-  for (int axis = 0; axis < 2; ++axis) {
-    std::list<SetData> left_list, right_list;
-    rval = split_sets( instance, box, axis, sets, left_list, right_list );
-    if (MB_SUCCESS != rval) 
-      { delete_tree( node_set ); return rval; }
-
-    double ratio = fabs((double)right_list.size() - left_list.size()) / sets.size();
-
-    if (ratio < best_ratio) {
-      best_ratio = ratio;
-      best_left_list.swap( left_list );
-      best_right_list.swap( right_list );
-    }
-  }
-  
-    // We must subdivide the list of sets, because we want to guarantee that
-    // there is a node in the tree corresponding to each of the sets.  So if
-    // we couldn't find a usable split plane, just split them in an arbitrary
-    // manner.
-  if (best_left_list.empty() || best_right_list.empty()) {
-    best_left_list.clear();
-    best_right_list.clear();
-    std::list<SetData>* lists[2] = {&best_left_list,&best_right_list};
-    int i = 0;
-    while (!sets.empty()) {
-      lists[i]->push_back( sets.front() );
-      sets.pop_front();
-      i = 1 - i;
-    }
-  }
-  else {
-    sets.clear(); // release memory before recursion
-  }
-  
-    // Create child sets
-    
-  MBEntityHandle child = 0;
-      
-  rval = build_sets( best_left_list, child, depth+1, settings );
-  if (MB_SUCCESS != rval)
-    { delete_tree( node_set ); return rval; }
-  rval = instance->add_child_meshset( node_set, child );
-  if (MB_SUCCESS != rval)
-    { delete_tree( node_set ); delete_tree( child ); return rval; }
-
-  rval = build_sets( best_right_list, child, depth+1, settings );
-  if (MB_SUCCESS != rval)
-    { delete_tree( node_set ); return rval; }
-  rval = instance->add_child_meshset( node_set, child );
-  if (MB_SUCCESS != rval)
-    { delete_tree( node_set ); delete_tree( child ); return rval; }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBOrientedBoxTreeTool::delete_tree( MBEntityHandle set )
-{
-  std::vector<MBEntityHandle> children;
-  MBErrorCode rval = instance->get_child_meshsets( set, children, 0 );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  createdTrees.erase( 
-    std::remove( createdTrees.begin(), createdTrees.end(), set ),
-    createdTrees.end() );
-  children.insert( children.begin(), set );
-  return instance->delete_entities( &children[0], children.size() );
-}
-
-
-/********************** Generic Tree Traversal ****************************/
-
-
-struct Data { MBEntityHandle set; int depth; };
-MBErrorCode MBOrientedBoxTreeTool::preorder_traverse( MBEntityHandle set,
-                                                      Op& operation, 
-                                                      TrvStats* accum )
-{
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> children;
-  std::vector<Data> the_stack;
-  Data data = { set, 0 };
-  the_stack.push_back( data );
-  int max_depth = -1;
-  
-  while (!the_stack.empty())
-  {
-    data = the_stack.back();
-    the_stack.pop_back();
-    
-    // increment traversal statistics
-    if( accum ){
-      accum->increment( data.depth );
-      max_depth = std::max( max_depth, data.depth );
-    }
-
-    bool descend = true;
-    rval = operation.visit( data.set, data.depth, descend );
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    if (!descend)
-      continue;
-    
-    children.clear();
-    rval = instance->get_child_meshsets( data.set, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (children.empty()) {
-      if( accum ){ accum->increment_leaf( data.depth ); }
-      rval = operation.leaf( data.set );
-      if (MB_SUCCESS != rval)
-        return rval;
-    }
-    else if (children.size() == 2) {
-      data.depth++;
-      data.set = children[0];
-      the_stack.push_back( data );
-      data.set = children[1];
-      the_stack.push_back( data );
-    }
-    else
-      return MB_MULTIPLE_ENTITIES_FOUND;
-  }
-  
-  if( accum ){
-    accum->end_traversal( max_depth );
-  }
-
-  return MB_SUCCESS;
-}
-
-/********************** General Sphere/Triangle Intersection ***************/
-
-struct MBOBBTreeSITFrame { 
-  MBOBBTreeSITFrame( MBEntityHandle n, MBEntityHandle s, int dp )
-    : node(n), surf(s), depth(dp) {}
-  MBEntityHandle node;
-  MBEntityHandle surf;
-  int depth;
-};
-
-MBErrorCode MBOrientedBoxTreeTool::sphere_intersect_triangles( 
-                                        const double* center_v,
-                                        double radius,
-                                        MBEntityHandle tree_root,
-                                        std::vector<MBEntityHandle>& facets_out,
-                                        std::vector<MBEntityHandle>* sets_out, 
-                                        TrvStats* accum )
-{
-  const double radsqr = radius * radius;
-  MBOrientedBox b;
-  MBErrorCode rval;
-  MBRange sets;
-  const MBCartVect center(center_v);
-  MBCartVect closest, coords[3];
-  const MBEntityHandle* conn;
-  int num_conn;
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-  MBRange tris;
-  MBRange::const_iterator t;
-#else
-  std::vector<MBEntityHandle> tris;
-  std::vector<MBEntityHandle>::const_iterator t;
-#endif
-  
-  std::vector<MBOBBTreeSITFrame> stack;
-  std::vector<MBEntityHandle> children;
-  stack.reserve(30);
-  stack.push_back( MBOBBTreeSITFrame( tree_root, 0, 0 ) );
-
-  int max_depth = -1;
-
-  while (!stack.empty()) {
-    MBEntityHandle surf = stack.back().surf; 
-    MBEntityHandle node = stack.back().node;
-    int current_depth   = stack.back().depth;
-    stack.pop_back();
-    
-      // increment traversal statistics.  
-    if( accum ){
-      accum->increment( current_depth );
-      max_depth = std::max( max_depth, current_depth );
-    }
-
-    if (!surf && sets_out) {
-      rval = get_moab_instance()->get_entities_by_type( node, MBENTITYSET, sets );
-      if (!sets.empty())
-        surf = sets.front();
-      sets.clear();
-    }
-    
-      // check if sphere intersects box
-    rval = box( node, b );
-    if (MB_SUCCESS != rval)
-      return rval;
-    b.closest_location_in_box( center, closest );
-    closest -= center;
-    if ((closest % closest) > radsqr)
-      continue;
-    
-      // push child boxes on stack
-    children.clear();
-    rval = instance->get_child_meshsets( node, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (!children.empty()) {
-      assert(children.size() == 2);
-      stack.push_back( MBOBBTreeSITFrame( children[0], surf, current_depth + 1 ) );
-      stack.push_back( MBOBBTreeSITFrame( children[1], surf, current_depth + 1 ) );
-      continue;
-    }
-    
-    if(accum){ accum->increment_leaf( current_depth ); }
-      // if leaf, intersect sphere with triangles
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-# ifdef MB_OBB_USE_TYPE_QUERIES
-    rval = get_moab_instance()->get_entities_by_type( node, MBTRI, tris );
-# else
-    rval = get_moab_instance()->get_entities_by_handle( node, tris );
-# endif
-    t = tris.begin();
-#else
-    rval = get_moab_instance()->get_entities_by_handle( node, tris );
-    t = tris.lower_bound( MBTRI );
-#endif
-    if (MB_SUCCESS != rval)
-      return rval;
-    
-    for (t = tris.begin(); t != tris.end(); ++t) {
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-      if (TYPE_FROM_HANDLE(*t) != MBTRI)
-        break;
-#elif !defined(MB_OBB_USE_TYPE_QUERIES)
-      if (TYPE_FROM_HANDLE(*t) != MBTRI)
-        continue;
-#endif      
-      rval = get_moab_instance()->get_connectivity( *t, conn, num_conn, true );
-      if (MB_SUCCESS != rval)
-        return rval;
-      if (num_conn != 3)
-        continue;
-      
-      rval = get_moab_instance()->get_coords( conn, num_conn, coords[0].array() );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      MBGeomUtil::closest_location_on_tri( center, coords, closest );
-      closest -= center;
-      if ((closest % closest) <= radsqr &&
-          std::find(facets_out.begin(),facets_out.end(),*t) == facets_out.end()) {
-        facets_out.push_back( *t );
-        if (sets_out)
-          sets_out->push_back( surf );
-      }
-    }
-  }
-
-  if( accum ){
-    accum->end_traversal( max_depth );
-  }
-  
-  return MB_SUCCESS;
-}
-      
-
-
-/********************** General Ray/Tree and Ray/Triangle Intersection ***************/
-
-
-class RayIntersector : public MBOrientedBoxTreeTool::Op
-{
-  private:
-    MBOrientedBoxTreeTool* tool;
-    const MBCartVect b, m;
-    const double* len;
-    const double tol;
-    MBRange& boxes;
-    
-  public:
-    RayIntersector( MBOrientedBoxTreeTool* tool_ptr,
-                    const double* ray_point,
-                    const double* unit_ray_dir,
-                    const double *ray_length,
-                    double tolerance,
-                    MBRange& leaf_boxes )
-      : tool(tool_ptr),
-        b(ray_point), m(unit_ray_dir),
-        len(ray_length), tol(tolerance),
-        boxes(leaf_boxes) 
-      { }
-  
-    virtual MBErrorCode visit( MBEntityHandle node,
-                               int depth,
-                               bool& descend );
-    virtual MBErrorCode leaf( MBEntityHandle node );
-};
-
-//#include <stdio.h>
-//inline void dump_fragmentation( const MBRange& range ) {
-//  static FILE* file = fopen( "fragmentation", "w" );
-//  unsigned ranges = 0, entities = 0;
-//  for (MBRange::const_pair_iterator i = range.const_pair_begin(); i != range.const_pair_end(); ++i)
-//  {
-//    ++ranges;
-//    entities += i->second - i->first + 1;
-//  }
-//  fprintf( file, "%u %u\n", ranges, entities );
-//}
-
-MBErrorCode MBOrientedBoxTreeTool::ray_intersect_triangles( 
-                          std::vector<double>& intersection_distances_out,
-                          const MBRange& boxes,
-                          double tolerance,
-                          const double ray_point[3],
-                          const double unit_ray_dir[3],
-                          const double* ray_length )
-{
-  MBErrorCode rval;
-  intersection_distances_out.clear();
-  std::vector<MBEntityHandle> tris;
-    
-  const MBCartVect point( ray_point );
-  const MBCartVect dir( unit_ray_dir );
-  
-  for (MBRange::iterator b = boxes.begin(); b != boxes.end(); ++b)
-  {
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-    MBRange tris;
-# ifdef MB_OBB_USE_TYPE_QUERIES
-    rval = instance->get_entities_by_type( *b, MBTRI, tris );
-# else
-    rval = instance->get_entities_by_handle( *b, tris );
-# endif
-#else
-    tris.clear();
-    rval = instance->get_entities_by_handle( *b, tris );
-#endif
-    if (MB_SUCCESS != rval)
-      return rval;
-//dump_fragmentation( tris );
-    
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-    for (MBRange::iterator t = tris.begin(); t != tris.end(); ++t)
-#else
-    for (std::vector<MBEntityHandle>::iterator t = tris.begin(); t != tris.end(); ++t)
-#endif
-    {
-#ifndef MB_OBB_USE_TYPE_QUERIES
-      if (TYPE_FROM_HANDLE(*t) != MBTRI)
-        continue;
-#endif
-    
-      const MBEntityHandle* conn;
-      int len;
-      rval = instance->get_connectivity( *t, conn, len, true );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      MBCartVect coords[3];
-      rval = instance->get_coords( conn, 3, coords[0].array() );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      double td;
-      if (MBGeomUtil::ray_tri_intersect( coords, point, dir, tolerance, td, ray_length ))
-        intersection_distances_out.push_back(td);
-    }
-  }
-  
-  return MB_SUCCESS;
-}                    
-
-MBErrorCode MBOrientedBoxTreeTool::ray_intersect_triangles( 
-                          std::vector<double>& intersection_distances_out,
-                          MBEntityHandle root_set,
-                          double tolerance,
-                          const double ray_point[3],
-                          const double unit_ray_dir[3],
-                          const double* ray_length, 
-                          TrvStats* accum )
-{
-  MBRange boxes;
-  MBErrorCode rval;
-  
-  rval = ray_intersect_boxes( boxes, root_set, tolerance, ray_point, unit_ray_dir, ray_length, accum );
-  if (MB_SUCCESS != rval)
-    return rval;
-    
-  return ray_intersect_triangles( intersection_distances_out, boxes, tolerance, ray_point, unit_ray_dir, ray_length );
-}
-
-MBErrorCode MBOrientedBoxTreeTool::ray_intersect_boxes( 
-                          MBRange& boxes_out,
-                          MBEntityHandle root_set,
-                          double tolerance,
-                          const double ray_point[3],
-                          const double unit_ray_dir[3],
-                          const double* ray_length, 
-                          TrvStats* accum )
-{
-  RayIntersector op( this, ray_point, unit_ray_dir, ray_length, tolerance, boxes_out );
-  return preorder_traverse( root_set, op, accum );
-}
-
-MBErrorCode RayIntersector::visit( MBEntityHandle node,
-                                   int ,
-                                   bool& descend ) 
-{
-  MBOrientedBox box;
-  MBErrorCode rval = tool->box( node, box );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  descend = box.intersect_ray( b, m, tol, len);
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode RayIntersector::leaf( MBEntityHandle node )
-{
-  boxes.insert(node);
-  return MB_SUCCESS;
-}
-
-
-/********************** Ray/Set Intersection ****************************/
-
-
-class RayIntersectSets : public MBOrientedBoxTreeTool::Op
-{
-  private:
-    MBOrientedBoxTreeTool* tool;
-    unsigned minTolInt;
-    const MBCartVect b, m;
-    const double* len;
-    const double tol;
-    std::vector<double>& intersections;
-    std::vector<MBEntityHandle>& sets;
-    std::vector<MBEntityHandle>& facets;    
-
-  MBEntityHandle lastSet;
-    int lastSetDepth;
-    
-  void add_intersection( double t, MBEntityHandle facet );
-    
-  public:
-    RayIntersectSets( MBOrientedBoxTreeTool* tool_ptr,
-                   const double* ray_point,
-                   const double* unit_ray_dir,
-                   const double *ray_length,
-                   double tolerance,
-                   unsigned min_tol_intersections,
-                   std::vector<double>& intersections,
-                   std::vector<MBEntityHandle>& surfaces,
-                   std::vector<MBEntityHandle>& facets )
-      : tool(tool_ptr), minTolInt(min_tol_intersections),
-        b(ray_point), m(unit_ray_dir),
-        len(ray_length), tol(tolerance),
-        intersections(intersections),
-        sets(surfaces), facets(facets), lastSet(0)
-      { }
-  
-    virtual MBErrorCode visit( MBEntityHandle node,
-                               int depth,
-                               bool& descend );
-    virtual MBErrorCode leaf( MBEntityHandle node );
-};
-
-MBErrorCode RayIntersectSets::visit( MBEntityHandle node,
-                                     int depth,
-                                     bool& descend ) 
-{
-  MBOrientedBox box;
-  MBErrorCode rval = tool->box( node, box );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  descend = box.intersect_ray( b, m, tol, len);
-  
-  if (lastSet && depth <= lastSetDepth)
-    lastSet = 0;
-
-  if (descend && !lastSet) {
-    MBRange sets;
-    rval = tool->get_moab_instance()->get_entities_by_type( node, MBENTITYSET, sets );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    if (!sets.empty()) {
-      if (sets.size() > 1)
-        return MB_FAILURE;
-      lastSet = *sets.begin();
-      lastSetDepth = depth;
-    }
-  }
-    
-  return MB_SUCCESS;
-}
-
-MBErrorCode RayIntersectSets::leaf( MBEntityHandle node )
-{
-  if (!lastSet) // if no surface has been visited yet, something's messed up.
-    return MB_FAILURE;
-  
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-  MBRange tris;
-# ifdef MB_OBB_USE_TYPE_QUERIES
-  MBErrorCode rval = tool->get_moab_instance()->get_entities_by_type( node, MBTRI, tris );
-# else
-  MBErrorCode rval = tool->get_moab_instance()->get_entities_by_handle( node, tris );
-# endif
-#else
-  std::vector<MBEntityHandle> tris;
-  MBErrorCode rval = tool->get_moab_instance()->get_entities_by_handle( node, tris );
-#endif
-  if (MB_SUCCESS != rval)
-    return rval;
-
-#ifndef MB_OBB_USE_VECTOR_QUERIES
-  for (MBRange::iterator t = tris.begin(); t != tris.end(); ++t)
-#else
-  for (std::vector<MBEntityHandle>::iterator t = tris.begin(); t != tris.end(); ++t)
-#endif
-  {
-#ifndef MB_OBB_USE_TYPE_QUERIES
-    if (TYPE_FROM_HANDLE(*t) != MBTRI)
-      continue;
-#endif
-    
-    const MBEntityHandle* conn;
-    int num_conn;
-    rval = tool->get_moab_instance()->get_connectivity( *t, conn, num_conn, true );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    MBCartVect coords[3];
-    rval = tool->get_moab_instance()->get_coords( conn, 3, coords[0].array() );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    double td;
-    if (MBGeomUtil::ray_tri_intersect( coords, b, m, tol, td, len )) 
-        // NOTE: add_intersection may modify the 'len' member, which
-        //       will affect subsequent calls to ray_tri_intersect in 
-        //       this loop.
-      add_intersection( td, *t );
-  }
-  return MB_SUCCESS;
-}
-
-void RayIntersectSets::add_intersection( double t, MBEntityHandle facet )
-{
-    // Check if the 'len' pointer is pointing into the intersection
-    // list.  If this is the case, then the list contains, at that
-    // location, an intersection greater than the tolerance away from
-    // the base point of the ray.
-  int len_idx = -1;
-  if (len && len >= &intersections[0] && len < &intersections[0] + intersections.size())
-    len_idx = len - &intersections[0];
-
-    // If the intersection is within tol of the ray base point, we 
-    // always add it to the list.
-  if (t <= tol) {
-      // If the list contains an intersection outside the tolerance...
-    if (len_idx >= 0) {
-        // If we no longer want an intersection outside the tolerance,
-        // remove it.
-      if (intersections.size() >= minTolInt) {
-        intersections[len_idx] = t;
-        sets[len_idx] = lastSet;
-        facets[len_idx] = facet;
-          // From now on, we want only intersections within the tolerance,
-          // so update length accordingly
-        len = &tol;
-      }
-        // Otherwise appended to the list and update pointer
-      else {
-        intersections.push_back(t);
-        sets.push_back(lastSet);
-        facets.push_back(facet);
-        len = &intersections[len_idx];
-      }
-    }
-      // Otherwise just append it
-    else {
-      intersections.push_back(t);
-      sets.push_back(lastSet);
-      facets.push_back(facet);
-        // If we have all the intersections we want, set
-        // length such that we will only find further intersections
-        // within the tolerance
-      if (intersections.size() >= minTolInt)
-        len = &tol;
-    }
-  }
-    // Otherwise the intersection is outside the tolerance
-    // If we already have an intersection outside the tolerance and
-    // this one is closer, replace the existing one with this one.
-  else if (len_idx >= 0) {
-    if (t <= *len) {
-      intersections[len_idx] = t;
-      sets[len_idx] = lastSet;
-      facets[len_idx] = facet;
-    }
-  }
-    // Otherwise if we want an intersection outside the tolerance
-    // and don'thave one yet, add it.
-  else if (intersections.size() < minTolInt) {
-    intersections.push_back( t );
-    sets.push_back( lastSet );
-    facets.push_back(facet);
-      // update length.  this is currently the closest intersection, so
-      // only want further intersections that are closer than this one.
-    len = &intersections.back();
-  }
-}
-  
-
-MBErrorCode MBOrientedBoxTreeTool::ray_intersect_sets( 
-                                    std::vector<double>& distances_out,
-                                    std::vector<MBEntityHandle>& sets_out,
-                                    std::vector<MBEntityHandle>& facets_out,
-                                    MBEntityHandle root_set,
-                                    double tolerance,
-                                    unsigned min_tolerace_intersections,
-                                    const double ray_point[3],
-                                    const double unit_ray_dir[3],
-                                    const double* ray_length, 
-                                    TrvStats* accum )
-{
-  RayIntersectSets op( this, ray_point, unit_ray_dir, ray_length, tolerance, 
-                       min_tolerace_intersections, distances_out, sets_out, facets_out ); 
-  return preorder_traverse( root_set, op, accum );
-}
-
-
-
-/********************** Closest Point code ***************/
-
-struct MBOBBTreeCPFrame {
-  MBOBBTreeCPFrame( double d, MBEntityHandle n, MBEntityHandle s, int dp )
-    : dist_sqr(d), node(n), mset(s), depth(dp) {}
-  double dist_sqr;
-  MBEntityHandle node;
-  MBEntityHandle mset;
-  int depth;
-};
-
-MBErrorCode MBOrientedBoxTreeTool::closest_to_location( 
-                                     const double* point,
-                                     MBEntityHandle root,
-                                     double* point_out,
-                                     MBEntityHandle& facet_out,
-                                     MBEntityHandle* set_out,
-                                     TrvStats* accum ) 
-{
-  MBErrorCode rval;
-  const MBCartVect loc( point );
-  double smallest_dist_sqr = std::numeric_limits<double>::max();
-  
-  MBEntityHandle current_set = 0;
-  MBRange sets;
-  std::vector<MBEntityHandle> children(2);
-  std::vector<double> coords;
-  std::vector<MBOBBTreeCPFrame> stack;
-  int max_depth = -1;
-
-  stack.push_back( MBOBBTreeCPFrame(0.0, root, current_set, 0) );
-  
-  while( !stack.empty() ) {
-
-      // pop from top of stack
-    MBEntityHandle node = stack.back().node;
-    double dist_sqr = stack.back().dist_sqr;
-    current_set = stack.back().mset;
-    int current_depth = stack.back().depth;
-    stack.pop_back();
-
-      // If current best result is closer than the box, skip this tree node.
-    if (dist_sqr > smallest_dist_sqr)
-      continue;
-
-      // increment traversal statistics.  
-    if( accum ){
-      accum->increment( current_depth );
-      max_depth = std::max( max_depth, current_depth );
-    }
-
-      // Check if this node has a set associated with it
-    if (set_out && !current_set) {
-      sets.clear();
-      rval = instance->get_entities_by_type( node, MBENTITYSET, sets );
-      if (MB_SUCCESS != rval)
-        return rval;
-      if (!sets.empty()) {
-        if (sets.size() != 1)
-          return MB_MULTIPLE_ENTITIES_FOUND;
-        current_set = sets.front();
-      }
-    }
-
-      // Get child boxes
-    children.clear();
-    rval = instance->get_child_meshsets( node, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-      // if not a leaf node
-    if (!children.empty()) {
-      if (children.size() != 2)
-        return MB_MULTIPLE_ENTITIES_FOUND;
-    
-        // get boxes
-      MBOrientedBox box1, box2;
-      rval = box( children[0], box1 );
-      if (MB_SUCCESS != rval) return rval;
-      rval = box( children[1], box2 );
-      if (MB_SUCCESS != rval) return rval;
-      
-        // get distance from each box
-      MBCartVect pt1, pt2;
-      box1.closest_location_in_box( loc, pt1 );
-      box2.closest_location_in_box( loc, pt2 );
-      pt1 -= loc;
-      pt2 -= loc;
-      const double dsqr1 = pt1 % pt1;
-      const double dsqr2 = pt2 % pt2;
-      
-        // push children on tree such that closer one is on top
-      if (dsqr1 < dsqr2) {
-        stack.push_back( MBOBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
-        stack.push_back( MBOBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
-      }
-      else {
-        stack.push_back( MBOBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
-        stack.push_back( MBOBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
-      }
-    }
-    else { // LEAF NODE
-      if( accum ){ accum->increment_leaf( current_depth ); }
-
-      MBRange facets;
-      rval = instance->get_entities_by_dimension( node, 2, facets );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      const MBEntityHandle* conn;
-      int len;
-      MBCartVect tmp, diff;
-      for (MBRange::iterator i = facets.begin(); i != facets.end(); ++i) {
-        rval = instance->get_connectivity( *i, conn, len, true );
-        if (MB_SUCCESS != rval)
-          return rval;
-        
-        coords.resize(3*len);
-        rval = instance->get_coords( conn, len, &coords[0] );
-        if (MB_SUCCESS != rval)
-          return rval;
-        
-        if (len == 3) 
-          MBGeomUtil::closest_location_on_tri( loc, (MBCartVect*)(&coords[0]), tmp );
-        else
-          MBGeomUtil::closest_location_on_polygon( loc, (MBCartVect*)(&coords[0]), len, tmp );
-        
-        diff = tmp - loc;
-        dist_sqr = diff % diff;
-        if (dist_sqr < smallest_dist_sqr) {
-          smallest_dist_sqr = dist_sqr;
-          facet_out = *i;
-          tmp.get( point_out );
-          if (set_out)
-            *set_out = current_set;
-        }
-      }
-    } // LEAF NODE
-  }
-
-  if( accum ){
-    accum->end_traversal( max_depth );
-  }
-  
-  return MB_SUCCESS;
-}
-                                     
-MBErrorCode MBOrientedBoxTreeTool::closest_to_location( const double* point,
-                                     MBEntityHandle root,
-                                     double tolerance,
-                                     std::vector<MBEntityHandle>& facets_out,
-                                     std::vector<MBEntityHandle>* sets_out, 
-                                     TrvStats* accum )
-{
-  MBErrorCode rval;
-  const MBCartVect loc( point );
-  double smallest_dist_sqr = std::numeric_limits<double>::max();
-  double smallest_dist = smallest_dist_sqr;
-  
-  MBEntityHandle current_set = 0;
-  MBRange sets;
-  std::vector<MBEntityHandle> children(2);
-  std::vector<double> coords;
-  std::vector<MBOBBTreeCPFrame> stack;
-  int max_depth = -1;
-
-  stack.push_back( MBOBBTreeCPFrame(0.0, root, current_set, 0) );
-  
-  while( !stack.empty() ) {
-
-      // pop from top of stack
-    MBEntityHandle node = stack.back().node;
-    double dist_sqr = stack.back().dist_sqr;
-    current_set = stack.back().mset;
-    int current_depth = stack.back().depth;
-    stack.pop_back();
-
-      // If current best result is closer than the box, skip this tree node.
-    if (dist_sqr > smallest_dist_sqr + tolerance)
-      continue;
-
-      // increment traversal statistics.  
-    if( accum ){
-      accum->increment( current_depth );
-      max_depth = std::max( max_depth, current_depth );
-    }
-
-      // Check if this node has a set associated with it
-    if (sets_out && !current_set) {
-      sets.clear();
-      rval = instance->get_entities_by_type( node, MBENTITYSET, sets );
-      if (MB_SUCCESS != rval)
-        return rval;
-      if (!sets.empty()) {
-        if (sets.size() != 1)
-          return MB_MULTIPLE_ENTITIES_FOUND;
-        current_set = *sets.begin();
-      }
-    }
-
-      // Get child boxes
-    children.clear();
-    rval = instance->get_child_meshsets( node, children );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-      // if not a leaf node
-    if (!children.empty()) {
-      if (children.size() != 2)
-        return MB_MULTIPLE_ENTITIES_FOUND;
-    
-        // get boxes
-      MBOrientedBox box1, box2;
-      rval = box( children[0], box1 );
-      if (MB_SUCCESS != rval) return rval;
-      rval = box( children[1], box2 );
-      if (MB_SUCCESS != rval) return rval;
-      
-        // get distance from each box
-      MBCartVect pt1, pt2;
-      box1.closest_location_in_box( loc, pt1 );
-      box2.closest_location_in_box( loc, pt2 );
-      pt1 -= loc;
-      pt2 -= loc;
-      const double dsqr1 = pt1 % pt1;
-      const double dsqr2 = pt2 % pt2;
-      
-        // push children on tree such that closer one is on top
-      if (dsqr1 < dsqr2) {
-        stack.push_back( MBOBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
-        stack.push_back( MBOBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
-      }
-      else {
-        stack.push_back( MBOBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
-        stack.push_back( MBOBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
-      }
-    }
-    else { // LEAF NODE
-      if( accum ){ accum->increment_leaf( current_depth ); }
-
-      MBRange facets;
-      rval = instance->get_entities_by_dimension( node, 2, facets );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      const MBEntityHandle* conn;
-      int len;
-      MBCartVect tmp, diff;
-      for (MBRange::iterator i = facets.begin(); i != facets.end(); ++i) {
-        rval = instance->get_connectivity( *i, conn, len, true );
-        if (MB_SUCCESS != rval)
-          return rval;
-        
-        coords.resize(3*len);
-        rval = instance->get_coords( conn, len, &coords[0] );
-        if (MB_SUCCESS != rval)
-          return rval;
-        
-        if (len == 3) 
-          MBGeomUtil::closest_location_on_tri( loc, (MBCartVect*)(&coords[0]), tmp );
-        else
-          MBGeomUtil::closest_location_on_polygon( loc, (MBCartVect*)(&coords[0]), len, tmp );
-        
-        diff = tmp - loc;
-        dist_sqr = diff % diff;
-        if (dist_sqr < smallest_dist_sqr) {
-          if (0.5*dist_sqr < 0.5*smallest_dist_sqr + tolerance*(0.5*tolerance - smallest_dist)) {
-            facets_out.clear();
-            if (sets_out)
-              sets_out->clear();
-          }
-          smallest_dist_sqr = dist_sqr;
-          smallest_dist = sqrt(smallest_dist_sqr);
-            // put closest result at start of lists
-          facets_out.push_back( *i );
-          std::swap( facets_out.front(), facets_out.back() );
-          if (sets_out) {
-            sets_out->push_back( current_set );
-            std::swap( sets_out->front(), sets_out->back() );
-          }
-        }
-        else if (dist_sqr <= smallest_dist_sqr + tolerance*(tolerance + 2*smallest_dist)) {
-          facets_out.push_back(*i);
-          if (sets_out)
-            sets_out->push_back( current_set );
-        }
-      }
-    } // LEAF NODE
-  }
-
-  if( accum ){
-    accum->end_traversal( max_depth );
-  }
-  
-  return MB_SUCCESS;
-}
-    
-    
-
-/********************** Tree Printing Code ****************************/
-
-
-class TreeLayoutPrinter : public MBOrientedBoxTreeTool::Op
-{
-  public:
-    TreeLayoutPrinter( std::ostream& stream,
-                       MBInterface* instance );
-    
-    virtual MBErrorCode visit( MBEntityHandle node, 
-                               int depth,
-                               bool& descend );
-    virtual MBErrorCode leaf( MBEntityHandle node );
-  private:
-
-    MBInterface* instance;
-    std::ostream& outputStream;
-    std::vector<bool> path;
-};
-
-TreeLayoutPrinter::TreeLayoutPrinter( std::ostream& stream,
-                                      MBInterface* interface )
-  : instance(interface),
-    outputStream(stream)
-  {}
-
-MBErrorCode TreeLayoutPrinter::visit( MBEntityHandle node, 
-                                      int depth,
-                                      bool& descend )
-{
-  descend = true;
-  
-  if ((unsigned)depth > path.size()) {
-    //assert(depth+1 == path.size); // preorder traversal
-    path.push_back(true);
-  }
-  else {
-    path.resize( depth );
-    if (depth)
-      path.back() = false;
-  }
-  
-  for (unsigned i = 0; i+1 < path.size(); ++i) {
-    if (path[i])
-      outputStream << "|   ";
-    else
-      outputStream << "    ";
-  }
-  if (depth) {
-    if (path.back())
-      outputStream << "+---";
-    else
-      outputStream << "\\---";
-  }
-  outputStream << instance->id_from_handle( node ) << std::endl;
-  return MB_SUCCESS;
-}
-
-MBErrorCode TreeLayoutPrinter::leaf( MBEntityHandle ) { return MB_SUCCESS; }
-    
-
-class TreeNodePrinter : public MBOrientedBoxTreeTool::Op
-{
-  public:
-    TreeNodePrinter( std::ostream& stream,
-                     bool list_contents,
-                     bool list_box,
-                     const char* id_tag_name,
-                     MBOrientedBoxTreeTool* tool_ptr );
-    
-    virtual MBErrorCode visit( MBEntityHandle node, 
-                               int depth,
-                               bool& descend );
-                               
-    virtual MBErrorCode leaf( MBEntityHandle ) { return MB_SUCCESS; }
-  private:
-  
-    MBErrorCode print_geometry( MBEntityHandle node );
-    MBErrorCode print_contents( MBEntityHandle node );
-    MBErrorCode print_counts( MBEntityHandle node );
-  
-    bool printContents;
-    bool printGeometry;
-    bool haveTag;
-    MBTag tag, gidTag, geomTag;
-    MBInterface* instance;
-    MBOrientedBoxTreeTool* tool;
-    std::ostream& outputStream;
-};
-
-
-TreeNodePrinter::TreeNodePrinter( std::ostream& stream,
-                                  bool list_contents,
-                                  bool list_box,
-                                  const char* id_tag_name,
-                                  MBOrientedBoxTreeTool* tool_ptr )
-  : printContents( list_contents ),
-    printGeometry( list_box ),
-    haveTag( false ),
-    tag( 0 ),
-    gidTag(0), geomTag(0),
-    instance( tool_ptr->get_moab_instance() ),
-    tool(tool_ptr),
-    outputStream( stream )
-{
-  MBErrorCode rval;
-  if (id_tag_name) {
-    rval = instance->tag_get_handle( id_tag_name, tag );
-    if (!rval) {
-      std::cerr << "Could not get tag \"" << id_tag_name << "\"\n";
-      stream << "Could not get tag \"" << id_tag_name << "\"\n";
-    }
-    else {
-      int size;
-      rval = instance->tag_get_size( tag, size );
-      if (!rval) {
-        std::cerr << "Could not get size for tag \"" << id_tag_name << "\"\n";
-        stream << "Could not get size for tag \"" << id_tag_name << "\"\n";
-      }
-      else if (size != sizeof(int)) {
-        std::cerr << "Tag \"" << id_tag_name << "\" is not an integer\n";
-        stream << "Tag \"" << id_tag_name << "\" is not an integer\n";
-      }
-      else {
-        haveTag = true;
-      }
-    }
-  }
-  
-  rval = instance->tag_get_handle( GLOBAL_ID_TAG_NAME, gidTag );
-  if (MB_SUCCESS != rval)
-    gidTag = 0;
-  rval = instance->tag_get_handle( GEOM_DIMENSION_TAG_NAME, geomTag );
-  if (MB_SUCCESS != rval)
-    geomTag = 0;
-}   
-
-MBErrorCode TreeNodePrinter::visit( MBEntityHandle node, int, bool& descend )
-{
-  descend = true;
-  MBEntityHandle setid = instance->id_from_handle( node );
-  outputStream << setid << ":" << std::endl;
-  
-  MBRange surfs;
-  MBErrorCode r3 = MB_SUCCESS;
-  if (geomTag) {
-    const int two = 2;
-    const void* tagdata[] = {&two};
-    r3 = instance->get_entities_by_type_and_tag( node, MBENTITYSET, &geomTag, tagdata, 1, surfs );
-  
-    if (MB_SUCCESS == r3 && surfs.size() == 1) {
-      MBEntityHandle surf = *surfs.begin();
-      int id;
-      if (gidTag && MB_SUCCESS == instance->tag_get_data( gidTag, &surf, 1, &id ))
-        outputStream << "  Surface " << id << std::endl;
-      else
-        outputStream << "  Surface w/ unknown ID (" << surf << ")" << std::endl;
-    }
-  }
-  
-  MBErrorCode r1 = printGeometry ? print_geometry( node ) : MB_SUCCESS;
-  MBErrorCode r2 = printContents ? print_contents( node ) : print_counts( node );
-  outputStream << std::endl;
-  
-  if (MB_SUCCESS != r1)
-    return r1;
-  else if (MB_SUCCESS != r2)
-    return r2;
-  else
-    return r3;
-}
-
-MBErrorCode TreeNodePrinter::print_geometry( MBEntityHandle node )
-{
-  MBOrientedBox box;
-  MBErrorCode rval= tool->box( node, box );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  MBCartVect length = box.dimensions();
-  
-  outputStream << box.center << "  Radius: " 
-               << box.inner_radius() << " - " << box.outer_radius() << std::endl
-               << '+' << box.axis[0] << " : " << length[0] << std::endl
-               << 'x' << box.axis[1] << " : " << length[1] << std::endl
-               << 'x' << box.axis[2] << " : " << length[2] << std::endl;
-  return MB_SUCCESS;
-}
-
-MBErrorCode TreeNodePrinter::print_counts( MBEntityHandle node )
-{
-  for (MBEntityType type = MBVERTEX; type != MBMAXTYPE; ++type) {
-    int count = 0;
-    MBErrorCode rval = instance->get_number_entities_by_type( node, type, count );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if(count > 0)
-      outputStream << " " << count << " " << MBCN::EntityTypeName(type) << std::endl;
-  }
-  return MB_SUCCESS;
-}
-
-MBErrorCode TreeNodePrinter::print_contents( MBEntityHandle node )
-{
-    // list contents
-  for (MBEntityType type = MBVERTEX; type != MBMAXTYPE; ++type) {
-    MBRange range;
-    MBErrorCode rval = instance->get_entities_by_type( node, type, range );
-    if (MB_SUCCESS != rval)
-      return rval;
-    if (range.empty())
-      continue;
-    outputStream << " " << MBCN::EntityTypeName(type) << " ";  
-    std::vector<int> ids( range.size() );
-    if (haveTag) {
-      rval = instance->tag_get_data( tag, range, &ids[0] );
-      std::sort( ids.begin(), ids.end() );
-    }
-    else {
-      MBRange::iterator ri = range.begin();
-      std::vector<int>::iterator vi = ids.begin();
-      while (ri != range.end()) {
-        *vi = instance->id_from_handle( *ri );
-        ++ri;
-        ++vi;
-      }
-    }
-    
-    unsigned i = 0;
-    for(;;) {
-      unsigned beg = i, end;
-      do { end = i++; } while (i < ids.size() && ids[end]+1 == ids[i]);
-      if (end == beg)
-        outputStream << ids[end];
-      else if (end == beg+1) 
-        outputStream << ids[beg] << ", " << ids[end];
-      else
-        outputStream << ids[beg] << "-" << ids[end];
-        
-      if (i == ids.size()) {
-        outputStream << std::endl;
-        break;
-      }
-      else 
-        outputStream << ", ";
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-  
-void MBOrientedBoxTreeTool::print( MBEntityHandle set, std::ostream& str, bool list, const char* tag )
-{
-  TreeLayoutPrinter op1( str, instance );
-  TreeNodePrinter op2( str, list, true, tag, this );
-  MBErrorCode r1 = preorder_traverse( set, op1 );
-  str << std::endl;
-  MBErrorCode r2 = preorder_traverse( set, op2 );
-  if (r1 != MB_SUCCESS || r2 != MB_SUCCESS) {
-    std::cerr << "Errors encountered while printing tree\n";
-    str << "Errors encountered while printing tree\n";
-  }
-}
-
-
-/********************* Traversal Metrics Code  **************************/
-
-void MBOrientedBoxTreeTool::TrvStats::reset(){
-  nodes_visited_count.clear();
-  leaves_visited_count.clear();
-  traversals_ended_count.clear();
-}
-
-void MBOrientedBoxTreeTool::TrvStats::increment( unsigned depth ){
-
-  while( nodes_visited_count.size() <= depth ){
-    nodes_visited_count.push_back(0);
-    leaves_visited_count.push_back(0);
-    traversals_ended_count.push_back(0);
-  }
-  nodes_visited_count[depth] += 1;
-}
-
-void MBOrientedBoxTreeTool::TrvStats::increment_leaf( unsigned depth ){
-  //assume safe depth, because increment is called first
-  leaves_visited_count[depth] += 1;
-}
-
-void MBOrientedBoxTreeTool::TrvStats::end_traversal( unsigned depth ){
-  // assume safe depth, because increment is always called on a given 
-  // tree level first
-  traversals_ended_count[depth] += 1;
-}
-
-void MBOrientedBoxTreeTool::TrvStats::print( std::ostream& str ) const {
-
-  const std::string h1 = "OBBTree Depth";
-  const std::string h2 = " - NodesVisited";
-  const std::string h3 = " - LeavesVisited";
-  const std::string h4 = " - TraversalsEnded";
-
-  str << h1 << h2 << h3 << h4 << std::endl;
-
-  unsigned num_visited = 0, num_leaves = 0, num_traversals = 0;
-  for( unsigned i = 0; i < traversals_ended_count.size(); ++i){
-
-    num_visited    += nodes_visited_count[i];
-    num_leaves     += leaves_visited_count[i];
-    num_traversals += traversals_ended_count[i];
-   
-    str << std::setw(h1.length()) << i 
-        << std::setw(h2.length()) << nodes_visited_count[i] 
-        << std::setw(h3.length()) << leaves_visited_count[i]
-        << std::setw(h4.length()) << traversals_ended_count[i] 
-        << std::endl;
-  }
-  
-  str << std::setw(h1.length()) << "---- Totals:" 
-      << std::setw(h2.length()) << num_visited 
-      << std::setw(h3.length()) << num_leaves
-      << std::setw(h4.length()) << num_traversals 
-      << std::endl;
-
-}
-
-/********************** Tree Statistics Code ****************************/
-
-
-struct StatData {
-  struct Ratio {
-    double min, max, sum, sqr;
-    int hist[10];
-    Ratio() 
-      : min(std::numeric_limits<double>::max()), 
-        max(-std::numeric_limits<double>::max()), 
-        sum(0.0), sqr(0.0)
-      { hist[0] = hist[1] = hist[2] = hist[3] = hist[4] = hist[5] =
-        hist[6] = hist[7] = hist[8] = hist[9] = 0; }
-    void accum( double v ) {
-      if (v < min) min = v;
-      if (v > max) max = v;
-      sum += v;
-      sqr += v*v;
-      int i = (int)(10*v);
-      if (i < 0) i = 0;
-      else if (i > 9) i = 9;
-      ++hist[i];
-    }
-  };
-  
-  template <typename T> struct Stat {
-    T min, max;
-    double sum, sqr;
-    Stat() : sum(0.0), sqr(0.0) {
-      std::numeric_limits<T> lim;
-      min = lim.max();
-      if (lim.is_integer)
-        max = lim.min();
-      else
-        max = -lim.max();
-    }
-    void accum( T v ) {
-      if (v < min) min = v;
-      if (v > max) max = v;
-      sum += v;
-      sqr += (double)v * v;
-    }
-  };
-
-  StatData() :
-    count(0) 
-    {}
-
-  Ratio volume;
-  Ratio entities;
-  Ratio radius;
-  Stat<unsigned> leaf_ent;
-  Stat<double> vol;
-  Stat<double> area;
-  std::vector<unsigned> leaf_depth;
-  unsigned count;
-};
-
-static int measure( const MBCartVect& v, double& result )
-{
-  const double tol = 1e-6;
-  int dims = 0;
-  result = 1;
-  for (int i = 0; i < 3; ++i)
-    if (v[i] > tol) {
-      ++dims; 
-      result *= v[i];
-  }
-  return dims;
-}
-  
-
-static MBErrorCode recursive_stats( MBOrientedBoxTreeTool* tool,
-                                    MBInterface* instance,
-                                    MBEntityHandle set,
-                                    int depth,
-                                    StatData& data,
-                                    unsigned& count_out,
-                                    MBCartVect& dimensions_out )
-{
-  MBErrorCode rval;
-  MBOrientedBox box;
-  std::vector<MBEntityHandle> children(2);
-  unsigned counts[2];
-  bool isleaf;
-  
-  ++data.count;
-  
-  rval = tool->box( set, box );
-  if (MB_SUCCESS != rval) return rval;
-  children.clear();
-  rval = instance->get_child_meshsets( set, children );
-  if (MB_SUCCESS != rval) return rval;
-  isleaf = children.empty();
-  if (!isleaf && children.size() != 2)
-    return MB_MULTIPLE_ENTITIES_FOUND;
-  
-  dimensions_out = box.dimensions();
-  data.radius.accum( box.inner_radius() / box.outer_radius());
-  data.vol.accum( box.volume() );
-  data.area.accum( box.area() );
-  
-  if (isleaf) {
-    if (data.leaf_depth.size() <= (unsigned)depth)
-      data.leaf_depth.resize( depth+1, 0 );
-    ++data.leaf_depth[depth];
-    
-    int count;
-    rval = instance->get_number_entities_by_handle( set, count );
-    if (MB_SUCCESS != rval) return rval;
-    count_out = count;
-    data.leaf_ent.accum( count_out );
-  }
-  else {
-    for (int i = 0; i < 2; ++i) {
-      MBCartVect dims;
-      rval = recursive_stats( tool, instance, children[i], depth+1, data, counts[i], dims );
-      if (MB_SUCCESS != rval) return rval;
-      double this_measure, chld_measure;
-      int this_dim = measure( dimensions_out, this_measure );
-      int chld_dim = measure( dims, chld_measure );
-      double ratio;
-      if (chld_dim < this_dim)
-        ratio = 0;
-      else
-        ratio = chld_measure / this_measure;
-  
-      data.volume.accum( ratio );
-    }
-    count_out = counts[0] + counts[1];
-    data.entities.accum( (double)counts[0] / count_out );
-    data.entities.accum( (double)counts[1] / count_out );
-  }
-  return MB_SUCCESS;
-}
-
-static inline double std_dev( double sqr, double sum, double count )
-{
-  sum /= count;
-  sqr /= count;
-  return sqrt( sqr - sum*sum );
-}
-
-//#define WW <<std::setw(10)<<std::fixed<<
-#define WE <<std::setw(10)<<
-#define WW WE
-MBErrorCode MBOrientedBoxTreeTool::stats( MBEntityHandle set, 
-                                          unsigned &total_entities,
-                                          double &rv,
-                                          double &tot_node_volume,
-                                          double &tot_to_root_volume,
-                                          unsigned &tree_height,
-                                          unsigned &node_count,
-                                          unsigned &num_leaves)
-{
-  StatData d;
-  MBErrorCode rval;
-  unsigned i;
-  MBCartVect total_dim;
-  
-  rval = recursive_stats( this, instance, set, 0, d, total_entities, total_dim );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  tree_height = d.leaf_depth.size();
-  unsigned min_leaf_depth = tree_height;
-  num_leaves = 0;
-  unsigned max_leaf_per_depth = 0;
-  double sum_leaf_depth = 0, sqr_leaf_depth = 0;
-  for (i = 0; i < d.leaf_depth.size(); ++i) {
-    unsigned val = d.leaf_depth[i];
-    num_leaves += val;
-    sum_leaf_depth += (double)val*i;
-    sqr_leaf_depth += (double)val*i*i;
-    if (val && i < min_leaf_depth)
-      min_leaf_depth = i;
-    if (max_leaf_per_depth < val)
-      max_leaf_per_depth = val;
-  }
-  rv = total_dim[0]*total_dim[1]*total_dim[2];
-  tot_node_volume = d.vol.sum;
-  tot_to_root_volume = d.vol.sum/rv;
-  node_count = d.count;
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBOrientedBoxTreeTool::stats( MBEntityHandle set, std::ostream& s )
-{
-  StatData d;
-  MBErrorCode rval;
-  unsigned total_entities, i;
-  MBCartVect total_dim;
-  
-  rval = recursive_stats( this, instance, set, 0, d, total_entities, total_dim );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  unsigned tree_height = d.leaf_depth.size();
-  unsigned min_leaf_depth = tree_height, num_leaves = 0;
-  unsigned max_leaf_per_depth = 0;
-  double sum_leaf_depth = 0, sqr_leaf_depth = 0;
-  for (i = 0; i < d.leaf_depth.size(); ++i) {
-    unsigned val = d.leaf_depth[i];
-    num_leaves += val;
-    sum_leaf_depth += (double)val*i;
-    sqr_leaf_depth += (double)val*i*i;
-    if (val && i < min_leaf_depth)
-      min_leaf_depth = i;
-    if (max_leaf_per_depth < val)
-      max_leaf_per_depth = val;
-  }
-  unsigned num_non_leaf = d.count - num_leaves;
-  
-  double rv = total_dim[0]*total_dim[1]*total_dim[2];
-  s << "entities in tree:  " << total_entities << std::endl
-    << "root volume:       " << rv << std::endl
-    << "total node volume: " << d.vol.sum << std::endl
-    << "total/root volume: " << d.vol.sum/rv << std::endl
-    << "tree height:       " << tree_height << std::endl
-    << "node count:        " << d.count << std::endl
-    << "leaf count:        " << num_leaves << std::endl
-    << std::endl;
-  
-  double avg_leaf_depth = sum_leaf_depth / num_leaves;
-  double rms_leaf_depth = sqrt( sqr_leaf_depth / num_leaves );
-  double std_leaf_depth = std_dev( sqr_leaf_depth, sum_leaf_depth, num_leaves );
-
-  double avg_leaf_ent = d.leaf_ent.sum / num_leaves;
-  double rms_leaf_ent = sqrt( d.leaf_ent.sqr / num_leaves );
-  double std_leaf_ent = std_dev( d.leaf_ent.sqr, d.leaf_ent.sum, num_leaves );
-
-  unsigned num_child = 2 * num_non_leaf;
-
-  double avg_vol_ratio = d.volume.sum / num_child;
-  double rms_vol_ratio = sqrt( d.volume.sqr / num_child );
-  double std_vol_ratio = std_dev( d.volume.sqr, d.volume.sum, num_child);
-
-  double avg_ent_ratio = d.entities.sum / num_child;
-  double rms_ent_ratio = sqrt( d.entities.sqr / num_child );
-  double std_ent_ratio = std_dev( d.entities.sqr, d.entities.sum, num_child);
-
-  double avg_rad_ratio = d.radius.sum / d.count;
-  double rms_rad_ratio = sqrt( d.radius.sqr / d.count );
-  double std_rad_ratio = std_dev( d.radius.sqr, d.radius.sum, d.count );
-  
-  double avg_vol = d.vol.sum / d.count;
-  double rms_vol = sqrt( d.vol.sqr / d.count );
-  double std_vol = std_dev( d.vol.sqr, d.vol.sum, d.count );
-  
-  double avg_area = d.area.sum / d.count;
-  double rms_area = sqrt( d.area.sqr / d.count );
-  double std_area = std_dev( d.area.sqr, d.area.sum, d.count );
-      
-  int prec = s.precision();
-  s <<                         "                   " WW "Minimum"      WW "Average"      WW "RMS"          WW "Maximum"             WW "Std.Dev."     << std::endl;
-  s << std::setprecision(1) << "Leaf Depth         " WW min_leaf_depth WW avg_leaf_depth WW rms_leaf_depth WW d.leaf_depth.size()-1 WW std_leaf_depth << std::endl; 
-  s << std::setprecision(0) << "Entities/Leaf      " WW d.leaf_ent.min WW avg_leaf_ent   WW rms_leaf_ent   WW d.leaf_ent.max        WW std_leaf_ent   << std::endl;
-  s << std::setprecision(3) << "Child Volume Ratio " WW d.volume.min   WW avg_vol_ratio  WW rms_vol_ratio  WW d.volume.max          WW std_vol_ratio  << std::endl;
-  s << std::setprecision(3) << "Child Entity Ratio " WW d.entities.min WW avg_ent_ratio  WW rms_ent_ratio  WW d.entities.max        WW std_ent_ratio  << std::endl;
-  s << std::setprecision(3) << "Box Radius Ratio   " WW d.radius.min   WW avg_rad_ratio  WW rms_rad_ratio  WW d.radius.max          WW std_rad_ratio  << std::endl;
-  s << std::setprecision(0) << "Box volume         " WE d.vol.min      WE avg_vol        WE rms_vol        WE d.vol.max             WE std_vol        << std::endl;
-  s << std::setprecision(0) << "Largest side area  " WE d.area.min     WE avg_area       WE rms_area       WE d.area.max            WE std_area       << std::endl;
-  s << std::setprecision(prec) << std::endl;
-  
-  s << "Leaf Depth Histogram (Root depth is 0)" << std::endl;
-  double f = 60.0 / max_leaf_per_depth;
-  for (i = min_leaf_depth; i < d.leaf_depth.size(); ++i)
-    s << std::setw(2) << i << " " << std::setw(5) << d.leaf_depth[i] << " |"
-      << std::setfill('*') << std::setw((int)floor(f*d.leaf_depth[i]+0.5)) << "" 
-      << std::setfill(' ') << std::endl;
-  s <<std::endl;
-  
-  s << "Child/Parent Volume Ratio Histogram" << std::endl;
-  f = 60.0 / *(std::max_element(d.volume.hist, d.volume.hist+10));
-  for (i = 0; i < 10u; ++i)
-    s << "0." << i << " " << std::setw(5) << d.volume.hist[i] << " |"
-      << std::setfill('*') << std::setw((int)floor(f*d.volume.hist[i]+0.5)) << ""
-      << std::setfill(' ') << std::endl;
-  s <<std::endl;
-  
-  s << "Child/Parent Entity Count Ratio Histogram" << std::endl;
-  f = 60.0 / *(std::max_element(d.entities.hist, d.entities.hist+10));
-  for (i = 0; i < 10u; ++i)
-    s << "0." << i << " " << std::setw(5) << d.entities.hist[i] << " |"
-      << std::setfill('*') << std::setw((int)floor(f*d.entities.hist[i]+0.5)) << ""
-      << std::setfill(' ') << std::endl;
-  s <<std::endl;
-  
-  s << "Inner/Outer Radius Ratio Histogram (~0.70 for cube)" << std::endl;
-    // max radius ratio for a box is about 0.7071.  Move any boxes
-    // in the .7 bucket into .6 and print .0 to .6.
-  d.radius.hist[6] += d.radius.hist[7]; 
-  f = 60.0 / *(std::max_element(d.entities.hist, d.entities.hist+7));
-  for (i = 0; i < 7u; ++i)
-    s << "0." << i << " " << std::setw(5) << d.entities.hist[i] << " |"
-      << std::setfill('*') << std::setw((int)floor(f*d.entities.hist[i]+0.5)) << ""
-      << std::setfill(' ') << std::endl;
-  s <<std::endl;
-  
-  return MB_SUCCESS;
-}

Deleted: MOAB/trunk/src/MBRange.cpp
===================================================================
--- MOAB/trunk/src/MBRange.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBRange.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,966 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/****************************************************
- * File     :      MBRange.cpp
- *
- * Purpose  :      Stores contiguous or partially
- *                 contiguous values in an optimized
- *                 fashion.  Partially contiguous
- *                 accessing patterns is also optimized.
- *
- * Creator  :      Clinton Stimpson
- *
- * Date     :      15 April 2002
- *
- *******************************************************/
-
-
-#include <assert.h>
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-#include "MBCN.hpp"
-#include <iostream>
-#include <string>
-
-#ifdef HAVE_BOOST_POOL_SINGLETON_POOL_HPP
-#  include <boost/pool/singleton_pool.hpp>
-   typedef boost::singleton_pool< MBRange::PairNode , sizeof(MBRange::PairNode) > 
-    PairAlloc;
-   static inline MBRange::PairNode* alloc_pair()
-    { return new (PairAlloc::malloc()) MBRange::PairNode; }
-   static inline MBRange::PairNode* alloc_pair(MBRange::PairNode* n, MBRange::PairNode* p, MBEntityHandle f, MBEntityHandle s)
-    { return new (PairAlloc::malloc()) MBRange::PairNode(n,p,f,s); }
-   static inline void free_pair( MBRange::PairNode* node )
-    { node->~PairNode(); PairAlloc::free( node ); }
-#else
-   static inline MBRange::PairNode* alloc_pair()
-    { return new MBRange::PairNode; }
-   static inline MBRange::PairNode* alloc_pair(MBRange::PairNode* n, MBRange::PairNode* p, MBEntityHandle f, MBEntityHandle s)
-    { return new MBRange::PairNode(n,p,f,s); }
-   static inline void free_pair( MBRange::PairNode* node )
-    { delete node; }
-#endif
-
-/*! 
-  returns the number of values this list represents
- */
-MBEntityHandle MBRange::size() const
-{
-  // go through each pair and add up the number of values
-  // we have.
-  MBEntityHandle size=0;
-  for(PairNode* iter = mHead.mNext; iter != &mHead; iter = iter->mNext)
-  {
-    size += ((iter->second - iter->first) + 1);
-  }
-  return size;
-}
-/*! 
-  returns the number of pairs in the list
- */
-MBEntityHandle MBRange::psize() const
-{
-  // go through each pair and add up the number of values
-  // we have.
-  MBEntityHandle size=0;
-  for(PairNode* iter = mHead.mNext; iter != &mHead; iter = iter->mNext)
-  {
-    ++size;
-  }
-  return size;
-}
-
-/*!
-  advance iterator
-*/
-MBRange::const_iterator& MBRange::const_iterator::operator+=( MBEntityID sstep )
-{
-    // Check negative now to avoid infinite loop below.
-  if (sstep < 0)
-  {
-    return operator-=( -sstep );
-  }
-  MBEntityHandle step = sstep;
-  
-    // Handle current PairNode.  Either step is within the current
-    // node or need to remove the remainder of the current node
-    // from step.
-  MBEntityHandle this_node_rem = mNode->second - mValue;
-  if (this_node_rem >= step)
-  {
-    mValue += step;
-    return *this;
-  }
-  step -= this_node_rem + 1;
-
-    // For each node we are stepping past, decrement step
-    // by the size of the node.
-  PairNode* node = mNode->mNext;
-  MBEntityHandle node_size = node->second - node->first + 1;
-  while (step >= node_size)
-  {
-    step -= node_size;
-    node = node->mNext;
-    node_size = node->second - node->first + 1;
-  }
-  
-    // Advance into the resulting node by whatever is
-    // left in step.
-  mNode = node;
-  mValue = mNode->first + step;
-  return *this;
-}
-  
-    
- 
-/*!
-  regress iterator
-*/
-MBRange::const_iterator& MBRange::const_iterator::operator-=( MBEntityID sstep )
-{
-    // Check negative now to avoid infinite loop below.
-  if (sstep < 0)
-  {
-    return operator+=( -sstep );
-  }
-  MBEntityHandle step = sstep;
-  
-    // Handle current PairNode.  Either step is within the current
-    // node or need to remove the remainder of the current node
-    // from step.
-  MBEntityHandle this_node_rem = mValue - mNode->first;
-  if (this_node_rem >= step)
-  {
-    mValue -= step;
-    return *this;
-  }
-  step -= this_node_rem + 1;
-
-    // For each node we are stepping past, decrement step
-    // by the size of the node.
-  PairNode* node = mNode->mPrev;
-  MBEntityHandle node_size = node->second - node->first + 1;
-  while (step >= node_size)
-  {
-    step -= node_size;
-    node = node->mPrev;
-    node_size = node->second - node->first + 1;
-  }
-  
-    // Advance into the resulting node by whatever is
-    // left in step.
-  mNode = node;
-  mValue = mNode->second - step;
-  return *this;
-}
-  
- 
-  
-
-  //! another constructor that takes an initial range
-MBRange::MBRange( MBEntityHandle val1, MBEntityHandle val2 )
-{
-  mHead.mNext = mHead.mPrev = alloc_pair(&mHead, &mHead, val1, val2);
-  mHead.first = mHead.second = 0;
-}
-
-  //! copy constructor
-MBRange::MBRange(const MBRange& copy)
-{
-    // set the head node to point to itself
-  mHead.mNext = mHead.mPrev = &mHead;
-  mHead.first = mHead.second = 0;
-
-  const PairNode* copy_node = copy.mHead.mNext;
-  PairNode* new_node = &mHead;
-  for(; copy_node != &(copy.mHead); copy_node = copy_node->mNext)
-  {
-    PairNode* tmp_node = alloc_pair(new_node->mNext, new_node, copy_node->first,
-                                      copy_node->second);
-    new_node->mNext->mPrev = tmp_node;
-    new_node->mNext = tmp_node;
-    new_node = tmp_node;
-  }
-}
-
-  //! clears the contents of the list 
-void MBRange::clear()
-{
-  PairNode* tmp_node = mHead.mNext;
-  while(tmp_node != &mHead)
-  {
-    PairNode* to_delete = tmp_node;
-    tmp_node = tmp_node->mNext;
-    free_pair( to_delete );
-  }
-  mHead.mNext = &mHead;
-  mHead.mPrev = &mHead;
-}
-
-MBRange& MBRange::operator=(const MBRange& copy)
-{
-  clear();
-  const PairNode* copy_node = copy.mHead.mNext;
-  PairNode* new_node = &mHead;
-  for(; copy_node != &(copy.mHead); copy_node = copy_node->mNext)
-  {
-    PairNode* tmp_node = alloc_pair(new_node->mNext, new_node, copy_node->first,
-                                      copy_node->second);
-    new_node->mNext->mPrev = tmp_node;
-    new_node->mNext = tmp_node;
-    new_node = tmp_node;
-  }
-  return *this;
-}
-
-
-/*!
-  inserts a single value into this range
-*/
-
-MBRange::iterator MBRange::insert( MBRange::iterator hint, MBEntityHandle val )
-{
-  // don't allow zero-valued handles in MBRange
-  if(val == 0)
-    return end();
-
-  // if this is empty, just add it and return an iterator to it
-  if(&mHead == mHead.mNext)
-  {
-    mHead.mNext = mHead.mPrev = alloc_pair(&mHead, &mHead, val, val);
-    return iterator(mHead.mNext, val);
-  }
-  
-  // find the location in the list where we can safely insert
-  // new items and keep it ordered
-  PairNode* hter = hint.mNode;
-  PairNode* jter = hter->first <= val ? hter : mHead.mNext;
-  for( ; (jter != &mHead) && (jter->second < val); jter=jter->mNext);
-  PairNode* iter = jter;
-  jter = jter->mPrev;
-
-  // if this val is already in the list
-  if( (iter->first <= val && iter->second >= val) && (iter != &mHead) )
-  {
-    // return an iterator pointing to this location
-    return iterator( iter, val );
-  }
-
-  // one of a few things can happen at this point
-  // 1. this range needs to be backwardly extended
-  // 2. the previous range needs to be forwardly extended
-  // 3. a new range needs to be added
-
-  
-  // extend this range back a bit
-  else if( (iter->first == (val+1)) && (iter != &mHead) )
-  {
-    iter->first = val;
-    // see if we need to merge two ranges
-    if( (iter != mHead.mNext) && (jter->second == (val-1)))
-    {
-      jter->second = iter->second;
-      iter->mPrev->mNext = iter->mNext;
-      iter->mNext->mPrev = iter->mPrev;
-      free_pair( iter );
-      return iterator( jter, val );
-    }
-    else
-    {
-      return iterator( iter, val );
-    }
-
-  }
-  // extend the previous range forward a bit
-  else if( (jter->second == (val-1)) && (iter != mHead.mNext) )
-  {
-    jter->second = val;
-    return iterator(jter, val);
-  }
-  // make a new range
-  else
-  {
-    PairNode* new_node = alloc_pair(iter, iter->mPrev, val, val);
-    iter->mPrev = new_node->mPrev->mNext = new_node;
-    return iterator(new_node, val);
-  }
-
-}
-
-MBRange::iterator MBRange::insert( MBRange::iterator prev,
-                                   MBEntityHandle val1, 
-                                   MBEntityHandle val2 )
-{
-  if(val1 == 0 || val1 > val2)
-    return end();
-
-  // Empty 
-  if (mHead.mNext == &mHead)
-  {
-    assert( prev == end() );
-    PairNode* new_node = alloc_pair( &mHead, &mHead, val1, val2 );
-    mHead.mNext = mHead.mPrev = new_node;
-    return iterator( mHead.mNext, val1 );
-  }
-  
-  PairNode* iter = prev.mNode;
-    // If iterator is at end, set it to last.
-    // Thus if the hint was to append, we start searching
-    // at the end of the list.
-  if (iter == &mHead) 
-    iter = mHead.mPrev;
-    // if hint (prev) is past insert position, reset it to the beginning.
-  if (iter != &mHead && iter->first > val2+1)
-    iter = mHead.mNext;
-  
-  // Input range is before beginning?
-  if (iter->mPrev == &mHead && val2 < iter->first - 1)
-  {
-    PairNode* new_node = alloc_pair( iter, &mHead,  val1, val2 );
-    mHead.mNext = iter->mPrev = new_node;
-    return iterator( mHead.mNext, val1 );
-  }
-  
-  // Find first intersecting list entry, or the next entry
-  // if none intersects.
-  while (iter != &mHead && iter->second+1 < val1)
-    iter = iter->mNext;
-  
-  // Need to insert new pair (don't intersect any existing pair)?
-  if (iter == &mHead || iter->first-1 > val2)
-  {
-    PairNode* new_node = alloc_pair( iter, iter->mPrev, val1, val2 );
-    iter->mPrev = iter->mPrev->mNext = new_node;
-    return iterator( iter->mPrev, val1 );
-  }
-  
-  // Make the first intersecting pair the union of itself with [val1,val2]
-  if (iter->first > val1)
-    iter->first = val1;
-  if (iter->second >= val2)  
-    return iterator( iter, val1 );
-  iter->second = val2;
-  
-  // Merge any remaining pairs that intersect [val1,val2]
-  while (iter->mNext != &mHead && iter->mNext->first <= val2 + 1)
-  {
-    PairNode* dead = iter->mNext;
-    iter->mNext = dead->mNext;
-    dead->mNext->mPrev = iter;
-    
-    if (dead->second > val2)
-      iter->second = dead->second;
-    free_pair( dead );
-  }
-  
-  return iterator( iter, val1 );
-}
-    
-
-/*!
-  erases an item from this list and returns an iterator to the next item
-*/
-
-MBRange::iterator MBRange::erase(iterator iter)
-{
-  // one of a few things could happen
-  // 1. shrink a range
-  // 2. split a range
-  // 3. remove a range
-
-  if(iter == end())
-    return end();
-
-  // the iterator most likely to be returned
-  iterator new_iter = iter;
-  ++new_iter;
-
-  PairNode* kter = iter.mNode;
-  
-  // just remove the range
-  if(kter->first == kter->second)
-  {
-    kter->mNext->mPrev = kter->mPrev;
-    kter->mPrev->mNext = kter->mNext;
-    free_pair( kter );
-    return new_iter;
-  }
-  // shrink it
-  else if(kter->first == iter.mValue)
-  {
-    kter->first++;
-    return new_iter;
-  }
-  // shrink it the other way
-  else if(kter->second == iter.mValue)
-  {
-    kter->second--;
-    return new_iter;
-  }
-  // split the range
-  else
-  {
-    PairNode* new_node = alloc_pair(iter.mNode->mNext, iter.mNode, iter.mValue+1, kter->second);
-    new_node->mPrev->mNext = new_node->mNext->mPrev = new_node;
-    iter.mNode->second = iter.mValue - 1;
-    new_iter = const_iterator(new_node, new_node->first);
-    return new_iter;
-  }
-
-}
-
-
-  //! remove a range of items from the list
-MBRange::iterator MBRange::erase( iterator iter1, iterator iter2)
-{
-  iterator result;
-  
-  if (iter1.mNode == iter2.mNode) {
-    if (iter2.mValue <= iter1.mValue) {
-        // empty range OK, otherwise invalid input
-      return iter2;
-    }
-    
-      // If both iterators reference the same pair node, then
-      // we're either removing values from the front of the
-      // node or splitting the node.  We can never be removing
-      // the last value in the node in this case because iter2
-      // points *after* the last entry to be removed.
-    
-    PairNode* node = iter1.mNode;
-    if (iter1.mValue == node->first) {
-        node->first = iter2.mValue;
-        result = iter2;
-    }
-    else {
-      PairNode* new_node = alloc_pair( node->mNext, node, iter2.mValue, node->second );
-      new_node->mNext->mPrev = new_node;
-      new_node->mPrev->mNext = new_node;
-      node->second = iter1.mValue - 1;
-      result = iterator( new_node, new_node->first );
-    }
-  }
-  else {
-    if (iter1.mNode == &mHead)
-      return iter1;
-    PairNode* dn = iter1.mNode;
-    if (iter1.mValue > dn->first) {
-      dn->second = iter1.mValue-1;
-      dn = dn->mNext;
-    }
-    if (iter2.mNode != &mHead) 
-      iter2.mNode->first = iter2.mValue;
-    while (dn != iter2.mNode) {
-      PairNode* dead = dn;
-      dn = dn->mNext;
-
-      dead->mPrev->mNext = dead->mNext;
-      dead->mNext->mPrev = dead->mPrev;
-      dead->mPrev = dead->mNext = 0;
-      delete dead;
-    }
-    
-    result = iter2;
-  }
-  
-  return result;
-}
-
-void MBRange::delete_pair_node( PairNode* node )
-{
-  if (node != &mHead) { // pop_front() and pop_back() rely on this check
-    node->mPrev->mNext = node->mNext;
-    node->mNext->mPrev = node->mPrev;
-    free_pair( node );
-  }
-}
-
-  //! remove first entity from range
-MBEntityHandle MBRange::pop_front()
-{
-  MBEntityHandle retval = front();
-  if (mHead.mNext->first == mHead.mNext->second) // need to remove pair from range
-    delete_pair_node( mHead.mNext );
-  else 
-    ++(mHead.mNext->first); // otherwise just adjust start value of pair
-
-  return retval;
-}
-
-  //! remove last entity from range
-MBEntityHandle MBRange::pop_back()
-{
-  MBEntityHandle retval = back();
-  if (mHead.mPrev->first == mHead.mPrev->second) // need to remove pair from range
-    delete_pair_node( mHead.mPrev );
-  else
-    --(mHead.mPrev->second); // otherwise just adjust end value of pair
-
-  return retval;
-}
-
-/*!
-  finds a value in the list.
-  this method is preferred over other algorithms because
-  it can be found faster this way.
-*/
-MBRange::const_iterator MBRange::find(MBEntityHandle val) const
-{
-  // iterator through the list
-  PairNode* iter = mHead.mNext;
-  for( ; iter != &mHead && (val > iter->second); iter=iter->mNext );
-  return ((iter->second >= val) && (iter->first <= val)) ? const_iterator(iter,val) : end();
-}
-
-/*!
-  merges another MBRange with this one
-*/
-
-
-void MBRange::merge( const MBRange& range )
-{
-  merge( range.begin(), range.end() );
-}
-
-void MBRange::merge( MBRange::const_iterator begin,
-                     MBRange::const_iterator end )
-{
-  if (begin == end)
-    return;
-  
-  PairNode* node = begin.mNode;
-  if (end.mNode == node)
-  {
-    insert( *begin, (*end)-1 );
-    return;
-  }
-  
-  MBRange::iterator hint = insert( *begin, node->second );
-  node = node->mNext;
-  while (node != end.mNode)
-  {
-    hint = insert( hint, node->first, node->second );
-    node = node->mNext;
-  }
-  
-  if (*end > node->first)
-  {
-    if (*end <= node->second)
-      insert( hint, node->first, *(end) - 1 );
-    else
-      insert( hint, node->first, node->second );
-  }
-}
-
-  
-  
-
-#include <algorithm>
-
-
-// checks the range to make sure everything is A-Ok.
-void MBRange::sanity_check() const
-{
-  if(empty())
-    return;
-
-  const PairNode* node = mHead.mNext;
-  std::vector<const PairNode*> seen_before;
-  bool stop_it = false;
-  
-  for(; stop_it == false; node = node->mNext)
-  {
-    // have we seen this node before?
-    assert(std::find(seen_before.begin(), seen_before.end(), node) == seen_before.end());
-    seen_before.push_back(node);
-
-    // is the connection correct?
-    assert(node->mNext->mPrev == node);
-
-    // are the values right?
-    assert(node->first <= node->second);
-    if(node != &mHead && node->mPrev != &mHead)
-      assert(node->mPrev->second < node->first);
-
-    if(node == &mHead)
-      stop_it = true;
-
-  }
-
-}
-
-// for debugging
-void MBRange::print(const char *indent_prefix) const
-{
-  print(std::cout, indent_prefix);
-}
-
-void MBRange::print(std::ostream& stream, const char *indent_prefix) const
-{
-  std::string indent_prefix_str;
-  if (NULL != indent_prefix) indent_prefix_str += indent_prefix;
-  
-  if (empty()) {
-    stream << indent_prefix_str << "\tempty" << std::endl;
-    return;
-  }
-  
-  for (const_pair_iterator i = const_pair_begin(); i != const_pair_end(); ++i) {
-    MBEntityType t1 = TYPE_FROM_HANDLE( i->first );
-    MBEntityType t2 = TYPE_FROM_HANDLE( i->second );
-  
-    stream << indent_prefix_str << "\t" << MBCN::EntityTypeName( t1 ) << " " 
-           << ID_FROM_HANDLE( i->first );
-    if(i->first != i->second) {
-      stream << " - ";
-      if (t1 != t2) 
-        stream << MBCN::EntityTypeName( t2 ) << " ";
-      stream << ID_FROM_HANDLE( i->second );
-    }
-    stream << std::endl;
-  }
-}
-
-  // intersect two ranges, placing the results in the return range
-#define MAX(a,b) (a < b ? b : a)
-#define MIN(a,b) (a > b ? b : a)
-MBRange intersect(const MBRange &range1, const MBRange &range2) 
-{
-  MBRange::const_pair_iterator r_it[2] = { range1.const_pair_begin(), 
-                                           range2.const_pair_begin() };
-  MBEntityHandle low_it, high_it;
-  
-  MBRange lhs;
-  MBRange::iterator hint = lhs.begin();
-  
-    // terminate the while loop when at least one "start" iterator is at the
-    // end of the list
-  while (r_it[0] != range1.end() && r_it[1] != range2.end()) {
-    
-    if (r_it[0]->second < r_it[1]->first)
-        // 1st subrange completely below 2nd subrange
-      r_it[0]++;
-    else if (r_it[1]->second < r_it[0]->first) 
-        // 2nd subrange completely below 1st subrange
-      r_it[1]++;
-    
-    else {
-        // else ranges overlap; first find greater start and lesser end
-      low_it = MAX(r_it[0]->first, r_it[1]->first);
-      high_it = MIN(r_it[0]->second, r_it[1]->second);
-      
-        // insert into result
-      hint = lhs.insert(hint, low_it, high_it);
-      
-        // now find bounds of this insertion and increment corresponding iterator
-      if (high_it == r_it[0]->second) r_it[0]++;
-      if (high_it == r_it[1]->second) r_it[1]++;
-    }
-  }
-  
-  return lhs;
-}
-
-MBRange subtract(const MBRange &range1, const MBRange &range2) 
-{
-  const bool braindead = false;
-  
-  if (braindead) {
-      // brain-dead implementation right now
-    MBRange res( range1 );
-    for (MBRange::const_iterator rit = range2.begin(); rit != range2.end(); rit++)
-      res.erase(*rit);
-
-    return res;
-  }
-  else {
-    MBRange lhs( range1 );
-  
-    MBRange::pair_iterator r_it0 = lhs.pair_begin();
-    MBRange::const_pair_iterator r_it1 = range2.const_pair_begin();
-  
-      // terminate the while loop when at least one "start" iterator is at the
-      // end of the list
-    while (r_it0 != lhs.end() && r_it1 != range2.end()) {
-        // case a: pair wholly within subtracted pair
-      if (r_it0->first >= r_it1->first && r_it0->second <= r_it1->second) {
-        MBRange::PairNode *rtmp = r_it0.node();
-        r_it0++;
-        lhs.delete_pair_node(rtmp);
-      }
-        // case b: pair overlaps upper part of subtracted pair
-      else if (r_it0->first <= r_it1->second &&
-               r_it0->first >= r_it1->first) {
-        r_it0->first = r_it1->second + 1;
-        r_it1++;
-      }
-        // case c: pair overlaps lower part of subtracted pair
-      else if (r_it0->second >= r_it1->first &&
-               r_it0->second <= r_it1->second) {
-        r_it0->second = r_it1->first - 1;
-        r_it0++;
-      }
-        // case d: pair completely surrounds subtracted pair
-      else if (r_it0->first < r_it1->first && 
-               r_it0->second > r_it1->second) {
-        MBRange::PairNode* new_node = alloc_pair(r_it0.node(), r_it0.node()->mPrev, 
-                                        r_it0->first, r_it1->first - 1);
-        new_node->mPrev->mNext = new_node->mNext->mPrev = new_node;
-        r_it0.node()->first = r_it1->second+1;
-        r_it1++;
-      }
-      else {
-        while (r_it0->second < r_it1->first && r_it0 != lhs.end()) r_it0++;
-        if (r_it0 == lhs.end()) break;
-        while (r_it1->second < r_it0->first && r_it1 != range2.end()) r_it1++;
-      }
-    }
-    
-    return lhs;
-  }
-}
-
-  
-MBEntityID 
-operator-( const MBRange::const_iterator& it2, const MBRange::const_iterator& it1 )
-{
-  assert( !it2.mValue || *it2 >= *it1 );
-  if (it2.mNode == it1.mNode) {
-    return *it2 - *it1;
-  }
-
-  MBEntityID result = it1.mNode->second - it1.mValue + 1;
-  for (MBRange::PairNode* n = it1.mNode->mNext; n != it2.mNode; n = n->mNext)
-    result += n->second - n->first + 1;
-  if (it2.mValue) // (it2.mNode != &mHead)
-    result += it2.mValue - it2.mNode->first;
-  return result;
-}
-
-
-MBRange::const_iterator MBRange::lower_bound(MBRange::const_iterator first,
-                                             MBRange::const_iterator last,
-                                             MBEntityHandle val)
-{
-    // Find the first pair whose end is >= val
-  PairNode* iter;
-  for (iter = first.mNode; iter != last.mNode; iter = iter->mNext)
-  {
-    if (iter->second >= val)
-    {
-        // This is the correct pair.  Either 'val' is in the range, or
-        // the range starts before 'val' and iter->first IS the lower_bound.
-      if (iter->first > val)
-        return const_iterator(iter, iter->first);
-      return const_iterator(iter, val);
-    }
-  }
-  
-  if (iter->first >= val)
-    return const_iterator( iter, iter->first );
-  else if(*last > val)
-    return const_iterator( iter, val );
-  else
-    return last;
-}
-
-MBRange::const_iterator MBRange::upper_bound(MBRange::const_iterator first,
-                                             MBRange::const_iterator last,
-                                             MBEntityHandle val)
-{
-  MBRange::const_iterator result = lower_bound( first, last, val );
-  if (result != last && *result == val)
-    ++result;
-  return result;
-}
-
-MBRange::const_iterator MBRange::lower_bound( MBEntityType type ) const
-{
-  int err;
-  MBEntityHandle handle = CREATE_HANDLE( type, 0, err );
-  return err ? end() : lower_bound( begin(), end(), handle );
-}
-MBRange::const_iterator MBRange::lower_bound( MBEntityType type,
-                                              const_iterator first ) const
-{
-  int err;
-  MBEntityHandle handle = CREATE_HANDLE( type, 0, err );
-  return err ? end() : lower_bound( first, end(), handle );
-}
-
-MBRange::const_iterator MBRange::upper_bound( MBEntityType type ) const
-{
-    // if (type+1) overflows, err will be true and we return end().
-  int err; 
-  MBEntityHandle handle = CREATE_HANDLE( type + 1, 0, err );
-  return err ? end() : lower_bound( begin(), end(), handle );
-}
-MBRange::const_iterator MBRange::upper_bound( MBEntityType type,
-                                              const_iterator first ) const
-{
-    // if (type+1) overflows, err will be true and we return end().
-  int err; 
-  MBEntityHandle handle = CREATE_HANDLE( type + 1, 0, err );
-  return err ? end() : lower_bound( first, end(), handle );
-}
-
-std::pair<MBRange::const_iterator, MBRange::const_iterator>
-MBRange::equal_range( MBEntityType type ) const
-{
-  std::pair<MBRange::const_iterator, MBRange::const_iterator> result;
-  int err;
-  MBEntityHandle handle = CREATE_HANDLE( type, 0, err );
-  result.first = err ? end() : lower_bound( begin(), end(), handle );
-    // if (type+1) overflows, err will be true and we return end().
-  handle = CREATE_HANDLE( type+1, 0, err );
-  result.second = err ? end() : lower_bound( result.first, end(), handle );
-  return result;
-}
-  
-bool MBRange::all_of_type( MBEntityType type ) const
-{
-  return empty() 
-      || (TYPE_FROM_HANDLE(front()) == type
-       && TYPE_FROM_HANDLE(back()) == type);
-}
-
-bool MBRange::all_of_dimension( int dimension ) const
-{
-  return empty() 
-      || (MBCN::Dimension(TYPE_FROM_HANDLE(front())) == dimension
-       && MBCN::Dimension(TYPE_FROM_HANDLE(back())) == dimension);
-}
-
-unsigned MBRange::num_of_type( MBEntityType type ) const
-{
-  const_pair_iterator iter = const_pair_begin();
-  while(iter != const_pair_end() && TYPE_FROM_HANDLE((*iter).second) < type)
-    ++iter;
-  
-  unsigned count = 0;
-  for ( ; iter != const_pair_end(); ++iter)
-  {
-    MBEntityType start_type = TYPE_FROM_HANDLE((*iter).first);
-    MBEntityType end_type = TYPE_FROM_HANDLE((*iter).second);
-    if (start_type > type)
-      break;
-   
-    int sid = start_type < type ? 1 : ID_FROM_HANDLE((*iter).first);
-    int eid = end_type > type ? MB_END_ID : ID_FROM_HANDLE((*iter).second);
-    count += eid - sid + 1;
-  }
-
-  return count;
-}
-  
-unsigned MBRange::num_of_dimension( int dim ) const
-{
-  const_pair_iterator iter = const_pair_begin();
-  while(iter != const_pair_end() && MBCN::Dimension(TYPE_FROM_HANDLE((*iter).second)) < dim)
-    ++iter;
-  
-  int junk;
-  unsigned count = 0;
-  for ( ; iter != const_pair_end(); ++iter)
-  {
-    int start_dim = MBCN::Dimension(TYPE_FROM_HANDLE((*iter).first));
-    int end_dim = MBCN::Dimension(TYPE_FROM_HANDLE((*iter).second));
-    if (start_dim > dim)
-      break;
-      
-    MBEntityHandle sh = start_dim < dim ? 
-                        CREATE_HANDLE( MBCN::TypeDimensionMap[dim].first, 1, junk ) :
-                        (*iter).first;
-    MBEntityHandle eh = end_dim > dim ?
-                        CREATE_HANDLE( MBCN::TypeDimensionMap[dim].second, MB_END_ID, junk ) :
-                        (*iter).second;
-    count += eh - sh + 1;
-  }
-
-  return count;
-}
-  
-    
-
-
-//! swap the contents of this range with another one
-//! THIS FUNCTION MUST NOT BE INLINED, THAT WILL ELIMINATE RANGE_EMPTY AND THIS_EMPTY
-//! BY SUBSTITUTION AND THE FUNCTION WON'T WORK RIGHT!
-void MBRange::swap( MBRange &range )
-{
-    // update next/prev nodes of head of both ranges
-  bool range_empty = (range.mHead.mNext == &(range.mHead));
-  bool this_empty = (mHead.mNext == &mHead);
-
-  range.mHead.mNext->mPrev = (range_empty ? &(range.mHead) : &mHead);
-  range.mHead.mPrev->mNext = (range_empty ? &(range.mHead) : &mHead);
-  mHead.mNext->mPrev = (this_empty ? &mHead : &(range.mHead));
-  mHead.mPrev->mNext = (this_empty ? &mHead : &(range.mHead));
-
-    // switch data in head nodes of both ranges
-  PairNode *range_next = range.mHead.mNext, *range_prev = range.mHead.mPrev;
-  range.mHead.mNext = (this_empty ? &(range.mHead) : mHead.mNext);
-  range.mHead.mPrev = (this_empty ? &(range.mHead) : mHead.mPrev);
-  mHead.mNext = (range_empty ? &mHead : range_next);
-  mHead.mPrev = (range_empty ? &mHead : range_prev);
-
-}
-
-int MBRange::index(MBEntityHandle handle) const 
-{
-  if (handle < *begin() || handle > *rbegin()) return -1;
-  
-  unsigned int i = 0;
-  MBRange::const_pair_iterator pit = const_pair_begin(); 
-  while (handle > (*pit).second && pit != const_pair_end()) {
-    i += (*pit).second - (*pit).first + 1;
-    pit++;
-  }
-  if (handle < (*pit).first || pit == const_pair_end()) return -1;
-  
-  return i + handle - (*pit).first;
-}
-
-    //! return a subset of this range, by type
-MBRange MBRange::subset_by_type(MBEntityType t) const
-{
-  MBRange result;
-  std::pair<const_iterator, const_iterator> iters = equal_range(t);
-  result.merge( iters.first, iters.second );
-  return result;
-}
-
-bool operator==( const MBRange& r1, const MBRange& r2 )
-{
-  MBRange::const_pair_iterator i1, i2;
-  i1 = r1.const_pair_begin();
-  i2 = r2.const_pair_begin();
-  for ( ; i1 != r1.const_pair_end(); ++i1, ++i2) 
-    if (i2 == r2.const_pair_end() ||
-        i1->first != i2->first ||
-        i1->second != i2->second)
-      return false;
-  return i2 == r2.const_pair_end();
-}
-
-unsigned long MBRange::get_memory_use() const
-{
-  unsigned long result = 0;
-  for (const PairNode* n = mHead.mNext; n != &mHead; n = n->mNext)
-    result += sizeof(PairNode);
-  return result;
-}
-

Deleted: MOAB/trunk/src/MBRangeSeqIntersectIter.cpp
===================================================================
--- MOAB/trunk/src/MBRangeSeqIntersectIter.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBRangeSeqIntersectIter.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,164 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBRangeSeqIntersectIter.cpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-08-11
- */
-
-#include "MBRangeSeqIntersectIter.hpp"
-#include "SequenceManager.hpp"
-#include "EntitySequence.hpp"
-#include <assert.h>
-
-MBErrorCode MBRangeSeqIntersectIter::init( MBRange::const_iterator start,
-                                           MBRange::const_iterator end )
-{
-  mSequence = 0;
-  rangeIter = start;
-
-    // special case : nothing to iterate over
-  if (start == end) {
-    mStartHandle = mEndHandle = mLastHandle = 0;
-    return MB_FAILURE;
-  }
-
-    // normal case
-  mStartHandle = *start;
-  --end;
-  mLastHandle = *end;
-  mEndHandle = (*rangeIter).second;
-  if (mEndHandle > mLastHandle)
-    mEndHandle = mLastHandle;
-
-#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
-  MBErrorCode result = update_entity_sequence();
-  update_stats(mEndHandle - mStartHandle + 1);
-  return result;
-#else
-  return update_entity_sequence();
-#endif
-}
-  
-
-MBErrorCode MBRangeSeqIntersectIter::step()
-{
-    // If at end, return MB_FAILURE
-  if (is_at_end())
-    return MB_FAILURE; 
-    // If the last block was at the end of the rangeIter pair,
-    // then advance the iterator and set the next block
-  else if (mEndHandle == (*rangeIter).second) {
-    ++rangeIter;
-    mStartHandle = (*rangeIter).first;
-  }
-    // Otherwise start with next entity in the pair
-  else {
-    mStartHandle = mEndHandle + 1;
-  }
-    // Always take the remaining entities in the rangeIter pair.
-    // will trim up the end of the range in update_entity_sequence().
-  mEndHandle = (*rangeIter).second;
-  if (mEndHandle > mLastHandle)
-    mEndHandle = mLastHandle;
-  
-    // Now trim up the range (decrease mEndHandle) as necessary
-    // for the corresponding EntitySquence
-#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
-  MBErrorCode result = update_entity_sequence();
-  update_stats(mEndHandle - mStartHandle + 1);
-  return result;
-#else
-  return update_entity_sequence();
-#endif
-}
-
-MBErrorCode MBRangeSeqIntersectIter::update_entity_sequence()
-{
-    // mStartHandle to mEndHandle is a subset of the MBRange.
-    // Update sequence data as necessary and trim that subset
-    // (reduce mEndHandle) for the current EntitySequence.
-  
-    // Need to update the sequence pointer?
-  if (!mSequence || mStartHandle > mSequence->end_handle()) {
-  
-      // Check that the mStartHandle is valid
-    if (TYPE_FROM_HANDLE(mStartHandle) >= MBMAXTYPE)
-      return MB_TYPE_OUT_OF_RANGE;
-
-    if (MB_SUCCESS != mSequenceManager->find( mStartHandle, mSequence ))
-      return find_invalid_range();
-  }
-    
-    // if mEndHandle is past end of sequence or block of used
-    // handles within sequence, shorten it.
-  if(mEndHandle > mSequence->end_handle())
-    mEndHandle = mSequence->end_handle();
-  
-  return MB_SUCCESS;
-}
- 
-MBErrorCode MBRangeSeqIntersectIter::find_invalid_range()
-{
-  assert(!mSequence);
-
-    // no more entities in current range
-  if (mStartHandle == mEndHandle)
-    return MB_ENTITY_NOT_FOUND;
-    
-    // Find the next MBEntitySequence
-  MBEntityType type = TYPE_FROM_HANDLE(mStartHandle);
-  const TypeSequenceManager& map = mSequenceManager->entity_map( type );
-  TypeSequenceManager::const_iterator iter = map.upper_bound( mStartHandle );
-    // If no next sequence of the same type
-  if (iter == map.end()) {
-      // If end type not the same as start type, split on type
-    if (type != TYPE_FROM_HANDLE( mEndHandle )) {
-      int junk;
-      mEndHandle = CREATE_HANDLE( type, MB_END_ID, junk );
-    }
-  }
-    // otherwise invalid range ends at min(mEndHandle, sequence start handle - 1)
-  else if ((*iter)->start_handle() <= mEndHandle) {
-    mEndHandle = (*iter)->start_handle()-1;
-  }
-  
-  return MB_ENTITY_NOT_FOUND;
-}
-        
-#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
-double MBRangeSeqIntersectIter::doubleNumCalls = 0;
-double MBRangeSeqIntersectIter::doubleEntCount = 0;
-unsigned long MBRangeSeqIntersectIter::intNumCalls = 0;
-unsigned long MBRangeSeqIntersectIter::intEntCount = 0;
-
-void MBRangeSeqIntersectIter::update_stats( unsigned long num_ents )
-{
-  if (std::numeric_limits<unsigned long>::max() == intNumCalls) {
-    doubleNumCalls += intNumCalls;
-    intNumCalls = 0;
-  }
-  ++intNumCalls;
-  
-  if (std::numeric_limits<unsigned long>::max() - intEntCount > num_ents) {
-    doubleNumCalls += intEntCount;
-    intEntCount = num_ents;
-  }
-  else {
-    intEntCount += num_ents;
-  }
-}
-#endif
-

Deleted: MOAB/trunk/src/MBRangeSeqIntersectIter.hpp
===================================================================
--- MOAB/trunk/src/MBRangeSeqIntersectIter.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBRangeSeqIntersectIter.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,137 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBRangeSeqIntersectIter.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-08-11
- *\date 2007-11-06
- */
-
-#ifndef MB_RANGE_SEQ_INTERSECT_ITER_HPP
-#define MB_RANGE_SEQ_INTERSECT_ITER_HPP
-
-#include "MBTypes.h"
-#include "MBRange.hpp"
-
-class SequenceManager;
-class EntitySequence;
-
-#define MB_RANGE_SEQ_INTERSECT_ITER_STATS 0
-
-/** \brief Iterate over the blocks of MBEntityHandles in an MBRange that
- *         are in the same EntitySequence.
- *
- * Iterate over an MBRange, returning blocks of entities that are the 
- * largest ranges of contiguous handles that meet one of the following
- * conditions:
- *  - All are valid handles belonging to the same EntitySequence
- *  - All are invalid handles of the same MBEntityType
- *
- * The return type from init() or step() indicates whether or not the
- * current range contains valid entities.  If the handles are either
- * all valid or all holes in an EntitySequence, that sequence can
- * be obtained with get_sequence().  get_sequence() will return NULL if
- * there is no corresponding EntitySequence for the block of handles.
- *
- * This class keeps a data related to the 'current' EntitySequence and
- * references to the MBRange pasesd to init().  Changing either of these
- * while an instance of this class is in use would be bad.
- */
-class MBRangeSeqIntersectIter {
-public:
-  
-  MBRangeSeqIntersectIter( SequenceManager* sequences )
-    : mSequenceManager( sequences ),
-      mSequence( 0 ),
-      mStartHandle( 0 ),
-      mEndHandle( 0 ),
-      mLastHandle( 0 )
-    { }
-    
-    /** Initialize iterator to first valid subset 
-     *\return - MB_SUCCESS : initial position of iterator is valid
-     *        - MB_ENITITY_NOT_FOUND : range contains invalid handle -- can step past by calling again
-     *        - MB_FAILURE : No entities (start == end)
-     */
-  MBErrorCode init( MBRange::const_iterator start, MBRange::const_iterator end );
-  
-    /** Step iterator to next range.  
-     *\return - MB_SUCCESS : there is another range, and iter has been changed to it
-     *        - MB_ENITITY_NOT_FOUND : range contains invalid handle -- can step past by calling again
-     *        - MB_FAILURE : at end.
-     */
-  MBErrorCode step();
-  
-    /**\brief Check if next call to step() will return MB_FAILURE.
-     *
-     * Check if the iterator cannot be advanced any further.
-     * If this method returns true, then the *next* call to step()
-     * will return MB_FAILURE.
-     */
-  bool is_at_end() const
-    { return mEndHandle == mLastHandle; }
-  
-    /** Get the MBEntitySequence for the current block.
-     *  May be NULL for invaild handles.
-     */
-  EntitySequence* get_sequence() const
-    { return mSequence; }
-  
-    /** Get first handle in block */
-  MBEntityHandle get_start_handle() const
-    { return mStartHandle; }
-  
-    /** Get last handle in block */
-  MBEntityHandle get_end_handle() const
-    { return mEndHandle; }
-
-#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
-  static double fragmentation() 
-    { return (doubleNumCalls + intNumCalls) / (doubleEntCount + intEntCount); }
-#endif
-    
-private:
-
-  /** Update entity sequence data (mSequence and freeIndex) for current
-   *  mStartHandle.  If mEndHandle is past end of sequence, trim it.
-   *  Called by step() and init().  step() handles iterating over the pairs 
-   *  in the MBRange.  This method handles iterating over the set of 
-   *  MBEntitySequences that intersect the pair.
-   */
-  MBErrorCode update_entity_sequence();
-  
-  /** Handle error case where we encountered an MBEntityHandle w/out
-   *  a corresponding MBEntitySequence.  Trim mEndHandle such that it
-   *  is before the next valid MBEntityHandle of the same type.
-   *\return Always returns MB_ENTITY_NOT_FOUND
-   */
-  MBErrorCode find_invalid_range();
-
-  SequenceManager* mSequenceManager;       //!< THE EntitySequenceManager
-  EntitySequence* mSequence;               //!< EntitySequence corresponding to current location
-  MBRange::const_pair_iterator rangeIter;  //!< Current position in MBRange.
-  MBEntityHandle mStartHandle, mEndHandle; //!< Subset of current MBEntitySequence
-  MBEntityHandle mLastHandle;              //!< The last of the list of all handles in the MBRange
-
-#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
-  static double doubleNumCalls, doubleEntCount;
-  static unsigned long intNumCalls, intEntCount;
-  static void update_stats( unsigned long num_ents);
-#endif
-};
-
-#endif
-
-

Deleted: MOAB/trunk/src/MBReadUtil.cpp
===================================================================
--- MOAB/trunk/src/MBReadUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBReadUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,392 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifdef WIN32
-#ifdef _DEBUG
-// turn off warnings that say they debugging identifier has been truncated
-// this warning comes up when using some STL containers
-#pragma warning(disable : 4786)
-#endif
-#endif
-
-#include "MBReadUtil.hpp"
-#include "MBCore.hpp"
-#include "AEntityFactory.hpp"
-#include "MBError.hpp"
-#include "SequenceManager.hpp"
-#include "VertexSequence.hpp"
-#include "ElementSequence.hpp"
-
-#define RR if (MB_SUCCESS != result) return result
-
-MBReadUtil::MBReadUtil(MBCore* mdb, MBError* error_handler) 
-    : MBReadUtilIface(), mMB(mdb), mError(error_handler)
-{
-}
-
-MBErrorCode MBReadUtil::get_node_arrays(
-    const int /*num_arrays*/,
-    const int num_nodes, 
-    const int preferred_start_id,
-    MBEntityHandle& actual_start_handle, 
-    std::vector<double*>& arrays)
-{
-
-  MBErrorCode error;
-  EntitySequence* seq = 0;
-  
-  if (num_nodes < 1) {
-    actual_start_handle = 0;
-    arrays.clear();
-    return MB_INDEX_OUT_OF_RANGE;
-  }
-
-  // create an entity sequence for these nodes 
-  error = mMB->sequence_manager()->create_entity_sequence(
-    MBVERTEX, num_nodes, 0, preferred_start_id, 
-    actual_start_handle,
-    seq);
-
-  if(error != MB_SUCCESS)
-    return error;
-
-  if (seq->start_handle() > actual_start_handle ||
-      seq->end_handle() < actual_start_handle ||
-      seq->end_handle() - actual_start_handle + 1 < (unsigned)num_nodes)
-    return MB_FAILURE;
-
-  arrays.resize(3);
-
-  error = static_cast<VertexSequence*>(seq)->get_coordinate_arrays(arrays[0], arrays[1], arrays[2]);
-  for (unsigned i = 0; i< arrays.size(); ++i)
-    if (arrays[i])
-      arrays[i] += (actual_start_handle - seq->start_handle());
-  
-  return error;
-}
-
-MBErrorCode MBReadUtil::get_element_array(
-    const int num_elements, 
-    const int verts_per_element,
-    const MBEntityType mdb_type,
-    const int preferred_start_id, 
-    MBEntityHandle& actual_start_handle, 
-    MBEntityHandle*& array)
-{
-
-  MBErrorCode error;
-  EntitySequence* seq;
-  
-  if (num_elements < 1) {
-    actual_start_handle = 0;
-    array = 0;
-    return MB_INDEX_OUT_OF_RANGE;
-  }
-  
-//  if (mdb_type <= MBVERTEX || mdb_type >= MBPOLYHEDRON || mdb_type == MBPOLYGON)
-//    return MB_TYPE_OUT_OF_RANGE;
-
-  // make an entity sequence to hold these elements
-  error = mMB->sequence_manager()->create_entity_sequence(
-      mdb_type, num_elements, verts_per_element, preferred_start_id, 
-      actual_start_handle, seq);
-  if (MB_SUCCESS != error)
-    return error;
-
-  if (seq->start_handle() > actual_start_handle ||
-      seq->end_handle() < actual_start_handle ||
-      seq->end_handle() - actual_start_handle + 1 < (unsigned)num_elements)
-    return MB_FAILURE;
-
-  // get an array for the connectivity
-  array = static_cast<ElementSequence*>(seq)->get_connectivity_array();
-  if (!array)
-    return MB_FAILURE;
-  array += (actual_start_handle - seq->start_handle()) 
-         * static_cast<ElementSequence*>(seq)->nodes_per_element();
-
-  return error;
-  
-}
-
-MBErrorCode MBReadUtil::create_entity_sets( MBEntityID num_sets,
-                                            const unsigned* flags ,
-                                            MBEntityID start_id,
-                                            MBEntityHandle& start_handle )
-{
-  if (num_sets < 1) {
-    start_handle = 0;
-    return MB_INDEX_OUT_OF_RANGE;
-  }
-
-  MBErrorCode error;
-  EntitySequence* seq;
-  error = mMB->sequence_manager()->create_meshset_sequence( num_sets,
-                                                            start_id,
-                                                            flags,
-                                                            start_handle,
-                                                            seq );
-  if (MB_SUCCESS != error)
-    return error;
-
-  if (seq->start_handle() > start_handle ||
-      seq->end_handle() < start_handle ||
-      seq->end_handle() - start_handle + 1 < (MBEntityHandle)num_sets)
-    return MB_FAILURE;
-    
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBReadUtil::update_adjacencies(
-      const MBEntityHandle start_handle,
-      const int number_elements,
-      const int number_vertices_per_element,
-      const MBEntityHandle* conn_array)
-{
-
-  MBEntityHandle tmp_hndl = start_handle;
-  AEntityFactory* adj_fact = mMB->a_entity_factory();
-
-  // iterator over the elements and update adjacency information
-  if(adj_fact != NULL && adj_fact->vert_elem_adjacencies())
-  {
-    int j=0;
-    for(int i=0; i<number_elements; i++)
-    {
-      adj_fact->notify_create_entity( tmp_hndl, (conn_array+j), number_vertices_per_element);
-      tmp_hndl++;
-      j+=number_vertices_per_element;
-    }
-  }
-  return MB_SUCCESS;
-}
-
-
-
-MBErrorCode MBReadUtil::report_error( const std::string& error )
-{
-  if(mError)
-    return mError->set_last_error(error);
-  else
-    return MB_FAILURE;
-}
-
-
-MBErrorCode MBReadUtil::report_error( const char* error, ... )
-{
-  va_list args;
-  va_start(args, error);
-  MBErrorCode result = mError->set_last_error(error, args);
-  va_end(args);
-  return result;
-}
-
-MBErrorCode MBReadUtil::gather_related_ents(MBRange &partition,
-                                            MBRange &related_ents,
-                                            MBRange *all_sets) 
-{
-    // loop over any sets, getting contained ents
-  std::pair<MBRange::const_iterator, MBRange::const_iterator> pair_it =
-    partition.equal_range(MBENTITYSET);
-
-  MBErrorCode result = MB_SUCCESS;
-  for (MBRange::const_iterator rit = pair_it.first; 
-       rit != pair_it.second; rit++) {
-    MBErrorCode tmp_result = 
-      mMB->get_entities_by_handle(*rit, related_ents, 
-                                  MBInterface::UNION);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  RR;
-
-    // gather adjacent ents of other dimensions
-  MBRange tmp_ents;
-  for (int dim = 3; dim >= 0; dim--) {
-    tmp_ents.clear();
-    MBErrorCode tmp_result = mMB->get_adjacencies(related_ents, dim, false, 
-                                                  tmp_ents, 
-                                                  MBInterface::UNION);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-    else related_ents.merge(tmp_ents);
-  }
-  RR;
-  
-    // related ents includes the partition itself
-  related_ents.merge(partition);
-  
-    // get contains-related sets
-  MBRange tmp_ents3, last_related;
-  if (!all_sets) all_sets = &tmp_ents3;
-  result = mMB->get_entities_by_type(0, MBENTITYSET, *all_sets); RR;
-  while (related_ents.size() != last_related.size()) {
-    last_related = related_ents;
-    for (MBRange::iterator rit = all_sets->begin(); 
-         rit != all_sets->end(); rit++) {
-      if (related_ents.find(*rit) != related_ents.end()) continue;
-      
-      tmp_ents.clear();
-      result = mMB->get_entities_by_handle(*rit, tmp_ents, true); RR;
-      MBRange tmp_ents2 = intersect( tmp_ents, related_ents);
-    
-        // if the intersection is not empty, set is related
-      if (!tmp_ents2.empty()) related_ents.insert(*rit);
-    }
-  }
-  
-    // get parent/child-related sets
-  last_related.clear();
-  while (related_ents.size() != last_related.size()) {
-    last_related = related_ents;
-    std::pair<MBRange::const_iterator, MBRange::const_iterator> it_pair = 
-      last_related.equal_range(MBENTITYSET);
-
-    for (MBRange::const_iterator rit = it_pair.first;
-         rit != it_pair.second; rit++) {
-        // get all parents/children and add to related ents
-      tmp_ents.clear();
-      result = mMB->get_parent_meshsets(*rit, tmp_ents, 0); RR;
-      related_ents.merge(tmp_ents);
-      
-      tmp_ents.clear();
-      result = mMB->get_child_meshsets(*rit, tmp_ents, 0); RR;
-      related_ents.merge(tmp_ents);
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBReadUtil::get_ordered_vertices(MBEntityHandle *bound_ents,
-                                             int *sense, 
-                                             int bound_size,
-                                             int dim,
-                                             MBEntityHandle *bound_verts, 
-                                             MBEntityType &etype) 
-{
-    // get dimension of bounding entities
-  int bound_dim = MBCN::Dimension(TYPE_FROM_HANDLE(bound_ents[0]));
-  int indices[MB_MAX_SUB_ENTITY_VERTICES];
-  const MBEntityHandle *connect;
-  std::vector<MBEntityHandle> tmp_connect;
-  
-    // find the right entity type based on # bounding ents
-  int numv = 0, num_connect;
-  MBErrorCode result;
-  for (MBEntityType t = MBEDGE; t < MBENTITYSET; t++) {
-    int nindex = MBCN::NumSubEntities(t, bound_dim);
-    if (MBCN::Dimension(t) != dim || nindex != bound_size) 
-      continue;
-
-      // fill in vertices from bounding entity vertices
-    int nverts = MBCN::VerticesPerEntity(t);
-    std::fill(bound_verts, bound_verts+nverts, 0);
-    for (int index = 0; index < nindex; index++) {
-      result = mMB->get_connectivity(bound_ents[index], connect, num_connect,
-                                     false, &tmp_connect);
-      if (MB_SUCCESS != result) return result;
-      
-      MBCN::SubEntityVertexIndices(t, bound_dim, index, indices);
-
-      for (int c = 0; c < num_connect; c++) {
-        if (!bound_verts[indices[c]]) {
-          bound_verts[indices[c]] = (sense[index] > 0) ?
-              connect[c] : connect[num_connect - c - 1];
-          numv++;
-        }
-      }
-      if (numv == nverts) {
-        etype = t;
-        return MB_SUCCESS;
-      }
-    }
-  }
-  
-    // if we get here, we didn't get full connectivity
-  etype = MBMAXTYPE;
-  return MB_FAILURE;
-}
-
-static MBErrorCode check_int_tag( MBInterface* mb, MBTag tag )
-{
-  int size;
-  MBDataType type;
-  MBErrorCode rval = mb->tag_get_size( tag, size );
-  if (MB_SUCCESS != rval)
-    return rval;
-  if (size != sizeof(int))
-    return MB_TYPE_OUT_OF_RANGE;
-  rval = mb->tag_get_data_type( tag, type );
-  if (type != MB_TYPE_OPAQUE && type != MB_TYPE_INTEGER)
-    return MB_TYPE_OUT_OF_RANGE;
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBReadUtil::assign_ids( MBTag id_tag, const MBRange& ents, int start )
-{
-  MBErrorCode rval = check_int_tag( mMB, id_tag );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-  MBRange tmp_range;
-  std::vector<int> data;
-  for (MBRange::const_pair_iterator i = ents.pair_begin(); 
-       i != ents.pair_end(); ++i) {
-    data.resize( i->second + 1 - i->first );
-    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
-      *j = start++;
-    tmp_range.clear();
-    tmp_range.insert( i->first, i->second );
-    rval = mMB->tag_set_data( id_tag, tmp_range, &data[0] );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBReadUtil::assign_ids( MBTag id_tag, 
-                                    const MBEntityHandle* ents, 
-                                    size_t num_ents, 
-                                    int start )
-{
-  MBErrorCode rval = check_int_tag( mMB, id_tag );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-  std::vector<int> data;
-  const MBEntityHandle* const end = ents + num_ents;
-  const MBEntityHandle* i = ents;
-  while (i != end) {
-    const MBEntityHandle* next = std::find( i, end, 0 );
-    size_t size = next - i;
-    if (!size) {
-      ++i;
-      continue;
-    }
-    
-    int id = start + (i - ents);
-    data.resize(size);
-    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
-      *j = id++;
-    
-    rval = mMB->tag_set_data( id_tag, i, size, &data[0] );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  return MB_SUCCESS;
-}
-

Deleted: MOAB/trunk/src/MBReadUtil.hpp
===================================================================
--- MOAB/trunk/src/MBReadUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBReadUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,116 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-#ifndef MB_READ_UTIL_HPP
-#define MB_READ_UTIL_HPP
-
-#ifndef IS_BUILDING_MB
-#error "MBReadUtil.hpp isn't supposed to be included into an application"
-#endif
-
-#include "MBReadUtilIface.hpp"
-
-class MBCore;
-class MBError;
-
-class MBReadUtil : public MBReadUtilIface
-{
-private:
-  //! pointer to the MBCore
-  MBCore* mMB;
-  MBError* mError;
-public:
-
-  //! constructor takes MBCore pointer
-  MBReadUtil(MBCore* mdb, MBError* error_handler);
-
-  //! destructor
-  ~MBReadUtil(){}
-
-  //! gets arrays for coordinate data from the MB
-  MBErrorCode get_node_arrays(
-      const int num_arrays,
-      const int num_nodes, 
-      const int preferred_start_id,
-      MBEntityHandle& actual_start_handle, 
-      std::vector<double*>& arrays
-      );
-
-  //! get array for connectivity data from the MB
-  MBErrorCode get_element_array(
-      const int num_elements, 
-      const int verts_per_element,
-      const MBEntityType mdb_type,
-      const int preferred_start_id, 
-      MBEntityHandle& actual_start_handle, 
-      MBEntityHandle*& array
-      );
-
-    /**
-     *\brief Gather entities related to those in the partition
-     * Gather entities related to those in the input partition.  Related
-     * means down-adjacent to, contained in, etc.
-     * \param partition Entities for which to gather related entities
-     * \param related_ents Related entities
-     * \param all_sets If non-NULL, all sets in mesh instance are returned
-     * in the pointed-to range
-     */
-  MBErrorCode gather_related_ents(MBRange &partition,
-                                  MBRange &related_ents,
-                                  MBRange *all_sets);
-  
-  MBErrorCode create_entity_sets(
-    MBEntityID num_sets,
-    const unsigned* set_flags,
-    MBEntityID preffered_start_id,
-    MBEntityHandle& actual_start_handle
-  );
- 
-  //! tell MB which elements have been added to the database
-  MBErrorCode update_adjacencies(
-      const MBEntityHandle start_handle,
-      const int number_elements,
-      const int number_vertices_per_element,
-      const MBEntityHandle* conn_array);
-
-  //! tell MB there was an error when reading the mesh
-  //! it makes sense to have this as long as MBInterface has a load_mesh function
-  MBErrorCode report_error( const std::string& error );
-
-  MBErrorCode report_error( const char* error, ... )
-#ifdef __GNUC__
-__attribute__((format(printf,2,3)))
-#endif
-  ;
-
-    //! given an ordered list of bounding entities and the sense of
-    //! those entities, return an ordered list of vertices
-  MBErrorCode get_ordered_vertices(MBEntityHandle *bound_ents, 
-                                   int *sense, 
-                                   int num_bound,
-                                   int dim,
-                                   MBEntityHandle *bound_verts, 
-                                   MBEntityType &etype);
-
-
-  MBErrorCode assign_ids( MBTag id_tag, const MBRange& ents, int start = 0 );
-  MBErrorCode assign_ids( MBTag id_tag, const MBEntityHandle* ents, 
-                          size_t num_ents, int start = 0 );
-};
-
-#endif
-
-

Deleted: MOAB/trunk/src/MBReaderWriterSet.cpp
===================================================================
--- MOAB/trunk/src/MBReaderWriterSet.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBReaderWriterSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,283 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#include "MBCore.hpp"
-#include "MBError.hpp"
-
-#include "MBReaderWriterSet.hpp"
-#include "MBReaderIface.hpp"
-#include "MBWriterIface.hpp"
-
-#include "ReadVtk.hpp"
-#include "ReadSTL.hpp"
-#include "ReadGmsh.hpp"
-#include "ReadIDEAS.hpp"
-#include "ReadMCNP5.hpp"
-#include "ReadNASTRAN.hpp"
-#include "ReadABAQUS.hpp"
-#include "ReadSms.hpp"
-#include "Tqdcfr.hpp"
-#include "ReadTetGen.hpp"
-#include "ReadSmf.hpp"
-#ifdef CGM
-#  include "ReadCGM.hpp"
-#endif
-
-#include "WriteAns.hpp"
-#include "WriteVtk.hpp"
-#include "WriteGMV.hpp"
-#include "WriteSTL.hpp"
-#include "WriteGmsh.hpp"
-#include "WriteSmf.hpp"
-
-#ifdef NETCDF_FILE
-#  include "ReadNCDF.hpp"
-#  include "WriteNCDF.hpp"
-#  include "WriteSLAC.hpp"
-#endif
-
-#ifdef CCMIO_FILE
-#  include "WriteCCMIO.hpp"
-#  include "ReadCCMIO.hpp"
-#endif
-
-#ifdef HDF5_FILE
-#  include "ReadHDF5.hpp"
-#  ifdef HDF5_PARALLEL
-#    include "WriteHDF5Parallel.hpp"
-#  else
-#    include "WriteHDF5.hpp"
-#  endif
-#endif
-
-#include <algorithm>
-
-MBReaderWriterSet::MBReaderWriterSet( MBCore* mdb, MBError* handler )
-  : mbCore( mdb ), mbError( handler ) 
-{
-#ifdef HDF5_FILE
-  const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
-#ifdef HDF5_PARALLEL
-  register_factory(  ReadHDF5::factory, WriteHDF5Parallel::factory, 
-                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
-#else
-  register_factory(  ReadHDF5::factory, WriteHDF5::factory, 
-                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
-#endif
-#endif
-
-#ifdef NETCDF_FILE
-  const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
-  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
-#endif
-
-  register_factory( ReadIDEAS::factory, NULL, "IDEAS format", "unv", "UNV" );
-  
-  register_factory( ReadMCNP5::factory, NULL, "MCNP5 format", "meshtal", "MESHTAL" );
-  
-  const char* nastran_sufxs[] = { "nas", "bdf", NULL };
-  register_factory( ReadNASTRAN::factory, NULL, "NASTRAN format", nastran_sufxs, "NAS" );
-
-  register_factory( ReadABAQUS::factory, NULL, "ABAQUS INP mesh format", "abq", "Abaqus mesh" );
-  
-  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );
-  
-  register_factory( ReadSms::factory, NULL, "RPI SMS", "sms", "SMS" );
-  
-  register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );
-  
-  register_factory( ReadSmf::factory, WriteSmf::factory , "QSlim format", "smf", "SMF");
-
-#ifdef CGM
-  const char* acis_sufxs[] = { "sat", "sab", NULL };
-  const char* occ_sufxs[] = { "brep", "occ", NULL };
-  const char* step_sufxs[] = { "step", "stp", NULL };
-  const char* iges_sufxs[] = { "iges", "igs", NULL };
-  register_factory( ReadCGM::factory, NULL, "ACIS solid model", acis_sufxs, "ACIS");
-  register_factory( ReadCGM::factory, NULL, "OpenCascade solid model", occ_sufxs, "OCC");
-  register_factory( ReadCGM::factory, NULL, "STEP B-Rep exchange", step_sufxs, "STEP");
-  register_factory( ReadCGM::factory, NULL, "IGES B-Rep exchange", iges_sufxs, "IGES");
-#endif
-
-#ifdef NETCDF_FILE  
-  register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
-#endif
-
-#ifdef CCMIO_FILE  
-  const char* ccmio_sufxs[] = { "ccm", "ccmg", NULL };
-  register_factory( ReadCCMIO::factory, WriteCCMIO::factory, "CCMIO files", ccmio_sufxs, "CCMIO");
-#endif
-
-  register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );
-  
-  register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );
-  
-  const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
-  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );
-  
-  register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );
-
-  const char* tetgen_sufxs[] = { "node", "ele", "face", "edge", NULL };
-  register_factory( ReadTetGen::factory, 0, "TetGen output files", tetgen_sufxs, "TETGEN" );
-}
-
-
-MBReaderWriterSet::~MBReaderWriterSet()
-{
-}
-
-MBErrorCode MBReaderWriterSet::register_factory( reader_factory_t reader,
-                                                 writer_factory_t writer,
-                                                 const char* description,
-                                                 const char* const* extensions,
-                                                 const char* name )
-{
-  if (!reader && !writer)
-    return MB_FAILURE;
-    
-    // check for duplicate names
-  iterator h = handler_by_name( name );
-  if (h != end()) {
-    mbError->set_last_error( "Conflicting string name for file formats: \"%s\"",
-                             name );
-    return MB_FAILURE;
-  }
-  
-    // count extensions and check for duplicates
-  const char* const* iter;
-  for (iter = extensions; *iter; ++iter)
-  {
-    h = handler_from_extension( *iter );
-    if (h != end())
-    {
-      if (NULL != reader && h->have_reader())
-        mbError->set_last_error( "Conflicting readers for file extension \"%s\":"
-                                 " \"%s\" and \"%s\".",
-                                 *iter, h->description().c_str(), description );
-      else if(NULL != writer && h->have_writer())
-        mbError->set_last_error( "Conflicting writers for file extension \"%s\":"
-                                 " \"%s\" and \"%s\".",
-                                 *iter, h->description().c_str(), description );
-    }
-  }
-  handlerList.push_back( Handler(reader, writer, name, description, extensions, iter - extensions) );
-  return MB_SUCCESS;
-}    
-
-MBErrorCode MBReaderWriterSet::register_factory( reader_factory_t reader,
-                                                 writer_factory_t writer,
-                                                 const char* description,
-                                                 const char* extension,
-                                                 const char* name )
-{
-  const char* extensions[2] = {extension, NULL};
-  return register_factory( reader, writer, description, extensions, name );
-}
-
-  
-MBReaderIface* MBReaderWriterSet::get_file_extension_reader( 
-                                  const std::string& filename ) const
-{
-  std::string ext = extension_from_filename( filename );
-  iterator handler = handler_from_extension( ext, true, false );
-  return handler == end() ? NULL : handler->make_reader(mbCore);
-}
-
-MBWriterIface* MBReaderWriterSet::get_file_extension_writer( 
-                                  const std::string& filename ) const
-{
-  std::string ext = extension_from_filename( filename );
-  iterator handler = handler_from_extension( ext, false, true );
-  return handler == end() ? NULL : handler->make_writer(mbCore);
-}
-
-std::string MBReaderWriterSet::extension_from_filename( 
-                                 const std::string& filename )
-{
-  std::string::size_type idx = filename.find_last_of( "." );
-  if (idx == std::string::npos)
-    return std::string("");
-  else
-    return filename.substr( idx + 1 );
-}
-
-MBReaderWriterSet::Handler::Handler( reader_factory_t read_f, 
-                                     writer_factory_t write_f,
-                                     const char* name,
-                                     const char* desc, 
-                                     const char* const* ext, 
-                                     int num_ext )
- : mReader(read_f), mWriter(write_f), mName(name), mDescription(desc), mExtensions(num_ext)
-{
-  for (int i = 0; i < num_ext; ++i)
-    mExtensions[i] = ext[i];
-}
-
-#ifdef WIN32
-#define strcasecmp(A,B) _stricmp( A, B )
-#endif
-
-MBReaderWriterSet::iterator 
-MBReaderWriterSet::handler_from_extension( const std::string& ext,
-                                           bool with_reader,
-                                           bool with_writer ) const
-{
-  iterator iter;
-  std::vector<std::string>::const_iterator siter;
-  
-    // try case-sensitive compare
-  for (iter = begin(); iter != end(); ++iter)
-  {
-    if ((with_reader && !iter->have_reader()) ||
-        (with_writer && !iter->have_writer()))
-      continue;
-      
-    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
-      if (*siter == ext)
-        return iter;
-  }
-  
-    // try case-insensitive compare
-  for (iter = begin(); iter != end(); ++iter)
-  {
-    if ((with_reader && !iter->have_reader()) ||
-        (with_writer && !iter->have_writer()))
-      continue;
- 
-    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
-      if (0 == strcasecmp( siter->c_str(), ext.c_str() ))
-        return iter;
-  }
-  
-  return end();
-}
-
-MBReaderWriterSet::iterator
-MBReaderWriterSet::handler_by_name( const char* name ) const
-{
-  return std::find( begin(), end(), name );
-}
-
-bool MBReaderWriterSet::Handler::operator==( const char* name ) const
-{
-    // do case-insensitive comparison
-  std::string::const_iterator siter = mName.begin();
-  for (; *name; ++name, ++siter)
-    if (siter == mName.end() || tolower(*name) != tolower(*siter))
-      return false;
-  return *name == '\0';
-}
-
-

Deleted: MOAB/trunk/src/MBSkinner.cpp
===================================================================
--- MOAB/trunk/src/MBSkinner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBSkinner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1919 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifdef __MFC_VER
-#pragma warning(disable:4786)
-#endif
-
-#include "MBSkinner.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include <vector>
-#include <set>
-#include <algorithm>
-#include <math.h>
-#include <assert.h>
-#include <iostream>
-#include "MBUtil.hpp"
-#include "MBInternals.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
-#include "AEntityFactory.hpp"
-
-#ifdef M_PI
-#  define SKINNER_PI M_PI
-#else
-#  define SKINNER_PI 3.1415926535897932384626
-#endif
-
-
-
-MBSkinner::~MBSkinner()
-{
-  // delete the adjacency tag
-}
-
-
-void MBSkinner::initialize()
-{
-  // go through and mark all the target dimension entities
-  // that already exist as not deleteable
-  // also get the connectivity tags for each type
-  // also populate adjacency information
-  MBEntityType type;
-  MBDimensionPair target_ent_types = MBCN::TypeDimensionMap[mTargetDim];
-
-  void* null_ptr = NULL;
-  MBErrorCode result;
-
-  result = thisMB->tag_create("skinner adj", sizeof(void*), MB_TAG_DENSE, mAdjTag, &null_ptr);
-  assert(MB_SUCCESS == result);
-
-  if(mDeletableMBTag == 0) {
-    result = thisMB->tag_create("skinner deletable", 1, MB_TAG_BIT, mDeletableMBTag, NULL);
-    assert(MB_SUCCESS == result);
-  }
-  
-  MBRange entities;
-
-    // go through each type at this dimension 
-  for(type = target_ent_types.first; type <= target_ent_types.second; ++type)
-  {
-      // get the entities of this type in the MB
-    thisMB->get_entities_by_type(0, type, entities);
-
-      // go through each entity of this type in the MB
-      // and set its deletable tag to NO
-    MBRange::iterator iter, end_iter;
-    end_iter = entities.end();
-    for(iter = entities.begin(); iter != end_iter; ++iter)
-    {
-      unsigned char bit = 0x1;
-      result = thisMB->tag_set_data(mDeletableMBTag, &(*iter), 1, &bit);
-      assert(MB_SUCCESS == result);
-        // add adjacency information too
-      if (TYPE_FROM_HANDLE(*iter) != MBVERTEX)
-        add_adjacency(*iter);
-    }
-  }
-}
-
-void MBSkinner::deinitialize()
-{
-  MBErrorCode result = MB_SUCCESS;
-  
-  if (0 != mDeletableMBTag) {
-    result = thisMB->tag_delete( mDeletableMBTag);
-    mDeletableMBTag = 0;
-    assert(MB_SUCCESS == result);
-  }
-
-  // remove the adjaceny tag
-  std::vector< std::vector<MBEntityHandle>* > adj_arr;
-  std::vector< std::vector<MBEntityHandle>* >::iterator i;
-  if (0 != mAdjTag) {
-    for (MBEntityType t = MBVERTEX; t != MBMAXTYPE; ++t) {
-      MBRange entities;
-      result = thisMB->get_entities_by_type_and_tag( 0, t, &mAdjTag, 0, 1, entities );
-      assert(MB_SUCCESS == result);
-      adj_arr.resize( entities.size() );
-      result = thisMB->tag_get_data( mAdjTag, entities, &adj_arr[0] );
-      assert(MB_SUCCESS == result);
-      for (i = adj_arr.begin(); i != adj_arr.end(); ++i)
-        delete *i;
-    }
-  
-    result = thisMB->tag_delete(mAdjTag);
-    mAdjTag = 0;
-    assert(MB_SUCCESS == result);
-  }
-}
-
-
-void MBSkinner::add_adjacency(MBEntityHandle entity)
-{
-  std::vector<MBEntityHandle> *adj = NULL;
-  const MBEntityHandle *nodes;
-  int num_nodes;
-  MBErrorCode result = thisMB->get_connectivity(entity, nodes, num_nodes);
-  assert(MB_SUCCESS == result);
-  const MBEntityHandle *iter =
-    std::min_element(nodes, nodes+num_nodes);
-
-  if(iter == nodes+num_nodes)
-    return;
-
-  // add this entity to the node
-  if(thisMB->tag_get_data(mAdjTag, iter, 1, &adj) == MB_SUCCESS && adj != NULL)
-  {
-    adj->push_back(entity);    
-  }
-  // create a new vector and add it
-  else
-  {
-    adj = new std::vector<MBEntityHandle>;
-    adj->push_back(entity);
-    result = thisMB->tag_set_data(mAdjTag, iter, 1, &adj);
-    assert(MB_SUCCESS == result);
-  }
-}
-
-void MBSkinner::add_adjacency(MBEntityHandle entity, 
-                               const MBEntityHandle *nodes,
-                               const int num_nodes)
-{
-  std::vector<MBEntityHandle> *adj = NULL;
-  const MBEntityHandle *iter = 
-    std::min_element(nodes, nodes+num_nodes);
-
-  if(iter == nodes+num_nodes)
-    return;
-
-  // add this entity to the node
-  if(thisMB->tag_get_data(mAdjTag, iter, 1, &adj) == MB_SUCCESS && adj != NULL)
-  {
-    adj->push_back(entity);    
-  }
-  // create a new vector and add it
-  else
-  {
-    adj = new std::vector<MBEntityHandle>;
-    adj->push_back(entity);
-    thisMB->tag_set_data(mAdjTag, iter, 1, &adj);
-  }
-}
-
-MBErrorCode MBSkinner::find_geometric_skin(MBRange &forward_target_entities) 
-{
-    // attempts to find whole model skin, using geom topo sets first then
-    // normal find_skin function
-  bool debug = true;
-
-    // look for geom topo sets
-  MBTag geom_tag;
-  MBErrorCode result = thisMB->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
-                                            MB_TAG_SPARSE, geom_tag, NULL);
-
-  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
-    return result;
-  
-    // get face sets (dimension = 2)
-  MBRange face_sets;
-  int two = 2;
-  const void *two_ptr = &two;
-  result = thisMB->get_entities_by_type_and_tag(0, MBENTITYSET, &geom_tag, &two_ptr, 1,
-                                                 face_sets);
-
-  MBRange::iterator it;
-  if (MB_SUCCESS != result)
-    return result;
-  else if (face_sets.empty())
-    return MB_ENTITY_NOT_FOUND;
-
-    // ok, we have face sets; use those to determine skin
-  MBRange skin_sets;
-  if (debug) std::cout << "Found " << face_sets.size() << " face sets total..." << std::endl;
-  
-  for (it = face_sets.begin(); it != face_sets.end(); it++) {
-    int num_parents;
-    result = thisMB->num_parent_meshsets(*it, &num_parents);
-    if (MB_SUCCESS != result)
-      return result;
-    else if (num_parents == 1)
-      skin_sets.insert(*it);
-  }
-
-  if (debug) std::cout << "Found " << skin_sets.size() << " 1-parent face sets..." << std::endl;
-
-  if (skin_sets.empty())
-    return MB_FAILURE;
-      
-    // ok, we have the shell; gather up the elements, putting them all in forward for now
-  for (it = skin_sets.begin(); it != skin_sets.end(); it++) {
-    result = thisMB->get_entities_by_handle(*it, forward_target_entities, true);
-    if (MB_SUCCESS != result) 
-      return result;
-  }
-        
-  return result;
-}
-
-MBErrorCode MBSkinner::find_skin( const MBRange& source_entities,
-                                  bool get_vertices,
-                                  MBRange& output_handles,
-                                  MBRange* output_reverse_handles,
-                                  bool create_vert_elem_adjs,
-                                  bool create_skin_elements )
-{
-  if (source_entities.empty())
-    return MB_SUCCESS;
-
-  MBCore* this_core = dynamic_cast<MBCore*>(thisMB);
-  if (this_core && create_vert_elem_adjs && 
-      !this_core->a_entity_factory()->vert_elem_adjacencies())
-    this_core->a_entity_factory()->create_vert_elem_adjacencies();
-    
-  if (this_core && this_core->a_entity_factory()->vert_elem_adjacencies())
-    return find_skin_vertices( source_entities, 
-                               get_vertices ? &output_handles : 0,
-                               get_vertices ? 0 : &output_handles,
-                               output_reverse_handles,
-                               create_skin_elements );
-  
-  MBRange forward, reverse;
-  MBRange prev;
-  const int d = MBCN::Dimension(TYPE_FROM_HANDLE(source_entities.front()));
-  if (!source_entities.all_of_dimension(d))
-    return MB_TYPE_OUT_OF_RANGE;
-  
-  MBErrorCode rval = thisMB->get_entities_by_dimension( 0, d-1, prev );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = find_skin_noadj( source_entities, forward, reverse );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (get_vertices && !output_reverse_handles) {
-    forward.merge( reverse );
-    reverse.clear();
-  }
-  
-  if (get_vertices) {
-    rval = thisMB->get_connectivity( forward, output_handles );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  if (!create_skin_elements) {
-    MBRange new_skin;
-    rval = thisMB->get_entities_by_dimension( 0, d-1, new_skin);
-    if (MB_SUCCESS != rval)
-      return rval;
-    new_skin = subtract( new_skin, prev );
-    forward = subtract( forward, new_skin );
-    reverse = subtract( reverse, new_skin );
-    rval = thisMB->delete_entities( new_skin );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  if (!get_vertices) {
-    if (output_handles.empty())
-      output_handles.swap( forward );
-    else
-      output_handles.merge( forward );
-    if (!output_reverse_handles)
-      output_handles.merge( reverse );
-    else if (output_reverse_handles->empty())
-      output_reverse_handles->swap( reverse );
-    else
-      output_reverse_handles->merge( reverse );
-  }
-  
-  return MB_SUCCESS;  
-}
-
-MBErrorCode MBSkinner::find_skin_noadj(const MBRange &source_entities,
-                                 MBRange &forward_target_entities,
-                                 MBRange &reverse_target_entities/*,
-                                 bool create_vert_elem_adjs*/)
-{
-  if(source_entities.empty())
-    return MB_FAILURE;
-  
-  // get our working dimensions
-  MBEntityType type = thisMB->type_from_handle(*(source_entities.begin()));
-  const int source_dim = MBCN::Dimension(type);
-  mTargetDim = source_dim - 1;
-
-  // make sure we can handle the working dimensions
-  if(mTargetDim < 0 || source_dim > 3)
-    return MB_FAILURE;
-
-  //MBCore *this_core = dynamic_cast<MBCore*>(thisMB);
-  //bool use_adjs = false;
-  //if (!this_core->a_entity_factory()->vert_elem_adjacencies() &&
-  //  create_vert_elem_adjs)
-  //  this_core->a_entity_factory()->create_vert_elem_adjacencies();
-  //
-  //if (this_core->a_entity_factory()->vert_elem_adjacencies())
-  //  use_adjs = true;
-  //
-  //else 
-  initialize();
-
-  MBRange::const_iterator iter, end_iter;
-  end_iter = source_entities.end();
-  const MBEntityHandle *conn;
-  MBEntityHandle match;
-
-  direction direct;
-  MBErrorCode result;
-    // assume we'll never have more than 32 vertices on a facet (checked
-    // with assert later)
-  MBEntityHandle sub_conn[32];
-  std::vector<MBEntityHandle> tmp_conn_vec;
-  int num_nodes, num_sub_nodes, num_sides;
-  const short *sub_indices;
-  MBEntityType sub_type;
-
-  // for each source entity
-  for(iter = source_entities.begin(); iter != end_iter; ++iter)
-  {
-    // get the connectivity of this entity
-    result = thisMB->get_connectivity(*iter, conn, num_nodes, false, &tmp_conn_vec);
-    if (MB_SUCCESS != result)
-      return result;
-    
-    type = thisMB->type_from_handle(*iter);
-    MBRange::iterator seek_iter;
-    MBRange dum_elems, dum_sub_elems;
-    
-    // get connectivity of each n-1 dimension entity
-    num_sides = MBCN::NumSubEntities( type, mTargetDim );
-    for(int i=0; i<num_sides; i++)
-    {
-      sub_indices = MBCN::SubEntityVertexIndices( type, mTargetDim, i, sub_type, num_sub_nodes );
-      assert(num_sub_nodes <= 32);
-      for(int j=0; j<num_sub_nodes; j++)
-        sub_conn[j] = conn[sub_indices[j]];
-      
-//      if (use_adjs) {
-//        dum_elems.clear();
-//        result = thisMB->get_adjacencies(sub_conn, num_sub_nodes, source_dim, false,
-//                                         dum_elems);
-//        if (MB_SUCCESS != result) return result;
-//        dum_elems = intersect( dum_elems, source_entities );
-//        if (dum_elems.empty()) {
-//          assert(false);  // should never happen
-//          return MB_FAILURE;
-//        }
-//        // if (dum_elems.size() > 2) { 
-//          // source entities do not form a valid source-dim patch (t-junction).
-//          // do we care?
-//        // }
-//        
-//        if (1 == dum_elems.size()) {
-//            // this sub_element is on the skin
-//
-//            // check for existing entity
-//          dum_sub_elems.clear();
-//          result = thisMB->get_adjacencies(sub_conn, num_sub_nodes, mTargetDim, false,
-//                                           dum_sub_elems);
-//          if (MB_SUCCESS != result) return result;
-//          if (dum_sub_elems.empty()) {
-//              // need to create one
-//            MBEntityHandle tmphndl=0;
-//            int indices[MB_MAX_SUB_ENTITY_VERTICES];
-//            MBEntityType new_type;
-//            int num_new_nodes;
-//            MBCN::SubEntityNodeIndices( type, num_nodes, mTargetDim, i, new_type, num_new_nodes, indices );
-//            for(int j=0; j<num_new_nodes; j++)
-//              sub_conn[j] = conn[indices[j]];
-//        
-//            result = thisMB->create_element(new_type, sub_conn,  
-//                                            num_new_nodes, tmphndl);
-//            forward_target_entities.insert(tmphndl);
-//          }
-//          else {
-//              // else find the relative sense of this entity to the source_entity in this set
-//            int side_no, sense = 0, offset;
-//            if (source_entities.find(*dum_elems.begin()) == source_entities.end()) {
-//              result = thisMB->side_number(*dum_elems.rbegin(), *dum_sub_elems.begin(),
-//                                           side_no, sense, offset);
-//            }
-//            else {
-//              result = thisMB->side_number(*dum_elems.begin(), *dum_sub_elems.begin(),
-//                                           side_no, sense, offset);
-//            }
-//            if (-1 == sense) reverse_target_entities.insert(*dum_sub_elems.begin());
-//            else if (1 == sense) forward_target_entities.insert(*dum_sub_elems.begin());
-//            else return MB_FAILURE;
-//          }
-//        }
-//      }
-//      else {
-        
-          // see if we can match this connectivity with
-          // an existing entity
-        find_match( sub_type, sub_conn, num_sub_nodes, match, direct );
-        
-          // if there is no match, create a new entity
-        if(match == 0)
-        {
-          MBEntityHandle tmphndl=0;
-          int indices[MB_MAX_SUB_ENTITY_VERTICES];
-          MBEntityType new_type;
-          int num_new_nodes;
-          MBCN::SubEntityNodeIndices( type, num_nodes, mTargetDim, i, new_type, num_new_nodes, indices );
-          for(int j=0; j<num_new_nodes; j++)
-            sub_conn[j] = conn[indices[j]];
-          result = thisMB->create_element(new_type, sub_conn, num_new_nodes,
-                                          tmphndl);
-          assert(MB_SUCCESS == result);
-          add_adjacency(tmphndl, sub_conn, num_sub_nodes);
-          forward_target_entities.insert(tmphndl);
-        }
-          // if there is a match, delete the matching entity
-          // if we can. 
-        else
-        {
-          if ( (seek_iter = forward_target_entities.find(match)) != forward_target_entities.end())
-          {
-            forward_target_entities.erase(seek_iter);
-            remove_adjacency(match);
-            if(/*!use_adjs &&*/ entity_deletable(match))
-            {
-              result = thisMB->delete_entities(&match, 1);
-              assert(MB_SUCCESS == result);
-            }
-          }
-          else if ( (seek_iter = reverse_target_entities.find(match)) != reverse_target_entities.end())
-          {
-            reverse_target_entities.erase(seek_iter);
-            remove_adjacency(match);
-            if(/*!use_adjs &&*/ entity_deletable(match))
-            {
-              result = thisMB->delete_entities(&match, 1);
-              assert(MB_SUCCESS == result);
-            }
-          }
-          else
-          {
-            if(direct == FORWARD)
-            {
-              forward_target_entities.insert(match);
-            }
-            else
-            {
-              reverse_target_entities.insert(match);
-            }
-          }
-        }
-      //}
-    }
-  }
-
-  deinitialize();
-
-  return MB_SUCCESS;
-}
-
-
-void MBSkinner::find_match( MBEntityType type, 
-                             const MBEntityHandle *conn,
-                             const int num_nodes,
-                             MBEntityHandle& match,
-                             MBSkinner::direction &direct)
-{
-  match = 0;
-
-  if (type == MBVERTEX) {
-    match = *conn;
-    direct = FORWARD;
-    return;
-  }
-
-  const MBEntityHandle *iter = std::min_element(conn, conn+num_nodes);
-
-  std::vector<MBEntityHandle> *adj = NULL;
-
-  MBErrorCode result = thisMB->tag_get_data(mAdjTag, iter, 1, &adj);
-  if(result == MB_FAILURE || adj == NULL)
-  {
-    return;
-  }
-
-  std::vector<MBEntityHandle>::iterator jter, end_jter;
-  end_jter = adj->end();
-
-  const MBEntityHandle *tmp;
-  int num_verts;
-
-  for(jter = adj->begin(); jter != end_jter; ++jter)
-  {
-    MBEntityType tmp_type;
-    tmp_type = thisMB->type_from_handle(*jter);
-
-    if( type != tmp_type )
-      continue;
-
-    result = thisMB->get_connectivity(*jter, tmp, num_verts, true);
-    assert(MB_SUCCESS == result && num_verts >= num_nodes);
-    if(connectivity_match(conn, tmp, num_verts, direct))
-    {
-      match = *jter;
-      break;
-    }        
-  }
-}
-
-bool MBSkinner::connectivity_match( const MBEntityHandle *conn1,
-                                     const MBEntityHandle *conn2,
-                                     const int num_verts,
-                                     MBSkinner::direction &direct)
-{
-  const MBEntityHandle *iter =
-    std::find(conn2, conn2+num_verts, conn1[0]);
-  if(iter == conn2+num_verts)
-    return false;
-
-  bool they_match = true;
-
-  int i;
-  unsigned int j = iter - conn2;
-    
-  // first compare forward
-  for(i = 1; i<num_verts; ++i)
-  {
-    if(conn1[i] != conn2[(j+i)%num_verts])
-    {
-      they_match = false;
-      break;
-    }
-  }
-  
-  if(they_match == true)
-  {
-    // need to check for reversed edges here
-    direct = (num_verts == 2 && j) ? REVERSE : FORWARD;
-    return true;
-  }
-  
-  they_match = true;
-  
-  // then compare reverse
-  j += num_verts;
-  for(i = 1; i < num_verts; )
-  {
-    if(conn1[i] != conn2[(j-i)%num_verts])
-    {
-      they_match = false;
-      break;
-    }
-    ++i;
-  }
-  if (they_match)
-  {
-    direct = REVERSE;
-  }
-  return they_match;
-}
-
-  
-MBErrorCode MBSkinner::remove_adjacency(MBEntityHandle entity)
-{
-  std::vector<MBEntityHandle> nodes, *adj = NULL;
-  MBErrorCode result = thisMB->get_connectivity(&entity, 1, nodes);
-  if (MB_SUCCESS != result) return result;
-  std::vector<MBEntityHandle>::iterator iter = 
-    std::min_element(nodes.begin(), nodes.end());
-
-  if(iter == nodes.end())
-    return MB_FAILURE;
-
-  // remove this entity from the node
-  if(thisMB->tag_get_data(mAdjTag, &(*iter), 1, &adj) == MB_SUCCESS && adj != NULL)
-  {
-    iter = std::find(adj->begin(), adj->end(), entity);
-    if(iter != adj->end())
-      adj->erase(iter);
-  }
-
-  return result;
-}
-
-bool MBSkinner::entity_deletable(MBEntityHandle entity)
-{
-  unsigned char deletable=0;
-  MBErrorCode result = thisMB->tag_get_data(mDeletableMBTag, &entity, 1, &deletable);
-  assert(MB_SUCCESS == result);
-  if(MB_SUCCESS == result && deletable == 1)
-    return false;
-  return true;
-}
-
-MBErrorCode MBSkinner::classify_2d_boundary( const MBRange &boundary,
-                                               const MBRange &bar_elements,
-                                               MBEntityHandle boundary_edges,
-                                               MBEntityHandle inferred_edges,
-                                               MBEntityHandle non_manifold_edges,
-                                               MBEntityHandle other_edges,
-                                               int &number_boundary_nodes)
-{
-  MBRange bedges, iedges, nmedges, oedges;
-  MBErrorCode result = classify_2d_boundary(boundary, bar_elements,
-                                             bedges, iedges, nmedges, oedges,
-                                             number_boundary_nodes);
-  if (MB_SUCCESS != result) return result;
-  
-    // now set the input meshsets to the output ranges
-  result = thisMB->clear_meshset(&boundary_edges, 1);
-  if (MB_SUCCESS != result) return result;
-  result = thisMB->add_entities(boundary_edges, bedges);
-  if (MB_SUCCESS != result) return result;
-
-  result = thisMB->clear_meshset(&inferred_edges, 1);
-  if (MB_SUCCESS != result) return result;
-  result = thisMB->add_entities(inferred_edges, iedges);
-  if (MB_SUCCESS != result) return result;
-
-  result = thisMB->clear_meshset(&non_manifold_edges, 1);
-  if (MB_SUCCESS != result) return result;
-  result = thisMB->add_entities(non_manifold_edges, nmedges);
-  if (MB_SUCCESS != result) return result;
-
-  result = thisMB->clear_meshset(&other_edges, 1);
-  if (MB_SUCCESS != result) return result;
-  result = thisMB->add_entities(other_edges, oedges);
-  if (MB_SUCCESS != result) return result;
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBSkinner::classify_2d_boundary( const MBRange &boundary,
-                                               const MBRange &bar_elements,
-                                               MBRange &boundary_edges,
-                                               MBRange &inferred_edges,
-                                               MBRange &non_manifold_edges,
-                                               MBRange &other_edges,
-                                               int &number_boundary_nodes)
-{
-
-  // clear out the edge lists
-
-  boundary_edges.clear();
-  inferred_edges.clear();
-  non_manifold_edges.clear();
-  other_edges.clear();
-
-  number_boundary_nodes = 0;
-
-  // make sure we have something to work with
-  if(boundary.empty())
-  {
-    return MB_FAILURE;
-  }
-  
-  // get our working dimensions
-  MBEntityType type = thisMB->type_from_handle(*(boundary.begin()));
-  const int source_dim = MBCN::Dimension(type);
-
-  // make sure we can handle the working dimensions
-  if(source_dim != 2)
-  {
-    return MB_FAILURE;
-  }
-  mTargetDim = source_dim - 1;
-
-  // initialize
-  initialize();
-
-  // additional initialization for this routine
-  // define a tag for MBEDGE which counts the occurances of the edge below
-  // default should be 0 for existing edges, if any
-
-  MBTag count_tag;
-  int default_count = 0;
-  MBErrorCode result = thisMB->tag_create("mdbskinner count edges", sizeof(int),
-                                            MB_TAG_DENSE, count_tag, &default_count);
-  assert(MB_SUCCESS == result);
-
- 
-  MBRange::const_iterator iter, end_iter;
-  end_iter = boundary.end();
-
-  std::vector<MBEntityHandle> conn;
-  MBEntityHandle sub_conn[2];
-  MBEntityHandle match;
-
-  MBRange edge_list;
-  MBRange boundary_nodes;
-  MBSkinner::direction direct;
-  
-  MBEntityType sub_type;
-  int num_edge, num_sub_ent_vert;
-  const short* edge_verts;
-  
-  // now, process each entity in the boundary
-
-  for(iter = boundary.begin(); iter != end_iter; ++iter)
-  {
-    // get the connectivity of this entity
-    conn.clear();
-    result = thisMB->get_connectivity(&(*iter), 1, conn, false);
-    assert(MB_SUCCESS == result);
-
-    // add node handles to boundary_node range
-    std::copy(conn.begin(), conn.begin()+MBCN::VerticesPerEntity(type), 
-              mb_range_inserter(boundary_nodes));
-
-    type = thisMB->type_from_handle(*iter);
-    
-    // get connectivity of each n-1 dimension entity (edge in this case)
-    const struct MBCN::ConnMap* conn_map = &(MBCN::mConnectivityMap[type][0]);
-    num_edge = MBCN::NumSubEntities( type, 1 );
-    for(int i=0; i<num_edge; i++)
-    {
-      edge_verts = MBCN::SubEntityVertexIndices( type, 1, i, sub_type, num_sub_ent_vert );
-      assert( sub_type == MBEDGE && num_sub_ent_vert == 2 );
-      sub_conn[0] = conn[edge_verts[0]];
-      sub_conn[1] = conn[edge_verts[1]];
-      int num_sub_nodes = conn_map->num_corners_per_sub_element[i];
-      
-      // see if we can match this connectivity with
-      // an existing entity
-      find_match( MBEDGE, sub_conn, num_sub_nodes, match, direct );
-  
-      // if there is no match, create a new entity
-      if(match == 0)
-      {
-        MBEntityHandle tmphndl=0;
-        int indices[MB_MAX_SUB_ENTITY_VERTICES];
-        MBEntityType new_type;
-        int num_new_nodes;
-        MBCN::SubEntityNodeIndices( type, conn.size(), 1, i, new_type, num_new_nodes, indices );
-        for(int j=0; j<num_new_nodes; j++)
-          sub_conn[j] = conn[indices[j]];
-        
-        result = thisMB->create_element(new_type, sub_conn,  
-                                        num_new_nodes, tmphndl);
-        assert(MB_SUCCESS == result);
-        add_adjacency(tmphndl, sub_conn, num_sub_nodes);
-        //target_entities.insert(tmphndl);
-        edge_list.insert(tmphndl);
-        int count;
-        result = thisMB->tag_get_data(count_tag, &tmphndl, 1, &count);
-        assert(MB_SUCCESS == result);
-        count++;
-        result = thisMB->tag_set_data(count_tag, &tmphndl, 1, &count);
-        assert(MB_SUCCESS == result);
-
-      }
-      else
-      {
-        // We found a match, we must increment the count on the match
-        int count;
-        result = thisMB->tag_get_data(count_tag, &match, 1, &count);
-        assert(MB_SUCCESS == result);
-        count++;
-        result = thisMB->tag_set_data(count_tag, &match, 1, &count);
-        assert(MB_SUCCESS == result);
-
-        // if the entity is not deletable, it was pre-existing in
-        // the database.  We therefore may need to add it to the
-        // edge_list.  Since it will not hurt the range, we add
-        // whether it was added before or not
-        if(!entity_deletable(match))
-        {
-          edge_list.insert(match);
-        }
-      }
-    }
-  }
-
-  // Any bar elements in the model should be classified separately
-  // If the element is in the skin edge_list, then it should be put in
-  // the non-manifold edge list.  Edges not in the edge_list are stand-alone
-  // bars, and we make them simply boundary elements
-
-  if (!bar_elements.empty())
-  {
-    MBRange::iterator bar_iter;
-    for(iter = bar_elements.begin(); iter != bar_elements.end(); ++iter)
-    {
-      MBEntityHandle handle = *iter;
-      bar_iter = edge_list.find(handle);
-      if (bar_iter != edge_list.end())
-      {
-        // it is in the list, erase it and put in non-manifold list
-        edge_list.erase(bar_iter);
-        non_manifold_edges.insert(handle);
-      }
-      else
-      {
-        // not in the edge list, make it a boundary edge
-        boundary_edges.insert(handle);
-      }
-    }
-  }
-
-  // now all edges should be classified.  Go through the edge_list,
-  // and put all in the appropriate lists
-
-  MBRange::iterator edge_iter, edge_end_iter;
-  edge_end_iter = edge_list.end();
-  int count;
-  for(edge_iter = edge_list.begin(); edge_iter != edge_end_iter; edge_iter++)
-  {
-    // check the count_tag
-    result = thisMB->tag_get_data(count_tag, &(*edge_iter), 1, &count);
-    assert(MB_SUCCESS == result);
-    if (count == 1)
-    {
-      boundary_edges.insert(*edge_iter);
-   }
-    else if (count == 2)
-    {
-      other_edges.insert(*edge_iter);
-    }
-    else
-    {
-      non_manifold_edges.insert(*edge_iter);
-    }
-  }
-
-  // find the inferred edges from the other_edge_list
-
-  double min_angle_degrees = 20.0;
-  find_inferred_edges(const_cast<MBRange&> (boundary), other_edges, inferred_edges, min_angle_degrees);
-
-  // we now want to remove the inferred_edges from the other_edges
-
-  MBRange temp_range;
- 
-  std::set_difference(other_edges.begin(), other_edges.end(),
-                      inferred_edges.begin(), inferred_edges.end(),
-                      mb_range_inserter(temp_range),
-                      std::less<MBEntityHandle>() );
-
-  other_edges = temp_range;
-
-  // get rid of count tag and deinitialize
-
-  result = thisMB->tag_delete(count_tag);
-  assert(MB_SUCCESS == result);
-  deinitialize();
-
-  // set the node count
-  number_boundary_nodes = boundary_nodes.size();
-
-  return MB_SUCCESS;
-} 
-
-void MBSkinner::find_inferred_edges(MBRange &skin_boundary,
-                                     MBRange &candidate_edges,
-                                     MBRange &inferred_edges,
-                                     double reference_angle_degrees)
-{
-
-  // mark all the entities in the skin boundary
-  MBTag mark_tag;
-  MBErrorCode result = thisMB->tag_create("find inferred edges mark", 1, MB_TAG_BIT, mark_tag, NULL);
-  assert(MB_SUCCESS == result);
-  for(MBRange::iterator mark_iter = skin_boundary.begin();
-      mark_iter != skin_boundary.end(); ++mark_iter)
-  {
-    unsigned char bit = true;
-    result = thisMB->tag_set_data(mark_tag, &(*mark_iter), 1, &bit);
-    assert(MB_SUCCESS == result);
-  }
-
-  // find the cosine of the reference angle
-
-  double reference_cosine = cos(reference_angle_degrees*SKINNER_PI/180.0);
-  
-  // check all candidate edges for an angle greater than the minimum
-
-  MBRange::iterator iter, end_iter = candidate_edges.end();
-  std::vector<MBEntityHandle> adjacencies;
-  std::vector<MBEntityHandle>::iterator adj_iter;
-  MBEntityHandle face[2];
-
-  for(iter = candidate_edges.begin(); iter != end_iter; ++iter)
-  {
-
-    // get the 2D elements connected to this edge
-    adjacencies.clear();
-    result = thisMB->get_adjacencies(&(*iter), 1, 2, false, adjacencies);
-    if (MB_SUCCESS != result) 
-      continue;
-
-    // there should be exactly two, that is why the edge is classified as nonBoundary
-    // and manifold
-
-    int faces_found = 0;
-    for(adj_iter = adjacencies.begin(); adj_iter != adjacencies.end() && faces_found < 2; ++adj_iter)
-    {
-      // we need to find two of these which are in the skin
-      unsigned char is_marked = 0;
-      result = thisMB->tag_get_data(mark_tag, &(*adj_iter), 1, &is_marked);
-      assert(MB_SUCCESS == result);
-      if(is_marked)
-      {
-        face[faces_found] = *adj_iter;
-        faces_found++;
-      } 
-    }
-
-//    assert(faces_found == 2 || faces_found == 0);
-    if (2 != faces_found) 
-      continue;
-
-    // see if the two entities have a sufficient angle
-
-    if ( has_larger_angle(face[0], face[1], reference_cosine) )
-    {
-       inferred_edges.insert(*iter);
-    }
-  }
-  
-  result = thisMB->tag_delete(mark_tag);
-  assert(MB_SUCCESS == result);
-}
-
-bool MBSkinner::has_larger_angle(MBEntityHandle &entity1,
-                                 MBEntityHandle &entity2,
-                                 double reference_angle_cosine)
-{
-  // compare normals to get angle.  We assume that the surface quads
-  // which we test here will be approximately planar
-
-  double norm[2][3];
-  MBUtil::normal(thisMB, entity1, norm[0][0], norm[0][1], norm[0][2]);
-  MBUtil::normal(thisMB, entity2, norm[1][0], norm[1][1], norm[1][2]);
-
-  double cosine = norm[0][0] * norm[1][0] + norm[0][1] * norm[1][1] + norm[0][2] * norm[1][2];
-
-  if (cosine < reference_angle_cosine)
-  {
-    return true;
-  }
-
-
-  return false;
-}
-
-  // get skin entities of prescribed dimension
-MBErrorCode MBSkinner::find_skin(const MBRange &entities,
-                                 int dim,
-                                 MBRange &skin_entities,
-                                 bool create_vert_elem_adjs) 
-{
-  MBRange tmp_skin;
-  MBErrorCode result = find_skin(entities, (dim==0), tmp_skin, 0, 
-                                 create_vert_elem_adjs, true);
-  if (MB_SUCCESS != result || tmp_skin.empty()) return result;
-  
-  if (tmp_skin.all_of_dimension(dim)) {
-    if (skin_entities.empty())
-      skin_entities.swap(tmp_skin);
-    else
-      skin_entities.merge(tmp_skin);
-  }
-  else {
-    result = thisMB->get_adjacencies( tmp_skin, dim, true, skin_entities, 
-                                      MBInterface::UNION );
-  }
-  
-  return result;
-}
-
-MBErrorCode MBSkinner::find_skin_vertices( const MBRange& entities,
-                                           MBRange* skin_verts,
-                                           MBRange* skin_elems,
-                                           MBRange* skin_rev_elems,
-                                           bool create_skin_elems,
-                                           bool corners_only )
-{
-  MBErrorCode rval;
-  if (entities.empty())
-    return MB_SUCCESS;
-  
-  const int dim = MBCN::Dimension(TYPE_FROM_HANDLE(entities.front()));
-  if (dim < 1 || dim > 3 || !entities.all_of_dimension(dim))
-    return MB_TYPE_OUT_OF_RANGE;
-  
-    // are we skinning all entities
-  size_t count = entities.size();
-  int num_total;
-  rval = thisMB->get_number_entities_by_dimension( 0, dim, num_total );
-  if (MB_SUCCESS != rval)
-    return rval;
-  bool all = (count == (size_t)num_total);
-  
-    // Create a bit tag for fast intersection with input entities range. 
-    // If we're skinning all the entities in the mesh, we really don't
-    // need the tag.  To save memory, just create it with a default value
-    // of one and don't set it.  That way MOAB will return 1 for all 
-    // entities.
-  MBTag tag;
-  char bit = all ? 1 : 0;
-  rval = thisMB->tag_create( NULL, 1, MB_TAG_BIT, tag, &bit );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // tag all entities in input range
-  if (!all) {
-    std::vector<unsigned char> vect(count, 1);
-    rval = thisMB->tag_set_data( tag, entities, &vect[0] );
-    if (MB_SUCCESS != rval) {
-      thisMB->tag_delete(tag);
-      return rval;
-    }
-  }
-  
-  switch (dim) {
-    case 1:
-      if (skin_verts)
-        rval = find_skin_vertices_1D( tag, entities, *skin_verts );
-      else if (skin_elems)
-        rval = find_skin_vertices_1D( tag, entities, *skin_elems );
-      else
-        rval = MB_SUCCESS;
-      break;
-    case 2:
-      rval = find_skin_vertices_2D( tag, entities, skin_verts, 
-                                    skin_elems, skin_rev_elems, 
-                                    create_skin_elems, corners_only );
-      break;
-    case 3:
-      rval = find_skin_vertices_3D( tag, entities, skin_verts, 
-                                    skin_elems, skin_rev_elems, 
-                                    create_skin_elems, corners_only );
-      break;
-    default:
-      rval = MB_TYPE_OUT_OF_RANGE;
-      break;
-  }
-  
-  thisMB->tag_delete(tag);
-  return rval;
-}
-
-MBErrorCode MBSkinner::find_skin_vertices_1D( MBTag tag,
-                                              const MBRange& edges,
-                                              MBRange& skin_verts )
-{
-  // This rather simple algorithm is provided for completeness
-  // (not sure how often one really wants the 'skin' of a chain
-  // or tangle of edges.)
-  //
-  // A vertex is on the skin of the edges if it is contained in exactly
-  // one of the edges *in the input range*.  
-  //
-  // This function expects the caller to have tagged all edges in the
-  // input range with a value of one for the passed bit tag, and all
-  // other edges with a value of zero.  This allows us to do a faster
-  // intersection with the input range and the edges adjacent to a vertex.
-
-  MBErrorCode rval;
-  std::vector<MBEntityHandle>::iterator i;
-  MBRange::iterator hint = skin_verts.begin();
-  
-  // All input entities must be edges.
-  if (!edges.all_of_dimension(1))
-    return MB_TYPE_OUT_OF_RANGE;
-  
-    // get all the vertices
-  MBRange verts;
-  rval = thisMB->get_connectivity( edges, verts, true );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // Test how many edges each input vertex is adjacent to.
-  std::vector<char> tag_vals;
-  std::vector<MBEntityHandle> adj;
-  int count;
-  for (MBRange::const_iterator it = verts.begin(); it != verts.end(); ++it) {
-      // get edges adjacent to vertex
-    adj.clear();
-    rval = thisMB->get_adjacencies( &*it, 1, 1, false, adj );
-    if (MB_SUCCESS != rval) return rval;
-    if (adj.empty())
-      continue;
-
-      // Intersect adjacent edges with the input list of edges
-    tag_vals.resize( adj.size() );
-    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
-    if (MB_SUCCESS != rval) return rval;
-    count = std::count( tag_vals.begin(), tag_vals.end(), '\001' );
-    
-      // If adjacent to only one input edge, then vertex is on skin
-    if (count == 1) {
-      hint = skin_verts.insert( hint, *it );
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-// A Container for storing a list of element sides adjacent
-// to a vertex.  The template parameter is the number of 
-// corners for the side.
-template <unsigned CORNERS> 
-class AdjSides 
-{
-public:
-  
-  /**
-   * This struct is used to for a reduced representation of element
-   * "sides" adjacent to a give vertex.  As such, it 
-   * a) does not store the initial vertex that all sides are adjacent to
-   * b) orders the remaining vertices in a specific way for fast comparison.
-   * 
-   * For edge elements, only the opposite vertex is stored.
-   * For triangle elements, only the other two vertices are stored,
-   *   and they are stored with the smaller of those two handles first.
-   * For quad elements, only the other three vertices are stored.
-   *  They are stored such that the vertex opposite the implicit (not
-   *  stored) vertex is always in slot 1.  The other two vertices 
-   *  (in slots 0 and 2) are ordered such that the handle of the one in 
-   *  slot 0 is smaller than the handle in slot 2.
-   *
-   * For each side, the adj_elem field is used to store the element that
-   * it is a side of as long as the element is considered to be on the skin.
-   * The adj_elem field is cleared (set to zero) to indicate that this
-   * side is no longer considered to be on the skin (and is the side of
-   * more than one element.)
-   */
-  struct Side {
-    MBEntityHandle handles[CORNERS-1]; //!< side vertices, except for implicit one
-    MBEntityHandle adj_elem;           //!< element that this is a side of, or zero
-    bool skin() const { return 0 != adj_elem; }
-    
-    /** construct from connectivity of side
-     *\param array The connectivity of the element side.
-     *\param idx   The index of the implicit vertex (contained
-     *             in all sides in the list.)
-     *\param adj   The element that this is a side of.
-     */
-    Side( const MBEntityHandle* array, int idx,
-          MBEntityHandle adj, unsigned short  ) 
-      : adj_elem(adj) /*, elem_side(side)*/ 
-    {
-      switch (CORNERS) {
-        default:
-          assert(false);
-          break;
-        case 4: handles[2] = array[(idx+3)%CORNERS];
-        case 3: handles[1] = array[(idx+2)%CORNERS];
-        case 2: handles[0] = array[(idx+1)%CORNERS];
-      }
-      if (CORNERS == 3 && handles[1] > handles[0])
-        std::swap( handles[0], handles[1] );
-      if (CORNERS == 4 && handles[2] > handles[0])
-        std::swap( handles[0], handles[2] );
-    }
-    
-    /** construct from connectivity of parent element
-     *\param array The connectivity of the parent element
-     *\param idx   The index of the implicit vertex (contained
-     *             in all sides in the list.)  This is an index
-     *             into 'indices', not 'array'.
-     *\param adj   The element that this is a side of.
-     *\param indices  The indices into 'array' at which the vertices
-     *             representing the side occur.
-     */
-    Side( const MBEntityHandle* array,  int idx,
-          MBEntityHandle adj, unsigned short ,
-          const short* indices ) 
-      : adj_elem(adj) /*, elem_side(side)*/ 
-    {
-      switch (CORNERS) {
-        default:
-          assert(false);
-          break;
-        case 4: handles[2] = array[indices[(idx+3)%CORNERS]];
-        case 3: handles[1] = array[indices[(idx+2)%CORNERS]];
-        case 2: handles[0] = array[indices[(idx+1)%CORNERS]];
-      }
-      if (CORNERS == 3 && handles[1] > handles[0])
-        std::swap( handles[0], handles[1] );
-      if (CORNERS == 4 && handles[2] > handles[0])
-        std::swap( handles[0], handles[2] );
-    }
-   
-    // Compare two side instances.  Relies in the ordering of 
-    // vertex handles as described above.
-    bool operator==( const Side& other ) const 
-    {
-      switch (CORNERS) {
-        default:
-          assert(false);
-          return false;
-        case 4:
-          return handles[0] == other.handles[0] 
-              && handles[1] == other.handles[1]
-              && handles[2] == other.handles[2];
-        case 3:
-          return handles[0] == other.handles[0] 
-              && handles[1] == other.handles[1];
-        case 2:
-          return handles[0] == other.handles[0];
-      }
-    }
-  };
-
-private:
-
-  std::vector<Side> data; //!< List of sides
-  size_t skin_count;      //!< Cached count of sides that are skin
-  
-public:
-
-  typedef typename std::vector<Side>::iterator iterator;
-  typedef typename std::vector<Side>::const_iterator const_iterator;
-  const_iterator begin() const { return data.begin(); }
-  const_iterator end() const { return data.end(); }
-  
-  void clear() { data.clear(); skin_count = 0; }
-  bool empty() const { return data.empty(); }
-  
-  AdjSides() : skin_count(0) {}
-  
-  size_t num_skin() const { return skin_count; }
-  
-    /** \brief insert side, specifying side connectivity
-     *
-     * Either insert a new side, or if the side is already in the
-     * list, mark it as not on the skin.
-     *
-     *\param handles The connectivity of the element side.
-     *\param skip_idx The index of the implicit vertex (contained
-     *             in all sides in the list.)
-     *\param adj_elem The element that this is a side of.
-     *\param elem_side Which side of adj_elem are we storing
-     *             (MBCN side number.)
-     */
-  void insert( const MBEntityHandle* handles, int skip_idx,
-               MBEntityHandle adj_elem, unsigned short elem_side )
-  {
-    Side side( handles, skip_idx, adj_elem, elem_side );
-    iterator p = std::find( data.begin(), data.end(), side );
-    if (p == data.end()) {
-      data.push_back( side );
-      ++skin_count; // not in list yet, so skin side (so far)
-    }
-    else if (p->adj_elem) {
-      p->adj_elem = 0; // mark as not on skin
-      --skin_count; // decrement cached count of skin elements
-    }
-  }
-  
-    /** \brief insert side, specifying list of indices into parent element
-     * connectivity.
-     *
-     * Either insert a new side, or if the side is already in the
-     * list, mark it as not on the skin.
-     *
-     *\param handles The connectivity of the parent element
-     *\param skip_idx The index of the implicit vertex (contained
-     *             in all sides in the list.)  This is an index
-     *             into 'indices', not 'handles'.
-     *\param adj_elem The element that this is a side of (parent handle).
-     *\param indices  The indices into 'handles' at which the vertices
-     *             representing the side occur.
-     *\param elem_side Which side of adj_elem are we storing
-     *             (MBCN side number.)
-     */
-  void insert( const MBEntityHandle* handles,  int skip_idx,
-               MBEntityHandle adj_elem, unsigned short elem_side,
-               const short* indices )
-  {
-    Side side( handles, skip_idx, adj_elem, elem_side, indices );
-    iterator p = std::find( data.begin(), data.end(), side );
-    if (p == data.end()) {
-      data.push_back( side );
-      ++skin_count; // not in list yet, so skin side (so far)
-    }
-    else if (p->adj_elem) {
-      p->adj_elem = 0; // mark as not on skin
-      --skin_count; // decrement cached count of skin elements
-    }
-  }
-  
-  /**\brief Search list for a given side, and if found, mark as not skin.
-   *
-   *\param other   Connectivity of side
-   *\param skip_index Index in 'other' at which implicit vertex occurs.
-   *\param elem_out If return value is true, the element that the side is a
-   *                side of.  If return value is false, not set.
-   *\return true if found and marked not-skin, false if not found.
-   *
-   * Given the connectivity of some existing element, check if it occurs
-   * in the list.  If it does, clear the "is skin" state of the side so
-   * that we know that we don't need to later create the side element.
-   */
-  bool find_and_unmark( const MBEntityHandle* other, int skip_index, MBEntityHandle& elem_out ) 
-  {
-    Side s( other, skip_index, 0, 0 );
-    iterator p = std::find( data.begin(), data.end(), s );
-    if (p == data.end() || !p->adj_elem)
-      return false;
-    else {
-      elem_out = p->adj_elem;
-      p->adj_elem = 0; // clear "is skin" state for side
-      --skin_count;    // decrement cached count of skin sides
-      return true;
-    }
-  }
-};
-
-// Utiltiy function used by find_skin_vertices_2D and
-// find_skin_vertices_3D to create elements representing
-// the skin side of a higher-dimension element if one
-// does not already exist.  
-//
-// Some arguments may seem redundant, but they are used
-// to create the correct order of element when the input
-// element contains higher-order nodes.
-//
-// This function always creates elements that have a "forward"
-// orientation with respect to the parent element (have
-// nodes ordered the same as MBCN returns for the "side").
-//
-// elem - The higher-dimension element for which to create
-//        a lower-dim element representing the side.
-// side_type - The MBEntityType of the desired side.
-// side_conn - The connectivity of the new side.
-MBErrorCode MBSkinner::create_side( MBEntityHandle elem,
-                                    MBEntityType side_type,
-                                    const MBEntityHandle* side_conn,
-                                    MBEntityHandle& side_elem )
-{
-  const int max_side = 9;
-  const MBEntityHandle* conn;
-  int len, side_len, side, sense, offset, indices[max_side];
-  MBErrorCode rval;
-  MBEntityType type = TYPE_FROM_HANDLE(elem), tmp_type;
-  const int ncorner = MBCN::VerticesPerEntity( side_type );
-  const int d = MBCN::Dimension(side_type);
-  std::vector<MBEntityHandle> storage;
-  
-  // Get the connectivity of the parent element
-  rval = thisMB->get_connectivity( elem, conn, len, false, &storage );
-  if (MB_SUCCESS != rval) return rval;
- 
-  // Find which side we are creating and get indices of all nodes
-  // (including higher-order, if any.)
-  MBCN::SideNumber( type, conn, side_conn, ncorner, d, side, sense, offset );
-  MBCN::SubEntityNodeIndices( type, len, d, side, tmp_type, side_len, indices );
-  assert(side_len <= max_side);
-  assert(side_type == tmp_type);
-  
-  //NOTE: re-create conn array even when no higher-order nodes
-  //      because we want it to always be forward with respect
-  //      to the side ordering.
-  MBEntityHandle side_conn_full[max_side];
-  for (int i = 0; i < side_len; ++i)
-    side_conn_full[i] = conn[indices[i]];
-  
-  return thisMB->create_element( side_type, side_conn_full, side_len, side_elem );
-}
-
-// Test if an edge is reversed with respect MBCN's ordering
-// for the "side" of a face.
-bool MBSkinner::edge_reversed( MBEntityHandle face,
-                               const MBEntityHandle* edge_ends )
-{
-  const MBEntityHandle* conn;
-  int len, idx;
-  MBErrorCode rval = thisMB->get_connectivity( face, conn, len, true );
-  if (MB_SUCCESS != rval) {
-    assert(false);
-    return false;
-  }
-  idx = std::find( conn, conn+len, edge_ends[0] ) - conn;
-  if (idx == len) {
-    assert(false);
-    return false;
-  }
-  return (edge_ends[1] == conn[(idx+len-1)%len]);
-}
-
-// Test if a 2D element representing the side or face of a
-// volume element is reversed with respect to the MBCN node
-// ordering for the corresponding region element side.
-bool MBSkinner::face_reversed( MBEntityHandle region,
-                               const MBEntityHandle* face_corners,
-                               MBEntityType face_type )
-{
-  const MBEntityHandle* conn;
-  int len, side, sense, offset;
-  MBErrorCode rval = thisMB->get_connectivity( region, conn, len, true );
-  if (MB_SUCCESS != rval) {
-    assert(false);
-    return false;
-  }
-  short r = MBCN::SideNumber( TYPE_FROM_HANDLE(region), conn, face_corners, 
-                              MBCN::VerticesPerEntity(face_type),
-                              MBCN::Dimension(face_type),
-                              side, sense, offset );
-  assert(0 == r);
-  return (!r && sense == -1);
-}
-
-MBErrorCode MBSkinner::find_skin_vertices_2D( MBTag tag,
-                                              const MBRange& faces,
-                                              MBRange* skin_verts,
-                                              MBRange* skin_edges,
-                                              MBRange* reversed_edges,
-                                              bool create_edges,
-                                              bool corners_only )
-{
-  // This function iterates over all the vertices contained in the
-  // input face list.  For each such vertex, it then iterates over
-  // all of the sides of the face elements adjacent to the vertex.
-  // If an adjacent side is the side of only one of the input
-  // faces, then that side is on the skin.  
-  //
-  // This algorithm will visit each skin vertex exactly once.  It
-  // will visit each skin side once for each vertex in the side.
-  //
-  // This function expects the caller to have created the passed bit
-  // tag and set it to one only for the faces in the passed range.  This
-  // tag is used to do a fast intersection of the faces adjacent to a 
-  // vertex with the faces in the input range (discard any for which the
-  // tag is not set to one.)
-
-  MBErrorCode rval;
-  std::vector<MBEntityHandle>::iterator i, j;
-  MBRange::iterator hint;
-  if (skin_verts)
-    hint = skin_verts->begin();
-  std::vector<MBEntityHandle> storage;
-  const MBEntityHandle *conn;
-  int len;
-  bool find_edges = skin_edges || create_edges;
-  MBEntityHandle face;
-  
-  if (!faces.all_of_dimension(2))
-    return MB_TYPE_OUT_OF_RANGE;
-  
-    // get all the vertices
-  MBRange verts;
-  rval = thisMB->get_connectivity( faces, verts, true );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  std::vector<char> tag_vals;
-  std::vector<MBEntityHandle> adj;
-  AdjSides<2> adj_edges;
-  for (MBRange::const_iterator it = verts.begin(); it != verts.end(); ++it) {
-    bool higher_order = false;
-  
-      // get all adjacent faces
-    adj.clear();
-    rval = thisMB->get_adjacencies( &*it, 1, 2, false, adj );
-    if (MB_SUCCESS != rval) return rval;
-    if (adj.empty())
-      continue;
-
-      // remove those not in the input list (intersect with input list)
-    i = j = adj.begin();
-    tag_vals.resize( adj.size() );
-    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
-    if (MB_SUCCESS != rval) return rval;
-      // remove non-tagged entries
-    i = j = adj.begin();
-    for (; i != adj.end(); ++i) 
-      if (tag_vals[i - adj.begin()])
-        *(j++) = *i;
-    adj.erase( j, adj.end() );
-    
-      // For each adjacent face, check the edges adjacent to the current vertex
-    adj_edges.clear();    // other vertex for adjacent edges
-    for (i = adj.begin(); i != adj.end(); ++i) {
-      rval = thisMB->get_connectivity( *i, conn, len, false, &storage );
-      if (MB_SUCCESS != rval) return rval;
-      
-        // For a single face element adjacent to this vertex, there
-        // will be exactly two sides (edges) adjacent to the vertex.
-        // Find the other vertex for each of the two edges.
-        
-      MBEntityHandle prev, next; // vertices of two adjacent edge-sides
-      const int idx = std::find(conn, conn+len, *it) - conn;
-      assert(idx != len);
-
-      if (TYPE_FROM_HANDLE(*i) == MBTRI && len > 3) {
-        len = 3;
-        higher_order = true;
-        if (idx > 2) // skip higher-order nodes for now
-          continue;
-      }
-      else if (TYPE_FROM_HANDLE(*i) == MBQUAD && len > 4) {
-        len = 4;
-        higher_order = true;
-        if (idx > 3) // skip higher-order nodes for now
-          continue;
-      }
-
-      const int prev_idx = (idx + len - 1)%len;
-      prev = conn[prev_idx];
-      next = conn[(idx+1)%len];
-      
-        // Insert sides (edges) in our list of candidate skin sides
-      adj_edges.insert( &prev, 1, *i, prev_idx );
-      adj_edges.insert( &next, 1, *i, idx );
-    }
-    
-      // If vertex is not on skin, advance to next vertex.
-      // adj_edges handled checking for duplicates on insertion.
-      // If every candidate skin edge occurred more than once (was
-      // not in fact on the skin), then we're done with this vertex.
-    if (0 == adj_edges.num_skin())
-      continue;
-    
-      // If user requested MBRange of *vertices* on the skin...
-    if (skin_verts) {
-        // Put skin vertex in output list
-      hint = skin_verts->insert( hint, *it );
- 
-        // Add mid edge nodes to vertex list
-      if (!corners_only && higher_order) {
-        for (AdjSides<2>::const_iterator p = adj_edges.begin(); p != adj_edges.end(); ++p) {
-          if (p->skin()) {
-            face = p->adj_elem;
-            MBEntityType type = TYPE_FROM_HANDLE(face);
-
-            rval = thisMB->get_connectivity( face, conn, len, false );
-            if (MB_SUCCESS != rval) return rval;
-            if (!MBCN::HasMidEdgeNodes( type, len ))
-              continue;
-
-            MBEntityHandle ec[2] = { *it, p->handles[0] };
-            int side, sense, offset;
-            MBCN::SideNumber( type, conn, ec, 2, 1, side, sense, offset );
-            offset = MBCN::HONodeIndex( type, len, 1, side );
-            assert(offset >= 0 && offset < len);
-            skin_verts->insert( conn[offset] );
-          }
-        }
-      }
-    }
- 
-      // If user requested MBRange of *edges* on the skin...
-    if (find_edges) {
-        // Search list of existing adjacent edges for any that are on the skin
-      adj.clear();
-      rval = thisMB->get_adjacencies( &*it, 1, 1, false, adj );
-      if (MB_SUCCESS != rval) return rval;
-      for (i = adj.begin(); i != adj.end(); ++i) {
-        rval = thisMB->get_connectivity( *i, conn, len, true );
-        if (MB_SUCCESS != rval) return rval;
-
-          // bool equality expression within find_and_unmark call
-          // will be evaluate to the index of *it in the conn array. 
-          //
-          // Note that the order of the terms in the if statement is important.
-          // We want to unmark any existing skin edges even if we aren't 
-          // returning them.  Otherwise we'll end up creating duplicates 
-          // if create_edges is true and skin_edges is not.
-        if (adj_edges.find_and_unmark( conn, (conn[1] == *it), face ) && skin_edges) {
-          if (reversed_edges && edge_reversed( face, conn ))
-            reversed_edges->insert( *i );
-          else
-            skin_edges->insert( *i );
-        }
-      }
-    }
-    
-      // If the user requested that we create new edges for sides
-      // on the skin for which there is no existing edge, and there
-      // are still skin sides for which no corresponding edge was found...
-    if (create_edges && adj_edges.num_skin()) {
-        // Create any skin edges that don't exist
-      for (AdjSides<2>::const_iterator p = adj_edges.begin(); p != adj_edges.end(); ++p) {
-        if (p->skin()) {
-          MBEntityHandle edge, ec[] = { *it, p->handles[0] };
-          rval = create_side( p->adj_elem, MBEDGE, ec, edge );
-          if (MB_SUCCESS != rval) return rval;
-          if (skin_edges)
-            skin_edges->insert( edge );
-        }
-      }
-    }
-
-  } // end for each vertex
-  
-  return MB_SUCCESS;
-}
-  
-
-MBErrorCode MBSkinner::find_skin_vertices_3D( MBTag tag,
-                                              const MBRange& entities,
-                                              MBRange* skin_verts,
-                                              MBRange* skin_faces,
-                                              MBRange* reversed_faces,
-                                              bool create_faces,
-                                              bool corners_only )
-{
-  // This function iterates over all the vertices contained in the
-  // input vol elem list.  For each such vertex, it then iterates over
-  // all of the sides of the vol elements adjacent to the vertex.
-  // If an adjacent side is the side of only one of the input
-  // elements, then that side is on the skin.  
-  //
-  // This algorithm will visit each skin vertex exactly once.  It
-  // will visit each skin side once for each vertex in the side.
-  //
-  // This function expects the caller to have created the passed bit
-  // tag and set it to one only for the elements in the passed range.  This
-  // tag is used to do a fast intersection of the elements adjacent to a 
-  // vertex with the elements in the input range (discard any for which the
-  // tag is not set to one.)
-  //
-  // For each vertex, iterate over each adjacent element.  Construct
-  // lists of the sides of each adjacent element that contain the vertex.
-  //
-  // A list of three-vertex sides is kept for all triangular faces,
-  // included three-vertex faces of type MBPOLYGON.  Putting polygons
-  // in the same list ensures that we find polyhedron and non-polyhedron
-  // elements that are adjacent.
-  //
-  // A list of four-vertex sides is kept for all quadrilateral faces,
-  // including four-vertex faces of type MBPOLYGON.
-  //
-  // Sides with more than four vertices must have an explicit MBPOLYGON
-  // element representing them because MBPOLYHEDRON connectivity is a
-  // list of faces rather than vertices.  So the third list (vertices>=5),
-  // need contain only the handle of the face rather than the vertex handles.
-
-  MBErrorCode rval;
-  std::vector<MBEntityHandle>::iterator i, j;
-  MBRange::iterator hint;
-  if (skin_verts)
-    hint = skin_verts->begin();
-  std::vector<MBEntityHandle> storage, storage2; // temp storage for conn lists
-  const MBEntityHandle *conn, *conn2;
-  int len, len2;
-  bool find_faces = skin_faces || create_faces;
-  int clen, side, sense, offset, indices[9];
-  MBEntityType face_type;
-  MBEntityHandle elem;
-  
-  if (!entities.all_of_dimension(3))
-    return MB_TYPE_OUT_OF_RANGE;
-  
-  // get all the vertices
-  MBRange verts;
-  rval = thisMB->get_adjacencies( entities, 0, false, verts, MBInterface::UNION );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  AdjSides<4> adj_quads; // 4-node sides adjacent to a vertex
-  AdjSides<3> adj_tris;  // 3-node sides adjacent to a vertex
-  AdjSides<2> adj_poly;  // n-node sides (n>5) adjacent to vertex
-                         // (must have an explicit polygon, so store
-                         // polygon handle rather than vertices.)
-  std::vector<char> tag_vals;
-  std::vector<MBEntityHandle> adj;
-  for (MBRange::const_iterator it = verts.begin(); it != verts.end(); ++it) {
-    bool higher_order = false;
-  
-      // get all adjacent elements
-    adj.clear();
-    rval = thisMB->get_adjacencies( &*it, 1, 3, false, adj );
-    if (MB_SUCCESS != rval) return rval;
-    if (adj.empty())
-      continue;
-      
-      // remove those not tagged (intersect with input range)
-    i = j = adj.begin();
-    tag_vals.resize( adj.size() );
-    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
-    if (MB_SUCCESS != rval) return rval;
-    for (; i != adj.end(); ++i) 
-      if (tag_vals[i - adj.begin()])
-        *(j++) = *i;
-    adj.erase( j, adj.end() );
-      
-      // Build lists of sides of 3D element adjacent to the current vertex
-    adj_quads.clear(); // store three other vertices for each adjacent quad face
-    adj_tris.clear();  // store two other vertices for each adjacent tri face
-    adj_poly.clear();  // store handle of each adjacent polygonal face
-    int idx;
-    for (i = adj.begin(); i != adj.end(); ++i) {
-      const MBEntityType type = TYPE_FROM_HANDLE(*i);
-      
-        // Special case for POLYHEDRA
-      if (type == MBPOLYHEDRON) {
-        rval = thisMB->get_connectivity( *i, conn, len );
-        if (MB_SUCCESS != rval) return rval;
-        for (int k = 0; k < len; ++k) {
-          rval = thisMB->get_connectivity( conn[k], conn2, len2, true, &storage2 );
-          if (MB_SUCCESS != rval) return rval;
-          idx = std::find( conn2, conn2+len2, *it) - conn2;
-          if (idx == len2) // vertex not in this face
-            continue;
-          
-            // Treat 3- and 4-vertex faces specially, so that
-            // if the mesh contains both elements and polyhedra,
-            // we don't miss one type adjacent to the other.
-          switch (len2) {
-            case 3:
-              adj_tris.insert( conn2, idx, *i, k );
-              break;
-            case 4:
-              adj_quads.insert( conn2, idx, *i, k );
-              break;
-            default:
-              adj_poly.insert( conn+k, 1, *i, k );
-              break;
-            }
-        }
-      }
-      else {
-        rval = thisMB->get_connectivity( *i, conn, len, false, &storage );
-        if (MB_SUCCESS != rval) return rval;
-
-        idx = std::find(conn, conn+len, *it) - conn;
-        assert(idx != len);
-        
-        if (len > MBCN::VerticesPerEntity( type )) {
-          higher_order =true;
-            // skip higher-order nodes for now
-          if (idx >= MBCN::VerticesPerEntity( type )) 
-            continue;
-        }
-
-          // For each side of the element...
-        const int num_faces = MBCN::NumSubEntities( type, 2 );
-        for (int f = 0; f < num_faces; ++f) {
-          int num_vtx;
-          const short* face_indices = MBCN::SubEntityVertexIndices(type, 2, f, face_type, num_vtx );
-          const short face_idx = std::find(face_indices, face_indices+num_vtx, (short)idx) - face_indices;
-            // skip sides that do not contain vertex from outer loop
-          if (face_idx == num_vtx)
-            continue; // current vertex not in this face
-
-          assert(num_vtx <= 4); // polyhedra handled above
-          switch (face_type) {
-            case MBTRI:
-              adj_tris.insert( conn, face_idx, *i, f, face_indices );
-              break;
-            case MBQUAD:
-              adj_quads.insert( conn, face_idx, *i, f, face_indices );
-              break;
-            default:
-              return MB_TYPE_OUT_OF_RANGE;
-          }
-        }
-      }
-    } // end for (adj[3])
-    
-      // If vertex is not on skin, advance to next vertex
-    if (0 == (adj_tris.num_skin() + adj_quads.num_skin() + adj_poly.num_skin()))
-      continue;
-    
-      // If user requested that skin *vertices* be passed back...
-    if (skin_verts) {
-        // Put skin vertex in output list
-      hint = skin_verts->insert( hint, *it );
- 
-        // Add mid-edge and mid-face nodes to vertex list
-      if (!corners_only && higher_order) {
-        for (AdjSides<3>::const_iterator t = adj_tris.begin(); t != adj_tris.end(); ++t) {
-          if (t->skin()) {
-            elem = t->adj_elem;
-            MBEntityType type = TYPE_FROM_HANDLE(elem);
-
-            rval = thisMB->get_connectivity( elem, conn, len, false );
-            if (MB_SUCCESS != rval) return rval;
-            if (!MBCN::HasMidNodes( type, len ))
-              continue;
-
-            MBEntityHandle ec[3] = { *it, t->handles[0], t->handles[1] };
-            MBCN::SideNumber( type, conn, ec, 3, 2, side, sense, offset );
-            MBCN::SubEntityNodeIndices( type, len, 2, side, face_type, clen, indices );
-            assert(MBTRI == face_type);
-            for (int k = 3; k < clen; ++k)
-              skin_verts->insert( conn[indices[k]] );
-          }
-        }
-        for (AdjSides<4>::const_iterator q = adj_quads.begin(); q != adj_quads.end(); ++q) {
-          if (q->skin()) {
-            elem = q->adj_elem;
-            MBEntityType type = TYPE_FROM_HANDLE(elem);
-
-            rval = thisMB->get_connectivity( elem, conn, len, false );
-            if (MB_SUCCESS != rval) return rval;
-            if (!MBCN::HasMidNodes( type, len ))
-              continue;
-
-            MBEntityHandle ec[4] = { *it, q->handles[0], q->handles[1], q->handles[2] };
-            MBCN::SideNumber( type, conn, ec, 4, 2, side, sense, offset );
-            MBCN::SubEntityNodeIndices( type, len, 2, side, face_type, clen, indices );
-            assert(MBQUAD == face_type);
-            for (int k = 4; k < clen; ++k)
-              skin_verts->insert( conn[indices[k]] );
-          }
-        }
-      }
-    }
-
-      // If user requested that we pass back the list of 2D elements
-      // representing the skin of the mesh...
-    if (find_faces) {
-        // Search list of adjacent faces for any that are on the skin
-      adj.clear();
-      rval = thisMB->get_adjacencies( &*it, 1, 2, false, adj );
-      if (MB_SUCCESS != rval) return rval;
-
-      for (i = adj.begin(); i != adj.end(); ++i) {
-        rval = thisMB->get_connectivity( *i, conn, len, true );
-        if (MB_SUCCESS != rval) return rval;
-        const int idx = std::find( conn, conn+len, *it ) - conn;
-        assert(idx != len);
-          // Note that the order of the terms in the if statements below
-          // is important.  We want to unmark any existing skin faces even 
-          // if we aren't returning them.  Otherwise we'll end up creating 
-          // duplicates if create_faces is true.
-        if (3 == len) {
-          if (adj_tris.find_and_unmark( conn, idx, elem ) && skin_faces) {
-            if (reversed_faces && face_reversed( elem, conn, MBTRI ))
-              reversed_faces->insert( *i );
-            else
-              skin_faces->insert( *i );
-          }
-        }
-        else if (4 == len) {
-          if (adj_quads.find_and_unmark( conn, idx, elem ) && skin_faces) {
-            if (reversed_faces && face_reversed( elem, conn, MBQUAD ))
-              reversed_faces->insert( *i );
-            else
-              skin_faces->insert( *i );
-          }
-        }
-        else {
-          if (adj_poly.find_and_unmark( &*i, 1, elem ) && skin_faces)
-            skin_faces->insert( *i );
-        }
-      }
-    }
-
-      // If user does not want use to create new faces representing
-      // sides for which there is currently no explicit element, 
-      // skip the remaining code and advance the outer loop to the 
-      // next vertex.
-    if (!create_faces)
-      continue;
-
-      // Polyhedra always have explictly defined faces, so
-      // there is no way we could need to create such a face.
-    assert(0 == adj_poly.num_skin());
-    
-      // Create any skin tris that don't exist
-    if (adj_tris.num_skin()) {
-      for (AdjSides<3>::const_iterator t = adj_tris.begin(); t != adj_tris.end(); ++t) {
-        if (t->skin()) {
-          MBEntityHandle tri, c[3] = { *it, t->handles[0], t->handles[1] };
-          rval = create_side( t->adj_elem, MBTRI, c, tri );
-          if (MB_SUCCESS != rval) return rval;
-          if (skin_faces)
-            skin_faces->insert( tri );
-        }
-      }
-    }
-    
-      // Create any skin quads that don't exist
-    if (adj_quads.num_skin()) {
-      for (AdjSides<4>::const_iterator q = adj_quads.begin(); q != adj_quads.end(); ++q) {
-        if (q->skin()) {
-          MBEntityHandle quad, c[4] = { *it, q->handles[0], q->handles[1], q->handles[2] };
-          rval = create_side( q->adj_elem, MBQUAD, c, quad );
-          if (MB_SUCCESS != rval) return rval;
-          if (skin_faces)
-            skin_faces->insert( quad );
-        }
-      }
-    }
-  } // end for each vertex
-  
-  return MB_SUCCESS;
-}

Deleted: MOAB/trunk/src/MBSysUtil.cpp
===================================================================
--- MOAB/trunk/src/MBSysUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBSysUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,174 +0,0 @@
-#include "MBSysUtil.hpp"
-
-#include <fstream>
-#include <algorithm>
-#include <assert.h>
-
-#include "MBEntityHandle.h"
-
-namespace MBSysUtil
-{
-
-
-void setmem( void* mem, const void* value, unsigned value_size, size_t num_elem )
-{
-  if (!num_elem)
-    return;
-  
-  char* array = reinterpret_cast<char*>(mem);
-  memcpy( array, value, value_size );
-  size_t count;
-  for (count = 1; count*2 < num_elem; count *= 2)
-    memcpy( array + count * value_size, array, count * value_size );
-  memcpy( array + count * value_size, array, (num_elem - count) * value_size );
-}
-    
-
-long filesize( FILE* filp )
-{
-  long curr_pos = ftell( filp );
-  if (fseek( filp, 0, SEEK_END ))
-    return -1;
-  
-  long length = ftell( filp );
-  if (fseek( filp, curr_pos, SEEK_SET))
-  {
-    assert(0); 
-    return -2;
-  }
-  
-  return length;
-}
-
-
-long filesize( std::ifstream& str )
-{
-  std::istream::pos_type curr_pos = str.tellg();
-  if (!str.seekg( 0, std::ios_base::end ))
-    return -1;
-  
-  long length = static_cast<long>(str.tellg());
-  if (!str.seekg( curr_pos, std::ios_base::beg ))
-  {
-    assert(0);
-    return -2;
-  }
-  
-  return length;
-}
-
-
-void byteswap( void* data, unsigned value_size, size_t num_elem )
-{
-  char* mem = reinterpret_cast<char*>(data);
-  char* const end = mem + value_size * num_elem;
-  for ( ; mem < end; mem += value_size) {
-    unsigned i = 0, j = value_size - 1;
-    while (i < j)
-      std::swap( mem[i++], mem[j--] );
-  }
-}
-
-inline static uint16_t swap_bytes( uint16_t value )
-{
-  return (value >> 8) | (value << 8);
-}
-
-inline static uint32_t swap_bytes( uint32_t value )
-{
-  return ((value /*& (uint32_t)0xFF000000*/) >> 24) |
-         ((value   & (uint32_t)0x00FF0000  ) >>  8) |
-         ((value   & (uint32_t)0x0000FF00  ) <<  8) |
-         ((value /*& (uint32_t)0X000000FF*/) << 24);
-}
-
-const uint64_t m64b1 = 0xFF;
-const uint64_t m64b2 = m64b1 <<  8;
-const uint64_t m64b3 = m64b1 << 16;
-const uint64_t m64b4 = m64b1 << 24;
-const uint64_t m64b5 = m64b1 << 32;
-const uint64_t m64b6 = m64b1 << 40;
-const uint64_t m64b7 = m64b1 << 48;
-//const uint64_t m64b8 = m64b1 << 56;
-
-inline static uint64_t swap_bytes( uint64_t value )
-{
-  return ((value /*& m64b8*/) >> 56) |
-         ((value   & m64b7  ) >> 40) |
-         ((value   & m64b6  ) >> 24) |
-         ((value   & m64b5  ) >>  8) |
-         ((value   & m64b4  ) <<  8) |
-         ((value   & m64b3  ) << 24) |
-         ((value   & m64b2  ) << 40) |
-         ((value /*& m64b1*/) << 56);
-}
-/*
-inline static uint32_t swap_byte_pairs( uint32_t value )
-{
-  return ((value & (uint32_t)0xFF000000) >> 8) |
-         ((value & (uint32_t)0x00FF0000) << 8) |
-         ((value & (uint32_t)0x0000FF00) >> 8) |
-         ((value & (uint32_t)0X000000FF) << 8);
-}
-
-inline static uint64_t swap_byte_quads( uint64_t value )
-{
-  return ((value & m64b8) >> 24) |
-         ((value & m64b7) >>  8) |
-         ((value & m64b6) <<  8) |
-         ((value & m64b5) << 24) |
-         ((value & m64b4) >> 24) |
-         ((value & m64b3) >>  8) |
-         ((value & m64b2) <<  8) |
-         ((value & m64b1) << 24);
-}
-
-inline static uint64_t swap_byte_pairs( uint64_t value )
-{
-  return ((value & m64b8) >> 8) |
-         ((value & m64b7) << 8) |
-         ((value & m64b6) >> 8) |
-         ((value & m64b5) << 8) |
-         ((value & m64b4) >> 8) |
-         ((value & m64b3) << 8) |
-         ((value & m64b2) >> 8) |
-         ((value & m64b1) << 8);
-}
-*/
-void byteswap2( void* data, size_t num_elem )
-{
-  uint16_t* mem = reinterpret_cast<uint16_t*>(data);
-  uint16_t* end = mem + num_elem;
-  for (; mem < end; ++mem)
-    *mem = swap_bytes( *mem );
-}
-
-void byteswap4( void* data, size_t num_elem )
-{
-  uint32_t* mem = reinterpret_cast<uint32_t*>(data);
-  uint32_t* end = mem + num_elem;
-  for (; mem < end; ++mem)
-    *mem = swap_bytes( *mem );
-}
-
-void byteswap8( void* data, size_t num_elem )
-{
-  if (sizeof(void*) >= 8) {
-    uint64_t* mem = reinterpret_cast<uint64_t*>(data);
-    uint64_t* end = mem + num_elem;
-    for (; mem < end; ++mem)
-      *mem = swap_bytes( *mem );
-  }
-  else {
-    uint32_t* mem = reinterpret_cast<uint32_t*>(data);
-    uint32_t* end = mem + 2*num_elem;
-    for (; mem < end; mem += 2) {
-      uint32_t tmp = swap_bytes( mem[0] );
-      mem[0] = swap_bytes( mem[1] );
-      mem[1] = tmp;
-    }
-  }
-}
-
-} // namespace MBSysUtil
-

Deleted: MOAB/trunk/src/MBSysUtil.hpp
===================================================================
--- MOAB/trunk/src/MBSysUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBSysUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,106 +0,0 @@
-#ifndef MB_SYS_UTIL_HPP
-#define MB_SYS_UTIL_HPP
-
-#include <string.h> // for size_t
-#include <stdio.h>
-#include <iosfwd>
-
-namespace MBSysUtil
-{
-
-/**\brief Similar to memset, but accepts values larger than 1 char
- *
- * Set block of memory to repeating copies of a sequene of bytes.
- *\param mem   Pointer to start of memory block to initialize
- *\param value Byte sequence to initialize mem with
- *\param value_size Size of 'value'
- *\param num_elem Size of 'mem' as a multiple of value_size (the number of
- *             copies of 'value' to write into 'mem'.)
- */
-void setmem( void* mem, const void* value, unsigned value_size, size_t num_elem );
-
-/**\brief Get size of file (if it is a regular file)
- *
- * Get size of regular file.  
- *\return - file size if known
- *        - -1 if file size cannot be determined (e.g. a pipe) 
- *        - -2 if an unexpected failure occured (may indicate change
- *           in file position.)
- */
-long filesize( FILE* filp );
-
-/**\brief Get size of file (if it is a regular file)
- *
- * Get size of regular file.  
- *\return - file size if known
- *        - -1 if file size cannot be determined (e.g. a pipe) 
- *        - -2 if an unexpected failure occured (may indicate change
- *           in file position.)
- */
-long filesize( std::ifstream& str );
-
-/**\brief Check if platform is little-endian
- * 
- * Check if platform is little-endian (least significant
- * byte at highest memory address.)
- */
-inline bool little_endian()
-{
-  const unsigned one = 1;
-  return !*((char*)&one);
-}
-
-/**\brief Check if platform is big-endian
- * 
- * Check if platform is big-endian (least significant
- * byte at lowest memory address.)
- */
-inline bool big_endian()
-{
-  const unsigned one = 1;
-  return !(((char*)&one)[sizeof(unsigned)-1]);
-}
-
-/**\brief Swap byte order (e.g. change from big-endian to little-endian)
- *
- * Reverse byte order or array of values.
- *\param data        Pointer to beginning of memory block to modify
- *\param values_size Size of one value
- *\param num_elem    Number of values of size 'value_size' in 'data'
- */
-void byteswap( void* data, unsigned value_size, size_t num_elem );
-
-/**\brief Alternate byteswap optimized for 2-byte values */
-void byteswap2( void* data, size_t num_elem );
-/**\brief Alternate byteswap optimized for 4-byte values */
-void byteswap4( void* data, size_t num_elem );
-/**\brief Alternate byteswap optimized for 8-byte values */
-void byteswap8( void* data, size_t num_elem );
-
-/**\brief Type-specific byte swap */
-template <typename T> 
-inline void byteswap( T* data, size_t num_elem )
-{
-  switch (sizeof(T)) {
-    case 1:
-      break;
-    case 2:  
-      byteswap2( data, num_elem ); 
-      break;
-    case 4:  
-      byteswap4( data, num_elem ); 
-      break;
-    case 8: 
-      byteswap8( data, num_elem ); 
-      break;
-    default: 
-      byteswap( data, sizeof(T), num_elem ); 
-      break;
-  }
-}
-
-
-} // namespace MBSysUtil
-
-
-#endif

Deleted: MOAB/trunk/src/MBUtil.cpp
===================================================================
--- MOAB/trunk/src/MBUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,177 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-//-------------------------------------------------------------------------
-// Filename      : MBUtil.cpp
-//
-// Purpose       : This file contains utility functions that can be used
-//                 with MB
-//
-// Special Notes : This is a pure virtual class, to prevent instantiation.
-//                 All functions are static, called like this:
-//                 MBUtil::function_name();
-//
-// Creator       : Ray J. Meyers
-//
-// Date          : 09/01/02
-//
-// Owner         : Ray J. meyers
-//-------------------------------------------------------------------------
-
-#include "MBUtil.hpp"
-#include "MBInterface.hpp"
-#include <assert.h>
-#include <math.h>
-#include "MBCN.hpp"
-#include <algorithm>
-
-//! temporary normal function for MBEntities.  This should be moved to
-//! an appropriate MB algorithms file
-
-void MBUtil::normal(MBInterface* MB, MBEntityHandle handle, double& x, double& y, double& z)
-{
-
-   // get connectivity
-   const MBEntityHandle *connectivity;
-   int number_nodes = 0;
-   MB->get_connectivity(handle, connectivity, number_nodes, true);
-   assert(number_nodes >= 3);
-
-   // get_coordinates
-   double coords[3][3];
-   MB->get_coords(&(connectivity[0]), 1, coords[0]);
-   MB->get_coords(&(connectivity[1]), 1, coords[1]);
-   MB->get_coords(&(connectivity[2]), 1, coords[2]);
-
-   double vecs[2][3];
-   vecs[0][0] = coords[1][0] - coords[0][0];
-   vecs[0][1] = coords[1][1] - coords[0][1];
-   vecs[0][2] = coords[1][2] - coords[0][2];
-   vecs[1][0] = coords[2][0] - coords[0][0];
-   vecs[1][1] = coords[2][1] - coords[0][1];
-   vecs[1][2] = coords[2][2] - coords[0][2];
-
-   x = vecs[0][1] * vecs[1][2] - vecs[0][2] * vecs[1][1];
-   y = vecs[0][2] * vecs[1][0] - vecs[0][0] * vecs[1][2];
-   z = vecs[0][0] * vecs[1][1] - vecs[0][1] * vecs[1][0];
-
-   double mag = sqrt(x*x + y*y + z*z);
-   if(mag !=0)
-   {
-     x /= mag;
-     y /= mag;
-     z /= mag;
-   }
-}
-void MBUtil::centroid(MBInterface *MB, MBEntityHandle handle, MBCoord &coord)
-{
-   const MBEntityHandle *connectivity;
-   int number_nodes = 0;
-   MB->get_connectivity(handle, connectivity, number_nodes,true);
-   
-   coord.x=0.0;
-   coord.y=0.0;
-   coord.z=0.0;
-
-   for(int i = 0; i< number_nodes; i++)
-   {
-      double node_coords[3];
-      MB->get_coords(&(connectivity[i]), 1, node_coords);
-     
-      coord.x+=node_coords[0];
-      coord.y+=node_coords[1];
-      coord.z+=node_coords[2];
-   }
-   
-   coord.x/=(double)number_nodes;
-   coord.y/=(double)number_nodes;
-   coord.z/=(double)number_nodes;
-}
-
-/*//This function calculates the coordinates for the centers of each edges of the entity specified by handle. The coordinates are returned in the list coords_list
-void MBUtil::edge_centers(MBInterface *MB, MBEntityHandle handle, std::vector<MBCoord> &coords_list)
-{
-  MB canon_tool(MB);
-  MBEntityType type;
-  int i = 0;
-  int number_nodes = 0;
-  double coords[2][3];
-  const MBEntityHandle *connectivity;
-
-
-  MB->get_connectivity(handle, connectivity, number_nodes,true);
-  
-  MB->type_from_handle(handle,type);
-  
-  const struct MBCN::ConnMap* conn_map = &(canon_tool.mConnectivityMap[type][0]); //get edge sub_elements
-
-  coords_list.resize(conn_map->num_sub_elements);
-
-  for(i = 0; i<conn_map->num_sub_elements; i++)
-  {
-    
-    MB->get_coords(connectivity[conn_map->conn[i][0]], coords[0]);
-    MB->get_coords(connectivity[conn_map->conn[i][1]], coords[1]);
-
-    coords_list[i].x = (coords[0][0] + coords[1][0])/2.0;
-    coords_list[i].y = (coords[0][1] + coords[1][1])/2.0;
-    coords_list[i].z = (coords[0][2] + coords[1][2])/2.0;
-
-  }
-
-
-
-}
-*/  
-
-/*
-void MBUtil::face_centers(MBInterface *MB, MBEntityHandle handle, std::vector<MBCoord> &coords_list)
-{
-  MB canon_tool(MB);
-  MBEntityType type;
-  int i = 0;
-  int number_nodes = 0;
-  double node_coords[3];
-  const MBEntityHandle *connectivity;
-
-
-  MB->get_connectivity(handle, connectivity, number_nodes,true);
-  
-  MB->type_from_handle(handle,type);
-  
-  const struct MBCN::ConnMap* conn_map = &(canon_tool.mConnectivityMap[type][1]); //get face sub_elements
-
-  coords_list.resize(conn_map->num_sub_elements);
-
-  for(i = 0; i<conn_map->num_sub_elements;i++)
-  {
-    int number_nodes_per_element = conn_map->num_nodes_per_sub_element[i];
-
-    for(int j = 0; j<number_nodes_per_element; j++)
-    {
-      MB->get_coords(connectivity[conn_map->conn[i][j]], node_coords);
-     
-      coords_list[i].x+=node_coords[0];
-      coords_list[i].y+=node_coords[1];
-      coords_list[i].z+=node_coords[2];
-    }
-   
-    coords_list[i].x/=(double)number_nodes_per_element;
-    coords_list[i].y/=(double)number_nodes_per_element;
-    coords_list[i].z/=(double)number_nodes_per_element;
-  }
-
-}
-*/

Deleted: MOAB/trunk/src/MBWriteUtil.cpp
===================================================================
--- MOAB/trunk/src/MBWriteUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBWriteUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,793 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifdef WIN32
-#pragma warning(disable : 4786)
-#endif
-
-#include "MBWriteUtil.hpp"
-#include "MBCore.hpp"
-#include "MBError.hpp"
-#include "SequenceManager.hpp"
-#include "ElementSequence.hpp"
-#include "VertexSequence.hpp"
-#include "TagServer.hpp"
-#include "AEntityFactory.hpp"
-#include "MBTagConventions.hpp"
-#include "MBRangeSeqIntersectIter.hpp"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <assert.h>
-#include <iostream>
-
-#ifdef WIN32
-#  define stat _stat
-#else
-#  include <unistd.h>
-#endif
-
-
-MBWriteUtil::MBWriteUtil(MBCore* mdb, MBError* error_handler) 
-    : MBWriteUtilIface(), mMB(mdb), mError(error_handler)
-{
-}
-
-  //! Check if the specified file already exists.
-  //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
-  //! if file does exist, or MB_FAILURE for some other error condition.
-MBErrorCode MBWriteUtil::check_doesnt_exist( const char* file_name )
-{
-  struct stat s;
-  if (0 == stat( file_name, &s ))
-  {
-    report_error( "%s: file already exists.\n", file_name );
-    return MB_ALREADY_ALLOCATED;  
-  }
-  else if (errno == ENOENT)
-  {
-    return MB_SUCCESS;
-  }
-  else
-  {
-    return MB_FAILURE;
-  }
-}
-
-
-MBErrorCode MBWriteUtil::get_node_arrays(
-    const int num_arrays,
-    const int num_nodes, 
-    const MBRange& entities, 
-    MBTag node_id_tag,
-    const int start_node_id,
-    std::vector<double*>& arrays)
-{
-  // check the data coming into the function
-  // dimension should be proper
-  if(num_arrays < 1 || num_arrays > 3)
-    return MB_FAILURE;
-
-  // there should be some entities
-  //if(entities.empty())
-  //  return MB_FAILURE;
-  // The above necessitates annoying special cases for files 
-  // w/out vertices (e.g. a kD-tree).  Return NULL array
-  // pointers instead. - kraftcheck, 3-14-08
-  if (entities.empty()) {
-    arrays.clear();
-    arrays.resize( num_arrays, NULL );
-    return MB_SUCCESS;
-  }
-
-  // memory should already be allocated for us
-  int tmp_num_arrays = 0;
-  for (unsigned int i = 0; i < 3; i++)
-    if (i+1 <= arrays.size() && NULL != arrays[i]) tmp_num_arrays++;
-  if (0 == tmp_num_arrays)
-    return MB_FAILURE;
-
-  // get coordinate data
-  MBErrorCode result = mMB->get_coords( entities, 
-                   num_arrays < 1 || arrays.size() < 1 ? NULL : arrays[0],
-                   num_arrays < 2 || arrays.size() < 2 ? NULL : arrays[1],
-                   num_arrays < 3 || arrays.size() < 3 ? NULL : arrays[2] );
-                   
-
-  if (0 == node_id_tag || MB_SUCCESS != result) 
-    return result;
-  
-    // now assign tags
-  std::vector<int> ids(num_nodes);
-  int node_id = start_node_id;
-  for (int i = 0; i < num_nodes; i++) ids[i] = node_id++;
-  result = mMB->tag_set_data(node_id_tag, entities, &ids[0]);
-
-  return result;
-}
-
-MBErrorCode MBWriteUtil::get_node_array(
-    const int which_array, /* 0->X, 1->Y, 2->Z */
-    MBRange::const_iterator iter,
-    const MBRange::const_iterator end,
-    const size_t output_array_len,
-    double* const output_array)
-{
-  // check the data coming into the function
-  // dimension should be proper
-  if(which_array < 0 || which_array > 2)
-    return MB_FAILURE;
-
-  // there should be some entities
-  if(iter == end)
-    return MB_FAILURE;
-
-  // memory should already be allocated for us
-  if (NULL == output_array || 0 == output_array_len)
-    return MB_FAILURE;
-
-  // Sequence iterators
-  TypeSequenceManager::iterator seq_iter, seq_end;
-  seq_iter = mMB->sequence_manager()->entity_map(MBVERTEX).begin();
-  seq_end = mMB->sequence_manager()->entity_map(MBVERTEX).end();
-  
-  // loop over range, getting coordinate value
-  double* output_iter = output_array;
-  double* const output_end = output_array + output_array_len;
-  while (iter != end)
-  {
-      // Find the sqeuence containing the current handle
-    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
-      ++seq_iter;
-    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
-      return MB_FAILURE;
-    
-      // Determine how much of the sequence we want.
-    MBRange::pair_iterator pair(iter);
-    MBRange::const_iterator prev(end);
-    --prev;
-    MBEntityHandle range_end = pair->second;
-    MBEntityHandle sequence_end = (*seq_iter)->end_handle();
-    MBEntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
-    if (end_handle > *prev)
-      end_handle = *prev;
-    MBEntityHandle count = end_handle - *iter + 1;
-    
-      // Get offset in sequence to start at
-    assert( *iter >= (*seq_iter)->start_handle() );
-    MBEntityHandle offset = *iter - (*seq_iter)->start_handle();
-    
-      // Get coordinate arrays from sequence
-    double* coord_array[3];
-    static_cast<VertexSequence*>(*seq_iter)
-      ->get_coordinate_arrays( coord_array[0], coord_array[1], coord_array[2]);
-    
-      // Copy data to ouput buffer
-    if (output_iter + count > output_end)
-      return MB_FAILURE;
-    memcpy( output_iter, coord_array[which_array] + offset, count * sizeof(double) );
-    
-      // Iterate
-    output_iter += count;
-    iter += count;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBWriteUtil::get_element_array(
-    const int num_elements, 
-    const int verts_per_element,
-    MBTag node_id_tag,
-    const MBRange& elements, 
-    MBTag element_id_tag,
-    int start_element_id,
-    int* element_array)
-{
-
-  // check the data we got
-  if(num_elements < 1)
-    return MB_FAILURE;
-  if(verts_per_element < 1)
-    return MB_FAILURE;
-  if(elements.empty())
-    return MB_FAILURE;
-  if(!element_array)
-    return MB_FAILURE;
-
-  TagServer* tag_server = mMB->tag_server();
-
-  MBRange::const_iterator range_iter = elements.begin();
-  MBRange::const_iterator range_iter_end = elements.end();
-
-  TypeSequenceManager::iterator seq_iter, seq_iter_end;
-  MBEntityType current_type = TYPE_FROM_HANDLE(*range_iter);
- 
-  seq_iter = mMB->sequence_manager()->entity_map(current_type).begin();
-  seq_iter_end = mMB->sequence_manager()->entity_map(current_type).end();
-
-  // lets find the entity sequence which holds the first entity
-  TypeSequenceManager::iterator seq_iter_lookahead = seq_iter;
-  seq_iter_lookahead++;
-  for( ; seq_iter_lookahead != seq_iter_end && 
-      (*seq_iter_lookahead)->start_handle() < *range_iter; )
-  {
-    ++seq_iter;
-    ++seq_iter_lookahead;
-  }
-
-  // a look ahead iterator
-  MBRange::const_iterator range_iter_lookahead = range_iter;
-
-  // our main loop
-  for(; range_iter != range_iter_end && seq_iter != seq_iter_end; /* ++ is handled in loop*/ )
-  {
-    // find a range that fits in the current entity sequence
-    for(; range_iter_lookahead != range_iter_end && 
-        *range_iter_lookahead <= (*seq_iter)->end_handle(); 
-        ++range_iter_lookahead)
-    {}
-  
-    if(current_type != TYPE_FROM_HANDLE(*range_iter))
-    {
-      current_type = TYPE_FROM_HANDLE(*range_iter);
-      seq_iter = mMB->sequence_manager()->entity_map(current_type).begin();
-      seq_iter_end = mMB->sequence_manager()->entity_map(current_type).end();
-
-      // lets find the entity sequence which holds the first entity of this type
-      TypeSequenceManager::const_iterator seq_iter_lookahead = seq_iter;
-      seq_iter_lookahead++;
-      for( ; seq_iter_lookahead != seq_iter_end && 
-          (*seq_iter_lookahead)->start_handle() < *range_iter; )
-      {
-        ++seq_iter;
-        ++seq_iter_lookahead;
-      }
-    }
-
-    int i = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
-
-    // get the connectivity array
-    MBEntityHandle* conn_array = 
-      static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
- 
-    MBEntityHandle start_handle = (*seq_iter)->start_handle();
-
-    for(MBRange::const_iterator tmp_iter = range_iter; 
-        tmp_iter != range_iter_lookahead;
-        ++tmp_iter)
-    {
-      // set the element id tag
-      tag_server->set_data(element_id_tag, *tmp_iter, &start_element_id);
-      ++start_element_id;
-
-      // for each node
-      for(int j=0; j<i; j++)
-      {
-        MBEntityHandle node = *(conn_array + j + i*(*tmp_iter - start_handle));
-        tag_server->get_data(node_id_tag, node, element_array);
-        element_array++;
-      }
-    }
-
-    // go to the next entity sequence
-    ++seq_iter;
-    // start with the next entities
-    range_iter = range_iter_lookahead;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBWriteUtil::get_element_array(
-    MBRange::const_iterator iter,
-    const MBRange::const_iterator end,
-    const int vertices_per_elem,
-    MBTag node_id_tag,
-    const size_t elem_array_size, 
-    int *const element_array)
-{
-
-  // check the data we got
-  if(iter == end)
-    return MB_FAILURE;
-  if(vertices_per_elem < 1)
-    return MB_FAILURE;
-  if(!element_array || elem_array_size < (unsigned)vertices_per_elem)
-    return MB_FAILURE;
-
-  TagServer* tag_server = mMB->tag_server();
-
-
-  // Sequence iterators
-  TypeSequenceManager::const_iterator seq_iter, seq_end;
-  
-  // loop over range, getting coordinate value
-  MBEntityType current_type = MBMAXTYPE;
-  int* output_iter = element_array;
-  int*const output_end = element_array + elem_array_size;
-  while (iter != end)
-  {
-      // Make sure we have the right sequence list (and get the sequence 
-      // list for the first iteration.)
-    MBEntityType type = TYPE_FROM_HANDLE(*iter);
-    if (type != current_type)
-    {
-      if (type >= MBENTITYSET || type < MBEDGE)
-        return MB_FAILURE;
-      seq_iter = mMB->sequence_manager()->entity_map(type).begin();
-      seq_end  = mMB->sequence_manager()->entity_map(type).end();
-      current_type = type;
-    }
-    
-      // Find the sqeuence containing the current handle
-    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
-      ++seq_iter;
-    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
-      return MB_FAILURE;
- 
-      // get the connectivity array
-    MBEntityHandle* conn_array = NULL;
-    int conn_size = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
-    conn_array = static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
-   
-      // Determine how much of the sequence we want.
-    MBRange::pair_iterator pair(iter);
-    MBRange::const_iterator prev(end);
-    --prev;
-    MBEntityHandle range_end = pair->second;
-    MBEntityHandle sequence_end = (*seq_iter)->end_handle();
-    MBEntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
-    if (end_handle > *prev)
-      end_handle = *prev;
-    MBEntityHandle count = end_handle - *iter + 1;
-    
-      // Get offset in sequence to start at
-    assert( *iter >= (*seq_iter)->start_handle() );
-    MBEntityHandle offset = *iter - (*seq_iter)->start_handle();
-
-      // Make sure sufficient space in output array
-    if (output_iter + (count * conn_size) > output_end)
-      return MB_FAILURE;
-
-      // If the nodes per element match, do in one call
-    conn_array += (conn_size * offset);
-    if (vertices_per_elem == conn_size)
-    {
-      MBErrorCode rval = tag_server->get_data( node_id_tag, 
-                                               conn_array,
-                                               count * conn_size,
-                                               output_iter );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      output_iter += count * conn_size;
-    }
-      // Otherwise need to do one at a time
-    else
-    {
-      int min = vertices_per_elem > conn_size ? conn_size : vertices_per_elem;
-      for (MBEntityHandle i = 0; i < count; ++i)
-      {
-        MBErrorCode rval = tag_server->get_data( node_id_tag,
-                                                 conn_array,
-                                                 min,
-                                                 output_iter );
-        if (MB_SUCCESS != rval)
-          return rval;
-
-        output_iter += min;
-        conn_array += conn_size;
-
-        if (vertices_per_elem > conn_size) // need to pad
-        {
-          memset( output_iter, 0, sizeof(int) * (vertices_per_elem - conn_size) );
-          output_iter += (vertices_per_elem - conn_size);
-        }
-      }
-    }
-
-    iter += count;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBWriteUtil::get_element_array(
-                                       MBRange::const_iterator iter,
-                                       const MBRange::const_iterator end,
-                                       const int vertices_per_elem,
-                                       const size_t elem_array_size, 
-                                       MBEntityHandle *const element_array )
-{
-  // check the data we got
-  if(iter == end)
-    return MB_FAILURE;
-  if(vertices_per_elem < 1)
-    return MB_FAILURE;
-  if(!element_array || elem_array_size < (unsigned)vertices_per_elem)
-    return MB_FAILURE;
-
-  // Sequence iterators
-  TypeSequenceManager::const_iterator seq_iter, seq_end;
-  
-  // loop over range, getting coordinate value
-  MBEntityType current_type = MBMAXTYPE;
-  MBEntityHandle* output_iter = element_array;
-  MBEntityHandle*const output_end = element_array + elem_array_size;
-  while (iter != end)
-  {
-      // Make sure we have the right sequence list (and get the sequence 
-      // list for the first iteration.)
-    MBEntityType type = TYPE_FROM_HANDLE(*iter);
-    if (type != current_type)
-    {
-      if (type >= MBENTITYSET || type < MBEDGE)
-        return MB_FAILURE;
-      seq_iter = mMB->sequence_manager()->entity_map(type).begin();
-      seq_end  = mMB->sequence_manager()->entity_map(type).end();
-      current_type = type;
-    }
-    
-      // Find the sqeuence containing the current handle
-    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
-      ++seq_iter;
-    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
-      return MB_FAILURE;
- 
-      // get the connectivity array
-    MBEntityHandle* conn_array = NULL;
-    int conn_size = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
-    if (conn_size != vertices_per_elem)
-      return MB_FAILURE;
-    conn_array = static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
-   
-      // Determine how much of the sequence we want.
-    MBRange::pair_iterator pair(iter);
-    MBRange::const_iterator prev(end);
-    --prev;
-    MBEntityHandle range_end = pair->second;
-    MBEntityHandle sequence_end = (*seq_iter)->end_handle();
-    MBEntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
-    if (end_handle > *prev)
-      end_handle = *prev;
-    MBEntityHandle count = end_handle - *iter + 1;
-    
-      // Get offset in sequence to start at
-    assert( *iter >= (*seq_iter)->start_handle() );
-    MBEntityHandle offset = *iter - (*seq_iter)->start_handle();
-
-      // Make sure sufficient space in output array
-    if (output_iter + (count * conn_size) > output_end)
-      return MB_FAILURE;
-
-      // Copy connectivity into output array
-    conn_array += (conn_size * offset);
-    memcpy( output_iter, conn_array, count * conn_size * sizeof(MBEntityHandle));
-    output_iter += count * conn_size;
-    iter += count;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBWriteUtil::get_poly_array_size(
-      MBRange::const_iterator ,
-      const MBRange::const_iterator ,
-      int&  )
-{
-  return MB_NOT_IMPLEMENTED;
-}
-
-MBErrorCode MBWriteUtil::get_poly_arrays(
-      MBRange::const_iterator& ,
-      const MBRange::const_iterator ,
-      const MBTag ,
-      size_t& ,
-      int *const ,
-      size_t& ,
-      int*const ,
-      int&  )
-{
-  return MB_NOT_IMPLEMENTED;
-}
-
-      
-MBErrorCode MBWriteUtil::gather_nodes_from_elements(
-      const MBRange& elements,
-      const MBTag node_bit_mark_tag,
-      MBRange& nodes
-      )
-{
-  bool printed_warning = false;
-
-  if(elements.empty())
-    return MB_SUCCESS;
-
-  if (TYPE_FROM_HANDLE(elements.front()) <= MBVERTEX ||
-      TYPE_FROM_HANDLE(elements.back()) >= MBENTITYSET)
-    return MB_TYPE_OUT_OF_RANGE;
-
-  TagServer* tag_server = mMB->tag_server();
-
-  // see if we need to use our own marking tag
-  MBTag exporting_nodes_tag = 0;
-  if(node_bit_mark_tag)
-    exporting_nodes_tag = node_bit_mark_tag;
-  else
-  {
-    mMB->tag_create("__MBWriteUtil::exporting_nodes", 1, MB_TAG_BIT, 
-                     exporting_nodes_tag, NULL);
-  }
-
-  // the x,y,z tag handles we need
-  MBEntityHandle lower_bound = ~0, upper_bound = 0;
-  
-  std::vector<MBEntityHandle> tmp_conn;
-  
-  MBRangeSeqIntersectIter iter( mMB->sequence_manager() );
-  for (MBErrorCode rval = iter.init( elements.begin(), elements.end() ); 
-       MB_FAILURE != rval; rval = iter.step()) {
-    if (MB_ENTITY_NOT_FOUND == rval) {
-      if (!printed_warning) {
-        std::cerr << "Warning: ignoring invalid element handle(s) in gather_nodes_from_elements" << std::endl;
-        printed_warning = true;
-      }
-      continue;
-    }
-    
-    ElementSequence* seq = static_cast<ElementSequence*>(iter.get_sequence());
-
-    // get the connectivity array
-    const MBEntityHandle* conn_array = seq->get_connectivity_array();
-    
-    // if unstructed mesh
-    if (conn_array) {
-      assert(iter.get_start_handle() >= seq->start_handle());
-      assert(iter.get_end_handle() <= seq->end_handle());
-      const MBEntityHandle offset = iter.get_start_handle() - seq->start_handle();
-      const MBEntityHandle num_elem = iter.get_end_handle() - iter.get_start_handle() + 1;
-      
-      conn_array += offset * seq->nodes_per_element();
-      const MBEntityHandle num_node = num_elem * seq->nodes_per_element();
- 
-        // for each node
-      for (MBEntityHandle j = 0; j < num_node; j++)
-      {
-        MBEntityHandle node = conn_array[j];
-        if(node < lower_bound)
-          lower_bound = node;
-        if(node > upper_bound)
-          upper_bound = node;
-        unsigned char bit = 0x1;
-        rval = tag_server->set_data(exporting_nodes_tag, &node, 1, &bit);
-        assert(MB_SUCCESS == rval);
-        if (MB_SUCCESS != rval)
-          return rval;
-      }
-    }
-      // structured mesh
-    else {
-      for (MBEntityHandle h = iter.get_start_handle();
-           h < iter.get_end_handle(); ++h) {
-        tmp_conn.clear();
-        rval = seq->get_connectivity( h, tmp_conn, false );
-        if (MB_SUCCESS != rval) {
-          if(node_bit_mark_tag == 0)
-            mMB->tag_delete(exporting_nodes_tag);
-          return rval;
-        }
-
-          // for each node
-        for(size_t j=0; j<tmp_conn.size(); j++)
-        {
-          MBEntityHandle node = tmp_conn[j];
-          if(node < lower_bound)
-            lower_bound = node;
-          if(node > upper_bound)
-            upper_bound = node;
-          unsigned char bit = 0x1;
-          tag_server->set_data(exporting_nodes_tag, &node, 1, &bit);
-        }
-      }
-    }
-  }
-
-  // we can get a REALLY long loop if lower_bound is zero
-  assert(lower_bound != 0);
-  // gather up all the nodes
-  for(; upper_bound >= lower_bound; --upper_bound)
-  {
-    unsigned char node_marked=0;
-    tag_server->get_data(exporting_nodes_tag, &upper_bound, 1, &node_marked);
-    if(node_marked == 0x1)
-      nodes.insert(upper_bound);
-  }
-
-  // clean up our own marking tag
-  if(node_bit_mark_tag == 0)
-    mMB->tag_delete(exporting_nodes_tag);
-  
-  return MB_SUCCESS;
-}
-
-  //! assign ids to input elements starting with start_id, written to id_tag
-  //! if zero, assigns to GLOBAL_ID_TAG_NAME
-MBErrorCode MBWriteUtil::assign_ids(MBRange &elements,
-                                    MBTag id_tag,
-                                    const int start_id) 
-{
-  MBErrorCode result;
-  if (0 == id_tag) {
-      // get the global id tag
-    result = mMB->tag_get_handle(GLOBAL_ID_TAG_NAME, id_tag);
-    if (MB_TAG_NOT_FOUND == result) {
-      int def_val = -1;
-      result = mMB->tag_create(GLOBAL_ID_TAG_NAME, 4, MB_TAG_DENSE, id_tag, &def_val);
-    }
-    
-    if (MB_SUCCESS != result) return result;
-  }
-  
-    // now assign the ids
-  int i;
-  MBRange::iterator rit;
-  MBErrorCode tmp_result;
-  result = MB_SUCCESS;
-  for (i = start_id, rit = elements.begin(); rit != elements.end(); rit++, i++) {
-    tmp_result = mMB->tag_set_data(id_tag, &(*rit), 1, &i);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  
-  return result;
-}
-
-MBErrorCode MBWriteUtil::report_error( const std::string& error )
-{
-  if(mError)
-    return mError->set_last_error(error);
-  else
-    return MB_FAILURE;
-}
-
-
-MBErrorCode MBWriteUtil::report_error( const char* error, ... )
-{
-  va_list args;
-  va_start(args, error);
-  MBErrorCode result = mError->set_last_error(error, args);
-  va_end(args);
-  return result;
-}
-
-
-MBErrorCode MBWriteUtil::get_adjacencies( MBEntityHandle entity,
-                                          MBTag id_tag,
-                                          std::vector<int>& adj )
-{
-  MBErrorCode rval;
-  const MBEntityHandle* adj_array;
-  int num_adj, id;
-
-  TagServer* tag_server = mMB->tag_server();
- 
-    // Get handles of adjacent entities 
-  rval = mMB->a_entity_factory()->get_adjacencies( entity, adj_array, num_adj );
-  if (MB_SUCCESS != rval)
-  {
-    adj.clear();
-    return rval;
-  }
-  
-    // Append IDs of adjacent entities -- skip meshsets
-  adj.resize( num_adj );  // pre-allocate space
-  adj.clear();            // clear used space
-  
-  const MBEntityHandle* const end = adj_array + num_adj;
-  for (const MBEntityHandle* iter = adj_array; iter != end; ++iter)
-  {
-    if (TYPE_FROM_HANDLE( *iter ) != MBENTITYSET)
-    {
-      rval = tag_server->get_data( id_tag, iter, 1, &id );
-      if (MB_SUCCESS != rval)
-        return rval;
-      adj.push_back( id );
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBWriteUtil::get_adjacencies( MBEntityHandle entity,
-                                          const MBEntityHandle*& adj_array,
-                                          int& num_adj )
-{
-  return mMB->a_entity_factory()->get_adjacencies( entity, adj_array, num_adj );
-}
-
-MBErrorCode MBWriteUtil::get_tag_list( std::vector<MBTag>& result_list,
-                                       const MBTag* user_tag_list, 
-                                       int user_tag_list_length,
-                                       bool include_variable_length_tags )
-{
-  MBErrorCode rval;
-  
-  if (user_tag_list) {
-    result_list.clear();
-    result_list.reserve( user_tag_list_length );
-    for (int i = 0; i < user_tag_list_length; ++i) {
-      std::string name;
-      rval = mMB->tag_get_name( user_tag_list[i], name );
-      if (MB_SUCCESS != rval) {
-        report_error( "Error %d getting name for tag.  Invalid input tag handle?", (int)rval );
-        return rval;
-      }
-      
-      if (name.empty()) {
-        report_error( "Explicit request to save anonymous tag." );
-        return MB_TAG_NOT_FOUND;
-      }
-      
-      int size;
-      if (!include_variable_length_tags &&
-          MB_VARIABLE_DATA_LENGTH == mMB->tag_get_size( user_tag_list[i], size )) {
-        report_error( "File format cannot store variable-length tag: \"%s\".", name.c_str() );
-        return MB_TYPE_OUT_OF_RANGE;
-      }
-      
-      result_list.push_back( user_tag_list[i] );
-    }
-  }
-  else {
-    std::vector<MBTag> temp_list;
-    rval = mMB->tag_get_tags( temp_list );
-    if (MB_SUCCESS != rval) {
-      report_error( "MBInterface::tag_get_tags failed!" );
-      return rval;
-    }
-
-    result_list.clear();
-    result_list.reserve( temp_list.size() );
-    
-    std::vector<MBTag>::iterator i;
-    for (i = temp_list.begin(); i != temp_list.end(); ++i) {
-      std::string name;
-      rval = mMB->tag_get_name( *i, name );
-      if (MB_SUCCESS != rval) {
-        report_error( "Error %d getting name for tag.  Stale tag handle?", (int)rval );
-        return rval;
-      }
-      
-        // skip anonymous tags
-      if (name.empty())
-        continue;
-      
-        // skip private/internal tags
-      if (name.size() >= 2 && name[0] == '_' && name[1] == '_')
-        continue;
-      
-        // if reqested, skip variable-length tags
-      int size;
-      if (!include_variable_length_tags &&
-          MB_VARIABLE_DATA_LENGTH == mMB->tag_get_size( *i, size ))
-        continue;
-      
-       result_list.push_back( *i );
-    }
-  }
-  
-  return MB_SUCCESS;  
-}

Deleted: MOAB/trunk/src/MBWriteUtil.hpp
===================================================================
--- MOAB/trunk/src/MBWriteUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MBWriteUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,277 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-#ifndef MB_WRITE_UTIL_HPP
-#define MB_WRITE_UTIL_HPP
-
-#ifndef IS_BUILDING_MB
-#error "MBWriteUtil.hpp isn't supposed to be included into an application"
-#endif
-
-#include "MBWriteUtilIface.hpp"
-
-class MBCore;
-class MBError;
-
-class MBWriteUtil : public MBWriteUtilIface
-{
-private:
-  //! pointer to the MBCore
-  MBCore* mMB;
-  MBError* mError;
-public:
-
-  //! constructor takes MBCore pointer
-  MBWriteUtil(MBCore* mdb, MBError* error_handler);
-
-  //! destructor
-  ~MBWriteUtil(){}
-  
-    //! Check if the specified file already exists.
-    //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
-    //! if file does exist, or MB_FAILURE for some other error condition.
-  virtual MBErrorCode check_doesnt_exist( const char* file_name );
-
-  //! gets arrays for coordinate data from the MB
-  MBErrorCode get_node_arrays(
-      const int num_arrays,
-      const int num_nodes, 
-      const MBRange& entities,
-      MBTag node_id_tag,
-      const int start_node_id,
-      std::vector<double*>& arrays
-      );
-      
-  /** Get an array of coordinate values for nodes
-   *
-   * Given a range of node handles, retreive a single coordinate
-   * value for each. 
-   *
-   * Failure conditions:
-   *  - invalid entity handles (not vertices, non-existant entity, etc.)
-   *  - range is empty (<code>iter == end</code>)
-   *  - <code>output_array</code> is null
-   *  - insufficient space in <code>output_array</code>
-   *
-   *\param which_array  The coordinate to retreive (0-&gt;X, 1-&gt;Y, 2-&gt;Z)
-   *\param begin        The first node handle.
-   *\param end          One past the last node handle.
-   *\param output_size  The size of <code>output_array</code>.
-   *\param output_array The memory in which to write the node coordinates.
-   *\author Jason Kraftcheck
-   */
-  MBErrorCode get_node_array(
-      const int which_array, 
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const size_t output_size,
-      double* const output_array
-      );
-
-  //! get array for connectivity data from the MB
-  MBErrorCode get_element_array(
-      const int num_elements, 
-      const int verts_per_element,
-      MBTag node_id_tag,
-      const MBRange& entities, 
-      MBTag element_id_tag,
-      int start_element_id,
-      int* array
-      );
-
-  /** Get connectivity for elements 
-   *
-   * Get the connectivity list for a range of elements.
-   *
-   * Failure cases:
-   *  - Passed range is empty (<code>begin == end</code>).
-   *  - <code>vertices_per_elem</code> is less than one
-   *  - <code>element_array</code> is null.
-   *  - The range contains invalid handles (non-existant entities,
-   *      not an element, etc.)
-   *  - Retreiving ID tag for an entity failed.
-   *  - Insufficient space in passed array.
-   *
-   *\param begin        The first element handle
-   *\param end          One past the last element handle
-   *\param vertices_per_elem Number of vertices to retreive for each
-   *                    element.  If the element has more vertices, the
-   *                    element connectivity will be truncated.  If 
-   *                    <code>vertices_per_elem</code> is greater than the
-   *                    number of nodes for an eleement, the data will be
-   *                    padded with zeros.
-   *\param node_id_tag  A tag with integer values.  
-   *\param array_size   The length of <code>element_array</code>
-   *\param element_array The memory location at which to store the 
-   *                    connectivity list.
-   *\author Jason Kraftcheck
-   */
-  MBErrorCode get_element_array(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const int vertices_per_elem,
-      MBTag node_id_tag,
-      const size_t array_size, 
-      int *const element_array
-      );
-
-  /** Get connectivity for elements 
-   *
-   * Get the connectivity list for a range of elements.
-   *
-   * Failure cases:
-   *  - Passed range is empty (<code>begin == end</code>).
-   *  - <code>vertices_per_elem</code> is less than one
-   *  - <code>element_array</code> is null.
-   *  - The range contains invalid handles (non-existant entities,
-   *      not an element, etc.)
-   *  - Insufficient space in passed array.
-   *
-   *\param begin        The first element handle
-   *\param end          One past the last element handle
-   *\param vertices_per_elem Number of vertices to retreive for each
-   *                    element.  If the element has more vertices, the
-   *                    element connectivity will be truncated.  If 
-   *                    <code>vertices_per_elem</code> is greater than the
-   *                    number of nodes for an eleement, the data will be
-   *                    padded with zeros.
-   *\param array_size   The length of <code>element_array</code>
-   *\param element_array The memory location at which to store the 
-   *                    connectivity list.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_element_array(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const int vertices_per_elem,
-      const size_t array_size, 
-      MBEntityHandle *const element_array
-      );
-
-  /** Get poly (polygon or polyhedron) connectivity size
-   *\param begin  First iterator in range of poly
-   *\param end    One past last in range of poly.
-   *\param connectivity_size  The lenght of the connectivity list
-   *              For the specified range of polyhedra.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_poly_array_size(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      int& connectivity_size 
-      );
-   
-   
-  /** Get poly (polygon or polyhedron) connectivity.
-   *
-   * This function will add as many polys as possible to the
-   * passed arrays given the sizes of those arrays.  It will
-   * then pass back position at which it stoped and the sizes
-   * of the data written to the arrays.
-   *
-   *\param iter               As input, the first element handle.
-   *                          As output, one past the last element handle
-   *                          for which data was written to the arrays.
-   *\param end                The iterator at which to stop.
-   *\param node_id_tag        A tag with integer values.  
-   *\param element_array_len  As input, length of <code>element_array</code>.
-   *                          As output, the number of entries written in that
-   *                          array.
-   *\param element_array      The memory location at which to store the 
-   *                          connectivity list.
-   *\param index_array_len    As input, the length of <code>index_array</code>.
-   *                          As output, the number of entries written in that
-   *                          array.
-   *\param index_array        The memory location at which to store offsets.
-   *\param index_offset       Value to offset (add to) index values.  As output
-   *                          the input value plus the amount of data 
-   *                          written to the element array.  (The value you
-   *                          presumably want to pass to the next call.)
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_poly_arrays(
-      MBRange::const_iterator& iter,
-      const MBRange::const_iterator end,
-      const MBTag node_id_tag,
-      size_t& handle_array_len,
-      int *const handle_array,
-      size_t& index_array_len,
-      int *const index_array,
-      int& index_offset 
-      );
- 
-  //! get a set of nodes that represent a set of elements
-  MBErrorCode gather_nodes_from_elements(
-      const MBRange& elements,
-      const MBTag node_bit_mark_tag,
-      MBRange& nodes
-      );
-  
-    //! assign ids to input elements starting with start_id, written to id_tag
-    //! if zero, assigns to GLOBAL_ID_TAG_NAME
-  MBErrorCode assign_ids(MBRange &elements,
-                         MBTag id_tag,
-                         const int start_id);
-
-  
-  /** Get explict adjacencies 
-   *
-   * Get explicit adjacences stored in database.
-   * Does not create any explicit adjacencies or search for
-   * implicit ones.
-   *
-   *\param entity  The entity to retreive adjacencies for.
-   *\param id_tag  The global ID tag
-   *\param adj     The output list of global IDs of adjacent entities.
-   */
-  MBErrorCode get_adjacencies(
-      MBEntityHandle entity,
-      MBTag id_tag,
-      std::vector<int>& adj 
-  );
-  
-  MBErrorCode get_adjacencies( MBEntityHandle entity,
-                               const MBEntityHandle*& adj_array,
-                               int& num_adj );
-
-
-  /**\brief Get list of tags to write.
-   *
-   * Get the list of tags to write to the file, possibly using
-   * an optional user-specifed tag list.
-   *
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode 
-  get_tag_list( std::vector<MBTag>& result_list,
-                const MBTag* user_tag_list = 0, 
-                int user_tag_list_length = 0,
-                bool include_variable_length_tags = true );
-
-  //! tell MB there was an error when writing the mesh
-  //! it makes sense to have this as long as MBInterface has a write_mesh function
-  MBErrorCode report_error( const std::string& error );
-
-  MBErrorCode report_error( const char* error, ... )
-#ifdef __GNUC__
- __attribute__((format(printf,2,3)))
-#endif
-  ;
-};
-
-#endif
-
-

Modified: MOAB/trunk/src/Makefile.am
===================================================================
--- MOAB/trunk/src/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -10,6 +10,9 @@
   AM_CPPFLAGS += -I$(srcdir)/parallel
 endif
 SUBDIRS += io .
+if OLD_HEADERS
+  SUBDIRS += oldinc
+endif
 
 BUILT_SOURCES = MBCN_protos.h
 
@@ -17,12 +20,8 @@
 AM_CPPFLAGS += -DIS_BUILDING_MB \
                -I. \
                -I$(srcdir)/io \
-               -I$(srcdir)/io/moab \
                -I$(srcdir)/io/mhdf/include \
-               -I./moab \
-               -I$(srcdir)/moab \
-               -I$(srcdir)/parallel/moab \
-               -I./parallel/moab
+               -I$(srcdir)/parallel
 
 # The directory in which to install headers
 libMOAB_la_includedir = $(includedir)
@@ -39,44 +38,44 @@
   ElementSequence.hpp \
   EntitySequence.cpp \
   EntitySequence.hpp \
+  Error.hpp \
   FileOptions.cpp \
   FileOptions.hpp \
   GeomTopoTool.cpp \
   HigherOrderFactory.cpp \
   HomXform.cpp \
-  MBAdaptiveKDTree.cpp \
-  MBAffineXform.cpp \
-  MBAffineXform.hpp \
-  MBAxisBox.cpp \
-  MBAxisBox.hpp \
-  MBBSPTree.cpp \
+  AdaptiveKDTree.cpp \
+  AffineXform.cpp \
+  AffineXform.hpp \
+  AxisBox.cpp \
+  AxisBox.hpp \
+  BSPTree.cpp \
   MBCN.cpp \
-  MBCNArrays.hpp \
-  MBCartVect.cpp \
-  MBCartVect.hpp \
-  MBMatrix3.cpp \
-  MBMatrix3.hpp \
-  MBCore.cpp \
-  MBFactory.cpp \
-  MBGeomUtil.cpp \
-  MBInternals.hpp \
-  MBMeshSet.cpp \
-  MBMeshSet.hpp \
-  MBOrientedBox.cpp \
-  MBOrientedBox.hpp \
-  MBOrientedBoxTreeTool.cpp \
-  MBRange.cpp \
-  MBRangeSeqIntersectIter.cpp \
-  MBRangeSeqIntersectIter.hpp \
-  MBReadUtil.cpp \
-  MBReadUtil.hpp \
-  MBReaderWriterSet.cpp \
-  MBSkinner.cpp \
-  MBSysUtil.cpp \
-  MBSysUtil.hpp \
-  MBUtil.cpp \
-  MBWriteUtil.cpp \
-  MBWriteUtil.hpp \
+  CNArrays.hpp \
+  CartVect.cpp \
+  Matrix3.cpp \
+  Matrix3.hpp \
+  Core.cpp \
+  Factory.cpp \
+  GeomUtil.cpp \
+  Internals.hpp \
+  MeshSet.cpp \
+  MeshSet.hpp \
+  OrientedBox.cpp \
+  OrientedBox.hpp \
+  OrientedBoxTreeTool.cpp \
+  Range.cpp \
+  RangeSeqIntersectIter.cpp \
+  RangeSeqIntersectIter.hpp \
+  ReadUtil.cpp \
+  ReadUtil.hpp \
+  ReaderWriterSet.cpp \
+  Skinner.cpp \
+  SysUtil.cpp \
+  SysUtil.hpp \
+  Util.cpp \
+  WriteUtil.cpp \
+  WriteUtil.hpp \
   MeshSetSequence.cpp \
   MeshSetSequence.hpp \
   MeshTopoUtil.cpp \
@@ -121,29 +120,29 @@
   moab/GeomTopoTool.hpp \
   moab/HigherOrderFactory.hpp \
   moab/HomXform.hpp \
-  moab/MBAdaptiveKDTree.hpp \
-  moab/MBBSPTree.hpp \
+  moab/AdaptiveKDTree.hpp \
+  moab/BSPTree.hpp \
   moab/MBCN.hpp \
-  moab/MBCore.hpp \
-  moab/MBEntityType.h \
-  moab/MBEntityHandle.h \
-  moab/MBError.hpp \
-  moab/MBForward.hpp \
-  moab/MBGeomUtil.hpp \
-  moab/MBInterface.hpp \
-  moab/MBOrientedBoxTreeTool.hpp \
+  moab/CartVect.hpp \
+  moab/Core.hpp \
+  moab/EntityType.hpp \
+  moab/EntityHandle.hpp \
+  moab/Forward.hpp \
+  moab/GeomUtil.hpp \
+  moab/Interface.hpp \
+  moab/OrientedBoxTreeTool.hpp \
   moab/BSPTreePoly.hpp \
-  moab/MBRange.hpp \
-  moab/MBReadUtilIface.hpp \
-  moab/MBReaderIface.hpp \
-  moab/MBReaderWriterSet.hpp \
-  moab/MBSkinner.hpp \
+  moab/Range.hpp \
+  moab/ReadUtilIface.hpp \
+  moab/ReaderIface.hpp \
+  moab/ReaderWriterSet.hpp \
+  moab/Skinner.hpp \
   moab/MBTagConventions.hpp \
-  moab/MBTypes.h \
-  moab/MBUnknownInterface.hpp \
-  moab/MBUtil.hpp \
-  moab/MBWriteUtilIface.hpp \
-  moab/MBWriterIface.hpp \
+  moab/Types.hpp \
+  moab/UnknownInterface.hpp \
+  moab/Util.hpp \
+  moab/WriteUtilIface.hpp \
+  moab/WriterIface.hpp \
   moab/MeshTopoUtil.hpp \
   moab/RangeMap.hpp \
   MBCN.h \

Copied: MOAB/trunk/src/Matrix3.cpp (from rev 3583, MOAB/trunk/src/MBMatrix3.cpp)
===================================================================
--- MOAB/trunk/src/Matrix3.cpp	                        (rev 0)
+++ MOAB/trunk/src/Matrix3.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,227 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file Matrix3.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#include "Matrix3.hpp"
+#include <math.h>
+#include <iostream>
+
+namespace moab {
+
+// Copied from "Visualization Toolkit"
+//  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+//  All rights reserved.
+//  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
+//
+// Jacobi iteration for the solution of eigenvectors/eigenvalues of a nxn
+// real symmetric matrix. Square nxn matrix a; size of matrix in n;
+// output eigenvalues in w; and output eigenvectors in v. Resulting
+// eigenvalues/vectors are sorted in decreasing order; eigenvectors are
+// normalized.
+#define VTK_ROTATE(a,i,j,k,l) g=a[i][j];h=a[k][l];a[i][j]=g-s*(h+g*tau);\
+        a[k][l]=h+s*(g-h*tau)
+ErrorCode EigenDecomp( const Matrix3& a_in, 
+                         double w[3],
+                         CartVect v[3] )
+{
+  const int MAX_ROTATIONS = 20;
+  const double one_ninth = 1./9;
+  int i, j, k, iq, ip, numPos;
+  double tresh, theta, tau, t, sm, s, h, g, c, tmp;
+  double b[3], z[3];
+  Matrix3 a(a_in);
+
+  // initialize
+  for (ip=0; ip<3; ip++) 
+    {
+    for (iq=0; iq<3; iq++)
+      {
+      v[ip][iq] = 0.0;
+      }
+    v[ip][ip] = 1.0;
+    }
+  for (ip=0; ip<3; ip++) 
+    {
+    b[ip] = w[ip] = a[ip][ip];
+    z[ip] = 0.0;
+    }
+
+  // begin rotation sequence
+  for (i=0; i<MAX_ROTATIONS; i++) 
+    {
+    sm = 0.0;
+    for (ip=0; ip<2; ip++) 
+      {
+      for (iq=ip+1; iq<3; iq++)
+        {
+        sm += fabs(a[ip][iq]);
+        }
+      }
+    if (sm == 0.0)
+      {
+      break;
+      }
+
+    if (i < 3)                                // first 3 sweeps
+      {
+      tresh = 0.2*sm*one_ninth;
+      }
+    else
+      {
+      tresh = 0.0;
+      }
+
+    for (ip=0; ip<2; ip++) 
+      {
+      for (iq=ip+1; iq<3; iq++) 
+        {
+        g = 100.0*fabs(a[ip][iq]);
+
+        // after 4 sweeps
+        if (i > 3 && (fabs(w[ip])+g) == fabs(w[ip])
+        && (fabs(w[iq])+g) == fabs(w[iq]))
+          {
+          a[ip][iq] = 0.0;
+          }
+        else if (fabs(a[ip][iq]) > tresh) 
+          {
+          h = w[iq] - w[ip];
+          if ( (fabs(h)+g) == fabs(h))
+            {
+            t = (a[ip][iq]) / h;
+            }
+          else 
+            {
+            theta = 0.5*h / (a[ip][iq]);
+            t = 1.0 / (fabs(theta)+sqrt(1.0+theta*theta));
+            if (theta < 0.0)
+              {
+              t = -t;
+              }
+            }
+          c = 1.0 / sqrt(1+t*t);
+          s = t*c;
+          tau = s/(1.0+c);
+          h = t*a[ip][iq];
+          z[ip] -= h;
+          z[iq] += h;
+          w[ip] -= h;
+          w[iq] += h;
+          a[ip][iq]=0.0;
+
+          // ip already shifted left by 1 unit
+          for (j = 0;j <= ip-1;j++) 
+            {
+            VTK_ROTATE(a,j,ip,j,iq);
+            }
+          // ip and iq already shifted left by 1 unit
+          for (j = ip+1;j <= iq-1;j++) 
+            {
+            VTK_ROTATE(a,ip,j,j,iq);
+            }
+          // iq already shifted left by 1 unit
+          for (j=iq+1; j<3; j++) 
+            {
+            VTK_ROTATE(a,ip,j,iq,j);
+            }
+          for (j=0; j<3; j++) 
+            {
+            VTK_ROTATE(v,j,ip,j,iq);
+            }
+          }
+        }
+      }
+
+    for (ip=0; ip<3; ip++) 
+      {
+      b[ip] += z[ip];
+      w[ip] = b[ip];
+      z[ip] = 0.0;
+      }
+    }
+
+  //// this is NEVER called
+  if ( i >= MAX_ROTATIONS )
+    {
+      std::cerr << "Matrix3D: Error extracting eigenfunctions" << std::endl;
+      return MB_FAILURE;
+    }
+
+  // sort eigenfunctions                 these changes do not affect accuracy 
+  for (j=0; j<2; j++)                  // boundary incorrect
+    {
+    k = j;
+    tmp = w[k];
+    for (i=j+1; i<3; i++)                // boundary incorrect, shifted already
+      {
+      if (w[i] >= tmp)                   // why exchage if same?
+        {
+        k = i;
+        tmp = w[k];
+        }
+      }
+    if (k != j) 
+      {
+      w[k] = w[j];
+      w[j] = tmp;
+      for (i=0; i<3; i++) 
+        {
+        tmp = v[i][j];
+        v[i][j] = v[i][k];
+        v[i][k] = tmp;
+        }
+      }
+    }
+  // insure eigenvector consistency (i.e., Jacobi can compute vectors that
+  // are negative of one another (.707,.707,0) and (-.707,-.707,0). This can
+  // reek havoc in hyperstreamline/other stuff. We will select the most
+  // positive eigenvector.
+  int ceil_half_n = (3 >> 1) + (3 & 1);
+  for (j=0; j<3; j++)
+    {
+    for (numPos=0, i=0; i<3; i++)
+      {
+      if ( v[i][j] >= 0.0 )
+        {
+        numPos++;
+        }
+      }
+//    if ( numPos < ceil(double(n)/double(2.0)) )
+    if ( numPos < ceil_half_n)
+      {
+      for(i=0; i<3; i++)
+        {
+        v[i][j] *= -1.0;
+        }
+      }
+    }
+
+  return MB_SUCCESS;
+}
+
+
+std::ostream& operator<<( std::ostream& s, const Matrix3& m )
+{
+  return s <<  "| " << m(0,0) << " " << m(0,1) << " " << m(0,2) 
+           << " | " << m(1,0) << " " << m(1,1) << " " << m(1,2) 
+           << " | " << m(2,0) << " " << m(2,1) << " " << m(2,2) 
+           << " |" ;
+}
+
+} // namespace moab

Copied: MOAB/trunk/src/Matrix3.hpp (from rev 3583, MOAB/trunk/src/MBMatrix3.hpp)
===================================================================
--- MOAB/trunk/src/Matrix3.hpp	                        (rev 0)
+++ MOAB/trunk/src/Matrix3.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,289 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file Matrix3.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#ifndef MB_MATRIX_3_HPP
+#define MB_MATRIX_3_HPP
+
+#include "moab/CartVect.hpp"
+#include "moab/Types.hpp"
+#include <iosfwd>
+#include <limits>
+
+#ifdef _MSC_VER
+# define finite _finite
+#endif
+
+namespace moab {
+
+class Matrix3 
+{
+  double d[9];
+public:
+
+  inline Matrix3() 
+    {}
+  
+  inline Matrix3( double diagonal )
+    { 
+      d[0] = d[4] = d[8] = diagonal;
+      d[1] = d[2] = d[3] = 0;
+      d[5] = d[6] = d[7] = 0;
+    }
+    
+  inline Matrix3( const CartVect& diagonal )
+    { 
+      d[0] = diagonal[0];
+      d[4] = diagonal[1],
+      d[8] = diagonal[2];
+      d[1] = d[2] = d[3] = 0;
+      d[5] = d[6] = d[7] = 0;
+    }
+  
+  
+  inline Matrix3( const CartVect& row0,
+                    const CartVect& row1,
+                    const CartVect& row2 )
+    {
+      row0.get( d );
+      row1.get( d+3 );
+      row2.get( d+6 );
+    }
+  
+  inline Matrix3( const double* v )
+    { 
+      d[0] = v[0]; d[1] = v[1]; d[2] = v[2];
+      d[3] = v[3]; d[4] = v[4]; d[5] = v[5]; 
+      d[6] = v[6]; d[7] = v[7]; d[8] = v[8];
+    }
+  
+  inline Matrix3( double v00, double v01, double v02,
+                    double v10, double v11, double v12,
+                    double v20, double v21, double v22 )
+    {
+      d[0] = v00; d[1] = v01; d[2] = v02;
+      d[3] = v10; d[4] = v11; d[5] = v12;
+      d[6] = v20; d[7] = v21; d[8] = v22;
+    }
+  
+  inline Matrix3( const Matrix3& m )
+    {
+      d[0] = m.d[0]; d[1] = m.d[1]; d[2] = m.d[2];
+      d[3] = m.d[3]; d[4] = m.d[4]; d[5] = m.d[5];
+      d[6] = m.d[6]; d[7] = m.d[7]; d[8] = m.d[8];
+    }
+   
+  inline Matrix3& operator=( const Matrix3& m )
+    {
+      d[0] = m.d[0]; d[1] = m.d[1]; d[2] = m.d[2];
+      d[3] = m.d[3]; d[4] = m.d[4]; d[5] = m.d[5];
+      d[6] = m.d[6]; d[7] = m.d[7]; d[8] = m.d[8];
+      return *this;
+    }
+  
+  inline Matrix3& operator=( const double* v )
+    { 
+      d[0] = v[0]; d[1] = v[1]; d[2] = v[2];
+      d[3] = v[3]; d[4] = v[4]; d[5] = v[5]; 
+      d[6] = v[6]; d[7] = v[7]; d[8] = v[8];
+      return *this;
+    }
+
+  inline double* operator[]( unsigned i )
+    { return d + 3*i; }
+  inline const double* operator[]( unsigned i ) const
+    { return d + 3*i; }
+  inline double& operator()(unsigned r, unsigned c)
+    { return d[3*r+c]; }
+  inline double operator()(unsigned r, unsigned c) const
+    { return d[3*r+c]; }
+  
+  inline Matrix3& operator+=( const Matrix3& m )
+    {
+      d[0] += m.d[0]; d[1] += m.d[1]; d[2] += m.d[2];
+      d[3] += m.d[3]; d[4] += m.d[4]; d[5] += m.d[5];
+      d[6] += m.d[6]; d[7] += m.d[7]; d[8] += m.d[8];
+      return *this;
+    }
+  
+  inline Matrix3& operator-=( const Matrix3& m )
+    {
+      d[0] -= m.d[0]; d[1] -= m.d[1]; d[2] -= m.d[2];
+      d[3] -= m.d[3]; d[4] -= m.d[4]; d[5] -= m.d[5];
+      d[6] -= m.d[6]; d[7] -= m.d[7]; d[8] -= m.d[8];
+      return *this;
+    }
+  
+  inline Matrix3& operator*=( double s )
+    {
+      d[0] *= s; d[1] *= s; d[2] *= s;
+      d[3] *= s; d[4] *= s; d[5] *= s;
+      d[6] *= s; d[7] *= s; d[8] *= s;
+      return *this;
+    }
+  
+  inline Matrix3& operator/=( double s )
+    {
+      d[0] /= s; d[1] /= s; d[2] /= s;
+      d[3] /= s; d[4] /= s; d[5] /= s;
+      d[6] /= s; d[7] /= s; d[8] /= s;
+      return *this;
+    }
+  
+  inline Matrix3& operator*=( const Matrix3& m );
+  
+  inline double determinant() const;
+  
+  inline Matrix3 inverse() const;
+  
+    // invert matrix without re-calculating the
+    // reciprocal of the determinant.
+  inline Matrix3 inverse( double inverse_det ) const;
+  
+  inline bool positive_definite() const;
+  inline bool positive_definite( double& determinant_out ) const;
+  
+  inline Matrix3 transpose() const;
+  
+  inline bool invert();
+  
+    // Calculate determinant of 2x2 submatrix composed of the
+    // elements not in the passed row or column.
+  inline double subdet( int r, int c ) const;
+};
+
+inline Matrix3 operator+( const Matrix3& a, const Matrix3& b )
+  { return Matrix3(a) += b; }
+
+inline Matrix3 operator-( const Matrix3& a, const Matrix3& b )
+  { return Matrix3(a) -= b; }
+
+inline Matrix3 operator*( const Matrix3& a, const Matrix3& b )
+{
+  return Matrix3( a(0,0) * b(0,0) + a(0,1) * b(1,0) + a(0,2) * b(2,0),
+                    a(0,0) * b(0,1) + a(0,1) * b(1,1) + a(0,2) * b(2,1),
+                    a(0,0) * b(0,2) + a(0,1) * b(1,2) + a(0,2) * b(2,2),
+                    a(1,0) * b(0,0) + a(1,1) * b(1,0) + a(1,2) * b(2,0),
+                    a(1,0) * b(0,1) + a(1,1) * b(1,1) + a(1,2) * b(2,1),
+                    a(1,0) * b(0,2) + a(1,1) * b(1,2) + a(1,2) * b(2,2),
+                    a(2,0) * b(0,0) + a(2,1) * b(1,0) + a(2,2) * b(2,0),
+                    a(2,0) * b(0,1) + a(2,1) * b(1,1) + a(2,2) * b(2,1),
+                    a(2,0) * b(0,2) + a(2,1) * b(1,2) + a(2,2) * b(2,2) );
+}
+
+inline Matrix3& Matrix3::operator*=( const Matrix3& m )
+  { return *this = Matrix3(*this) * m; }
+
+inline Matrix3 outer_product( const CartVect& u,
+                                const CartVect& v )
+{
+  return Matrix3( u[0] * v[0], u[0] * v[1], u[0] * v[2],
+                    u[1] * v[0], u[1] * v[1], u[1] * v[2],
+                    u[2] * v[0], u[2] * v[1], u[2] * v[2] );
+}
+
+inline CartVect operator*( const CartVect& v, const Matrix3& m )
+{
+  return CartVect( v[0] * m(0,0) + v[1] * m(1,0) + v[2] * m(2,0),
+                     v[0] * m(0,1) + v[1] * m(1,1) + v[2] * m(2,1),
+                     v[0] * m(0,2) + v[1] * m(1,2) + v[2] * m(2,2) );
+}
+
+inline CartVect operator*( const Matrix3& m, const CartVect& v )
+{
+  return CartVect( v[0] * m(0,0) + v[1] * m(0,1) + v[2] * m(0,2),
+                     v[0] * m(1,0) + v[1] * m(1,1) + v[2] * m(1,2),
+                     v[0] * m(2,0) + v[1] * m(2,1) + v[2] * m(2,2) );
+} 
+
+inline double Matrix3::determinant() const
+{
+  return d[0] * d[4] * d[8] 
+       + d[1] * d[5] * d[6]
+       + d[2] * d[3] * d[7]
+       - d[0] * d[5] * d[7]
+       - d[1] * d[3] * d[8]
+       - d[2] * d[4] * d[6];
+}
+
+inline bool Matrix3::positive_definite( double& det ) const
+{
+  double subdet6 = d[1]*d[5]-d[2]*d[4];
+  double subdet7 = d[2]*d[3]-d[0]*d[5];
+  double subdet8 = d[0]*d[4]-d[1]*d[3];
+  det = d[6]*subdet6 + d[7]*subdet7 + d[8]*subdet8;
+  return d[0] > 0 && subdet8 > 0 && det > 0;
+}
+
+inline bool Matrix3::positive_definite() const
+{
+  double d;
+  return positive_definite(d);
+}
+
+inline Matrix3 Matrix3::inverse( double i ) const
+{
+  return Matrix3( i * (d[4] * d[8] - d[5] * d[7]),
+                    i * (d[2] * d[7] - d[8] * d[1]),
+                    i * (d[1] * d[5] - d[4] * d[2]),
+                    i * (d[5] * d[6] - d[8] * d[3]),
+                    i * (d[0] * d[8] - d[6] * d[2]),
+                    i * (d[2] * d[3] - d[5] * d[0]),
+                    i * (d[3] * d[7] - d[6] * d[4]),
+                    i * (d[1] * d[6] - d[7] * d[0]),
+                    i * (d[0] * d[4] - d[3] * d[1]) );
+}  
+
+inline Matrix3 Matrix3::inverse() const
+{
+  return inverse( 1.0 / determinant() );
+}
+
+inline bool Matrix3::invert()
+{
+  double i = 1.0 / determinant();
+  if (!finite(i) || fabs(i) < std::numeric_limits<double>::epsilon())
+    return false;
+  *this = inverse( i );
+  return true;
+}
+
+inline Matrix3 Matrix3::transpose() const
+{
+  return Matrix3( d[0], d[3], d[6],
+                    d[1], d[4], d[7],
+                    d[2], d[5], d[8] );
+}
+
+inline double Matrix3::subdet( int r, int c ) const
+{
+  const int r1 = (r+1)%3, r2 = (r+2)%3;
+  const int c1 = (c+1)%3, c2 = (c+2)%3;
+  return d[3*r1+c1]*d[3*r2+c2] - d[3*r1+c2]*d[3*r2+c1];
+}
+                         
+ErrorCode EigenDecomp( const Matrix3& a, 
+                         double Eigenvalues[3],
+                         CartVect Eigenvectors[3] );
+
+std::ostream& operator<<( std::ostream&, const Matrix3& );
+  
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/MeshSet.cpp (from rev 3583, MOAB/trunk/src/MBMeshSet.cpp)
===================================================================
--- MOAB/trunk/src/MeshSet.cpp	                        (rev 0)
+++ MOAB/trunk/src/MeshSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1131 @@
+#ifdef WIN32
+#ifdef _DEBUG
+// turn off warnings that say they debugging identifier has been truncated
+// this warning comes up when using some STL containers
+#pragma warning(disable : 4786)
+#endif
+#endif
+
+#include "MeshSet.hpp"
+#include "AEntityFactory.hpp"
+
+namespace moab {
+
+
+/*****************************************************************************************
+ *                          Helper Function Declarations                                 *
+ *****************************************************************************************/
+
+/**\brief Insert into parent/child list */
+static inline 
+MeshSet::Count insert_in_vector( const MeshSet::Count count, 
+                                   MeshSet::CompactList& list,
+                                   const EntityHandle h,
+                                   int &result );
+
+/**\brief Remvoe from parent/child list */
+static inline
+MeshSet::Count remove_from_vector( const MeshSet::Count count, 
+                                     MeshSet::CompactList& list,
+                                     const EntityHandle h,
+                                     int &result );
+
+
+/**\brief Resize MeshSet::CompactList.  Returns pointer to storage */
+static EntityHandle* resize_compact_list( MeshSet::Count& count,
+                                            MeshSet::CompactList& clist,
+                                            size_t new_list_size );
+/**\brief Methods to insert/remove range-based data from contents list.
+ *        Templatized to operate on both Range and set-based MeshSets.
+ */
+template <typename pair_iter_t> class range_tool
+{
+public:
+  /** Insert range-based data into range-based MeshSet */
+  inline static ErrorCode ranged_insert_entities( MeshSet::Count& count, 
+                                                    MeshSet::CompactList& clist, 
+                                                    pair_iter_t begin, 
+                                                    pair_iter_t end, 
+                                                    EntityHandle my_handle, 
+                                                    AEntityFactory* adj );
+  
+  /** Remove range-based data from range-based MeshSet */
+  inline static ErrorCode ranged_remove_entities( MeshSet::Count& count, 
+                                                    MeshSet::CompactList& clist, 
+                                                    pair_iter_t begin, 
+                                                    pair_iter_t end, 
+                                                    EntityHandle my_handle, 
+                                                    AEntityFactory* adj );
+
+  /** Insert range-based data into list-based MeshSet */
+  inline static ErrorCode vector_insert_entities( MeshSet::Count& count, 
+                                                    MeshSet::CompactList& clist, 
+                                                    pair_iter_t begin, 
+                                                    pair_iter_t end, 
+                                                    EntityHandle my_handle, 
+                                                    AEntityFactory* adj );
+};
+
+/** Remove Range of handles fromr vector-based MeshSet */
+static ErrorCode vector_remove_range( MeshSet::Count& count, 
+                                        MeshSet::CompactList& clist, 
+                                        const Range& range, 
+                                        EntityHandle my_handle, 
+                                        AEntityFactory* adj );
+
+/** Remove range-based MeshSet contents from vector-based MeshSet */
+static ErrorCode vector_remove_ranges( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* pair_list,
+                                         size_t num_pairs,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj );
+
+/** Remove unsorted array of handles from vector-based MeshSet */
+static ErrorCode vector_remove_vector( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* vect,
+                                         size_t vect_size,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj );
+
+/** Insert unsorted array of handles into vector-based MeshSet */
+static ErrorCode vector_insert_vector( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* vect,
+                                         size_t vect_size,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj );
+
+/** Convert unsorted array of handles into array of ranged [begin,end] pairs */
+static void convert_to_ranges( const EntityHandle* vect_in, size_t vect_in_len,
+                               std::vector<EntityHandle>& vect_out );
+
+
+/*****************************************************************************************
+ *                             Parent/Child Operations                                   *
+ *****************************************************************************************/
+
+static inline 
+MeshSet::Count insert_in_vector( const MeshSet::Count count, 
+                                MeshSet::CompactList& list,
+                                const EntityHandle h,
+                                int &result )
+{
+  switch (count) {
+    case MeshSet::ZERO:
+      list.hnd[0] = h;
+      result = true;
+      return MeshSet::ONE;
+    case MeshSet::ONE:
+      if (list.hnd[0] == h) {
+        result = false;
+        return MeshSet::ONE;
+      }
+      else {
+        result = true;
+        list.hnd[1] = h;
+        return MeshSet::TWO;
+      }
+    case MeshSet::TWO:
+      if (list.hnd[0] == h || list.hnd[1] == h) {
+        result = false;
+        return MeshSet::TWO;
+      }
+      else {
+        EntityHandle* ptr = (EntityHandle*)malloc(3*sizeof(EntityHandle));
+        ptr[0] = list.hnd[0];
+        ptr[1] = list.hnd[1];
+        ptr[2] = h;
+        list.ptr[0] = ptr;
+        list.ptr[1] = ptr + 3;
+        result = true;
+        return MeshSet::MANY;
+      }
+    case MeshSet::MANY:
+      if (std::find( list.ptr[0], list.ptr[1], h ) != list.ptr[1]) {
+        result = false;
+      }
+      else {
+        int size = list.ptr[1] - list.ptr[0];
+        list.ptr[0] = (EntityHandle*)realloc( list.ptr[0], (size+1)*sizeof(EntityHandle) );
+        list.ptr[0][size] = h;
+        list.ptr[1] = list.ptr[0] + size + 1;
+        result = true;
+      }
+      return MeshSet::MANY;
+  }
+
+  return MeshSet::ZERO;
+}
+
+static inline
+MeshSet::Count remove_from_vector( const MeshSet::Count count, 
+                                  MeshSet::CompactList& list,
+                                  const EntityHandle h,
+                                  int &result )
+{
+  switch (count) {
+    case MeshSet::ZERO:
+      result = false;
+      return MeshSet::ZERO;
+    case MeshSet::ONE:
+      if (h == list.hnd[0]) {
+        result = true;
+        return MeshSet::ZERO;
+      }
+      else {
+        result = false;
+        return MeshSet::ONE;
+      }
+    case MeshSet::TWO:
+      if (h == list.hnd[0]) {
+        list.hnd[0] = list.hnd[1];
+        result = true;
+        return MeshSet::ONE;
+      } 
+      else if (h == list.hnd[1]) {
+        result = true;
+        return MeshSet::ONE;
+      }
+      else {
+        result = false;
+        return MeshSet::TWO;
+      }
+    case MeshSet::MANY: {
+      EntityHandle *i, *j, *p;
+      i = std::find( list.ptr[0], list.ptr[1], h );
+      if (i == list.ptr[1]) {
+        result = false;
+        return MeshSet::MANY;
+      }
+      
+      result = true;
+      p = list.ptr[1] - 1;
+      while (i != p) {
+        j = i + 1;
+        *i = *j;
+        i = j;
+      }
+      int size = p - list.ptr[0];
+      if (size == 2) {
+        p = list.ptr[0];
+        list.hnd[0] = p[0];
+        list.hnd[1] = p[1];
+        free( p );
+        return MeshSet::TWO;
+      }
+      else {
+        list.ptr[0] = (EntityHandle*)realloc( list.ptr[0], size*sizeof(EntityHandle) );
+        list.ptr[1] = list.ptr[0] + size;
+        return MeshSet::MANY;
+      }
+    }
+  }
+
+  return MeshSet::ZERO;
+}
+
+
+int MeshSet::add_parent( EntityHandle parent )
+{ 
+  int result = 0;
+  mParentCount = insert_in_vector( (Count)mParentCount, parentMeshSets, parent, result );
+  return result;
+}
+int MeshSet::add_child( EntityHandle child )
+{ 
+  int result = 0;
+  mChildCount = insert_in_vector( (Count)mChildCount, childMeshSets, child, result );
+  return result;
+}
+
+int MeshSet::remove_parent( EntityHandle parent )
+{ 
+  int result = 0;
+  mParentCount = remove_from_vector( (Count)mParentCount, parentMeshSets, parent, result );
+  return result;
+}
+int MeshSet::remove_child( EntityHandle child )
+{ 
+  int result = 0;
+  mChildCount = remove_from_vector( (Count)mChildCount, childMeshSets, child, result );
+  return result;
+}
+
+
+/*****************************************************************************************
+ *                          Flag Conversion Operations                                   *
+ *****************************************************************************************/
+
+ErrorCode MeshSet::convert( unsigned flags, EntityHandle my_handle, AEntityFactory* adj )
+{
+  ErrorCode rval = MB_SUCCESS;
+  if ((mFlags & MESHSET_TRACK_OWNER) && !(flags & MESHSET_TRACK_OWNER))
+    rval = remove_adjacencies( my_handle, adj );
+  else if (!(mFlags & MESHSET_TRACK_OWNER) && (flags & MESHSET_TRACK_OWNER))
+    rval = create_adjacencies( my_handle, adj );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  if (!(mFlags & MESHSET_ORDERED) && (flags & MESHSET_ORDERED)) {
+    size_t datalen;
+    EntityHandle* data = get_contents(datalen);
+    if (datalen) {
+      std::vector<EntityHandle> list( datalen );
+      memcpy( &list[0], data, datalen*sizeof(EntityHandle) );
+      int num_ents = num_entities();
+      Count count = (Count)mContentCount;
+      data = resize_compact_list( count, contentList, num_ents );
+      mContentCount = count;
+      assert( list.size() % 2 == 0 );
+      std::vector<EntityHandle>::iterator i = list.begin();
+      while (i != list.end()) {
+        EntityHandle h = *i; ++i;
+        EntityHandle e = *i; ++i;
+        for (; h <= e; ++h) {
+          *data = h; 
+          ++data;
+        }
+      }
+    }
+  }
+  else if ((mFlags & MESHSET_ORDERED) && !(flags & MESHSET_ORDERED)) {
+    size_t datalen;
+    EntityHandle* data = get_contents(datalen);
+    if (datalen) {
+      std::vector<EntityHandle> ranges;
+      convert_to_ranges( data, datalen, ranges );
+      Count count = (Count)mContentCount;
+      data = resize_compact_list( count, contentList, ranges.size() );
+      mContentCount = count;
+      memcpy( data, &ranges[0], ranges.size()*sizeof(EntityHandle) );
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode MeshSet::create_adjacencies( EntityHandle my_handle, AEntityFactory* adj )
+{
+  ErrorCode rval = MB_SUCCESS;;
+  size_t count;
+  const EntityHandle *const ptr = get_contents( count );
+  const EntityHandle *const end = ptr + count;
+  if (vector_based()) {
+    for (const EntityHandle* i = ptr; i != end; ++i) {
+      rval = adj->add_adjacency( *i, my_handle, false );
+      if (MB_SUCCESS != rval) {
+        for (const EntityHandle* j = ptr; j != i; ++j) 
+          adj->remove_adjacency( *j, my_handle );
+        return rval;
+      }
+    }
+  }
+  else {
+    assert( 0 == count % 2 );
+    for (const EntityHandle* i = ptr; i != end; i += 2) {
+      for (EntityHandle h = i[0]; h <= i[1]; ++h) {
+        rval = adj->add_adjacency( h, my_handle, false );
+        if (MB_SUCCESS != rval) {
+          for (EntityHandle j = i[0]; j < h; ++j)
+            adj->remove_adjacency( j, my_handle );
+          for (const EntityHandle* j = ptr; j != i; j += 2)
+            for (EntityHandle k = j[0]; k <= j[1]; ++k)
+              adj->remove_adjacency( k, my_handle );
+          return rval;
+        }
+      }
+    }
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode MeshSet::remove_adjacencies( EntityHandle my_handle, AEntityFactory* adj )
+{
+  size_t count;
+  const EntityHandle *const ptr = get_contents( count );
+  const EntityHandle *const end = ptr + count;
+  if (vector_based()) {
+    for (const EntityHandle* i = ptr; i != end; ++i)
+      adj->remove_adjacency( *i, my_handle );
+  }
+  else {
+    assert( 0 == count % 2 );
+    for (const EntityHandle* i = ptr; i != end; i += 2)
+      for (EntityHandle h = i[0]; h <= i[1]; ++h)
+        adj->remove_adjacency( h, my_handle );
+  }
+  return MB_SUCCESS;
+}
+
+
+/*****************************************************************************************
+ *                          Contents Modifiction Methods                                 *
+ *****************************************************************************************/
+
+static EntityHandle* resize_compact_list( MeshSet::Count& count,
+                                            MeshSet::CompactList& clist,
+                                            size_t new_list_size )
+{
+  if (count <= 2) {
+    if (new_list_size <= 2) {
+      count = (MeshSet::Count)new_list_size;
+      return clist.hnd;
+    }
+    else {
+      EntityHandle* list = (EntityHandle*)malloc( new_list_size*sizeof(EntityHandle) );
+      list[0] = clist.hnd[0];
+      list[1] = clist.hnd[1];
+      clist.ptr[0] = list;
+      clist.ptr[1] = list + new_list_size;
+      count = MeshSet::MANY;
+      return list;
+    }
+  }
+  else if (new_list_size > 2) {
+    if (new_list_size > (size_t)(clist.ptr[1] - clist.ptr[0]))
+      clist.ptr[0] = (EntityHandle*)realloc( clist.ptr[0], new_list_size*sizeof(EntityHandle) );
+    clist.ptr[1] = clist.ptr[0] + new_list_size;
+    count = MeshSet::MANY;
+    return clist.ptr[0];
+  }
+  else {
+    EntityHandle* list = clist.ptr[0];
+    clist.hnd[0] = list[0];
+    clist.hnd[1] = list[1];
+    free(list);
+    count = (MeshSet::Count)new_list_size;
+    return clist.hnd;
+  }
+}
+
+template <typename pair_iter_t> inline ErrorCode
+range_tool<pair_iter_t>::ranged_insert_entities( MeshSet::Count& count, 
+                                                 MeshSet::CompactList& clist, 
+                                                 pair_iter_t begin, 
+                                                 pair_iter_t end, 
+                                                 EntityHandle my_handle, 
+                                                 AEntityFactory* adj )
+{
+    //first pass:
+    // 1) merge existing ranges 
+    // 2) count number of new ranges that must be inserted
+  ptrdiff_t insert_count = 0;
+  EntityHandle *list;
+  size_t list_size;
+  if (count < MeshSet::MANY) {
+    list = clist.hnd;
+    list_size = count;
+  }
+  else {
+    list = clist.ptr[0];
+    list_size = clist.ptr[1] - clist.ptr[0];
+  }
+
+  EntityHandle* list_write = list;
+  EntityHandle *const list_end = list + list_size, *list_read = list;
+  pair_iter_t i = begin;
+  
+  while(i != end) {
+    
+      // if there are holes in the current array, shuffle blocks 
+      // down until we find the next block to merge with or insert before
+    if (list_read != list_write) {
+      while (list_read != list_end && i->second + 1 < list_read[0]) {
+      	list_write[0] = list_read[0];
+        list_write[1] = list_read[1];
+        list_write += 2;
+        list_read += 2;
+      }
+    }
+      // otherwise do a binary search
+    else {
+      list_write = std::lower_bound( list_write, list_end, i->first - 1 );
+      	// if in middle of range block (odd index), back up to start of block
+      list_write -= (list_write - list)%2;
+      list_read = list_write;
+    }
+    
+      // handle any straight insertions of range blocks
+    for ( ; i != end && (list_read == list_end || i->second+1 < list_read[0]); ++i) {
+        // If we haven't removed any range pairs, we don't have space to
+        // insert here.  Defer the insertion until later.
+      if (list_read == list_write) {
+        ++insert_count;
+      }
+      else {
+        if (adj) 
+          for (EntityHandle j = i->first; j <= i->second; ++j)
+            adj->add_adjacency( j, my_handle, false );
+
+        list_write[0] = i->first;
+        list_write[1] = i->second;
+        list_write += 2;
+      }
+    }
+    if (i == end)
+      break;
+    
+      // check if we need to prepend to the current range block
+    if (i->first >= list_read[0]) 
+      list_write[0] = list_read[0];
+    else {
+      if (adj)
+        for (EntityHandle h = i->first; h < list_read[0]; ++h)
+          adj->add_adjacency( h, my_handle, false );
+      list_write[0] = i->first;
+    }
+    list_write[1] = list_read[1];
+    list_read += 2;
+    
+      // discard any input blocks already in the set
+    for (; i != end && i->second <= list_write[1]; ++i);
+    if (i == end || i->first > list_write[1]+1) {
+      list_write += 2;
+      continue;
+    }
+    
+      // merge subsequent blocks in meshset
+    for (;list_read != list_end && list_read[0]+1 <= i->second; list_read += 2) {
+      if (adj)
+      	for (EntityHandle h = list_write[1]+1; h < list_read[0]; ++h)
+      	  adj->add_adjacency( h, my_handle, false );
+      list_write[1] = list_read[1];
+    }
+    
+      // check if we need to append to current meshset block
+    if (i->second > list_write[1]) {
+      if (adj)
+      	for (EntityHandle h = list_write[1]+1; h <= i->second; ++h)
+      	  adj->add_adjacency( h, my_handle, false );
+      list_write[1] = i->second;
+    }
+    
+    ++i;
+    list_write += 2;
+  }
+
+    // shuffle down entries to fill holes
+  if (list_read == list_write) 
+    list_read = list_write = list_end;
+  else while(list_read < list_end) {
+    list_write[0] = list_read[0];
+    list_write[1] = list_read[1];
+    list_read += 2;
+    list_write += 2;
+  }
+
+    // adjust allocated array size
+  const size_t occupied_size = list_write - list;
+  const size_t new_list_size = occupied_size + 2*insert_count;
+  list = resize_compact_list( count, clist, new_list_size );
+    // done?
+  if (!insert_count)
+    return MB_SUCCESS;
+
+    // Second pass: insert non-mergable range pairs
+    // All range pairs in the input are either completely disjoint from
+    // the ones in the mesh set and must be inserted or are entirely contained
+    // within range pair in the mesh set.
+  assert( begin != end ); // can't have items to insert if given empty input list
+  pair_iter_t ri = end; --ri;
+  list_write = list + new_list_size - 2;
+  list_read = list + occupied_size - 2;
+  for ( ; list_write >= list; list_write -= 2 ) {
+    if (list_read >= list) {
+      while (ri->first >= list_read[0] && ri->second <= list_read[1]) {
+        assert(ri != begin);
+        --ri;
+      }
+    
+      if (list_read[0] > ri->second) {
+        list_write[0] = list_read[0];
+        list_write[1] = list_read[1];
+        list_read -= 2;
+        continue;
+      }
+    }
+    
+    assert( insert_count > 0 );
+    if (adj) 
+      for (EntityHandle j = ri->first; j <= ri->second; ++j) 
+        adj->add_adjacency( j, my_handle, false );
+    list_write[0] = ri->first;
+    list_write[1] = ri->second;
+
+      // don't have reverse iterator, so check before decrement
+      // if insert_count isn't zero, must be more in range
+    if (0 == --insert_count) {
+      assert( list_read == list_write-2 );
+      break;
+    }
+    else {
+      --ri;
+    }
+  }
+
+  assert(!insert_count);
+  return MB_SUCCESS;
+}
+  
+template <typename pair_iter_t> inline ErrorCode
+range_tool<pair_iter_t>::ranged_remove_entities( MeshSet::Count& count, 
+                                                 MeshSet::CompactList& clist, 
+                                                 pair_iter_t begin, 
+                                                 pair_iter_t end, 
+                                                 EntityHandle my_handle, 
+                                                 AEntityFactory* adj )
+{
+    //first pass:
+    // 1) remove (from) existing ranges 
+    // 2) count number of ranges that must be split
+  ptrdiff_t split_count = 0;
+  EntityHandle *list;
+  size_t list_size;
+  if (count < MeshSet::MANY) {
+    list = clist.hnd;
+    list_size = count;
+  }
+  else {
+    list = clist.ptr[0];
+    list_size = clist.ptr[1] - clist.ptr[0];
+  }
+
+  EntityHandle* list_write = list;
+  EntityHandle *const list_end = list + list_size, *list_read = list;
+  pair_iter_t i = begin;
+  
+  while(list_read != list_end && i != end) {
+    
+    while (i != end && i->second < list_read[0])
+      ++i;
+    if (i == end)
+      break;
+    
+      // if there are holes in the current array, shuffle blocks 
+      // down until we find the next block to remove
+    if (list_read != list_write) {
+      while (list_read != list_end && i->second < list_read[0]) {
+      	list_write[0] = list_read[0];
+        list_write[1] = list_read[1];
+        list_write += 2;
+        list_read += 2;
+      }
+    }
+      // otherwise do a binary search
+    else {
+      list_write = std::lower_bound( list_write, list_end, i->first );
+      	// if in middle of range block (odd index), back up to start of block
+      list_write -= (list_write - list)%2;
+      list_read = list_write;
+    }
+    
+      // if everything remaning is past end of set contents...
+    if (list_read == list_end) 
+      break;
+      
+      // skip any remove pairs that aren't in the list
+    if (i->second < list_read[0]) {
+      ++i;
+      continue;
+    }
+    
+      // Begin by assuming that we will keep the entire block
+    list_write[0] = list_read[0];
+    list_write[1] = list_read[1];
+    list_read += 2;
+    
+    for (; i != end && i->first <= list_write[1]; ++i) {
+      if (i->first <= list_write[0]) {
+          // remove whole block
+        if (i->second >= list_write[1]) {
+          if (adj)
+            for (EntityHandle h = list_write[0]; h <= list_write[1]; ++h)
+              adj->remove_adjacency( h, my_handle );
+          list_write -= 2;
+          break;
+        }
+          // remove from start of block
+        else if (i->second >= list_write[0]) {
+          if (adj)
+            for (EntityHandle h = list_write[0]; h <= i->second; ++h)
+              adj->remove_adjacency( h, my_handle );
+          list_write[0] = i->second + 1;
+        }
+      }
+      else if (i->first <= list_write[1]) {
+          // remove from end of block
+        if (i->second >= list_write[1]) {
+          if (adj)
+            for (EntityHandle h = i->first; h <= list_write[1]; ++h)
+              adj->remove_adjacency( h, my_handle );
+          list_write[1] = i->first - 1;
+          //list_write += 2;
+          break;
+        }
+          // split block
+        else {
+          if (adj)
+            for (EntityHandle h = i->first; h <= i->second; ++h)
+              adj->remove_adjacency( h, my_handle );
+
+          if (list_read - list_write <= 2) {
+            ++split_count;
+            continue;
+          }
+          else {
+            list_write[3] = list_write[1];
+            list_write[1] = i->first - 1;
+            list_write[2] = i->second + 1;
+            list_write += 2;
+          }
+        }
+      }
+    }
+    list_write += 2;
+  }
+
+    // shuffle down entries to fill holes
+  if (list_read == list_write) 
+    list_read = list_write = list_end;
+  else 
+    while(list_read < list_end) {
+      list_write[0] = list_read[0];
+      list_write[1] = list_read[1];
+      list_read += 2;
+      list_write += 2;
+    }
+
+    // adjust allocated array size
+  const size_t occupied_size = list_write - list;
+  const size_t new_list_size = occupied_size + 2*split_count;
+  list = resize_compact_list( count, clist, new_list_size );
+    // done?
+  if (!split_count)
+    return MB_SUCCESS;
+
+    // Second pass: split range pairs
+    // All range pairs in the input are either already removed or
+    // require one of the existing range pairs to be split
+  assert( begin != end ); // can't have ranges to split if given empty input list
+  pair_iter_t ri = end; --ri;
+  list_write = list + new_list_size - 2;
+  list_read = list + occupied_size - 2;
+  for ( ; list_write >= list; list_write -= 2 ) {
+    if (list_read >= list) {
+      while (ri->second > list_read[1]) {
+        assert(ri != begin);
+        --ri;
+      }
+    
+      if (list_read[0] > ri->second) {
+        list_write[0] = list_read[0];
+        list_write[1] = list_read[1];
+        list_read -= 2;
+        continue;
+      }
+    }
+    
+    assert( split_count > 0 );
+    list_write[0] = ri->second + 1;
+    list_write[1] = list_read[1];
+    list_read[1] = ri->first - 1;
+
+      // don't have reverse iterator, so check before decrement
+      // if insert_count isn't zero, must be more in range
+    if (0 == --split_count) {
+      assert( list_read == list_write-2 );
+      break;
+    }
+    else {
+      --ri;
+    }
+  }
+
+  assert(!split_count);
+  return MB_SUCCESS;
+}
+
+
+template <typename pair_iter_t> inline ErrorCode
+range_tool<pair_iter_t>::vector_insert_entities( MeshSet::Count& count, 
+                                                 MeshSet::CompactList& clist, 
+                                                 pair_iter_t begin, 
+                                                 pair_iter_t end, 
+                                                 EntityHandle my_handle, 
+                                                 AEntityFactory* adj )
+{
+  const size_t init_size = count < MeshSet::MANY ? count : clist.ptr[1] - clist.ptr[0];
+  size_t add_size = 0;
+  for (pair_iter_t i = begin; i != end; ++i)
+    add_size += i->second - i->first + 1;
+  EntityHandle* list = resize_compact_list( count, clist, init_size + add_size );
+  EntityHandle* li = list + init_size;
+
+  for (pair_iter_t i = begin; i != end; ++i) {
+    for (EntityHandle h = i->first; h <= i->second; ++h) {
+      if (adj)
+        adj->add_adjacency( h, my_handle, false );
+      *li = h;
+      ++li;
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+static ErrorCode vector_remove_range( MeshSet::Count& count, 
+                                        MeshSet::CompactList& clist, 
+                                        const Range& range, 
+                                        EntityHandle my_handle, 
+                                        AEntityFactory* adj )
+{
+  EntityHandle *list;
+  size_t list_size;
+  if (count < MeshSet::MANY) {
+    list = clist.hnd;
+    list_size = count;
+  }
+  else {
+    list = clist.ptr[0];
+    list_size = clist.ptr[1] - clist.ptr[0];
+  }
+
+  const EntityHandle * const list_end = list + list_size;
+  EntityHandle* list_write = list;
+  for (const EntityHandle* list_read = list; list_read != list_end; ++list_read) {
+    if (range.find(*list_read) == range.end()) { // keep
+      *list_write = *list_read;
+      ++list_write;
+    }
+    else if (adj) {    
+      adj->remove_adjacency( *list_read, my_handle );
+    }
+  }
+
+  resize_compact_list( count, clist, list_write - list );
+  return MB_SUCCESS;
+}
+
+static ErrorCode vector_remove_ranges( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* pair_list,
+                                         size_t num_pairs,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj )
+{
+  EntityHandle *list;
+  size_t list_size;
+  if (count < MeshSet::MANY) {
+    list = clist.hnd;
+    list_size = count;
+  }
+  else {
+    list = clist.ptr[0];
+    list_size = clist.ptr[1] - clist.ptr[0];
+  }
+
+  const EntityHandle *const list_end = list + list_size, 
+                       *const input_end = pair_list + 2*num_pairs;
+  EntityHandle* list_write = list;
+  for (const EntityHandle* list_read = list; list_read != list_end; ++list_read) {
+    const EntityHandle* ptr = std::lower_bound( pair_list, input_end, *list_read );
+    if ((ptr != input_end && (*ptr == *list_read || (ptr - pair_list)%2)) && // if in delete list
+        std::find(list_read+1, list_end, *list_read) == list_end) { // and is last occurance in list 
+        // only remove adj if no previous occurance
+      if (adj && std::find(list, list_write, *list_read) == list_write)
+        adj->remove_adjacency( *list_read, my_handle );
+    }
+    else {
+      *list_write = *list_read;
+      ++list_write;
+    }
+  }
+
+  resize_compact_list( count, clist, list_write - list );
+  return MB_SUCCESS;
+}
+
+static ErrorCode vector_remove_vector( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* vect,
+                                         size_t vect_size,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj )
+{
+  EntityHandle *list;
+  size_t list_size;
+  if (count < MeshSet::MANY) {
+    list = clist.hnd;
+    list_size = count;
+  }
+  else {
+    list = clist.ptr[0];
+    list_size = clist.ptr[1] - clist.ptr[0];
+  }
+
+  const EntityHandle *const list_end = list + list_size, 
+                       *const input_end = vect + vect_size;
+  EntityHandle* list_write = list;
+  for (const EntityHandle* list_read = list; list_read != list_end; ++list_read) {
+    if (std::find(vect, input_end, *list_read) != input_end && // if in delete list
+        std::find(list_read+1, list_end, *list_read) == list_end) { // and is last occurance in list 
+        // only remove adj if no previous occurance?
+      if (adj ) // && std::find(list, list_write, *list_read) == list_write)
+        adj->remove_adjacency( *list_read, my_handle );
+    }
+    else {
+      *list_write = *list_read;
+      ++list_write;
+    }
+  }
+
+  resize_compact_list( count, clist, list_write - list );
+  return MB_SUCCESS;
+}
+
+static ErrorCode vector_insert_vector( MeshSet::Count& count, 
+                                         MeshSet::CompactList& clist, 
+                                         const EntityHandle* vect,
+                                         size_t vect_size,
+                                         EntityHandle my_handle, 
+                                         AEntityFactory* adj )
+{
+  const size_t orig_size = count < MeshSet::MANY ? count : clist.ptr[1] - clist.ptr[0];
+  EntityHandle* list = resize_compact_list( count, clist, orig_size + vect_size );
+  if (adj) 
+    for (size_t i = 0; i < vect_size; ++i)
+      adj->add_adjacency( vect[i], my_handle, false );
+  memcpy( list+orig_size, vect, sizeof(EntityHandle)*vect_size );
+  return MB_SUCCESS;
+}
+
+ErrorCode MeshSet::insert_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj )
+{
+  typedef const std::pair<EntityHandle,EntityHandle>* pair_vect_t;
+  pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(range_vect);
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  ErrorCode rval;
+  if (!vector_based())
+    rval = range_tool<pair_vect_t>::ranged_insert_entities( count, contentList,  pair_vect, 
+                                             pair_vect + len/2, my_h, tracking() ? adj : 0 );
+  else
+    rval = range_tool<pair_vect_t>::vector_insert_entities( count, contentList,  pair_vect, 
+                                             pair_vect + len/2, my_h, tracking() ? adj : 0 );
+  mContentCount = count;
+  return rval;
+}
+
+ErrorCode MeshSet::insert_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj )
+{
+  ErrorCode rval;
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  if (!vector_based())
+    rval = range_tool<Range::const_pair_iterator>::ranged_insert_entities( count, 
+                             contentList, range.const_pair_begin(), range.const_pair_end(), 
+                             my_h, tracking() ? adj : 0 );
+  else
+    rval = range_tool<Range::const_pair_iterator>::vector_insert_entities( count, 
+                             contentList, range.const_pair_begin(), range.const_pair_end(), 
+                             my_h, tracking() ? adj : 0 );
+  mContentCount = count;
+  return rval;
+}
+
+ErrorCode MeshSet::remove_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj )
+{
+  ErrorCode rval;
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  if (vector_based()) 
+    rval = vector_remove_ranges( count, contentList, range_vect, len/2, my_h, 
+                                 tracking() ? adj : 0 );
+  else {
+    typedef const std::pair<EntityHandle,EntityHandle>* pair_vect_t;
+    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(range_vect);
+    rval = range_tool<pair_vect_t>::ranged_remove_entities( count, contentList, pair_vect, 
+                                           pair_vect + len/2, my_h, tracking() ? adj : 0 );
+  }
+  mContentCount = count;
+  return rval;
+}
+
+ErrorCode MeshSet::remove_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj )
+{
+  ErrorCode rval;
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  if (vector_based()) 
+    rval = vector_remove_range( count, contentList, range, my_h, tracking() ? adj : 0 );
+  else 
+    rval = range_tool<Range::const_pair_iterator>::ranged_remove_entities( count, 
+                         contentList, range.const_pair_begin(), range.const_pair_end(), 
+                         my_h, tracking() ? adj : 0 );
+  mContentCount = count;
+  return rval;
+}
+
+
+ErrorCode MeshSet::intersect( const MeshSet* other, EntityHandle my_handle, AEntityFactory* adj )
+{
+  ErrorCode rval;
+  if (!vector_based() && !other->vector_based()) {
+    size_t other_count = 0;
+    const EntityHandle* other_vect = other->get_contents( other_count );
+    if (!other_count)
+      return clear( my_handle, adj );
+    assert(0 == other_count%2);
+    
+    std::vector<EntityHandle> compliment;
+    compliment.reserve( other_count + 4 );
+    if (*other_vect > 0) {
+      compliment.push_back( 0 );
+      compliment.push_back( *other_vect - 1 );
+    }
+    ++other_vect;
+    const EntityHandle *const other_end = other_vect + other_count - 2;
+    for (; other_vect < other_end; other_vect += 2) {
+      compliment.push_back( other_vect[0] + 1 );
+      compliment.push_back( other_vect[1] - 1 );
+    }
+    if (*other_vect < ~(EntityHandle)0) {
+      compliment.push_back( *other_vect + 1 );
+      compliment.push_back( ~(EntityHandle)0 );
+    }
+    
+    return remove_entity_ranges( &compliment[0], compliment.size(), my_handle, adj );
+  }
+  else {
+    Range my_ents, other_ents;
+    rval = get_entities(my_ents);
+    if (MB_SUCCESS != rval)
+      return rval;
+    rval = other->get_entities(other_ents);
+    return remove_entities( moab::subtract(my_ents, other_ents), my_handle, adj );
+  }
+}
+
+static void convert_to_ranges( const EntityHandle* vect_in, size_t vect_in_len,
+                               std::vector<EntityHandle>& vect_out )
+{
+  vect_out.reserve( 2*vect_in_len );
+  vect_out.resize( vect_in_len );
+  std::copy( vect_in, vect_in+vect_in_len, vect_out.begin() );
+  std::sort( vect_out.begin(), vect_out.end() );
+  vect_out.erase( std::unique( vect_out.begin(), vect_out.end() ), vect_out.end() );
+
+    // duplicate all entries
+  vect_out.resize( vect_out.size() * 2 );
+  for (long i = vect_out.size() - 1; i >= 0; --i) 
+    vect_out[i] = vect_out[i/2];
+   
+    // compact adjacent ranges
+  std::vector<EntityHandle>::iterator r = vect_out.begin(), w = vect_out.begin();
+  while (r != vect_out.end()) {
+    *w = *r;
+    ++w; 
+    ++r;
+    *w = *r;
+    ++r;
+    
+    while (r != vect_out.end() && *w + 1 == *r) {
+      ++r;
+      *w = *r;
+      ++r;
+    }
+    ++w;
+  }
+  
+    // remove extra space
+  vect_out.erase( w, vect_out.end() );
+}
+
+ErrorCode MeshSet::insert_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj )
+{
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  ErrorCode rval;
+  if (vector_based())
+    rval = vector_insert_vector( count, contentList, vect, len, my_h, tracking() ? adj : 0 );
+  else {
+    std::vector<EntityHandle> rangevect;
+    convert_to_ranges( vect, len, rangevect );
+    typedef const std::pair<EntityHandle,EntityHandle>* pair_vect_t;
+    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(&rangevect[0]);
+    rval = range_tool<pair_vect_t>::ranged_insert_entities( count, contentList, pair_vect, 
+                                 pair_vect + rangevect.size()/2, my_h, tracking() ? adj : 0 );
+  }
+  mContentCount = count;
+  return rval;
+}
+
+ErrorCode MeshSet::remove_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj )
+{
+  MeshSet::Count count = static_cast<MeshSet::Count>(mContentCount);
+  ErrorCode rval;
+  if (vector_based())
+    rval = vector_remove_vector( count, contentList, vect, len, my_h, tracking() ? adj : 0 );
+  else {
+    std::vector<EntityHandle> rangevect;
+    convert_to_ranges( vect, len, rangevect );
+    typedef const std::pair<EntityHandle,EntityHandle>* pair_vect_t;
+    pair_vect_t pair_vect = reinterpret_cast<pair_vect_t>(&rangevect[0]);
+    rval = range_tool<pair_vect_t>::ranged_remove_entities( count, contentList, pair_vect, 
+                                pair_vect + rangevect.size()/2, my_h, tracking() ? adj : 0 );
+  }
+  mContentCount = count;
+  return rval;
+}
+
+
+
+ErrorCode MeshSet::replace_entities( EntityHandle my_handle,
+                                         const EntityHandle* old_entities,
+                                         const EntityHandle* new_entities,
+                                         size_t num_entities,
+                                         AEntityFactory* adjfact )
+{
+  if (vector_based()) {
+    ErrorCode result = MB_SUCCESS;
+    size_t count;
+    EntityHandle* vect = get_contents( count );
+    EntityHandle* const vect_end = vect+count;
+    for (size_t i = 0; i < num_entities; ++i) {
+      EntityHandle* p = std::find( vect, vect_end, old_entities[i] );
+      if (p == vect_end) {
+        result = MB_ENTITY_NOT_FOUND;
+      }
+      else do {
+        if (tracking()) {
+          adjfact->remove_adjacency( *p, my_handle );
+          adjfact->add_adjacency( new_entities[i], my_handle, false );
+        }
+        *p = new_entities[i];
+        p = std::find( p+1, vect_end, old_entities[i] );
+      } while (p != vect_end);
+    }
+    return result;
+  }
+  else {
+    ErrorCode r1 = remove_entities( old_entities, num_entities, my_handle, adjfact );
+    ErrorCode r2 = add_entities( new_entities, num_entities, my_handle, adjfact );
+    return (MB_SUCCESS == r2) ? r1 : r2;
+  }
+}
+
+
+/*****************************************************************************************
+ *                                  Misc. Methods                                        *
+ *****************************************************************************************/
+
+unsigned long MeshSet::get_memory_use() const
+{
+  unsigned long result = 0;
+  if (mParentCount == MANY)
+    result += parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
+  if (mChildCount == MANY)
+    result += childMeshSets.ptr[1] - childMeshSets.ptr[0];
+  if (mContentCount == MANY)
+    result += contentList.ptr[1] - contentList.ptr[0];
+  return sizeof(EntityHandle)*result;
+}
+  
+} // namespace moab

Copied: MOAB/trunk/src/MeshSet.hpp (from rev 3583, MOAB/trunk/src/MBMeshSet.hpp)
===================================================================
--- MOAB/trunk/src/MeshSet.hpp	                        (rev 0)
+++ MOAB/trunk/src/MeshSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,799 @@
+#ifndef MB_MESHSET_HPP
+#define MB_MESHSET_HPP
+
+#ifndef IS_BUILDING_MB
+#error "MB_MeshSet.hpp isn't supposed to be included into an application"
+#endif
+
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+
+#include <assert.h>
+#include <vector>
+#include <algorithm>
+#include <iterator>
+
+namespace moab {
+
+class AEntityFactory;
+
+/** \brief Class to implement entity set functionality 
+  * \author Jason Kraftcheck <kraftche at cae.wisc.edu>
+  */
+class MeshSet
+{
+public:
+
+  //! create an empty meshset
+  inline MeshSet();
+  inline MeshSet(unsigned flags);
+
+  //! destructor
+  inline ~MeshSet();
+  
+  inline ErrorCode set_flags( unsigned flags, EntityHandle my_handle, AEntityFactory* adjacencies );
+    
+
+    //! get all children pointed to by this meshset
+  inline const EntityHandle* get_children( int& count_out ) const ;
+
+    //! get all parents pointed to by this meshset
+  inline const EntityHandle* get_parents( int& count_out ) const;
+
+    //! return the number of children pointed to by this meshset
+  inline int num_children() const ;
+    
+    //! return the number of parents pointed to by this meshset
+  inline int num_parents() const;
+
+    //! add a parent to this meshset; returns true if parent was added, 0 if it was
+    //! already a parent of this meshset
+  int add_parent(EntityHandle parent);
+    
+    //! add a child to this meshset; returns true if child was added, 0 if it was
+    //! already a child of this meshset
+  int add_child(EntityHandle child);
+    
+    //! remove a parent from this meshset; returns true if parent was removed, 0 if it was
+    //! not a parent of this meshset
+  int remove_parent(EntityHandle parent);
+    
+    //! remove a child from this meshset; returns true if child was removed, 0 if it was
+    //! not a child of this meshset
+  int remove_child(EntityHandle child);
+
+  unsigned flags() const { return mFlags; }
+  //! returns whether entities of meshsets know this meshset 
+  int tracking()     const { return mFlags & MESHSET_TRACK_OWNER; }
+  int set()          const { return mFlags & MESHSET_SET; }
+  int ordered()      const { return mFlags & MESHSET_ORDERED; }
+  int vector_based() const { return ordered(); }
+
+    //! replace one entity with another in the set (contents and parent/child
+    //! lists); returns whether it was replaced or not
+  ErrorCode replace_entities(EntityHandle my_handle, 
+                               const EntityHandle *old_entities, 
+                               const EntityHandle *new_entities,
+                               size_t num_entities,
+                               AEntityFactory* mAdjFact);
+  
+    /** Clear *contents* of set (not parents or children) */
+  inline ErrorCode clear( EntityHandle myhandle, AEntityFactory* adjacencies );
+  
+    /** Clear all set lists (contents, parents, and children) */
+  inline ErrorCode clear_all( EntityHandle myhandle, AEntityFactory* adjacencies );
+
+    /** Get contents data array.  NOTE: this may not contain what you expect if not vector_based */
+  inline const EntityHandle* get_contents( size_t& count_out ) const;
+    /** Get contents data array.  NOTE: this may not contain what you expect if not vector_based */
+  inline EntityHandle* get_contents( size_t& count_out );
+
+    /** Get entities contained in set */
+  inline ErrorCode get_entities(std::vector<EntityHandle>& entities) const;
+
+    /** Get entities contained in set */
+  inline ErrorCode get_entities( Range& entities ) const;
+  
+    //! get all entities in this MeshSet with the specified type
+  inline ErrorCode get_entities_by_type(EntityType entity_type, std::vector<EntityHandle> &entity_list) const;
+  
+  inline ErrorCode get_entities_by_type( EntityType type, Range& entity_list) const;
+    
+    //! return the number of entities with the given type contained in this meshset
+  inline unsigned int num_entities_by_type(EntityType type) const;
+      
+  inline ErrorCode get_entities_by_dimension( int dimension, std::vector<EntityHandle> &entity_list) const;
+
+  inline ErrorCode get_entities_by_dimension( int dimension, Range& entity_list) const;
+  
+    //! return the number of entities with the given type contained in this meshset
+  inline unsigned int num_entities_by_dimension(int dimension) const;
+      
+  inline ErrorCode get_non_set_entities( Range& range ) const;
+
+  /** Test of meshset contains some or all of passed entities
+   *
+   *\param entities Array of entities
+   *\param num_entities Length of array of entities.
+   *\param op - Interface::UNION     : Test if set contains any of the input entities
+   *          - Interface::INTERSECT : Test if set contains all of the input entities
+   */
+  inline bool contains_entities(const EntityHandle *entities, int num_entities, const int op) const;
+
+  
+  //! subtract/intersect/unite meshset_2 from/with/into meshset_1; modifies meshset_1
+  inline ErrorCode subtract(const MeshSet *meshset_2,
+                               EntityHandle my_handle,
+                               AEntityFactory* adjacencies);
+
+  ErrorCode intersect(const MeshSet *meshset_2,
+                                EntityHandle my_handle,
+                                AEntityFactory* adjacencies);
+
+  inline ErrorCode unite(const MeshSet *meshset_2,
+                            EntityHandle my_handle,
+                            AEntityFactory* adjacencies);
+
+  //! add these entities to this meshset
+  inline ErrorCode add_entities(const EntityHandle *entity_handles,
+                                   const int num_entities,
+                                   EntityHandle my_handle,
+                                   AEntityFactory* adjacencies);
+    
+    //! add these entities to this meshset
+  inline ErrorCode add_entities(const Range &entities,
+                                   EntityHandle my_handle,
+                                   AEntityFactory* adjacencies);
+    
+    //! add these entities to this meshset
+  inline ErrorCode remove_entities(const Range& entities,
+                                      EntityHandle my_handle,
+                                      AEntityFactory* adjacencies);
+    
+   
+    //! remove these entities from this meshset
+  inline ErrorCode remove_entities(const EntityHandle *entities,
+                                      const int num_entities,
+                                      EntityHandle my_handle,
+                                      AEntityFactory* adjacencies);
+
+    //! return the number of entities contained in this meshset
+  inline unsigned int num_entities() const;
+  
+  inline bool empty() const { return mContentCount == ZERO; }
+  
+  unsigned long get_memory_use() const;
+
+protected:
+  
+  /** Convert for changing flag values */
+  ErrorCode convert( unsigned flags, EntityHandle my_handle, AEntityFactory* adj );
+
+  /** Add explicit adjacencies from all contained entities to this (i.e. convert to tracking) */
+  ErrorCode create_adjacencies( EntityHandle myhandle, AEntityFactory* adjacencies );
+
+  /** Remvoe explicit adjacencies from all contained entities to this (i.e. convert from tracking) */
+  ErrorCode remove_adjacencies( EntityHandle myhandle, AEntityFactory* adjacencies );
+
+  /** Insert vector of handles into MeshSet */
+  ErrorCode insert_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
+ 
+  /** Insert vector of handle range pairs into MeshSet */
+  ErrorCode insert_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
+
+  /** Insert Range of handles into MeshSet */
+  ErrorCode insert_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj );
+
+  /** Remove vector of handles from MeshSet */
+  ErrorCode remove_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
+
+  /** Remove vector of handle range pairs from MeshSet */
+  ErrorCode remove_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
+
+  /** Remove Range of handles from MeshSet */
+  ErrorCode remove_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj );
+
+public:  
+    //! Possible values of mParentCount and mChildCount
+  enum Count { ZERO=0, ONE=1, TWO=2, MANY=3 };
+    //! If the number of entities is less than 3, store
+    //! the handles directly in the hnd member.  Otherwise
+    //! use the ptr member to hold the beginning and end
+    //! of a dynamically allocated array.
+  union CompactList {
+    EntityHandle hnd[2];  //!< Two handles
+    EntityHandle* ptr[2]; //!< begin and end pointers for array
+  };
+
+private:
+  //!Meshset propery flags
+  unsigned char mFlags;
+  //! If less than MANY, the number of parents stored inline in
+  //! parentMeshSets.hnd.  If MANY, then parentMeshSets.ptr contains
+  //! array begin and end pointers for a dynamically allocated array
+  //! of parent handles.
+  unsigned mParentCount : 2;
+  //! If less than MANY, the number of children stored inline in
+  //! childMeshSets.hnd.  If MANY, then childMeshSets.ptr contains
+  //! array begin and end pointers for a dynamically allocated array
+  //! of child handles.
+  unsigned mChildCount : 2;
+  //! If less than MANY, the number of children stored inline in
+  //! contentList.hnd.  If MANY, then contentList.ptr contains
+  //! array begin and end pointers for a dynamically allocated array..
+  unsigned mContentCount : 2;
+  //! Storage for data lists
+  CompactList parentMeshSets, childMeshSets, contentList;
+
+public:
+    /** get dimension of enity */
+  static inline int DIM_FROM_HANDLE( EntityHandle h )
+    { return MBCN::Dimension( TYPE_FROM_HANDLE( h ) ); }
+  
+    /** Get smallest possible handle with specified dimension (first handle for first type of dimension) */
+  static inline EntityHandle FIRST_OF_DIM( int dim )
+    { return FIRST_HANDLE( MBCN::TypeDimensionMap[dim].first ); }
+  
+    /** Get largest possible handle with specified dimension (largest handle for last type of dimension) */
+  static inline EntityHandle LAST_OF_DIM( int dim )
+    { return LAST_HANDLE( MBCN::TypeDimensionMap[dim].second ); }
+
+    /** functor: test if handle is not of type */
+  struct not_type_test {
+      inline not_type_test( EntityType type ) : mType(type) {}
+      inline bool operator()( EntityHandle handle )
+        { return TYPE_FROM_HANDLE(handle) != mType; }
+      EntityType mType;
+  };
+
+    /** functor: test if handle is of type */
+  struct type_test {
+      inline type_test( EntityType type ) : mType(type) {}
+      inline bool operator()( EntityHandle handle )
+        { return TYPE_FROM_HANDLE(handle) == mType; }
+      EntityType mType;
+  };
+
+    /** functor: test if handle is not of dimension */
+  struct not_dim_test {
+      inline not_dim_test( int dimension ) : mDim(dimension) {}
+      inline bool operator()( EntityHandle handle ) const
+        { return DIM_FROM_HANDLE(handle) != mDim; }
+      int mDim;
+  };
+
+    /** functor: test if handle is of dimension */
+  struct dim_test {
+      inline dim_test( int dimension ) : mDim(dimension) {}
+      inline bool operator()( EntityHandle handle ) const
+        { return DIM_FROM_HANDLE(handle) == mDim; }
+      int mDim;
+  };
+  
+    /** Iterate over range of handles.  That is, given [first_handle,last_handle],
+     *  step through all contained values.
+     */
+  struct hdl_iter {
+    EntityHandle h;
+    hdl_iter( EntityHandle val ) : h(val) {}
+    hdl_iter& operator++() { ++h; return *this; }
+    hdl_iter& operator--() { --h; return *this; }
+    hdl_iter operator++(int) { return hdl_iter(h++); }
+    hdl_iter operator--(int) { return hdl_iter(h--); }
+    hdl_iter& operator+=(size_t s) { h += s; return *this; }
+    hdl_iter& operator-=(size_t s) { h -= s; return *this; }
+    EntityHandle operator*() const { return h; }
+    bool operator==(hdl_iter other) const { return h == other.h; }
+    bool operator!=(hdl_iter other) const { return h != other.h; }
+    bool operator< (hdl_iter other) const { return h <  other.h; }
+    bool operator> (hdl_iter other) const { return h >  other.h; }
+    bool operator<=(hdl_iter other) const { return h <= other.h; }
+    bool operator>=(hdl_iter other) const { return h >= other.h; }
+    
+    struct iterator_category : public std::random_access_iterator_tag { };
+    typedef EntityID difference_type;
+    typedef EntityHandle value_type;
+    typedef EntityHandle* pointer;
+    typedef EntityHandle& reference;
+  };
+  
+};
+
+inline MeshSet::hdl_iter::difference_type
+ operator-( const MeshSet::hdl_iter a, const MeshSet::hdl_iter b )
+  { return (MeshSet::hdl_iter::difference_type)a.h 
+         - (MeshSet::hdl_iter::difference_type)b.h; }
+
+
+  //! create an empty meshset
+MeshSet::MeshSet()
+  : mFlags(0), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
+{ }
+
+  //! create an empty meshset
+MeshSet::MeshSet(unsigned flags)
+  : mFlags(flags), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
+{ }
+
+  //! destructor
+MeshSet::~MeshSet() 
+{
+  if (mChildCount == MANY)
+    free( childMeshSets.ptr[0] );
+  if (mParentCount == MANY)
+    free( parentMeshSets.ptr[0] );
+  if (mContentCount == MANY)
+    free( contentList.ptr[0] );
+  mChildCount = mParentCount = mContentCount = ZERO;
+}
+  
+ErrorCode MeshSet::set_flags( unsigned flags, EntityHandle my_handle, AEntityFactory* adjacencies ) 
+{
+  if(ZERO != mContentCount) {
+    ErrorCode result = convert(flags, my_handle, adjacencies);
+    if(MB_SUCCESS != result) return result;
+  }
+  mFlags = flags;
+  return MB_SUCCESS;
+}
+    
+
+//! get all children pointed to by this meshset
+const EntityHandle* MeshSet::get_children( int& count_out ) const 
+{ 
+  count_out = mChildCount;
+  if (count_out < MANY)
+    return childMeshSets.hnd;
+
+  count_out = childMeshSets.ptr[1] - childMeshSets.ptr[0];
+  return childMeshSets.ptr[0];
+}
+
+//! get all parents pointed to by this meshset
+const EntityHandle* MeshSet::get_parents( int& count_out ) const
+{ 
+  count_out = mParentCount;
+  if (count_out < MANY)
+    return parentMeshSets.hnd;
+
+  count_out = parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
+  return parentMeshSets.ptr[0];
+}
+
+//! return the number of children pointed to by this meshset
+int MeshSet::num_children() const 
+{
+  if (mChildCount < MANY)
+    return mChildCount;
+  else
+    return childMeshSets.ptr[1] - childMeshSets.ptr[0];
+}
+
+//! return the number of parents pointed to by this meshset
+int MeshSet::num_parents() const
+{
+  if (mParentCount < MANY)
+    return mParentCount;
+  else
+    return parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
+}
+  
+inline ErrorCode MeshSet::clear( EntityHandle myhandle, AEntityFactory* adjacencies )
+{ 
+  if (tracking())
+    remove_adjacencies( myhandle, adjacencies );
+  if (mContentCount == MANY)
+    free( contentList.ptr[0] );
+  mContentCount = ZERO;
+  return MB_SUCCESS;
+}
+  
+inline ErrorCode MeshSet::clear_all( EntityHandle myhandle, AEntityFactory* adjacencies )
+{ 
+  ErrorCode rval = clear( myhandle, adjacencies );
+  if (mChildCount == MANY)
+    free( childMeshSets.ptr[0] );
+  mChildCount = ZERO;
+  if (mParentCount == MANY)
+    free( parentMeshSets.ptr[0] );
+  mParentCount = ZERO;
+  return rval;
+}
+
+inline const EntityHandle* MeshSet::get_contents( size_t& count_out ) const
+{
+  if (mContentCount == MANY) {
+    count_out = contentList.ptr[1] - contentList.ptr[0];
+    return contentList.ptr[0];
+  }
+  else {
+    count_out = mContentCount;
+    return contentList.hnd;
+  }
+}
+
+inline EntityHandle* MeshSet::get_contents( size_t& count_out )
+{
+  if (mContentCount == MANY) {
+    count_out = contentList.ptr[1] - contentList.ptr[0];
+    return contentList.ptr[0];
+  }
+  else {
+    count_out = mContentCount;
+    return contentList.hnd;
+  }
+}
+
+inline ErrorCode MeshSet::get_entities(std::vector<EntityHandle>& entities) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    size_t old_size = entities.size();
+    entities.resize( count+old_size );
+    std::copy( ptr, ptr+count, entities.begin()+old_size );
+  }
+  else {
+    assert(count%2 == 0);
+    for (size_t i = 0; i < count; i += 2) 
+      std::copy( hdl_iter(ptr[i]), hdl_iter(ptr[i+1]+1), std::back_inserter(entities) );
+  }
+  return MB_SUCCESS;
+} 
+
+inline ErrorCode MeshSet::get_entities(Range& entities) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::copy( ptr, ptr+count, range_inserter(entities) );
+  }
+  else {
+    assert(count%2 == 0);
+    Range::iterator in = entities.begin();
+    for (size_t i = 0; i < count; i += 2) 
+      in = entities.insert( in, ptr[i], ptr[i+1] );
+  }
+  return MB_SUCCESS;
+} 
+
+
+  //! get all entities in this MeshSet with the specified type
+inline ErrorCode MeshSet::get_entities_by_type(EntityType type,
+                                                   std::vector<EntityHandle> &entity_list
+                                                   ) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::remove_copy_if( ptr, ptr+count, 
+                         std::back_inserter( entity_list ),
+                         not_type_test(type) );
+  }
+  else {
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
+    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
+      if (idx % 2) { // only part of first block is of type
+        std::copy( hdl_iter(FIRST_HANDLE(type)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
+          std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
+        else {
+          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
+            std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_HANDLE(type)), std::back_inserter( entity_list ) );
+          break;
+        }
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+
+inline ErrorCode MeshSet::get_entities_by_type( EntityType type,
+                                                    Range& entity_list) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::remove_copy_if( ptr, ptr+count, 
+                         range_inserter( entity_list ),
+                         not_type_test(type) );
+  }
+  else {
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
+    Range::iterator in = entity_list.begin();
+    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
+      if (idx % 2) { // only part of first block is of type
+        in = entity_list.insert( in, FIRST_HANDLE(type), ptr[idx] );
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
+          in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
+        else {
+          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
+            entity_list.insert( in, ptr[idx], LAST_HANDLE(type) );
+          break;
+        }
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+  //! return the number of entities with the given type contained in this meshset
+inline unsigned int MeshSet::num_entities_by_type(EntityType type) const
+{
+  unsigned int result;
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    #ifndef __SUNPRO_CC
+      result = std::count_if( ptr, ptr+count, type_test(type) );
+    #else
+      std::count_if( ptr, ptr+count, type_test(type), result );
+    #endif
+  }
+  else {
+    result = 0;
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
+    if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
+      if (idx % 2) { // only part of first block is of type
+        result += ptr[idx] - FIRST_HANDLE(type) + 1;
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
+          result += ptr[idx+1] - ptr[idx] + 1;
+        else {
+          if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
+            result += LAST_HANDLE(type) - ptr[idx] + 1;
+          break;
+        }
+      }
+    }
+  }
+
+  return result;
+}
+
+inline ErrorCode MeshSet::get_entities_by_dimension( int dimension,
+                                                         std::vector<EntityHandle> &entity_list
+                                                         ) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::remove_copy_if( ptr, ptr+count, 
+                         std::back_inserter( entity_list ),
+                         not_dim_test(dimension) );
+  }
+  else {
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
+    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
+      if (idx % 2) { // only part of first block is of type
+        std::copy( hdl_iter(FIRST_OF_DIM(dimension)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
+          std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
+        else {
+          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
+            std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_OF_DIM(dimension)), std::back_inserter( entity_list ) );
+          break;
+        }
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+
+inline ErrorCode MeshSet::get_entities_by_dimension( int dimension,
+                                                         Range& entity_list) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::remove_copy_if( ptr, ptr+count, 
+                         range_inserter( entity_list ),
+                         not_dim_test(dimension) );
+  }
+  else {
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
+    Range::iterator in = entity_list.begin();
+    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
+      if (idx % 2) { // only part of first block is of type
+        in = entity_list.insert( in, FIRST_OF_DIM(dimension), ptr[idx] );
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
+          in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
+        else {
+          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
+            entity_list.insert( in, ptr[idx], LAST_OF_DIM(dimension) );
+          break;
+        }
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+  //! return the number of entities with the given type contained in this meshset
+inline unsigned int MeshSet::num_entities_by_dimension(int dimension) const
+{
+  unsigned int result;
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    #ifndef __SUNPRO_CC
+      result = std::count_if( ptr, ptr+count, dim_test(dimension) );
+    #else
+      std::count_if( ptr, ptr+count, dim_test(dimension), result );
+    #endif
+  }
+  else {
+    result = 0;
+    size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
+    if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
+      if (idx % 2) { // only part of first block is of type
+        result += ptr[idx] - FIRST_OF_DIM(dimension) + 1;
+        ++idx;
+      }
+      for (; idx < count; idx += 2) {
+        if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
+          result += ptr[idx+1] - ptr[idx] + 1;
+        else {
+          if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
+            result += LAST_OF_DIM(dimension) - ptr[idx] + 1;
+          break;
+        }
+      }
+    }
+  }
+
+  return result;
+}
+
+inline ErrorCode MeshSet::get_non_set_entities( Range& range ) const
+{
+  size_t count;
+  const EntityHandle* ptr = get_contents( count );
+  if (vector_based()) {
+    std::remove_copy_if( ptr, ptr+count, 
+                         range_inserter( range ),
+                         type_test(MBENTITYSET) );
+  }
+  else {
+    Range::iterator in = range.begin();
+    for (size_t idx = 0; idx < count; idx += 2) {
+      if (TYPE_FROM_HANDLE(ptr[idx+1]) != MBENTITYSET)
+        in = range.insert( ptr[idx], ptr[idx+1] );
+      else {
+        if (TYPE_FROM_HANDLE(ptr[idx]) != MBENTITYSET)
+          range.insert( ptr[idx], LAST_HANDLE( MBENTITYSET - 1 ) );
+        break;
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+inline bool MeshSet::contains_entities(const EntityHandle *entities, 
+                                         int num_entities,
+                                         const int op) const
+{
+  size_t count;
+  const EntityHandle* const ptr = get_contents( count );
+  const EntityHandle* const end = ptr + count;
+  size_t found_count = 0;
+  if (vector_based()) {
+    for (int i = 0; i < num_entities; ++i)
+      if (std::find( ptr, end, entities[i] ) < end)
+        ++found_count; 
+  }
+  else {
+    assert(0 == count % 2);
+    for (int i = 0; i < num_entities; ++i) {
+      const unsigned long idx = std::lower_bound( ptr, end, entities[i] ) - ptr;
+      if (idx < count && (idx%2 != 0 || ptr[idx] == entities[i]))
+        ++found_count;
+    }
+  }
+
+  return found_count >= ((Interface::INTERSECT == op) ? (unsigned)num_entities : 1u);
+}
+
+
+
+//! subtract/intersect/unite meshset_2 from/with/into meshset_1; modifies meshset_1
+inline ErrorCode MeshSet::subtract(const MeshSet *meshset_2,
+                                       EntityHandle my_handle,
+                                       AEntityFactory* adjacencies)
+{
+  size_t count;
+  const EntityHandle* const ptr = meshset_2->get_contents( count );
+  if (meshset_2->vector_based()) 
+    return remove_entity_vector( ptr, count, my_handle, adjacencies );
+  else
+    return remove_entity_ranges( ptr, count, my_handle, adjacencies );
+}
+
+inline ErrorCode MeshSet::unite(const MeshSet *meshset_2,
+                                    EntityHandle my_handle,
+                                    AEntityFactory* adjacencies)
+{
+  size_t count;
+  const EntityHandle* const ptr = meshset_2->get_contents( count );
+  if (meshset_2->vector_based()) 
+    return insert_entity_vector( ptr, count, my_handle, adjacencies );
+  else
+    return insert_entity_ranges( ptr, count, my_handle, adjacencies );
+}
+
+//! add these entities to this meshset
+inline ErrorCode MeshSet::add_entities(const EntityHandle *entity_handles,
+                                           const int num_entities,
+                                           EntityHandle my_handle,
+                                           AEntityFactory* adjacencies)
+{
+  return insert_entity_vector( entity_handles, num_entities, my_handle, adjacencies );
+}
+
+  //! add these entities to this meshset
+inline ErrorCode MeshSet::add_entities(const Range &entities,
+                                           EntityHandle my_handle,
+                                           AEntityFactory* adjacencies)
+{
+  return insert_entity_ranges( entities, my_handle, adjacencies );
+}
+
+  //! add these entities to this meshset
+inline ErrorCode MeshSet::remove_entities(const Range& entities,
+                                              EntityHandle my_handle,
+                                              AEntityFactory* adjacencies)
+{
+  return remove_entity_ranges(  entities, my_handle, adjacencies );
+}
+
+
+  //! remove these entities from this meshset
+inline ErrorCode MeshSet::remove_entities(const EntityHandle *entities,
+                                              const int num_entities,
+                                              EntityHandle my_handle,
+                                              AEntityFactory* adjacencies)
+{
+  return remove_entity_vector( entities, num_entities, my_handle, adjacencies );
+}
+
+  //! return the number of entities contained in this meshset
+unsigned int MeshSet::num_entities() const
+{
+  size_t count;
+  const EntityHandle* list = get_contents( count );
+  if (vector_based())
+    return count;
+  
+  int result = 0;
+  const EntityHandle *const end = list + count;
+  for (; list < end; list += 2)
+    result += list[1] - list[0] + 1;
+  return result;
+}
+  
+} // namespace moab
+
+#endif

Modified: MOAB/trunk/src/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/src/MeshSetSequence.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MeshSetSequence.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,8 +21,10 @@
 #include "MeshSetSequence.hpp"
 #include "SequenceManager.hpp"
 
-MeshSetSequence::MeshSetSequence( MBEntityHandle start,
-                                  MBEntityID count,
+namespace moab {
+
+MeshSetSequence::MeshSetSequence( EntityHandle start,
+                                  EntityID count,
                                   const unsigned* flags,
                                   SequenceData* data )
   : EntitySequence( start, count, data )
@@ -30,8 +32,8 @@
   initialize( flags );
 }
 
-MeshSetSequence::MeshSetSequence( MBEntityHandle start,
-                                  MBEntityID count,
+MeshSetSequence::MeshSetSequence( EntityHandle start,
+                                  EntityID count,
                                   unsigned flags,
                                   SequenceData* data )
   : EntitySequence( start, count, data )
@@ -40,19 +42,19 @@
   initialize( &vect[0] );
 }
 
-MeshSetSequence::MeshSetSequence( MBEntityHandle start,
-                                  MBEntityID count,
+MeshSetSequence::MeshSetSequence( EntityHandle start,
+                                  EntityID count,
                                   const unsigned* flags,
-                                  MBEntityID data_size )
+                                  EntityID data_size )
   : EntitySequence( start, count, new SequenceData( 1, start, start+data_size-1) )
 {
   initialize( flags );
 }
 
-MeshSetSequence::MeshSetSequence( MBEntityHandle start,
-                                  MBEntityID count,
+MeshSetSequence::MeshSetSequence( EntityHandle start,
+                                  EntityID count,
                                   unsigned flags,
-                                  MBEntityID data_size )
+                                  EntityID data_size )
   : EntitySequence( start, count, new SequenceData( 1, start, start+data_size-1) )
 {
   std::vector<unsigned> vect( count, flags );
@@ -64,60 +66,60 @@
   if (!data()->get_sequence_data(0))
     data()->create_sequence_data( 0, SET_SIZE );
  
-  MBEntityID offset = start_handle() - data()->start_handle();
-  for (MBEntityID i = 0; i < size(); ++i)
+  EntityID offset = start_handle() - data()->start_handle();
+  for (EntityID i = 0; i < size(); ++i)
     allocate_set( flags[i], i+offset );
 }
 
 MeshSetSequence::~MeshSetSequence()
 {
-  MBEntityID offset = start_handle() - data()->start_handle();
-  MBEntityID count = size();
-  for (MBEntityID i = 0; i < count; ++i)
+  EntityID offset = start_handle() - data()->start_handle();
+  EntityID count = size();
+  for (EntityID i = 0; i < count; ++i)
     deallocate_set( i + offset );
 }
 
-EntitySequence* MeshSetSequence::split( MBEntityHandle here )
+EntitySequence* MeshSetSequence::split( EntityHandle here )
 {
   return new MeshSetSequence( *this, here );
 }
 
-MBErrorCode MeshSetSequence::pop_back( MBEntityID count )
+ErrorCode MeshSetSequence::pop_back( EntityID count )
 {
-  MBEntityID offset = end_handle() + 1 - count - data()->start_handle();
-  MBErrorCode rval = EntitySequence::pop_back(count);
+  EntityID offset = end_handle() + 1 - count - data()->start_handle();
+  ErrorCode rval = EntitySequence::pop_back(count);
   if (MB_SUCCESS == rval)
-    for (MBEntityID i = 0; i < count; ++i)
+    for (EntityID i = 0; i < count; ++i)
       deallocate_set( i + offset );
   return rval;
 }
 
-MBErrorCode MeshSetSequence::pop_front( MBEntityID count )
+ErrorCode MeshSetSequence::pop_front( EntityID count )
 {
-  MBEntityID offset = start_handle() - data()->start_handle();
-  MBErrorCode rval = EntitySequence::pop_front(count);
+  EntityID offset = start_handle() - data()->start_handle();
+  ErrorCode rval = EntitySequence::pop_front(count);
   if (MB_SUCCESS == rval)
-    for (MBEntityID i = 0; i < count; ++i)
+    for (EntityID i = 0; i < count; ++i)
       deallocate_set( i + offset );
   return rval;
 }
 
-MBErrorCode MeshSetSequence::push_back( MBEntityID count, const unsigned* flags )
+ErrorCode MeshSetSequence::push_back( EntityID count, const unsigned* flags )
 {
-  MBEntityID offset = end_handle() + 1 - data()->start_handle();
-  MBErrorCode rval = EntitySequence::append_entities( count );
+  EntityID offset = end_handle() + 1 - data()->start_handle();
+  ErrorCode rval = EntitySequence::append_entities( count );
   if (MB_SUCCESS == rval)
-    for (MBEntityID i = 0; i < count; ++i)
+    for (EntityID i = 0; i < count; ++i)
       allocate_set( flags[i], i + offset );
   return rval;
 }
 
-MBErrorCode MeshSetSequence::push_front( MBEntityID count, const unsigned* flags )
+ErrorCode MeshSetSequence::push_front( EntityID count, const unsigned* flags )
 {
-  MBEntityID offset = start_handle() - data()->start_handle() - count;
-  MBErrorCode rval = EntitySequence::prepend_entities( count );
+  EntityID offset = start_handle() - data()->start_handle() - count;
+  ErrorCode rval = EntitySequence::prepend_entities( count );
   if (MB_SUCCESS == rval)
-    for (MBEntityID i = 0; i < count; ++i)
+    for (EntityID i = 0; i < count; ++i)
       allocate_set( flags[i], i + offset );
   return rval;
 }
@@ -129,8 +131,8 @@
   seq_size = sizeof(*this);
 }
 
-unsigned long MeshSetSequence::get_per_entity_memory_use( MBEntityHandle first,
-                                                          MBEntityHandle last
+unsigned long MeshSetSequence::get_per_entity_memory_use( EntityHandle first,
+                                                          EntityHandle last
                                                         ) const
 {
   if (first < start_handle())
@@ -139,14 +141,14 @@
     last = end_handle();
   
   unsigned long sum = 0;
-  for (MBEntityHandle h = first; h <= last; ++h) 
+  for (EntityHandle h = first; h <= last; ++h) 
     sum += get_set(h)->get_memory_use();
   return sum;
 }
 
-MBErrorCode MeshSetSequence::get_entities( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
-                                           MBRange& entities,
+ErrorCode MeshSetSequence::get_entities( const SequenceManager* seqman,
+                                           EntityHandle handle,
+                                           Range& entities,
                                            bool recursive ) const
 {
   if (!recursive) {
@@ -154,25 +156,25 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
-    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    std::vector<const MeshSet*> list;
+    ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+    for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_non_set_entities( entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::get_entities( MBEntityHandle handle,
-                                std::vector<MBEntityHandle>& entities ) const
+ErrorCode MeshSetSequence::get_entities( EntityHandle handle,
+                                std::vector<EntityHandle>& entities ) const
 {
   get_set(handle)->get_entities( entities );
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshSetSequence::get_dimension( const SequenceManager* seqman,
-                                            MBEntityHandle handle,
+ErrorCode MeshSetSequence::get_dimension( const SequenceManager* seqman,
+                                            EntityHandle handle,
                                             int dimension,
-                                            std::vector<MBEntityHandle>& entities,
+                                            std::vector<EntityHandle>& entities,
                                             bool recursive ) const
 {
   if (!recursive) {
@@ -180,18 +182,18 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
-    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    std::vector<const MeshSet*> list;
+    ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+    for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_dimension( dimension, entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::get_dimension( const SequenceManager* seqman,
-                                            MBEntityHandle handle,
+ErrorCode MeshSetSequence::get_dimension( const SequenceManager* seqman,
+                                            EntityHandle handle,
                                             int dimension,
-                                            MBRange& entities,
+                                            Range& entities,
                                             bool recursive ) const
 {
   if (!recursive) {
@@ -199,18 +201,18 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
-    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    std::vector<const MeshSet*> list;
+    ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+    for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_dimension( dimension, entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
-                                       MBEntityHandle handle,
-                                       MBEntityType type,
-                                       std::vector<MBEntityHandle>& entities,
+ErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
+                                       EntityHandle handle,
+                                       EntityType type,
+                                       std::vector<EntityHandle>& entities,
                                        bool recursive ) const
 {
   if (!recursive) {
@@ -221,18 +223,18 @@
     return recursive_get_sets( handle, seqman, 0, 0, &entities );
   }
   else {
-    std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
-    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    std::vector<const MeshSet*> list;
+    ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+    for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_type( type, entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
-                                       MBEntityHandle handle,
-                                       MBEntityType type,
-                                       MBRange& entities,
+ErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
+                                       EntityHandle handle,
+                                       EntityType type,
+                                       Range& entities,
                                        bool recursive ) const
 {
   if (!recursive) {
@@ -243,16 +245,16 @@
     return recursive_get_sets( handle, seqman, 0, &entities );
   }
   else {
-    std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
-    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    std::vector<const MeshSet*> list;
+    ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+    for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_type( type, entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::num_entities( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
+ErrorCode MeshSetSequence::num_entities( const SequenceManager* seqman,
+                                           EntityHandle handle,
                                            int& number,
                                            bool recursive ) const
 {
@@ -261,15 +263,15 @@
     return MB_SUCCESS;
   }
   else {
-    MBRange range;
-    MBErrorCode result = get_entities( seqman, handle, range, true );
+    Range range;
+    ErrorCode result = get_entities( seqman, handle, range, true );
     number = range.size();
     return result;
   }
 }
 
-MBErrorCode MeshSetSequence::num_dimension( const SequenceManager* seqman,
-                                            MBEntityHandle handle,
+ErrorCode MeshSetSequence::num_dimension( const SequenceManager* seqman,
+                                            EntityHandle handle,
                                             int dimension,
                                             int& number,
                                             bool recursive ) const
@@ -279,16 +281,16 @@
     return MB_SUCCESS;
   }
   else {
-    MBRange range;
-    MBErrorCode result = get_dimension( seqman, handle, dimension, range, true );
+    Range range;
+    ErrorCode result = get_dimension( seqman, handle, dimension, range, true );
     number = range.size();
     return result;
   }
 }
  
-MBErrorCode MeshSetSequence::num_type( const SequenceManager* seqman,
-                                       MBEntityHandle handle,
-                                       MBEntityType type,
+ErrorCode MeshSetSequence::num_type( const SequenceManager* seqman,
+                                       EntityHandle handle,
+                                       EntityType type,
                                        int& number,
                                        bool recursive ) const
 {
@@ -297,25 +299,25 @@
     return MB_SUCCESS;
   }
   else {
-    MBRange range;
-    MBErrorCode result = get_type( seqman, handle, type, range, true );
+    Range range;
+    ErrorCode result = get_type( seqman, handle, type, range, true );
     number = range.size();
     return result;
   }
 }
 
-MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
+ErrorCode MeshSetSequence::recursive_get_sets( EntityHandle start_set,
                               const SequenceManager* seq_sets,
-                              std::vector<const MBMeshSet*>* sets,
-                              MBRange* set_handles,
-                              std::vector<MBEntityHandle>* set_vector )
+                              std::vector<const MeshSet*>* sets,
+                              Range* set_handles,
+                              std::vector<EntityHandle>* set_vector )
 {
-  std::set<MBEntityHandle> visited;
-  std::vector<MBEntityHandle> stack;
+  std::set<EntityHandle> visited;
+  std::vector<EntityHandle> stack;
   stack.push_back( start_set );
   bool remove_start_set = true;
   while (!stack.empty()) {
-    MBEntityHandle handle = stack.back();
+    EntityHandle handle = stack.back();
     stack.pop_back();
     
     if (!visited.insert(handle).second) {
@@ -325,16 +327,16 @@
     }
     
     const EntitySequence* seq;
-    MBErrorCode rval = seq_sets->find( handle, seq );
+    ErrorCode rval = seq_sets->find( handle, seq );
     if (MB_SUCCESS != rval)
       return rval;
     
     const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
-    const MBMeshSet *ms_ptr = mseq->get_set( handle );
+    const MeshSet *ms_ptr = mseq->get_set( handle );
     if (sets)
       sets->push_back( ms_ptr );
     
-    MBRange tmp_range;
+    Range tmp_range;
     ms_ptr->get_entities_by_type( MBENTITYSET, tmp_range );
     std::copy( tmp_range.begin(), tmp_range.end(), std::back_inserter( stack ) );
   }
@@ -342,8 +344,8 @@
   if (set_handles) {
     if (remove_start_set)
       visited.erase( start_set );
-    MBRange::iterator hint = set_handles->begin();
-    std::set<MBEntityHandle>::iterator it;
+    Range::iterator hint = set_handles->begin();
+    std::set<EntityHandle>::iterator it;
     for (it = visited.begin(); it != visited.end(); ++it)
       hint = set_handles->insert( hint, *it, *it );
   }
@@ -357,30 +359,30 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
+ErrorCode MeshSetSequence::recursive_get_sets( EntityHandle start_set,
                               SequenceManager* seq_sets,
-                              std::vector<MBMeshSet*>& sets )
+                              std::vector<MeshSet*>& sets )
 {
-  std::set<MBEntityHandle> visited;
-  std::vector<MBEntityHandle> stack;
+  std::set<EntityHandle> visited;
+  std::vector<EntityHandle> stack;
   stack.push_back( start_set );
   while (!stack.empty()) {
-    MBEntityHandle handle = stack.back();
+    EntityHandle handle = stack.back();
     stack.pop_back();
     
     if (!visited.insert(handle).second)
       continue;
     
     EntitySequence* seq;
-    MBErrorCode rval = seq_sets->find( handle, seq );
+    ErrorCode rval = seq_sets->find( handle, seq );
     if (MB_SUCCESS != rval)
       return rval;
     
     MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
-    MBMeshSet *ms_ptr = mseq->get_set( handle );
+    MeshSet *ms_ptr = mseq->get_set( handle );
     sets.push_back( ms_ptr );
     
-    MBRange tmp_range;
+    Range tmp_range;
     ms_ptr->get_entities_by_type( MBENTITYSET, tmp_range );
     std::copy( tmp_range.begin(), tmp_range.end(), std::back_inserter( stack ) );
   }
@@ -388,15 +390,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshSetSequence::get_parent_child_meshsets( MBEntityHandle meshset,
+ErrorCode MeshSetSequence::get_parent_child_meshsets( EntityHandle meshset,
                                     const SequenceManager* seq_sets,
-                                    std::vector<MBEntityHandle>& results,
+                                    std::vector<EntityHandle>& results,
                                     int num_hops, SearchType link_type ) const
 {
-  MBErrorCode result = MB_SUCCESS;
-  std::vector<MBEntityHandle>::iterator i;
-  const MBEntityHandle *array = 0, *end;
-  MBEntityHandle s, e;
+  ErrorCode result = MB_SUCCESS;
+  std::vector<EntityHandle>::iterator i;
+  const EntityHandle *array = 0, *end;
+  EntityHandle s, e;
   int count = 0;
   size_t n;
   
@@ -405,12 +407,12 @@
     // that we should.)  There is an exception to that if the
     // input meshset is in the list, which is handled by the order
     // of checks in the main loop below.
-  std::set<MBEntityHandle> visited;
+  std::set<EntityHandle> visited;
   for (i = results.begin(); i != results.end(); ++i)
     visited.insert( *i );
     
     // Two lists for breadth-first search
-  std::vector<MBEntityHandle> lists[2];
+  std::vector<EntityHandle> lists[2];
   int index = 0;  // which list to read from (write to lists[1-index])
   lists[index].push_back( meshset ); // begin with input set
     // loop for num_hops (or until no more sets)
@@ -419,10 +421,10 @@
     for (i = lists[index].begin(); i != lists[index].end(); ++i) {
         // get meshset from handle
       const EntitySequence* seq;
-      MBErrorCode rval = seq_sets->find( *i, seq );
+      ErrorCode rval = seq_sets->find( *i, seq );
       if (MB_SUCCESS != rval)
         return rval;
-      const MBMeshSet *ms_ptr = reinterpret_cast<const MeshSetSequence*>(seq)->get_set( *i );
+      const MeshSet *ms_ptr = reinterpret_cast<const MeshSetSequence*>(seq)->get_set( *i );
       
       
       switch (link_type) {
@@ -484,14 +486,14 @@
   return result;
 }
 
-MBErrorCode MeshSetSequence::get_parents( const SequenceManager* seqman,
-                                          MBEntityHandle handle,
-                                          std::vector<MBEntityHandle>& parents,
+ErrorCode MeshSetSequence::get_parents( const SequenceManager* seqman,
+                                          EntityHandle handle,
+                                          std::vector<EntityHandle>& parents,
                                           int num_hops ) const
 {
   if (num_hops == 1) {
     int count;
-    const MBEntityHandle* array = get_set( handle )->get_parents(count);  
+    const EntityHandle* array = get_set( handle )->get_parents(count);  
     if (parents.empty()) {
       parents.resize(count);
       std::copy( array, array + count, parents.begin() );
@@ -508,14 +510,14 @@
     return get_parent_child_meshsets( handle, seqman, parents, -1, PARENTS );
 }
 
-MBErrorCode MeshSetSequence::get_children( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
-                                           std::vector<MBEntityHandle>& children,
+ErrorCode MeshSetSequence::get_children( const SequenceManager* seqman,
+                                           EntityHandle handle,
+                                           std::vector<EntityHandle>& children,
                                            int num_hops ) const
 {
   if (num_hops == 1) {
     int count;
-    const MBEntityHandle* array = get_set( handle )->get_children(count);  
+    const EntityHandle* array = get_set( handle )->get_children(count);  
     if (children.empty()) {
       children.resize(count);
       std::copy( array, array + count, children.begin() );
@@ -532,9 +534,9 @@
     return get_parent_child_meshsets( handle, seqman, children, -1, CHILDREN );
 }
 
-MBErrorCode MeshSetSequence::get_contained_sets( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
-                                           std::vector<MBEntityHandle>& contained,
+ErrorCode MeshSetSequence::get_contained_sets( const SequenceManager* seqman,
+                                           EntityHandle handle,
+                                           std::vector<EntityHandle>& contained,
                                            int num_hops ) const
 {
   if (num_hops == 1 && contained.empty()) {
@@ -547,8 +549,8 @@
     return get_parent_child_meshsets( handle, seqman, contained, -1, CONTAINED );
 }
 
-MBErrorCode MeshSetSequence::num_parents( const SequenceManager* seqman,
-                                          MBEntityHandle handle,
+ErrorCode MeshSetSequence::num_parents( const SequenceManager* seqman,
+                                          EntityHandle handle,
                                           int& number,
                                           int num_hops ) const
 {
@@ -557,15 +559,15 @@
     return MB_SUCCESS;
   }
   
-  std::vector<MBEntityHandle> parents;
-  MBErrorCode result = get_parents( seqman, handle, parents, num_hops );
+  std::vector<EntityHandle> parents;
+  ErrorCode result = get_parents( seqman, handle, parents, num_hops );
   number = parents.size();
   return result;
 }
 
 
-MBErrorCode MeshSetSequence::num_children( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
+ErrorCode MeshSetSequence::num_children( const SequenceManager* seqman,
+                                           EntityHandle handle,
                                            int& number,
                                            int num_hops ) const
 {
@@ -574,14 +576,14 @@
     return MB_SUCCESS;
   }
   
-  std::vector<MBEntityHandle> children;
-  MBErrorCode result = get_children( seqman, handle, children, num_hops );
+  std::vector<EntityHandle> children;
+  ErrorCode result = get_children( seqman, handle, children, num_hops );
   number = children.size();
   return result;
 }
 
-MBErrorCode MeshSetSequence::num_contained_sets( const SequenceManager* seqman,
-                                           MBEntityHandle handle,
+ErrorCode MeshSetSequence::num_contained_sets( const SequenceManager* seqman,
+                                           EntityHandle handle,
                                            int& number,
                                            int num_hops ) const
 {
@@ -590,8 +592,10 @@
     return MB_SUCCESS;
   }
   
-  std::vector<MBEntityHandle> contained;
-  MBErrorCode result = get_contained_sets( seqman, handle, contained, num_hops );
+  std::vector<EntityHandle> contained;
+  ErrorCode result = get_contained_sets( seqman, handle, contained, num_hops );
   number = contained.size();
   return result;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/MeshSetSequence.hpp
===================================================================
--- MOAB/trunk/src/MeshSetSequence.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MeshSetSequence.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -22,99 +22,101 @@
 #define MESH_SET_SEQUENCE_HPP
 
 #include "EntitySequence.hpp"
-#include "MBMeshSet.hpp"
+#include "MeshSet.hpp"
 #include "SequenceData.hpp"
 
+namespace moab {
+
 class SequenceManager;
 
 class MeshSetSequence : public EntitySequence
 {
 public:
 
-  MeshSetSequence( MBEntityHandle start,
-                   MBEntityID count,
+  MeshSetSequence( EntityHandle start,
+                   EntityID count,
                    const unsigned* flags,
                    SequenceData* data );
   
-  MeshSetSequence( MBEntityHandle start,
-                   MBEntityID count,
+  MeshSetSequence( EntityHandle start,
+                   EntityID count,
                    unsigned flags,
                    SequenceData* data );
 
-  MeshSetSequence( MBEntityHandle start,
-                   MBEntityID count,
+  MeshSetSequence( EntityHandle start,
+                   EntityID count,
                    const unsigned* flags,
-                   MBEntityID sequence_size );
+                   EntityID sequence_size );
   
-  MeshSetSequence( MBEntityHandle start,
-                   MBEntityID count,
+  MeshSetSequence( EntityHandle start,
+                   EntityID count,
                    unsigned flags,
-                   MBEntityID sequence_size );
+                   EntityID sequence_size );
 
   virtual ~MeshSetSequence();
 
-  EntitySequence* split( MBEntityHandle here );
+  EntitySequence* split( EntityHandle here );
   
-  SequenceData* create_data_subset( MBEntityHandle, MBEntityHandle ) const
+  SequenceData* create_data_subset( EntityHandle, EntityHandle ) const
     { return 0; }
   
-  MBErrorCode pop_back( MBEntityID count );
-  MBErrorCode pop_front( MBEntityID count );
-  MBErrorCode push_back( MBEntityID count, const unsigned* flags );
-  MBErrorCode push_front( MBEntityID count, const unsigned* flags );
+  ErrorCode pop_back( EntityID count );
+  ErrorCode pop_front( EntityID count );
+  ErrorCode push_back( EntityID count, const unsigned* flags );
+  ErrorCode push_front( EntityID count, const unsigned* flags );
   
   void get_const_memory_use( unsigned long& bytes_per_entity,
                              unsigned long& size_of_sequence ) const;
-  unsigned long get_per_entity_memory_use( MBEntityHandle first,
-                                           MBEntityHandle last ) const;
+  unsigned long get_per_entity_memory_use( EntityHandle first,
+                                           EntityHandle last ) const;
 
 
-  inline MBMeshSet* get_set( MBEntityHandle h );
-  inline const MBMeshSet* get_set( MBEntityHandle h ) const;
+  inline MeshSet* get_set( EntityHandle h );
+  inline const MeshSet* get_set( EntityHandle h ) const;
   
-  MBErrorCode get_entities( MBEntityHandle set, std::vector<MBEntityHandle>& entities ) const;
-  MBErrorCode get_entities(  SequenceManager const* seqman, MBEntityHandle set,                    MBRange& entities, bool recursive ) const;
-  MBErrorCode get_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           std::vector<MBEntityHandle>& entities, bool recursive ) const;
-  MBErrorCode get_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           MBRange& entities, bool recursive ) const;
-  MBErrorCode get_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, std::vector<MBEntityHandle>& entities, bool recursive ) const;
-  MBErrorCode get_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, MBRange& entities, bool recursive ) const;
+  ErrorCode get_entities( EntityHandle set, std::vector<EntityHandle>& entities ) const;
+  ErrorCode get_entities(  SequenceManager const* seqman, EntityHandle set,                    Range& entities, bool recursive ) const;
+  ErrorCode get_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           std::vector<EntityHandle>& entities, bool recursive ) const;
+  ErrorCode get_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           Range& entities, bool recursive ) const;
+  ErrorCode get_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, std::vector<EntityHandle>& entities, bool recursive ) const;
+  ErrorCode get_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, Range& entities, bool recursive ) const;
   
-  MBErrorCode num_entities(  SequenceManager const* seqman, MBEntityHandle set,                    int& count, bool recursive ) const;
-  MBErrorCode num_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           int& count, bool recursive ) const;
-  MBErrorCode num_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, int& count, bool recursive ) const;
+  ErrorCode num_entities(  SequenceManager const* seqman, EntityHandle set,                    int& count, bool recursive ) const;
+  ErrorCode num_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           int& count, bool recursive ) const;
+  ErrorCode num_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, int& count, bool recursive ) const;
 
-  MBErrorCode get_parents       ( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& parents,  int num_hops ) const;
-  MBErrorCode get_children      ( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& children, int num_hops ) const;
-  MBErrorCode get_contained_sets( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& contents, int num_hops ) const;
-  MBErrorCode num_parents       ( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
-  MBErrorCode num_children      ( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
-  MBErrorCode num_contained_sets( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
+  ErrorCode get_parents       ( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& parents,  int num_hops ) const;
+  ErrorCode get_children      ( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& children, int num_hops ) const;
+  ErrorCode get_contained_sets( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& contents, int num_hops ) const;
+  ErrorCode num_parents       ( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
+  ErrorCode num_children      ( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
+  ErrorCode num_contained_sets( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
   
 private:
 
   enum SearchType { PARENTS, CHILDREN, CONTAINED };
 
-  MeshSetSequence( MeshSetSequence& split_from, MBEntityHandle split_at )
+  MeshSetSequence( MeshSetSequence& split_from, EntityHandle split_at )
     : EntitySequence( split_from, split_at )
     {}
 
   void initialize( const unsigned* set_flags );
   
-  MBErrorCode get_parent_child_meshsets( MBEntityHandle meshset,
+  ErrorCode get_parent_child_meshsets( EntityHandle meshset,
                                     SequenceManager const* set_sequences,
-                                    std::vector<MBEntityHandle>& results,
+                                    std::vector<EntityHandle>& results,
                                     int num_hops, SearchType link_type ) const;
                                     
-  static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
+  static ErrorCode recursive_get_sets( EntityHandle start_set,
                             SequenceManager const* set_sequences,
-                            std::vector<const MBMeshSet*>* sets_out = 0,
-                            MBRange* set_handles_out = 0,
-                            std::vector<MBEntityHandle>* set_handle_vect_out = 0 );
-  static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
+                            std::vector<const MeshSet*>* sets_out = 0,
+                            Range* set_handles_out = 0,
+                            std::vector<EntityHandle>* set_handle_vect_out = 0 );
+  static ErrorCode recursive_get_sets( EntityHandle start_set,
                             SequenceManager* set_sequences,
-                            std::vector<MBMeshSet*>& sets_out );
+                            std::vector<MeshSet*>& sets_out );
   
-  enum { SET_SIZE = sizeof(MBMeshSet) };
+  enum { SET_SIZE = sizeof(MeshSet) };
 
   inline const unsigned char* array() const
     { return reinterpret_cast<const unsigned char*>(data()->get_sequence_data(0)); }
@@ -122,26 +124,28 @@
   inline unsigned char* array()
     { return reinterpret_cast<unsigned char*>(data()->get_sequence_data(0)); }
     
-  inline void allocate_set( unsigned flags, MBEntityID index )
+  inline void allocate_set( unsigned flags, EntityID index )
   {
     unsigned char* const ptr = array() + index * SET_SIZE;
-    new (ptr) MBMeshSet(flags);
+    new (ptr) MeshSet(flags);
   }
     
-  inline void deallocate_set( MBEntityID index ) 
+  inline void deallocate_set( EntityID index ) 
   {
-    MBMeshSet* set = reinterpret_cast<MBMeshSet*>(array() + SET_SIZE * index );
-    set->~MBMeshSet();
+    MeshSet* set = reinterpret_cast<MeshSet*>(array() + SET_SIZE * index );
+    set->~MeshSet();
   }
 };
 
-inline MBMeshSet* MeshSetSequence::get_set( MBEntityHandle h )
+inline MeshSet* MeshSetSequence::get_set( EntityHandle h )
 {
-  return reinterpret_cast<MBMeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
+  return reinterpret_cast<MeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
 }
-inline const MBMeshSet* MeshSetSequence::get_set( MBEntityHandle h ) const
+inline const MeshSet* MeshSetSequence::get_set( EntityHandle h ) const
 {
-  return reinterpret_cast<const MBMeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
+  return reinterpret_cast<const MeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
 }
+  
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/MeshTopoUtil.cpp
===================================================================
--- MOAB/trunk/src/MeshTopoUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/MeshTopoUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -17,57 +17,59 @@
 #pragma warning (disable : 4786)
 #endif
 
-#include "MeshTopoUtil.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBCN.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBCN.hpp"
 
 #include <assert.h>
 
 #define RR {if (MB_SUCCESS != result) return result;}
 
+namespace moab {
+
     //! generate all the AEntities bounding the vertices
-MBErrorCode MeshTopoUtil::construct_aentities(const MBRange &vertices) 
+ErrorCode MeshTopoUtil::construct_aentities(const Range &vertices) 
 {
-  MBRange out_range;
-  MBErrorCode result;
-  result = mbImpl->get_adjacencies(vertices, 1, true, out_range, MBInterface::UNION);
+  Range out_range;
+  ErrorCode result;
+  result = mbImpl->get_adjacencies(vertices, 1, true, out_range, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   out_range.clear();
-  result = mbImpl->get_adjacencies(vertices, 2, true, out_range, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(vertices, 2, true, out_range, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   out_range.clear();
-  result = mbImpl->get_adjacencies(vertices, 3, true, out_range, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(vertices, 3, true, out_range, Interface::UNION);
 
   return result;
 }
 
 //! given an entity, get its average position (avg vertex locations)
-MBErrorCode MeshTopoUtil::get_average_position(MBRange &entities,
+ErrorCode MeshTopoUtil::get_average_position(Range &entities,
                                                double *avg_position) 
 {
-  std::vector<MBEntityHandle> ent_vec;
+  std::vector<EntityHandle> ent_vec;
   std::copy(entities.begin(), entities.end(), std::back_inserter(ent_vec));
   return get_average_position(&ent_vec[0], ent_vec.size(), avg_position);
 }
 
 //! given an entity, get its average position (avg vertex locations)
-MBErrorCode MeshTopoUtil::get_average_position(const MBEntityHandle *entities,
+ErrorCode MeshTopoUtil::get_average_position(const EntityHandle *entities,
                                                const int num_entities,
                                                double *avg_position) 
 {
   double dum_pos[3];
   avg_position[0] = avg_position[1] = avg_position[2] = 0.0;
 
-  MBRange connect;
-  MBErrorCode result = mbImpl->get_adjacencies(entities, num_entities, 0, false,
-                                               connect, MBInterface::UNION);
+  Range connect;
+  ErrorCode result = mbImpl->get_adjacencies(entities, num_entities, 0, false,
+                                               connect, Interface::UNION);
   if (MB_SUCCESS != result) return result;
 
   if (connect.empty()) return MB_FAILURE;
   
-  for (MBRange::iterator rit = connect.begin(); rit != connect.end(); rit++) {
+  for (Range::iterator rit = connect.begin(); rit != connect.end(); rit++) {
     result = mbImpl->get_coords(&(*rit), 1, dum_pos);
     if (MB_SUCCESS != result) return result;
     avg_position[0] += dum_pos[0]; 
@@ -82,15 +84,15 @@
 }
   
     //! given an entity, get its average position (avg vertex locations)
-MBErrorCode MeshTopoUtil::get_average_position(const MBEntityHandle entity,
+ErrorCode MeshTopoUtil::get_average_position(const EntityHandle entity,
                                                double *avg_position) 
 {
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
   if (MBVERTEX == mbImpl->type_from_handle(entity))
     return mbImpl->get_coords(&entity, 1, avg_position);
     
-  MBErrorCode result = mbImpl->get_connectivity(entity, connect, num_connect);
+  ErrorCode result = mbImpl->get_connectivity(entity, connect, num_connect);
   if (MB_SUCCESS != result) return result;
 
   return get_average_position(connect, num_connect, avg_position);
@@ -100,21 +102,21 @@
   // that entity, ordered by connection through next higher dimension entities; 
   // if any of the star entities is in only one entity of next higher dimension, 
   // on_boundary is returned true
-MBErrorCode MeshTopoUtil::star_entities(const MBEntityHandle star_center,
-                                        std::vector<MBEntityHandle> &star_entities,
+ErrorCode MeshTopoUtil::star_entities(const EntityHandle star_center,
+                                        std::vector<EntityHandle> &star_entities,
                                         bool &bdy_entity,
-                                        const MBEntityHandle starting_star_entity,
-                                        std::vector<MBEntityHandle> *star_entities_dp2,
-                                        MBRange *star_candidates_dp2)
+                                        const EntityHandle starting_star_entity,
+                                        std::vector<EntityHandle> *star_entities_dp2,
+                                        Range *star_candidates_dp2)
 {
     // now start the traversal
   bdy_entity = false;
-  MBEntityHandle last_entity = starting_star_entity, last_dp2 = 0, next_entity, next_dp2;
-  std::vector<MBEntityHandle> star_dp2;
-  MBErrorCode result;
+  EntityHandle last_entity = starting_star_entity, last_dp2 = 0, next_entity, next_dp2;
+  std::vector<EntityHandle> star_dp2;
+  ErrorCode result;
   int center_dim = mbImpl->dimension_from_handle(star_center);
   
-  MBRange tmp_candidates_dp2;
+  Range tmp_candidates_dp2;
   if (NULL != star_candidates_dp2) tmp_candidates_dp2 = *star_candidates_dp2;
   else {
     result = mbImpl->get_adjacencies(&star_center, 1, 
@@ -187,24 +189,24 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshTopoUtil::star_next_entity(const MBEntityHandle star_center,
-                                           const MBEntityHandle last_entity,
-                                           const MBEntityHandle last_dp1,
-                                           MBRange *star_candidates_dp1,
-                                           MBEntityHandle &next_entity,
-                                           MBEntityHandle &next_dp1) 
+ErrorCode MeshTopoUtil::star_next_entity(const EntityHandle star_center,
+                                           const EntityHandle last_entity,
+                                           const EntityHandle last_dp1,
+                                           Range *star_candidates_dp1,
+                                           EntityHandle &next_entity,
+                                           EntityHandle &next_dp1) 
 {
     // given a star_center, a last_entity (whose dimension should be 1 greater than center)
     // and last_dp1 (dimension 2 higher than center), returns the next star entity across
     // last_dp1, and the next dp1 entity sharing next_entity; if star_candidates is non-empty,
     // star must come from those
-  MBRange from_ents, to_ents;
+  Range from_ents, to_ents;
   from_ents.insert(star_center);
   if (0 != last_dp1) from_ents.insert(last_dp1);
     
   int dim = mbImpl->dimension_from_handle(star_center);
   
-  MBErrorCode result = mbImpl->get_adjacencies(from_ents, dim+1, false, to_ents);
+  ErrorCode result = mbImpl->get_adjacencies(from_ents, dim+1, false, to_ents);
   if (MB_SUCCESS != result) return result;
   
     // remove last_entity from result, and should only have 1 left, if any
@@ -212,8 +214,8 @@
 
     // if no last_dp1, contents of to_ents should share dp1-dimensional entity with last_entity
   if (0 != last_entity && 0 == last_dp1) {
-    MBRange tmp_to_ents;
-    for (MBRange::iterator rit = to_ents.begin(); rit != to_ents.end(); rit++) {
+    Range tmp_to_ents;
+    for (Range::iterator rit = to_ents.begin(); rit != to_ents.end(); rit++) {
       if (0 != common_entity(last_entity, *rit, dim+2))
         tmp_to_ents.insert(*rit);
     }
@@ -225,7 +227,7 @@
       // if we have a choice of to_ents and no previous dp1 and dp1 candidates, 
       // the one we choose needs to be adjacent to one of the candidates
     result = mbImpl->get_adjacencies(*star_candidates_dp1, dim+1, false,
-                                     from_ents, MBInterface::UNION);
+                                     from_ents, Interface::UNION);
     if (MB_SUCCESS != result) return result;
     to_ents = intersect( to_ents, from_ents);
   }
@@ -255,10 +257,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshTopoUtil::star_entities_nonmanifold(const MBEntityHandle star_entity,
-                                                    std::vector<std::vector<MBEntityHandle> > &stars,
+ErrorCode MeshTopoUtil::star_entities_nonmanifold(const EntityHandle star_entity,
+                                                    std::vector<std::vector<EntityHandle> > &stars,
                                                     std::vector<bool> *bdy_flags,
-                                                    std::vector<std::vector<MBEntityHandle> > *dp2_stars) 
+                                                    std::vector<std::vector<EntityHandle> > *dp2_stars) 
 {
     // Get a series of (d+1)-dimensional stars around a d-dimensional entity, such that
     // each star is on a (d+2)-manifold containing the d-dimensional entity; each star
@@ -283,16 +285,16 @@
   
     // get the (d+2)-manifold entities; for d=1 / d+2=3, just assume all connected elements, since
     //   we don't do 4d yet
-  MBRange dp2_manifold;
-  MBErrorCode result = get_manifold(star_entity, this_dim+2, dp2_manifold);
+  Range dp2_manifold;
+  ErrorCode result = get_manifold(star_entity, this_dim+2, dp2_manifold);
   if (MB_SUCCESS != result) return result;
   
     // get intersection of (d+1)-entities adjacent to star and union of (d+1)-entities 
     //   adjacent to (d+2)-manifold entities; also add manifold (d+1)-entities, to catch
     //   any not connected to (d+2)-entities
-  MBRange dp1_manifold;
+  Range dp1_manifold;
   result = mbImpl->get_adjacencies(dp2_manifold, this_dim+1, false, dp1_manifold,
-                                   MBInterface::UNION);
+                                   Interface::UNION);
   if (MB_SUCCESS != result) return result;
 
   result = mbImpl->get_adjacencies(&star_entity, 1, this_dim+1, false, dp1_manifold);
@@ -306,10 +308,10 @@
     
       //   get (d+1)-entity from (d+1)-entities (don't remove it until after star,
       //     since the star entities must come from dp1_manifold)
-    MBEntityHandle this_ent = *dp1_manifold.begin();
+    EntityHandle this_ent = *dp1_manifold.begin();
     
       //   get the (d+1)-star and (d+2)-star around that (d+1)-entity (using star_entities)
-    std::vector<MBEntityHandle> this_star_dp1, this_star_dp2;
+    std::vector<EntityHandle> this_star_dp1, this_star_dp2;
     bool on_bdy;
     result = star_entities(star_entity, this_star_dp1, on_bdy, this_ent, &this_star_dp2, 
                            &dp2_manifold);
@@ -319,7 +321,7 @@
       // entities (wasn't put into star in star_entities 'cuz we're passing in non-null
       // dp2_manifold above); put it in
     if (this_star_dp1.empty()) {
-      MBRange dum_range;
+      Range dum_range;
       result = mbImpl->get_adjacencies(&this_ent, 1, this_dim+2, false, dum_range);
       if (MB_SUCCESS != result) return result;
       if (dum_range.empty()) this_star_dp1.push_back(this_ent);
@@ -336,12 +338,12 @@
     }
     
       //   remove (d+2)-entities from the (d+2)-manifold entities
-    for (std::vector<MBEntityHandle>::iterator vit = this_star_dp2.begin(); 
+    for (std::vector<EntityHandle>::iterator vit = this_star_dp2.begin(); 
          vit != this_star_dp2.end(); vit++)
       dp2_manifold.erase(*vit);
     
       //   remove (d+1)-entities from the (d+1)-entities
-    for (std::vector<MBEntityHandle>::iterator vit = this_star_dp1.begin(); 
+    for (std::vector<EntityHandle>::iterator vit = this_star_dp1.begin(); 
          vit != this_star_dp1.end(); vit++)
       dp1_manifold.erase(*vit);
     
@@ -351,7 +353,7 @@
     // check for leftover dp2 manifold entities, these should be in one of the 
     // stars
   if (!dp2_manifold.empty()) {
-    for (MBRange::iterator rit = dp2_manifold.begin(); rit != dp2_manifold.end(); rit++) {
+    for (Range::iterator rit = dp2_manifold.begin(); rit != dp2_manifold.end(); rit++) {
     }
   }
     
@@ -362,13 +364,13 @@
 //! the entities with <= 1 connected (target_dim+2)-dimensional adjacent entities;
 //! for target_dim=3, just return all of them
 //! just insert into the list, w/o clearing manifold list first
-MBErrorCode MeshTopoUtil::get_manifold(const MBEntityHandle star_entity,
+ErrorCode MeshTopoUtil::get_manifold(const EntityHandle star_entity,
                                        const int target_dim,
-                                       MBRange &manifold) 
+                                       Range &manifold) 
 {
     // get all the entities of target dimension connected to star
-  MBRange tmp_range;
-  MBErrorCode result = mbImpl->get_adjacencies(&star_entity, 1, target_dim, false, tmp_range);
+  Range tmp_range;
+  ErrorCode result = mbImpl->get_adjacencies(&star_entity, 1, target_dim, false, tmp_range);
   if (MB_SUCCESS != result) return result;
   
     // now save the ones which are (target_dim+1)-dimensional manifold;
@@ -378,8 +380,8 @@
     return MB_SUCCESS;
   }
   
-  for (MBRange::iterator rit = tmp_range.begin(); rit != tmp_range.end(); rit++) {
-    MBRange dum_range;
+  for (Range::iterator rit = tmp_range.begin(); rit != tmp_range.end(); rit++) {
+    Range dum_range;
       // get (target_dim+1)-dimensional entities
     result = mbImpl->get_adjacencies(&(*rit), 1, target_dim+1, false, dum_range);
     if (MB_SUCCESS != result) return result;
@@ -392,39 +394,39 @@
 }
 
     //! get "bridge" or "2nd order" adjacencies, going through dimension bridge_dim
-MBErrorCode MeshTopoUtil::get_bridge_adjacencies(MBRange &from_entities,
+ErrorCode MeshTopoUtil::get_bridge_adjacencies(Range &from_entities,
                                                  int bridge_dim,
                                                  int to_dim, 
-                                                 MBRange &to_ents,
+                                                 Range &to_ents,
                                                  int num_layers)
 {
-  MBRange bridge_ents, last_toents, new_toents(from_entities);
-  MBErrorCode result;
+  Range bridge_ents, last_toents, new_toents(from_entities);
+  ErrorCode result;
   if (0 == num_layers || from_entities.empty()) return MB_FAILURE;
   
     // for each layer, get bridge-adj entities and accumulate
   for (int nl = 0; nl < num_layers; nl++) {
-    MBRange new_bridges;
+    Range new_bridges;
       // get bridge ents
     result = mbImpl->get_adjacencies(new_toents, bridge_dim, true, new_bridges,
-                                     MBInterface::UNION);
+                                     Interface::UNION);
     if (MB_SUCCESS != result) return result;
     
       // get to_dim adjacencies, merge into to_ents
     last_toents =  to_ents;
     if (-1 == to_dim) {
       result = mbImpl->get_adjacencies(new_bridges, 3, false, to_ents,
-				       MBInterface::UNION);
+				       Interface::UNION);
       if (MB_SUCCESS != result) return result;
       for (int d = 2; d >= 1; d--) {
 	result = mbImpl->get_adjacencies(to_ents, d, true, to_ents,
-					 MBInterface::UNION);
+					 Interface::UNION);
 	if (MB_SUCCESS != result) return result;
       }
     }
     else {
       result = mbImpl->get_adjacencies(new_bridges, to_dim, false, to_ents,
-				       MBInterface::UNION);
+				       Interface::UNION);
       if (MB_SUCCESS != result) return result;
     }
 
@@ -437,16 +439,16 @@
 }
 
     //! get "bridge" or "2nd order" adjacencies, going through dimension bridge_dim
-MBErrorCode MeshTopoUtil::get_bridge_adjacencies(const MBEntityHandle from_entity,
+ErrorCode MeshTopoUtil::get_bridge_adjacencies(const EntityHandle from_entity,
                                                  const int bridge_dim,
                                                  const int to_dim,
-                                                 MBRange &to_adjs) 
+                                                 Range &to_adjs) 
 {
     // get pointer to connectivity for this entity
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode result = MB_SUCCESS;
-  MBEntityType from_type = TYPE_FROM_HANDLE(from_entity);
+  ErrorCode result = MB_SUCCESS;
+  EntityType from_type = TYPE_FROM_HANDLE(from_entity);
   if (from_type == MBVERTEX) {
     connect = &from_entity;
     num_connect = 1;
@@ -460,13 +462,13 @@
 
   int from_dim = MBCN::Dimension(from_type);
   
-  MBRange to_ents;
+  Range to_ents;
 
   if (MB_SUCCESS != result) return result;
 
   if (bridge_dim < from_dim) {
       // looping over each sub-entity of dimension bridge_dim...
-    MBEntityHandle bridge_verts[MB_MAX_SUB_ENTITIES];
+    EntityHandle bridge_verts[MB_MAX_SUB_ENTITIES];
     int bridge_indices[MB_MAX_SUB_ENTITIES];
     for (int i = 0; i < MBCN::NumSubEntities(from_type, bridge_dim); i++) {
 
@@ -479,8 +481,8 @@
     
         // get the to_dim entities adjacent
       to_ents.clear();
-      MBErrorCode tmp_result = mbImpl->get_adjacencies(bridge_verts, num_bridge_verts,
-                                                       to_dim, false, to_ents, MBInterface::INTERSECT);
+      ErrorCode tmp_result = mbImpl->get_adjacencies(bridge_verts, num_bridge_verts,
+                                                       to_dim, false, to_ents, Interface::INTERSECT);
       if (MB_SUCCESS != tmp_result) result = tmp_result;
     
       to_adjs.merge(to_ents);
@@ -490,15 +492,15 @@
 
     // now get the direct ones too, or only in the case where we're 
     // going to higher dimension for bridge
-  MBRange bridge_ents, tmp_ents;
+  Range bridge_ents, tmp_ents;
   tmp_ents.insert(from_entity);
-  MBErrorCode tmp_result = mbImpl->get_adjacencies(tmp_ents, bridge_dim,
+  ErrorCode tmp_result = mbImpl->get_adjacencies(tmp_ents, bridge_dim,
                                                    false, bridge_ents, 
-                                                   MBInterface::UNION);
+                                                   Interface::UNION);
   if (MB_SUCCESS != tmp_result) return tmp_result;
     
   tmp_result = mbImpl->get_adjacencies(bridge_ents, to_dim, false, to_adjs, 
-                                       MBInterface::UNION);
+                                       Interface::UNION);
   if (MB_SUCCESS != tmp_result) return tmp_result;
   
     // if to_dimension is same as that of from_entity, make sure from_entity isn't
@@ -509,13 +511,13 @@
 }
 
     //! return a common entity of the specified dimension, or 0 if there isn't one
-MBEntityHandle MeshTopoUtil::common_entity(const MBEntityHandle ent1,
-                                           const MBEntityHandle ent2,
+EntityHandle MeshTopoUtil::common_entity(const EntityHandle ent1,
+                                           const EntityHandle ent2,
                                            const int dim) 
 {
-  MBRange tmp_range, tmp_range2;
+  Range tmp_range, tmp_range2;
   tmp_range.insert(ent1); tmp_range.insert(ent2);
-  MBErrorCode result = mbImpl->get_adjacencies(tmp_range, dim, false, tmp_range2);
+  ErrorCode result = mbImpl->get_adjacencies(tmp_range, dim, false, tmp_range2);
   if (MB_SUCCESS != result || tmp_range2.empty()) return 0;
   else return *tmp_range2.begin();
 }
@@ -527,13 +529,13 @@
   //! \param parent The parent element
   //! \param child The child element
   //! \param opposite_element The index of the opposite element
-MBErrorCode MeshTopoUtil::opposite_entity(const MBEntityHandle parent,
-                                          const MBEntityHandle child,
-                                          MBEntityHandle &opposite_element) 
+ErrorCode MeshTopoUtil::opposite_entity(const EntityHandle parent,
+                                          const EntityHandle child,
+                                          EntityHandle &opposite_element) 
 {
     // get the side no.
   int side_no, offset, sense;
-  MBErrorCode result = mbImpl->side_number(parent, child, side_no, 
+  ErrorCode result = mbImpl->side_number(parent, child, side_no, 
                                            offset, sense);
   if (MB_SUCCESS != result) return result;
   
@@ -552,20 +554,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MeshTopoUtil::split_entities_manifold(MBRange &entities,
-                                                  MBRange &new_entities,
-                                                  MBRange *fill_entities) 
+ErrorCode MeshTopoUtil::split_entities_manifold(Range &entities,
+                                                  Range &new_entities,
+                                                  Range *fill_entities) 
 {
-  MBRange tmp_range, *tmp_ptr_fill_entity;
+  Range tmp_range, *tmp_ptr_fill_entity;
   if (NULL != fill_entities) tmp_ptr_fill_entity = &tmp_range;
   else tmp_ptr_fill_entity = NULL;
   
-  for (MBRange::iterator rit = entities.begin(); rit != entities.end(); rit++) {
-    MBEntityHandle new_entity;
+  for (Range::iterator rit = entities.begin(); rit != entities.end(); rit++) {
+    EntityHandle new_entity;
     if (NULL != tmp_ptr_fill_entity) tmp_ptr_fill_entity->clear();
 
-    MBEntityHandle this_ent = *rit;
-    MBErrorCode result = split_entities_manifold(&this_ent, 1, &new_entity, 
+    EntityHandle this_ent = *rit;
+    ErrorCode result = split_entities_manifold(&this_ent, 1, &new_entity, 
                                                  tmp_ptr_fill_entity);
     if (MB_SUCCESS != result) return result;
 
@@ -577,32 +579,32 @@
 }
 
 
-MBErrorCode MeshTopoUtil::split_entities_manifold(MBEntityHandle *entities,
+ErrorCode MeshTopoUtil::split_entities_manifold(EntityHandle *entities,
                                                   const int num_entities,
-                                                  MBEntityHandle *new_entities,
-                                                  MBRange *fill_entities,
-                                                  MBEntityHandle *gowith_ents)
+                                                  EntityHandle *new_entities,
+                                                  Range *fill_entities,
+                                                  EntityHandle *gowith_ents)
 {
     // split entities by duplicating them; splitting manifold means that there is at
     // most two higher-dimension entities bounded by a given entity; after split, the
     // new entity bounds one and the original entity bounds the other
 
-#define ITERATE_RANGE(range, it) for (MBRange::iterator it = range.begin(); it != range.end(); it++)
+#define ITERATE_RANGE(range, it) for (Range::iterator it = range.begin(); it != range.end(); it++)
 #define GET_CONNECT_DECL(ent, connect, num_connect) \
-  const MBEntityHandle *connect; int num_connect; \
-  {MBErrorCode connect_result = mbImpl->get_connectivity(ent, connect, num_connect); \
+  const EntityHandle *connect; int num_connect; \
+  {ErrorCode connect_result = mbImpl->get_connectivity(ent, connect, num_connect); \
    if (MB_SUCCESS != connect_result) return connect_result;}
 #define GET_CONNECT(ent, connect, num_connect) \
-  {MBErrorCode connect_result = mbImpl->get_connectivity(ent, connect, num_connect);\
+  {ErrorCode connect_result = mbImpl->get_connectivity(ent, connect, num_connect);\
    if (MB_SUCCESS != connect_result) return connect_result;}
 #define TC if (MB_SUCCESS != tmp_result) {result = tmp_result; continue;}
 
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   for (int i = 0; i < num_entities; i++) {
-    MBErrorCode tmp_result;
+    ErrorCode tmp_result;
       
       // get original higher-dimensional bounding entities
-    MBRange up_adjs[4];
+    Range up_adjs[4];
       // can only do a split_manifold if there are at most 2 entities of each
       // higher dimension; otherwise it's a split non-manifold
     bool valid_up_adjs = true;
@@ -617,7 +619,7 @@
       
       // ok to split; create the new entity, with connectivity of the original
     GET_CONNECT_DECL(entities[i], connect, num_connect);
-    MBEntityHandle new_entity;
+    EntityHandle new_entity;
     result = mbImpl->create_element(mbImpl->type_from_handle(entities[i]), connect, num_connect, 
                                     new_entity); TC;
       
@@ -630,7 +632,7 @@
       if (dim < MBCN::Dimension(TYPE_FROM_HANDLE(entities[i]))) {
           // adjacencies from other entities to this one; if any of those are equivalent entities,
           // need to make explicit adjacency to new entity too
-        for (MBRange::iterator rit = up_adjs[dim].begin(); rit != up_adjs[dim].end(); rit++) {
+        for (Range::iterator rit = up_adjs[dim].begin(); rit != up_adjs[dim].end(); rit++) {
           if (equivalent_entities(*rit))
             result = mbImpl->add_adjacencies(*rit, &new_entity, 1, false);
         }
@@ -638,14 +640,14 @@
       else {
         
           // get the two up-elements
-        MBEntityHandle up_elem1 = *(up_adjs[dim].begin()),
+        EntityHandle up_elem1 = *(up_adjs[dim].begin()),
             up_elem2 = (up_adjs[dim].size() > 1 ? *(up_adjs[dim].rbegin()) : 0);
         
           // if two, and a gowith entity was input, make sure the new entity goes with
           // that one
         if (gowith_ents && up_elem2 && 
             gowith_ents[i] != up_elem1 && gowith_ents[i] == up_elem2) {
-          MBEntityHandle tmp_elem = up_elem1;
+          EntityHandle tmp_elem = up_elem1;
           up_elem1 = up_elem2;
           up_elem2 = tmp_elem;
         }
@@ -662,8 +664,8 @@
     }
 
       // if we're asked to build a next-higher-dimension object, do so
-    MBEntityHandle fill_entity = 0;
-    MBEntityHandle tmp_ents[2];
+    EntityHandle fill_entity = 0;
+    EntityHandle tmp_ents[2];
     if (NULL != fill_entities) {
         // how to do this depends on dimension
       switch (MBCN::Dimension(TYPE_FROM_HANDLE(entities[i]))) {
@@ -698,63 +700,63 @@
   return result;
 }
 
-MBErrorCode MeshTopoUtil::split_entity_nonmanifold(MBEntityHandle split_ent,
-                                                   MBRange &old_adjs,
-                                                   MBRange &new_adjs,
-                                                   MBEntityHandle &new_entity) 
+ErrorCode MeshTopoUtil::split_entity_nonmanifold(EntityHandle split_ent,
+                                                   Range &old_adjs,
+                                                   Range &new_adjs,
+                                                   EntityHandle &new_entity) 
 {
     // split an entity into two entities; new entity gets explicit adj to new_adjs,
     // old to old_adjs
 
     // make new entities and add adjacencies
     // create the new entity
-  MBEntityType split_type = mbImpl->type_from_handle(split_ent);
+  EntityType split_type = mbImpl->type_from_handle(split_ent);
   
-  MBErrorCode result;
+  ErrorCode result;
   if (MBVERTEX == split_type) {
     double coords[3];
     result = mbImpl->get_coords(&split_ent, 1, coords); RR;
     result = mbImpl->create_vertex(coords, new_entity); RR;
   }
   else {
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
     result = mbImpl->get_connectivity(split_ent, connect, num_connect); RR;
     result = mbImpl->create_element(split_type, connect, num_connect, new_entity); RR;
 
       // remove any explicit adjacencies between new_adjs and split entity
-    for (MBRange::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++)
+    for (Range::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++)
       mbImpl->remove_adjacencies(split_ent, &(*rit), 1);
   }
       
   if (MBVERTEX != split_type) {
         //  add adj's between new_adjs & new entity, old_adjs & split_entity
-    for (MBRange::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++)
+    for (Range::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++)
       mbImpl->add_adjacencies(new_entity, &(*rit), 1, true);
-    for (MBRange::iterator rit = old_adjs.begin(); rit != old_adjs.end(); rit++)
+    for (Range::iterator rit = old_adjs.begin(); rit != old_adjs.end(); rit++)
       mbImpl->add_adjacencies(split_ent, &(*rit), 1, true);
   }
   else if (split_ent != new_entity) {
       // in addition to explicit adjs, need to check if vertex is part of any
       // other entities, and check those entities against ents in old and new adjs
-    MBRange other_adjs;
+    Range other_adjs;
     for (int i = 1; i < 4; i++) {
       result = mbImpl->get_adjacencies(&split_ent, 1, i, false, other_adjs, 
-                                       MBInterface::UNION); RR;
+                                       Interface::UNION); RR;
     }
     other_adjs = subtract( other_adjs, old_adjs);
     other_adjs = subtract( other_adjs, new_adjs);
-    for (MBRange::iterator rit1 = other_adjs.begin(); rit1 != other_adjs.end(); rit1++) {
+    for (Range::iterator rit1 = other_adjs.begin(); rit1 != other_adjs.end(); rit1++) {
         // find an adjacent lower-dimensional entity in old_ or new_ adjs
       bool found = false;
-      for (MBRange::iterator rit2 = old_adjs.begin(); rit2 != old_adjs.end(); rit2++) {
+      for (Range::iterator rit2 = old_adjs.begin(); rit2 != old_adjs.end(); rit2++) {
         if (mbImpl->dimension_from_handle(*rit1) != mbImpl->dimension_from_handle(*rit2) &&
             common_entity(*rit1, *rit2, mbImpl->dimension_from_handle(*rit1))) {
           found = true; old_adjs.insert(*rit1); break;
         }
       }
       if (found) continue;
-      for (MBRange::iterator rit2 = new_adjs.begin(); rit2 != new_adjs.end(); rit2++) {
+      for (Range::iterator rit2 = new_adjs.begin(); rit2 != new_adjs.end(); rit2++) {
         if (mbImpl->dimension_from_handle(*rit1) != mbImpl->dimension_from_handle(*rit2) &&
             common_entity(*rit1, *rit2, mbImpl->dimension_from_handle(*rit1))) {
           found = true; new_adjs.insert(*rit1); break;
@@ -764,8 +766,8 @@
     }
           
       // instead of adjs replace in connectivity
-    std::vector<MBEntityHandle> connect;
-    for (MBRange::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++) {
+    std::vector<EntityHandle> connect;
+    for (Range::iterator rit = new_adjs.begin(); rit != new_adjs.end(); rit++) {
       connect.clear();
       result = mbImpl->get_connectivity(&(*rit), 1, connect); RR;
       std::replace(connect.begin(), connect.end(), split_ent, new_entity);
@@ -783,13 +785,13 @@
 
     // split entity d, producing entity nd; generates various new entities,
     // see algorithm description in notes from 2/25/05
-  const MBEntityHandle split_types = {MBEDGE, MBPOLYGON, MBPOLYHEDRON};
-  MBErrorCode result = MB_SUCCESS;
+  const EntityHandle split_types = {MBEDGE, MBPOLYGON, MBPOLYHEDRON};
+  ErrorCode result = MB_SUCCESS;
   const int dim = MBCN::Dimension(TYPE_FROM_HANDLE(d));
   MeshTopoUtil mtu(this);
 
     // get all (d+2)-, (d+1)-cells connected to d
-  MBRange dp2s, dp1s, dp1s_manif, dp2s_manif;
+  Range dp2s, dp1s, dp1s_manif, dp2s_manif;
   result = get_adjacencies(&d, 1, dim+2, false, dp2s); RR;
   result = get_adjacencies(&d, 1, dim+1, false, dp1s); RR;
 
@@ -799,28 +801,28 @@
   
     // make new cell nd, then ndp1
   result = copy_entity(d, nd); RR;
-  MBEntityHandle tmp_connect[] = {d, nd};
-  MBEntityHandle ndp1;
+  EntityHandle tmp_connect[] = {d, nd};
+  EntityHandle ndp1;
   result = create_element(split_types[dim],
                           tmp_connect, 2, ndp1); RR;
   
     // modify (d+2)-cells, depending on what type they are
   ITERATE_RANGE(dp2s, dp2) {
       // first, get number of connected manifold (d+1)-entities
-    MBRange tmp_range, tmp_range2(dp1s_manif);
+    Range tmp_range, tmp_range2(dp1s_manif);
     tmp_range.insert(*dp2);
     tmp_range.insert(d);
     tmp_result = get_adjacencies(tmp_range, 1, false, tmp_range2); TC;
-    MBEntityHandle ndp2;
+    EntityHandle ndp2;
     
       // a. manif (d+1)-cells is zero
     if (tmp_range2.empty()) {
         // construct new (d+1)-cell
-      MBEntityHandle ndp1a;
-      MBEntityHandle tmp_result = create_element(split_types[dim],
+      EntityHandle ndp1a;
+      EntityHandle tmp_result = create_element(split_types[dim],
                                                  tmp_connect, 2, ndp1a); TC;
         // now make new (d+2)-cell
-      MBEntityHandle tmp_connect2[] = {ndp1, ndp1a};
+      EntityHandle tmp_connect2[] = {ndp1, ndp1a};
       tmp_result = create_element(split_types[dim+1],
                                   tmp_connect2, 2, ndp2); TC;
         // need to add explicit adjacencies, since by definition ndp1, ndp1a will be equivalent
@@ -829,10 +831,10 @@
       tmp_result = add_adjacencies(ndp1, &ndp2, 1, false); TC;
 
         // now insert nd into connectivity of dp2, right after d if dim < 1
-      std::vector<MBEntityHandle> connect;
+      std::vector<EntityHandle> connect;
       tmp_result = get_connectivity(&dp2, 1, connect); TC;
       if (dim < 1) {
-        std::vector<MBEntityHandle>::iterator vit = std::find(connect.begin(), connect.end(), d);
+        std::vector<EntityHandle>::iterator vit = std::find(connect.begin(), connect.end(), d);
         if (vit == connect.end()) {
           result = MB_FAILURE;
           continue;
@@ -846,7 +848,7 @@
         // if dim < 1, need to add explicit adj from ndp2 to higher-dim ents, since it'll
         // be equiv to other dp2 entities
       if (dim < 1) {
-        MBRange tmp_dp3s;
+        Range tmp_dp3s;
         tmp_result = get_adjacencies(&dp2, 1, dim+3, false, tmp_dp3s); TC;
         tmp_result = add_adjacencies(ndp2, tmp_dp3s, false); TC;
       }
@@ -857,17 +859,17 @@
         // b1. check validity, and skip if not valid
 
         // only change if not dp1-adjacent to manifold dp2cell; check that...
-      MBRange tmp_adjs(dp2s_manif);
+      Range tmp_adjs(dp2s_manif);
       tmp_result = get_adjacencies(&(*tmp_range2.begin()), 1, dim+2, false, tmp_adjs); TC;
       if (!tmp_adjs.empty()) continue;
 
-      MBEntityHandle dp1 = *tmp_range2.begin();
+      EntityHandle dp1 = *tmp_range2.begin();
 
         // b2. make new (d+1)- and (d+2)-cell next to dp2
 
         // get the (d+2)-cell on the other side of dp1
       tmp_result = get_adjacencies(&dp1, 1, dim+2, false, tmp_adjs); TC;
-      MBEntityHandle odp2 = *tmp_adjs.begin();
+      EntityHandle odp2 = *tmp_adjs.begin();
       if (odp2 == dp2) odp2 = *tmp_adjs.rbegin();
 
         // get od, the d-cell on dp1_manif which isn't d
@@ -877,7 +879,7 @@
         result = MB_FAILURE;
         continue;
       }
-      MBEntityHandle od = *tmp_adjs.begin();
+      EntityHandle od = *tmp_adjs.begin();
 
         // make a new (d+1)-cell from od and nd
       tmp_adjs.insert(nd);
@@ -889,7 +891,7 @@
       tmp_result = create_element(split_types[2], tmp_adjs, ndp2); TC;
 
         // b3. replace d, dp1 in connect/adjs of odp2
-      std::vector<MBEntityHandle> connect;
+      std::vector<EntityHandle> connect;
       tmp_result = get_connectivity(&odp2, 1, connect); TC;
       if (dim == 0) {
         *(std::find(connect.begin(), connect.end(), d)) = nd;
@@ -908,15 +910,15 @@
     //! return whether entity is equivalent to any other of same type and same vertices;
     //! if equivalent entity is found, it's returned in equiv_ents and return value is true,
     //! false otherwise.
-bool MeshTopoUtil::equivalent_entities(const MBEntityHandle entity,
-                                       MBRange *equiv_ents) 
+bool MeshTopoUtil::equivalent_entities(const EntityHandle entity,
+                                       Range *equiv_ents) 
 {
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode result = mbImpl->get_connectivity(entity, connect, num_connect);
+  ErrorCode result = mbImpl->get_connectivity(entity, connect, num_connect);
   if (MB_SUCCESS != result) return false;
 
-  MBRange dum;
+  Range dum;
   result = mbImpl->get_adjacencies(connect, num_connect, 
                                    mbImpl->dimension_from_handle(entity),
                                    false, dum);
@@ -929,5 +931,6 @@
   if (!dum.empty()) return true;
   else return false;
 }
+  
+} // namespace moab
 
-  

Copied: MOAB/trunk/src/OrientedBox.cpp (from rev 3583, MOAB/trunk/src/MBOrientedBox.cpp)
===================================================================
--- MOAB/trunk/src/OrientedBox.cpp	                        (rev 0)
+++ MOAB/trunk/src/OrientedBox.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,659 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/* 
+ * The algorithms for the calculation of the oriented box from a
+ * set of points or a set of cells was copied from the implemenation
+ " in the "Visualization Toolkit".  J.K. - 2006-07-19
+ *
+ * Program:   Visualization Toolkit
+ * Module:    $RCSfile$
+ *
+ * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+ * All rights reserved.
+ * See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
+ */
+
+/**\file OrientedBox.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#include "moab/Interface.hpp"
+#include "moab/MBCN.hpp"
+#include "OrientedBox.hpp"
+#include "moab/Range.hpp"
+#include "Matrix3.hpp"
+#include <ostream>
+#include <assert.h>
+#include <limits>
+
+namespace moab {
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#  include <float.h>
+#  define finite(A) _finite(A)
+#endif
+ 
+std::ostream& operator<<( std::ostream& s, const OrientedBox& b )
+{
+  return s << b.center 
+           << " + " 
+           << b.axis[0] 
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+           << ":" << b.length[0] 
+#endif
+           << " x " 
+           << b.axis[1] 
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+           << ":" << b.length[1] 
+#endif
+           << " x " 
+           << b.axis[2]
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+           << ":" << b.length[2] 
+#endif
+            ;
+}
+
+/**\brief Find closest point on line
+ *
+ * Find the point on the line for which a line trough the 
+ * input point \a p and the result position is orthogonal to
+ * the input line.
+ * \param p  The point for which to find the perpendicular
+ * \param b  A point on the line
+ * \param m  The direction of the line
+ * \return   The location on the line specified as 't' in the
+ *           formula t * m + b
+ */
+static double point_perp( const CartVect& p,   // closest to this point
+                          const CartVect& b,   // point on line
+                          const CartVect& m )  // line direction
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  double t = (m % (p - b));
+#else
+  double t = (m % (p - b)) / (m % m);
+#endif
+  return finite(t) ? t : 0.0;
+}
+
+OrientedBox::OrientedBox( const CartVect axes[3], const CartVect& mid )
+  : center(mid)
+{
+    // re-order axes by length
+  CartVect len( axes[0].length(), axes[1].length(), axes[2].length() );
+  axis[0] = axes[0];
+  axis[1] = axes[1];
+  axis[2] = axes[2];
+  
+  if (len[2] < len[1])
+  {
+    if (len[2] < len[0]) {
+      std::swap( len[0], len[2] );
+      std::swap( axis[0], axis[2] );
+    }
+  }
+  else if (len[1] < len[0]) {
+    std::swap( len[0], len[1] );
+    std::swap( axis[0], axis[1] );
+  }
+  if (len[1] > len[2]) {
+    std::swap( len[1], len[2] );
+    std::swap( axis[1], axis[2] );
+  }
+  
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  this->length = len;
+  if (len[0] > 0.0)
+    axis[0] /= len[0];
+  if (len[1] > 0.0)
+    axis[1] /= len[1];
+  if (len[2] > 0.0)
+    axis[2] /= len[2];
+#endif
+
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  radius = len.length();
+#endif
+}
+
+ErrorCode OrientedBox::tag_handle( Tag& handle_out,
+                                       Interface* instance,
+                                       const char* name,
+                                       bool create )
+{
+    // We're going to assume this when mapping the OrientedBox
+    // to tag data, so assert it.  
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  const size_t rad_size = sizeof(double);
+#else
+  const size_t rad_size = 0;
+#endif
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  const size_t SIZE = rad_size + 15 * sizeof(double);
+#else
+  const size_t SIZE = rad_size + 12 * sizeof(double);
+#endif
+  assert( sizeof(OrientedBox) == SIZE );
+  
+  ErrorCode rval = instance->tag_get_handle( name, handle_out );
+  if (rval == MB_TAG_NOT_FOUND)
+  {
+    rval = instance->tag_create( name, 
+                                 SIZE,
+                                 MB_TAG_DENSE,
+                                 MB_TYPE_DOUBLE,
+                                 handle_out,
+                                 0 );
+  }
+  else if (rval == MB_SUCCESS)
+  {
+    DataType type;
+    rval = instance->tag_get_data_type( handle_out, type );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    int size;
+    rval = instance->tag_get_size( handle_out, size );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    if (type != MB_TYPE_DOUBLE && type != MB_TYPE_OPAQUE)
+      return MB_FAILURE;
+    if ((unsigned)size != SIZE)
+      return MB_FAILURE;
+  }
+  
+  return rval;
+}
+
+/**\brief Common code for box calculation
+ *
+ * Given the orientation of the box and an approximate center,
+ * calculate the exact center and extents of the box.
+ * 
+ *\param result.center  As input, the approximate center of the box.
+ *                      As output, the exact center of the box.
+ *\param result.axes    As input, directions of principal axes corresponding
+ *                      to the orientation of the box.  Axes are assumed to
+ *                      be unit-length on input.  Output will include extents
+ *                      of box.
+ *\param points  The set of points the box should contain.
+ */
+static ErrorCode box_from_axes( OrientedBox& result,
+                                  Interface* instance,
+                                  const Range& points )
+{ 
+  ErrorCode rval;
+  
+    // project points onto axes to get box extents
+  CartVect min(std::numeric_limits<double>::max()), 
+             max(-std::numeric_limits<double>::max());
+  for (Range::iterator i = points.begin(); i != points.end(); ++i)
+  {
+    CartVect coords;
+    rval = instance->get_coords( &*i, 1, coords.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    for (int d = 0; d < 3; ++d)
+    {
+      double t = point_perp( coords, result.center, result.axis[d] );
+      if (t < min[d])
+        min[d] = t;
+      if (t > max[d])
+        max[d] = t;
+    }
+  }
+  
+    // We now have a box defined by three orthogonal line segments
+    // that intersect at the center of the box.  Each line segment
+    // is defined as result.center + t * result.axis[i], where the
+    // range of t is [min[i], max[i]].
+  
+    // Calculate new center
+  CartVect mid = 0.5 * (min + max);
+  result.center += mid[0] * result.axis[0] +
+                   mid[1] * result.axis[1] +
+                   mid[2] * result.axis[2];
+  
+    // reorder axes by length
+  CartVect range = 0.5 * (max - min);
+  if (range[2] < range[1])
+  {
+    if (range[2] < range[0]) {
+      std::swap( range[0], range[2] );
+      std::swap( result.axis[0], result.axis[2] );
+    }
+  }
+  else if (range[1] < range[0]) {
+    std::swap( range[0], range[1] );
+    std::swap( result.axis[0], result.axis[1] );
+  }
+  if (range[1] > range[2]) {
+    std::swap( range[1], range[2] );
+    std::swap( result.axis[1], result.axis[2] );
+  }
+
+    // scale axis to encompass all points, divide in half
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  result.length = range;
+#else
+  result.axis[0] *= range[0];
+  result.axis[1] *= range[1];
+  result.axis[2] *= range[2];
+#endif
+
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  result.radius = range.length();
+#endif
+
+  return MB_SUCCESS;
+}
+
+
+ErrorCode OrientedBox::compute_from_vertices( OrientedBox& result,
+                                                  Interface* instance,
+                                                  const Range& vertices )
+{
+  const Range::iterator begin = vertices.lower_bound( MBVERTEX );
+  const Range::iterator end = vertices.upper_bound( MBVERTEX );
+  size_t count = 0;
+  
+    // compute mean
+  CartVect v;
+  result.center = CartVect( 0, 0, 0 );
+  for (Range::iterator i = begin; i != end; ++i)
+  {
+    ErrorCode rval = instance->get_coords( &*i, 1, v.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    result.center += v;
+    ++count;
+  }
+  result.center /= count;
+  
+    // compute covariance matrix
+  Matrix3 a( 0.0 );
+  for (Range::iterator i = begin; i != end; ++i)
+  {
+    ErrorCode rval = instance->get_coords( &*i, 1, v.array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+  
+    v -= result.center;
+    a += outer_product( v, v );
+  }
+  a /= count;
+
+    // Get axes (Eigenvectors) from covariance matrix
+  double lambda[3];
+  EigenDecomp( a, lambda, result.axis );
+  
+    // Calculate center and extents of box given orientation defined by axes
+  return box_from_axes( result, instance, vertices );
+}
+
+ErrorCode OrientedBox::covariance_data_from_tris( CovarienceData& result,
+                                                 Interface* instance,
+                                                 const Range& elements )
+{
+  ErrorCode rval;
+  const Range::iterator begin = elements.lower_bound( MBCN::TypeDimensionMap[2].first );
+  const Range::iterator end = elements.lower_bound( MBCN::TypeDimensionMap[3].first );
+  
+    // compute mean and moments
+  result.matrix = Matrix3(0.0);
+  result.center = CartVect(0.0);
+  result.area = 0.0;
+  for (Range::iterator i = begin; i != end; ++i)
+  {
+    const EntityHandle* conn;
+    int conn_len;
+    rval = instance->get_connectivity( *i, conn, conn_len );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+      // for each triangle in the 2-D cell
+    for (int j = 2; j < conn_len; ++j)
+    {
+      EntityHandle vertices[3] = { conn[0], conn[j-1], conn[j] };
+      CartVect coords[3];
+      rval = instance->get_coords( vertices, 3, coords[0].array() );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+        // edge vectors
+      const CartVect edge0 = coords[1] - coords[0];
+      const CartVect edge1 = coords[2] - coords[0];
+      const CartVect centroid = (coords[0] + coords[1] + coords[2]) / 3;
+      const double tri_area2 = (edge0 * edge1).length();
+      result.area += tri_area2;
+      result.center += tri_area2 * centroid;
+      
+      result.matrix += tri_area2 * (9 * outer_product( centroid,  centroid  ) +
+                                    outer_product( coords[0], coords[0] ) +
+                                    outer_product( coords[1], coords[1] ) +
+                                    outer_product( coords[2], coords[2] ));
+    } // for each triangle
+  } // for each element
+
+  return MB_SUCCESS;
+}
+
+
+ErrorCode OrientedBox::compute_from_2d_cells( OrientedBox& result,
+                                                  Interface* instance,
+                                                  const Range& elements )
+{
+    // Get orientation data from elements
+  CovarienceData data;
+  ErrorCode rval = covariance_data_from_tris( data, instance, elements );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // get vertices from elements
+  Range points;
+  rval = instance->get_adjacencies( elements, 0, false, points, Interface::UNION );
+  if (MB_SUCCESS != rval)
+    return rval;
+    
+    // Calculate box given points and orientation data
+  return compute_from_covariance_data( result, instance, data, points );
+}
+
+ErrorCode OrientedBox::compute_from_covariance_data(
+                                                OrientedBox& result,
+                                                Interface* instance,
+                                                CovarienceData& data,
+                                                const Range& vertices )
+{
+  if (data.area <= 0.0) {
+    CartVect axis[3] = { CartVect(0.), CartVect(0.), CartVect(0.) };
+    result = OrientedBox( axis, CartVect(0.) );
+    return MB_SUCCESS;
+  }
+
+    // get center from sum
+  result.center = data.center / data.area;
+
+    // get covariance matrix from moments
+  data.matrix /= 12 * data.area;
+  data.matrix -= outer_product( result.center, result.center );
+
+    // get axes (Eigenvectors) from covariance matrix
+  double lamda[3];
+  EigenDecomp( data.matrix, lamda, result.axis );
+
+    // We now have only the axes.  Calculate proper center
+    // and extents for enclosed points.
+  return box_from_axes( result, instance, vertices );
+}      
+
+bool OrientedBox::contained( const CartVect& point, double tol ) const
+{
+  CartVect from_center = point - center;
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return fabs(from_center % axis[0]) - length[0] <= tol &&
+         fabs(from_center % axis[1]) - length[1] <= tol &&
+         fabs(from_center % axis[2]) - length[2] <= tol ;
+#else
+  for (int i = 0; i < 3; ++i) {
+    double length = axis[i].length();
+    if (fabs(from_center % axis[i]) - length*length > length*tol)
+      return false;
+  }
+  return true;
+#endif
+}
+
+ErrorCode OrientedBox::compute_from_covariance_data( OrientedBox& result,
+                                                Interface* moab_instance,
+                                                const CovarienceData* data,
+                                                unsigned data_length,
+                                                const Range& vertices )
+{
+    // Sum input CovarienceData structures
+  CovarienceData data_sum( Matrix3(0.0), CartVect(0.0), 0.0 );
+  for (const CovarienceData* const end = data+data_length; data != end; ++data) {
+    data_sum.matrix += data->matrix;
+    data_sum.center += data->center;
+    data_sum.area += data->area;
+  }
+    // Compute box from sum of structs
+  return compute_from_covariance_data( result, moab_instance, data_sum, vertices );
+}
+
+
+
+//bool OrientedBox::contained( const OrientedBox& box, double tol ) const
+//{
+//  for (int i = -1; i < 2; i += 2) 
+//  {
+//    for (int j = -1; j < 2; j += 2) 
+//    {
+//      for (int k = -1; k < 2; k += 2) 
+//      {
+//        CartVect corner( center );
+//#ifdef MB_ORIENTED_BOX_UNIT_VECTORS
+//        corner += i * box.length[0] * box.axis[0];
+//        corner += j * box.length[1] * box.axis[1];
+//        corner += k * box.length[2] * box.axis[2];
+//#else
+//        corner += i * box.axis[0];
+//        corner += j * box.axis[1];
+//        corner += k * box.axis[2];
+//#endif
+//        if (!contained( corner, tol ))
+//          return false;
+//      }
+//    }
+//  }
+//  return true;
+//}
+
+
+/* This implementation copied from cgmMC (overlap.C).
+ * Original author:  Tim Taugtes?
+ */
+bool OrientedBox::intersect_ray( const CartVect& b,
+                                   const CartVect& m,
+                                   double reps,
+                                   const double* len ) const
+{
+    // test distance from box center to line
+  const CartVect cx = center - b;
+  double dist_s = cx % m;
+  double dist_sq = cx % cx - (dist_s*dist_s);
+  double max_diagsq = outer_radius_squared(reps);
+  
+    // if greater than the longest diagonal, we don't hit
+  if (dist_sq > max_diagsq)
+    return false;
+
+  // If the closest possible hit is farther than len, we don't want the hit.
+  // Problem: the previous method was wrong because max_diagsq will be greater
+  // than max_diag if max_diag>1 but less than max_diag if max_diag<1.
+  // Be careful with absolute value, squaring distances, and subtracting squared
+  // distances.
+  if (len) {
+    const double temp = fabs(dist_s) - *len;
+    if(0.0<temp && temp*temp>max_diagsq) return false;
+  } 
+
+    // if smaller than shortest diagonal, we do hit
+  if (dist_sq < inner_radius_squared(reps) && dist_s >= 0.0)
+    return true;
+    
+    // get transpose of axes
+    // Note: if axes were stored as a matrix, could skip
+    // transpose and just switch order of operands in
+    // matrix-vector multiplies below. - J.K.
+  //Matrix3 B( axis[0][0], axis[1][0], axis[2][0],
+  //             axis[0][1], axis[1][1], axis[2][1],
+  //             axis[0][2], axis[1][2], axis[2][2] );
+  Matrix3 B( axis[0][0], axis[0][1], axis[0][2],
+               axis[1][0], axis[1][1], axis[1][2],
+               axis[2][0], axis[2][1], axis[2][2] );
+  //CartVect T = B * -center;
+  
+    // transform ray to box coordintae system
+  //CartVect par_pos = T + B * b;
+  CartVect par_pos = B * (b - center);
+  CartVect par_dir = B * m;
+  
+    //fast rejection test
+  const double half_x = length[0] + reps;
+  if ((par_pos[0] >  half_x && par_dir[0] >= 0) ||
+      (par_pos[0] < -half_x && par_dir[0] <= 0))
+    return false;
+  
+  const double half_y = length[1] + reps;
+  if ((par_pos[1] >  half_y && par_dir[1] >= 0) ||
+      (par_pos[1] < -half_y && par_dir[1] <= 0))
+    return false;
+    
+  const double half_z = length[2] + reps;
+  if ((par_pos[2] >  half_z && par_dir[2] >= 0) ||
+      (par_pos[2] < -half_z && par_dir[2] <= 0))
+    return false;
+  
+    // test if point is inside
+  if (par_pos[0] <= half_x && par_pos[0] >= -half_x &&
+      par_pos[1] <= half_y && par_pos[1] >= -half_y &&
+      par_pos[2] <= half_z && par_pos[2] >= -half_z)
+    return true;
+
+    //test two xy plane
+  if ((half_z - par_pos[2]) * par_dir[2] >= 0 &&
+      fabs(par_dir[0] * (half_z - par_pos[2]) + par_dir[2] * par_pos[0]) 
+        <= fabs(par_dir[2] * half_x) && 
+      fabs(par_dir[1] * (half_z - par_pos[2]) + par_dir[2] * par_pos[1]) 
+        <= fabs(par_dir[2] * half_y)) 
+    return true;
+  if ((-half_z - par_pos[2]) * par_dir[2] >= 0 &&
+      fabs(par_dir[0] * (-half_z - par_pos[2]) + par_dir[2] * par_pos[0]) 
+        <= fabs(par_dir[2] * half_x) && 
+      fabs(par_dir[1] * (-half_z - par_pos[2]) + par_dir[2] * par_pos[1]) 
+        <= fabs(par_dir[2] * half_y))
+    return true;
+
+    //test two xz plane
+  if ((half_y - par_pos[1]) * par_dir[1] >= 0 &&
+      fabs(par_dir[0] * (half_y - par_pos[1]) + par_dir[1] * par_pos[0]) 
+        <= fabs(par_dir[1] * half_x) && 
+      fabs(par_dir[2] * (half_y - par_pos[1]) + par_dir[1] * par_pos[2]) 
+        <= fabs(par_dir[1] * half_z))
+    return true;
+  if ((-half_y - par_pos[1]) * par_dir[1] >= 0 &&
+      fabs(par_dir[0] * (-half_y - par_pos[1]) + par_dir[1] * par_pos[0]) 
+        <= fabs(par_dir[1] * half_x)  && 
+      fabs(par_dir[2] * (-half_y - par_pos[1]) + par_dir[1] * par_pos[2])
+        <= fabs(par_dir[1] * half_z))
+    return true;
+
+    //test two yz plane
+  if ((half_x - par_pos[0]) * par_dir[0] >= 0 &&
+      fabs(par_dir[1] * (half_x - par_pos[0]) + par_dir[0] * par_pos[1]) 
+        <= fabs(par_dir[0] * half_y) &&
+      fabs(par_dir[2] * (half_x - par_pos[0]) + par_dir[0] * par_pos[2]) 
+        <= fabs(par_dir[0] * half_z))
+    return true;
+  if ((-half_x - par_pos[0]) * par_dir[0] >= 0 &&
+      fabs(par_dir[1] * (-half_x - par_pos[0]) + par_dir[0] * par_pos[1])
+        <= fabs(par_dir[0] * half_y) &&
+      fabs(par_dir[2] * (-half_x - par_pos[0]) + par_dir[0] * par_pos[2]) 
+        <= fabs(par_dir[0] * half_z))
+    return true;
+
+  return false;
+}
+
+ErrorCode OrientedBox::make_hex( EntityHandle& hex, Interface* instance )
+{
+  ErrorCode rval;
+  int signs[8][3] = { { -1, -1, -1 },
+                      {  1, -1, -1 },
+                      {  1,  1, -1 },
+                      { -1,  1, -1 },
+                      { -1, -1,  1 },
+                      {  1, -1,  1 },
+                      {  1,  1,  1 },
+                      { -1,  1,  1 } };
+                      
+  std::vector<EntityHandle> vertices;
+  for (int i = 0; i < 8; ++i)
+  {
+    CartVect coords(center);
+    for (int j = 0; j < 3; ++j)
+      coords += signs[i][j] * axis[j];
+    EntityHandle handle;
+    rval = instance->create_vertex( coords.array(), handle );
+    if (MB_SUCCESS != rval) {
+      instance->delete_entities( &vertices[0], vertices.size() );
+      return rval;
+    }
+    vertices.push_back( handle );
+  }
+  
+  rval = instance->create_element( MBHEX, &vertices[0], vertices.size(), hex );
+  if (MB_SUCCESS != rval) {
+    instance->delete_entities( &vertices[0], vertices.size() );
+    return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+  
+void OrientedBox::closest_location_in_box( 
+                                    const CartVect& input_position,
+                                    CartVect& output_position ) const
+{
+    // get coordinates on box axes
+  const CartVect from_center = input_position - center;
+
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  CartVect local( from_center % axis[0],
+                    from_center % axis[1],
+                    from_center % axis[2] );
+
+  for (int i = 0; i < 3; ++i) {
+    if (local[i] < -length[i])
+      local[i] = -length[i];
+    else if (local[i] > length[i])
+      local[i] =  length[i];
+  }
+#else
+  CartVect local( (from_center % axis[0]) / (axis[0] % axis[0]),
+                    (from_center % axis[1]) / (axis[1] % axis[1]),
+                    (from_center % axis[2]) / (axis[2] % axis[2]) );
+
+  for (int i = 0; i < 3; ++i) {
+    if (local[i] < -1.0)
+      local[i] = -1.0;
+    else if (local[i] > 1.0)
+      local[i] = 1.0;
+  }
+#endif
+
+  output_position = center
+                  + local[0] * axis[0] 
+                  + local[1] * axis[1]
+                  + local[2] * axis[2];
+}
+  
+} // namespace moab

Copied: MOAB/trunk/src/OrientedBox.hpp (from rev 3583, MOAB/trunk/src/MBOrientedBox.hpp)
===================================================================
--- MOAB/trunk/src/OrientedBox.hpp	                        (rev 0)
+++ MOAB/trunk/src/OrientedBox.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,246 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file OrientedBox.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#ifndef MB_ORIENTED_BOX_HPP
+#define MB_ORIENTED_BOX_HPP
+
+#include "moab/Forward.hpp"
+#include "moab/CartVect.hpp"
+#include "Matrix3.hpp"
+
+#include <iosfwd>
+
+namespace moab {
+
+#define MB_ORIENTED_BOX_UNIT_VECTORS 1
+#define MB_ORIENTED_BOX_OUTER_RADIUS 1
+
+class Range;
+
+
+/**\brief Oriented bounding box
+ */
+class OrientedBox
+{
+public:
+  CartVect center;  //!< Box center
+  CartVect axis[3]; //!< Box axes, unit vectors sorted by extent of box along axis
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  CartVect length;  //!< distance from center to plane along each axis
+#endif
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  double radius;      //!< outer radius (1/2 diagonal length) of box
+#endif
+
+  inline OrientedBox() {}
+
+  OrientedBox( const CartVect axis[3], const CartVect& center );
+
+  inline double inner_radius() const; //!< radius of inscribed sphere
+  inline double outer_radius() const; //!< radius of circumscribed sphere
+  inline double outer_radius_squared(const double reps) const; //!< square of (radius+at least epsilon) of circumsphere
+  inline double inner_radius_squared(const double reps) const; //!< square of (radius-epsilon) of inscribed sphere
+  inline double volume() const;               //!< volume of box
+  inline CartVect dimensions() const;       //!< number of dimensions for which box is not flat
+  inline double area() const;                 //!< largest side area
+  inline CartVect scaled_axis( int index ) const; //!< get vector in direction of axis, from box center to face
+  
+  /** Test if point is contained in box */
+  bool contained( const CartVect& point, double tolerance ) const;
+  
+  //bool contained( const OrientedBox& other, double tolerance ) const;
+  
+  /**\brief get tag handle for storing oriented box
+   *
+   * Get the handle for the tag with the specified name and
+   * check that the tag is appropriate for storing instances
+   * of OrientedBox.  The resulting tag may be used to store
+   * instances of OrientedBox directly.
+   *
+   *\param handle_out  The TagHandle, passed back to caller
+   *\param name        The tag name
+   *\param create      If true, tag will be created if it does not exist
+   */
+  static ErrorCode tag_handle( Tag& handle_out,
+                                 Interface* instance, 
+                                 const char* name,
+                                 bool create = true );
+
+  /**\brief Calculate an oriented box from a set of vertices */
+  static ErrorCode compute_from_vertices( OrientedBox& result,
+                                            Interface* instance,
+                                            const Range& vertices );
+                                  
+  /**\brief Calculate an oriented box from a set of 2D elements */
+  static ErrorCode compute_from_2d_cells( OrientedBox& result,
+                                            Interface* instance,
+                                            const Range& elements );
+
+    /** Structure to hold temporary accumulated triangle data for
+     *  caculating box orietation.  See box_from_covariance_data
+     *  to see how this is used to calculate the final covariance matrix
+     *  and resulting box orientation.
+     */
+  struct CovarienceData {
+    CovarienceData() {}
+    CovarienceData( const Matrix3& m, const CartVect& c, double a)
+      : matrix(m), center(c), area(a) {}
+    Matrix3 matrix;    //!< Running sum for covariance matrix
+    CartVect center;   //!< Sum of triangle centroids weighted by 2*triangle area
+    double area;         //!< 2x the sum of the triangle areas
+  };
+  
+    /** Calculate a CovarienceData struct from a list of triangles */
+  static ErrorCode covariance_data_from_tris( CovarienceData& result,
+                                                Interface* moab_instance,
+                                                const Range& elements );
+  
+    /** Calculate an OrientedBox given an arrray of CovarienceData and 
+     *  the list  of vertices the box is to bound.
+     */
+  static ErrorCode compute_from_covariance_data( OrientedBox& result,
+                                          Interface* moab_instance,
+                                          const CovarienceData* orient_array,
+                                          unsigned orient_array_length,
+                                          const Range& vertices );
+  
+    /** Test for intersection of a ray (or line segment) with this box
+     *\param ray_start_point The base point of the ray
+     *\param ray_unit_direction The direction of the ray (must be unit length)
+     *\param distance_tolerance Tolerance to use in intersection checks
+     *\param segment_length Optional length of ray
+     */
+  bool intersect_ray( const CartVect& ray_start_point,
+                      const CartVect& ray_unit_direction,
+                      double distance_tolerance,
+                      const double* segment_length = 0 ) const;
+                      
+    /**\brief Find closest position on/within box to input position.
+     * 
+     * Find the closest position in the solid box to the input position.
+     * If the input position is on or within the box, then the output
+     * position will be the same as the input position.  If the input
+     * position is outside the box, the outside position will be the
+     * closest point on the box boundary to the input position.
+     */
+  void closest_location_in_box( const CartVect& input_position,
+                                CartVect& output_position ) const;
+                      
+    //! Construct a hexahedral element with the same shape as this box.
+  ErrorCode make_hex( EntityHandle& hex, Interface* instance );
+                                    
+  
+    /** Calculate an OrientedBox given a CovarienceData struct and
+     *  the list of points the box is to bound.
+     */
+  static ErrorCode compute_from_covariance_data( OrientedBox& result,
+                                          Interface* moab_instance,
+                                          CovarienceData& orientation_data,
+                                          const Range& vertices );
+};
+
+std::ostream& operator<<( std::ostream&, const OrientedBox& );
+
+double OrientedBox::inner_radius() const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return length[0];
+#else
+  return axis[0].length();
+#endif
+}
+
+double OrientedBox::outer_radius() const
+{
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  return radius;
+#elif MB_ORIENTED_BOX_UNIT_VECTORS
+  return length.length();
+#else
+  return (axis[0] + axis[1] + axis[2]).length();
+#endif
+}
+
+// Add at least epsilon to the radius, before squaring it.
+double OrientedBox::outer_radius_squared(const double reps) const
+{
+#if MB_ORIENTED_BOX_OUTER_RADIUS
+  return (radius+reps)*(radius+reps);
+#elif MB_ORIENTED_BOX_UNIT_VECTORS
+  CartVect tmp(length[0]+reps,length[1]+reps,length[2]+reps);
+  return tmp % tmp;
+#else
+  CartVect half_diag = axis[0] + axis[1] + axis[2];
+  half_diag += CartVect(reps,reps,reps);
+  return half_diag % half_diag;
+#endif
+}
+
+// Subtract epsilon from the length of the shortest axis, before squaring it.
+double OrientedBox::inner_radius_squared(const double reps) const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return (length[0]-reps) * (length[0]-reps);
+#else
+  CartVect tmp = axis[0];
+  tmp -= CartVect(reps,reps,reps);
+  return (tmp % tmp);
+#endif
+}
+
+double OrientedBox::volume() const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return 8 * length[0] * length[1] * length[2];
+#else
+  return fabs(8 * axis[0] % (axis[1] * axis[2]));
+#endif
+}
+
+CartVect OrientedBox::dimensions() const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return 2.0 * length;
+#else
+  return 2.0 * CartVect( axis[0].length(), axis[1].length(), axis[2].length() );
+#endif
+}
+
+double OrientedBox::area() const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return 4 * length[1] * length[2];
+#else
+  return 4 * (axis[1] * axis[2]).length();
+#endif
+}
+
+CartVect OrientedBox::scaled_axis( int index ) const
+{
+#if MB_ORIENTED_BOX_UNIT_VECTORS
+  return length[index] * axis[index];
+#else
+  return axis[index];
+#endif
+}
+  
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/OrientedBoxTreeTool.cpp (from rev 3583, MOAB/trunk/src/MBOrientedBoxTreeTool.cpp)
===================================================================
--- MOAB/trunk/src/OrientedBoxTreeTool.cpp	                        (rev 0)
+++ MOAB/trunk/src/OrientedBoxTreeTool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1967 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file OrientedBox.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
+#include "OrientedBox.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/GeomUtil.hpp"
+#include "moab/MBTagConventions.hpp"
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+#include <limits>
+#include <assert.h>
+#include <math.h>
+
+//#define MB_OBB_USE_VECTOR_QUERIES
+//#define MB_OBB_USE_TYPE_QUERIES
+
+namespace moab {
+
+#if defined(MB_OBB_USE_VECTOR_QUERIES) && defined(MB_OBB_USE_TYPE_QUERIES)
+# undef MB_OBB_USE_TYPE_QUERIES
+#endif
+
+const char DEFAULT_TAG_NAME[] = "OBB";
+
+OrientedBoxTreeTool::Op::~Op() {}
+
+OrientedBoxTreeTool::OrientedBoxTreeTool( Interface* i,
+                                              const char* tag_name,
+                                              bool destroy_created_trees )
+  : instance( i ), cleanUpTrees(destroy_created_trees)
+{
+  if (!tag_name)
+    tag_name = DEFAULT_TAG_NAME;
+  ErrorCode rval = OrientedBox::tag_handle( tagHandle, instance, tag_name, true );
+  if (MB_SUCCESS != rval)
+    tagHandle = 0;
+}
+
+OrientedBoxTreeTool::~OrientedBoxTreeTool()
+{
+  if (!cleanUpTrees)
+    return;
+    
+  while (!createdTrees.empty()) {
+    EntityHandle tree = createdTrees.back();
+      // make sure this is a tree (rather than some other, stale handle)
+    const void* data_ptr = 0;
+    ErrorCode rval = instance->tag_get_data( tagHandle, &tree, 1, &data_ptr );
+    if (MB_SUCCESS == rval)
+      rval = delete_tree( tree );
+    if (MB_SUCCESS != rval)
+      createdTrees.pop_back();
+  }
+}
+
+OrientedBoxTreeTool::Settings::Settings() 
+  : max_leaf_entities( 8 ),
+    max_depth( 0 ),
+    worst_split_ratio( 0.95 ),
+    best_split_ratio( 0.4 ),
+    set_options( MESHSET_SET )
+  {}
+
+bool OrientedBoxTreeTool::Settings::valid() const
+{
+  return max_leaf_entities > 0 
+      && max_depth >= 0
+      && worst_split_ratio <= 1.0
+      && best_split_ratio >= 0.0
+      && worst_split_ratio >= best_split_ratio
+      ;
+}
+
+
+/********************** Simple Tree Access Methods ****************************/
+
+
+ErrorCode OrientedBoxTreeTool::box( EntityHandle set, OrientedBox& obb )
+{
+  return instance->tag_get_data( tagHandle, &set, 1, &obb );
+}
+
+ErrorCode OrientedBoxTreeTool::box( EntityHandle set,
+                                        double center[3],
+                                        double axis1[3],
+                                        double axis2[3],
+                                        double axis3[3] )
+{
+  OrientedBox obb;
+  ErrorCode rval = this->box( set, obb );
+  obb.center.get( center );
+  obb.scaled_axis(0).get( axis1 );
+  obb.scaled_axis(1).get( axis2 );
+  obb.scaled_axis(2).get( axis3 );
+  return rval;
+}
+
+
+/********************** Tree Construction Code ****************************/
+
+
+struct OrientedBoxTreeTool::SetData {
+  EntityHandle handle;
+  OrientedBox::CovarienceData box_data;
+  //Range vertices;
+};
+
+
+ErrorCode OrientedBoxTreeTool::build( const Range& entities,
+                                          EntityHandle& set_handle_out,
+                                          const Settings* settings )
+{
+  if (!entities.all_of_dimension(2))
+    return MB_TYPE_OUT_OF_RANGE;
+  if (settings && !settings->valid())
+    return MB_FAILURE;
+    
+  return build_tree( entities, set_handle_out, 0, 
+                     settings ? *settings : Settings() );
+}
+
+ErrorCode OrientedBoxTreeTool::join_trees( const Range& sets,
+                                               EntityHandle& set_handle_out,
+                                               const Settings* settings )
+{
+  if (!sets.all_of_type(MBENTITYSET))
+    return MB_TYPE_OUT_OF_RANGE;
+  if (settings && !settings->valid())
+    return MB_FAILURE;
+  
+    // Build initial set data list.
+  std::list<SetData> data;
+  for (Range::const_iterator i = sets.begin(); i != sets.end(); ++i) {
+    Range elements;
+    ErrorCode rval = instance->get_entities_by_dimension( *i, 2, elements, true );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (elements.empty())
+      continue;
+    
+    data.push_back( SetData() );
+    SetData& set_data = data.back();
+    set_data.handle = *i;
+    rval = OrientedBox::covariance_data_from_tris( set_data.box_data, instance, elements );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+
+  ErrorCode result = build_sets( data, set_handle_out, 0, 
+                          settings ? *settings : Settings() );
+  if (MB_SUCCESS != result)
+    return result;
+  
+  for (Range::reverse_iterator i = sets.rbegin(); i != sets.rend(); ++i) {
+    createdTrees.erase(
+      std::remove( createdTrees.begin(), createdTrees.end(), *i ), 
+      createdTrees.end() );
+  }
+  createdTrees.push_back( set_handle_out );
+  return MB_SUCCESS;
+}
+  
+
+/**\brief Split triangles by which side of a plane they are on
+ *
+ * Given a plane specified as a bisecting plane normal to one
+ * of the axes of a box, split triangles based on which side
+ * of the plane they are on.
+ *\param instance   MOAB instance
+ *\param box        The oriented box containing all the entities
+ *\param axis       The axis for which the split plane is orthogonal
+ *\param left_list  Output, entities to the left of the plane
+ *\param right_list Output, entities to the right of the plane
+ *\param num_intersecting Output, number entities intersecting plane
+ */
+static ErrorCode split_box( Interface* instance, 
+                              const OrientedBox& box, 
+                              int axis, 
+                              const Range& entities, 
+                              Range& left_list, 
+                              Range& right_list )
+{
+  ErrorCode rval;
+  left_list.clear();
+  right_list.clear();
+
+  std::vector<CartVect> coords;
+  for (Range::reverse_iterator i = entities.rbegin(); i != entities.rend(); ++i) {
+    const EntityHandle *conn;
+    int conn_len;
+    rval = instance->get_connectivity( *i, conn, conn_len );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    coords.resize( conn_len );
+    rval = instance->get_coords( conn, conn_len, coords[0].array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    CartVect centroid(0.0);
+    for (int j = 0; j < conn_len; ++j)
+      centroid += coords[j];
+    centroid /= conn_len;
+    
+    if ((box.axis[axis] % (centroid - box.center)) < 0.0)
+      left_list.insert( *i );
+    else
+      right_list.insert( *i );
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+ErrorCode OrientedBoxTreeTool::build_tree( const Range& entities,
+                                               EntityHandle& set,
+                                               int depth,
+                                               const Settings& settings )
+{
+  OrientedBox box;
+  ErrorCode rval;
+  
+  if (entities.empty()) {
+    CartVect axis[3] = { CartVect(0.), CartVect(0.), CartVect(0.) };
+    box = OrientedBox( axis, CartVect(0.) );
+  }
+  else {
+    rval = OrientedBox::compute_from_2d_cells( box, instance, entities );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+    // create an entity set for the tree node
+  rval = instance->create_meshset( settings.set_options, set );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = instance->tag_set_data( tagHandle, &set, 1, &box );
+  if (MB_SUCCESS != rval) 
+    { delete_tree( set ); return rval; }
+  
+    // check if should create children
+  bool leaf = true;
+  ++depth;
+  if ((!settings.max_depth || depth < settings.max_depth) && 
+      entities.size() > (unsigned)settings.max_leaf_entities) {
+      // try splitting with planes normal to each axis of the box
+      // until we find an acceptable split
+    double best_ratio = settings.worst_split_ratio; // worst case ratio
+    Range best_left_list, best_right_list;
+      // Axes are sorted from shortest to longest, so search backwards
+    for (int axis = 2; best_ratio > settings.best_split_ratio && axis >= 0; --axis) {
+      Range left_list, right_list;
+
+      rval = split_box( instance, box, axis, entities, left_list, right_list );
+      if (MB_SUCCESS != rval) 
+        { delete_tree( set ); return rval; }
+        
+      double ratio = fabs((double)right_list.size() - left_list.size()) / entities.size();
+      
+      if (ratio < best_ratio) {
+        best_ratio = ratio;
+        best_left_list.swap( left_list );
+        best_right_list.swap( right_list );
+      }
+    }
+    
+      // create children
+    if (!best_left_list.empty())
+    {
+      EntityHandle child = 0;
+      
+      rval = build_tree( best_left_list, child, depth, settings );
+      if (MB_SUCCESS != rval)
+        { delete_tree( set ); return rval; }
+      rval = instance->add_child_meshset( set, child );
+      if (MB_SUCCESS != rval)
+        { delete_tree( set ); delete_tree( child ); return rval; }
+      
+      rval = build_tree( best_right_list, child, depth, settings );
+      if (MB_SUCCESS != rval)
+        { delete_tree( set ); return rval; }
+      rval = instance->add_child_meshset( set, child );
+      if (MB_SUCCESS != rval)
+        { delete_tree( set ); delete_tree( child ); return rval; }
+      
+      leaf = false;
+    }
+  }
+  
+  if (leaf)
+  {
+    rval = instance->add_entities( set, entities );
+    if (MB_SUCCESS != rval) 
+      { delete_tree( set ); return rval; }
+  }
+  
+  createdTrees.push_back( set );
+  return MB_SUCCESS;
+}
+
+
+static ErrorCode split_sets( Interface* , 
+                               const OrientedBox& box, 
+                               int axis, 
+                               const std::list<OrientedBoxTreeTool::SetData>& sets,
+                               std::list<OrientedBoxTreeTool::SetData>& left,
+                               std::list<OrientedBoxTreeTool::SetData>& right )
+{
+  left.clear();
+  right.clear();
+
+  std::list<OrientedBoxTreeTool::SetData>::const_iterator i;
+  for (i = sets.begin(); i != sets.end(); ++i) {
+    CartVect centroid(i->box_data.center / i->box_data.area);
+    if ((box.axis[axis] % (centroid - box.center)) < 0.0)
+      left.push_back( *i );
+    else
+      right.push_back( *i );
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+ErrorCode OrientedBoxTreeTool::build_sets( std::list<SetData>& sets,
+                                               EntityHandle& node_set,
+                                               int depth,
+                                               const Settings& settings )
+{
+  ErrorCode rval;
+  int count = sets.size();
+  if (0 == count)
+    return MB_FAILURE;
+  
+    // calculate box
+  OrientedBox box;
+
+  // make vector go out of scope when done, so memory is released
+  { 
+    Range elems;
+    std::vector<OrientedBox::CovarienceData> data(sets.size());
+    data.clear();
+    for (std::list<SetData>::iterator i = sets.begin(); i != sets.end(); ++i) {
+      data.push_back( i->box_data );
+      rval = instance->get_entities_by_dimension( i->handle, 2, elems, true );
+      if (MB_SUCCESS != rval)
+        return rval;
+    }
+    
+    Range points;
+    rval = instance->get_adjacencies( elems, 0, false, points, Interface::UNION );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    rval = OrientedBox::compute_from_covariance_data( box, instance, &data[0], data.size(), points );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+    // If only one set in list...
+  if (count == 1) {
+    node_set = sets.front().handle;
+    return instance->tag_set_data( tagHandle, &node_set, 1, &box );
+  }
+  
+    // create an entity set for the tree node
+  rval = instance->create_meshset( settings.set_options, node_set );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = instance->tag_set_data( tagHandle, &node_set, 1, &box );
+  if (MB_SUCCESS != rval) 
+    { delete_tree( node_set ); return rval; }
+  
+  double best_ratio = 2.0; 
+  std::list<SetData> best_left_list, best_right_list;
+  for (int axis = 0; axis < 2; ++axis) {
+    std::list<SetData> left_list, right_list;
+    rval = split_sets( instance, box, axis, sets, left_list, right_list );
+    if (MB_SUCCESS != rval) 
+      { delete_tree( node_set ); return rval; }
+
+    double ratio = fabs((double)right_list.size() - left_list.size()) / sets.size();
+
+    if (ratio < best_ratio) {
+      best_ratio = ratio;
+      best_left_list.swap( left_list );
+      best_right_list.swap( right_list );
+    }
+  }
+  
+    // We must subdivide the list of sets, because we want to guarantee that
+    // there is a node in the tree corresponding to each of the sets.  So if
+    // we couldn't find a usable split plane, just split them in an arbitrary
+    // manner.
+  if (best_left_list.empty() || best_right_list.empty()) {
+    best_left_list.clear();
+    best_right_list.clear();
+    std::list<SetData>* lists[2] = {&best_left_list,&best_right_list};
+    int i = 0;
+    while (!sets.empty()) {
+      lists[i]->push_back( sets.front() );
+      sets.pop_front();
+      i = 1 - i;
+    }
+  }
+  else {
+    sets.clear(); // release memory before recursion
+  }
+  
+    // Create child sets
+    
+  EntityHandle child = 0;
+      
+  rval = build_sets( best_left_list, child, depth+1, settings );
+  if (MB_SUCCESS != rval)
+    { delete_tree( node_set ); return rval; }
+  rval = instance->add_child_meshset( node_set, child );
+  if (MB_SUCCESS != rval)
+    { delete_tree( node_set ); delete_tree( child ); return rval; }
+
+  rval = build_sets( best_right_list, child, depth+1, settings );
+  if (MB_SUCCESS != rval)
+    { delete_tree( node_set ); return rval; }
+  rval = instance->add_child_meshset( node_set, child );
+  if (MB_SUCCESS != rval)
+    { delete_tree( node_set ); delete_tree( child ); return rval; }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode OrientedBoxTreeTool::delete_tree( EntityHandle set )
+{
+  std::vector<EntityHandle> children;
+  ErrorCode rval = instance->get_child_meshsets( set, children, 0 );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  createdTrees.erase( 
+    std::remove( createdTrees.begin(), createdTrees.end(), set ),
+    createdTrees.end() );
+  children.insert( children.begin(), set );
+  return instance->delete_entities( &children[0], children.size() );
+}
+
+
+/********************** Generic Tree Traversal ****************************/
+
+
+struct Data { EntityHandle set; int depth; };
+ErrorCode OrientedBoxTreeTool::preorder_traverse( EntityHandle set,
+                                                      Op& operation, 
+                                                      TrvStats* accum )
+{
+  ErrorCode rval;
+  std::vector<EntityHandle> children;
+  std::vector<Data> the_stack;
+  Data data = { set, 0 };
+  the_stack.push_back( data );
+  int max_depth = -1;
+  
+  while (!the_stack.empty())
+  {
+    data = the_stack.back();
+    the_stack.pop_back();
+    
+    // increment traversal statistics
+    if( accum ){
+      accum->increment( data.depth );
+      max_depth = std::max( max_depth, data.depth );
+    }
+
+    bool descend = true;
+    rval = operation.visit( data.set, data.depth, descend );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    if (!descend)
+      continue;
+    
+    children.clear();
+    rval = instance->get_child_meshsets( data.set, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (children.empty()) {
+      if( accum ){ accum->increment_leaf( data.depth ); }
+      rval = operation.leaf( data.set );
+      if (MB_SUCCESS != rval)
+        return rval;
+    }
+    else if (children.size() == 2) {
+      data.depth++;
+      data.set = children[0];
+      the_stack.push_back( data );
+      data.set = children[1];
+      the_stack.push_back( data );
+    }
+    else
+      return MB_MULTIPLE_ENTITIES_FOUND;
+  }
+  
+  if( accum ){
+    accum->end_traversal( max_depth );
+  }
+
+  return MB_SUCCESS;
+}
+
+/********************** General Sphere/Triangle Intersection ***************/
+
+struct OBBTreeSITFrame { 
+  OBBTreeSITFrame( EntityHandle n, EntityHandle s, int dp )
+    : node(n), surf(s), depth(dp) {}
+  EntityHandle node;
+  EntityHandle surf;
+  int depth;
+};
+
+ErrorCode OrientedBoxTreeTool::sphere_intersect_triangles( 
+                                        const double* center_v,
+                                        double radius,
+                                        EntityHandle tree_root,
+                                        std::vector<EntityHandle>& facets_out,
+                                        std::vector<EntityHandle>* sets_out, 
+                                        TrvStats* accum )
+{
+  const double radsqr = radius * radius;
+  OrientedBox b;
+  ErrorCode rval;
+  Range sets;
+  const CartVect center(center_v);
+  CartVect closest, coords[3];
+  const EntityHandle* conn;
+  int num_conn;
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+  Range tris;
+  Range::const_iterator t;
+#else
+  std::vector<EntityHandle> tris;
+  std::vector<EntityHandle>::const_iterator t;
+#endif
+  
+  std::vector<OBBTreeSITFrame> stack;
+  std::vector<EntityHandle> children;
+  stack.reserve(30);
+  stack.push_back( OBBTreeSITFrame( tree_root, 0, 0 ) );
+
+  int max_depth = -1;
+
+  while (!stack.empty()) {
+    EntityHandle surf = stack.back().surf; 
+    EntityHandle node = stack.back().node;
+    int current_depth   = stack.back().depth;
+    stack.pop_back();
+    
+      // increment traversal statistics.  
+    if( accum ){
+      accum->increment( current_depth );
+      max_depth = std::max( max_depth, current_depth );
+    }
+
+    if (!surf && sets_out) {
+      rval = get_moab_instance()->get_entities_by_type( node, MBENTITYSET, sets );
+      if (!sets.empty())
+        surf = sets.front();
+      sets.clear();
+    }
+    
+      // check if sphere intersects box
+    rval = box( node, b );
+    if (MB_SUCCESS != rval)
+      return rval;
+    b.closest_location_in_box( center, closest );
+    closest -= center;
+    if ((closest % closest) > radsqr)
+      continue;
+    
+      // push child boxes on stack
+    children.clear();
+    rval = instance->get_child_meshsets( node, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (!children.empty()) {
+      assert(children.size() == 2);
+      stack.push_back( OBBTreeSITFrame( children[0], surf, current_depth + 1 ) );
+      stack.push_back( OBBTreeSITFrame( children[1], surf, current_depth + 1 ) );
+      continue;
+    }
+    
+    if(accum){ accum->increment_leaf( current_depth ); }
+      // if leaf, intersect sphere with triangles
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+# ifdef MB_OBB_USE_TYPE_QUERIES
+    rval = get_moab_instance()->get_entities_by_type( node, MBTRI, tris );
+# else
+    rval = get_moab_instance()->get_entities_by_handle( node, tris );
+# endif
+    t = tris.begin();
+#else
+    rval = get_moab_instance()->get_entities_by_handle( node, tris );
+    t = tris.lower_bound( MBTRI );
+#endif
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    for (t = tris.begin(); t != tris.end(); ++t) {
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+      if (TYPE_FROM_HANDLE(*t) != MBTRI)
+        break;
+#elif !defined(MB_OBB_USE_TYPE_QUERIES)
+      if (TYPE_FROM_HANDLE(*t) != MBTRI)
+        continue;
+#endif      
+      rval = get_moab_instance()->get_connectivity( *t, conn, num_conn, true );
+      if (MB_SUCCESS != rval)
+        return rval;
+      if (num_conn != 3)
+        continue;
+      
+      rval = get_moab_instance()->get_coords( conn, num_conn, coords[0].array() );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      GeomUtil::closest_location_on_tri( center, coords, closest );
+      closest -= center;
+      if ((closest % closest) <= radsqr &&
+          std::find(facets_out.begin(),facets_out.end(),*t) == facets_out.end()) {
+        facets_out.push_back( *t );
+        if (sets_out)
+          sets_out->push_back( surf );
+      }
+    }
+  }
+
+  if( accum ){
+    accum->end_traversal( max_depth );
+  }
+  
+  return MB_SUCCESS;
+}
+      
+
+
+/********************** General Ray/Tree and Ray/Triangle Intersection ***************/
+
+
+class RayIntersector : public OrientedBoxTreeTool::Op
+{
+  private:
+    OrientedBoxTreeTool* tool;
+    const CartVect b, m;
+    const double* len;
+    const double tol;
+    Range& boxes;
+    
+  public:
+    RayIntersector( OrientedBoxTreeTool* tool_ptr,
+                    const double* ray_point,
+                    const double* unit_ray_dir,
+                    const double *ray_length,
+                    double tolerance,
+                    Range& leaf_boxes )
+      : tool(tool_ptr),
+        b(ray_point), m(unit_ray_dir),
+        len(ray_length), tol(tolerance),
+        boxes(leaf_boxes) 
+      { }
+  
+    virtual ErrorCode visit( EntityHandle node,
+                               int depth,
+                               bool& descend );
+    virtual ErrorCode leaf( EntityHandle node );
+};
+
+//#include <stdio.h>
+//inline void dump_fragmentation( const Range& range ) {
+//  static FILE* file = fopen( "fragmentation", "w" );
+//  unsigned ranges = 0, entities = 0;
+//  for (Range::const_pair_iterator i = range.const_pair_begin(); i != range.const_pair_end(); ++i)
+//  {
+//    ++ranges;
+//    entities += i->second - i->first + 1;
+//  }
+//  fprintf( file, "%u %u\n", ranges, entities );
+//}
+
+ErrorCode OrientedBoxTreeTool::ray_intersect_triangles( 
+                          std::vector<double>& intersection_distances_out,
+                          const Range& boxes,
+                          double tolerance,
+                          const double ray_point[3],
+                          const double unit_ray_dir[3],
+                          const double* ray_length )
+{
+  ErrorCode rval;
+  intersection_distances_out.clear();
+  std::vector<EntityHandle> tris;
+    
+  const CartVect point( ray_point );
+  const CartVect dir( unit_ray_dir );
+  
+  for (Range::iterator b = boxes.begin(); b != boxes.end(); ++b)
+  {
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+    Range tris;
+# ifdef MB_OBB_USE_TYPE_QUERIES
+    rval = instance->get_entities_by_type( *b, MBTRI, tris );
+# else
+    rval = instance->get_entities_by_handle( *b, tris );
+# endif
+#else
+    tris.clear();
+    rval = instance->get_entities_by_handle( *b, tris );
+#endif
+    if (MB_SUCCESS != rval)
+      return rval;
+//dump_fragmentation( tris );
+    
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+    for (Range::iterator t = tris.begin(); t != tris.end(); ++t)
+#else
+    for (std::vector<EntityHandle>::iterator t = tris.begin(); t != tris.end(); ++t)
+#endif
+    {
+#ifndef MB_OBB_USE_TYPE_QUERIES
+      if (TYPE_FROM_HANDLE(*t) != MBTRI)
+        continue;
+#endif
+    
+      const EntityHandle* conn;
+      int len;
+      rval = instance->get_connectivity( *t, conn, len, true );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      CartVect coords[3];
+      rval = instance->get_coords( conn, 3, coords[0].array() );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      double td;
+      if (GeomUtil::ray_tri_intersect( coords, point, dir, tolerance, td, ray_length ))
+        intersection_distances_out.push_back(td);
+    }
+  }
+  
+  return MB_SUCCESS;
+}                    
+
+ErrorCode OrientedBoxTreeTool::ray_intersect_triangles( 
+                          std::vector<double>& intersection_distances_out,
+                          EntityHandle root_set,
+                          double tolerance,
+                          const double ray_point[3],
+                          const double unit_ray_dir[3],
+                          const double* ray_length, 
+                          TrvStats* accum )
+{
+  Range boxes;
+  ErrorCode rval;
+  
+  rval = ray_intersect_boxes( boxes, root_set, tolerance, ray_point, unit_ray_dir, ray_length, accum );
+  if (MB_SUCCESS != rval)
+    return rval;
+    
+  return ray_intersect_triangles( intersection_distances_out, boxes, tolerance, ray_point, unit_ray_dir, ray_length );
+}
+
+ErrorCode OrientedBoxTreeTool::ray_intersect_boxes( 
+                          Range& boxes_out,
+                          EntityHandle root_set,
+                          double tolerance,
+                          const double ray_point[3],
+                          const double unit_ray_dir[3],
+                          const double* ray_length, 
+                          TrvStats* accum )
+{
+  RayIntersector op( this, ray_point, unit_ray_dir, ray_length, tolerance, boxes_out );
+  return preorder_traverse( root_set, op, accum );
+}
+
+ErrorCode RayIntersector::visit( EntityHandle node,
+                                   int ,
+                                   bool& descend ) 
+{
+  OrientedBox box;
+  ErrorCode rval = tool->box( node, box );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  descend = box.intersect_ray( b, m, tol, len);
+  return MB_SUCCESS;
+}
+
+
+ErrorCode RayIntersector::leaf( EntityHandle node )
+{
+  boxes.insert(node);
+  return MB_SUCCESS;
+}
+
+
+/********************** Ray/Set Intersection ****************************/
+
+
+class RayIntersectSets : public OrientedBoxTreeTool::Op
+{
+  private:
+    OrientedBoxTreeTool* tool;
+    unsigned minTolInt;
+    const CartVect b, m;
+    const double* len;
+    const double tol;
+    std::vector<double>& intersections;
+    std::vector<EntityHandle>& sets;
+    std::vector<EntityHandle>& facets;    
+
+  EntityHandle lastSet;
+    int lastSetDepth;
+    
+  void add_intersection( double t, EntityHandle facet );
+    
+  public:
+    RayIntersectSets( OrientedBoxTreeTool* tool_ptr,
+                   const double* ray_point,
+                   const double* unit_ray_dir,
+                   const double *ray_length,
+                   double tolerance,
+                   unsigned min_tol_intersections,
+                   std::vector<double>& intersections,
+                   std::vector<EntityHandle>& surfaces,
+                   std::vector<EntityHandle>& facets )
+      : tool(tool_ptr), minTolInt(min_tol_intersections),
+        b(ray_point), m(unit_ray_dir),
+        len(ray_length), tol(tolerance),
+        intersections(intersections),
+        sets(surfaces), facets(facets), lastSet(0)
+      { }
+  
+    virtual ErrorCode visit( EntityHandle node,
+                               int depth,
+                               bool& descend );
+    virtual ErrorCode leaf( EntityHandle node );
+};
+
+ErrorCode RayIntersectSets::visit( EntityHandle node,
+                                     int depth,
+                                     bool& descend ) 
+{
+  OrientedBox box;
+  ErrorCode rval = tool->box( node, box );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  descend = box.intersect_ray( b, m, tol, len);
+  
+  if (lastSet && depth <= lastSetDepth)
+    lastSet = 0;
+
+  if (descend && !lastSet) {
+    Range sets;
+    rval = tool->get_moab_instance()->get_entities_by_type( node, MBENTITYSET, sets );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    if (!sets.empty()) {
+      if (sets.size() > 1)
+        return MB_FAILURE;
+      lastSet = *sets.begin();
+      lastSetDepth = depth;
+    }
+  }
+    
+  return MB_SUCCESS;
+}
+
+ErrorCode RayIntersectSets::leaf( EntityHandle node )
+{
+  if (!lastSet) // if no surface has been visited yet, something's messed up.
+    return MB_FAILURE;
+  
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+  Range tris;
+# ifdef MB_OBB_USE_TYPE_QUERIES
+  ErrorCode rval = tool->get_moab_instance()->get_entities_by_type( node, MBTRI, tris );
+# else
+  ErrorCode rval = tool->get_moab_instance()->get_entities_by_handle( node, tris );
+# endif
+#else
+  std::vector<EntityHandle> tris;
+  ErrorCode rval = tool->get_moab_instance()->get_entities_by_handle( node, tris );
+#endif
+  if (MB_SUCCESS != rval)
+    return rval;
+
+#ifndef MB_OBB_USE_VECTOR_QUERIES
+  for (Range::iterator t = tris.begin(); t != tris.end(); ++t)
+#else
+  for (std::vector<EntityHandle>::iterator t = tris.begin(); t != tris.end(); ++t)
+#endif
+  {
+#ifndef MB_OBB_USE_TYPE_QUERIES
+    if (TYPE_FROM_HANDLE(*t) != MBTRI)
+      continue;
+#endif
+    
+    const EntityHandle* conn;
+    int num_conn;
+    rval = tool->get_moab_instance()->get_connectivity( *t, conn, num_conn, true );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    CartVect coords[3];
+    rval = tool->get_moab_instance()->get_coords( conn, 3, coords[0].array() );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    double td;
+    if (GeomUtil::ray_tri_intersect( coords, b, m, tol, td, len )) 
+        // NOTE: add_intersection may modify the 'len' member, which
+        //       will affect subsequent calls to ray_tri_intersect in 
+        //       this loop.
+      add_intersection( td, *t );
+  }
+  return MB_SUCCESS;
+}
+
+void RayIntersectSets::add_intersection( double t, EntityHandle facet )
+{
+    // Check if the 'len' pointer is pointing into the intersection
+    // list.  If this is the case, then the list contains, at that
+    // location, an intersection greater than the tolerance away from
+    // the base point of the ray.
+  int len_idx = -1;
+  if (len && len >= &intersections[0] && len < &intersections[0] + intersections.size())
+    len_idx = len - &intersections[0];
+
+    // If the intersection is within tol of the ray base point, we 
+    // always add it to the list.
+  if (t <= tol) {
+      // If the list contains an intersection outside the tolerance...
+    if (len_idx >= 0) {
+        // If we no longer want an intersection outside the tolerance,
+        // remove it.
+      if (intersections.size() >= minTolInt) {
+        intersections[len_idx] = t;
+        sets[len_idx] = lastSet;
+        facets[len_idx] = facet;
+          // From now on, we want only intersections within the tolerance,
+          // so update length accordingly
+        len = &tol;
+      }
+        // Otherwise appended to the list and update pointer
+      else {
+        intersections.push_back(t);
+        sets.push_back(lastSet);
+        facets.push_back(facet);
+        len = &intersections[len_idx];
+      }
+    }
+      // Otherwise just append it
+    else {
+      intersections.push_back(t);
+      sets.push_back(lastSet);
+      facets.push_back(facet);
+        // If we have all the intersections we want, set
+        // length such that we will only find further intersections
+        // within the tolerance
+      if (intersections.size() >= minTolInt)
+        len = &tol;
+    }
+  }
+    // Otherwise the intersection is outside the tolerance
+    // If we already have an intersection outside the tolerance and
+    // this one is closer, replace the existing one with this one.
+  else if (len_idx >= 0) {
+    if (t <= *len) {
+      intersections[len_idx] = t;
+      sets[len_idx] = lastSet;
+      facets[len_idx] = facet;
+    }
+  }
+    // Otherwise if we want an intersection outside the tolerance
+    // and don'thave one yet, add it.
+  else if (intersections.size() < minTolInt) {
+    intersections.push_back( t );
+    sets.push_back( lastSet );
+    facets.push_back(facet);
+      // update length.  this is currently the closest intersection, so
+      // only want further intersections that are closer than this one.
+    len = &intersections.back();
+  }
+}
+  
+
+ErrorCode OrientedBoxTreeTool::ray_intersect_sets( 
+                                    std::vector<double>& distances_out,
+                                    std::vector<EntityHandle>& sets_out,
+                                    std::vector<EntityHandle>& facets_out,
+                                    EntityHandle root_set,
+                                    double tolerance,
+                                    unsigned min_tolerace_intersections,
+                                    const double ray_point[3],
+                                    const double unit_ray_dir[3],
+                                    const double* ray_length, 
+                                    TrvStats* accum )
+{
+  RayIntersectSets op( this, ray_point, unit_ray_dir, ray_length, tolerance, 
+                       min_tolerace_intersections, distances_out, sets_out, facets_out ); 
+  return preorder_traverse( root_set, op, accum );
+}
+
+
+
+/********************** Closest Point code ***************/
+
+struct OBBTreeCPFrame {
+  OBBTreeCPFrame( double d, EntityHandle n, EntityHandle s, int dp )
+    : dist_sqr(d), node(n), mset(s), depth(dp) {}
+  double dist_sqr;
+  EntityHandle node;
+  EntityHandle mset;
+  int depth;
+};
+
+ErrorCode OrientedBoxTreeTool::closest_to_location( 
+                                     const double* point,
+                                     EntityHandle root,
+                                     double* point_out,
+                                     EntityHandle& facet_out,
+                                     EntityHandle* set_out,
+                                     TrvStats* accum ) 
+{
+  ErrorCode rval;
+  const CartVect loc( point );
+  double smallest_dist_sqr = std::numeric_limits<double>::max();
+  
+  EntityHandle current_set = 0;
+  Range sets;
+  std::vector<EntityHandle> children(2);
+  std::vector<double> coords;
+  std::vector<OBBTreeCPFrame> stack;
+  int max_depth = -1;
+
+  stack.push_back( OBBTreeCPFrame(0.0, root, current_set, 0) );
+  
+  while( !stack.empty() ) {
+
+      // pop from top of stack
+    EntityHandle node = stack.back().node;
+    double dist_sqr = stack.back().dist_sqr;
+    current_set = stack.back().mset;
+    int current_depth = stack.back().depth;
+    stack.pop_back();
+
+      // If current best result is closer than the box, skip this tree node.
+    if (dist_sqr > smallest_dist_sqr)
+      continue;
+
+      // increment traversal statistics.  
+    if( accum ){
+      accum->increment( current_depth );
+      max_depth = std::max( max_depth, current_depth );
+    }
+
+      // Check if this node has a set associated with it
+    if (set_out && !current_set) {
+      sets.clear();
+      rval = instance->get_entities_by_type( node, MBENTITYSET, sets );
+      if (MB_SUCCESS != rval)
+        return rval;
+      if (!sets.empty()) {
+        if (sets.size() != 1)
+          return MB_MULTIPLE_ENTITIES_FOUND;
+        current_set = sets.front();
+      }
+    }
+
+      // Get child boxes
+    children.clear();
+    rval = instance->get_child_meshsets( node, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+      // if not a leaf node
+    if (!children.empty()) {
+      if (children.size() != 2)
+        return MB_MULTIPLE_ENTITIES_FOUND;
+    
+        // get boxes
+      OrientedBox box1, box2;
+      rval = box( children[0], box1 );
+      if (MB_SUCCESS != rval) return rval;
+      rval = box( children[1], box2 );
+      if (MB_SUCCESS != rval) return rval;
+      
+        // get distance from each box
+      CartVect pt1, pt2;
+      box1.closest_location_in_box( loc, pt1 );
+      box2.closest_location_in_box( loc, pt2 );
+      pt1 -= loc;
+      pt2 -= loc;
+      const double dsqr1 = pt1 % pt1;
+      const double dsqr2 = pt2 % pt2;
+      
+        // push children on tree such that closer one is on top
+      if (dsqr1 < dsqr2) {
+        stack.push_back( OBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
+        stack.push_back( OBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
+      }
+      else {
+        stack.push_back( OBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
+        stack.push_back( OBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
+      }
+    }
+    else { // LEAF NODE
+      if( accum ){ accum->increment_leaf( current_depth ); }
+
+      Range facets;
+      rval = instance->get_entities_by_dimension( node, 2, facets );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      const EntityHandle* conn;
+      int len;
+      CartVect tmp, diff;
+      for (Range::iterator i = facets.begin(); i != facets.end(); ++i) {
+        rval = instance->get_connectivity( *i, conn, len, true );
+        if (MB_SUCCESS != rval)
+          return rval;
+        
+        coords.resize(3*len);
+        rval = instance->get_coords( conn, len, &coords[0] );
+        if (MB_SUCCESS != rval)
+          return rval;
+        
+        if (len == 3) 
+          GeomUtil::closest_location_on_tri( loc, (CartVect*)(&coords[0]), tmp );
+        else
+          GeomUtil::closest_location_on_polygon( loc, (CartVect*)(&coords[0]), len, tmp );
+        
+        diff = tmp - loc;
+        dist_sqr = diff % diff;
+        if (dist_sqr < smallest_dist_sqr) {
+          smallest_dist_sqr = dist_sqr;
+          facet_out = *i;
+          tmp.get( point_out );
+          if (set_out)
+            *set_out = current_set;
+        }
+      }
+    } // LEAF NODE
+  }
+
+  if( accum ){
+    accum->end_traversal( max_depth );
+  }
+  
+  return MB_SUCCESS;
+}
+                                     
+ErrorCode OrientedBoxTreeTool::closest_to_location( const double* point,
+                                     EntityHandle root,
+                                     double tolerance,
+                                     std::vector<EntityHandle>& facets_out,
+                                     std::vector<EntityHandle>* sets_out, 
+                                     TrvStats* accum )
+{
+  ErrorCode rval;
+  const CartVect loc( point );
+  double smallest_dist_sqr = std::numeric_limits<double>::max();
+  double smallest_dist = smallest_dist_sqr;
+  
+  EntityHandle current_set = 0;
+  Range sets;
+  std::vector<EntityHandle> children(2);
+  std::vector<double> coords;
+  std::vector<OBBTreeCPFrame> stack;
+  int max_depth = -1;
+
+  stack.push_back( OBBTreeCPFrame(0.0, root, current_set, 0) );
+  
+  while( !stack.empty() ) {
+
+      // pop from top of stack
+    EntityHandle node = stack.back().node;
+    double dist_sqr = stack.back().dist_sqr;
+    current_set = stack.back().mset;
+    int current_depth = stack.back().depth;
+    stack.pop_back();
+
+      // If current best result is closer than the box, skip this tree node.
+    if (dist_sqr > smallest_dist_sqr + tolerance)
+      continue;
+
+      // increment traversal statistics.  
+    if( accum ){
+      accum->increment( current_depth );
+      max_depth = std::max( max_depth, current_depth );
+    }
+
+      // Check if this node has a set associated with it
+    if (sets_out && !current_set) {
+      sets.clear();
+      rval = instance->get_entities_by_type( node, MBENTITYSET, sets );
+      if (MB_SUCCESS != rval)
+        return rval;
+      if (!sets.empty()) {
+        if (sets.size() != 1)
+          return MB_MULTIPLE_ENTITIES_FOUND;
+        current_set = *sets.begin();
+      }
+    }
+
+      // Get child boxes
+    children.clear();
+    rval = instance->get_child_meshsets( node, children );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+      // if not a leaf node
+    if (!children.empty()) {
+      if (children.size() != 2)
+        return MB_MULTIPLE_ENTITIES_FOUND;
+    
+        // get boxes
+      OrientedBox box1, box2;
+      rval = box( children[0], box1 );
+      if (MB_SUCCESS != rval) return rval;
+      rval = box( children[1], box2 );
+      if (MB_SUCCESS != rval) return rval;
+      
+        // get distance from each box
+      CartVect pt1, pt2;
+      box1.closest_location_in_box( loc, pt1 );
+      box2.closest_location_in_box( loc, pt2 );
+      pt1 -= loc;
+      pt2 -= loc;
+      const double dsqr1 = pt1 % pt1;
+      const double dsqr2 = pt2 % pt2;
+      
+        // push children on tree such that closer one is on top
+      if (dsqr1 < dsqr2) {
+        stack.push_back( OBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
+        stack.push_back( OBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
+      }
+      else {
+        stack.push_back( OBBTreeCPFrame(dsqr1, children[0], current_set, current_depth+1 ) );
+        stack.push_back( OBBTreeCPFrame(dsqr2, children[1], current_set, current_depth+1 ) );
+      }
+    }
+    else { // LEAF NODE
+      if( accum ){ accum->increment_leaf( current_depth ); }
+
+      Range facets;
+      rval = instance->get_entities_by_dimension( node, 2, facets );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      const EntityHandle* conn;
+      int len;
+      CartVect tmp, diff;
+      for (Range::iterator i = facets.begin(); i != facets.end(); ++i) {
+        rval = instance->get_connectivity( *i, conn, len, true );
+        if (MB_SUCCESS != rval)
+          return rval;
+        
+        coords.resize(3*len);
+        rval = instance->get_coords( conn, len, &coords[0] );
+        if (MB_SUCCESS != rval)
+          return rval;
+        
+        if (len == 3) 
+          GeomUtil::closest_location_on_tri( loc, (CartVect*)(&coords[0]), tmp );
+        else
+          GeomUtil::closest_location_on_polygon( loc, (CartVect*)(&coords[0]), len, tmp );
+        
+        diff = tmp - loc;
+        dist_sqr = diff % diff;
+        if (dist_sqr < smallest_dist_sqr) {
+          if (0.5*dist_sqr < 0.5*smallest_dist_sqr + tolerance*(0.5*tolerance - smallest_dist)) {
+            facets_out.clear();
+            if (sets_out)
+              sets_out->clear();
+          }
+          smallest_dist_sqr = dist_sqr;
+          smallest_dist = sqrt(smallest_dist_sqr);
+            // put closest result at start of lists
+          facets_out.push_back( *i );
+          std::swap( facets_out.front(), facets_out.back() );
+          if (sets_out) {
+            sets_out->push_back( current_set );
+            std::swap( sets_out->front(), sets_out->back() );
+          }
+        }
+        else if (dist_sqr <= smallest_dist_sqr + tolerance*(tolerance + 2*smallest_dist)) {
+          facets_out.push_back(*i);
+          if (sets_out)
+            sets_out->push_back( current_set );
+        }
+      }
+    } // LEAF NODE
+  }
+
+  if( accum ){
+    accum->end_traversal( max_depth );
+  }
+  
+  return MB_SUCCESS;
+}
+    
+    
+
+/********************** Tree Printing Code ****************************/
+
+
+class TreeLayoutPrinter : public OrientedBoxTreeTool::Op
+{
+  public:
+    TreeLayoutPrinter( std::ostream& stream,
+                       Interface* instance );
+    
+    virtual ErrorCode visit( EntityHandle node, 
+                               int depth,
+                               bool& descend );
+    virtual ErrorCode leaf( EntityHandle node );
+  private:
+
+    Interface* instance;
+    std::ostream& outputStream;
+    std::vector<bool> path;
+};
+
+TreeLayoutPrinter::TreeLayoutPrinter( std::ostream& stream,
+                                      Interface* interface )
+  : instance(interface),
+    outputStream(stream)
+  {}
+
+ErrorCode TreeLayoutPrinter::visit( EntityHandle node, 
+                                      int depth,
+                                      bool& descend )
+{
+  descend = true;
+  
+  if ((unsigned)depth > path.size()) {
+    //assert(depth+1 == path.size); // preorder traversal
+    path.push_back(true);
+  }
+  else {
+    path.resize( depth );
+    if (depth)
+      path.back() = false;
+  }
+  
+  for (unsigned i = 0; i+1 < path.size(); ++i) {
+    if (path[i])
+      outputStream << "|   ";
+    else
+      outputStream << "    ";
+  }
+  if (depth) {
+    if (path.back())
+      outputStream << "+---";
+    else
+      outputStream << "\\---";
+  }
+  outputStream << instance->id_from_handle( node ) << std::endl;
+  return MB_SUCCESS;
+}
+
+ErrorCode TreeLayoutPrinter::leaf( EntityHandle ) { return MB_SUCCESS; }
+    
+
+class TreeNodePrinter : public OrientedBoxTreeTool::Op
+{
+  public:
+    TreeNodePrinter( std::ostream& stream,
+                     bool list_contents,
+                     bool list_box,
+                     const char* id_tag_name,
+                     OrientedBoxTreeTool* tool_ptr );
+    
+    virtual ErrorCode visit( EntityHandle node, 
+                               int depth,
+                               bool& descend );
+                               
+    virtual ErrorCode leaf( EntityHandle ) { return MB_SUCCESS; }
+  private:
+  
+    ErrorCode print_geometry( EntityHandle node );
+    ErrorCode print_contents( EntityHandle node );
+    ErrorCode print_counts( EntityHandle node );
+  
+    bool printContents;
+    bool printGeometry;
+    bool haveTag;
+    Tag tag, gidTag, geomTag;
+    Interface* instance;
+    OrientedBoxTreeTool* tool;
+    std::ostream& outputStream;
+};
+
+
+TreeNodePrinter::TreeNodePrinter( std::ostream& stream,
+                                  bool list_contents,
+                                  bool list_box,
+                                  const char* id_tag_name,
+                                  OrientedBoxTreeTool* tool_ptr )
+  : printContents( list_contents ),
+    printGeometry( list_box ),
+    haveTag( false ),
+    tag( 0 ),
+    gidTag(0), geomTag(0),
+    instance( tool_ptr->get_moab_instance() ),
+    tool(tool_ptr),
+    outputStream( stream )
+{
+  ErrorCode rval;
+  if (id_tag_name) {
+    rval = instance->tag_get_handle( id_tag_name, tag );
+    if (!rval) {
+      std::cerr << "Could not get tag \"" << id_tag_name << "\"\n";
+      stream << "Could not get tag \"" << id_tag_name << "\"\n";
+    }
+    else {
+      int size;
+      rval = instance->tag_get_size( tag, size );
+      if (!rval) {
+        std::cerr << "Could not get size for tag \"" << id_tag_name << "\"\n";
+        stream << "Could not get size for tag \"" << id_tag_name << "\"\n";
+      }
+      else if (size != sizeof(int)) {
+        std::cerr << "Tag \"" << id_tag_name << "\" is not an integer\n";
+        stream << "Tag \"" << id_tag_name << "\" is not an integer\n";
+      }
+      else {
+        haveTag = true;
+      }
+    }
+  }
+  
+  rval = instance->tag_get_handle( GLOBAL_ID_TAG_NAME, gidTag );
+  if (MB_SUCCESS != rval)
+    gidTag = 0;
+  rval = instance->tag_get_handle( GEOM_DIMENSION_TAG_NAME, geomTag );
+  if (MB_SUCCESS != rval)
+    geomTag = 0;
+}   
+
+ErrorCode TreeNodePrinter::visit( EntityHandle node, int, bool& descend )
+{
+  descend = true;
+  EntityHandle setid = instance->id_from_handle( node );
+  outputStream << setid << ":" << std::endl;
+  
+  Range surfs;
+  ErrorCode r3 = MB_SUCCESS;
+  if (geomTag) {
+    const int two = 2;
+    const void* tagdata[] = {&two};
+    r3 = instance->get_entities_by_type_and_tag( node, MBENTITYSET, &geomTag, tagdata, 1, surfs );
+  
+    if (MB_SUCCESS == r3 && surfs.size() == 1) {
+      EntityHandle surf = *surfs.begin();
+      int id;
+      if (gidTag && MB_SUCCESS == instance->tag_get_data( gidTag, &surf, 1, &id ))
+        outputStream << "  Surface " << id << std::endl;
+      else
+        outputStream << "  Surface w/ unknown ID (" << surf << ")" << std::endl;
+    }
+  }
+  
+  ErrorCode r1 = printGeometry ? print_geometry( node ) : MB_SUCCESS;
+  ErrorCode r2 = printContents ? print_contents( node ) : print_counts( node );
+  outputStream << std::endl;
+  
+  if (MB_SUCCESS != r1)
+    return r1;
+  else if (MB_SUCCESS != r2)
+    return r2;
+  else
+    return r3;
+}
+
+ErrorCode TreeNodePrinter::print_geometry( EntityHandle node )
+{
+  OrientedBox box;
+  ErrorCode rval= tool->box( node, box );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  CartVect length = box.dimensions();
+  
+  outputStream << box.center << "  Radius: " 
+               << box.inner_radius() << " - " << box.outer_radius() << std::endl
+               << '+' << box.axis[0] << " : " << length[0] << std::endl
+               << 'x' << box.axis[1] << " : " << length[1] << std::endl
+               << 'x' << box.axis[2] << " : " << length[2] << std::endl;
+  return MB_SUCCESS;
+}
+
+ErrorCode TreeNodePrinter::print_counts( EntityHandle node )
+{
+  for (EntityType type = MBVERTEX; type != MBMAXTYPE; ++type) {
+    int count = 0;
+    ErrorCode rval = instance->get_number_entities_by_type( node, type, count );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if(count > 0)
+      outputStream << " " << count << " " << MBCN::EntityTypeName(type) << std::endl;
+  }
+  return MB_SUCCESS;
+}
+
+ErrorCode TreeNodePrinter::print_contents( EntityHandle node )
+{
+    // list contents
+  for (EntityType type = MBVERTEX; type != MBMAXTYPE; ++type) {
+    Range range;
+    ErrorCode rval = instance->get_entities_by_type( node, type, range );
+    if (MB_SUCCESS != rval)
+      return rval;
+    if (range.empty())
+      continue;
+    outputStream << " " << MBCN::EntityTypeName(type) << " ";  
+    std::vector<int> ids( range.size() );
+    if (haveTag) {
+      rval = instance->tag_get_data( tag, range, &ids[0] );
+      std::sort( ids.begin(), ids.end() );
+    }
+    else {
+      Range::iterator ri = range.begin();
+      std::vector<int>::iterator vi = ids.begin();
+      while (ri != range.end()) {
+        *vi = instance->id_from_handle( *ri );
+        ++ri;
+        ++vi;
+      }
+    }
+    
+    unsigned i = 0;
+    for(;;) {
+      unsigned beg = i, end;
+      do { end = i++; } while (i < ids.size() && ids[end]+1 == ids[i]);
+      if (end == beg)
+        outputStream << ids[end];
+      else if (end == beg+1) 
+        outputStream << ids[beg] << ", " << ids[end];
+      else
+        outputStream << ids[beg] << "-" << ids[end];
+        
+      if (i == ids.size()) {
+        outputStream << std::endl;
+        break;
+      }
+      else 
+        outputStream << ", ";
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+  
+void OrientedBoxTreeTool::print( EntityHandle set, std::ostream& str, bool list, const char* tag )
+{
+  TreeLayoutPrinter op1( str, instance );
+  TreeNodePrinter op2( str, list, true, tag, this );
+  ErrorCode r1 = preorder_traverse( set, op1 );
+  str << std::endl;
+  ErrorCode r2 = preorder_traverse( set, op2 );
+  if (r1 != MB_SUCCESS || r2 != MB_SUCCESS) {
+    std::cerr << "Errors encountered while printing tree\n";
+    str << "Errors encountered while printing tree\n";
+  }
+}
+
+
+/********************* Traversal Metrics Code  **************************/
+
+void OrientedBoxTreeTool::TrvStats::reset(){
+  nodes_visited_count.clear();
+  leaves_visited_count.clear();
+  traversals_ended_count.clear();
+}
+
+void OrientedBoxTreeTool::TrvStats::increment( unsigned depth ){
+
+  while( nodes_visited_count.size() <= depth ){
+    nodes_visited_count.push_back(0);
+    leaves_visited_count.push_back(0);
+    traversals_ended_count.push_back(0);
+  }
+  nodes_visited_count[depth] += 1;
+}
+
+void OrientedBoxTreeTool::TrvStats::increment_leaf( unsigned depth ){
+  //assume safe depth, because increment is called first
+  leaves_visited_count[depth] += 1;
+}
+
+void OrientedBoxTreeTool::TrvStats::end_traversal( unsigned depth ){
+  // assume safe depth, because increment is always called on a given 
+  // tree level first
+  traversals_ended_count[depth] += 1;
+}
+
+void OrientedBoxTreeTool::TrvStats::print( std::ostream& str ) const {
+
+  const std::string h1 = "OBBTree Depth";
+  const std::string h2 = " - NodesVisited";
+  const std::string h3 = " - LeavesVisited";
+  const std::string h4 = " - TraversalsEnded";
+
+  str << h1 << h2 << h3 << h4 << std::endl;
+
+  unsigned num_visited = 0, num_leaves = 0, num_traversals = 0;
+  for( unsigned i = 0; i < traversals_ended_count.size(); ++i){
+
+    num_visited    += nodes_visited_count[i];
+    num_leaves     += leaves_visited_count[i];
+    num_traversals += traversals_ended_count[i];
+   
+    str << std::setw(h1.length()) << i 
+        << std::setw(h2.length()) << nodes_visited_count[i] 
+        << std::setw(h3.length()) << leaves_visited_count[i]
+        << std::setw(h4.length()) << traversals_ended_count[i] 
+        << std::endl;
+  }
+  
+  str << std::setw(h1.length()) << "---- Totals:" 
+      << std::setw(h2.length()) << num_visited 
+      << std::setw(h3.length()) << num_leaves
+      << std::setw(h4.length()) << num_traversals 
+      << std::endl;
+
+}
+
+/********************** Tree Statistics Code ****************************/
+
+
+struct StatData {
+  struct Ratio {
+    double min, max, sum, sqr;
+    int hist[10];
+    Ratio() 
+      : min(std::numeric_limits<double>::max()), 
+        max(-std::numeric_limits<double>::max()), 
+        sum(0.0), sqr(0.0)
+      { hist[0] = hist[1] = hist[2] = hist[3] = hist[4] = hist[5] =
+        hist[6] = hist[7] = hist[8] = hist[9] = 0; }
+    void accum( double v ) {
+      if (v < min) min = v;
+      if (v > max) max = v;
+      sum += v;
+      sqr += v*v;
+      int i = (int)(10*v);
+      if (i < 0) i = 0;
+      else if (i > 9) i = 9;
+      ++hist[i];
+    }
+  };
+  
+  template <typename T> struct Stat {
+    T min, max;
+    double sum, sqr;
+    Stat() : sum(0.0), sqr(0.0) {
+      std::numeric_limits<T> lim;
+      min = lim.max();
+      if (lim.is_integer)
+        max = lim.min();
+      else
+        max = -lim.max();
+    }
+    void accum( T v ) {
+      if (v < min) min = v;
+      if (v > max) max = v;
+      sum += v;
+      sqr += (double)v * v;
+    }
+  };
+
+  StatData() :
+    count(0) 
+    {}
+
+  Ratio volume;
+  Ratio entities;
+  Ratio radius;
+  Stat<unsigned> leaf_ent;
+  Stat<double> vol;
+  Stat<double> area;
+  std::vector<unsigned> leaf_depth;
+  unsigned count;
+};
+
+static int measure( const CartVect& v, double& result )
+{
+  const double tol = 1e-6;
+  int dims = 0;
+  result = 1;
+  for (int i = 0; i < 3; ++i)
+    if (v[i] > tol) {
+      ++dims; 
+      result *= v[i];
+  }
+  return dims;
+}
+  
+
+static ErrorCode recursive_stats( OrientedBoxTreeTool* tool,
+                                    Interface* instance,
+                                    EntityHandle set,
+                                    int depth,
+                                    StatData& data,
+                                    unsigned& count_out,
+                                    CartVect& dimensions_out )
+{
+  ErrorCode rval;
+  OrientedBox box;
+  std::vector<EntityHandle> children(2);
+  unsigned counts[2];
+  bool isleaf;
+  
+  ++data.count;
+  
+  rval = tool->box( set, box );
+  if (MB_SUCCESS != rval) return rval;
+  children.clear();
+  rval = instance->get_child_meshsets( set, children );
+  if (MB_SUCCESS != rval) return rval;
+  isleaf = children.empty();
+  if (!isleaf && children.size() != 2)
+    return MB_MULTIPLE_ENTITIES_FOUND;
+  
+  dimensions_out = box.dimensions();
+  data.radius.accum( box.inner_radius() / box.outer_radius());
+  data.vol.accum( box.volume() );
+  data.area.accum( box.area() );
+  
+  if (isleaf) {
+    if (data.leaf_depth.size() <= (unsigned)depth)
+      data.leaf_depth.resize( depth+1, 0 );
+    ++data.leaf_depth[depth];
+    
+    int count;
+    rval = instance->get_number_entities_by_handle( set, count );
+    if (MB_SUCCESS != rval) return rval;
+    count_out = count;
+    data.leaf_ent.accum( count_out );
+  }
+  else {
+    for (int i = 0; i < 2; ++i) {
+      CartVect dims;
+      rval = recursive_stats( tool, instance, children[i], depth+1, data, counts[i], dims );
+      if (MB_SUCCESS != rval) return rval;
+      double this_measure, chld_measure;
+      int this_dim = measure( dimensions_out, this_measure );
+      int chld_dim = measure( dims, chld_measure );
+      double ratio;
+      if (chld_dim < this_dim)
+        ratio = 0;
+      else
+        ratio = chld_measure / this_measure;
+  
+      data.volume.accum( ratio );
+    }
+    count_out = counts[0] + counts[1];
+    data.entities.accum( (double)counts[0] / count_out );
+    data.entities.accum( (double)counts[1] / count_out );
+  }
+  return MB_SUCCESS;
+}
+
+static inline double std_dev( double sqr, double sum, double count )
+{
+  sum /= count;
+  sqr /= count;
+  return sqrt( sqr - sum*sum );
+}
+
+//#define WW <<std::setw(10)<<std::fixed<<
+#define WE <<std::setw(10)<<
+#define WW WE
+ErrorCode OrientedBoxTreeTool::stats( EntityHandle set, 
+                                          unsigned &total_entities,
+                                          double &rv,
+                                          double &tot_node_volume,
+                                          double &tot_to_root_volume,
+                                          unsigned &tree_height,
+                                          unsigned &node_count,
+                                          unsigned &num_leaves)
+{
+  StatData d;
+  ErrorCode rval;
+  unsigned i;
+  CartVect total_dim;
+  
+  rval = recursive_stats( this, instance, set, 0, d, total_entities, total_dim );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  tree_height = d.leaf_depth.size();
+  unsigned min_leaf_depth = tree_height;
+  num_leaves = 0;
+  unsigned max_leaf_per_depth = 0;
+  double sum_leaf_depth = 0, sqr_leaf_depth = 0;
+  for (i = 0; i < d.leaf_depth.size(); ++i) {
+    unsigned val = d.leaf_depth[i];
+    num_leaves += val;
+    sum_leaf_depth += (double)val*i;
+    sqr_leaf_depth += (double)val*i*i;
+    if (val && i < min_leaf_depth)
+      min_leaf_depth = i;
+    if (max_leaf_per_depth < val)
+      max_leaf_per_depth = val;
+  }
+  rv = total_dim[0]*total_dim[1]*total_dim[2];
+  tot_node_volume = d.vol.sum;
+  tot_to_root_volume = d.vol.sum/rv;
+  node_count = d.count;
+
+  return MB_SUCCESS;
+}
+
+ErrorCode OrientedBoxTreeTool::stats( EntityHandle set, std::ostream& s )
+{
+  StatData d;
+  ErrorCode rval;
+  unsigned total_entities, i;
+  CartVect total_dim;
+  
+  rval = recursive_stats( this, instance, set, 0, d, total_entities, total_dim );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  unsigned tree_height = d.leaf_depth.size();
+  unsigned min_leaf_depth = tree_height, num_leaves = 0;
+  unsigned max_leaf_per_depth = 0;
+  double sum_leaf_depth = 0, sqr_leaf_depth = 0;
+  for (i = 0; i < d.leaf_depth.size(); ++i) {
+    unsigned val = d.leaf_depth[i];
+    num_leaves += val;
+    sum_leaf_depth += (double)val*i;
+    sqr_leaf_depth += (double)val*i*i;
+    if (val && i < min_leaf_depth)
+      min_leaf_depth = i;
+    if (max_leaf_per_depth < val)
+      max_leaf_per_depth = val;
+  }
+  unsigned num_non_leaf = d.count - num_leaves;
+  
+  double rv = total_dim[0]*total_dim[1]*total_dim[2];
+  s << "entities in tree:  " << total_entities << std::endl
+    << "root volume:       " << rv << std::endl
+    << "total node volume: " << d.vol.sum << std::endl
+    << "total/root volume: " << d.vol.sum/rv << std::endl
+    << "tree height:       " << tree_height << std::endl
+    << "node count:        " << d.count << std::endl
+    << "leaf count:        " << num_leaves << std::endl
+    << std::endl;
+  
+  double avg_leaf_depth = sum_leaf_depth / num_leaves;
+  double rms_leaf_depth = sqrt( sqr_leaf_depth / num_leaves );
+  double std_leaf_depth = std_dev( sqr_leaf_depth, sum_leaf_depth, num_leaves );
+
+  double avg_leaf_ent = d.leaf_ent.sum / num_leaves;
+  double rms_leaf_ent = sqrt( d.leaf_ent.sqr / num_leaves );
+  double std_leaf_ent = std_dev( d.leaf_ent.sqr, d.leaf_ent.sum, num_leaves );
+
+  unsigned num_child = 2 * num_non_leaf;
+
+  double avg_vol_ratio = d.volume.sum / num_child;
+  double rms_vol_ratio = sqrt( d.volume.sqr / num_child );
+  double std_vol_ratio = std_dev( d.volume.sqr, d.volume.sum, num_child);
+
+  double avg_ent_ratio = d.entities.sum / num_child;
+  double rms_ent_ratio = sqrt( d.entities.sqr / num_child );
+  double std_ent_ratio = std_dev( d.entities.sqr, d.entities.sum, num_child);
+
+  double avg_rad_ratio = d.radius.sum / d.count;
+  double rms_rad_ratio = sqrt( d.radius.sqr / d.count );
+  double std_rad_ratio = std_dev( d.radius.sqr, d.radius.sum, d.count );
+  
+  double avg_vol = d.vol.sum / d.count;
+  double rms_vol = sqrt( d.vol.sqr / d.count );
+  double std_vol = std_dev( d.vol.sqr, d.vol.sum, d.count );
+  
+  double avg_area = d.area.sum / d.count;
+  double rms_area = sqrt( d.area.sqr / d.count );
+  double std_area = std_dev( d.area.sqr, d.area.sum, d.count );
+      
+  int prec = s.precision();
+  s <<                         "                   " WW "Minimum"      WW "Average"      WW "RMS"          WW "Maximum"             WW "Std.Dev."     << std::endl;
+  s << std::setprecision(1) << "Leaf Depth         " WW min_leaf_depth WW avg_leaf_depth WW rms_leaf_depth WW d.leaf_depth.size()-1 WW std_leaf_depth << std::endl; 
+  s << std::setprecision(0) << "Entities/Leaf      " WW d.leaf_ent.min WW avg_leaf_ent   WW rms_leaf_ent   WW d.leaf_ent.max        WW std_leaf_ent   << std::endl;
+  s << std::setprecision(3) << "Child Volume Ratio " WW d.volume.min   WW avg_vol_ratio  WW rms_vol_ratio  WW d.volume.max          WW std_vol_ratio  << std::endl;
+  s << std::setprecision(3) << "Child Entity Ratio " WW d.entities.min WW avg_ent_ratio  WW rms_ent_ratio  WW d.entities.max        WW std_ent_ratio  << std::endl;
+  s << std::setprecision(3) << "Box Radius Ratio   " WW d.radius.min   WW avg_rad_ratio  WW rms_rad_ratio  WW d.radius.max          WW std_rad_ratio  << std::endl;
+  s << std::setprecision(0) << "Box volume         " WE d.vol.min      WE avg_vol        WE rms_vol        WE d.vol.max             WE std_vol        << std::endl;
+  s << std::setprecision(0) << "Largest side area  " WE d.area.min     WE avg_area       WE rms_area       WE d.area.max            WE std_area       << std::endl;
+  s << std::setprecision(prec) << std::endl;
+  
+  s << "Leaf Depth Histogram (Root depth is 0)" << std::endl;
+  double f = 60.0 / max_leaf_per_depth;
+  for (i = min_leaf_depth; i < d.leaf_depth.size(); ++i)
+    s << std::setw(2) << i << " " << std::setw(5) << d.leaf_depth[i] << " |"
+      << std::setfill('*') << std::setw((int)floor(f*d.leaf_depth[i]+0.5)) << "" 
+      << std::setfill(' ') << std::endl;
+  s <<std::endl;
+  
+  s << "Child/Parent Volume Ratio Histogram" << std::endl;
+  f = 60.0 / *(std::max_element(d.volume.hist, d.volume.hist+10));
+  for (i = 0; i < 10u; ++i)
+    s << "0." << i << " " << std::setw(5) << d.volume.hist[i] << " |"
+      << std::setfill('*') << std::setw((int)floor(f*d.volume.hist[i]+0.5)) << ""
+      << std::setfill(' ') << std::endl;
+  s <<std::endl;
+  
+  s << "Child/Parent Entity Count Ratio Histogram" << std::endl;
+  f = 60.0 / *(std::max_element(d.entities.hist, d.entities.hist+10));
+  for (i = 0; i < 10u; ++i)
+    s << "0." << i << " " << std::setw(5) << d.entities.hist[i] << " |"
+      << std::setfill('*') << std::setw((int)floor(f*d.entities.hist[i]+0.5)) << ""
+      << std::setfill(' ') << std::endl;
+  s <<std::endl;
+  
+  s << "Inner/Outer Radius Ratio Histogram (~0.70 for cube)" << std::endl;
+    // max radius ratio for a box is about 0.7071.  Move any boxes
+    // in the .7 bucket into .6 and print .0 to .6.
+  d.radius.hist[6] += d.radius.hist[7]; 
+  f = 60.0 / *(std::max_element(d.entities.hist, d.entities.hist+7));
+  for (i = 0; i < 7u; ++i)
+    s << "0." << i << " " << std::setw(5) << d.entities.hist[i] << " |"
+      << std::setfill('*') << std::setw((int)floor(f*d.entities.hist[i]+0.5)) << ""
+      << std::setfill(' ') << std::endl;
+  s <<std::endl;
+  
+  return MB_SUCCESS;
+}  
+
+} // namespace moab
+

Modified: MOAB/trunk/src/PolyElementSeq.cpp
===================================================================
--- MOAB/trunk/src/PolyElementSeq.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/PolyElementSeq.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,17 +1,19 @@
 #include "PolyElementSeq.hpp"
 
+namespace moab {
+
 PolyElementSeq::~PolyElementSeq() {}
   
-EntitySequence* PolyElementSeq::split( MBEntityHandle here )
+EntitySequence* PolyElementSeq::split( EntityHandle here )
   { return new PolyElementSeq( *this, here ); }
                        
 
-MBErrorCode
-PolyElementSeq::get_connectivity( MBEntityHandle handle,
-                                  std::vector<MBEntityHandle>& connect,
+ErrorCode
+PolyElementSeq::get_connectivity( EntityHandle handle,
+                                  std::vector<EntityHandle>& connect,
                                   bool ) const
 {
-  MBEntityHandle const* conn = get_array() + nodes_per_element() * (handle - start_handle());
+  EntityHandle const* conn = get_array() + nodes_per_element() * (handle - start_handle());
   int len = nodes_per_element();
   connect.reserve( connect.size() + len );
   std::copy( conn, conn+len, std::back_inserter( connect ) );
@@ -19,14 +21,16 @@
 }
 
 
-MBErrorCode
-PolyElementSeq::get_connectivity( MBEntityHandle handle,
-                                  MBEntityHandle const*& conn_ptr,
+ErrorCode
+PolyElementSeq::get_connectivity( EntityHandle handle,
+                                  EntityHandle const*& conn_ptr,
                                   int& len,
                                   bool,
-                                  std::vector<MBEntityHandle>* ) const
+                                  std::vector<EntityHandle>* ) const
 {
   conn_ptr = get_array() + nodes_per_element() * (handle - start_handle());
   len = nodes_per_element();
   return MB_SUCCESS;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/PolyElementSeq.hpp
===================================================================
--- MOAB/trunk/src/PolyElementSeq.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/PolyElementSeq.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,44 +3,48 @@
 
 #include "UnstructuredElemSeq.hpp"
 
+namespace moab {
 
+
 class PolyElementSeq : public UnstructuredElemSeq
 {
 public:
-  PolyElementSeq( MBEntityHandle start_handle, 
-                  MBEntityID entity_count, 
+  PolyElementSeq( EntityHandle start_handle, 
+                  EntityID entity_count, 
                   unsigned nodes_per_entity,
                   SequenceData* data )
     : UnstructuredElemSeq( start_handle, entity_count, nodes_per_entity, data )
     {}
 
-  PolyElementSeq( MBEntityHandle start_handle, 
-                  MBEntityID entity_count, 
+  PolyElementSeq( EntityHandle start_handle, 
+                  EntityID entity_count, 
                   unsigned nodes_per_entity,
-                  MBEntityID sequence_data_size)
+                  EntityID sequence_data_size)
     : UnstructuredElemSeq( start_handle, entity_count, nodes_per_entity, sequence_data_size )
     {}
 
   virtual ~PolyElementSeq();
   
-  virtual EntitySequence* split( MBEntityHandle here );
+  virtual EntitySequence* split( EntityHandle here );
                        
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool topological = false ) const;
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topological = false,
-                                        std::vector<MBEntityHandle>* storage = 0
+                                        std::vector<EntityHandle>* storage = 0
                                        ) const;
 
 protected:
 
-  PolyElementSeq( PolyElementSeq& split_from, MBEntityHandle here )
+  PolyElementSeq( PolyElementSeq& split_from, EntityHandle here )
     : UnstructuredElemSeq( split_from, here )
    {}
 };
+  
+} // namespace moab
 
 #endif

Copied: MOAB/trunk/src/Range.cpp (from rev 3583, MOAB/trunk/src/MBRange.cpp)
===================================================================
--- MOAB/trunk/src/Range.cpp	                        (rev 0)
+++ MOAB/trunk/src/Range.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,970 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/****************************************************
+ * File     :      Range.cpp
+ *
+ * Purpose  :      Stores contiguous or partially
+ *                 contiguous values in an optimized
+ *                 fashion.  Partially contiguous
+ *                 accessing patterns is also optimized.
+ *
+ * Creator  :      Clinton Stimpson
+ *
+ * Date     :      15 April 2002
+ *
+ *******************************************************/
+
+
+#include <assert.h>
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+#include "moab/MBCN.hpp"
+#include <iostream>
+#include <string>
+
+#ifdef HAVE_BOOST_POOL_SINGLETON_POOL_HPP
+#  include <boost/pool/singleton_pool.hpp>
+   typedef boost::singleton_pool< moab::Range::PairNode , sizeof(moab::Range::PairNode) > 
+    PairAlloc;
+   static inline moab::Range::PairNode* alloc_pair()
+    { return new (PairAlloc::malloc()) moab::Range::PairNode; }
+   static inline moab::Range::PairNode* alloc_pair(moab::Range::PairNode* n, moab::Range::PairNode* p, moab::EntityHandle f, moab::EntityHandle s)
+    { return new (PairAlloc::malloc()) moab::Range::PairNode(n,p,f,s); }
+   static inline void free_pair( moab::Range::PairNode* node )
+    { node->~PairNode(); PairAlloc::free( node ); }
+#else
+   static inline moab::Range::PairNode* alloc_pair()
+    { return new moab::Range::PairNode; }
+   static inline moab::Range::PairNode* alloc_pair(moab::Range::PairNode* n, moab::Range::PairNode* p, moab::EntityHandle f, moab::EntityHandle s)
+    { return new moab::Range::PairNode(n,p,f,s); }
+   static inline void free_pair( moab::Range::PairNode* node )
+    { delete node; }
+#endif
+
+namespace moab {
+
+/*! 
+  returns the number of values this list represents
+ */
+EntityHandle Range::size() const
+{
+  // go through each pair and add up the number of values
+  // we have.
+  EntityHandle size=0;
+  for(PairNode* iter = mHead.mNext; iter != &mHead; iter = iter->mNext)
+  {
+    size += ((iter->second - iter->first) + 1);
+  }
+  return size;
+}
+/*! 
+  returns the number of pairs in the list
+ */
+EntityHandle Range::psize() const
+{
+  // go through each pair and add up the number of values
+  // we have.
+  EntityHandle size=0;
+  for(PairNode* iter = mHead.mNext; iter != &mHead; iter = iter->mNext)
+  {
+    ++size;
+  }
+  return size;
+}
+
+/*!
+  advance iterator
+*/
+Range::const_iterator& Range::const_iterator::operator+=( EntityID sstep )
+{
+    // Check negative now to avoid infinite loop below.
+  if (sstep < 0)
+  {
+    return operator-=( -sstep );
+  }
+  EntityHandle step = sstep;
+  
+    // Handle current PairNode.  Either step is within the current
+    // node or need to remove the remainder of the current node
+    // from step.
+  EntityHandle this_node_rem = mNode->second - mValue;
+  if (this_node_rem >= step)
+  {
+    mValue += step;
+    return *this;
+  }
+  step -= this_node_rem + 1;
+
+    // For each node we are stepping past, decrement step
+    // by the size of the node.
+  PairNode* node = mNode->mNext;
+  EntityHandle node_size = node->second - node->first + 1;
+  while (step >= node_size)
+  {
+    step -= node_size;
+    node = node->mNext;
+    node_size = node->second - node->first + 1;
+  }
+  
+    // Advance into the resulting node by whatever is
+    // left in step.
+  mNode = node;
+  mValue = mNode->first + step;
+  return *this;
+}
+  
+    
+ 
+/*!
+  regress iterator
+*/
+Range::const_iterator& Range::const_iterator::operator-=( EntityID sstep )
+{
+    // Check negative now to avoid infinite loop below.
+  if (sstep < 0)
+  {
+    return operator+=( -sstep );
+  }
+  EntityHandle step = sstep;
+  
+    // Handle current PairNode.  Either step is within the current
+    // node or need to remove the remainder of the current node
+    // from step.
+  EntityHandle this_node_rem = mValue - mNode->first;
+  if (this_node_rem >= step)
+  {
+    mValue -= step;
+    return *this;
+  }
+  step -= this_node_rem + 1;
+
+    // For each node we are stepping past, decrement step
+    // by the size of the node.
+  PairNode* node = mNode->mPrev;
+  EntityHandle node_size = node->second - node->first + 1;
+  while (step >= node_size)
+  {
+    step -= node_size;
+    node = node->mPrev;
+    node_size = node->second - node->first + 1;
+  }
+  
+    // Advance into the resulting node by whatever is
+    // left in step.
+  mNode = node;
+  mValue = mNode->second - step;
+  return *this;
+}
+  
+ 
+  
+
+  //! another constructor that takes an initial range
+Range::Range( EntityHandle val1, EntityHandle val2 )
+{
+  mHead.mNext = mHead.mPrev = alloc_pair(&mHead, &mHead, val1, val2);
+  mHead.first = mHead.second = 0;
+}
+
+  //! copy constructor
+Range::Range(const Range& copy)
+{
+    // set the head node to point to itself
+  mHead.mNext = mHead.mPrev = &mHead;
+  mHead.first = mHead.second = 0;
+
+  const PairNode* copy_node = copy.mHead.mNext;
+  PairNode* new_node = &mHead;
+  for(; copy_node != &(copy.mHead); copy_node = copy_node->mNext)
+  {
+    PairNode* tmp_node = alloc_pair(new_node->mNext, new_node, copy_node->first,
+                                      copy_node->second);
+    new_node->mNext->mPrev = tmp_node;
+    new_node->mNext = tmp_node;
+    new_node = tmp_node;
+  }
+}
+
+  //! clears the contents of the list 
+void Range::clear()
+{
+  PairNode* tmp_node = mHead.mNext;
+  while(tmp_node != &mHead)
+  {
+    PairNode* to_delete = tmp_node;
+    tmp_node = tmp_node->mNext;
+    free_pair( to_delete );
+  }
+  mHead.mNext = &mHead;
+  mHead.mPrev = &mHead;
+}
+
+Range& Range::operator=(const Range& copy)
+{
+  clear();
+  const PairNode* copy_node = copy.mHead.mNext;
+  PairNode* new_node = &mHead;
+  for(; copy_node != &(copy.mHead); copy_node = copy_node->mNext)
+  {
+    PairNode* tmp_node = alloc_pair(new_node->mNext, new_node, copy_node->first,
+                                      copy_node->second);
+    new_node->mNext->mPrev = tmp_node;
+    new_node->mNext = tmp_node;
+    new_node = tmp_node;
+  }
+  return *this;
+}
+
+
+/*!
+  inserts a single value into this range
+*/
+
+Range::iterator Range::insert( Range::iterator hint, EntityHandle val )
+{
+  // don't allow zero-valued handles in Range
+  if(val == 0)
+    return end();
+
+  // if this is empty, just add it and return an iterator to it
+  if(&mHead == mHead.mNext)
+  {
+    mHead.mNext = mHead.mPrev = alloc_pair(&mHead, &mHead, val, val);
+    return iterator(mHead.mNext, val);
+  }
+  
+  // find the location in the list where we can safely insert
+  // new items and keep it ordered
+  PairNode* hter = hint.mNode;
+  PairNode* jter = hter->first <= val ? hter : mHead.mNext;
+  for( ; (jter != &mHead) && (jter->second < val); jter=jter->mNext);
+  PairNode* iter = jter;
+  jter = jter->mPrev;
+
+  // if this val is already in the list
+  if( (iter->first <= val && iter->second >= val) && (iter != &mHead) )
+  {
+    // return an iterator pointing to this location
+    return iterator( iter, val );
+  }
+
+  // one of a few things can happen at this point
+  // 1. this range needs to be backwardly extended
+  // 2. the previous range needs to be forwardly extended
+  // 3. a new range needs to be added
+
+  
+  // extend this range back a bit
+  else if( (iter->first == (val+1)) && (iter != &mHead) )
+  {
+    iter->first = val;
+    // see if we need to merge two ranges
+    if( (iter != mHead.mNext) && (jter->second == (val-1)))
+    {
+      jter->second = iter->second;
+      iter->mPrev->mNext = iter->mNext;
+      iter->mNext->mPrev = iter->mPrev;
+      free_pair( iter );
+      return iterator( jter, val );
+    }
+    else
+    {
+      return iterator( iter, val );
+    }
+
+  }
+  // extend the previous range forward a bit
+  else if( (jter->second == (val-1)) && (iter != mHead.mNext) )
+  {
+    jter->second = val;
+    return iterator(jter, val);
+  }
+  // make a new range
+  else
+  {
+    PairNode* new_node = alloc_pair(iter, iter->mPrev, val, val);
+    iter->mPrev = new_node->mPrev->mNext = new_node;
+    return iterator(new_node, val);
+  }
+
+}
+
+Range::iterator Range::insert( Range::iterator prev,
+                                   EntityHandle val1, 
+                                   EntityHandle val2 )
+{
+  if(val1 == 0 || val1 > val2)
+    return end();
+
+  // Empty 
+  if (mHead.mNext == &mHead)
+  {
+    assert( prev == end() );
+    PairNode* new_node = alloc_pair( &mHead, &mHead, val1, val2 );
+    mHead.mNext = mHead.mPrev = new_node;
+    return iterator( mHead.mNext, val1 );
+  }
+  
+  PairNode* iter = prev.mNode;
+    // If iterator is at end, set it to last.
+    // Thus if the hint was to append, we start searching
+    // at the end of the list.
+  if (iter == &mHead) 
+    iter = mHead.mPrev;
+    // if hint (prev) is past insert position, reset it to the beginning.
+  if (iter != &mHead && iter->first > val2+1)
+    iter = mHead.mNext;
+  
+  // Input range is before beginning?
+  if (iter->mPrev == &mHead && val2 < iter->first - 1)
+  {
+    PairNode* new_node = alloc_pair( iter, &mHead,  val1, val2 );
+    mHead.mNext = iter->mPrev = new_node;
+    return iterator( mHead.mNext, val1 );
+  }
+  
+  // Find first intersecting list entry, or the next entry
+  // if none intersects.
+  while (iter != &mHead && iter->second+1 < val1)
+    iter = iter->mNext;
+  
+  // Need to insert new pair (don't intersect any existing pair)?
+  if (iter == &mHead || iter->first-1 > val2)
+  {
+    PairNode* new_node = alloc_pair( iter, iter->mPrev, val1, val2 );
+    iter->mPrev = iter->mPrev->mNext = new_node;
+    return iterator( iter->mPrev, val1 );
+  }
+  
+  // Make the first intersecting pair the union of itself with [val1,val2]
+  if (iter->first > val1)
+    iter->first = val1;
+  if (iter->second >= val2)  
+    return iterator( iter, val1 );
+  iter->second = val2;
+  
+  // Merge any remaining pairs that intersect [val1,val2]
+  while (iter->mNext != &mHead && iter->mNext->first <= val2 + 1)
+  {
+    PairNode* dead = iter->mNext;
+    iter->mNext = dead->mNext;
+    dead->mNext->mPrev = iter;
+    
+    if (dead->second > val2)
+      iter->second = dead->second;
+    free_pair( dead );
+  }
+  
+  return iterator( iter, val1 );
+}
+    
+
+/*!
+  erases an item from this list and returns an iterator to the next item
+*/
+
+Range::iterator Range::erase(iterator iter)
+{
+  // one of a few things could happen
+  // 1. shrink a range
+  // 2. split a range
+  // 3. remove a range
+
+  if(iter == end())
+    return end();
+
+  // the iterator most likely to be returned
+  iterator new_iter = iter;
+  ++new_iter;
+
+  PairNode* kter = iter.mNode;
+  
+  // just remove the range
+  if(kter->first == kter->second)
+  {
+    kter->mNext->mPrev = kter->mPrev;
+    kter->mPrev->mNext = kter->mNext;
+    free_pair( kter );
+    return new_iter;
+  }
+  // shrink it
+  else if(kter->first == iter.mValue)
+  {
+    kter->first++;
+    return new_iter;
+  }
+  // shrink it the other way
+  else if(kter->second == iter.mValue)
+  {
+    kter->second--;
+    return new_iter;
+  }
+  // split the range
+  else
+  {
+    PairNode* new_node = alloc_pair(iter.mNode->mNext, iter.mNode, iter.mValue+1, kter->second);
+    new_node->mPrev->mNext = new_node->mNext->mPrev = new_node;
+    iter.mNode->second = iter.mValue - 1;
+    new_iter = const_iterator(new_node, new_node->first);
+    return new_iter;
+  }
+
+}
+
+
+  //! remove a range of items from the list
+Range::iterator Range::erase( iterator iter1, iterator iter2)
+{
+  iterator result;
+  
+  if (iter1.mNode == iter2.mNode) {
+    if (iter2.mValue <= iter1.mValue) {
+        // empty range OK, otherwise invalid input
+      return iter2;
+    }
+    
+      // If both iterators reference the same pair node, then
+      // we're either removing values from the front of the
+      // node or splitting the node.  We can never be removing
+      // the last value in the node in this case because iter2
+      // points *after* the last entry to be removed.
+    
+    PairNode* node = iter1.mNode;
+    if (iter1.mValue == node->first) {
+        node->first = iter2.mValue;
+        result = iter2;
+    }
+    else {
+      PairNode* new_node = alloc_pair( node->mNext, node, iter2.mValue, node->second );
+      new_node->mNext->mPrev = new_node;
+      new_node->mPrev->mNext = new_node;
+      node->second = iter1.mValue - 1;
+      result = iterator( new_node, new_node->first );
+    }
+  }
+  else {
+    if (iter1.mNode == &mHead)
+      return iter1;
+    PairNode* dn = iter1.mNode;
+    if (iter1.mValue > dn->first) {
+      dn->second = iter1.mValue-1;
+      dn = dn->mNext;
+    }
+    if (iter2.mNode != &mHead) 
+      iter2.mNode->first = iter2.mValue;
+    while (dn != iter2.mNode) {
+      PairNode* dead = dn;
+      dn = dn->mNext;
+
+      dead->mPrev->mNext = dead->mNext;
+      dead->mNext->mPrev = dead->mPrev;
+      dead->mPrev = dead->mNext = 0;
+      delete dead;
+    }
+    
+    result = iter2;
+  }
+  
+  return result;
+}
+
+void Range::delete_pair_node( PairNode* node )
+{
+  if (node != &mHead) { // pop_front() and pop_back() rely on this check
+    node->mPrev->mNext = node->mNext;
+    node->mNext->mPrev = node->mPrev;
+    free_pair( node );
+  }
+}
+
+  //! remove first entity from range
+EntityHandle Range::pop_front()
+{
+  EntityHandle retval = front();
+  if (mHead.mNext->first == mHead.mNext->second) // need to remove pair from range
+    delete_pair_node( mHead.mNext );
+  else 
+    ++(mHead.mNext->first); // otherwise just adjust start value of pair
+
+  return retval;
+}
+
+  //! remove last entity from range
+EntityHandle Range::pop_back()
+{
+  EntityHandle retval = back();
+  if (mHead.mPrev->first == mHead.mPrev->second) // need to remove pair from range
+    delete_pair_node( mHead.mPrev );
+  else
+    --(mHead.mPrev->second); // otherwise just adjust end value of pair
+
+  return retval;
+}
+
+/*!
+  finds a value in the list.
+  this method is preferred over other algorithms because
+  it can be found faster this way.
+*/
+Range::const_iterator Range::find(EntityHandle val) const
+{
+  // iterator through the list
+  PairNode* iter = mHead.mNext;
+  for( ; iter != &mHead && (val > iter->second); iter=iter->mNext );
+  return ((iter->second >= val) && (iter->first <= val)) ? const_iterator(iter,val) : end();
+}
+
+/*!
+  merges another Range with this one
+*/
+
+
+void Range::merge( const Range& range )
+{
+  merge( range.begin(), range.end() );
+}
+
+void Range::merge( Range::const_iterator begin,
+                     Range::const_iterator end )
+{
+  if (begin == end)
+    return;
+  
+  PairNode* node = begin.mNode;
+  if (end.mNode == node)
+  {
+    insert( *begin, (*end)-1 );
+    return;
+  }
+  
+  Range::iterator hint = insert( *begin, node->second );
+  node = node->mNext;
+  while (node != end.mNode)
+  {
+    hint = insert( hint, node->first, node->second );
+    node = node->mNext;
+  }
+  
+  if (*end > node->first)
+  {
+    if (*end <= node->second)
+      insert( hint, node->first, *(end) - 1 );
+    else
+      insert( hint, node->first, node->second );
+  }
+}
+
+  
+  
+
+#include <algorithm>
+
+
+// checks the range to make sure everything is A-Ok.
+void Range::sanity_check() const
+{
+  if(empty())
+    return;
+
+  const PairNode* node = mHead.mNext;
+  std::vector<const PairNode*> seen_before;
+  bool stop_it = false;
+  
+  for(; stop_it == false; node = node->mNext)
+  {
+    // have we seen this node before?
+    assert(std::find(seen_before.begin(), seen_before.end(), node) == seen_before.end());
+    seen_before.push_back(node);
+
+    // is the connection correct?
+    assert(node->mNext->mPrev == node);
+
+    // are the values right?
+    assert(node->first <= node->second);
+    if(node != &mHead && node->mPrev != &mHead)
+      assert(node->mPrev->second < node->first);
+
+    if(node == &mHead)
+      stop_it = true;
+
+  }
+
+}
+
+// for debugging
+void Range::print(const char *indent_prefix) const
+{
+  print(std::cout, indent_prefix);
+}
+
+void Range::print(std::ostream& stream, const char *indent_prefix) const
+{
+  std::string indent_prefix_str;
+  if (NULL != indent_prefix) indent_prefix_str += indent_prefix;
+  
+  if (empty()) {
+    stream << indent_prefix_str << "\tempty" << std::endl;
+    return;
+  }
+  
+  for (const_pair_iterator i = const_pair_begin(); i != const_pair_end(); ++i) {
+    EntityType t1 = TYPE_FROM_HANDLE( i->first );
+    EntityType t2 = TYPE_FROM_HANDLE( i->second );
+  
+    stream << indent_prefix_str << "\t" << MBCN::EntityTypeName( t1 ) << " " 
+           << ID_FROM_HANDLE( i->first );
+    if(i->first != i->second) {
+      stream << " - ";
+      if (t1 != t2) 
+        stream << MBCN::EntityTypeName( t2 ) << " ";
+      stream << ID_FROM_HANDLE( i->second );
+    }
+    stream << std::endl;
+  }
+}
+
+  // intersect two ranges, placing the results in the return range
+#define MAX(a,b) (a < b ? b : a)
+#define MIN(a,b) (a > b ? b : a)
+Range intersect(const Range &range1, const Range &range2) 
+{
+  Range::const_pair_iterator r_it[2] = { range1.const_pair_begin(), 
+                                           range2.const_pair_begin() };
+  EntityHandle low_it, high_it;
+  
+  Range lhs;
+  Range::iterator hint = lhs.begin();
+  
+    // terminate the while loop when at least one "start" iterator is at the
+    // end of the list
+  while (r_it[0] != range1.end() && r_it[1] != range2.end()) {
+    
+    if (r_it[0]->second < r_it[1]->first)
+        // 1st subrange completely below 2nd subrange
+      r_it[0]++;
+    else if (r_it[1]->second < r_it[0]->first) 
+        // 2nd subrange completely below 1st subrange
+      r_it[1]++;
+    
+    else {
+        // else ranges overlap; first find greater start and lesser end
+      low_it = MAX(r_it[0]->first, r_it[1]->first);
+      high_it = MIN(r_it[0]->second, r_it[1]->second);
+      
+        // insert into result
+      hint = lhs.insert(hint, low_it, high_it);
+      
+        // now find bounds of this insertion and increment corresponding iterator
+      if (high_it == r_it[0]->second) r_it[0]++;
+      if (high_it == r_it[1]->second) r_it[1]++;
+    }
+  }
+  
+  return lhs;
+}
+
+Range subtract(const Range &range1, const Range &range2) 
+{
+  const bool braindead = false;
+  
+  if (braindead) {
+      // brain-dead implementation right now
+    Range res( range1 );
+    for (Range::const_iterator rit = range2.begin(); rit != range2.end(); rit++)
+      res.erase(*rit);
+
+    return res;
+  }
+  else {
+    Range lhs( range1 );
+  
+    Range::pair_iterator r_it0 = lhs.pair_begin();
+    Range::const_pair_iterator r_it1 = range2.const_pair_begin();
+  
+      // terminate the while loop when at least one "start" iterator is at the
+      // end of the list
+    while (r_it0 != lhs.end() && r_it1 != range2.end()) {
+        // case a: pair wholly within subtracted pair
+      if (r_it0->first >= r_it1->first && r_it0->second <= r_it1->second) {
+        Range::PairNode *rtmp = r_it0.node();
+        r_it0++;
+        lhs.delete_pair_node(rtmp);
+      }
+        // case b: pair overlaps upper part of subtracted pair
+      else if (r_it0->first <= r_it1->second &&
+               r_it0->first >= r_it1->first) {
+        r_it0->first = r_it1->second + 1;
+        r_it1++;
+      }
+        // case c: pair overlaps lower part of subtracted pair
+      else if (r_it0->second >= r_it1->first &&
+               r_it0->second <= r_it1->second) {
+        r_it0->second = r_it1->first - 1;
+        r_it0++;
+      }
+        // case d: pair completely surrounds subtracted pair
+      else if (r_it0->first < r_it1->first && 
+               r_it0->second > r_it1->second) {
+        Range::PairNode* new_node = alloc_pair(r_it0.node(), r_it0.node()->mPrev, 
+                                        r_it0->first, r_it1->first - 1);
+        new_node->mPrev->mNext = new_node->mNext->mPrev = new_node;
+        r_it0.node()->first = r_it1->second+1;
+        r_it1++;
+      }
+      else {
+        while (r_it0->second < r_it1->first && r_it0 != lhs.end()) r_it0++;
+        if (r_it0 == lhs.end()) break;
+        while (r_it1->second < r_it0->first && r_it1 != range2.end()) r_it1++;
+      }
+    }
+    
+    return lhs;
+  }
+}
+
+  
+EntityID 
+operator-( const Range::const_iterator& it2, const Range::const_iterator& it1 )
+{
+  assert( !it2.mValue || *it2 >= *it1 );
+  if (it2.mNode == it1.mNode) {
+    return *it2 - *it1;
+  }
+
+  EntityID result = it1.mNode->second - it1.mValue + 1;
+  for (Range::PairNode* n = it1.mNode->mNext; n != it2.mNode; n = n->mNext)
+    result += n->second - n->first + 1;
+  if (it2.mValue) // (it2.mNode != &mHead)
+    result += it2.mValue - it2.mNode->first;
+  return result;
+}
+
+
+Range::const_iterator Range::lower_bound(Range::const_iterator first,
+                                             Range::const_iterator last,
+                                             EntityHandle val)
+{
+    // Find the first pair whose end is >= val
+  PairNode* iter;
+  for (iter = first.mNode; iter != last.mNode; iter = iter->mNext)
+  {
+    if (iter->second >= val)
+    {
+        // This is the correct pair.  Either 'val' is in the range, or
+        // the range starts before 'val' and iter->first IS the lower_bound.
+      if (iter->first > val)
+        return const_iterator(iter, iter->first);
+      return const_iterator(iter, val);
+    }
+  }
+  
+  if (iter->first >= val)
+    return const_iterator( iter, iter->first );
+  else if(*last > val)
+    return const_iterator( iter, val );
+  else
+    return last;
+}
+
+Range::const_iterator Range::upper_bound(Range::const_iterator first,
+                                             Range::const_iterator last,
+                                             EntityHandle val)
+{
+  Range::const_iterator result = lower_bound( first, last, val );
+  if (result != last && *result == val)
+    ++result;
+  return result;
+}
+
+Range::const_iterator Range::lower_bound( EntityType type ) const
+{
+  int err;
+  EntityHandle handle = CREATE_HANDLE( type, 0, err );
+  return err ? end() : lower_bound( begin(), end(), handle );
+}
+Range::const_iterator Range::lower_bound( EntityType type,
+                                              const_iterator first ) const
+{
+  int err;
+  EntityHandle handle = CREATE_HANDLE( type, 0, err );
+  return err ? end() : lower_bound( first, end(), handle );
+}
+
+Range::const_iterator Range::upper_bound( EntityType type ) const
+{
+    // if (type+1) overflows, err will be true and we return end().
+  int err; 
+  EntityHandle handle = CREATE_HANDLE( type + 1, 0, err );
+  return err ? end() : lower_bound( begin(), end(), handle );
+}
+Range::const_iterator Range::upper_bound( EntityType type,
+                                              const_iterator first ) const
+{
+    // if (type+1) overflows, err will be true and we return end().
+  int err; 
+  EntityHandle handle = CREATE_HANDLE( type + 1, 0, err );
+  return err ? end() : lower_bound( first, end(), handle );
+}
+
+std::pair<Range::const_iterator, Range::const_iterator>
+Range::equal_range( EntityType type ) const
+{
+  std::pair<Range::const_iterator, Range::const_iterator> result;
+  int err;
+  EntityHandle handle = CREATE_HANDLE( type, 0, err );
+  result.first = err ? end() : lower_bound( begin(), end(), handle );
+    // if (type+1) overflows, err will be true and we return end().
+  handle = CREATE_HANDLE( type+1, 0, err );
+  result.second = err ? end() : lower_bound( result.first, end(), handle );
+  return result;
+}
+  
+bool Range::all_of_type( EntityType type ) const
+{
+  return empty() 
+      || (TYPE_FROM_HANDLE(front()) == type
+       && TYPE_FROM_HANDLE(back()) == type);
+}
+
+bool Range::all_of_dimension( int dimension ) const
+{
+  return empty() 
+      || (MBCN::Dimension(TYPE_FROM_HANDLE(front())) == dimension
+       && MBCN::Dimension(TYPE_FROM_HANDLE(back())) == dimension);
+}
+
+unsigned Range::num_of_type( EntityType type ) const
+{
+  const_pair_iterator iter = const_pair_begin();
+  while(iter != const_pair_end() && TYPE_FROM_HANDLE((*iter).second) < type)
+    ++iter;
+  
+  unsigned count = 0;
+  for ( ; iter != const_pair_end(); ++iter)
+  {
+    EntityType start_type = TYPE_FROM_HANDLE((*iter).first);
+    EntityType end_type = TYPE_FROM_HANDLE((*iter).second);
+    if (start_type > type)
+      break;
+   
+    int sid = start_type < type ? 1 : ID_FROM_HANDLE((*iter).first);
+    int eid = end_type > type ? MB_END_ID : ID_FROM_HANDLE((*iter).second);
+    count += eid - sid + 1;
+  }
+
+  return count;
+}
+  
+unsigned Range::num_of_dimension( int dim ) const
+{
+  const_pair_iterator iter = const_pair_begin();
+  while(iter != const_pair_end() && MBCN::Dimension(TYPE_FROM_HANDLE((*iter).second)) < dim)
+    ++iter;
+  
+  int junk;
+  unsigned count = 0;
+  for ( ; iter != const_pair_end(); ++iter)
+  {
+    int start_dim = MBCN::Dimension(TYPE_FROM_HANDLE((*iter).first));
+    int end_dim = MBCN::Dimension(TYPE_FROM_HANDLE((*iter).second));
+    if (start_dim > dim)
+      break;
+      
+    EntityHandle sh = start_dim < dim ? 
+                        CREATE_HANDLE( MBCN::TypeDimensionMap[dim].first, 1, junk ) :
+                        (*iter).first;
+    EntityHandle eh = end_dim > dim ?
+                        CREATE_HANDLE( MBCN::TypeDimensionMap[dim].second, MB_END_ID, junk ) :
+                        (*iter).second;
+    count += eh - sh + 1;
+  }
+
+  return count;
+}
+  
+    
+
+
+//! swap the contents of this range with another one
+//! THIS FUNCTION MUST NOT BE INLINED, THAT WILL ELIMINATE RANGE_EMPTY AND THIS_EMPTY
+//! BY SUBSTITUTION AND THE FUNCTION WON'T WORK RIGHT!
+void Range::swap( Range &range )
+{
+    // update next/prev nodes of head of both ranges
+  bool range_empty = (range.mHead.mNext == &(range.mHead));
+  bool this_empty = (mHead.mNext == &mHead);
+
+  range.mHead.mNext->mPrev = (range_empty ? &(range.mHead) : &mHead);
+  range.mHead.mPrev->mNext = (range_empty ? &(range.mHead) : &mHead);
+  mHead.mNext->mPrev = (this_empty ? &mHead : &(range.mHead));
+  mHead.mPrev->mNext = (this_empty ? &mHead : &(range.mHead));
+
+    // switch data in head nodes of both ranges
+  PairNode *range_next = range.mHead.mNext, *range_prev = range.mHead.mPrev;
+  range.mHead.mNext = (this_empty ? &(range.mHead) : mHead.mNext);
+  range.mHead.mPrev = (this_empty ? &(range.mHead) : mHead.mPrev);
+  mHead.mNext = (range_empty ? &mHead : range_next);
+  mHead.mPrev = (range_empty ? &mHead : range_prev);
+
+}
+
+int Range::index(EntityHandle handle) const 
+{
+  if (handle < *begin() || handle > *rbegin()) return -1;
+  
+  unsigned int i = 0;
+  Range::const_pair_iterator pit = const_pair_begin(); 
+  while (handle > (*pit).second && pit != const_pair_end()) {
+    i += (*pit).second - (*pit).first + 1;
+    pit++;
+  }
+  if (handle < (*pit).first || pit == const_pair_end()) return -1;
+  
+  return i + handle - (*pit).first;
+}
+
+    //! return a subset of this range, by type
+Range Range::subset_by_type(EntityType t) const
+{
+  Range result;
+  std::pair<const_iterator, const_iterator> iters = equal_range(t);
+  result.merge( iters.first, iters.second );
+  return result;
+}
+
+bool operator==( const Range& r1, const Range& r2 )
+{
+  Range::const_pair_iterator i1, i2;
+  i1 = r1.const_pair_begin();
+  i2 = r2.const_pair_begin();
+  for ( ; i1 != r1.const_pair_end(); ++i1, ++i2) 
+    if (i2 == r2.const_pair_end() ||
+        i1->first != i2->first ||
+        i1->second != i2->second)
+      return false;
+  return i2 == r2.const_pair_end();
+}
+
+unsigned long Range::get_memory_use() const
+{
+  unsigned long result = 0;
+  for (const PairNode* n = mHead.mNext; n != &mHead; n = n->mNext)
+    result += sizeof(PairNode);
+  return result;
+}
+  
+} // namespace moab
+

Copied: MOAB/trunk/src/RangeSeqIntersectIter.cpp (from rev 3583, MOAB/trunk/src/MBRangeSeqIntersectIter.cpp)
===================================================================
--- MOAB/trunk/src/RangeSeqIntersectIter.cpp	                        (rev 0)
+++ MOAB/trunk/src/RangeSeqIntersectIter.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,168 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file RangeSeqIntersectIter.cpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-08-11
+ */
+
+#include "RangeSeqIntersectIter.hpp"
+#include "SequenceManager.hpp"
+#include "EntitySequence.hpp"
+#include <assert.h>
+
+namespace moab {
+
+ErrorCode RangeSeqIntersectIter::init( Range::const_iterator start,
+                                           Range::const_iterator end )
+{
+  mSequence = 0;
+  rangeIter = start;
+
+    // special case : nothing to iterate over
+  if (start == end) {
+    mStartHandle = mEndHandle = mLastHandle = 0;
+    return MB_FAILURE;
+  }
+
+    // normal case
+  mStartHandle = *start;
+  --end;
+  mLastHandle = *end;
+  mEndHandle = (*rangeIter).second;
+  if (mEndHandle > mLastHandle)
+    mEndHandle = mLastHandle;
+
+#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
+  ErrorCode result = update_entity_sequence();
+  update_stats(mEndHandle - mStartHandle + 1);
+  return result;
+#else
+  return update_entity_sequence();
+#endif
+}
+  
+
+ErrorCode RangeSeqIntersectIter::step()
+{
+    // If at end, return MB_FAILURE
+  if (is_at_end())
+    return MB_FAILURE; 
+    // If the last block was at the end of the rangeIter pair,
+    // then advance the iterator and set the next block
+  else if (mEndHandle == (*rangeIter).second) {
+    ++rangeIter;
+    mStartHandle = (*rangeIter).first;
+  }
+    // Otherwise start with next entity in the pair
+  else {
+    mStartHandle = mEndHandle + 1;
+  }
+    // Always take the remaining entities in the rangeIter pair.
+    // will trim up the end of the range in update_entity_sequence().
+  mEndHandle = (*rangeIter).second;
+  if (mEndHandle > mLastHandle)
+    mEndHandle = mLastHandle;
+  
+    // Now trim up the range (decrease mEndHandle) as necessary
+    // for the corresponding EntitySquence
+#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
+  ErrorCode result = update_entity_sequence();
+  update_stats(mEndHandle - mStartHandle + 1);
+  return result;
+#else
+  return update_entity_sequence();
+#endif
+}
+
+ErrorCode RangeSeqIntersectIter::update_entity_sequence()
+{
+    // mStartHandle to mEndHandle is a subset of the Range.
+    // Update sequence data as necessary and trim that subset
+    // (reduce mEndHandle) for the current EntitySequence.
+  
+    // Need to update the sequence pointer?
+  if (!mSequence || mStartHandle > mSequence->end_handle()) {
+  
+      // Check that the mStartHandle is valid
+    if (TYPE_FROM_HANDLE(mStartHandle) >= MBMAXTYPE)
+      return MB_TYPE_OUT_OF_RANGE;
+
+    if (MB_SUCCESS != mSequenceManager->find( mStartHandle, mSequence ))
+      return find_invalid_range();
+  }
+    
+    // if mEndHandle is past end of sequence or block of used
+    // handles within sequence, shorten it.
+  if(mEndHandle > mSequence->end_handle())
+    mEndHandle = mSequence->end_handle();
+  
+  return MB_SUCCESS;
+}
+ 
+ErrorCode RangeSeqIntersectIter::find_invalid_range()
+{
+  assert(!mSequence);
+
+    // no more entities in current range
+  if (mStartHandle == mEndHandle)
+    return MB_ENTITY_NOT_FOUND;
+    
+    // Find the next EntitySequence
+  EntityType type = TYPE_FROM_HANDLE(mStartHandle);
+  const TypeSequenceManager& map = mSequenceManager->entity_map( type );
+  TypeSequenceManager::const_iterator iter = map.upper_bound( mStartHandle );
+    // If no next sequence of the same type
+  if (iter == map.end()) {
+      // If end type not the same as start type, split on type
+    if (type != TYPE_FROM_HANDLE( mEndHandle )) {
+      int junk;
+      mEndHandle = CREATE_HANDLE( type, MB_END_ID, junk );
+    }
+  }
+    // otherwise invalid range ends at min(mEndHandle, sequence start handle - 1)
+  else if ((*iter)->start_handle() <= mEndHandle) {
+    mEndHandle = (*iter)->start_handle()-1;
+  }
+  
+  return MB_ENTITY_NOT_FOUND;
+}
+        
+#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
+double RangeSeqIntersectIter::doubleNumCalls = 0;
+double RangeSeqIntersectIter::doubleEntCount = 0;
+unsigned long RangeSeqIntersectIter::intNumCalls = 0;
+unsigned long RangeSeqIntersectIter::intEntCount = 0;
+
+void RangeSeqIntersectIter::update_stats( unsigned long num_ents )
+{
+  if (std::numeric_limits<unsigned long>::max() == intNumCalls) {
+    doubleNumCalls += intNumCalls;
+    intNumCalls = 0;
+  }
+  ++intNumCalls;
+  
+  if (std::numeric_limits<unsigned long>::max() - intEntCount > num_ents) {
+    doubleNumCalls += intEntCount;
+    intEntCount = num_ents;
+  }
+  else {
+    intEntCount += num_ents;
+  }
+}
+#endif
+  
+} // namespace moab
+

Copied: MOAB/trunk/src/RangeSeqIntersectIter.hpp (from rev 3583, MOAB/trunk/src/MBRangeSeqIntersectIter.hpp)
===================================================================
--- MOAB/trunk/src/RangeSeqIntersectIter.hpp	                        (rev 0)
+++ MOAB/trunk/src/RangeSeqIntersectIter.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,141 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file RangeSeqIntersectIter.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-08-11
+ *\date 2007-11-06
+ */
+
+#ifndef MB_RANGE_SEQ_INTERSECT_ITER_HPP
+#define MB_RANGE_SEQ_INTERSECT_ITER_HPP
+
+#include "moab/Types.hpp"
+#include "moab/Range.hpp"
+
+namespace moab {
+
+class SequenceManager;
+class EntitySequence;
+
+#define MB_RANGE_SEQ_INTERSECT_ITER_STATS 0
+
+/** \brief Iterate over the blocks of EntityHandles in an Range that
+ *         are in the same EntitySequence.
+ *
+ * Iterate over an Range, returning blocks of entities that are the 
+ * largest ranges of contiguous handles that meet one of the following
+ * conditions:
+ *  - All are valid handles belonging to the same EntitySequence
+ *  - All are invalid handles of the same EntityType
+ *
+ * The return type from init() or step() indicates whether or not the
+ * current range contains valid entities.  If the handles are either
+ * all valid or all holes in an EntitySequence, that sequence can
+ * be obtained with get_sequence().  get_sequence() will return NULL if
+ * there is no corresponding EntitySequence for the block of handles.
+ *
+ * This class keeps a data related to the 'current' EntitySequence and
+ * references to the Range pasesd to init().  Changing either of these
+ * while an instance of this class is in use would be bad.
+ */
+class RangeSeqIntersectIter {
+public:
+  
+  RangeSeqIntersectIter( SequenceManager* sequences )
+    : mSequenceManager( sequences ),
+      mSequence( 0 ),
+      mStartHandle( 0 ),
+      mEndHandle( 0 ),
+      mLastHandle( 0 )
+    { }
+    
+    /** Initialize iterator to first valid subset 
+     *\return - MB_SUCCESS : initial position of iterator is valid
+     *        - MB_ENITITY_NOT_FOUND : range contains invalid handle -- can step past by calling again
+     *        - MB_FAILURE : No entities (start == end)
+     */
+  ErrorCode init( Range::const_iterator start, Range::const_iterator end );
+  
+    /** Step iterator to next range.  
+     *\return - MB_SUCCESS : there is another range, and iter has been changed to it
+     *        - MB_ENITITY_NOT_FOUND : range contains invalid handle -- can step past by calling again
+     *        - MB_FAILURE : at end.
+     */
+  ErrorCode step();
+  
+    /**\brief Check if next call to step() will return MB_FAILURE.
+     *
+     * Check if the iterator cannot be advanced any further.
+     * If this method returns true, then the *next* call to step()
+     * will return MB_FAILURE.
+     */
+  bool is_at_end() const
+    { return mEndHandle == mLastHandle; }
+  
+    /** Get the EntitySequence for the current block.
+     *  May be NULL for invaild handles.
+     */
+  EntitySequence* get_sequence() const
+    { return mSequence; }
+  
+    /** Get first handle in block */
+  EntityHandle get_start_handle() const
+    { return mStartHandle; }
+  
+    /** Get last handle in block */
+  EntityHandle get_end_handle() const
+    { return mEndHandle; }
+
+#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
+  static double fragmentation() 
+    { return (doubleNumCalls + intNumCalls) / (doubleEntCount + intEntCount); }
+#endif
+    
+private:
+
+  /** Update entity sequence data (mSequence and freeIndex) for current
+   *  mStartHandle.  If mEndHandle is past end of sequence, trim it.
+   *  Called by step() and init().  step() handles iterating over the pairs 
+   *  in the Range.  This method handles iterating over the set of 
+   *  EntitySequences that intersect the pair.
+   */
+  ErrorCode update_entity_sequence();
+  
+  /** Handle error case where we encountered an EntityHandle w/out
+   *  a corresponding EntitySequence.  Trim mEndHandle such that it
+   *  is before the next valid EntityHandle of the same type.
+   *\return Always returns MB_ENTITY_NOT_FOUND
+   */
+  ErrorCode find_invalid_range();
+
+  SequenceManager* mSequenceManager;       //!< THE EntitySequenceManager
+  EntitySequence* mSequence;               //!< EntitySequence corresponding to current location
+  Range::const_pair_iterator rangeIter;  //!< Current position in Range.
+  EntityHandle mStartHandle, mEndHandle; //!< Subset of current EntitySequence
+  EntityHandle mLastHandle;              //!< The last of the list of all handles in the Range
+
+#if MB_RANGE_SEQ_INTERSECT_ITER_STATS
+  static double doubleNumCalls, doubleEntCount;
+  static unsigned long intNumCalls, intEntCount;
+  static void update_stats( unsigned long num_ents);
+#endif
+};
+  
+} // namespace moab
+
+#endif
+
+

Copied: MOAB/trunk/src/ReadUtil.cpp (from rev 3583, MOAB/trunk/src/MBReadUtil.cpp)
===================================================================
--- MOAB/trunk/src/ReadUtil.cpp	                        (rev 0)
+++ MOAB/trunk/src/ReadUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,395 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifdef WIN32
+#ifdef _DEBUG
+// turn off warnings that say they debugging identifier has been truncated
+// this warning comes up when using some STL containers
+#pragma warning(disable : 4786)
+#endif
+#endif
+
+#include "ReadUtil.hpp"
+#include "moab/Core.hpp"
+#include "AEntityFactory.hpp"
+#include "Error.hpp"
+#include "SequenceManager.hpp"
+#include "VertexSequence.hpp"
+#include "ElementSequence.hpp"
+
+namespace moab {
+
+#define RR if (MB_SUCCESS != result) return result
+
+ReadUtil::ReadUtil(Core* mdb, Error* error_handler) 
+    : ReadUtilIface(), mMB(mdb), mError(error_handler)
+{
+}
+
+ErrorCode ReadUtil::get_node_arrays(
+    const int /*num_arrays*/,
+    const int num_nodes, 
+    const int preferred_start_id,
+    EntityHandle& actual_start_handle, 
+    std::vector<double*>& arrays)
+{
+
+  ErrorCode error;
+  EntitySequence* seq = 0;
+  
+  if (num_nodes < 1) {
+    actual_start_handle = 0;
+    arrays.clear();
+    return MB_INDEX_OUT_OF_RANGE;
+  }
+
+  // create an entity sequence for these nodes 
+  error = mMB->sequence_manager()->create_entity_sequence(
+    MBVERTEX, num_nodes, 0, preferred_start_id, 
+    actual_start_handle,
+    seq);
+
+  if(error != MB_SUCCESS)
+    return error;
+
+  if (seq->start_handle() > actual_start_handle ||
+      seq->end_handle() < actual_start_handle ||
+      seq->end_handle() - actual_start_handle + 1 < (unsigned)num_nodes)
+    return MB_FAILURE;
+
+  arrays.resize(3);
+
+  error = static_cast<VertexSequence*>(seq)->get_coordinate_arrays(arrays[0], arrays[1], arrays[2]);
+  for (unsigned i = 0; i< arrays.size(); ++i)
+    if (arrays[i])
+      arrays[i] += (actual_start_handle - seq->start_handle());
+  
+  return error;
+}
+
+ErrorCode ReadUtil::get_element_array(
+    const int num_elements, 
+    const int verts_per_element,
+    const EntityType mdb_type,
+    const int preferred_start_id, 
+    EntityHandle& actual_start_handle, 
+    EntityHandle*& array)
+{
+
+  ErrorCode error;
+  EntitySequence* seq;
+  
+  if (num_elements < 1) {
+    actual_start_handle = 0;
+    array = 0;
+    return MB_INDEX_OUT_OF_RANGE;
+  }
+  
+//  if (mdb_type <= MBVERTEX || mdb_type >= MBPOLYHEDRON || mdb_type == MBPOLYGON)
+//    return MB_TYPE_OUT_OF_RANGE;
+
+  // make an entity sequence to hold these elements
+  error = mMB->sequence_manager()->create_entity_sequence(
+      mdb_type, num_elements, verts_per_element, preferred_start_id, 
+      actual_start_handle, seq);
+  if (MB_SUCCESS != error)
+    return error;
+
+  if (seq->start_handle() > actual_start_handle ||
+      seq->end_handle() < actual_start_handle ||
+      seq->end_handle() - actual_start_handle + 1 < (unsigned)num_elements)
+    return MB_FAILURE;
+
+  // get an array for the connectivity
+  array = static_cast<ElementSequence*>(seq)->get_connectivity_array();
+  if (!array)
+    return MB_FAILURE;
+  array += (actual_start_handle - seq->start_handle()) 
+         * static_cast<ElementSequence*>(seq)->nodes_per_element();
+
+  return error;
+  
+}
+
+ErrorCode ReadUtil::create_entity_sets( EntityID num_sets,
+                                            const unsigned* flags ,
+                                            EntityID start_id,
+                                            EntityHandle& start_handle )
+{
+  if (num_sets < 1) {
+    start_handle = 0;
+    return MB_INDEX_OUT_OF_RANGE;
+  }
+
+  ErrorCode error;
+  EntitySequence* seq;
+  error = mMB->sequence_manager()->create_meshset_sequence( num_sets,
+                                                            start_id,
+                                                            flags,
+                                                            start_handle,
+                                                            seq );
+  if (MB_SUCCESS != error)
+    return error;
+
+  if (seq->start_handle() > start_handle ||
+      seq->end_handle() < start_handle ||
+      seq->end_handle() - start_handle + 1 < (EntityHandle)num_sets)
+    return MB_FAILURE;
+    
+  return MB_SUCCESS;
+}
+
+
+ErrorCode ReadUtil::update_adjacencies(
+      const EntityHandle start_handle,
+      const int number_elements,
+      const int number_vertices_per_element,
+      const EntityHandle* conn_array)
+{
+
+  EntityHandle tmp_hndl = start_handle;
+  AEntityFactory* adj_fact = mMB->a_entity_factory();
+
+  // iterator over the elements and update adjacency information
+  if(adj_fact != NULL && adj_fact->vert_elem_adjacencies())
+  {
+    int j=0;
+    for(int i=0; i<number_elements; i++)
+    {
+      adj_fact->notify_create_entity( tmp_hndl, (conn_array+j), number_vertices_per_element);
+      tmp_hndl++;
+      j+=number_vertices_per_element;
+    }
+  }
+  return MB_SUCCESS;
+}
+
+
+
+ErrorCode ReadUtil::report_error( const std::string& error )
+{
+  if(mError)
+    return mError->set_last_error(error);
+  else
+    return MB_FAILURE;
+}
+
+
+ErrorCode ReadUtil::report_error( const char* error, ... )
+{
+  va_list args;
+  va_start(args, error);
+  ErrorCode result = mError->set_last_error(error, args);
+  va_end(args);
+  return result;
+}
+
+ErrorCode ReadUtil::gather_related_ents(Range &partition,
+                                            Range &related_ents,
+                                            Range *all_sets) 
+{
+    // loop over any sets, getting contained ents
+  std::pair<Range::const_iterator, Range::const_iterator> pair_it =
+    partition.equal_range(MBENTITYSET);
+
+  ErrorCode result = MB_SUCCESS;
+  for (Range::const_iterator rit = pair_it.first; 
+       rit != pair_it.second; rit++) {
+    ErrorCode tmp_result = 
+      mMB->get_entities_by_handle(*rit, related_ents, 
+                                  Interface::UNION);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  RR;
+
+    // gather adjacent ents of other dimensions
+  Range tmp_ents;
+  for (int dim = 3; dim >= 0; dim--) {
+    tmp_ents.clear();
+    ErrorCode tmp_result = mMB->get_adjacencies(related_ents, dim, false, 
+                                                  tmp_ents, 
+                                                  Interface::UNION);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+    else related_ents.merge(tmp_ents);
+  }
+  RR;
+  
+    // related ents includes the partition itself
+  related_ents.merge(partition);
+  
+    // get contains-related sets
+  Range tmp_ents3, last_related;
+  if (!all_sets) all_sets = &tmp_ents3;
+  result = mMB->get_entities_by_type(0, MBENTITYSET, *all_sets); RR;
+  while (related_ents.size() != last_related.size()) {
+    last_related = related_ents;
+    for (Range::iterator rit = all_sets->begin(); 
+         rit != all_sets->end(); rit++) {
+      if (related_ents.find(*rit) != related_ents.end()) continue;
+      
+      tmp_ents.clear();
+      result = mMB->get_entities_by_handle(*rit, tmp_ents, true); RR;
+      Range tmp_ents2 = intersect( tmp_ents, related_ents);
+    
+        // if the intersection is not empty, set is related
+      if (!tmp_ents2.empty()) related_ents.insert(*rit);
+    }
+  }
+  
+    // get parent/child-related sets
+  last_related.clear();
+  while (related_ents.size() != last_related.size()) {
+    last_related = related_ents;
+    std::pair<Range::const_iterator, Range::const_iterator> it_pair = 
+      last_related.equal_range(MBENTITYSET);
+
+    for (Range::const_iterator rit = it_pair.first;
+         rit != it_pair.second; rit++) {
+        // get all parents/children and add to related ents
+      tmp_ents.clear();
+      result = mMB->get_parent_meshsets(*rit, tmp_ents, 0); RR;
+      related_ents.merge(tmp_ents);
+      
+      tmp_ents.clear();
+      result = mMB->get_child_meshsets(*rit, tmp_ents, 0); RR;
+      related_ents.merge(tmp_ents);
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ReadUtil::get_ordered_vertices(EntityHandle *bound_ents,
+                                             int *sense, 
+                                             int bound_size,
+                                             int dim,
+                                             EntityHandle *bound_verts, 
+                                             EntityType &etype) 
+{
+    // get dimension of bounding entities
+  int bound_dim = MBCN::Dimension(TYPE_FROM_HANDLE(bound_ents[0]));
+  int indices[MB_MAX_SUB_ENTITY_VERTICES];
+  const EntityHandle *connect;
+  std::vector<EntityHandle> tmp_connect;
+  
+    // find the right entity type based on # bounding ents
+  int numv = 0, num_connect;
+  ErrorCode result;
+  for (EntityType t = MBEDGE; t < MBENTITYSET; t++) {
+    int nindex = MBCN::NumSubEntities(t, bound_dim);
+    if (MBCN::Dimension(t) != dim || nindex != bound_size) 
+      continue;
+
+      // fill in vertices from bounding entity vertices
+    int nverts = MBCN::VerticesPerEntity(t);
+    std::fill(bound_verts, bound_verts+nverts, 0);
+    for (int index = 0; index < nindex; index++) {
+      result = mMB->get_connectivity(bound_ents[index], connect, num_connect,
+                                     false, &tmp_connect);
+      if (MB_SUCCESS != result) return result;
+      
+      MBCN::SubEntityVertexIndices(t, bound_dim, index, indices);
+
+      for (int c = 0; c < num_connect; c++) {
+        if (!bound_verts[indices[c]]) {
+          bound_verts[indices[c]] = (sense[index] > 0) ?
+              connect[c] : connect[num_connect - c - 1];
+          numv++;
+        }
+      }
+      if (numv == nverts) {
+        etype = t;
+        return MB_SUCCESS;
+      }
+    }
+  }
+  
+    // if we get here, we didn't get full connectivity
+  etype = MBMAXTYPE;
+  return MB_FAILURE;
+}
+
+static ErrorCode check_int_tag( Interface* mb, Tag tag )
+{
+  int size;
+  DataType type;
+  ErrorCode rval = mb->tag_get_size( tag, size );
+  if (MB_SUCCESS != rval)
+    return rval;
+  if (size != sizeof(int))
+    return MB_TYPE_OUT_OF_RANGE;
+  rval = mb->tag_get_data_type( tag, type );
+  if (type != MB_TYPE_OPAQUE && type != MB_TYPE_INTEGER)
+    return MB_TYPE_OUT_OF_RANGE;
+  return MB_SUCCESS;
+}
+
+ErrorCode ReadUtil::assign_ids( Tag id_tag, const Range& ents, int start )
+{
+  ErrorCode rval = check_int_tag( mMB, id_tag );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  Range tmp_range;
+  std::vector<int> data;
+  for (Range::const_pair_iterator i = ents.pair_begin(); 
+       i != ents.pair_end(); ++i) {
+    data.resize( i->second + 1 - i->first );
+    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
+      *j = start++;
+    tmp_range.clear();
+    tmp_range.insert( i->first, i->second );
+    rval = mMB->tag_set_data( id_tag, tmp_range, &data[0] );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ReadUtil::assign_ids( Tag id_tag, 
+                                    const EntityHandle* ents, 
+                                    size_t num_ents, 
+                                    int start )
+{
+  ErrorCode rval = check_int_tag( mMB, id_tag );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  std::vector<int> data;
+  const EntityHandle* const end = ents + num_ents;
+  const EntityHandle* i = ents;
+  while (i != end) {
+    const EntityHandle* next = std::find( i, end, 0 );
+    size_t size = next - i;
+    if (!size) {
+      ++i;
+      continue;
+    }
+    
+    int id = start + (i - ents);
+    data.resize(size);
+    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
+      *j = id++;
+    
+    rval = mMB->tag_set_data( id_tag, i, size, &data[0] );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+} // namespace moab

Copied: MOAB/trunk/src/ReadUtil.hpp (from rev 3583, MOAB/trunk/src/MBReadUtil.hpp)
===================================================================
--- MOAB/trunk/src/ReadUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/ReadUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,120 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+#ifndef MB_READ_UTIL_HPP
+#define MB_READ_UTIL_HPP
+
+#ifndef IS_BUILDING_MB
+#error "ReadUtil.hpp isn't supposed to be included into an application"
+#endif
+
+#include "moab/ReadUtilIface.hpp"
+
+namespace moab {
+
+class Core;
+class Error;
+
+class ReadUtil : public ReadUtilIface
+{
+private:
+  //! pointer to the Core
+  Core* mMB;
+  Error* mError;
+public:
+
+  //! constructor takes Core pointer
+  ReadUtil(Core* mdb, Error* error_handler);
+
+  //! destructor
+  ~ReadUtil(){}
+
+  //! gets arrays for coordinate data from the MB
+  ErrorCode get_node_arrays(
+      const int num_arrays,
+      const int num_nodes, 
+      const int preferred_start_id,
+      EntityHandle& actual_start_handle, 
+      std::vector<double*>& arrays
+      );
+
+  //! get array for connectivity data from the MB
+  ErrorCode get_element_array(
+      const int num_elements, 
+      const int verts_per_element,
+      const EntityType mdb_type,
+      const int preferred_start_id, 
+      EntityHandle& actual_start_handle, 
+      EntityHandle*& array
+      );
+
+    /**
+     *\brief Gather entities related to those in the partition
+     * Gather entities related to those in the input partition.  Related
+     * means down-adjacent to, contained in, etc.
+     * \param partition Entities for which to gather related entities
+     * \param related_ents Related entities
+     * \param all_sets If non-NULL, all sets in mesh instance are returned
+     * in the pointed-to range
+     */
+  ErrorCode gather_related_ents(Range &partition,
+                                  Range &related_ents,
+                                  Range *all_sets);
+  
+  ErrorCode create_entity_sets(
+    EntityID num_sets,
+    const unsigned* set_flags,
+    EntityID preffered_start_id,
+    EntityHandle& actual_start_handle
+  );
+ 
+  //! tell MB which elements have been added to the database
+  ErrorCode update_adjacencies(
+      const EntityHandle start_handle,
+      const int number_elements,
+      const int number_vertices_per_element,
+      const EntityHandle* conn_array);
+
+  //! tell MB there was an error when reading the mesh
+  //! it makes sense to have this as long as Interface has a load_mesh function
+  ErrorCode report_error( const std::string& error );
+
+  ErrorCode report_error( const char* error, ... )
+#ifdef __GNUC__
+__attribute__((format(printf,2,3)))
+#endif
+  ;
+
+    //! given an ordered list of bounding entities and the sense of
+    //! those entities, return an ordered list of vertices
+  ErrorCode get_ordered_vertices(EntityHandle *bound_ents, 
+                                   int *sense, 
+                                   int num_bound,
+                                   int dim,
+                                   EntityHandle *bound_verts, 
+                                   EntityType &etype);
+
+
+  ErrorCode assign_ids( Tag id_tag, const Range& ents, int start = 0 );
+  ErrorCode assign_ids( Tag id_tag, const EntityHandle* ents, 
+                          size_t num_ents, int start = 0 );
+};
+  
+} // namespace moab
+
+#endif
+
+

Copied: MOAB/trunk/src/ReaderWriterSet.cpp (from rev 3583, MOAB/trunk/src/MBReaderWriterSet.cpp)
===================================================================
--- MOAB/trunk/src/ReaderWriterSet.cpp	                        (rev 0)
+++ MOAB/trunk/src/ReaderWriterSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,288 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#include "moab/Core.hpp"
+#include "Error.hpp"
+
+#include "moab/ReaderWriterSet.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/WriterIface.hpp"
+
+#include "ReadVtk.hpp"
+#include "ReadSTL.hpp"
+#include "ReadGmsh.hpp"
+#include "ReadIDEAS.hpp"
+#include "ReadMCNP5.hpp"
+#include "ReadNASTRAN.hpp"
+#include "ReadABAQUS.hpp"
+#include "ReadSms.hpp"
+#include "Tqdcfr.hpp"
+#include "ReadTetGen.hpp"
+#include "ReadSmf.hpp"
+#ifdef CGM
+#  include "ReadCGM.hpp"
+#endif
+
+#include "WriteAns.hpp"
+#include "WriteVtk.hpp"
+#include "WriteGMV.hpp"
+#include "WriteSTL.hpp"
+#include "WriteGmsh.hpp"
+#include "WriteSmf.hpp"
+
+#ifdef NETCDF_FILE
+#  include "ReadNCDF.hpp"
+#  include "WriteNCDF.hpp"
+#  include "WriteSLAC.hpp"
+#endif
+
+#ifdef CCMIO_FILE
+#  include "WriteCCMIO.hpp"
+#  include "ReadCCMIO.hpp"
+#endif
+
+#ifdef HDF5_FILE
+#  include "ReadHDF5.hpp"
+#  ifdef HDF5_PARALLEL
+#    include "WriteHDF5Parallel.hpp"
+#  else
+#    include "WriteHDF5.hpp"
+#  endif
+#endif
+
+#include <algorithm>
+
+namespace moab {
+
+ReaderWriterSet::ReaderWriterSet( Core* mdb, Error* handler )
+  : mbCore( mdb ), mbError( handler ) 
+{
+#ifdef HDF5_FILE
+  const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
+#ifdef HDF5_PARALLEL
+  register_factory(  ReadHDF5::factory, WriteHDF5Parallel::factory, 
+                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
+#else
+  register_factory(  ReadHDF5::factory, WriteHDF5::factory, 
+                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
+#endif
+#endif
+
+#ifdef NETCDF_FILE
+  const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
+  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
+#endif
+
+  register_factory( ReadIDEAS::factory, NULL, "IDEAS format", "unv", "UNV" );
+  
+  register_factory( ReadMCNP5::factory, NULL, "MCNP5 format", "meshtal", "MESHTAL" );
+  
+  const char* nastran_sufxs[] = { "nas", "bdf", NULL };
+  register_factory( ReadNASTRAN::factory, NULL, "NASTRAN format", nastran_sufxs, "NAS" );
+
+  register_factory( ReadABAQUS::factory, NULL, "ABAQUS INP mesh format", "abq", "Abaqus mesh" );
+  
+  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );
+  
+  register_factory( ReadSms::factory, NULL, "RPI SMS", "sms", "SMS" );
+  
+  register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );
+  
+  register_factory( ReadSmf::factory, WriteSmf::factory , "QSlim format", "smf", "SMF");
+
+#ifdef CGM
+  const char* acis_sufxs[] = { "sat", "sab", NULL };
+  const char* occ_sufxs[] = { "brep", "occ", NULL };
+  const char* step_sufxs[] = { "step", "stp", NULL };
+  const char* iges_sufxs[] = { "iges", "igs", NULL };
+  register_factory( ReadCGM::factory, NULL, "ACIS solid model", acis_sufxs, "ACIS");
+  register_factory( ReadCGM::factory, NULL, "OpenCascade solid model", occ_sufxs, "OCC");
+  register_factory( ReadCGM::factory, NULL, "STEP B-Rep exchange", step_sufxs, "STEP");
+  register_factory( ReadCGM::factory, NULL, "IGES B-Rep exchange", iges_sufxs, "IGES");
+#endif
+
+#ifdef NETCDF_FILE  
+  register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
+#endif
+
+#ifdef CCMIO_FILE  
+  const char* ccmio_sufxs[] = { "ccm", "ccmg", NULL };
+  register_factory( ReadCCMIO::factory, WriteCCMIO::factory, "CCMIO files", ccmio_sufxs, "CCMIO");
+#endif
+
+  register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );
+  
+  register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );
+  
+  const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
+  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );
+  
+  register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );
+
+  const char* tetgen_sufxs[] = { "node", "ele", "face", "edge", NULL };
+  register_factory( ReadTetGen::factory, 0, "TetGen output files", tetgen_sufxs, "TETGEN" );
+}
+
+
+ReaderWriterSet::~ReaderWriterSet()
+{
+}
+
+ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,
+                                                 writer_factory_t writer,
+                                                 const char* description,
+                                                 const char* const* extensions,
+                                                 const char* name )
+{
+  if (!reader && !writer)
+    return MB_FAILURE;
+    
+    // check for duplicate names
+  iterator h = handler_by_name( name );
+  if (h != end()) {
+    mbError->set_last_error( "Conflicting string name for file formats: \"%s\"",
+                             name );
+    return MB_FAILURE;
+  }
+  
+    // count extensions and check for duplicates
+  const char* const* iter;
+  for (iter = extensions; *iter; ++iter)
+  {
+    h = handler_from_extension( *iter );
+    if (h != end())
+    {
+      if (NULL != reader && h->have_reader())
+        mbError->set_last_error( "Conflicting readers for file extension \"%s\":"
+                                 " \"%s\" and \"%s\".",
+                                 *iter, h->description().c_str(), description );
+      else if(NULL != writer && h->have_writer())
+        mbError->set_last_error( "Conflicting writers for file extension \"%s\":"
+                                 " \"%s\" and \"%s\".",
+                                 *iter, h->description().c_str(), description );
+    }
+  }
+  handlerList.push_back( Handler(reader, writer, name, description, extensions, iter - extensions) );
+  return MB_SUCCESS;
+}    
+
+ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,
+                                                 writer_factory_t writer,
+                                                 const char* description,
+                                                 const char* extension,
+                                                 const char* name )
+{
+  const char* extensions[2] = {extension, NULL};
+  return register_factory( reader, writer, description, extensions, name );
+}
+
+  
+ReaderIface* ReaderWriterSet::get_file_extension_reader( 
+                                  const std::string& filename ) const
+{
+  std::string ext = extension_from_filename( filename );
+  iterator handler = handler_from_extension( ext, true, false );
+  return handler == end() ? NULL : handler->make_reader(mbCore);
+}
+
+WriterIface* ReaderWriterSet::get_file_extension_writer( 
+                                  const std::string& filename ) const
+{
+  std::string ext = extension_from_filename( filename );
+  iterator handler = handler_from_extension( ext, false, true );
+  return handler == end() ? NULL : handler->make_writer(mbCore);
+}
+
+std::string ReaderWriterSet::extension_from_filename( 
+                                 const std::string& filename )
+{
+  std::string::size_type idx = filename.find_last_of( "." );
+  if (idx == std::string::npos)
+    return std::string("");
+  else
+    return filename.substr( idx + 1 );
+}
+
+ReaderWriterSet::Handler::Handler( reader_factory_t read_f, 
+                                     writer_factory_t write_f,
+                                     const char* name,
+                                     const char* desc, 
+                                     const char* const* ext, 
+                                     int num_ext )
+ : mReader(read_f), mWriter(write_f), mName(name), mDescription(desc), mExtensions(num_ext)
+{
+  for (int i = 0; i < num_ext; ++i)
+    mExtensions[i] = ext[i];
+}
+
+#ifdef WIN32
+#define strcasecmp(A,B) _stricmp( A, B )
+#endif
+
+ReaderWriterSet::iterator 
+ReaderWriterSet::handler_from_extension( const std::string& ext,
+                                           bool with_reader,
+                                           bool with_writer ) const
+{
+  iterator iter;
+  std::vector<std::string>::const_iterator siter;
+  
+    // try case-sensitive compare
+  for (iter = begin(); iter != end(); ++iter)
+  {
+    if ((with_reader && !iter->have_reader()) ||
+        (with_writer && !iter->have_writer()))
+      continue;
+      
+    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
+      if (*siter == ext)
+        return iter;
+  }
+  
+    // try case-insensitive compare
+  for (iter = begin(); iter != end(); ++iter)
+  {
+    if ((with_reader && !iter->have_reader()) ||
+        (with_writer && !iter->have_writer()))
+      continue;
+ 
+    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
+      if (0 == strcasecmp( siter->c_str(), ext.c_str() ))
+        return iter;
+  }
+  
+  return end();
+}
+
+ReaderWriterSet::iterator
+ReaderWriterSet::handler_by_name( const char* name ) const
+{
+  return std::find( begin(), end(), name );
+}
+
+bool ReaderWriterSet::Handler::operator==( const char* name ) const
+{
+    // do case-insensitive comparison
+  std::string::const_iterator siter = mName.begin();
+  for (; *name; ++name, ++siter)
+    if (siter == mName.end() || tolower(*name) != tolower(*siter))
+      return false;
+  return *name == '\0';
+}
+  
+} // namespace moab
+
+
+

Modified: MOAB/trunk/src/ScdElementData.cpp
===================================================================
--- MOAB/trunk/src/ScdElementData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/ScdElementData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,13 +15,15 @@
 
 #include "ScdElementData.hpp"
 #include "ScdVertexData.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 #include <assert.h>
 
-MBEntityID ScdElementData::calc_num_entities(MBEntityHandle start_handle,
+namespace moab {
+
+EntityID ScdElementData::calc_num_entities(EntityHandle start_handle,
                                 int irange, int jrange, int krange)
 {
   size_t result = 1;
@@ -35,7 +37,7 @@
 }
 
 ScdElementData::ScdElementData(
-                             MBEntityHandle start_handle,
+                             EntityHandle start_handle,
                              const int imin, const int jmin, const int kmin,
                              const int imax, const int jmax, const int kmax) 
     : SequenceData(0, start_handle,
@@ -135,8 +137,8 @@
 }
 
 
-SequenceData* ScdElementData::subset( MBEntityHandle /*start*/, 
-                                      MBEntityHandle /*end*/,
+SequenceData* ScdElementData::subset( EntityHandle /*start*/, 
+                                      EntityHandle /*end*/,
                                       const int* /*sequence_data_sizes*/,
                                       const int* /*tag_data_sizes*/ ) const
 {
@@ -147,3 +149,5 @@
 {
   return sizeof(*this) + vertexSeqRefs.capacity() * sizeof(VertexDataRef);
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/ScdElementData.hpp
===================================================================
--- MOAB/trunk/src/ScdElementData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/ScdElementData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -28,15 +28,17 @@
 // handles associated with the element are each contiguous.
 
 #include "SequenceData.hpp"
-#include "HomXform.hpp"
-#include "MBCN.hpp"
+#include "moab/HomXform.hpp"
+#include "moab/MBCN.hpp"
 #include "ScdVertexData.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 
 #include <vector>
 #include <algorithm>
 
+namespace moab {
+
 class ScdElementData : public SequenceData
 {
 
@@ -78,19 +80,19 @@
 public:
 
     //! constructor
-  ScdElementData( MBEntityHandle start_handle,
+  ScdElementData( EntityHandle start_handle,
                   const int imin, const int jmin, const int kmin,
                   const int imax, const int jmax, const int kmax);
   
   virtual ~ScdElementData();
   
     //! get handle of vertex at homogeneous coords
-  inline MBEntityHandle get_vertex(const HomCoord &coords) const;
-  inline MBEntityHandle get_vertex(int i, int j, int k) const
+  inline EntityHandle get_vertex(const HomCoord &coords) const;
+  inline EntityHandle get_vertex(int i, int j, int k) const
     { return get_vertex(HomCoord(i,j,k)); }
   
     //! get handle of element at i, j, k
-  MBEntityHandle get_element(const int i, const int j, const int k) const;
+  EntityHandle get_element(const int i, const int j, const int k) const;
   
     //! get min params for this element
   const HomCoord &min_params() const;
@@ -102,7 +104,7 @@
   void param_extents(int &di, int &dj, int &dk) const;
 
     //! given a handle, get the corresponding parameters
-  MBErrorCode get_params(const MBEntityHandle ehandle,
+  ErrorCode get_params(const EntityHandle ehandle,
                           int &i, int &j, int &k) const;
   
     //! convenience functions for parameter extents
@@ -121,15 +123,15 @@
   inline bool contains(const HomCoord &coords) const;
 
     //! get connectivity of an entity given entity's parameters
-  inline MBErrorCode get_params_connectivity(const int i, const int j, const int k,
-                                       std::vector<MBEntityHandle>& connectivity) const;
+  inline ErrorCode get_params_connectivity(const int i, const int j, const int k,
+                                       std::vector<EntityHandle>& connectivity) const;
   
     //! add a vertex seq ref to this element sequence;
     //! if bb_input is true, bounding box (in eseq-local coords) of vseq being added 
     //! is input in bb_min and bb_max (allows partial sharing of vseq rather than the whole
     //! vseq); if it's false, the whole vseq is referenced and the eseq-local coordinates
     //! is computed from the transformed bounding box of the vseq
-  MBErrorCode add_vsequence(ScdVertexData *vseq, 
+  ErrorCode add_vsequence(ScdVertexData *vseq, 
                              const HomCoord &p1, const HomCoord &q1,
                              const HomCoord &p2, const HomCoord &q2,
                              const HomCoord &p3, const HomCoord &q3,
@@ -138,12 +140,12 @@
                              const HomCoord &bb_max = HomCoord::unitv[0]);
 
 
-  SequenceData* subset( MBEntityHandle start, 
-                        MBEntityHandle end,
+  SequenceData* subset( EntityHandle start, 
+                        EntityHandle end,
                         const int* sequence_data_sizes,
                         const int* tag_data_sizes ) const;
   
-  static MBEntityID calc_num_entities( MBEntityHandle start_handle,
+  static EntityID calc_num_entities( EntityHandle start_handle,
                                        int irange,
                                        int jrange,
                                        int krange );
@@ -151,7 +153,7 @@
   unsigned long get_memory_use() const;
 };
 
-inline MBEntityHandle ScdElementData::get_element(const int i, const int j, const int k) const
+inline EntityHandle ScdElementData::get_element(const int i, const int j, const int k) const
 {
   return start_handle() + (i-i_min()) + (j-j_min())*dIJKm1[0] + (k-k_min())*dIJKm1[0]*dIJKm1[1];
 }
@@ -174,7 +176,7 @@
   dk = dIJK[2];
 }
 
-inline MBErrorCode ScdElementData::get_params(const MBEntityHandle ehandle,
+inline ErrorCode ScdElementData::get_params(const EntityHandle ehandle,
                                               int &i, int &j, int &k) const
 {
   if (TYPE_FROM_HANDLE(ehandle) != TYPE_FROM_HANDLE(start_handle())) return MB_FAILURE;
@@ -218,7 +220,7 @@
   minmax[1] = HomCoord(this_max); 
 }
 
-inline MBEntityHandle ScdElementData::get_vertex(const HomCoord &coords) const
+inline EntityHandle ScdElementData::get_vertex(const HomCoord &coords) const
 {
   assert(boundary_complete());
    for (std::vector<VertexDataRef>::const_iterator it = vertexSeqRefs.begin();
@@ -236,7 +238,7 @@
    return 0;
 }
 
-inline MBErrorCode ScdElementData::add_vsequence(ScdVertexData *vseq, 
+inline ErrorCode ScdElementData::add_vsequence(ScdVertexData *vseq, 
                                                  const HomCoord &p1, const HomCoord &q1,
                                                  const HomCoord &p2, const HomCoord &q2, 
                                                  const HomCoord &p3, const HomCoord &q3,
@@ -285,8 +287,8 @@
   return MB_SUCCESS;
 }
 
-inline MBErrorCode ScdElementData::get_params_connectivity(const int i, const int j, const int k,
-                                                           std::vector<MBEntityHandle>& connectivity) const
+inline ErrorCode ScdElementData::get_params_connectivity(const int i, const int j, const int k,
+                                                           std::vector<EntityHandle>& connectivity) const
 {
   if (contains(HomCoord(i, j, k)) == false) return MB_FAILURE;
   
@@ -302,5 +304,7 @@
   connectivity.push_back(get_vertex(i, j+1, k+1));
   return MB_SUCCESS;
 }
+  
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/ScdVertexData.cpp
===================================================================
--- MOAB/trunk/src/ScdVertexData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/ScdVertexData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,8 +16,10 @@
 #include "ScdVertexData.hpp"
 #include <assert.h>
 
+namespace moab {
+
     //! constructor
-ScdVertexData::ScdVertexData(const MBEntityHandle start_vertex, 
+ScdVertexData::ScdVertexData(const EntityHandle start_vertex, 
                              const int imin, const int jmin, const int kmin,
                              const int imax, const int jmax, const int kmax) 
     : SequenceData( 3, start_vertex, 
@@ -40,10 +42,12 @@
   create_sequence_data( 2, sizeof(double) );
 }
 
-SequenceData* ScdVertexData::subset( MBEntityHandle /*start*/, 
-                                     MBEntityHandle /*end*/,
+SequenceData* ScdVertexData::subset( EntityHandle /*start*/, 
+                                     EntityHandle /*end*/,
                                      const int* /*sequence_data_sizes*/,
                                      const int* /*tag_data_sizes*/ ) const
 {
   return 0;
 }
+  
+} // namespace moab

Modified: MOAB/trunk/src/ScdVertexData.hpp
===================================================================
--- MOAB/trunk/src/ScdVertexData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/ScdVertexData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,8 +25,10 @@
 // the parametric space used to address those vertices.
 
 #include "SequenceData.hpp"
-#include "HomXform.hpp"
+#include "moab/HomXform.hpp"
 
+namespace moab {
+
 class ScdVertexData : public SequenceData
 {
 
@@ -46,21 +48,21 @@
 public:
 
     //! constructor
-  ScdVertexData(const MBEntityHandle start_vertex, 
+  ScdVertexData(const EntityHandle start_vertex, 
                 const int imin, const int jmin, const int kmin,
                 const int imax, const int jmax, const int kmax) ;
   
   virtual ~ScdVertexData() {};
 
     //! get handle of vertex at i, j, k
-  MBEntityHandle get_vertex(const int i, const int j, const int k) const;
+  EntityHandle get_vertex(const int i, const int j, const int k) const;
 
     //! get handle of vertex at homogeneous coordinates
-  MBEntityHandle get_vertex(const HomCoord &coords) const;
+  EntityHandle get_vertex(const HomCoord &coords) const;
 
     //! get the parameters of a given handle; return MB_FAILURE if vhandle not in this
     //! sequence
-  MBErrorCode get_params(const MBEntityHandle vhandle,
+  ErrorCode get_params(const EntityHandle vhandle,
                           int &i, int &j, int &k) const;
   
     //! get min params for this vertex
@@ -90,25 +92,25 @@
   bool contains(const HomCoord &coords) const;
   bool contains(const int i, const int j, const int k) const;
 
-  SequenceData* subset( MBEntityHandle start, 
-                        MBEntityHandle end,
+  SequenceData* subset( EntityHandle start, 
+                        EntityHandle end,
                         const int* sequence_data_sizes,
                         const int* tag_data_sizes ) const;
 };
 
-inline MBEntityHandle ScdVertexData::get_vertex(const int i, const int j, 
+inline EntityHandle ScdVertexData::get_vertex(const int i, const int j, 
                                                 const int k) const
 {
   return start_handle() + (i-i_min()) + (j-j_min())*dIJK[0] + 
     (k-k_min())*dIJK[0]*dIJK[1];
 }
 
-inline MBEntityHandle ScdVertexData::get_vertex(const HomCoord &coords) const
+inline EntityHandle ScdVertexData::get_vertex(const HomCoord &coords) const
 {
   return get_vertex(coords.hom_coord()[0], coords.hom_coord()[1], coords.hom_coord()[2]);
 }
 
-inline MBErrorCode ScdVertexData::get_params(const MBEntityHandle vhandle,
+inline ErrorCode ScdVertexData::get_params(const EntityHandle vhandle,
                                              int &i, int &j, int &k) const
 {
   if (TYPE_FROM_HANDLE(vhandle) != MBVERTEX) return MB_FAILURE;
@@ -172,5 +174,7 @@
 {
   return contains(HomCoord(i, j, k));
 }
+  
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/SequenceData.cpp
===================================================================
--- MOAB/trunk/src/SequenceData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SequenceData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
 #include "SequenceData.hpp"
 #include "TagServer.hpp"
-#include "MBSysUtil.hpp"
+#include "SysUtil.hpp"
 #include "VarLenTag.hpp"
 #include <assert.h>
 
+namespace moab {
+
 SequenceData::~SequenceData()
 {
   for (int i = -numSequenceData; i <= (int)numTagData; ++i)
@@ -15,7 +17,7 @@
 {  
   char* array = (char*)malloc( bytes_per_ent * size() );
   if (initial_value)
-    MBSysUtil::setmem( array, initial_value, bytes_per_ent, size() );
+    SysUtil::setmem( array, initial_value, bytes_per_ent, size() );
   else 
     memset( array, 0, bytes_per_ent * size() );
   
@@ -65,7 +67,7 @@
   numTagData += amount;
 }
 
-void* SequenceData::create_tag_data( MBTagId tag_num,
+void* SequenceData::create_tag_data( TagId tag_num,
                                      int bytes_per_ent,
                                      const void* initial_val )
 {
@@ -76,16 +78,16 @@
   return create_data( tag_num + 1, bytes_per_ent, initial_val );
 }
 
-SequenceData* SequenceData::subset( MBEntityHandle start,
-                                    MBEntityHandle end,
+SequenceData* SequenceData::subset( EntityHandle start,
+                                    EntityHandle end,
                                     const int* sequence_data_sizes ) const
 {
   return new SequenceData( this, start, end, sequence_data_sizes );
 }
 
 SequenceData::SequenceData( const SequenceData* from,
-                            MBEntityHandle start, 
-                            MBEntityHandle end,
+                            EntityHandle start, 
+                            EntityHandle end,
                             const int* sequence_data_sizes )
   : numSequenceData( from->numSequenceData ),
     numTagData( from->numTagData ),
@@ -158,7 +160,7 @@
     release_tag_data( i, tag_sizes[i] );
 }
 
-void SequenceData::release_tag_data( MBTagId tag_num, int tag_size )
+void SequenceData::release_tag_data( TagId tag_num, int tag_size )
 {
   if (tag_num < numTagData) {
     if (tag_size == MB_VARIABLE_LENGTH && arraySet[tag_num+1]) {
@@ -172,3 +174,4 @@
   }
 }
 
+} // namespace moab

Modified: MOAB/trunk/src/SequenceData.hpp
===================================================================
--- MOAB/trunk/src/SequenceData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SequenceData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -8,33 +8,35 @@
 #include <stdlib.h>
 #include <string.h>
 
+namespace moab {
+
 class TagServer;
 
 class SequenceData
 {
 public:
 
-  typedef std::vector<MBEntityHandle>* AdjacencyDataType;
+  typedef std::vector<EntityHandle>* AdjacencyDataType;
 
   /**\param num_sequence_arrays Number of data arrays needed by the EntitySequence
    * \param start               First handle in this SequenceData
    * \param end                 Last handle in this SequenceData
    */
   inline SequenceData( int num_sequence_arrays, 
-                       MBEntityHandle start,
-                       MBEntityHandle end );
+                       EntityHandle start,
+                       EntityHandle end );
   
   virtual ~SequenceData();
   
   /**\return first handle in this sequence data */
-  MBEntityHandle start_handle() const 
+  EntityHandle start_handle() const 
     { return startHandle; }
   
   /**\return last handle in this sequence data */
-  MBEntityHandle end_handle() const
+  EntityHandle end_handle() const
     { return endHandle; }
     
-  MBEntityID size() const
+  EntityID size() const
     { return endHandle + 1 - startHandle; }
   
   /**\return ith array of EnitySequence-specific data */
@@ -52,10 +54,10 @@
                 { return reinterpret_cast<AdjacencyDataType const*>(arraySet[0]); }
   
   /**\return array of dense tag data, or NULL if none. */
-  void*       get_tag_data( MBTagId tag_num )              
+  void*       get_tag_data( TagId tag_num )              
                 { return tag_num < numTagData  ? arraySet[tag_num+1] : 0; }
   /**\return array of dense tag data, or NULL if none. */
-  void const* get_tag_data( MBTagId tag_num ) const        
+  void const* get_tag_data( TagId tag_num ) const        
                 { return tag_num < numTagData  ? arraySet[tag_num+1] : 0; }
   
   /**\brief Allocate array of sequence-specific data
@@ -99,7 +101,7 @@
    *                      be bytes_per_ent long.  If NULL, array will be zeroed.
    *\return The newly allocated array, or NULL if error.
    */
-  void* create_tag_data( MBTagId tag_num, int bytes_per_ent, const void* initial_val = 0 );
+  void* create_tag_data( TagId tag_num, int bytes_per_ent, const void* initial_val = 0 );
   
   /**\brief Create new SequenceData that is a copy of a subset of this one
     *
@@ -112,8 +114,8 @@
     *\param sequence_data_sizes Bytes-per-entity for sequence-specific data.
     *\NOTE Does not copy tag data.
     */
-  SequenceData* subset( MBEntityHandle start, 
-                        MBEntityHandle end,
+  SequenceData* subset( EntityHandle start, 
+                        EntityHandle end,
                         const int* sequence_data_sizes ) const;
   
   /**\brief SequenceManager data */
@@ -125,13 +127,13 @@
   /**\brief Free all tag data arrays */
   void release_tag_data(const int* tag_sizes, int num_tag_sizes);
   /**\brief Free specified tag data array */
-  void release_tag_data( MBTagId tag_num, int tag_size );
+  void release_tag_data( TagId tag_num, int tag_size );
   
 protected:
 
   SequenceData( const SequenceData* subset_from,
-                MBEntityHandle start, 
-                MBEntityHandle end,
+                EntityHandle start, 
+                EntityHandle end,
                 const int* sequence_data_sizes );
 
 private:
@@ -148,12 +150,12 @@
   const int numSequenceData;
   unsigned numTagData;
   void** arraySet;
-  MBEntityHandle startHandle, endHandle;
+  EntityHandle startHandle, endHandle;
 };
 
 inline SequenceData::SequenceData( int num_sequence_arrays, 
-                                   MBEntityHandle start,
-                                   MBEntityHandle end )
+                                   EntityHandle start,
+                                   EntityHandle end )
   : numSequenceData(num_sequence_arrays),
     numTagData(0),
     startHandle(start),
@@ -165,5 +167,6 @@
   arraySet = data + num_sequence_arrays;
 }
 
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/SequenceManager.cpp
===================================================================
--- MOAB/trunk/src/SequenceManager.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SequenceManager.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,23 +5,29 @@
 #include "MeshSetSequence.hpp"
 #include "SweptElementSeq.hpp"
 #include "StructuredElementSeq.hpp"
-#include "HomXform.hpp"
+#include "moab/HomXform.hpp"
 #include "PolyElementSeq.hpp"
-#include "MBSysUtil.hpp"
+#include "SysUtil.hpp"
 #include "TagCompare.hpp"
 
 #include <assert.h>
 #include <new>
 #include <algorithm>
 
-const MBEntityID DEFAULT_VERTEX_SEQUENCE_SIZE = 4096;
-const MBEntityID DEFAULT_ELEMENT_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
-const MBEntityID DEFAULT_POLY_SEQUENCE_SIZE = 4 * DEFAULT_ELEMENT_SEQUENCE_SIZE;
-const MBEntityID DEFAULT_MESHSET_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+#ifndef NDEBUG
+#include <iostream>
+#endif 
 
+namespace moab {
+
+const EntityID DEFAULT_VERTEX_SEQUENCE_SIZE = 4096;
+const EntityID DEFAULT_ELEMENT_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+const EntityID DEFAULT_POLY_SEQUENCE_SIZE = 4 * DEFAULT_ELEMENT_SEQUENCE_SIZE;
+const EntityID DEFAULT_MESHSET_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+
 static inline
 const unsigned char* tag_array( const EntitySequence* seq, 
-                                MBEntityHandle h,
+                                EntityHandle h,
                                 int tag_id, 
                                 int tag_size )
 {
@@ -32,7 +38,7 @@
 
 static inline
 unsigned char* tag_array( EntitySequence* seq, 
-                          MBEntityHandle h, 
+                          EntityHandle h, 
                           int tag_id, 
                           int tag_size )
 {
@@ -43,7 +49,7 @@
 
 static inline
 unsigned char* make_tag( EntitySequence* seq, 
-                         MBEntityHandle h, 
+                         EntityHandle h, 
                          int tag_id, 
                          int tag_size,
                          const void* default_value )
@@ -57,7 +63,7 @@
 
 static inline
 const VarLenTag* vtag_array( const EntitySequence* seq, 
-                             MBEntityHandle h, 
+                             EntityHandle h, 
                              int tag_id )
 {
   const void* mem = seq->data()->get_tag_data(tag_id);
@@ -66,7 +72,7 @@
 
 static inline
 VarLenTag* vtag_array( EntitySequence* seq, 
-                       MBEntityHandle h, 
+                       EntityHandle h, 
                        int tag_id )
 {
   void* mem = seq->data()->get_tag_data(tag_id);
@@ -75,7 +81,7 @@
 
 static inline
 VarLenTag* make_vtag( EntitySequence* seq, 
-                      MBEntityHandle h, 
+                      EntityHandle h, 
                       int tag_id )
 {
   void* mem = seq->data()->get_tag_data(tag_id);
@@ -84,8 +90,8 @@
   return reinterpret_cast<VarLenTag*>(mem) + h - seq->data()->start_handle();
 }
 
-MBEntityID SequenceManager::default_poly_sequence_size( int conn_len )
-  {  return std::max( DEFAULT_POLY_SEQUENCE_SIZE / conn_len, (MBEntityID)1 ); }
+EntityID SequenceManager::default_poly_sequence_size( int conn_len )
+  {  return std::max( DEFAULT_POLY_SEQUENCE_SIZE / conn_len, (EntityID)1 ); }
 
 SequenceManager::~SequenceManager()
 {
@@ -103,21 +109,21 @@
       release_tag( i );
 
     // destroy all TypeSequenceManager instances
-  for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t)
+  for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t)
     typeData[t].~TypeSequenceManager();
     
     // now re-create TypeSequenceManager instances
-  for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t)
+  for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t)
     new (typeData+t) TypeSequenceManager();
 }  
 
-MBErrorCode SequenceManager::check_valid_entities( const MBRange& entities ) const
+ErrorCode SequenceManager::check_valid_entities( const Range& entities ) const
 {
-  MBErrorCode rval;
-  MBRange::const_pair_iterator i;
+  ErrorCode rval;
+  Range::const_pair_iterator i;
   for (i = entities.const_pair_begin(); i != entities.const_pair_end(); ++i) {
-    const MBEntityType type1 = TYPE_FROM_HANDLE(i->first);
-    const MBEntityType type2 = TYPE_FROM_HANDLE(i->second);
+    const EntityType type1 = TYPE_FROM_HANDLE(i->first);
+    const EntityType type2 = TYPE_FROM_HANDLE(i->second);
     if (type1 == type2) {
       rval = typeData[type1].check_valid_handles( i->first, i->second );
       if (MB_SUCCESS != rval)
@@ -125,7 +131,7 @@
     }
     else {
       int junk;
-      MBEntityHandle split = CREATE_HANDLE( type2, 0, junk );
+      EntityHandle split = CREATE_HANDLE( type2, 0, junk );
       rval = typeData[type1].check_valid_handles( i->first, split-1 );
       if (MB_SUCCESS != rval)
         return rval;
@@ -137,13 +143,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::check_valid_entities( const MBEntityHandle* entities,
+ErrorCode SequenceManager::check_valid_entities( const EntityHandle* entities,
                                                    size_t num_entities ) const
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   const EntitySequence* ptr = 0;
   
-  const MBEntityHandle* const end = entities + num_entities;
+  const EntityHandle* const end = entities + num_entities;
   for (; entities < end; ++entities) {
     rval = find(*entities, ptr);
     if (MB_SUCCESS != rval)
@@ -153,22 +159,22 @@
   return rval;
 }
 
-MBErrorCode SequenceManager::delete_entity( MBEntityHandle entity )
+ErrorCode SequenceManager::delete_entity( EntityHandle entity )
 {
   return typeData[TYPE_FROM_HANDLE(entity)].erase( entity );
 }
 
-MBErrorCode SequenceManager::delete_entities( const MBRange& entities )
+ErrorCode SequenceManager::delete_entities( const Range& entities )
 {
-  MBErrorCode rval = check_valid_entities( entities );
+  ErrorCode rval = check_valid_entities( entities );
   if (MB_SUCCESS != rval)
     return rval;
   
-  MBErrorCode result = MB_SUCCESS;
-  MBRange::const_pair_iterator i;
+  ErrorCode result = MB_SUCCESS;
+  Range::const_pair_iterator i;
   for (i = entities.const_pair_begin(); i != entities.const_pair_end(); ++i) {
-    const MBEntityType type1 = TYPE_FROM_HANDLE(i->first);
-    const MBEntityType type2 = TYPE_FROM_HANDLE(i->second);
+    const EntityType type1 = TYPE_FROM_HANDLE(i->first);
+    const EntityType type2 = TYPE_FROM_HANDLE(i->second);
     if (type1 == type2) {
       rval = typeData[type1].erase( i->first, i->second );
       if (MB_SUCCESS != rval)
@@ -176,7 +182,7 @@
     }
     else {
       int junk;
-      MBEntityHandle split = CREATE_HANDLE( type2, 0, junk );
+      EntityHandle split = CREATE_HANDLE( type2, 0, junk );
       rval = typeData[type1].erase( i->first, split-1 );
       if (MB_SUCCESS != rval)
         return result = rval;
@@ -188,18 +194,18 @@
   return result;
 }
   
-MBErrorCode SequenceManager::create_vertex( const double coords[3],
-                                            MBEntityHandle& handle )
+ErrorCode SequenceManager::create_vertex( const double coords[3],
+                                            EntityHandle& handle )
 {
-  const MBEntityHandle start = CREATE_HANDLE( MBVERTEX, MB_START_ID );
-  const MBEntityHandle   end = CREATE_HANDLE( MBVERTEX,   MB_END_ID );
+  const EntityHandle start = CREATE_HANDLE( MBVERTEX, MB_START_ID );
+  const EntityHandle   end = CREATE_HANDLE( MBVERTEX,   MB_END_ID );
   bool append;
   TypeSequenceManager::iterator seq = typeData[MBVERTEX].find_free_handle( start, end, append );
   VertexSequence* vseq;
   
   if (seq == typeData[MBVERTEX].end()) {
     SequenceData* seq_data = 0;
-    MBEntityID seq_data_size = 0;
+    EntityID seq_data_size = 0;
     handle = typeData[MBVERTEX].find_free_sequence( DEFAULT_VERTEX_SEQUENCE_SIZE, start, end, seq_data, seq_data_size );
     if (!handle) 
       return MB_FAILURE;
@@ -209,7 +215,7 @@
     else
       vseq = new VertexSequence( handle, 1, DEFAULT_VERTEX_SEQUENCE_SIZE );
       
-    MBErrorCode rval = typeData[MBVERTEX].insert_sequence( vseq );
+    ErrorCode rval = typeData[MBVERTEX].insert_sequence( vseq );
     if (MB_SUCCESS != rval) {
       SequenceData* vdata = vseq->data();
       delete vseq;
@@ -237,16 +243,16 @@
 }
 
   
-MBErrorCode SequenceManager::create_element( MBEntityType type,
-                                             const MBEntityHandle* conn,
+ErrorCode SequenceManager::create_element( EntityType type,
+                                             const EntityHandle* conn,
                                              unsigned conn_len,
-                                             MBEntityHandle& handle )
+                                             EntityHandle& handle )
 {
   if (type <= MBVERTEX || type >= MBENTITYSET)
     return MB_TYPE_OUT_OF_RANGE;
   
-  const MBEntityHandle start = CREATE_HANDLE( type, MB_START_ID );
-  const MBEntityHandle   end = CREATE_HANDLE( type,   MB_END_ID );
+  const EntityHandle start = CREATE_HANDLE( type, MB_START_ID );
+  const EntityHandle   end = CREATE_HANDLE( type,   MB_END_ID );
   bool append;
   TypeSequenceManager::iterator seq = typeData[type].find_free_handle( start, end, append, conn_len );
   UnstructuredElemSeq* eseq;
@@ -257,7 +263,7 @@
     if (type == MBPOLYGON || type == MBPOLYHEDRON) {
       size = default_poly_sequence_size( conn_len );
     }
-    MBEntityID seq_data_size = 0;
+    EntityID seq_data_size = 0;
     handle = typeData[type].find_free_sequence( size, start, end, seq_data, seq_data_size, conn_len );
     if (!handle) 
       return MB_FAILURE;
@@ -275,7 +281,7 @@
         eseq = new UnstructuredElemSeq( handle, 1, conn_len, size );
     }
     
-    MBErrorCode rval = typeData[type].insert_sequence( eseq );
+    ErrorCode rval = typeData[type].insert_sequence( eseq );
     if (MB_SUCCESS != rval) {
       SequenceData* vdata = eseq->data();
       delete eseq;
@@ -304,18 +310,18 @@
 
 
   
-MBErrorCode SequenceManager::create_mesh_set( unsigned flags,
-                                              MBEntityHandle& handle )
+ErrorCode SequenceManager::create_mesh_set( unsigned flags,
+                                              EntityHandle& handle )
 {
-  const MBEntityHandle start = CREATE_HANDLE( MBENTITYSET, MB_START_ID );
-  const MBEntityHandle   end = CREATE_HANDLE( MBENTITYSET,   MB_END_ID );
+  const EntityHandle start = CREATE_HANDLE( MBENTITYSET, MB_START_ID );
+  const EntityHandle   end = CREATE_HANDLE( MBENTITYSET,   MB_END_ID );
   bool append;
   TypeSequenceManager::iterator seq = typeData[MBENTITYSET].find_free_handle( start, end, append );
   MeshSetSequence* msseq;
   
   if (seq == typeData[MBENTITYSET].end()) {
     SequenceData* seq_data = 0;
-    MBEntityID seq_data_size = 0;
+    EntityID seq_data_size = 0;
     handle = typeData[MBENTITYSET].find_free_sequence( DEFAULT_MESHSET_SEQUENCE_SIZE, start, end, seq_data, seq_data_size );
     if (!handle) 
       return MB_FAILURE;
@@ -325,7 +331,7 @@
     else
       msseq = new MeshSetSequence( handle, 1, flags, DEFAULT_MESHSET_SEQUENCE_SIZE );
       
-    MBErrorCode rval = typeData[MBENTITYSET].insert_sequence( msseq );
+    ErrorCode rval = typeData[MBENTITYSET].insert_sequence( msseq );
     if (MB_SUCCESS != rval) {
       SequenceData* vdata = msseq->data();
       delete msseq;
@@ -352,13 +358,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::allocate_mesh_set( MBEntityHandle handle,
+ErrorCode SequenceManager::allocate_mesh_set( EntityHandle handle,
                                                 unsigned flags )
 {
   SequenceData* data = 0;
   TypeSequenceManager::iterator seqptr; 
-  MBEntityHandle block_start = 1, block_end = 0;
-  MBErrorCode rval = typeData[MBENTITYSET].is_free_handle( handle, seqptr, data, block_start, block_end );
+  EntityHandle block_start = 1, block_end = 0;
+  ErrorCode rval = typeData[MBENTITYSET].is_free_handle( handle, seqptr, data, block_start, block_end );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -396,7 +402,7 @@
       seq = new MeshSetSequence( handle, 1, flags, block_end - handle + 1 );
     }
     
-    MBErrorCode rval = typeData[MBENTITYSET].insert_sequence( seq );
+    ErrorCode rval = typeData[MBENTITYSET].insert_sequence( seq );
     if (MB_SUCCESS != rval) {
       SequenceData* vdata = seq->data();
       delete seq;
@@ -410,8 +416,8 @@
 }
 
 void
-SequenceManager::trim_sequence_block( MBEntityHandle start_handle,
-                                      MBEntityHandle& end_handle,
+SequenceManager::trim_sequence_block( EntityHandle start_handle,
+                                      EntityHandle& end_handle,
                                       unsigned max_size )
 {
   assert( end_handle >= start_handle );
@@ -422,35 +428,35 @@
     end_handle = start_handle + max_size - 1;
 }
 
-MBEntityHandle 
-SequenceManager::sequence_start_handle( MBEntityType type,
-                                        MBEntityID count,
+EntityHandle 
+SequenceManager::sequence_start_handle( EntityType type,
+                                        EntityID count,
                                         int size,
-                                        MBEntityID start,
+                                        EntityID start,
                                         SequenceData*& data,
-                                        MBEntityID &data_size)
+                                        EntityID &data_size)
 {
   TypeSequenceManager &tsm = typeData[type];
   data = 0;
-  MBEntityHandle handle = CREATE_HANDLE( type, start );
+  EntityHandle handle = CREATE_HANDLE( type, start );
   if (start < MB_START_ID ||
       !tsm.is_free_sequence( handle, count, data, size )) {
-    MBEntityHandle pstart = CREATE_HANDLE( type, MB_START_ID );
-    MBEntityHandle pend   = CREATE_HANDLE( type,   MB_END_ID );
+    EntityHandle pstart = CREATE_HANDLE( type, MB_START_ID );
+    EntityHandle pend   = CREATE_HANDLE( type,   MB_END_ID );
     handle = tsm.find_free_sequence( count, pstart, pend, data, data_size, size);
   }
   return handle;
 }
 
 
-MBEntityID SequenceManager::new_sequence_size( MBEntityHandle start,
-                                               MBEntityID requested_size,
-                                               MBEntityID default_size ) const
+EntityID SequenceManager::new_sequence_size( EntityHandle start,
+                                               EntityID requested_size,
+                                               EntityID default_size ) const
 {
   if (requested_size >= default_size)
     return requested_size;
   
-  MBEntityHandle last = typeData[TYPE_FROM_HANDLE(start)].last_free_handle( start );
+  EntityHandle last = typeData[TYPE_FROM_HANDLE(start)].last_free_handle( start );
 // tjt - when start is 41427, last comes back 41685, when there's really an entity
     // at 41673, and 41467+246-1=41672
   if (!last) {
@@ -458,23 +464,23 @@
     return 0;
   }
   
-  MBEntityID available_size = last - start + 1;
+  EntityID available_size = last - start + 1;
   if (default_size < available_size)
     return default_size;
   else
     return available_size;
 }
 
-MBErrorCode 
-SequenceManager::create_entity_sequence( MBEntityType type,
-                                         MBEntityID count,
+ErrorCode 
+SequenceManager::create_entity_sequence( EntityType type,
+                                         EntityID count,
                                          int size,
-                                         MBEntityID start,
-                                         MBEntityHandle& handle,
+                                         EntityID start,
+                                         EntityHandle& handle,
                                          EntitySequence*& sequence )
 {
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   handle = sequence_start_handle( type, count, size, start, data, data_size );
     
   if (!handle)
@@ -531,7 +537,7 @@
     break;
   }
   
-  MBErrorCode result = typeData[type].insert_sequence( sequence );
+  ErrorCode result = typeData[type].insert_sequence( sequence );
   if (MB_SUCCESS != result) {
       // change to NULL if had an existing data or if no existing data,
       // change to the new data created
@@ -545,15 +551,15 @@
 }
 
 
-MBErrorCode 
-SequenceManager::create_meshset_sequence( MBEntityID count,
-                                          MBEntityID start,
+ErrorCode 
+SequenceManager::create_meshset_sequence( EntityID count,
+                                          EntityID start,
                                           const unsigned* flags,
-                                          MBEntityHandle& handle,
+                                          EntityHandle& handle,
                                           EntitySequence*& sequence )
 {
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   handle = sequence_start_handle( MBENTITYSET, count, 0, start, data, data_size );
 
   if (!handle)
@@ -566,7 +572,7 @@
   
   
   
-  MBErrorCode result = typeData[MBENTITYSET].insert_sequence( sequence );
+  ErrorCode result = typeData[MBENTITYSET].insert_sequence( sequence );
   if (MB_SUCCESS != result) {
       // change to NULL if had an existing data or if no existing data,
       // change to the new data created
@@ -580,15 +586,15 @@
 }
 
 
-MBErrorCode 
-SequenceManager::create_meshset_sequence( MBEntityID count,
-                                          MBEntityID start,
+ErrorCode 
+SequenceManager::create_meshset_sequence( EntityID count,
+                                          EntityID start,
                                           unsigned flags,
-                                          MBEntityHandle& handle,
+                                          EntityHandle& handle,
                                           EntitySequence*& sequence )
 {
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   handle = sequence_start_handle( MBENTITYSET, count, 0, start, data, data_size );
   if (!handle)
     return MB_MEMORY_ALLOCATION_FAILED;
@@ -600,7 +606,7 @@
   
   
   
-  MBErrorCode result = typeData[MBENTITYSET].insert_sequence( sequence );
+  ErrorCode result = typeData[MBENTITYSET].insert_sequence( sequence );
   if (MB_SUCCESS != result) {
       // change to NULL if had an existing data or if no existing data,
       // change to the new data created
@@ -613,12 +619,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode
+ErrorCode
 SequenceManager::create_scd_sequence( int imin, int jmin, int kmin,
                                       int imax, int jmax, int kmax,
-                                      MBEntityType type,
-                                      MBEntityID start_id_hint,
-                                      MBEntityHandle& handle,
+                                      EntityType type,
+                                      EntityID start_id_hint,
+                                      EntityHandle& handle,
                                       EntitySequence*& sequence )
 {
   int this_dim = MBCN::Dimension(type);
@@ -629,9 +635,9 @@
          (this_dim < 1 || imax > imin));
 
     // compute # entities; not as easy as it would appear...
-  MBEntityID num_ent;
+  EntityID num_ent;
   if (MBVERTEX == type)
-    num_ent = (MBEntityID)(imax-imin+1)*(MBEntityID)(jmax-jmin+1)*(MBEntityID)(kmax-kmin+1);
+    num_ent = (EntityID)(imax-imin+1)*(EntityID)(jmax-jmin+1)*(EntityID)(kmax-kmin+1);
   else {
     num_ent = (imax-imin) *
       (this_dim >= 2 ? (jmax-jmin) : 1) *
@@ -640,7 +646,7 @@
   
     // get a start handle
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   handle = sequence_start_handle( type, num_ent, -1, start_id_hint, data, data_size );
 
   if (!handle)
@@ -661,7 +667,7 @@
     return MB_TYPE_OUT_OF_RANGE;
   }
   
-  MBErrorCode result = typeData[type].insert_sequence( sequence );
+  ErrorCode result = typeData[type].insert_sequence( sequence );
   if (MB_SUCCESS != result) {
     data = sequence->data();
     delete sequence;
@@ -672,12 +678,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode
+ErrorCode
 SequenceManager::create_scd_sequence( const HomCoord& coord_min,
                                       const HomCoord& coord_max,
-                                      MBEntityType type,
-                                      MBEntityID start_id_hint,
-                                      MBEntityHandle& first_handle_out,
+                                      EntityType type,
+                                      EntityID start_id_hint,
+                                      EntityHandle& first_handle_out,
                                       EntitySequence*& sequence_out )
 {
   return create_scd_sequence( coord_min.i(), coord_min.j(), coord_min.k(),
@@ -686,13 +692,13 @@
                               first_handle_out, sequence_out );
 }
 
-MBErrorCode
+ErrorCode
 SequenceManager::create_sweep_sequence( int imin, int jmin, int kmin,
 					int imax, int jmax, int kmax,
 					int* Cq,
-					MBEntityType type,
-					MBEntityID start_id_hint,
-					MBEntityHandle& handle,
+					EntityType type,
+					EntityID start_id_hint,
+					EntityHandle& handle,
 					EntitySequence*& sequence )
 {
   int this_dim = MBCN::Dimension(type);
@@ -701,9 +707,9 @@
          (this_dim < 2 || jmax > jmin) &&
          (this_dim < 1 || imax > imin));
 
-  MBEntityID num_ent;
+  EntityID num_ent;
   if (MBVERTEX == type)
-    num_ent = (MBEntityID)(imax-imin+1)*(MBEntityID)(jmax-jmin+1)*(MBEntityID)(kmax-kmin+1);
+    num_ent = (EntityID)(imax-imin+1)*(EntityID)(jmax-jmin+1)*(EntityID)(kmax-kmin+1);
   else {
     num_ent = (imax-imin) *
       (this_dim >= 2 ? (jmax-jmin) : 1) *
@@ -712,7 +718,7 @@
   
     // get a start handle
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   handle = sequence_start_handle( type, num_ent, -1, start_id_hint, data, data_size );
 
   if (!handle)
@@ -733,7 +739,7 @@
     return MB_TYPE_OUT_OF_RANGE;
   }
   
-  MBErrorCode result = typeData[type].insert_sequence( sequence );
+  ErrorCode result = typeData[type].insert_sequence( sequence );
   if (MB_SUCCESS != result) {
     data = sequence->data();
     delete sequence;
@@ -744,13 +750,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode
+ErrorCode
 SequenceManager::create_sweep_sequence( const HomCoord& coord_min,
 					const HomCoord& coord_max,
 					int* Cq,
-					MBEntityType type,
-					MBEntityID start_id_hint,
-					MBEntityHandle& first_handle_out,
+					EntityType type,
+					EntityID start_id_hint,
+					EntityHandle& first_handle_out,
 					EntitySequence*& sequence_out )
 {
   return create_sweep_sequence( coord_min.i(), coord_min.j(), coord_min.k(),
@@ -760,7 +766,7 @@
 				first_handle_out, sequence_out );
 }
 
-MBErrorCode 
+ErrorCode 
 SequenceManager::add_vsequence(EntitySequence *vert_seq,
                                EntitySequence *elem_seq,
                                const HomCoord &p1, const HomCoord &q1,
@@ -785,10 +791,10 @@
                                  bb_input, HomCoord::unitv[0], HomCoord::unitv[0]);
 }
  
-MBErrorCode
+ErrorCode
 SequenceManager::replace_subsequence( EntitySequence* new_seq, TagServer* ts )
 {
-  const MBEntityType type = TYPE_FROM_HANDLE(new_seq->start_handle());
+  const EntityType type = TYPE_FROM_HANDLE(new_seq->start_handle());
   return typeData[type].replace_subsequence( new_seq, ts );
 }
 
@@ -799,7 +805,7 @@
   total_entity_storage = 0;
   total_storage = 0;
   unsigned long temp_entity, temp_total;
-  for (MBEntityType i = MBVERTEX; i < MBMAXTYPE; ++i) {
+  for (EntityType i = MBVERTEX; i < MBMAXTYPE; ++i) {
     temp_entity = temp_total = 0;
     get_memory_use( i, temp_entity, temp_total );
     total_entity_storage += temp_entity;
@@ -807,24 +813,24 @@
   }
 }
 
-void SequenceManager::get_memory_use( MBEntityType type,
+void SequenceManager::get_memory_use( EntityType type,
                                       unsigned long& total_entity_storage,
                                       unsigned long& total_storage ) const
 {
   typeData[type].get_memory_use( total_entity_storage, total_storage );
 }
 
-void SequenceManager::get_memory_use( const MBRange& entities,
+void SequenceManager::get_memory_use( const Range& entities,
                                       unsigned long& total_entity_storage,
                                       unsigned long& total_amortized_storage ) const
 {
   total_entity_storage = 0;
   total_amortized_storage = 0;
   unsigned long temp_entity, temp_total;
-  MBRange::const_pair_iterator i;
+  Range::const_pair_iterator i;
   for (i = entities.const_pair_begin(); i != entities.const_pair_end(); ++i) {
-    const MBEntityType t1 = TYPE_FROM_HANDLE(i->first);
-    const MBEntityType t2 = TYPE_FROM_HANDLE(i->second);
+    const EntityType t1 = TYPE_FROM_HANDLE(i->first);
+    const EntityType t2 = TYPE_FROM_HANDLE(i->second);
     if (t1 == t2) {
       temp_entity = temp_total = 0;
       typeData[t1].get_memory_use( i->first, i->second, temp_entity, temp_total );
@@ -848,14 +854,14 @@
 }
 
 void SequenceManager::reset_tag_data() {
-  for (MBEntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
+  for (EntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
     TypeSequenceManager& seqs = entity_map(t);
     for (TypeSequenceManager::iterator i = seqs.begin(); i != seqs.end(); ++i)
       (*i)->data()->release_tag_data( &tagSizes[0], tagSizes.size() );
   }
 }
 
-MBErrorCode SequenceManager::reserve_tag_id( int size, MBTagId tag_id )
+ErrorCode SequenceManager::reserve_tag_id( int size, TagId tag_id )
 {
   if (size < 1 && size != MB_VARIABLE_LENGTH)
     return MB_INVALID_SIZE;
@@ -867,13 +873,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::release_tag( MBTagId tag_id )
+ErrorCode SequenceManager::release_tag( TagId tag_id )
 {
   if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
     return MB_TAG_NOT_FOUND;
   tagSizes[tag_id] = 0;
   
-  for (MBEntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
+  for (EntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
     TypeSequenceManager& seqs = entity_map(t);
     for (TypeSequenceManager::iterator i = seqs.begin(); i != seqs.end(); ++i)
       (*i)->data()->release_tag_data(tag_id, tagSizes[tag_id]);
@@ -881,8 +887,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::remove_tag_data( MBTagId tag_id, 
-                                              MBEntityHandle handle,
+ErrorCode SequenceManager::remove_tag_data( TagId tag_id, 
+                                              EntityHandle handle,
                                               const void* default_tag_value,
                                               int default_value_size )
 {
@@ -890,7 +896,7 @@
     return MB_TAG_NOT_FOUND;
 
   EntitySequence* seq = 0;
-  MBErrorCode rval = find( handle, seq );
+  ErrorCode rval = find( handle, seq );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -916,8 +922,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::set_tag_data( MBTagId tag_id,
-                                           const MBEntityHandle* handles,
+ErrorCode SequenceManager::set_tag_data( TagId tag_id,
+                                           const EntityHandle* handles,
                                            int num_handles,
                                            const void* values,
                                            const void* default_value )
@@ -929,12 +935,12 @@
       return MB_TAG_NOT_FOUND;
   }
   
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   const unsigned char* ptr = reinterpret_cast<const unsigned char*>(values);
-  const MBEntityHandle* const end = handles + num_handles;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ptr += tagSizes[tag_id] ) {
+  const EntityHandle* const end = handles + num_handles;
+  for (const EntityHandle* i = handles; i != end; ++i, ptr += tagSizes[tag_id] ) {
     EntitySequence* seq = 0;
-    MBErrorCode rval = find( *i, seq );
+    ErrorCode rval = find( *i, seq );
     if (MB_SUCCESS != rval) {
       result = rval;
       continue;
@@ -947,24 +953,24 @@
   return result;
 }
 
-MBErrorCode SequenceManager::set_tag_data( MBTagId tag_id,
-                                           const MBEntityHandle* handles,
+ErrorCode SequenceManager::set_tag_data( TagId tag_id,
+                                           const EntityHandle* handles,
                                            int num_handles,
                                            void const* const* values,
                                            const int* lengths,
                                            const void* default_value )
 {
-  MBErrorCode result = MB_SUCCESS;
-  const MBEntityHandle* const end = handles + num_handles;
+  ErrorCode result = MB_SUCCESS;
+  const EntityHandle* const end = handles + num_handles;
   
   if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
     if (!lengths)
       return MB_VARIABLE_DATA_LENGTH;
     
-    for (const MBEntityHandle* i = handles; i != end; ++i, ++values, ++lengths ) {
+    for (const EntityHandle* i = handles; i != end; ++i, ++values, ++lengths ) {
         // find sequence for entity
       EntitySequence* seq = 0;
-      MBErrorCode rval = find( *i, seq );
+      ErrorCode rval = find( *i, seq );
       if (MB_SUCCESS != rval) {
         result = rval;
         continue;
@@ -975,10 +981,10 @@
     }
   }
   else {
-    for (const MBEntityHandle* i = handles; i != end; ++i, ++values ) {
+    for (const EntityHandle* i = handles; i != end; ++i, ++values ) {
         // find sequence for entity
       EntitySequence* seq = 0;
-      MBErrorCode rval = find( *i, seq );
+      ErrorCode rval = find( *i, seq );
       if (MB_SUCCESS != rval) {
         result = rval;
         continue;
@@ -992,12 +998,12 @@
   return result;
 }
 
-MBErrorCode SequenceManager::set_tag_data( MBTagId tag_id,
-                                           const MBRange& handles,
+ErrorCode SequenceManager::set_tag_data( TagId tag_id,
+                                           const Range& handles,
                                            const void* values,
                                            const void* default_value )
 {
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
     // NOTE: Comparison of size to 1 should also catch 
     //       case where tag is variable-length.  
   if (tag_id >= tagSizes.size() || tagSizes[tag_id] < 1) {
@@ -1009,11 +1015,11 @@
   
   const char* data = reinterpret_cast<const char*>(values);
 
-  MBRange::const_pair_iterator p = handles.begin();
-  for (MBRange::const_pair_iterator p = handles.const_pair_begin(); 
+  Range::const_pair_iterator p = handles.begin();
+  for (Range::const_pair_iterator p = handles.const_pair_begin(); 
        p != handles.const_pair_end(); ++p) {
        
-    MBEntityHandle start = p->first;
+    EntityHandle start = p->first;
     while (start <= p->second) {
       
       EntitySequence* seq = 0;
@@ -1025,8 +1031,8 @@
         continue;
       }
       
-      const MBEntityHandle finish = std::min( p->second, seq->end_handle() );
-      const MBEntityID count = finish - start + 1;
+      const EntityHandle finish = std::min( p->second, seq->end_handle() );
+      const EntityID count = finish - start + 1;
       
       void* tag_array = seq->data()->get_tag_data( tag_id );
       if (!tag_array)
@@ -1045,13 +1051,13 @@
 }
       
 
-MBErrorCode SequenceManager::set_tag_data( MBTagId tag_id,
-                                           const MBRange& handles,
+ErrorCode SequenceManager::set_tag_data( TagId tag_id,
+                                           const Range& handles,
                                            void const* const* values,
                                            const int* lengths,
                                            const void* default_value )
 {
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
   if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
     return MB_TAG_NOT_FOUND;
 
@@ -1070,11 +1076,11 @@
   }
 
 
-  MBRange::const_pair_iterator p = handles.begin();
-  for (MBRange::const_pair_iterator p = handles.const_pair_begin(); 
+  Range::const_pair_iterator p = handles.begin();
+  for (Range::const_pair_iterator p = handles.const_pair_begin(); 
        p != handles.const_pair_end(); ++p) {
        
-    MBEntityHandle start = p->first;
+    EntityHandle start = p->first;
     while (start <= p->second) {
       
       EntitySequence* seq = 0;
@@ -1088,8 +1094,8 @@
         continue;
       }
       
-      const MBEntityHandle finish = std::min( p->second, seq->end_handle() ) + 1;
-      const MBEntityID count = finish - start;
+      const EntityHandle finish = std::min( p->second, seq->end_handle() ) + 1;
+      const EntityID count = finish - start;
       
       void* tag_array = seq->data()->get_tag_data( tag_id );
       if (!tag_array)
@@ -1125,8 +1131,8 @@
 }
       
 
-MBErrorCode SequenceManager::get_tag_data( MBTagId tag_id,
-                                           const MBEntityHandle* handles,
+ErrorCode SequenceManager::get_tag_data( TagId tag_id,
+                                           const EntityHandle* handles,
                                            int num_handles,
                                            void* values,
                                            const void* default_value ) const
@@ -1142,11 +1148,11 @@
 
   const int len = tagSizes[tag_id];
   unsigned char* ptr = reinterpret_cast<unsigned char*>(values);
-  const MBEntityHandle *const end = handles + num_handles;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ptr += len) {
+  const EntityHandle *const end = handles + num_handles;
+  for (const EntityHandle* i = handles; i != end; ++i, ptr += len) {
     
     const EntitySequence* seq = 0;
-    MBErrorCode rval = find( *i, seq );
+    ErrorCode rval = find( *i, seq );
     // keep MOAB 3.0 behavior : return default value for invalid handles
     if (MB_SUCCESS != rval)
       return rval;
@@ -1165,8 +1171,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_tag_data( MBTagId tag_id,
-                                           const MBEntityHandle* handles,
+ErrorCode SequenceManager::get_tag_data( TagId tag_id,
+                                           const EntityHandle* handles,
                                            int num_handles,
                                            const void** values,
                                            int* lengths,
@@ -1176,15 +1182,15 @@
   if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
     return MB_TAG_NOT_FOUND;
   
-  MBErrorCode result = MB_SUCCESS;
-  const MBEntityHandle *const end = handles + num_handles;
+  ErrorCode result = MB_SUCCESS;
+  const EntityHandle *const end = handles + num_handles;
   const int len = tagSizes[tag_id];
   
   if (len == MB_VARIABLE_LENGTH) {
-    for (const MBEntityHandle* i = handles; i != end; ++i) {
+    for (const EntityHandle* i = handles; i != end; ++i) {
       
       const EntitySequence* seq = 0;
-      MBErrorCode rval = find( *i, seq );
+      ErrorCode rval = find( *i, seq );
       if (MB_SUCCESS != rval) {
         result = rval;
         *values = 0;
@@ -1213,11 +1219,11 @@
   }
   else {
     if (lengths) 
-      MBSysUtil::setmem( lengths, &len, sizeof(int), num_handles );
+      SysUtil::setmem( lengths, &len, sizeof(int), num_handles );
   
-    for (const MBEntityHandle* i = handles; i != end; ++i) {
+    for (const EntityHandle* i = handles; i != end; ++i) {
       const EntitySequence* seq = 0;
-      MBErrorCode rval = find( *i, seq );
+      ErrorCode rval = find( *i, seq );
       if (MB_SUCCESS != rval) {
         result = rval;
         *values = 0;
@@ -1238,12 +1244,12 @@
   return result;
 }
 
-MBErrorCode SequenceManager::get_tag_data( MBTagId tag_id,
-                                           const MBRange& handles,
+ErrorCode SequenceManager::get_tag_data( TagId tag_id,
+                                           const Range& handles,
                                            void* values,
                                            const void* default_value ) const
 {
-  MBErrorCode rval;
+  ErrorCode rval;
     // NOTE: Comparison of size to 1 should also catch 
     //       case where tag is variable-length.  
   if (tag_id >= tagSizes.size() || tagSizes[tag_id] < 1) {
@@ -1255,10 +1261,10 @@
     
   char* data = reinterpret_cast<char*>(values);
 
-  for (MBRange::const_pair_iterator p = handles.const_pair_begin(); 
+  for (Range::const_pair_iterator p = handles.const_pair_begin(); 
        p != handles.const_pair_end(); ++p) {
        
-    MBEntityHandle start = p->first;
+    EntityHandle start = p->first;
     while (start <= p->second) {
       
       const EntitySequence* seq = 0;
@@ -1266,8 +1272,8 @@
       if (MB_SUCCESS != rval)
         return rval;
      
-      const MBEntityHandle finish = std::min( p->second, seq->end_handle() );
-      const MBEntityID count = finish - start + 1;
+      const EntityHandle finish = std::min( p->second, seq->end_handle() );
+      const EntityID count = finish - start + 1;
       
       const void* tag_array = seq->data()->get_tag_data( tag_id );
       if (tag_array) {
@@ -1276,7 +1282,7 @@
         memcpy( data, tag_data, tagSizes[tag_id] * count );
       }
       else if (default_value) {
-        MBSysUtil::setmem( data, default_value, tagSizes[tag_id], count );
+        SysUtil::setmem( data, default_value, tagSizes[tag_id], count );
       }
       else {
         return MB_TAG_NOT_FOUND;
@@ -1290,14 +1296,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_tag_data( MBTagId tag_id,
-                                           const MBRange& handles,
+ErrorCode SequenceManager::get_tag_data( TagId tag_id,
+                                           const Range& handles,
                                            const void** values,
                                            int* lengths,
                                            const void* default_value,
                                            int default_value_length ) const
 {
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
   if (!default_value)
     default_value_length = 0;
 
@@ -1310,13 +1316,13 @@
   }
   else if (lengths) {
     int len = tagSizes[tag_id];
-    MBSysUtil::setmem( lengths, &len, sizeof(int), handles.size() );
+    SysUtil::setmem( lengths, &len, sizeof(int), handles.size() );
   }
   
-  for (MBRange::const_pair_iterator p = handles.const_pair_begin(); 
+  for (Range::const_pair_iterator p = handles.const_pair_begin(); 
        p != handles.const_pair_end(); ++p) {
 
-    MBEntityHandle start = p->first;
+    EntityHandle start = p->first;
     while (start <= p->second) {
 
       const EntitySequence* seq = 0;
@@ -1333,13 +1339,13 @@
         continue;
       }
 
-      const MBEntityHandle finish = std::min( p->second, seq->end_handle() ) + 1;
-      const MBEntityID count = finish - start;
+      const EntityHandle finish = std::min( p->second, seq->end_handle() ) + 1;
+      const EntityID count = finish - start;
       if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
         const VarLenTag* tag_data = vtag_array( seq, start, tag_id );
         if (!tag_data) {
-          MBSysUtil::setmem( values, &default_value, sizeof(void*), count );
-          MBSysUtil::setmem( lengths, &default_value_length, sizeof(int), count );
+          SysUtil::setmem( values, &default_value, sizeof(void*), count );
+          SysUtil::setmem( lengths, &default_value_length, sizeof(int), count );
           values += count;
           lengths += count;
           if (!default_value)
@@ -1370,7 +1376,7 @@
       else {
         const unsigned char* tag_data = tag_array( seq, start, tag_id, tagSizes[tag_id] );
         if (!tag_data) {
-          MBSysUtil::setmem( values, &default_value, sizeof(void*), count );
+          SysUtil::setmem( values, &default_value, sizeof(void*), count );
           values += count;
           if (!default_value)
             result = MB_TAG_NOT_FOUND;
@@ -1391,15 +1397,15 @@
   return result;
 }
 
-MBErrorCode SequenceManager::get_entity_tags(  MBEntityHandle entity,
-                                 std::vector<MBTag>& tags_out ) const
+ErrorCode SequenceManager::get_entity_tags(  EntityHandle entity,
+                                 std::vector<Tag>& tags_out ) const
 {
   const EntitySequence* seq = 0;
-  MBErrorCode rval = find( entity, seq );
+  ErrorCode rval = find( entity, seq );
   if (MB_SUCCESS != rval)
     return rval;
   
-  for (MBTagId i = 0; i < tagSizes.size(); ++i) {
+  for (TagId i = 0; i < tagSizes.size(); ++i) {
     if (tagSizes[i] == MB_VARIABLE_LENGTH) {
       const void* data_array = seq->data()->get_tag_data(i);
       if (data_array) {
@@ -1418,14 +1424,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_tagged_entities( MBTagId tag_id, 
-                                                  MBEntityType type,
-                                                  MBRange& entities_out ) const
+ErrorCode SequenceManager::get_tagged_entities( TagId tag_id, 
+                                                  EntityType type,
+                                                  Range& entities_out ) const
 {
   if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
     return MB_TAG_NOT_FOUND;
 
-  MBRange::iterator insert = entities_out.begin();
+  Range::iterator insert = entities_out.begin();
   const TypeSequenceManager& map = entity_map( type );
   if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
     const VarLenTag *data, *iter, *end;
@@ -1435,7 +1441,7 @@
         continue;
       end = data + (*i)->end_handle() - (*i)->data()->start_handle() + 1;
       iter = data + (*i)->start_handle() - (*i)->data()->start_handle();
-      MBEntityHandle handle = (*i)->start_handle();
+      EntityHandle handle = (*i)->start_handle();
       for (; iter != end; ++iter, ++handle)
         if (iter->size()) 
           insert = entities_out.insert( insert, handle, handle );
@@ -1450,8 +1456,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::count_tagged_entities( MBTagId tag_id, 
-                                                    MBEntityType type,
+ErrorCode SequenceManager::count_tagged_entities( TagId tag_id, 
+                                                    EntityType type,
                                                     int& count ) const
 {
   if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
@@ -1482,17 +1488,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_entities_with_tag_value( MBTagId id,
+ErrorCode SequenceManager::get_entities_with_tag_value( TagId id,
                                                           const TagInfo& tag_info,
-                                                          MBEntityType type,
-                                                          MBRange& entities_out,
+                                                          EntityType type,
+                                                          Range& entities_out,
                                                           const void* value,
                                                           int size ) const
 {
   if (id >= tagSizes.size() || !tagSizes[id])
     return MB_TAG_NOT_FOUND;
 
-  MBRange::iterator insert = entities_out.begin();
+  Range::iterator insert = entities_out.begin();
   const TypeSequenceManager& map = entity_map( type );
   for (TypeSequenceManager::const_iterator i = map.begin(); i != map.end(); ++i) {
     if (const void* data = (*i)->data()->get_tag_data(id)) {
@@ -1506,25 +1512,25 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_entities_with_tag_value( const MBRange& range,
-                                                          MBTagId id,
+ErrorCode SequenceManager::get_entities_with_tag_value( const Range& range,
+                                                          TagId id,
                                                           const TagInfo& tag_info,
-                                                          MBEntityType type,
-                                                          MBRange& entities_out,
+                                                          EntityType type,
+                                                          Range& entities_out,
                                                           const void* value,
                                                           int size ) const
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (id >= tagSizes.size() || !tagSizes[id])
     return MB_TAG_NOT_FOUND;
     
-  MBRange::iterator insert = entities_out.begin();
-  MBRange::const_pair_iterator p = range.lower_bound(type);         
-  for (MBRange::const_pair_iterator p = range.const_pair_begin(); 
+  Range::iterator insert = entities_out.begin();
+  Range::const_pair_iterator p = range.lower_bound(type);         
+  for (Range::const_pair_iterator p = range.const_pair_begin(); 
        p != range.const_pair_end() && TYPE_FROM_HANDLE(p->first) == type; 
        ++p) {
     
-    MBEntityHandle start = p->first;
+    EntityHandle start = p->first;
     while (start <= p->second) {
       
       const EntitySequence* seq = 0;
@@ -1532,7 +1538,7 @@
       if (MB_SUCCESS != rval) 
         return rval;
      
-      const MBEntityHandle finish = std::min( p->second, seq->end_handle() );
+      const EntityHandle finish = std::min( p->second, seq->end_handle() );
       const void* tag_array = seq->data()->get_tag_data( id );
       if (tag_array) {
         ByteArrayIterator start( seq->data()->start_handle(), tag_array, tag_info );
@@ -1547,7 +1553,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SequenceManager::get_tag_memory_use( MBTagId id, 
+ErrorCode SequenceManager::get_tag_memory_use( TagId id, 
                                        unsigned long& total, 
                                        unsigned long& per_entity ) const
 {
@@ -1556,7 +1562,7 @@
     
   per_entity = tagSizes[id];
   total = 0;
-  for (MBEntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
+  for (EntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
     const TypeSequenceManager& map = entity_map(t);
     const SequenceData* prev_data = 0;
     for (TypeSequenceManager::const_iterator i = map.begin(); i != map.end(); ++i) {
@@ -1574,7 +1580,6 @@
 // These are meant to be called from the debugger (not declared in any header)
 // so leave them out of release builds (-DNDEBUG).
 #ifndef NDEBUG
-#include <iostream>
 
 std::ostream& operator<<( std::ostream& s, const TypeSequenceManager& seq_man )
 {
@@ -1602,7 +1607,7 @@
 
 std::ostream& operator<<( std::ostream& s, const SequenceManager& seq_man )
 {
-  for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t) 
+  for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) 
     if (!seq_man.entity_map(t).empty()) 
       s << std::endl 
         << "****************** " << MBCN::EntityTypeName( t ) << " ******************"
@@ -1620,4 +1625,6 @@
   std::cout << seqman << std::endl;
 }
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/SequenceManager.hpp
===================================================================
--- MOAB/trunk/src/SequenceManager.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SequenceManager.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,6 +5,8 @@
 #include "TagInfo.hpp"
 #include <vector>
 
+namespace moab {
+
 class HomCoord;
 class TagServer;
 
@@ -20,7 +22,7 @@
       /** Find entity sequence containing specified handle.
        *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
        */
-    MBErrorCode find( MBEntityHandle handle, EntitySequence*& sequence_out )
+    ErrorCode find( EntityHandle handle, EntitySequence*& sequence_out )
       { 
         return typeData[TYPE_FROM_HANDLE(handle)].find( handle, sequence_out );
       }
@@ -28,25 +30,25 @@
       /** Find entity sequence containing specified handle.
        *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
        */
-    MBErrorCode find( MBEntityHandle handle, const EntitySequence*& sequence_out ) const
+    ErrorCode find( EntityHandle handle, const EntitySequence*& sequence_out ) const
       { 
         return typeData[TYPE_FROM_HANDLE(handle)].find( handle, sequence_out );
       }
     
-      /** Get all entities of a given MBEntityType */
-   void get_entities( MBEntityType type, MBRange& entities_out ) const
+      /** Get all entities of a given EntityType */
+   void get_entities( EntityType type, Range& entities_out ) const
       { typeData[type].get_entities( entities_out ); }
     
-      /** Get all entities of a given MBEntityType */
-   void get_entities( MBEntityType type, std::vector<MBEntityHandle>& entities_out ) const
+      /** Get all entities of a given EntityType */
+   void get_entities( EntityType type, std::vector<EntityHandle>& entities_out ) const
       { typeData[type].get_entities( entities_out ); }
     
-      /** Count entities of a given MBEntityType */
-    MBEntityID get_number_entities( MBEntityType type ) const
+      /** Count entities of a given EntityType */
+    EntityID get_number_entities( EntityType type ) const
       { return typeData[type].get_number_entities(); }
       
       /** Get most recently accessed sequence for a given type */
-    const EntitySequence* get_last_accessed_sequence( MBEntityType type ) const
+    const EntitySequence* get_last_accessed_sequence( EntityType type ) const
       { return typeData[type].get_last_accessed(); }
     
       /**\brief Replace subset of existing sequence with new 
@@ -57,42 +59,42 @@
        * sequence.  Existing sequence will be removed, modified, or split
        * into two prevent it from overlapping the new sequence.
        */
-    MBErrorCode replace_subsequence( EntitySequence* new_seq, TagServer* ts );
+    ErrorCode replace_subsequence( EntitySequence* new_seq, TagServer* ts );
     
       /** Check if passed entity handles are valid */
-    MBErrorCode check_valid_entities( const MBRange& entities ) const;
+    ErrorCode check_valid_entities( const Range& entities ) const;
     
       /** Check if passed entity handles are valid */
-    MBErrorCode check_valid_entities( const MBEntityHandle entities[],
+    ErrorCode check_valid_entities( const EntityHandle entities[],
                                       size_t num_entities ) const;
     
       /** Delete an entity.  Deletes sequence if only contained entity. */
-    MBErrorCode delete_entity( MBEntityHandle entity );
+    ErrorCode delete_entity( EntityHandle entity );
     
       /** Delete entities */
-    MBErrorCode delete_entities( const MBRange& entities );
+    ErrorCode delete_entities( const Range& entities );
     
       /** Allocate a vertex (possibly in an existing sequence) and 
        *  assign it the passed coordinate values.
        */
-    MBErrorCode create_vertex( const double coords[3],
-                               MBEntityHandle& handle_out );
+    ErrorCode create_vertex( const double coords[3],
+                               EntityHandle& handle_out );
     
       /** Allocate a element (possibly in an existing sequence) and 
        *  assign it the passed connectivity.
        */
-    MBErrorCode create_element( MBEntityType type,
-                                const MBEntityHandle* conn_array,
+    ErrorCode create_element( EntityType type,
+                                const EntityHandle* conn_array,
                                 unsigned num_vertices,
-                                MBEntityHandle& handle_out );
+                                EntityHandle& handle_out );
     
       /** Allocate an entity set (possibly in an existing sequence) */
-    MBErrorCode create_mesh_set( unsigned flags,
-                                 MBEntityHandle& handle_out );
+    ErrorCode create_mesh_set( unsigned flags,
+                                 EntityHandle& handle_out );
       /** Allocate an entity set with the specified handle. 
        *\return MB_ALREADY_ALLOCATED if handle is in use, MB_SUCCESS otherwise.
        */
-    MBErrorCode allocate_mesh_set( MBEntityHandle at_this_handle,
+    ErrorCode allocate_mesh_set( EntityHandle at_this_handle,
                                    unsigned flags );
     
       /**\brief Allocate a block of consecutive entity handles
@@ -112,11 +114,11 @@
        *                    NOTE: first_handle_out may not be first handle in
        *                    sequence.
        */
-    MBErrorCode create_entity_sequence( MBEntityType type,
-                                        MBEntityID num_entities,
+    ErrorCode create_entity_sequence( EntityType type,
+                                        EntityID num_entities,
                                         int nodes_per_entity,
-                                        MBEntityID start_id_hint,
-                                        MBEntityHandle& first_handle_out,
+                                        EntityID start_id_hint,
+                                        EntityHandle& first_handle_out,
                                         EntitySequence*& sequence_out );
     
        /**\brief Allocate a block of consecutive mesh sets
@@ -136,59 +138,59 @@
        *                    NOTE: first_handle_out may not be first handle in
        *                    sequence.
        */
-    MBErrorCode create_meshset_sequence( MBEntityID num_sets,
-                                         MBEntityID start_id_hint,
+    ErrorCode create_meshset_sequence( EntityID num_sets,
+                                         EntityID start_id_hint,
                                          const unsigned* flags,
-                                         MBEntityHandle& first_handle_out,
+                                         EntityHandle& first_handle_out,
                                          EntitySequence*& sequence_out );
     
       /**\brief Allocate a block of consecutive mesh sets
        *
        * Alternate form that creates all mesh sets with same flags.
        */
-    MBErrorCode create_meshset_sequence( MBEntityID num_sets,
-                                         MBEntityID start_id_hint,
+    ErrorCode create_meshset_sequence( EntityID num_sets,
+                                         EntityID start_id_hint,
                                          unsigned flags,
-                                         MBEntityHandle& first_handle_out,
+                                         EntityHandle& first_handle_out,
                                          EntitySequence*& sequence_out );
     
       /** Create structured mesh */
-    MBErrorCode create_scd_sequence( int imin, int jmin, int kmin,
+    ErrorCode create_scd_sequence( int imin, int jmin, int kmin,
                                      int imax, int jmax, int kmax,
-                                     MBEntityType type,
-                                     MBEntityID start_id_hint,
-                                     MBEntityHandle& first_handle_out,
+                                     EntityType type,
+                                     EntityID start_id_hint,
+                                     EntityHandle& first_handle_out,
                                      EntitySequence*& sequence_out );
     
       /** Create structured mesh */
-    MBErrorCode create_scd_sequence( const HomCoord& coord_min,
+    ErrorCode create_scd_sequence( const HomCoord& coord_min,
                                      const HomCoord& coord_max,
-                                     MBEntityType type,
-                                     MBEntityID start_id_hint,
-                                     MBEntityHandle& first_handle_out,
+                                     EntityType type,
+                                     EntityID start_id_hint,
+                                     EntityHandle& first_handle_out,
                                      EntitySequence*& sequence_out );
 
       /** Create swept mesh */
-    MBErrorCode create_sweep_sequence( int imin, int jmin, int kmin,
+    ErrorCode create_sweep_sequence( int imin, int jmin, int kmin,
 				       int imax, int jmax, int kmax,
 				       int* Cq,
-				       MBEntityType type,
-				       MBEntityID start_id_hint,
-				       MBEntityHandle& first_handle_out,
+				       EntityType type,
+				       EntityID start_id_hint,
+				       EntityHandle& first_handle_out,
 				       EntitySequence*& sequence_out );
     
       /** Create swept mesh */
-    MBErrorCode create_sweep_sequence( const HomCoord& coord_min,
+    ErrorCode create_sweep_sequence( const HomCoord& coord_min,
 				       const HomCoord& coord_max,
 				       int* Cq,
-				       MBEntityType type,
-				       MBEntityID start_id_hint,
-				       MBEntityHandle& first_handle_out,
+				       EntityType type,
+				       EntityID start_id_hint,
+				       EntityHandle& first_handle_out,
 				       EntitySequence*& sequence_out );
 
     /** Add a structured vertex sequence to this structured element sequence;
      * see comments in ScdElementData */
-  MBErrorCode add_vsequence(EntitySequence *vert_seq,
+  ErrorCode add_vsequence(EntitySequence *vert_seq,
                             EntitySequence *elem_seq,
                             const HomCoord &p1, const HomCoord &q1,
                             const HomCoord &p2, const HomCoord &q2,
@@ -197,22 +199,22 @@
                             const HomCoord *bb_min = NULL,
                             const HomCoord *bb_max = NULL);
 
-      /** Get data for a specific MBEntityType */
-    TypeSequenceManager& entity_map( MBEntityType type )
+      /** Get data for a specific EntityType */
+    TypeSequenceManager& entity_map( EntityType type )
       { return typeData[type]; }
     
-      /** Get data for a specific MBEntityType */
-    const TypeSequenceManager& entity_map( MBEntityType type ) const
+      /** Get data for a specific EntityType */
+    const TypeSequenceManager& entity_map( EntityType type ) const
       { return typeData[type]; }
     
     void get_memory_use( unsigned long& total_entity_storage,
                          unsigned long& total_storage ) const;
                          
-    void get_memory_use( MBEntityType type,
+    void get_memory_use( EntityType type,
                          unsigned long& total_entity_storage,
                          unsigned long& total_storage ) const;
     
-    void get_memory_use( const MBRange& entities,
+    void get_memory_use( const Range& entities,
                          unsigned long& total_entity_storage,
                          unsigned long& total_amortized_storage ) const;
     
@@ -227,17 +229,17 @@
        *\param tag_id   The ID to allocate/reserve
        *\param tag_size The size of the tag value for each entity
        */
-    MBErrorCode reserve_tag_id( int tag_size, MBTagId tag_id );
+    ErrorCode reserve_tag_id( int tag_size, TagId tag_id );
     
       /** Release a reserved tag ID any any associated storage */
-    MBErrorCode release_tag( MBTagId tag_id );
+    ErrorCode release_tag( TagId tag_id );
     
       /** If tag data is allocated for the specified entity,
        *  change it to the passed default value.  Otherwise 
        *  do nothing. 
        */
-    MBErrorCode remove_tag_data( MBTagId tag_id, 
-                                 MBEntityHandle handle,
+    ErrorCode remove_tag_data( TagId tag_id, 
+                                 EntityHandle handle,
                                  const void* default_tag_value,
                                  int default_value_size = 0 );
                                  
@@ -247,8 +249,8 @@
        *
        *\NOTE Will fail for variable-length tag data.
        */
-    MBErrorCode set_tag_data( MBTagId tag_id,
-                              const MBEntityHandle* handles,
+    ErrorCode set_tag_data( TagId tag_id,
+                              const EntityHandle* handles,
                               int num_handles,
                               const void* values,
                               const void* default_value );
@@ -262,24 +264,24 @@
        *\param default_value Used to initialize any additional tag storage.  Ignored
        *                   for variable-length tags.
        */
-    MBErrorCode set_tag_data( MBTagId tag_id,
-                              const MBEntityHandle* handles,
+    ErrorCode set_tag_data( TagId tag_id,
+                              const EntityHandle* handles,
                               int num_handles,
                               void const* const* values,
                               const int* lengths,
                               const void* default_value );
                               
-      /** Set fixed-length tag value for an MBRange of entities
+      /** Set fixed-length tag value for an Range of entities
        *\NOTE Default value must be given because it is often
        *      necessary to allocate storage for other entities
        *\NOTE Will fail for variable-length tag data
        */
-    MBErrorCode set_tag_data( MBTagId tag_id,
-                              const MBRange& handles,
+    ErrorCode set_tag_data( TagId tag_id,
+                              const Range& handles,
                               const void* values,
                               const void* default_value );
                               
-      /** Set tag data for an MBRange of entities.
+      /** Set tag data for an Range of entities.
        *
        *\param tag_id  The tag
        *\param handles The entities
@@ -291,8 +293,8 @@
        *\param default_value The default value for the tag.  Ignored for
        *               variable-length tags.
        */
-     MBErrorCode set_tag_data( MBTagId tag_id,
-                               const MBRange& handles,
+     ErrorCode set_tag_data( TagId tag_id,
+                               const Range& handles,
                                void const* const* values,
                                const int* lengths,
                                const void* default_value );
@@ -301,8 +303,8 @@
        *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
        *      for variable-length tag.
        */
-    MBErrorCode get_tag_data( MBTagId tag_id,
-                              const MBEntityHandle* handles,
+    ErrorCode get_tag_data( TagId tag_id,
+                              const EntityHandle* handles,
                               int num_handles,
                               void* values, 
                               const void* default_value ) const;
@@ -317,24 +319,24 @@
        *\param default_value_length  Length of default tag value.  Ingored for
        *                   fixed-length tags.
        */
-    MBErrorCode get_tag_data( MBTagId tag_id,
-                              const MBEntityHandle* handles,
+    ErrorCode get_tag_data( TagId tag_id,
+                              const EntityHandle* handles,
                               int num_handles,
                               const void** tag_ptrs,
                               int* lengths,
                               const void* default_value,
                               int default_value_length ) const;
                               
-      /** Get fixed-length tag value for an MBRange of entities
+      /** Get fixed-length tag value for an Range of entities
        *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
        *      for variable-length tag.
        */
-    MBErrorCode get_tag_data( MBTagId tag_id,
-                              const MBRange& handles,
+    ErrorCode get_tag_data( TagId tag_id,
+                              const Range& handles,
                               void* values,
                               const void* default_value ) const;
                               
-      /** Get pointers to tag data for an MBRange of entities.
+      /** Get pointers to tag data for an Range of entities.
        *
        *\param tag_id   The tag.
        *\param handles  The entities.
@@ -348,8 +350,8 @@
        *\param default_value The default value for the tag.
        *\param default_value_length The length of the default tag value.
        */
-    MBErrorCode get_tag_data( MBTagId tag_id,
-                              const MBRange& handles,
+    ErrorCode get_tag_data( TagId tag_id,
+                              const Range& handles,
                               const void** values,
                               int* lengths,
                               const void* default_value,
@@ -360,32 +362,32 @@
        *\NOTE For variable-length data, will only return tag if
        *      data length is greater than zero.
        */
-    MBErrorCode get_entity_tags( MBEntityHandle entity,
-                                 std::vector<MBTag>& tags_out ) const;
+    ErrorCode get_entity_tags( EntityHandle entity,
+                                 std::vector<Tag>& tags_out ) const;
 
       /** Get all entities for which storage for a specific tag has
        *  been allocated.
        *\NOTE For variable-length data, will only return entities for
        *      which data length is greater than zero.
        */
-    MBErrorCode get_tagged_entities( MBTagId tag_id, 
-                                     MBEntityType type,
-                                     MBRange& entities_out ) const;
+    ErrorCode get_tagged_entities( TagId tag_id, 
+                                     EntityType type,
+                                     Range& entities_out ) const;
 
       /** Count all entities for which storage for a specific tag has
        *  been allocated.
        *\NOTE For variable-length data, will only count entities for
        *      which data length is greater than zero.
        */
-    MBErrorCode count_tagged_entities( MBTagId tag, 
-                                       MBEntityType type, 
+    ErrorCode count_tagged_entities( TagId tag, 
+                                       EntityType type, 
                                        int& result ) const;
 
       /** Get entities by type and tag value (intersection) */
-    MBErrorCode get_entities_with_tag_value( MBTagId id,
+    ErrorCode get_entities_with_tag_value( TagId id,
                                              const TagInfo& tag_info,
-                                             MBEntityType type,
-                                             MBRange& entities_out,
+                                             EntityType type,
+                                             Range& entities_out,
                                              const void* value,
                                              int value_size ) const;
                                              
@@ -396,25 +398,25 @@
        *\param entities_out Result (subset of input 'range')
        *\param value The tag value
        */
-    MBErrorCode get_entities_with_tag_value( const MBRange& range,
-                                             MBTagId id,
+    ErrorCode get_entities_with_tag_value( const Range& range,
+                                             TagId id,
                                              const TagInfo& tag_info,
-                                             MBEntityType type,
-                                             MBRange& entities_out,
+                                             EntityType type,
+                                             Range& entities_out,
                                              const void* value,
                                              int value_size ) const;
     
-    MBErrorCode get_tag_memory_use( MBTagId id, 
+    ErrorCode get_tag_memory_use( TagId id, 
                                     unsigned long& total, 
                                     unsigned long& per_entity ) const;
     
       /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */
-    static MBEntityID default_poly_sequence_size( int entity_connectivity_length );
+    static EntityID default_poly_sequence_size( int entity_connectivity_length );
     
       /**\brief Size to allocate for new SquenceData */
-    MBEntityID new_sequence_size( MBEntityHandle start_handle, 
-                                  MBEntityID reqested_size,
-                                  MBEntityID default_size ) const;
+    EntityID new_sequence_size( EntityHandle start_handle, 
+                                  EntityID reqested_size,
+                                  EntityID default_size ) const;
     
   private:
   
@@ -423,15 +425,15 @@
      * Given a block of available handles, determine the non-strict
      * subset at which to create a new EntitySequence.
      */
-    void trim_sequence_block( MBEntityHandle start_handle,
-                              MBEntityHandle& end_handle_in_out,
+    void trim_sequence_block( EntityHandle start_handle,
+                              EntityHandle& end_handle_in_out,
                               unsigned maximum_sequence_size );
   
   
       /**\brief Get range of handles in which to create an entity sequence
        *
        * Get range of handles in whcih to place a new entity sequence.
-       *\param type              The MBEntityType for the contents of the sequence
+       *\param type              The EntityType for the contents of the sequence
        *\param entity_count      The number of entities in the range
        *\param values_per_entity Vertices per element, zero for other types
        *\param start_id_hint     Preferred id of first handle
@@ -441,16 +443,18 @@
        *                         the handle range.
        *\return zero if no available handle range, start handle otherwise.
        */
-    MBEntityHandle sequence_start_handle( MBEntityType type,
-                                          MBEntityID entity_count,
+    EntityHandle sequence_start_handle( EntityType type,
+                                          EntityID entity_count,
                                           int values_per_entity,
-                                          MBEntityID start_id_hint,
+                                          EntityID start_id_hint,
                                           SequenceData*& data_out,
-                                          MBEntityID &data_size );
+                                          EntityID &data_size );
   
     TypeSequenceManager typeData[MBMAXTYPE];
     
     std::vector<int> tagSizes;
 };
 
+} // namespace moab
+
 #endif

Copied: MOAB/trunk/src/Skinner.cpp (from rev 3583, MOAB/trunk/src/MBSkinner.cpp)
===================================================================
--- MOAB/trunk/src/Skinner.cpp	                        (rev 0)
+++ MOAB/trunk/src/Skinner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1921 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifdef __MFC_VER
+#pragma warning(disable:4786)
+#endif
+
+#include "moab/Skinner.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include <vector>
+#include <set>
+#include <algorithm>
+#include <math.h>
+#include <assert.h>
+#include <iostream>
+#include "moab/Util.hpp"
+#include "Internals.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "AEntityFactory.hpp"
+
+#ifdef M_PI
+#  define SKINNER_PI M_PI
+#else
+#  define SKINNER_PI 3.1415926535897932384626
+#endif
+
+namespace moab {
+
+Skinner::~Skinner()
+{
+  // delete the adjacency tag
+}
+
+
+void Skinner::initialize()
+{
+  // go through and mark all the target dimension entities
+  // that already exist as not deleteable
+  // also get the connectivity tags for each type
+  // also populate adjacency information
+  EntityType type;
+  DimensionPair target_ent_types = MBCN::TypeDimensionMap[mTargetDim];
+
+  void* null_ptr = NULL;
+  ErrorCode result;
+
+  result = thisMB->tag_create("skinner adj", sizeof(void*), MB_TAG_DENSE, mAdjTag, &null_ptr);
+  assert(MB_SUCCESS == result);
+
+  if(mDeletableMBTag == 0) {
+    result = thisMB->tag_create("skinner deletable", 1, MB_TAG_BIT, mDeletableMBTag, NULL);
+    assert(MB_SUCCESS == result);
+  }
+  
+  Range entities;
+
+    // go through each type at this dimension 
+  for(type = target_ent_types.first; type <= target_ent_types.second; ++type)
+  {
+      // get the entities of this type in the MB
+    thisMB->get_entities_by_type(0, type, entities);
+
+      // go through each entity of this type in the MB
+      // and set its deletable tag to NO
+    Range::iterator iter, end_iter;
+    end_iter = entities.end();
+    for(iter = entities.begin(); iter != end_iter; ++iter)
+    {
+      unsigned char bit = 0x1;
+      result = thisMB->tag_set_data(mDeletableMBTag, &(*iter), 1, &bit);
+      assert(MB_SUCCESS == result);
+        // add adjacency information too
+      if (TYPE_FROM_HANDLE(*iter) != MBVERTEX)
+        add_adjacency(*iter);
+    }
+  }
+}
+
+void Skinner::deinitialize()
+{
+  ErrorCode result = MB_SUCCESS;
+  
+  if (0 != mDeletableMBTag) {
+    result = thisMB->tag_delete( mDeletableMBTag);
+    mDeletableMBTag = 0;
+    assert(MB_SUCCESS == result);
+  }
+
+  // remove the adjaceny tag
+  std::vector< std::vector<EntityHandle>* > adj_arr;
+  std::vector< std::vector<EntityHandle>* >::iterator i;
+  if (0 != mAdjTag) {
+    for (EntityType t = MBVERTEX; t != MBMAXTYPE; ++t) {
+      Range entities;
+      result = thisMB->get_entities_by_type_and_tag( 0, t, &mAdjTag, 0, 1, entities );
+      assert(MB_SUCCESS == result);
+      adj_arr.resize( entities.size() );
+      result = thisMB->tag_get_data( mAdjTag, entities, &adj_arr[0] );
+      assert(MB_SUCCESS == result);
+      for (i = adj_arr.begin(); i != adj_arr.end(); ++i)
+        delete *i;
+    }
+  
+    result = thisMB->tag_delete(mAdjTag);
+    mAdjTag = 0;
+    assert(MB_SUCCESS == result);
+  }
+}
+
+
+void Skinner::add_adjacency(EntityHandle entity)
+{
+  std::vector<EntityHandle> *adj = NULL;
+  const EntityHandle *nodes;
+  int num_nodes;
+  ErrorCode result = thisMB->get_connectivity(entity, nodes, num_nodes);
+  assert(MB_SUCCESS == result);
+  const EntityHandle *iter =
+    std::min_element(nodes, nodes+num_nodes);
+
+  if(iter == nodes+num_nodes)
+    return;
+
+  // add this entity to the node
+  if(thisMB->tag_get_data(mAdjTag, iter, 1, &adj) == MB_SUCCESS && adj != NULL)
+  {
+    adj->push_back(entity);    
+  }
+  // create a new vector and add it
+  else
+  {
+    adj = new std::vector<EntityHandle>;
+    adj->push_back(entity);
+    result = thisMB->tag_set_data(mAdjTag, iter, 1, &adj);
+    assert(MB_SUCCESS == result);
+  }
+}
+
+void Skinner::add_adjacency(EntityHandle entity, 
+                               const EntityHandle *nodes,
+                               const int num_nodes)
+{
+  std::vector<EntityHandle> *adj = NULL;
+  const EntityHandle *iter = 
+    std::min_element(nodes, nodes+num_nodes);
+
+  if(iter == nodes+num_nodes)
+    return;
+
+  // add this entity to the node
+  if(thisMB->tag_get_data(mAdjTag, iter, 1, &adj) == MB_SUCCESS && adj != NULL)
+  {
+    adj->push_back(entity);    
+  }
+  // create a new vector and add it
+  else
+  {
+    adj = new std::vector<EntityHandle>;
+    adj->push_back(entity);
+    thisMB->tag_set_data(mAdjTag, iter, 1, &adj);
+  }
+}
+
+ErrorCode Skinner::find_geometric_skin(Range &forward_target_entities) 
+{
+    // attempts to find whole model skin, using geom topo sets first then
+    // normal find_skin function
+  bool debug = true;
+
+    // look for geom topo sets
+  Tag geom_tag;
+  ErrorCode result = thisMB->tag_create(GEOM_DIMENSION_TAG_NAME, 4, 
+                                            MB_TAG_SPARSE, geom_tag, NULL);
+
+  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
+    return result;
+  
+    // get face sets (dimension = 2)
+  Range face_sets;
+  int two = 2;
+  const void *two_ptr = &two;
+  result = thisMB->get_entities_by_type_and_tag(0, MBENTITYSET, &geom_tag, &two_ptr, 1,
+                                                 face_sets);
+
+  Range::iterator it;
+  if (MB_SUCCESS != result)
+    return result;
+  else if (face_sets.empty())
+    return MB_ENTITY_NOT_FOUND;
+
+    // ok, we have face sets; use those to determine skin
+  Range skin_sets;
+  if (debug) std::cout << "Found " << face_sets.size() << " face sets total..." << std::endl;
+  
+  for (it = face_sets.begin(); it != face_sets.end(); it++) {
+    int num_parents;
+    result = thisMB->num_parent_meshsets(*it, &num_parents);
+    if (MB_SUCCESS != result)
+      return result;
+    else if (num_parents == 1)
+      skin_sets.insert(*it);
+  }
+
+  if (debug) std::cout << "Found " << skin_sets.size() << " 1-parent face sets..." << std::endl;
+
+  if (skin_sets.empty())
+    return MB_FAILURE;
+      
+    // ok, we have the shell; gather up the elements, putting them all in forward for now
+  for (it = skin_sets.begin(); it != skin_sets.end(); it++) {
+    result = thisMB->get_entities_by_handle(*it, forward_target_entities, true);
+    if (MB_SUCCESS != result) 
+      return result;
+  }
+        
+  return result;
+}
+
+ErrorCode Skinner::find_skin( const Range& source_entities,
+                                  bool get_vertices,
+                                  Range& output_handles,
+                                  Range* output_reverse_handles,
+                                  bool create_vert_elem_adjs,
+                                  bool create_skin_elements )
+{
+  if (source_entities.empty())
+    return MB_SUCCESS;
+
+  Core* this_core = dynamic_cast<Core*>(thisMB);
+  if (this_core && create_vert_elem_adjs && 
+      !this_core->a_entity_factory()->vert_elem_adjacencies())
+    this_core->a_entity_factory()->create_vert_elem_adjacencies();
+    
+  if (this_core && this_core->a_entity_factory()->vert_elem_adjacencies())
+    return find_skin_vertices( source_entities, 
+                               get_vertices ? &output_handles : 0,
+                               get_vertices ? 0 : &output_handles,
+                               output_reverse_handles,
+                               create_skin_elements );
+  
+  Range forward, reverse;
+  Range prev;
+  const int d = MBCN::Dimension(TYPE_FROM_HANDLE(source_entities.front()));
+  if (!source_entities.all_of_dimension(d))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+  ErrorCode rval = thisMB->get_entities_by_dimension( 0, d-1, prev );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  rval = find_skin_noadj( source_entities, forward, reverse );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (get_vertices && !output_reverse_handles) {
+    forward.merge( reverse );
+    reverse.clear();
+  }
+  
+  if (get_vertices) {
+    rval = thisMB->get_connectivity( forward, output_handles );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  if (!create_skin_elements) {
+    Range new_skin;
+    rval = thisMB->get_entities_by_dimension( 0, d-1, new_skin);
+    if (MB_SUCCESS != rval)
+      return rval;
+    new_skin = subtract( new_skin, prev );
+    forward = subtract( forward, new_skin );
+    reverse = subtract( reverse, new_skin );
+    rval = thisMB->delete_entities( new_skin );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  if (!get_vertices) {
+    if (output_handles.empty())
+      output_handles.swap( forward );
+    else
+      output_handles.merge( forward );
+    if (!output_reverse_handles)
+      output_handles.merge( reverse );
+    else if (output_reverse_handles->empty())
+      output_reverse_handles->swap( reverse );
+    else
+      output_reverse_handles->merge( reverse );
+  }
+  
+  return MB_SUCCESS;  
+}
+
+ErrorCode Skinner::find_skin_noadj(const Range &source_entities,
+                                 Range &forward_target_entities,
+                                 Range &reverse_target_entities/*,
+                                 bool create_vert_elem_adjs*/)
+{
+  if(source_entities.empty())
+    return MB_FAILURE;
+  
+  // get our working dimensions
+  EntityType type = thisMB->type_from_handle(*(source_entities.begin()));
+  const int source_dim = MBCN::Dimension(type);
+  mTargetDim = source_dim - 1;
+
+  // make sure we can handle the working dimensions
+  if(mTargetDim < 0 || source_dim > 3)
+    return MB_FAILURE;
+
+  //Core *this_core = dynamic_cast<Core*>(thisMB);
+  //bool use_adjs = false;
+  //if (!this_core->a_entity_factory()->vert_elem_adjacencies() &&
+  //  create_vert_elem_adjs)
+  //  this_core->a_entity_factory()->create_vert_elem_adjacencies();
+  //
+  //if (this_core->a_entity_factory()->vert_elem_adjacencies())
+  //  use_adjs = true;
+  //
+  //else 
+  initialize();
+
+  Range::const_iterator iter, end_iter;
+  end_iter = source_entities.end();
+  const EntityHandle *conn;
+  EntityHandle match;
+
+  direction direct;
+  ErrorCode result;
+    // assume we'll never have more than 32 vertices on a facet (checked
+    // with assert later)
+  EntityHandle sub_conn[32];
+  std::vector<EntityHandle> tmp_conn_vec;
+  int num_nodes, num_sub_nodes, num_sides;
+  const short *sub_indices;
+  EntityType sub_type;
+
+  // for each source entity
+  for(iter = source_entities.begin(); iter != end_iter; ++iter)
+  {
+    // get the connectivity of this entity
+    result = thisMB->get_connectivity(*iter, conn, num_nodes, false, &tmp_conn_vec);
+    if (MB_SUCCESS != result)
+      return result;
+    
+    type = thisMB->type_from_handle(*iter);
+    Range::iterator seek_iter;
+    Range dum_elems, dum_sub_elems;
+    
+    // get connectivity of each n-1 dimension entity
+    num_sides = MBCN::NumSubEntities( type, mTargetDim );
+    for(int i=0; i<num_sides; i++)
+    {
+      sub_indices = MBCN::SubEntityVertexIndices( type, mTargetDim, i, sub_type, num_sub_nodes );
+      assert(num_sub_nodes <= 32);
+      for(int j=0; j<num_sub_nodes; j++)
+        sub_conn[j] = conn[sub_indices[j]];
+      
+//      if (use_adjs) {
+//        dum_elems.clear();
+//        result = thisMB->get_adjacencies(sub_conn, num_sub_nodes, source_dim, false,
+//                                         dum_elems);
+//        if (MB_SUCCESS != result) return result;
+//        dum_elems = intersect( dum_elems, source_entities );
+//        if (dum_elems.empty()) {
+//          assert(false);  // should never happen
+//          return MB_FAILURE;
+//        }
+//        // if (dum_elems.size() > 2) { 
+//          // source entities do not form a valid source-dim patch (t-junction).
+//          // do we care?
+//        // }
+//        
+//        if (1 == dum_elems.size()) {
+//            // this sub_element is on the skin
+//
+//            // check for existing entity
+//          dum_sub_elems.clear();
+//          result = thisMB->get_adjacencies(sub_conn, num_sub_nodes, mTargetDim, false,
+//                                           dum_sub_elems);
+//          if (MB_SUCCESS != result) return result;
+//          if (dum_sub_elems.empty()) {
+//              // need to create one
+//            EntityHandle tmphndl=0;
+//            int indices[MB_MAX_SUB_ENTITY_VERTICES];
+//            EntityType new_type;
+//            int num_new_nodes;
+//            MBCN::SubEntityNodeIndices( type, num_nodes, mTargetDim, i, new_type, num_new_nodes, indices );
+//            for(int j=0; j<num_new_nodes; j++)
+//              sub_conn[j] = conn[indices[j]];
+//        
+//            result = thisMB->create_element(new_type, sub_conn,  
+//                                            num_new_nodes, tmphndl);
+//            forward_target_entities.insert(tmphndl);
+//          }
+//          else {
+//              // else find the relative sense of this entity to the source_entity in this set
+//            int side_no, sense = 0, offset;
+//            if (source_entities.find(*dum_elems.begin()) == source_entities.end()) {
+//              result = thisMB->side_number(*dum_elems.rbegin(), *dum_sub_elems.begin(),
+//                                           side_no, sense, offset);
+//            }
+//            else {
+//              result = thisMB->side_number(*dum_elems.begin(), *dum_sub_elems.begin(),
+//                                           side_no, sense, offset);
+//            }
+//            if (-1 == sense) reverse_target_entities.insert(*dum_sub_elems.begin());
+//            else if (1 == sense) forward_target_entities.insert(*dum_sub_elems.begin());
+//            else return MB_FAILURE;
+//          }
+//        }
+//      }
+//      else {
+        
+          // see if we can match this connectivity with
+          // an existing entity
+        find_match( sub_type, sub_conn, num_sub_nodes, match, direct );
+        
+          // if there is no match, create a new entity
+        if(match == 0)
+        {
+          EntityHandle tmphndl=0;
+          int indices[MB_MAX_SUB_ENTITY_VERTICES];
+          EntityType new_type;
+          int num_new_nodes;
+          MBCN::SubEntityNodeIndices( type, num_nodes, mTargetDim, i, new_type, num_new_nodes, indices );
+          for(int j=0; j<num_new_nodes; j++)
+            sub_conn[j] = conn[indices[j]];
+          result = thisMB->create_element(new_type, sub_conn, num_new_nodes,
+                                          tmphndl);
+          assert(MB_SUCCESS == result);
+          add_adjacency(tmphndl, sub_conn, num_sub_nodes);
+          forward_target_entities.insert(tmphndl);
+        }
+          // if there is a match, delete the matching entity
+          // if we can. 
+        else
+        {
+          if ( (seek_iter = forward_target_entities.find(match)) != forward_target_entities.end())
+          {
+            forward_target_entities.erase(seek_iter);
+            remove_adjacency(match);
+            if(/*!use_adjs &&*/ entity_deletable(match))
+            {
+              result = thisMB->delete_entities(&match, 1);
+              assert(MB_SUCCESS == result);
+            }
+          }
+          else if ( (seek_iter = reverse_target_entities.find(match)) != reverse_target_entities.end())
+          {
+            reverse_target_entities.erase(seek_iter);
+            remove_adjacency(match);
+            if(/*!use_adjs &&*/ entity_deletable(match))
+            {
+              result = thisMB->delete_entities(&match, 1);
+              assert(MB_SUCCESS == result);
+            }
+          }
+          else
+          {
+            if(direct == FORWARD)
+            {
+              forward_target_entities.insert(match);
+            }
+            else
+            {
+              reverse_target_entities.insert(match);
+            }
+          }
+        }
+      //}
+    }
+  }
+
+  deinitialize();
+
+  return MB_SUCCESS;
+}
+
+
+void Skinner::find_match( EntityType type, 
+                             const EntityHandle *conn,
+                             const int num_nodes,
+                             EntityHandle& match,
+                             Skinner::direction &direct)
+{
+  match = 0;
+
+  if (type == MBVERTEX) {
+    match = *conn;
+    direct = FORWARD;
+    return;
+  }
+
+  const EntityHandle *iter = std::min_element(conn, conn+num_nodes);
+
+  std::vector<EntityHandle> *adj = NULL;
+
+  ErrorCode result = thisMB->tag_get_data(mAdjTag, iter, 1, &adj);
+  if(result == MB_FAILURE || adj == NULL)
+  {
+    return;
+  }
+
+  std::vector<EntityHandle>::iterator jter, end_jter;
+  end_jter = adj->end();
+
+  const EntityHandle *tmp;
+  int num_verts;
+
+  for(jter = adj->begin(); jter != end_jter; ++jter)
+  {
+    EntityType tmp_type;
+    tmp_type = thisMB->type_from_handle(*jter);
+
+    if( type != tmp_type )
+      continue;
+
+    result = thisMB->get_connectivity(*jter, tmp, num_verts, true);
+    assert(MB_SUCCESS == result && num_verts >= num_nodes);
+    if(connectivity_match(conn, tmp, num_verts, direct))
+    {
+      match = *jter;
+      break;
+    }        
+  }
+}
+
+bool Skinner::connectivity_match( const EntityHandle *conn1,
+                                     const EntityHandle *conn2,
+                                     const int num_verts,
+                                     Skinner::direction &direct)
+{
+  const EntityHandle *iter =
+    std::find(conn2, conn2+num_verts, conn1[0]);
+  if(iter == conn2+num_verts)
+    return false;
+
+  bool they_match = true;
+
+  int i;
+  unsigned int j = iter - conn2;
+    
+  // first compare forward
+  for(i = 1; i<num_verts; ++i)
+  {
+    if(conn1[i] != conn2[(j+i)%num_verts])
+    {
+      they_match = false;
+      break;
+    }
+  }
+  
+  if(they_match == true)
+  {
+    // need to check for reversed edges here
+    direct = (num_verts == 2 && j) ? REVERSE : FORWARD;
+    return true;
+  }
+  
+  they_match = true;
+  
+  // then compare reverse
+  j += num_verts;
+  for(i = 1; i < num_verts; )
+  {
+    if(conn1[i] != conn2[(j-i)%num_verts])
+    {
+      they_match = false;
+      break;
+    }
+    ++i;
+  }
+  if (they_match)
+  {
+    direct = REVERSE;
+  }
+  return they_match;
+}
+
+  
+ErrorCode Skinner::remove_adjacency(EntityHandle entity)
+{
+  std::vector<EntityHandle> nodes, *adj = NULL;
+  ErrorCode result = thisMB->get_connectivity(&entity, 1, nodes);
+  if (MB_SUCCESS != result) return result;
+  std::vector<EntityHandle>::iterator iter = 
+    std::min_element(nodes.begin(), nodes.end());
+
+  if(iter == nodes.end())
+    return MB_FAILURE;
+
+  // remove this entity from the node
+  if(thisMB->tag_get_data(mAdjTag, &(*iter), 1, &adj) == MB_SUCCESS && adj != NULL)
+  {
+    iter = std::find(adj->begin(), adj->end(), entity);
+    if(iter != adj->end())
+      adj->erase(iter);
+  }
+
+  return result;
+}
+
+bool Skinner::entity_deletable(EntityHandle entity)
+{
+  unsigned char deletable=0;
+  ErrorCode result = thisMB->tag_get_data(mDeletableMBTag, &entity, 1, &deletable);
+  assert(MB_SUCCESS == result);
+  if(MB_SUCCESS == result && deletable == 1)
+    return false;
+  return true;
+}
+
+ErrorCode Skinner::classify_2d_boundary( const Range &boundary,
+                                               const Range &bar_elements,
+                                               EntityHandle boundary_edges,
+                                               EntityHandle inferred_edges,
+                                               EntityHandle non_manifold_edges,
+                                               EntityHandle other_edges,
+                                               int &number_boundary_nodes)
+{
+  Range bedges, iedges, nmedges, oedges;
+  ErrorCode result = classify_2d_boundary(boundary, bar_elements,
+                                             bedges, iedges, nmedges, oedges,
+                                             number_boundary_nodes);
+  if (MB_SUCCESS != result) return result;
+  
+    // now set the input meshsets to the output ranges
+  result = thisMB->clear_meshset(&boundary_edges, 1);
+  if (MB_SUCCESS != result) return result;
+  result = thisMB->add_entities(boundary_edges, bedges);
+  if (MB_SUCCESS != result) return result;
+
+  result = thisMB->clear_meshset(&inferred_edges, 1);
+  if (MB_SUCCESS != result) return result;
+  result = thisMB->add_entities(inferred_edges, iedges);
+  if (MB_SUCCESS != result) return result;
+
+  result = thisMB->clear_meshset(&non_manifold_edges, 1);
+  if (MB_SUCCESS != result) return result;
+  result = thisMB->add_entities(non_manifold_edges, nmedges);
+  if (MB_SUCCESS != result) return result;
+
+  result = thisMB->clear_meshset(&other_edges, 1);
+  if (MB_SUCCESS != result) return result;
+  result = thisMB->add_entities(other_edges, oedges);
+  if (MB_SUCCESS != result) return result;
+
+  return MB_SUCCESS;
+}
+
+ErrorCode Skinner::classify_2d_boundary( const Range &boundary,
+                                               const Range &bar_elements,
+                                               Range &boundary_edges,
+                                               Range &inferred_edges,
+                                               Range &non_manifold_edges,
+                                               Range &other_edges,
+                                               int &number_boundary_nodes)
+{
+
+  // clear out the edge lists
+
+  boundary_edges.clear();
+  inferred_edges.clear();
+  non_manifold_edges.clear();
+  other_edges.clear();
+
+  number_boundary_nodes = 0;
+
+  // make sure we have something to work with
+  if(boundary.empty())
+  {
+    return MB_FAILURE;
+  }
+  
+  // get our working dimensions
+  EntityType type = thisMB->type_from_handle(*(boundary.begin()));
+  const int source_dim = MBCN::Dimension(type);
+
+  // make sure we can handle the working dimensions
+  if(source_dim != 2)
+  {
+    return MB_FAILURE;
+  }
+  mTargetDim = source_dim - 1;
+
+  // initialize
+  initialize();
+
+  // additional initialization for this routine
+  // define a tag for MBEDGE which counts the occurances of the edge below
+  // default should be 0 for existing edges, if any
+
+  Tag count_tag;
+  int default_count = 0;
+  ErrorCode result = thisMB->tag_create("mdbskinner count edges", sizeof(int),
+                                            MB_TAG_DENSE, count_tag, &default_count);
+  assert(MB_SUCCESS == result);
+
+ 
+  Range::const_iterator iter, end_iter;
+  end_iter = boundary.end();
+
+  std::vector<EntityHandle> conn;
+  EntityHandle sub_conn[2];
+  EntityHandle match;
+
+  Range edge_list;
+  Range boundary_nodes;
+  Skinner::direction direct;
+  
+  EntityType sub_type;
+  int num_edge, num_sub_ent_vert;
+  const short* edge_verts;
+  
+  // now, process each entity in the boundary
+
+  for(iter = boundary.begin(); iter != end_iter; ++iter)
+  {
+    // get the connectivity of this entity
+    conn.clear();
+    result = thisMB->get_connectivity(&(*iter), 1, conn, false);
+    assert(MB_SUCCESS == result);
+
+    // add node handles to boundary_node range
+    std::copy(conn.begin(), conn.begin()+MBCN::VerticesPerEntity(type), 
+              range_inserter(boundary_nodes));
+
+    type = thisMB->type_from_handle(*iter);
+    
+    // get connectivity of each n-1 dimension entity (edge in this case)
+    const struct MBCN::ConnMap* conn_map = &(MBCN::mConnectivityMap[type][0]);
+    num_edge = MBCN::NumSubEntities( type, 1 );
+    for(int i=0; i<num_edge; i++)
+    {
+      edge_verts = MBCN::SubEntityVertexIndices( type, 1, i, sub_type, num_sub_ent_vert );
+      assert( sub_type == MBEDGE && num_sub_ent_vert == 2 );
+      sub_conn[0] = conn[edge_verts[0]];
+      sub_conn[1] = conn[edge_verts[1]];
+      int num_sub_nodes = conn_map->num_corners_per_sub_element[i];
+      
+      // see if we can match this connectivity with
+      // an existing entity
+      find_match( MBEDGE, sub_conn, num_sub_nodes, match, direct );
+  
+      // if there is no match, create a new entity
+      if(match == 0)
+      {
+        EntityHandle tmphndl=0;
+        int indices[MB_MAX_SUB_ENTITY_VERTICES];
+        EntityType new_type;
+        int num_new_nodes;
+        MBCN::SubEntityNodeIndices( type, conn.size(), 1, i, new_type, num_new_nodes, indices );
+        for(int j=0; j<num_new_nodes; j++)
+          sub_conn[j] = conn[indices[j]];
+        
+        result = thisMB->create_element(new_type, sub_conn,  
+                                        num_new_nodes, tmphndl);
+        assert(MB_SUCCESS == result);
+        add_adjacency(tmphndl, sub_conn, num_sub_nodes);
+        //target_entities.insert(tmphndl);
+        edge_list.insert(tmphndl);
+        int count;
+        result = thisMB->tag_get_data(count_tag, &tmphndl, 1, &count);
+        assert(MB_SUCCESS == result);
+        count++;
+        result = thisMB->tag_set_data(count_tag, &tmphndl, 1, &count);
+        assert(MB_SUCCESS == result);
+
+      }
+      else
+      {
+        // We found a match, we must increment the count on the match
+        int count;
+        result = thisMB->tag_get_data(count_tag, &match, 1, &count);
+        assert(MB_SUCCESS == result);
+        count++;
+        result = thisMB->tag_set_data(count_tag, &match, 1, &count);
+        assert(MB_SUCCESS == result);
+
+        // if the entity is not deletable, it was pre-existing in
+        // the database.  We therefore may need to add it to the
+        // edge_list.  Since it will not hurt the range, we add
+        // whether it was added before or not
+        if(!entity_deletable(match))
+        {
+          edge_list.insert(match);
+        }
+      }
+    }
+  }
+
+  // Any bar elements in the model should be classified separately
+  // If the element is in the skin edge_list, then it should be put in
+  // the non-manifold edge list.  Edges not in the edge_list are stand-alone
+  // bars, and we make them simply boundary elements
+
+  if (!bar_elements.empty())
+  {
+    Range::iterator bar_iter;
+    for(iter = bar_elements.begin(); iter != bar_elements.end(); ++iter)
+    {
+      EntityHandle handle = *iter;
+      bar_iter = edge_list.find(handle);
+      if (bar_iter != edge_list.end())
+      {
+        // it is in the list, erase it and put in non-manifold list
+        edge_list.erase(bar_iter);
+        non_manifold_edges.insert(handle);
+      }
+      else
+      {
+        // not in the edge list, make it a boundary edge
+        boundary_edges.insert(handle);
+      }
+    }
+  }
+
+  // now all edges should be classified.  Go through the edge_list,
+  // and put all in the appropriate lists
+
+  Range::iterator edge_iter, edge_end_iter;
+  edge_end_iter = edge_list.end();
+  int count;
+  for(edge_iter = edge_list.begin(); edge_iter != edge_end_iter; edge_iter++)
+  {
+    // check the count_tag
+    result = thisMB->tag_get_data(count_tag, &(*edge_iter), 1, &count);
+    assert(MB_SUCCESS == result);
+    if (count == 1)
+    {
+      boundary_edges.insert(*edge_iter);
+   }
+    else if (count == 2)
+    {
+      other_edges.insert(*edge_iter);
+    }
+    else
+    {
+      non_manifold_edges.insert(*edge_iter);
+    }
+  }
+
+  // find the inferred edges from the other_edge_list
+
+  double min_angle_degrees = 20.0;
+  find_inferred_edges(const_cast<Range&> (boundary), other_edges, inferred_edges, min_angle_degrees);
+
+  // we now want to remove the inferred_edges from the other_edges
+
+  Range temp_range;
+ 
+  std::set_difference(other_edges.begin(), other_edges.end(),
+                      inferred_edges.begin(), inferred_edges.end(),
+                      range_inserter(temp_range),
+                      std::less<EntityHandle>() );
+
+  other_edges = temp_range;
+
+  // get rid of count tag and deinitialize
+
+  result = thisMB->tag_delete(count_tag);
+  assert(MB_SUCCESS == result);
+  deinitialize();
+
+  // set the node count
+  number_boundary_nodes = boundary_nodes.size();
+
+  return MB_SUCCESS;
+} 
+
+void Skinner::find_inferred_edges(Range &skin_boundary,
+                                     Range &candidate_edges,
+                                     Range &inferred_edges,
+                                     double reference_angle_degrees)
+{
+
+  // mark all the entities in the skin boundary
+  Tag mark_tag;
+  ErrorCode result = thisMB->tag_create("find inferred edges mark", 1, MB_TAG_BIT, mark_tag, NULL);
+  assert(MB_SUCCESS == result);
+  for(Range::iterator mark_iter = skin_boundary.begin();
+      mark_iter != skin_boundary.end(); ++mark_iter)
+  {
+    unsigned char bit = true;
+    result = thisMB->tag_set_data(mark_tag, &(*mark_iter), 1, &bit);
+    assert(MB_SUCCESS == result);
+  }
+
+  // find the cosine of the reference angle
+
+  double reference_cosine = cos(reference_angle_degrees*SKINNER_PI/180.0);
+  
+  // check all candidate edges for an angle greater than the minimum
+
+  Range::iterator iter, end_iter = candidate_edges.end();
+  std::vector<EntityHandle> adjacencies;
+  std::vector<EntityHandle>::iterator adj_iter;
+  EntityHandle face[2];
+
+  for(iter = candidate_edges.begin(); iter != end_iter; ++iter)
+  {
+
+    // get the 2D elements connected to this edge
+    adjacencies.clear();
+    result = thisMB->get_adjacencies(&(*iter), 1, 2, false, adjacencies);
+    if (MB_SUCCESS != result) 
+      continue;
+
+    // there should be exactly two, that is why the edge is classified as nonBoundary
+    // and manifold
+
+    int faces_found = 0;
+    for(adj_iter = adjacencies.begin(); adj_iter != adjacencies.end() && faces_found < 2; ++adj_iter)
+    {
+      // we need to find two of these which are in the skin
+      unsigned char is_marked = 0;
+      result = thisMB->tag_get_data(mark_tag, &(*adj_iter), 1, &is_marked);
+      assert(MB_SUCCESS == result);
+      if(is_marked)
+      {
+        face[faces_found] = *adj_iter;
+        faces_found++;
+      } 
+    }
+
+//    assert(faces_found == 2 || faces_found == 0);
+    if (2 != faces_found) 
+      continue;
+
+    // see if the two entities have a sufficient angle
+
+    if ( has_larger_angle(face[0], face[1], reference_cosine) )
+    {
+       inferred_edges.insert(*iter);
+    }
+  }
+  
+  result = thisMB->tag_delete(mark_tag);
+  assert(MB_SUCCESS == result);
+}
+
+bool Skinner::has_larger_angle(EntityHandle &entity1,
+                                 EntityHandle &entity2,
+                                 double reference_angle_cosine)
+{
+  // compare normals to get angle.  We assume that the surface quads
+  // which we test here will be approximately planar
+
+  double norm[2][3];
+  Util::normal(thisMB, entity1, norm[0][0], norm[0][1], norm[0][2]);
+  Util::normal(thisMB, entity2, norm[1][0], norm[1][1], norm[1][2]);
+
+  double cosine = norm[0][0] * norm[1][0] + norm[0][1] * norm[1][1] + norm[0][2] * norm[1][2];
+
+  if (cosine < reference_angle_cosine)
+  {
+    return true;
+  }
+
+
+  return false;
+}
+
+  // get skin entities of prescribed dimension
+ErrorCode Skinner::find_skin(const Range &entities,
+                                 int dim,
+                                 Range &skin_entities,
+                                 bool create_vert_elem_adjs) 
+{
+  Range tmp_skin;
+  ErrorCode result = find_skin(entities, (dim==0), tmp_skin, 0, 
+                                 create_vert_elem_adjs, true);
+  if (MB_SUCCESS != result || tmp_skin.empty()) return result;
+  
+  if (tmp_skin.all_of_dimension(dim)) {
+    if (skin_entities.empty())
+      skin_entities.swap(tmp_skin);
+    else
+      skin_entities.merge(tmp_skin);
+  }
+  else {
+    result = thisMB->get_adjacencies( tmp_skin, dim, true, skin_entities, 
+                                      Interface::UNION );
+  }
+  
+  return result;
+}
+
+ErrorCode Skinner::find_skin_vertices( const Range& entities,
+                                           Range* skin_verts,
+                                           Range* skin_elems,
+                                           Range* skin_rev_elems,
+                                           bool create_skin_elems,
+                                           bool corners_only )
+{
+  ErrorCode rval;
+  if (entities.empty())
+    return MB_SUCCESS;
+  
+  const int dim = MBCN::Dimension(TYPE_FROM_HANDLE(entities.front()));
+  if (dim < 1 || dim > 3 || !entities.all_of_dimension(dim))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+    // are we skinning all entities
+  size_t count = entities.size();
+  int num_total;
+  rval = thisMB->get_number_entities_by_dimension( 0, dim, num_total );
+  if (MB_SUCCESS != rval)
+    return rval;
+  bool all = (count == (size_t)num_total);
+  
+    // Create a bit tag for fast intersection with input entities range. 
+    // If we're skinning all the entities in the mesh, we really don't
+    // need the tag.  To save memory, just create it with a default value
+    // of one and don't set it.  That way MOAB will return 1 for all 
+    // entities.
+  Tag tag;
+  char bit = all ? 1 : 0;
+  rval = thisMB->tag_create( NULL, 1, MB_TAG_BIT, tag, &bit );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // tag all entities in input range
+  if (!all) {
+    std::vector<unsigned char> vect(count, 1);
+    rval = thisMB->tag_set_data( tag, entities, &vect[0] );
+    if (MB_SUCCESS != rval) {
+      thisMB->tag_delete(tag);
+      return rval;
+    }
+  }
+  
+  switch (dim) {
+    case 1:
+      if (skin_verts)
+        rval = find_skin_vertices_1D( tag, entities, *skin_verts );
+      else if (skin_elems)
+        rval = find_skin_vertices_1D( tag, entities, *skin_elems );
+      else
+        rval = MB_SUCCESS;
+      break;
+    case 2:
+      rval = find_skin_vertices_2D( tag, entities, skin_verts, 
+                                    skin_elems, skin_rev_elems, 
+                                    create_skin_elems, corners_only );
+      break;
+    case 3:
+      rval = find_skin_vertices_3D( tag, entities, skin_verts, 
+                                    skin_elems, skin_rev_elems, 
+                                    create_skin_elems, corners_only );
+      break;
+    default:
+      rval = MB_TYPE_OUT_OF_RANGE;
+      break;
+  }
+  
+  thisMB->tag_delete(tag);
+  return rval;
+}
+
+ErrorCode Skinner::find_skin_vertices_1D( Tag tag,
+                                              const Range& edges,
+                                              Range& skin_verts )
+{
+  // This rather simple algorithm is provided for completeness
+  // (not sure how often one really wants the 'skin' of a chain
+  // or tangle of edges.)
+  //
+  // A vertex is on the skin of the edges if it is contained in exactly
+  // one of the edges *in the input range*.  
+  //
+  // This function expects the caller to have tagged all edges in the
+  // input range with a value of one for the passed bit tag, and all
+  // other edges with a value of zero.  This allows us to do a faster
+  // intersection with the input range and the edges adjacent to a vertex.
+
+  ErrorCode rval;
+  std::vector<EntityHandle>::iterator i;
+  Range::iterator hint = skin_verts.begin();
+  
+  // All input entities must be edges.
+  if (!edges.all_of_dimension(1))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+    // get all the vertices
+  Range verts;
+  rval = thisMB->get_connectivity( edges, verts, true );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // Test how many edges each input vertex is adjacent to.
+  std::vector<char> tag_vals;
+  std::vector<EntityHandle> adj;
+  int count;
+  for (Range::const_iterator it = verts.begin(); it != verts.end(); ++it) {
+      // get edges adjacent to vertex
+    adj.clear();
+    rval = thisMB->get_adjacencies( &*it, 1, 1, false, adj );
+    if (MB_SUCCESS != rval) return rval;
+    if (adj.empty())
+      continue;
+
+      // Intersect adjacent edges with the input list of edges
+    tag_vals.resize( adj.size() );
+    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
+    if (MB_SUCCESS != rval) return rval;
+    count = std::count( tag_vals.begin(), tag_vals.end(), '\001' );
+    
+      // If adjacent to only one input edge, then vertex is on skin
+    if (count == 1) {
+      hint = skin_verts.insert( hint, *it );
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+// A Container for storing a list of element sides adjacent
+// to a vertex.  The template parameter is the number of 
+// corners for the side.
+template <unsigned CORNERS> 
+class AdjSides 
+{
+public:
+  
+  /**
+   * This struct is used to for a reduced representation of element
+   * "sides" adjacent to a give vertex.  As such, it 
+   * a) does not store the initial vertex that all sides are adjacent to
+   * b) orders the remaining vertices in a specific way for fast comparison.
+   * 
+   * For edge elements, only the opposite vertex is stored.
+   * For triangle elements, only the other two vertices are stored,
+   *   and they are stored with the smaller of those two handles first.
+   * For quad elements, only the other three vertices are stored.
+   *  They are stored such that the vertex opposite the implicit (not
+   *  stored) vertex is always in slot 1.  The other two vertices 
+   *  (in slots 0 and 2) are ordered such that the handle of the one in 
+   *  slot 0 is smaller than the handle in slot 2.
+   *
+   * For each side, the adj_elem field is used to store the element that
+   * it is a side of as long as the element is considered to be on the skin.
+   * The adj_elem field is cleared (set to zero) to indicate that this
+   * side is no longer considered to be on the skin (and is the side of
+   * more than one element.)
+   */
+  struct Side {
+    EntityHandle handles[CORNERS-1]; //!< side vertices, except for implicit one
+    EntityHandle adj_elem;           //!< element that this is a side of, or zero
+    bool skin() const { return 0 != adj_elem; }
+    
+    /** construct from connectivity of side
+     *\param array The connectivity of the element side.
+     *\param idx   The index of the implicit vertex (contained
+     *             in all sides in the list.)
+     *\param adj   The element that this is a side of.
+     */
+    Side( const EntityHandle* array, int idx,
+          EntityHandle adj, unsigned short  ) 
+      : adj_elem(adj) /*, elem_side(side)*/ 
+    {
+      switch (CORNERS) {
+        default:
+          assert(false);
+          break;
+        case 4: handles[2] = array[(idx+3)%CORNERS];
+        case 3: handles[1] = array[(idx+2)%CORNERS];
+        case 2: handles[0] = array[(idx+1)%CORNERS];
+      }
+      if (CORNERS == 3 && handles[1] > handles[0])
+        std::swap( handles[0], handles[1] );
+      if (CORNERS == 4 && handles[2] > handles[0])
+        std::swap( handles[0], handles[2] );
+    }
+    
+    /** construct from connectivity of parent element
+     *\param array The connectivity of the parent element
+     *\param idx   The index of the implicit vertex (contained
+     *             in all sides in the list.)  This is an index
+     *             into 'indices', not 'array'.
+     *\param adj   The element that this is a side of.
+     *\param indices  The indices into 'array' at which the vertices
+     *             representing the side occur.
+     */
+    Side( const EntityHandle* array,  int idx,
+          EntityHandle adj, unsigned short ,
+          const short* indices ) 
+      : adj_elem(adj) /*, elem_side(side)*/ 
+    {
+      switch (CORNERS) {
+        default:
+          assert(false);
+          break;
+        case 4: handles[2] = array[indices[(idx+3)%CORNERS]];
+        case 3: handles[1] = array[indices[(idx+2)%CORNERS]];
+        case 2: handles[0] = array[indices[(idx+1)%CORNERS]];
+      }
+      if (CORNERS == 3 && handles[1] > handles[0])
+        std::swap( handles[0], handles[1] );
+      if (CORNERS == 4 && handles[2] > handles[0])
+        std::swap( handles[0], handles[2] );
+    }
+   
+    // Compare two side instances.  Relies in the ordering of 
+    // vertex handles as described above.
+    bool operator==( const Side& other ) const 
+    {
+      switch (CORNERS) {
+        default:
+          assert(false);
+          return false;
+        case 4:
+          return handles[0] == other.handles[0] 
+              && handles[1] == other.handles[1]
+              && handles[2] == other.handles[2];
+        case 3:
+          return handles[0] == other.handles[0] 
+              && handles[1] == other.handles[1];
+        case 2:
+          return handles[0] == other.handles[0];
+      }
+    }
+  };
+
+private:
+
+  std::vector<Side> data; //!< List of sides
+  size_t skin_count;      //!< Cached count of sides that are skin
+  
+public:
+
+  typedef typename std::vector<Side>::iterator iterator;
+  typedef typename std::vector<Side>::const_iterator const_iterator;
+  const_iterator begin() const { return data.begin(); }
+  const_iterator end() const { return data.end(); }
+  
+  void clear() { data.clear(); skin_count = 0; }
+  bool empty() const { return data.empty(); }
+  
+  AdjSides() : skin_count(0) {}
+  
+  size_t num_skin() const { return skin_count; }
+  
+    /** \brief insert side, specifying side connectivity
+     *
+     * Either insert a new side, or if the side is already in the
+     * list, mark it as not on the skin.
+     *
+     *\param handles The connectivity of the element side.
+     *\param skip_idx The index of the implicit vertex (contained
+     *             in all sides in the list.)
+     *\param adj_elem The element that this is a side of.
+     *\param elem_side Which side of adj_elem are we storing
+     *             (MBCN side number.)
+     */
+  void insert( const EntityHandle* handles, int skip_idx,
+               EntityHandle adj_elem, unsigned short elem_side )
+  {
+    Side side( handles, skip_idx, adj_elem, elem_side );
+    iterator p = std::find( data.begin(), data.end(), side );
+    if (p == data.end()) {
+      data.push_back( side );
+      ++skin_count; // not in list yet, so skin side (so far)
+    }
+    else if (p->adj_elem) {
+      p->adj_elem = 0; // mark as not on skin
+      --skin_count; // decrement cached count of skin elements
+    }
+  }
+  
+    /** \brief insert side, specifying list of indices into parent element
+     * connectivity.
+     *
+     * Either insert a new side, or if the side is already in the
+     * list, mark it as not on the skin.
+     *
+     *\param handles The connectivity of the parent element
+     *\param skip_idx The index of the implicit vertex (contained
+     *             in all sides in the list.)  This is an index
+     *             into 'indices', not 'handles'.
+     *\param adj_elem The element that this is a side of (parent handle).
+     *\param indices  The indices into 'handles' at which the vertices
+     *             representing the side occur.
+     *\param elem_side Which side of adj_elem are we storing
+     *             (MBCN side number.)
+     */
+  void insert( const EntityHandle* handles,  int skip_idx,
+               EntityHandle adj_elem, unsigned short elem_side,
+               const short* indices )
+  {
+    Side side( handles, skip_idx, adj_elem, elem_side, indices );
+    iterator p = std::find( data.begin(), data.end(), side );
+    if (p == data.end()) {
+      data.push_back( side );
+      ++skin_count; // not in list yet, so skin side (so far)
+    }
+    else if (p->adj_elem) {
+      p->adj_elem = 0; // mark as not on skin
+      --skin_count; // decrement cached count of skin elements
+    }
+  }
+  
+  /**\brief Search list for a given side, and if found, mark as not skin.
+   *
+   *\param other   Connectivity of side
+   *\param skip_index Index in 'other' at which implicit vertex occurs.
+   *\param elem_out If return value is true, the element that the side is a
+   *                side of.  If return value is false, not set.
+   *\return true if found and marked not-skin, false if not found.
+   *
+   * Given the connectivity of some existing element, check if it occurs
+   * in the list.  If it does, clear the "is skin" state of the side so
+   * that we know that we don't need to later create the side element.
+   */
+  bool find_and_unmark( const EntityHandle* other, int skip_index, EntityHandle& elem_out ) 
+  {
+    Side s( other, skip_index, 0, 0 );
+    iterator p = std::find( data.begin(), data.end(), s );
+    if (p == data.end() || !p->adj_elem)
+      return false;
+    else {
+      elem_out = p->adj_elem;
+      p->adj_elem = 0; // clear "is skin" state for side
+      --skin_count;    // decrement cached count of skin sides
+      return true;
+    }
+  }
+};
+
+// Utiltiy function used by find_skin_vertices_2D and
+// find_skin_vertices_3D to create elements representing
+// the skin side of a higher-dimension element if one
+// does not already exist.  
+//
+// Some arguments may seem redundant, but they are used
+// to create the correct order of element when the input
+// element contains higher-order nodes.
+//
+// This function always creates elements that have a "forward"
+// orientation with respect to the parent element (have
+// nodes ordered the same as MBCN returns for the "side").
+//
+// elem - The higher-dimension element for which to create
+//        a lower-dim element representing the side.
+// side_type - The EntityType of the desired side.
+// side_conn - The connectivity of the new side.
+ErrorCode Skinner::create_side( EntityHandle elem,
+                                    EntityType side_type,
+                                    const EntityHandle* side_conn,
+                                    EntityHandle& side_elem )
+{
+  const int max_side = 9;
+  const EntityHandle* conn;
+  int len, side_len, side, sense, offset, indices[max_side];
+  ErrorCode rval;
+  EntityType type = TYPE_FROM_HANDLE(elem), tmp_type;
+  const int ncorner = MBCN::VerticesPerEntity( side_type );
+  const int d = MBCN::Dimension(side_type);
+  std::vector<EntityHandle> storage;
+  
+  // Get the connectivity of the parent element
+  rval = thisMB->get_connectivity( elem, conn, len, false, &storage );
+  if (MB_SUCCESS != rval) return rval;
+ 
+  // Find which side we are creating and get indices of all nodes
+  // (including higher-order, if any.)
+  MBCN::SideNumber( type, conn, side_conn, ncorner, d, side, sense, offset );
+  MBCN::SubEntityNodeIndices( type, len, d, side, tmp_type, side_len, indices );
+  assert(side_len <= max_side);
+  assert(side_type == tmp_type);
+  
+  //NOTE: re-create conn array even when no higher-order nodes
+  //      because we want it to always be forward with respect
+  //      to the side ordering.
+  EntityHandle side_conn_full[max_side];
+  for (int i = 0; i < side_len; ++i)
+    side_conn_full[i] = conn[indices[i]];
+  
+  return thisMB->create_element( side_type, side_conn_full, side_len, side_elem );
+}
+
+// Test if an edge is reversed with respect MBCN's ordering
+// for the "side" of a face.
+bool Skinner::edge_reversed( EntityHandle face,
+                               const EntityHandle* edge_ends )
+{
+  const EntityHandle* conn;
+  int len, idx;
+  ErrorCode rval = thisMB->get_connectivity( face, conn, len, true );
+  if (MB_SUCCESS != rval) {
+    assert(false);
+    return false;
+  }
+  idx = std::find( conn, conn+len, edge_ends[0] ) - conn;
+  if (idx == len) {
+    assert(false);
+    return false;
+  }
+  return (edge_ends[1] == conn[(idx+len-1)%len]);
+}
+
+// Test if a 2D element representing the side or face of a
+// volume element is reversed with respect to the MBCN node
+// ordering for the corresponding region element side.
+bool Skinner::face_reversed( EntityHandle region,
+                               const EntityHandle* face_corners,
+                               EntityType face_type )
+{
+  const EntityHandle* conn;
+  int len, side, sense, offset;
+  ErrorCode rval = thisMB->get_connectivity( region, conn, len, true );
+  if (MB_SUCCESS != rval) {
+    assert(false);
+    return false;
+  }
+  short r = MBCN::SideNumber( TYPE_FROM_HANDLE(region), conn, face_corners, 
+                              MBCN::VerticesPerEntity(face_type),
+                              MBCN::Dimension(face_type),
+                              side, sense, offset );
+  assert(0 == r);
+  return (!r && sense == -1);
+}
+
+ErrorCode Skinner::find_skin_vertices_2D( Tag tag,
+                                              const Range& faces,
+                                              Range* skin_verts,
+                                              Range* skin_edges,
+                                              Range* reversed_edges,
+                                              bool create_edges,
+                                              bool corners_only )
+{
+  // This function iterates over all the vertices contained in the
+  // input face list.  For each such vertex, it then iterates over
+  // all of the sides of the face elements adjacent to the vertex.
+  // If an adjacent side is the side of only one of the input
+  // faces, then that side is on the skin.  
+  //
+  // This algorithm will visit each skin vertex exactly once.  It
+  // will visit each skin side once for each vertex in the side.
+  //
+  // This function expects the caller to have created the passed bit
+  // tag and set it to one only for the faces in the passed range.  This
+  // tag is used to do a fast intersection of the faces adjacent to a 
+  // vertex with the faces in the input range (discard any for which the
+  // tag is not set to one.)
+
+  ErrorCode rval;
+  std::vector<EntityHandle>::iterator i, j;
+  Range::iterator hint;
+  if (skin_verts)
+    hint = skin_verts->begin();
+  std::vector<EntityHandle> storage;
+  const EntityHandle *conn;
+  int len;
+  bool find_edges = skin_edges || create_edges;
+  EntityHandle face;
+  
+  if (!faces.all_of_dimension(2))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+    // get all the vertices
+  Range verts;
+  rval = thisMB->get_connectivity( faces, verts, true );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  std::vector<char> tag_vals;
+  std::vector<EntityHandle> adj;
+  AdjSides<2> adj_edges;
+  for (Range::const_iterator it = verts.begin(); it != verts.end(); ++it) {
+    bool higher_order = false;
+  
+      // get all adjacent faces
+    adj.clear();
+    rval = thisMB->get_adjacencies( &*it, 1, 2, false, adj );
+    if (MB_SUCCESS != rval) return rval;
+    if (adj.empty())
+      continue;
+
+      // remove those not in the input list (intersect with input list)
+    i = j = adj.begin();
+    tag_vals.resize( adj.size() );
+    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
+    if (MB_SUCCESS != rval) return rval;
+      // remove non-tagged entries
+    i = j = adj.begin();
+    for (; i != adj.end(); ++i) 
+      if (tag_vals[i - adj.begin()])
+        *(j++) = *i;
+    adj.erase( j, adj.end() );
+    
+      // For each adjacent face, check the edges adjacent to the current vertex
+    adj_edges.clear();    // other vertex for adjacent edges
+    for (i = adj.begin(); i != adj.end(); ++i) {
+      rval = thisMB->get_connectivity( *i, conn, len, false, &storage );
+      if (MB_SUCCESS != rval) return rval;
+      
+        // For a single face element adjacent to this vertex, there
+        // will be exactly two sides (edges) adjacent to the vertex.
+        // Find the other vertex for each of the two edges.
+        
+      EntityHandle prev, next; // vertices of two adjacent edge-sides
+      const int idx = std::find(conn, conn+len, *it) - conn;
+      assert(idx != len);
+
+      if (TYPE_FROM_HANDLE(*i) == MBTRI && len > 3) {
+        len = 3;
+        higher_order = true;
+        if (idx > 2) // skip higher-order nodes for now
+          continue;
+      }
+      else if (TYPE_FROM_HANDLE(*i) == MBQUAD && len > 4) {
+        len = 4;
+        higher_order = true;
+        if (idx > 3) // skip higher-order nodes for now
+          continue;
+      }
+
+      const int prev_idx = (idx + len - 1)%len;
+      prev = conn[prev_idx];
+      next = conn[(idx+1)%len];
+      
+        // Insert sides (edges) in our list of candidate skin sides
+      adj_edges.insert( &prev, 1, *i, prev_idx );
+      adj_edges.insert( &next, 1, *i, idx );
+    }
+    
+      // If vertex is not on skin, advance to next vertex.
+      // adj_edges handled checking for duplicates on insertion.
+      // If every candidate skin edge occurred more than once (was
+      // not in fact on the skin), then we're done with this vertex.
+    if (0 == adj_edges.num_skin())
+      continue;
+    
+      // If user requested Range of *vertices* on the skin...
+    if (skin_verts) {
+        // Put skin vertex in output list
+      hint = skin_verts->insert( hint, *it );
+ 
+        // Add mid edge nodes to vertex list
+      if (!corners_only && higher_order) {
+        for (AdjSides<2>::const_iterator p = adj_edges.begin(); p != adj_edges.end(); ++p) {
+          if (p->skin()) {
+            face = p->adj_elem;
+            EntityType type = TYPE_FROM_HANDLE(face);
+
+            rval = thisMB->get_connectivity( face, conn, len, false );
+            if (MB_SUCCESS != rval) return rval;
+            if (!MBCN::HasMidEdgeNodes( type, len ))
+              continue;
+
+            EntityHandle ec[2] = { *it, p->handles[0] };
+            int side, sense, offset;
+            MBCN::SideNumber( type, conn, ec, 2, 1, side, sense, offset );
+            offset = MBCN::HONodeIndex( type, len, 1, side );
+            assert(offset >= 0 && offset < len);
+            skin_verts->insert( conn[offset] );
+          }
+        }
+      }
+    }
+ 
+      // If user requested Range of *edges* on the skin...
+    if (find_edges) {
+        // Search list of existing adjacent edges for any that are on the skin
+      adj.clear();
+      rval = thisMB->get_adjacencies( &*it, 1, 1, false, adj );
+      if (MB_SUCCESS != rval) return rval;
+      for (i = adj.begin(); i != adj.end(); ++i) {
+        rval = thisMB->get_connectivity( *i, conn, len, true );
+        if (MB_SUCCESS != rval) return rval;
+
+          // bool equality expression within find_and_unmark call
+          // will be evaluate to the index of *it in the conn array. 
+          //
+          // Note that the order of the terms in the if statement is important.
+          // We want to unmark any existing skin edges even if we aren't 
+          // returning them.  Otherwise we'll end up creating duplicates 
+          // if create_edges is true and skin_edges is not.
+        if (adj_edges.find_and_unmark( conn, (conn[1] == *it), face ) && skin_edges) {
+          if (reversed_edges && edge_reversed( face, conn ))
+            reversed_edges->insert( *i );
+          else
+            skin_edges->insert( *i );
+        }
+      }
+    }
+    
+      // If the user requested that we create new edges for sides
+      // on the skin for which there is no existing edge, and there
+      // are still skin sides for which no corresponding edge was found...
+    if (create_edges && adj_edges.num_skin()) {
+        // Create any skin edges that don't exist
+      for (AdjSides<2>::const_iterator p = adj_edges.begin(); p != adj_edges.end(); ++p) {
+        if (p->skin()) {
+          EntityHandle edge, ec[] = { *it, p->handles[0] };
+          rval = create_side( p->adj_elem, MBEDGE, ec, edge );
+          if (MB_SUCCESS != rval) return rval;
+          if (skin_edges)
+            skin_edges->insert( edge );
+        }
+      }
+    }
+
+  } // end for each vertex
+  
+  return MB_SUCCESS;
+}
+  
+
+ErrorCode Skinner::find_skin_vertices_3D( Tag tag,
+                                              const Range& entities,
+                                              Range* skin_verts,
+                                              Range* skin_faces,
+                                              Range* reversed_faces,
+                                              bool create_faces,
+                                              bool corners_only )
+{
+  // This function iterates over all the vertices contained in the
+  // input vol elem list.  For each such vertex, it then iterates over
+  // all of the sides of the vol elements adjacent to the vertex.
+  // If an adjacent side is the side of only one of the input
+  // elements, then that side is on the skin.  
+  //
+  // This algorithm will visit each skin vertex exactly once.  It
+  // will visit each skin side once for each vertex in the side.
+  //
+  // This function expects the caller to have created the passed bit
+  // tag and set it to one only for the elements in the passed range.  This
+  // tag is used to do a fast intersection of the elements adjacent to a 
+  // vertex with the elements in the input range (discard any for which the
+  // tag is not set to one.)
+  //
+  // For each vertex, iterate over each adjacent element.  Construct
+  // lists of the sides of each adjacent element that contain the vertex.
+  //
+  // A list of three-vertex sides is kept for all triangular faces,
+  // included three-vertex faces of type MBPOLYGON.  Putting polygons
+  // in the same list ensures that we find polyhedron and non-polyhedron
+  // elements that are adjacent.
+  //
+  // A list of four-vertex sides is kept for all quadrilateral faces,
+  // including four-vertex faces of type MBPOLYGON.
+  //
+  // Sides with more than four vertices must have an explicit MBPOLYGON
+  // element representing them because MBPOLYHEDRON connectivity is a
+  // list of faces rather than vertices.  So the third list (vertices>=5),
+  // need contain only the handle of the face rather than the vertex handles.
+
+  ErrorCode rval;
+  std::vector<EntityHandle>::iterator i, j;
+  Range::iterator hint;
+  if (skin_verts)
+    hint = skin_verts->begin();
+  std::vector<EntityHandle> storage, storage2; // temp storage for conn lists
+  const EntityHandle *conn, *conn2;
+  int len, len2;
+  bool find_faces = skin_faces || create_faces;
+  int clen, side, sense, offset, indices[9];
+  EntityType face_type;
+  EntityHandle elem;
+  
+  if (!entities.all_of_dimension(3))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+  // get all the vertices
+  Range verts;
+  rval = thisMB->get_adjacencies( entities, 0, false, verts, Interface::UNION );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  AdjSides<4> adj_quads; // 4-node sides adjacent to a vertex
+  AdjSides<3> adj_tris;  // 3-node sides adjacent to a vertex
+  AdjSides<2> adj_poly;  // n-node sides (n>5) adjacent to vertex
+                         // (must have an explicit polygon, so store
+                         // polygon handle rather than vertices.)
+  std::vector<char> tag_vals;
+  std::vector<EntityHandle> adj;
+  for (Range::const_iterator it = verts.begin(); it != verts.end(); ++it) {
+    bool higher_order = false;
+  
+      // get all adjacent elements
+    adj.clear();
+    rval = thisMB->get_adjacencies( &*it, 1, 3, false, adj );
+    if (MB_SUCCESS != rval) return rval;
+    if (adj.empty())
+      continue;
+      
+      // remove those not tagged (intersect with input range)
+    i = j = adj.begin();
+    tag_vals.resize( adj.size() );
+    rval = thisMB->tag_get_data( tag, &adj[0], adj.size(), &tag_vals[0] );
+    if (MB_SUCCESS != rval) return rval;
+    for (; i != adj.end(); ++i) 
+      if (tag_vals[i - adj.begin()])
+        *(j++) = *i;
+    adj.erase( j, adj.end() );
+      
+      // Build lists of sides of 3D element adjacent to the current vertex
+    adj_quads.clear(); // store three other vertices for each adjacent quad face
+    adj_tris.clear();  // store two other vertices for each adjacent tri face
+    adj_poly.clear();  // store handle of each adjacent polygonal face
+    int idx;
+    for (i = adj.begin(); i != adj.end(); ++i) {
+      const EntityType type = TYPE_FROM_HANDLE(*i);
+      
+        // Special case for POLYHEDRA
+      if (type == MBPOLYHEDRON) {
+        rval = thisMB->get_connectivity( *i, conn, len );
+        if (MB_SUCCESS != rval) return rval;
+        for (int k = 0; k < len; ++k) {
+          rval = thisMB->get_connectivity( conn[k], conn2, len2, true, &storage2 );
+          if (MB_SUCCESS != rval) return rval;
+          idx = std::find( conn2, conn2+len2, *it) - conn2;
+          if (idx == len2) // vertex not in this face
+            continue;
+          
+            // Treat 3- and 4-vertex faces specially, so that
+            // if the mesh contains both elements and polyhedra,
+            // we don't miss one type adjacent to the other.
+          switch (len2) {
+            case 3:
+              adj_tris.insert( conn2, idx, *i, k );
+              break;
+            case 4:
+              adj_quads.insert( conn2, idx, *i, k );
+              break;
+            default:
+              adj_poly.insert( conn+k, 1, *i, k );
+              break;
+            }
+        }
+      }
+      else {
+        rval = thisMB->get_connectivity( *i, conn, len, false, &storage );
+        if (MB_SUCCESS != rval) return rval;
+
+        idx = std::find(conn, conn+len, *it) - conn;
+        assert(idx != len);
+        
+        if (len > MBCN::VerticesPerEntity( type )) {
+          higher_order =true;
+            // skip higher-order nodes for now
+          if (idx >= MBCN::VerticesPerEntity( type )) 
+            continue;
+        }
+
+          // For each side of the element...
+        const int num_faces = MBCN::NumSubEntities( type, 2 );
+        for (int f = 0; f < num_faces; ++f) {
+          int num_vtx;
+          const short* face_indices = MBCN::SubEntityVertexIndices(type, 2, f, face_type, num_vtx );
+          const short face_idx = std::find(face_indices, face_indices+num_vtx, (short)idx) - face_indices;
+            // skip sides that do not contain vertex from outer loop
+          if (face_idx == num_vtx)
+            continue; // current vertex not in this face
+
+          assert(num_vtx <= 4); // polyhedra handled above
+          switch (face_type) {
+            case MBTRI:
+              adj_tris.insert( conn, face_idx, *i, f, face_indices );
+              break;
+            case MBQUAD:
+              adj_quads.insert( conn, face_idx, *i, f, face_indices );
+              break;
+            default:
+              return MB_TYPE_OUT_OF_RANGE;
+          }
+        }
+      }
+    } // end for (adj[3])
+    
+      // If vertex is not on skin, advance to next vertex
+    if (0 == (adj_tris.num_skin() + adj_quads.num_skin() + adj_poly.num_skin()))
+      continue;
+    
+      // If user requested that skin *vertices* be passed back...
+    if (skin_verts) {
+        // Put skin vertex in output list
+      hint = skin_verts->insert( hint, *it );
+ 
+        // Add mid-edge and mid-face nodes to vertex list
+      if (!corners_only && higher_order) {
+        for (AdjSides<3>::const_iterator t = adj_tris.begin(); t != adj_tris.end(); ++t) {
+          if (t->skin()) {
+            elem = t->adj_elem;
+            EntityType type = TYPE_FROM_HANDLE(elem);
+
+            rval = thisMB->get_connectivity( elem, conn, len, false );
+            if (MB_SUCCESS != rval) return rval;
+            if (!MBCN::HasMidNodes( type, len ))
+              continue;
+
+            EntityHandle ec[3] = { *it, t->handles[0], t->handles[1] };
+            MBCN::SideNumber( type, conn, ec, 3, 2, side, sense, offset );
+            MBCN::SubEntityNodeIndices( type, len, 2, side, face_type, clen, indices );
+            assert(MBTRI == face_type);
+            for (int k = 3; k < clen; ++k)
+              skin_verts->insert( conn[indices[k]] );
+          }
+        }
+        for (AdjSides<4>::const_iterator q = adj_quads.begin(); q != adj_quads.end(); ++q) {
+          if (q->skin()) {
+            elem = q->adj_elem;
+            EntityType type = TYPE_FROM_HANDLE(elem);
+
+            rval = thisMB->get_connectivity( elem, conn, len, false );
+            if (MB_SUCCESS != rval) return rval;
+            if (!MBCN::HasMidNodes( type, len ))
+              continue;
+
+            EntityHandle ec[4] = { *it, q->handles[0], q->handles[1], q->handles[2] };
+            MBCN::SideNumber( type, conn, ec, 4, 2, side, sense, offset );
+            MBCN::SubEntityNodeIndices( type, len, 2, side, face_type, clen, indices );
+            assert(MBQUAD == face_type);
+            for (int k = 4; k < clen; ++k)
+              skin_verts->insert( conn[indices[k]] );
+          }
+        }
+      }
+    }
+
+      // If user requested that we pass back the list of 2D elements
+      // representing the skin of the mesh...
+    if (find_faces) {
+        // Search list of adjacent faces for any that are on the skin
+      adj.clear();
+      rval = thisMB->get_adjacencies( &*it, 1, 2, false, adj );
+      if (MB_SUCCESS != rval) return rval;
+
+      for (i = adj.begin(); i != adj.end(); ++i) {
+        rval = thisMB->get_connectivity( *i, conn, len, true );
+        if (MB_SUCCESS != rval) return rval;
+        const int idx = std::find( conn, conn+len, *it ) - conn;
+        assert(idx != len);
+          // Note that the order of the terms in the if statements below
+          // is important.  We want to unmark any existing skin faces even 
+          // if we aren't returning them.  Otherwise we'll end up creating 
+          // duplicates if create_faces is true.
+        if (3 == len) {
+          if (adj_tris.find_and_unmark( conn, idx, elem ) && skin_faces) {
+            if (reversed_faces && face_reversed( elem, conn, MBTRI ))
+              reversed_faces->insert( *i );
+            else
+              skin_faces->insert( *i );
+          }
+        }
+        else if (4 == len) {
+          if (adj_quads.find_and_unmark( conn, idx, elem ) && skin_faces) {
+            if (reversed_faces && face_reversed( elem, conn, MBQUAD ))
+              reversed_faces->insert( *i );
+            else
+              skin_faces->insert( *i );
+          }
+        }
+        else {
+          if (adj_poly.find_and_unmark( &*i, 1, elem ) && skin_faces)
+            skin_faces->insert( *i );
+        }
+      }
+    }
+
+      // If user does not want use to create new faces representing
+      // sides for which there is currently no explicit element, 
+      // skip the remaining code and advance the outer loop to the 
+      // next vertex.
+    if (!create_faces)
+      continue;
+
+      // Polyhedra always have explictly defined faces, so
+      // there is no way we could need to create such a face.
+    assert(0 == adj_poly.num_skin());
+    
+      // Create any skin tris that don't exist
+    if (adj_tris.num_skin()) {
+      for (AdjSides<3>::const_iterator t = adj_tris.begin(); t != adj_tris.end(); ++t) {
+        if (t->skin()) {
+          EntityHandle tri, c[3] = { *it, t->handles[0], t->handles[1] };
+          rval = create_side( t->adj_elem, MBTRI, c, tri );
+          if (MB_SUCCESS != rval) return rval;
+          if (skin_faces)
+            skin_faces->insert( tri );
+        }
+      }
+    }
+    
+      // Create any skin quads that don't exist
+    if (adj_quads.num_skin()) {
+      for (AdjSides<4>::const_iterator q = adj_quads.begin(); q != adj_quads.end(); ++q) {
+        if (q->skin()) {
+          EntityHandle quad, c[4] = { *it, q->handles[0], q->handles[1], q->handles[2] };
+          rval = create_side( q->adj_elem, MBQUAD, c, quad );
+          if (MB_SUCCESS != rval) return rval;
+          if (skin_faces)
+            skin_faces->insert( quad );
+        }
+      }
+    }
+  } // end for each vertex
+  
+  return MB_SUCCESS;
+}
+
+} // namespace moab

Modified: MOAB/trunk/src/SparseTagCollection.cpp
===================================================================
--- MOAB/trunk/src/SparseTagCollection.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SparseTagCollection.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -31,10 +31,12 @@
 #include <algorithm>
 
 #include "SparseTagCollection.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include "TagCompare.hpp"
 #include "VarLenTag.hpp"
 
+namespace moab {
+
 SparseTagCollection::SparseTagCollection(int data_size)
 {
   mDataSize = data_size;
@@ -56,12 +58,12 @@
   mData.clear();
 }
 
-MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data)
+ErrorCode SparseTagCollection::set_data(const EntityHandle entity_handle, const void* data)
 {
   if (mDataSize == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  MBErrorCode ret_val = MB_TAG_NOT_FOUND;
+  ErrorCode ret_val = MB_TAG_NOT_FOUND;
 
 #ifdef HAVE_UNORDERED_MAP
   myMapType::iterator iterator = mData.find(entity_handle);
@@ -80,14 +82,14 @@
   {
     void* new_data = mAllocator.allocate(mDataSize);
     memcpy(new_data, data, mDataSize);
-    mData.insert(iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data));
+    mData.insert(iterator, std::pair<const EntityHandle,void*>(entity_handle, new_data));
     ret_val = MB_SUCCESS;
   }
 
   return ret_val;
 }
 
-MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, void* data)
+ErrorCode SparseTagCollection::get_data(const EntityHandle entity_handle, void* data)
 {
   if (mDataSize == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
@@ -101,7 +103,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data, int size)
+ErrorCode SparseTagCollection::set_data(const EntityHandle entity_handle, const void* data, int size)
 {
 #ifdef HAVE_UNORDERED_MAP
   myMapType::iterator iterator = mData.find(entity_handle);
@@ -119,7 +121,7 @@
     if (iterator == mData.end() || iterator->first != entity_handle) {
       void* new_data = mAllocator.allocate(sizeof(VarLenTag));
       new (new_data) VarLenTag;
-      iterator = mData.insert( iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data) );
+      iterator = mData.insert( iterator, std::pair<const EntityHandle,void*>(entity_handle, new_data) );
     }
     reinterpret_cast<VarLenTag*>(iterator->second)->set( data, size );
   }
@@ -129,7 +131,7 @@
   
     if (iterator == mData.end() || iterator->first != entity_handle) {
       void* new_data = mAllocator.allocate(mDataSize);
-      iterator = mData.insert( iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data) );
+      iterator = mData.insert( iterator, std::pair<const EntityHandle,void*>(entity_handle, new_data) );
     }
     memcpy( iterator->second, data, mDataSize);
   }
@@ -137,7 +139,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, const void*& data, int& size)
+ErrorCode SparseTagCollection::get_data(const EntityHandle entity_handle, const void*& data, int& size)
 {
   myMapType::iterator iter = mData.find(entity_handle);
 
@@ -158,7 +160,7 @@
 
 
 
-MBErrorCode SparseTagCollection::remove_data( const MBEntityHandle entity_handle )
+ErrorCode SparseTagCollection::remove_data( const EntityHandle entity_handle )
 {
   myMapType::iterator iterator = mData.find(entity_handle);
 
@@ -175,7 +177,7 @@
 
 
 //! get number of entities of type
-MBErrorCode SparseTagCollection::get_number_entities(MBEntityType type, int& num_entities)
+ErrorCode SparseTagCollection::get_number_entities(EntityType type, int& num_entities)
 {
   num_entities = 0;
   myMapType::iterator iter;
@@ -188,7 +190,7 @@
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagCollection::get_entities(MBEntityType type, MBRange &entities)
+ErrorCode SparseTagCollection::get_entities(EntityType type, Range &entities)
 {
   myMapType::iterator iter;
   for(iter = mData.begin(); iter != mData.end(); ++iter)
@@ -201,10 +203,10 @@
 
 
 //! gets all entity handles that match a type, tag and tag value
-MBErrorCode SparseTagCollection::get_entities_with_tag_value(
+ErrorCode SparseTagCollection::get_entities_with_tag_value(
                                                     const TagInfo& tag_info,
-                                                    MBEntityType type, 
-                                                    MBRange &entities, 
+                                                    EntityType type, 
+                                                    Range &entities, 
                                                     const void* tag_value,
                                                     int value_size)
 {
@@ -231,6 +233,7 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
 
 
 

Modified: MOAB/trunk/src/SparseTagCollection.hpp
===================================================================
--- MOAB/trunk/src/SparseTagCollection.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SparseTagCollection.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -49,11 +49,13 @@
 #endif
 #include <vector>
 
-#include "MBTypes.h"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "moab/Types.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 #include "TagInfo.hpp"
 
+namespace moab {
+
 //! allocator for tag data
 class SparseTagDataAllocator
 {
@@ -83,12 +85,12 @@
   //! set the tag data for an entity id
   //!\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called for 
   //!      variable-length tag.
-  MBErrorCode set_data(const MBEntityHandle entity_handle, const void* data);
+  ErrorCode set_data(const EntityHandle entity_handle, const void* data);
 
   //! get the tag data for an entity id
   //!\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called for 
   //!      variable-length tag.
-  MBErrorCode get_data(const MBEntityHandle entity_handle, void* data);
+  ErrorCode get_data(const EntityHandle entity_handle, void* data);
   
   //! set variable-length tag data for an entity id
   //!
@@ -96,36 +98,36 @@
   //!
   //!\NOTE If called with zero size for a variable-length tag, is equivalent
   //!      to remove_data().
-  MBErrorCode set_data(const MBEntityHandle entity_handle, const void* data, int length);
+  ErrorCode set_data(const EntityHandle entity_handle, const void* data, int length);
 
   //! get the variable-length data for an entity id
-  MBErrorCode get_data(const MBEntityHandle entity_handle, const void*& data, int& length);
+  ErrorCode get_data(const EntityHandle entity_handle, const void*& data, int& length);
 
   //! removes the data
-  MBErrorCode remove_data(const MBEntityHandle entity_handle);
+  ErrorCode remove_data(const EntityHandle entity_handle);
 
   //! get number of entities of type
-  MBErrorCode get_number_entities(MBEntityType type, int& num_entities);
+  ErrorCode get_number_entities(EntityType type, int& num_entities);
   
   //! get number of entities
   unsigned long get_number_entities()
     { return mData.size(); }
 
   //! gets all entity handles that match a type and tag
-  MBErrorCode get_entities(MBEntityType type, MBRange &entities);
+  ErrorCode get_entities(EntityType type, Range &entities);
 
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities(MBRange &entities) const;
+  ErrorCode get_entities(Range &entities) const;
 
   //! gets all entity handles that match a type, tag, tag_value
-  MBErrorCode get_entities_with_tag_value( const TagInfo& info,
-                                           MBEntityType type, 
-                                           MBRange &entities, 
+  ErrorCode get_entities_with_tag_value( const TagInfo& info,
+                                           EntityType type, 
+                                           Range &entities, 
                                            const void* tag_value,
                                            int value_size);
 
   //! if this collection contains this entity, return true, otherwise false
-  bool contains(const MBEntityHandle entity) const;
+  bool contains(const EntityHandle entity) const;
   
   int tag_size() const { return mDataSize; }
 
@@ -142,20 +144,20 @@
 
   //! map of entity id and tag data
 #ifdef HAVE_UNORDERED_MAP
-  typedef UNORDERED_MAP_NS::unordered_map<MBEntityHandle,void*> myMapType;
+  typedef UNORDERED_MAP_NS::unordered_map<EntityHandle,void*> myMapType;
 #else
-  typedef std::map<MBEntityHandle /*entity_handle*/ , void* /*data*/ > myMapType;
+  typedef std::map<EntityHandle /*entity_handle*/ , void* /*data*/ > myMapType;
 #endif
 
   myMapType mData;
 };
 
-inline bool SparseTagCollection::contains(const MBEntityHandle entity) const
+inline bool SparseTagCollection::contains(const EntityHandle entity) const
 {
   return (mData.find(entity) == mData.end() ? false : true);
 }
 
-inline MBErrorCode SparseTagCollection::get_entities(MBRange &entities) const 
+inline ErrorCode SparseTagCollection::get_entities(Range &entities) const 
 {
   for (myMapType::const_iterator mit = mData.begin(); mit != mData.end(); mit++) 
     entities.insert((*mit).first);
@@ -163,6 +165,7 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
 
 #endif //SPARSE_TAG_COLLECTION_HPP
 

Modified: MOAB/trunk/src/SparseTagSuperCollection.cpp
===================================================================
--- MOAB/trunk/src/SparseTagSuperCollection.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SparseTagSuperCollection.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -32,8 +32,10 @@
 
 #include "SparseTagSuperCollection.hpp"
 #include "SparseTagCollection.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 
+namespace moab {
+
 /*
   SparseTagSuperCollection functions -----------------------------
 */
@@ -60,7 +62,7 @@
   
 }
 
-MBErrorCode SparseTagSuperCollection::reserve_tag_id(int data_size, MBTagId tag_id)
+ErrorCode SparseTagSuperCollection::reserve_tag_id(int data_size, TagId tag_id)
 {
   if(data_size<=0 && data_size != MB_VARIABLE_LENGTH)
     return MB_FAILURE;
@@ -75,7 +77,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SparseTagSuperCollection::release_tag_id(MBTagId tag_id)
+ErrorCode SparseTagSuperCollection::release_tag_id(TagId tag_id)
 {
   if (tag_id >= mDataTags.size() || !mDataTags[tag_id])
     return MB_TAG_NOT_FOUND;
@@ -85,15 +87,15 @@
   return MB_SUCCESS;
 }
 
-int SparseTagSuperCollection::tag_size(const MBTagId tag_id) const
+int SparseTagSuperCollection::tag_size(const TagId tag_id) const
 {
   SparseTagCollection* coll = get_collection(tag_id);
   return coll ? coll->tag_size() : 0;
 }
 
 
-MBErrorCode SparseTagSuperCollection::set_data( MBTagId tag_handle,
-                                                const MBEntityHandle* handles,
+ErrorCode SparseTagSuperCollection::set_data( TagId tag_handle,
+                                                const EntityHandle* handles,
                                                 int num_handles,
                                                 const void* data )
 {
@@ -105,10 +107,10 @@
   if (length == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
   const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
-  const MBEntityHandle *const end = handles + num_handles;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ptr += length) {
+  const EntityHandle *const end = handles + num_handles;
+  for (const EntityHandle* i = handles; i != end; ++i, ptr += length) {
     rval = coll->set_data( *i, ptr );
     if (MB_SUCCESS != rval)
       result = rval;
@@ -117,8 +119,8 @@
   return result;
 }
 
-MBErrorCode SparseTagSuperCollection::set_data( MBTagId tag_handle,
-                                                const MBEntityHandle* handles,
+ErrorCode SparseTagSuperCollection::set_data( TagId tag_handle,
+                                                const EntityHandle* handles,
                                                 int num_handles,
                                                 void const* const* data_ptrs,
                                                 const int* lengths )
@@ -139,10 +141,10 @@
     length_step = 0;
   }
 
-  MBErrorCode rval, result = MB_SUCCESS;
-  const MBEntityHandle *const end = handles + num_handles;
+  ErrorCode rval, result = MB_SUCCESS;
+  const EntityHandle *const end = handles + num_handles;
   void const* const* ptr = data_ptrs;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ++ptr, lengths += length_step) {
+  for (const EntityHandle* i = handles; i != end; ++i, ++ptr, lengths += length_step) {
     rval = coll->set_data( *i, *ptr, *lengths );
     if (MB_SUCCESS != rval)
       result = rval;
@@ -152,8 +154,8 @@
 }
 
 
-MBErrorCode SparseTagSuperCollection::set_data( MBTagId tag_handle,
-                                                const MBRange& handles,
+ErrorCode SparseTagSuperCollection::set_data( TagId tag_handle,
+                                                const Range& handles,
                                                 const void* data )
 {
   SparseTagCollection* coll = get_collection(tag_handle);
@@ -164,9 +166,9 @@
   if (length == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
   const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
-  for (MBRange::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
+  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
     rval = coll->set_data( *i, ptr );
     if (MB_SUCCESS != rval)
       result = rval;
@@ -175,8 +177,8 @@
   return result;
 }
 
-MBErrorCode SparseTagSuperCollection::set_data( MBTagId tag_handle,
-                                                const MBRange& handles,
+ErrorCode SparseTagSuperCollection::set_data( TagId tag_handle,
+                                                const Range& handles,
                                                 void const* const* data_ptrs,
                                                 const int* lengths )
 {
@@ -196,9 +198,9 @@
     length_step = 0;
   }
 
-  MBErrorCode rval, result = MB_SUCCESS;
+  ErrorCode rval, result = MB_SUCCESS;
   void const* const* ptr = data_ptrs;
-  for (MBRange::const_iterator i = handles.begin(); i != handles.end(); ++i, ++ptr, lengths += length_step) {
+  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ++ptr, lengths += length_step) {
     rval = coll->set_data( *i, *ptr, *lengths );
     if (MB_SUCCESS != rval)
       result = rval;
@@ -208,8 +210,8 @@
 }
 
 
-MBErrorCode SparseTagSuperCollection::get_data( MBTagId tag_handle,
-                                                const MBEntityHandle* handles,
+ErrorCode SparseTagSuperCollection::get_data( TagId tag_handle,
+                                                const EntityHandle* handles,
                                                 int num_handles,
                                                 void* data,
                                                 const void* default_value ) const
@@ -222,10 +224,10 @@
   if (length == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  MBErrorCode rval;
+  ErrorCode rval;
   unsigned char* ptr = reinterpret_cast<unsigned char*>(data);
-  const MBEntityHandle *const end = handles + num_handles;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ptr += length) {
+  const EntityHandle *const end = handles + num_handles;
+  for (const EntityHandle* i = handles; i != end; ++i, ptr += length) {
     rval = coll->get_data( *i, ptr );
     if (MB_SUCCESS != rval) {
       if (MB_TAG_NOT_FOUND == rval && default_value) 
@@ -238,8 +240,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SparseTagSuperCollection::get_data( MBTagId tag_handle,
-                                                const MBEntityHandle* handles,
+ErrorCode SparseTagSuperCollection::get_data( TagId tag_handle,
+                                                const EntityHandle* handles,
                                                 int num_handles,
                                                 const void** data,
                                                 int* lengths,
@@ -261,9 +263,9 @@
   }
   
   
-  MBErrorCode rval, result = MB_SUCCESS;
-  const MBEntityHandle *const end = handles + num_handles;
-  for (const MBEntityHandle* i = handles; i != end; ++i, ++data, lengths += length_step) {
+  ErrorCode rval, result = MB_SUCCESS;
+  const EntityHandle *const end = handles + num_handles;
+  for (const EntityHandle* i = handles; i != end; ++i, ++data, lengths += length_step) {
     rval = coll->get_data( *i, *data, *lengths );
     if (MB_SUCCESS != rval) {
       if (MB_TAG_NOT_FOUND == rval && default_value) {
@@ -282,8 +284,8 @@
 }
 
 
-MBErrorCode SparseTagSuperCollection::get_data( MBTagId tag_handle,
-                                                const MBRange& handles,
+ErrorCode SparseTagSuperCollection::get_data( TagId tag_handle,
+                                                const Range& handles,
                                                 void* data,
                                                 const void* default_value ) const
 {
@@ -295,9 +297,9 @@
   if (length == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  MBErrorCode rval;
+  ErrorCode rval;
   unsigned char* ptr = reinterpret_cast<unsigned char*>(data);
-  for (MBRange::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
+  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
     rval = coll->get_data( *i, ptr );
     if (MB_SUCCESS != rval) {
       if (MB_TAG_NOT_FOUND == rval && default_value) 
@@ -310,8 +312,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode SparseTagSuperCollection::get_data( MBTagId tag_handle,
-                                                const MBRange& handles,
+ErrorCode SparseTagSuperCollection::get_data( TagId tag_handle,
+                                                const Range& handles,
                                                 const void** data,
                                                 int* lengths,
                                                 const void* default_value,
@@ -332,8 +334,8 @@
   }
   
   
-  MBErrorCode rval, result = MB_SUCCESS;
-  for (MBRange::const_iterator i = handles.begin(); i != handles.end(); ++i, ++data, lengths += length_step) {
+  ErrorCode rval, result = MB_SUCCESS;
+  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ++data, lengths += length_step) {
     rval = coll->get_data( *i, *data, *lengths );
     if (MB_SUCCESS != rval) {
       if (MB_TAG_NOT_FOUND == rval && default_value) {
@@ -351,8 +353,8 @@
   return result;
 }
 
-MBErrorCode SparseTagSuperCollection::remove_data( const MBTagId tag_handle, 
-    const MBEntityHandle entity_handle )
+ErrorCode SparseTagSuperCollection::remove_data( const TagId tag_handle, 
+    const EntityHandle entity_handle )
 {
   SparseTagCollection* coll = get_collection(tag_handle);
   return coll ? coll->remove_data( entity_handle ) : MB_TAG_NOT_FOUND;
@@ -360,44 +362,44 @@
 
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle, 
-                                                   MBRange &entities)
+ErrorCode SparseTagSuperCollection::get_entities(const TagId tag_handle, 
+                                                   Range &entities)
 {
   SparseTagCollection* coll = get_collection(tag_handle);
   return coll ? coll->get_entities(entities) : MB_TAG_NOT_FOUND;
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle, const MBEntityType type,
-                                                    MBRange &entities)
+ErrorCode SparseTagSuperCollection::get_entities(const TagId tag_handle, const EntityType type,
+                                                    Range &entities)
 {
   SparseTagCollection* coll = get_collection(tag_handle);
   return coll ? coll->get_entities(type, entities) : MB_TAG_NOT_FOUND;
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities(const MBRange &range,
-                                                    const MBTagId tag_handle, const MBEntityType type,
-                                                    MBRange &entities)
+ErrorCode SparseTagSuperCollection::get_entities(const Range &range,
+                                                    const TagId tag_handle, const EntityType type,
+                                                    Range &entities)
 {
   SparseTagCollection* coll = get_collection(tag_handle);
   if (!coll)
     return MB_TAG_NOT_FOUND;
   
-  MBRange dum_range;
-  MBErrorCode result = coll->get_entities(type, dum_range);
+  Range dum_range;
+  ErrorCode result = coll->get_entities(type, dum_range);
 
   std::set_intersection(dum_range.begin(), dum_range.end(),
                         range.begin(), range.end(),
-                        mb_range_inserter(entities));
+                        range_inserter(entities));
   
   return result;
 }
 
-MBErrorCode SparseTagSuperCollection::get_tags(const MBEntityHandle entity,
-                                                std::vector<MBTag> &all_tags)
+ErrorCode SparseTagSuperCollection::get_tags(const EntityHandle entity,
+                                                std::vector<Tag> &all_tags)
 {
-  for (MBTagId id = 0; id < mDataTags.size(); ++id)
+  for (TagId id = 0; id < mDataTags.size(); ++id)
     if (mDataTags[id] && mDataTags[id]->contains(entity))
       all_tags.push_back( TAG_HANDLE_FROM_ID( id, MB_TAG_SPARSE ) );
   
@@ -405,11 +407,11 @@
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
-                           const MBTagId tag_handle, 
+ErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
+                           const TagId tag_handle, 
                            const TagInfo& tag_info,
-                           const MBEntityType type,
-                           MBRange &entities, 
+                           const EntityType type,
+                           Range &entities, 
                            const void* tag_value,
                            int value_size)
 {
@@ -421,12 +423,12 @@
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
-                          const MBRange &range,
-                          const MBTagId tag_handle, 
+ErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
+                          const Range &range,
+                          const TagId tag_handle, 
                           const TagInfo& tag_info,
-                          const MBEntityType type,
-                          MBRange &entities, 
+                          const EntityType type,
+                          Range &entities, 
                           const void* tag_value,
                           int value_size)
 {
@@ -434,20 +436,20 @@
   if (!coll)
     return MB_TAG_NOT_FOUND;
 
-  MBRange dum_range;
-  MBErrorCode result = coll->get_entities_with_tag_value(
+  Range dum_range;
+  ErrorCode result = coll->get_entities_with_tag_value(
                            tag_info, type, dum_range, tag_value, value_size);
 
     // do this the hard way to preserve order in the vector
   std::set_intersection(range.begin(), range.end(),
                         dum_range.begin(), dum_range.end(),
-                        mb_range_inserter(entities));
+                        range_inserter(entities));
   
   return result;
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_number_entities(const MBTagId tag_handle, const MBEntityType type,
+ErrorCode SparseTagSuperCollection::get_number_entities(const TagId tag_handle, const EntityType type,
                                                            int& num_entities)
 {
   SparseTagCollection* coll = get_collection(tag_handle);
@@ -455,18 +457,18 @@
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_number_entities(const MBRange &range,
-                                                           const MBTagId tag_handle, const MBEntityType type,
+ErrorCode SparseTagSuperCollection::get_number_entities(const Range &range,
+                                                           const TagId tag_handle, const EntityType type,
                                                            int& num_entities)
 {
-  MBRange dum_range;
-  MBErrorCode result = get_entities(range, tag_handle, type, dum_range);
+  Range dum_range;
+  ErrorCode result = get_entities(range, tag_handle, type, dum_range);
   num_entities = dum_range.size();
   return result;
 }
 
 
-MBErrorCode SparseTagSuperCollection::get_memory_use( MBTagId tag_id,
+ErrorCode SparseTagSuperCollection::get_memory_use( TagId tag_id,
                                               unsigned long& total,
                                               unsigned long& per_entity )
 {
@@ -475,9 +477,9 @@
     return MB_TAG_NOT_FOUND;
 
     // 3*sizeof(void*)                      - std::map RB tree node
-    // sizeof(void*)*sizeof(MBEntityHandle) - data in std::map node
+    // sizeof(void*)*sizeof(EntityHandle) - data in std::map node
     // coll->tag_size()                     - the actual tag data
-  per_entity = 4*sizeof(void*)+sizeof(MBEntityHandle)+coll->tag_size();
+  per_entity = 4*sizeof(void*)+sizeof(EntityHandle)+coll->tag_size();
     
     // Count number of occupied slots in mDataTags vector
   unsigned num_coll =0;
@@ -494,5 +496,8 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
 
 
+
+

Modified: MOAB/trunk/src/SparseTagSuperCollection.hpp
===================================================================
--- MOAB/trunk/src/SparseTagSuperCollection.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SparseTagSuperCollection.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -42,13 +42,15 @@
 #include <map>
 #include <vector>
 
-#include "MBTypes.h"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "moab/Types.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 #include "TagInfo.hpp"
 
 #define get_collection( A ) ((A) < mDataTags.size() ? mDataTags[(A)] : 0)
 
+namespace moab {
+
 class SparseTagCollection;
 
 //! a collection of SparseTagCollections
@@ -64,19 +66,19 @@
   void reset_data();
 
   //! allocate new tag id
-  MBErrorCode reserve_tag_id(int data_size, MBTagId tag_id);
+  ErrorCode reserve_tag_id(int data_size, TagId tag_id);
 
-  //! releases an MBTagId
-  MBErrorCode release_tag_id(MBTagId tag_id);
+  //! releases an TagId
+  ErrorCode release_tag_id(TagId tag_id);
 
   //! size of data tag
-  int tag_size(const MBTagId tag_id) const;
+  int tag_size(const TagId tag_id) const;
 
     /** Set fixed-length tag values.
      *\NOTE Will fail for variable-length tag data.
      */
-  MBErrorCode set_data( MBTagId tag_handle,
-                        const MBEntityHandle* handles,
+  ErrorCode set_data( TagId tag_handle,
+                        const EntityHandle* handles,
                         int num_handles,
                         const void* data );
 
@@ -87,20 +89,20 @@
      *\param values      Array of pointers to tag values, one pointer for each handle
      *\param lengths     Length of each tag value.  Ignored for fixed-length tags.
      */
-  MBErrorCode set_data( MBTagId tag_handle,
-                        const MBEntityHandle* handles,
+  ErrorCode set_data( TagId tag_handle,
+                        const EntityHandle* handles,
                         int num_handles,
                         void const* const* data_pointers,
                         const int* lengths = 0 );
 
-    /** Set fixed-length tag value for an MBRange of entities
+    /** Set fixed-length tag value for an Range of entities
      *\NOTE Will fail for variable-length tag data
      */
-  MBErrorCode set_data( MBTagId tag_handle,
-                        const MBRange& handles,
+  ErrorCode set_data( TagId tag_handle,
+                        const Range& handles,
                         const void* data );
 
-    /** Set tag data for an MBRange of entities.
+    /** Set tag data for an Range of entities.
      *
      *\param tag_id  The tag
      *\param handles The entities
@@ -110,8 +112,8 @@
      *               length of the tag value for each entity.  Ingored
      *               for fixed-length tags.
      */
-  MBErrorCode set_data( MBTagId tag_handle,
-                        const MBRange& handles,
+  ErrorCode set_data( TagId tag_handle,
+                        const Range& handles,
                         void const* const* data_pointers,
                         const int* lengths = 0 );
   
@@ -119,8 +121,8 @@
      *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
      *      for variable-length tag.
      */
-  MBErrorCode get_data( MBTagId tag_handle,
-                        const MBEntityHandle* handles,
+  ErrorCode get_data( TagId tag_handle,
+                        const EntityHandle* handles,
                         int num_handles,
                         void* data,
                         const void* default_value ) const;
@@ -135,24 +137,24 @@
      *\param default_value_length  Length of default tag value.  Ingored for
      *                   fixed-length tags.
      */
-  MBErrorCode get_data( MBTagId tag_handle,
-                        const MBEntityHandle* handles,
+  ErrorCode get_data( TagId tag_handle,
+                        const EntityHandle* handles,
                         int num_handles,
                         const void** data,
                         int* lengths,
                         const void* default_value,
                         int default_value_length ) const;
   
-    /** Get fixed-length tag value for an MBRange of entities
+    /** Get fixed-length tag value for an Range of entities
      *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
      *      for variable-length tag.
      */
-  MBErrorCode get_data( MBTagId tag_handle,
-                        const MBRange& handles,
+  ErrorCode get_data( TagId tag_handle,
+                        const Range& handles,
                         void* data,
                         const void* default_value ) const;
   
-    /** Get pointers to tag data for an MBRange of entities.
+    /** Get pointers to tag data for an Range of entities.
      *
      *\param tag_id   The tag.
      *\param handles  The entities.
@@ -166,58 +168,58 @@
      *\param default_value The default value for the tag.
      *\param default_value_length The length of the default tag value.
      */
-  MBErrorCode get_data( MBTagId tag_handle,
-                        const MBRange& handles,
+  ErrorCode get_data( TagId tag_handle,
+                        const Range& handles,
                         const void** data,
                         int* lengths,
                         const void* default_value,
                         int default_value_length ) const;
 
   //! removes data
-  MBErrorCode remove_data(const MBTagId tag_handle, const MBEntityHandle entity_handle);
+  ErrorCode remove_data(const TagId tag_handle, const EntityHandle entity_handle);
 
   //! gets all entity handles that match a type and tag
-  MBErrorCode get_entities(const MBTagId tag_handle, MBRange &entities);
+  ErrorCode get_entities(const TagId tag_handle, Range &entities);
 
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities(const MBTagId tag_handle, const MBEntityType type,
-                            MBRange &entities);
+  ErrorCode get_entities(const TagId tag_handle, const EntityType type,
+                            Range &entities);
 
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities(const MBRange &range,
-                            const MBTagId tag_handle, const MBEntityType type,
-                            MBRange &entities);
+  ErrorCode get_entities(const Range &range,
+                            const TagId tag_handle, const EntityType type,
+                            Range &entities);
 
   //! gets all tags on a given entity handle
-  MBErrorCode get_tags(const MBEntityHandle entity,
-                       std::vector<MBTag> &all_tags);
+  ErrorCode get_tags(const EntityHandle entity,
+                       std::vector<Tag> &all_tags);
   
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities_with_tag_value( const MBTagId tag_handle, 
+  ErrorCode get_entities_with_tag_value( const TagId tag_handle, 
                                            const TagInfo& tag_info,
-                                           const MBEntityType type,
-                                           MBRange &entities,
+                                           const EntityType type,
+                                           Range &entities,
                                            const void* tag_value,
                                            int value_size);
 
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities_with_tag_value( const MBRange &range,
-                                           const MBTagId tag_handle, 
+  ErrorCode get_entities_with_tag_value( const Range &range,
+                                           const TagId tag_handle, 
                                            const TagInfo& tag_info,
-                                           const MBEntityType type,
-                                           MBRange &entities,
+                                           const EntityType type,
+                                           Range &entities,
                                            const void* tag_value,
                                            int value_size);
 
   //! gets the number of entities that match a tag
-  MBErrorCode get_number_entities(const MBTagId tag_handle, const MBEntityType type, int& num_ent);
+  ErrorCode get_number_entities(const TagId tag_handle, const EntityType type, int& num_ent);
 
 
   //! gets the number of entities that match a tag
-  MBErrorCode get_number_entities(const MBRange &range,
-                                   const MBTagId tag_handle, const MBEntityType type, int& num_ent);
+  ErrorCode get_number_entities(const Range &range,
+                                   const TagId tag_handle, const EntityType type, int& num_ent);
 
-  MBErrorCode get_memory_use( MBTagId tag_id, 
+  ErrorCode get_memory_use( TagId tag_id, 
                               unsigned long& total,
                               unsigned long& per_entity );
 
@@ -226,6 +228,7 @@
   std::vector<SparseTagCollection*> mDataTags;
 };
 
+} // namespace moab
 
 #endif //SPARSE_TAG_SUPER_COLLECTION_HPP
 

Modified: MOAB/trunk/src/StructuredElementSeq.cpp
===================================================================
--- MOAB/trunk/src/StructuredElementSeq.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/StructuredElementSeq.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,12 +16,14 @@
 #include "StructuredElementSeq.hpp"
 #include "ScdVertexData.hpp"
 #include "ScdElementData.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 
-StructuredElementSeq::StructuredElementSeq(MBEntityHandle start_handle,
+namespace moab {
+
+StructuredElementSeq::StructuredElementSeq(EntityHandle start_handle,
                              const int imin, const int jmin, const int kmin,
                              const int imax, const int jmax, const int kmax) 
   : ElementSequence( start_handle, 
@@ -40,24 +42,24 @@
 {
 }
 
-MBErrorCode StructuredElementSeq::get_connectivity( 
-                                        MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+ErrorCode StructuredElementSeq::get_connectivity( 
+                                        EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool /*topological*/ ) const
 {
   int i, j, k;
-  MBErrorCode rval = get_params( handle, i, j, k );
+  ErrorCode rval = get_params( handle, i, j, k );
   if (MB_SUCCESS == rval)
     rval = get_params_connectivity( i, j, k, connect );
   return rval;
 }
 
-MBErrorCode StructuredElementSeq::get_connectivity( 
-                                        MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+ErrorCode StructuredElementSeq::get_connectivity( 
+                                        EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topo,
-                                        std::vector<MBEntityHandle>* storage
+                                        std::vector<EntityHandle>* storage
                                         ) const
 {
   if (!storage) {
@@ -67,30 +69,30 @@
   }
   
   storage->clear();
-  MBErrorCode rval = get_connectivity( handle, *storage, topo );
+  ErrorCode rval = get_connectivity( handle, *storage, topo );
   connect = &(*storage)[0];
   connect_length = storage->size();
   return rval;
 }
 
-MBErrorCode StructuredElementSeq::set_connectivity( 
-                                        MBEntityHandle,
-                                        MBEntityHandle const*,
+ErrorCode StructuredElementSeq::set_connectivity( 
+                                        EntityHandle,
+                                        EntityHandle const*,
                                         int )
 {
   return MB_NOT_IMPLEMENTED;
 }
 
-MBEntityHandle* StructuredElementSeq::get_connectivity_array()
+EntityHandle* StructuredElementSeq::get_connectivity_array()
   { return 0; }
 
 int StructuredElementSeq::values_per_entity() const
   { return -1; } // never reuse freed handles for structured elements 
 
-EntitySequence* StructuredElementSeq::split( MBEntityHandle here )
+EntitySequence* StructuredElementSeq::split( EntityHandle here )
   { return new StructuredElementSeq( *this, here ); }
 
-SequenceData* StructuredElementSeq::create_data_subset( MBEntityHandle, MBEntityHandle ) const
+SequenceData* StructuredElementSeq::create_data_subset( EntityHandle, EntityHandle ) const
   { return 0; }
 
 void StructuredElementSeq::get_const_memory_use( unsigned long& bytes_per_entity,
@@ -99,3 +101,5 @@
   sequence_size = sizeof(*this);
   bytes_per_entity = sdata()->get_memory_use() / sdata()->size();
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/StructuredElementSeq.hpp
===================================================================
--- MOAB/trunk/src/StructuredElementSeq.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/StructuredElementSeq.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -30,13 +30,15 @@
 #include "ElementSequence.hpp"
 #include "ScdElementData.hpp"
 
+namespace moab {
+
 class StructuredElementSeq : public ElementSequence
 {
 public:
 
     //! constructor
   StructuredElementSeq(
-                MBEntityHandle start_handle,
+                EntityHandle start_handle,
                 const int imin, const int jmin, const int kmin,
                 const int imax, const int jmax, const int kmax);
   
@@ -48,19 +50,19 @@
     { return reinterpret_cast<const ScdElementData*>(data()); }
 
     //! get handle of vertex at i, j, k
-  MBEntityHandle get_vertex(const int i, const int j, const int k) const
+  EntityHandle get_vertex(const int i, const int j, const int k) const
     { return get_vertex( HomCoord(i,j,k) ); }
   
     //! get handle of vertex at homogeneous coords
-  inline MBEntityHandle get_vertex(const HomCoord &coords) const
+  inline EntityHandle get_vertex(const HomCoord &coords) const
     { return sdata()->get_vertex(coords); }
   
     //! get handle of element at i, j, k
-  MBEntityHandle get_element(const int i, const int j, const int k) const
+  EntityHandle get_element(const int i, const int j, const int k) const
     { return sdata()->get_element( i, j, k ); }
   
     //! get handle of element at homogeneous coords
-  MBEntityHandle get_element(const HomCoord &coords) const
+  EntityHandle get_element(const HomCoord &coords) const
     { return sdata()->get_element( coords.i(), coords.j(), coords.k() ); }
   
     //! get min params for this element
@@ -84,7 +86,7 @@
     { sdata()->param_extents( di, dj, dk ); }
 
     //! given a handle, get the corresponding parameters
-  MBErrorCode get_params(const MBEntityHandle ehandle,
+  ErrorCode get_params(const EntityHandle ehandle,
                           int &i, int &j, int &k) const
     { return sdata()->get_params( ehandle, i, j, k ); }
   
@@ -108,29 +110,29 @@
     { return sdata()->contains(coords); }
 
     //! get connectivity of an entity given entity's parameters
-  MBErrorCode get_params_connectivity(const int i, const int j, const int k,
-                                std::vector<MBEntityHandle>& connectivity) const
+  ErrorCode get_params_connectivity(const int i, const int j, const int k,
+                                std::vector<EntityHandle>& connectivity) const
     { return sdata()->get_params_connectivity( i, j, k, connectivity ); }
   
   
     /***************** Methods from ElementSequence *****************/
 
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool topological = false ) const;
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topological = false,
-                                        std::vector<MBEntityHandle>* storage = 0
+                                        std::vector<EntityHandle>* storage = 0
                                        ) const;
 
-  virtual MBErrorCode set_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const* connect,
+  virtual ErrorCode set_connectivity( EntityHandle handle,
+                                        EntityHandle const* connect,
                                         int connect_length );
   
-  virtual MBEntityHandle* get_connectivity_array();
+  virtual EntityHandle* get_connectivity_array();
   
   
     /***************** Methods from EntitySequence *****************/
@@ -141,18 +143,20 @@
      */
   virtual int values_per_entity() const;
 
-  virtual EntitySequence* split( MBEntityHandle here );
+  virtual EntitySequence* split( EntityHandle here );
 
-  virtual SequenceData* create_data_subset( MBEntityHandle start_handle,
-                                            MBEntityHandle end_handle ) const;
+  virtual SequenceData* create_data_subset( EntityHandle start_handle,
+                                            EntityHandle end_handle ) const;
 
   virtual void get_const_memory_use( unsigned long& bytes_per_entity,
                                      unsigned long& size_of_sequence ) const;
 
 protected:
-  StructuredElementSeq( StructuredElementSeq& split_from, MBEntityHandle here )
+  StructuredElementSeq( StructuredElementSeq& split_from, EntityHandle here )
     : ElementSequence( split_from, here )
     {}
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/SweptElementData.cpp
===================================================================
--- MOAB/trunk/src/SweptElementData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptElementData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,13 +15,15 @@
 
 #include "SweptElementData.hpp"
 #include "SweptVertexData.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 #include <assert.h>
 
-MBEntityID SweptElementData::calc_num_entities(MBEntityHandle start_handle,
+namespace moab {
+
+EntityID SweptElementData::calc_num_entities(EntityHandle start_handle,
                                 int irange, int jrange, int krange)
 {
   size_t result = 1;
@@ -35,7 +37,7 @@
 }
 
 SweptElementData::SweptElementData(
-                             MBEntityHandle start_handle,
+                             EntityHandle start_handle,
                              const int imin, const int jmin, const int kmin,
                              const int imax, const int jmax, const int kmax,
 			     const int* Cq ) 
@@ -136,8 +138,8 @@
 }
 
 
-SequenceData* SweptElementData::subset( MBEntityHandle /*start*/, 
-                                      MBEntityHandle /*end*/,
+SequenceData* SweptElementData::subset( EntityHandle /*start*/, 
+                                      EntityHandle /*end*/,
                                       const int* /*sequence_data_sizes*/,
                                       const int* /*tag_data_sizes*/ ) const
 {
@@ -148,3 +150,5 @@
 {
   return sizeof(*this) + vertexSeqRefs.capacity() * sizeof(VertexDataRef);
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/SweptElementData.hpp
===================================================================
--- MOAB/trunk/src/SweptElementData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptElementData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -28,15 +28,17 @@
 // handles associated with the element are each contiguous.
 
 #include "SequenceData.hpp"
-#include "HomXform.hpp"
-#include "MBCN.hpp"
+#include "moab/HomXform.hpp"
+#include "moab/MBCN.hpp"
 #include "SweptVertexData.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 
 #include <vector>
 #include <algorithm>
 
+namespace moab {
+
 class SweptElementData : public SequenceData
 {
 
@@ -78,7 +80,7 @@
 public:
 
     //! constructor
-  SweptElementData( MBEntityHandle start_handle,
+  SweptElementData( EntityHandle start_handle,
                   const int imin, const int jmin, const int kmin,
 		    const int imax, const int jmax, const int kmax,
 		  const int* Cq );
@@ -86,12 +88,12 @@
   virtual ~SweptElementData();
   
     //! get handle of vertex at homogeneous coords
-  inline MBEntityHandle get_vertex(const HomCoord &coords) const;
-  inline MBEntityHandle get_vertex(int i, int j, int k) const
+  inline EntityHandle get_vertex(const HomCoord &coords) const;
+  inline EntityHandle get_vertex(int i, int j, int k) const
     { return get_vertex(HomCoord(i,j,k)); }
   
     //! get handle of element at i, j, k
-  MBEntityHandle get_element(const int i, const int j, const int k) const;
+  EntityHandle get_element(const int i, const int j, const int k) const;
   
     //! get min params for this element
   const HomCoord &min_params() const;
@@ -103,7 +105,7 @@
   void param_extents(int &di, int &dj, int &dk) const;
 
     //! given a handle, get the corresponding parameters
-  MBErrorCode get_params(const MBEntityHandle ehandle,
+  ErrorCode get_params(const EntityHandle ehandle,
                           int &i, int &j, int &k) const;
   
     //! convenience functions for parameter extents
@@ -122,15 +124,15 @@
   inline bool contains(const HomCoord &coords) const;
 
     //! get connectivity of an entity given entity's parameters
-  inline MBErrorCode get_params_connectivity(const int i, const int j, const int k,
-                                       std::vector<MBEntityHandle>& connectivity) const;
+  inline ErrorCode get_params_connectivity(const int i, const int j, const int k,
+                                       std::vector<EntityHandle>& connectivity) const;
   
     //! add a vertex seq ref to this element sequence;
     //! if bb_input is true, bounding box (in eseq-local coords) of vseq being added 
     //! is input in bb_min and bb_max (allows partial sharing of vseq rather than the whole
     //! vseq); if it's false, the whole vseq is referenced and the eseq-local coordinates
     //! is computed from the transformed bounding box of the vseq
-  MBErrorCode add_vsequence(SweptVertexData *vseq, 
+  ErrorCode add_vsequence(SweptVertexData *vseq, 
                              const HomCoord &p1, const HomCoord &q1,
                              const HomCoord &p2, const HomCoord &q2,
                              const HomCoord &p3, const HomCoord &q3,
@@ -139,12 +141,12 @@
                              const HomCoord &bb_max = HomCoord::unitv[0]);
 
 
-  SequenceData* subset( MBEntityHandle start, 
-                        MBEntityHandle end,
+  SequenceData* subset( EntityHandle start, 
+                        EntityHandle end,
                         const int* sequence_data_sizes,
                         const int* tag_data_sizes ) const;
   
-  static MBEntityID calc_num_entities( MBEntityHandle start_handle,
+  static EntityID calc_num_entities( EntityHandle start_handle,
                                        int irange,
                                        int jrange,
                                        int krange );
@@ -152,7 +154,7 @@
   unsigned long get_memory_use() const;
 };
 
-inline MBEntityHandle SweptElementData::get_element(const int i, const int j, const int k) const
+inline EntityHandle SweptElementData::get_element(const int i, const int j, const int k) const
 {
   return start_handle() + (i-i_min()) + (j-j_min())*dIJKm1[0] + (k-k_min())*dIJKm1[0]*dIJKm1[1];
 }
@@ -175,7 +177,7 @@
   dk = dIJK[2];
 }
 
-inline MBErrorCode SweptElementData::get_params(const MBEntityHandle ehandle,
+inline ErrorCode SweptElementData::get_params(const EntityHandle ehandle,
                                               int &i, int &j, int &k) const
 {
   if (TYPE_FROM_HANDLE(ehandle) != TYPE_FROM_HANDLE(start_handle())) return MB_FAILURE;
@@ -219,7 +221,7 @@
   minmax[1] = HomCoord(this_max); 
 }
 
-inline MBEntityHandle SweptElementData::get_vertex(const HomCoord &coords) const
+inline EntityHandle SweptElementData::get_vertex(const HomCoord &coords) const
 {
   assert(boundary_complete());
    for (std::vector<VertexDataRef>::const_iterator it = vertexSeqRefs.begin();
@@ -237,7 +239,7 @@
    return 0;
 }
 
-inline MBErrorCode SweptElementData::add_vsequence(SweptVertexData *vseq, 
+inline ErrorCode SweptElementData::add_vsequence(SweptVertexData *vseq, 
                                                  const HomCoord &p1, const HomCoord &q1,
                                                  const HomCoord &p2, const HomCoord &q2, 
                                                  const HomCoord &p3, const HomCoord &q3,
@@ -286,8 +288,8 @@
   return MB_SUCCESS;
 }
 
-inline MBErrorCode SweptElementData::get_params_connectivity(const int i, const int j, const int k,
-                                                           std::vector<MBEntityHandle>& connectivity) const
+inline ErrorCode SweptElementData::get_params_connectivity(const int i, const int j, const int k,
+                                                           std::vector<EntityHandle>& connectivity) const
 {
   if (contains(HomCoord(i, j, k)) == false) return MB_FAILURE;
   
@@ -304,4 +306,6 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/SweptElementSeq.cpp
===================================================================
--- MOAB/trunk/src/SweptElementSeq.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptElementSeq.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,12 +16,14 @@
 #include "SweptElementSeq.hpp"
 #include "SweptVertexData.hpp"
 #include "SweptElementData.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 
-SweptElementSeq::SweptElementSeq(MBEntityHandle start_handle,
+namespace moab {
+
+SweptElementSeq::SweptElementSeq(EntityHandle start_handle,
                                  const int imin, const int jmin, const int kmin,
 				 const int imax, const int jmax, const int kmax,
                                  const int* Cq ) 
@@ -42,24 +44,24 @@
 {
 }
 
-MBErrorCode SweptElementSeq::get_connectivity( 
-                                        MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+ErrorCode SweptElementSeq::get_connectivity( 
+                                        EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool /*topological*/ ) const
 {
   int i, j, k;
-  MBErrorCode rval = get_params( handle, i, j, k );
+  ErrorCode rval = get_params( handle, i, j, k );
   if (MB_SUCCESS == rval)
     rval = get_params_connectivity( i, j, k, connect );
   return rval;
 }
 
-MBErrorCode SweptElementSeq::get_connectivity( 
-                                        MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+ErrorCode SweptElementSeq::get_connectivity( 
+                                        EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topo,
-                                        std::vector<MBEntityHandle>* storage
+                                        std::vector<EntityHandle>* storage
                                         ) const
 {
   if (!storage) {
@@ -69,30 +71,30 @@
   }
   
   storage->clear();
-  MBErrorCode rval = get_connectivity( handle, *storage, topo );
+  ErrorCode rval = get_connectivity( handle, *storage, topo );
   connect = &(*storage)[0];
   connect_length = storage->size();
   return rval;
 }
 
-MBErrorCode SweptElementSeq::set_connectivity( 
-                                        MBEntityHandle,
-                                        MBEntityHandle const*,
+ErrorCode SweptElementSeq::set_connectivity( 
+                                        EntityHandle,
+                                        EntityHandle const*,
                                         int )
 {
   return MB_NOT_IMPLEMENTED;
 }
 
-MBEntityHandle* SweptElementSeq::get_connectivity_array()
+EntityHandle* SweptElementSeq::get_connectivity_array()
   { return 0; }
 
 int SweptElementSeq::values_per_entity() const
   { return -1; } // never reuse freed handles for swept elements 
 
-EntitySequence* SweptElementSeq::split( MBEntityHandle here )
+EntitySequence* SweptElementSeq::split( EntityHandle here )
   { return new SweptElementSeq( *this, here ); }
 
-SequenceData* SweptElementSeq::create_data_subset( MBEntityHandle, MBEntityHandle ) const
+SequenceData* SweptElementSeq::create_data_subset( EntityHandle, EntityHandle ) const
   { return 0; }
 
 void SweptElementSeq::get_const_memory_use( unsigned long& bytes_per_entity,
@@ -101,3 +103,5 @@
   sequence_size = sizeof(*this);
 //  bytes_per_entity = sdata()->get_memory_use() / sdata()->size();
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/SweptElementSeq.hpp
===================================================================
--- MOAB/trunk/src/SweptElementSeq.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptElementSeq.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,13 +25,15 @@
 #include "ElementSequence.hpp"
 #include "ScdElementData.hpp"
 
+namespace moab {
+
 class SweptElementSeq : public ElementSequence
 {
 public:
 
     //! constructor
   SweptElementSeq(
-		  MBEntityHandle start_handle,
+		  EntityHandle start_handle,
 		  const int imin, const int jmin, const int kmin,
 		  const int imax, const int jmax, const int kmax,
 		  const int* Cq );
@@ -44,19 +46,19 @@
   { return reinterpret_cast<const ScdElementData*>(data()); } 
  
   //! get handle of vertex at i, j, k 
-  MBEntityHandle get_vertex(const int i, const int j, const int k) const 
+  EntityHandle get_vertex(const int i, const int j, const int k) const 
   { return get_vertex( HomCoord(i,j,k) ); } 
    
   //! get handle of vertex at homogeneous coords 
-  inline MBEntityHandle get_vertex(const HomCoord &coords) const 
+  inline EntityHandle get_vertex(const HomCoord &coords) const 
   { return sdata()->get_vertex(coords); } 
    
   //! get handle of element at i, j, k 
-  MBEntityHandle get_element(const int i, const int j, const int k) const 
+  EntityHandle get_element(const int i, const int j, const int k) const 
   { return sdata()->get_element( i, j, k ); } 
    
   //! get handle of element at homogeneous coords 
-  MBEntityHandle get_element(const HomCoord &coords) const 
+  EntityHandle get_element(const HomCoord &coords) const 
   { return sdata()->get_element( coords.i(), coords.j(), coords.k() ); } 
    
   //! get min params for this element 
@@ -80,7 +82,7 @@
   { sdata()->param_extents( di, dj, dk ); } 
  
   //! given a handle, get the corresponding parameters 
-  MBErrorCode get_params(const MBEntityHandle ehandle, 
+  ErrorCode get_params(const EntityHandle ehandle, 
                          int &i, int &j, int &k) const 
   { return sdata()->get_params( ehandle, i, j, k ); } 
    
@@ -104,28 +106,28 @@
   { return sdata()->contains(coords); } 
  
   //! get connectivity of an entity given entity's parameters 
-  MBErrorCode get_params_connectivity(const int i, const int j, const int k, 
-                                      std::vector<MBEntityHandle>& connectivity) const 
+  ErrorCode get_params_connectivity(const int i, const int j, const int k, 
+                                      std::vector<EntityHandle>& connectivity) const 
   { return sdata()->get_params_connectivity( i, j, k, connectivity ); } 
    
     /***************** Methods from ElementSeq *****************/
 
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool topological = false ) const;
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topological = false,
-                                        std::vector<MBEntityHandle>* storage = 0
+                                        std::vector<EntityHandle>* storage = 0
                                        ) const;
 
-  virtual MBErrorCode set_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const* connect,
+  virtual ErrorCode set_connectivity( EntityHandle handle,
+                                        EntityHandle const* connect,
                                         int connect_length );
   
-  virtual MBEntityHandle* get_connectivity_array();
+  virtual EntityHandle* get_connectivity_array();
  
    /***************** Methods from EntitySequence *****************/
 
@@ -135,18 +137,20 @@
      */
   virtual int values_per_entity() const;
 
-  virtual EntitySequence* split( MBEntityHandle here );
+  virtual EntitySequence* split( EntityHandle here );
 
-  virtual SequenceData* create_data_subset( MBEntityHandle start_handle,
-                                            MBEntityHandle end_handle ) const;
+  virtual SequenceData* create_data_subset( EntityHandle start_handle,
+                                            EntityHandle end_handle ) const;
 
   virtual void get_const_memory_use( unsigned long& bytes_per_entity,
                                      unsigned long& size_of_sequence ) const;
 
 protected:
-  SweptElementSeq( SweptElementSeq& split_from, MBEntityHandle here )
+  SweptElementSeq( SweptElementSeq& split_from, EntityHandle here )
     : ElementSequence( split_from, here )
     {}
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/SweptVertexData.cpp
===================================================================
--- MOAB/trunk/src/SweptVertexData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptVertexData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,8 +16,10 @@
 #include "SweptVertexData.hpp"
 #include <assert.h>
 
+namespace moab {
+
     //! constructor
-SweptVertexData::SweptVertexData(const MBEntityHandle start_vertex, 
+SweptVertexData::SweptVertexData(const EntityHandle start_vertex, 
                              const int imin, const int jmin, const int kmin,
                              const int imax, const int jmax, const int kmax) 
     : SequenceData( 3, start_vertex, 
@@ -40,10 +42,12 @@
   create_sequence_data( 2, sizeof(double) );
 }
 
-SequenceData* SweptVertexData::subset( MBEntityHandle /*start*/, 
-                                     MBEntityHandle /*end*/,
+SequenceData* SweptVertexData::subset( EntityHandle /*start*/, 
+                                     EntityHandle /*end*/,
                                      const int* /*sequence_data_sizes*/,
                                      const int* /*tag_data_sizes*/ ) const
 {
   return 0;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/SweptVertexData.hpp
===================================================================
--- MOAB/trunk/src/SweptVertexData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/SweptVertexData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,8 +25,10 @@
 // the parametric space used to address those vertices.
 
 #include "SequenceData.hpp"
-#include "HomXform.hpp"
+#include "moab/HomXform.hpp"
 
+namespace moab {
+
 class SweptVertexData : public SequenceData
 {
 
@@ -46,21 +48,21 @@
 public:
 
     //! constructor
-  SweptVertexData(const MBEntityHandle start_vertex, 
+  SweptVertexData(const EntityHandle start_vertex, 
                 const int imin, const int jmin, const int kmin,
                 const int imax, const int jmax, const int kmax) ;
   
   virtual ~SweptVertexData() {};
 
     //! get handle of vertex at i, j, k
-  MBEntityHandle get_vertex(const int i, const int j, const int k) const;
+  EntityHandle get_vertex(const int i, const int j, const int k) const;
 
     //! get handle of vertex at homogeneous coordinates
-  MBEntityHandle get_vertex(const HomCoord &coords) const;
+  EntityHandle get_vertex(const HomCoord &coords) const;
 
     //! get the parameters of a given handle; return MB_FAILURE if vhandle not in this
     //! sequence
-  MBErrorCode get_params(const MBEntityHandle vhandle,
+  ErrorCode get_params(const EntityHandle vhandle,
                           int &i, int &j, int &k) const;
   
     //! get min params for this vertex
@@ -90,25 +92,25 @@
   bool contains(const HomCoord &coords) const;
   bool contains(const int i, const int j, const int k) const;
 
-  SequenceData* subset( MBEntityHandle start, 
-                        MBEntityHandle end,
+  SequenceData* subset( EntityHandle start, 
+                        EntityHandle end,
                         const int* sequence_data_sizes,
                         const int* tag_data_sizes ) const;
 };
 
-inline MBEntityHandle SweptVertexData::get_vertex(const int i, const int j, 
+inline EntityHandle SweptVertexData::get_vertex(const int i, const int j, 
                                                 const int k) const
 {
   return start_handle() + (i-i_min()) + (j-j_min())*dIJK[0] + 
     (k-k_min())*dIJK[0]*dIJK[1];
 }
 
-inline MBEntityHandle SweptVertexData::get_vertex(const HomCoord &coords) const
+inline EntityHandle SweptVertexData::get_vertex(const HomCoord &coords) const
 {
   return get_vertex(coords.hom_coord()[0], coords.hom_coord()[1], coords.hom_coord()[2]);
 }
 
-inline MBErrorCode SweptVertexData::get_params(const MBEntityHandle vhandle,
+inline ErrorCode SweptVertexData::get_params(const EntityHandle vhandle,
                                              int &i, int &j, int &k) const
 {
   if (TYPE_FROM_HANDLE(vhandle) != MBVERTEX) return MB_FAILURE;
@@ -173,4 +175,6 @@
   return contains(HomCoord(i, j, k));
 }
 
+} // namespace moab
+
 #endif

Copied: MOAB/trunk/src/SysUtil.cpp (from rev 3583, MOAB/trunk/src/MBSysUtil.cpp)
===================================================================
--- MOAB/trunk/src/SysUtil.cpp	                        (rev 0)
+++ MOAB/trunk/src/SysUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,178 @@
+#include "SysUtil.hpp"
+
+#include <fstream>
+#include <algorithm>
+#include <assert.h>
+
+#include "moab/EntityHandle.hpp"
+
+namespace moab {
+
+namespace SysUtil
+{
+
+
+void setmem( void* mem, const void* value, unsigned value_size, size_t num_elem )
+{
+  if (!num_elem)
+    return;
+  
+  char* array = reinterpret_cast<char*>(mem);
+  memcpy( array, value, value_size );
+  size_t count;
+  for (count = 1; count*2 < num_elem; count *= 2)
+    memcpy( array + count * value_size, array, count * value_size );
+  memcpy( array + count * value_size, array, (num_elem - count) * value_size );
+}
+    
+
+long filesize( FILE* filp )
+{
+  long curr_pos = ftell( filp );
+  if (fseek( filp, 0, SEEK_END ))
+    return -1;
+  
+  long length = ftell( filp );
+  if (fseek( filp, curr_pos, SEEK_SET))
+  {
+    assert(0); 
+    return -2;
+  }
+  
+  return length;
+}
+
+
+long filesize( std::ifstream& str )
+{
+  std::istream::pos_type curr_pos = str.tellg();
+  if (!str.seekg( 0, std::ios_base::end ))
+    return -1;
+  
+  long length = static_cast<long>(str.tellg());
+  if (!str.seekg( curr_pos, std::ios_base::beg ))
+  {
+    assert(0);
+    return -2;
+  }
+  
+  return length;
+}
+
+
+void byteswap( void* data, unsigned value_size, size_t num_elem )
+{
+  char* mem = reinterpret_cast<char*>(data);
+  char* const end = mem + value_size * num_elem;
+  for ( ; mem < end; mem += value_size) {
+    unsigned i = 0, j = value_size - 1;
+    while (i < j)
+      std::swap( mem[i++], mem[j--] );
+  }
+}
+
+inline static uint16_t swap_bytes( uint16_t value )
+{
+  return (value >> 8) | (value << 8);
+}
+
+inline static uint32_t swap_bytes( uint32_t value )
+{
+  return ((value /*& (uint32_t)0xFF000000*/) >> 24) |
+         ((value   & (uint32_t)0x00FF0000  ) >>  8) |
+         ((value   & (uint32_t)0x0000FF00  ) <<  8) |
+         ((value /*& (uint32_t)0X000000FF*/) << 24);
+}
+
+const uint64_t m64b1 = 0xFF;
+const uint64_t m64b2 = m64b1 <<  8;
+const uint64_t m64b3 = m64b1 << 16;
+const uint64_t m64b4 = m64b1 << 24;
+const uint64_t m64b5 = m64b1 << 32;
+const uint64_t m64b6 = m64b1 << 40;
+const uint64_t m64b7 = m64b1 << 48;
+//const uint64_t m64b8 = m64b1 << 56;
+
+inline static uint64_t swap_bytes( uint64_t value )
+{
+  return ((value /*& m64b8*/) >> 56) |
+         ((value   & m64b7  ) >> 40) |
+         ((value   & m64b6  ) >> 24) |
+         ((value   & m64b5  ) >>  8) |
+         ((value   & m64b4  ) <<  8) |
+         ((value   & m64b3  ) << 24) |
+         ((value   & m64b2  ) << 40) |
+         ((value /*& m64b1*/) << 56);
+}
+/*
+inline static uint32_t swap_byte_pairs( uint32_t value )
+{
+  return ((value & (uint32_t)0xFF000000) >> 8) |
+         ((value & (uint32_t)0x00FF0000) << 8) |
+         ((value & (uint32_t)0x0000FF00) >> 8) |
+         ((value & (uint32_t)0X000000FF) << 8);
+}
+
+inline static uint64_t swap_byte_quads( uint64_t value )
+{
+  return ((value & m64b8) >> 24) |
+         ((value & m64b7) >>  8) |
+         ((value & m64b6) <<  8) |
+         ((value & m64b5) << 24) |
+         ((value & m64b4) >> 24) |
+         ((value & m64b3) >>  8) |
+         ((value & m64b2) <<  8) |
+         ((value & m64b1) << 24);
+}
+
+inline static uint64_t swap_byte_pairs( uint64_t value )
+{
+  return ((value & m64b8) >> 8) |
+         ((value & m64b7) << 8) |
+         ((value & m64b6) >> 8) |
+         ((value & m64b5) << 8) |
+         ((value & m64b4) >> 8) |
+         ((value & m64b3) << 8) |
+         ((value & m64b2) >> 8) |
+         ((value & m64b1) << 8);
+}
+*/
+void byteswap2( void* data, size_t num_elem )
+{
+  uint16_t* mem = reinterpret_cast<uint16_t*>(data);
+  uint16_t* end = mem + num_elem;
+  for (; mem < end; ++mem)
+    *mem = swap_bytes( *mem );
+}
+
+void byteswap4( void* data, size_t num_elem )
+{
+  uint32_t* mem = reinterpret_cast<uint32_t*>(data);
+  uint32_t* end = mem + num_elem;
+  for (; mem < end; ++mem)
+    *mem = swap_bytes( *mem );
+}
+
+void byteswap8( void* data, size_t num_elem )
+{
+  if (sizeof(void*) >= 8) {
+    uint64_t* mem = reinterpret_cast<uint64_t*>(data);
+    uint64_t* end = mem + num_elem;
+    for (; mem < end; ++mem)
+      *mem = swap_bytes( *mem );
+  }
+  else {
+    uint32_t* mem = reinterpret_cast<uint32_t*>(data);
+    uint32_t* end = mem + 2*num_elem;
+    for (; mem < end; mem += 2) {
+      uint32_t tmp = swap_bytes( mem[0] );
+      mem[0] = swap_bytes( mem[1] );
+      mem[1] = tmp;
+    }
+  }
+}
+
+} // namespace SysUtil
+
+
+} // namespace moab

Copied: MOAB/trunk/src/SysUtil.hpp (from rev 3583, MOAB/trunk/src/MBSysUtil.hpp)
===================================================================
--- MOAB/trunk/src/SysUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/SysUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,110 @@
+#ifndef MB_SYS_UTIL_HPP
+#define MB_SYS_UTIL_HPP
+
+#include <string.h> // for size_t
+#include <stdio.h>
+#include <iosfwd>
+
+namespace moab {
+
+namespace SysUtil
+{
+
+/**\brief Similar to memset, but accepts values larger than 1 char
+ *
+ * Set block of memory to repeating copies of a sequene of bytes.
+ *\param mem   Pointer to start of memory block to initialize
+ *\param value Byte sequence to initialize mem with
+ *\param value_size Size of 'value'
+ *\param num_elem Size of 'mem' as a multiple of value_size (the number of
+ *             copies of 'value' to write into 'mem'.)
+ */
+void setmem( void* mem, const void* value, unsigned value_size, size_t num_elem );
+
+/**\brief Get size of file (if it is a regular file)
+ *
+ * Get size of regular file.  
+ *\return - file size if known
+ *        - -1 if file size cannot be determined (e.g. a pipe) 
+ *        - -2 if an unexpected failure occured (may indicate change
+ *           in file position.)
+ */
+long filesize( FILE* filp );
+
+/**\brief Get size of file (if it is a regular file)
+ *
+ * Get size of regular file.  
+ *\return - file size if known
+ *        - -1 if file size cannot be determined (e.g. a pipe) 
+ *        - -2 if an unexpected failure occured (may indicate change
+ *           in file position.)
+ */
+long filesize( std::ifstream& str );
+
+/**\brief Check if platform is little-endian
+ * 
+ * Check if platform is little-endian (least significant
+ * byte at highest memory address.)
+ */
+inline bool little_endian()
+{
+  const unsigned one = 1;
+  return !*((char*)&one);
+}
+
+/**\brief Check if platform is big-endian
+ * 
+ * Check if platform is big-endian (least significant
+ * byte at lowest memory address.)
+ */
+inline bool big_endian()
+{
+  const unsigned one = 1;
+  return !(((char*)&one)[sizeof(unsigned)-1]);
+}
+
+/**\brief Swap byte order (e.g. change from big-endian to little-endian)
+ *
+ * Reverse byte order or array of values.
+ *\param data        Pointer to beginning of memory block to modify
+ *\param values_size Size of one value
+ *\param num_elem    Number of values of size 'value_size' in 'data'
+ */
+void byteswap( void* data, unsigned value_size, size_t num_elem );
+
+/**\brief Alternate byteswap optimized for 2-byte values */
+void byteswap2( void* data, size_t num_elem );
+/**\brief Alternate byteswap optimized for 4-byte values */
+void byteswap4( void* data, size_t num_elem );
+/**\brief Alternate byteswap optimized for 8-byte values */
+void byteswap8( void* data, size_t num_elem );
+
+/**\brief Type-specific byte swap */
+template <typename T> 
+inline void byteswap( T* data, size_t num_elem )
+{
+  switch (sizeof(T)) {
+    case 1:
+      break;
+    case 2:  
+      byteswap2( data, num_elem ); 
+      break;
+    case 4:  
+      byteswap4( data, num_elem ); 
+      break;
+    case 8: 
+      byteswap8( data, num_elem ); 
+      break;
+    default: 
+      byteswap( data, sizeof(T), num_elem ); 
+      break;
+  }
+}
+
+
+} // namespace SysUtil
+
+} // namespace moab
+
+
+#endif

Modified: MOAB/trunk/src/TagCompare.hpp
===================================================================
--- MOAB/trunk/src/TagCompare.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TagCompare.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,6 +4,8 @@
 #include "TagInfo.hpp"
 #include "VarLenTag.hpp"
 
+namespace moab {
+
 /* OPAQUE FUNCTORS */
 
 /** Test fixed-length opaque tags for equality */
@@ -203,10 +205,10 @@
 
 typedef TagBytesEqual                   TagHandlesEqual;
 typedef TagVarBytesEqual                TagVarHandlesEqual;
-typedef TagTypeLess    <MBEntityHandle> TagHandlesLess;
-typedef TagVarTypeLess <MBEntityHandle> TagVarHandlesLess;
-typedef TagOneTypeEqual<MBEntityHandle> TagOneHandleEqual;
-typedef TagOneTypeLess <MBEntityHandle> TagOneHandleLess;
+typedef TagTypeLess    <EntityHandle> TagHandlesLess;
+typedef TagVarTypeLess <EntityHandle> TagVarHandlesLess;
+typedef TagOneTypeEqual<EntityHandle> TagOneHandleEqual;
+typedef TagOneTypeLess <EntityHandle> TagOneHandleLess;
 
 typedef TagTypeEqual   <double> TagDoublesEqual;
 typedef TagVarTypeEqual<double> TagVarDoublesEqual;
@@ -222,9 +224,9 @@
 void find_tag_values( Functor compare,
                       IteratorType begin,
                       IteratorType end,
-                      MBRange& results )
+                      Range& results )
 {
-  MBRange::iterator insert = results.begin();
+  Range::iterator insert = results.begin();
   for (IteratorType i = begin; i != end; ++i) 
     if (compare( i->second ))
       insert = results.insert( insert, i->first, i->first );
@@ -235,9 +237,9 @@
 void find_tag_values( Functor compare,
                       IteratorType begin,
                       IteratorType end,
-                      std::vector<MBEntityHandle>& results )
+                      std::vector<EntityHandle>& results )
 {
-  MBRange::iterator insert = results.begin();
+  Range::iterator insert = results.begin();
   for (IteratorType i = begin; i != end; ++i) 
     if (compare( i->second ))
       results.push_back( i->first );
@@ -247,7 +249,7 @@
  *\param IteratorType : an iterator that has map behavior:
  *                      the value of 'first' is the entity handle.
  *                      the value of 'second' is a pointer to the tag data.
- *\param ContainerType : std::vector<MBEntityHandle> or MBRange
+ *\param ContainerType : std::vector<EntityHandle> or Range
  */
 template <class IteratorType, class ContainerType>
 void find_tag_values_equal( const TagInfo& tag_info,
@@ -291,7 +293,7 @@
         case MB_VARIABLE_LENGTH:
           find_tag_values( TagVarHandlesEqual( value, size ), begin, end, results );
           break;
-        case sizeof(MBEntityHandle):
+        case sizeof(EntityHandle):
           find_tag_values( TagOneHandleEqual( value ), begin, end, results );
           break;
         default:
@@ -314,17 +316,17 @@
 {
   private:
     size_t step;
-    typedef std::pair<MBEntityHandle, const char*> data_type;
+    typedef std::pair<EntityHandle, const char*> data_type;
     data_type data;
   public:
-    ByteArrayIterator( MBEntityHandle start_handle,
+    ByteArrayIterator( EntityHandle start_handle,
                        const void* data_array,
                        size_t tag_size )
       : step(tag_size),
         data(start_handle, reinterpret_cast<const char*>(data_array))
         
       {}
-    ByteArrayIterator( MBEntityHandle start_handle,
+    ByteArrayIterator( EntityHandle start_handle,
                        const void* data_array,
                        const TagInfo& tag_info )
       : step(tag_info.get_size() == MB_VARIABLE_LENGTH ? sizeof(VarLenTag) : tag_info.get_size()),
@@ -346,7 +348,7 @@
       { data.first += amt; data.second += amt*step; return *this; }
     ByteArrayIterator& operator-=(size_t amt)
       { data.first -= amt; data.second -= amt*step; return *this; }
-    MBEntityHandle operator-( const ByteArrayIterator& other ) const
+    EntityHandle operator-( const ByteArrayIterator& other ) const
       { return data.first - other.data.first; }
     const data_type& operator*() const 
       { return data; }
@@ -354,5 +356,7 @@
       { return &data; }
 };
 
+} // namespace moab
+
 #endif
 

Modified: MOAB/trunk/src/TagInfo.cpp
===================================================================
--- MOAB/trunk/src/TagInfo.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TagInfo.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,13 +1,14 @@
 #include "TagInfo.hpp"
 
+namespace moab {
 
-int TagInfo::size_from_data_type( MBDataType t )
+int TagInfo::size_from_data_type( DataType t )
 {
   static const int sizes[] = { 1, 
                                sizeof(int), 
                                sizeof(double), 
                                1, 
-                               sizeof(MBEntityHandle),
+                               sizeof(EntityHandle),
                                0 };  
    return sizes[t];
 }
@@ -108,3 +109,5 @@
   return (sum == 0);
 }
 
+} // namespace moab
+

Modified: MOAB/trunk/src/TagInfo.hpp
===================================================================
--- MOAB/trunk/src/TagInfo.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TagInfo.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,14 @@
 #ifndef TAG_INFO_HPP
 #define TAG_INFO_HPP
 
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 
 #include <string>
 #include <string.h>  /* memcpy */
 #include <stdlib.h>  /* realloc & free */
 
+namespace moab {
+
 // ! stores information about a tag
 class TagInfo
 {
@@ -26,7 +28,7 @@
   //! constructor that takes all parameters
   inline TagInfo( const char * name, 
                   int size, 
-                  MBDataType type, 
+                  DataType type, 
                   const void * default_value,
                   int default_value_size);
   
@@ -68,11 +70,11 @@
     //! remove mesh value
   void remove_mesh_value();
   
-  inline MBDataType get_data_type() const     { return dataType; }
+  inline DataType get_data_type() const     { return dataType; }
   
-  inline void set_data_type( MBDataType t )   { dataType = t; }
+  inline void set_data_type( DataType t )   { dataType = t; }
 
-  static int size_from_data_type( MBDataType t );
+  static int size_from_data_type( DataType t );
   
   bool is_valid() const { return isValid; }
   void invalidate();
@@ -83,7 +85,7 @@
 
 private:    
 
-  MBErrorCode reserve_mesh_tag_id( int& id_out );
+  ErrorCode reserve_mesh_tag_id( int& id_out );
 
   //! stores the default data, if any
   void* mDefaultValue;
@@ -101,7 +103,7 @@
   int mDataSize;
   
   //! type of tag data
-  MBDataType dataType;
+  DataType dataType;
 
   //! stores the tag name
   std::string mTagName;
@@ -113,7 +115,7 @@
 
 inline TagInfo::TagInfo( const char* name, 
                          int size, 
-                         MBDataType type,
+                         DataType type,
                          const void* default_value,
                          int default_value_size)
  : mDefaultValue(0),
@@ -139,4 +141,6 @@
   mDefaultValueSize = mMeshValueSize = 0;
 }
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/TagServer.cpp
===================================================================
--- MOAB/trunk/src/TagServer.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TagServer.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -39,13 +39,15 @@
 #include <algorithm>
 #include <assert.h>
 #include "TagServer.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include "SparseTagSuperCollection.hpp"
 #include "BitTagServer.hpp"
-#include "MBInterface.hpp"
+#include "moab/Interface.hpp"
 #include "SequenceManager.hpp"
 #include "TagCompare.hpp"
 
+namespace moab {
+
 using namespace std;
   
 static inline bool check_lengths( const int* length_array, int expected_value, int count )
@@ -76,7 +78,7 @@
 }
 
 
-MBErrorCode TagServer::reset_all_data()
+ErrorCode TagServer::reset_all_data()
 {
   mSparseData->reset_data();
   mBitServer->reset_data();
@@ -86,11 +88,11 @@
 }
 
 
-MBErrorCode TagServer::add_tag( const char *tag_name, 
+ErrorCode TagServer::add_tag( const char *tag_name, 
                                 const int data_size,
-                                const MBTagType storage,
-                                const MBDataType data_type,
-                                MBTag &tag_handle,
+                                const TagType storage,
+                                const DataType data_type,
+                                Tag &tag_handle,
                                 const void *default_value,
                                 int default_value_size)
 {
@@ -142,10 +144,10 @@
     *i = TagInfo( tag_name, data_size, data_type, default_value, default_value_size );
 
 
-  MBTagId tag_id = i - list.begin() + 1;
+  TagId tag_id = i - list.begin() + 1;
   tag_handle = TAG_HANDLE_FROM_ID( tag_id, storage );
 
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   switch (storage) {
     case MB_TAG_BIT:
       result = mBitServer->reserve_tag_id( data_size, tag_id );
@@ -167,16 +169,16 @@
 }
 
 
-MBErrorCode TagServer::remove_tag(const MBTag tag_handle)
+ErrorCode TagServer::remove_tag(const Tag tag_handle)
 {
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE( tag_handle );
-  const MBTagType tag_type = PROP_FROM_TAG_HANDLE( tag_handle );
+  const TagId tag_id = ID_FROM_TAG_HANDLE( tag_handle );
+  const TagType tag_type = PROP_FROM_TAG_HANDLE( tag_handle );
   const unsigned tag_idx = tag_id - 1;
   if (tag_idx >= mTagTable[tag_type].size() ||
       !mTagTable[tag_type][tag_idx].is_valid())
     return MB_TAG_NOT_FOUND;
   
-  MBErrorCode status = MB_FAILURE;
+  ErrorCode status = MB_FAILURE;
   switch (tag_type) {
     case MB_TAG_BIT:
       status = mBitServer->release_tag_id(tag_id);
@@ -199,11 +201,11 @@
 
 //! resets all data tagged to this entity handle back to default data or NULL.
 //! this is used to clean out stale data that might be referenced again
-MBErrorCode TagServer::reset_data(MBEntityHandle entity_handle)
+ErrorCode TagServer::reset_data(EntityHandle entity_handle)
 {
   std::vector<TagInfo>::iterator i;
 
-  MBTagId tag_id;
+  TagId tag_id;
 
   for (tag_id = 1; tag_id <= mTagTable[MB_TAG_BIT].size(); ++tag_id) 
     if (mTagTable[MB_TAG_BIT][tag_id-1].is_valid())
@@ -224,7 +226,7 @@
 }
 
 
-MBErrorCode TagServer::set_mesh_data( const MBTag tag_handle,
+ErrorCode TagServer::set_mesh_data( const Tag tag_handle,
                                       const void* data,
                                       int size )
 {
@@ -246,14 +248,14 @@
 }
 
 
-MBErrorCode TagServer::set_data( const MBTag tag_handle, 
-                                 const MBEntityHandle* entity_handles, 
+ErrorCode TagServer::set_data( const Tag tag_handle, 
+                                 const EntityHandle* entity_handles, 
                                  const int num_entities,
                                  const void* data )
 {
-  MBErrorCode rval;
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode rval;
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* tag_info;
   switch (tag_type) {
     case MB_TAG_DENSE:
@@ -288,13 +290,13 @@
   return rval;
 }
 
-MBErrorCode TagServer::set_data( const MBTag tag_handle, 
-                                 const MBRange& entity_handles, 
+ErrorCode TagServer::set_data( const Tag tag_handle, 
+                                 const Range& entity_handles, 
                                  const void* data )
 {
-  MBErrorCode rval;
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode rval;
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* tag_info;
   switch (tag_type) {
     case MB_TAG_DENSE:
@@ -330,15 +332,15 @@
   return rval;
 }
 
-MBErrorCode TagServer::set_data( const MBTag tag_handle, 
-                                 const MBEntityHandle* entity_handles, 
+ErrorCode TagServer::set_data( const Tag tag_handle, 
+                                 const EntityHandle* entity_handles, 
                                  const int num_entities,
                                  void const* const* data,
                                  const int* lengths )
 {
-  MBErrorCode rval;
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode rval;
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* tag_info = get_tag_info( tag_id, tag_type );
   if (!tag_info)
     return MB_TAG_NOT_FOUND;
@@ -371,14 +373,14 @@
   return rval;
 }
 
-MBErrorCode TagServer::set_data( const MBTag tag_handle, 
-                                 const MBRange& entity_handles, 
+ErrorCode TagServer::set_data( const Tag tag_handle, 
+                                 const Range& entity_handles, 
                                  void const* const* data,
                                  const int* lengths )
 {
-  MBErrorCode rval;
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode rval;
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType tag_type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* tag_info = get_tag_info( tag_id, tag_type );
   if (!tag_info)
     return MB_TAG_NOT_FOUND;
@@ -413,7 +415,7 @@
 
 
 
-MBErrorCode TagServer::get_mesh_data( const MBTag tag_handle,
+ErrorCode TagServer::get_mesh_data( const Tag tag_handle,
                                       void* data ) const
 {
   const TagInfo* info = get_tag_info( tag_handle );
@@ -433,7 +435,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_mesh_data( MBTag tag_handle,
+ErrorCode TagServer::get_mesh_data( Tag tag_handle,
                                       const void*& data,
                                       int& size ) const
 {
@@ -464,13 +466,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_data( const MBTag tag_handle,
-                                 const MBEntityHandle* entity_handles,
+ErrorCode TagServer::get_data( const Tag tag_handle,
+                                 const EntityHandle* entity_handles,
                                  const int num_entities,
                                  void* data )
 {
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType type = PROP_FROM_TAG_HANDLE(tag_handle);
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
     return MB_TAG_NOT_FOUND;
@@ -489,12 +491,12 @@
   }
 }
 
-MBErrorCode TagServer::get_data( const MBTag tag_handle,
-                                 const MBRange& entity_handles,
+ErrorCode TagServer::get_data( const Tag tag_handle,
+                                 const Range& entity_handles,
                                  void* data )
 {
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType type = PROP_FROM_TAG_HANDLE(tag_handle);
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
     return MB_TAG_NOT_FOUND;
@@ -513,14 +515,14 @@
   }
 }
 
-MBErrorCode TagServer::get_data( const MBTag tag_handle,
-                                 const MBEntityHandle* entity_handles,
+ErrorCode TagServer::get_data( const Tag tag_handle,
+                                 const EntityHandle* entity_handles,
                                  const int num_entities,
                                  const void** data,
                                  int* lengths )
 {
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType type = PROP_FROM_TAG_HANDLE(tag_handle);
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
     return MB_TAG_NOT_FOUND;
@@ -538,13 +540,13 @@
   }
 }
 
-MBErrorCode TagServer::get_data( const MBTag tag_handle,
-                                 const MBRange& entity_handles,
+ErrorCode TagServer::get_data( const Tag tag_handle,
+                                 const Range& entity_handles,
                                  const void** data,
                                  int* lengths )
 {
-  const MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  const MBTagType type = PROP_FROM_TAG_HANDLE(tag_handle);
+  const TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  const TagType type = PROP_FROM_TAG_HANDLE(tag_handle);
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
     return MB_TAG_NOT_FOUND;
@@ -563,32 +565,32 @@
 }
 
 
-MBTag TagServer::get_handle(const char *tag_name) const
+Tag TagServer::get_handle(const char *tag_name) const
 {
   if (tag_name && *tag_name)
     for (int i = 0; i < MB_TAG_LAST+1; ++i) 
-      for (MBTagId j = 0; j < mTagTable[i].size(); ++j) 
+      for (TagId j = 0; j < mTagTable[i].size(); ++j) 
         if (mTagTable[i][j].is_valid() && mTagTable[i][j].get_name() == tag_name)
-          return TAG_HANDLE_FROM_ID( j + 1, (MBTagType)i );
+          return TAG_HANDLE_FROM_ID( j + 1, (TagType)i );
   
   return 0;
 }
 
-MBErrorCode TagServer::get_tags(std::vector<MBTag> &all_tags)
+ErrorCode TagServer::get_tags(std::vector<Tag> &all_tags)
 {
   for (int i = 0; i < MB_TAG_LAST+1; ++i) 
-    for (MBTagId j = 0; j < mTagTable[i].size(); ++j) 
+    for (TagId j = 0; j < mTagTable[i].size(); ++j) 
       if (mTagTable[i][j].is_valid())
-        all_tags.push_back( TAG_HANDLE_FROM_ID( j + 1, (MBTagType)i ) );
+        all_tags.push_back( TAG_HANDLE_FROM_ID( j + 1, (TagType)i ) );
 
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_tags(const MBEntityHandle entity, std::vector<MBTag> &all_tags)
+ErrorCode TagServer::get_tags(const EntityHandle entity, std::vector<Tag> &all_tags)
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
-  MBErrorCode tmp_result = mSparseData->get_tags(entity, all_tags);
+  ErrorCode tmp_result = mSparseData->get_tags(entity, all_tags);
   if (MB_SUCCESS != tmp_result) result = tmp_result;
   
   tmp_result = sequenceManager->get_entity_tags(entity, all_tags);
@@ -600,17 +602,17 @@
   return result;
 }
 
-MBErrorCode TagServer::get_mesh_tags( std::vector<MBTag>& all_tags ) const
+ErrorCode TagServer::get_mesh_tags( std::vector<Tag>& all_tags ) const
 {
   for (int i = 0; i < MB_TAG_LAST+1; ++i) 
-    for (MBTagId j = 0; j < mTagTable[i].size(); ++j) 
+    for (TagId j = 0; j < mTagTable[i].size(); ++j) 
       if (mTagTable[i][j].is_valid() && mTagTable[i][j].get_mesh_value())
-        all_tags.push_back( TAG_HANDLE_FROM_ID( j + 1, (MBTagType)i ) );
+        all_tags.push_back( TAG_HANDLE_FROM_ID( j + 1, (TagType)i ) );
   
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_default_data_ref( const MBTag tag_handle, 
+ErrorCode TagServer::get_default_data_ref( const Tag tag_handle, 
                                              const void *& data,
                                              int& size) 
 {
@@ -633,7 +635,7 @@
 }
 
 
-MBErrorCode TagServer::get_default_data( const MBTag tag_handle, 
+ErrorCode TagServer::get_default_data( const Tag tag_handle, 
                                          void *data,
                                          int& size) 
 {
@@ -653,7 +655,7 @@
 }
 
 
-MBErrorCode TagServer::remove_mesh_data( const MBTag tag_handle )
+ErrorCode TagServer::remove_mesh_data( const Tag tag_handle )
 {
   TagInfo* info = get_tag_info( tag_handle );
   if (!info || !info->get_mesh_value_size())
@@ -663,10 +665,10 @@
 }
 
 
-MBErrorCode TagServer::remove_data( const MBTag tag_handle, const MBEntityHandle entity_handle )
+ErrorCode TagServer::remove_data( const Tag tag_handle, const EntityHandle entity_handle )
 {
-  MBTagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
-  MBTagType storage = PROP_FROM_TAG_HANDLE(tag_handle);
+  TagId tag_id = ID_FROM_TAG_HANDLE(tag_handle);
+  TagType storage = PROP_FROM_TAG_HANDLE(tag_handle);
   if (tag_id > mTagTable[storage].size())
     return MB_TAG_NOT_FOUND;
   const void* defval = mTagTable[storage][tag_id-1].default_value();
@@ -689,11 +691,11 @@
 
 
 //! gets all entity handles that match a type and tag
-MBErrorCode TagServer::get_entities(const MBTag tag_handle, const MBEntityType type,
-                                     MBRange &entities)
+ErrorCode TagServer::get_entities(const Tag tag_handle, const EntityType type,
+                                     Range &entities)
 {
-  MBErrorCode result = MB_TAG_NOT_FOUND;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode result = MB_TAG_NOT_FOUND;
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       result = mSparseData->get_entities(id, type, entities);
@@ -713,16 +715,16 @@
 }
 
 //! gets all entity handles that match a tag
-MBErrorCode TagServer::get_entities(const MBTag tag_handle, MBRange &entities)
+ErrorCode TagServer::get_entities(const Tag tag_handle, Range &entities)
 {
-  MBErrorCode result = MB_TAG_NOT_FOUND;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode result = MB_TAG_NOT_FOUND;
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       result = mSparseData->get_entities(id, entities);
       break;
     case MB_TAG_DENSE:
-      for (MBEntityType t = MBENTITYSET; t >= MBVERTEX; --t)
+      for (EntityType t = MBENTITYSET; t >= MBVERTEX; --t)
         result = sequenceManager->get_tagged_entities(id, t, entities);
       break;
     case MB_TAG_BIT:
@@ -737,18 +739,18 @@
 }
 
 //! gets all entity handles that match a type and tag
-MBErrorCode TagServer::get_entities(const MBRange &range,
-                                     const MBTag tag_handle, const MBEntityType type,
-                                     MBRange &entities)
+ErrorCode TagServer::get_entities(const Range &range,
+                                     const Tag tag_handle, const EntityType type,
+                                     Range &entities)
 {
-  MBErrorCode result = MB_TAG_NOT_FOUND;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode result = MB_TAG_NOT_FOUND;
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       result = mSparseData->get_entities(range, id, type, entities);
       break;
     case MB_TAG_DENSE: {
-      MBRange temp;
+      Range temp;
       result = sequenceManager->get_tagged_entities(id, type, temp);
       entities.merge( intersect( range, temp) );
       }
@@ -764,15 +766,15 @@
   return result;
 }
 
-MBErrorCode TagServer::get_entities_with_tag_value( const MBEntityType type,
-                                                    const MBTag tag_handle,
+ErrorCode TagServer::get_entities_with_tag_value( const EntityType type,
+                                                    const Tag tag_handle,
                                                     const void* value,
-                                                    MBRange &entities,
+                                                    Range &entities,
                                                     int value_size ) 
 {
 
-  MBErrorCode result = MB_TAG_NOT_FOUND;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode result = MB_TAG_NOT_FOUND;
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
 
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
@@ -800,16 +802,16 @@
   
 }
 
-MBErrorCode TagServer::get_entities_with_tag_value( const MBRange &range,
-                                                    const MBEntityType type,
-                                                    const MBTag tag_handle,
+ErrorCode TagServer::get_entities_with_tag_value( const Range &range,
+                                                    const EntityType type,
+                                                    const Tag tag_handle,
                                                     const void* value,
-                                                    MBRange &entities,
+                                                    Range &entities,
                                                     int value_size ) 
 {
 
-  MBErrorCode result = MB_TAG_NOT_FOUND;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  ErrorCode result = MB_TAG_NOT_FOUND;
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
 
   const TagInfo* info = get_tag_info( tag_handle );
   if (!info)
@@ -830,7 +832,7 @@
     else
       equals_default = !memcmp( value, info->default_value(), info->default_value_size() );
   }
-  MBRange tmp_ents;
+  Range tmp_ents;
   if (equals_default)
     tmp_ents.swap( entities );
   
@@ -856,7 +858,7 @@
     // If tag value is default value, then we want every entity
     // in 'range' of the correct type, except those with a different tag value.
   
-  MBRange all_tagged;
+  Range all_tagged;
   result = get_entities( range, tag_handle, type, all_tagged );
   if (MB_SUCCESS != result) 
     return result;
@@ -866,7 +868,7 @@
     // get everything that does not have a different value
   entities = subtract( range, entities );
     // remove entities of the incorrect type, if any
-  std::pair<MBRange::iterator,MBRange::iterator> p = entities.equal_range(type);
+  std::pair<Range::iterator,Range::iterator> p = entities.equal_range(type);
   entities.erase( entities.begin(), p.first );
   entities.erase( p.second, entities.end() );
     // merge with entities initially in range
@@ -876,24 +878,24 @@
   
 }
 
-MBErrorCode TagServer::get_entities_with_tag_values( const MBRange &input_range,
-                                                      const MBEntityType type,
-                                                      const MBTag *tags,
+ErrorCode TagServer::get_entities_with_tag_values( const Range &input_range,
+                                                      const EntityType type,
+                                                      const Tag *tags,
                                                       const void* const* values,
                                                       const int num_tags,
-                                                      MBRange &entities,
+                                                      Range &entities,
                                                       const int condition) 
 {
     // range should never come in empty
   assert(!input_range.empty());
   if (input_range.empty()) return MB_FAILURE;
-  MBRange range = input_range;
+  Range range = input_range;
   
-  MBErrorCode result;
-  MBRange temp1;
+  ErrorCode result;
+  Range temp1;
 
-  if (condition != MBInterface::INTERSECT &&
-      condition != MBInterface::UNION)
+  if (condition != Interface::INTERSECT &&
+      condition != Interface::UNION)
     return MB_FAILURE;
 
   for (unsigned int it = 0; it < (unsigned int) num_tags; it++) {
@@ -910,14 +912,14 @@
 
       // if we're doing a running intersection and we're just starting and
       // the list comes in empty, the 1st result is the start
-    if (0 == it && condition == MBInterface::INTERSECT && entities.empty()) {
+    if (0 == it && condition == Interface::INTERSECT && entities.empty()) {
       entities = intersect( temp1, range);
     }
 
       // else if we're doing a running intersection, intersect this result (temp1)
       // with the running result (entities) into temp2, then move that to the running
       // result (entities)
-    else if (condition == MBInterface::INTERSECT) {
+    else if (condition == Interface::INTERSECT) {
       entities = intersect( entities, temp1);
       if (entities.empty()) return MB_SUCCESS;
 
@@ -928,7 +930,7 @@
 
       // else if we're doing a union, put these results (temp1) into the running 
       // result (entities)
-    else if (condition == MBInterface::UNION) {
+    else if (condition == Interface::UNION) {
       entities.merge(temp1);
     }
   }
@@ -937,13 +939,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_number_entities( const MBTag tag_handle,
+ErrorCode TagServer::get_number_entities( const Tag tag_handle,
                                             unsigned long& num_entities )
 {
   num_entities = 0;
-  for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
+  for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
     int type_num_entities;
-    MBErrorCode rval = get_number_entities( tag_handle, t, type_num_entities );
+    ErrorCode rval = get_number_entities( tag_handle, t, type_num_entities );
     if (MB_SUCCESS != rval) 
       return rval;
     num_entities += type_num_entities;
@@ -951,11 +953,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TagServer::get_number_entities( const MBTag tag_handle, 
-                                             const MBEntityType type,
+ErrorCode TagServer::get_number_entities( const Tag tag_handle, 
+                                             const EntityType type,
                                              int& num_entities)
 {
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       return mSparseData->get_number_entities(id, type, num_entities);
@@ -969,18 +971,18 @@
   return MB_TAG_NOT_FOUND;
 }
 
-MBErrorCode TagServer::get_number_entities( const MBRange &range,
-                                             const MBTag tag_handle, 
-                                             const MBEntityType type,
+ErrorCode TagServer::get_number_entities( const Range &range,
+                                             const Tag tag_handle, 
+                                             const EntityType type,
                                              int& num_entities)
 {
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       return mSparseData->get_number_entities(range, id, type, num_entities);
     case MB_TAG_DENSE: {
-      MBRange temp;
-      MBErrorCode rval = get_entities( range, tag_handle, type, temp );
+      Range temp;
+      ErrorCode rval = get_entities( range, tag_handle, type, temp );
       num_entities = temp.size();
       return rval;
     }
@@ -992,14 +994,14 @@
   return MB_TAG_NOT_FOUND;
 }
 
-unsigned long TagServer::get_memory_use( MBTag tag_handle ) const
+unsigned long TagServer::get_memory_use( Tag tag_handle ) const
 {
   const TagInfo* tag_info = get_tag_info(tag_handle);
   if (!tag_info)
     return 0;
 
   unsigned long result = 0, tmp;
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       mSparseData->get_memory_use( id, result, tmp );
@@ -1015,14 +1017,14 @@
   }
 
     // add in size of entry in mTagTable
-  result += sizeof(MBTag) + sizeof(TagInfo) + 3*sizeof(void*);
+  result += sizeof(Tag) + sizeof(TagInfo) + 3*sizeof(void*);
   result += tag_info->default_value_size();
   result += tag_info->get_mesh_value_size();
   result += tag_info->get_name().size();
   return result;
 }
 
-MBErrorCode TagServer::get_memory_use( MBTag tag_handle,
+ErrorCode TagServer::get_memory_use( Tag tag_handle,
                                        unsigned long& total,
                                        unsigned long& per_entity ) const
 {
@@ -1030,7 +1032,7 @@
   if(!tag_info)
     return MB_TAG_NOT_FOUND;
 
-  MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
+  TagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
     case MB_TAG_SPARSE:
       mSparseData->get_memory_use( id, total, per_entity );
@@ -1046,7 +1048,7 @@
   }
   
     // size of entry in mTagTable map
-  total += sizeof(MBTag) + sizeof(TagInfo) + 3*sizeof(void*);
+  total += sizeof(Tag) + sizeof(TagInfo) + 3*sizeof(void*);
   total += tag_info->default_value_size();
   total += tag_info->get_mesh_value_size();
   total += tag_info->get_name().size();
@@ -1054,9 +1056,9 @@
   return MB_SUCCESS;
 }
     
-  
-  
 
+} // namespace moab
+
 #ifdef TEST
 
 #include <iostream>
@@ -1066,6 +1068,7 @@
 
 #include "TagServer.hpp"
 
+using namespace moab;
 
 const int MAX_ID = 10000;
 const int SET_TAG_LOOPS = 0xFFF;
@@ -1080,11 +1083,11 @@
   std::string tag_name;
   tag_name.reserve(TAG_NAME_SIZE+1);
   //char tag_name[TAG_NAME_SIZE+1] = {0};
-  MBTag my_tag_handle;
+  Tag my_tag_handle;
   unsigned char tag_data[MAX_TAG_DATA_SIZE] = {0};
   unsigned char tag_size;
   unsigned int entity_type;
-  MBTag tag_handle = (MBTag)3245;
+  Tag tag_handle = (Tag)3245;
 
 
   tag_server.add_tag("densex", 4, MB_TAG_DENSE, MB_TYPE_OPAQUE, my_tag_handle);
@@ -1112,7 +1115,7 @@
     {
       std::cout << "adding tag - " << tag_name << " " << my_tag_handle << " with entity type " << entity_type << " of size " << static_cast<int>(tag_size) << std::endl;
 
-      MBTag tmp_tag_handle = tag_server.get_handle(tag_name.c_str());
+      Tag tmp_tag_handle = tag_server.get_handle(tag_name.c_str());
 
       if(tmp_tag_handle != my_tag_handle)
       {
@@ -1126,13 +1129,13 @@
       // test the find_entity function.  This test succeeds on failure
       tag_data[0] = rand();
       tag_server.set_data(my_tag_handle, 200, tag_data);
-      MBRange tmp_range;
+      Range tmp_range;
       tag_server.get_entities_with_tag_value( TYPE_FROM_HANDLE(200), my_tag_handle, tag_data, tmp_range );
       assert( tmp_range.size() == 1 && tmp_range.begin() == 200 );
 
       for( int i=0; i<SET_TAG_LOOPS; i++ )
       {
-        MBEntityHandle id = (MAX_ID*rand())/(RAND_MAX+1);
+        EntityHandle id = (MAX_ID*rand())/(RAND_MAX+1);
         for(int j=0; j<tag_size; j++)
           tag_data[j] = rand();
 
@@ -1154,7 +1157,7 @@
     {
       unsigned int entity_type_tmp = (0x3 & rand()) + 1;
       // try to get the handle and remove it
-      MBTag tmp = tag_server.get_handle(tag_name.c_str()); 
+      Tag tmp = tag_server.get_handle(tag_name.c_str()); 
       if(tmp)
       {
         std::cout << " removing tag - " << tag_name << " with entity type " << entity_type_tmp << std::endl;
@@ -1167,5 +1170,4 @@
   return 0;
 }
 
-
 #endif

Modified: MOAB/trunk/src/TagServer.hpp
===================================================================
--- MOAB/trunk/src/TagServer.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TagServer.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -38,11 +38,13 @@
 #include <string>
 #include <vector>
 
-#include "MBTypes.h"
-#include "MBInternals.hpp"
+#include "moab/Types.hpp"
+#include "Internals.hpp"
 #include "TagInfo.hpp"
 
-class MBRange;
+namespace moab {
+
+class Range;
 class SparseTagSuperCollection;
 class SequenceManager;
 class BitTagServer;
@@ -57,11 +59,11 @@
   virtual ~TagServer();
 
   //! add a tag
-  MBErrorCode add_tag(const char *tag_name, 
+  ErrorCode add_tag(const char *tag_name, 
                        const int data_size,
-                       const MBTagType storage,
-                       const MBDataType data_type,
-                       MBTag &tag_handle,
+                       const TagType storage,
+                       const DataType data_type,
+                       Tag &tag_handle,
                        const void *default_data = NULL,
                        int default_value_size = 0);
 
@@ -74,18 +76,18 @@
   // data_size is the size of the data in bytes
 
   //! remove a tag from this tag server
-  MBErrorCode remove_tag(const MBTag tag_handle);
+  ErrorCode remove_tag(const Tag tag_handle);
 
   //! resets all tag data associated with this handle back to default data or NULL
-  MBErrorCode reset_data(MBEntityHandle entity_handle);
+  ErrorCode reset_data(EntityHandle entity_handle);
 
   //! cleans out all data tagged on all entities
-  MBErrorCode reset_all_data();
+  ErrorCode reset_all_data();
 
   //! set global/mesh value of tag
-  MBErrorCode set_mesh_data( const MBTag tag_handle, const void* data, int size = 0);
+  ErrorCode set_mesh_data( const Tag tag_handle, const void* data, int size = 0);
 
-  /**\brief Set value for {MBTag,MBEntityHandle) tuple.
+  /**\brief Set value for {Tag,EntityHandle) tuple.
    * 
    * Set tag value.
    *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH for variable-length tags.
@@ -93,7 +95,7 @@
    *\param entity_handle The entity.
    *\param data          Pointer to tag value.
    */
-  MBErrorCode set_data(const MBTag tag_handle, const MBEntityHandle entity_handle, const void* data )
+  ErrorCode set_data(const Tag tag_handle, const EntityHandle entity_handle, const void* data )
     { return set_data( tag_handle, &entity_handle, 1, data ); }
   
   /**\brief Set tag values for an array of entity handles.
@@ -107,19 +109,19 @@
    *                      tag values for all entities, in the order the
    *                      entities are specified in entity_handles.
    */
-  MBErrorCode set_data(const MBTag tag_handle, const MBEntityHandle* entity_handles, const int num_entities, const void* data );
+  ErrorCode set_data(const Tag tag_handle, const EntityHandle* entity_handles, const int num_entities, const void* data );
   
-  /**\brief Set tag values for an MBRange of entity handles.
+  /**\brief Set tag values for an Range of entity handles.
    * 
    * Set tag values.
    *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH for variable-length tags.
    *\param tag_handle     The tag.
-   *\param entity_handles MBRange of entity handles.
+   *\param entity_handles Range of entity handles.
    *\param data           Pointer to memory containing concatenation of
    *                      tag values for all entities, in the order the
    *                      entities are specified in entity_handles.
    */
-  MBErrorCode set_data(const MBTag tag_handle, const MBRange& entity_handles, const void* data );
+  ErrorCode set_data(const Tag tag_handle, const Range& entity_handles, const void* data );
   
   /**\brief Set tag values for an array of entity handles.
    * 
@@ -131,13 +133,13 @@
    *\param lengths        Length of each entity's tag value.  Ignored
    *                      for fixed-length tags.
    */
-  MBErrorCode set_data( const MBTag tag_handle, 
-                        const MBEntityHandle* entity_handles, 
+  ErrorCode set_data( const Tag tag_handle, 
+                        const EntityHandle* entity_handles, 
                         const int num_entities, 
                         void const* const* data,
                         const int* lengths = 0 );
   
-  /**\brief Set tag values for an MBRange of entity handles.
+  /**\brief Set tag values for an Range of entity handles.
    * 
    * Set tag values.
    *\param tag_handle     The tag.
@@ -146,26 +148,26 @@
    *\param lengths        Length of each entity's tag value.  Ignored
    *                      for fixed-length tags.
    */
-  MBErrorCode set_data( const MBTag tag_handle, 
-                        const MBRange& entity_handles, 
+  ErrorCode set_data( const Tag tag_handle, 
+                        const Range& entity_handles, 
                         void const* const* data,
                         const int* lengths = 0 );
 
   //! get global/mesh value of tag
-  MBErrorCode get_mesh_data( const MBTag tag_handle, void* data ) const;
+  ErrorCode get_mesh_data( const Tag tag_handle, void* data ) const;
 
   //! get pointer/reference to mesh data
-  MBErrorCode get_mesh_data( MBTag tag_handle, const void*& data_ptr, int& size ) const;
+  ErrorCode get_mesh_data( Tag tag_handle, const void*& data_ptr, int& size ) const;
 
   /**\Brief Get tag value
    *
-   * Get the value for a {MBTag,MBEntityHandle} tuple.
+   * Get the value for a {Tag,EntityHandle} tuple.
    *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH for variable-length tags.
    *\param tag_handle    The tag
    *\param entity_handle The entity
    *\param data          Pointer to memory location to which to copy tag value.
    */
-  MBErrorCode get_data(const MBTag tag_handle, const MBEntityHandle entity_handle, void* data )
+  ErrorCode get_data(const Tag tag_handle, const EntityHandle entity_handle, void* data )
     { return get_data( tag_handle, &entity_handle, 1, data ); }
   
   /**\Brief Get tag values
@@ -179,11 +181,11 @@
    *                      Writes the concatenation of tag values, in the order
    *                      of the entity handles in the input array.
    */
-  MBErrorCode get_data(const MBTag tag_handle, const MBEntityHandle* entity_handles, const int num_ents, void* data );
+  ErrorCode get_data(const Tag tag_handle, const EntityHandle* entity_handles, const int num_ents, void* data );
   
   /**\Brief Get tag values
    *
-   * For a single tag, get the tag value for an MBRange of entities.
+   * For a single tag, get the tag value for an Range of entities.
    *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH for variable-length tags.
    *\param tag_handle     The tag
    *\param entity_handles Entity handles
@@ -191,7 +193,7 @@
    *                      Writes the concatenation of tag values, in the order
    *                      of the entity handles in the input array.
    */
-  MBErrorCode get_data(const MBTag tag_handle, const MBRange& entity_handles, void* data );
+  ErrorCode get_data(const Tag tag_handle, const Range& entity_handles, void* data );
   
   /**\brief Get pointers to tag values for an array of entity handles.
    * 
@@ -203,13 +205,13 @@
    *\param lengths        Output: Length of each entity's tag value.  
    *                      Optional for fixed-length tags.
    */
-  MBErrorCode get_data( const MBTag tag_handle, 
-                        const MBEntityHandle* entity_handles, 
+  ErrorCode get_data( const Tag tag_handle, 
+                        const EntityHandle* entity_handles, 
                         const int num_entities, 
                         const void** data,
                         int* lengths = 0 );
   
-  /**\brief Get pointers to tag values for an MBRange of entity handles.
+  /**\brief Get pointers to tag values for an Range of entity handles.
    * 
    * Get pointers to tag values.
    *\param tag_handle     The tag.
@@ -218,98 +220,98 @@
    *\param lengths        Output: Length of each entity's tag value.  
    *                      Optional for fixed-length tags.
    */
-  MBErrorCode get_data( const MBTag tag_handle, 
-                        const MBRange& entity_handles, 
+  ErrorCode get_data( const Tag tag_handle, 
+                        const Range& entity_handles, 
                         const void** data,
                         int* lengths = 0 );
 
   //! remove global/mesh value of tag
-  MBErrorCode remove_mesh_data( const MBTag tag_handle );
+  ErrorCode remove_mesh_data( const Tag tag_handle );
 
   //! remove the tag data on an entity
-  MBErrorCode remove_data( const MBTag tag_handle, const MBEntityHandle entity_handle );
+  ErrorCode remove_data( const Tag tag_handle, const EntityHandle entity_handle );
 
   //! gets all entity handles that match a type and tag
-  MBErrorCode get_entities( const MBTag tag_handle, 
-                             const MBEntityType type,
-                             MBRange &entities);
+  ErrorCode get_entities( const Tag tag_handle, 
+                             const EntityType type,
+                             Range &entities);
 
   //! gets all entity handles that match a tag
-  MBErrorCode get_entities( const MBTag tag_handle, 
-                             MBRange &entities);
+  ErrorCode get_entities( const Tag tag_handle, 
+                             Range &entities);
 
   //! For the set of entities in the input range, return those
   //! that match the specified type and have a value for the 
   //! specified tag.
-  MBErrorCode get_entities( const MBRange &input_range,
-                             const MBTag tag_handle, 
-                             const MBEntityType type,
-                             MBRange &entities);
+  ErrorCode get_entities( const Range &input_range,
+                             const Tag tag_handle, 
+                             const EntityType type,
+                             Range &entities);
 
   //! gets all entity handles that match a type, tag and tag value 
-  MBErrorCode get_entities_with_tag_value( const MBEntityType type,
-                                            const MBTag tag_handle,
+  ErrorCode get_entities_with_tag_value( const EntityType type,
+                                            const Tag tag_handle,
                                             const void* value,
-                                            MBRange &entities,
+                                            Range &entities,
                                             int value_size = 0 );
   
   //! For the set of entities in the input range, return those
   //! that match the specified type and have the specified tag value.
-  MBErrorCode get_entities_with_tag_value( const MBRange &input_range,
-                                            const MBEntityType type,
-                                            const MBTag tag_handle,
+  ErrorCode get_entities_with_tag_value( const Range &input_range,
+                                            const EntityType type,
+                                            const Tag tag_handle,
                                             const void* value,
-                                            MBRange &entities,
+                                            Range &entities,
                                             int value_size = 0 );
   
-  MBErrorCode get_entities_with_tag_values( const MBRange &input_range,
-                                             const MBEntityType type,
-                                             const MBTag *tags,
+  ErrorCode get_entities_with_tag_values( const Range &input_range,
+                                             const EntityType type,
+                                             const Tag *tags,
                                              const void* const* values,
                                              const int num_tags,
-                                             MBRange &entities,
+                                             Range &entities,
                                              const int condition);
   
   //! gets number of entities that match a type and tag
-  MBErrorCode get_number_entities( const MBTag tag_handle, const MBEntityType type,
+  ErrorCode get_number_entities( const Tag tag_handle, const EntityType type,
                              int& num_entities);
 
   //! get number of entities with tag set
-  MBErrorCode get_number_entities( const MBTag tag_handle, unsigned long& num_ents );
+  ErrorCode get_number_entities( const Tag tag_handle, unsigned long& num_ents );
 
   //! gets number of entities that match a type and tag
-  MBErrorCode get_number_entities(const MBRange &input_range,
-                                   const MBTag tag_handle, const MBEntityType type,
+  ErrorCode get_number_entities(const Range &input_range,
+                                   const Tag tag_handle, const EntityType type,
                                     int& num_entities);
 
   //! gets a tag handle by name and entity handle
-  MBTag get_handle(const char *tag_name) const;
+  Tag get_handle(const char *tag_name) const;
 
   //! get all the tags which have been defined for this entity
-  MBErrorCode get_tags(const MBEntityHandle entity, std::vector<MBTag> &all_tags);
+  ErrorCode get_tags(const EntityHandle entity, std::vector<Tag> &all_tags);
  
   //! get all the tags which have a global/mesh value
-  MBErrorCode get_mesh_tags(std::vector<MBTag> &all_tags) const;
+  ErrorCode get_mesh_tags(std::vector<Tag> &all_tags) const;
  
   //! get all the tags which have been defined
-  MBErrorCode get_tags(std::vector<MBTag> &all_tags);
+  ErrorCode get_tags(std::vector<Tag> &all_tags);
   
     //! get the default value for a given tag
-  MBErrorCode get_default_data(const MBTag tag_handle, void *data, int& size);
+  ErrorCode get_default_data(const Tag tag_handle, void *data, int& size);
 
     //! get the default value for a given tag
-  MBErrorCode get_default_data_ref(const MBTag tag_handle, const void *& data, int& size);
+  ErrorCode get_default_data_ref(const Tag tag_handle, const void *& data, int& size);
 
   //! get information about a tag
   inline const TagInfo* get_tag_info(const char *tag_name ) const;
-  inline const TagInfo* get_tag_info( MBTag tag_handle ) const;
-  inline TagInfo* get_tag_info( MBTag tag_handle );
-  inline const TagInfo* get_tag_info( MBTagId id, MBTagType storage ) const;
-  inline TagInfo* get_tag_info( MBTagId id, MBTagType storage );
+  inline const TagInfo* get_tag_info( Tag tag_handle ) const;
+  inline TagInfo* get_tag_info( Tag tag_handle );
+  inline const TagInfo* get_tag_info( TagId id, TagType storage ) const;
+  inline TagInfo* get_tag_info( TagId id, TagType storage );
   
-  unsigned long get_memory_use( MBTag tag_handle ) const;
+  unsigned long get_memory_use( Tag tag_handle ) const;
   
-  MBErrorCode get_memory_use( MBTag tag_handle,
+  ErrorCode get_memory_use( Tag tag_handle,
                               unsigned long& total,
                               unsigned long& per_entity ) const;
 
@@ -333,21 +335,21 @@
 
 inline const TagInfo* TagServer::get_tag_info( const char *tag_name ) const
 {
-  const MBTag handle = get_handle( tag_name );
+  const Tag handle = get_handle( tag_name );
   return handle ? get_tag_info( handle ) : 0;
 }
 
-inline const TagInfo* TagServer::get_tag_info( MBTag tag ) const
+inline const TagInfo* TagServer::get_tag_info( Tag tag ) const
 {
   return get_tag_info( ID_FROM_TAG_HANDLE(tag), PROP_FROM_TAG_HANDLE(tag) );
 }
 
-inline TagInfo* TagServer::get_tag_info( MBTag tag )
+inline TagInfo* TagServer::get_tag_info( Tag tag )
 {
   return get_tag_info( ID_FROM_TAG_HANDLE(tag), PROP_FROM_TAG_HANDLE(tag) );
 }
 
-inline const TagInfo* TagServer::get_tag_info( MBTagId id, MBTagType type ) const
+inline const TagInfo* TagServer::get_tag_info( TagId id, TagType type ) const
 {
   if (id > 0 && id <= mTagTable[type].size() && mTagTable[type][id-1].is_valid())
     return &mTagTable[type][id-1];
@@ -355,7 +357,7 @@
     return NULL;
 }
 
-inline TagInfo* TagServer::get_tag_info( MBTagId id, MBTagType type )
+inline TagInfo* TagServer::get_tag_info( TagId id, TagType type )
 {
   if (id > 0 && id <= mTagTable[type].size() && mTagTable[type][id-1].is_valid())
     return &mTagTable[type][id-1];
@@ -363,6 +365,8 @@
     return NULL;
 }
 
+} // namespace moab
+
 #endif //TAG_SERVER_HPP
 
 

Modified: MOAB/trunk/src/TypeSequenceManager.cpp
===================================================================
--- MOAB/trunk/src/TypeSequenceManager.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TypeSequenceManager.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,7 +2,10 @@
 #include "SequenceData.hpp"
 #include <assert.h>
 #include <limits>
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
+
+namespace moab {
+
 TypeSequenceManager::~TypeSequenceManager()
 {
     // We assume that for there to be multiple squences referenceing
@@ -36,11 +39,11 @@
   availableList.clear();
 }
 
-MBErrorCode TypeSequenceManager::merge_internal( iterator i, iterator j )
+ErrorCode TypeSequenceManager::merge_internal( iterator i, iterator j )
 {
   EntitySequence* dead = *j;
   sequenceSet.erase( j );
-  MBErrorCode rval = (*i)->merge( *dead );
+  ErrorCode rval = (*i)->merge( *dead );
   if (MB_SUCCESS != rval) {
     sequenceSet.insert( dead );
     return rval;
@@ -58,7 +61,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TypeSequenceManager::check_merge_next( iterator i )
+ErrorCode TypeSequenceManager::check_merge_next( iterator i )
 {
   iterator j = i; ++j;
   if (j == end() || (*j)->data() != (*i)->data() || 
@@ -69,7 +72,7 @@
   return merge_internal( i, j );
 }  
 
-MBErrorCode TypeSequenceManager::check_merge_prev( iterator i )
+ErrorCode TypeSequenceManager::check_merge_prev( iterator i )
 {
   if (i == begin())
     return MB_SUCCESS;
@@ -83,7 +86,7 @@
   return merge_internal( i, j );
 }  
 
-MBErrorCode TypeSequenceManager::insert_sequence( EntitySequence* seq_ptr )
+ErrorCode TypeSequenceManager::insert_sequence( EntitySequence* seq_ptr )
 {
   if (!seq_ptr->data())
     return MB_FAILURE;
@@ -150,7 +153,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TypeSequenceManager::replace_subsequence( EntitySequence* seq_ptr,
+ErrorCode TypeSequenceManager::replace_subsequence( EntitySequence* seq_ptr,
                                                       TagServer* tag_server )
 {
     // find the sequence of interest
@@ -300,7 +303,7 @@
 }
   
 
-MBErrorCode TypeSequenceManager::remove_sequence( const EntitySequence* seq_ptr,
+ErrorCode TypeSequenceManager::remove_sequence( const EntitySequence* seq_ptr,
                                                   bool& unreferenced_data )
 {
     // remove sequence from set
@@ -328,8 +331,8 @@
 }
 
 TypeSequenceManager::iterator
-TypeSequenceManager::find_free_handle(  MBEntityHandle min_start_handle,
-                                        MBEntityHandle max_end_handle,
+TypeSequenceManager::find_free_handle(  EntityHandle min_start_handle,
+                                        EntityHandle max_end_handle,
                                         bool& append_out,
                                         int values_per_ent )
 {
@@ -361,8 +364,8 @@
   return end();
 }
 
-bool TypeSequenceManager::is_free_sequence( MBEntityHandle start, 
-                                            MBEntityID num_entities,
+bool TypeSequenceManager::is_free_sequence( EntityHandle start, 
+                                            EntityID num_entities,
                                             SequenceData*& data_out,
                                             int values_per_ent )
 {
@@ -421,9 +424,9 @@
 }
 
 
-MBEntityHandle TypeSequenceManager::find_free_block( MBEntityID num_entities,
-                                                     MBEntityHandle min_start_handle,
-                                                     MBEntityHandle max_end_handle )
+EntityHandle TypeSequenceManager::find_free_block( EntityID num_entities,
+                                                     EntityHandle min_start_handle,
+                                                     EntityHandle max_end_handle )
 {
   const_iterator i = lower_bound( min_start_handle );
   if (i == end())
@@ -432,9 +435,9 @@
   if ((*i)->start_handle() < min_start_handle + num_entities)
     return min_start_handle;
   
-  MBEntityHandle prev_end = (*i)->end_handle(); ++i;
+  EntityHandle prev_end = (*i)->end_handle(); ++i;
   for (; i != end(); prev_end = (*i)->end_handle(), ++i) {
-    MBEntityID len = (*i)->start_handle() - prev_end - 1;
+    EntityID len = (*i)->start_handle() - prev_end - 1;
     if (len >= num_entities) 
       break;
   }
@@ -446,17 +449,17 @@
 }
 
 struct range_data {
-  MBEntityID num_entities;
-  MBEntityHandle min_start_handle, max_end_handle;
-  MBEntityHandle first, last;
+  EntityID num_entities;
+  EntityHandle min_start_handle, max_end_handle;
+  EntityHandle first, last;
 };
 
 static bool check_range( const range_data& d,
                          bool prefer_end,
-                         MBEntityHandle& result )
+                         EntityHandle& result )
 {
-  MBEntityHandle first = std::max( d.min_start_handle, d.first );
-  MBEntityHandle  last = std::min( d.max_end_handle, d.last );
+  EntityHandle first = std::max( d.min_start_handle, d.first );
+  EntityHandle  last = std::min( d.max_end_handle, d.last );
   if (last < first + d.num_entities - 1) {
     result = 0;
     return false;
@@ -466,17 +469,17 @@
   return true;
 }
 
-MBEntityHandle TypeSequenceManager::find_free_sequence( MBEntityID num_entities, 
-                                                        MBEntityHandle min_start_handle,
-                                                        MBEntityHandle max_end_handle,
+EntityHandle TypeSequenceManager::find_free_sequence( EntityID num_entities, 
+                                                        EntityHandle min_start_handle,
+                                                        EntityHandle max_end_handle,
                                                         SequenceData*& data_out,
-                                                        MBEntityID &data_size,
+                                                        EntityID &data_size,
                                                         int num_verts)
 {
   if (max_end_handle < min_start_handle + num_entities - 1)
     return 0;
   
-  MBEntityHandle result;
+  EntityHandle result;
   iterator p, i = lower_bound( min_start_handle );
   range_data d = { num_entities, min_start_handle, max_end_handle, 0, 0 };
   
@@ -567,7 +570,7 @@
   return 0;
 }
 
-MBEntityHandle TypeSequenceManager::last_free_handle( MBEntityHandle after_this ) const
+EntityHandle TypeSequenceManager::last_free_handle( EntityHandle after_this ) const
 {
   int junk;
   const_iterator it = lower_bound( after_this );
@@ -575,22 +578,22 @@
     return CREATE_HANDLE( TYPE_FROM_HANDLE(after_this), MB_END_ID, junk );
   else if ((*it)->start_handle() > after_this) {
       // need to check against the sequence data first
-    MBEntityHandle rhandle = (*it)->data()->start_handle();
+    EntityHandle rhandle = (*it)->data()->start_handle();
     return rhandle - 1;
   }
   else
     return 0;
 }
 
-MBErrorCode TypeSequenceManager::check_valid_handles( MBEntityHandle first,
-                                                      MBEntityHandle last ) const
+ErrorCode TypeSequenceManager::check_valid_handles( EntityHandle first,
+                                                      EntityHandle last ) const
 {
   const_iterator i = lower_bound( first );
   if (i == end() || (*i)->start_handle() > first)
     return MB_ENTITY_NOT_FOUND;
 
   while ((*i)->end_handle() < last) {
-    MBEntityHandle prev_end = (*i)->end_handle();
+    EntityHandle prev_end = (*i)->end_handle();
     ++i;
     if (i == end() || prev_end + 1 != (*i)->start_handle())
       return MB_ENTITY_NOT_FOUND;
@@ -599,7 +602,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TypeSequenceManager::erase( MBEntityHandle h )
+ErrorCode TypeSequenceManager::erase( EntityHandle h )
 {
   EntitySequence* seq = find(h);
   if (!seq)
@@ -614,7 +617,7 @@
     }
     SequenceData* data = seq->data();
     bool delete_data;
-    MBErrorCode rval = remove_sequence( seq, delete_data );
+    ErrorCode rval = remove_sequence( seq, delete_data );
     if (MB_SUCCESS != rval)
       return rval;
     delete seq;
@@ -640,11 +643,11 @@
   }
 }
 
-MBErrorCode TypeSequenceManager::erase( MBEntityHandle first, MBEntityHandle last )
+ErrorCode TypeSequenceManager::erase( EntityHandle first, EntityHandle last )
 {
     // first check that all entities in range are valid
 
-  MBErrorCode rval = check_valid_handles( first, last );
+  ErrorCode rval = check_valid_handles( first, last );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -692,7 +695,7 @@
 }
 
 TypeSequenceManager::iterator 
-TypeSequenceManager::split_sequence( iterator i, MBEntityHandle h )
+TypeSequenceManager::split_sequence( iterator i, EntityHandle h )
 {
   EntitySequence* seq = (*i)->split( h );
   if (!seq)
@@ -703,12 +706,12 @@
   return i;
 }
 
-MBErrorCode 
-TypeSequenceManager::is_free_handle( MBEntityHandle handle,
+ErrorCode 
+TypeSequenceManager::is_free_handle( EntityHandle handle,
                                      iterator& seq_iter_out,
                                      SequenceData*& data_ptr_out,
-                                     MBEntityHandle& block_start,
-                                     MBEntityHandle& block_end,
+                                     EntityHandle& block_start,
+                                     EntityHandle& block_end,
                                      int values_per_ent )
 {
   int junk;
@@ -783,17 +786,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode TypeSequenceManager::notify_appended( iterator seq )
+ErrorCode TypeSequenceManager::notify_appended( iterator seq )
 {
-  MBErrorCode rval = check_merge_next( seq );
+  ErrorCode rval = check_merge_next( seq );
   if ((*seq)->using_entire_data())
     availableList.erase( (*seq)->data() );
   return rval;
 }
 
-MBErrorCode TypeSequenceManager::notify_prepended( iterator seq )
+ErrorCode TypeSequenceManager::notify_prepended( iterator seq )
 {
-  MBErrorCode rval =  check_merge_prev( seq );
+  ErrorCode rval =  check_merge_prev( seq );
   if ((*seq)->using_entire_data())
     availableList.erase( (*seq)->data() );
   return rval;
@@ -806,7 +809,7 @@
   if (empty())
     return;
   
-  MBEntityType mytype = TYPE_FROM_HANDLE(lastReferenced->start_handle());
+  EntityType mytype = TYPE_FROM_HANDLE(lastReferenced->start_handle());
   int junk;
   get_memory_use( CREATE_HANDLE( mytype, MB_START_ID, junk ), 
                   CREATE_HANDLE( mytype, MB_END_ID,   junk ),
@@ -814,8 +817,8 @@
                   total_storage );
 } 
 
-void TypeSequenceManager::append_memory_use( MBEntityHandle first,
-                                             MBEntityHandle last,
+void TypeSequenceManager::append_memory_use( EntityHandle first,
+                                             EntityHandle last,
                                              const SequenceData* data,
                                              unsigned long& entity_storage,
                                              unsigned long& total_storage ) const
@@ -832,8 +835,8 @@
     occupied_count += (*i)->size();
     ++sequence_count;
     
-    MBEntityHandle start = std::max( first, (*i)->start_handle() );
-    MBEntityHandle  stop = std::min(  last, (*i)->end_handle() );
+    EntityHandle start = std::max( first, (*i)->start_handle() );
+    EntityHandle  stop = std::min(  last, (*i)->end_handle() );
     if (stop < start)
       continue;
     
@@ -855,8 +858,8 @@
   }
 }
 
-void TypeSequenceManager::get_memory_use( MBEntityHandle first,
-                                          MBEntityHandle last,
+void TypeSequenceManager::get_memory_use( EntityHandle first,
+                                          EntityHandle last,
                                           unsigned long& entity_storage,
                                           unsigned long& total_storage ) const
 {
@@ -875,9 +878,9 @@
   }
 }
 
-MBEntityID TypeSequenceManager::get_occupied_size( const SequenceData* data ) const
+EntityID TypeSequenceManager::get_occupied_size( const SequenceData* data ) const
 {
-  MBEntityID result = 0;
+  EntityID result = 0;
   for (const_iterator i = data->seqManData.firstSequence; i != end() && (*i)->data() == data; ++i)
     result += (*i)->size();
   return result;
@@ -937,6 +940,9 @@
   
   return true;
 }
+
+} // namespace moab
+
 #endif
 
     

Modified: MOAB/trunk/src/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/src/TypeSequenceManager.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/TypeSequenceManager.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,18 +2,21 @@
 #define TYPE_SEQUENCE_MANAGER_HPP
 
 #include "EntitySequence.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 
 #include <set>
 #include <vector>
+
+namespace moab {
+
 class TagServer;
 
 /**\brief Maintain data structures organizing EntitySequence instances
  *
  * EntitySequenceManager is a composition of instances of TypeSequenceManager,
- * one instance for each MBEntityType.  The TypeSequenceManager provides
+ * one instance for each EntityType.  The TypeSequenceManager provides
  * organization, owership, and querying of EntitySequences for a specific
- * MBEntityType.
+ * EntityType.
  */
 class TypeSequenceManager
 {
@@ -30,17 +33,17 @@
   /**\brief Dummy EntitySequence for use in querying set container */
   class DummySequence : public EntitySequence {
     public:
-      DummySequence( MBEntityHandle start )
+      DummySequence( EntityHandle start )
         : EntitySequence( start ) {}
   
-      EntitySequence* split( MBEntityHandle ) 
+      EntitySequence* split( EntityHandle ) 
         { return 0; }
-      SequenceData* create_data_subset( MBEntityHandle, MBEntityHandle ) const
+      SequenceData* create_data_subset( EntityHandle, EntityHandle ) const
         { return 0; }
       
       void get_const_memory_use( unsigned long& a, unsigned long& b) const
         { a = b = 0; }
-      unsigned long get_per_entity_memory_use( MBEntityHandle, MBEntityHandle) const
+      unsigned long get_per_entity_memory_use( EntityHandle, EntityHandle) const
         { return 0; }
   };
 
@@ -67,22 +70,22 @@
 
   iterator erase( iterator i );  //!< Remove a sequence
   
-  iterator split_sequence( iterator i, MBEntityHandle h ); //!< split a sequence
+  iterator split_sequence( iterator i, EntityHandle h ); //!< split a sequence
 
-  void append_memory_use( MBEntityHandle first,
-                          MBEntityHandle last,
+  void append_memory_use( EntityHandle first,
+                          EntityHandle last,
                           const SequenceData* data,
                           unsigned long& entity_storage,
                           unsigned long& total_storage ) const;
 
     // check if sequence at passed iterator should be merged with
     // the subsequent sequence, and if so merge them retaining i.
-  MBErrorCode check_merge_next( iterator i );
+  ErrorCode check_merge_next( iterator i );
     // check if sequence at passed iterator should be merged with
     // the previous sequence, and if so merge them retaining i.
-  MBErrorCode check_merge_prev( iterator i );
+  ErrorCode check_merge_prev( iterator i );
     // common code for check_merge_next and check_merge_prev
-  MBErrorCode merge_internal( iterator keep, iterator dead );
+  ErrorCode merge_internal( iterator keep, iterator dead );
 
 #ifndef NDEBUG
   bool check_valid_data( const EntitySequence* seq ) const;
@@ -101,7 +104,7 @@
    *        EntitySequence* is the remaining one, but the passed
    *        sequence may have modified start and end handles.
    */
-  MBErrorCode insert_sequence( EntitySequence* seq_ptr );
+  ErrorCode insert_sequence( EntitySequence* seq_ptr );
   
   /**\brief Remove an entity sequence.
    *
@@ -111,7 +114,7 @@
    * is also relinquished because the specified EntitySequence is
    * the last one referencing it.  
    */
-  MBErrorCode remove_sequence( const EntitySequence* seq_ptr,
+  ErrorCode remove_sequence( const EntitySequence* seq_ptr,
                                bool& is_last_user_of_sequence_data );
                                
                                
@@ -126,7 +129,7 @@
    * This method is provided for use when changing the
    * number of nodes in elements. 
    */
-  MBErrorCode replace_subsequence( EntitySequence* seq_ptr, TagServer* ts );
+  ErrorCode replace_subsequence( EntitySequence* seq_ptr, TagServer* ts );
   
   TypeSequenceManager() : lastReferenced(0) {}
   
@@ -146,12 +149,12 @@
      *  no such sequence, the next one.  Returns end() if
      *  all sequences have ranges less than specified handle.
      */
-  const_iterator lower_bound( MBEntityHandle h ) const 
+  const_iterator lower_bound( EntityHandle h ) const 
     { 
       DummySequence f(h);
       return sequenceSet.lower_bound( &f ); 
     }
-  iterator lower_bound( MBEntityHandle h )
+  iterator lower_bound( EntityHandle h )
     { 
       DummySequence f(h);
       return sequenceSet.lower_bound( &f ); 
@@ -164,7 +167,7 @@
      *  all sequences have start handles less than specified 
      *  handle.
      */
-  const_iterator upper_bound( MBEntityHandle h ) const 
+  const_iterator upper_bound( EntityHandle h ) const 
     { 
       DummySequence f(h);
       return sequenceSet.upper_bound( &f ); 
@@ -173,22 +176,22 @@
     /**\brief Get EntitySequence for handle. 
      *\return EntitySequence for handle, or NULL if no such sequence.
      */
-  inline EntitySequence* find( MBEntityHandle h ) const;
-  inline EntitySequence* find( MBEntityHandle h );
-  inline MBErrorCode find( MBEntityHandle h, EntitySequence*& );
-  inline MBErrorCode find( MBEntityHandle h, const EntitySequence*& ) const;
+  inline EntitySequence* find( EntityHandle h ) const;
+  inline EntitySequence* find( EntityHandle h );
+  inline ErrorCode find( EntityHandle h, EntitySequence*& );
+  inline ErrorCode find( EntityHandle h, const EntitySequence*& ) const;
   inline const EntitySequence* get_last_accessed() const;
   
     /**\brief Get handles for all entities in all sequences. */
-  inline void get_entities( MBRange& entities_out ) const;
+  inline void get_entities( Range& entities_out ) const;
   
     /**\brief Get handles for all entities in all sequences. */
-  inline void get_entities( std::vector<MBEntityHandle>& entities_out ) const;
+  inline void get_entities( std::vector<EntityHandle>& entities_out ) const;
   
     /**\brief Get number of entities represented by all sequences. */
-  inline MBEntityID get_number_entities() const;
+  inline EntityID get_number_entities() const;
   
-  MBErrorCode check_valid_handles( MBEntityHandle first, MBEntityHandle last ) const;
+  ErrorCode check_valid_handles( EntityHandle first, EntityHandle last ) const;
   
     /**\brief Remove entities 
      *
@@ -196,8 +199,8 @@
      * specified entities (e.g. split sequences, delete sequences,
      * free SequenceData instances, etc.)
      */
-  MBErrorCode erase( MBEntityHandle first, MBEntityHandle last );
-  MBErrorCode erase( MBEntityHandle entity );
+  ErrorCode erase( EntityHandle first, EntityHandle last );
+  ErrorCode erase( EntityHandle entity );
   
   /**\brief Test if this instance contains no sequences */
   bool empty() const
@@ -215,8 +218,8 @@
    * find_free_sequence() to find appropriate values for the
    * creation of a new EntitySequence.
    */
-  iterator find_free_handle( MBEntityHandle min_start_handle,
-                             MBEntityHandle max_end_handle,
+  iterator find_free_handle( EntityHandle min_start_handle,
+                             EntityHandle max_end_handle,
                              bool& append_out,
                              int values_per_ent = 0 );
   
@@ -226,9 +229,9 @@
      * overlap any existing EntitySequence. 
      *\return First handle of block, or zero if no block found.
      */
-  MBEntityHandle find_free_block( MBEntityID num_entities, 
-                                  MBEntityHandle min_start_handle,
-                                  MBEntityHandle max_end_handle );
+  EntityHandle find_free_block( EntityID num_entities, 
+                                  EntityHandle min_start_handle,
+                                  EntityHandle max_end_handle );
   
     /**\brief Find block of free handles
      *
@@ -247,11 +250,11 @@
      *                         the existing EntitySequences using have a different
      *                         value than the passed one.
      */
-  MBEntityHandle find_free_sequence( MBEntityID num_entities, 
-                                     MBEntityHandle min_start_handle,
-                                     MBEntityHandle max_end_handle,
+  EntityHandle find_free_sequence( EntityID num_entities, 
+                                     EntityHandle min_start_handle,
+                                     EntityHandle max_end_handle,
                                      SequenceData*& sequence_data_out,
-                                     MBEntityID &sequence_data_size,
+                                     EntityID &sequence_data_size,
                                      int values_per_ent = 0 );
 
     /**\brief Check if block of handles is free.
@@ -261,8 +264,8 @@
      * is contained within an unused portion of a SequenceData,
      * the SequenceData is returned.
      */
-  bool is_free_sequence( MBEntityHandle start_handle, 
-                         MBEntityID num_entities,
+  bool is_free_sequence( EntityHandle start_handle, 
+                         EntityID num_entities,
                          SequenceData*& sequence_data_out,
                          int values_per_ent = 0 );
   
@@ -302,33 +305,33 @@
      *\param block_start Output: Smallest possible start handle for new sequence.
      *\param block_end   Output: Largest possible end handle for new sequence.
      */
-  MBErrorCode is_free_handle( MBEntityHandle handle,
+  ErrorCode is_free_handle( EntityHandle handle,
                               iterator& seq_ptr_out,
                               SequenceData*& data_ptr_out,
-                              MBEntityHandle& block_start,
-                              MBEntityHandle& block_end,
+                              EntityHandle& block_start,
+                              EntityHandle& block_end,
                               int values_per_ent = 0 );  
 
-  MBEntityHandle last_free_handle( MBEntityHandle after_this ) const;
+  EntityHandle last_free_handle( EntityHandle after_this ) const;
 
     /**\brief Notify that sequence was prepended to
      *
      * Notify of sequence modifications so we can check if
      * sequence needs to be merged.
      */
-  MBErrorCode notify_prepended( iterator seq );
+  ErrorCode notify_prepended( iterator seq );
   
     /**\brief Notify that sequence was appended to
      *
      * Notify of sequence modifications so we can check if
      * sequence needs to be merged.
      */
-  MBErrorCode notify_appended( iterator seq );
+  ErrorCode notify_appended( iterator seq );
     
   void get_memory_use( unsigned long& total_entity_storage,
                        unsigned long& total_storage ) const;
   
-  void get_memory_use( MBEntityHandle start, MBEntityHandle end,
+  void get_memory_use( EntityHandle start, EntityHandle end,
                        unsigned long& total_entity_storage,
                        unsigned long& total_amortized_storage ) const;
                        
@@ -340,10 +343,10 @@
      * Get the sum of the size of all EntitySequences referencing
      * a SequenceData.  Used for memory use calculations.
      */
-  MBEntityID get_occupied_size( const SequenceData* ) const;
+  EntityID get_occupied_size( const SequenceData* ) const;
 };
 
-inline EntitySequence* TypeSequenceManager::find( MBEntityHandle h ) const
+inline EntitySequence* TypeSequenceManager::find( EntityHandle h ) const
 {
   if (!lastReferenced) // only null if empty
     return 0;
@@ -355,7 +358,7 @@
     return i == end() ? 0 : (lastReferenced = *i);
   }
 }   
-inline EntitySequence* TypeSequenceManager::find( MBEntityHandle h )
+inline EntitySequence* TypeSequenceManager::find( EntityHandle h )
 {
   if (!lastReferenced) // only null if empty
     return 0;
@@ -368,7 +371,7 @@
   }
 }   
 
-inline MBErrorCode TypeSequenceManager::find( MBEntityHandle h, EntitySequence*& seq )
+inline ErrorCode TypeSequenceManager::find( EntityHandle h, EntitySequence*& seq )
 {
   if (!lastReferenced) { // only null if empty
     seq = 0;
@@ -392,7 +395,7 @@
   }
 }   
 
-inline MBErrorCode TypeSequenceManager::find( MBEntityHandle h, const EntitySequence*& seq ) const
+inline ErrorCode TypeSequenceManager::find( EntityHandle h, const EntitySequence*& seq ) const
 {
   if (!lastReferenced) { // only null if empty
     seq = 0;
@@ -419,26 +422,28 @@
 inline const EntitySequence* TypeSequenceManager::get_last_accessed() const
   { return lastReferenced; /* only NULL if TypeSequenceManager is empty */ }
 
-inline void TypeSequenceManager::get_entities( MBRange& entities_out ) const
+inline void TypeSequenceManager::get_entities( Range& entities_out ) const
 {
-  MBRange::iterator in = entities_out.begin();
+  Range::iterator in = entities_out.begin();
   for (const_iterator i = begin(); i != end(); ++i)
     in = entities_out.insert( in, (*i)->start_handle(), (*i)->end_handle() );
 }
 
-inline void TypeSequenceManager::get_entities( std::vector<MBEntityHandle>& entities_out ) const
+inline void TypeSequenceManager::get_entities( std::vector<EntityHandle>& entities_out ) const
 {
   for (const_iterator i = begin(); i != end(); ++i)
-    for (MBEntityHandle j = (*i)->start_handle(); j <= (*i)->end_handle(); ++j)
+    for (EntityHandle j = (*i)->start_handle(); j <= (*i)->end_handle(); ++j)
       entities_out.push_back( j );
 }
 
-inline MBEntityID TypeSequenceManager::get_number_entities() const
+inline EntityID TypeSequenceManager::get_number_entities() const
 {
-  MBEntityID count = 0;
+  EntityID count = 0;
   for (const_iterator i = begin(); i != end(); ++i)
     count += (*i)->size();
   return count;
 }
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/UnstructuredElemSeq.cpp
===================================================================
--- MOAB/trunk/src/UnstructuredElemSeq.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/UnstructuredElemSeq.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,23 +1,25 @@
 #include "UnstructuredElemSeq.hpp"
 #include "SequenceData.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 
-UnstructuredElemSeq::UnstructuredElemSeq( MBEntityHandle start_handle, 
-                                          MBEntityID entity_count, 
+namespace moab {
+
+UnstructuredElemSeq::UnstructuredElemSeq( EntityHandle start_handle, 
+                                          EntityID entity_count, 
                                           unsigned nodes_per_entity,
                                           SequenceData* data )
   : ElementSequence( start_handle, entity_count, nodes_per_entity, data )
   {}
   
 
-UnstructuredElemSeq::UnstructuredElemSeq( MBEntityHandle start_handle, 
-                                          MBEntityID entity_count, 
+UnstructuredElemSeq::UnstructuredElemSeq( EntityHandle start_handle, 
+                                          EntityID entity_count, 
                                           unsigned nodes_per_entity,
-                                          MBEntityID data_size )
+                                          EntityID data_size )
   : ElementSequence( start_handle, entity_count, nodes_per_entity,
                       new SequenceData( 1, start_handle, start_handle + data_size - 1))
 {
-  data()->create_sequence_data( 0, nodes_per_entity * sizeof(MBEntityHandle) );
+  data()->create_sequence_data( 0, nodes_per_entity * sizeof(EntityHandle) );
 }
 
 
@@ -30,7 +32,7 @@
 
 
 EntitySequence*
-UnstructuredElemSeq::split( MBEntityHandle here )
+UnstructuredElemSeq::split( EntityHandle here )
 {
   if (here <= start_handle() || here > end_handle())
     return 0;
@@ -40,9 +42,9 @@
 
 
 SequenceData*
-UnstructuredElemSeq::create_data_subset( MBEntityHandle start, MBEntityHandle end ) const
+UnstructuredElemSeq::create_data_subset( EntityHandle start, EntityHandle end ) const
 {
-  int esize = nodes_per_element() * sizeof(MBEntityHandle);
+  int esize = nodes_per_element() * sizeof(EntityHandle);
   return data()->subset(start, end, &esize );
 }
 
@@ -51,16 +53,16 @@
 UnstructuredElemSeq::get_const_memory_use( unsigned long& bytes_per_entity,
                                            unsigned long& size_of_sequence ) const
 {
-  bytes_per_entity = nodes_per_element() * sizeof(MBEntityHandle);
+  bytes_per_entity = nodes_per_element() * sizeof(EntityHandle);
   size_of_sequence = sizeof(this);
 }
 
-MBErrorCode
-UnstructuredElemSeq::get_connectivity( MBEntityHandle handle,
-                                       std::vector<MBEntityHandle>& connect,
+ErrorCode
+UnstructuredElemSeq::get_connectivity( EntityHandle handle,
+                                       std::vector<EntityHandle>& connect,
                                        bool topological ) const
 {
-  MBEntityHandle const* conn = get_array() + nodes_per_element() * (handle - start_handle());
+  EntityHandle const* conn = get_array() + nodes_per_element() * (handle - start_handle());
   int len = topological ? MBCN::VerticesPerEntity(type()) : nodes_per_element();
   connect.reserve( connect.size() + len );
   std::copy( conn, conn+len, std::back_inserter( connect ) );
@@ -68,12 +70,12 @@
 }
 
 
-MBErrorCode
-UnstructuredElemSeq::get_connectivity( MBEntityHandle handle,
-                                       MBEntityHandle const*& conn_ptr,
+ErrorCode
+UnstructuredElemSeq::get_connectivity( EntityHandle handle,
+                                       EntityHandle const*& conn_ptr,
                                        int& len,
                                        bool topological,
-                                       std::vector<MBEntityHandle>* ) const
+                                       std::vector<EntityHandle>* ) const
 {
   conn_ptr = get_array() + nodes_per_element() * (handle - start_handle());
   len = topological ? MBCN::VerticesPerEntity(type()) : nodes_per_element();
@@ -81,25 +83,27 @@
 }
 
 
-MBErrorCode
-UnstructuredElemSeq::set_connectivity( MBEntityHandle handle,
-                                       MBEntityHandle const* connect,
+ErrorCode
+UnstructuredElemSeq::set_connectivity( EntityHandle handle,
+                                       EntityHandle const* connect,
                                        int connect_length )
 {
   if ((unsigned)connect_length != nodes_per_element())
     return MB_INDEX_OUT_OF_RANGE;
-  MBEntityHandle* conn_ptr = get_array() + nodes_per_element() * (handle - start_handle());
+  EntityHandle* conn_ptr = get_array() + nodes_per_element() * (handle - start_handle());
   std::copy( connect, connect+connect_length, conn_ptr );
   return MB_SUCCESS;
 }
 
 
-MBEntityHandle* UnstructuredElemSeq::get_connectivity_array()
+EntityHandle* UnstructuredElemSeq::get_connectivity_array()
   { return get_array(); }
 
-MBErrorCode UnstructuredElemSeq::push_back( MBEntityID count )
+ErrorCode UnstructuredElemSeq::push_back( EntityID count )
   { return EntitySequence::append_entities(count); }
 
-MBErrorCode UnstructuredElemSeq::push_front( MBEntityID count )
+ErrorCode UnstructuredElemSeq::push_front( EntityID count )
   { return EntitySequence::prepend_entities(count); }
 
+
+} // namespace moab

Modified: MOAB/trunk/src/UnstructuredElemSeq.hpp
===================================================================
--- MOAB/trunk/src/UnstructuredElemSeq.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/UnstructuredElemSeq.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,71 +4,74 @@
 #include "ElementSequence.hpp"
 #include "SequenceData.hpp"
 
+namespace moab {
 
 class UnstructuredElemSeq : public ElementSequence
 {
 public:
 
-  UnstructuredElemSeq( MBEntityHandle start_handle, 
-                       MBEntityID entity_count, 
+  UnstructuredElemSeq( EntityHandle start_handle, 
+                       EntityID entity_count, 
                        unsigned nodes_per_entity,
                        SequenceData* data );
 
-  UnstructuredElemSeq( MBEntityHandle start_handle, 
-                       MBEntityID entity_count, 
+  UnstructuredElemSeq( EntityHandle start_handle, 
+                       EntityID entity_count, 
                        unsigned nodes_per_entity,
-                       MBEntityID sequence_data_size);
+                       EntityID sequence_data_size);
 
   virtual ~UnstructuredElemSeq();
 
   int values_per_entity() const;
   
-  virtual EntitySequence* split( MBEntityHandle here );
+  virtual EntitySequence* split( EntityHandle here );
   
-  SequenceData* create_data_subset( MBEntityHandle start, MBEntityHandle end ) const;
+  SequenceData* create_data_subset( EntityHandle start, EntityHandle end ) const;
                        
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        std::vector<MBEntityHandle>& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        std::vector<EntityHandle>& connect,
                                         bool topological = false ) const;
   
-  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
-                                        MBEntityHandle const*& connect,
+  virtual ErrorCode get_connectivity( EntityHandle handle,
+                                        EntityHandle const*& connect,
                                         int &connect_length,
                                         bool topological = false,
-                                        std::vector<MBEntityHandle>* storage = 0
+                                        std::vector<EntityHandle>* storage = 0
                                        ) const;
 
-  MBErrorCode set_connectivity( MBEntityHandle handle,
-                                MBEntityHandle const* connect,
+  ErrorCode set_connectivity( EntityHandle handle,
+                                EntityHandle const* connect,
                                 int connect_length );
   
-  MBEntityHandle* get_connectivity_array();
+  EntityHandle* get_connectivity_array();
   
-  MBErrorCode push_front( MBEntityID count );
-  MBErrorCode push_back ( MBEntityID count );
+  ErrorCode push_front( EntityID count );
+  ErrorCode push_back ( EntityID count );
   
   
   void get_const_memory_use( unsigned long& bytes_per_entity,
                              unsigned long& size_of_sequence ) const;
 protected:
 
-  inline MBEntityHandle const* get_array() const
+  inline EntityHandle const* get_array() const
   {
-    return reinterpret_cast<MBEntityHandle const*>(data()->get_sequence_data(0))
+    return reinterpret_cast<EntityHandle const*>(data()->get_sequence_data(0))
       + nodes_per_element() * (start_handle() - data()->start_handle());
   }
 
-  inline MBEntityHandle* get_array()
+  inline EntityHandle* get_array()
   {
-    return reinterpret_cast<MBEntityHandle*>(data()->get_sequence_data(0))
+    return reinterpret_cast<EntityHandle*>(data()->get_sequence_data(0))
       + nodes_per_element() * (start_handle() - data()->start_handle());
   }
 
-  UnstructuredElemSeq( UnstructuredElemSeq& split_from, MBEntityHandle here )
+  UnstructuredElemSeq( UnstructuredElemSeq& split_from, EntityHandle here )
     : ElementSequence( split_from, here )
    {}
 };
 
+} // namespace moab
+
 #endif
 
   

Copied: MOAB/trunk/src/Util.cpp (from rev 3583, MOAB/trunk/src/MBUtil.cpp)
===================================================================
--- MOAB/trunk/src/Util.cpp	                        (rev 0)
+++ MOAB/trunk/src/Util.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,181 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+//-------------------------------------------------------------------------
+// Filename      : Util.cpp
+//
+// Purpose       : This file contains utility functions that can be used
+//                 with MB
+//
+// Special Notes : This is a pure virtual class, to prevent instantiation.
+//                 All functions are static, called like this:
+//                 Util::function_name();
+//
+// Creator       : Ray J. Meyers
+//
+// Date          : 09/01/02
+//
+// Owner         : Ray J. meyers
+//-------------------------------------------------------------------------
+
+#include "moab/Util.hpp"
+#include "moab/Interface.hpp"
+#include <assert.h>
+#include <math.h>
+#include "moab/MBCN.hpp"
+#include <algorithm>
+
+namespace moab {
+
+//! temporary normal function for MBEntities.  This should be moved to
+//! an appropriate MB algorithms file
+
+void Util::normal(Interface* MB, EntityHandle handle, double& x, double& y, double& z)
+{
+
+   // get connectivity
+   const EntityHandle *connectivity;
+   int number_nodes = 0;
+   MB->get_connectivity(handle, connectivity, number_nodes, true);
+   assert(number_nodes >= 3);
+
+   // get_coordinates
+   double coords[3][3];
+   MB->get_coords(&(connectivity[0]), 1, coords[0]);
+   MB->get_coords(&(connectivity[1]), 1, coords[1]);
+   MB->get_coords(&(connectivity[2]), 1, coords[2]);
+
+   double vecs[2][3];
+   vecs[0][0] = coords[1][0] - coords[0][0];
+   vecs[0][1] = coords[1][1] - coords[0][1];
+   vecs[0][2] = coords[1][2] - coords[0][2];
+   vecs[1][0] = coords[2][0] - coords[0][0];
+   vecs[1][1] = coords[2][1] - coords[0][1];
+   vecs[1][2] = coords[2][2] - coords[0][2];
+
+   x = vecs[0][1] * vecs[1][2] - vecs[0][2] * vecs[1][1];
+   y = vecs[0][2] * vecs[1][0] - vecs[0][0] * vecs[1][2];
+   z = vecs[0][0] * vecs[1][1] - vecs[0][1] * vecs[1][0];
+
+   double mag = sqrt(x*x + y*y + z*z);
+   if(mag !=0)
+   {
+     x /= mag;
+     y /= mag;
+     z /= mag;
+   }
+}
+void Util::centroid(Interface *MB, EntityHandle handle, Coord &coord)
+{
+   const EntityHandle *connectivity;
+   int number_nodes = 0;
+   MB->get_connectivity(handle, connectivity, number_nodes,true);
+   
+   coord.x=0.0;
+   coord.y=0.0;
+   coord.z=0.0;
+
+   for(int i = 0; i< number_nodes; i++)
+   {
+      double node_coords[3];
+      MB->get_coords(&(connectivity[i]), 1, node_coords);
+     
+      coord.x+=node_coords[0];
+      coord.y+=node_coords[1];
+      coord.z+=node_coords[2];
+   }
+   
+   coord.x/=(double)number_nodes;
+   coord.y/=(double)number_nodes;
+   coord.z/=(double)number_nodes;
+}
+
+/*//This function calculates the coordinates for the centers of each edges of the entity specified by handle. The coordinates are returned in the list coords_list
+void Util::edge_centers(Interface *MB, EntityHandle handle, std::vector<Coord> &coords_list)
+{
+  MB canon_tool(MB);
+  EntityType type;
+  int i = 0;
+  int number_nodes = 0;
+  double coords[2][3];
+  const EntityHandle *connectivity;
+
+
+  MB->get_connectivity(handle, connectivity, number_nodes,true);
+  
+  MB->type_from_handle(handle,type);
+  
+  const struct MBCN::ConnMap* conn_map = &(canon_tool.mConnectivityMap[type][0]); //get edge sub_elements
+
+  coords_list.resize(conn_map->num_sub_elements);
+
+  for(i = 0; i<conn_map->num_sub_elements; i++)
+  {
+    
+    MB->get_coords(connectivity[conn_map->conn[i][0]], coords[0]);
+    MB->get_coords(connectivity[conn_map->conn[i][1]], coords[1]);
+
+    coords_list[i].x = (coords[0][0] + coords[1][0])/2.0;
+    coords_list[i].y = (coords[0][1] + coords[1][1])/2.0;
+    coords_list[i].z = (coords[0][2] + coords[1][2])/2.0;
+
+  }
+
+
+
+}
+*/  
+
+/*
+void Util::face_centers(Interface *MB, EntityHandle handle, std::vector<Coord> &coords_list)
+{
+  MB canon_tool(MB);
+  EntityType type;
+  int i = 0;
+  int number_nodes = 0;
+  double node_coords[3];
+  const EntityHandle *connectivity;
+
+
+  MB->get_connectivity(handle, connectivity, number_nodes,true);
+  
+  MB->type_from_handle(handle,type);
+  
+  const struct MBCN::ConnMap* conn_map = &(canon_tool.mConnectivityMap[type][1]); //get face sub_elements
+
+  coords_list.resize(conn_map->num_sub_elements);
+
+  for(i = 0; i<conn_map->num_sub_elements;i++)
+  {
+    int number_nodes_per_element = conn_map->num_nodes_per_sub_element[i];
+
+    for(int j = 0; j<number_nodes_per_element; j++)
+    {
+      MB->get_coords(connectivity[conn_map->conn[i][j]], node_coords);
+     
+      coords_list[i].x+=node_coords[0];
+      coords_list[i].y+=node_coords[1];
+      coords_list[i].z+=node_coords[2];
+    }
+   
+    coords_list[i].x/=(double)number_nodes_per_element;
+    coords_list[i].y/=(double)number_nodes_per_element;
+    coords_list[i].z/=(double)number_nodes_per_element;
+  }
+
+}
+*/
+
+} // namespace moab

Modified: MOAB/trunk/src/VarLenTag.hpp
===================================================================
--- MOAB/trunk/src/VarLenTag.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/VarLenTag.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+namespace moab {
+
 /* Remove this preprocessor macro to compile 
  * simple implementation w/ no inlined storage
  */
@@ -221,6 +223,8 @@
     memcpy( resize(size), data, size );
 }
 
+} // namespace moab
+
 #endif
 
 

Modified: MOAB/trunk/src/VertexSequence.cpp
===================================================================
--- MOAB/trunk/src/VertexSequence.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/VertexSequence.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,21 +1,23 @@
 #include "VertexSequence.hpp"
 
+namespace moab {
+
 VertexSequence::~VertexSequence() {}
 
-EntitySequence* VertexSequence::split( MBEntityHandle here )
+EntitySequence* VertexSequence::split( EntityHandle here )
   { return new VertexSequence( *this, here ); }
 
-SequenceData* VertexSequence::create_data_subset( MBEntityHandle start,
-                                                  MBEntityHandle end ) const
+SequenceData* VertexSequence::create_data_subset( EntityHandle start,
+                                                  EntityHandle end ) const
 {
   const int sizes[] = { sizeof(double), sizeof(double), sizeof(double) };
   return data()->subset(start, end, sizes );
 }
   
-MBErrorCode VertexSequence::push_back( MBEntityID count )
+ErrorCode VertexSequence::push_back( EntityID count )
   { return EntitySequence::append_entities(count); }
 
-MBErrorCode VertexSequence::push_front( MBEntityID count )
+ErrorCode VertexSequence::push_front( EntityID count )
   { return EntitySequence::prepend_entities(count); }
 
 void VertexSequence::get_const_memory_use( unsigned long& per_ent, unsigned long& seq ) const
@@ -23,3 +25,5 @@
   per_ent = 3 * sizeof(double);
   seq = sizeof(*this);
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/VertexSequence.hpp
===================================================================
--- MOAB/trunk/src/VertexSequence.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/VertexSequence.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,19 +4,21 @@
 #include "EntitySequence.hpp"
 #include "SequenceData.hpp"
 
+namespace moab {
+
 class VertexSequence : public EntitySequence
 {
 public:
 
-  VertexSequence( MBEntityHandle start,
-                  MBEntityID count,
+  VertexSequence( EntityHandle start,
+                  EntityID count,
                   SequenceData* data )
     : EntitySequence( start, count, data )
     {}
   
-  VertexSequence( MBEntityHandle start,
-                  MBEntityID count,
-                  MBEntityID data_size )
+  VertexSequence( EntityHandle start,
+                  EntityID count,
+                  EntityID data_size )
     : EntitySequence( start, count, new SequenceData( 3, start, start+data_size-1 ) )
     {
       data()->create_sequence_data( X, sizeof(double) );
@@ -26,41 +28,41 @@
   
   virtual ~VertexSequence();
   
-  inline MBErrorCode get_coordinates( MBEntityHandle handle,
+  inline ErrorCode get_coordinates( EntityHandle handle,
                                       double& x,
                                       double& y,
                                       double& z ) const;
 
-  inline MBErrorCode get_coordinates( MBEntityHandle handle,
+  inline ErrorCode get_coordinates( EntityHandle handle,
                                       double coords[3] ) const;
 
-  inline MBErrorCode get_coordinates_ref( MBEntityHandle handle,
+  inline ErrorCode get_coordinates_ref( EntityHandle handle,
                                           const double*& x,
                                           const double*& y,
                                           const double*& z ) const;
 
-  inline MBErrorCode set_coordinates( MBEntityHandle entity,
+  inline ErrorCode set_coordinates( EntityHandle entity,
                                       double x, 
                                       double y,
                                       double z );
 
-  inline MBErrorCode set_coordinates( MBEntityHandle entity,
+  inline ErrorCode set_coordinates( EntityHandle entity,
                                       const double xyz[3] );
 
-  inline MBErrorCode get_coordinate_arrays( double*& x, 
+  inline ErrorCode get_coordinate_arrays( double*& x, 
                                             double*& y, 
                                             double*& z );
 
-  inline MBErrorCode get_coordinate_arrays( const double*& x,
+  inline ErrorCode get_coordinate_arrays( const double*& x,
                                             const double*& y,
                                             const double*& z ) const;
  
-  EntitySequence* split( MBEntityHandle here );
+  EntitySequence* split( EntityHandle here );
   
-  SequenceData* create_data_subset( MBEntityHandle start, MBEntityHandle end ) const;
+  SequenceData* create_data_subset( EntityHandle start, EntityHandle end ) const;
   
-  MBErrorCode push_front( MBEntityID count );
-  MBErrorCode push_back( MBEntityID count );
+  ErrorCode push_front( EntityID count );
+  ErrorCode push_back( EntityID count );
   
   void get_const_memory_use( unsigned long& bytes_per_entity,
                              unsigned long& size_of_sequence ) const;
@@ -87,28 +89,28 @@
   inline const double* y_array() const { return array(Y); }
   inline const double* z_array() const { return array(Z); }
   
-  VertexSequence( VertexSequence& split_from, MBEntityHandle here )
+  VertexSequence( VertexSequence& split_from, EntityHandle here )
     : EntitySequence( split_from, here )
     {}
 };
 
   
-MBErrorCode VertexSequence::get_coordinates( MBEntityHandle handle,
+ErrorCode VertexSequence::get_coordinates( EntityHandle handle,
                                              double& x,
                                              double& y,
                                              double& z ) const
 {
-  MBEntityID offset = handle - data()->start_handle();
+  EntityID offset = handle - data()->start_handle();
   x = x_array()[offset];
   y = y_array()[offset];
   z = z_array()[offset];
   return MB_SUCCESS;
 }
 
-MBErrorCode VertexSequence::get_coordinates( MBEntityHandle handle,
+ErrorCode VertexSequence::get_coordinates( EntityHandle handle,
                                              double coords[3] ) const
 {
-  MBEntityID offset = handle - data()->start_handle();
+  EntityID offset = handle - data()->start_handle();
   coords[X] = x_array()[offset];
   coords[Y] = y_array()[offset];
   coords[Z] = z_array()[offset];
@@ -116,56 +118,58 @@
 }
   
 
-MBErrorCode VertexSequence::get_coordinates_ref( MBEntityHandle handle,
+ErrorCode VertexSequence::get_coordinates_ref( EntityHandle handle,
                                                  const double*& x,
                                                  const double*& y,
                                                  const double*& z ) const
 {
-  MBEntityID offset = handle - data()->start_handle();
+  EntityID offset = handle - data()->start_handle();
   x = x_array()+offset;
   y = y_array()+offset;
   z = z_array()+offset;
   return MB_SUCCESS;
 }
 
-MBErrorCode VertexSequence::set_coordinates( MBEntityHandle entity,
+ErrorCode VertexSequence::set_coordinates( EntityHandle entity,
                                              double x, 
                                              double y,
                                              double z )
 {
-  MBEntityID offset = entity - data()->start_handle();
+  EntityID offset = entity - data()->start_handle();
   x_array()[offset] = x;
   y_array()[offset] = y;
   z_array()[offset] = z;
   return MB_SUCCESS;
 }
 
-MBErrorCode VertexSequence::set_coordinates( MBEntityHandle entity,
+ErrorCode VertexSequence::set_coordinates( EntityHandle entity,
                                              const double* xyz )
 {
-  MBEntityID offset = entity - data()->start_handle();
+  EntityID offset = entity - data()->start_handle();
   x_array()[offset] = xyz[0];
   y_array()[offset] = xyz[1];
   z_array()[offset] = xyz[2];
   return MB_SUCCESS;
 }
 
-MBErrorCode VertexSequence::get_coordinate_arrays( double*& x, 
+ErrorCode VertexSequence::get_coordinate_arrays( double*& x, 
                                                    double*& y, 
                                                    double*& z )
 {
-  MBEntityID offset = start_handle() - data()->start_handle();
+  EntityID offset = start_handle() - data()->start_handle();
   x = x_array()+offset;
   y = y_array()+offset;
   z = z_array()+offset;
   return MB_SUCCESS;
 }
   
-MBErrorCode VertexSequence::get_coordinate_arrays( const double*& x,
+ErrorCode VertexSequence::get_coordinate_arrays( const double*& x,
                                                    const double*& y,
                                                    const double*& z ) const
 {
   return get_coordinates_ref( start_handle(), x, y, z ); 
 }
 
+} // namespace moab
+
 #endif

Copied: MOAB/trunk/src/WriteUtil.cpp (from rev 3583, MOAB/trunk/src/MBWriteUtil.cpp)
===================================================================
--- MOAB/trunk/src/WriteUtil.cpp	                        (rev 0)
+++ MOAB/trunk/src/WriteUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,796 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifdef WIN32
+#pragma warning(disable : 4786)
+#endif
+
+#include "WriteUtil.hpp"
+#include "moab/Core.hpp"
+#include "Error.hpp"
+#include "SequenceManager.hpp"
+#include "ElementSequence.hpp"
+#include "VertexSequence.hpp"
+#include "TagServer.hpp"
+#include "AEntityFactory.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "RangeSeqIntersectIter.hpp"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <assert.h>
+#include <iostream>
+
+#ifdef WIN32
+#  define stat _stat
+#else
+#  include <unistd.h>
+#endif
+
+namespace moab {
+
+WriteUtil::WriteUtil(Core* mdb, Error* error_handler) 
+    : WriteUtilIface(), mMB(mdb), mError(error_handler)
+{
+}
+
+  //! Check if the specified file already exists.
+  //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
+  //! if file does exist, or MB_FAILURE for some other error condition.
+ErrorCode WriteUtil::check_doesnt_exist( const char* file_name )
+{
+  struct stat s;
+  if (0 == stat( file_name, &s ))
+  {
+    report_error( "%s: file already exists.\n", file_name );
+    return MB_ALREADY_ALLOCATED;  
+  }
+  else if (errno == ENOENT)
+  {
+    return MB_SUCCESS;
+  }
+  else
+  {
+    return MB_FAILURE;
+  }
+}
+
+
+ErrorCode WriteUtil::get_node_arrays(
+    const int num_arrays,
+    const int num_nodes, 
+    const Range& entities, 
+    Tag node_id_tag,
+    const int start_node_id,
+    std::vector<double*>& arrays)
+{
+  // check the data coming into the function
+  // dimension should be proper
+  if(num_arrays < 1 || num_arrays > 3)
+    return MB_FAILURE;
+
+  // there should be some entities
+  //if(entities.empty())
+  //  return MB_FAILURE;
+  // The above necessitates annoying special cases for files 
+  // w/out vertices (e.g. a kD-tree).  Return NULL array
+  // pointers instead. - kraftcheck, 3-14-08
+  if (entities.empty()) {
+    arrays.clear();
+    arrays.resize( num_arrays, NULL );
+    return MB_SUCCESS;
+  }
+
+  // memory should already be allocated for us
+  int tmp_num_arrays = 0;
+  for (unsigned int i = 0; i < 3; i++)
+    if (i+1 <= arrays.size() && NULL != arrays[i]) tmp_num_arrays++;
+  if (0 == tmp_num_arrays)
+    return MB_FAILURE;
+
+  // get coordinate data
+  ErrorCode result = mMB->get_coords( entities, 
+                   num_arrays < 1 || arrays.size() < 1 ? NULL : arrays[0],
+                   num_arrays < 2 || arrays.size() < 2 ? NULL : arrays[1],
+                   num_arrays < 3 || arrays.size() < 3 ? NULL : arrays[2] );
+                   
+
+  if (0 == node_id_tag || MB_SUCCESS != result) 
+    return result;
+  
+    // now assign tags
+  std::vector<int> ids(num_nodes);
+  int node_id = start_node_id;
+  for (int i = 0; i < num_nodes; i++) ids[i] = node_id++;
+  result = mMB->tag_set_data(node_id_tag, entities, &ids[0]);
+
+  return result;
+}
+
+ErrorCode WriteUtil::get_node_array(
+    const int which_array, /* 0->X, 1->Y, 2->Z */
+    Range::const_iterator iter,
+    const Range::const_iterator end,
+    const size_t output_array_len,
+    double* const output_array)
+{
+  // check the data coming into the function
+  // dimension should be proper
+  if(which_array < 0 || which_array > 2)
+    return MB_FAILURE;
+
+  // there should be some entities
+  if(iter == end)
+    return MB_FAILURE;
+
+  // memory should already be allocated for us
+  if (NULL == output_array || 0 == output_array_len)
+    return MB_FAILURE;
+
+  // Sequence iterators
+  TypeSequenceManager::iterator seq_iter, seq_end;
+  seq_iter = mMB->sequence_manager()->entity_map(MBVERTEX).begin();
+  seq_end = mMB->sequence_manager()->entity_map(MBVERTEX).end();
+  
+  // loop over range, getting coordinate value
+  double* output_iter = output_array;
+  double* const output_end = output_array + output_array_len;
+  while (iter != end)
+  {
+      // Find the sqeuence containing the current handle
+    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
+      ++seq_iter;
+    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
+      return MB_FAILURE;
+    
+      // Determine how much of the sequence we want.
+    Range::pair_iterator pair(iter);
+    Range::const_iterator prev(end);
+    --prev;
+    EntityHandle range_end = pair->second;
+    EntityHandle sequence_end = (*seq_iter)->end_handle();
+    EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
+    if (end_handle > *prev)
+      end_handle = *prev;
+    EntityHandle count = end_handle - *iter + 1;
+    
+      // Get offset in sequence to start at
+    assert( *iter >= (*seq_iter)->start_handle() );
+    EntityHandle offset = *iter - (*seq_iter)->start_handle();
+    
+      // Get coordinate arrays from sequence
+    double* coord_array[3];
+    static_cast<VertexSequence*>(*seq_iter)
+      ->get_coordinate_arrays( coord_array[0], coord_array[1], coord_array[2]);
+    
+      // Copy data to ouput buffer
+    if (output_iter + count > output_end)
+      return MB_FAILURE;
+    memcpy( output_iter, coord_array[which_array] + offset, count * sizeof(double) );
+    
+      // Iterate
+    output_iter += count;
+    iter += count;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode WriteUtil::get_element_array(
+    const int num_elements, 
+    const int verts_per_element,
+    Tag node_id_tag,
+    const Range& elements, 
+    Tag element_id_tag,
+    int start_element_id,
+    int* element_array)
+{
+
+  // check the data we got
+  if(num_elements < 1)
+    return MB_FAILURE;
+  if(verts_per_element < 1)
+    return MB_FAILURE;
+  if(elements.empty())
+    return MB_FAILURE;
+  if(!element_array)
+    return MB_FAILURE;
+
+  TagServer* tag_server = mMB->tag_server();
+
+  Range::const_iterator range_iter = elements.begin();
+  Range::const_iterator range_iter_end = elements.end();
+
+  TypeSequenceManager::iterator seq_iter, seq_iter_end;
+  EntityType current_type = TYPE_FROM_HANDLE(*range_iter);
+ 
+  seq_iter = mMB->sequence_manager()->entity_map(current_type).begin();
+  seq_iter_end = mMB->sequence_manager()->entity_map(current_type).end();
+
+  // lets find the entity sequence which holds the first entity
+  TypeSequenceManager::iterator seq_iter_lookahead = seq_iter;
+  seq_iter_lookahead++;
+  for( ; seq_iter_lookahead != seq_iter_end && 
+      (*seq_iter_lookahead)->start_handle() < *range_iter; )
+  {
+    ++seq_iter;
+    ++seq_iter_lookahead;
+  }
+
+  // a look ahead iterator
+  Range::const_iterator range_iter_lookahead = range_iter;
+
+  // our main loop
+  for(; range_iter != range_iter_end && seq_iter != seq_iter_end; /* ++ is handled in loop*/ )
+  {
+    // find a range that fits in the current entity sequence
+    for(; range_iter_lookahead != range_iter_end && 
+        *range_iter_lookahead <= (*seq_iter)->end_handle(); 
+        ++range_iter_lookahead)
+    {}
+  
+    if(current_type != TYPE_FROM_HANDLE(*range_iter))
+    {
+      current_type = TYPE_FROM_HANDLE(*range_iter);
+      seq_iter = mMB->sequence_manager()->entity_map(current_type).begin();
+      seq_iter_end = mMB->sequence_manager()->entity_map(current_type).end();
+
+      // lets find the entity sequence which holds the first entity of this type
+      TypeSequenceManager::const_iterator seq_iter_lookahead = seq_iter;
+      seq_iter_lookahead++;
+      for( ; seq_iter_lookahead != seq_iter_end && 
+          (*seq_iter_lookahead)->start_handle() < *range_iter; )
+      {
+        ++seq_iter;
+        ++seq_iter_lookahead;
+      }
+    }
+
+    int i = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
+
+    // get the connectivity array
+    EntityHandle* conn_array = 
+      static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
+ 
+    EntityHandle start_handle = (*seq_iter)->start_handle();
+
+    for(Range::const_iterator tmp_iter = range_iter; 
+        tmp_iter != range_iter_lookahead;
+        ++tmp_iter)
+    {
+      // set the element id tag
+      tag_server->set_data(element_id_tag, *tmp_iter, &start_element_id);
+      ++start_element_id;
+
+      // for each node
+      for(int j=0; j<i; j++)
+      {
+        EntityHandle node = *(conn_array + j + i*(*tmp_iter - start_handle));
+        tag_server->get_data(node_id_tag, node, element_array);
+        element_array++;
+      }
+    }
+
+    // go to the next entity sequence
+    ++seq_iter;
+    // start with the next entities
+    range_iter = range_iter_lookahead;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode WriteUtil::get_element_array(
+    Range::const_iterator iter,
+    const Range::const_iterator end,
+    const int vertices_per_elem,
+    Tag node_id_tag,
+    const size_t elem_array_size, 
+    int *const element_array)
+{
+
+  // check the data we got
+  if(iter == end)
+    return MB_FAILURE;
+  if(vertices_per_elem < 1)
+    return MB_FAILURE;
+  if(!element_array || elem_array_size < (unsigned)vertices_per_elem)
+    return MB_FAILURE;
+
+  TagServer* tag_server = mMB->tag_server();
+
+
+  // Sequence iterators
+  TypeSequenceManager::const_iterator seq_iter, seq_end;
+  
+  // loop over range, getting coordinate value
+  EntityType current_type = MBMAXTYPE;
+  int* output_iter = element_array;
+  int*const output_end = element_array + elem_array_size;
+  while (iter != end)
+  {
+      // Make sure we have the right sequence list (and get the sequence 
+      // list for the first iteration.)
+    EntityType type = TYPE_FROM_HANDLE(*iter);
+    if (type != current_type)
+    {
+      if (type >= MBENTITYSET || type < MBEDGE)
+        return MB_FAILURE;
+      seq_iter = mMB->sequence_manager()->entity_map(type).begin();
+      seq_end  = mMB->sequence_manager()->entity_map(type).end();
+      current_type = type;
+    }
+    
+      // Find the sqeuence containing the current handle
+    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
+      ++seq_iter;
+    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
+      return MB_FAILURE;
+ 
+      // get the connectivity array
+    EntityHandle* conn_array = NULL;
+    int conn_size = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
+    conn_array = static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
+   
+      // Determine how much of the sequence we want.
+    Range::pair_iterator pair(iter);
+    Range::const_iterator prev(end);
+    --prev;
+    EntityHandle range_end = pair->second;
+    EntityHandle sequence_end = (*seq_iter)->end_handle();
+    EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
+    if (end_handle > *prev)
+      end_handle = *prev;
+    EntityHandle count = end_handle - *iter + 1;
+    
+      // Get offset in sequence to start at
+    assert( *iter >= (*seq_iter)->start_handle() );
+    EntityHandle offset = *iter - (*seq_iter)->start_handle();
+
+      // Make sure sufficient space in output array
+    if (output_iter + (count * conn_size) > output_end)
+      return MB_FAILURE;
+
+      // If the nodes per element match, do in one call
+    conn_array += (conn_size * offset);
+    if (vertices_per_elem == conn_size)
+    {
+      ErrorCode rval = tag_server->get_data( node_id_tag, 
+                                               conn_array,
+                                               count * conn_size,
+                                               output_iter );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      output_iter += count * conn_size;
+    }
+      // Otherwise need to do one at a time
+    else
+    {
+      int min = vertices_per_elem > conn_size ? conn_size : vertices_per_elem;
+      for (EntityHandle i = 0; i < count; ++i)
+      {
+        ErrorCode rval = tag_server->get_data( node_id_tag,
+                                                 conn_array,
+                                                 min,
+                                                 output_iter );
+        if (MB_SUCCESS != rval)
+          return rval;
+
+        output_iter += min;
+        conn_array += conn_size;
+
+        if (vertices_per_elem > conn_size) // need to pad
+        {
+          memset( output_iter, 0, sizeof(int) * (vertices_per_elem - conn_size) );
+          output_iter += (vertices_per_elem - conn_size);
+        }
+      }
+    }
+
+    iter += count;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode WriteUtil::get_element_array(
+                                       Range::const_iterator iter,
+                                       const Range::const_iterator end,
+                                       const int vertices_per_elem,
+                                       const size_t elem_array_size, 
+                                       EntityHandle *const element_array )
+{
+  // check the data we got
+  if(iter == end)
+    return MB_FAILURE;
+  if(vertices_per_elem < 1)
+    return MB_FAILURE;
+  if(!element_array || elem_array_size < (unsigned)vertices_per_elem)
+    return MB_FAILURE;
+
+  // Sequence iterators
+  TypeSequenceManager::const_iterator seq_iter, seq_end;
+  
+  // loop over range, getting coordinate value
+  EntityType current_type = MBMAXTYPE;
+  EntityHandle* output_iter = element_array;
+  EntityHandle*const output_end = element_array + elem_array_size;
+  while (iter != end)
+  {
+      // Make sure we have the right sequence list (and get the sequence 
+      // list for the first iteration.)
+    EntityType type = TYPE_FROM_HANDLE(*iter);
+    if (type != current_type)
+    {
+      if (type >= MBENTITYSET || type < MBEDGE)
+        return MB_FAILURE;
+      seq_iter = mMB->sequence_manager()->entity_map(type).begin();
+      seq_end  = mMB->sequence_manager()->entity_map(type).end();
+      current_type = type;
+    }
+    
+      // Find the sqeuence containing the current handle
+    while (seq_iter != seq_end && (*seq_iter)->end_handle() < *iter)
+      ++seq_iter;
+    if (seq_iter == seq_end || *iter < (*seq_iter)->start_handle())
+      return MB_FAILURE;
+ 
+      // get the connectivity array
+    EntityHandle* conn_array = NULL;
+    int conn_size = static_cast<ElementSequence*>(*seq_iter)->nodes_per_element();
+    if (conn_size != vertices_per_elem)
+      return MB_FAILURE;
+    conn_array = static_cast<ElementSequence*>(*seq_iter)->get_connectivity_array();
+   
+      // Determine how much of the sequence we want.
+    Range::pair_iterator pair(iter);
+    Range::const_iterator prev(end);
+    --prev;
+    EntityHandle range_end = pair->second;
+    EntityHandle sequence_end = (*seq_iter)->end_handle();
+    EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
+    if (end_handle > *prev)
+      end_handle = *prev;
+    EntityHandle count = end_handle - *iter + 1;
+    
+      // Get offset in sequence to start at
+    assert( *iter >= (*seq_iter)->start_handle() );
+    EntityHandle offset = *iter - (*seq_iter)->start_handle();
+
+      // Make sure sufficient space in output array
+    if (output_iter + (count * conn_size) > output_end)
+      return MB_FAILURE;
+
+      // Copy connectivity into output array
+    conn_array += (conn_size * offset);
+    memcpy( output_iter, conn_array, count * conn_size * sizeof(EntityHandle));
+    output_iter += count * conn_size;
+    iter += count;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode WriteUtil::get_poly_array_size(
+      Range::const_iterator ,
+      const Range::const_iterator ,
+      int&  )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+ErrorCode WriteUtil::get_poly_arrays(
+      Range::const_iterator& ,
+      const Range::const_iterator ,
+      const Tag ,
+      size_t& ,
+      int *const ,
+      size_t& ,
+      int*const ,
+      int&  )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+      
+ErrorCode WriteUtil::gather_nodes_from_elements(
+      const Range& elements,
+      const Tag node_bit_mark_tag,
+      Range& nodes
+      )
+{
+  bool printed_warning = false;
+
+  if(elements.empty())
+    return MB_SUCCESS;
+
+  if (TYPE_FROM_HANDLE(elements.front()) <= MBVERTEX ||
+      TYPE_FROM_HANDLE(elements.back()) >= MBENTITYSET)
+    return MB_TYPE_OUT_OF_RANGE;
+
+  TagServer* tag_server = mMB->tag_server();
+
+  // see if we need to use our own marking tag
+  Tag exporting_nodes_tag = 0;
+  if(node_bit_mark_tag)
+    exporting_nodes_tag = node_bit_mark_tag;
+  else
+  {
+    mMB->tag_create("__MBWriteUtil::exporting_nodes", 1, MB_TAG_BIT, 
+                     exporting_nodes_tag, NULL);
+  }
+
+  // the x,y,z tag handles we need
+  EntityHandle lower_bound = ~0, upper_bound = 0;
+  
+  std::vector<EntityHandle> tmp_conn;
+  
+  RangeSeqIntersectIter iter( mMB->sequence_manager() );
+  for (ErrorCode rval = iter.init( elements.begin(), elements.end() ); 
+       MB_FAILURE != rval; rval = iter.step()) {
+    if (MB_ENTITY_NOT_FOUND == rval) {
+      if (!printed_warning) {
+        std::cerr << "Warning: ignoring invalid element handle(s) in gather_nodes_from_elements" << std::endl;
+        printed_warning = true;
+      }
+      continue;
+    }
+    
+    ElementSequence* seq = static_cast<ElementSequence*>(iter.get_sequence());
+
+    // get the connectivity array
+    const EntityHandle* conn_array = seq->get_connectivity_array();
+    
+    // if unstructed mesh
+    if (conn_array) {
+      assert(iter.get_start_handle() >= seq->start_handle());
+      assert(iter.get_end_handle() <= seq->end_handle());
+      const EntityHandle offset = iter.get_start_handle() - seq->start_handle();
+      const EntityHandle num_elem = iter.get_end_handle() - iter.get_start_handle() + 1;
+      
+      conn_array += offset * seq->nodes_per_element();
+      const EntityHandle num_node = num_elem * seq->nodes_per_element();
+ 
+        // for each node
+      for (EntityHandle j = 0; j < num_node; j++)
+      {
+        EntityHandle node = conn_array[j];
+        if(node < lower_bound)
+          lower_bound = node;
+        if(node > upper_bound)
+          upper_bound = node;
+        unsigned char bit = 0x1;
+        rval = tag_server->set_data(exporting_nodes_tag, &node, 1, &bit);
+        assert(MB_SUCCESS == rval);
+        if (MB_SUCCESS != rval)
+          return rval;
+      }
+    }
+      // structured mesh
+    else {
+      for (EntityHandle h = iter.get_start_handle();
+           h < iter.get_end_handle(); ++h) {
+        tmp_conn.clear();
+        rval = seq->get_connectivity( h, tmp_conn, false );
+        if (MB_SUCCESS != rval) {
+          if(node_bit_mark_tag == 0)
+            mMB->tag_delete(exporting_nodes_tag);
+          return rval;
+        }
+
+          // for each node
+        for(size_t j=0; j<tmp_conn.size(); j++)
+        {
+          EntityHandle node = tmp_conn[j];
+          if(node < lower_bound)
+            lower_bound = node;
+          if(node > upper_bound)
+            upper_bound = node;
+          unsigned char bit = 0x1;
+          tag_server->set_data(exporting_nodes_tag, &node, 1, &bit);
+        }
+      }
+    }
+  }
+
+  // we can get a REALLY long loop if lower_bound is zero
+  assert(lower_bound != 0);
+  // gather up all the nodes
+  for(; upper_bound >= lower_bound; --upper_bound)
+  {
+    unsigned char node_marked=0;
+    tag_server->get_data(exporting_nodes_tag, &upper_bound, 1, &node_marked);
+    if(node_marked == 0x1)
+      nodes.insert(upper_bound);
+  }
+
+  // clean up our own marking tag
+  if(node_bit_mark_tag == 0)
+    mMB->tag_delete(exporting_nodes_tag);
+  
+  return MB_SUCCESS;
+}
+
+  //! assign ids to input elements starting with start_id, written to id_tag
+  //! if zero, assigns to GLOBAL_ID_TAG_NAME
+ErrorCode WriteUtil::assign_ids(Range &elements,
+                                    Tag id_tag,
+                                    const int start_id) 
+{
+  ErrorCode result;
+  if (0 == id_tag) {
+      // get the global id tag
+    result = mMB->tag_get_handle(GLOBAL_ID_TAG_NAME, id_tag);
+    if (MB_TAG_NOT_FOUND == result) {
+      int def_val = -1;
+      result = mMB->tag_create(GLOBAL_ID_TAG_NAME, 4, MB_TAG_DENSE, id_tag, &def_val);
+    }
+    
+    if (MB_SUCCESS != result) return result;
+  }
+  
+    // now assign the ids
+  int i;
+  Range::iterator rit;
+  ErrorCode tmp_result;
+  result = MB_SUCCESS;
+  for (i = start_id, rit = elements.begin(); rit != elements.end(); rit++, i++) {
+    tmp_result = mMB->tag_set_data(id_tag, &(*rit), 1, &i);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  
+  return result;
+}
+
+ErrorCode WriteUtil::report_error( const std::string& error )
+{
+  if(mError)
+    return mError->set_last_error(error);
+  else
+    return MB_FAILURE;
+}
+
+
+ErrorCode WriteUtil::report_error( const char* error, ... )
+{
+  va_list args;
+  va_start(args, error);
+  ErrorCode result = mError->set_last_error(error, args);
+  va_end(args);
+  return result;
+}
+
+
+ErrorCode WriteUtil::get_adjacencies( EntityHandle entity,
+                                          Tag id_tag,
+                                          std::vector<int>& adj )
+{
+  ErrorCode rval;
+  const EntityHandle* adj_array;
+  int num_adj, id;
+
+  TagServer* tag_server = mMB->tag_server();
+ 
+    // Get handles of adjacent entities 
+  rval = mMB->a_entity_factory()->get_adjacencies( entity, adj_array, num_adj );
+  if (MB_SUCCESS != rval)
+  {
+    adj.clear();
+    return rval;
+  }
+  
+    // Append IDs of adjacent entities -- skip meshsets
+  adj.resize( num_adj );  // pre-allocate space
+  adj.clear();            // clear used space
+  
+  const EntityHandle* const end = adj_array + num_adj;
+  for (const EntityHandle* iter = adj_array; iter != end; ++iter)
+  {
+    if (TYPE_FROM_HANDLE( *iter ) != MBENTITYSET)
+    {
+      rval = tag_server->get_data( id_tag, iter, 1, &id );
+      if (MB_SUCCESS != rval)
+        return rval;
+      adj.push_back( id );
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode WriteUtil::get_adjacencies( EntityHandle entity,
+                                          const EntityHandle*& adj_array,
+                                          int& num_adj )
+{
+  return mMB->a_entity_factory()->get_adjacencies( entity, adj_array, num_adj );
+}
+
+ErrorCode WriteUtil::get_tag_list( std::vector<Tag>& result_list,
+                                       const Tag* user_tag_list, 
+                                       int user_tag_list_length,
+                                       bool include_variable_length_tags )
+{
+  ErrorCode rval;
+  
+  if (user_tag_list) {
+    result_list.clear();
+    result_list.reserve( user_tag_list_length );
+    for (int i = 0; i < user_tag_list_length; ++i) {
+      std::string name;
+      rval = mMB->tag_get_name( user_tag_list[i], name );
+      if (MB_SUCCESS != rval) {
+        report_error( "Error %d getting name for tag.  Invalid input tag handle?", (int)rval );
+        return rval;
+      }
+      
+      if (name.empty()) {
+        report_error( "Explicit request to save anonymous tag." );
+        return MB_TAG_NOT_FOUND;
+      }
+      
+      int size;
+      if (!include_variable_length_tags &&
+          MB_VARIABLE_DATA_LENGTH == mMB->tag_get_size( user_tag_list[i], size )) {
+        report_error( "File format cannot store variable-length tag: \"%s\".", name.c_str() );
+        return MB_TYPE_OUT_OF_RANGE;
+      }
+      
+      result_list.push_back( user_tag_list[i] );
+    }
+  }
+  else {
+    std::vector<Tag> temp_list;
+    rval = mMB->tag_get_tags( temp_list );
+    if (MB_SUCCESS != rval) {
+      report_error( "Interface::tag_get_tags failed!" );
+      return rval;
+    }
+
+    result_list.clear();
+    result_list.reserve( temp_list.size() );
+    
+    std::vector<Tag>::iterator i;
+    for (i = temp_list.begin(); i != temp_list.end(); ++i) {
+      std::string name;
+      rval = mMB->tag_get_name( *i, name );
+      if (MB_SUCCESS != rval) {
+        report_error( "Error %d getting name for tag.  Stale tag handle?", (int)rval );
+        return rval;
+      }
+      
+        // skip anonymous tags
+      if (name.empty())
+        continue;
+      
+        // skip private/internal tags
+      if (name.size() >= 2 && name[0] == '_' && name[1] == '_')
+        continue;
+      
+        // if reqested, skip variable-length tags
+      int size;
+      if (!include_variable_length_tags &&
+          MB_VARIABLE_DATA_LENGTH == mMB->tag_get_size( *i, size ))
+        continue;
+      
+       result_list.push_back( *i );
+    }
+  }
+  
+  return MB_SUCCESS;  
+}
+
+} // namespace moab

Copied: MOAB/trunk/src/WriteUtil.hpp (from rev 3583, MOAB/trunk/src/MBWriteUtil.hpp)
===================================================================
--- MOAB/trunk/src/WriteUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/WriteUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,281 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+#ifndef MB_WRITE_UTIL_HPP
+#define MB_WRITE_UTIL_HPP
+
+#ifndef IS_BUILDING_MB
+#error "WriteUtil.hpp isn't supposed to be included into an application"
+#endif
+
+#include "moab/WriteUtilIface.hpp"
+
+namespace moab {
+
+class Core;
+class Error;
+
+class WriteUtil : public WriteUtilIface
+{
+private:
+  //! pointer to the Core
+  Core* mMB;
+  Error* mError;
+public:
+
+  //! constructor takes Core pointer
+  WriteUtil(Core* mdb, Error* error_handler);
+
+  //! destructor
+  ~WriteUtil(){}
+  
+    //! Check if the specified file already exists.
+    //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
+    //! if file does exist, or MB_FAILURE for some other error condition.
+  virtual ErrorCode check_doesnt_exist( const char* file_name );
+
+  //! gets arrays for coordinate data from the MB
+  ErrorCode get_node_arrays(
+      const int num_arrays,
+      const int num_nodes, 
+      const Range& entities,
+      Tag node_id_tag,
+      const int start_node_id,
+      std::vector<double*>& arrays
+      );
+      
+  /** Get an array of coordinate values for nodes
+   *
+   * Given a range of node handles, retreive a single coordinate
+   * value for each. 
+   *
+   * Failure conditions:
+   *  - invalid entity handles (not vertices, non-existant entity, etc.)
+   *  - range is empty (<code>iter == end</code>)
+   *  - <code>output_array</code> is null
+   *  - insufficient space in <code>output_array</code>
+   *
+   *\param which_array  The coordinate to retreive (0-&gt;X, 1-&gt;Y, 2-&gt;Z)
+   *\param begin        The first node handle.
+   *\param end          One past the last node handle.
+   *\param output_size  The size of <code>output_array</code>.
+   *\param output_array The memory in which to write the node coordinates.
+   *\author Jason Kraftcheck
+   */
+  ErrorCode get_node_array(
+      const int which_array, 
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const size_t output_size,
+      double* const output_array
+      );
+
+  //! get array for connectivity data from the MB
+  ErrorCode get_element_array(
+      const int num_elements, 
+      const int verts_per_element,
+      Tag node_id_tag,
+      const Range& entities, 
+      Tag element_id_tag,
+      int start_element_id,
+      int* array
+      );
+
+  /** Get connectivity for elements 
+   *
+   * Get the connectivity list for a range of elements.
+   *
+   * Failure cases:
+   *  - Passed range is empty (<code>begin == end</code>).
+   *  - <code>vertices_per_elem</code> is less than one
+   *  - <code>element_array</code> is null.
+   *  - The range contains invalid handles (non-existant entities,
+   *      not an element, etc.)
+   *  - Retreiving ID tag for an entity failed.
+   *  - Insufficient space in passed array.
+   *
+   *\param begin        The first element handle
+   *\param end          One past the last element handle
+   *\param vertices_per_elem Number of vertices to retreive for each
+   *                    element.  If the element has more vertices, the
+   *                    element connectivity will be truncated.  If 
+   *                    <code>vertices_per_elem</code> is greater than the
+   *                    number of nodes for an eleement, the data will be
+   *                    padded with zeros.
+   *\param node_id_tag  A tag with integer values.  
+   *\param array_size   The length of <code>element_array</code>
+   *\param element_array The memory location at which to store the 
+   *                    connectivity list.
+   *\author Jason Kraftcheck
+   */
+  ErrorCode get_element_array(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const int vertices_per_elem,
+      Tag node_id_tag,
+      const size_t array_size, 
+      int *const element_array
+      );
+
+  /** Get connectivity for elements 
+   *
+   * Get the connectivity list for a range of elements.
+   *
+   * Failure cases:
+   *  - Passed range is empty (<code>begin == end</code>).
+   *  - <code>vertices_per_elem</code> is less than one
+   *  - <code>element_array</code> is null.
+   *  - The range contains invalid handles (non-existant entities,
+   *      not an element, etc.)
+   *  - Insufficient space in passed array.
+   *
+   *\param begin        The first element handle
+   *\param end          One past the last element handle
+   *\param vertices_per_elem Number of vertices to retreive for each
+   *                    element.  If the element has more vertices, the
+   *                    element connectivity will be truncated.  If 
+   *                    <code>vertices_per_elem</code> is greater than the
+   *                    number of nodes for an eleement, the data will be
+   *                    padded with zeros.
+   *\param array_size   The length of <code>element_array</code>
+   *\param element_array The memory location at which to store the 
+   *                    connectivity list.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_element_array(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const int vertices_per_elem,
+      const size_t array_size, 
+      EntityHandle *const element_array
+      );
+
+  /** Get poly (polygon or polyhedron) connectivity size
+   *\param begin  First iterator in range of poly
+   *\param end    One past last in range of poly.
+   *\param connectivity_size  The lenght of the connectivity list
+   *              For the specified range of polyhedra.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_poly_array_size(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      int& connectivity_size 
+      );
+   
+   
+  /** Get poly (polygon or polyhedron) connectivity.
+   *
+   * This function will add as many polys as possible to the
+   * passed arrays given the sizes of those arrays.  It will
+   * then pass back position at which it stoped and the sizes
+   * of the data written to the arrays.
+   *
+   *\param iter               As input, the first element handle.
+   *                          As output, one past the last element handle
+   *                          for which data was written to the arrays.
+   *\param end                The iterator at which to stop.
+   *\param node_id_tag        A tag with integer values.  
+   *\param element_array_len  As input, length of <code>element_array</code>.
+   *                          As output, the number of entries written in that
+   *                          array.
+   *\param element_array      The memory location at which to store the 
+   *                          connectivity list.
+   *\param index_array_len    As input, the length of <code>index_array</code>.
+   *                          As output, the number of entries written in that
+   *                          array.
+   *\param index_array        The memory location at which to store offsets.
+   *\param index_offset       Value to offset (add to) index values.  As output
+   *                          the input value plus the amount of data 
+   *                          written to the element array.  (The value you
+   *                          presumably want to pass to the next call.)
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_poly_arrays(
+      Range::const_iterator& iter,
+      const Range::const_iterator end,
+      const Tag node_id_tag,
+      size_t& handle_array_len,
+      int *const handle_array,
+      size_t& index_array_len,
+      int *const index_array,
+      int& index_offset 
+      );
+ 
+  //! get a set of nodes that represent a set of elements
+  ErrorCode gather_nodes_from_elements(
+      const Range& elements,
+      const Tag node_bit_mark_tag,
+      Range& nodes
+      );
+  
+    //! assign ids to input elements starting with start_id, written to id_tag
+    //! if zero, assigns to GLOBAL_ID_TAG_NAME
+  ErrorCode assign_ids(Range &elements,
+                         Tag id_tag,
+                         const int start_id);
+
+  
+  /** Get explict adjacencies 
+   *
+   * Get explicit adjacences stored in database.
+   * Does not create any explicit adjacencies or search for
+   * implicit ones.
+   *
+   *\param entity  The entity to retreive adjacencies for.
+   *\param id_tag  The global ID tag
+   *\param adj     The output list of global IDs of adjacent entities.
+   */
+  ErrorCode get_adjacencies(
+      EntityHandle entity,
+      Tag id_tag,
+      std::vector<int>& adj 
+  );
+  
+  ErrorCode get_adjacencies( EntityHandle entity,
+                               const EntityHandle*& adj_array,
+                               int& num_adj );
+
+
+  /**\brief Get list of tags to write.
+   *
+   * Get the list of tags to write to the file, possibly using
+   * an optional user-specifed tag list.
+   *
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode 
+  get_tag_list( std::vector<Tag>& result_list,
+                const Tag* user_tag_list = 0, 
+                int user_tag_list_length = 0,
+                bool include_variable_length_tags = true );
+
+  //! tell MB there was an error when writing the mesh
+  //! it makes sense to have this as long as Interface has a write_mesh function
+  ErrorCode report_error( const std::string& error );
+
+  ErrorCode report_error( const char* error, ... )
+#ifdef __GNUC__
+ __attribute__((format(printf,2,3)))
+#endif
+  ;
+};
+
+} // namespace moab
+
+#endif
+
+

Modified: MOAB/trunk/src/io/CMakeLists.txt
===================================================================
--- MOAB/trunk/src/io/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -30,10 +30,6 @@
     ${MOAB_BINARY_DIR}/src
     ${MOAB_SOURCE_DIR}/src/parallel
     ${MOAB_BINARY_DIR}/src/parallel
-    ${MOAB_SOURCE_DIR}/src/moab
-    ${MOAB_BINARY_DIR}/src/moab
-    ${MOAB_SOURCE_DIR}/src/parallel/moab
-    ${MOAB_BINARY_DIR}/src/parallel/moab
   )
 
   if ( MOAB_USE_NETCDF )

Modified: MOAB/trunk/src/io/ExoIIUtil.cpp
===================================================================
--- MOAB/trunk/src/io/ExoIIUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ExoIIUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,16 +14,18 @@
  */
 
 #include "ExoIIUtil.hpp"
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBCN.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBCN.hpp"
 #include <string.h>
 
+namespace moab {
+
 //
 // definitions of ExoII-related static arrays
 //
 
-const MBEntityType ExoIIUtil::ExoIIElementMBEntity[] =
+const EntityType ExoIIUtil::ExoIIElementMBEntity[] =
 {
   MBVERTEX, // SPHERE,
   MBEDGE, // SPRING,
@@ -274,14 +276,14 @@
   return EXOII_MAX_ELEM_TYPE;
 }
 
-ExoIIElementType ExoIIUtil::static_get_element_type(MBInterface *mdbImpl, 
-                                             const MBEntityHandle entity, 
-                                             const MBTag mid_nodes_tag, 
-                                                    const MBTag geom_dimension_tag,
-                                             const MBEntityType indiv_entity_type) 
+ExoIIElementType ExoIIUtil::static_get_element_type(Interface *mdbImpl, 
+                                             const EntityHandle entity, 
+                                             const Tag mid_nodes_tag, 
+                                                    const Tag geom_dimension_tag,
+                                             const EntityType indiv_entity_type) 
 {
     // branch based on what kind of entity we're looking at
-  MBEntityType handle_type = mdbImpl->type_from_handle(entity);
+  EntityType handle_type = mdbImpl->type_from_handle(entity);
   
   if (handle_type == MBENTITYSET) 
   {
@@ -334,7 +336,7 @@
     return EXOII_SPHERE;
 
   else {
-    std::vector<MBEntityHandle> tmp(31);
+    std::vector<EntityHandle> tmp(31);
 
     mdbImpl->get_connectivity(&entity, 1, tmp, true);
     return get_element_type_from_num_verts(tmp.size(), indiv_entity_type);
@@ -346,7 +348,7 @@
 }
 
 ExoIIElementType ExoIIUtil::get_element_type_from_num_verts(const int num_verts, 
-                                                            const MBEntityType entity_type,
+                                                            const EntityType entity_type,
                                                             const int dimension) 
 {
   for (int i = 0; i < EXOII_MAX_ELEM_TYPE; i++) {
@@ -359,3 +361,4 @@
   return EXOII_MAX_ELEM_TYPE;
 }
 
+} // namespace moab

Modified: MOAB/trunk/src/io/ExoIIUtil.hpp
===================================================================
--- MOAB/trunk/src/io/ExoIIUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ExoIIUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,17 +24,19 @@
 #error "ExoIIUtil.hpp isn't supposed to be included into an application"
 #endif
 
-#include "MBForward.hpp"
-#include "ExoIIInterface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ExoIIInterface.hpp"
 
 
+namespace moab {
+
 class ExoIIUtil : public ExoIIInterface
 {
 
-  MBInterface* mMB;
+  Interface* mMB;
 
 public:
-  ExoIIUtil(MBInterface* mdb) : mMB(mdb) {}
+  ExoIIUtil(Interface* mdb) : mMB(mdb) {}
   ~ExoIIUtil(){}
 
   //! given the element name, return the type
@@ -46,9 +48,9 @@
   //! get the element type of the entity; this entity can either be a meshset, 
   //! in which case it will be assumed to be a material set meshset, or an 
   //! individual entity.
-  virtual  ExoIIElementType get_element_type(MBEntityHandle entity,
-                                             MBTag mid_nodes_tag, MBTag geom_dimension_tag, 
-                                             MBEntityType indiv_entity_type = MBMAXTYPE)
+  virtual  ExoIIElementType get_element_type(EntityHandle entity,
+                                             Tag mid_nodes_tag, Tag geom_dimension_tag, 
+                                             EntityType indiv_entity_type = MBMAXTYPE)
   {
     return static_get_element_type(mMB, entity, mid_nodes_tag, geom_dimension_tag,
                                    indiv_entity_type);    
@@ -86,21 +88,21 @@
 //! case it will be assumed to be a material set meshset, or an individual entity.  If a
 //! meshset, and indiv_entity_type is input, that type is used to start the search for
 //! the connectivity tag which determines how many vertices per entity are defined for that meshset
-  static ExoIIElementType static_get_element_type(MBInterface *mdbImpl,
-                                           const MBEntityHandle entity,
-                                           const MBTag mid_nodes_tag,
-                                           const MBTag geom_dimension_tag,
-                                           const MBEntityType indiv_entity_type = MBMAXTYPE);
+  static ExoIIElementType static_get_element_type(Interface *mdbImpl,
+                                           const EntityHandle entity,
+                                           const Tag mid_nodes_tag,
+                                           const Tag geom_dimension_tag,
+                                           const EntityType indiv_entity_type = MBMAXTYPE);
 
 //! given the number of vertices in an entity, and optionally the entity type and
 //! geometric dimension, return the corresponding exodusII element type; dimension defaults
 //! to 3 following TSTT convention
   static ExoIIElementType get_element_type_from_num_verts(const int num_verts, 
-                                                          const MBEntityType entity_type = MBMAXTYPE,
+                                                          const EntityType entity_type = MBMAXTYPE,
                                                           const int dimension = 3);
 
 //! the MB entity type used for each element type
-  static const MBEntityType ExoIIElementMBEntity[];
+  static const EntityType ExoIIElementMBEntity[];
 
 //! names for all the element types that MB ExoII reader supports
   static const char* ElementTypeNames[];
@@ -117,16 +119,18 @@
 
 };
 
-//! postfix increment operator for MBEntityType
+//! postfix increment operator for EntityType
 inline ExoIIElementType operator++(ExoIIElementType &type, int)
 {
   return (ExoIIElementType)(((int&)type)++);
 }  
 
-//! prefix increment operator for MBEntityType
+//! prefix increment operator for EntityType
 inline ExoIIElementType& operator++(ExoIIElementType& type)
 {
   return (ExoIIElementType&)(++((int&)type));
 }
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/FileTokenizer.cpp
===================================================================
--- MOAB/trunk/src/io/FileTokenizer.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/FileTokenizer.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,14 +14,17 @@
  */
 
 #include "FileTokenizer.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include <cstring>
 #include <cctype>
 #include <string>
 #include <cstdlib>
+
+namespace moab {
+
 using namespace std;
 
-FileTokenizer::FileTokenizer( FILE* file_ptr, MBReadUtilIface* rif_ptr )
+FileTokenizer::FileTokenizer( FILE* file_ptr, ReadUtilIface* rif_ptr )
   : filePtr( file_ptr ),
     readUtilPtr( rif_ptr ),
     nextToken( buffer ),
@@ -485,3 +488,5 @@
   return size == fread( mem, 1, size, filePtr );
 }
 
+
+} // namespace moab

Modified: MOAB/trunk/src/io/FileTokenizer.hpp
===================================================================
--- MOAB/trunk/src/io/FileTokenizer.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/FileTokenizer.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,12 +16,14 @@
 #ifndef FILE_TOKENIZER_HPP
 #define FILE_TOKENIZER_HPP
 
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 #include <cstdio>
 #include <sys/types.h>
 
-class MBReadUtilIface;
+namespace moab {
 
+class ReadUtilIface;
+
 /** 
  * \class  FileTokenizer
  * \brief  Parse a file as space-separated tokens
@@ -50,7 +52,7 @@
        *                      reporting errors.
        */
     FileTokenizer( std::FILE* file_ptr,
-                   MBReadUtilIface* read_util_ptr );
+                   ReadUtilIface* read_util_ptr );
     
       /** \brief destructor : closes file.
        *
@@ -220,7 +222,7 @@
     std::FILE* filePtr;
     
       /** Pointer to MOAB ReadUtil Interface */
-    MBReadUtilIface* readUtilPtr;
+    ReadUtilIface* readUtilPtr;
     
       /** Input buffer */
     char buffer[512];
@@ -241,4 +243,6 @@
     char lastChar;
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/GmshUtil.cpp
===================================================================
--- MOAB/trunk/src/io/GmshUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/GmshUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,6 +15,8 @@
 
 #include "GmshUtil.hpp"
 
+namespace moab {
+
 // Indexed by position in Gmsh order, containing cooresponding
 // position in MOAB order.
 const int hex_27_node_order[] =  {  
@@ -73,7 +75,7 @@
 
 const unsigned GmshUtil::numGmshElemType = sizeof(GmshUtil::gmshElemTypes) / sizeof(GmshUtil::gmshElemTypes[0]);
 
-// Define an array, indexed by MBEntityType and number of nodes, 
+// Define an array, indexed by EntityType and number of nodes, 
 // containing the corresponding Gmsh element type.
 #define TWENTYEIGHT_ZEROS { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 const int MAX_NODES = 28;
@@ -93,7 +95,7 @@
   TWENTYEIGHT_ZEROS,  // MBENTITYSET
   TWENTYEIGHT_ZEROS };// MBMAXTYPE
 
-int GmshUtil::get_gmsh_type( MBEntityType type, unsigned num_nodes )
+int GmshUtil::get_gmsh_type( EntityType type, unsigned num_nodes )
 {
   if (num_nodes >= (unsigned)MAX_NODES)
     return -1;
@@ -105,3 +107,5 @@
   return gmshElemTypes[idx].mb_type == MBMAXTYPE ? -1 : idx;
 }
 
+
+} // namespace moab

Modified: MOAB/trunk/src/io/GmshUtil.hpp
===================================================================
--- MOAB/trunk/src/io/GmshUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/GmshUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,8 +16,10 @@
 #ifndef GMSH_UTIL_HPP
 #define GMSH_UTIL_HPP
 
-#include "MBEntityType.h"
+#include "moab/EntityType.hpp"
 
+namespace moab {
+
 //! Structure defining relation between MOAB and VTK element
 //! types.  VTK had different types for quadratic than linear
 //! elements, so a tuple of the MOAB type and number of
@@ -26,7 +28,7 @@
 {
   const char* name;      //!< String name for use in error messages
   unsigned gmsh_type;    //!< GMsh integer type
-  MBEntityType mb_type;  //!< MOAB type
+  EntityType mb_type;  //!< MOAB type
   unsigned num_nodes;    //!< Number of nodes (0 for polygon)
   const int* node_order; //!< Gmsh element node ordering, indexed by
                          //!< the Gmsh node position and containing
@@ -49,8 +51,10 @@
   static const unsigned numGmshElemType;
   
     //! Get the Gmsh type corresponding to a tuple of the MOAB type and number of nodes.
-    //! num_nodes is ignored for POLYGON type.  Returns -1 for unsupported types.
-  static int get_gmsh_type( MBEntityType type, unsigned num_nodes );
+    //! num_nodes is ignored for MBPOLYGON type.  Returns -1 for unsupported types.
+  static int get_gmsh_type( EntityType type, unsigned num_nodes );
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/Makefile.am
===================================================================
--- MOAB/trunk/src/io/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -10,8 +10,7 @@
 libmoabio_la_LIBADD = $(NETCDF_LIBS) $(HDF5_LIBS) 
 
 AM_CPPFLAGS += -DIS_BUILDING_MB \
-               -I..  -I$(srcdir)/.. -I$(srcdir)/../parallel \
-               -I../moab -I$(srcdir)/../moab -I$(srcdir)/../parallel/moab -I$(srcdir)/moab
+               -I..  -I$(srcdir)/.. -I$(srcdir)/../parallel
 
 if NETCDF_FILE
   MOAB_NETCDF_SRCS = ReadNCDF.cpp  ReadNCDF.hpp \

Modified: MOAB/trunk/src/io/ReadABAQUS.cpp
===================================================================
--- MOAB/trunk/src/io/ReadABAQUS.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadABAQUS.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -29,36 +29,38 @@
 #include <stdio.h>
 #include <cmath>
 
-#include "MBCN.hpp"
-#include "MBRange.hpp"
-#include "MBInterface.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInternals.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBAffineXform.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/Range.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "Internals.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "AffineXform.hpp"
 // #include "abaqus_order.h"
 #include "FileOptions.hpp"
 
+namespace moab {
+
 #define ABQ_AMBIGUOUS "AMBIGUOUS"
 #define ABQ_UNDEFINED "UNDEFINED"
 #define DEG2RAD 0.017453292519943295769236907684886
 
 #define MB_RETURN_IF_FAIL if (MB_SUCCESS != status) return status
 
-MBReaderIface* ReadABAQUS::factory( MBInterface* iface )
+ReaderIface* ReadABAQUS::factory( Interface* iface )
   { return new ReadABAQUS( iface ); }
 
 
 
-ReadABAQUS::ReadABAQUS(MBInterface* impl)
+ReadABAQUS::ReadABAQUS(Interface* impl)
   : mdbImpl(impl)
 {
   assert(impl != NULL);
   reset();
   
   void* ptr = 0;
-  impl->query_interface( "MBReadUtilIface", &ptr );
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  impl->query_interface( "ReadUtilIface", &ptr );
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   mMaterialSetTag  = 0;
@@ -86,9 +88,9 @@
   mHasMidNodesTag  = get_tag(HAS_MID_NODES_TAG_NAME,4*sizeof(int),MB_TAG_SPARSE,MB_TYPE_INTEGER,def_val);
 
   mSetTypeTag        = get_tag(ABAQUS_SET_TYPE_TAG_NAME,          sizeof(int),           MB_TAG_SPARSE,MB_TYPE_INTEGER);
-  mPartHandleTag     = get_tag(ABAQUS_PART_HANDLE_TAG_NAME,       sizeof(MBEntityHandle),MB_TAG_SPARSE,MB_TYPE_HANDLE);
-  mInstanceHandleTag = get_tag(ABAQUS_INSTANCE_HANDLE_TAG_NAME,   sizeof(MBEntityHandle),MB_TAG_DENSE, MB_TYPE_HANDLE);
-  mAssemblyHandleTag = get_tag(ABAQUS_ASSEMBLY_HANDLE_TAG_NAME,   sizeof(MBEntityHandle),MB_TAG_DENSE, MB_TYPE_HANDLE);
+  mPartHandleTag     = get_tag(ABAQUS_PART_HANDLE_TAG_NAME,       sizeof(EntityHandle),MB_TAG_SPARSE,MB_TYPE_HANDLE);
+  mInstanceHandleTag = get_tag(ABAQUS_INSTANCE_HANDLE_TAG_NAME,   sizeof(EntityHandle),MB_TAG_DENSE, MB_TYPE_HANDLE);
+  mAssemblyHandleTag = get_tag(ABAQUS_ASSEMBLY_HANDLE_TAG_NAME,   sizeof(EntityHandle),MB_TAG_DENSE, MB_TYPE_HANDLE);
   mInstancePIDTag    = get_tag(ABAQUS_INSTANCE_PART_ID_TAG_NAME,  sizeof(int),           MB_TAG_SPARSE,MB_TYPE_INTEGER);
   mInstanceGIDTag    = get_tag(ABAQUS_INSTANCE_GLOBAL_ID_TAG_NAME,sizeof(int),           MB_TAG_SPARSE,MB_TYPE_INTEGER);
   mLocalIDTag        = get_tag(ABAQUS_LOCAL_ID_TAG_NAME,          sizeof(int),           MB_TAG_DENSE, MB_TYPE_INTEGER);
@@ -105,7 +107,7 @@
 
 ReadABAQUS::~ReadABAQUS() 
 {
-  std::string iface_name = "MBReadUtilIface";
+  std::string iface_name = "ReadUtilIface";
   mdbImpl->release_interface(iface_name, readMeshIface);
   if (NULL != abFile)
     abFile.close();
@@ -113,13 +115,13 @@
 
 /* 
 
-MBErrorCode ReadABAQUS::check_file_stats()
+ErrorCode ReadABAQUS::check_file_stats()
 * check for existence of file
 * initialize meshsets, and offsets if necessary
 
 */
 
-MBErrorCode ReadABAQUS::read_tag_values( const char* /* file_name */,
+ErrorCode ReadABAQUS::read_tag_values( const char* /* file_name */,
 					 const char* /* tag_name */,
 					 const FileOptions& /* opts */,
 					 std::vector<int>& /* tag_values_out */,
@@ -131,14 +133,14 @@
 
 
 
-MBErrorCode ReadABAQUS::load_file(const char *abaqus_file_name,
-				  const MBEntityHandle* file_set_ptr,
+ErrorCode ReadABAQUS::load_file(const char *abaqus_file_name,
+				  const EntityHandle* file_set_ptr,
 				  const FileOptions& opts,
-				  const MBReaderIface::IDTag* subset_list,
+				  const ReaderIface::IDTag* subset_list,
 				  int subset_list_length,
-				  const MBTag* file_id_tag)
+				  const Tag* file_id_tag)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   // open file
   lineNo = 0;
@@ -148,7 +150,7 @@
 
   bool in_unsupported = false;
 
-  MBEntityHandle file_set;
+  EntityHandle file_set;
   status = mdbImpl->create_meshset( MESHSET_SET, file_set );
   if (MB_SUCCESS != status)
     return status;
@@ -204,7 +206,7 @@
 
   // temporary??? delete parts
   // get all node sets in part
-  MBRange part_sets;
+  Range part_sets;
   int tag_val = ABQ_PART_SET;
   void* tag_data[] = {&tag_val};
   status = mdbImpl->get_entities_by_type_and_tag(file_set,
@@ -213,11 +215,11 @@
 						 tag_data, 1, part_sets);
   MB_RETURN_IF_FAIL;
   
-  for (MBRange::iterator part_set = part_sets.begin();
+  for (Range::iterator part_set = part_sets.begin();
        part_set != part_sets.end();
        part_set++)
     {
-      MBRange ent_sets;
+      Range ent_sets;
       tag_val = ABQ_NODE_SET;
       tag_data[0] = &tag_val;
 
@@ -242,7 +244,7 @@
       status = mdbImpl->delete_entities(ent_sets);
       MB_RETURN_IF_FAIL;
 
-      MBRange node_list,ele_list;
+      Range node_list,ele_list;
       status = get_set_elements(*part_set,ele_list);
       MB_RETURN_IF_FAIL;
 
@@ -267,7 +269,7 @@
 }
   
 
-MBErrorCode ReadABAQUS::read_heading(MBEntityHandle file_set)
+ErrorCode ReadABAQUS::read_heading(EntityHandle file_set)
 {
   
   std::vector<std::string> tokens;
@@ -284,9 +286,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadABAQUS::read_assembly(MBEntityHandle file_set)
+ErrorCode ReadABAQUS::read_assembly(EntityHandle file_set)
 {
-  MBErrorCode status = MB_SUCCESS;
+  ErrorCode status = MB_SUCCESS;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -345,7 +347,7 @@
     }
 
 
-  MBEntityHandle assembly_set;
+  EntityHandle assembly_set;
   
   status = add_entity_set(file_set,ABQ_ASSEMBLY_SET,assembly_name,assembly_set);
 
@@ -410,9 +412,9 @@
 }
 
 
-MBErrorCode ReadABAQUS::read_instance(MBEntityHandle assembly_set,MBEntityHandle file_set)
+ErrorCode ReadABAQUS::read_instance(EntityHandle assembly_set,EntityHandle file_set)
 {
-  MBErrorCode status = MB_SUCCESS;
+  ErrorCode status = MB_SUCCESS;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -555,7 +557,7 @@
       
    }
 
-  MBEntityHandle instance_set;
+  EntityHandle instance_set;
   
   status = create_instance_of_part(file_set,assembly_set,part_name,
 				   instance_name,instance_set,translation,rotation);
@@ -566,9 +568,9 @@
 }
 
 
-MBErrorCode ReadABAQUS::read_part(MBEntityHandle file_set)
+ErrorCode ReadABAQUS::read_part(EntityHandle file_set)
 {
-  MBErrorCode status = MB_SUCCESS;
+  ErrorCode status = MB_SUCCESS;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -627,7 +629,7 @@
     }
 
 
-  MBEntityHandle part_set;
+  EntityHandle part_set;
   
   status = add_entity_set(file_set,ABQ_PART_SET,part_name,part_set);
 
@@ -697,9 +699,9 @@
   return MB_SUCCESS;
 }  
 
-MBErrorCode ReadABAQUS::read_solid_section(MBEntityHandle parent_set)
+ErrorCode ReadABAQUS::read_solid_section(EntityHandle parent_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -762,7 +764,7 @@
 	}
     }
   
-  MBEntityHandle set_handle;
+  EntityHandle set_handle;
   status = get_set_by_name(parent_set,ABQ_ELEMENT_SET,elset_name,set_handle);
 
   status = mdbImpl->tag_set_data(mMatNameTag,&set_handle,1,mat_name.c_str());
@@ -784,9 +786,9 @@
 
 }
 
-MBErrorCode ReadABAQUS::read_element_set(MBEntityHandle parent_set, MBEntityHandle file_set, MBEntityHandle assembly_set)
+ErrorCode ReadABAQUS::read_element_set(EntityHandle parent_set, EntityHandle file_set, EntityHandle assembly_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -803,13 +805,13 @@
   std::string elset_name;
   bool generate_elset = false;
   std::string instance_name;
-  MBEntityHandle element_container_set = parent_set;
+  EntityHandle element_container_set = parent_set;
 
   // tokenize last line read
   tokenize(readline,tokens,",\n");
   extract_keyword_parameters(tokens,params);
   
-  MBRange element_range;
+  Range element_range;
   
   // search for required parameters
   for (std::map<std::string,abaqus_elset_params>::iterator thisParam=requiredParams.begin();
@@ -861,7 +863,7 @@
   
   
   std::vector<int> element_list;
-  MBRange tmp_element_range;
+  Range tmp_element_range;
 
   next_line_type = get_next_line_type();
   
@@ -912,7 +914,7 @@
   
   element_range.merge(tmp_element_range);
 
-  MBEntityHandle element_set;
+  EntityHandle element_set;
   
   status = add_entity_set(parent_set,ABQ_ELEMENT_SET,elset_name,element_set);
   MB_RETURN_IF_FAIL;
@@ -943,9 +945,9 @@
 
 
 
-MBErrorCode ReadABAQUS::read_node_set(MBEntityHandle parent_set,MBEntityHandle file_set, MBEntityHandle assembly_set)
+ErrorCode ReadABAQUS::read_node_set(EntityHandle parent_set,EntityHandle file_set, EntityHandle assembly_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -964,13 +966,13 @@
   bool make_from_elset = false;
   bool generate_nset = false;
   std::string elset_name, instance_name;
-  MBEntityHandle node_container_set = parent_set;
+  EntityHandle node_container_set = parent_set;
 
   // tokenize last line read
   tokenize(readline,tokens,",\n");
   extract_keyword_parameters(tokens,params);
 
-  MBRange node_range;
+  Range node_range;
   
   // search for required parameters
   for (std::map<std::string,abaqus_nset_params>::iterator thisParam=requiredParams.begin();
@@ -1038,7 +1040,7 @@
   else
     {
       std::vector<int> node_list;
-      MBRange tmp_node_range;
+      Range tmp_node_range;
 
       next_line_type = get_next_line_type();
       
@@ -1092,7 +1094,7 @@
       
     }
   
-  MBEntityHandle node_set;
+  EntityHandle node_set;
   
   status = add_entity_set(parent_set,ABQ_NODE_SET,nset_name,node_set);
   MB_RETURN_IF_FAIL;
@@ -1119,9 +1121,9 @@
 
 }
 
-MBErrorCode ReadABAQUS::read_element_list(MBEntityHandle parent_set)
+ErrorCode ReadABAQUS::read_element_list(EntityHandle parent_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -1136,7 +1138,7 @@
 
   std::map<std::string,abaqus_element_type> elementTypes;
   std::map<abaqus_element_type,unsigned int> nodes_per_element;
-  std::map<abaqus_element_type,MBEntityType> entityTypeMap;
+  std::map<abaqus_element_type,EntityType> entityTypeMap;
   elementTypes["DC3D8"]                 = abq_eletype_dc3d8;
   nodes_per_element[abq_eletype_dc3d8]  = 8;
   entityTypeMap[abq_eletype_dc3d8]      = MBHEX;
@@ -1242,8 +1244,8 @@
   int num_elements = element_ids.size();
 
   // get and fill element arrays
-  MBEntityHandle start_element = 0;
-  MBEntityHandle *connect;
+  EntityHandle start_element = 0;
+  EntityHandle *connect;
 
   status = readMeshIface->get_element_array( num_elements, nodes_per_element[element_type],
 					     entityTypeMap[element_type], MB_START_ID,
@@ -1253,7 +1255,7 @@
 
   // ASSUME: elements must be defined after nodes!
   // get list of node entity handles and node IDs
-  MBRange node_list;
+  Range node_list;
   status = mdbImpl->get_entities_by_dimension(parent_set, 0, node_list);
   MB_RETURN_IF_FAIL;
   
@@ -1261,14 +1263,14 @@
   status = mdbImpl->tag_get_data(mLocalIDTag,node_list,&node_ids[0]);
   MB_RETURN_IF_FAIL;
 
-  std::map<int,MBEntityHandle> nodeIdMap;
+  std::map<int,EntityHandle> nodeIdMap;
   for (unsigned int idx=0;idx<node_list.size();idx++)
     nodeIdMap[node_ids[idx]] = node_list[idx];
 
   for (unsigned int node=0;node<connect_list.size();node++)
     connect[node] = nodeIdMap[connect_list[node]];
 
-  MBRange element_range(start_element, start_element+num_elements-1);
+  Range element_range(start_element, start_element+num_elements-1);
 
   // add elements to file_set
   // status = mdbImpl->add_entities(file_set,element_range);
@@ -1286,7 +1288,7 @@
 
   if (make_element_set)
     {
-      MBEntityHandle element_set;
+      EntityHandle element_set;
 
       status = add_entity_set(parent_set,ABQ_ELEMENT_SET,element_set_name,element_set);
       MB_RETURN_IF_FAIL;
@@ -1306,9 +1308,9 @@
 
 }
  
-MBErrorCode ReadABAQUS::read_node_list(MBEntityHandle parent_set)
+ErrorCode ReadABAQUS::read_node_list(EntityHandle parent_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   std::vector<std::string> tokens;
   std::map<std::string,std::string> params;
@@ -1404,7 +1406,7 @@
 
   // get and fill coordinate arrays
   std::vector<double*> coord_arrays(3);
-  MBEntityHandle start_node = 0;
+  EntityHandle start_node = 0;
   status = readMeshIface->get_node_arrays(3, num_nodes,MB_START_ID,
 					  start_node,coord_arrays);
   MB_RETURN_IF_FAIL;
@@ -1418,7 +1420,7 @@
       coord_arrays[2][idx] = coord_list[idx*3+2];
     }
   
-  MBRange node_range(start_node, start_node+num_nodes-1);
+  Range node_range(start_node, start_node+num_nodes-1);
   // add nodes to file_set
   // status = mdbImpl->add_entities(file_set,node_range);
   // MB_RETURN_IF_FAIL;
@@ -1435,7 +1437,7 @@
 
   if (make_node_set)
     {
-      MBEntityHandle node_set;
+      EntityHandle node_set;
       
       status = add_entity_set(parent_set,ABQ_NODE_SET,node_set_name,node_set);
       MB_RETURN_IF_FAIL;
@@ -1455,12 +1457,12 @@
 
 // SET CREATION & ACCESS UTILITIES
 
-MBErrorCode ReadABAQUS::get_elements_by_id(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::get_elements_by_id(EntityHandle parent_set,
 					   std::vector<int> element_ids_subset,
-					   MBRange &element_range)
+					   Range &element_range)
 {
-  MBErrorCode status;
-  MBRange all_elements;
+  ErrorCode status;
+  Range all_elements;
 
   status = get_set_elements(parent_set,all_elements);
   MB_RETURN_IF_FAIL;
@@ -1469,7 +1471,7 @@
   status = mdbImpl->tag_get_data(mLocalIDTag,all_elements,&element_ids[0]);
   MB_RETURN_IF_FAIL;
 
-  std::map<int,MBEntityHandle> elementIdMap;
+  std::map<int,EntityHandle> elementIdMap;
   for (unsigned int idx=0;idx<all_elements.size();idx++)
     elementIdMap[element_ids[idx]] = all_elements[idx];
 
@@ -1481,13 +1483,13 @@
   return MB_SUCCESS;
 
 }
-MBErrorCode ReadABAQUS::get_nodes_by_id(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::get_nodes_by_id(EntityHandle parent_set,
 					std::vector<int> node_ids_subset,
-					MBRange &node_range)
+					Range &node_range)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
-  MBRange all_nodes;
+  Range all_nodes;
   status = mdbImpl->get_entities_by_type(parent_set,MBVERTEX,all_nodes);
   MB_RETURN_IF_FAIL;
 
@@ -1495,7 +1497,7 @@
   status = mdbImpl->tag_get_data(mLocalIDTag,all_nodes,&node_ids[0]);
   MB_RETURN_IF_FAIL;
   
-  std::map<int,MBEntityHandle> nodeIdMap;
+  std::map<int,EntityHandle> nodeIdMap;
   for (unsigned int idx=0;idx<all_nodes.size();idx++)
     nodeIdMap[node_ids[idx]] = all_nodes[idx];
 
@@ -1511,18 +1513,18 @@
 }
 
 
-MBErrorCode ReadABAQUS::get_set_by_name(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::get_set_by_name(EntityHandle parent_set,
 					int ABQ_set_type,
 					std::string set_name,
-					MBEntityHandle &set_handle)
+					EntityHandle &set_handle)
 {
-  MBErrorCode status;
+  ErrorCode status;
   
   char this_set_name[ABAQUS_SET_NAME_LENGTH];
   
   set_handle = 0;
 
-  MBRange sets;
+  Range sets;
   void* tag_data[] = {&ABQ_set_type};
   status = mdbImpl->get_entities_by_type_and_tag(parent_set,
 						 MBENTITYSET,
@@ -1534,7 +1536,7 @@
       return status;
     }
   
-  for (MBRange::iterator this_set=sets.begin();
+  for (Range::iterator this_set=sets.begin();
        this_set != sets.end() && 0 == set_handle;
        this_set++)
     {
@@ -1555,12 +1557,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadABAQUS::get_set_elements(MBEntityHandle set_handle,
-					 MBRange &element_range)
+ErrorCode ReadABAQUS::get_set_elements(EntityHandle set_handle,
+					 Range &element_range)
 {
-  MBErrorCode status;
+  ErrorCode status;
   
-  MBRange dim_ent_list;
+  Range dim_ent_list;
 
   // could have elements of multiple dimensions in this set???
   for (int dim=1;dim<=3;dim++)
@@ -1575,14 +1577,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadABAQUS::get_set_elements_by_name(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::get_set_elements_by_name(EntityHandle parent_set,
 						 int ABQ_set_type,
 						 std::string set_name,
-						 MBRange &element_range)
+						 Range &element_range)
 {
-  MBErrorCode status;
+  ErrorCode status;
   
-  MBEntityHandle set_handle;
+  EntityHandle set_handle;
   status = get_set_by_name(parent_set,ABQ_set_type,set_name,set_handle);
   MB_RETURN_IF_FAIL;
   
@@ -1599,19 +1601,19 @@
 }
   
 
-MBErrorCode ReadABAQUS::get_set_nodes(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::get_set_nodes(EntityHandle parent_set,
 				      int ABQ_set_type,
 				      std::string set_name,
-				      MBRange &node_range)
+				      Range &node_range)
 {
-  MBErrorCode status;
+  ErrorCode status;
   
-  MBEntityHandle set_handle;
+  EntityHandle set_handle;
   status = get_set_by_name(parent_set,ABQ_set_type,set_name,set_handle);
   MB_RETURN_IF_FAIL;
 
-  MBRange ent_list;
-  MBRange dim_ent_list;
+  Range ent_list;
+  Range dim_ent_list;
   // could have elements of multiple dimensions in this set???
   for (int dim=0;dim<=3;dim++)
     {
@@ -1634,10 +1636,10 @@
 }
   
 
-MBTag ReadABAQUS::get_tag(const char* tag_name, 
+Tag ReadABAQUS::get_tag(const char* tag_name, 
 			  int tag_size,
-			  MBTagType tag_type,
-			  MBDataType tag_data_type)
+			  TagType tag_type,
+			  DataType tag_data_type)
 {
   int def_val = 0;
   
@@ -1645,13 +1647,13 @@
 
 }
 
-MBTag ReadABAQUS::get_tag(const char* tag_name, 
+Tag ReadABAQUS::get_tag(const char* tag_name, 
 			  int tag_size,
-			  MBTagType tag_type,
-			  MBDataType tag_data_type,
+			  TagType tag_type,
+			  DataType tag_data_type,
 			  const void* def_val)
 {
-  MBTag retval;
+  Tag retval;
 
   if (MB_TAG_NOT_FOUND == mdbImpl->tag_get_handle(tag_name, retval) )
     mdbImpl->tag_create(tag_name,tag_size,tag_type,tag_data_type,retval,def_val);
@@ -1661,17 +1663,17 @@
   
 }
 
-MBErrorCode ReadABAQUS::create_instance_of_part(const MBEntityHandle file_set,
-						const MBEntityHandle assembly_set,
+ErrorCode ReadABAQUS::create_instance_of_part(const EntityHandle file_set,
+						const EntityHandle assembly_set,
 						const std::string part_name,
 						const std::string instance_name,
-						MBEntityHandle &instance_set,
+						EntityHandle &instance_set,
 						const std::vector<double> &translation,
 						const std::vector<double> &rotation)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
-  MBEntityHandle part_set;
+  EntityHandle part_set;
   status = get_set_by_name(file_set,ABQ_PART_SET,part_name,part_set);
   MB_RETURN_IF_FAIL;
 
@@ -1695,7 +1697,7 @@
   // ---- NODES ---- 
 
   // get all nodes and IDs
-  MBRange part_node_list;
+  Range part_node_list;
   status = mdbImpl->get_entities_by_dimension(part_set,0,part_node_list);
   MB_RETURN_IF_FAIL;
 
@@ -1703,13 +1705,13 @@
   status = mdbImpl->tag_get_data(mLocalIDTag,part_node_list,&node_ids[0]);
   MB_RETURN_IF_FAIL;
 
-  std::map<int,MBEntityHandle> nodeIdMap;
+  std::map<int,EntityHandle> nodeIdMap;
   for (unsigned int idx=0;idx<part_node_list.size();idx++)
     nodeIdMap[node_ids[idx]] = part_node_list[idx];
 
   // create new nodes
   std::vector<double*> coord_arrays(3);
-  MBEntityHandle start_node = 0;
+  EntityHandle start_node = 0;
   status = readMeshIface->get_node_arrays(3, part_node_list.size(),MB_START_ID,
 					  start_node,coord_arrays);
   MB_RETURN_IF_FAIL;
@@ -1725,9 +1727,9 @@
   rot_axis[1] = rotation[4]-rotation[1];
   rot_axis[2] = rotation[5]-rotation[2];
   
-  MBAffineXform rotationXform;
+  AffineXform rotationXform;
   if (rotation[6] != 0)
-    rotationXform = MBAffineXform::rotation(rotation[6]*DEG2RAD,rot_axis);
+    rotationXform = AffineXform::rotation(rotation[6]*DEG2RAD,rot_axis);
 
   // translate to new position
   for (unsigned int idx=0;idx<part_node_list.size();idx++)
@@ -1748,7 +1750,7 @@
 
     }
 
-  MBRange instance_node_list(start_node, start_node+part_node_list.size()-1);
+  Range instance_node_list(start_node, start_node+part_node_list.size()-1);
 
   // (DO NOT) add nodes to file_set
   // status = mdbImpl->add_entities(file_set,instance_node_list);
@@ -1767,19 +1769,19 @@
   MB_RETURN_IF_FAIL;
 
   // tag nodes with their instance handle
-  std::vector<MBEntityHandle> tmp_instance_handles;
+  std::vector<EntityHandle> tmp_instance_handles;
   tmp_instance_handles.assign(part_node_list.size(),instance_set);
   status = mdbImpl->tag_set_data(mInstanceHandleTag,instance_node_list,&tmp_instance_handles[0]);
   MB_RETURN_IF_FAIL;
 
   // create a map of old handles to new handles!!!
-  std::map<MBEntityHandle,MBEntityHandle> p2i_nodes;
+  std::map<EntityHandle,EntityHandle> p2i_nodes;
   for (unsigned int idx=0;idx<part_node_list.size();idx++)
     p2i_nodes[part_node_list[idx]]=instance_node_list[idx];
   
   //  ---- ELEMENTS ----
   
-  MBRange part_element_list;
+  Range part_element_list;
   status = get_set_elements(part_set,part_element_list);
   MB_RETURN_IF_FAIL;
 
@@ -1787,31 +1789,31 @@
   status = mdbImpl->tag_get_data(mLocalIDTag,part_element_list,&part_element_ids[0]);
   MB_RETURN_IF_FAIL;
 
-  std::map<int,MBEntityHandle> elementIdMap;
+  std::map<int,EntityHandle> elementIdMap;
   for (unsigned int idx=0;idx<part_element_list.size();idx++)
       elementIdMap[part_element_ids[idx]] = part_element_list[idx];
 
   // create new elements
-  MBRange instance_element_list;
+  Range instance_element_list;
   instance_element_list.clear();
 
   // cross-referencing storage and pointers/iterators
-  std::map<MBEntityHandle,MBEntityHandle> p2i_elements;
+  std::map<EntityHandle,EntityHandle> p2i_elements;
   std::vector<int> instance_element_ids;
   std::vector<int>::iterator part_element_id = part_element_ids.begin();
 
-  for (MBRange::iterator part_element=part_element_list.begin();
+  for (Range::iterator part_element=part_element_list.begin();
        part_element != part_element_list.end();
        part_element++,part_element_id++)
     {
-      MBEntityType element_type = mdbImpl->type_from_handle(*part_element);
-      std::vector<MBEntityHandle> part_connectivity,instance_connectivity;
-      MBEntityHandle new_element;
+      EntityType element_type = mdbImpl->type_from_handle(*part_element);
+      std::vector<EntityHandle> part_connectivity,instance_connectivity;
+      EntityHandle new_element;
       status = mdbImpl->get_connectivity(&(*part_element),1,part_connectivity);
       MB_RETURN_IF_FAIL;
 
       instance_connectivity.clear();
-      for (std::vector<MBEntityHandle>::iterator connectivity_node=part_connectivity.begin();
+      for (std::vector<EntityHandle>::iterator connectivity_node=part_connectivity.begin();
 	   connectivity_node != part_connectivity.end();
 	   connectivity_node++)
 	instance_connectivity.push_back(p2i_nodes[*connectivity_node]);
@@ -1848,7 +1850,7 @@
   // ----- NODE SETS -----
 
   // get all node sets in part
-  MBRange part_node_sets;
+  Range part_node_sets;
   int tag_val = ABQ_NODE_SET;
   void* tag_data[] = {&tag_val};
   status = mdbImpl->get_entities_by_type_and_tag(part_set,
@@ -1857,8 +1859,8 @@
 						 tag_data, 1, part_node_sets);
   MB_RETURN_IF_FAIL;
 
-  MBRange part_node_set_list, instance_node_set_list;
-  for (MBRange::iterator part_node_set = part_node_sets.begin();
+  Range part_node_set_list, instance_node_set_list;
+  for (Range::iterator part_node_set = part_node_sets.begin();
        part_node_set != part_node_sets.end();
        part_node_set++)
     {
@@ -1871,12 +1873,12 @@
       status = mdbImpl->get_entities_by_dimension(*part_node_set,0,part_node_set_list);
 
       instance_node_set_list.clear();
-      for (MBRange::iterator set_node = part_node_set_list.begin();
+      for (Range::iterator set_node = part_node_set_list.begin();
 	   set_node != part_node_set_list.end();
 	   set_node++)
 	instance_node_set_list.insert(p2i_nodes[*set_node]);
 
-      MBEntityHandle instance_node_set;
+      EntityHandle instance_node_set;
       
       status = add_entity_set(instance_set,ABQ_NODE_SET,node_set_name,instance_node_set);
       MB_RETURN_IF_FAIL;
@@ -1901,7 +1903,7 @@
   // ----- ELEMENT SETS -----
 
   // get all element sets in part
-  MBRange part_element_sets;
+  Range part_element_sets;
   tag_val = ABQ_ELEMENT_SET;
   tag_data[0] = &tag_val;
   status = mdbImpl->get_entities_by_type_and_tag(part_set,
@@ -1910,8 +1912,8 @@
 						 tag_data, 1, part_element_sets);
   MB_RETURN_IF_FAIL;
 
-  MBRange part_element_set_list, instance_element_set_list;
-  for (MBRange::iterator part_element_set = part_element_sets.begin();
+  Range part_element_set_list, instance_element_set_list;
+  for (Range::iterator part_element_set = part_element_sets.begin();
        part_element_set != part_element_sets.end();
        part_element_set++)
     {
@@ -1924,12 +1926,12 @@
       status = get_set_elements(*part_element_set,part_element_set_list);
 
       instance_element_set_list.clear();
-      for (MBRange::iterator set_element = part_element_set_list.begin();
+      for (Range::iterator set_element = part_element_set_list.begin();
 	   set_element != part_element_set_list.end();
 	   set_element++)
 	instance_element_set_list.insert(p2i_elements[*set_element]);
 
-      MBEntityHandle instance_element_set;
+      EntityHandle instance_element_set;
       status = add_entity_set(instance_set,ABQ_ELEMENT_SET,element_set_name,instance_element_set);
       MB_RETURN_IF_FAIL;
 
@@ -1983,12 +1985,12 @@
 }
 
 
-MBErrorCode ReadABAQUS::add_entity_set(MBEntityHandle parent_set,
+ErrorCode ReadABAQUS::add_entity_set(EntityHandle parent_set,
 				       int ABQ_Set_Type,
 				       std::string set_name,
-				       MBEntityHandle &entity_set)
+				       EntityHandle &entity_set)
 {
-  MBErrorCode status;
+  ErrorCode status;
   
   status = mdbImpl->create_meshset(MESHSET_SET, entity_set);
   MB_RETURN_IF_FAIL;
@@ -2221,3 +2223,6 @@
 {
   readMeshIface->report_error( "Error at line %d: %s\n", lineNo, message );
 }
+
+} // namespace moab
+

Modified: MOAB/trunk/src/io/ReadABAQUS.hpp
===================================================================
--- MOAB/trunk/src/io/ReadABAQUS.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadABAQUS.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -81,7 +81,7 @@
 In order to provide convenient access to the data and mesh structures
 the following data model is used:
 
-• MBEntitySet file_set
+• EntitySet file_set
    • tags
        • NONE
    • members
@@ -89,7 +89,7 @@
        • all elements of all parts and all instances
        • all assembly_sets
        • all part_sets
-• MBEntitySet part_set
+• EntitySet part_set
    • tags
        • mSetNameTag (opaque=char*)
          name of entitity set
@@ -98,7 +98,7 @@
        • part elements
        • part node sets
        • part element sets
-• MBEntitySet assembly_set
+• EntitySet assembly_set
    • tags
        • mSetNameTag (opaque=char*)
          name of entitity set
@@ -108,7 +108,7 @@
       • instance node_sets  
       • instance nodes
       • instance elements
-• MBEntitySet instance_set
+• EntitySet instance_set
    • tags
        • mSetNameTag (opaque=char*)
          name of entitity set
@@ -125,7 +125,7 @@
       • instance elements
       • instance node_sets  
       • instanec element_sets
-• MBEntitySet node_set
+• EntitySet node_set
    • tags
        • mSetNameTag (opaque=char*)
          name of entitity set
@@ -139,7 +139,7 @@
          (NULL if this node_set is not in an assembly)
    • members
       • nodes
-• MBEntitySet element_set
+• EntitySet element_set
    • tags
        • mSetNameTag (opaque=char*)
          name of entitity set
@@ -157,14 +157,14 @@
          material id in these elements
    • members
       • elements
-• MBEntity node
+• Entity node
    • tags
        • mLocalIDTag (int)
          numerical ID of node in local scope (part, instance)
        • mInstanceHandleTag (handle)
          pointer back to instance set in which this node exists
          (NULL if this node is not in an instance)
-• MBEntity element
+• Entity element
    • tags
        • mLocalIDTag (int)
          numerical ID of element in local scope (part, instance)
@@ -189,10 +189,12 @@
 #include <iostream>
 #include <fstream>
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/Range.hpp"
 
+namespace moab {
+
 #define ABAQUS_SET_TYPE_TAG_NAME "abaqus_set_type"
 #define ABAQUS_SET_NAME_TAG_NAME "abaqus_set_name"
 #define ABAQUS_SET_NAME_LENGTH   100
@@ -296,27 +298,27 @@
 
 
 
-class MBReadUtilIface;
+class ReadUtilIface;
 
-class ReadABAQUS : public MBReaderIface
+class ReadABAQUS : public ReaderIface
 {
 public:
   
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
   
   void tokenize( const std::string& str,
                  std::vector<std::string>& tokens,
                  const char* delimiters );
   
   //! load an ABAQUS file
-  MBErrorCode load_file( const char *exodus_file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *exodus_file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
   
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -324,7 +326,7 @@
                                int subset_list_length = 0 );
   
   //! Constructor
-  ReadABAQUS(MBInterface* impl = NULL);
+  ReadABAQUS(Interface* impl = NULL);
   
   //! Destructor
   virtual ~ReadABAQUS();
@@ -333,67 +335,67 @@
   
   void reset();
   
-  MBErrorCode read_heading(MBEntityHandle file_set);
-  MBErrorCode read_part(MBEntityHandle file_set);
-  MBErrorCode read_assembly(MBEntityHandle file_set);
-  MBErrorCode read_unsupported(MBEntityHandle file_set);
-  MBErrorCode read_node_list(MBEntityHandle parent_set);
-  MBErrorCode read_element_list(MBEntityHandle parent_set);
-  MBErrorCode read_node_set(MBEntityHandle parent_set,
-			    MBEntityHandle file_set = 0,
-			    MBEntityHandle assembly_set = 0);
-  MBErrorCode read_element_set(MBEntityHandle parent_set,
-			    MBEntityHandle file_set = 0,
-			    MBEntityHandle assembly_set = 0);
-  MBErrorCode read_solid_section(MBEntityHandle parent_set);
-  MBErrorCode read_instance(MBEntityHandle assembly_set,
-			    MBEntityHandle file_set);
+  ErrorCode read_heading(EntityHandle file_set);
+  ErrorCode read_part(EntityHandle file_set);
+  ErrorCode read_assembly(EntityHandle file_set);
+  ErrorCode read_unsupported(EntityHandle file_set);
+  ErrorCode read_node_list(EntityHandle parent_set);
+  ErrorCode read_element_list(EntityHandle parent_set);
+  ErrorCode read_node_set(EntityHandle parent_set,
+			    EntityHandle file_set = 0,
+			    EntityHandle assembly_set = 0);
+  ErrorCode read_element_set(EntityHandle parent_set,
+			    EntityHandle file_set = 0,
+			    EntityHandle assembly_set = 0);
+  ErrorCode read_solid_section(EntityHandle parent_set);
+  ErrorCode read_instance(EntityHandle assembly_set,
+			    EntityHandle file_set);
   
 
-  MBErrorCode get_elements_by_id(MBEntityHandle parent_set,
+  ErrorCode get_elements_by_id(EntityHandle parent_set,
 				 std::vector<int> element_ids_subset,
-				 MBRange &element_range);
+				 Range &element_range);
   
-  MBErrorCode get_nodes_by_id(MBEntityHandle parent_set,
+  ErrorCode get_nodes_by_id(EntityHandle parent_set,
 			      std::vector<int> node_ids_subset,
-			      MBRange &node_range);
+			      Range &node_range);
     
-  MBErrorCode get_set_by_name(MBEntityHandle parent_set,
+  ErrorCode get_set_by_name(EntityHandle parent_set,
 			      int ABQ_set_type,
 			      std::string set_name,
-			      MBEntityHandle &set_handle);
+			      EntityHandle &set_handle);
 
-  MBErrorCode get_set_elements(MBEntityHandle set_handle,
-			       MBRange &element_range);
+  ErrorCode get_set_elements(EntityHandle set_handle,
+			       Range &element_range);
 
-  MBErrorCode get_set_elements_by_name(MBEntityHandle parent_set,
+  ErrorCode get_set_elements_by_name(EntityHandle parent_set,
 				       int ABQ_set_type,
 				       std::string set_name,
-				       MBRange &element_range);
+				       Range &element_range);
     
 			      
-  MBErrorCode get_set_nodes(MBEntityHandle parent_set,
+  ErrorCode get_set_nodes(EntityHandle parent_set,
 			    int ABQ_set_type,
 			    std::string set_name,
-			    MBRange &node_range);
+			    Range &node_range);
   
-  MBErrorCode add_entity_set(MBEntityHandle parent_set,
+  ErrorCode add_entity_set(EntityHandle parent_set,
 			     int ABQ_set_type,
 			     std::string set_name,
-			     MBEntityHandle &entity_set);
+			     EntityHandle &entity_set);
 
-  MBErrorCode create_instance_of_part(const MBEntityHandle file_set,
-				      const MBEntityHandle parent_set,
+  ErrorCode create_instance_of_part(const EntityHandle file_set,
+				      const EntityHandle parent_set,
 				      const std::string part_name,
 				      const std::string instance_name,
-				      MBEntityHandle &entity_set,
+				      EntityHandle &entity_set,
 				      const std::vector<double> &translation,
 				      const std::vector<double> &rotation);
 
-  MBTag get_tag(const char* tag_name, int tag_size, MBTagType tag_type,
-                MBDataType tag_data_type);
-  MBTag get_tag(const char* tag_name, int tag_size, MBTagType tag_type,
-                MBDataType tag_data_type, const void* def_val);
+  Tag get_tag(const char* tag_name, int tag_size, TagType tag_type,
+                DataType tag_data_type);
+  Tag get_tag(const char* tag_name, int tag_size, TagType tag_type,
+                DataType tag_data_type, const void* def_val);
   
   void cyl2rect(std::vector<double> coord_list);
 
@@ -413,10 +415,10 @@
 				  std::map<std::string,std::string>& params);
 
   //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
 
   // read mesh interface
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
   std::ifstream abFile;        // abaqus file
 
@@ -428,31 +430,32 @@
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
 
-  MBTag mSetTypeTag;
-  MBTag mPartHandleTag;
-  MBTag mInstancePIDTag;
-  MBTag mInstanceGIDTag;
+  Tag mSetTypeTag;
+  Tag mPartHandleTag;
+  Tag mInstancePIDTag;
+  Tag mInstanceGIDTag;
 
-  MBTag mLocalIDTag;
-  MBTag mInstanceHandleTag;
-  MBTag mAssemblyHandleTag;
+  Tag mLocalIDTag;
+  Tag mInstanceHandleTag;
+  Tag mAssemblyHandleTag;
 
-  MBTag mSetNameTag;
-  MBTag mMatNameTag;
+  Tag mSetNameTag;
+  Tag mMatNameTag;
 
   abaqus_line_types  next_line_type;
 
-  std::map<MBEntityHandle,unsigned int> num_part_instances;
-  std::map<MBEntityHandle,unsigned int> num_assembly_instances;
+  std::map<EntityHandle,unsigned int> num_part_instances;
+  std::map<EntityHandle,unsigned int> num_assembly_instances;
   std::map<std::string,unsigned int> matIDmap;
   unsigned mat_id;
   
 };
 
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/io/ReadCCMIO.cpp
===================================================================
--- MOAB/trunk/src/io/ReadCCMIO.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadCCMIO.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,18 +5,20 @@
 #include <string>
 #include <algorithm>
 
-#include "MBCN.hpp"
-#include "MBRange.hpp"
-#include "MBInterface.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInternals.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/Range.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "Internals.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "FileOptions.hpp"
 #include "ReadCCMIO.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/MeshTopoUtil.hpp"
 
 #include "ccmio.h"
 
+namespace moab {
+
 /*
  * CCMIO file structure
  *
@@ -64,17 +66,17 @@
     {if (kCCMIONoErr != a) {if (b) readMeshIface->report_error(b); return MB_FAILURE;}}
   
 
-MBReaderIface* ReadCCMIO::factory( MBInterface* iface )
+ReaderIface* ReadCCMIO::factory( Interface* iface )
 { return new ReadCCMIO( iface ); }
 
-ReadCCMIO::ReadCCMIO(MBInterface* impl)
+ReadCCMIO::ReadCCMIO(Interface* impl)
     : mbImpl(impl)
 {
   assert(impl != NULL);
   
   void* ptr = 0;
-  impl->query_interface( "MBReadUtilIface", &ptr );
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  impl->query_interface( "ReadUtilIface", &ptr );
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   mMaterialSetTag  = 0;
@@ -85,7 +87,7 @@
 
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, 
                               sizeof(int), 
@@ -133,12 +135,12 @@
 ReadCCMIO::~ReadCCMIO() 
 {}
 
-MBErrorCode ReadCCMIO::load_file(const char *file_name,
-                                 const MBEntityHandle* file_set,
+ErrorCode ReadCCMIO::load_file(const char *file_name,
+                                 const EntityHandle* file_set,
                                  const FileOptions& opts,
-                                 const MBReaderIface::IDTag* subset_list,
+                                 const ReaderIface::IDTag* subset_list,
                                  int subset_list_length,
-                                 const MBTag* file_id_tag)
+                                 const Tag* file_id_tag)
 {
   CCMIOID rootID, problemID, stateID, processorID;
   CCMIOError error = kCCMIONoErr;
@@ -147,7 +149,7 @@
   CHKCCMERR(error, "Problem opening file.");
 
     // get the file state
-  MBErrorCode rval = get_state(rootID, problemID, stateID);
+  ErrorCode rval = get_state(rootID, problemID, stateID);
   CHKERR(rval,NULL);
 
     // get processors
@@ -156,7 +158,7 @@
   CHKERR(rval,NULL);
 
   std::set<CCMIOSize_t>::iterator sit;
-  MBRange new_ents, *new_ents_ptr = NULL;
+  Range new_ents, *new_ents_ptr = NULL;
   if (file_set) new_ents_ptr = &new_ents;
   
   for (sit = procs.begin(); sit != procs.end(); sit++) {
@@ -177,12 +179,12 @@
   return rval;
 }
 
-MBErrorCode ReadCCMIO::load_metadata(CCMIOID rootID, CCMIOID problemID,
-                                     const MBEntityHandle *file_set) 
+ErrorCode ReadCCMIO::load_metadata(CCMIOID rootID, CCMIOID problemID,
+                                     const EntityHandle *file_set) 
 {
     // Read the simulation title.
   CCMIOError error = kCCMIONoErr;
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   CCMIONode rootNode;
 
   if (kCCMIONoErr == CCMIOGetEntityNode(&error, rootID, &rootNode)) {
@@ -191,14 +193,14 @@
 
     if (NULL != name && strlen(name) != 0) {
         // make a tag for it and tag the read set
-      MBTag simname;
+      Tag simname;
       rval = mbImpl->tag_get_handle("SimulationName", simname);
       if (MB_TAG_NOT_FOUND == rval) {
         rval = mbImpl->tag_create("SimulationName", strlen(name), MB_TAG_SPARSE, 
                                   MB_TYPE_OPAQUE, simname, NULL);
         CHKERR(rval, "Simulation name tag not found or created.");
       }
-      MBEntityHandle tag_set = (NULL != file_set ? *file_set : 0);
+      EntityHandle tag_set = (NULL != file_set ? *file_set : 0);
       rval = mbImpl->tag_set_data(simname, &tag_set, 1, name);
       CHKERR(rval, "Problem setting simulation name tag.");
 
@@ -212,7 +214,7 @@
   return rval;
 }
 
-MBErrorCode ReadCCMIO::load_matset_data(CCMIOID problemID) 
+ErrorCode ReadCCMIO::load_matset_data(CCMIOID problemID) 
 {
     // make sure there are matsets
   if (newMatsets.empty()) return MB_SUCCESS;
@@ -222,8 +224,8 @@
   CCMIOID next;
   std::vector<char> mtype_name;
   CCMIOError error = kCCMIONoErr;
-  MBTag matNameTag = 0, matPorosityTag = 0, matSpinTag = 0, matGroupTag = 0;
-  MBErrorCode rval = create_matset_tags(matNameTag, matPorosityTag, 
+  Tag matNameTag = 0, matPorosityTag = 0, matSpinTag = 0, matGroupTag = 0;
+  ErrorCode rval = create_matset_tags(matNameTag, matPorosityTag, 
                                         matSpinTag, matGroupTag);
   CHKERR(rval, NULL);
   
@@ -238,7 +240,7 @@
       // do Id first, since it should be set to something to identify set as a matset
     if (kCCMIONoErr != CCMIOReadOpti(NULL, next, "MaterialId", &idum))
       idum = mindex + 1;
-    MBEntityHandle dum_ent = newMatsets[mindex];
+    EntityHandle dum_ent = newMatsets[mindex];
     rval = mbImpl->tag_set_data(mMaterialSetTag, &dum_ent, 1, &idum);
     CHKERR(rval, "Failed to set material set id tag.");
 
@@ -276,10 +278,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::create_matset_tags(MBTag &matNameTag, MBTag &matPorosityTag, 
-                                          MBTag &matSpinTag, MBTag &matGroupTag)
+ErrorCode ReadCCMIO::create_matset_tags(Tag &matNameTag, Tag &matPorosityTag, 
+                                          Tag &matSpinTag, Tag &matGroupTag)
 {
-  MBErrorCode rval = mbImpl->tag_create("MaterialName", NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE,
+  ErrorCode rval = mbImpl->tag_create("MaterialName", NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE,
                                         matNameTag, NULL, true);
   CHKERR(rval, "Failed to create matNameTag.");
 
@@ -298,12 +300,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::read_processor(CCMIOID stateID, CCMIOID problemID,
+ErrorCode ReadCCMIO::read_processor(CCMIOID stateID, CCMIOID problemID,
                                       CCMIOID processorID, CCMIOSize_t proc,
-                                      MBRange *new_ents) 
+                                      Range *new_ents) 
 {
   CCMIOError error = kCCMIONoErr;
-  MBErrorCode rval;
+  ErrorCode rval;
   bool has_solution = true;
   CCMIOID verticesID, topologyID, solutionID;
   
@@ -334,43 +336,43 @@
   return rval;
 }
 
-MBErrorCode ReadCCMIO::read_cells(CCMIOSize_t proc, CCMIOID problemID,
+ErrorCode ReadCCMIO::read_cells(CCMIOSize_t proc, CCMIOID problemID,
                                   CCMIOID verticesID, CCMIOID topologyID,
                                   CCMIOID solutionID, bool has_solution,
-                                  TupleList &vert_map, MBRange *new_ents) 
+                                  TupleList &vert_map, Range *new_ents) 
 {
 
     // read the faces.
     // face_map fields: s:forward/reverse, i: cell id, ul: face handle, r: none
-  MBErrorCode rval;
-#ifdef TUPLE_LIST
+  ErrorCode rval;
+#ifdef READCCMIO_USE_TUPLE_LIST
   TupleList face_map(1, 1, 1, 0, 0); 
 #else
   TupleList face_map;
   SenseList sense_map;
 #endif
   rval = read_all_faces(topologyID, vert_map, face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                         , sense_map
 #endif
                         , new_ents);
   CHKERR(rval, NULL);
   
     // now construct the cells; sort the face map by cell ids first
-#ifdef TUPLE_LIST  
+#ifdef READCCMIO_USE_TUPLE_LIST  
   rval = face_map.sort(1);
   CHKERR(rval, "Couldn't sort face map by cell id.");
 #endif
-  std::vector<MBEntityHandle> new_cells;
+  std::vector<EntityHandle> new_cells;
   rval = construct_cells(face_map, 
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                          sense_map,
 #endif
                          vert_map, new_cells);
   CHKERR(rval, NULL);
   if (new_ents) {
-    MBRange::iterator rit = new_ents->end();
-    std::vector<MBEntityHandle>::reverse_iterator vit;
+    Range::iterator rit = new_ents->end();
+    std::vector<EntityHandle>::reverse_iterator vit;
     for (vit = new_cells.rbegin(); vit != new_cells.rend(); vit++)
       rit = new_ents->insert(rit, *vit);
   }
@@ -381,9 +383,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::read_gids_and_types(CCMIOID problemID,
+ErrorCode ReadCCMIO::read_gids_and_types(CCMIOID problemID,
                                            CCMIOID topologyID,
-                                           std::vector<MBEntityHandle> &cells) 
+                                           std::vector<EntityHandle> &cells) 
 {
     // get the cells entity and number of cells
   CCMIOSize_t num_cells;
@@ -404,7 +406,7 @@
                CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd));
   CHKCCMERR(error, "Couldn't read cells or cell id map.");
 
-  MBErrorCode rval = mbImpl->tag_set_data(mGlobalIdTag, &cells[0], 
+  ErrorCode rval = mbImpl->tag_set_data(mGlobalIdTag, &cells[0], 
                                           cells.size(), &cell_gids[0]);
   CHKERR(rval, "Couldn't set gids tag.");
 
@@ -422,7 +424,7 @@
 
     // create the matsets
   for (int i = 0; i < num_matsets; i++) {
-    MBEntityHandle matset;
+    EntityHandle matset;
     rval = mbImpl->create_meshset(MESHSET_SET, matset);
     CHKERR(rval, "Couldn't create material set.");
     newMatsets.insert(matset);
@@ -445,7 +447,7 @@
   }
   else {
       // now stream through cell types, gather cells for each type, add to matsets
-    MBRange mcells;
+    Range mcells;
     for (int i = 1; i <= num_matsets; i++) {
       mcells.clear();
         // go backwards, since it's more efficient when adding to the end of a range
@@ -462,18 +464,18 @@
 }
 
 
-MBErrorCode ReadCCMIO::construct_cells(TupleList &face_map, 
-#ifndef TUPLE_LIST
+ErrorCode ReadCCMIO::construct_cells(TupleList &face_map, 
+#ifndef READCCMIO_USE_TUPLE_LIST
                                        SenseList &sense_map, 
 #endif
                                        TupleList &vert_map,
-                                       std::vector<MBEntityHandle> &new_cells) 
+                                       std::vector<EntityHandle> &new_cells) 
 {
-  std::vector<MBEntityHandle> facehs;
+  std::vector<EntityHandle> facehs;
   std::vector<int> senses;
-  MBEntityHandle cell;
-  MBErrorCode tmp_rval, rval = MB_SUCCESS;
-#ifdef TUPLE_LIST
+  EntityHandle cell;
+  ErrorCode tmp_rval, rval = MB_SUCCESS;
+#ifdef READCCMIO_USE_TUPLE_LIST
   unsigned int i = 0;
   while (i < face_map.n) {
       // pull out face handles bounding the same cell
@@ -482,13 +484,13 @@
     unsigned int inext = i;
     while (face_map.get_int(inext) == this_id && inext <= face_map.n) {
       inext++;
-      MBEntityHandle face = face_map.get_ulong(inext);
+      EntityHandle face = face_map.get_ulong(inext);
       facehs.push_back(face);
       senses.push_back(face_map.get_short(inext));
     }
 #else
       
-  std::map<int,std::vector<MBEntityHandle> >::iterator fmit;
+  std::map<int,std::vector<EntityHandle> >::iterator fmit;
   std::map<int,std::vector<int> >::iterator smit;
   for (fmit = face_map.begin(), smit = sense_map.begin();
        fmit != face_map.end(); fmit++, smit++) {
@@ -512,14 +514,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::create_cell_from_faces(std::vector<MBEntityHandle> &facehs,
+ErrorCode ReadCCMIO::create_cell_from_faces(std::vector<EntityHandle> &facehs,
                                               std::vector<int> &senses,
-                                              MBEntityHandle &cell) 
+                                              EntityHandle &cell) 
 {
     // test to see if they're one type
-  MBEntityType this_type = mbImpl->type_from_handle(facehs[0]);
+  EntityType this_type = mbImpl->type_from_handle(facehs[0]);
   bool same_type = true;
-  for (std::vector<MBEntityHandle>::iterator vit = facehs.begin(); vit != facehs.end(); vit++) {
+  for (std::vector<EntityHandle>::iterator vit = facehs.begin(); vit != facehs.end(); vit++) {
     if (this_type != mbImpl->type_from_handle(*vit)) {
       same_type = false;
       break;
@@ -527,7 +529,7 @@
   }
   
     // if different, we can quit here, we'll consider this a polyhedron
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   if (!same_type || 
       (MBTRI == this_type && facehs.size() != 4) ||
       (MBQUAD == this_type && facehs.size() != 6) ||
@@ -538,7 +540,7 @@
   }
   
     // try tet and hex elements; get connectivity of first face
-  std::vector<MBEntityHandle> verts;
+  std::vector<EntityHandle> verts;
   rval = mbImpl->get_connectivity(&facehs[0], 1, verts);
   CHKERR(rval, "Couldn't get connectivity.");
   bool match = false;
@@ -547,11 +549,11 @@
     // into entity
   if (senses[0] > 0) std::reverse(verts.begin(), verts.end());
 
-  std::vector<MBEntityHandle> storage;
+  std::vector<EntityHandle> storage;
   MeshTopoUtil mtu(mbImpl);
   if (MBTRI == this_type) {
       // get the 4th vertex through the next tri
-    const MBEntityHandle *conn; int conn_size;
+    const EntityHandle *conn; int conn_size;
     rval = mbImpl->get_connectivity(facehs[1], conn, conn_size, true, &storage);
     CHKERR(rval, "Couldn't get connectivity.");
     int i = 0;
@@ -575,32 +577,32 @@
 
 
       // get the other vertices for this hex; need to find the quad with no common vertices
-    MBRange tmp_faces, tmp_verts;
+    Range tmp_faces, tmp_verts;
 
       // get q1, which shares 2 vertices with q0
-    std::copy(facehs.begin(), facehs.end(), mb_range_inserter(tmp_faces));
+    std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces));
     rval = mbImpl->get_adjacencies(&verts[0], 2, 2, false, tmp_faces);
     if (MB_SUCCESS != rval || tmp_faces.size() != 2)
       CHKERR(MB_FAILURE, "Couldn't get adj face.");
     tmp_faces.erase(facehs[0]);
-    MBEntityHandle q1 = *tmp_faces.begin();
+    EntityHandle q1 = *tmp_faces.begin();
       // get other 2 verts of q1
     rval = mbImpl->get_connectivity(&q1, 1, tmp_verts);
     CHKERR(rval, "Couldn't get adj verts.");
     tmp_verts.erase(verts[0]); tmp_verts.erase(verts[1]);
       // get q2
-    std::copy(facehs.begin(), facehs.end(), mb_range_inserter(tmp_faces));
+    std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces));
     rval = mbImpl->get_adjacencies(tmp_verts, 2, false, tmp_faces);
     if (MB_SUCCESS != rval || tmp_faces.size() != 2)
       CHKERR(MB_FAILURE, "Couldn't get adj face.");
     tmp_faces.erase(q1);
-    MBEntityHandle q2 = *tmp_faces.begin();
+    EntityHandle q2 = *tmp_faces.begin();
       // get verts in q2
     rval = mbImpl->get_connectivity(&q2, 1, storage);
     CHKERR(rval, "Couldn't get adj vertices.");
 
       // get verts in q1 opposite from v[1] and v[0] in q0
-    MBEntityHandle v0 = 0, v1 = 0;
+    EntityHandle v0 = 0, v1 = 0;
     rval = mtu.opposite_entity(q1, verts[1], v0);
     rval = mtu.opposite_entity(q1, verts[0], v1);
     if (!v0 || !v1)
@@ -633,16 +635,16 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode ReadCCMIO::read_all_faces(CCMIOID topologyID, TupleList &vert_map, 
+ErrorCode ReadCCMIO::read_all_faces(CCMIOID topologyID, TupleList &vert_map, 
                                       TupleList &face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                                       ,SenseList &sense_map
 #endif
-                                      , MBRange *new_faces) 
+                                      , Range *new_faces) 
 {
   CCMIOSize_t index = CCMIOSIZEC(0);
   CCMIOID faceID;
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // get total # internal/bdy faces, size the face map accordingly
   int nint_faces = 0, nbdy_faces = 0;
@@ -657,7 +659,7 @@
   CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID);
   CCMIOEntitySize(&error, faceID, &nf, NULL);
   nint_faces = nint_faces + nf;
-#ifdef TUPLE_LIST
+#ifdef READCCMIO_USE_TUPLE_LIST
   face_map.resize(2*nint_faces + nbdy_faces);
 #endif
   
@@ -667,7 +669,7 @@
                                         &faceID))
   {
     rval = read_faces(faceID, kCCMIOBoundaryFaces, vert_map, face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                       , sense_map
 #endif
                       , new_faces);
@@ -678,7 +680,7 @@
   CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID);
 
   rval = read_faces(faceID, kCCMIOInternalFaces, vert_map,face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                     , sense_map
 #endif
                     , new_faces);
@@ -687,13 +689,13 @@
   return rval;
 }
 
-MBErrorCode ReadCCMIO::read_faces(CCMIOID faceID, CCMIOEntity bdy_or_int,
+ErrorCode ReadCCMIO::read_faces(CCMIOID faceID, CCMIOEntity bdy_or_int,
                                   TupleList &vert_map,
                                   TupleList &face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                                   ,SenseList &sense_map
 #endif
-                                  , MBRange *new_faces)
+                                  , Range *new_faces)
 {
   if (kCCMIOInternalFaces != bdy_or_int && kCCMIOBoundaryFaces != bdy_or_int)
     CHKERR(MB_FAILURE, "Face type isn't boundary or internal.");
@@ -721,8 +723,8 @@
                  farray, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd));
   CHKCCMERR(error, "Trouble reading face connectivity.");
 
-  std::vector<MBEntityHandle> face_handles(GETINT32(num_faces), 0);
-  MBErrorCode rval = make_faces(farray, vert_map, face_handles);
+  std::vector<EntityHandle> face_handles(GETINT32(num_faces), 0);
+  ErrorCode rval = make_faces(farray, vert_map, face_handles);
   CHKERR(rval, NULL);
 
     // read face cells and make tuples
@@ -735,7 +737,7 @@
 
   int *tmp_ptr = face_cells;
   for (int i = 0; i < num_faces; i++) {
-#ifdef TUPLE_LIST
+#ifdef READCCMIO_USE_TUPLE_LIST
     short forward = 1, reverse = -1;
     face_map.push_back(&forward, tmp_ptr++, &face_handles[i], NULL);
     if (2 == num_sides)
@@ -760,8 +762,8 @@
     // ok, now sort face handles, and add to range
   std::sort(face_handles.begin(), face_handles.end());
   if (new_faces) {
-    MBRange::iterator rit = new_faces->end();
-    for (std::vector<MBEntityHandle>::reverse_iterator vit = face_handles.rbegin(); 
+    Range::iterator rit = new_faces->end();
+    for (std::vector<EntityHandle>::reverse_iterator vit = face_handles.rbegin(); 
          vit != face_handles.rend(); vit++)
       rit = new_faces->insert(rit, *vit);
   }
@@ -770,13 +772,13 @@
 }
   
 
-MBErrorCode ReadCCMIO::make_faces(int *farray, 
+ErrorCode ReadCCMIO::make_faces(int *farray, 
                                   TupleList &vert_map,
-                                  std::vector<MBEntityHandle> &new_faces) 
+                                  std::vector<EntityHandle> &new_faces) 
 {
   unsigned int num_faces = new_faces.size();
-  std::vector<MBEntityHandle> verts;
-  MBErrorCode tmp_rval = MB_SUCCESS, rval = MB_SUCCESS;
+  std::vector<EntityHandle> verts;
+  ErrorCode tmp_rval = MB_SUCCESS, rval = MB_SUCCESS;
   
   for (unsigned int i = 0; i < num_faces; i++) {
     int num_verts = *farray++;
@@ -784,7 +786,7 @@
 
       // fill in connectivity by looking up by gid in vert tuple_list
     for (int j = 0; j < num_verts; j++) {
-#ifdef TUPLE_LIST
+#ifdef READCCMIO_USE_TUPLE_LIST
       int tindex = vert_map.find(1, farray[j]);
       if (-1 == tindex) {
         tmp_rval = MB_FAILURE;
@@ -800,9 +802,9 @@
     if (MB_SUCCESS == tmp_rval) {
     
         // make face
-      MBEntityType ftype = (3 == num_verts ? MBTRI :
+      EntityType ftype = (3 == num_verts ? MBTRI :
                             (4 == num_verts ? MBQUAD : MBPOLYGON));
-      MBEntityHandle faceh;
+      EntityHandle faceh;
       tmp_rval = mbImpl->create_element(ftype, &verts[0], num_verts, faceh);
       if (faceh) new_faces[i] = faceh;
     }
@@ -813,9 +815,9 @@
   return rval;
 }
 
-MBErrorCode ReadCCMIO::read_vertices(CCMIOSize_t proc, CCMIOID processorID, CCMIOID verticesID,
+ErrorCode ReadCCMIO::read_vertices(CCMIOSize_t proc, CCMIOID processorID, CCMIOID verticesID,
                                      CCMIOID topologyID, CCMIOID solutionID, bool has_solution,
-                                     MBRange *verts, TupleList &vert_map) 
+                                     Range *verts, TupleList &vert_map) 
 {
   CCMIOError error = kCCMIONoErr;
   
@@ -831,7 +833,7 @@
   CHKCCMERR(error, "Couldn't get number of dimensions.");
 
     // allocate vertex space
-  MBEntityHandle node_handle = 0;
+  EntityHandle node_handle = 0;
   std::vector<double*> arrays;
   readMeshIface->get_node_arrays(3, GETINT32(nverts), MB_START_ID, node_handle, arrays);
 
@@ -867,7 +869,7 @@
   std::vector<int> gids(GETINT32(nverts));
   CCMIOReadMap(&error, mapID, &gids[0], CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd));
   CHKCCMERR(error, "Trouble reading vertex global ids.");
-#ifdef TUPLE_LIST
+#ifdef READCCMIO_USE_TUPLE_LIST
   vert_map.resize(GETINT32(nverts));
   for (i = 0; i < GETINT32(nverts); i++) {
     vert_map.push_back(NULL, &gids[i], &node_handle, NULL);
@@ -881,7 +883,7 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode ReadCCMIO::get_processors(CCMIOID stateID, CCMIOID &processorID,
+ErrorCode ReadCCMIO::get_processors(CCMIOID stateID, CCMIOID &processorID,
                                       std::set<CCMIOSize_t> &procs) 
 {
   CCMIOSize_t proc = CCMIOSIZEC(0);
@@ -892,7 +894,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::get_state(CCMIOID rootID, CCMIOID &problemID, CCMIOID &stateID) 
+ErrorCode ReadCCMIO::get_state(CCMIOID rootID, CCMIOID &problemID, CCMIOID &stateID) 
 {
   CCMIOError error = kCCMIONoErr;
   
@@ -911,7 +913,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadCCMIO::read_tag_values( const char* file_name,
+ErrorCode ReadCCMIO::read_tag_values( const char* file_name,
                                         const char* tag_name,
                                         const FileOptions& opts,
                                         std::vector<int>& tag_values_out,
@@ -1982,3 +1984,6 @@
 
 
 */
+
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadCCMIO.hpp
===================================================================
--- MOAB/trunk/src/io/ReadCCMIO.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadCCMIO.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -10,130 +10,135 @@
 #include <map>
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/ReaderIface.hpp"
 #include "TupleList.hpp"
 #include "ccmio.h"
 
-#define TupleList std::map<int, std::vector<MBEntityHandle> > 
-#define SenseList std::map<int, std::vector<int> > 
-#undef TUPLE_LIST
+namespace moab {
 
-class MBReadUtilIface;
+#undef READCCMIO_USE_TUPLE_LIST
 
-class MB_DLL_EXPORT ReadCCMIO : public MBReaderIface
+class ReadUtilIface;
+
+class ReadCCMIO : public ReaderIface
 {
  
 public:
 
+  typedef std::map<int, std::vector<EntityHandle> > TupleList;
+  typedef std::map<int, std::vector<int> > SenseList;
+
     //! Constructor
-  ReadCCMIO(MBInterface *impl);
+  ReadCCMIO(Interface *impl);
 
    //! Destructor
   virtual ~ReadCCMIO();
   
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
-  MBErrorCode load_file(const char *file_name,
-                        const MBEntityHandle* file_set,
+  ErrorCode load_file(const char *file_name,
+                        const EntityHandle* file_set,
                         const FileOptions& opts,
-                        const MBReaderIface::IDTag* subset_list,
+                        const ReaderIface::IDTag* subset_list,
                         int subset_list_length,
-                        const MBTag* file_id_tag);
+                        const Tag* file_id_tag);
 
 private:
   
-  MBErrorCode read_processor(CCMIOID rootID, CCMIOID problemID,
+  ErrorCode read_processor(CCMIOID rootID, CCMIOID problemID,
                              CCMIOID processorID, CCMIOSize_t proc,
-                             MBRange *new_ents);
+                             Range *new_ents);
 
 
-  MBErrorCode read_cells(CCMIOSize_t proc, CCMIOID processorID,
+  ErrorCode read_cells(CCMIOSize_t proc, CCMIOID processorID,
                          CCMIOID verticesID, CCMIOID topologyID,
                          CCMIOID solutionID, bool has_solution,
-                         TupleList &vert_map, MBRange *new_cells);
+                         TupleList &vert_map, Range *new_cells);
 
 
-  MBErrorCode construct_cells(TupleList &face_map, 
-#ifndef TUPLE_LIST
+  ErrorCode construct_cells(TupleList &face_map, 
+#ifndef READCCMIO_USE_TUPLE_LIST
                               SenseList &sense_map,
 #endif
                               TupleList &vert_map, 
-                              std::vector<MBEntityHandle> &new_cells);
+                              std::vector<EntityHandle> &new_cells);
 
 
-  MBErrorCode create_cell_from_faces(std::vector<MBEntityHandle> &facehs,
+  ErrorCode create_cell_from_faces(std::vector<EntityHandle> &facehs,
                                      std::vector<int> &senses,
-                                     MBEntityHandle &cell);
+                                     EntityHandle &cell);
 
-  MBErrorCode read_gids_and_types(CCMIOID problemID,
+  ErrorCode read_gids_and_types(CCMIOID problemID,
                                   CCMIOID topologyID,
-                                  std::vector<MBEntityHandle> &cells);
+                                  std::vector<EntityHandle> &cells);
 
-  MBErrorCode read_all_faces(CCMIOID topologyID, TupleList &vert_map, 
+  ErrorCode read_all_faces(CCMIOID topologyID, TupleList &vert_map, 
                              TupleList &face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                              ,SenseList &sense_map
 #endif
-                             , MBRange *new_faces);
+                             , Range *new_faces);
 
 
-  MBErrorCode read_faces(CCMIOID faceID, CCMIOEntity bdy_or_int,
+  ErrorCode read_faces(CCMIOID faceID, CCMIOEntity bdy_or_int,
                          TupleList &vert_map,
                          TupleList &face_map
-#ifndef TUPLE_LIST
+#ifndef READCCMIO_USE_TUPLE_LIST
                          ,SenseList &sense_map
 #endif
-                         , MBRange *new_faces);
+                         , Range *new_faces);
 
-  MBErrorCode make_faces(int *farray, 
+  ErrorCode make_faces(int *farray, 
                          TupleList &vert_map,
-                         std::vector<MBEntityHandle> &new_faces);
+                         std::vector<EntityHandle> &new_faces);
 
-  MBErrorCode read_vertices(CCMIOSize_t proc, CCMIOID processorID, CCMIOID verticesID,
+  ErrorCode read_vertices(CCMIOSize_t proc, CCMIOID processorID, CCMIOID verticesID,
                             CCMIOID topologyID, CCMIOID solutionID, bool has_solution,
-                            MBRange *verts, TupleList &vert_map);
+                            Range *verts, TupleList &vert_map);
 
 
-  MBErrorCode get_processors(CCMIOID stateID, CCMIOID &processorID,
+  ErrorCode get_processors(CCMIOID stateID, CCMIOID &processorID,
                              std::set<CCMIOSize_t> &procs);
 
 
-  MBErrorCode get_state(CCMIOID rootID, CCMIOID &problemID, CCMIOID &stateID);
+  ErrorCode get_state(CCMIOID rootID, CCMIOID &problemID, CCMIOID &stateID);
 
 
-  virtual MBErrorCode read_tag_values( const char* file_name,
+  virtual ErrorCode read_tag_values( const char* file_name,
                                        const char* tag_name,
                                        const FileOptions& opts,
                                        std::vector<int>& tag_values_out,
                                        const IDTag* subset_list = 0,
                                        int subset_list_length = 0 );
   
-  MBErrorCode load_matset_data(CCMIOID problemID);
+  ErrorCode load_matset_data(CCMIOID problemID);
   
-  MBErrorCode load_metadata(CCMIOID rootID, CCMIOID problemID, 
-                            const MBEntityHandle *file_set);
+  ErrorCode load_metadata(CCMIOID rootID, CCMIOID problemID, 
+                            const EntityHandle *file_set);
   
-  MBErrorCode create_matset_tags(MBTag &matNameTag, MBTag &matPorosityTag, 
-                                 MBTag &matSpinTag, MBTag &matGroupTag);
+  ErrorCode create_matset_tags(Tag &matNameTag, Tag &matPorosityTag, 
+                                 Tag &matSpinTag, Tag &matGroupTag);
 
     //! Cached tags for reading.  Note that all these tags are defined when the
     //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGlobalIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGlobalIdTag;
   
-  MBInterface *mbImpl;
+  Interface *mbImpl;
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
-  MBRange newMatsets;
+  Range newMatsets;
   
   bool hasSolution;
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/ReadCGM.cpp
===================================================================
--- MOAB/trunk/src/io/ReadCGM.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadCGM.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -33,21 +33,23 @@
 #include "Body.hpp"
 #include "InitCGMA.hpp"
 
-#include "MBCore.hpp"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
 #include "FileOptions.hpp"
 
-#include "GeomTopoTool.hpp"
+#include "moab/GeomTopoTool.hpp"
 
 #include <stdio.h>
 #include <algorithm>
 #include <assert.h>
 
 #include "ReadCGM.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/ReadUtilIface.hpp"
 
+namespace moab {
+
 #define GF_CUBIT_FILE_TYPE    "CUBIT"
 #define GF_STEP_FILE_TYPE     "STEP"
 #define GF_IGES_FILE_TYPE     "IGES"
@@ -55,10 +57,10 @@
 #define GF_ACIS_BIN_FILE_TYPE "ACIS_SAB"
 #define GF_OCC_BREP_FILE_TYPE "OCC"
 
-MBReaderIface* ReadCGM::factory( MBInterface* iface )
+ReaderIface* ReadCGM::factory( Interface* iface )
 { return new ReadCGM( iface ); }
 
-ReadCGM::ReadCGM(MBInterface *impl)
+ReadCGM::ReadCGM(Interface *impl)
   : geom_tag(0), id_tag(0), name_tag(0), category_tag(0), faceting_tol_tag(0), 
     geometry_resabs_tag(0)
 {
@@ -66,11 +68,11 @@
   mdbImpl = impl;
   myGeomTool = new GeomTopoTool(impl);
   void* ptr = 0;
-  impl->query_interface( "MBReadUtilIface", &ptr );
+  impl->query_interface( "ReadUtilIface", &ptr );
   assert(NULL != ptr);
-  readUtilIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  readUtilIface = reinterpret_cast<ReadUtilIface*>(ptr);
 
-  MBErrorCode rval;
+  ErrorCode rval;
 
   // get some tag handles
   rval = mdbImpl->tag_create( GEOM_DIMENSION_TAG_NAME, sizeof(int), 
@@ -96,13 +98,13 @@
 
 ReadCGM::~ReadCGM()
 {
-  std::string iface_name = "MBReadUtilIface";
+  std::string iface_name = "ReadUtilIface";
   mdbImpl->release_interface(iface_name, readUtilIface);
   delete myGeomTool;
 }
 
 
-MBErrorCode ReadCGM::read_tag_values( const char* /* file_name */,
+ErrorCode ReadCGM::read_tag_values( const char* /* file_name */,
                                       const char* /* tag_name */,
                                       const FileOptions& /* opts */,
                                       std::vector<int>& /* tag_values_out */,
@@ -115,15 +117,15 @@
 
 
 // copy geometry into mesh database
-MBErrorCode ReadCGM::load_file(const char *cgm_file_name,
-                      const MBEntityHandle* file_set,
+ErrorCode ReadCGM::load_file(const char *cgm_file_name,
+                      const EntityHandle* file_set,
                       const FileOptions& opts,
-                      const MBReaderIface::IDTag* subset_list,
+                      const ReaderIface::IDTag* subset_list,
                       int subset_list_length,
-                      const MBTag* file_id_tag)
+                      const Tag* file_id_tag)
 {
   // blocks_to_load and num_blocks are ignored.
-  MBErrorCode rval;
+  ErrorCode rval;
 
   if (subset_list && subset_list_length) {
     readUtilIface->report_error( "Reading subset of files not supported for CGM data." );
@@ -158,8 +160,8 @@
   }
 
   // CGM data
-  std::map<RefEntity*,MBEntityHandle> entmap[5]; // one for each dim, and one for groups
-  std::map<RefEntity*,MBEntityHandle>::iterator ci;
+  std::map<RefEntity*,EntityHandle> entmap[5]; // one for each dim, and one for groups
+  std::map<RefEntity*,EntityHandle>::iterator ci;
   const char geom_categories[][CATEGORY_TAG_SIZE] = 
     {"Vertex\0", "Curve\0", "Surface\0", "Volume\0", "Group\0"};
   const char* const names[] = { "Vertex", "Curve", "Surface", "Volume"};
@@ -205,7 +207,7 @@
     entlist.reset();
     for (int i = entlist.size(); i--; ) {
       RefEntity* ent = entlist.get_and_step();
-      MBEntityHandle handle;
+      EntityHandle handle;
       rval = mdbImpl->create_meshset( dim == 1 ? MESHSET_ORDERED : MESHSET_SET, handle );
       if (MB_SUCCESS != rval)
         return rval;
@@ -235,7 +237,7 @@
       entlist.reset();
       for (int i = entlist.size(); i--; ) {
         RefEntity* ent = entlist.get_and_step();
-        MBEntityHandle h = entmap[dim-1][ent];
+        EntityHandle h = entmap[dim-1][ent];
         rval = mdbImpl->add_parent_child( ci->second, h );
         if (MB_SUCCESS != rval)
           return rval;
@@ -285,7 +287,7 @@
   }
 
     // create entity sets for all ref groups
-  std::vector<MBTag> extra_name_tags;
+  std::vector<Tag> extra_name_tags;
   DLIList<CubitString*> name_list;
   entlist.clean_out();
   GeometryQueryTool::instance()->ref_entity_list( "group", entlist );
@@ -299,7 +301,7 @@
     name_list.reset();
     CubitString name = *name_list.get();
     
-    MBEntityHandle h;
+    EntityHandle h;
     rval = mdbImpl->create_meshset( MESHSET_SET, h );
     if (MB_SUCCESS != rval)
       return rval;
@@ -326,7 +328,7 @@
     if (name_list.size() > 1) {
       for (int j = extra_name_tags.size(); j < name_list.size(); ++j) {
         sprintf( namebuf, "EXTRA_%s%d", NAME_TAG_NAME, j );
-        MBTag t;
+        Tag t;
         rval = mdbImpl->tag_create( namebuf, NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE, t, 0, true );
         assert(!rval);
         extra_name_tags.push_back(t);
@@ -355,7 +357,7 @@
     entlist.clean_out();
     grp->get_child_ref_entities( entlist );
     
-    MBRange entities;
+    Range entities;
     while (entlist.size()) {
       RefEntity* ent = entlist.pop();
       int dim = ent->dimension();
@@ -410,7 +412,7 @@
   for (ci = entmap[0].begin(); ci != entmap[0].end(); ++ci) {
     CubitVector pos = dynamic_cast<RefVertex*>(ci->first)->coordinates();
     double coords[3] = {pos.x(), pos.y(), pos.z()};
-    MBEntityHandle vh;
+    EntityHandle vh;
     rval = mdbImpl->create_vertex( coords, vh );
     if (MB_SUCCESS != rval)
       return MB_FAILURE;
@@ -453,7 +455,7 @@
         std::cerr << "Warning: No facetting for curve " << edge->id() << std::endl;
         continue;
       }
-      MBEntityHandle h = entmap[0][start_vtx];
+      EntityHandle h = entmap[0][start_vtx];
       rval = mdbImpl->add_entities( ci->second, &h, 1 );
       if (MB_SUCCESS != rval)
         return MB_FAILURE;
@@ -473,11 +475,11 @@
     }
     
       // create interior points
-    std::vector<MBEntityHandle> verts, edges;
+    std::vector<EntityHandle> verts, edges;
     verts.push_back( entmap[0][start_vtx] );
     for (size_t i = 1; i < points.size() - 1; ++i) {
       double coords[] = { points[i].x(), points[i].y(), points[i].z() };
-      MBEntityHandle h;
+      EntityHandle h;
       rval = mdbImpl->create_vertex( coords, h );
       if (MB_SUCCESS != rval)
         return MB_FAILURE;
@@ -487,7 +489,7 @@
     
       // create edges
     for (size_t i = 0; i < verts.size()-1; ++i) {
-      MBEntityHandle h;
+      EntityHandle h;
       rval = mdbImpl->create_element( MBEDGE, &verts[i], 2, h );
       if (MB_SUCCESS != rval)
         return MB_FAILURE;
@@ -517,7 +519,7 @@
       return MB_FAILURE;
 
       // declare array of all vertex handles
-    std::vector<MBEntityHandle> verts( data.pointListCount, 0 );
+    std::vector<EntityHandle> verts( data.pointListCount, 0 );
     
       // get list of vertices in surface
     me_list.clean_out();
@@ -554,8 +556,8 @@
     }
     
       // now create facets
-    MBRange facets;
-    std::vector<MBEntityHandle> corners;
+    Range facets;
+    std::vector<EntityHandle> corners;
     for (int i = 0; i < data.fListCount; i += data.facet_list()[i]+1) {
       int* facet = data.facet_list() + i;
       corners.resize( *facet );
@@ -566,7 +568,7 @@
         }
         corners[j-1] = verts[facet[j]];
       }
-      MBEntityType type;
+      EntityType type;
       if (*facet == 3)
         type = MBTRI;
       else {
@@ -581,7 +583,7 @@
       // if (surf->bridge_sense() == CUBIT_REVERSED)
       //   std::reverse( corners.begin(), corners.end() );
       
-      MBEntityHandle h;
+      EntityHandle h;
       rval = mdbImpl->create_element( type, &corners[0], corners.size(), h );
       if (MB_SUCCESS != rval)
         return MB_FAILURE;
@@ -718,3 +720,4 @@
   }
 }
 
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadCGM.hpp
===================================================================
--- MOAB/trunk/src/io/ReadCGM.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadCGM.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -34,16 +34,19 @@
 #endif
 
 #include <string>
-class MBReadUtilIface;
+#include "moab/ReaderIface.hpp"
+
+namespace moab {
+
+class ReadUtilIface;
 class GeomTopoTool;
 
-#include "MBReaderIface.hpp"
-class ReadCGM : public MBReaderIface
+class ReadCGM : public ReaderIface
 {
 
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
   void tokenize( const std::string& str,
                  std::vector<std::string>& tokens,
@@ -55,14 +58,14 @@
     //  * FACET_DISTANCE_TOLERANCE=<real> (default: 0.001)
     //  * MAX_FACET_EDGE_LENGTH=<real> (default: 0.0)
     //  * CGM_ATTRIBS=<yes|no>         (default: no)
-  MBErrorCode load_file( const char *cgm_file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *cgm_file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -70,14 +73,14 @@
                                int subset_list_length = 0 );
 
    //! Constructor
-   ReadCGM(MBInterface* impl = NULL);
+   ReadCGM(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadCGM();
 
 private:
 
-  MBReadUtilIface* readUtilIface;
+  ReadUtilIface* readUtilIface;
 
   GeomTopoTool* myGeomTool;
 
@@ -95,10 +98,12 @@
   //------------member variables ------------//
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
 
-  MBTag geom_tag, id_tag, name_tag, category_tag, faceting_tol_tag, 
+  Tag geom_tag, id_tag, name_tag, category_tag, faceting_tol_tag, 
         geometry_resabs_tag;
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/ReadGmsh.cpp
===================================================================
--- MOAB/trunk/src/io/ReadGmsh.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadGmsh.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,13 +24,13 @@
 
 #include "ReadGmsh.hpp"
 #include "FileTokenizer.hpp" // for file tokenizer
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBParallelConventions.h"
-#include "MBCN.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBCN.hpp"
 #include "GmshUtil.hpp"
 
 #include <errno.h>
@@ -38,27 +38,29 @@
 #include <map>
 #include <set>
 
-MBReaderIface* ReadGmsh::factory( MBInterface* iface )
+namespace moab {
+
+ReaderIface* ReadGmsh::factory( Interface* iface )
   { return new ReadGmsh(iface); }
 
-ReadGmsh::ReadGmsh(MBInterface* impl)
+ReadGmsh::ReadGmsh(Interface* impl)
     : mdbImpl(impl)
 {
   void* ptr = 0;
-  mdbImpl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  mdbImpl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 ReadGmsh::~ReadGmsh()
 {
   if (readMeshIface) {
-    mdbImpl->release_interface("MBReadUtilIface", readMeshIface);
+    mdbImpl->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
 
 
-MBErrorCode ReadGmsh::read_tag_values( const char* /* file_name */,
+ErrorCode ReadGmsh::read_tag_values( const char* /* file_name */,
                                        const char* /* tag_name */,
                                        const FileOptions& /* opts */,
                                        std::vector<int>& /* tag_values_out */,
@@ -69,12 +71,12 @@
 }
 
 
-MBErrorCode ReadGmsh::load_file( const char* filename, 
-                                 const MBEntityHandle*,
+ErrorCode ReadGmsh::load_file( const char* filename, 
+                                 const EntityHandle*,
                                  const FileOptions& ,
-                                 const MBReaderIface::IDTag* subset_list,
+                                 const ReaderIface::IDTag* subset_list,
                                  int subset_list_length,
-                                 const MBTag* file_id_tag )
+                                 const Tag* file_id_tag )
 {
   int num_material_sets = 0;
   const int* material_set_list = 0;
@@ -88,7 +90,7 @@
   }
 
   geomSets.clear();
-  MBErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, globalId );
+  ErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, globalId );
   if (MB_TAG_NOT_FOUND == result)
     result = mdbImpl->tag_create( GLOBAL_ID_TAG_NAME,
                                   sizeof(int), MB_TAG_SPARSE,
@@ -103,7 +105,7 @@
     blocks.insert( *material_set_list );
   
     // Map of ID->handle for nodes
-  std::map<long,MBEntityHandle> node_id_map;
+  std::map<long,EntityHandle> node_id_map;
   int data_size = 8;
   
     // Open file and hand off pointer to tokenizer
@@ -148,7 +150,7 @@
   
     // allocate nodes
   std::vector<double*> coord_arrays;
-  MBEntityHandle handle = 0;
+  EntityHandle handle = 0;
   result = readMeshIface->get_node_arrays( 3, num_nodes, MB_START_ID, 
                                            handle, coord_arrays );
   if (MB_SUCCESS != result)
@@ -167,7 +169,7 @@
         !tokens.get_doubles( 1, z++ ))
       return MB_FILE_WRITE_ERROR;
     
-    if (!node_id_map.insert( std::pair<long,MBEntityHandle>( id, handle ) ).second)
+    if (!node_id_map.insert( std::pair<long,EntityHandle>( id, handle ) ).second)
     {
       readMeshIface->report_error( "Dulicate node ID at line %d\n",
                                    tokens.line_number() );
@@ -178,9 +180,9 @@
     // create reverse map from handle to id
   std::vector<int> ids( num_nodes );
   std::vector<int>::iterator id_iter = ids.begin();
-  std::vector<MBEntityHandle> handles( num_nodes );
-  std::vector<MBEntityHandle>::iterator h_iter = handles.begin();
-  for (std::map<long,MBEntityHandle>::iterator i = node_id_map.begin();
+  std::vector<EntityHandle> handles( num_nodes );
+  std::vector<EntityHandle>::iterator h_iter = handles.begin();
+  for (std::map<long,EntityHandle>::iterator i = node_id_map.begin();
         i != node_id_map.end(); ++i, ++id_iter, ++h_iter)
   {
     *id_iter = i->first;
@@ -209,7 +211,7 @@
     return MB_FILE_WRITE_ERROR;
   
     // lists of data accumulated for elements
-  std::vector<MBEntityHandle> connectivity;
+  std::vector<EntityHandle> connectivity;
   std::vector<int> mat_set_list, geom_set_list, part_set_list, id_list;
     // temporary, per-element data
   std::vector<int> int_data(5), tag_data(2);
@@ -299,7 +301,7 @@
       // Convert conectivity from IDs to handles
     for (unsigned j = 0; j < tmp_conn.size(); ++j)
     {
-      std::map<long,MBEntityHandle>::iterator k = node_id_map.find( tmp_conn[j] );
+      std::map<long,EntityHandle>::iterator k = node_id_map.find( tmp_conn[j] );
       if (k == node_id_map.end()) {
         readMeshIface->report_error( "Invalid node ID at line %d\n",
                                      tokens.line_number() );
@@ -332,15 +334,15 @@
 }
 
 //! Create an element sequence
-MBErrorCode ReadGmsh::create_elements( const GmshElemType& type,
+ErrorCode ReadGmsh::create_elements( const GmshElemType& type,
                                const std::vector<int>& elem_ids,
                                const std::vector<int>& matl_ids,
                                const std::vector<int>& geom_ids,
                                const std::vector<int>& prtn_ids,
-                               const std::vector<MBEntityHandle>& connectivity,
-                               const MBTag* file_id_tag )
+                               const std::vector<EntityHandle>& connectivity,
+                               const Tag* file_id_tag )
 {
-  MBErrorCode result;
+  ErrorCode result;
   
     // Make sure input is consistent
   const unsigned long num_elem = elem_ids.size();
@@ -352,8 +354,8 @@
     return MB_FAILURE;
   
     // Create the element sequence
-  MBEntityHandle handle = 0;
-  MBEntityHandle* conn_array;
+  EntityHandle handle = 0;
+  EntityHandle* conn_array;
   result = readMeshIface->get_element_array( num_elem, node_per_elem, type.mb_type,
                                              MB_START_ID, 
                                              handle, conn_array );
@@ -369,7 +371,7 @@
   }
   else
   {
-    memcpy( conn_array, &connectivity[0], connectivity.size() * sizeof(MBEntityHandle) );
+    memcpy( conn_array, &connectivity[0], connectivity.size() * sizeof(EntityHandle) );
   }
 
     // notify MOAB of the new elements
@@ -377,7 +379,7 @@
   if (MB_SUCCESS != result) return result;
 
     // Store element IDs
-  MBRange elements( handle, handle + num_elem - 1 );
+  Range elements( handle, handle + num_elem - 1 );
   result = mdbImpl->tag_set_data( globalId, elements, &elem_ids[0] );
   if (MB_SUCCESS != result)
     return result;
@@ -404,12 +406,12 @@
 }
 
 //! Add elements to sets as dictated by grouping ID in file.
-MBErrorCode ReadGmsh::create_sets( MBEntityType type,
-                                   const MBRange& elements,
+ErrorCode ReadGmsh::create_sets( EntityType type,
+                                   const Range& elements,
                                    const std::vector<int>& set_ids,
                                    int set_type )
 { 
-  MBErrorCode result;
+  ErrorCode result;
   
     // Get a unque list of set IDs
   std::set<int> ids;
@@ -423,7 +425,7 @@
 
     // Get/create tag handles
   int num_tags;
-  MBTag tag_handles[2];
+  Tag tag_handles[2];
   int tag_val;
   const void* tag_values[2] = { &tag_val, NULL };
   
@@ -474,9 +476,9 @@
       continue;
     
       // Get all entities with the current set ID
-    MBRange entities, sets;
+    Range entities, sets;
     std::vector<int>::const_iterator j = set_ids.begin();
-    for (MBRange::iterator k = elements.begin(); k != elements.end(); ++j, ++k)
+    for (Range::iterator k = elements.begin(); k != elements.end(); ++j, ++k)
       if (*i == *j)
         entities.insert( *k );
   
@@ -493,7 +495,7 @@
       sets = intersect( sets,  geomSets );
     
       // Get set handle
-    MBEntityHandle set;
+    EntityHandle set;
       // If no sets with ID, create one
     if (sets.empty())
     {
@@ -548,7 +550,7 @@
 //! NOT IMPLEMENTED
 //! Reconstruct parent-child relations for geometry sets from
 //! mesh connectivity.  
-MBErrorCode ReadGmsh::create_geometric_topology()
+ErrorCode ReadGmsh::create_geometric_topology()
 {
   if (geomSets.empty())
     return MB_SUCCESS;
@@ -557,3 +559,5 @@
   geomSets.clear();
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadGmsh.hpp
===================================================================
--- MOAB/trunk/src/io/ReadGmsh.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadGmsh.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -23,30 +23,32 @@
 #ifndef READ_GMSH_HPP
 #define READ_GMSH_HPP
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/Range.hpp"
 
-class MBReadUtilIface;
+namespace moab {
+
+class ReadUtilIface;
 struct GmshElemType;
 
 // Base class for binary and ASCII readers
-class ReadGmsh : public MBReaderIface
+class ReadGmsh : public ReaderIface
 {
    
 public:
 
     //! factory method 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -54,37 +56,38 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadGmsh(MBInterface* impl = NULL);
+  ReadGmsh(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadGmsh();
 
 private:
 
-  MBErrorCode create_elements( const GmshElemType& type,
+  ErrorCode create_elements( const GmshElemType& type,
                                const std::vector<int>& elem_ids,
                                const std::vector<int>& matl_ids,
                                const std::vector<int>& geom_ids,
                                const std::vector<int>& prtn_ids,
-                               const std::vector<MBEntityHandle>& connectivity,
-                               const MBTag* file_id_tag );
+                               const std::vector<EntityHandle>& connectivity,
+                               const Tag* file_id_tag );
 
-  MBErrorCode create_sets( MBEntityType element_type,
-                           const MBRange& elements,
+  ErrorCode create_sets( EntityType element_type,
+                           const Range& elements,
                            const std::vector<int>& set_ids,
                            int set_type );
   
-  MBErrorCode create_geometric_topology();
+  ErrorCode create_geometric_topology();
   
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
   
-  MBTag globalId;
-  MBRange geomSets;
+  Tag globalId;
+  Range geomSets;
 };
 
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/io/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/src/io/ReadHDF5.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadHDF5.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -27,19 +27,19 @@
 /* include our MPI header before any HDF5 because otherwise
    it will get included indirectly by HDF5 */
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif 
 #include <H5Tpublic.h>
 #include <H5Ppublic.h>
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/MBTagConventions.hpp"
 #include "ReadHDF5.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 #include "FileOptions.hpp"
 #ifdef HDF5_PARALLEL
 #  include "ReadParallel.hpp"
-#  include "MBParallelComm.hpp"
+#  include "moab/ParallelComm.hpp"
 #  include <H5FDmpi.h>
 #  include <H5FDmpio.h>
 #endif
@@ -50,6 +50,8 @@
 #include <limits>
 #include <functional>
 
+namespace moab {
+
 #undef DEBUG
 
 #ifdef DEBUG
@@ -69,34 +71,34 @@
 
 // This function doesn't do anything useful.  It's just a nice
 // place to set a break point to determine why the reader fails.
-static inline MBErrorCode error( MBErrorCode rval )
+static inline ErrorCode error( ErrorCode rval )
   { return rval; }
 
-static void copy_sorted_file_ids( const MBEntityHandle* sorted_ids, 
+static void copy_sorted_file_ids( const EntityHandle* sorted_ids, 
                                   long num_ids,
-                                  MBRange& results )
+                                  Range& results )
 {
-  MBRange::iterator hint = results.begin();
+  Range::iterator hint = results.begin();
   long i = 0;
   while (i < num_ids) {
-    MBEntityHandle start = sorted_ids[i];
+    EntityHandle start = sorted_ids[i];
     for (++i; i < num_ids && sorted_ids[i] == 1+sorted_ids[i-1]; ++i);
     hint = results.insert( hint, start, sorted_ids[i-1] );
   }
 }
 
-static void intersect( const mhdf_EntDesc& group, const MBRange& range, MBRange& result )
+static void intersect( const mhdf_EntDesc& group, const Range& range, Range& result )
 {
-  MBRange::const_iterator s, e;
-  s = MBRange::lower_bound( range.begin(), range.end(), group.start_id );
-  e = MBRange::lower_bound( s, range.end(), group.start_id + group.count );
+  Range::const_iterator s, e;
+  s = Range::lower_bound( range.begin(), range.end(), group.start_id );
+  e = Range::lower_bound( s, range.end(), group.start_id + group.count );
   result.merge( s, e );
 }
 
-MBReaderIface* ReadHDF5::factory( MBInterface* iface )
+ReaderIface* ReadHDF5::factory( Interface* iface )
   { return new ReadHDF5( iface ); }
 
-ReadHDF5::ReadHDF5( MBInterface* iface )
+ReadHDF5::ReadHDF5( Interface* iface )
   : bufferSize( READ_HDF5_BUFFER_SIZE ),
     dataBuffer( 0 ),
     iFace( iface ), 
@@ -109,9 +111,9 @@
 {
 }
 
-MBErrorCode ReadHDF5::init()
+ErrorCode ReadHDF5::init()
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
   if (readUtil) 
     return MB_SUCCESS;
@@ -123,20 +125,20 @@
   if (handleType < 0)
     return error(MB_FAILURE);
   
-  if (H5Tset_size( handleType, sizeof(MBEntityHandle)) < 0)
+  if (H5Tset_size( handleType, sizeof(EntityHandle)) < 0)
   {
     H5Tclose( handleType );
     return error(MB_FAILURE);
   }
   
   void* ptr = 0;
-  rval = iFace->query_interface( "MBReadUtilIface", &ptr );
+  rval = iFace->query_interface( "ReadUtilIface", &ptr );
   if (MB_SUCCESS != rval)
   {
     H5Tclose( handleType );
     return error(rval);
   }
-  readUtil = reinterpret_cast<MBReadUtilIface*>(ptr);
+  readUtil = reinterpret_cast<ReadUtilIface*>(ptr);
   
   idMap.clear();
   fileInfo = 0;
@@ -150,14 +152,14 @@
   if (!readUtil) // init() failed.
     return;
 
-  iFace->release_interface( "MBReadUtilIface", readUtil );
+  iFace->release_interface( "ReadUtilIface", readUtil );
   H5Tclose( handleType );
 }
 
-MBErrorCode ReadHDF5::set_up_read( const char* filename,
+ErrorCode ReadHDF5::set_up_read( const char* filename,
                                    const FileOptions& opts )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   indepIO = collIO = H5P_DEFAULT;
 
@@ -183,7 +185,7 @@
   if (MB_SUCCESS != rval) {
     bufferSize = READ_HDF5_BUFFER_SIZE;
   }
-  else if (bufferSize < (int)std::max( sizeof(MBEntityHandle), sizeof(void*) )) {
+  else if (bufferSize < (int)std::max( sizeof(EntityHandle), sizeof(void*) )) {
     return error(MB_INVALID_SIZE);
   }
   
@@ -203,9 +205,9 @@
       readUtil->report_error("Invalid value for PARALLEL_COMM option");
       return rval;
     }
-    MBParallelComm* myPcomm = MBParallelComm::get_pcomm(iFace, pcomm_no);
+    ParallelComm* myPcomm = ParallelComm::get_pcomm(iFace, pcomm_no);
     if (0 == myPcomm) {
-      myPcomm = new MBParallelComm(iFace);
+      myPcomm = new ParallelComm(iFace);
     }
     const int rank = myPcomm->proc_config().proc_rank();
 
@@ -299,7 +301,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::clean_up_read( const FileOptions& )
+ErrorCode ReadHDF5::clean_up_read( const FileOptions& )
 {
   free( dataBuffer );
   free( fileInfo );
@@ -316,14 +318,14 @@
     return MB_FAILURE;
 }
 
-MBErrorCode ReadHDF5::load_file( const char* filename, 
-                                 const MBEntityHandle* file_set, 
+ErrorCode ReadHDF5::load_file( const char* filename, 
+                                 const EntityHandle* file_set, 
                                  const FileOptions& opts,
-                                 const MBReaderIface::IDTag* subset_list,
+                                 const ReaderIface::IDTag* subset_list,
                                  int subset_list_length,
-                                 const MBTag* file_id_tag )
+                                 const Tag* file_id_tag )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
  
   rval = set_up_read( filename, opts );
   if (MB_SUCCESS != rval)
@@ -340,7 +342,7 @@
   if (MB_SUCCESS == rval && 0 != file_set)
     rval = read_qa( *file_set );
     
-  MBErrorCode rval2 = clean_up_read( opts );
+  ErrorCode rval2 = clean_up_read( opts );
   if (rval == MB_SUCCESS && rval2 != MB_SUCCESS)
     rval = rval2;
   
@@ -349,16 +351,16 @@
   
 
 
-MBErrorCode ReadHDF5::load_file_impl( const FileOptions& opts )
+ErrorCode ReadHDF5::load_file_impl( const FileOptions& opts )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   std::string tagname;
   int i;
 
 DEBUGOUT("Reading Nodes.\n");
   
-  MBRange ids;
+  Range ids;
   if (fileInfo->nodes.count) {
     ids.insert( fileInfo->nodes.start_id,
                 fileInfo->nodes.start_id + fileInfo->nodes.count - 1);
@@ -432,7 +434,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::find_int_tag( const char* name, int& index )
+ErrorCode ReadHDF5::find_int_tag( const char* name, int& index )
 {
   for (index = 0; index < fileInfo->num_tag_desc; ++index) 
     if (!strcmp( name, fileInfo->tags[index].name))
@@ -452,11 +454,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::get_subset_ids( const MBReaderIface::IDTag* subset_list,
+ErrorCode ReadHDF5::get_subset_ids( const ReaderIface::IDTag* subset_list,
                                       int subset_list_length,
-                                      MBRange& file_ids )
+                                      Range& file_ids )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   for (int i = 0; i < subset_list_length; ++i) {  
     
@@ -465,7 +467,7 @@
     if (MB_SUCCESS != rval)
       return error(rval);
   
-    MBRange tmp_file_ids;
+    Range tmp_file_ids;
     if (!subset_list[i].num_tag_values) {
       rval = get_tagged_entities( tag_index, tmp_file_ids );
     }
@@ -488,10 +490,10 @@
         return error(MB_TYPE_OUT_OF_RANGE);
       }
       
-      MBRange::iterator s = tmp_file_ids.begin();
+      Range::iterator s = tmp_file_ids.begin();
       size_t num_per_proc = tmp_file_ids.size() / subset_list[i].num_parts;
       size_t num_extra = tmp_file_ids.size() % subset_list[i].num_parts;
-      MBRange::iterator e;
+      Range::iterator e;
       if (subset_list[i].part_number < (long)num_extra) {
         s += (num_per_proc+1) * subset_list[i].part_number;
         e = s;
@@ -515,7 +517,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::load_file_partial( const MBReaderIface::IDTag* subset_list,
+ErrorCode ReadHDF5::load_file_partial( const ReaderIface::IDTag* subset_list,
                                          int subset_list_length,
                                          const FileOptions& opts )
 {
@@ -523,8 +525,8 @@
   
 DEBUGOUT( "RETREIVING TAGGED ENTITIES" );
     
-  MBRange file_ids;
-  MBErrorCode rval = get_subset_ids( subset_list, subset_list_length, file_ids );
+  Range file_ids;
+  ErrorCode rval = get_subset_ids( subset_list, subset_list_length, file_ids );
   if (MB_SUCCESS != rval)
     return error(rval);
   
@@ -551,7 +553,7 @@
     // If we want the contents of contained/child sets, 
     // search for them now (before gathering the non-set contents
     // of the sets.)
-  MBRange sets;
+  Range sets;
   intersect( fileInfo->sets, file_ids, sets );
   if (content_mode == 2 || child_mode == 2) {
     rval = read_set_ids_recursive( sets, content_mode == 2, child_mode == 2 );
@@ -569,11 +571,11 @@
   
     // if input contained any polyhedra, need to get faces
   for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
-    MBEntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
+    EntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
     if (type != MBPOLYHEDRON)
       continue;
     
-    MBRange polyhedra;
+    Range polyhedra;
     intersect( fileInfo->elems[i].desc, file_ids, polyhedra );
     rval = read_elems( i, polyhedra, file_ids );
     if (MB_SUCCESS != rval)
@@ -581,10 +583,10 @@
   }
   
     // get node file ids for all elements
-  MBRange nodes;
+  Range nodes;
   intersect( fileInfo->nodes, file_ids, nodes );
   for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
-    MBEntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
+    EntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
     if (type <= MBVERTEX || type >= MBENTITYSET) {
       assert( false ); // for debug code die for unknown element tyoes
       continue; // for release code, skip unknown element types
@@ -592,7 +594,7 @@
     if (MBPOLYHEDRON == type)
       continue;
     
-    MBRange subset;
+    Range subset;
     intersect( fileInfo->elems[i].desc, file_ids, subset );
     rval = read_elems( i, subset, nodes );
     if (MB_SUCCESS != rval)
@@ -616,7 +618,7 @@
   if (MB_ENTITY_NOT_FOUND == rval) {
       // Chose default based on whether or not any elements have been
       // specified.
-    MBRange tmp;
+    Range tmp;
     intersect( fileInfo->nodes, file_ids, tmp );
       // If only nodes were specified, then default to "NODES", otherwise
       // default to "SIDES".
@@ -634,9 +636,9 @@
     case 0: // ELEMENTS=EXPLICIT : read only specified element IDS
     for (int dim = 1; dim <= 3; ++dim) {
       for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
-        MBEntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
+        EntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
         if (MBCN::Dimension(type) == dim) {
-          MBRange subset;
+          Range subset;
           intersect( fileInfo->elems[i].desc, file_ids, subset );
           rval = read_elems( fileInfo->elems[i],  subset );
           if (MB_SUCCESS != rval)
@@ -649,7 +651,7 @@
     case 1: // ELEMENTS=NODES : read all elements for which all nodes have been read
     for (int dim = 1; dim <= 3; ++dim) {
       for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
-        MBEntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
+        EntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
         if (MBCN::Dimension(type) == dim) {
           rval = read_node_adj_elems( fileInfo->elems[i] );
           if (MB_SUCCESS != rval)
@@ -684,7 +686,7 @@
     return error(rval);
     // Now actually read all set data and instantiate sets in MOAB.
     // Get any contained sets out of file_ids.
-  MBEntityHandle first_set = fileInfo->sets.start_id;
+  EntityHandle first_set = fileInfo->sets.start_id;
   sets.merge( file_ids.lower_bound( first_set ),
               file_ids.lower_bound( first_set + fileInfo->sets.count ) );
   rval = read_sets( sets );
@@ -720,13 +722,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::search_tag_values( int tag_index,
+ErrorCode ReadHDF5::search_tag_values( int tag_index,
                                          const std::vector<int>& sorted_values,
-                                         MBRange& file_ids )
+                                         Range& file_ids )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  std::vector<MBEntityHandle>::iterator iter;
+  std::vector<EntityHandle>::iterator iter;
   const mhdf_TagDesc& tag = fileInfo->tags[tag_index];
   long size;
   long start_id;
@@ -735,9 +737,9 @@
     
   hid_t table;
   const char* name;
-  std::vector<MBEntityHandle> indices;
+  std::vector<EntityHandle> indices;
     // These are probably in order of dimension, so iterate
-    // in reverse order to make MBRange insertions more efficient.
+    // in reverse order to make Range insertions more efficient.
   std::vector<int> grp_indices( tag.dense_elem_indices, tag.dense_elem_indices+tag.num_dense_indices );
   for (std::vector<int>::reverse_iterator i = grp_indices.rbegin(); i != grp_indices.rend(); ++i)
   {
@@ -764,8 +766,8 @@
     if (MB_SUCCESS != rval || is_error(status))
       return error(MB_FAILURE);
       // Convert from table indices to file IDs and add to result list
-    std::sort( indices.begin(), indices.end(), std::greater<MBEntityHandle>() );
-    std::transform( indices.begin(), indices.end(), mb_range_inserter(file_ids),
+    std::sort( indices.begin(), indices.end(), std::greater<EntityHandle>() );
+    std::transform( indices.begin(), indices.end(), range_inserter(file_ids),
                     std::bind1st( std::plus<long>(), start_id ) );
     indices.clear();
   }
@@ -788,11 +790,11 @@
   }
     // convert to ranges
   std::sort( indices.begin(), indices.end() );
-  std::vector<MBEntityHandle> ranges;
+  std::vector<EntityHandle> ranges;
   iter = indices.begin();
   while (iter != indices.end()) {
     ranges.push_back( *iter );
-    MBEntityHandle last = *iter;
+    EntityHandle last = *iter;
     for (++iter; iter != indices.end() && (last + 1) == *iter; ++iter, ++last);
     ranges.push_back( last );
   }
@@ -820,12 +822,12 @@
   return MB_SUCCESS;  
 }
 
-MBErrorCode ReadHDF5::get_tagged_entities( int tag_index, MBRange& file_ids )
+ErrorCode ReadHDF5::get_tagged_entities( int tag_index, Range& file_ids )
 {
   const mhdf_TagDesc& tag = fileInfo->tags[tag_index];
    
     // do dense data
-  MBRange::iterator hint = file_ids.begin();
+  Range::iterator hint = file_ids.begin();
   for (int i = 0; i < tag.num_dense_indices; ++i)
   {
     int idx = tag.dense_elem_indices[i];
@@ -840,7 +842,7 @@
       ents = &(fileInfo->elems[idx].desc);
     }
     
-    MBEntityHandle h = (MBEntityHandle)ents->start_id;
+    EntityHandle h = (EntityHandle)ents->start_id;
     hint = file_ids.insert( hint, h, h + ents->count );
   }
   
@@ -862,8 +864,8 @@
   }
   
   hint = file_ids.begin();
-  MBEntityHandle* buffer = reinterpret_cast<MBEntityHandle*>(dataBuffer);
-  const long buffer_size = bufferSize / sizeof(MBEntityHandle);
+  EntityHandle* buffer = reinterpret_cast<EntityHandle*>(dataBuffer);
+  const long buffer_size = bufferSize / sizeof(EntityHandle);
   long remaining = size, offset = 0;
   while (remaining) {
     long count = std::min( buffer_size, remaining );
@@ -889,10 +891,10 @@
   return MB_SUCCESS;  
 }
 
-MBErrorCode ReadHDF5::search_tag_values( hid_t tag_table, 
+ErrorCode ReadHDF5::search_tag_values( hid_t tag_table, 
                                          unsigned long table_size,
                                          const std::vector<int>& sorted_values,
-                                         std::vector<MBEntityHandle>& value_indices )
+                                         std::vector<EntityHandle>& value_indices )
 {
   mhdf_Status status;
   size_t chunk_size = bufferSize / sizeof(unsigned);
@@ -917,12 +919,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_nodes( const MBRange& node_file_ids )
+ErrorCode ReadHDF5::read_nodes( const Range& node_file_ids )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   const int dim = fileInfo->nodes.vals_per_ent;
-  MBRange range;
+  Range range;
   
   if (node_file_ids.empty())
     return MB_SUCCESS;
@@ -944,7 +946,7 @@
     return error(MB_FAILURE);
 
   
-  MBEntityHandle handle;
+  EntityHandle handle;
   std::vector<double*> arrays(dim);
   rval = readUtil->get_node_arrays( dim, (int)node_file_ids.size(), 0, handle, arrays );
   if (MB_SUCCESS != rval)
@@ -954,7 +956,7 @@
   }
   
     // read blocks of coordinates
-  MBRange::const_pair_iterator p;
+  Range::const_pair_iterator p;
   for (p = node_file_ids.const_pair_begin(); p != node_file_ids.const_pair_end(); ++p)
   {
     long count = p->second - p->first + 1;
@@ -988,15 +990,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_elems( int i )
+ErrorCode ReadHDF5::read_elems( int i )
 {
-  MBRange ids;
+  Range ids;
   ids.insert( fileInfo->elems[i].desc.start_id,
               fileInfo->elems[i].desc.start_id + fileInfo->elems[i].desc.count - 1);
   return read_elems( i, ids );
 }
 
-MBErrorCode ReadHDF5::read_elems( int i, const MBRange& file_ids )
+ErrorCode ReadHDF5::read_elems( int i, const Range& file_ids )
 {
   if (fileInfo->elems[i].desc.vals_per_ent < 0)
     return read_poly( fileInfo->elems[i], file_ids );
@@ -1004,12 +1006,12 @@
     return read_elems( fileInfo->elems[i], file_ids );
 }
 
-MBErrorCode ReadHDF5::read_elems( const mhdf_ElemDesc& elems, const MBRange& file_ids )
+ErrorCode ReadHDF5::read_elems( const mhdf_ElemDesc& elems, const Range& file_ids )
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   mhdf_Status status;
   
-  MBEntityType type = MBCN::EntityTypeFromName( elems.type );
+  EntityType type = MBCN::EntityTypeFromName( elems.type );
   if (type == MBMAXTYPE)
   {
     readUtil->report_error( "Unknown element type: \"%s\".\n", elems.type );
@@ -1022,12 +1024,12 @@
   if (is_error(status))
     return error(MB_FAILURE);
 
-  MBRange::const_pair_iterator p;
+  Range::const_pair_iterator p;
   for (p = file_ids.const_pair_begin(); p != file_ids.const_pair_end(); ++p) {
     const long count = p->second - p->first + 1;
     
-    MBEntityHandle handle;
-    MBEntityHandle* array;
+    EntityHandle handle;
+    EntityHandle* array;
     rval = readUtil->get_element_array( (int)count,
                                          nodes_per_elem,
                                          type,
@@ -1060,10 +1062,10 @@
   return rval;
 }
 
-MBErrorCode ReadHDF5::read_node_adj_elems( const mhdf_ElemDesc& group )
+ErrorCode ReadHDF5::read_node_adj_elems( const mhdf_ElemDesc& group )
 {
   mhdf_Status status;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   hid_t table = mhdf_openConnectivitySimple( filePtr, group.handle, &status );
   if (is_error(status))
@@ -1077,17 +1079,17 @@
   return rval;
 }
 
-MBErrorCode ReadHDF5::read_node_adj_elems( const mhdf_ElemDesc& group, 
+ErrorCode ReadHDF5::read_node_adj_elems( const mhdf_ElemDesc& group, 
                                            hid_t table_handle )
 {
   mhdf_Status status;
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // copy data to local variables (makes other code clearer)
   const int node_per_elem = group.desc.vals_per_ent;
   long start_id = group.desc.start_id;
   long remaining = group.desc.count;
-  const MBEntityType type = MBCN::EntityTypeFromName( group.type );
+  const EntityType type = MBCN::EntityTypeFromName( group.type );
   
     // figure out how many elements we can read in each pass
   long* const buffer = reinterpret_cast<long*>( dataBuffer );
@@ -1126,8 +1128,8 @@
     }
     
       // create elements
-    MBEntityHandle handle;
-    MBEntityHandle* array;
+    EntityHandle handle;
+    EntityHandle* array;
     rval = readUtil->get_element_array( (int)num_elem,
                                          node_per_elem,
                                          type,
@@ -1139,8 +1141,8 @@
     
       // copy all non-zero connectivity values
     iter = buffer;
-    MBEntityHandle* iter2 = array;
-    MBEntityHandle h = handle;
+    EntityHandle* iter2 = array;
+    EntityHandle h = handle;
     for (long i = 0; i < count; ++i) {
       if (!*iter) {
         iter += node_per_elem;
@@ -1151,7 +1153,7 @@
         
       long* const end = iter + node_per_elem;
       for (; iter != end; ++iter, ++iter2)
-        *iter2 = (MBEntityHandle)*iter;
+        *iter2 = (EntityHandle)*iter;
     }
     assert( iter2 - array == num_elem * node_per_elem );
     start_id += count;
@@ -1161,10 +1163,10 @@
 }
   
 
-MBErrorCode ReadHDF5::read_elems( int i, const MBRange& elems_in, MBRange& nodes )
+ErrorCode ReadHDF5::read_elems( int i, const Range& elems_in, Range& nodes )
 {
-  MBEntityHandle* const buffer = reinterpret_cast<MBEntityHandle*>(dataBuffer);
-  const size_t buffer_size = bufferSize / sizeof(MBEntityHandle);
+  EntityHandle* const buffer = reinterpret_cast<EntityHandle*>(dataBuffer);
+  const size_t buffer_size = bufferSize / sizeof(EntityHandle);
   int node_per_elem = fileInfo->elems[i].desc.vals_per_ent;
   
   if (elems_in.empty())
@@ -1182,9 +1184,9 @@
   if (is_error(status))
     return error(MB_FAILURE);
     
-  MBRange elements( elems_in );
+  Range elements( elems_in );
   while (!elements.empty()) {
-    MBEntityHandle file_id = elements.front();
+    EntityHandle file_id = elements.front();
     long count = elements.const_pair_begin()->second - file_id + 1;
     long offset = file_id - fileInfo->elems[i].desc.start_id;
     if (count*node_per_elem > (long)buffer_size)
@@ -1208,32 +1210,32 @@
   return is_error(status) ? error(MB_FAILURE) : MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_poly( const mhdf_ElemDesc& elems, const MBRange& file_ids )
+ErrorCode ReadHDF5::read_poly( const mhdf_ElemDesc& elems, const Range& file_ids )
 {
   class PolyReader : public ContentReader {
     private:
-      const MBEntityType type;
+      const EntityType type;
       hid_t indexHandle, connHandle, handleType;
-      MBInterface *const mb;
+      Interface *const mb;
       IDMap& idMap;
     public:
-    PolyReader( MBEntityType elem_type, hid_t idx, hid_t conn, 
-                hid_t handle_type, MBInterface* iface, IDMap& id_map )
+    PolyReader( EntityType elem_type, hid_t idx, hid_t conn, 
+                hid_t handle_type, Interface* iface, IDMap& id_map )
                : type(elem_type), indexHandle(idx), connHandle(conn), 
                  handleType(handle_type), mb(iface), idMap(id_map) 
                {}
     void read_indices( long offset, long count, long* buffer, mhdf_Status& status ) 
       { mhdf_readPolyConnIndices( indexHandle, offset, count, H5T_NATIVE_LONG, buffer, &status ); }
-    void read_contents( long offset, long count, MBEntityHandle* buffer, mhdf_Status& status )
+    void read_contents( long offset, long count, EntityHandle* buffer, mhdf_Status& status )
       { mhdf_readPolyConnIDs( connHandle, offset, count, handleType, buffer, &status ); }
-    MBErrorCode store_data( MBEntityHandle, long file_id, MBEntityHandle* conn, long len, bool )
+    ErrorCode store_data( EntityHandle, long file_id, EntityHandle* conn, long len, bool )
     {
       size_t valid;
       convert_id_to_handle( conn, len, valid, idMap );
       if (valid != (size_t)len)
         return error(MB_ENTITY_NOT_FOUND);
-      MBEntityHandle handle;
-      MBErrorCode rval = mb->create_element( type, conn, len, handle );
+      EntityHandle handle;
+      ErrorCode rval = mb->create_element( type, conn, len, handle );
       if (MB_SUCCESS != rval)
         return error(rval);
       if (!idMap.insert( file_id, handle, 1 ).second) 
@@ -1242,7 +1244,7 @@
     }
   };
   
-  MBEntityType type = MBCN::EntityTypeFromName( elems.type );
+  EntityType type = MBCN::EntityTypeFromName( elems.type );
   if (type == MBMAXTYPE)
   {
     readUtil->report_error( "Unknown element type: \"%s\".\n", elems.type );
@@ -1258,8 +1260,8 @@
     return error(MB_FAILURE);
 
   PolyReader tool( type, handles[0], handles[1], handleType, iFace, idMap );
-  MBRange empty;
-  MBErrorCode rval = read_contents( tool, file_ids, first_id, 0, num_poly, num_conn, empty );
+  Range empty;
+  ErrorCode rval = read_contents( tool, file_ids, first_id, 0, num_poly, num_conn, empty );
   mhdf_closeData( filePtr, handles[0], &status );
   if (MB_SUCCESS == rval && is_error(status))
     rval = error(MB_FAILURE);
@@ -1270,9 +1272,9 @@
   return rval;
 }
 /*
-MBErrorCode ReadHDF5::read_poly( const char* elem_group )
+ErrorCode ReadHDF5::read_poly( const char* elem_group )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   char name[64];
    
@@ -1282,7 +1284,7 @@
     readUtil->report_error( mhdf_message( &status ) );
     return error(MB_FAILURE);
   }
-  MBEntityType type = MBCN::EntityTypeFromName( name );
+  EntityType type = MBCN::EntityTypeFromName( name );
 
   long count, first_id, data_len;
   hid_t handles[2];
@@ -1298,10 +1300,10 @@
   empty_set.type = MBCN::EntityTypeFromName( name );
   empty_set.type2 = elem_group;
   
-  MBEntityHandle h;
+  EntityHandle h;
   bool first = true;
   long connend = -1;
-  std::vector<MBEntityHandle> connectivity; 
+  std::vector<EntityHandle> connectivity; 
   for (long i = 0; i < count; ++i) {
     long prevend = connend;
     mhdf_readPolyConnIndicesWithOpt( handles[0], i, 1, H5T_NATIVE_LONG, &connend, ioProp, &status );
@@ -1347,7 +1349,7 @@
     elemList.back().range.insert( h );
   }
  
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   mhdf_closeData( filePtr, handles[0], &status );
   if (mhdf_isError( &status )) {
     readUtil->report_error( mhdf_message( &status ));
@@ -1362,10 +1364,10 @@
 }
 */
 
-MBErrorCode ReadHDF5::read_elements_and_sides( const MBRange& file_ids )
+ErrorCode ReadHDF5::read_elements_and_sides( const Range& file_ids )
 {
-  MBErrorCode rval;
-  MBEntityType type;
+  ErrorCode rval;
+  EntityType type;
     
     // determine largest element dimension
   int max_dim = 0;
@@ -1373,32 +1375,32 @@
     type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
     int dim = MBCN::Dimension(type);
     if (dim > max_dim) {
-      MBEntityHandle start = (MBEntityHandle)fileInfo->elems[i].desc.start_id;
-      MBRange::iterator it = file_ids.lower_bound( start );
+      EntityHandle start = (EntityHandle)fileInfo->elems[i].desc.start_id;
+      Range::iterator it = file_ids.lower_bound( start );
       if (it != file_ids.end() && (long)(*it - start ) < fileInfo->elems[i].desc.count)
         max_dim = dim;
     }
   }
   
-    // Get MBRange of element IDs only
-  MBRange elem_ids( file_ids );
-  MBRange::iterator s, e;
+    // Get Range of element IDs only
+  Range elem_ids( file_ids );
+  Range::iterator s, e;
   if (fileInfo->nodes.count) {
-    MBEntityHandle first = (MBEntityHandle)fileInfo->nodes.start_id;
+    EntityHandle first = (EntityHandle)fileInfo->nodes.start_id;
     s = elem_ids.lower_bound( first );
-    e = MBRange::lower_bound( s, elem_ids.end(), first + fileInfo->nodes.count );
+    e = Range::lower_bound( s, elem_ids.end(), first + fileInfo->nodes.count );
     elem_ids.erase( s, e );
   }
   if (fileInfo->sets.count) {
-    MBEntityHandle first = (MBEntityHandle)fileInfo->sets.start_id;
+    EntityHandle first = (EntityHandle)fileInfo->sets.start_id;
     s = elem_ids.lower_bound( first );
-    e = MBRange::lower_bound( s, elem_ids.end(), first + fileInfo->sets.count );
+    e = Range::lower_bound( s, elem_ids.end(), first + fileInfo->sets.count );
     elem_ids.erase( s, e );
   }
   
     // read all node-adjacent elements of smaller dimensions
   for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
-    MBEntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
+    EntityType type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
     if (MBCN::Dimension(type) < max_dim) {
       rval = read_node_adj_elems( fileInfo->elems[i] );
       if (MB_SUCCESS != rval)
@@ -1413,7 +1415,7 @@
   for (int i = 0; i < fileInfo->num_elem_desc; ++i) {
     type = MBCN::EntityTypeFromName( fileInfo->elems[i].type );
     if (MBCN::Dimension(type) == max_dim) {
-      MBRange subset;
+      Range subset;
       intersect( fileInfo->elems[i].desc, elem_ids, subset );
       if (!subset.empty()) {
         subtract( elem_ids,  subset );
@@ -1427,13 +1429,13 @@
     // delete anything we read in that we should not have
     // (e.g. an edge spanning two disjoint blocks of elements)
     
-    // get MBRange of all explicitly specified elements, grouped by dimension
-  MBRange explicit_elems[4];
-  MBRange::iterator hints[4] = { explicit_elems[0].begin(),
+    // get Range of all explicitly specified elements, grouped by dimension
+  Range explicit_elems[4];
+  Range::iterator hints[4] = { explicit_elems[0].begin(),
                                  explicit_elems[1].begin(),
                                  explicit_elems[2].begin(),
                                  explicit_elems[3].begin() };
-  RangeMap<long, MBEntityHandle>::iterator rit;
+  RangeMap<long, EntityHandle>::iterator rit;
   while (!elem_ids.empty()) {
     long start = elem_ids.front();
     long count = elem_ids.const_pair_begin()->second - start + 1;
@@ -1443,7 +1445,7 @@
     long avail = rit->count - offset;
     if (avail > count)
       count = avail;
-    MBEntityHandle start_h = rit->value + offset;
+    EntityHandle start_h = rit->value + offset;
     int d = MBCN::Dimension( TYPE_FROM_HANDLE( start_h ) );
     if (MBCN::Dimension( TYPE_FROM_HANDLE( start_h + count - 1 ) ) != d) 
       count = start - LAST_HANDLE( TYPE_FROM_HANDLE(start_h) ) + 1;
@@ -1452,10 +1454,10 @@
     hints[d] = explicit_elems[d].insert( hints[d], rit->value + offset, rit->value + offset + count - 1 );
   }
   
-    // get MBRange of all read elements, and remove any that were explicity specified
+    // get Range of all read elements, and remove any that were explicity specified
     // get handles for everything we've read
-  MBRange all_elems;
-  MBRange::iterator hint = all_elems.begin();
+  Range all_elems;
+  Range::iterator hint = all_elems.begin();
   for (rit = idMap.begin(); rit != idMap.end(); ++rit)
     hint = all_elems.insert( hint, rit->value, rit->value + rit->count - 1 );
     // remove any vertex handles
@@ -1470,22 +1472,22 @@
  
     // remove any elements that are adjacent to some explicity specified element.
   if (max_dim > 1 && !explicit_elems[2].empty()) {
-    MBRange adj;
-    rval = iFace->get_adjacencies( explicit_elems[2], 1, false, adj, MBInterface::UNION );
+    Range adj;
+    rval = iFace->get_adjacencies( explicit_elems[2], 1, false, adj, Interface::UNION );
     if (MB_SUCCESS != rval)
       return error(rval);
     if (!adj.empty())
       all_elems = subtract( all_elems,  adj );
   }
   if (max_dim == 3) {
-    MBRange adj;
-    rval = iFace->get_adjacencies( explicit_elems[3], 1, false, adj, MBInterface::UNION );
+    Range adj;
+    rval = iFace->get_adjacencies( explicit_elems[3], 1, false, adj, Interface::UNION );
     if (MB_SUCCESS != rval)
       return error(rval);
     if (!adj.empty())
       all_elems = subtract( all_elems,  adj );
     adj.clear();
-    rval = iFace->get_adjacencies( explicit_elems[3], 2, false, adj, MBInterface::UNION );
+    rval = iFace->get_adjacencies( explicit_elems[3], 2, false, adj, Interface::UNION );
     if (MB_SUCCESS != rval)
       return error(rval);
     if (!adj.empty())
@@ -1499,16 +1501,16 @@
   
     // remove dead entities from ID map
   while (!all_elems.empty()) {
-    MBEntityHandle start = all_elems.front();
-    MBEntityID count = all_elems.const_pair_begin()->second - start + 1;
+    EntityHandle start = all_elems.front();
+    EntityID count = all_elems.const_pair_begin()->second - start + 1;
     for (rit = idMap.begin(); rit != idMap.end(); ++rit) 
       if (rit->value <= start && (long)(start - rit->value) < rit->count)
         break;
     if (rit == idMap.end())
       return error(MB_FAILURE);
   
-    MBEntityID offset = start - rit->value;
-    MBEntityID avail = rit->count - offset;
+    EntityID offset = start - rit->value;
+    EntityID avail = rit->count - offset;
     if (avail < count)
       count = avail;
     
@@ -1519,10 +1521,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_sets( const MBRange& file_ids )
+ErrorCode ReadHDF5::read_sets( const Range& file_ids )
 {
   mhdf_Status status;
-  MBErrorCode rval;
+  ErrorCode rval;
   if (fileInfo->sets.count == 0 || file_ids.empty()) {
     assert(file_ids.empty());
     return MB_SUCCESS;
@@ -1534,8 +1536,8 @@
 
 
     // create sets 
-  MBRange ranged_set_ids;
-  MBEntityHandle start_handle;
+  Range ranged_set_ids;
+  EntityHandle start_handle;
   rval = read_sets( file_ids, meta_handle, ranged_set_ids, start_handle );
   if (MB_SUCCESS != rval) {
     mhdf_closeData( filePtr, meta_handle, &status );
@@ -1604,7 +1606,7 @@
   return is_error(status) ? error(MB_FAILURE) : MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_set_ids_recursive( MBRange& sets_in_out,
+ErrorCode ReadHDF5::read_set_ids_recursive( Range& sets_in_out,
                                               bool contained_sets,
                                               bool child_sets )
 {
@@ -1651,8 +1653,8 @@
     }
   }
   
-  MBErrorCode rval = MB_SUCCESS;
-  MBRange children, new_children(sets_in_out);
+  ErrorCode rval = MB_SUCCESS;
+  Range children, new_children(sets_in_out);
   do {
     children.clear();
     if (child_sets) {
@@ -1686,9 +1688,9 @@
   return rval;
 }
 
-MBErrorCode ReadHDF5::find_sets_containing( MBRange& sets_out )
+ErrorCode ReadHDF5::find_sets_containing( Range& sets_out )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
 
   if (!fileInfo->have_set_contents)
@@ -1721,7 +1723,7 @@
 static bool set_map_intersect( unsigned short flags,
                                const long* contents,
                                int content_len,
-                               const RangeMap<long,MBEntityHandle>& id_map  )
+                               const RangeMap<long,EntityHandle>& id_map  )
 {
   if (flags & mhdf_SET_RANGE_BIT) {
     if (!content_len || id_map.empty())
@@ -1746,10 +1748,10 @@
   return false;
 }
 
-MBErrorCode ReadHDF5::find_sets_containing( hid_t meta_handle,
+ErrorCode ReadHDF5::find_sets_containing( hid_t meta_handle,
                                             hid_t contents_handle, 
                                             long contents_len,
-                                            MBRange& file_ids )
+                                            Range& file_ids )
 {
   const long avg_set_len = contents_len / fileInfo->sets.count;
   long sets_per_buffer = bufferSize / (sizeof(short) + sizeof(long) * (2+avg_set_len));
@@ -1765,7 +1767,7 @@
   assert(dataBuffer + bufferSize >= (char*)(content_buffer + content_len));
     // scan set table  
   mhdf_Status status;
-  MBRange::iterator hint = file_ids.begin();
+  Range::iterator hint = file_ids.begin();
   long remaining = fileInfo->sets.count;
   long offset = 0;
   long prev_idx = -1;
@@ -1840,17 +1842,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_child_ids( const MBRange& input_file_ids,
+ErrorCode ReadHDF5::read_child_ids( const Range& input_file_ids,
                                       hid_t meta_handle,
                                       hid_t child_handle,
-                                      MBRange& child_file_ids )
+                                      Range& child_file_ids )
 {
   mhdf_Status status;
   long* buffer = reinterpret_cast<long*>(dataBuffer);
   long buffer_size = bufferSize / sizeof(long);
   long first, range[2], count, remaining;
-  MBRange sets(input_file_ids);
-  MBRange::iterator hint;
+  Range sets(input_file_ids);
+  Range::iterator hint;
   while (!sets.empty()) {
     count = (long)sets.const_pair_begin()->second - sets.front() + 1;
     first = (long)sets.front() - fileInfo->sets.start_id;
@@ -1899,7 +1901,7 @@
       count = std::unique( buffer, buffer + count ) - buffer;
       hint = child_file_ids.begin();
       for (long i = 0; i < count; ++i) {
-        MBEntityHandle h = (MBEntityHandle)buffer[i];
+        EntityHandle h = (EntityHandle)buffer[i];
         hint = child_file_ids.insert( hint, h, h );
       }
     }
@@ -1908,10 +1910,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_contained_set_ids( const MBRange& input_file_ids,
+ErrorCode ReadHDF5::read_contained_set_ids( const Range& input_file_ids,
                                               hid_t meta_handle,
                                               hid_t content_handle,
-                                              MBRange& contained_set_file_ids )
+                                              Range& contained_set_file_ids )
 {
   mhdf_Status status;
   long buffer_size = bufferSize / (sizeof(long) + sizeof(short));
@@ -1921,8 +1923,8 @@
   unsigned short* flag_buffer = reinterpret_cast<unsigned short*>(content_buffer + buffer_size);
   long first, range[2], count, remaining, sets_offset;
 
-  MBRange sets(input_file_ids);
-  MBRange::iterator hint;
+  Range sets(input_file_ids);
+  Range::iterator hint;
   while (!sets.empty()) {
     count = (long)sets.const_pair_begin()->second - sets.front() + 1;
     first = (long)sets.front() - fileInfo->sets.start_id;
@@ -1984,8 +1986,8 @@
         if (ranged) {
           hint = contained_set_file_ids.begin();
           for (long i = 0; i < content_count; i += 2) {
-            MBEntityHandle s = (MBEntityHandle)content_buffer[i];
-            MBEntityHandle e = s + content_buffer[i+1];
+            EntityHandle s = (EntityHandle)content_buffer[i];
+            EntityHandle e = s + content_buffer[i+1];
             if ((long)s < fileInfo->sets.start_id)
               s = fileInfo->sets.start_id;
             if ((long)e > fileInfo->sets.start_id + fileInfo->sets.count)
@@ -2003,7 +2005,7 @@
           e = std::unique( s, e );
           hint = contained_set_file_ids.begin();
           for ( ; s != e; ++s) {
-            MBEntityHandle h = *s;
+            EntityHandle h = *s;
             hint = contained_set_file_ids.insert( hint, h, h );
           }
         }
@@ -2014,13 +2016,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_sets( const MBRange& file_ids,
+ErrorCode ReadHDF5::read_sets( const Range& file_ids,
                                  hid_t meta_handle, 
-                                 MBRange& ranged_file_ids,
-                                 MBEntityHandle& start_handle,
+                                 Range& ranged_file_ids,
+                                 EntityHandle& start_handle,
                                  bool create )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
 
   size_t count = file_ids.size();
@@ -2038,7 +2040,7 @@
   }
   
   unsigned* buff_iter = buffer;
-  MBRange::const_pair_iterator p;
+  Range::const_pair_iterator p;
   for (p = file_ids.const_pair_begin(); p != file_ids.const_pair_end(); ++p) {
     long offset = p->first - fileInfo->sets.start_id;
     long count = p->second - p->first + 1;
@@ -2051,8 +2053,8 @@
   }
   
   buff_iter = buffer;
-  MBRange::iterator hint = ranged_file_ids.begin();
-  for (MBRange::iterator i = file_ids.begin(); i != file_ids.end(); ++i, ++buff_iter) {
+  Range::iterator hint = ranged_file_ids.begin();
+  for (Range::iterator i = file_ids.begin(); i != file_ids.end(); ++i, ++buff_iter) {
     if ((*buff_iter) & mhdf_SET_RANGE_BIT) {
       *buff_iter &= ~(unsigned)mhdf_SET_RANGE_BIT;
       hint = ranged_file_ids.insert( hint, *i, *i );
@@ -2064,7 +2066,7 @@
     if (MB_SUCCESS != rval)
       return error(rval);
       
-    MBEntityHandle h = start_handle;
+    EntityHandle h = start_handle;
     for (p = file_ids.const_pair_begin(); p != file_ids.const_pair_end(); ++p) {
       long count = p->second - p->first + 1;
       if (!idMap.insert( p->first, h, count ).second) 
@@ -2077,15 +2079,15 @@
 }
 
 
-MBErrorCode ReadHDF5::read_contents( ContentReader& tool,
-                                     const MBRange& file_ids,
+ErrorCode ReadHDF5::read_contents( ContentReader& tool,
+                                     const Range& file_ids,
                                      const long start_id,
-                                     const MBEntityHandle start_handle,
+                                     const EntityHandle start_handle,
                                      const long entity_count,
                                      const long content_len,
-                                     const MBRange& ranged_ids_in )
+                                     const Range& ranged_ids_in )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   if (file_ids.empty())
     return MB_SUCCESS;
@@ -2093,29 +2095,29 @@
 // If doing a full reed, we should end up reading the entire offset
 // column in order
 #ifndef NDEBUG
-  const bool full_read = (file_ids.front() == (MBEntityHandle)start_id) 
+  const bool full_read = (file_ids.front() == (EntityHandle)start_id) 
                       && (file_ids.size() == (size_t)entity_count);
   int offset_idx = 0;
 #endif
     
     // things will get messed up if this isn't true
   assert( subtract( ranged_ids_in, file_ids ).empty() );
-  assert( file_ids.front() >= (MBEntityHandle)start_id );
-  assert( file_ids.back() - start_id < (MBEntityHandle)entity_count );
+  assert( file_ids.front() >= (EntityHandle)start_id );
+  assert( file_ids.back() - start_id < (EntityHandle)entity_count );
 
   const long avg_set_len = content_len / entity_count;
-  long sets_per_buffer = bufferSize / (sizeof(long) + (avg_set_len+1)*sizeof(MBEntityHandle));
+  long sets_per_buffer = bufferSize / (sizeof(long) + (avg_set_len+1)*sizeof(EntityHandle));
     // round to down multiple of 8 to avoid alignment issues
   sets_per_buffer = 8 * (sets_per_buffer / 8);
   if (sets_per_buffer < 10) { // just in case there's one huge set
     sets_per_buffer = 10;  
     if (sets_per_buffer * (long)sizeof(long) > bufferSize) 
-      sets_per_buffer = bufferSize/(sizeof(long)+2*sizeof(MBEntityHandle));
+      sets_per_buffer = bufferSize/(sizeof(long)+2*sizeof(EntityHandle));
   }
   long* offset_buffer = (long*)dataBuffer;
-  MBEntityHandle* content_buffer = (MBEntityHandle*)(offset_buffer + sets_per_buffer);
+  EntityHandle* content_buffer = (EntityHandle*)(offset_buffer + sets_per_buffer);
   assert(bufferSize % sizeof(long) == 0);
-  long content_size = (MBEntityHandle*)(dataBuffer + bufferSize) - content_buffer;
+  long content_size = (EntityHandle*)(dataBuffer + bufferSize) - content_buffer;
   assert(dataBuffer + bufferSize >= (char*)(content_buffer + content_size));
     // content_size must be an even number or we might end up with half of a 
     // range pair in the buffer, which will break code below
@@ -2127,9 +2129,9 @@
     return MB_FAILURE;
   }
  
-  MBRange ranged_ids(ranged_ids_in);
-  MBEntityHandle h = start_handle;
-  MBRange sets(file_ids), range;
+  Range ranged_ids(ranged_ids_in);
+  EntityHandle h = start_handle;
+  Range sets(file_ids), range;
   long prev_start = start_id;
   long prev_count = 0;
   while (!sets.empty()) {
@@ -2209,7 +2211,7 @@
                             content_buffer, status );
         if (is_error(status))
           return error(MB_FAILURE);
-        MBEntityHandle* content_iter = content_buffer;
+        EntityHandle* content_iter = content_buffer;
         for (long i = 0; i < read_count; ++i) {
 #ifndef NDEBUG
           size_t exp_off = file_id - start_id; // the offset we think we are at
@@ -2241,24 +2243,24 @@
 
 
 
-MBErrorCode ReadHDF5::read_contents( const MBRange& set_file_ids,
-                                     MBEntityHandle start_handle,
+ErrorCode ReadHDF5::read_contents( const Range& set_file_ids,
+                                     EntityHandle start_handle,
                                      hid_t set_meta_data_table,
                                      hid_t set_contents_table,
                                      long set_contents_length,
-                                     const MBRange& ranged_set_file_ids )
+                                     const Range& ranged_set_file_ids )
 {
 
   class ReadSetContents : public ReadHDF5::ContentReader {
     const hid_t metaHandle, contentHandle, handleType, ioMode;
-    MBInterface *const mb;
+    Interface *const mb;
     const IDMap& idMap;
   public:
     ReadSetContents( hid_t meta, 
                      hid_t content, 
                      hid_t handle_type, 
                      hid_t io_mode,
-                     MBInterface* iface, 
+                     Interface* iface, 
                      const IDMap& id_map )
                     : metaHandle(meta), contentHandle(content), 
                       handleType(handle_type), ioMode(io_mode),
@@ -2268,15 +2270,15 @@
       { mhdf_readSetContentEndIndicesWithOpt( metaHandle, offset, count, 
                                               H5T_NATIVE_LONG, buffer, 
                                               ioMode, &status ); }
-    void read_contents( long offset, long count, MBEntityHandle* buffer, mhdf_Status& status )
+    void read_contents( long offset, long count, EntityHandle* buffer, mhdf_Status& status )
       { mhdf_readSetDataWithOpt( contentHandle, offset, count, handleType, 
                                  buffer, ioMode, &status ); }
-    MBErrorCode store_data( MBEntityHandle set, long, MBEntityHandle* array, long len, bool ranged ) 
+    ErrorCode store_data( EntityHandle set, long, EntityHandle* array, long len, bool ranged ) 
     {
       if (ranged) {
         if (len % 2) 
           return error(MB_INDEX_OUT_OF_RANGE);
-        MBRange range;
+        Range range;
         convert_range_to_handle( array, len/2, idMap, range );
         return mb->add_entities( set, range );
       }
@@ -2297,22 +2299,22 @@
 }
 
 
-MBErrorCode ReadHDF5::read_children( const MBRange& set_file_ids,
-                                     MBEntityHandle start_handle,
+ErrorCode ReadHDF5::read_children( const Range& set_file_ids,
+                                     EntityHandle start_handle,
                                      hid_t set_meta_data_table,
                                      hid_t set_contents_table,
                                      long set_contents_length )
 {
   class ReadSetChildren : public ReadHDF5::ContentReader {
     const hid_t metaHandle, contentHandle, handleType, ioMode;
-    MBInterface *const mb;
+    Interface *const mb;
     const IDMap& idMap;
   public:
     ReadSetChildren( hid_t meta, 
                      hid_t content, 
                      hid_t handle_type,
                      hid_t io_mode,
-                     MBInterface* iface, 
+                     Interface* iface, 
                      const IDMap& id_map )
                     : metaHandle(meta), contentHandle(content), 
                       handleType(handle_type), ioMode(io_mode),
@@ -2323,11 +2325,11 @@
                                             H5T_NATIVE_LONG, buffer, 
                                             ioMode, &status ); 
       }
-    void read_contents( long offset, long count, MBEntityHandle* buffer, mhdf_Status& status )
+    void read_contents( long offset, long count, EntityHandle* buffer, mhdf_Status& status )
       { mhdf_readSetParentsChildrenWithOpt( contentHandle, offset, count, 
                                             handleType, buffer, ioMode, &status );
       }
-    MBErrorCode store_data( MBEntityHandle set, long, MBEntityHandle* array, long len, bool ranged ) 
+    ErrorCode store_data( EntityHandle set, long, EntityHandle* array, long len, bool ranged ) 
     {
       assert(!ranged);
       size_t valid;
@@ -2336,26 +2338,26 @@
     }
   };
 
-  MBRange empty;
+  Range empty;
   ReadSetChildren tool( set_meta_data_table, set_contents_table, 
                         handleType, indepIO, iFace, idMap );
   return read_contents( tool, set_file_ids, fileInfo->sets.start_id, start_handle, 
                         fileInfo->sets.count, set_contents_length, empty );
 }
 
-MBErrorCode ReadHDF5::read_parents( const MBRange& set_file_ids,
-                                    MBEntityHandle start_handle,
+ErrorCode ReadHDF5::read_parents( const Range& set_file_ids,
+                                    EntityHandle start_handle,
                                     hid_t set_meta_data_table,
                                     hid_t set_contents_table,
                                     long set_contents_length )
 {
   class ReadSetParents : public ReadHDF5::ContentReader {
     const hid_t metaHandle, contentHandle, handleType, ioMode;
-    MBInterface *const mb;
+    Interface *const mb;
     const IDMap& idMap;
   public:
     ReadSetParents( hid_t meta, hid_t content, hid_t handle_type, 
-                    hid_t io_mode, MBInterface* iface, const IDMap& id_map )
+                    hid_t io_mode, Interface* iface, const IDMap& id_map )
                     : metaHandle(meta), contentHandle(content), 
                       handleType(handle_type), ioMode(io_mode),
                       mb(iface), idMap(id_map) 
@@ -2365,11 +2367,11 @@
                                              H5T_NATIVE_LONG, buffer, 
                                              ioMode, &status ); 
       }
-    void read_contents( long offset, long count, MBEntityHandle* buffer, mhdf_Status& status )
+    void read_contents( long offset, long count, EntityHandle* buffer, mhdf_Status& status )
       { mhdf_readSetParentsChildrenWithOpt( contentHandle, offset, count, 
                                             handleType, buffer, ioMode, &status ); 
       }
-    MBErrorCode store_data( MBEntityHandle set, long, MBEntityHandle* array, long len, bool ranged ) 
+    ErrorCode store_data( EntityHandle set, long, EntityHandle* array, long len, bool ranged ) 
     {
       assert(!ranged);
       size_t valid;
@@ -2378,7 +2380,7 @@
     }
   };
 
-  MBRange empty;
+  Range empty;
   ReadSetParents tool( set_meta_data_table, set_contents_table, 
                         handleType, indepIO, iFace, idMap );
   return read_contents( tool, set_file_ids, fileInfo->sets.start_id, start_handle, 
@@ -2386,13 +2388,13 @@
 }
 
 static void copy_set_contents( int ranged,
-                               const MBEntityHandle* contents,
+                               const EntityHandle* contents,
                                long length,
-                               MBRange& results )
+                               Range& results )
 {
   if (ranged) {
     assert( length%2 == 0 );
-    MBRange::iterator hint = results.begin();
+    Range::iterator hint = results.begin();
     for (long i = 0; i < length; i += 2)
       hint = results.insert( hint, contents[i], contents[i] + contents[i+1] - 1 );
   }
@@ -2403,14 +2405,14 @@
 }
 
 
-MBErrorCode ReadHDF5::get_set_contents( const MBRange& sets, MBRange& file_ids )
+ErrorCode ReadHDF5::get_set_contents( const Range& sets, Range& file_ids )
 {
   class GetContentList : public ReadHDF5::ContentReader {
     const hid_t metaHandle, contentHandle, handleType, ioMode;
-    MBRange *const resultList;
+    Range *const resultList;
   public:
     GetContentList( hid_t meta, hid_t content, hid_t handle_type, hid_t io_mode,
-                    MBRange* result_set )
+                    Range* result_set )
                     : metaHandle(meta), contentHandle(content), 
                       handleType(handle_type), ioMode(io_mode),
                       resultList(result_set) 
@@ -2421,11 +2423,11 @@
                                               H5T_NATIVE_LONG, buffer, 
                                               ioMode, &status );
       }
-    void read_contents( long offset, long count, MBEntityHandle* buffer, mhdf_Status& status )
+    void read_contents( long offset, long count, EntityHandle* buffer, mhdf_Status& status )
       { mhdf_readSetDataWithOpt( contentHandle, offset, count, handleType, 
                                  buffer, ioMode, &status ); 
       }
-    MBErrorCode store_data( MBEntityHandle set, long, MBEntityHandle* array, long len, bool ranged ) 
+    ErrorCode store_data( EntityHandle set, long, EntityHandle* array, long len, bool ranged ) 
     {
       if (ranged) {
         if (len % 2)
@@ -2440,7 +2442,7 @@
     }
   };
 
-  MBErrorCode rval;
+  ErrorCode rval;
   if (sets.empty())
     return MB_SUCCESS;
 
@@ -2456,8 +2458,8 @@
     return error(MB_FAILURE);
   }
 
-  MBEntityHandle junk;
-  MBRange ranged;
+  EntityHandle junk;
+  Range ranged;
   rval = read_sets( sets, meta, ranged, junk, false );
   if (MB_SUCCESS != rval) {
     mhdf_closeData( filePtr, meta, &status );
@@ -2474,13 +2476,13 @@
 }
 
 
-MBErrorCode ReadHDF5::read_adjacencies( hid_t table, long table_len )
+ErrorCode ReadHDF5::read_adjacencies( hid_t table, long table_len )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   
-  MBEntityHandle* buffer = (MBEntityHandle*)dataBuffer;
-  size_t chunk_size = bufferSize / sizeof(MBEntityHandle);
+  EntityHandle* buffer = (EntityHandle*)dataBuffer;
+  size_t chunk_size = bufferSize / sizeof(EntityHandle);
   size_t remaining = table_len;
   size_t left_over = 0;
   size_t offset = 0;
@@ -2495,12 +2497,12 @@
     if (is_error(status))
       return error(MB_FAILURE);
     
-    MBEntityHandle* iter = buffer;
-    MBEntityHandle* end = buffer + count + left_over;
+    EntityHandle* iter = buffer;
+    EntityHandle* end = buffer + count + left_over;
     while (end - iter >= 3)
     {
-      MBEntityHandle h = idMap.find( *iter++ );
-      MBEntityHandle count2 = *iter++;
+      EntityHandle h = idMap.find( *iter++ );
+      EntityHandle count2 = *iter++;
       if (!h) {
         iter += count2;
         continue;
@@ -2534,11 +2536,11 @@
 }
 
 
-MBErrorCode ReadHDF5::read_tag( int tag_index )
+ErrorCode ReadHDF5::read_tag( int tag_index )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  MBTag tag = 0;
+  Tag tag = 0;
   hid_t read_type;
   rval = create_tag( fileInfo->tags[tag_index], tag, read_type ); 
   if (MB_SUCCESS != rval)
@@ -2635,14 +2637,14 @@
     
 
 
-MBErrorCode ReadHDF5::create_tag( const mhdf_TagDesc& info,
-                                  MBTag& handle,
+ErrorCode ReadHDF5::create_tag( const mhdf_TagDesc& info,
+                                  Tag& handle,
                                   hid_t& hdf_type )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  MBTagType storage;
-  MBDataType mb_type;
+  TagType storage;
+  DataType mb_type;
   bool re_read_default = false;
 
   switch (info.storage) {
@@ -2671,7 +2673,7 @@
     mb_type = MB_TYPE_OPAQUE;
 
       // Check for user-provided type
-    MBTag type_handle;
+    Tag type_handle;
     std::string tag_type_name = "__hdf5_tag_type_";
     tag_type_name += info.name;
     rval = iFace->tag_get_handle( tag_type_name.c_str(), type_handle );
@@ -2749,14 +2751,14 @@
     
     if (MB_TYPE_HANDLE == mb_type) {
       if (info.default_value) {
-        rval = convert_id_to_handle( (MBEntityHandle*)info.default_value, info.default_value_size );
+        rval = convert_id_to_handle( (EntityHandle*)info.default_value, info.default_value_size );
         if (MB_SUCCESS != rval) {
           if (hdf_type) H5Tclose( hdf_type );
           return error(rval);
         }
       }
       if (info.global_value) {
-        rval = convert_id_to_handle( (MBEntityHandle*)info.global_value, info.global_value_size );
+        rval = convert_id_to_handle( (EntityHandle*)info.global_value, info.global_value_size );
         if (MB_SUCCESS != rval) {
           if (hdf_type) H5Tclose( hdf_type );
           return error(rval);
@@ -2771,8 +2773,8 @@
   if (MB_SUCCESS == rval) {
     // If tag exists, make sure it is consistant with the type in the file
     int curr_size;
-    MBDataType curr_type;
-    MBTagType curr_store;
+    DataType curr_type;
+    TagType curr_store;
     
     rval = iFace->tag_get_size( handle, curr_size );
     if (MB_VARIABLE_DATA_LENGTH == rval)
@@ -2840,15 +2842,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_dense_tag( MBTag tag_handle,
+ErrorCode ReadHDF5::read_dense_tag( Tag tag_handle,
                                       hid_t hdf_read_type,
                                       hid_t data,
                                       long start_id,
                                       long num_values )
 {
   mhdf_Status status;
-  MBErrorCode rval;
-  MBDataType mb_type;
+  ErrorCode rval;
+  DataType mb_type;
   
   rval = iFace->tag_get_data_type( tag_handle, mb_type );
   if (MB_SUCCESS != rval) 
@@ -2862,7 +2864,7 @@
   }
   
     // get actual entities read from file
-  MBRange file_ids;
+  Range file_ids;
   IDMap::iterator l, u;
   l = idMap.lower_bound( start_id );
   u = idMap.lower_bound( start_id + num_values - 1 );
@@ -2894,12 +2896,12 @@
       return error(MB_FAILURE);
   
     if (MB_TYPE_HANDLE == mb_type) {
-      rval = convert_id_to_handle( (MBEntityHandle*)dataBuffer, count * read_size / sizeof(MBEntityHandle) );
+      rval = convert_id_to_handle( (EntityHandle*)dataBuffer, count * read_size / sizeof(EntityHandle) );
       if (MB_SUCCESS != rval)
         return error(rval);
     }
     
-    MBRange ents;
+    Range ents;
     ents.insert( idMap.find( first ), idMap.find( first + count - 1 ) );
     rval = iFace->tag_set_data( tag_handle, ents, dataBuffer );
     if (MB_SUCCESS != rval)
@@ -2910,15 +2912,15 @@
 }
 
 
-MBErrorCode ReadHDF5::read_sparse_tag( MBTag tag_handle,
+ErrorCode ReadHDF5::read_sparse_tag( Tag tag_handle,
                                        hid_t hdf_read_type,
                                        hid_t id_table,
                                        hid_t value_table,
                                        long num_values )
 {
   mhdf_Status status;
-  MBErrorCode rval;
-  MBDataType mbtype;
+  ErrorCode rval;
+  DataType mbtype;
   
   rval = iFace->tag_get_data_type( tag_handle, mbtype );
   if (MB_SUCCESS != rval) 
@@ -2937,7 +2939,7 @@
       return error(MB_FAILURE);
   }
 
-  const int handles_per_tag = read_size/sizeof(MBEntityHandle);
+  const int handles_per_tag = read_size/sizeof(EntityHandle);
   
   
     // Split buffer into two portions: one for handles and one for data.
@@ -2947,12 +2949,12 @@
     // pass as the size of the buffer over the sum of the size of a handle
     // and value.  Subtract off the size of one value so we reserve space
     // for adjusting for data alignment.
-  long chunk_size = (bufferSize - read_size) / (sizeof(MBEntityHandle) + read_size);
+  long chunk_size = (bufferSize - read_size) / (sizeof(EntityHandle) + read_size);
   
     // Use the first half of the buffer for the handles.
-  MBEntityHandle* idbuf = (MBEntityHandle*)dataBuffer;
+  EntityHandle* idbuf = (EntityHandle*)dataBuffer;
     // Use the latter portion of the buffer for data
-  char* databuf = dataBuffer + (chunk_size * sizeof(MBEntityHandle));
+  char* databuf = dataBuffer + (chunk_size * sizeof(EntityHandle));
     // To be safe, align tag data to the size of an entire tag value
   if ((size_t)databuf % read_size)
     databuf += read_size - ((size_t)databuf % read_size);
@@ -3004,7 +3006,7 @@
         // for read & delete, they will both be collective IO.
       if (collIO == indepIO && j == count && 2*i >= count && remaining > count) {
         long keep = j - i;
-        memmove( idbuf, idbuf + i, sizeof(MBEntityHandle)*keep );
+        memmove( idbuf, idbuf + i, sizeof(EntityHandle)*keep );
         long count2 = std::min( remaining - keep, count - keep );
         mhdf_readSparseTagEntitiesWithOpt( id_table, next_offset, count2, handleType, 
                                            idbuf+keep, indepIO, &status );
@@ -3032,7 +3034,7 @@
         return error(MB_FAILURE);
       
       if (MB_TYPE_HANDLE == mbtype) {
-        rval = convert_id_to_handle( (MBEntityHandle*)databuf + i*handles_per_tag, 
+        rval = convert_id_to_handle( (EntityHandle*)databuf + i*handles_per_tag, 
                                      (j-i) * handles_per_tag );
         if (MB_SUCCESS != rval)
           return error(rval);
@@ -3054,7 +3056,7 @@
 #define assert_range( ARRAY, BYTES ) \
   assert( (char*)(ARRAY) >= dataBuffer && ((char*)(ARRAY)) + (BYTES) <= dataBuffer + bufferSize )
 
-MBErrorCode ReadHDF5::read_var_len_tag( MBTag tag_handle,
+ErrorCode ReadHDF5::read_var_len_tag( Tag tag_handle,
                                         hid_t hdf_read_type,
                                         hid_t ent_table,
                                         hid_t val_table,
@@ -3064,8 +3066,8 @@
 {
   std::vector<char> tmp_buffer;
   mhdf_Status status;
-  MBErrorCode rval;
-  MBDataType mbtype;
+  ErrorCode rval;
+  DataType mbtype;
   
   rval = iFace->tag_get_data_type( tag_handle, mbtype );
   if (MB_SUCCESS != rval) 
@@ -3101,16 +3103,16 @@
     // 3) tag sizes (calculated from file data)
     // 4) tag data
   const long avg_data_size = (num_values * read_size) / num_entities;
-  const long per_ent_size = sizeof(long) + sizeof(MBEntityHandle) + sizeof(int);
+  const long per_ent_size = sizeof(long) + sizeof(EntityHandle) + sizeof(int);
   long num_ent = bufferSize / (per_ent_size + avg_data_size + avg_data_size/2);
   if (num_ent == 0) 
     num_ent = bufferSize / 4 / sizeof(void*);
   const long data_buffer_size = (bufferSize - num_ent * per_ent_size) / read_size;
   long* const end_idx_buffer = reinterpret_cast<long*>(dataBuffer);
   char* handle_buffer_start = reinterpret_cast<char*>(end_idx_buffer + num_ent+1);
-  if (((size_t)handle_buffer_start) % sizeof(MBEntityHandle))
-    handle_buffer_start += sizeof(MBEntityHandle) - ((size_t)handle_buffer_start);
-  MBEntityHandle* const handle_buffer = reinterpret_cast<MBEntityHandle*>(handle_buffer_start);
+  if (((size_t)handle_buffer_start) % sizeof(EntityHandle))
+    handle_buffer_start += sizeof(EntityHandle) - ((size_t)handle_buffer_start);
+  EntityHandle* const handle_buffer = reinterpret_cast<EntityHandle*>(handle_buffer_start);
   int* const size_buffer = reinterpret_cast<int*>(handle_buffer + num_ent);
   char* const data_buffer = reinterpret_cast<char*>(size_buffer + num_ent);
   
@@ -3126,13 +3128,13 @@
     remaining -= count;
  
       // read entity IDs
-    assert_range( handle_buffer, count * sizeof(MBEntityHandle) );
+    assert_range( handle_buffer, count * sizeof(EntityHandle) );
     mhdf_readSparseTagEntitiesWithOpt( ent_table, offset, count, handleType, 
                                        handle_buffer, collIO, &status );
     if (is_error(status))
       return error(MB_FAILURE);
     
-      // convert entity ID to MBEntityHandle
+      // convert entity ID to EntityHandle
     rval = convert_id_to_handle( handle_buffer, count );
     if (MB_SUCCESS != rval)
       return error(rval);
@@ -3165,7 +3167,7 @@
         // for read & delete, they will both be collective IO.
       if (collIO == indepIO && j == count && 2*i >= count && remaining > count) {
         long keep = j - i;
-        memmove( handle_buffer, handle_buffer + i, sizeof(MBEntityHandle)*keep );
+        memmove( handle_buffer, handle_buffer + i, sizeof(EntityHandle)*keep );
           // read more entity IDs
         long count2 = std::min( remaining - keep, count - keep );
         mhdf_readSparseTagEntitiesWithOpt( ent_table, next_offset, count2, handleType, 
@@ -3237,7 +3239,7 @@
           return error(MB_FAILURE);
       
         if (MB_TYPE_HANDLE == mbtype) {
-          rval = convert_id_to_handle( (MBEntityHandle*)memptr, val_count );
+          rval = convert_id_to_handle( (EntityHandle*)memptr, val_count );
           if (MB_SUCCESS != rval)
             return error(rval);
         }
@@ -3279,26 +3281,26 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::convert_id_to_handle( MBEntityHandle* array, 
+ErrorCode ReadHDF5::convert_id_to_handle( EntityHandle* array, 
                                             size_t size )
 {
   convert_id_to_handle( array, size, idMap );
   return MB_SUCCESS;
 }
 
-void ReadHDF5::convert_id_to_handle( MBEntityHandle* array, 
+void ReadHDF5::convert_id_to_handle( EntityHandle* array, 
                                      size_t size,
-                                     const RangeMap<long,MBEntityHandle>& id_map )
+                                     const RangeMap<long,EntityHandle>& id_map )
 {
-  for (MBEntityHandle* const end = array + size; array != end; ++array)
+  for (EntityHandle* const end = array + size; array != end; ++array)
     *array = id_map.find( *array );
 }
 
-void ReadHDF5::convert_id_to_handle( MBEntityHandle* array, 
+void ReadHDF5::convert_id_to_handle( EntityHandle* array, 
                                      size_t size, size_t& new_size,
-                                     const RangeMap<long,MBEntityHandle>& id_map )
+                                     const RangeMap<long,EntityHandle>& id_map )
 {
-  RangeMap<long,MBEntityHandle>::const_iterator it;
+  RangeMap<long,EntityHandle>::const_iterator it;
   new_size = 0;
   for (size_t i = 0; i < size; ++i) {
     it = id_map.lower_bound( array[i] );
@@ -3307,12 +3309,12 @@
   }
 }
 
-void ReadHDF5::convert_range_to_handle( const MBEntityHandle* ranges,
+void ReadHDF5::convert_range_to_handle( const EntityHandle* ranges,
                                         size_t num_ranges,
-                                        const RangeMap<long,MBEntityHandle>& id_map,
-                                        MBRange& merge )
+                                        const RangeMap<long,EntityHandle>& id_map,
+                                        Range& merge )
 {
-  RangeMap<long,MBEntityHandle>::iterator it = id_map.begin();
+  RangeMap<long,EntityHandle>::iterator it = id_map.begin();
   for (size_t i = 0; i < num_ranges; ++i) {
     long id = ranges[2*i];
     const long end = id + ranges[2*i+1];
@@ -3336,16 +3338,16 @@
   }
 }
 
-MBErrorCode ReadHDF5::convert_range_to_handle( const MBEntityHandle* array,
+ErrorCode ReadHDF5::convert_range_to_handle( const EntityHandle* array,
                                                size_t num_ranges,
-                                               MBRange& range )
+                                               Range& range )
 {
   convert_range_to_handle( array, num_ranges, idMap, range );
   return MB_SUCCESS;
 }
   
 
-MBErrorCode ReadHDF5::read_qa( MBEntityHandle import_set )
+ErrorCode ReadHDF5::read_qa( EntityHandle import_set )
 {
   mhdf_Status status;
   std::vector<std::string> qa_list;
@@ -3370,7 +3372,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::store_file_ids( MBTag tag )
+ErrorCode ReadHDF5::store_file_ids( Tag tag )
 {
   typedef int tag_type;
   tag_type* buffer = reinterpret_cast<tag_type*>(dataBuffer);
@@ -3389,14 +3391,14 @@
     while (range.count) {
       long count = buffer_size < range.count ? buffer_size : range.count;
 
-      MBRange handles;
+      Range handles;
       handles.insert( range.value, range.value + count - 1 );
       range.value += count;
       range.count -= count;
       for (long j = 0; j < count; ++j) 
         buffer[j] = (tag_type)range.begin++;
 
-      MBErrorCode rval = iFace->tag_set_data( tag, handles, buffer );
+      ErrorCode rval = iFace->tag_set_data( tag, handles, buffer );
       if (MB_SUCCESS != rval)
         return rval;
     }
@@ -3404,14 +3406,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_tag_values( const char* file_name,
+ErrorCode ReadHDF5::read_tag_values( const char* file_name,
                                        const char* tag_name,
                                        const FileOptions& opts,
                                        std::vector<int>& tag_values_out,
                                        const IDTag* subset_list,
                                        int subset_list_length )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   rval = set_up_read( file_name, opts );
   if (MB_SUCCESS != rval)
@@ -3425,7 +3427,7 @@
   }
   
   if (subset_list && subset_list_length) {
-    MBRange file_ids;
+    Range file_ids;
     rval = get_subset_ids( subset_list, subset_list_length, file_ids );
     if (MB_SUCCESS != rval) {
       clean_up_read( opts );
@@ -3449,8 +3451,8 @@
   return clean_up_read( opts );
 }
 
-MBErrorCode ReadHDF5::read_tag_values_partial( int tag_index,
-                                               const MBRange& file_ids,
+ErrorCode ReadHDF5::read_tag_values_partial( int tag_index,
+                                               const Range& file_ids,
                                                std::vector<int>& tag_values )
 {
   mhdf_Status status;
@@ -3468,7 +3470,7 @@
     
       // read all entity handles and fill 'offsets' with ranges of
       // offsets into the data table for entities that we want.
-    MBRange offsets;
+    Range offsets;
     long* buffer = reinterpret_cast<long*>(dataBuffer);
     const long buffer_size = bufferSize/sizeof(long);
     long remaining = num_ent, offset = 0;
@@ -3485,8 +3487,8 @@
       }
       
       std::sort( buffer, buffer+count );
-      MBRange::iterator ins = offsets.begin();
-      MBRange::const_iterator i = file_ids.begin();
+      Range::iterator ins = offsets.begin();
+      Range::const_iterator i = file_ids.begin();
       for (long j = 0; j < count; ++j) {
         while (i != file_ids.end() && (long)*i < buffer[j])
           ++i;
@@ -3509,7 +3511,7 @@
     }
 
     tag_values.clear();
-    MBRange::const_pair_iterator p;
+    Range::const_pair_iterator p;
     for (p = offsets.const_pair_begin(); p != offsets.const_pair_end(); ++p) {
       long offset = p->first;
       long count = p->second - p->first + 1;
@@ -3554,10 +3556,10 @@
       desc = &fileInfo->elems[grp].desc;
     }
     
-    MBRange::iterator s = file_ids.lower_bound( (MBEntityHandle)(desc->start_id) );
-    MBRange::iterator e = MBRange::lower_bound( s, file_ids.end(),  
-                                   (MBEntityHandle)(desc->start_id) + desc->count );
-    MBRange subset;
+    Range::iterator s = file_ids.lower_bound( (EntityHandle)(desc->start_id) );
+    Range::iterator e = Range::lower_bound( s, file_ids.end(),  
+                                   (EntityHandle)(desc->start_id) + desc->count );
+    Range subset;
     subset.merge( s, e );
     
     hid_t handle = mhdf_openDenseTagData( filePtr, tag.name, gname, &num_val, &status );
@@ -3567,7 +3569,7 @@
     }
     
     curr_data.clear();
-    MBRange::const_pair_iterator p;
+    Range::const_pair_iterator p;
     for (p = subset.const_pair_begin(); p != subset.const_pair_end(); ++p) {
       long offset = p->first - desc->start_id;
       long count = p->second - p->first + 1;
@@ -3601,7 +3603,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadHDF5::read_tag_values_all( int tag_index,
+ErrorCode ReadHDF5::read_tag_values_all( int tag_index,
                                            std::vector<int>& tag_values )
 {
   mhdf_Status status;
@@ -3686,3 +3688,5 @@
   
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadHDF5.hpp
===================================================================
--- MOAB/trunk/src/io/ReadHDF5.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadHDF5.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -26,22 +26,24 @@
 #include <stdlib.h>
 #include <list>
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 #include "mhdf.h"
-#include "MBForward.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBRange.hpp"
-#include "MBReaderIface.hpp"
-#include "RangeMap.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/RangeMap.hpp"
 
-class ReadHDF5 : public MBReaderIface
+namespace moab {
+
+class ReadHDF5 : public ReaderIface
 {
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
-  ReadHDF5( MBInterface* iface );
+  ReadHDF5( Interface* iface );
   
   virtual ~ReadHDF5();
   
@@ -50,14 +52,14 @@
    * \param export_sets  Array of handles to sets to export, or NULL to export all.
    * \param export_set_count Length of <code>export_sets</code> array.
    */
-  MBErrorCode load_file( const char* filename,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char* filename,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -66,18 +68,18 @@
 
 protected:
 
-  MBErrorCode load_file_impl( const FileOptions& opts );
+  ErrorCode load_file_impl( const FileOptions& opts );
 
-  MBErrorCode load_file_partial( const MBReaderIface::IDTag* subset_list,
+  ErrorCode load_file_partial( const ReaderIface::IDTag* subset_list,
                                  int subset_list_length,
                                  const FileOptions& opts );
 
-  MBErrorCode read_tag_values_all( int tag_index, std::vector<int>& results );
-  MBErrorCode read_tag_values_partial( int tag_index, const MBRange& file_ids,
+  ErrorCode read_tag_values_all( int tag_index, std::vector<int>& results );
+  ErrorCode read_tag_values_partial( int tag_index, const Range& file_ids,
                                        std::vector<int>& results );
 
 private:
-  MBErrorCode init();
+  ErrorCode init();
   
   inline int is_error( mhdf_Status& status ) {
     int i;
@@ -91,8 +93,8 @@
   //! A memory buffer to use for all I/O operations.
   char* dataBuffer;
 
-  //! MBInterface pointer passed to constructor
-  MBInterface* iFace;
+  //! Interface pointer passed to constructor
+  Interface* iFace;
   
   //! The file handle from the mhdf library
   mhdf_FileHandle filePtr;
@@ -101,13 +103,13 @@
   mhdf_FileDesc* fileInfo;
   
   //! Map from File ID to MOAB handle
-  typedef RangeMap< long, MBEntityHandle > IDMap;
+  typedef RangeMap< long, EntityHandle > IDMap;
   IDMap idMap;
   
   //! Cache pointer to read util
-  MBReadUtilIface* readUtil;
+  ReadUtilIface* readUtil;
   
-  //! The type of an MBEntityHandle
+  //! The type of an EntityHandle
   hid_t handleType;
   
   //! read/write property handle
@@ -117,82 +119,82 @@
   //! when reading the entire file on all processors.
   hid_t indepIO, collIO;
   
-  MBErrorCode set_up_read( const char* file_name, const FileOptions& opts );
-  MBErrorCode clean_up_read( const FileOptions& opts );
+  ErrorCode set_up_read( const char* file_name, const FileOptions& opts );
+  ErrorCode clean_up_read( const FileOptions& opts );
   
   
   //! Given a list of tags and values, get the file ids for the
   //! corresponding entities in the file.
-  MBErrorCode get_subset_ids( const MBReaderIface::IDTag* subset_list,
+  ErrorCode get_subset_ids( const ReaderIface::IDTag* subset_list,
                               int subset_list_length,
-                              MBRange& file_ids_out );
+                              Range& file_ids_out );
   
-  MBErrorCode read_nodes( const MBRange& node_file_ids );
+  ErrorCode read_nodes( const Range& node_file_ids );
   
     // Read elements in fileInfo->elems[index]
-  MBErrorCode read_elems( int index );
+  ErrorCode read_elems( int index );
   
     // Read subset of elements in fileInfo->elems[index]
-  MBErrorCode read_elems( int index, const MBRange& file_ids );
+  ErrorCode read_elems( int index, const Range& file_ids );
   
   //! Read element connectivity.
-  MBErrorCode read_elems( const mhdf_ElemDesc& elems, const MBRange& file_ids );
+  ErrorCode read_elems( const mhdf_ElemDesc& elems, const Range& file_ids );
   
   
     // Read connectivity data for a list of element file ids.
     // passing back the file IDs for the element connectivity 
     // w/out actually creating any elements in MOAB.
-  MBErrorCode read_elems( int index, const MBRange& element_file_ids, MBRange& node_file_ids );
+  ErrorCode read_elems( int index, const Range& element_file_ids, Range& node_file_ids );
 
     // Scan all elements in group.  For each element for which all vertices
     // are contained in idMap (class member), read the element.  All new
     // elements are added to idMap.
     //
     // NOTE: Collective IO calls in parallel.
-  MBErrorCode read_node_adj_elems( const mhdf_ElemDesc& group );
+  ErrorCode read_node_adj_elems( const mhdf_ElemDesc& group );
   
     // Scan all elements in specified file table.  For each element for 
     // which all vertices are contained in idMap (class member), read the 
     // element.  All new elements are added to idMap.
     //
     // NOTE: Collective IO calls in parallel.
-  MBErrorCode read_node_adj_elems( const mhdf_ElemDesc& group,
+  ErrorCode read_node_adj_elems( const mhdf_ElemDesc& group,
                                    hid_t connectivity_handle );
 
   //! Read poly(gons|hedra)
-  MBErrorCode read_poly( const mhdf_ElemDesc& elems, const MBRange& file_ids );
+  ErrorCode read_poly( const mhdf_ElemDesc& elems, const Range& file_ids );
   
   //! Read specified elements and any adjacent elements of lower dimension.
   //! Assumes vertices are already read in.
-  MBErrorCode read_elements_and_sides( const MBRange& file_ids );
+  ErrorCode read_elements_and_sides( const Range& file_ids );
   
   //! Read sets
-  MBErrorCode read_sets( const MBRange& set_file_ids );
+  ErrorCode read_sets( const Range& set_file_ids );
   
   //! Read set contents
-  MBErrorCode read_set_contents( hid_t set_description_handle,
+  ErrorCode read_set_contents( hid_t set_description_handle,
                                  hid_t set_contents_handle,
                                  const unsigned long data_len );
   
   //! Read set parents/children
-  MBErrorCode read_parents_children( bool parents, 
+  ErrorCode read_parents_children( bool parents, 
                                      hid_t set_description_handle,
                                      hid_t set_contents_handle,
                                      const unsigned long data_len );
   
-  MBErrorCode read_adjacencies( hid_t adjacency_table,
+  ErrorCode read_adjacencies( hid_t adjacency_table,
                                 long table_length );
                                 
   
   //! Create tag and read all data.
-  MBErrorCode read_tag( int index );
+  ErrorCode read_tag( int index );
   
   //! Create new tag or varify type matches existing tag
-  MBErrorCode create_tag( const mhdf_TagDesc& info, MBTag& handle, hid_t& type );
+  ErrorCode create_tag( const mhdf_TagDesc& info, Tag& handle, hid_t& type );
   
   
   //! Read dense tag for all entities 
-  MBErrorCode read_dense_tag( MBTag tag_handle,
+  ErrorCode read_dense_tag( Tag tag_handle,
                               hid_t hdf_read_type,
                               hid_t data_table,
                               long start_id,
@@ -200,14 +202,14 @@
 
   
   //! Read sparse tag for all entities.
-  MBErrorCode read_sparse_tag( MBTag tag_handle,
+  ErrorCode read_sparse_tag( Tag tag_handle,
                                hid_t hdf_read_type,
                                hid_t ent_table,
                                hid_t val_table,
                                long num_entities );
   
   //! Read variable-length tag for all entities.
-  MBErrorCode read_var_len_tag( MBTag tag_handle,
+  ErrorCode read_var_len_tag( Tag tag_handle,
                                 hid_t hdf_read_type,
                                 hid_t ent_table,
                                 hid_t val_table,
@@ -215,31 +217,31 @@
                                 long num_entities,
                                 long num_values );
                                
-  MBErrorCode read_qa( MBEntityHandle file_set );
+  ErrorCode read_qa( EntityHandle file_set );
                                
-  MBErrorCode convert_id_to_handle( MBEntityHandle* in_out_array,
+  ErrorCode convert_id_to_handle( EntityHandle* in_out_array,
                                     size_t array_length );
                                     
-  MBErrorCode convert_range_to_handle( const MBEntityHandle* ranges,
+  ErrorCode convert_range_to_handle( const EntityHandle* ranges,
                                        size_t num_ranges,
-                                       MBRange& merge );
+                                       Range& merge );
                                     
   static
-  void convert_id_to_handle( MBEntityHandle* in_out_array,
+  void convert_id_to_handle( EntityHandle* in_out_array,
                              size_t array_length,
-                             const RangeMap<long,MBEntityHandle>& id_map );
+                             const RangeMap<long,EntityHandle>& id_map );
                                     
   static
-  void convert_id_to_handle( MBEntityHandle* in_out_array,
+  void convert_id_to_handle( EntityHandle* in_out_array,
                              size_t array_length,
                              size_t& array_length_out,
-                             const RangeMap<long,MBEntityHandle>& id_map );
+                             const RangeMap<long,EntityHandle>& id_map );
 
   static
-  void convert_range_to_handle( const MBEntityHandle* ranges,
+  void convert_range_to_handle( const EntityHandle* ranges,
                                 size_t num_ranges,
-                                const RangeMap<long,MBEntityHandle>& id_map,
-                                MBRange& merge );
+                                const RangeMap<long,EntityHandle>& id_map,
+                                Range& merge );
   
   /**\brief Search for entities with specified tag values 
    * 
@@ -250,9 +252,9 @@
    *                  order.
    *\param file_ids_out  File IDs for entities with specified tag values.
    */
-  MBErrorCode search_tag_values( int tag_index,
+  ErrorCode search_tag_values( int tag_index,
                                  const std::vector<int>& sorted_values,
-                                 MBRange& file_ids_out );
+                                 Range& file_ids_out );
   
   /**\brief Search for entities with specified tag 
    * 
@@ -261,7 +263,7 @@
    *\param tag_index  Index into info->tags specifying which tag to search.
    *\param file_ids_out  File IDs for entities with specified tag values.
    */
-  MBErrorCode get_tagged_entities( int tag_index, MBRange& file_ids_out );
+  ErrorCode get_tagged_entities( int tag_index, Range& file_ids_out );
                                  
   /**\brief Search a table of tag data for a specified set of values.
    *
@@ -276,10 +278,10 @@
    *\param value_indices Output: Offsets into the table of data at which 
    *                       matching values were found.
    */
-  MBErrorCode search_tag_values( hid_t tag_table, 
+  ErrorCode search_tag_values( hid_t tag_table, 
                                  unsigned long table_size,
                                  const std::vector<int>& sorted_values,
-                                 std::vector<MBEntityHandle>& value_indices );
+                                 std::vector<EntityHandle>& value_indices );
   
   /**\brief Get the file IDs for nodes and elements contained in sets.
    *
@@ -288,20 +290,20 @@
    *\param sets       Container of file IDs designating entity sets.
    *\param file_ids   Output: File IDs of entities contained in sets.
    */
-  MBErrorCode get_set_contents( const MBRange& sets, MBRange& file_ids );
+  ErrorCode get_set_contents( const Range& sets, Range& file_ids );
  
   /** Given a list of file IDs for entity sets, find all contained
-   *  or child sets (at any depth) and append them to the MBRange 
+   *  or child sets (at any depth) and append them to the Range 
    *  of file IDs.
    */
-  MBErrorCode read_set_ids_recursive( MBRange& sets_in_out,
+  ErrorCode read_set_ids_recursive( Range& sets_in_out,
                                       bool containted_sets,
                                       bool child_sets );
   
   /** Find all sets containing one or more entities read from the file
    *  and added to idMap 
    */
-  MBErrorCode find_sets_containing( MBRange& sets_out );
+  ErrorCode find_sets_containing( Range& sets_out );
  
   /**\brief Read sets from file into MOAB for partial read of file.
    *
@@ -312,29 +314,29 @@
    * already-read element or node.)
    *\param sets_in    File IDs for sets to read (unconditionally)
    */
-  MBErrorCode read_sets_partial( const MBRange& sets_in );
+  ErrorCode read_sets_partial( const Range& sets_in );
 
   /** Find file IDs of sets containing any entities in the passed id_map */
-  MBErrorCode find_sets_containing( hid_t meta_handle,
+  ErrorCode find_sets_containing( hid_t meta_handle,
                                     hid_t content_handle, 
                                     long content_len,
-                                    MBRange& file_ids );  
+                                    Range& file_ids );  
  
   /** Given a list of file IDs for entity sets, read the list of 
    *  file IDs for all child entity sets.
    */
-  MBErrorCode read_child_ids( const MBRange& set_file_ids,
+  ErrorCode read_child_ids( const Range& set_file_ids,
                               hid_t meta_handle,
                               hid_t child_handle,
-                              MBRange& child_file_ids );
+                              Range& child_file_ids );
  
   /** Given a list of file IDs for entity sets, read the list of 
    *  file IDs for all contained entity sets.
    */
-  MBErrorCode read_contained_set_ids( const MBRange& set_file_ids,
+  ErrorCode read_contained_set_ids( const Range& set_file_ids,
                                       hid_t meta_handle,
                                       hid_t contents_handle,
-                                      MBRange& containd_set_file_ids );
+                                      Range& containd_set_file_ids );
     
     /**\brief Create sets 
      *
@@ -344,34 +346,34 @@
      *\param info      Summary of data contained in the file.
      *\param file_ids  List of file IDs designating which sets will be read.
      *\param set_meta_handle HDF5/mhdf handle for set metadata table.
-     *\parma id_map    Map from file IDs to MBEntityHandle for entities read
+     *\parma id_map    Map from file IDs to EntityHandle for entities read
      *                 from file.  Sets created by this function will be appended.
      *\param ranged_file_ids_out This function will add to this container
      *                 the file IDs for any sets for which the contents are
      *                 stored using ranged compression (any set for which
      *                 mhdf_SET_RANGE_BIT is set in the flags.)
      */
-  MBErrorCode read_sets( const MBRange& file_ids,
+  ErrorCode read_sets( const Range& file_ids,
                          hid_t set_meta_handle, 
-                         MBRange& ranged_file_ids_out,
-                         MBEntityHandle& start_handle,
+                         Range& ranged_file_ids_out,
+                         EntityHandle& start_handle,
                          bool create = true );
    
-   MBErrorCode read_contents( const MBRange& set_file_ids,
-                              MBEntityHandle start_handle,
+   ErrorCode read_contents( const Range& set_file_ids,
+                              EntityHandle start_handle,
                               hid_t set_meta_data_table,
                               hid_t set_contents_table,
                               long set_contents_length,
-                              const MBRange& ranged_set_file_ids );
+                              const Range& ranged_set_file_ids );
 
-   MBErrorCode read_parents( const MBRange& set_file_ids,
-                             MBEntityHandle start_handle,
+   ErrorCode read_parents( const Range& set_file_ids,
+                             EntityHandle start_handle,
                              hid_t set_meta_data_table,
                              hid_t set_parents_table,
                              long set_parents_length );
 
-   MBErrorCode read_children( const MBRange& set_file_ids,
-                              MBEntityHandle start_handle,
+   ErrorCode read_children( const Range& set_file_ids,
+                              EntityHandle start_handle,
                               hid_t set_meta_data_table,
                               hid_t set_children_table,
                               long set_children_length );
@@ -383,10 +385,10 @@
       read_indices( long, long, long*, mhdf_Status& ) = 0;
       
       virtual void 
-      read_contents( long, long, MBEntityHandle*, mhdf_Status& ) = 0;
+      read_contents( long, long, EntityHandle*, mhdf_Status& ) = 0;
       
-      virtual MBErrorCode 
-      store_data( MBEntityHandle, long file_id, MBEntityHandle*, long len, bool ranged = false ) = 0;
+      virtual ErrorCode 
+      store_data( EntityHandle, long file_id, EntityHandle*, long len, bool ranged = false ) = 0;
    };
    
    /**\brief Read end-indexed variable length handle lists such as
@@ -398,34 +400,36 @@
      * have been read from the file.
      *\param file_ids        File IDs of entity sets to read.
      *\param start_id        ID of first entity in table.
-     *\param start_handle    MBEntityHandle for first entity set in file_ids
+     *\param start_handle    EntityHandle for first entity set in file_ids
      *                       (assumes all sets in file_ids have sequential
      *                        handles.)
      *\param set_content_len Length of set contents table.
      *\param ranged_file_ids Subset of file_ids for which set contents
      *                       are stored in ranged format.
      */
-  MBErrorCode read_contents( ContentReader& tool,
-                             const MBRange& file_ids,
+  ErrorCode read_contents( ContentReader& tool,
+                             const Range& file_ids,
                              const long start_id,
-                             const MBEntityHandle start_handle,
+                             const EntityHandle start_handle,
                              const long num_sets,
                              const long set_content_len,
-                             const MBRange& ranged_file_ids );
+                             const Range& ranged_file_ids );
   
     /**\brief Store file IDS in tag values
      *
      * Copy fild ID from IDMap for each entity read from file
      * into a tag value on the entity.
      */
-  MBErrorCode store_file_ids( MBTag tag );
+  ErrorCode store_file_ids( Tag tag );
   
     /**\brief Find index in mhdf_FileDesc* fileInfo for specified tag name
      *
      * Given a tag name, find its index in fileInfo and verify that
      * each tag value is a single integer.
      */
-  MBErrorCode find_int_tag( const char* name, int& index_out );
+  ErrorCode find_int_tag( const char* name, int& index_out );
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/ReadIDEAS.cpp
===================================================================
--- MOAB/trunk/src/io/ReadIDEAS.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadIDEAS.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,25 +5,27 @@
 #include "assert.h"
 
 #include "ReadIDEAS.hpp"
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "FileTokenizer.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 
-MBReaderIface* ReadIDEAS::factory( MBInterface* iface )
+namespace moab {
+
+ReaderIface* ReadIDEAS::factory( Interface* iface )
   { return new ReadIDEAS( iface ); }
 
-ReadIDEAS::ReadIDEAS(MBInterface* impl)
+ReadIDEAS::ReadIDEAS(Interface* impl)
     : MBI(impl)
 {
   void* ptr = 0;
-  impl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  impl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 
-MBErrorCode ReadIDEAS::read_tag_values( const char* /* file_name */,
+ErrorCode ReadIDEAS::read_tag_values( const char* /* file_name */,
                                         const char* /* tag_name */,
                                         const FileOptions& /* opts */,
                                         std::vector<int>& /* tag_values_out */,
@@ -34,12 +36,12 @@
 }
 
 
-MBErrorCode ReadIDEAS::load_file(const char* fname, 
-                                 const MBEntityHandle* , 
+ErrorCode ReadIDEAS::load_file(const char* fname, 
+                                 const EntityHandle* , 
                                  const FileOptions& options,
-                                 const MBReaderIface::IDTag* subset_list,
+                                 const ReaderIface::IDTag* subset_list,
                                  int subset_list_length,
-                                 const MBTag* file_id_tag ) {
+                                 const Tag* file_id_tag ) {
 
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for IDEAS." );
@@ -52,14 +54,14 @@
     return MB_FILE_DOES_NOT_EXIST;
   }
 
-  MBErrorCode rval;
+  ErrorCode rval;
 
   char line[10000];
   file.getline(line, 10000);
   std::string s = line;
   if (s.find("-1") > s.length()) return MB_FAILURE;
 
-  MBEntityHandle first_vertex = 0;
+  EntityHandle first_vertex = 0;
 
   while (! file.eof() ) {
     file.getline(line, 10000);
@@ -88,7 +90,7 @@
 
 }
 
-MBErrorCode ReadIDEAS::skip_header() {
+ErrorCode ReadIDEAS::skip_header() {
 
   // Go until finding a pair of -1 lines
   char *ctmp;
@@ -118,8 +120,8 @@
 
 
 
-MBErrorCode ReadIDEAS::create_vertices(MBEntityHandle& first_vertex,
-                                       const MBTag* file_id_tag) {
+ErrorCode ReadIDEAS::create_vertices(EntityHandle& first_vertex,
+                                       const Tag* file_id_tag) {
 
   // Read two lines: first has some data, second has coordinates
   char line1[10000], line2[10000];
@@ -127,7 +129,7 @@
   char *ctmp1, *ctmp2;
   std::string s1, s2;
 
-  MBErrorCode rval;
+  ErrorCode rval;
 
   int top_of_block = file.tellg();
   unsigned int num_verts = 0;
@@ -157,7 +159,7 @@
   if (MB_SUCCESS != rval)
     return rval;
 
-  MBRange verts;
+  Range verts;
   verts.insert( first_vertex, first_vertex + num_verts - 1 );
   
   double *x = arrays[0];
@@ -192,20 +194,20 @@
 }
 
 
-MBErrorCode ReadIDEAS::create_tetrahedral_elements(MBEntityHandle vstart,
-                                                   const MBTag* file_id_tag) {
+ErrorCode ReadIDEAS::create_tetrahedral_elements(EntityHandle vstart,
+                                                   const Tag* file_id_tag) {
 
-  MBEntityHandle connect[4];
+  EntityHandle connect[4];
   char line1[10000], line2[10000];
   int il1, il2, id = 0;
   char *ctmp1, *ctmp2;
   std::string s1, s2;
   long verts[4];
 
-  MBErrorCode rval;
-  MBEntityHandle handle;
+  ErrorCode rval;
+  EntityHandle handle;
 
-  MBTag mat_prop_tag, phys_prop_tag;
+  Tag mat_prop_tag, phys_prop_tag;
   rval = MBI->tag_create( MAT_PROP_TABLE_TAG  , sizeof(int), MB_TAG_DENSE, mat_prop_tag, 0); 
   if (MB_SUCCESS != rval && MB_ALREADY_ALLOCATED != rval) return rval;
   rval = MBI->tag_create( PHYS_PROP_TABLE_TAG , sizeof(int), MB_TAG_DENSE, phys_prop_tag, 0); 
@@ -256,3 +258,5 @@
   
   return MB_FAILURE;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadIDEAS.hpp
===================================================================
--- MOAB/trunk/src/io/ReadIDEAS.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadIDEAS.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,8 +2,8 @@
 #include <fstream>
 #include <vector>
 
-#include "MBReaderIface.hpp"
-#include "MBInterface.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/Interface.hpp"
 
 #define VERTEX_LIST       2411 
 #define MAKE_TETRAHEDRA   2412
@@ -11,23 +11,25 @@
 #define MAT_PROP_TABLE_TAG "mat_prop_table"
 #define PHYS_PROP_TABLE_TAG "phys_prop_table"
 
-class MBReadUtilIface;
+namespace moab {
 
-class ReadIDEAS : public MBReaderIface
+class ReadUtilIface;
+
+class ReadIDEAS : public ReaderIface
 {
 
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
-  MBErrorCode load_file( const char* fname, 
-			 const MBEntityHandle* meshset, 
+  ErrorCode load_file( const char* fname, 
+			 const EntityHandle* meshset, 
 			 const FileOptions&,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -35,25 +37,27 @@
                                int subset_list_length = 0 );
   
   //! Constructor
-  ReadIDEAS(MBInterface* impl = NULL);
+  ReadIDEAS(Interface* impl = NULL);
   
   //! Destructor
   virtual ~ReadIDEAS() {}
 
 protected:
   
-  MBErrorCode skip_header();
-  MBErrorCode create_vertices(MBEntityHandle& first_vertex, const MBTag* file_id_tag);
-  MBErrorCode create_tetrahedral_elements(MBEntityHandle first_vertex, const MBTag* file_id_tag);
+  ErrorCode skip_header();
+  ErrorCode create_vertices(EntityHandle& first_vertex, const Tag* file_id_tag);
+  ErrorCode create_tetrahedral_elements(EntityHandle first_vertex, const Tag* file_id_tag);
   
 private:
   
   std::ifstream file;
   
   // Read mesh interface
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
   
   // MOAB Interface
-  MBInterface* MBI;
+  Interface* MBI;
 
 };
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadMCNP5.cpp
===================================================================
--- MOAB/trunk/src/io/ReadMCNP5.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadMCNP5.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,10 +14,10 @@
  */ 
 
 #include "ReadMCNP5.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBInternals.hpp" // for MB_START_ID
-#include "MBRange.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "Internals.hpp" // for MB_START_ID
+#include "moab/Range.hpp"
 #include "FileOptions.hpp"
 
 #include <iostream>
@@ -28,35 +28,37 @@
 #include "assert.h"
 #include "math.h"
 
+namespace moab {
+
 // parameters
 const double ReadMCNP5::PI   = 3.141592653589793;
 const double ReadMCNP5::C2PI = 0.1591549430918954;
 const double ReadMCNP5::CPI  = 0.3183098861837907;
 
-MBReaderIface* ReadMCNP5::factory( MBInterface* iface ) { 
+ReaderIface* ReadMCNP5::factory( Interface* iface ) { 
   return new ReadMCNP5( iface );
 }
 
 // constructor
-ReadMCNP5::ReadMCNP5(MBInterface* impl)
+ReadMCNP5::ReadMCNP5(Interface* impl)
   : MBI(impl), fileIDTag(0) {
     assert( NULL!=impl);
     void *ptr = 0;
-    MBI->query_interface("MBReadUtilIface", &ptr);
+    MBI->query_interface("ReadUtilIface", &ptr);
     assert( NULL!=ptr );
-    readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+    readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 // destructor
 ReadMCNP5::~ReadMCNP5() {
   if (readMeshIface) {
-    MBI->release_interface("MBReadUtilIface", readMeshIface);
+    MBI->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
 
 
-MBErrorCode ReadMCNP5::read_tag_values( const char* /* file_name */,
+ErrorCode ReadMCNP5::read_tag_values( const char* /* file_name */,
                                         const char* /* tag_name */,
                                         const FileOptions& /* opts */,
                                         std::vector<int>& /* tag_values_out */,
@@ -67,13 +69,13 @@
 }
 
 
-// load the file as called by the MBInterface function
-MBErrorCode ReadMCNP5::load_file(const char                 *filename, 
-                                 const MBEntityHandle       *input_meshset, 
+// load the file as called by the Interface function
+ErrorCode ReadMCNP5::load_file(const char                 *filename, 
+                                 const EntityHandle       *input_meshset, 
                                  const FileOptions          &options,
-                                 const MBReaderIface::IDTag *subset_list,
+                                 const ReaderIface::IDTag *subset_list,
                                  int                         subset_list_length,
-                                 const MBTag                *file_id_tag) {
+                                 const Tag                *file_id_tag) {
   // at this time there is no support for reading a subset of the file
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for meshtal." );
@@ -90,7 +92,7 @@
   // Indices start with 1.
   int n_files;
   bool average = false;
-  MBErrorCode result;
+  ErrorCode result;
   if(MB_SUCCESS == options.get_int_option("AVERAGE_TALLY", n_files)) {
    
     // read the first file (but do not average -> can't average a single file)
@@ -132,21 +134,21 @@
 
 // This actually reads the file. It creates the mesh elements unless
 // the file is being averaged with a pre-existing mesh.
-MBErrorCode ReadMCNP5::load_one_file(const char           *fname,
-                                     const MBEntityHandle *input_meshset,
+ErrorCode ReadMCNP5::load_one_file(const char           *fname,
+                                     const EntityHandle *input_meshset,
                                      const FileOptions    &options,
                                      const bool           average ) {
 
   bool debug = false;
   if (debug) std::cout << "begin ReadMCNP5::load_one_file" << std::endl;
 
-  MBErrorCode result;
+  ErrorCode result;
   std::fstream file;
   file.open( fname, std::fstream::in );
   char line[10000];
 
   // create tags
-  MBTag date_and_time_tag,  
+  Tag date_and_time_tag,  
         title_tag,           
         nps_tag,  
         tally_number_tag,    
@@ -301,7 +303,7 @@
     // with a tally already existing in the MOAB instance.
     // ****************************************************************
     if (!average) {
-      MBEntityHandle tally_meshset;
+      EntityHandle tally_meshset;
       result = MBI->create_meshset(MESHSET_SET, tally_meshset);
       if(MB_SUCCESS != result) return result;
       
@@ -319,7 +321,7 @@
 
       // The only info needed to build elements is the mesh plane boundaries.
       // Build vertices...
-      MBEntityHandle start_vert = NULL;
+      EntityHandle start_vert = NULL;
       result = create_vertices( planes, 
                                 debug,
                                 start_vert, 
@@ -371,7 +373,7 @@
   // Add the new nps to the existing file's nps if we are averaging.
   // This is calculated during every tally averaging but only used after the last one.
   if (average) {
-    MBRange matching_nps_sets;
+    Range matching_nps_sets;
     result = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &nps_tag, 
                                                 0, 1, matching_nps_sets );
     if(MB_SUCCESS != result) return result;
@@ -388,16 +390,16 @@
 }
 
 // create tags needed for this reader
-MBErrorCode ReadMCNP5::create_tags( MBTag &date_and_time_tag,
-                                    MBTag &title_tag,
-                                    MBTag &nps_tag,
-                                    MBTag &tally_number_tag,
-                                    MBTag &tally_comment_tag,
-                                    MBTag &tally_particle_tag,
-                                    MBTag &tally_coord_sys_tag,
-                                    MBTag &tally_tag,
-                                    MBTag &error_tag ) {
-  MBErrorCode result;
+ErrorCode ReadMCNP5::create_tags( Tag &date_and_time_tag,
+                                    Tag &title_tag,
+                                    Tag &nps_tag,
+                                    Tag &tally_number_tag,
+                                    Tag &tally_comment_tag,
+                                    Tag &tally_particle_tag,
+                                    Tag &tally_coord_sys_tag,
+                                    Tag &tally_tag,
+                                    Tag &error_tag ) {
+  ErrorCode result;
   result = MBI->tag_create("DATE_AND_TIME_TAG", sizeof(char[100]), MB_TAG_SPARSE, 
                            MB_TYPE_OPAQUE, date_and_time_tag, 0);
   if(MB_SUCCESS!=result && MB_ALREADY_ALLOCATED!=result) return result;
@@ -428,7 +430,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::read_file_header( std::fstream      &file,
+ErrorCode ReadMCNP5::read_file_header( std::fstream      &file,
                                          bool              debug,
                                          char              date_and_time[100],  
                                          char              title[100], 
@@ -462,14 +464,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::set_header_tags( MBEntityHandle    output_meshset, 
+ErrorCode ReadMCNP5::set_header_tags( EntityHandle    output_meshset, 
                                         char              date_and_time[100],
                                         char              title[100],
                                         unsigned long int nps,
-                                        MBTag             data_and_time_tag,
-                                        MBTag             title_tag,
-                                        MBTag             nps_tag ) {
-  MBErrorCode result;
+                                        Tag             data_and_time_tag,
+                                        Tag             title_tag,
+                                        Tag             nps_tag ) {
+  ErrorCode result;
   result = MBI->tag_set_data( data_and_time_tag, &output_meshset, 1, &date_and_time);
   if(MB_SUCCESS != result) return result;
   result = MBI->tag_set_data( title_tag, &output_meshset, 1, &title);
@@ -479,7 +481,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::read_tally_header( std::fstream   &file,
+ErrorCode ReadMCNP5::read_tally_header( std::fstream   &file,
                                           bool           debug,
                                           unsigned int   &tally_number,
                                           char           tally_comment[100],
@@ -487,7 +489,7 @@
 
   // get tally number
   // Mesh Tally Number 104
-  MBErrorCode result;
+  ErrorCode result;
   char line[100];
   file.getline(line, 100);
   std::string a = line;
@@ -523,7 +525,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::get_tally_particle( std::string    a,
+ErrorCode ReadMCNP5::get_tally_particle( std::string    a,
                                            bool           debug,
                                            particle       &tally_particle ) {
   
@@ -539,13 +541,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::read_mesh_planes( std::fstream        &file, 
+ErrorCode ReadMCNP5::read_mesh_planes( std::fstream        &file, 
                                          bool                debug, 
                                          std::vector<double> planes[3], 
                                          coordinate_system   &coord_sys ) {
 
   // Tally bin boundaries:
-  MBErrorCode result;
+  ErrorCode result;
   char line[10000];
   file.getline(line, 10000);
   std::string a = line;
@@ -661,7 +663,7 @@
 }
 
 // Given a stringstream, return a vector of values in the string.
-MBErrorCode ReadMCNP5::get_mesh_plane( std::istringstream  &ss,
+ErrorCode ReadMCNP5::get_mesh_plane( std::istringstream  &ss,
                                        bool                debug, 
                                        std::vector<double> &plane) {
   double value;
@@ -675,7 +677,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::read_element_values_and_errors( 
+ErrorCode ReadMCNP5::read_element_values_and_errors( 
                                             std::fstream        &file,
                                             bool                debug,
                                             std::vector<double> planes[3],
@@ -726,16 +728,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::set_tally_tags( MBEntityHandle    tally_meshset,
+ErrorCode ReadMCNP5::set_tally_tags( EntityHandle    tally_meshset,
                                        unsigned int      tally_number,
                                        char              tally_comment[100],
                                        particle          tally_particle,
                                        coordinate_system tally_coord_sys,
-                                       MBTag             tally_number_tag, 
-                                       MBTag             tally_comment_tag,
-                                       MBTag             tally_particle_tag,
-                                       MBTag             tally_coord_sys_tag ) {
-  MBErrorCode result;
+                                       Tag             tally_number_tag, 
+                                       Tag             tally_comment_tag,
+                                       Tag             tally_particle_tag,
+                                       Tag             tally_coord_sys_tag ) {
+  ErrorCode result;
   result = MBI->tag_set_data( tally_number_tag,    &tally_meshset, 1, &tally_number);
   if(MB_SUCCESS != result) return result;
   result = MBI->tag_set_data( tally_comment_tag,   &tally_meshset, 1, &tally_comment);
@@ -747,14 +749,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::create_vertices( std::vector<double> planes[3],
+ErrorCode ReadMCNP5::create_vertices( std::vector<double> planes[3],
                                         bool                debug,
-                                        MBEntityHandle      &start_vert,
+                                        EntityHandle      &start_vert,
                                         coordinate_system   coord_sys,
-                                        MBEntityHandle      tally_meshset ) {
+                                        EntityHandle      tally_meshset ) {
                                          
   // The only info needed to build elements is the mesh plane boundaries.
-  MBErrorCode result;
+  ErrorCode result;
   int n_verts = planes[0].size() * planes[1].size() * planes[2].size();
   if (debug) std::cout << "n_verts=" << n_verts << std::endl;
   std::vector<double*> coord_arrays(3);
@@ -782,7 +784,7 @@
       }
     }
   }
-  MBRange vert_range(start_vert, start_vert+n_verts-1);
+  Range vert_range(start_vert, start_vert+n_verts-1);
   result = MBI->add_entities( tally_meshset, vert_range );
   if(MB_SUCCESS != result) return result;
   
@@ -796,23 +798,23 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::create_elements( bool                debug, 
+ErrorCode ReadMCNP5::create_elements( bool                debug, 
                                         std::vector<double> planes[3],
                                         unsigned int        n_chopped_x0_planes,
                                         unsigned int        n_chopped_x2_planes,
-                                        MBEntityHandle      start_vert,
+                                        EntityHandle      start_vert,
                                         double              *values,
                                         double              *errors,
-                                        MBTag               tally_tag,
-                                        MBTag               error_tag,
-                                        MBEntityHandle      tally_meshset,
+                                        Tag               tally_tag,
+                                        Tag               error_tag,
+                                        EntityHandle      tally_meshset,
                                         coordinate_system   tally_coord_sys ) {
-  MBErrorCode result;
+  ErrorCode result;
   unsigned int index;
-  MBEntityHandle start_element = 0;
+  EntityHandle start_element = 0;
   unsigned int n_elements = (planes[0].size()-1) * (planes[1].size()-1) 
                                                  * (planes[2].size()-1);
-  MBEntityHandle *connect;
+  EntityHandle *connect;
   result = readMeshIface->get_element_array( n_elements, 8, MBHEX, MB_START_ID, 
                                              start_element, connect );
   if(MB_SUCCESS != result) return result;
@@ -858,7 +860,7 @@
   if (counter != n_elements) std::cout << "counter=" << counter << " n_elements=" 
                                        << n_elements << std::endl;
 
-  MBRange element_range(start_element, start_element+n_elements-1);
+  Range element_range(start_element, start_element+n_elements-1);
   result = MBI->tag_set_data(tally_tag, element_range, values);
   if(MB_SUCCESS != result) return result;
   result = MBI->tag_set_data(error_tag, element_range, errors);
@@ -881,23 +883,23 @@
 
 // Average a tally that was recently read in with one that alread exists in
 // the interface. Only the existing values will be updated.
-MBErrorCode ReadMCNP5::average_with_existing_tally( bool         debug,
+ErrorCode ReadMCNP5::average_with_existing_tally( bool         debug,
                                                     unsigned long int &new_nps,
                                                     unsigned long int nps1,
                                                     unsigned int tally_number,
-                                                    MBTag        tally_number_tag,
-                                                    MBTag        nps_tag,
-                                                    MBTag        tally_tag,
-                                                    MBTag        error_tag,
+                                                    Tag        tally_number_tag,
+                                                    Tag        nps_tag,
+                                                    Tag        tally_tag,
+                                                    Tag        error_tag,
                                                     double       *values1,
                                                     double       *errors1,
                                                     unsigned int n_elements ) {
     
   // get the tally number
-  MBErrorCode result;
+  ErrorCode result;
 
   // match the tally number with one from the existing meshtal file
-  MBRange matching_tally_number_sets;
+  Range matching_tally_number_sets;
   const void* const tally_number_val[] = {&tally_number};
   result = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &tally_number_tag, 
                                               tally_number_val, 1, 
@@ -908,18 +910,18 @@
   assert(1 == matching_tally_number_sets.size());
 
   // identify which of the meshsets is existing
-  MBEntityHandle existing_meshset;
+  EntityHandle existing_meshset;
   existing_meshset = matching_tally_number_sets.front();
 
   // get the existing elements from the set
-  MBRange existing_elements;
+  Range existing_elements;
   result = MBI->get_entities_by_type( existing_meshset, MBHEX, existing_elements );
   if(MB_SUCCESS != result) return result;
   assert(existing_elements.size() == n_elements);
 
   // get the nps of the existing and new tally
   unsigned long int nps0;
-  MBRange sets_with_this_tag;
+  Range sets_with_this_tag;
   result = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &nps_tag, 0, 1, 
                                               sets_with_this_tag);
   if(MB_SUCCESS != result) return result;
@@ -956,7 +958,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadMCNP5::transform_point_to_cartesian(double *in, double *out, 
+ErrorCode ReadMCNP5::transform_point_to_cartesian(double *in, double *out, 
                                                     coordinate_system coord_sys ) {
   // Transform coordinate system
   switch(coord_sys) {
@@ -984,7 +986,7 @@
 
 // Average two tally values and their error. Return average values in the
 // place of first tally values.
-MBErrorCode ReadMCNP5::average_tally_values(const unsigned long int nps0, 
+ErrorCode ReadMCNP5::average_tally_values(const unsigned long int nps0, 
                                             const unsigned long int nps1,
                                             double                  *values0,
                                             const double            *values1,
@@ -1010,3 +1012,5 @@
   // REMEMBER TO UPDATE NPS0 = NPS0 + NPS1 after this
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadMCNP5.hpp
===================================================================
--- MOAB/trunk/src/io/ReadMCNP5.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadMCNP5.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,30 +37,32 @@
  *       ERROR_TAG
  */
 
-#include "MBInterface.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReaderIface.hpp"
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <vector>
 
-class MBReadUtilIface;
+namespace moab {
 
-class ReadMCNP5 : public MBReaderIface
+class ReadUtilIface;
+
+class ReadMCNP5 : public ReaderIface
 {
 
 public:
   // factory method
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
   
-  MBErrorCode load_file( const char*                 fname,
-                         const MBEntityHandle        *input_meshset,
+  ErrorCode load_file( const char*                 fname,
+                         const EntityHandle        *input_meshset,
                          const FileOptions           &options,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int                         subset_list_length = 0,
-                         const MBTag*                file_id_tag = 0 );
+                         const Tag*                file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char*        file_name,
+  ErrorCode read_tag_values( const char*        file_name,
                                const char*        tag_name,
                                const FileOptions& opts,
                                std::vector<int>&  tag_values_out,
@@ -68,7 +70,7 @@
                                int                subset_list_length = 0 );
 
   // constructor
-  ReadMCNP5(MBInterface* impl = NULL);
+  ReadMCNP5(Interface* impl = NULL);
 
   // destructor
   virtual ~ReadMCNP5();
@@ -90,64 +92,64 @@
                   ELECTRON };
   
   // read mesh interface
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
   
   // MOAB Interface
-  MBInterface* MBI;
+  Interface* MBI;
   
-  const MBTag* fileIDTag;
+  const Tag* fileIDTag;
   int nodeId, elemId;
 
   // reads the meshtal file
-  MBErrorCode load_one_file( const char           *fname,
-                             const MBEntityHandle *input_meshset,
+  ErrorCode load_one_file( const char           *fname,
+                             const EntityHandle *input_meshset,
                              const FileOptions    &options,
                              const bool           average );
   
-  MBErrorCode create_tags( MBTag &date_and_time_tag,  
-                           MBTag &title_tag,
-                           MBTag &nps_tag, 
-                           MBTag &tally_number_tag,   
-                           MBTag &tally_comment_tag,
-                           MBTag &tally_particle_tag, 
-                           MBTag &tally_coord_sys_tag,
-                           MBTag &tally_tag,          
-                           MBTag &error_tag );
+  ErrorCode create_tags( Tag &date_and_time_tag,  
+                           Tag &title_tag,
+                           Tag &nps_tag, 
+                           Tag &tally_number_tag,   
+                           Tag &tally_comment_tag,
+                           Tag &tally_particle_tag, 
+                           Tag &tally_coord_sys_tag,
+                           Tag &tally_tag,          
+                           Tag &error_tag );
 
-  MBErrorCode read_file_header( std::fstream      &file,
+  ErrorCode read_file_header( std::fstream      &file,
                                 bool              debug,
                                 char              date_and_time[100], 
                                 char              title[100], 
                                 unsigned long int &nps );
 
-  MBErrorCode set_header_tags( MBEntityHandle             output_meshset, 
+  ErrorCode set_header_tags( EntityHandle             output_meshset, 
                                         char              date_and_time[100],
                                         char              title[100],
                                         unsigned long int nps,
-                                        MBTag             data_and_time_tag,
-                                        MBTag             title_tag,
-                                        MBTag             nps_tag );
+                                        Tag             data_and_time_tag,
+                                        Tag             title_tag,
+                                        Tag             nps_tag );
 
-  MBErrorCode read_tally_header( std::fstream &file,
+  ErrorCode read_tally_header( std::fstream &file,
                                  bool         debug,
                                  unsigned int &tally_number,
                                  char         tally_comment[100],
                                  particle     &tally_particle );
 
-  MBErrorCode get_tally_particle( std::string a,
+  ErrorCode get_tally_particle( std::string a,
                                   bool        debug,
                                   particle    &tally_particle );
 
-  MBErrorCode read_mesh_planes( std::fstream         &file, 
+  ErrorCode read_mesh_planes( std::fstream         &file, 
                                 bool                 debug, 
                                 std::vector<double>  planes[3], 
                                 coordinate_system    &coord_sys);
 
-  MBErrorCode get_mesh_plane( std::istringstream  &ss, 
+  ErrorCode get_mesh_plane( std::istringstream  &ss, 
                               bool                debug, 
                               std::vector<double> &plane);
 
-  MBErrorCode read_element_values_and_errors( std::fstream        &file,
+  ErrorCode read_element_values_and_errors( std::fstream        &file,
                                               bool                debug,
                                               std::vector<double> planes[3],
                                               unsigned int        n_chopped_x0_planes,
@@ -156,51 +158,51 @@
                                               double              values[],
                                               double              errors[] );
 
-  MBErrorCode set_tally_tags( MBEntityHandle    tally_meshset,
+  ErrorCode set_tally_tags( EntityHandle    tally_meshset,
                               unsigned int      tally_number,
                               char              tally_comment[100],
                               particle          tally_particle,
                               coordinate_system tally_coord_sys,
-                              MBTag             tally_number_tag, 
-                              MBTag             tally_comment_tag,
-                              MBTag             tally_particle_tag,
-                              MBTag             tally_coord_sys_tag );
+                              Tag             tally_number_tag, 
+                              Tag             tally_comment_tag,
+                              Tag             tally_particle_tag,
+                              Tag             tally_coord_sys_tag );
 
-  MBErrorCode create_vertices( std::vector<double> planes[3],
+  ErrorCode create_vertices( std::vector<double> planes[3],
                                bool                debug,
-                               MBEntityHandle      &start_vert,
+                               EntityHandle      &start_vert,
                                coordinate_system   coord_sys,
-                               MBEntityHandle      tally_meshset );
+                               EntityHandle      tally_meshset );
  
-  MBErrorCode create_elements( bool                debug, 
+  ErrorCode create_elements( bool                debug, 
                                std::vector<double> planes[3],
                                unsigned int        n_chopped_x0_planes,
                                unsigned int        n_chopped_x2_planes,
-                               MBEntityHandle      start_vert,
+                               EntityHandle      start_vert,
                                double              values[],
                                double              errors[],
-                               MBTag               tally_tag,
-                               MBTag               error_tag,
-                               MBEntityHandle      tally_meshset,
+                               Tag               tally_tag,
+                               Tag               error_tag,
+                               EntityHandle      tally_meshset,
                                coordinate_system   tally_coord_sys );
 
-  MBErrorCode average_with_existing_tally( bool              debug,
+  ErrorCode average_with_existing_tally( bool              debug,
                                            unsigned long int &new_nps,
                                            unsigned long int nps,
                                            unsigned int      tally_number,
-                                           MBTag             tally_number_tag,
-                                           MBTag             nps_tag,
-                                           MBTag             tally_tag,
-                                           MBTag             error_tag,
+                                           Tag             tally_number_tag,
+                                           Tag             nps_tag,
+                                           Tag             tally_tag,
+                                           Tag             error_tag,
                                            double            values[],
                                            double            errors[],
                                            unsigned int      n_elements );
   
-  MBErrorCode transform_point_to_cartesian(double *in, 
+  ErrorCode transform_point_to_cartesian(double *in, 
                                            double *out, 
                                            coordinate_system coord_sys);
 
-  MBErrorCode average_tally_values(const unsigned long int nps0, 
+  ErrorCode average_tally_values(const unsigned long int nps0, 
                                    const unsigned long int nps1,
                                    double                  *values0,
                                    const double            *values1,
@@ -208,3 +210,5 @@
                                    const double            *errors1,
                                    const unsigned long int n_values);
 };
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadNASTRAN.cpp
===================================================================
--- MOAB/trunk/src/io/ReadNASTRAN.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadNASTRAN.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -23,38 +23,40 @@
 #include <assert.h>
 #include <cmath>
 
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBInternals.hpp" // for MB_START_ID
-#include "MBRange.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "Internals.hpp" // for MB_START_ID
+#include "moab/Range.hpp"
 #include "FileOptions.hpp"
 #include "FileTokenizer.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 
-MBReaderIface* ReadNASTRAN::factory( MBInterface* iface ) { 
+namespace moab {
+
+ReaderIface* ReadNASTRAN::factory( Interface* iface ) { 
   return new ReadNASTRAN( iface );
 }
 
 // constructor
-ReadNASTRAN::ReadNASTRAN(MBInterface* impl)
+ReadNASTRAN::ReadNASTRAN(Interface* impl)
   : MBI(impl) {
     assert(NULL != impl);
     void *ptr = 0;
-    MBI->query_interface("MBReadUtilIface", &ptr);
+    MBI->query_interface("ReadUtilIface", &ptr);
     assert(NULL != ptr);
-    readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+    readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 // destructor
 ReadNASTRAN::~ReadNASTRAN() {
   if (readMeshIface) {
-    MBI->release_interface("MBReadUtilIface", readMeshIface);
+    MBI->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
 
-MBErrorCode ReadNASTRAN::read_tag_values( const char*        file_name,
+ErrorCode ReadNASTRAN::read_tag_values( const char*        file_name,
                                           const char*        tag_name,
                                           const FileOptions& opts,
                                           std::vector<int>&  tag_values_out,
@@ -64,13 +66,13 @@
   return MB_NOT_IMPLEMENTED;
 }
 
-// load the file as called by the MBInterface function
-MBErrorCode ReadNASTRAN::load_file(const char                  *filename, 
-                                   const MBEntityHandle        *, 
+// load the file as called by the Interface function
+ErrorCode ReadNASTRAN::load_file(const char                  *filename, 
+                                   const EntityHandle        *, 
                                    const FileOptions           &options,
-                                   const MBReaderIface::IDTag  *subset_list,
+                                   const ReaderIface::IDTag  *subset_list,
                                    int                         subset_list_length,
-                                   const MBTag*                file_id_tag) {
+                                   const Tag*                file_id_tag) {
   // at this time there is no support for reading a subset of the file
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for NASTRAN." );
@@ -82,7 +84,7 @@
 
   bool debug = false;
   if (debug) std::cout << "begin ReadNASTRAN::load_file" << std::endl;
-  MBErrorCode result;
+  ErrorCode result;
 
   // Count the entities of each type in the file. This is used to allocate the node array. 
   int entity_count[MBMAXTYPE];
@@ -110,7 +112,7 @@
     if(MB_SUCCESS != result) return result;
 
     // Process the tokens of the line. The first token describes the entity type.
-    MBEntityType type;
+    EntityType type;
     result = determine_entity_type( tokens.front(), type );
     if(MB_SUCCESS != result) return result;
     entity_count[type]++;
@@ -124,10 +126,10 @@
   }
   
   // Keep list of material sets
-  std::vector<MBRange> materials;
+  std::vector<Range> materials;
 
   // Now that the number of vertices is known, create the vertices.
-  MBEntityHandle start_vert = NULL;
+  EntityHandle start_vert = NULL;
   std::vector<double*> coord_arrays(3);
   result = readMeshIface->get_node_arrays( 3, entity_count[0], MB_START_ID,
 					   start_vert, coord_arrays );
@@ -151,7 +153,7 @@
     if(MB_SUCCESS != result) return result;
 
     // Process the tokens of the line. The first token describes the entity type.
-    MBEntityType type;
+    EntityType type;
     result = determine_entity_type( tokens.front(), type );
     if(MB_SUCCESS != result) return result;
 
@@ -188,7 +190,7 @@
      large field: 1x8, 4x16, 1x8. Field 1 must have an asterisk following the character string
      free field: each line entry must be separated by a comma
      Implementation tries to avoid more searches than necessary. */
-MBErrorCode ReadNASTRAN::determine_line_format( const std::string line, 
+ErrorCode ReadNASTRAN::determine_line_format( const std::string line, 
                                                   line_format &format ) {
   std::string::size_type found_asterisk = line.find("*");
   if(std::string::npos != found_asterisk) {
@@ -207,7 +209,7 @@
   }
 
   /* Tokenize the line. Continue-lines have not been implemented. */
-MBErrorCode ReadNASTRAN::tokenize_line(const std::string line, const line_format format, 
+ErrorCode ReadNASTRAN::tokenize_line(const std::string line, const line_format format, 
 				       std::vector<std::string> &tokens ) { 
   size_t line_size = line.size();
   switch(format) {
@@ -233,8 +235,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNASTRAN::determine_entity_type( const std::string first_token, 
-                                                  MBEntityType &type ) {
+ErrorCode ReadNASTRAN::determine_entity_type( const std::string first_token, 
+                                                  EntityType &type ) {
   if     (0==first_token.compare("GRID    ")) type = MBVERTEX;
   else if(0==first_token.compare("CTETRA  ")) type = MBTET;
   else if(0==first_token.compare("CPENTA  ")) type = MBPRISM;
@@ -259,7 +261,7 @@
    has the coordinates: ( 3.980454, 6.9052e-1, 5.6008e-1 )
    GRID      200005       04.004752-3.985-15.4955-1  
    has the coordinates: ( 4.004752, -3.985e-1, 5.4955e-1 ) */
-MBErrorCode ReadNASTRAN::get_real( const std::string token, double &real ) {
+ErrorCode ReadNASTRAN::get_real( const std::string token, double &real ) {
   std::string significand = token;
   std::string exponent = "0";
 
@@ -312,12 +314,12 @@
 
 /* It has been determined that this line is a vertex. Read the rest of
    the line and create the vertex. */
-MBErrorCode ReadNASTRAN::read_node( const std::vector<std::string> tokens, 
+ErrorCode ReadNASTRAN::read_node( const std::vector<std::string> tokens, 
 				    const bool debug, 
 				    double* coords[3],
                                     int& id ) {
   // read the node's id (unique)
-  MBErrorCode result;
+  ErrorCode result;
   id = atoi(tokens[1].c_str());
 
   // read the node's coordinate system number
@@ -342,23 +344,23 @@
 /* The type of element has already been identified. Read the rest of the
    line and create the element. Assume that all of the nodes have already
    been created. */
-MBErrorCode ReadNASTRAN::read_element( const std::vector<std::string> tokens, 
-				       std::vector<MBRange> &materials,
-				       const MBEntityType element_type,
+ErrorCode ReadNASTRAN::read_element( const std::vector<std::string> tokens, 
+				       std::vector<Range> &materials,
+				       const EntityType element_type,
 				       const bool debug ) {
 
   // read the element's id (unique) and material set
-  MBErrorCode result;
+  ErrorCode result;
   int id = atoi(tokens[1].c_str());    
   int material = atoi(tokens[2].c_str());
   
     // Resize materials list if necessary.  This code is somewhat complicated
-    // so as to avoid copying of MBRanges
+    // so as to avoid copying of Ranges
   if (material >= (int)materials.size()) {
     if ((int)materials.capacity() < material)
       materials.resize( material+1 );
     else {
-      std::vector<MBRange> new_mat( material+1 );
+      std::vector<Range> new_mat( material+1 );
       for (size_t i = 0; i < materials.size(); ++i)
         new_mat[i].swap( materials[i] );
       materials.swap( new_mat );
@@ -367,8 +369,8 @@
 
   // the size of the connectivity array depends on the element type
   int n_conn = MBCN::VerticesPerEntity(element_type);
-  MBEntityHandle conn_verts[27];
-  assert(n_conn <= (int)(sizeof(conn_verts)/sizeof(MBEntityHandle)));
+  EntityHandle conn_verts[27];
+  assert(n_conn <= (int)(sizeof(conn_verts)/sizeof(EntityHandle)));
   
   // read the connected node ids from the file
   for(int i=0; i<n_conn; i++) {
@@ -379,7 +381,7 @@
   }
 
   // Create the element and set the global id from the NASTRAN file
-  MBEntityHandle element;
+  EntityHandle element;
   result = MBI->create_element( element_type, conn_verts, n_conn, element );
   if(MB_SUCCESS != result) return result;
   elemIdMap.insert( id, element, 1 );
@@ -389,10 +391,10 @@
 }
 
 
-MBErrorCode ReadNASTRAN::create_materials( const std::vector<MBRange>& materials )
+ErrorCode ReadNASTRAN::create_materials( const std::vector<Range>& materials )
 {
-  MBErrorCode result;
-  MBTag material_tag;
+  ErrorCode result;
+  Tag material_tag;
   result = MBI->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_DENSE, 
                            MB_TYPE_INTEGER, material_tag, 0);
   if(MB_SUCCESS!=result && MB_ALREADY_ALLOCATED!=result) return result;
@@ -405,7 +407,7 @@
       // created new by only merging with existing in current file set,
       // so do the same here. - j.kraftcheck
       
-    MBEntityHandle handle;
+    EntityHandle handle;
     result = MBI->create_meshset( MESHSET_SET, handle );
     if (MB_SUCCESS != result)
       return result;
@@ -423,22 +425,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNASTRAN::assign_ids( const MBTag* file_id_tag )
+ErrorCode ReadNASTRAN::assign_ids( const Tag* file_id_tag )
 {
 
   // create tag
-  MBErrorCode result;
-  MBTag id_tag;
+  ErrorCode result;
+  Tag id_tag;
   result = MBI->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, 
                            MB_TYPE_INTEGER, id_tag, 0);
   if(MB_SUCCESS!=result && MB_ALREADY_ALLOCATED!=result) return result;
 
-  RangeMap<int,MBEntityHandle>::iterator i;
+  RangeMap<int,EntityHandle>::iterator i;
   std::vector<int> ids;
   for (int t = 0; t < 2; ++t) {
-    RangeMap<int,MBEntityHandle>& fileIdMap = t ? elemIdMap : nodeIdMap;
+    RangeMap<int,EntityHandle>& fileIdMap = t ? elemIdMap : nodeIdMap;
     for (i = fileIdMap.begin(); i != fileIdMap.end(); ++i) {
-      MBRange range( i->value, i->value + i->count - 1 );
+      Range range( i->value, i->value + i->count - 1 );
 
       result = readMeshIface->assign_ids( id_tag, range, i->begin );
       if (MB_SUCCESS != result)
@@ -454,3 +456,5 @@
   
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadNASTRAN.hpp
===================================================================
--- MOAB/trunk/src/io/ReadNASTRAN.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadNASTRAN.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -36,33 +36,35 @@
 #include <sstream>
 #include <vector>
 
-#include "MBInterface.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReaderIface.hpp"
 #include "FileTokenizer.hpp"
-#include "RangeMap.hpp"
+#include "moab/RangeMap.hpp"
 
-class MBReadUtilIface;
+namespace moab {
 
-class ReadNASTRAN : public MBReaderIface
+class ReadUtilIface;
+
+class ReadNASTRAN : public ReaderIface
 {
 
 public:
   // factory method
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
   
-  MBErrorCode load_file( const char                  *filename,
-                         const MBEntityHandle        *file_set,
+  ErrorCode load_file( const char                  *filename,
+                         const EntityHandle        *file_set,
                          const FileOptions           &options,
-                         const MBReaderIface::IDTag  *subset_list = 0,
+                         const ReaderIface::IDTag  *subset_list = 0,
                          int                         subset_list_length = 0,
-                         const MBTag                 *file_id_tag = 0 );
+                         const Tag                 *file_id_tag = 0 );
   // constructor
-  ReadNASTRAN(MBInterface* impl = NULL);
+  ReadNASTRAN(Interface* impl = NULL);
 
   // destructor
   virtual ~ReadNASTRAN();
 
-  MBErrorCode read_tag_values( const char         *file_name,
+  ErrorCode read_tag_values( const char         *file_name,
 			       const char         *tag_name,
 			       const FileOptions  &opts,
 			       std::vector<int>   &tag_values_out,
@@ -73,40 +75,43 @@
   
 private:  
   // read mesh interface
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
   
   // MOAB Interface
-  MBInterface* MBI;
+  Interface* MBI;
   
-  RangeMap<int, MBEntityHandle> nodeIdMap, elemIdMap;
+  RangeMap<int, EntityHandle> nodeIdMap, elemIdMap;
 
   enum line_format { SMALL_FIELD,                     
                      LARGE_FIELD,                 
                      FREE_FIELD }; 
 
-  MBErrorCode determine_line_format( const std::string line, 
+  ErrorCode determine_line_format( const std::string line, 
                                      line_format &format );
   
-  MBErrorCode tokenize_line( const std::string line, 
+  ErrorCode tokenize_line( const std::string line, 
                              const line_format format,
                              std::vector<std::string> &tokens );  
 
-  MBErrorCode determine_entity_type( const std::string token, MBEntityType &type); 
+  ErrorCode determine_entity_type( const std::string token, EntityType &type); 
 
-  MBErrorCode get_real( const std::string, double &real );
+  ErrorCode get_real( const std::string, double &real );
 
-  MBErrorCode read_node(const std::vector<std::string> tokens, 
+  ErrorCode read_node(const std::vector<std::string> tokens, 
                         const bool           debug, 
                         double*              coord_arrays[3], 
                         int                  &node_id);
 
-  MBErrorCode read_element(const std::vector<std::string> tokens, 
-                           std::vector<MBRange>           &materials,
-                           const MBEntityType             element_type,
+  ErrorCode read_element(const std::vector<std::string> tokens, 
+                           std::vector<Range>           &materials,
+                           const EntityType             element_type,
                            const bool                     debug );
 
-  MBErrorCode create_materials( const std::vector<MBRange> &materials );
+  ErrorCode create_materials( const std::vector<Range> &materials );
 
-  MBErrorCode assign_ids( const MBTag* file_id_tag );
+  ErrorCode assign_ids( const Tag* file_id_tag );
 };
+
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/src/io/ReadNCDF.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadNCDF.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -31,18 +31,20 @@
 #include <sstream>
 #include <map>
 
-#include "MBCN.hpp"
-#include "MBRange.hpp"
-#include "MBInterface.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/Range.hpp"
+#include "moab/Interface.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInternals.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "Internals.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "exodus_order.h"
 #include "FileOptions.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBCartVect.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/CartVect.hpp"
 
+namespace moab {
+
 #define INS_ID(stringvar, prefix, id) \
           sprintf(stringvar, prefix, id)
           
@@ -67,18 +69,18 @@
             val = ncdim->size();\
           } else val = 0;
 
-MBReaderIface* ReadNCDF::factory( MBInterface* iface )
+ReaderIface* ReadNCDF::factory( Interface* iface )
   { return new ReadNCDF( iface ); }
 
-ReadNCDF::ReadNCDF(MBInterface* impl)
+ReadNCDF::ReadNCDF(Interface* impl)
     : mdbImpl(impl), max_line_length(-1), max_str_length(-1)
 {
   assert(impl != NULL);
   reset();
   
   void* ptr = 0;
-  impl->query_interface( "MBReadUtilIface", &ptr );
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  impl->query_interface( "ReadUtilIface", &ptr );
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   mMaterialSetTag  = 0;
@@ -91,7 +93,7 @@
 
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, 
                               sizeof(int), 
@@ -176,12 +178,12 @@
 
 ReadNCDF::~ReadNCDF() 
 {
-  std::string iface_name = "MBReadUtilIface";
+  std::string iface_name = "ReadUtilIface";
   mdbImpl->release_interface(iface_name, readMeshIface);
 }
   
 
-MBErrorCode ReadNCDF::read_tag_values(const char* file_name,
+ErrorCode ReadNCDF::read_tag_values(const char* file_name,
                                       const char* tag_name,
                                       const FileOptions& opts,
                                       std::vector<int>& id_array,
@@ -204,7 +206,7 @@
   std::auto_ptr<NcFile> deleter(ncFile);
 
     // 1. Read the header
-  MBErrorCode rval = read_exodus_header( );
+  ErrorCode rval = read_exodus_header( );
   if (MB_FAILURE == rval) 
     return rval;
   
@@ -254,14 +256,14 @@
 
 
 
-MBErrorCode ReadNCDF::load_file(const char *exodus_file_name,
-                                const MBEntityHandle* file_set,
+ErrorCode ReadNCDF::load_file(const char *exodus_file_name,
+                                const EntityHandle* file_set,
                                 const FileOptions& opts,
-                                const MBReaderIface::IDTag* subset_list,
+                                const ReaderIface::IDTag* subset_list,
                                 int subset_list_length,
-                                const MBTag* file_id_tag)
+                                const Tag* file_id_tag)
 {
-  MBErrorCode status;
+  ErrorCode status;
 
   int num_blocks = 0;
   const int* blocks_to_load = 0;
@@ -282,7 +284,7 @@
     // the actual work
   
   //See if opts has tdata.
-  MBErrorCode rval;
+  ErrorCode rval;
   std::string s;
   rval = opts.get_str_option("tdata", s ); 
   if(MB_SUCCESS == rval && !s.empty())
@@ -347,7 +349,7 @@
 
 
 
-MBErrorCode ReadNCDF::read_exodus_header()
+ErrorCode ReadNCDF::read_exodus_header()
 {
   CPU_WORD_SIZE = sizeof(double);  // With ExodusII version 2, all floats
   IO_WORD_SIZE = sizeof(double);   // should be changed to doubles
@@ -400,7 +402,7 @@
   return MB_SUCCESS;
 }
  
-MBErrorCode ReadNCDF::read_nodes(const MBTag* file_id_tag)
+ErrorCode ReadNCDF::read_nodes(const Tag* file_id_tag)
 {
 
     // read the nodes into memory
@@ -410,7 +412,7 @@
   // create a sequence to hold the node coordinates
   // get the current number of entities and start at the next slot
 
-  MBEntityHandle node_handle = 0;
+  EntityHandle node_handle = 0;
   std::vector<double*> arrays;
   readMeshIface->get_node_arrays(3, numberNodes_loading, 
       MB_START_ID, node_handle, arrays);
@@ -459,7 +461,7 @@
   }
   
   if (file_id_tag) {
-    MBRange nodes;
+    Range nodes;
     nodes.insert( node_handle, node_handle + numberNodes_loading - 1 );
     readMeshIface->assign_ids( *file_id_tag, nodes, vertexOffset );
   }
@@ -467,7 +469,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNCDF::read_block_headers(const int *blocks_to_load,
+ErrorCode ReadNCDF::read_block_headers(const int *blocks_to_load,
                                            const int num_blocks)
 {
      
@@ -563,7 +565,7 @@
   return false;
 }
 
-MBErrorCode ReadNCDF::read_elements(const MBTag* file_id_tag)
+ErrorCode ReadNCDF::read_elements(const Tag* file_id_tag)
 {
     // read in elements
   
@@ -591,7 +593,7 @@
 
     // get some information about this block
     int block_id = (*this_it).blockId;
-    MBEntityHandle *conn = 0;
+    EntityHandle *conn = 0;
 
       // get the ncdf connect variable and the element type
     INS_ID(temp_string, "connect%d", block_seq_id);
@@ -615,7 +617,7 @@
     
     int verts_per_element = ExoIIUtil::VerticesPerElement[(*this_it).elemType];
     int number_nodes = (*this_it).numElements*verts_per_element;
-    const MBEntityType mb_type = ExoIIUtil::ExoIIElementMBEntity[(*this_it).elemType];
+    const EntityType mb_type = ExoIIUtil::ExoIIElementMBEntity[(*this_it).elemType];
 
     // allocate an array to read in connectivity data
     readMeshIface->get_element_array(
@@ -627,17 +629,17 @@
         conn);
         
         // create a range for this sequence of elements
-      MBEntityHandle start_range, end_range;
+      EntityHandle start_range, end_range;
       start_range = (*this_it).startMBId;
       end_range   = start_range + (*this_it).numElements-1;
 
-      MBRange new_range(start_range, end_range);
-      //MBRange<MBEntityHandle> new_range((*this_it).startMBId, 
+      Range new_range(start_range, end_range);
+      //Range<EntityHandle> new_range((*this_it).startMBId, 
       //                                  (*this_it).startMBId+(*this_it).numElements-1);
     
         // create a MBSet for this block and set the material tag
 
-      MBEntityHandle ms_handle;
+      EntityHandle ms_handle;
       if( mdbImpl->create_meshset( MESHSET_SET | MESHSET_TRACK_OWNER, ms_handle ) != MB_SUCCESS)
         return MB_FAILURE;
 
@@ -650,13 +652,13 @@
         return MB_FAILURE;
       
     // just a check because the following code won't work if this case fails
-    assert(sizeof(MBEntityHandle) >= sizeof(int));
+    assert(sizeof(EntityHandle) >= sizeof(int));
 
     // tmp_ptr is of type int* and points at the same place as conn
     int* tmp_ptr = reinterpret_cast<int*>(conn);
     
     // read the connetivity into that memory,  this will take only part of the array
-    // 1/2 if sizeof(MBEntityHandle) == 64 bits.
+    // 1/2 if sizeof(EntityHandle) == 64 bits.
     NcBool status = temp_var->get(tmp_ptr, this_it->numElements, verts_per_element);
     if (status == 0) {
       readMeshIface->report_error("MBCN:: Problem getting connectivity.");
@@ -671,13 +673,13 @@
         return MB_FAILURE;
       }
       nodesInLoadedBlocks[tmp_ptr[i]] = 1;
-      conn[i] = static_cast<MBEntityHandle>(tmp_ptr[i]) + vertexOffset;
+      conn[i] = static_cast<EntityHandle>(tmp_ptr[i]) + vertexOffset;
     }
     
     // Adjust connectivity order if necessary
     const int* reorder = exodus_elem_order_map[mb_type][verts_per_element];
     if (reorder)
-      MBReadUtilIface::reorder( reorder, conn, this_it->numElements, verts_per_element );
+      ReadUtilIface::reorder( reorder, conn, this_it->numElements, verts_per_element );
     
 
       
@@ -699,7 +701,7 @@
       
       
     if (file_id_tag) {
-      MBRange range;
+      Range range;
       range.insert( this_it->startMBId, this_it->startMBId + this_it->numElements - 1 );
       readMeshIface->assign_ids( *file_id_tag, range, this_it->startExoId );
     }
@@ -708,7 +710,7 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode ReadNCDF::read_global_ids()
+ErrorCode ReadNCDF::read_global_ids()
 {
     // read in the map from the exodus file
   int* ptr = new int [numberElements_loading];
@@ -734,8 +736,8 @@
     {
       if (iter->startMBId != 0)
       {
-        MBRange range(iter->startMBId, iter->startMBId+iter->numElements-1);
-        MBErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
+        Range range(iter->startMBId, iter->startMBId+iter->numElements-1);
+        ErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
                                                   range, &ptr[ptr_pos]);
         if (error != MB_SUCCESS)
         {
@@ -768,9 +770,9 @@
       delete [] ptr;
       return MB_FAILURE;
     } 
-    MBRange range(MB_START_ID+vertexOffset, 
+    Range range(MB_START_ID+vertexOffset, 
                   MB_START_ID+vertexOffset+numberNodes_loading-1);
-    MBErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
+    ErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
                                               range, &ptr[0]);
     if (MB_SUCCESS != error)
       readMeshIface->report_error("ReadNCDF:: Problem setting node global ids.");
@@ -781,7 +783,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNCDF::read_nodesets() 
+ErrorCode ReadNCDF::read_nodesets() 
 {
     // read in the nodesets for the model
 
@@ -856,17 +858,17 @@
     }
 
       // Maybe there is already a nodesets meshset here we can append to 
-    MBRange child_meshsets;
+    Range child_meshsets;
     if( mdbImpl->get_entities_by_handle(0, child_meshsets ) != MB_SUCCESS ) 
       return MB_FAILURE;
 
     child_meshsets = subtract( child_meshsets, initRange);
 
-    MBRange::iterator iter, end_iter;
+    Range::iterator iter, end_iter;
     iter = child_meshsets.begin();
     end_iter = child_meshsets.end();
 
-    MBEntityHandle ns_handle = 0;
+    EntityHandle ns_handle = 0;
     for(; iter != end_iter; iter++)
     {
       int nodeset_id;
@@ -881,15 +883,15 @@
       }
     } 
 
-    std::vector< MBEntityHandle > nodes_of_nodeset;
+    std::vector< EntityHandle > nodes_of_nodeset;
     if( ns_handle )
       if( mdbImpl->get_entities_by_handle( ns_handle, nodes_of_nodeset, true) != MB_SUCCESS )
         return MB_FAILURE;
 
       // make these into entity handles
-      // TODO: could we have read it into MBEntityHandle sized array in the first place?
+      // TODO: could we have read it into EntityHandle sized array in the first place?
     int j, temp;
-    std::vector<MBEntityHandle> nodes;
+    std::vector<EntityHandle> nodes;
     std::vector<double> dist_factor_vector;
     for (j = 0; j < number_nodes_in_set; j++)
     {
@@ -965,7 +967,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNCDF::read_sidesets() 
+ErrorCode ReadNCDF::read_sidesets() 
 {
   // uhhh if you read the same file (previously_read==true) then blow away the 
   // sidesets pertaining to this file?  How do you do that?  If you read a 
@@ -994,14 +996,14 @@
 
 
   // Maybe there is already a sidesets meshset here we can append to 
-  MBRange child_meshsets;
+  Range child_meshsets;
   if( mdbImpl->get_entities_by_type(0, MBENTITYSET, 
                                     child_meshsets ) != MB_SUCCESS ) 
     return MB_FAILURE;
 
   child_meshsets = subtract( child_meshsets, initRange);
 
-  MBRange::iterator iter, end_iter;
+  Range::iterator iter, end_iter;
 
   int i;
   std::vector<char> temp_string_storage(max_str_length+1);
@@ -1044,7 +1046,7 @@
     }
 
     std::vector<double> temp_dist_factor_vector;
-    std::vector<MBEntityHandle> entities_to_add, reverse_entities;
+    std::vector<EntityHandle> entities_to_add, reverse_entities;
     // create the sideset entities 
     if( create_ss_elements( &element_list[0], &side_list[0], number_sides_in_set, number_dist_factors_in_set, 
                             entities_to_add, reverse_entities, temp_dist_factor_vector, 
@@ -1057,7 +1059,7 @@
       iter = child_meshsets.begin();
       end_iter = child_meshsets.end();
 
-      MBEntityHandle ss_handle = 0;
+      EntityHandle ss_handle = 0;
       for(; iter != end_iter; iter++)
       {
         int sideset_id;
@@ -1091,20 +1093,20 @@
 
         if (!reverse_entities.empty()) {
             // also make a reverse set to put in this set
-          MBEntityHandle reverse_set;
+          EntityHandle reverse_set;
           if (mdbImpl->create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, reverse_set) != MB_SUCCESS)
             return MB_FAILURE;
 
 
             // add the reverse set to the sideset set and the entities to the reverse set
-          MBErrorCode result = mdbImpl->add_entities(ss_handle, &reverse_set, 1);
+          ErrorCode result = mdbImpl->add_entities(ss_handle, &reverse_set, 1);
           if (MB_SUCCESS != result) return result;
 
           result = mdbImpl->add_entities(reverse_set, &reverse_entities[0], reverse_entities.size());
           if (MB_SUCCESS != result) return result;
 
             // set the reverse tag
-          MBTag sense_tag;
+          Tag sense_tag;
           result = mdbImpl->tag_get_handle("SENSE", sense_tag);
           int dum_sense = 0;
           if (result == MB_TAG_NOT_FOUND) {
@@ -1145,12 +1147,12 @@
 
 }
 
-MBErrorCode ReadNCDF::create_ss_elements( int *element_ids, 
+ErrorCode ReadNCDF::create_ss_elements( int *element_ids, 
                                             int *side_list, 
                                             int num_sides,  
                                             int num_dist_factors, 
-                                            std::vector<MBEntityHandle> &entities_to_add,
-                                            std::vector<MBEntityHandle> &reverse_entities,
+                                            std::vector<EntityHandle> &entities_to_add,
+                                            std::vector<EntityHandle> &reverse_entities,
                                             std::vector<double> &dist_factor_vector, 
                                            int ss_seq_id)
 {
@@ -1180,10 +1182,10 @@
     }
   }
 
-  MBEntityType subtype;
+  EntityType subtype;
   int num_side_nodes, num_elem_nodes;
-  const MBEntityHandle* nodes;
-  std::vector<MBEntityHandle> connectivity;
+  const EntityHandle* nodes;
+  std::vector<EntityHandle> connectivity;
   int side_node_idx[32];
 
   int df_index = 0;
@@ -1196,9 +1198,9 @@
     if( find_side_element_type( element_ids[i], exoii_type, block_data, df_index, side_list[i]) != MB_SUCCESS )
       continue; //isn't being read in this time
 
-    MBEntityType type = ExoIIUtil::ExoIIElementMBEntity[exoii_type];
+    EntityType type = ExoIIUtil::ExoIIElementMBEntity[exoii_type];
 
-    MBEntityHandle ent_handle = element_ids[i] - block_data.startExoId + block_data.startMBId;
+    EntityHandle ent_handle = element_ids[i] - block_data.startExoId + block_data.startMBId;
 
     const int side_num = side_list[i] - 1;
     if(type == MBHEX)
@@ -1386,19 +1388,19 @@
   return MB_SUCCESS; 
 }
 
-MBErrorCode ReadNCDF::create_sideset_element( const std::vector<MBEntityHandle>& connectivity, 
-                                              MBEntityType type, MBEntityHandle& handle)
+ErrorCode ReadNCDF::create_sideset_element( const std::vector<EntityHandle>& connectivity, 
+                                              EntityType type, EntityHandle& handle)
 {
   // get adjacent entities
-  MBErrorCode error = MB_SUCCESS;
+  ErrorCode error = MB_SUCCESS;
   int to_dim = MBCN::Dimension(type);
-  std::vector<MBEntityHandle> adj_ent;
+  std::vector<EntityHandle> adj_ent;
   mdbImpl->get_adjacencies(&(connectivity[0]), 1, to_dim, false, adj_ent);
 
   // for each entity, see if we can find a match
   // if we find a match, return it
   bool match_found = false;
-  std::vector<MBEntityHandle> match_conn;
+  std::vector<EntityHandle> match_conn;
   for(unsigned int i=0; i<adj_ent.size() && match_found == false; i++)
   {
     // get the connectivity
@@ -1411,7 +1413,7 @@
       continue;
 
     // find a matching node
-    std::vector<MBEntityHandle>::iterator iter;
+    std::vector<EntityHandle>::iterator iter;
     iter = std::find(match_conn.begin(), match_conn.end(), connectivity[0]);
     if(iter == match_conn.end())
       continue;
@@ -1461,7 +1463,7 @@
 }
 
 
-MBErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementType &elem_type, 
+ErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementType &elem_type, 
                                                 ReadBlockData &block_data, int &df_index, int side_id)
 {
 
@@ -1510,7 +1512,7 @@
   return MB_FAILURE;
 }
 
-MBErrorCode ReadNCDF::read_qa_records(MBEntityHandle file_set)
+ErrorCode ReadNCDF::read_qa_records(EntityHandle file_set)
 {
   std::vector<std::string> qa_records;
   read_qa_information( qa_records );
@@ -1534,7 +1536,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNCDF::read_qa_information(std::vector<std::string> &qa_record_list)
+ErrorCode ReadNCDF::read_qa_information(std::vector<std::string> &qa_record_list)
 {
   // inquire on the genesis file to find the number of qa records
 
@@ -1559,7 +1561,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadNCDF::read_qa_string(char *temp_string,
+ErrorCode ReadNCDF::read_qa_string(char *temp_string,
                                      int record_number,
                                      int record_position)
 {
@@ -1587,11 +1589,11 @@
 // The cub_file_set contains the mesh to be updated. There could exist other
 // file sets that should be kept separate, such as the geometry file set from
 // ReadCGM.
-MBErrorCode ReadNCDF::update(const char *exodus_file_name, 
+ErrorCode ReadNCDF::update(const char *exodus_file_name, 
                              const FileOptions& opts, 
                              const int num_blocks, 
                              const int *blocks_to_load,
-                             const MBEntityHandle cub_file_set)
+                             const EntityHandle cub_file_set)
 {
   //Function : updating current database from new exodus_file. 
   //Creator:   Jane Hu
@@ -1620,7 +1622,7 @@
   // *******************************************************************
   // Move nodes to their deformed locations.
   // *******************************************************************  
-  MBErrorCode rval;
+  ErrorCode rval;
   std::string s;
   rval = opts.get_str_option("tdata", s ); 
   if(MB_SUCCESS != rval)
@@ -1806,20 +1808,20 @@
   int lost = 0;
 
   // Place cub verts in a kdtree.
-  MBRange cub_verts;
+  Range cub_verts;
   rval = mdbImpl->get_entities_by_type( cub_file_set, MBVERTEX, cub_verts );
   if(MB_SUCCESS != rval) return rval;
   std::cout << "  cub_file_set contains " << cub_verts.size() << " nodes." 
             << std::endl;
-  MBAdaptiveKDTree kdtree( mdbImpl, true );
-  MBEntityHandle root;
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree kdtree( mdbImpl, true );
+  EntityHandle root;
+  AdaptiveKDTree::Settings settings;
   settings.maxEntPerLeaf = 1;                                   
   settings.candidateSplitsPerDir = 1;                
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
   rval = kdtree.build_tree( cub_verts, root, &settings );      
   if(MB_SUCCESS != rval) return rval;
-  MBAdaptiveKDTreeIter tree_iter;                                                     
+  AdaptiveKDTreeIter tree_iter;                                                     
   rval = kdtree.get_tree_iterator( root, tree_iter );
   if(MB_SUCCESS != rval) return rval;
 
@@ -1831,7 +1833,7 @@
 
   // We should not use cub verts unless they have been matched. Place in a map
   // for fast handle_by_id lookup.
-  std::map<int,MBEntityHandle> matched_cub_vert_id_map;
+  std::map<int,EntityHandle> matched_cub_vert_id_map;
 
   // For each exo vert find the closest cub vert. Use proximity because kd-tree
   // search is O(logn) but MOAB tag search is O(n). For 150k nodes this 
@@ -1841,24 +1843,24 @@
   std::cout << "  exodus file contains " << numberNodes_loading << " nodes." 
             << std::endl;
   for(int i=0; i<numberNodes_loading; ++i) {
-    MBEntityHandle cub_vert = 0;
-    std::vector<MBEntityHandle> leaves;
+    EntityHandle cub_vert = 0;
+    std::vector<EntityHandle> leaves;
     int exo_id = ptr[i];
-    MBCartVect exo_coords( orig_coords[0][i], orig_coords[1][i], orig_coords[2][i] );
+    CartVect exo_coords( orig_coords[0][i], orig_coords[1][i], orig_coords[2][i] );
 
     double min_dist = MAX_NODE_DIST;
 
     rval = kdtree.leaves_within_distance( root, exo_coords.array(), MAX_NODE_DIST, leaves );    
     if(MB_SUCCESS != rval) return rval;
-    for(std::vector<MBEntityHandle>::const_iterator j=leaves.begin(); 
+    for(std::vector<EntityHandle>::const_iterator j=leaves.begin(); 
       j!=leaves.end(); ++j) {
       //if(0 != cub_vert) break;
-      std::vector<MBEntityHandle> leaf_verts;
+      std::vector<EntityHandle> leaf_verts;
       rval = mdbImpl->get_entities_by_type( *j, MBVERTEX, leaf_verts );
       if(MB_SUCCESS != rval) return rval;
 
       // Find the matching cub node by id or proximity
-      for(std::vector<MBEntityHandle>::const_iterator k=leaf_verts.begin(); 
+      for(std::vector<EntityHandle>::const_iterator k=leaf_verts.begin(); 
         k!=leaf_verts.end(); ++k) {
         if(match_node_ids) {
           int cub_id;
@@ -1869,7 +1871,7 @@
             break;
           }
         } else {
-          MBCartVect orig_cub_coords, difference;
+          CartVect orig_cub_coords, difference;
           rval = mdbImpl->get_coords( &(*k), 1, orig_cub_coords.array() );
           if(MB_SUCCESS != rval) return rval;
           difference = orig_cub_coords - exo_coords;
@@ -1883,7 +1885,7 @@
     }
     // If a cub vert is found, update it with the deformed coords from the exo file.
     if(0 != cub_vert) {
-      MBCartVect updated_exo_coords;
+      CartVect updated_exo_coords;
       matched_cub_vert_id_map[exo_id] = cub_vert;
       updated_exo_coords[0] = orig_coords[0][i] + deformed_arrays[0][i];
       updated_exo_coords[1] = orig_coords[1][i] + deformed_arrays[1][i];
@@ -2034,13 +2036,13 @@
     ExoIIElementType elem_type = ExoIIUtil::static_element_name_to_type(dum_str);
     delete [] dum_str;
     (*i).elemType = elem_type;
-    const MBEntityType mb_type = ExoIIUtil::ExoIIElementMBEntity[(*i).elemType];
+    const EntityType mb_type = ExoIIUtil::ExoIIElementMBEntity[(*i).elemType];
 
     // Get the number of nodes per element
     unsigned int nodes_per_element = ExoIIUtil::VerticesPerElement[(*i).elemType];
     
     // read the connectivity into that memory,  this will take only part of the array
-    // 1/2 if sizeof(MBEntityHandle) == 64 bits.
+    // 1/2 if sizeof(EntityHandle) == 64 bits.
     int exo_conn[i->numElements][nodes_per_element];
     NcBool status = temp_var->get( &exo_conn[0][0], i->numElements, nodes_per_element);
     if (0 == status) {
@@ -2082,7 +2084,7 @@
     for (int j=0; j<i->numElements; ++j) {
       if (1 != death_status[j]) {
 
-        MBRange cub_elem, cub_nodes;
+        Range cub_elem, cub_nodes;
         if(match_elems_by_connectivity) {
           // get exodus nodes for the element
 	  std::vector<int> elem_conn(nodes_per_element);
@@ -2099,7 +2101,7 @@
           // The map is a log search and takes almost no time. 
           // MOAB's linear tag search takes 5-10 minutes.
           for(unsigned int k=0; k<nodes_per_element; ++k) {
-	    std::map<int,MBEntityHandle>::iterator k_iter;
+	    std::map<int,EntityHandle>::iterator k_iter;
             k_iter = matched_cub_vert_id_map.find( elem_conn_node_ids[k] );
             
             if(k_iter == matched_cub_vert_id_map.end()) {
@@ -2130,7 +2132,7 @@
           // get the element by id
           rval = mdbImpl->get_entities_by_type_and_tag( cub_file_set, mb_type, 
 		  				        &mGlobalIdTag, id, 1, cub_elem, 
-                                                        MBInterface::INTERSECT );
+                                                        Interface::INTERSECT );
           if(MB_SUCCESS != rval) return rval;
         }
 
@@ -2184,3 +2186,5 @@
       pos = str.size();
   }
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadNCDF.hpp
===================================================================
--- MOAB/trunk/src/io/ReadNCDF.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadNCDF.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,46 +37,48 @@
 #include <vector>
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/Range.hpp"
 
-class MBReadUtilIface;
+class NcFile;
 
+namespace moab {
+
+class ReadUtilIface;
+
 struct ReadBlockData
 {
   int blockId;
   int startExoId; 
-  MBEntityHandle startMBId; 
+  EntityHandle startMBId; 
   int numElements;
   bool reading_in;
   ExoIIElementType elemType;
 };
 
-class NcFile;
-
 //! Output Exodus File for VERDE
-class ReadNCDF : public MBReaderIface
+class ReadNCDF : public ReaderIface
 {
    
 public:
   
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
   
   void tokenize( const std::string& str,
                  std::vector<std::string>& tokens,
                  const char* delimiters );
 
     //! load an ExoII file
-  MBErrorCode load_file( const char *exodus_file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *exodus_file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -84,45 +86,45 @@
                                int subset_list_length = 0 );
   
    //! Constructor
-   ReadNCDF(MBInterface* impl = NULL);
+   ReadNCDF(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadNCDF();
 
   //update the coords for deformed mesh according to FileOptions
-  MBErrorCode update(const char *exodus_file_name, const FileOptions& opts,
+  ErrorCode update(const char *exodus_file_name, const FileOptions& opts,
                      const int num_blocks, const int *blocks_to_load,
-                     const MBEntityHandle file_set );
+                     const EntityHandle file_set );
 
 private:
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
   bool dimension_exists(const char *attrib_name);
   
   void reset();
 
     //! read the header from the ExoII file
-  MBErrorCode read_exodus_header();
+  ErrorCode read_exodus_header();
   
     //! read the nodes
-  MBErrorCode read_nodes(const MBTag* file_id_tag);
+  ErrorCode read_nodes(const Tag* file_id_tag);
   
     //! read block headers, containing info about element type, number, etc.
-  MBErrorCode read_block_headers(const int *blocks_to_load,
+  ErrorCode read_block_headers(const int *blocks_to_load,
                                   const int num_blocks);
   
     //! read the element blocks
-  MBErrorCode read_elements(const MBTag* file_id_tag);
+  ErrorCode read_elements(const Tag* file_id_tag);
   
     //! read in the global element ids
-  MBErrorCode read_global_ids();
+  ErrorCode read_global_ids();
 
     //! read the nodesets into meshsets
-  MBErrorCode read_nodesets();
+  ErrorCode read_nodesets();
   
     //! read the sidesets (does nothing for now)
-  MBErrorCode read_sidesets();
+  ErrorCode read_sidesets();
 
     //! exodus file bound to this object
   int exodus_file();
@@ -131,10 +133,10 @@
   int number_dimensions();
 
   //! map a character exodusII element type to a TSTT type & topology
-  MBErrorCode get_type(char *exo_element_type,
-                        MBEntityType &elem_type);
+  ErrorCode get_type(char *exo_element_type,
+                        EntityType &elem_type);
  
-  MBErrorCode get_type(MBEntityType &elem_type,
+  ErrorCode get_type(EntityType &elem_type,
                         std::string &exo_element_type);
 
   /* 
@@ -143,38 +145,38 @@
  */
 
   //qa record stuff 
-  MBErrorCode read_qa_records(MBEntityHandle file_set);
-  MBErrorCode read_qa_information( std::vector<std::string> &qa_record_list);
+  ErrorCode read_qa_records(EntityHandle file_set);
+  ErrorCode read_qa_information( std::vector<std::string> &qa_record_list);
 
-  MBErrorCode read_qa_string(char *string,
+  ErrorCode read_qa_string(char *string,
                               int record_number,
                               int record_position); 
 
-  MBErrorCode create_ss_elements( int *element_ids, int *side_list,
+  ErrorCode create_ss_elements( int *element_ids, int *side_list,
                                    int num_sides, int num_dist_factors,
-                                   std::vector<MBEntityHandle> &entities_to_add,
-                                   std::vector<MBEntityHandle> &reverse_entities,
+                                   std::vector<EntityHandle> &entities_to_add,
+                                   std::vector<EntityHandle> &reverse_entities,
                                    std::vector<double> &dist_factor_vector,
                                    int ss_seq_id);
 
-  MBErrorCode find_side_element_type( const int element_id, ExoIIElementType &type, 
+  ErrorCode find_side_element_type( const int element_id, ExoIIElementType &type, 
                                        ReadBlockData &block_data, int &df_index, int side_id );
   
- /* MBErrorCode assign_block_ids_to_ssets(MBEntityHandle ss_handle,
+ /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
                                          MB_MeshSet *ss_mesh_set);
                                          */
 
   //! creates an element with the given connectivity
-  MBErrorCode create_sideset_element( const std::vector<MBEntityHandle>&, MBEntityType, MBEntityHandle&);
+  ErrorCode create_sideset_element( const std::vector<EntityHandle>&, EntityType, EntityHandle&);
 
-  int get_number_nodes( MBEntityHandle handle );
+  int get_number_nodes( EntityHandle handle );
 
 
 
   //------------member variables ------------//
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
   
   NcFile *ncFile;        // netcdf/exodus file
 
@@ -205,7 +207,7 @@
   int numberDimensions_loading;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //keeps track of the exodus ids of the elements and nodes just loaded
   std::vector<char> nodesInLoadedBlocks;
@@ -216,18 +218,18 @@
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mDistFactorTag;
-  MBTag mGlobalIdTag;
-  MBTag mQaRecordTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mDistFactorTag;
+  Tag mGlobalIdTag;
+  Tag mQaRecordTag;
 
   int max_line_length, max_str_length;
 
     //! range of entities in initial mesh, before this read
-  MBRange initRange;
+  Range initRange;
 };
 
 // inline functions
@@ -236,6 +238,7 @@
    return numberDimensions_loading;
 }
 
+} // namespace moab
 
 #endif
 

Modified: MOAB/trunk/src/io/ReadSTL.cpp
===================================================================
--- MOAB/trunk/src/io/ReadSTL.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSTL.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,35 +21,34 @@
 
 #include "ReadSTL.hpp"
 #include "FileTokenizer.hpp" // for FileTokenizer
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBRange.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/Range.hpp"
 #include "FileOptions.hpp"
-#include "MBSysUtil.hpp"
+#include "SysUtil.hpp"
 
-#include "MBEntityHandle.h"
-
 #include <errno.h>
 #include <string.h>
 #include <limits.h>
 #include <assert.h>
 #include <map>
 
+namespace moab {
 
 
-ReadSTL::ReadSTL(MBInterface* impl)
+ReadSTL::ReadSTL(Interface* impl)
     : mdbImpl(impl)
 {
   void* ptr = 0;
-  mdbImpl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  mdbImpl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 ReadSTL::~ReadSTL()
 {
   if (readMeshIface) {
-    mdbImpl->release_interface("MBReadUtilIface", readMeshIface);
+    mdbImpl->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
@@ -62,7 +61,7 @@
 
 
 
-MBErrorCode ReadSTL::read_tag_values( const char* /* file_name */,
+ErrorCode ReadSTL::read_tag_values( const char* /* file_name */,
                                       const char* /* tag_name */,
                                       const FileOptions& /* opts */,
                                       std::vector<int>& /* tag_values_out */,
@@ -75,19 +74,19 @@
 // Generic load function for both ASCII and binary.  Calls
 // pure-virtual function implemented in subclasses to read
 // the data from the file.
-MBErrorCode ReadSTL::load_file( const char* filename,
-                                const MBEntityHandle* , 
+ErrorCode ReadSTL::load_file( const char* filename,
+                                const EntityHandle* , 
                                 const FileOptions& opts,
-                                const MBReaderIface::IDTag* subset_list,
+                                const ReaderIface::IDTag* subset_list,
                                 int subset_list_length,
-                                const MBTag* file_id_tag )
+                                const Tag* file_id_tag )
 {
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for STL." );
     return MB_UNSUPPORTED_OPERATION;
   }
 
-  MBErrorCode result;
+  ErrorCode result;
 
   std::vector<ReadSTL::Triangle> triangles;
  
@@ -130,7 +129,7 @@
 
     // Create a std::map from position->handle, and such
     // that all positions are specified, and handles are zero.
-  std::map<Point,MBEntityHandle> vertex_map;
+  std::map<Point,EntityHandle> vertex_map;
   for (std::vector<Triangle>::iterator i = triangles.begin(); i != triangles.end(); ++i)
   {
     vertex_map[i->points[0]] = 0;
@@ -140,7 +139,7 @@
   
     // Create vertices 
   std::vector<double*> coord_arrays;
-  MBEntityHandle handle = 0;
+  EntityHandle handle = 0;
   result = readMeshIface->get_node_arrays( 3, vertex_map.size(), MB_START_ID,
                                            handle, coord_arrays );
   if (MB_SUCCESS != result)
@@ -149,7 +148,7 @@
     // Copy vertex coordinates into entity sequence coordinate arrays
     // and copy handle into vertex_map.
   double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2];
-  for (std::map<Point,MBEntityHandle>::iterator i = vertex_map.begin();
+  for (std::map<Point,EntityHandle>::iterator i = vertex_map.begin();
        i != vertex_map.end(); ++i)
   {
     i->second = handle; ++handle;
@@ -160,7 +159,7 @@
   
     // Allocate triangles
   handle = 0;
-  MBEntityHandle* connectivity;
+  EntityHandle* connectivity;
   result = readMeshIface->get_element_array( triangles.size(),
                                              3,
                                              MBTRI,
@@ -172,7 +171,7 @@
   
     // Use vertex_map to reconver triangle connectivity from
     // vertex coordinates.
-  MBEntityHandle *conn_sav = connectivity;
+  EntityHandle *conn_sav = connectivity;
   for (std::vector<Triangle>::iterator i = triangles.begin(); i != triangles.end(); ++i)
   {
     *connectivity = vertex_map[i->points[0]]; ++connectivity;
@@ -190,7 +189,7 @@
 
 
 // Read ASCII file
-MBErrorCode ReadSTL::ascii_read_triangles( const char* name,
+ErrorCode ReadSTL::ascii_read_triangles( const char* name,
                                           std::vector<ReadSTL::Triangle>& tris )
 {
   FILE* file = fopen( name, "r" );
@@ -268,7 +267,7 @@
 };
 
 // Read a binary STL file
-MBErrorCode ReadSTL::binary_read_triangles( const char* name,
+ErrorCode ReadSTL::binary_read_triangles( const char* name,
                                            ReadSTL::ByteOrder byte_order,
                                            std::vector<ReadSTL::Triangle>& tris )
 {
@@ -290,7 +289,7 @@
   
     // Allow user setting for byte order, default to little endian
   const bool want_big_endian = (byte_order == STL_BIG_ENDIAN);
-  const bool am_big_endian = !MBSysUtil::little_endian();
+  const bool am_big_endian = !SysUtil::little_endian();
   bool swap_bytes = (want_big_endian == am_big_endian);
   
     // Compare the number of triangles to the length of the file.  
@@ -307,11 +306,11 @@
   
     // Get expected number of triangles
   if (swap_bytes)
-    MBSysUtil::byteswap( &header.count, 1 );
+    SysUtil::byteswap( &header.count, 1 );
   unsigned long num_tri = header.count;
   
     // Get the file length
-  long filesize = MBSysUtil::filesize( file );
+  long filesize = SysUtil::filesize( file );
   if (filesize >= 0) // -1 indicates could not determine file size (e.g. reading from FIFO)
   {
       // Check file size, but be careful of numeric overflow
@@ -321,7 +320,7 @@
         // Unless the byte order was specified explicitly in the 
         // tag, try the opposite byte order.
       uint32_t num_tri_tmp = header.count;
-      MBSysUtil::byteswap( &num_tri_tmp, 1 );
+      SysUtil::byteswap( &num_tri_tmp, 1 );
       unsigned long num_tri_swap = num_tri_tmp;
       if (byte_order != STL_UNKNOWN_BYTE_ORDER || // If byte order was specified, fail now
           ULONG_MAX / 50 - 84 < num_tri_swap  || // watch for overflow in next line
@@ -351,7 +350,7 @@
     }
     
     if (swap_bytes)
-      MBSysUtil::byteswap( tri.coords, 9 );
+      SysUtil::byteswap( tri.coords, 9 );
     
     for (unsigned j = 0; j < 9; ++j)
       i->points[j/3].coords[j%3] = tri.coords[j];
@@ -362,5 +361,7 @@
 }
 
 
-MBReaderIface* ReadSTL::factory( MBInterface* iface )
+ReaderIface* ReadSTL::factory( Interface* iface )
   { return new ReadSTL(iface); }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadSTL.hpp
===================================================================
--- MOAB/trunk/src/io/ReadSTL.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSTL.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -55,30 +55,32 @@
 #define READ_STL_HPP
 
 #include <stdio.h>
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
 
-class MBReadUtilIface;
+namespace moab {
 
+class ReadUtilIface;
+
 // Base class for binary and ASCII readers
-class ReadSTL : public MBReaderIface
+class ReadSTL : public ReaderIface
 {
    
 public:
 
     //! factory method for STL reader
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
     //! Generic file loading code for both binary and ASCII readers.
     //! Calls reader-specific read_triangles function to do actual I/O.
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -86,7 +88,7 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadSTL(MBInterface* impl = NULL);
+  ReadSTL(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadSTL();
@@ -107,19 +109,21 @@
 protected:
 
     // I/O specific part of reader - read ASCII file
-  MBErrorCode ascii_read_triangles( const char* file_name, 
+  ErrorCode ascii_read_triangles( const char* file_name, 
                                     std::vector<Triangle>& tris_out );
 
     // I/O specific part of reader - read binary file
-  MBErrorCode binary_read_triangles( const char* file_name, 
+  ErrorCode binary_read_triangles( const char* file_name, 
                                      ByteOrder byte_order,
                                      std::vector<Triangle>& tris_out );
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
 
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/ReadSmf.cpp
===================================================================
--- MOAB/trunk/src/io/ReadSmf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSmf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,15 +24,17 @@
 #include <iostream>
 
 #include "ReadSmf.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "FileOptions.hpp"
-#include "MBAffineXform.hpp"
+#include "AffineXform.hpp"
 
-inline int streq(const char *a,const char *b) { return strcmp(a,b)==0; }
+static inline int streq(const char *a,const char *b) { return strcmp(a,b)==0; }
 
+namespace moab {
+
 ReadSmf::cmd_entry ReadSmf::read_cmds[] = {
     { "v", &ReadSmf::vertex },
     { ":vn", &ReadSmf::v_normal },
@@ -56,14 +58,14 @@
     { "", NULL }
 };
 
-MBAffineXform mat_from_args(std::vector<std::string> & argv)
+AffineXform mat_from_args(std::vector<std::string> & argv)
 {
     double m3[9], offset[3];
     for (int i=0; i<9; i++)
 	m3[i] = atof(argv[i].c_str());
     for (int j=0; j<3; j++)
 	offset[j] = atof(argv[j+9].c_str());// only the first 12 are used, the last row (or column?) is 0001?
-    MBAffineXform M(m3, offset);
+    AffineXform M(m3, offset);
     return M;
 }
 
@@ -72,15 +74,15 @@
     std::cerr << "SMF: Malformed annotation ["<< cmd << "]" << std::endl;
 }
 
-MBReaderIface* ReadSmf::factory( MBInterface* iface )
+ReaderIface* ReadSmf::factory( Interface* iface )
   { return new ReadSmf( iface ); }
 
-ReadSmf::ReadSmf(MBInterface* impl)
+ReadSmf::ReadSmf(Interface* impl)
     : mdbImpl(impl)
 {
   void* ptr = 0;
-  mdbImpl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  mdbImpl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
   _numNodes= _numFaces = 0;
   _numNodesInFile = _numElementsInFile = 0;
 }
@@ -88,13 +90,13 @@
 ReadSmf::~ReadSmf()
 {
   if (readMeshIface) {
-    mdbImpl->release_interface("MBReadUtilIface", readMeshIface);
+    mdbImpl->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
 
 
-MBErrorCode ReadSmf::read_tag_values( const char* /* file_name */,
+ErrorCode ReadSmf::read_tag_values( const char* /* file_name */,
                                       const char* /* tag_name */,
                                       const FileOptions& /* opts */,
                                       std::vector<int>& /* tag_values_out */,
@@ -105,14 +107,14 @@
 }
 
 
-MBErrorCode ReadSmf::load_file( const char *filename,
-                                const MBEntityHandle* ,
+ErrorCode ReadSmf::load_file( const char *filename,
+                                const EntityHandle* ,
                                 const FileOptions& opts,
-                                const MBReaderIface::IDTag* subset_list,
+                                const ReaderIface::IDTag* subset_list,
                                 int subset_list_length,
-                                const MBTag* file_id_tag) 
+                                const Tag* file_id_tag) 
 {
-  MBErrorCode result;
+  ErrorCode result;
   
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for VTK." );
@@ -151,7 +153,7 @@
   
     // Create vertices
   std::vector<double*> arrays;
-  MBEntityHandle start_handle_out;
+  EntityHandle start_handle_out;
   start_handle_out = 0;
   result = readMeshIface->get_node_arrays( 3, _numNodesInFile, MB_START_ID,
                                            start_handle_out, arrays );
@@ -170,12 +172,12 @@
     }
   // elements
   
-  MBEntityHandle start_handle_elem_out;
+  EntityHandle start_handle_elem_out;
   start_handle_elem_out = 0;
-  MBEntityHandle* conn_array_out;
+  EntityHandle* conn_array_out;
   result = readMeshIface->get_element_array( _numElementsInFile,
                                              3,
-                                             MBTRI , // MBEntityType
+                                             MBTRI , // EntityType
                                              MB_START_ID,
                                              start_handle_elem_out,
                                              conn_array_out );
@@ -193,7 +195,7 @@
   if (MB_SUCCESS != result)
     return result;
 
-  MBRange range(start_handle_out, start_handle_out+_numElementsInFile-1);
+  Range range(start_handle_out, start_handle_out+_numElementsInFile-1);
  
  
   return MB_SUCCESS;
@@ -259,7 +261,7 @@
     
 }
 
-MBErrorCode ReadSmf::parse_line(char *line)
+ErrorCode ReadSmf::parse_line(char *line)
 {
     char *cmd,*s;
     std::vector<std::string>  argv;
@@ -377,7 +379,7 @@
     double v3[3];
     for (int i=0; i<3; i++)
 	v3[i] = atof(argv[i].c_str());
-    MBAffineXform M = MBAffineXform::translation(v3);
+    AffineXform M = AffineXform::translation(v3);
     //Mat4 M = Mat4::trans(atof(argv(0)), atof(argv(1)), atof(argv(2)));
     state->mmult(M);
 }
@@ -386,7 +388,7 @@
     double v3[3];
     for (int i=0; i<3; i++)
 	v3[i] = atof(argv[i].c_str());
-    MBAffineXform M = MBAffineXform::scale(v3);
+    AffineXform M = AffineXform::scale(v3);
     //Mat4 M = Mat4::scale(atof(argv(0)), atof(argv(1)), atof(argv(2)));
     state->mmult(M);
 }
@@ -409,7 +411,7 @@
 	  std::cerr << "SMF: Malformed rotation command" << std::endl;
 	break;
     }
-    MBAffineXform M = MBAffineXform::rotation( angle, axis );
+    AffineXform M = AffineXform::rotation( angle, axis );
     state->mmult(M);
 }
 void ReadSmf::mmult(std::vector<std::string> & argv)
@@ -420,3 +422,5 @@
 {
     state->mload(mat_from_args(argv));
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadSmf.hpp
===================================================================
--- MOAB/trunk/src/io/ReadSmf.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSmf.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -18,32 +18,34 @@
 
 #define SMF_MAXLINE 4096
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
 
 #include "SMF_State.hpp"
 #include <iosfwd>
 #include <fstream>
 
-class MBReadUtilIface;
+namespace moab {
+
+class ReadUtilIface;
 class FileTokenizer;
 
-class ReadSmf : public MBReaderIface
+class ReadSmf : public ReaderIface
 {
    
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
     //! load a file
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions&,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -51,7 +53,7 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadSmf(MBInterface* impl = NULL);
+  ReadSmf(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadSmf();
@@ -84,20 +86,20 @@
     void mmult(std::vector<std::string> &);
     void mload(std::vector<std::string> &);
 
-    MBErrorCode parse_line(char *line);
+    ErrorCode parse_line(char *line);
 private:
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
   //------------member variables ------------//
 
 
      //! interface instance
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
     //! A field which, if present and having a single integer for storage, should be used to partition the mesh by range. Defaults to MATERIAL_SET_TAG_NAME
   std::string mPartitionTagName;
@@ -116,6 +118,8 @@
    
 };
 
+} // namespace moab
+
 #endif
 
 

Modified: MOAB/trunk/src/io/ReadSms.cpp
===================================================================
--- MOAB/trunk/src/io/ReadSms.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSms.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,13 +21,13 @@
 
 #include "ReadSms.hpp"
 #include "FileTokenizer.hpp" // for file tokenizer
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBParallelConventions.h"
-#include "MBCN.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBCN.hpp"
 
 #include <errno.h>
 #include <string.h>
@@ -42,26 +42,28 @@
 
 #define CHECKN(a) if (n != (a)) return MB_FILE_WRITE_ERROR
 
-MBReaderIface* ReadSms::factory( MBInterface* iface )
+namespace moab {
+
+ReaderIface* ReadSms::factory( Interface* iface )
   { return new ReadSms(iface); }
 
-ReadSms::ReadSms(MBInterface* impl)
+ReadSms::ReadSms(Interface* impl)
     : mdbImpl(impl)
 {
   void* ptr = 0;
-  mdbImpl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  mdbImpl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 ReadSms::~ReadSms()
 {
   if (readMeshIface) {
-    mdbImpl->release_interface("MBReadUtilIface", readMeshIface);
+    mdbImpl->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
 
-MBErrorCode ReadSms::read_tag_values(const char* /* file_name */,
+ErrorCode ReadSms::read_tag_values(const char* /* file_name */,
                                      const char* /* tag_name */,
                                      const FileOptions& /* opts */,
                                      std::vector<int>& /* tag_values_out */,
@@ -72,12 +74,12 @@
 }
 
 
-MBErrorCode ReadSms::load_file( const char* filename, 
-                                const MBEntityHandle* ,
+ErrorCode ReadSms::load_file( const char* filename, 
+                                const EntityHandle* ,
                                 const FileOptions& ,
-                                const MBReaderIface::IDTag* subset_list,
+                                const ReaderIface::IDTag* subset_list,
                                 int subset_list_length,
-                                const MBTag* file_id_tag )
+                                const Tag* file_id_tag )
 {
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for Sms." );
@@ -94,17 +96,17 @@
     return MB_FILE_DOES_NOT_EXIST;
   }
 
-  const MBErrorCode result = load_file_impl( file_ptr, file_id_tag );
+  const ErrorCode result = load_file_impl( file_ptr, file_id_tag );
   fclose( file_ptr );
 
   return result;
 }
 
-MBErrorCode ReadSms::load_file_impl( FILE* file_ptr, const MBTag* file_id_tag )
+ErrorCode ReadSms::load_file_impl( FILE* file_ptr, const Tag* file_id_tag )
 {
   bool warned = false;
   
-  MBErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, globalId );
+  ErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, globalId );
   if (MB_TAG_NOT_FOUND == result)
     result = mdbImpl->tag_create( GLOBAL_ID_TAG_NAME,
                                   sizeof(int), MB_TAG_SPARSE,
@@ -153,7 +155,7 @@
 
     // create the vertices
   std::vector<double*> coord_arrays;
-  MBEntityHandle vstart = 0;
+  EntityHandle vstart = 0;
   result = readMeshIface->get_node_arrays( 3, nvertices, MB_START_ID, 
                                            vstart, coord_arrays );
   CHECK("Failed to get node arrays.");
@@ -164,8 +166,8 @@
   if (MB_SUCCESS != result)
     return result;
   
-  MBEntityHandle this_gent, new_handle;
-  std::vector<MBEntityHandle> gentities[4];
+  EntityHandle this_gent, new_handle;
+  std::vector<EntityHandle> gentities[4];
   int gent_id, dum_int;
   int gent_type, num_connections;
   
@@ -215,8 +217,8 @@
 // *******************************
 
   int vert1, vert2, num_pts;
-  std::vector<MBEntityHandle> everts(2);
-  MBEntityHandle estart, *connect;
+  std::vector<EntityHandle> everts(2);
+  EntityHandle estart, *connect;
   result = readMeshIface->get_element_array(nedges, 2, MBEDGE, 1, estart, connect);
   CHECK("Failed to create array of edges.");
   if (MB_SUCCESS != result) return result;
@@ -285,9 +287,9 @@
 // *******************************
 //	Read Faces
 // *******************************
-  std::vector<MBEntityHandle> bound_ents, bound_verts, new_faces;
+  std::vector<EntityHandle> bound_ents, bound_verts, new_faces;
   int bound_id;
-  MBRange shverts;
+  Range shverts;
   new_faces.resize(nfaces);
   int num_bounding;
     
@@ -328,7 +330,7 @@
       shverts.clear();
     }
 
-    result = mdbImpl->create_element((MBEntityType)(MBTRI+num_bounding-3),
+    result = mdbImpl->create_element((EntityType)(MBTRI+num_bounding-3),
                                      &bound_verts[0], bound_verts.size(), 
                                      new_faces[i]);
     CHECK("Failed to create edge.");
@@ -377,7 +379,7 @@
   int sense[MB_MAX_SUB_ENTITIES];
   bound_verts.resize(MB_MAX_SUB_ENTITIES);
 
-  std::vector<MBEntityHandle> regions;
+  std::vector<EntityHandle> regions;
   if (file_id_tag)
     regions.resize( nregions );
   for(int i = 0; i < nregions; i++)
@@ -399,7 +401,7 @@
       bound_ents[j] = new_faces[abs(bound_id)-1];
     }
 
-    MBEntityType etype;
+    EntityType etype;
     result = readMeshIface->get_ordered_vertices(&bound_ents[0], sense, 
                                                  num_bounding,
                                                  3, &bound_verts[0], etype);
@@ -431,13 +433,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadSms::get_set(std::vector<MBEntityHandle> *sets,
+ErrorCode ReadSms::get_set(std::vector<EntityHandle> *sets,
                              int set_dim, int set_id,
-                             MBTag dim_tag,
-                             MBEntityHandle &this_set,
-                             const MBTag* file_id_tag) 
+                             Tag dim_tag,
+                             EntityHandle &this_set,
+                             const Tag* file_id_tag) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
   if (set_dim < 0 || set_dim > 3)
     return MB_FILE_WRITE_ERROR;
@@ -474,7 +476,7 @@
   return result;
 }
 
-MBErrorCode ReadSms::read_parallel_info(FILE *file_ptr) 
+ErrorCode ReadSms::read_parallel_info(FILE *file_ptr) 
 {
   return MB_FAILURE;
     /*
@@ -484,7 +486,7 @@
   
     // read interfaces
   int iface_id, iface_dim, iface_own, num_iface_corners;
-  MBEntityHandle this_iface;
+  EntityHandle this_iface;
   std::vector<int> *iface_corners;
   for (int i = 0; i < num_ifaces; i++) {
     fscanf(file_ptr, "%d %d %d %d", &iface_id, &iface_dim, &iface_own,
@@ -509,14 +511,16 @@
     */
 }
 
-MBErrorCode ReadSms::add_entities( MBEntityHandle start,
-                                   MBEntityHandle count,
-                                   const MBTag* file_id_tag )
+ErrorCode ReadSms::add_entities( EntityHandle start,
+                                   EntityHandle count,
+                                   const Tag* file_id_tag )
 {
   if (!count || !file_id_tag)
     return MB_FAILURE;
 
-  MBRange range;
+  Range range;
   range.insert( start, start + count - 1 );
   return readMeshIface->assign_ids( *file_id_tag, range, 1 );
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadSms.hpp
===================================================================
--- MOAB/trunk/src/io/ReadSms.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadSms.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,30 +1,32 @@
 #ifndef READ_SMS_HPP
 #define READ_SMS_HPP
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/Range.hpp"
 #include <vector>
 
-class MBReadUtilIface;
+namespace moab {
 
+class ReadUtilIface;
+
 // Base class for binary and ASCII readers
-class ReadSms : public MBReaderIface
+class ReadSms : public ReaderIface
 {
    
 public:
 
     //! factory method 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -32,36 +34,37 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadSms(MBInterface* impl = NULL);
+  ReadSms(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadSms();
 
 private:
 
-  MBErrorCode add_entities( MBEntityHandle start, 
-                            MBEntityHandle count,
-                            const MBTag* file_id_tag );
+  ErrorCode add_entities( EntityHandle start, 
+                            EntityHandle count,
+                            const Tag* file_id_tag );
 
-  MBErrorCode load_file_impl( FILE* file, const MBTag* file_id_tag );
+  ErrorCode load_file_impl( FILE* file, const Tag* file_id_tag );
   
-  MBErrorCode get_set(std::vector<MBEntityHandle> *sets,
+  ErrorCode get_set(std::vector<EntityHandle> *sets,
                       int set_type, int set_id,
-                      MBTag set_tag,
-                      MBEntityHandle &this_set,
-                      const MBTag* file_id_tag );
+                      Tag set_tag,
+                      EntityHandle &this_set,
+                      const Tag* file_id_tag );
 
-  MBErrorCode read_parallel_info(FILE *file_ptr);
+  ErrorCode read_parallel_info(FILE *file_ptr);
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
   
-  MBTag globalId, paramCoords, geomDimension;
+  Tag globalId, paramCoords, geomDimension;
   
   int setId;
 };
 
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/io/ReadTetGen.cpp
===================================================================
--- MOAB/trunk/src/io/ReadTetGen.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadTetGen.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,34 +1,36 @@
 #include "ReadTetGen.hpp"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "FileOptions.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/MBTagConventions.hpp"
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <ctype.h>
 #include <map>
 
-MBReaderIface* ReadTetGen::factory( MBInterface* moab )
+namespace moab {
+
+ReaderIface* ReadTetGen::factory( Interface* moab )
   { return new ReadTetGen(moab); }
 
-ReadTetGen::ReadTetGen( MBInterface* moab )
+ReadTetGen::ReadTetGen( Interface* moab )
   : mbIface(moab), readTool(0)
 {
   void* tool_ptr = 0;
-  MBErrorCode rval = moab->query_interface( "MBReadUtilIface", &tool_ptr );
+  ErrorCode rval = moab->query_interface( "ReadUtilIface", &tool_ptr );
   if (MB_SUCCESS == rval)
-    readTool = reinterpret_cast<MBReadUtilIface*>(tool_ptr);
+    readTool = reinterpret_cast<ReadUtilIface*>(tool_ptr);
 }
 
 ReadTetGen::~ReadTetGen()
 {
   if (mbIface && readTool)
-    mbIface->release_interface( "MBReadUtilIface", readTool );
+    mbIface->release_interface( "ReadUtilIface", readTool );
 }
 
-MBErrorCode ReadTetGen::open_file( const std::string& filename,
+ErrorCode ReadTetGen::open_file( const std::string& filename,
                                    const std::string& basename,
                                    const std::string& suffix,
                                    const char* exp_suffix,
@@ -38,7 +40,7 @@
                                    bool file_required )
 {
   std::string real_file_name;
-  MBErrorCode rval = opts.get_option( opt_name, real_file_name );
+  ErrorCode rval = opts.get_option( opt_name, real_file_name );
   if (MB_ENTITY_NOT_FOUND == rval || real_file_name.empty()) {
     if (MB_SUCCESS == rval)
       file_required = true;
@@ -62,7 +64,7 @@
 }
 
 
-MBErrorCode ReadTetGen::read_tag_values( const char* /* file_name */,
+ErrorCode ReadTetGen::read_tag_values( const char* /* file_name */,
                                          const char* /* tag_name */,
                                          const FileOptions& /* opts */,
                                          std::vector<int>& /* tag_values_out */,
@@ -73,15 +75,15 @@
 }
 
 
-MBErrorCode ReadTetGen::load_file( const char* file_name_c,
-                                   const MBEntityHandle* ,
+ErrorCode ReadTetGen::load_file( const char* file_name_c,
+                                   const EntityHandle* ,
                                    const FileOptions& opts,
-                                   const MBReaderIface::IDTag* subset_list,
+                                   const ReaderIface::IDTag* subset_list,
                                    int subset_list_length,
-                                   const MBTag* file_id_tag )
+                                   const Tag* file_id_tag )
 {
   std::ifstream node_file, ele_file, face_file, edge_file;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   if (subset_list && subset_list_length) {
     readTool->report_error( "Reading subset of files not supported for TetGen." );
@@ -119,7 +121,7 @@
   if (MB_SUCCESS != rval)
     return rval;
   
-  std::vector<MBTag> attr_tags[4];
+  std::vector<Tag> attr_tags[4];
   std::vector<int> attr_idx[4];
   const char* option_names[4] = { "NODE_ATTR_LIST", "EDGE_ATTR_LIST", "TRI_ATTR_LIST", "TET_ATTR_LIST" };
   const char* group_names[4] = { 0, "CURVE_ID", "SURFACE_ID", "VOLUME_ID" };
@@ -135,8 +137,8 @@
     }
   }
   
-  MBRange tets, tris, edges;
-  std::vector<MBEntityHandle> nodes;
+  Range tets, tris, edges;
+  std::vector<EntityHandle> nodes;
   rval = read_node_file( node_file, &attr_tags[0][0], &attr_idx[0][0], attr_tags[0].size(), nodes );
   if (MB_SUCCESS == rval && ele_file.is_open()) 
     rval = read_elem_file( MBTET, ele_file, nodes, tets );
@@ -157,8 +159,8 @@
   return rval;  
 }
 
-MBErrorCode ReadTetGen::parse_attr_list( const std::string& option_str,
-                                         std::vector<MBTag>& tag_list,
+ErrorCode ReadTetGen::parse_attr_list( const std::string& option_str,
+                                         std::vector<Tag>& tag_list,
                                          std::vector<int>& index_list,
                                          const char* group_designator )
 {
@@ -185,7 +187,7 @@
       index_list[i] = 0;
     }
     else {
-      MBErrorCode rval = mbIface->tag_create( name_list[i].c_str(),
+      ErrorCode rval = mbIface->tag_create( name_list[i].c_str(),
                                   name_count[name_list[i]]*sizeof(double),
                                   MB_TAG_DENSE,
                                   MB_TYPE_DOUBLE,
@@ -200,7 +202,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadTetGen::read_line( std::istream& file,
+ErrorCode ReadTetGen::read_line( std::istream& file,
                                    std::string& line,
                                    int& lineno )
 {
@@ -226,14 +228,14 @@
   return MB_SUCCESS;  
 }
 
-MBErrorCode ReadTetGen::read_line( std::istream& file,
+ErrorCode ReadTetGen::read_line( std::istream& file,
                                    double* values_out,
                                    int num_values, 
                                    int& lineno )
 {
     // get a line of text
   std::string line;
-  MBErrorCode rval = read_line( file, line, lineno );
+  ErrorCode rval = read_line( file, line, lineno );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -258,15 +260,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadTetGen::read_node_file( std::istream& file, 
-                                        const MBTag* attr_tag_list,
+ErrorCode ReadTetGen::read_node_file( std::istream& file, 
+                                        const Tag* attr_tag_list,
                                         const int* attr_tag_index,
                                         int attr_tag_list_len,
-                                        std::vector<MBEntityHandle>& nodes )
+                                        std::vector<EntityHandle>& nodes )
 {
   int lineno = 0;
   std::string line;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   double header_vals[4];
   rval = read_line( file, header_vals, 4, lineno );
@@ -285,8 +287,8 @@
     attr_tag_list_len = num_attr;
   
     // allocate space for tag data
-  std::map< MBTag, int > tag_size;
-  std::map< MBTag, std::vector<double> > tag_data;
+  std::map< Tag, int > tag_size;
+  std::map< Tag, std::vector<double> > tag_data;
   for (int i = 0; i < attr_tag_list_len; ++i) {
     if (!attr_tag_list[i] || attr_tag_index[i] < 0)
       continue;
@@ -311,7 +313,7 @@
   
     // allocate vertices
   std::vector<double*> coords;
-  MBEntityHandle start_handle;
+  EntityHandle start_handle;
   rval = readTool->get_node_arrays( dim, num_vtx, 1, start_handle, coords );
   if (MB_SUCCESS != rval)
     return rval;
@@ -344,15 +346,15 @@
   }
   
     // store tag data
-  MBRange node_range;
+  Range node_range;
   node_range.insert( start_handle, start_handle + num_vtx - 1 );
-  for (std::map< MBTag, std::vector<double> >::iterator i = tag_data.begin();
+  for (std::map< Tag, std::vector<double> >::iterator i = tag_data.begin();
        i != tag_data.end(); ++i) {
     rval = mbIface->tag_set_data( i->first, node_range, &i->second[0] );
     if (MB_SUCCESS != rval)
       return rval;
   }
-  MBTag idtag;
+  Tag idtag;
   rval = mbIface->tag_get_handle( GLOBAL_ID_TAG_NAME, idtag );
   if (MB_SUCCESS == rval) {
     rval = mbIface->tag_set_data( idtag, node_range, &ids[0] );
@@ -364,14 +366,14 @@
 }
   
 
-MBErrorCode ReadTetGen::read_elem_file( MBEntityType type,
+ErrorCode ReadTetGen::read_elem_file( EntityType type,
                                         std::istream& file, 
-                                        const std::vector<MBEntityHandle>& nodes,
-                                        MBRange& elems )
+                                        const std::vector<EntityHandle>& nodes,
+                                        Range& elems )
 {
   int lineno = 0;
   std::string line;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   int node_per_elem, have_group_id, dim;
   double header_vals[3];
@@ -407,8 +409,8 @@
   }
   
     // create group map
-  std::map<double,MBEntityHandle> groups;
-  MBTag dim_tag, id_tag;
+  std::map<double,EntityHandle> groups;
+  Tag dim_tag, id_tag;
   rval = mbIface->tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   if (MB_SUCCESS != rval)
     return rval;
@@ -420,7 +422,7 @@
     
   
     // allocate elements
-  MBEntityHandle start_handle, *conn_array;
+  EntityHandle start_handle, *conn_array;
   rval = readTool->get_element_array( num_elem, node_per_elem, type, 1, start_handle, conn_array );
   if (MB_SUCCESS != rval)
     return rval;
@@ -444,7 +446,7 @@
       // grouping
     if (have_group_id && 0.0 != data[node_per_elem+1]) {
       double id = data[node_per_elem+1];
-      MBEntityHandle grp = groups[id];
+      EntityHandle grp = groups[id];
       if (0 == grp) {
         rval = mbIface->create_meshset( MESHSET_SET, grp );
         if (MB_SUCCESS != rval)
@@ -459,7 +461,7 @@
           return rval;
         groups[id] = grp;
       }
-      MBEntityHandle handle = start_handle + i;
+      EntityHandle handle = start_handle + i;
       rval = mbIface->add_entities( grp, &handle, 1 );
       if (MB_SUCCESS != rval)
         return rval;
@@ -467,7 +469,7 @@
   }
   
     // store id data
-  MBRange elems2;
+  Range elems2;
   elems2.insert( start_handle, start_handle + num_elem - 1 );
   rval = mbIface->tag_set_data( id_tag, elems2, &ids[0] );
   if (MB_SUCCESS != rval)
@@ -476,3 +478,5 @@
   return MB_SUCCESS;
 }
   
+
+} // namespace moab

Modified: MOAB/trunk/src/io/ReadTetGen.hpp
===================================================================
--- MOAB/trunk/src/io/ReadTetGen.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadTetGen.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,10 +2,13 @@
 #define READ_TET_GEN_HPP
 
 #include <iosfwd>
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-class MBReadUtilIface;
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
 
+namespace moab {
+
+class ReadUtilIface;
+
 /* TetGen mesh data is typically split into two or three files:
  * name.node : node data
  * name.ele  : tet data
@@ -28,22 +31,22 @@
  *                                     name is zero-length, the attribute data
  *                                     will be disgarded.  
  */
-class ReadTetGen : public MBReaderIface
+class ReadTetGen : public ReaderIface
 {
    
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
     //! load a file
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions&,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -51,15 +54,15 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadTetGen(MBInterface* impl = NULL);
+  ReadTetGen(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadTetGen();
 
 private:
 
-  MBInterface* mbIface;
-  MBReadUtilIface* readTool;
+  Interface* mbIface;
+  ReadUtilIface* readTool;
 
   /**\brief Try to open one of several input files
    *
@@ -75,7 +78,7 @@
    *\param opts             Input options list.
    *\param file_stream      The stream to open for the file.
    */
-  MBErrorCode open_file( const std::string& input_file_name,
+  ErrorCode open_file( const std::string& input_file_name,
                          const std::string& input_name_base,
                          const std::string& input_name_suffix,
                          const char* file_type_suffix,
@@ -92,11 +95,11 @@
    *\param lineno Incremented for each real line read from the stream
    *              (including disgarded empty and comment lines.)
    */
-  MBErrorCode read_line( std::istream& file, std::string& line, int& lineno );
+  ErrorCode read_line( std::istream& file, std::string& line, int& lineno );
 
   /**\brief Read a line of double values from a file.
    */
-  MBErrorCode read_line( std::istream& file, 
+  ErrorCode read_line( std::istream& file, 
                          double* values_out, int num_values,
                          int& lineno );
 
@@ -116,22 +119,23 @@
    * \param group_designator Input: special tag name used to designate an
    *                    attribute as the group (surface or volume) ID.
    */
-  MBErrorCode parse_attr_list( const std::string& option_str,
-                               std::vector<MBTag>& tag_list,
+  ErrorCode parse_attr_list( const std::string& option_str,
+                               std::vector<Tag>& tag_list,
                                std::vector<int>& index_list,
                                const char* group_designator = 0 );
 
-  MBErrorCode read_node_file( std::istream& file, 
-                              const MBTag* attr_tag_list,
+  ErrorCode read_node_file( std::istream& file, 
+                              const Tag* attr_tag_list,
                               const int* attr_tag_index,
                               int attr_tag_list_len,
-                              std::vector<MBEntityHandle>& nodes );
+                              std::vector<EntityHandle>& nodes );
 
-  MBErrorCode read_elem_file( MBEntityType type,
+  ErrorCode read_elem_file( EntityType type,
                               std::istream& file, 
-                              const std::vector<MBEntityHandle>& nodes,
-                              MBRange& elems );
+                              const std::vector<EntityHandle>& nodes,
+                              Range& elems );
 };
 
+} // namespace moab
 
 #endif // defined(READ_TET_GEN_HPP)

Modified: MOAB/trunk/src/io/ReadVtk.cpp
===================================================================
--- MOAB/trunk/src/io/ReadVtk.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadVtk.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,48 +24,50 @@
 #include <string.h>
 
 #include "ReadVtk.hpp"
-#include "MBRange.hpp"
-#include "MBInternals.hpp"
-#include "MBInterface.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "Internals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "FileOptions.hpp"
 #include "FileTokenizer.hpp"
 #include "VtkUtil.hpp"
 
 #define MB_VTK_MATERIAL_SETS
 #ifdef MB_VTK_MATERIAL_SETS
-#  include "MBTagConventions.hpp"
+#  include "moab/MBTagConventions.hpp"
 #  include <map>
 
-class MBHash
+namespace moab {
+
+class Hash
 {
 public:
   unsigned long value;
 
-  MBHash()
+  Hash()
     {
     this->value = 5381L;
     }
-  MBHash( const unsigned char* bytes, size_t len )
+  Hash( const unsigned char* bytes, size_t len )
     { // djb2, a hash by dan bernstein presented on comp.lang.c for hashing strings.
     this->value = 5381L;
     for ( ; len ; -- len, ++ bytes )
       this->value = this->value * 33 + ( *bytes );
     }
-  MBHash( bool duh )
+  Hash( bool duh )
     {
     this->value = duh; // hashing a single bit with a long is stupid but easy.
     }
-  MBHash( const MBHash& src )
+  Hash( const Hash& src )
     {
     this->value = src.value;
     }
-  MBHash& operator = ( const MBHash& src )
+  Hash& operator = ( const Hash& src )
     {
     this->value = src.value;
     return *this;
     }
-  bool operator < ( const MBHash& other ) const
+  bool operator < ( const Hash& other ) const
     {
     return this->value < other.value;
     }
@@ -78,12 +80,12 @@
 // will be placed into the same set.
 // There will be no collisions when the opaque data is shorter than an
 // unsigned long, and this is really the only case we need to support.
-// The rest is bonus. MBHash does quite well with strings, even those
+// The rest is bonus. Hash does quite well with strings, even those
 // with identical prefixes.
-class MBModulator : public std::map<MBHash,MBEntityHandle>
+class Modulator : public std::map<Hash,EntityHandle>
 {
 public:
-  MBModulator( MBInterface* iface, std::string tag_name, MBDataType mb_type, size_t size, size_t per_elem )
+  Modulator( Interface* iface, std::string tag_name, DataType mb_type, size_t size, size_t per_elem )
     {
     this->mesh = iface;
     std::vector<unsigned char> default_val;
@@ -91,28 +93,28 @@
     this->mesh->tag_create( tag_name.c_str(), size, MB_TAG_SPARSE,
       mb_type, this->tag, &default_val[0], true );
     }
-  void add_entity( MBEntityHandle ent, const unsigned char* bytes, size_t len )
+  void add_entity( EntityHandle ent, const unsigned char* bytes, size_t len )
     {
-    MBHash h( bytes, len );
-    MBEntityHandle mset = this->congruence_class( h, bytes );
+    Hash h( bytes, len );
+    EntityHandle mset = this->congruence_class( h, bytes );
     this->mesh->add_entities( mset, &ent, 1 );
     }
-  void add_entities( MBRange& range, const unsigned char* bytes, size_t bytes_per_ent )
+  void add_entities( Range& range, const unsigned char* bytes, size_t bytes_per_ent )
     {
-    for( MBRange::iterator it = range.begin(); it != range.end(); ++ it, bytes += bytes_per_ent )
+    for( Range::iterator it = range.begin(); it != range.end(); ++ it, bytes += bytes_per_ent )
       {
-      MBHash h( bytes, bytes_per_ent );
-      MBEntityHandle mset = this->congruence_class( h, bytes );
+      Hash h( bytes, bytes_per_ent );
+      EntityHandle mset = this->congruence_class( h, bytes );
       this->mesh->add_entities( mset, &*it, 1 );
       }
     }
-  MBEntityHandle congruence_class( const MBHash& h, const void* tag_data )
+  EntityHandle congruence_class( const Hash& h, const void* tag_data )
     {
-    std::map<MBHash,MBEntityHandle>::iterator it = this->find( h );
+    std::map<Hash,EntityHandle>::iterator it = this->find( h );
     if ( it == this->end() )
       {
-      MBEntityHandle mset;
-      MBRange preexist;
+      EntityHandle mset;
+      Range preexist;
       this->mesh->get_entities_by_type_and_tag( 0, MBENTITYSET, &this->tag, &tag_data, 1, preexist );
       if ( preexist.size() )
         {
@@ -129,26 +131,26 @@
     return it->second;
     }
 
-  MBInterface* mesh;
-  MBTag tag;
+  Interface* mesh;
+  Tag tag;
 };
 #endif // MB_VTK_MATERIAL_SETS
 
-MBReaderIface* ReadVtk::factory( MBInterface* iface )
+ReaderIface* ReadVtk::factory( Interface* iface )
   { return new ReadVtk( iface ); }
 
-ReadVtk::ReadVtk(MBInterface* impl)
+ReadVtk::ReadVtk(Interface* impl)
     : mdbImpl(impl), mPartitionTagName(MATERIAL_SET_TAG_NAME)
 {
   void* ptr = 0;
-  mdbImpl->query_interface("MBReadUtilIface", &ptr);
-  readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  mdbImpl->query_interface("ReadUtilIface", &ptr);
+  readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
 }
 
 ReadVtk::~ReadVtk()
 {
   if (readMeshIface) {
-    mdbImpl->release_interface("MBReadUtilIface", readMeshIface);
+    mdbImpl->release_interface("ReadUtilIface", readMeshIface);
     readMeshIface = 0;
   }
 }
@@ -168,7 +170,7 @@
                                        0 };
 
 
-MBErrorCode ReadVtk::read_tag_values( const char* /* file_name */,
+ErrorCode ReadVtk::read_tag_values( const char* /* file_name */,
                                       const char* /* tag_name */,
                                       const FileOptions& /* opts */,
                                       std::vector<int>& /* tag_values_out */,
@@ -179,19 +181,19 @@
 }
 
 
-MBErrorCode ReadVtk::load_file( const char *filename,
-                                const MBEntityHandle* ,
+ErrorCode ReadVtk::load_file( const char *filename,
+                                const EntityHandle* ,
                                 const FileOptions& opts,
-                                const MBReaderIface::IDTag* subset_list,
+                                const ReaderIface::IDTag* subset_list,
                                 int subset_list_length,
-                                const MBTag* file_id_tag) 
+                                const Tag* file_id_tag) 
 {
-  MBErrorCode result;
+  ErrorCode result;
 
   int major, minor;
   char vendor_string[257];
-  std::vector<MBRange> element_list;
-  MBRange vertices;
+  std::vector<Range> element_list;
+  Range vertices;
   
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for VTK." );
@@ -270,12 +272,12 @@
   
     // Count the number of elements read
   long elem_count = 0;
-  for (std::vector<MBRange>::iterator it = element_list.begin(); it != element_list.end(); ++it )
+  for (std::vector<Range>::iterator it = element_list.begin(); it != element_list.end(); ++it )
     elem_count += it->size();
   
     // Read attribute data until end of file.
   const char* const block_type_names[] = { "POINT_DATA", "CELL_DATA", 0 };
-  std::vector<MBRange> vertex_list(1);
+  std::vector<Range> vertex_list(1);
   vertex_list[0] = vertices;
   int blocktype = 0;
   while (!tokens.eof())
@@ -330,13 +332,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::allocate_vertices( long num_verts,
-                                        MBEntityHandle& start_handle_out,
+ErrorCode ReadVtk::allocate_vertices( long num_verts,
+                                        EntityHandle& start_handle_out,
                                         double*& x_coord_array_out,
                                         double*& y_coord_array_out,
                                         double*& z_coord_array_out )
 {
-  MBErrorCode result;
+  ErrorCode result;
   
     // Create vertices
   std::vector<double*> arrays;
@@ -353,11 +355,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::read_vertices( FileTokenizer& tokens,
+ErrorCode ReadVtk::read_vertices( FileTokenizer& tokens,
                                     long num_verts, 
-                                    MBEntityHandle& start_handle_out )
+                                    EntityHandle& start_handle_out )
 {
-  MBErrorCode result;
+  ErrorCode result;
   double *x, *y, *z;
   
   result = allocate_vertices( num_verts, start_handle_out, x, y, z );
@@ -376,14 +378,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::allocate_elements( long num_elements,
+ErrorCode ReadVtk::allocate_elements( long num_elements,
                                         int vert_per_element,
-                                        MBEntityType type,
-                                        MBEntityHandle& start_handle_out,
-                                        MBEntityHandle*& conn_array_out,
-                                        std::vector<MBRange>& append_to_this )
+                                        EntityType type,
+                                        EntityHandle& start_handle_out,
+                                        EntityHandle*& conn_array_out,
+                                        std::vector<Range>& append_to_this )
 {
-  MBErrorCode result;
+  ErrorCode result;
   
   start_handle_out = 0;
   result = readMeshIface->get_element_array( num_elements,
@@ -395,14 +397,14 @@
   if (MB_SUCCESS != result)
     return result;
   
-  MBRange range(start_handle_out, start_handle_out+num_elements-1);
+  Range range(start_handle_out, start_handle_out+num_elements-1);
   append_to_this.push_back( range );
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::vtk_read_dataset( FileTokenizer& tokens,
-                                       MBRange& vertex_list,
-                                       std::vector<MBRange>& element_list )
+ErrorCode ReadVtk::vtk_read_dataset( FileTokenizer& tokens,
+                                       Range& vertex_list,
+                                       std::vector<Range>& element_list )
 {
   const char* const data_type_names[] = { "STRUCTURED_POINTS",
                                           "STRUCTURED_GRID",
@@ -426,14 +428,14 @@
 }
 
 
-MBErrorCode ReadVtk::vtk_read_structured_points( FileTokenizer& tokens, 
-                                                 MBRange& vertex_list,
-                                                 std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_read_structured_points( FileTokenizer& tokens, 
+                                                 Range& vertex_list,
+                                                 std::vector<Range>& elem_list )
 {
   long i, j, k;
   long dims[3];
   double origin[3], space[3];
-  MBErrorCode result;
+  ErrorCode result;
  
   if (!tokens.match_token( "DIMENSIONS" ) || 
       !tokens.get_long_ints( 3, dims ) ||
@@ -460,7 +462,7 @@
   
     // Create vertices
   double *x, *y, *z;
-  MBEntityHandle start_handle = 0;
+  EntityHandle start_handle = 0;
   long num_verts = dims[0]*dims[1]*dims[2];
   result = allocate_vertices( num_verts, start_handle, x, y, z );
   if (MB_SUCCESS != result)
@@ -479,12 +481,12 @@
   return vtk_create_structured_elems( dims, start_handle, elem_list );
 }
 
-MBErrorCode ReadVtk::vtk_read_structured_grid( FileTokenizer& tokens, 
-                                               MBRange& vertex_list,
-                                               std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_read_structured_grid( FileTokenizer& tokens, 
+                                               Range& vertex_list,
+                                               std::vector<Range>& elem_list )
 {
   long num_verts, dims[3];
-  MBErrorCode result;
+  ErrorCode result;
  
   if (!tokens.match_token( "DIMENSIONS" ) ||
       !tokens.get_long_ints( 3, dims )    ||
@@ -513,7 +515,7 @@
   }
   
     // Create and read vertices
-  MBEntityHandle start_handle = 0;
+  EntityHandle start_handle = 0;
   result = read_vertices( tokens, num_verts, start_handle );
   if (MB_SUCCESS != result)
     return result;
@@ -522,15 +524,15 @@
   return vtk_create_structured_elems( dims, start_handle, elem_list );
 }
 
-MBErrorCode ReadVtk::vtk_read_rectilinear_grid( FileTokenizer& tokens, 
-                                                MBRange& vertex_list,
-                                                std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_read_rectilinear_grid( FileTokenizer& tokens, 
+                                                Range& vertex_list,
+                                                std::vector<Range>& elem_list )
 {
   int i, j, k;
   long dims[3];
   const char* labels[] = { "X_COORDINATES", "Y_COORDINATES", "Z_COORDINATES" };
   std::vector<double> coords[3];
-  MBErrorCode result;
+  ErrorCode result;
   
   if (!tokens.match_token( "DIMENSIONS" )||
       !tokens.get_long_ints( 3, dims )   ||
@@ -567,7 +569,7 @@
   
     // Create vertices
   double *x, *y, *z;
-  MBEntityHandle start_handle = 0;
+  EntityHandle start_handle = 0;
   long num_verts = dims[0]*dims[1]*dims[2];
   result = allocate_vertices( num_verts, start_handle, x, y, z );
   if (MB_SUCCESS != result)
@@ -588,11 +590,11 @@
   return vtk_create_structured_elems( dims, start_handle, elem_list );
 }
 
-MBErrorCode ReadVtk::vtk_read_polydata( FileTokenizer& tokens, 
-                                        MBRange& vertex_list,
-                                        std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_read_polydata( FileTokenizer& tokens, 
+                                        Range& vertex_list,
+                                        std::vector<Range>& elem_list )
 {
-  MBErrorCode result;
+  ErrorCode result;
   long num_verts;
   std::vector<int> connectivity;
   const char* const poly_data_names[] = { "VERTICES",
@@ -615,7 +617,7 @@
   }
   
     // Create vertices and read coordinates
-  MBEntityHandle start_handle = 0;
+  EntityHandle start_handle = 0;
   result = read_vertices( tokens, num_verts, start_handle );
   if (MB_SUCCESS != result)
     return result;
@@ -653,21 +655,21 @@
   return result;
 }
 
-MBErrorCode ReadVtk::vtk_read_polygons( FileTokenizer& tokens,
-                                        MBEntityHandle first_vtx, 
-                                        std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_read_polygons( FileTokenizer& tokens,
+                                        EntityHandle first_vtx, 
+                                        std::vector<Range>& elem_list )
 {
-  MBErrorCode result;
+  ErrorCode result;
   long size[2];
   
   if (!tokens.get_long_ints( 2, size ) ||
       !tokens.get_newline( ))
     return MB_FAILURE;
 
-  const MBRange empty;
-  std::vector<MBEntityHandle> conn_hdl;
+  const Range empty;
+  std::vector<EntityHandle> conn_hdl;
   std::vector<long> conn_idx;
-  MBEntityHandle first = 0, prev = 0, handle;
+  EntityHandle first = 0, prev = 0, handle;
   for (int i = 0; i < size[0]; ++i) {
     long count;
     if (!tokens.get_long_ints( 1, &count ))
@@ -705,13 +707,13 @@
 
 
 
-MBErrorCode ReadVtk::vtk_read_unstructured_grid( FileTokenizer& tokens,
-                                                 MBRange& vertex_list,
-                                                 std::vector<MBRange>& elem_list  )
+ErrorCode ReadVtk::vtk_read_unstructured_grid( FileTokenizer& tokens,
+                                                 Range& vertex_list,
+                                                 std::vector<Range>& elem_list  )
 {
-  MBErrorCode result;
+  ErrorCode result;
   long i, num_verts, num_elems[2];
-  MBEntityHandle tmp_conn_list[27];
+  EntityHandle tmp_conn_list[27];
 
   if (!tokens.match_token( "POINTS" )        ||
       !tokens.get_long_ints( 1, &num_verts ) ||
@@ -726,7 +728,7 @@
   }
   
     // Create vertices and read coordinates
-  MBEntityHandle first_vertex = 0;
+  EntityHandle first_vertex = 0;
   result = read_vertices( tokens, num_verts, first_vertex );
   if (MB_SUCCESS != result)
     return result;
@@ -764,7 +766,7 @@
     if (vtk_type >= VtkUtil::numVtkElemType)
       return MB_FAILURE;
       
-    MBEntityType type = VtkUtil::vtkElemTypes[vtk_type].mb_type;
+    EntityType type = VtkUtil::vtkElemTypes[vtk_type].mb_type;
     if (type == MBMAXTYPE) {
       readMeshIface->report_error( "Unsupported VTK element type: %s (%d)\n",
                                    VtkUtil::vtkElemTypes[vtk_type].name, vtk_type );
@@ -791,15 +793,15 @@
     
       // Allocate element block
     long num_elem = end_id - id;
-    MBEntityHandle start_handle = 0;
-    MBEntityHandle* conn_array;
+    EntityHandle start_handle = 0;
+    EntityHandle* conn_array;
     
     result = allocate_elements( num_elem, num_vtx, type, start_handle,
                                 conn_array, elem_list );
     if (MB_SUCCESS != result)
       return result;
 
-    MBEntityHandle *conn_sav = conn_array;
+    EntityHandle *conn_sav = conn_array;
     
       // Store element connectivity
     for ( ; id < end_id; ++id)
@@ -836,8 +838,8 @@
       const unsigned* order = VtkUtil::vtkElemTypes[vtk_type].node_order;
       if ( order )
       {
-        assert( num_vtx * sizeof(MBEntityHandle) <= sizeof(tmp_conn_list) );
-        memcpy( tmp_conn_list, conn_array, num_vtx * sizeof(MBEntityHandle) );
+        assert( num_vtx * sizeof(EntityHandle) <= sizeof(tmp_conn_list) );
+        memcpy( tmp_conn_list, conn_array, num_vtx * sizeof(EntityHandle) );
         for (int j = 0; j < num_vtx; ++j)
           conn_array[order[j]] = tmp_conn_list[j];
       }       
@@ -854,11 +856,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::vtk_create_structured_elems( const long* dims, 
-                                            MBEntityHandle first_vtx,
-                                            std::vector<MBRange>& elem_list )
+ErrorCode ReadVtk::vtk_create_structured_elems( const long* dims, 
+                                            EntityHandle first_vtx,
+                                            std::vector<Range>& elem_list )
 {
-  MBErrorCode result;
+  ErrorCode result;
   int non_zero[3] = {0,0,0};  // True if dim > 0 for x, y, z respectively
   long elem_dim = 0;          // Element dimension (2->quad, 3->hex)
   long num_elems = 1;         // Total number of elements
@@ -876,7 +878,7 @@
   vert_per_elem = 1 << elem_dim;
   
     // Get element type from element dimension
-  MBEntityType type;
+  EntityType type;
   switch( elem_dim )
   {
     case 1: type = MBEDGE; break;
@@ -889,14 +891,14 @@
   }
 
     // Allocate storage for elements
-  MBEntityHandle start_handle = 0;
-  MBEntityHandle* conn_array;
+  EntityHandle start_handle = 0;
+  EntityHandle* conn_array;
   result = allocate_elements( num_elems, vert_per_elem, type, start_handle,
                               conn_array, elem_list );
   if (MB_SUCCESS != result)
     return MB_FAILURE;
 
-  MBEntityHandle *conn_sav = conn_array;
+  EntityHandle *conn_sav = conn_array;
   
     // Offsets of element vertices in grid relative to corner closest to origin 
   long k = dims[0]*dims[1];
@@ -920,7 +922,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::vtk_read_field( FileTokenizer& tokens )
+ErrorCode ReadVtk::vtk_read_field( FileTokenizer& tokens )
 {
     // This is not supported yet.
     // Parse the data but throw it away because
@@ -960,8 +962,8 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::vtk_read_attrib_data( FileTokenizer& tokens, 
-                                           std::vector<MBRange>& entities )
+ErrorCode ReadVtk::vtk_read_attrib_data( FileTokenizer& tokens, 
+                                           std::vector<Range>& entities )
 {
   const char* const type_names[] = { "SCALARS",
                                      "COLOR_SCALARS",
@@ -995,14 +997,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::vtk_read_tag_data( FileTokenizer& tokens, 
+ErrorCode ReadVtk::vtk_read_tag_data( FileTokenizer& tokens, 
                                         int type, 
                                         size_t per_elem, 
-                                        std::vector<MBRange>& entities,
+                                        std::vector<Range>& entities,
                                         const char* name )
 {
-  MBErrorCode result;
-  MBDataType mb_type;
+  ErrorCode result;
+  DataType mb_type;
   size_t size;
   if (type == 1)
   {
@@ -1030,15 +1032,15 @@
   }
 
 #ifdef MB_VTK_MATERIAL_SETS
-  MBModulator materialMap( this->mdbImpl, this->mPartitionTagName, mb_type, size, per_elem );
+  Modulator materialMap( this->mdbImpl, this->mPartitionTagName, mb_type, size, per_elem );
   bool isMaterial =
-    size * per_elem <= 4 &&                            // must have int-sized values (MBParallelComm requires it)
+    size * per_elem <= 4 &&                            // must have int-sized values (ParallelComm requires it)
     ! this->mPartitionTagName.empty() &&               // must have a non-empty field name...
     ! strcmp( name, this->mPartitionTagName.c_str() ); // ... that matches our spec.
 #endif // MB_VTK_MATERIAL_SETS
   
     // get/create tag
-  MBTag handle;
+  Tag handle;
   result = mdbImpl->tag_get_handle ( name, handle );
   if (result == MB_TAG_NOT_FOUND)
   {
@@ -1052,7 +1054,7 @@
   else if (result == MB_SUCCESS)
   {
     int existing_size;
-    MBDataType existing_type;
+    DataType existing_type;
     
     result = mdbImpl->tag_get_size( handle, existing_size );
     if (MB_SUCCESS != result)
@@ -1078,7 +1080,7 @@
  
     // Count number of entities
   long count = 0;
-  std::vector<MBRange>::iterator iter;
+  std::vector<Range>::iterator iter;
   for (iter = entities.begin(); iter != entities.end(); ++iter)
     count += iter->size();
 
@@ -1094,7 +1096,7 @@
       }
       
       bool* data_iter = data;
-      MBRange::iterator ent_iter = iter->begin();
+      Range::iterator ent_iter = iter->begin();
       for ( ; ent_iter != iter->end(); ++ent_iter)
       {
         unsigned char bits = 0;
@@ -1157,8 +1159,8 @@
 }
   
 
-MBErrorCode ReadVtk::vtk_read_scalar_attrib( FileTokenizer& tokens, 
-                                             std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_scalar_attrib( FileTokenizer& tokens, 
+                                             std::vector<Range>& entities,
                                              const char* name)
 {
   int type = tokens.match_token( vtk_type_names );
@@ -1195,8 +1197,8 @@
 }
 
 
-MBErrorCode ReadVtk::vtk_read_color_attrib( FileTokenizer& tokens, 
-                                            std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_color_attrib( FileTokenizer& tokens, 
+                                            std::vector<Range>& entities,
                                             const char* name)
 {
   long size;
@@ -1206,8 +1208,8 @@
   return vtk_read_tag_data( tokens, 10, size, entities, name );
 }
 
-MBErrorCode ReadVtk::vtk_read_vector_attrib( FileTokenizer& tokens, 
-                                             std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_vector_attrib( FileTokenizer& tokens, 
+                                             std::vector<Range>& entities,
                                              const char* name)
 {
   int type = tokens.match_token( vtk_type_names );
@@ -1217,8 +1219,8 @@
   return vtk_read_tag_data( tokens, type, 3, entities, name );
 }
 
-MBErrorCode ReadVtk::vtk_read_texture_attrib( FileTokenizer& tokens,
-                                              std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_texture_attrib( FileTokenizer& tokens,
+                                              std::vector<Range>& entities,
                                               const char* name)
 {
   int type, dim;
@@ -1236,8 +1238,8 @@
   return vtk_read_tag_data( tokens, type, dim, entities, name );
 }
 
-MBErrorCode ReadVtk::vtk_read_tensor_attrib( FileTokenizer& tokens,
-                                             std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_tensor_attrib( FileTokenizer& tokens,
+                                             std::vector<Range>& entities,
                                              const char* name ) 
 {
   int type = tokens.match_token( vtk_type_names );
@@ -1247,8 +1249,8 @@
   return vtk_read_tag_data( tokens, type, 9, entities, name );
 }  
 
-MBErrorCode ReadVtk::vtk_read_field_attrib( FileTokenizer& tokens, 
-                                            std::vector<MBRange>& entities,
+ErrorCode ReadVtk::vtk_read_field_attrib( FileTokenizer& tokens, 
+                                            std::vector<Range>& entities,
                                             const char* )
 {
   long num_fields;
@@ -1276,7 +1278,7 @@
     if (!type)
       return MB_FAILURE;
 
-    MBErrorCode result;
+    ErrorCode result;
     if ( ( result = vtk_read_tag_data( tokens, type, num_comp, entities, name_alloc.c_str() ) ) != MB_SUCCESS )
       {
       readMeshIface->report_error(
@@ -1289,10 +1291,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ReadVtk::store_file_ids( MBTag tag, const MBRange& verts,
-                                     const std::vector<MBRange>& elems )
+ErrorCode ReadVtk::store_file_ids( Tag tag, const Range& verts,
+                                     const std::vector<Range>& elems )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   rval = readMeshIface->assign_ids( tag, verts );
   if (MB_SUCCESS != rval)
@@ -1307,5 +1309,7 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
+
     
     

Modified: MOAB/trunk/src/io/ReadVtk.hpp
===================================================================
--- MOAB/trunk/src/io/ReadVtk.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/ReadVtk.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,30 +16,32 @@
 #ifndef READ_VTK_HPP
 #define READ_VTK_HPP
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
 
 #include <string>
 
-class MBReadUtilIface;
+namespace moab {
+
+class ReadUtilIface;
 class FileTokenizer;
 
-class ReadVtk : public MBReaderIface
+class ReadVtk : public ReaderIface
 {
    
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
     //! load a file
-  MBErrorCode load_file( const char *file_name,
-                         const MBEntityHandle* file_set,
+  ErrorCode load_file( const char *file_name,
+                         const EntityHandle* file_set,
                          const FileOptions&,
-                         const MBReaderIface::IDTag* subset_list = 0,
+                         const ReaderIface::IDTag* subset_list = 0,
                          int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
+                         const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
@@ -47,117 +49,119 @@
                                int subset_list_length = 0 );
   
     //! Constructor
-  ReadVtk(MBInterface* impl = NULL);
+  ReadVtk(Interface* impl = NULL);
 
    //! Destructor
   virtual ~ReadVtk();
 
 protected:
 
-  MBErrorCode allocate_vertices( long num_vtx,
-                                 MBEntityHandle& start_handle_out,
+  ErrorCode allocate_vertices( long num_vtx,
+                                 EntityHandle& start_handle_out,
                                  double*& x_coord_array_out,
                                  double*& y_coord_array_out,
                                  double*& z_coord_array_out );
 
-  MBErrorCode read_vertices( FileTokenizer& tokens,
+  ErrorCode read_vertices( FileTokenizer& tokens,
                              long num_verts, 
-                             MBEntityHandle& start_handle_out );
+                             EntityHandle& start_handle_out );
 
-  MBErrorCode allocate_elements( long num_elements,
+  ErrorCode allocate_elements( long num_elements,
                                  int vert_per_element,
-                                 MBEntityType type,
-                                 MBEntityHandle& start_handle_out,
-                                 MBEntityHandle*& conn_array_out,
-                                 std::vector<MBRange>& append_to_this );
+                                 EntityType type,
+                                 EntityHandle& start_handle_out,
+                                 EntityHandle*& conn_array_out,
+                                 std::vector<Range>& append_to_this );
 
-  MBErrorCode vtk_read_dataset( FileTokenizer& tokens,
-                                MBRange& vertex_list,
-                                std::vector<MBRange>& element_list );
+  ErrorCode vtk_read_dataset( FileTokenizer& tokens,
+                                Range& vertex_list,
+                                std::vector<Range>& element_list );
 
-  MBErrorCode vtk_read_structured_points( FileTokenizer& tokens, 
-                                          MBRange& vertex_list,
-                                          std::vector<MBRange>& elem_list );
+  ErrorCode vtk_read_structured_points( FileTokenizer& tokens, 
+                                          Range& vertex_list,
+                                          std::vector<Range>& elem_list );
 
-  MBErrorCode vtk_read_structured_grid( FileTokenizer& tokens, 
-                                        MBRange& vertex_list,
-                                        std::vector<MBRange>& elem_list );
+  ErrorCode vtk_read_structured_grid( FileTokenizer& tokens, 
+                                        Range& vertex_list,
+                                        std::vector<Range>& elem_list );
 
-  MBErrorCode vtk_read_rectilinear_grid( FileTokenizer& tokens, 
-                                         MBRange& vertex_list,
-                                         std::vector<MBRange>& elem_list );
+  ErrorCode vtk_read_rectilinear_grid( FileTokenizer& tokens, 
+                                         Range& vertex_list,
+                                         std::vector<Range>& elem_list );
                                          
-  MBErrorCode vtk_read_polydata( FileTokenizer& tokens, 
-                                 MBRange& vertex_list,
-                                 std::vector<MBRange>& elem_list );
+  ErrorCode vtk_read_polydata( FileTokenizer& tokens, 
+                                 Range& vertex_list,
+                                 std::vector<Range>& elem_list );
                                  
-  MBErrorCode vtk_read_polygons( FileTokenizer& tokens,
-                                 MBEntityHandle first_vtx, 
-                                 std::vector<MBRange>& elem_list );
+  ErrorCode vtk_read_polygons( FileTokenizer& tokens,
+                                 EntityHandle first_vtx, 
+                                 std::vector<Range>& elem_list );
 
-  MBErrorCode vtk_read_unstructured_grid( FileTokenizer& tokens,
-                                          MBRange& vertex_list,
-                                          std::vector<MBRange>& elem_list  );
+  ErrorCode vtk_read_unstructured_grid( FileTokenizer& tokens,
+                                          Range& vertex_list,
+                                          std::vector<Range>& elem_list  );
 
-  MBErrorCode vtk_create_structured_elems( const long* dims, 
-                                           MBEntityHandle first_vtx,
-                                           std::vector<MBRange>& elem_list );
+  ErrorCode vtk_create_structured_elems( const long* dims, 
+                                           EntityHandle first_vtx,
+                                           std::vector<Range>& elem_list );
 
-  MBErrorCode vtk_read_field( FileTokenizer& tokens );
+  ErrorCode vtk_read_field( FileTokenizer& tokens );
 
-  MBErrorCode vtk_read_attrib_data( FileTokenizer& tokens, 
-                                    std::vector<MBRange>& entities );
+  ErrorCode vtk_read_attrib_data( FileTokenizer& tokens, 
+                                    std::vector<Range>& entities );
 
-  MBErrorCode vtk_read_tag_data( FileTokenizer& tokens, 
+  ErrorCode vtk_read_tag_data( FileTokenizer& tokens, 
                                  int type, 
                                  size_t per_elem, 
-                                 std::vector<MBRange>& entities,
+                                 std::vector<Range>& entities,
                                  const char* name );
 
-  MBErrorCode vtk_read_scalar_attrib( FileTokenizer& tokens, 
-                                      std::vector<MBRange>& entities,
+  ErrorCode vtk_read_scalar_attrib( FileTokenizer& tokens, 
+                                      std::vector<Range>& entities,
                                       const char* name);
 
-  MBErrorCode vtk_read_color_attrib( FileTokenizer& tokens, 
-                                     std::vector<MBRange>& entities,
+  ErrorCode vtk_read_color_attrib( FileTokenizer& tokens, 
+                                     std::vector<Range>& entities,
                                      const char* name);
 
-  MBErrorCode vtk_read_vector_attrib( FileTokenizer& tokens, 
-                                      std::vector<MBRange>& entities,
+  ErrorCode vtk_read_vector_attrib( FileTokenizer& tokens, 
+                                      std::vector<Range>& entities,
                                       const char* name);
 
-  MBErrorCode vtk_read_texture_attrib( FileTokenizer& tokens,
-                                       std::vector<MBRange>& entities,
+  ErrorCode vtk_read_texture_attrib( FileTokenizer& tokens,
+                                       std::vector<Range>& entities,
                                        const char* name);
 
-  MBErrorCode vtk_read_tensor_attrib( FileTokenizer& tokens,
-                                      std::vector<MBRange>& entities,
+  ErrorCode vtk_read_tensor_attrib( FileTokenizer& tokens,
+                                      std::vector<Range>& entities,
                                       const char* name );
 
-  MBErrorCode vtk_read_field_attrib( FileTokenizer& tokens, 
-                                     std::vector<MBRange>& entities,
+  ErrorCode vtk_read_field_attrib( FileTokenizer& tokens, 
+                                     std::vector<Range>& entities,
                                      const char* name);
 
-  MBErrorCode store_file_ids( MBTag tag,
-                              const MBRange& vertices,
-                              const std::vector<MBRange>& elements );
+  ErrorCode store_file_ids( Tag tag,
+                              const Range& vertices,
+                              const std::vector<Range>& elements );
 
 private:
 
-  MBReadUtilIface* readMeshIface;
+  ReadUtilIface* readMeshIface;
 
   //------------member variables ------------//
 
     //! interface instance
-  MBInterface* mdbImpl;
+  Interface* mdbImpl;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
     //! A field which, if present and having a single integer for storage, should be used to partition the mesh by range. Defaults to MATERIAL_SET_TAG_NAME
   std::string mPartitionTagName;
 };
 
+} // namespace moab
+
 #endif
 
 

Modified: MOAB/trunk/src/io/SMF_State.cpp
===================================================================
--- MOAB/trunk/src/io/SMF_State.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/SMF_State.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,8 +4,9 @@
 #include <cstring>
 #include <cstdlib>
 
-inline int streq(const char *a,const char *b) { return std::strcmp(a,b)==0; }
+static inline int streq(const char *a,const char *b) { return std::strcmp(a,b)==0; }
 
+namespace moab {
 
 SMF_State::SMF_State(const SMF_ivars& ivar, SMF_State *link)
 {
@@ -19,7 +20,7 @@
     else
     {
 	vertex_correction = 0;
-        MBAffineXform identity;
+        AffineXform identity;
 	xform = identity;
     }
 
@@ -54,17 +55,19 @@
 	vertex_correction = atoi(argv[1].c_str());
 }
 
-void SMF_State::mmult(const MBAffineXform &M)
+void SMF_State::mmult(const AffineXform &M)
 {
     // initially, we tried this:
     // xform.accumulate(M);
     // maybe we should do M.accumulate(xform) 
-    MBAffineXform tmp=M;
+    AffineXform tmp=M;
     tmp.accumulate(xform);
     xform = tmp;
 }
 
-void SMF_State::mload(const MBAffineXform& M)
+void SMF_State::mload(const AffineXform& M)
 {
     xform = M;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/SMF_State.hpp
===================================================================
--- MOAB/trunk/src/io/SMF_State.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/SMF_State.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,12 @@
 #ifndef GFXSMF_STATE_INCLUDED // -*- C++ -*-
 #define GFXSMF_STATE_INCLUDED
 
-#include "MBAffineXform.hpp"
+#include "AffineXform.hpp"
 #include <string>
 #include <vector>
 
+namespace moab {
+
 struct SMF_ivars
 {
     int next_vertex;
@@ -20,7 +22,7 @@
     // Standard state variables
     int first_vertex;
     int vertex_correction;
-    MBAffineXform xform;
+    AffineXform xform;
 
 public:
     SMF_State(const SMF_ivars& ivar,SMF_State *link=NULL);
@@ -30,14 +32,15 @@
     void inc(const char *var, int delta=1);
     void dec(const char *var, int delta=1);
 
-    void mmult(const MBAffineXform&);
-    void mload(const MBAffineXform&);
+    void mmult(const AffineXform&);
+    void mload(const AffineXform&);
 
     void vertex(double v[3]);
     void normal(double n[3]);
     void face(int *, const SMF_ivars& ivar);
 };
 
+} // namespace moab
 
 // GFXSMF_STATE_INCLUDED
 #endif

Modified: MOAB/trunk/src/io/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/src/io/Tqdcfr.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/Tqdcfr.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,38 +14,40 @@
  */
 
 #include "Tqdcfr.hpp"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include "FileOptions.hpp"
 #include <iostream>
 
 #ifdef USE_MPI
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #endif
 
 #ifndef TEST_TQDCFR
 
-#include "MBReadUtilIface.hpp"
-#include "GeomTopoTool.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
-#include "HigherOrderFactory.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/GeomTopoTool.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
+#include "moab/HigherOrderFactory.hpp"
 #include "exodus_order.h"
 
 #include <sstream>
 #include <assert.h>
 #include <string.h>
 
+namespace moab {
+
 const bool debug = false;
 const int ACIS_DIMS[] = {-1, 3, -1, 2, -1, -1, 1, 0, -1, -1};
 const char Tqdcfr::geom_categories[][CATEGORY_TAG_SIZE] = 
 {"Vertex\0", "Curve\0", "Surface\0", "Volume\0"};
-const MBEntityType Tqdcfr::group_type_to_mb_type[] = {
+const EntityType Tqdcfr::group_type_to_mb_type[] = {
   MBENTITYSET, MBENTITYSET, MBENTITYSET, // group, body, volume
   MBENTITYSET, MBENTITYSET, MBENTITYSET, // surface, curve, vertex
   MBHEX, MBTET, MBPYRAMID, MBQUAD, MBTRI, MBEDGE, MBVERTEX};
-const MBEntityType Tqdcfr::block_type_to_mb_type[] = {
+const EntityType Tqdcfr::block_type_to_mb_type[] = {
   MBVERTEX, // sphere
   MBEDGE, MBEDGE, MBEDGE, // bars
   MBEDGE, MBEDGE, MBEDGE, // beams
@@ -63,7 +65,7 @@
 };
 
 // mapping from mesh packet type to moab type
-const MBEntityType Tqdcfr::mp_type_to_mb_type[] = {
+const EntityType Tqdcfr::mp_type_to_mb_type[] = {
   MBHEX, MBHEX, MBHEX, MBHEX, MBHEX, MBHEX, MBHEX, MBHEX, 
   MBTET, MBTET, MBTET, MBTET, MBTET, MBTET, MBTET, MBTET, 
   MBPYRAMID, MBPYRAMID, MBPYRAMID, MBPYRAMID, 
@@ -88,7 +90,7 @@
   0};
 
 // Define node-order map from Cubit to MBCN.  Table is indexed
-// by MBEntityType and number of nodes.  Entries are NULL if Cubit order
+// by EntityType and number of nodes.  Entries are NULL if Cubit order
 // is the same as MBCN ordering.  Non-null entries contain the
 // index into the MOAB node order for the corresponding vertex
 // in the Cubit connectivity list.  Thus for a 27-node hex:
@@ -159,10 +161,10 @@
     int_buf[i] = uint_buf[i];
 }
 
-MBReaderIface* Tqdcfr::factory( MBInterface* iface )
+ReaderIface* Tqdcfr::factory( Interface* iface )
 { return new Tqdcfr( iface ); }
 
-Tqdcfr::Tqdcfr(MBInterface *impl) 
+Tqdcfr::Tqdcfr(Interface *impl) 
     : cubFile(NULL), globalIdTag(0), geomTag(0), uniqueIdTag(0), 
       blockTag(0), nsTag(0), ssTag(0), attribVectorTag(0), entityNameTag(0),
       categoryTag(0), hasMidNodesTag(0), printedSeqWarning(false), printedElemWarning(false)
@@ -170,12 +172,12 @@
   assert(NULL != impl);
   mdbImpl = impl;
   void* ptr = 0;
-  impl->query_interface( "MBReadUtilIface", &ptr );
+  impl->query_interface( "ReadUtilIface", &ptr );
   assert(NULL != ptr);
-  readUtilIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  readUtilIface = reinterpret_cast<ReadUtilIface*>(ptr);
 
   currVHandleOffset = -1;
-  for (MBEntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++)
+  for (EntityType this_type = MBVERTEX; this_type < MBMAXTYPE; this_type++)
     currElementIdOffset[this_type] = -1;
 
   mdbImpl->tag_get_handle(MATERIAL_SET_TAG_NAME, blockTag);
@@ -187,7 +189,7 @@
 
 Tqdcfr::~Tqdcfr() 
 {
-  std::string iface_name = "MBReadUtilIface";
+  std::string iface_name = "ReadUtilIface";
   mdbImpl->release_interface(iface_name, readUtilIface);
 
   if (NULL != cubMOABVertexMap) delete cubMOABVertexMap;
@@ -195,7 +197,7 @@
 }
 
 
-MBErrorCode Tqdcfr::read_tag_values( const char* /* file_name */,
+ErrorCode Tqdcfr::read_tag_values( const char* /* file_name */,
                                      const char* /* tag_name */,
                                      const FileOptions& /* opts */,
                                      std::vector<int>& /* tag_values_out */,
@@ -205,14 +207,14 @@
   return MB_NOT_IMPLEMENTED;
 }
 
-MBErrorCode Tqdcfr::load_file(const char *file_name,
-                              const MBEntityHandle* ,
+ErrorCode Tqdcfr::load_file(const char *file_name,
+                              const EntityHandle* ,
                               const FileOptions& opts,
-                              const MBReaderIface::IDTag* subset_list,
+                              const ReaderIface::IDTag* subset_list,
                               int subset_list_length,
-                              const MBTag* file_id_tag) 
+                              const Tag* file_id_tag) 
 {
-  MBErrorCode result;
+  ErrorCode result;
 
   if (subset_list && subset_list_length) {
     readUtilIface->report_error( "Reading subset of files not supported for CUB files." );
@@ -384,7 +386,7 @@
     // convert blocks to nodesets/sidesets if tag is set
   result = convert_nodesets_sidesets();
   
-  MBRange after_ents;
+  Range after_ents;
   result = mdbImpl->get_entities_by_handle(0, after_ents);
   if (MB_SUCCESS != result) 
     return result;
@@ -397,14 +399,14 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::convert_nodesets_sidesets() 
+ErrorCode Tqdcfr::convert_nodesets_sidesets() 
 {
 
     // look first for the nodeset and sideset offset flags; if they're not
     // set, we don't need to convert
   unsigned int nodeset_offset, sideset_offset;
-  MBTag tmp_tag;
-  MBErrorCode result = mdbImpl->tag_get_handle(BLOCK_NODESET_OFFSET_TAG_NAME,
+  Tag tmp_tag;
+  ErrorCode result = mdbImpl->tag_get_handle(BLOCK_NODESET_OFFSET_TAG_NAME,
                                                tmp_tag);
   if (MB_SUCCESS != result) nodeset_offset = 0;
   else {
@@ -423,7 +425,7 @@
   if (0 == nodeset_offset && 0 == sideset_offset) return MB_SUCCESS;
 
     // look for all blocks
-  MBRange blocks;
+  Range blocks;
   result = mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET,
                                                  &blockTag, NULL, 1,
                                                  blocks);
@@ -435,8 +437,8 @@
   if (MB_SUCCESS != result) return result;
 
   unsigned int i = 0;
-  MBRange::iterator rit = blocks.begin();
-  MBRange new_nodesets, new_sidesets;
+  Range::iterator rit = blocks.begin();
+  Range new_nodesets, new_sidesets;
   std::vector<int> new_nodeset_ids, new_sideset_ids;
   for (; rit != blocks.end(); i++, rit++) {
     if (0 != nodeset_offset && block_ids[i] >= (int) nodeset_offset && 
@@ -455,7 +457,7 @@
 
     // ok, have the new nodesets and sidesets; now remove the block tags, and
     // add nodeset and sideset tags
-  MBErrorCode tmp_result = MB_SUCCESS;
+  ErrorCode tmp_result = MB_SUCCESS;
   if (0 != nodeset_offset) {
     if (0 == nsTag) {
       int default_val = 0;
@@ -488,7 +490,7 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::read_nodeset(Tqdcfr::ModelEntry *model,
+ErrorCode Tqdcfr::read_nodeset(Tqdcfr::ModelEntry *model,
                                  Tqdcfr::NodesetHeader *nodeseth)  
 {
   if (nodeseth->memTypeCt == 0) return MB_SUCCESS;
@@ -498,7 +500,7 @@
   
     // read ids for each entity type
   unsigned int this_type, num_ents;
-  std::vector<MBEntityHandle> ns_entities, excl_entities;
+  std::vector<EntityHandle> ns_entities, excl_entities;
   for (unsigned int i = 0; i < nodeseth->memTypeCt; i++) {
       // get how many and what type
     FREADI(2);
@@ -509,19 +511,19 @@
     FREADI(num_ents);
     CONVERT_TO_INTS(num_ents);
     
-    MBErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
+    ErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
                                       ns_entities, excl_entities);
     if (MB_SUCCESS != result) return result;
   }
 
     // and put entities into this nodeset's set
-  MBErrorCode result = put_into_set(nodeseth->setHandle, ns_entities, excl_entities);
+  ErrorCode result = put_into_set(nodeseth->setHandle, ns_entities, excl_entities);
   if (MB_SUCCESS != result) return result;
 
   return result;
 }
 
-MBErrorCode Tqdcfr::read_sideset(const double data_version,
+ErrorCode Tqdcfr::read_sideset(const double data_version,
                                  Tqdcfr::ModelEntry *model,
                                  Tqdcfr::SidesetHeader *sideseth)  
 {
@@ -533,7 +535,7 @@
     // read ids for each entity type
   unsigned int this_type, num_ents, sense_size;
 
-  std::vector<MBEntityHandle> ss_entities, excl_entities;
+  std::vector<EntityHandle> ss_entities, excl_entities;
   std::vector<double> ss_dfs;
   if (data_version <= 1.0) {
     for (unsigned int i = 0; i < sideseth->memTypeCt; i++) {
@@ -547,7 +549,7 @@
       FREADI(num_ents);
       CONVERT_TO_INTS(num_ents);
     
-      MBErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
+      ErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
                                         ss_entities, excl_entities);
       if (MB_SUCCESS != result) return result;
 
@@ -579,8 +581,8 @@
       FREADIA(num_ents, &mem_types[0]);
       FREADI(num_ents);
 
-      std::vector<MBEntityHandle> ss_entities;
-      MBErrorCode result = get_entities(&mem_types[0], &int_buf[0], num_ents, false,
+      std::vector<EntityHandle> ss_entities;
+      ErrorCode result = get_entities(&mem_types[0], &int_buf[0], num_ents, false,
                                         ss_entities);
       if (MB_SUCCESS != result) return result;
 
@@ -603,8 +605,8 @@
   if (sideseth->numDF > 0) {
       // have to read dist factors
     FREADD(sideseth->numDF);
-    MBTag distFactorTag;
-    MBErrorCode result = mdbImpl->tag_create_variable_length( "distFactor", 
+    Tag distFactorTag;
+    ErrorCode result = mdbImpl->tag_create_variable_length( "distFactor", 
                                                                MB_TAG_SPARSE,
                                                                MB_TYPE_DOUBLE,
                                                                distFactorTag );
@@ -618,12 +620,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::process_sideset_10(const int this_type, const int num_ents,
+ErrorCode Tqdcfr::process_sideset_10(const int this_type, const int num_ents,
                                        const int sense_size,
-                                       std::vector<MBEntityHandle> &ss_entities,
+                                       std::vector<EntityHandle> &ss_entities,
                                        Tqdcfr::SidesetHeader *sideseth) 
 {
-  std::vector<MBEntityHandle> forward, reverse;
+  std::vector<EntityHandle> forward, reverse;
   if (this_type == 3 // surface
       && sense_size == 1 // byte size 
       ) {
@@ -651,20 +653,20 @@
   }
   
     // now actually put them in the set
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   if (!forward.empty()) {
-    MBErrorCode tmp_result = mdbImpl->add_entities(sideseth->setHandle, &forward[0], forward.size());
+    ErrorCode tmp_result = mdbImpl->add_entities(sideseth->setHandle, &forward[0], forward.size());
     if (tmp_result != MB_SUCCESS) result = tmp_result;
   }
   if (!reverse.empty()) {
       // need to make a new set, add a reverse sense tag, then add to the sideset
-    MBEntityHandle reverse_set;
-    MBErrorCode tmp_result = create_set(reverse_set);
+    EntityHandle reverse_set;
+    ErrorCode tmp_result = create_set(reverse_set);
     if (MB_SUCCESS != tmp_result) result = tmp_result;
     tmp_result = mdbImpl->add_entities(reverse_set, &reverse[0], reverse.size());
     if (tmp_result != MB_SUCCESS) result = tmp_result;
     int def_val = 1;
-    MBTag sense_tag;
+    Tag sense_tag;
     tmp_result = mdbImpl->tag_create("SENSE", sizeof(int), 
                                      MB_TAG_SPARSE, MB_TYPE_INTEGER, sense_tag, &def_val);
     if (tmp_result != MB_SUCCESS && tmp_result != MB_ALREADY_ALLOCATED) result = tmp_result;
@@ -678,11 +680,11 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::process_sideset_11(std::vector<MBEntityHandle> &ss_entities,
+ErrorCode Tqdcfr::process_sideset_11(std::vector<EntityHandle> &ss_entities,
                                        int num_wrts,
                                        Tqdcfr::SidesetHeader *sideseth)
 {
-  std::vector<MBEntityHandle> forward, reverse;
+  std::vector<EntityHandle> forward, reverse;
 
   unsigned int num_ents = ss_entities.size();
   unsigned int *wrt_it = &uint_buf[0];
@@ -709,20 +711,20 @@
   }
   
     // now actually put them in the set
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   if (!forward.empty()) {
-    MBErrorCode tmp_result = mdbImpl->add_entities(sideseth->setHandle, &forward[0], forward.size());
+    ErrorCode tmp_result = mdbImpl->add_entities(sideseth->setHandle, &forward[0], forward.size());
     if (tmp_result != MB_SUCCESS) result = tmp_result;
   }
   if (!reverse.empty()) {
       // need to make a new set, add a reverse sense tag, then add to the sideset
-    MBEntityHandle reverse_set;
-    MBErrorCode tmp_result = create_set(reverse_set);
+    EntityHandle reverse_set;
+    ErrorCode tmp_result = create_set(reverse_set);
     if (MB_SUCCESS != tmp_result) result = tmp_result;
     tmp_result = mdbImpl->add_entities(reverse_set, &reverse[0], reverse.size());
     if (tmp_result != MB_SUCCESS) result = tmp_result;
     int def_val = 1;
-    MBTag sense_tag;
+    Tag sense_tag;
     tmp_result = mdbImpl->tag_create("SENSE", sizeof(int), 
                                      MB_TAG_SPARSE, MB_TYPE_INTEGER, sense_tag, &def_val);
     if (tmp_result != MB_SUCCESS && tmp_result != MB_ALREADY_ALLOCATED) result = tmp_result;
@@ -736,7 +738,7 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::read_block(const double data_version,
+ErrorCode Tqdcfr::read_block(const double data_version,
                                Tqdcfr::ModelEntry *model,
                                Tqdcfr::BlockHeader *blockh)  
 {
@@ -747,7 +749,7 @@
   
     // read ids for each entity type
   int this_type, num_ents;
-  std::vector<MBEntityHandle> block_entities, excl_entities;
+  std::vector<EntityHandle> block_entities, excl_entities;
   for (unsigned int i = 0; i < blockh->memTypeCt; i++) {
       // get how many and what type
     FREADI(2);
@@ -758,22 +760,22 @@
     FREADI(num_ents);
     CONVERT_TO_INTS(num_ents);
 
-    MBErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
+    ErrorCode result = get_entities(this_type+2, &int_buf[0], num_ents, 
                                       block_entities, excl_entities);
     if (MB_SUCCESS != result) return result;
   }
   
     // and put entities into this block's set
-  MBErrorCode result = put_into_set(blockh->setHandle, block_entities, excl_entities);
+  ErrorCode result = put_into_set(blockh->setHandle, block_entities, excl_entities);
   if (MB_SUCCESS != result) return result;
   
     // read attribs if there are any
   if (blockh->attribOrder > 0) {
-    MBTag block_attribs;
+    Tag block_attribs;
     
     FREADD(blockh->attribOrder);
       // now do something with them...
-    MBErrorCode result = mdbImpl->tag_create("Block_Attributes", 
+    ErrorCode result = mdbImpl->tag_create("Block_Attributes", 
                                              blockh->attribOrder*sizeof(double), MB_TAG_SPARSE, 
                                              MB_TYPE_DOUBLE, block_attribs, NULL);
     if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
@@ -791,21 +793,21 @@
   if (MBCN::VerticesPerEntity(blockh->blockEntityType) == node_per_elem)
     return MB_SUCCESS;
   
-    // Can't use MBInterface::convert_entities because block could contain
+    // Can't use Interface::convert_entities because block could contain
     // both entity sets and entities.  convert_entities will fail if block
     // contains an entity set, but we still need to call it on any elements
     // directly in the block (rather than a geometry subset).  So bypass
-    // MBInterface and call HOFactory directly with an MBRange of entities.
-  MBRange entities;
+    // Interface and call HOFactory directly with an Range of entities.
+  Range entities;
   mdbImpl->get_entities_by_type( blockh->setHandle, blockh->blockEntityType, entities, true );
   
   int mid_nodes[4];
   MBCN::HasMidNodes( blockh->blockEntityType, node_per_elem, mid_nodes );
-  HigherOrderFactory ho_fact( dynamic_cast<MBCore*>(mdbImpl), 0 );
+  HigherOrderFactory ho_fact( dynamic_cast<Core*>(mdbImpl), 0 );
   return ho_fact.convert( entities, !!mid_nodes[1], !!mid_nodes[2], !!mid_nodes[3] );
 }
 
-MBErrorCode Tqdcfr::read_group(const unsigned int group_index,
+ErrorCode Tqdcfr::read_group(const unsigned int group_index,
                                Tqdcfr::ModelEntry *model,
                                Tqdcfr::GroupHeader *grouph)  
 {
@@ -815,7 +817,7 @@
   
     // read ids for each entity type
   int this_type, num_ents;
-  std::vector<MBEntityHandle> grp_entities, excl_entities;
+  std::vector<EntityHandle> grp_entities, excl_entities;
   for (unsigned int i = 0; i < grouph->memTypeCt; i++) {
       // get how many and what type
     FREADI(2);
@@ -827,12 +829,12 @@
     CONVERT_TO_INTS(num_ents);
     
       // get the entities in this group
-    MBErrorCode result = get_entities(this_type, &int_buf[0], num_ents, grp_entities, excl_entities);
+    ErrorCode result = get_entities(this_type, &int_buf[0], num_ents, grp_entities, excl_entities);
     if (MB_SUCCESS != result) return result;
   }
 
     // now add the entities
-  MBErrorCode result = put_into_set(grouph->setHandle, grp_entities, excl_entities);
+  ErrorCode result = put_into_set(grouph->setHandle, grp_entities, excl_entities);
   if (MB_SUCCESS != result) return result;
   
     // now get group names, if any
@@ -866,7 +868,7 @@
         md_index = model->groupMD.get_md_entry(group_index, extra_name_label.str().c_str());
         if (-1 != md_index) {
           md_entry = &(model->groupMD.metadataEntries[md_index]);
-          MBTag extra_name_tag;
+          Tag extra_name_tag;
           result = mdbImpl->tag_get_handle(moab_extra_name.str().c_str(), extra_name_tag);
           assert(md_entry->mdStringValue.length()+1 <= NAME_TAG_SIZE);
           if (MB_SUCCESS != result || 0 == extra_name_tag) {
@@ -886,22 +888,22 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::put_into_set(MBEntityHandle set_handle,
-                                 std::vector<MBEntityHandle> &entities,
-                                 std::vector<MBEntityHandle> &excl_entities)
+ErrorCode Tqdcfr::put_into_set(EntityHandle set_handle,
+                                 std::vector<EntityHandle> &entities,
+                                 std::vector<EntityHandle> &excl_entities)
 {
     // and put entities into this block's set
-  MBErrorCode result = mdbImpl->add_entities(set_handle, &entities[0], entities.size());
+  ErrorCode result = mdbImpl->add_entities(set_handle, &entities[0], entities.size());
   if (MB_SUCCESS != result) return result;
 
     // check for excluded entities, and add them to a vector hung off the block if there
-  MBTag excl_tag;
+  Tag excl_tag;
   if (!excl_entities.empty()) {
-    MBErrorCode result = mdbImpl->tag_create("Exclude_Entities", 
-                                             sizeof(std::vector<MBEntityHandle>), MB_TAG_SPARSE, 
+    ErrorCode result = mdbImpl->tag_create("Exclude_Entities", 
+                                             sizeof(std::vector<EntityHandle>), MB_TAG_SPARSE, 
                                              excl_tag, NULL);
     if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
-    std::vector<MBEntityHandle> *new_vector = new std::vector<MBEntityHandle>;
+    std::vector<EntityHandle> *new_vector = new std::vector<EntityHandle>;
     new_vector->swap(excl_entities);
     result = mdbImpl->tag_set_data(excl_tag, &set_handle, 1, &new_vector);
     if (MB_SUCCESS != result) {
@@ -913,12 +915,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::get_entities(const unsigned int *mem_types, 
+ErrorCode Tqdcfr::get_entities(const unsigned int *mem_types, 
                                  int *id_buf, const unsigned int id_buf_size,
                                  const bool is_group,
-                                 std::vector<MBEntityHandle> &entities) 
+                                 std::vector<EntityHandle> &entities) 
 {
-  MBErrorCode tmp_result, result = MB_SUCCESS;
+  ErrorCode tmp_result, result = MB_SUCCESS;
   
   for (unsigned int i = 0; i < id_buf_size; i++) {
     if (is_group)
@@ -932,24 +934,24 @@
   return result;
 }
   
-MBErrorCode Tqdcfr::get_entities(const unsigned int this_type, 
+ErrorCode Tqdcfr::get_entities(const unsigned int this_type, 
                                  int *id_buf, const unsigned int id_buf_size,
-                                 std::vector<MBEntityHandle> &entities,
-                                 std::vector<MBEntityHandle> &excl_entities) 
+                                 std::vector<EntityHandle> &entities,
+                                 std::vector<EntityHandle> &excl_entities) 
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   
   if (this_type >= GROUP && this_type <= VERTEX)
     result = get_ref_entities(this_type, id_buf, id_buf_size, entities);
-  else if (this_type >= HEX && this_type <= NODE)
+  else if (this_type >= MBHEX && this_type <= NODE)
     result = get_mesh_entities(this_type, id_buf, id_buf_size, entities, excl_entities);
 
   return result;
 }
 
-MBErrorCode Tqdcfr::get_ref_entities(const unsigned int this_type, 
+ErrorCode Tqdcfr::get_ref_entities(const unsigned int this_type, 
                                      int *id_buf, const unsigned int id_buf_size,
-                                     std::vector<MBEntityHandle> &entities) 
+                                     std::vector<EntityHandle> &entities) 
 {
   for (unsigned int i = 0; i < id_buf_size; i++)
     entities.push_back((gidSetMap[5-this_type])[id_buf[i]]);
@@ -957,14 +959,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::get_mesh_entities(const unsigned int this_type, 
+ErrorCode Tqdcfr::get_mesh_entities(const unsigned int this_type, 
                                       int *id_buf, const unsigned int id_buf_size,
-                                      std::vector<MBEntityHandle> &entities,
-                                      std::vector<MBEntityHandle> &excl_entities) 
+                                      std::vector<EntityHandle> &entities,
+                                      std::vector<EntityHandle> &excl_entities) 
 {
-  MBErrorCode result = MB_SUCCESS;
-  std::vector<MBEntityHandle> *ent_list = NULL;
-  MBEntityType this_ent_type;
+  ErrorCode result = MB_SUCCESS;
+  std::vector<EntityHandle> *ent_list = NULL;
+  EntityType this_ent_type;
   if (this_type > 1000) {
     this_ent_type = group_type_to_mb_type[this_type-1000];
     ent_list = &excl_entities;
@@ -979,7 +981,7 @@
       // use either vertex offset or cubMOABVertexMap
     if (NULL == cubMOABVertexMap) {
       for (unsigned int i = 0; i < id_buf_size; i++)
-        ent_list->push_back((MBEntityHandle)(id_buf[i]+currVHandleOffset));
+        ent_list->push_back((EntityHandle)(id_buf[i]+currVHandleOffset));
     }
     else {
       for (unsigned int i = 0; i < id_buf_size; i++) {
@@ -989,7 +991,7 @@
     }
   }
   else {
-    MBRange tmp_ents;
+    Range tmp_ents;
     result = mdbImpl->get_entities_by_type(0, this_ent_type, tmp_ents);
     if (MB_SUCCESS != result) return result;
     if (tmp_ents.empty() && 0 != id_buf_size) return MB_FAILURE;
@@ -1003,7 +1005,7 @@
       std::vector<int>::iterator vit = 
         std::find(cub_ids.begin(), cub_ids.end(), id_buf[i]);
       if (vit != cub_ids.end()) {
-        MBEntityHandle this_ent = tmp_ents[vit-cub_ids.begin()];
+        EntityHandle this_ent = tmp_ents[vit-cub_ids.begin()];
         if (mdbImpl->type_from_handle(this_ent) != MBMAXTYPE) ent_list->push_back(this_ent);
       }
       else {
@@ -1016,7 +1018,7 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::read_nodes(const unsigned int gindex,
+ErrorCode Tqdcfr::read_nodes(const unsigned int gindex,
                                Tqdcfr::ModelEntry *model,
                                Tqdcfr::GeomHeader *entity) 
 {
@@ -1041,7 +1043,7 @@
   }
 
     // get a space for reading nodal data directly into MB, and read that data
-  MBEntityHandle vhandle = 0;
+  EntityHandle vhandle = 0;
   std::vector<double*> arrays;
   readUtilIface->get_node_arrays(3, entity->nodeCt,
                                  uint_buf[0], 
@@ -1055,9 +1057,9 @@
   FREADDA(entity->nodeCt, arrays[2]);
 
     // add these nodes into the entity's set
-  MBRange dum_range(vhandle, 
+  Range dum_range(vhandle, 
                     vhandle+entity->nodeCt-1);
-  MBErrorCode result = mdbImpl->add_entities(entity->setHandle, dum_range);
+  ErrorCode result = mdbImpl->add_entities(entity->setHandle, dum_range);
   if (MB_SUCCESS != result) return result;
 
     // check for id contiguity; know that cid's will never be > 32bit, so
@@ -1076,7 +1078,7 @@
   if (!cubMOABVertexMap &&
       (currVHandleOffset != vhandle_offset || !contig)) {
       // get all vertices, removing ones in this batch
-    MBRange vrange, tmp_range(dum_range);
+    Range vrange, tmp_range(dum_range);
     result = mdbImpl->get_entities_by_type(0, MBVERTEX, vrange); RR;
     if (!beforeEnts.empty()) tmp_range.merge(beforeEnts.subset_by_type(MBVERTEX));
     vrange = subtract( vrange, tmp_range);
@@ -1087,10 +1089,10 @@
     long new_max = *vrange.rbegin()-currVHandleOffset;
     assert(new_max >= 0 && *vrange.begin() - currVHandleOffset >= 0);
     max_cid = MAX(max_cid, ((unsigned int) new_max));
-    cubMOABVertexMap = new std::vector<MBEntityHandle>(max_cid+1);
+    cubMOABVertexMap = new std::vector<EntityHandle>(max_cid+1);
       // initialize to zero then put previous vertices into the map
     std::fill(cubMOABVertexMap->begin(), cubMOABVertexMap->end(), 0);
-    MBRange::iterator rit;
+    Range::iterator rit;
     for (rit = vrange.begin(); rit != vrange.end(); rit++) {
       assert(*rit-currVHandleOffset >= 0 &&
              *rit-currVHandleOffset <= max_cid);
@@ -1135,7 +1137,7 @@
       // put new vertices into the map
       // now set the new values
     unsigned int *vit = &uint_buf[0];
-    MBRange::iterator rit = dum_range.begin();
+    Range::iterator rit = dum_range.begin();
     for (; rit != dum_range.end(); vit++, rit++) {
       assert(*vit < cubMOABVertexMap->size());
       (*cubMOABVertexMap)[*vit] = *rit;
@@ -1169,15 +1171,15 @@
   for (std::vector<unsigned int>::iterator vit = md_entry->mdIntArrayValue.begin();
        vit != md_entry->mdIntArrayValue.end(); vit++) {
 #ifndef NDEBUG
-    MBEntityHandle fixed_v = (cubMOABVertexMap ? 
+    EntityHandle fixed_v = (cubMOABVertexMap ? 
                               (*cubMOABVertexMap)[*vit] : 
-                              (MBEntityHandle) currVHandleOffset+*vit);
+                              (EntityHandle) currVHandleOffset+*vit);
     assert(fixed_v >= *dum_range.begin() && fixed_v <= *dum_range.rbegin());
 #endif
     fixed_flags[*vit - *dum_range.begin()] = 1;
   }
 
-  MBTag fixedFlagTag;
+  Tag fixedFlagTag;
   result = mdbImpl->tag_get_handle("NodeFixed", fixedFlagTag);
   if (MB_SUCCESS != result || 0 == fixedFlagTag) {
     int dum_val = 0;
@@ -1190,7 +1192,7 @@
   return result;
 }
 
-MBErrorCode Tqdcfr::read_elements(Tqdcfr::ModelEntry *model,
+ErrorCode Tqdcfr::read_elements(Tqdcfr::ModelEntry *model,
                                   Tqdcfr::GeomHeader *entity) 
 {
   if (entity->elemTypeCt == 0) return MB_SUCCESS;
@@ -1204,7 +1206,7 @@
 
   int int_type, nodes_per_elem, num_elem;
   int max_dim = -1;
-  MBErrorCode result;
+  ErrorCode result;
   for (unsigned int i = 0; i < entity->elemTypeCt; i++) {
       // for this elem type, get the type, nodes per elem, num elems
     FREADI(3);
@@ -1213,7 +1215,7 @@
     num_elem = uint_buf[2];
 
       // get MB element type from cub file's 
-    MBEntityType elem_type = mp_type_to_mb_type[int_type];
+    EntityType elem_type = mp_type_to_mb_type[int_type];
     max_dim = (max_dim < MBCN::Dimension(elem_type) ? MBCN::Dimension(elem_type) : max_dim);
 
     if (debug)
@@ -1236,7 +1238,7 @@
     }
     
       // get a space for reading connectivity data directly into MB
-    MBEntityHandle *conn, start_handle;
+    EntityHandle *conn, start_handle;
     
     result = readUtilIface->get_element_array(num_elem, nodes_per_elem,
                                      elem_type, int_buf[0], 
@@ -1244,7 +1246,7 @@
     if (MB_SUCCESS != result)
       return result;
     
-    MBRange dum_range(start_handle, start_handle+num_elem-1);
+    Range dum_range(start_handle, start_handle+num_elem-1);
         
     long elem_offset;
     elem_offset = (1 == contig ? start_handle - int_buf[0] : int_buf[num_elem-1]);
@@ -1262,7 +1264,7 @@
     FREADI(total_conn);
 
       // post-process connectivity into handles
-    MBEntityHandle new_handle;
+    EntityHandle new_handle;
     int j = 0;
     for (int e = 0; e < num_elem; ++e) {
       for (int k = 0; k < nodes_per_elem; ++k, ++j) {
@@ -1271,14 +1273,14 @@
           std::cout << ", " << uint_buf[j];
         }
         if (NULL == cubMOABVertexMap)
-          new_handle = (MBEntityHandle) currVHandleOffset+uint_buf[j];
+          new_handle = (EntityHandle) currVHandleOffset+uint_buf[j];
         else {
           assert(uint_buf[j] < cubMOABVertexMap->size() &&
                  0 != (*cubMOABVertexMap)[uint_buf[j]]);
           new_handle = (*cubMOABVertexMap)[uint_buf[j]];
         }
   #ifndef NDEBUG
-        MBEntityHandle dum_handle;
+        EntityHandle dum_handle;
         assert(MB_SUCCESS == 
                mdbImpl->handle_from_id(MBVERTEX, mdbImpl->id_from_handle(new_handle), 
                                        dum_handle));
@@ -1372,7 +1374,7 @@
   instance->FREADI(1);
 }
 
-MBErrorCode Tqdcfr::read_file_header() 
+ErrorCode Tqdcfr::read_file_header() 
 {
     // read file header
   FSEEK(4);
@@ -1388,7 +1390,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::read_model_entries() 
+ErrorCode Tqdcfr::read_model_entries() 
 {
   
     // read model entries
@@ -1419,7 +1421,7 @@
   return -1;
 }
 
-MBErrorCode Tqdcfr::read_meta_data(const unsigned int metadata_offset, 
+ErrorCode Tqdcfr::read_meta_data(const unsigned int metadata_offset, 
                                    Tqdcfr::MetaDataContainer &mc) 
 {
     // read the metadata header
@@ -1480,7 +1482,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::read_md_string(std::string &name) 
+ErrorCode Tqdcfr::read_md_string(std::string &name) 
 {
   FREADI(1);
   int str_size = uint_buf[0];
@@ -1502,7 +1504,7 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode Tqdcfr::GeomHeader::read_info_header(const unsigned int model_offset, 
+ErrorCode Tqdcfr::GeomHeader::read_info_header(const unsigned int model_offset, 
                                                  const Tqdcfr::FEModelHeader::ArrayInfo &info,
                                                  Tqdcfr* instance,
                                                  Tqdcfr::GeomHeader *&geom_headers) 
@@ -1510,7 +1512,7 @@
   geom_headers = new GeomHeader[info.numEntities];
   instance->FSEEK(model_offset+info.tableOffset);
   int dum_int;
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == instance->categoryTag) {
     static const char val[CATEGORY_TAG_SIZE] = "\0";
@@ -1564,7 +1566,7 @@
       int int_type = instance->uint_buf[0];
       int nodes_per_elem = instance->uint_buf[1];
       int num_elem = instance->uint_buf[2];
-      MBEntityType elem_type = mp_type_to_mb_type[int_type];
+      EntityType elem_type = mp_type_to_mb_type[int_type];
       geom_headers[i].maxDim = std::max(geom_headers[i].maxDim, 
                                         (int)MBCN::Dimension(elem_type));
       if (j < geom_headers[i].elemTypeCt-1) 
@@ -1576,14 +1578,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::GroupHeader::read_info_header(const unsigned int model_offset, 
+ErrorCode Tqdcfr::GroupHeader::read_info_header(const unsigned int model_offset, 
                                            const Tqdcfr::FEModelHeader::ArrayInfo &info,
                                            Tqdcfr* instance,
                                            Tqdcfr::GroupHeader *&group_headers) 
 {
   group_headers = new GroupHeader[info.numEntities];
   instance->FSEEK(model_offset+info.tableOffset);
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == instance->categoryTag) {
     static const char val[CATEGORY_TAG_SIZE] = "\0";
@@ -1625,7 +1627,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::BlockHeader::read_info_header(const double data_version,
+ErrorCode Tqdcfr::BlockHeader::read_info_header(const double data_version,
                                                   const unsigned int model_offset, 
                                                   const Tqdcfr::FEModelHeader::ArrayInfo &info,
                                                   Tqdcfr* instance,
@@ -1633,7 +1635,7 @@
 {
   block_headers = new BlockHeader[info.numEntities];
   instance->FSEEK(model_offset+info.tableOffset);
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == instance->categoryTag) {
     static const char val[CATEGORY_TAG_SIZE] = "\0";
@@ -1708,14 +1710,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::NodesetHeader::read_info_header(const unsigned int model_offset, 
+ErrorCode Tqdcfr::NodesetHeader::read_info_header(const unsigned int model_offset, 
                                              const Tqdcfr::FEModelHeader::ArrayInfo &info,
                                              Tqdcfr* instance,
                                              Tqdcfr::NodesetHeader *&nodeset_headers) 
 {
   nodeset_headers = new NodesetHeader[info.numEntities];
   instance->FSEEK(model_offset+info.tableOffset);
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == instance->categoryTag) {
     static const char val[CATEGORY_TAG_SIZE] = "\0";
@@ -1758,14 +1760,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::SidesetHeader::read_info_header(const unsigned int model_offset, 
+ErrorCode Tqdcfr::SidesetHeader::read_info_header(const unsigned int model_offset, 
                                              const Tqdcfr::FEModelHeader::ArrayInfo &info,
                                              Tqdcfr* instance,
                                              Tqdcfr::SidesetHeader *&sideset_headers) 
 {
   sideset_headers = new SidesetHeader[info.numEntities];
   instance->FSEEK(model_offset+info.tableOffset);
-  MBErrorCode result;
+  ErrorCode result;
 
   if (0 == instance->categoryTag) {
     static const char val[CATEGORY_TAG_SIZE] = "\0";
@@ -1861,11 +1863,11 @@
     for (unsigned int i = 0; i < num_headers; i++) header[i].print();
 }
     
-MBErrorCode Tqdcfr::ModelEntry::read_header_info( Tqdcfr* instance, const double data_version)
+ErrorCode Tqdcfr::ModelEntry::read_header_info( Tqdcfr* instance, const double data_version)
 {
   feModelHeader.init(modelOffset, instance);
   int default_val = -1;
-  MBErrorCode result;
+  ErrorCode result;
 
   result = instance->mdbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER,
                                          instance->globalIdTag, &default_val);
@@ -1936,7 +1938,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::ModelEntry::read_metadata_info(Tqdcfr *tqd) 
+ErrorCode Tqdcfr::ModelEntry::read_metadata_info(Tqdcfr *tqd) 
 {
   if (debug) std::cout << "Geom metadata:" << std::endl;
   tqd->read_meta_data(modelOffset+feModelHeader.geomArray.metaDataOffset,
@@ -1963,7 +1965,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::read_acis_records( const char* sat_filename ) 
+ErrorCode Tqdcfr::read_acis_records( const char* sat_filename ) 
 {
 
     // get the acis model location
@@ -2068,11 +2070,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::interpret_acis_records(std::vector<AcisRecord> &records) 
+ErrorCode Tqdcfr::interpret_acis_records(std::vector<AcisRecord> &records) 
 {
     // make a tag for the vector holding unrecognized attributes
   void *default_val = NULL;
-  MBErrorCode result = 
+  ErrorCode result = 
     mdbImpl->tag_create("ATTRIB_VECTOR", sizeof(void*), MB_TAG_SPARSE, 
                         attribVectorTag, &default_val);
   if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
@@ -2106,7 +2108,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::parse_acis_attribs(const unsigned int entity_rec_num,
+ErrorCode Tqdcfr::parse_acis_attribs(const unsigned int entity_rec_num,
                                        std::vector<AcisRecord> &records) 
 {
   unsigned int num_read;
@@ -2117,7 +2119,7 @@
   int id = -1;
   int uid = -1;
   int next_attrib = -1;
-  MBErrorCode result;
+  ErrorCode result;
   
   int current_attrib = records[entity_rec_num].first_attrib;
   if (-1 == current_attrib) return MB_SUCCESS;
@@ -2189,7 +2191,7 @@
       (records[entity_rec_num].entity == 0 && uid == -1)) {
     return MB_SUCCESS;
       // Warning: couldn't resolve entity of type 1 because no uid was found.
-      // ddriv: GeomTopoTool.cpp:172: MBErrorCode GeomTopoTool::separate_by_dimension(const MBRange&, MBRange*, void**): Assertion `false' failed.
+      // ddriv: GeomTopoTool.cpp:172: ErrorCode GeomTopoTool::separate_by_dimension(const Range&, Range*, void**): Assertion `false' failed.
       // xxx
   }
   
@@ -2256,7 +2258,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::reset_record(AcisRecord &this_record) 
+ErrorCode Tqdcfr::reset_record(AcisRecord &this_record) 
 {
   this_record.rec_type = Tqdcfr::UNKNOWN;
   this_record.att_string.clear();
@@ -2268,7 +2270,7 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode Tqdcfr::process_record(AcisRecord &this_record)
+ErrorCode Tqdcfr::process_record(AcisRecord &this_record)
 {
     // get the entity type
   const char *type_substr;
@@ -2574,17 +2576,23 @@
             << std::endl;
 }
 
-MBErrorCode Tqdcfr::create_set( MBEntityHandle& h, unsigned int flags )
+ErrorCode Tqdcfr::create_set( EntityHandle& h, unsigned int flags )
 {
   return mdbImpl->create_meshset( flags, h );
 }
 
+
+} // namespace moab
+
+
 // #ifdef TEST_TQDCFR
 #else
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #define STRINGIFY_(A) #A
 #define STRINGIFY(A) STRINGIFY_(A)
 
+using namespace moab;
+
 int main(int argc, char* argv[])
 {
 
@@ -2598,11 +2606,11 @@
   else
     file = argv[1];
 
-  MBCore *my_impl = new MBCore();
+  Core *my_impl = new Core();
   Tqdcfr *my_tqd = new Tqdcfr(my_impl);
   FileOptions opts(NULL);
   
-  MBErrorCode result = my_tqd->load_file(file, 0, opts, 0, 0, 0);
+  ErrorCode result = my_tqd->load_file(file, 0, opts, 0, 0, 0);
 
   if (MB_SUCCESS == result)
     std::cout << "Success." << std::endl;
@@ -2618,7 +2626,7 @@
   delete my_impl;
   
     // now check for multiple procs
-  my_impl = new MBCore;
+  my_impl = new Core;
   my_tqd = new Tqdcfr(my_impl);
   
   result = my_tqd->load_file(file, 0, opts, 0, 0, 0);
@@ -2643,7 +2651,7 @@
   err = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     // create MOAB instance based on that
-  my_impl = new MBCore ;//(rank, nprocs);
+  my_impl = new Core ;//(rank, nprocs);
   if (NULL == my_impl) return 1;
   
   std::string options = "PARALLEL=READ_DELETE;PARTITION=MATERIAL_SET;PARTITION_DISTRIBUTE";
@@ -2666,4 +2674,5 @@
 
   return result;
 }
+
 #endif

Modified: MOAB/trunk/src/io/Tqdcfr.hpp
===================================================================
--- MOAB/trunk/src/io/Tqdcfr.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/Tqdcfr.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,17 +21,19 @@
 #ifndef TQDCFR
 #define TQDCFR
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
-#include "MBTagConventions.hpp"
-#include "MBRange.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Range.hpp"
 
 #include <stdio.h>
 #include <string>
 #include <vector>
 #include <map>
 
-class MBReadUtilIface;
+namespace moab {
+
+class ReadUtilIface;
 class FEModelHeader;
 class GeomHeader;
 class GroupHeader;
@@ -40,7 +42,7 @@
 class SidesetHeader;
 
 
-class Tqdcfr : public MBReaderIface
+class Tqdcfr : public ReaderIface
 {
 public:  
 
@@ -124,11 +126,11 @@
 
     int maxDim;
     
-    MBEntityHandle setHandle;
+    EntityHandle setHandle;
 
     void print();
 
-    static MBErrorCode read_info_header(const unsigned int model_offset, 
+    static ErrorCode read_info_header(const unsigned int model_offset, 
                                         const FEModelHeader::ArrayInfo &info,
                                         Tqdcfr* instance,
                                         GeomHeader *&entity_headers);
@@ -141,11 +143,11 @@
   public:
     unsigned int grpID, grpType, memCt, memOffset, memTypeCt, grpLength;
 
-    MBEntityHandle setHandle;
+    EntityHandle setHandle;
 
     void print();
 
-    static MBErrorCode read_info_header(const unsigned int model_offset, 
+    static ErrorCode read_info_header(const unsigned int model_offset, 
                                  const FEModelHeader::ArrayInfo &info,
                                  Tqdcfr* instance,
                                  GroupHeader *&entity_headers);
@@ -159,13 +161,13 @@
     unsigned int blockID, blockElemType, memCt, memOffset, memTypeCt, attribOrder, blockCol,
       blockMixElemType, blockPyrType, blockMat, blockLength, blockDim;
 
-    MBEntityHandle setHandle;
+    EntityHandle setHandle;
 
-    MBEntityType blockEntityType;
+    EntityType blockEntityType;
 
     void print();
 
-    static MBErrorCode read_info_header(const double data_version,
+    static ErrorCode read_info_header(const double data_version,
                                         const unsigned int model_offset, 
                                         const FEModelHeader::ArrayInfo &info,
                                         Tqdcfr* instance,
@@ -179,11 +181,11 @@
   public:
     unsigned int nsID, memCt, memOffset, memTypeCt, pointSym, nsCol, nsLength;
 
-    MBEntityHandle setHandle;
+    EntityHandle setHandle;
 
     void print();
 
-    static MBErrorCode read_info_header(const unsigned int model_offset, 
+    static ErrorCode read_info_header(const unsigned int model_offset, 
                                  const FEModelHeader::ArrayInfo &info,
                                  Tqdcfr* instance,
                                  NodesetHeader *&entity_headers);
@@ -196,11 +198,11 @@
   public:
     unsigned int ssID, memCt, memOffset, memTypeCt, numDF, ssCol, useShell, ssLength;
 
-    MBEntityHandle setHandle;
+    EntityHandle setHandle;
 
     void print();
 
-    static MBErrorCode read_info_header(const unsigned int model_offset, 
+    static ErrorCode read_info_header(const unsigned int model_offset, 
                                  const FEModelHeader::ArrayInfo &info,
                                  Tqdcfr* instance,
                                  SidesetHeader *&entity_headers);
@@ -250,8 +252,8 @@
                                SidesetHeader *header,
                                const unsigned int num_headers);
     
-    MBErrorCode read_header_info( Tqdcfr* instance, const double data_version);
-    MBErrorCode read_metadata_info(Tqdcfr *tqd);
+    ErrorCode read_header_info( Tqdcfr* instance, const double data_version);
+    ErrorCode read_metadata_info(Tqdcfr *tqd);
   };
 
   enum {aBODY, LUMP, SHELL, FACE, LOOP, COEDGE, aEDGE, aVERTEX, ATTRIB, UNKNOWN};
@@ -265,109 +267,109 @@
     bool processed;
     int first_attrib;
     int att_prev, att_next, att_ent_num;
-    MBEntityHandle entity;
+    EntityHandle entity;
   };
 
   ~Tqdcfr();
 
-  MBReadUtilIface *readUtilIface;
-  MBInterface *mdbImpl;
+  ReadUtilIface *readUtilIface;
+  Interface *mdbImpl;
   FILE *cubFile;
   FileTOC fileTOC;
   std::vector<ModelEntry> modelEntries;
   MetaDataContainer modelMetaData;
   long currVHandleOffset;
-  MBRange beforeEnts;
+  Range beforeEnts;
   long currElementIdOffset[MBMAXTYPE];
-  MBTag globalIdTag, cubIdTag, geomTag, uniqueIdTag, blockTag, nsTag, ssTag,
+  Tag globalIdTag, cubIdTag, geomTag, uniqueIdTag, blockTag, nsTag, ssTag,
     attribVectorTag, entityNameTag, categoryTag, hasMidNodesTag;
-  std::map<int, MBEntityHandle> uidSetMap;
-  std::map<int, MBEntityHandle> gidSetMap[6];
+  std::map<int, EntityHandle> uidSetMap;
+  std::map<int, EntityHandle> gidSetMap[6];
 
   std::vector<unsigned int> uint_buf;
   int *int_buf;
   std::vector<double> dbl_buf;
   std::vector<char> char_buf;
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
   
     // read cub file
-  MBErrorCode load_file(const char *file_name,
-                        const MBEntityHandle *file_set,
+  ErrorCode load_file(const char *file_name,
+                        const EntityHandle *file_set,
                         const FileOptions& opts,
-                        const MBReaderIface::IDTag* subset_list = 0,
+                        const ReaderIface::IDTag* subset_list = 0,
                         int subset_list_length = 0,
-                        const MBTag* file_id_tag = 0 );
+                        const Tag* file_id_tag = 0 );
 
-  MBErrorCode read_tag_values( const char* file_name,
+  ErrorCode read_tag_values( const char* file_name,
                                const char* tag_name,
                                const FileOptions& opts,
                                std::vector<int>& tag_values_out,
                                const IDTag* subset_list = 0,
                                int subset_list_length = 0 );
                                
-  MBErrorCode read_nodeset(ModelEntry *model,
+  ErrorCode read_nodeset(ModelEntry *model,
                     NodesetHeader *nodeseth);
-  MBErrorCode read_sideset(const double data_version,
+  ErrorCode read_sideset(const double data_version,
                     ModelEntry *model,
                     SidesetHeader *sideseth);
-  MBErrorCode read_block(const double data_version,
+  ErrorCode read_block(const double data_version,
                   ModelEntry *model,
                   BlockHeader *blockh);
-  MBErrorCode read_group(const unsigned int gr_index,
+  ErrorCode read_group(const unsigned int gr_index,
                          ModelEntry *model,
                          GroupHeader *grouph);
-  MBErrorCode read_nodes(const unsigned int gindex,
+  ErrorCode read_nodes(const unsigned int gindex,
                   ModelEntry *model,
                   GeomHeader *entity);
-  MBErrorCode read_elements(ModelEntry *model,
+  ErrorCode read_elements(ModelEntry *model,
                      GeomHeader *entity);
-  MBErrorCode read_file_header();
-  MBErrorCode read_model_entries();
+  ErrorCode read_file_header();
+  ErrorCode read_model_entries();
   int find_model(const unsigned int model_type);
-  MBErrorCode read_meta_data(const unsigned int metadata_offset, 
+  ErrorCode read_meta_data(const unsigned int metadata_offset, 
                       MetaDataContainer &mc);
-  MBErrorCode read_md_string(std::string &name);
+  ErrorCode read_md_string(std::string &name);
   
   enum {mesh, acist, acisb, facet, exodusmesh};
-  MBEntityType type_from_cub_type(const unsigned int cub_type, const unsigned int nodes_per_elem);
+  EntityType type_from_cub_type(const unsigned int cub_type, const unsigned int nodes_per_elem);
   void check_contiguous(const unsigned int num_ents, int &contig, 
                         unsigned int &min_id, unsigned int &max_id);
 
-  Tqdcfr(MBInterface *impl);
+  Tqdcfr(Interface *impl);
 
-  MBErrorCode create_set( MBEntityHandle& h, unsigned int flags = MESHSET_SET );
+  ErrorCode create_set( EntityHandle& h, unsigned int flags = MESHSET_SET );
 
 private:
 
-  MBEntityHandle mFileSet; // set containing read entities.
+  EntityHandle mFileSet; // set containing read entities.
 
   bool printedSeqWarning; // only print acis sequence #'s warning once
   
   bool printedElemWarning; // only print element #'s warning once
   
-  MBErrorCode convert_nodesets_sidesets();
+  ErrorCode convert_nodesets_sidesets();
 
-  MBErrorCode read_acis_records( const char* sat_file_name = 0 );
+  ErrorCode read_acis_records( const char* sat_file_name = 0 );
   
-  MBErrorCode parse_acis_attribs(const unsigned int entity_rec_num,
+  ErrorCode parse_acis_attribs(const unsigned int entity_rec_num,
                           std::vector<AcisRecord> &records);
-  MBErrorCode interpret_acis_records(std::vector<AcisRecord> &records);
+  ErrorCode interpret_acis_records(std::vector<AcisRecord> &records);
 
-  MBErrorCode reset_record(AcisRecord &this_record);
+  ErrorCode reset_record(AcisRecord &this_record);
   
-  MBErrorCode process_record(AcisRecord &this_record);
+  ErrorCode process_record(AcisRecord &this_record);
   
   static const char geom_categories[][CATEGORY_TAG_SIZE];
   
   FILE* acisDumpFile;
 
     // map between cub ids and MOAB handles
-  std::vector<MBEntityHandle> *cubMOABVertexMap;
+  std::vector<EntityHandle> *cubMOABVertexMap;
 
     // enum used to identify element/entity type in groups
   enum {GROUP = 0, BODY, VOLUME, SURFACE, CURVE, VERTEX, HEX, TET, PYRAMID, QUAD, TRI, EDGE, NODE};
-  static const MBEntityType group_type_to_mb_type[];
+  static const EntityType group_type_to_mb_type[];
 
   enum {SPHERE_EXO=0,
         BAR, BAR2, BAR3,
@@ -382,53 +384,55 @@
         PYRAMIDfive, PYRAMID5, PYRAMID8, PYRAMID13, PYRAMID18,
         HEXeight, HEX8, HEX9, HEX20, HEX27, HEXSHELL, 
         INVALID_ELEMENT_TYPE};
-  static const MBEntityType block_type_to_mb_type[];
+  static const EntityType block_type_to_mb_type[];
   static const int cub_elem_num_verts[];
 
     //! mapping from mesh packet type to moab type
-  static const MBEntityType mp_type_to_mb_type[];
+  static const EntityType mp_type_to_mb_type[];
   
     //! get entities with individually-specified types; if is_group is false, 
     //! increment each mem_type by 2 since they're CSOEntityType's and not group types
-  MBErrorCode get_entities(const unsigned int *mem_types,
+  ErrorCode get_entities(const unsigned int *mem_types,
                            int *id_buf, const unsigned int id_buf_size,
                            const bool is_group,
-                           std::vector<MBEntityHandle> &entities);
+                           std::vector<EntityHandle> &entities);
   
     //! get entities specified by type and ids, append to entities
-  MBErrorCode get_entities(const unsigned int this_type, 
+  ErrorCode get_entities(const unsigned int this_type, 
                            int *id_buf, const unsigned int id_buf_size,
-                           std::vector<MBEntityHandle> &entities,
-                           std::vector<MBEntityHandle> &excl_entities);
+                           std::vector<EntityHandle> &entities,
+                           std::vector<EntityHandle> &excl_entities);
   
     //! get ref entity sets with specified type and ids
-  MBErrorCode get_ref_entities(const unsigned int this_type, 
+  ErrorCode get_ref_entities(const unsigned int this_type, 
                                int *id_buf, const unsigned id_buf_size,
-                               std::vector<MBEntityHandle> &entities);
+                               std::vector<EntityHandle> &entities);
   
     //! get mesh entities with specified type and ids
-  MBErrorCode get_mesh_entities(const unsigned int this_type, 
+  ErrorCode get_mesh_entities(const unsigned int this_type, 
                                 int *id_buf, const unsigned id_buf_size,
-                                std::vector<MBEntityHandle> &entities,
-                                std::vector<MBEntityHandle> &excl_entities);
+                                std::vector<EntityHandle> &entities,
+                                std::vector<EntityHandle> &excl_entities);
   
     //! process entities in a sideset according to sense flags stored in uint_buf
     //! or char_buf (depending on sense_size)
-  MBErrorCode process_sideset_10(const int this_type, const int num_ents,
+  ErrorCode process_sideset_10(const int this_type, const int num_ents,
                                  const int sense_size,
-                                 std::vector<MBEntityHandle> &ss_entities,
+                                 std::vector<EntityHandle> &ss_entities,
                                  Tqdcfr::SidesetHeader *sideseth);
 
-  MBErrorCode process_sideset_11(std::vector<MBEntityHandle> &ss_entities,
+  ErrorCode process_sideset_11(std::vector<EntityHandle> &ss_entities,
                                  int num_wrts,
                                  Tqdcfr::SidesetHeader *sideseth);
   
     // put entities into the specfied set, and excluded entities into a 
     // std::vector pointed to by the "Exclude_Entities" tag on that set
-  MBErrorCode put_into_set(MBEntityHandle set_handle,
-                           std::vector<MBEntityHandle> &entities,
-                           std::vector<MBEntityHandle> &excl_entities);
+  ErrorCode put_into_set(EntityHandle set_handle,
+                           std::vector<EntityHandle> &entities,
+                           std::vector<EntityHandle> &excl_entities);
   
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/VtkUtil.cpp
===================================================================
--- MOAB/trunk/src/io/VtkUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/VtkUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,7 +15,9 @@
 
 #include "VtkUtil.hpp"
 
+namespace moab {
 
+
 const char* VtkUtil::vtkTypeNames[] = {
  "unsigned_char", // MB_TYPE_OPAQUE
  "int",           // MB_TYPE_INTEGER
@@ -30,7 +32,7 @@
  sizeof(int),            // MB_TYPE_INTEGER
  sizeof(double),         // MB_TYPE_DOUBLE
  1,                      // MB_TYPE_BIT
- sizeof(MBEntityHandle), // MB_TYPE_HANDLE
+ sizeof(EntityHandle), // MB_TYPE_HANDLE
 };
 */
 
@@ -96,7 +98,7 @@
 
 const unsigned VtkUtil::numVtkElemType = sizeof(VtkUtil::vtkElemTypes) / sizeof(VtkUtil::vtkElemTypes[0]);
 
-// Define an array, indexed by MBEntityType containing the corresponding 
+// Define an array, indexed by EntityType containing the corresponding 
 // VTK element type numbers for the linear, quadratic (mid-edge),
 // and full (mid-face & mid-region node) elements.
 // Zero is used to indicate an invalid type (not supported by VTK.)  The
@@ -116,7 +118,7 @@
   {  0,  0,  0 },  // MBENTITYSET
   {  0,  0,  0 } };// MBMAXTYPE
 
-const VtkElemType* VtkUtil::get_vtk_type( MBEntityType type, unsigned num_nodes )
+const VtkElemType* VtkUtil::get_vtk_type( EntityType type, unsigned num_nodes )
 {
   const int i = mb_to_vtk_type[type][0]; // Index for linear type
   const int j = mb_to_vtk_type[type][1]; // Index for quadratic type
@@ -140,3 +142,4 @@
   return 0;
 }
 
+} // namespace moab

Modified: MOAB/trunk/src/io/VtkUtil.hpp
===================================================================
--- MOAB/trunk/src/io/VtkUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/VtkUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,8 +16,10 @@
 #ifndef VTK_UTIL_HPP
 #define VTK_UTIL_HPP
 
-#include "MBEntityType.h"
+#include "moab/EntityType.hpp"
 
+namespace moab {
+
 //! Structure defining relation between MOAB and VTK element
 //! types.  VTK had different types for quadratic than linear
 //! elements, so a tuple of the MOAB type and number of
@@ -26,7 +28,7 @@
 {
   const char* name;            //!< String name for use in error messages
   unsigned vtk_type;           //!< VTK integer type
-  MBEntityType mb_type;        //!< MOAB type
+  EntityType mb_type;        //!< MOAB type
   unsigned num_nodes;          //!< Number of nodes (0 for polygon)
   const unsigned* node_order;  //!< VTK element node ordering, indexed by
                                //!< the VTK node position and containing
@@ -41,7 +43,7 @@
 {
 
 public:
-    //! vtk data type names, indexed by MBDataType
+    //! vtk data type names, indexed by DataType
   static const char *vtkTypeNames[];
   
     //! Vtk types, indexed by VTK type number.
@@ -52,8 +54,10 @@
   static const unsigned numVtkElemType;
   
     //! Get the VTK type corresponding to a tuple of the MOAB type and number of nodes.
-    //! num_nodes is ignored for POLYGON type.
-  static const VtkElemType* get_vtk_type( MBEntityType type, unsigned num_nodes );
+    //! num_nodes is ignored for MBPOLYGON type.
+  static const VtkElemType* get_vtk_type( EntityType type, unsigned num_nodes );
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteAns.cpp
===================================================================
--- MOAB/trunk/src/io/WriteAns.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteAns.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -35,33 +35,35 @@
 #include <fstream>
 #include <iomanip>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
 #include "assert.h"
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/MBTagConventions.hpp"
 
 #define INS_ID(stringvar, prefix, id) \
           sprintf(stringvar, prefix, id)
 
-MBWriterIface* WriteAns::factory( MBInterface* iface )
+namespace moab {
+
+WriterIface* WriteAns::factory( Interface* iface )
   { return new WriteAns( iface ); }
 
-WriteAns::WriteAns(MBInterface *impl) 
+WriteAns::WriteAns(Interface *impl) 
     : mbImpl(impl), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
     // initialize in case tag_get_handle fails below
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, mMaterialSetTag,
                               &dum_val);
@@ -80,18 +82,18 @@
 
 WriteAns::~WriteAns() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mbImpl->release_interface(iface_name, mWriteIface);
 
 }
 
-MBErrorCode WriteAns::write_file(const char *file_name, 
+ErrorCode WriteAns::write_file(const char *file_name, 
                                       const bool /* overwrite (commented out to remove warning) */,
                                       const FileOptions&,
-                                      const MBEntityHandle *ent_handles,
+                                      const EntityHandle *ent_handles,
                                       const int num_sets,
                                       const std::vector<std::string>&, 
-                                      const MBTag* ,
+                                      const Tag* ,
                                       int ,
                                       int )
 {
@@ -99,7 +101,7 @@
          0 != mNeumannSetTag &&
          0 != mDirichletSetTag);
   
-  MBErrorCode result;
+  ErrorCode result;
 
   //set SOLID45 element type to #60000, hope nobody has already...
   const char *ETSolid45 = "60045";
@@ -137,7 +139,7 @@
   ans_file << "/prep7" << std::endl;
 
   //gather single output set
-  MBEntityHandle output_set = 0;
+  EntityHandle output_set = 0;
   if(ent_handles && num_sets > 0)
     {
       for(int i=0;i<num_sets;i++)
@@ -149,14 +151,14 @@
     }
   
   //search for all nodes
-  MBRange node_range;
+  Range node_range;
   result=mbImpl->get_entities_by_type(output_set, MBVERTEX, node_range, true);
   if(result !=MB_SUCCESS) return result;
   
   
   // Commented out until Seg Fault taken care of in gather_nodes...
   //get any missing nodes which are needed for elements
-  //MBRange all_ent_range,missing_range;
+  //Range all_ent_range,missing_range;
   //result=mbImpl->get_entities_by_handle(output_set,all_ent_range,true);
   //if(result !=MB_SUCCESS) return result;
   //result=mWriteIface->gather_nodes_from_elements(all_ent_range,0,missing_range);
@@ -165,9 +167,9 @@
 
   // write the nodes 
   double coord[3];
-  for(MBRange::iterator it = node_range.begin(); it != node_range.end(); it++)
+  for(Range::iterator it = node_range.begin(); it != node_range.end(); it++)
     {
-      MBEntityHandle node_handle = *it;
+      EntityHandle node_handle = *it;
      
       result = mbImpl->get_coords(&node_handle,1, coord);
       if(result !=MB_SUCCESS) return result;
@@ -186,20 +188,20 @@
   ans_file << "nread," << base_string << ",node" << std::endl;
 
   //search for all node sets (Dirichlet Sets)
-  MBRange node_mesh_sets;
+  Range node_mesh_sets;
   int ns_id;
   result = mbImpl->get_entities_by_type_and_tag(0,MBENTITYSET,&mDirichletSetTag,NULL,1,node_mesh_sets);
   if(result !=MB_SUCCESS)return result;
 
-  for(MBRange::iterator ns_it = node_mesh_sets.begin(); ns_it!=node_mesh_sets.end();ns_it++)
+  for(Range::iterator ns_it = node_mesh_sets.begin(); ns_it!=node_mesh_sets.end();ns_it++)
     {
       result = mbImpl->tag_get_data(mDirichletSetTag, &(*ns_it),1,&ns_id);
       if(result !=MB_SUCCESS)return result;
-      std::vector<MBEntityHandle> node_vector;
+      std::vector<EntityHandle> node_vector;
       result = mbImpl->get_entities_by_handle(*ns_it,node_vector, true);
       if(result !=MB_SUCCESS)return result;
       //for every nodeset found, cycle through nodes in set:
-      for(std::vector<MBEntityHandle>::iterator node_it = node_vector.begin(); node_it!=node_vector.end();node_it++)
+      for(std::vector<EntityHandle>::iterator node_it = node_vector.begin(); node_it!=node_vector.end();node_it++)
 	{
 	  int ns_node_id = mbImpl->id_from_handle(*node_it);
 	  if(node_it==node_vector.begin())
@@ -228,14 +230,14 @@
   // For all nodes past 8, write on second line
 
   //Write all MBTET elements
-  MBRange tet_range;
+  Range tet_range;
   result = mbImpl->get_entities_by_type(output_set, MBTET, tet_range, true);
   if(result !=MB_SUCCESS) return result;
-  for(MBRange::iterator elem_it=tet_range.begin();elem_it!=tet_range.end();elem_it++)
+  for(Range::iterator elem_it=tet_range.begin();elem_it!=tet_range.end();elem_it++)
     {
-      MBEntityHandle elem_handle = *elem_it;
+      EntityHandle elem_handle = *elem_it;
       int elem_id = mbImpl->id_from_handle(elem_handle);
-      std::vector<MBEntityHandle> conn;
+      std::vector<EntityHandle> conn;
       result = mbImpl->get_connectivity(&elem_handle, 1, conn, false);
       if(result !=MB_SUCCESS) return result;
       //make sure 4 or 10 node tet
@@ -276,14 +278,14 @@
     }
 
   //Write all MBHEX elements
-  MBRange hex_range;
+  Range hex_range;
   result = mbImpl->get_entities_by_type(output_set, MBHEX, hex_range, true);
   if(result !=MB_SUCCESS) return result;
-  for(MBRange::iterator elem_it=hex_range.begin();elem_it!=hex_range.end();elem_it++)
+  for(Range::iterator elem_it=hex_range.begin();elem_it!=hex_range.end();elem_it++)
     {
-      MBEntityHandle elem_handle = *elem_it;
+      EntityHandle elem_handle = *elem_it;
       int elem_id = mbImpl->id_from_handle(elem_handle);
-      std::vector<MBEntityHandle> conn;
+      std::vector<EntityHandle> conn;
       result = mbImpl->get_connectivity(&elem_handle, 1, conn,false);
       if(result !=MB_SUCCESS) return result;
       //make sure supported hex type
@@ -330,14 +332,14 @@
       
     }
   //Write all MBPRISM elements
-  MBRange prism_range;
+  Range prism_range;
   result = mbImpl->get_entities_by_type(output_set, MBPRISM, prism_range, true);
   if(result !=MB_SUCCESS) return result;
-  for(MBRange::iterator elem_it=prism_range.begin();elem_it!=prism_range.end();elem_it++)
+  for(Range::iterator elem_it=prism_range.begin();elem_it!=prism_range.end();elem_it++)
     {
-      MBEntityHandle elem_handle = *elem_it;
+      EntityHandle elem_handle = *elem_it;
       int elem_id = mbImpl->id_from_handle(elem_handle);
-      std::vector<MBEntityHandle> conn;
+      std::vector<EntityHandle> conn;
       result = mbImpl->get_connectivity(&elem_handle, 1, conn,false);
       if(result !=MB_SUCCESS) return result;
       //make sure supported prism type
@@ -373,26 +375,26 @@
   ans_file << "eread," << base_string << ",elem" << std::endl;
 
   //search for all side sets (Neumann)
-  MBRange side_mesh_sets;
+  Range side_mesh_sets;
   int ss_id;
   result = mbImpl->get_entities_by_type_and_tag(0,MBENTITYSET,&mNeumannSetTag,NULL,1,side_mesh_sets);
   if(result !=MB_SUCCESS)return result;
   //cycle through all sets found
-  for(MBRange::iterator ss_it = side_mesh_sets.begin(); ss_it!=side_mesh_sets.end();ss_it++)
+  for(Range::iterator ss_it = side_mesh_sets.begin(); ss_it!=side_mesh_sets.end();ss_it++)
     {
       result = mbImpl->tag_get_data(mNeumannSetTag, &(*ss_it),1,&ss_id);
       if(result !=MB_SUCCESS)return result;
-      std::vector<MBEntityHandle> elem_vector;
+      std::vector<EntityHandle> elem_vector;
       result = mbImpl->get_entities_by_handle(*ss_it,elem_vector, true);
       if(result !=MB_SUCCESS)return result;
       
       //cycle through elements in current side set
-      for(std::vector<MBEntityHandle>::iterator elem_it = elem_vector.begin(); elem_it!=elem_vector.end();elem_it++)
+      for(std::vector<EntityHandle>::iterator elem_it = elem_vector.begin(); elem_it!=elem_vector.end();elem_it++)
 	{
-	  MBEntityHandle elem_handle = *elem_it;
+	  EntityHandle elem_handle = *elem_it;
 	  	  
 	  //instead of selecting current element in set, select its nodes...
-	  std::vector<MBEntityHandle> conn;
+	  std::vector<EntityHandle> conn;
 	  result = mbImpl->get_connectivity(&elem_handle, 1, conn);
 	  if(result !=MB_SUCCESS)return result;
 	  if(elem_it==elem_vector.begin())
@@ -415,23 +417,23 @@
     }
   
   //Gather all element blocks
-  MBRange matset;
+  Range matset;
   int mat_id;
   result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &mMaterialSetTag, NULL, 1, matset);
   if(result !=MB_SUCCESS)return result;
   //cycle through all elem blocks
-  for(MBRange::iterator mat_it = matset.begin(); mat_it!=matset.end();mat_it++)
+  for(Range::iterator mat_it = matset.begin(); mat_it!=matset.end();mat_it++)
     {
-      MBEntityHandle matset_handle = *mat_it;
+      EntityHandle matset_handle = *mat_it;
       result = mbImpl->tag_get_data(mMaterialSetTag,&matset_handle, 1,&mat_id);
       if(result !=MB_SUCCESS)return result;
-      std::vector<MBEntityHandle> mat_vector;
+      std::vector<EntityHandle> mat_vector;
       result = mbImpl->get_entities_by_handle(*mat_it,mat_vector, true);
       if(result !=MB_SUCCESS)return result;
       //cycle through elements in current mat set
-      for(std::vector<MBEntityHandle>::iterator elem_it = mat_vector.begin(); elem_it!=mat_vector.end();elem_it++)
+      for(std::vector<EntityHandle>::iterator elem_it = mat_vector.begin(); elem_it!=mat_vector.end();elem_it++)
 	{
-	  MBEntityHandle elem_handle = *elem_it;
+	  EntityHandle elem_handle = *elem_it;
 	  int elem_id = mbImpl->id_from_handle(elem_handle);
 	  if(elem_it==mat_vector.begin())
 	    {
@@ -451,3 +453,5 @@
 
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/io/WriteAns.hpp
===================================================================
--- MOAB/trunk/src/io/WriteAns.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteAns.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -36,34 +36,36 @@
 
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/WriterIface.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
-class MB_DLL_EXPORT WriteAns : public MBWriterIface
+class WriteUtilIface;
+
+class MB_DLL_EXPORT WriteAns : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteAns(MBInterface *impl);
+   WriteAns(Interface *impl);
 
    //! Destructor
   virtual ~WriteAns();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                          const MBEntityHandle *output_list,
+                          const EntityHandle *output_list,
                           const int num_sets,
                           const std::vector<std::string>& qa_list,
-                          const MBTag* tag_list,
+                          const Tag* tag_list,
                           int num_tags,
                           int export_dimension);
   
@@ -76,8 +78,8 @@
     int number_nodes_per_element;
     int number_attributes;
     ExoIIElementType element_type;
-    MBEntityType moab_type;
-    MBRange *elements;
+    EntityType moab_type;
+    Range *elements;
   };
 
 //! struct used to hold data for each nodeset to be output; used by
@@ -86,7 +88,7 @@
   {
     int id;
     int number_nodes;
-    std::vector< MBEntityHandle > nodes;
+    std::vector< EntityHandle > nodes;
     std::vector< double > node_dist_factors;
   
   };
@@ -97,9 +99,9 @@
   {
     int id;
     int number_elements;
-    std::vector<MBEntityHandle> elements;
+    std::vector<EntityHandle> elements;
     std::vector<int> side_numbers;
-    MBEntityHandle mesh_set_handle;
+    EntityHandle mesh_set_handle;
   };
 
 
@@ -109,7 +111,7 @@
   //int number_dimensions();
 
     //! open a file for writing
-  //MBErrorCode open_file(const char *filename);
+  //ErrorCode open_file(const char *filename);
 
   //! contains the general information about a mesh
   class MeshInfo
@@ -121,7 +123,7 @@
     unsigned int num_matsets;
     unsigned int num_dirsets;
     unsigned int num_neusets;
-    MBRange nodes;
+    Range nodes;
 
     MeshInfo() 
         : num_dim(0), num_nodes(0), num_elements(0), num_matsets(0), 
@@ -133,26 +135,28 @@
 private:
 
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! file name
   std::string fileName;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mGlobalIdTag;
-  MBTag mMatSetIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mGlobalIdTag;
+  Tag mMatSetIdTag;
   
-  MBErrorCode write_nodes(const int num_nodes, const MBRange& nodes, 
+  ErrorCode write_nodes(const int num_nodes, const Range& nodes, 
                           const int dimension, const char *file_name );
   
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteCCMIO.cpp
===================================================================
--- MOAB/trunk/src/io/WriteCCMIO.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteCCMIO.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -36,15 +36,17 @@
 #include <iostream>
 #include <algorithm>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
 #include "assert.h"
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
 
+namespace moab {
+
 static char const kStateName[] = "default";
 
 static const int ccm_types[] = {
@@ -64,22 +66,22 @@
 #define INS_ID(stringvar, prefix, id)           \
     sprintf(stringvar, prefix, id)
 
-MBWriterIface* WriteCCMIO::factory( MBInterface* iface )
+WriterIface* WriteCCMIO::factory( Interface* iface )
 { return new WriteCCMIO( iface ); }
 
-WriteCCMIO::WriteCCMIO(MBInterface *impl) 
+WriteCCMIO::WriteCCMIO(Interface *impl) 
         : mbImpl(impl), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
     // initialize in case tag_get_handle fails below
     //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, mMaterialSetTag,
                               &dum_val);
@@ -124,7 +126,7 @@
 
 WriteCCMIO::~WriteCCMIO() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mbImpl->release_interface(iface_name, mWriteIface);
 
   mbImpl->tag_delete(mEntityMark);
@@ -141,13 +143,13 @@
   }
 }
 
-MBErrorCode WriteCCMIO::write_file(const char *file_name, 
+ErrorCode WriteCCMIO::write_file(const char *file_name, 
                                    const bool /* overwrite (commented out to remove warning) */,
                                    const FileOptions& opts,
-                                   const MBEntityHandle *ent_handles,
+                                   const EntityHandle *ent_handles,
                                    const int num_sets,
                                    const std::vector<std::string>&,
-                                   const MBTag* ,
+                                   const Tag* ,
                                    int ,
                                    int )
 {
@@ -159,7 +161,7 @@
   if (NULL == strstr(file_name, ".ccmio"))
     return MB_FAILURE;
 
-  std::vector<MBEntityHandle> matsets, dirsets, neusets, partsets, entities;
+  std::vector<EntityHandle> matsets, dirsets, neusets, partsets, entities;
 
   fileName = file_name;
   
@@ -167,7 +169,7 @@
 
   if (num_sets == 0) {
       // default to all defined sets
-    MBRange this_range;
+    Range this_range;
     mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &mMaterialSetTag, NULL, 1, this_range);
     std::copy(this_range.begin(), this_range.end(), std::back_inserter(matsets));
     this_range.clear();
@@ -185,7 +187,7 @@
   
   else {
     int dummy;
-    for (const MBEntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
+    for (const EntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
     {
       if (MB_SUCCESS == mbImpl->tag_get_data(mMaterialSetTag, &(*iter), 1, &dummy))
         matsets.push_back(*iter);
@@ -199,7 +201,7 @@
     }
   }
 
-  MBErrorCode result = mbImpl->tag_get_handle(HAS_MID_NODES_TAG_NAME, mHasMidNodesTag);
+  ErrorCode result = mbImpl->tag_get_handle(HAS_MID_NODES_TAG_NAME, mHasMidNodesTag);
   if (MB_TAG_NOT_FOUND == result) {
     int dum_val_array[] = {0, 0, 0, 0};
     result = mbImpl->tag_create(HAS_MID_NODES_TAG_NAME, 4*sizeof(int), MB_TAG_SPARSE, mHasMidNodesTag,
@@ -297,7 +299,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::write_problem_description(CCMIOID rootID, CCMIOID stateID) 
+ErrorCode WriteCCMIO::write_problem_description(CCMIOID rootID, CCMIOID stateID) 
 {
   // Write out a dummy problem description.  If we happen to know that
   // there already is a problem description previously recorded that
@@ -325,16 +327,16 @@
 }
 
 
-MBErrorCode WriteCCMIO::gather_mesh_information(MeshInfo &mesh_info,
+ErrorCode WriteCCMIO::gather_mesh_information(MeshInfo &mesh_info,
                                                 std::vector<WriteCCMIO::MaterialSetData> &matset_info,
                                                 std::vector<WriteCCMIO::NeumannSetData> &neuset_info,
                                                 std::vector<WriteCCMIO::DirichletSetData> &dirset_info,
-                                                std::vector<MBEntityHandle> &matsets,
-                                                std::vector<MBEntityHandle> &neusets,
-                                                std::vector<MBEntityHandle> &dirsets)
+                                                std::vector<EntityHandle> &matsets,
+                                                std::vector<EntityHandle> &neusets,
+                                                std::vector<EntityHandle> &dirsets)
 {
 
-  std::vector<MBEntityHandle>::iterator vector_iter, end_vector_iter;
+  std::vector<EntityHandle>::iterator vector_iter, end_vector_iter;
 
   mesh_info.num_nodes = 0;
   mesh_info.num_elements = 0;
@@ -347,7 +349,7 @@
 
   mesh_info.num_matsets = matsets.size();
 
-  std::vector<MBEntityHandle> parent_meshsets;
+  std::vector<EntityHandle> parent_meshsets;
 
     // clean out the bits for the element mark
   mbImpl->tag_delete(mEntityMark);
@@ -359,18 +361,18 @@
   {
        
     WriteCCMIO::MaterialSetData matset_data;
-    matset_data.elements = new MBRange;
+    matset_data.elements = new Range;
 
       //for the purpose of qa records, get the parents of these matsets 
     if( mbImpl->get_parent_meshsets( *vector_iter, parent_meshsets ) != MB_SUCCESS )
       return MB_FAILURE;
 
       // get all Entity Handles in the mesh set
-    MBRange dummy_range;
+    Range dummy_range;
     mbImpl->get_entities_by_handle(*vector_iter, dummy_range, true );
 
       // find the dimension of the last entity in this range
-    MBRange::iterator entity_iter = dummy_range.end();
+    Range::iterator entity_iter = dummy_range.end();
     entity_iter = dummy_range.end();
     entity_iter--;
     int this_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*entity_iter));
@@ -380,7 +382,7 @@
       entity_iter++;
     
     if (entity_iter != dummy_range.end())
-      std::copy(entity_iter, dummy_range.end(), mb_range_inserter(*(matset_data.elements)));
+      std::copy(entity_iter, dummy_range.end(), range_inserter(*(matset_data.elements)));
 
     assert(matset_data.elements->begin() == matset_data.elements->end() ||
            MBCN::Dimension(TYPE_FROM_HANDLE(*(matset_data.elements->begin()))) == this_dim);
@@ -395,13 +397,13 @@
     matset_data.number_attributes = 0;
  
       // iterate through all the elements in the meshset
-    MBRange::iterator elem_range_iter, end_elem_range_iter;
+    Range::iterator elem_range_iter, end_elem_range_iter;
     elem_range_iter = matset_data.elements->begin();
     end_elem_range_iter = matset_data.elements->end();
 
       // get the entity type for this matset, verifying that it's the same for all elements
       // THIS ASSUMES HANDLES SORT BY TYPE!!!
-    MBEntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
+    EntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
     end_elem_range_iter--;
     if (entity_type != TYPE_FROM_HANDLE(*(end_elem_range_iter++))) {
       mWriteIface->report_error("Entities in matset %i not of common type", id);
@@ -416,7 +418,7 @@
     matset_data.moab_type = mbImpl->type_from_handle(*(matset_data.elements->begin()));
     if (MBMAXTYPE == matset_data.moab_type) return MB_FAILURE;
     
-    std::vector<MBEntityHandle> tmp_conn;
+    std::vector<EntityHandle> tmp_conn;
     mbImpl->get_connectivity(&(*(matset_data.elements->begin())), 1, tmp_conn);
     matset_data.element_type = 
         ExoIIUtil::get_element_type_from_num_verts(tmp_conn.size(), entity_type, dimension);
@@ -440,7 +442,7 @@
     if(!neusets.empty())
     {
         // if there are neusets, keep track of which elements are being written out
-      for(MBRange::iterator iter = matset_data.elements->begin(); 
+      for(Range::iterator iter = matset_data.elements->begin(); 
           iter != matset_data.elements->end(); ++iter)
       {
         unsigned char bit = 0x1;
@@ -463,7 +465,7 @@
       mesh_info.num_dim = highest_dimension_of_element_matsets;
   }
 
-  MBRange::iterator range_iter, end_range_iter;
+  Range::iterator range_iter, end_range_iter;
   range_iter = mesh_info.nodes.begin();
   end_range_iter = mesh_info.nodes.end();
 
@@ -489,20 +491,20 @@
     
     dirset_data.id = id; 
 
-    std::vector<MBEntityHandle> node_vector;
+    std::vector<EntityHandle> node_vector;
       //get the nodes of the dirset that are in mesh_info.nodes
     if( mbImpl->get_entities_by_handle(*vector_iter, node_vector, true) != MB_SUCCESS ) {
       mWriteIface->report_error("Couldn't get nodes in dirset %i", id);
       return MB_FAILURE;
     }
 
-    std::vector<MBEntityHandle>::iterator iter, end_iter;
+    std::vector<EntityHandle>::iterator iter, end_iter;
     iter = node_vector.begin();
     end_iter= node_vector.end();
  
     int j=0; 
     unsigned char node_marked = 0;
-    MBErrorCode result;
+    ErrorCode result;
     for(; iter != end_iter; iter++)
     {
       if (TYPE_FROM_HANDLE(*iter) != MBVERTEX) continue;
@@ -537,11 +539,11 @@
  
       //get the sides in two lists, one forward the other reverse; starts with forward sense
       // by convention
-    MBRange forward_elems, reverse_elems;
+    Range forward_elems, reverse_elems;
     if(get_neuset_elems(*vector_iter, 0, forward_elems, reverse_elems) == MB_FAILURE)
       return MB_FAILURE;
 
-    MBErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
+    ErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
     if (MB_SUCCESS != result) {
       mWriteIface->report_error("Couldn't get valid sides data.");
       return result;
@@ -559,14 +561,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::get_valid_sides(MBRange &elems, const int sense,
+ErrorCode WriteCCMIO::get_valid_sides(Range &elems, const int sense,
                                         WriteCCMIO::NeumannSetData &neuset_data) 
 {
     // this is where we see if underlying element of side set element is included in output 
 
   unsigned char element_marked = 0;
-  MBErrorCode result;
-  for(MBRange::iterator iter = elems.begin(); iter != elems.end(); iter++)
+  ErrorCode result;
+  for(Range::iterator iter = elems.begin(); iter != elems.end(); iter++)
   {
       // should insert here if "side" is a quad/tri on a quad/tri mesh
     result = mbImpl->tag_get_data(mEntityMark, &(*iter), 1, &element_marked);
@@ -584,7 +586,7 @@
     }
     else //then "side" is probably a quad/tri on a hex/tet mesh
     {
-      std::vector<MBEntityHandle> parents;
+      std::vector<EntityHandle> parents;
       int dimension = MBCN::Dimension( TYPE_FROM_HANDLE(*iter));
 
         //get the adjacent parent element of "side"
@@ -626,12 +628,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::get_gids(const MBRange &ents, int *&gids,
+ErrorCode WriteCCMIO::get_gids(const Range &ents, int *&gids,
                                  int &minid, int &maxid) 
 {
   int num_ents = ents.size();
   gids = new int[num_ents];
-  MBErrorCode result = mbImpl->tag_get_data(mGlobalIdTag, ents, &gids[0]);
+  ErrorCode result = mbImpl->tag_get_data(mGlobalIdTag, ents, &gids[0]);
   if (MB_SUCCESS != result) {
     mWriteIface->report_error("Couldn't get global id data.");
     return result;
@@ -651,13 +653,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::write_nodes(CCMIOID rootID, const MBRange& nodes, 
+ErrorCode WriteCCMIO::write_nodes(CCMIOID rootID, const Range& nodes, 
                                     const int dimension, int *&vgids)
 {
     // get/write map (global ids) first
   const int num_nodes = nodes.size();
   int minid, maxid;
-  MBErrorCode result = get_gids(nodes, vgids, minid, maxid);
+  ErrorCode result = get_gids(nodes, vgids, minid, maxid);
   if (MB_SUCCESS != result) return result;
   
   CCMIOID mapID;
@@ -707,10 +709,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::transform_coords(const int dimension, const int num_nodes, double *coords) 
+ErrorCode WriteCCMIO::transform_coords(const int dimension, const int num_nodes, double *coords) 
 {
-  MBTag trans_tag;
-  MBErrorCode result = mbImpl->tag_get_handle( MESH_TRANSFORM_TAG_NAME, trans_tag);
+  Tag trans_tag;
+  ErrorCode result = mbImpl->tag_get_handle( MESH_TRANSFORM_TAG_NAME, trans_tag);
   if( result == MB_TAG_NOT_FOUND ) return MB_SUCCESS;
   double trans_matrix[16]; 
   result = mbImpl->tag_get_data( trans_tag, NULL, 0, trans_matrix ); 
@@ -736,22 +738,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::write_matsets(MeshInfo & /* mesh_info (commented out to remove warning) */,
+ErrorCode WriteCCMIO::write_matsets(MeshInfo & /* mesh_info (commented out to remove warning) */,
                                       std::vector<WriteCCMIO::MaterialSetData> &matset_data,
                                       std::vector<WriteCCMIO::NeumannSetData> &/* neuset_data  */,
                                         // (commented out to remove warning)
-                                      MBRange &verts,
+                                      Range &verts,
                                       const int *vgids)
 {
   std::vector<int> connect;
-  MBErrorCode result;
+  ErrorCode result;
   CCMIOID rootID, cellMapID, topologyID, id;
   
     // don't usually have anywhere near 31 nodes per element
   connect.reserve(31);
-  MBRange::const_iterator rit;
+  Range::const_iterator rit;
 
-  MBRange all_elems;
+  Range all_elems;
   for (unsigned int i = 0; i < matset_data.size(); i++)
     all_elems.merge(*(matset_data[i].elements));
 
@@ -786,7 +788,7 @@
     // Write the faces
     // first, allocate a tag of length 6 (max # faces per region, except
     // for polyhedra)
-  MBTag mark_tag;
+  Tag mark_tag;
   short int def_val = 0;
   result = mbImpl->tag_create("__mark", 1, MB_TAG_DENSE, MB_TYPE_OPAQUE, 
                               mark_tag, &def_val);
@@ -797,17 +799,17 @@
   
     // now faces
   unsigned char markt;
-  std::vector<MBEntityHandle> tmp_face_cells, storage;
+  std::vector<EntityHandle> tmp_face_cells, storage;
   std::vector<int> iface_connect, iface_cells;
   std::vector<int> eface_connect, eface_cells;
-  MBEntityHandle tmp_connect[MBCN::MAX_NODES_PER_ELEMENT]; // tmp connect vector
-  const MBEntityHandle *connectc; int num_connectc; // cell connectivity
-  const MBEntityHandle *connectf; int num_connectf; // face connectivity
+  EntityHandle tmp_connect[MBCN::MAX_NODES_PER_ELEMENT]; // tmp connect vector
+  const EntityHandle *connectc; int num_connectc; // cell connectivity
+  const EntityHandle *connectf; int num_connectf; // face connectivity
   i = 0;
   rit = all_elems.begin();
   for (; i < num_elems; i++, rit++) {
       // if not polyh, get mark
-    MBEntityType etype = TYPE_FROM_HANDLE(*rit);
+    EntityType etype = TYPE_FROM_HANDLE(*rit);
     if (MBPOLYHEDRON != etype && MBPOLYGON != etype) {
       result = mbImpl->tag_get_data(mark_tag, &(*rit), 1, &markt);
       if (MB_SUCCESS != result) {
@@ -863,7 +865,7 @@
                          2, side_num, sense, offset);
         if (sense == 1 && tmp_face_cells[0] != *rit) {
           assert(2 == tmp_face_cells.size());
-          MBEntityHandle tmph = tmp_face_cells[0]; 
+          EntityHandle tmph = tmp_face_cells[0]; 
           tmp_face_cells[1] = tmp_face_cells[0]; 
           tmp_face_cells[0] = tmph;
         }
@@ -883,8 +885,8 @@
 
       if (!is_polyh && is_internal) {
           // mark other cell for this face, if there is another cell
-        MBEntityHandle other_cell = tmp_face_cells[0];
-        const MBEntityHandle *connecto; int num_connecto;
+        EntityHandle other_cell = tmp_face_cells[0];
+        const EntityHandle *connecto; int num_connecto;
         if (other_cell == *rit) other_cell = tmp_face_cells[1];
         result = mbImpl->get_connectivity(other_cell, connecto, num_connecto, 
                                           false, &storage);
@@ -955,7 +957,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::open_file(const char* filename)
+ErrorCode WriteCCMIO::open_file(const char* filename)
 {
     // not a valid filname
   if(strlen((const char*)filename) == 0)
@@ -970,28 +972,28 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteCCMIO::get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                                         MBRange &forward_elems, MBRange &reverse_elems) 
+ErrorCode WriteCCMIO::get_neuset_elems(EntityHandle neuset, int current_sense,
+                                         Range &forward_elems, Range &reverse_elems) 
 {
-  MBRange neuset_elems, neuset_meshsets;
+  Range neuset_elems, neuset_meshsets;
 
     // get the sense tag; don't need to check return, might be an error if the tag
     // hasn't been created yet
-  MBTag sense_tag = 0;
+  Tag sense_tag = 0;
   mbImpl->tag_get_handle("SENSE", sense_tag);
 
     // get the entities in this set
-  MBErrorCode result = mbImpl->get_entities_by_handle(neuset, neuset_elems, true);
+  ErrorCode result = mbImpl->get_entities_by_handle(neuset, neuset_elems, true);
   if (MB_FAILURE == result) return result;
   
     // now remove the meshsets into the neuset_meshsets; first find the first meshset,
-  MBRange::iterator range_iter = neuset_elems.begin();
+  Range::iterator range_iter = neuset_elems.begin();
   while (TYPE_FROM_HANDLE(*range_iter) != MBENTITYSET && range_iter != neuset_elems.end())
     range_iter++;
   
     // then, if there are some, copy them into neuset_meshsets and erase from neuset_elems
   if (range_iter != neuset_elems.end()) {
-    std::copy(range_iter, neuset_elems.end(), mb_range_inserter(neuset_meshsets));
+    std::copy(range_iter, neuset_elems.end(), range_inserter(neuset_meshsets));
     neuset_elems.erase(range_iter, neuset_elems.end());
   }
   
@@ -1000,7 +1002,7 @@
     // (if the sense is 0, copy into both ranges)
 
     // need to step forward on list until we reach the right dimension
-  MBRange::iterator dum_it = neuset_elems.end();
+  Range::iterator dum_it = neuset_elems.end();
   dum_it--;
   int target_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*dum_it));
   dum_it = neuset_elems.begin();
@@ -1009,9 +1011,9 @@
     dum_it++;
 
   if (current_sense == 1 || current_sense == 0)
-    std::copy(dum_it, neuset_elems.end(), mb_range_inserter(forward_elems));
+    std::copy(dum_it, neuset_elems.end(), range_inserter(forward_elems));
   if (current_sense == -1 || current_sense == 0)
-    std::copy(dum_it, neuset_elems.end(), mb_range_inserter(reverse_elems));
+    std::copy(dum_it, neuset_elems.end(), range_inserter(reverse_elems));
   
     // now loop over the contained meshsets, getting the sense of those and calling this
     // function recursively
@@ -1032,4 +1034,6 @@
 }
 
 
+} // namespace moab
+
   

Modified: MOAB/trunk/src/io/WriteCCMIO.hpp
===================================================================
--- MOAB/trunk/src/io/WriteCCMIO.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteCCMIO.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,35 +37,37 @@
 #include <vector>
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/WriterIface.hpp"
 #include "ccmio.h"
 
-class MBWriteUtilIface;
+namespace moab {
 
-class MB_DLL_EXPORT WriteCCMIO : public MBWriterIface
+class WriteUtilIface;
+
+class MB_DLL_EXPORT WriteCCMIO : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteCCMIO(MBInterface *impl);
+   WriteCCMIO(Interface *impl);
 
    //! Destructor
   virtual ~WriteCCMIO();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                          const MBEntityHandle *output_list,
+                          const EntityHandle *output_list,
                           const int num_sets,
                           const std::vector<std::string>& qa_list,
-                          const MBTag* tag_list,
+                          const Tag* tag_list,
                           int num_tags,
                           int export_dimension);
   
@@ -78,8 +80,8 @@
     int number_nodes_per_element;
     int number_attributes;
     ExoIIElementType element_type;
-    MBEntityType moab_type;
-    MBRange *elements;
+    EntityType moab_type;
+    Range *elements;
   };
 
 //! struct used to hold data for each nodeset to be output; used by
@@ -88,7 +90,7 @@
   {
     int id;
     int number_nodes;
-    std::vector< MBEntityHandle > nodes;
+    std::vector< EntityHandle > nodes;
     std::vector< double > node_dist_factors;
   
   };
@@ -99,9 +101,9 @@
   {
     int id;
     int number_elements;
-    std::vector<MBEntityHandle> elements;
+    std::vector<EntityHandle> elements;
     std::vector<int> side_numbers;
-    MBEntityHandle mesh_set_handle;
+    EntityHandle mesh_set_handle;
   };
 
 
@@ -111,7 +113,7 @@
   //int number_dimensions();
 
     //! open a file for writing
-  MBErrorCode open_file(const char *filename);
+  ErrorCode open_file(const char *filename);
 
   //! contains the general information about a mesh
   class MeshInfo
@@ -123,7 +125,7 @@
     unsigned int num_matsets;
     unsigned int num_dirsets;
     unsigned int num_neusets;
-    MBRange nodes;
+    Range nodes;
 
     MeshInfo() 
         : num_dim(0), num_nodes(0), num_elements(0), num_matsets(0), 
@@ -135,62 +137,64 @@
 private:
 
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! file name
   std::string fileName;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mPartitionSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGlobalIdTag;
-  MBTag mMatSetIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mPartitionSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGlobalIdTag;
+  Tag mMatSetIdTag;
 
-  MBTag mEntityMark;   //used to say whether an entity will be exported
+  Tag mEntityMark;   //used to say whether an entity will be exported
 
-  MBErrorCode gather_mesh_information(MeshInfo &mesh_info,
+  ErrorCode gather_mesh_information(MeshInfo &mesh_info,
                                       std::vector<MaterialSetData> &matset_info,
                                       std::vector<NeumannSetData> &neuset_info,
                                       std::vector<DirichletSetData> &dirset_info,
-                                      std::vector<MBEntityHandle> &matsets,
-                                      std::vector<MBEntityHandle> &neusets,
-                                      std::vector<MBEntityHandle> &dirsets);
+                                      std::vector<EntityHandle> &matsets,
+                                      std::vector<EntityHandle> &neusets,
+                                      std::vector<EntityHandle> &dirsets);
   
-  MBErrorCode initialize_file(MeshInfo &mesh_info);
+  ErrorCode initialize_file(MeshInfo &mesh_info);
 
-  MBErrorCode write_nodes(CCMIOID rootID, const MBRange& nodes, 
+  ErrorCode write_nodes(CCMIOID rootID, const Range& nodes, 
                           const int dimension, int *&vgids);
   
     // get global ids for these entities; allocates gids and passes back,
     // caller is responsible for deleting
-  MBErrorCode get_gids(const MBRange &ents, int *&gids,
+  ErrorCode get_gids(const Range &ents, int *&gids,
                        int &minid, int &maxid);
   
-  MBErrorCode write_matsets(MeshInfo &mesh_info, 
+  ErrorCode write_matsets(MeshInfo &mesh_info, 
                             std::vector<MaterialSetData> &matset_data,
                             std::vector<NeumannSetData> &neuset_data,
-                            MBRange &verts,
+                            Range &verts,
                             const int *vgids);
   
-  MBErrorCode get_valid_sides(MBRange &elems, const int sense,
+  ErrorCode get_valid_sides(Range &elems, const int sense,
                               WriteCCMIO::NeumannSetData &neuset_data);
   
   void reset_matset(std::vector<MaterialSetData> &matset_info);
   
-  MBErrorCode get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                               MBRange &forward_elems, MBRange &reverse_elems);
+  ErrorCode get_neuset_elems(EntityHandle neuset, int current_sense,
+                               Range &forward_elems, Range &reverse_elems);
   
-  MBErrorCode transform_coords(const int dimension, const int num_nodes, double *coords);
+  ErrorCode transform_coords(const int dimension, const int num_nodes, double *coords);
 
-  MBErrorCode write_problem_description(CCMIOID rootID, CCMIOID stateID);
+  ErrorCode write_problem_description(CCMIOID rootID, CCMIOID stateID);
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteGMV.cpp
===================================================================
--- MOAB/trunk/src/io/WriteGMV.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteGMV.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,15 +24,17 @@
 
 #include "WriteGMV.hpp"
 
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
 #include <fstream>
 #include <assert.h>
 
+namespace moab {
+
 const char *WriteGMV::gmvTypeNames[] = {
   "",
   "line",
@@ -48,17 +50,17 @@
   ""
 };
 
-MBWriterIface* WriteGMV::factory( MBInterface* iface )
+WriterIface* WriteGMV::factory( Interface* iface )
   { return new WriteGMV( iface ); }
 
-WriteGMV::WriteGMV(MBInterface *impl) 
+WriteGMV::WriteGMV(Interface *impl) 
     : mbImpl(impl), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   mMaterialSetTag  = 0;
@@ -72,7 +74,7 @@
   // initialize in case tag_get_handle fails below
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, mMaterialSetTag,
                               &dum_val);
@@ -102,19 +104,19 @@
 
 WriteGMV::~WriteGMV() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mbImpl->release_interface(iface_name, mWriteIface);
 }
 
-MBErrorCode WriteGMV::write_file(const char *file_name,
-                                 const MBEntityHandle output_set,
+ErrorCode WriteGMV::write_file(const char *file_name,
+                                 const EntityHandle output_set,
                                  const int user_dimension,
                                  const bool mesh,
                                  const bool poly_mesh) 
 {
     // general function for writing a mesh
   
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
 
     // initialize file
 
@@ -131,17 +133,17 @@
   return result;
 }
 
-MBErrorCode WriteGMV::write_file( const char* filename,
+ErrorCode WriteGMV::write_file( const char* filename,
                                   const bool ,
                                   const FileOptions& opts,
-                                  const MBEntityHandle* output_sets,
+                                  const EntityHandle* output_sets,
                                   const int num_output_sets,
                                   const std::vector<std::string>& ,
-                                  const MBTag*,
+                                  const Tag*,
                                   int,
                                   int dimension )
 {
-  MBEntityHandle output_set = 0;
+  EntityHandle output_set = 0;
   if (output_sets && num_output_sets > 0)
   {
     if (num_output_sets > 1)
@@ -158,14 +160,14 @@
 }
   
 
-MBErrorCode WriteGMV::local_write_mesh(const char *file_name,
-                                       const MBEntityHandle output_set,
+ErrorCode WriteGMV::local_write_mesh(const char *file_name,
+                                       const EntityHandle output_set,
                                        const int user_dimension,
                                        const bool mesh,
                                        const bool poly_mesh)
 {
   std::ofstream ofile;
-  MBErrorCode result;
+  ErrorCode result;
 
   if (mesh) {
       // need to insert ".gmv"
@@ -183,8 +185,8 @@
   ofile << "gmvinput ascii" << std::endl;
   
     // get elements to be output
-  MBRange dum_range, elements, all_verts;
-  MBEntityType otype;
+  Range dum_range, elements, all_verts;
+  EntityType otype;
   if (poly_mesh) {
     result = mbImpl->get_entities_by_type(output_set, MBPOLYGON, elements, true);
     if (MB_SUCCESS != result) return result;
@@ -197,12 +199,12 @@
       result = mbImpl->get_entities_by_type(output_set, otype, dum_range, true);
       if (MB_SUCCESS != result) return result;
 
-      std::copy(dum_range.begin(), dum_range.end(), mb_range_inserter(elements));
+      std::copy(dum_range.begin(), dum_range.end(), range_inserter(elements));
     }
   }
   
     // gather the vertices in these elements
-  result = mbImpl->get_adjacencies(elements, 0, false, all_verts, MBInterface::UNION);
+  result = mbImpl->get_adjacencies(elements, 0, false, all_verts, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   
   int num_verts = all_verts.size();
@@ -239,25 +241,25 @@
     // iterate over types in selected dimension
 
   std::vector<int> connect;
-  std::vector<MBEntityHandle> connecth;
+  std::vector<EntityHandle> connecth;
 
   if (mesh) {
-    MBRange sub_range;
+    Range sub_range;
     
     ofile << "cells " << elements.size() << std::endl;
   
-    for (MBEntityType otype = MBCN::TypeDimensionMap[user_dimension].first;
+    for (EntityType otype = MBCN::TypeDimensionMap[user_dimension].first;
          otype <= MBCN::TypeDimensionMap[user_dimension].second; otype++) {
 
       if (otype == MBPOLYGON || otype == MBPOLYHEDRON) continue;
       
         // get the first element of this type in the range, and one past the last
-      MBRange::iterator lower =
-        MBRange::lower_bound(elements.begin(),
+      Range::iterator lower =
+        Range::lower_bound(elements.begin(),
                              elements.end(),
                              CREATE_HANDLE(otype, MB_START_ID, i));
-      MBRange::iterator upper =
-        MBRange::lower_bound(elements.begin(),
+      Range::iterator upper =
+        Range::lower_bound(elements.begin(),
                              elements.end(),
                              CREATE_HANDLE(otype+1, MB_START_ID, i));
       
@@ -265,7 +267,7 @@
     
         // copy these elements into a subrange
       sub_range.clear();
-      std::copy(lower, upper, mb_range_inserter(sub_range));
+      std::copy(lower, upper, range_inserter(sub_range));
 
         // make sure the connectivity array is big enough
       int verts_per = MBCN::VerticesPerEntity(otype);
@@ -296,7 +298,7 @@
   else if (poly_mesh) {
   
       // write polygons/hedra, if any
-    MBRange polygons, polyhedra;
+    Range polygons, polyhedra;
     result = mbImpl->get_entities_by_type(output_set, MBPOLYGON, polygons, true);
     if (MB_SUCCESS != result) return result;
   
@@ -311,7 +313,7 @@
 
     ofile << "faces " << polygons.size() << " " << polyhedra.size() << std::endl;
 
-    for (MBRange::iterator rit = polygons.begin(); rit != polygons.end(); rit++) {
+    for (Range::iterator rit = polygons.begin(); rit != polygons.end(); rit++) {
         // get the vertices
       connecth.clear();
       result = mbImpl->get_connectivity(&(*rit), 1, connecth, true);
@@ -322,7 +324,7 @@
         // get the polyhedra, if any
       if (user_dimension == 3) {
         polyhedra.clear();
-        result = mbImpl->get_adjacencies(MBRange(*rit, *rit), 3, false, polyhedra);
+        result = mbImpl->get_adjacencies(Range(*rit, *rit), 3, false, polyhedra);
         if (MB_SUCCESS != result) return result;
     
           // put them in the connect array
@@ -358,3 +360,5 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
+

Modified: MOAB/trunk/src/io/WriteGMV.hpp
===================================================================
--- MOAB/trunk/src/io/WriteGMV.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteGMV.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -29,37 +29,40 @@
 #ifndef WRITEGMV_HPP
 #define WRITEGMV_HPP
 
-#include "MBForward.hpp"
-#include "MBWriterIface.hpp"
-class MBWriteUtilIface;
+#include "moab/Forward.hpp"
+#include "moab/WriterIface.hpp"
 
+namespace moab {
+
+class WriteUtilIface;
+
 //! Output Exodus File for VERDE
-class MB_DLL_EXPORT WriteGMV : public MBWriterIface
+class MB_DLL_EXPORT WriteGMV : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteGMV(MBInterface *impl);
+   WriteGMV(Interface *impl);
 
    //! Destructor
   virtual ~WriteGMV();
 
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
-  MBErrorCode write_file( const char* filename,
+  ErrorCode write_file( const char* filename,
                           const bool overwite,
                           const FileOptions& opts,
-                          const MBEntityHandle* output_sets,
+                          const EntityHandle* output_sets,
                           const int num_output_sets,
                           const std::vector<std::string>& qa_list,
-                          const MBTag* tag_list,
+                          const Tag* tag_list,
                           int num_tags,
                           int requested_dimension );
 
     //! writes out a mesh file
-  MBErrorCode write_file(const char *file_name,
-                         const MBEntityHandle output_set,
+  ErrorCode write_file(const char *file_name,
+                         const EntityHandle output_set,
                          const int user_dimension = 3,
                          const bool mesh = true,
                          const bool poly_mesh = true);
@@ -69,28 +72,30 @@
 private:
 
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! Meshset Handle for the mesh that is currently being written
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGeomDimensionTag;
-  MBTag mGlobalIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGeomDimensionTag;
+  Tag mGlobalIdTag;
 
   static const char *gmvTypeNames[MBMAXTYPE];
   
-  MBErrorCode local_write_mesh(const char *file_name,
-                               const MBEntityHandle output_set,
+  ErrorCode local_write_mesh(const char *file_name,
+                               const EntityHandle output_set,
                                const int user_dimension,
                                const bool mesh,
                                const bool poly_mesh);
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteGmsh.cpp
===================================================================
--- MOAB/trunk/src/io/WriteGmsh.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteGmsh.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
 #include "WriteGmsh.hpp"
-#include "MBCN.hpp"
-#include "MBTagConventions.hpp"
-#include "MBParallelConventions.h"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/WriteUtilIface.hpp"
 #include "FileOptions.hpp"
 #include "GmshUtil.hpp"
 
@@ -12,22 +12,24 @@
 #include <map>
 #include <set>
 
+namespace moab {
+
 const int DEFAULT_PRECISION = 10;
 
-MBWriterIface *WriteGmsh::factory( MBInterface* iface )
+WriterIface *WriteGmsh::factory( Interface* iface )
   { return new WriteGmsh( iface ); }
 
-WriteGmsh::WriteGmsh(MBInterface *impl) 
+WriteGmsh::WriteGmsh(Interface *impl) 
     : mbImpl(impl)
 {
   void* ptr = 0;
-  impl->query_interface("MBWriteUtilIface", &ptr);
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface("WriteUtilIface", &ptr);
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 }
 
 WriteGmsh::~WriteGmsh() 
 {
-  mbImpl->release_interface("MBWriteUtilIface", mWriteIface);
+  mbImpl->release_interface("WriteUtilIface", mWriteIface);
 }
 
 
@@ -45,18 +47,18 @@
 };
   
     //! writes out a file
-MBErrorCode WriteGmsh::write_file(const char *file_name,
+ErrorCode WriteGmsh::write_file(const char *file_name,
                                   const bool overwrite,
                                   const FileOptions& options,
-                                  const MBEntityHandle *output_list,
+                                  const EntityHandle *output_list,
                                   const int num_sets,
                                   const std::vector<std::string>& ,
-                                  const MBTag* ,
+                                  const Tag* ,
                                   int ,
                                   int )
 {
-  MBErrorCode rval;
-  MBTag global_id = 0, block_tag = 0, geom_tag = 0, prtn_tag = 0;
+  ErrorCode rval;
+  Tag global_id = 0, block_tag = 0, geom_tag = 0, prtn_tag = 0;
 
   if (!overwrite)
   {
@@ -74,12 +76,12 @@
   
   
     // Define arrays to hold entity sets of interest
-  MBRange sets[3];
-  MBTag set_tags[] = { block_tag, geom_tag, prtn_tag };
-  MBTag set_ids[] = { block_tag, 0 /*global_id*/, prtn_tag };
+  Range sets[3];
+  Tag set_tags[] = { block_tag, geom_tag, prtn_tag };
+  Tag set_ids[] = { block_tag, 0 /*global_id*/, prtn_tag };
   
     // Get entities to write
-  MBRange elements, nodes;
+  Range elements, nodes;
   if (!output_list)
   {
     rval = mbImpl->get_entities_by_dimension( 0, 0, nodes, false );
@@ -87,7 +89,7 @@
       return rval;
     for (int d = 1; d < 3; ++d)
     {
-      MBRange tmp_range;
+      Range tmp_range;
       rval = mbImpl->get_entities_by_dimension( 0, d, tmp_range, false );
       if (MB_SUCCESS != rval)
         return rval;
@@ -105,10 +107,10 @@
   {
     for (int i = 0; i < num_sets; ++i)
     {
-      MBEntityHandle set = output_list[i];
+      EntityHandle set = output_list[i];
       for (int d = 1; d < 3; ++d)
       {
-        MBRange tmp_range, tmp_nodes;
+        Range tmp_range, tmp_nodes;
         rval = mbImpl->get_entities_by_dimension( set, d, tmp_range, true );
         if (rval != MB_SUCCESS)
           return rval;
@@ -122,7 +124,7 @@
       for (int s = 0; s < 3; ++s)
         if (set_tags[s])
         {
-          MBRange tmp_range;
+          Range tmp_range;
           rval = mbImpl->get_entities_by_type_and_tag( set, MBENTITYSET, set_tags+s, 0, 1, tmp_range );
           if (MB_SUCCESS != rval) return rval;
           sets[s].merge( tmp_range );
@@ -149,7 +151,7 @@
             mbImpl->tag_get_data( global_id, elements, &global_id_array[0] ) )
   {
     id_iter = global_id_array.begin();
-    for (MBRange::iterator i = elements.begin(); i != elements.end(); ++i, ++id_iter)
+    for (Range::iterator i = elements.begin(); i != elements.end(); ++i, ++id_iter)
       *id_iter = mbImpl->id_from_handle( *i );
   }
   
@@ -161,12 +163,12 @@
       max_id = *id_iter;
   
     // Initialize ElemInfo struct for each element
-  std::map<MBEntityHandle,ElemInfo> elem_sets; // per-element info
+  std::map<EntityHandle,ElemInfo> elem_sets; // per-element info
   std::set<int> elem_global_ids;               // temporary for finding duplicate IDs
   id_iter = global_id_array.begin();
     // Iterate backwards to give highest-dimension entities first dibs for
     // a conflicting ID.
-  for (MBRange::reverse_iterator i = elements.rbegin(); i != elements.rend(); ++i)
+  for (Range::reverse_iterator i = elements.rbegin(); i != elements.rend(); ++i)
   {
     int id = *id_iter; ++id_iter;
     if (!elem_global_ids.insert(id).second)
@@ -176,9 +178,9 @@
     ei.count = 0;
     ei.id = id;
     
-    MBEntityType type = mbImpl->type_from_handle( *i );
+    EntityType type = mbImpl->type_from_handle( *i );
     int num_vtx;
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     rval = mbImpl->get_connectivity( *i, conn, num_vtx );
     if (MB_SUCCESS != rval)
       return rval;
@@ -203,7 +205,7 @@
     if (!set_tags[s])
       continue;
       
-    for (MBRange::iterator i = sets[s].begin(); i != sets[s].end(); ++i)
+    for (Range::iterator i = sets[s].begin(); i != sets[s].end(); ++i)
     {
       int id;
       if (set_ids[s]) 
@@ -217,13 +219,13 @@
         id = mbImpl->id_from_handle( *i );
       }
       
-      MBRange elems;
+      Range elems;
       rval = mbImpl->get_entities_by_handle( *i, elems );
       if (MB_SUCCESS != rval)
         return rval;
 
       elems = intersect( elems,  elements );
-      for (MBRange::iterator j = elems.begin(); j != elems.end(); ++j)
+      for (Range::iterator j = elems.begin(); j != elems.end(); ++j)
         elem_sets[*j].set( s, id );
     }
   }
@@ -255,7 +257,7 @@
   if (MB_SUCCESS != rval)
     return rval;
   std::vector<double>::iterator c = coords.begin();
-  for (MBRange::iterator i = nodes.begin(); i != nodes.end(); ++i)
+  for (Range::iterator i = nodes.begin(); i != nodes.end(); ++i)
   {
     out << mbImpl->id_from_handle( *i );
     out << " " << *c; ++c;
@@ -272,11 +274,11 @@
     // Write elements
   out << "$Elements" << std::endl;
   out << elem_sets.size() << std::endl;
-  for (std::map<MBEntityHandle,ElemInfo>::iterator i = elem_sets.begin();
+  for (std::map<EntityHandle,ElemInfo>::iterator i = elem_sets.begin();
        i != elem_sets.end(); ++i)
   {
     int num_vtx;
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     rval = mbImpl->get_connectivity( i->first, conn, num_vtx );
     if (MB_SUCCESS != rval)
       return rval;
@@ -306,4 +308,6 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab
 
+

Modified: MOAB/trunk/src/io/WriteGmsh.hpp
===================================================================
--- MOAB/trunk/src/io/WriteGmsh.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteGmsh.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -30,43 +30,47 @@
 #ifndef WRITE_GMSH_HPP
 #define WRITE_GMSH_HPP
 
-#include "MBForward.hpp"
-#include "MBWriterIface.hpp"
-class MBWriteUtilIface;
-
+#include "moab/Forward.hpp"
+#include "moab/WriterIface.hpp"
 #include <stdio.h>
 
-class WriteGmsh : public MBWriterIface
+namespace moab {
+
+class WriteUtilIface;
+
+class WriteGmsh : public WriterIface
 {
  
 public:
   
     //! factory method
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
    //! Constructor
-  WriteGmsh(MBInterface *impl);
+  WriteGmsh(Interface *impl);
 
    //! Destructor
   virtual ~WriteGmsh();
   
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                         const MBEntityHandle *output_list,
+                         const EntityHandle *output_list,
                          const int num_sets,
                          const std::vector<std::string>& qa_list,
-                         const MBTag* tag_list,
+                         const Tag* tag_list,
                          int num_tags,
                          int export_dimension);  
 
 private:
                                        
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
 
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/src/io/WriteHDF5.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteHDF5.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,7 +25,6 @@
 // Creation Date : 04/01/04
 //-------------------------------------------------------------------------
 
-#include "MBEntityHandle.h"
 #ifndef HDF5_FILE
 #  error Attempt to compile WriteHDF5 with HDF5 support disabled
 #endif
@@ -44,18 +43,18 @@
 /* include our MPI header before any HDF5 because otherwise
    it will get included indirectly by HDF5 */
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif 
 #include <H5Tpublic.h>
 #include <H5Ppublic.h>
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 #include "WriteHDF5.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/WriteUtilIface.hpp"
 #include "FileOptions.hpp"
-#include "MBVersion.h"
+#include "moab/Version.h"
 #include "mhdf.h"
 /* Access HDF5 file handle for debugging
 #include <H5Fpublic.h>
@@ -99,6 +98,8 @@
 #  endif
 #endif
 
+namespace moab {
+
 template <typename T> inline 
 void VALGRIND_MAKE_VEC_UNDEFINED( std::vector<T>& v ) {
     VALGRIND_MAKE_MEM_UNDEFINED( &v[0], v.size() * sizeof(T) );
@@ -131,7 +132,7 @@
 
   // Some macros to handle error checking.  The
   // CHK_MHDF__ERR* macros check the value of an mhdf_Status 
-  // object.  The CHK_MB_ERR_* check the value of an MBStatus.
+  // object.  The CHK_MB_ERR_* check the value of an ErrorCode.
   // The *_0 macros accept no other arguments. The *_1
   // macros accept a single hdf5 handle to close on error.
   // The *_2 macros accept an array of two hdf5 handles to
@@ -222,8 +223,8 @@
   return (A);                                   \
 } while(false)
 
-bool WriteHDF5::convert_handle_tag( const MBEntityHandle* source,
-                                    MBEntityHandle* dest, size_t count ) const
+bool WriteHDF5::convert_handle_tag( const EntityHandle* source,
+                                    EntityHandle* dest, size_t count ) const
 {
   bool some_valid = false;
   for (size_t i = 0; i < count; ++i) {
@@ -238,17 +239,17 @@
   return some_valid;
 }
 
-bool WriteHDF5::convert_handle_tag( MBEntityHandle* data, size_t count ) const
+bool WriteHDF5::convert_handle_tag( EntityHandle* data, size_t count ) const
 {
-  assert( sizeof(MBEntityHandle) == sizeof(id_t) );
+  assert( sizeof(EntityHandle) == sizeof(id_t) );
   return convert_handle_tag( data, data, count );
 }
 
-MBErrorCode WriteHDF5::assign_ids( const MBRange& entities, id_t id )
+ErrorCode WriteHDF5::assign_ids( const Range& entities, id_t id )
 {
-  MBRange::const_pair_iterator pi;
+  Range::const_pair_iterator pi;
   for (pi = entities.const_pair_begin(); pi != entities.const_pair_end(); ++pi) {
-    const MBEntityHandle n = pi->second - pi->first + 1;
+    const EntityHandle n = pi->second - pi->first + 1;
 #ifdef DEBUG
     printf( "Assigning %s %lu to %lu to file IDs [%lu,%lu]\n",
       MBCN::EntityTypeName(TYPE_FROM_HANDLE(pi->first)),
@@ -279,10 +280,10 @@
 }
   
 
-MBWriterIface* WriteHDF5::factory( MBInterface* iface )
+WriterIface* WriteHDF5::factory( Interface* iface )
   { return new WriteHDF5( iface ); }
 
-WriteHDF5::WriteHDF5( MBInterface* iface )
+WriteHDF5::WriteHDF5( Interface* iface )
   : bufferSize( WRITE_HDF5_BUFFER_SIZE ),
     dataBuffer( 0 ),
     iFace( iface ), 
@@ -302,9 +303,9 @@
 {
 }
 
-MBErrorCode WriteHDF5::init()
+ErrorCode WriteHDF5::init()
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
   if (writeUtil) // init has already been called
     return MB_SUCCESS;
@@ -319,7 +320,7 @@
  
     // Get the util interface
   void* ptr = 0;
-  rval = iFace->query_interface( "MBWriteUtilIface", &ptr );
+  rval = iFace->query_interface( "WriteUtilIface", &ptr );
   CHK_MB_ERR_0(rval);
 
   idMap.clear();
@@ -330,11 +331,11 @@
     return rval;
   }
 
-  writeUtil = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  writeUtil = reinterpret_cast<WriteUtilIface*>(ptr);
   return MB_SUCCESS;
 }
   
-MBErrorCode WriteHDF5::write_finished()
+ErrorCode WriteHDF5::write_finished()
 {
     // release memory allocated in lists
   exportList.clear();
@@ -369,17 +370,17 @@
   if (!writeUtil) // init() failed.
     return;
 
-  iFace->release_interface( "MBWriteUtilIface", writeUtil );
+  iFace->release_interface( "WriteUtilIface", writeUtil );
 }
 
 
-MBErrorCode WriteHDF5::write_file( const char* filename,
+ErrorCode WriteHDF5::write_file( const char* filename,
                                    bool overwrite,
                                    const FileOptions& opts,
-                                   const MBEntityHandle* set_array,
+                                   const EntityHandle* set_array,
                                    const int num_sets,
                                    const std::vector<std::string>& qa_records,
-                                   const MBTag* tag_list,
+                                   const Tag* tag_list,
                                    int num_tags,
                                    int user_dimension )
 {
@@ -387,7 +388,7 @@
 
   bufferSize = WRITE_HDF5_BUFFER_SIZE;
   int buf_size;
-  MBErrorCode rval = opts.get_int_option( "BUFFER_SIZE", buf_size );
+  ErrorCode rval = opts.get_int_option( "BUFFER_SIZE", buf_size );
   if (MB_SUCCESS == rval && buf_size >= 24)
     bufferSize = buf_size;
 
@@ -400,7 +401,7 @@
   filePtr = 0;
 
     // Do actual write.
-  MBErrorCode result = write_file_impl( filename, overwrite, opts, 
+  ErrorCode result = write_file_impl( filename, overwrite, opts, 
                                         set_array, num_sets, 
                                         qa_records, 
                                         tag_list, num_tags,
@@ -438,20 +439,20 @@
 }  
 
 
-MBErrorCode WriteHDF5::write_file_impl( const char* filename,
+ErrorCode WriteHDF5::write_file_impl( const char* filename,
                                         bool overwrite,
                                         const FileOptions& opts,
-                                        const MBEntityHandle* set_array,
+                                        const EntityHandle* set_array,
                                         const int num_sets,
                                         const std::vector<std::string>& qa_records,
-                                        const MBTag* tag_list, 
+                                        const Tag* tag_list, 
                                         int num_tags,
                                         int user_dimension )
 {
-  MBErrorCode result;
+  ErrorCode result;
   std::list<SparseTag>::const_iterator t_itor;
   std::list<ExportSet>::iterator ex_itor;
-  MBEntityHandle elem_count, max_id;
+  EntityHandle elem_count, max_id;
   
   if (MB_SUCCESS != init())
     return MB_FAILURE;
@@ -467,7 +468,7 @@
   }
   else
   {
-    std::vector<MBEntityHandle> passed_export_list(set_array, set_array+num_sets);
+    std::vector<EntityHandle> passed_export_list(set_array, set_array+num_sets);
     VALGRIND_MAKE_VEC_UNDEFINED( passed_export_list );
     result = gather_mesh_info( passed_export_list );
     if (MB_SUCCESS != result) 
@@ -483,7 +484,7 @@
   elem_count = nodeSet.range.size() + setSet.range.size();
   for (ex_itor = exportList.begin(); ex_itor != exportList.end(); ++ex_itor)
     elem_count += ex_itor->range.size();
-  max_id = (MBEntityHandle)1 << (8*sizeof(id_t)-1);
+  max_id = (EntityHandle)1 << (8*sizeof(id_t)-1);
   if (elem_count > max_id)
   {
     writeUtil->report_error("ID space insufficient for mesh size.\n");
@@ -575,9 +576,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::initialize_mesh( const MBRange ranges[5] )
+ErrorCode WriteHDF5::initialize_mesh( const Range ranges[5] )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   if (!ranges[0].all_of_type(MBVERTEX))
     return MB_FAILURE;
@@ -595,9 +596,9 @@
   maxNumSetContent = maxNumSetChildren = maxMumSetParents = 0;
 
   exportList.clear();
-  std::vector<MBRange> bins(1024); // sort entities by connectivity length
-                                   // resize is expensive due to MBRange copy, so start big
-  for (MBEntityType type = MBEDGE; type < MBENTITYSET; ++type)
+  std::vector<Range> bins(1024); // sort entities by connectivity length
+                                   // resize is expensive due to Range copy, so start big
+  for (EntityType type = MBEDGE; type < MBENTITYSET; ++type)
   {
     ExportSet set;
     set.max_num_ents = set.max_num_adjs = 0;
@@ -606,11 +607,11 @@
       // Group entities by connectivity length
     bins.clear();
     assert(dim >= 0 && dim <= 4);
-    std::pair<MBRange::const_iterator,MBRange::const_iterator> p = ranges[dim].equal_range(type);
-    MBRange::const_iterator i = p.first;
+    std::pair<Range::const_iterator,Range::const_iterator> p = ranges[dim].equal_range(type);
+    Range::const_iterator i = p.first;
     while (i != p.second) {
-      MBRange::const_iterator first = i;
-      MBEntityHandle const* conn;
+      Range::const_iterator first = i;
+      EntityHandle const* conn;
       int len, firstlen;
       rval = iFace->get_connectivity( *i, conn, firstlen );
       if (MB_SUCCESS != rval)
@@ -631,7 +632,7 @@
     }
 
       // Create ExportSet for each group
-    for (std::vector<MBRange>::iterator j = bins.begin(); j != bins.end(); ++j) {
+    for (std::vector<Range>::iterator j = bins.begin(); j != bins.end(); ++j) {
       if (j->empty())
         continue;
         
@@ -648,29 +649,29 @@
 
                                          
   // Gather the mesh to be written from a list of owning meshsets.
-MBErrorCode WriteHDF5::gather_mesh_info( 
-                           const std::vector<MBEntityHandle>& export_sets )
+ErrorCode WriteHDF5::gather_mesh_info( 
+                           const std::vector<EntityHandle>& export_sets )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   int dim;
-  MBRange range;      // temporary storage
-  MBRange ranges[5];  // lists of entities to export, grouped by dimension
+  Range range;      // temporary storage
+  Range ranges[5];  // lists of entities to export, grouped by dimension
   
     // Gather list of all related sets
-  std::vector<MBEntityHandle> stack(export_sets);
+  std::vector<EntityHandle> stack(export_sets);
   std::copy( export_sets.begin(), export_sets.end(), stack.begin() );
-  std::vector<MBEntityHandle> set_children;
+  std::vector<EntityHandle> set_children;
   while( !stack.empty() )
   {
-    MBEntityHandle meshset = stack.back(); stack.pop_back();
+    EntityHandle meshset = stack.back(); stack.pop_back();
     ranges[4].insert( meshset );
   
       // Get contained sets
     range.clear();
     rval = iFace->get_entities_by_type( meshset, MBENTITYSET, range );
     CHK_MB_ERR_0(rval);
-    for (MBRange::iterator ritor = range.begin(); ritor != range.end(); ++ritor)
+    for (Range::iterator ritor = range.begin(); ritor != range.end(); ++ritor)
       if (ranges[4].find( *ritor ) == ranges[4].end())
         stack.push_back( *ritor );
     
@@ -678,7 +679,7 @@
     set_children.clear();
     rval = iFace->get_child_meshsets( meshset, set_children, 1 );
     CHK_MB_ERR_0(rval);
-    for (std::vector<MBEntityHandle>::iterator vitor = set_children.begin();
+    for (std::vector<EntityHandle>::iterator vitor = set_children.begin();
          vitor != set_children.end(); ++vitor )
       if (ranges[4].find( *vitor ) == ranges[4].end())
         stack.push_back( *vitor );
@@ -686,7 +687,7 @@
   
     // Gather list of all mesh entities from list of sets,
     // grouped by dimension.
-  for (MBRange::iterator setitor = ranges[4].begin();
+  for (Range::iterator setitor = ranges[4].begin();
        setitor != ranges[4].end(); ++setitor)
   {
     for (dim = 0; dim < 4; ++dim)
@@ -720,10 +721,10 @@
 }
 
   // Gather all the mesh and related information to be written.
-MBErrorCode WriteHDF5::gather_all_mesh( )
+ErrorCode WriteHDF5::gather_all_mesh( )
 {
-  MBErrorCode rval;
-  MBRange ranges[5];
+  ErrorCode rval;
+  Range ranges[5];
 
   rval = iFace->get_entities_by_type( 0, MBVERTEX, ranges[0] );
   if (MB_SUCCESS != rval)
@@ -748,11 +749,11 @@
   return initialize_mesh( ranges );
 }
   
-MBErrorCode WriteHDF5::write_nodes( )
+ErrorCode WriteHDF5::write_nodes( )
 {
   mhdf_Status status;
   int dim, mesh_dim;
-  MBErrorCode rval;
+  ErrorCode rval;
   hid_t node_table;
   long first_id, num_nodes;
   
@@ -774,13 +775,13 @@
   long remaining_writes = num_writes;
 
   long offset = nodeSet.offset;
-  MBRange::const_iterator iter = nodeSet.range.begin();
+  Range::const_iterator iter = nodeSet.range.begin();
   while (remaining)
   {
     VALGRIND_MAKE_MEM_UNDEFINED( dataBuffer, bufferSize );
     long count = chunk_size < remaining ? chunk_size : remaining;
     remaining -= count;
-    MBRange::const_iterator end = iter;
+    Range::const_iterator end = iter;
     end += count;
     
     for (int d = 0; d < dim; d++)
@@ -823,10 +824,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::write_elems( ExportSet& elems )
+ErrorCode WriteHDF5::write_elems( ExportSet& elems )
 {
   mhdf_Status status;
-  MBErrorCode rval;
+  ErrorCode rval;
   long first_id;
   int nodes_per_elem;
   long table_size;
@@ -843,7 +844,7 @@
   assert ((unsigned long)table_size >= elems.offset + elems.range.size());
   
   
-  MBEntityHandle* buffer = (MBEntityHandle*)dataBuffer;
+  EntityHandle* buffer = (EntityHandle*)dataBuffer;
   int chunk_size = bufferSize / (elems.num_nodes * sizeof(id_t));
   long offset = elems.offset;
   long remaining = elems.range.size();
@@ -853,7 +854,7 @@
     num_writes = (elems.max_num_ents+chunk_size-1) / chunk_size;
   }
   long remaining_writes = num_writes;
-  MBRange::iterator iter = elems.range.begin();
+  Range::iterator iter = elems.range.begin();
   
   while (remaining)
   {
@@ -861,7 +862,7 @@
     long count = chunk_size < remaining ? chunk_size : remaining;
     remaining -= count;
   
-    MBRange::iterator next = iter;
+    Range::iterator next = iter;
     next += count;
     rval = writeUtil->get_element_array( iter, next, elems.num_nodes, 
                                          count * elems.num_nodes, buffer );
@@ -897,13 +898,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::get_set_info( MBEntityHandle set,
+ErrorCode WriteHDF5::get_set_info( EntityHandle set,
                                      long& num_entities,
                                      long& num_children,
                                      long& num_parents,
                                      unsigned long& flags )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int i;
   unsigned int u;
   
@@ -926,16 +927,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::write_parents_children( bool children )
+ErrorCode WriteHDF5::write_parents_children( bool children )
 {
   mhdf_Status status;
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   long table_size;
   hid_t table;
-  MBRange::const_iterator iter = setSet.range.begin();
-  const MBRange::const_iterator end = setSet.range.end();
+  Range::const_iterator iter = setSet.range.begin();
+  const Range::const_iterator end = setSet.range.end();
   std::vector<id_t> id_list;
-  std::vector<MBEntityHandle> handle_list;
+  std::vector<EntityHandle> handle_list;
   
   assert(writeSets);
 
@@ -1005,11 +1006,11 @@
 }
 
 
-MBErrorCode WriteHDF5::write_sets( )
+ErrorCode WriteHDF5::write_sets( )
 {
   mhdf_Status status;
-  MBRange& sets = setSet.range;
-  MBErrorCode rval;
+  Range& sets = setSet.range;
+  ErrorCode rval;
   long first_id, meta_size, table_size, content_size, parent_size, child_size;
   hid_t set_table = 0, content_table = 0;
   
@@ -1048,15 +1049,15 @@
     VALGRIND_MAKE_MEM_UNDEFINED( content_buffer, content_chunk_size*sizeof(content_buffer[0]) );
   }
     
-  MBRange set_contents;
-  MBRange::const_iterator iter = sets.begin();
+  Range set_contents;
+  Range::const_iterator iter = sets.begin();
   long set_offset = setSet.offset;
   long content_offset = setContentsOffset;
   long child_offset = setChildrenOffset;
   long parent_offset = setParentsOffset;
   unsigned long flags;
   std::vector<id_t> id_list;
-  std::vector<MBEntityHandle> handle_list;
+  std::vector<EntityHandle> handle_list;
   while (remaining) {
     long* set_data = buffer;
     long count = remaining < chunk_size ? remaining : chunk_size;
@@ -1195,13 +1196,13 @@
 }
 
 /*
-MBErrorCode WriteHDF5::range_to_blocked_list( const MBRange& input_range,
+ErrorCode WriteHDF5::range_to_blocked_list( const Range& input_range,
                                               std::vector<id_t>& output_id_list )
 {
-  MBRange::const_iterator r_iter;
-  MBRange::const_iterator const r_end = input_range.end();
+  Range::const_iterator r_iter;
+  Range::const_iterator const r_end = input_range.end();
   std::vector<id_t>::iterator i_iter, w_iter;
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // Get file IDs from handles
   output_id_list.resize( input_range.size() );
@@ -1261,7 +1262,7 @@
   return MB_SUCCESS;
 }
 */
-MBErrorCode WriteHDF5::range_to_blocked_list( const MBRange& input_range,
+ErrorCode WriteHDF5::range_to_blocked_list( const Range& input_range,
                                               std::vector<id_t>& output_id_list, 
                                               bool& ranged_list )
 {
@@ -1273,13 +1274,13 @@
 
     // first try ranged format, but give up if we reach the 
     // non-range format size.
-  RangeMap<MBEntityHandle,id_t>::iterator ri = idMap.begin();
-  MBRange::const_pair_iterator pi;
+  RangeMap<EntityHandle,id_t>::iterator ri = idMap.begin();
+  Range::const_pair_iterator pi;
     // if we end up with more than this many range blocks, then
     // we're better off just writing the set as a simple list
   size_t pairs_remaining = input_range.size() / 2; 
   for (pi = input_range.const_pair_begin(); pi != input_range.const_pair_end(); ++pi) {
-    MBEntityHandle h = pi->first;
+    EntityHandle h = pi->first;
     while (h <= pi->second) {
       ri = idMap.lower_bound( ri, idMap.end(), h );
       if (ri == idMap.end() || ri->begin > h) {
@@ -1310,7 +1311,7 @@
     }
   }
   
-    // if we aren't writing anything (no entities in MBRange are
+    // if we aren't writing anything (no entities in Range are
     // being written to to file), clean up and return
   if (output_id_list.empty())
     return MB_SUCCESS;
@@ -1337,16 +1338,16 @@
 }
   
 
-MBErrorCode WriteHDF5::range_to_id_list( const MBRange& range,
+ErrorCode WriteHDF5::range_to_id_list( const Range& range,
                                          id_t* array )
 {
   VALGRIND_MAKE_MEM_UNDEFINED( array, sizeof(id_t)*range.size() );
-  MBErrorCode rval = MB_SUCCESS;
-  RangeMap<MBEntityHandle,id_t>::iterator ri = idMap.begin();
-  MBRange::const_pair_iterator pi;
+  ErrorCode rval = MB_SUCCESS;
+  RangeMap<EntityHandle,id_t>::iterator ri = idMap.begin();
+  Range::const_pair_iterator pi;
   id_t* i = array;
   for (pi = range.const_pair_begin(); pi != range.const_pair_end(); ++pi) {
-    MBEntityHandle h = pi->first;
+    EntityHandle h = pi->first;
     while (h <= pi->second) {
       ri = idMap.lower_bound( ri, idMap.end(), h );
       if (ri == idMap.end() || ri->begin > h) {
@@ -1371,13 +1372,13 @@
   return rval;
 }
  
-MBErrorCode WriteHDF5::vector_to_id_list( 
-                                 const std::vector<MBEntityHandle>& input,
+ErrorCode WriteHDF5::vector_to_id_list( 
+                                 const std::vector<EntityHandle>& input,
                                  std::vector<id_t>& output,
                                  bool remove_zeros )
 {
-  std::vector<MBEntityHandle>::const_iterator i_iter = input.begin();
-  const std::vector<MBEntityHandle>::const_iterator i_end = input.end();
+  std::vector<EntityHandle>::const_iterator i_iter = input.begin();
+  const std::vector<EntityHandle>::const_iterator i_end = input.end();
   output.resize(input.size());
   VALGRIND_MAKE_VEC_UNDEFINED( output );
   std::vector<id_t>::iterator o_iter = output.begin();
@@ -1395,12 +1396,12 @@
 
 
 
-inline MBErrorCode WriteHDF5::get_adjacencies( MBEntityHandle entity,
+inline ErrorCode WriteHDF5::get_adjacencies( EntityHandle entity,
                                         std::vector<id_t>& adj )
 {
-  const MBEntityHandle* adj_array;
+  const EntityHandle* adj_array;
   int num_adj;
-  MBErrorCode rval = writeUtil->get_adjacencies( entity, adj_array, num_adj );
+  ErrorCode rval = writeUtil->get_adjacencies( entity, adj_array, num_adj );
   if (MB_SUCCESS != rval)
     return rval;
   
@@ -1414,12 +1415,12 @@
 }
 
 
-MBErrorCode WriteHDF5::write_adjacencies( const ExportSet& elements )
+ErrorCode WriteHDF5::write_adjacencies( const ExportSet& elements )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  MBRange::const_iterator iter;
-  const MBRange::const_iterator end = elements.range.end();
+  Range::const_iterator iter;
+  const Range::const_iterator end = elements.range.end();
   std::vector<id_t> adj_list;
   
   /* Count Adjacencies */
@@ -1507,11 +1508,11 @@
 
 /*
 
-MBErrorCode WriteHDF5::write_tag( MBTag tag_handle )
+ErrorCode WriteHDF5::write_tag( Tag tag_handle )
 {
-  MBErrorCode rval;
-  MBTagType tag_type;
-  MBTag type_handle;
+  ErrorCode rval;
+  TagType tag_type;
+  Tag type_handle;
   int tag_size, mem_size;
   mhdf_Status status;
   hid_t hdf_tag_type;
@@ -1613,10 +1614,10 @@
 }
 
 
-MBErrorCode WriteHDF5::write_dense_tag( MBTag handle,
+ErrorCode WriteHDF5::write_dense_tag( Tag handle,
                                         hid_t type )
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   
   if (!nodeSet.range.empty())
     rval = write_dense_tag( nodeSet, handle, type );
@@ -1625,7 +1626,7 @@
   std::list<ExportSet>::iterator iter, end = exportList.end();
   for (iter = exportList.begin(); iter != end; ++iter)
   {
-    MBErrorCode rval = write_dense_tag( *iter, handle, type );
+    ErrorCode rval = write_dense_tag( *iter, handle, type );
     CHK_MB_ERR_0(rval);
   }
   
@@ -1634,17 +1635,17 @@
   return rval;
 }
 
-MBErrorCode WriteHDF5::write_dense_tag( ExportSet& set,
-                                        MBTag handle,
+ErrorCode WriteHDF5::write_dense_tag( ExportSet& set,
+                                        Tag handle,
                                         hid_t type )
 {
-  MBRange sub_range;
-  MBErrorCode rval;
+  Range sub_range;
+  ErrorCode rval;
   mhdf_Status status;
   hid_t data_handle;
   std::string name;
   int tag_size;
-  MBTagType mb_type;
+  TagType mb_type;
   
     //get tag properties
   if (MB_SUCCESS != iFace->tag_get_name( handle, name )    ||
@@ -1662,12 +1663,12 @@
   long chunk_size = bufferSize / tag_size;
   long offset = 0;
   
-  MBRange::const_iterator iter = set.range.begin();
+  Range::const_iterator iter = set.range.begin();
   long remaining = set.range.size();
   while (remaining)
   {
     long count = remaining > chunk_size ? chunk_size : remaining;
-    MBRange::const_iterator next = iter;
+    Range::const_iterator next = iter;
     next += count;
     sub_range.clear();
     sub_range.merge( iter, next );
@@ -1696,10 +1697,10 @@
 
 */
 
-MBErrorCode WriteHDF5::write_sparse_ids( const SparseTag& tag_data,
+ErrorCode WriteHDF5::write_sparse_ids( const SparseTag& tag_data,
                                          hid_t id_table )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
 
 
@@ -1708,7 +1709,7 @@
   id_t* id_buffer = (id_t*)dataBuffer;
   
     // Write IDs of tagged entities.
-  MBRange range;
+  Range range;
   long remaining = tag_data.range.size();
   long offset = tag_data.offset;
   long num_writes = (remaining + chunk_size - 1)/chunk_size;
@@ -1716,7 +1717,7 @@
     assert(tag_data.max_num_ents >= remaining);
     num_writes = (tag_data.max_num_ents + chunk_size - 1)/chunk_size;
   }
-  MBRange::const_iterator iter = tag_data.range.begin();
+  Range::const_iterator iter = tag_data.range.begin();
   while (remaining)
   {
     VALGRIND_MAKE_MEM_UNDEFINED( dataBuffer, bufferSize );
@@ -1724,7 +1725,7 @@
       // write "chunk_size" blocks of data
     long count = (unsigned long)remaining > chunk_size ? chunk_size : remaining;
     remaining -= count;
-    MBRange::const_iterator stop = iter;
+    Range::const_iterator stop = iter;
     stop += count;
     range.clear();
     range.merge( iter, stop );
@@ -1756,15 +1757,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::write_sparse_tag( const SparseTag& tag_data )
+ErrorCode WriteHDF5::write_sparse_tag( const SparseTag& tag_data )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   hid_t tables[3];
   std::string name;
   int mb_size;
-  MBTagType mb_type;
-  MBDataType mb_data_type;
+  TagType mb_type;
+  DataType mb_data_type;
   long table_size, data_size;
   hid_t value_type = 0;
   
@@ -1805,7 +1806,7 @@
   char* tag_buffer = (char*)dataBuffer;
 
   if (mb_data_type == MB_TYPE_HANDLE) {
-    hsize_t len = mb_size / sizeof(MBEntityHandle);
+    hsize_t len = mb_size / sizeof(EntityHandle);
     if (len == 1)
       value_type = id_type;
     else {
@@ -1824,7 +1825,7 @@
     // Write the tag values
   size_t remaining = tag_data.range.size();
   size_t offset = tag_data.offset;
-  MBRange::const_iterator iter = tag_data.range.begin();
+  Range::const_iterator iter = tag_data.range.begin();
   long num_writes = (remaining + chunk_size - 1)/chunk_size;
   if (tag_data.max_num_ents) {
     assert( tag_data.max_num_ents >= (long)remaining );
@@ -1838,9 +1839,9 @@
     long count = (unsigned long)remaining > chunk_size ? chunk_size : remaining;
     remaining -= count;
     memset( tag_buffer, 0, count * mb_size );
-    MBRange::const_iterator stop = iter;
+    Range::const_iterator stop = iter;
     stop += count;
-    MBRange range;
+    Range range;
     range.merge( iter, stop );
     iter = stop;
     assert(range.size() == (unsigned)count);
@@ -1853,10 +1854,10 @@
       return rval;
     }
     
-      // Convert MBEntityHandles to file ids
+      // Convert EntityHandles to file ids
     if (mb_data_type == MB_TYPE_HANDLE)
-      convert_handle_tag( reinterpret_cast<MBEntityHandle*>(tag_buffer), 
-                          count * mb_size / sizeof(MBEntityHandle) );
+      convert_handle_tag( reinterpret_cast<EntityHandle*>(tag_buffer), 
+                          count * mb_size / sizeof(EntityHandle) );
     
       // write the data
     tprint("  writing sparse tag value chunk.");
@@ -1887,9 +1888,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::write_var_len_tag( const SparseTag& tag_data )
+ErrorCode WriteHDF5::write_var_len_tag( const SparseTag& tag_data )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   hid_t tables[3];
   std::string name;
@@ -1902,7 +1903,7 @@
     
     // get type and size information
   int mb_size, type_size, file_size;
-  MBDataType mb_data_type;
+  DataType mb_data_type;
   mhdf_TagDataType file_type;
   hid_t hdf_type;
   if (MB_SUCCESS != get_tag_size( tag_data.tag_id, 
@@ -1965,7 +1966,7 @@
     // iterate in blocks of num_entities entities
   size_t bytes = 0; // occupied size of data buffer
   size_t remaining = tag_data.range.size();
-  MBRange::const_iterator i = tag_data.range.begin();
+  Range::const_iterator i = tag_data.range.begin();
   while (remaining) {
     VALGRIND_MAKE_MEM_UNDEFINED( pointer_buffer, num_entities*sizeof(pointer_buffer[0]) );
     VALGRIND_MAKE_MEM_UNDEFINED( offset_buffer,  num_entities*sizeof(offset_buffer[0]) );
@@ -1975,8 +1976,8 @@
     remaining -= count;
     
       // get subset of entity handles
-    MBRange::const_iterator e = i; e += count;
-    MBRange subrange; subrange.merge( i, e );
+    Range::const_iterator e = i; e += count;
+    Range subrange; subrange.merge( i, e );
     i = e;
   
       // get pointers and sizes for entities from MOAB
@@ -2012,9 +2013,9 @@
         // special case: if tag data is larger than buffer write it w/out buffering
       if (size > data_buffer_size) {
         if (mb_data_type == MB_TYPE_HANDLE) {
-          std::vector<MBEntityHandle> tmp_storage(size/sizeof(MBEntityHandle));
+          std::vector<EntityHandle> tmp_storage(size/sizeof(EntityHandle));
           VALGRIND_MAKE_VEC_UNDEFINED( tmp_storage );
-          convert_handle_tag( reinterpret_cast<const MBEntityHandle*>(ptr),
+          convert_handle_tag( reinterpret_cast<const EntityHandle*>(ptr),
                               &tmp_storage[0], tmp_storage.size() );
           ptr = &tmp_storage[0];
         }
@@ -2028,9 +2029,9 @@
         // otherwise copy data into buffer to be written during a later ieration
       else {
         if (mb_data_type == MB_TYPE_HANDLE) 
-          convert_handle_tag( reinterpret_cast<const MBEntityHandle*>(ptr),
-                              reinterpret_cast<MBEntityHandle*>(data_buffer + bytes), 
-                              size/sizeof(MBEntityHandle) );
+          convert_handle_tag( reinterpret_cast<const EntityHandle*>(ptr),
+                              reinterpret_cast<EntityHandle*>(data_buffer + bytes), 
+                              size/sizeof(EntityHandle) );
         else
           memcpy( data_buffer + bytes, pointer_buffer[j], size );
         bytes += size;
@@ -2066,7 +2067,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::write_qa( const std::vector<std::string>& list )
+ErrorCode WriteHDF5::write_qa( const std::vector<std::string>& list )
 {
   const char* app = "MOAB";
   const char* vers = MB_VERSION;
@@ -2101,12 +2102,12 @@
 }
 
 /*
-MBErrorCode WriteHDF5::register_known_tag_types( MBInterface* iface )
+ErrorCode WriteHDF5::register_known_tag_types( Interface* iface )
 {
   hid_t int4, double16;
   hsize_t dim[1];
   int error = 0;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   dim[0] = 4;
   int4 = H5Tarray_create( H5T_NATIVE_INT, 1, dim, NULL );
@@ -2132,7 +2133,7 @@
     if (list[i].type < 1)
       { ++error; continue; }
     
-    MBTag handle;
+    Tag handle;
     
     std::string name("__hdf5_tag_type_");
     name += list[i].name;
@@ -2157,13 +2158,13 @@
 }
 */
 
-MBErrorCode WriteHDF5::gather_tags( const MBTag* user_tag_list, int num_tags )
+ErrorCode WriteHDF5::gather_tags( const Tag* user_tag_list, int num_tags )
 {
-  MBErrorCode result;
+  ErrorCode result;
   std::string tagname;
-  std::vector<MBTag> tag_list;
-  std::vector<MBTag>::iterator t_itor;
-  MBRange range;
+  std::vector<Tag> tag_list;
+  std::vector<Tag>::iterator t_itor;
+  Range range;
     
     // Get list of Tags to write
   result = writeUtil->get_tag_list( tag_list, user_tag_list, num_tags );
@@ -2186,7 +2187,7 @@
   const std::list<SparseTag>::iterator td_end = tagList.end();
   for ( ; td_iter != td_end; ++td_iter)
   {  
-    MBTag handle = td_iter->tag_id;
+    Tag handle = td_iter->tag_id;
       // Get list of entities for which tag is set
     std::list<ExportSet>::iterator e_iter, e_end = exportList.end();
     for (e_iter = exportList.begin(); e_iter != e_end; ++e_iter)
@@ -2218,18 +2219,18 @@
       // If the tag contains multiple handle values, write it if any one
       // of those handles is valid.  Consider special case of 0 handle as
       // valid.
-    MBDataType data_type;
+    DataType data_type;
     iFace->tag_get_data_type( handle, data_type );
     if (MB_TYPE_HANDLE == data_type)
     {
       int tag_size;
       result = iFace->tag_get_size( handle, tag_size );
       CHK_MB_ERR_0(result);
-      if (tag_size % sizeof(MBEntityHandle)) // not an even multiple?
+      if (tag_size % sizeof(EntityHandle)) // not an even multiple?
         td_iter->range.clear(); // don't write any values
       
-      std::vector<MBEntityHandle> values(tag_size / sizeof(MBEntityHandle));
-      MBRange::iterator i = td_iter->range.begin();
+      std::vector<EntityHandle> values(tag_size / sizeof(EntityHandle));
+      Range::iterator i = td_iter->range.begin();
       while (i != td_iter->range.end())
       {
         result = iFace->tag_get_data( handle, &*i, 1, &values[0] );
@@ -2252,10 +2253,10 @@
   // overridden with an alternate version in WriteHDF5Parallel
   // that supports parallel I/O.  If we're here 
   // then MOAB was not built with support for parallel HDF5 I/O.
-MBErrorCode WriteHDF5::parallel_create_file( const char* ,
+ErrorCode WriteHDF5::parallel_create_file( const char* ,
                                     bool ,
                                     const std::vector<std::string>& ,
-                                    const MBTag*,
+                                    const Tag*,
                                     int ,
                                     int,
                                     int  )
@@ -2263,10 +2264,10 @@
   return MB_NOT_IMPLEMENTED;
 }
 
-MBErrorCode WriteHDF5::serial_create_file( const char* filename,
+ErrorCode WriteHDF5::serial_create_file( const char* filename,
                                     bool overwrite,
                                     const std::vector<std::string>& qa_records,
-                                    const MBTag* user_tag_list,
+                                    const Tag* user_tag_list,
                                     int num_user_tags,
                                     int dimension )
 {
@@ -2274,11 +2275,11 @@
   mhdf_Status status;
   hid_t handle;
   std::list<ExportSet>::iterator ex_itor;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   const char* type_names[MBMAXTYPE];
   memset( type_names, 0, MBMAXTYPE * sizeof(char*) );
-  for (MBEntityType i = MBEDGE; i < MBENTITYSET; ++i)
+  for (EntityType i = MBEDGE; i < MBENTITYSET; ++i)
     type_names[i] = MBCN::EntityTypeName( i );
  
     // Create the file
@@ -2413,12 +2414,12 @@
 }
 
 
-MBErrorCode WriteHDF5::count_adjacencies( const MBRange& set, id_t& result )
+ErrorCode WriteHDF5::count_adjacencies( const Range& set, id_t& result )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   std::vector<id_t> adj_list;
-  MBRange::const_iterator iter = set.begin();
-  const MBRange::const_iterator end = set.end();
+  Range::const_iterator iter = set.begin();
+  const Range::const_iterator end = set.end();
   result = 0;
   for ( ; iter != end; ++iter )
   {
@@ -2432,7 +2433,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::create_elem_tables( MBEntityType mb_type,
+ErrorCode WriteHDF5::create_elem_tables( EntityType mb_type,
                                            int nodes_per_elem,
                                            id_t num_elements,
                                            long& first_id_out )
@@ -2459,15 +2460,15 @@
 }
 
 
-MBErrorCode WriteHDF5::count_set_size( const MBRange& sets, 
+ErrorCode WriteHDF5::count_set_size( const Range& sets, 
                                        long& contents_length_out,
                                        long& children_length_out,
                                        long& parents_length_out )
 {
-  MBErrorCode rval;
-  MBRange set_contents;
-  MBRange::const_iterator iter = sets.begin();
-  const MBRange::const_iterator end = sets.end();
+  ErrorCode rval;
+  Range set_contents;
+  Range::const_iterator iter = sets.begin();
+  const Range::const_iterator end = sets.end();
   long contents_length_set, children_length_set, parents_length_set;
   unsigned long flags;
   std::vector<id_t> set_contents_ids;
@@ -2508,7 +2509,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::create_set_meta( id_t num_sets, long& first_id_out )
+ErrorCode WriteHDF5::create_set_meta( id_t num_sets, long& first_id_out )
 {
   hid_t handle;
   mhdf_Status status;
@@ -2521,7 +2522,7 @@
 }
 
 
-MBErrorCode WriteHDF5::create_set_tables( long num_set_contents,
+ErrorCode WriteHDF5::create_set_tables( long num_set_contents,
                                           long num_set_children,
                                           long num_set_parents )
 {
@@ -2552,16 +2553,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::get_tag_size( MBTag tag,
-                                     MBDataType& moab_type,
+ErrorCode WriteHDF5::get_tag_size( Tag tag,
+                                     DataType& moab_type,
                                      int& num_bytes,
                                      int& elem_size,
                                      int& file_size,
                                      mhdf_TagDataType& file_type,
                                      hid_t& hdf_type )
 {
-  MBErrorCode rval;
-  MBTag type_handle;
+  ErrorCode rval;
+  Tag type_handle;
   std::string tag_name, tag_type_name;
    
     // We return NULL for hdf_type if it can be determined from
@@ -2591,7 +2592,7 @@
     file_type = mhdf_BITFIELD;
     break;
   case MB_TYPE_HANDLE:
-    elem_size = sizeof(MBEntityHandle);
+    elem_size = sizeof(EntityHandle);
     file_type = mhdf_ENTITY_ID;
     break;
   case MB_TYPE_OPAQUE:
@@ -2636,9 +2637,9 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5::get_tag_data_length( const SparseTag& tag_info, unsigned long& result )
+ErrorCode WriteHDF5::get_tag_data_length( const SparseTag& tag_info, unsigned long& result )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   result = 0;
   
     // split buffer into two pieces, one for pointers and one for sizes
@@ -2646,11 +2647,11 @@
   step = bufferSize / (sizeof(int) + sizeof(void*));
   const void** ptr_buffer = reinterpret_cast<const void**>(dataBuffer);
   int* size_buffer = reinterpret_cast<int*>(ptr_buffer + step); 
-  MBRange subrange;
-  MBRange::const_iterator iter = tag_info.range.begin();
+  Range subrange;
+  Range::const_iterator iter = tag_info.range.begin();
   for (remaining = tag_info.range.size(); remaining >= step; remaining -= step) {
       // get subset of range containing 'count' entities
-    MBRange::const_iterator end = iter; end += step;
+    Range::const_iterator end = iter; end += step;
     subrange.clear();
     subrange.merge( iter, end );
     iter = end;
@@ -2672,14 +2673,14 @@
   for (size_t i= 0; i < remaining; ++i)
     result += size_buffer[i];
     
-  MBDataType type;
+  DataType type;
   rval = iFace->tag_get_data_type( tag_info.tag_id, type );
   if (MB_SUCCESS != rval)
     return rval;
   switch (type) {
     case MB_TYPE_INTEGER: result /= sizeof(int);            break;
     case MB_TYPE_DOUBLE:  result /= sizeof(double);         break;
-    case MB_TYPE_HANDLE:  result /= sizeof(MBEntityHandle); break;
+    case MB_TYPE_HANDLE:  result /= sizeof(EntityHandle); break;
     case MB_TYPE_OPAQUE:                                    break;
       // We fail for MB_TYPE_BIT because MOAB currently does
       // not support variable-length bit tags.
@@ -2691,18 +2692,18 @@
     
                                      
 
-MBErrorCode WriteHDF5::create_tag( MBTag tag_id,
+ErrorCode WriteHDF5::create_tag( Tag tag_id,
                                    unsigned long num_sparse_entities,
                                    unsigned long data_table_size )
 {
-  MBTagType mb_storage;
-  MBDataType mb_type;
+  TagType mb_storage;
+  DataType mb_type;
   mhdf_TagDataType mhdf_type;
   int tag_size, elem_size, mhdf_size, storage;
   hid_t hdf_type = (hid_t)0;
   hid_t handles[3];
   std::string tag_name;
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   
 
@@ -2747,8 +2748,8 @@
       // convert default value
     if (def_value) {
       memcpy( dataBuffer, def_value, def_val_len );
-      if (convert_handle_tag( reinterpret_cast<MBEntityHandle*>(dataBuffer), 
-                              def_val_len / sizeof(MBEntityHandle) ))
+      if (convert_handle_tag( reinterpret_cast<EntityHandle*>(dataBuffer), 
+                              def_val_len / sizeof(EntityHandle) ))
         def_value = dataBuffer;
       else
         def_value = 0;
@@ -2756,9 +2757,9 @@
     
       // convert mesh value
     if (mesh_value) {
-      MBEntityHandle* ptr = reinterpret_cast<MBEntityHandle*>(dataBuffer + def_val_len);
+      EntityHandle* ptr = reinterpret_cast<EntityHandle*>(dataBuffer + def_val_len);
       memcpy( ptr, mesh_value, mesh_val_len );
-      if (convert_handle_tag( ptr, mesh_val_len / sizeof(MBEntityHandle) ))
+      if (convert_handle_tag( ptr, mesh_val_len / sizeof(EntityHandle) ))
         mesh_value = ptr;
       else
         mesh_value = 0;
@@ -2830,10 +2831,10 @@
 
 void WriteHDF5::print_id_map( std::ostream& s, const char* pfx ) const
 {
-  RangeMap<MBEntityHandle,id_t>::const_iterator i;
+  RangeMap<EntityHandle,id_t>::const_iterator i;
   for (i = idMap.begin(); i != idMap.end(); ++i) {
     const char* n1 = MBCN::EntityTypeName(TYPE_FROM_HANDLE(i->begin));
-    MBEntityID id = ID_FROM_HANDLE(i->begin);
+    EntityID id = ID_FROM_HANDLE(i->begin);
     if (i->count == 1) {
       s << pfx << n1 << " " << id << " -> " << i->value << std::endl;
     }
@@ -2852,5 +2853,5 @@
   }
 }
 
-      
- 
+} // namespace moab
+

Modified: MOAB/trunk/src/io/WriteHDF5.hpp
===================================================================
--- MOAB/trunk/src/io/WriteHDF5.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteHDF5.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,36 +25,38 @@
 
 #include <list>
 #ifdef USE_MPI // include this before HDF5 headers to avoid conflicts
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 #include "mhdf.h"
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "MBWriterIface.hpp"
-#include "RangeMap.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/WriterIface.hpp"
+#include "moab/RangeMap.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
+class WriteUtilIface;
+
 /* If this define is not set, node->entity adjacencies will not be written */
 #undef MB_H5M_WRITE_NODE_ADJACENCIES
 
-class MB_DLL_EXPORT WriteHDF5 : public MBWriterIface
+class MB_DLL_EXPORT WriteHDF5 : public WriterIface
 {
 public:
 
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
   /** The type to use for entity IDs w/in the file.
    * 
    * NOTE:  If this is changed, the value of id_type 
    *        MUST be changed accordingly.
    */
-  typedef MBEntityHandle id_t;
+  typedef EntityHandle id_t;
   
   /** HDF5 type corresponding to type of id_t */
   static const hid_t id_type;
 
-  WriteHDF5( MBInterface* iface );
+  WriteHDF5( Interface* iface );
   
   virtual ~WriteHDF5();
   
@@ -63,52 +65,52 @@
    * \param export_sets  Array of handles to sets to export, or NULL to export all.
    * \param export_set_count Length of <code>export_sets</code> array.
    */
-  MBErrorCode write_file( const char* filename,
+  ErrorCode write_file( const char* filename,
                           const bool overwrite,
                           const FileOptions& opts,
-                          const MBEntityHandle* export_sets,
+                          const EntityHandle* export_sets,
                           const int export_set_count,
                           const std::vector<std::string>& qa_records,
-                          const MBTag* tag_list = 0,
+                          const Tag* tag_list = 0,
                           int num_tags = 0,
                           int user_dimension = 3 );
 
   /** Create attributes holding the HDF5 type handle for the 
    *  type of a bunch of the default tags.
    */
-  //static MBErrorCode register_known_tag_types( MBInterface* );
+  //static ErrorCode register_known_tag_types( Interface* );
 
 protected:
   
-  MBErrorCode serial_create_file( const char* filename,
+  ErrorCode serial_create_file( const char* filename,
                                   bool overwrite,
                                   const std::vector<std::string>& qa_records,
-                                  const MBTag* tag_list,
+                                  const Tag* tag_list,
                                   int num_tags,
                                   int dimension = 3 );
 
   /** Function to create the file.  Virtual to allow override
    *  for parallel version.
    */
-  virtual MBErrorCode parallel_create_file( const char* filename,
+  virtual ErrorCode parallel_create_file( const char* filename,
                                             bool overwrite,
                                             const std::vector<std::string>& qa_records,
-                                            const MBTag* tag_list,
+                                            const Tag* tag_list,
                                             int num_tags,
                                             int dimension = 3,
                                             int pcomm_no = 0 );
 
 
   /** Functions that the parallel version overrides*/
-  virtual MBErrorCode write_shared_set_descriptions( hid_t ) 
+  virtual ErrorCode write_shared_set_descriptions( hid_t ) 
     { return MB_SUCCESS;}
-  virtual MBErrorCode write_shared_set_contents( hid_t )
+  virtual ErrorCode write_shared_set_contents( hid_t )
     { return MB_SUCCESS;}
-  virtual MBErrorCode write_shared_set_children( hid_t )
+  virtual ErrorCode write_shared_set_children( hid_t )
     { return MB_SUCCESS;}
-  virtual MBErrorCode write_shared_set_parents( hid_t )
+  virtual ErrorCode write_shared_set_parents( hid_t )
     { return MB_SUCCESS;}
-  virtual MBErrorCode write_finished();
+  virtual ErrorCode write_finished();
   virtual void tprint( const char* fmt, ... )
 #ifdef __GNUC__
 __attribute__((format(printf,2,3)))
@@ -117,21 +119,21 @@
 
  
   //! Gather tags
-  MBErrorCode gather_tags( const MBTag* user_tag_list, int user_tag_list_length );
+  ErrorCode gather_tags( const Tag* user_tag_list, int user_tag_list_length );
 
   /** Helper function for create-file
    *
    * Calculate the sum of the number of non-set adjacencies
    * of all entities in the passed range.
    */
-  MBErrorCode count_adjacencies( const MBRange& elements, id_t& result );
+  ErrorCode count_adjacencies( const Range& elements, id_t& result );
   
   /** Helper function for create-file
    *
    * Create zero-ed tables where element connectivity and 
    * adjacency data will be stored.
    */
-  MBErrorCode create_elem_tables( MBEntityType mb_type,
+  ErrorCode create_elem_tables( EntityType mb_type,
                                   int nodes_per_element,
                                   id_t number_elements,
                                   long& first_id_out );
@@ -140,7 +142,7 @@
    *
    * Calculate total length of set contents and child tables.
    */
-  MBErrorCode count_set_size( const MBRange& sets,
+  ErrorCode count_set_size( const Range& sets,
                               long& contents_length_out,
                               long& children_length_out,
                               long& parents_length_out );
@@ -149,27 +151,27 @@
    *
    * Create zero-ed table where set descriptions will be written
    */
-  MBErrorCode create_set_meta( id_t number_sets, long& first_id_out );
+  ErrorCode create_set_meta( id_t number_sets, long& first_id_out );
 
   /** Helper function for create-file
    *
    * Create zero-ed tables where set data will be written.
    */
-  MBErrorCode create_set_tables( long contents_length, 
+  ErrorCode create_set_tables( long contents_length, 
                                  long children_length,
                                  long parents_length );
 
   //! Write exodus-type QA info
-  MBErrorCode write_qa( const std::vector<std::string>& list );
+  ErrorCode write_qa( const std::vector<std::string>& list );
 
 
   //! Range of entities, grouped by type, to export 
   struct ExportSet 
   {
     //! The range of entities.
-    MBRange range;
+    Range range;
     //! The type of the entities in the range
-    MBEntityType type;
+    EntityType type;
     //! The number of nodes per entity - not used for nodes and sets
     int num_nodes;
     //! The first Id allocated by the mhdf library.  Entities in range have sequential IDs.
@@ -178,7 +180,7 @@
     //! Always zero except for parallel IO.
     id_t offset;
     //! Offset for adjacency data.  Always zero except for parallel IO
-    MBEntityID adj_offset;
+    EntityID adj_offset;
     //! If doing parallel IO, largest number of entities to write
     //! for any processor (needed to do collective IO).  Zero if unused.
     long max_num_ents, max_num_adjs;
@@ -198,9 +200,9 @@
   struct SparseTag
   {
     //! The tag handle
-    MBTag tag_id;
+    Tag tag_id;
     //! The list of entities with this tag
-    MBRange range;
+    Range range;
     //! The offset at which to begin writting this processor's data.
     //! Always zero except for parallel IO. 
     id_t offset;
@@ -224,16 +226,16 @@
   //! A memory buffer to use for all I/O operations.
   char* dataBuffer;
 
-  //! MBInterface pointer passed to constructor
-  MBInterface* iFace;
+  //! Interface pointer passed to constructor
+  Interface* iFace;
   //! Cached pointer to writeUtil interface.
-  MBWriteUtilIface* writeUtil;
+  WriteUtilIface* writeUtil;
   
   //! The file handle from the mhdf library
   mhdf_FileHandle filePtr;
   
   //! Map from entity handles to file IDs
-  RangeMap<MBEntityHandle,id_t> idMap;
+  RangeMap<EntityHandle,id_t> idMap;
   
   //! The list elements to export.
   std::list<ExportSet> exportList;
@@ -277,20 +279,20 @@
 
   //! Do the actual work of write_file.  Separated from write_file
   //! for easier resource cleanup.
-  MBErrorCode write_file_impl( const char* filename,
+  ErrorCode write_file_impl( const char* filename,
                                const bool overwrite,
                                const FileOptions& opts,
-                               const MBEntityHandle* export_sets,
+                               const EntityHandle* export_sets,
                                const int export_set_count,
                                const std::vector<std::string>& qa_records,
-                               const MBTag* tag_list,
+                               const Tag* tag_list,
                                int num_tags,
                                int user_dimension = 3 );
 
-  MBErrorCode init();
+  ErrorCode init();
 
   //! Get information about a meshset
-  MBErrorCode get_set_info( MBEntityHandle set,
+  ErrorCode get_set_info( EntityHandle set,
                             long& num_entities,
                             long& num_children,
                             long& num_parents,
@@ -306,12 +308,12 @@
    *\param var_len_total For variable-length tags, the total number of values
    *                     in the data table.
    */
-  MBErrorCode create_tag( MBTag tag_id, 
+  ErrorCode create_tag( Tag tag_id, 
                           unsigned long num_entities,
                           unsigned long var_len_total );
   
   /**\brief add entities to idMap */
-  MBErrorCode assign_ids( const MBRange& entities, id_t first_id );
+  ErrorCode assign_ids( const Range& entities, id_t first_id );
   
   /** Get possibly compacted list of IDs for passed entities
    *
@@ -327,34 +329,34 @@
    * If the ID list is compacted, ranged_list will be 'true'.
    * Otherwise it will be 'false'.
    */
-  MBErrorCode range_to_blocked_list( const MBRange& input_range,
+  ErrorCode range_to_blocked_list( const Range& input_range,
                                      std::vector<id_t>& output_id_list , 
                                      bool& ranged_list );
   
 
-  MBErrorCode range_to_id_list( const MBRange& input_range,
+  ErrorCode range_to_id_list( const Range& input_range,
                                 id_t* array );
   //! Get IDs for entities 
-  MBErrorCode vector_to_id_list( const std::vector<MBEntityHandle>& input,
+  ErrorCode vector_to_id_list( const std::vector<EntityHandle>& input,
                                  std::vector<id_t>& output, 
                                  bool remove_non_written = false );
 
-  /** When writing tags containing MBEntityHandles to file, need to convert tag
-   *  data from MBEntityHandles to file IDs.  This function does that. 
+  /** When writing tags containing EntityHandles to file, need to convert tag
+   *  data from EntityHandles to file IDs.  This function does that. 
    *
    * If the handle is not valid or does not correspond to an entity that will
    * be written to the file, the file ID is set to zero.
-   *\param data  The data buffer.  As input, an array of MBEntityHandles.  As
+   *\param data  The data buffer.  As input, an array of EntityHandles.  As
    *             output an array of file IDS, where the size of each integral
-   *             file ID is the same as the size of MBEntityHandle.
+   *             file ID is the same as the size of EntityHandle.
    *\param count The number of handles in the buffer.
    *\return true if at least one of the handles is valid and will be written to
    *             the file or at least one of the handles is NULL (zero). false
    *             otherwise
    */
-  bool convert_handle_tag( MBEntityHandle* data, size_t count ) const;
-  bool convert_handle_tag( const MBEntityHandle* source,
-                           MBEntityHandle* dest, 
+  bool convert_handle_tag( EntityHandle* data, size_t count ) const;
+  bool convert_handle_tag( const EntityHandle* source,
+                           EntityHandle* dest, 
                            size_t count ) const;
 
   /** Get IDs of adjacent entities.
@@ -363,11 +365,11 @@
    * adjacent entity is to be exported (ID is not zero), append
    * the ID to the passed list.
    */
-  MBErrorCode get_adjacencies( MBEntityHandle entity, std::vector<id_t>& adj );
+  ErrorCode get_adjacencies( EntityHandle entity, std::vector<id_t>& adj );
                                 
   //! get sum of lengths of tag values (as number of type) for 
   //! variable length tag data.
-  MBErrorCode get_tag_data_length( const SparseTag& tag_info,
+  ErrorCode get_tag_data_length( const SparseTag& tag_info,
                                    unsigned long& result );
   
 private:
@@ -379,19 +381,19 @@
    *
    * \param export_sets  The list of meshsets to export
    */
-  MBErrorCode gather_mesh_info( const std::vector<MBEntityHandle>& export_sets );
+  ErrorCode gather_mesh_info( const std::vector<EntityHandle>& export_sets );
   
   //! Same as gather_mesh_info, except for entire mesh
-  MBErrorCode gather_all_mesh( );
+  ErrorCode gather_all_mesh( );
   
   //! Initialize internal data structures from gathered mesh
-  MBErrorCode initialize_mesh( const MBRange entities_by_dim[5] );
+  ErrorCode initialize_mesh( const Range entities_by_dim[5] );
  
   /** Write out the nodes.
    *
    * Note: Assigns IDs to nodes.
    */
-  MBErrorCode write_nodes( );
+  ErrorCode write_nodes( );
   
   /** Write out element connectivity.
    *
@@ -400,7 +402,7 @@
    * Note: Assigns element IDs.
    * Note: Must do write_nodes first so node IDs get assigned.
    */
-  MBErrorCode write_elems( ExportSet& elemset );
+  ErrorCode write_elems( ExportSet& elemset );
   
   /** Write out meshsets
    * 
@@ -409,16 +411,16 @@
    * Note: Must have written nodes and element connectivity
    *       so entities have assigned IDs.
    */
-  MBErrorCode write_sets( );
+  ErrorCode write_sets( );
 
-  MBErrorCode write_parents_children( bool children );
+  ErrorCode write_parents_children( bool children );
   
   /** Write adjacency info for passed set of elements
    *
    * Note: Must have written element connectivity so elements
    *       have IDs assigned.
    */
-  MBErrorCode write_adjacencies( const ExportSet& export_set );
+  ErrorCode write_adjacencies( const ExportSet& export_set );
   
   /** Write tag information and data.
    * 
@@ -426,29 +428,29 @@
    *       sets so that entities have IDs assigned.
    */
 /*
-  MBErrorCode write_tag( MBTag tag_handle );
+  ErrorCode write_tag( Tag tag_handle );
   
   //! Write dense tag for all entities 
-  MBErrorCode write_dense_tag( MBTag tag_handle,
+  ErrorCode write_dense_tag( Tag tag_handle,
                                hid_t hdf_write_type );
 
   //! Write dense tag for specified entity set
-  MBErrorCode write_dense_tag( ExportSet& set,
-                               MBTag tag_handle,
+  ErrorCode write_dense_tag( ExportSet& set,
+                               Tag tag_handle,
                                hid_t hdf_write_type );
 */  
   //! Write sparse tag for all entities.
-  MBErrorCode write_sparse_tag( const SparseTag& tag_data );
+  ErrorCode write_sparse_tag( const SparseTag& tag_data );
                             
   //! Get element connectivity
-  MBErrorCode get_connectivity( MBRange::const_iterator begin,
-                                MBRange::const_iterator end,
+  ErrorCode get_connectivity( Range::const_iterator begin,
+                                Range::const_iterator end,
                                 int nodes_per_element,
                                 id_t* id_data_out );
                                    
   //! Get size data for tag
   //!\param tag       MOAB tag ID
-  //!\param moab_type Output: MBDataType for tag
+  //!\param moab_type Output: DataType for tag
   //!\param num_bytes Output: MOAB tag size (bits for bit tags).
   //!                         MB_VARIABLE_LENGTH for variable-length tags.
   //!\param elem_size Output: Size of type values per entity (e.g.
@@ -459,8 +461,8 @@
   //!\param hdf_type  Output: zero or handle for user-defined custom type
   //!                         (user-defined type available only for opaque
   //!                         data.)
-  MBErrorCode get_tag_size( MBTag tag,
-                            MBDataType& moab_type,
+  ErrorCode get_tag_size( Tag tag,
+                            DataType& moab_type,
                             int& num_bytes,
                             int& elem_size,
                             int& file_size,
@@ -468,10 +470,12 @@
                             hid_t& hdf_type );
                             
   //! Write ID table for sparse tag
-  MBErrorCode write_sparse_ids( const SparseTag& tag_data, hid_t table_handle );
+  ErrorCode write_sparse_ids( const SparseTag& tag_data, hid_t table_handle );
   
   //! Write varialbe-length tag data
-  MBErrorCode write_var_len_tag( const SparseTag& tag_info );
+  ErrorCode write_var_len_tag( const SparseTag& tag_info );
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteNCDF.cpp
===================================================================
--- MOAB/trunk/src/io/WriteNCDF.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteNCDF.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,36 +37,38 @@
 #include <string.h>
 #include <assert.h>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "Internals.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/WriteUtilIface.hpp"
 #include "exodus_order.h"
 
+namespace moab {
+
 const int TIME_STR_LEN = 11;
 
 #define INS_ID(stringvar, prefix, id) \
           sprintf(stringvar, prefix, id)
 
-MBWriterIface* WriteNCDF::factory( MBInterface* iface )
+WriterIface* WriteNCDF::factory( Interface* iface )
   { return new WriteNCDF( iface ); }
 
-WriteNCDF::WriteNCDF(MBInterface *impl) 
+WriteNCDF::WriteNCDF(Interface *impl) 
     : mdbImpl(impl), ncFile(0), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, 
                               MB_TYPE_INTEGER, mMaterialSetTag, &dum_val);
@@ -114,7 +116,7 @@
 
 WriteNCDF::~WriteNCDF() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mdbImpl->release_interface(iface_name, mWriteIface);
 
   mdbImpl->tag_delete(mEntityMark);
@@ -151,13 +153,13 @@
    date_string[10] = (char)NULL;
 }
 
-MBErrorCode WriteNCDF::write_file(const char *exodus_file_name, 
+ErrorCode WriteNCDF::write_file(const char *exodus_file_name, 
                                     const bool overwrite,
                                     const FileOptions&,
-                                    const MBEntityHandle *ent_handles,
+                                    const EntityHandle *ent_handles,
                                     const int num_sets,
                                     const std::vector<std::string> &qa_records,
-                                    const MBTag*,
+                                    const Tag*,
                                     int,
                                     int user_dimension)
 {
@@ -169,13 +171,13 @@
    mdbImpl->get_dimension( user_dimension );
   
 
-  std::vector<MBEntityHandle> blocks, nodesets, sidesets, entities;
+  std::vector<EntityHandle> blocks, nodesets, sidesets, entities;
 
     // separate into blocks, nodesets, sidesets
 
   if (num_sets == 0) {
       // default to all defined block, nodeset and sideset-type sets
-    MBRange this_range;
+    Range this_range;
     mdbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &mMaterialSetTag, NULL, 1, this_range);
     std::copy(this_range.begin(), this_range.end(), std::back_inserter(blocks));
     this_range.clear();
@@ -194,7 +196,7 @@
       if (this_range.empty())
         return MB_FILE_WRITE_ERROR;
 
-      MBEntityHandle block_handle;
+      EntityHandle block_handle;
       int block_id = 1;
       mdbImpl->create_meshset( MESHSET_SET, block_handle );
       mdbImpl->tag_set_data( mMaterialSetTag, &block_handle, 1, &block_id );
@@ -204,7 +206,7 @@
   }
   else {
     int dummy;
-    for (const MBEntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
+    for (const EntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
     {
       if (MB_SUCCESS == mdbImpl->tag_get_data(mMaterialSetTag, &(*iter), 1, &dummy))
         blocks.push_back(*iter);
@@ -320,17 +322,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::gather_mesh_information(
+ErrorCode WriteNCDF::gather_mesh_information(
                         ExodusMeshInfo &mesh_info,
                         std::vector<MaterialSetData> &block_info,
                         std::vector<NeumannSetData> &sideset_info,
                         std::vector<DirichletSetData> &nodeset_info,
-                        std::vector<MBEntityHandle> &blocks,
-                        std::vector<MBEntityHandle> &sidesets,
-                        std::vector<MBEntityHandle> &nodesets)
+                        std::vector<EntityHandle> &blocks,
+                        std::vector<EntityHandle> &sidesets,
+                        std::vector<EntityHandle> &nodesets)
 {
-  MBErrorCode rval;
-  std::vector<MBEntityHandle>::iterator vector_iter, end_vector_iter;
+  ErrorCode rval;
+  std::vector<EntityHandle>::iterator vector_iter, end_vector_iter;
 
   mesh_info.num_nodes = 0;
   mesh_info.num_elements = 0;
@@ -341,7 +343,7 @@
   vector_iter= blocks.begin();
   end_vector_iter = blocks.end();
 
-  std::vector<MBEntityHandle> parent_meshsets;
+  std::vector<EntityHandle> parent_meshsets;
 
   // clean out the bits for the element mark
   rval = mdbImpl->tag_delete(mEntityMark);
@@ -363,7 +365,7 @@
       return MB_FAILURE;
 
     // get all Entity Handles in the mesh set
-    MBRange dummy_range;
+    Range dummy_range;
     rval = mdbImpl->get_entities_by_handle(*vector_iter, dummy_range, true );
     if (MB_SUCCESS != rval)
       return rval;
@@ -375,7 +377,7 @@
     // wait a minute, we are doing some filtering here that doesn't make sense at this level  CJS
 
       // find the dimension of the last entity in this range
-    MBRange::iterator entity_iter = dummy_range.end();
+    Range::iterator entity_iter = dummy_range.end();
     entity_iter = dummy_range.end();
     entity_iter--;
     int this_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*entity_iter));
@@ -385,7 +387,7 @@
       entity_iter++;
     
     if (entity_iter != dummy_range.end())
-      std::copy(entity_iter, dummy_range.end(), mb_range_inserter(block_data.elements));
+      std::copy(entity_iter, dummy_range.end(), range_inserter(block_data.elements));
 
     assert(block_data.elements.begin() == block_data.elements.end() ||
            MBCN::Dimension(TYPE_FROM_HANDLE(*(block_data.elements.begin()))) == this_dim);
@@ -403,13 +405,13 @@
     block_data.number_attributes = 0;
  
      // iterate through all the elements in the meshset
-    MBRange::iterator elem_range_iter, end_elem_range_iter;
+    Range::iterator elem_range_iter, end_elem_range_iter;
     elem_range_iter = block_data.elements.begin();
     end_elem_range_iter = block_data.elements.end();
 
       // get the entity type for this block, verifying that it's the same for all elements
       // THIS ASSUMES HANDLES SORT BY TYPE!!!
-    MBEntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
+    EntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
     end_elem_range_iter--;
     if (entity_type != TYPE_FROM_HANDLE(*(end_elem_range_iter++))) {
       mWriteIface->report_error("Entities in block %i not of common type", id);
@@ -427,7 +429,7 @@
     if( dimension > highest_dimension_of_element_blocks )
       highest_dimension_of_element_blocks = dimension;
 
-    std::vector<MBEntityHandle> tmp_conn;
+    std::vector<EntityHandle> tmp_conn;
     rval = mdbImpl->get_connectivity(&(*(block_data.elements.begin())), 1, tmp_conn);
     if (MB_SUCCESS != rval)
       return rval;
@@ -454,7 +456,7 @@
     if(!sidesets.empty())
     {
       // if there are sidesets, keep track of which elements are being written out
-      for(MBRange::iterator iter = block_data.elements.begin(); 
+      for(Range::iterator iter = block_data.elements.begin(); 
           iter != block_data.elements.end(); ++iter)
       {
         unsigned char bit = 0x1;
@@ -495,7 +497,7 @@
   }
 
 
-  MBRange::iterator range_iter, end_range_iter;
+  Range::iterator range_iter, end_range_iter;
   range_iter = mesh_info.nodes.begin();
   end_range_iter = mesh_info.nodes.end();
 
@@ -521,7 +523,7 @@
     
     nodeset_data.id = id; 
 
-    std::vector<MBEntityHandle> node_vector;
+    std::vector<EntityHandle> node_vector;
     //get the nodes of the nodeset that are in mesh_info.nodes
     if( mdbImpl->get_entities_by_handle(*vector_iter, node_vector, true) != MB_SUCCESS ) {
       mWriteIface->report_error("Couldn't get nodes in nodeset %i", id);
@@ -541,13 +543,13 @@
       has_dist_factors = 1;
     dist_factor_size /= sizeof(double);
     dist_factor_vector = reinterpret_cast<const double*>(ptr);
-    std::vector<MBEntityHandle>::iterator iter, end_iter;
+    std::vector<EntityHandle>::iterator iter, end_iter;
     iter = node_vector.begin();
     end_iter= node_vector.end();
  
     int j=0; 
     unsigned char node_marked = 0;
-    MBErrorCode result;
+    ErrorCode result;
     for(; iter != end_iter; iter++)
     {
       if (TYPE_FROM_HANDLE(*iter) != MBVERTEX) continue;
@@ -591,11 +593,11 @@
  
     //get the sides in two lists, one forward the other reverse; starts with forward sense
       // by convention
-    MBRange forward_elems, reverse_elems;
+    Range forward_elems, reverse_elems;
     if(get_sideset_elems(*vector_iter, 0, forward_elems, reverse_elems) == MB_FAILURE)
       return MB_FAILURE;
 
-    MBErrorCode result = get_valid_sides(forward_elems, mesh_info, 1, sideset_data);
+    ErrorCode result = get_valid_sides(forward_elems, mesh_info, 1, sideset_data);
     if (MB_SUCCESS != result) {
       mWriteIface->report_error("Couldn't get valid sides data.");
       return result;
@@ -615,7 +617,7 @@
 
 }
 
-MBErrorCode WriteNCDF::get_valid_sides(MBRange &elems, ExodusMeshInfo& /*mesh_info*/, 
+ErrorCode WriteNCDF::get_valid_sides(Range &elems, ExodusMeshInfo& /*mesh_info*/, 
                                          const int sense,
                                          NeumannSetData &sideset_data) 
 {
@@ -640,8 +642,8 @@
   }
 
   unsigned char element_marked = 0;
-  MBErrorCode result;
-  for(MBRange::iterator iter = elems.begin(); iter != elems.end(); iter++)
+  ErrorCode result;
+  for(Range::iterator iter = elems.begin(); iter != elems.end(); iter++)
   {
       // should insert here if "side" is a quad/tri on a quad/tri mesh
     result = mdbImpl->tag_get_data(mEntityMark, &(*iter), 1, &element_marked);
@@ -659,7 +661,7 @@
     }
     else //then "side" is probably a quad/tri on a hex/tet mesh
     {
-      std::vector<MBEntityHandle> parents;
+      std::vector<EntityHandle> parents;
       int dimension = MBCN::Dimension( TYPE_FROM_HANDLE(*iter));
 
         //get the adjacent parent element of "side"
@@ -718,7 +720,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::write_qa_records(std::vector<std::string> &qa_record_list)
+ErrorCode WriteNCDF::write_qa_records(std::vector<std::string> &qa_record_list)
 {
   int i = 0;
   
@@ -735,7 +737,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::write_qa_string(const char *string,
+ErrorCode WriteNCDF::write_qa_string(const char *string,
                                          int record_number,
                                          int record_position)
 {
@@ -773,7 +775,7 @@
 }
 
 
-MBErrorCode WriteNCDF::write_nodes(int num_nodes, MBRange& nodes, int dimension)
+ErrorCode WriteNCDF::write_nodes(int num_nodes, Range& nodes, int dimension)
 {
   // write coordinates names
   NcVar *coord_var = ncFile->get_var("coor_names");
@@ -790,8 +792,8 @@
   if (!status) return MB_FAILURE;
   
   //see if should transform coordinates
-  MBErrorCode result;
-  MBTag trans_tag;
+  ErrorCode result;
+  Tag trans_tag;
   result = mdbImpl->tag_get_handle( MESH_TRANSFORM_TAG_NAME, trans_tag);
   bool transform_needed = true;
   if( result == MB_TAG_NOT_FOUND )
@@ -875,7 +877,7 @@
 }
 
 
-MBErrorCode WriteNCDF::write_header(ExodusMeshInfo& mesh_info,
+ErrorCode WriteNCDF::write_header(ExodusMeshInfo& mesh_info,
                                      std::vector<MaterialSetData> &block_info,
                                      std::vector<NeumannSetData> &sideset_info,
                                      std::vector<DirichletSetData> &nodeset_info,
@@ -895,8 +897,8 @@
   title_string.append( ": " );
   title_string.append( "time " );
 
-  if(title_string.length() > MAX_LINE_LENGTH)
-    title_string.resize( MAX_LINE_LENGTH );
+  if(title_string.length() > ExoIIInterface::MAX_LINE_LENGTH)
+    title_string.resize( ExoIIInterface::MAX_LINE_LENGTH );
 
   // initialize the exodus file
 
@@ -910,7 +912,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::write_elementblocks(std::vector<MaterialSetData> &block_data )
+ErrorCode WriteNCDF::write_elementblocks(std::vector<MaterialSetData> &block_data )
 {
 
   unsigned int i;
@@ -951,7 +953,7 @@
     const unsigned int num_nodes = num_nodes_per_elem * num_elem;
     int* connectivity = new int[num_nodes];
 
-    MBErrorCode result = mWriteIface->get_element_array(
+    ErrorCode result = mWriteIface->get_element_array(
         num_elem, num_nodes_per_elem, mGlobalIdTag, block.elements, mGlobalIdTag, exodus_id ,connectivity);
 
     if(result != MB_SUCCESS) {
@@ -961,11 +963,11 @@
     }
     
     // if necessary, convert from EXODUS to MBCN node order
-    const MBEntityType elem_type = ExoIIUtil::ExoIIElementMBEntity[block.element_type];
+    const EntityType elem_type = ExoIIUtil::ExoIIElementMBEntity[block.element_type];
     assert( block.elements.all_of_type( elem_type ) );
     const int* reorder = exodus_elem_order_map[elem_type][block.number_nodes_per_element];
     if (reorder)
-      MBWriteUtilIface::reorder( reorder, connectivity, 
+      WriteUtilIface::reorder( reorder, connectivity, 
                                  block.number_elements,
                                  block.number_nodes_per_element );
 
@@ -991,7 +993,7 @@
 }
 
 
-MBErrorCode WriteNCDF::write_global_node_order_map(int num_nodes, MBRange& nodes)
+ErrorCode WriteNCDF::write_global_node_order_map(int num_nodes, Range& nodes)
 {
   // note: this routine bypasses the standard exodusII interface for efficiency!
 
@@ -1000,7 +1002,7 @@
 
   // for now, output a dummy map!
 
-   MBRange::iterator range_iter, end_iter;
+   Range::iterator range_iter, end_iter;
    range_iter = nodes.begin();
    end_iter = nodes.end();
 
@@ -1032,7 +1034,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::write_global_element_order_map(int num_elements)
+ErrorCode WriteNCDF::write_global_element_order_map(int num_elements)
 {
 
   // allocate map array
@@ -1070,7 +1072,7 @@
 }
 
 
-MBErrorCode WriteNCDF::write_element_order_map(int num_elements)
+ErrorCode WriteNCDF::write_element_order_map(int num_elements)
 {
   // note: this routine bypasses the standard exodusII interface for efficiency!
 
@@ -1107,7 +1109,7 @@
 
 
 
-MBErrorCode WriteNCDF::write_exodus_integer_variable(const char* variable_name,
+ErrorCode WriteNCDF::write_exodus_integer_variable(const char* variable_name,
                                                       int *variable_array,
                                                       int start_position,
                                                       int number_values)
@@ -1158,7 +1160,7 @@
 
 
 
-MBErrorCode WriteNCDF::write_BCs(std::vector<NeumannSetData> &sidesets,
+ErrorCode WriteNCDF::write_BCs(std::vector<NeumannSetData> &sidesets,
                                        std::vector<DirichletSetData> &nodesets)
 {
   unsigned int i,j;
@@ -1183,7 +1185,7 @@
     int * exodus_id_array = new int[number_nodes];
     double * dist_factor_array = new double[number_nodes];
 
-    std::vector<MBEntityHandle>::iterator begin_iter, end_iter;
+    std::vector<EntityHandle>::iterator begin_iter, end_iter;
     std::vector<double>::iterator other_iter;
     begin_iter = (*ns_it).nodes.begin();
     end_iter = (*ns_it).nodes.end();
@@ -1191,7 +1193,7 @@
 
     j=0;
     int exodus_id;
-    MBErrorCode result;
+    ErrorCode result;
     //fill up node array and dist. factor array at the same time
     for(; begin_iter != end_iter; begin_iter++)
     {
@@ -1285,7 +1287,7 @@
     int * output_element_ids = new int[number_elements];
     int * output_element_side_numbers = new int[number_elements]; 
 
-    std::vector<MBEntityHandle>::iterator begin_iter, end_iter;
+    std::vector<EntityHandle>::iterator begin_iter, end_iter;
     begin_iter = sideset_data.elements.begin();
     end_iter = sideset_data.elements.end();
     std::vector<int>::iterator side_iter = sideset_data.side_numbers.begin();
@@ -1297,7 +1299,7 @@
       //for each "side"
     for(; begin_iter != end_iter; begin_iter++, side_iter++)
     {
-      MBErrorCode result = mdbImpl->tag_get_data(mGlobalIdTag,
+      ErrorCode result = mdbImpl->tag_get_data(mGlobalIdTag,
                                                   &(*begin_iter), 
                                                   1, &exodus_id);
       if (MB_FAILURE == result) {
@@ -1317,7 +1319,7 @@
       int num_values = 1;
     
         // ss_prop1[ss_index] = side_set_id
-      MBErrorCode result = write_exodus_integer_variable("ss_prop1",
+      ErrorCode result = write_exodus_integer_variable("ss_prop1",
                                                           &side_set_id, 
                                                           ss_index,num_values);
 
@@ -1392,7 +1394,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::initialize_exodus_file(ExodusMeshInfo &mesh_info,
+ErrorCode WriteNCDF::initialize_exodus_file(ExodusMeshInfo &mesh_info,
                                                 std::vector<MaterialSetData> &block_data,
                                                 std::vector<NeumannSetData> & sideset_data,
                                                 std::vector<DirichletSetData> & nodeset_data,
@@ -1423,12 +1425,12 @@
     // inquire on defined string dimension and general dimension for qa
 
   NcDim *dim_str, *dim_four, *dim_line, *dim_time;
-  if ((dim_str = ncFile->add_dim("len_string", MAX_STR_LENGTH)) == NULL)
+  if ((dim_str = ncFile->add_dim("len_string", ExoIIInterface::MAX_STR_LENGTH)) == NULL)
   {
     mWriteIface->report_error("WriteNCDF: failed to get string length in file");
     return (MB_FAILURE);
   }
-  if ((dim_line = ncFile->add_dim("len_line", MAX_LINE_LENGTH)) == NULL)
+  if ((dim_line = ncFile->add_dim("len_line", ExoIIInterface::MAX_LINE_LENGTH)) == NULL)
   {
     mWriteIface->report_error("WriteNCDF: failed to get line length in file");
     return (MB_FAILURE);
@@ -1608,7 +1610,7 @@
 
       /* store element type as attribute of connectivity variable */
 
-    char element_type_string[MAX_STR_LENGTH+1];
+    char element_type_string[ExoIIInterface::MAX_STR_LENGTH+1];
     strcpy(element_type_string, ExoIIUtil::ElementTypeNames[ block.element_type ]);
 
     if (!connect->add_att("elem_type", element_type_string))
@@ -1874,7 +1876,7 @@
 }
 
 
-MBErrorCode WriteNCDF::open_file(const char* filename)
+ErrorCode WriteNCDF::open_file(const char* filename)
 {
    // not a valid filname
    if(strlen((const char*)filename) == 0)
@@ -1894,28 +1896,28 @@
    return MB_SUCCESS;
 }
 
-MBErrorCode WriteNCDF::get_sideset_elems(MBEntityHandle sideset, int current_sense,
-                                           MBRange &forward_elems, MBRange &reverse_elems) 
+ErrorCode WriteNCDF::get_sideset_elems(EntityHandle sideset, int current_sense,
+                                           Range &forward_elems, Range &reverse_elems) 
 {
-  MBRange ss_elems, ss_meshsets;
+  Range ss_elems, ss_meshsets;
 
     // get the sense tag; don't need to check return, might be an error if the tag
     // hasn't been created yet
-  MBTag sense_tag = 0;
+  Tag sense_tag = 0;
   mdbImpl->tag_get_handle("SENSE", sense_tag);
 
     // get the entities in this set
-  MBErrorCode result = mdbImpl->get_entities_by_handle(sideset, ss_elems, true);
+  ErrorCode result = mdbImpl->get_entities_by_handle(sideset, ss_elems, true);
   if (MB_FAILURE == result) return result;
   
     // now remove the meshsets into the ss_meshsets; first find the first meshset,
-  MBRange::iterator range_iter = ss_elems.begin();
+  Range::iterator range_iter = ss_elems.begin();
   while (TYPE_FROM_HANDLE(*range_iter) != MBENTITYSET && range_iter != ss_elems.end())
     range_iter++;
   
     // then, if there are some, copy them into ss_meshsets and erase from ss_elems
   if (range_iter != ss_elems.end()) {
-    std::copy(range_iter, ss_elems.end(), mb_range_inserter(ss_meshsets));
+    std::copy(range_iter, ss_elems.end(), range_inserter(ss_meshsets));
     ss_elems.erase(range_iter, ss_elems.end());
   }
   
@@ -1924,7 +1926,7 @@
     // (if the sense is 0, copy into both ranges)
 
     // need to step forward on list until we reach the right dimension
-  MBRange::iterator dum_it = ss_elems.end();
+  Range::iterator dum_it = ss_elems.end();
   dum_it--;
   int target_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*dum_it));
   dum_it = ss_elems.begin();
@@ -1933,9 +1935,9 @@
     dum_it++;
 
   if (current_sense == 1 || current_sense == 0)
-    std::copy(dum_it, ss_elems.end(), mb_range_inserter(forward_elems));
+    std::copy(dum_it, ss_elems.end(), range_inserter(forward_elems));
   if (current_sense == -1 || current_sense == 0)
-    std::copy(dum_it, ss_elems.end(), mb_range_inserter(reverse_elems));
+    std::copy(dum_it, ss_elems.end(), range_inserter(reverse_elems));
   
     // now loop over the contained meshsets, getting the sense of those and calling this
     // function recursively
@@ -1956,4 +1958,6 @@
 }
 
 
+} // namespace moab
+
   

Modified: MOAB/trunk/src/io/WriteNCDF.hpp
===================================================================
--- MOAB/trunk/src/io/WriteNCDF.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteNCDF.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -38,13 +38,15 @@
 #include <string>
 
 #include "netcdf.hh"
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/WriterIface.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
+class WriteUtilIface;
+
 //! struct used to hold data for each block to be output in Exodus; used by
 //! initialize_exodus_file to initialize the file header for increased speed
 struct MaterialSetData
@@ -54,7 +56,7 @@
   int number_nodes_per_element;
   int number_attributes;
   ExoIIElementType element_type;
-  MBRange elements;
+  Range elements;
 };
 
 //! struct used to hold data for each nodeset to be output in Exodus; used by
@@ -63,7 +65,7 @@
 {
   int id;
   int number_nodes;
-  std::vector< MBEntityHandle > nodes;
+  std::vector< EntityHandle > nodes;
   std::vector< double > node_dist_factors;
   
 };
@@ -74,35 +76,35 @@
 {
   int id;
   int number_elements;
-  std::vector<MBEntityHandle> elements;
+  std::vector<EntityHandle> elements;
   std::vector<int> side_numbers;
-  MBEntityHandle mesh_set_handle;
+  EntityHandle mesh_set_handle;
   std::vector< double > ss_dist_factors;
 };
 
 
 //! Output Exodus File for VERDE
-class MB_DLL_EXPORT WriteNCDF : public MBWriterIface
+class MB_DLL_EXPORT WriteNCDF : public WriterIface
 {
  
 public:
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
    //! Constructor
-   WriteNCDF(MBInterface *impl);
+   WriteNCDF(Interface *impl);
 
    //! Destructor
   virtual ~WriteNCDF();
 
     //! writes out an ExoII file
-  MBErrorCode write_file(const char *exodus_file_name,
+  ErrorCode write_file(const char *exodus_file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                          const MBEntityHandle *output_list,
+                          const EntityHandle *output_list,
                           const int num_sets,
                           const std::vector<std::string> &qa_records, 
-                          const MBTag*,
+                          const Tag*,
                           int,
                           int user_dimension);
   
@@ -112,7 +114,7 @@
   //int number_dimensions();
 
     //! open an ExoII file for writing
-  MBErrorCode open_file(const char *file_name);
+  ErrorCode open_file(const char *file_name);
 
   //! contains the general information about a mesh
   struct ExodusMeshInfo
@@ -122,50 +124,50 @@
     unsigned int num_elements;
     unsigned int num_elementblocks;
     std::vector<std::string> qaRecords;
-    MBRange nodes;
+    Range nodes;
   };
   
 private:
 
     //! interface instance
-  MBInterface *mdbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mdbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! file name
   std::string exodusFile;
   NcFile *ncFile;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGeomDimensionTag;
-  MBTag mDistFactorTag;
-  MBTag mGlobalIdTag;
-  MBTag mQaRecordTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGeomDimensionTag;
+  Tag mDistFactorTag;
+  Tag mGlobalIdTag;
+  Tag mQaRecordTag;
 
-  MBTag mEntityMark;   //used to say whether an entity will be exported
+  Tag mEntityMark;   //used to say whether an entity will be exported
 
-  MBErrorCode gather_mesh_information(ExodusMeshInfo &mesh_info,
+  ErrorCode gather_mesh_information(ExodusMeshInfo &mesh_info,
                                        std::vector<MaterialSetData> &block_info,
                                        std::vector<NeumannSetData> &sideset_info,
                                        std::vector<DirichletSetData> &nodeset_info,
-                                       std::vector<MBEntityHandle> &blocks,
-                                       std::vector<MBEntityHandle> &sidesets,
-                                       std::vector<MBEntityHandle> &nodesets);
+                                       std::vector<EntityHandle> &blocks,
+                                       std::vector<EntityHandle> &sidesets,
+                                       std::vector<EntityHandle> &nodesets);
 
-  MBErrorCode write_header(ExodusMeshInfo& mesh_info,
+  ErrorCode write_header(ExodusMeshInfo& mesh_info,
                             std::vector<MaterialSetData> &block_info,
                             std::vector<NeumannSetData> &sideset_info,
                             std::vector<DirichletSetData> &nodeset_info,
                             const char *filename);
 
-  MBErrorCode initialize_exodus_file(ExodusMeshInfo &mesh_info,
+  ErrorCode initialize_exodus_file(ExodusMeshInfo &mesh_info,
                                       std::vector<MaterialSetData> &block_data,
                                       std::vector<NeumannSetData> & sideset_data,
                                       std::vector<DirichletSetData> & nodeset_data,
@@ -173,44 +175,44 @@
                                       bool write_maps = true,
                                       bool write_sideset_distribution_factors = true);
 
-  MBErrorCode write_qa_string(const char *string,
+  ErrorCode write_qa_string(const char *string,
                                int record_number,
                                int record_position);
 
-  MBErrorCode write_qa_records( std::vector<std::string> &qa_record_list);
+  ErrorCode write_qa_records( std::vector<std::string> &qa_record_list);
 
-  MBErrorCode write_nodes(int num_nodes, MBRange& nodes, int dimension );
+  ErrorCode write_nodes(int num_nodes, Range& nodes, int dimension );
 
-  MBErrorCode write_elementblocks(std::vector<MaterialSetData> &block_data );
+  ErrorCode write_elementblocks(std::vector<MaterialSetData> &block_data );
 
-  MBErrorCode write_exodus_integer_variable(const char* variable_name,
+  ErrorCode write_exodus_integer_variable(const char* variable_name,
                                                       int *variable_array,
                                                       int start_position,
                                                       int number_values);
 
-  MBErrorCode write_global_node_order_map(int num_nodes, MBRange& nodes);
-  MBErrorCode write_global_element_order_map(int num_elements);
-  MBErrorCode write_element_order_map(int num_elements);
+  ErrorCode write_global_node_order_map(int num_nodes, Range& nodes);
+  ErrorCode write_global_element_order_map(int num_elements);
+  ErrorCode write_element_order_map(int num_elements);
 
-  MBErrorCode write_BCs(std::vector<NeumannSetData> &sidesets,
+  ErrorCode write_BCs(std::vector<NeumannSetData> &sidesets,
                          std::vector<DirichletSetData> &nodesets);
 
-  MBErrorCode find_side_element_type( const int element_id, ExoIIElementType &type );
+  ErrorCode find_side_element_type( const int element_id, ExoIIElementType &type );
 
- /* MBErrorCode assign_block_ids_to_ssets(MBEntityHandle ss_handle,
+ /* ErrorCode assign_block_ids_to_ssets(EntityHandle ss_handle,
                                          MB_MeshSet *ss_mesh_set);
                                          */
-  //! free up allocated MBRanges
+  //! free up allocated Ranges
   void reset_block(std::vector<MaterialSetData> &block_info);
 
     //! recursive function; given a meshset handle, get the entities and put them
     //! on the right list, then call recursively for any contained meshsets, first
     //! checking for sense reversals
-  MBErrorCode get_sideset_elems(MBEntityHandle sideset, int current_sense,
-                                 MBRange &forward_elems, MBRange &reverse_elems);
+  ErrorCode get_sideset_elems(EntityHandle sideset, int current_sense,
+                                 Range &forward_elems, Range &reverse_elems);
   
 
-  MBErrorCode get_valid_sides(MBRange &elems, ExodusMeshInfo &mesh_info, 
+  ErrorCode get_valid_sides(Range &elems, ExodusMeshInfo &mesh_info, 
                                const int sense,
                                NeumannSetData &sideset_data);
   
@@ -218,4 +220,6 @@
   static void time_and_date(char* time_string, char* date_string);
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteSLAC.cpp
===================================================================
--- MOAB/trunk/src/io/WriteSLAC.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSLAC.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -39,33 +39,35 @@
 #include <assert.h>
 
 #include "netcdf.hh"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "Internals.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
 
+namespace moab {
+
 #define INS_ID(stringvar, prefix, id) \
           sprintf(stringvar, prefix, id)
 
-MBWriterIface* WriteSLAC::factory( MBInterface* iface )
+WriterIface* WriteSLAC::factory( Interface* iface )
   { return new WriteSLAC( iface ); }
 
-WriteSLAC::WriteSLAC(MBInterface *impl) 
+WriteSLAC::WriteSLAC(Interface *impl) 
     : mbImpl(impl), ncFile(0), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, mMaterialSetTag,
                               &dum_val);
@@ -105,7 +107,7 @@
 
 WriteSLAC::~WriteSLAC() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mbImpl->release_interface(iface_name, mWriteIface);
 
   mbImpl->tag_delete(mEntityMark);
@@ -124,13 +126,13 @@
   }
 }
 
-MBErrorCode WriteSLAC::write_file(const char *file_name, 
+ErrorCode WriteSLAC::write_file(const char *file_name, 
                                   const bool overwrite,
                                   const FileOptions&,
-                                  const MBEntityHandle *ent_handles,
+                                  const EntityHandle *ent_handles,
                                   const int num_sets,
                                   const std::vector<std::string>&, 
-                                  const MBTag*,
+                                  const Tag*,
                                   int,
                                   int )
 {
@@ -142,7 +144,7 @@
   if (NULL == strstr(file_name, ".ncdf"))
     return MB_FAILURE;
 
-  std::vector<MBEntityHandle> matsets, dirsets, neusets, entities;
+  std::vector<EntityHandle> matsets, dirsets, neusets, entities;
 
   fileName = file_name;
   
@@ -150,7 +152,7 @@
 
   if (num_sets == 0) {
       // default to all defined sets
-    MBRange this_range;
+    Range this_range;
     mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &mMaterialSetTag, NULL, 1, this_range);
     std::copy(this_range.begin(), this_range.end(), std::back_inserter(matsets));
     this_range.clear();
@@ -162,7 +164,7 @@
   }
   else {
     int dummy;
-    for (const MBEntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
+    for (const EntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
     {
       if (MB_SUCCESS == mbImpl->tag_get_data(mMaterialSetTag, &(*iter), 1, &dummy))
         matsets.push_back(*iter);
@@ -220,16 +222,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteSLAC::gather_mesh_information(MeshInfo &mesh_info,
+ErrorCode WriteSLAC::gather_mesh_information(MeshInfo &mesh_info,
                                                std::vector<WriteSLAC::MaterialSetData> &matset_info,
                                                std::vector<WriteSLAC::NeumannSetData> &neuset_info,
                                                std::vector<WriteSLAC::DirichletSetData> &dirset_info,
-                                               std::vector<MBEntityHandle> &matsets,
-                                               std::vector<MBEntityHandle> &neusets,
-                                               std::vector<MBEntityHandle> &dirsets)
+                                               std::vector<EntityHandle> &matsets,
+                                               std::vector<EntityHandle> &neusets,
+                                               std::vector<EntityHandle> &dirsets)
 {
 
-  std::vector<MBEntityHandle>::iterator vector_iter, end_vector_iter;
+  std::vector<EntityHandle>::iterator vector_iter, end_vector_iter;
 
   mesh_info.num_nodes = 0;
   mesh_info.num_elements = 0;
@@ -242,7 +244,7 @@
 
   mesh_info.num_matsets = matsets.size();
 
-  std::vector<MBEntityHandle> parent_meshsets;
+  std::vector<EntityHandle> parent_meshsets;
 
   // clean out the bits for the element mark
   mbImpl->tag_delete(mEntityMark);
@@ -254,14 +256,14 @@
   {
        
     WriteSLAC::MaterialSetData matset_data;
-    matset_data.elements = new MBRange;
+    matset_data.elements = new Range;
 
     //for the purpose of qa records, get the parents of these matsets 
     if( mbImpl->get_parent_meshsets( *vector_iter, parent_meshsets ) != MB_SUCCESS )
       return MB_FAILURE;
 
     // get all Entity Handles in the mesh set
-    MBRange dummy_range;
+    Range dummy_range;
     mbImpl->get_entities_by_handle(*vector_iter, dummy_range, true );
 
 
@@ -269,7 +271,7 @@
     // wait a minute, we are doing some filtering here that doesn't make sense at this level  CJS
 
       // find the dimension of the last entity in this range
-    MBRange::iterator entity_iter = dummy_range.end();
+    Range::iterator entity_iter = dummy_range.end();
     entity_iter = dummy_range.end();
     entity_iter--;
     int this_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*entity_iter));
@@ -279,7 +281,7 @@
       entity_iter++;
     
     if (entity_iter != dummy_range.end())
-      std::copy(entity_iter, dummy_range.end(), mb_range_inserter(*(matset_data.elements)));
+      std::copy(entity_iter, dummy_range.end(), range_inserter(*(matset_data.elements)));
 
     assert(matset_data.elements->begin() == matset_data.elements->end() ||
            MBCN::Dimension(TYPE_FROM_HANDLE(*(matset_data.elements->begin()))) == this_dim);
@@ -294,13 +296,13 @@
     matset_data.number_attributes = 0;
  
      // iterate through all the elements in the meshset
-    MBRange::iterator elem_range_iter, end_elem_range_iter;
+    Range::iterator elem_range_iter, end_elem_range_iter;
     elem_range_iter = matset_data.elements->begin();
     end_elem_range_iter = matset_data.elements->end();
 
       // get the entity type for this matset, verifying that it's the same for all elements
       // THIS ASSUMES HANDLES SORT BY TYPE!!!
-    MBEntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
+    EntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
     end_elem_range_iter--;
     if (entity_type != TYPE_FROM_HANDLE(*(end_elem_range_iter++))) {
       mWriteIface->report_error("Entities in matset %i not of common type", id);
@@ -321,7 +323,7 @@
     matset_data.moab_type = mbImpl->type_from_handle(*(matset_data.elements->begin()));
     if (MBMAXTYPE == matset_data.moab_type) return MB_FAILURE;
     
-    std::vector<MBEntityHandle> tmp_conn;
+    std::vector<EntityHandle> tmp_conn;
     mbImpl->get_connectivity(&(*(matset_data.elements->begin())), 1, tmp_conn);
     matset_data.element_type = 
       ExoIIUtil::get_element_type_from_num_verts(tmp_conn.size(), entity_type, dimension);
@@ -345,7 +347,7 @@
     if(!neusets.empty())
     {
       // if there are neusets, keep track of which elements are being written out
-      for(MBRange::iterator iter = matset_data.elements->begin(); 
+      for(Range::iterator iter = matset_data.elements->begin(); 
           iter != matset_data.elements->end(); ++iter)
       {
         unsigned char bit = 0x1;
@@ -368,7 +370,7 @@
       mesh_info.num_dim = highest_dimension_of_element_matsets;
   }
 
-  MBRange::iterator range_iter, end_range_iter;
+  Range::iterator range_iter, end_range_iter;
   range_iter = mesh_info.nodes.begin();
   end_range_iter = mesh_info.nodes.end();
 
@@ -394,20 +396,20 @@
     
     dirset_data.id = id; 
 
-    std::vector<MBEntityHandle> node_vector;
+    std::vector<EntityHandle> node_vector;
     //get the nodes of the dirset that are in mesh_info.nodes
     if( mbImpl->get_entities_by_handle(*vector_iter, node_vector, true) != MB_SUCCESS ) {
       mWriteIface->report_error("Couldn't get nodes in dirset %i", id);
       return MB_FAILURE;
     }
 
-    std::vector<MBEntityHandle>::iterator iter, end_iter;
+    std::vector<EntityHandle>::iterator iter, end_iter;
     iter = node_vector.begin();
     end_iter= node_vector.end();
  
     int j=0; 
     unsigned char node_marked = 0;
-    MBErrorCode result;
+    ErrorCode result;
     for(; iter != end_iter; iter++)
     {
       if (TYPE_FROM_HANDLE(*iter) != MBVERTEX) continue;
@@ -442,11 +444,11 @@
  
     //get the sides in two lists, one forward the other reverse; starts with forward sense
       // by convention
-    MBRange forward_elems, reverse_elems;
+    Range forward_elems, reverse_elems;
     if(get_neuset_elems(*vector_iter, 0, forward_elems, reverse_elems) == MB_FAILURE)
       return MB_FAILURE;
 
-    MBErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
+    ErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
     if (MB_SUCCESS != result) {
       mWriteIface->report_error("Couldn't get valid sides data.");
       return result;
@@ -465,14 +467,14 @@
   return gather_interior_exterior(mesh_info, matset_info, neuset_info);
 }
 
-MBErrorCode WriteSLAC::get_valid_sides(MBRange &elems, const int sense,
+ErrorCode WriteSLAC::get_valid_sides(Range &elems, const int sense,
                                        WriteSLAC::NeumannSetData &neuset_data) 
 {
     // this is where we see if underlying element of side set element is included in output 
 
   unsigned char element_marked = 0;
-  MBErrorCode result;
-  for(MBRange::iterator iter = elems.begin(); iter != elems.end(); iter++)
+  ErrorCode result;
+  for(Range::iterator iter = elems.begin(); iter != elems.end(); iter++)
   {
       // should insert here if "side" is a quad/tri on a quad/tri mesh
     result = mbImpl->tag_get_data(mEntityMark, &(*iter), 1, &element_marked);
@@ -490,7 +492,7 @@
     }
     else //then "side" is probably a quad/tri on a hex/tet mesh
     {
-      std::vector<MBEntityHandle> parents;
+      std::vector<EntityHandle> parents;
       int dimension = MBCN::Dimension( TYPE_FROM_HANDLE(*iter));
 
         //get the adjacent parent element of "side"
@@ -532,11 +534,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteSLAC::write_nodes(const int num_nodes, const MBRange& nodes, const int dimension)
+ErrorCode WriteSLAC::write_nodes(const int num_nodes, const Range& nodes, const int dimension)
 {
   //see if should transform coordinates
-  MBErrorCode result;
-  MBTag trans_tag;
+  ErrorCode result;
+  Tag trans_tag;
   result = mbImpl->tag_get_handle( MESH_TRANSFORM_TAG_NAME, trans_tag);
   bool transform_needed = true;
   if( result == MB_TAG_NOT_FOUND )
@@ -627,18 +629,18 @@
 }
 
 
-MBErrorCode WriteSLAC::gather_interior_exterior(MeshInfo &mesh_info,
+ErrorCode WriteSLAC::gather_interior_exterior(MeshInfo &mesh_info,
                                                 std::vector<WriteSLAC::MaterialSetData> &matset_data,
                                                 std::vector<WriteSLAC::NeumannSetData> &neuset_data)
 {
     // need to assign a tag with the matset id
-  MBTag matset_id_tag;
+  Tag matset_id_tag;
   unsigned int i;
   int dum = -1;
-  MBErrorCode result = mbImpl->tag_create("__matset_id", 4, MB_TAG_DENSE, matset_id_tag, &dum);
+  ErrorCode result = mbImpl->tag_create("__matset_id", 4, MB_TAG_DENSE, matset_id_tag, &dum);
   if (MB_SUCCESS != result) return result;
 
-  MBRange::iterator rit;
+  Range::iterator rit;
   mesh_info.num_int_hexes = mesh_info.num_int_tets = 0;
   
   for(i=0; i< matset_data.size(); i++)
@@ -663,7 +665,7 @@
 
     // now go through the neumann sets, pulling out the hexes with faces on the 
     // boundary
-  std::vector<MBEntityHandle>::iterator vit;
+  std::vector<EntityHandle>::iterator vit;
   for(i=0; i< neuset_data.size(); i++)
   {
     WriteSLAC::NeumannSetData neuset = neuset_data[i];
@@ -682,16 +684,16 @@
 }
 
 
-MBErrorCode WriteSLAC::write_matsets(MeshInfo &mesh_info,
+ErrorCode WriteSLAC::write_matsets(MeshInfo &mesh_info,
                                      std::vector<WriteSLAC::MaterialSetData> &matset_data,
                                      std::vector<WriteSLAC::NeumannSetData> &neuset_data)
 {
 
   unsigned int i;
   std::vector<int> connect;
-  const MBEntityHandle *connecth;
+  const EntityHandle *connecth;
   int num_connecth;
-  MBErrorCode result;
+  ErrorCode result;
   
     // first write the interior hexes
   NcVar *hex_conn = NULL;
@@ -701,7 +703,7 @@
     if (NULL == hex_conn) return MB_FAILURE;
   }
   connect.reserve(13);
-  MBRange::iterator rit;
+  Range::iterator rit;
 
   int elem_num = 0;
   WriteSLAC::MaterialSetData matset;
@@ -802,7 +804,7 @@
 
           // now write the side numbers
         for (i = 0; i < neuset_data.size(); i++) {
-          std::vector<MBEntityHandle>::iterator vit = 
+          std::vector<EntityHandle>::iterator vit = 
             std::find(neuset_data[i].elements.begin(), neuset_data[i].elements.end(), *rit);
           while (vit != neuset_data[i].elements.end()) {
               // have a side - get the side # and put in connect array
@@ -853,7 +855,7 @@
 
           // now write the side numbers
         for (i = 0; i < neuset_data.size(); i++) {
-          std::vector<MBEntityHandle>::iterator vit = 
+          std::vector<EntityHandle>::iterator vit = 
             std::find(neuset_data[i].elements.begin(), neuset_data[i].elements.end(), *rit);
           while (vit != neuset_data[i].elements.end()) {
               // have a side - get the side # and put in connect array
@@ -877,7 +879,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteSLAC::initialize_file(MeshInfo &mesh_info)
+ErrorCode WriteSLAC::initialize_file(MeshInfo &mesh_info)
 {
     // perform the initializations
 
@@ -996,7 +998,7 @@
 }
 
 
-MBErrorCode WriteSLAC::open_file(const char* filename)
+ErrorCode WriteSLAC::open_file(const char* filename)
 {
    // not a valid filname
    if(strlen((const char*)filename) == 0)
@@ -1016,28 +1018,28 @@
    return MB_SUCCESS;
 }
 
-MBErrorCode WriteSLAC::get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                                        MBRange &forward_elems, MBRange &reverse_elems) 
+ErrorCode WriteSLAC::get_neuset_elems(EntityHandle neuset, int current_sense,
+                                        Range &forward_elems, Range &reverse_elems) 
 {
-  MBRange ss_elems, ss_meshsets;
+  Range ss_elems, ss_meshsets;
 
     // get the sense tag; don't need to check return, might be an error if the tag
     // hasn't been created yet
-  MBTag sense_tag = 0;
+  Tag sense_tag = 0;
   mbImpl->tag_get_handle("SENSE", sense_tag);
 
     // get the entities in this set
-  MBErrorCode result = mbImpl->get_entities_by_handle(neuset, ss_elems, true);
+  ErrorCode result = mbImpl->get_entities_by_handle(neuset, ss_elems, true);
   if (MB_FAILURE == result) return result;
   
     // now remove the meshsets into the ss_meshsets; first find the first meshset,
-  MBRange::iterator range_iter = ss_elems.begin();
+  Range::iterator range_iter = ss_elems.begin();
   while (TYPE_FROM_HANDLE(*range_iter) != MBENTITYSET && range_iter != ss_elems.end())
     range_iter++;
   
     // then, if there are some, copy them into ss_meshsets and erase from ss_elems
   if (range_iter != ss_elems.end()) {
-    std::copy(range_iter, ss_elems.end(), mb_range_inserter(ss_meshsets));
+    std::copy(range_iter, ss_elems.end(), range_inserter(ss_meshsets));
     ss_elems.erase(range_iter, ss_elems.end());
   }
   
@@ -1046,7 +1048,7 @@
     // (if the sense is 0, copy into both ranges)
 
     // need to step forward on list until we reach the right dimension
-  MBRange::iterator dum_it = ss_elems.end();
+  Range::iterator dum_it = ss_elems.end();
   dum_it--;
   int target_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*dum_it));
   dum_it = ss_elems.begin();
@@ -1055,9 +1057,9 @@
     dum_it++;
 
   if (current_sense == 1 || current_sense == 0)
-    std::copy(dum_it, ss_elems.end(), mb_range_inserter(forward_elems));
+    std::copy(dum_it, ss_elems.end(), range_inserter(forward_elems));
   if (current_sense == -1 || current_sense == 0)
-    std::copy(dum_it, ss_elems.end(), mb_range_inserter(reverse_elems));
+    std::copy(dum_it, ss_elems.end(), range_inserter(reverse_elems));
   
     // now loop over the contained meshsets, getting the sense of those and calling this
     // function recursively
@@ -1077,5 +1079,6 @@
   return result;
 }
 
+} // namespace moab
 
   

Modified: MOAB/trunk/src/io/WriteSLAC.hpp
===================================================================
--- MOAB/trunk/src/io/WriteSLAC.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSLAC.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,35 +37,38 @@
 #include <vector>
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/WriterIface.hpp"
 
 class NcFile;
-class MBWriteUtilIface;
 
-class MB_DLL_EXPORT WriteSLAC : public MBWriterIface
+namespace moab {
+
+class WriteUtilIface;
+
+class MB_DLL_EXPORT WriteSLAC : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteSLAC(MBInterface *impl);
+   WriteSLAC(Interface *impl);
 
    //! Destructor
   virtual ~WriteSLAC();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                          const MBEntityHandle *output_list,
+                          const EntityHandle *output_list,
                           const int num_sets,
                           const std::vector<std::string>& qa_list,
-                          const MBTag* tag_list,
+                          const Tag* tag_list,
                           int num_tags,
                           int export_dimension);
   
@@ -78,8 +81,8 @@
     int number_nodes_per_element;
     int number_attributes;
     ExoIIElementType element_type;
-    MBEntityType moab_type;
-    MBRange *elements;
+    EntityType moab_type;
+    Range *elements;
   };
 
 //! struct used to hold data for each nodeset to be output; used by
@@ -88,7 +91,7 @@
   {
     int id;
     int number_nodes;
-    std::vector< MBEntityHandle > nodes;
+    std::vector< EntityHandle > nodes;
     std::vector< double > node_dist_factors;
   
   };
@@ -99,9 +102,9 @@
   {
     int id;
     int number_elements;
-    std::vector<MBEntityHandle> elements;
+    std::vector<EntityHandle> elements;
     std::vector<int> side_numbers;
-    MBEntityHandle mesh_set_handle;
+    EntityHandle mesh_set_handle;
   };
 
 
@@ -111,7 +114,7 @@
   //int number_dimensions();
 
     //! open a file for writing
-  MBErrorCode open_file(const char *filename);
+  ErrorCode open_file(const char *filename);
 
   //! contains the general information about a mesh
   class MeshInfo
@@ -123,8 +126,8 @@
     unsigned int num_matsets;
     unsigned int num_int_hexes;
     unsigned int num_int_tets;
-    MBRange bdy_hexes, bdy_tets;
-    MBRange nodes;
+    Range bdy_hexes, bdy_tets;
+    Range nodes;
 
     MeshInfo() 
         : num_dim(0), num_nodes(0), num_elements(0), num_matsets(0), 
@@ -136,56 +139,58 @@
 private:
 
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! file name
   std::string fileName;
   NcFile *ncFile;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGlobalIdTag;
-  MBTag mMatSetIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGlobalIdTag;
+  Tag mMatSetIdTag;
 
-  MBTag mEntityMark;   //used to say whether an entity will be exported
+  Tag mEntityMark;   //used to say whether an entity will be exported
 
-  MBErrorCode gather_mesh_information(MeshInfo &mesh_info,
+  ErrorCode gather_mesh_information(MeshInfo &mesh_info,
                                       std::vector<MaterialSetData> &matset_info,
                                       std::vector<NeumannSetData> &neuset_info,
                                       std::vector<DirichletSetData> &dirset_info,
-                                      std::vector<MBEntityHandle> &matsets,
-                                      std::vector<MBEntityHandle> &neusets,
-                                      std::vector<MBEntityHandle> &dirsets);
+                                      std::vector<EntityHandle> &matsets,
+                                      std::vector<EntityHandle> &neusets,
+                                      std::vector<EntityHandle> &dirsets);
   
-  MBErrorCode initialize_file(MeshInfo &mesh_info);
+  ErrorCode initialize_file(MeshInfo &mesh_info);
 
-  MBErrorCode write_nodes(const int num_nodes, const MBRange& nodes, 
+  ErrorCode write_nodes(const int num_nodes, const Range& nodes, 
                           const int dimension );
 
-  MBErrorCode write_matsets(MeshInfo &mesh_info, 
+  ErrorCode write_matsets(MeshInfo &mesh_info, 
                             std::vector<MaterialSetData> &matset_data,
                             std::vector<NeumannSetData> &neuset_data);
   
-  MBErrorCode get_valid_sides(MBRange &elems, const int sense,
+  ErrorCode get_valid_sides(Range &elems, const int sense,
                               WriteSLAC::NeumannSetData &sideset_data);
   
   void reset_matset(std::vector<MaterialSetData> &matset_info);
   
-  MBErrorCode get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                               MBRange &forward_elems, MBRange &reverse_elems);
+  ErrorCode get_neuset_elems(EntityHandle neuset, int current_sense,
+                               Range &forward_elems, Range &reverse_elems);
   
-  MBErrorCode gather_interior_exterior(MeshInfo &mesh_info,
+  ErrorCode gather_interior_exterior(MeshInfo &mesh_info,
                                        std::vector<MaterialSetData> &matset_data,
                                        std::vector<NeumannSetData> &neuset_data);
   
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteSTL.cpp
===================================================================
--- MOAB/trunk/src/io/WriteSTL.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSTL.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,15 +21,13 @@
 
 
 #include "WriteSTL.hpp"
-#include "MBCN.hpp"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/WriteUtilIface.hpp"
 #include "FileOptions.hpp"
-#include "MBSysUtil.hpp"
+#include "SysUtil.hpp"
 
-#include "MBEntityHandle.h"
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -38,6 +36,8 @@
 #include <fcntl.h>
 #include <limits.h>
 
+namespace moab {
+
 #if defined(_MSC_VER) || defined(__MINGW32__) /* windows */
 #  include <io.h>
 #  ifndef __MINGW32__
@@ -51,36 +51,36 @@
 
 const int DEFAULT_PRECISION = 6;
 
-MBWriterIface *WriteSTL::factory( MBInterface* iface )
+WriterIface *WriteSTL::factory( Interface* iface )
   { return new WriteSTL( iface ); }
 
-WriteSTL::WriteSTL(MBInterface *impl) 
+WriteSTL::WriteSTL(Interface *impl) 
     : mbImpl(impl)
 {
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 }
 
 WriteSTL::~WriteSTL() 
 {
-  mbImpl->release_interface("MBWriteUtilIface", mWriteIface);
+  mbImpl->release_interface("WriteUtilIface", mWriteIface);
 }
 
 
-MBErrorCode WriteSTL::write_file(const char *file_name, 
+ErrorCode WriteSTL::write_file(const char *file_name, 
                                  const bool overwrite,
                                  const FileOptions& opts,
-                                 const MBEntityHandle *ent_handles,
+                                 const EntityHandle *ent_handles,
                                  const int num_sets,
                                  const std::vector<std::string>& qa_list, 
-                                 const MBTag* tag_list,
+                                 const Tag* tag_list,
                                  int num_tags,
                                  int  )
 {
   char header[81];
-  MBRange triangles;
-  MBErrorCode rval;
+  Range triangles;
+  ErrorCode rval;
   
   if (tag_list && num_tags) {
     mWriteIface->report_error( "STL file does not support tag data\n" );
@@ -181,7 +181,7 @@
   return result;
 }
 
-MBErrorCode WriteSTL::make_header( char header[81], 
+ErrorCode WriteSTL::make_header( char header[81], 
                                    const std::vector<std::string>& qa_list )
 {
   memset( header, 0, 81 );
@@ -201,21 +201,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteSTL::get_triangles( const MBEntityHandle* set_array,
+ErrorCode WriteSTL::get_triangles( const EntityHandle* set_array,
                                      int set_array_length,
-                                     MBRange& triangles )
+                                     Range& triangles )
 {
   if (!set_array || set_array_length == 0)
   {
     return mbImpl->get_entities_by_type( 0, MBTRI, triangles );
   }
   
-  const MBEntityHandle* iter = set_array;
-  const MBEntityHandle* end = iter + set_array_length;
+  const EntityHandle* iter = set_array;
+  const EntityHandle* end = iter + set_array_length;
   for (; iter != end; ++iter)
   {
-    MBRange r;
-    MBErrorCode rval = mbImpl->get_entities_by_type( *iter, MBTRI, r, true );
+    Range r;
+    ErrorCode rval = mbImpl->get_entities_by_type( *iter, MBTRI, r, true );
     if (MB_SUCCESS != rval)
       return rval;
     triangles.merge( r );
@@ -224,7 +224,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteSTL::get_triangle_data( const double coords[9],
+ErrorCode WriteSTL::get_triangle_data( const double coords[9],
                                          float v1[3],
                                          float v2[3],
                                          float v3[3],
@@ -257,9 +257,9 @@
 }
 
 
-MBErrorCode WriteSTL::ascii_write_triangles( FILE* file,
+ErrorCode WriteSTL::ascii_write_triangles( FILE* file,
                                              const char header[81],
-                                             const MBRange& triangles,
+                                             const Range& triangles,
                                              int prec )
 {
   const char solid_name[] = "MOAB";
@@ -271,14 +271,14 @@
   if (EOF == fputs( myheader, file ) || EOF == fputs( "\n", file ))
     return MB_FILE_WRITE_ERROR;
   
-  MBErrorCode rval;
+  ErrorCode rval;
   double coords[9];
   float v1[3], v2[3], v3[3];
   float n[3];
-  for (MBRange::const_iterator iter = triangles.begin();
+  for (Range::const_iterator iter = triangles.begin();
        iter != triangles.end(); ++iter)
   {
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int num_vtx;
     
     rval = mbImpl->get_connectivity( *iter, conn, num_vtx );
@@ -317,18 +317,18 @@
   char pad[2];
 };
 
-MBErrorCode WriteSTL::binary_write_triangles( FILE* file,
+ErrorCode WriteSTL::binary_write_triangles( FILE* file,
                                              const char header[81],
                                              ByteOrder byte_order,
-                                             const MBRange& triangles )
+                                             const Range& triangles )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (fwrite( header, 80, 1, file ) != 1)
     return MB_FILE_WRITE_ERROR;
   
     // default to little endian if byte_order == UNKNOWN_BYTE_ORDER
   const bool want_big_endian = (byte_order == STL_BIG_ENDIAN);
-  const bool am_big_endian = !MBSysUtil::little_endian();
+  const bool am_big_endian = !SysUtil::little_endian();
   const bool swap_bytes = (want_big_endian == am_big_endian);
     
   if (triangles.size() > INT_MAX) // can't write that many triangles
@@ -336,17 +336,17 @@
   
   uint32_t count = (uint32_t)triangles.size();
   if (swap_bytes)
-    MBSysUtil::byteswap(&count, 1);
+    SysUtil::byteswap(&count, 1);
   if (fwrite( &count, 4, 1, file ) != 1)
     return MB_FILE_WRITE_ERROR;
 
   double coords[9];
   BinTri tri;
   tri.pad[0] = tri.pad[1] = '\0';
-  for (MBRange::const_iterator iter = triangles.begin();
+  for (Range::const_iterator iter = triangles.begin();
        iter != triangles.end(); ++iter)
   {
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int num_vtx;
     
     rval = mbImpl->get_connectivity( *iter, conn, num_vtx );
@@ -365,10 +365,10 @@
     
     if (swap_bytes)
     {
-      MBSysUtil::byteswap( tri.normal, 3 );
-      MBSysUtil::byteswap( tri.vertex1, 3 );
-      MBSysUtil::byteswap( tri.vertex2, 3 );
-      MBSysUtil::byteswap( tri.vertex3, 3 );
+      SysUtil::byteswap( tri.normal, 3 );
+      SysUtil::byteswap( tri.vertex1, 3 );
+      SysUtil::byteswap( tri.vertex2, 3 );
+      SysUtil::byteswap( tri.vertex3, 3 );
     }
    
     if (1 != fwrite( &tri, 50, 1, file ))
@@ -378,3 +378,4 @@
   return MB_SUCCESS;
 }
 
+} // namespace moab

Modified: MOAB/trunk/src/io/WriteSTL.hpp
===================================================================
--- MOAB/trunk/src/io/WriteSTL.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSTL.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -32,35 +32,37 @@
 #ifndef WRITE_STL_HPP
 #define WRITE_STL_HPP
 
-#include "MBForward.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/WriterIface.hpp"
 
 #include <stdio.h>
 
-class MBWriteUtilIface;
+namespace moab {
 
-class WriteSTL : public MBWriterIface
+class WriteUtilIface;
+
+class WriteSTL : public WriterIface
 {
  
 public:
   
     //! factory method forSTL writer
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
    //! Constructor
-  WriteSTL(MBInterface *impl);
+  WriteSTL(Interface *impl);
 
    //! Destructor
   virtual ~WriteSTL();
   
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                         const MBEntityHandle *output_list,
+                         const EntityHandle *output_list,
                          const int num_sets,
                          const std::vector<std::string>& qa_list,
-                         const MBTag* tag_list,
+                         const Tag* tag_list,
                          int num_tags,
                          int export_dimension);  
 
@@ -69,45 +71,46 @@
   enum ByteOrder { STL_BIG_ENDIAN, STL_LITTLE_ENDIAN, STL_UNKNOWN_BYTE_ORDER };
   
     //! Write list of triangles to an STL file.  
-  MBErrorCode ascii_write_triangles( FILE* file,
+  ErrorCode ascii_write_triangles( FILE* file,
                                      const char header[82],
-                                     const MBRange& triangles,
+                                     const Range& triangles,
                                      int precision );
     //! Write list of triangles to an STL file.  
-  MBErrorCode binary_write_triangles( FILE* file,
+  ErrorCode binary_write_triangles( FILE* file,
                                       const char header[82],
                                       ByteOrder byte_order,
-                                      const MBRange& triangles );
+                                      const Range& triangles );
 
     //! Given an array of vertex coordinates for a triangle,
     //! pass back individual point coordinates as floats and 
     //! calculate triangle normal.
-  MBErrorCode get_triangle_data( const double vtx_coords[9],
+  ErrorCode get_triangle_data( const double vtx_coords[9],
                                  float v1[3],
                                  float v2[3],
                                  float v3[3],
                                  float n[3] );
                                        
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
 private:
 
     //! Construct 80-byte, null-terminated description string from
     //! qa_list.  Unused space in header will be null-char padded.
-  MBErrorCode make_header( char header[82], const std::vector<std::string>& qa_list );
+  ErrorCode make_header( char header[82], const std::vector<std::string>& qa_list );
   
     //! Get triangles to write from input array of entity sets.  If
     //! no sets, gets all triangles.
-  MBErrorCode get_triangles( const MBEntityHandle* set_array,
+  ErrorCode get_triangles( const EntityHandle* set_array,
                              int set_array_length,
-                             MBRange& triangles );  
+                             Range& triangles );  
   
     //! Open a file, respecting passed overwrite value and
     //! subclass-specified value for need_binary_io().
   FILE* open_file( const char* name, bool overwrite, bool binary );
 };
 
+} // namespace moab
 
 #endif

Modified: MOAB/trunk/src/io/WriteSmf.cpp
===================================================================
--- MOAB/trunk/src/io/WriteSmf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSmf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -34,47 +34,49 @@
 #include <iterator>
 #include <algorithm>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "Internals.hpp"
 #include "FileOptions.hpp"
-#include "MBVersion.h"
+#include "moab/Version.h"
 
+namespace moab {
+
 const int DEFAULT_PRECISION = 10;
 const bool DEFAULT_STRICT = true;
 
-MBWriterIface *WriteSmf::factory( MBInterface* iface )
+WriterIface *WriteSmf::factory( Interface* iface )
   { return new WriteSmf( iface ); }
 
-WriteSmf::WriteSmf(MBInterface *impl) 
+WriteSmf::WriteSmf(Interface *impl) 
     : mbImpl(impl), writeTool(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  writeTool = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  writeTool = reinterpret_cast<WriteUtilIface*>(ptr);
 }
 
 WriteSmf::~WriteSmf() 
 {
-  mbImpl->release_interface("MBWriteUtilIface", writeTool);
+  mbImpl->release_interface("WriteUtilIface", writeTool);
 }
 
-MBErrorCode WriteSmf::write_file(const char *file_name, 
+ErrorCode WriteSmf::write_file(const char *file_name, 
                                  const bool overwrite,
                                  const FileOptions& opts,
-                                 const MBEntityHandle *output_list,
+                                 const EntityHandle *output_list,
                                  const int num_sets,
                                  const std::vector<std::string>& ,
-                                 const MBTag* tag_list,
+                                 const Tag* tag_list,
                                  int num_tags,
                                  int )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // Get precision for node coordinates
   int precision;
@@ -99,7 +101,7 @@
   file.precision( precision );
     // Get entities to write
   
-  MBRange triangles;
+  Range triangles;
   if (!output_list || !num_sets)
   {
     rval = mbImpl->get_entities_by_type( 0, MBTRI, triangles, false);
@@ -116,14 +118,14 @@
   // use an array with all the connectivities in the triangles; it will be converted later to ints
   int numTriangles = triangles.size();
   int array_alloc = 3*numTriangles;       // allocated size of 'array'
-  MBEntityHandle* array = new MBEntityHandle[array_alloc]; // ptr to working array of result handles
+  EntityHandle* array = new EntityHandle[array_alloc]; // ptr to working array of result handles
   // fill up array with node handles; reorder and uniquify 
   if (!array)
      return MB_MEMORY_ALLOCATION_FAILED;
   int fillA = 0;
-  for (MBRange::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
     {
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       int conn_len;
       rval = mbImpl->get_connectivity( *e, conn, conn_len );
       if (MB_SUCCESS != rval  ) 
@@ -153,7 +155,7 @@
   double coord[3];
   for(int i=0; i<numNodes; i++)
     {
-      MBEntityHandle node_handle = array[i];
+      EntityHandle node_handle = array[i];
      
       rval = mbImpl->get_coords(&node_handle,1, coord);
       if(rval !=MB_SUCCESS) return rval;
@@ -163,9 +165,9 @@
   // write faces now
   // leave a blank line for cosmetics
   file << " \n";
-  for (MBRange::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
     {
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       int conn_len;
       rval = mbImpl->get_connectivity( *e, conn, conn_len );
       if (MB_SUCCESS != rval  ) 
@@ -186,4 +188,5 @@
   return MB_SUCCESS;
 }
 
-  
+} // namespace moab
+

Modified: MOAB/trunk/src/io/WriteSmf.hpp
===================================================================
--- MOAB/trunk/src/io/WriteSmf.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteSmf.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -19,40 +19,44 @@
 
 #include <iosfwd>
 
-#include "MBForward.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/WriterIface.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
-//class MB_DLL_EXPORT WriteSmf : public MBWriterIface
-class WriteSmf : public MBWriterIface
+class WriteUtilIface;
+
+//class MB_DLL_EXPORT WriteSmf : public WriterIface
+class WriteSmf : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteSmf(MBInterface *impl);
+   WriteSmf(Interface *impl);
 
    //! Destructor
   virtual ~WriteSmf();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                         const MBEntityHandle *output_list,
+                         const EntityHandle *output_list,
                          const int num_sets,
                          const std::vector<std::string>& qa_list,
-                         const MBTag* tag_list,
+                         const Tag* tag_list,
                          int num_tags,
                          int export_dimension);
 
   private:
      
-    MBInterface* mbImpl;
-    MBWriteUtilIface* writeTool;
+    Interface* mbImpl;
+    WriteUtilIface* writeTool;
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteTemplate.cpp
===================================================================
--- MOAB/trunk/src/io/WriteTemplate.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteTemplate.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -34,34 +34,36 @@
 #include <string.h>
 #include <iostream>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
 #include "assert.h"
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #include "ExoIIUtil.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
 
+namespace moab {
+
 #define INS_ID(stringvar, prefix, id) \
           sprintf(stringvar, prefix, id)
 
-MBWriterIface* WriteTEMPLATE::factory( MBInterface* iface )
+WriterIface* WriteTEMPLATE::factory( Interface* iface )
   { return new WriteTEMPLATE( iface ); }
 
-WriteTEMPLATE::WriteTEMPLATE(MBInterface *impl) 
+WriteTEMPLATE::WriteTEMPLATE(Interface *impl) 
     : mbImpl(impl), mCurrentMeshHandle(0)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  mWriteIface = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  mWriteIface = reinterpret_cast<WriteUtilIface*>(ptr);
 
   // initialize in case tag_get_handle fails below
   //! get and cache predefined tag handles
   int dum_val = 0;
-  MBErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
+  ErrorCode result = impl->tag_get_handle(MATERIAL_SET_TAG_NAME,  mMaterialSetTag);
   if (MB_TAG_NOT_FOUND == result)
     result = impl->tag_create(MATERIAL_SET_TAG_NAME, sizeof(int), MB_TAG_SPARSE, mMaterialSetTag,
                               &dum_val);
@@ -101,7 +103,7 @@
 
 WriteTEMPLATE::~WriteTEMPLATE() 
 {
-  std::string iface_name = "MBWriteUtilIface";
+  std::string iface_name = "WriteUtilIface";
   mbImpl->release_interface(iface_name, mWriteIface);
 
   mbImpl->tag_delete(mEntityMark);
@@ -118,13 +120,13 @@
   }
 }
 
-MBErrorCode WriteTEMPLATE::write_file(const char *file_name, 
+ErrorCode WriteTEMPLATE::write_file(const char *file_name, 
                                       const bool /* overwrite (commented out to remove warning) */,
                                       const FileOptions& opts,
-                                      const MBEntityHandle *ent_handles,
+                                      const EntityHandle *ent_handles,
                                       const int num_sets,
                                       const std::vector<std::string>&,
-                                      const MBTag* ,
+                                      const Tag* ,
                                       int ,
                                       int )
 {
@@ -136,7 +138,7 @@
   if (NULL == strstr(file_name, ".template"))
     return MB_FAILURE;
 
-  std::vector<MBEntityHandle> matsets, dirsets, neusets, entities;
+  std::vector<EntityHandle> matsets, dirsets, neusets, entities;
 
   fileName = file_name;
   
@@ -144,7 +146,7 @@
 
   if (num_sets == 0) {
       // default to all defined sets
-    MBRange this_range;
+    Range this_range;
     mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &mMaterialSetTag, NULL, 1, this_range);
     std::copy(this_range.begin(), this_range.end(), std::back_inserter(matsets));
     this_range.clear();
@@ -156,7 +158,7 @@
   }
   else {
     int dummy;
-    for (const MBEntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
+    for (const EntityHandle *iter = ent_handles; iter < ent_handles+num_sets; iter++) 
     {
       if (MB_SUCCESS == mbImpl->tag_get_data(mMaterialSetTag, &(*iter), 1, &dummy))
         matsets.push_back(*iter);
@@ -213,16 +215,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteTEMPLATE::gather_mesh_information(MeshInfo &mesh_info,
+ErrorCode WriteTEMPLATE::gather_mesh_information(MeshInfo &mesh_info,
                                                    std::vector<WriteTEMPLATE::MaterialSetData> &matset_info,
                                                    std::vector<WriteTEMPLATE::NeumannSetData> &neuset_info,
                                                    std::vector<WriteTEMPLATE::DirichletSetData> &dirset_info,
-                                                   std::vector<MBEntityHandle> &matsets,
-                                                   std::vector<MBEntityHandle> &neusets,
-                                                   std::vector<MBEntityHandle> &dirsets)
+                                                   std::vector<EntityHandle> &matsets,
+                                                   std::vector<EntityHandle> &neusets,
+                                                   std::vector<EntityHandle> &dirsets)
 {
 
-  std::vector<MBEntityHandle>::iterator vector_iter, end_vector_iter;
+  std::vector<EntityHandle>::iterator vector_iter, end_vector_iter;
 
   mesh_info.num_nodes = 0;
   mesh_info.num_elements = 0;
@@ -235,7 +237,7 @@
 
   mesh_info.num_matsets = matsets.size();
 
-  std::vector<MBEntityHandle> parent_meshsets;
+  std::vector<EntityHandle> parent_meshsets;
 
   // clean out the bits for the element mark
   mbImpl->tag_delete(mEntityMark);
@@ -247,18 +249,18 @@
   {
        
     WriteTEMPLATE::MaterialSetData matset_data;
-    matset_data.elements = new MBRange;
+    matset_data.elements = new Range;
 
     //for the purpose of qa records, get the parents of these matsets 
     if( mbImpl->get_parent_meshsets( *vector_iter, parent_meshsets ) != MB_SUCCESS )
       return MB_FAILURE;
 
     // get all Entity Handles in the mesh set
-    MBRange dummy_range;
+    Range dummy_range;
     mbImpl->get_entities_by_handle(*vector_iter, dummy_range, true );
 
       // find the dimension of the last entity in this range
-    MBRange::iterator entity_iter = dummy_range.end();
+    Range::iterator entity_iter = dummy_range.end();
     entity_iter = dummy_range.end();
     entity_iter--;
     int this_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*entity_iter));
@@ -268,7 +270,7 @@
       entity_iter++;
     
     if (entity_iter != dummy_range.end())
-      std::copy(entity_iter, dummy_range.end(), mb_range_inserter(*(matset_data.elements)));
+      std::copy(entity_iter, dummy_range.end(), range_inserter(*(matset_data.elements)));
 
     assert(matset_data.elements->begin() == matset_data.elements->end() ||
            MBCN::Dimension(TYPE_FROM_HANDLE(*(matset_data.elements->begin()))) == this_dim);
@@ -283,13 +285,13 @@
     matset_data.number_attributes = 0;
  
      // iterate through all the elements in the meshset
-    MBRange::iterator elem_range_iter, end_elem_range_iter;
+    Range::iterator elem_range_iter, end_elem_range_iter;
     elem_range_iter = matset_data.elements->begin();
     end_elem_range_iter = matset_data.elements->end();
 
       // get the entity type for this matset, verifying that it's the same for all elements
       // THIS ASSUMES HANDLES SORT BY TYPE!!!
-    MBEntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
+    EntityType entity_type = TYPE_FROM_HANDLE(*elem_range_iter);
     end_elem_range_iter--;
     if (entity_type != TYPE_FROM_HANDLE(*(end_elem_range_iter++))) {
       mWriteIface->report_error("Entities in matset %i not of common type", id);
@@ -304,7 +306,7 @@
     matset_data.moab_type = mbImpl->type_from_handle(*(matset_data.elements->begin()));
     if (MBMAXTYPE == matset_data.moab_type) return MB_FAILURE;
     
-    std::vector<MBEntityHandle> tmp_conn;
+    std::vector<EntityHandle> tmp_conn;
     mbImpl->get_connectivity(&(*(matset_data.elements->begin())), 1, tmp_conn);
     matset_data.element_type = 
       ExoIIUtil::get_element_type_from_num_verts(tmp_conn.size(), entity_type, dimension);
@@ -328,7 +330,7 @@
     if(!neusets.empty())
     {
       // if there are neusets, keep track of which elements are being written out
-      for(MBRange::iterator iter = matset_data.elements->begin(); 
+      for(Range::iterator iter = matset_data.elements->begin(); 
           iter != matset_data.elements->end(); ++iter)
       {
         unsigned char bit = 0x1;
@@ -351,7 +353,7 @@
       mesh_info.num_dim = highest_dimension_of_element_matsets;
   }
 
-  MBRange::iterator range_iter, end_range_iter;
+  Range::iterator range_iter, end_range_iter;
   range_iter = mesh_info.nodes.begin();
   end_range_iter = mesh_info.nodes.end();
 
@@ -377,20 +379,20 @@
     
     dirset_data.id = id; 
 
-    std::vector<MBEntityHandle> node_vector;
+    std::vector<EntityHandle> node_vector;
     //get the nodes of the dirset that are in mesh_info.nodes
     if( mbImpl->get_entities_by_handle(*vector_iter, node_vector, true) != MB_SUCCESS ) {
       mWriteIface->report_error("Couldn't get nodes in dirset %i", id);
       return MB_FAILURE;
     }
 
-    std::vector<MBEntityHandle>::iterator iter, end_iter;
+    std::vector<EntityHandle>::iterator iter, end_iter;
     iter = node_vector.begin();
     end_iter= node_vector.end();
  
     int j=0; 
     unsigned char node_marked = 0;
-    MBErrorCode result;
+    ErrorCode result;
     for(; iter != end_iter; iter++)
     {
       if (TYPE_FROM_HANDLE(*iter) != MBVERTEX) continue;
@@ -425,11 +427,11 @@
  
     //get the sides in two lists, one forward the other reverse; starts with forward sense
       // by convention
-    MBRange forward_elems, reverse_elems;
+    Range forward_elems, reverse_elems;
     if(get_neuset_elems(*vector_iter, 0, forward_elems, reverse_elems) == MB_FAILURE)
       return MB_FAILURE;
 
-    MBErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
+    ErrorCode result = get_valid_sides(forward_elems, 1, neuset_data);
     if (MB_SUCCESS != result) {
       mWriteIface->report_error("Couldn't get valid sides data.");
       return result;
@@ -447,14 +449,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteTEMPLATE::get_valid_sides(MBRange &elems, const int sense,
+ErrorCode WriteTEMPLATE::get_valid_sides(Range &elems, const int sense,
                                            WriteTEMPLATE::NeumannSetData &neuset_data) 
 {
     // this is where we see if underlying element of side set element is included in output 
 
   unsigned char element_marked = 0;
-  MBErrorCode result;
-  for(MBRange::iterator iter = elems.begin(); iter != elems.end(); iter++)
+  ErrorCode result;
+  for(Range::iterator iter = elems.begin(); iter != elems.end(); iter++)
   {
       // should insert here if "side" is a quad/tri on a quad/tri mesh
     result = mbImpl->tag_get_data(mEntityMark, &(*iter), 1, &element_marked);
@@ -472,7 +474,7 @@
     }
     else //then "side" is probably a quad/tri on a hex/tet mesh
     {
-      std::vector<MBEntityHandle> parents;
+      std::vector<EntityHandle> parents;
       int dimension = MBCN::Dimension( TYPE_FROM_HANDLE(*iter));
 
         //get the adjacent parent element of "side"
@@ -514,11 +516,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteTEMPLATE::write_nodes(const int num_nodes, const MBRange& nodes, const int dimension)
+ErrorCode WriteTEMPLATE::write_nodes(const int num_nodes, const Range& nodes, const int dimension)
 {
   //see if should transform coordinates
-  MBErrorCode result;
-  MBTag trans_tag;
+  ErrorCode result;
+  Tag trans_tag;
   result = mbImpl->tag_get_handle( MESH_TRANSFORM_TAG_NAME, trans_tag);
   bool transform_needed = true;
   if( result == MB_TAG_NOT_FOUND )
@@ -594,20 +596,20 @@
 
 }
 
-MBErrorCode WriteTEMPLATE::write_matsets(MeshInfo & /* mesh_info (commented out to remove warning) */,
+ErrorCode WriteTEMPLATE::write_matsets(MeshInfo & /* mesh_info (commented out to remove warning) */,
                                          std::vector<WriteTEMPLATE::MaterialSetData> &matset_data,
                                          std::vector<WriteTEMPLATE::NeumannSetData> &/* neuset_data (commented out to remove warning) */)
 {
 
   unsigned int i;
   std::vector<int> connect;
-  const MBEntityHandle *connecth;
+  const EntityHandle *connecth;
   int num_connecth;
-  MBErrorCode result;
+  ErrorCode result;
   
     // don't usually have anywhere near 31 nodes per element
   connect.reserve(31);
-  MBRange::iterator rit;
+  Range::iterator rit;
 
   WriteTEMPLATE::MaterialSetData matset;
   for (i = 0; i < matset_data.size(); i++) {
@@ -638,7 +640,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteTEMPLATE::initialize_file(MeshInfo &mesh_info)
+ErrorCode WriteTEMPLATE::initialize_file(MeshInfo &mesh_info)
 {
     // perform the initializations
 
@@ -660,7 +662,7 @@
 }
 
 
-MBErrorCode WriteTEMPLATE::open_file(const char* filename)
+ErrorCode WriteTEMPLATE::open_file(const char* filename)
 {
    // not a valid filname
    if(strlen((const char*)filename) == 0)
@@ -680,28 +682,28 @@
    return MB_SUCCESS;
 }
 
-MBErrorCode WriteTEMPLATE::get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                                        MBRange &forward_elems, MBRange &reverse_elems) 
+ErrorCode WriteTEMPLATE::get_neuset_elems(EntityHandle neuset, int current_sense,
+                                        Range &forward_elems, Range &reverse_elems) 
 {
-  MBRange neuset_elems, neuset_meshsets;
+  Range neuset_elems, neuset_meshsets;
 
     // get the sense tag; don't need to check return, might be an error if the tag
     // hasn't been created yet
-  MBTag sense_tag = 0;
+  Tag sense_tag = 0;
   mbImpl->tag_get_handle("SENSE", sense_tag);
 
     // get the entities in this set
-  MBErrorCode result = mbImpl->get_entities_by_handle(neuset, neuset_elems, true);
+  ErrorCode result = mbImpl->get_entities_by_handle(neuset, neuset_elems, true);
   if (MB_FAILURE == result) return result;
   
     // now remove the meshsets into the neuset_meshsets; first find the first meshset,
-  MBRange::iterator range_iter = neuset_elems.begin();
+  Range::iterator range_iter = neuset_elems.begin();
   while (TYPE_FROM_HANDLE(*range_iter) != MBENTITYSET && range_iter != neuset_elems.end())
     range_iter++;
   
     // then, if there are some, copy them into neuset_meshsets and erase from neuset_elems
   if (range_iter != neuset_elems.end()) {
-    std::copy(range_iter, neuset_elems.end(), mb_range_inserter(neuset_meshsets));
+    std::copy(range_iter, neuset_elems.end(), range_inserter(neuset_meshsets));
     neuset_elems.erase(range_iter, neuset_elems.end());
   }
   
@@ -710,7 +712,7 @@
     // (if the sense is 0, copy into both ranges)
 
     // need to step forward on list until we reach the right dimension
-  MBRange::iterator dum_it = neuset_elems.end();
+  Range::iterator dum_it = neuset_elems.end();
   dum_it--;
   int target_dim = MBCN::Dimension(TYPE_FROM_HANDLE(*dum_it));
   dum_it = neuset_elems.begin();
@@ -719,9 +721,9 @@
     dum_it++;
 
   if (current_sense == 1 || current_sense == 0)
-    std::copy(dum_it, neuset_elems.end(), mb_range_inserter(forward_elems));
+    std::copy(dum_it, neuset_elems.end(), range_inserter(forward_elems));
   if (current_sense == -1 || current_sense == 0)
-    std::copy(dum_it, neuset_elems.end(), mb_range_inserter(reverse_elems));
+    std::copy(dum_it, neuset_elems.end(), range_inserter(reverse_elems));
   
     // now loop over the contained meshsets, getting the sense of those and calling this
     // function recursively
@@ -741,5 +743,6 @@
   return result;
 }
 
+} // namespace moab
 
   

Modified: MOAB/trunk/src/io/WriteTemplate.hpp
===================================================================
--- MOAB/trunk/src/io/WriteTemplate.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteTemplate.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,34 +37,36 @@
 #include <vector>
 #include <string>
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "ExoIIInterface.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/ExoIIInterface.hpp"
+#include "moab/WriterIface.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
-class MB_DLL_EXPORT WriteTEMPLATE : public MBWriterIface
+class WriteUtilIface;
+
+class MB_DLL_EXPORT WriteTEMPLATE : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteTEMPLATE(MBInterface *impl);
+   WriteTEMPLATE(Interface *impl);
 
    //! Destructor
   virtual ~WriteTEMPLATE();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                          const MBEntityHandle *output_list,
+                          const EntityHandle *output_list,
                           const int num_sets,
                           const std::vector<std::string>& qa_list,
-                          const MBTag* tag_list,
+                          const Tag* tag_list,
                           int num_tags,
                           int export_dimension);
   
@@ -77,8 +79,8 @@
     int number_nodes_per_element;
     int number_attributes;
     ExoIIElementType element_type;
-    MBEntityType moab_type;
-    MBRange *elements;
+    EntityType moab_type;
+    Range *elements;
   };
 
 //! struct used to hold data for each nodeset to be output; used by
@@ -87,7 +89,7 @@
   {
     int id;
     int number_nodes;
-    std::vector< MBEntityHandle > nodes;
+    std::vector< EntityHandle > nodes;
     std::vector< double > node_dist_factors;
   
   };
@@ -98,9 +100,9 @@
   {
     int id;
     int number_elements;
-    std::vector<MBEntityHandle> elements;
+    std::vector<EntityHandle> elements;
     std::vector<int> side_numbers;
-    MBEntityHandle mesh_set_handle;
+    EntityHandle mesh_set_handle;
   };
 
 
@@ -110,7 +112,7 @@
   //int number_dimensions();
 
     //! open a file for writing
-  MBErrorCode open_file(const char *filename);
+  ErrorCode open_file(const char *filename);
 
   //! contains the general information about a mesh
   class MeshInfo
@@ -122,7 +124,7 @@
     unsigned int num_matsets;
     unsigned int num_dirsets;
     unsigned int num_neusets;
-    MBRange nodes;
+    Range nodes;
 
     MeshInfo() 
         : num_dim(0), num_nodes(0), num_elements(0), num_matsets(0), 
@@ -134,51 +136,53 @@
 private:
 
     //! interface instance
-  MBInterface *mbImpl;
-  MBWriteUtilIface* mWriteIface;
+  Interface *mbImpl;
+  WriteUtilIface* mWriteIface;
   
     //! file name
   std::string fileName;
 
     //! Meshset Handle for the mesh that is currently being read
-  MBEntityHandle mCurrentMeshHandle;
+  EntityHandle mCurrentMeshHandle;
 
   //! Cached tags for reading.  Note that all these tags are defined when the
   //! core is initialized.
-  MBTag mMaterialSetTag;
-  MBTag mDirichletSetTag;
-  MBTag mNeumannSetTag;
-  MBTag mHasMidNodesTag;
-  MBTag mGlobalIdTag;
-  MBTag mMatSetIdTag;
+  Tag mMaterialSetTag;
+  Tag mDirichletSetTag;
+  Tag mNeumannSetTag;
+  Tag mHasMidNodesTag;
+  Tag mGlobalIdTag;
+  Tag mMatSetIdTag;
 
-  MBTag mEntityMark;   //used to say whether an entity will be exported
+  Tag mEntityMark;   //used to say whether an entity will be exported
 
-  MBErrorCode gather_mesh_information(MeshInfo &mesh_info,
+  ErrorCode gather_mesh_information(MeshInfo &mesh_info,
                                       std::vector<MaterialSetData> &matset_info,
                                       std::vector<NeumannSetData> &neuset_info,
                                       std::vector<DirichletSetData> &dirset_info,
-                                      std::vector<MBEntityHandle> &matsets,
-                                      std::vector<MBEntityHandle> &neusets,
-                                      std::vector<MBEntityHandle> &dirsets);
+                                      std::vector<EntityHandle> &matsets,
+                                      std::vector<EntityHandle> &neusets,
+                                      std::vector<EntityHandle> &dirsets);
   
-  MBErrorCode initialize_file(MeshInfo &mesh_info);
+  ErrorCode initialize_file(MeshInfo &mesh_info);
 
-  MBErrorCode write_nodes(const int num_nodes, const MBRange& nodes, 
+  ErrorCode write_nodes(const int num_nodes, const Range& nodes, 
                           const int dimension );
 
-  MBErrorCode write_matsets(MeshInfo &mesh_info, 
+  ErrorCode write_matsets(MeshInfo &mesh_info, 
                             std::vector<MaterialSetData> &matset_data,
                             std::vector<NeumannSetData> &neuset_data);
   
-  MBErrorCode get_valid_sides(MBRange &elems, const int sense,
+  ErrorCode get_valid_sides(Range &elems, const int sense,
                               WriteTEMPLATE::NeumannSetData &neuset_data);
   
   void reset_matset(std::vector<MaterialSetData> &matset_info);
   
-  MBErrorCode get_neuset_elems(MBEntityHandle neuset, int current_sense,
-                               MBRange &forward_elems, MBRange &reverse_elems);
+  ErrorCode get_neuset_elems(EntityHandle neuset, int current_sense,
+                               Range &forward_elems, Range &reverse_elems);
   
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/WriteVtk.cpp
===================================================================
--- MOAB/trunk/src/io/WriteVtk.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteVtk.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -34,50 +34,52 @@
 #include <set>
 #include <iterator>
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
-#include "MBTagConventions.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MBInternals.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "Internals.hpp"
 #include "FileOptions.hpp"
-#include "MBVersion.h"
+#include "moab/Version.h"
 
 #define INS_ID(stringvar, prefix, id) \
 sprintf(stringvar, prefix, id)
 
+namespace moab {
+
 const int DEFAULT_PRECISION = 10;
 const bool DEFAULT_STRICT = true;
 
-MBWriterIface *WriteVtk::factory( MBInterface* iface )
+WriterIface *WriteVtk::factory( Interface* iface )
   { return new WriteVtk( iface ); }
 
-WriteVtk::WriteVtk(MBInterface *impl) 
+WriteVtk::WriteVtk(Interface *impl) 
     : mbImpl(impl), writeTool(0), mStrict(DEFAULT_STRICT)
 {
   assert(impl != NULL);
 
   void* ptr = 0;
-  impl->query_interface( "MBWriteUtilIface", &ptr );
-  writeTool = reinterpret_cast<MBWriteUtilIface*>(ptr);
+  impl->query_interface( "WriteUtilIface", &ptr );
+  writeTool = reinterpret_cast<WriteUtilIface*>(ptr);
 }
 
 WriteVtk::~WriteVtk() 
 {
-  mbImpl->release_interface("MBWriteUtilIface", writeTool);
+  mbImpl->release_interface("WriteUtilIface", writeTool);
 }
 
-MBErrorCode WriteVtk::write_file(const char *file_name, 
+ErrorCode WriteVtk::write_file(const char *file_name, 
                                  const bool overwrite,
                                  const FileOptions& opts,
-                                 const MBEntityHandle *output_list,
+                                 const EntityHandle *output_list,
                                  const int num_sets,
                                  const std::vector<std::string>& ,
-                                 const MBTag* tag_list,
+                                 const Tag* tag_list,
                                  int num_tags,
                                  int )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // Get precision for node coordinates
   int precision;
@@ -92,7 +94,7 @@
     mStrict = DEFAULT_STRICT;
   
     // Get entities to write
-  MBRange nodes, elems;
+  Range nodes, elems;
   rval = gather_mesh( output_list, num_sets, nodes, elems );
   if (MB_SUCCESS != rval)
     return rval;
@@ -130,21 +132,21 @@
 }
 
 
-MBErrorCode WriteVtk::gather_mesh( const MBEntityHandle* set_list,
+ErrorCode WriteVtk::gather_mesh( const EntityHandle* set_list,
                                    int num_sets, 
-                                   MBRange& nodes,
-                                   MBRange& elems )
+                                   Range& nodes,
+                                   Range& elems )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int e;
   
   if (!set_list || !num_sets)
   {
-    MBRange a;
+    Range a;
     rval = mbImpl->get_entities_by_handle( 0, a );
     if (MB_SUCCESS != rval) return rval;
 
-    MBRange::const_iterator node_i, elem_i, set_i;
+    Range::const_iterator node_i, elem_i, set_i;
     node_i = a.lower_bound( a.begin(), a.end(), CREATE_HANDLE(    MBVERTEX, 0, e ) );
     elem_i = a.lower_bound(    node_i, a.end(), CREATE_HANDLE(      MBEDGE, 0, e ) );
     set_i  = a.lower_bound(    elem_i, a.end(), CREATE_HANDLE( MBENTITYSET, 0, e ) );
@@ -152,10 +154,10 @@
     elems.merge( elem_i, set_i );
 
       // filter out unsupported element types
-    MBEntityType et = MBEDGE;
+    EntityType et = MBEDGE;
     for (et++; et < MBENTITYSET; et++) {
       if (VtkUtil::get_vtk_type(et, MBCN::VerticesPerEntity(et))) continue;
-      MBRange::iterator 
+      Range::iterator 
         eit = elems.lower_bound(elems.begin(), elems.end(), CREATE_HANDLE(et, 0, e)),
         ep1it = elems.lower_bound(elems.begin(), elems.end(), CREATE_HANDLE(et+1, 0, e));
       elems.erase(eit, ep1it);
@@ -163,23 +165,23 @@
   }
   else
   {
-    std::set<MBEntityHandle> visited;
-    std::vector<MBEntityHandle> sets;
+    std::set<EntityHandle> visited;
+    std::vector<EntityHandle> sets;
     sets.reserve(num_sets);
     std::copy( set_list, set_list + num_sets, std::back_inserter(sets) );
     while (!sets.empty()) {
         // get next set
-      MBEntityHandle set = sets.back();
+      EntityHandle set = sets.back();
       sets.pop_back();
         // skip sets we've already done
       if (!visited.insert(set).second)
         continue;
       
-      MBRange a;
+      Range a;
       rval = mbImpl->get_entities_by_handle( set, a );
       if (MB_SUCCESS != rval) return rval;
       
-      MBRange::const_iterator node_i, elem_i, set_i;
+      Range::const_iterator node_i, elem_i, set_i;
       node_i = a.lower_bound( a.begin(), a.end(), CREATE_HANDLE(    MBVERTEX, 0, e ) );
       elem_i = a.lower_bound(    node_i, a.end(), CREATE_HANDLE(      MBEDGE, 0, e ) );
       set_i  = a.lower_bound(    elem_i, a.end(), CREATE_HANDLE( MBENTITYSET, 0, e ) );
@@ -192,9 +194,9 @@
       std::copy( a.begin(), a.end(), std::back_inserter(sets) );
     }
     
-    for (MBRange::const_iterator e = elems.begin(); e != elems.end(); ++e)
+    for (Range::const_iterator e = elems.begin(); e != elems.end(); ++e)
     {
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       int conn_len;
       rval = mbImpl->get_connectivity( *e, conn, conn_len );
       if (MB_SUCCESS != rval) return rval;
@@ -213,7 +215,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteVtk::write_header( std::ostream& stream )
+ErrorCode WriteVtk::write_header( std::ostream& stream )
 {
   stream << "# vtk DataFile Version 3.0" << std::endl;
   stream << MB_VERSION_STRING << std::endl;
@@ -223,14 +225,14 @@
 }
 
 
-MBErrorCode WriteVtk::write_nodes( std::ostream& stream, const MBRange& nodes )
+ErrorCode WriteVtk::write_nodes( std::ostream& stream, const Range& nodes )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   stream << "POINTS " << nodes.size() << " double" << std::endl;
   
   double coords[3];
-  for (MBRange::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
+  for (Range::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
     coords[1] = coords[2] = 0.0;
     rval = mbImpl->get_coords( &*i, 1, coords );
     if (MB_SUCCESS != rval)
@@ -241,20 +243,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteVtk::write_elems( std::ostream& stream, 
-                                   const MBRange& nodes,
-                                   const MBRange& elems )
+ErrorCode WriteVtk::write_elems( std::ostream& stream, 
+                                   const Range& nodes,
+                                   const Range& elems )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
   // Get and write counts
   unsigned long num_elems, num_uses;
   num_elems = num_uses = elems.size();
-  for (MBRange::const_iterator i = elems.begin(); i != elems.end(); ++i)
+  for (Range::const_iterator i = elems.begin(); i != elems.end(); ++i)
   {
-    MBEntityType type = mbImpl->type_from_handle(*i);
+    EntityType type = mbImpl->type_from_handle(*i);
     if (!VtkUtil::get_vtk_type(type, MBCN::VerticesPerEntity(type))) continue;
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int conn_len;
     rval = mbImpl->get_connectivity( *i, conn, conn_len );
     if (MB_SUCCESS != rval)
@@ -267,13 +269,13 @@
   std::vector<int> conn_data;
   std::vector<unsigned> vtk_types( elems.size() );
   std::vector<unsigned>::iterator t = vtk_types.begin();
-  for (MBRange::const_iterator i = elems.begin(); i != elems.end(); ++i)
+  for (Range::const_iterator i = elems.begin(); i != elems.end(); ++i)
   {
       // Get type information for element
-    MBEntityType type = TYPE_FROM_HANDLE(*i);
+    EntityType type = TYPE_FROM_HANDLE(*i);
 
       // Get element connectivity
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int conn_len;
     rval = mbImpl->get_connectivity( *i, conn, conn_len );
     if (MB_SUCCESS != rval)
@@ -319,13 +321,13 @@
 
 
 
-MBErrorCode WriteVtk::write_tags( std::ostream& stream, 
+ErrorCode WriteVtk::write_tags( std::ostream& stream, 
                                   bool nodes, 
-                                  const MBRange& entities,
-                                  const MBTag* tag_list,
+                                  const Range& entities,
+                                  const Tag* tag_list,
                                   int num_tags )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // The #$%@#$% MOAB interface does not have a function to retreive
     // all entities with a tag, only all entities with a specified type
@@ -334,7 +336,7 @@
     // to have the implementation subdivide the results by type and have
     // to call that function once for each type just to recombine the results.
     // Unfortunamtely, there doesn't seem to be any other way.
-  MBEntityType low_type, high_type;
+  EntityType low_type, high_type;
   if (nodes) 
   {
     low_type = MBVERTEX;
@@ -347,18 +349,18 @@
   }
 
     // Get all defined tags
-  std::vector<MBTag> tags;
-  std::vector<MBTag>::iterator i;
+  std::vector<Tag> tags;
+  std::vector<Tag>::iterator i;
   rval = writeTool->get_tag_list( tags, tag_list, num_tags, false );
   if (MB_SUCCESS != rval)
     return rval;
   
     // For each tag...  
   bool entities_have_tags = false;
-  for (std::vector<MBTag>::iterator i = tags.begin(); i != tags.end(); ++i)
+  for (std::vector<Tag>::iterator i = tags.begin(); i != tags.end(); ++i)
   {
       // Skip tags holding entity handles -- no way to save them
-    MBDataType type;
+    DataType type;
     rval = mbImpl->tag_get_data_type( *i, type );
     if (MB_SUCCESS != rval)
       return rval;
@@ -366,7 +368,7 @@
       continue;
       
       // Get size.  Variable-length tags should have been filtered
-      // out by MBWriteUtil already.
+      // out by WriteUtil already.
     int size;
     rval = mbImpl->tag_get_size( *i, size );
     if (MB_SUCCESS != rval)
@@ -396,10 +398,10 @@
           
     
       // Get subset of input entities that have the tag set
-    MBRange tagged;
-    for (MBEntityType type = low_type; type < high_type; ++type)
+    Range tagged;
+    for (EntityType type = low_type; type < high_type; ++type)
     {
-      MBRange tmp_tagged;
+      Range tmp_tagged;
       rval = mbImpl->get_entities_by_type_and_tag( 0, type, &*i, 0, 1, tmp_tagged );
       if (MB_SUCCESS != rval)
         return rval;
@@ -470,10 +472,10 @@
 
 
 template <typename T>
-MBErrorCode WriteVtk::write_tag( std::ostream& stream, MBTag tag, const MBRange& entities, const MBRange& tagged,
+ErrorCode WriteVtk::write_tag( std::ostream& stream, Tag tag, const Range& entities, const Range& tagged,
                                  const int)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   const unsigned long n = entities.size();
   
     // Get tag properties  
@@ -496,9 +498,9 @@
     // the entities that actually have the tag set.
   std::vector<T> data;
   data.resize( n * vals_per_tag, 0 );
-  MBRange::const_iterator t = tagged.begin();
+  Range::const_iterator t = tagged.begin();
   typename std::vector<T>::iterator d = data.begin();
-  for (MBRange::const_iterator i = entities.begin(); 
+  for (Range::const_iterator i = entities.begin(); 
        i != entities.end() && t != tagged.end(); ++i, d += vals_per_tag)
   {
     if (*i == *t)
@@ -516,12 +518,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteVtk::write_bit_tag( std::ostream& stream, 
-                                     MBTag tag, 
-                                     const MBRange& entities, 
-                                     const MBRange& tagged )
+ErrorCode WriteVtk::write_bit_tag( std::ostream& stream, 
+                                     Tag tag, 
+                                     const Range& entities, 
+                                     const Range& tagged )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   const unsigned long n = entities.size();
   
     // Get tag properties  
@@ -544,9 +546,9 @@
     // those entities for which the tag is not set.
   std::vector<unsigned short> data;
   data.resize( n * vals_per_tag, 0 );
-  MBRange::const_iterator t = tagged.begin();
+  Range::const_iterator t = tagged.begin();
   std::vector<unsigned short>::iterator d = data.begin();
-  for (MBRange::const_iterator i = entities.begin(); 
+  for (Range::const_iterator i = entities.begin(); 
        i != entities.end() && t != tagged.end(); ++i)
   {
     if (*i == *t)
@@ -572,13 +574,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteVtk::write_tag( std::ostream& s, MBTag tag,
-                                 const MBRange& entities,
-                                 const MBRange& tagged )
+ErrorCode WriteVtk::write_tag( std::ostream& s, Tag tag,
+                                 const Range& entities,
+                                 const Range& tagged )
 {
     // Get tag properties
   std::string name;
-  MBDataType type;
+  DataType type;
   int size;
   if (MB_SUCCESS != mbImpl->tag_get_name( tag, name ) ||
       MB_SUCCESS != mbImpl->tag_get_size( tag, size ) ||
@@ -632,4 +634,4 @@
   }
 }
 
-  
+} // namespace moab

Modified: MOAB/trunk/src/io/WriteVtk.hpp
===================================================================
--- MOAB/trunk/src/io/WriteVtk.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/WriteVtk.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -19,76 +19,80 @@
 
 #include <iosfwd>
 
-#include "MBForward.hpp"
-#include "MBWriterIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/WriterIface.hpp"
 
-class MBWriteUtilIface;
+namespace moab {
 
-//class MB_DLL_EXPORT WriteVtk : public MBWriterIface
-class WriteVtk : public MBWriterIface
+class WriteUtilIface;
+
+//class MB_DLL_EXPORT WriteVtk : public WriterIface
+class WriteVtk : public WriterIface
 {
  
 public:
 
    //! Constructor
-   WriteVtk(MBInterface *impl);
+   WriteVtk(Interface *impl);
 
    //! Destructor
   virtual ~WriteVtk();
   
-  static MBWriterIface* factory( MBInterface* );
+  static WriterIface* factory( Interface* );
 
     //! writes out a file
-  MBErrorCode write_file(const char *file_name,
+  ErrorCode write_file(const char *file_name,
                          const bool overwrite,
                          const FileOptions& opts,
-                         const MBEntityHandle *output_list,
+                         const EntityHandle *output_list,
                          const int num_sets,
                          const std::vector<std::string>& qa_list,
-                         const MBTag* tag_list,
+                         const Tag* tag_list,
                          int num_tags,
                          int export_dimension);
 
 private:
 
     //! Get entities to write, given set list passed to \ref write_file
-  MBErrorCode gather_mesh( const MBEntityHandle* set_list,
+  ErrorCode gather_mesh( const EntityHandle* set_list,
                            int num_sets, 
-                           MBRange& nodes,
-                           MBRange& elems );
+                           Range& nodes,
+                           Range& elems );
     
     //! Write 4-line VTK file header
-  MBErrorCode write_header( std::ostream& stream );
+  ErrorCode write_header( std::ostream& stream );
   
     //! Write node coordinates
-  MBErrorCode write_nodes( std::ostream& stream, const MBRange& nodes );
+  ErrorCode write_nodes( std::ostream& stream, const Range& nodes );
   
     //! Write element connectivity
-  MBErrorCode write_elems( std::ostream& stream, const MBRange& nodes, const MBRange& elems );
+  ErrorCode write_elems( std::ostream& stream, const Range& nodes, const Range& elems );
   
     //! Write all tags on either the list of nodes or the list of elements
-  MBErrorCode write_tags( std::ostream& stream, bool nodes, const MBRange& entities,
-                          const MBTag* tag_list, int num_tags );
+  ErrorCode write_tags( std::ostream& stream, bool nodes, const Range& entities,
+                          const Tag* tag_list, int num_tags );
   
     //! Write the tad description for the passed tag and call the template
     //! \ref write_tag function to write the tag data.
-  MBErrorCode write_tag( std::ostream& stream, MBTag tag, const MBRange& entities, const MBRange& tagged_entities );
+  ErrorCode write_tag( std::ostream& stream, Tag tag, const Range& entities, const Range& tagged_entities );
   
     //! Write tag data
   template <typename T> 
-  MBErrorCode write_tag( std::ostream& stream, MBTag tag, const MBRange& entities, const MBRange& tagged_entities,
+  ErrorCode write_tag( std::ostream& stream, Tag tag, const Range& entities, const Range& tagged_entities,
                          const int);
 
-  MBErrorCode write_bit_tag( std::ostream& stream, MBTag tag, const MBRange& entities, const MBRange& tagged_entities );
+  ErrorCode write_bit_tag( std::ostream& stream, Tag tag, const Range& entities, const Range& tagged_entities );
     //! Write a list of values
   template <typename T>
   void write_data( std::ostream& stream, const std::vector<T>& data, unsigned vals_per_tag );
 
-  MBInterface* mbImpl;
-  MBWriteUtilIface* writeTool;
+  Interface* mbImpl;
+  WriteUtilIface* writeTool;
  
   bool mStrict; // If true, do not write data that cannot fit in strict VTK file format.
   
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/io/exodus_order.h
===================================================================
--- MOAB/trunk/src/io/exodus_order.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/exodus_order.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,6 +5,7 @@
 
 #ifdef __cplusplus
 extern "C" {
+namespace moab {
 #endif
 
 /* Cubit writes ExodusII files with tet mid-face nodes in this order */
@@ -41,6 +42,7 @@
 
 #ifdef __cplusplus
 } /*  extern "C" */
+} /* namespace moab */
 #endif
 
 #endif

Modified: MOAB/trunk/src/io/mhdf/include/mhdf.h
===================================================================
--- MOAB/trunk/src/io/mhdf/include/mhdf.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/mhdf/include/mhdf.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -529,7 +529,7 @@
  * Add a element group to the file. 
  * An element group is the data for a block of elements with the same 
  * TSTT type and same number of nodes in their connectivity data.
- * (e.g. all the HEX20 elements).  This function is also
+ * (e.g. all the MBHEX20 elements).  This function is also
  * used to create the groups for general polygon data and
  * general polyhedron data.  The requirement that all elements
  * have the same number of nodes in their connectivity does not
@@ -558,7 +558,7 @@
  * Get the list of element groups in the file.
  * An element group is the data for a block of elements with the same 
  * TSTT type and same number of nodes in their connectivity data.
- * (e.g. all the HEX20 elements).  This function is also
+ * (e.g. all the MBHEX20 elements).  This function is also
  * used to retrieve the groups for general polygon data and
  * general polyhedron data.  The requirement that all elements
  * have the same number of nodes in their connectivity does not

Modified: MOAB/trunk/src/io/moab/ExoIIInterface.hpp
===================================================================
--- MOAB/trunk/src/io/moab/ExoIIInterface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/moab/ExoIIInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,9 +14,13 @@
  */
 
 
-#ifndef EXOII_INTERFACE_HPP
-#define EXOII_INTERFACE_HPP
+#ifndef MOAB_EXOII_INTERFACE_HPP
+#define MOAB_EXOII_INTERFACE_HPP
 
+#include "moab/Types.hpp"
+
+namespace moab {
+
 enum ExoIIElementType
 {
   EXOII_SPHERE = 0,
@@ -37,14 +41,15 @@
 };
 
 
-#define MAX_STR_LENGTH 33
-#define MAX_LINE_LENGTH 80
-
-#include "MBTypes.h"
-
 class MB_DLL_EXPORT ExoIIInterface
 {
 public:
+  enum {
+    MAX_STR_LENGTH = 33,
+    MAX_LINE_LENGTH = 80
+  };
+
+
   ExoIIInterface(){}
   virtual ~ExoIIInterface(){}
       
@@ -54,8 +59,8 @@
   //! get the element type of the entity; this entity can either be a meshset, 
   //! in which case it will be assumed to be a material set meshset, or an 
   //! individual entity.
-  virtual  ExoIIElementType get_element_type(MBEntityHandle entity,
-      MBTag mid_nodes_tag, MBTag geom_dimension_tag, MBEntityType indiv_entity_type = MBMAXTYPE) = 0;
+  virtual  ExoIIElementType get_element_type(EntityHandle entity,
+      Tag mid_nodes_tag, Tag geom_dimension_tag, EntityType indiv_entity_type = MBMAXTYPE) = 0;
 
   virtual int has_mid_nodes(ExoIIElementType elem_type, int dimension) = 0;
   virtual void has_mid_nodes(ExoIIElementType elem_type, int* array) = 0;
@@ -67,6 +72,7 @@
   
 };
 
+} // namespace moab
 
 #endif
 

Modified: MOAB/trunk/src/io/patran_order.h
===================================================================
--- MOAB/trunk/src/io/patran_order.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/io/patran_order.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,6 +3,7 @@
 
 #ifdef __cplusplus
 extern "C" {
+namespace moab {
 #endif
 
 /* Define maps that, when indexed by the PATRAN connectivity index return
@@ -85,7 +86,7 @@
                                         0, 0, 0, 0, 0, 0, 0, 0, 
                                         0 };
 
-/* Define matrix of maps indexed by element topology (MBEntityType) and
+/* Define matrix of maps indexed by element topology (EntityType) and
    number of nodes. Entries are NULL where MBCN connectivity
    is the same as PATRAN (or the number of nodes is invalid.) */
 
@@ -106,6 +107,7 @@
 
 #ifdef __cplusplus
 } /*  extern "C" */
+} /* namespace moab */
 #endif
 
 #endif

Copied: MOAB/trunk/src/moab/AdaptiveKDTree.hpp (from rev 3583, MOAB/trunk/src/moab/MBAdaptiveKDTree.hpp)
===================================================================
--- MOAB/trunk/src/moab/AdaptiveKDTree.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/AdaptiveKDTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,421 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file AdaptiveKDTree.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2007-04-1
+ */
+
+#ifndef MOAB_ADAPTIVE_KD_TREE_HPP
+#define MOAB_ADAPTIVE_KD_TREE_HPP
+
+#include "moab/Types.hpp"
+
+#include <string>
+#include <vector>
+#include <math.h>
+
+namespace moab {
+
+class AdaptiveKDTreeIter;
+class Interface;
+class Range;
+
+class AdaptiveKDTree
+{
+private:
+
+  Interface* mbInstance;
+  Tag planeTag, axisTag, rootTag;
+  unsigned meshSetFlags;
+  bool cleanUpTrees;
+  std::vector<EntityHandle> createdTrees;
+  
+public:
+
+  AdaptiveKDTree( Interface* iface, 
+                    const char* tagname = 0,
+                    unsigned meshset_creation_flags = MESHSET_SET );
+
+  AdaptiveKDTree( Interface* iface, 
+                    bool destroy_created_trees,
+                    const char* tagname = 0,
+                    unsigned meshset_creation_flags = MESHSET_SET );
+
+  ~AdaptiveKDTree();
+
+  //! Enumeriate split plane directions
+  enum Axis { X = 0, Y = 1, Z = 2 };
+  
+  //! Split plane 
+  struct Plane {
+    double coord;  //!< Location of plane as coordinate on normal axis
+    int norm; //!< The principal axis that is the normal of the plane;
+    
+      /** return true if point is below/to the left of the split plane */
+    bool left_side( const double point[3] ) {
+      return point[norm] < coord;
+    }
+      /** return true if point is above/to the right of the split plane */
+    bool right_side( const double point[3] ) {
+      return point[norm] > coord;
+    }
+      /** return distance from point to plane */
+    double distance( const double point[3] ) const {
+      return fabs(point[norm] - coord);
+    }
+  };
+  
+  //! Get split plane for tree node
+  ErrorCode get_split_plane( EntityHandle node, Plane& plane );
+  
+  //! Set split plane for tree node
+  ErrorCode set_split_plane( EntityHandle node, const Plane& plane );
+  
+  //! Get bounding box for entire tree
+  ErrorCode get_tree_box( EntityHandle root_node,
+                            double box_min_out[3], 
+                            double box_max_out[3] );
+  
+  //! Set bounding box for entire tree
+  ErrorCode set_tree_box( EntityHandle root_node,
+                            const double box_min[3], 
+                            const double box_max[3] );
+  
+  //! Create tree root node
+  ErrorCode create_tree( const double box_min[3],
+                           const double box_max[3],
+                           EntityHandle& root_handle );
+
+  //! Find all tree roots
+  ErrorCode find_all_trees( Range& results );
+
+  //! Destroy a tree
+  ErrorCode delete_tree( EntityHandle root_handle );
+
+  Interface* moab() { return mbInstance; }
+
+  //! Get iterator for tree
+  ErrorCode get_tree_iterator( EntityHandle tree_root,
+                                 AdaptiveKDTreeIter& result );
+  
+  //! Get iterator at right-most ('last') leaf.
+  ErrorCode get_last_iterator( EntityHandle tree_root,
+                                 AdaptiveKDTreeIter& result );
+
+  //! Get iterator for tree or subtree
+  ErrorCode get_sub_tree_iterator( EntityHandle tree_root,
+                                     const double box_min[3], 
+                                     const double box_max[3],
+                                     AdaptiveKDTreeIter& result );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( AdaptiveKDTreeIter& leaf, Plane plane );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( AdaptiveKDTreeIter& leaf, 
+                          Plane plane,
+                          EntityHandle& left_child,
+                          EntityHandle& right_child );
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( AdaptiveKDTreeIter& leaf, 
+                          Plane plane,
+                          const Range& left_entities,
+                          const Range& right_entities );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( AdaptiveKDTreeIter& leaf, 
+                          Plane plane,
+                          const std::vector<EntityHandle>& left_entities,
+                          const std::vector<EntityHandle>& right_entities );
+  
+  //! Merge the leaf pointed to by the current iterator with it's
+  //! sibling.  If the sibling is not a leaf, multiple merges may
+  //! be done.
+  ErrorCode merge_leaf( AdaptiveKDTreeIter& iter );
+  
+    //! methods for selecting candidate split planes
+  enum CandidatePlaneSet {
+    //! Candidiate planes at evenly spaced intervals 
+    SUBDIVISION,
+    //! Like SUBDIVISION, except snap to closest vertex coordinate
+    SUBDIVISION_SNAP,
+    //! Median vertex coodinate values
+    VERTEX_MEDIAN,
+    //! Random sampling of vertex coordinate values
+    VERTEX_SAMPLE
+  };
+  
+    //! Settings used for tree construction
+  struct Settings {
+    Settings(); //!< initialize to defaults
+    unsigned maxEntPerLeaf; //!< split leafs with more entities than this
+    unsigned maxTreeDepth;  //!< limit on the depth of the tree
+    unsigned candidateSplitsPerDir; //!< number of cadiditate split planes to consider in each axial direction
+    CandidatePlaneSet candidatePlaneSet;
+    double minBoxWidth; //!< Tolerance
+  };
+  
+  //! Build a tree
+  ErrorCode build_tree( const Range& entities,
+                          EntityHandle& root_set_out,
+                          const Settings* settings = 0 );
+
+  ErrorCode depth( EntityHandle root,
+                     unsigned int& min_depth,
+                     unsigned int& max_depth );
+
+    //! get some information about the tree
+  ErrorCode get_info(EntityHandle root,
+                       double min[3], double max[3], 
+                       unsigned int &max_dep);
+  
+  //! Find triangle closest to input position. 
+  //!\param from_coords  The input position to test against
+  //!\param closest_point_out  The closest point on the set of triangles in the tree
+  //!\param triangle_out The triangle closest to the input position
+  ErrorCode closest_triangle( EntityHandle tree_root,
+                                const double from_coords[3],
+                                double closest_point_out[3],
+                                EntityHandle& triangle_out );
+
+  ErrorCode sphere_intersect_triangles( EntityHandle tree_root,
+                                          const double center[3],
+                                          double radius,
+                                          std::vector<EntityHandle>& triangles );
+
+  ErrorCode ray_intersect_triangles( EntityHandle tree_root,
+                                       const double tolerance,
+                                       const double ray_unit_dir[3],
+                                       const double ray_base_pt[3],
+                                       std::vector<EntityHandle>& triangles_out,
+                                       std::vector<double>& distance_out,
+                                       int result_count_limit = 0,
+                                       double distance_limit = -1.0);
+
+  //! Get leaf contianing input position.
+  //!
+  //! Does not take into account global bounding box of tree.
+  //! - Therefore there is always one leaf containing the point.
+  //! - If caller wants to account for global bounding box, then
+  //!   caller can test against that box and not call this method
+  //!   at all if the point is outside the box, as there is no leaf
+  //!   containing the point in that case.
+  ErrorCode leaf_containing_point( EntityHandle tree_root,
+                                     const double point[3],
+                                     EntityHandle& leaf_out );
+
+  //! Get iterator at leaf containing input position.
+  //! 
+  //! Returns MB_ENTITY_NOT_FOUND if point is not within
+  //! bounding box of tree.
+  ErrorCode leaf_containing_point( EntityHandle tree_root,
+                                     const double xyz[3],
+                                     AdaptiveKDTreeIter& result );
+
+  //! Find all leaves within a given distance from point in space.
+  ErrorCode leaves_within_distance( EntityHandle tree_root,
+                                      const double from_point[3],
+                                      const double distance,
+                                      std::vector<EntityHandle>& leaves_out );
+
+  //! Calculate bounding box for entities.
+  ErrorCode bounding_box( const Range& entities,
+                            double box_min_out[3],
+                            double box_max_out[3] );
+
+private:
+  
+  void init( const char* tagname );
+  
+  /**\brief find a triangle near the input point */
+  ErrorCode find_close_triangle( EntityHandle root,
+                                   const double from_point[3],
+                                   double pt[3],
+                                   EntityHandle& triangle );
+};
+                    
+
+//! Iterate over leaves of an adapative kD-tree
+class AdaptiveKDTreeIter
+{
+public:
+
+  enum Direction { LEFT = 0, RIGHT = 1 };
+
+private:
+  
+  struct StackObj {
+    StackObj( EntityHandle e, double c ) : entity(e), coord(c) {}
+    StackObj() {}
+    EntityHandle entity; //!< handle for tree node
+    double coord;          //!< box coordinate of parent
+  };
+  
+  enum { BMIN = 0, BMAX = 1 };  //!< indices into mBox and child list
+  
+  double mBox[2][3];                //!< min and max corners of bounding box
+  AdaptiveKDTree* treeTool;       //!< tool for tree
+  std::vector<StackObj> mStack;     //!< stack storing path through tree
+  mutable std::vector<EntityHandle> childVect; //!< tempory storage of child handles
+  
+  //! Descend tree to left most leaf from current position
+  //! No-op if at leaf.
+  ErrorCode step_to_first_leaf( Direction direction );
+
+  friend class AdaptiveKDTree;
+public:
+
+  AdaptiveKDTreeIter() : treeTool(0), childVect(2) {}
+  
+  ErrorCode initialize( AdaptiveKDTree* tool,
+                          EntityHandle root,
+                          const double box_min[3],
+                          const double box_max[3],
+                          Direction direction );
+
+  AdaptiveKDTree* tool() const
+    { return treeTool; }
+
+    //! Get handle for current leaf
+  EntityHandle handle() const
+    { return mStack.back().entity; }
+  
+    //! Get min corner of axis-aligned box for current leaf
+  const double* box_min() const 
+    { return mBox[BMIN]; }
+    
+    //! Get max corner of axis-aligned box for current leaf
+  const double* box_max() const 
+    { return mBox[BMAX]; }
+  
+  double volume() const
+    { return (mBox[BMAX][0] - mBox[BMIN][0]) * 
+             (mBox[BMAX][1] - mBox[BMIN][1]) * 
+             (mBox[BMAX][2] - mBox[BMIN][2]); }
+  
+    //! test if a plane intersects the leaf box
+  bool intersects( const AdaptiveKDTree::Plane& plane ) const
+    { return mBox[BMIN][plane.norm] <= plane.coord &&
+             mBox[BMAX][plane.norm] >= plane.coord; }
+  
+    //! Get depth in tree. root is at depth of 1.
+  unsigned depth() const
+    { return mStack.size(); }
+  
+  //! Advance the iterator either left or right in the tree
+  //! Note:  stepping past the end of the tree will invalidate
+  //!        the iterator.  It will *not* be work step the
+  //!        other direction.
+  ErrorCode step( Direction direction );
+
+    //! Advance to next leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at end.
+    //! Note: steping past the end of the tree will invalidate
+    //!       the iterator. Calling back() will not work.
+  ErrorCode step() { return step(RIGHT); }
+
+    //! Move back to previous leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
+    //! Note: steping past the start of the tree will invalidate
+    //!       the iterator. Calling step() will not work.
+  ErrorCode back() { return step(LEFT); }
+  
+  
+    //! Return the side of the box bounding this tree node
+    //! that is shared with the immediately adjacent sibling
+    //! (the tree node that shares a common parent node with
+    //! this node in the binary tree.)
+    //!
+    //!\param axis_out The principal axis orthogonal to the side of the box
+    //!\param neg_out  true if the side of the box is toward the decreasing
+    //!                direction of the principal axis indicated by axis_out,
+    //!                false if it is toward the increasing direction.
+    //!\return MB_ENTITY_NOT FOUND if root node.
+    //!        MB_FAILURE if internal error.
+    //!        MB_SUCCESS otherwise.
+  ErrorCode sibling_side( AdaptiveKDTree::Axis& axis_out, bool& neg_out ) const;
+
+    //! Get adjacent leaf nodes on side indicated by norm and neg.
+    //!
+    //! E.g. if norm == X and neg == true, then get neighbor(s)
+    //! adjacent to the side of the box contained in the plane
+    //! with normal to the X axis and with the x coordinate equal 
+    //! to the minimum x of the bounding box.
+    //!
+    //! E.g. if norm == Y and neg == false, then get neighbor(s)
+    //! adjacent to the side of the box with y = maximum y of bounding box.
+    //!
+    //!\param norm  Normal vector for box side (X, Y, or Z)
+    //!\param neg   Which of two planes with norm (true->smaller coord, 
+    //!             false->larget coord)
+    //!\param results List to which to append results.  This function does
+    //!             *not* clear existing values in list.
+    //!\param epsilon Tolerance on overlap.  A positive value E will
+    //!              result in nodes that are separated by as much as E
+    //!              to be considered touching.  A negative value -E will
+    //!              cause leaves that do not overlap by at least E to be
+    //!              considered non-overlapping.  Amongst other things, 
+    //!              this value can be used to control whether or not
+    //!              leaves adjacent at only their edges or corners are
+    //!              returned.
+  ErrorCode get_neighbors( AdaptiveKDTree::Axis norm, bool neg,
+                             std::vector<AdaptiveKDTreeIter>& results,
+                             double epsilon = 0.0 ) const;
+  
+    //! Get split plane that separates this node from its immediate sibling.
+  ErrorCode get_parent_split_plane( AdaptiveKDTree::Plane& plane ) const;
+  
+    //! Return true if thos node and the passed node share the
+    //! same immediate parent.
+  bool is_sibling( const AdaptiveKDTreeIter& other_leaf ) const;
+  
+    //! Return true if thos node and the passed node share the
+    //! same immediate parent.
+  bool is_sibling( EntityHandle other_leaf ) const;
+  
+    //! Returns true if calling step() will advance to the
+    //! immediate sibling of the current node.  Returns false
+    //! if current node is root or back() will move to the 
+    //! immediate sibling.
+  bool sibling_is_forward( ) const;
+  
+    //! Find range of overlap between ray and leaf.
+    //!
+    //!\param ray_point Coordinates of start point of ray
+    //!\param ray_vect  Directionion vector for ray such that
+    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
+    //!                 for t > 0.
+    //!\param t_enter   Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray entered the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\param t_exit    Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray exited the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\return true if ray intersects leaf, false otherwise.
+  bool intersect_ray( const double ray_point[3],
+                      const double ray_vect[3],
+                      double& t_enter, double& t_exit ) const;
+};
+
+} // namespace moab 
+
+#endif

Copied: MOAB/trunk/src/moab/BSPTree.hpp (from rev 3583, MOAB/trunk/src/moab/MBBSPTree.hpp)
===================================================================
--- MOAB/trunk/src/moab/BSPTree.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/BSPTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,457 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file AdaptiveKDTree.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2008-05-12
+ */
+
+#ifndef MOAB_BSP_TREE_HPP
+#define MOAB_BSP_TREE_HPP
+
+#include "moab/Types.hpp"
+#include "moab/Interface.hpp"
+
+#include <math.h>
+#include <string>
+#include <vector>
+
+namespace moab {
+
+class BSPTreeBoxIter;
+class BSPTreeIter;
+class Range;
+class BSPTreePoly;
+
+class BSPTree
+{
+private:
+  Interface* mbInstance;
+  Tag planeTag, rootTag;
+  unsigned meshSetFlags;
+  bool cleanUpTrees;
+  std::vector<EntityHandle> createdTrees;
+
+  ErrorCode init_tags( const char* tagname = 0 );
+
+public:
+  
+  static double epsilon() { return 1e-6; }
+
+  BSPTree( Interface* iface,
+             const char* tagname = 0,
+             unsigned meshset_creation_flags = MESHSET_SET );
+
+  BSPTree( Interface* iface,
+             bool destroy_created_trees,
+             const char* tagname = 0,
+             unsigned meshset_creation_flags = MESHSET_SET );
+  
+  ~BSPTree();
+
+  //! Enumeriate split plane directions
+  enum Axis { X = 0, Y = 1, Z = 2 };
+  
+  /**\brief struct to store a plane 
+   *
+   * If plane is defined as Ax+By+Cz+D=0, then
+   * norm={A,B,C} and coeff=-D.
+   */
+  struct Plane {
+    Plane() {}
+    Plane( const double n[3], double d ) : coeff(d)
+      { norm[0] = n[0]; norm[1] = n[1]; norm[2] = n[2]; }
+      /** a x + b y + c z + d = 0 */
+    Plane( double a, double b, double c, double d ) : coeff(d)
+      { norm[0] = a; norm[1] = b; norm[2] = c; }
+      /** Create Y = 1 plane by doing Plane( Y, 1.0 ); */
+    Plane( Axis normal, double point_on_axis ) : coeff(-point_on_axis)
+      { norm[0] = norm[1] = norm[2] = 0; norm[normal] = 1.0; }
+  
+    double norm[3]; //!< Unit normal of plane
+    double coeff;   //!< norm[0]*x + norm[1]*y + norm[2]*z + coeff = 0
+    
+      /** Signed distance from point to plane: 
+       *    absolute value is distance from point to plane
+       *    positive if 'above' plane, negative if 'below'
+       *  Note: assumes unit-length normal.
+       */
+    double signed_distance( const double point[3] ) const
+      { return point[0]*norm[0]+point[1]*norm[1]+point[2]*norm[2] + coeff; }
+    
+      /** return true if point is below the plane */
+    bool below( const double point[3] ) const
+      { return signed_distance(point) <= 0.0; }
+    
+      /** return true if point is above the plane */
+    bool above( const double point[3] ) const
+      { return signed_distance(point) >= 0.0; }
+      
+    double distance( const double point[3] ) const
+      { return fabs( signed_distance(point) ); }
+  
+      /** reverse plane normal */
+    void flip()
+      { norm[0] = -norm[0]; norm[1] = -norm[1]; norm[2] = -norm[2]; coeff = -coeff; }
+  
+    void set( const double normal[3], const double point[3] )
+      { 
+         const double dot = normal[0]*point[0] + normal[1]*point[1] + normal[2]*point[2];
+        *this = Plane( normal, -dot ); 
+      }
+      
+    void set( const double pt1[3], const double pt2[3], const double pt3[3] );
+    
+    void set( double i, double j, double k, double coeff )
+      { *this = Plane( i, j, k, coeff ); }
+    
+      /** Create Y = 1 plane by doing set( Y, 1.0 ); */
+    void set( Axis normal, double point_on_axis )
+      { 
+        coeff = -point_on_axis;
+        norm[0] = norm[1] = norm[2] = 0; 
+        norm[normal] = 1.0; 
+      }
+  };
+  
+  //! Get split plane for tree node
+  ErrorCode get_split_plane( EntityHandle node, Plane& plane )
+    { return moab()->tag_get_data( planeTag, &node, 1, &plane ); }
+  
+  //! Set split plane for tree node
+  ErrorCode set_split_plane( EntityHandle node, const Plane& plane );
+  
+  //! Get bounding box for entire tree
+  ErrorCode get_tree_box( EntityHandle root_node,
+                            double corner_coords[8][3] );
+  
+  //! Get bounding box for entire tree
+  ErrorCode get_tree_box( EntityHandle root_node,
+                            double corner_coords[24] );
+  
+  //! Set bounding box for entire tree
+  ErrorCode set_tree_box( EntityHandle root_node,
+                            const double box_min[3], 
+                            const double box_max[3] );
+  ErrorCode set_tree_box( EntityHandle root_node,
+                            const double corner_coords[8][3] );
+  
+  //! Create tree root node
+  ErrorCode create_tree( const double box_min[3],
+                           const double box_max[3],
+                           EntityHandle& root_handle );
+  ErrorCode create_tree( const double corner_coords[8][3],
+                           EntityHandle& root_handle );
+  
+  //! Create tree root node
+  ErrorCode create_tree( EntityHandle& root_handle );
+
+  //! Find all tree roots
+  ErrorCode find_all_trees( Range& results );
+
+  //! Destroy a tree
+  ErrorCode delete_tree( EntityHandle root_handle );
+
+  Interface* moab() { return mbInstance; }
+
+  //! Get iterator for tree
+  ErrorCode get_tree_iterator( EntityHandle tree_root,
+                                 BSPTreeIter& result );
+  
+  //! Get iterator at right-most ('last') leaf.
+  ErrorCode get_tree_end_iterator( EntityHandle tree_root,
+                                     BSPTreeIter& result );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( BSPTreeIter& leaf, Plane plane );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( BSPTreeIter& leaf, 
+                          Plane plane,
+                          EntityHandle& left_child,
+                          EntityHandle& right_child );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( BSPTreeIter& leaf, 
+                          Plane plane,
+                          const Range& left_entities,
+                          const Range& right_entities );
+
+  //! Split leaf of tree
+  //! Updates iterator location to point to first new leaf node.
+  ErrorCode split_leaf( BSPTreeIter& leaf, 
+                          Plane plane,
+                          const std::vector<EntityHandle>& left_entities,
+                          const std::vector<EntityHandle>& right_entities );
+  
+  //! Merge the leaf pointed to by the current iterator with it's
+  //! sibling.  If the sibling is not a leaf, multiple merges may
+  //! be done.
+  ErrorCode merge_leaf( BSPTreeIter& iter );
+
+  //! Get leaf contianing input position.
+  //!
+  //! Does not take into account global bounding box of tree.
+  //! - Therefore there is always one leaf containing the point.
+  //! - If caller wants to account for global bounding box, then
+  //!   caller can test against that box and not call this method
+  //!   at all if the point is outside the box, as there is no leaf
+  //!   containing the point in that case.
+  ErrorCode leaf_containing_point( EntityHandle tree_root,
+                                     const double point[3],
+                                     EntityHandle& leaf_out );
+
+  //! Get iterator at leaf containing input position.
+  //! 
+  //! Returns MB_ENTITY_NOT_FOUND if point is not within
+  //! bounding box of tree.
+  ErrorCode leaf_containing_point( EntityHandle tree_root,
+                                     const double xyz[3],
+                                     BSPTreeIter& result );
+};
+
+class BSPTreeIter
+{
+public:
+  
+  enum Direction { LEFT = 0, RIGHT = 1 };
+
+private:
+  friend class BSPTree;
+
+  BSPTree* treeTool;
+
+protected:
+  std::vector<EntityHandle> mStack;
+  mutable std::vector<EntityHandle> childVect;
+
+  virtual ErrorCode step_to_first_leaf( Direction direction );
+
+  virtual ErrorCode up();
+  virtual ErrorCode down( const BSPTree::Plane& plane, Direction direction );
+  
+  virtual ErrorCode initialize( BSPTree* tool,
+                                  EntityHandle root,
+                                  const double* point = 0 );
+  
+public:
+  
+  BSPTreeIter() : treeTool(0), childVect(2) {}
+  virtual ~BSPTreeIter() {}
+  
+
+  BSPTree* tool() const
+    { return treeTool; }
+
+    //! Get handle for current leaf
+  EntityHandle handle() const
+    { return mStack.back(); }
+    
+    //! Get depth in tree. root is at depth of 1.
+  unsigned depth() const
+    { return mStack.size(); }
+  
+  //! Advance the iterator either left or right in the tree
+  //! Note:  stepping past the end of the tree will invalidate
+  //!        the iterator.  It will *not* be work step the
+  //!        other direction.
+  virtual ErrorCode step( Direction direction );
+
+    //! Advance to next leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at end.
+    //! Note: steping past the end of the tree will invalidate
+    //!       the iterator. Calling back() will not work.
+  ErrorCode step() { return step(RIGHT); }
+
+    //! Move back to previous leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
+    //! Note: steping past the start of the tree will invalidate
+    //!       the iterator. Calling step() will not work.
+  ErrorCode back() { return step(LEFT); }
+  
+  
+    //! Get split plane that separates this node from its immediate sibling.
+  ErrorCode get_parent_split_plane( BSPTree::Plane& plane ) const;
+  
+    //! Get volume of leaf polyhedron
+  virtual double volume() const;
+  
+    //! Find range of overlap between ray and leaf.
+    //!
+    //!\param ray_point Coordinates of start point of ray
+    //!\param ray_vect  Directionion vector for ray such that
+    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
+    //!                 for t > 0.
+    //!\param t_enter   Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray entered the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\param t_exit    Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray exited the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\return true if ray intersects leaf, false otherwise.
+  virtual bool intersect_ray( const double ray_point[3],
+                              const double ray_vect[3],
+                              double& t_enter, double& t_exit ) const;
+  
+    //! Return true if thos node and the passed node share the
+    //! same immediate parent.
+  bool is_sibling( const BSPTreeIter& other_leaf ) const;
+  
+    //! Return true if thos node and the passed node share the
+    //! same immediate parent.
+  bool is_sibling( EntityHandle other_leaf ) const;
+  
+    //! Returns true if calling step() will advance to the
+    //! immediate sibling of the current node.  Returns false
+    //! if current node is root or back() will move to the 
+    //! immediate sibling.
+  bool sibling_is_forward( ) const;
+  
+    //! Calculate the convex polyhedron bounding this leaf.
+  virtual ErrorCode calculate_polyhedron( BSPTreePoly& polyhedron_out ) const;
+};
+
+class BSPTreeBoxIter : public BSPTreeIter
+{
+  private:
+    
+    double leafCoords[8][3];
+    struct Corners { double coords[4][3]; };
+    std::vector<Corners> stackData;
+  
+  protected:
+
+    virtual ErrorCode step_to_first_leaf( Direction direction );
+    
+    virtual ErrorCode up();
+    virtual ErrorCode down( const BSPTree::Plane& plane, Direction direction );
+  
+    virtual ErrorCode initialize( BSPTree* tool,
+                                    EntityHandle root,
+                                    const double* point = 0 );
+  public:
+  
+
+    //! Faces of a hex : corner bitmap
+  enum SideBits { B0154 = 0x33, //!< Face defined by corners {0,1,5,4}: 1st Exodus side
+                  B1265 = 0x66, //!< Face defined by corners {1,2,6,5}: 2nd Exodus side
+                  B2376 = 0xCC, //!< Face defined by corners {2,3,7,6}: 3rd Exodus side
+                  B3047 = 0x99, //!< Face defined by corners {3,0,4,7}: 4th Exodus side
+                  B3210 = 0x0F, //!< Face defined by corners {3,2,1,0}: 5th Exodus side
+                  B4567 = 0xF0  //!< Face defined by corners {4,5,6,7}: 6th Exodus side
+                 };
+  
+  static SideBits side_above_plane( const double hex_coords[8][3],
+                                    const BSPTree::Plane& plane );
+  
+  static SideBits side_on_plane( const double hex_coords[8][3],
+                                 const BSPTree::Plane& plane );
+  
+  static SideBits opposite_face( const SideBits& bits ) 
+    { return (SideBits)((~bits) & 0xFF); }
+  
+  static ErrorCode face_corners( const SideBits face, 
+                                   const double hex_corners[8][3],
+                                   double face_corners_out[4][3] );
+  
+  //! Advance the iterator either left or right in the tree
+  //! Note:  stepping past the end of the tree will invalidate
+  //!        the iterator.  It will *not* work to subsequently 
+  //!        step the other direction.
+  virtual ErrorCode step( Direction direction );
+
+    //! Advance to next leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at end.
+    //! Note: steping past the end of the tree will invalidate
+    //!       the iterator. Calling back() will not work.
+  ErrorCode step() { return BSPTreeIter::step(); }
+
+    //! Move back to previous leaf
+    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
+    //! Note: steping past the start of the tree will invalidate
+    //!       the iterator. Calling step() will not work.
+  ErrorCode back() { return BSPTreeIter::back(); }
+  
+    //! Get coordinates of box corners, in Exodus II hexahedral ordering.
+  ErrorCode get_box_corners( double coords[8][3] ) const;
+  
+    //! Get volume of leaf box
+  double volume() const;
+  
+    //! test if a plane intersects the leaf box
+  enum XSect { MISS = 0, SPLIT = 1, NONHEX = -1 };
+  XSect splits( const BSPTree::Plane& plane ) const;
+  
+    //! test if a plane intersects the leaf box
+  bool intersects( const BSPTree::Plane& plane ) const;
+  
+    //! Find range of overlap between ray and leaf.
+    //!
+    //!\param ray_point Coordinates of start point of ray
+    //!\param ray_vect  Directionion vector for ray such that
+    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
+    //!                 for t > 0.
+    //!\param t_enter   Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray entered the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\param t_exit    Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray exited the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\return true if ray intersects leaf, false otherwise.
+  bool intersect_ray( const double ray_point[3],
+                      const double ray_vect[3],
+                      double& t_enter, double& t_exit ) const;
+  
+    //! Return the side of the box bounding this tree node
+    //! that is shared with the immediately adjacent sibling
+    //! (the tree node that shares a common parent node with
+    //! this node in the binary tree.)
+    //!
+    //!\return MB_ENTITY_NOT FOUND if root node.
+    //!        MB_FAILURE if internal error.
+    //!        MB_SUCCESS otherwise.
+  ErrorCode sibling_side( SideBits& side_out ) const;
+  
+    //! Get adjacent leaf nodes on indicated side
+    //!
+    //!\param side   Face of box for which to retrieve neighbors
+    //!\param results List to which to append results.  This function does
+    //!             *not* clear existing values in list.
+    //!\param epsilon Tolerance on overlap.  A positive value E will
+    //!              result in nodes that are separated by as much as E
+    //!              to be considered touching.  A negative value -E will
+    //!              cause leaves that do not overlap by at least E to be
+    //!              considered non-overlapping.  Amongst other things, 
+    //!              this value can be used to control whether or not
+    //!              leaves adjacent at only their edges or corners are
+    //!              returned.
+  ErrorCode get_neighbors( SideBits side,
+                             std::vector<BSPTreeBoxIter>& results,
+                             double epsilon = 0.0 ) const;
+  
+    //! Calculate the convex polyhedron bounding this leaf.
+  ErrorCode calculate_polyhedron( BSPTreePoly& polyhedron_out ) const;
+};
+
+} // namespace moab 
+
+#endif

Modified: MOAB/trunk/src/moab/BSPTreePoly.hpp
===================================================================
--- MOAB/trunk/src/moab/BSPTreePoly.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/BSPTreePoly.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,11 +1,13 @@
-#ifndef MB_BSP_TREE_POLY_HPP
-#define MB_BSP_TREE_POLY_HPP
+#ifndef MOAB_BSP_TREE_POLY_HPP
+#define MOAB_BSP_TREE_POLY_HPP
 
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 #include <vector>
 
-class MBCartVect;
+namespace moab {
 
+class CartVect;
+
 /**\brief Convex polyhedron
  *
  * This class is used to represent the convex polyhedron that bounds
@@ -32,34 +34,34 @@
       /**\brief Initialize as a planar-faced hexahedron
        *\param hex_corners Corner coordinates for a hexahedron, in Exodus/Patran order
        */
-    BSPTreePoly( const MBCartVect hex_corners[8] ) : faceList(0) { set(hex_corners); }
+    BSPTreePoly( const CartVect hex_corners[8] ) : faceList(0) { set(hex_corners); }
     BSPTreePoly( ) : faceList(0) { }
     ~BSPTreePoly() { clear(); }
     
       /**\brief Initialize as a planar-faced hexahedron
        *\param hex_corners Corner coordinates for a hexahedron, in Exodus/Patran order
        */
-    MBErrorCode set( const MBCartVect hex_corners[8] );
+    ErrorCode set( const CartVect hex_corners[8] );
     void clear();
     
       /**\brief Get handles for faces */
     void get_faces( std::vector<const Face*>& face_list ) const;
       /**\brief Get corner coordinates for a face */
     void get_vertices( const Face* face, 
-                       std::vector<MBCartVect>& vertices ) const;
+                       std::vector<CartVect>& vertices ) const;
     
       /** Intersect a plane with a polyhedron, retaining
        * the portion of the polyhedron below the plane.
        * This will fail if polyhedron is not convex. 
        */
-    bool cut_polyhedron( const MBCartVect& plane_normal,
+    bool cut_polyhedron( const CartVect& plane_normal,
                          double plane_coeff );
     
       /** Test if a point is contained in the polyhedron.
        *
        *\NOTE algorithm assumes *convex* polyhedron.
        */
-    bool is_point_contained( const MBCartVect& point ) const;
+    bool is_point_contained( const CartVect& point ) const;
     
       //! Assumes planar faces
     double volume() const;
@@ -72,4 +74,6 @@
     static void reset_debug_ids();
 };
 
+} // namespace moab 
+
 #endif

Copied: MOAB/trunk/src/moab/CartVect.hpp (from rev 3583, MOAB/trunk/src/MBCartVect.hpp)
===================================================================
--- MOAB/trunk/src/moab/CartVect.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/CartVect.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,161 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class CartVect
+ * \brief Cartesian Vector
+ * \author Jason Kraftcheck
+ * \date July, 2006
+ */
+
+#ifndef MB_CART_VECT_HPP
+#define MB_CART_VECT_HPP
+
+#include <cmath>
+#include <iosfwd>
+
+namespace moab {
+
+class CartVect
+{
+  private:
+    double d[3];
+  
+  public:
+    
+    inline CartVect() 
+      { }
+      /**Initialze all three values to same scalar (typically zero)*/
+    explicit inline CartVect( double v ) 
+      { d[0] = d[1] = d[2] = v; }
+    inline CartVect( double i, double j, double k )
+      { d[0] = i; d[1] = j; d[2] = k; }
+      /**Initialze from array*/
+    explicit inline CartVect( const double a[3] )
+      { d[0] = a[0]; d[1] = a[1]; d[2] = a[2]; }
+    inline CartVect& operator=( const double v[3] )
+      { d[0]= v[0]; d[1] = v[1]; d[2] = v[2]; return *this; }
+    
+    inline double& operator[]( unsigned i )
+      { return d[i]; }
+    inline double operator[]( unsigned i ) const
+      { return d[i]; }
+    
+    inline CartVect& operator+=( const CartVect& v )
+      { d[0] += v.d[0]; d[1] += v.d[1]; d[2] += v.d[2]; return *this; }
+    inline CartVect& operator-=( const CartVect& v )
+      { d[0] -= v.d[0]; d[1] -= v.d[1]; d[2] -= v.d[2]; return *this; }
+      /** Assign cross product to this */
+    inline CartVect& operator*=( const CartVect& v );
+
+    inline CartVect& operator+=( double s )
+      { d[0] += s; d[1] += s; d[2] += s; return *this; }
+    inline CartVect& operator-=( double s )
+      { d[0] -= s; d[1] -= s; d[2] -= s; return *this; }
+    inline CartVect& operator*=( double s )
+      { d[0] *= s; d[1] *= s; d[2] *= s; return *this; }
+    inline CartVect& operator/=( double s )
+      { d[0] /= s; d[1] /= s; d[2] /= s; return *this; }
+    
+    inline double length() const; //!< vector length
+    
+    inline double length_squared() const;
+    
+    inline void normalize(); //!< make unit length
+    
+    inline void flip(); //!< flip direction
+    
+      /** per-element scalar multiply (this[0] *= v[0], this[1] *= v[1], ...) */
+    inline void scale( const CartVect& v )
+      { d[0] *= v.d[0]; d[1] *= v.d[1]; d[2] *= v.d[2]; }
+    
+      // get pointer to array of three doubles
+    inline double* array()
+      { return d; }
+    inline const double* array() const
+      { return d; }
+      
+      /** initialize array from this */
+    inline void get( double v[3] ) const
+      { v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
+};
+
+inline CartVect operator+( const CartVect& u, const CartVect& v )
+  { return CartVect( u[0] + v[0], u[1] + v[1], u[2] + v[2] ); }
+
+inline CartVect operator-( const CartVect& u, const CartVect& v )
+  { return CartVect( u[0] - v[0], u[1] - v[1], u[2] - v[2] ); }
+
+/** cross product */
+inline CartVect operator*( const CartVect& u, const CartVect& v )
+{
+  return CartVect( u[1] * v[2] - u[2] * v[1],
+                     u[2] * v[0] - u[0] * v[2],
+                     u[0] * v[1] - u[1] * v[0] );
+}
+
+//! Dot product
+inline double operator%( const CartVect& u, const CartVect& v )
+  { return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]; }
+
+inline CartVect& CartVect::operator*=( const CartVect& v )
+  { return *this = *this * v; }
+
+inline double CartVect::length() const
+  { return std::sqrt( *this % *this ); }
+
+inline double CartVect::length_squared() const
+  { return d[0]*d[0] + d[1]*d[1] + d[2]*d[2]; }
+
+inline void CartVect::normalize()
+  { *this /= length(); }
+
+inline void CartVect::flip()
+  { d[0] = -d[0]; d[1] = -d[1]; d[2] = -d[2]; }
+
+//! Interior angle between two vectors
+inline double angle( const CartVect& u, const CartVect& v )
+  { return std::acos( (u % v) / std::sqrt((u % u) * (v % v)) ); }
+
+inline CartVect operator-( const CartVect& v )
+  { return CartVect( -v[0], -v[1], -v[2] ); }
+inline CartVect operator+( const CartVect& v, double s ) 
+  { return CartVect( v[0] + s, v[1] + s, v[2] + s ); }
+inline CartVect operator-( const CartVect& v, double s )
+  { return CartVect( v[0] - s, v[1] - s, v[2] - s ); }
+inline CartVect operator*( const CartVect& v, double s )
+  { return CartVect( v[0] * s, v[1] * s, v[2] * s ); }
+inline CartVect operator/( const CartVect& v, double s )
+  { return CartVect( v[0] / s, v[1] / s, v[2] / s ); }
+inline CartVect operator+( double s, const CartVect& v )
+  { return CartVect( v[0] + s, v[1] + s, v[2] + s ); }
+inline CartVect operator-( double s, const CartVect& v )
+  { return CartVect( v[0] - s, v[1] - s, v[2] - s ); }
+inline CartVect operator*( double s, const CartVect& v )
+  { return CartVect( v[0] * s, v[1] * s, v[2] * s ); }
+
+//! Get unit vector in same direction 
+inline CartVect unit( const CartVect& v )
+{
+  const double len = v.length();
+  return CartVect( v[0] / len, v[1] / len, v[2] / len ); 
+}
+
+    
+std::ostream& operator<<( std::ostream& s, const CartVect& v );
+
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/moab/Core.hpp (from rev 3583, MOAB/trunk/src/moab/MBCore.hpp)
===================================================================
--- MOAB/trunk/src/moab/Core.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Core.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1211 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifndef MOAB_IMPL_GENERAL_HPP
+#define MOAB_IMPL_GENERAL_HPP
+
+#include "moab/Interface.hpp"
+#include "moab/ReaderIface.hpp"
+#include <map>
+
+namespace moab {
+
+class WriteUtil;
+class ReadUtil;
+class AEntityFactory;
+class SequenceManager;
+class TagServer;
+class Error;
+class HomCoord;
+class ReaderWriterSet;
+class EntitySequence;
+class FileOptions;
+
+#ifdef XPCOM_MB
+
+#define MBCORE_CID \
+{ 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xba, 0xb2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
+
+#define MBCORE_CONTRACTID "@sandia.gov/MB;1"
+
+#endif
+
+
+class Core : public Interface 
+{
+
+public:
+
+  //!constructor
+  MB_DLL_EXPORT Core();
+
+  //! depricated constructor -- values are ignored
+  MB_DLL_EXPORT Core( int rank, int num_cpu );
+
+  //!destructor
+  MB_DLL_EXPORT ~Core();
+  
+  //! query an MB internal interface
+  virtual ErrorCode query_interface(const std::string& iface_name, void** iface);
+ 
+  //! release an MB internal interface 
+  virtual ErrorCode release_interface(const std::string& iface_name, void* iface);
+
+#if defined(XPCOM_MB)
+  // this macro expands to all the nsISupports interface functions
+  NS_DECL_ISUPPORTS
+#endif
+
+  virtual int QueryInterface (const MBuuid& uuid, UnknownInterface** iface );
+
+    //! Returns the major.minor version number of the implementation
+    /**
+       \param iface_name If non-NULL, will be filled in with a string, possibly 
+       containing implementation-specific information
+    */
+  virtual float impl_version(std::string *version_string = NULL);
+
+  //! get the type from a handle, returns type
+  virtual EntityType type_from_handle(const EntityHandle handle) const;
+  
+  //! get the id from a handle, returns id
+  virtual EntityID id_from_handle(const EntityHandle handle) const;
+  
+  //! get a handle from an id and type
+  virtual ErrorCode handle_from_id(const EntityType type, 
+                                      const EntityID id, 
+                                      EntityHandle& handle) const;
+  
+  virtual int dimension_from_handle( const EntityHandle ) const;
+
+  //! load mesh from data in file
+  //! NOTE: if there is mesh already present, the new mesh will be added
+  virtual ErrorCode load_mesh(const char *file_name,
+                                 const int *active_block_id_list = NULL,
+                                 const int num_blocks = 0);
+
+  /**Load or import a file. */
+  virtual ErrorCode load_file( const char* file_name,
+                                 const EntityHandle* file_set = 0,
+                                 const char* options = 0,
+                                 const char* set_tag_name = 0,
+                                 const int* set_tag_values = 0,
+                                 int num_set_tag_values = 0 );
+
+  /**Load or import a file. */
+  ErrorCode serial_load_file( const char* file_name,
+                         const EntityHandle* file_set,
+                         const FileOptions& opts,
+                         const ReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const Tag* file_id_tag = 0 );
+                         
+  ErrorCode serial_read_tag( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_vals,
+                               const ReaderIface::IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
+  
+  virtual ErrorCode write_mesh(const char *file_name,
+                                  const EntityHandle *output_list = NULL,
+                                  const int num_sets = 0);
+  /** Write or export a file. */
+  virtual ErrorCode write_file( const char* file_name,
+                                  const char* file_type = 0,
+                                  const char* options = 0,
+                                  const EntityHandle* output_sets = 0,
+                                  int num_output_sets = 0,
+                                  const Tag* tag_list = 0,
+                                  int num_tags = 0 );
+
+  /** Write or export a file */
+  virtual ErrorCode write_file( const char* file_name,
+                                  const char* file_type,
+                                  const char* options,
+                                  const Range& output_sets,
+                                  const Tag* tag_list = 0,
+                                  int num_tags = 0 );
+
+  //! deletes all mesh entities from this datastore
+  virtual ErrorCode delete_mesh();
+
+  //! get overall geometric dimension
+  virtual ErrorCode get_dimension(int &dim) const;
+
+  //! set overall geometric dimension
+  /** Returns error if setting to 3 dimensions, mesh has been created, and 
+   *  there are only 2 dimensions on that mesh
+   */
+  virtual ErrorCode set_dimension(const int dim);
+
+  //! get blocked vertex coordinates for all vertices
+  /** Blocked = all x, then all y, etc. 
+   */
+  virtual ErrorCode get_vertex_coordinates(std::vector<double> &coords) const;
+
+  //! get the coordinate information for this handle if it is of type Vertex
+  //! otherwise, return an error
+  virtual ErrorCode  get_coords(const Range &entity_handles, 
+                                   double *coords) const;
+  
+  virtual ErrorCode  get_coords(const EntityHandle *entity_handles, 
+                                   const int num_entities, 
+                                   double *coords) const;
+  
+  virtual ErrorCode  get_coords(const EntityHandle entity_handle, 
+                                   const double *& x, const double *& y, const double *& z) const;
+ 
+  virtual ErrorCode get_coords( const Range& entity_handles,
+                                  double* x_coords,
+                                  double* y_coords,
+                                  double* z_coords ) const;
+
+  //! set the coordinate information for this handle if it is of type Vertex
+  //! otherwise, return an error
+  virtual ErrorCode  set_coords( const EntityHandle *entity_handles, 
+                                   const int num_entities,
+                                   const double *coords);
+
+  //! set the coordinate information for this handle if it is of type Vertex
+  //! otherwise, return an error
+  virtual ErrorCode  set_coords(Range entity_handles,
+                                  const double *coords);
+
+      //! get global connectivity array for specified entity type
+      /**  Assumes just vertices, no higher order nodes
+       */
+    virtual ErrorCode get_connectivity_by_type(const EntityType type, 
+                                                  std::vector<EntityHandle> &connect) const;
+
+      //! Gets the connectivity for an element EntityHandle. 
+      /** For non-element handles (ie, MeshSets), 
+          returns an error. Connectivity data is copied from the database into the vector 
+          <em>connectivity</em>. The nodes in <em>connectivity</em> are properly ordered.
+          \param entity_handle EntityHandle to get connectivity of.
+          \param connectivity Vector in which connectivity of <em>entity_handle</em> is returned.  
+          Should contain MeshVertices.
+          \param topological_connectivity If true, higher order nodes are ignored. 
+
+          Example: \code 
+          std::vector<EntityHandle> conn;
+          get_connectivity( entity_handle, conn ); \endcode */
+    virtual ErrorCode  get_connectivity(const EntityHandle *entity_handles, 
+                                           const int num_handles,
+                                           std::vector<EntityHandle> &connectivity, 
+                                           bool topological_connectivity = false) const;
+ 
+    //! Gets the connectivity for a vector of elements
+    /** Same as vector-based version except range is returned (unordered!)
+     */
+  virtual ErrorCode  get_connectivity(const EntityHandle *entity_handles, 
+                                        const int num_handles,
+                                        Range &connectivity, 
+                                        bool topological_connectivity = false) const;
+
+    //! Gets the connectivity for elements
+    /** Same as vector-based version except range is returned (unordered!)
+    */
+  virtual ErrorCode get_connectivity( const Range& entity_handles, 
+                                        Range &connectivity, 
+                                        bool topological_connectivity = false) const;
+ 
+    //! Gets a pointer to constant connectivity data of <em>entity_handle</em> 
+      /** Sets <em>number_nodes</em> equal to the number of nodes of the <em> 
+          entity_handle </em>.  Faster then the other <em>get_connectivity</em> function. 
+          The nodes in 'connectivity' are properly ordered. 
+          \param entity_handle EntityHandle to get connectivity of.
+          \param connectivity Array in which connectivity of <em>entity_handle</em> is returned.
+          Should contain MeshVertex's.
+          \param num_nodes Number of MeshVertices in array <em>connectivity</em>. 
+
+          Example: \code 
+          const EntityHandle* conn;
+          int number_nodes = 0;
+          get_connectivity( entity_handle, conn, number_nodes ); \endcode 
+          
+          Example2: \code
+          std::vector<EntityHandle> sm_storage;
+          const EntityHandle* conn;
+          int number_nodes;
+          get_connectivity( handle, conn, number_nodes, false, &sm_storage );
+          if (conn == &sm_storage[0])
+            std::cout << "Structured mesh element" << std::endl;
+          \endcode
+        */
+    virtual ErrorCode  get_connectivity( const EntityHandle entity_handle, 
+                                           const EntityHandle *&connectivity, 
+                                           int &num_nodes, 
+                                           bool topological_connectivity = false,
+                                           std::vector<EntityHandle>* storage = 0
+                                          ) const;
+
+      //! Sets the connectivity for an EntityHandle.  For non-element handles, return an error.
+      /** Connectivity is stored exactly as it is ordered in vector <em>connectivity</em>. 
+          \param entity_handle EntityHandle to set connectivity of.
+          \param connect Vector containing new connectivity of <em>entity_handle</em>.
+          \param num_connect Number of vertices in <em>connect</em>
+   
+          Example: \code 
+          std::vector<EntityHandle> conn(3);
+          conn[0] = node1;
+          conn[1] = node2;
+          conn[2] = node3;
+          set_connectivity( entity_handle, conn, 3 ); \endcode */
+    virtual ErrorCode  set_connectivity(const EntityHandle entity_handle, 
+                                          EntityHandle *connect,
+                                          const int num_connect);
+
+      //! get the adjacencies associated with a set of entities
+      /** \param from_entities vector of EntityHandle to get adjacencies of.
+          \param to_dimension Dimension of desired adjacency information.
+          \param adj_entities Vector in which adjacent EntityHandles are returned. 
+          \param operation_type enum of INTERSECT or UNION.  Defines whether to take
+          the intersection or union of the set of adjacencies recovered for the from_entities.
+
+          The adjacent entities in vector <em>adjacencies</em> are not in any particular 
+          order. 
+
+          Example: \code
+            // get the set of edges that are adjacent to all entities in the from_entities list
+            std::vector<EntityHandle> from_entities = {hex1, hex2};
+            std::vector<EntityHandle> adjacencies;
+            get_adjacencies( from_entities, MB_1D_ENTITY, adjacencies ); 
+            \endcode */
+
+    virtual ErrorCode get_adjacencies(const EntityHandle *from_entities,
+                                         const int num_entities,
+                                         const int to_dimension,
+                                         const bool create_if_missing,
+                                         std::vector<EntityHandle>& adj_entities,
+                                         const int operation_type = Interface::INTERSECT);
+
+    virtual ErrorCode get_adjacencies(const EntityHandle *from_entities,
+                                        const int num_entities,
+                                         const int to_dimension,
+                                         const bool create_if_missing,
+                                         Range &adj_entities,
+                                         const int operation_type = Interface::INTERSECT);
+
+    virtual ErrorCode get_adjacencies(const Range &from_entities,
+                                         const int to_dimension,
+                                         const bool create_if_missing,
+                                         Range &adj_entities,
+                                         const int operation_type = Interface::INTERSECT);
+
+      /**\brief Get all vertices for input entities
+       *
+       * Special case of get_adjacencies where to_dimension == 0
+       * and operation_type == Interface::UNION.  
+       *\Note This is not a variation of get_connectivity because
+       *      the behavior is different for polyhedra.
+       */
+    virtual ErrorCode get_vertices( const Range& from_entities,
+                                      Range& vertices );
+
+      //! Adds adjacencies
+      /** \param from_handle entities 
+          \param both_ways add the adjacency information to both the
+          to_handle and and the from_from :handle
+
+          Example: \code
+      */
+    virtual ErrorCode add_adjacencies(const EntityHandle from_handle, 
+                                         const EntityHandle *to_handles,
+                                         const int num_handles,
+                                         bool both_ways);
+
+      //! Adds adjacencies; same as vector-based, but with range instead
+    virtual ErrorCode add_adjacencies(const EntityHandle from_handle, 
+                                        Range &adjacencies,
+                                        bool both_ways);
+
+      //! Removes adjacencies
+      /** \param handle EntityHandle to get adjacencies of.
+
+      Example: \code
+      */
+    virtual ErrorCode remove_adjacencies(const EntityHandle from_handle, 
+                                            const EntityHandle *to_handles,
+                                            const int num_handles);
+
+      //! Retrieves all entities in the database of given dimension.  
+      /** \param dimension Dimension of entities desired.
+          \param entities Range in which entities of dimension <em>dimension</em> are returned.
+
+          Example: \code
+          int dimension = 2;
+          Range entities;
+          get_entities_by_dimension( dimension, entities ); //get 2D EntityHandles in the database
+          \endcode */
+    virtual ErrorCode get_entities_by_dimension( const EntityHandle meshset,
+                                                   const int dimension, 
+                                                   Range &entities,
+                                                   const bool recursive = false) const;
+
+    virtual ErrorCode get_entities_by_dimension( const EntityHandle meshset,
+                                                   const int dimension, 
+                                                   std::vector<EntityHandle> &entities,
+                                                   const bool recursive = false) const;
+
+      //! Retrieves all entities in the data base of given type.  
+      /** \param type EntityType of entities desired (ie, MeshHex, MeshEdge, MeshTri, etc )
+          \param entities Range in which entities of EntityType <em>type</em> are returned.
+
+          Example: \code
+          EntityType type = MeshTet;
+          Range entities;
+          get_entities_by_dimension( type, entities ); //get MeshTet type EntityHandles in the database
+          \endcode */
+    virtual ErrorCode get_entities_by_type( const EntityHandle meshset,
+                                              const EntityType type, 
+                                              Range &entities,
+                                              const bool recursive = false) const;
+
+    virtual ErrorCode get_entities_by_type( const EntityHandle meshset,
+                                              const EntityType type, 
+                                              std::vector<EntityHandle> &entities,
+                                              const bool recursive = false) const;
+
+    virtual ErrorCode get_entities_by_type_and_tag(const EntityHandle meshset,
+                                                      const EntityType type,
+                                                      const Tag *tag_handles,
+                                                      const void* const* values,
+                                                      const int num_tags,
+                                                      Range &entities,
+                                                      const int condition = Interface::INTERSECT,
+                                                      const bool recursive = false) const;
+
+      //! Retrieves all entities in the data base
+      /** \param entities Range in which entities of EntityType <em>type</em> are returned.
+
+      Example: \code
+      Range entities;
+      get_entities( entities ); //get MeshTet type EntityHandles in the database
+      \endcode */
+    virtual ErrorCode get_entities_by_handle(const EntityHandle meshset,
+                                      Range &entities,
+                                      const bool recursive = false) const;
+
+      //! Retrieves all entities in the data base
+      /** \param entities Range in which entities of EntityType <em>type</em> are returned.
+
+      Example: \code
+      Range entities;
+      get_entities( entities ); //get MeshTet type EntityHandles in the database
+      \endcode */
+    virtual ErrorCode get_entities_by_handle(const EntityHandle meshset,
+                                      std::vector<EntityHandle> &entities,
+                                      const bool recursive = false) const;
+
+      //! Retrieves all entities in the database of given dimension.  
+      /** \param dimension Dimension of entities desired.
+          \param entities Range in which entities of dimension <em>dimension</em> are returned.
+
+          Example: \code
+          int dimension = 2;
+          Range entities;
+          get_entities_by_dimension( dimension, entities ); //get 2D EntityHandles in the database
+          \endcode */
+    virtual ErrorCode get_number_entities_by_dimension(const EntityHandle meshset,
+                                                          const int dimension, 
+                                                          int &num_entities,
+                                                          const bool recursive = false) const;
+
+      //! Retrieves all entities in the data base of given type.  
+      /** \param type EntityType of entities desired (ie, MeshHex, MeshEdge, MeshTri, etc )
+          \param entities Range in which entities of EntityType <em>type</em> are returned.
+
+          Example: \code
+          EntityType type = MeshTet;
+          Range entities;
+          get_entities_by_dimension( type, entities ); //get MeshTet type EntityHandles in the database
+          \endcode */
+    virtual ErrorCode get_number_entities_by_type(const EntityHandle meshset,
+                                                     const EntityType type, 
+                                                     int &num_entities,
+                                                     const bool recursive = false) const;
+
+    virtual ErrorCode get_number_entities_by_type_and_tag(const EntityHandle meshset,
+                                                             const EntityType type,
+                                                             const Tag *tag_handles,
+                                                             const void* const* values,
+                                                             const int num_tags,
+                                                             int &num_entities,
+                                                             const bool recursive = false) const;
+
+      //! Retrieves all entities in the data base
+      /** \param entities Range in which entities of EntityType <em>type</em> are returned.
+
+      Example: \code
+      Range entities;
+      get_entities( entities ); //get MeshTet type EntityHandles in the database
+      \endcode */
+    virtual ErrorCode get_number_entities_by_handle(const EntityHandle meshset,
+                                             int &num_entities,
+                                             const bool recursive = false) const;
+
+      //! Creates an element based on the type and connectivity. 
+      /** If connectivity vector is not correct for EntityType <em>type</em> (ie, a vector with 
+          3 vertices is passed in to make an MeshQuad), the function returns MB_FAILURE. 
+          \param type Type of element to create. (MeshTet, MeshTri, MeshKnife, etc.) 
+          \param connectivity Vector containing connectivity of element to create.
+          \param handle EntityHandle representing the newly created element in the database.
+
+          Example: \code
+          EntityType type = MeshQuad;
+          std::vector<EntityHandle> connectivity(4);
+          quad_conn[0] = vertex0;
+          quad_conn[1] = vertex1;
+          quad_conn[2] = vertex2;
+          quad_conn[3] = vertex3;
+          EntityHandle element_handle;
+          create_element( type, connectivity, element_handle ); \endcode */
+    virtual ErrorCode create_element(const EntityType type, 
+                                        const EntityHandle *connectivity,
+                                        const int num_nodes, 
+                                        EntityHandle &element_handle);
+
+      //! Creates a vertex based on coordinates.  
+      /**
+         \param coordinates Array that has 3 doubles in it.
+         \param entity_handle EntityHandle representing the newly created vertex in the database.
+
+         Example: \code
+         double *coordinates = double[3];
+         coordinates[0] = 1.034;
+         coordinates[1] = 23.23; 
+         coordinates[2] = -0.432; 
+         EntityHandle entity_handle = 0;
+         create_vertex( coordinates, entity_handle ); \endcode */
+    virtual ErrorCode create_vertex(const double coordinates[3], 
+                                       EntityHandle &entity_handle );
+
+    //! Create a set of vertices with the specified coordinates
+    /**
+       \param coordinates Array that has 3*n doubles in it.
+       \param nverts Number of vertices to create
+       \param entity_handles Range passed back with new vertex handles
+    */
+  virtual ErrorCode create_vertices(const double *coordinates, 
+                                      const int nverts,
+                                      Range &entity_handles );
+
+      //! merges two entities
+    virtual ErrorCode merge_entities(EntityHandle entity_to_keep, 
+                                        EntityHandle entity_to_remove,
+                                        bool auto_merge,
+                                        bool delete_removed_entity);
+
+      //! Removes entities in a vector from the data base.  
+      /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
+          which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity<\em> are 
+          removed as part of this function.
+          \param entities 1d vector of entities to delete
+          \param num_entities Number of entities in 1d vector
+      */ 
+    virtual ErrorCode delete_entities(const EntityHandle *entities,
+                                         const int num_entities);
+
+      //! Removes entities in a range from the data base.  
+      /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
+          which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity<\em> are 
+          removed as part of this function.
+          \param entities Range of entities to delete
+      */ 
+    virtual ErrorCode delete_entities(const Range &entities);
+
+  virtual ErrorCode list_entities(const Range &entities) const;
+  
+  virtual ErrorCode list_entities(const EntityHandle *entities,
+                                    const int num_entities) const;
+
+  virtual ErrorCode list_entity(const EntityHandle entity) const;
+
+      //! function object for recieving events from MB of higher order nodes
+      //! added to entities
+    class HONodeAddedRemoved
+    {
+    public:
+      HONodeAddedRemoved(){}
+      virtual ~HONodeAddedRemoved(){}
+        //! node_added called when a node was added to an element's connectivity array
+        //! note: connectivity array of element may be incomplete (corner nodes will exist always)
+      virtual void node_added(EntityHandle node, EntityHandle element);
+      virtual void node_removed(EntityHandle node);
+    };
+  
+    virtual ErrorCode convert_entities(const EntityHandle meshset, 
+                                          const bool mid_side,
+                                          const bool mid_face, 
+                                          const bool mid_volume, 
+                                          Interface::HONodeAddedRemoved* function_object = 0);
+
+      //! function to get the side number given two elements; returns
+      //! MB_FAILURE if child not related to parent; does *not* create adjacencies
+      //! between parent and child
+    virtual ErrorCode side_number(const EntityHandle parent,
+                                     const EntityHandle child,
+                                     int &side_number,
+                                     int &sense,
+                                     int &offset) const;
+
+      //! given an entity and the connectivity and type of one of its subfacets, find the
+      //! high order node on that subfacet, if any
+    virtual ErrorCode high_order_node(const EntityHandle parent_handle,
+                                         const EntityHandle *subfacet_conn,
+                                         const EntityType subfacet_type,
+                                         EntityHandle &high_order_node) const;
+
+      //! given an entity and a target dimension & side number, get that entity
+    virtual ErrorCode side_element(const EntityHandle source_entity,
+                                      const int dim, 
+                                      const int side_number,
+                                      EntityHandle &target_entity) const;
+
+      //-------------------------Tag Stuff-------------------------------------//
+
+  //! Creates a dense tag with a name.
+  /** Use to store data that is larger than 8 bits, on many 
+      EntityHandles across all entity types.  Allows for storage of data of 
+      <em>tag_size</em> bytes on any arbitrary entity.  
+      \param tag_name String name of Tag.
+      \param tag_size Size of data to store on tag, in bytes.  For storing data 
+      1 byte or less in size, use tag_create_bits(...)
+      \param tag_handle Tag to be created.
+      \param default_value Default value tag data is set to when initially created.
+
+      Example: \code
+      std::string tag_name = "my_meshset_tag";
+      int tag_size = sizeof(double); 
+      Tag tag_handle = 0;
+      double value = 100.5;
+      const void *default_value = &value;
+      tag_create_dense( tag_name, 
+              tag_size, default_value ); //Create a dense tag. 
+                                         //The tag will hold data the size of a 
+                                         //double and that data will initially be 
+                                         //set to 100.5  \endcode */
+  virtual ErrorCode tag_create(const char *tag_name,
+                                  const int tag_size, 
+                                  const TagType type,
+                                  Tag &tag_handle, 
+                                  const void *default_value);
+
+    /** \brief Define a new tag.
+     *
+     * Define a new tag for storing application-defined data on MB entities.  
+     *
+     * \param name    The name of the tag.
+     * \param size    The size of the tag data in bytes.
+     * \param storage The tag storage type.
+     * \param data    The tag data type.
+     * \param handle  The tag handle (output)
+     * \param def_val Optional default value for tag.
+     * \param use_existing  If true, and a tag with the same name and
+     *                same description exists, successfully return the
+     *                handle of the tag.
+     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
+     *         - MB_FAILURE if inconsistant arguments
+     *         - MB_SUCCESS otherwise.
+     */
+  virtual ErrorCode tag_create( const      char* name,
+                                  const        int size,
+                                  const  TagType storage,
+                                  const DataType data,
+                                            Tag& handle,
+                                  const      void* def_val,
+                                              bool use_existing);
+
+    /**\brief Define a new tag that can store variable-length data.
+     *
+     * Define a new tag for storing application-defined data on MB entities.  
+     *
+     * \param name          The name of the tag.
+     * \param storage       The tag storage type (MB_TAG_BIT not supported).
+     * \param data_type     The tag data type.
+     * \param handle_out    The tag handle (output)
+     * \param default_value Optional default value for tag.
+     * \param default_val_len Length of default value.  Required if
+     *                      default value is specified.
+     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
+     *         - MB_FAILURE if inconsistant arguments
+     *         - MB_SUCCESS otherwise.
+     */
+  virtual ErrorCode tag_create_variable_length( const char* name,
+                                                  TagType   storage,
+                                                  DataType  data_type,
+                                                  Tag&      handle_out,
+                                                  const void* default_value = 0,
+                                                  int         default_val_len = 0 
+                                                 );
+
+  //! Gets the tag name string of the tag_handle.
+  /** \param tag_handle Tag you want the name of.  
+      \param tag_name Name string of <em>tag_handle</em>. 
+
+      Example: \code
+      Tag tag_handle = 0;
+      std::string tag_name = "my_special_tag";
+      tag_get_name( tag_handle, tag_name );  //gets the Tag from the tag's name string
+      \endcode */
+  virtual ErrorCode  tag_get_name(const Tag tag_handle, 
+                                     std::string& tag_name) const;
+
+  //! Gets tag handle from the tag's string name. 
+  /**
+      \param tag_name Name string of desired tag. 
+      \param tag_handle Tag to be retrieved.
+
+      Example: \code
+      Tag tag_handle = 0;
+      std::string tag_name = "quad_data_flag";
+      tag_get_handle( tag_name, tag_handle ); \endcode */ 
+  virtual ErrorCode  tag_get_handle(const char *tag_name, 
+                                       Tag &tag_handle) const;
+
+  //! Get handles for all tags defined on this entity
+  virtual ErrorCode tag_get_tags_on_entity(const EntityHandle entity,
+                                             std::vector<Tag> &tag_handles) const;
+
+  //! get size of tag in bytes
+  virtual ErrorCode tag_get_size(const Tag, int &tag_size) const;
+
+    //! Get the default value of the specified tag
+  virtual ErrorCode tag_get_default_value(const Tag tag, void *def_val) const;
+  virtual ErrorCode tag_get_default_value( Tag tag, const void*& def_val, int& size) const;
+
+  //! get type of tag (sparse, dense, etc.; 0 = dense, 1 = sparse, 2 = bit, 3 = mesh)
+  virtual ErrorCode tag_get_type(const Tag, TagType &tag_type) const;
+
+   /** \brief Get data type of tag.
+    *
+    * Get the type of the tag data.  The tag is data is assumed to
+    * be a vector of this type.  If the tag data vetcor contains 
+    * more than one value, then the tag size must be a multiple of
+    * the size of this type.
+    * \param tag  The tag 
+    * \param type The type of the specified tag (output).
+    */
+  virtual ErrorCode tag_get_data_type(const Tag tag, DataType& type) const;
+
+  //! get handles for all tags defined
+  virtual ErrorCode tag_get_tags(std::vector<Tag> &tag_handles) const;
+
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                     const EntityHandle* entity_handles, 
+                                     const int num_entities, 
+                                     void *tag_data) const;
+
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                     const Range& entity_handles, 
+                                     void *tag_data) const;
+
+  //! Sets the data of a given EntityHandle and Tag.  
+  /** If the <em>tag_handle</em> and the entity type of <em>entity_handle</em> are not 
+      compatible, data of <em>entity_handle</em> never existed and MB_FAILURE 
+      is returned. 
+      \param tag_handle Tag indicating what data is to be set.
+      \param entity_handle EntityHandle on which to set tag's data. 
+      \param tag_data Data to set the <em>entity_handle</em>'s tag data to.
+
+      Example: \code
+      int tag_data = 1004;
+      tag_set_data( tag_handle, entity_handle, &tag_data ); \endcode */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                     const EntityHandle* entity_handles, 
+                                     const int num_entities,
+                                     const void *tag_data );
+  
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                     const Range& entity_handles,
+                                     const void *tag_data );
+
+
+    /**\brief Get pointers to tag data
+     *
+     * For a tag, get the values for a list of passed entity handles.
+     *\param tag_handle     The tag
+     *\param entity_handles An array of entity handles for which to retreive tag values.
+     *\param num_entities   The length of the 'entity_handles' array.
+     *\param tag_data       An array of 'const void*'.  Array must be at least
+     *                      'num_entitities' long.  Array is populated (output)
+     *                      with pointers to the internal storage for the
+     *                      tag value corresponding to each entity handle.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities, 
+                                    const void** tag_data,
+                                    int* tag_sizes = 0 ) const;
+
+    /**\brief Get pointers to tag data
+     *
+     * For a tag, get the values for a list of passed entity handles.
+     *\param tag_handle     The tag
+     *\param entity_handles The entity handles for which to retreive tag values.
+     *\param tag_data       An array of 'const void*'.  Array is populated (output)
+     *                      with pointers to the internal storage for the
+     *                      tag value corresponding to each entity handle.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const Range& entity_handles, 
+                                    const void** tag_data,
+                                    int* tag_sizes = 0 ) const;
+
+    /**\brief Set tag data given an array of pointers to tag values.
+     *
+     * For a tag, set the values for a list of passed entity handles.
+     *\param tag_handle     The tag
+     *\param entity_handles An array of entity handles for which to set tag values.
+     *\param num_entities   The length of the 'entity_handles' array.
+     *\param tag_data       An array of 'const void*'.  Array must be at least
+     *                      'num_entitities' long.  Array is expected to
+     *                      contain pointers to tag values for the corresponding
+     *                      EntityHandle in 'entity_handles'.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities,
+                                    void const* const* tag_data ,
+                                    const int* tag_sizes = 0 );
+  
+    /**\brief Set tag data given an array of pointers to tag values.
+     *
+     * For a tag, set the values for a list of passed entity handles.
+     *\param tag_handle     The tag
+     *\param entity_handles The entity handles for which to set tag values.
+     *\param tag_data       An array of 'const void*'.  Array is expected to
+     *                      contain pointers to tag values for the corresponding
+     *                      EntityHandle in 'entity_handles'.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const Range& entity_handles,
+                                    void const* const* tag_data,
+                                    const int* tag_sizes = 0 );
+
+  //! Delete the data of a vector of entity handles and sparse tag
+  /** Delete the data of a tag on a vector of entity handles.  Only sparse tag data are deleted with this
+      function; dense tags are deleted by deleting the tag itself using tag_delete.
+      \param tag_handle Handle of the (sparse) tag being deleted from entity
+      \param entity_handles 1d vector of entity handles from which the tag is being deleted
+      \param num_handles Number of entity handles in 1d vector
+  */
+  virtual ErrorCode  tag_delete_data(const Tag tag_handle, 
+                                        const EntityHandle *entity_handles,
+                                        const int num_handles);
+
+  //! Delete the data of a range of entity handles and sparse tag
+  /** Delete the data of a tag on a range of entity handles.  Only sparse tag data are deleted with this
+      function; dense tags are deleted by deleting the tag itself using tag_delete.
+      \param tag_handle Handle of the (sparse) tag being deleted from entity
+      \param entity_range Range of entities from which the tag is being deleted
+  */
+  virtual ErrorCode  tag_delete_data(const Tag tag_handle, 
+                                        const Range &entity_range);
+
+  //! Removes the tag from the database and deletes all of its associated data.
+  virtual ErrorCode  tag_delete(Tag tag_handle);
+
+  /**a;dlfa;sfsdafasdfl; 
+     a;dlfja;sljfl;sadfasd
+     a;dlkfj;lsajdf */
+
+  //! creates a mesh set
+  virtual ErrorCode create_meshset(const unsigned int options, 
+                                     EntityHandle &ms_handle,
+                                     int start_id = 0);
+
+  //! Empty a vector of mesh set
+  /** Empty a mesh set.
+      \param ms_handles 1d vector of handles of sets being emptied
+      \param num_meshsets Number of entities in 1d vector
+  */
+  virtual ErrorCode clear_meshset( const EntityHandle *ms_handles, 
+                                     const int num_meshsets);
+
+  //! Empty a range of mesh set
+  /** Empty a mesh set.
+      \param ms_handles Range of handles of sets being emptied
+  */
+  virtual ErrorCode clear_meshset(const Range &ms_handles);
+
+  //! get the options of a mesh set
+  virtual ErrorCode get_meshset_options(const EntityHandle ms_handle, 
+                                           unsigned int& options) const;
+
+  //! set the options of a mesh set
+  virtual ErrorCode set_meshset_options(const EntityHandle ms_handle, 
+                                          const unsigned int options);
+
+  //! subtracts meshset2 from meshset1 - modifies meshset1
+  virtual ErrorCode subtract_meshset(EntityHandle meshset1, 
+                                        const EntityHandle meshset2);
+
+  //! intersects meshset2 with meshset1 - modifies meshset1
+  virtual ErrorCode intersect_meshset(EntityHandle meshset1, 
+                                         const EntityHandle meshset2);
+    
+  //! unites meshset2 with meshset1 - modifies meshset1
+  virtual ErrorCode unite_meshset(EntityHandle meshset1, 
+                                     const EntityHandle meshset2);
+
+  //! add entities to meshset
+  virtual ErrorCode add_entities(EntityHandle meshset, 
+                                    const Range &entities);
+
+  //! add entities to meshset
+  virtual ErrorCode add_entities(EntityHandle meshset, 
+                                    const EntityHandle *entities,
+                                    const int num_entities);
+  
+  //! remove entities from meshset
+  virtual ErrorCode remove_entities(EntityHandle meshset, 
+                                       const Range &entities);
+
+  //! remove entities from meshset
+  virtual ErrorCode remove_entities(EntityHandle meshset, 
+                                       const EntityHandle *entities,
+                                       const int num_entities);
+
+    //! return true if all entities are contained in set
+  virtual bool contains_entities(EntityHandle meshset, 
+                                 const EntityHandle *entities,
+                                 int num_entities,
+                                 const int operation_type = Interface::INTERSECT);
+
+    //! replace entities
+  virtual ErrorCode replace_entities(EntityHandle meshset, 
+                                       const EntityHandle *old_entities,
+                                       const EntityHandle *new_entities,
+                                       int num_entities);
+
+  //------MeshSet Parent/Child functions------
+  
+  //! get parent meshsets
+  virtual ErrorCode get_parent_meshsets(const EntityHandle meshset,
+                                           std::vector<EntityHandle> &parents, 
+                                           const int num_hops = 1) const;
+
+  //! get parent meshsets
+  virtual ErrorCode get_parent_meshsets(const EntityHandle meshset,
+                                          Range &parents, 
+                                          const int num_hops = 1) const;
+
+  //! get child meshsets
+  virtual ErrorCode get_child_meshsets(const EntityHandle meshset, 
+                                          std::vector<EntityHandle> &children, 
+                                          const int num_hops = 1) const;
+
+  //! get child meshsets
+  virtual ErrorCode get_child_meshsets(const EntityHandle meshset, 
+                                         Range &children, 
+                                          const int num_hops = 1) const;
+
+  //! get contained meshsets
+  virtual ErrorCode get_contained_meshsets(const EntityHandle meshset, 
+                                             std::vector<EntityHandle> &contained, 
+                                             const int num_hops = 1) const;
+
+  //! get contained meshsets
+  virtual ErrorCode get_contained_meshsets(const EntityHandle meshset, 
+                                             Range &contained, 
+                                             const int num_hops = 1) const;
+
+  //! gets number of parent meshsets
+  virtual ErrorCode num_parent_meshsets(const EntityHandle meshset,  
+                                          int *number,
+                                          const int num_hops = 1) const;
+
+  //! gets number of child meshsets
+  virtual ErrorCode num_child_meshsets(const EntityHandle meshset, 
+                                         int *number, 
+                                         const int num_hops = 1) const;
+
+  //! gets number of contained meshsets
+  virtual ErrorCode num_contained_meshsets(const EntityHandle meshset, 
+                                             int *number, 
+                                             const int num_hops = 1) const;
+
+  //! add a parent meshset
+  virtual ErrorCode add_parent_meshset(EntityHandle meshset, 
+                                          const EntityHandle parent_meshset);
+
+  //! add parent meshsets
+  virtual ErrorCode add_parent_meshsets(EntityHandle meshset, 
+                                          const EntityHandle* parent_meshsets,
+                                          int num_parent_meshsets);
+
+  //! add a child meshset
+  virtual ErrorCode add_child_meshset(EntityHandle meshset, 
+                                         const EntityHandle child_meshset);
+
+  //! add parent meshsets
+  virtual ErrorCode add_child_meshsets(EntityHandle meshset, 
+                                         const EntityHandle* child_meshsets,
+                                         int num_child_meshsets);
+
+  //! adds 'parent' to child's parent list and adds 'child' to parent's child list
+  virtual ErrorCode add_parent_child( EntityHandle parent, 
+                                         EntityHandle child );
+
+  //! removes 'parent' to child's parent list and removes 'child' to parent's child list
+  virtual ErrorCode remove_parent_child( EntityHandle parent, 
+                                            EntityHandle child );
+
+  //! remove parent meshset
+  virtual ErrorCode remove_parent_meshset(EntityHandle meshset, 
+                                             const EntityHandle parent_meshset);
+  
+  //! remove child meshset
+  virtual ErrorCode remove_child_meshset(EntityHandle meshset, 
+                                            const EntityHandle child_meshset);
+
+  // ************************  error condition information *************** 
+
+    //! return various specific tag handles
+  Tag material_tag();
+  Tag neumannBC_tag();
+  Tag dirichletBC_tag();
+  Tag globalId_tag();
+  Tag geom_dimension_tag();
+
+    //! get/set the number of nodes
+    //int total_num_nodes() const;
+    //void total_num_nodes(const int val);
+  
+    //! get/set the number of elements
+    //int total_num_elements() const;
+    //void total_num_elements(const int val);
+
+    //! return a reference to the tag server
+  TagServer* tag_server() {return tagServer;}
+
+    //! return a reference to the sequence manager
+  SequenceManager* sequence_manager() { return sequenceManager; }
+  const SequenceManager* sequence_manager() const { return sequenceManager; }
+
+    /// create structured sequence
+  ErrorCode create_scd_sequence(const HomCoord &    coord_min,
+                                  const HomCoord &  coord_max,
+                                  EntityType  type,
+                                  EntityID  start_id_hint,
+                                  EntityHandle &  first_handle_out,
+                                  EntitySequence *&  sequence_out );
+
+  ErrorCode add_vsequence(EntitySequence *    vert_seq,
+                            EntitySequence *  elem_seq,
+                            const HomCoord &  p1,
+                            const HomCoord &  q1,
+                            const HomCoord &  p2,
+                            const HomCoord &  q2,
+                            const HomCoord &  p3,
+                            const HomCoord &  q3,
+                            bool  bb_input = false,
+                            const HomCoord *  bb_min = NULL,
+                            const HomCoord *  bb_max = NULL);
+   
+    //! return the a_entity_factory pointer
+  AEntityFactory *a_entity_factory() { return aEntityFactory; }
+  const AEntityFactory *a_entity_factory() const { return aEntityFactory; }
+  
+    //! return set of registered IO tools
+  ReaderWriterSet* reader_writer_set() { return readerWriterSet; }
+
+  Error* get_error_handler() { return mError; }
+
+//-----------------MeshSet Interface Functions------------------//
+
+  void print(const EntityHandle handle, const char *prefix,
+             bool first_call = true) const;
+
+  virtual ErrorCode get_last_error(std::string& info) const;
+
+  virtual std::string get_error_string(const ErrorCode code) const;
+
+    //! check all adjacencies for consistency
+  ErrorCode check_adjacencies();
+  
+    //! check some adjacencies for consistency
+  ErrorCode check_adjacencies(const EntityHandle *ents, int num_ents);
+  
+    //! return whether the input handle is valid or not
+  bool is_valid(const EntityHandle this_ent) const;
+  
+//-----------------Memory Functions------------------//
+
+
+  /**\brief Calculate amount of memory used to store MOAB data
+   *
+   * This function calculates the amount of memory used to store
+   * MOAB data.  
+   *
+   * There are two possible values for each catagory of memory use.
+   * The exact value and the amortized value.  The exact value is the
+   * amount of memory used to store the data for the specified entities.
+   * The amortized value includes the exact value and an amortized 
+   * estimate of the memory consumed in overhead for storing the values
+   * (indexing structures, access structures, etc.)  
+   *
+   * Note: If ent_array is NULL, the total memory used by MOAB for storing
+   *       data will be returned in the address pointed to by
+   *       total_amortized_storage, if total_amortized_storage is not NULL.
+   *
+   *\param ent_array Array of entities for which to estimate the memory use.
+   *                 If NULL, estimate is done for all entities.
+   *\param num_ents The length of ent_array.  Not used if ent_rray is NULL.
+   *\param total_(amortized_)storage The sum of the memory entity, adjacency, and all tag storage.
+   *\param (amortized_)entity_storage The storage for the entity definitions
+   *                 (connectivity arrays for elements, coordinates for vertices,
+   *                  list storage within sets, etc.)
+   *\param (amortized_)adjacency_storage The storage for adjacency data.
+   *\param tag_array  An array of tags for which to calculate the memory use.
+   *\param num_tags   The lenght of tag_array
+   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
+   *                   for each tag specifying the memory used for storing that
+   *                   tag.  If tag_array is NULL and this value is not, the
+   *                   location at which to store the total memory used for
+   *                   all tags.
+   */
+  void estimated_memory_use( const EntityHandle* ent_array = 0,
+                             unsigned long  num_ents = 0,
+                             unsigned long* total_storage = 0,
+                             unsigned long* total_amortized_storage = 0,
+                             unsigned long* entity_storage = 0,
+                             unsigned long* amortized_entity_storage = 0,
+                             unsigned long* adjacency_storage = 0,
+                             unsigned long* amortized_adjacency_storage = 0,
+                             const Tag*   tag_array = 0,
+                             unsigned       num_tags = 0,
+                             unsigned long* tag_storage = 0,
+                             unsigned long* amortized_tag_storage = 0 );
+
+  /**\brief Calculate amount of memory used to store MOAB data
+   *
+   * This function calculates the amount of memory used to store
+   * MOAB data.  
+   *
+   * There are two possible values for each catagory of memory use.
+   * The exact value and the amortized value.  The exact value is the
+   * amount of memory used to store the data for the specified entities.
+   * The amortized value includes the exact value and an amortized 
+   * estimate of the memory consumed in overhead for storing the values
+   * (indexing structures, access structures, etc.)  
+   *
+   *\param ents      Entities for which to estimate the memory use.
+   *\param total_(amortized_)storage The sum of the memory entity, adjacency, and all tag storage.
+   *\param (amortized_)entity_storage The storage for the entity definitions
+   *                 (connectivity arrays for elements, coordinates for vertices,
+   *                  list storage within sets, etc.)
+   *\param (amortized_)adjacency_storage The storage for adjacency data.
+   *\param tag_array  An array of tags for which to calculate the memory use.
+   *\param num_tags   The lenght of tag_array
+   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
+   *                   for each tag specifying the memory used for storing that
+   *                   tag.  If tag_array is NULL and this value is not, the
+   *                   location at which to store the total memory used for
+   *                   all tags.
+   */
+  void estimated_memory_use( const Range& ents,
+                             unsigned long* total_storage = 0,
+                             unsigned long* total_amortized_storage = 0,
+                             unsigned long* entity_storage = 0,
+                             unsigned long* amortized_entity_storage = 0,
+                             unsigned long* adjacency_storage = 0,
+                             unsigned long* amortized_adjacency_storage = 0,
+                             const Tag*   tag_array = 0,
+                             unsigned       num_tags = 0,
+                             unsigned long* tag_storage = 0,
+                             unsigned long* amortized_tag_storage = 0 );
+                                     
+
+  void print_database() const;
+
+private:
+
+  /**\brief Do not allow copying */
+  Core( const Core& copy );
+  /**\brief Do not allow copying */
+  Core& operator=( const Core& copy );
+
+  void estimated_memory_use_internal( const Range* ents,
+                            unsigned long* total_storage,
+                            unsigned long* total_amortized_storage,
+                            unsigned long* entity_storage,
+                            unsigned long* amortized_entity_storage,
+                            unsigned long* adjacency_storage,
+                            unsigned long* amortized_adjacency_storage,
+                            const Tag*   tag_array,
+                            unsigned       num_tags,
+                            unsigned long* tag_storage,
+                            unsigned long* amortized_tag_storage );
+
+    //! database init and de-init routines
+  ErrorCode initialize();
+  void deinitialize();
+
+    //! return the entity set representing the whole mesh
+  EntityHandle get_root_set();
+  
+  
+    //!\brief Clean up after a file reader returns failure.
+    //!
+    //! Delete all entities not contained in initial_entities
+    //! and all tags not contained in initial_tags.
+  void clean_up_failed_read( const Range& initial_entities,
+                             std::vector<Tag> initial_tags );
+  
+    // other interfaces for MB
+  WriteUtil* mMBWriteUtil;
+  ReadUtil* mMBReadUtil;
+
+    //! store the total number of elements defined in this interface
+    //int totalNumElements;
+  
+    //! store the total number of nodes defined in this interface
+    //int totalNumNodes;
+
+    //! the overall geometric dimension of this mesh
+  int geometricDimension;
+
+  Tag materialTag;
+  Tag neumannBCTag;
+  Tag dirichletBCTag;
+  Tag geomDimensionTag;
+  Tag globalIdTag;
+
+    //! tag server for this interface
+  TagServer* tagServer;
+
+  SequenceManager *sequenceManager;
+
+  AEntityFactory *aEntityFactory;
+  
+  ReaderWriterSet* readerWriterSet;
+
+  Error* mError;
+};
+
+} // namespace moab 
+
+#endif   // MOAB_IMPL_GENERAL_HPP

Modified: MOAB/trunk/src/moab/DualTool.hpp
===================================================================
--- MOAB/trunk/src/moab/DualTool.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/DualTool.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -22,11 +22,13 @@
  *          
  */ 
 
-#ifndef DUAL_TOOL_HPP
-#define DUAL_TOOL_HPP
+#ifndef MOAB_DUAL_TOOL_HPP
+#define MOAB_DUAL_TOOL_HPP
 
-#include "MBForward.hpp"
+#include "moab/Forward.hpp"
 
+namespace moab {
+
 class DualTool
 {
 public:
@@ -71,300 +73,300 @@
     int id;
   };
   
-  DualTool(MBInterface *impl);
+  DualTool(Interface *impl);
   
   ~DualTool();
 
     //! construct the dual entities for the entire mesh
-  MBErrorCode construct_dual(MBEntityHandle *entities, 
+  ErrorCode construct_dual(EntityHandle *entities, 
                              const int num_entities);
   
     //! construct the dual entities for a hex mesh, including dual surfaces & curves
-  MBErrorCode construct_hex_dual(MBEntityHandle *entities,
+  ErrorCode construct_hex_dual(EntityHandle *entities,
                                  const int num_entities);
   
     //! construct the dual entities for a hex mesh, including dual surfaces & curves
-  MBErrorCode construct_hex_dual(MBRange &entities);
+  ErrorCode construct_hex_dual(Range &entities);
   
   //! get the dual entities; if non-null, only dual of entities passed in are returned
-  MBErrorCode get_dual_entities(const int dim, 
-                                MBEntityHandle *entities, 
+  ErrorCode get_dual_entities(const int dim, 
+                                EntityHandle *entities, 
                                 const int num_entities, 
-                                MBRange &dual_ents);
+                                Range &dual_ents);
   
   //! get the dual entities; if non-null, only dual of entities passed in are returned
-  MBErrorCode get_dual_entities(const int dim, 
-                                MBEntityHandle *entities, 
+  ErrorCode get_dual_entities(const int dim, 
+                                EntityHandle *entities, 
                                 const int num_entities, 
-                                std::vector<MBEntityHandle> &dual_ents);
+                                std::vector<EntityHandle> &dual_ents);
 
     //! return the corresponding dual entity
-  MBEntityHandle get_dual_entity(const MBEntityHandle this_ent) const;
+  EntityHandle get_dual_entity(const EntityHandle this_ent) const;
   
     //! return the corresponding extra dual entity
-  MBEntityHandle get_extra_dual_entity(const MBEntityHandle this_ent);
+  EntityHandle get_extra_dual_entity(const EntityHandle this_ent);
   
     //! get the d-dimensional hyperplane sets; static 'cuz it's easy to do without an active
     //! dualtool
-  static MBErrorCode get_dual_hyperplanes(const MBInterface *impl, const int dim, 
-                                          MBRange &dual_ents);
+  static ErrorCode get_dual_hyperplanes(const Interface *impl, const int dim, 
+                                          Range &dual_ents);
 
     //! get the graphics points for single entity (dual_ent CAN'T be a set);
     //! returns multiple facets, each with npts[i] points
-  MBErrorCode get_graphics_points(MBEntityHandle dual_ent,
+  ErrorCode get_graphics_points(EntityHandle dual_ent,
                                   std::vector<int> &npts,
                                   std::vector<GraphicsPoint> &gpoints);
   
     //! get the graphics points for a range of entities or sets (if set, the
     //! entities in those sets); optionally reset ids on points
-  MBErrorCode get_graphics_points(const MBRange &in_range,
+  ErrorCode get_graphics_points(const Range &in_range,
                                   std::vector<GraphicsPoint> &gpoints,
                                   const bool assign_ids = false,
                                   const int start_id = 0);
   
     //! given a last_v (possibly zero) and this_v, find the next loop vertex on 
     //! this dual surface
-  MBEntityHandle next_loop_vertex(const MBEntityHandle last_v,
-                                  const MBEntityHandle this_v,
-                                  const MBEntityHandle dual_surf);
+  EntityHandle next_loop_vertex(const EntityHandle last_v,
+                                  const EntityHandle this_v,
+                                  const EntityHandle dual_surf);
   
     //! get/set the tag for dual surfaces
-  MBTag dualSurface_tag() const;
-  MBErrorCode dualSurface_tag(const MBTag tag);
+  Tag dualSurface_tag() const;
+  ErrorCode dualSurface_tag(const Tag tag);
   
     //! get/set the tag for dual curves
-  MBTag dualCurve_tag() const;
-  MBErrorCode dualCurve_tag(const MBTag tag);
+  Tag dualCurve_tag() const;
+  ErrorCode dualCurve_tag(const Tag tag);
 
     //! get/set the tag for dual cells
-  MBTag isDualCell_tag() const;
-  MBErrorCode isDualCell_tag(const MBTag tag);
+  Tag isDualCell_tag() const;
+  ErrorCode isDualCell_tag(const Tag tag);
 
     //! get/set the tag for dual entities
-  MBTag dualEntity_tag() const;
-  MBErrorCode dualEntity_tag(const MBTag tag);
+  Tag dualEntity_tag() const;
+  ErrorCode dualEntity_tag(const Tag tag);
 
     //! get/set the tag for dual entities
-  MBTag extraDualEntity_tag() const;
-  MBErrorCode extraDualEntity_tag(const MBTag tag);
+  Tag extraDualEntity_tag() const;
+  ErrorCode extraDualEntity_tag(const Tag tag);
 
     //! get/set the tag for dual entities
-  MBTag dualGraphicsPoint_tag() const;
-  MBErrorCode dualGraphicsPoint_tag(const MBTag tag);
+  Tag dualGraphicsPoint_tag() const;
+  ErrorCode dualGraphicsPoint_tag(const Tag tag);
 
     //! get/set the global id tag
-  MBTag globalId_tag() const;
-  MBErrorCode globalId_tag(const MBTag tag);
+  Tag globalId_tag() const;
+  ErrorCode globalId_tag(const Tag tag);
 
     //! given an entity, return any dual surface or curve it's in
-  MBEntityHandle get_dual_hyperplane(const MBEntityHandle ncell);
+  EntityHandle get_dual_hyperplane(const EntityHandle ncell);
 
     //! returns true if first & last vertices are dual to hexes (not faces)
-  bool is_blind(const MBEntityHandle chord);
+  bool is_blind(const EntityHandle chord);
   
     //! set the dual surface or curve for an entity
-  MBErrorCode set_dual_surface_or_curve(MBEntityHandle entity, 
-                                        const MBEntityHandle dual_hyperplane,
+  ErrorCode set_dual_surface_or_curve(EntityHandle entity, 
+                                        const EntityHandle dual_hyperplane,
                                         const int dimension);
   
     //! effect atomic pillow operation
-  MBErrorCode atomic_pillow(MBEntityHandle odedge, MBEntityHandle &quad1,
-                            MBEntityHandle &quad2);
+  ErrorCode atomic_pillow(EntityHandle odedge, EntityHandle &quad1,
+                            EntityHandle &quad2);
 
     //! effect reverse atomic pillow operation
-  MBErrorCode rev_atomic_pillow(MBEntityHandle pillow, MBRange &chords);
+  ErrorCode rev_atomic_pillow(EntityHandle pillow, Range &chords);
 
     //! effect face shrink operation
-  MBErrorCode face_shrink(MBEntityHandle odedge);
+  ErrorCode face_shrink(EntityHandle odedge);
   
     //! effect reverse atomic pillow operation
-  MBErrorCode rev_face_shrink(MBEntityHandle edge);
+  ErrorCode rev_face_shrink(EntityHandle edge);
   
     //! effect a face open-collapse operation
-  MBErrorCode face_open_collapse(MBEntityHandle ocl, MBEntityHandle ocr);
+  ErrorCode face_open_collapse(EntityHandle ocl, EntityHandle ocr);
 
     //! given the two 1-cells involved in the foc, get entities associated with
     //! the quads being opened/collapsed; see implementation for more details
-  MBErrorCode foc_get_ents(MBEntityHandle ocl, 
-                           MBEntityHandle ocr, 
-                           MBEntityHandle *quads, 
-                           MBEntityHandle *split_edges, 
-                           MBEntityHandle *split_nodes, 
-                           MBRange &hexes, 
-                           MBEntityHandle *other_edges, 
-                           MBEntityHandle *other_nodes);
+  ErrorCode foc_get_ents(EntityHandle ocl, 
+                           EntityHandle ocr, 
+                           EntityHandle *quads, 
+                           EntityHandle *split_edges, 
+                           EntityHandle *split_nodes, 
+                           Range &hexes, 
+                           EntityHandle *other_edges, 
+                           EntityHandle *other_nodes);
   
     //! given a 1-cell and a chord, return the neighboring vertices on the
     //! chord, in the same order as the 1-cell's vertices
-  MBErrorCode get_opposite_verts(const MBEntityHandle middle_edge, 
-                                 const MBEntityHandle chord, 
-                                 MBEntityHandle *verts);
+  ErrorCode get_opposite_verts(const EntityHandle middle_edge, 
+                                 const EntityHandle chord, 
+                                 EntityHandle *verts);
 
     //! given a dual surface or curve, return the 2-cells, 1-cells, 0-cells, and
     //! loop 0/1-cells, if requested; any of those range pointers can be NULL,
     //! in which case that range isn't returned
-  MBErrorCode get_dual_entities(const MBEntityHandle dual_ent,
-                                MBRange *dcells,
-                                MBRange *dedges,
-                                MBRange *dverts,
-                                MBRange *dverts_loop,
-                                MBRange *dedges_loop);
+  ErrorCode get_dual_entities(const EntityHandle dual_ent,
+                                Range *dcells,
+                                Range *dedges,
+                                Range *dverts,
+                                Range *dverts_loop,
+                                Range *dedges_loop);
   
-  MBErrorCode list_entities(const MBRange &entities) const;
-  MBErrorCode list_entities(const MBEntityHandle *entities,
+  ErrorCode list_entities(const Range &entities) const;
+  ErrorCode list_entities(const EntityHandle *entities,
                             const int num_entities) const;
   
     //! delete all the dual data
-  MBErrorCode delete_whole_dual();
+  ErrorCode delete_whole_dual();
   
     //! check dual-primal adjacencies
-  MBErrorCode check_dual_adjs();
+  ErrorCode check_dual_adjs();
 
 private:
 
     //! construct dual vertices for specified regions
-  MBErrorCode construct_dual_vertices(const MBRange &all_regions,
-                                      MBRange &new_dual_ents);
+  ErrorCode construct_dual_vertices(const Range &all_regions,
+                                      Range &new_dual_ents);
   
     //! construct dual edges for specified faces
-  MBErrorCode construct_dual_edges(const MBRange &all_faces,
-                                      MBRange &new_dual_ents);
+  ErrorCode construct_dual_edges(const Range &all_faces,
+                                      Range &new_dual_ents);
   
     //! construct dual faces for specified edges
-  MBErrorCode construct_dual_faces(const MBRange &all_edges,
-                                      MBRange &new_dual_ents);
+  ErrorCode construct_dual_faces(const Range &all_edges,
+                                      Range &new_dual_ents);
   
     //! construct dual cells for specified vertices
-  MBErrorCode construct_dual_cells(const MBRange &all_verts,
-                                   MBRange &new_dual_ents);
+  ErrorCode construct_dual_cells(const Range &all_verts,
+                                   Range &new_dual_ents);
   
     //! traverse dual faces of input dimension, constructing
     //! dual hyperplanes of them in sets as it goes
-  MBErrorCode construct_dual_hyperplanes(const int dim, 
-                                         MBEntityHandle *entities, 
+  ErrorCode construct_dual_hyperplanes(const int dim, 
+                                         EntityHandle *entities, 
                                          const int num_entities);
 
     //! order 1cells on a chord 
-  MBErrorCode order_chord(MBEntityHandle chord_set);
+  ErrorCode order_chord(EntityHandle chord_set);
   
     //! make a new dual hyperplane with the specified id; if the id specified is -1,
     //! set the new one's id to the max found
-  MBErrorCode construct_new_hyperplane(const int dim, MBEntityHandle &new_hyperplane,
+  ErrorCode construct_new_hyperplane(const int dim, EntityHandle &new_hyperplane,
                                        int &id);
   
     //! traverse the cells of a dual hyperplane, starting with this_ent (dimension
     //! of this_ent determines hyperplane dimension)
     //! simpler method for traversing hyperplane, using same basic algorithm but
     //! using MeshTopoUtil::get_bridge_adjacencies
-  MBErrorCode traverse_hyperplane(const MBTag hp_tag, 
-                                  MBEntityHandle &this_hp, 
-                                  MBEntityHandle this_ent);
+  ErrorCode traverse_hyperplane(const Tag hp_tag, 
+                                  EntityHandle &this_hp, 
+                                  EntityHandle this_ent);
   
     //! connect dual surfaces with dual curves using parent/child connections
-  MBErrorCode construct_hp_parent_child();
+  ErrorCode construct_hp_parent_child();
   
   //! given an edge handle, return a list of dual vertices in radial order 
   //! around the edge; also returns whether this edge is on the boundary
-  MBErrorCode get_radial_dverts(const MBEntityHandle edge,
-                                std::vector<MBEntityHandle> &rad_verts,
+  ErrorCode get_radial_dverts(const EntityHandle edge,
+                                std::vector<EntityHandle> &rad_verts,
                                 bool &bdy_edge);
   
-  MBErrorCode construct_dual_vertex(MBEntityHandle entity, 
-                                    MBEntityHandle &dual_ent, 
+  ErrorCode construct_dual_vertex(EntityHandle entity, 
+                                    EntityHandle &dual_ent, 
                                     const bool extra = false,
                                     const bool add_graphics_pt = true);
 
     //! add a graphics point to an entity (on a tag)
-  MBErrorCode add_graphics_point(MBEntityHandle entity,
+  ErrorCode add_graphics_point(EntityHandle entity,
                                  double *avg_pos = NULL);
   
     //! get points defining facets of a 2cell
-  MBErrorCode get_cell_points(MBEntityHandle dual_ent,
+  ErrorCode get_cell_points(EntityHandle dual_ent,
                               std::vector<int> &npts,
                               std::vector<GraphicsPoint> &points);
 
     //! if this_ent is an edge, is a dual entity, and has quads as
     //! its vertices' dual entities, return true, otherwise false
-  bool check_1d_loop_edge(MBEntityHandle this_ent);
+  bool check_1d_loop_edge(EntityHandle this_ent);
   
     //! go through potential dual equivalent edges (edges whose nodes define
     //! multiple edges), and add explicit adjacencies to corrent 2cells
-  MBErrorCode check_dual_equiv_edges(MBRange &dual_edges);
+  ErrorCode check_dual_equiv_edges(Range &dual_edges);
   
     //! delete a dual entity; updates primal to no longer point to it
-  MBErrorCode delete_dual_entities(MBEntityHandle *entities, const int num_entities);
+  ErrorCode delete_dual_entities(EntityHandle *entities, const int num_entities);
 
     //! delete a range of dual entities; updates primal to no longer point to them
-  MBErrorCode delete_dual_entities(MBRange &entities);
+  ErrorCode delete_dual_entities(Range &entities);
   
     //! check sense of connect arrays, and reverse/rotate if necessary
-  MBErrorCode fs_check_quad_sense(MBEntityHandle hex0,
-                                  MBEntityHandle quad0,
-                                  std::vector<MBEntityHandle> *connects);
+  ErrorCode fs_check_quad_sense(EntityHandle hex0,
+                                  EntityHandle quad0,
+                                  std::vector<EntityHandle> *connects);
   
     //! get the three quads for a face shrink, the two hexes, and the connectivity
     //! of the three quads
-  MBErrorCode fs_get_quads(MBEntityHandle odedge, 
-                           MBEntityHandle *quads,
-                           MBEntityHandle *hexes,
-                           std::vector<MBEntityHandle> *connects);
+  ErrorCode fs_get_quads(EntityHandle odedge, 
+                           EntityHandle *quads,
+                           EntityHandle *hexes,
+                           std::vector<EntityHandle> *connects);
   
     //! get loops of quads around 2 hexes, ordered similarly to vertex loops
-  MBErrorCode  fs_get_quad_loops(MBEntityHandle *hexes, 
-                                 std::vector<MBEntityHandle> *connects, 
-                                 std::vector<MBEntityHandle> *side_quads);
+  ErrorCode  fs_get_quad_loops(EntityHandle *hexes, 
+                                 std::vector<EntityHandle> *connects, 
+                                 std::vector<EntityHandle> *side_quads);
   
     //! given connectivity of first 3 quads for reverse face shrink, 
     //! get fourth (outer 4 verts to be shared by two inner hexes) and quads
     //! around the side of the structure
-  MBErrorCode fsr_get_fourth_quad(std::vector<MBEntityHandle> *connects,
-                                  std::vector<MBEntityHandle> *side_quads);
+  ErrorCode fsr_get_fourth_quad(std::vector<EntityHandle> *connects,
+                                  std::vector<EntityHandle> *side_quads);
 
 /*  
     //! get pairs of entities to be merged as part of foc operation
-  MBErrorCode foc_get_merge_ents(MBEntityHandle *quads, MBEntityHandle *new_quads, 
-                                 MBRange &edge, MBRange &new_edge,
-                                 std::vector<MBEntityHandle> &merge_ents);
+  ErrorCode foc_get_merge_ents(EntityHandle *quads, EntityHandle *new_quads, 
+                                 Range &edge, Range &new_edge,
+                                 std::vector<EntityHandle> &merge_ents);
 */
 
     //! function for deleting dual prior to foc operation; special because in
     //! many cases need to delete a sheet in preparation for merging onto another
-  MBErrorCode foc_delete_dual(MBEntityHandle *split_quads,
-                              MBEntityHandle *split_edges,
-                              MBRange &hexes);
+  ErrorCode foc_delete_dual(EntityHandle *split_quads,
+                              EntityHandle *split_edges,
+                              Range &hexes);
 
     //! split a pair of quads and the edge(s) shared by them
-  MBErrorCode split_pair_nonmanifold(MBEntityHandle *split_quads,
-                                     MBEntityHandle *split_edges,
-                                     MBEntityHandle *split_nodes,
-                                     std::vector<MBEntityHandle> *star_dp1,
-                                     std::vector<MBEntityHandle> *star_dp2,
-                                     MBEntityHandle *other_edges,
-                                     MBEntityHandle *other_nodes,
-                                     MBEntityHandle *new_quads,
-                                     MBEntityHandle *new_edges,
-                                     MBEntityHandle *new_nodes);
+  ErrorCode split_pair_nonmanifold(EntityHandle *split_quads,
+                                     EntityHandle *split_edges,
+                                     EntityHandle *split_nodes,
+                                     std::vector<EntityHandle> *star_dp1,
+                                     std::vector<EntityHandle> *star_dp2,
+                                     EntityHandle *other_edges,
+                                     EntityHandle *other_nodes,
+                                     EntityHandle *new_quads,
+                                     EntityHandle *new_edges,
+                                     EntityHandle *new_nodes);
   
     //! for foc's splitting two shared edges, there might be additional entities
     //! connected to the split node that also have to be updated
-  MBErrorCode foc_get_addl_ents(std::vector<MBEntityHandle> *star_dp1, 
-                                std::vector<MBEntityHandle> *star_dp2, 
-                                MBEntityHandle *split_edges,
-                                MBEntityHandle split_node,
-                                MBRange *addl_ents);
+  ErrorCode foc_get_addl_ents(std::vector<EntityHandle> *star_dp1, 
+                                std::vector<EntityHandle> *star_dp2, 
+                                EntityHandle *split_edges,
+                                EntityHandle split_node,
+                                Range *addl_ents);
   
     //! given the split quads and edges, get the face and hex stars around the
     //! edge(s), separated into halves, each of which goes with the new or old entities
     //! after the split
-  MBErrorCode foc_get_stars(MBEntityHandle *split_quads,
-                            MBEntityHandle *split_edges,
-                            std::vector<MBEntityHandle> *star_dp1,
-                            std::vector<MBEntityHandle> *star_dp2);
+  ErrorCode foc_get_stars(EntityHandle *split_quads,
+                            EntityHandle *split_edges,
+                            std::vector<EntityHandle> *star_dp1,
+                            std::vector<EntityHandle> *star_dp2);
   
-  void print_cell(MBEntityHandle cell);
+  void print_cell(EntityHandle cell);
   
     //! private copy of interface *
-  MBInterface *mbImpl;
+  Interface *mbImpl;
 
     //! static constant number of points bounding any cell
   enum
@@ -373,57 +375,57 @@
   };
   
     //! tags used for dual surfaces, curves, cells, entities
-  MBTag dualCurveTag;
-  MBTag dualSurfaceTag;
-  MBTag isDualCellTag;
-  MBTag dualEntityTag;
-  MBTag extraDualEntityTag;
-  MBTag dualGraphicsPointTag;
-  MBTag categoryTag;
-  MBTag globalIdTag;
+  Tag dualCurveTag;
+  Tag dualSurfaceTag;
+  Tag isDualCellTag;
+  Tag dualEntityTag;
+  Tag extraDualEntityTag;
+  Tag dualGraphicsPointTag;
+  Tag categoryTag;
+  Tag globalIdTag;
 
   int maxHexId;
 };
 
-inline MBTag DualTool::dualSurface_tag() const
+inline Tag DualTool::dualSurface_tag() const
 {
   return dualSurfaceTag;
 }
 
-inline MBTag DualTool::dualCurve_tag() const
+inline Tag DualTool::dualCurve_tag() const
 {
   return dualCurveTag;
 }
 
-inline MBTag DualTool::isDualCell_tag() const
+inline Tag DualTool::isDualCell_tag() const
 {
   return isDualCellTag;
 }
 
-inline MBTag DualTool::dualEntity_tag() const
+inline Tag DualTool::dualEntity_tag() const
 {
   return dualEntityTag;
 }
 
-inline MBTag DualTool::extraDualEntity_tag() const
+inline Tag DualTool::extraDualEntity_tag() const
 {
   return extraDualEntityTag;
 }
 
-inline MBTag DualTool::dualGraphicsPoint_tag() const
+inline Tag DualTool::dualGraphicsPoint_tag() const
 {
   return dualGraphicsPointTag;
 }
 
-inline MBTag DualTool::globalId_tag() const
+inline Tag DualTool::globalId_tag() const
 {
   return globalIdTag;
 }
 
   //! get/set the tag for dual surfaces
-inline MBErrorCode DualTool::dualSurface_tag(const MBTag tag) 
+inline ErrorCode DualTool::dualSurface_tag(const Tag tag) 
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == dualSurfaceTag && tag) || dualSurfaceTag != tag) {
     dualSurfaceTag = tag;
     result = MB_SUCCESS;
@@ -433,9 +435,9 @@
 }
   
   //! get/set the tag for dual curves
-inline MBErrorCode DualTool::dualCurve_tag(const MBTag tag)
+inline ErrorCode DualTool::dualCurve_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == dualCurveTag && tag) || dualCurveTag != tag) {
     dualCurveTag = tag;
     result = MB_SUCCESS;
@@ -445,9 +447,9 @@
 }
   
   //! get/set the tag for dual cells
-inline MBErrorCode DualTool::isDualCell_tag(const MBTag tag)
+inline ErrorCode DualTool::isDualCell_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == isDualCellTag && tag) || isDualCellTag != tag) {
     isDualCellTag = tag;
     result = MB_SUCCESS;
@@ -457,9 +459,9 @@
 }
   
   //! get/set the tag for dual entities
-inline MBErrorCode DualTool::dualEntity_tag(const MBTag tag)
+inline ErrorCode DualTool::dualEntity_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == dualEntityTag && tag) || dualEntityTag != tag) {
     dualEntityTag = tag;
     result = MB_SUCCESS;
@@ -469,9 +471,9 @@
 }
   
   //! get/set the tag for dual entities
-inline MBErrorCode DualTool::extraDualEntity_tag(const MBTag tag)
+inline ErrorCode DualTool::extraDualEntity_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == extraDualEntityTag && tag) || extraDualEntityTag != tag) {
     extraDualEntityTag = tag;
     result = MB_SUCCESS;
@@ -481,9 +483,9 @@
 }
   
   //! get/set the tag for dual entities
-inline MBErrorCode DualTool::dualGraphicsPoint_tag(const MBTag tag)
+inline ErrorCode DualTool::dualGraphicsPoint_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == dualGraphicsPointTag && tag) || dualGraphicsPointTag != tag) {
     dualGraphicsPointTag = tag;
     result = MB_SUCCESS;
@@ -493,9 +495,9 @@
 }
   
   //! get/set the tag for dual entities
-inline MBErrorCode DualTool::globalId_tag(const MBTag tag)
+inline ErrorCode DualTool::globalId_tag(const Tag tag)
 {
-  MBErrorCode result = MB_FAILURE;
+  ErrorCode result = MB_FAILURE;
   if ((0 == globalIdTag && tag) || globalIdTag != tag) {
     globalIdTag = tag;
     result = MB_SUCCESS;
@@ -503,6 +505,8 @@
   
   return result;
 }
-  
+
+} // namespace moab 
+
 #endif
 

Copied: MOAB/trunk/src/moab/EntityHandle.hpp.in (from rev 3583, MOAB/trunk/src/moab/MBEntityHandle.h.in)
===================================================================
--- MOAB/trunk/src/moab/EntityHandle.hpp.in	                        (rev 0)
+++ MOAB/trunk/src/moab/EntityHandle.hpp.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,77 @@
+#ifndef MOAB_ENTITY_HANDLE_HPP
+#define MOAB_ENTITY_HANDLE_HPP
+
+/* MOAB qualified HAVE_INTTYPES_H */
+#undef MOAB_HAVE_INTTYPES_H
+
+/* MOAB qualified HAVE_STDDEF_H */
+#undef MOAB_HAVE_STDDEF_H
+
+/* MOAB qualified HAVE_STDINT_H */
+#undef MOAB_HAVE_STDINT_H
+
+/* MOAB qualified HAVE_STDLIB_H */
+#undef MOAB_HAVE_STDLIB_H
+
+/* MOAB qualified HAVE_SYS_TYPES_H */
+#undef MOAB_HAVE_SYS_TYPES_H
+
+/* Use int32_t for handles */
+#undef MOAB_FORCE_32_BIT_HANDLES
+
+/* Use int64_t for handles */
+#undef MOAB_FORCE_64_BIT_HANDLES
+
+/* System provides ptrdiff_t typedef */
+#undef MOAB_HAVE_PTRDIFF_T
+
+/* System provides size_t typedef */
+#undef MOAB_HAVE_SIZE_T
+
+#ifdef MOAB_HAVE_INTTYPES_H
+# include <inttypes.h>
+#elif defined (MOAB_HAVE_STDINT_H)
+# include <stdint.h>
+#elif defined (_MSC_VER)
+  typedef __int8 int8_t;
+  typedef __int16 int16_t;
+  typedef __int32 int32_t;
+  typedef __int64 int64_t;
+  typedef unsigned __int8 uint8_t;
+  typedef unsigned __int16 uint16_t;
+  typedef unsigned __int32 uint32_t;
+  typedef unsigned __int64 uint64_t;
+#endif
+
+#ifdef MOAB_HAVE_STDDEF_H
+# include <stddef.h>
+#elif defined (MOAB_HAVE_STDLIB_H)
+# include <stdlib.h>
+#elif defined (HAVE_SYS_TYPES_H)
+# include <sys/types.h>
+#endif
+
+namespace moab {
+
+#ifdef MOAB_FORCE_64_BIT_HANDLES
+  typedef uint64_t EntityHandle;
+  typedef  int64_t EntityID;
+#elif defined (MOAB_FORCE_32_BIT_HANDLES)
+  typedef uint32_t EntityHandle;
+  typedef  int32_t EntityID;
+#else
+# ifdef MOAB_HAVE_SIZE_T
+    typedef size_t EntityHandle;
+# else
+    typedef unsigned long EntityHandle;
+# endif
+# ifdef MOAB_HAVE_PTRDIFF_T
+    typedef ptrdiff_t EntityID;
+# else
+    typedef long EntityID;
+# endif
+#endif 
+
+} // namespace moab
+
+#endif

Added: MOAB/trunk/src/moab/EntityType.hpp
===================================================================
--- MOAB/trunk/src/moab/EntityType.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/EntityType.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,12 @@
+#ifndef MOAB_ENTITY_TYPE_HPP
+#define MOAB_ENTITY_TYPE_HPP
+
+namespace moab {
+  #undef MB_ENTITY_TYPE_H
+  #define MOAB_ENTITY_TYPE_NAME EntityType
+  #include "MBEntityType.h"
+  #undef MB_ENTITY_TYPE_H
+}
+
+#endif
+

Copied: MOAB/trunk/src/moab/Forward.hpp (from rev 3583, MOAB/trunk/src/moab/MBForward.hpp)
===================================================================
--- MOAB/trunk/src/moab/Forward.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Forward.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,32 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifndef MOAB_FORWARD_HPP
+#define MOAB_FORWARD_HPP
+
+#include "moab/Types.hpp"
+#include <vector>
+
+namespace moab {
+
+class Interface;
+class Range;
+class ProcConfig;
+
+typedef std::vector<EntityHandle> HandleVec;
+
+} // namespace moab
+
+#endif

Modified: MOAB/trunk/src/moab/GeomTopoTool.hpp
===================================================================
--- MOAB/trunk/src/moab/GeomTopoTool.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/GeomTopoTool.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,69 +15,71 @@
 
 
 
-#ifndef GEOM_TOPO_TOOL_HPP
-#define GEOM_TOPO_TOOL_HPP
+#ifndef MOAB_GEOM_TOPO_TOOL_HPP
+#define MOAB_GEOM_TOPO_TOOL_HPP
 
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
 
+namespace moab {
+
 class GeomTopoTool
 {
 public:
-  GeomTopoTool(MBInterface *impl, bool find_geoments = false);
+  GeomTopoTool(Interface *impl, bool find_geoments = false);
   ~GeomTopoTool() {}
   
     //! Restore parent/child links between GEOM_TOPO mesh sets
-  MBErrorCode restore_topology();
+  ErrorCode restore_topology();
   
     //! Store sense of surface relative to volume.
     //!\return MB_MULTIPLE_ENTITIES_FOUND if surface already has a forward volume.
     //!        MB_SUCCESS if successful
     //!        otherwise whatever internal error code occured.
-  MBErrorCode set_sense( MBEntityHandle surface,
-                         MBEntityHandle volume,
+  ErrorCode set_sense( EntityHandle surface,
+                         EntityHandle volume,
                          bool forward );
 
-  MBErrorCode get_sense( MBEntityHandle surface,
-                         MBEntityHandle volume,
+  ErrorCode get_sense( EntityHandle surface,
+                         EntityHandle volume,
                          bool& forward );
 
-  MBErrorCode find_geomsets(MBRange *ranges = NULL);
+  ErrorCode find_geomsets(Range *ranges = NULL);
 
-  MBErrorCode construct_obb_trees();
+  ErrorCode construct_obb_trees();
 
-  MBErrorCode get_root(MBEntityHandle vol_or_surf, MBEntityHandle &root);
+  ErrorCode get_root(EntityHandle vol_or_surf, EntityHandle &root);
 
-  MBOrientedBoxTreeTool *obb_tree() {return &obbTree;}
+  OrientedBoxTreeTool *obb_tree() {return &obbTree;}
 
 private:
-  MBInterface *mdbImpl;
-  MBTag sense2Tag;
-  MBTag geomTag;
-  MBRange geomRanges[4];
+  Interface *mdbImpl;
+  Tag sense2Tag;
+  Tag geomTag;
+  Range geomRanges[4];
 
-  MBOrientedBoxTreeTool obbTree;
-  MBEntityHandle setOffset;
-  std::vector<MBEntityHandle> rootSets;
+  OrientedBoxTreeTool obbTree;
+  EntityHandle setOffset;
+  std::vector<EntityHandle> rootSets;
   
     //! compute vertices inclusive and put on tag on sets in geom_sets
-  MBErrorCode construct_vertex_ranges(const MBRange &geom_sets,
-				      const MBTag verts_tag);
+  ErrorCode construct_vertex_ranges(const Range &geom_sets,
+				      const Tag verts_tag);
   
     //! given a range of geom topology sets, separate by dimension
-  MBErrorCode separate_by_dimension(const MBRange &geom_sets,
-				    MBRange *entities, MBTag geom_tag = 0);
+  ErrorCode separate_by_dimension(const Range &geom_sets,
+				    Range *entities, Tag geom_tag = 0);
 
-  //MBErrorCode construct_obb_trees(MBEntityHandle& offset,
-  //			  MBRange& rootSets,
-  //			  MBOrientedBoxTreeTool& obbTree);
+  //ErrorCode construct_obb_trees(EntityHandle& offset,
+  //			  Range& rootSets,
+  //			  OrientedBoxTreeTool& obbTree);
   
   
   
 };
 
-inline GeomTopoTool::GeomTopoTool(MBInterface *impl, 
+inline GeomTopoTool::GeomTopoTool(Interface *impl, 
                                   bool find_geoments) 
   : mdbImpl(impl), obbTree(impl), sense2Tag(0) 
 {
@@ -85,12 +87,14 @@
 }
 
 // get the root of the obbtree for a given entity
-inline MBErrorCode GeomTopoTool::get_root(MBEntityHandle vol_or_surf, MBEntityHandle &root) 
+inline ErrorCode GeomTopoTool::get_root(EntityHandle vol_or_surf, EntityHandle &root) 
 {
   unsigned int index = vol_or_surf - setOffset;
   root = (index < rootSets.size() ? rootSets[index] : 0);
   return (root ? MB_SUCCESS : MB_INDEX_OUT_OF_RANGE);
 }
 
+} // namespace moab 
+
 #endif
 

Copied: MOAB/trunk/src/moab/GeomUtil.hpp (from rev 3583, MOAB/trunk/src/moab/MBGeomUtil.hpp)
===================================================================
--- MOAB/trunk/src/moab/GeomUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/GeomUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,299 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file Geometry.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-27
+ */
+
+#ifndef MB_GEOM_UTIL_HPP
+#define MB_GEOM_UTIL_HPP
+
+#include "moab/CartVect.hpp"
+#include <cmath>
+
+namespace moab {
+
+namespace GeomUtil {
+
+/** Given a line segment and an axis-aligned box, 
+ *  return the sub-segment of the line segment that 
+ *  itersects the box.
+ *  
+ *  Can be used to intersect ray with box by passing seg_end
+ *  as HUGE_VAL or std::numeric_limits<double>::maximum().
+ *
+ *\param box_min   Minimum corner of axis-aligned box
+ *\param box_max   Maximum corner of axis-aligned box
+ *\param seg_pt    A point in the line containing the segement
+ *\param seg_unit_dir A unit vector in the direction of the line 
+ *                 containing the semgent.
+ *\param seg_start The distance from seg_pt in the direction of
+ *                 seg_unit_dir at which the segment begins.
+ *                 As input, the start of the original segment, as output, the
+ *                 start of the sub-segment intersecting the box.
+ *                 Note:  seg_start must be less than seg_end
+ *\param seg_end   The distance from seg_pt in the direction of 
+ *                 seg_unit_dir at which the segment ends.
+ *                 As input, the end of the original segment, as output, the
+ *                 end of the sub-segment intersecting the box.
+ *                 Note:  seg_start must be less than seg_end
+ *\return true if line semgent intersects box, false otherwise.
+ */
+bool segment_box_intersect( CartVect box_min,
+                            CartVect box_max,
+                            const CartVect& seg_pt,
+                            const CartVect& seg_unit_dir,
+                            double& seg_start, double& seg_end );
+
+/**\brief Test for intersection between a ray and a triangle.
+ *\param ray_point  The start point of the ray.
+ *\param ray_unit_direciton  The direction of the ray. Must be a unit vector.
+ *\param tolerance  Absolute distance tolerance for point equality
+ *\param t_out Output: The distance along the ray from ray_point in the
+ *                  direction of ray_unit_direction at which the ray
+ *                  itersected the triangle.
+ *\param ray_length Optional:  If non-null, a pointer a maximum length
+ *                  for the ray, converting this function to a segment-tri-
+ *                  intersect test.
+ *\return true if intersection, false otherwise.
+ */
+bool ray_tri_intersect( const CartVect vertices[3],
+                        const CartVect& ray_point,
+                        const CartVect& ray_unit_direction,
+                        double tolerance,
+                        double& t_out,
+                        const double* ray_length = 0 );
+
+
+    //! Find range of overlap between ray and axis-aligned box.
+    //!
+    //!\param box_min   Box corner with minimum coordinate values
+    //!\param box_max   Box corner with minimum coordinate values
+    //!\param ray_pt    Coordinates of start point of ray
+    //!\param ray_dir   Directionion vector for ray such that
+    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
+    //!                 for t > 0.
+    //!\param t_enter   Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray entered the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\param t_exit    Output: if return value is true, this value
+    //!                 is the parameter location along the ray at which
+    //!                 the ray exited the leaf.  If return value is false,
+    //!                 then this value is undefined.
+    //!\return true if ray intersects leaf, false otherwise.
+bool ray_box_intersect( const CartVect& box_min,
+                        const CartVect& box_max,
+                        const CartVect& ray_pt,
+                        const CartVect& ray_dir,
+                        double& t_enter, double& t_exit );
+
+/**\brief Test if plane intersects axis-aligned box
+ *
+ * Test for intersection between an unbounded plane and
+ * an axis-aligned box.
+ *\param plane_normal Vector in plane normal direction (need *not*
+ *                    be a unit vector).  The N in 
+ *                    the plane equation: N . X + D = 0
+ *\param plane_coeff  The scalar 'D' term in the plane equation:
+ *                    N . X + D = 0
+ *\param box_min_corner The smallest coordinates of the box along each
+ *                    axis.  The corner of the box for which all three
+ *                    coordinate values are smaller than those of any
+ *                    other corner.  The X, Y, Z values for the planes
+ *                    normal to those axes and bounding the box on the
+ *                    -X, -Y, and -Z sides respectively.
+ *\param box_max_corner The largest coordinates of the box along each
+ *                    axis.  The corner of the box for which all three
+ *                    coordinate values are larger than those of any
+ *                    other corner.  The X, Y, Z values for the planes
+ *                    normal to those axes and bounding the box on the
+ *                    +X, +Y, and +Z sides respectively.
+ *\return true if overlap, false otherwise.
+ */
+bool box_plane_overlap( const CartVect& plane_normal, 
+                        double            plane_coeff,
+                        CartVect        box_min_corner, 
+                        CartVect        box_max_corner );
+
+/**\brief Test if triangle intersects axis-aligned box
+ *
+ * Test if a triangle intersects an axis-aligned box.
+ *\param triangle_corners  The corners of the triangle.
+ *\param box_min_corner The smallest coordinates of the box along each
+ *                    axis.  The corner of the box for which all three
+ *                    coordinate values are smaller than those of any
+ *                    other corner.  The X, Y, Z values for the planes
+ *                    normal to those axes and bounding the box on the
+ *                    -X, -Y, and -Z sides respectively.
+ *\param box_max_corner The largest coordinates of the box along each
+ *                    axis.  The corner of the box for which all three
+ *                    coordinate values are larger than those of any
+ *                    other corner.  The X, Y, Z values for the planes
+ *                    normal to those axes and bounding the box on the
+ *                    +X, +Y, and +Z sides respectively.
+ *\param tolerance    The tolerance used in the intersection test.  The box
+ *                    size is increased by this amount before the intersection
+ *                    test.
+ *\return true if overlap, false otherwise.
+ */
+bool box_tri_overlap( const CartVect  triangle_corners[3],
+                      const CartVect& box_min_corner,
+                      const CartVect& box_max_corner,
+                      double            tolerance );
+
+/**\brief Test if triangle intersects axis-aligned box
+ *
+ * Test if a triangle intersects an axis-aligned box.
+ *\param triangle_corners  The corners of the triangle.
+ *\param box_center   The center of the box.
+ *\param box_hanf_dims The distance along each axis, respectively, from the
+ *                    box_center to the boundary of the box.
+ *\return true if overlap, false otherwise.
+ */
+bool box_tri_overlap( const CartVect  triangle_corners[3],
+                      const CartVect& box_center,
+                      const CartVect& box_half_dims );
+
+bool box_point_overlap( const CartVect& box_min_corner,
+                        const CartVect& box_max_corner,
+                        const CartVect& point,
+                        double tolerance );
+
+/**\brief Test if the specified element intersects an axis-aligned box.
+ *
+ * Test if element intersects axis-aligned box.  Use element-specific
+ * optimization if available, otherwise call box_general_elem_overlap.
+ *
+ *\param elem_corners The coordinates of the element vertices
+ *\param elem_type    The toplogy of the element.
+ *\param box_center   The center of the axis-aligned box
+ *\param box_half_dims Half of the width of the box in each axial
+ *                     direction.
+ */
+bool box_elem_overlap( const CartVect *elem_corners,
+                       EntityType elem_type,
+                       const CartVect& box_center,
+                       const CartVect& box_half_dims ); 
+
+/**\brief Test if the specified element intersects an axis-aligned box.
+ *
+ * Uses MBCN and separating axis theorem for general algorithm that
+ * works for all fixed-size elements (not poly*).
+ *
+ *\param elem_corners The coordinates of the element vertices
+ *\param elem_type    The toplogy of the element.
+ *\param box_center   The center of the axis-aligned box
+ *\param box_half_dims Half of the width of the box in each axial
+ *                     direction.
+ */
+bool box_linear_elem_overlap( const CartVect *elem_corners,
+                              EntityType elem_type,
+                              const CartVect& box_center,
+                              const CartVect& box_half_dims ); 
+
+/**\brief Test if the specified element intersects an axis-aligned box.
+ *
+ * Uses MBCN and separating axis theorem for general algorithm that
+ * works for all fixed-size elements (not poly*).  Box and element
+ * vertices must be translated such that box center is at origin.
+ *
+ *\param elem_corners The coordinates of the element vertices, in 
+ *                    local coordinate system of box.
+ *\param elem_type    The toplogy of the element.
+ *\param box_half_dims Half of the width of the box in each axial
+ *                     direction.
+ */
+bool box_linear_elem_overlap( const CartVect *elem_corners,
+                              EntityType elem_type,
+                              const CartVect& box_half_dims ); 
+
+void closest_location_on_box( const CartVect& box_min_corner,
+                              const CartVect& box_max_corner,
+                              const CartVect& point,
+                              CartVect& closest );
+
+/**\brief find closest location on triangle
+ *
+ * Find closest location on linear triangle.
+ *\param location  Input position to evaluate from
+ *\param vertices  Array of three corner vertex coordinates.
+ *\param closest_out Result position 
+ */
+void closest_location_on_tri( const CartVect& location,
+                              const CartVect* vertices,
+                              CartVect& closest_out );
+
+/**\brief find closest location on polygon
+ *
+ * Find closest location on polygon
+ *\param location  Input position to evaluate from
+ *\param vertices  Array of corner vertex coordinates.
+ *\param num_vertices Length of 'vertices' array.
+ *\param closest_out Result position 
+ */
+void closest_location_on_polygon( const CartVect& location,
+                                  const CartVect* vertices,
+                                  int num_vertices,
+                                  CartVect& closest_out );
+
+/**\brief find closest topological location on triangle
+ *
+ * Find closest location on linear triangle.
+ *\param location  Input position to evaluate from
+ *\param vertices  Array of three corner vertex coordinates.
+ *\param tolerance Tolerance to use when comparing to corners and edges
+ *\param closest_out Result position 
+ *\param closest_topo Closest topological entity
+ *                     0-2 : vertex index
+ *                     3-5 : edge beginning at closest_topo - 3
+ *                       6 : triangle interior
+ */
+void closest_location_on_tri( const CartVect& location,
+                              const CartVect* vertices,
+                              double tolerance,
+                              CartVect& closest_out,
+                              int& closest_topo );
+
+// Finds whether or not a box defined by the center and the half
+// width intersects a trilinear hex defined by its eight vertices.
+bool box_hex_overlap( const CartVect hexv[8],
+                      const CartVect& box_center,
+                      const CartVect& box_dims);
+
+// Finds whether or not a box defined by the center and the half
+// width intersects a linear tetrahedron defined by its four vertices.
+bool box_tet_overlap( const CartVect tet_corners[4],
+                      const CartVect& box_center,
+                      const CartVect& box_dims);
+
+//
+// point_in_trilinear_hex
+// Tests if a point in xyz space is within a hex element defined with
+// its eight vertex points forming a trilinear basis function.  Computes
+// the natural coordinates with respect to the hex of the xyz point 
+// and checks if each are between +/-1.  If anyone is outside the range
+// the function returns false, otherwise it returns true.
+//
+bool point_in_trilinear_hex(const CartVect *hex, 
+                            const CartVect& xyz,
+                            double etol);
+
+} // namespace GeomUtil
+
+} // namespace moab
+
+#endif

Modified: MOAB/trunk/src/moab/HigherOrderFactory.hpp
===================================================================
--- MOAB/trunk/src/moab/HigherOrderFactory.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/HigherOrderFactory.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,28 +21,31 @@
  *          
  */ 
 
-#ifndef HIGHER_ORDER_FACTORY_HPP
-#define HIGHER_ORDER_FACTORY_HPP
+#ifndef MOAB_HIGHER_ORDER_FACTORY_HPP
+#define MOAB_HIGHER_ORDER_FACTORY_HPP
 
 #ifndef IS_BUILDING_MB
 #error "HigherOrderFactory.hpp isn't supposed to be included into an application"
 #endif
 
-#include "MBInterface.hpp"
+#include "moab/Interface.hpp"
+
+namespace moab {
+
 class ElementSequence;
-class MBCore;
+class Core;
 
 class HigherOrderFactory
 {
 public:
 
-  HigherOrderFactory(MBCore* MB, MBInterface::HONodeAddedRemoved* function_object);
+  HigherOrderFactory(Core* , Interface::HONodeAddedRemoved* function_object);
   ~HigherOrderFactory();
 
-  MBErrorCode convert(const MBEntityHandle meshset, const bool mid_edge_nodes, 
+  ErrorCode convert(const EntityHandle meshset, const bool mid_edge_nodes, 
                        const bool mid_face_nodes, const bool mid_volume_nodes);
 
-  MBErrorCode convert( const MBRange& entities, const bool mid_edge_nodes, 
+  ErrorCode convert( const Range& entities, const bool mid_edge_nodes, 
                        const bool mid_face_nodes, const bool mid_volume_nodes);
 
   unsigned char mNodeMap[MBMAXTYPE][8][8];
@@ -52,69 +55,70 @@
   //static bool mMapInitialized;
   void initialize_map();
 
-  MBCore* mMB;
-  MBInterface::HONodeAddedRemoved* mHONodeAddedRemoved;
+  Core* mMB;
+  Interface::HONodeAddedRemoved* mHONodeAddedRemoved;
 
-  MBErrorCode convert_sequence(ElementSequence* sequence, 
-                               MBEntityHandle sequence_subset_start,
-                               MBEntityHandle sequence_subset_end,
+  ErrorCode convert_sequence(ElementSequence* sequence, 
+                               EntityHandle sequence_subset_start,
+                               EntityHandle sequence_subset_end,
                                bool mid_edge_nodes, 
                                bool mid_face_nodes,
                                bool mid_volume_nodes);
-  MBErrorCode add_mid_edge_nodes(ElementSequence*);
-  MBErrorCode add_mid_face_nodes(ElementSequence*);
-  MBErrorCode add_mid_volume_nodes(ElementSequence*);
+  ErrorCode add_mid_edge_nodes(ElementSequence*);
+  ErrorCode add_mid_face_nodes(ElementSequence*);
+  ErrorCode add_mid_volume_nodes(ElementSequence*);
 
   //! returns the handle of the first center node found between the two corner nodes.
   //! returns zero if none found
   //! entities that share those two corner nodes and have space allocated for mid-edge nodes are returned in a vector
-  MBEntityHandle center_node_exist(MBEntityHandle corner1, MBEntityHandle corner2,
-         std::vector<MBEntityHandle>& adj_entities);
+  EntityHandle center_node_exist(EntityHandle corner1, EntityHandle corner2,
+         std::vector<EntityHandle>& adj_entities);
   
   //! returns the handle of the first center node found between the 3-4 corner nodes.
   //! set the last node to zero if you want only 3 nodes
   //! returns zero if none found
   //! entities that share those corner nodes and have space allocated for mid face nodes are returned in a vector
-  MBEntityHandle center_node_exist(MBEntityHandle corners[4], std::vector<MBEntityHandle>& adj_entities);
+  EntityHandle center_node_exist(EntityHandle corners[4], std::vector<EntityHandle>& adj_entities);
 
   //! adds a center node to element between corner nodes, returns success
-  bool add_center_node(MBEntityType type, MBEntityHandle* element_conn, int conn_size, 
-      MBEntityHandle corner_node1, MBEntityHandle corner_node2, MBEntityHandle center_node);
+  bool add_center_node(EntityType type, EntityHandle* element_conn, int conn_size, 
+      EntityHandle corner_node1, EntityHandle corner_node2, EntityHandle center_node);
 
 
-  MBErrorCode copy_corner_nodes( ElementSequence* src, ElementSequence* dst );
-  MBErrorCode copy_mid_edge_nodes( ElementSequence* src, ElementSequence* dst ); 
-  MBErrorCode copy_mid_face_nodes( ElementSequence* src, ElementSequence* dst ); 
-  MBErrorCode copy_mid_volume_nodes( ElementSequence* src, ElementSequence* dst ); 
-  MBErrorCode copy_nodes( ElementSequence* src, 
+  ErrorCode copy_corner_nodes( ElementSequence* src, ElementSequence* dst );
+  ErrorCode copy_mid_edge_nodes( ElementSequence* src, ElementSequence* dst ); 
+  ErrorCode copy_mid_face_nodes( ElementSequence* src, ElementSequence* dst ); 
+  ErrorCode copy_mid_volume_nodes( ElementSequence* src, ElementSequence* dst ); 
+  ErrorCode copy_nodes( ElementSequence* src, 
                           ElementSequence* dst,
                           unsigned nodes_per_elem_to_copy,
                           unsigned src_conn_offset,
                           unsigned dst_conn_offset ); 
 
-  MBErrorCode remove_mid_edge_nodes( ElementSequence* seq, 
-                                     MBEntityHandle start,
-                                     MBEntityHandle stop,
-                                     MBTag deletable_ndoes );
-  MBErrorCode remove_mid_face_nodes( ElementSequence* seq, 
-                                     MBEntityHandle start,
-                                     MBEntityHandle stop,
-                                     MBTag deletable_ndoes );
-  MBErrorCode remove_mid_volume_nodes( ElementSequence* seq, 
-                                       MBEntityHandle start,
-                                       MBEntityHandle stop,
-                                       MBTag deletable_ndoes );
-  MBErrorCode remove_ho_nodes( ElementSequence* sequence,
-                               MBEntityHandle subset_start_handle,
-                               MBEntityHandle subset_end_handle,
+  ErrorCode remove_mid_edge_nodes( ElementSequence* seq, 
+                                     EntityHandle start,
+                                     EntityHandle stop,
+                                     Tag deletable_ndoes );
+  ErrorCode remove_mid_face_nodes( ElementSequence* seq, 
+                                     EntityHandle start,
+                                     EntityHandle stop,
+                                     Tag deletable_ndoes );
+  ErrorCode remove_mid_volume_nodes( ElementSequence* seq, 
+                                       EntityHandle start,
+                                       EntityHandle stop,
+                                       Tag deletable_ndoes );
+  ErrorCode remove_ho_nodes( ElementSequence* sequence,
+                               EntityHandle subset_start_handle,
+                               EntityHandle subset_end_handle,
                                int nodes_per_elem_to_remove,
                                int elem_conn_offset_to_remove,
-                               MBTag deletable_nodes );
-  bool tag_for_deletion( MBEntityHandle element_with_node,
+                               Tag deletable_nodes );
+  bool tag_for_deletion( EntityHandle element_with_node,
                          int node_index_in_elem_connectivity,
                          ElementSequence* sequence );
 };
 
+} // namespace moab 
 
 #endif
 

Modified: MOAB/trunk/src/moab/HomXform.hpp
===================================================================
--- MOAB/trunk/src/moab/HomXform.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/HomXform.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,8 +13,8 @@
  * 
  */
 
-#ifndef HOMXFORM
-#define HOMXFORM
+#ifndef MOAB_HOMXFORM
+#define MOAB_HOMXFORM
 
 //
 // Class: HomXform
@@ -31,6 +31,8 @@
 
 #include <math.h>
 
+namespace moab {
+
 class HomXform;
 
 class HomCoord 
@@ -703,4 +705,6 @@
     1);
 }
 
+} // namespace moab 
+
 #endif

Copied: MOAB/trunk/src/moab/Interface.hpp (from rev 3583, MOAB/trunk/src/moab/MBInterface.hpp)
===================================================================
--- MOAB/trunk/src/moab/Interface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Interface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1802 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class Interface
+ * \brief Main interface class to MOAB
+ * \author Tim Tautges, Karl Merkley, Ray Meyers, Corey Ernst, Clinton Stimpson,
+ * \author Hong-Jun Kim, Jason Kraftcheck
+ * \version 1.00
+ * \date April, 2004
+ */
+#ifndef MOAB_INTERFACE_HPP
+#define MOAB_INTERFACE_HPP
+
+#define MOAB_API_VERSION 1.01
+#define MOAB_API_VERSION_STRING "1.01"
+
+#include "moab/Forward.hpp"
+
+// include files
+#include <string>
+#include <functional>
+
+
+//! component architecture definitions
+#ifdef XPCOM_MB
+
+#ifndef __gen_nsISupports_h__
+#include "nsISupports.h"
+#endif
+
+#ifndef NS_NO_VTABLE
+#define NS_NO_VTABLE
+#endif
+
+#define MBINTERFACE_IID_STR "f728830e-1dd1-11b2-9598-fb9f414f2465"
+
+{0xf728830e, 0x1dd1, 0x11b2, \
+  { 0x95, 0x98, 0xfb, 0x9f, 0x4
+#define MBINTERFACE_IID \1, 0x4f, 0x24, 0x65 }}
+
+#endif
+
+
+#include "moab/UnknownInterface.hpp"
+#define MB_INTERFACE_VERSION "2.0.0"
+namespace moab {
+
+static const MBuuid IDD_MBCore = MBuuid( 0x8956e0a, 0xc300, 0x4005,
+                                         0xbd, 0xf6, 0xc3, 0x4e, 0xf7, 0x1f, 0x5a, 0x52 );
+
+
+
+#if defined(XPCOM_MB)
+class NS_NO_VTABLE Interface : public nsISupports {
+#else
+class MB_DLL_EXPORT Interface : public UnknownInterface {
+#endif
+
+public:
+
+#ifdef XPCOM_MB
+  NS_DEFINE_STATIC_IID_ACCESSOR(MBINTERFACE_IID)
+#endif
+
+      //! \name Interface-level functions
+
+      //@{
+
+      //! constructor
+  Interface() {}
+
+    //! destructor
+  virtual ~Interface() {}
+
+    //! return the entity set representing the whole mesh
+  virtual EntityHandle get_root_set()=0;
+  
+    //! query an MB internal interface
+  virtual ErrorCode query_interface(const std::string& iface_name, void** iface)=0;
+ 
+    //! release an MB internal interface 
+  virtual ErrorCode release_interface(const std::string& iface_name, void* iface)=0;
+
+    //! Returns the major.minor version number of the interface
+    /**
+       \param version_string If non-NULL, will be filled in with a string, possibly 
+       containing implementation-specific information
+    */
+  virtual float api_version(std::string *version_string = NULL);
+    
+    //! Returns the major.minor version number of the implementation
+    /**
+       \param version_string If non-NULL, will be filled in with a string, possibly 
+       containing implementation-specific information
+    */
+  virtual float impl_version(std::string *version_string = NULL)=0;
+
+    //@}    
+
+    //! \name Type and id utility functions
+
+    //@{
+
+    //! Returns the entity type of an EntityHandle.
+    /** Returns the EntityType (ie, MeshVertex, MeshQuad, MeshHex ) of <em>handle</em>.
+        \param handle The EntityHandle you want to find the entity type of.
+        \return type The entity type of <em>handle</em>. 
+
+        Example: \code
+        EntityType type = type_from_handle( handle); 
+        if( type == MeshHex ) ...  \endcode 
+    */
+  virtual EntityType type_from_handle(const EntityHandle handle) const = 0;
+ 
+    //! Returns the id from an EntityHandle.
+    /** \param handle The EntityHandle you want to find the id of. 
+        \return id Id of <em>handle</em>
+     
+        Example: \code
+        int id = id_from_handle(handle); \endcode 
+    */
+  virtual EntityID id_from_handle(const EntityHandle handle) const =0;
+
+    //! Returns the topological dimension of an entity
+    /** Returns the EntityType (ie, MeshVertex, MeshQuad, MeshHex ) of <em>handle</em>.
+        \param handle The EntityHandle you want to find the dimension of.
+        \return type The topological dimension of <em>handle</em>. 
+
+        Example: \code
+        int dim = dimension_from_handle( handle); 
+        if( dim == 0 ) ...  \endcode 
+    */
+  virtual int dimension_from_handle(const EntityHandle handle) const = 0;
+
+    //! Gets an entity handle from the data base, if it exists, according to type and id.
+    /** Given an EntiyType and an id, this function gets the existent EntityHandle. 
+        If no such EntityHandle exits, it returns MB_ENTITY_NOT_FOUND 
+        and sets handle to zero.
+        \param type The type of the EntityHandle to retrieve from the database.
+        \param id The id of the EntityHandle to retrieve from the database.
+        \param handle An EntityHandle of type <em>type</em> and <em>id</em>. 
+
+        Example: \code
+        EntityType handle;
+        ErrorCode error_code = handle_from_id(MeshTri, 204, handle );
+        if( error_code == MB_ENTITY_NOT_FOUND ) ... \endcode
+    */
+  virtual ErrorCode handle_from_id(const EntityType type, 
+                                     const EntityID, 
+                                     EntityHandle& handle) const =0;
+
+    //@}
+
+    //! \name Mesh input/output functions
+
+    //@{
+
+    //! Loads a mesh file into the database.
+    /** Loads the file 'file_name'; types of mesh which can be loaded 
+        depend on modules available at MB compile time.  If 
+        active_block_id_list is NULL, all material sets (blocks in the 
+        ExodusII jargon) are loaded.  Individual material sets  can be 
+        loaded by specifying their ids in 'active_block_id_list'.  All 
+        nodes are loaded on first call for a given file.  Subsequent 
+        calls for a file load any material sets not loaded in previous 
+        calls.
+        \param file_name Name of file to load into database.
+        \param active_block_id_list Material set/block ids to load.  
+                If NULL, ALL blocks of <em>file_name</em> are loaded.
+        \param num_blocks Number of blocks in active_block_id_list
+
+        Example: \code
+        std::vector<int> active_block_id_list;
+        int active_block_id_list[] = {1, 4, 10};
+        load_mesh( "temp.gen", active_block_id_list, 3 );  //load blocks 1, 4, 10 
+        \endcode 
+    */
+  virtual ErrorCode load_mesh(const char *file_name,
+                                const int *active_block_id_list = NULL,
+                                const int num_blocks = 0)=0;
+
+  /**\brief Load or import a file.
+   *
+   * Load a MOAB-native file or import data from some other supported
+   * file format.
+   *
+   *\param file_name The location of the file to read.
+   *\param file_set  Output: a handle to a new set containing all entities 
+   *                        read or imported from the file.
+   *\param options A list of string options, separated by semicolons (;).
+   *               See README.IO for more information.  Options are typically
+   *               format-specific options or parallel options.  If an
+   *               option value is unrecognized but the file read otherwise
+   *               succeeded, MB_UNHANDLED_OPTION will be returned.
+   *\param set_tag_name The name of a tag used to designate the subset
+   *               of the file to read.  The name must correspond to 
+   *               data in the file that will be instantiated in MOAB
+   *               as a tag.  
+   *\param set_tag_values If the name specified in 'set_tag_name'
+   *               corresponds to a tag with a single integer value,
+   *               the values in this tag can be used to further
+   *               limit the subset of data written from the file to
+   *               only those entities or sets that have a value for
+   *               the tag that is one of the values in this array.
+   *\param num_set_tag_values The length of set_tag_values.
+   */
+  virtual ErrorCode load_file( const char* file_name,
+                                 const EntityHandle* file_set = 0,
+                                 const char* options = 0,
+                                 const char* set_tag_name = 0,
+                                 const int* set_tag_values = 0,
+                                 int num_set_tag_values = 0 ) = 0;
+
+    //! Writes mesh to a file.
+    /** Write mesh to file 'file_name'; if output_list is non-NULL, only 
+        material sets contained in that list will be written.
+        \param file_name Name of file to write.
+        \param output_list 1d array of material set handles to write; if 
+                           NULL, all sets are written
+        \param num_sets Number of sets in output_list array
+
+        Example: \code
+        EntityHandle output_list[] = {meshset1, meshset2, meshset3}; 
+        write_mesh( "output_file.gen", output_list, 3 ); \endcode 
+    */
+  virtual ErrorCode write_mesh(const char *file_name,
+                                 const EntityHandle *output_list = NULL,
+                                 const int num_sets = 0) = 0;
+
+  /**\brief Write or export a file.
+   * 
+   * Write a MOAB-native file or export data to some other supported
+   * file format.
+   *
+   *\param file_name The location of the file to write.
+   *\param file_type The type of the file.  If this value is NULL, 
+   *                 then file type will be determined using the 
+   *                 file name suffix.  
+   *\param options   A semicolon-separated list of options.
+   *                 See README.IO for more information.  Typical options
+   *                 include the file type, parallel options, and options
+   *                 specific to certain file formats.
+   *\param output_sets A list of entity sets to write to the file.  If
+   *                 no sets are sepcified, the default behavior is to
+   *                 write all data that is supported by the target file
+   *                 type.
+   *\param num_output_sets The length of the output_sets array.
+   *\param tag_list A list of tags for which to write the tag data.  The
+   *                write may fail if a tag list is specified but the 
+   *                target file type is not capable of representing the
+   *                data.  If no tags are specified, the default is to
+   *                write whatever data the target file format supports.
+   *\param num_tags The length of tag_list.
+   */
+  virtual ErrorCode write_file( const char* file_name,
+                                  const char* file_type = 0,
+                                  const char* options = 0,
+                                  const EntityHandle* output_sets = 0,
+                                  int num_output_sets = 0,
+                                  const Tag* tag_list = 0,
+                                  int num_tags = 0 ) = 0;
+
+  /**\brief Write or export a file.
+   * 
+   * Write a MOAB-native file or export data to some other supported
+   * file format.
+   *
+   *\param file_name The location of the file to write.
+   *\param file_type The type of the file.  If this value is NULL, 
+   *                 then file type will be determined using the 
+   *                 file name suffix.  
+   *\param options   A semicolon-separated list of options.
+   *                 See README.IO for more information.  Typical options
+   *                 include the file type, parallel options, and options
+   *                 specific to certain file formats.
+   *\param output_sets A list of entity sets to write to the file.  If
+   *                 no sets are sepcified, the default behavior is to
+   *                 write all data that is supported by the target file
+   *                 type.
+   *\param tag_list A list of tags for which to write the tag data.  The
+   *                write may fail if a tag list is specified but the 
+   *                target file type is not capable of representing the
+   *                data.  If no tags are specified, the default is to
+   *                write whatever data the target file format supports.
+   *\param num_tags The length of tag_list.
+   */
+  virtual ErrorCode write_file( const char* file_name,
+                                  const char* file_type,
+                                  const char* options,
+                                  const Range& output_sets,
+                                  const Tag* tag_list = 0,
+                                  int num_tags = 0 ) = 0;
+
+    //! Deletes all mesh entities from this MB instance
+  virtual ErrorCode delete_mesh()=0;
+
+    //@}
+
+    //! \name Geometric dimension functions
+
+    //@{
+
+    //! Get overall geometric dimension
+  virtual ErrorCode get_dimension(int &dim) const =0;
+
+    //! Set overall geometric dimension
+    /** Returns error if setting to 3 dimensions, mesh has been created, and 
+     *  there are only 2 dimensions on that mesh
+     */
+  virtual ErrorCode set_dimension(const int dim)=0;
+
+    //@}
+
+    //! \name Vertex coordinate functions
+
+    //@{
+
+    //! Get blocked vertex coordinates for all vertices
+    /** Blocked = all x, then all y, etc. 
+          
+    Example: \code
+    std::vector<double> coords;
+    get_vertex_coordinates(coords);
+    double xavg = 0;
+    for (int i = 0; i < coords.size()/3; i++) xavg += coords[i]; \endcode
+    */
+  virtual ErrorCode get_vertex_coordinates(std::vector<double> &coords) const =0;
+
+    //! Gets xyz coordinate information for range of vertices
+    /** Length of 'coords' should be at least 3*<em>entity_handles.size()</em> before making call.
+        \param entity_handles Range of vertex handles (error if not of type MeshVertex)
+        \param coords Array used to return x, y, and z coordinates.
+   
+        Example: \code 
+        double coords[3];
+        get_coords( vertex_handle, coords ); 
+        std::cout<<"x = "<<coords[0]<<std::endl;
+        std::cout<<"y = "<<coords[1]<<std::endl;
+        std::cout<<"z = "<<coords[2]<<std::endl; \endcode 
+    */
+  virtual ErrorCode  get_coords(const Range& entity_handles, 
+                                  double *coords) const =0;
+    
+    //! Gets xyz coordinate information for vector of vertices
+    /** Identical to range-based function, except entity handles are specified using a 1d vector
+        and vector length.
+    */
+  virtual ErrorCode  get_coords(const EntityHandle* entity_handles, 
+                                  const int num_entities, 
+                                  double *coords) const =0;
+  
+  /**\brief Get vertex coordinates in blocks by dimension.
+   *
+   * Get the X, Y, and Z coordinates of a group of vertices.  
+   * Coordinates are returned in separate arrays, one for each 
+   * dimension.  Each coordinate array must be of sufficient
+   * length to hold the coordinate value for each vertex.  Array
+   * pointers may be NULL if coordinates in the the respective 
+   * dimension are not desired.
+   *\param entity_handles  The group of vertex handles for which to get the coordiantes.
+   *\param x_coords        Output: the X coordinate of each vertex.  May be NULL.
+   *\param y_coords        Output: the Y coordinate of each vertex.  May be NULL.
+   *\param z_coords        Output: the Z coordinate of each vertex.  May be NULL.
+   */
+  virtual ErrorCode get_coords( const Range& entity_handles,
+                                  double* x_coords,
+                                  double* y_coords,
+                                  double* z_coords ) const = 0;
+  
+  
+    //! Sets the xyz coordinates for a vector of vertices
+    /** An error is returned if any entities in the vector are not vertices.
+        \param entity_handles EntityHandle's to set coordinates of. (Must be of type MeshVertex)
+        \param num_entities Number of entities in entity_handles
+        \param coords Array containing new xyz coordinates.
+ 
+        Example: \code
+        double coords[3] = {0.234, -2.52, 12.023};
+        set_coords( entity_handle, 1, coords ); \endcode 
+    */
+  virtual ErrorCode  set_coords(const EntityHandle *entity_handles, 
+                                  const int num_entities,
+                                  const double *coords)=0;
+
+    //! Sets the xyz coordinates for a vector of vertices
+    /** An error is returned if any entities in the vector are not vertices.
+        \param entity_handles EntityHandle's to set coordinates of. (Must be of type MeshVertex)
+        \param num_entities Number of entities in entity_handles
+        \param coords Array containing new xyz coordinates.
+ 
+        Example: \code
+        double coords[3] = {0.234, -2.52, 12.023};
+        set_coords( entity_handle, 1, coords ); \endcode 
+    */
+  virtual ErrorCode  set_coords(Range entity_handles,
+                                  const double *coords)=0;
+
+    //@}
+
+    //! \name Connectivity functions
+
+    //@{
+
+    //! Get the connectivity array for all entities of the specified entity type
+    /**  This function returns the connectivity of just the corner vertices, no higher order nodes
+         \param type The entity type of elements whose connectivity is to be returned
+         \param connect an STL vector used to return connectivity array (in the form of entity handles)
+    */
+  virtual ErrorCode get_connectivity_by_type(const EntityType type, 
+                                               std::vector<EntityHandle> &connect) const =0;
+
+    //! Gets the connectivity for a vector of elements
+    /** Same as vector-based version except range is returned (unordered!)
+    */
+  virtual ErrorCode  get_connectivity(const EntityHandle *entity_handles, 
+                                        const int num_handles,
+                                        Range &connectivity, 
+                                        bool topological_connectivity = false) const =0;
+
+    //! Gets the connectivity for elements
+    /** Same as vector-based version except range is returned (unordered!)
+    */
+  virtual ErrorCode get_connectivity( const Range& entity_handles, 
+                                        Range &connectivity, 
+                                        bool topological_connectivity = false) const =0;
+ 
+    //! Gets the connectivity for a vector of elements
+    /** Corner vertices or all vertices (including higher-order nodes, if any) are returned.
+        For non-element handles (ie, MB_MeshSets), returns an error. Connectivity data is copied 
+        from the database into the vector.  Connectivity of a vertex is the same vertex.
+        The nodes in <em>connectivity</em> are properly ordered according to that element's 
+        canonical ordering.
+        \param entity_handles Vector of element handles to get connectivity of.
+        \param num_handles Number of entity handles in <em>entity_handles</em>
+        \param connectivity Vector in which connectivity of <em>entity_handles</em> is returned.  
+        \param topological_connectivity If true, higher order nodes are ignored. 
+    */
+  virtual ErrorCode  get_connectivity(const EntityHandle *entity_handles, 
+                                        const int num_handles,
+                                        std::vector<EntityHandle> &connectivity, 
+                                        bool topological_connectivity = false) const =0;
+ 
+    //! Gets a pointer to constant connectivity data of <em>entity_handle</em> 
+    /** Sets <em>number_nodes</em> equal to the number of nodes of the <em> 
+        entity_handle </em>.  Faster then the other <em>get_connectivity</em> function because no
+        data is copied.  The nodes in 'connectivity' are properly ordered according to the 
+        element's canonical ordering.
+        
+
+          Example: \code 
+          const EntityHandle* conn;
+          int number_nodes = 0;
+          get_connectivity( entity_handle, conn, number_nodes ); \endcode 
+          
+          Example2: \code
+          std::vector<EntityHandle> sm_storage;
+          const EntityHandle* conn;
+          int number_nodes;
+          get_connectivity( handle, conn, number_nodes, false, &sm_storage );
+          if (conn == &sm_storage[0])
+            std::cout << "Structured mesh element" << std::endl;
+          \endcode
+        
+        \param entity_handle EntityHandle to get connectivity of.
+        \param connectivity Array in which connectivity of <em>entity_handle</em> is returned.
+        \param num_nodes Number of MeshVertices in array <em>connectivity</em>. 
+        \param topological_connectivity If true, num_nodes will be set to number of corner vertices
+        for that element type.
+        \param storage Some elements (e.g. structured mesh) may not have an
+                       explicit connectivity list.  This function will normally
+                       return MB_NOT_IMPLEMENTED for such elements.  However,
+                       if the caller passes in a non-null value for this 
+                       argument, space will be allocated in this vector for
+                       the connectivity data and the connectivity pointer will
+                       be set to the data in this vector.
+    */
+  virtual ErrorCode  get_connectivity(const EntityHandle entity_handle, 
+                                        const EntityHandle *&connectivity, 
+                                        int &num_nodes, 
+                                        bool topological_connectivity = false,
+                                        std::vector<EntityHandle>* storage = 0
+                                        ) const =0;
+
+    //! Sets the connectivity for an EntityHandle.  For non-element handles, return an error.
+    /** Connectivity is stored exactly as it is ordered in vector <em>connectivity</em>. 
+        \param entity_handle EntityHandle to set connectivity of.
+        \param connect Vector containing new connectivity of <em>entity_handle</em>.
+        \param num_connect Number of vertices in <em>connect</em>
+   
+        Example: \code 
+        EntityHandle conn[] = {node1, node2, node3};
+        set_connectivity( tri_element, conn, 3 ); \endcode 
+    */
+  virtual ErrorCode  set_connectivity(const EntityHandle entity_handle, 
+                                        EntityHandle *connect,
+                                        const int num_connect)=0;
+
+    //! Sets the connectivity for an EntityHandle.  For non-element handles, return an error.
+    //@}
+
+    //! \name Adjacencies functions 
+
+    //@{
+
+    //! Get the adjacencies associated with a vector of entities to entities of a specfied dimension.
+    /** \param from_entities Vector of EntityHandle to get adjacencies of.
+        \param num_entities Number of entities in <em>from_entities</em>
+        \param to_dimension Dimension of desired adjacencies
+        \param create_if_missing If true, MB will create any entities of the specfied dimension
+        which have not yet been created (only useful when <em>to_dimension < dim(*from_entities)</em>)
+        \param adj_entities STL vector to which adjacent entities are appended. 
+        \param operation_type Enum of INTERSECT or UNION.  Defines whether to take
+        the intersection or union of the set of adjacencies recovered for the from_entities.
+
+        The adjacent entities in vector <em>adjacencies</em> are not in any particular 
+        order. 
+
+        Example: \code
+        std::vector<EntityHandle> adjacencies, from_entities = {hex1, hex2};
+          // generate all edges for these two hexes
+          get_adjacencies( from_entities, 2, 1, true, adjacencies, Interface::UNION); 
+          adjacencies.clear();
+            // now find the edges common to both hexes
+            get_adjacencies( from_entities, 2, 1, false, adjacencies, Interface::INTERSECT); 
+            \endcode 
+    */
+  virtual ErrorCode get_adjacencies(const EntityHandle *from_entities,
+                                      const int num_entities,
+                                      const int to_dimension,
+                                      const bool create_if_missing,
+                                      std::vector<EntityHandle>& adj_entities,
+                                      const int operation_type = Interface::INTERSECT) = 0;
+
+    //! Get the adjacencies associated with a vector of entities to entities of a specfied dimension.
+    /** Identical to vector-based get_adjacencies function, except results are returned in a
+        range instead of a vector.
+    */
+  virtual ErrorCode get_adjacencies(const EntityHandle *from_entities,
+                                      const int num_entities,
+                                      const int to_dimension,
+                                      const bool create_if_missing,
+                                      Range &adj_entities,
+                                      const int operation_type = Interface::INTERSECT) = 0;
+
+    //! Get the adjacencies associated with a range of entities to entities of a specfied dimension.
+    /** Identical to vector-based get_adjacencies function, except "from" entities specified in a
+        range instead of a vector.
+    */
+  virtual ErrorCode get_adjacencies(const Range &from_entities,
+                                      const int to_dimension,
+                                      const bool create_if_missing,
+                                      Range &adj_entities,
+                                      const int operation_type = Interface::INTERSECT) = 0;
+
+    //! Adds adjacencies between "from" and "to" entities.
+    /** \param from_handle Entities on which the adjacencies are placed
+        \param to_handles Vector of entities referenced by new adjacencies added to <em>from_handle</em>
+        \param num_handles Number of entities in <em>to_handles</em>
+        \param both_ways If true, add the adjacency information in both directions; if false,
+        adjacencies are added only to <em>from_handle</em>
+    */
+  virtual ErrorCode add_adjacencies(const EntityHandle from_handle, 
+                                      const EntityHandle *to_handles,
+                                      const int num_handles,
+                                      bool both_ways) = 0;
+
+    //! Adds adjacencies; same as vector-based, but with range instead
+  virtual ErrorCode add_adjacencies(const EntityHandle from_handle, 
+                                      Range &adjacencies,
+                                      bool both_ways) = 0;
+
+    //! Removes adjacencies between handles.
+    /** Adjacencies in both directions are removed.
+        \param from_handle Entity from which adjacencies are being removed.
+        \param to_handles Entities to which adjacencies are being removed.
+        \param num_handles Number of handles in <em>to_handles</em>
+    */
+  virtual ErrorCode remove_adjacencies(const EntityHandle from_handle, 
+                                         const EntityHandle *to_handles,
+                                         const int num_handles) = 0;
+
+    //@}
+
+    //! Enumerated type used in get_adjacencies() and other functions
+  enum {INTERSECT, UNION};
+
+    //! \name Functions for getting entities
+
+    //@{
+
+    //! Retrieves all entities of a given topological dimension in the database or meshset.
+    /** Appends entities to list passed in.
+        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
+        \param dimension Topological dimension of entities desired.
+        \param entities Range in which entities of dimension <em>dimension</em> are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves if true.
+
+        Example: \code
+          // get 1d (edge) elements in the entire mesh
+          Range edges;
+          get_entities_by_dimension( 0, 1, edges );
+          \endcode 
+    */
+  virtual ErrorCode get_entities_by_dimension(const EntityHandle meshset,
+                                                const int dimension, 
+                                                Range &entities,
+                                                const bool recursive = false)  const = 0;
+
+  virtual ErrorCode get_entities_by_dimension(const EntityHandle meshset,
+                                                const int dimension, 
+                                                std::vector<EntityHandle> &entities,
+                                                const bool recursive = false)  const = 0;
+
+    //! Retrieve all entities of a given type in the database or meshset.
+    /** Appends entities to list passed in.
+        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
+        \param type Type of entities to be returned
+        \param entities Range in which entities of type <em>type</em> are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves.  Specifying 
+                         both recursive=true and type=MBENTITYSET is an error, as it would always 
+                         result in an empty list.
+
+        Example: \code
+          // get the quadrilateral elements in meshset
+          Range quads;
+          get_entities_by_type( meshset, MeshQuad, quads );
+          \endcode 
+    */
+  virtual ErrorCode get_entities_by_type(const EntityHandle meshset,
+                                           const EntityType type, 
+                                           Range &entities,
+                                           const bool recursive = false) const = 0;
+
+  virtual ErrorCode get_entities_by_type(const EntityHandle meshset,
+                                           const EntityType type, 
+                                           std::vector<EntityHandle> &entities,
+                                           const bool recursive = false) const = 0;
+
+    //! Retrieve entities in the database or meshset which have any or all of the tag(s) and (optionally)
+    //! value(s) specified.
+    /** \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
+        \param type Type of entities to be returned
+        \param tag_handles Vector of tag handles entities must have
+        \param values Vector of pointers to values of tags in <em>tag_handles</em>
+        \param num_tags Number of tags and values in <em>tag_handles</em> and <em>values</em>
+        \param entities Range in which entities are returned.
+        \param condition Boolean condition, either Interface::UNION or Interface::INTERSECT
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves.  Specifying 
+                         both recursive=true and type=MBENTITYSET is an error, as it would always 
+                         result in an empty list.
+
+        If Interface::UNION is specified as the condition, entities with <em>any</em> of the tags
+        and values specified are returned.  If Interface::INTERSECT is specified, only entities with
+        <em>all</em> of the tags/values are returned.
+
+        If <em>values</em> is NULL, entities with the specified tags and any corresponding values are
+        returned.  Note that if <em>values</em> is non-NULL, it is a vector of <em>pointers</em> to
+        tag values.
+
+        Example: \code
+          // get the dirichlet sets in a mesh
+          Range dir_sets;
+          Tag dir_tag;
+          tag_get_handle(DIRICHLET_SET_TAG_NAME, dir_tag);
+          get_entities_by_type_and_tag(0, MeshEntitySet, &dir_tag, NULL, 1, dir_sets, 
+          Interface::UNION);
+          \endcode 
+    */
+  virtual ErrorCode get_entities_by_type_and_tag(const EntityHandle meshset,
+                                                   const EntityType type,
+                                                   const Tag *tag_handles,
+                                                   const void* const* values,
+                                                   const int num_tags,
+                                                   Range &entities,
+                                                   const int condition = Interface::INTERSECT,
+                                                   const bool recursive = false) const = 0;
+
+    //! Returns all entities in the data base or meshset, in a range (order not preserved)
+    /** Appends entities to list passed in.
+        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
+        \param entities Range in which entities are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves if true.
+
+        Example: \code
+        Range entities;
+          // get all non-meshset entities in meshset, including in contained meshsets
+          get_entities_by_handle(meshset, entities, true);
+          \endcode 
+    */
+  virtual ErrorCode get_entities_by_handle(const EntityHandle meshset,
+                                             Range &entities,
+                                             const bool recursive = false) const = 0;
+
+    //! Returns all entities in the data base or meshset, in a vector (order preserved)
+    /** Appends entities to list passed in.
+        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
+        \param entities STL vector in which entities are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves if true.
+
+        Example: \code
+        std::vector<EntityHandle> entities;
+          // get all non-meshset entities in meshset, including in contained meshsets
+          get_entities_by_handle(meshset, entities, true);
+          \endcode 
+    */
+  virtual ErrorCode get_entities_by_handle(const EntityHandle meshset,
+                                             std::vector<EntityHandle> &entities,
+                                             const bool recursive = false) const = 0;
+
+    //! Return the number of entities of given dimension in the database or meshset
+    /** \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
+        \param dimension Dimension of entities desired.
+        \param num_entities Number of entities of the given dimension
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves if true.
+    */
+  virtual ErrorCode get_number_entities_by_dimension(const EntityHandle meshset,
+                                                       const int dimension, 
+                                                       int &num_entities,
+                                                       const bool recursive = false) const = 0;
+
+    //! Retrieve the number of entities of a given type in the database or meshset.
+    /** Identical to get_entities_by_dimension, except returns number instead of entities
+        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
+        \param type Type of entities to be returned
+        \param num_entities Number of entities of type <em>type</em>
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves.  Specifying 
+                         both recursive=true and type=MBENTITYSET is an error, as it would always 
+                         result in an empty list.
+    */
+  virtual ErrorCode get_number_entities_by_type(const EntityHandle meshset,
+                                                  const EntityType type, 
+                                                  int &num_entities,
+                                                  const bool recursive = false) const = 0;
+
+    //! Retrieve number of entities in the database or meshset which have any or all of the 
+    //! tag(s) and (optionally) value(s) specified.
+    /** Identical to get_entities_by_type_and_tag, except number instead of entities are returned
+        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
+        \param type Type of entities to be returned
+        \param tag_handles Vector of tag handles entities must have
+        \param values Vector of pointers to values of tags in <em>tag_handles</em>
+        \param num_tags Number of tags and values in <em>tag_handles</em> and <em>values</em>
+        \param num_entities Range in which number of entities are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves.  Specifying 
+                         both recursive=true and type=MBENTITYSET is an error, as it would always 
+                         result in an empty list.
+    */
+  virtual ErrorCode get_number_entities_by_type_and_tag(const EntityHandle meshset,
+                                                          const EntityType type,
+                                                          const Tag *tag_handles,
+                                                          const void* const* values,
+                                                          const int num_tags,
+                                                          int &num_entities,
+                                                          const bool recursive = false) const = 0;
+
+    //! Returns number of entities in the data base or meshset
+    /** Identical to get-entities_by_handle, except number instead of entities are returned
+        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
+        \param num_entities Range in which num_entities are returned.
+        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
+                         the contents of meshsets, but not the meshsets themselves if true.
+    */
+  virtual ErrorCode get_number_entities_by_handle(const EntityHandle meshset,
+                                                    int &num_entities,
+                                                    const bool recursive = false) const = 0;
+
+    //@}
+
+    //! \name Modifying the mesh
+
+    //@{
+
+    //! Create an element based on the type and connectivity. 
+    /** Create a new element in the database.  Vertices composing this element must already exist,
+        and connectivity must be specified in canonical order for the given element type.  If 
+        connectivity vector is not correct for EntityType <em>type</em> (ie, a vector with 
+        3 vertices is passed in to make an MeshQuad), the function returns MB_FAILURE. 
+        \param type Type of element to create. (MeshTet, MeshTri, MeshKnife, etc.) 
+        \param connectivity 1d vector containing connectivity of element to create.
+        \param num_vertices Number of vertices in element
+        \param element_handle Handle representing the newly created element in the database.
+
+        Example: \code
+        EntityHandle quad_conn[] = {vertex0, vertex1, vertex2, vertex3};
+        EntityHandle quad_handle = 0;
+        create_element( MeshQuad, quad_conn, 4, quad_handle ); \endcode 
+    */
+  virtual ErrorCode create_element(const EntityType type, 
+                                     const EntityHandle *connectivity,
+                                     const int num_vertices, 
+                                     EntityHandle &element_handle) = 0;
+
+    //! Creates a vertex with the specified coordinates.  
+    /**
+       \param coordinates Array that has 3 doubles in it.
+       \param entity_handle EntityHandle representing the newly created vertex in the database.
+
+       Example: \code
+       double coordinates[] = {1.034, 23.23, -0.432};
+       EntityHandle new_handle = 0;
+       create_vertex( coordinates, entity_handle ); \endcode 
+    */
+  virtual ErrorCode create_vertex(const double coordinates[3], 
+                                    EntityHandle &entity_handle ) = 0;
+
+    //! Create a set of vertices with the specified coordinates
+    /**
+       \param coordinates Array that has 3*n doubles in it.
+       \param nverts Number of vertices to create
+       \param entity_handles Range passed back with new vertex handles
+    */
+  virtual ErrorCode create_vertices(const double *coordinates, 
+                                      const int nverts,
+                                      Range &entity_handles ) = 0;
+
+    //! Merge two entities into a single entity
+    /** Merge two entities into a single entities, with <em>entity_to_keep</em> receiving
+        adjacencies that were on <em>entity_to_remove</em>.
+        \param entity_to_keep Entity to be kept after merge
+        \param entity_to_remove Entity to be merged into <em>entity_to_keep</em>
+        \param auto_merge If false, <em>entity_to_keep</em> and <em>entity_to_remove</em> must share
+        the same lower-dimensional entities; if true, MB tries to merge those entities automatically
+        \param delete_removed_entity If true, <em>entity_to_remove</em> is deleted after merge is complete
+    */
+  virtual ErrorCode merge_entities(EntityHandle entity_to_keep, 
+                                     EntityHandle entity_to_remove,
+                                     bool auto_merge,
+                                     bool delete_removed_entity) = 0;
+
+    //! Removes entities in a vector from the data base.  
+    /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
+        which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity</em> are 
+        removed as part of this function.
+        \param entities 1d vector of entities to delete
+        \param num_entities Number of entities in 1d vector
+    */ 
+  virtual ErrorCode delete_entities(const EntityHandle *entities,
+                                      const int num_entities) = 0;
+
+    //! Removes entities in a range from the data base.  
+    /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
+        which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity</em> are 
+        removed as part of this function.
+        \param entities Range of entities to delete
+    */ 
+  virtual ErrorCode delete_entities(const Range &entities) = 0;
+
+    //@}
+
+    //! \name Listing entities
+
+    //@{
+
+    //! List entities to standard output
+    /** Lists all data pertaining to entities (i.e. vertex coordinates if vertices, connectivity if
+        elements, set membership if set).  Useful for debugging, but output can become quite long
+        for large databases.
+    */
+  virtual ErrorCode list_entities(const Range &entities) const = 0;
+  
+    //! List entities, or number of entities in database, to standard output
+    /** Lists data pertaining to entities to standard output.  If <em>entities</em> is NULL and
+        <em>num_entities</em> is zero, lists only the number of entities of each type in the 
+        database.  If <em>entities</em> is NULL and <em>num_entities</em> is non-zero, lists all
+        information for all entities in the database.
+        \param entities 1d vector of entities to list
+        \param num_entities Number of entities in 1d vector
+    */
+  virtual ErrorCode list_entities(const EntityHandle *entities,
+                                    const int num_entities) const = 0;
+
+    //! List a single entity; no header printed
+    /** Lists a single entity, including its connectivity and its adjacencies.
+     *  No header is printed, because calling function might print information between header
+     *  and information printed by this function.
+     *  \param entity The entity to be listed.
+     */
+  virtual ErrorCode list_entity(const EntityHandle entity) const = 0;
+
+    //@}
+
+    //! \name Functions for higher-order elements
+
+    //@{
+
+    //! function object for recieving events from MB of higher order nodes added to entities
+  class HONodeAddedRemoved
+  {
+  public:
+      //! Constructor
+    HONodeAddedRemoved(){}
+ 
+      //! Destructor
+    virtual ~HONodeAddedRemoved(){}
+
+      //! node_added called when a node was added to an element's connectivity array
+      //! note: connectivity array of element may be incomplete (corner nodes will exist always)
+      /** 
+       * \param node Node being added
+       * \param element Element node is being added to
+       */
+    virtual void node_added(EntityHandle node, EntityHandle element) = 0;
+
+      //! node_added called when a node was added to an element's connectivity array
+      //! note: connectivity array of element may be incomplete (corner nodes will exist always)
+      /**
+       * \param node Node being removed.
+       */
+    virtual void node_removed(EntityHandle node) = 0;
+  };
+  
+    //! Convert entities to higher-order elements by adding mid nodes
+    /** This function causes MB to create mid-nodes on all edges, faces, and element interiors 
+        for all entities in <em>meshset</em>.  Higher order nodes appear in an element's connectivity
+        array according to the algorithm described in the documentation for Mesh.  If 
+        <em>HONodeAddedRemoved</em> function is input, this function is called to notify the application
+        of nodes being added/removed from the mesh.
+        \param meshset The set of entities being converted
+        \param mid_edge If true, mid-edge nodes are created 
+        \param mid_face If true, mid-face nodes are created 
+        \param mid_region If true, mid-element nodes are created 
+        \param function_object If non-NULL, the node_added or node_removed functions on this object 
+        are called when nodes are added or removed from an entity, respectively
+    */
+  virtual ErrorCode convert_entities(const EntityHandle meshset, 
+                                       const bool mid_edge,
+                                       const bool mid_face, 
+                                       const bool mid_region, 
+                                       HONodeAddedRemoved* function_object = 0) = 0;
+
+    //! Returns the side number, in canonical ordering, of <em>child</em> with respect to <em>parent</em>
+    /** Given a parent and child entity, returns the canonical ordering information side number, sense, 
+        and offset of <em>child</em> with respect to <em>parent</em>.  This function returns
+        MB_FAILURE if <em>child</em> is not related to <em>parent</em>.  This function does *not* 
+        create adjacencies between <em>parent</em> and <em>child</em>.
+        \param parent Parent entity to be compared
+        \param child Child entity to be compared
+        \param side_number Side number in canonical ordering of <em>child</em> with respect to 
+        <em>parent</em>
+        \param sense Sense of <em>child</em> with respect to <em>parent</em>, assuming ordering of 
+        <em>child</em> as given by get_connectivity called on <em>child</em>; sense is 1, -1
+        for forward/reverse sense, resp.
+        \param offset Offset between first vertex of <em>child</em> and first vertex of side 
+        <em>side_number</em> on <em>parent</em>
+    */
+  virtual ErrorCode side_number(const EntityHandle parent,
+                                  const EntityHandle child,
+                                  int &side_number,
+                                  int &sense,
+                                  int &offset) const = 0;
+
+    //! Find the higher-order node on a subfacet of an entity
+    /** Given an entity and the connectivity and type of one of its subfacets, find the
+        high order node on that subfacet, if any.  The number of vertices in <em>subfacet_conn</em>
+        is derived from <em>subfacet_type</em> and the canonical numbering for that type.
+        \param parent_handle The element whose subfacet is being queried
+        \param subfacet_conn The connectivity of the subfacet being queried
+        \param subfacet_type The type of subfacet being queried
+        \param high_order_node If the subfacet has a high-order node defined on <em>parent_handle</em>,
+        the handle for that node.
+    */
+  virtual ErrorCode high_order_node(const EntityHandle parent_handle,
+                                      const EntityHandle *subfacet_conn,
+                                      const EntityType subfacet_type,
+                                      EntityHandle &high_order_node) const = 0;
+
+    //! Return the handle of the side element of a given dimension and index
+    /** Given a parent entity and a target dimension and side number, return the handle of
+        the entity corresponding to that side.  If an entity has not been created to represent
+        that side, one is not created by this function, and zero is returned in <em>target_entity</em>.
+        \param source_entity The entity whose side is being queried.
+        \param dim The topological dimension of the side being queried.
+        \param side_number The canonical index of the side being queried.
+        \param target_entity The handle of the entity representing this side, if any.
+    */
+  virtual ErrorCode side_element(const EntityHandle source_entity,
+                                   const int dim, 
+                                   const int side_number,
+                                   EntityHandle &target_entity) const = 0;
+
+    //@}
+
+    //! \name Tag functions
+
+    //@{
+
+    //! Create a tag with the specified name, type and length
+    /** Create a "tag", used to store application-defined data on MB entities.  If MB_ALREADY_ALLOCATED
+        is returned, a tag with this name has already been created.  Tags created with this function
+        are assigned to entities using the tag_set_data function described below.
+        \param tag_name Name of this tag
+        \param tag_size Size of data to store on tag, in bytes (MB_TAG_DENSE, MB_TAG_SPARSE) or
+        bits (MB_TAG_BITS).
+        \param type Type of tag to create (MB_TAG_BIT, MB_TAG_SPARSE, MB_TAG_DENSE, MB_TAG_MESH)
+        \param tag_handle Tag handle created
+        \param default_value Default value tag data is set to when initially created
+
+        Example: \code
+        Tag tag_handle;
+        double value = 100.0;
+          // create a dense tag with default value of 100
+          tag_create( "my_tag", sizeof(double), MB_TAG_DENSE, tag_handle, &value );\endcode
+    */
+  virtual ErrorCode tag_create(const char *tag_name,
+                                 const int tag_size, 
+                                 const TagType type,
+                                 Tag &tag_handle, 
+                                 const void *default_value) = 0;
+
+    /** \brief Define a new tag.
+     *
+     * Define a new tag for storing application-defined data on MB entities.  
+     *
+     * \param name    The name of the tag.
+     * \param size    The size of the tag data in bytes.
+     * \param storage The tag storage type.
+     * \param data    The tag data type.
+     * \param handle  The tag handle (output)
+     * \param def_val Optional default value for tag.
+     * \param use_existing  If true, and a tag with the same name and
+     *                same description exists, successfully return the
+     *                handle of the tag.
+     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
+     *         - MB_FAILURE if inconsistant arguments
+     *         - MB_SUCCESS otherwise.
+     */
+  virtual ErrorCode tag_create( const      char* name,
+                                  const        int size,
+                                  const  TagType storage,
+                                  const DataType data,
+                                            Tag& handle,
+                                  const      void* def_val,
+                                              bool use_existing = false ) = 0;
+
+    /**\brief Define a new tag that can store variable-length data.
+     *
+     * Define a new tag for storing application-defined data on MB entities.  
+     *
+     * \param name          The name of the tag.
+     * \param storage       The tag storage type (MB_TAG_BIT not supported).
+     * \param data_type     The tag data type.
+     * \param handle_out    The tag handle (output)
+     * \param default_value Optional default value for tag.
+     * \param default_val_len Length of default value.  Required if
+     *                      default value is specified.
+     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
+     *         - MB_FAILURE if inconsistant arguments
+     *         - MB_SUCCESS otherwise.
+     */
+  virtual ErrorCode tag_create_variable_length( const char* name,
+                                                  TagType   storage,
+                                                  DataType  data_type,
+                                                  Tag&      handle_out,
+                                                  const void* default_value = 0,
+                                                  int         default_val_len = 0 
+                                                 ) = 0;
+
+    //! Get the name of a tag corresponding to a handle
+    /** \param tag_handle Tag you want the name of.  
+        \param tag_name Name string for <em>tag_handle</em>. 
+    */
+  virtual ErrorCode  tag_get_name(const Tag tag_handle, 
+                                    std::string& tag_name) const = 0;
+
+    //! Gets the tag handle corresponding to a name
+    /** If a tag of that name does not exist, returns MB_TAG_NOT_FOUND
+        \param tag_name Name of the desired tag. 
+        \param tag_handle Tag handle corresponding to <em>tag_name</em>
+    */ 
+  virtual ErrorCode  tag_get_handle(const char *tag_name, 
+                                      Tag &tag_handle) const = 0;
+
+    //! Get the size of the specified tag
+    /** Get the size of the specified tag, in bytes (MB_TAG_SPARSE, MB_TAG_DENSE, MB_TAG_MESH) or
+        bits (MB_TAG_BIT).
+        \param tag Handle of the desired tag. 
+        \param tag_size Size of the specified tag
+    */ 
+  virtual ErrorCode tag_get_size(const Tag tag, int &tag_size) const = 0;
+
+    //! Get the type of the specified tag
+    /** Get the type of the specified tag
+        \param tag Handle of the desired tag. 
+        \param tag_type Type of the specified tag
+    */ 
+  virtual ErrorCode tag_get_type(const Tag tag, TagType &tag_type) const = 0;
+
+    /** \brief Get data type of tag.
+     *
+     * Get the type of the tag data.  The tag is data is assumed to
+     * be a vector of this type.  If the tag data vetcor contains 
+     * more than one value, then the tag size must be a multiple of
+     * the size of this type.
+     * \param tag  The tag 
+     * \param type The type of the specified tag (output).
+     */
+   virtual ErrorCode tag_get_data_type(const Tag tag, DataType& type) const = 0;
+
+    //! Get the default value of the specified tag
+    /** Get the default value of the specified tag
+        \param tag Handle of the desired tag. 
+        \param def_value Pointer to memory where default value of the specified tag is written
+        \return - MB_ENTITY_NOT_FOUND If no default value is set for tag.
+                - MB_SUCCESS          If success.
+                - MB_FAILURE          If <code>def_val</code> is NULL.
+                - MB_TAG_NOT_FOUND    If <code>tag_handle</code> is invalid.
+    */ 
+  virtual ErrorCode tag_get_default_value(const Tag tag, void *def_val) const = 0;
+  virtual ErrorCode tag_get_default_value( Tag tag, const void*& def_val, int& size) const = 0;
+
+    //! Get handles for all tags defined in the mesh instance
+    /** Get handles for all tags defined on the mesh instance.
+        \param tag_handles STL vector of all tags
+    */
+  virtual ErrorCode tag_get_tags(std::vector<Tag> &tag_handles) const = 0;
+
+    //! Get handles for all tags defined on this entity
+    /** Get handles for all tags defined on this entity; if zero, get all tags defined 
+        on mesh instance
+        \param entity Entity for which you want tags
+        \param tag_handles STL vector of all tags defined on <em>entity</em>
+    */
+  virtual ErrorCode tag_get_tags_on_entity(const EntityHandle entity,
+                                             std::vector<Tag> &tag_handles) const = 0;
+
+    //! Get the value of the indicated tag on the specified entities in the specified vector
+    /** Get the value of the indicated tag on the specified entities; <em>tag_data</em> must contain
+        enough space (i.e. tag_size*num_entities bytes) to hold all tag data.  MOAB does <em>not</em>
+        check whether this space is available before writing to it.
+        \note For bit tags, tag_data must contain one byte per entity.  For each
+              entity, the corresponding byte will contain the tag bits in the
+              lower bit positions and zero bits in the higher.
+        \param tag_handle Tag whose values are being queried.
+        \param entity_handles 1d vector of entity handles whose tag values are being queried
+        \param num_entities Number of entities in 1d vector of entity handles
+        \param tag_data Pointer to memory into which tag data will be written
+    */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities, 
+                                    void *tag_data) const = 0;
+
+    //! Get the value of the indicated tag on the specified entities in the specified range
+    /** Identical to previous function, except entities are specified using a range instead of a 1d vector.
+        \param tag_handle Tag whose values are being queried.
+        \param entity_handles Range of entity handles whose tag values are being queried
+        \param tag_data Pointer to memory into which tag data will be written
+    */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const Range& entity_handles, 
+                                    void *tag_data) const = 0;
+
+    //! Set the value of the indicated tag on the specified entities in the specified vector
+    /** Set the value of the indicated tag on the specified entities; <em>tag_data</em> contains the
+        values, <em>one value per entity in <em>entity_handles</em></em>.
+        \note For bit tags, tag_data must contain one byte per entity.  For each
+              entity, the tag bits will be read from the lower bits of the 
+              corresponding byte.
+        \param tag_handle Tag whose values are being set
+        \param entity_handles 1d vector of entity handles whose tag values are being set
+        \param num_entities Number of entities in 1d vector of entity handles
+        \param tag_data Pointer to memory holding tag values to be set, <em>one entry per entity handle</em>
+    */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities,
+                                    const void *tag_data ) = 0;
+  
+    //! Set the value of the indicated tag on the specified entities in the specified range
+    /** Identical to previous function, except entities are specified using a range instead of a 1d vector.
+        \param tag_handle Tag whose values are being set
+        \param entity_handles Range of entity handles whose tag values are being set
+        \param tag_data Pointer to memory holding tag values to be set, <em>one entry per entity handle</em>
+    */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const Range& entity_handles,
+                                    const void *tag_data ) = 0;
+
+
+    /**\brief Get pointers to tag data
+     *
+     * For a tag, get the values for a list of passed entity handles.
+     *\note  This function may not be used for bit tags.
+     *\param tag_handle     The tag
+     *\param entity_handles An array of entity handles for which to retreive tag values.
+     *\param num_entities   The length of the 'entity_handles' array.
+     *\param tag_data       An array of 'const void*'.  Array must be at least
+     *                      'num_entitities' long.  Array is populated (output)
+     *                      with pointers to the internal storage for the
+     *                      tag value corresponding to each entity handle.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities, 
+                                    const void** tag_data,
+                                    int* tag_sizes = 0 ) const = 0;
+
+    /**\brief Get pointers to tag data
+     *
+     * For a tag, get the values for a list of passed entity handles.
+     *\note  This function may not be used for bit tags.
+     *\param tag_handle     The tag
+     *\param entity_handles The entity handles for which to retreive tag values.
+     *\param tag_data       An array of 'const void*'.  Array is populated (output)
+     *                      with pointers to the internal storage for the
+     *                      tag value corresponding to each entity handle.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_get_data(const Tag tag_handle, 
+                                    const Range& entity_handles, 
+                                    const void** tag_data,
+                                    int* tag_sizes = 0 ) const = 0;
+
+    /**\brief Set tag data given an array of pointers to tag values.
+     *
+     * For a tag, set the values for a list of passed entity handles.
+     *\note  This function may not be used for bit tags.
+     *\param tag_handle     The tag
+     *\param entity_handles An array of entity handles for which to set tag values.
+     *\param num_entities   The length of the 'entity_handles' array.
+     *\param tag_data       An array of 'const void*'.  Array must be at least
+     *                      'num_entitities' long.  Array is expected to
+     *                      contain pointers to tag values for the corresponding
+     *                      EntityHandle in 'entity_handles'.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const EntityHandle* entity_handles, 
+                                    const int num_entities,
+                                    void const* const* tag_data,
+                                    const int* tag_sizes = 0 ) = 0;
+  
+    /**\brief Set tag data given an array of pointers to tag values.
+     *
+     * For a tag, set the values for a list of passed entity handles.
+     *\note  This function may not be used for bit tags.
+     *\param tag_handle     The tag
+     *\param entity_handles The entity handles for which to set tag values.
+     *\param tag_data       An array of 'const void*'.  Array is expected to
+     *                      contain pointers to tag values for the corresponding
+     *                      EntityHandle in 'entity_handles'.
+     *\param tag_sizes      The length of each tag value.  Optional for 
+     *                      fixed-length tags.  Required for variable-length tags.
+     */
+  virtual ErrorCode  tag_set_data(const Tag tag_handle, 
+                                    const Range& entity_handles,
+                                    void const* const* tag_data,
+                                    const int* tag_sizes = 0 ) = 0;
+
+    //! Delete the data of a vector of entity handles and sparse tag
+    /** Delete the data of a tag on a vector of entity handles.  Only sparse tag data are deleted with this
+        function; dense tags are deleted by deleting the tag itself using tag_delete.
+        \param tag_handle Handle of the (sparse) tag being deleted from entity
+        \param entity_handles 1d vector of entity handles from which the tag is being deleted
+        \param num_handles Number of entity handles in 1d vector
+    */
+  virtual ErrorCode  tag_delete_data(const Tag tag_handle, 
+                                       const EntityHandle *entity_handles,
+                                       const int num_handles) = 0;
+
+    //! Delete the data of a range of entity handles and sparse tag
+    /** Delete the data of a tag on a range of entity handles.  Only sparse tag data are deleted with this
+        function; dense tags are deleted by deleting the tag itself using tag_delete.
+        \param tag_handle Handle of the (sparse) tag being deleted from entity
+        \param entity_range Range of entities from which the tag is being deleted
+    */
+  virtual ErrorCode  tag_delete_data(const Tag tag_handle, 
+                                       const Range &entity_range) = 0;
+
+    //! Remove a tag from the database and delete all of its associated data
+    /** Deletes a tag and all associated data.
+     */
+  virtual ErrorCode  tag_delete(Tag tag_handle) = 0;
+
+    //@}
+
+    //! \name Meshset functions
+
+    //@{
+
+    //! Create a new mesh set
+    /** Create a new mesh set.  Meshsets can store entities ordered or unordered. A set can include entities
+        at most once (MESHSET_SET) or more than once.  Meshsets can optionally track its members using
+        adjacencies (MESHSET_TRACK_OWNER); if set, entities are deleted from tracking meshsets before
+        being deleted.  This adds data to mesh entities, which can be expensive.
+        \param options Options bitmask for the new meshset, possible values defined above
+        \param ms_handle Handle for the meshset created
+    */
+  virtual ErrorCode create_meshset(const unsigned int options, 
+                                     EntityHandle &ms_handle,
+                                     int start_id = 0) = 0;
+
+    //! Empty a vector of mesh set
+    /** Empty a mesh set.
+        \param ms_handles 1d vector of handles of sets being emptied
+        \param num_meshsets Number of entities in 1d vector
+    */
+  virtual ErrorCode clear_meshset( const EntityHandle *ms_handles, 
+                                     const int num_meshsets) = 0;
+
+    //! Empty a range of mesh set
+    /** Empty a mesh set.
+        \param ms_handles Range of handles of sets being emptied
+    */
+  virtual ErrorCode clear_meshset( const Range &ms_handles) = 0;
+
+    //! Get the options of a mesh set
+    /** Get the options of a mesh set.
+        \param ms_handle Handle for mesh set being queried
+        \param options Bit mask in which mesh set options are returned
+    */
+  virtual ErrorCode get_meshset_options(const EntityHandle ms_handle, 
+                                          unsigned int& options) const = 0;
+
+    //! Set the options of a mesh set
+    /** Set the options of a mesh set.
+        \param ms_handle Handle for meshset whose options are being changed
+        \param options Bit mask of options to be used
+    */
+  virtual ErrorCode set_meshset_options(const EntityHandle ms_handle, 
+                                          const unsigned int options) = 0;
+
+    //! Subtract meshsets
+    /** Subtract <em>meshset2</em> from <em>meshset1</em>, placing the results in meshset1.
+        \param meshset1 Mesh set being subtracted from, also used to pass back result
+        \param meshset2 Mesh set being subtracted from <em>meshset1</em>
+    */
+  virtual ErrorCode subtract_meshset(EntityHandle meshset1, 
+                                       const EntityHandle meshset2) = 0;
+
+    //! Intersect meshsets
+    /** Intersect <em>meshset1</em> with <em>meshset2</em>, placing the results in meshset1.
+        \param meshset1 Mesh set being intersected, also used to pass back result
+        \param meshset2 Mesh set being intersected with <em>meshset1</em>
+    */
+  virtual ErrorCode intersect_meshset(EntityHandle meshset1, 
+                                        const EntityHandle meshset2) = 0;
+    
+    //! Unite meshsets
+    /** Unite <em>meshset1</em> with <em>meshset2</em>, placing the results in meshset1.
+        \param meshset1 Mesh set being united, also used to pass back result
+        \param meshset2 Mesh set being united with <em>meshset1</em>
+    */
+  virtual ErrorCode unite_meshset(EntityHandle meshset1, 
+                                    const EntityHandle meshset2) = 0;
+
+    //! Add to a meshset entities in specified range
+    /** Add to a meshset entities in specified range.  If <em>meshset</em> has MESHSET_TRACK_OWNER
+        option set, adjacencies are also added to entities in <em>entities</em>.
+        \param meshset Mesh set being added to
+        \param entities Range of entities being added to meshset
+    */
+  virtual ErrorCode add_entities(EntityHandle meshset, 
+                                   const Range &entities) = 0;
+
+    //! Add to a meshset entities in specified vector
+    /** Add to a meshset entities in specified vector.  If <em>meshset</em> has MESHSET_TRACK_OWNER
+        option set, adjacencies are also added to entities in <em>entities</em>.
+        \param meshset Mesh set being added to
+        \param entities 1d vector of entities being added to meshset
+        \param num_entities Number of entities in 1d vector
+    */
+  virtual ErrorCode add_entities(EntityHandle meshset, 
+                                   const EntityHandle *entities,
+                                   const int num_entities) = 0;
+  
+    //! Remove from a meshset entities in specified range
+    /** Remove from a meshset entities in specified range.  If <em>meshset</em> has MESHSET_TRACK_OWNER
+        option set, adjacencies in entities in <em>entities</em> are updated.
+        \param meshset Mesh set being removed from
+        \param entities Range of entities being removed from meshset
+    */
+  virtual ErrorCode remove_entities(EntityHandle meshset, 
+                                      const Range &entities) = 0;
+
+    //! Remove from a meshset entities in specified vector
+    /** Remove from a meshset entities in specified vector.  If <em>meshset</em> has MESHSET_TRACK_OWNER
+        option set, adjacencies in entities in <em>entities</em> are updated.
+        \param meshset Mesh set being removed from
+        \param entities 1d vector of entities being removed from meshset
+        \param num_entities Number of entities in 1d vector
+    */
+  virtual ErrorCode remove_entities(EntityHandle meshset, 
+                                      const EntityHandle *entities,
+                                      const int num_entities) = 0;
+
+    //! Return whether a set contains entities
+    /** Return whether a set contains entities.  Returns true only
+     * if ALL entities are contained
+     * \param meshset Mesh set being queried
+     * \param entities Entities being queried
+     * \param num_entities Number of entities
+     * \return bool If true, all entities are contained in set
+    */
+  virtual bool contains_entities(EntityHandle meshset, 
+                                 const EntityHandle *entities,
+                                 int num_entities,
+                                 const int operation_type = Interface::INTERSECT) = 0;
+
+    //! Replace entities in a set with other entities
+    /** Replace entities in a set with other entities
+     * 
+     * \note  Behavior is undefined if an entity handle exists in both the
+     *        old_entities and the new_entities arrays or old_entities
+     *        contains multiple copies of an entity.
+     * \note  If an entity occurs multiple times in an ordered set, all
+     *        occurances will be replaced.
+     * \note  For list-based sets, if not all handles in old_entities 
+     *        occcur in the set, the corresponding new_entities will not 
+     *        be added and  MB_ENTITY_NOT_FOUND will be returned.
+     *        For set-based sets, all entities in new_entities wll be
+     *        added and any contained entities in old_entities will be 
+     *        removed, and the return value will be MB_SUCCESS.
+     * \param meshset Mesh set being modified
+     * \param old_entities Entities to replace
+     * \param new_entities New entities to add
+     * \param num_entities Number of entities in input arrays
+     * \return - MB_SUCCESS : all entities in old_entities replaced
+     *         - MB_ENTITY_NOT_FOUND : one or more entities in new_entities 
+     *                        not added to set because corresponding entity
+     *                        in old_entities did not occur in the ordered
+     *                        set.
+     *         - MB_FAILURE : internal error
+    */
+  virtual ErrorCode replace_entities(EntityHandle meshset, 
+                                       const EntityHandle *old_entities,
+                                       const EntityHandle *new_entities,
+                                       int num_entities) = 0;
+    //@}
+
+    //! \name MeshSet parent/child functions
+
+    //@{
+  
+    //! Get parent mesh sets of a mesh set
+    /** If <em>num_hops</em> is 1, only immediate parents are returned.  If <em>num_hops</em> is zero,
+        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
+        generations to traverse.
+        \param meshset The mesh set whose parents are being queried
+        \param parents STL vector holding the parents returned by this function
+        \param num_hops Number of generations to traverse (0 = all)
+    */
+  virtual ErrorCode get_parent_meshsets(const EntityHandle meshset,
+                                          std::vector<EntityHandle> &parents, 
+                                          const int num_hops = 1) const = 0;
+
+    //! Get parent mesh sets of a mesh set
+    /** If <em>num_hops</em> is 1, only immediate parents are returned.  If <em>num_hops</em> is zero,
+        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
+        generations to traverse.
+        \param meshset The mesh set whose parents are being queried
+        \param parents Range holding the parents returned by this function
+        \param num_hops Number of generations to traverse (0 = all)
+    */
+  virtual ErrorCode get_parent_meshsets(const EntityHandle meshset,
+                                          Range &parents,
+                                          const int num_hops = 1) const = 0;
+
+    //! Get child mesh sets of a mesh set
+    /** If <em>num_hops</em> is 1, only immediate children are returned.  If <em>num_hops</em> is zero,
+        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
+        generations to traverse.
+        \param meshset The mesh set whose children are being queried
+        \param children STL vector holding the children returned by this function
+        \param num_hops Number of generations to traverse (0 = all)
+    */
+  virtual ErrorCode get_child_meshsets(const EntityHandle meshset, 
+                                         std::vector<EntityHandle> &children, 
+                                         const int num_hops = 1) const = 0;
+
+    //! Get child mesh sets of a mesh set
+    /** If <em>num_hops</em> is 1, only immediate children are returned.  If <em>num_hops</em> is zero,
+        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
+        generations to traverse.
+        \param meshset The mesh set whose children are being queried
+        \param children Range holding the children returned by this function
+        \param num_hops Number of generations to traverse (0 = all)
+    */
+  virtual ErrorCode get_child_meshsets(const EntityHandle meshset, 
+                                         Range &children, 
+                                         const int num_hops = 1) const = 0;
+
+    /**\brief Get mesh sets contained in a mesh set
+     *
+     * If <em>num_hops</em> is 1, only immediate contents are returned. 
+     * Otherwise a recursive query of all contained sets is performed, 
+     * returning every visted set.  The value of num_hops limites the
+     * depth of the search, with zero indicating no depth limit. 
+     *
+     *\param meshset The mesh set whose contents are being queried
+     *\param contained The result list.
+     *\param num_hops Number of generations to traverse (0 = all)
+     */
+  virtual ErrorCode get_contained_meshsets(const EntityHandle meshset, 
+                                         std::vector<EntityHandle> &contained, 
+                                         const int num_hops = 1) const = 0;
+
+    /**\brief Get mesh sets contained in a mesh set
+     *
+     * If <em>num_hops</em> is 1, only immediate contents are returned. 
+     * Otherwise a recursive query of all contained sets is performed, 
+     * returning every visted set.  The value of num_hops limites the
+     * depth of the search, with zero indicating no depth limit. 
+     *
+     *\param meshset The mesh set whose contents are being queried
+     *\param contained The result list.
+     *\param num_hops Number of generations to traverse (0 = all)
+     */
+  virtual ErrorCode get_contained_meshsets(const EntityHandle meshset, 
+                                             Range &contained, 
+                                             const int num_hops = 1) const = 0;
+
+    //! Get the number of parent mesh sets of a mesh set
+    /** Identical to get_parent_meshsets, only number is returned instead of actual parents.
+        \param meshset The mesh set whose parents are being queried
+        \param number Number of parents
+    */
+  virtual ErrorCode num_parent_meshsets(const EntityHandle meshset,  
+                                          int *number,
+                                          const int num_hops = 1) const = 0;
+
+    //! Get the number of child mesh sets of a mesh set
+    /** Identical to get_child_meshsets, only number is returned instead of actual children.
+        \param meshset The mesh set whose children are being queried
+        \param number Number of children
+    */
+  virtual ErrorCode num_child_meshsets(const EntityHandle meshset, 
+                                         int *number,
+                                         const int num_hops = 1) const = 0;
+
+    /**\brief Get the number of mesh sets contained in a mesh set
+     *
+     * Return the number of sets that would be returned by get_contained_meshsets
+     *
+     *\param meshset  The initial set to begin the query from.
+     *\param number   (Output) The result count.
+     *\param num_hops Search depth (0 => unbounded).
+     */
+  virtual ErrorCode num_contained_meshsets(const EntityHandle meshset, 
+                                             int *number,
+                                             const int num_hops = 1) const = 0;
+
+    //! Add a parent mesh set to a mesh set
+    /** Make <em>parent_meshset</em> a new parent of <em>child_meshset</em>.  This function does 
+        <em>not</em> add a corresponding child link to <em>parent_meshset</em>.
+        \param child_meshset The child mesh set being given a new parent.
+        \param parent_meshset The parent being added to <em>child_meshset</em>
+    */
+  virtual ErrorCode add_parent_meshset(EntityHandle child_meshset, 
+                                         const EntityHandle parent_meshset) = 0;
+
+    //! Add a parent mesh sets to a mesh set
+    /** Make <em>parent_meshset</em> a new parent of <em>child_meshset</em>.  This function does 
+        <em>not</em> add a corresponding child link to <em>parent_meshset</em>.
+        \param child_meshset The child mesh set being given a new parent.
+        \param parent_meshset The parent being added to <em>child_meshset</em>
+    */
+  virtual ErrorCode add_parent_meshsets(EntityHandle child_meshset, 
+                                          const EntityHandle* parent_meshsets,
+                                          int num_parent_meshsets ) = 0;
+
+    //! Add a child mesh set to a mesh set
+    /** Make <em>child_meshset</em> a new child of <em>parent_meshset</em>.  This function does 
+        <em>not</em> add a corresponding parent link to <em>child_meshset</em>.
+        \param parent_meshset The parent mesh set being given a new child.
+        \param child_meshset The child being added to <em>parent_meshset</em>
+    */
+  virtual ErrorCode add_child_meshset(EntityHandle parent_meshset, 
+                                        const EntityHandle child_meshset) = 0;
+
+    //! Add a child mesh sets to a mesh set
+    /** Make <em>child_meshset</em> a new child of <em>parent_meshset</em>.  This function does 
+        <em>not</em> add a corresponding parent link to <em>child_meshset</em>.
+        \param parent_meshset The parent mesh set being given a new child.
+        \param child_meshset The child being added to <em>parent_meshset</em>
+    */
+  virtual ErrorCode add_child_meshsets(EntityHandle parent_meshset, 
+                                         const EntityHandle* child_meshsets,
+                                         int num_child_meshsets ) = 0;
+
+    //! Add parent and child links between mesh sets
+    /** Makes <em>child_meshset</em> a new child of <em>parent_meshset</em>, and vica versa.
+        \param parent The parent mesh set being given a new child, and the new parent
+        \param child The child being given a new parent, and the new child
+    */
+  virtual ErrorCode add_parent_child( EntityHandle parent, 
+                                        EntityHandle child ) = 0;
+
+    //! Remove parent and child links between mesh sets
+    /** Removes parent/child links between <em>child_meshset</em> and <em>parent_meshset</em>.
+        \param parent The parent mesh set being removed from <em>child</em>
+        \param child The child mesh set being removed from <em>parent</em>
+    */
+  virtual ErrorCode remove_parent_child( EntityHandle parent, 
+                                           EntityHandle child ) = 0;
+
+    //! Remove a parent mesh set from a mesh set
+    /** Removes <em>parent_meshset</em> from the parents of <em>child_meshset</em>.  This function does 
+        <em>not</em> remove a corresponding child link from <em>parent_meshset</em>.
+        \param child_meshset The child mesh whose parent is being removed
+        \param parent_meshset The parent being removed from <em>meshset</em>
+    */
+  virtual ErrorCode remove_parent_meshset(EntityHandle child_meshset, 
+                                            const EntityHandle parent_meshset) = 0;
+  
+    //! Remove a child mesh set from a mesh set
+    /** Removes <em>child_meshset</em> from the children of <em>parent_meshset</em>.  This function does 
+        <em>not</em> remove a corresponding parent link from <em>child_meshset</em>.
+        \param parent_meshset The parent mesh set whose child is being removed
+        \param child_meshset The child being removed from <em>parent_meshset</em>
+    */
+  virtual ErrorCode remove_child_meshset(EntityHandle parent_meshset, 
+                                           const EntityHandle child_meshset) = 0;
+
+    //@}
+
+    //! \name Error condition information 
+
+    //@{
+
+    //! Return information about the last error
+    /** \param info std::string into which information on the last error is written.
+     */
+  virtual ErrorCode get_last_error(std::string& info) const = 0;
+
+    //! Return string representation of given error code
+    /** \param code Error code for which string is wanted
+     */
+  virtual std::string get_error_string(const ErrorCode code) const = 0;
+
+    //@}
+
+  /**\brief Calculate amount of memory used to store MOAB data
+   *
+   * This function calculates the amount of memory used to store
+   * MOAB data.  
+   *
+   * There are two possible values for each catagory of memory use.
+   * The exact value and the amortized value.  The exact value is the
+   * amount of memory used to store the data for the specified entities.
+   * The amortized value includes the exact value and an amortized 
+   * estimate of the memory consumed in overhead for storing the values
+   * (indexing structures, access structures, etc.)  
+   *
+   * Note: If ent_array is NULL and total_amortized_storage is *not* NULL,
+   *       the total memory used by MOAB for storing data all will be 
+   *       returned in the address pointed to by total_amortized_storage.
+   *
+   *\param ent_array Array of entities for which to estimate the memory use.
+   *                 If NULL, estimate is done for all entities.
+   *\param num_ents The length of ent_array.  Not used if ent_rray is NULL.
+   *\param total_(amortized_)storage The sum of the memory entity, adjacency,
+   *                   and all tag storage.
+   *\param (amortized_)entity_storage The storage for the entity definitions
+   *                   (connectivity arrays for elements, coordinates for 
+   *                   vertices, list storage within sets, etc.)
+   *\param (amortized_)adjacency_storage The storage for adjacency data.
+   *\param tag_array   An array of tags for which to calculate the memory use.
+   *\param num_tags    The lenght of tag_array
+   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
+   *                   for each tag specifying the memory used for storing 
+   *                   that tag.  If tag_array is NULL and this value is not,
+   *                   the location at which to store the total memory used
+   *                   for all tags.
+   */
+  virtual void estimated_memory_use( const EntityHandle* ent_array = 0,
+                             unsigned long  num_ents = 0,
+                             unsigned long* total_storage = 0,
+                             unsigned long* total_amortized_storage = 0,
+                             unsigned long* entity_storage = 0,
+                             unsigned long* amortized_entity_storage = 0,
+                             unsigned long* adjacency_storage = 0,
+                             unsigned long* amortized_adjacency_storage = 0,
+                             const Tag*   tag_array = 0,
+                             unsigned       num_tags = 0,
+                             unsigned long* tag_storage = 0,
+                             unsigned long* amortized_tag_storage = 0 ) = 0;
+
+  /**\brief Calculate amount of memory used to store MOAB data
+   *
+   * This function calculates the amount of memory used to store
+   * MOAB data.  
+   *
+   * There are two possible values for each catagory of memory use.
+   * The exact value and the amortized value.  The exact value is the
+   * amount of memory used to store the data for the specified entities.
+   * The amortized value includes the exact value and an amortized 
+   * estimate of the memory consumed in overhead for storing the values
+   * (indexing structures, access structures, etc.)  
+   *
+   *\param ents        Entities for which to estimate the memory use.
+   *\param total_(amortized_)storage The sum of the memory entity, adjacency,
+   *                   and all tag storage.
+   *\param (amortized_)entity_storage The storage for the entity definitions
+   *                   (connectivity arrays for elements, coordinates for 
+   *                   vertices, list storage within sets, etc.)
+   *\param (amortized_)adjacency_storage The storage for adjacency data.
+   *\param tag_array   An array of tags for which to calculate the memory use.
+   *\param num_tags    The lenght of tag_array
+   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
+   *                   for each tag specifying the memory used for storing 
+   *                   that tag.  If tag_array is NULL and this value is not,
+   *                   the location at which to store the total memory used
+   *                   for all tags.
+   */
+  virtual void estimated_memory_use( const Range& ents,
+                             unsigned long* total_storage = 0,
+                             unsigned long* total_amortized_storage = 0,
+                             unsigned long* entity_storage = 0,
+                             unsigned long* amortized_entity_storage = 0,
+                             unsigned long* adjacency_storage = 0,
+                             unsigned long* amortized_adjacency_storage = 0,
+                             const Tag*   tag_array = 0,
+                             unsigned       num_tags = 0,
+                             unsigned long* tag_storage = 0,
+                             unsigned long* amortized_tag_storage = 0 ) = 0;
+};
+
+//! predicate for STL algorithms.  Returns true if the entity handle is
+//! of the specified type.  For example, to remove all the tris out of a list
+//! of 2D entities retrieved using get_adjacencies you could do
+//! \example std::remove_if(list.begin(), list.end(), type_equals(gMB, MeshTri));
+class type_equals : public std::unary_function<EntityHandle, bool>
+{
+public:
+    //! interface object
+  Interface* meshDB;
+
+    //! type corresponding to this predicate
+  const EntityType test_type;
+
+    //! Constructor
+  type_equals(Interface* mdb, const EntityType type) : meshDB(mdb), test_type(type){}
+
+    //! operator predicate
+  bool operator()(EntityHandle handle) const
+    { 
+      return (meshDB->type_from_handle(handle) ==  test_type); 
+    } 
+};
+
+//! predicate for STL algorithms.  Returns true if the entity handle is not
+//! of the specified type.  For example, to remove all but the tris out of a list
+//! of 2D entities retrieved using get_adjacencies you could do
+//! \example std::remove_if(list.begin(), list.end(), type_not_equals(gMB, MeshTri));
+class type_not_equals : public std::unary_function<EntityHandle, bool>
+{
+public:
+
+    //! interface object
+  Interface* meshDB;
+
+    //! type corresponding to this predicate
+  const EntityType test_type;
+
+    //! Constructor
+  type_not_equals(Interface* mdb, const EntityType type) : meshDB(mdb), test_type(type){}
+
+    //! operator predicate
+  bool operator()(EntityHandle handle) const
+    { 
+      return (meshDB->type_from_handle(handle) !=  test_type); 
+    } 
+};
+
+inline float Interface::api_version(std::string *version_string) 
+{
+  if (NULL != version_string)
+    *version_string = std::string("MOAB API version ") + std::string(MOAB_API_VERSION_STRING);
+  return MOAB_API_VERSION;
+}
+
+} // namespace moab 
+
+#endif   // MB_INTERFACE_HPP
+
+  

Deleted: MOAB/trunk/src/moab/MBAdaptiveKDTree.hpp
===================================================================
--- MOAB/trunk/src/moab/MBAdaptiveKDTree.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBAdaptiveKDTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,417 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBAdaptiveKDTree.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2007-04-1
- */
-
-#ifndef MB_ADAPTIVE_KD_TREE_HPP
-#define MB_ADAPTIVE_KD_TREE_HPP
-
-#include "MBTypes.h"
-
-#include <string>
-#include <vector>
-#include <math.h>
-
-class MBAdaptiveKDTreeIter;
-class MBInterface;
-class MBRange;
-
-class MBAdaptiveKDTree
-{
-private:
-
-  MBInterface* mbInstance;
-  MBTag planeTag, axisTag, rootTag;
-  unsigned meshSetFlags;
-  bool cleanUpTrees;
-  std::vector<MBEntityHandle> createdTrees;
-  
-public:
-
-  MBAdaptiveKDTree( MBInterface* iface, 
-                    const char* tagname = 0,
-                    unsigned meshset_creation_flags = MESHSET_SET );
-
-  MBAdaptiveKDTree( MBInterface* iface, 
-                    bool destroy_created_trees,
-                    const char* tagname = 0,
-                    unsigned meshset_creation_flags = MESHSET_SET );
-
-  ~MBAdaptiveKDTree();
-
-  //! Enumeriate split plane directions
-  enum Axis { X = 0, Y = 1, Z = 2 };
-  
-  //! Split plane 
-  struct Plane {
-    double coord;  //!< Location of plane as coordinate on normal axis
-    int norm; //!< The principal axis that is the normal of the plane;
-    
-      /** return true if point is below/to the left of the split plane */
-    bool left_side( const double point[3] ) {
-      return point[norm] < coord;
-    }
-      /** return true if point is above/to the right of the split plane */
-    bool right_side( const double point[3] ) {
-      return point[norm] > coord;
-    }
-      /** return distance from point to plane */
-    double distance( const double point[3] ) const {
-      return fabs(point[norm] - coord);
-    }
-  };
-  
-  //! Get split plane for tree node
-  MBErrorCode get_split_plane( MBEntityHandle node, Plane& plane );
-  
-  //! Set split plane for tree node
-  MBErrorCode set_split_plane( MBEntityHandle node, const Plane& plane );
-  
-  //! Get bounding box for entire tree
-  MBErrorCode get_tree_box( MBEntityHandle root_node,
-                            double box_min_out[3], 
-                            double box_max_out[3] );
-  
-  //! Set bounding box for entire tree
-  MBErrorCode set_tree_box( MBEntityHandle root_node,
-                            const double box_min[3], 
-                            const double box_max[3] );
-  
-  //! Create tree root node
-  MBErrorCode create_tree( const double box_min[3],
-                           const double box_max[3],
-                           MBEntityHandle& root_handle );
-
-  //! Find all tree roots
-  MBErrorCode find_all_trees( MBRange& results );
-
-  //! Destroy a tree
-  MBErrorCode delete_tree( MBEntityHandle root_handle );
-
-  MBInterface* moab() { return mbInstance; }
-
-  //! Get iterator for tree
-  MBErrorCode get_tree_iterator( MBEntityHandle tree_root,
-                                 MBAdaptiveKDTreeIter& result );
-  
-  //! Get iterator at right-most ('last') leaf.
-  MBErrorCode get_last_iterator( MBEntityHandle tree_root,
-                                 MBAdaptiveKDTreeIter& result );
-
-  //! Get iterator for tree or subtree
-  MBErrorCode get_sub_tree_iterator( MBEntityHandle tree_root,
-                                     const double box_min[3], 
-                                     const double box_max[3],
-                                     MBAdaptiveKDTreeIter& result );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBAdaptiveKDTreeIter& leaf, Plane plane );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBAdaptiveKDTreeIter& leaf, 
-                          Plane plane,
-                          MBEntityHandle& left_child,
-                          MBEntityHandle& right_child );
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBAdaptiveKDTreeIter& leaf, 
-                          Plane plane,
-                          const MBRange& left_entities,
-                          const MBRange& right_entities );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBAdaptiveKDTreeIter& leaf, 
-                          Plane plane,
-                          const std::vector<MBEntityHandle>& left_entities,
-                          const std::vector<MBEntityHandle>& right_entities );
-  
-  //! Merge the leaf pointed to by the current iterator with it's
-  //! sibling.  If the sibling is not a leaf, multiple merges may
-  //! be done.
-  MBErrorCode merge_leaf( MBAdaptiveKDTreeIter& iter );
-  
-    //! methods for selecting candidate split planes
-  enum CandidatePlaneSet {
-    //! Candidiate planes at evenly spaced intervals 
-    SUBDIVISION,
-    //! Like SUBDIVISION, except snap to closest vertex coordinate
-    SUBDIVISION_SNAP,
-    //! Median vertex coodinate values
-    VERTEX_MEDIAN,
-    //! Random sampling of vertex coordinate values
-    VERTEX_SAMPLE
-  };
-  
-    //! Settings used for tree construction
-  struct Settings {
-    Settings(); //!< initialize to defaults
-    unsigned maxEntPerLeaf; //!< split leafs with more entities than this
-    unsigned maxTreeDepth;  //!< limit on the depth of the tree
-    unsigned candidateSplitsPerDir; //!< number of cadiditate split planes to consider in each axial direction
-    CandidatePlaneSet candidatePlaneSet;
-    double minBoxWidth; //!< Tolerance
-  };
-  
-  //! Build a tree
-  MBErrorCode build_tree( const MBRange& entities,
-                          MBEntityHandle& root_set_out,
-                          const Settings* settings = 0 );
-
-  MBErrorCode depth( MBEntityHandle root,
-                     unsigned int& min_depth,
-                     unsigned int& max_depth );
-
-    //! get some information about the tree
-  MBErrorCode get_info(MBEntityHandle root,
-                       double min[3], double max[3], 
-                       unsigned int &max_dep);
-  
-  //! Find triangle closest to input position. 
-  //!\param from_coords  The input position to test against
-  //!\param closest_point_out  The closest point on the set of triangles in the tree
-  //!\param triangle_out The triangle closest to the input position
-  MBErrorCode closest_triangle( MBEntityHandle tree_root,
-                                const double from_coords[3],
-                                double closest_point_out[3],
-                                MBEntityHandle& triangle_out );
-
-  MBErrorCode sphere_intersect_triangles( MBEntityHandle tree_root,
-                                          const double center[3],
-                                          double radius,
-                                          std::vector<MBEntityHandle>& triangles );
-
-  MBErrorCode ray_intersect_triangles( MBEntityHandle tree_root,
-                                       const double tolerance,
-                                       const double ray_unit_dir[3],
-                                       const double ray_base_pt[3],
-                                       std::vector<MBEntityHandle>& triangles_out,
-                                       std::vector<double>& distance_out,
-                                       int result_count_limit = 0,
-                                       double distance_limit = -1.0);
-
-  //! Get leaf contianing input position.
-  //!
-  //! Does not take into account global bounding box of tree.
-  //! - Therefore there is always one leaf containing the point.
-  //! - If caller wants to account for global bounding box, then
-  //!   caller can test against that box and not call this method
-  //!   at all if the point is outside the box, as there is no leaf
-  //!   containing the point in that case.
-  MBErrorCode leaf_containing_point( MBEntityHandle tree_root,
-                                     const double point[3],
-                                     MBEntityHandle& leaf_out );
-
-  //! Get iterator at leaf containing input position.
-  //! 
-  //! Returns MB_ENTITY_NOT_FOUND if point is not within
-  //! bounding box of tree.
-  MBErrorCode leaf_containing_point( MBEntityHandle tree_root,
-                                     const double xyz[3],
-                                     MBAdaptiveKDTreeIter& result );
-
-  //! Find all leaves within a given distance from point in space.
-  MBErrorCode leaves_within_distance( MBEntityHandle tree_root,
-                                      const double from_point[3],
-                                      const double distance,
-                                      std::vector<MBEntityHandle>& leaves_out );
-
-  //! Calculate bounding box for entities.
-  MBErrorCode bounding_box( const MBRange& entities,
-                            double box_min_out[3],
-                            double box_max_out[3] );
-
-private:
-  
-  void init( const char* tagname );
-  
-  /**\brief find a triangle near the input point */
-  MBErrorCode find_close_triangle( MBEntityHandle root,
-                                   const double from_point[3],
-                                   double pt[3],
-                                   MBEntityHandle& triangle );
-};
-                    
-
-//! Iterate over leaves of an adapative kD-tree
-class MBAdaptiveKDTreeIter
-{
-public:
-
-  enum Direction { LEFT = 0, RIGHT = 1 };
-
-private:
-  
-  struct StackObj {
-    StackObj( MBEntityHandle e, double c ) : entity(e), coord(c) {}
-    StackObj() {}
-    MBEntityHandle entity; //!< handle for tree node
-    double coord;          //!< box coordinate of parent
-  };
-  
-  enum { BMIN = 0, BMAX = 1 };  //!< indices into mBox and child list
-  
-  double mBox[2][3];                //!< min and max corners of bounding box
-  MBAdaptiveKDTree* treeTool;       //!< tool for tree
-  std::vector<StackObj> mStack;     //!< stack storing path through tree
-  mutable std::vector<MBEntityHandle> childVect; //!< tempory storage of child handles
-  
-  //! Descend tree to left most leaf from current position
-  //! No-op if at leaf.
-  MBErrorCode step_to_first_leaf( Direction direction );
-
-  friend class MBAdaptiveKDTree;
-public:
-
-  MBAdaptiveKDTreeIter() : treeTool(0), childVect(2) {}
-  
-  MBErrorCode initialize( MBAdaptiveKDTree* tool,
-                          MBEntityHandle root,
-                          const double box_min[3],
-                          const double box_max[3],
-                          Direction direction );
-
-  MBAdaptiveKDTree* tool() const
-    { return treeTool; }
-
-    //! Get handle for current leaf
-  MBEntityHandle handle() const
-    { return mStack.back().entity; }
-  
-    //! Get min corner of axis-aligned box for current leaf
-  const double* box_min() const 
-    { return mBox[BMIN]; }
-    
-    //! Get max corner of axis-aligned box for current leaf
-  const double* box_max() const 
-    { return mBox[BMAX]; }
-  
-  double volume() const
-    { return (mBox[BMAX][0] - mBox[BMIN][0]) * 
-             (mBox[BMAX][1] - mBox[BMIN][1]) * 
-             (mBox[BMAX][2] - mBox[BMIN][2]); }
-  
-    //! test if a plane intersects the leaf box
-  bool intersects( const MBAdaptiveKDTree::Plane& plane ) const
-    { return mBox[BMIN][plane.norm] <= plane.coord &&
-             mBox[BMAX][plane.norm] >= plane.coord; }
-  
-    //! Get depth in tree. root is at depth of 1.
-  unsigned depth() const
-    { return mStack.size(); }
-  
-  //! Advance the iterator either left or right in the tree
-  //! Note:  stepping past the end of the tree will invalidate
-  //!        the iterator.  It will *not* be work step the
-  //!        other direction.
-  MBErrorCode step( Direction direction );
-
-    //! Advance to next leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at end.
-    //! Note: steping past the end of the tree will invalidate
-    //!       the iterator. Calling back() will not work.
-  MBErrorCode step() { return step(RIGHT); }
-
-    //! Move back to previous leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
-    //! Note: steping past the start of the tree will invalidate
-    //!       the iterator. Calling step() will not work.
-  MBErrorCode back() { return step(LEFT); }
-  
-  
-    //! Return the side of the box bounding this tree node
-    //! that is shared with the immediately adjacent sibling
-    //! (the tree node that shares a common parent node with
-    //! this node in the binary tree.)
-    //!
-    //!\param axis_out The principal axis orthogonal to the side of the box
-    //!\param neg_out  true if the side of the box is toward the decreasing
-    //!                direction of the principal axis indicated by axis_out,
-    //!                false if it is toward the increasing direction.
-    //!\return MB_ENTITY_NOT FOUND if root node.
-    //!        MB_FAILURE if internal error.
-    //!        MB_SUCCESS otherwise.
-  MBErrorCode sibling_side( MBAdaptiveKDTree::Axis& axis_out, bool& neg_out ) const;
-
-    //! Get adjacent leaf nodes on side indicated by norm and neg.
-    //!
-    //! E.g. if norm == X and neg == true, then get neighbor(s)
-    //! adjacent to the side of the box contained in the plane
-    //! with normal to the X axis and with the x coordinate equal 
-    //! to the minimum x of the bounding box.
-    //!
-    //! E.g. if norm == Y and neg == false, then get neighbor(s)
-    //! adjacent to the side of the box with y = maximum y of bounding box.
-    //!
-    //!\param norm  Normal vector for box side (X, Y, or Z)
-    //!\param neg   Which of two planes with norm (true->smaller coord, 
-    //!             false->larget coord)
-    //!\param results List to which to append results.  This function does
-    //!             *not* clear existing values in list.
-    //!\param epsilon Tolerance on overlap.  A positive value E will
-    //!              result in nodes that are separated by as much as E
-    //!              to be considered touching.  A negative value -E will
-    //!              cause leaves that do not overlap by at least E to be
-    //!              considered non-overlapping.  Amongst other things, 
-    //!              this value can be used to control whether or not
-    //!              leaves adjacent at only their edges or corners are
-    //!              returned.
-  MBErrorCode get_neighbors( MBAdaptiveKDTree::Axis norm, bool neg,
-                             std::vector<MBAdaptiveKDTreeIter>& results,
-                             double epsilon = 0.0 ) const;
-  
-    //! Get split plane that separates this node from its immediate sibling.
-  MBErrorCode get_parent_split_plane( MBAdaptiveKDTree::Plane& plane ) const;
-  
-    //! Return true if thos node and the passed node share the
-    //! same immediate parent.
-  bool is_sibling( const MBAdaptiveKDTreeIter& other_leaf ) const;
-  
-    //! Return true if thos node and the passed node share the
-    //! same immediate parent.
-  bool is_sibling( MBEntityHandle other_leaf ) const;
-  
-    //! Returns true if calling step() will advance to the
-    //! immediate sibling of the current node.  Returns false
-    //! if current node is root or back() will move to the 
-    //! immediate sibling.
-  bool sibling_is_forward( ) const;
-  
-    //! Find range of overlap between ray and leaf.
-    //!
-    //!\param ray_point Coordinates of start point of ray
-    //!\param ray_vect  Directionion vector for ray such that
-    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
-    //!                 for t > 0.
-    //!\param t_enter   Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray entered the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\param t_exit    Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray exited the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\return true if ray intersects leaf, false otherwise.
-  bool intersect_ray( const double ray_point[3],
-                      const double ray_vect[3],
-                      double& t_enter, double& t_exit ) const;
-};
-
-#endif

Deleted: MOAB/trunk/src/moab/MBBSPTree.hpp
===================================================================
--- MOAB/trunk/src/moab/MBBSPTree.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBBSPTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,453 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBAdaptiveKDTree.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2008-05-12
- */
-
-#ifndef MB_BSP_TREE_HPP
-#define MB_BSP_TREE_HPP
-
-#include "MBTypes.h"
-#include "MBInterface.hpp"
-
-#include <math.h>
-#include <string>
-#include <vector>
-
-class MBBSPTreeBoxIter;
-class MBBSPTreeIter;
-class MBRange;
-class BSPTreePoly;
-
-class MBBSPTree
-{
-private:
-  MBInterface* mbInstance;
-  MBTag planeTag, rootTag;
-  unsigned meshSetFlags;
-  bool cleanUpTrees;
-  std::vector<MBEntityHandle> createdTrees;
-
-  MBErrorCode init_tags( const char* tagname = 0 );
-
-public:
-  
-  static double epsilon() { return 1e-6; }
-
-  MBBSPTree( MBInterface* iface,
-             const char* tagname = 0,
-             unsigned meshset_creation_flags = MESHSET_SET );
-
-  MBBSPTree( MBInterface* iface,
-             bool destroy_created_trees,
-             const char* tagname = 0,
-             unsigned meshset_creation_flags = MESHSET_SET );
-  
-  ~MBBSPTree();
-
-  //! Enumeriate split plane directions
-  enum Axis { X = 0, Y = 1, Z = 2 };
-  
-  /**\brief struct to store a plane 
-   *
-   * If plane is defined as Ax+By+Cz+D=0, then
-   * norm={A,B,C} and coeff=-D.
-   */
-  struct Plane {
-    Plane() {}
-    Plane( const double n[3], double d ) : coeff(d)
-      { norm[0] = n[0]; norm[1] = n[1]; norm[2] = n[2]; }
-      /** a x + b y + c z + d = 0 */
-    Plane( double a, double b, double c, double d ) : coeff(d)
-      { norm[0] = a; norm[1] = b; norm[2] = c; }
-      /** Create Y = 1 plane by doing Plane( Y, 1.0 ); */
-    Plane( Axis normal, double point_on_axis ) : coeff(-point_on_axis)
-      { norm[0] = norm[1] = norm[2] = 0; norm[normal] = 1.0; }
-  
-    double norm[3]; //!< Unit normal of plane
-    double coeff;   //!< norm[0]*x + norm[1]*y + norm[2]*z + coeff = 0
-    
-      /** Signed distance from point to plane: 
-       *    absolute value is distance from point to plane
-       *    positive if 'above' plane, negative if 'below'
-       *  Note: assumes unit-length normal.
-       */
-    double signed_distance( const double point[3] ) const
-      { return point[0]*norm[0]+point[1]*norm[1]+point[2]*norm[2] + coeff; }
-    
-      /** return true if point is below the plane */
-    bool below( const double point[3] ) const
-      { return signed_distance(point) <= 0.0; }
-    
-      /** return true if point is above the plane */
-    bool above( const double point[3] ) const
-      { return signed_distance(point) >= 0.0; }
-      
-    double distance( const double point[3] ) const
-      { return fabs( signed_distance(point) ); }
-  
-      /** reverse plane normal */
-    void flip()
-      { norm[0] = -norm[0]; norm[1] = -norm[1]; norm[2] = -norm[2]; coeff = -coeff; }
-  
-    void set( const double normal[3], const double point[3] )
-      { 
-         const double dot = normal[0]*point[0] + normal[1]*point[1] + normal[2]*point[2];
-        *this = Plane( normal, -dot ); 
-      }
-      
-    void set( const double pt1[3], const double pt2[3], const double pt3[3] );
-    
-    void set( double i, double j, double k, double coeff )
-      { *this = Plane( i, j, k, coeff ); }
-    
-      /** Create Y = 1 plane by doing set( Y, 1.0 ); */
-    void set( Axis normal, double point_on_axis )
-      { 
-        coeff = -point_on_axis;
-        norm[0] = norm[1] = norm[2] = 0; 
-        norm[normal] = 1.0; 
-      }
-  };
-  
-  //! Get split plane for tree node
-  MBErrorCode get_split_plane( MBEntityHandle node, Plane& plane )
-    { return moab()->tag_get_data( planeTag, &node, 1, &plane ); }
-  
-  //! Set split plane for tree node
-  MBErrorCode set_split_plane( MBEntityHandle node, const Plane& plane );
-  
-  //! Get bounding box for entire tree
-  MBErrorCode get_tree_box( MBEntityHandle root_node,
-                            double corner_coords[8][3] );
-  
-  //! Get bounding box for entire tree
-  MBErrorCode get_tree_box( MBEntityHandle root_node,
-                            double corner_coords[24] );
-  
-  //! Set bounding box for entire tree
-  MBErrorCode set_tree_box( MBEntityHandle root_node,
-                            const double box_min[3], 
-                            const double box_max[3] );
-  MBErrorCode set_tree_box( MBEntityHandle root_node,
-                            const double corner_coords[8][3] );
-  
-  //! Create tree root node
-  MBErrorCode create_tree( const double box_min[3],
-                           const double box_max[3],
-                           MBEntityHandle& root_handle );
-  MBErrorCode create_tree( const double corner_coords[8][3],
-                           MBEntityHandle& root_handle );
-  
-  //! Create tree root node
-  MBErrorCode create_tree( MBEntityHandle& root_handle );
-
-  //! Find all tree roots
-  MBErrorCode find_all_trees( MBRange& results );
-
-  //! Destroy a tree
-  MBErrorCode delete_tree( MBEntityHandle root_handle );
-
-  MBInterface* moab() { return mbInstance; }
-
-  //! Get iterator for tree
-  MBErrorCode get_tree_iterator( MBEntityHandle tree_root,
-                                 MBBSPTreeIter& result );
-  
-  //! Get iterator at right-most ('last') leaf.
-  MBErrorCode get_tree_end_iterator( MBEntityHandle tree_root,
-                                     MBBSPTreeIter& result );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBBSPTreeIter& leaf, Plane plane );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBBSPTreeIter& leaf, 
-                          Plane plane,
-                          MBEntityHandle& left_child,
-                          MBEntityHandle& right_child );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBBSPTreeIter& leaf, 
-                          Plane plane,
-                          const MBRange& left_entities,
-                          const MBRange& right_entities );
-
-  //! Split leaf of tree
-  //! Updates iterator location to point to first new leaf node.
-  MBErrorCode split_leaf( MBBSPTreeIter& leaf, 
-                          Plane plane,
-                          const std::vector<MBEntityHandle>& left_entities,
-                          const std::vector<MBEntityHandle>& right_entities );
-  
-  //! Merge the leaf pointed to by the current iterator with it's
-  //! sibling.  If the sibling is not a leaf, multiple merges may
-  //! be done.
-  MBErrorCode merge_leaf( MBBSPTreeIter& iter );
-
-  //! Get leaf contianing input position.
-  //!
-  //! Does not take into account global bounding box of tree.
-  //! - Therefore there is always one leaf containing the point.
-  //! - If caller wants to account for global bounding box, then
-  //!   caller can test against that box and not call this method
-  //!   at all if the point is outside the box, as there is no leaf
-  //!   containing the point in that case.
-  MBErrorCode leaf_containing_point( MBEntityHandle tree_root,
-                                     const double point[3],
-                                     MBEntityHandle& leaf_out );
-
-  //! Get iterator at leaf containing input position.
-  //! 
-  //! Returns MB_ENTITY_NOT_FOUND if point is not within
-  //! bounding box of tree.
-  MBErrorCode leaf_containing_point( MBEntityHandle tree_root,
-                                     const double xyz[3],
-                                     MBBSPTreeIter& result );
-};
-
-class MBBSPTreeIter
-{
-public:
-  
-  enum Direction { LEFT = 0, RIGHT = 1 };
-
-private:
-  friend class MBBSPTree;
-
-  MBBSPTree* treeTool;
-
-protected:
-  std::vector<MBEntityHandle> mStack;
-  mutable std::vector<MBEntityHandle> childVect;
-
-  virtual MBErrorCode step_to_first_leaf( Direction direction );
-
-  virtual MBErrorCode up();
-  virtual MBErrorCode down( const MBBSPTree::Plane& plane, Direction direction );
-  
-  virtual MBErrorCode initialize( MBBSPTree* tool,
-                                  MBEntityHandle root,
-                                  const double* point = 0 );
-  
-public:
-  
-  MBBSPTreeIter() : treeTool(0), childVect(2) {}
-  virtual ~MBBSPTreeIter() {}
-  
-
-  MBBSPTree* tool() const
-    { return treeTool; }
-
-    //! Get handle for current leaf
-  MBEntityHandle handle() const
-    { return mStack.back(); }
-    
-    //! Get depth in tree. root is at depth of 1.
-  unsigned depth() const
-    { return mStack.size(); }
-  
-  //! Advance the iterator either left or right in the tree
-  //! Note:  stepping past the end of the tree will invalidate
-  //!        the iterator.  It will *not* be work step the
-  //!        other direction.
-  virtual MBErrorCode step( Direction direction );
-
-    //! Advance to next leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at end.
-    //! Note: steping past the end of the tree will invalidate
-    //!       the iterator. Calling back() will not work.
-  MBErrorCode step() { return step(RIGHT); }
-
-    //! Move back to previous leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
-    //! Note: steping past the start of the tree will invalidate
-    //!       the iterator. Calling step() will not work.
-  MBErrorCode back() { return step(LEFT); }
-  
-  
-    //! Get split plane that separates this node from its immediate sibling.
-  MBErrorCode get_parent_split_plane( MBBSPTree::Plane& plane ) const;
-  
-    //! Get volume of leaf polyhedron
-  virtual double volume() const;
-  
-    //! Find range of overlap between ray and leaf.
-    //!
-    //!\param ray_point Coordinates of start point of ray
-    //!\param ray_vect  Directionion vector for ray such that
-    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
-    //!                 for t > 0.
-    //!\param t_enter   Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray entered the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\param t_exit    Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray exited the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\return true if ray intersects leaf, false otherwise.
-  virtual bool intersect_ray( const double ray_point[3],
-                              const double ray_vect[3],
-                              double& t_enter, double& t_exit ) const;
-  
-    //! Return true if thos node and the passed node share the
-    //! same immediate parent.
-  bool is_sibling( const MBBSPTreeIter& other_leaf ) const;
-  
-    //! Return true if thos node and the passed node share the
-    //! same immediate parent.
-  bool is_sibling( MBEntityHandle other_leaf ) const;
-  
-    //! Returns true if calling step() will advance to the
-    //! immediate sibling of the current node.  Returns false
-    //! if current node is root or back() will move to the 
-    //! immediate sibling.
-  bool sibling_is_forward( ) const;
-  
-    //! Calculate the convex polyhedron bounding this leaf.
-  virtual MBErrorCode calculate_polyhedron( BSPTreePoly& polyhedron_out ) const;
-};
-
-class MBBSPTreeBoxIter : public MBBSPTreeIter
-{
-  private:
-    
-    double leafCoords[8][3];
-    struct Corners { double coords[4][3]; };
-    std::vector<Corners> stackData;
-  
-  protected:
-
-    virtual MBErrorCode step_to_first_leaf( Direction direction );
-    
-    virtual MBErrorCode up();
-    virtual MBErrorCode down( const MBBSPTree::Plane& plane, Direction direction );
-  
-    virtual MBErrorCode initialize( MBBSPTree* tool,
-                                    MBEntityHandle root,
-                                    const double* point = 0 );
-  public:
-  
-
-    //! Faces of a hex : corner bitmap
-  enum SideBits { B0154 = 0x33, //!< Face defined by corners {0,1,5,4}: 1st Exodus side
-                  B1265 = 0x66, //!< Face defined by corners {1,2,6,5}: 2nd Exodus side
-                  B2376 = 0xCC, //!< Face defined by corners {2,3,7,6}: 3rd Exodus side
-                  B3047 = 0x99, //!< Face defined by corners {3,0,4,7}: 4th Exodus side
-                  B3210 = 0x0F, //!< Face defined by corners {3,2,1,0}: 5th Exodus side
-                  B4567 = 0xF0  //!< Face defined by corners {4,5,6,7}: 6th Exodus side
-                 };
-  
-  static SideBits side_above_plane( const double hex_coords[8][3],
-                                    const MBBSPTree::Plane& plane );
-  
-  static SideBits side_on_plane( const double hex_coords[8][3],
-                                 const MBBSPTree::Plane& plane );
-  
-  static SideBits opposite_face( const SideBits& bits ) 
-    { return (SideBits)((~bits) & 0xFF); }
-  
-  static MBErrorCode face_corners( const SideBits face, 
-                                   const double hex_corners[8][3],
-                                   double face_corners_out[4][3] );
-  
-  //! Advance the iterator either left or right in the tree
-  //! Note:  stepping past the end of the tree will invalidate
-  //!        the iterator.  It will *not* work to subsequently 
-  //!        step the other direction.
-  virtual MBErrorCode step( Direction direction );
-
-    //! Advance to next leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at end.
-    //! Note: steping past the end of the tree will invalidate
-    //!       the iterator. Calling back() will not work.
-  MBErrorCode step() { return MBBSPTreeIter::step(); }
-
-    //! Move back to previous leaf
-    //! Returns MB_ENTITY_NOT_FOUND if at beginning.
-    //! Note: steping past the start of the tree will invalidate
-    //!       the iterator. Calling step() will not work.
-  MBErrorCode back() { return MBBSPTreeIter::back(); }
-  
-    //! Get coordinates of box corners, in Exodus II hexahedral ordering.
-  MBErrorCode get_box_corners( double coords[8][3] ) const;
-  
-    //! Get volume of leaf box
-  double volume() const;
-  
-    //! test if a plane intersects the leaf box
-  enum XSect { MISS = 0, SPLIT = 1, NONHEX = -1 };
-  XSect splits( const MBBSPTree::Plane& plane ) const;
-  
-    //! test if a plane intersects the leaf box
-  bool intersects( const MBBSPTree::Plane& plane ) const;
-  
-    //! Find range of overlap between ray and leaf.
-    //!
-    //!\param ray_point Coordinates of start point of ray
-    //!\param ray_vect  Directionion vector for ray such that
-    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
-    //!                 for t > 0.
-    //!\param t_enter   Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray entered the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\param t_exit    Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray exited the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\return true if ray intersects leaf, false otherwise.
-  bool intersect_ray( const double ray_point[3],
-                      const double ray_vect[3],
-                      double& t_enter, double& t_exit ) const;
-  
-    //! Return the side of the box bounding this tree node
-    //! that is shared with the immediately adjacent sibling
-    //! (the tree node that shares a common parent node with
-    //! this node in the binary tree.)
-    //!
-    //!\return MB_ENTITY_NOT FOUND if root node.
-    //!        MB_FAILURE if internal error.
-    //!        MB_SUCCESS otherwise.
-  MBErrorCode sibling_side( SideBits& side_out ) const;
-  
-    //! Get adjacent leaf nodes on indicated side
-    //!
-    //!\param side   Face of box for which to retrieve neighbors
-    //!\param results List to which to append results.  This function does
-    //!             *not* clear existing values in list.
-    //!\param epsilon Tolerance on overlap.  A positive value E will
-    //!              result in nodes that are separated by as much as E
-    //!              to be considered touching.  A negative value -E will
-    //!              cause leaves that do not overlap by at least E to be
-    //!              considered non-overlapping.  Amongst other things, 
-    //!              this value can be used to control whether or not
-    //!              leaves adjacent at only their edges or corners are
-    //!              returned.
-  MBErrorCode get_neighbors( SideBits side,
-                             std::vector<MBBSPTreeBoxIter>& results,
-                             double epsilon = 0.0 ) const;
-  
-    //! Calculate the convex polyhedron bounding this leaf.
-  MBErrorCode calculate_polyhedron( BSPTreePoly& polyhedron_out ) const;
-};
-
-#endif

Modified: MOAB/trunk/src/moab/MBCN.hpp
===================================================================
--- MOAB/trunk/src/moab/MBCN.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBCN.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -29,22 +29,24 @@
  * Numbering Conventions", Timothy J. Tautges, Sandia National Laboratories
  * Report #SAND2004-xxxx.
  */
-#ifndef MBCN_HPP
-#define MBCN_HPP
+#ifndef MOAB_MBCN_HPP
+#define MOAB_MBCN_HPP
 
 #include <vector>
 #include <algorithm>
 #include <cassert>
 
-#include "MBEntityType.h"
+#include "moab/EntityType.hpp"
 
+namespace moab {
+
 // the maximum number n-1 dimension adjacencies a element may have
 #define MB_MAX_SUB_ENTITIES  12
 
 // the maximum number of nodes an n-1 dimensional element may have
 #define MB_MAX_SUB_ENTITY_VERTICES 9
 
-typedef std::pair<MBEntityType, MBEntityType> MBDimensionPair;
+typedef std::pair<EntityType, EntityType> DimensionPair;
 
 class MBCN
 {
@@ -89,7 +91,7 @@
     short int num_corners_per_sub_element[MB_MAX_SUB_ENTITIES];
 
       // Type of each sub-element
-    MBEntityType target_type[MB_MAX_SUB_ENTITIES];
+    EntityType target_type[MB_MAX_SUB_ENTITIES];
 
       // Connectivity of each of the sub-elements
     short int conn[MB_MAX_SUB_ENTITIES][MB_MAX_SUB_ENTITY_VERTICES];
@@ -129,10 +131,10 @@
   static short int permuteVec[MBMAXTYPE][3][MB_MAX_SUB_ENTITIES+1];
   static short int revPermuteVec[MBMAXTYPE][3][MB_MAX_SUB_ENTITIES+1];
   
-  //! this const vector defines the starting and ending MBEntityType for 
-  //! each dimension, e.g. TypeDimensionMap[2] returns a pair of MBEntityTypes 
+  //! this const vector defines the starting and ending EntityType for 
+  //! each dimension, e.g. TypeDimensionMap[2] returns a pair of EntityTypes 
   //! bounding dimension 2.
-  static const MBDimensionPair TypeDimensionMap[];
+  static const DimensionPair TypeDimensionMap[];
 
   //! get the basis of the numbering system
   static short int GetBasis();
@@ -142,22 +144,22 @@
 
   //! return the string type name for this type
   static inline
-  const char *EntityTypeName(const MBEntityType this_type);
+  const char *EntityTypeName(const EntityType this_type);
   
   //! given a name, find the corresponding entity type
-  static MBEntityType EntityTypeFromName(const char *name);
+  static EntityType EntityTypeFromName(const char *name);
   
   //! return the topological entity dimension
   static inline
-  short int Dimension(const MBEntityType t);
+  short int Dimension(const EntityType t);
 
   //! return the number of (corner) vertices contained in the specified type.  
   static inline
-  short int VerticesPerEntity(const MBEntityType t);
+  short int VerticesPerEntity(const EntityType t);
   
   //! return the number of sub-entities bounding the entity.
   static inline
-  short int NumSubEntities(const MBEntityType t, const int d);
+  short int NumSubEntities(const EntityType t, const int d);
 
   //! return the type of a particular sub-entity.
   //! \param this_type Type of entity for which sub-entity type is being queried
@@ -165,7 +167,7 @@
   //! \param index Index of sub-entity whose type is being queried
   //! \return type Entity type of sub-entity with specified dimension and index
   static inline
-  MBEntityType SubEntityType(const MBEntityType this_type,
+  EntityType SubEntityType(const EntityType this_type,
                              const int sub_dimension,
                              const int index);
   
@@ -175,7 +177,7 @@
   //! \param sub_index Index of sub-entity
   //! \param sub_entity_conn Connectivity of sub-entity (returned to calling function)
   static inline
-  void SubEntityVertexIndices(const MBEntityType this_type, 
+  void SubEntityVertexIndices(const EntityType this_type, 
                               const int sub_dimension,
                               const int sub_index,
                               int sub_entity_conn[]);
@@ -186,10 +188,10 @@
   //! \param sub_index Index of sub-entity
   //! \param num_sub_ent_vertices the number of vertices in the sub-entity
   static inline
-  const short* SubEntityVertexIndices( const MBEntityType this_type, 
+  const short* SubEntityVertexIndices( const EntityType this_type, 
                                        const int sub_dimension,
                                        const int sub_index,
-                                       MBEntityType& sub_type,
+                                       EntityType& sub_type,
                                        int& num_sub_ent_vertices );
   
   //! return the node indices of the specified sub-entity.
@@ -200,11 +202,11 @@
   //! \param sub_entity_topo      (Output) Topology of requested sub-entity.
   //! \param num_sub_entity_nodes (Output) Number of nodes in the requested sub-entity.
   //! \param sub_entity_conn      (Output) Connectivity of sub-entity
-  static void SubEntityNodeIndices(const MBEntityType this_topo, 
+  static void SubEntityNodeIndices(const EntityType this_topo, 
                                    const int num_nodes,
                                    const int sub_dimension,
                                    const int sub_index,
-                                   MBEntityType& sub_entity_topo,
+                                   EntityType& sub_entity_topo,
                                    int& num_sub_entity_nodes,
                                    int sub_entity_conn[]);
 
@@ -216,7 +218,7 @@
   //! \param sub_entity_conn Connectivity of sub-entity, based on parent_conn and canonical
   //!           ordering for parent_type
   //! \param num_sub_vertices Number of vertices in sub-entity
-  static void SubEntityConn(const void *parent_conn, const MBEntityType parent_type,
+  static void SubEntityConn(const void *parent_conn, const EntityType parent_type,
                             const int sub_dimension,
                             const int sub_index,
                             void *sub_entity_conn, int &num_sub_vertices);
@@ -231,7 +233,7 @@
   //! \param index_list Indices of target entities (returned)
   //! \param operation_type Specify either MBCN::INTERSECT or MBCN::UNION to get intersection
   //!        or union of target entity lists over source entities
-  static short int AdjacentSubEntities(const MBEntityType this_type,
+  static short int AdjacentSubEntities(const EntityType this_type,
                                  const int *source_indices,
                                  const int num_source_indices,
                                  const int source_dim,
@@ -250,23 +252,23 @@
   //! \param sense Sense of child entity with respect to order in <em>child_conn</em> (returned)
   //! \param offset Offset of <em>child_conn</em> with respect to canonical ordering data (returned)
   //! \return status Returns zero if successful, -1 if not
-  static short int SideNumber(const MBEntityType parent_type, const int *parent_conn, 
+  static short int SideNumber(const EntityType parent_type, const int *parent_conn, 
                               const int *child_conn, const int child_num_verts,
                               const int child_dim,
                         int &side_number, int &sense, int &offset);
-  static short int SideNumber(const MBEntityType parent_type, const unsigned int *parent_conn, 
+  static short int SideNumber(const EntityType parent_type, const unsigned int *parent_conn, 
                         const unsigned int *child_conn, const int child_num_verts,
                         const int child_dim,
                         int &side_number, int &sense, int &offset);
-  static short int SideNumber(const MBEntityType parent_type, const long *parent_conn, 
+  static short int SideNumber(const EntityType parent_type, const long *parent_conn, 
                         const long *child_conn, const int child_num_verts,
                         const int child_dim,
                         int &side_number, int &sense, int &offset);
-  static short int SideNumber(const MBEntityType parent_type, const unsigned long *parent_conn, 
+  static short int SideNumber(const EntityType parent_type, const unsigned long *parent_conn, 
                         const unsigned long *child_conn, const int child_num_verts,
                         const int child_dim,
                         int &side_number, int &sense, int &offset);
-  static short int SideNumber(const MBEntityType parent_type, void * const *parent_conn, 
+  static short int SideNumber(const EntityType parent_type, void * const *parent_conn, 
                         void * const *child_conn, const int child_num_verts,
                         const int child_dim,
                         int &side_number, int &sense, int &offset);
@@ -281,7 +283,7 @@
   //! \param sense Sense of child entity with respect to order in <em>child_conn</em> (returned)
   //! \param offset Offset of <em>child_conn</em> with respect to canonical ordering data (returned)
   //! \return status Returns zero if successful, -1 if not
-  static short int SideNumber(const MBEntityType parent_type,
+  static short int SideNumber(const EntityType parent_type,
                         const int *child_conn_indices, const int child_num_verts,
                         const int child_dim,
                         int &side_number, int &sense, int &offset);
@@ -299,7 +301,7 @@
   //! \param child_index The index of the child element
   //! \param opposite_index The index of the opposite element
   //! \return status Returns 0 if successful, -1 if not
-  static short int OppositeSide(const MBEntityType parent_type,
+  static short int OppositeSide(const EntityType parent_type,
                           const int child_index,
                           const int child_dim,
                           int &opposite_index,
@@ -344,14 +346,14 @@
     //! \param num_entries Number of indicies in permutation array
     //! \param is_reverse Array is reverse permutation
   static inline
-  void setPermutation(const MBEntityType t, const int dim, int *pvec, 
+  void setPermutation(const EntityType t, const int dim, int *pvec, 
                       const int num_entries, const bool is_reverse = false);
 
     //! Reset permutation or reverse permutation vector
     //! \param t EntityType whose permutation vector is being reset
     //! \param dim Dimension of facets being reset; if -1 is input, all dimensions are reset
   static inline
-  void resetPermutation(const MBEntityType t, const int dim);
+  void resetPermutation(const EntityType t, const int dim);
   
     //! Permute a handle array according to permutation vector set with setPermute; 
     //! permutation is done in-place
@@ -360,13 +362,13 @@
     //! \param pvec Handle array being permuted
     //! \param indices_per_ent Number of indices per entity
     //! \param num_entries Number of entities in pvec
-  static int permuteThis(const MBEntityType t, const int dim, int *pvec, 
+  static int permuteThis(const EntityType t, const int dim, int *pvec, 
                          const int indices_per_ent, const int num_entries);
-  static int permuteThis(const MBEntityType t, const int dim, unsigned int *pvec, 
+  static int permuteThis(const EntityType t, const int dim, unsigned int *pvec, 
                          const int indices_per_ent, const int num_entries);
-  static int permuteThis(const MBEntityType t, const int dim, long *pvec, 
+  static int permuteThis(const EntityType t, const int dim, long *pvec, 
                          const int indices_per_ent, const int num_entries);
-  static int permuteThis(const MBEntityType t, const int dim, void **pvec, 
+  static int permuteThis(const EntityType t, const int dim, void **pvec, 
                          const int indices_per_ent, const int num_entries);
 
     //! Reverse permute a handle array according to reverse permutation vector set with setPermute; 
@@ -376,13 +378,13 @@
     //! \param pvec Handle array being reverse permuted
     //! \param indices_per_ent Number of indices per entity
     //! \param num_entries Number of entities in pvec
-  static int revPermuteThis(const MBEntityType t, const int dim, int *pvec, 
+  static int revPermuteThis(const EntityType t, const int dim, int *pvec, 
                             const int indices_per_ent, const int num_entries);
-  static int revPermuteThis(const MBEntityType t, const int dim, unsigned int *pvec, 
+  static int revPermuteThis(const EntityType t, const int dim, unsigned int *pvec, 
                             const int indices_per_ent, const int num_entries);
-  static int revPermuteThis(const MBEntityType t, const int dim, long *pvec, 
+  static int revPermuteThis(const EntityType t, const int dim, long *pvec, 
                             const int indices_per_ent, const int num_entries);
-  static int revPermuteThis(const MBEntityType t, const int dim, void **pvec, 
+  static int revPermuteThis(const EntityType t, const int dim, void **pvec, 
                             const int indices_per_ent, const int num_entries);
 
   //! true if entities of a given type and number of nodes indicates mid edge nodes are present.
@@ -391,7 +393,7 @@
   //! \return bool Returns true if <em>this_type</em> combined with <em>num_nodes</em> indicates
   //!  mid-edge nodes are likely
   static inline
-  bool HasMidEdgeNodes(const MBEntityType this_type, 
+  bool HasMidEdgeNodes(const EntityType this_type, 
                        const int num_verts);
 
   //! true if entities of a given type and number of nodes indicates mid face nodes are present.
@@ -400,7 +402,7 @@
   //! \return bool Returns true if <em>this_type</em> combined with <em>num_nodes</em> indicates
   //!  mid-face nodes are likely
   static inline
-  bool HasMidFaceNodes(const MBEntityType this_type, 
+  bool HasMidFaceNodes(const EntityType this_type, 
                        const int num_verts);
 
   //! true if entities of a given type and number of nodes indicates mid region nodes are present.
@@ -409,7 +411,7 @@
   //! \return bool Returns true if <em>this_type</em> combined with <em>num_nodes</em> indicates
   //!  mid-region nodes are likely
   static inline
-  bool HasMidRegionNodes(const MBEntityType this_type, 
+  bool HasMidRegionNodes(const EntityType this_type, 
                          const int num_verts);
 
   //! true if entities of a given type and number of nodes indicates mid edge/face/region nodes 
@@ -419,7 +421,7 @@
   //! \param mid_nodes If <em>mid_nodes[i], i=1..2</em> is non-zero, indicates that mid-edge 
   //!    (i=1), mid-face (i=2), and/or mid-region (i=3) nodes are likely
   static inline
-  void HasMidNodes(const MBEntityType this_type, 
+  void HasMidNodes(const EntityType this_type, 
                    const int num_verts, 
                    int mid_nodes[4]);
 
@@ -428,7 +430,7 @@
   //! mid nodes on sub entities of the least dimension (0) to the highest
   //! dimension (3) are present in the elment type.
   static inline
-  int HasMidNodes( const MBEntityType this_type, const int num_verts );
+  int HasMidNodes( const EntityType this_type, const int num_verts );
 
   //! given data about an element and a vertex in that element, return the dimension
   //! and index of the sub-entity that the vertex resolves.  If it does not resolve a
@@ -439,7 +441,7 @@
   //! \param ho_node_index The position of the HO node in the connectivity list (zero based)
   //! \param parent_dim Dimension of sub-entity high-order node resolves (returned)
   //! \param parent_index Index of sub-entity high-order node resolves (returned)
-  static void HONodeParent( MBEntityType elem_type,
+  static void HONodeParent( EntityType elem_type,
                             int num_nodes, 
                             int ho_node_index,
                             int &parent_dim, 
@@ -453,36 +455,36 @@
   //! \param subfacet_dim Dimension of sub-entity being queried
   //! \param subfacet_index Index of sub-entity being queried
   //! \return index Index of sub-entity's higher-order node
-  static short int HONodeIndex(const MBEntityType this_type, const int num_verts,
+  static short int HONodeIndex(const EntityType this_type, const int num_verts,
                          const int subfacet_dim, const int subfacet_index);
 };
 
   //! get the basis of the numbering system
 inline short int MBCN::GetBasis() {return numberBasis;}
   
-inline const char *MBCN::EntityTypeName(const MBEntityType this_type) 
+inline const char *MBCN::EntityTypeName(const EntityType this_type) 
 {
   return entityTypeNames[this_type];
 }
 
-inline short int MBCN::Dimension(const MBEntityType t) 
+inline short int MBCN::Dimension(const EntityType t) 
 {
   return mConnectivityMap[t][0].topo_dimension;
 }
 
-inline short int MBCN::VerticesPerEntity(const MBEntityType t) 
+inline short int MBCN::VerticesPerEntity(const EntityType t) 
 {
   return (MBVERTEX == t ? 1 : mConnectivityMap[t][mConnectivityMap[t][0].topo_dimension-1].num_corners_per_sub_element[0]);
 }
 
-inline short int MBCN::NumSubEntities(const MBEntityType t, const int d)
+inline short int MBCN::NumSubEntities(const EntityType t, const int d)
 {
   return (t != MBVERTEX && d > 0 ? mConnectivityMap[t][d-1].num_sub_elements :
           (d ? -1 : VerticesPerEntity(t)));
 }
 
   //! return the type of a particular sub-entity.
-inline MBEntityType MBCN::SubEntityType(const MBEntityType this_type,
+inline EntityType MBCN::SubEntityType(const EntityType this_type,
                                         const int sub_dimension,
                                         const int index) 
 {
@@ -492,10 +494,10 @@
           mConnectivityMap[this_type][sub_dimension-1].target_type[index]));
 }
 
-inline const short* MBCN::SubEntityVertexIndices( const MBEntityType this_type, 
+inline const short* MBCN::SubEntityVertexIndices( const EntityType this_type, 
                                                   const int sub_dimension,
                                                   const int index,
-                                                  MBEntityType& sub_type,
+                                                  EntityType& sub_type,
                                                   int& n ) 
 {
   if (sub_dimension == 0) {
@@ -512,46 +514,46 @@
 }
   
   //! return the connectivity of the specified sub-entity.
-inline void MBCN::SubEntityVertexIndices(const MBEntityType this_type, 
+inline void MBCN::SubEntityVertexIndices(const EntityType this_type, 
                                          const int sub_dimension,
                                          const int index,
                                          int sub_entity_conn[]) 
 {
-  MBEntityType type;
+  EntityType type;
   int n;
   const short* indices = SubEntityVertexIndices( this_type, sub_dimension, index, type, n );
   std::copy( indices, indices+n, sub_entity_conn );
 }
 
-inline bool MBCN::HasMidEdgeNodes(const MBEntityType this_type, 
+inline bool MBCN::HasMidEdgeNodes(const EntityType this_type, 
                                      const int num_nodes)
 {
   const int bits = HasMidNodes( this_type, num_nodes );
   return static_cast<bool>( (bits & (1<<1)) >> 1 );
 }
 
-inline bool MBCN::HasMidFaceNodes(const MBEntityType this_type, 
+inline bool MBCN::HasMidFaceNodes(const EntityType this_type, 
                                        const int num_nodes)
 {
   const int bits = HasMidNodes( this_type, num_nodes );
   return static_cast<bool>( (bits & (1<<2)) >> 2 );
 }
 
-inline bool MBCN::HasMidRegionNodes(const MBEntityType this_type, 
+inline bool MBCN::HasMidRegionNodes(const EntityType this_type, 
                                          const int num_nodes)
 {
   const int bits = HasMidNodes( this_type, num_nodes );
   return static_cast<bool>( (bits & (1<<3)) >> 3 );
 }
 
-inline int MBCN::HasMidNodes( const MBEntityType this_type, const int num_nodes )
+inline int MBCN::HasMidNodes( const EntityType this_type, const int num_nodes )
 {
   assert( (unsigned)num_nodes <= (unsigned)MAX_NODES_PER_ELEMENT );
   return midNodesPerType[this_type][num_nodes];
 }
   
 
-inline void MBCN::HasMidNodes(const MBEntityType this_type, const int num_nodes,
+inline void MBCN::HasMidNodes(const EntityType this_type, const int num_nodes,
                               int mid_nodes[4])
 {
   const int bits = HasMidNodes( this_type, num_nodes );
@@ -562,7 +564,7 @@
 }
 
 //! Set permutation or reverse permutation vector
-inline void MBCN::setPermutation(const MBEntityType t, const int dim, int *pvec, 
+inline void MBCN::setPermutation(const EntityType t, const int dim, int *pvec, 
                                  const int num_entries, const bool is_reverse) 
 {
   short int *this_vec = permuteVec[t][dim], *that_vec = revPermuteVec[t][dim];
@@ -580,7 +582,7 @@
 }
 
 //! Reset permutation or reverse permutation vector
-inline void MBCN::resetPermutation(const MBEntityType t, const int dim) 
+inline void MBCN::resetPermutation(const EntityType t, const int dim) 
 {
   if (-1 == dim) {
     for (unsigned int i = 0; i < 3; i++) resetPermutation(t, i);
@@ -595,4 +597,6 @@
     permuteVec[t][dim][MB_MAX_SUB_ENTITIES] = MB_MAX_SUB_ENTITIES+1;
 }
 
+} // namespace moab 
+
 #endif

Deleted: MOAB/trunk/src/moab/MBCore.hpp
===================================================================
--- MOAB/trunk/src/moab/MBCore.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBCore.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1208 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifndef MB_IMPL_GENERAL_HPP
-#define MB_IMPL_GENERAL_HPP
-
-#include "MBInterface.hpp"
-#include "MBReaderIface.hpp"
-#include <map>
-
-class MBWriteUtil;
-class MBReadUtil;
-class AEntityFactory;
-class SequenceManager;
-class TagServer;
-class MBError;
-class HomCoord;
-class MBReaderWriterSet;
-class EntitySequence;
-class FileOptions;
-
-#ifdef XPCOM_MB
-
-#define MBCORE_CID \
-{ 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xba, 0xb2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
-
-#define MBCORE_CONTRACTID "@sandia.gov/MB;1"
-
-#endif
-
-
-class MBCore : public MBInterface 
-{
-
-public:
-
-  //!constructor
-  MB_DLL_EXPORT MBCore();
-
-  //! depricated constructor -- values are ignored
-  MB_DLL_EXPORT MBCore( int rank, int num_cpu );
-
-  //!destructor
-  MB_DLL_EXPORT ~MBCore();
-  
-  //! query an MB internal interface
-  virtual MBErrorCode query_interface(const std::string& iface_name, void** iface);
- 
-  //! release an MB internal interface 
-  virtual MBErrorCode release_interface(const std::string& iface_name, void* iface);
-
-#if defined(XPCOM_MB)
-  // this macro expands to all the nsISupports interface functions
-  NS_DECL_ISUPPORTS
-#endif
-
-  virtual int QueryInterface (const MBuuid& uuid, MBUnknownInterface** iface );
-
-    //! Returns the major.minor version number of the implementation
-    /**
-       \param iface_name If non-NULL, will be filled in with a string, possibly 
-       containing implementation-specific information
-    */
-  virtual float impl_version(std::string *version_string = NULL);
-
-  //! get the type from a handle, returns type
-  virtual MBEntityType type_from_handle(const MBEntityHandle handle) const;
-  
-  //! get the id from a handle, returns id
-  virtual MBEntityID id_from_handle(const MBEntityHandle handle) const;
-  
-  //! get a handle from an id and type
-  virtual MBErrorCode handle_from_id(const MBEntityType type, 
-                                      const MBEntityID id, 
-                                      MBEntityHandle& handle) const;
-  
-  virtual int dimension_from_handle( const MBEntityHandle ) const;
-
-  //! load mesh from data in file
-  //! NOTE: if there is mesh already present, the new mesh will be added
-  virtual MBErrorCode load_mesh(const char *file_name,
-                                 const int *active_block_id_list = NULL,
-                                 const int num_blocks = 0);
-
-  /**Load or import a file. */
-  virtual MBErrorCode load_file( const char* file_name,
-                                 const MBEntityHandle* file_set = 0,
-                                 const char* options = 0,
-                                 const char* set_tag_name = 0,
-                                 const int* set_tag_values = 0,
-                                 int num_set_tag_values = 0 );
-
-  /**Load or import a file. */
-  MBErrorCode serial_load_file( const char* file_name,
-                         const MBEntityHandle* file_set,
-                         const FileOptions& opts,
-                         const MBReaderIface::IDTag* subset_list = 0,
-                         int subset_list_length = 0,
-                         const MBTag* file_id_tag = 0 );
-                         
-  MBErrorCode serial_read_tag( const char* file_name,
-                               const char* tag_name,
-                               const FileOptions& opts,
-                               std::vector<int>& tag_vals,
-                               const MBReaderIface::IDTag* subset_list = 0,
-                               int subset_list_length = 0 );
-  
-  virtual MBErrorCode write_mesh(const char *file_name,
-                                  const MBEntityHandle *output_list = NULL,
-                                  const int num_sets = 0);
-  /** Write or export a file. */
-  virtual MBErrorCode write_file( const char* file_name,
-                                  const char* file_type = 0,
-                                  const char* options = 0,
-                                  const MBEntityHandle* output_sets = 0,
-                                  int num_output_sets = 0,
-                                  const MBTag* tag_list = 0,
-                                  int num_tags = 0 );
-
-  /** Write or export a file */
-  virtual MBErrorCode write_file( const char* file_name,
-                                  const char* file_type,
-                                  const char* options,
-                                  const MBRange& output_sets,
-                                  const MBTag* tag_list = 0,
-                                  int num_tags = 0 );
-
-  //! deletes all mesh entities from this datastore
-  virtual MBErrorCode delete_mesh();
-
-  //! get overall geometric dimension
-  virtual MBErrorCode get_dimension(int &dim) const;
-
-  //! set overall geometric dimension
-  /** Returns error if setting to 3 dimensions, mesh has been created, and 
-   *  there are only 2 dimensions on that mesh
-   */
-  virtual MBErrorCode set_dimension(const int dim);
-
-  //! get blocked vertex coordinates for all vertices
-  /** Blocked = all x, then all y, etc. 
-   */
-  virtual MBErrorCode get_vertex_coordinates(std::vector<double> &coords) const;
-
-  //! get the coordinate information for this handle if it is of type Vertex
-  //! otherwise, return an error
-  virtual MBErrorCode  get_coords(const MBRange &entity_handles, 
-                                   double *coords) const;
-  
-  virtual MBErrorCode  get_coords(const MBEntityHandle *entity_handles, 
-                                   const int num_entities, 
-                                   double *coords) const;
-  
-  virtual MBErrorCode  get_coords(const MBEntityHandle entity_handle, 
-                                   const double *& x, const double *& y, const double *& z) const;
- 
-  virtual MBErrorCode get_coords( const MBRange& entity_handles,
-                                  double* x_coords,
-                                  double* y_coords,
-                                  double* z_coords ) const;
-
-  //! set the coordinate information for this handle if it is of type Vertex
-  //! otherwise, return an error
-  virtual MBErrorCode  set_coords( const MBEntityHandle *entity_handles, 
-                                   const int num_entities,
-                                   const double *coords);
-
-  //! set the coordinate information for this handle if it is of type Vertex
-  //! otherwise, return an error
-  virtual MBErrorCode  set_coords(MBRange entity_handles,
-                                  const double *coords);
-
-      //! get global connectivity array for specified entity type
-      /**  Assumes just vertices, no higher order nodes
-       */
-    virtual MBErrorCode get_connectivity_by_type(const MBEntityType type, 
-                                                  std::vector<MBEntityHandle> &connect) const;
-
-      //! Gets the connectivity for an element MBEntityHandle. 
-      /** For non-element handles (ie, MBMeshSets), 
-          returns an error. Connectivity data is copied from the database into the vector 
-          <em>connectivity</em>. The nodes in <em>connectivity</em> are properly ordered.
-          \param entity_handle MBEntityHandle to get connectivity of.
-          \param connectivity Vector in which connectivity of <em>entity_handle</em> is returned.  
-          Should contain MeshVertices.
-          \param topological_connectivity If true, higher order nodes are ignored. 
-
-          Example: \code 
-          std::vector<MBEntityHandle> conn;
-          get_connectivity( entity_handle, conn ); \endcode */
-    virtual MBErrorCode  get_connectivity(const MBEntityHandle *entity_handles, 
-                                           const int num_handles,
-                                           std::vector<MBEntityHandle> &connectivity, 
-                                           bool topological_connectivity = false) const;
- 
-    //! Gets the connectivity for a vector of elements
-    /** Same as vector-based version except range is returned (unordered!)
-     */
-  virtual MBErrorCode  get_connectivity(const MBEntityHandle *entity_handles, 
-                                        const int num_handles,
-                                        MBRange &connectivity, 
-                                        bool topological_connectivity = false) const;
-
-    //! Gets the connectivity for elements
-    /** Same as vector-based version except range is returned (unordered!)
-    */
-  virtual MBErrorCode get_connectivity( const MBRange& entity_handles, 
-                                        MBRange &connectivity, 
-                                        bool topological_connectivity = false) const;
- 
-    //! Gets a pointer to constant connectivity data of <em>entity_handle</em> 
-      /** Sets <em>number_nodes</em> equal to the number of nodes of the <em> 
-          entity_handle </em>.  Faster then the other <em>get_connectivity</em> function. 
-          The nodes in 'connectivity' are properly ordered. 
-          \param entity_handle MBEntityHandle to get connectivity of.
-          \param connectivity Array in which connectivity of <em>entity_handle</em> is returned.
-          Should contain MeshVertex's.
-          \param num_nodes Number of MeshVertices in array <em>connectivity</em>. 
-
-          Example: \code 
-          const MBEntityHandle* conn;
-          int number_nodes = 0;
-          get_connectivity( entity_handle, conn, number_nodes ); \endcode 
-          
-          Example2: \code
-          std::vector<MBEntityHandle> sm_storage;
-          const MBEntityHandle* conn;
-          int number_nodes;
-          get_connectivity( handle, conn, number_nodes, false, &sm_storage );
-          if (conn == &sm_storage[0])
-            std::cout << "Structured mesh element" << std::endl;
-          \endcode
-        */
-    virtual MBErrorCode  get_connectivity( const MBEntityHandle entity_handle, 
-                                           const MBEntityHandle *&connectivity, 
-                                           int &num_nodes, 
-                                           bool topological_connectivity = false,
-                                           std::vector<MBEntityHandle>* storage = 0
-                                          ) const;
-
-      //! Sets the connectivity for an MBEntityHandle.  For non-element handles, return an error.
-      /** Connectivity is stored exactly as it is ordered in vector <em>connectivity</em>. 
-          \param entity_handle MBEntityHandle to set connectivity of.
-          \param connect Vector containing new connectivity of <em>entity_handle</em>.
-          \param num_connect Number of vertices in <em>connect</em>
-   
-          Example: \code 
-          std::vector<MBEntityHandle> conn(3);
-          conn[0] = node1;
-          conn[1] = node2;
-          conn[2] = node3;
-          set_connectivity( entity_handle, conn, 3 ); \endcode */
-    virtual MBErrorCode  set_connectivity(const MBEntityHandle entity_handle, 
-                                          MBEntityHandle *connect,
-                                          const int num_connect);
-
-      //! get the adjacencies associated with a set of entities
-      /** \param from_entities vector of MBEntityHandle to get adjacencies of.
-          \param to_dimension Dimension of desired adjacency information.
-          \param adj_entities Vector in which adjacent MBEntityHandles are returned. 
-          \param operation_type enum of INTERSECT or UNION.  Defines whether to take
-          the intersection or union of the set of adjacencies recovered for the from_entities.
-
-          The adjacent entities in vector <em>adjacencies</em> are not in any particular 
-          order. 
-
-          Example: \code
-            // get the set of edges that are adjacent to all entities in the from_entities list
-            std::vector<MBEntityHandle> from_entities = {hex1, hex2};
-            std::vector<MBEntityHandle> adjacencies;
-            get_adjacencies( from_entities, MB_1D_ENTITY, adjacencies ); 
-            \endcode */
-
-    virtual MBErrorCode get_adjacencies(const MBEntityHandle *from_entities,
-                                         const int num_entities,
-                                         const int to_dimension,
-                                         const bool create_if_missing,
-                                         std::vector<MBEntityHandle>& adj_entities,
-                                         const int operation_type = MBInterface::INTERSECT);
-
-    virtual MBErrorCode get_adjacencies(const MBEntityHandle *from_entities,
-                                        const int num_entities,
-                                         const int to_dimension,
-                                         const bool create_if_missing,
-                                         MBRange &adj_entities,
-                                         const int operation_type = MBInterface::INTERSECT);
-
-    virtual MBErrorCode get_adjacencies(const MBRange &from_entities,
-                                         const int to_dimension,
-                                         const bool create_if_missing,
-                                         MBRange &adj_entities,
-                                         const int operation_type = MBInterface::INTERSECT);
-
-      /**\brief Get all vertices for input entities
-       *
-       * Special case of get_adjacencies where to_dimension == 0
-       * and operation_type == MBInterface::UNION.  
-       *\Note This is not a variation of get_connectivity because
-       *      the behavior is different for polyhedra.
-       */
-    virtual MBErrorCode get_vertices( const MBRange& from_entities,
-                                      MBRange& vertices );
-
-      //! Adds adjacencies
-      /** \param from_handle entities 
-          \param both_ways add the adjacency information to both the
-          to_handle and and the from_from :handle
-
-          Example: \code
-      */
-    virtual MBErrorCode add_adjacencies(const MBEntityHandle from_handle, 
-                                         const MBEntityHandle *to_handles,
-                                         const int num_handles,
-                                         bool both_ways);
-
-      //! Adds adjacencies; same as vector-based, but with range instead
-    virtual MBErrorCode add_adjacencies(const MBEntityHandle from_handle, 
-                                        MBRange &adjacencies,
-                                        bool both_ways);
-
-      //! Removes adjacencies
-      /** \param handle MBEntityHandle to get adjacencies of.
-
-      Example: \code
-      */
-    virtual MBErrorCode remove_adjacencies(const MBEntityHandle from_handle, 
-                                            const MBEntityHandle *to_handles,
-                                            const int num_handles);
-
-      //! Retrieves all entities in the database of given dimension.  
-      /** \param dimension Dimension of entities desired.
-          \param entities Range in which entities of dimension <em>dimension</em> are returned.
-
-          Example: \code
-          int dimension = 2;
-          MBRange entities;
-          get_entities_by_dimension( dimension, entities ); //get 2D MBEntityHandles in the database
-          \endcode */
-    virtual MBErrorCode get_entities_by_dimension( const MBEntityHandle meshset,
-                                                   const int dimension, 
-                                                   MBRange &entities,
-                                                   const bool recursive = false) const;
-
-    virtual MBErrorCode get_entities_by_dimension( const MBEntityHandle meshset,
-                                                   const int dimension, 
-                                                   std::vector<MBEntityHandle> &entities,
-                                                   const bool recursive = false) const;
-
-      //! Retrieves all entities in the data base of given type.  
-      /** \param type MBEntityType of entities desired (ie, MeshHex, MeshEdge, MeshTri, etc )
-          \param entities Range in which entities of MBEntityType <em>type</em> are returned.
-
-          Example: \code
-          MBEntityType type = MeshTet;
-          MBRange entities;
-          get_entities_by_dimension( type, entities ); //get MeshTet type MBEntityHandles in the database
-          \endcode */
-    virtual MBErrorCode get_entities_by_type( const MBEntityHandle meshset,
-                                              const MBEntityType type, 
-                                              MBRange &entities,
-                                              const bool recursive = false) const;
-
-    virtual MBErrorCode get_entities_by_type( const MBEntityHandle meshset,
-                                              const MBEntityType type, 
-                                              std::vector<MBEntityHandle> &entities,
-                                              const bool recursive = false) const;
-
-    virtual MBErrorCode get_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                      const MBEntityType type,
-                                                      const MBTag *tag_handles,
-                                                      const void* const* values,
-                                                      const int num_tags,
-                                                      MBRange &entities,
-                                                      const int condition = MBInterface::INTERSECT,
-                                                      const bool recursive = false) const;
-
-      //! Retrieves all entities in the data base
-      /** \param entities Range in which entities of MBEntityType <em>type</em> are returned.
-
-      Example: \code
-      MBRange entities;
-      get_entities( entities ); //get MeshTet type MBEntityHandles in the database
-      \endcode */
-    virtual MBErrorCode get_entities_by_handle(const MBEntityHandle meshset,
-                                      MBRange &entities,
-                                      const bool recursive = false) const;
-
-      //! Retrieves all entities in the data base
-      /** \param entities Range in which entities of MBEntityType <em>type</em> are returned.
-
-      Example: \code
-      MBRange entities;
-      get_entities( entities ); //get MeshTet type MBEntityHandles in the database
-      \endcode */
-    virtual MBErrorCode get_entities_by_handle(const MBEntityHandle meshset,
-                                      std::vector<MBEntityHandle> &entities,
-                                      const bool recursive = false) const;
-
-      //! Retrieves all entities in the database of given dimension.  
-      /** \param dimension Dimension of entities desired.
-          \param entities Range in which entities of dimension <em>dimension</em> are returned.
-
-          Example: \code
-          int dimension = 2;
-          MBRange entities;
-          get_entities_by_dimension( dimension, entities ); //get 2D MBEntityHandles in the database
-          \endcode */
-    virtual MBErrorCode get_number_entities_by_dimension(const MBEntityHandle meshset,
-                                                          const int dimension, 
-                                                          int &num_entities,
-                                                          const bool recursive = false) const;
-
-      //! Retrieves all entities in the data base of given type.  
-      /** \param type MBEntityType of entities desired (ie, MeshHex, MeshEdge, MeshTri, etc )
-          \param entities Range in which entities of MBEntityType <em>type</em> are returned.
-
-          Example: \code
-          MBEntityType type = MeshTet;
-          MBRange entities;
-          get_entities_by_dimension( type, entities ); //get MeshTet type MBEntityHandles in the database
-          \endcode */
-    virtual MBErrorCode get_number_entities_by_type(const MBEntityHandle meshset,
-                                                     const MBEntityType type, 
-                                                     int &num_entities,
-                                                     const bool recursive = false) const;
-
-    virtual MBErrorCode get_number_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                             const MBEntityType type,
-                                                             const MBTag *tag_handles,
-                                                             const void* const* values,
-                                                             const int num_tags,
-                                                             int &num_entities,
-                                                             const bool recursive = false) const;
-
-      //! Retrieves all entities in the data base
-      /** \param entities Range in which entities of MBEntityType <em>type</em> are returned.
-
-      Example: \code
-      MBRange entities;
-      get_entities( entities ); //get MeshTet type MBEntityHandles in the database
-      \endcode */
-    virtual MBErrorCode get_number_entities_by_handle(const MBEntityHandle meshset,
-                                             int &num_entities,
-                                             const bool recursive = false) const;
-
-      //! Creates an element based on the type and connectivity. 
-      /** If connectivity vector is not correct for MBEntityType <em>type</em> (ie, a vector with 
-          3 vertices is passed in to make an MeshQuad), the function returns MB_FAILURE. 
-          \param type Type of element to create. (MeshTet, MeshTri, MeshKnife, etc.) 
-          \param connectivity Vector containing connectivity of element to create.
-          \param handle MBEntityHandle representing the newly created element in the database.
-
-          Example: \code
-          MBEntityType type = MeshQuad;
-          std::vector<MBEntityHandle> connectivity(4);
-          quad_conn[0] = vertex0;
-          quad_conn[1] = vertex1;
-          quad_conn[2] = vertex2;
-          quad_conn[3] = vertex3;
-          MBEntityHandle element_handle;
-          create_element( type, connectivity, element_handle ); \endcode */
-    virtual MBErrorCode create_element(const MBEntityType type, 
-                                        const MBEntityHandle *connectivity,
-                                        const int num_nodes, 
-                                        MBEntityHandle &element_handle);
-
-      //! Creates a vertex based on coordinates.  
-      /**
-         \param coordinates Array that has 3 doubles in it.
-         \param entity_handle MBEntityHandle representing the newly created vertex in the database.
-
-         Example: \code
-         double *coordinates = double[3];
-         coordinates[0] = 1.034;
-         coordinates[1] = 23.23; 
-         coordinates[2] = -0.432; 
-         MBEntityHandle entity_handle = 0;
-         create_vertex( coordinates, entity_handle ); \endcode */
-    virtual MBErrorCode create_vertex(const double coordinates[3], 
-                                       MBEntityHandle &entity_handle );
-
-    //! Create a set of vertices with the specified coordinates
-    /**
-       \param coordinates Array that has 3*n doubles in it.
-       \param nverts Number of vertices to create
-       \param entity_handles MBRange passed back with new vertex handles
-    */
-  virtual MBErrorCode create_vertices(const double *coordinates, 
-                                      const int nverts,
-                                      MBRange &entity_handles );
-
-      //! merges two entities
-    virtual MBErrorCode merge_entities(MBEntityHandle entity_to_keep, 
-                                        MBEntityHandle entity_to_remove,
-                                        bool auto_merge,
-                                        bool delete_removed_entity);
-
-      //! Removes entities in a vector from the data base.  
-      /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
-          which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity<\em> are 
-          removed as part of this function.
-          \param entities 1d vector of entities to delete
-          \param num_entities Number of entities in 1d vector
-      */ 
-    virtual MBErrorCode delete_entities(const MBEntityHandle *entities,
-                                         const int num_entities);
-
-      //! Removes entities in a range from the data base.  
-      /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
-          which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity<\em> are 
-          removed as part of this function.
-          \param entities Range of entities to delete
-      */ 
-    virtual MBErrorCode delete_entities(const MBRange &entities);
-
-  virtual MBErrorCode list_entities(const MBRange &entities) const;
-  
-  virtual MBErrorCode list_entities(const MBEntityHandle *entities,
-                                    const int num_entities) const;
-
-  virtual MBErrorCode list_entity(const MBEntityHandle entity) const;
-
-      //! function object for recieving events from MB of higher order nodes
-      //! added to entities
-    class HONodeAddedRemoved
-    {
-    public:
-      HONodeAddedRemoved(){}
-      virtual ~HONodeAddedRemoved(){}
-        //! node_added called when a node was added to an element's connectivity array
-        //! note: connectivity array of element may be incomplete (corner nodes will exist always)
-      virtual void node_added(MBEntityHandle node, MBEntityHandle element);
-      virtual void node_removed(MBEntityHandle node);
-    };
-  
-    virtual MBErrorCode convert_entities(const MBEntityHandle meshset, 
-                                          const bool mid_side,
-                                          const bool mid_face, 
-                                          const bool mid_volume, 
-                                          MBInterface::HONodeAddedRemoved* function_object = 0);
-
-      //! function to get the side number given two elements; returns
-      //! MB_FAILURE if child not related to parent; does *not* create adjacencies
-      //! between parent and child
-    virtual MBErrorCode side_number(const MBEntityHandle parent,
-                                     const MBEntityHandle child,
-                                     int &side_number,
-                                     int &sense,
-                                     int &offset) const;
-
-      //! given an entity and the connectivity and type of one of its subfacets, find the
-      //! high order node on that subfacet, if any
-    virtual MBErrorCode high_order_node(const MBEntityHandle parent_handle,
-                                         const MBEntityHandle *subfacet_conn,
-                                         const MBEntityType subfacet_type,
-                                         MBEntityHandle &high_order_node) const;
-
-      //! given an entity and a target dimension & side number, get that entity
-    virtual MBErrorCode side_element(const MBEntityHandle source_entity,
-                                      const int dim, 
-                                      const int side_number,
-                                      MBEntityHandle &target_entity) const;
-
-      //-------------------------Tag Stuff-------------------------------------//
-
-  //! Creates a dense tag with a name.
-  /** Use to store data that is larger than 8 bits, on many 
-      MBEntityHandles across all entity types.  Allows for storage of data of 
-      <em>tag_size</em> bytes on any arbitrary entity.  
-      \param tag_name String name of MBTag.
-      \param tag_size Size of data to store on tag, in bytes.  For storing data 
-      1 byte or less in size, use tag_create_bits(...)
-      \param tag_handle MBTag to be created.
-      \param default_value Default value tag data is set to when initially created.
-
-      Example: \code
-      std::string tag_name = "my_meshset_tag";
-      int tag_size = sizeof(double); 
-      MBTag tag_handle = 0;
-      double value = 100.5;
-      const void *default_value = &value;
-      tag_create_dense( tag_name, 
-              tag_size, default_value ); //Create a dense tag. 
-                                         //The tag will hold data the size of a 
-                                         //double and that data will initially be 
-                                         //set to 100.5  \endcode */
-  virtual MBErrorCode tag_create(const char *tag_name,
-                                  const int tag_size, 
-                                  const MBTagType type,
-                                  MBTag &tag_handle, 
-                                  const void *default_value);
-
-    /** \brief Define a new tag.
-     *
-     * Define a new tag for storing application-defined data on MB entities.  
-     *
-     * \param name    The name of the tag.
-     * \param size    The size of the tag data in bytes.
-     * \param storage The tag storage type.
-     * \param data    The tag data type.
-     * \param handle  The tag handle (output)
-     * \param def_val Optional default value for tag.
-     * \param use_existing  If true, and a tag with the same name and
-     *                same description exists, successfully return the
-     *                handle of the tag.
-     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
-     *         - MB_FAILURE if inconsistant arguments
-     *         - MB_SUCCESS otherwise.
-     */
-  virtual MBErrorCode tag_create( const      char* name,
-                                  const        int size,
-                                  const  MBTagType storage,
-                                  const MBDataType data,
-                                            MBTag& handle,
-                                  const      void* def_val,
-                                              bool use_existing);
-
-    /**\brief Define a new tag that can store variable-length data.
-     *
-     * Define a new tag for storing application-defined data on MB entities.  
-     *
-     * \param name          The name of the tag.
-     * \param storage       The tag storage type (MB_TAG_BIT not supported).
-     * \param data_type     The tag data type.
-     * \param handle_out    The tag handle (output)
-     * \param default_value Optional default value for tag.
-     * \param default_val_len Length of default value.  Required if
-     *                      default value is specified.
-     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
-     *         - MB_FAILURE if inconsistant arguments
-     *         - MB_SUCCESS otherwise.
-     */
-  virtual MBErrorCode tag_create_variable_length( const char* name,
-                                                  MBTagType   storage,
-                                                  MBDataType  data_type,
-                                                  MBTag&      handle_out,
-                                                  const void* default_value = 0,
-                                                  int         default_val_len = 0 
-                                                 );
-
-  //! Gets the tag name string of the tag_handle.
-  /** \param tag_handle MBTag you want the name of.  
-      \param tag_name Name string of <em>tag_handle</em>. 
-
-      Example: \code
-      MBTag tag_handle = 0;
-      std::string tag_name = "my_special_tag";
-      tag_get_name( tag_handle, tag_name );  //gets the MBTag from the tag's name string
-      \endcode */
-  virtual MBErrorCode  tag_get_name(const MBTag tag_handle, 
-                                     std::string& tag_name) const;
-
-  //! Gets tag handle from the tag's string name. 
-  /**
-      \param tag_name Name string of desired tag. 
-      \param tag_handle MBTag to be retrieved.
-
-      Example: \code
-      MBTag tag_handle = 0;
-      std::string tag_name = "quad_data_flag";
-      tag_get_handle( tag_name, tag_handle ); \endcode */ 
-  virtual MBErrorCode  tag_get_handle(const char *tag_name, 
-                                       MBTag &tag_handle) const;
-
-  //! Get handles for all tags defined on this entity
-  virtual MBErrorCode tag_get_tags_on_entity(const MBEntityHandle entity,
-                                             std::vector<MBTag> &tag_handles) const;
-
-  //! get size of tag in bytes
-  virtual MBErrorCode tag_get_size(const MBTag, int &tag_size) const;
-
-    //! Get the default value of the specified tag
-  virtual MBErrorCode tag_get_default_value(const MBTag tag, void *def_val) const;
-  virtual MBErrorCode tag_get_default_value( MBTag tag, const void*& def_val, int& size) const;
-
-  //! get type of tag (sparse, dense, etc.; 0 = dense, 1 = sparse, 2 = bit, 3 = mesh)
-  virtual MBErrorCode tag_get_type(const MBTag, MBTagType &tag_type) const;
-
-   /** \brief Get data type of tag.
-    *
-    * Get the type of the tag data.  The tag is data is assumed to
-    * be a vector of this type.  If the tag data vetcor contains 
-    * more than one value, then the tag size must be a multiple of
-    * the size of this type.
-    * \param tag  The tag 
-    * \param type The type of the specified tag (output).
-    */
-  virtual MBErrorCode tag_get_data_type(const MBTag tag, MBDataType& type) const;
-
-  //! get handles for all tags defined
-  virtual MBErrorCode tag_get_tags(std::vector<MBTag> &tag_handles) const;
-
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                     const MBEntityHandle* entity_handles, 
-                                     const int num_entities, 
-                                     void *tag_data) const;
-
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                     const MBRange& entity_handles, 
-                                     void *tag_data) const;
-
-  //! Sets the data of a given EntityHandle and MBTag.  
-  /** If the <em>tag_handle</em> and the entity type of <em>entity_handle</em> are not 
-      compatible, data of <em>entity_handle</em> never existed and MB_FAILURE 
-      is returned. 
-      \param tag_handle MBTag indicating what data is to be set.
-      \param entity_handle MBEntityHandle on which to set tag's data. 
-      \param tag_data Data to set the <em>entity_handle</em>'s tag data to.
-
-      Example: \code
-      int tag_data = 1004;
-      tag_set_data( tag_handle, entity_handle, &tag_data ); \endcode */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                     const MBEntityHandle* entity_handles, 
-                                     const int num_entities,
-                                     const void *tag_data );
-  
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                     const MBRange& entity_handles,
-                                     const void *tag_data );
-
-
-    /**\brief Get pointers to tag data
-     *
-     * For a tag, get the values for a list of passed entity handles.
-     *\param tag_handle     The tag
-     *\param entity_handles An array of entity handles for which to retreive tag values.
-     *\param num_entities   The length of the 'entity_handles' array.
-     *\param tag_data       An array of 'const void*'.  Array must be at least
-     *                      'num_entitities' long.  Array is populated (output)
-     *                      with pointers to the internal storage for the
-     *                      tag value corresponding to each entity handle.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities, 
-                                    const void** tag_data,
-                                    int* tag_sizes = 0 ) const;
-
-    /**\brief Get pointers to tag data
-     *
-     * For a tag, get the values for a list of passed entity handles.
-     *\param tag_handle     The tag
-     *\param entity_handles The entity handles for which to retreive tag values.
-     *\param tag_data       An array of 'const void*'.  Array is populated (output)
-     *                      with pointers to the internal storage for the
-     *                      tag value corresponding to each entity handle.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles, 
-                                    const void** tag_data,
-                                    int* tag_sizes = 0 ) const;
-
-    /**\brief Set tag data given an array of pointers to tag values.
-     *
-     * For a tag, set the values for a list of passed entity handles.
-     *\param tag_handle     The tag
-     *\param entity_handles An array of entity handles for which to set tag values.
-     *\param num_entities   The length of the 'entity_handles' array.
-     *\param tag_data       An array of 'const void*'.  Array must be at least
-     *                      'num_entitities' long.  Array is expected to
-     *                      contain pointers to tag values for the corresponding
-     *                      MBEntityHandle in 'entity_handles'.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities,
-                                    void const* const* tag_data ,
-                                    const int* tag_sizes = 0 );
-  
-    /**\brief Set tag data given an array of pointers to tag values.
-     *
-     * For a tag, set the values for a list of passed entity handles.
-     *\param tag_handle     The tag
-     *\param entity_handles The entity handles for which to set tag values.
-     *\param tag_data       An array of 'const void*'.  Array is expected to
-     *                      contain pointers to tag values for the corresponding
-     *                      MBEntityHandle in 'entity_handles'.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles,
-                                    void const* const* tag_data,
-                                    const int* tag_sizes = 0 );
-
-  //! Delete the data of a vector of entity handles and sparse tag
-  /** Delete the data of a tag on a vector of entity handles.  Only sparse tag data are deleted with this
-      function; dense tags are deleted by deleting the tag itself using tag_delete.
-      \param tag_handle Handle of the (sparse) tag being deleted from entity
-      \param entity_handles 1d vector of entity handles from which the tag is being deleted
-      \param num_handles Number of entity handles in 1d vector
-  */
-  virtual MBErrorCode  tag_delete_data(const MBTag tag_handle, 
-                                        const MBEntityHandle *entity_handles,
-                                        const int num_handles);
-
-  //! Delete the data of a range of entity handles and sparse tag
-  /** Delete the data of a tag on a range of entity handles.  Only sparse tag data are deleted with this
-      function; dense tags are deleted by deleting the tag itself using tag_delete.
-      \param tag_handle Handle of the (sparse) tag being deleted from entity
-      \param entity_range Range of entities from which the tag is being deleted
-  */
-  virtual MBErrorCode  tag_delete_data(const MBTag tag_handle, 
-                                        const MBRange &entity_range);
-
-  //! Removes the tag from the database and deletes all of its associated data.
-  virtual MBErrorCode  tag_delete(MBTag tag_handle);
-
-  /**a;dlfa;sfsdafasdfl; 
-     a;dlfja;sljfl;sadfasd
-     a;dlkfj;lsajdf */
-
-  //! creates a mesh set
-  virtual MBErrorCode create_meshset(const unsigned int options, 
-                                     MBEntityHandle &ms_handle,
-                                     int start_id = 0);
-
-  //! Empty a vector of mesh set
-  /** Empty a mesh set.
-      \param ms_handles 1d vector of handles of sets being emptied
-      \param num_meshsets Number of entities in 1d vector
-  */
-  virtual MBErrorCode clear_meshset( const MBEntityHandle *ms_handles, 
-                                     const int num_meshsets);
-
-  //! Empty a range of mesh set
-  /** Empty a mesh set.
-      \param ms_handles Range of handles of sets being emptied
-  */
-  virtual MBErrorCode clear_meshset(const MBRange &ms_handles);
-
-  //! get the options of a mesh set
-  virtual MBErrorCode get_meshset_options(const MBEntityHandle ms_handle, 
-                                           unsigned int& options) const;
-
-  //! set the options of a mesh set
-  virtual MBErrorCode set_meshset_options(const MBEntityHandle ms_handle, 
-                                          const unsigned int options);
-
-  //! subtracts meshset2 from meshset1 - modifies meshset1
-  virtual MBErrorCode subtract_meshset(MBEntityHandle meshset1, 
-                                        const MBEntityHandle meshset2);
-
-  //! intersects meshset2 with meshset1 - modifies meshset1
-  virtual MBErrorCode intersect_meshset(MBEntityHandle meshset1, 
-                                         const MBEntityHandle meshset2);
-    
-  //! unites meshset2 with meshset1 - modifies meshset1
-  virtual MBErrorCode unite_meshset(MBEntityHandle meshset1, 
-                                     const MBEntityHandle meshset2);
-
-  //! add entities to meshset
-  virtual MBErrorCode add_entities(MBEntityHandle meshset, 
-                                    const MBRange &entities);
-
-  //! add entities to meshset
-  virtual MBErrorCode add_entities(MBEntityHandle meshset, 
-                                    const MBEntityHandle *entities,
-                                    const int num_entities);
-  
-  //! remove entities from meshset
-  virtual MBErrorCode remove_entities(MBEntityHandle meshset, 
-                                       const MBRange &entities);
-
-  //! remove entities from meshset
-  virtual MBErrorCode remove_entities(MBEntityHandle meshset, 
-                                       const MBEntityHandle *entities,
-                                       const int num_entities);
-
-    //! return true if all entities are contained in set
-  virtual bool contains_entities(MBEntityHandle meshset, 
-                                 const MBEntityHandle *entities,
-                                 int num_entities,
-                                 const int operation_type = MBInterface::INTERSECT);
-
-    //! replace entities
-  virtual MBErrorCode replace_entities(MBEntityHandle meshset, 
-                                       const MBEntityHandle *old_entities,
-                                       const MBEntityHandle *new_entities,
-                                       int num_entities);
-
-  //------MeshSet Parent/Child functions------
-  
-  //! get parent meshsets
-  virtual MBErrorCode get_parent_meshsets(const MBEntityHandle meshset,
-                                           std::vector<MBEntityHandle> &parents, 
-                                           const int num_hops = 1) const;
-
-  //! get parent meshsets
-  virtual MBErrorCode get_parent_meshsets(const MBEntityHandle meshset,
-                                          MBRange &parents, 
-                                          const int num_hops = 1) const;
-
-  //! get child meshsets
-  virtual MBErrorCode get_child_meshsets(const MBEntityHandle meshset, 
-                                          std::vector<MBEntityHandle> &children, 
-                                          const int num_hops = 1) const;
-
-  //! get child meshsets
-  virtual MBErrorCode get_child_meshsets(const MBEntityHandle meshset, 
-                                         MBRange &children, 
-                                          const int num_hops = 1) const;
-
-  //! get contained meshsets
-  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
-                                             std::vector<MBEntityHandle> &contained, 
-                                             const int num_hops = 1) const;
-
-  //! get contained meshsets
-  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
-                                             MBRange &contained, 
-                                             const int num_hops = 1) const;
-
-  //! gets number of parent meshsets
-  virtual MBErrorCode num_parent_meshsets(const MBEntityHandle meshset,  
-                                          int *number,
-                                          const int num_hops = 1) const;
-
-  //! gets number of child meshsets
-  virtual MBErrorCode num_child_meshsets(const MBEntityHandle meshset, 
-                                         int *number, 
-                                         const int num_hops = 1) const;
-
-  //! gets number of contained meshsets
-  virtual MBErrorCode num_contained_meshsets(const MBEntityHandle meshset, 
-                                             int *number, 
-                                             const int num_hops = 1) const;
-
-  //! add a parent meshset
-  virtual MBErrorCode add_parent_meshset(MBEntityHandle meshset, 
-                                          const MBEntityHandle parent_meshset);
-
-  //! add parent meshsets
-  virtual MBErrorCode add_parent_meshsets(MBEntityHandle meshset, 
-                                          const MBEntityHandle* parent_meshsets,
-                                          int num_parent_meshsets);
-
-  //! add a child meshset
-  virtual MBErrorCode add_child_meshset(MBEntityHandle meshset, 
-                                         const MBEntityHandle child_meshset);
-
-  //! add parent meshsets
-  virtual MBErrorCode add_child_meshsets(MBEntityHandle meshset, 
-                                         const MBEntityHandle* child_meshsets,
-                                         int num_child_meshsets);
-
-  //! adds 'parent' to child's parent list and adds 'child' to parent's child list
-  virtual MBErrorCode add_parent_child( MBEntityHandle parent, 
-                                         MBEntityHandle child );
-
-  //! removes 'parent' to child's parent list and removes 'child' to parent's child list
-  virtual MBErrorCode remove_parent_child( MBEntityHandle parent, 
-                                            MBEntityHandle child );
-
-  //! remove parent meshset
-  virtual MBErrorCode remove_parent_meshset(MBEntityHandle meshset, 
-                                             const MBEntityHandle parent_meshset);
-  
-  //! remove child meshset
-  virtual MBErrorCode remove_child_meshset(MBEntityHandle meshset, 
-                                            const MBEntityHandle child_meshset);
-
-  // ************************  error condition information *************** 
-
-    //! return various specific tag handles
-  MBTag material_tag();
-  MBTag neumannBC_tag();
-  MBTag dirichletBC_tag();
-  MBTag globalId_tag();
-  MBTag geom_dimension_tag();
-
-    //! get/set the number of nodes
-    //int total_num_nodes() const;
-    //void total_num_nodes(const int val);
-  
-    //! get/set the number of elements
-    //int total_num_elements() const;
-    //void total_num_elements(const int val);
-
-    //! return a reference to the tag server
-  TagServer* tag_server() {return tagServer;}
-
-    //! return a reference to the sequence manager
-  SequenceManager* sequence_manager() { return sequenceManager; }
-  const SequenceManager* sequence_manager() const { return sequenceManager; }
-
-    /// create structured sequence
-  MBErrorCode create_scd_sequence(const HomCoord &    coord_min,
-                                  const HomCoord &  coord_max,
-                                  MBEntityType  type,
-                                  MBEntityID  start_id_hint,
-                                  MBEntityHandle &  first_handle_out,
-                                  EntitySequence *&  sequence_out );
-
-  MBErrorCode add_vsequence(EntitySequence *    vert_seq,
-                            EntitySequence *  elem_seq,
-                            const HomCoord &  p1,
-                            const HomCoord &  q1,
-                            const HomCoord &  p2,
-                            const HomCoord &  q2,
-                            const HomCoord &  p3,
-                            const HomCoord &  q3,
-                            bool  bb_input = false,
-                            const HomCoord *  bb_min = NULL,
-                            const HomCoord *  bb_max = NULL);
-   
-    //! return the a_entity_factory pointer
-  AEntityFactory *a_entity_factory() { return aEntityFactory; }
-  const AEntityFactory *a_entity_factory() const { return aEntityFactory; }
-  
-    //! return set of registered IO tools
-  MBReaderWriterSet* reader_writer_set() { return readerWriterSet; }
-
-  MBError* get_error_handler() { return mError; }
-
-//-----------------MeshSet Interface Functions------------------//
-
-  void print(const MBEntityHandle handle, const char *prefix,
-             bool first_call = true) const;
-
-  virtual MBErrorCode get_last_error(std::string& info) const;
-
-  virtual std::string get_error_string(const MBErrorCode code) const;
-
-    //! check all adjacencies for consistency
-  MBErrorCode check_adjacencies();
-  
-    //! check some adjacencies for consistency
-  MBErrorCode check_adjacencies(const MBEntityHandle *ents, int num_ents);
-  
-    //! return whether the input handle is valid or not
-  bool is_valid(const MBEntityHandle this_ent) const;
-  
-//-----------------Memory Functions------------------//
-
-
-  /**\brief Calculate amount of memory used to store MOAB data
-   *
-   * This function calculates the amount of memory used to store
-   * MOAB data.  
-   *
-   * There are two possible values for each catagory of memory use.
-   * The exact value and the amortized value.  The exact value is the
-   * amount of memory used to store the data for the specified entities.
-   * The amortized value includes the exact value and an amortized 
-   * estimate of the memory consumed in overhead for storing the values
-   * (indexing structures, access structures, etc.)  
-   *
-   * Note: If ent_array is NULL, the total memory used by MOAB for storing
-   *       data will be returned in the address pointed to by
-   *       total_amortized_storage, if total_amortized_storage is not NULL.
-   *
-   *\param ent_array Array of entities for which to estimate the memory use.
-   *                 If NULL, estimate is done for all entities.
-   *\param num_ents The length of ent_array.  Not used if ent_rray is NULL.
-   *\param total_(amortized_)storage The sum of the memory entity, adjacency, and all tag storage.
-   *\param (amortized_)entity_storage The storage for the entity definitions
-   *                 (connectivity arrays for elements, coordinates for vertices,
-   *                  list storage within sets, etc.)
-   *\param (amortized_)adjacency_storage The storage for adjacency data.
-   *\param tag_array  An array of tags for which to calculate the memory use.
-   *\param num_tags   The lenght of tag_array
-   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
-   *                   for each tag specifying the memory used for storing that
-   *                   tag.  If tag_array is NULL and this value is not, the
-   *                   location at which to store the total memory used for
-   *                   all tags.
-   */
-  void estimated_memory_use( const MBEntityHandle* ent_array = 0,
-                             unsigned long  num_ents = 0,
-                             unsigned long* total_storage = 0,
-                             unsigned long* total_amortized_storage = 0,
-                             unsigned long* entity_storage = 0,
-                             unsigned long* amortized_entity_storage = 0,
-                             unsigned long* adjacency_storage = 0,
-                             unsigned long* amortized_adjacency_storage = 0,
-                             const MBTag*   tag_array = 0,
-                             unsigned       num_tags = 0,
-                             unsigned long* tag_storage = 0,
-                             unsigned long* amortized_tag_storage = 0 );
-
-  /**\brief Calculate amount of memory used to store MOAB data
-   *
-   * This function calculates the amount of memory used to store
-   * MOAB data.  
-   *
-   * There are two possible values for each catagory of memory use.
-   * The exact value and the amortized value.  The exact value is the
-   * amount of memory used to store the data for the specified entities.
-   * The amortized value includes the exact value and an amortized 
-   * estimate of the memory consumed in overhead for storing the values
-   * (indexing structures, access structures, etc.)  
-   *
-   *\param ents      Entities for which to estimate the memory use.
-   *\param total_(amortized_)storage The sum of the memory entity, adjacency, and all tag storage.
-   *\param (amortized_)entity_storage The storage for the entity definitions
-   *                 (connectivity arrays for elements, coordinates for vertices,
-   *                  list storage within sets, etc.)
-   *\param (amortized_)adjacency_storage The storage for adjacency data.
-   *\param tag_array  An array of tags for which to calculate the memory use.
-   *\param num_tags   The lenght of tag_array
-   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
-   *                   for each tag specifying the memory used for storing that
-   *                   tag.  If tag_array is NULL and this value is not, the
-   *                   location at which to store the total memory used for
-   *                   all tags.
-   */
-  void estimated_memory_use( const MBRange& ents,
-                             unsigned long* total_storage = 0,
-                             unsigned long* total_amortized_storage = 0,
-                             unsigned long* entity_storage = 0,
-                             unsigned long* amortized_entity_storage = 0,
-                             unsigned long* adjacency_storage = 0,
-                             unsigned long* amortized_adjacency_storage = 0,
-                             const MBTag*   tag_array = 0,
-                             unsigned       num_tags = 0,
-                             unsigned long* tag_storage = 0,
-                             unsigned long* amortized_tag_storage = 0 );
-                                     
-
-  void print_database() const;
-
-private:
-
-  /**\brief Do not allow copying */
-  MBCore( const MBCore& copy );
-  /**\brief Do not allow copying */
-  MBCore& operator=( const MBCore& copy );
-
-  void estimated_memory_use_internal( const MBRange* ents,
-                            unsigned long* total_storage,
-                            unsigned long* total_amortized_storage,
-                            unsigned long* entity_storage,
-                            unsigned long* amortized_entity_storage,
-                            unsigned long* adjacency_storage,
-                            unsigned long* amortized_adjacency_storage,
-                            const MBTag*   tag_array,
-                            unsigned       num_tags,
-                            unsigned long* tag_storage,
-                            unsigned long* amortized_tag_storage );
-
-    //! database init and de-init routines
-  MBErrorCode initialize();
-  void deinitialize();
-
-    //! return the entity set representing the whole mesh
-  MBEntityHandle get_root_set();
-  
-  
-    //!\brief Clean up after a file reader returns failure.
-    //!
-    //! Delete all entities not contained in initial_entities
-    //! and all tags not contained in initial_tags.
-  void clean_up_failed_read( const MBRange& initial_entities,
-                             std::vector<MBTag> initial_tags );
-  
-    // other interfaces for MB
-  MBWriteUtil* mMBWriteUtil;
-  MBReadUtil* mMBReadUtil;
-
-    //! store the total number of elements defined in this interface
-    //int totalNumElements;
-  
-    //! store the total number of nodes defined in this interface
-    //int totalNumNodes;
-
-    //! the overall geometric dimension of this mesh
-  int geometricDimension;
-
-  MBTag materialTag;
-  MBTag neumannBCTag;
-  MBTag dirichletBCTag;
-  MBTag geomDimensionTag;
-  MBTag globalIdTag;
-
-    //! tag server for this interface
-  TagServer* tagServer;
-
-  SequenceManager *sequenceManager;
-
-  AEntityFactory *aEntityFactory;
-  
-  MBReaderWriterSet* readerWriterSet;
-
-  MBError* mError;
-};
-
-  
-#endif   // MB_IMPL_GENERAL_HPP

Deleted: MOAB/trunk/src/moab/MBEntityHandle.h.in
===================================================================
--- MOAB/trunk/src/moab/MBEntityHandle.h.in	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBEntityHandle.h.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,81 +0,0 @@
-#ifndef MB_ENTITY_HANDLE_H
-#define MB_ENTITY_HANDLE_H
-
-/* MOAB qualified HAVE_INTTYPES_H */
-#undef MOAB_HAVE_INTTYPES_H
-
-/* MOAB qualified HAVE_STDDEF_H */
-#undef MOAB_HAVE_STDDEF_H
-
-/* MOAB qualified HAVE_STDINT_H */
-#undef MOAB_HAVE_STDINT_H
-
-/* MOAB qualified HAVE_STDLIB_H */
-#undef MOAB_HAVE_STDLIB_H
-
-/* MOAB qualified HAVE_SYS_TYPES_H */
-#undef MOAB_HAVE_SYS_TYPES_H
-
-/* Use int32_t for handles */
-#undef MOAB_FORCE_32_BIT_HANDLES
-
-/* Use int64_t for handles */
-#undef MOAB_FORCE_64_BIT_HANDLES
-
-/* System provides ptrdiff_t typedef */
-#undef MOAB_HAVE_PTRDIFF_T
-
-/* System provides size_t typedef */
-#undef MOAB_HAVE_SIZE_T
-
-#ifdef MOAB_HAVE_INTTYPES_H
-# include <inttypes.h>
-#elif defined (MOAB_HAVE_STDINT_H)
-# include <stdint.h>
-#elif defined (_MSC_VER)
-  typedef __int8 int8_t;
-  typedef __int16 int16_t;
-  typedef __int32 int32_t;
-  typedef __int64 int64_t;
-  typedef unsigned __int8 uint8_t;
-  typedef unsigned __int16 uint16_t;
-  typedef unsigned __int32 uint32_t;
-  typedef unsigned __int64 uint64_t;
-#endif
-
-#ifdef MOAB_HAVE_STDDEF_H
-# include <stddef.h>
-#elif defined (MOAB_HAVE_STDLIB_H)
-# include <stdlib.h>
-#elif defined (HAVE_SYS_TYPES_H)
-# include <sys/types.h>
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef MOAB_FORCE_64_BIT_HANDLES
-  typedef uint64_t MBEntityHandle;
-  typedef  int64_t MBEntityID;
-#elif defined (MOAB_FORCE_32_BIT_HANDLES)
-  typedef uint32_t MBEntityHandle;
-  typedef  int32_t MBEntityID;
-#else
-# ifdef MOAB_HAVE_SIZE_T
-    typedef size_t MBEntityHandle;
-# else
-    typedef unsigned long MBEntityHandle;
-# endif
-# ifdef MOAB_HAVE_PTRDIFF_T
-    typedef ptrdiff_t MBEntityID;
-# else
-    typedef long MBEntityID;
-# endif
-#endif 
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif

Deleted: MOAB/trunk/src/moab/MBEntityType.h
===================================================================
--- MOAB/trunk/src/moab/MBEntityType.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBEntityType.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,80 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifndef MB_ENTITY_TYPE_HPP
-#define MB_ENTITY_TYPE_HPP
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! Entity types defined in MOAB and MBCN
- *  The ordering here must ensure that all element types are 
- *  grouped together and all elements of similar dimension are
- *  grouped together.
- */
-typedef enum 
-{
-  MBVERTEX = 0, /**< Mesh Vertex AKA node */
-  MBEDGE,       /**< Mesh Edge */
-  MBTRI,        /**< Triangular element (including shells) */
-  MBQUAD,       /**< Quadrilateral element (including shells) */
-  MBPOLYGON,    /**< Polygon */
-  MBTET,        /**< Tetrahedral element */
-  MBPYRAMID,    /**< Pyramid element (where are the face ids for this defined?) */
-  MBPRISM,      /**< Wedge element (Exodus has one, Cubit doesn't. Does Mesh need it?) */
-  MBKNIFE,      /**< Knife element */
-  MBHEX,        /**< Hexahedral element */
-  MBPOLYHEDRON, /**< Polyhedron */
-  MBENTITYSET,    /**< MeshSet */
-  MBMAXTYPE  /**< Just a place keeper - must be the # of entities, for array */
-    /**< dimensioning purposes  */
-} MBEntityType;
-
-#ifdef __cplusplus
-} /* extern "C" */
-
-
-/** prefix increment operator for MBEntityType */
-inline MBEntityType & operator++(MBEntityType &type)
-{
-  return type = static_cast<MBEntityType>(type+1);
-}
-
-/** postfix increment operator for MBEntityType */
-inline MBEntityType operator++(MBEntityType &type, int)
-{
-  MBEntityType oldval = type;
-  ++type;
-  return oldval;
-}
-
-/** prefix increment operator for MBEntityType */
-inline MBEntityType & operator--(MBEntityType &type)
-{
-  return type = static_cast<MBEntityType>(type-1);
-}
-
-/** postfix increment operator for MBEntityType */
-inline MBEntityType operator--(MBEntityType &type, int)
-{
-  MBEntityType oldval = type;
-  --type;
-  return oldval;
-}
-
-#endif
-
-#endif

Deleted: MOAB/trunk/src/moab/MBError.hpp
===================================================================
--- MOAB/trunk/src/moab/MBError.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBError.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,105 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-/*  
- *
- *  File:      MBError.hpp
- *
- *  Purpose:   To keep track of detail information about errors that occur
- *             in MB.
- *
- *  Date:      9-26-2002
- *
- *  Author:    Clinton Stimpson
- *
- */
-
-
-
-#ifndef MB_ERROR_HPP
-#define MB_ERROR_HPP
-
-#ifndef IS_BUILDING_MB
-#error "MBError.hpp isn't supposed to be included into an application"
-#endif
-
-#include <string>
-#include <stdarg.h>
-#include <stdio.h>
-
-#include "MBTypes.h"
-
-#ifdef WIN32
-#define VSNPRINTF _vsnprintf
-#else
-#define VSNPRINTF vsnprintf
-#endif
-
-class MBError
-{
-  //! string to hold the last error that occurred in MB
-  std::string mLastError;
-
-public:
-
-  MBError() {}
-  ~MBError(){}
-
-  MBErrorCode set_last_error(const std::string& error) 
-  { 
-    mLastError = error; 
-    return MB_SUCCESS; 
-  }
-
-  inline MBErrorCode set_last_error(const char* fmt, ...)
-#ifdef __GNUC__
-__attribute__((format(printf,2,3)))
-#endif
-  ;
-  
-  MBErrorCode set_last_error( const char* fmt, va_list args )
-  {
-    char text[1024];
-    VSNPRINTF( text, sizeof(text), fmt, args );
-    mLastError = text;
-    return MB_SUCCESS;
-  }
-
-  MBErrorCode get_last_error(std::string& error) const
-  { 
-    error = mLastError; 
-    return MB_SUCCESS;
-  }
-
-};
-
-inline MBErrorCode MBError::set_last_error(const char* fmt, ...)
-{
-  MBErrorCode result = MB_FAILURE;
-  if (fmt)
-  {
-    va_list args;
-    va_start( args, fmt );
-    result = set_last_error( fmt, args );
-    va_end( args );
-  }
-  return result;
-}
-
-
-#endif
-
-

Deleted: MOAB/trunk/src/moab/MBForward.hpp
===================================================================
--- MOAB/trunk/src/moab/MBForward.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBForward.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,28 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifndef MB_FORWARD_HPP
-#define MB_FORWARD_HPP
-
-#include "MBTypes.h"
-#include <vector>
-
-class MBInterface;
-class MBRange;
-class MBProcConfig;
-
-typedef std::vector<MBEntityHandle> MBHandleVec;
-
-#endif

Deleted: MOAB/trunk/src/moab/MBGeomUtil.hpp
===================================================================
--- MOAB/trunk/src/moab/MBGeomUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBGeomUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,295 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBGeometry.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-27
- */
-
-#ifndef MB_GEOM_UTIL_HPP
-#define MB_GEOM_UTIL_HPP
-
-#include "MBCartVect.hpp"
-#include <cmath>
-
-namespace MBGeomUtil {
-
-/** Given a line segment and an axis-aligned box, 
- *  return the sub-segment of the line segment that 
- *  itersects the box.
- *  
- *  Can be used to intersect ray with box by passing seg_end
- *  as HUGE_VAL or std::numeric_limits<double>::maximum().
- *
- *\param box_min   Minimum corner of axis-aligned box
- *\param box_max   Maximum corner of axis-aligned box
- *\param seg_pt    A point in the line containing the segement
- *\param seg_unit_dir A unit vector in the direction of the line 
- *                 containing the semgent.
- *\param seg_start The distance from seg_pt in the direction of
- *                 seg_unit_dir at which the segment begins.
- *                 As input, the start of the original segment, as output, the
- *                 start of the sub-segment intersecting the box.
- *                 Note:  seg_start must be less than seg_end
- *\param seg_end   The distance from seg_pt in the direction of 
- *                 seg_unit_dir at which the segment ends.
- *                 As input, the end of the original segment, as output, the
- *                 end of the sub-segment intersecting the box.
- *                 Note:  seg_start must be less than seg_end
- *\return true if line semgent intersects box, false otherwise.
- */
-bool segment_box_intersect( MBCartVect box_min,
-                            MBCartVect box_max,
-                            const MBCartVect& seg_pt,
-                            const MBCartVect& seg_unit_dir,
-                            double& seg_start, double& seg_end );
-
-/**\brief Test for intersection between a ray and a triangle.
- *\param ray_point  The start point of the ray.
- *\param ray_unit_direciton  The direction of the ray. Must be a unit vector.
- *\param tolerance  Absolute distance tolerance for point equality
- *\param t_out Output: The distance along the ray from ray_point in the
- *                  direction of ray_unit_direction at which the ray
- *                  itersected the triangle.
- *\param ray_length Optional:  If non-null, a pointer a maximum length
- *                  for the ray, converting this function to a segment-tri-
- *                  intersect test.
- *\return true if intersection, false otherwise.
- */
-bool ray_tri_intersect( const MBCartVect vertices[3],
-                        const MBCartVect& ray_point,
-                        const MBCartVect& ray_unit_direction,
-                        double tolerance,
-                        double& t_out,
-                        const double* ray_length = 0 );
-
-
-    //! Find range of overlap between ray and axis-aligned box.
-    //!
-    //!\param box_min   Box corner with minimum coordinate values
-    //!\param box_max   Box corner with minimum coordinate values
-    //!\param ray_pt    Coordinates of start point of ray
-    //!\param ray_dir   Directionion vector for ray such that
-    //!                 the ray is defined by r(t) = ray_point + t * ray_vect
-    //!                 for t > 0.
-    //!\param t_enter   Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray entered the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\param t_exit    Output: if return value is true, this value
-    //!                 is the parameter location along the ray at which
-    //!                 the ray exited the leaf.  If return value is false,
-    //!                 then this value is undefined.
-    //!\return true if ray intersects leaf, false otherwise.
-bool ray_box_intersect( const MBCartVect& box_min,
-                        const MBCartVect& box_max,
-                        const MBCartVect& ray_pt,
-                        const MBCartVect& ray_dir,
-                        double& t_enter, double& t_exit );
-
-/**\brief Test if plane intersects axis-aligned box
- *
- * Test for intersection between an unbounded plane and
- * an axis-aligned box.
- *\param plane_normal Vector in plane normal direction (need *not*
- *                    be a unit vector).  The N in 
- *                    the plane equation: N . X + D = 0
- *\param plane_coeff  The scalar 'D' term in the plane equation:
- *                    N . X + D = 0
- *\param box_min_corner The smallest coordinates of the box along each
- *                    axis.  The corner of the box for which all three
- *                    coordinate values are smaller than those of any
- *                    other corner.  The X, Y, Z values for the planes
- *                    normal to those axes and bounding the box on the
- *                    -X, -Y, and -Z sides respectively.
- *\param box_max_corner The largest coordinates of the box along each
- *                    axis.  The corner of the box for which all three
- *                    coordinate values are larger than those of any
- *                    other corner.  The X, Y, Z values for the planes
- *                    normal to those axes and bounding the box on the
- *                    +X, +Y, and +Z sides respectively.
- *\return true if overlap, false otherwise.
- */
-bool box_plane_overlap( const MBCartVect& plane_normal, 
-                        double            plane_coeff,
-                        MBCartVect        box_min_corner, 
-                        MBCartVect        box_max_corner );
-
-/**\brief Test if triangle intersects axis-aligned box
- *
- * Test if a triangle intersects an axis-aligned box.
- *\param triangle_corners  The corners of the triangle.
- *\param box_min_corner The smallest coordinates of the box along each
- *                    axis.  The corner of the box for which all three
- *                    coordinate values are smaller than those of any
- *                    other corner.  The X, Y, Z values for the planes
- *                    normal to those axes and bounding the box on the
- *                    -X, -Y, and -Z sides respectively.
- *\param box_max_corner The largest coordinates of the box along each
- *                    axis.  The corner of the box for which all three
- *                    coordinate values are larger than those of any
- *                    other corner.  The X, Y, Z values for the planes
- *                    normal to those axes and bounding the box on the
- *                    +X, +Y, and +Z sides respectively.
- *\param tolerance    The tolerance used in the intersection test.  The box
- *                    size is increased by this amount before the intersection
- *                    test.
- *\return true if overlap, false otherwise.
- */
-bool box_tri_overlap( const MBCartVect  triangle_corners[3],
-                      const MBCartVect& box_min_corner,
-                      const MBCartVect& box_max_corner,
-                      double            tolerance );
-
-/**\brief Test if triangle intersects axis-aligned box
- *
- * Test if a triangle intersects an axis-aligned box.
- *\param triangle_corners  The corners of the triangle.
- *\param box_center   The center of the box.
- *\param box_hanf_dims The distance along each axis, respectively, from the
- *                    box_center to the boundary of the box.
- *\return true if overlap, false otherwise.
- */
-bool box_tri_overlap( const MBCartVect  triangle_corners[3],
-                      const MBCartVect& box_center,
-                      const MBCartVect& box_half_dims );
-
-bool box_point_overlap( const MBCartVect& box_min_corner,
-                        const MBCartVect& box_max_corner,
-                        const MBCartVect& point,
-                        double tolerance );
-
-/**\brief Test if the specified element intersects an axis-aligned box.
- *
- * Test if element intersects axis-aligned box.  Use element-specific
- * optimization if available, otherwise call box_general_elem_overlap.
- *
- *\param elem_corners The coordinates of the element vertices
- *\param elem_type    The toplogy of the element.
- *\param box_center   The center of the axis-aligned box
- *\param box_half_dims Half of the width of the box in each axial
- *                     direction.
- */
-bool box_elem_overlap( const MBCartVect *elem_corners,
-                       MBEntityType elem_type,
-                       const MBCartVect& box_center,
-                       const MBCartVect& box_half_dims ); 
-
-/**\brief Test if the specified element intersects an axis-aligned box.
- *
- * Uses MBCN and separating axis theorem for general algorithm that
- * works for all fixed-size elements (not poly*).
- *
- *\param elem_corners The coordinates of the element vertices
- *\param elem_type    The toplogy of the element.
- *\param box_center   The center of the axis-aligned box
- *\param box_half_dims Half of the width of the box in each axial
- *                     direction.
- */
-bool box_linear_elem_overlap( const MBCartVect *elem_corners,
-                              MBEntityType elem_type,
-                              const MBCartVect& box_center,
-                              const MBCartVect& box_half_dims ); 
-
-/**\brief Test if the specified element intersects an axis-aligned box.
- *
- * Uses MBCN and separating axis theorem for general algorithm that
- * works for all fixed-size elements (not poly*).  Box and element
- * vertices must be translated such that box center is at origin.
- *
- *\param elem_corners The coordinates of the element vertices, in 
- *                    local coordinate system of box.
- *\param elem_type    The toplogy of the element.
- *\param box_half_dims Half of the width of the box in each axial
- *                     direction.
- */
-bool box_linear_elem_overlap( const MBCartVect *elem_corners,
-                              MBEntityType elem_type,
-                              const MBCartVect& box_half_dims ); 
-
-void closest_location_on_box( const MBCartVect& box_min_corner,
-                              const MBCartVect& box_max_corner,
-                              const MBCartVect& point,
-                              MBCartVect& closest );
-
-/**\brief find closest location on triangle
- *
- * Find closest location on linear triangle.
- *\param location  Input position to evaluate from
- *\param vertices  Array of three corner vertex coordinates.
- *\param closest_out Result position 
- */
-void closest_location_on_tri( const MBCartVect& location,
-                              const MBCartVect* vertices,
-                              MBCartVect& closest_out );
-
-/**\brief find closest location on polygon
- *
- * Find closest location on polygon
- *\param location  Input position to evaluate from
- *\param vertices  Array of corner vertex coordinates.
- *\param num_vertices Length of 'vertices' array.
- *\param closest_out Result position 
- */
-void closest_location_on_polygon( const MBCartVect& location,
-                                  const MBCartVect* vertices,
-                                  int num_vertices,
-                                  MBCartVect& closest_out );
-
-/**\brief find closest topological location on triangle
- *
- * Find closest location on linear triangle.
- *\param location  Input position to evaluate from
- *\param vertices  Array of three corner vertex coordinates.
- *\param tolerance Tolerance to use when comparing to corners and edges
- *\param closest_out Result position 
- *\param closest_topo Closest topological entity
- *                     0-2 : vertex index
- *                     3-5 : edge beginning at closest_topo - 3
- *                       6 : triangle interior
- */
-void closest_location_on_tri( const MBCartVect& location,
-                              const MBCartVect* vertices,
-                              double tolerance,
-                              MBCartVect& closest_out,
-                              int& closest_topo );
-
-// Finds whether or not a box defined by the center and the half
-// width intersects a trilinear hex defined by its eight vertices.
-bool box_hex_overlap( const MBCartVect hexv[8],
-                      const MBCartVect& box_center,
-                      const MBCartVect& box_dims);
-
-// Finds whether or not a box defined by the center and the half
-// width intersects a linear tetrahedron defined by its four vertices.
-bool box_tet_overlap( const MBCartVect tet_corners[4],
-                      const MBCartVect& box_center,
-                      const MBCartVect& box_dims);
-
-//
-// point_in_trilinear_hex
-// Tests if a point in xyz space is within a hex element defined with
-// its eight vertex points forming a trilinear basis function.  Computes
-// the natural coordinates with respect to the hex of the xyz point 
-// and checks if each are between +/-1.  If anyone is outside the range
-// the function returns false, otherwise it returns true.
-//
-bool point_in_trilinear_hex(const MBCartVect *hex, 
-                            const MBCartVect& xyz,
-                            double etol);
-
-} // namespace MBGeoemtry
-
-#endif

Deleted: MOAB/trunk/src/moab/MBInterface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBInterface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1798 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBInterface
- * \brief Main interface class to MOAB
- * \author Tim Tautges, Karl Merkley, Ray Meyers, Corey Ernst, Clinton Stimpson,
- * \author Hong-Jun Kim, Jason Kraftcheck
- * \version 1.00
- * \date April, 2004
- */
-#ifndef MB_INTERFACE_HPP
-#define MB_INTERFACE_HPP
-
-#define MOAB_API_VERSION 1.01
-#define MOAB_API_VERSION_STRING "1.01"
-
-#include "MBForward.hpp"
-
-// include files
-#include <string>
-#include <functional>
-
-
-//! component architecture definitions
-#ifdef XPCOM_MB
-
-#ifndef __gen_nsISupports_h__
-#include "nsISupports.h"
-#endif
-
-#ifndef NS_NO_VTABLE
-#define NS_NO_VTABLE
-#endif
-
-#define MBINTERFACE_IID_STR "f728830e-1dd1-11b2-9598-fb9f414f2465"
-
-{0xf728830e, 0x1dd1, 0x11b2, \
-  { 0x95, 0x98, 0xfb, 0x9f, 0x4
-#define MBINTERFACE_IID \1, 0x4f, 0x24, 0x65 }}
-
-#endif
-
-
-#include "MBUnknownInterface.hpp"
-#define MB_INTERFACE_VERSION "2.0.0"
-static const MBuuid IDD_MBCore = MBuuid( 0x8956e0a, 0xc300, 0x4005,
-                                         0xbd, 0xf6, 0xc3, 0x4e, 0xf7, 0x1f, 0x5a, 0x52 );
-
-
-#if defined(XPCOM_MB)
-class NS_NO_VTABLE MBInterface : public nsISupports {
-#else
-class MB_DLL_EXPORT MBInterface : public MBUnknownInterface {
-#endif
-
-public:
-
-#ifdef XPCOM_MB
-  NS_DEFINE_STATIC_IID_ACCESSOR(MBINTERFACE_IID)
-#endif
-
-      //! \name Interface-level functions
-
-      //@{
-
-      //! constructor
-  MBInterface() {}
-
-    //! destructor
-  virtual ~MBInterface() {}
-
-    //! return the entity set representing the whole mesh
-  virtual MBEntityHandle get_root_set()=0;
-  
-    //! query an MB internal interface
-  virtual MBErrorCode query_interface(const std::string& iface_name, void** iface)=0;
- 
-    //! release an MB internal interface 
-  virtual MBErrorCode release_interface(const std::string& iface_name, void* iface)=0;
-
-    //! Returns the major.minor version number of the interface
-    /**
-       \param version_string If non-NULL, will be filled in with a string, possibly 
-       containing implementation-specific information
-    */
-  virtual float api_version(std::string *version_string = NULL);
-    
-    //! Returns the major.minor version number of the implementation
-    /**
-       \param version_string If non-NULL, will be filled in with a string, possibly 
-       containing implementation-specific information
-    */
-  virtual float impl_version(std::string *version_string = NULL)=0;
-
-    //@}    
-
-    //! \name Type and id utility functions
-
-    //@{
-
-    //! Returns the entity type of an MBEntityHandle.
-    /** Returns the MBEntityType (ie, MeshVertex, MeshQuad, MeshHex ) of <em>handle</em>.
-        \param handle The MBEntityHandle you want to find the entity type of.
-        \return type The entity type of <em>handle</em>. 
-
-        Example: \code
-        MBEntityType type = type_from_handle( handle); 
-        if( type == MeshHex ) ...  \endcode 
-    */
-  virtual MBEntityType type_from_handle(const MBEntityHandle handle) const = 0;
- 
-    //! Returns the id from an MBEntityHandle.
-    /** \param handle The MBEntityHandle you want to find the id of. 
-        \return id Id of <em>handle</em>
-     
-        Example: \code
-        int id = id_from_handle(handle); \endcode 
-    */
-  virtual MBEntityID id_from_handle(const MBEntityHandle handle) const =0;
-
-    //! Returns the topological dimension of an entity
-    /** Returns the MBEntityType (ie, MeshVertex, MeshQuad, MeshHex ) of <em>handle</em>.
-        \param handle The MBEntityHandle you want to find the dimension of.
-        \return type The topological dimension of <em>handle</em>. 
-
-        Example: \code
-        int dim = dimension_from_handle( handle); 
-        if( dim == 0 ) ...  \endcode 
-    */
-  virtual int dimension_from_handle(const MBEntityHandle handle) const = 0;
-
-    //! Gets an entity handle from the data base, if it exists, according to type and id.
-    /** Given an MBEntiyType and an id, this function gets the existent MBEntityHandle. 
-        If no such MBEntityHandle exits, it returns MB_ENTITY_NOT_FOUND 
-        and sets handle to zero.
-        \param type The type of the MBEntityHandle to retrieve from the database.
-        \param id The id of the MBEntityHandle to retrieve from the database.
-        \param handle An MBEntityHandle of type <em>type</em> and <em>id</em>. 
-
-        Example: \code
-        MBEntityType handle;
-        MBErrorCode error_code = handle_from_id(MeshTri, 204, handle );
-        if( error_code == MB_ENTITY_NOT_FOUND ) ... \endcode
-    */
-  virtual MBErrorCode handle_from_id(const MBEntityType type, 
-                                     const MBEntityID, 
-                                     MBEntityHandle& handle) const =0;
-
-    //@}
-
-    //! \name Mesh input/output functions
-
-    //@{
-
-    //! Loads a mesh file into the database.
-    /** Loads the file 'file_name'; types of mesh which can be loaded 
-        depend on modules available at MB compile time.  If 
-        active_block_id_list is NULL, all material sets (blocks in the 
-        ExodusII jargon) are loaded.  Individual material sets  can be 
-        loaded by specifying their ids in 'active_block_id_list'.  All 
-        nodes are loaded on first call for a given file.  Subsequent 
-        calls for a file load any material sets not loaded in previous 
-        calls.
-        \param file_name Name of file to load into database.
-        \param active_block_id_list Material set/block ids to load.  
-                If NULL, ALL blocks of <em>file_name</em> are loaded.
-        \param num_blocks Number of blocks in active_block_id_list
-
-        Example: \code
-        std::vector<int> active_block_id_list;
-        int active_block_id_list[] = {1, 4, 10};
-        load_mesh( "temp.gen", active_block_id_list, 3 );  //load blocks 1, 4, 10 
-        \endcode 
-    */
-  virtual MBErrorCode load_mesh(const char *file_name,
-                                const int *active_block_id_list = NULL,
-                                const int num_blocks = 0)=0;
-
-  /**\brief Load or import a file.
-   *
-   * Load a MOAB-native file or import data from some other supported
-   * file format.
-   *
-   *\param file_name The location of the file to read.
-   *\param file_set  Output: a handle to a new set containing all entities 
-   *                        read or imported from the file.
-   *\param options A list of string options, separated by semicolons (;).
-   *               See README.IO for more information.  Options are typically
-   *               format-specific options or parallel options.  If an
-   *               option value is unrecognized but the file read otherwise
-   *               succeeded, MB_UNHANDLED_OPTION will be returned.
-   *\param set_tag_name The name of a tag used to designate the subset
-   *               of the file to read.  The name must correspond to 
-   *               data in the file that will be instantiated in MOAB
-   *               as a tag.  
-   *\param set_tag_values If the name specified in 'set_tag_name'
-   *               corresponds to a tag with a single integer value,
-   *               the values in this tag can be used to further
-   *               limit the subset of data written from the file to
-   *               only those entities or sets that have a value for
-   *               the tag that is one of the values in this array.
-   *\param num_set_tag_values The length of set_tag_values.
-   */
-  virtual MBErrorCode load_file( const char* file_name,
-                                 const MBEntityHandle* file_set = 0,
-                                 const char* options = 0,
-                                 const char* set_tag_name = 0,
-                                 const int* set_tag_values = 0,
-                                 int num_set_tag_values = 0 ) = 0;
-
-    //! Writes mesh to a file.
-    /** Write mesh to file 'file_name'; if output_list is non-NULL, only 
-        material sets contained in that list will be written.
-        \param file_name Name of file to write.
-        \param output_list 1d array of material set handles to write; if 
-                           NULL, all sets are written
-        \param num_sets Number of sets in output_list array
-
-        Example: \code
-        MBEntityHandle output_list[] = {meshset1, meshset2, meshset3}; 
-        write_mesh( "output_file.gen", output_list, 3 ); \endcode 
-    */
-  virtual MBErrorCode write_mesh(const char *file_name,
-                                 const MBEntityHandle *output_list = NULL,
-                                 const int num_sets = 0) = 0;
-
-  /**\brief Write or export a file.
-   * 
-   * Write a MOAB-native file or export data to some other supported
-   * file format.
-   *
-   *\param file_name The location of the file to write.
-   *\param file_type The type of the file.  If this value is NULL, 
-   *                 then file type will be determined using the 
-   *                 file name suffix.  
-   *\param options   A semicolon-separated list of options.
-   *                 See README.IO for more information.  Typical options
-   *                 include the file type, parallel options, and options
-   *                 specific to certain file formats.
-   *\param output_sets A list of entity sets to write to the file.  If
-   *                 no sets are sepcified, the default behavior is to
-   *                 write all data that is supported by the target file
-   *                 type.
-   *\param num_output_sets The length of the output_sets array.
-   *\param tag_list A list of tags for which to write the tag data.  The
-   *                write may fail if a tag list is specified but the 
-   *                target file type is not capable of representing the
-   *                data.  If no tags are specified, the default is to
-   *                write whatever data the target file format supports.
-   *\param num_tags The length of tag_list.
-   */
-  virtual MBErrorCode write_file( const char* file_name,
-                                  const char* file_type = 0,
-                                  const char* options = 0,
-                                  const MBEntityHandle* output_sets = 0,
-                                  int num_output_sets = 0,
-                                  const MBTag* tag_list = 0,
-                                  int num_tags = 0 ) = 0;
-
-  /**\brief Write or export a file.
-   * 
-   * Write a MOAB-native file or export data to some other supported
-   * file format.
-   *
-   *\param file_name The location of the file to write.
-   *\param file_type The type of the file.  If this value is NULL, 
-   *                 then file type will be determined using the 
-   *                 file name suffix.  
-   *\param options   A semicolon-separated list of options.
-   *                 See README.IO for more information.  Typical options
-   *                 include the file type, parallel options, and options
-   *                 specific to certain file formats.
-   *\param output_sets A list of entity sets to write to the file.  If
-   *                 no sets are sepcified, the default behavior is to
-   *                 write all data that is supported by the target file
-   *                 type.
-   *\param tag_list A list of tags for which to write the tag data.  The
-   *                write may fail if a tag list is specified but the 
-   *                target file type is not capable of representing the
-   *                data.  If no tags are specified, the default is to
-   *                write whatever data the target file format supports.
-   *\param num_tags The length of tag_list.
-   */
-  virtual MBErrorCode write_file( const char* file_name,
-                                  const char* file_type,
-                                  const char* options,
-                                  const MBRange& output_sets,
-                                  const MBTag* tag_list = 0,
-                                  int num_tags = 0 ) = 0;
-
-    //! Deletes all mesh entities from this MB instance
-  virtual MBErrorCode delete_mesh()=0;
-
-    //@}
-
-    //! \name Geometric dimension functions
-
-    //@{
-
-    //! Get overall geometric dimension
-  virtual MBErrorCode get_dimension(int &dim) const =0;
-
-    //! Set overall geometric dimension
-    /** Returns error if setting to 3 dimensions, mesh has been created, and 
-     *  there are only 2 dimensions on that mesh
-     */
-  virtual MBErrorCode set_dimension(const int dim)=0;
-
-    //@}
-
-    //! \name Vertex coordinate functions
-
-    //@{
-
-    //! Get blocked vertex coordinates for all vertices
-    /** Blocked = all x, then all y, etc. 
-          
-    Example: \code
-    std::vector<double> coords;
-    get_vertex_coordinates(coords);
-    double xavg = 0;
-    for (int i = 0; i < coords.size()/3; i++) xavg += coords[i]; \endcode
-    */
-  virtual MBErrorCode get_vertex_coordinates(std::vector<double> &coords) const =0;
-
-    //! Gets xyz coordinate information for range of vertices
-    /** Length of 'coords' should be at least 3*<em>entity_handles.size()</em> before making call.
-        \param entity_handles Range of vertex handles (error if not of type MeshVertex)
-        \param coords Array used to return x, y, and z coordinates.
-   
-        Example: \code 
-        double coords[3];
-        get_coords( vertex_handle, coords ); 
-        std::cout<<"x = "<<coords[0]<<std::endl;
-        std::cout<<"y = "<<coords[1]<<std::endl;
-        std::cout<<"z = "<<coords[2]<<std::endl; \endcode 
-    */
-  virtual MBErrorCode  get_coords(const MBRange& entity_handles, 
-                                  double *coords) const =0;
-    
-    //! Gets xyz coordinate information for vector of vertices
-    /** Identical to range-based function, except entity handles are specified using a 1d vector
-        and vector length.
-    */
-  virtual MBErrorCode  get_coords(const MBEntityHandle* entity_handles, 
-                                  const int num_entities, 
-                                  double *coords) const =0;
-  
-  /**\brief Get vertex coordinates in blocks by dimension.
-   *
-   * Get the X, Y, and Z coordinates of a group of vertices.  
-   * Coordinates are returned in separate arrays, one for each 
-   * dimension.  Each coordinate array must be of sufficient
-   * length to hold the coordinate value for each vertex.  Array
-   * pointers may be NULL if coordinates in the the respective 
-   * dimension are not desired.
-   *\param entity_handles  The group of vertex handles for which to get the coordiantes.
-   *\param x_coords        Output: the X coordinate of each vertex.  May be NULL.
-   *\param y_coords        Output: the Y coordinate of each vertex.  May be NULL.
-   *\param z_coords        Output: the Z coordinate of each vertex.  May be NULL.
-   */
-  virtual MBErrorCode get_coords( const MBRange& entity_handles,
-                                  double* x_coords,
-                                  double* y_coords,
-                                  double* z_coords ) const = 0;
-  
-  
-    //! Sets the xyz coordinates for a vector of vertices
-    /** An error is returned if any entities in the vector are not vertices.
-        \param entity_handles MBEntityHandle's to set coordinates of. (Must be of type MeshVertex)
-        \param num_entities Number of entities in entity_handles
-        \param coords Array containing new xyz coordinates.
- 
-        Example: \code
-        double coords[3] = {0.234, -2.52, 12.023};
-        set_coords( entity_handle, 1, coords ); \endcode 
-    */
-  virtual MBErrorCode  set_coords(const MBEntityHandle *entity_handles, 
-                                  const int num_entities,
-                                  const double *coords)=0;
-
-    //! Sets the xyz coordinates for a vector of vertices
-    /** An error is returned if any entities in the vector are not vertices.
-        \param entity_handles MBEntityHandle's to set coordinates of. (Must be of type MeshVertex)
-        \param num_entities Number of entities in entity_handles
-        \param coords Array containing new xyz coordinates.
- 
-        Example: \code
-        double coords[3] = {0.234, -2.52, 12.023};
-        set_coords( entity_handle, 1, coords ); \endcode 
-    */
-  virtual MBErrorCode  set_coords(MBRange entity_handles,
-                                  const double *coords)=0;
-
-    //@}
-
-    //! \name Connectivity functions
-
-    //@{
-
-    //! Get the connectivity array for all entities of the specified entity type
-    /**  This function returns the connectivity of just the corner vertices, no higher order nodes
-         \param type The entity type of elements whose connectivity is to be returned
-         \param connect an STL vector used to return connectivity array (in the form of entity handles)
-    */
-  virtual MBErrorCode get_connectivity_by_type(const MBEntityType type, 
-                                               std::vector<MBEntityHandle> &connect) const =0;
-
-    //! Gets the connectivity for a vector of elements
-    /** Same as vector-based version except range is returned (unordered!)
-    */
-  virtual MBErrorCode  get_connectivity(const MBEntityHandle *entity_handles, 
-                                        const int num_handles,
-                                        MBRange &connectivity, 
-                                        bool topological_connectivity = false) const =0;
-
-    //! Gets the connectivity for elements
-    /** Same as vector-based version except range is returned (unordered!)
-    */
-  virtual MBErrorCode get_connectivity( const MBRange& entity_handles, 
-                                        MBRange &connectivity, 
-                                        bool topological_connectivity = false) const =0;
- 
-    //! Gets the connectivity for a vector of elements
-    /** Corner vertices or all vertices (including higher-order nodes, if any) are returned.
-        For non-element handles (ie, MB_MeshSets), returns an error. Connectivity data is copied 
-        from the database into the vector.  Connectivity of a vertex is the same vertex.
-        The nodes in <em>connectivity</em> are properly ordered according to that element's 
-        canonical ordering.
-        \param entity_handles Vector of element handles to get connectivity of.
-        \param num_handles Number of entity handles in <em>entity_handles</em>
-        \param connectivity Vector in which connectivity of <em>entity_handles</em> is returned.  
-        \param topological_connectivity If true, higher order nodes are ignored. 
-    */
-  virtual MBErrorCode  get_connectivity(const MBEntityHandle *entity_handles, 
-                                        const int num_handles,
-                                        std::vector<MBEntityHandle> &connectivity, 
-                                        bool topological_connectivity = false) const =0;
- 
-    //! Gets a pointer to constant connectivity data of <em>entity_handle</em> 
-    /** Sets <em>number_nodes</em> equal to the number of nodes of the <em> 
-        entity_handle </em>.  Faster then the other <em>get_connectivity</em> function because no
-        data is copied.  The nodes in 'connectivity' are properly ordered according to the 
-        element's canonical ordering.
-        
-
-          Example: \code 
-          const MBEntityHandle* conn;
-          int number_nodes = 0;
-          get_connectivity( entity_handle, conn, number_nodes ); \endcode 
-          
-          Example2: \code
-          std::vector<MBEntityHandle> sm_storage;
-          const MBEntityHandle* conn;
-          int number_nodes;
-          get_connectivity( handle, conn, number_nodes, false, &sm_storage );
-          if (conn == &sm_storage[0])
-            std::cout << "Structured mesh element" << std::endl;
-          \endcode
-        
-        \param entity_handle MBEntityHandle to get connectivity of.
-        \param connectivity Array in which connectivity of <em>entity_handle</em> is returned.
-        \param num_nodes Number of MeshVertices in array <em>connectivity</em>. 
-        \param topological_connectivity If true, num_nodes will be set to number of corner vertices
-        for that element type.
-        \param storage Some elements (e.g. structured mesh) may not have an
-                       explicit connectivity list.  This function will normally
-                       return MB_NOT_IMPLEMENTED for such elements.  However,
-                       if the caller passes in a non-null value for this 
-                       argument, space will be allocated in this vector for
-                       the connectivity data and the connectivity pointer will
-                       be set to the data in this vector.
-    */
-  virtual MBErrorCode  get_connectivity(const MBEntityHandle entity_handle, 
-                                        const MBEntityHandle *&connectivity, 
-                                        int &num_nodes, 
-                                        bool topological_connectivity = false,
-                                        std::vector<MBEntityHandle>* storage = 0
-                                        ) const =0;
-
-    //! Sets the connectivity for an MBEntityHandle.  For non-element handles, return an error.
-    /** Connectivity is stored exactly as it is ordered in vector <em>connectivity</em>. 
-        \param entity_handle MBEntityHandle to set connectivity of.
-        \param connect Vector containing new connectivity of <em>entity_handle</em>.
-        \param num_connect Number of vertices in <em>connect</em>
-   
-        Example: \code 
-        MBEntityHandle conn[] = {node1, node2, node3};
-        set_connectivity( tri_element, conn, 3 ); \endcode 
-    */
-  virtual MBErrorCode  set_connectivity(const MBEntityHandle entity_handle, 
-                                        MBEntityHandle *connect,
-                                        const int num_connect)=0;
-
-    //! Sets the connectivity for an MBEntityHandle.  For non-element handles, return an error.
-    //@}
-
-    //! \name Adjacencies functions 
-
-    //@{
-
-    //! Get the adjacencies associated with a vector of entities to entities of a specfied dimension.
-    /** \param from_entities Vector of MBEntityHandle to get adjacencies of.
-        \param num_entities Number of entities in <em>from_entities</em>
-        \param to_dimension Dimension of desired adjacencies
-        \param create_if_missing If true, MB will create any entities of the specfied dimension
-        which have not yet been created (only useful when <em>to_dimension < dim(*from_entities)</em>)
-        \param adj_entities STL vector to which adjacent entities are appended. 
-        \param operation_type Enum of INTERSECT or UNION.  Defines whether to take
-        the intersection or union of the set of adjacencies recovered for the from_entities.
-
-        The adjacent entities in vector <em>adjacencies</em> are not in any particular 
-        order. 
-
-        Example: \code
-        std::vector<MBEntityHandle> adjacencies, from_entities = {hex1, hex2};
-          // generate all edges for these two hexes
-          get_adjacencies( from_entities, 2, 1, true, adjacencies, MBInterface::UNION); 
-          adjacencies.clear();
-            // now find the edges common to both hexes
-            get_adjacencies( from_entities, 2, 1, false, adjacencies, MBInterface::INTERSECT); 
-            \endcode 
-    */
-  virtual MBErrorCode get_adjacencies(const MBEntityHandle *from_entities,
-                                      const int num_entities,
-                                      const int to_dimension,
-                                      const bool create_if_missing,
-                                      std::vector<MBEntityHandle>& adj_entities,
-                                      const int operation_type = MBInterface::INTERSECT) = 0;
-
-    //! Get the adjacencies associated with a vector of entities to entities of a specfied dimension.
-    /** Identical to vector-based get_adjacencies function, except results are returned in a
-        range instead of a vector.
-    */
-  virtual MBErrorCode get_adjacencies(const MBEntityHandle *from_entities,
-                                      const int num_entities,
-                                      const int to_dimension,
-                                      const bool create_if_missing,
-                                      MBRange &adj_entities,
-                                      const int operation_type = MBInterface::INTERSECT) = 0;
-
-    //! Get the adjacencies associated with a range of entities to entities of a specfied dimension.
-    /** Identical to vector-based get_adjacencies function, except "from" entities specified in a
-        range instead of a vector.
-    */
-  virtual MBErrorCode get_adjacencies(const MBRange &from_entities,
-                                      const int to_dimension,
-                                      const bool create_if_missing,
-                                      MBRange &adj_entities,
-                                      const int operation_type = MBInterface::INTERSECT) = 0;
-
-    //! Adds adjacencies between "from" and "to" entities.
-    /** \param from_handle Entities on which the adjacencies are placed
-        \param to_handles Vector of entities referenced by new adjacencies added to <em>from_handle</em>
-        \param num_handles Number of entities in <em>to_handles</em>
-        \param both_ways If true, add the adjacency information in both directions; if false,
-        adjacencies are added only to <em>from_handle</em>
-    */
-  virtual MBErrorCode add_adjacencies(const MBEntityHandle from_handle, 
-                                      const MBEntityHandle *to_handles,
-                                      const int num_handles,
-                                      bool both_ways) = 0;
-
-    //! Adds adjacencies; same as vector-based, but with range instead
-  virtual MBErrorCode add_adjacencies(const MBEntityHandle from_handle, 
-                                      MBRange &adjacencies,
-                                      bool both_ways) = 0;
-
-    //! Removes adjacencies between handles.
-    /** Adjacencies in both directions are removed.
-        \param from_handle Entity from which adjacencies are being removed.
-        \param to_handles Entities to which adjacencies are being removed.
-        \param num_handles Number of handles in <em>to_handles</em>
-    */
-  virtual MBErrorCode remove_adjacencies(const MBEntityHandle from_handle, 
-                                         const MBEntityHandle *to_handles,
-                                         const int num_handles) = 0;
-
-    //@}
-
-    //! Enumerated type used in get_adjacencies() and other functions
-  enum {INTERSECT, UNION};
-
-    //! \name Functions for getting entities
-
-    //@{
-
-    //! Retrieves all entities of a given topological dimension in the database or meshset.
-    /** Appends entities to list passed in.
-        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
-        \param dimension Topological dimension of entities desired.
-        \param entities Range in which entities of dimension <em>dimension</em> are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves if true.
-
-        Example: \code
-          // get 1d (edge) elements in the entire mesh
-          MBRange edges;
-          get_entities_by_dimension( 0, 1, edges );
-          \endcode 
-    */
-  virtual MBErrorCode get_entities_by_dimension(const MBEntityHandle meshset,
-                                                const int dimension, 
-                                                MBRange &entities,
-                                                const bool recursive = false)  const = 0;
-
-  virtual MBErrorCode get_entities_by_dimension(const MBEntityHandle meshset,
-                                                const int dimension, 
-                                                std::vector<MBEntityHandle> &entities,
-                                                const bool recursive = false)  const = 0;
-
-    //! Retrieve all entities of a given type in the database or meshset.
-    /** Appends entities to list passed in.
-        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
-        \param type Type of entities to be returned
-        \param entities Range in which entities of type <em>type</em> are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves.  Specifying 
-                         both recursive=true and type=MBMESHSET is an error, as it would always 
-                         result in an empty list.
-
-        Example: \code
-          // get the quadrilateral elements in meshset
-          MBRange quads;
-          get_entities_by_type( meshset, MeshQuad, quads );
-          \endcode 
-    */
-  virtual MBErrorCode get_entities_by_type(const MBEntityHandle meshset,
-                                           const MBEntityType type, 
-                                           MBRange &entities,
-                                           const bool recursive = false) const = 0;
-
-  virtual MBErrorCode get_entities_by_type(const MBEntityHandle meshset,
-                                           const MBEntityType type, 
-                                           std::vector<MBEntityHandle> &entities,
-                                           const bool recursive = false) const = 0;
-
-    //! Retrieve entities in the database or meshset which have any or all of the tag(s) and (optionally)
-    //! value(s) specified.
-    /** \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
-        \param type Type of entities to be returned
-        \param tag_handles Vector of tag handles entities must have
-        \param values Vector of pointers to values of tags in <em>tag_handles</em>
-        \param num_tags Number of tags and values in <em>tag_handles</em> and <em>values</em>
-        \param entities Range in which entities are returned.
-        \param condition Boolean condition, either MBInterface::UNION or MBInterface::INTERSECT
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves.  Specifying 
-                         both recursive=true and type=MBMESHSET is an error, as it would always 
-                         result in an empty list.
-
-        If MBInterface::UNION is specified as the condition, entities with <em>any</em> of the tags
-        and values specified are returned.  If MBInterface::INTERSECT is specified, only entities with
-        <em>all</em> of the tags/values are returned.
-
-        If <em>values</em> is NULL, entities with the specified tags and any corresponding values are
-        returned.  Note that if <em>values</em> is non-NULL, it is a vector of <em>pointers</em> to
-        tag values.
-
-        Example: \code
-          // get the dirichlet sets in a mesh
-          MBRange dir_sets;
-          MBTag dir_tag;
-          tag_get_handle(DIRICHLET_SET_TAG_NAME, dir_tag);
-          get_entities_by_type_and_tag(0, MeshEntitySet, &dir_tag, NULL, 1, dir_sets, 
-          MBInterface::UNION);
-          \endcode 
-    */
-  virtual MBErrorCode get_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                   const MBEntityType type,
-                                                   const MBTag *tag_handles,
-                                                   const void* const* values,
-                                                   const int num_tags,
-                                                   MBRange &entities,
-                                                   const int condition = MBInterface::INTERSECT,
-                                                   const bool recursive = false) const = 0;
-
-    //! Returns all entities in the data base or meshset, in a range (order not preserved)
-    /** Appends entities to list passed in.
-        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
-        \param entities Range in which entities are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves if true.
-
-        Example: \code
-        MBRange entities;
-          // get all non-meshset entities in meshset, including in contained meshsets
-          get_entities_by_handle(meshset, entities, true);
-          \endcode 
-    */
-  virtual MBErrorCode get_entities_by_handle(const MBEntityHandle meshset,
-                                             MBRange &entities,
-                                             const bool recursive = false) const = 0;
-
-    //! Returns all entities in the data base or meshset, in a vector (order preserved)
-    /** Appends entities to list passed in.
-        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
-        \param entities STL vector in which entities are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves if true.
-
-        Example: \code
-        std::vector<MBEntityHandle> entities;
-          // get all non-meshset entities in meshset, including in contained meshsets
-          get_entities_by_handle(meshset, entities, true);
-          \endcode 
-    */
-  virtual MBErrorCode get_entities_by_handle(const MBEntityHandle meshset,
-                                             std::vector<MBEntityHandle> &entities,
-                                             const bool recursive = false) const = 0;
-
-    //! Return the number of entities of given dimension in the database or meshset
-    /** \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
-        \param dimension Dimension of entities desired.
-        \param num_entities Number of entities of the given dimension
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves if true.
-    */
-  virtual MBErrorCode get_number_entities_by_dimension(const MBEntityHandle meshset,
-                                                       const int dimension, 
-                                                       int &num_entities,
-                                                       const bool recursive = false) const = 0;
-
-    //! Retrieve the number of entities of a given type in the database or meshset.
-    /** Identical to get_entities_by_dimension, except returns number instead of entities
-        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
-        \param type Type of entities to be returned
-        \param num_entities Number of entities of type <em>type</em>
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves.  Specifying 
-                         both recursive=true and type=MBMESHSET is an error, as it would always 
-                         result in an empty list.
-    */
-  virtual MBErrorCode get_number_entities_by_type(const MBEntityHandle meshset,
-                                                  const MBEntityType type, 
-                                                  int &num_entities,
-                                                  const bool recursive = false) const = 0;
-
-    //! Retrieve number of entities in the database or meshset which have any or all of the 
-    //! tag(s) and (optionally) value(s) specified.
-    /** Identical to get_entities_by_type_and_tag, except number instead of entities are returned
-        \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
-        \param type Type of entities to be returned
-        \param tag_handles Vector of tag handles entities must have
-        \param values Vector of pointers to values of tags in <em>tag_handles</em>
-        \param num_tags Number of tags and values in <em>tag_handles</em> and <em>values</em>
-        \param num_entities Range in which number of entities are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves.  Specifying 
-                         both recursive=true and type=MBMESHSET is an error, as it would always 
-                         result in an empty list.
-    */
-  virtual MBErrorCode get_number_entities_by_type_and_tag(const MBEntityHandle meshset,
-                                                          const MBEntityType type,
-                                                          const MBTag *tag_handles,
-                                                          const void* const* values,
-                                                          const int num_tags,
-                                                          int &num_entities,
-                                                          const bool recursive = false) const = 0;
-
-    //! Returns number of entities in the data base or meshset
-    /** Identical to get-entities_by_handle, except number instead of entities are returned
-        \param meshset Meshset whose entities are being queried (zero if query is for the entire mesh).
-        \param num_entities Range in which num_entities are returned.
-        \param recursive If true, meshsets containing meshsets are queried recursively.  Returns
-                         the contents of meshsets, but not the meshsets themselves if true.
-    */
-  virtual MBErrorCode get_number_entities_by_handle(const MBEntityHandle meshset,
-                                                    int &num_entities,
-                                                    const bool recursive = false) const = 0;
-
-    //@}
-
-    //! \name Modifying the mesh
-
-    //@{
-
-    //! Create an element based on the type and connectivity. 
-    /** Create a new element in the database.  Vertices composing this element must already exist,
-        and connectivity must be specified in canonical order for the given element type.  If 
-        connectivity vector is not correct for MBEntityType <em>type</em> (ie, a vector with 
-        3 vertices is passed in to make an MeshQuad), the function returns MB_FAILURE. 
-        \param type Type of element to create. (MeshTet, MeshTri, MeshKnife, etc.) 
-        \param connectivity 1d vector containing connectivity of element to create.
-        \param num_vertices Number of vertices in element
-        \param element_handle Handle representing the newly created element in the database.
-
-        Example: \code
-        MBEntityHandle quad_conn[] = {vertex0, vertex1, vertex2, vertex3};
-        MBEntityHandle quad_handle = 0;
-        create_element( MeshQuad, quad_conn, 4, quad_handle ); \endcode 
-    */
-  virtual MBErrorCode create_element(const MBEntityType type, 
-                                     const MBEntityHandle *connectivity,
-                                     const int num_vertices, 
-                                     MBEntityHandle &element_handle) = 0;
-
-    //! Creates a vertex with the specified coordinates.  
-    /**
-       \param coordinates Array that has 3 doubles in it.
-       \param entity_handle MBEntityHandle representing the newly created vertex in the database.
-
-       Example: \code
-       double coordinates[] = {1.034, 23.23, -0.432};
-       MBEntityHandle new_handle = 0;
-       create_vertex( coordinates, entity_handle ); \endcode 
-    */
-  virtual MBErrorCode create_vertex(const double coordinates[3], 
-                                    MBEntityHandle &entity_handle ) = 0;
-
-    //! Create a set of vertices with the specified coordinates
-    /**
-       \param coordinates Array that has 3*n doubles in it.
-       \param nverts Number of vertices to create
-       \param entity_handles MBRange passed back with new vertex handles
-    */
-  virtual MBErrorCode create_vertices(const double *coordinates, 
-                                      const int nverts,
-                                      MBRange &entity_handles ) = 0;
-
-    //! Merge two entities into a single entity
-    /** Merge two entities into a single entities, with <em>entity_to_keep</em> receiving
-        adjacencies that were on <em>entity_to_remove</em>.
-        \param entity_to_keep Entity to be kept after merge
-        \param entity_to_remove Entity to be merged into <em>entity_to_keep</em>
-        \param auto_merge If false, <em>entity_to_keep</em> and <em>entity_to_remove</em> must share
-        the same lower-dimensional entities; if true, MB tries to merge those entities automatically
-        \param delete_removed_entity If true, <em>entity_to_remove</em> is deleted after merge is complete
-    */
-  virtual MBErrorCode merge_entities(MBEntityHandle entity_to_keep, 
-                                     MBEntityHandle entity_to_remove,
-                                     bool auto_merge,
-                                     bool delete_removed_entity) = 0;
-
-    //! Removes entities in a vector from the data base.  
-    /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
-        which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity</em> are 
-        removed as part of this function.
-        \param entities 1d vector of entities to delete
-        \param num_entities Number of entities in 1d vector
-    */ 
-  virtual MBErrorCode delete_entities(const MBEntityHandle *entities,
-                                      const int num_entities) = 0;
-
-    //! Removes entities in a range from the data base.  
-    /** If any of the entities are contained in any meshsets, it is removed from those meshsets 
-        which were created with MESHSET_TRACK_OWNER option bit set.  Tags for <em>entity</em> are 
-        removed as part of this function.
-        \param entities Range of entities to delete
-    */ 
-  virtual MBErrorCode delete_entities(const MBRange &entities) = 0;
-
-    //@}
-
-    //! \name Listing entities
-
-    //@{
-
-    //! List entities to standard output
-    /** Lists all data pertaining to entities (i.e. vertex coordinates if vertices, connectivity if
-        elements, set membership if set).  Useful for debugging, but output can become quite long
-        for large databases.
-    */
-  virtual MBErrorCode list_entities(const MBRange &entities) const = 0;
-  
-    //! List entities, or number of entities in database, to standard output
-    /** Lists data pertaining to entities to standard output.  If <em>entities</em> is NULL and
-        <em>num_entities</em> is zero, lists only the number of entities of each type in the 
-        database.  If <em>entities</em> is NULL and <em>num_entities</em> is non-zero, lists all
-        information for all entities in the database.
-        \param entities 1d vector of entities to list
-        \param num_entities Number of entities in 1d vector
-    */
-  virtual MBErrorCode list_entities(const MBEntityHandle *entities,
-                                    const int num_entities) const = 0;
-
-    //! List a single entity; no header printed
-    /** Lists a single entity, including its connectivity and its adjacencies.
-     *  No header is printed, because calling function might print information between header
-     *  and information printed by this function.
-     *  \param entity The entity to be listed.
-     */
-  virtual MBErrorCode list_entity(const MBEntityHandle entity) const = 0;
-
-    //@}
-
-    //! \name Functions for higher-order elements
-
-    //@{
-
-    //! function object for recieving events from MB of higher order nodes added to entities
-  class HONodeAddedRemoved
-  {
-  public:
-      //! Constructor
-    HONodeAddedRemoved(){}
- 
-      //! Destructor
-    virtual ~HONodeAddedRemoved(){}
-
-      //! node_added called when a node was added to an element's connectivity array
-      //! note: connectivity array of element may be incomplete (corner nodes will exist always)
-      /** 
-       * \param node Node being added
-       * \param element Element node is being added to
-       */
-    virtual void node_added(MBEntityHandle node, MBEntityHandle element) = 0;
-
-      //! node_added called when a node was added to an element's connectivity array
-      //! note: connectivity array of element may be incomplete (corner nodes will exist always)
-      /**
-       * \param node Node being removed.
-       */
-    virtual void node_removed(MBEntityHandle node) = 0;
-  };
-  
-    //! Convert entities to higher-order elements by adding mid nodes
-    /** This function causes MB to create mid-nodes on all edges, faces, and element interiors 
-        for all entities in <em>meshset</em>.  Higher order nodes appear in an element's connectivity
-        array according to the algorithm described in the documentation for Mesh.  If 
-        <em>HONodeAddedRemoved</em> function is input, this function is called to notify the application
-        of nodes being added/removed from the mesh.
-        \param meshset The set of entities being converted
-        \param mid_edge If true, mid-edge nodes are created 
-        \param mid_face If true, mid-face nodes are created 
-        \param mid_region If true, mid-element nodes are created 
-        \param function_object If non-NULL, the node_added or node_removed functions on this object 
-        are called when nodes are added or removed from an entity, respectively
-    */
-  virtual MBErrorCode convert_entities(const MBEntityHandle meshset, 
-                                       const bool mid_edge,
-                                       const bool mid_face, 
-                                       const bool mid_region, 
-                                       HONodeAddedRemoved* function_object = 0) = 0;
-
-    //! Returns the side number, in canonical ordering, of <em>child</em> with respect to <em>parent</em>
-    /** Given a parent and child entity, returns the canonical ordering information side number, sense, 
-        and offset of <em>child</em> with respect to <em>parent</em>.  This function returns
-        MB_FAILURE if <em>child</em> is not related to <em>parent</em>.  This function does *not* 
-        create adjacencies between <em>parent</em> and <em>child</em>.
-        \param parent Parent entity to be compared
-        \param child Child entity to be compared
-        \param side_number Side number in canonical ordering of <em>child</em> with respect to 
-        <em>parent</em>
-        \param sense Sense of <em>child</em> with respect to <em>parent</em>, assuming ordering of 
-        <em>child</em> as given by get_connectivity called on <em>child</em>; sense is 1, -1
-        for forward/reverse sense, resp.
-        \param offset Offset between first vertex of <em>child</em> and first vertex of side 
-        <em>side_number</em> on <em>parent</em>
-    */
-  virtual MBErrorCode side_number(const MBEntityHandle parent,
-                                  const MBEntityHandle child,
-                                  int &side_number,
-                                  int &sense,
-                                  int &offset) const = 0;
-
-    //! Find the higher-order node on a subfacet of an entity
-    /** Given an entity and the connectivity and type of one of its subfacets, find the
-        high order node on that subfacet, if any.  The number of vertices in <em>subfacet_conn</em>
-        is derived from <em>subfacet_type</em> and the canonical numbering for that type.
-        \param parent_handle The element whose subfacet is being queried
-        \param subfacet_conn The connectivity of the subfacet being queried
-        \param subfacet_type The type of subfacet being queried
-        \param high_order_node If the subfacet has a high-order node defined on <em>parent_handle</em>,
-        the handle for that node.
-    */
-  virtual MBErrorCode high_order_node(const MBEntityHandle parent_handle,
-                                      const MBEntityHandle *subfacet_conn,
-                                      const MBEntityType subfacet_type,
-                                      MBEntityHandle &high_order_node) const = 0;
-
-    //! Return the handle of the side element of a given dimension and index
-    /** Given a parent entity and a target dimension and side number, return the handle of
-        the entity corresponding to that side.  If an entity has not been created to represent
-        that side, one is not created by this function, and zero is returned in <em>target_entity</em>.
-        \param source_entity The entity whose side is being queried.
-        \param dim The topological dimension of the side being queried.
-        \param side_number The canonical index of the side being queried.
-        \param target_entity The handle of the entity representing this side, if any.
-    */
-  virtual MBErrorCode side_element(const MBEntityHandle source_entity,
-                                   const int dim, 
-                                   const int side_number,
-                                   MBEntityHandle &target_entity) const = 0;
-
-    //@}
-
-    //! \name Tag functions
-
-    //@{
-
-    //! Create a tag with the specified name, type and length
-    /** Create a "tag", used to store application-defined data on MB entities.  If MB_ALREADY_ALLOCATED
-        is returned, a tag with this name has already been created.  Tags created with this function
-        are assigned to entities using the tag_set_data function described below.
-        \param tag_name Name of this tag
-        \param tag_size Size of data to store on tag, in bytes (MB_TAG_DENSE, MB_TAG_SPARSE) or
-        bits (MB_TAG_BITS).
-        \param type Type of tag to create (MB_TAG_BIT, MB_TAG_SPARSE, MB_TAG_DENSE, MB_TAG_MESH)
-        \param tag_handle Tag handle created
-        \param default_value Default value tag data is set to when initially created
-
-        Example: \code
-        MBTag tag_handle;
-        double value = 100.0;
-          // create a dense tag with default value of 100
-          tag_create( "my_tag", sizeof(double), MB_TAG_DENSE, tag_handle, &value );\endcode
-    */
-  virtual MBErrorCode tag_create(const char *tag_name,
-                                 const int tag_size, 
-                                 const MBTagType type,
-                                 MBTag &tag_handle, 
-                                 const void *default_value) = 0;
-
-    /** \brief Define a new tag.
-     *
-     * Define a new tag for storing application-defined data on MB entities.  
-     *
-     * \param name    The name of the tag.
-     * \param size    The size of the tag data in bytes.
-     * \param storage The tag storage type.
-     * \param data    The tag data type.
-     * \param handle  The tag handle (output)
-     * \param def_val Optional default value for tag.
-     * \param use_existing  If true, and a tag with the same name and
-     *                same description exists, successfully return the
-     *                handle of the tag.
-     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
-     *         - MB_FAILURE if inconsistant arguments
-     *         - MB_SUCCESS otherwise.
-     */
-  virtual MBErrorCode tag_create( const      char* name,
-                                  const        int size,
-                                  const  MBTagType storage,
-                                  const MBDataType data,
-                                            MBTag& handle,
-                                  const      void* def_val,
-                                              bool use_existing = false ) = 0;
-
-    /**\brief Define a new tag that can store variable-length data.
-     *
-     * Define a new tag for storing application-defined data on MB entities.  
-     *
-     * \param name          The name of the tag.
-     * \param storage       The tag storage type (MB_TAG_BIT not supported).
-     * \param data_type     The tag data type.
-     * \param handle_out    The tag handle (output)
-     * \param default_value Optional default value for tag.
-     * \param default_val_len Length of default value.  Required if
-     *                      default value is specified.
-     * \return - MB_ALREADY_ALLOCATED if a tag with name already exists.
-     *         - MB_FAILURE if inconsistant arguments
-     *         - MB_SUCCESS otherwise.
-     */
-  virtual MBErrorCode tag_create_variable_length( const char* name,
-                                                  MBTagType   storage,
-                                                  MBDataType  data_type,
-                                                  MBTag&      handle_out,
-                                                  const void* default_value = 0,
-                                                  int         default_val_len = 0 
-                                                 ) = 0;
-
-    //! Get the name of a tag corresponding to a handle
-    /** \param tag_handle Tag you want the name of.  
-        \param tag_name Name string for <em>tag_handle</em>. 
-    */
-  virtual MBErrorCode  tag_get_name(const MBTag tag_handle, 
-                                    std::string& tag_name) const = 0;
-
-    //! Gets the tag handle corresponding to a name
-    /** If a tag of that name does not exist, returns MB_TAG_NOT_FOUND
-        \param tag_name Name of the desired tag. 
-        \param tag_handle Tag handle corresponding to <em>tag_name</em>
-    */ 
-  virtual MBErrorCode  tag_get_handle(const char *tag_name, 
-                                      MBTag &tag_handle) const = 0;
-
-    //! Get the size of the specified tag
-    /** Get the size of the specified tag, in bytes (MB_TAG_SPARSE, MB_TAG_DENSE, MB_TAG_MESH) or
-        bits (MB_TAG_BIT).
-        \param tag Handle of the desired tag. 
-        \param tag_size Size of the specified tag
-    */ 
-  virtual MBErrorCode tag_get_size(const MBTag tag, int &tag_size) const = 0;
-
-    //! Get the type of the specified tag
-    /** Get the type of the specified tag
-        \param tag Handle of the desired tag. 
-        \param tag_type Type of the specified tag
-    */ 
-  virtual MBErrorCode tag_get_type(const MBTag tag, MBTagType &tag_type) const = 0;
-
-    /** \brief Get data type of tag.
-     *
-     * Get the type of the tag data.  The tag is data is assumed to
-     * be a vector of this type.  If the tag data vetcor contains 
-     * more than one value, then the tag size must be a multiple of
-     * the size of this type.
-     * \param tag  The tag 
-     * \param type The type of the specified tag (output).
-     */
-   virtual MBErrorCode tag_get_data_type(const MBTag tag, MBDataType& type) const = 0;
-
-    //! Get the default value of the specified tag
-    /** Get the default value of the specified tag
-        \param tag Handle of the desired tag. 
-        \param def_value Pointer to memory where default value of the specified tag is written
-        \return - MB_ENTITY_NOT_FOUND If no default value is set for tag.
-                - MB_SUCCESS          If success.
-                - MB_FAILURE          If <code>def_val</code> is NULL.
-                - MB_TAG_NOT_FOUND    If <code>tag_handle</code> is invalid.
-    */ 
-  virtual MBErrorCode tag_get_default_value(const MBTag tag, void *def_val) const = 0;
-  virtual MBErrorCode tag_get_default_value( MBTag tag, const void*& def_val, int& size) const = 0;
-
-    //! Get handles for all tags defined in the mesh instance
-    /** Get handles for all tags defined on the mesh instance.
-        \param tag_handles STL vector of all tags
-    */
-  virtual MBErrorCode tag_get_tags(std::vector<MBTag> &tag_handles) const = 0;
-
-    //! Get handles for all tags defined on this entity
-    /** Get handles for all tags defined on this entity; if zero, get all tags defined 
-        on mesh instance
-        \param entity Entity for which you want tags
-        \param tag_handles STL vector of all tags defined on <em>entity</em>
-    */
-  virtual MBErrorCode tag_get_tags_on_entity(const MBEntityHandle entity,
-                                             std::vector<MBTag> &tag_handles) const = 0;
-
-    //! Get the value of the indicated tag on the specified entities in the specified vector
-    /** Get the value of the indicated tag on the specified entities; <em>tag_data</em> must contain
-        enough space (i.e. tag_size*num_entities bytes) to hold all tag data.  MOAB does <em>not</em>
-        check whether this space is available before writing to it.
-        \note For bit tags, tag_data must contain one byte per entity.  For each
-              entity, the corresponding byte will contain the tag bits in the
-              lower bit positions and zero bits in the higher.
-        \param tag_handle Tag whose values are being queried.
-        \param entity_handles 1d vector of entity handles whose tag values are being queried
-        \param num_entities Number of entities in 1d vector of entity handles
-        \param tag_data Pointer to memory into which tag data will be written
-    */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities, 
-                                    void *tag_data) const = 0;
-
-    //! Get the value of the indicated tag on the specified entities in the specified range
-    /** Identical to previous function, except entities are specified using a range instead of a 1d vector.
-        \param tag_handle Tag whose values are being queried.
-        \param entity_handles Range of entity handles whose tag values are being queried
-        \param tag_data Pointer to memory into which tag data will be written
-    */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles, 
-                                    void *tag_data) const = 0;
-
-    //! Set the value of the indicated tag on the specified entities in the specified vector
-    /** Set the value of the indicated tag on the specified entities; <em>tag_data</em> contains the
-        values, <em>one value per entity in <em>entity_handles</em></em>.
-        \note For bit tags, tag_data must contain one byte per entity.  For each
-              entity, the tag bits will be read from the lower bits of the 
-              corresponding byte.
-        \param tag_handle Tag whose values are being set
-        \param entity_handles 1d vector of entity handles whose tag values are being set
-        \param num_entities Number of entities in 1d vector of entity handles
-        \param tag_data Pointer to memory holding tag values to be set, <em>one entry per entity handle</em>
-    */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities,
-                                    const void *tag_data ) = 0;
-  
-    //! Set the value of the indicated tag on the specified entities in the specified range
-    /** Identical to previous function, except entities are specified using a range instead of a 1d vector.
-        \param tag_handle Tag whose values are being set
-        \param entity_handles Range of entity handles whose tag values are being set
-        \param tag_data Pointer to memory holding tag values to be set, <em>one entry per entity handle</em>
-    */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles,
-                                    const void *tag_data ) = 0;
-
-
-    /**\brief Get pointers to tag data
-     *
-     * For a tag, get the values for a list of passed entity handles.
-     *\note  This function may not be used for bit tags.
-     *\param tag_handle     The tag
-     *\param entity_handles An array of entity handles for which to retreive tag values.
-     *\param num_entities   The length of the 'entity_handles' array.
-     *\param tag_data       An array of 'const void*'.  Array must be at least
-     *                      'num_entitities' long.  Array is populated (output)
-     *                      with pointers to the internal storage for the
-     *                      tag value corresponding to each entity handle.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities, 
-                                    const void** tag_data,
-                                    int* tag_sizes = 0 ) const = 0;
-
-    /**\brief Get pointers to tag data
-     *
-     * For a tag, get the values for a list of passed entity handles.
-     *\note  This function may not be used for bit tags.
-     *\param tag_handle     The tag
-     *\param entity_handles The entity handles for which to retreive tag values.
-     *\param tag_data       An array of 'const void*'.  Array is populated (output)
-     *                      with pointers to the internal storage for the
-     *                      tag value corresponding to each entity handle.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_get_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles, 
-                                    const void** tag_data,
-                                    int* tag_sizes = 0 ) const = 0;
-
-    /**\brief Set tag data given an array of pointers to tag values.
-     *
-     * For a tag, set the values for a list of passed entity handles.
-     *\note  This function may not be used for bit tags.
-     *\param tag_handle     The tag
-     *\param entity_handles An array of entity handles for which to set tag values.
-     *\param num_entities   The length of the 'entity_handles' array.
-     *\param tag_data       An array of 'const void*'.  Array must be at least
-     *                      'num_entitities' long.  Array is expected to
-     *                      contain pointers to tag values for the corresponding
-     *                      MBEntityHandle in 'entity_handles'.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBEntityHandle* entity_handles, 
-                                    const int num_entities,
-                                    void const* const* tag_data,
-                                    const int* tag_sizes = 0 ) = 0;
-  
-    /**\brief Set tag data given an array of pointers to tag values.
-     *
-     * For a tag, set the values for a list of passed entity handles.
-     *\note  This function may not be used for bit tags.
-     *\param tag_handle     The tag
-     *\param entity_handles The entity handles for which to set tag values.
-     *\param tag_data       An array of 'const void*'.  Array is expected to
-     *                      contain pointers to tag values for the corresponding
-     *                      MBEntityHandle in 'entity_handles'.
-     *\param tag_sizes      The length of each tag value.  Optional for 
-     *                      fixed-length tags.  Required for variable-length tags.
-     */
-  virtual MBErrorCode  tag_set_data(const MBTag tag_handle, 
-                                    const MBRange& entity_handles,
-                                    void const* const* tag_data,
-                                    const int* tag_sizes = 0 ) = 0;
-
-    //! Delete the data of a vector of entity handles and sparse tag
-    /** Delete the data of a tag on a vector of entity handles.  Only sparse tag data are deleted with this
-        function; dense tags are deleted by deleting the tag itself using tag_delete.
-        \param tag_handle Handle of the (sparse) tag being deleted from entity
-        \param entity_handles 1d vector of entity handles from which the tag is being deleted
-        \param num_handles Number of entity handles in 1d vector
-    */
-  virtual MBErrorCode  tag_delete_data(const MBTag tag_handle, 
-                                       const MBEntityHandle *entity_handles,
-                                       const int num_handles) = 0;
-
-    //! Delete the data of a range of entity handles and sparse tag
-    /** Delete the data of a tag on a range of entity handles.  Only sparse tag data are deleted with this
-        function; dense tags are deleted by deleting the tag itself using tag_delete.
-        \param tag_handle Handle of the (sparse) tag being deleted from entity
-        \param entity_range Range of entities from which the tag is being deleted
-    */
-  virtual MBErrorCode  tag_delete_data(const MBTag tag_handle, 
-                                       const MBRange &entity_range) = 0;
-
-    //! Remove a tag from the database and delete all of its associated data
-    /** Deletes a tag and all associated data.
-     */
-  virtual MBErrorCode  tag_delete(MBTag tag_handle) = 0;
-
-    //@}
-
-    //! \name Meshset functions
-
-    //@{
-
-    //! Create a new mesh set
-    /** Create a new mesh set.  Meshsets can store entities ordered or unordered. A set can include entities
-        at most once (MESHSET_SET) or more than once.  Meshsets can optionally track its members using
-        adjacencies (MESHSET_TRACK_OWNER); if set, entities are deleted from tracking meshsets before
-        being deleted.  This adds data to mesh entities, which can be expensive.
-        \param options Options bitmask for the new meshset, possible values defined above
-        \param ms_handle Handle for the meshset created
-    */
-  virtual MBErrorCode create_meshset(const unsigned int options, 
-                                     MBEntityHandle &ms_handle,
-                                     int start_id = 0) = 0;
-
-    //! Empty a vector of mesh set
-    /** Empty a mesh set.
-        \param ms_handles 1d vector of handles of sets being emptied
-        \param num_meshsets Number of entities in 1d vector
-    */
-  virtual MBErrorCode clear_meshset( const MBEntityHandle *ms_handles, 
-                                     const int num_meshsets) = 0;
-
-    //! Empty a range of mesh set
-    /** Empty a mesh set.
-        \param ms_handles Range of handles of sets being emptied
-    */
-  virtual MBErrorCode clear_meshset( const MBRange &ms_handles) = 0;
-
-    //! Get the options of a mesh set
-    /** Get the options of a mesh set.
-        \param ms_handle Handle for mesh set being queried
-        \param options Bit mask in which mesh set options are returned
-    */
-  virtual MBErrorCode get_meshset_options(const MBEntityHandle ms_handle, 
-                                          unsigned int& options) const = 0;
-
-    //! Set the options of a mesh set
-    /** Set the options of a mesh set.
-        \param ms_handle Handle for meshset whose options are being changed
-        \param options Bit mask of options to be used
-    */
-  virtual MBErrorCode set_meshset_options(const MBEntityHandle ms_handle, 
-                                          const unsigned int options) = 0;
-
-    //! Subtract meshsets
-    /** Subtract <em>meshset2</em> from <em>meshset1</em>, placing the results in meshset1.
-        \param meshset1 Mesh set being subtracted from, also used to pass back result
-        \param meshset2 Mesh set being subtracted from <em>meshset1</em>
-    */
-  virtual MBErrorCode subtract_meshset(MBEntityHandle meshset1, 
-                                       const MBEntityHandle meshset2) = 0;
-
-    //! Intersect meshsets
-    /** Intersect <em>meshset1</em> with <em>meshset2</em>, placing the results in meshset1.
-        \param meshset1 Mesh set being intersected, also used to pass back result
-        \param meshset2 Mesh set being intersected with <em>meshset1</em>
-    */
-  virtual MBErrorCode intersect_meshset(MBEntityHandle meshset1, 
-                                        const MBEntityHandle meshset2) = 0;
-    
-    //! Unite meshsets
-    /** Unite <em>meshset1</em> with <em>meshset2</em>, placing the results in meshset1.
-        \param meshset1 Mesh set being united, also used to pass back result
-        \param meshset2 Mesh set being united with <em>meshset1</em>
-    */
-  virtual MBErrorCode unite_meshset(MBEntityHandle meshset1, 
-                                    const MBEntityHandle meshset2) = 0;
-
-    //! Add to a meshset entities in specified range
-    /** Add to a meshset entities in specified range.  If <em>meshset</em> has MESHSET_TRACK_OWNER
-        option set, adjacencies are also added to entities in <em>entities</em>.
-        \param meshset Mesh set being added to
-        \param entities Range of entities being added to meshset
-    */
-  virtual MBErrorCode add_entities(MBEntityHandle meshset, 
-                                   const MBRange &entities) = 0;
-
-    //! Add to a meshset entities in specified vector
-    /** Add to a meshset entities in specified vector.  If <em>meshset</em> has MESHSET_TRACK_OWNER
-        option set, adjacencies are also added to entities in <em>entities</em>.
-        \param meshset Mesh set being added to
-        \param entities 1d vector of entities being added to meshset
-        \param num_entities Number of entities in 1d vector
-    */
-  virtual MBErrorCode add_entities(MBEntityHandle meshset, 
-                                   const MBEntityHandle *entities,
-                                   const int num_entities) = 0;
-  
-    //! Remove from a meshset entities in specified range
-    /** Remove from a meshset entities in specified range.  If <em>meshset</em> has MESHSET_TRACK_OWNER
-        option set, adjacencies in entities in <em>entities</em> are updated.
-        \param meshset Mesh set being removed from
-        \param entities Range of entities being removed from meshset
-    */
-  virtual MBErrorCode remove_entities(MBEntityHandle meshset, 
-                                      const MBRange &entities) = 0;
-
-    //! Remove from a meshset entities in specified vector
-    /** Remove from a meshset entities in specified vector.  If <em>meshset</em> has MESHSET_TRACK_OWNER
-        option set, adjacencies in entities in <em>entities</em> are updated.
-        \param meshset Mesh set being removed from
-        \param entities 1d vector of entities being removed from meshset
-        \param num_entities Number of entities in 1d vector
-    */
-  virtual MBErrorCode remove_entities(MBEntityHandle meshset, 
-                                      const MBEntityHandle *entities,
-                                      const int num_entities) = 0;
-
-    //! Return whether a set contains entities
-    /** Return whether a set contains entities.  Returns true only
-     * if ALL entities are contained
-     * \param meshset Mesh set being queried
-     * \param entities Entities being queried
-     * \param num_entities Number of entities
-     * \return bool If true, all entities are contained in set
-    */
-  virtual bool contains_entities(MBEntityHandle meshset, 
-                                 const MBEntityHandle *entities,
-                                 int num_entities,
-                                 const int operation_type = MBInterface::INTERSECT) = 0;
-
-    //! Replace entities in a set with other entities
-    /** Replace entities in a set with other entities
-     * 
-     * \note  Behavior is undefined if an entity handle exists in both the
-     *        old_entities and the new_entities arrays or old_entities
-     *        contains multiple copies of an entity.
-     * \note  If an entity occurs multiple times in an ordered set, all
-     *        occurances will be replaced.
-     * \note  For list-based sets, if not all handles in old_entities 
-     *        occcur in the set, the corresponding new_entities will not 
-     *        be added and  MB_ENTITY_NOT_FOUND will be returned.
-     *        For set-based sets, all entities in new_entities wll be
-     *        added and any contained entities in old_entities will be 
-     *        removed, and the return value will be MB_SUCCESS.
-     * \param meshset Mesh set being modified
-     * \param old_entities Entities to replace
-     * \param new_entities New entities to add
-     * \param num_entities Number of entities in input arrays
-     * \return - MB_SUCCESS : all entities in old_entities replaced
-     *         - MB_ENTITY_NOT_FOUND : one or more entities in new_entities 
-     *                        not added to set because corresponding entity
-     *                        in old_entities did not occur in the ordered
-     *                        set.
-     *         - MB_FAILURE : internal error
-    */
-  virtual MBErrorCode replace_entities(MBEntityHandle meshset, 
-                                       const MBEntityHandle *old_entities,
-                                       const MBEntityHandle *new_entities,
-                                       int num_entities) = 0;
-    //@}
-
-    //! \name MeshSet parent/child functions
-
-    //@{
-  
-    //! Get parent mesh sets of a mesh set
-    /** If <em>num_hops</em> is 1, only immediate parents are returned.  If <em>num_hops</em> is zero,
-        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
-        generations to traverse.
-        \param meshset The mesh set whose parents are being queried
-        \param parents STL vector holding the parents returned by this function
-        \param num_hops Number of generations to traverse (0 = all)
-    */
-  virtual MBErrorCode get_parent_meshsets(const MBEntityHandle meshset,
-                                          std::vector<MBEntityHandle> &parents, 
-                                          const int num_hops = 1) const = 0;
-
-    //! Get parent mesh sets of a mesh set
-    /** If <em>num_hops</em> is 1, only immediate parents are returned.  If <em>num_hops</em> is zero,
-        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
-        generations to traverse.
-        \param meshset The mesh set whose parents are being queried
-        \param parents MBRange holding the parents returned by this function
-        \param num_hops Number of generations to traverse (0 = all)
-    */
-  virtual MBErrorCode get_parent_meshsets(const MBEntityHandle meshset,
-                                          MBRange &parents,
-                                          const int num_hops = 1) const = 0;
-
-    //! Get child mesh sets of a mesh set
-    /** If <em>num_hops</em> is 1, only immediate children are returned.  If <em>num_hops</em> is zero,
-        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
-        generations to traverse.
-        \param meshset The mesh set whose children are being queried
-        \param children STL vector holding the children returned by this function
-        \param num_hops Number of generations to traverse (0 = all)
-    */
-  virtual MBErrorCode get_child_meshsets(const MBEntityHandle meshset, 
-                                         std::vector<MBEntityHandle> &children, 
-                                         const int num_hops = 1) const = 0;
-
-    //! Get child mesh sets of a mesh set
-    /** If <em>num_hops</em> is 1, only immediate children are returned.  If <em>num_hops</em> is zero,
-        all ancenstors are returned.  Otherwise, <em>num_hops</em> specifies the maximum number of 
-        generations to traverse.
-        \param meshset The mesh set whose children are being queried
-        \param children MBRange holding the children returned by this function
-        \param num_hops Number of generations to traverse (0 = all)
-    */
-  virtual MBErrorCode get_child_meshsets(const MBEntityHandle meshset, 
-                                         MBRange &children, 
-                                         const int num_hops = 1) const = 0;
-
-    /**\brief Get mesh sets contained in a mesh set
-     *
-     * If <em>num_hops</em> is 1, only immediate contents are returned. 
-     * Otherwise a recursive query of all contained sets is performed, 
-     * returning every visted set.  The value of num_hops limites the
-     * depth of the search, with zero indicating no depth limit. 
-     *
-     *\param meshset The mesh set whose contents are being queried
-     *\param contained The result list.
-     *\param num_hops Number of generations to traverse (0 = all)
-     */
-  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
-                                         std::vector<MBEntityHandle> &contained, 
-                                         const int num_hops = 1) const = 0;
-
-    /**\brief Get mesh sets contained in a mesh set
-     *
-     * If <em>num_hops</em> is 1, only immediate contents are returned. 
-     * Otherwise a recursive query of all contained sets is performed, 
-     * returning every visted set.  The value of num_hops limites the
-     * depth of the search, with zero indicating no depth limit. 
-     *
-     *\param meshset The mesh set whose contents are being queried
-     *\param contained The result list.
-     *\param num_hops Number of generations to traverse (0 = all)
-     */
-  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
-                                             MBRange &contained, 
-                                             const int num_hops = 1) const = 0;
-
-    //! Get the number of parent mesh sets of a mesh set
-    /** Identical to get_parent_meshsets, only number is returned instead of actual parents.
-        \param meshset The mesh set whose parents are being queried
-        \param number Number of parents
-    */
-  virtual MBErrorCode num_parent_meshsets(const MBEntityHandle meshset,  
-                                          int *number,
-                                          const int num_hops = 1) const = 0;
-
-    //! Get the number of child mesh sets of a mesh set
-    /** Identical to get_child_meshsets, only number is returned instead of actual children.
-        \param meshset The mesh set whose children are being queried
-        \param number Number of children
-    */
-  virtual MBErrorCode num_child_meshsets(const MBEntityHandle meshset, 
-                                         int *number,
-                                         const int num_hops = 1) const = 0;
-
-    /**\brief Get the number of mesh sets contained in a mesh set
-     *
-     * Return the number of sets that would be returned by get_contained_meshsets
-     *
-     *\param meshset  The initial set to begin the query from.
-     *\param number   (Output) The result count.
-     *\param num_hops Search depth (0 => unbounded).
-     */
-  virtual MBErrorCode num_contained_meshsets(const MBEntityHandle meshset, 
-                                             int *number,
-                                             const int num_hops = 1) const = 0;
-
-    //! Add a parent mesh set to a mesh set
-    /** Make <em>parent_meshset</em> a new parent of <em>child_meshset</em>.  This function does 
-        <em>not</em> add a corresponding child link to <em>parent_meshset</em>.
-        \param child_meshset The child mesh set being given a new parent.
-        \param parent_meshset The parent being added to <em>child_meshset</em>
-    */
-  virtual MBErrorCode add_parent_meshset(MBEntityHandle child_meshset, 
-                                         const MBEntityHandle parent_meshset) = 0;
-
-    //! Add a parent mesh sets to a mesh set
-    /** Make <em>parent_meshset</em> a new parent of <em>child_meshset</em>.  This function does 
-        <em>not</em> add a corresponding child link to <em>parent_meshset</em>.
-        \param child_meshset The child mesh set being given a new parent.
-        \param parent_meshset The parent being added to <em>child_meshset</em>
-    */
-  virtual MBErrorCode add_parent_meshsets(MBEntityHandle child_meshset, 
-                                          const MBEntityHandle* parent_meshsets,
-                                          int num_parent_meshsets ) = 0;
-
-    //! Add a child mesh set to a mesh set
-    /** Make <em>child_meshset</em> a new child of <em>parent_meshset</em>.  This function does 
-        <em>not</em> add a corresponding parent link to <em>child_meshset</em>.
-        \param parent_meshset The parent mesh set being given a new child.
-        \param child_meshset The child being added to <em>parent_meshset</em>
-    */
-  virtual MBErrorCode add_child_meshset(MBEntityHandle parent_meshset, 
-                                        const MBEntityHandle child_meshset) = 0;
-
-    //! Add a child mesh sets to a mesh set
-    /** Make <em>child_meshset</em> a new child of <em>parent_meshset</em>.  This function does 
-        <em>not</em> add a corresponding parent link to <em>child_meshset</em>.
-        \param parent_meshset The parent mesh set being given a new child.
-        \param child_meshset The child being added to <em>parent_meshset</em>
-    */
-  virtual MBErrorCode add_child_meshsets(MBEntityHandle parent_meshset, 
-                                         const MBEntityHandle* child_meshsets,
-                                         int num_child_meshsets ) = 0;
-
-    //! Add parent and child links between mesh sets
-    /** Makes <em>child_meshset</em> a new child of <em>parent_meshset</em>, and vica versa.
-        \param parent The parent mesh set being given a new child, and the new parent
-        \param child The child being given a new parent, and the new child
-    */
-  virtual MBErrorCode add_parent_child( MBEntityHandle parent, 
-                                        MBEntityHandle child ) = 0;
-
-    //! Remove parent and child links between mesh sets
-    /** Removes parent/child links between <em>child_meshset</em> and <em>parent_meshset</em>.
-        \param parent The parent mesh set being removed from <em>child</em>
-        \param child The child mesh set being removed from <em>parent</em>
-    */
-  virtual MBErrorCode remove_parent_child( MBEntityHandle parent, 
-                                           MBEntityHandle child ) = 0;
-
-    //! Remove a parent mesh set from a mesh set
-    /** Removes <em>parent_meshset</em> from the parents of <em>child_meshset</em>.  This function does 
-        <em>not</em> remove a corresponding child link from <em>parent_meshset</em>.
-        \param child_meshset The child mesh whose parent is being removed
-        \param parent_meshset The parent being removed from <em>meshset</em>
-    */
-  virtual MBErrorCode remove_parent_meshset(MBEntityHandle child_meshset, 
-                                            const MBEntityHandle parent_meshset) = 0;
-  
-    //! Remove a child mesh set from a mesh set
-    /** Removes <em>child_meshset</em> from the children of <em>parent_meshset</em>.  This function does 
-        <em>not</em> remove a corresponding parent link from <em>child_meshset</em>.
-        \param parent_meshset The parent mesh set whose child is being removed
-        \param child_meshset The child being removed from <em>parent_meshset</em>
-    */
-  virtual MBErrorCode remove_child_meshset(MBEntityHandle parent_meshset, 
-                                           const MBEntityHandle child_meshset) = 0;
-
-    //@}
-
-    //! \name Error condition information 
-
-    //@{
-
-    //! Return information about the last error
-    /** \param info std::string into which information on the last error is written.
-     */
-  virtual MBErrorCode get_last_error(std::string& info) const = 0;
-
-    //! Return string representation of given error code
-    /** \param code Error code for which string is wanted
-     */
-  virtual std::string get_error_string(const MBErrorCode code) const = 0;
-
-    //@}
-
-  /**\brief Calculate amount of memory used to store MOAB data
-   *
-   * This function calculates the amount of memory used to store
-   * MOAB data.  
-   *
-   * There are two possible values for each catagory of memory use.
-   * The exact value and the amortized value.  The exact value is the
-   * amount of memory used to store the data for the specified entities.
-   * The amortized value includes the exact value and an amortized 
-   * estimate of the memory consumed in overhead for storing the values
-   * (indexing structures, access structures, etc.)  
-   *
-   * Note: If ent_array is NULL and total_amortized_storage is *not* NULL,
-   *       the total memory used by MOAB for storing data all will be 
-   *       returned in the address pointed to by total_amortized_storage.
-   *
-   *\param ent_array Array of entities for which to estimate the memory use.
-   *                 If NULL, estimate is done for all entities.
-   *\param num_ents The length of ent_array.  Not used if ent_rray is NULL.
-   *\param total_(amortized_)storage The sum of the memory entity, adjacency,
-   *                   and all tag storage.
-   *\param (amortized_)entity_storage The storage for the entity definitions
-   *                   (connectivity arrays for elements, coordinates for 
-   *                   vertices, list storage within sets, etc.)
-   *\param (amortized_)adjacency_storage The storage for adjacency data.
-   *\param tag_array   An array of tags for which to calculate the memory use.
-   *\param num_tags    The lenght of tag_array
-   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
-   *                   for each tag specifying the memory used for storing 
-   *                   that tag.  If tag_array is NULL and this value is not,
-   *                   the location at which to store the total memory used
-   *                   for all tags.
-   */
-  virtual void estimated_memory_use( const MBEntityHandle* ent_array = 0,
-                             unsigned long  num_ents = 0,
-                             unsigned long* total_storage = 0,
-                             unsigned long* total_amortized_storage = 0,
-                             unsigned long* entity_storage = 0,
-                             unsigned long* amortized_entity_storage = 0,
-                             unsigned long* adjacency_storage = 0,
-                             unsigned long* amortized_adjacency_storage = 0,
-                             const MBTag*   tag_array = 0,
-                             unsigned       num_tags = 0,
-                             unsigned long* tag_storage = 0,
-                             unsigned long* amortized_tag_storage = 0 ) = 0;
-
-  /**\brief Calculate amount of memory used to store MOAB data
-   *
-   * This function calculates the amount of memory used to store
-   * MOAB data.  
-   *
-   * There are two possible values for each catagory of memory use.
-   * The exact value and the amortized value.  The exact value is the
-   * amount of memory used to store the data for the specified entities.
-   * The amortized value includes the exact value and an amortized 
-   * estimate of the memory consumed in overhead for storing the values
-   * (indexing structures, access structures, etc.)  
-   *
-   *\param ents        Entities for which to estimate the memory use.
-   *\param total_(amortized_)storage The sum of the memory entity, adjacency,
-   *                   and all tag storage.
-   *\param (amortized_)entity_storage The storage for the entity definitions
-   *                   (connectivity arrays for elements, coordinates for 
-   *                   vertices, list storage within sets, etc.)
-   *\param (amortized_)adjacency_storage The storage for adjacency data.
-   *\param tag_array   An array of tags for which to calculate the memory use.
-   *\param num_tags    The lenght of tag_array
-   *\param (amortized_)tag_storage If tag_array is not NULL, then one value
-   *                   for each tag specifying the memory used for storing 
-   *                   that tag.  If tag_array is NULL and this value is not,
-   *                   the location at which to store the total memory used
-   *                   for all tags.
-   */
-  virtual void estimated_memory_use( const MBRange& ents,
-                             unsigned long* total_storage = 0,
-                             unsigned long* total_amortized_storage = 0,
-                             unsigned long* entity_storage = 0,
-                             unsigned long* amortized_entity_storage = 0,
-                             unsigned long* adjacency_storage = 0,
-                             unsigned long* amortized_adjacency_storage = 0,
-                             const MBTag*   tag_array = 0,
-                             unsigned       num_tags = 0,
-                             unsigned long* tag_storage = 0,
-                             unsigned long* amortized_tag_storage = 0 ) = 0;
-};
-
-//! predicate for STL algorithms.  Returns true if the entity handle is
-//! of the specified type.  For example, to remove all the tris out of a list
-//! of 2D entities retrieved using get_adjacencies you could do
-//! \example std::remove_if(list.begin(), list.end(), type_equals(gMB, MeshTri));
-class type_equals : public std::unary_function<MBEntityHandle, bool>
-{
-public:
-    //! interface object
-  MBInterface* meshDB;
-
-    //! type corresponding to this predicate
-  const MBEntityType test_type;
-
-    //! Constructor
-  type_equals(MBInterface* mdb, const MBEntityType type) : meshDB(mdb), test_type(type){}
-
-    //! operator predicate
-  bool operator()(MBEntityHandle handle) const
-    { 
-      return (meshDB->type_from_handle(handle) ==  test_type); 
-    } 
-};
-
-//! predicate for STL algorithms.  Returns true if the entity handle is not
-//! of the specified type.  For example, to remove all but the tris out of a list
-//! of 2D entities retrieved using get_adjacencies you could do
-//! \example std::remove_if(list.begin(), list.end(), type_not_equals(gMB, MeshTri));
-class type_not_equals : public std::unary_function<MBEntityHandle, bool>
-{
-public:
-
-    //! interface object
-  MBInterface* meshDB;
-
-    //! type corresponding to this predicate
-  const MBEntityType test_type;
-
-    //! Constructor
-  type_not_equals(MBInterface* mdb, const MBEntityType type) : meshDB(mdb), test_type(type){}
-
-    //! operator predicate
-  bool operator()(MBEntityHandle handle) const
-    { 
-      return (meshDB->type_from_handle(handle) !=  test_type); 
-    } 
-};
-
-inline float MBInterface::api_version(std::string *version_string) 
-{
-  if (NULL != version_string)
-    *version_string = std::string("MOAB API version ") + std::string(MOAB_API_VERSION_STRING);
-  return MOAB_API_VERSION;
-}
-
-
-#endif   // MB_INTERFACE_HPP
-
-  

Deleted: MOAB/trunk/src/moab/MBOrientedBoxTreeTool.hpp
===================================================================
--- MOAB/trunk/src/moab/MBOrientedBoxTreeTool.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBOrientedBoxTreeTool.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,422 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\file MBOrientedBoxTreeTool.hpp
- *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
- *\date 2006-07-18
- */
-
-#ifndef MB_ORIENTED_BOX_TREE_TOOL_HPP
-#define MB_ORIENTED_BOX_TREE_TOOL_HPP
-
-#include "MBForward.hpp"
-
-#include <iosfwd>
-#include <list>
-#include <vector>
-
-class MBRange;
-class MBOrientedBox;
-
-class MBOrientedBoxTreeTool
-{
-  public:
-  
-    /**\brief Misc. knobs controlling tree subdivision
-     *
-     * Available settings for controlling when and how nodes in the tree
-     * are split.  The constructor will initialize to the default
-     * settings.  All settings except best_split_ratio control when
-     * a node is subdivided.  best_split_ratio influences the choice
-     * of how the node is subdivided.
-     *
-     * A calculated ratio is used in the determination of when and how
-     * to split a node.  The ratio is calculated as:
-     * - \f$max(\frac{|n_L - n_R|}{n_L+n_R}, f*\frac{n_I}{n_L+n_R})\f$
-     * - \f$n_L\f$ : num entities to be placed in left child
-     * - \f$n_R\f$ : num entities to be placed in right child
-     * - \f$f\f$ : Settings::intersect_ratio_factor
-     * - \f$n_I\f$: num entities intersecting split plane
-     *
-     * ALL of the following conditions must be met for a node to be further
-     * subdivied:
-     *  - Depth must be less than max_depth
-     *  - Node must contain more than max_leaf_entities entities.
-     *  - The 'ratio' must be less than worst_split_ratio
-     *
-     * The node will be subdivided using a plane normal to one of the
-     * box axis and containing the box center.  The planes are tested 
-     * beginning with the one orthogonal to the longest box axis and
-     * finishing with the one orthogonal to the shortest box axis.  The
-     * search will stop at the first plane for which the 'ratio' is
-     * at least Settings::best_split_ratio .  Giving Settings::best_split_ratio
-     * a non-zero value gives preference to a split orthogonal to larger
-     * box dimensions.
-     */
-    struct Settings {
-      public:
-        Settings();              //!< set defaults
-        int max_leaf_entities;   //!< Average number of entities per leaf
-        int max_depth;           //!< Maximum tree depth - 0->no limit
-        //! Must be in [best_split_ratio,1.0]
-        //! A tree node will not be split if the ratio of children
-        //! in the child nodes is greater than this value.
-        double worst_split_ratio;
-        //! Must be in [0.0,worst_split_ratio]
-        //! The search for an optimal split plane for splitting a node
-        //! will stop if at least this ratio is achieved for the number of
-        //! entities on each side of the split plane.
-        double best_split_ratio;
-        //! Flags used to create entity sets representing tree nodes
-        unsigned int set_options;
-        //! Check if settings are valid.
-        bool valid() const;
-    };
-  
-    MBOrientedBoxTreeTool( MBInterface* i, 
-                           const char* tag_name = 0,
-                           bool destroy_created_trees = false ) ;
-  
-    ~MBOrientedBoxTreeTool();
-  
-    /**\brief Build oriented bounding box tree
-     *
-     * Build an oriented bounding box tree.  
-     *\param entities A list of either vertices or 2-D elements (not both)
-     *                for which to build a tree.
-     *\param set_handle_out A handle for the entity set representing the
-     *                root of the tree.
-     */
-    MBErrorCode build( const MBRange& entities, 
-                       MBEntityHandle& set_handle_out,
-                       const Settings* settings = 0 );
-     
-    /**\brief Build a tree of sets, where each set contains triangles.
-     *
-     * Build a tree of sets.  Each set must contain at least one triangle
-     * to define its geometry.  Each passed set will become a leaf of
-     * the OBB tree.  Settings controlling tree depth are ignored by
-     * this method.  The tree will be as deep as it needs to be for each
-     * input set to be a leaf.
-     *
-     * To build a tree representing the surfaces of a geometric volume,
-     * 1) Build an OBB tree for each surface using the 'build' method
-     * 2) Add each surface to the contents of the resulting OBB tree root set
-     * 3) Build a tree from all the surface OBB tree root sets using this
-     *    method to get a combined tree for the volume.
-     */
-    MBErrorCode join_trees( const MBRange& tree_roots,
-                            MBEntityHandle& root_set_out,
-                            const Settings* settings = 0 );
-
-    /**\brief Traversal statistics structure
-     *
-     * Structure to accumulate statistics on traversal performance. Passed optionally
-     * to query functions, this structure contains the count of nodes visited at each
-     * level in a tree, and the count of traversals that ended at each level.
-     * One TrvStats structure can be used with multiple OBB trees or multiple queries,
-     * or used on only a single tree or a single query.
-     *
-     * Note that these traversal statistics are not related to the stats() query below,
-     * which calculates static information about a tree.  These statistics relate
-     * to a tree's dynamic behavior on particular operations.
-     */
-    class TrvStats{ 
-      public:
-
-        //! return counts of nodes visited, indexed by tree depth.  
-        //! the counts include both leaves and interior nodes
-        const std::vector< unsigned >& nodes_visited() const
-        { return nodes_visited_count; }
-        //! return counts of tree leaves visited, indexed by tree depth
-        const std::vector< unsigned >& leaves_visited() const
-        { return leaves_visited_count; }
-        //! return counts of traversals ended, indexed by tree depth
-        const std::vector< unsigned >& traversals_ended() const 
-        { return traversals_ended_count; }        
-        //! reset all counters on this structure
-        void reset();
-        //! print the contents of this structure to given stream
-        void print( std::ostream& str ) const ;
-
-      private: 
-      
-        std::vector< unsigned > nodes_visited_count;
-        std::vector< unsigned > leaves_visited_count;
-        std::vector< unsigned > traversals_ended_count;
-        
-        void increment( unsigned depth );
-        void increment_leaf( unsigned depth );
-        void end_traversal( unsigned depth );
-
-      friend class MBOrientedBoxTreeTool;
-
-    };
-
-
-    /**\brief Intersect a ray with the triangles contained within the tree
-     *
-     * Intersect a ray with the triangles contained in the tree and return
-     * the distance at which the intersection occured.
-     *\param distances_out The output list of intersection points on the ray.
-     *\param root_set      The MBENTITYSET representing the root of the tree.
-     *\param tolerance     The tolerance to use in intersection checks.
-     *\param ray_point     The base point of the ray.
-     *\param unit_ray_dir  The ray direction vector (must be unit length)
-     *\param ray_length    Optional ray length (intersect segment instead of ray.)
-     */
-    MBErrorCode ray_intersect_triangles( std::vector<double>& distances_out,
-                                         MBEntityHandle root_set,
-                                         double tolerance,
-                                         const double ray_point[3],
-                                         const double unit_ray_dir[3],
-                                         const double* ray_length = 0,
-                                         TrvStats* accum = 0 );
-    
-    /**\brief Intersect ray with tree
-     *
-     * Return the tree nodes (as MBENTITYSET handles) for the leaf boxes
-     * of the tree intersected by a ray.
-     *\param boxes_out    The boxes intersected by the ray.
-     *\param tolerance     The tolerance to use in intersection checks.
-     *\param ray_point     The base point of the ray.
-     *\param unit_ray_dir  The ray direction vector (must be unit length)
-     *\param ray_length    Optional ray length (intersect segment instead of ray.)
-     */
-    MBErrorCode ray_intersect_boxes( MBRange& boxes_out,
-                                     MBEntityHandle root_set,
-                                     double tolerance,
-                                     const double ray_point[3],
-                                     const double unit_ray_dir[3],
-                                     const double* ray_length = 0,
-                                     TrvStats* accum = 0 );
-
-    /**\brief Intersect ray with triangles contained in passed MBENTITYSETs */
-    MBErrorCode ray_intersect_triangles( 
-                          std::vector<double>& intersection_distances_out,
-                          const MBRange& leaf_boxes_containing_tris,
-                          double tolerance,
-                          const double ray_point[3],
-                          const double unit_ray_dir[3],
-                          const double* ray_length = 0);
-                          
-
-    /**\brief Intersect a ray with the triangles contained within the tree
-     *
-     * Intersect a ray with the triangles contained in the tree and return
-     * the distance at which the intersection occured.
-     *\param distances_out The output list of intersection points on the ray.
-     *\param sets_out      The contained set encountered during the tree traversal
-     *                     (see 'set_build').  For the most common use, this is the
-     *                     set corresponding to the geometric surface containing the
-     *                     intersected triangle.
-     *\param root_set      The MBENTITYSET representing the root of the tree.
-     *\param min_tolerance_intersections This method returns all intersections
-     *                     within 'tolerance' of the start of the ray and if 
-     *                     the number of intersections within the 'tolerance' of the
-     *                     ray start point is less than this number, the next closest
-     *                     intersection.  If the desired result is only the closest
-     *                     intersection, pass zero for this argument.
-     *\param tolerance     The tolerance to use in intersection checks.
-     *\param ray_point     The base point of the ray.
-     *\param unit_ray_dir  The ray direction vector (must be unit length)
-     *\param ray_length    Optional ray length (intersect segment instead of ray.)
-     */
-    MBErrorCode ray_intersect_sets( std::vector<double>& distances_out,
-                                    std::vector<MBEntityHandle>& sets_out,
-                                    std::vector<MBEntityHandle>& facets_out,
-                                    MBEntityHandle root_set,
-                                    double tolerance,
-                                    unsigned min_tolerace_intersections,
-                                    const double ray_point[3],
-                                    const double unit_ray_dir[3],
-                                    const double* ray_length = 0,
-                                    TrvStats* accum = 0 );
-    
-    /**\brief Find closest surface, facet in surface, and location on facet
-     *
-     * Find the closest location in the tree to the specified location.
-     *\param point Location to search from
-     *\param point_out Closest location on closest facet
-     *\param facet_out Closest 2D element to input position
-     *\param set_out Set containing closest facet.  0 if tree was not 
-     *               constructed using 'set_build'
-     */
-    MBErrorCode closest_to_location( const double* point,
-                                     MBEntityHandle tree_root,
-                                     double* point_out,
-                                     MBEntityHandle& facet_out,
-                                     MBEntityHandle* set_out = 0, 
-                                     TrvStats* accum = 0 );
-                                     
-    /**\brief Find closest facet(s) to input position.
-     *
-     * Find the closest location(s) in the tree to the specified location.
-     *\param point Location to search from
-     *\param facets_out Closest 2D elements to input position are appended to this list
-     *\param sets_out If non-null, sets owning facets are appended to this list.
-     */
-    MBErrorCode closest_to_location( const double* point,
-                                     MBEntityHandle tree_root,
-                                     double tolerance,
-                                     std::vector<MBEntityHandle>& facets_out,
-                                     std::vector<MBEntityHandle>* sets_out = 0, 
-                                     TrvStats* accum = 0 );
-    
-    /**\brief Find facets intersected by a sphere 
-     *
-     * Find facets intersected by a spherical volume.
-     *\param center     Sphere center
-     *\param radius     Sphere radius
-     *\param tree_root  Root of OBB tree
-     *\param facets_out List of triangles intersecting sphere
-     *\param sets_out   If not null, sets owning facets are appended to this
-     *                  list in an order corresponding to the entries in 
-     *                  facets_out.
-     */
-    MBErrorCode sphere_intersect_triangles( const double* center,
-                                        double radius,
-                                        MBEntityHandle tree_root,
-                                        std::vector<MBEntityHandle>& facets_out,
-                                        std::vector<MBEntityHandle>* sets_out = 0, 
-                                        TrvStats* accum = 0 );
-    
-    /**\brief Get oriented box at node in tree
-     *
-     * Get the oriented box for a node in an oriented bounding box tree.
-     */
-    MBErrorCode box( MBEntityHandle node_set,
-                     MBOrientedBox& box );
-    
-    /**\brief Get oriented box at node in tree
-     *
-     * Get the oriented box for a node in an oriented bounding box tree.
-     */
-    MBErrorCode box( MBEntityHandle node_set,
-                     double center[3],
-                     double axis1[3],
-                     double axis2[3],
-                     double axis3[3] );
-                         
-    MBErrorCode delete_tree( MBEntityHandle root_set );
-
-    /**\brief Print out tree
-     *
-     * Print the tree to an output stream in a human-readable form.
-     *\param tree_root_set  Entity set representing tree root.
-     *\param list_contents  If true, list entities in each tree node,
-     *                      If false, just list number of entities.
-     *\param id_tag_name    If specified, must be the name of an existing
-     *                      integer tag containing an ID for the entities.
-     *                      Not used if list_contents is false.
-     */
-    void print( MBEntityHandle tree_root_set, 
-                std::ostream& stream,
-                bool list_contents = false,
-                const char* id_tag_name = 0 );
-                
-    /**\brief Print tree statistics
-     *
-     * Print misc. stats. describing tree
-     */
-    MBErrorCode stats( MBEntityHandle tree_root_set, std::ostream& stream );
-  
-    /**\brief Get tree statistics
-     *
-     * Get summary stats. describing tree
-     * \param set Root of tree for which data is requested
-     * \param total_entities Entities in tree
-     * \param root_volume Total volume of root box
-     * \param tot_node_volume Total volume in all nodes
-     * \param tot_to_root_volume Ratio of total / root volume
-     * \param tree_height Maximum height of tree, from root to leaf
-     * \param node_count Number of nodes in tree
-     * \param num_leaves Number of leaf nodes in tree
-     */
-  MBErrorCode stats( MBEntityHandle set, 
-                     unsigned &entities_in_tree,
-                     double &root_volume,
-                     double &tot_node_volume,
-                     double &tot_to_root_volume,
-                     unsigned &tree_height,
-                     unsigned &node_count,
-                     unsigned &num_leaves);
-  
-    /** \brief Implement this and pass instance to preorder_traverse
-     * 
-     * This interface may be implemented and an instance passed to
-     * preorder_traverse to define some operation to do when traversing
-     * the tree.
-     */
-    class Op {
-      public:
-
-        /**\brief Visit a node in the tree during a traversal.
-         *
-         * This method is called for each node in the tree visited
-         * during a pre-order traversal.  
-         *\param node The MBEntityHandle for the entity set for the tree node.
-         *\param depth The current depth in the tree.
-         *\param descend Output: if false, traversal will skip children
-         *             of the current node, or if the current node is a
-         *             leaf, the 'leaf' method will not be called.
-         */
-        virtual MBErrorCode visit( MBEntityHandle node,
-                                   int depth,
-                                   bool& descend ) = 0;
-       
-        /**\brief Process a leaf node during tree traversal */
-        virtual MBErrorCode leaf( MBEntityHandle node ) = 0;
-
-        virtual ~Op(); // probably isn't necessary in this case, and
-                       // does nothing, but lots of compilers warn if
-                       // virtual function but no virtual destructor.
-    };
-    
-    /**\brief Visitor pattern - do operation for each tree node
-     *
-     * Do a preorder traversal of the tree, calling the method
-     * in the passed operation instance for each node in the tree.
-     * Parent node is visited before either child (pre-order traversal).
-     * If operator method passes back the 'descend' argument as false,
-     * traversal will not descend to the children of the current node.
-     */
-    MBErrorCode preorder_traverse( MBEntityHandle root_set,
-                                   Op& operation, 
-                                   TrvStats* accum = 0 );
-  
-    MBInterface* get_moab_instance() const { return instance; }
-  
-    struct SetData;
-  private:
-  
-    MBErrorCode build_tree( const MBRange& entities, 
-                            MBEntityHandle& set, 
-                            int depth,
-                            const Settings& settings );
-  
-    MBErrorCode build_sets( std::list<SetData>& sets,
-                            MBEntityHandle& node_set,
-                            int depth,
-                            const Settings& settings );
-  
-    MBInterface* instance;
-    MBTag tagHandle;
- 
-    bool cleanUpTrees;
-    std::vector<MBEntityHandle> createdTrees;
-};
-
-#endif

Deleted: MOAB/trunk/src/moab/MBRange.hpp
===================================================================
--- MOAB/trunk/src/moab/MBRange.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBRange.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,803 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBRange
- *
- * Stores contiguous or partially contiguous values in an optimized
- * fashion.  Partially contiguous accessing patterns is also optimized.
- *
- * \author Clinton Stimpson
- *
- * \date 15 April 2002
- *
- */
-
-
-/*
- *************  MBRange FAQ and tips ********************
-
- The purpose of this FAQ is to familiarize a user with
- the appropriate use of the MBRange template.
-
-   ******* A few points about MBRange: *******
- 1.  MBRange is not the be all of generic containers.
- 2.  MBRange has its strengths and weakneses as any other
-     STL container has.
- 3.  Strengths:
-     a. For contiguous values, storage is extremely minimal.
-     b. Searching through contiguous values, at best, is
-        a constant time operation.
-     b. Fairly compatible with most STL algorithms.
-     c. Insertions of data from high value to low value
-        is a linear operation (constant for each insertion).
-     d. Removal of a value using an iterator is constant time.
-
- 4.  Weaknesses:
-     a. For non-contiguous values, storage is not minimal and is
-        on the order of 4x the storage space as using a vector.
-     b. Searching through non-contiguous values is linear
-        time operation.
-     c. Insertions of random data is VERY slow.
-
-   Given the above characteristics of MBRanges, you can now
-   decide between MBRange and another STL container for your
-   particular needs.
-
-
-   ******* Tips *******
- 1.  Be aware of what iterators are available.  Currently, there are
-     three.  MBRange<T>::iterator, MBRange<T>::const_iterator,
-     and MBRange<T>::RangeListIterator.
-     iterator is derived from const_iterator.  const_iterator
-     is derived from RangeListIterator.  RangeListIterator is a
-     std::list<std::pair<T,T> >::const_iterator.
-     If a particular algorithm could be more efficient by using
-     RangeListIterator, do so.
-
-     ie.
-     
-     MBRange<char> range1;
-     ... put some stuff in range1
-     MBRange<char> range2;
-     
-     // the SLOW way.
-     std::copy(range1.begin(), range1.end(), mb_range_inserter<...>(range2));
-
-     // the FAST way.
-     for(MBRange<char>::RangeListIterator iter = range1.begin(),
-         iter != range1.end(); ++iter)
-     {
-       range2.insert(iter->first, iter->second);
-     }
-
- 2.  Prefer insert(val1, val2) over insert(val) where possible.
- 
- 3.  insert(val) and insert(val1, val2) have to perform searching
-     to find out where to insert an item.  Searches are started
-     from the beginning of the values.  Inserting larger values 
-     before smaller values will increase efficiency.
-
-     ie.
-     std::set<int> my_set;
-     MBRange<int> my_range;
-     .. perform some operations which set does efficiently.
-
-     // now copy the results from the set into the range.
-     // copy from the end of the set to the beginning of the set
-     std::copy(my_set.rbegin(), my_set.rend(), 
-         mb_range_inserter< MBRange<int> > ( my_range );
-
- 4.  Use empty() instead of size() if you only need to find out
-     if there is anything in the list.
-
- 5.  Know what swap() does.  Sometimes it is useful.  It'll replace
-     the contents of one list with another.
-
-     void compute_and_get_some_set( 
-         MBRange<char> range1, 
-         MBRange<char> range2,
-         MBRange<char>& results
-         );
-     {
-       MBRange<char> tmp_results;
-       .. perform some computation on range1 and range2
-          and put results in tmp_results;
-       .. filter tmp_results out for some special type.
-       .. etc....
-       // return results
-       results.swap(tmp_results);
-     }
-
-
-   ******* FAQ *******
- 1. Why won't this code compile?
-    ------------------------
-    class SomeClass
-    {
-    public:
-      MBRange<int> range;
-    };
-    ....
-    void some_function( const SomeClass& some_class )
-    {
-      MBRange<int>::iterator = some_class.range.begin();
-    }
-    ---------------------
-    Solution:  you need to use
-    MBRange<int>::const_iterator instead.
-
- 2. Why doesn't this work right when I try to change the
-    contents of an MBRange?
-
-    // make a range that has the letters A,B,C in it.
-    MBRange<char> my_chars('A', 'C');
-    // make an iterator that points to 'A'.
-    MBRange<char>::iterator iter = my_chars.begin();
-    // change A to D
-    *iter = 'D';
-    // print contents of my_chars to stdout
-    std::copy(my_chars.begin(), my_chars.end(),
-              std::ostream_iterator(std::cout, " "));
-
-    result is 
-      A B C
-    instead of
-      B C D
-
-    When one calls *iter, which returns 'A', the actual storage of the value 'A' 
-    which is returned is in the iterator and not in the MBRange.  This allows
-    for multiple iterators on a single MBRange and the MBRange does not have
-    to keep track of which iterator is referencing which value.
-
-
-
-*/
-
-
-#ifndef MB_RANGE_HPP
-#define MB_RANGE_HPP
-
-#include <iterator>
-#include <iosfwd>
-#include "MBTypes.h"
-
-struct range_iter_tag : public std::bidirectional_iterator_tag {};
-
-struct range_base_iter
-{
-  typedef range_iter_tag iterator_category;
-  typedef MBEntityID difference_type;
-  typedef MBEntityHandle value_type;
-  typedef MBEntityHandle* pointer;
-  typedef MBEntityHandle& reference;
-};
-
-
-//! the class MBRange
-class MBRange
-{
-public:
-
-    // forward declare the iterators
-  class const_iterator;
-  class const_reverse_iterator;
-  typedef const_iterator iterator;
-  typedef const_reverse_iterator reverse_iterator;
- 
-  friend MBRange intersect( const MBRange&, const MBRange& );
-  friend MBRange subtract( const MBRange&, const MBRange& );
-
-  //! for short hand notation, lets typedef the 
-  //! container class that holds the ranges
-  typedef MBEntityHandle value_type;
-
-  //! default constructor
-  MBRange();
-
-    //! copy constructor
-  MBRange(const MBRange& copy);
-
-  //! another constructor that takes an initial range
-  MBRange( MBEntityHandle val1, MBEntityHandle val2 );
-
-    //! operator=
-  MBRange& operator=(const MBRange& copy);
-  
-  //! destructor
-  ~MBRange();
-
-  //! return the beginning const iterator of this range
-  inline const_iterator begin() const;
-  
-  //! return the beginning const reverse iterator of this range
-  inline const_reverse_iterator rbegin() const;
- 
-  //! return the ending const iterator for this range
-  inline const_iterator end() const;
-  
-  //! return the ending const reverse iterator for this range
-  inline const_reverse_iterator rend() const;
-
-  //! return the number of values this Ranges represents
-  MBEntityHandle size() const;
-
-  //! return the number of range pairs in the list
-  MBEntityHandle psize() const;
-  
-  //! return whether empty or not 
-  //! always use "if(!Ranges::empty())" instead of "if(Ranges::size())"
-  inline bool empty() const;
-
-  iterator insert( iterator hint, MBEntityHandle val );
-
-  //! insert an item into the list and return the iterator for the inserted item
-  iterator insert(MBEntityHandle val)
-    { return insert( begin(), val ); }
-  
-  //! insert a range of items into this list and return the iterator for the first
-  //! inserted item
-  iterator insert( iterator hint, MBEntityHandle first, MBEntityHandle last );
-  
-  //! insert a range of items into this list and return the iterator for the first
-  //! inserted item
-  iterator insert(MBEntityHandle val1, MBEntityHandle val2)
-    { return insert( begin(), val1, val2 ); }
-  
-    //! remove an item from this list and return an iterator to the next item
-  iterator erase(iterator iter);
-
-  //! remove a range of items from the list
-  iterator erase( iterator iter1, iterator iter2);
-
-  //! erases a value from this container
-  inline iterator erase(MBEntityHandle val);
-  
-  //! get first entity in range
-  inline const MBEntityHandle& front() const;
-  //! get last entity in range
-  inline const MBEntityHandle& back() const;
-  //! remove first entity from range
-  MBEntityHandle pop_front();
-  //! remove last entity from range
-  MBEntityHandle pop_back();
-  
-  //! find an item int the list and return an iterator at that value
-  const_iterator find(MBEntityHandle val) const;
-
-  //! return an iterator to the first value >= val
-  static const_iterator lower_bound(const_iterator first,
-                                    const_iterator last,
-                                    MBEntityHandle val);
-  static const_iterator upper_bound(const_iterator first,
-                                    const_iterator last,
-                                    MBEntityHandle val);
-  
-  const_iterator lower_bound( MBEntityHandle val ) const 
-    { return lower_bound( begin(), end(), val ); }
-  const_iterator upperbound( MBEntityHandle val ) const 
-    { return upper_bound( begin(), end(), val ); }
-  const_iterator lower_bound( MBEntityType type ) const;
-  const_iterator upper_bound( MBEntityType type ) const;
-  std::pair<const_iterator, const_iterator> equal_range( MBEntityType type ) const;
-  const_iterator lower_bound( MBEntityType type, const_iterator first ) const;
-  const_iterator upper_bound( MBEntityType type, const_iterator first ) const;
-  
-  //! True if all entities in range are of passed type 
-  //! (also true if range is empty)
-  bool all_of_type( MBEntityType type ) const;
-  //! True if all entities in range are of passed dimension 
-  //! (also true if range is empty)
-  bool all_of_dimension( int dimension ) const;
-  
-  unsigned num_of_type( MBEntityType type ) const;
-  unsigned num_of_dimension( int dim ) const;
-  
-  //! clears the contents of the list 
-  void clear();
-  
-  //! for debugging
-  void print(const char *indent_prefix = NULL) const;
-  void print(std::ostream& s, const char *indent_prefix = NULL) const;
-  
-  unsigned long get_memory_use() const;
-
-  //! merges this MBRange with another range
-  void merge( const MBRange& range );
-  
-  //! merge a subset of some other range
-  void merge( MBRange::const_iterator begin,
-              MBRange::const_iterator end );
-
-  //! swap the contents of this range with another one
-  void swap( MBRange &range );
-
-    //! check for internal consistency
-  void sanity_check() const;
-
-    //! return a subset of this range, by type
-  MBRange subset_by_type(MBEntityType t) const;
-  
-  struct PairNode : public std::pair<MBEntityHandle,MBEntityHandle>
-  {
-
-    PairNode() : std::pair<MBEntityHandle,MBEntityHandle>(0, 0), mNext(NULL), mPrev(NULL) {}
-    PairNode(PairNode* next, PairNode* prev, 
-             MBEntityHandle _first, MBEntityHandle _second)
-      : std::pair<MBEntityHandle,MBEntityHandle>(_first,_second), mNext(next), mPrev(prev) {}
-
-    PairNode* mNext;
-    PairNode* mPrev;
-  };
-
-  
-  MBEntityHandle operator[](MBEntityID index) const;
-
-  int index(MBEntityHandle handle) const;
-  
-protected:
-
-  //! the head of the list that contains pairs that represent the ranges 
-  //! this list is sorted and unique at all times
-  PairNode mHead;
-  
-  //! if dead_node is not mHead, remove it from the list and free it's memory.
-  void delete_pair_node( PairNode* dead_node );
-
-public:
-
-    //! used to iterate over sub-ranges of a range
-  class pair_iterator : public range_base_iter
-  {
-    friend class MBRange;
-  public:
-    pair_iterator() : mNode(NULL) {}
-    pair_iterator(PairNode *node) : mNode(node) {}
-    pair_iterator(const pair_iterator& copy)
-      : mNode(copy.mNode) {}
-    pair_iterator(const const_iterator& copy)
-      : mNode(copy.mNode) {}
-
-    std::pair<MBEntityHandle,MBEntityHandle>* operator->() { return mNode; }
-    
-    pair_iterator& operator++()
-    {
-      mNode = mNode->mNext;
-      return *this;
-    }
-    pair_iterator operator++(int)
-    {
-      pair_iterator tmp(*this);
-      this->operator ++();
-      return tmp;
-    }
-
-    pair_iterator& operator--()
-    {
-      mNode = mNode->mPrev;
-      return *this;
-    }
-    pair_iterator operator--(int)
-    {
-      pair_iterator tmp(*this);
-      this->operator--();
-      return tmp;
-    }
-    bool operator==(const pair_iterator& other) const
-    {
-      return mNode == other.mNode;
-    }
-
-    bool operator!=(const pair_iterator& other) const
-    {
-      return mNode != other.mNode;
-    }
-  
-    PairNode* node() { return mNode; }
-
-  private:
-    
-    PairNode* mNode;
-  };
-
-  class const_pair_iterator;
-
-  //! a const iterator which iterates over an MBRange
-  class const_iterator : public range_base_iter
-  {
-    friend class MBRange;
-    friend class pair_iterator;
-    friend class const_pair_iterator;
-    friend MBEntityID operator-( const const_iterator&, const const_iterator& );
-  public:
-    //! default constructor - intialize base default constructor
-    const_iterator() : mNode(NULL), mValue(0) {}
-
-    //! constructor used by MBRange
-    const_iterator( const PairNode* iter, const MBEntityHandle val) 
-      : mNode(const_cast<PairNode*>(iter)), mValue(val)  {} 
-
-    //! dereference that value this iterator points to
-    //! returns a const reference
-    const MBEntityHandle& operator*() const { return  mValue; }
-
-    //! prefix incrementer
-    const_iterator& operator++()
-    {
-      // see if we need to increment the base iterator
-      if(mValue == mNode->second)
-      {
-        mNode = mNode->mNext;
-        mValue = mNode->first;
-      }
-      // if not, just increment the value in the range
-      else
-        ++mValue;
-      return *this;
-    }
-
-    //! postfix incrementer
-    const_iterator operator++(int)
-    {
-      // make a temporary copy
-      const_iterator tmp(*this);
-      // increment self
-      this->operator ++();
-      // return the copy
-      return tmp;
-    }
-
-    //! prefix decrementer
-    const_iterator& operator--()
-    {
-      // see if we need to decrement the base iterator
-      if(mValue == mNode->first)
-      {
-        mNode = mNode->mPrev;;
-        mValue = mNode->second;
-      }
-      // if not, just decrement the value
-      else
-        --mValue;
-      return *this;
-    }
-
-    //! postfix decrementer
-    const_iterator operator--(int)
-    {
-      // make a copy of this
-      const_iterator tmp(*this);
-      // decrement self
-      this->operator --();
-      // return the copy
-      return tmp;
-    }
-    
-    //! Advance iterator specified amount.
-    //! Potentially O(n), but typically better.  Always
-    //! more efficient than calling operator++ step times.
-    const_iterator& operator+=( MBEntityID step );
-    
-    //! Regress iterator specified amount.
-    //! Potentially O(n), but typically better.  Always
-    //! more efficient than calling operator-- step times.
-    const_iterator& operator-=( MBEntityID step );
-
-    //! equals operator
-    bool operator==( const const_iterator& other ) const
-    {
-      // see if the base iterator is the same and the
-      // value of this iterator is the same
-      return (mNode == other.mNode) && (mValue == other.mValue);
-    }
-
-    //! not equals operator
-    bool operator!=( const const_iterator& other ) const
-    {
-      // call == operator and not it.
-      return (mNode != other.mNode) || (mValue != other.mValue);
-    }
-    
-    /**\brief get an iterator at the end of the block
-     *
-     * Get an iterator at the end of the block of consecutive
-     * handles that this iterator is currently contained in.
-     * That is, if the range contains blocks of consecutive 
-     * handles of the form { [1,5], [7,100], ... } and this
-     * iterator is at any handle in the range [7,100], return
-     * an iterator at the '100' handle.
-     *
-     * Never returns begin() or end() unless this iterator is
-     * at begin() or end().  May return the same location as
-     * this iterator.
-     */
-    inline const_iterator end_of_block() const;
-
-  protected:
-
-    //! the node we are pointing at
-    PairNode* mNode;
-    //! the value in the range
-    MBEntityHandle mValue;
-  };
-
-  //! a const reverse iterator which iterates over an MBRange
-  class const_reverse_iterator : public range_base_iter
-  {
-    friend class MBRange;
-    friend class pair_iterator;
-  public:
-    //! default constructor - intialize base default constructor
-    const_reverse_iterator() {}
-    
-    const_reverse_iterator( const_iterator fwd_iter ) : myIter(fwd_iter) {}
-
-    //! constructor used by MBRange
-    const_reverse_iterator( const PairNode* iter, const MBEntityHandle val) 
-      : myIter(iter, val)  {} 
-
-    //! dereference that value this iterator points to
-    //! returns a const reference
-    const MBEntityHandle& operator*() const { return  *myIter; }
-
-    //! prefix incrementer
-    const_reverse_iterator& operator++()
-    {
-      --myIter;
-      return *this;
-    }
-
-    //! postfix incrementer
-    const_reverse_iterator operator++(int)
-    {
-      return const_reverse_iterator( myIter-- );
-    }
-
-    //! prefix decrementer
-    const_reverse_iterator& operator--()
-    {
-      ++myIter;
-      return *this;
-    }
-
-    //! postfix decrementer
-    const_reverse_iterator operator--(int)
-    {
-      return const_reverse_iterator( myIter++ );
-    }
-    
-    //! Advance iterator specified amount.
-    //! Potentially O(n), but typically better.  Always
-    //! more efficient than calling operator++ step times.
-    const_reverse_iterator& operator+=( MBEntityID step )
-    {
-      myIter -= step;
-      return *this;
-    }
-
-    //! Regress iterator specified amount.
-    //! Potentially O(n), but typically better.  Always
-    //! more efficient than calling operator-- step times.
-    const_reverse_iterator& operator-=( MBEntityID step )
-    {
-      myIter += step;
-      return *this;
-    }
-
-    //! equals operator
-    bool operator==( const const_reverse_iterator& other ) const
-    {
-      return myIter == other.myIter;
-    }
-
-    //! not equals operator
-    bool operator!=( const const_reverse_iterator& other ) const
-    {
-      return myIter != other.myIter;
-    }
-
-  protected:
-
-    //! the node we are pointing at
-    const_iterator myIter;
-  };
-
-public:
-
-  class const_pair_iterator {
-    public:
-      const_pair_iterator() : myNode(NULL) {}
-      const_pair_iterator( const PairNode* node ) : myNode(node) {}
-      const_pair_iterator( const const_iterator& i ) : myNode(i.mNode) {}
-      
-      const std::pair<MBEntityHandle, MBEntityHandle>& operator*() const
-        { return *myNode; }
-      
-      const std::pair<MBEntityHandle, MBEntityHandle>* operator->() const
-        { return myNode; }
-      
-      const_pair_iterator& operator--()
-        { myNode = myNode->mPrev; return *this; }
-      
-      const_pair_iterator& operator++()
-        { myNode = myNode->mNext; return *this; }
-      
-      const_pair_iterator operator--(int)
-        { const_pair_iterator rval(*this); this->operator--(); return rval; }
-      
-      const_pair_iterator operator++(int)
-        { const_pair_iterator rval(*this); this->operator++(); return rval; }
-        
-      bool operator==( const const_pair_iterator& other ) const
-        { return other.myNode == myNode; }
-    
-      bool operator!=( const const_pair_iterator& other ) const
-        { return other.myNode != myNode; }
-        
-    private:
-      const PairNode* myNode;
-  };
-  
-  pair_iterator pair_begin() { return pair_iterator(mHead.mNext); }
-  pair_iterator pair_end() { return pair_iterator(&mHead); }
-
-  const_pair_iterator const_pair_begin() const { return const_pair_iterator( mHead.mNext ); }
-  const_pair_iterator const_pair_end() const { return const_pair_iterator( &mHead ); }
-  const_pair_iterator pair_begin() const { return const_pair_iterator( mHead.mNext ); }
-  const_pair_iterator pair_end() const { return const_pair_iterator( &mHead ); }
-};
-
- 
-    //! intersect two ranges, placing the results in the return range
-MBRange intersect( const MBRange&, const MBRange& );
-
-    //! subtract range2 from this, placing the results in the return range
-MBRange subtract( const MBRange& from, const MBRange& );
-
-    //! unite two ranges, placing the results in the return range
-inline MBRange unite( const MBRange& r1, const MBRange& r2 )
-  { MBRange r(r1); r.merge(r2); return r; }
-
-
-inline MBRange::const_iterator 
-operator+( const MBRange::const_iterator& it, MBEntityID step )
-  { MBRange::const_iterator tmp(it); return tmp += step; }
-  
-inline MBRange::const_iterator 
-operator+( MBEntityID step, const MBRange::const_iterator& it )
-  { MBRange::const_iterator tmp(it); return tmp += step; }
-  
-inline MBRange::const_iterator 
-operator-( const MBRange::const_iterator& it, MBEntityID step )
-  { MBRange::const_iterator tmp(it); return tmp -= step; }
-  
-inline MBRange::const_iterator 
-operator-( MBEntityID step, const MBRange::const_iterator& it )
-  { MBRange::const_iterator tmp(it); return tmp -= step; }
-  
-MBEntityID 
-operator-(  const MBRange::const_iterator& it1, const MBRange::const_iterator& it2 );
-
-//! Use as you would an STL back_inserter
-/**
- *  e.g. std::copy(list.begin(), list.end(), mb_range_inserter(my_range);
- * Also, see comments/instructions at the top of this class declaration
- */
-class mb_range_inserter 
-{
-  
-protected:
-  MBRange* container;
- 
-public:
-  //constructor
-  explicit mb_range_inserter(MBRange& x) : container(&x) {}
-  mb_range_inserter&
-  operator=(const MBRange::value_type& value) 
-  {
-    container->insert(value);
-    return *this;
-  }
-
-  mb_range_inserter& operator*() { return *this; }
-  mb_range_inserter& operator++() { return *this; }
-  mb_range_inserter& operator++(int) { return *this; }
-
-  typedef MBEntityHandle            value_type;
-  typedef MBEntityID                difference_type;
-  typedef std::output_iterator_tag  iterator_category;
-  typedef MBEntityHandle*           pointer;
-  typedef MBEntityHandle&           reference;
-};
-
-
-inline MBRange::MBRange()
-{
-    // set the head node to point to itself
-  mHead.mNext = mHead.mPrev = &mHead;
-  mHead.first = mHead.second = 0;
-}
-  
-  //! destructor
-inline MBRange::~MBRange()
-{
-  clear();
-}
-
-  //! return the beginning const iterator of this range
-inline MBRange::const_iterator MBRange::begin() const
-{
-  return const_iterator(mHead.mNext, mHead.mNext->first);
-}
-  
-  //! return the beginning const reverse iterator of this range
-inline MBRange::const_reverse_iterator MBRange::rbegin() const
-{
-  return const_reverse_iterator(mHead.mPrev, mHead.mPrev->second);
-}
- 
-  //! return the ending const iterator for this range
-inline MBRange::const_iterator MBRange::end() const
-{
-  return const_iterator(&mHead, mHead.first);
-}
-  
-  //! return the ending const reverse iterator for this range
-inline MBRange::const_reverse_iterator MBRange::rend() const
-{
-  return const_reverse_iterator(&mHead, mHead.second);
-}
-
-  //! return whether empty or not 
-  //! always use "if(!Ranges::empty())" instead of "if(Ranges::size())"
-inline bool MBRange::empty() const
-{
-  return (mHead.mNext == &mHead);
-}
-
-  //! erases a value from this container
-inline MBRange::iterator MBRange::erase(MBEntityHandle val) 
-{ 
-  return erase(find(val)); 
-}
-  
-inline MBRange::const_iterator MBRange::const_iterator::end_of_block() const
-  { return MBRange::const_iterator( mNode, mNode->second ); }
-
-  //! get first entity in range
-inline const MBEntityHandle& MBRange::front() const
-  { return mHead.mNext->first; }
-  //! get last entity in range
-inline const MBEntityHandle& MBRange::back() const
-  { return mHead.mPrev->second; }
-
-inline std::ostream& operator<<( std::ostream& s, const MBRange& r )
-  { r.print(s); return s; }
-  
-bool operator==( const MBRange& r1, const MBRange& r2 );
-inline bool operator!=( const MBRange& r1, const MBRange& r2 )
-  { return !(r1 == r2); }
-
-inline MBEntityHandle MBRange::operator[](MBEntityID index) const
-{
-  MBRange::const_iterator i = begin();
-  i += index;
-  return *i;
-}
-
-#endif // MB_RANGE_HPP
-
-
-

Deleted: MOAB/trunk/src/moab/MBReadUtilIface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBReadUtilIface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBReadUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,177 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-#ifndef MB_READ_UTIL_IFACE_HPP
-#define MB_READ_UTIL_IFACE_HPP
-
-
-#include <vector>
-#include <string>
-#include "MBTypes.h"
-
-class MBRange;
-
-//! Interface implemented in MOAB which provides memory for mesh reading utilities
-class MB_DLL_EXPORT MBReadUtilIface
-{
-public:
-
-    //! constructor 
-  MBReadUtilIface(){}
-
-    //! destructor
-  virtual ~MBReadUtilIface(){}
-
-    //! Given a requested number of vertices and number of coordinates, returns
-    //! memory space which will be used to store vertex coordinates and information
-    //! about what handles those new vertices are assigned; allows direct read of 
-    //! coordinate data into memory
-    //! \param num_arrays Number of node position arrays requested
-    //! \param num_nodes Number of nodes
-    //! \param preferred_start_id Preferred integer id starting value
-    //! \param actual_start_handle Actual starting id value
-    //! \param arrays STL vector of double*'s, point to memory storage to be used for 
-    //!     these vertices
-    //! \return status Success/failure of this call
-  virtual MBErrorCode get_node_arrays(
-    const int num_arrays,
-    const int num_nodes, 
-    const int preferred_start_id,
-    MBEntityHandle& actual_start_handle, 
-    std::vector<double*>& arrays
-    ) = 0;
-
-    //! Given requested number of elements, element type, and number of
-    //! elements, returns pointer to memory space allocated to store connectivity
-    //! of those elements; allows direct read of connectivity data into memory
-    //! \param num_elements Number of elements being requested
-    //! \param verts_per_element Number of vertices per element (incl. higher-order nodes)
-    //! \param mdb_type Element type
-    //! \param preferred_start_id Preferred integer id for first element
-    //! \param actual_start_handle Actual integer id for first element (returned)
-    //! \param array Pointer to memory allocated for storing connectivity for these elements
-    //! \return status Success/failure of this call
-  virtual MBErrorCode get_element_array(
-    const int num_elements, 
-    const int verts_per_element,
-    const MBEntityType mdb_type,
-    const int preferred_start_id, 
-    MBEntityHandle& actual_start_handle, 
-    MBEntityHandle*& array
-    ) = 0;
-
-    /**
-     *\brief Gather entities related to those in the partition
-     * Gather entities related to those in the input partition.  Related
-     * means down-adjacent to, contained in, etc.
-     * \param partition Entities for which to gather related entities
-     * \param related_ents Related entities
-     * \param all_sets If non-NULL, all sets in mesh instance are returned
-     * in the pointed-to range
-     */
-  virtual MBErrorCode gather_related_ents(MBRange &partition,
-                                          MBRange &related_ents,
-                                          MBRange *all_sets) = 0;
-  
-  virtual MBErrorCode create_entity_sets(
-    MBEntityID num_sets,
-    const unsigned* set_flags,
-    MBEntityID preffered_start_id,
-    MBEntityHandle& actual_start_handle
-  ) = 0;
-
-    //! update adjacencies
-    //! given information about new elements, adjacency information will be updated
-    //! in MOAB.  Think of this function as a way of Readers telling MOAB what elements are 
-    //! new because we aren't using the MBInterface to create elements.
-    //! \param start_handle Handle of first new element
-    //! \param number_elements Number of new elements
-    //! \param number_vertices_per_element Number of vertices in each new element
-    //! \param conn_array Connectivity of new elements
-    //! \return status Success/failure of this call
-  virtual MBErrorCode update_adjacencies(
-    const MBEntityHandle start_handle,
-    const int number_elements,
-    const int number_vertices_per_element,
-    const MBEntityHandle* conn_array
-    ) = 0;
-
-
-  
-  /**\brief Re-order incomming element connectivity
-   *
-   * Permute the connectivity of each element such that the node
-   * order is that of MBCN rather than the target file format.
-   *\param order The permutation to use.  Must be an array of 'node_per_elem'
-   *             integers and be a permutation of the values [0..node_per_elem-1].
-   *             Such that for a single element:
-   *             mbcn_conn[order[i]] == target_conn[i]
-   *\param conn  The connectivty array to re-order
-   *\param num_elem  The number of elements in the connectivity array
-   *\param node_per_elem The number of nodes in each element's connectivity list.
-   */
-  static inline 
-  void reorder( const int* order, MBEntityHandle* conn, 
-                int num_elem, int node_per_elem );
-
-    //! if an error occured when reading the mesh, report it to MOAB
-    //! it makes sense to have this as long as MBInterface has a load_mesh function
-  virtual MBErrorCode report_error( const std::string& error ) = 0;
-
-    //! overloaded report_error behaves like the above
-  virtual MBErrorCode report_error( const char* error, ... )
-#ifdef __GNUC__
-__attribute__((format(printf,2,3)))
-#endif
-  = 0;
-
-    //! given an ordered list of bounding entities and the sense of
-    //! those entities, return an ordered list of vertices
-  virtual MBErrorCode get_ordered_vertices(MBEntityHandle *bound_ents, 
-                                           int *sense, 
-                                           int num_bound,
-                                           int dim,
-                                           MBEntityHandle *bound_verts, 
-                                           MBEntityType &etype) = 0;
-
-    //! Assign sequential IDS to entities in range and store IDs in tag
-  virtual MBErrorCode assign_ids( MBTag id_tag, const MBRange& ents, 
-                                  int start = 0 ) = 0;
-  
-    //! Assign to each entity in an array the ID that is its position
-    //! in the array plus the value of 'start'.  For any non-zero handles
-    //! in the array, store the ID value in the passed tag.
-  virtual MBErrorCode assign_ids( MBTag id_tag, const MBEntityHandle* ents, 
-                                  size_t num_ents, int start = 0 ) = 0;
-};
-
-inline 
-void MBReadUtilIface::reorder( const int* order, MBEntityHandle* conn, 
-                               int num_elem, int node_per_elem )
-{
-  std::vector<MBEntityHandle> elem(node_per_elem);
-  MBEntityHandle* const end = conn + num_elem*node_per_elem;
-  while (conn != end) {
-    std::copy( conn, conn+node_per_elem, elem.begin() );
-    for (int j = 0; j < node_per_elem; ++j) 
-      conn[order[j]] = elem[j];
-    conn += node_per_elem;
-  }
-}
-
-#endif 
-
-

Deleted: MOAB/trunk/src/moab/MBReaderIface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBReaderIface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBReaderIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,98 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- *\class MBReaderIface
- *\brief Interface for mesh reader implementations.
- *\version 1.00
- *\date 2004-4-23
- *\author Jason Kraftcheck
- */
-
-#ifndef MB_READER_IFACE_HPP
-#define MB_READER_IFACE_HPP
-
-#include "MBTypes.h"
-
-class FileOptions;
-
-class MBReaderIface
-{
-  public:
-  
-    virtual ~MBReaderIface() {}
-    
-      /** Struct used to specify subset of file to read */
-    struct IDTag {
-      const char* tag_name;  //!< Name of tag containing integer IDs
-      const int* tag_values; //!< Array of integer ID values
-      int num_tag_values;    //!< Length of tag_values array
-      int num_parts;         //!< If non-zero, load 1/num_parts of the matching sets
-      int part_number;       //!< If num_parts is non-zero, load part_number-th fraction of the sets
-    };
-    
-    /**
-     *\brief Load mesh from a file.
-     *
-     * Method all readers must provide to import a mesh.
-     *
-     *\param file_name      The file to read.
-     *\param file_set       Optional pointer to entity set representing
-     *                      file.  If this is not NULL, reader may optionally
-     *                      tag the pointed-to set with format-specific
-     *                      meta-data.
-     *\param subset_list    An array of tag name and value sets specifying
-     *                      the subset of the file to read.  If multiple
-     *                      tags are specified, the sets that match all
-     *                      tags (intersection) should be read.
-     *\param subset_list_length The length of the 'subset_list' array.
-     *\param file_id_tag    If specified, reader should store for each entity
-     *                      it reads, a unique integer ID for this tag.
-     *\author Jason Kraftcheck
-     */
-    virtual MBErrorCode load_file( const char* file_name,
-                                   const MBEntityHandle* file_set,
-                                   const FileOptions& opts,
-                                   const IDTag* subset_list = 0,
-                                   int subset_list_length = 0,
-                                   const MBTag* file_id_tag = 0 ) = 0;
-
-
-    /**
-     *\brief Read tag values from a file.
-     *
-     * Read the list if all integer tag values from the file for
-     * a tag that is a single integer value per entity.
-     *
-     *\param file_name      The file to read.
-     *\param tag_name       The tag for which to read values
-     *\param tag_values_out Output: The list of tag values.
-     *\param subset_list    An array of tag name and value sets specifying
-     *                      the subset of the file to read.  If multiple
-     *                      tags are specified, the sets that match all
-     *                      tags (intersection) should be read.
-     *\param subset_list_length The length of the 'subset_list' array.
-     */
-    virtual MBErrorCode read_tag_values( const char* file_name,
-                                         const char* tag_name,
-                                         const FileOptions& opts,
-                                         std::vector<int>& tag_values_out,
-                                         const IDTag* subset_list = 0,
-                                         int subset_list_length = 0 ) = 0;
-};
-
-#endif
-
-    

Deleted: MOAB/trunk/src/moab/MBReaderWriterSet.hpp
===================================================================
--- MOAB/trunk/src/moab/MBReaderWriterSet.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBReaderWriterSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,164 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- *\class MBReaderWriterSet
- *\brief Maintain list of readers and writers.
- *\version 1.00
- *\date 2004-4-23
- *\author Jason Kraftcheck
- */
-
-#ifndef MB_READER_WRITER_SET_HPP
-#define MB_READER_WRITER_SET_HPP
-
-#include <list>
-#include <string>
-#include "MBTypes.h"
-
-class MBReaderIface;
-class MBWriterIface;
-class MBCore;
-class MBError;
-
-class MBReaderWriterSet
-{
-
-  public:
-    
-    typedef MBReaderIface* (*reader_factory_t)( MBInterface* );
-    typedef MBWriterIface* (*writer_factory_t)( MBInterface* );
-  
-    MBReaderWriterSet( MBCore* mdb, MBError* handler );
-  
-    ~MBReaderWriterSet();
-    
-    /**
-     * Regiseter a reader and/or writer
-     * Either factory function may be NULL, but not both.
-     *
-     *\param reader_fact  A factory method to create an instance of the reader
-     *\param writer_fact  A factory method to create an instance of the reader
-     *\param description  A short description of the file format.
-     *\param extensions   A null-terminated list of file extensions
-     *\param name         File format identifier string.
-     */
-    MBErrorCode register_factory( reader_factory_t reader_fact,
-                                  writer_factory_t writer_fact,
-                                  const char* description,
-                                  const char* const* extensions,
-                                  const char* name );
-    MBErrorCode register_factory( reader_factory_t reader_fact,
-                                  writer_factory_t writer_fact,
-                                  const char* description,
-                                  const char* extension,
-                                  const char* name );
-  
-    /** 
-     * Create a reader object for the passed file name 
-     * according to the dot-extension of the file name.
-     * Caller must delete the object when finished.
-     * Returns null if no matching file extension.
-     */
-    MBReaderIface* get_file_extension_reader( const std::string& filename ) const;
-
-    /** 
-     * Create a writer object for the passed file name 
-     * according to the dot-extension of the file name.
-     * Caller must delete the object when finished.
-     * Returns null if no matching file extension.
-     */
-    MBWriterIface* get_file_extension_writer( const std::string& filename ) const;
-    
-    /**
-     * Create a reader object for the passed file format type.
-     * Caller is responsible for deletion of returned object.
-     * Returns NULL if no match.
-     */
-    MBReaderIface* get_file_reader( const char* format_name ) const; 
-     
-    /**
-     * Create a writer object for the passed file format type.
-     * Caller is responsible for deletion of returned object.
-     * Returns NULL if no match.
-     */
-    MBWriterIface* get_file_writer( const char* format_name ) const; 
-    
-    /** 
-     * Get the file extension from a file name
-     */
-    static std::string extension_from_filename( const std::string& filename );
-  
-    class Handler {
-      
-      friend class MBReaderWriterSet;
-      
-      public:
-      
-      Handler( reader_factory_t read_f,
-               writer_factory_t write_f,
-               const char* name,
-               const char* desc, 
-               const char* const* ext, 
-               int num_ext );
-      
-      inline const std::string& name() const { return mName; }
-      inline const std::string& description() const { return mDescription; }
-      inline void get_extensions( std::vector<std::string>& list_out ) const
-        { list_out = mExtensions; }
-      
-      inline bool have_reader() const { return NULL != mReader; }
-      inline bool have_writer() const { return NULL != mWriter; }
-      
-      inline MBReaderIface* make_reader( MBInterface* iface ) const
-        { return have_reader() ? mReader(iface) : NULL; }
-      
-      inline MBWriterIface* make_writer( MBInterface* iface ) const
-        { return have_writer() ? mWriter(iface) : NULL; }
-      
-      bool operator==( const char* name ) const;
-      
-      private:
-      
-      reader_factory_t mReader;
-      writer_factory_t mWriter;
-      
-      std::string mName, mDescription;
-      std::vector<std::string> mExtensions;
-    };
-    
-    typedef std::list<Handler>::const_iterator iterator;
-    
-    inline iterator begin() const { return handlerList.begin(); }
-    
-    inline iterator end()   const { return handlerList.end();   }
-    
-    
-    iterator handler_from_extension( const std::string& extension,
-                                      bool with_reader = false, 
-                                      bool with_writer = false) const;
-    
-    iterator handler_by_name( const char* name ) const;
-    
-  private:
-  
-    MBCore* mbCore;
-    MBError* mbError;
-  
-    std::list<Handler> handlerList;
-};
-
-
-#endif

Deleted: MOAB/trunk/src/moab/MBSkinner.hpp
===================================================================
--- MOAB/trunk/src/moab/MBSkinner.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBSkinner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,233 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-
-#ifndef MB_SKINNER_HPP
-#define MB_SKINNER_HPP
-
-#include "MBForward.hpp"
-#include <vector>
-
-class MBSkinner 
-{
-
-  enum direction{FORWARD=1, REVERSE=-1};
-protected:
-  //! the MB instance that this works with
-  MBInterface* thisMB;
-
-  MBTag mDeletableMBTag;
-  MBTag mAdjTag;
-  int mTargetDim;
-
-public:
-  //! constructor, takes mdb instance
-  MBSkinner(MBInterface* mdb) 
-    : thisMB(mdb), mDeletableMBTag(0), mAdjTag(0){}
-
-  //! destructor
-  ~MBSkinner();
-
-  MBErrorCode find_geometric_skin(MBRange &forward_target_entities);
-  
-  // will accept entities all of one dimension
-  // and return entities of n-1 dimension
-  MBErrorCode find_skin( const MBRange &entities,
-                         bool get_vertices,
-                         MBRange &output_handles,
-                         MBRange *output_reverse_handles = 0,
-                         bool create_vert_elem_adjs = false,
-                         bool create_skin_elements = true);
-
-    // get skin entities of prescribed dimension
-  MBErrorCode find_skin(const MBRange &entities,
-                        int dim,
-                        MBRange &skin_entities,
-                        bool create_vert_elem_adjs = false);
-
-    /**\brief Find vertices on the skin of a set of mesh entities.
-     *\param entities The elements for which to find the skin.  Range
-     *                may NOT contain vertices, polyhedra, or entity sets.
-     *                All elements in range must be of the same dimension.
-     *\param skin_verts Output: the vertices on the skin.
-     *\param skin_elems Optional output: elements representing sides of entities 
-     *                    that are on the skin
-     *\param create_if_missing If skin_elemts is non-null and this is true, 
-     *                    create new elements representing the sides of 
-     *                    entities on the skin.  If this is false, skin_elems
-     *                    will contain only those skin elements that already
-     *                    exist.
-     */
-  MBErrorCode find_skin_vertices( const MBRange& entities,
-                                  MBRange& skin_verts,
-                                  MBRange* skin_elems = 0,
-                                  bool create_if_missing = true );
-
-  MBErrorCode classify_2d_boundary( const MBRange &boundary,
-                                     const MBRange &bar_elements,
-                                     MBEntityHandle boundary_edges,
-                                     MBEntityHandle inferred_edges,
-                                     MBEntityHandle non_manifold_edges,
-                                     MBEntityHandle other_edges,
-                                     int &number_boundary_nodes);
-  
-  //!given a skin of dimension 2, will classify and return edges
-  //! as boundary, inferred, and non-manifold, and the rest (other)
-  MBErrorCode classify_2d_boundary( const MBRange  &boundary,
-                                     const MBRange  &mesh_1d_elements,
-                                     MBRange  &boundary_edges,
-                                     MBRange  &inferred_edges,
-                                     MBRange  &non_manifold_edges,
-                                     MBRange  &other_edges,
-                                     int &number_boundary_nodes);
-
-protected:
-  
-  void initialize();
-  
-  void deinitialize();
-
-  MBErrorCode find_skin_noadj( const MBRange &source_entities,
-                               MBRange &forward_target_entities,
-                               MBRange &reverse_target_entities );
-
-  void add_adjacency(MBEntityHandle entity);
-  
-  void add_adjacency(MBEntityHandle entity, const MBEntityHandle *conn,
-                     const int num_nodes);
-
-  MBErrorCode remove_adjacency(MBEntityHandle entity);
-
-  bool entity_deletable(MBEntityHandle entity);
-
-  void find_match( MBEntityType type, 
-                   const MBEntityHandle *conn, 
-                   const int num_nodes,
-                   MBEntityHandle& match,
-                   MBSkinner::direction &direct);
-
-  bool connectivity_match(const MBEntityHandle *conn1,
-                          const MBEntityHandle *conn2,
-                          const int num_verts,
-                          MBSkinner::direction &direct);
-
-  void find_inferred_edges(MBRange &skin_boundary,
-                           MBRange &candidate_edges,
-                           MBRange &inferred_edges,
-                           double reference_angle_degrees);
-
-  bool has_larger_angle(MBEntityHandle &entity1,
-                       MBEntityHandle &entity2,
-                       double reference_angle_cosine);
-
-
-    /**\brief Find vertices on the skin of a set of mesh entities.
-     *\param entities The elements for which to find the skin.  Range
-     *                may NOT contain vertices, polyhedra, or entity sets.
-     *                All elements in range must be of the same dimension.
-     *\param skin_verts Output: the vertices on the skin.
-     *\param skin_elems Optional output: elements representing sides of entities 
-     *                    that are on the skin
-     *\param create_if_missing If skin_elemts is non-null and this is true, 
-     *                    create new elements representing the sides of 
-     *                    entities on the skin.  If this is false, skin_elems
-     *                    will contain only those skin elements that already
-     *                    exist.
-     */
-  MBErrorCode find_skin_vertices( const MBRange& entities,
-                                  MBRange* skin_verts = 0,
-                                  MBRange* skin_elems = 0,
-                                  MBRange* rev_elems = 0,
-                                  bool create_if_missing = true,
-                                  bool corners_only = false );
-
-  /**\brief Skin edges
-   *
-   * Return any vertices adjacent to exactly one of the input edges.
-   */
-  MBErrorCode find_skin_vertices_1D( MBTag tag,
-                                     const MBRange& edges,
-                                     MBRange& skin_verts );
-                                     
-  /**\brief Skin faces
-   *
-   * For the set of face sides (logical edges), return 
-   * vertices on such sides and/or edges equivalent to such sides.
-   *\param faces  Set of toplogically 2D entities to skin.
-   *\param skin_verts If non-NULL, skin vertices will be added to this container.
-   *\param skin_edges If non-NULL, skin edges will be added to this container
-   *\param reverse_edges If skin_edges is not NULL and this is not NULL, then
-   *                  any existing skin edges that are reversed with respect
-   *                  to the skin side will be placed in this range instead of
-   *                  skin_edges.  Note: this argument is ignored if skin_edges
-   *                  is NULL.
-   *\param create_edges If true, edges equivalent to face sides on the skin
-   *                  that don't already exist will be created.  Note: this
-   *                  parameter is honored regardless of whether or not skin
-   *                  edges or vertices are returned.
-   *\param corners_only If true, only skin vertices that correspond to the
-   *                  corners of sides will be returned (i.e. no higher-order
-   *                  nodes.)  This argument is ignored if skin_verts is NULL.
-   */
-  MBErrorCode find_skin_vertices_2D( MBTag tag,
-                                     const MBRange& faces,
-                                     MBRange* skin_verts = 0,
-                                     MBRange* skin_edges = 0,
-                                     MBRange* reverse_edges = 0,
-                                     bool create_edges = false,
-                                     bool corners_only = false );
-                                     
-  /**\brief Skin volume mesh
-   *
-   * For the set of element sides (logical faces), return 
-   * vertices on such sides and/or faces equivalent to such sides.
-   *\param entities  Set of toplogically 3D entities to skin.
-   *\param skin_verts If non-NULL, skin vertices will be added to this container.
-   *\param skin_faces If non-NULL, skin faces will be added to this container
-   *\param reverse_faces If skin_faces is not NULL and this is not NULL, then
-   *                  any existing skin faces that are reversed with respect
-   *                  to the skin side will be placed in this range instead of
-   *                  skin_faces.  Note: this argument is ignored if skin_faces
-   *                  is NULL.
-   *\param create_faces If true, face equivalent to sides on the skin
-   *                  that don't already exist will be created.  Note: this
-   *                  parameter is honored regardless of whether or not skin
-   *                  faces or vertices are returned.
-   *\param corners_only If true, only skin vertices that correspond to the
-   *                  corners of sides will be returned (i.e. no higher-order
-   *                  nodes.)  This argument is ignored if skin_verts is NULL.
-   */
-  MBErrorCode find_skin_vertices_3D( MBTag tag,
-                                     const MBRange& entities,
-                                     MBRange* skin_verts = 0,
-                                     MBRange* skin_faces = 0,
-                                     MBRange* reverse_faces = 0,
-                                     bool create_faces = false,
-                                     bool corners_only = false );
-
-  MBErrorCode create_side( MBEntityHandle element,
-                           MBEntityType side_type,
-                           const MBEntityHandle* side_corners,
-                           MBEntityHandle& side_elem_handle_out );
-                           
-  bool edge_reversed( MBEntityHandle face, const MBEntityHandle edge_ends[2] );
-  bool face_reversed( MBEntityHandle region, const MBEntityHandle* face_conn, 
-                      MBEntityType face_type );
-};
-
-
-#endif
-

Deleted: MOAB/trunk/src/moab/MBTypes.h
===================================================================
--- MOAB/trunk/src/moab/MBTypes.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBTypes.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,103 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifndef MB_TYPES_H
-#define MB_TYPES_H
-
-#include "MBEntityType.h"
-#include "MBEntityHandle.h"
-
-/**\name Types and names
- * Types used in the MOAB interface
- */
-/*@{*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef WIN32
-#ifdef MB_EXPORTS
-#define MB_DLL_EXPORT __declspec(dllexport)
-#else
-#define MB_DLL_EXPORT
-#endif
-#else
-#define MB_DLL_EXPORT
-#endif
-
-/** MOAB error codes */
-enum MBErrorCode { MB_SUCCESS = 0,
-                   MB_INDEX_OUT_OF_RANGE,
-                   MB_TYPE_OUT_OF_RANGE,
-                   MB_MEMORY_ALLOCATION_FAILED,
-                   MB_ENTITY_NOT_FOUND,
-                   MB_MULTIPLE_ENTITIES_FOUND,
-                   MB_TAG_NOT_FOUND,
-                   MB_FILE_DOES_NOT_EXIST,
-                   MB_FILE_WRITE_ERROR,
-                   MB_NOT_IMPLEMENTED,
-                   MB_ALREADY_ALLOCATED,
-                   MB_VARIABLE_DATA_LENGTH,
-                   MB_INVALID_SIZE,
-                   MB_UNSUPPORTED_OPERATION,
-                   MB_UNHANDLED_OPTION,
-                   MB_FAILURE};
-
-/** Misc. integer constants, declared in enum for portability */
-enum MBConstants {
-  MB_VARIABLE_LENGTH = -1 /**< Length value for variable-length tags */ 
-};
-
-/** Specify storage type for tags.  See MOAB users guide for more information. */
-enum MBTagType {
-  MB_TAG_BIT = 0, /**< size measured in bits instead of bytes, otherwise identical to sparse */
-  MB_TAG_SPARSE,  /**< tags stored in (entity handle, tag value) pairs */
-  MB_TAG_DENSE,   /**< tags stored in vectors directly on entity sequences, cheaper for tags which go on lots of entities */ 
-  MB_TAG_MESH, 
-  MB_TAG_LAST=MB_TAG_MESH};
-
-/** Specify data type for tags. */
-enum MBDataType {
-  MB_TYPE_OPAQUE  = 0, /**< byte array */
-  MB_TYPE_INTEGER = 1, /**< native 'int' type */
-  MB_TYPE_DOUBLE  = 2, /**< native 'double' type */
-  MB_TYPE_BIT     = 3, /**< mandatory type for tags with MB_TAG_BIT storage */
-  MB_TYPE_HANDLE  = 4, /**< MBEntityHandle */
-  MB_MAX_DATA_TYPE = MB_TYPE_HANDLE
-};
-
-/** Used to reference tags; since they're so different from entities, we
- *  use void** instead of a uint to prevent them from being confused as 
- *  entity handles.
- */
-typedef void** MBTag;
-
-/** Meshset options: properties for meshset creation.
- *  Values are bit flags that may be combined with a bitwise OR (|)
- */
-enum MBEntitySetProperty {
-  MESHSET_TRACK_OWNER = 0x1, /**< create entity to meshset adjacencies */
-  MESHSET_SET         = 0x2, /**< set contents are unique */
-  MESHSET_ORDERED     = 0x4  /**< order of set contents is preserved */
-};
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-/*@}*/
-
-#endif

Deleted: MOAB/trunk/src/moab/MBUnknownInterface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBUnknownInterface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBUnknownInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,101 +0,0 @@
-/*  Filename   :     MBUnkonwnInterface.h
- *  Creator    :     Clinton Stimpson
- *
- *  Date       :     10 Jan 2002
- *
- *  Owner      :     Clinton Stimpson
- *
- *  Description:     Contains declarations for MBuuid which keeps
- *                   track of different interfaces.
- *                   Also contains the declaration for the base class
- *                   MBUknownInterface from which all interfaces are
- *                   derived from
- */
-
-#ifndef MBUNKNOWNINTERFACE_HPP
-#define MBUNKNOWNINTERFACE_HPP
-
-#include <memory.h>
-
-typedef unsigned char   MBuchar;
-typedef unsigned short  MBushort;
-typedef unsigned        MBuint;
-
-//!  struct that handles universally unique id's for the Mesh Database
-
-// note: this MBuuid is compliant with the windows GUID.  
-// It is possible to do a memcpy() to copy the data from a MBuuid to a GUID
-// if we want to support dll registration
-struct MBuuid
-{
-   //! default constructor that initializes to zero
-   MBuuid()
-   {
-      memset( this, 0, sizeof(MBuuid) );
-   }
-   //! constructor that takes initialization arguments
-   MBuuid( MBuint l, MBushort w1, MBushort w2, 
-         MBuchar b1, MBuchar b2, MBuchar b3, 
-         MBuchar b4, MBuchar b5, MBuchar b6, 
-         MBuchar b7, MBuchar b8 )
-   {
-      data1 = l;
-      data2 = w1;
-      data3 = w2;
-      data4[0] = b1;
-      data4[1] = b2;
-      data4[2] = b3;
-      data4[3] = b4;
-      data4[4] = b5;
-      data4[5] = b6;
-      data4[6] = b7;
-      data4[7] = b8;
-   }
-   //! copy constructor
-   MBuuid( const MBuuid& mdbuuid )
-   {
-      memcpy( this, &mdbuuid, sizeof(MBuuid));
-   }
-   //! sets this uuid equal to another one
-   MBuuid &operator=(const MBuuid& orig)
-   {
-      memcpy( this, &orig, sizeof(MBuuid));
-      return *this;
-   }
-   //! returns whether two uuid's are equal
-   bool operator==(const MBuuid& orig) const
-   {
-      return !memcmp(this, &orig, sizeof(MBuuid));
-   }
-   //! returns whether two uuid's are not equal
-   bool operator!=(const MBuuid& orig) const
-   {
-      return!(*this == orig);
-   }
-
-   //! uuid data storage
-   MBuint   data1;
-   MBushort data2;
-   MBushort data3;
-   MBuchar  data4[8];
-};
-  
-//! MBuuid for an unknown interface
-//! this can be used to either return a default interface
-//! or a NULL interface
-static const MBuuid IDD_MBUnknown = MBuuid( 0xf4f6605e, 0x2a7e, 0x4760, 
-   0xbb, 0x06, 0xb9, 0xed, 0x27, 0xe9, 0x4a, 0xec );
-
-
-//! base class for all interface classes
-class MBUnknownInterface
-{
-public:
-   virtual int QueryInterface
-      ( const MBuuid&, MBUnknownInterface** ) = 0;
-   virtual ~MBUnknownInterface() {};
-};
-
-
-#endif  // MBUNKNOWNINTERFACE_HPP
-

Deleted: MOAB/trunk/src/moab/MBUtil.hpp
===================================================================
--- MOAB/trunk/src/moab/MBUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,66 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-//-------------------------------------------------------------------------
-// Filename      : MBUtil.hpp
-//
-// Purpose       : This file contains utility functions that can be used
-//                 with MB
-//
-// Special Notes : This is a pure virtual class, to prevent instantiation.
-//                 All functions are static, called like this:
-//                 MBUtil::function_name();
-//
-// Creator       : Ray J. Meyers
-//
-// Date          : 09/01/02
-//
-// Owner         : Ray J. meyers
-//-------------------------------------------------------------------------
-
-
-#ifndef MB_UTIL_HPP
-#define MB_UTIL_HPP
-
-#include "MBForward.hpp"
-
-struct  MBCoord
-{
-  double x;
-  double y;
-  double z;
-};
-
-
-//! utility function to be use throughout VERDE
-class MBUtil
-{
-public:
-
-   
-  static void normal(MBInterface* MB, MBEntityHandle handle, double& x, double& y, double& z);
-
-  static void centroid(MBInterface *MB, MBEntityHandle handle,MBCoord &coord);
- // static void edge_centers(MBInterface *MB, MBEntityHandle handle, std::vector<MBCoord> &coords_list);
-
-  //static void face_centers(MBInterface *MB, MBEntityHandle handle, std::vector<MBCoord> &coords_list);
-
-private:
-
-  MBUtil(){};
-
-};
-
-#endif

Deleted: MOAB/trunk/src/moab/MBVersion.h.in
===================================================================
--- MOAB/trunk/src/moab/MBVersion.h.in	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBVersion.h.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,19 +0,0 @@
-#ifndef MB_VERSION_H
-#define MB_VERSION_H
-
-/* MOAB Version */
-#undef MB_VERSION
-
-/* MOAB Major Version */
-#undef MB_VERSION_MAJOR
-
-/* MOAB Minor Version */
-#undef MB_VERSION_MINOR
-
-/* MOAB Patch Level */
-#undef MB_VERSION_PATCH
-
-/* MOAB Version String */
-#undef MB_VERSION_STRING
-
-#endif

Deleted: MOAB/trunk/src/moab/MBWriteUtilIface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBWriteUtilIface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBWriteUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,347 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-
-#ifndef MB_WRITE_UTIL_IFACE_HPP
-#define MB_WRITE_UTIL_IFACE_HPP
-
-
-#include "MBRange.hpp"
-#include <vector>
-
-//! Interface implemented in MOAB which provides memory for mesh reading utilities
-class MB_DLL_EXPORT MBWriteUtilIface
-{
-public:
-
-    //! constructor
-  MBWriteUtilIface(){}
-
-    //! destructor
-  virtual ~MBWriteUtilIface(){}
-  
-    //! Check if the specified file already exists.
-    //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
-    //! if file does exist, or MB_FAILURE for some other error condition.
-  virtual MBErrorCode check_doesnt_exist( const char* file_name ) = 0;
-
-    //! Given information about the nodes to be written, and pointers to memory
-    //! to which coordinates will be written, writes coordinate data there, and
-    //! also assigns global ids to nodes & writes to a tag, if a tag is specified
-    //! \param num_arrays Number of coordinate arrays requested
-    //! \param num_nodes Number of nodes to be written
-    //! \param entities Range of nodes to be written
-    //! \param node_id_tag Tag used to write ids to nodes
-    //! \param start_node_id Starting value for node ids
-    //! \param arrays Pointers to memory where coordinate data will be written
-    //! \return status Return status
-  virtual MBErrorCode get_node_arrays(
-    const int num_arrays,
-    const int num_nodes, 
-    const MBRange& entities, 
-    MBTag node_id_tag,
-    const int start_node_id,
-    std::vector<double*>& arrays
-    ) = 0;
-      
-  /** Get an array of coordinate values for nodes
-   *
-   * Given a range of node handles, retreive a single coordinate
-   * value for each. 
-   *
-   * Failure conditions:
-   *  - invalid entity handles (not vertices, non-existant entity, etc.)
-   *  - range is empty (<code>iter == end</code>)
-   *  - <code>output_array</code> is null
-   *  - insufficient space in <code>output_array</code>
-   *
-   *\param which_array  The coordinate to retreive (0-&gt;X, 1-&gt;Y, 2-&gt;Z)
-   *\param begin        The first node handle.
-   *\param end          One past the last node handle.
-   *\param output_size  The size of <code>output_array</code>.
-   *\param output_array The memory in which to write the node coordinates.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_node_array(
-      const int which_array, 
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const size_t output_size,
-      double* const output_array
-      ) = 0;
-
-    //! Given information about elements to be written and a pointer to memory
-    //! where connectivity for those elements should be written, writes connectivity
-    //! to that memory; uses node ids stored in a tag during call to <em>get_node_arrays</em>
-    //! function
-    //! \param num_elements Number of elements to be written
-    //! \param verts_per_element Number of vertices per element
-    //! \param node_id_tag Tag used to store node ids
-    //! \param entities Range of elements to be written
-    //! \param element_id_tag Tag which should be used to store element ids
-    //! \param start_element_id Starting value for element ids
-    //! \param array Pointer to memory where connectivity data will be written
-    //! \return status Return status
-  virtual MBErrorCode get_element_array(
-    const int num_elements, 
-    const int verts_per_element,
-    MBTag node_id_tag,
-    const MBRange& entities, 
-    MBTag element_id_tag,
-    int start_element_id,
-    int* array
-    ) = 0;
-
-  /** Get connectivity for elements 
-   *
-   * Get the connectivity list for a range of elements.
-   *
-   * Failure cases:
-   *  - Passed range is empty (<code>begin == end</code>).
-   *  - <code>vertices_per_elem</code> is less than one
-   *  - <code>element_array</code> is null.
-   *  - The range contains invalid handles (non-existant entities,
-   *      not an element, etc.)
-   *  - Retreiving ID tag for an entity failed.
-   *  - Insufficient space in passed array.
-   *
-   *\param begin        The first element handle
-   *\param end          One past the last element handle
-   *\param vertices_per_elem Number of vertices to retreive for each
-   *                    element.  If the element has more vertices, the
-   *                    element connectivity will be truncated.  If 
-   *                    <code>vertices_per_elem</code> is greater than the
-   *                    number of nodes for an eleement, the data will be
-   *                    padded with zeros.
-   *\param node_id_tag  A tag with integer values.  
-   *\param array_size   The length of <code>element_array</code>
-   *\param element_array The memory location at which to store the 
-   *                    connectivity list.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_element_array(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const int vertices_per_elem,
-      MBTag node_id_tag,
-      const size_t array_size, 
-      int *const element_array
-      ) = 0;
-
-  /** Get connectivity for elements 
-   *
-   * Get the connectivity list for a range of elements.
-   *
-   * Failure cases:
-   *  - Passed range is empty (<code>begin == end</code>).
-   *  - <code>vertices_per_elem</code> is less than one
-   *  - <code>element_array</code> is null.
-   *  - The range contains invalid handles (non-existant entities,
-   *      not an element, etc.)
-   *  - Insufficient space in passed array.
-   *
-   *\param begin        The first element handle
-   *\param end          One past the last element handle
-   *\param vertices_per_elem Number of vertices to retreive for each
-   *                    element.  If the element has more vertices, the
-   *                    element connectivity will be truncated.  If 
-   *                    <code>vertices_per_elem</code> is greater than the
-   *                    number of nodes for an eleement, the data will be
-   *                    padded with zeros.
-   *\param array_size   The length of <code>element_array</code>
-   *\param element_array The memory location at which to store the 
-   *                    connectivity list.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_element_array(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      const int vertices_per_elem,
-      const size_t array_size, 
-      MBEntityHandle *const element_array
-      ) = 0;
-
-
-  /** Get poly (polygon or polyhedron) connectivity size
-   *\param begin  First iterator in range of poly
-   *\param end    One past last in range of poly.
-   *\param connectivity_size  The lenght of the connectivity list
-   *              For the specified range of polyhedra.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_poly_array_size(
-      MBRange::const_iterator begin,
-      const MBRange::const_iterator end,
-      int& connectivity_size 
-      ) = 0;
-   
-
-  /** Get poly (polygon or polyhedron) connectivity.
-   *
-   * Connectivity is returned in two arrays.  The first is
-   * an array of global IDs that is the concatenation of the
-   * connectivity for the entire range of polys.  The second
-   * is the last index of the connectivity data for each poly
-   * in the global ID array.
-   *
-   * This function will add as many polys as possible to the
-   * passed arrays given the sizes of those arrays.  It will
-   * then pass back position at which it stoped and the sizes
-   * of the data written to the arrays.
-   *
-   * Failure cases:
-   *  - Passed range is empty (<code>begin == end</code>).
-   *  - <code>element_array</code> or <code>index_array</code> is null.
-   *  - The range contains invalid handles (non-existant entities,
-   *      not an poly, etc.)
-   *  - Retreiving ID tag for an entity failed.
-   *
-   *\param iter               As input, the first element handle.
-   *                          As output, one past the last element handle
-   *                          for which data was written to the arrays.
-   *\param end                The iterator at which to stop.
-   *\param node_id_tag        A tag with integer values.  
-   *\param element_array_len  As input, length of <code>element_array</code>.
-   *                          As output, the number of entries written in that
-   *                          array.
-   *\param element_array      The memory location at which to store the 
-   *                          connectivity list.
-   *\param index_array_len    As input, the length of <code>index_array</code>.
-   *                          As output, the number of entries written in that
-   *                          array.
-   *\param index_array        The memory location at which to store offsets.
-   *\param index_offset       Value to offset (add to) index values.  As output
-   *                          the input value plus the amount of data 
-   *                          written to the element array.  (The value you
-   *                          presumably want to pass to the next call.)
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_poly_arrays(
-      MBRange::const_iterator& iter,
-      const MBRange::const_iterator end,
-      const MBTag node_id_tag,
-      size_t& element_array_len,
-      int *const element_array,
-      size_t& index_array_len,
-      int *const index_array,
-      int& index_offset
-      ) = 0;
-
-    //! given elements to be written, gather all the nodes which define those elements
-    //! \param elements Range of elements to be written
-    //! \param node_bit_mark_tag Bit tag to use to identify nodes
-    //! \param nodes Range of nodes gathered from elements (returned)
-    //! \return status Return status
-  virtual MBErrorCode gather_nodes_from_elements(
-    const MBRange& elements,
-    const MBTag node_bit_mark_tag,
-    MBRange& nodes
-    ) = 0;
-
-    //! assign ids to input entities starting with start_id, written to id_tag
-    //! if id_tag is zero, assigns to GLOBAL_ID_TAG_NAME
-    //! \param elements Entities to be written
-    //! \param id_tag Tag used to store entity id
-    //! \param start_id Starting value for entity ids
-    //! \return status Return status
-  virtual MBErrorCode assign_ids(MBRange &elements,
-                                 MBTag id_tag,
-                                 const int start_id) = 0;
-  
-
-  /** Get explict adjacencies 
-   *
-   * Get explicit adjacences stored in database.
-   * Does not create any explicit adjacencies or search for
-   * implicit ones.
-   *
-   *\param entity  The entity to retreive adjacencies for.
-   *\param id_tag  The global ID tag
-   *\param adj     The output list of global IDs of adjacent entities.
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode get_adjacencies(
-      MBEntityHandle entity,
-      MBTag id_tag,
-      std::vector<int>& adj 
-  ) = 0;
-  
-  
-  virtual MBErrorCode get_adjacencies( MBEntityHandle entity,
-                               const MBEntityHandle*& adj_array,
-                               int& num_adj ) = 0;
-
-  
-  /**\brief Re-order outgoing element connectivity
-   *
-   * Permute the connectivity of each element such that the node
-   * order is that of the target file format rather than that of MBCN.
-   *\param order The permutation to use.  Must be an array of 'node_per_elem'
-   *             integers and be a permutation of the values [0..node_per_elem-1].
-   *             Such that for a single element:
-   *             target_conn[i] == mbcn_conn[order[i]]
-   *\param conn  The connectivty array to re-order
-   *\param num_elem  The number of elements in the connectivity array
-   *\param node_per_elem The number of nodes in each element's connectivity list.
-   */
-  template <typename T> static inline 
-  void reorder( const int* order, T* conn, int num_elem, int node_per_elem );
-
-
-  /**\brief Get list of tags to write.
-   *
-   * Get the list of tags to write to the file, possibly using
-   * an optional user-specifed tag list.
-   *
-   *\author Jason Kraftcheck
-   */
-  virtual MBErrorCode 
-  get_tag_list( std::vector<MBTag>& result_list,
-                const MBTag* user_tag_list = 0, 
-                int user_tag_list_length = 0,
-                bool include_variable_length_tags = true ) = 0;
-
-    //! if an error occured when reading the mesh, report it to MB
-    //! it makes sense to have this as long as MBInterface has a write_mesh function
-    //! \return status Return status
-  virtual MBErrorCode report_error( const std::string& error ) = 0;
-  
-    //! overloaded report_error behaves like the above
-    //! \return status Return status
-  virtual MBErrorCode report_error( const char* error, ... ) 
-#ifdef __GNUC__
-__attribute__((format(printf,2,3)))
-#endif
-  = 0;
-
-};
-
-  
-template <typename T> inline 
-void MBWriteUtilIface::reorder( const int* order, T* conn, 
-                                int num_elem, int node_per_elem )
-{
-  std::vector<T> elem(node_per_elem);
-  T* const end = conn + num_elem*node_per_elem;
-  while (conn != end) {
-    std::copy( conn, conn+node_per_elem, elem.begin() );
-    for (int j = 0; j < node_per_elem; ++j, ++conn) 
-      *conn = elem[order[j]];
-  }
-}
-
-#endif 
-
-

Deleted: MOAB/trunk/src/moab/MBWriterIface.hpp
===================================================================
--- MOAB/trunk/src/moab/MBWriterIface.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MBWriterIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,75 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- *\class MBWriterIface
- *\brief Interface for mesh writer implementations.
- *\version 1.00
- *\date 2004-4-23
- *\author Jason Kraftcheck
- */
-
-#ifndef MB_WRITER_IFACE_HPP
-#define MB_WRITER_IFACE_HPP
-
-#include <vector>
-#include <string>
-#include "MBTypes.h"
-
-class FileOptions;
-
-class MBWriterIface
-{
-  public:
-  
-    virtual ~MBWriterIface() {}
-    
-    /**
-     *\brief Export mesh to a file.
-     *
-     * Method all writers must provide to export a mesh.
-     *
-     *\param file_name      The name of the file to create.
-     *\param overwrite      If false, reader should fail if the file already
-     *                      exists.  
-     *\param meshset_list   A list of meshsets to export, or NULL if the
-     *                      whole mesh is to be exported.
-     *\param num_sets       The length of <code>meshset_list</code> or zero
-     *                      if the whole mesh is to be exported.
-     *\param qa_records     File history metadata
-     *\param tag_list       Array of handles for tags to write.  If null,
-     *                      write all tags.  If non-NULL but num_tags is
-     *                      zero, write no tags.
-     *\param requseted_output_dimension  The geometric dimension of the
-     *                      output mesh (coord values per vertex.)  If
-     *                      zero, the dimension of the mesh as returned
-     *                      from MBInterface should be used.
-     *\author Jason Kraftcheck
-     */
-    virtual MBErrorCode write_file( const char* file_name,
-                                    const bool overwrite,
-                                    const FileOptions& opts,
-                                    const MBEntityHandle* meshset_list,
-                                    const int num_sets,
-                                    const std::vector<std::string>& qa_records,
-                                    const MBTag* tag_list,
-                                    int num_tags,
-                                    int requested_output_dimension = 0 ) = 0;
-};
-
-#endif
-
-    
-    

Modified: MOAB/trunk/src/moab/MeshTopoUtil.hpp
===================================================================
--- MOAB/trunk/src/moab/MeshTopoUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/MeshTopoUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -21,31 +21,33 @@
  *          
  */ 
 
-#ifndef MESH_TOPO_UTIL_HPP
-#define MESH_TOPO_UTIL_HPP
+#ifndef MOAB_MESH_TOPO_UTIL_HPP
+#define MOAB_MESH_TOPO_UTIL_HPP
 
-#include "MBForward.hpp"
+#include "moab/Forward.hpp"
 
+namespace moab {
+
 class MeshTopoUtil
 {
 public:
-  MeshTopoUtil(MBInterface *impl) : mbImpl(impl) {}
+  MeshTopoUtil(Interface *impl) : mbImpl(impl) {}
   
   ~MeshTopoUtil() {}
 
     //! generate all the AEntities bounding the vertices
-  MBErrorCode construct_aentities(const MBRange &vertices);
+  ErrorCode construct_aentities(const Range &vertices);
 
     //! given an entity, get its average position (avg vertex locations)
-  MBErrorCode get_average_position(MBRange &entities,
+  ErrorCode get_average_position(Range &entities,
                                    double *avg_position);
 
     //! given an entity, get its average position (avg vertex locations)
-  MBErrorCode get_average_position(const MBEntityHandle entity,
+  ErrorCode get_average_position(const EntityHandle entity,
                                    double *avg_position);
 
     //! given a set of entities, get their average position (avg vertex locations)
-  MBErrorCode get_average_position(const MBEntityHandle *entities,
+  ErrorCode get_average_position(const EntityHandle *entities,
                                    const int num_entities,
                                    double *avg_position);
 
@@ -53,57 +55,57 @@
     //! the entities with <= 1 connected (target_dim+2)-dimensional adjacent entities;
     //! for target_dim=3, just return all of them
     //! just insert into the list, w/o clearing manifold list first
-  MBErrorCode get_manifold(const MBEntityHandle star_entity,
+  ErrorCode get_manifold(const EntityHandle star_entity,
                            const int target_dim,
-                           MBRange &manifold);
+                           Range &manifold);
   
   //! given an entity, find the entities of next higher dimension around
   //! that entity, ordered by connection through next higher dimension entities; 
   //! if any of the star entities is in only entity of next higher dimension, 
   //! on_boundary is returned true
-  MBErrorCode star_entities(const MBEntityHandle star_center,
-                            std::vector<MBEntityHandle> &star_entities,
+  ErrorCode star_entities(const EntityHandle star_center,
+                            std::vector<EntityHandle> &star_entities,
                             bool &bdy_entity,
-                            const MBEntityHandle starting_star_entity = 0,
-                            std::vector<MBEntityHandle> *star_entities_dp1 = NULL,
-                            MBRange *star_entities_candidates_dp1 = NULL);
+                            const EntityHandle starting_star_entity = 0,
+                            std::vector<EntityHandle> *star_entities_dp1 = NULL,
+                            Range *star_entities_candidates_dp1 = NULL);
 
     //! Get a series of (d+1)-dimensional stars around a d-dimensional entity, such that
     //! each star is on a (d+2)-manifold containing the d-dimensional entity; each star
     //! is either open or closed, and also defines a (d+2)-star whose entities are bounded by
     //! (d+1)-entities on the star and on the (d+2)-manifold
-  MBErrorCode star_entities_nonmanifold(const MBEntityHandle star_entity,
-                                        std::vector<std::vector<MBEntityHandle> > &stars,
+  ErrorCode star_entities_nonmanifold(const EntityHandle star_entity,
+                                        std::vector<std::vector<EntityHandle> > &stars,
                                         std::vector<bool> *bdy_flags = NULL,
-                                        std::vector<std::vector<MBEntityHandle> > *dp2_stars = NULL);
+                                        std::vector<std::vector<EntityHandle> > *dp2_stars = NULL);
 
     //! given a star_center, a last_entity (whose dimension should be 1 greater than center)
     //! and last_dp1 (dimension 2 higher than center), returns the next star entity across
     //! last_dp1, and the next dp1 entity sharing next_entity; if star_candidates is non-empty,
     //! star must come from those
-  MBErrorCode star_next_entity(const MBEntityHandle star_center,
-                               const MBEntityHandle last_entity,
-                               const MBEntityHandle last_dp1,
-                               MBRange *star_candidates_dp1,
-                               MBEntityHandle &next_entity,
-                               MBEntityHandle &next_dp1);
+  ErrorCode star_next_entity(const EntityHandle star_center,
+                               const EntityHandle last_entity,
+                               const EntityHandle last_dp1,
+                               Range *star_candidates_dp1,
+                               EntityHandle &next_entity,
+                               EntityHandle &next_dp1);
   
     //! get "bridge" or "2nd order" adjacencies, going through dimension bridge_dim
-  MBErrorCode get_bridge_adjacencies(MBRange &from_entities,
+  ErrorCode get_bridge_adjacencies(Range &from_entities,
                                      int bridge_dim,
                                      int to_dim, 
-                                     MBRange &to_ents,
+                                     Range &to_ents,
                                      int num_layers = 1);
   
     //! get "bridge" or "2nd order" adjacencies, going through dimension bridge_dim
-  MBErrorCode get_bridge_adjacencies(const MBEntityHandle from_entity,
+  ErrorCode get_bridge_adjacencies(const EntityHandle from_entity,
                                      const int bridge_dim,
                                      const int to_dim,
-                                     MBRange &to_adjs);
+                                     Range &to_adjs);
 
     //! return a common entity of the specified dimension, or 0 if there isn't one
-  MBEntityHandle common_entity(const MBEntityHandle ent1,
-                               const MBEntityHandle ent2,
+  EntityHandle common_entity(const EntityHandle ent1,
+                               const EntityHandle ent2,
                                const int dim);
   
   //! return the opposite side entity given a parent and bounding entity.
@@ -113,18 +115,18 @@
   //! \param parent The parent element
   //! \param child The child element
   //! \param opposite_element The index of the opposite element
-  MBErrorCode opposite_entity(const MBEntityHandle parent,
-                              const MBEntityHandle child,
-                              MBEntityHandle &opposite_element);
+  ErrorCode opposite_entity(const EntityHandle parent,
+                              const EntityHandle child,
+                              EntityHandle &opposite_element);
 
     //! split entity which is non-manifold, that is, which has > 2 connected entities
     //! of next higher dimension; assumes that there are >= 2 connected regions of
     //! (d+2)-dimensional entities; a new d-entity is created for each region after the
     //! first, and it's made explicitly-adjacent to the region to which it corresponds
-  MBErrorCode split_entity_nonmanifold(MBEntityHandle split_ent,
-                                       MBRange &old_adjs,
-                                       MBRange &new_adjs,
-                                       MBEntityHandle &new_entity);
+  ErrorCode split_entity_nonmanifold(EntityHandle split_ent,
+                                       Range &old_adjs,
+                                       Range &new_adjs,
+                                       EntityHandle &new_entity);
   
     //! split entities that are manifold (shared by two or less entities of each higher dimension),
     //! optionally creating an entity of next higher dimension to fill the gap
@@ -134,9 +136,9 @@
        \param fill_entities If non-NULL, create an entity of next higher dimension to fill the gap,
                        passing it back in *fill_entities
     */
-  MBErrorCode split_entities_manifold(MBRange &entities,
-                                      MBRange &new_entities,
-                                      MBRange *fill_entities);
+  ErrorCode split_entities_manifold(Range &entities,
+                                      Range &new_entities,
+                                      Range *fill_entities);
   
     //! split entities that are manifold (shared by two or less entities of each higher dimension),
     //! optionally creating an entity of next higher dimension to fill the gap
@@ -151,24 +153,25 @@
                        remains on the boundary (i.e. not adj to any entity of higher 
                        dimension).  Dimension of gowith_ents must be the same as entities.
     */
-  MBErrorCode split_entities_manifold(MBEntityHandle *entities,
+  ErrorCode split_entities_manifold(EntityHandle *entities,
                                       const int num_entities,
-                                      MBEntityHandle *new_entities,
-                                      MBRange *fill_entities,
-                                      MBEntityHandle *gowith_ents = NULL);
+                                      EntityHandle *new_entities,
+                                      Range *fill_entities,
+                                      EntityHandle *gowith_ents = NULL);
 
     //! return whether entity is equivalent to any other of same type and same vertices;
     //! if equivalent entity is found, it's returned in equiv_ents and return value is true,
     //! false otherwise.
-  bool equivalent_entities(const MBEntityHandle entity,
-                           MBRange *equiv_ents = NULL);
+  bool equivalent_entities(const EntityHandle entity,
+                           Range *equiv_ents = NULL);
   
                                   
 private:
-  MBInterface *mbImpl;
+  Interface *mbImpl;
   
 };
 
+} // namespace moab 
 
 #endif
 

Copied: MOAB/trunk/src/moab/OrientedBoxTreeTool.hpp (from rev 3583, MOAB/trunk/src/moab/MBOrientedBoxTreeTool.hpp)
===================================================================
--- MOAB/trunk/src/moab/OrientedBoxTreeTool.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/OrientedBoxTreeTool.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,426 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\file OrientedBoxTreeTool.hpp
+ *\author Jason Kraftcheck (kraftche at cae.wisc.edu)
+ *\date 2006-07-18
+ */
+
+#ifndef MOAB_ORIENTED_BOX_TREE_TOOL_HPP
+#define MOAB_ORIENTED_BOX_TREE_TOOL_HPP
+
+#include "moab/Forward.hpp"
+
+#include <iosfwd>
+#include <list>
+#include <vector>
+
+namespace moab {
+
+class Range;
+class OrientedBox;
+
+class OrientedBoxTreeTool
+{
+  public:
+  
+    /**\brief Misc. knobs controlling tree subdivision
+     *
+     * Available settings for controlling when and how nodes in the tree
+     * are split.  The constructor will initialize to the default
+     * settings.  All settings except best_split_ratio control when
+     * a node is subdivided.  best_split_ratio influences the choice
+     * of how the node is subdivided.
+     *
+     * A calculated ratio is used in the determination of when and how
+     * to split a node.  The ratio is calculated as:
+     * - \f$max(\frac{|n_L - n_R|}{n_L+n_R}, f*\frac{n_I}{n_L+n_R})\f$
+     * - \f$n_L\f$ : num entities to be placed in left child
+     * - \f$n_R\f$ : num entities to be placed in right child
+     * - \f$f\f$ : Settings::intersect_ratio_factor
+     * - \f$n_I\f$: num entities intersecting split plane
+     *
+     * ALL of the following conditions must be met for a node to be further
+     * subdivied:
+     *  - Depth must be less than max_depth
+     *  - Node must contain more than max_leaf_entities entities.
+     *  - The 'ratio' must be less than worst_split_ratio
+     *
+     * The node will be subdivided using a plane normal to one of the
+     * box axis and containing the box center.  The planes are tested 
+     * beginning with the one orthogonal to the longest box axis and
+     * finishing with the one orthogonal to the shortest box axis.  The
+     * search will stop at the first plane for which the 'ratio' is
+     * at least Settings::best_split_ratio .  Giving Settings::best_split_ratio
+     * a non-zero value gives preference to a split orthogonal to larger
+     * box dimensions.
+     */
+    struct Settings {
+      public:
+        Settings();              //!< set defaults
+        int max_leaf_entities;   //!< Average number of entities per leaf
+        int max_depth;           //!< Maximum tree depth - 0->no limit
+        //! Must be in [best_split_ratio,1.0]
+        //! A tree node will not be split if the ratio of children
+        //! in the child nodes is greater than this value.
+        double worst_split_ratio;
+        //! Must be in [0.0,worst_split_ratio]
+        //! The search for an optimal split plane for splitting a node
+        //! will stop if at least this ratio is achieved for the number of
+        //! entities on each side of the split plane.
+        double best_split_ratio;
+        //! Flags used to create entity sets representing tree nodes
+        unsigned int set_options;
+        //! Check if settings are valid.
+        bool valid() const;
+    };
+  
+    OrientedBoxTreeTool( Interface* i, 
+                           const char* tag_name = 0,
+                           bool destroy_created_trees = false ) ;
+  
+    ~OrientedBoxTreeTool();
+  
+    /**\brief Build oriented bounding box tree
+     *
+     * Build an oriented bounding box tree.  
+     *\param entities A list of either vertices or 2-D elements (not both)
+     *                for which to build a tree.
+     *\param set_handle_out A handle for the entity set representing the
+     *                root of the tree.
+     */
+    ErrorCode build( const Range& entities, 
+                       EntityHandle& set_handle_out,
+                       const Settings* settings = 0 );
+     
+    /**\brief Build a tree of sets, where each set contains triangles.
+     *
+     * Build a tree of sets.  Each set must contain at least one triangle
+     * to define its geometry.  Each passed set will become a leaf of
+     * the OBB tree.  Settings controlling tree depth are ignored by
+     * this method.  The tree will be as deep as it needs to be for each
+     * input set to be a leaf.
+     *
+     * To build a tree representing the surfaces of a geometric volume,
+     * 1) Build an OBB tree for each surface using the 'build' method
+     * 2) Add each surface to the contents of the resulting OBB tree root set
+     * 3) Build a tree from all the surface OBB tree root sets using this
+     *    method to get a combined tree for the volume.
+     */
+    ErrorCode join_trees( const Range& tree_roots,
+                            EntityHandle& root_set_out,
+                            const Settings* settings = 0 );
+
+    /**\brief Traversal statistics structure
+     *
+     * Structure to accumulate statistics on traversal performance. Passed optionally
+     * to query functions, this structure contains the count of nodes visited at each
+     * level in a tree, and the count of traversals that ended at each level.
+     * One TrvStats structure can be used with multiple OBB trees or multiple queries,
+     * or used on only a single tree or a single query.
+     *
+     * Note that these traversal statistics are not related to the stats() query below,
+     * which calculates static information about a tree.  These statistics relate
+     * to a tree's dynamic behavior on particular operations.
+     */
+    class TrvStats{ 
+      public:
+
+        //! return counts of nodes visited, indexed by tree depth.  
+        //! the counts include both leaves and interior nodes
+        const std::vector< unsigned >& nodes_visited() const
+        { return nodes_visited_count; }
+        //! return counts of tree leaves visited, indexed by tree depth
+        const std::vector< unsigned >& leaves_visited() const
+        { return leaves_visited_count; }
+        //! return counts of traversals ended, indexed by tree depth
+        const std::vector< unsigned >& traversals_ended() const 
+        { return traversals_ended_count; }        
+        //! reset all counters on this structure
+        void reset();
+        //! print the contents of this structure to given stream
+        void print( std::ostream& str ) const ;
+
+      private: 
+      
+        std::vector< unsigned > nodes_visited_count;
+        std::vector< unsigned > leaves_visited_count;
+        std::vector< unsigned > traversals_ended_count;
+        
+        void increment( unsigned depth );
+        void increment_leaf( unsigned depth );
+        void end_traversal( unsigned depth );
+
+      friend class OrientedBoxTreeTool;
+
+    };
+
+
+    /**\brief Intersect a ray with the triangles contained within the tree
+     *
+     * Intersect a ray with the triangles contained in the tree and return
+     * the distance at which the intersection occured.
+     *\param distances_out The output list of intersection points on the ray.
+     *\param root_set      The MBENTITYSET representing the root of the tree.
+     *\param tolerance     The tolerance to use in intersection checks.
+     *\param ray_point     The base point of the ray.
+     *\param unit_ray_dir  The ray direction vector (must be unit length)
+     *\param ray_length    Optional ray length (intersect segment instead of ray.)
+     */
+    ErrorCode ray_intersect_triangles( std::vector<double>& distances_out,
+                                         EntityHandle root_set,
+                                         double tolerance,
+                                         const double ray_point[3],
+                                         const double unit_ray_dir[3],
+                                         const double* ray_length = 0,
+                                         TrvStats* accum = 0 );
+    
+    /**\brief Intersect ray with tree
+     *
+     * Return the tree nodes (as MBENTITYSET handles) for the leaf boxes
+     * of the tree intersected by a ray.
+     *\param boxes_out    The boxes intersected by the ray.
+     *\param tolerance     The tolerance to use in intersection checks.
+     *\param ray_point     The base point of the ray.
+     *\param unit_ray_dir  The ray direction vector (must be unit length)
+     *\param ray_length    Optional ray length (intersect segment instead of ray.)
+     */
+    ErrorCode ray_intersect_boxes( Range& boxes_out,
+                                     EntityHandle root_set,
+                                     double tolerance,
+                                     const double ray_point[3],
+                                     const double unit_ray_dir[3],
+                                     const double* ray_length = 0,
+                                     TrvStats* accum = 0 );
+
+    /**\brief Intersect ray with triangles contained in passed MBENTITYSETs */
+    ErrorCode ray_intersect_triangles( 
+                          std::vector<double>& intersection_distances_out,
+                          const Range& leaf_boxes_containing_tris,
+                          double tolerance,
+                          const double ray_point[3],
+                          const double unit_ray_dir[3],
+                          const double* ray_length = 0);
+                          
+
+    /**\brief Intersect a ray with the triangles contained within the tree
+     *
+     * Intersect a ray with the triangles contained in the tree and return
+     * the distance at which the intersection occured.
+     *\param distances_out The output list of intersection points on the ray.
+     *\param sets_out      The contained set encountered during the tree traversal
+     *                     (see 'set_build').  For the most common use, this is the
+     *                     set corresponding to the geometric surface containing the
+     *                     intersected triangle.
+     *\param root_set      The MBENTITYSET representing the root of the tree.
+     *\param min_tolerance_intersections This method returns all intersections
+     *                     within 'tolerance' of the start of the ray and if 
+     *                     the number of intersections within the 'tolerance' of the
+     *                     ray start point is less than this number, the next closest
+     *                     intersection.  If the desired result is only the closest
+     *                     intersection, pass zero for this argument.
+     *\param tolerance     The tolerance to use in intersection checks.
+     *\param ray_point     The base point of the ray.
+     *\param unit_ray_dir  The ray direction vector (must be unit length)
+     *\param ray_length    Optional ray length (intersect segment instead of ray.)
+     */
+    ErrorCode ray_intersect_sets( std::vector<double>& distances_out,
+                                    std::vector<EntityHandle>& sets_out,
+                                    std::vector<EntityHandle>& facets_out,
+                                    EntityHandle root_set,
+                                    double tolerance,
+                                    unsigned min_tolerace_intersections,
+                                    const double ray_point[3],
+                                    const double unit_ray_dir[3],
+                                    const double* ray_length = 0,
+                                    TrvStats* accum = 0 );
+    
+    /**\brief Find closest surface, facet in surface, and location on facet
+     *
+     * Find the closest location in the tree to the specified location.
+     *\param point Location to search from
+     *\param point_out Closest location on closest facet
+     *\param facet_out Closest 2D element to input position
+     *\param set_out Set containing closest facet.  0 if tree was not 
+     *               constructed using 'set_build'
+     */
+    ErrorCode closest_to_location( const double* point,
+                                     EntityHandle tree_root,
+                                     double* point_out,
+                                     EntityHandle& facet_out,
+                                     EntityHandle* set_out = 0, 
+                                     TrvStats* accum = 0 );
+                                     
+    /**\brief Find closest facet(s) to input position.
+     *
+     * Find the closest location(s) in the tree to the specified location.
+     *\param point Location to search from
+     *\param facets_out Closest 2D elements to input position are appended to this list
+     *\param sets_out If non-null, sets owning facets are appended to this list.
+     */
+    ErrorCode closest_to_location( const double* point,
+                                     EntityHandle tree_root,
+                                     double tolerance,
+                                     std::vector<EntityHandle>& facets_out,
+                                     std::vector<EntityHandle>* sets_out = 0, 
+                                     TrvStats* accum = 0 );
+    
+    /**\brief Find facets intersected by a sphere 
+     *
+     * Find facets intersected by a spherical volume.
+     *\param center     Sphere center
+     *\param radius     Sphere radius
+     *\param tree_root  Root of OBB tree
+     *\param facets_out List of triangles intersecting sphere
+     *\param sets_out   If not null, sets owning facets are appended to this
+     *                  list in an order corresponding to the entries in 
+     *                  facets_out.
+     */
+    ErrorCode sphere_intersect_triangles( const double* center,
+                                        double radius,
+                                        EntityHandle tree_root,
+                                        std::vector<EntityHandle>& facets_out,
+                                        std::vector<EntityHandle>* sets_out = 0, 
+                                        TrvStats* accum = 0 );
+    
+    /**\brief Get oriented box at node in tree
+     *
+     * Get the oriented box for a node in an oriented bounding box tree.
+     */
+    ErrorCode box( EntityHandle node_set,
+                     OrientedBox& box );
+    
+    /**\brief Get oriented box at node in tree
+     *
+     * Get the oriented box for a node in an oriented bounding box tree.
+     */
+    ErrorCode box( EntityHandle node_set,
+                     double center[3],
+                     double axis1[3],
+                     double axis2[3],
+                     double axis3[3] );
+                         
+    ErrorCode delete_tree( EntityHandle root_set );
+
+    /**\brief Print out tree
+     *
+     * Print the tree to an output stream in a human-readable form.
+     *\param tree_root_set  Entity set representing tree root.
+     *\param list_contents  If true, list entities in each tree node,
+     *                      If false, just list number of entities.
+     *\param id_tag_name    If specified, must be the name of an existing
+     *                      integer tag containing an ID for the entities.
+     *                      Not used if list_contents is false.
+     */
+    void print( EntityHandle tree_root_set, 
+                std::ostream& stream,
+                bool list_contents = false,
+                const char* id_tag_name = 0 );
+                
+    /**\brief Print tree statistics
+     *
+     * Print misc. stats. describing tree
+     */
+    ErrorCode stats( EntityHandle tree_root_set, std::ostream& stream );
+  
+    /**\brief Get tree statistics
+     *
+     * Get summary stats. describing tree
+     * \param set Root of tree for which data is requested
+     * \param total_entities Entities in tree
+     * \param root_volume Total volume of root box
+     * \param tot_node_volume Total volume in all nodes
+     * \param tot_to_root_volume Ratio of total / root volume
+     * \param tree_height Maximum height of tree, from root to leaf
+     * \param node_count Number of nodes in tree
+     * \param num_leaves Number of leaf nodes in tree
+     */
+  ErrorCode stats( EntityHandle set, 
+                     unsigned &entities_in_tree,
+                     double &root_volume,
+                     double &tot_node_volume,
+                     double &tot_to_root_volume,
+                     unsigned &tree_height,
+                     unsigned &node_count,
+                     unsigned &num_leaves);
+  
+    /** \brief Implement this and pass instance to preorder_traverse
+     * 
+     * This interface may be implemented and an instance passed to
+     * preorder_traverse to define some operation to do when traversing
+     * the tree.
+     */
+    class Op {
+      public:
+
+        /**\brief Visit a node in the tree during a traversal.
+         *
+         * This method is called for each node in the tree visited
+         * during a pre-order traversal.  
+         *\param node The EntityHandle for the entity set for the tree node.
+         *\param depth The current depth in the tree.
+         *\param descend Output: if false, traversal will skip children
+         *             of the current node, or if the current node is a
+         *             leaf, the 'leaf' method will not be called.
+         */
+        virtual ErrorCode visit( EntityHandle node,
+                                   int depth,
+                                   bool& descend ) = 0;
+       
+        /**\brief Process a leaf node during tree traversal */
+        virtual ErrorCode leaf( EntityHandle node ) = 0;
+
+        virtual ~Op(); // probably isn't necessary in this case, and
+                       // does nothing, but lots of compilers warn if
+                       // virtual function but no virtual destructor.
+    };
+    
+    /**\brief Visitor pattern - do operation for each tree node
+     *
+     * Do a preorder traversal of the tree, calling the method
+     * in the passed operation instance for each node in the tree.
+     * Parent node is visited before either child (pre-order traversal).
+     * If operator method passes back the 'descend' argument as false,
+     * traversal will not descend to the children of the current node.
+     */
+    ErrorCode preorder_traverse( EntityHandle root_set,
+                                   Op& operation, 
+                                   TrvStats* accum = 0 );
+  
+    Interface* get_moab_instance() const { return instance; }
+  
+    struct SetData;
+  private:
+  
+    ErrorCode build_tree( const Range& entities, 
+                            EntityHandle& set, 
+                            int depth,
+                            const Settings& settings );
+  
+    ErrorCode build_sets( std::list<SetData>& sets,
+                            EntityHandle& node_set,
+                            int depth,
+                            const Settings& settings );
+  
+    Interface* instance;
+    Tag tagHandle;
+ 
+    bool cleanUpTrees;
+    std::vector<EntityHandle> createdTrees;
+};
+
+} // namespace moab 
+
+#endif

Copied: MOAB/trunk/src/moab/Range.hpp (from rev 3583, MOAB/trunk/src/moab/MBRange.hpp)
===================================================================
--- MOAB/trunk/src/moab/Range.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Range.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,807 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class Range
+ *
+ * Stores contiguous or partially contiguous values in an optimized
+ * fashion.  Partially contiguous accessing patterns is also optimized.
+ *
+ * \author Clinton Stimpson
+ *
+ * \date 15 April 2002
+ *
+ */
+
+
+/*
+ *************  Range FAQ and tips ********************
+
+ The purpose of this FAQ is to familiarize a user with
+ the appropriate use of the Range template.
+
+   ******* A few points about Range: *******
+ 1.  Range is not the be all of generic containers.
+ 2.  Range has its strengths and weakneses as any other
+     STL container has.
+ 3.  Strengths:
+     a. For contiguous values, storage is extremely minimal.
+     b. Searching through contiguous values, at best, is
+        a constant time operation.
+     b. Fairly compatible with most STL algorithms.
+     c. Insertions of data from high value to low value
+        is a linear operation (constant for each insertion).
+     d. Removal of a value using an iterator is constant time.
+
+ 4.  Weaknesses:
+     a. For non-contiguous values, storage is not minimal and is
+        on the order of 4x the storage space as using a vector.
+     b. Searching through non-contiguous values is linear
+        time operation.
+     c. Insertions of random data is VERY slow.
+
+   Given the above characteristics of Ranges, you can now
+   decide between Range and another STL container for your
+   particular needs.
+
+
+   ******* Tips *******
+ 1.  Be aware of what iterators are available.  Currently, there are
+     three.  Range<T>::iterator, Range<T>::const_iterator,
+     and Range<T>::RangeListIterator.
+     iterator is derived from const_iterator.  const_iterator
+     is derived from RangeListIterator.  RangeListIterator is a
+     std::list<std::pair<T,T> >::const_iterator.
+     If a particular algorithm could be more efficient by using
+     RangeListIterator, do so.
+
+     ie.
+     
+     Range<char> range1;
+     ... put some stuff in range1
+     Range<char> range2;
+     
+     // the SLOW way.
+     std::copy(range1.begin(), range1.end(), range_inserter<...>(range2));
+
+     // the FAST way.
+     for(Range<char>::RangeListIterator iter = range1.begin(),
+         iter != range1.end(); ++iter)
+     {
+       range2.insert(iter->first, iter->second);
+     }
+
+ 2.  Prefer insert(val1, val2) over insert(val) where possible.
+ 
+ 3.  insert(val) and insert(val1, val2) have to perform searching
+     to find out where to insert an item.  Searches are started
+     from the beginning of the values.  Inserting larger values 
+     before smaller values will increase efficiency.
+
+     ie.
+     std::set<int> my_set;
+     Range<int> my_range;
+     .. perform some operations which set does efficiently.
+
+     // now copy the results from the set into the range.
+     // copy from the end of the set to the beginning of the set
+     std::copy(my_set.rbegin(), my_set.rend(), 
+         range_inserter< Range<int> > ( my_range );
+
+ 4.  Use empty() instead of size() if you only need to find out
+     if there is anything in the list.
+
+ 5.  Know what swap() does.  Sometimes it is useful.  It'll replace
+     the contents of one list with another.
+
+     void compute_and_get_some_set( 
+         Range<char> range1, 
+         Range<char> range2,
+         Range<char>& results
+         );
+     {
+       Range<char> tmp_results;
+       .. perform some computation on range1 and range2
+          and put results in tmp_results;
+       .. filter tmp_results out for some special type.
+       .. etc....
+       // return results
+       results.swap(tmp_results);
+     }
+
+
+   ******* FAQ *******
+ 1. Why won't this code compile?
+    ------------------------
+    class SomeClass
+    {
+    public:
+      Range<int> range;
+    };
+    ....
+    void some_function( const SomeClass& some_class )
+    {
+      Range<int>::iterator = some_class.range.begin();
+    }
+    ---------------------
+    Solution:  you need to use
+    Range<int>::const_iterator instead.
+
+ 2. Why doesn't this work right when I try to change the
+    contents of an Range?
+
+    // make a range that has the letters A,B,C in it.
+    Range<char> my_chars('A', 'C');
+    // make an iterator that points to 'A'.
+    Range<char>::iterator iter = my_chars.begin();
+    // change A to D
+    *iter = 'D';
+    // print contents of my_chars to stdout
+    std::copy(my_chars.begin(), my_chars.end(),
+              std::ostream_iterator(std::cout, " "));
+
+    result is 
+      A B C
+    instead of
+      B C D
+
+    When one calls *iter, which returns 'A', the actual storage of the value 'A' 
+    which is returned is in the iterator and not in the Range.  This allows
+    for multiple iterators on a single Range and the Range does not have
+    to keep track of which iterator is referencing which value.
+
+
+
+*/
+
+
+#ifndef MOAB_RANGE_HPP
+#define MOAB_RANGE_HPP
+
+#include <iterator>
+#include <iosfwd>
+#include "moab/Types.hpp"
+
+namespace moab {
+
+struct range_iter_tag : public std::bidirectional_iterator_tag {};
+
+struct range_base_iter
+{
+  typedef range_iter_tag iterator_category;
+  typedef EntityID difference_type;
+  typedef EntityHandle value_type;
+  typedef EntityHandle* pointer;
+  typedef EntityHandle& reference;
+};
+
+
+//! the class Range
+class Range
+{
+public:
+
+    // forward declare the iterators
+  class const_iterator;
+  class const_reverse_iterator;
+  typedef const_iterator iterator;
+  typedef const_reverse_iterator reverse_iterator;
+ 
+  friend Range intersect( const Range&, const Range& );
+  friend Range subtract( const Range&, const Range& );
+
+  //! for short hand notation, lets typedef the 
+  //! container class that holds the ranges
+  typedef EntityHandle value_type;
+
+  //! default constructor
+  Range();
+
+    //! copy constructor
+  Range(const Range& copy);
+
+  //! another constructor that takes an initial range
+  Range( EntityHandle val1, EntityHandle val2 );
+
+    //! operator=
+  Range& operator=(const Range& copy);
+  
+  //! destructor
+  ~Range();
+
+  //! return the beginning const iterator of this range
+  inline const_iterator begin() const;
+  
+  //! return the beginning const reverse iterator of this range
+  inline const_reverse_iterator rbegin() const;
+ 
+  //! return the ending const iterator for this range
+  inline const_iterator end() const;
+  
+  //! return the ending const reverse iterator for this range
+  inline const_reverse_iterator rend() const;
+
+  //! return the number of values this Ranges represents
+  EntityHandle size() const;
+
+  //! return the number of range pairs in the list
+  EntityHandle psize() const;
+  
+  //! return whether empty or not 
+  //! always use "if(!Ranges::empty())" instead of "if(Ranges::size())"
+  inline bool empty() const;
+
+  iterator insert( iterator hint, EntityHandle val );
+
+  //! insert an item into the list and return the iterator for the inserted item
+  iterator insert(EntityHandle val)
+    { return insert( begin(), val ); }
+  
+  //! insert a range of items into this list and return the iterator for the first
+  //! inserted item
+  iterator insert( iterator hint, EntityHandle first, EntityHandle last );
+  
+  //! insert a range of items into this list and return the iterator for the first
+  //! inserted item
+  iterator insert(EntityHandle val1, EntityHandle val2)
+    { return insert( begin(), val1, val2 ); }
+  
+    //! remove an item from this list and return an iterator to the next item
+  iterator erase(iterator iter);
+
+  //! remove a range of items from the list
+  iterator erase( iterator iter1, iterator iter2);
+
+  //! erases a value from this container
+  inline iterator erase(EntityHandle val);
+  
+  //! get first entity in range
+  inline const EntityHandle& front() const;
+  //! get last entity in range
+  inline const EntityHandle& back() const;
+  //! remove first entity from range
+  EntityHandle pop_front();
+  //! remove last entity from range
+  EntityHandle pop_back();
+  
+  //! find an item int the list and return an iterator at that value
+  const_iterator find(EntityHandle val) const;
+
+  //! return an iterator to the first value >= val
+  static const_iterator lower_bound(const_iterator first,
+                                    const_iterator last,
+                                    EntityHandle val);
+  static const_iterator upper_bound(const_iterator first,
+                                    const_iterator last,
+                                    EntityHandle val);
+  
+  const_iterator lower_bound( EntityHandle val ) const 
+    { return lower_bound( begin(), end(), val ); }
+  const_iterator upperbound( EntityHandle val ) const 
+    { return upper_bound( begin(), end(), val ); }
+  const_iterator lower_bound( EntityType type ) const;
+  const_iterator upper_bound( EntityType type ) const;
+  std::pair<const_iterator, const_iterator> equal_range( EntityType type ) const;
+  const_iterator lower_bound( EntityType type, const_iterator first ) const;
+  const_iterator upper_bound( EntityType type, const_iterator first ) const;
+  
+  //! True if all entities in range are of passed type 
+  //! (also true if range is empty)
+  bool all_of_type( EntityType type ) const;
+  //! True if all entities in range are of passed dimension 
+  //! (also true if range is empty)
+  bool all_of_dimension( int dimension ) const;
+  
+  unsigned num_of_type( EntityType type ) const;
+  unsigned num_of_dimension( int dim ) const;
+  
+  //! clears the contents of the list 
+  void clear();
+  
+  //! for debugging
+  void print(const char *indent_prefix = NULL) const;
+  void print(std::ostream& s, const char *indent_prefix = NULL) const;
+  
+  unsigned long get_memory_use() const;
+
+  //! merges this Range with another range
+  void merge( const Range& range );
+  
+  //! merge a subset of some other range
+  void merge( Range::const_iterator begin,
+              Range::const_iterator end );
+
+  //! swap the contents of this range with another one
+  void swap( Range &range );
+
+    //! check for internal consistency
+  void sanity_check() const;
+
+    //! return a subset of this range, by type
+  Range subset_by_type(EntityType t) const;
+  
+  struct PairNode : public std::pair<EntityHandle,EntityHandle>
+  {
+
+    PairNode() : std::pair<EntityHandle,EntityHandle>(0, 0), mNext(NULL), mPrev(NULL) {}
+    PairNode(PairNode* next, PairNode* prev, 
+             EntityHandle _first, EntityHandle _second)
+      : std::pair<EntityHandle,EntityHandle>(_first,_second), mNext(next), mPrev(prev) {}
+
+    PairNode* mNext;
+    PairNode* mPrev;
+  };
+
+  
+  EntityHandle operator[](EntityID index) const;
+
+  int index(EntityHandle handle) const;
+  
+protected:
+
+  //! the head of the list that contains pairs that represent the ranges 
+  //! this list is sorted and unique at all times
+  PairNode mHead;
+  
+  //! if dead_node is not mHead, remove it from the list and free it's memory.
+  void delete_pair_node( PairNode* dead_node );
+
+public:
+
+    //! used to iterate over sub-ranges of a range
+  class pair_iterator : public range_base_iter
+  {
+    friend class Range;
+  public:
+    pair_iterator() : mNode(NULL) {}
+    pair_iterator(PairNode *node) : mNode(node) {}
+    pair_iterator(const pair_iterator& copy)
+      : mNode(copy.mNode) {}
+    pair_iterator(const const_iterator& copy)
+      : mNode(copy.mNode) {}
+
+    std::pair<EntityHandle,EntityHandle>* operator->() { return mNode; }
+    
+    pair_iterator& operator++()
+    {
+      mNode = mNode->mNext;
+      return *this;
+    }
+    pair_iterator operator++(int)
+    {
+      pair_iterator tmp(*this);
+      this->operator ++();
+      return tmp;
+    }
+
+    pair_iterator& operator--()
+    {
+      mNode = mNode->mPrev;
+      return *this;
+    }
+    pair_iterator operator--(int)
+    {
+      pair_iterator tmp(*this);
+      this->operator--();
+      return tmp;
+    }
+    bool operator==(const pair_iterator& other) const
+    {
+      return mNode == other.mNode;
+    }
+
+    bool operator!=(const pair_iterator& other) const
+    {
+      return mNode != other.mNode;
+    }
+  
+    PairNode* node() { return mNode; }
+
+  private:
+    
+    PairNode* mNode;
+  };
+
+  class const_pair_iterator;
+
+  //! a const iterator which iterates over an Range
+  class const_iterator : public range_base_iter
+  {
+    friend class Range;
+    friend class pair_iterator;
+    friend class const_pair_iterator;
+    friend EntityID operator-( const const_iterator&, const const_iterator& );
+  public:
+    //! default constructor - intialize base default constructor
+    const_iterator() : mNode(NULL), mValue(0) {}
+
+    //! constructor used by Range
+    const_iterator( const PairNode* iter, const EntityHandle val) 
+      : mNode(const_cast<PairNode*>(iter)), mValue(val)  {} 
+
+    //! dereference that value this iterator points to
+    //! returns a const reference
+    const EntityHandle& operator*() const { return  mValue; }
+
+    //! prefix incrementer
+    const_iterator& operator++()
+    {
+      // see if we need to increment the base iterator
+      if(mValue == mNode->second)
+      {
+        mNode = mNode->mNext;
+        mValue = mNode->first;
+      }
+      // if not, just increment the value in the range
+      else
+        ++mValue;
+      return *this;
+    }
+
+    //! postfix incrementer
+    const_iterator operator++(int)
+    {
+      // make a temporary copy
+      const_iterator tmp(*this);
+      // increment self
+      this->operator ++();
+      // return the copy
+      return tmp;
+    }
+
+    //! prefix decrementer
+    const_iterator& operator--()
+    {
+      // see if we need to decrement the base iterator
+      if(mValue == mNode->first)
+      {
+        mNode = mNode->mPrev;;
+        mValue = mNode->second;
+      }
+      // if not, just decrement the value
+      else
+        --mValue;
+      return *this;
+    }
+
+    //! postfix decrementer
+    const_iterator operator--(int)
+    {
+      // make a copy of this
+      const_iterator tmp(*this);
+      // decrement self
+      this->operator --();
+      // return the copy
+      return tmp;
+    }
+    
+    //! Advance iterator specified amount.
+    //! Potentially O(n), but typically better.  Always
+    //! more efficient than calling operator++ step times.
+    const_iterator& operator+=( EntityID step );
+    
+    //! Regress iterator specified amount.
+    //! Potentially O(n), but typically better.  Always
+    //! more efficient than calling operator-- step times.
+    const_iterator& operator-=( EntityID step );
+
+    //! equals operator
+    bool operator==( const const_iterator& other ) const
+    {
+      // see if the base iterator is the same and the
+      // value of this iterator is the same
+      return (mNode == other.mNode) && (mValue == other.mValue);
+    }
+
+    //! not equals operator
+    bool operator!=( const const_iterator& other ) const
+    {
+      // call == operator and not it.
+      return (mNode != other.mNode) || (mValue != other.mValue);
+    }
+    
+    /**\brief get an iterator at the end of the block
+     *
+     * Get an iterator at the end of the block of consecutive
+     * handles that this iterator is currently contained in.
+     * That is, if the range contains blocks of consecutive 
+     * handles of the form { [1,5], [7,100], ... } and this
+     * iterator is at any handle in the range [7,100], return
+     * an iterator at the '100' handle.
+     *
+     * Never returns begin() or end() unless this iterator is
+     * at begin() or end().  May return the same location as
+     * this iterator.
+     */
+    inline const_iterator end_of_block() const;
+
+  protected:
+
+    //! the node we are pointing at
+    PairNode* mNode;
+    //! the value in the range
+    EntityHandle mValue;
+  };
+
+  //! a const reverse iterator which iterates over an Range
+  class const_reverse_iterator : public range_base_iter
+  {
+    friend class Range;
+    friend class pair_iterator;
+  public:
+    //! default constructor - intialize base default constructor
+    const_reverse_iterator() {}
+    
+    const_reverse_iterator( const_iterator fwd_iter ) : myIter(fwd_iter) {}
+
+    //! constructor used by Range
+    const_reverse_iterator( const PairNode* iter, const EntityHandle val) 
+      : myIter(iter, val)  {} 
+
+    //! dereference that value this iterator points to
+    //! returns a const reference
+    const EntityHandle& operator*() const { return  *myIter; }
+
+    //! prefix incrementer
+    const_reverse_iterator& operator++()
+    {
+      --myIter;
+      return *this;
+    }
+
+    //! postfix incrementer
+    const_reverse_iterator operator++(int)
+    {
+      return const_reverse_iterator( myIter-- );
+    }
+
+    //! prefix decrementer
+    const_reverse_iterator& operator--()
+    {
+      ++myIter;
+      return *this;
+    }
+
+    //! postfix decrementer
+    const_reverse_iterator operator--(int)
+    {
+      return const_reverse_iterator( myIter++ );
+    }
+    
+    //! Advance iterator specified amount.
+    //! Potentially O(n), but typically better.  Always
+    //! more efficient than calling operator++ step times.
+    const_reverse_iterator& operator+=( EntityID step )
+    {
+      myIter -= step;
+      return *this;
+    }
+
+    //! Regress iterator specified amount.
+    //! Potentially O(n), but typically better.  Always
+    //! more efficient than calling operator-- step times.
+    const_reverse_iterator& operator-=( EntityID step )
+    {
+      myIter += step;
+      return *this;
+    }
+
+    //! equals operator
+    bool operator==( const const_reverse_iterator& other ) const
+    {
+      return myIter == other.myIter;
+    }
+
+    //! not equals operator
+    bool operator!=( const const_reverse_iterator& other ) const
+    {
+      return myIter != other.myIter;
+    }
+
+  protected:
+
+    //! the node we are pointing at
+    const_iterator myIter;
+  };
+
+public:
+
+  class const_pair_iterator {
+    public:
+      const_pair_iterator() : myNode(NULL) {}
+      const_pair_iterator( const PairNode* node ) : myNode(node) {}
+      const_pair_iterator( const const_iterator& i ) : myNode(i.mNode) {}
+      
+      const std::pair<EntityHandle, EntityHandle>& operator*() const
+        { return *myNode; }
+      
+      const std::pair<EntityHandle, EntityHandle>* operator->() const
+        { return myNode; }
+      
+      const_pair_iterator& operator--()
+        { myNode = myNode->mPrev; return *this; }
+      
+      const_pair_iterator& operator++()
+        { myNode = myNode->mNext; return *this; }
+      
+      const_pair_iterator operator--(int)
+        { const_pair_iterator rval(*this); this->operator--(); return rval; }
+      
+      const_pair_iterator operator++(int)
+        { const_pair_iterator rval(*this); this->operator++(); return rval; }
+        
+      bool operator==( const const_pair_iterator& other ) const
+        { return other.myNode == myNode; }
+    
+      bool operator!=( const const_pair_iterator& other ) const
+        { return other.myNode != myNode; }
+        
+    private:
+      const PairNode* myNode;
+  };
+  
+  pair_iterator pair_begin() { return pair_iterator(mHead.mNext); }
+  pair_iterator pair_end() { return pair_iterator(&mHead); }
+
+  const_pair_iterator const_pair_begin() const { return const_pair_iterator( mHead.mNext ); }
+  const_pair_iterator const_pair_end() const { return const_pair_iterator( &mHead ); }
+  const_pair_iterator pair_begin() const { return const_pair_iterator( mHead.mNext ); }
+  const_pair_iterator pair_end() const { return const_pair_iterator( &mHead ); }
+};
+
+ 
+    //! intersect two ranges, placing the results in the return range
+Range intersect( const Range&, const Range& );
+
+    //! subtract range2 from this, placing the results in the return range
+Range subtract( const Range& from, const Range& );
+
+    //! unite two ranges, placing the results in the return range
+inline Range unite( const Range& r1, const Range& r2 )
+  { Range r(r1); r.merge(r2); return r; }
+
+
+inline Range::const_iterator 
+operator+( const Range::const_iterator& it, EntityID step )
+  { Range::const_iterator tmp(it); return tmp += step; }
+  
+inline Range::const_iterator 
+operator+( EntityID step, const Range::const_iterator& it )
+  { Range::const_iterator tmp(it); return tmp += step; }
+  
+inline Range::const_iterator 
+operator-( const Range::const_iterator& it, EntityID step )
+  { Range::const_iterator tmp(it); return tmp -= step; }
+  
+inline Range::const_iterator 
+operator-( EntityID step, const Range::const_iterator& it )
+  { Range::const_iterator tmp(it); return tmp -= step; }
+  
+EntityID 
+operator-(  const Range::const_iterator& it1, const Range::const_iterator& it2 );
+
+//! Use as you would an STL back_inserter
+/**
+ *  e.g. std::copy(list.begin(), list.end(), range_inserter(my_range);
+ * Also, see comments/instructions at the top of this class declaration
+ */
+class range_inserter 
+{
+  
+protected:
+  Range* container;
+ 
+public:
+  //constructor
+  explicit range_inserter(Range& x) : container(&x) {}
+  range_inserter&
+  operator=(const Range::value_type& value) 
+  {
+    container->insert(value);
+    return *this;
+  }
+
+  range_inserter& operator*() { return *this; }
+  range_inserter& operator++() { return *this; }
+  range_inserter& operator++(int) { return *this; }
+
+  typedef EntityHandle            value_type;
+  typedef EntityID                difference_type;
+  typedef std::output_iterator_tag  iterator_category;
+  typedef EntityHandle*           pointer;
+  typedef EntityHandle&           reference;
+};
+
+
+inline Range::Range()
+{
+    // set the head node to point to itself
+  mHead.mNext = mHead.mPrev = &mHead;
+  mHead.first = mHead.second = 0;
+}
+  
+  //! destructor
+inline Range::~Range()
+{
+  clear();
+}
+
+  //! return the beginning const iterator of this range
+inline Range::const_iterator Range::begin() const
+{
+  return const_iterator(mHead.mNext, mHead.mNext->first);
+}
+  
+  //! return the beginning const reverse iterator of this range
+inline Range::const_reverse_iterator Range::rbegin() const
+{
+  return const_reverse_iterator(mHead.mPrev, mHead.mPrev->second);
+}
+ 
+  //! return the ending const iterator for this range
+inline Range::const_iterator Range::end() const
+{
+  return const_iterator(&mHead, mHead.first);
+}
+  
+  //! return the ending const reverse iterator for this range
+inline Range::const_reverse_iterator Range::rend() const
+{
+  return const_reverse_iterator(&mHead, mHead.second);
+}
+
+  //! return whether empty or not 
+  //! always use "if(!Ranges::empty())" instead of "if(Ranges::size())"
+inline bool Range::empty() const
+{
+  return (mHead.mNext == &mHead);
+}
+
+  //! erases a value from this container
+inline Range::iterator Range::erase(EntityHandle val) 
+{ 
+  return erase(find(val)); 
+}
+  
+inline Range::const_iterator Range::const_iterator::end_of_block() const
+  { return Range::const_iterator( mNode, mNode->second ); }
+
+  //! get first entity in range
+inline const EntityHandle& Range::front() const
+  { return mHead.mNext->first; }
+  //! get last entity in range
+inline const EntityHandle& Range::back() const
+  { return mHead.mPrev->second; }
+
+inline std::ostream& operator<<( std::ostream& s, const Range& r )
+  { r.print(s); return s; }
+  
+bool operator==( const Range& r1, const Range& r2 );
+inline bool operator!=( const Range& r1, const Range& r2 )
+  { return !(r1 == r2); }
+
+inline EntityHandle Range::operator[](EntityID index) const
+{
+  Range::const_iterator i = begin();
+  i += index;
+  return *i;
+}
+
+} // namespace moab 
+
+#endif // MOAB_RANGE_HPP
+
+
+

Modified: MOAB/trunk/src/moab/RangeMap.hpp
===================================================================
--- MOAB/trunk/src/moab/RangeMap.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/moab/RangeMap.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -18,16 +18,18 @@
  *\date 2007-04-25
  */
 
-#ifndef RANGE_MAP_HPP
-#define RANGE_MAP_HPP
+#ifndef MOAB_RANGE_MAP_HPP
+#define MOAB_RANGE_MAP_HPP
 
 #include <vector>
 #include <algorithm>
 
+namespace moab {
+
 /**\brief Map ranges of values 
  *
  * This class provides a map between ranges of values, such as
- * a map between file IDs and MBEntityHandles.  It is intended
+ * a map between file IDs and EntityHandles.  It is intended
  * for use in situations where there are relatively few insertions
  * of large contiguous ranges of values.
  */
@@ -237,4 +239,6 @@
   return i;
 }
 
+} // namespace moab 
+
 #endif

Copied: MOAB/trunk/src/moab/ReadUtilIface.hpp (from rev 3583, MOAB/trunk/src/moab/MBReadUtilIface.hpp)
===================================================================
--- MOAB/trunk/src/moab/ReadUtilIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/ReadUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,181 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+#ifndef MOAB_READ_UTIL_IFACE_HPP
+#define MOAB_READ_UTIL_IFACE_HPP
+
+
+#include <vector>
+#include <string>
+#include "moab/Types.hpp"
+
+namespace moab {
+
+class Range;
+
+//! Interface implemented in MOAB which provides memory for mesh reading utilities
+class MB_DLL_EXPORT ReadUtilIface
+{
+public:
+
+    //! constructor 
+  ReadUtilIface(){}
+
+    //! destructor
+  virtual ~ReadUtilIface(){}
+
+    //! Given a requested number of vertices and number of coordinates, returns
+    //! memory space which will be used to store vertex coordinates and information
+    //! about what handles those new vertices are assigned; allows direct read of 
+    //! coordinate data into memory
+    //! \param num_arrays Number of node position arrays requested
+    //! \param num_nodes Number of nodes
+    //! \param preferred_start_id Preferred integer id starting value
+    //! \param actual_start_handle Actual starting id value
+    //! \param arrays STL vector of double*'s, point to memory storage to be used for 
+    //!     these vertices
+    //! \return status Success/failure of this call
+  virtual ErrorCode get_node_arrays(
+    const int num_arrays,
+    const int num_nodes, 
+    const int preferred_start_id,
+    EntityHandle& actual_start_handle, 
+    std::vector<double*>& arrays
+    ) = 0;
+
+    //! Given requested number of elements, element type, and number of
+    //! elements, returns pointer to memory space allocated to store connectivity
+    //! of those elements; allows direct read of connectivity data into memory
+    //! \param num_elements Number of elements being requested
+    //! \param verts_per_element Number of vertices per element (incl. higher-order nodes)
+    //! \param mdb_type Element type
+    //! \param preferred_start_id Preferred integer id for first element
+    //! \param actual_start_handle Actual integer id for first element (returned)
+    //! \param array Pointer to memory allocated for storing connectivity for these elements
+    //! \return status Success/failure of this call
+  virtual ErrorCode get_element_array(
+    const int num_elements, 
+    const int verts_per_element,
+    const EntityType mdb_type,
+    const int preferred_start_id, 
+    EntityHandle& actual_start_handle, 
+    EntityHandle*& array
+    ) = 0;
+
+    /**
+     *\brief Gather entities related to those in the partition
+     * Gather entities related to those in the input partition.  Related
+     * means down-adjacent to, contained in, etc.
+     * \param partition Entities for which to gather related entities
+     * \param related_ents Related entities
+     * \param all_sets If non-NULL, all sets in mesh instance are returned
+     * in the pointed-to range
+     */
+  virtual ErrorCode gather_related_ents(Range &partition,
+                                          Range &related_ents,
+                                          Range *all_sets) = 0;
+  
+  virtual ErrorCode create_entity_sets(
+    EntityID num_sets,
+    const unsigned* set_flags,
+    EntityID preffered_start_id,
+    EntityHandle& actual_start_handle
+  ) = 0;
+
+    //! update adjacencies
+    //! given information about new elements, adjacency information will be updated
+    //! in MOAB.  Think of this function as a way of Readers telling MOAB what elements are 
+    //! new because we aren't using the Interface to create elements.
+    //! \param start_handle Handle of first new element
+    //! \param number_elements Number of new elements
+    //! \param number_vertices_per_element Number of vertices in each new element
+    //! \param conn_array Connectivity of new elements
+    //! \return status Success/failure of this call
+  virtual ErrorCode update_adjacencies(
+    const EntityHandle start_handle,
+    const int number_elements,
+    const int number_vertices_per_element,
+    const EntityHandle* conn_array
+    ) = 0;
+
+
+  
+  /**\brief Re-order incomming element connectivity
+   *
+   * Permute the connectivity of each element such that the node
+   * order is that of MBCN rather than the target file format.
+   *\param order The permutation to use.  Must be an array of 'node_per_elem'
+   *             integers and be a permutation of the values [0..node_per_elem-1].
+   *             Such that for a single element:
+   *             mbcn_conn[order[i]] == target_conn[i]
+   *\param conn  The connectivty array to re-order
+   *\param num_elem  The number of elements in the connectivity array
+   *\param node_per_elem The number of nodes in each element's connectivity list.
+   */
+  static inline 
+  void reorder( const int* order, EntityHandle* conn, 
+                int num_elem, int node_per_elem );
+
+    //! if an error occured when reading the mesh, report it to MOAB
+    //! it makes sense to have this as long as Interface has a load_mesh function
+  virtual ErrorCode report_error( const std::string& error ) = 0;
+
+    //! overloaded report_error behaves like the above
+  virtual ErrorCode report_error( const char* error, ... )
+#ifdef __GNUC__
+__attribute__((format(printf,2,3)))
+#endif
+  = 0;
+
+    //! given an ordered list of bounding entities and the sense of
+    //! those entities, return an ordered list of vertices
+  virtual ErrorCode get_ordered_vertices(EntityHandle *bound_ents, 
+                                           int *sense, 
+                                           int num_bound,
+                                           int dim,
+                                           EntityHandle *bound_verts, 
+                                           EntityType &etype) = 0;
+
+    //! Assign sequential IDS to entities in range and store IDs in tag
+  virtual ErrorCode assign_ids( Tag id_tag, const Range& ents, 
+                                  int start = 0 ) = 0;
+  
+    //! Assign to each entity in an array the ID that is its position
+    //! in the array plus the value of 'start'.  For any non-zero handles
+    //! in the array, store the ID value in the passed tag.
+  virtual ErrorCode assign_ids( Tag id_tag, const EntityHandle* ents, 
+                                  size_t num_ents, int start = 0 ) = 0;
+};
+
+inline 
+void ReadUtilIface::reorder( const int* order, EntityHandle* conn, 
+                               int num_elem, int node_per_elem )
+{
+  std::vector<EntityHandle> elem(node_per_elem);
+  EntityHandle* const end = conn + num_elem*node_per_elem;
+  while (conn != end) {
+    std::copy( conn, conn+node_per_elem, elem.begin() );
+    for (int j = 0; j < node_per_elem; ++j) 
+      conn[order[j]] = elem[j];
+    conn += node_per_elem;
+  }
+}
+
+} // namespace moab 
+
+#endif 
+
+

Copied: MOAB/trunk/src/moab/ReaderIface.hpp (from rev 3583, MOAB/trunk/src/moab/MBReaderIface.hpp)
===================================================================
--- MOAB/trunk/src/moab/ReaderIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/ReaderIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,102 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ *\class ReaderIface
+ *\brief Interface for mesh reader implementations.
+ *\version 1.00
+ *\date 2004-4-23
+ *\author Jason Kraftcheck
+ */
+
+#ifndef MOAB_READER_IFACE_HPP
+#define MOAB_READER_IFACE_HPP
+
+#include "moab/Types.hpp"
+
+namespace moab {
+
+class FileOptions;
+
+class ReaderIface
+{
+  public:
+  
+    virtual ~ReaderIface() {}
+    
+      /** Struct used to specify subset of file to read */
+    struct IDTag {
+      const char* tag_name;  //!< Name of tag containing integer IDs
+      const int* tag_values; //!< Array of integer ID values
+      int num_tag_values;    //!< Length of tag_values array
+      int num_parts;         //!< If non-zero, load 1/num_parts of the matching sets
+      int part_number;       //!< If num_parts is non-zero, load part_number-th fraction of the sets
+    };
+    
+    /**
+     *\brief Load mesh from a file.
+     *
+     * Method all readers must provide to import a mesh.
+     *
+     *\param file_name      The file to read.
+     *\param file_set       Optional pointer to entity set representing
+     *                      file.  If this is not NULL, reader may optionally
+     *                      tag the pointed-to set with format-specific
+     *                      meta-data.
+     *\param subset_list    An array of tag name and value sets specifying
+     *                      the subset of the file to read.  If multiple
+     *                      tags are specified, the sets that match all
+     *                      tags (intersection) should be read.
+     *\param subset_list_length The length of the 'subset_list' array.
+     *\param file_id_tag    If specified, reader should store for each entity
+     *                      it reads, a unique integer ID for this tag.
+     *\author Jason Kraftcheck
+     */
+    virtual ErrorCode load_file( const char* file_name,
+                                   const EntityHandle* file_set,
+                                   const FileOptions& opts,
+                                   const IDTag* subset_list = 0,
+                                   int subset_list_length = 0,
+                                   const Tag* file_id_tag = 0 ) = 0;
+
+
+    /**
+     *\brief Read tag values from a file.
+     *
+     * Read the list if all integer tag values from the file for
+     * a tag that is a single integer value per entity.
+     *
+     *\param file_name      The file to read.
+     *\param tag_name       The tag for which to read values
+     *\param tag_values_out Output: The list of tag values.
+     *\param subset_list    An array of tag name and value sets specifying
+     *                      the subset of the file to read.  If multiple
+     *                      tags are specified, the sets that match all
+     *                      tags (intersection) should be read.
+     *\param subset_list_length The length of the 'subset_list' array.
+     */
+    virtual ErrorCode read_tag_values( const char* file_name,
+                                         const char* tag_name,
+                                         const FileOptions& opts,
+                                         std::vector<int>& tag_values_out,
+                                         const IDTag* subset_list = 0,
+                                         int subset_list_length = 0 ) = 0;
+};
+
+} // namespace moab 
+
+#endif
+
+    

Copied: MOAB/trunk/src/moab/ReaderWriterSet.hpp (from rev 3583, MOAB/trunk/src/moab/MBReaderWriterSet.hpp)
===================================================================
--- MOAB/trunk/src/moab/ReaderWriterSet.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/ReaderWriterSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,167 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ *\class ReaderWriterSet
+ *\brief Maintain list of readers and writers.
+ *\version 1.00
+ *\date 2004-4-23
+ *\author Jason Kraftcheck
+ */
+
+#ifndef MOAB_READER_WRITER_SET_HPP
+#define MOAB_READER_WRITER_SET_HPP
+
+#include <list>
+#include <string>
+#include "moab/Types.hpp"
+
+namespace moab {
+
+class ReaderIface;
+class WriterIface;
+class Core;
+class Error;
+
+class ReaderWriterSet
+{
+
+  public:
+    
+    typedef ReaderIface* (*reader_factory_t)( Interface* );
+    typedef WriterIface* (*writer_factory_t)( Interface* );
+  
+    ReaderWriterSet( Core* mdb, Error* handler );
+  
+    ~ReaderWriterSet();
+    
+    /**
+     * Regiseter a reader and/or writer
+     * Either factory function may be NULL, but not both.
+     *
+     *\param reader_fact  A factory method to create an instance of the reader
+     *\param writer_fact  A factory method to create an instance of the reader
+     *\param description  A short description of the file format.
+     *\param extensions   A null-terminated list of file extensions
+     *\param name         File format identifier string.
+     */
+    ErrorCode register_factory( reader_factory_t reader_fact,
+                                  writer_factory_t writer_fact,
+                                  const char* description,
+                                  const char* const* extensions,
+                                  const char* name );
+    ErrorCode register_factory( reader_factory_t reader_fact,
+                                  writer_factory_t writer_fact,
+                                  const char* description,
+                                  const char* extension,
+                                  const char* name );
+  
+    /** 
+     * Create a reader object for the passed file name 
+     * according to the dot-extension of the file name.
+     * Caller must delete the object when finished.
+     * Returns null if no matching file extension.
+     */
+    ReaderIface* get_file_extension_reader( const std::string& filename ) const;
+
+    /** 
+     * Create a writer object for the passed file name 
+     * according to the dot-extension of the file name.
+     * Caller must delete the object when finished.
+     * Returns null if no matching file extension.
+     */
+    WriterIface* get_file_extension_writer( const std::string& filename ) const;
+    
+    /**
+     * Create a reader object for the passed file format type.
+     * Caller is responsible for deletion of returned object.
+     * Returns NULL if no match.
+     */
+    ReaderIface* get_file_reader( const char* format_name ) const; 
+     
+    /**
+     * Create a writer object for the passed file format type.
+     * Caller is responsible for deletion of returned object.
+     * Returns NULL if no match.
+     */
+    WriterIface* get_file_writer( const char* format_name ) const; 
+    
+    /** 
+     * Get the file extension from a file name
+     */
+    static std::string extension_from_filename( const std::string& filename );
+  
+    class Handler {
+      
+      friend class ReaderWriterSet;
+      
+      public:
+      
+      Handler( reader_factory_t read_f,
+               writer_factory_t write_f,
+               const char* name,
+               const char* desc, 
+               const char* const* ext, 
+               int num_ext );
+      
+      inline const std::string& name() const { return mName; }
+      inline const std::string& description() const { return mDescription; }
+      inline void get_extensions( std::vector<std::string>& list_out ) const
+        { list_out = mExtensions; }
+      
+      inline bool have_reader() const { return NULL != mReader; }
+      inline bool have_writer() const { return NULL != mWriter; }
+      
+      inline ReaderIface* make_reader( Interface* iface ) const
+        { return have_reader() ? mReader(iface) : NULL; }
+      
+      inline WriterIface* make_writer( Interface* iface ) const
+        { return have_writer() ? mWriter(iface) : NULL; }
+      
+      bool operator==( const char* name ) const;
+      
+      private:
+      
+      reader_factory_t mReader;
+      writer_factory_t mWriter;
+      
+      std::string mName, mDescription;
+      std::vector<std::string> mExtensions;
+    };
+    
+    typedef std::list<Handler>::const_iterator iterator;
+    
+    inline iterator begin() const { return handlerList.begin(); }
+    
+    inline iterator end()   const { return handlerList.end();   }
+    
+    
+    iterator handler_from_extension( const std::string& extension,
+                                      bool with_reader = false, 
+                                      bool with_writer = false) const;
+    
+    iterator handler_by_name( const char* name ) const;
+    
+  private:
+  
+    Core* mbCore;
+    Error* mbError;
+  
+    std::list<Handler> handlerList;
+};
+
+} // namespace moab 
+
+#endif

Copied: MOAB/trunk/src/moab/Skinner.hpp (from rev 3583, MOAB/trunk/src/moab/MBSkinner.hpp)
===================================================================
--- MOAB/trunk/src/moab/Skinner.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Skinner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,236 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+
+#ifndef MOAB_SKINNER_HPP
+#define MOAB_SKINNER_HPP
+
+#include "moab/Forward.hpp"
+#include <vector>
+
+namespace moab {
+
+class Skinner 
+{
+
+  enum direction{FORWARD=1, REVERSE=-1};
+protected:
+  //! the MB instance that this works with
+  Interface* thisMB;
+
+  Tag mDeletableMBTag;
+  Tag mAdjTag;
+  int mTargetDim;
+
+public:
+  //! constructor, takes mdb instance
+  Skinner(Interface* mdb) 
+    : thisMB(mdb), mDeletableMBTag(0), mAdjTag(0){}
+
+  //! destructor
+  ~Skinner();
+
+  ErrorCode find_geometric_skin(Range &forward_target_entities);
+  
+  // will accept entities all of one dimension
+  // and return entities of n-1 dimension
+  ErrorCode find_skin( const Range &entities,
+                         bool get_vertices,
+                         Range &output_handles,
+                         Range *output_reverse_handles = 0,
+                         bool create_vert_elem_adjs = false,
+                         bool create_skin_elements = true);
+
+    // get skin entities of prescribed dimension
+  ErrorCode find_skin(const Range &entities,
+                        int dim,
+                        Range &skin_entities,
+                        bool create_vert_elem_adjs = false);
+
+    /**\brief Find vertices on the skin of a set of mesh entities.
+     *\param entities The elements for which to find the skin.  Range
+     *                may NOT contain vertices, polyhedra, or entity sets.
+     *                All elements in range must be of the same dimension.
+     *\param skin_verts Output: the vertices on the skin.
+     *\param skin_elems Optional output: elements representing sides of entities 
+     *                    that are on the skin
+     *\param create_if_missing If skin_elemts is non-null and this is true, 
+     *                    create new elements representing the sides of 
+     *                    entities on the skin.  If this is false, skin_elems
+     *                    will contain only those skin elements that already
+     *                    exist.
+     */
+  ErrorCode find_skin_vertices( const Range& entities,
+                                  Range& skin_verts,
+                                  Range* skin_elems = 0,
+                                  bool create_if_missing = true );
+
+  ErrorCode classify_2d_boundary( const Range &boundary,
+                                     const Range &bar_elements,
+                                     EntityHandle boundary_edges,
+                                     EntityHandle inferred_edges,
+                                     EntityHandle non_manifold_edges,
+                                     EntityHandle other_edges,
+                                     int &number_boundary_nodes);
+  
+  //!given a skin of dimension 2, will classify and return edges
+  //! as boundary, inferred, and non-manifold, and the rest (other)
+  ErrorCode classify_2d_boundary( const Range  &boundary,
+                                     const Range  &mesh_1d_elements,
+                                     Range  &boundary_edges,
+                                     Range  &inferred_edges,
+                                     Range  &non_manifold_edges,
+                                     Range  &other_edges,
+                                     int &number_boundary_nodes);
+
+protected:
+  
+  void initialize();
+  
+  void deinitialize();
+
+  ErrorCode find_skin_noadj( const Range &source_entities,
+                               Range &forward_target_entities,
+                               Range &reverse_target_entities );
+
+  void add_adjacency(EntityHandle entity);
+  
+  void add_adjacency(EntityHandle entity, const EntityHandle *conn,
+                     const int num_nodes);
+
+  ErrorCode remove_adjacency(EntityHandle entity);
+
+  bool entity_deletable(EntityHandle entity);
+
+  void find_match( EntityType type, 
+                   const EntityHandle *conn, 
+                   const int num_nodes,
+                   EntityHandle& match,
+                   Skinner::direction &direct);
+
+  bool connectivity_match(const EntityHandle *conn1,
+                          const EntityHandle *conn2,
+                          const int num_verts,
+                          Skinner::direction &direct);
+
+  void find_inferred_edges(Range &skin_boundary,
+                           Range &candidate_edges,
+                           Range &inferred_edges,
+                           double reference_angle_degrees);
+
+  bool has_larger_angle(EntityHandle &entity1,
+                       EntityHandle &entity2,
+                       double reference_angle_cosine);
+
+
+    /**\brief Find vertices on the skin of a set of mesh entities.
+     *\param entities The elements for which to find the skin.  Range
+     *                may NOT contain vertices, polyhedra, or entity sets.
+     *                All elements in range must be of the same dimension.
+     *\param skin_verts Output: the vertices on the skin.
+     *\param skin_elems Optional output: elements representing sides of entities 
+     *                    that are on the skin
+     *\param create_if_missing If skin_elemts is non-null and this is true, 
+     *                    create new elements representing the sides of 
+     *                    entities on the skin.  If this is false, skin_elems
+     *                    will contain only those skin elements that already
+     *                    exist.
+     */
+  ErrorCode find_skin_vertices( const Range& entities,
+                                  Range* skin_verts = 0,
+                                  Range* skin_elems = 0,
+                                  Range* rev_elems = 0,
+                                  bool create_if_missing = true,
+                                  bool corners_only = false );
+
+  /**\brief Skin edges
+   *
+   * Return any vertices adjacent to exactly one of the input edges.
+   */
+  ErrorCode find_skin_vertices_1D( Tag tag,
+                                     const Range& edges,
+                                     Range& skin_verts );
+                                     
+  /**\brief Skin faces
+   *
+   * For the set of face sides (logical edges), return 
+   * vertices on such sides and/or edges equivalent to such sides.
+   *\param faces  Set of toplogically 2D entities to skin.
+   *\param skin_verts If non-NULL, skin vertices will be added to this container.
+   *\param skin_edges If non-NULL, skin edges will be added to this container
+   *\param reverse_edges If skin_edges is not NULL and this is not NULL, then
+   *                  any existing skin edges that are reversed with respect
+   *                  to the skin side will be placed in this range instead of
+   *                  skin_edges.  Note: this argument is ignored if skin_edges
+   *                  is NULL.
+   *\param create_edges If true, edges equivalent to face sides on the skin
+   *                  that don't already exist will be created.  Note: this
+   *                  parameter is honored regardless of whether or not skin
+   *                  edges or vertices are returned.
+   *\param corners_only If true, only skin vertices that correspond to the
+   *                  corners of sides will be returned (i.e. no higher-order
+   *                  nodes.)  This argument is ignored if skin_verts is NULL.
+   */
+  ErrorCode find_skin_vertices_2D( Tag tag,
+                                     const Range& faces,
+                                     Range* skin_verts = 0,
+                                     Range* skin_edges = 0,
+                                     Range* reverse_edges = 0,
+                                     bool create_edges = false,
+                                     bool corners_only = false );
+                                     
+  /**\brief Skin volume mesh
+   *
+   * For the set of element sides (logical faces), return 
+   * vertices on such sides and/or faces equivalent to such sides.
+   *\param entities  Set of toplogically 3D entities to skin.
+   *\param skin_verts If non-NULL, skin vertices will be added to this container.
+   *\param skin_faces If non-NULL, skin faces will be added to this container
+   *\param reverse_faces If skin_faces is not NULL and this is not NULL, then
+   *                  any existing skin faces that are reversed with respect
+   *                  to the skin side will be placed in this range instead of
+   *                  skin_faces.  Note: this argument is ignored if skin_faces
+   *                  is NULL.
+   *\param create_faces If true, face equivalent to sides on the skin
+   *                  that don't already exist will be created.  Note: this
+   *                  parameter is honored regardless of whether or not skin
+   *                  faces or vertices are returned.
+   *\param corners_only If true, only skin vertices that correspond to the
+   *                  corners of sides will be returned (i.e. no higher-order
+   *                  nodes.)  This argument is ignored if skin_verts is NULL.
+   */
+  ErrorCode find_skin_vertices_3D( Tag tag,
+                                     const Range& entities,
+                                     Range* skin_verts = 0,
+                                     Range* skin_faces = 0,
+                                     Range* reverse_faces = 0,
+                                     bool create_faces = false,
+                                     bool corners_only = false );
+
+  ErrorCode create_side( EntityHandle element,
+                           EntityType side_type,
+                           const EntityHandle* side_corners,
+                           EntityHandle& side_elem_handle_out );
+                           
+  bool edge_reversed( EntityHandle face, const EntityHandle edge_ends[2] );
+  bool face_reversed( EntityHandle region, const EntityHandle* face_conn, 
+                      EntityType face_type );
+};
+
+} // namespace moab 
+
+#endif
+

Copied: MOAB/trunk/src/moab/Types.hpp (from rev 3583, MOAB/trunk/src/moab/MBTypes.h)
===================================================================
--- MOAB/trunk/src/moab/Types.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Types.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,105 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifndef MOAB_TYPES_HPP
+#define MOAB_TYPES_HPP
+
+#ifdef __cplusplus
+#include "moab/EntityType.hpp"
+#include "moab/EntityHandle.hpp"
+#endif
+
+/**\name Types and names
+ * Types used in the MOAB interface
+ */
+/*@{*/
+
+#ifdef __cplusplus
+namespace moab {
+#endif
+
+#ifdef WIN32
+#ifdef MB_EXPORTS
+#define MB_DLL_EXPORT __declspec(dllexport)
+#else
+#define MB_DLL_EXPORT
+#endif
+#else
+#define MB_DLL_EXPORT
+#endif
+
+/** MOAB error codes */
+enum ErrorCode { MB_SUCCESS = 0,
+                   MB_INDEX_OUT_OF_RANGE,
+                   MB_TYPE_OUT_OF_RANGE,
+                   MB_MEMORY_ALLOCATION_FAILED,
+                   MB_ENTITY_NOT_FOUND,
+                   MB_MULTIPLE_ENTITIES_FOUND,
+                   MB_TAG_NOT_FOUND,
+                   MB_FILE_DOES_NOT_EXIST,
+                   MB_FILE_WRITE_ERROR,
+                   MB_NOT_IMPLEMENTED,
+                   MB_ALREADY_ALLOCATED,
+                   MB_VARIABLE_DATA_LENGTH,
+                   MB_INVALID_SIZE,
+                   MB_UNSUPPORTED_OPERATION,
+                   MB_UNHANDLED_OPTION,
+                   MB_FAILURE};
+
+/** Misc. integer constants, declared in enum for portability */
+enum Constants {
+  MB_VARIABLE_LENGTH = -1 /**< Length value for variable-length tags */ 
+};
+
+/** Specify storage type for tags.  See MOAB users guide for more information. */
+enum TagType {
+  MB_TAG_BIT = 0, /**< size measured in bits instead of bytes, otherwise identical to sparse */
+  MB_TAG_SPARSE,  /**< tags stored in (entity handle, tag value) pairs */
+  MB_TAG_DENSE,   /**< tags stored in vectors directly on entity sequences, cheaper for tags which go on lots of entities */ 
+  MB_TAG_MESH, 
+  MB_TAG_LAST=MB_TAG_MESH};
+
+/** Specify data type for tags. */
+enum DataType {
+  MB_TYPE_OPAQUE  = 0, /**< byte array */
+  MB_TYPE_INTEGER = 1, /**< native 'int' type */
+  MB_TYPE_DOUBLE  = 2, /**< native 'double' type */
+  MB_TYPE_BIT     = 3, /**< mandatory type for tags with MB_TAG_BIT storage */
+  MB_TYPE_HANDLE  = 4, /**< EntityHandle */
+  MB_MAX_DATA_TYPE = MB_TYPE_HANDLE
+};
+
+/** Used to reference tags; since they're so different from entities, we
+ *  use void** instead of a uint to prevent them from being confused as 
+ *  entity handles.
+ */
+typedef void** Tag;
+
+/** Meshset options: properties for meshset creation.
+ *  Values are bit flags that may be combined with a bitwise OR (|)
+ */
+enum EntitySetProperty {
+  MESHSET_TRACK_OWNER = 0x1, /**< create entity to meshset adjacencies */
+  MESHSET_SET         = 0x2, /**< set contents are unique */
+  MESHSET_ORDERED     = 0x4  /**< order of set contents is preserved */
+};
+
+#ifdef __cplusplus
+} // namespace moab 
+#endif
+
+/*@}*/
+
+#endif

Copied: MOAB/trunk/src/moab/UnknownInterface.hpp (from rev 3583, MOAB/trunk/src/moab/MBUnknownInterface.hpp)
===================================================================
--- MOAB/trunk/src/moab/UnknownInterface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/UnknownInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,100 @@
+/*  Filename   :     UnkonwnInterface.h
+ *  Creator    :     Clinton Stimpson
+ *
+ *  Date       :     10 Jan 2002
+ *
+ *  Owner      :     Clinton Stimpson
+ *
+ *  Description:     Contains declarations for MBuuid which keeps
+ *                   track of different interfaces.
+ *                   Also contains the declaration for the base class
+ *                   UknownInterface from which all interfaces are
+ *                   derived from
+ */
+
+#ifndef MOAB_UNKNOWN_INTERFACE_HPP
+#define MOAB_UNKNOWN_INTERFACE_HPP
+
+#include <memory.h>
+
+namespace moab {
+
+//!  struct that handles universally unique id's for the Mesh Database
+
+// note: this MBuuid is compliant with the windows GUID.  
+// It is possible to do a memcpy() to copy the data from a MBuuid to a GUID
+// if we want to support dll registration
+struct MBuuid
+{
+   //! default constructor that initializes to zero
+   MBuuid()
+   {
+      memset( this, 0, sizeof(MBuuid) );
+   }
+   //! constructor that takes initialization arguments
+   MBuuid( unsigned l, unsigned short w1, unsigned short w2, 
+         unsigned char b1, unsigned char b2, unsigned char b3, 
+         unsigned char b4, unsigned char b5, unsigned char b6, 
+         unsigned char b7, unsigned char b8 )
+   {
+      data1 = l;
+      data2 = w1;
+      data3 = w2;
+      data4[0] = b1;
+      data4[1] = b2;
+      data4[2] = b3;
+      data4[3] = b4;
+      data4[4] = b5;
+      data4[5] = b6;
+      data4[6] = b7;
+      data4[7] = b8;
+   }
+   //! copy constructor
+   MBuuid( const MBuuid& mdbuuid )
+   {
+      memcpy( this, &mdbuuid, sizeof(MBuuid));
+   }
+   //! sets this uuid equal to another one
+   MBuuid &operator=(const MBuuid& orig)
+   {
+      memcpy( this, &orig, sizeof(MBuuid));
+      return *this;
+   }
+   //! returns whether two uuid's are equal
+   bool operator==(const MBuuid& orig) const
+   {
+      return !memcmp(this, &orig, sizeof(MBuuid));
+   }
+   //! returns whether two uuid's are not equal
+   bool operator!=(const MBuuid& orig) const
+   {
+      return!(*this == orig);
+   }
+
+   //! uuid data storage
+   unsigned   data1;
+   unsigned short data2;
+   unsigned short data3;
+   unsigned char  data4[8];
+};
+  
+//! uuid for an unknown interface
+//! this can be used to either return a default interface
+//! or a NULL interface
+static const MBuuid IDD_MBUnknown = MBuuid( 0xf4f6605e, 0x2a7e, 0x4760, 
+   0xbb, 0x06, 0xb9, 0xed, 0x27, 0xe9, 0x4a, 0xec );
+
+
+//! base class for all interface classes
+class UnknownInterface
+{
+public:
+   virtual int QueryInterface
+      ( const MBuuid&, UnknownInterface** ) = 0;
+   virtual ~UnknownInterface() {};
+};
+
+} // namespace moab 
+
+#endif  // MOAB_UNKNOWN_INTERFACE_HPP
+

Copied: MOAB/trunk/src/moab/Util.hpp (from rev 3583, MOAB/trunk/src/moab/MBUtil.hpp)
===================================================================
--- MOAB/trunk/src/moab/Util.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/Util.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,70 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+//-------------------------------------------------------------------------
+// Filename      : Util.hpp
+//
+// Purpose       : This file contains utility functions that can be used
+//                 with MB
+//
+// Special Notes : This is a pure virtual class, to prevent instantiation.
+//                 All functions are static, called like this:
+//                 Util::function_name();
+//
+// Creator       : Ray J. Meyers
+//
+// Date          : 09/01/02
+//
+// Owner         : Ray J. meyers
+//-------------------------------------------------------------------------
+
+
+#ifndef MB_UTIL_HPP
+#define MB_UTIL_HPP
+
+#include "moab/Forward.hpp"
+
+namespace moab {
+
+struct  Coord
+{
+  double x;
+  double y;
+  double z;
+};
+
+
+//! utility function to be use throughout VERDE
+class Util
+{
+public:
+
+   
+  static void normal(Interface* MB, EntityHandle handle, double& x, double& y, double& z);
+
+  static void centroid(Interface *MB, EntityHandle handle,Coord &coord);
+ // static void edge_centers(Interface *MB, EntityHandle handle, std::vector<Coord> &coords_list);
+
+  //static void face_centers(Interface *MB, EntityHandle handle, std::vector<Coord> &coords_list);
+
+private:
+
+  Util(){};
+
+};
+
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/moab/Version.h.in (from rev 3583, MOAB/trunk/src/moab/MBVersion.h.in)
===================================================================
--- MOAB/trunk/src/moab/Version.h.in	                        (rev 0)
+++ MOAB/trunk/src/moab/Version.h.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,19 @@
+#ifndef MB_VERSION_H
+#define MB_VERSION_H
+
+/* MOAB Version */
+#undef MB_VERSION
+
+/* MOAB Major Version */
+#undef MB_VERSION_MAJOR
+
+/* MOAB Minor Version */
+#undef MB_VERSION_MINOR
+
+/* MOAB Patch Level */
+#undef MB_VERSION_PATCH
+
+/* MOAB Version String */
+#undef MB_VERSION_STRING
+
+#endif

Copied: MOAB/trunk/src/moab/WriteUtilIface.hpp (from rev 3583, MOAB/trunk/src/moab/MBWriteUtilIface.hpp)
===================================================================
--- MOAB/trunk/src/moab/WriteUtilIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/WriteUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,351 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+
+#ifndef MOAB_WRITE_UTIL_IFACE_HPP
+#define MOAB_WRITE_UTIL_IFACE_HPP
+
+
+#include "moab/Range.hpp"
+#include <vector>
+
+namespace moab {
+
+//! Interface implemented in MOAB which provides memory for mesh reading utilities
+class MB_DLL_EXPORT WriteUtilIface
+{
+public:
+
+    //! constructor
+  WriteUtilIface(){}
+
+    //! destructor
+  virtual ~WriteUtilIface(){}
+  
+    //! Check if the specified file already exists.
+    //! Returns MB_SUCCESS if file does not exist, MB_ALREADY_ALLOCATED
+    //! if file does exist, or MB_FAILURE for some other error condition.
+  virtual ErrorCode check_doesnt_exist( const char* file_name ) = 0;
+
+    //! Given information about the nodes to be written, and pointers to memory
+    //! to which coordinates will be written, writes coordinate data there, and
+    //! also assigns global ids to nodes & writes to a tag, if a tag is specified
+    //! \param num_arrays Number of coordinate arrays requested
+    //! \param num_nodes Number of nodes to be written
+    //! \param entities Range of nodes to be written
+    //! \param node_id_tag Tag used to write ids to nodes
+    //! \param start_node_id Starting value for node ids
+    //! \param arrays Pointers to memory where coordinate data will be written
+    //! \return status Return status
+  virtual ErrorCode get_node_arrays(
+    const int num_arrays,
+    const int num_nodes, 
+    const Range& entities, 
+    Tag node_id_tag,
+    const int start_node_id,
+    std::vector<double*>& arrays
+    ) = 0;
+      
+  /** Get an array of coordinate values for nodes
+   *
+   * Given a range of node handles, retreive a single coordinate
+   * value for each. 
+   *
+   * Failure conditions:
+   *  - invalid entity handles (not vertices, non-existant entity, etc.)
+   *  - range is empty (<code>iter == end</code>)
+   *  - <code>output_array</code> is null
+   *  - insufficient space in <code>output_array</code>
+   *
+   *\param which_array  The coordinate to retreive (0-&gt;X, 1-&gt;Y, 2-&gt;Z)
+   *\param begin        The first node handle.
+   *\param end          One past the last node handle.
+   *\param output_size  The size of <code>output_array</code>.
+   *\param output_array The memory in which to write the node coordinates.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_node_array(
+      const int which_array, 
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const size_t output_size,
+      double* const output_array
+      ) = 0;
+
+    //! Given information about elements to be written and a pointer to memory
+    //! where connectivity for those elements should be written, writes connectivity
+    //! to that memory; uses node ids stored in a tag during call to <em>get_node_arrays</em>
+    //! function
+    //! \param num_elements Number of elements to be written
+    //! \param verts_per_element Number of vertices per element
+    //! \param node_id_tag Tag used to store node ids
+    //! \param entities Range of elements to be written
+    //! \param element_id_tag Tag which should be used to store element ids
+    //! \param start_element_id Starting value for element ids
+    //! \param array Pointer to memory where connectivity data will be written
+    //! \return status Return status
+  virtual ErrorCode get_element_array(
+    const int num_elements, 
+    const int verts_per_element,
+    Tag node_id_tag,
+    const Range& entities, 
+    Tag element_id_tag,
+    int start_element_id,
+    int* array
+    ) = 0;
+
+  /** Get connectivity for elements 
+   *
+   * Get the connectivity list for a range of elements.
+   *
+   * Failure cases:
+   *  - Passed range is empty (<code>begin == end</code>).
+   *  - <code>vertices_per_elem</code> is less than one
+   *  - <code>element_array</code> is null.
+   *  - The range contains invalid handles (non-existant entities,
+   *      not an element, etc.)
+   *  - Retreiving ID tag for an entity failed.
+   *  - Insufficient space in passed array.
+   *
+   *\param begin        The first element handle
+   *\param end          One past the last element handle
+   *\param vertices_per_elem Number of vertices to retreive for each
+   *                    element.  If the element has more vertices, the
+   *                    element connectivity will be truncated.  If 
+   *                    <code>vertices_per_elem</code> is greater than the
+   *                    number of nodes for an eleement, the data will be
+   *                    padded with zeros.
+   *\param node_id_tag  A tag with integer values.  
+   *\param array_size   The length of <code>element_array</code>
+   *\param element_array The memory location at which to store the 
+   *                    connectivity list.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_element_array(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const int vertices_per_elem,
+      Tag node_id_tag,
+      const size_t array_size, 
+      int *const element_array
+      ) = 0;
+
+  /** Get connectivity for elements 
+   *
+   * Get the connectivity list for a range of elements.
+   *
+   * Failure cases:
+   *  - Passed range is empty (<code>begin == end</code>).
+   *  - <code>vertices_per_elem</code> is less than one
+   *  - <code>element_array</code> is null.
+   *  - The range contains invalid handles (non-existant entities,
+   *      not an element, etc.)
+   *  - Insufficient space in passed array.
+   *
+   *\param begin        The first element handle
+   *\param end          One past the last element handle
+   *\param vertices_per_elem Number of vertices to retreive for each
+   *                    element.  If the element has more vertices, the
+   *                    element connectivity will be truncated.  If 
+   *                    <code>vertices_per_elem</code> is greater than the
+   *                    number of nodes for an eleement, the data will be
+   *                    padded with zeros.
+   *\param array_size   The length of <code>element_array</code>
+   *\param element_array The memory location at which to store the 
+   *                    connectivity list.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_element_array(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      const int vertices_per_elem,
+      const size_t array_size, 
+      EntityHandle *const element_array
+      ) = 0;
+
+
+  /** Get poly (polygon or polyhedron) connectivity size
+   *\param begin  First iterator in range of poly
+   *\param end    One past last in range of poly.
+   *\param connectivity_size  The lenght of the connectivity list
+   *              For the specified range of polyhedra.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_poly_array_size(
+      Range::const_iterator begin,
+      const Range::const_iterator end,
+      int& connectivity_size 
+      ) = 0;
+   
+
+  /** Get poly (polygon or polyhedron) connectivity.
+   *
+   * Connectivity is returned in two arrays.  The first is
+   * an array of global IDs that is the concatenation of the
+   * connectivity for the entire range of polys.  The second
+   * is the last index of the connectivity data for each poly
+   * in the global ID array.
+   *
+   * This function will add as many polys as possible to the
+   * passed arrays given the sizes of those arrays.  It will
+   * then pass back position at which it stoped and the sizes
+   * of the data written to the arrays.
+   *
+   * Failure cases:
+   *  - Passed range is empty (<code>begin == end</code>).
+   *  - <code>element_array</code> or <code>index_array</code> is null.
+   *  - The range contains invalid handles (non-existant entities,
+   *      not an poly, etc.)
+   *  - Retreiving ID tag for an entity failed.
+   *
+   *\param iter               As input, the first element handle.
+   *                          As output, one past the last element handle
+   *                          for which data was written to the arrays.
+   *\param end                The iterator at which to stop.
+   *\param node_id_tag        A tag with integer values.  
+   *\param element_array_len  As input, length of <code>element_array</code>.
+   *                          As output, the number of entries written in that
+   *                          array.
+   *\param element_array      The memory location at which to store the 
+   *                          connectivity list.
+   *\param index_array_len    As input, the length of <code>index_array</code>.
+   *                          As output, the number of entries written in that
+   *                          array.
+   *\param index_array        The memory location at which to store offsets.
+   *\param index_offset       Value to offset (add to) index values.  As output
+   *                          the input value plus the amount of data 
+   *                          written to the element array.  (The value you
+   *                          presumably want to pass to the next call.)
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_poly_arrays(
+      Range::const_iterator& iter,
+      const Range::const_iterator end,
+      const Tag node_id_tag,
+      size_t& element_array_len,
+      int *const element_array,
+      size_t& index_array_len,
+      int *const index_array,
+      int& index_offset
+      ) = 0;
+
+    //! given elements to be written, gather all the nodes which define those elements
+    //! \param elements Range of elements to be written
+    //! \param node_bit_mark_tag Bit tag to use to identify nodes
+    //! \param nodes Range of nodes gathered from elements (returned)
+    //! \return status Return status
+  virtual ErrorCode gather_nodes_from_elements(
+    const Range& elements,
+    const Tag node_bit_mark_tag,
+    Range& nodes
+    ) = 0;
+
+    //! assign ids to input entities starting with start_id, written to id_tag
+    //! if id_tag is zero, assigns to GLOBAL_ID_TAG_NAME
+    //! \param elements Entities to be written
+    //! \param id_tag Tag used to store entity id
+    //! \param start_id Starting value for entity ids
+    //! \return status Return status
+  virtual ErrorCode assign_ids(Range &elements,
+                                 Tag id_tag,
+                                 const int start_id) = 0;
+  
+
+  /** Get explict adjacencies 
+   *
+   * Get explicit adjacences stored in database.
+   * Does not create any explicit adjacencies or search for
+   * implicit ones.
+   *
+   *\param entity  The entity to retreive adjacencies for.
+   *\param id_tag  The global ID tag
+   *\param adj     The output list of global IDs of adjacent entities.
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode get_adjacencies(
+      EntityHandle entity,
+      Tag id_tag,
+      std::vector<int>& adj 
+  ) = 0;
+  
+  
+  virtual ErrorCode get_adjacencies( EntityHandle entity,
+                               const EntityHandle*& adj_array,
+                               int& num_adj ) = 0;
+
+  
+  /**\brief Re-order outgoing element connectivity
+   *
+   * Permute the connectivity of each element such that the node
+   * order is that of the target file format rather than that of MBCN.
+   *\param order The permutation to use.  Must be an array of 'node_per_elem'
+   *             integers and be a permutation of the values [0..node_per_elem-1].
+   *             Such that for a single element:
+   *             target_conn[i] == mbcn_conn[order[i]]
+   *\param conn  The connectivty array to re-order
+   *\param num_elem  The number of elements in the connectivity array
+   *\param node_per_elem The number of nodes in each element's connectivity list.
+   */
+  template <typename T> static inline 
+  void reorder( const int* order, T* conn, int num_elem, int node_per_elem );
+
+
+  /**\brief Get list of tags to write.
+   *
+   * Get the list of tags to write to the file, possibly using
+   * an optional user-specifed tag list.
+   *
+   *\author Jason Kraftcheck
+   */
+  virtual ErrorCode 
+  get_tag_list( std::vector<Tag>& result_list,
+                const Tag* user_tag_list = 0, 
+                int user_tag_list_length = 0,
+                bool include_variable_length_tags = true ) = 0;
+
+    //! if an error occured when reading the mesh, report it to MB
+    //! it makes sense to have this as long as Interface has a write_mesh function
+    //! \return status Return status
+  virtual ErrorCode report_error( const std::string& error ) = 0;
+  
+    //! overloaded report_error behaves like the above
+    //! \return status Return status
+  virtual ErrorCode report_error( const char* error, ... ) 
+#ifdef __GNUC__
+__attribute__((format(printf,2,3)))
+#endif
+  = 0;
+
+};
+
+  
+template <typename T> inline 
+void WriteUtilIface::reorder( const int* order, T* conn, 
+                                int num_elem, int node_per_elem )
+{
+  std::vector<T> elem(node_per_elem);
+  T* const end = conn + num_elem*node_per_elem;
+  while (conn != end) {
+    std::copy( conn, conn+node_per_elem, elem.begin() );
+    for (int j = 0; j < node_per_elem; ++j, ++conn) 
+      *conn = elem[order[j]];
+  }
+}
+
+} // namespace moab 
+
+#endif 
+
+

Copied: MOAB/trunk/src/moab/WriterIface.hpp (from rev 3583, MOAB/trunk/src/moab/MBWriterIface.hpp)
===================================================================
--- MOAB/trunk/src/moab/WriterIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/moab/WriterIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,78 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ *\class WriterIface
+ *\brief Interface for mesh writer implementations.
+ *\version 1.00
+ *\date 2004-4-23
+ *\author Jason Kraftcheck
+ */
+
+#ifndef MOAB_WRITER_IFACE_HPP
+#define MOAB_WRITER_IFACE_HPP
+
+#include <vector>
+#include <string>
+#include "moab/Types.hpp"
+
+namespace moab {
+
+class FileOptions;
+
+class WriterIface
+{
+  public:
+  
+    virtual ~WriterIface() {}
+    
+    /**
+     *\brief Export mesh to a file.
+     *
+     * Method all writers must provide to export a mesh.
+     *
+     *\param file_name      The name of the file to create.
+     *\param overwrite      If false, reader should fail if the file already
+     *                      exists.  
+     *\param meshset_list   A list of meshsets to export, or NULL if the
+     *                      whole mesh is to be exported.
+     *\param num_sets       The length of <code>meshset_list</code> or zero
+     *                      if the whole mesh is to be exported.
+     *\param qa_records     File history metadata
+     *\param tag_list       Array of handles for tags to write.  If null,
+     *                      write all tags.  If non-NULL but num_tags is
+     *                      zero, write no tags.
+     *\param requseted_output_dimension  The geometric dimension of the
+     *                      output mesh (coord values per vertex.)  If
+     *                      zero, the dimension of the mesh as returned
+     *                      from Interface should be used.
+     *\author Jason Kraftcheck
+     */
+    virtual ErrorCode write_file( const char* file_name,
+                                    const bool overwrite,
+                                    const FileOptions& opts,
+                                    const EntityHandle* meshset_list,
+                                    const int num_sets,
+                                    const std::vector<std::string>& qa_records,
+                                    const Tag* tag_list,
+                                    int num_tags,
+                                    int requested_output_dimension = 0 ) = 0;
+};
+
+} // namespace moab 
+
+#endif
+
+    

Added: MOAB/trunk/src/oldinc/MBAdaptiveKDTree.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBAdaptiveKDTree.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBAdaptiveKDTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBAdaptiveKDTree_HEADER
+#define MBAdaptiveKDTree_HEADER
+#include "moab/AdaptiveKDTree.hpp"
+typedef moab::AdaptiveKDTree MBAdaptiveKDTree;
+#endif

Added: MOAB/trunk/src/oldinc/MBBSPTree.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBBSPTree.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBBSPTree.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBBSPTree_HEADER
+#define MBBSPTree_HEADER
+#include "moab/BSPTree.hpp"
+typedef moab::BSPTree MBBSPTree;
+#endif

Added: MOAB/trunk/src/oldinc/MBCore.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBCore.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBCore.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBCore_HEADER
+#define MBCore_HEADER
+#include "moab/Core.hpp"
+typedef moab::Core MBCore;
+#endif

Added: MOAB/trunk/src/oldinc/MBEntityHandle.h
===================================================================
--- MOAB/trunk/src/oldinc/MBEntityHandle.h	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBEntityHandle.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBEntityHandle_HEADER
+#define MBEntityHandle_HEADER
+#include "moab/EntityHandle.hpp"
+typedef moab::EntityHandle MBEntityHandle;
+#endif

Added: MOAB/trunk/src/oldinc/MBForward.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBForward.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBForward.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,8 @@
+#ifndef MBForward_HEADER
+#define MBForward_HEADER
+#include "moab/Forward.hpp"
+typedef moab::Interface  MBInterface;
+typedef moab::Range      MBRange;
+typedef moab::ProcConfig MBProcConfig;
+typedef moab::HandleVec  MBHandleVec;
+#endif

Added: MOAB/trunk/src/oldinc/MBGeomUtil.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBGeomUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBGeomUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBGeomUtil_HEADER
+#define MBGeomUtil_HEADER
+#include "moab/GeomUtil.hpp"
+namespace MBGeomUtil = moab::GeomUtil;
+#endif

Added: MOAB/trunk/src/oldinc/MBInterface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBInterface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBInterface_HEADER
+#define MBInterface_HEADER
+#include "moab/Interface.hpp"
+typedef moab::Interface MBInterface;
+#endif

Added: MOAB/trunk/src/oldinc/MBOrientedBoxTreeTool.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBOrientedBoxTreeTool.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBOrientedBoxTreeTool.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBOrientedBoxTreeTool_HEADER
+#define MBOrientedBoxTreeTool_HEADER
+#include "moab/OrientedBoxTreeTool.hpp"
+typedef moab::OrientedBoxTreeTool MBOrientedBoxTreeTool;
+#endif

Added: MOAB/trunk/src/oldinc/MBParallelComm.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBParallelComm.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBParallelComm.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBParallelComm_HEADER
+#define MBParallelComm_HEADER
+#include "moab/ParallelComm.hpp"
+typedef moab::ParallelComm MBParallelComm;
+#endif


Property changes on: MOAB/trunk/src/oldinc/MBParallelComm.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Added: MOAB/trunk/src/oldinc/MBParallelData.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBParallelData.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBParallelData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBParallelData_HEADER
+#define MBParallelData_HEADER
+#include "moab/ParallelData.hpp"
+typedef moab::ParallelData MBParallelData;
+#endif


Property changes on: MOAB/trunk/src/oldinc/MBParallelData.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Added: MOAB/trunk/src/oldinc/MBProcConfig.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBProcConfig.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBProcConfig.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBProcConfig_HEADER
+#define MBProcConfig_HEADER
+#include "moab/ProcConfig.hpp"
+typedef moab::ProcConfig MBProcConfig;
+#endif


Property changes on: MOAB/trunk/src/oldinc/MBProcConfig.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Added: MOAB/trunk/src/oldinc/MBRange.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBRange.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBRange.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,12 @@
+#ifndef MBRange_HEADER
+#define MBRange_HEADER
+
+#include "moab/Range.hpp"
+
+typedef moab::Range MBRange;
+typedef moab::range_inserter mb_range_inserter;
+using moab::intersect; //( const moab::Range&, const moab::Range& );
+using moab::subtract;  //( const moab::Range&, const moab::Range& );
+using moab::unite;     //( const moab::Range&, const moab::Range& );
+
+#endif

Added: MOAB/trunk/src/oldinc/MBReadUtilIface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBReadUtilIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBReadUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBReadUtilIface_HEADER
+#define MBReadUtilIface_HEADER
+#include "moab/ReadUtilIface.hpp"
+typedef moab::ReadUtilIface MBReadUtilIface;
+#endif

Added: MOAB/trunk/src/oldinc/MBReaderIface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBReaderIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBReaderIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBReaderIface_HEADER
+#define MBReaderIface_HEADER
+#include "moab/ReaderIface.hpp"
+typedef moab::ReaderIface MBReaderIface;
+#endif

Added: MOAB/trunk/src/oldinc/MBReaderWriterSet.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBReaderWriterSet.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBReaderWriterSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBReaderWriterSet_HEADER
+#define MBReaderWriterSet_HEADER
+#include "moab/ReaderWriterSet.hpp"
+typedef moab::ReaderWriterSet MBReaderWriterSet;
+#endif

Added: MOAB/trunk/src/oldinc/MBSkinner.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBSkinner.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBSkinner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBSkinner_HEADER
+#define MBSkinner_HEADER
+#include "moab/Skinner.hpp"
+typedef moab::Skinner MBSkinner;
+#endif

Added: MOAB/trunk/src/oldinc/MBTypes.h
===================================================================
--- MOAB/trunk/src/oldinc/MBTypes.h	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBTypes.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,50 @@
+#ifndef MBTypes_HEADER
+#define MBTypes_HEADER
+
+#include "moab/Types.hpp"
+#include "MBEntityType.h"
+#include "MBEntityHandle.h"
+
+typedef moab::Tag MBTag;
+
+typedef moab::ErrorCode MBErrorCode;
+using moab::MB_SUCCESS;
+using moab::MB_INDEX_OUT_OF_RANGE;
+using moab::MB_MEMORY_ALLOCATION_FAILED;
+using moab::MB_ENTITY_NOT_FOUND;
+using moab::MB_MULTIPLE_ENTITIES_FOUND;
+using moab::MB_TAG_NOT_FOUND;
+using moab::MB_FILE_DOES_NOT_EXIST;
+using moab::MB_FILE_WRITE_ERROR;
+using moab::MB_NOT_IMPLEMENTED;
+using moab::MB_ALREADY_ALLOCATED;
+using moab::MB_VARIABLE_DATA_LENGTH;
+using moab::MB_INVALID_SIZE;
+using moab::MB_UNSUPPORTED_OPERATION;
+using moab::MB_UNHANDLED_OPTION;
+using moab::MB_FAILURE;
+
+typedef moab::Constants MBConstants;
+using moab::MB_VARIABLE_LENGTH;
+
+typedef moab::TagType MBTagType;
+using moab::MB_TAG_BIT;
+using moab::MB_TAG_SPARSE;
+using moab::MB_TAG_DENSE;
+using moab::MB_TAG_MESH;
+using moab::MB_TAG_LAST;
+
+typedef moab::DataType MBDataType;
+using moab::MB_TYPE_OPAQUE;
+using moab::MB_TYPE_INTEGER;
+using moab::MB_TYPE_DOUBLE;
+using moab::MB_TYPE_BIT;
+using moab::MB_TYPE_HANDLE;
+using moab::MB_MAX_DATA_TYPE;
+
+typedef moab::EntitySetProperty MBEntitySetProperty;
+using moab::MESHSET_TRACK_OWNER;
+using moab::MESHSET_SET;
+using moab::MESHSET_ORDERED;
+
+#endif

Added: MOAB/trunk/src/oldinc/MBUnknownInterface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBUnknownInterface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBUnknownInterface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBUnknownInterface_HEADER
+#define MBUnknownInterface_HEADER
+#include "moab/UnknownInterface.hpp"
+typedef moab::UnknownInterface MBUnknownInterface;
+#endif

Added: MOAB/trunk/src/oldinc/MBUtil.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBUtil.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,6 @@
+#ifndef MBUtil_HEADER
+#define MBUtil_HEADER
+#include "moab/Util.hpp"
+typedef moab::Coord MBCoord;
+typedef moab::Util  MBUtil;
+#endif

Added: MOAB/trunk/src/oldinc/MBVersion.h
===================================================================
--- MOAB/trunk/src/oldinc/MBVersion.h	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBVersion.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,4 @@
+#ifndef MBVersion_HEADER
+#define MBVersion_HEADER
+#include "moab/Version.h"
+#endif

Added: MOAB/trunk/src/oldinc/MBWriteUtilIface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBWriteUtilIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBWriteUtilIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBWriteUtilIface_HEADER
+#define MBWriteUtilIface_HEADER
+#include "moab/WriteUtilIface.hpp"
+typedef moab::WriteUtilIface MBWriteUtilIface;
+#endif

Added: MOAB/trunk/src/oldinc/MBWriterIface.hpp
===================================================================
--- MOAB/trunk/src/oldinc/MBWriterIface.hpp	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBWriterIface.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,5 @@
+#ifndef MBWriterIface_HEADER
+#define MBWriterIface_HEADER
+#include "moab/WriterIface.hpp"
+typedef moab::WriterIface MBWriterIface;
+#endif

Added: MOAB/trunk/src/oldinc/MBmpi.h
===================================================================
--- MOAB/trunk/src/oldinc/MBmpi.h	                        (rev 0)
+++ MOAB/trunk/src/oldinc/MBmpi.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,4 @@
+#ifndef MBmpi_HEADER
+#define MBmpi_HEADER
+#include "moab_mpi.h"
+#endif


Property changes on: MOAB/trunk/src/oldinc/MBmpi.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Added: MOAB/trunk/src/oldinc/Makefile.am
===================================================================
--- MOAB/trunk/src/oldinc/Makefile.am	                        (rev 0)
+++ MOAB/trunk/src/oldinc/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,24 @@
+
+include_HEADERS = MBAdaptiveKDTree.hpp \
+                  MBBSPTree.hpp \
+                  MBCore.hpp \
+                  MBEntityHandle.h \
+                  MBForward.hpp \
+                  MBGeomUtil.hpp \
+                  MBInterface.hpp \
+                  MBmpi.h \
+                  MBOrientedBoxTreeTool.hpp \
+                  MBParallelComm.hpp \
+                  MBParallelData.hpp \
+                  MBProcConfig.hpp \
+                  MBRange.hpp \
+                  MBReaderIface.hpp \
+                  MBReaderWriterSet.hpp \
+                  MBReadUtilIface.hpp \
+                  MBSkinner.hpp \
+                  MBTypes.h \
+                  MBUnknownInterface.hpp \
+                  MBUtil.hpp \
+                  MBVersion.h \
+                  MBWriterIface.hpp \
+                  MBWriteUtilIface.hpp

Modified: MOAB/trunk/src/parallel/CMakeLists.txt
===================================================================
--- MOAB/trunk/src/parallel/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
 set( moab_PARALLEL_SRCS
-  MBParallelComm.cpp
-  MBProcConfig.cpp
-  MBParallelData.cpp
+  ParallelComm.cpp
+  ProcConfig.cpp
+  ParallelData.cpp
   ReadParallel.cpp
   crystal.c
   errmem.c

Deleted: MOAB/trunk/src/parallel/MBParallelComm.cpp
===================================================================
--- MOAB/trunk/src/parallel/MBParallelComm.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/MBParallelComm.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6245 +0,0 @@
-#include "MBInterface.hpp"
-#include "MBParallelComm.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MBReadUtilIface.hpp"
-#include "SequenceManager.hpp"
-#include "EntitySequence.hpp"
-#include "TagServer.hpp"
-#include "MBTagConventions.hpp"
-#include "MBSkinner.hpp"
-#include "MBParallelConventions.h"
-#include "MBCore.hpp"
-#include "MBError.hpp"
-#include "ElementSequence.hpp"
-#include "MBCN.hpp"
-#include "RangeMap.hpp"
-#include "MeshTopoUtil.hpp"
-
-#include <iostream>
-#include <sstream>
-#include <algorithm>
-#include <functional>
-#include <numeric>
-
-#define MIN(a,b) (a < b ? a : b)
-#define MAX(a,b) (a > b ? a : b)
-const bool debug = false;
-
-#include <math.h>
-#include <assert.h>
-
-
-
-extern "C" 
-{
-#include "types.h"
-#include "minmax.h"
-#include "gs.h"
-#include "errmem.h"
-#include "sort.h"
-#include "tuple_list.h"
-}
-
-#ifdef USE_MPI
-#include "MBmpi.h"
-#endif
-
-const unsigned int MBParallelComm::INITIAL_BUFF_SIZE = 1024;
-
-const int MAX_BCAST_SIZE = (1<<28);
-
-#undef DEBUG_MPE
-//#define DEBUG_MPE 1
-#ifdef DEBUG_MPE
-#include "mpe.h"
-int IFACE_START, IFACE_END;
-int GHOST_START, GHOST_END;
-int SHAREDV_START, SHAREDV_END;
-int RESOLVE_START, RESOLVE_END;
-int ENTITIES_START, ENTITIES_END;
-int RHANDLES_START, RHANDLES_END;
-
-#endif
-#undef DEBUG_COMM
-//#define DEBUG_COMM 1
-#undef DEBUG_PACKING
-#undef DEBUG_MSGS
-//#define DEBUG_MSGS 1
-#undef DEBUG_BARRIER
-#define DEBUG_BARRIER 1
-#ifdef DEBUG_MSGS
-std::vector<MBParallelComm::Buffer*> msgs;
-#endif
-#ifdef DEBUG_PACKING
-unsigned int __PACK_num = 0, __UNPACK_num = 0, __PACK_count = 0, __UNPACK_count = 0;
-std::string __PACK_string, __UNPACK_string;
-
-#define PC(n, m) {\
-          if (__PACK_num == (unsigned int)n && __PACK_string == m) __PACK_count++;\
-          else {\
-            if (__PACK_count > 1) std::cerr << " (" << __PACK_count << "x)";\
-            __PACK_count = 1; __PACK_string = m; __PACK_num = n;\
-            std::cerr << std::endl << "PACK: " << n << m;\
-          }}
-#define UPC(n, m) {\
-          if (__UNPACK_num == (unsigned int)n && __UNPACK_string == m) __UNPACK_count++;\
-          else {\
-            if (__UNPACK_count > 1) std::cerr << "(" << __UNPACK_count << "x)";\
-            __UNPACK_count = 1; __UNPACK_string = m; __UNPACK_num = n;\
-            std::cerr << std::endl << "UNPACK: " << n << m;\
-          }}
-#else
-#define PC(n, m)
-#define UPC(n, m)
-#endif
-
-template <typename T> static inline
-void UNPACK( unsigned char*& buff, T* val, size_t count )
-{
-  memcpy( val, buff, count*sizeof(T) );
-  buff += count*sizeof(T);
-}
-
-template <typename T> static inline
-void PACK( unsigned char*& buff, const T* val, size_t count )
-{
-  memcpy( buff, val, count*sizeof(T) );
-  buff += count*sizeof(T);
-}
-
-static inline
-void PACK_INTS( unsigned char*& buff, const int* int_val, size_t num )
-  { PACK( buff, int_val, num ); PC(num, " ints"); }
-
-static inline
-void PACK_INT( unsigned char*& buff, int int_val )
-  { PACK_INTS( buff, &int_val, 1 ); }
-
-static inline
-void PACK_DBL( unsigned char*& buff, const double* dbl_val, size_t num )
-  { PACK( buff, dbl_val, num ); PC(num, " doubles"); }
-
-static inline
-void PACK_EH( unsigned char*& buff, const MBEntityHandle* eh_val, size_t num )
-  { PACK( buff, eh_val, num ); PC(num, " handles"); }
-
-static inline
-void PACK_CHAR_64( unsigned char*& buff, const char* str )
-{
-  strncpy( reinterpret_cast<char*>(buff), str, 64 );
-  buff += 64;
-  PC(64, " chars");
-}
-
-static inline
-void PACK_VOID( unsigned char*& buff, const void* val, size_t num )
-{
-  PACK( buff, reinterpret_cast<const unsigned char*>(val), num );
-  PC(num, " void");
-}
-
-static inline
-void PACK_BYTES( unsigned char*& buff, const void* val, int num )
-  { PACK_INT(buff, num); PACK_VOID(buff, val, num); }
-
-static inline
-void PACK_RANGE( unsigned char*& buff, const MBRange& rng )
-{
-  PACK_INT( buff, rng.psize() );
-  MBRange::const_pair_iterator cit;
-  for (cit = rng.const_pair_begin(); cit != rng.const_pair_end(); ++cit) {
-    MBEntityHandle eh[2] = { cit->first, cit->second };
-    PACK_EH(buff, eh, 2);
-  }
-  PC(rng.psize(), "-subranged range");
-}
-
-static inline
-void UNPACK_INTS( unsigned char*& buff, int* int_val, size_t num )
-  { UNPACK(buff, int_val, num); UPC(num, " ints"); }
-
-static inline
-void UNPACK_INT( unsigned char*& buff, int& int_val )
-  { UNPACK_INTS( buff, &int_val, 1 ); }
-
-static inline
-void UNPACK_DBL( unsigned char*& buff, double* dbl_val, size_t num )
-  { UNPACK(buff, dbl_val, num); UPC(num, " doubles"); }
-
-static inline
-void UNPACK_EH( unsigned char*& buff, MBEntityHandle* eh_val, size_t num )
-  { UNPACK(buff, eh_val, num); UPC(num, " handles"); }
-
-static inline
-void UNPACK_CHAR_64( unsigned char*& buff, char* char_val )
-{
-  memcpy( buff, char_val, 64 );
-  buff += 64;
-  UPC(64, " chars");
-}
-
-static inline
-void UNPACK_VOID( unsigned char*& buff, void* val, size_t num )
-{
-  UNPACK(buff, reinterpret_cast<unsigned char*>(val), num);
-  UPC(num, " void");
-}
-
-static inline
-void UNPACK_TYPE( unsigned char*& buff, MBEntityType& type )
-{
-  int int_type = MBMAXTYPE;
-  UNPACK_INT(buff, int_type);
-  type = static_cast<MBEntityType>(int_type);
-  assert(type >= MBVERTEX && type <= MBMAXTYPE);
-}
-
-static inline
-void UNPACK_RANGE( unsigned char*& buff, MBRange& rng )
-{
-  int num_subs;
-  MBEntityHandle eh[2];
-  UNPACK_INT( buff, num_subs );
-  for (int i = 0; i < num_subs; ++i) {
-    UPC(num_subs, "-subranged range"); 
-    UNPACK_EH(buff, eh, 2); 
-    rng.insert(eh[0], eh[1]);
-  }
-}    
-
-enum MBMessageTag {MB_MESG_ANY=MPI_ANY_TAG, 
-                   MB_MESG_ENTS_ACK,
-                   MB_MESG_ENTS_SIZE,
-                   MB_MESG_ENTS_LARGE,
-                   MB_MESG_REMOTEH_ACK,
-                   MB_MESG_REMOTEH_SIZE,
-                   MB_MESG_REMOTEH_LARGE,
-                   MB_MESG_TAGS_ACK,
-                   MB_MESG_TAGS_SIZE,
-                   MB_MESG_TAGS_LARGE};
-    
-static inline size_t RANGE_SIZE(const MBRange& rng)
-  { return 2*sizeof(MBEntityHandle)*rng.psize()+sizeof(int); }
-
-static inline void PRINT_DEBUG_ISEND(int from, int to, unsigned char *buff,
-                                     int tag, int size) 
-{
-#ifdef DEBUG_COMM
-  std::cerr << "Isend, " << from << "->" << to
-            << ", buffer ptr = " << (void*)buff << ", tag=" << tag 
-            << ", size=" << size << std::endl; std::cerr.flush();
-#endif
-}
-
-static inline void PRINT_DEBUG_IRECV(int to, int from, unsigned char *buff, int size,
-                                     int tag, int incoming) 
-{
-#ifdef DEBUG_COMM
-  std::cerr << "Irecv, " << to << "<-" << from << ", buffer ptr=" << (void*)buff
-            << ", size=" << size << ", tag=" << tag
-            << (tag < MB_MESG_REMOTEH_ACK ? ", incoming1=" : 
-                (tag < MB_MESG_TAGS_ACK ? ", incoming2=" : ", incoming="))
-            << incoming << std::endl; std::cerr.flush();
-#endif
-}
-
-static inline void PRINT_DEBUG_RECD(MPI_Status status) 
-{
-#ifdef DEBUG_COMM
-  int this_count;
-  int success = MPI_Get_count(&status, MPI_UNSIGNED_CHAR, &this_count);
-  if (MPI_SUCCESS != success) this_count = -1;
-  std::cerr << "Received from " << status.MPI_SOURCE
-            << ", count = " << this_count 
-            << ", tag = " << status.MPI_TAG
-            << std::endl; std::cerr.flush();
-#endif    
-}
-
-static inline void PRINT_DEBUG_WAITANY(std::vector<MPI_Request> &reqs, int tag, int proc) 
-{
-#ifdef DEBUG_COMM
-  std::cerr << "Waitany, p=" << proc
-            << (tag < MB_MESG_REMOTEH_ACK ? ", recv_ent_reqs = " : 
-                (tag < MB_MESG_TAGS_ACK ? ", recv_remoteh_reqs = " : ", recv_tag_reqs = "));
-  for (unsigned int i = 0; i < reqs.size(); i++) std::cerr << " " << reqs[i];
-  std::cerr << std::endl; std::cerr.flush();
-#endif
-}
-
-
-#define RR(a) if (MB_SUCCESS != result) {\
-          dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(a);\
-          return result;}
-
-#define RRA(a) if (MB_SUCCESS != result) {\
-      std::string tmp_str; mbImpl->get_last_error(tmp_str);\
-      tmp_str.append("\n"); tmp_str.append(a);\
-      dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(tmp_str); \
-      return result;}
-
-#define RRAI(i, a) if (MB_SUCCESS != result) {                \
-      std::string tmp_str; i->get_last_error(tmp_str);\
-      tmp_str.append("\n"); tmp_str.append(a);\
-      dynamic_cast<MBCore*>(i)->get_error_handler()->set_last_error(tmp_str); \
-      return result;}
-
-/** Name of tag used to store MBParallelComm Index on mesh paritioning sets */
-const char* PARTITIONING_PCOMM_TAG_NAME = "__PRTN_PCOMM";
- 
-/** \brief Tag storing parallel communication objects
- *
- * This tag stores pointers to MBParallelComm communication
- * objects; one of these is allocated for each different
- * communicator used to read mesh.  MBParallelComm stores
- * partition and interface sets corresponding to its parallel mesh.
- * By default, a parallel read uses the first MBParallelComm object
- * on the interface instance; if instantiated with one, ReadParallel
- * adds this object to the interface instance too.
- *
- * Tag type: opaque
- * Tag size: MAX_SHARING_PROCS*sizeof(MBParallelComm*)
- */
-#define PARALLEL_COMM_TAG_NAME "__PARALLEL_COMM"
-
-
-MBParallelComm::MBParallelComm(MBInterface *impl, MPI_Comm comm, int* id ) 
-        : mbImpl(impl), procConfig(comm),
-          sharedpTag(0), sharedpsTag(0), 
-          sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0),
-          partitionTag(0), globalPartCount(-1), partitioningSet(0)
-{
-  initialize();
-  
-  if (id)
-    *id = pcommID;
-}
-
-MBParallelComm::MBParallelComm(MBInterface *impl,
-                               std::vector<unsigned char> &tmp_buff, 
-                               MPI_Comm comm,
-                               int* id) 
-    : mbImpl(impl), procConfig(comm),
-      sharedpTag(0), sharedpsTag(0), 
-      sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0),
-      partitionTag(0), globalPartCount(-1), partitioningSet(0)
-{
-  initialize();
-  
-  if (id)
-    *id = pcommID;
-}
-
-MBParallelComm::~MBParallelComm() 
-{
-  remove_pcomm(this);
-  delete_all_buffers();
-}
-
-void MBParallelComm::initialize() 
-{
-  tagServer = dynamic_cast<MBCore*>(mbImpl)->tag_server();
-  sequenceManager = dynamic_cast<MBCore*>(mbImpl)->sequence_manager();
-  
-    // initialize MPI, if necessary
-  int flag = 1;
-  int retval = MPI_Initialized(&flag);
-  if (MPI_SUCCESS != retval || !flag) {
-    int argc = 0;
-    char **argv = NULL;
-    
-      // mpi not initialized yet - initialize here
-    retval = MPI_Init(&argc, &argv);
-  }
-
-    // reserve space for vectors
-  buffProcs.reserve(MAX_SHARING_PROCS);
-  localOwnedBuffs.reserve(MAX_SHARING_PROCS);
-  remoteOwnedBuffs.reserve(MAX_SHARING_PROCS);
-
-  pcommID = add_pcomm(this);
-}
-
-int MBParallelComm::add_pcomm(MBParallelComm *pc) 
-{
-    // add this pcomm to instance tag
-  std::vector<MBParallelComm *> pc_array(MAX_SHARING_PROCS, 
-                                         (MBParallelComm*)NULL);
-  MBTag pc_tag = pcomm_tag(mbImpl, true);
-  assert(0 != pc_tag);
-  
-  MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]);
-  if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) 
-    return -1;
-  int index = 0;
-  while (index < MAX_SHARING_PROCS && pc_array[index]) index++;
-  if (index == MAX_SHARING_PROCS) {
-    index = -1;
-    assert(false);
-  }
-  else {
-    pc_array[index] = pc;
-    mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]);
-  }
-  return index;
-}
-
-void MBParallelComm::remove_pcomm(MBParallelComm *pc) 
-{
-    // remove this pcomm from instance tag
-  std::vector<MBParallelComm *> pc_array(MAX_SHARING_PROCS);
-  MBTag pc_tag = pcomm_tag(mbImpl, true);
-  
-  MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]);
-  std::vector<MBParallelComm*>::iterator pc_it = 
-    std::find(pc_array.begin(), pc_array.end(), pc);
-  assert(MB_SUCCESS == result && 
-         pc_it != pc_array.end());
-  *pc_it = NULL;
-  mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]);
-}
-
-//! assign a global id space, for largest-dimension or all entities (and
-//! in either case for vertices too)
-MBErrorCode MBParallelComm::assign_global_ids(MBEntityHandle this_set,
-                                              const int dimension, 
-                                              const int start_id,
-                                              const bool largest_dim_only,
-                                              const bool parallel) 
-{
-  MBRange entities[4];
-  int local_num_elements[4];
-  MBErrorCode result;
-  std::vector<unsigned char> pstatus;
-  for (int dim = 0; dim <= dimension; dim++) {
-    if (dim == 0 || !largest_dim_only || dim == dimension) {
-      result = mbImpl->get_entities_by_dimension(this_set, dim, entities[dim]); 
-      RRA("Failed to get vertices in assign_global_ids.");
-    }
-
-      // need to filter out non-locally-owned entities!!!
-    pstatus.resize(entities[dim].size());
-    result = mbImpl->tag_get_data(pstatus_tag(), entities[dim], &pstatus[0]);
-    RRA("Failed to get pstatus in assign_global_ids.");
-    
-    MBRange dum_range;
-    MBRange::iterator rit;
-    unsigned int i;
-    for (rit = entities[dim].begin(), i = 0; rit != entities[dim].end(); rit++, i++)
-      if (pstatus[i] & PSTATUS_NOT_OWNED)
-        dum_range.insert(*rit);
-    entities[dim] = subtract( entities[dim], dum_range);
-    
-    local_num_elements[dim] = entities[dim].size();
-  }
-  
-    // communicate numbers
-  std::vector<int> num_elements(procConfig.proc_size()*4);
-#ifdef USE_MPI
-  if (procConfig.proc_size() > 1 && parallel) {
-    int retval = MPI_Allgather(local_num_elements, 4, MPI_INT,
-                               &num_elements[0], 4, 
-                               MPI_INT, procConfig.proc_comm());
-    if (0 != retval) return MB_FAILURE;
-  }
-  else
-#endif
-    for (int dim = 0; dim < 4; dim++) num_elements[dim] = local_num_elements[dim];
-  
-    // my entities start at one greater than total_elems[d]
-  int total_elems[4] = {start_id, start_id, start_id, start_id};
-  
-  for (unsigned int proc = 0; proc < procConfig.proc_rank(); proc++) {
-    for (int dim = 0; dim < 4; dim++) total_elems[dim] += num_elements[4*proc + dim];
-  }
-  
-    //assign global ids now
-  MBTag gid_tag;
-  int zero = 0;
-  result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), 
-                              MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
-                              &zero, true);
-  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
-  
-  for (int dim = 0; dim < 4; dim++) {
-    if (entities[dim].empty()) continue;
-    num_elements.resize(entities[dim].size());
-    int i = 0;
-    for (MBRange::iterator rit = entities[dim].begin(); rit != entities[dim].end(); rit++)
-      num_elements[i++] = total_elems[dim]++;
-    
-    result = mbImpl->tag_set_data(gid_tag, entities[dim], &num_elements[0]); 
-    RRA("Failed to set global id tag in assign_global_ids.");
-  }
-  
-  return MB_SUCCESS;
-}
-
-int MBParallelComm::get_buffers(int to_proc, bool *is_new) 
-{
-  int ind = -1;
-  std::vector<unsigned int>::iterator vit = 
-    std::find(buffProcs.begin(), buffProcs.end(), to_proc);
-  if (vit == buffProcs.end()) {
-    ind = buffProcs.size();
-    buffProcs.push_back((unsigned int)to_proc);
-    localOwnedBuffs.push_back(new Buffer(INITIAL_BUFF_SIZE));
-    remoteOwnedBuffs.push_back(new Buffer(INITIAL_BUFF_SIZE));
-    if (is_new) *is_new = true;
-  }
-  else {
-    ind = vit - buffProcs.begin();
-    if (is_new) *is_new = false;
-  }
-  assert(ind < MAX_SHARING_PROCS);
-  return ind;
-}
-
-MBErrorCode MBParallelComm::broadcast_entities( const int from_proc,
-                                                MBRange &entities,
-                                                const bool adjacencies,
-                                                const bool tags) 
-{
-#ifndef USE_MPI
-  return MB_FAILURE;
-#else
-  
-  MBErrorCode result = MB_SUCCESS;
-  int success;
-  int buff_size;
-
-  Buffer buff(INITIAL_BUFF_SIZE);
-  buff.reset_ptr(sizeof(int));
-  if ((int)procConfig.proc_rank() == from_proc) {
-    result = add_verts(entities);
-    RRA("Failed to add adj vertices.");
-
-    buff.reset_ptr(sizeof(int));
-    result = pack_buffer( entities, adjacencies, tags, 
-                          false, -1, &buff); 
-    RRA("Failed to compute buffer size in broadcast_entities.");
-    buff.set_stored_size();
-    buff_size = buff.buff_ptr - buff.mem_ptr;
-  }
-
-  success = MPI_Bcast( &buff_size, 1, MPI_INT, from_proc, procConfig.proc_comm() );
-  if (MPI_SUCCESS != success) {
-    result = MB_FAILURE;
-    RRA("MPI_Bcast of buffer size failed.");
-  }
-  
-  if (!buff_size) // no data
-    return MB_SUCCESS;
-
-  if ((int)procConfig.proc_rank() != from_proc) 
-    buff.reserve(buff_size);
-
-  size_t offset = 0;
-  while (buff_size) {
-    int size = std::min( buff_size, MAX_BCAST_SIZE );
-    success = MPI_Bcast(buff.mem_ptr+offset, size, MPI_UNSIGNED_CHAR, from_proc, procConfig.proc_comm() );
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("MPI_Bcast of buffer failed.");
-    }
-    
-    offset += size;
-    buff_size -= size;
-  }
-
-  if ((int)procConfig.proc_rank() != from_proc) {
-    std::vector<std::vector<MBEntityHandle> > dum1a, dum1b;
-    std::vector<std::vector<int> > dum1p;
-    std::vector<MBEntityHandle> dum2;
-    std::vector<unsigned int> dum3;
-    buff.reset_ptr(sizeof(int));
-    result = unpack_buffer(buff.buff_ptr, false, from_proc, -1, 
-                           dum1a, dum1b, dum1p, dum2, dum2, dum3, entities);
-    RRA("Failed to unpack buffer in broadcast_entities.");
-  }
-
-  return MB_SUCCESS;
-#endif
-}
-
-MBErrorCode MBParallelComm::pack_buffer(MBRange &orig_ents, 
-                                        const bool adjacencies,
-                                        const bool tags,
-                                        const bool store_remote_handles,
-                                        const int to_proc,
-                                        Buffer *buff) 
-{
-    // pack the buffer with the entity ranges, adjacencies, and tags sections
-    // 
-    // Note: new entities used in subsequent connectivity lists, sets, or tags, 
-    //   are referred to as (MBMAXTYPE + index), where index is into vector 
-    //   of new entities, 0-based
-  MBErrorCode result;
-
-  MBRange set_range;
-  std::vector<MBRange> set_ranges;
-  std::vector<MBTag> all_tags;
-  std::vector<MBRange> tag_ranges;
-  std::vector<int> set_sizes;
-  std::vector<unsigned int> options_vec;
-
-  MBRange::const_iterator rit;
-
-    // entities
-  result = pack_entities(orig_ents, buff,
-                         store_remote_handles, to_proc, false); 
-  RRA("Packing entities failed.");
-  
-    // sets
-  result = pack_sets(orig_ents, buff,
-                     store_remote_handles, to_proc); 
-  RRA("Packing sets (count) failed.");
-
-    // tags
-  MBRange final_ents;
-  if (tags) {
-    result = get_tag_send_list(orig_ents, all_tags, tag_ranges );
-    RRA("Failed to get tagged entities.");
-    result = pack_tags(orig_ents, all_tags, all_tags, tag_ranges, 
-                       buff, store_remote_handles, to_proc);
-    RRA("Packing tags (count) failed.");
-  }
-
-  return result;
-}
- 
-MBErrorCode MBParallelComm::unpack_buffer(unsigned char *buff_ptr,
-                                          const bool store_remote_handles,
-                                          const int from_proc,
-                                          const int ind,
-                                          std::vector<std::vector<MBEntityHandle> > &L1hloc,
-                                          std::vector<std::vector<MBEntityHandle> > &L1hrem,
-                                          std::vector<std::vector<int> > &L1p,
-                                          std::vector<MBEntityHandle> &L2hloc, 
-                                          std::vector<MBEntityHandle> &L2hrem,
-                                          std::vector<unsigned int> &L2p,
-                                          MBRange &new_ents) 
-{
-#ifdef DEBUG_PACKING
-    unsigned char *tmp_buff = buff_ptr;
-#endif  
-    MBErrorCode result;
-    result = unpack_entities(buff_ptr, store_remote_handles,
-                             ind, false, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents);
-  RRA("Unpacking entities failed.");
-#ifdef DEBUG_PACKING
-    std::cerr << "unpack_entities buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
-    tmp_buff = buff_ptr;
-#endif  
-  result = unpack_sets(buff_ptr, new_ents, store_remote_handles, from_proc);
-  RRA("Unpacking sets failed.");
-#ifdef DEBUG_PACKING
-    std::cerr << "unpack_sets buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
-    tmp_buff = buff_ptr;
-#endif  
-  result = unpack_tags(buff_ptr, new_ents, store_remote_handles, from_proc);
-  RRA("Unpacking tags failed.");
-#ifdef DEBUG_PACKING
-    std::cerr << "unpack_tags buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
-    tmp_buff = buff_ptr;
-#endif  
-
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl;
-#endif
-  
-  return MB_SUCCESS;
-}
-
-int MBParallelComm::num_subranges(const MBRange &this_range)
-{
-    // ok, have all the ranges we'll pack; count the subranges
-  int num_sub_ranges = 0;
-  for (MBRange::const_pair_iterator pit = this_range.const_pair_begin(); 
-       pit != this_range.const_pair_end(); pit++)
-    num_sub_ranges++;
-
-  return num_sub_ranges;
-}
-
-int MBParallelComm::estimate_ents_buffer_size(MBRange &entities,
-                                              const bool store_remote_handles) 
-{
-  int buff_size = 0;
-  std::vector<MBEntityHandle> dum_connect_vec;
-  const MBEntityHandle *connect;
-  int num_connect;
-
-  int num_verts = entities.num_of_type(MBVERTEX);
-    // # verts + coords + handles
-  buff_size += 2*sizeof(int) + 3*sizeof(double)*num_verts;
-  if (store_remote_handles) buff_size += sizeof(MBEntityHandle)*num_verts;
-
-    // do a rough count by looking at first entity of each type
-  for (MBEntityType t = MBEDGE; t < MBENTITYSET; t++) {
-    const MBRange::iterator rit = entities.lower_bound(t);
-    if (TYPE_FROM_HANDLE(*rit) != t) continue;
-    
-    MBErrorCode result = mbImpl->get_connectivity(*rit, connect, num_connect, 
-                                                  true, &dum_connect_vec);
-    RRA("Failed to get connectivity to estimate buffer size.");
-
-      // number, type, nodes per entity
-    buff_size += 3*sizeof(int);
-    int num_ents = entities.num_of_type(t);
-      // connectivity, handle for each ent
-    buff_size += (num_connect+1)*sizeof(MBEntityHandle)*num_ents;
-  }
-
-      // extra entity type at end, passed as int
-  buff_size += sizeof(int);
-
-  return buff_size;
-}
-
-int MBParallelComm::estimate_sets_buffer_size(MBRange &entities,
-                                              const bool store_remote_handles) 
-{
-    // number of sets
-  int buff_size = sizeof(int);
-  
-    // do a rough count by looking at first entity of each type
-  MBRange::iterator rit = entities.lower_bound(MBENTITYSET);
-  MBErrorCode result;
-  
-  for (; rit != entities.end(); rit++) {
-    unsigned int options;
-    result = mbImpl->get_meshset_options(*rit, options);
-    RRA("Failed to get meshset options.");
-
-    buff_size += sizeof(int);
-    
-    MBRange set_range;
-    if (options & MESHSET_SET) {
-        // range-based set; count the subranges
-      result = mbImpl->get_entities_by_handle(*rit, set_range);
-      RRA("Failed to get set entities.");
-
-        // set range
-      buff_size += RANGE_SIZE(set_range);
-    }
-    else if (options & MESHSET_ORDERED) {
-        // just get the number of entities in the set
-      int num_ents;
-      result = mbImpl->get_number_entities_by_handle(*rit, num_ents);
-      RRA("Failed to get number entities in ordered set.");
-
-        // set vec
-      buff_size += sizeof(MBEntityHandle) * num_ents + sizeof(int);
-    }
-
-      // get numbers of parents/children
-    int num_par, num_ch;
-    result = mbImpl->num_child_meshsets(*rit, &num_ch);
-    RRA("Failed to get num children.");
-
-    result = mbImpl->num_parent_meshsets(*rit, &num_par);
-    RRA("Failed to get num parents.");
-
-    buff_size += (num_ch + num_par) * sizeof(MBEntityHandle) + 2*sizeof(int);
-  }
-
-  return buff_size;
-}
-
-MBErrorCode MBParallelComm::pack_entities(MBRange &entities,
-                                          Buffer *buff,
-                                          const bool store_remote_handles,
-                                          const int to_proc,
-                                          const bool is_iface,
-                                          std::vector<std::set<unsigned int> > *entprocs,
-                                          MBRange *allsent) 
-{
-    // packed information:
-    // 1. # entities = E
-    // 2. for e in E
-    //   a. # procs sharing e, incl. sender and receiver = P
-    //   b. for p in P (procs sharing e)
-    //   c. for p in P (handle for e on p) (Note1)
-    // 3. vertex/entity info
-
-    // get an estimate of the buffer size & pre-allocate buffer size
-  unsigned int buff_size = estimate_ents_buffer_size(entities, 
-                                                     store_remote_handles);
-  buff->check_space(buff_size);
-  
-  MBWriteUtilIface *wu;
-  MBErrorCode result = mbImpl->query_interface(std::string("MBWriteUtilIface"), 
-                                               reinterpret_cast<void**>(&wu));
-  RRA("Couldn't get MBWriteUtilIface.");
-
-  unsigned int num_ents;
-
-    // first pack procs/handles sharing this ent, not including this dest but including
-    // others (with zero handles)
-  if (store_remote_handles) {
-
-      // buff space is at least proc+handle for each entity; use avg of 4 other procs
-      // to estimate buff size, but check later
-    buff->check_space(sizeof(int) + (5*sizeof(int) + sizeof(MBEntityHandle))*entities.size());
-
-      // 1. # entities = E
-    PACK_INT(buff->buff_ptr, entities.size());
-  
-    MBRange::iterator rit;
-  
-      // pre-fetch sharedp and pstatus
-    std::vector<int> sharedp_vals(entities.size());
-    result = mbImpl->tag_get_data(sharedp_tag(), entities, &sharedp_vals[0]);
-    RRA("Failed to get sharedp_tag.");
-    std::vector<char> pstatus_vals(entities.size());
-    result = mbImpl->tag_get_data(pstatus_tag(), entities, &pstatus_vals[0]);
-    RRA("Failed to get sharedp_tag.");
-  
-    unsigned int i;
-    std::vector<std::set<unsigned int> >::iterator vit;
-    int tmp_procs[MAX_SHARING_PROCS];
-    MBEntityHandle tmp_handles[MAX_SHARING_PROCS];
-    std::set<unsigned int> dumprocs;
-
-      // 2. for e in E
-    for (rit = entities.begin(), i = 0; 
-         rit != entities.end(); rit++, i++) {
-      result = build_sharedhps_list(*rit, pstatus_vals[i], sharedp_vals[i],
-                                    (entprocs ? (*entprocs)[allsent->index(*rit)] : dumprocs),
-                                    num_ents, tmp_procs, tmp_handles);
-      RRA("Failed to build sharedhps.");
-
-        // now pack them
-      buff->check_space((num_ents+1)*sizeof(int) + 
-                       num_ents*sizeof(MBEntityHandle));
-      PACK_INT(buff->buff_ptr, num_ents);
-      PACK_INTS(buff->buff_ptr, tmp_procs, num_ents);
-      PACK_EH(buff->buff_ptr, tmp_handles, num_ents);
-
-#ifndef NDEBUG
-        // check for duplicates in proc list
-      unsigned int dp = 0;
-      for (; dp < MAX_SHARING_PROCS && -1 != tmp_procs[dp]; dp++)
-        dumprocs.insert(tmp_procs[dp]);
-      assert(dumprocs.size() == dp);
-      dumprocs.clear();
-#endif      
-    }
-  }
-  
-    // pack vertices
-  MBRange these_ents = entities.subset_by_type(MBVERTEX);
-  num_ents = these_ents.size();
-
-  if (num_ents) {
-    buff_size = 2*sizeof(int) + 3*num_ents*sizeof(double);
-    buff->check_space(buff_size);
-
-    // type, # ents
-    PACK_INT(buff->buff_ptr, ((int) MBVERTEX));
-    PACK_INT(buff->buff_ptr, ((int) num_ents));
-
-    result = mbImpl->get_coords(these_ents, (double*)buff->buff_ptr);
-    RRA("Couldn't get vertex coordinates.");
-    PC(3*num_ents, " doubles");
-
-    buff->buff_ptr += 3 * num_ents * sizeof(double);
-
-#ifdef DEBUG_PACKING
-  std::cerr << "Packed " << these_ents.size() << " ents of type " 
-            << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*these_ents.begin())) << std::endl;
-#endif      
-  }
-
-    // now entities; go through range, packing by type and equal # verts per element
-  MBRange::iterator start_rit = entities.find(*these_ents.rbegin());
-  start_rit++;
-  int last_nodes = -1;
-  MBEntityType last_type = MBMAXTYPE;
-  these_ents.clear();
-  MBRange::iterator end_rit = start_rit;
-  EntitySequence *seq;
-  ElementSequence *eseq;
-  
-  while (start_rit != entities.end() || !these_ents.empty()) {
-      // cases:
-      // A: !end, last_type == MAXTYPE, seq: save contig sequence in these_ents
-      // B: !end, last type & nodes same, seq: save contig sequence in these_ents
-      // C: !end, last type & nodes different: pack these_ents, then save contig sequence in these_ents
-      // D: end: pack these_ents
-
-      // find the sequence holding current start entity, if we're not at end
-    eseq = NULL;
-    if (start_rit != entities.end()) {
-      result = sequenceManager->find(*start_rit, seq);
-      RRA("Couldn't find entity sequence.");
-      if (NULL == seq) return MB_FAILURE;
-      eseq = dynamic_cast<ElementSequence*>(seq);
-    }
-
-      // pack the last batch if at end or next one is different
-    if (!these_ents.empty() &&
-        (!eseq || eseq->type() != last_type ||
-         last_nodes != (int) eseq->nodes_per_element())) {
-      result = pack_entity_seq(last_nodes, store_remote_handles,
-                               to_proc, these_ents, entities, buff);
-      RRA("Failed to pack entities from a sequence.");
-      these_ents.clear();
-    }
-
-    if (eseq) {
-        // continuation of current range, just save these entities
-        // get position in entities list one past end of this sequence
-      end_rit = entities.lower_bound(start_rit, entities.end(), eseq->end_handle()+1);
-
-        // put these entities in the range
-      std::copy(start_rit, end_rit, mb_range_inserter(these_ents));
-
-      last_type = eseq->type();
-      last_nodes = eseq->nodes_per_element();
-    }
-    else if (start_rit != entities.end() &&
-             TYPE_FROM_HANDLE(*start_rit) == MBENTITYSET)
-      break;
-
-    start_rit = end_rit;
-  }
-
-    // pack MBMAXTYPE to indicate end of ranges
-  buff->check_space(sizeof(int));
-  PACK_INT(buff->buff_ptr, ((int)MBMAXTYPE));
-
-  buff->set_stored_size();
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::build_sharedhps_list(const MBEntityHandle entity,
-                                                 const unsigned char pstatus,
-                                                 const int sharedp, 
-                                                 const std::set<unsigned int> &entprocs,
-                                                 unsigned int &num_ents,
-                                                 int *tmp_procs,
-                                                 MBEntityHandle *tmp_handles)
-{
-  num_ents = 0;
-  unsigned char pstat;
-  MBErrorCode result = get_sharing_data(entity, tmp_procs, tmp_handles,
-                                        pstat, num_ents);
-  RRA("Failed in get_sharing_data.");
-  assert(pstat == pstatus);
-  
-    // build shared proc/handle lists
-    // start with multi-shared, since if it is the owner will be first
-  if (pstatus & PSTATUS_MULTISHARED) {
-  }
-  else if (pstatus & PSTATUS_NOT_OWNED) {
-      // if not multishared and not owned, other sharing proc is owner, put that
-      // one first
-    assert("If not owned, I should be shared too" &&
-           pstatus & PSTATUS_SHARED &&
-           num_ents == 1);
-    tmp_procs[1] = procConfig.proc_rank();
-    tmp_handles[1] = entity;
-    num_ents = 2;
-  }
-  else if (pstatus & PSTATUS_SHARED) {
-      // if not multishared and owned, I'm owner
-    assert("shared and owned, should be only 1 sharing proc" &&
-           1 == num_ents);
-    tmp_procs[1] = tmp_procs[0];
-    tmp_procs[0] = procConfig.proc_rank();
-    tmp_handles[1] = tmp_handles[0];
-    tmp_handles[0] = entity;
-    num_ents = 2;
-  }
-  else {
-      // not shared yet, just add owner (me)
-    tmp_procs[0] = procConfig.proc_rank();
-    tmp_handles[0] = entity;
-    num_ents = 1;
-  }
-
-#ifndef NDEBUG
-  int tmp_ps = num_ents;
-#endif
-  
-    // now add others, with zero handle for now
-  for (std::set<unsigned int>::iterator sit = entprocs.begin();
-       sit != entprocs.end(); sit++) {
-    assert("these procs shouldn't already be in the shared list" &&
-           std::find(tmp_procs, tmp_procs+tmp_ps, *sit) == tmp_procs+tmp_ps);
-    tmp_procs[num_ents] = *sit;
-    tmp_handles[num_ents] = 0;
-    num_ents++;
-  }
-
-    // put -1 after procs and 0 after handles
-  if (MAX_SHARING_PROCS > num_ents) {
-    tmp_procs[num_ents] = -1;
-    tmp_handles[num_ents] = 0;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::pack_entity_seq(const int nodes_per_entity,
-                                            const bool store_remote_handles,
-                                            const int to_proc,
-                                            MBRange &these_ents,
-                                            MBRange &entities,
-                                            Buffer *buff) 
-{
-  int tmp_space = 3*sizeof(int) + nodes_per_entity*these_ents.size()*sizeof(MBEntityHandle);
-  buff->check_space(tmp_space);
-  
-    // pack the entity type
-  PACK_INT(buff->buff_ptr, ((int)TYPE_FROM_HANDLE(*these_ents.begin())));
-
-    // pack # ents
-  PACK_INT(buff->buff_ptr, these_ents.size());
-      
-    // pack the nodes per entity
-  PACK_INT(buff->buff_ptr, nodes_per_entity);
-      
-    // pack the connectivity
-  const MBEntityHandle *connect;
-  int num_connect;
-  std::vector<MBEntityHandle> dum_connect;
-  MBEntityHandle *start_vec = (MBEntityHandle*)buff->buff_ptr;
-  MBErrorCode result = MB_SUCCESS;
-  for (MBRange::const_iterator rit = these_ents.begin(); rit != these_ents.end(); rit++) {
-    result = mbImpl->get_connectivity(*rit, connect, num_connect, false,
-                                      &dum_connect);
-    RRA("Failed to get connectivity.");
-    assert(num_connect == nodes_per_entity);
-    PACK_EH(buff->buff_ptr, connect, num_connect);
-  }
-
-    // substitute destination handles
-  result = get_remote_handles(store_remote_handles, start_vec, start_vec,
-                              nodes_per_entity*these_ents.size(), to_proc,
-                              entities);
-  RRA("Trouble getting remote handles when packing entities.");
-
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Packed " << these_ents.size() << " ents of type " 
-            << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*these_ents.begin())) << std::endl;
-#endif      
-
-  return result;
-}
-
-
-MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles,
-                                               MBEntityHandle *from_vec, 
-                                               MBEntityHandle *to_vec_tmp,
-                                               int num_ents, int to_proc,
-                                               const MBRange &new_ents) 
-{
-    // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE RANGE-BASED VERSION, NO REUSE
-    // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE
-    // OTHER VERSION TOO!!!
-  if (0 == num_ents) return MB_SUCCESS;
-  
-    // use a local destination ptr in case we're doing an in-place copy
-  std::vector<MBEntityHandle> tmp_vector;
-  MBEntityHandle *to_vec = to_vec_tmp;
-  if (to_vec == from_vec) {
-    tmp_vector.resize(num_ents);
-    to_vec = &tmp_vector[0];
-  }
-
-  if (!store_remote_handles) {
-    int err;
-      // in this case, substitute position in new_ents list
-    for (int i = 0; i < num_ents; i++) {
-      int ind = new_ents.index(from_vec[i]);
-      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err);
-      assert(to_vec[i] != 0 && !err && -1 != ind);
-    }
-  }
-  else {
-    MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
-    MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
-                                              sharedh_tag, sharedhs_tag, pstatus_tag);
-  
-      // get single-proc destination handles and shared procs
-    std::vector<int> sharing_procs(num_ents);
-    result = mbImpl->tag_get_data(sharedh_tag, from_vec, num_ents,
-                                  to_vec);
-    RRA("Failed to get shared handle tag for remote_handles.");
-    result = mbImpl->tag_get_data(sharedp_tag, from_vec, num_ents, &sharing_procs[0]);
-    RRA("Failed to get sharing proc tag in remote_handles.");
-    for (int j = 0; j < num_ents; j++) {
-      if (to_vec[j] && sharing_procs[j] != to_proc)
-        to_vec[j] = 0;
-    }
-    
-    MBEntityHandle tmp_handles[MAX_SHARING_PROCS];
-    int tmp_procs[MAX_SHARING_PROCS];
-    int i;
-      // go through results, and for 0-valued ones, look for multiple shared proc
-    MBEntityHandle *tmp_eh;
-    for (tmp_eh = to_vec, i = 0; i < num_ents; i++) {
-      if (!to_vec[i]) {
-        result = mbImpl->tag_get_data(sharedps_tag, from_vec+i, 1, tmp_procs);
-        if (MB_SUCCESS == result) {
-          for (int j = 0; j < MAX_SHARING_PROCS; j++) {
-            if (-1 == tmp_procs[j]) break;
-            else if (tmp_procs[j] == to_proc) {
-              result = mbImpl->tag_get_data(sharedhs_tag, from_vec+i, 1, tmp_handles);
-              RRA("Trouble getting sharedhs tag.");
-              to_vec[i] = tmp_handles[j];
-              assert(to_vec[i]);
-              break;
-            }
-          }
-        }
-        if (!to_vec[i]) {
-          int j = new_ents.index(from_vec[i]);
-          if (-1 == j) {
-            result = MB_FAILURE;
-            RRA("Failed to find new entity in send list.");
-          }
-          int err;
-          to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err);
-          if (err) {
-            result = MB_FAILURE;
-            RRA("Failed to create handle in remote_handles.");
-          }
-        }
-      }
-    }
-  }
-  
-    // memcpy over results if from_vec and to_vec are the same
-  if (to_vec_tmp == from_vec) 
-    memcpy(from_vec, to_vec, num_ents * sizeof(MBEntityHandle));
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles,
-                                               const MBRange &from_range, 
-                                               MBEntityHandle *to_vec,
-                                               int to_proc,
-                                               const MBRange &new_ents) 
-{
-    // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE VECTOR-BASED VERSION, NO REUSE
-    // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE
-    // OTHER VERSION TOO!!!
-  if (from_range.empty()) return MB_SUCCESS;
-  
-  if (!store_remote_handles) {
-    int err;
-      // in this case, substitute position in new_ents list
-    MBRange::iterator rit;
-    unsigned int i;
-    for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) {
-      int ind = new_ents.index(*rit);
-      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err);
-      assert(to_vec[i] != 0 && !err && -1 != ind);
-    }
-  }
-  else {
-    MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
-    MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
-                                              sharedh_tag, sharedhs_tag, pstatus_tag);
-  
-      // get single-proc destination handles and shared procs
-    std::vector<int> sharing_procs(from_range.size());
-    result = mbImpl->tag_get_data(sharedh_tag, from_range, to_vec);
-    RRA("Failed to get shared handle tag for remote_handles.");
-    result = mbImpl->tag_get_data(sharedp_tag, from_range, &sharing_procs[0]);
-    RRA("Failed to get sharing proc tag in remote_handles.");
-    for (unsigned int j = 0; j < from_range.size(); j++) {
-      if (to_vec[j] && sharing_procs[j] != to_proc)
-        to_vec[j] = 0;
-    }
-    
-    MBEntityHandle tmp_handles[MAX_SHARING_PROCS];
-    int tmp_procs[MAX_SHARING_PROCS];
-      // go through results, and for 0-valued ones, look for multiple shared proc
-    MBRange::iterator rit;
-    unsigned int i;
-    for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) {
-      if (!to_vec[i]) {
-        result = mbImpl->tag_get_data(sharedhs_tag, &(*rit), 1, tmp_handles);
-        if (MB_SUCCESS == result) {
-          result = mbImpl->tag_get_data(sharedps_tag, &(*rit), 1, tmp_procs);
-          RRA("Trouble getting sharedps tag.");
-          for (int j = 0; j < MAX_SHARING_PROCS; j++)
-            if (tmp_procs[j] == to_proc) {
-              to_vec[i] = tmp_handles[j];
-              break;
-            }
-        }
-      
-        if (!to_vec[i]) {
-          int j = new_ents.index(*rit);
-          if (-1 == j) {
-            result = MB_FAILURE;
-            RRA("Failed to find new entity in send list.");
-          }
-          int err;
-          to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err);
-          if (err) {
-            result = MB_FAILURE;
-            RRA("Failed to create handle in remote_handles.");
-          }
-        }
-      }
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles,
-                                               const MBRange &from_range, 
-                                               MBRange &to_range,
-                                               int to_proc,
-                                               const MBRange &new_ents) 
-{
-  std::vector<MBEntityHandle> to_vector(from_range.size());
-
-  MBErrorCode result =
-    get_remote_handles(store_remote_handles, from_range, &to_vector[0],
-                       to_proc, new_ents);
-  RRA("Trouble getting remote handles.");
-  std::copy(to_vector.begin(), to_vector.end(), mb_range_inserter(to_range));
-  return result;
-}
-
-MBErrorCode MBParallelComm::unpack_entities(unsigned char *&buff_ptr,
-                                            const bool store_remote_handles,
-                                            const int from_ind,
-                                            const bool is_iface,
-                                            std::vector<std::vector<MBEntityHandle> > &L1hloc,
-                                            std::vector<std::vector<MBEntityHandle> > &L1hrem,
-                                            std::vector<std::vector<int> > &L1p,
-                                            std::vector<MBEntityHandle> &L2hloc, 
-                                            std::vector<MBEntityHandle> &L2hrem,
-                                            std::vector<unsigned int> &L2p,
-                                            MBRange &new_ents) 
-{
-    // general algorithm:
-    // - unpack # entities
-    // - save start of remote handle info, then scan forward to entity definition data
-    // - for all vertices or entities w/ same # verts:
-    //   . get entity type, num ents, and (if !vert) # verts 
-    //   . for each ent:
-    //      o get # procs/handles in remote handle info
-    //      o if # procs/handles > 2, check for already-created entity:
-    //        x get index of owner proc (1st in proc list), resize L1 list if nec
-    //        x look for already-arrived entity in L2 by owner handle
-    //      o if no existing entity:
-    //        x if iface, look for existing entity with same connect & type
-    //        x if none found, create vertex or element
-    //        x if !iface & multi-shared, save on L2
-    //        x if !iface, put new entity on new_ents list
-    //      o update proc/handle, pstatus tags, adjusting to put owner first if iface
-    //      o if !iface, save new handle on L1 for all sharing procs
-
-    // lists of handles/procs to return to sending/other procs
-    // L1hloc[p], L1hrem[p]: handle pairs [h, h'], where h is the local proc handle
-    //         and h' is either the remote proc handle (if that is known) or
-    //         the owner proc handle (otherwise);
-    // L1p[p]: indicates whether h is remote handle (= -1) or owner (rank of owner)
-    // L2hloc, L2hrem: local/remote handles for entities shared by > 2 procs;
-    //         remote handles are on owning proc
-    // L2p: owning procs for handles in L2hrem
-
-  MBErrorCode result;
-  bool done = false;
-  MBReadUtilIface *ru = NULL;
-
-  result = mbImpl->query_interface(std::string("MBReadUtilIface"), 
-                                   reinterpret_cast<void**>(&ru));
-  RRA("Failed to get MBReadUtilIface.");
-
-    // procs the sending proc is telling me I'll be receiving from
-  std::set<unsigned int> comm_procs;
-
-    // 1. # entities = E
-  int num_ents;
-  unsigned char *buff_save = buff_ptr;
-  int i, j;
-
-  if (store_remote_handles) {
-    UNPACK_INT(buff_ptr, num_ents);
-
-    buff_save = buff_ptr;
-    
-      // save place where remote handle info starts, then scan forward to ents
-    for (i = 0; i < num_ents; i++) {
-      UNPACK_INT(buff_ptr, j);
-      if (j < 0) {
-        std::cout << "Should be non-negative # proc/handles.";
-        return MB_FAILURE;
-      }
-      
-      buff_ptr += j * (sizeof(int)+sizeof(MBEntityHandle));
-    }
-  }
-
-  std::vector<MBEntityHandle> msg_ents;
-  
-  while (!done) {
-    MBEntityType this_type = MBMAXTYPE;
-    UNPACK_TYPE(buff_ptr, this_type);
-    assert(this_type != MBENTITYSET);
-
-      // MBMAXTYPE signifies end of entities data
-    if (MBMAXTYPE == this_type) break;
-
-    assert(!is_iface || this_type != MBVERTEX);
-    
-      // get the number of ents
-    int num_ents2, verts_per_entity;
-    UNPACK_INT(buff_ptr, num_ents2);
-
-      // unpack the nodes per entity
-    if (MBVERTEX != this_type && num_ents2) {
-      UNPACK_INT(buff_ptr, verts_per_entity);
-    }
-      
-    std::vector<int> ps(MAX_SHARING_PROCS, -1);
-    std::vector<MBEntityHandle> hs(MAX_SHARING_PROCS, 0);
-    for (int e = 0; e < num_ents2; e++) {
-        // check for existing entity, otherwise make new one
-      MBEntityHandle new_h = 0;
-
-      MBEntityHandle *connect;
-      double *coords;
-      int num_ps = -1;
-
-        //=======================================
-        // unpack all the data at once, to make sure the buffer pointers
-        // are tracked correctly
-        //=======================================
-      if (store_remote_handles) {
-          // pointers to other procs/handles
-        UNPACK_INT(buff_save, num_ps);
-        if (0 >= num_ps) {
-          std::cout << "Shouldn't ever be fewer than 1 procs here." << std::endl;
-          return MB_FAILURE;
-        }
-        
-        UNPACK_INTS(buff_save, &ps[0], num_ps);
-        UNPACK_EH(buff_save, &hs[0], num_ps);
-      }
-
-      if (MBVERTEX == this_type) {
-        coords = (double*) buff_ptr;
-        buff_ptr += 3*sizeof(double);
-      }
-      else {
-        connect = (MBEntityHandle*) buff_ptr;
-        buff_ptr += verts_per_entity * sizeof(MBEntityHandle);
-
-          // update connectivity to local handles
-        result = get_local_handles(connect, verts_per_entity, msg_ents);
-        RRA("Couldn't get local handles.");
-      }
-
-        //=======================================
-        // now, process that data; begin by finding an identical 
-        // entity, if there is one
-        //=======================================
-      if (store_remote_handles) {
-        result = find_existing_entity(is_iface, ps[0], hs[0], num_ps, 
-                                      connect, verts_per_entity,
-                                      this_type,
-                                      L2hloc, L2hrem, L2p,
-                                      new_h);
-        RRA("Trouble getting existing entity.");
-      }
-
-        //=======================================
-        // if we didn't find one, we'll have to create one
-        //=======================================
-      bool created_here = false;
-      if (!new_h && !is_iface) {
-        
-        if (MBVERTEX == this_type) {
-            // create a vertex
-          result = mbImpl->create_vertex(coords, new_h);
-          RRA("Couldn't make new vertex.");
-        }
-        else {
-            // create the element
-          result = mbImpl->create_element(this_type, connect, verts_per_entity, new_h);
-          RRA("Couldn't make new vertex.");
-
-            // update adjacencies
-          result = ru->update_adjacencies(new_h, 1, 
-                                          verts_per_entity, connect);
-          RRA("Failed to update adjacencies.");
-        }
-
-          // should have a new handle now
-        assert(new_h);
-        
-          // if a new multi-shared entity, save owner for subsequent lookup in L2 lists
-        if (store_remote_handles && !is_iface && num_ps > 2) {
-          L2hrem.push_back(hs[0]);
-          L2hloc.push_back(new_h);
-          L2p.push_back(ps[0]);
-        }
-
-        created_here = true;
-      }
-
-        //=======================================
-        // take care of sharing data
-        //=======================================
-
-        // need to save entities found in order, for interpretation of
-        // later parts of this message
-      if (!is_iface) {
-        assert(new_h);
-        msg_ents.push_back(new_h);
-      }
-
-      if (created_here) new_ents.insert(new_h);
-
-      if (new_h && store_remote_handles) {
-        
-          // update sharing data and pstatus, adjusting order if iface
-        result = update_remote_data(new_h, &ps[0], &hs[0], num_ps, 
-                                    (is_iface ? PSTATUS_INTERFACE :
-                                     (created_here ? (PSTATUS_GHOST | PSTATUS_NOT_OWNED) : 0)));
-        RRA("");
-
-          // need to send this new handle to all sharing procs
-        if (!is_iface) {
-          for (j = 0; j < num_ps; j++) {
-            if (ps[j] == (int)procConfig.proc_rank()) continue;
-            int idx = get_buffers(ps[j]);
-            if (idx == (int)L1hloc.size()) {
-              L1hloc.resize(idx+1);
-              L1hrem.resize(idx+1);
-              L1p.resize(idx+1);
-            }
-            
-              // don't bother adding if it's already in the list
-            std::vector<MBEntityHandle>::iterator vit = 
-                std::find(L1hloc[idx].begin(), L1hloc[idx].end(), new_h);
-            if (vit != L1hloc[idx].end()) {
-                // if it's in the list but remote handle isn't known but we know
-                // it, replace in the list
-              if (L1p[idx][vit-L1hloc[idx].begin()] != -1 && hs[j]) {
-                L1hrem[idx][vit-L1hloc[idx].begin()] = hs[j];
-                L1p[idx][vit-L1hloc[idx].begin()] = -1;
-              }
-              else continue;
-            }
-            else {
-              if (!hs[j]) {
-                assert(-1 != ps[0] && num_ps > 2);
-                L1p[idx].push_back(ps[0]);
-                L1hrem[idx].push_back(hs[0]);
-              }
-              else {
-                assert("either this remote handle isn't in the remote list, or it's for another proc" &&
-                       (std::find(L1hrem[idx].begin(), L1hrem[idx].end(), hs[j]) == 
-                        L1hrem[idx].end() ||
-                        L1p[idx][std::find(L1hrem[idx].begin(), L1hrem[idx].end(), hs[j]) - 
-                                 L1hrem[idx].begin()] != -1));
-                L1p[idx].push_back(-1);
-                L1hrem[idx].push_back(hs[j]);
-              }
-              L1hloc[idx].push_back(new_h);
-            }
-          }
-        }
-
-        assert("Shouldn't be here for non-shared entities" &&
-               -1 != num_ps);
-        std::fill(&ps[0], &ps[num_ps], -1);
-        std::fill(&hs[0], &hs[num_ps], 0);
-      }
-    }
-    
-    
-#ifdef DEBUG_PACKING
-      std::cerr << "Unpacked " << num_ents << " ents of type " 
-                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(this_type)) << std::endl;
-#endif      
-
-  }
-
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Done unpacking entities." << std::endl;
-#endif
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::print_buffer(unsigned char *buff_ptr, 
-                                         int mesg_tag, 
-                                         int from_proc, bool sent) 
-{
-  std::cerr << procConfig.proc_rank();
-  if (sent) std::cerr << " sent";
-  else std::cerr << " received";
-  std::cerr << " message type " << mesg_tag 
-            << " to/from proc " << from_proc << "; contents:" << std::endl;
-
-  int msg_length, num_ents;
-  unsigned char *orig_ptr = buff_ptr;
-  UNPACK_INT(buff_ptr, msg_length);
-  std::cerr << msg_length << " bytes..." << std::endl;
-
-  if (MB_MESG_ENTS_SIZE == mesg_tag || MB_MESG_ENTS_LARGE == mesg_tag) {
-
-      // 1. # entities = E
-    int i, j, k;
-    std::vector<int> ps;
-    std::vector<MBEntityHandle> hs;
-
-    UNPACK_INT(buff_ptr, num_ents);
-    std::cerr << num_ents << " entities..." << std::endl;
-
-      // save place where remote handle info starts, then scan forward to ents
-    for (i = 0; i < num_ents; i++) {
-      UNPACK_INT(buff_ptr, j);
-      if (0 > j) return MB_FAILURE;
-      ps.resize(j);
-      hs.resize(j);
-      std::cerr << "Entity " << i << ", # procs = " << j << std::endl;
-      UNPACK_INTS(buff_ptr, &ps[0], j);
-      UNPACK_EH(buff_ptr, &hs[0], j);
-      std::cerr << "   Procs: ";
-      for (k = 0; k < j; k++) std::cerr << ps[k] << " ";
-      std::cerr << std::endl;
-      std::cerr << "   Handles: ";
-      for (k = 0; k < j; k++) std::cerr << hs[k] << " ";
-      std::cerr << std::endl;
-
-      if (buff_ptr-orig_ptr > msg_length) {
-        std::cerr << "End of buffer..." << std::endl;
-        std::cerr.flush();
-        return MB_FAILURE;
-      }
-    }
-  
-    while (true) {
-      MBEntityType this_type = MBMAXTYPE;
-      UNPACK_TYPE(buff_ptr, this_type);
-      assert(this_type != MBENTITYSET);
-
-        // MBMAXTYPE signifies end of entities data
-      if (MBMAXTYPE == this_type) break;
-
-        // get the number of ents
-      int num_ents2, verts_per_entity;
-      UNPACK_INT(buff_ptr, num_ents2);
-
-        // unpack the nodes per entity
-      if (MBVERTEX != this_type && num_ents2) {
-        UNPACK_INT(buff_ptr, verts_per_entity);
-      }
-
-      std::cerr << "Type: " << MBCN::EntityTypeName(this_type)
-                << "; num_ents = " << num_ents2;
-      if (MBVERTEX != this_type) std::cerr << "; verts_per_ent = " << verts_per_entity;
-      std::cerr << std::endl;
-      if (num_ents2 < 0 || num_ents2 > msg_length) {
-        std::cerr << "Wrong number of entities, returning." << std::endl;
-        return MB_FAILURE;
-      }
-    
-      for (int e = 0; e < num_ents2; e++) {
-          // check for existing entity, otherwise make new one
-        MBEntityHandle *connect;
-        double *coords;
-
-        if (MBVERTEX == this_type) {
-          coords = (double*) buff_ptr;
-          buff_ptr += 3*sizeof(double);
-          std::cerr << "xyz = " << coords[0] << ", " << coords[1] << ", " 
-                    << coords[2] << std::endl;
-        }
-        else {
-          connect = (MBEntityHandle*) buff_ptr;
-          buff_ptr += verts_per_entity * sizeof(MBEntityHandle);
-
-            // update connectivity to local handles
-          std::cerr << "Connectivity: ";
-          for (k = 0; k < verts_per_entity; k++) std::cerr << connect[k] << " ";
-          std::cerr << std::endl;
-        }
-
-        if (buff_ptr-orig_ptr > msg_length) {
-          std::cerr << "End of buffer..." << std::endl;
-          std::cerr.flush();
-          return MB_FAILURE;
-        }
-      }
-    }
-  }
-  
-  else if (MB_MESG_REMOTEH_SIZE == mesg_tag || MB_MESG_REMOTEH_LARGE == mesg_tag) {
-    UNPACK_INT(buff_ptr, num_ents);
-    std::cerr << num_ents << " entities..." << std::endl;
-    if (0 > num_ents || num_ents > msg_length) {
-      std::cerr << "Wrong number of entities, returning." << std::endl;
-      return MB_FAILURE;
-    }
-    std::vector<MBEntityHandle> L1hloc(num_ents), L1hrem(num_ents);
-    std::vector<int> L1p(num_ents);
-    UNPACK_INTS(buff_ptr, &L1p[0], num_ents);
-    UNPACK_EH(buff_ptr, &L1hrem[0], num_ents);
-    UNPACK_EH(buff_ptr, &L1hloc[0], num_ents);
-    std::cerr << num_ents << " Entity pairs; hremote/hlocal/proc: " << std::endl;
-    for (int i = 0; i < num_ents; i++) {
-      MBEntityType etype = TYPE_FROM_HANDLE(L1hloc[i]);
-      std::cerr << MBCN::EntityTypeName(etype) << ID_FROM_HANDLE(L1hrem[i])  << ", " 
-                << MBCN::EntityTypeName(etype) << ID_FROM_HANDLE(L1hloc[i])  << ", " 
-                << L1p[i] << std::endl;
-    }
-
-    if (buff_ptr-orig_ptr > msg_length) {
-      std::cerr << "End of buffer..." << std::endl;
-      std::cerr.flush();
-      return MB_FAILURE;
-    }
-
-  }
-  else if (mesg_tag == MB_MESG_TAGS_SIZE || mesg_tag == MB_MESG_TAGS_LARGE) {
-    int num_tags, dum1, num_ents, data_type, tag_size;
-    UNPACK_INT(buff_ptr, num_tags);
-    std::cerr << "Number of tags = " << num_tags << std::endl;
-    for (int i = 0; i < num_tags; i++) {
-      std::cerr << "Tag " << i << ":" << std::endl;
-      UNPACK_INT(buff_ptr, tag_size);
-      UNPACK_INT(buff_ptr, dum1);
-      UNPACK_INT(buff_ptr, data_type);
-      std::cerr << "Tag size, type, data type = " << tag_size << ", " 
-                << dum1 << ", " << data_type << std::endl;
-      UNPACK_INT(buff_ptr, dum1);
-      std::cerr << "Default value size = " << dum1 << std::endl;
-      buff_ptr += dum1;
-      UNPACK_INT(buff_ptr, dum1);
-      std::cerr << "Tag name = " << (char*) buff_ptr << std::endl;
-      buff_ptr += dum1;
-      UNPACK_INT(buff_ptr, num_ents);
-      std::cerr << "Number of ents = " << num_ents << std::endl;
-      unsigned char *tmp_buff = buff_ptr;
-      buff_ptr += num_ents*sizeof(MBEntityHandle);
-      int tot_length = 0;
-      for (int i = 0; i < num_ents; i++) {
-        MBEntityType etype = TYPE_FROM_HANDLE(*((MBEntityHandle*)tmp_buff));
-        std::cerr << MBCN::EntityTypeName(etype) << " " 
-                  << ID_FROM_HANDLE(*((MBEntityHandle*)tmp_buff))
-                  << ", tag = ";
-        if (tag_size == MB_VARIABLE_LENGTH) {
-          UNPACK_INT(buff_ptr, dum1);
-          tot_length += dum1;
-          std::cerr << "(variable, length = " << dum1 << ")" << std::endl;
-        }
-        else if (data_type == MB_TYPE_DOUBLE) std::cerr << *((double*)buff_ptr) << std::endl;
-        else if (data_type == MB_TYPE_INTEGER) std::cerr << *((int*)buff_ptr) << std::endl;
-        else if (data_type == MB_TYPE_OPAQUE) std::cerr << "(opaque)" << std::endl;
-        else if (data_type == MB_TYPE_HANDLE) 
-          std::cerr <<  (MBEntityHandle)*buff_ptr << std::endl;
-        else if (data_type == MB_TYPE_BIT) std::cerr << "(bit)" << std::endl;
-        tmp_buff += sizeof(MBEntityHandle);
-        buff_ptr += tag_size;
-      }
-
-      if (tag_size == MB_VARIABLE_LENGTH) buff_ptr += tot_length;
-    }
-  }
-  else {
-    assert(false);
-    return MB_FAILURE;
-  }
-
-  std::cerr.flush();
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::list_entities(const MBEntityHandle *ents, int num_ents) 
-{
-  if (NULL == ents && 0 == num_ents) {
-    sharedEnts.print("Shared entities:\n");
-    return MB_SUCCESS;
-  }
-  
-  else if (NULL == ents && 0 != num_ents) {
-    return list_entities(sharedEnts);
-  }
-    
-  unsigned char pstat;
-  MBEntityHandle tmp_handles[MAX_SHARING_PROCS];
-  int tmp_procs[MAX_SHARING_PROCS];
-  unsigned int num_ps;
-  MBErrorCode result;
-
-  for (int i = 0; i < num_ents; i++) {
-    result = mbImpl->list_entities(ents+i, 1);
-
-    result = get_sharing_data(ents[i], tmp_procs, tmp_handles, pstat, num_ps);
-    RRA("Failed to get sharing data.");
-
-    std::cout << "Pstatus: ";
-    if (!num_ps)
-      std::cout << "local " << std::endl;
-    else {
-      if (pstat & PSTATUS_NOT_OWNED) std::cout << "NOT_OWNED; ";
-      if (pstat & PSTATUS_SHARED) std::cout << "SHARED; ";
-      if (pstat & PSTATUS_MULTISHARED) std::cout << "MULTISHARED; ";
-      if (pstat & PSTATUS_INTERFACE) std::cout << "INTERFACE; ";
-      if (pstat & PSTATUS_GHOST) std::cout << "GHOST; ";
-      std::cout << std::endl;
-      for (unsigned int j = 0; j < num_ps; j++) {
-        std::cout << "  proc " << tmp_procs[j] << " id (handle) " 
-                  << mbImpl->id_from_handle(tmp_handles[j]) 
-                  << "(" << tmp_handles[j] << ")" << std::endl;
-      }
-    }
-    std::cout << std::endl;
-  }
-
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::list_entities(const MBRange &ents) 
-{
-  for (MBRange::iterator rit = ents.begin(); rit != ents.end(); rit++)
-    list_entities(&(*rit), 1);
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::update_remote_data(MBRange &local_range,
-                                               MBRange &remote_range,
-                                               int other_proc,
-                                               const unsigned char add_pstat) 
-{
-  MBRange::iterator rit, rit2;
-  MBErrorCode result = MB_SUCCESS;
-
-    // for each pair of local/remote handles:
-  for (rit = local_range.begin(), rit2 = remote_range.begin(); 
-       rit != local_range.end(); rit++, rit2++) {
-
-    result = update_remote_data(*rit, &other_proc, &(*rit2), 1, add_pstat);
-    RRA(" ");
-  }
-
-  return result;
-}
-  
-MBErrorCode MBParallelComm::update_remote_data(const MBEntityHandle new_h,
-                                               const int *ps,
-                                               const MBEntityHandle *hs,
-                                               const int num_ps,
-                                               const unsigned char add_pstat) 
-{
-  MBEntityHandle tag_hs[MAX_SHARING_PROCS];
-  int tag_ps[MAX_SHARING_PROCS];
-  unsigned char pstat;
-    // get initial sharing data; tag_ps and tag_hs get terminated with -1 and 0
-    // in this function, so no need to initialize
-  unsigned int num_exist;
-  MBErrorCode result = get_sharing_data(new_h, tag_ps, tag_hs, pstat, num_exist);
-  RRA("");
-  
-#ifndef NDEBUG
-  {
-      // check for duplicates in proc list
-    std::set<unsigned int> dumprocs;
-    unsigned int dp = 0;
-    for (; (int) dp < num_ps && -1 != ps[dp]; dp++)
-      dumprocs.insert(ps[dp]);
-    assert(dp == dumprocs.size());
-  }
-#endif      
-
-    // add any new sharing data
-  bool changed = false;
-  int idx;
-  if (!num_exist) {
-      // just take what caller passed
-    memcpy(tag_ps, ps, num_ps*sizeof(int));
-    memcpy(tag_hs, hs, num_ps*sizeof(MBEntityHandle));
-    num_exist = num_ps;
-      // if it's only one, hopefully I'm not there yet...
-    assert("I shouldn't be the only proc there." &&
-           (1 != num_exist || ps[0] != (int)procConfig.proc_rank()));
-    changed = true;
-  }
-  else {
-    for (int i = 0; i < num_ps; i++) {
-      idx = std::find(tag_ps, tag_ps+num_exist, ps[i]) - tag_ps;
-      if (idx == (int) num_exist) {
-          // if there's only 1 sharing proc, and it's not me, then
-          // we'll end up with 3; add me to the front
-        if (!i && num_ps == 1 && num_exist == 1 &&
-            ps[0] != (int)procConfig.proc_rank()) {
-          int j = 1;
-            // if I own this entity, put me at front, otherwise after first
-          if (!(pstat & PSTATUS_NOT_OWNED)) {
-            tag_ps[1] = tag_ps[0];
-            tag_hs[1] = tag_hs[0];
-            j = 0;
-          }
-          tag_ps[j] = procConfig.proc_rank();
-          tag_hs[j] = new_h;
-          num_exist++;
-        }
-        
-        tag_ps[num_exist] = ps[i];
-        tag_hs[num_exist] = hs[i];
-        num_exist++;
-        changed = true;
-      }
-      else if (0 == tag_hs[idx]) {
-        tag_hs[idx] = hs[i];
-        changed = true;
-      }
-      else if (0 != hs[i]) {
-        assert(hs[i] == tag_hs[idx]);
-      }
-    }
-  }
-  
-    // adjust for interface layer if necessary
-  if (add_pstat & PSTATUS_INTERFACE) {
-    idx = std::min_element(tag_ps, tag_ps+num_exist) - tag_ps;
-    if (idx) {
-      int tag_proc = tag_ps[idx];
-      tag_ps[idx] = tag_ps[0];
-      tag_ps[0] = tag_proc;
-      MBEntityHandle tag_h = tag_hs[idx];
-      tag_hs[idx] = tag_hs[0];
-      tag_hs[0] = tag_h;
-      changed = true;
-      if (tag_ps[0] != (int)procConfig.proc_rank()) pstat |= PSTATUS_NOT_OWNED;
-    }
-  }
-    
-  if (!changed) return MB_SUCCESS;
-  
-  assert("interface entities should have > 1 proc" &&
-         (!(add_pstat & PSTATUS_INTERFACE) || num_exist > 1));
-  assert("ghost entities should have > 1 proc" &&
-         (!(add_pstat & PSTATUS_GHOST) || num_exist > 1));
-  
-    // if it's multi-shared and we created the entity in this unpack,
-    // local handle probably isn't in handle list yet
-  if (num_exist > 2) {
-    idx = std::find(tag_ps, tag_ps+num_exist, procConfig.proc_rank()) - tag_ps;
-    assert(idx < (int) num_exist);
-    if (!tag_hs[idx])
-      tag_hs[idx] = new_h;
-  }
-      
-  int tag_p;
-  MBEntityHandle tag_h;
-
-    // reset single shared proc/handle if was shared and moving to multi-shared
-  if (num_exist > 2 && !(pstat & PSTATUS_MULTISHARED) &&
-      (pstat & PSTATUS_SHARED)) {
-      // must remove sharedp/h first, which really means set to default value
-    tag_p = -1;
-    result = mbImpl->tag_set_data(sharedp_tag(), &new_h, 1, &tag_p);
-    RRA("Couldn't set sharedp tag.");
-    tag_h = 0;
-    result = mbImpl->tag_set_data(sharedh_tag(), &new_h, 1, &tag_h);
-    RRA("Couldn't set sharedh tag.");
-  }
-
-    // update pstat
-  pstat |= add_pstat;
-  
-    // set sharing tags
-  if (num_exist > 2) {
-    std::fill(tag_ps+num_exist, tag_ps+MAX_SHARING_PROCS, -1);
-    std::fill(tag_hs+num_exist, tag_hs+MAX_SHARING_PROCS, 0);
-    result = mbImpl->tag_set_data(sharedps_tag(), &new_h, 1, tag_ps);
-    RRA("Couldn't set sharedps tag.");
-    result = mbImpl->tag_set_data(sharedhs_tag(), &new_h, 1, tag_hs);
-    RRA("Couldn't set sharedhs tag.");
-    pstat |= (PSTATUS_MULTISHARED | PSTATUS_SHARED);
-
-#ifndef NDEBUG
-    {
-        // check for duplicates in proc list
-      std::set<unsigned int> dumprocs;
-      unsigned int dp = 0;
-      for (; dp < num_exist && -1 != tag_ps[dp]; dp++)
-        dumprocs.insert(tag_ps[dp]);
-      assert(dp == dumprocs.size());
-    }
-#endif      
-  }
-  else if (num_exist == 2 || num_exist == 1) {
-    if (tag_ps[0] == (int) procConfig.proc_rank()) {
-      assert(2 == num_exist && tag_ps[1] != (int) procConfig.proc_rank());
-      tag_ps[0] = tag_ps[1];
-      tag_hs[0] = tag_hs[1];
-    }
-    assert(tag_ps[0] != -1 && tag_hs[0] != 0);
-    result = mbImpl->tag_set_data(sharedp_tag(), &new_h, 1, tag_ps);
-    RRA("Couldn't set sharedp tag.");
-    result = mbImpl->tag_set_data(sharedh_tag(), &new_h, 1, tag_hs);
-    RRA("Couldn't set sharedh tag.");
-    pstat |= PSTATUS_SHARED;
-  }
-
-    // now set new pstatus
-  result = mbImpl->tag_set_data(pstatus_tag(), &new_h, 1, &pstat);
-  RRA("Couldn't set pstatus tag.");
-
-  if (pstat & PSTATUS_SHARED) sharedEnts.insert(new_h);
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_sharing_data(const MBRange &entities,
-                                             std::set<int> &procs,
-                                             int operation)
-{
-    // get the union or intersection of sharing data for multiple entities
-
-  MBErrorCode result;
-  int sp2[MAX_SHARING_PROCS];
-  int num_ps;
-  unsigned char pstat;
-  std::set<int> tmp_procs;
-  procs.clear();
-  
-  for (MBRange::const_iterator rit = entities.begin(); rit != entities.end(); rit++) {
-        
-      // get sharing procs
-    result = get_sharing_data(*rit, sp2, NULL, pstat, num_ps);
-    RRA("Problem getting sharing data in get_sharing_data.");
-    if (!(pstat & PSTATUS_SHARED) && MBInterface::INTERSECT == operation) {
-      procs.clear();
-      return MB_SUCCESS;
-    }
-        
-    if (rit == entities.begin()) {
-      std::copy(sp2, sp2+num_ps, std::inserter(procs, procs.begin()));
-    }
-    else {
-      std::sort(sp2, sp2+num_ps);
-      tmp_procs.clear();
-      if (MBInterface::UNION == operation) 
-        std::set_union(procs.begin(), procs.end(), 
-                       sp2, sp2+num_ps, std::inserter(tmp_procs, tmp_procs.end()));
-      else if (MBInterface::INTERSECT == operation)
-        std::set_intersection(procs.begin(), procs.end(), 
-                              sp2, sp2+num_ps, std::inserter(tmp_procs, tmp_procs.end()));
-      else {
-        assert("Unknown operation." && false);
-        return MB_FAILURE;
-      }
-      procs.swap(tmp_procs);
-    }
-    if (MBInterface::INTERSECT == operation && procs.empty()) 
-      return MB_SUCCESS;
-  }
-
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::get_sharing_data(const MBEntityHandle entity,
-                                             int *ps, 
-                                             MBEntityHandle *hs,
-                                             unsigned char &pstat,
-                                             unsigned int &num_ps)
-{
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1, &pstat);
-  RRA("Couldn't get pstatus tag.");
-  if (pstat & PSTATUS_MULTISHARED) {
-    result = mbImpl->tag_get_data(sharedps_tag(), &entity, 1, ps);
-    RRA("Couldn't get sharedps tag.");
-    if (hs) {
-      result = mbImpl->tag_get_data(sharedhs_tag(), &entity, 1, hs);
-      RRA("Couldn't get sharedhs tag.");
-    }
-    num_ps = std::find(ps, ps+MAX_SHARING_PROCS, -1) - ps;
-  }
-  else if (pstat & PSTATUS_SHARED) {
-    result = mbImpl->tag_get_data(sharedp_tag(), &entity, 1, ps);
-    RRA("Couldn't get sharedp tag.");
-    if (hs) {
-      result = mbImpl->tag_get_data(sharedh_tag(), &entity, 1, hs);
-      RRA("Couldn't get sharedh tag.");
-      hs[1] = 0;
-    }
-      // initialize past end of data
-    ps[1] = -1;
-    num_ps = 1;
-  }
-  else {
-    ps[0] = -1;
-    if (hs) hs[0] = 0;
-    num_ps = 0;
-  }
-
-  assert(0 <= num_ps && MAX_SHARING_PROCS >= num_ps);
-  
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::find_existing_entity(const bool is_iface,
-                                                 const int owner_p,
-                                                 const MBEntityHandle owner_h,
-                                                 const int num_ps,
-                                                 const MBEntityHandle *connect,
-                                                 const int num_connect,
-                                                 const MBEntityType this_type,
-                                                 std::vector<MBEntityHandle> &L2hloc,
-                                                 std::vector<MBEntityHandle> &L2hrem,
-                                                 std::vector<unsigned int> &L2p,
-                                                 MBEntityHandle &new_h) 
-{
-  new_h = 0;
-  if (!is_iface && num_ps > 2) {
-    for (unsigned int i = 0; i < L2hrem.size(); i++) {
-      if (L2hrem[i] == owner_h && owner_p == (int) L2p[i]) {
-        new_h = L2hloc[i];
-        return MB_SUCCESS;
-      }
-    }        
-  }
-
-    // if we got here and it's a vertex, we don't need to look further
-  if (MBVERTEX == this_type || !connect || !num_connect) return MB_SUCCESS;
-  
-  MBRange tmp_range;
-  MBErrorCode result = mbImpl->get_adjacencies(connect, num_connect, 
-                                               MBCN::Dimension(this_type), false, 
-                                               tmp_range);
-  RRA("Problem getting existing entity.");
-  if (!tmp_range.empty()) {
-      // found a corresponding entity - return target
-    new_h = *tmp_range.begin();
-  }  
-  else {
-    new_h = 0;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_local_handles(const MBRange &remote_handles,
-                                              MBRange &local_handles,
-                                              const MBRange &new_ents) 
-{
-  std::vector<MBEntityHandle> rh_vec;
-  rh_vec.reserve(remote_handles.size());
-  std::copy(remote_handles.begin(), remote_handles.end(), std::back_inserter(rh_vec));
-  MBErrorCode result = get_local_handles(&rh_vec[0], remote_handles.size(), new_ents);
-  std::copy(rh_vec.begin(), rh_vec.end(), mb_range_inserter(local_handles));
-  return result;
-}
-  
-MBErrorCode MBParallelComm::get_local_handles(MBEntityHandle *from_vec, 
-                                              int num_ents,
-                                              const MBRange &new_ents) 
-{
-  std::vector<MBEntityHandle> tmp_ents;
-  std::copy(new_ents.begin(), new_ents.end(), std::back_inserter(tmp_ents));
-  return get_local_handles(from_vec, num_ents, tmp_ents);
-}
-
-MBErrorCode MBParallelComm::get_local_handles(MBEntityHandle *from_vec,
-                                              int num_ents,
-                                              const std::vector<MBEntityHandle> &new_ents) 
-{
-  for (int i = 0; i < num_ents; i++) {
-    if (TYPE_FROM_HANDLE(from_vec[i]) == MBMAXTYPE) {
-      assert(ID_FROM_HANDLE(from_vec[i]) < (int) new_ents.size());
-      from_vec[i] = new_ents[ID_FROM_HANDLE(from_vec[i])];
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-template <typename T> void
-insert_in_array( T* array, size_t array_size, size_t location, T value )
-{
-  assert( location+1 < array_size );
-  for (size_t i = array_size-1; i > location; --i)
-    array[i] = array[i-1];
-  array[location] = value;
-}
-
-MBErrorCode MBParallelComm::pack_range_map(MBRange &key_range, MBEntityHandle val_start,
-                                           HandleMap &handle_map) 
-{
-  for (MBRange::const_pair_iterator key_it = key_range.const_pair_begin(); 
-       key_it != key_range.const_pair_end(); key_it++) {
-    int tmp_num = (*key_it).second - (*key_it).first + 1;
-    handle_map.insert((*key_it).first, val_start, tmp_num);
-    val_start += tmp_num;
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::pack_sets(MBRange &entities,
-                                      Buffer *buff,
-                                      const bool store_remote_handles,
-                                      const int to_proc)
-{
-    // SETS:
-    // . #sets
-    // . for each set:
-    //   - options[#sets] (unsigned int)
-    //   - if (unordered) set range 
-    //   - else if ordered
-    //     . #ents in set
-    //     . handles[#ents]
-    //   - #parents
-    //   - if (#parents) handles[#parents]
-    //   - #children
-    //   - if (#children) handles[#children]
-  
-    // now the sets; assume any sets the application wants to pass are in the entities list
-  MBErrorCode result;
-  MBRange all_sets = entities.subset_by_type(MBENTITYSET);
-
-  int buff_size = estimate_sets_buffer_size(all_sets, store_remote_handles);
-  buff->check_space(buff_size);
-
-    // number of sets
-  PACK_INT(buff->buff_ptr, all_sets.size());
-
-    // options for all sets
-  std::vector<unsigned int> options(all_sets.size());
-  MBRange::iterator rit;
-  std::vector<MBEntityHandle> members;
-  int i;
-  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
-      result = mbImpl->get_meshset_options(*rit, options[i]);
-      RRA("Failed to get meshset options.");
-  }
-  buff->check_space(all_sets.size()*sizeof(unsigned int));
-  PACK_VOID(buff->buff_ptr, &options[0], all_sets.size()*sizeof(unsigned int));
-  
-    // vectors/ranges
-  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
-      MBRange set_range;
-      if (options[i] & MESHSET_SET) {
-        MBRange set_range;
-        result = mbImpl->get_entities_by_handle(*rit, set_range);
-        RRA("Failed to get set entities.");
-
-        buff_size = RANGE_SIZE(set_range);
-        buff->check_space(buff_size);
-        PACK_RANGE(buff->buff_ptr, set_range);
-      }
-      else if (options[i] & MESHSET_ORDERED) {
-        members.clear();
-        result = mbImpl->get_entities_by_handle(*rit, members);
-        RRA("Failed to get entities in ordered set.");
-        
-        buff->check_space(members.size()*sizeof(MBEntityHandle)+sizeof(int));
-        PACK_INT(buff->buff_ptr, members.size());
-        PACK_EH(buff->buff_ptr, &members[0], members.size());
-      }
-  }
-    // pack numbers of parents/children
-  unsigned int tot_pch = 0;
-  int num_pch;
-  buff->check_space(2*all_sets.size()*sizeof(int));
-  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
-      // pack parents
-    result = mbImpl->num_parent_meshsets(*rit, &num_pch);
-    RRA("Failed to get num parents.");
-    PACK_INT(buff->buff_ptr, num_pch);
-    tot_pch += num_pch;
-    result = mbImpl->num_child_meshsets(*rit, &num_pch);
-    RRA("Failed to get num children.");
-    PACK_INT(buff->buff_ptr, num_pch);
-    tot_pch += num_pch;
-  }
-
-    // now pack actual parents/children
-  members.clear();
-  members.reserve(tot_pch);
-  std::vector<MBEntityHandle> tmp_pch;
-  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
-    result = mbImpl->get_parent_meshsets(*rit, tmp_pch);
-    RRA("Failed to get parents.");
-    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members));
-    tmp_pch.clear();
-    result = mbImpl->get_child_meshsets(*rit, tmp_pch);
-    RRA("Failed to get children.");
-    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members));
-    tmp_pch.clear();
-  }
-  assert(members.size() == tot_pch);
-  if (!members.empty()) {
-    result = get_remote_handles(store_remote_handles,
-                                &members[0], &members[0], 
-                                members.size(), to_proc,
-                                entities);
-    RRA("Trouble getting remote handles for set parent/child sets.");
-#ifndef NDEBUG
-      // check that all handles are either sets or maxtype
-    for (unsigned int __j = 0; __j < members.size(); __j++)
-      assert((TYPE_FROM_HANDLE(members[__j]) == MBMAXTYPE &&
-              ID_FROM_HANDLE(members[__j]) < (int)entities.size()) ||
-             TYPE_FROM_HANDLE(members[__j]) == MBENTITYSET);
-#endif        
-    buff->check_space(members.size()*sizeof(MBEntityHandle));
-    PACK_EH(buff->buff_ptr, &members[0], members.size());
-  }
-    
-    // pack the handles
-  if (store_remote_handles && !all_sets.empty()) {
-    buff_size = RANGE_SIZE(all_sets);
-    buff->check_space(buff_size);
-    PACK_RANGE(buff->buff_ptr, all_sets);
-  }
-  
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Done packing sets." << std::endl;
-#endif
-
-  buff->set_stored_size();
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::unpack_sets(unsigned char *&buff_ptr,
-                                        MBRange &entities,
-                                        const bool store_remote_handles,
-                                        const int from_proc)
-{
-  
-    // now the sets; assume any sets the application wants to pass are in the entities list
-  MBErrorCode result;
-
-  MBRange new_sets;
-  int num_sets;
-  UNPACK_INT(buff_ptr, num_sets);
-
-  if (!num_sets) return MB_SUCCESS;
-         
-  std::vector<MBEntityHandle> members;
-  int num_ents;
-  std::vector<unsigned int> options_vec(num_sets);
-      // option value
-  if (num_sets)
-    UNPACK_VOID(buff_ptr, &options_vec[0], num_sets*sizeof(unsigned int));
-
-    // create sets
-  int i;
-  MBRange::const_iterator rit;
-  for (i = 0; i < num_sets; i++) {
-    
-      // create the set
-    MBEntityHandle set_handle;
-    result = mbImpl->create_meshset(options_vec[i], set_handle);
-    RRA("Failed to create set in unpack.");
-
-    // make sure new sets handles are monotonically increasing
-    assert(set_handle > *new_sets.rbegin());
-
-    new_sets.insert(set_handle);
-  }
-
-  entities.merge(new_sets);
-  
-  for (rit = new_sets.begin(), i = 0; rit != new_sets.end(); rit++, i++) {
-    if (options_vec[i] & MESHSET_SET) {
-        // unpack entities as a range
-      MBRange set_range, tmp_range;
-      UNPACK_RANGE(buff_ptr, tmp_range);
-      result = get_local_handles(tmp_range, set_range, entities);      
-      RRA("Failed to get local handles for unordered set contents.");
-      result = mbImpl->add_entities(*rit, set_range);
-      RRA("Failed to add ents to unordered set in unpack.");
-    }
-    else if (options_vec[i] & MESHSET_ORDERED) {
-        // unpack entities as vector, with length
-      UNPACK_INT(buff_ptr, num_ents);
-      members.resize(num_ents);
-      if (num_ents) UNPACK_EH(buff_ptr, &members[0], num_ents);
-      result = get_local_handles(&members[0], num_ents, entities);
-      RRA("Failed to get local handles for ordered set contents.");
-      result = mbImpl->add_entities(*rit, &members[0], num_ents);
-      RRA("Failed to add ents to ordered set in unpack.");
-    }
-  }
-
-  std::vector<int> num_pch(2*new_sets.size());
-  std::vector<int>::iterator vit;
-  int tot_pch = 0;
-  for (vit = num_pch.begin(); vit != num_pch.end(); vit++) {
-    UNPACK_INT(buff_ptr, *vit);
-    tot_pch += *vit;
-  }
-  
-  members.resize(tot_pch);
-  UNPACK_EH(buff_ptr, &members[0], tot_pch);
-  result = get_local_handles(&members[0], tot_pch, entities);
-  RRA("Couldn't get local handle for parent/child sets.");
-
-  int num = 0;
-  MBEntityHandle *mem_ptr = &members[0];
-  for (rit = new_sets.begin(); rit != new_sets.end(); rit++) {
-      // unpack parents/children
-    int num_par = num_pch[num++], num_child = num_pch[num++];
-    if (num_par+num_child) {
-      for (i = 0; i < num_par; i++) {
-        assert(0 != mem_ptr[i]);
-        result = mbImpl->add_parent_meshset(*rit, mem_ptr[i]);
-        RRA("Failed to add parent to set in unpack.");
-      }
-      mem_ptr += num_par;
-      for (i = 0; i < num_child; i++) {
-        assert(0 != mem_ptr[i]);
-        result = mbImpl->add_child_meshset(*rit, mem_ptr[i]);
-        RRA("Failed to add child to set in unpack.");
-      }
-      mem_ptr += num_child;
-    }
-  }
-
-    // unpack source handles
-  MBRange dum_range;
-  if (store_remote_handles && !new_sets.empty()) {
-    UNPACK_RANGE(buff_ptr, dum_range);
-    result = update_remote_data(new_sets, dum_range, from_proc, 0);
-    RRA("Couldn't set sharing data for sets");
-  }
-
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Done unpacking sets." << std::endl;
-#endif
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::pack_adjacencies(MBRange &entities,
-                                             MBRange::const_iterator &start_rit,
-                                             MBRange &whole_range,
-                                             unsigned char *&buff_ptr,
-                                             int &count,
-                                             const bool just_count,
-                                             const bool store_handles,
-                                             const int to_proc)
-{
-  return MB_FAILURE;
-}
-
-MBErrorCode MBParallelComm::unpack_adjacencies(unsigned char *&buff_ptr,
-                                               MBRange &entities,
-                                               const bool store_handles,
-                                               const int from_proc)
-{
-  return MB_FAILURE;
-}
-
-MBErrorCode MBParallelComm::pack_tags(MBRange &entities,
-                                      const std::vector<MBTag> &src_tags,
-                                      const std::vector<MBTag> &dst_tags,
-                                      const std::vector<MBRange> &tag_ranges,
-                                      Buffer *buff,
-                                      const bool store_remote_handles,
-                                      const int to_proc)
-{
-  
-
-  MBErrorCode result;
-  std::vector<MBTag>::const_iterator tag_it, dst_it;
-  std::vector<MBRange>::const_iterator rit;
-  int count = 0;
-  
-  for (tag_it = src_tags.begin(), rit = tag_ranges.begin(); 
-       tag_it != src_tags.end(); tag_it++, rit++) {
-
-    result = packed_tag_size( *tag_it, *rit, count );
-    if (MB_SUCCESS != result)
-      return result;
-  }
-    
-    // number of tags
-  count += sizeof(int);
-
-  buff->check_space(count);
-  
-  PACK_INT(buff->buff_ptr, src_tags.size());
-    
-  for (tag_it = src_tags.begin(), dst_it = dst_tags.begin(), rit = tag_ranges.begin(); 
-       tag_it != src_tags.end(); tag_it++, dst_it++, rit++) {
-    
-    result = pack_tag( *tag_it, *dst_it, *rit, entities, buff,
-                       store_remote_handles, to_proc );
-    if (MB_SUCCESS != result)
-      return result;
-  }
-  
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Done packing tags." << std::endl;
-#endif
-
-  buff->set_stored_size();
-  
-  return MB_SUCCESS;
-}
-         
-
-MBErrorCode MBParallelComm::packed_tag_size( MBTag tag,
-                                             const MBRange &tagged_entities,
-                                             int &count )
-{
-    // for dense tags, compute size assuming all entities have that tag
-    // for sparse tags, get number of entities w/ that tag to compute size
-
-  std::vector<int> var_len_sizes;
-  std::vector<const void*> var_len_values;
-    
-  const TagInfo *tinfo = tagServer->get_tag_info(tag);
-    // default value
-  count += sizeof(int);
-  if (NULL != tinfo->default_value()) 
-    count += tinfo->default_value_size();
-
-    // size, type, data type
-  count += 3*sizeof(int);
-
-    // name
-  count += sizeof(int);
-  count += tinfo->get_name().size();
-
-    // range of tag
-  count += sizeof(int) + tagged_entities.size() * sizeof(MBEntityHandle);
-
-  if (tinfo->get_size() == MB_VARIABLE_LENGTH) {
-    const int num_ent = tagged_entities.size();
-      // send a tag size for each entity
-    count += num_ent * sizeof(int);
-      // send tag data for each entity
-    var_len_sizes.resize( num_ent );
-    var_len_values.resize( num_ent );
-    MBErrorCode result = tagServer->get_data( tag,
-                                              tagged_entities, 
-                                              &var_len_values[0], 
-                                              &var_len_sizes[0] );
-    RRA("Failed to get lenghts of variable-length tag values.");
-    count += std::accumulate( var_len_sizes.begin(), var_len_sizes.end(), 0 );
-  }
-  else {
-      // tag data values for range or vector
-    count += tagged_entities.size() * tinfo->get_size();
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-MBErrorCode MBParallelComm::pack_tag( MBTag src_tag,
-                                      MBTag dst_tag,
-                                      const MBRange &tagged_entities,
-                                      const MBRange &whole_range,
-                                      Buffer *buff,
-                                      const bool store_remote_handles,
-                                      const int to_proc )
-{
-  MBErrorCode result;
-  std::vector<int> var_len_sizes;
-  std::vector<const void*> var_len_values;
-
-  const TagInfo* tinfo = tagServer->get_tag_info(src_tag);
-  if (!tinfo)
-    return MB_TAG_NOT_FOUND;
-    
-  const TagInfo* dst_tinfo;
-  if (src_tag == dst_tag) {
-    dst_tinfo = tinfo;
-  }
-  else {
-    dst_tinfo = tagServer->get_tag_info(dst_tag);
-    if (!dst_tinfo)
-      return MB_TAG_NOT_FOUND;
-    if (dst_tinfo->get_size() != tinfo->get_size())
-      return MB_TYPE_OUT_OF_RANGE;
-    if (dst_tinfo->get_data_type() != tinfo->get_data_type() && 
-        dst_tinfo->get_data_type() != MB_TYPE_OPAQUE &&
-            tinfo->get_data_type() != MB_TYPE_OPAQUE)
-      return MB_TYPE_OUT_OF_RANGE;
-  }
-    
-    // size, type, data type
-  buff->check_space(3*sizeof(int));
-  PACK_INT(buff->buff_ptr, tinfo->get_size());
-  MBTagType this_type;
-  result = mbImpl->tag_get_type(dst_tag, this_type);
-  PACK_INT(buff->buff_ptr, (int)this_type);
-  PACK_INT(buff->buff_ptr, (int)(tinfo->get_data_type()));
-
-    // default value
-  if (NULL == tinfo->default_value()) {
-    buff->check_space(sizeof(int));
-    PACK_INT(buff->buff_ptr, 0);
-  }
-  else {
-    buff->check_space(tinfo->default_value_size());
-    PACK_BYTES(buff->buff_ptr, tinfo->default_value(), tinfo->default_value_size());
-  }
-
-    // name
-  buff->check_space(tinfo->get_name().size());
-  PACK_BYTES(buff->buff_ptr, dst_tinfo->get_name().c_str(), dst_tinfo->get_name().size());
-
-#ifdef DEBUG_PACKING
-  std::cerr << "Packing tag \"" << tinfo->get_name() << "\"";
-  if (tinfo != dst_tinfo)
-    std::cerr << " (as tag \"" << dst_tinfo->get_name() << "\")";
-  std::cerr << std::endl;
-#endif    
-    // pack entities
-  buff->check_space(tagged_entities.size()*sizeof(MBEntityHandle)+sizeof(int));
-  PACK_INT(buff->buff_ptr, tagged_entities.size());
-  result = get_remote_handles(store_remote_handles,
-                              tagged_entities, (MBEntityHandle*)buff->buff_ptr, to_proc,
-                              whole_range);
-#ifdef DEBUG_PACKING
-  if (MB_SUCCESS != result) {
-    std::cerr << "Trouble getting remote handles for tagged entities:" << std::endl;
-    tagged_entities.print("  ");
-  }
-#else
-  RRA("Trouble getting remote handles for tagged entities.");
-#endif
-
-  buff->buff_ptr += tagged_entities.size() * sizeof(MBEntityHandle);
-
-  const size_t num_ent = tagged_entities.size();
-  if (tinfo->get_size() == MB_VARIABLE_LENGTH) {
-    var_len_sizes.resize( num_ent, 0 );
-    var_len_values.resize( num_ent, 0 );
-    result = mbImpl->tag_get_data(src_tag, tagged_entities, &var_len_values[0], 
-                                  &var_len_sizes[0] );
-    RRA("Failed to get variable-length tag data in pack_tags.");
-    buff->check_space(num_ent*sizeof(int));
-    PACK_INTS(buff->buff_ptr, &var_len_sizes[0], num_ent);
-    for (unsigned int i = 0; i < num_ent; ++i) {
-      buff->check_space(var_len_sizes[i]);
-      PACK_VOID(buff->buff_ptr, var_len_values[i], var_len_sizes[i]);
-    }
-  }
-  else {
-    buff->check_space(num_ent * tinfo->get_size());
-    result = mbImpl->tag_get_data(src_tag, tagged_entities, buff->buff_ptr);
-    RRA("Failed to get tag data in pack_tags.");
-    buff->buff_ptr += num_ent * tinfo->get_size();
-    PC(num_ent*tinfo->get_size(), " void");
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_tag_send_list( const MBRange& whole_range,
-                                               std::vector<MBTag>& all_tags,
-                                               std::vector<MBRange>& tag_ranges )
-{
-  std::vector<MBTag> tmp_tags;
-  MBErrorCode result = tagServer->get_tags(tmp_tags);
-  RRA("Failed to get tags in pack_tags.");
-
-  std::vector<MBTag>::iterator tag_it;
-  for (tag_it = tmp_tags.begin(); tag_it != tmp_tags.end(); tag_it++) {
-    std::string tag_name;
-    result = mbImpl->tag_get_name(*tag_it, tag_name);
-    if (tag_name.c_str()[0] == '_' && tag_name.c_str()[1] == '_')
-      continue;
-
-    MBRange tmp_range;
-    result = tagServer->get_entities(*tag_it, tmp_range);
-    RRA("Failed to get entities for tag in pack_tags.");
-    tmp_range = intersect( tmp_range, whole_range);
-
-    if (tmp_range.empty()) continue;
-        
-      // ok, we'll be sending this tag
-    all_tags.push_back( *tag_it );
-    tag_ranges.push_back( MBRange() );
-    tag_ranges.back().swap( tmp_range );
-  }
-  
-  return MB_SUCCESS;
-}
-
-
-
-MBErrorCode MBParallelComm::unpack_tags(unsigned char *&buff_ptr,
-                                        MBRange &entities,
-                                        const bool store_remote_handles,
-                                        const int from_proc)
-{
-    // tags
-    // get all the tags
-    // for dense tags, compute size assuming all entities have that tag
-    // for sparse tags, get number of entities w/ that tag to compute size
-
-  MBErrorCode result;
-  
-  int num_tags;
-  UNPACK_INT(buff_ptr, num_tags);
-  std::vector<MBEntityHandle> tag_ents;
-  std::vector<const void*> var_len_vals;
-  std::vector<int> var_lengths;
-
-  for (int i = 0; i < num_tags; i++) {
-    
-        // tag handle
-    MBTag tag_handle;
-
-      // size, data type
-    int tag_size, tag_data_type, tag_type;
-    UNPACK_INT(buff_ptr, tag_size);
-    UNPACK_INT(buff_ptr, tag_type);
-    UNPACK_INT(buff_ptr, tag_data_type);
-      
-      // default value
-    int def_val_size;
-    UNPACK_INT(buff_ptr, def_val_size);
-    void *def_val_ptr = NULL;
-    if (def_val_size) {
-      def_val_ptr = buff_ptr;
-      buff_ptr += def_val_size;
-      UPC(tag_size, " void");
-    }
-    
-      // name
-    int name_len;
-    UNPACK_INT(buff_ptr, name_len);
-    std::string tag_name( reinterpret_cast<char*>(buff_ptr), name_len );
-    buff_ptr += name_len;
-    UPC(64, " chars");
-#ifdef DEBUG_PACKING
-    std::cerr << "Unpacking tag " << tag_name << std::endl;
-#endif    
-
-      // create the tag
-    if (tag_size == MB_VARIABLE_LENGTH) 
-      result = mbImpl->tag_create_variable_length( tag_name.c_str(), (MBTagType)tag_type,
-                                                   (MBDataType)tag_data_type, tag_handle,
-                                                   def_val_ptr, def_val_size );
-    else
-      result = mbImpl->tag_create(tag_name.c_str(), tag_size, (MBTagType) tag_type, 
-                                  (MBDataType) tag_data_type, tag_handle,
-                                  def_val_ptr);
-    if (MB_ALREADY_ALLOCATED == result) {
-        // already allocated tag, check to make sure it's the same size, type, etc.
-      const TagInfo *tag_info = tagServer->get_tag_info(tag_name.c_str());
-      MBTagType this_type;
-      result = mbImpl->tag_get_type(tag_handle, this_type);
-      if (tag_size != tag_info->get_size() ||
-          tag_type != this_type ||
-          tag_data_type != tag_info->get_data_type() ||
-          (def_val_ptr && !tag_info->default_value()) ||
-          (!def_val_ptr && tag_info->default_value())) {
-        RRA("Didn't get correct tag info when unpacking tag.");
-      }
-    }
-    else if (MB_SUCCESS != result) return result;
-
-      // go through handle vec (in buffer) and convert to local handles in-place
-    int num_ents;
-    UNPACK_INT(buff_ptr, num_ents);
-    MBEntityHandle *handle_vec = (MBEntityHandle*)buff_ptr;
-    buff_ptr += num_ents * sizeof(MBEntityHandle);
-
-    if (!store_remote_handles) {
-        // in this case handles are indices into new entity range; need to convert
-        // to local handles
-      result = get_local_handles(handle_vec, num_ents, entities);
-      RRA("Unable to convert to local handles.");
-    }
-
-      // if it's a handle type, also convert tag vals in-place in buffer
-    if (MB_TYPE_HANDLE == tag_type) {
-      MBEntityHandle *val_vec = (MBEntityHandle*)buff_ptr;
-      result = get_local_handles(val_vec, num_ents, entities);
-      RRA("Failed to get local handles for tag vals.");
-    }
-
-    if (tag_size == MB_VARIABLE_LENGTH) {
-        // Be careful of alignment here.  If the integers are aligned
-        // in the buffer, we can use them directly.  Otherwise we must
-        // copy them.
-      const int* size_arr;
-      if (((size_t)buff_ptr)%4) {
-        var_lengths.resize( num_ents );
-        memcpy( &var_lengths[0], buff_ptr, num_ents*sizeof(int) );
-        size_arr = &var_lengths[0];
-      }
-      else {
-        size_arr = reinterpret_cast<const int*>(buff_ptr);
-      }
-      buff_ptr += sizeof(int) * num_ents;
-      UPC(sizeof(int) * num_ents, " void");
-      
-        // get pointers into buffer for each tag value
-      var_len_vals.resize(num_ents);
-      for (std::vector<MBEntityHandle>::size_type i = 0; 
-           i < (std::vector<MBEntityHandle>::size_type) num_ents; ++i) {
-        var_len_vals[i] = buff_ptr;
-        buff_ptr += size_arr[i];
-        UPC(size_arr[i], " void");
-      }
-      result = mbImpl->tag_set_data( tag_handle, handle_vec, num_ents,
-                                     &var_len_vals[0], size_arr );
-      RRA("Trouble setting tag data when unpacking variable-length tag.");
-    }
-    else {
-      result = mbImpl->tag_set_data(tag_handle, handle_vec,
-                                    num_ents, buff_ptr);
-      RRA("Trouble setting range-based tag data when unpacking tag.");
-      buff_ptr += num_ents * tag_size;
-      UPC(num_ents * tag_size, " void");
-    }
-  }
-  
-#ifdef DEBUG_PACKING
-  std::cerr << std::endl << "Done unpacking tags." << std::endl;
-#endif
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::resolve_shared_ents(MBEntityHandle this_set,
-                                                int resolve_dim,
-                                                int shared_dim,
-                                                const MBTag* id_tag) 
-{
-  MBErrorCode result;
-  MBRange proc_ents;
-      // get the entities in the partition sets
-  for (MBRange::iterator rit = partitionSets.begin(); rit != partitionSets.end(); rit++) {
-    MBRange tmp_ents;
-    result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true);
-    if (MB_SUCCESS != result) return result;
-    proc_ents.merge(tmp_ents);
-  }
-
-    // resolve dim is maximal dim of entities in proc_ents
-  if (-1 == resolve_dim) {
-    resolve_dim = mbImpl->dimension_from_handle(*proc_ents.rbegin()); 
-    RRA("Couldn't get dimension.");
-    
-  }
-
-    // proc_ents should all be of same dimension
-  if (resolve_dim > shared_dim &&
-      mbImpl->dimension_from_handle(*proc_ents.rbegin()) !=
-      mbImpl->dimension_from_handle(*proc_ents.begin())) {
-    MBRange::iterator lower = proc_ents.lower_bound(MBCN::TypeDimensionMap[0].first),
-      upper = proc_ents.upper_bound(MBCN::TypeDimensionMap[resolve_dim-1].second);
-    proc_ents.erase(lower, upper);
-  }
-  
-    // must call even if we don't have any entities, to make sure
-    // collective comm'n works
-  return resolve_shared_ents(this_set, proc_ents, resolve_dim, shared_dim, id_tag);
-}
-  
-MBErrorCode MBParallelComm::resolve_shared_ents(MBEntityHandle this_set,
-                                                MBRange &proc_ents,
-                                                int resolve_dim,
-                                                int shared_dim,
-                                                const MBTag* id_tag) 
-{
-#ifdef DEBUG_MPE
-  define_mpe();
-
-  MPE_Log_event(RESOLVE_START, procConfig.proc_rank(), "Entering resolve_shared_ents.");
-#endif
-
-  MBErrorCode result;
-  if (debug) std::cerr << "Resolving shared entities." << std::endl;
-
-  if (-1 == shared_dim) {
-    if (0 == resolve_dim) {
-      result = mbImpl->get_dimension(shared_dim); 
-      RRA("Couldn't get dimension.");
-    }
-    else if (!proc_ents.empty())
-      shared_dim = mbImpl->dimension_from_handle(*proc_ents.begin())-1;
-    else if (resolve_dim == 3)
-      shared_dim = 2;
-    else {
-      assert(false && "Unable to guess shared_dim.");
-      return MB_FAILURE;
-    }
-  }
-  assert(shared_dim >= 0 && resolve_dim >= 0);
-  
-    // get the skin entities by dimension
-  MBRange skin_ents[4];
-  std::vector<int> gid_data;
-  std::vector<MBEntityHandle> handle_vec;
-  int skin_dim;
-
-    // get the entities to be skinned
-  if (resolve_dim < shared_dim) {
-      // for vertex-based partition, it's the elements adj to the vertices
-    result = mbImpl->get_adjacencies(proc_ents, shared_dim,
-                                     false, skin_ents[resolve_dim],
-                                     MBInterface::UNION);
-    RRA("Failed getting skinned entities.");
-    skin_dim = shared_dim-1;
-  }
-  else {
-      // for element-based partition, it's just the elements
-    skin_ents[resolve_dim] = proc_ents;
-    skin_dim = resolve_dim-1;
-  }
-
-    // find the skin
-  MBSkinner skinner(mbImpl);
-  result = skinner.find_skin(skin_ents[skin_dim+1], false, skin_ents[skin_dim],
-                             0, true);
-  RRA("Failed to find skin.");
-  if (debug) std::cerr << "Found skin, now resolving." << std::endl;
-
-    // get entities adjacent to skin ents from shared_dim down to zero
-  for (int this_dim = skin_dim-1; this_dim >= 0; this_dim--) {
-    result = mbImpl->get_adjacencies(skin_ents[skin_dim], this_dim,
-                                     true, skin_ents[this_dim],
-                                     MBInterface::UNION);
-    RRA("Failed getting skin adjacencies.");
-  }
-
-    // resolve shared vertices first
-
-    // global id tag
-  MBTag gid_tag; int def_val = -1;
-  if (id_tag)
-    gid_tag = *id_tag;
-  else {
-    result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int),
-                                MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
-                                &def_val, true);
-    if (MB_FAILURE == result) return result;
-
-    else if (MB_ALREADY_ALLOCATED != result) {
-        // just created it, so we need global ids
-      result = assign_global_ids(0, skin_dim+1);
-      RRA("Failed assigning global ids.");
-    }
-  }
-  
-    // store index in temp tag; reuse gid_data 
-  gid_data.resize(2*skin_ents[0].size());
-  int idx = 0;
-  for (MBRange::iterator rit = skin_ents[0].begin(); 
-       rit != skin_ents[0].end(); rit++) 
-    gid_data[idx] = idx, idx++;
-  MBTag idx_tag;
-  result = mbImpl->tag_create("__idx_tag", sizeof(int), MB_TAG_DENSE,
-                              MB_TYPE_INTEGER, idx_tag, &def_val, true);
-  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
-  result = mbImpl->tag_set_data(idx_tag, skin_ents[0], &gid_data[0]);
-  RRA("Couldn't assign index tag.");
-
-    // get gids for skin ents in a vector, to pass to gs
-  result = mbImpl->tag_get_data(gid_tag, skin_ents[0], &gid_data[0]);
-  RRA("Couldn't get gid tag for skin vertices.");
-
-    // put handles in vector for passing to gs setup
-  std::copy(skin_ents[0].begin(), skin_ents[0].end(), 
-            std::back_inserter(handle_vec));
-  
-#ifdef DEBUG_MPE
-  MPE_Log_event(SHAREDV_START, procConfig.proc_rank(), "Creating crystal router.");
-#endif
-
-    // get a crystal router
-  crystal_data *cd = procConfig.crystal_router();
-
-/*  
-    // get total number of entities; will overshoot highest global id, but
-    // that's ok
-  int num_total[2] = {0, 0}, num_local[2] = {0, 0};
-  result = mbImpl->get_number_entities_by_dimension(0, 0, num_local);
-  if (MB_SUCCESS != result) return result;
-  int failure = MPI_Allreduce(num_local, num_total, 1,
-                              MPI_INTEGER, MPI_SUM, procConfig.proc_comm());
-  if (failure) {
-    result = MB_FAILURE;
-    RRA("Allreduce for total number of shared ents failed.");
-  }
-  
-*/
-    // call gather-scatter to get shared ids & procs
-  gs_data *gsd;
-  assert(sizeof(ulong_) == sizeof(MBEntityHandle));
-  if (sizeof(int) != sizeof(ulong_)) {
-    std::vector<long> lgid_data(gid_data.size());
-    std::copy(gid_data.begin(), gid_data.end(), lgid_data.begin());
-    gsd = gs_data_setup(skin_ents[0].size(), &lgid_data[0], 
-                        (ulong_*)&handle_vec[0], 2, 1, 1, cd);
-  }
-  else {
-    gsd = gs_data_setup(skin_ents[0].size(), (long*)&gid_data[0], 
-                        (ulong_*)&handle_vec[0], 2, 1, 1, cd);
-  }
-  
-  if (NULL == gsd) {
-    result = MB_FAILURE;
-    RRA("Couldn't create gs data.");
-  }
-
-    // get shared proc tags
-  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
-  result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
-                                sharedh_tag, sharedhs_tag, pstatus_tag);
-  RRA("Couldn't get shared proc tags.");
-  
-    // load shared verts into a tuple, then sort by index
-  tuple_list shared_verts;
-  tuple_list_init_max(&shared_verts, 2, 0, 1, 0, 
-                      skin_ents[0].size()*(MAX_SHARING_PROCS+1));
-  unsigned int i = 0, j = 0;
-  for (unsigned int p = 0; p < gsd->nlinfo->np; p++) 
-    for (unsigned int np = 0; np < gsd->nlinfo->nshared[p]; np++) {
-      shared_verts.vi[i++] = gsd->nlinfo->sh_ind[j];
-      shared_verts.vi[i++] = gsd->nlinfo->target[p];
-      shared_verts.vul[j] = gsd->nlinfo->ulabels[j];
-      j++;
-      shared_verts.n++;
-    }
-  
-  int max_size = skin_ents[0].size()*(MAX_SHARING_PROCS+1);
-  buffer sort_buffer;
-  buffer_init(&sort_buffer, max_size);
-  tuple_list_sort(&shared_verts, 0, &sort_buffer);
-  buffer_free(&sort_buffer);
-
-    // set sharing procs and handles tags on skin ents
-  int maxp = -1;
-  std::vector<int> sharing_procs(MAX_SHARING_PROCS);
-  std::fill(sharing_procs.begin(), sharing_procs.end(), maxp);
-  j = 0; i = 0;
-
-    // get ents shared by 1 or n procs
-  std::map<std::vector<int>, MBRange> proc_nranges;
-  MBRange proc_verts;
-  result = mbImpl->get_adjacencies(proc_ents, 0, false, proc_verts,
-                                   MBInterface::UNION);
-  RRA("Couldn't get proc_verts.");
-  
-  result = tag_shared_verts(shared_verts, skin_ents,
-                            proc_nranges, proc_verts);
-  RRA("Trouble tagging shared verts.");
-
-#ifdef DEBUG_MPE
-  MPE_Log_event(SHAREDV_END, procConfig.proc_rank(), "Finished tag_shared_verts.");
-#endif
-
-    // get entities shared by 1 or n procs
-  result = tag_shared_ents(resolve_dim, shared_dim, skin_ents,
-                           proc_nranges);
-  RRA("Trouble tagging shared entities.");
-
-  tuple_list_free(&shared_verts);
-  
-  if (debug) {
-    for (std::map<std::vector<int>, MBRange>::const_iterator mit = proc_nranges.begin();
-         mit != proc_nranges.end(); mit++) {
-      std::cout << "Iface: ";
-      for (std::vector<int>::const_iterator vit = (mit->first).begin();
-           vit != (mit->first).end(); vit++) std::cout << " " << *vit;
-      std::cout << std::endl;
-    }
-  }
-  
-    // create the sets for each interface; store them as tags on
-    // the interface instance
-  MBRange iface_sets;
-  result = create_interface_sets(proc_nranges, resolve_dim, shared_dim);
-  RRA("Trouble creating iface sets.");
-
-    // establish comm procs and buffers for them
-  std::set<unsigned int> procs;
-  result = get_interface_procs(procs, true);
-  RRA("Trouble getting iface procs.");
-
-    // resolve shared entity remote handles; implemented in ghost cell exchange
-    // code because it's so similar
-  result = exchange_ghost_cells(-1, -1, 0, true, true);
-  RRA("Trouble resolving shared entity remote handles.");
-
-    // now build parent/child links for interface sets
-  result = create_iface_pc_links();
-  RRA("Trouble creating interface parent/child links.");
-
-  gs_data_free(gsd);
-
-#ifdef DEBUG_MPE
-  MPE_Log_event(RESOLVE_END, procConfig.proc_rank(), "Exiting resolve_shared_ents.");
-#endif
-
-    // done
-  return result;
-}
-
-void MBParallelComm::define_mpe() 
-{
-#ifdef DEBUG_MPE
-    // define mpe states used for logging
-  int success;
-  MPE_Log_get_state_eventIDs( &IFACE_START, &IFACE_END);
-  MPE_Log_get_state_eventIDs( &GHOST_START, &GHOST_END);
-  MPE_Log_get_state_eventIDs( &SHAREDV_START, &SHAREDV_END);
-  MPE_Log_get_state_eventIDs( &RESOLVE_START, &RESOLVE_END);
-  MPE_Log_get_state_eventIDs( &ENTITIES_START, &ENTITIES_END);
-  MPE_Log_get_state_eventIDs( &RHANDLES_START, &RHANDLES_END);
-  success = MPE_Describe_state(IFACE_START, IFACE_END, "Resolve interface ents", "green");
-  success = MPE_Describe_state(GHOST_START, GHOST_END, "Exchange ghost ents", "red");
-  success = MPE_Describe_state(SHAREDV_START, SHAREDV_END, "Resolve interface vertices", "blue");
-  success = MPE_Describe_state(RESOLVE_START, RESOLVE_END, "Resolve shared ents", "purple");
-  success = MPE_Describe_state(ENTITIES_START, ENTITIES_END, "Exchange shared ents", "yellow");
-  success = MPE_Describe_state(RHANDLES_START, RHANDLES_END, "Remote handles", "cyan");
-#endif
-}
-
-MBErrorCode MBParallelComm::resolve_shared_ents(MBParallelComm **pc, 
-                                                const unsigned int np, 
-                                                const int part_dim) 
-{
-  std::vector<MBRange> verts(np);
-  int tot_verts = 0;
-  unsigned int p, i, j, v;
-  MBErrorCode rval;
-  for (p = 0; p < np; p++) {
-    MBSkinner skinner(pc[p]->get_moab());
-    MBRange part_ents, skin_ents;
-    rval = pc[p]->get_moab()->get_entities_by_dimension(0, part_dim, part_ents);
-    if (MB_SUCCESS != rval) return rval;
-    rval = skinner.find_skin(part_ents, false, skin_ents, 0, true);
-    if (MB_SUCCESS != rval) return rval;
-    rval = pc[p]->get_moab()->get_adjacencies(skin_ents, 0, true, verts[p],
-                                              MBInterface::UNION);
-    if (MB_SUCCESS != rval) return rval;
-    tot_verts += verts[p].size();
-  }
-  
-  tuple_list shared_ents;
-  tuple_list_init_max(&shared_ents, 2, 0, 1, 0, tot_verts);
-
-  i = 0; j = 0;
-  std::vector<int> gids;
-  MBRange::iterator rit;
-  MBTag gid_tag;
-  int dum_default = -1;
-  for (p = 0; p < np; p++) {
-    rval = pc[p]->get_moab()->tag_create(GLOBAL_ID_TAG_NAME, 
-                                         sizeof(int), MB_TAG_DENSE,
-                                         MB_TYPE_INTEGER, gid_tag, 
-                                         &dum_default, true);
-    gids.resize(verts[p].size());
-    rval = pc[p]->get_moab()->tag_get_data(gid_tag, verts[p], &gids[0]);
-    if (MB_SUCCESS != rval) return rval;
-    
-    for (v = 0, rit = verts[p].begin(); v < gids.size(); v++, rit++) {
-      shared_ents.vi[i++] = gids[v];
-      shared_ents.vi[i++] = p;
-      shared_ents.vul[j] = *rit;
-      j++;
-      shared_ents.n++;
-    }
-  }
-  
-  buffer sort_buffer;
-  buffer_init(&sort_buffer, tot_verts);
-  tuple_list_sort(&shared_ents, 0, &sort_buffer);
-  buffer_free(&sort_buffer);
-
-  j = 0; i = 0;
-  std::vector<MBEntityHandle> handles;
-  std::vector<int> procs;
-  
-  while (i < shared_ents.n) {
-    handles.clear();
-    procs.clear();
-    
-      // count & accumulate sharing procs
-    int this_gid = shared_ents.vi[j];
-    while (i < shared_ents.n && shared_ents.vi[j] == this_gid) {
-      j++;
-      procs.push_back( shared_ents.vi[j++] );
-      handles.push_back( shared_ents.vul[i++] );
-    }
-    if (1 == procs.size()) continue;
-    
-    for (v = 0; v < procs.size(); v++) {
-      rval = pc[procs[v]]->update_remote_data(handles[v], 
-                                              &procs[0], &handles[0], procs.size(),
-                                              PSTATUS_INTERFACE);
-      if (MB_SUCCESS != rval) return rval;
-    }
-  }
-
-  std::set<unsigned int> psets;
-  for (p = 0; p < np; p++) {
-    rval = pc[p]->create_interface_sets(part_dim, part_dim-1);
-    if (MB_SUCCESS != rval) return rval;
-      // establish comm procs and buffers for them
-    psets.clear();
-    rval = pc[p]->get_interface_procs(psets, true);
-    if (MB_SUCCESS != rval) return rval;
-  }
-
-  tuple_list_free(&shared_ents);
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::tag_iface_entities() 
-{
-  MBErrorCode result = MB_SUCCESS;
-  MBRange iface_ents, tmp_ents, rmv_ents;
-  std::vector<unsigned char> pstat;
-  unsigned char set_pstat;
-  MBRange::iterator rit2;
-  unsigned int i;
-  
-  for (MBRange::iterator rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
-    iface_ents.clear();
-    
-    result = mbImpl->get_entities_by_handle(*rit, iface_ents);
-    RRA("Couldn't get iface set contents.");
-    pstat.resize(iface_ents.size());
-    result = mbImpl->tag_get_data(pstatus_tag(), iface_ents, &pstat[0]);
-    RRA("Couldn't get pstatus values for set ents.");
-    result = mbImpl->tag_get_data(pstatus_tag(), &(*rit), 1, &set_pstat);
-    RRA("Couldn't get pstatus values for set.");
-    rmv_ents.clear();
-    for (rit2 = iface_ents.begin(), i = 0; rit2 != iface_ents.end(); rit2++, i++) {
-      if (!(pstat[i] & PSTATUS_INTERFACE)) {
-        rmv_ents.insert(*rit2);
-        pstat[i] = 0x0;
-      }
-    }
-    result = mbImpl->remove_entities(*rit, rmv_ents);
-    RRA("Couldn't remove entities from set.");
-
-    if (!(set_pstat & PSTATUS_NOT_OWNED)) continue;
-      // if we're here, we need to set the notowned status on (remaining) set contents
-
-      // remove rmv_ents from the contents list
-    iface_ents = subtract(iface_ents, rmv_ents);
-      // compress the pstat vector (removing 0x0's)
-    std::remove_if(pstat.begin(), pstat.end(), 
-                   std::bind2nd(std::equal_to<unsigned char>(), 0x0));
-      // fold the not_owned bit into remaining values
-    unsigned int sz = iface_ents.size();
-    for (i = 0; i < sz; i++)
-      pstat[i] |= PSTATUS_NOT_OWNED;
-
-      // set the tag on the entities
-    result = mbImpl->tag_set_data(pstatus_tag(), iface_ents, &pstat[0]);
-    RRA("Couldn't set pstatus values for set ents.");
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::set_pstatus_entities(MBRange &pstatus_ents,
-                                                 unsigned char pstatus_val,
-                                                 bool lower_dim_ents,
-                                                 bool verts_too,
-                                                 int operation) 
-{
-  std::vector<unsigned char> pstatus_vals(pstatus_ents.size());
-  MBRange all_ents, *range_ptr = &pstatus_ents;
-  MBErrorCode result;
-  if (lower_dim_ents || verts_too) {
-    all_ents = pstatus_ents;
-    range_ptr = &all_ents;
-    int start_dim = (lower_dim_ents ? mbImpl->dimension_from_handle(*pstatus_ents.rbegin())-1 : 0);
-    for (; start_dim >= 0; start_dim--) {
-      result = mbImpl->get_adjacencies(all_ents, start_dim, true, all_ents,
-                                       MBInterface::UNION);
-      RRA(" ");
-    }
-  }
-  if (MBInterface::UNION == operation) {
-    result = mbImpl->tag_get_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]);
-    RRA("Couldn't get pstatus tag value.");
-    for (unsigned int i = 0; i < pstatus_vals.size(); i++)
-      pstatus_vals[i] |= pstatus_val;
-  }
-  else {
-    for (unsigned int i = 0; i < pstatus_vals.size(); i++)
-      pstatus_vals[i] = pstatus_val;
-  }
-  result = mbImpl->tag_set_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]);
-  RRA("Couldn't set pstatus tag value.");
-  
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::set_pstatus_entities(MBEntityHandle *pstatus_ents,
-                                                 int num_ents,
-                                                 unsigned char pstatus_val,
-                                                 bool lower_dim_ents,
-                                                 bool verts_too,
-                                                 int operation) 
-{
-  std::vector<unsigned char> pstatus_vals(num_ents);
-  MBErrorCode result;
-  if (lower_dim_ents || verts_too) {
-      // in this case, call the range-based version
-    MBRange tmp_range;
-    std::copy(pstatus_ents, pstatus_ents+num_ents, mb_range_inserter(tmp_range));
-    return set_pstatus_entities(tmp_range, pstatus_val, lower_dim_ents, 
-                                verts_too, operation);
-  }
-
-  if (MBInterface::UNION == operation) {
-    result = mbImpl->tag_get_data(pstatus_tag(), pstatus_ents, num_ents, &pstatus_vals[0]);
-    RRA("Couldn't get pstatus tag value.");
-    for (unsigned int i = 0; i < (unsigned int) num_ents; i++)
-      pstatus_vals[i] |= pstatus_val;
-  }
-  else {
-    for (unsigned int i = 0; i < (unsigned int) num_ents; i++)
-      pstatus_vals[i] = pstatus_val;
-  }
-  result = mbImpl->tag_set_data(pstatus_tag(), pstatus_ents, num_ents, &pstatus_vals[0]);
-  RRA("Couldn't set pstatus tag value.");
-  
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::create_interface_sets(int resolve_dim, int shared_dim) 
-{
-  std::map<std::vector<int>, MBRange> proc_nranges;
-  
-    // build up the list of shared entities
-  int procs[MAX_SHARING_PROCS];
-  MBEntityHandle handles[MAX_SHARING_PROCS];
-  MBErrorCode result;
-  int nprocs;
-  unsigned char pstat;
-  for (MBRange::iterator rit = sharedEnts.begin(); rit != sharedEnts.end(); rit++) {
-    if (shared_dim != -1 && mbImpl->dimension_from_handle(*rit) > shared_dim)
-      continue;
-    result = get_sharing_data(*rit, procs, handles, pstat, nprocs);
-    RRA("");
-    std::sort(procs, procs+nprocs);
-    std::vector<int> tmp_procs(procs, procs + nprocs);
-    proc_nranges[tmp_procs].insert(*rit);
-  }
-                                                  
-  MBSkinner skinner(mbImpl);
-  MBRange skin_ents[4];
-  result = mbImpl->get_entities_by_dimension(0, resolve_dim, skin_ents[resolve_dim]);
-  RRA("");
-  result = skinner.find_skin(skin_ents[resolve_dim], false, 
-                             skin_ents[resolve_dim-1], 0, true);
-  RRA("Failed to find skin.");
-  if (shared_dim > 1) {
-    result = mbImpl->get_adjacencies(skin_ents[resolve_dim-1], resolve_dim-2, true,
-                                     skin_ents[resolve_dim-2], MBInterface::UNION);
-    RRA("");
-  }
-
-  result = tag_shared_ents(resolve_dim, shared_dim, skin_ents,
-                           proc_nranges);
-    
-  return create_interface_sets(proc_nranges, resolve_dim, shared_dim);
-}
-  
-MBErrorCode MBParallelComm::create_interface_sets(std::map<std::vector<int>, MBRange> &proc_nranges,
-                                                  int resolve_dim, int shared_dim) 
-{
-  if (proc_nranges.empty()) return MB_SUCCESS;
-  
-  int proc_ids[MAX_SHARING_PROCS];
-  MBEntityHandle proc_handles[MAX_SHARING_PROCS];
-  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
-  MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
-                                            sharedh_tag, sharedhs_tag,
-                                            pstatus_tag);
-  RRA("Trouble getting shared proc tags in create_interface_sets.");
-  MBRange::iterator rit;
-
-    // create interface sets, tag them, and tag their contents with iface set tag
-  std::vector<MBEntityHandle> tag_vals;
-  std::vector<unsigned char> pstatus;
-  for (std::map<std::vector<int>,MBRange>::iterator mit = proc_nranges.begin();
-       mit != proc_nranges.end(); mit++) {
-      // create the set
-    MBEntityHandle new_set;
-    result = mbImpl->create_meshset(MESHSET_SET, new_set); 
-    RRA("Failed to create interface set.");
-    interfaceSets.insert(new_set);
-
-      // add entities
-    result = mbImpl->add_entities(new_set, mit->second); 
-    RRA("Failed to add entities to interface set.");
-      // tag set with the proc rank(s)
-    if (mit->first.size() == 1) {
-      result = mbImpl->tag_set_data(sharedp_tag, &new_set, 1, 
-                                    &(mit->first)[0]); 
-      proc_handles[0] = 0;
-      result = mbImpl->tag_set_data(sharedh_tag, &new_set, 1, 
-                                    proc_handles); 
-    }
-    else {
-      // pad tag data out to MAX_SHARING_PROCS with -1
-      assert( mit->first.size() <= MAX_SHARING_PROCS );
-      std::copy( mit->first.begin(), mit->first.end(), proc_ids );
-      std::fill( proc_ids + mit->first.size(), proc_ids + MAX_SHARING_PROCS, -1 );
-      result = mbImpl->tag_set_data(sharedps_tag, &new_set, 1, proc_ids );
-      unsigned int ind = std::find(proc_ids, proc_ids+mit->first.size(), procConfig.proc_rank())
-          - proc_ids;
-      assert(ind < mit->first.size());
-      std::fill( proc_handles + mit->first.size(), proc_handles + MAX_SHARING_PROCS, 0);
-      proc_handles[ind] = new_set;
-      result = mbImpl->tag_set_data(sharedhs_tag, &new_set, 1, proc_handles); 
-    }
-    RRA("Failed to tag interface set with procs.");
-    
-      // get the owning proc, then set the pstatus tag on iface set
-    int min_proc = (mit->first)[0];
-    unsigned char pval = (PSTATUS_SHARED | PSTATUS_INTERFACE);
-    if (min_proc < (int) procConfig.proc_rank()) pval |= PSTATUS_NOT_OWNED;
-    if (mit->first.size() > 1) pval |= PSTATUS_MULTISHARED;
-    result = mbImpl->tag_set_data(pstatus_tag, &new_set, 1, &pval); 
-    RRA("Failed to tag interface set with pstatus.");
-
-      // tag the vertices with the same thing
-    pstatus.clear();
-    MBRange verts = (mit->second).subset_by_type(MBVERTEX);
-    pstatus.resize(verts.size(), pval);
-    result = mbImpl->tag_set_data(pstatus_tag, verts, &pstatus[0]); 
-    RRA("Failed to tag interface set vertices with pstatus.");
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::create_iface_pc_links() 
-{
-    // now that we've resolved the entities in the iface sets, 
-    // set parent/child links between the iface sets
-
-    // first tag all entities in the iface sets
-  MBTag tmp_iface_tag;
-  MBEntityHandle tmp_iface_set = 0;
-  MBErrorCode result = mbImpl->tag_create("__tmp_iface", sizeof(MBEntityHandle),
-                                          MB_TAG_DENSE, MB_TYPE_HANDLE,
-                                          tmp_iface_tag, &tmp_iface_set);
-  if (MB_ALREADY_ALLOCATED != result && MB_SUCCESS != result) 
-    RRA("Failed to create temporary iface set tag.");
-
-  MBRange iface_ents;
-  std::vector<MBEntityHandle> tag_vals;
-  MBRange::iterator rit;
-  
-  for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
-      // tag entities with interface set
-    iface_ents.clear();
-    result = mbImpl->get_entities_by_handle(*rit, iface_ents);
-    RRA("Couldn't get entities in iface set.");
-    
-    if (iface_ents.empty()) continue;
-    
-    tag_vals.resize(iface_ents.size());
-    std::fill(tag_vals.begin(), tag_vals.end(), *rit);
-    result = mbImpl->tag_set_data(tmp_iface_tag, iface_ents, &tag_vals[0]); 
-    RRA("Failed to tag iface entities with interface set.");
-  }
-  
-    // now go back through interface sets and add parent/child links
-  MBRange tmp_ents2;
-  for (int d = 2; d >= 0; d--) {
-    for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
-        // get entities on this interface
-      iface_ents.clear();
-      result = mbImpl->get_entities_by_handle(*rit, iface_ents, true);
-      RRA("Couldn't get entities by dimension.");
-      if (iface_ents.empty() ||
-          mbImpl->dimension_from_handle(*iface_ents.rbegin()) != d) continue;
-
-        // get higher-dimensional entities and their interface sets
-      result = mbImpl->get_adjacencies(&(*iface_ents.begin()), 1, d+1,
-                                       false, tmp_ents2);
-      RRA("Couldn't get adjacencies for interface sets.");
-      tag_vals.resize(tmp_ents2.size());
-      result = mbImpl->tag_get_data(tmp_iface_tag, tmp_ents2, &tag_vals[0]);
-      RRA("Couldn't get iface set tag for interface sets.");
-      
-        // go through and for any on interface make it a parent
-      MBEntityHandle last_set = 0;
-      for (unsigned int i = 0; i < tag_vals.size(); i++) {
-        if (tag_vals[i] && tag_vals[i] != last_set) {
-          result = mbImpl->add_parent_child(tag_vals[i], *rit);
-          RRA("Couldn't add parent/child link for interface set.");
-          last_set = tag_vals[i];
-        }
-      }
-    }
-  }
-  
-    // delete the temporary tag
-  result = mbImpl->tag_delete(tmp_iface_tag);
-  RRA("Couldn't delete tmp iface tag.");
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::tag_shared_ents(int resolve_dim,
-                                            int shared_dim,
-                                            MBRange *skin_ents,
-                                            std::map<std::vector<int>, MBRange> &proc_nranges) 
-{
-    // set sharing procs tags on other skin ents
-  MBErrorCode result;
-  const MBEntityHandle *connect; int num_connect;
-  std::set<int> sharing_procs;
-  std::vector<MBEntityHandle> dum_connect;
-  std::vector<int> sp_vec;
-
-  for (int d = 3; d > 0; d--) {
-    if (resolve_dim == d) continue;
-    
-    for (MBRange::iterator rit = skin_ents[d].begin();
-         rit != skin_ents[d].end(); rit++) {
-        // get connectivity
-      result = mbImpl->get_connectivity(*rit, connect, num_connect, true,
-                                        &dum_connect);
-      RRA("Failed to get connectivity on non-vertex skin entities.");
- 
-      int op = (resolve_dim < shared_dim ? MBInterface::UNION : MBInterface::INTERSECT);      
-      result = get_sharing_data(connect, num_connect, sharing_procs, op);
-      RRA("Failed to get sharing data in tag_shared_ents");
-      if (sharing_procs.empty()) continue;
-
-        // intersection is the owning proc(s) for this skin ent
-      sp_vec.clear();
-      std::copy(sharing_procs.begin(), sharing_procs.end(), std::back_inserter(sp_vec));
-      proc_nranges[sp_vec].insert(*rit);
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::tag_shared_verts(tuple_list &shared_ents,
-                                             MBRange *skin_ents,
-                                             std::map<std::vector<int>, MBRange> &proc_nranges,
-                                             MBRange &proc_verts) 
-{
-  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
-  MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
-                                            sharedh_tag, sharedhs_tag, pstatus_tag);
-  RRA("Trouble getting shared proc tags in tag_shared_verts.");
-  
-  unsigned int j = 0, i = 0;
-  std::vector<int> sharing_procs, sharing_procs2;
-  std::vector<MBEntityHandle> sharing_handles, sharing_handles2;
-  
-  while (j < 2*shared_ents.n) {
-      // count & accumulate sharing procs
-    int this_idx = shared_ents.vi[j];
-    MBEntityHandle this_ent = skin_ents[0][this_idx];
-    while (j < 2*shared_ents.n && shared_ents.vi[j] == this_idx) {
-      j++;
-      sharing_procs.push_back( shared_ents.vi[j++] );
-      sharing_handles.push_back( shared_ents.vul[i++] );
-    }
-
-    if (sharing_procs.size() > 1) {
-        // add current proc/handle to list
-      sharing_procs.push_back(procConfig.proc_rank());
-      sharing_handles.push_back(this_ent);
-    }
-      
-      // sort sharing_procs and sharing_handles such that
-      // sharing_procs is in ascending order.  Use temporary
-      // lists and binary search to re-order sharing_handles.
-    sharing_procs2 = sharing_procs;
-    std::sort( sharing_procs2.begin(), sharing_procs2.end() );
-    sharing_handles2.resize( sharing_handles.size() );
-    for (size_t k = 0; k < sharing_handles.size(); ++k) {
-      size_t idx = std::lower_bound( sharing_procs2.begin(), 
-                                     sharing_procs2.end(), 
-                                     sharing_procs[k] ) - sharing_procs2.begin();
-      sharing_handles2[idx] = sharing_handles[k];
-    }
-    sharing_procs.swap( sharing_procs2 );
-    sharing_handles.swap( sharing_handles2 );
-    
-    
-    proc_nranges[sharing_procs].insert(this_ent);
-
-    unsigned char share_flag = PSTATUS_SHARED, 
-        ms_flag = (PSTATUS_SHARED | PSTATUS_MULTISHARED);
-    if (sharing_procs.size() == 1) {
-      result = mbImpl->tag_set_data(sharedp_tag, &this_ent, 1,
-                                    &sharing_procs[0]);
-      result = mbImpl->tag_set_data(sharedh_tag, &this_ent, 1,
-                                    &sharing_handles[0]);
-      result = mbImpl->tag_set_data(pstatus_tag, &this_ent, 1, &share_flag);
-      RRA("Couldn't set shared tag on shared vertex.");
-      sharedEnts.insert(this_ent);
-    }
-    else {
-        // pad lists 
-      assert( sharing_procs.size() <= MAX_SHARING_PROCS );
-      sharing_procs.resize( MAX_SHARING_PROCS, -1 );
-      sharing_handles.resize( MAX_SHARING_PROCS, 0 );
-      result = mbImpl->tag_set_data(sharedps_tag, &this_ent, 1,
-                                    &sharing_procs[0]);
-      result = mbImpl->tag_set_data(sharedhs_tag, &this_ent, 1,
-                                    &sharing_handles[0]);
-      result = mbImpl->tag_set_data(pstatus_tag, &this_ent, 1, &ms_flag);
-      RRA("Couldn't set multi-shared tag on shared vertex.");
-      sharedEnts.insert(this_ent);
-    }
-    RRA("Failed setting shared_procs tag on skin vertices.");
-
-      // reset sharing proc(s) tags
-    sharing_procs.clear();
-    sharing_handles.clear();
-  }
-
-  return MB_SUCCESS;
-}
-  
-  //! get processors with which this processor communicates; sets are sorted by processor
-MBErrorCode MBParallelComm::get_interface_procs(std::set<unsigned int> &procs_set,
-                                                bool get_buffs)
-{
-    // make sure the sharing procs vector is empty
-  procs_set.clear();
-
-    // pre-load vector of single-proc tag values
-  unsigned int i, j;
-  std::vector<int> iface_proc(interfaceSets.size());
-  MBErrorCode result = mbImpl->tag_get_data(sharedp_tag(), interfaceSets, &iface_proc[0]);
-  RRA("Failed to get iface_proc for iface sets.");
-
-    // get sharing procs either from single-proc vector or by getting
-    // multi-proc tag value
-  int tmp_iface_procs[MAX_SHARING_PROCS];
-  std::fill(tmp_iface_procs, tmp_iface_procs+MAX_SHARING_PROCS, -1);
-  MBRange::iterator rit;
-  for (rit = interfaceSets.begin(), i = 0; rit != interfaceSets.end(); rit++, i++) {
-    if (-1 != iface_proc[i]) procs_set.insert((unsigned int) iface_proc[i]);
-    else {
-        // get the sharing_procs tag
-      result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1,
-                                    tmp_iface_procs);
-      RRA("Failed to get iface_procs for iface set.");
-      for (j = 0; j < MAX_SHARING_PROCS; j++) {
-        if (-1 != tmp_iface_procs[j] && tmp_iface_procs[j] != (int)procConfig.proc_rank()) 
-          procs_set.insert((unsigned int) tmp_iface_procs[j]);
-        else if (-1 == tmp_iface_procs[j]) {
-          std::fill(tmp_iface_procs, tmp_iface_procs+j, -1);
-          break;
-        }
-      }
-    }
-  }
-
-  if (get_buffs) {
-    for (std::set<unsigned int>::iterator sit = procs_set.begin(); sit != procs_set.end(); sit++)
-      get_buffers(*sit);
-  }
-  
-  return MB_SUCCESS;
-}
-  
-MBErrorCode MBParallelComm::get_pstatus_entities(int dim,
-                                                 unsigned char pstatus_val,
-                                                 MBRange &pstatus_ents)
-{
-  MBRange ents;
-  MBErrorCode result;
-  
-  if (-1 == dim) result = mbImpl->get_entities_by_handle(0, ents);
-  else result = mbImpl->get_entities_by_dimension(0, dim, ents);
-  RRA(" ");
-  
-  std::vector<unsigned char> pstatus(ents.size());
-  result = mbImpl->tag_get_data(pstatus_tag(), ents, &pstatus[0]);
-  RRA("Couldn't get pastatus tag.");
-  MBRange::iterator rit = ents.begin();
-  int i = 0;
-  if (pstatus_val) {
-    for (; rit != ents.end(); i++, rit++)
-      if (pstatus[i]&pstatus_val &&
-          (-1 == dim || mbImpl->dimension_from_handle(*rit) == dim)) 
-        pstatus_ents.insert(*rit);
-  }
-  else {
-    for (; rit != ents.end(); i++, rit++)
-      if (!pstatus[i] &&
-          (-1 == dim || mbImpl->dimension_from_handle(*rit) == dim)) 
-        pstatus_ents.insert(*rit);
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::check_global_ids(MBEntityHandle this_set,
-                                             const int dimension, 
-                                             const int start_id,
-                                             const bool largest_dim_only,
-                                             const bool parallel)
-{
-    // global id tag
-  MBTag gid_tag; int def_val = -1;
-  MBErrorCode result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int),
-                                          MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
-                                          &def_val, true);
-  if (MB_ALREADY_ALLOCATED != result &&
-      MB_SUCCESS != result) {
-    RRA("Failed to create/get gid tag handle.");
-  }
-
-  MBRange dum_range;
-  if (MB_ALREADY_ALLOCATED == result) {
-    void *tag_ptr = &def_val;
-    MBErrorCode tmp_result = mbImpl->get_entities_by_type_and_tag(this_set, MBVERTEX, 
-                                                                  &gid_tag, &tag_ptr, 1,
-                                                                  dum_range);
-    if (MB_SUCCESS != tmp_result) {
-      result = tmp_result;
-      RRA("Failed to get gid tag.");
-    }
-  }
-  
-  if (MB_ALREADY_ALLOCATED != result || !dum_range.empty()) {
-      // just created it, so we need global ids
-    result = assign_global_ids(this_set, dimension, start_id, largest_dim_only,
-                               parallel);
-    RRA("Failed assigning global ids.");
-  }
-
-  return MB_SUCCESS;
-}
-
-bool MBParallelComm::is_iface_proc(MBEntityHandle this_set,
-                                   int to_proc) 
-{
-  int sharing_procs[MAX_SHARING_PROCS];
-  std::fill(sharing_procs, sharing_procs+MAX_SHARING_PROCS, -1);
-  MBErrorCode result = mbImpl->tag_get_data(sharedp_tag(), &this_set, 1,
-                                            sharing_procs);
-  if (to_proc == sharing_procs[0]) return true;
-  
-  result = mbImpl->tag_get_data(sharedps_tag(), &this_set, 1,
-                                sharing_procs);
-  for (int i = 0; i < MAX_SHARING_PROCS; i++) {
-    if (to_proc == sharing_procs[i]) return true;
-    else if (-1 == sharing_procs[i]) return false;
-  }
-  
-  return false;
-}
-
-MBErrorCode MBParallelComm::filter_pstatus( MBRange &ents,
-                                            unsigned char pstat,
-                                            unsigned char op,
-                                            int to_proc,
-                                            MBRange *returned_ents)
-{
-  MBRange tmp_ents;
-
-  //assert(!ents.empty());
-  if (ents.empty()) {
-    if (returned_ents)
-      returned_ents->clear();
-    return MB_SUCCESS;
-  }
-
-    // Put into tmp_ents any entities which are not owned locally or
-    // who are already shared with to_proc
-  std::vector<unsigned char> shared_flags(ents.size()), shared_flags2;
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), ents,
-                                            &shared_flags[0]);
-  RRA("Failed to get pstatus flag.");
-  MBRange::const_iterator rit;
-  int i;
-  if (op == PSTATUS_OR) {
-    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++) 
-      if (((shared_flags[i] & ~pstat)^shared_flags[i]) & pstat) {
-        tmp_ents.insert(*rit);
-        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
-      }
-  }
-  else if (op == PSTATUS_AND) {
-    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++)
-      if ((shared_flags[i] & pstat) == pstat) {
-        tmp_ents.insert(*rit);
-        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
-      }
-  }
-  else if (op == PSTATUS_NOT) {
-    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++)
-      if (!(shared_flags[i] & pstat)) {
-        tmp_ents.insert(*rit);
-        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
-      }
-  }
-  else {
-    assert(false);
-    return MB_FAILURE;
-  }
-
-  if (-1 != to_proc) {
-
-    int sharing_procs[MAX_SHARING_PROCS];
-    std::fill(sharing_procs, sharing_procs+MAX_SHARING_PROCS, -1);
-    MBRange tmp_ents2;
-
-    for (rit = tmp_ents.begin(), i = 0; rit != tmp_ents.end(); rit++, i++) {
-        // we need to check sharing procs
-      if (shared_flags2[i] & PSTATUS_MULTISHARED) {
-        result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1,
-                                      sharing_procs);
-        assert(-1 != sharing_procs[0]);
-        RRA(" ");
-        for (unsigned int j = 0; j < MAX_SHARING_PROCS; j++) {
-            // if to_proc shares this entity, add it to list
-          if (sharing_procs[j] == to_proc) {
-            tmp_ents2.insert(*rit);
-          }
-          else if (sharing_procs[j] == -1) break;
-
-          sharing_procs[j] = -1;
-        }
-      }
-      else if (shared_flags2[i] & PSTATUS_SHARED) {
-        result = mbImpl->tag_get_data(sharedp_tag(), &(*rit), 1,
-                                      sharing_procs);
-        RRA(" ");
-        assert(-1 != sharing_procs[0]);
-        if (sharing_procs[0] == to_proc) tmp_ents2.insert(*rit);
-        sharing_procs[0] = -1;
-      }
-      else
-        assert("should never get here" && false);
-    }
-
-    tmp_ents.swap(tmp_ents2);
-  }
-  
-  if (returned_ents)
-    returned_ents->swap(tmp_ents);
-  else
-    ents.swap(tmp_ents);
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::exchange_ghost_cells(int ghost_dim, int bridge_dim,
-                                                 int num_layers,
-                                                 bool store_remote_handles,
-                                                 bool wait_all)
-{
-#ifdef DEBUG_MPE
-  if (!num_layers)
-    MPE_Log_event(IFACE_START, procConfig.proc_rank(), "Starting interface exchange.");
-  else
-    MPE_Log_event(GHOST_START, procConfig.proc_rank(), "Starting ghost exchange.");
-#endif
-
-#ifdef DEBUG_COMM
-//  std::ostringstream pfile("p");
-//  pfile << "p" << procConfig.proc_rank() << ".txt";
-//  std::cerr.open(pfile.str().c_str(), std::ios_base::trunc);
-  std::cerr << "Entering exchange_ghost_cells with num_layers = " 
-        << num_layers << std::endl; std::cerr.flush();
-#endif
-#ifdef DEBUG_MSGS
-  msgs.clear();
-  msgs.reserve(MAX_SHARING_PROCS);
-#endif
-
-    // if we're only finding out about existing ents, we have to be storing
-    // remote handles too
-  assert(num_layers > 0 || store_remote_handles);
-  
-  const bool is_iface = !num_layers;
-
-    // get the b-dimensional interface(s) with with_proc, where b = bridge_dim
-  
-  int success;
-  MBErrorCode result = MB_SUCCESS;
-  int incoming1 = 0, incoming2 = 0;
-
-  reset_all_buffers();
-  
-    // when this function is called, buffProcs should already have any 
-    // communicating procs
-
-    //===========================================
-    // post ghost irecv's for ghost entities from all communicating procs
-    //===========================================
-#ifdef DEBUG_MPE
-  MPE_Log_event(ENTITIES_START, procConfig.proc_rank(), "Starting entity exchange.");
-#endif
-    // index reqs the same as buffer/sharing procs indices
-  std::vector<MPI_Request> recv_ent_reqs(2*buffProcs.size(), MPI_REQUEST_NULL),
-      recv_remoteh_reqs(2*buffProcs.size(), MPI_REQUEST_NULL);
-  std::vector<unsigned int>::iterator proc_it;
-  int ind, p;
-  sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
-  for (ind = 0, proc_it = buffProcs.begin(); 
-       proc_it != buffProcs.end(); proc_it++, ind++) {
-    incoming1++;
-    PRINT_DEBUG_IRECV(procConfig.proc_rank(), buffProcs[ind], 
-                      remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE, 
-                      MB_MESG_ENTS_SIZE, incoming1);
-    success = MPI_Irecv(remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE, 
-                        MPI_UNSIGNED_CHAR, buffProcs[ind],
-                        MB_MESG_ENTS_SIZE, procConfig.proc_comm(), 
-                        &recv_ent_reqs[2*ind]);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv in ghost exchange.");
-    }
-  }
-  
-    //===========================================
-    // get entities to be sent to neighbors
-    //===========================================
-
-  MBRange sent_ents[MAX_SHARING_PROCS], allsent, tmp_range;
-  std::vector<std::set<unsigned int> > entprocs(allsent.size());
-  int dum_ack_buff;
-  result = get_sent_ents(is_iface, bridge_dim, ghost_dim, num_layers,
-                         sent_ents, allsent, entprocs);
-  RRA("get_sent_ents failed.");
-  
-    //===========================================
-    // pack and send ents from this proc to others
-    //===========================================
-  for (p = 0, proc_it = buffProcs.begin(); 
-       proc_it != buffProcs.end(); proc_it++, p++) {
-
-      // reserve space on front for size and for initial buff size
-    localOwnedBuffs[p]->reset_buffer(sizeof(int));
-
-      // entities
-    result = pack_entities(sent_ents[p], localOwnedBuffs[p], 
-                           store_remote_handles, buffProcs[p], is_iface,
-                           &entprocs, &allsent); 
-    RRA("Packing entities failed.");
-
-#ifdef DEBUG_MSGS
-    msgs.resize(msgs.size()+1);
-    msgs.back() = new Buffer(*localOwnedBuffs[p]);
-      //result = print_buffer(&ownerSBuffs[ind][0], MB_MESG_ENTS_SIZE, *proc_it, true);
-#endif
-
-      // send the buffer (size stored in front in send_buffer)
-    result = send_buffer(*proc_it, localOwnedBuffs[p], 
-                         MB_MESG_ENTS_SIZE, sendReqs[2*p], 
-                         recv_ent_reqs[2*p+1], &dum_ack_buff,
-                         incoming1,
-                         MB_MESG_REMOTEH_SIZE, 
-                         (!is_iface && store_remote_handles ? 
-                          localOwnedBuffs[p] : NULL),
-                         &recv_remoteh_reqs[2*p], &incoming2);
-    RRA("Failed to Isend in ghost exchange.");
-  }
-    
-
-    //===========================================
-    // receive/unpack new entities
-    //===========================================
-    // number of incoming messages for ghosts is the number of procs we 
-    // communicate with; for iface, it's the number of those with lower rank
-  MPI_Status status;
-  std::vector<std::vector<MBEntityHandle> > recd_ents(buffProcs.size());
-  std::vector<std::vector<MBEntityHandle> > L1hloc(buffProcs.size()), L1hrem(buffProcs.size());
-  std::vector<std::vector<int> > L1p(buffProcs.size());
-  std::vector<MBEntityHandle> L2hloc, L2hrem;
-  std::vector<unsigned int> L2p;
-  MBRange new_ents;
-  
-  while (incoming1) {
-      // wait for all recvs of ghost ents before proceeding to sending remote handles,
-      // b/c some procs may have sent to a 3rd proc ents owned by me;
-    PRINT_DEBUG_WAITANY(recv_ent_reqs, MB_MESG_ENTS_SIZE, procConfig.proc_rank());
-    
-    success = MPI_Waitany(2*buffProcs.size(), &recv_ent_reqs[0], &ind, &status);
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitany in ghost exchange.");
-    }
-
-    PRINT_DEBUG_RECD(status);
-    
-      // ok, received something; decrement incoming counter
-    incoming1--;
-    bool done = false;
-
-      // In case ind is for ack, we need index of one before it
-    unsigned int base_ind = 2*(ind/2);
-    result = recv_buffer(MB_MESG_ENTS_SIZE,
-                         status,
-                         remoteOwnedBuffs[ind/2],
-                         recv_ent_reqs[ind], recv_ent_reqs[ind+1],
-                         incoming1,
-                         localOwnedBuffs[ind/2], sendReqs[base_ind], sendReqs[base_ind+1],
-                         done,
-                         (!is_iface && store_remote_handles ? 
-                          localOwnedBuffs[ind/2] : NULL),
-                         MB_MESG_REMOTEH_SIZE,
-                         &recv_remoteh_reqs[base_ind], &incoming2);
-    RRA("Failed to receive buffer.");
-
-    if (done) {
-#ifdef DEBUG_MSGS
-    msgs.resize(msgs.size()+1);
-    msgs.back() = new Buffer(*remoteOwnedBuffs[ind/2]);
-        //print_buffer(&ghostRBuffs[ind/2][0], MB_MESG_ENTS_SIZE, buffProcs[ind/2], false);
-#endif
-
-        // message completely received - process buffer that was sent
-    remoteOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
-    result = unpack_entities(remoteOwnedBuffs[ind/2]->buff_ptr,
-                             store_remote_handles, ind/2, is_iface,
-                             L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents);
-      if (MB_SUCCESS != result) {
-        std::cout << "Failed to unpack entities.  Buffer contents:" << std::endl;
-        print_buffer(remoteOwnedBuffs[ind/2]->mem_ptr, MB_MESG_ENTS_SIZE, buffProcs[ind/2], false);
-        return result;
-      }
-
-      if (recv_ent_reqs.size() != 2*buffProcs.size()) {
-          // post irecv's for remote handles from new proc; shouldn't be iface, 
-          // since we know about all procs we share with
-        assert(!is_iface);
-        recv_remoteh_reqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
-        for (unsigned int i = recv_ent_reqs.size(); i < 2*buffProcs.size(); i+=2) {
-          localOwnedBuffs[i/2]->reset_buffer();
-          incoming2++;
-          PRINT_DEBUG_IRECV(procConfig.proc_rank(), buffProcs[i/2], 
-                            localOwnedBuffs[i/2]->mem_ptr, INITIAL_BUFF_SIZE,
-                            MB_MESG_REMOTEH_SIZE, incoming2);
-          success = MPI_Irecv(localOwnedBuffs[i/2]->mem_ptr, INITIAL_BUFF_SIZE, 
-                              MPI_UNSIGNED_CHAR, buffProcs[i/2],
-                              MB_MESG_REMOTEH_SIZE, procConfig.proc_comm(), 
-                              &recv_remoteh_reqs[i]);
-          if (success != MPI_SUCCESS) {
-            result = MB_FAILURE;
-            RRA("Failed to post irecv for remote handles in ghost exchange.");
-          }
-        }
-        recv_ent_reqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
-        sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
-      }
-    }
-  }
-  
-    // add requests for any new addl procs
-  if (recv_ent_reqs.size() != 2*buffProcs.size()) {
-      // shouldn't get here...
-    result = MB_FAILURE;
-    RRA("Requests length doesn't match proc count in ghost exchange.");
-  }
-    
-#ifdef DEBUG_MPE
-  MPE_Log_event(ENTITIES_END, procConfig.proc_rank(), "Ending entity exchange.");
-#endif
-
-  if (is_iface) {
-      // need to check over entities I sent and make sure I received 
-      // handles for them from all expected procs; if not, need to clean
-      // them up
-    result = check_clean_iface(allsent);
-    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
-    
-      // now set the shared/interface tag on non-vertex entities on interface
-    result = tag_iface_entities();
-    RRA("Failed to tag iface entities.");
-
-#ifndef NDEBUG
-    result = check_sent_ents(allsent);
-    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
-    result = check_all_shared_handles();
-    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
-#endif
-
-#ifdef DEBUG_MPE
-    MPE_Log_event(IFACE_END, procConfig.proc_rank(), "Ending interface exchange.");
-#endif
-#ifdef DEBUG_COMM
-    std::cerr << "Exiting exchange_ghost_cells" << std::endl; std::cerr.flush();
-#endif
-
-      //===========================================
-      // wait if requested
-      //===========================================
-    if (wait_all) {
-#ifdef DEBUG_BARRIER
-      success = MPI_Barrier(procConfig.proc_comm());
-#else
-      success = MPI_Waitall(2*buffProcs.size(), &recv_ent_reqs[0], &status);
-      success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], &status);
-#endif
-      if (MPI_SUCCESS != success) {
-        result = MB_FAILURE;
-        RRA("Failed in waitall in ghost exchange.");
-      }
-    }
-    return MB_SUCCESS;
-  }
-
-    //===========================================
-    // send local handles for new ghosts to owner, then add
-    // those to ghost list for that owner
-    //===========================================
-  for (p = 0, proc_it = buffProcs.begin(); 
-       proc_it != buffProcs.end(); proc_it++, p++) {
-
-      // reserve space on front for size and for initial buff size
-    remoteOwnedBuffs[p]->reset_buffer(sizeof(int));
-
-    result = pack_remote_handles(L1hloc[p], L1hrem[p], L1p[p], *proc_it,
-                                 remoteOwnedBuffs[p]);
-    RRA("Failed to pack remote handles.");
-    remoteOwnedBuffs[p]->set_stored_size();
-    
-#ifdef DEBUG_MSGS
-    msgs.resize(msgs.size()+1);
-    msgs.back() = new Buffer(*remoteOwnedBuffs[p]);
-      //print_buffer(&ownerSBuffs[ind][0], MB_MESG_REMOTEH_SIZE, buffProcs[ind], true);
-#endif  
-    result = send_buffer(buffProcs[p], remoteOwnedBuffs[p], 
-                         MB_MESG_REMOTEH_SIZE, 
-                         sendReqs[2*p], recv_remoteh_reqs[2*p+1], 
-                         &dum_ack_buff, incoming2);
-    RRA("Failed to send remote handles.");
-  }
-  
-    //===========================================
-    // process remote handles of my ghosteds
-    //===========================================
-  while (incoming2) {
-    PRINT_DEBUG_WAITANY(recv_remoteh_reqs, MB_MESG_REMOTEH_SIZE, procConfig.proc_rank());
-    success = MPI_Waitany(2*buffProcs.size(), &recv_remoteh_reqs[0], &ind, &status);
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitany in ghost exchange.");
-    }
-    
-      // ok, received something; decrement incoming counter
-    incoming2--;
-
-    PRINT_DEBUG_RECD(status);
-    
-    bool done = false;
-    unsigned int base_ind = 2*(ind/2);
-    result = recv_buffer(MB_MESG_REMOTEH_SIZE, status, 
-                         localOwnedBuffs[ind/2], 
-                         recv_remoteh_reqs[ind], recv_remoteh_reqs[ind+1], incoming2,
-                         remoteOwnedBuffs[ind/2], 
-                         sendReqs[base_ind], sendReqs[base_ind+1],
-                         done);
-    RRA("Failed to receive remote handles.");
-    if (done) {
-        // incoming remote handles
-#ifdef DEBUG_MSGS
-    msgs.resize(msgs.size()+1);
-    msgs.back() = new Buffer(*localOwnedBuffs[ind]);
-      //print_buffer(&remotehRBuffs[ind/2][0], MB_MESG_REMOTEH_SIZE, buffProcs[ind/2], false);
-#endif  
-    localOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
-    result = unpack_remote_handles(buffProcs[ind/2], 
-                                   localOwnedBuffs[ind/2]->buff_ptr,
-                                   L2hloc, L2hrem, L2p);
-      RRA("Failed to unpack remote handles.");
-    }
-  }
-    
-#ifdef DEBUG_MPE
-  MPE_Log_event(RHANDLES_END, procConfig.proc_rank(), "Ending remote handles.");
-#endif
-#ifdef DEBUG_MPE
-  MPE_Log_event(GHOST_END, procConfig.proc_rank(), 
-                "Ending ghost exchange (still doing checks).");
-#endif
-
-    //===========================================
-    // wait if requested
-    //===========================================
-  if (wait_all) {
-#ifdef DEBUG_BARRIER
-    success = MPI_Barrier(procConfig.proc_comm());
-#else
-    success = MPI_Waitall(2*buffProcs.size(), &recv_remoteh_reqs[0], &status);
-    success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], &status);
-#endif
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitall in ghost exchange.");
-    }
-  }
-
-#ifndef NDEBUG
-  result = check_sent_ents(allsent);
-  RRA("Failed check on shared entities.");
-  result = check_all_shared_handles();
-  RRA("Failed check on all shared handles.");
-#endif
-#ifdef DEBUG_COMM
-  std::cerr << "Exiting exchange_ghost_cells" << std::endl; std::cerr.flush();
-#endif
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::send_buffer(const unsigned int to_proc,
-                                        Buffer *send_buff,
-                                        int mesg_tag,
-                                        MPI_Request &send_req,
-                                        MPI_Request &ack_req,
-                                        int *ack_buff,
-                                        int &this_incoming,
-                                        int next_mesg_tag,
-                                        Buffer *next_recv_buff,
-                                        MPI_Request *next_recv_req,
-                                        int *next_incoming) 
-{
-  MBErrorCode result = MB_SUCCESS;
-  int success;
-
-    // if small message, post recv for remote handle message
-  if (send_buff->get_stored_size() <= (int)INITIAL_BUFF_SIZE && next_recv_buff) {
-    (*next_incoming)++;
-    PRINT_DEBUG_IRECV(procConfig.proc_rank(), to_proc, next_recv_buff->mem_ptr,
-                      INITIAL_BUFF_SIZE, next_mesg_tag, *next_incoming);
-    success = MPI_Irecv(next_recv_buff->mem_ptr, INITIAL_BUFF_SIZE, 
-                        MPI_UNSIGNED_CHAR, to_proc,
-                        next_mesg_tag, procConfig.proc_comm(), 
-                        next_recv_req);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv for next message in ghost exchange.");
-    }
-  }
-    // if large, we'll need an ack before sending the rest
-  else if (send_buff->get_stored_size() > (int)INITIAL_BUFF_SIZE) {
-    this_incoming++;
-    PRINT_DEBUG_IRECV(procConfig.proc_rank(), to_proc, (unsigned char*)ack_buff,
-                      sizeof(int), mesg_tag-1, this_incoming);
-    success = MPI_Irecv(ack_buff, sizeof(int), 
-                        MPI_UNSIGNED_CHAR, to_proc,
-                        mesg_tag-1, procConfig.proc_comm(), 
-                        &ack_req);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv for entity ack in ghost exchange.");
-    }
-  }
-
-    // send the buffer
-  PRINT_DEBUG_ISEND(procConfig.proc_rank(), to_proc, send_buff->mem_ptr, mesg_tag,
-                    std::min(send_buff->get_stored_size(), (int)INITIAL_BUFF_SIZE));
-  assert(0 <= send_buff->get_stored_size() && 
-         send_buff->get_stored_size() <= (int)send_buff->alloc_size);
-  success = MPI_Isend(send_buff->mem_ptr, 
-                      std::min(send_buff->get_stored_size(), 
-                               (int)INITIAL_BUFF_SIZE),
-                      MPI_UNSIGNED_CHAR, to_proc, 
-                      mesg_tag, procConfig.proc_comm(), &send_req);
-  if (success != MPI_SUCCESS) return MB_FAILURE;
-
-  return result;
-}
-
-MBErrorCode MBParallelComm::recv_buffer(int mesg_tag_expected,
-                                        const MPI_Status &mpi_status,
-                                        Buffer *recv_buff,
-                                        MPI_Request &recv_req,
-                                        MPI_Request &ack_recvd_req,
-                                        int &this_incoming,
-                                        Buffer *send_buff,
-                                        MPI_Request &send_req,
-                                        MPI_Request &sent_ack_req,
-                                        bool &done,
-                                        Buffer *next_buff,
-                                        int next_tag,
-                                        MPI_Request *next_req,
-                                        int *next_incoming) 
-{
-    // process a received message; if there will be more coming, 
-    // post a receive for 2nd part then send an ack message
-    //
-  int from_proc = mpi_status.MPI_SOURCE;
-  int success;
-  MBErrorCode result = MB_SUCCESS;
-
-    // set the buff_ptr on the recv_buffer; needs to point beyond any
-    // valid data already in the buffer
-  recv_buff->reset_ptr(std::min(recv_buff->get_stored_size(), 
-                                (int)recv_buff->alloc_size));
-  
-  if (mpi_status.MPI_TAG == mesg_tag_expected &&
-      recv_buff->get_stored_size() > (int)INITIAL_BUFF_SIZE) {
-      // 1st message & large - allocate buffer, post irecv for 2nd message,
-      // then send ack
-    recv_buff->reserve(recv_buff->get_stored_size());
-    assert(recv_buff->alloc_size > INITIAL_BUFF_SIZE);
-
-      // will expect a 2nd message
-    this_incoming++;
-
-    PRINT_DEBUG_IRECV(procConfig.proc_rank(), from_proc, 
-                      recv_buff->mem_ptr+INITIAL_BUFF_SIZE,
-                      recv_buff->get_stored_size() - INITIAL_BUFF_SIZE,
-                      mesg_tag_expected+1, this_incoming);
-    success = MPI_Irecv(recv_buff->mem_ptr+INITIAL_BUFF_SIZE, 
-                        recv_buff->get_stored_size() - INITIAL_BUFF_SIZE, 
-                        MPI_UNSIGNED_CHAR, from_proc,
-                        mesg_tag_expected+1, procConfig.proc_comm(), 
-                        &recv_req);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post 2nd iRecv in ghost exchange.");
-    }
-
-      // send ack, doesn't matter what data actually is
-    PRINT_DEBUG_ISEND(procConfig.proc_rank(), from_proc, recv_buff->mem_ptr, 
-                      mesg_tag_expected-1, sizeof(int));
-    success = MPI_Isend(recv_buff->mem_ptr, sizeof(int),
-                        MPI_UNSIGNED_CHAR, from_proc, 
-                        mesg_tag_expected-1, procConfig.proc_comm(), &sent_ack_req);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to send ack in ghost exchange.");
-    }
-  }
-
-  else if (mpi_status.MPI_TAG == mesg_tag_expected-1) {
-      // got an ack back, send the 2nd half of message
-
-      // should be a large message if we got this
-    assert(*((size_t*)send_buff->mem_ptr) > INITIAL_BUFF_SIZE);
-
-      // post irecv for next message, then send 2nd message
-    if (next_buff) {
-        // we'll expect a return message
-      (*next_incoming)++;
-      PRINT_DEBUG_IRECV(procConfig.proc_rank(), from_proc, next_buff->mem_ptr,
-                        INITIAL_BUFF_SIZE, next_tag, *next_incoming);
-
-      success = MPI_Irecv(next_buff->mem_ptr, 
-                          INITIAL_BUFF_SIZE, 
-                          MPI_UNSIGNED_CHAR, from_proc,
-                          next_tag, procConfig.proc_comm(), 
-                          next_req);
-      if (success != MPI_SUCCESS) {
-        result = MB_FAILURE;
-        RRA("Failed to post next irecv in ghost exchange.");
-      }
-
-    }
-    
-      // send 2nd message
-    PRINT_DEBUG_ISEND(procConfig.proc_rank(), from_proc, 
-                      send_buff->mem_ptr+INITIAL_BUFF_SIZE,
-                      mesg_tag_expected+1,
-                      send_buff->get_stored_size() - INITIAL_BUFF_SIZE);
-    
-    assert(send_buff->get_stored_size()-INITIAL_BUFF_SIZE < send_buff->alloc_size &&
-           0 <= send_buff->get_stored_size());
-    success = MPI_Isend(send_buff->mem_ptr+INITIAL_BUFF_SIZE, 
-                        send_buff->get_stored_size() - INITIAL_BUFF_SIZE,
-                        MPI_UNSIGNED_CHAR, from_proc, mesg_tag_expected+1, 
-                        procConfig.proc_comm(), &send_req);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to send 2nd message in ghost exchange.");
-    }
-  }
-  else if ((mpi_status.MPI_TAG == mesg_tag_expected && 
-            recv_buff->get_stored_size() <= (int)INITIAL_BUFF_SIZE) ||
-           mpi_status.MPI_TAG == mesg_tag_expected+1) {
-      // message completely received - signal that we're done
-    done = true;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::check_clean_iface(MBRange &allsent) 
-{
-    // allsent is all entities I think are on interface; go over them, looking
-    // for zero-valued handles, and fix any I find
-
-  MBErrorCode result;
-  MBRange::iterator rit;
-  unsigned char pstatus;
-  int sharedp[MAX_SHARING_PROCS], nump;
-  MBEntityHandle sharedh[MAX_SHARING_PROCS];
-  for (rit = allsent.begin(); rit != allsent.end(); rit++) {
-    result = get_sharing_data(*rit, sharedp, sharedh, pstatus, nump);
-    RRA("");
-    assert("Should be shared with at least one other proc" && 
-           (nump > 1 || sharedp[0] != (int)procConfig.proc_rank()));
-    int numz = 0;
-    for (int i = 0; i < nump; i++) {
-      if (!sharedh[i]) numz++;
-      else if (numz) {
-          // shift downward
-        sharedh[i-numz] = sharedh[i];
-        sharedp[i-numz] = sharedp[i];
-      }
-    }
-    if (numz) {
-      for (int i = numz; i > 0; i--) {
-        sharedp[nump-i] = -1;
-        sharedh[nump-i] = 0;
-      }
-      result = set_sharing_data(*rit, pstatus, nump, nump-numz, sharedp, sharedh);
-      RRA("");
-    }
-  }
-  
-  return result;
-}
-
-MBErrorCode MBParallelComm::set_sharing_data(MBEntityHandle ent, unsigned char pstatus,
-                                             int old_nump, int new_nump,
-                                             int *ps, MBEntityHandle *hs) 
-{
-  assert("Should call this function only when reducing sharing procs." &&
-         new_nump < old_nump);
-
-    // set sharing data to what's passed in; may have to clean up existing sharing tags
-    // if things changed too much
-  
-  MBErrorCode result;
-  if (pstatus & PSTATUS_MULTISHARED && new_nump < 3) {
-      // need to remove multishared tags
-    result = mbImpl->tag_delete_data(sharedps_tag(), &ent, 1);
-    RRA("");
-    result = mbImpl->tag_delete_data(sharedhs_tag(), &ent, 1);
-    RRA("");
-    pstatus ^= PSTATUS_MULTISHARED;
-    if (new_nump < 2) pstatus = 0x0;
-  }
-  else if (pstatus & PSTATUS_SHARED && new_nump < 2) {
-    hs[0] = 0;
-    ps[0] = -1;
-    pstatus = 0x0;
-  }
-
-  if (new_nump > 2) {
-    result = mbImpl->tag_set_data(sharedps_tag(), &ent, 1, ps);
-    RRA("");
-    result = mbImpl->tag_set_data(sharedhs_tag(), &ent, 1, hs);
-    RRA("");
-#ifndef NDEBUG
-    {
-        // check for duplicates in proc list
-      std::set<unsigned int> dumprocs;
-      int dp = 0;
-      for (; dp < old_nump && -1 != ps[dp]; dp++)
-        dumprocs.insert(ps[dp]);
-      assert(dp == (int)dumprocs.size());
-    }
-#endif      
-  }
-  else {
-    unsigned int j = (ps[0] == (int)procConfig.proc_rank() ? 1 : 0);
-    assert(-1 != ps[j]);
-    result = mbImpl->tag_set_data(sharedp_tag(), &ent, 1, ps+j);
-    RRA("");
-    result = mbImpl->tag_set_data(sharedh_tag(), &ent, 1, hs+j);
-    RRA("");
-  }
-  
-  result = mbImpl->tag_set_data(pstatus_tag(), &ent, 1, &pstatus);
-  RRA("");
-
-  if (old_nump > 1 && new_nump < 2) sharedEnts.erase(ent);
-
-  return result;
-}
-
-MBErrorCode MBParallelComm::get_sent_ents(const bool is_iface, 
-                                          const int bridge_dim, const int ghost_dim,
-                                          const int num_layers,
-                                          MBRange *sent_ents, MBRange &allsent,
-                                          std::vector<std::set<unsigned int> > &entprocs) 
-{
-  MBErrorCode result;
-  int ind;
-  std::vector<unsigned int>::iterator proc_it;
-  MBRange tmp_range;
-  
-    // done in a separate loop over procs because sometimes later procs 
-    // need to add info to earlier procs' messages
-  for (ind = 0, proc_it = buffProcs.begin(); 
-       proc_it != buffProcs.end(); proc_it++, ind++) {
-    if (!is_iface) {
-      result = get_ghosted_entities(bridge_dim, ghost_dim, buffProcs[ind],
-                                    num_layers, sent_ents[ind]);
-      RRA("Failed to get ghost layers.");
-    }
-    else {
-      result = get_iface_entities(buffProcs[ind], -1, sent_ents[ind]);
-      RRA("Failed to get interface layers.");
-    }
-
-      // filter out entities already shared with destination
-    tmp_range.clear();
-    result = filter_pstatus(sent_ents[ind], PSTATUS_SHARED, PSTATUS_AND,
-                            buffProcs[ind], &tmp_range);
-    RRA("Couldn't filter on owner.");
-    if (!tmp_range.empty()) 
-      sent_ents[ind] = subtract( sent_ents[ind], tmp_range);
-
-    allsent.merge(sent_ents[ind]);
-  }
-
-    //===========================================
-    // need to get procs each entity is sent to
-    //===========================================
-  MBRange::iterator rit;
-  entprocs.resize(allsent.size());
-  for (ind = 0, proc_it = buffProcs.begin(); 
-       proc_it != buffProcs.end(); proc_it++, ind++) {
-    for (rit = sent_ents[ind].begin(); rit != sent_ents[ind].end(); rit++) {
-      int rind = allsent.index(*rit);
-      assert(rind < (int) allsent.size() && rind >= 0);
-      entprocs[rind].insert(*proc_it);
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::exchange_ghost_cells(MBParallelComm **pcs,
-                                                 unsigned int num_procs,
-                                                 int ghost_dim, int bridge_dim,
-                                                 int num_layers,
-                                                 bool store_remote_handles)
-{
-    // static version of function, exchanging info through buffers rather 
-    // than through messages
-
-    // if we're only finding out about existing ents, we have to be storing
-    // remote handles too
-  assert(num_layers > 0 || store_remote_handles);
-  
-  const bool is_iface = !num_layers;
-  
-  unsigned int ind;
-  MBParallelComm *pc;
-  MBErrorCode result = MB_SUCCESS;
-
-    // when this function is called, buffProcs should already have any 
-    // communicating procs
-
-    //===========================================
-    // get entities to be sent to neighbors
-    //===========================================
-
-    // done in a separate loop over procs because sometimes later procs 
-    // need to add info to earlier procs' messages
-  MBRange sent_ents[MAX_SHARING_PROCS][MAX_SHARING_PROCS], 
-      allsent[MAX_SHARING_PROCS];
-
-    //===========================================
-    // get entities to be sent to neighbors
-    //===========================================
-
-  std::vector<std::set<unsigned int> > entprocs[MAX_SHARING_PROCS];
-  for (unsigned int p = 0; p < num_procs; p++) {
-    pc = pcs[p];
-    result = pc->get_sent_ents(is_iface, bridge_dim, ghost_dim, num_layers,
-                               sent_ents[p], allsent[p], entprocs[p]);
-    RRAI(pc->get_moab(), "get_sent_ents failed.");
-  
-    //===========================================
-    // pack entities into buffers
-    //===========================================
-
-    for (ind = 0; ind < pc->buffProcs.size(); ind++) {
-        // entities
-      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
-      result = pc->pack_entities(sent_ents[p][ind], pc->localOwnedBuffs[ind],
-                                 store_remote_handles, pc->buffProcs[ind], is_iface,
-                                 &entprocs[p], &allsent[p]); 
-      RRAI(pc->get_moab(), "Packing entities failed.");
-    }
-  }
-
-    //===========================================
-    // receive/unpack new entities
-    //===========================================
-    // number of incoming messages for ghosts is the number of procs we 
-    // communicate with; for iface, it's the number of those with lower rank
-  std::vector<std::vector<MBEntityHandle> > L1hloc[MAX_SHARING_PROCS], L1hrem[MAX_SHARING_PROCS];
-  std::vector<std::vector<int> > L1p[MAX_SHARING_PROCS];
-  std::vector<MBEntityHandle> L2hloc[MAX_SHARING_PROCS], L2hrem[MAX_SHARING_PROCS];
-  std::vector<unsigned int> L2p[MAX_SHARING_PROCS];
-  MBRange new_ents[MAX_SHARING_PROCS];
-  
-  for (unsigned int p = 0; p < num_procs; p++) {
-    L1hloc[p].resize(pcs[p]->buffProcs.size());
-    L1hrem[p].resize(pcs[p]->buffProcs.size());
-    L1p[p].resize(pcs[p]->buffProcs.size());
-  }
-  
-  for (unsigned int p = 0; p < num_procs; p++) {
-  
-    MBParallelComm *pc = pcs[p];
-    
-    for (ind = 0; ind < pc->buffProcs.size(); ind++) {
-        // incoming ghost entities; unpack; returns entities received
-        // both from sending proc and from owning proc (which may be different)
-
-        // buffer could be empty, which means there isn't any message to
-        // unpack (due to this comm proc getting added as a result of indirect
-        // communication); just skip this unpack
-      if (pc->localOwnedBuffs[ind]->get_stored_size() == 0) continue;
-
-      unsigned int to_p = pc->buffProcs[ind];
-      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
-      result = pcs[to_p]->unpack_entities(pc->localOwnedBuffs[ind]->buff_ptr,
-                                          store_remote_handles, ind, is_iface,
-                                          L1hloc[to_p], L1hrem[to_p], L1p[to_p], L2hloc[to_p], 
-                                          L2hrem[to_p], L2p[to_p], new_ents[to_p]);
-      RRAI(pc->get_moab(), "Failed to unpack entities.");
-    }
-  }
-
-  if (is_iface) {
-      // need to check over entities I sent and make sure I received 
-      // handles for them from all expected procs; if not, need to clean
-      // them up
-    for (unsigned int p = 0; p < num_procs; p++) {
-      result = pcs[p]->check_clean_iface(allsent[p]);
-      RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
-    }
-
-#ifndef NDEBUG
-    for (unsigned int p = 0; p < num_procs; p++) {
-      result = pcs[p]->check_sent_ents(allsent[p]);
-      RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
-    }
-    result = check_all_shared_handles(pcs, num_procs);
-    RRAI(pcs[0]->get_moab(), "Failed check on all shared handles.");
-#endif
-    return MB_SUCCESS;
-  }
-  
-      //===========================================
-      // send local handles for new ghosts to owner, then add
-      // those to ghost list for that owner
-      //===========================================
-  std::vector<unsigned int>::iterator proc_it;
-  for (unsigned int p = 0; p < num_procs; p++) {
-    pc = pcs[p];
-  
-    for (ind = 0, proc_it = pc->buffProcs.begin(); 
-         proc_it != pc->buffProcs.end(); proc_it++, ind++) {
-        // skip if iface layer and higher-rank proc
-      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
-      result = pc->pack_remote_handles(L1hloc[p][ind], L1hrem[p][ind], L1p[p][ind], *proc_it,
-                                       pc->localOwnedBuffs[ind]);
-      RRAI(pc->get_moab(), "Failed to pack remote handles.");
-    }
-  }
-  
-    //===========================================
-    // process remote handles of my ghosteds
-    //===========================================
-  for (unsigned int p = 0; p < num_procs; p++) {
-    pc = pcs[p];
-  
-    for (ind = 0, proc_it = pc->buffProcs.begin(); 
-         proc_it != pc->buffProcs.end(); proc_it++, ind++) {
-        // incoming remote handles
-      unsigned int to_p = pc->buffProcs[ind];
-      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
-      result = pcs[to_p]->unpack_remote_handles(p, 
-                                                pc->localOwnedBuffs[ind]->buff_ptr,
-                                                L2hloc[to_p], L2hrem[to_p], L2p[to_p]);
-      RRAI(pc->get_moab(), "Failed to unpack remote handles.");
-    }
-  }
-    
-#ifndef NDEBUG
-  for (unsigned int p = 0; p < num_procs; p++) {
-    result = pcs[p]->check_sent_ents(allsent[p]);
-    RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
-  }
-  
-  result = MBParallelComm::check_all_shared_handles(pcs, num_procs);
-  RRAI(pcs[0]->get_moab(), "Failed check on all shared handles.");
-#endif
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_iface_entities(int other_proc,
-                                               int dim,
-                                               MBRange &iface_ents) 
-{
-  MBRange iface_sets;
-  MBErrorCode result = MB_SUCCESS;
-  
-  for (MBRange::iterator rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
-    if (-1 != other_proc && !is_iface_proc(*rit, other_proc)) continue;
-    
-    if (-1 == dim) result = mbImpl->get_entities_by_handle(*rit, iface_ents);
-    else result = mbImpl->get_entities_by_dimension(*rit, dim, iface_ents);
-    RRA(" Failed to get entities in iface set.");
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::check_sent_ents(MBRange &allsent) 
-{
-    // check entities to make sure there are no zero-valued remote handles
-    // where they shouldn't be
-  std::vector<unsigned char> pstat(allsent.size());
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), allsent, &pstat[0]);
-  RRA("Trouble getting pstatus.");
-  std::vector<MBEntityHandle> handles(allsent.size());
-  result = mbImpl->tag_get_data(sharedh_tag(), allsent, &handles[0]);
-  RRA("Trouble getting shared handles.");
-  std::vector<int> procs(allsent.size());
-  result = mbImpl->tag_get_data(sharedp_tag(), allsent, &procs[0]);
-  RRA("Trouble getting shared procs.");
-
-  MBRange bad_entities;
-  
-  MBRange::iterator rit;
-  unsigned int i;
-  MBEntityHandle dum_hs[MAX_SHARING_PROCS];
-  int dum_ps[MAX_SHARING_PROCS];
-  
-  for (rit = allsent.begin(), i = 0; rit != allsent.end(); rit++, i++) {
-    if (-1 != procs[i] && 0 == handles[i]) bad_entities.insert(*rit);
-    else {
-        // might be multi-shared...
-      result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1, dum_ps);
-      if (MB_TAG_NOT_FOUND == result) continue;
-      RRA("Trouble getting sharedps.");
-      result = mbImpl->tag_get_data(sharedhs_tag(), &(*rit), 1, dum_hs);
-      RRA("Trouble getting sharedhs.");
-
-        // find first non-set proc
-      int *ns_proc = std::find(dum_ps, dum_ps+MAX_SHARING_PROCS, -1);
-      int num_procs = ns_proc-dum_ps;
-      assert(num_procs <= MAX_SHARING_PROCS);
-        // now look for zero handles in active part of dum_hs
-      MBEntityHandle *ns_handle = std::find(dum_hs, dum_hs+num_procs, 0);
-      int num_handles = ns_handle-dum_hs;
-      assert(num_handles <= num_procs);
-      if (num_handles != num_procs) bad_entities.insert(*rit);
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::pack_remote_handles(std::vector<MBEntityHandle> &L1hloc,
-                                                std::vector<MBEntityHandle> &L1hrem,
-                                                std::vector<int> &L1p,
-                                                unsigned int to_proc,
-                                                Buffer *buff) 
-{
-    // 2 vectors of handles plus ints
-  buff->check_space(((L1p.size()+1)*sizeof(int) + 
-                     (L1hloc.size()+1)*sizeof(MBEntityHandle) + 
-                     (L1hrem.size()+1)*sizeof(MBEntityHandle)));
-  
-    // should be in pairs of handles
-  PACK_INT(buff->buff_ptr, L1hloc.size());
-  PACK_INTS(buff->buff_ptr, &L1p[0], L1p.size());
-  PACK_EH(buff->buff_ptr, &L1hrem[0], L1hrem.size());
-  PACK_EH(buff->buff_ptr, &L1hloc[0], L1hloc.size());
-  
-  buff->set_stored_size();
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::unpack_remote_handles(unsigned int from_proc,
-                                                  unsigned char *&buff_ptr,
-                                                  std::vector<MBEntityHandle> &L2hloc,
-                                                  std::vector<MBEntityHandle> &L2hrem,
-                                                  std::vector<unsigned int> &L2p)
-{
-    // incoming remote handles; use to set remote handles
-  int num_eh;
-  UNPACK_INT(buff_ptr, num_eh);
-
-  unsigned char *buff_proc = buff_ptr;
-  buff_ptr += num_eh * sizeof(int);
-  unsigned char *buff_rem = buff_ptr + num_eh * sizeof(MBEntityHandle);
-  MBErrorCode result;
-  MBEntityHandle hpair[2], dum_h;
-  int proc;
-  for (int i = 0; i < num_eh; i++) {
-    UNPACK_INT(buff_proc, proc);
-    UNPACK_EH(buff_ptr, hpair, 1);
-    UNPACK_EH(buff_rem, hpair+1, 1);
-
-    if (-1 != proc) {
-      result = find_existing_entity(false, proc, hpair[0], 3, NULL, 0,
-                                    mbImpl->type_from_handle(hpair[1]),
-                                    L2hloc, L2hrem, L2p, dum_h);
-      RRA("Didn't get existing entity.");
-      if (dum_h) hpair[0] = dum_h;
-      else hpair[0] = 0;
-    }
-    if (!(hpair[0] && hpair[1])) return MB_FAILURE;
-    int this_proc = from_proc;
-    result = update_remote_data(hpair[0], &this_proc, hpair+1, 1, 0);
-    RRA("Trouble setting remote data range on sent entities in ghost exchange.");
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_ghosted_entities(int bridge_dim,
-                                                 int ghost_dim,
-                                                 int to_proc, 
-                                                 int num_layers,
-                                                 MBRange &ghosted_ents) 
-{
-    // get bridge ents on interface(s)
-  MBRange from_ents;
-  MBErrorCode result = MB_SUCCESS;
-  assert(0 < num_layers);
-  for (MBRange::iterator rit = interfaceSets.begin(); rit != interfaceSets.end();
-       rit++) {
-    if (!is_iface_proc(*rit, to_proc)) continue;
-      
-      // get starting "from" entities
-    if (bridge_dim == -1)
-      result = mbImpl->get_entities_by_handle(*rit, from_ents);
-    else
-      result = mbImpl->get_entities_by_dimension(*rit, bridge_dim, from_ents);
-    RRA("Couldn't get bridge ents in the set.");
-
-      // need to get layers of bridge-adj entities
-    if (from_ents.empty()) continue;
-    result = MeshTopoUtil(mbImpl).get_bridge_adjacencies(from_ents, bridge_dim,
-                                                         ghost_dim, ghosted_ents, 
-                                                         num_layers);
-    RRA("Couldn't get bridge adjacencies.");
-  }
-  
-  result = add_verts(ghosted_ents);
-  RRA("Couldn't add verts.");
-
-  return result;
-}
-
-MBErrorCode MBParallelComm::add_verts(MBRange &sent_ents) 
-{
-      // get the verts adj to these entities, since we'll have to send those too
-
-    // first check sets
-  std::pair<MBRange::const_iterator, MBRange::const_iterator>
-      set_range = sent_ents.equal_range(MBENTITYSET);
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  for (MBRange::const_iterator rit = set_range.first; rit != set_range.second; rit++) {
-    tmp_result = mbImpl->get_entities_by_type(*rit, MBVERTEX, sent_ents);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  RRA("Failed to get contained verts.");
-  
-    // now non-sets
-  MBRange tmp_ents;
-  std::copy(sent_ents.begin(), set_range.first, mb_range_inserter(tmp_ents));
-  result = mbImpl->get_adjacencies(tmp_ents, 0, false, sent_ents,
-                                   MBInterface::UNION);
-  RRA("Couldn't get vertices adj to ghosted ents.");
-
-  return result;
-}
-
-
-MBErrorCode MBParallelComm::exchange_tags(std::vector<MBTag> &src_tags,
-                                          std::vector<MBTag> &dst_tags,
-                                          MBRange &entities)
-{
-  MBErrorCode result;
-  int success;
-
-#ifdef DEBUG_COMM
-  std::cerr << "Entering exchange_tags" << std::endl; std::cerr.flush();
-#endif
-
-    // get all procs interfacing to this proc
-  std::set<unsigned int> exch_procs;
-  result = get_comm_procs(exch_procs);  
-
-    // post ghost irecv's for all interface procs
-    // index greqs the same as buffer/sharing procs indices
-  std::vector<MPI_Request> recv_tag_reqs(2*buffProcs.size(), MPI_REQUEST_NULL),
-      sent_ack_reqs(buffProcs.size(), MPI_REQUEST_NULL);
-  std::vector<unsigned int>::iterator sit;
-  int ind;
-
-  reset_all_buffers();
-  int incoming = 0;
-
-  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
-    incoming++;
-    PRINT_DEBUG_IRECV(*sit, procConfig.proc_rank(), remoteOwnedBuffs[ind]->mem_ptr,
-                      INITIAL_BUFF_SIZE, MB_MESG_TAGS_SIZE, incoming);
-
-    success = MPI_Irecv(remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE,
-                        MPI_UNSIGNED_CHAR, *sit,
-                        MB_MESG_TAGS_SIZE, procConfig.proc_comm(), 
-                        &recv_tag_reqs[2*ind]);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv in ghost exchange.");
-    }
-
-  }
-  
-    // pack and send tags from this proc to others
-    // make sendReqs vector to simplify initialization
-  sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
-  
-    // take all shared entities if incoming list is empty
-  if (entities.empty()) entities = sharedEnts;
-  
-  int dum_ack_buff;
-
-  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
-    
-    MBRange tag_ents = entities;
-    
-      // get ents shared by proc *sit
-    result = filter_pstatus(tag_ents, PSTATUS_SHARED, PSTATUS_AND, *sit);
-    RRA("Failed pstatus AND check.");
-    
-      // remote nonowned entities
-    if (!tag_ents.empty()) {
-      result = filter_pstatus(tag_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT);
-      RRA("Failed pstatus NOT check.");
-    }
-    
-      // pack-send; this also posts receives if store_remote_handles is true
-    std::vector<MBRange> tag_ranges;
-    for (std::vector<MBTag>::iterator vit = src_tags.begin(); vit != src_tags.end(); vit++) {
-      const void* ptr;
-      int size;
-      if (tagServer->get_default_data_ref( *vit, ptr, size ) != MB_SUCCESS) {
-        MBRange tagged_ents;
-        tagServer->get_entities( *vit, tagged_ents );
-        tag_ranges.push_back( intersect( tag_ents, tagged_ents ) );
-      } 
-      else {
-        tag_ranges.push_back(tag_ents);
-      }
-    }
-    
-      // pack the data
-      // reserve space on front for size and for initial buff size
-    localOwnedBuffs[ind]->reset_ptr(sizeof(int));
-    
-    result = pack_tags(tag_ents,
-                       src_tags, dst_tags, tag_ranges, 
-                       localOwnedBuffs[ind], true, *sit);
-    RRA("Failed to count buffer in pack_send_tag.");
-
-      // now send it
-    result = send_buffer(*sit, localOwnedBuffs[ind], MB_MESG_TAGS_SIZE, sendReqs[2*ind],
-                         recv_tag_reqs[2*ind+1], &dum_ack_buff, incoming);
-    RRA("Failed to send buffer.");
-                         
-  }
-  
-    // receive/unpack tags
-  while (incoming) {
-    int ind;
-    MPI_Status status;
-    PRINT_DEBUG_WAITANY(recv_tag_reqs, MB_MESG_TAGS_SIZE, procConfig.proc_rank());
-    success = MPI_Waitany(2*buffProcs.size(), &recv_tag_reqs[0], &ind, &status);
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitany in ghost exchange.");
-    }
-    
-    PRINT_DEBUG_RECD(status);
-
-      // ok, received something; decrement incoming counter
-    incoming--;
-    
-    bool done = false;
-    MBRange dum_range;
-    result = recv_buffer(MB_MESG_TAGS_SIZE,
-                         status,
-                         remoteOwnedBuffs[ind/2],
-                         recv_tag_reqs[ind/2 * 2], recv_tag_reqs[ind/2 * 2 + 1],
-                         incoming,
-                         localOwnedBuffs[ind/2], sendReqs[ind/2*2], sendReqs[ind/2*2+1],
-                         done);
-    RRA("Failed to resize recv buffer.");
-    if (done) {
-      remoteOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
-      result = unpack_tags(remoteOwnedBuffs[ind/2]->buff_ptr,
-                           dum_range, true, buffProcs[ind/2]);
-      RRA("Failed to recv-unpack-tag message.");
-    }
-  }
-  
-    // ok, now wait
-#ifdef DEBUG_BARRIER  
-  success = MPI_Barrier(procConfig.proc_comm());
-#else
-  MPI_Status status;
-  success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], status);
-#endif
-  if (MPI_SUCCESS != success) {
-    result = MB_FAILURE;
-    RRA("Failure in waitall in tag exchange.");
-  }
-  
-#ifdef DEBUG_COMM
-  std::cerr << "Exiting exchange_tags" << std::endl; std::cerr.flush();
-#endif
-
-  return MB_SUCCESS;
-}
-
-/*
-MBErrorCode MBParallelComm::exchange_tags( MBTag src_tag, 
-                                           MBTag dst_tag, 
-                                           const MBRange& entities )
-{
-  MBErrorCode result;
-  int success;
-
-    // get all procs interfacing to this proc
-  std::set<unsigned int> exch_procs;
-  result = get_comm_procs(exch_procs);  
-
-    // post ghost irecv's for all interface procs
-    // index greqs the same as buffer/sharing procs indices
-  std::vector<MPI_Request> recv_reqs(MAX_SHARING_PROCS, MPI_REQUEST_NULL);
-  std::vector<MPI_Status> gstatus(MAX_SHARING_PROCS);
-  std::vector<unsigned int>::iterator sit;
-  int ind;
-  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
-    success = MPI_Irecv(&ghostRBuffs[ind][0], ghostRBuffs[ind].size(), 
-                        MPI_UNSIGNED_CHAR, *sit,
-                        MB_MESG_ANY, procConfig.proc_comm(), 
-                        &recv_reqs[ind]);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv in ghost exchange.");
-    }
-  }
-  
-    // figure out which entities are shared with which processors
-  std::map<int,MBRange> proc_ents;
-  int other_procs[MAX_SHARING_PROCS], num_sharing;
-  for (MBRange::const_iterator i = entities.begin(); i != entities.end(); ++i) {
-    int owner;
-    result = get_owner( *i, owner );
-    RRA("Failed to get entity owner.");
-
-      // only send entities that this proc owns
-    if ((unsigned)owner != proc_config().proc_rank()) 
-      continue;
-    
-    result = get_sharing_parts( *i, other_procs, num_sharing );
-    RRA("Failed to get procs sharing entity.");
-    if (num_sharing == 0) // keep track of non-shared entities for later
-      proc_ents[proc_config().proc_rank()].insert( *i );
-    for (int j = 0; j < num_sharing; ++j)
-      proc_ents[other_procs[j]].insert( *i );
-  }
-  
-    // pack and send tags from this proc to others
-    // make sendReqs vector to simplify initialization
-  std::fill(sendReqs, sendReqs+MAX_SHARING_PROCS, MPI_REQUEST_NULL);
-  std::map<unsigned int,MBRange>::const_iterator mit;
-  
-  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
-    
-      // count first
-      // buffer needs to begin with the number of tags (one)
-    int buff_size = sizeof(int);
-    result = packed_tag_size( src_tag, proc_ents[*sit], buff_size );
-    RRA("Failed to count buffer in pack_send_tag.");
-
-    unsigned char *buff_ptr = &ownerSBuffs[ind][0];
-    buff->check_space(ownerSBuffs[ind], buff_ptr, buff_size);
-    PACK_INT( buff_ptr, 1 ); // number of tags
-    result = pack_tag( src_tag, dst_tag, proc_ents[*sit], proc_ents[*sit],
-                       ownerSBuffs[ind], buff_ptr, true, *sit );
-    RRA("Failed to pack buffer in pack_send_tag.");
-
-      // if the message is large, send a first message to tell how large
-    if (INITIAL_BUFF_SIZE < buff_size) {
-      int tmp_buff_size = -buff_size;
-      int success = MPI_Send(&tmp_buff_size, sizeof(int), MPI_UNSIGNED_CHAR, 
-                             *sit, MB_MESG_SIZE, procConfig.proc_comm());
-      if (success != MPI_SUCCESS) return MB_FAILURE;
-    }
-    
-      // send the buffer
-    success = MPI_Isend(&ownerSBuffs[ind][0], buff_size, MPI_UNSIGNED_CHAR, *sit, 
-                        MB_MESG_TAGS, procConfig.proc_comm(), &sendReqs[ind]);
-    if (success != MPI_SUCCESS) return MB_FAILURE;
-  }
-  
-    // receive/unpack tags
-  int num_incoming = exch_procs.size();
-  
-  while (num_incoming) {
-    int ind;
-    MPI_Status status;
-    success = MPI_Waitany(MAX_SHARING_PROCS, &recv_reqs[0], &ind, &status);
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitany in ghost exchange.");
-    }
-    
-      // ok, received something; decrement incoming counter
-    num_incoming--;
-    
-    int new_size;
-    unsigned char *buff_ptr;
-    MBRange dum_range;
-    
-      // branch on message type
-    switch (status.MPI_TAG) {
-      case MB_MESG_SIZE:
-          // incoming message just has size; resize buffer and re-call recv,
-          // then re-increment incoming count
-        assert(ind < MAX_SHARING_PROCS);
-        new_size = *((int*)&ghostRBuffs[ind][0]);
-        assert(0 > new_size);
-        result = recv_size_buff(buffProcs[ind], ghostRBuffs[ind], recv_reqs[ind],
-                                MB_MESG_TAGS);
-        RRA("Failed to resize recv buffer.");
-        num_incoming++;
-        break;
-      case MB_MESG_TAGS:
-          // incoming ghost entities; process
-          buff_ptr = &ghostRBuffs[ind][0];
-          result = unpack_tags(buff_ptr, dum_range, true,
-                               buffProcs[ind]);
-        RRA("Failed to recv-unpack-tag message.");
-        break;
-      default:
-        result = MB_FAILURE;
-        RRA("Failed to get message of correct type in exch_tags.");
-        break;
-    }
-  }
-  
-    // ok, now wait
-  MPI_Status status[MAX_SHARING_PROCS];
-  success = MPI_Waitall(MAX_SHARING_PROCS, &sendReqs[0], status);
-  if (MPI_SUCCESS != success) {
-    result = MB_FAILURE;
-    RRA("Failure in waitall in tag exchange.");
-  }
-  
-    // if src and destination tags aren't the same, need to copy 
-    // values for local entities
-  if (src_tag != dst_tag) {
-    const MBRange& myents = proc_ents[proc_config().proc_rank()];
-    std::vector<const void*> data_ptrs(myents.size());
-    std::vector<int> data_sizes(myents.size());
-    result = get_moab()->tag_get_data( src_tag, myents, &data_ptrs[0], &data_sizes[0] );
-    RRA("Failure to get pointers to local data.");
-    result = get_moab()->tag_set_data( dst_tag, myents, &data_ptrs[0], &data_sizes[0] );
-    RRA("Failure to get pointers to local data.");
-  }  
-  
-  return MB_SUCCESS;
-}
-*/
-
-MBErrorCode MBParallelComm::update_shared_mesh()
-{
-//  MBErrorCode result;
-//  int success;
-
-    // ,,,
-    /*
-
-    // get all procs interfacing to this proc
-  std::set<unsigned int> iface_procs;
-  result = get_interface_procs(iface_procs);
-  RRA("Failed to get iface sets, procs");
-
-    // post ghost irecv's for all interface procs
-    // index greqs the same as buffer/sharing procs indices
-  std::vector<MPI_Request> recv_reqs(2*MAX_SHARING_PROCS, MPI_REQUEST_NULL);
-  std::vector<MPI_Status> gstatus(MAX_SHARING_PROCS);
-  std::set<unsigned int>::iterator sit;
-  for (sit = iface_procs.begin(); sit != iface_procs.end(); sit++) {
-    int ind = get_buffers(*sit);
-    success = MPI_Irecv(&ghostRBuffs[ind][0], ghostRBuffs[ind].size(), 
-                        MPI_UNSIGNED_CHAR, *sit,
-                        MB_MESG_ANY, procConfig.proc_comm(), 
-                        &recv_reqs[ind]);
-    if (success != MPI_SUCCESS) {
-      result = MB_FAILURE;
-      RRA("Failed to post irecv in ghost exchange.");
-    }
-  }
-  
-    // pack and send vertex coordinates from this proc to others
-    // make sendReqs vector to simplify initialization
-  std::fill(sendReqs, sendReqs+2*MAX_SHARING_PROCS, MPI_REQUEST_NULL);
-  MBRange recd_ents[MAX_SHARING_PROCS];
-  
-  for (sit = iface_procs.begin(); sit != iface_procs.end(); sit++) {
-    int ind = get_buffers(*sit);
-    
-    MBRange vertices;
-    for (MBRange::iterator rit = interfaceSets.begin(); rit != interfaceSets.end();
-         rit++) {
-      if (!is_iface_proc(*rit, *sit)) 
-        continue;
-      
-      result = mbImpl->get_entities_by_type( *rit, MBVERTEX, vertices );
-      RRA("Bad interface set.");
-    }
-    std::map<unsigned int,MBRange>::iterator ghosted = ghostedEnts.find(*sit);
-    if (ghosted != ghostedEnts.end()) {
-      MBRange::iterator e = ghosted->second.upper_bound(MBVERTEX);
-      vertices.merge( ghosted->second.begin(), e );
-    }
-
-      // pack-send; this also posts receives if store_remote_handles is true
-    MBRange sent;
-    result = pack_send_entities(*sit, vertices, false, false, 
-                                false, true,
-                                ownerSBuffs[ind], ownerRBuffs[MAX_SHARING_PROCS+ind], 
-                                sendReqs[ind], recv_reqs[MAX_SHARING_PROCS+ind], 
-                                sent);
-    RRA("Failed to pack-send in mesh update exchange.");
-  }
-  
-    // receive/unpack entities
-    // number of incoming messages depends on whether we're getting back
-    // remote handles
-  int num_incoming = iface_procs.size();
-  
-  while (num_incoming) {
-    int ind;
-    MPI_Status status;
-    success = MPI_Waitany(2*MAX_SHARING_PROCS, &recv_reqs[0], &ind, &status);
-    if (MPI_SUCCESS != success) {
-      result = MB_FAILURE;
-      RRA("Failed in waitany in ghost exchange.");
-    }
-    
-      // ok, received something; decrement incoming counter
-    num_incoming--;
-    
-    std::vector<MBEntityHandle> remote_handles_v, sent_ents_tmp;
-    MBRange remote_handles_r;
-    int new_size;
-    
-      // branch on message type
-    switch (status.MPI_TAG) {
-      case MB_MESG_SIZE:
-          // incoming message just has size; resize buffer and re-call recv,
-          // then re-increment incoming count
-        assert(ind < MAX_SHARING_PROCS);
-        new_size = *((int*)&ghostRBuffs[ind][0]);
-        assert(0 > new_size);
-        result = recv_size_buff(buffProcs[ind], ghostRBuffs[ind], recv_reqs[ind],
-                                MB_MESG_ENTS);
-        RRA("Failed to resize recv buffer.");
-        num_incoming++;
-        break;
-      case MB_MESG_ENTS:
-          // incoming ghost entities; process
-        result = recv_unpack_entities(buffProcs[ind], true,
-                                      false, 
-                                      ghostRBuffs[ind], ghostSBuffs[ind], 
-                                      sendReqs[ind], recd_ents[ind]);
-        RRA("Failed to recv-unpack message.");
-        break;
-    }
-  }
-  
-    // ok, now wait if requested
-  MPI_Status status[2*MAX_SHARING_PROCS];
-  success = MPI_Waitall(2*MAX_SHARING_PROCS, &sendReqs[0], status);
-  if (MPI_SUCCESS != success) {
-    result = MB_FAILURE;
-    RRA("Failure in waitall in ghost exchange.");
-  }
-  
-  return MB_SUCCESS;
-}
-MBErrorCode MBParallelComm::update_iface_sets(MBRange &sent_ents,
-                                              std::vector<MBEntityHandle> &remote_handles, 
-                                              int from_proc) 
-{
-  std::vector<MBEntityHandle>::iterator remote_it = remote_handles.begin();
-  MBRange::iterator sent_it = sent_ents.begin();
-  MBRange ents_to_remove;
-  for (; sent_it != sent_ents.end(); sent_it++, remote_it++) {
-    if (!*remote_it) ents_to_remove.insert(*sent_it);
-  }
-  
-  for (MBRange::iterator set_it = interfaceSets.begin(); set_it != interfaceSets.end(); set_it++) {
-    if (!is_iface_proc(*set_it, from_proc)) continue;
-    MBErrorCode result = mbImpl->remove_entities(*set_it, ents_to_remove);
-    RRA("Couldn't remove entities from iface set in update_iface_sets.");
-  }
-
-*/
-  
-  return MB_SUCCESS;
-}
-
-  //! return sharedp tag
-MBTag MBParallelComm::sharedp_tag()
-{
-  if (!sharedpTag) {
-    int def_val = -1;
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_PROC_TAG_NAME, 
-                                            sizeof(int), 
-                                            MB_TAG_DENSE,
-                                            MB_TYPE_INTEGER, sharedpTag, 
-                                            &def_val, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
-      return 0;
-  }
-  
-  return sharedpTag;
-}
-
-  //! return sharedps tag
-MBTag MBParallelComm::sharedps_tag()
-{
-  if (!sharedpsTag) {
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_PROCS_TAG_NAME, 
-                                            MAX_SHARING_PROCS*sizeof(int), 
-                                            MB_TAG_SPARSE,
-                                            MB_TYPE_INTEGER, sharedpsTag, NULL, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
-      return 0;
-  }
-  
-  return sharedpsTag;
-}
-  
-  //! return sharedh tag
-MBTag MBParallelComm::sharedh_tag()
-{
-  if (!sharedhTag) {
-    MBEntityHandle def_val = 0;
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_HANDLE_TAG_NAME, 
-                                            sizeof(MBEntityHandle), 
-                                            MB_TAG_DENSE,
-                                            MB_TYPE_HANDLE, sharedhTag, 
-                                            &def_val, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
-      return 0;
-  }
-  
-  return sharedhTag;
-}
-  
-  //! return sharedhs tag
-MBTag MBParallelComm::sharedhs_tag()
-{  
-  if (!sharedhsTag) {
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_HANDLES_TAG_NAME, 
-                                            MAX_SHARING_PROCS*sizeof(MBEntityHandle), 
-                                            MB_TAG_SPARSE,
-                                            MB_TYPE_INTEGER, sharedhsTag, NULL, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
-      return 0;
-  }
-
-  return sharedhsTag;
-}
-  
-  //! return pstatus tag
-MBTag MBParallelComm::pstatus_tag()
-{  
-  if (!pstatusTag) {
-    unsigned char tmp_pstatus = 0;
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_STATUS_TAG_NAME, 
-                                            sizeof(unsigned char),
-                                            MB_TAG_DENSE,
-                                            MB_TYPE_OPAQUE, pstatusTag, 
-                                            &tmp_pstatus, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
-      return 0;
-  }
-  
-  return pstatusTag;
-}
-  
-  //! return partition set tag
-MBTag MBParallelComm::partition_tag()
-{  
-  if (!partitionTag) {
-    MBErrorCode result = mbImpl->tag_create(PARALLEL_PARTITION_TAG_NAME, 
-                                            sizeof(int),
-                                            MB_TAG_SPARSE,
-                                            MB_TYPE_INTEGER, 
-                                            partitionTag, 
-                                            NULL, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
-      return 0;
-  }
-  
-  return partitionTag;
-}
-  
-  //! return pcomm tag; passes in impl 'cuz this is a static function
-MBTag MBParallelComm::pcomm_tag(MBInterface *impl,
-                                bool create_if_missing)
-{
-  MBTag this_tag = 0;
-  MBErrorCode result;
-  result = impl->tag_get_handle(PARALLEL_COMM_TAG_NAME, this_tag);
-  if ((MB_TAG_NOT_FOUND == result || 0 == this_tag) &&
-      create_if_missing) {
-    result = impl->tag_create(PARALLEL_COMM_TAG_NAME, 
-                              MAX_SHARING_PROCS*sizeof(MBParallelComm*),
-                              MB_TAG_SPARSE,
-                              MB_TYPE_OPAQUE, this_tag,
-                              NULL, true);
-    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
-      return 0;
-  }
-  
-  return this_tag;
-}
-
-    //! get the indexed pcomm object from the interface
-MBParallelComm *MBParallelComm::get_pcomm(MBInterface *impl, const int index) 
-{
-  MBTag pc_tag = pcomm_tag(impl, false);
-  if (0 == pc_tag) return NULL;
-  
-  MBParallelComm *pc_array[MAX_SHARING_PROCS];
-  MBErrorCode result = impl->tag_get_data(pc_tag, 0, 0, (void*)pc_array);
-  if (MB_SUCCESS != result) return NULL;
-  
-  return pc_array[index];
-}
-
-MBErrorCode MBParallelComm::get_all_pcomm( MBInterface* impl, std::vector<MBParallelComm*>& list )
-{
-  MBTag pc_tag = pcomm_tag(impl, false);
-  if (0 == pc_tag)
-    return MB_TAG_NOT_FOUND;
-  
-  MBParallelComm *pc_array[MAX_SHARING_PROCS];
-  MBErrorCode rval = impl->tag_get_data( pc_tag, 0, 0, pc_array );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  for (int i = 0; i < MAX_SHARING_PROCS; ++i)
-    if (pc_array[i])
-      list.push_back( pc_array[i] );
-  
-  return MB_SUCCESS;
-}
-  
-
-    //! get the indexed pcomm object from the interface
-MBParallelComm *MBParallelComm::get_pcomm( MBInterface *impl, 
-                                           MBEntityHandle prtn,
-                                           const MPI_Comm* comm ) 
-{
-  MBErrorCode rval;
-  MBParallelComm* result = 0;
-  
-  MBTag prtn_tag;
-  rval = impl->tag_create( PARTITIONING_PCOMM_TAG_NAME, 
-                           sizeof(int),
-                           MB_TAG_SPARSE,
-                           MB_TYPE_INTEGER,
-                           prtn_tag,
-                           0, true );
-  if (MB_SUCCESS != rval)
-    return 0;
-  
-  int pcomm_id;
-  rval = impl->tag_get_data( prtn_tag, &prtn, 1, &pcomm_id );
-  if (MB_SUCCESS == rval) {
-    result= get_pcomm( impl, pcomm_id );
-  }
-  else if (MB_TAG_NOT_FOUND == rval && comm) {
-    result = new MBParallelComm( impl, *comm, &pcomm_id );
-    if (!result)
-      return 0;
-    result->set_partitioning( prtn );
-    
-    rval = impl->tag_set_data( prtn_tag, &prtn, 1, &pcomm_id );
-    if (MB_SUCCESS != rval) {
-      delete result;
-      result = 0;
-    }
-  }
-  
-  return result;
-}
-
-MBErrorCode MBParallelComm::set_partitioning( MBEntityHandle set) 
-{
-  MBErrorCode rval;
-  MBTag prtn_tag;
-  rval = mbImpl->tag_create( PARTITIONING_PCOMM_TAG_NAME, 
-                           sizeof(int),
-                           MB_TAG_SPARSE,
-                           MB_TYPE_INTEGER,
-                           prtn_tag,
-                           0, true );
-  if (MB_SUCCESS != rval)
-    return rval;
-
-    // get my id
-  MBParallelComm* pcomm_arr[MAX_SHARING_PROCS];
-  MBTag pc_tag = pcomm_tag(mbImpl, false);
-  if (0 == pc_tag) 
-    return MB_FAILURE;
-  MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, pcomm_arr);
-  if (MB_SUCCESS != result) 
-    return MB_FAILURE;  
-  int id = std::find(pcomm_arr,pcomm_arr+MAX_SHARING_PROCS,this) - pcomm_arr;
-  if (id == MAX_SHARING_PROCS)
-    return MB_FAILURE;
-
-  MBEntityHandle old = partitioningSet;
-  if (old) {
-    rval = mbImpl->tag_delete_data( prtn_tag, &old, 1 );
-    if (MB_SUCCESS != rval)
-      return rval;
-    partitioningSet = 0;
-  }
-  
-  if (!set) 
-    return MB_SUCCESS;
-  
-  MBRange contents;
-  if (old) {
-    rval = mbImpl->get_entities_by_handle( old, contents );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  else {
-    contents = partition_sets();
-  }
-
-  rval = mbImpl->add_entities( set, contents );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // store pcomm id on new partition set
-  rval = mbImpl->tag_set_data( prtn_tag, &set, 1, &id );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  partitioningSet = set;
-  return MB_SUCCESS;
-}
-  
-
-  //! return all the entities in parts owned locally
-MBErrorCode MBParallelComm::get_part_entities(MBRange &ents, int dim) 
-{
-  MBErrorCode result;
-  
-  for (MBRange::iterator rit = partitionSets.begin(); 
-       rit != partitionSets.end(); rit++) {
-    MBRange tmp_ents;
-    if (-1 == dim) 
-      result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true);
-    else
-      result = mbImpl->get_entities_by_dimension(*rit, dim, tmp_ents, true);
-
-    if (MB_SUCCESS != result) return result;
-    ents.merge(tmp_ents);
-  }
-  
-  return MB_SUCCESS;
-}
-
-  /** \brief Return the rank of the entity owner
-   */
-MBErrorCode MBParallelComm::get_owner_handle(MBEntityHandle entity,
-                                             int &owner,
-                                             MBEntityHandle &handle) 
-{
-  unsigned char pstat;
-  int sharing_procs[MAX_SHARING_PROCS];
-  MBEntityHandle sharing_handles[MAX_SHARING_PROCS];
-
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1,
-                                            &pstat);
-  if (!(pstat & PSTATUS_NOT_OWNED)) {
-    owner = proc_config().proc_rank();
-    handle = entity;
-  }
-  
-  else if (pstat & PSTATUS_MULTISHARED) {
-    result = mbImpl->tag_get_data(sharedps_tag(), &entity, 1,
-                                  sharing_procs);
-    owner = sharing_procs[0];
-    result = mbImpl->tag_get_data(sharedhs_tag(), &entity, 1,
-                                  sharing_handles);
-    handle = sharing_handles[0];
-  }
-  else if (pstat & PSTATUS_SHARED) {
-    result = mbImpl->tag_get_data(sharedp_tag(), &entity, 1,
-                                  sharing_procs);
-    RRA(" ");
-    owner = sharing_procs[0];
-    result = mbImpl->tag_get_data(sharedh_tag(), &entity, 1,
-                                  sharing_handles);
-    handle = sharing_handles[0];
-  }
-  else {
-    owner = -1;
-    handle = 0;
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_global_part_count( int& count_out ) const
-{
-  count_out = globalPartCount;
-  return count_out < 0 ? MB_FAILURE : MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_part_owner( int part_id, int& owner ) const
-{
-  // FIXME: assumes only 1 local part
-  owner = part_id;
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_part_id( MBEntityHandle /*part*/, int& id_out ) const
-{
-  // FIXME: assumes only 1 local part
-  id_out = proc_config().proc_rank();
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_part_handle( int id, MBEntityHandle& handle_out ) const
-{
-  // FIXME: assumes only 1 local part
-  if ((unsigned)id != proc_config().proc_rank())
-    return MB_ENTITY_NOT_FOUND;
-  handle_out = partition_sets().front();
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::create_part( MBEntityHandle& set_out )
-{
-    // mark as invalid so we know that it needs to be updated
-  globalPartCount = -1;
-  
-    // create set representing part
-  MBErrorCode rval = mbImpl->create_meshset( MESHSET_SET, set_out );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-    // set tag on set
-    // FIXME: need to assign valid global id
-  int val = 0;
-  rval = mbImpl->tag_set_data( part_tag(), &set_out, 1, &val );
-  if (MB_SUCCESS != rval) {
-    mbImpl->delete_entities( &set_out, 1 );
-    return rval;
-  }
-  
-  if (get_partitioning()) {
-    rval = mbImpl->add_entities( get_partitioning(), &set_out, 1 );
-    if (MB_SUCCESS != rval) {
-      mbImpl->delete_entities( &set_out, 1 );
-      return rval;
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::destroy_part( MBEntityHandle part_id )
-{
-    // mark as invalid so we know that it needs to be updated
-  globalPartCount = -1;
-  
-  MBErrorCode rval;
-  if (get_partitioning()) {
-    rval = mbImpl->remove_entities( get_partitioning(), &part_id, 1 );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  return mbImpl->delete_entities( &part_id, 1 );
-}
-
-MBErrorCode MBParallelComm::collective_sync_partition()
-{
-  int count = partition_sets().size();
-  globalPartCount = 0;
-  int err = MPI_Allreduce( &count, &globalPartCount, 1, MPI_INT, MPI_SUM, 
-                           proc_config().proc_comm() );
-  return err ? MB_FAILURE : MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_part_neighbor_ids( MBEntityHandle part,
-                                                   int neighbors_out[MAX_SHARING_PROCS],
-                                                   int& num_neighbors_out )
-{
-  MBErrorCode rval;
-  MBRange iface;
-  rval = get_interface_sets( part, iface );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  num_neighbors_out = 0;
-  int n, j = 0;
-  int tmp[MAX_SHARING_PROCS], curr[MAX_SHARING_PROCS];
-  int *parts[2] = { neighbors_out, tmp };
-  for (MBRange::iterator i = iface.begin(); i != iface.end(); ++i) {
-    unsigned char pstat;
-    rval = get_sharing_data( *i, curr, NULL, pstat, n);
-    if (MB_SUCCESS != rval)
-      return rval;
-    std::sort( curr, curr+n );
-    assert( num_neighbors_out < MAX_SHARING_PROCS );
-    int* k = std::set_union( parts[j], parts[j]+num_neighbors_out,
-                             curr, curr + n, parts[1-j] );
-    j = 1-j;
-    num_neighbors_out = k - parts[j];
-  }
-  if (parts[j] != neighbors_out)
-    std::copy( parts[j], parts[j]+num_neighbors_out, neighbors_out );
-    
-    
-    // remove input part from list
-  int id;
-  rval = get_part_id( part, id );
-  if (MB_SUCCESS == rval) 
-    num_neighbors_out = std::remove( neighbors_out, neighbors_out+num_neighbors_out, id ) - neighbors_out;
-  return rval;
-}
-
-MBErrorCode MBParallelComm::get_interface_sets( MBEntityHandle ,
-                                                MBRange& iface_sets_out,
-                                                int* adj_part_id )
-{
-    // FIXME : assumes one part per processor.
-    // Need to store part iface sets as children to implement
-    // this correctly.
-  iface_sets_out = interface_sets();
-
-  if (adj_part_id) {
-    int part_ids[MAX_SHARING_PROCS], num_parts;
-    MBRange::iterator i = iface_sets_out.begin();
-    while (i != iface_sets_out.end()) {
-      unsigned char pstat;
-      MBErrorCode rval = get_sharing_data( *i, part_ids, NULL, pstat, num_parts );
-      if (MB_SUCCESS != rval)
-        return rval;
-      
-      if (std::find(part_ids, part_ids+num_parts, *adj_part_id) - part_ids != num_parts)
-        ++i;
-      else
-        i = iface_sets_out.erase( i );
-    }
-  }
-    
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_owning_part( MBEntityHandle handle,
-                                             int& owning_part_id,
-                                             MBEntityHandle* remote_handle )
-{
-
-  // FIXME : assumes one part per proc, and therefore part_id == rank
-  
-    // If entity is not shared, then we're the owner.
-  unsigned char pstat;
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &handle, 1,
-                                            &pstat);
-  if (!(pstat & PSTATUS_NOT_OWNED)) {
-    owning_part_id = proc_config().proc_rank();
-    if (remote_handle)
-      *remote_handle = handle;
-    return MB_SUCCESS;
-  }
-  
-    // If entity is shared with one other proc, then
-    // sharedp_tag will contain a positive value.
-  result = mbImpl->tag_get_data( sharedp_tag(), &handle, 1, &owning_part_id );
-  if (MB_SUCCESS != result)
-    return result;
-  if (owning_part_id != -1) {
-      // done?
-    if (!remote_handle)
-      return MB_SUCCESS;
-      
-      // get handles on remote processors (and this one)
-    return mbImpl->tag_get_data( sharedh_tag(), &handle, 1, remote_handle );
-  }
-  
-    // If here, then the entity is shared with at least two other processors.
-    // Get the list from the sharedps_tag
-  const void* part_id_list = 0;
-  result = mbImpl->tag_get_data( sharedps_tag(), &handle, 1, &part_id_list );
-  if (MB_SUCCESS != result)
-    return result;
-  owning_part_id = ((const int*)part_id_list)[0];
- 
-    // done?
-  if (!remote_handle)
-    return MB_SUCCESS;
-  
-    // get remote handles
-  const void* handle_list = 0;
-  result = mbImpl->tag_get_data( sharedhs_tag(), &handle, 1, &handle_list );
-  if (MB_SUCCESS != result)
-    return result;
-  
-  *remote_handle = ((const MBEntityHandle*)handle_list)[0];
-  return MB_SUCCESS;
-}    
-
-MBErrorCode MBParallelComm::get_sharing_parts( MBEntityHandle entity,
-                                               int part_ids_out[MAX_SHARING_PROCS],
-                                               int& num_part_ids_out,
-                                               MBEntityHandle remote_handles[MAX_SHARING_PROCS] )
-{
-
-  // FIXME : assumes one part per proc, and therefore part_id == rank
-  
-    // If entity is not shared, then we're the owner.
-  unsigned char pstat;
-  MBErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1,
-                                            &pstat);
-  if (!(pstat & PSTATUS_SHARED)) {
-    part_ids_out[0] = proc_config().proc_rank();
-    if (remote_handles)
-      remote_handles[0] = entity;
-    num_part_ids_out = 1;
-    return MB_SUCCESS;
-  }
-  
-    // If entity is shared with one other proc, then
-    // sharedp_tag will contain a positive value.
-  result = mbImpl->tag_get_data( sharedp_tag(), &entity, 1, part_ids_out );
-  if (MB_SUCCESS != result)
-    return result;
-  if (part_ids_out[0] != -1) {
-    
-    num_part_ids_out = 2;
-    part_ids_out[1] = proc_config().proc_rank();
-
-      // done?
-    if (!remote_handles)
-      return MB_SUCCESS;
-      
-      // get handles on remote processors (and this one)
-    remote_handles[1] = entity;
-    return mbImpl->tag_get_data( sharedh_tag(), &entity, 1, remote_handles );
-  }
-  
-    // If here, then the entity is shared with at least two other processors.
-    // Get the list from the sharedps_tag
-  result = mbImpl->tag_get_data( sharedps_tag(), &entity, 1, part_ids_out );
-  if (MB_SUCCESS != result)
-    return result;
-    // Count number of valid (positive) entries in sharedps_tag
-  for (num_part_ids_out = 0; num_part_ids_out < MAX_SHARING_PROCS &&
-       part_ids_out[num_part_ids_out] >= 0; ++num_part_ids_out);
-  part_ids_out[num_part_ids_out++] = proc_config().proc_rank();
-  
-    // done?
-  if (!remote_handles)
-    return MB_SUCCESS;
-  
-    // get remote handles
-  result = mbImpl->tag_get_data( sharedhs_tag(), &entity, 1, remote_handles );
-  remote_handles[num_part_ids_out-1] = entity;
-  return result;
-}
-
-MBErrorCode MBParallelComm::pack_shared_handles(
-    std::vector<std::vector<SharedEntityData> > &send_data) 
-{
-    // get all shared entities
-  MBRange all_shared, dum_range;
-  MBErrorCode rval = mbImpl->get_entities_by_handle(0, all_shared);
-  if (MB_SUCCESS != rval)
-    return rval;
-  rval = get_pstatus_entities(-1, 0, dum_range);
-  if (MB_SUCCESS != rval)
-    return rval;
-  all_shared = subtract( all_shared, dum_range);
-  all_shared.erase(all_shared.upper_bound(MBPOLYHEDRON), all_shared.end());
-  assert(sharedEnts == all_shared);
-
-    // build up send buffers
-  int ent_procs[MAX_SHARING_PROCS];
-  MBEntityHandle handles[MAX_SHARING_PROCS];
-  int num_sharing;
-  SharedEntityData tmp;
-  send_data.resize(buffProcs.size());
-  for (MBRange::iterator i = all_shared.begin(); i != all_shared.end(); ++i) {
-    tmp.remote = *i; // swap local/remote so they're correct on the remote proc.
-    rval = get_owner( *i, tmp.owner );
-    if (MB_SUCCESS != rval)
-      return rval;
-
-    unsigned char pstat;
-    rval = get_sharing_data( *i, ent_procs, handles, pstat, num_sharing );
-    if (MB_SUCCESS != rval)
-      return rval;
-    for (int j = 0; j < num_sharing; ++j) {
-      if (ent_procs[j] == (int)proc_config().proc_rank())
-        continue;
-      tmp.local = handles[j];
-      int ind = get_buffers(ent_procs[j]);
-      assert(-1 != ind);
-      send_data[ind].push_back( tmp );
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::exchange_all_shared_handles(  
-    std::vector<std::vector<SharedEntityData> > &send_data, 
-    std::vector<std::vector<SharedEntityData> > &result)
-{
-  int ierr;
-  const int tag = 0x4A41534E;
-  const MPI_Comm comm = procConfig.proc_comm();
-  const int num_proc = buffProcs.size();
-  const std::vector<int> procs( buffProcs.begin(), buffProcs.end() );
-  std::vector<MPI_Request> recv_req(buffProcs.size(), MPI_REQUEST_NULL);
-  
-    // set up to receive sizes
-  std::vector<int> sizes_send(num_proc), sizes_recv(num_proc);
-  for (int i = 0; i < num_proc; ++i) {
-    ierr = MPI_Irecv( &sizes_recv[i], 1, MPI_INT, procs[i], tag, comm, &recv_req[i] );
-    if (ierr) 
-      return MB_FILE_WRITE_ERROR;
-  }
-  
-    // send sizes
-  assert(num_proc == (int)send_data.size());
-  
-  sendReqs.resize(buffProcs.size(), MPI_REQUEST_NULL);
-  for (int i = 0; i < num_proc; ++i) {
-    sizes_send[i] = send_data[i].size();
-    ierr = MPI_Isend( &sizes_send[i], 1, MPI_INT, buffProcs[i], tag, comm, &sendReqs[i] );
-    if (ierr) 
-      return MB_FILE_WRITE_ERROR;
-  }
-  
-    // receive sizes
-  std::vector<MPI_Status> stat(num_proc);
-  ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
-  if (ierr)
-    return MB_FILE_WRITE_ERROR;
-  
-    // wait until all sizes are sent (clean up pending req's)
-  ierr = MPI_Waitall( num_proc, &sendReqs[0], &stat[0] );
-  if (ierr)
-    return MB_FILE_WRITE_ERROR;
-  
-    // set up to receive data
-  for (int i = 0; i < num_proc; ++i) {
-    result[i].resize( sizes_recv[i] );
-    ierr = MPI_Irecv( &result[i][0], 
-                      sizeof(SharedEntityData)*sizes_recv[i], 
-                      MPI_UNSIGNED_CHAR, 
-                      buffProcs[i], tag, comm, &recv_req[i] );
-    if (ierr) 
-      return MB_FILE_WRITE_ERROR;
-  }
-  
-    // send data
-  for (int i = 0; i < num_proc; ++i) {
-    ierr = MPI_Isend( &send_data[i][0], 
-                      sizeof(SharedEntityData)*sizes_send[i], 
-                      MPI_UNSIGNED_CHAR, 
-                      buffProcs[i], tag, comm, &sendReqs[i] );
-    if (ierr) 
-      return MB_FILE_WRITE_ERROR;
-  }
-  
-    // receive data
-  ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
-  if (ierr)
-    return MB_FILE_WRITE_ERROR;
-  
-    // wait until everything is sent to release send buffers
-  ierr = MPI_Waitall( num_proc, &sendReqs[0], &stat[0] );
-  if (ierr)
-    return MB_FILE_WRITE_ERROR;
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::check_all_shared_handles() 
-{
-    // get all shared ent data from other procs
-  std::vector<std::vector<SharedEntityData> > shents(buffProcs.size()),
-      send_data(buffProcs.size());
-
-  MBErrorCode result = check_local_shared();
-  if (MB_SUCCESS != result)
-    return result;
-
-  result = pack_shared_handles(send_data);
-  if (MB_SUCCESS != result)
-    return result;
-  
-  result = exchange_all_shared_handles(send_data, shents);
-  if (MB_SUCCESS != result)
-    return result;
-  else if (shents.empty())
-    return MB_SUCCESS;
-
-  return check_my_shared_handles(shents);
-}
-
-MBErrorCode MBParallelComm::check_local_shared() 
-{
-    // do some local checks on shared entities to make sure things look
-    // consistent
-
-    // check that non-vertex shared entities are shared by same procs as all
-    // their vertices
-  std::pair<MBRange::const_iterator,MBRange::const_iterator> vert_it =
-      sharedEnts.equal_range(MBVERTEX);
-  std::vector<MBEntityHandle> dum_connect;
-  const MBEntityHandle *connect;
-  int num_connect;
-  int tmp_procs[MAX_SHARING_PROCS];
-  MBEntityHandle tmp_hs[MAX_SHARING_PROCS];
-  std::set<int> tmp_set, vset;
-  int num_ps;
-  MBErrorCode result;
-  unsigned char pstat;
-  MBRange bad_ents;
-  std::vector<std::string> errors;
-  std::string dum_err;
-  
-  MBRange::const_iterator rit;
-  for (rit = sharedEnts.begin(); rit != sharedEnts.end(); rit++) {
-
-      // get sharing procs for this ent
-    result = get_sharing_data(*rit, tmp_procs, tmp_hs, pstat, num_ps);
-    if (MB_SUCCESS != result) {
-      bad_ents.insert(*rit);
-      errors.push_back(std::string("Failure getting sharing data."));
-      continue;
-    }
-
-    bool bad = false;
-      // entity must be shared
-    if (!(pstat & PSTATUS_SHARED))
-      errors.push_back(std::string("Entity should be shared but isn't.")), bad = true;
-
-      // if entity is not owned this must not be first proc
-    if (pstat & PSTATUS_NOT_OWNED && tmp_procs[0] == (int)procConfig.proc_rank())
-      errors.push_back(std::string("Entity not owned but is first proc.")), bad = true;
-
-      // if entity is owned and multishared, this must be first proc
-    if (!(pstat & PSTATUS_NOT_OWNED) && pstat & PSTATUS_MULTISHARED && 
-        (tmp_procs[0] != (int)procConfig.proc_rank() || tmp_hs[0] != *rit))
-      errors.push_back(std::string("Entity owned and multishared but not first proc or not first handle.")), bad = true;
-
-    if (bad) {
-      bad_ents.insert(*rit);
-      continue;
-    }
-    
-    if (mbImpl->type_from_handle(*rit) == MBVERTEX) continue;
-
-      // copy element's procs to vset and save size
-    int orig_ps = num_ps; vset.clear(); 
-    std::copy(tmp_procs, tmp_procs+num_ps, std::inserter(vset, vset.begin()));
-    
-      // get vertices for this ent and intersection of sharing procs
-    result = mbImpl->get_connectivity(*rit, connect, num_connect, false, &dum_connect);
-    if (MB_SUCCESS != result) {
-      bad_ents.insert(*rit); 
-      errors.push_back(std::string("Couldn't get connectivity."));
-      continue;
-    }
-    
-    for (int i = 0; i < num_connect; i++) {
-      result = get_sharing_data(connect[i], tmp_procs, NULL, pstat, num_ps);
-      if (MB_SUCCESS != result) {bad_ents.insert(*rit); continue;}
-      if (!num_ps) {vset.clear(); break;}
-      std::sort(tmp_procs, tmp_procs+num_ps);
-      tmp_set.clear();
-      std::set_intersection(tmp_procs, tmp_procs+num_ps,
-                            vset.begin(), vset.end(), std::inserter(tmp_set, tmp_set.end()));
-      vset.swap(tmp_set);
-      if (vset.empty()) break;
-    }
-    
-      // intersect them; should be the same size as orig_ps
-    tmp_set.clear();
-    std::set_intersection(tmp_procs, tmp_procs+num_ps,
-                          vset.begin(), vset.end(), std::inserter(tmp_set, tmp_set.end()));
-    if (orig_ps != (int)tmp_set.size()) {
-      errors.push_back(std::string("Vertex proc set not same size as entity proc set."));
-      bad_ents.insert(*rit);
-    }
-  }
-  
-  if (!bad_ents.empty()) {
-    std::cout << "Found bad entities in check_local_shared, proc rank "
-              << procConfig.proc_rank() << "," << std::endl;
-    std::vector<std::string>::iterator vit;
-    for (rit = bad_ents.begin(), vit = errors.begin(); rit != bad_ents.end(); rit++, vit++) {
-      list_entities(&(*rit), 1);
-      std::cout << "Reason: " << *vit << std::endl;
-    }
-    return MB_FAILURE;
-  }
-
-    // to do: check interface sets
-
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::check_all_shared_handles(MBParallelComm **pcs,
-                                                     int num_pcs) 
-{
-  std::vector<std::vector<std::vector<SharedEntityData> > > shents, send_data;
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-
-    // get all shared ent data from each proc to all other procs
-  send_data.resize(num_pcs);
-  for (int p = 0; p < num_pcs; p++) {
-    tmp_result = pcs[p]->pack_shared_handles(send_data[p]);
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  if (MB_SUCCESS != result) return result;
-
-    // move the data sorted by sending proc to data sorted by receiving proc
-  shents.resize(num_pcs);
-  for (int p = 0; p < num_pcs; p++)
-    shents[p].resize(pcs[p]->buffProcs.size());
-    
-  for (int p = 0; p < num_pcs; p++) {
-    for (unsigned int idx_p = 0; idx_p < pcs[p]->buffProcs.size(); idx_p++) {
-        // move send_data[p][to_p] to shents[to_p][idx_p]
-      int to_p = pcs[p]->buffProcs[idx_p];
-      int top_idx_p = pcs[to_p]->get_buffers(p);
-      assert(-1 != top_idx_p);
-      shents[to_p][top_idx_p] = send_data[p][idx_p];
-    }
-  }
-  
-  for (int p = 0; p < num_pcs; p++) {
-    std::ostringstream ostr;
-    ostr << "Processor " << p << " bad entities:";
-    tmp_result = pcs[p]->check_my_shared_handles(shents[p], ostr.str().c_str());
-    if (MB_SUCCESS != tmp_result) result = tmp_result;
-  }
-  
-  return result;
-}
-
-MBErrorCode MBParallelComm::check_my_shared_handles(
-    std::vector<std::vector<SharedEntityData> > &shents,
-                                                    const char *prefix) 
-{
-    // now check against what I think data should be
-    // get all shared entities
-  MBErrorCode result;
-  MBRange dum_range, all_shared = sharedEnts;
-  all_shared.erase(all_shared.upper_bound(MBPOLYHEDRON), all_shared.end());
-
-  MBRange bad_ents, local_shared;
-  std::vector<SharedEntityData>::iterator vit;
-  for (unsigned int i = 0; i < shents.size(); i++) {
-    int other_proc = buffProcs[i];
-    result = get_shared_entities(other_proc, local_shared);
-    if (MB_SUCCESS != result) return result;
-    for (vit = shents[i].begin(); vit != shents[i].end(); vit++) {
-      MBEntityHandle localh = vit->local, remoteh = vit->remote, dumh;
-      local_shared.erase(localh);
-      result = get_remote_handles(true, &localh, &dumh, 1, other_proc, dum_range);
-      if (MB_SUCCESS != result || dumh != remoteh) 
-        bad_ents.insert(localh);
-    }
-
-    if (!local_shared.empty()) 
-      bad_ents.merge(local_shared);
-  }
-  
-  if (!bad_ents.empty()) {
-    if (prefix) {
-      std::cout << prefix << std::endl;
-      list_entities(bad_ents);
-    }
-    return MB_FAILURE;
-  }
-
-  else return MB_SUCCESS;
-}
-
-MBErrorCode MBParallelComm::get_shared_entities(int other_proc,
-                                                MBRange &shared_ents,
-                                                int dim,
-                                                const bool iface,
-                                                const bool owned_filter) 
-{
-  shared_ents.clear();
-  MBErrorCode result = MB_SUCCESS;
-  
-    // dimension
-  if (-1 != dim) {
-    MBDimensionPair dp = MBCN::TypeDimensionMap[dim];
-    MBRange dum_range;
-    shared_ents.merge(sharedEnts.lower_bound(dp.first), 
-                      sharedEnts.upper_bound(dp.second));
-  }
-  else shared_ents = sharedEnts;
-
-    // filter by iface
-  if (iface) {
-    result = filter_pstatus(shared_ents, PSTATUS_INTERFACE, PSTATUS_AND);
-    RRA("");
-  }
-  
-    // filter by owned
-  if (owned_filter) {
-    result = filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT);
-    RRA("");
-  }
-
-    // filter by proc
-  if (-1 != other_proc) {
-    result = filter_pstatus(shared_ents, PSTATUS_SHARED, PSTATUS_AND, other_proc);
-    RRA("");
-  }
-  
-  return result;
-}
-
-#ifdef TEST_PARALLELCOMM
-
-#include <iostream>
-
-#include "MBCore.hpp"
-#include "MBParallelComm.hpp"
-#include "MBRange.hpp"
-
-#define PM {std::cerr << "Test failed; error message:" << std::endl;\
-          std::string errmsg; \
-          dynamic_cast<MBCore*>(my_impl)->get_last_error(errmsg); \
-          std::cerr << errmsg << std::endl;\
-          return 1;}
-
-int main(int argc, char* argv[])
-{
-
-    // Check command line arg
-  if (argc < 2)
-  {
-    std::cout << "Usage: " << argv[0] << " <mesh_file_name>" << std::endl;
-    exit(1);
-  }
-
-  const char* file = argv[1];
-  MBCore *my_impl = new MBCore(0, 2);
-  MBInterface* mbImpl = my_impl;
-
-    // create a communicator class, which will start mpi too
-  MBParallelComm pcomm(mbImpl, my_impl->tag_server(), my_impl->sequence_manager());
-  MBErrorCode result;
-
-    // load the mesh
-  result = mbImpl->load_mesh(file, 0, 0);
-  if (MB_SUCCESS != result) return result;
-
-    // get the mesh
-  MBRange all_mesh, whole_range;
-  result = mbImpl->get_entities_by_dimension(0, 3, all_mesh);
-  if (MB_SUCCESS != result) return result;
-    
-  int buff_size;
-  result = pcomm.pack_buffer(all_mesh, false, true, true, false, whole_range, buff_size);
-  PM;
-
-
-    // allocate space in the buffer
-  pcomm.buffer_size(buff_size);
-
-    // pack the actual buffer
-  int actual_buff_size;
-  result = pcomm.pack_buffer(whole_range, false, true, false, false, all_mesh, 
-                             actual_buff_size);
-  PM;
-
-    // list the entities that got packed
-  std::cout << "ENTITIES PACKED:" << std::endl;
-  mbImpl->list_entities(all_mesh);
-
-    // get the buffer
-  std::vector<unsigned char> tmp_buffer;
-  pcomm.take_buffer(tmp_buffer);
-    
-    // stop and restart MOAB
-  delete mbImpl;
-  my_impl = new MBCore(1, 2);
-  mbImpl = my_impl;
-    
-    // create a new communicator class, using our old buffer
-  MBParallelComm pcomm2(mbImpl, my_impl->tag_server(), my_impl->sequence_manager(),
-                        tmp_buffer);
-
-    // unpack the results
-  all_mesh.clear();
-  result = pcomm2.unpack_buffer(all_mesh, store_remote_handles, from_proc);
-  PM;
-  
-  std::cout << "ENTITIES UNPACKED:" << std::endl;
-  mbImpl->list_entities(all_mesh);
-  
-  std::cout << "Success, processor " << mbImpl->proc_rank() << "." << std::endl;
-  
-  return 1;
-}
-#endif

Deleted: MOAB/trunk/src/parallel/MBParallelData.cpp
===================================================================
--- MOAB/trunk/src/parallel/MBParallelData.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/MBParallelData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,96 +0,0 @@
-#include "MBParallelData.hpp"
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBInterface.hpp"
-
-#include <map>
-
-    //! return partition sets; if tag_name is input, gets sets with
-    //! that tag name, otherwise uses PARALLEL_PARTITION tag
-MBErrorCode MBParallelData::get_partition_sets(MBRange &part_sets,
-                                               const char *tag_name) 
-{
-  MBTag part_tag = 0;
-  MBErrorCode result;
-  
-  if (NULL != tag_name) 
-    result = mbImpl->tag_get_handle(tag_name, part_tag);
-  else
-    result = mbImpl->tag_get_handle(PARALLEL_PARTITION_TAG_NAME, part_tag);
-    
-  if (MB_SUCCESS != result) return result;
-  else if (0 == part_tag) return MB_TAG_NOT_FOUND;
-  
-  result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, 
-                                                NULL, 1, part_sets,
-                                                MBInterface::UNION);
-  return result;
-}
-  
-
-    //! get communication interface sets and the processors with which
-    //! this processor communicates; sets are sorted by processor
-MBErrorCode MBParallelData::get_interface_sets(std::vector<MBEntityHandle> &iface_sets,
-                                               std::vector<int> &iface_procs) 
-{
-#define CONTINUE {result = tmp_result; continue;}
-  iface_sets.clear();
-  iface_procs.clear();
-  
-  MBTag proc_tag = 0, procs_tag = 0;
-  MBErrorCode result = MB_SUCCESS;
-  int my_rank;
-  if (parallelComm) 
-    my_rank = parallelComm->proc_config().proc_rank();
-  else 
-    return MB_FAILURE;
-
-  std::multimap<int, MBEntityHandle> iface_data;
-
-  for (int i = 0; i < 2; i++) {
-    MBErrorCode tmp_result;
-    
-    if (0 == i)
-      tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROC_TAG_NAME, 
-                                      proc_tag);
-    else
-      tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROCS_TAG_NAME, 
-                                      proc_tag);
-    if (0 == proc_tag) CONTINUE;
-
-    int tsize;
-    tmp_result = mbImpl->tag_get_size(proc_tag, tsize);
-    if (0 == tsize || MB_SUCCESS != tmp_result) CONTINUE;
-    
-    MBRange proc_sets;
-    tmp_result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, 
-                                                  &proc_tag, NULL, 1,
-                                                  proc_sets, MBInterface::UNION);
-    if (MB_SUCCESS != tmp_result) CONTINUE;
-    
-    if (proc_sets.empty()) CONTINUE;
-      
-    std::vector<int> proc_tags(proc_sets.size()*tsize/sizeof(int));
-    tmp_result = mbImpl->tag_get_data(procs_tag, proc_sets, &proc_tags[0]);
-    if (MB_SUCCESS != tmp_result) CONTINUE;
-    int k;
-    MBRange::iterator rit;
-    
-    for (k = 0, rit = proc_sets.begin(); rit != proc_sets.end(); rit++, k++) {
-      for (int j = 0; j < tsize; j++) {
-        if (my_rank != proc_tags[2*k+j] && proc_tags[2*k+j] >= 0)
-          iface_data.insert(std::pair<int,MBEntityHandle>(proc_tags[2*k+j], *rit));
-      }
-    }
-  }
-
-    // now get the results in sorted order
-  std::multimap<int,MBEntityHandle>::iterator mit;
-  for (mit = iface_data.begin(); mit != iface_data.end(); mit++)
-    iface_procs.push_back((*mit).first),
-      iface_sets.push_back((*mit).second);
-    
-  return result;
-}
-
-

Deleted: MOAB/trunk/src/parallel/MBProcConfig.cpp
===================================================================
--- MOAB/trunk/src/parallel/MBProcConfig.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/MBProcConfig.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,66 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#include "MBProcConfig.hpp"
-extern "C" {
-#ifdef USE_MPI
-#  include "types.h"
-#  include "errmem.h"
-#  include "crystal.h"
-#else
-   struct crystal_data {};
-#endif
-} // extern "C"
-
-//! Constructor
-MBProcConfig::MBProcConfig(MPI_Comm proc_comm) 
-    : procComm(proc_comm),
-      crystalData(0)
-{
-#ifdef USE_MPI
-  int rank, size;
-  MPI_Comm_rank(procComm, &rank); 
-  procRank = (unsigned int) rank;
-  MPI_Comm_size(procComm, &size); 
-  procSize = (unsigned int) size;
-#else
-  procRank = 0;
-  procSize = 1;
-#endif
-}
-
-crystal_data *MBProcConfig::crystal_router(bool construct_if_missing)
-{
-#ifdef USE_MPI
-  if (!crystalData && construct_if_missing) {
-    crystalData = new crystal_data;
-    crystal_init(crystalData, procComm);
-  }
-#endif
-
-  return crystalData;
-}
-
-MBProcConfig::~MBProcConfig() 
-{
-  if (crystalData) {
-#ifdef USE_MPI
-    crystal_free(crystalData);
-#endif
-    delete crystalData;
-    crystalData = 0;
-  }
-}
-

Modified: MOAB/trunk/src/parallel/Makefile.am
===================================================================
--- MOAB/trunk/src/parallel/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,18 +1,13 @@
 # Don't require GNU-standard files (Changelog, README, etc.)
 AUTOMAKE_OPTIONS = foreign
 
-# Subdirectories to build
-SUBDIRS = 
-
 # Things to build
 noinst_LTLIBRARIES = libMOABpar.la
          
 # Some variables
 AM_CPPFLAGS += -DIS_BUILDING_MB -DSRCDIR=$(srcdir) \
                -I$(srcdir)/.. -I.. -I$(srcdir)/../io \
-               -I$(srcdir)/../io/mhdf/include  \
-               -I$(srcdir)/../moab -I../moab \
-               -I$(srcdir)/moab -Imoab
+               -I$(srcdir)/../io/mhdf/include 
 
 # The directory in which to install headers
 libMOABpar_la_includedir = $(includedir)
@@ -29,9 +24,9 @@
 if PARALLEL
 # The list of source files, and any header files that do not need to be installed
   MOAB_PARALLEL_SRCS += \
-     MBParallelComm.cpp \
-     MBProcConfig.cpp \
-     MBParallelData.cpp \
+     ParallelComm.cpp \
+     ProcConfig.cpp \
+     ParallelData.cpp \
      ReadParallel.cpp \
      ReadParallel.hpp \
      crystal.h errmem.h types.h \
@@ -42,11 +37,11 @@
 
 # The list of header files which are to be installed
   MOAB_PARALLEL_HDRS += \
-     moab/MBmpi.h \
-     moab/MBmpi_config.h \
-     moab/MBParallelComm.hpp \
-     moab/MBProcConfig.hpp \
-     moab/MBParallelData.hpp \
+     moab_mpi.h \
+     moab_mpi_config.h \
+     moab/ParallelComm.hpp \
+     moab/ProcConfig.hpp \
+     moab/ParallelData.hpp \
      moab/MBParallelConventions.h 
 
 if PARALLEL_HDF5

Copied: MOAB/trunk/src/parallel/ParallelComm.cpp (from rev 3583, MOAB/trunk/src/parallel/MBParallelComm.cpp)
===================================================================
--- MOAB/trunk/src/parallel/ParallelComm.cpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/ParallelComm.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,6252 @@
+#include "moab/Interface.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "SequenceManager.hpp"
+#include "EntitySequence.hpp"
+#include "TagServer.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Skinner.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/Core.hpp"
+#include "Error.hpp"
+#include "ElementSequence.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/RangeMap.hpp"
+#include "moab/MeshTopoUtil.hpp"
+
+#include <iostream>
+#include <sstream>
+#include <algorithm>
+#include <functional>
+#include <numeric>
+
+#define MIN(a,b) (a < b ? a : b)
+#define MAX(a,b) (a > b ? a : b)
+const bool debug = false;
+
+#include <math.h>
+#include <assert.h>
+
+
+
+extern "C" 
+{
+#include "types.h"
+#include "minmax.h"
+#include "gs.h"
+#include "errmem.h"
+#include "sort.h"
+#include "tuple_list.h"
+}
+
+#ifdef USE_MPI
+#include "moab_mpi.h"
+#endif
+#undef DEBUG_MPE
+//#define DEBUG_MPE 1
+#ifdef DEBUG_MPE
+#include "mpe.h"
+int IFACE_START, IFACE_END;
+int GHOST_START, GHOST_END;
+int SHAREDV_START, SHAREDV_END;
+int RESOLVE_START, RESOLVE_END;
+int ENTITIES_START, ENTITIES_END;
+int RHANDLES_START, RHANDLES_END;
+#endif
+
+namespace moab {
+
+const unsigned int ParallelComm::INITIAL_BUFF_SIZE = 1024;
+
+const int MAX_BCAST_SIZE = (1<<28);
+
+#undef DEBUG_COMM
+//#define DEBUG_COMM 1
+#undef DEBUG_PACKING
+#undef DEBUG_MSGS
+//#define DEBUG_MSGS 1
+#undef DEBUG_BARRIER
+#define DEBUG_BARRIER 1
+#ifdef DEBUG_MSGS
+std::vector<ParallelComm::Buffer*> msgs;
+#endif
+#ifdef DEBUG_PACKING
+unsigned int __PACK_num = 0, __UNPACK_num = 0, __PACK_count = 0, __UNPACK_count = 0;
+std::string __PACK_string, __UNPACK_string;
+
+#define PC(n, m) {\
+          if (__PACK_num == (unsigned int)n && __PACK_string == m) __PACK_count++;\
+          else {\
+            if (__PACK_count > 1) std::cerr << " (" << __PACK_count << "x)";\
+            __PACK_count = 1; __PACK_string = m; __PACK_num = n;\
+            std::cerr << std::endl << "PACK: " << n << m;\
+          }}
+#define UPC(n, m) {\
+          if (__UNPACK_num == (unsigned int)n && __UNPACK_string == m) __UNPACK_count++;\
+          else {\
+            if (__UNPACK_count > 1) std::cerr << "(" << __UNPACK_count << "x)";\
+            __UNPACK_count = 1; __UNPACK_string = m; __UNPACK_num = n;\
+            std::cerr << std::endl << "UNPACK: " << n << m;\
+          }}
+#else
+#define PC(n, m)
+#define UPC(n, m)
+#endif
+
+template <typename T> static inline
+void UNPACK( unsigned char*& buff, T* val, size_t count )
+{
+  memcpy( val, buff, count*sizeof(T) );
+  buff += count*sizeof(T);
+}
+
+template <typename T> static inline
+void PACK( unsigned char*& buff, const T* val, size_t count )
+{
+  memcpy( buff, val, count*sizeof(T) );
+  buff += count*sizeof(T);
+}
+
+static inline
+void PACK_INTS( unsigned char*& buff, const int* int_val, size_t num )
+  { PACK( buff, int_val, num ); PC(num, " ints"); }
+
+static inline
+void PACK_INT( unsigned char*& buff, int int_val )
+  { PACK_INTS( buff, &int_val, 1 ); }
+
+static inline
+void PACK_DBL( unsigned char*& buff, const double* dbl_val, size_t num )
+  { PACK( buff, dbl_val, num ); PC(num, " doubles"); }
+
+static inline
+void PACK_EH( unsigned char*& buff, const EntityHandle* eh_val, size_t num )
+  { PACK( buff, eh_val, num ); PC(num, " handles"); }
+
+static inline
+void PACK_CHAR_64( unsigned char*& buff, const char* str )
+{
+  strncpy( reinterpret_cast<char*>(buff), str, 64 );
+  buff += 64;
+  PC(64, " chars");
+}
+
+static inline
+void PACK_VOID( unsigned char*& buff, const void* val, size_t num )
+{
+  PACK( buff, reinterpret_cast<const unsigned char*>(val), num );
+  PC(num, " void");
+}
+
+static inline
+void PACK_BYTES( unsigned char*& buff, const void* val, int num )
+  { PACK_INT(buff, num); PACK_VOID(buff, val, num); }
+
+static inline
+void PACK_RANGE( unsigned char*& buff, const Range& rng )
+{
+  PACK_INT( buff, rng.psize() );
+  Range::const_pair_iterator cit;
+  for (cit = rng.const_pair_begin(); cit != rng.const_pair_end(); ++cit) {
+    EntityHandle eh[2] = { cit->first, cit->second };
+    PACK_EH(buff, eh, 2);
+  }
+  PC(rng.psize(), "-subranged range");
+}
+
+static inline
+void UNPACK_INTS( unsigned char*& buff, int* int_val, size_t num )
+  { UNPACK(buff, int_val, num); UPC(num, " ints"); }
+
+static inline
+void UNPACK_INT( unsigned char*& buff, int& int_val )
+  { UNPACK_INTS( buff, &int_val, 1 ); }
+
+static inline
+void UNPACK_DBL( unsigned char*& buff, double* dbl_val, size_t num )
+  { UNPACK(buff, dbl_val, num); UPC(num, " doubles"); }
+
+static inline
+void UNPACK_EH( unsigned char*& buff, EntityHandle* eh_val, size_t num )
+  { UNPACK(buff, eh_val, num); UPC(num, " handles"); }
+
+static inline
+void UNPACK_CHAR_64( unsigned char*& buff, char* char_val )
+{
+  memcpy( buff, char_val, 64 );
+  buff += 64;
+  UPC(64, " chars");
+}
+
+static inline
+void UNPACK_VOID( unsigned char*& buff, void* val, size_t num )
+{
+  UNPACK(buff, reinterpret_cast<unsigned char*>(val), num);
+  UPC(num, " void");
+}
+
+static inline
+void UNPACK_TYPE( unsigned char*& buff, EntityType& type )
+{
+  int int_type = MBMAXTYPE;
+  UNPACK_INT(buff, int_type);
+  type = static_cast<EntityType>(int_type);
+  assert(type >= MBVERTEX && type <= MBMAXTYPE);
+}
+
+static inline
+void UNPACK_RANGE( unsigned char*& buff, Range& rng )
+{
+  int num_subs;
+  EntityHandle eh[2];
+  UNPACK_INT( buff, num_subs );
+  for (int i = 0; i < num_subs; ++i) {
+    UPC(num_subs, "-subranged range"); 
+    UNPACK_EH(buff, eh, 2); 
+    rng.insert(eh[0], eh[1]);
+  }
+}    
+
+enum MBMessageTag {MB_MESG_ANY=MPI_ANY_TAG, 
+                   MB_MESG_ENTS_ACK,
+                   MB_MESG_ENTS_SIZE,
+                   MB_MESG_ENTS_LARGE,
+                   MB_MESG_REMOTEH_ACK,
+                   MB_MESG_REMOTEH_SIZE,
+                   MB_MESG_REMOTEH_LARGE,
+                   MB_MESG_TAGS_ACK,
+                   MB_MESG_TAGS_SIZE,
+                   MB_MESG_TAGS_LARGE};
+    
+static inline size_t RANGE_SIZE(const Range& rng)
+  { return 2*sizeof(EntityHandle)*rng.psize()+sizeof(int); }
+
+static inline void PRINT_DEBUG_ISEND(int from, int to, unsigned char *buff,
+                                     int tag, int size) 
+{
+#ifdef DEBUG_COMM
+  std::cerr << "Isend, " << from << "->" << to
+            << ", buffer ptr = " << (void*)buff << ", tag=" << tag 
+            << ", size=" << size << std::endl; std::cerr.flush();
+#endif
+}
+
+static inline void PRINT_DEBUG_IRECV(int to, int from, unsigned char *buff, int size,
+                                     int tag, int incoming) 
+{
+#ifdef DEBUG_COMM
+  std::cerr << "Irecv, " << to << "<-" << from << ", buffer ptr=" << (void*)buff
+            << ", size=" << size << ", tag=" << tag
+            << (tag < MB_MESG_REMOTEH_ACK ? ", incoming1=" : 
+                (tag < MB_MESG_TAGS_ACK ? ", incoming2=" : ", incoming="))
+            << incoming << std::endl; std::cerr.flush();
+#endif
+}
+
+static inline void PRINT_DEBUG_RECD(MPI_Status status) 
+{
+#ifdef DEBUG_COMM
+  int this_count;
+  int success = MPI_Get_count(&status, MPI_UNSIGNED_CHAR, &this_count);
+  if (MPI_SUCCESS != success) this_count = -1;
+  std::cerr << "Received from " << status.MPI_SOURCE
+            << ", count = " << this_count 
+            << ", tag = " << status.MPI_TAG
+            << std::endl; std::cerr.flush();
+#endif    
+}
+
+static inline void PRINT_DEBUG_WAITANY(std::vector<MPI_Request> &reqs, int tag, int proc) 
+{
+#ifdef DEBUG_COMM
+  std::cerr << "Waitany, p=" << proc
+            << (tag < MB_MESG_REMOTEH_ACK ? ", recv_ent_reqs = " : 
+                (tag < MB_MESG_TAGS_ACK ? ", recv_remoteh_reqs = " : ", recv_tag_reqs = "));
+  for (unsigned int i = 0; i < reqs.size(); i++) std::cerr << " " << reqs[i];
+  std::cerr << std::endl; std::cerr.flush();
+#endif
+}
+
+
+#define RR(a) if (MB_SUCCESS != result) {\
+          dynamic_cast<Core*>(mbImpl)->get_error_handler()->set_last_error(a);\
+          return result;}
+
+#define RRA(a) if (MB_SUCCESS != result) {\
+      std::string tmp_str; mbImpl->get_last_error(tmp_str);\
+      tmp_str.append("\n"); tmp_str.append(a);\
+      dynamic_cast<Core*>(mbImpl)->get_error_handler()->set_last_error(tmp_str); \
+      return result;}
+
+#define RRAI(i, a) if (MB_SUCCESS != result) {                \
+      std::string tmp_str; i->get_last_error(tmp_str);\
+      tmp_str.append("\n"); tmp_str.append(a);\
+      dynamic_cast<Core*>(i)->get_error_handler()->set_last_error(tmp_str); \
+      return result;}
+
+/** Name of tag used to store ParallelComm Index on mesh paritioning sets */
+const char* PARTITIONING_PCOMM_TAG_NAME = "__PRTN_PCOMM";
+ 
+/** \brief Tag storing parallel communication objects
+ *
+ * This tag stores pointers to ParallelComm communication
+ * objects; one of these is allocated for each different
+ * communicator used to read mesh.  ParallelComm stores
+ * partition and interface sets corresponding to its parallel mesh.
+ * By default, a parallel read uses the first ParallelComm object
+ * on the interface instance; if instantiated with one, ReadParallel
+ * adds this object to the interface instance too.
+ *
+ * Tag type: opaque
+ * Tag size: MAX_SHARING_PROCS*sizeof(ParallelComm*)
+ */
+#define PARALLEL_COMM_TAG_NAME "__PARALLEL_COMM"
+
+
+ParallelComm::ParallelComm(Interface *impl, MPI_Comm comm, int* id ) 
+        : mbImpl(impl), procConfig(comm),
+          sharedpTag(0), sharedpsTag(0), 
+          sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0),
+          partitionTag(0), globalPartCount(-1), partitioningSet(0)
+{
+  initialize();
+  
+  if (id)
+    *id = pcommID;
+}
+
+ParallelComm::ParallelComm(Interface *impl,
+                               std::vector<unsigned char> &tmp_buff, 
+                               MPI_Comm comm,
+                               int* id) 
+    : mbImpl(impl), procConfig(comm),
+      sharedpTag(0), sharedpsTag(0), 
+      sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0),
+      partitionTag(0), globalPartCount(-1), partitioningSet(0)
+{
+  initialize();
+  
+  if (id)
+    *id = pcommID;
+}
+
+ParallelComm::~ParallelComm() 
+{
+  remove_pcomm(this);
+  delete_all_buffers();
+}
+
+void ParallelComm::initialize() 
+{
+  tagServer = dynamic_cast<Core*>(mbImpl)->tag_server();
+  sequenceManager = dynamic_cast<Core*>(mbImpl)->sequence_manager();
+  
+    // initialize MPI, if necessary
+  int flag = 1;
+  int retval = MPI_Initialized(&flag);
+  if (MPI_SUCCESS != retval || !flag) {
+    int argc = 0;
+    char **argv = NULL;
+    
+      // mpi not initialized yet - initialize here
+    retval = MPI_Init(&argc, &argv);
+  }
+
+    // reserve space for vectors
+  buffProcs.reserve(MAX_SHARING_PROCS);
+  localOwnedBuffs.reserve(MAX_SHARING_PROCS);
+  remoteOwnedBuffs.reserve(MAX_SHARING_PROCS);
+
+  pcommID = add_pcomm(this);
+}
+
+int ParallelComm::add_pcomm(ParallelComm *pc) 
+{
+    // add this pcomm to instance tag
+  std::vector<ParallelComm *> pc_array(MAX_SHARING_PROCS, 
+                                         (ParallelComm*)NULL);
+  Tag pc_tag = pcomm_tag(mbImpl, true);
+  assert(0 != pc_tag);
+  
+  ErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]);
+  if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) 
+    return -1;
+  int index = 0;
+  while (index < MAX_SHARING_PROCS && pc_array[index]) index++;
+  if (index == MAX_SHARING_PROCS) {
+    index = -1;
+    assert(false);
+  }
+  else {
+    pc_array[index] = pc;
+    mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]);
+  }
+  return index;
+}
+
+void ParallelComm::remove_pcomm(ParallelComm *pc) 
+{
+    // remove this pcomm from instance tag
+  std::vector<ParallelComm *> pc_array(MAX_SHARING_PROCS);
+  Tag pc_tag = pcomm_tag(mbImpl, true);
+  
+  ErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]);
+  std::vector<ParallelComm*>::iterator pc_it = 
+    std::find(pc_array.begin(), pc_array.end(), pc);
+  assert(MB_SUCCESS == result && 
+         pc_it != pc_array.end());
+  *pc_it = NULL;
+  mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]);
+}
+
+//! assign a global id space, for largest-dimension or all entities (and
+//! in either case for vertices too)
+ErrorCode ParallelComm::assign_global_ids(EntityHandle this_set,
+                                              const int dimension, 
+                                              const int start_id,
+                                              const bool largest_dim_only,
+                                              const bool parallel) 
+{
+  Range entities[4];
+  int local_num_elements[4];
+  ErrorCode result;
+  std::vector<unsigned char> pstatus;
+  for (int dim = 0; dim <= dimension; dim++) {
+    if (dim == 0 || !largest_dim_only || dim == dimension) {
+      result = mbImpl->get_entities_by_dimension(this_set, dim, entities[dim]); 
+      RRA("Failed to get vertices in assign_global_ids.");
+    }
+
+      // need to filter out non-locally-owned entities!!!
+    pstatus.resize(entities[dim].size());
+    result = mbImpl->tag_get_data(pstatus_tag(), entities[dim], &pstatus[0]);
+    RRA("Failed to get pstatus in assign_global_ids.");
+    
+    Range dum_range;
+    Range::iterator rit;
+    unsigned int i;
+    for (rit = entities[dim].begin(), i = 0; rit != entities[dim].end(); rit++, i++)
+      if (pstatus[i] & PSTATUS_NOT_OWNED)
+        dum_range.insert(*rit);
+    entities[dim] = subtract( entities[dim], dum_range);
+    
+    local_num_elements[dim] = entities[dim].size();
+  }
+  
+    // communicate numbers
+  std::vector<int> num_elements(procConfig.proc_size()*4);
+#ifdef USE_MPI
+  if (procConfig.proc_size() > 1 && parallel) {
+    int retval = MPI_Allgather(local_num_elements, 4, MPI_INT,
+                               &num_elements[0], 4, 
+                               MPI_INT, procConfig.proc_comm());
+    if (0 != retval) return MB_FAILURE;
+  }
+  else
+#endif
+    for (int dim = 0; dim < 4; dim++) num_elements[dim] = local_num_elements[dim];
+  
+    // my entities start at one greater than total_elems[d]
+  int total_elems[4] = {start_id, start_id, start_id, start_id};
+  
+  for (unsigned int proc = 0; proc < procConfig.proc_rank(); proc++) {
+    for (int dim = 0; dim < 4; dim++) total_elems[dim] += num_elements[4*proc + dim];
+  }
+  
+    //assign global ids now
+  Tag gid_tag;
+  int zero = 0;
+  result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), 
+                              MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
+                              &zero, true);
+  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
+  
+  for (int dim = 0; dim < 4; dim++) {
+    if (entities[dim].empty()) continue;
+    num_elements.resize(entities[dim].size());
+    int i = 0;
+    for (Range::iterator rit = entities[dim].begin(); rit != entities[dim].end(); rit++)
+      num_elements[i++] = total_elems[dim]++;
+    
+    result = mbImpl->tag_set_data(gid_tag, entities[dim], &num_elements[0]); 
+    RRA("Failed to set global id tag in assign_global_ids.");
+  }
+  
+  return MB_SUCCESS;
+}
+
+int ParallelComm::get_buffers(int to_proc, bool *is_new) 
+{
+  int ind = -1;
+  std::vector<unsigned int>::iterator vit = 
+    std::find(buffProcs.begin(), buffProcs.end(), to_proc);
+  if (vit == buffProcs.end()) {
+    ind = buffProcs.size();
+    buffProcs.push_back((unsigned int)to_proc);
+    localOwnedBuffs.push_back(new Buffer(INITIAL_BUFF_SIZE));
+    remoteOwnedBuffs.push_back(new Buffer(INITIAL_BUFF_SIZE));
+    if (is_new) *is_new = true;
+  }
+  else {
+    ind = vit - buffProcs.begin();
+    if (is_new) *is_new = false;
+  }
+  assert(ind < MAX_SHARING_PROCS);
+  return ind;
+}
+
+ErrorCode ParallelComm::broadcast_entities( const int from_proc,
+                                                Range &entities,
+                                                const bool adjacencies,
+                                                const bool tags) 
+{
+#ifndef USE_MPI
+  return MB_FAILURE;
+#else
+  
+  ErrorCode result = MB_SUCCESS;
+  int success;
+  int buff_size;
+
+  Buffer buff(INITIAL_BUFF_SIZE);
+  buff.reset_ptr(sizeof(int));
+  if ((int)procConfig.proc_rank() == from_proc) {
+    result = add_verts(entities);
+    RRA("Failed to add adj vertices.");
+
+    buff.reset_ptr(sizeof(int));
+    result = pack_buffer( entities, adjacencies, tags, 
+                          false, -1, &buff); 
+    RRA("Failed to compute buffer size in broadcast_entities.");
+    buff.set_stored_size();
+    buff_size = buff.buff_ptr - buff.mem_ptr;
+  }
+
+  success = MPI_Bcast( &buff_size, 1, MPI_INT, from_proc, procConfig.proc_comm() );
+  if (MPI_SUCCESS != success) {
+    result = MB_FAILURE;
+    RRA("MPI_Bcast of buffer size failed.");
+  }
+  
+  if (!buff_size) // no data
+    return MB_SUCCESS;
+
+  if ((int)procConfig.proc_rank() != from_proc) 
+    buff.reserve(buff_size);
+
+  size_t offset = 0;
+  while (buff_size) {
+    int size = std::min( buff_size, MAX_BCAST_SIZE );
+    success = MPI_Bcast(buff.mem_ptr+offset, size, MPI_UNSIGNED_CHAR, from_proc, procConfig.proc_comm() );
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("MPI_Bcast of buffer failed.");
+    }
+    
+    offset += size;
+    buff_size -= size;
+  }
+
+  if ((int)procConfig.proc_rank() != from_proc) {
+    std::vector<std::vector<EntityHandle> > dum1a, dum1b;
+    std::vector<std::vector<int> > dum1p;
+    std::vector<EntityHandle> dum2;
+    std::vector<unsigned int> dum3;
+    buff.reset_ptr(sizeof(int));
+    result = unpack_buffer(buff.buff_ptr, false, from_proc, -1, 
+                           dum1a, dum1b, dum1p, dum2, dum2, dum3, entities);
+    RRA("Failed to unpack buffer in broadcast_entities.");
+  }
+
+  return MB_SUCCESS;
+#endif
+}
+
+ErrorCode ParallelComm::pack_buffer(Range &orig_ents, 
+                                        const bool adjacencies,
+                                        const bool tags,
+                                        const bool store_remote_handles,
+                                        const int to_proc,
+                                        Buffer *buff) 
+{
+    // pack the buffer with the entity ranges, adjacencies, and tags sections
+    // 
+    // Note: new entities used in subsequent connectivity lists, sets, or tags, 
+    //   are referred to as (MBMAXTYPE + index), where index is into vector 
+    //   of new entities, 0-based
+  ErrorCode result;
+
+  Range set_range;
+  std::vector<Range> set_ranges;
+  std::vector<Tag> all_tags;
+  std::vector<Range> tag_ranges;
+  std::vector<int> set_sizes;
+  std::vector<unsigned int> options_vec;
+
+  Range::const_iterator rit;
+
+    // entities
+  result = pack_entities(orig_ents, buff,
+                         store_remote_handles, to_proc, false); 
+  RRA("Packing entities failed.");
+  
+    // sets
+  result = pack_sets(orig_ents, buff,
+                     store_remote_handles, to_proc); 
+  RRA("Packing sets (count) failed.");
+
+    // tags
+  Range final_ents;
+  if (tags) {
+    result = get_tag_send_list(orig_ents, all_tags, tag_ranges );
+    RRA("Failed to get tagged entities.");
+    result = pack_tags(orig_ents, all_tags, all_tags, tag_ranges, 
+                       buff, store_remote_handles, to_proc);
+    RRA("Packing tags (count) failed.");
+  }
+
+  return result;
+}
+ 
+ErrorCode ParallelComm::unpack_buffer(unsigned char *buff_ptr,
+                                          const bool store_remote_handles,
+                                          const int from_proc,
+                                          const int ind,
+                                          std::vector<std::vector<EntityHandle> > &L1hloc,
+                                          std::vector<std::vector<EntityHandle> > &L1hrem,
+                                          std::vector<std::vector<int> > &L1p,
+                                          std::vector<EntityHandle> &L2hloc, 
+                                          std::vector<EntityHandle> &L2hrem,
+                                          std::vector<unsigned int> &L2p,
+                                          Range &new_ents) 
+{
+#ifdef DEBUG_PACKING
+    unsigned char *tmp_buff = buff_ptr;
+#endif  
+    ErrorCode result;
+    result = unpack_entities(buff_ptr, store_remote_handles,
+                             ind, false, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents);
+  RRA("Unpacking entities failed.");
+#ifdef DEBUG_PACKING
+    std::cerr << "unpack_entities buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
+    tmp_buff = buff_ptr;
+#endif  
+  result = unpack_sets(buff_ptr, new_ents, store_remote_handles, from_proc);
+  RRA("Unpacking sets failed.");
+#ifdef DEBUG_PACKING
+    std::cerr << "unpack_sets buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
+    tmp_buff = buff_ptr;
+#endif  
+  result = unpack_tags(buff_ptr, new_ents, store_remote_handles, from_proc);
+  RRA("Unpacking tags failed.");
+#ifdef DEBUG_PACKING
+    std::cerr << "unpack_tags buffer space: " << buff_ptr - tmp_buff << " bytes." << std::endl;
+    tmp_buff = buff_ptr;
+#endif  
+
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl;
+#endif
+  
+  return MB_SUCCESS;
+}
+
+int ParallelComm::num_subranges(const Range &this_range)
+{
+    // ok, have all the ranges we'll pack; count the subranges
+  int num_sub_ranges = 0;
+  for (Range::const_pair_iterator pit = this_range.const_pair_begin(); 
+       pit != this_range.const_pair_end(); pit++)
+    num_sub_ranges++;
+
+  return num_sub_ranges;
+}
+
+int ParallelComm::estimate_ents_buffer_size(Range &entities,
+                                              const bool store_remote_handles) 
+{
+  int buff_size = 0;
+  std::vector<EntityHandle> dum_connect_vec;
+  const EntityHandle *connect;
+  int num_connect;
+
+  int num_verts = entities.num_of_type(MBVERTEX);
+    // # verts + coords + handles
+  buff_size += 2*sizeof(int) + 3*sizeof(double)*num_verts;
+  if (store_remote_handles) buff_size += sizeof(EntityHandle)*num_verts;
+
+    // do a rough count by looking at first entity of each type
+  for (EntityType t = MBEDGE; t < MBENTITYSET; t++) {
+    const Range::iterator rit = entities.lower_bound(t);
+    if (TYPE_FROM_HANDLE(*rit) != t) continue;
+    
+    ErrorCode result = mbImpl->get_connectivity(*rit, connect, num_connect, 
+                                                  true, &dum_connect_vec);
+    RRA("Failed to get connectivity to estimate buffer size.");
+
+      // number, type, nodes per entity
+    buff_size += 3*sizeof(int);
+    int num_ents = entities.num_of_type(t);
+      // connectivity, handle for each ent
+    buff_size += (num_connect+1)*sizeof(EntityHandle)*num_ents;
+  }
+
+      // extra entity type at end, passed as int
+  buff_size += sizeof(int);
+
+  return buff_size;
+}
+
+int ParallelComm::estimate_sets_buffer_size(Range &entities,
+                                              const bool store_remote_handles) 
+{
+    // number of sets
+  int buff_size = sizeof(int);
+  
+    // do a rough count by looking at first entity of each type
+  Range::iterator rit = entities.lower_bound(MBENTITYSET);
+  ErrorCode result;
+  
+  for (; rit != entities.end(); rit++) {
+    unsigned int options;
+    result = mbImpl->get_meshset_options(*rit, options);
+    RRA("Failed to get meshset options.");
+
+    buff_size += sizeof(int);
+    
+    Range set_range;
+    if (options & MESHSET_SET) {
+        // range-based set; count the subranges
+      result = mbImpl->get_entities_by_handle(*rit, set_range);
+      RRA("Failed to get set entities.");
+
+        // set range
+      buff_size += RANGE_SIZE(set_range);
+    }
+    else if (options & MESHSET_ORDERED) {
+        // just get the number of entities in the set
+      int num_ents;
+      result = mbImpl->get_number_entities_by_handle(*rit, num_ents);
+      RRA("Failed to get number entities in ordered set.");
+
+        // set vec
+      buff_size += sizeof(EntityHandle) * num_ents + sizeof(int);
+    }
+
+      // get numbers of parents/children
+    int num_par, num_ch;
+    result = mbImpl->num_child_meshsets(*rit, &num_ch);
+    RRA("Failed to get num children.");
+
+    result = mbImpl->num_parent_meshsets(*rit, &num_par);
+    RRA("Failed to get num parents.");
+
+    buff_size += (num_ch + num_par) * sizeof(EntityHandle) + 2*sizeof(int);
+  }
+
+  return buff_size;
+}
+
+ErrorCode ParallelComm::pack_entities(Range &entities,
+                                          Buffer *buff,
+                                          const bool store_remote_handles,
+                                          const int to_proc,
+                                          const bool is_iface,
+                                          std::vector<std::set<unsigned int> > *entprocs,
+                                          Range *allsent) 
+{
+    // packed information:
+    // 1. # entities = E
+    // 2. for e in E
+    //   a. # procs sharing e, incl. sender and receiver = P
+    //   b. for p in P (procs sharing e)
+    //   c. for p in P (handle for e on p) (Note1)
+    // 3. vertex/entity info
+
+    // get an estimate of the buffer size & pre-allocate buffer size
+  unsigned int buff_size = estimate_ents_buffer_size(entities, 
+                                                     store_remote_handles);
+  buff->check_space(buff_size);
+  
+  WriteUtilIface *wu;
+  ErrorCode result = mbImpl->query_interface(std::string("WriteUtilIface"), 
+                                               reinterpret_cast<void**>(&wu));
+  RRA("Couldn't get WriteUtilIface.");
+
+  unsigned int num_ents;
+
+    // first pack procs/handles sharing this ent, not including this dest but including
+    // others (with zero handles)
+  if (store_remote_handles) {
+
+      // buff space is at least proc+handle for each entity; use avg of 4 other procs
+      // to estimate buff size, but check later
+    buff->check_space(sizeof(int) + (5*sizeof(int) + sizeof(EntityHandle))*entities.size());
+
+      // 1. # entities = E
+    PACK_INT(buff->buff_ptr, entities.size());
+  
+    Range::iterator rit;
+  
+      // pre-fetch sharedp and pstatus
+    std::vector<int> sharedp_vals(entities.size());
+    result = mbImpl->tag_get_data(sharedp_tag(), entities, &sharedp_vals[0]);
+    RRA("Failed to get sharedp_tag.");
+    std::vector<char> pstatus_vals(entities.size());
+    result = mbImpl->tag_get_data(pstatus_tag(), entities, &pstatus_vals[0]);
+    RRA("Failed to get sharedp_tag.");
+  
+    unsigned int i;
+    std::vector<std::set<unsigned int> >::iterator vit;
+    int tmp_procs[MAX_SHARING_PROCS];
+    EntityHandle tmp_handles[MAX_SHARING_PROCS];
+    std::set<unsigned int> dumprocs;
+
+      // 2. for e in E
+    for (rit = entities.begin(), i = 0; 
+         rit != entities.end(); rit++, i++) {
+      result = build_sharedhps_list(*rit, pstatus_vals[i], sharedp_vals[i],
+                                    (entprocs ? (*entprocs)[allsent->index(*rit)] : dumprocs),
+                                    num_ents, tmp_procs, tmp_handles);
+      RRA("Failed to build sharedhps.");
+
+        // now pack them
+      buff->check_space((num_ents+1)*sizeof(int) + 
+                       num_ents*sizeof(EntityHandle));
+      PACK_INT(buff->buff_ptr, num_ents);
+      PACK_INTS(buff->buff_ptr, tmp_procs, num_ents);
+      PACK_EH(buff->buff_ptr, tmp_handles, num_ents);
+
+#ifndef NDEBUG
+        // check for duplicates in proc list
+      unsigned int dp = 0;
+      for (; dp < MAX_SHARING_PROCS && -1 != tmp_procs[dp]; dp++)
+        dumprocs.insert(tmp_procs[dp]);
+      assert(dumprocs.size() == dp);
+      dumprocs.clear();
+#endif      
+    }
+  }
+  
+    // pack vertices
+  Range these_ents = entities.subset_by_type(MBVERTEX);
+  num_ents = these_ents.size();
+
+  if (num_ents) {
+    buff_size = 2*sizeof(int) + 3*num_ents*sizeof(double);
+    buff->check_space(buff_size);
+
+    // type, # ents
+    PACK_INT(buff->buff_ptr, ((int) MBVERTEX));
+    PACK_INT(buff->buff_ptr, ((int) num_ents));
+
+    result = mbImpl->get_coords(these_ents, (double*)buff->buff_ptr);
+    RRA("Couldn't get vertex coordinates.");
+    PC(3*num_ents, " doubles");
+
+    buff->buff_ptr += 3 * num_ents * sizeof(double);
+
+#ifdef DEBUG_PACKING
+  std::cerr << "Packed " << these_ents.size() << " ents of type " 
+            << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*these_ents.begin())) << std::endl;
+#endif      
+  }
+
+    // now entities; go through range, packing by type and equal # verts per element
+  Range::iterator start_rit = entities.find(*these_ents.rbegin());
+  start_rit++;
+  int last_nodes = -1;
+  EntityType last_type = MBMAXTYPE;
+  these_ents.clear();
+  Range::iterator end_rit = start_rit;
+  EntitySequence *seq;
+  ElementSequence *eseq;
+  
+  while (start_rit != entities.end() || !these_ents.empty()) {
+      // cases:
+      // A: !end, last_type == MBMAXTYPE, seq: save contig sequence in these_ents
+      // B: !end, last type & nodes same, seq: save contig sequence in these_ents
+      // C: !end, last type & nodes different: pack these_ents, then save contig sequence in these_ents
+      // D: end: pack these_ents
+
+      // find the sequence holding current start entity, if we're not at end
+    eseq = NULL;
+    if (start_rit != entities.end()) {
+      result = sequenceManager->find(*start_rit, seq);
+      RRA("Couldn't find entity sequence.");
+      if (NULL == seq) return MB_FAILURE;
+      eseq = dynamic_cast<ElementSequence*>(seq);
+    }
+
+      // pack the last batch if at end or next one is different
+    if (!these_ents.empty() &&
+        (!eseq || eseq->type() != last_type ||
+         last_nodes != (int) eseq->nodes_per_element())) {
+      result = pack_entity_seq(last_nodes, store_remote_handles,
+                               to_proc, these_ents, entities, buff);
+      RRA("Failed to pack entities from a sequence.");
+      these_ents.clear();
+    }
+
+    if (eseq) {
+        // continuation of current range, just save these entities
+        // get position in entities list one past end of this sequence
+      end_rit = entities.lower_bound(start_rit, entities.end(), eseq->end_handle()+1);
+
+        // put these entities in the range
+      std::copy(start_rit, end_rit, range_inserter(these_ents));
+
+      last_type = eseq->type();
+      last_nodes = eseq->nodes_per_element();
+    }
+    else if (start_rit != entities.end() &&
+             TYPE_FROM_HANDLE(*start_rit) == MBENTITYSET)
+      break;
+
+    start_rit = end_rit;
+  }
+
+    // pack MBMAXTYPE to indicate end of ranges
+  buff->check_space(sizeof(int));
+  PACK_INT(buff->buff_ptr, ((int)MBMAXTYPE));
+
+  buff->set_stored_size();
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::build_sharedhps_list(const EntityHandle entity,
+                                                 const unsigned char pstatus,
+                                                 const int sharedp, 
+                                                 const std::set<unsigned int> &entprocs,
+                                                 unsigned int &num_ents,
+                                                 int *tmp_procs,
+                                                 EntityHandle *tmp_handles)
+{
+  num_ents = 0;
+  unsigned char pstat;
+  ErrorCode result = get_sharing_data(entity, tmp_procs, tmp_handles,
+                                        pstat, num_ents);
+  RRA("Failed in get_sharing_data.");
+  assert(pstat == pstatus);
+  
+    // build shared proc/handle lists
+    // start with multi-shared, since if it is the owner will be first
+  if (pstatus & PSTATUS_MULTISHARED) {
+  }
+  else if (pstatus & PSTATUS_NOT_OWNED) {
+      // if not multishared and not owned, other sharing proc is owner, put that
+      // one first
+    assert("If not owned, I should be shared too" &&
+           pstatus & PSTATUS_SHARED &&
+           num_ents == 1);
+    tmp_procs[1] = procConfig.proc_rank();
+    tmp_handles[1] = entity;
+    num_ents = 2;
+  }
+  else if (pstatus & PSTATUS_SHARED) {
+      // if not multishared and owned, I'm owner
+    assert("shared and owned, should be only 1 sharing proc" &&
+           1 == num_ents);
+    tmp_procs[1] = tmp_procs[0];
+    tmp_procs[0] = procConfig.proc_rank();
+    tmp_handles[1] = tmp_handles[0];
+    tmp_handles[0] = entity;
+    num_ents = 2;
+  }
+  else {
+      // not shared yet, just add owner (me)
+    tmp_procs[0] = procConfig.proc_rank();
+    tmp_handles[0] = entity;
+    num_ents = 1;
+  }
+
+#ifndef NDEBUG
+  int tmp_ps = num_ents;
+#endif
+  
+    // now add others, with zero handle for now
+  for (std::set<unsigned int>::iterator sit = entprocs.begin();
+       sit != entprocs.end(); sit++) {
+    assert("these procs shouldn't already be in the shared list" &&
+           std::find(tmp_procs, tmp_procs+tmp_ps, *sit) == tmp_procs+tmp_ps);
+    tmp_procs[num_ents] = *sit;
+    tmp_handles[num_ents] = 0;
+    num_ents++;
+  }
+
+    // put -1 after procs and 0 after handles
+  if (MAX_SHARING_PROCS > num_ents) {
+    tmp_procs[num_ents] = -1;
+    tmp_handles[num_ents] = 0;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::pack_entity_seq(const int nodes_per_entity,
+                                            const bool store_remote_handles,
+                                            const int to_proc,
+                                            Range &these_ents,
+                                            Range &entities,
+                                            Buffer *buff) 
+{
+  int tmp_space = 3*sizeof(int) + nodes_per_entity*these_ents.size()*sizeof(EntityHandle);
+  buff->check_space(tmp_space);
+  
+    // pack the entity type
+  PACK_INT(buff->buff_ptr, ((int)TYPE_FROM_HANDLE(*these_ents.begin())));
+
+    // pack # ents
+  PACK_INT(buff->buff_ptr, these_ents.size());
+      
+    // pack the nodes per entity
+  PACK_INT(buff->buff_ptr, nodes_per_entity);
+      
+    // pack the connectivity
+  const EntityHandle *connect;
+  int num_connect;
+  std::vector<EntityHandle> dum_connect;
+  EntityHandle *start_vec = (EntityHandle*)buff->buff_ptr;
+  ErrorCode result = MB_SUCCESS;
+  for (Range::const_iterator rit = these_ents.begin(); rit != these_ents.end(); rit++) {
+    result = mbImpl->get_connectivity(*rit, connect, num_connect, false,
+                                      &dum_connect);
+    RRA("Failed to get connectivity.");
+    assert(num_connect == nodes_per_entity);
+    PACK_EH(buff->buff_ptr, connect, num_connect);
+  }
+
+    // substitute destination handles
+  result = get_remote_handles(store_remote_handles, start_vec, start_vec,
+                              nodes_per_entity*these_ents.size(), to_proc,
+                              entities);
+  RRA("Trouble getting remote handles when packing entities.");
+
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Packed " << these_ents.size() << " ents of type " 
+            << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*these_ents.begin())) << std::endl;
+#endif      
+
+  return result;
+}
+
+
+ErrorCode ParallelComm::get_remote_handles(const bool store_remote_handles,
+                                               EntityHandle *from_vec, 
+                                               EntityHandle *to_vec_tmp,
+                                               int num_ents, int to_proc,
+                                               const Range &new_ents) 
+{
+    // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE RANGE-BASED VERSION, NO REUSE
+    // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE
+    // OTHER VERSION TOO!!!
+  if (0 == num_ents) return MB_SUCCESS;
+  
+    // use a local destination ptr in case we're doing an in-place copy
+  std::vector<EntityHandle> tmp_vector;
+  EntityHandle *to_vec = to_vec_tmp;
+  if (to_vec == from_vec) {
+    tmp_vector.resize(num_ents);
+    to_vec = &tmp_vector[0];
+  }
+
+  if (!store_remote_handles) {
+    int err;
+      // in this case, substitute position in new_ents list
+    for (int i = 0; i < num_ents; i++) {
+      int ind = new_ents.index(from_vec[i]);
+      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err);
+      assert(to_vec[i] != 0 && !err && -1 != ind);
+    }
+  }
+  else {
+    Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+    ErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
+                                              sharedh_tag, sharedhs_tag, pstatus_tag);
+  
+      // get single-proc destination handles and shared procs
+    std::vector<int> sharing_procs(num_ents);
+    result = mbImpl->tag_get_data(sharedh_tag, from_vec, num_ents,
+                                  to_vec);
+    RRA("Failed to get shared handle tag for remote_handles.");
+    result = mbImpl->tag_get_data(sharedp_tag, from_vec, num_ents, &sharing_procs[0]);
+    RRA("Failed to get sharing proc tag in remote_handles.");
+    for (int j = 0; j < num_ents; j++) {
+      if (to_vec[j] && sharing_procs[j] != to_proc)
+        to_vec[j] = 0;
+    }
+    
+    EntityHandle tmp_handles[MAX_SHARING_PROCS];
+    int tmp_procs[MAX_SHARING_PROCS];
+    int i;
+      // go through results, and for 0-valued ones, look for multiple shared proc
+    EntityHandle *tmp_eh;
+    for (tmp_eh = to_vec, i = 0; i < num_ents; i++) {
+      if (!to_vec[i]) {
+        result = mbImpl->tag_get_data(sharedps_tag, from_vec+i, 1, tmp_procs);
+        if (MB_SUCCESS == result) {
+          for (int j = 0; j < MAX_SHARING_PROCS; j++) {
+            if (-1 == tmp_procs[j]) break;
+            else if (tmp_procs[j] == to_proc) {
+              result = mbImpl->tag_get_data(sharedhs_tag, from_vec+i, 1, tmp_handles);
+              RRA("Trouble getting sharedhs tag.");
+              to_vec[i] = tmp_handles[j];
+              assert(to_vec[i]);
+              break;
+            }
+          }
+        }
+        if (!to_vec[i]) {
+          int j = new_ents.index(from_vec[i]);
+          if (-1 == j) {
+            result = MB_FAILURE;
+            RRA("Failed to find new entity in send list.");
+          }
+          int err;
+          to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err);
+          if (err) {
+            result = MB_FAILURE;
+            RRA("Failed to create handle in remote_handles.");
+          }
+        }
+      }
+    }
+  }
+  
+    // memcpy over results if from_vec and to_vec are the same
+  if (to_vec_tmp == from_vec) 
+    memcpy(from_vec, to_vec, num_ents * sizeof(EntityHandle));
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_remote_handles(const bool store_remote_handles,
+                                               const Range &from_range, 
+                                               EntityHandle *to_vec,
+                                               int to_proc,
+                                               const Range &new_ents) 
+{
+    // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE VECTOR-BASED VERSION, NO REUSE
+    // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE
+    // OTHER VERSION TOO!!!
+  if (from_range.empty()) return MB_SUCCESS;
+  
+  if (!store_remote_handles) {
+    int err;
+      // in this case, substitute position in new_ents list
+    Range::iterator rit;
+    unsigned int i;
+    for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) {
+      int ind = new_ents.index(*rit);
+      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err);
+      assert(to_vec[i] != 0 && !err && -1 != ind);
+    }
+  }
+  else {
+    Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+    ErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
+                                              sharedh_tag, sharedhs_tag, pstatus_tag);
+  
+      // get single-proc destination handles and shared procs
+    std::vector<int> sharing_procs(from_range.size());
+    result = mbImpl->tag_get_data(sharedh_tag, from_range, to_vec);
+    RRA("Failed to get shared handle tag for remote_handles.");
+    result = mbImpl->tag_get_data(sharedp_tag, from_range, &sharing_procs[0]);
+    RRA("Failed to get sharing proc tag in remote_handles.");
+    for (unsigned int j = 0; j < from_range.size(); j++) {
+      if (to_vec[j] && sharing_procs[j] != to_proc)
+        to_vec[j] = 0;
+    }
+    
+    EntityHandle tmp_handles[MAX_SHARING_PROCS];
+    int tmp_procs[MAX_SHARING_PROCS];
+      // go through results, and for 0-valued ones, look for multiple shared proc
+    Range::iterator rit;
+    unsigned int i;
+    for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) {
+      if (!to_vec[i]) {
+        result = mbImpl->tag_get_data(sharedhs_tag, &(*rit), 1, tmp_handles);
+        if (MB_SUCCESS == result) {
+          result = mbImpl->tag_get_data(sharedps_tag, &(*rit), 1, tmp_procs);
+          RRA("Trouble getting sharedps tag.");
+          for (int j = 0; j < MAX_SHARING_PROCS; j++)
+            if (tmp_procs[j] == to_proc) {
+              to_vec[i] = tmp_handles[j];
+              break;
+            }
+        }
+      
+        if (!to_vec[i]) {
+          int j = new_ents.index(*rit);
+          if (-1 == j) {
+            result = MB_FAILURE;
+            RRA("Failed to find new entity in send list.");
+          }
+          int err;
+          to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err);
+          if (err) {
+            result = MB_FAILURE;
+            RRA("Failed to create handle in remote_handles.");
+          }
+        }
+      }
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_remote_handles(const bool store_remote_handles,
+                                               const Range &from_range, 
+                                               Range &to_range,
+                                               int to_proc,
+                                               const Range &new_ents) 
+{
+  std::vector<EntityHandle> to_vector(from_range.size());
+
+  ErrorCode result =
+    get_remote_handles(store_remote_handles, from_range, &to_vector[0],
+                       to_proc, new_ents);
+  RRA("Trouble getting remote handles.");
+  std::copy(to_vector.begin(), to_vector.end(), range_inserter(to_range));
+  return result;
+}
+
+ErrorCode ParallelComm::unpack_entities(unsigned char *&buff_ptr,
+                                            const bool store_remote_handles,
+                                            const int from_ind,
+                                            const bool is_iface,
+                                            std::vector<std::vector<EntityHandle> > &L1hloc,
+                                            std::vector<std::vector<EntityHandle> > &L1hrem,
+                                            std::vector<std::vector<int> > &L1p,
+                                            std::vector<EntityHandle> &L2hloc, 
+                                            std::vector<EntityHandle> &L2hrem,
+                                            std::vector<unsigned int> &L2p,
+                                            Range &new_ents) 
+{
+    // general algorithm:
+    // - unpack # entities
+    // - save start of remote handle info, then scan forward to entity definition data
+    // - for all vertices or entities w/ same # verts:
+    //   . get entity type, num ents, and (if !vert) # verts 
+    //   . for each ent:
+    //      o get # procs/handles in remote handle info
+    //      o if # procs/handles > 2, check for already-created entity:
+    //        x get index of owner proc (1st in proc list), resize L1 list if nec
+    //        x look for already-arrived entity in L2 by owner handle
+    //      o if no existing entity:
+    //        x if iface, look for existing entity with same connect & type
+    //        x if none found, create vertex or element
+    //        x if !iface & multi-shared, save on L2
+    //        x if !iface, put new entity on new_ents list
+    //      o update proc/handle, pstatus tags, adjusting to put owner first if iface
+    //      o if !iface, save new handle on L1 for all sharing procs
+
+    // lists of handles/procs to return to sending/other procs
+    // L1hloc[p], L1hrem[p]: handle pairs [h, h'], where h is the local proc handle
+    //         and h' is either the remote proc handle (if that is known) or
+    //         the owner proc handle (otherwise);
+    // L1p[p]: indicates whether h is remote handle (= -1) or owner (rank of owner)
+    // L2hloc, L2hrem: local/remote handles for entities shared by > 2 procs;
+    //         remote handles are on owning proc
+    // L2p: owning procs for handles in L2hrem
+
+  ErrorCode result;
+  bool done = false;
+  ReadUtilIface *ru = NULL;
+
+  result = mbImpl->query_interface(std::string("ReadUtilIface"), 
+                                   reinterpret_cast<void**>(&ru));
+  RRA("Failed to get ReadUtilIface.");
+
+    // procs the sending proc is telling me I'll be receiving from
+  std::set<unsigned int> comm_procs;
+
+    // 1. # entities = E
+  int num_ents;
+  unsigned char *buff_save = buff_ptr;
+  int i, j;
+
+  if (store_remote_handles) {
+    UNPACK_INT(buff_ptr, num_ents);
+
+    buff_save = buff_ptr;
+    
+      // save place where remote handle info starts, then scan forward to ents
+    for (i = 0; i < num_ents; i++) {
+      UNPACK_INT(buff_ptr, j);
+      if (j < 0) {
+        std::cout << "Should be non-negative # proc/handles.";
+        return MB_FAILURE;
+      }
+      
+      buff_ptr += j * (sizeof(int)+sizeof(EntityHandle));
+    }
+  }
+
+  std::vector<EntityHandle> msg_ents;
+  
+  while (!done) {
+    EntityType this_type = MBMAXTYPE;
+    UNPACK_TYPE(buff_ptr, this_type);
+    assert(this_type != MBENTITYSET);
+
+      // MBMAXTYPE signifies end of entities data
+    if (MBMAXTYPE == this_type) break;
+
+    assert(!is_iface || this_type != MBVERTEX);
+    
+      // get the number of ents
+    int num_ents2, verts_per_entity;
+    UNPACK_INT(buff_ptr, num_ents2);
+
+      // unpack the nodes per entity
+    if (MBVERTEX != this_type && num_ents2) {
+      UNPACK_INT(buff_ptr, verts_per_entity);
+    }
+      
+    std::vector<int> ps(MAX_SHARING_PROCS, -1);
+    std::vector<EntityHandle> hs(MAX_SHARING_PROCS, 0);
+    for (int e = 0; e < num_ents2; e++) {
+        // check for existing entity, otherwise make new one
+      EntityHandle new_h = 0;
+
+      EntityHandle *connect;
+      double *coords;
+      int num_ps = -1;
+
+        //=======================================
+        // unpack all the data at once, to make sure the buffer pointers
+        // are tracked correctly
+        //=======================================
+      if (store_remote_handles) {
+          // pointers to other procs/handles
+        UNPACK_INT(buff_save, num_ps);
+        if (0 >= num_ps) {
+          std::cout << "Shouldn't ever be fewer than 1 procs here." << std::endl;
+          return MB_FAILURE;
+        }
+        
+        UNPACK_INTS(buff_save, &ps[0], num_ps);
+        UNPACK_EH(buff_save, &hs[0], num_ps);
+      }
+
+      if (MBVERTEX == this_type) {
+        coords = (double*) buff_ptr;
+        buff_ptr += 3*sizeof(double);
+      }
+      else {
+        connect = (EntityHandle*) buff_ptr;
+        buff_ptr += verts_per_entity * sizeof(EntityHandle);
+
+          // update connectivity to local handles
+        result = get_local_handles(connect, verts_per_entity, msg_ents);
+        RRA("Couldn't get local handles.");
+      }
+
+        //=======================================
+        // now, process that data; begin by finding an identical 
+        // entity, if there is one
+        //=======================================
+      if (store_remote_handles) {
+        result = find_existing_entity(is_iface, ps[0], hs[0], num_ps, 
+                                      connect, verts_per_entity,
+                                      this_type,
+                                      L2hloc, L2hrem, L2p,
+                                      new_h);
+        RRA("Trouble getting existing entity.");
+      }
+
+        //=======================================
+        // if we didn't find one, we'll have to create one
+        //=======================================
+      bool created_here = false;
+      if (!new_h && !is_iface) {
+        
+        if (MBVERTEX == this_type) {
+            // create a vertex
+          result = mbImpl->create_vertex(coords, new_h);
+          RRA("Couldn't make new vertex.");
+        }
+        else {
+            // create the element
+          result = mbImpl->create_element(this_type, connect, verts_per_entity, new_h);
+          RRA("Couldn't make new vertex.");
+
+            // update adjacencies
+          result = ru->update_adjacencies(new_h, 1, 
+                                          verts_per_entity, connect);
+          RRA("Failed to update adjacencies.");
+        }
+
+          // should have a new handle now
+        assert(new_h);
+        
+          // if a new multi-shared entity, save owner for subsequent lookup in L2 lists
+        if (store_remote_handles && !is_iface && num_ps > 2) {
+          L2hrem.push_back(hs[0]);
+          L2hloc.push_back(new_h);
+          L2p.push_back(ps[0]);
+        }
+
+        created_here = true;
+      }
+
+        //=======================================
+        // take care of sharing data
+        //=======================================
+
+        // need to save entities found in order, for interpretation of
+        // later parts of this message
+      if (!is_iface) {
+        assert(new_h);
+        msg_ents.push_back(new_h);
+      }
+
+      if (created_here) new_ents.insert(new_h);
+
+      if (new_h && store_remote_handles) {
+        
+          // update sharing data and pstatus, adjusting order if iface
+        result = update_remote_data(new_h, &ps[0], &hs[0], num_ps, 
+                                    (is_iface ? PSTATUS_INTERFACE :
+                                     (created_here ? (PSTATUS_GHOST | PSTATUS_NOT_OWNED) : 0)));
+        RRA("");
+
+          // need to send this new handle to all sharing procs
+        if (!is_iface) {
+          for (j = 0; j < num_ps; j++) {
+            if (ps[j] == (int)procConfig.proc_rank()) continue;
+            int idx = get_buffers(ps[j]);
+            if (idx == (int)L1hloc.size()) {
+              L1hloc.resize(idx+1);
+              L1hrem.resize(idx+1);
+              L1p.resize(idx+1);
+            }
+            
+              // don't bother adding if it's already in the list
+            std::vector<EntityHandle>::iterator vit = 
+                std::find(L1hloc[idx].begin(), L1hloc[idx].end(), new_h);
+            if (vit != L1hloc[idx].end()) {
+                // if it's in the list but remote handle isn't known but we know
+                // it, replace in the list
+              if (L1p[idx][vit-L1hloc[idx].begin()] != -1 && hs[j]) {
+                L1hrem[idx][vit-L1hloc[idx].begin()] = hs[j];
+                L1p[idx][vit-L1hloc[idx].begin()] = -1;
+              }
+              else continue;
+            }
+            else {
+              if (!hs[j]) {
+                assert(-1 != ps[0] && num_ps > 2);
+                L1p[idx].push_back(ps[0]);
+                L1hrem[idx].push_back(hs[0]);
+              }
+              else {
+                assert("either this remote handle isn't in the remote list, or it's for another proc" &&
+                       (std::find(L1hrem[idx].begin(), L1hrem[idx].end(), hs[j]) == 
+                        L1hrem[idx].end() ||
+                        L1p[idx][std::find(L1hrem[idx].begin(), L1hrem[idx].end(), hs[j]) - 
+                                 L1hrem[idx].begin()] != -1));
+                L1p[idx].push_back(-1);
+                L1hrem[idx].push_back(hs[j]);
+              }
+              L1hloc[idx].push_back(new_h);
+            }
+          }
+        }
+
+        assert("Shouldn't be here for non-shared entities" &&
+               -1 != num_ps);
+        std::fill(&ps[0], &ps[num_ps], -1);
+        std::fill(&hs[0], &hs[num_ps], 0);
+      }
+    }
+    
+    
+#ifdef DEBUG_PACKING
+      std::cerr << "Unpacked " << num_ents << " ents of type " 
+                << MBCN::EntityTypeName(TYPE_FROM_HANDLE(this_type)) << std::endl;
+#endif      
+
+  }
+
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Done unpacking entities." << std::endl;
+#endif
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::print_buffer(unsigned char *buff_ptr, 
+                                         int mesg_tag, 
+                                         int from_proc, bool sent) 
+{
+  std::cerr << procConfig.proc_rank();
+  if (sent) std::cerr << " sent";
+  else std::cerr << " received";
+  std::cerr << " message type " << mesg_tag 
+            << " to/from proc " << from_proc << "; contents:" << std::endl;
+
+  int msg_length, num_ents;
+  unsigned char *orig_ptr = buff_ptr;
+  UNPACK_INT(buff_ptr, msg_length);
+  std::cerr << msg_length << " bytes..." << std::endl;
+
+  if (MB_MESG_ENTS_SIZE == mesg_tag || MB_MESG_ENTS_LARGE == mesg_tag) {
+
+      // 1. # entities = E
+    int i, j, k;
+    std::vector<int> ps;
+    std::vector<EntityHandle> hs;
+
+    UNPACK_INT(buff_ptr, num_ents);
+    std::cerr << num_ents << " entities..." << std::endl;
+
+      // save place where remote handle info starts, then scan forward to ents
+    for (i = 0; i < num_ents; i++) {
+      UNPACK_INT(buff_ptr, j);
+      if (0 > j) return MB_FAILURE;
+      ps.resize(j);
+      hs.resize(j);
+      std::cerr << "Entity " << i << ", # procs = " << j << std::endl;
+      UNPACK_INTS(buff_ptr, &ps[0], j);
+      UNPACK_EH(buff_ptr, &hs[0], j);
+      std::cerr << "   Procs: ";
+      for (k = 0; k < j; k++) std::cerr << ps[k] << " ";
+      std::cerr << std::endl;
+      std::cerr << "   Handles: ";
+      for (k = 0; k < j; k++) std::cerr << hs[k] << " ";
+      std::cerr << std::endl;
+
+      if (buff_ptr-orig_ptr > msg_length) {
+        std::cerr << "End of buffer..." << std::endl;
+        std::cerr.flush();
+        return MB_FAILURE;
+      }
+    }
+  
+    while (true) {
+      EntityType this_type = MBMAXTYPE;
+      UNPACK_TYPE(buff_ptr, this_type);
+      assert(this_type != MBENTITYSET);
+
+        // MBMAXTYPE signifies end of entities data
+      if (MBMAXTYPE == this_type) break;
+
+        // get the number of ents
+      int num_ents2, verts_per_entity;
+      UNPACK_INT(buff_ptr, num_ents2);
+
+        // unpack the nodes per entity
+      if (MBVERTEX != this_type && num_ents2) {
+        UNPACK_INT(buff_ptr, verts_per_entity);
+      }
+
+      std::cerr << "Type: " << MBCN::EntityTypeName(this_type)
+                << "; num_ents = " << num_ents2;
+      if (MBVERTEX != this_type) std::cerr << "; verts_per_ent = " << verts_per_entity;
+      std::cerr << std::endl;
+      if (num_ents2 < 0 || num_ents2 > msg_length) {
+        std::cerr << "Wrong number of entities, returning." << std::endl;
+        return MB_FAILURE;
+      }
+    
+      for (int e = 0; e < num_ents2; e++) {
+          // check for existing entity, otherwise make new one
+        EntityHandle *connect;
+        double *coords;
+
+        if (MBVERTEX == this_type) {
+          coords = (double*) buff_ptr;
+          buff_ptr += 3*sizeof(double);
+          std::cerr << "xyz = " << coords[0] << ", " << coords[1] << ", " 
+                    << coords[2] << std::endl;
+        }
+        else {
+          connect = (EntityHandle*) buff_ptr;
+          buff_ptr += verts_per_entity * sizeof(EntityHandle);
+
+            // update connectivity to local handles
+          std::cerr << "Connectivity: ";
+          for (k = 0; k < verts_per_entity; k++) std::cerr << connect[k] << " ";
+          std::cerr << std::endl;
+        }
+
+        if (buff_ptr-orig_ptr > msg_length) {
+          std::cerr << "End of buffer..." << std::endl;
+          std::cerr.flush();
+          return MB_FAILURE;
+        }
+      }
+    }
+  }
+  
+  else if (MB_MESG_REMOTEH_SIZE == mesg_tag || MB_MESG_REMOTEH_LARGE == mesg_tag) {
+    UNPACK_INT(buff_ptr, num_ents);
+    std::cerr << num_ents << " entities..." << std::endl;
+    if (0 > num_ents || num_ents > msg_length) {
+      std::cerr << "Wrong number of entities, returning." << std::endl;
+      return MB_FAILURE;
+    }
+    std::vector<EntityHandle> L1hloc(num_ents), L1hrem(num_ents);
+    std::vector<int> L1p(num_ents);
+    UNPACK_INTS(buff_ptr, &L1p[0], num_ents);
+    UNPACK_EH(buff_ptr, &L1hrem[0], num_ents);
+    UNPACK_EH(buff_ptr, &L1hloc[0], num_ents);
+    std::cerr << num_ents << " Entity pairs; hremote/hlocal/proc: " << std::endl;
+    for (int i = 0; i < num_ents; i++) {
+      EntityType etype = TYPE_FROM_HANDLE(L1hloc[i]);
+      std::cerr << MBCN::EntityTypeName(etype) << ID_FROM_HANDLE(L1hrem[i])  << ", " 
+                << MBCN::EntityTypeName(etype) << ID_FROM_HANDLE(L1hloc[i])  << ", " 
+                << L1p[i] << std::endl;
+    }
+
+    if (buff_ptr-orig_ptr > msg_length) {
+      std::cerr << "End of buffer..." << std::endl;
+      std::cerr.flush();
+      return MB_FAILURE;
+    }
+
+  }
+  else if (mesg_tag == MB_MESG_TAGS_SIZE || mesg_tag == MB_MESG_TAGS_LARGE) {
+    int num_tags, dum1, num_ents, data_type, tag_size;
+    UNPACK_INT(buff_ptr, num_tags);
+    std::cerr << "Number of tags = " << num_tags << std::endl;
+    for (int i = 0; i < num_tags; i++) {
+      std::cerr << "Tag " << i << ":" << std::endl;
+      UNPACK_INT(buff_ptr, tag_size);
+      UNPACK_INT(buff_ptr, dum1);
+      UNPACK_INT(buff_ptr, data_type);
+      std::cerr << "Tag size, type, data type = " << tag_size << ", " 
+                << dum1 << ", " << data_type << std::endl;
+      UNPACK_INT(buff_ptr, dum1);
+      std::cerr << "Default value size = " << dum1 << std::endl;
+      buff_ptr += dum1;
+      UNPACK_INT(buff_ptr, dum1);
+      std::cerr << "Tag name = " << (char*) buff_ptr << std::endl;
+      buff_ptr += dum1;
+      UNPACK_INT(buff_ptr, num_ents);
+      std::cerr << "Number of ents = " << num_ents << std::endl;
+      unsigned char *tmp_buff = buff_ptr;
+      buff_ptr += num_ents*sizeof(EntityHandle);
+      int tot_length = 0;
+      for (int i = 0; i < num_ents; i++) {
+        EntityType etype = TYPE_FROM_HANDLE(*((EntityHandle*)tmp_buff));
+        std::cerr << MBCN::EntityTypeName(etype) << " " 
+                  << ID_FROM_HANDLE(*((EntityHandle*)tmp_buff))
+                  << ", tag = ";
+        if (tag_size == MB_VARIABLE_LENGTH) {
+          UNPACK_INT(buff_ptr, dum1);
+          tot_length += dum1;
+          std::cerr << "(variable, length = " << dum1 << ")" << std::endl;
+        }
+        else if (data_type == MB_TYPE_DOUBLE) std::cerr << *((double*)buff_ptr) << std::endl;
+        else if (data_type == MB_TYPE_INTEGER) std::cerr << *((int*)buff_ptr) << std::endl;
+        else if (data_type == MB_TYPE_OPAQUE) std::cerr << "(opaque)" << std::endl;
+        else if (data_type == MB_TYPE_HANDLE) 
+          std::cerr <<  (EntityHandle)*buff_ptr << std::endl;
+        else if (data_type == MB_TYPE_BIT) std::cerr << "(bit)" << std::endl;
+        tmp_buff += sizeof(EntityHandle);
+        buff_ptr += tag_size;
+      }
+
+      if (tag_size == MB_VARIABLE_LENGTH) buff_ptr += tot_length;
+    }
+  }
+  else {
+    assert(false);
+    return MB_FAILURE;
+  }
+
+  std::cerr.flush();
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::list_entities(const EntityHandle *ents, int num_ents) 
+{
+  if (NULL == ents && 0 == num_ents) {
+    sharedEnts.print("Shared entities:\n");
+    return MB_SUCCESS;
+  }
+  
+  else if (NULL == ents && 0 != num_ents) {
+    return list_entities(sharedEnts);
+  }
+    
+  unsigned char pstat;
+  EntityHandle tmp_handles[MAX_SHARING_PROCS];
+  int tmp_procs[MAX_SHARING_PROCS];
+  unsigned int num_ps;
+  ErrorCode result;
+
+  for (int i = 0; i < num_ents; i++) {
+    result = mbImpl->list_entities(ents+i, 1);
+
+    result = get_sharing_data(ents[i], tmp_procs, tmp_handles, pstat, num_ps);
+    RRA("Failed to get sharing data.");
+
+    std::cout << "Pstatus: ";
+    if (!num_ps)
+      std::cout << "local " << std::endl;
+    else {
+      if (pstat & PSTATUS_NOT_OWNED) std::cout << "NOT_OWNED; ";
+      if (pstat & PSTATUS_SHARED) std::cout << "SHARED; ";
+      if (pstat & PSTATUS_MULTISHARED) std::cout << "MULTISHARED; ";
+      if (pstat & PSTATUS_INTERFACE) std::cout << "INTERFACE; ";
+      if (pstat & PSTATUS_GHOST) std::cout << "GHOST; ";
+      std::cout << std::endl;
+      for (unsigned int j = 0; j < num_ps; j++) {
+        std::cout << "  proc " << tmp_procs[j] << " id (handle) " 
+                  << mbImpl->id_from_handle(tmp_handles[j]) 
+                  << "(" << tmp_handles[j] << ")" << std::endl;
+      }
+    }
+    std::cout << std::endl;
+  }
+
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::list_entities(const Range &ents) 
+{
+  for (Range::iterator rit = ents.begin(); rit != ents.end(); rit++)
+    list_entities(&(*rit), 1);
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::update_remote_data(Range &local_range,
+                                               Range &remote_range,
+                                               int other_proc,
+                                               const unsigned char add_pstat) 
+{
+  Range::iterator rit, rit2;
+  ErrorCode result = MB_SUCCESS;
+
+    // for each pair of local/remote handles:
+  for (rit = local_range.begin(), rit2 = remote_range.begin(); 
+       rit != local_range.end(); rit++, rit2++) {
+
+    result = update_remote_data(*rit, &other_proc, &(*rit2), 1, add_pstat);
+    RRA(" ");
+  }
+
+  return result;
+}
+  
+ErrorCode ParallelComm::update_remote_data(const EntityHandle new_h,
+                                               const int *ps,
+                                               const EntityHandle *hs,
+                                               const int num_ps,
+                                               const unsigned char add_pstat) 
+{
+  EntityHandle tag_hs[MAX_SHARING_PROCS];
+  int tag_ps[MAX_SHARING_PROCS];
+  unsigned char pstat;
+    // get initial sharing data; tag_ps and tag_hs get terminated with -1 and 0
+    // in this function, so no need to initialize
+  unsigned int num_exist;
+  ErrorCode result = get_sharing_data(new_h, tag_ps, tag_hs, pstat, num_exist);
+  RRA("");
+  
+#ifndef NDEBUG
+  {
+      // check for duplicates in proc list
+    std::set<unsigned int> dumprocs;
+    unsigned int dp = 0;
+    for (; (int) dp < num_ps && -1 != ps[dp]; dp++)
+      dumprocs.insert(ps[dp]);
+    assert(dp == dumprocs.size());
+  }
+#endif      
+
+    // add any new sharing data
+  bool changed = false;
+  int idx;
+  if (!num_exist) {
+      // just take what caller passed
+    memcpy(tag_ps, ps, num_ps*sizeof(int));
+    memcpy(tag_hs, hs, num_ps*sizeof(EntityHandle));
+    num_exist = num_ps;
+      // if it's only one, hopefully I'm not there yet...
+    assert("I shouldn't be the only proc there." &&
+           (1 != num_exist || ps[0] != (int)procConfig.proc_rank()));
+    changed = true;
+  }
+  else {
+    for (int i = 0; i < num_ps; i++) {
+      idx = std::find(tag_ps, tag_ps+num_exist, ps[i]) - tag_ps;
+      if (idx == (int) num_exist) {
+          // if there's only 1 sharing proc, and it's not me, then
+          // we'll end up with 3; add me to the front
+        if (!i && num_ps == 1 && num_exist == 1 &&
+            ps[0] != (int)procConfig.proc_rank()) {
+          int j = 1;
+            // if I own this entity, put me at front, otherwise after first
+          if (!(pstat & PSTATUS_NOT_OWNED)) {
+            tag_ps[1] = tag_ps[0];
+            tag_hs[1] = tag_hs[0];
+            j = 0;
+          }
+          tag_ps[j] = procConfig.proc_rank();
+          tag_hs[j] = new_h;
+          num_exist++;
+        }
+        
+        tag_ps[num_exist] = ps[i];
+        tag_hs[num_exist] = hs[i];
+        num_exist++;
+        changed = true;
+      }
+      else if (0 == tag_hs[idx]) {
+        tag_hs[idx] = hs[i];
+        changed = true;
+      }
+      else if (0 != hs[i]) {
+        assert(hs[i] == tag_hs[idx]);
+      }
+    }
+  }
+  
+    // adjust for interface layer if necessary
+  if (add_pstat & PSTATUS_INTERFACE) {
+    idx = std::min_element(tag_ps, tag_ps+num_exist) - tag_ps;
+    if (idx) {
+      int tag_proc = tag_ps[idx];
+      tag_ps[idx] = tag_ps[0];
+      tag_ps[0] = tag_proc;
+      EntityHandle tag_h = tag_hs[idx];
+      tag_hs[idx] = tag_hs[0];
+      tag_hs[0] = tag_h;
+      changed = true;
+      if (tag_ps[0] != (int)procConfig.proc_rank()) pstat |= PSTATUS_NOT_OWNED;
+    }
+  }
+    
+  if (!changed) return MB_SUCCESS;
+  
+  assert("interface entities should have > 1 proc" &&
+         (!(add_pstat & PSTATUS_INTERFACE) || num_exist > 1));
+  assert("ghost entities should have > 1 proc" &&
+         (!(add_pstat & PSTATUS_GHOST) || num_exist > 1));
+  
+    // if it's multi-shared and we created the entity in this unpack,
+    // local handle probably isn't in handle list yet
+  if (num_exist > 2) {
+    idx = std::find(tag_ps, tag_ps+num_exist, procConfig.proc_rank()) - tag_ps;
+    assert(idx < (int) num_exist);
+    if (!tag_hs[idx])
+      tag_hs[idx] = new_h;
+  }
+      
+  int tag_p;
+  EntityHandle tag_h;
+
+    // reset single shared proc/handle if was shared and moving to multi-shared
+  if (num_exist > 2 && !(pstat & PSTATUS_MULTISHARED) &&
+      (pstat & PSTATUS_SHARED)) {
+      // must remove sharedp/h first, which really means set to default value
+    tag_p = -1;
+    result = mbImpl->tag_set_data(sharedp_tag(), &new_h, 1, &tag_p);
+    RRA("Couldn't set sharedp tag.");
+    tag_h = 0;
+    result = mbImpl->tag_set_data(sharedh_tag(), &new_h, 1, &tag_h);
+    RRA("Couldn't set sharedh tag.");
+  }
+
+    // update pstat
+  pstat |= add_pstat;
+  
+    // set sharing tags
+  if (num_exist > 2) {
+    std::fill(tag_ps+num_exist, tag_ps+MAX_SHARING_PROCS, -1);
+    std::fill(tag_hs+num_exist, tag_hs+MAX_SHARING_PROCS, 0);
+    result = mbImpl->tag_set_data(sharedps_tag(), &new_h, 1, tag_ps);
+    RRA("Couldn't set sharedps tag.");
+    result = mbImpl->tag_set_data(sharedhs_tag(), &new_h, 1, tag_hs);
+    RRA("Couldn't set sharedhs tag.");
+    pstat |= (PSTATUS_MULTISHARED | PSTATUS_SHARED);
+
+#ifndef NDEBUG
+    {
+        // check for duplicates in proc list
+      std::set<unsigned int> dumprocs;
+      unsigned int dp = 0;
+      for (; dp < num_exist && -1 != tag_ps[dp]; dp++)
+        dumprocs.insert(tag_ps[dp]);
+      assert(dp == dumprocs.size());
+    }
+#endif      
+  }
+  else if (num_exist == 2 || num_exist == 1) {
+    if (tag_ps[0] == (int) procConfig.proc_rank()) {
+      assert(2 == num_exist && tag_ps[1] != (int) procConfig.proc_rank());
+      tag_ps[0] = tag_ps[1];
+      tag_hs[0] = tag_hs[1];
+    }
+    assert(tag_ps[0] != -1 && tag_hs[0] != 0);
+    result = mbImpl->tag_set_data(sharedp_tag(), &new_h, 1, tag_ps);
+    RRA("Couldn't set sharedp tag.");
+    result = mbImpl->tag_set_data(sharedh_tag(), &new_h, 1, tag_hs);
+    RRA("Couldn't set sharedh tag.");
+    pstat |= PSTATUS_SHARED;
+  }
+
+    // now set new pstatus
+  result = mbImpl->tag_set_data(pstatus_tag(), &new_h, 1, &pstat);
+  RRA("Couldn't set pstatus tag.");
+
+  if (pstat & PSTATUS_SHARED) sharedEnts.insert(new_h);
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_sharing_data(const Range &entities,
+                                             std::set<int> &procs,
+                                             int operation)
+{
+    // get the union or intersection of sharing data for multiple entities
+
+  ErrorCode result;
+  int sp2[MAX_SHARING_PROCS];
+  int num_ps;
+  unsigned char pstat;
+  std::set<int> tmp_procs;
+  procs.clear();
+  
+  for (Range::const_iterator rit = entities.begin(); rit != entities.end(); rit++) {
+        
+      // get sharing procs
+    result = get_sharing_data(*rit, sp2, NULL, pstat, num_ps);
+    RRA("Problem getting sharing data in get_sharing_data.");
+    if (!(pstat & PSTATUS_SHARED) && Interface::INTERSECT == operation) {
+      procs.clear();
+      return MB_SUCCESS;
+    }
+        
+    if (rit == entities.begin()) {
+      std::copy(sp2, sp2+num_ps, std::inserter(procs, procs.begin()));
+    }
+    else {
+      std::sort(sp2, sp2+num_ps);
+      tmp_procs.clear();
+      if (Interface::UNION == operation) 
+        std::set_union(procs.begin(), procs.end(), 
+                       sp2, sp2+num_ps, std::inserter(tmp_procs, tmp_procs.end()));
+      else if (Interface::INTERSECT == operation)
+        std::set_intersection(procs.begin(), procs.end(), 
+                              sp2, sp2+num_ps, std::inserter(tmp_procs, tmp_procs.end()));
+      else {
+        assert("Unknown operation." && false);
+        return MB_FAILURE;
+      }
+      procs.swap(tmp_procs);
+    }
+    if (Interface::INTERSECT == operation && procs.empty()) 
+      return MB_SUCCESS;
+  }
+
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::get_sharing_data(const EntityHandle entity,
+                                             int *ps, 
+                                             EntityHandle *hs,
+                                             unsigned char &pstat,
+                                             unsigned int &num_ps)
+{
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1, &pstat);
+  RRA("Couldn't get pstatus tag.");
+  if (pstat & PSTATUS_MULTISHARED) {
+    result = mbImpl->tag_get_data(sharedps_tag(), &entity, 1, ps);
+    RRA("Couldn't get sharedps tag.");
+    if (hs) {
+      result = mbImpl->tag_get_data(sharedhs_tag(), &entity, 1, hs);
+      RRA("Couldn't get sharedhs tag.");
+    }
+    num_ps = std::find(ps, ps+MAX_SHARING_PROCS, -1) - ps;
+  }
+  else if (pstat & PSTATUS_SHARED) {
+    result = mbImpl->tag_get_data(sharedp_tag(), &entity, 1, ps);
+    RRA("Couldn't get sharedp tag.");
+    if (hs) {
+      result = mbImpl->tag_get_data(sharedh_tag(), &entity, 1, hs);
+      RRA("Couldn't get sharedh tag.");
+      hs[1] = 0;
+    }
+      // initialize past end of data
+    ps[1] = -1;
+    num_ps = 1;
+  }
+  else {
+    ps[0] = -1;
+    if (hs) hs[0] = 0;
+    num_ps = 0;
+  }
+
+  assert(0 <= num_ps && MAX_SHARING_PROCS >= num_ps);
+  
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::find_existing_entity(const bool is_iface,
+                                                 const int owner_p,
+                                                 const EntityHandle owner_h,
+                                                 const int num_ps,
+                                                 const EntityHandle *connect,
+                                                 const int num_connect,
+                                                 const EntityType this_type,
+                                                 std::vector<EntityHandle> &L2hloc,
+                                                 std::vector<EntityHandle> &L2hrem,
+                                                 std::vector<unsigned int> &L2p,
+                                                 EntityHandle &new_h) 
+{
+  new_h = 0;
+  if (!is_iface && num_ps > 2) {
+    for (unsigned int i = 0; i < L2hrem.size(); i++) {
+      if (L2hrem[i] == owner_h && owner_p == (int) L2p[i]) {
+        new_h = L2hloc[i];
+        return MB_SUCCESS;
+      }
+    }        
+  }
+
+    // if we got here and it's a vertex, we don't need to look further
+  if (MBVERTEX == this_type || !connect || !num_connect) return MB_SUCCESS;
+  
+  Range tmp_range;
+  ErrorCode result = mbImpl->get_adjacencies(connect, num_connect, 
+                                               MBCN::Dimension(this_type), false, 
+                                               tmp_range);
+  RRA("Problem getting existing entity.");
+  if (!tmp_range.empty()) {
+      // found a corresponding entity - return target
+    new_h = *tmp_range.begin();
+  }  
+  else {
+    new_h = 0;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_local_handles(const Range &remote_handles,
+                                              Range &local_handles,
+                                              const Range &new_ents) 
+{
+  std::vector<EntityHandle> rh_vec;
+  rh_vec.reserve(remote_handles.size());
+  std::copy(remote_handles.begin(), remote_handles.end(), std::back_inserter(rh_vec));
+  ErrorCode result = get_local_handles(&rh_vec[0], remote_handles.size(), new_ents);
+  std::copy(rh_vec.begin(), rh_vec.end(), range_inserter(local_handles));
+  return result;
+}
+  
+ErrorCode ParallelComm::get_local_handles(EntityHandle *from_vec, 
+                                              int num_ents,
+                                              const Range &new_ents) 
+{
+  std::vector<EntityHandle> tmp_ents;
+  std::copy(new_ents.begin(), new_ents.end(), std::back_inserter(tmp_ents));
+  return get_local_handles(from_vec, num_ents, tmp_ents);
+}
+
+ErrorCode ParallelComm::get_local_handles(EntityHandle *from_vec,
+                                              int num_ents,
+                                              const std::vector<EntityHandle> &new_ents) 
+{
+  for (int i = 0; i < num_ents; i++) {
+    if (TYPE_FROM_HANDLE(from_vec[i]) == MBMAXTYPE) {
+      assert(ID_FROM_HANDLE(from_vec[i]) < (int) new_ents.size());
+      from_vec[i] = new_ents[ID_FROM_HANDLE(from_vec[i])];
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+template <typename T> void
+insert_in_array( T* array, size_t array_size, size_t location, T value )
+{
+  assert( location+1 < array_size );
+  for (size_t i = array_size-1; i > location; --i)
+    array[i] = array[i-1];
+  array[location] = value;
+}
+
+ErrorCode ParallelComm::pack_range_map(Range &key_range, EntityHandle val_start,
+                                           HandleMap &handle_map) 
+{
+  for (Range::const_pair_iterator key_it = key_range.const_pair_begin(); 
+       key_it != key_range.const_pair_end(); key_it++) {
+    int tmp_num = (*key_it).second - (*key_it).first + 1;
+    handle_map.insert((*key_it).first, val_start, tmp_num);
+    val_start += tmp_num;
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::pack_sets(Range &entities,
+                                      Buffer *buff,
+                                      const bool store_remote_handles,
+                                      const int to_proc)
+{
+    // SETS:
+    // . #sets
+    // . for each set:
+    //   - options[#sets] (unsigned int)
+    //   - if (unordered) set range 
+    //   - else if ordered
+    //     . #ents in set
+    //     . handles[#ents]
+    //   - #parents
+    //   - if (#parents) handles[#parents]
+    //   - #children
+    //   - if (#children) handles[#children]
+  
+    // now the sets; assume any sets the application wants to pass are in the entities list
+  ErrorCode result;
+  Range all_sets = entities.subset_by_type(MBENTITYSET);
+
+  int buff_size = estimate_sets_buffer_size(all_sets, store_remote_handles);
+  buff->check_space(buff_size);
+
+    // number of sets
+  PACK_INT(buff->buff_ptr, all_sets.size());
+
+    // options for all sets
+  std::vector<unsigned int> options(all_sets.size());
+  Range::iterator rit;
+  std::vector<EntityHandle> members;
+  int i;
+  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
+      result = mbImpl->get_meshset_options(*rit, options[i]);
+      RRA("Failed to get meshset options.");
+  }
+  buff->check_space(all_sets.size()*sizeof(unsigned int));
+  PACK_VOID(buff->buff_ptr, &options[0], all_sets.size()*sizeof(unsigned int));
+  
+    // vectors/ranges
+  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
+      Range set_range;
+      if (options[i] & MESHSET_SET) {
+        Range set_range;
+        result = mbImpl->get_entities_by_handle(*rit, set_range);
+        RRA("Failed to get set entities.");
+
+        buff_size = RANGE_SIZE(set_range);
+        buff->check_space(buff_size);
+        PACK_RANGE(buff->buff_ptr, set_range);
+      }
+      else if (options[i] & MESHSET_ORDERED) {
+        members.clear();
+        result = mbImpl->get_entities_by_handle(*rit, members);
+        RRA("Failed to get entities in ordered set.");
+        
+        buff->check_space(members.size()*sizeof(EntityHandle)+sizeof(int));
+        PACK_INT(buff->buff_ptr, members.size());
+        PACK_EH(buff->buff_ptr, &members[0], members.size());
+      }
+  }
+    // pack numbers of parents/children
+  unsigned int tot_pch = 0;
+  int num_pch;
+  buff->check_space(2*all_sets.size()*sizeof(int));
+  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
+      // pack parents
+    result = mbImpl->num_parent_meshsets(*rit, &num_pch);
+    RRA("Failed to get num parents.");
+    PACK_INT(buff->buff_ptr, num_pch);
+    tot_pch += num_pch;
+    result = mbImpl->num_child_meshsets(*rit, &num_pch);
+    RRA("Failed to get num children.");
+    PACK_INT(buff->buff_ptr, num_pch);
+    tot_pch += num_pch;
+  }
+
+    // now pack actual parents/children
+  members.clear();
+  members.reserve(tot_pch);
+  std::vector<EntityHandle> tmp_pch;
+  for (rit = all_sets.begin(), i = 0; rit != all_sets.end(); rit++, i++) {
+    result = mbImpl->get_parent_meshsets(*rit, tmp_pch);
+    RRA("Failed to get parents.");
+    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members));
+    tmp_pch.clear();
+    result = mbImpl->get_child_meshsets(*rit, tmp_pch);
+    RRA("Failed to get children.");
+    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members));
+    tmp_pch.clear();
+  }
+  assert(members.size() == tot_pch);
+  if (!members.empty()) {
+    result = get_remote_handles(store_remote_handles,
+                                &members[0], &members[0], 
+                                members.size(), to_proc,
+                                entities);
+    RRA("Trouble getting remote handles for set parent/child sets.");
+#ifndef NDEBUG
+      // check that all handles are either sets or maxtype
+    for (unsigned int __j = 0; __j < members.size(); __j++)
+      assert((TYPE_FROM_HANDLE(members[__j]) == MBMAXTYPE &&
+              ID_FROM_HANDLE(members[__j]) < (int)entities.size()) ||
+             TYPE_FROM_HANDLE(members[__j]) == MBENTITYSET);
+#endif        
+    buff->check_space(members.size()*sizeof(EntityHandle));
+    PACK_EH(buff->buff_ptr, &members[0], members.size());
+  }
+    
+    // pack the handles
+  if (store_remote_handles && !all_sets.empty()) {
+    buff_size = RANGE_SIZE(all_sets);
+    buff->check_space(buff_size);
+    PACK_RANGE(buff->buff_ptr, all_sets);
+  }
+  
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Done packing sets." << std::endl;
+#endif
+
+  buff->set_stored_size();
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::unpack_sets(unsigned char *&buff_ptr,
+                                        Range &entities,
+                                        const bool store_remote_handles,
+                                        const int from_proc)
+{
+  
+    // now the sets; assume any sets the application wants to pass are in the entities list
+  ErrorCode result;
+
+  Range new_sets;
+  int num_sets;
+  UNPACK_INT(buff_ptr, num_sets);
+
+  if (!num_sets) return MB_SUCCESS;
+         
+  std::vector<EntityHandle> members;
+  int num_ents;
+  std::vector<unsigned int> options_vec(num_sets);
+      // option value
+  if (num_sets)
+    UNPACK_VOID(buff_ptr, &options_vec[0], num_sets*sizeof(unsigned int));
+
+    // create sets
+  int i;
+  Range::const_iterator rit;
+  for (i = 0; i < num_sets; i++) {
+    
+      // create the set
+    EntityHandle set_handle;
+    result = mbImpl->create_meshset(options_vec[i], set_handle);
+    RRA("Failed to create set in unpack.");
+
+    // make sure new sets handles are monotonically increasing
+    assert(set_handle > *new_sets.rbegin());
+
+    new_sets.insert(set_handle);
+  }
+
+  entities.merge(new_sets);
+  
+  for (rit = new_sets.begin(), i = 0; rit != new_sets.end(); rit++, i++) {
+    if (options_vec[i] & MESHSET_SET) {
+        // unpack entities as a range
+      Range set_range, tmp_range;
+      UNPACK_RANGE(buff_ptr, tmp_range);
+      result = get_local_handles(tmp_range, set_range, entities);      
+      RRA("Failed to get local handles for unordered set contents.");
+      result = mbImpl->add_entities(*rit, set_range);
+      RRA("Failed to add ents to unordered set in unpack.");
+    }
+    else if (options_vec[i] & MESHSET_ORDERED) {
+        // unpack entities as vector, with length
+      UNPACK_INT(buff_ptr, num_ents);
+      members.resize(num_ents);
+      if (num_ents) UNPACK_EH(buff_ptr, &members[0], num_ents);
+      result = get_local_handles(&members[0], num_ents, entities);
+      RRA("Failed to get local handles for ordered set contents.");
+      result = mbImpl->add_entities(*rit, &members[0], num_ents);
+      RRA("Failed to add ents to ordered set in unpack.");
+    }
+  }
+
+  std::vector<int> num_pch(2*new_sets.size());
+  std::vector<int>::iterator vit;
+  int tot_pch = 0;
+  for (vit = num_pch.begin(); vit != num_pch.end(); vit++) {
+    UNPACK_INT(buff_ptr, *vit);
+    tot_pch += *vit;
+  }
+  
+  members.resize(tot_pch);
+  UNPACK_EH(buff_ptr, &members[0], tot_pch);
+  result = get_local_handles(&members[0], tot_pch, entities);
+  RRA("Couldn't get local handle for parent/child sets.");
+
+  int num = 0;
+  EntityHandle *mem_ptr = &members[0];
+  for (rit = new_sets.begin(); rit != new_sets.end(); rit++) {
+      // unpack parents/children
+    int num_par = num_pch[num++], num_child = num_pch[num++];
+    if (num_par+num_child) {
+      for (i = 0; i < num_par; i++) {
+        assert(0 != mem_ptr[i]);
+        result = mbImpl->add_parent_meshset(*rit, mem_ptr[i]);
+        RRA("Failed to add parent to set in unpack.");
+      }
+      mem_ptr += num_par;
+      for (i = 0; i < num_child; i++) {
+        assert(0 != mem_ptr[i]);
+        result = mbImpl->add_child_meshset(*rit, mem_ptr[i]);
+        RRA("Failed to add child to set in unpack.");
+      }
+      mem_ptr += num_child;
+    }
+  }
+
+    // unpack source handles
+  Range dum_range;
+  if (store_remote_handles && !new_sets.empty()) {
+    UNPACK_RANGE(buff_ptr, dum_range);
+    result = update_remote_data(new_sets, dum_range, from_proc, 0);
+    RRA("Couldn't set sharing data for sets");
+  }
+
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Done unpacking sets." << std::endl;
+#endif
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::pack_adjacencies(Range &entities,
+                                             Range::const_iterator &start_rit,
+                                             Range &whole_range,
+                                             unsigned char *&buff_ptr,
+                                             int &count,
+                                             const bool just_count,
+                                             const bool store_handles,
+                                             const int to_proc)
+{
+  return MB_FAILURE;
+}
+
+ErrorCode ParallelComm::unpack_adjacencies(unsigned char *&buff_ptr,
+                                               Range &entities,
+                                               const bool store_handles,
+                                               const int from_proc)
+{
+  return MB_FAILURE;
+}
+
+ErrorCode ParallelComm::pack_tags(Range &entities,
+                                      const std::vector<Tag> &src_tags,
+                                      const std::vector<Tag> &dst_tags,
+                                      const std::vector<Range> &tag_ranges,
+                                      Buffer *buff,
+                                      const bool store_remote_handles,
+                                      const int to_proc)
+{
+  
+
+  ErrorCode result;
+  std::vector<Tag>::const_iterator tag_it, dst_it;
+  std::vector<Range>::const_iterator rit;
+  int count = 0;
+  
+  for (tag_it = src_tags.begin(), rit = tag_ranges.begin(); 
+       tag_it != src_tags.end(); tag_it++, rit++) {
+
+    result = packed_tag_size( *tag_it, *rit, count );
+    if (MB_SUCCESS != result)
+      return result;
+  }
+    
+    // number of tags
+  count += sizeof(int);
+
+  buff->check_space(count);
+  
+  PACK_INT(buff->buff_ptr, src_tags.size());
+    
+  for (tag_it = src_tags.begin(), dst_it = dst_tags.begin(), rit = tag_ranges.begin(); 
+       tag_it != src_tags.end(); tag_it++, dst_it++, rit++) {
+    
+    result = pack_tag( *tag_it, *dst_it, *rit, entities, buff,
+                       store_remote_handles, to_proc );
+    if (MB_SUCCESS != result)
+      return result;
+  }
+  
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Done packing tags." << std::endl;
+#endif
+
+  buff->set_stored_size();
+  
+  return MB_SUCCESS;
+}
+         
+
+ErrorCode ParallelComm::packed_tag_size( Tag tag,
+                                             const Range &tagged_entities,
+                                             int &count )
+{
+    // for dense tags, compute size assuming all entities have that tag
+    // for sparse tags, get number of entities w/ that tag to compute size
+
+  std::vector<int> var_len_sizes;
+  std::vector<const void*> var_len_values;
+    
+  const TagInfo *tinfo = tagServer->get_tag_info(tag);
+    // default value
+  count += sizeof(int);
+  if (NULL != tinfo->default_value()) 
+    count += tinfo->default_value_size();
+
+    // size, type, data type
+  count += 3*sizeof(int);
+
+    // name
+  count += sizeof(int);
+  count += tinfo->get_name().size();
+
+    // range of tag
+  count += sizeof(int) + tagged_entities.size() * sizeof(EntityHandle);
+
+  if (tinfo->get_size() == MB_VARIABLE_LENGTH) {
+    const int num_ent = tagged_entities.size();
+      // send a tag size for each entity
+    count += num_ent * sizeof(int);
+      // send tag data for each entity
+    var_len_sizes.resize( num_ent );
+    var_len_values.resize( num_ent );
+    ErrorCode result = tagServer->get_data( tag,
+                                              tagged_entities, 
+                                              &var_len_values[0], 
+                                              &var_len_sizes[0] );
+    RRA("Failed to get lenghts of variable-length tag values.");
+    count += std::accumulate( var_len_sizes.begin(), var_len_sizes.end(), 0 );
+  }
+  else {
+      // tag data values for range or vector
+    count += tagged_entities.size() * tinfo->get_size();
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+ErrorCode ParallelComm::pack_tag( Tag src_tag,
+                                      Tag dst_tag,
+                                      const Range &tagged_entities,
+                                      const Range &whole_range,
+                                      Buffer *buff,
+                                      const bool store_remote_handles,
+                                      const int to_proc )
+{
+  ErrorCode result;
+  std::vector<int> var_len_sizes;
+  std::vector<const void*> var_len_values;
+
+  const TagInfo* tinfo = tagServer->get_tag_info(src_tag);
+  if (!tinfo)
+    return MB_TAG_NOT_FOUND;
+    
+  const TagInfo* dst_tinfo;
+  if (src_tag == dst_tag) {
+    dst_tinfo = tinfo;
+  }
+  else {
+    dst_tinfo = tagServer->get_tag_info(dst_tag);
+    if (!dst_tinfo)
+      return MB_TAG_NOT_FOUND;
+    if (dst_tinfo->get_size() != tinfo->get_size())
+      return MB_TYPE_OUT_OF_RANGE;
+    if (dst_tinfo->get_data_type() != tinfo->get_data_type() && 
+        dst_tinfo->get_data_type() != MB_TYPE_OPAQUE &&
+            tinfo->get_data_type() != MB_TYPE_OPAQUE)
+      return MB_TYPE_OUT_OF_RANGE;
+  }
+    
+    // size, type, data type
+  buff->check_space(3*sizeof(int));
+  PACK_INT(buff->buff_ptr, tinfo->get_size());
+  TagType this_type;
+  result = mbImpl->tag_get_type(dst_tag, this_type);
+  PACK_INT(buff->buff_ptr, (int)this_type);
+  PACK_INT(buff->buff_ptr, (int)(tinfo->get_data_type()));
+
+    // default value
+  if (NULL == tinfo->default_value()) {
+    buff->check_space(sizeof(int));
+    PACK_INT(buff->buff_ptr, 0);
+  }
+  else {
+    buff->check_space(tinfo->default_value_size());
+    PACK_BYTES(buff->buff_ptr, tinfo->default_value(), tinfo->default_value_size());
+  }
+
+    // name
+  buff->check_space(tinfo->get_name().size());
+  PACK_BYTES(buff->buff_ptr, dst_tinfo->get_name().c_str(), dst_tinfo->get_name().size());
+
+#ifdef DEBUG_PACKING
+  std::cerr << "Packing tag \"" << tinfo->get_name() << "\"";
+  if (tinfo != dst_tinfo)
+    std::cerr << " (as tag \"" << dst_tinfo->get_name() << "\")";
+  std::cerr << std::endl;
+#endif    
+    // pack entities
+  buff->check_space(tagged_entities.size()*sizeof(EntityHandle)+sizeof(int));
+  PACK_INT(buff->buff_ptr, tagged_entities.size());
+  result = get_remote_handles(store_remote_handles,
+                              tagged_entities, (EntityHandle*)buff->buff_ptr, to_proc,
+                              whole_range);
+#ifdef DEBUG_PACKING
+  if (MB_SUCCESS != result) {
+    std::cerr << "Trouble getting remote handles for tagged entities:" << std::endl;
+    tagged_entities.print("  ");
+  }
+#else
+  RRA("Trouble getting remote handles for tagged entities.");
+#endif
+
+  buff->buff_ptr += tagged_entities.size() * sizeof(EntityHandle);
+
+  const size_t num_ent = tagged_entities.size();
+  if (tinfo->get_size() == MB_VARIABLE_LENGTH) {
+    var_len_sizes.resize( num_ent, 0 );
+    var_len_values.resize( num_ent, 0 );
+    result = mbImpl->tag_get_data(src_tag, tagged_entities, &var_len_values[0], 
+                                  &var_len_sizes[0] );
+    RRA("Failed to get variable-length tag data in pack_tags.");
+    buff->check_space(num_ent*sizeof(int));
+    PACK_INTS(buff->buff_ptr, &var_len_sizes[0], num_ent);
+    for (unsigned int i = 0; i < num_ent; ++i) {
+      buff->check_space(var_len_sizes[i]);
+      PACK_VOID(buff->buff_ptr, var_len_values[i], var_len_sizes[i]);
+    }
+  }
+  else {
+    buff->check_space(num_ent * tinfo->get_size());
+    result = mbImpl->tag_get_data(src_tag, tagged_entities, buff->buff_ptr);
+    RRA("Failed to get tag data in pack_tags.");
+    buff->buff_ptr += num_ent * tinfo->get_size();
+    PC(num_ent*tinfo->get_size(), " void");
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_tag_send_list( const Range& whole_range,
+                                               std::vector<Tag>& all_tags,
+                                               std::vector<Range>& tag_ranges )
+{
+  std::vector<Tag> tmp_tags;
+  ErrorCode result = tagServer->get_tags(tmp_tags);
+  RRA("Failed to get tags in pack_tags.");
+
+  std::vector<Tag>::iterator tag_it;
+  for (tag_it = tmp_tags.begin(); tag_it != tmp_tags.end(); tag_it++) {
+    std::string tag_name;
+    result = mbImpl->tag_get_name(*tag_it, tag_name);
+    if (tag_name.c_str()[0] == '_' && tag_name.c_str()[1] == '_')
+      continue;
+
+    Range tmp_range;
+    result = tagServer->get_entities(*tag_it, tmp_range);
+    RRA("Failed to get entities for tag in pack_tags.");
+    tmp_range = intersect( tmp_range, whole_range);
+
+    if (tmp_range.empty()) continue;
+        
+      // ok, we'll be sending this tag
+    all_tags.push_back( *tag_it );
+    tag_ranges.push_back( Range() );
+    tag_ranges.back().swap( tmp_range );
+  }
+  
+  return MB_SUCCESS;
+}
+
+
+
+ErrorCode ParallelComm::unpack_tags(unsigned char *&buff_ptr,
+                                        Range &entities,
+                                        const bool store_remote_handles,
+                                        const int from_proc)
+{
+    // tags
+    // get all the tags
+    // for dense tags, compute size assuming all entities have that tag
+    // for sparse tags, get number of entities w/ that tag to compute size
+
+  ErrorCode result;
+  
+  int num_tags;
+  UNPACK_INT(buff_ptr, num_tags);
+  std::vector<EntityHandle> tag_ents;
+  std::vector<const void*> var_len_vals;
+  std::vector<int> var_lengths;
+
+  for (int i = 0; i < num_tags; i++) {
+    
+        // tag handle
+    Tag tag_handle;
+
+      // size, data type
+    int tag_size, tag_data_type, tag_type;
+    UNPACK_INT(buff_ptr, tag_size);
+    UNPACK_INT(buff_ptr, tag_type);
+    UNPACK_INT(buff_ptr, tag_data_type);
+      
+      // default value
+    int def_val_size;
+    UNPACK_INT(buff_ptr, def_val_size);
+    void *def_val_ptr = NULL;
+    if (def_val_size) {
+      def_val_ptr = buff_ptr;
+      buff_ptr += def_val_size;
+      UPC(tag_size, " void");
+    }
+    
+      // name
+    int name_len;
+    UNPACK_INT(buff_ptr, name_len);
+    std::string tag_name( reinterpret_cast<char*>(buff_ptr), name_len );
+    buff_ptr += name_len;
+    UPC(64, " chars");
+#ifdef DEBUG_PACKING
+    std::cerr << "Unpacking tag " << tag_name << std::endl;
+#endif    
+
+      // create the tag
+    if (tag_size == MB_VARIABLE_LENGTH) 
+      result = mbImpl->tag_create_variable_length( tag_name.c_str(), (TagType)tag_type,
+                                                   (DataType)tag_data_type, tag_handle,
+                                                   def_val_ptr, def_val_size );
+    else
+      result = mbImpl->tag_create(tag_name.c_str(), tag_size, (TagType) tag_type, 
+                                  (DataType) tag_data_type, tag_handle,
+                                  def_val_ptr);
+    if (MB_ALREADY_ALLOCATED == result) {
+        // already allocated tag, check to make sure it's the same size, type, etc.
+      const TagInfo *tag_info = tagServer->get_tag_info(tag_name.c_str());
+      TagType this_type;
+      result = mbImpl->tag_get_type(tag_handle, this_type);
+      if (tag_size != tag_info->get_size() ||
+          tag_type != this_type ||
+          tag_data_type != tag_info->get_data_type() ||
+          (def_val_ptr && !tag_info->default_value()) ||
+          (!def_val_ptr && tag_info->default_value())) {
+        RRA("Didn't get correct tag info when unpacking tag.");
+      }
+    }
+    else if (MB_SUCCESS != result) return result;
+
+      // go through handle vec (in buffer) and convert to local handles in-place
+    int num_ents;
+    UNPACK_INT(buff_ptr, num_ents);
+    EntityHandle *handle_vec = (EntityHandle*)buff_ptr;
+    buff_ptr += num_ents * sizeof(EntityHandle);
+
+    if (!store_remote_handles) {
+        // in this case handles are indices into new entity range; need to convert
+        // to local handles
+      result = get_local_handles(handle_vec, num_ents, entities);
+      RRA("Unable to convert to local handles.");
+    }
+
+      // if it's a handle type, also convert tag vals in-place in buffer
+    if (MB_TYPE_HANDLE == tag_type) {
+      EntityHandle *val_vec = (EntityHandle*)buff_ptr;
+      result = get_local_handles(val_vec, num_ents, entities);
+      RRA("Failed to get local handles for tag vals.");
+    }
+
+    if (tag_size == MB_VARIABLE_LENGTH) {
+        // Be careful of alignment here.  If the integers are aligned
+        // in the buffer, we can use them directly.  Otherwise we must
+        // copy them.
+      const int* size_arr;
+      if (((size_t)buff_ptr)%4) {
+        var_lengths.resize( num_ents );
+        memcpy( &var_lengths[0], buff_ptr, num_ents*sizeof(int) );
+        size_arr = &var_lengths[0];
+      }
+      else {
+        size_arr = reinterpret_cast<const int*>(buff_ptr);
+      }
+      buff_ptr += sizeof(int) * num_ents;
+      UPC(sizeof(int) * num_ents, " void");
+      
+        // get pointers into buffer for each tag value
+      var_len_vals.resize(num_ents);
+      for (std::vector<EntityHandle>::size_type i = 0; 
+           i < (std::vector<EntityHandle>::size_type) num_ents; ++i) {
+        var_len_vals[i] = buff_ptr;
+        buff_ptr += size_arr[i];
+        UPC(size_arr[i], " void");
+      }
+      result = mbImpl->tag_set_data( tag_handle, handle_vec, num_ents,
+                                     &var_len_vals[0], size_arr );
+      RRA("Trouble setting tag data when unpacking variable-length tag.");
+    }
+    else {
+      result = mbImpl->tag_set_data(tag_handle, handle_vec,
+                                    num_ents, buff_ptr);
+      RRA("Trouble setting range-based tag data when unpacking tag.");
+      buff_ptr += num_ents * tag_size;
+      UPC(num_ents * tag_size, " void");
+    }
+  }
+  
+#ifdef DEBUG_PACKING
+  std::cerr << std::endl << "Done unpacking tags." << std::endl;
+#endif
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::resolve_shared_ents(EntityHandle this_set,
+                                                int resolve_dim,
+                                                int shared_dim,
+                                                const Tag* id_tag) 
+{
+  ErrorCode result;
+  Range proc_ents;
+      // get the entities in the partition sets
+  for (Range::iterator rit = partitionSets.begin(); rit != partitionSets.end(); rit++) {
+    Range tmp_ents;
+    result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true);
+    if (MB_SUCCESS != result) return result;
+    proc_ents.merge(tmp_ents);
+  }
+
+    // resolve dim is maximal dim of entities in proc_ents
+  if (-1 == resolve_dim) {
+    resolve_dim = mbImpl->dimension_from_handle(*proc_ents.rbegin()); 
+    RRA("Couldn't get dimension.");
+    
+  }
+
+    // proc_ents should all be of same dimension
+  if (resolve_dim > shared_dim &&
+      mbImpl->dimension_from_handle(*proc_ents.rbegin()) !=
+      mbImpl->dimension_from_handle(*proc_ents.begin())) {
+    Range::iterator lower = proc_ents.lower_bound(MBCN::TypeDimensionMap[0].first),
+      upper = proc_ents.upper_bound(MBCN::TypeDimensionMap[resolve_dim-1].second);
+    proc_ents.erase(lower, upper);
+  }
+  
+    // must call even if we don't have any entities, to make sure
+    // collective comm'n works
+  return resolve_shared_ents(this_set, proc_ents, resolve_dim, shared_dim, id_tag);
+}
+  
+ErrorCode ParallelComm::resolve_shared_ents(EntityHandle this_set,
+                                                Range &proc_ents,
+                                                int resolve_dim,
+                                                int shared_dim,
+                                                const Tag* id_tag) 
+{
+#ifdef DEBUG_MPE
+  define_mpe();
+
+  MPE_Log_event(RESOLVE_START, procConfig.proc_rank(), "Entering resolve_shared_ents.");
+#endif
+
+  ErrorCode result;
+  if (debug) std::cerr << "Resolving shared entities." << std::endl;
+
+  if (-1 == shared_dim) {
+    if (0 == resolve_dim) {
+      result = mbImpl->get_dimension(shared_dim); 
+      RRA("Couldn't get dimension.");
+    }
+    else if (!proc_ents.empty())
+      shared_dim = mbImpl->dimension_from_handle(*proc_ents.begin())-1;
+    else if (resolve_dim == 3)
+      shared_dim = 2;
+    else {
+      assert(false && "Unable to guess shared_dim.");
+      return MB_FAILURE;
+    }
+  }
+  assert(shared_dim >= 0 && resolve_dim >= 0);
+  
+    // get the skin entities by dimension
+  Range skin_ents[4];
+  std::vector<int> gid_data;
+  std::vector<EntityHandle> handle_vec;
+  int skin_dim;
+
+    // get the entities to be skinned
+  if (resolve_dim < shared_dim) {
+      // for vertex-based partition, it's the elements adj to the vertices
+    result = mbImpl->get_adjacencies(proc_ents, shared_dim,
+                                     false, skin_ents[resolve_dim],
+                                     Interface::UNION);
+    RRA("Failed getting skinned entities.");
+    skin_dim = shared_dim-1;
+  }
+  else {
+      // for element-based partition, it's just the elements
+    skin_ents[resolve_dim] = proc_ents;
+    skin_dim = resolve_dim-1;
+  }
+
+    // find the skin
+  Skinner skinner(mbImpl);
+  result = skinner.find_skin(skin_ents[skin_dim+1], false, skin_ents[skin_dim],
+                             0, true);
+  RRA("Failed to find skin.");
+  if (debug) std::cerr << "Found skin, now resolving." << std::endl;
+
+    // get entities adjacent to skin ents from shared_dim down to zero
+  for (int this_dim = skin_dim-1; this_dim >= 0; this_dim--) {
+    result = mbImpl->get_adjacencies(skin_ents[skin_dim], this_dim,
+                                     true, skin_ents[this_dim],
+                                     Interface::UNION);
+    RRA("Failed getting skin adjacencies.");
+  }
+
+    // resolve shared vertices first
+
+    // global id tag
+  Tag gid_tag; int def_val = -1;
+  if (id_tag)
+    gid_tag = *id_tag;
+  else {
+    result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int),
+                                MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
+                                &def_val, true);
+    if (MB_FAILURE == result) return result;
+
+    else if (MB_ALREADY_ALLOCATED != result) {
+        // just created it, so we need global ids
+      result = assign_global_ids(0, skin_dim+1);
+      RRA("Failed assigning global ids.");
+    }
+  }
+  
+    // store index in temp tag; reuse gid_data 
+  gid_data.resize(2*skin_ents[0].size());
+  int idx = 0;
+  for (Range::iterator rit = skin_ents[0].begin(); 
+       rit != skin_ents[0].end(); rit++) 
+    gid_data[idx] = idx, idx++;
+  Tag idx_tag;
+  result = mbImpl->tag_create("__idx_tag", sizeof(int), MB_TAG_DENSE,
+                              MB_TYPE_INTEGER, idx_tag, &def_val, true);
+  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result;
+  result = mbImpl->tag_set_data(idx_tag, skin_ents[0], &gid_data[0]);
+  RRA("Couldn't assign index tag.");
+
+    // get gids for skin ents in a vector, to pass to gs
+  result = mbImpl->tag_get_data(gid_tag, skin_ents[0], &gid_data[0]);
+  RRA("Couldn't get gid tag for skin vertices.");
+
+    // put handles in vector for passing to gs setup
+  std::copy(skin_ents[0].begin(), skin_ents[0].end(), 
+            std::back_inserter(handle_vec));
+  
+#ifdef DEBUG_MPE
+  MPE_Log_event(SHAREDV_START, procConfig.proc_rank(), "Creating crystal router.");
+#endif
+
+    // get a crystal router
+  crystal_data *cd = procConfig.crystal_router();
+
+/*  
+    // get total number of entities; will overshoot highest global id, but
+    // that's ok
+  int num_total[2] = {0, 0}, num_local[2] = {0, 0};
+  result = mbImpl->get_number_entities_by_dimension(0, 0, num_local);
+  if (MB_SUCCESS != result) return result;
+  int failure = MPI_Allreduce(num_local, num_total, 1,
+                              MPI_INTEGER, MPI_SUM, procConfig.proc_comm());
+  if (failure) {
+    result = MB_FAILURE;
+    RRA("Allreduce for total number of shared ents failed.");
+  }
+  
+*/
+    // call gather-scatter to get shared ids & procs
+  gs_data *gsd;
+  assert(sizeof(ulong_) == sizeof(EntityHandle));
+  if (sizeof(int) != sizeof(ulong_)) {
+    std::vector<long> lgid_data(gid_data.size());
+    std::copy(gid_data.begin(), gid_data.end(), lgid_data.begin());
+    gsd = gs_data_setup(skin_ents[0].size(), &lgid_data[0], 
+                        (ulong_*)&handle_vec[0], 2, 1, 1, cd);
+  }
+  else {
+    gsd = gs_data_setup(skin_ents[0].size(), (long*)&gid_data[0], 
+                        (ulong_*)&handle_vec[0], 2, 1, 1, cd);
+  }
+  
+  if (NULL == gsd) {
+    result = MB_FAILURE;
+    RRA("Couldn't create gs data.");
+  }
+
+    // get shared proc tags
+  Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+  result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
+                                sharedh_tag, sharedhs_tag, pstatus_tag);
+  RRA("Couldn't get shared proc tags.");
+  
+    // load shared verts into a tuple, then sort by index
+  tuple_list shared_verts;
+  tuple_list_init_max(&shared_verts, 2, 0, 1, 0, 
+                      skin_ents[0].size()*(MAX_SHARING_PROCS+1));
+  unsigned int i = 0, j = 0;
+  for (unsigned int p = 0; p < gsd->nlinfo->np; p++) 
+    for (unsigned int np = 0; np < gsd->nlinfo->nshared[p]; np++) {
+      shared_verts.vi[i++] = gsd->nlinfo->sh_ind[j];
+      shared_verts.vi[i++] = gsd->nlinfo->target[p];
+      shared_verts.vul[j] = gsd->nlinfo->ulabels[j];
+      j++;
+      shared_verts.n++;
+    }
+  
+  int max_size = skin_ents[0].size()*(MAX_SHARING_PROCS+1);
+  buffer sort_buffer;
+  buffer_init(&sort_buffer, max_size);
+  tuple_list_sort(&shared_verts, 0, &sort_buffer);
+  buffer_free(&sort_buffer);
+
+    // set sharing procs and handles tags on skin ents
+  int maxp = -1;
+  std::vector<int> sharing_procs(MAX_SHARING_PROCS);
+  std::fill(sharing_procs.begin(), sharing_procs.end(), maxp);
+  j = 0; i = 0;
+
+    // get ents shared by 1 or n procs
+  std::map<std::vector<int>, Range> proc_nranges;
+  Range proc_verts;
+  result = mbImpl->get_adjacencies(proc_ents, 0, false, proc_verts,
+                                   Interface::UNION);
+  RRA("Couldn't get proc_verts.");
+  
+  result = tag_shared_verts(shared_verts, skin_ents,
+                            proc_nranges, proc_verts);
+  RRA("Trouble tagging shared verts.");
+
+#ifdef DEBUG_MPE
+  MPE_Log_event(SHAREDV_END, procConfig.proc_rank(), "Finished tag_shared_verts.");
+#endif
+
+    // get entities shared by 1 or n procs
+  result = tag_shared_ents(resolve_dim, shared_dim, skin_ents,
+                           proc_nranges);
+  RRA("Trouble tagging shared entities.");
+
+  tuple_list_free(&shared_verts);
+  
+  if (debug) {
+    for (std::map<std::vector<int>, Range>::const_iterator mit = proc_nranges.begin();
+         mit != proc_nranges.end(); mit++) {
+      std::cout << "Iface: ";
+      for (std::vector<int>::const_iterator vit = (mit->first).begin();
+           vit != (mit->first).end(); vit++) std::cout << " " << *vit;
+      std::cout << std::endl;
+    }
+  }
+  
+    // create the sets for each interface; store them as tags on
+    // the interface instance
+  Range iface_sets;
+  result = create_interface_sets(proc_nranges, resolve_dim, shared_dim);
+  RRA("Trouble creating iface sets.");
+
+    // establish comm procs and buffers for them
+  std::set<unsigned int> procs;
+  result = get_interface_procs(procs, true);
+  RRA("Trouble getting iface procs.");
+
+    // resolve shared entity remote handles; implemented in ghost cell exchange
+    // code because it's so similar
+  result = exchange_ghost_cells(-1, -1, 0, true, true);
+  RRA("Trouble resolving shared entity remote handles.");
+
+    // now build parent/child links for interface sets
+  result = create_iface_pc_links();
+  RRA("Trouble creating interface parent/child links.");
+
+  gs_data_free(gsd);
+
+#ifdef DEBUG_MPE
+  MPE_Log_event(RESOLVE_END, procConfig.proc_rank(), "Exiting resolve_shared_ents.");
+#endif
+
+    // done
+  return result;
+}
+
+void ParallelComm::define_mpe() 
+{
+#ifdef DEBUG_MPE
+    // define mpe states used for logging
+  int success;
+  MPE_Log_get_state_eventIDs( &IFACE_START, &IFACE_END);
+  MPE_Log_get_state_eventIDs( &GHOST_START, &GHOST_END);
+  MPE_Log_get_state_eventIDs( &SHAREDV_START, &SHAREDV_END);
+  MPE_Log_get_state_eventIDs( &RESOLVE_START, &RESOLVE_END);
+  MPE_Log_get_state_eventIDs( &ENTITIES_START, &ENTITIES_END);
+  MPE_Log_get_state_eventIDs( &RHANDLES_START, &RHANDLES_END);
+  success = MPE_Describe_state(IFACE_START, IFACE_END, "Resolve interface ents", "green");
+  success = MPE_Describe_state(GHOST_START, GHOST_END, "Exchange ghost ents", "red");
+  success = MPE_Describe_state(SHAREDV_START, SHAREDV_END, "Resolve interface vertices", "blue");
+  success = MPE_Describe_state(RESOLVE_START, RESOLVE_END, "Resolve shared ents", "purple");
+  success = MPE_Describe_state(ENTITIES_START, ENTITIES_END, "Exchange shared ents", "yellow");
+  success = MPE_Describe_state(RHANDLES_START, RHANDLES_END, "Remote handles", "cyan");
+#endif
+}
+
+ErrorCode ParallelComm::resolve_shared_ents(ParallelComm **pc, 
+                                                const unsigned int np, 
+                                                const int part_dim) 
+{
+  std::vector<Range> verts(np);
+  int tot_verts = 0;
+  unsigned int p, i, j, v;
+  ErrorCode rval;
+  for (p = 0; p < np; p++) {
+    Skinner skinner(pc[p]->get_moab());
+    Range part_ents, skin_ents;
+    rval = pc[p]->get_moab()->get_entities_by_dimension(0, part_dim, part_ents);
+    if (MB_SUCCESS != rval) return rval;
+    rval = skinner.find_skin(part_ents, false, skin_ents, 0, true);
+    if (MB_SUCCESS != rval) return rval;
+    rval = pc[p]->get_moab()->get_adjacencies(skin_ents, 0, true, verts[p],
+                                              Interface::UNION);
+    if (MB_SUCCESS != rval) return rval;
+    tot_verts += verts[p].size();
+  }
+  
+  tuple_list shared_ents;
+  tuple_list_init_max(&shared_ents, 2, 0, 1, 0, tot_verts);
+
+  i = 0; j = 0;
+  std::vector<int> gids;
+  Range::iterator rit;
+  Tag gid_tag;
+  int dum_default = -1;
+  for (p = 0; p < np; p++) {
+    rval = pc[p]->get_moab()->tag_create(GLOBAL_ID_TAG_NAME, 
+                                         sizeof(int), MB_TAG_DENSE,
+                                         MB_TYPE_INTEGER, gid_tag, 
+                                         &dum_default, true);
+    gids.resize(verts[p].size());
+    rval = pc[p]->get_moab()->tag_get_data(gid_tag, verts[p], &gids[0]);
+    if (MB_SUCCESS != rval) return rval;
+    
+    for (v = 0, rit = verts[p].begin(); v < gids.size(); v++, rit++) {
+      shared_ents.vi[i++] = gids[v];
+      shared_ents.vi[i++] = p;
+      shared_ents.vul[j] = *rit;
+      j++;
+      shared_ents.n++;
+    }
+  }
+  
+  buffer sort_buffer;
+  buffer_init(&sort_buffer, tot_verts);
+  tuple_list_sort(&shared_ents, 0, &sort_buffer);
+  buffer_free(&sort_buffer);
+
+  j = 0; i = 0;
+  std::vector<EntityHandle> handles;
+  std::vector<int> procs;
+  
+  while (i < shared_ents.n) {
+    handles.clear();
+    procs.clear();
+    
+      // count & accumulate sharing procs
+    int this_gid = shared_ents.vi[j];
+    while (i < shared_ents.n && shared_ents.vi[j] == this_gid) {
+      j++;
+      procs.push_back( shared_ents.vi[j++] );
+      handles.push_back( shared_ents.vul[i++] );
+    }
+    if (1 == procs.size()) continue;
+    
+    for (v = 0; v < procs.size(); v++) {
+      rval = pc[procs[v]]->update_remote_data(handles[v], 
+                                              &procs[0], &handles[0], procs.size(),
+                                              PSTATUS_INTERFACE);
+      if (MB_SUCCESS != rval) return rval;
+    }
+  }
+
+  std::set<unsigned int> psets;
+  for (p = 0; p < np; p++) {
+    rval = pc[p]->create_interface_sets(part_dim, part_dim-1);
+    if (MB_SUCCESS != rval) return rval;
+      // establish comm procs and buffers for them
+    psets.clear();
+    rval = pc[p]->get_interface_procs(psets, true);
+    if (MB_SUCCESS != rval) return rval;
+  }
+
+  tuple_list_free(&shared_ents);
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::tag_iface_entities() 
+{
+  ErrorCode result = MB_SUCCESS;
+  Range iface_ents, tmp_ents, rmv_ents;
+  std::vector<unsigned char> pstat;
+  unsigned char set_pstat;
+  Range::iterator rit2;
+  unsigned int i;
+  
+  for (Range::iterator rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
+    iface_ents.clear();
+    
+    result = mbImpl->get_entities_by_handle(*rit, iface_ents);
+    RRA("Couldn't get iface set contents.");
+    pstat.resize(iface_ents.size());
+    result = mbImpl->tag_get_data(pstatus_tag(), iface_ents, &pstat[0]);
+    RRA("Couldn't get pstatus values for set ents.");
+    result = mbImpl->tag_get_data(pstatus_tag(), &(*rit), 1, &set_pstat);
+    RRA("Couldn't get pstatus values for set.");
+    rmv_ents.clear();
+    for (rit2 = iface_ents.begin(), i = 0; rit2 != iface_ents.end(); rit2++, i++) {
+      if (!(pstat[i] & PSTATUS_INTERFACE)) {
+        rmv_ents.insert(*rit2);
+        pstat[i] = 0x0;
+      }
+    }
+    result = mbImpl->remove_entities(*rit, rmv_ents);
+    RRA("Couldn't remove entities from set.");
+
+    if (!(set_pstat & PSTATUS_NOT_OWNED)) continue;
+      // if we're here, we need to set the notowned status on (remaining) set contents
+
+      // remove rmv_ents from the contents list
+    iface_ents = subtract(iface_ents, rmv_ents);
+      // compress the pstat vector (removing 0x0's)
+    std::remove_if(pstat.begin(), pstat.end(), 
+                   std::bind2nd(std::equal_to<unsigned char>(), 0x0));
+      // fold the not_owned bit into remaining values
+    unsigned int sz = iface_ents.size();
+    for (i = 0; i < sz; i++)
+      pstat[i] |= PSTATUS_NOT_OWNED;
+
+      // set the tag on the entities
+    result = mbImpl->tag_set_data(pstatus_tag(), iface_ents, &pstat[0]);
+    RRA("Couldn't set pstatus values for set ents.");
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::set_pstatus_entities(Range &pstatus_ents,
+                                                 unsigned char pstatus_val,
+                                                 bool lower_dim_ents,
+                                                 bool verts_too,
+                                                 int operation) 
+{
+  std::vector<unsigned char> pstatus_vals(pstatus_ents.size());
+  Range all_ents, *range_ptr = &pstatus_ents;
+  ErrorCode result;
+  if (lower_dim_ents || verts_too) {
+    all_ents = pstatus_ents;
+    range_ptr = &all_ents;
+    int start_dim = (lower_dim_ents ? mbImpl->dimension_from_handle(*pstatus_ents.rbegin())-1 : 0);
+    for (; start_dim >= 0; start_dim--) {
+      result = mbImpl->get_adjacencies(all_ents, start_dim, true, all_ents,
+                                       Interface::UNION);
+      RRA(" ");
+    }
+  }
+  if (Interface::UNION == operation) {
+    result = mbImpl->tag_get_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]);
+    RRA("Couldn't get pstatus tag value.");
+    for (unsigned int i = 0; i < pstatus_vals.size(); i++)
+      pstatus_vals[i] |= pstatus_val;
+  }
+  else {
+    for (unsigned int i = 0; i < pstatus_vals.size(); i++)
+      pstatus_vals[i] = pstatus_val;
+  }
+  result = mbImpl->tag_set_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]);
+  RRA("Couldn't set pstatus tag value.");
+  
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::set_pstatus_entities(EntityHandle *pstatus_ents,
+                                                 int num_ents,
+                                                 unsigned char pstatus_val,
+                                                 bool lower_dim_ents,
+                                                 bool verts_too,
+                                                 int operation) 
+{
+  std::vector<unsigned char> pstatus_vals(num_ents);
+  ErrorCode result;
+  if (lower_dim_ents || verts_too) {
+      // in this case, call the range-based version
+    Range tmp_range;
+    std::copy(pstatus_ents, pstatus_ents+num_ents, range_inserter(tmp_range));
+    return set_pstatus_entities(tmp_range, pstatus_val, lower_dim_ents, 
+                                verts_too, operation);
+  }
+
+  if (Interface::UNION == operation) {
+    result = mbImpl->tag_get_data(pstatus_tag(), pstatus_ents, num_ents, &pstatus_vals[0]);
+    RRA("Couldn't get pstatus tag value.");
+    for (unsigned int i = 0; i < (unsigned int) num_ents; i++)
+      pstatus_vals[i] |= pstatus_val;
+  }
+  else {
+    for (unsigned int i = 0; i < (unsigned int) num_ents; i++)
+      pstatus_vals[i] = pstatus_val;
+  }
+  result = mbImpl->tag_set_data(pstatus_tag(), pstatus_ents, num_ents, &pstatus_vals[0]);
+  RRA("Couldn't set pstatus tag value.");
+  
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::create_interface_sets(int resolve_dim, int shared_dim) 
+{
+  std::map<std::vector<int>, Range> proc_nranges;
+  
+    // build up the list of shared entities
+  int procs[MAX_SHARING_PROCS];
+  EntityHandle handles[MAX_SHARING_PROCS];
+  ErrorCode result;
+  int nprocs;
+  unsigned char pstat;
+  for (Range::iterator rit = sharedEnts.begin(); rit != sharedEnts.end(); rit++) {
+    if (shared_dim != -1 && mbImpl->dimension_from_handle(*rit) > shared_dim)
+      continue;
+    result = get_sharing_data(*rit, procs, handles, pstat, nprocs);
+    RRA("");
+    std::sort(procs, procs+nprocs);
+    std::vector<int> tmp_procs(procs, procs + nprocs);
+    proc_nranges[tmp_procs].insert(*rit);
+  }
+                                                  
+  Skinner skinner(mbImpl);
+  Range skin_ents[4];
+  result = mbImpl->get_entities_by_dimension(0, resolve_dim, skin_ents[resolve_dim]);
+  RRA("");
+  result = skinner.find_skin(skin_ents[resolve_dim], false, 
+                             skin_ents[resolve_dim-1], 0, true);
+  RRA("Failed to find skin.");
+  if (shared_dim > 1) {
+    result = mbImpl->get_adjacencies(skin_ents[resolve_dim-1], resolve_dim-2, true,
+                                     skin_ents[resolve_dim-2], Interface::UNION);
+    RRA("");
+  }
+
+  result = tag_shared_ents(resolve_dim, shared_dim, skin_ents,
+                           proc_nranges);
+    
+  return create_interface_sets(proc_nranges, resolve_dim, shared_dim);
+}
+  
+ErrorCode ParallelComm::create_interface_sets(std::map<std::vector<int>, Range> &proc_nranges,
+                                                  int resolve_dim, int shared_dim) 
+{
+  if (proc_nranges.empty()) return MB_SUCCESS;
+  
+  int proc_ids[MAX_SHARING_PROCS];
+  EntityHandle proc_handles[MAX_SHARING_PROCS];
+  Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+  ErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
+                                            sharedh_tag, sharedhs_tag,
+                                            pstatus_tag);
+  RRA("Trouble getting shared proc tags in create_interface_sets.");
+  Range::iterator rit;
+
+    // create interface sets, tag them, and tag their contents with iface set tag
+  std::vector<EntityHandle> tag_vals;
+  std::vector<unsigned char> pstatus;
+  for (std::map<std::vector<int>,Range>::iterator mit = proc_nranges.begin();
+       mit != proc_nranges.end(); mit++) {
+      // create the set
+    EntityHandle new_set;
+    result = mbImpl->create_meshset(MESHSET_SET, new_set); 
+    RRA("Failed to create interface set.");
+    interfaceSets.insert(new_set);
+
+      // add entities
+    result = mbImpl->add_entities(new_set, mit->second); 
+    RRA("Failed to add entities to interface set.");
+      // tag set with the proc rank(s)
+    if (mit->first.size() == 1) {
+      result = mbImpl->tag_set_data(sharedp_tag, &new_set, 1, 
+                                    &(mit->first)[0]); 
+      proc_handles[0] = 0;
+      result = mbImpl->tag_set_data(sharedh_tag, &new_set, 1, 
+                                    proc_handles); 
+    }
+    else {
+      // pad tag data out to MAX_SHARING_PROCS with -1
+      assert( mit->first.size() <= MAX_SHARING_PROCS );
+      std::copy( mit->first.begin(), mit->first.end(), proc_ids );
+      std::fill( proc_ids + mit->first.size(), proc_ids + MAX_SHARING_PROCS, -1 );
+      result = mbImpl->tag_set_data(sharedps_tag, &new_set, 1, proc_ids );
+      unsigned int ind = std::find(proc_ids, proc_ids+mit->first.size(), procConfig.proc_rank())
+          - proc_ids;
+      assert(ind < mit->first.size());
+      std::fill( proc_handles + mit->first.size(), proc_handles + MAX_SHARING_PROCS, 0);
+      proc_handles[ind] = new_set;
+      result = mbImpl->tag_set_data(sharedhs_tag, &new_set, 1, proc_handles); 
+    }
+    RRA("Failed to tag interface set with procs.");
+    
+      // get the owning proc, then set the pstatus tag on iface set
+    int min_proc = (mit->first)[0];
+    unsigned char pval = (PSTATUS_SHARED | PSTATUS_INTERFACE);
+    if (min_proc < (int) procConfig.proc_rank()) pval |= PSTATUS_NOT_OWNED;
+    if (mit->first.size() > 1) pval |= PSTATUS_MULTISHARED;
+    result = mbImpl->tag_set_data(pstatus_tag, &new_set, 1, &pval); 
+    RRA("Failed to tag interface set with pstatus.");
+
+      // tag the vertices with the same thing
+    pstatus.clear();
+    Range verts = (mit->second).subset_by_type(MBVERTEX);
+    pstatus.resize(verts.size(), pval);
+    result = mbImpl->tag_set_data(pstatus_tag, verts, &pstatus[0]); 
+    RRA("Failed to tag interface set vertices with pstatus.");
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::create_iface_pc_links() 
+{
+    // now that we've resolved the entities in the iface sets, 
+    // set parent/child links between the iface sets
+
+    // first tag all entities in the iface sets
+  Tag tmp_iface_tag;
+  EntityHandle tmp_iface_set = 0;
+  ErrorCode result = mbImpl->tag_create("__tmp_iface", sizeof(EntityHandle),
+                                          MB_TAG_DENSE, MB_TYPE_HANDLE,
+                                          tmp_iface_tag, &tmp_iface_set);
+  if (MB_ALREADY_ALLOCATED != result && MB_SUCCESS != result) 
+    RRA("Failed to create temporary iface set tag.");
+
+  Range iface_ents;
+  std::vector<EntityHandle> tag_vals;
+  Range::iterator rit;
+  
+  for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
+      // tag entities with interface set
+    iface_ents.clear();
+    result = mbImpl->get_entities_by_handle(*rit, iface_ents);
+    RRA("Couldn't get entities in iface set.");
+    
+    if (iface_ents.empty()) continue;
+    
+    tag_vals.resize(iface_ents.size());
+    std::fill(tag_vals.begin(), tag_vals.end(), *rit);
+    result = mbImpl->tag_set_data(tmp_iface_tag, iface_ents, &tag_vals[0]); 
+    RRA("Failed to tag iface entities with interface set.");
+  }
+  
+    // now go back through interface sets and add parent/child links
+  Range tmp_ents2;
+  for (int d = 2; d >= 0; d--) {
+    for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
+        // get entities on this interface
+      iface_ents.clear();
+      result = mbImpl->get_entities_by_handle(*rit, iface_ents, true);
+      RRA("Couldn't get entities by dimension.");
+      if (iface_ents.empty() ||
+          mbImpl->dimension_from_handle(*iface_ents.rbegin()) != d) continue;
+
+        // get higher-dimensional entities and their interface sets
+      result = mbImpl->get_adjacencies(&(*iface_ents.begin()), 1, d+1,
+                                       false, tmp_ents2);
+      RRA("Couldn't get adjacencies for interface sets.");
+      tag_vals.resize(tmp_ents2.size());
+      result = mbImpl->tag_get_data(tmp_iface_tag, tmp_ents2, &tag_vals[0]);
+      RRA("Couldn't get iface set tag for interface sets.");
+      
+        // go through and for any on interface make it a parent
+      EntityHandle last_set = 0;
+      for (unsigned int i = 0; i < tag_vals.size(); i++) {
+        if (tag_vals[i] && tag_vals[i] != last_set) {
+          result = mbImpl->add_parent_child(tag_vals[i], *rit);
+          RRA("Couldn't add parent/child link for interface set.");
+          last_set = tag_vals[i];
+        }
+      }
+    }
+  }
+  
+    // delete the temporary tag
+  result = mbImpl->tag_delete(tmp_iface_tag);
+  RRA("Couldn't delete tmp iface tag.");
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::tag_shared_ents(int resolve_dim,
+                                            int shared_dim,
+                                            Range *skin_ents,
+                                            std::map<std::vector<int>, Range> &proc_nranges) 
+{
+    // set sharing procs tags on other skin ents
+  ErrorCode result;
+  const EntityHandle *connect; int num_connect;
+  std::set<int> sharing_procs;
+  std::vector<EntityHandle> dum_connect;
+  std::vector<int> sp_vec;
+
+  for (int d = 3; d > 0; d--) {
+    if (resolve_dim == d) continue;
+    
+    for (Range::iterator rit = skin_ents[d].begin();
+         rit != skin_ents[d].end(); rit++) {
+        // get connectivity
+      result = mbImpl->get_connectivity(*rit, connect, num_connect, true,
+                                        &dum_connect);
+      RRA("Failed to get connectivity on non-vertex skin entities.");
+ 
+      int op = (resolve_dim < shared_dim ? Interface::UNION : Interface::INTERSECT);      
+      result = get_sharing_data(connect, num_connect, sharing_procs, op);
+      RRA("Failed to get sharing data in tag_shared_ents");
+      if (sharing_procs.empty()) continue;
+
+        // intersection is the owning proc(s) for this skin ent
+      sp_vec.clear();
+      std::copy(sharing_procs.begin(), sharing_procs.end(), std::back_inserter(sp_vec));
+      proc_nranges[sp_vec].insert(*rit);
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::tag_shared_verts(tuple_list &shared_ents,
+                                             Range *skin_ents,
+                                             std::map<std::vector<int>, Range> &proc_nranges,
+                                             Range &proc_verts) 
+{
+  Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+  ErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, 
+                                            sharedh_tag, sharedhs_tag, pstatus_tag);
+  RRA("Trouble getting shared proc tags in tag_shared_verts.");
+  
+  unsigned int j = 0, i = 0;
+  std::vector<int> sharing_procs, sharing_procs2;
+  std::vector<EntityHandle> sharing_handles, sharing_handles2;
+  
+  while (j < 2*shared_ents.n) {
+      // count & accumulate sharing procs
+    int this_idx = shared_ents.vi[j];
+    EntityHandle this_ent = skin_ents[0][this_idx];
+    while (j < 2*shared_ents.n && shared_ents.vi[j] == this_idx) {
+      j++;
+      sharing_procs.push_back( shared_ents.vi[j++] );
+      sharing_handles.push_back( shared_ents.vul[i++] );
+    }
+
+    if (sharing_procs.size() > 1) {
+        // add current proc/handle to list
+      sharing_procs.push_back(procConfig.proc_rank());
+      sharing_handles.push_back(this_ent);
+    }
+      
+      // sort sharing_procs and sharing_handles such that
+      // sharing_procs is in ascending order.  Use temporary
+      // lists and binary search to re-order sharing_handles.
+    sharing_procs2 = sharing_procs;
+    std::sort( sharing_procs2.begin(), sharing_procs2.end() );
+    sharing_handles2.resize( sharing_handles.size() );
+    for (size_t k = 0; k < sharing_handles.size(); ++k) {
+      size_t idx = std::lower_bound( sharing_procs2.begin(), 
+                                     sharing_procs2.end(), 
+                                     sharing_procs[k] ) - sharing_procs2.begin();
+      sharing_handles2[idx] = sharing_handles[k];
+    }
+    sharing_procs.swap( sharing_procs2 );
+    sharing_handles.swap( sharing_handles2 );
+    
+    
+    proc_nranges[sharing_procs].insert(this_ent);
+
+    unsigned char share_flag = PSTATUS_SHARED, 
+        ms_flag = (PSTATUS_SHARED | PSTATUS_MULTISHARED);
+    if (sharing_procs.size() == 1) {
+      result = mbImpl->tag_set_data(sharedp_tag, &this_ent, 1,
+                                    &sharing_procs[0]);
+      result = mbImpl->tag_set_data(sharedh_tag, &this_ent, 1,
+                                    &sharing_handles[0]);
+      result = mbImpl->tag_set_data(pstatus_tag, &this_ent, 1, &share_flag);
+      RRA("Couldn't set shared tag on shared vertex.");
+      sharedEnts.insert(this_ent);
+    }
+    else {
+        // pad lists 
+      assert( sharing_procs.size() <= MAX_SHARING_PROCS );
+      sharing_procs.resize( MAX_SHARING_PROCS, -1 );
+      sharing_handles.resize( MAX_SHARING_PROCS, 0 );
+      result = mbImpl->tag_set_data(sharedps_tag, &this_ent, 1,
+                                    &sharing_procs[0]);
+      result = mbImpl->tag_set_data(sharedhs_tag, &this_ent, 1,
+                                    &sharing_handles[0]);
+      result = mbImpl->tag_set_data(pstatus_tag, &this_ent, 1, &ms_flag);
+      RRA("Couldn't set multi-shared tag on shared vertex.");
+      sharedEnts.insert(this_ent);
+    }
+    RRA("Failed setting shared_procs tag on skin vertices.");
+
+      // reset sharing proc(s) tags
+    sharing_procs.clear();
+    sharing_handles.clear();
+  }
+
+  return MB_SUCCESS;
+}
+  
+  //! get processors with which this processor communicates; sets are sorted by processor
+ErrorCode ParallelComm::get_interface_procs(std::set<unsigned int> &procs_set,
+                                                bool get_buffs)
+{
+    // make sure the sharing procs vector is empty
+  procs_set.clear();
+
+    // pre-load vector of single-proc tag values
+  unsigned int i, j;
+  std::vector<int> iface_proc(interfaceSets.size());
+  ErrorCode result = mbImpl->tag_get_data(sharedp_tag(), interfaceSets, &iface_proc[0]);
+  RRA("Failed to get iface_proc for iface sets.");
+
+    // get sharing procs either from single-proc vector or by getting
+    // multi-proc tag value
+  int tmp_iface_procs[MAX_SHARING_PROCS];
+  std::fill(tmp_iface_procs, tmp_iface_procs+MAX_SHARING_PROCS, -1);
+  Range::iterator rit;
+  for (rit = interfaceSets.begin(), i = 0; rit != interfaceSets.end(); rit++, i++) {
+    if (-1 != iface_proc[i]) procs_set.insert((unsigned int) iface_proc[i]);
+    else {
+        // get the sharing_procs tag
+      result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1,
+                                    tmp_iface_procs);
+      RRA("Failed to get iface_procs for iface set.");
+      for (j = 0; j < MAX_SHARING_PROCS; j++) {
+        if (-1 != tmp_iface_procs[j] && tmp_iface_procs[j] != (int)procConfig.proc_rank()) 
+          procs_set.insert((unsigned int) tmp_iface_procs[j]);
+        else if (-1 == tmp_iface_procs[j]) {
+          std::fill(tmp_iface_procs, tmp_iface_procs+j, -1);
+          break;
+        }
+      }
+    }
+  }
+
+  if (get_buffs) {
+    for (std::set<unsigned int>::iterator sit = procs_set.begin(); sit != procs_set.end(); sit++)
+      get_buffers(*sit);
+  }
+  
+  return MB_SUCCESS;
+}
+  
+ErrorCode ParallelComm::get_pstatus_entities(int dim,
+                                                 unsigned char pstatus_val,
+                                                 Range &pstatus_ents)
+{
+  Range ents;
+  ErrorCode result;
+  
+  if (-1 == dim) result = mbImpl->get_entities_by_handle(0, ents);
+  else result = mbImpl->get_entities_by_dimension(0, dim, ents);
+  RRA(" ");
+  
+  std::vector<unsigned char> pstatus(ents.size());
+  result = mbImpl->tag_get_data(pstatus_tag(), ents, &pstatus[0]);
+  RRA("Couldn't get pastatus tag.");
+  Range::iterator rit = ents.begin();
+  int i = 0;
+  if (pstatus_val) {
+    for (; rit != ents.end(); i++, rit++)
+      if (pstatus[i]&pstatus_val &&
+          (-1 == dim || mbImpl->dimension_from_handle(*rit) == dim)) 
+        pstatus_ents.insert(*rit);
+  }
+  else {
+    for (; rit != ents.end(); i++, rit++)
+      if (!pstatus[i] &&
+          (-1 == dim || mbImpl->dimension_from_handle(*rit) == dim)) 
+        pstatus_ents.insert(*rit);
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::check_global_ids(EntityHandle this_set,
+                                             const int dimension, 
+                                             const int start_id,
+                                             const bool largest_dim_only,
+                                             const bool parallel)
+{
+    // global id tag
+  Tag gid_tag; int def_val = -1;
+  ErrorCode result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int),
+                                          MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
+                                          &def_val, true);
+  if (MB_ALREADY_ALLOCATED != result &&
+      MB_SUCCESS != result) {
+    RRA("Failed to create/get gid tag handle.");
+  }
+
+  Range dum_range;
+  if (MB_ALREADY_ALLOCATED == result) {
+    void *tag_ptr = &def_val;
+    ErrorCode tmp_result = mbImpl->get_entities_by_type_and_tag(this_set, MBVERTEX, 
+                                                                  &gid_tag, &tag_ptr, 1,
+                                                                  dum_range);
+    if (MB_SUCCESS != tmp_result) {
+      result = tmp_result;
+      RRA("Failed to get gid tag.");
+    }
+  }
+  
+  if (MB_ALREADY_ALLOCATED != result || !dum_range.empty()) {
+      // just created it, so we need global ids
+    result = assign_global_ids(this_set, dimension, start_id, largest_dim_only,
+                               parallel);
+    RRA("Failed assigning global ids.");
+  }
+
+  return MB_SUCCESS;
+}
+
+bool ParallelComm::is_iface_proc(EntityHandle this_set,
+                                   int to_proc) 
+{
+  int sharing_procs[MAX_SHARING_PROCS];
+  std::fill(sharing_procs, sharing_procs+MAX_SHARING_PROCS, -1);
+  ErrorCode result = mbImpl->tag_get_data(sharedp_tag(), &this_set, 1,
+                                            sharing_procs);
+  if (to_proc == sharing_procs[0]) return true;
+  
+  result = mbImpl->tag_get_data(sharedps_tag(), &this_set, 1,
+                                sharing_procs);
+  for (int i = 0; i < MAX_SHARING_PROCS; i++) {
+    if (to_proc == sharing_procs[i]) return true;
+    else if (-1 == sharing_procs[i]) return false;
+  }
+  
+  return false;
+}
+
+ErrorCode ParallelComm::filter_pstatus( Range &ents,
+                                            unsigned char pstat,
+                                            unsigned char op,
+                                            int to_proc,
+                                            Range *returned_ents)
+{
+  Range tmp_ents;
+
+  //assert(!ents.empty());
+  if (ents.empty()) {
+    if (returned_ents)
+      returned_ents->clear();
+    return MB_SUCCESS;
+  }
+
+    // Put into tmp_ents any entities which are not owned locally or
+    // who are already shared with to_proc
+  std::vector<unsigned char> shared_flags(ents.size()), shared_flags2;
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), ents,
+                                            &shared_flags[0]);
+  RRA("Failed to get pstatus flag.");
+  Range::const_iterator rit;
+  int i;
+  if (op == PSTATUS_OR) {
+    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++) 
+      if (((shared_flags[i] & ~pstat)^shared_flags[i]) & pstat) {
+        tmp_ents.insert(*rit);
+        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
+      }
+  }
+  else if (op == PSTATUS_AND) {
+    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++)
+      if ((shared_flags[i] & pstat) == pstat) {
+        tmp_ents.insert(*rit);
+        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
+      }
+  }
+  else if (op == PSTATUS_NOT) {
+    for (rit = ents.begin(), i = 0; rit != ents.end(); rit++, i++)
+      if (!(shared_flags[i] & pstat)) {
+        tmp_ents.insert(*rit);
+        if (-1 != to_proc) shared_flags2.push_back(shared_flags[i]);
+      }
+  }
+  else {
+    assert(false);
+    return MB_FAILURE;
+  }
+
+  if (-1 != to_proc) {
+
+    int sharing_procs[MAX_SHARING_PROCS];
+    std::fill(sharing_procs, sharing_procs+MAX_SHARING_PROCS, -1);
+    Range tmp_ents2;
+
+    for (rit = tmp_ents.begin(), i = 0; rit != tmp_ents.end(); rit++, i++) {
+        // we need to check sharing procs
+      if (shared_flags2[i] & PSTATUS_MULTISHARED) {
+        result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1,
+                                      sharing_procs);
+        assert(-1 != sharing_procs[0]);
+        RRA(" ");
+        for (unsigned int j = 0; j < MAX_SHARING_PROCS; j++) {
+            // if to_proc shares this entity, add it to list
+          if (sharing_procs[j] == to_proc) {
+            tmp_ents2.insert(*rit);
+          }
+          else if (sharing_procs[j] == -1) break;
+
+          sharing_procs[j] = -1;
+        }
+      }
+      else if (shared_flags2[i] & PSTATUS_SHARED) {
+        result = mbImpl->tag_get_data(sharedp_tag(), &(*rit), 1,
+                                      sharing_procs);
+        RRA(" ");
+        assert(-1 != sharing_procs[0]);
+        if (sharing_procs[0] == to_proc) tmp_ents2.insert(*rit);
+        sharing_procs[0] = -1;
+      }
+      else
+        assert("should never get here" && false);
+    }
+
+    tmp_ents.swap(tmp_ents2);
+  }
+  
+  if (returned_ents)
+    returned_ents->swap(tmp_ents);
+  else
+    ents.swap(tmp_ents);
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::exchange_ghost_cells(int ghost_dim, int bridge_dim,
+                                                 int num_layers,
+                                                 bool store_remote_handles,
+                                                 bool wait_all)
+{
+#ifdef DEBUG_MPE
+  if (!num_layers)
+    MPE_Log_event(IFACE_START, procConfig.proc_rank(), "Starting interface exchange.");
+  else
+    MPE_Log_event(GHOST_START, procConfig.proc_rank(), "Starting ghost exchange.");
+#endif
+
+#ifdef DEBUG_COMM
+//  std::ostringstream pfile("p");
+//  pfile << "p" << procConfig.proc_rank() << ".txt";
+//  std::cerr.open(pfile.str().c_str(), std::ios_base::trunc);
+  std::cerr << "Entering exchange_ghost_cells with num_layers = " 
+        << num_layers << std::endl; std::cerr.flush();
+#endif
+#ifdef DEBUG_MSGS
+  msgs.clear();
+  msgs.reserve(MAX_SHARING_PROCS);
+#endif
+
+    // if we're only finding out about existing ents, we have to be storing
+    // remote handles too
+  assert(num_layers > 0 || store_remote_handles);
+  
+  const bool is_iface = !num_layers;
+
+    // get the b-dimensional interface(s) with with_proc, where b = bridge_dim
+  
+  int success;
+  ErrorCode result = MB_SUCCESS;
+  int incoming1 = 0, incoming2 = 0;
+
+  reset_all_buffers();
+  
+    // when this function is called, buffProcs should already have any 
+    // communicating procs
+
+    //===========================================
+    // post ghost irecv's for ghost entities from all communicating procs
+    //===========================================
+#ifdef DEBUG_MPE
+  MPE_Log_event(ENTITIES_START, procConfig.proc_rank(), "Starting entity exchange.");
+#endif
+    // index reqs the same as buffer/sharing procs indices
+  std::vector<MPI_Request> recv_ent_reqs(2*buffProcs.size(), MPI_REQUEST_NULL),
+      recv_remoteh_reqs(2*buffProcs.size(), MPI_REQUEST_NULL);
+  std::vector<unsigned int>::iterator proc_it;
+  int ind, p;
+  sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
+  for (ind = 0, proc_it = buffProcs.begin(); 
+       proc_it != buffProcs.end(); proc_it++, ind++) {
+    incoming1++;
+    PRINT_DEBUG_IRECV(procConfig.proc_rank(), buffProcs[ind], 
+                      remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE, 
+                      MB_MESG_ENTS_SIZE, incoming1);
+    success = MPI_Irecv(remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE, 
+                        MPI_UNSIGNED_CHAR, buffProcs[ind],
+                        MB_MESG_ENTS_SIZE, procConfig.proc_comm(), 
+                        &recv_ent_reqs[2*ind]);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv in ghost exchange.");
+    }
+  }
+  
+    //===========================================
+    // get entities to be sent to neighbors
+    //===========================================
+
+  Range sent_ents[MAX_SHARING_PROCS], allsent, tmp_range;
+  std::vector<std::set<unsigned int> > entprocs(allsent.size());
+  int dum_ack_buff;
+  result = get_sent_ents(is_iface, bridge_dim, ghost_dim, num_layers,
+                         sent_ents, allsent, entprocs);
+  RRA("get_sent_ents failed.");
+  
+    //===========================================
+    // pack and send ents from this proc to others
+    //===========================================
+  for (p = 0, proc_it = buffProcs.begin(); 
+       proc_it != buffProcs.end(); proc_it++, p++) {
+
+      // reserve space on front for size and for initial buff size
+    localOwnedBuffs[p]->reset_buffer(sizeof(int));
+
+      // entities
+    result = pack_entities(sent_ents[p], localOwnedBuffs[p], 
+                           store_remote_handles, buffProcs[p], is_iface,
+                           &entprocs, &allsent); 
+    RRA("Packing entities failed.");
+
+#ifdef DEBUG_MSGS
+    msgs.resize(msgs.size()+1);
+    msgs.back() = new Buffer(*localOwnedBuffs[p]);
+      //result = print_buffer(&ownerSBuffs[ind][0], MB_MESG_ENTS_SIZE, *proc_it, true);
+#endif
+
+      // send the buffer (size stored in front in send_buffer)
+    result = send_buffer(*proc_it, localOwnedBuffs[p], 
+                         MB_MESG_ENTS_SIZE, sendReqs[2*p], 
+                         recv_ent_reqs[2*p+1], &dum_ack_buff,
+                         incoming1,
+                         MB_MESG_REMOTEH_SIZE, 
+                         (!is_iface && store_remote_handles ? 
+                          localOwnedBuffs[p] : NULL),
+                         &recv_remoteh_reqs[2*p], &incoming2);
+    RRA("Failed to Isend in ghost exchange.");
+  }
+    
+
+    //===========================================
+    // receive/unpack new entities
+    //===========================================
+    // number of incoming messages for ghosts is the number of procs we 
+    // communicate with; for iface, it's the number of those with lower rank
+  MPI_Status status;
+  std::vector<std::vector<EntityHandle> > recd_ents(buffProcs.size());
+  std::vector<std::vector<EntityHandle> > L1hloc(buffProcs.size()), L1hrem(buffProcs.size());
+  std::vector<std::vector<int> > L1p(buffProcs.size());
+  std::vector<EntityHandle> L2hloc, L2hrem;
+  std::vector<unsigned int> L2p;
+  Range new_ents;
+  
+  while (incoming1) {
+      // wait for all recvs of ghost ents before proceeding to sending remote handles,
+      // b/c some procs may have sent to a 3rd proc ents owned by me;
+    PRINT_DEBUG_WAITANY(recv_ent_reqs, MB_MESG_ENTS_SIZE, procConfig.proc_rank());
+    
+    success = MPI_Waitany(2*buffProcs.size(), &recv_ent_reqs[0], &ind, &status);
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitany in ghost exchange.");
+    }
+
+    PRINT_DEBUG_RECD(status);
+    
+      // ok, received something; decrement incoming counter
+    incoming1--;
+    bool done = false;
+
+      // In case ind is for ack, we need index of one before it
+    unsigned int base_ind = 2*(ind/2);
+    result = recv_buffer(MB_MESG_ENTS_SIZE,
+                         status,
+                         remoteOwnedBuffs[ind/2],
+                         recv_ent_reqs[ind], recv_ent_reqs[ind+1],
+                         incoming1,
+                         localOwnedBuffs[ind/2], sendReqs[base_ind], sendReqs[base_ind+1],
+                         done,
+                         (!is_iface && store_remote_handles ? 
+                          localOwnedBuffs[ind/2] : NULL),
+                         MB_MESG_REMOTEH_SIZE,
+                         &recv_remoteh_reqs[base_ind], &incoming2);
+    RRA("Failed to receive buffer.");
+
+    if (done) {
+#ifdef DEBUG_MSGS
+    msgs.resize(msgs.size()+1);
+    msgs.back() = new Buffer(*remoteOwnedBuffs[ind/2]);
+        //print_buffer(&ghostRBuffs[ind/2][0], MB_MESG_ENTS_SIZE, buffProcs[ind/2], false);
+#endif
+
+        // message completely received - process buffer that was sent
+    remoteOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
+    result = unpack_entities(remoteOwnedBuffs[ind/2]->buff_ptr,
+                             store_remote_handles, ind/2, is_iface,
+                             L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents);
+      if (MB_SUCCESS != result) {
+        std::cout << "Failed to unpack entities.  Buffer contents:" << std::endl;
+        print_buffer(remoteOwnedBuffs[ind/2]->mem_ptr, MB_MESG_ENTS_SIZE, buffProcs[ind/2], false);
+        return result;
+      }
+
+      if (recv_ent_reqs.size() != 2*buffProcs.size()) {
+          // post irecv's for remote handles from new proc; shouldn't be iface, 
+          // since we know about all procs we share with
+        assert(!is_iface);
+        recv_remoteh_reqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
+        for (unsigned int i = recv_ent_reqs.size(); i < 2*buffProcs.size(); i+=2) {
+          localOwnedBuffs[i/2]->reset_buffer();
+          incoming2++;
+          PRINT_DEBUG_IRECV(procConfig.proc_rank(), buffProcs[i/2], 
+                            localOwnedBuffs[i/2]->mem_ptr, INITIAL_BUFF_SIZE,
+                            MB_MESG_REMOTEH_SIZE, incoming2);
+          success = MPI_Irecv(localOwnedBuffs[i/2]->mem_ptr, INITIAL_BUFF_SIZE, 
+                              MPI_UNSIGNED_CHAR, buffProcs[i/2],
+                              MB_MESG_REMOTEH_SIZE, procConfig.proc_comm(), 
+                              &recv_remoteh_reqs[i]);
+          if (success != MPI_SUCCESS) {
+            result = MB_FAILURE;
+            RRA("Failed to post irecv for remote handles in ghost exchange.");
+          }
+        }
+        recv_ent_reqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
+        sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
+      }
+    }
+  }
+  
+    // add requests for any new addl procs
+  if (recv_ent_reqs.size() != 2*buffProcs.size()) {
+      // shouldn't get here...
+    result = MB_FAILURE;
+    RRA("Requests length doesn't match proc count in ghost exchange.");
+  }
+    
+#ifdef DEBUG_MPE
+  MPE_Log_event(ENTITIES_END, procConfig.proc_rank(), "Ending entity exchange.");
+#endif
+
+  if (is_iface) {
+      // need to check over entities I sent and make sure I received 
+      // handles for them from all expected procs; if not, need to clean
+      // them up
+    result = check_clean_iface(allsent);
+    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
+    
+      // now set the shared/interface tag on non-vertex entities on interface
+    result = tag_iface_entities();
+    RRA("Failed to tag iface entities.");
+
+#ifndef NDEBUG
+    result = check_sent_ents(allsent);
+    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
+    result = check_all_shared_handles();
+    if (MB_SUCCESS != result) std::cout << "Failed check." << std::endl;
+#endif
+
+#ifdef DEBUG_MPE
+    MPE_Log_event(IFACE_END, procConfig.proc_rank(), "Ending interface exchange.");
+#endif
+#ifdef DEBUG_COMM
+    std::cerr << "Exiting exchange_ghost_cells" << std::endl; std::cerr.flush();
+#endif
+
+      //===========================================
+      // wait if requested
+      //===========================================
+    if (wait_all) {
+#ifdef DEBUG_BARRIER
+      success = MPI_Barrier(procConfig.proc_comm());
+#else
+      success = MPI_Waitall(2*buffProcs.size(), &recv_ent_reqs[0], &status);
+      success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], &status);
+#endif
+      if (MPI_SUCCESS != success) {
+        result = MB_FAILURE;
+        RRA("Failed in waitall in ghost exchange.");
+      }
+    }
+    return MB_SUCCESS;
+  }
+
+    //===========================================
+    // send local handles for new ghosts to owner, then add
+    // those to ghost list for that owner
+    //===========================================
+  for (p = 0, proc_it = buffProcs.begin(); 
+       proc_it != buffProcs.end(); proc_it++, p++) {
+
+      // reserve space on front for size and for initial buff size
+    remoteOwnedBuffs[p]->reset_buffer(sizeof(int));
+
+    result = pack_remote_handles(L1hloc[p], L1hrem[p], L1p[p], *proc_it,
+                                 remoteOwnedBuffs[p]);
+    RRA("Failed to pack remote handles.");
+    remoteOwnedBuffs[p]->set_stored_size();
+    
+#ifdef DEBUG_MSGS
+    msgs.resize(msgs.size()+1);
+    msgs.back() = new Buffer(*remoteOwnedBuffs[p]);
+      //print_buffer(&ownerSBuffs[ind][0], MB_MESG_REMOTEH_SIZE, buffProcs[ind], true);
+#endif  
+    result = send_buffer(buffProcs[p], remoteOwnedBuffs[p], 
+                         MB_MESG_REMOTEH_SIZE, 
+                         sendReqs[2*p], recv_remoteh_reqs[2*p+1], 
+                         &dum_ack_buff, incoming2);
+    RRA("Failed to send remote handles.");
+  }
+  
+    //===========================================
+    // process remote handles of my ghosteds
+    //===========================================
+  while (incoming2) {
+    PRINT_DEBUG_WAITANY(recv_remoteh_reqs, MB_MESG_REMOTEH_SIZE, procConfig.proc_rank());
+    success = MPI_Waitany(2*buffProcs.size(), &recv_remoteh_reqs[0], &ind, &status);
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitany in ghost exchange.");
+    }
+    
+      // ok, received something; decrement incoming counter
+    incoming2--;
+
+    PRINT_DEBUG_RECD(status);
+    
+    bool done = false;
+    unsigned int base_ind = 2*(ind/2);
+    result = recv_buffer(MB_MESG_REMOTEH_SIZE, status, 
+                         localOwnedBuffs[ind/2], 
+                         recv_remoteh_reqs[ind], recv_remoteh_reqs[ind+1], incoming2,
+                         remoteOwnedBuffs[ind/2], 
+                         sendReqs[base_ind], sendReqs[base_ind+1],
+                         done);
+    RRA("Failed to receive remote handles.");
+    if (done) {
+        // incoming remote handles
+#ifdef DEBUG_MSGS
+    msgs.resize(msgs.size()+1);
+    msgs.back() = new Buffer(*localOwnedBuffs[ind]);
+      //print_buffer(&remotehRBuffs[ind/2][0], MB_MESG_REMOTEH_SIZE, buffProcs[ind/2], false);
+#endif  
+    localOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
+    result = unpack_remote_handles(buffProcs[ind/2], 
+                                   localOwnedBuffs[ind/2]->buff_ptr,
+                                   L2hloc, L2hrem, L2p);
+      RRA("Failed to unpack remote handles.");
+    }
+  }
+    
+#ifdef DEBUG_MPE
+  MPE_Log_event(RHANDLES_END, procConfig.proc_rank(), "Ending remote handles.");
+#endif
+#ifdef DEBUG_MPE
+  MPE_Log_event(GHOST_END, procConfig.proc_rank(), 
+                "Ending ghost exchange (still doing checks).");
+#endif
+
+    //===========================================
+    // wait if requested
+    //===========================================
+  if (wait_all) {
+#ifdef DEBUG_BARRIER
+    success = MPI_Barrier(procConfig.proc_comm());
+#else
+    success = MPI_Waitall(2*buffProcs.size(), &recv_remoteh_reqs[0], &status);
+    success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], &status);
+#endif
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitall in ghost exchange.");
+    }
+  }
+
+#ifndef NDEBUG
+  result = check_sent_ents(allsent);
+  RRA("Failed check on shared entities.");
+  result = check_all_shared_handles();
+  RRA("Failed check on all shared handles.");
+#endif
+#ifdef DEBUG_COMM
+  std::cerr << "Exiting exchange_ghost_cells" << std::endl; std::cerr.flush();
+#endif
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::send_buffer(const unsigned int to_proc,
+                                        Buffer *send_buff,
+                                        int mesg_tag,
+                                        MPI_Request &send_req,
+                                        MPI_Request &ack_req,
+                                        int *ack_buff,
+                                        int &this_incoming,
+                                        int next_mesg_tag,
+                                        Buffer *next_recv_buff,
+                                        MPI_Request *next_recv_req,
+                                        int *next_incoming) 
+{
+  ErrorCode result = MB_SUCCESS;
+  int success;
+
+    // if small message, post recv for remote handle message
+  if (send_buff->get_stored_size() <= (int)INITIAL_BUFF_SIZE && next_recv_buff) {
+    (*next_incoming)++;
+    PRINT_DEBUG_IRECV(procConfig.proc_rank(), to_proc, next_recv_buff->mem_ptr,
+                      INITIAL_BUFF_SIZE, next_mesg_tag, *next_incoming);
+    success = MPI_Irecv(next_recv_buff->mem_ptr, INITIAL_BUFF_SIZE, 
+                        MPI_UNSIGNED_CHAR, to_proc,
+                        next_mesg_tag, procConfig.proc_comm(), 
+                        next_recv_req);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv for next message in ghost exchange.");
+    }
+  }
+    // if large, we'll need an ack before sending the rest
+  else if (send_buff->get_stored_size() > (int)INITIAL_BUFF_SIZE) {
+    this_incoming++;
+    PRINT_DEBUG_IRECV(procConfig.proc_rank(), to_proc, (unsigned char*)ack_buff,
+                      sizeof(int), mesg_tag-1, this_incoming);
+    success = MPI_Irecv(ack_buff, sizeof(int), 
+                        MPI_UNSIGNED_CHAR, to_proc,
+                        mesg_tag-1, procConfig.proc_comm(), 
+                        &ack_req);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv for entity ack in ghost exchange.");
+    }
+  }
+
+    // send the buffer
+  PRINT_DEBUG_ISEND(procConfig.proc_rank(), to_proc, send_buff->mem_ptr, mesg_tag,
+                    std::min(send_buff->get_stored_size(), (int)INITIAL_BUFF_SIZE));
+  assert(0 <= send_buff->get_stored_size() && 
+         send_buff->get_stored_size() <= (int)send_buff->alloc_size);
+  success = MPI_Isend(send_buff->mem_ptr, 
+                      std::min(send_buff->get_stored_size(), 
+                               (int)INITIAL_BUFF_SIZE),
+                      MPI_UNSIGNED_CHAR, to_proc, 
+                      mesg_tag, procConfig.proc_comm(), &send_req);
+  if (success != MPI_SUCCESS) return MB_FAILURE;
+
+  return result;
+}
+
+ErrorCode ParallelComm::recv_buffer(int mesg_tag_expected,
+                                        const MPI_Status &mpi_status,
+                                        Buffer *recv_buff,
+                                        MPI_Request &recv_req,
+                                        MPI_Request &ack_recvd_req,
+                                        int &this_incoming,
+                                        Buffer *send_buff,
+                                        MPI_Request &send_req,
+                                        MPI_Request &sent_ack_req,
+                                        bool &done,
+                                        Buffer *next_buff,
+                                        int next_tag,
+                                        MPI_Request *next_req,
+                                        int *next_incoming) 
+{
+    // process a received message; if there will be more coming, 
+    // post a receive for 2nd part then send an ack message
+    //
+  int from_proc = mpi_status.MPI_SOURCE;
+  int success;
+  ErrorCode result = MB_SUCCESS;
+
+    // set the buff_ptr on the recv_buffer; needs to point beyond any
+    // valid data already in the buffer
+  recv_buff->reset_ptr(std::min(recv_buff->get_stored_size(), 
+                                (int)recv_buff->alloc_size));
+  
+  if (mpi_status.MPI_TAG == mesg_tag_expected &&
+      recv_buff->get_stored_size() > (int)INITIAL_BUFF_SIZE) {
+      // 1st message & large - allocate buffer, post irecv for 2nd message,
+      // then send ack
+    recv_buff->reserve(recv_buff->get_stored_size());
+    assert(recv_buff->alloc_size > INITIAL_BUFF_SIZE);
+
+      // will expect a 2nd message
+    this_incoming++;
+
+    PRINT_DEBUG_IRECV(procConfig.proc_rank(), from_proc, 
+                      recv_buff->mem_ptr+INITIAL_BUFF_SIZE,
+                      recv_buff->get_stored_size() - INITIAL_BUFF_SIZE,
+                      mesg_tag_expected+1, this_incoming);
+    success = MPI_Irecv(recv_buff->mem_ptr+INITIAL_BUFF_SIZE, 
+                        recv_buff->get_stored_size() - INITIAL_BUFF_SIZE, 
+                        MPI_UNSIGNED_CHAR, from_proc,
+                        mesg_tag_expected+1, procConfig.proc_comm(), 
+                        &recv_req);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post 2nd iRecv in ghost exchange.");
+    }
+
+      // send ack, doesn't matter what data actually is
+    PRINT_DEBUG_ISEND(procConfig.proc_rank(), from_proc, recv_buff->mem_ptr, 
+                      mesg_tag_expected-1, sizeof(int));
+    success = MPI_Isend(recv_buff->mem_ptr, sizeof(int),
+                        MPI_UNSIGNED_CHAR, from_proc, 
+                        mesg_tag_expected-1, procConfig.proc_comm(), &sent_ack_req);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to send ack in ghost exchange.");
+    }
+  }
+
+  else if (mpi_status.MPI_TAG == mesg_tag_expected-1) {
+      // got an ack back, send the 2nd half of message
+
+      // should be a large message if we got this
+    assert(*((size_t*)send_buff->mem_ptr) > INITIAL_BUFF_SIZE);
+
+      // post irecv for next message, then send 2nd message
+    if (next_buff) {
+        // we'll expect a return message
+      (*next_incoming)++;
+      PRINT_DEBUG_IRECV(procConfig.proc_rank(), from_proc, next_buff->mem_ptr,
+                        INITIAL_BUFF_SIZE, next_tag, *next_incoming);
+
+      success = MPI_Irecv(next_buff->mem_ptr, 
+                          INITIAL_BUFF_SIZE, 
+                          MPI_UNSIGNED_CHAR, from_proc,
+                          next_tag, procConfig.proc_comm(), 
+                          next_req);
+      if (success != MPI_SUCCESS) {
+        result = MB_FAILURE;
+        RRA("Failed to post next irecv in ghost exchange.");
+      }
+
+    }
+    
+      // send 2nd message
+    PRINT_DEBUG_ISEND(procConfig.proc_rank(), from_proc, 
+                      send_buff->mem_ptr+INITIAL_BUFF_SIZE,
+                      mesg_tag_expected+1,
+                      send_buff->get_stored_size() - INITIAL_BUFF_SIZE);
+    
+    assert(send_buff->get_stored_size()-INITIAL_BUFF_SIZE < send_buff->alloc_size &&
+           0 <= send_buff->get_stored_size());
+    success = MPI_Isend(send_buff->mem_ptr+INITIAL_BUFF_SIZE, 
+                        send_buff->get_stored_size() - INITIAL_BUFF_SIZE,
+                        MPI_UNSIGNED_CHAR, from_proc, mesg_tag_expected+1, 
+                        procConfig.proc_comm(), &send_req);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to send 2nd message in ghost exchange.");
+    }
+  }
+  else if ((mpi_status.MPI_TAG == mesg_tag_expected && 
+            recv_buff->get_stored_size() <= (int)INITIAL_BUFF_SIZE) ||
+           mpi_status.MPI_TAG == mesg_tag_expected+1) {
+      // message completely received - signal that we're done
+    done = true;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::check_clean_iface(Range &allsent) 
+{
+    // allsent is all entities I think are on interface; go over them, looking
+    // for zero-valued handles, and fix any I find
+
+  ErrorCode result;
+  Range::iterator rit;
+  unsigned char pstatus;
+  int sharedp[MAX_SHARING_PROCS], nump;
+  EntityHandle sharedh[MAX_SHARING_PROCS];
+  for (rit = allsent.begin(); rit != allsent.end(); rit++) {
+    result = get_sharing_data(*rit, sharedp, sharedh, pstatus, nump);
+    RRA("");
+    assert("Should be shared with at least one other proc" && 
+           (nump > 1 || sharedp[0] != (int)procConfig.proc_rank()));
+    int numz = 0;
+    for (int i = 0; i < nump; i++) {
+      if (!sharedh[i]) numz++;
+      else if (numz) {
+          // shift downward
+        sharedh[i-numz] = sharedh[i];
+        sharedp[i-numz] = sharedp[i];
+      }
+    }
+    if (numz) {
+      for (int i = numz; i > 0; i--) {
+        sharedp[nump-i] = -1;
+        sharedh[nump-i] = 0;
+      }
+      result = set_sharing_data(*rit, pstatus, nump, nump-numz, sharedp, sharedh);
+      RRA("");
+    }
+  }
+  
+  return result;
+}
+
+ErrorCode ParallelComm::set_sharing_data(EntityHandle ent, unsigned char pstatus,
+                                             int old_nump, int new_nump,
+                                             int *ps, EntityHandle *hs) 
+{
+  assert("Should call this function only when reducing sharing procs." &&
+         new_nump < old_nump);
+
+    // set sharing data to what's passed in; may have to clean up existing sharing tags
+    // if things changed too much
+  
+  ErrorCode result;
+  if (pstatus & PSTATUS_MULTISHARED && new_nump < 3) {
+      // need to remove multishared tags
+    result = mbImpl->tag_delete_data(sharedps_tag(), &ent, 1);
+    RRA("");
+    result = mbImpl->tag_delete_data(sharedhs_tag(), &ent, 1);
+    RRA("");
+    pstatus ^= PSTATUS_MULTISHARED;
+    if (new_nump < 2) pstatus = 0x0;
+  }
+  else if (pstatus & PSTATUS_SHARED && new_nump < 2) {
+    hs[0] = 0;
+    ps[0] = -1;
+    pstatus = 0x0;
+  }
+
+  if (new_nump > 2) {
+    result = mbImpl->tag_set_data(sharedps_tag(), &ent, 1, ps);
+    RRA("");
+    result = mbImpl->tag_set_data(sharedhs_tag(), &ent, 1, hs);
+    RRA("");
+#ifndef NDEBUG
+    {
+        // check for duplicates in proc list
+      std::set<unsigned int> dumprocs;
+      int dp = 0;
+      for (; dp < old_nump && -1 != ps[dp]; dp++)
+        dumprocs.insert(ps[dp]);
+      assert(dp == (int)dumprocs.size());
+    }
+#endif      
+  }
+  else {
+    unsigned int j = (ps[0] == (int)procConfig.proc_rank() ? 1 : 0);
+    assert(-1 != ps[j]);
+    result = mbImpl->tag_set_data(sharedp_tag(), &ent, 1, ps+j);
+    RRA("");
+    result = mbImpl->tag_set_data(sharedh_tag(), &ent, 1, hs+j);
+    RRA("");
+  }
+  
+  result = mbImpl->tag_set_data(pstatus_tag(), &ent, 1, &pstatus);
+  RRA("");
+
+  if (old_nump > 1 && new_nump < 2) sharedEnts.erase(ent);
+
+  return result;
+}
+
+ErrorCode ParallelComm::get_sent_ents(const bool is_iface, 
+                                          const int bridge_dim, const int ghost_dim,
+                                          const int num_layers,
+                                          Range *sent_ents, Range &allsent,
+                                          std::vector<std::set<unsigned int> > &entprocs) 
+{
+  ErrorCode result;
+  int ind;
+  std::vector<unsigned int>::iterator proc_it;
+  Range tmp_range;
+  
+    // done in a separate loop over procs because sometimes later procs 
+    // need to add info to earlier procs' messages
+  for (ind = 0, proc_it = buffProcs.begin(); 
+       proc_it != buffProcs.end(); proc_it++, ind++) {
+    if (!is_iface) {
+      result = get_ghosted_entities(bridge_dim, ghost_dim, buffProcs[ind],
+                                    num_layers, sent_ents[ind]);
+      RRA("Failed to get ghost layers.");
+    }
+    else {
+      result = get_iface_entities(buffProcs[ind], -1, sent_ents[ind]);
+      RRA("Failed to get interface layers.");
+    }
+
+      // filter out entities already shared with destination
+    tmp_range.clear();
+    result = filter_pstatus(sent_ents[ind], PSTATUS_SHARED, PSTATUS_AND,
+                            buffProcs[ind], &tmp_range);
+    RRA("Couldn't filter on owner.");
+    if (!tmp_range.empty()) 
+      sent_ents[ind] = subtract( sent_ents[ind], tmp_range);
+
+    allsent.merge(sent_ents[ind]);
+  }
+
+    //===========================================
+    // need to get procs each entity is sent to
+    //===========================================
+  Range::iterator rit;
+  entprocs.resize(allsent.size());
+  for (ind = 0, proc_it = buffProcs.begin(); 
+       proc_it != buffProcs.end(); proc_it++, ind++) {
+    for (rit = sent_ents[ind].begin(); rit != sent_ents[ind].end(); rit++) {
+      int rind = allsent.index(*rit);
+      assert(rind < (int) allsent.size() && rind >= 0);
+      entprocs[rind].insert(*proc_it);
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::exchange_ghost_cells(ParallelComm **pcs,
+                                                 unsigned int num_procs,
+                                                 int ghost_dim, int bridge_dim,
+                                                 int num_layers,
+                                                 bool store_remote_handles)
+{
+    // static version of function, exchanging info through buffers rather 
+    // than through messages
+
+    // if we're only finding out about existing ents, we have to be storing
+    // remote handles too
+  assert(num_layers > 0 || store_remote_handles);
+  
+  const bool is_iface = !num_layers;
+  
+  unsigned int ind;
+  ParallelComm *pc;
+  ErrorCode result = MB_SUCCESS;
+
+    // when this function is called, buffProcs should already have any 
+    // communicating procs
+
+    //===========================================
+    // get entities to be sent to neighbors
+    //===========================================
+
+    // done in a separate loop over procs because sometimes later procs 
+    // need to add info to earlier procs' messages
+  Range sent_ents[MAX_SHARING_PROCS][MAX_SHARING_PROCS], 
+      allsent[MAX_SHARING_PROCS];
+
+    //===========================================
+    // get entities to be sent to neighbors
+    //===========================================
+
+  std::vector<std::set<unsigned int> > entprocs[MAX_SHARING_PROCS];
+  for (unsigned int p = 0; p < num_procs; p++) {
+    pc = pcs[p];
+    result = pc->get_sent_ents(is_iface, bridge_dim, ghost_dim, num_layers,
+                               sent_ents[p], allsent[p], entprocs[p]);
+    RRAI(pc->get_moab(), "get_sent_ents failed.");
+  
+    //===========================================
+    // pack entities into buffers
+    //===========================================
+
+    for (ind = 0; ind < pc->buffProcs.size(); ind++) {
+        // entities
+      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
+      result = pc->pack_entities(sent_ents[p][ind], pc->localOwnedBuffs[ind],
+                                 store_remote_handles, pc->buffProcs[ind], is_iface,
+                                 &entprocs[p], &allsent[p]); 
+      RRAI(pc->get_moab(), "Packing entities failed.");
+    }
+  }
+
+    //===========================================
+    // receive/unpack new entities
+    //===========================================
+    // number of incoming messages for ghosts is the number of procs we 
+    // communicate with; for iface, it's the number of those with lower rank
+  std::vector<std::vector<EntityHandle> > L1hloc[MAX_SHARING_PROCS], L1hrem[MAX_SHARING_PROCS];
+  std::vector<std::vector<int> > L1p[MAX_SHARING_PROCS];
+  std::vector<EntityHandle> L2hloc[MAX_SHARING_PROCS], L2hrem[MAX_SHARING_PROCS];
+  std::vector<unsigned int> L2p[MAX_SHARING_PROCS];
+  Range new_ents[MAX_SHARING_PROCS];
+  
+  for (unsigned int p = 0; p < num_procs; p++) {
+    L1hloc[p].resize(pcs[p]->buffProcs.size());
+    L1hrem[p].resize(pcs[p]->buffProcs.size());
+    L1p[p].resize(pcs[p]->buffProcs.size());
+  }
+  
+  for (unsigned int p = 0; p < num_procs; p++) {
+  
+    ParallelComm *pc = pcs[p];
+    
+    for (ind = 0; ind < pc->buffProcs.size(); ind++) {
+        // incoming ghost entities; unpack; returns entities received
+        // both from sending proc and from owning proc (which may be different)
+
+        // buffer could be empty, which means there isn't any message to
+        // unpack (due to this comm proc getting added as a result of indirect
+        // communication); just skip this unpack
+      if (pc->localOwnedBuffs[ind]->get_stored_size() == 0) continue;
+
+      unsigned int to_p = pc->buffProcs[ind];
+      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
+      result = pcs[to_p]->unpack_entities(pc->localOwnedBuffs[ind]->buff_ptr,
+                                          store_remote_handles, ind, is_iface,
+                                          L1hloc[to_p], L1hrem[to_p], L1p[to_p], L2hloc[to_p], 
+                                          L2hrem[to_p], L2p[to_p], new_ents[to_p]);
+      RRAI(pc->get_moab(), "Failed to unpack entities.");
+    }
+  }
+
+  if (is_iface) {
+      // need to check over entities I sent and make sure I received 
+      // handles for them from all expected procs; if not, need to clean
+      // them up
+    for (unsigned int p = 0; p < num_procs; p++) {
+      result = pcs[p]->check_clean_iface(allsent[p]);
+      RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
+    }
+
+#ifndef NDEBUG
+    for (unsigned int p = 0; p < num_procs; p++) {
+      result = pcs[p]->check_sent_ents(allsent[p]);
+      RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
+    }
+    result = check_all_shared_handles(pcs, num_procs);
+    RRAI(pcs[0]->get_moab(), "Failed check on all shared handles.");
+#endif
+    return MB_SUCCESS;
+  }
+  
+      //===========================================
+      // send local handles for new ghosts to owner, then add
+      // those to ghost list for that owner
+      //===========================================
+  std::vector<unsigned int>::iterator proc_it;
+  for (unsigned int p = 0; p < num_procs; p++) {
+    pc = pcs[p];
+  
+    for (ind = 0, proc_it = pc->buffProcs.begin(); 
+         proc_it != pc->buffProcs.end(); proc_it++, ind++) {
+        // skip if iface layer and higher-rank proc
+      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
+      result = pc->pack_remote_handles(L1hloc[p][ind], L1hrem[p][ind], L1p[p][ind], *proc_it,
+                                       pc->localOwnedBuffs[ind]);
+      RRAI(pc->get_moab(), "Failed to pack remote handles.");
+    }
+  }
+  
+    //===========================================
+    // process remote handles of my ghosteds
+    //===========================================
+  for (unsigned int p = 0; p < num_procs; p++) {
+    pc = pcs[p];
+  
+    for (ind = 0, proc_it = pc->buffProcs.begin(); 
+         proc_it != pc->buffProcs.end(); proc_it++, ind++) {
+        // incoming remote handles
+      unsigned int to_p = pc->buffProcs[ind];
+      pc->localOwnedBuffs[ind]->reset_ptr(sizeof(int));
+      result = pcs[to_p]->unpack_remote_handles(p, 
+                                                pc->localOwnedBuffs[ind]->buff_ptr,
+                                                L2hloc[to_p], L2hrem[to_p], L2p[to_p]);
+      RRAI(pc->get_moab(), "Failed to unpack remote handles.");
+    }
+  }
+    
+#ifndef NDEBUG
+  for (unsigned int p = 0; p < num_procs; p++) {
+    result = pcs[p]->check_sent_ents(allsent[p]);
+    RRAI(pcs[p]->get_moab(), "Failed check on shared entities.");
+  }
+  
+  result = ParallelComm::check_all_shared_handles(pcs, num_procs);
+  RRAI(pcs[0]->get_moab(), "Failed check on all shared handles.");
+#endif
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_iface_entities(int other_proc,
+                                               int dim,
+                                               Range &iface_ents) 
+{
+  Range iface_sets;
+  ErrorCode result = MB_SUCCESS;
+  
+  for (Range::iterator rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) {
+    if (-1 != other_proc && !is_iface_proc(*rit, other_proc)) continue;
+    
+    if (-1 == dim) result = mbImpl->get_entities_by_handle(*rit, iface_ents);
+    else result = mbImpl->get_entities_by_dimension(*rit, dim, iface_ents);
+    RRA(" Failed to get entities in iface set.");
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::check_sent_ents(Range &allsent) 
+{
+    // check entities to make sure there are no zero-valued remote handles
+    // where they shouldn't be
+  std::vector<unsigned char> pstat(allsent.size());
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), allsent, &pstat[0]);
+  RRA("Trouble getting pstatus.");
+  std::vector<EntityHandle> handles(allsent.size());
+  result = mbImpl->tag_get_data(sharedh_tag(), allsent, &handles[0]);
+  RRA("Trouble getting shared handles.");
+  std::vector<int> procs(allsent.size());
+  result = mbImpl->tag_get_data(sharedp_tag(), allsent, &procs[0]);
+  RRA("Trouble getting shared procs.");
+
+  Range bad_entities;
+  
+  Range::iterator rit;
+  unsigned int i;
+  EntityHandle dum_hs[MAX_SHARING_PROCS];
+  int dum_ps[MAX_SHARING_PROCS];
+  
+  for (rit = allsent.begin(), i = 0; rit != allsent.end(); rit++, i++) {
+    if (-1 != procs[i] && 0 == handles[i]) bad_entities.insert(*rit);
+    else {
+        // might be multi-shared...
+      result = mbImpl->tag_get_data(sharedps_tag(), &(*rit), 1, dum_ps);
+      if (MB_TAG_NOT_FOUND == result) continue;
+      RRA("Trouble getting sharedps.");
+      result = mbImpl->tag_get_data(sharedhs_tag(), &(*rit), 1, dum_hs);
+      RRA("Trouble getting sharedhs.");
+
+        // find first non-set proc
+      int *ns_proc = std::find(dum_ps, dum_ps+MAX_SHARING_PROCS, -1);
+      int num_procs = ns_proc-dum_ps;
+      assert(num_procs <= MAX_SHARING_PROCS);
+        // now look for zero handles in active part of dum_hs
+      EntityHandle *ns_handle = std::find(dum_hs, dum_hs+num_procs, 0);
+      int num_handles = ns_handle-dum_hs;
+      assert(num_handles <= num_procs);
+      if (num_handles != num_procs) bad_entities.insert(*rit);
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::pack_remote_handles(std::vector<EntityHandle> &L1hloc,
+                                                std::vector<EntityHandle> &L1hrem,
+                                                std::vector<int> &L1p,
+                                                unsigned int to_proc,
+                                                Buffer *buff) 
+{
+    // 2 vectors of handles plus ints
+  buff->check_space(((L1p.size()+1)*sizeof(int) + 
+                     (L1hloc.size()+1)*sizeof(EntityHandle) + 
+                     (L1hrem.size()+1)*sizeof(EntityHandle)));
+  
+    // should be in pairs of handles
+  PACK_INT(buff->buff_ptr, L1hloc.size());
+  PACK_INTS(buff->buff_ptr, &L1p[0], L1p.size());
+  PACK_EH(buff->buff_ptr, &L1hrem[0], L1hrem.size());
+  PACK_EH(buff->buff_ptr, &L1hloc[0], L1hloc.size());
+  
+  buff->set_stored_size();
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::unpack_remote_handles(unsigned int from_proc,
+                                                  unsigned char *&buff_ptr,
+                                                  std::vector<EntityHandle> &L2hloc,
+                                                  std::vector<EntityHandle> &L2hrem,
+                                                  std::vector<unsigned int> &L2p)
+{
+    // incoming remote handles; use to set remote handles
+  int num_eh;
+  UNPACK_INT(buff_ptr, num_eh);
+
+  unsigned char *buff_proc = buff_ptr;
+  buff_ptr += num_eh * sizeof(int);
+  unsigned char *buff_rem = buff_ptr + num_eh * sizeof(EntityHandle);
+  ErrorCode result;
+  EntityHandle hpair[2], dum_h;
+  int proc;
+  for (int i = 0; i < num_eh; i++) {
+    UNPACK_INT(buff_proc, proc);
+    UNPACK_EH(buff_ptr, hpair, 1);
+    UNPACK_EH(buff_rem, hpair+1, 1);
+
+    if (-1 != proc) {
+      result = find_existing_entity(false, proc, hpair[0], 3, NULL, 0,
+                                    mbImpl->type_from_handle(hpair[1]),
+                                    L2hloc, L2hrem, L2p, dum_h);
+      RRA("Didn't get existing entity.");
+      if (dum_h) hpair[0] = dum_h;
+      else hpair[0] = 0;
+    }
+    if (!(hpair[0] && hpair[1])) return MB_FAILURE;
+    int this_proc = from_proc;
+    result = update_remote_data(hpair[0], &this_proc, hpair+1, 1, 0);
+    RRA("Trouble setting remote data range on sent entities in ghost exchange.");
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_ghosted_entities(int bridge_dim,
+                                                 int ghost_dim,
+                                                 int to_proc, 
+                                                 int num_layers,
+                                                 Range &ghosted_ents) 
+{
+    // get bridge ents on interface(s)
+  Range from_ents;
+  ErrorCode result = MB_SUCCESS;
+  assert(0 < num_layers);
+  for (Range::iterator rit = interfaceSets.begin(); rit != interfaceSets.end();
+       rit++) {
+    if (!is_iface_proc(*rit, to_proc)) continue;
+      
+      // get starting "from" entities
+    if (bridge_dim == -1)
+      result = mbImpl->get_entities_by_handle(*rit, from_ents);
+    else
+      result = mbImpl->get_entities_by_dimension(*rit, bridge_dim, from_ents);
+    RRA("Couldn't get bridge ents in the set.");
+
+      // need to get layers of bridge-adj entities
+    if (from_ents.empty()) continue;
+    result = MeshTopoUtil(mbImpl).get_bridge_adjacencies(from_ents, bridge_dim,
+                                                         ghost_dim, ghosted_ents, 
+                                                         num_layers);
+    RRA("Couldn't get bridge adjacencies.");
+  }
+  
+  result = add_verts(ghosted_ents);
+  RRA("Couldn't add verts.");
+
+  return result;
+}
+
+ErrorCode ParallelComm::add_verts(Range &sent_ents) 
+{
+      // get the verts adj to these entities, since we'll have to send those too
+
+    // first check sets
+  std::pair<Range::const_iterator, Range::const_iterator>
+      set_range = sent_ents.equal_range(MBENTITYSET);
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  for (Range::const_iterator rit = set_range.first; rit != set_range.second; rit++) {
+    tmp_result = mbImpl->get_entities_by_type(*rit, MBVERTEX, sent_ents);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  RRA("Failed to get contained verts.");
+  
+    // now non-sets
+  Range tmp_ents;
+  std::copy(sent_ents.begin(), set_range.first, range_inserter(tmp_ents));
+  result = mbImpl->get_adjacencies(tmp_ents, 0, false, sent_ents,
+                                   Interface::UNION);
+  RRA("Couldn't get vertices adj to ghosted ents.");
+
+  return result;
+}
+
+
+ErrorCode ParallelComm::exchange_tags(std::vector<Tag> &src_tags,
+                                          std::vector<Tag> &dst_tags,
+                                          Range &entities)
+{
+  ErrorCode result;
+  int success;
+
+#ifdef DEBUG_COMM
+  std::cerr << "Entering exchange_tags" << std::endl; std::cerr.flush();
+#endif
+
+    // get all procs interfacing to this proc
+  std::set<unsigned int> exch_procs;
+  result = get_comm_procs(exch_procs);  
+
+    // post ghost irecv's for all interface procs
+    // index greqs the same as buffer/sharing procs indices
+  std::vector<MPI_Request> recv_tag_reqs(2*buffProcs.size(), MPI_REQUEST_NULL),
+      sent_ack_reqs(buffProcs.size(), MPI_REQUEST_NULL);
+  std::vector<unsigned int>::iterator sit;
+  int ind;
+
+  reset_all_buffers();
+  int incoming = 0;
+
+  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
+    incoming++;
+    PRINT_DEBUG_IRECV(*sit, procConfig.proc_rank(), remoteOwnedBuffs[ind]->mem_ptr,
+                      INITIAL_BUFF_SIZE, MB_MESG_TAGS_SIZE, incoming);
+
+    success = MPI_Irecv(remoteOwnedBuffs[ind]->mem_ptr, INITIAL_BUFF_SIZE,
+                        MPI_UNSIGNED_CHAR, *sit,
+                        MB_MESG_TAGS_SIZE, procConfig.proc_comm(), 
+                        &recv_tag_reqs[2*ind]);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv in ghost exchange.");
+    }
+
+  }
+  
+    // pack and send tags from this proc to others
+    // make sendReqs vector to simplify initialization
+  sendReqs.resize(2*buffProcs.size(), MPI_REQUEST_NULL);
+  
+    // take all shared entities if incoming list is empty
+  if (entities.empty()) entities = sharedEnts;
+  
+  int dum_ack_buff;
+
+  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
+    
+    Range tag_ents = entities;
+    
+      // get ents shared by proc *sit
+    result = filter_pstatus(tag_ents, PSTATUS_SHARED, PSTATUS_AND, *sit);
+    RRA("Failed pstatus AND check.");
+    
+      // remote nonowned entities
+    if (!tag_ents.empty()) {
+      result = filter_pstatus(tag_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+      RRA("Failed pstatus NOT check.");
+    }
+    
+      // pack-send; this also posts receives if store_remote_handles is true
+    std::vector<Range> tag_ranges;
+    for (std::vector<Tag>::iterator vit = src_tags.begin(); vit != src_tags.end(); vit++) {
+      const void* ptr;
+      int size;
+      if (tagServer->get_default_data_ref( *vit, ptr, size ) != MB_SUCCESS) {
+        Range tagged_ents;
+        tagServer->get_entities( *vit, tagged_ents );
+        tag_ranges.push_back( intersect( tag_ents, tagged_ents ) );
+      } 
+      else {
+        tag_ranges.push_back(tag_ents);
+      }
+    }
+    
+      // pack the data
+      // reserve space on front for size and for initial buff size
+    localOwnedBuffs[ind]->reset_ptr(sizeof(int));
+    
+    result = pack_tags(tag_ents,
+                       src_tags, dst_tags, tag_ranges, 
+                       localOwnedBuffs[ind], true, *sit);
+    RRA("Failed to count buffer in pack_send_tag.");
+
+      // now send it
+    result = send_buffer(*sit, localOwnedBuffs[ind], MB_MESG_TAGS_SIZE, sendReqs[2*ind],
+                         recv_tag_reqs[2*ind+1], &dum_ack_buff, incoming);
+    RRA("Failed to send buffer.");
+                         
+  }
+  
+    // receive/unpack tags
+  while (incoming) {
+    int ind;
+    MPI_Status status;
+    PRINT_DEBUG_WAITANY(recv_tag_reqs, MB_MESG_TAGS_SIZE, procConfig.proc_rank());
+    success = MPI_Waitany(2*buffProcs.size(), &recv_tag_reqs[0], &ind, &status);
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitany in ghost exchange.");
+    }
+    
+    PRINT_DEBUG_RECD(status);
+
+      // ok, received something; decrement incoming counter
+    incoming--;
+    
+    bool done = false;
+    Range dum_range;
+    result = recv_buffer(MB_MESG_TAGS_SIZE,
+                         status,
+                         remoteOwnedBuffs[ind/2],
+                         recv_tag_reqs[ind/2 * 2], recv_tag_reqs[ind/2 * 2 + 1],
+                         incoming,
+                         localOwnedBuffs[ind/2], sendReqs[ind/2*2], sendReqs[ind/2*2+1],
+                         done);
+    RRA("Failed to resize recv buffer.");
+    if (done) {
+      remoteOwnedBuffs[ind/2]->reset_ptr(sizeof(int));
+      result = unpack_tags(remoteOwnedBuffs[ind/2]->buff_ptr,
+                           dum_range, true, buffProcs[ind/2]);
+      RRA("Failed to recv-unpack-tag message.");
+    }
+  }
+  
+    // ok, now wait
+#ifdef DEBUG_BARRIER  
+  success = MPI_Barrier(procConfig.proc_comm());
+#else
+  MPI_Status status;
+  success = MPI_Waitall(2*buffProcs.size(), &sendReqs[0], status);
+#endif
+  if (MPI_SUCCESS != success) {
+    result = MB_FAILURE;
+    RRA("Failure in waitall in tag exchange.");
+  }
+  
+#ifdef DEBUG_COMM
+  std::cerr << "Exiting exchange_tags" << std::endl; std::cerr.flush();
+#endif
+
+  return MB_SUCCESS;
+}
+
+/*
+ErrorCode ParallelComm::exchange_tags( Tag src_tag, 
+                                           Tag dst_tag, 
+                                           const Range& entities )
+{
+  ErrorCode result;
+  int success;
+
+    // get all procs interfacing to this proc
+  std::set<unsigned int> exch_procs;
+  result = get_comm_procs(exch_procs);  
+
+    // post ghost irecv's for all interface procs
+    // index greqs the same as buffer/sharing procs indices
+  std::vector<MPI_Request> recv_reqs(MAX_SHARING_PROCS, MPI_REQUEST_NULL);
+  std::vector<MPI_Status> gstatus(MAX_SHARING_PROCS);
+  std::vector<unsigned int>::iterator sit;
+  int ind;
+  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
+    success = MPI_Irecv(&ghostRBuffs[ind][0], ghostRBuffs[ind].size(), 
+                        MPI_UNSIGNED_CHAR, *sit,
+                        MB_MESG_ANY, procConfig.proc_comm(), 
+                        &recv_reqs[ind]);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv in ghost exchange.");
+    }
+  }
+  
+    // figure out which entities are shared with which processors
+  std::map<int,Range> proc_ents;
+  int other_procs[MAX_SHARING_PROCS], num_sharing;
+  for (Range::const_iterator i = entities.begin(); i != entities.end(); ++i) {
+    int owner;
+    result = get_owner( *i, owner );
+    RRA("Failed to get entity owner.");
+
+      // only send entities that this proc owns
+    if ((unsigned)owner != proc_config().proc_rank()) 
+      continue;
+    
+    result = get_sharing_parts( *i, other_procs, num_sharing );
+    RRA("Failed to get procs sharing entity.");
+    if (num_sharing == 0) // keep track of non-shared entities for later
+      proc_ents[proc_config().proc_rank()].insert( *i );
+    for (int j = 0; j < num_sharing; ++j)
+      proc_ents[other_procs[j]].insert( *i );
+  }
+  
+    // pack and send tags from this proc to others
+    // make sendReqs vector to simplify initialization
+  std::fill(sendReqs, sendReqs+MAX_SHARING_PROCS, MPI_REQUEST_NULL);
+  std::map<unsigned int,Range>::const_iterator mit;
+  
+  for (ind = 0, sit = buffProcs.begin(); sit != buffProcs.end(); sit++, ind++) {
+    
+      // count first
+      // buffer needs to begin with the number of tags (one)
+    int buff_size = sizeof(int);
+    result = packed_tag_size( src_tag, proc_ents[*sit], buff_size );
+    RRA("Failed to count buffer in pack_send_tag.");
+
+    unsigned char *buff_ptr = &ownerSBuffs[ind][0];
+    buff->check_space(ownerSBuffs[ind], buff_ptr, buff_size);
+    PACK_INT( buff_ptr, 1 ); // number of tags
+    result = pack_tag( src_tag, dst_tag, proc_ents[*sit], proc_ents[*sit],
+                       ownerSBuffs[ind], buff_ptr, true, *sit );
+    RRA("Failed to pack buffer in pack_send_tag.");
+
+      // if the message is large, send a first message to tell how large
+    if (INITIAL_BUFF_SIZE < buff_size) {
+      int tmp_buff_size = -buff_size;
+      int success = MPI_Send(&tmp_buff_size, sizeof(int), MPI_UNSIGNED_CHAR, 
+                             *sit, MB_MESG_SIZE, procConfig.proc_comm());
+      if (success != MPI_SUCCESS) return MB_FAILURE;
+    }
+    
+      // send the buffer
+    success = MPI_Isend(&ownerSBuffs[ind][0], buff_size, MPI_UNSIGNED_CHAR, *sit, 
+                        MB_MESG_TAGS, procConfig.proc_comm(), &sendReqs[ind]);
+    if (success != MPI_SUCCESS) return MB_FAILURE;
+  }
+  
+    // receive/unpack tags
+  int num_incoming = exch_procs.size();
+  
+  while (num_incoming) {
+    int ind;
+    MPI_Status status;
+    success = MPI_Waitany(MAX_SHARING_PROCS, &recv_reqs[0], &ind, &status);
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitany in ghost exchange.");
+    }
+    
+      // ok, received something; decrement incoming counter
+    num_incoming--;
+    
+    int new_size;
+    unsigned char *buff_ptr;
+    Range dum_range;
+    
+      // branch on message type
+    switch (status.MPI_TAG) {
+      case MB_MESG_SIZE:
+          // incoming message just has size; resize buffer and re-call recv,
+          // then re-increment incoming count
+        assert(ind < MAX_SHARING_PROCS);
+        new_size = *((int*)&ghostRBuffs[ind][0]);
+        assert(0 > new_size);
+        result = recv_size_buff(buffProcs[ind], ghostRBuffs[ind], recv_reqs[ind],
+                                MB_MESG_TAGS);
+        RRA("Failed to resize recv buffer.");
+        num_incoming++;
+        break;
+      case MB_MESG_TAGS:
+          // incoming ghost entities; process
+          buff_ptr = &ghostRBuffs[ind][0];
+          result = unpack_tags(buff_ptr, dum_range, true,
+                               buffProcs[ind]);
+        RRA("Failed to recv-unpack-tag message.");
+        break;
+      default:
+        result = MB_FAILURE;
+        RRA("Failed to get message of correct type in exch_tags.");
+        break;
+    }
+  }
+  
+    // ok, now wait
+  MPI_Status status[MAX_SHARING_PROCS];
+  success = MPI_Waitall(MAX_SHARING_PROCS, &sendReqs[0], status);
+  if (MPI_SUCCESS != success) {
+    result = MB_FAILURE;
+    RRA("Failure in waitall in tag exchange.");
+  }
+  
+    // if src and destination tags aren't the same, need to copy 
+    // values for local entities
+  if (src_tag != dst_tag) {
+    const Range& myents = proc_ents[proc_config().proc_rank()];
+    std::vector<const void*> data_ptrs(myents.size());
+    std::vector<int> data_sizes(myents.size());
+    result = get_moab()->tag_get_data( src_tag, myents, &data_ptrs[0], &data_sizes[0] );
+    RRA("Failure to get pointers to local data.");
+    result = get_moab()->tag_set_data( dst_tag, myents, &data_ptrs[0], &data_sizes[0] );
+    RRA("Failure to get pointers to local data.");
+  }  
+  
+  return MB_SUCCESS;
+}
+*/
+
+ErrorCode ParallelComm::update_shared_mesh()
+{
+//  ErrorCode result;
+//  int success;
+
+    // ,,,
+    /*
+
+    // get all procs interfacing to this proc
+  std::set<unsigned int> iface_procs;
+  result = get_interface_procs(iface_procs);
+  RRA("Failed to get iface sets, procs");
+
+    // post ghost irecv's for all interface procs
+    // index greqs the same as buffer/sharing procs indices
+  std::vector<MPI_Request> recv_reqs(2*MAX_SHARING_PROCS, MPI_REQUEST_NULL);
+  std::vector<MPI_Status> gstatus(MAX_SHARING_PROCS);
+  std::set<unsigned int>::iterator sit;
+  for (sit = iface_procs.begin(); sit != iface_procs.end(); sit++) {
+    int ind = get_buffers(*sit);
+    success = MPI_Irecv(&ghostRBuffs[ind][0], ghostRBuffs[ind].size(), 
+                        MPI_UNSIGNED_CHAR, *sit,
+                        MB_MESG_ANY, procConfig.proc_comm(), 
+                        &recv_reqs[ind]);
+    if (success != MPI_SUCCESS) {
+      result = MB_FAILURE;
+      RRA("Failed to post irecv in ghost exchange.");
+    }
+  }
+  
+    // pack and send vertex coordinates from this proc to others
+    // make sendReqs vector to simplify initialization
+  std::fill(sendReqs, sendReqs+2*MAX_SHARING_PROCS, MPI_REQUEST_NULL);
+  Range recd_ents[MAX_SHARING_PROCS];
+  
+  for (sit = iface_procs.begin(); sit != iface_procs.end(); sit++) {
+    int ind = get_buffers(*sit);
+    
+    Range vertices;
+    for (Range::iterator rit = interfaceSets.begin(); rit != interfaceSets.end();
+         rit++) {
+      if (!is_iface_proc(*rit, *sit)) 
+        continue;
+      
+      result = mbImpl->get_entities_by_type( *rit, MBVERTEX, vertices );
+      RRA("Bad interface set.");
+    }
+    std::map<unsigned int,Range>::iterator ghosted = ghostedEnts.find(*sit);
+    if (ghosted != ghostedEnts.end()) {
+      Range::iterator e = ghosted->second.upper_bound(MBVERTEX);
+      vertices.merge( ghosted->second.begin(), e );
+    }
+
+      // pack-send; this also posts receives if store_remote_handles is true
+    Range sent;
+    result = pack_send_entities(*sit, vertices, false, false, 
+                                false, true,
+                                ownerSBuffs[ind], ownerRBuffs[MAX_SHARING_PROCS+ind], 
+                                sendReqs[ind], recv_reqs[MAX_SHARING_PROCS+ind], 
+                                sent);
+    RRA("Failed to pack-send in mesh update exchange.");
+  }
+  
+    // receive/unpack entities
+    // number of incoming messages depends on whether we're getting back
+    // remote handles
+  int num_incoming = iface_procs.size();
+  
+  while (num_incoming) {
+    int ind;
+    MPI_Status status;
+    success = MPI_Waitany(2*MAX_SHARING_PROCS, &recv_reqs[0], &ind, &status);
+    if (MPI_SUCCESS != success) {
+      result = MB_FAILURE;
+      RRA("Failed in waitany in ghost exchange.");
+    }
+    
+      // ok, received something; decrement incoming counter
+    num_incoming--;
+    
+    std::vector<EntityHandle> remote_handles_v, sent_ents_tmp;
+    Range remote_handles_r;
+    int new_size;
+    
+      // branch on message type
+    switch (status.MPI_TAG) {
+      case MB_MESG_SIZE:
+          // incoming message just has size; resize buffer and re-call recv,
+          // then re-increment incoming count
+        assert(ind < MAX_SHARING_PROCS);
+        new_size = *((int*)&ghostRBuffs[ind][0]);
+        assert(0 > new_size);
+        result = recv_size_buff(buffProcs[ind], ghostRBuffs[ind], recv_reqs[ind],
+                                MB_MESG_ENTS);
+        RRA("Failed to resize recv buffer.");
+        num_incoming++;
+        break;
+      case MB_MESG_ENTS:
+          // incoming ghost entities; process
+        result = recv_unpack_entities(buffProcs[ind], true,
+                                      false, 
+                                      ghostRBuffs[ind], ghostSBuffs[ind], 
+                                      sendReqs[ind], recd_ents[ind]);
+        RRA("Failed to recv-unpack message.");
+        break;
+    }
+  }
+  
+    // ok, now wait if requested
+  MPI_Status status[2*MAX_SHARING_PROCS];
+  success = MPI_Waitall(2*MAX_SHARING_PROCS, &sendReqs[0], status);
+  if (MPI_SUCCESS != success) {
+    result = MB_FAILURE;
+    RRA("Failure in waitall in ghost exchange.");
+  }
+  
+  return MB_SUCCESS;
+}
+ErrorCode ParallelComm::update_iface_sets(Range &sent_ents,
+                                              std::vector<EntityHandle> &remote_handles, 
+                                              int from_proc) 
+{
+  std::vector<EntityHandle>::iterator remote_it = remote_handles.begin();
+  Range::iterator sent_it = sent_ents.begin();
+  Range ents_to_remove;
+  for (; sent_it != sent_ents.end(); sent_it++, remote_it++) {
+    if (!*remote_it) ents_to_remove.insert(*sent_it);
+  }
+  
+  for (Range::iterator set_it = interfaceSets.begin(); set_it != interfaceSets.end(); set_it++) {
+    if (!is_iface_proc(*set_it, from_proc)) continue;
+    ErrorCode result = mbImpl->remove_entities(*set_it, ents_to_remove);
+    RRA("Couldn't remove entities from iface set in update_iface_sets.");
+  }
+
+*/
+  
+  return MB_SUCCESS;
+}
+
+  //! return sharedp tag
+Tag ParallelComm::sharedp_tag()
+{
+  if (!sharedpTag) {
+    int def_val = -1;
+    ErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_PROC_TAG_NAME, 
+                                            sizeof(int), 
+                                            MB_TAG_DENSE,
+                                            MB_TYPE_INTEGER, sharedpTag, 
+                                            &def_val, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
+      return 0;
+  }
+  
+  return sharedpTag;
+}
+
+  //! return sharedps tag
+Tag ParallelComm::sharedps_tag()
+{
+  if (!sharedpsTag) {
+    ErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_PROCS_TAG_NAME, 
+                                            MAX_SHARING_PROCS*sizeof(int), 
+                                            MB_TAG_SPARSE,
+                                            MB_TYPE_INTEGER, sharedpsTag, NULL, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
+      return 0;
+  }
+  
+  return sharedpsTag;
+}
+  
+  //! return sharedh tag
+Tag ParallelComm::sharedh_tag()
+{
+  if (!sharedhTag) {
+    EntityHandle def_val = 0;
+    ErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_HANDLE_TAG_NAME, 
+                                            sizeof(EntityHandle), 
+                                            MB_TAG_DENSE,
+                                            MB_TYPE_HANDLE, sharedhTag, 
+                                            &def_val, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
+      return 0;
+  }
+  
+  return sharedhTag;
+}
+  
+  //! return sharedhs tag
+Tag ParallelComm::sharedhs_tag()
+{  
+  if (!sharedhsTag) {
+    ErrorCode result = mbImpl->tag_create(PARALLEL_SHARED_HANDLES_TAG_NAME, 
+                                            MAX_SHARING_PROCS*sizeof(EntityHandle), 
+                                            MB_TAG_SPARSE,
+                                            MB_TYPE_INTEGER, sharedhsTag, NULL, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) 
+      return 0;
+  }
+
+  return sharedhsTag;
+}
+  
+  //! return pstatus tag
+Tag ParallelComm::pstatus_tag()
+{  
+  if (!pstatusTag) {
+    unsigned char tmp_pstatus = 0;
+    ErrorCode result = mbImpl->tag_create(PARALLEL_STATUS_TAG_NAME, 
+                                            sizeof(unsigned char),
+                                            MB_TAG_DENSE,
+                                            MB_TYPE_OPAQUE, pstatusTag, 
+                                            &tmp_pstatus, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
+      return 0;
+  }
+  
+  return pstatusTag;
+}
+  
+  //! return partition set tag
+Tag ParallelComm::partition_tag()
+{  
+  if (!partitionTag) {
+    ErrorCode result = mbImpl->tag_create(PARALLEL_PARTITION_TAG_NAME, 
+                                            sizeof(int),
+                                            MB_TAG_SPARSE,
+                                            MB_TYPE_INTEGER, 
+                                            partitionTag, 
+                                            NULL, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
+      return 0;
+  }
+  
+  return partitionTag;
+}
+  
+  //! return pcomm tag; passes in impl 'cuz this is a static function
+Tag ParallelComm::pcomm_tag(Interface *impl,
+                                bool create_if_missing)
+{
+  Tag this_tag = 0;
+  ErrorCode result;
+  result = impl->tag_get_handle(PARALLEL_COMM_TAG_NAME, this_tag);
+  if ((MB_TAG_NOT_FOUND == result || 0 == this_tag) &&
+      create_if_missing) {
+    result = impl->tag_create(PARALLEL_COMM_TAG_NAME, 
+                              MAX_SHARING_PROCS*sizeof(ParallelComm*),
+                              MB_TAG_SPARSE,
+                              MB_TYPE_OPAQUE, this_tag,
+                              NULL, true);
+    if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result)
+      return 0;
+  }
+  
+  return this_tag;
+}
+
+    //! get the indexed pcomm object from the interface
+ParallelComm *ParallelComm::get_pcomm(Interface *impl, const int index) 
+{
+  Tag pc_tag = pcomm_tag(impl, false);
+  if (0 == pc_tag) return NULL;
+  
+  ParallelComm *pc_array[MAX_SHARING_PROCS];
+  ErrorCode result = impl->tag_get_data(pc_tag, 0, 0, (void*)pc_array);
+  if (MB_SUCCESS != result) return NULL;
+  
+  return pc_array[index];
+}
+
+ErrorCode ParallelComm::get_all_pcomm( Interface* impl, std::vector<ParallelComm*>& list )
+{
+  Tag pc_tag = pcomm_tag(impl, false);
+  if (0 == pc_tag)
+    return MB_TAG_NOT_FOUND;
+  
+  ParallelComm *pc_array[MAX_SHARING_PROCS];
+  ErrorCode rval = impl->tag_get_data( pc_tag, 0, 0, pc_array );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  for (int i = 0; i < MAX_SHARING_PROCS; ++i)
+    if (pc_array[i])
+      list.push_back( pc_array[i] );
+  
+  return MB_SUCCESS;
+}
+  
+
+    //! get the indexed pcomm object from the interface
+ParallelComm *ParallelComm::get_pcomm( Interface *impl, 
+                                           EntityHandle prtn,
+                                           const MPI_Comm* comm ) 
+{
+  ErrorCode rval;
+  ParallelComm* result = 0;
+  
+  Tag prtn_tag;
+  rval = impl->tag_create( PARTITIONING_PCOMM_TAG_NAME, 
+                           sizeof(int),
+                           MB_TAG_SPARSE,
+                           MB_TYPE_INTEGER,
+                           prtn_tag,
+                           0, true );
+  if (MB_SUCCESS != rval)
+    return 0;
+  
+  int pcomm_id;
+  rval = impl->tag_get_data( prtn_tag, &prtn, 1, &pcomm_id );
+  if (MB_SUCCESS == rval) {
+    result= get_pcomm( impl, pcomm_id );
+  }
+  else if (MB_TAG_NOT_FOUND == rval && comm) {
+    result = new ParallelComm( impl, *comm, &pcomm_id );
+    if (!result)
+      return 0;
+    result->set_partitioning( prtn );
+    
+    rval = impl->tag_set_data( prtn_tag, &prtn, 1, &pcomm_id );
+    if (MB_SUCCESS != rval) {
+      delete result;
+      result = 0;
+    }
+  }
+  
+  return result;
+}
+
+ErrorCode ParallelComm::set_partitioning( EntityHandle set) 
+{
+  ErrorCode rval;
+  Tag prtn_tag;
+  rval = mbImpl->tag_create( PARTITIONING_PCOMM_TAG_NAME, 
+                           sizeof(int),
+                           MB_TAG_SPARSE,
+                           MB_TYPE_INTEGER,
+                           prtn_tag,
+                           0, true );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+    // get my id
+  ParallelComm* pcomm_arr[MAX_SHARING_PROCS];
+  Tag pc_tag = pcomm_tag(mbImpl, false);
+  if (0 == pc_tag) 
+    return MB_FAILURE;
+  ErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, pcomm_arr);
+  if (MB_SUCCESS != result) 
+    return MB_FAILURE;  
+  int id = std::find(pcomm_arr,pcomm_arr+MAX_SHARING_PROCS,this) - pcomm_arr;
+  if (id == MAX_SHARING_PROCS)
+    return MB_FAILURE;
+
+  EntityHandle old = partitioningSet;
+  if (old) {
+    rval = mbImpl->tag_delete_data( prtn_tag, &old, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+    partitioningSet = 0;
+  }
+  
+  if (!set) 
+    return MB_SUCCESS;
+  
+  Range contents;
+  if (old) {
+    rval = mbImpl->get_entities_by_handle( old, contents );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  else {
+    contents = partition_sets();
+  }
+
+  rval = mbImpl->add_entities( set, contents );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // store pcomm id on new partition set
+  rval = mbImpl->tag_set_data( prtn_tag, &set, 1, &id );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  partitioningSet = set;
+  return MB_SUCCESS;
+}
+  
+
+  //! return all the entities in parts owned locally
+ErrorCode ParallelComm::get_part_entities(Range &ents, int dim) 
+{
+  ErrorCode result;
+  
+  for (Range::iterator rit = partitionSets.begin(); 
+       rit != partitionSets.end(); rit++) {
+    Range tmp_ents;
+    if (-1 == dim) 
+      result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true);
+    else
+      result = mbImpl->get_entities_by_dimension(*rit, dim, tmp_ents, true);
+
+    if (MB_SUCCESS != result) return result;
+    ents.merge(tmp_ents);
+  }
+  
+  return MB_SUCCESS;
+}
+
+  /** \brief Return the rank of the entity owner
+   */
+ErrorCode ParallelComm::get_owner_handle(EntityHandle entity,
+                                             int &owner,
+                                             EntityHandle &handle) 
+{
+  unsigned char pstat;
+  int sharing_procs[MAX_SHARING_PROCS];
+  EntityHandle sharing_handles[MAX_SHARING_PROCS];
+
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1,
+                                            &pstat);
+  if (!(pstat & PSTATUS_NOT_OWNED)) {
+    owner = proc_config().proc_rank();
+    handle = entity;
+  }
+  
+  else if (pstat & PSTATUS_MULTISHARED) {
+    result = mbImpl->tag_get_data(sharedps_tag(), &entity, 1,
+                                  sharing_procs);
+    owner = sharing_procs[0];
+    result = mbImpl->tag_get_data(sharedhs_tag(), &entity, 1,
+                                  sharing_handles);
+    handle = sharing_handles[0];
+  }
+  else if (pstat & PSTATUS_SHARED) {
+    result = mbImpl->tag_get_data(sharedp_tag(), &entity, 1,
+                                  sharing_procs);
+    RRA(" ");
+    owner = sharing_procs[0];
+    result = mbImpl->tag_get_data(sharedh_tag(), &entity, 1,
+                                  sharing_handles);
+    handle = sharing_handles[0];
+  }
+  else {
+    owner = -1;
+    handle = 0;
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_global_part_count( int& count_out ) const
+{
+  count_out = globalPartCount;
+  return count_out < 0 ? MB_FAILURE : MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_part_owner( int part_id, int& owner ) const
+{
+  // FIXME: assumes only 1 local part
+  owner = part_id;
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_part_id( EntityHandle /*part*/, int& id_out ) const
+{
+  // FIXME: assumes only 1 local part
+  id_out = proc_config().proc_rank();
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_part_handle( int id, EntityHandle& handle_out ) const
+{
+  // FIXME: assumes only 1 local part
+  if ((unsigned)id != proc_config().proc_rank())
+    return MB_ENTITY_NOT_FOUND;
+  handle_out = partition_sets().front();
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::create_part( EntityHandle& set_out )
+{
+    // mark as invalid so we know that it needs to be updated
+  globalPartCount = -1;
+  
+    // create set representing part
+  ErrorCode rval = mbImpl->create_meshset( MESHSET_SET, set_out );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // set tag on set
+    // FIXME: need to assign valid global id
+  int val = 0;
+  rval = mbImpl->tag_set_data( part_tag(), &set_out, 1, &val );
+  if (MB_SUCCESS != rval) {
+    mbImpl->delete_entities( &set_out, 1 );
+    return rval;
+  }
+  
+  if (get_partitioning()) {
+    rval = mbImpl->add_entities( get_partitioning(), &set_out, 1 );
+    if (MB_SUCCESS != rval) {
+      mbImpl->delete_entities( &set_out, 1 );
+      return rval;
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::destroy_part( EntityHandle part_id )
+{
+    // mark as invalid so we know that it needs to be updated
+  globalPartCount = -1;
+  
+  ErrorCode rval;
+  if (get_partitioning()) {
+    rval = mbImpl->remove_entities( get_partitioning(), &part_id, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  return mbImpl->delete_entities( &part_id, 1 );
+}
+
+ErrorCode ParallelComm::collective_sync_partition()
+{
+  int count = partition_sets().size();
+  globalPartCount = 0;
+  int err = MPI_Allreduce( &count, &globalPartCount, 1, MPI_INT, MPI_SUM, 
+                           proc_config().proc_comm() );
+  return err ? MB_FAILURE : MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_part_neighbor_ids( EntityHandle part,
+                                                   int neighbors_out[MAX_SHARING_PROCS],
+                                                   int& num_neighbors_out )
+{
+  ErrorCode rval;
+  Range iface;
+  rval = get_interface_sets( part, iface );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  num_neighbors_out = 0;
+  int n, j = 0;
+  int tmp[MAX_SHARING_PROCS], curr[MAX_SHARING_PROCS];
+  int *parts[2] = { neighbors_out, tmp };
+  for (Range::iterator i = iface.begin(); i != iface.end(); ++i) {
+    unsigned char pstat;
+    rval = get_sharing_data( *i, curr, NULL, pstat, n);
+    if (MB_SUCCESS != rval)
+      return rval;
+    std::sort( curr, curr+n );
+    assert( num_neighbors_out < MAX_SHARING_PROCS );
+    int* k = std::set_union( parts[j], parts[j]+num_neighbors_out,
+                             curr, curr + n, parts[1-j] );
+    j = 1-j;
+    num_neighbors_out = k - parts[j];
+  }
+  if (parts[j] != neighbors_out)
+    std::copy( parts[j], parts[j]+num_neighbors_out, neighbors_out );
+    
+    
+    // remove input part from list
+  int id;
+  rval = get_part_id( part, id );
+  if (MB_SUCCESS == rval) 
+    num_neighbors_out = std::remove( neighbors_out, neighbors_out+num_neighbors_out, id ) - neighbors_out;
+  return rval;
+}
+
+ErrorCode ParallelComm::get_interface_sets( EntityHandle ,
+                                                Range& iface_sets_out,
+                                                int* adj_part_id )
+{
+    // FIXME : assumes one part per processor.
+    // Need to store part iface sets as children to implement
+    // this correctly.
+  iface_sets_out = interface_sets();
+
+  if (adj_part_id) {
+    int part_ids[MAX_SHARING_PROCS], num_parts;
+    Range::iterator i = iface_sets_out.begin();
+    while (i != iface_sets_out.end()) {
+      unsigned char pstat;
+      ErrorCode rval = get_sharing_data( *i, part_ids, NULL, pstat, num_parts );
+      if (MB_SUCCESS != rval)
+        return rval;
+      
+      if (std::find(part_ids, part_ids+num_parts, *adj_part_id) - part_ids != num_parts)
+        ++i;
+      else
+        i = iface_sets_out.erase( i );
+    }
+  }
+    
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_owning_part( EntityHandle handle,
+                                             int& owning_part_id,
+                                             EntityHandle* remote_handle )
+{
+
+  // FIXME : assumes one part per proc, and therefore part_id == rank
+  
+    // If entity is not shared, then we're the owner.
+  unsigned char pstat;
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &handle, 1,
+                                            &pstat);
+  if (!(pstat & PSTATUS_NOT_OWNED)) {
+    owning_part_id = proc_config().proc_rank();
+    if (remote_handle)
+      *remote_handle = handle;
+    return MB_SUCCESS;
+  }
+  
+    // If entity is shared with one other proc, then
+    // sharedp_tag will contain a positive value.
+  result = mbImpl->tag_get_data( sharedp_tag(), &handle, 1, &owning_part_id );
+  if (MB_SUCCESS != result)
+    return result;
+  if (owning_part_id != -1) {
+      // done?
+    if (!remote_handle)
+      return MB_SUCCESS;
+      
+      // get handles on remote processors (and this one)
+    return mbImpl->tag_get_data( sharedh_tag(), &handle, 1, remote_handle );
+  }
+  
+    // If here, then the entity is shared with at least two other processors.
+    // Get the list from the sharedps_tag
+  const void* part_id_list = 0;
+  result = mbImpl->tag_get_data( sharedps_tag(), &handle, 1, &part_id_list );
+  if (MB_SUCCESS != result)
+    return result;
+  owning_part_id = ((const int*)part_id_list)[0];
+ 
+    // done?
+  if (!remote_handle)
+    return MB_SUCCESS;
+  
+    // get remote handles
+  const void* handle_list = 0;
+  result = mbImpl->tag_get_data( sharedhs_tag(), &handle, 1, &handle_list );
+  if (MB_SUCCESS != result)
+    return result;
+  
+  *remote_handle = ((const EntityHandle*)handle_list)[0];
+  return MB_SUCCESS;
+}    
+
+ErrorCode ParallelComm::get_sharing_parts( EntityHandle entity,
+                                               int part_ids_out[MAX_SHARING_PROCS],
+                                               int& num_part_ids_out,
+                                               EntityHandle remote_handles[MAX_SHARING_PROCS] )
+{
+
+  // FIXME : assumes one part per proc, and therefore part_id == rank
+  
+    // If entity is not shared, then we're the owner.
+  unsigned char pstat;
+  ErrorCode result = mbImpl->tag_get_data(pstatus_tag(), &entity, 1,
+                                            &pstat);
+  if (!(pstat & PSTATUS_SHARED)) {
+    part_ids_out[0] = proc_config().proc_rank();
+    if (remote_handles)
+      remote_handles[0] = entity;
+    num_part_ids_out = 1;
+    return MB_SUCCESS;
+  }
+  
+    // If entity is shared with one other proc, then
+    // sharedp_tag will contain a positive value.
+  result = mbImpl->tag_get_data( sharedp_tag(), &entity, 1, part_ids_out );
+  if (MB_SUCCESS != result)
+    return result;
+  if (part_ids_out[0] != -1) {
+    
+    num_part_ids_out = 2;
+    part_ids_out[1] = proc_config().proc_rank();
+
+      // done?
+    if (!remote_handles)
+      return MB_SUCCESS;
+      
+      // get handles on remote processors (and this one)
+    remote_handles[1] = entity;
+    return mbImpl->tag_get_data( sharedh_tag(), &entity, 1, remote_handles );
+  }
+  
+    // If here, then the entity is shared with at least two other processors.
+    // Get the list from the sharedps_tag
+  result = mbImpl->tag_get_data( sharedps_tag(), &entity, 1, part_ids_out );
+  if (MB_SUCCESS != result)
+    return result;
+    // Count number of valid (positive) entries in sharedps_tag
+  for (num_part_ids_out = 0; num_part_ids_out < MAX_SHARING_PROCS &&
+       part_ids_out[num_part_ids_out] >= 0; ++num_part_ids_out);
+  part_ids_out[num_part_ids_out++] = proc_config().proc_rank();
+  
+    // done?
+  if (!remote_handles)
+    return MB_SUCCESS;
+  
+    // get remote handles
+  result = mbImpl->tag_get_data( sharedhs_tag(), &entity, 1, remote_handles );
+  remote_handles[num_part_ids_out-1] = entity;
+  return result;
+}
+
+ErrorCode ParallelComm::pack_shared_handles(
+    std::vector<std::vector<SharedEntityData> > &send_data) 
+{
+    // get all shared entities
+  Range all_shared, dum_range;
+  ErrorCode rval = mbImpl->get_entities_by_handle(0, all_shared);
+  if (MB_SUCCESS != rval)
+    return rval;
+  rval = get_pstatus_entities(-1, 0, dum_range);
+  if (MB_SUCCESS != rval)
+    return rval;
+  all_shared = subtract( all_shared, dum_range);
+  all_shared.erase(all_shared.upper_bound(MBPOLYHEDRON), all_shared.end());
+  assert(sharedEnts == all_shared);
+
+    // build up send buffers
+  int ent_procs[MAX_SHARING_PROCS];
+  EntityHandle handles[MAX_SHARING_PROCS];
+  int num_sharing;
+  SharedEntityData tmp;
+  send_data.resize(buffProcs.size());
+  for (Range::iterator i = all_shared.begin(); i != all_shared.end(); ++i) {
+    tmp.remote = *i; // swap local/remote so they're correct on the remote proc.
+    rval = get_owner( *i, tmp.owner );
+    if (MB_SUCCESS != rval)
+      return rval;
+
+    unsigned char pstat;
+    rval = get_sharing_data( *i, ent_procs, handles, pstat, num_sharing );
+    if (MB_SUCCESS != rval)
+      return rval;
+    for (int j = 0; j < num_sharing; ++j) {
+      if (ent_procs[j] == (int)proc_config().proc_rank())
+        continue;
+      tmp.local = handles[j];
+      int ind = get_buffers(ent_procs[j]);
+      assert(-1 != ind);
+      send_data[ind].push_back( tmp );
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::exchange_all_shared_handles(  
+    std::vector<std::vector<SharedEntityData> > &send_data, 
+    std::vector<std::vector<SharedEntityData> > &result)
+{
+  int ierr;
+  const int tag = 0x4A41534E;
+  const MPI_Comm comm = procConfig.proc_comm();
+  const int num_proc = buffProcs.size();
+  const std::vector<int> procs( buffProcs.begin(), buffProcs.end() );
+  std::vector<MPI_Request> recv_req(buffProcs.size(), MPI_REQUEST_NULL);
+  
+    // set up to receive sizes
+  std::vector<int> sizes_send(num_proc), sizes_recv(num_proc);
+  for (int i = 0; i < num_proc; ++i) {
+    ierr = MPI_Irecv( &sizes_recv[i], 1, MPI_INT, procs[i], tag, comm, &recv_req[i] );
+    if (ierr) 
+      return MB_FILE_WRITE_ERROR;
+  }
+  
+    // send sizes
+  assert(num_proc == (int)send_data.size());
+  
+  sendReqs.resize(buffProcs.size(), MPI_REQUEST_NULL);
+  for (int i = 0; i < num_proc; ++i) {
+    sizes_send[i] = send_data[i].size();
+    ierr = MPI_Isend( &sizes_send[i], 1, MPI_INT, buffProcs[i], tag, comm, &sendReqs[i] );
+    if (ierr) 
+      return MB_FILE_WRITE_ERROR;
+  }
+  
+    // receive sizes
+  std::vector<MPI_Status> stat(num_proc);
+  ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
+  if (ierr)
+    return MB_FILE_WRITE_ERROR;
+  
+    // wait until all sizes are sent (clean up pending req's)
+  ierr = MPI_Waitall( num_proc, &sendReqs[0], &stat[0] );
+  if (ierr)
+    return MB_FILE_WRITE_ERROR;
+  
+    // set up to receive data
+  for (int i = 0; i < num_proc; ++i) {
+    result[i].resize( sizes_recv[i] );
+    ierr = MPI_Irecv( &result[i][0], 
+                      sizeof(SharedEntityData)*sizes_recv[i], 
+                      MPI_UNSIGNED_CHAR, 
+                      buffProcs[i], tag, comm, &recv_req[i] );
+    if (ierr) 
+      return MB_FILE_WRITE_ERROR;
+  }
+  
+    // send data
+  for (int i = 0; i < num_proc; ++i) {
+    ierr = MPI_Isend( &send_data[i][0], 
+                      sizeof(SharedEntityData)*sizes_send[i], 
+                      MPI_UNSIGNED_CHAR, 
+                      buffProcs[i], tag, comm, &sendReqs[i] );
+    if (ierr) 
+      return MB_FILE_WRITE_ERROR;
+  }
+  
+    // receive data
+  ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
+  if (ierr)
+    return MB_FILE_WRITE_ERROR;
+  
+    // wait until everything is sent to release send buffers
+  ierr = MPI_Waitall( num_proc, &sendReqs[0], &stat[0] );
+  if (ierr)
+    return MB_FILE_WRITE_ERROR;
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::check_all_shared_handles() 
+{
+    // get all shared ent data from other procs
+  std::vector<std::vector<SharedEntityData> > shents(buffProcs.size()),
+      send_data(buffProcs.size());
+
+  ErrorCode result = check_local_shared();
+  if (MB_SUCCESS != result)
+    return result;
+
+  result = pack_shared_handles(send_data);
+  if (MB_SUCCESS != result)
+    return result;
+  
+  result = exchange_all_shared_handles(send_data, shents);
+  if (MB_SUCCESS != result)
+    return result;
+  else if (shents.empty())
+    return MB_SUCCESS;
+
+  return check_my_shared_handles(shents);
+}
+
+ErrorCode ParallelComm::check_local_shared() 
+{
+    // do some local checks on shared entities to make sure things look
+    // consistent
+
+    // check that non-vertex shared entities are shared by same procs as all
+    // their vertices
+  std::pair<Range::const_iterator,Range::const_iterator> vert_it =
+      sharedEnts.equal_range(MBVERTEX);
+  std::vector<EntityHandle> dum_connect;
+  const EntityHandle *connect;
+  int num_connect;
+  int tmp_procs[MAX_SHARING_PROCS];
+  EntityHandle tmp_hs[MAX_SHARING_PROCS];
+  std::set<int> tmp_set, vset;
+  int num_ps;
+  ErrorCode result;
+  unsigned char pstat;
+  Range bad_ents;
+  std::vector<std::string> errors;
+  std::string dum_err;
+  
+  Range::const_iterator rit;
+  for (rit = sharedEnts.begin(); rit != sharedEnts.end(); rit++) {
+
+      // get sharing procs for this ent
+    result = get_sharing_data(*rit, tmp_procs, tmp_hs, pstat, num_ps);
+    if (MB_SUCCESS != result) {
+      bad_ents.insert(*rit);
+      errors.push_back(std::string("Failure getting sharing data."));
+      continue;
+    }
+
+    bool bad = false;
+      // entity must be shared
+    if (!(pstat & PSTATUS_SHARED))
+      errors.push_back(std::string("Entity should be shared but isn't.")), bad = true;
+
+      // if entity is not owned this must not be first proc
+    if (pstat & PSTATUS_NOT_OWNED && tmp_procs[0] == (int)procConfig.proc_rank())
+      errors.push_back(std::string("Entity not owned but is first proc.")), bad = true;
+
+      // if entity is owned and multishared, this must be first proc
+    if (!(pstat & PSTATUS_NOT_OWNED) && pstat & PSTATUS_MULTISHARED && 
+        (tmp_procs[0] != (int)procConfig.proc_rank() || tmp_hs[0] != *rit))
+      errors.push_back(std::string("Entity owned and multishared but not first proc or not first handle.")), bad = true;
+
+    if (bad) {
+      bad_ents.insert(*rit);
+      continue;
+    }
+    
+    if (mbImpl->type_from_handle(*rit) == MBVERTEX) continue;
+
+      // copy element's procs to vset and save size
+    int orig_ps = num_ps; vset.clear(); 
+    std::copy(tmp_procs, tmp_procs+num_ps, std::inserter(vset, vset.begin()));
+    
+      // get vertices for this ent and intersection of sharing procs
+    result = mbImpl->get_connectivity(*rit, connect, num_connect, false, &dum_connect);
+    if (MB_SUCCESS != result) {
+      bad_ents.insert(*rit); 
+      errors.push_back(std::string("Couldn't get connectivity."));
+      continue;
+    }
+    
+    for (int i = 0; i < num_connect; i++) {
+      result = get_sharing_data(connect[i], tmp_procs, NULL, pstat, num_ps);
+      if (MB_SUCCESS != result) {bad_ents.insert(*rit); continue;}
+      if (!num_ps) {vset.clear(); break;}
+      std::sort(tmp_procs, tmp_procs+num_ps);
+      tmp_set.clear();
+      std::set_intersection(tmp_procs, tmp_procs+num_ps,
+                            vset.begin(), vset.end(), std::inserter(tmp_set, tmp_set.end()));
+      vset.swap(tmp_set);
+      if (vset.empty()) break;
+    }
+    
+      // intersect them; should be the same size as orig_ps
+    tmp_set.clear();
+    std::set_intersection(tmp_procs, tmp_procs+num_ps,
+                          vset.begin(), vset.end(), std::inserter(tmp_set, tmp_set.end()));
+    if (orig_ps != (int)tmp_set.size()) {
+      errors.push_back(std::string("Vertex proc set not same size as entity proc set."));
+      bad_ents.insert(*rit);
+    }
+  }
+  
+  if (!bad_ents.empty()) {
+    std::cout << "Found bad entities in check_local_shared, proc rank "
+              << procConfig.proc_rank() << "," << std::endl;
+    std::vector<std::string>::iterator vit;
+    for (rit = bad_ents.begin(), vit = errors.begin(); rit != bad_ents.end(); rit++, vit++) {
+      list_entities(&(*rit), 1);
+      std::cout << "Reason: " << *vit << std::endl;
+    }
+    return MB_FAILURE;
+  }
+
+    // to do: check interface sets
+
+  return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::check_all_shared_handles(ParallelComm **pcs,
+                                                     int num_pcs) 
+{
+  std::vector<std::vector<std::vector<SharedEntityData> > > shents, send_data;
+  ErrorCode result = MB_SUCCESS, tmp_result;
+
+    // get all shared ent data from each proc to all other procs
+  send_data.resize(num_pcs);
+  for (int p = 0; p < num_pcs; p++) {
+    tmp_result = pcs[p]->pack_shared_handles(send_data[p]);
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  if (MB_SUCCESS != result) return result;
+
+    // move the data sorted by sending proc to data sorted by receiving proc
+  shents.resize(num_pcs);
+  for (int p = 0; p < num_pcs; p++)
+    shents[p].resize(pcs[p]->buffProcs.size());
+    
+  for (int p = 0; p < num_pcs; p++) {
+    for (unsigned int idx_p = 0; idx_p < pcs[p]->buffProcs.size(); idx_p++) {
+        // move send_data[p][to_p] to shents[to_p][idx_p]
+      int to_p = pcs[p]->buffProcs[idx_p];
+      int top_idx_p = pcs[to_p]->get_buffers(p);
+      assert(-1 != top_idx_p);
+      shents[to_p][top_idx_p] = send_data[p][idx_p];
+    }
+  }
+  
+  for (int p = 0; p < num_pcs; p++) {
+    std::ostringstream ostr;
+    ostr << "Processor " << p << " bad entities:";
+    tmp_result = pcs[p]->check_my_shared_handles(shents[p], ostr.str().c_str());
+    if (MB_SUCCESS != tmp_result) result = tmp_result;
+  }
+  
+  return result;
+}
+
+ErrorCode ParallelComm::check_my_shared_handles(
+    std::vector<std::vector<SharedEntityData> > &shents,
+                                                    const char *prefix) 
+{
+    // now check against what I think data should be
+    // get all shared entities
+  ErrorCode result;
+  Range dum_range, all_shared = sharedEnts;
+  all_shared.erase(all_shared.upper_bound(MBPOLYHEDRON), all_shared.end());
+
+  Range bad_ents, local_shared;
+  std::vector<SharedEntityData>::iterator vit;
+  for (unsigned int i = 0; i < shents.size(); i++) {
+    int other_proc = buffProcs[i];
+    result = get_shared_entities(other_proc, local_shared);
+    if (MB_SUCCESS != result) return result;
+    for (vit = shents[i].begin(); vit != shents[i].end(); vit++) {
+      EntityHandle localh = vit->local, remoteh = vit->remote, dumh;
+      local_shared.erase(localh);
+      result = get_remote_handles(true, &localh, &dumh, 1, other_proc, dum_range);
+      if (MB_SUCCESS != result || dumh != remoteh) 
+        bad_ents.insert(localh);
+    }
+
+    if (!local_shared.empty()) 
+      bad_ents.merge(local_shared);
+  }
+  
+  if (!bad_ents.empty()) {
+    if (prefix) {
+      std::cout << prefix << std::endl;
+      list_entities(bad_ents);
+    }
+    return MB_FAILURE;
+  }
+
+  else return MB_SUCCESS;
+}
+
+ErrorCode ParallelComm::get_shared_entities(int other_proc,
+                                                Range &shared_ents,
+                                                int dim,
+                                                const bool iface,
+                                                const bool owned_filter) 
+{
+  shared_ents.clear();
+  ErrorCode result = MB_SUCCESS;
+  
+    // dimension
+  if (-1 != dim) {
+    DimensionPair dp = MBCN::TypeDimensionMap[dim];
+    Range dum_range;
+    shared_ents.merge(sharedEnts.lower_bound(dp.first), 
+                      sharedEnts.upper_bound(dp.second));
+  }
+  else shared_ents = sharedEnts;
+
+    // filter by iface
+  if (iface) {
+    result = filter_pstatus(shared_ents, PSTATUS_INTERFACE, PSTATUS_AND);
+    RRA("");
+  }
+  
+    // filter by owned
+  if (owned_filter) {
+    result = filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+    RRA("");
+  }
+
+    // filter by proc
+  if (-1 != other_proc) {
+    result = filter_pstatus(shared_ents, PSTATUS_SHARED, PSTATUS_AND, other_proc);
+    RRA("");
+  }
+  
+  return result;
+}
+
+
+} // namespace moab
+
+#ifdef TEST_PARALLELCOMM
+
+#include <iostream>
+
+#include "moab/Core.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/Range.hpp"
+
+#define PM {std::cerr << "Test failed; error message:" << std::endl;\
+          std::string errmsg; \
+          dynamic_cast<Core*>(my_impl)->get_last_error(errmsg); \
+          std::cerr << errmsg << std::endl;\
+          return 1;}
+
+using namespace moab;
+
+int main(int argc, char* argv[])
+{
+
+    // Check command line arg
+  if (argc < 2)
+  {
+    std::cout << "Usage: " << argv[0] << " <mesh_file_name>" << std::endl;
+    exit(1);
+  }
+
+  const char* file = argv[1];
+  Core *my_impl = new Core(0, 2);
+  Interface* mbImpl = my_impl;
+
+    // create a communicator class, which will start mpi too
+  ParallelComm pcomm(mbImpl, my_impl->tag_server(), my_impl->sequence_manager());
+  ErrorCode result;
+
+    // load the mesh
+  result = mbImpl->load_mesh(file, 0, 0);
+  if (MB_SUCCESS != result) return result;
+
+    // get the mesh
+  Range all_mesh, whole_range;
+  result = mbImpl->get_entities_by_dimension(0, 3, all_mesh);
+  if (MB_SUCCESS != result) return result;
+    
+  int buff_size;
+  result = pcomm.pack_buffer(all_mesh, false, true, true, false, whole_range, buff_size);
+  PM;
+
+
+    // allocate space in the buffer
+  pcomm.buffer_size(buff_size);
+
+    // pack the actual buffer
+  int actual_buff_size;
+  result = pcomm.pack_buffer(whole_range, false, true, false, false, all_mesh, 
+                             actual_buff_size);
+  PM;
+
+    // list the entities that got packed
+  std::cout << "ENTITIES PACKED:" << std::endl;
+  mbImpl->list_entities(all_mesh);
+
+    // get the buffer
+  std::vector<unsigned char> tmp_buffer;
+  pcomm.take_buffer(tmp_buffer);
+    
+    // stop and restart MOAB
+  delete mbImpl;
+  my_impl = new Core(1, 2);
+  mbImpl = my_impl;
+    
+    // create a new communicator class, using our old buffer
+  ParallelComm pcomm2(mbImpl, my_impl->tag_server(), my_impl->sequence_manager(),
+                        tmp_buffer);
+
+    // unpack the results
+  all_mesh.clear();
+  result = pcomm2.unpack_buffer(all_mesh, store_remote_handles, from_proc);
+  PM;
+  
+  std::cout << "ENTITIES UNPACKED:" << std::endl;
+  mbImpl->list_entities(all_mesh);
+  
+  std::cout << "Success, processor " << mbImpl->proc_rank() << "." << std::endl;
+  
+  return 1;
+}
+
+#endif

Copied: MOAB/trunk/src/parallel/ParallelData.cpp (from rev 3583, MOAB/trunk/src/parallel/MBParallelData.cpp)
===================================================================
--- MOAB/trunk/src/parallel/ParallelData.cpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/ParallelData.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,100 @@
+#include "moab/ParallelData.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/Interface.hpp"
+
+#include <map>
+
+namespace moab {
+
+    //! return partition sets; if tag_name is input, gets sets with
+    //! that tag name, otherwise uses PARALLEL_PARTITION tag
+ErrorCode ParallelData::get_partition_sets(Range &part_sets,
+                                               const char *tag_name) 
+{
+  Tag part_tag = 0;
+  ErrorCode result;
+  
+  if (NULL != tag_name) 
+    result = mbImpl->tag_get_handle(tag_name, part_tag);
+  else
+    result = mbImpl->tag_get_handle(PARALLEL_PARTITION_TAG_NAME, part_tag);
+    
+  if (MB_SUCCESS != result) return result;
+  else if (0 == part_tag) return MB_TAG_NOT_FOUND;
+  
+  result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, 
+                                                NULL, 1, part_sets,
+                                                Interface::UNION);
+  return result;
+}
+  
+
+    //! get communication interface sets and the processors with which
+    //! this processor communicates; sets are sorted by processor
+ErrorCode ParallelData::get_interface_sets(std::vector<EntityHandle> &iface_sets,
+                                               std::vector<int> &iface_procs) 
+{
+#define CONTINUE {result = tmp_result; continue;}
+  iface_sets.clear();
+  iface_procs.clear();
+  
+  Tag proc_tag = 0, procs_tag = 0;
+  ErrorCode result = MB_SUCCESS;
+  int my_rank;
+  if (parallelComm) 
+    my_rank = parallelComm->proc_config().proc_rank();
+  else 
+    return MB_FAILURE;
+
+  std::multimap<int, EntityHandle> iface_data;
+
+  for (int i = 0; i < 2; i++) {
+    ErrorCode tmp_result;
+    
+    if (0 == i)
+      tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROC_TAG_NAME, 
+                                      proc_tag);
+    else
+      tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROCS_TAG_NAME, 
+                                      proc_tag);
+    if (0 == proc_tag) CONTINUE;
+
+    int tsize;
+    tmp_result = mbImpl->tag_get_size(proc_tag, tsize);
+    if (0 == tsize || MB_SUCCESS != tmp_result) CONTINUE;
+    
+    Range proc_sets;
+    tmp_result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, 
+                                                  &proc_tag, NULL, 1,
+                                                  proc_sets, Interface::UNION);
+    if (MB_SUCCESS != tmp_result) CONTINUE;
+    
+    if (proc_sets.empty()) CONTINUE;
+      
+    std::vector<int> proc_tags(proc_sets.size()*tsize/sizeof(int));
+    tmp_result = mbImpl->tag_get_data(procs_tag, proc_sets, &proc_tags[0]);
+    if (MB_SUCCESS != tmp_result) CONTINUE;
+    int k;
+    Range::iterator rit;
+    
+    for (k = 0, rit = proc_sets.begin(); rit != proc_sets.end(); rit++, k++) {
+      for (int j = 0; j < tsize; j++) {
+        if (my_rank != proc_tags[2*k+j] && proc_tags[2*k+j] >= 0)
+          iface_data.insert(std::pair<int,EntityHandle>(proc_tags[2*k+j], *rit));
+      }
+    }
+  }
+
+    // now get the results in sorted order
+  std::multimap<int,EntityHandle>::iterator mit;
+  for (mit = iface_data.begin(); mit != iface_data.end(); mit++)
+    iface_procs.push_back((*mit).first),
+      iface_sets.push_back((*mit).second);
+    
+  return result;
+}
+
+
+} // namespace moab
+

Copied: MOAB/trunk/src/parallel/ProcConfig.cpp (from rev 3583, MOAB/trunk/src/parallel/MBProcConfig.cpp)
===================================================================
--- MOAB/trunk/src/parallel/ProcConfig.cpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/ProcConfig.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,71 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#include "moab/ProcConfig.hpp"
+extern "C" {
+#ifdef USE_MPI
+#  include "types.h"
+#  include "errmem.h"
+#  include "crystal.h"
+#else
+   struct crystal_data {};
+#endif
+} // extern "C"
+
+namespace moab {
+
+
+//! Constructor
+ProcConfig::ProcConfig(MPI_Comm proc_comm) 
+    : procComm(proc_comm),
+      crystalData(0)
+{
+#ifdef USE_MPI
+  int rank, size;
+  MPI_Comm_rank(procComm, &rank); 
+  procRank = (unsigned int) rank;
+  MPI_Comm_size(procComm, &size); 
+  procSize = (unsigned int) size;
+#else
+  procRank = 0;
+  procSize = 1;
+#endif
+}
+
+crystal_data *ProcConfig::crystal_router(bool construct_if_missing)
+{
+#ifdef USE_MPI
+  if (!crystalData && construct_if_missing) {
+    crystalData = new crystal_data;
+    crystal_init(crystalData, procComm);
+  }
+#endif
+
+  return crystalData;
+}
+
+ProcConfig::~ProcConfig() 
+{
+  if (crystalData) {
+#ifdef USE_MPI
+    crystal_free(crystalData);
+#endif
+    delete crystalData;
+    crystalData = 0;
+  }
+}
+
+
+} // namespace moab

Modified: MOAB/trunk/src/parallel/ReadParallel.cpp
===================================================================
--- MOAB/trunk/src/parallel/ReadParallel.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/ReadParallel.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,13 +1,13 @@
 #include "ReadParallel.hpp"
-#include "MBCore.hpp"
-#include "MBProcConfig.hpp"
+#include "moab/Core.hpp"
+#include "moab/ProcConfig.hpp"
 #include "FileOptions.hpp"
-#include "MBError.hpp"
-#include "MBReaderWriterSet.hpp"
-#include "MBReadUtilIface.hpp"
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBCN.hpp"
+#include "Error.hpp"
+#include "moab/ReaderWriterSet.hpp"
+#include "moab/ReadUtilIface.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBCN.hpp"
 
 #include <iostream>
 #include <iomanip>
@@ -16,10 +16,12 @@
 #include <algorithm>
 #include <assert.h>
 
+namespace moab {
+
 const bool debug = false;
 
 #define RR(a) if (MB_SUCCESS != result) {                               \
-      dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(a); \
+      dynamic_cast<Core*>(mbImpl)->get_error_handler()->set_last_error(a); \
       return result;}
 
 const char *ReadParallel::ParallelActionsNames[] = {
@@ -42,29 +44,29 @@
                                                   "", 
                                                   0 };
 
-ReadParallel::ReadParallel(MBInterface* impl, 
-                           MBParallelComm *pc) 
+ReadParallel::ReadParallel(Interface* impl, 
+                           ParallelComm *pc) 
         : mbImpl(impl), myPcomm(pc) 
 {
   if (!myPcomm) {
-    myPcomm = MBParallelComm::get_pcomm(mbImpl, 0);
-    if (NULL == myPcomm) myPcomm = new MBParallelComm(mbImpl);
+    myPcomm = ParallelComm::get_pcomm(mbImpl, 0);
+    if (NULL == myPcomm) myPcomm = new ParallelComm(mbImpl);
   }
 }
 
-MBErrorCode ReadParallel::load_file(const char **file_names,
+ErrorCode ReadParallel::load_file(const char **file_names,
                                     const int num_files,
-                                    const MBEntityHandle* file_set,
+                                    const EntityHandle* file_set,
                                     const FileOptions &opts,
-                                    const MBReaderIface::IDTag* subset_list,
+                                    const ReaderIface::IDTag* subset_list,
                                     int subset_list_length,
-                                    const MBTag* file_id_tag ) 
+                                    const Tag* file_id_tag ) 
 {
-  MBError *merror = ((MBCore*)mbImpl)->get_error_handler();
+  Error *merror = ((Core*)mbImpl)->get_error_handler();
 
     // Get parallel settings
   int parallel_mode;
-  MBErrorCode result = opts.match_option( "PARALLEL", parallelOptsNames, 
+  ErrorCode result = opts.match_option( "PARALLEL", parallelOptsNames, 
                                           parallel_mode );
   if (MB_FAILURE == result) {
     merror->set_last_error( "Unexpected value for 'PARALLEL' option\n" );
@@ -220,9 +222,9 @@
                    ghost_dim, bridge_dim, num_layers);
 }
     
-MBErrorCode ReadParallel::load_file(const char **file_names,
+ErrorCode ReadParallel::load_file(const char **file_names,
                                     const int num_files,
-                                    const MBEntityHandle* file_set_ptr,
+                                    const EntityHandle* file_set_ptr,
                                     int parallel_mode, 
                                     std::string &partition_tag_name, 
                                     std::vector<int> &partition_tag_vals, 
@@ -230,9 +232,9 @@
                                     bool partition_by_rank,
                                     std::vector<int> &pa_vec,
                                     const FileOptions &opts,
-                                    const MBReaderIface::IDTag* subset_list,
+                                    const ReaderIface::IDTag* subset_list,
                                     int subset_list_length,
-                                    const MBTag* file_id_tag,
+                                    const Tag* file_id_tag,
                                     const int reader_rank,
                                     const bool cputime,
                                     const int resolve_dim,
@@ -241,18 +243,18 @@
                                     const int bridge_dim,
                                     const int num_layers) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   if (myPcomm == NULL)
-    myPcomm = new MBParallelComm(mbImpl);
+    myPcomm = new ParallelComm(mbImpl);
 
-  MBError *merror = ((MBCore*)mbImpl)->get_error_handler();
+  Error *merror = ((Core*)mbImpl)->get_error_handler();
 
-  MBRange entities; 
-  MBTag file_set_tag = 0;
+  Range entities; 
+  Tag file_set_tag = 0;
   int other_sets = 0;
-  MBReaderWriterSet::iterator iter;
-  MBRange other_file_sets, file_sets;
-  MBCore *impl = dynamic_cast<MBCore*>(mbImpl);
+  ReaderWriterSet::iterator iter;
+  Range other_file_sets, file_sets;
+  Core *impl = dynamic_cast<Core*>(mbImpl);
 
   std::vector<double> act_times(pa_vec.size()+1);
   double stime = 0.0;
@@ -262,18 +264,18 @@
   act_times[0] = MPI_Wtime();
   
     // make a new set for the parallel read
-  MBEntityHandle file_set;
+  EntityHandle file_set;
   result = mbImpl->create_meshset(MESHSET_SET, file_set);
   if (MB_SUCCESS != result) return result;
 
   bool i_read = false;
-  MBTag id_tag = 0;
+  Tag id_tag = 0;
   bool use_id_tag = false;
 
   for (i = 1, vit = pa_vec.begin();
        vit != pa_vec.end(); vit++, i++) {
 
-    MBErrorCode tmp_result = MB_SUCCESS;
+    ErrorCode tmp_result = MB_SUCCESS;
     switch (*vit) {
 //==================
       case PA_READ:
@@ -283,7 +285,7 @@
             if (debug)
               std::cout << "Reading file " << file_names[j] << std::endl;
 
-            MBEntityHandle new_file_set;
+            EntityHandle new_file_set;
             result = mbImpl->create_meshset(MESHSET_SET, new_file_set);
             if (MB_SUCCESS != result) return result;
             tmp_result = impl->serial_load_file( file_names[j], 
@@ -297,7 +299,7 @@
               // put the contents of each file set for the reader into the 
               // file set for the parallel read
             assert(0 != new_file_set);
-            MBRange all_ents;
+            Range all_ents;
             tmp_result = mbImpl->get_entities_by_handle(new_file_set, all_ents);
             if (MB_SUCCESS != tmp_result) break;
             all_ents.insert(new_file_set);
@@ -341,7 +343,7 @@
             }
           }
           
-          MBReaderIface::IDTag parts = { partition_tag_name.c_str(),
+          ReaderIface::IDTag parts = { partition_tag_name.c_str(),
                                          0, 0, 0, 0 };
           int rank = myPcomm->rank();
           if (partition_by_rank) {
@@ -357,7 +359,7 @@
               parts.num_tag_values = partition_tag_vals.size();
             }
           }
-          std::vector<MBReaderIface::IDTag> subset( subset_list, 
+          std::vector<ReaderIface::IDTag> subset( subset_list, 
                                                     subset_list + subset_list_length );
           subset.push_back( parts );
           tmp_result = impl->serial_load_file( *file_names, &file_set, opts, 
@@ -477,7 +479,7 @@
   }
 
   if (use_id_tag) {
-    MBErrorCode tmp_result = mbImpl->tag_delete( id_tag );
+    ErrorCode tmp_result = mbImpl->tag_delete( id_tag );
     if (MB_SUCCESS != tmp_result && MB_SUCCESS == result)
       result = tmp_result;
   }
@@ -495,7 +497,7 @@
   }
   
   if (MB_SUCCESS == result && file_set_ptr) {
-    MBRange all_ents;
+    Range all_ents;
     result = mbImpl->get_entities_by_handle(file_set, all_ents);
     if (MB_SUCCESS == result)
       result = mbImpl->add_entities(*file_set_ptr, all_ents);
@@ -504,15 +506,15 @@
   return result;
 }
 
-MBErrorCode ReadParallel::delete_nonlocal_entities(std::string &ptag_name,
+ErrorCode ReadParallel::delete_nonlocal_entities(std::string &ptag_name,
                                                    std::vector<int> &ptag_vals,
                                                    bool distribute,
-                                                   MBEntityHandle file_set) 
+                                                   EntityHandle file_set) 
 {
-  MBRange partition_sets;
-  MBErrorCode result;
+  Range partition_sets;
+  ErrorCode result;
 
-  MBTag ptag;
+  Tag ptag;
   result = mbImpl->tag_get_handle(ptag_name.c_str(), ptag); 
   RR("Failed getting tag handle in delete_nonlocal_entities.");
 
@@ -526,7 +528,7 @@
 
   if (!ptag_vals.empty()) {
       // values input, get sets with those values
-    MBRange tmp_sets;
+    Range tmp_sets;
     std::vector<int> tag_vals(myPcomm->partition_sets().size());
     result = mbImpl->tag_get_data(ptag, myPcomm->partition_sets(), &tag_vals[0]);
     RR("Failed to get tag data for partition vals tag.");
@@ -549,7 +551,7 @@
       RR("Number of procs greater than number of partitions.");
     }
     
-    MBRange tmp_sets;
+    Range tmp_sets;
       // distribute the partition sets
     unsigned int num_sets = myPcomm->partition_sets().size() / proc_sz;
     unsigned int num_leftover = myPcomm->partition_sets().size() % proc_sz;
@@ -578,17 +580,17 @@
   return result;
 }
 
-MBErrorCode ReadParallel::create_partition_sets( std::string &ptag_name,
-                                                 MBEntityHandle file_set )
+ErrorCode ReadParallel::create_partition_sets( std::string &ptag_name,
+                                                 EntityHandle file_set )
 {
   if (ptag_name == PARALLEL_PARTITION_TAG_NAME)
     return MB_SUCCESS;
   
   int proc_rk = myPcomm->proc_config().proc_rank();
-  MBRange partition_sets;
-  MBErrorCode result;
+  Range partition_sets;
+  ErrorCode result;
 
-  MBTag ptag;
+  Tag ptag;
   result = mbImpl->tag_get_handle(ptag_name.c_str(), ptag); 
   RR("Failed getting tag handle in create_partition_sets.");
 
@@ -606,7 +608,7 @@
     if (MB_ALREADY_ALLOCATED == result) {
         // this tag already exists; better check to see that tagged sets
         // agree with this partition
-      MBRange tagged_sets;
+      Range tagged_sets;
       int *proc_rk_ptr = &proc_rk;
       result = mbImpl->get_entities_by_type_and_tag(file_set, MBENTITYSET, &ptag, 
                                                     (const void* const*)&proc_rk_ptr, 1,
@@ -627,17 +629,17 @@
   return result;
 }
 
-MBErrorCode ReadParallel::delete_nonlocal_entities(MBEntityHandle file_set) 
+ErrorCode ReadParallel::delete_nonlocal_entities(EntityHandle file_set) 
 {
 
-  MBErrorCode result;
+  ErrorCode result;
 
     // get partition entities and ents related to/used by those
     // get ents in the partition
-  std::string iface_name = "MBReadUtilIface";
-  MBReadUtilIface *read_iface;
+  std::string iface_name = "ReadUtilIface";
+  ReadUtilIface *read_iface;
   mbImpl->query_interface(iface_name, reinterpret_cast<void**>(&read_iface));
-  MBRange partition_ents, all_sets;
+  Range partition_ents, all_sets;
 
   if (debug) std::cout << "Gathering related entities." << std::endl;
   
@@ -646,7 +648,7 @@
   RR("Failure gathering related entities.");
 
     // get pre-existing entities
-  MBRange file_ents;
+  Range file_ents;
   result = mbImpl->get_entities_by_handle(file_set, file_ents); 
   RR("Couldn't get pre-existing entities.");
 
@@ -656,16 +658,16 @@
   }
   
     // get deletable entities by subtracting partition ents from file ents
-  MBRange deletable_ents = subtract( file_ents, partition_ents);
+  Range deletable_ents = subtract( file_ents, partition_ents);
 
     // cache deletable vs. keepable sets
-  MBRange deletable_sets = intersect( all_sets, deletable_ents);
-  MBRange keepable_sets = subtract( all_sets, deletable_sets);
+  Range deletable_sets = intersect( all_sets, deletable_ents);
+  Range keepable_sets = subtract( all_sets, deletable_sets);
   
   if (debug) std::cout << "Removing deletable entities from keepable sets." << std::endl;
 
     // remove deletable ents from all keepable sets
-  for (MBRange::iterator rit = keepable_sets.begin();
+  for (Range::iterator rit = keepable_sets.begin();
        rit != keepable_sets.end(); rit++) {
     result = mbImpl->remove_entities(*rit, deletable_ents);
     RR("Failure removing deletable entities.");
@@ -698,3 +700,5 @@
 
   return result;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/parallel/ReadParallel.hpp
===================================================================
--- MOAB/trunk/src/parallel/ReadParallel.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/ReadParallel.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,41 +1,43 @@
 #ifndef READ_PARALLEL_HPP
 #define READ_PARALLEL_HPP
 
-#include "MBForward.hpp"
-#include "MBReaderIface.hpp"
+#include "moab/Forward.hpp"
+#include "moab/ReaderIface.hpp"
 
 #include <string>
 
-class MBReadUtilIface;
-class MBParallelComm;
+namespace moab {
 
+class ReadUtilIface;
+class ParallelComm;
+
 class ReadParallel
 {
    
 public:
 
-  static MBReaderIface* factory( MBInterface* );
+  static ReaderIface* factory( Interface* );
 
     //! load a file
-  MBErrorCode load_file(const char *file_name,
-                        const MBEntityHandle* file_set,
+  ErrorCode load_file(const char *file_name,
+                        const EntityHandle* file_set,
                         const FileOptions &opts,
-                        const MBReaderIface::IDTag* subset_list = 0,
+                        const ReaderIface::IDTag* subset_list = 0,
                         int subset_list_length = 0,
-                        const MBTag* file_id_tag = 0 );
+                        const Tag* file_id_tag = 0 );
   
     //! load multiple files
-  MBErrorCode load_file(const char **file_names,
+  ErrorCode load_file(const char **file_names,
                         const int num_files,
-                        const MBEntityHandle* file_set,
+                        const EntityHandle* file_set,
                         const FileOptions &opts,
-                        const MBReaderIface::IDTag* subset_list = 0,
+                        const ReaderIface::IDTag* subset_list = 0,
                         int subset_list_length = 0,
-                        const MBTag* file_id_tag = 0 );
+                        const Tag* file_id_tag = 0 );
   
-  MBErrorCode load_file(const char **file_names,
+  ErrorCode load_file(const char **file_names,
                         const int num_files,
-                        const MBEntityHandle* file_set,
+                        const EntityHandle* file_set,
                         int parallel_mode, 
                         std::string &partition_tag_name, 
                         std::vector<int> &partition_tag_vals, 
@@ -43,9 +45,9 @@
                         bool partition_by_rank,
                         std::vector<int> &pa_vec,
                         const FileOptions &opts,
-                        const MBReaderIface::IDTag* subset_list,
+                        const ReaderIface::IDTag* subset_list,
                         int subset_list_length,
-                        const MBTag* file_id_tag,
+                        const Tag* file_id_tag,
                         const int reader_rank,
                         const bool cputime,
                         const int resolve_dim,
@@ -54,7 +56,7 @@
                         const int bridge_dim,
                         const int num_layers);
     //! Constructor
-  ReadParallel(MBInterface* impl = NULL, MBParallelComm *pc = NULL);
+  ReadParallel(Interface* impl = NULL, ParallelComm *pc = NULL);
 
    //! Destructor
   virtual ~ReadParallel() {}
@@ -81,34 +83,36 @@
                       POPT_DEFAULT};
 
     //! PUBLIC TO ALLOW TESTING
-  MBErrorCode delete_nonlocal_entities(std::string &ptag_name,
+  ErrorCode delete_nonlocal_entities(std::string &ptag_name,
                                        std::vector<int> &ptag_vals,
                                        bool distribute,
-                                       MBEntityHandle file_set);
+                                       EntityHandle file_set);
   
-  MBErrorCode delete_nonlocal_entities(MBEntityHandle file_set);
+  ErrorCode delete_nonlocal_entities(EntityHandle file_set);
 
 protected:
-  MBErrorCode create_partition_sets( std::string &ptag_name,
-                                     MBEntityHandle file_set );
+  ErrorCode create_partition_sets( std::string &ptag_name,
+                                     EntityHandle file_set );
 
 private:
 
-  MBInterface *mbImpl;
+  Interface *mbImpl;
 
     // each reader can keep track of its own pcomm
-  MBParallelComm *myPcomm;
+  ParallelComm *myPcomm;
 };
 
-inline MBErrorCode ReadParallel::load_file(const char *file_name,
-                                           const MBEntityHandle* file_set,
+inline ErrorCode ReadParallel::load_file(const char *file_name,
+                                           const EntityHandle* file_set,
                                            const FileOptions &opts,
-                                           const MBReaderIface::IDTag* subset_list,
+                                           const ReaderIface::IDTag* subset_list,
                                            int subset_list_length,
-                                           const MBTag* file_id_tag )
+                                           const Tag* file_id_tag )
 {
   return load_file(&file_name, 1, file_set, opts, 
                    subset_list, subset_list_length, file_id_tag);
 }
-  
+
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/parallel/WriteHDF5Parallel.cpp
===================================================================
--- MOAB/trunk/src/parallel/WriteHDF5Parallel.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/WriteHDF5Parallel.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -22,7 +22,7 @@
 #include <iostream>
 #include <sstream>
 
-#include "MBmpi.h"
+#include "moab_mpi.h"
 
 #include <H5Tpublic.h>
 #include <H5Ppublic.h>
@@ -31,17 +31,18 @@
 
 #include "mhdf.h"
 
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBTagConventions.hpp"
-#include "MBParallelConventions.h"
-#include "MBParallelComm.hpp"
-#include "MBCN.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MBRange.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "moab/Range.hpp"
 
 #include "WriteHDF5Parallel.hpp"
 
+namespace moab {
 
 #define CHECK_MPI(A) do { if (MPI_SUCCESS != (A)) { \
   writeUtil->report_error( "MPI Failure at " __FILE__ ":%d\n", __LINE__ ); \
@@ -124,19 +125,19 @@
 
 
 #ifndef DEBUG
-void WriteHDF5Parallel::printrange( MBRange& ) {}
+void WriteHDF5Parallel::printrange( Range& ) {}
 #else
-void WriteHDF5Parallel::printrange( MBRange& r )
+void WriteHDF5Parallel::printrange( Range& r )
 {
   int rank;
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
-  MBEntityType type = MBMAXTYPE;
-  for (MBRange::const_pair_iterator i = r.const_pair_begin(); i != r.const_pair_end(); ++i)
+  EntityType type = MBMAXTYPE;
+  for (Range::const_pair_iterator i = r.const_pair_begin(); i != r.const_pair_end(); ++i)
   {
-    MBEntityHandle a, b;
+    EntityHandle a, b;
     a = (*i).first;
     b = (*i).second;
-    MBEntityType mytype = iFace->type_from_handle(a);
+    EntityType mytype = iFace->type_from_handle(a);
     if (mytype != type)
     {
       type = mytype;
@@ -156,19 +157,19 @@
 
 
 #ifndef DEBUG
-static void print_type_sets( MBInterface* , int , int , MBRange& ) {}
+static void print_type_sets( Interface* , int , int , Range& ) {}
 #else
-static void print_type_sets( MBInterface* iFace, int rank, int size, MBRange& sets )
+static void print_type_sets( Interface* iFace, int rank, int size, Range& sets )
 {
-  MBTag gid, did, bid, sid, nid;
+  Tag gid, did, bid, sid, nid;
   iFace->tag_get_handle( GLOBAL_ID_TAG_NAME, gid ); 
   iFace->tag_get_handle( GEOM_DIMENSION_TAG_NAME, did );
   iFace->tag_get_handle( MATERIAL_SET_TAG_NAME, bid );
   iFace->tag_get_handle( DIRICHLET_SET_TAG_NAME, nid );
   iFace->tag_get_handle( NEUMANN_SET_TAG_NAME, sid );
-  MBRange typesets[10];
+  Range typesets[10];
   const char* typenames[] = {"Block", "Sideset", "NodeSet", "Vertex", "Curve", "Surface", "Volume", "Body", "Other"};
-  for (MBRange::iterator riter = sets.begin(); riter != sets.end(); ++riter)
+  for (Range::iterator riter = sets.begin(); riter != sets.end(); ++riter)
   {
     unsigned dim, id, oldsize;
     if (MB_SUCCESS == iFace->tag_get_data(bid, &*riter, 1, &id)) 
@@ -199,7 +200,7 @@
       continue;
     sprintf(num, "(%lu):",(unsigned long)typesets[ii].size());
     line += num;
-    for (MBRange::const_pair_iterator piter = typesets[ii].const_pair_begin();
+    for (Range::const_pair_iterator piter = typesets[ii].const_pair_begin();
          piter != typesets[ii].const_pair_end(); ++piter)
     {
       sprintf(num," %lx", (unsigned long)(*piter).first);
@@ -217,17 +218,17 @@
 #endif
 
 
-static void range_remove( MBRange& from, const MBRange& removed )
+static void range_remove( Range& from, const Range& removed )
 {
   
 /* The following should be more efficient, but isn't due
-   to the inefficient implementation of MBRange::erase(iter,iter)
-  MBRange::const_iterator s, e, n = from.begin();
-  for (MBRange::const_pair_iterator p = removed.pair_begin();
+   to the inefficient implementation of Range::erase(iter,iter)
+  Range::const_iterator s, e, n = from.begin();
+  for (Range::const_pair_iterator p = removed.pair_begin();
        p != removed.pair_end(); ++p)
   {
-    e = s = MBRange::lower_bound(n, from.end(), (*p).first);
-    e = MBRange::lower_bound(s, from.end(), (*p).second);
+    e = s = Range::lower_bound(n, from.end(), (*p).first);
+    e = Range::lower_bound(s, from.end(), (*p).second);
     if (e != from.end() && *e == (*p).second)
       ++e;
     n = from.erase( s, e );
@@ -236,12 +237,12 @@
 
   if (removed.size())
   {
-    MBRange tmp = subtract( from, removed);
+    Range tmp = subtract( from, removed);
     from.swap( tmp );
   }
 }
 
-MBWriterIface* WriteHDF5Parallel::factory( MBInterface* iface )
+WriterIface* WriteHDF5Parallel::factory( Interface* iface )
   { return new WriteHDF5Parallel( iface ); }
 
 void WriteHDF5Parallel::MultiProcSetTags::add( const std::string& name )
@@ -257,7 +258,7 @@
   { list.push_back( Data(filter,data,filterval) ); }
 
 
-WriteHDF5Parallel::WriteHDF5Parallel( MBInterface* iface)
+WriteHDF5Parallel::WriteHDF5Parallel( Interface* iface)
     : WriteHDF5(iface), myPcomm(NULL), pcommAllocated(false)
 {
   multiProcSetTags.add(  MATERIAL_SET_TAG_NAME );
@@ -269,7 +270,7 @@
   multiProcSetTags.add( GEOM_DIMENSION_TAG_NAME, 3, GLOBAL_ID_TAG_NAME );
 }
 
-WriteHDF5Parallel::WriteHDF5Parallel( MBInterface* iface,
+WriteHDF5Parallel::WriteHDF5Parallel( Interface* iface,
                                       const std::vector<std::string>& tag_names )
   : WriteHDF5(iface), myPcomm(NULL), pcommAllocated(false)
 {
@@ -278,7 +279,7 @@
     multiProcSetTags.add( *i );
 }
 
-WriteHDF5Parallel::WriteHDF5Parallel( MBInterface* iface,
+WriteHDF5Parallel::WriteHDF5Parallel( Interface* iface,
                                       const MultiProcSetTags& set_tags )
     : WriteHDF5(iface), multiProcSetTags(set_tags), myPcomm(NULL), 
       pcommAllocated(false)
@@ -295,11 +296,11 @@
 // (and for elements, connectivity length).  This function:
 //  o determines which entities are to be written by a remote processor
 //  o removes those entities from the ExportSet structs in WriteMesh
-//  o puts them in the 'interfaceMesh' array of MBRanges in this class
+//  o puts them in the 'interfaceMesh' array of Ranges in this class
 //  o sets their file Id to '1'
-MBErrorCode WriteHDF5Parallel::gather_interface_meshes()
+ErrorCode WriteHDF5Parallel::gather_interface_meshes()
 {
-  MBErrorCode result;
+  ErrorCode result;
   
   //START_SERIAL;
   printdebug( "Pre-interface mesh:\n");
@@ -309,11 +310,11 @@
     printrange(eiter->range);
   printrange(setSet.range);
   
-  MBRange iface_sets = myPcomm->interface_sets();
+  Range iface_sets = myPcomm->interface_sets();
 
     // Populate lists of interface mesh entities
-  MBRange tmpset;
-  for (MBRange::iterator ifit = iface_sets.begin(); ifit != iface_sets.end(); ifit++) {
+  Range tmpset;
+  for (Range::iterator ifit = iface_sets.begin(); ifit != iface_sets.end(); ifit++) {
     int owner;
     result = myPcomm->get_owner(*ifit, owner);
     if (MB_SUCCESS != result || -1 == owner) return result;
@@ -332,7 +333,7 @@
     // First move handles of non-owned entities from lists of entities
     // that this processor will write to the 'nonowned' list.
     
-  MBRange nonowned;
+  Range nonowned;
   result = myPcomm->filter_pstatus( nodeSet.range, PSTATUS_NOT_OWNED, PSTATUS_AND, -1, &nonowned);
   if (MB_SUCCESS != result)
     return result;
@@ -362,7 +363,7 @@
   for (std::list<ExportSet>::iterator eiter = exportList.begin();
        eiter != exportList.end(); ++eiter ) 
     tmpset.merge( eiter->range );
-  MBRange& my_remote_mesh = interfaceMesh[myPcomm->proc_config().proc_rank()];
+  Range& my_remote_mesh = interfaceMesh[myPcomm->proc_config().proc_rank()];
   my_remote_mesh = intersect( my_remote_mesh,  tmpset );
   
     // print some debug output summarizing what we've accomplished
@@ -385,21 +386,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5Parallel::parallel_create_file( const char* filename,
+ErrorCode WriteHDF5Parallel::parallel_create_file( const char* filename,
                                             bool overwrite,
                                             const std::vector<std::string>& qa_records,
-                                            const MBTag* user_tag_list,
+                                            const Tag* user_tag_list,
                                             int user_tag_count,
                                             int dimension,
                                             int pcomm_no)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int result;
   mhdf_Status status;
 
-  myPcomm = MBParallelComm::get_pcomm(iFace, pcomm_no);
+  myPcomm = ParallelComm::get_pcomm(iFace, pcomm_no);
   if (0 == myPcomm) {
-    myPcomm = new MBParallelComm(iFace);
+    myPcomm = new ParallelComm(iFace);
     pcommAllocated = true;
   }
 
@@ -420,7 +421,7 @@
       // create the file
     const char* type_names[MBMAXTYPE];
     memset( type_names, 0, MBMAXTYPE * sizeof(char*) );
-    for (MBEntityType i = MBEDGE; i < MBENTITYSET; ++i)
+    for (EntityType i = MBEDGE; i < MBENTITYSET; ++i)
       type_names[i] = MBCN::EntityTypeName( i );
    
 tprint("call mhdf_createFile");
@@ -475,7 +476,7 @@
   
     /* Need to write tags for shared sets this proc is responsible for */
   
-  MBRange parallel_sets;
+  Range parallel_sets;
   for (std::list<ParallelSet>::const_iterator psiter = parallelSets.begin();
        psiter != parallelSets.end(); ++psiter)
     if (psiter->description)
@@ -642,7 +643,7 @@
 }
 
 
-MBErrorCode WriteHDF5Parallel::create_node_table( int dimension )
+ErrorCode WriteHDF5Parallel::create_node_table( int dimension )
 {
   int result;
   mhdf_Status status;
@@ -728,7 +729,7 @@
 };
 
 
-MBErrorCode WriteHDF5Parallel::negotiate_type_list()
+ErrorCode WriteHDF5Parallel::negotiate_type_list()
 {
   int result;
   
@@ -759,7 +760,7 @@
   {
     int type = *viter; ++viter;
     int count = *viter; ++viter;
-    printdebug("  %s : %d\n", MBCN::EntityTypeName((MBEntityType)type), count);
+    printdebug("  %s : %d\n", MBCN::EntityTypeName((EntityType)type), count);
   }
   END_SERIAL;
   #endif
@@ -822,7 +823,7 @@
   {
     int type = *viter; ++viter;
     int count = *viter; ++viter;
-    printdebug("  %s : %d\n", MBCN::EntityTypeName((MBEntityType)type), count);
+    printdebug("  %s : %d\n", MBCN::EntityTypeName((EntityType)type), count);
   }
   END_SERIAL;
   #endif
@@ -850,7 +851,7 @@
     if (!equal)
     {
       ExportSet insert;
-      insert.type = (MBEntityType)mbtype;
+      insert.type = (EntityType)mbtype;
       insert.num_nodes = numnode;
       insert.first_id = 0;
       insert.offset = 0;
@@ -862,10 +863,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5Parallel::create_element_tables()
+ErrorCode WriteHDF5Parallel::create_element_tables()
 {
   int result;
-  MBErrorCode rval;
+  ErrorCode rval;
   std::list<ExportSet>::iterator ex_iter;
   std::vector<long>::iterator viter;
   
@@ -948,9 +949,9 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode WriteHDF5Parallel::create_adjacency_tables()
+ErrorCode WriteHDF5Parallel::create_adjacency_tables()
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   unsigned int j;
   int i, result;
@@ -1059,12 +1060,12 @@
 }
 
 /*
-MBErrorCode WriteHDF5Parallel::get_interface_set_data( RemoteSetData& data,
+ErrorCode WriteHDF5Parallel::get_interface_set_data( RemoteSetData& data,
                                                        long& offset )
 {
   const char* PROC_ID_TAG = "HDF5Writer_Rank";
-  MBTag iface_tag, proc_tag;
-  MBErrorCode rval;
+  Tag iface_tag, proc_tag;
+  ErrorCode rval;
   
   rval = iFace->tag_get_handle( PARALLEL_INTERFACE_TAG_NAME, iface_tag );
   if (MB_SUCCESS != rval) return rval;
@@ -1075,12 +1076,12 @@
   rval = iFace->tag_create( PROC_ID_TAG, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, proc_tag, 0 );
   if (MB_SUCCESS != rval) return rval;
     
-  MBRange interface_sets, sets;
+  Range interface_sets, sets;
   rval = iFace->get_entities_by_type_and_tag( 0, MBENTITYSET, &iface_tag, 0, 1, interface_sets );
   if (MB_SUCCESS != rval) return rval;
   
   std::vector<int> list;
-  for (MBRange::iterator i = interface_sets.begin(); i != interface_sets.end(); ++i)
+  for (Range::iterator i = interface_sets.begin(); i != interface_sets.end(); ++i)
   {
     int proc_ids[2];
     rval = iFace->tag_get_data( iface_tag, &*i, 1, proc_ids );
@@ -1102,10 +1103,10 @@
   
 /** Working data for group of global sets identified by an ID tag */
 struct RemoteSetData {
-  MBTag data_tag;    //!< The ID tag for matching sets across processors
-  MBTag filter_tag;  //!< Optional tag to filter on (e.g. geometric dimension)
+  Tag data_tag;    //!< The ID tag for matching sets across processors
+  Tag filter_tag;  //!< Optional tag to filter on (e.g. geometric dimension)
   int filter_value;  //!< Value of filter_tag for this group
-  MBRange range;     //!< Set handles with data_tag set (and optionally filter_tag == filter_value)
+  Range range;     //!< Set handles with data_tag set (and optionally filter_tag == filter_value)
   std::vector<int> counts;       //!< Number of sets with tag on each proc, indexed by MPI rank
   std::vector<int> displs;       //!< Offset in all_values at which the data_tag values for
                                  //!< each processor begin. displs[n] = sum(i from 0 to n-1)(counts[i])
@@ -1115,7 +1116,7 @@
   std::vector<int> local_values; //!< data_tag values for sets that exist on this processor
 };
 
-static void print_remote_set_data( std::ostream& s, MBInterface* mb,
+static void print_remote_set_data( std::ostream& s, Interface* mb,
                             const struct RemoteSetData& data,
                             const char* pfx = "" )
 {
@@ -1144,14 +1145,14 @@
   std::cerr << std::endl;
 }
 
-MBErrorCode WriteHDF5Parallel::get_remote_set_data( 
+ErrorCode WriteHDF5Parallel::get_remote_set_data( 
                         const WriteHDF5Parallel::MultiProcSetTags::Data& tags,
                         RemoteSetData& data, long& offset )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int i;
   int result;
-  MBRange::iterator riter;
+  Range::iterator riter;
 
   rval = iFace->tag_get_handle( tags.filterTag.c_str(), data.filter_tag );
   if (rval != MB_SUCCESS) return rval;
@@ -1189,7 +1190,7 @@
   if (rval != MB_TAG_NOT_FOUND)
   {
     if (tags.useFilterValue) {
-      MBTag handles[] = { data.filter_tag, data.data_tag };
+      Tag handles[] = { data.filter_tag, data.data_tag };
       const void* values[] = {&tags.filterValue, 0 };
       rval = iFace->get_entities_by_type_and_tag( 0, 
                                                   MBENTITYSET, 
@@ -1207,7 +1208,7 @@
                                                   data.range );
     }
     if (rval != MB_SUCCESS) return rval;
-    MBRange tmp = intersect( data.range,  setSet.range );
+    Range tmp = intersect( data.range,  setSet.range );
     data.range.swap( tmp );
     range_remove( setSet.range, data.range );
   }
@@ -1330,7 +1331,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5Parallel::set_shared_set_ids( RemoteSetData& data, long& offset )
+ErrorCode WriteHDF5Parallel::set_shared_set_ids( RemoteSetData& data, long& offset )
 {
     // Determine File ID for each shared set.
   std::map<int,long> val_id_map; // Map from tag value to file ID for set
@@ -1340,7 +1341,7 @@
     if (p == val_id_map.end())
       val_id_map[data.all_values[i]] = offset++;
   }
-  MBRange::const_iterator riter = data.range.begin();
+  Range::const_iterator riter = data.range.begin();
   for (size_t i = 0; i < data.local_values.size(); ++i, ++riter)
   {
     std::map<int,long>::iterator p = val_id_map.find( data.local_values[i] );
@@ -1385,12 +1386,12 @@
 }
   
 
-MBErrorCode WriteHDF5Parallel::create_meshset_tables()
+ErrorCode WriteHDF5Parallel::create_meshset_tables()
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   int result, i;
   long total_offset = 0;
-  MBRange::const_iterator riter;
+  Range::const_iterator riter;
 
   START_SERIAL;
   print_type_sets( iFace, myPcomm->proc_config().proc_rank(), myPcomm->proc_config().proc_size(), setSet.range );
@@ -1535,10 +1536,10 @@
   return MB_SUCCESS;
 }
 
-void WriteHDF5Parallel::remove_remote_entities( MBEntityHandle relative,
-                                                MBRange& range )
+void WriteHDF5Parallel::remove_remote_entities( EntityHandle relative,
+                                                Range& range )
 {
-  MBRange result;
+  Range result;
   result.merge( intersect( range,  nodeSet.range ) );
   result.merge( intersect( range,  setSet.range ) );  
   for (std::list<ExportSet>::iterator eiter = exportList.begin();
@@ -1547,22 +1548,22 @@
     result.merge( intersect( range, eiter->range ) );
   }
   //result.merge( intersect( range, myParallelSets ) );
-  MBRange sets;
+  Range sets;
   int junk;
-  sets.merge( MBRange::lower_bound( range.begin(), range.end(), CREATE_HANDLE(MBENTITYSET, 0, junk )), range.end() );
+  sets.merge( Range::lower_bound( range.begin(), range.end(), CREATE_HANDLE(MBENTITYSET, 0, junk )), range.end() );
   remove_remote_sets( relative, sets );
   result.merge( sets );
   range.swap(result);
 }
 
-void WriteHDF5Parallel::remove_remote_sets( MBEntityHandle relative, 
-                                            MBRange& range )
+void WriteHDF5Parallel::remove_remote_sets( EntityHandle relative, 
+                                            Range& range )
 {
-  MBRange result( intersect( range,  setSet.range ) );
+  Range result( intersect( range,  setSet.range ) );
   //result.merge( intersect( range, yParallelSets ) );
-  MBRange remaining( subtract( range, result ) );
+  Range remaining( subtract( range, result ) );
   
-  for(MBRange::iterator i = remaining.begin(); i != remaining.end(); ++i)
+  for(Range::iterator i = remaining.begin(); i != remaining.end(); ++i)
   {
       // Look for the first CPU which knows about both sets.
     proc_iter cpu;
@@ -1585,11 +1586,11 @@
   
   
 
-void WriteHDF5Parallel::remove_remote_entities( MBEntityHandle relative,
-                                                std::vector<MBEntityHandle>& vect )
+void WriteHDF5Parallel::remove_remote_entities( EntityHandle relative,
+                                                std::vector<EntityHandle>& vect )
 {
-  MBRange intrsct;
-  for (std::vector<MBEntityHandle>::const_iterator iter = vect.begin();
+  Range intrsct;
+  for (std::vector<EntityHandle>::const_iterator iter = vect.begin();
        iter != vect.end(); ++iter)
     intrsct.insert(*iter);
   remove_remote_entities( relative, intrsct );
@@ -1610,11 +1611,11 @@
 
   
 
-void WriteHDF5Parallel::remove_remote_sets( MBEntityHandle relative,
-                                            std::vector<MBEntityHandle>& vect )
+void WriteHDF5Parallel::remove_remote_sets( EntityHandle relative,
+                                            std::vector<EntityHandle>& vect )
 {
-  MBRange intrsct;
-  for (std::vector<MBEntityHandle>::const_iterator iter = vect.begin();
+  Range intrsct;
+  for (std::vector<EntityHandle>::const_iterator iter = vect.begin();
        iter != vect.end(); ++iter)
     intrsct.insert(*iter);
   remove_remote_sets( relative, intrsct );
@@ -1636,12 +1637,12 @@
 // Given a RemoteSetData object describing the set information for a 
 // single tag (or tag pair), populate the list of parallel sets
 // (this->parallelSets) with the per-entityset data.
-MBErrorCode WriteHDF5Parallel::negotiate_remote_set_contents( RemoteSetData& data,
+ErrorCode WriteHDF5Parallel::negotiate_remote_set_contents( RemoteSetData& data,
                                                               long* offsets /* long[3] */ )
 {
   unsigned i;
-  MBErrorCode rval;
-  MBRange::const_iterator riter;
+  ErrorCode rval;
+  Range::const_iterator riter;
   int result;
   const unsigned count = data.range.size();
   const unsigned total = data.all_values.size();
@@ -1651,8 +1652,8 @@
   std::vector<long> local_sizes(3*count);
   VALGRIND_MAKE_VEC_UNDEFINED( local_sizes );
   std::vector<long>::iterator sizes_iter = local_sizes.begin();
-  MBRange tmp_range;
-  std::vector<MBEntityHandle> child_list;
+  Range tmp_range;
+  std::vector<EntityHandle> child_list;
   for (riter = data.range.begin(); riter != data.range.end(); ++riter)
   {
       // Count contents
@@ -1662,7 +1663,7 @@
     if (MB_SUCCESS != rval)
       return rval;
     remove_remote_entities( *riter, tmp_range );
-    for (MBRange::iterator iter = tmp_range.begin(); iter != tmp_range.end(); ++iter)
+    for (Range::iterator iter = tmp_range.begin(); iter != tmp_range.end(); ++iter)
       if (0 != idMap.find( *iter ))
         ++*sizes_iter;
     ++sizes_iter;
@@ -1674,7 +1675,7 @@
     if (MB_SUCCESS != rval)
       return rval;
     remove_remote_sets( *riter, child_list );
-    for (std::vector<MBEntityHandle>::iterator iter = child_list.begin();
+    for (std::vector<EntityHandle>::iterator iter = child_list.begin();
          iter != child_list.end(); ++iter)
       if (0 != idMap.find( *iter ))
         ++*sizes_iter;
@@ -1687,7 +1688,7 @@
     if (MB_SUCCESS != rval)
       return rval;
     remove_remote_sets( *riter, child_list );
-    for (std::vector<MBEntityHandle>::iterator iter = child_list.begin();
+    for (std::vector<EntityHandle>::iterator iter = child_list.begin();
          iter != child_list.end(); ++iter)
       if (0 != idMap.find( *iter ))
         ++*sizes_iter;
@@ -1875,7 +1876,7 @@
 }
 
 
-MBErrorCode WriteHDF5Parallel::write_shared_set_descriptions( hid_t table )
+ErrorCode WriteHDF5Parallel::write_shared_set_descriptions( hid_t table )
 {
 //char buffer[256];
 //sprintf(buffer, "write_shared_set_descriptions( %u )", (unsigned)parallelSets.size() );
@@ -1883,7 +1884,7 @@
 tprint( "write_shared_set_descriptions" );
 
   const id_t start_id = setSet.first_id;
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
   
   for( std::list<ParallelSet>::const_iterator iter = parallelSets.begin();
@@ -1918,13 +1919,13 @@
 }
     
 
-MBErrorCode WriteHDF5Parallel::write_shared_set_contents( hid_t table )
+ErrorCode WriteHDF5Parallel::write_shared_set_contents( hid_t table )
 {
 tprint( "write_shared_set_contents" );
 
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  std::vector<MBEntityHandle> handle_list;
+  std::vector<EntityHandle> handle_list;
   std::vector<id_t> id_list;
   
   for( std::list<ParallelSet>::const_iterator iter = parallelSets.begin();
@@ -1956,13 +1957,13 @@
 }
     
 
-MBErrorCode WriteHDF5Parallel::write_shared_set_children( hid_t table )
+ErrorCode WriteHDF5Parallel::write_shared_set_children( hid_t table )
 {
 tprint( "write_shared_set_children" );
 
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  std::vector<MBEntityHandle> handle_list;
+  std::vector<EntityHandle> handle_list;
   std::vector<id_t> id_list;
   
   printdebug("Writing %d parallel sets.\n", parallelSets.size());
@@ -1994,13 +1995,13 @@
 }
     
 
-MBErrorCode WriteHDF5Parallel::write_shared_set_parents( hid_t table )
+ErrorCode WriteHDF5Parallel::write_shared_set_parents( hid_t table )
 {
 tprint( "write_shared_set_parents" );
 
-  MBErrorCode rval;
+  ErrorCode rval;
   mhdf_Status status;
-  std::vector<MBEntityHandle> handle_list;
+  std::vector<EntityHandle> handle_list;
   std::vector<id_t> id_list;
   
   printdebug("Writing %d parallel sets.\n", parallelSets.size());
@@ -2031,7 +2032,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode WriteHDF5Parallel::write_finished()
+ErrorCode WriteHDF5Parallel::write_finished()
 {
   parallelSets.clear();
   cpuParallelSets.clear();
@@ -2059,10 +2060,10 @@
 }
 
 class TagNameCompare {
-  MBInterface* iFace;
+  Interface* iFace;
   std::string name1, name2;
 public:
-  TagNameCompare( MBInterface* iface ) : iFace(iface) {}
+  TagNameCompare( Interface* iface ) : iFace(iface) {}
   bool operator() (const WriteHDF5::SparseTag& t1, 
                    const WriteHDF5::SparseTag& t2);
 };
@@ -2080,13 +2081,13 @@
 }
 
 
-MBErrorCode WriteHDF5Parallel::exchange_file_ids()
+ErrorCode WriteHDF5Parallel::exchange_file_ids()
 {
     // create tag to store file IDs
-  MBEntityHandle default_val = 0;
-  MBTag file_id_tag = 0;
-  MBErrorCode rval = iFace->tag_create( "__hdf5_ll_fileid", 
-                                        sizeof(MBEntityHandle),
+  EntityHandle default_val = 0;
+  Tag file_id_tag = 0;
+  ErrorCode rval = iFace->tag_create( "__hdf5_ll_fileid", 
+                                        sizeof(EntityHandle),
                                         MB_TAG_DENSE,
                                         MB_TYPE_HANDLE,
                                         file_id_tag,
@@ -2095,11 +2096,11 @@
     return rval;
 
     // get file ids for my interface entities
-  MBRange::const_iterator i;
-  const MBRange& imesh = interfaceMesh[myPcomm->proc_config().proc_rank()];
-  std::vector<MBEntityHandle> file_id_vect( imesh.size() );
+  Range::const_iterator i;
+  const Range& imesh = interfaceMesh[myPcomm->proc_config().proc_rank()];
+  std::vector<EntityHandle> file_id_vect( imesh.size() );
   VALGRIND_MAKE_VEC_UNDEFINED( file_id_vect );
-  std::vector<MBEntityHandle>::iterator j = file_id_vect.begin();
+  std::vector<EntityHandle>::iterator j = file_id_vect.begin();
   for (i = imesh.begin(); i != imesh.end(); ++i, ++j) {
     *j = idMap.find( *i );
     if (!*j) {
@@ -2119,7 +2120,7 @@
   }
   
     // do communication
-  MBRange dum_range;
+  Range dum_range;
   rval = myPcomm->exchange_tags( file_id_tag, dum_range );
   if (MB_SUCCESS != rval) {
     iFace->tag_delete( file_id_tag );
@@ -2158,25 +2159,25 @@
 }
 
 
-MBErrorCode WriteHDF5Parallel::get_sharedset_tags() 
+ErrorCode WriteHDF5Parallel::get_sharedset_tags() 
 {
     // get all the sets
-  MBRange all_sets;
-  MBErrorCode result = iFace->get_entities_by_type_and_tag(0, MBENTITYSET, NULL, NULL, 0,
+  Range all_sets;
+  ErrorCode result = iFace->get_entities_by_type_and_tag(0, MBENTITYSET, NULL, NULL, 0,
                                                            all_sets);
   if (MB_SUCCESS != result || all_sets.empty()) return result;
   
     // get all the tags on those sets & test against known exceptions
-  std::set<MBTag> all_tags;
-  std::vector<MBTag> all_tagsv;
+  std::set<Tag> all_tags;
+  std::vector<Tag> all_tagsv;
   std::string tag_name;
   
-  for (MBRange::iterator rit = all_sets.begin(); rit != all_sets.end(); rit++) {
+  for (Range::iterator rit = all_sets.begin(); rit != all_sets.end(); rit++) {
     all_tagsv.clear();
     result = iFace->tag_get_tags_on_entity(*rit, all_tagsv);
     if (MB_SUCCESS != result) return result;
 
-    for (std::vector<MBTag>::iterator vit = all_tagsv.begin(); vit != all_tagsv.end(); vit++) {
+    for (std::vector<Tag>::iterator vit = all_tagsv.begin(); vit != all_tagsv.end(); vit++) {
         // don't look at tags already selected
       if (std::find(all_tags.begin(), all_tags.end(), *vit) != all_tags.end()) continue;
 
@@ -2199,7 +2200,7 @@
   }
   
     // now add the tag names to the list
-  for (std::set<MBTag>::iterator sit = all_tags.begin(); sit != all_tags.end(); sit++) {
+  for (std::set<Tag>::iterator sit = all_tags.begin(); sit != all_tags.end(); sit++) {
     result = iFace->tag_get_name(*sit, tag_name);
     if (MB_SUCCESS != result) return result;
     multiProcSetTags.add( tag_name);
@@ -2207,3 +2208,5 @@
     
   return MB_SUCCESS;
 }
+
+} // namespace moab

Modified: MOAB/trunk/src/parallel/WriteHDF5Parallel.hpp
===================================================================
--- MOAB/trunk/src/parallel/WriteHDF5Parallel.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/WriteHDF5Parallel.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -9,17 +9,19 @@
 #define WRITE_HDF5_PARALLEL_HPP
 
 #include "WriteHDF5.hpp"
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include <map>
 
+namespace moab {
+
 struct RemoteSetData;
-class MBParallelComm;
+class ParallelComm;
 
-class MB_DLL_EXPORT WriteHDF5Parallel : public WriteHDF5
+class WriteHDF5Parallel : public WriteHDF5
 {
   public:
 
-    static MBWriterIface* factory( MBInterface* );
+    static WriterIface* factory( Interface* );
     
       /** Consturctor
        *
@@ -30,7 +32,7 @@
        * disable this functionality, call one of the other construtors
        * with an empty list of tags.
        */
-    WriteHDF5Parallel( MBInterface* iface );
+    WriteHDF5Parallel( Interface* iface );
      
     
       /** Constructor
@@ -45,7 +47,7 @@
        * NOTE: This list must be identical on all processors, including
        *       the order!
        */
-    WriteHDF5Parallel( MBInterface* iface,
+    WriteHDF5Parallel( Interface* iface,
                        const std::vector<std::string>& multiproc_set_tags );
 
   virtual ~WriteHDF5Parallel();
@@ -92,7 +94,7 @@
        *                          NOTE:  This must be identical on all processors, including
        *                          the order in which tags were added to the object!
        */
-    WriteHDF5Parallel( MBInterface* iface, const MultiProcSetTags& multiproc_set_tags );
+    WriteHDF5Parallel( Interface* iface, const MultiProcSetTags& multiproc_set_tags );
       
     
   
@@ -100,10 +102,10 @@
   
       //! Called by normal (non-parallel) writer.  Sets up
       //! necessary data for parallel write.
-    virtual MBErrorCode parallel_create_file( const char* filename,
+    virtual ErrorCode parallel_create_file( const char* filename,
                                      bool overwrite,
                                      const std::vector<std::string>& qa_records,
-                                     const MBTag* user_tag_list = 0,
+                                     const Tag* user_tag_list = 0,
                                      int user_tag_count = 0,
                                      int dimension = 3,
                                      int pcomm_no = 0);
@@ -111,14 +113,14 @@
       //! Figure out which mesh local mesh is duplicated on
       //! remote processors and which processor will write
       //! that mesh.
-    MBErrorCode gather_interface_meshes();
+    ErrorCode gather_interface_meshes();
     
       //! For entities that will be written by another 
       //! processor but are referenced by entities on this
       //! processor, get the file Ids that will be assigned
       //! to those so they can be referenced by
       //! entities to be written on this processor.
-    MBErrorCode exchange_file_ids();
+    ErrorCode exchange_file_ids();
     
       //! Sort the list of tag information in the parent
       //! class by name so all procs have them in the same
@@ -126,75 +128,75 @@
     void sort_tags_by_name();
     
       //! Create the node table in the file.
-    MBErrorCode create_node_table( int dimension );
+    ErrorCode create_node_table( int dimension );
     
       //! Communicate with other processors to negotiate 
       //! the types of elements that will be written
       //! (the union of the types defined on each proc.)
-    MBErrorCode negotiate_type_list();
+    ErrorCode negotiate_type_list();
     
       //! Create tables to hold element connectivity
-    MBErrorCode create_element_tables();
+    ErrorCode create_element_tables();
     
       //! Create tables to hold element adjacencies.
-    MBErrorCode create_adjacency_tables();
+    ErrorCode create_adjacency_tables();
     
       //! Identify and set up meshsets that span multiple
       //! processors.
       //!\param offsets Output array of three values.
-    MBErrorCode negotiate_shared_meshsets( long* offsets );
+    ErrorCode negotiate_shared_meshsets( long* offsets );
     
       //! Setup meshsets spanning multiple processors
-    MBErrorCode get_remote_set_data( const MultiProcSetTags::Data& tag,
+    ErrorCode get_remote_set_data( const MultiProcSetTags::Data& tag,
                                      RemoteSetData& data,
                                      long& offset );
                                      
       //! Setup interface meshsets spanning multiple processors
-    MBErrorCode get_interface_set_data( RemoteSetData& data, long& offset );
+    ErrorCode get_interface_set_data( RemoteSetData& data, long& offset );
     
       //! Determine offsets in contents and children tables for 
       //! meshsets shared between processors.
-    MBErrorCode negotiate_remote_set_contents( RemoteSetData& data,
+    ErrorCode negotiate_remote_set_contents( RemoteSetData& data,
                                                long* offsets );
     
       //! Create tables for mesh sets
-    MBErrorCode create_meshset_tables();
+    ErrorCode create_meshset_tables();
     
       //! Write tag descriptions and create tables to hold tag data.
-    MBErrorCode create_tag_tables();
+    ErrorCode create_tag_tables();
     
       //! Mark multiple-processor meshsets with correct file Id
       //! from the set description offset stored in that tag by
       //! negotiate_shared_meshsets(..).
-    MBErrorCode set_shared_set_ids( RemoteSetData& data, long& start_id );
+    ErrorCode set_shared_set_ids( RemoteSetData& data, long& start_id );
       
       //! Write set descriptions for multi-processor meshsets.
       //! Virtual function called by non-parallel code after
       //! the normal (single-processor) meshset descriptions have
       //! been written.
-    MBErrorCode write_shared_set_descriptions( hid_t table );
+    ErrorCode write_shared_set_descriptions( hid_t table );
        
       //! Write set contents for multi-processor meshsets.
       //! Virtual function called by non-parallel code after
       //! the normal (single-processor) meshset contents have
       //! been written.
-    MBErrorCode write_shared_set_contents( hid_t table );
+    ErrorCode write_shared_set_contents( hid_t table );
        
       //! Write set children for multi-processor meshsets.
       //! Virtual function called by non-parallel code after
       //! the normal (single-processor) meshset children have
       //! been written.
-    MBErrorCode write_shared_set_children( hid_t table );
+    ErrorCode write_shared_set_children( hid_t table );
        
       //! Write set children for multi-processor meshsets.
       //! Virtual function called by non-parallel code after
       //! the normal (single-processor) meshset children have
       //! been written.
-    MBErrorCode write_shared_set_parents( hid_t table );
+    ErrorCode write_shared_set_parents( hid_t table );
   
       //! Virtual function overridden from WriteHDF5.  
       //! Release memory by clearing member lists.
-    MBErrorCode write_finished();
+    ErrorCode write_finished();
 
     virtual void tprint( const char* fmt, ... )
 #ifdef __GNUC__
@@ -203,27 +205,27 @@
     ;
     
       //! Remove any remote mesh entities from the passed range.
-    void remove_remote_entities( MBEntityHandle relative, MBRange& range );
-    void remove_remote_entities( MBEntityHandle relative, std::vector<MBEntityHandle>& vect );
-    void remove_remote_sets( MBEntityHandle relative, MBRange& range );
-    void remove_remote_sets( MBEntityHandle relative, std::vector<MBEntityHandle>& vect );
+    void remove_remote_entities( EntityHandle relative, Range& range );
+    void remove_remote_entities( EntityHandle relative, std::vector<EntityHandle>& vect );
+    void remove_remote_sets( EntityHandle relative, Range& range );
+    void remove_remote_sets( EntityHandle relative, std::vector<EntityHandle>& vect );
   
     //! get any existing tags which aren't excluded and add to shared set tags
-  MBErrorCode get_sharedset_tags();
+  ErrorCode get_sharedset_tags();
   
   private:
     
       //! An array of interface mesh which is to be written by
       //! remote processors.  Indexed by MPI rank (processor number).
-    std::map<unsigned,MBRange> interfaceMesh;
-    typedef std::map<unsigned,MBRange>::iterator proc_iter;
+    std::map<unsigned,Range> interfaceMesh;
+    typedef std::map<unsigned,Range>::iterator proc_iter;
     
       //! Tag names for identifying multi-processor meshsets
     MultiProcSetTags multiProcSetTags;
     
       //! Struct describing a multi-processor meshset
     struct ParallelSet {
-      MBEntityHandle handle;// set handle on this processor
+      EntityHandle handle;// set handle on this processor
       long contentsOffset;  // offset in table at which to write set contents
       long childrenOffset;  // offset in table at which to write set children
       long parentsOffset;   // offset in table at which to write set parents
@@ -238,18 +240,18 @@
     
       //! Vector indexed by MPI rank, containing the list
       //! of parallel sets that each processor knows about.
-    std::map<unsigned,MBRange> cpuParallelSets;
+    std::map<unsigned,Range> cpuParallelSets;
     
       //! List of parallel sets "owned" by this processor
-    //MBRange myParallelSets;
+    //Range myParallelSets;
 
     //! pcomm controlling parallel nature of mesh
-  MBParallelComm *myPcomm;
+  ParallelComm *myPcomm;
 
     //! whether this instance allocated (and dtor should delete) the pcomm
   bool pcommAllocated;
     
-    void printrange( MBRange& );
+    void printrange( Range& );
 };
 
 
@@ -270,4 +272,6 @@
   bool useFilterValue;
 };
 
+} // namespace moab
+
 #endif

Modified: MOAB/trunk/src/parallel/crystal.c
===================================================================
--- MOAB/trunk/src/parallel/crystal.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/crystal.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -48,7 +48,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
-#include "MBmpi.h"
+#include "moab_mpi.h"
 
 #include "errmem.h"
 #include "types.h"

Modified: MOAB/trunk/src/parallel/fcrystal.c
===================================================================
--- MOAB/trunk/src/parallel/fcrystal.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/fcrystal.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -28,7 +28,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #ifdef MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 
 #include "fname.h"

Modified: MOAB/trunk/src/parallel/gs.c
===================================================================
--- MOAB/trunk/src/parallel/gs.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/gs.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -71,7 +71,7 @@
 #include <string.h>
 #include <math.h>
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 
 #include "errmem.h"     

Deleted: MOAB/trunk/src/parallel/moab/MBParallelComm.hpp
===================================================================
--- MOAB/trunk/src/parallel/moab/MBParallelComm.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/moab/MBParallelComm.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1258 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**
- * \class MBParallelComm
- * \brief Parallel communications in MOAB
- * \author Tim Tautges
- *
- *  This class implements methods to communicate mesh between processors
- *
- */
-
-#ifndef MB_PARALLEL_COMM_HPP
-#define MB_PARALLEL_COMM_HPP
-
-#include "MBForward.hpp"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
-#include "MBProcConfig.hpp"
-#include <map>
-#include <set>
-#include <vector>
-#include <iostream>
-#include <fstream>
-#include <assert.h>
-#include <stdlib.h>
-#include "math.h"
-#include "MBmpi.h"
-
-extern "C" {
-  struct tuple_list;
-}
-
-class TagServer;
-class SequenceManager;
-template <typename KeyType, typename ValType, ValType NullVal> class RangeMap;
-typedef RangeMap<MBEntityHandle, MBEntityHandle, 0> HandleMap;
-
-#define MAX_SHARING_PROCS 64
-
-class MBParallelComm 
-{
-public:
-
-    // ==================================
-    // \section CONSTRUCTORS/DESTRUCTORS/PCOMM MANAGEMENT
-    // ==================================
-
-    //! constructor
-  MBParallelComm(MBInterface *impl,
-                 MPI_Comm comm = MPI_COMM_WORLD,
-                 int* pcomm_id_out = 0);
-
-    //! constructor taking packed buffer, for testing
-  MBParallelComm(MBInterface *impl,
-                 std::vector<unsigned char> &tmp_buff,
-                 MPI_Comm comm = MPI_COMM_WORLD,
-                 int* pcomm_id_out = 0);
-
-    //! Get ID used to reference this PCOMM instance
-  int get_id() const { return pcommID; }
-
-    //! get the indexed pcomm object from the interface
-  static MBParallelComm *get_pcomm(MBInterface *impl, const int index);
-  
-    //! Get MBParallelComm instance associated with partition handle
-    //! Will create MBParallelComm instance if a) one does not already
-    //! exist and b) a valid value for MPI_Comm is passed.
-  static MBParallelComm *get_pcomm( MBInterface* impl, 
-                                    MBEntityHandle partitioning,
-                                    const MPI_Comm* comm = 0 );
-
-  static MBErrorCode get_all_pcomm( MBInterface* impl,
-                                    std::vector<MBParallelComm*>& list );
-
-    //! destructor
-  ~MBParallelComm();
-  
-  static unsigned char PROC_SHARED, PROC_OWNER;
-  
-    // ==================================
-    // \section GLOBAL IDS
-    // ==================================
-
-    //! assign a global id space, for largest-dimension or all entities (and
-    //! in either case for vertices too)
-  MBErrorCode assign_global_ids(MBEntityHandle this_set,
-                                const int dimension,
-                                const int start_id = 1,
-                                const bool largest_dim_only = true,
-                                const bool parallel = true);
-
-    //! check for global ids; based only on tag handle being there or not;
-    //! if it's not there, create them for the specified dimensions
-  MBErrorCode check_global_ids(MBEntityHandle this_set,
-                               const int dimension, 
-                               const int start_id = 1,
-                               const bool largest_dim_only = true,
-                               const bool parallel = true);
-  
-    // ==================================
-    // \section HIGH-LEVEL COMMUNICATION (send/recv/bcast ents, exchange tags)
-    // ==================================
-
-    /** \brief send entities to another processor, optionally waiting until it's done
-     *
-     * Send entities to another processor, with adjs, sets, and tags.  
-     * If store_remote_handles is true, this call receives back handles assigned to
-     * entities sent to destination processor and stores them in sharedh_tag or 
-     * sharedhs_tag.
-     * \param to_proc Destination processor
-     * \param orig_ents Entities requested to send
-     * \param adjs If true, send adjacencies for equiv entities (currently unsupported)
-     * \param tags If true, send tag values for all tags assigned to entities
-     * \param store_remote_handles If true, also recv message with handles on destination processor
-     * \param final_ents Range containing all entities sent
-     * \param wait_all If true, wait until all messages received/sent complete
-     */
-  MBErrorCode send_entities(const int to_proc,
-                            MBRange &orig_ents,
-                            const bool adjs,
-                            const bool tags,
-                            const bool store_remote_handles,
-                            MBRange &final_ents,
-                            bool wait_all = true);
-  
-    /** \brief Receive entities from another processor, optionally waiting until it's done
-     *
-     * Receive entities from another processor, with adjs, sets, and tags.  
-     * If store_remote_handles is true, this call sends back handles assigned to
-     * the entities received.
-     * \param from_proc Source processor
-     * \param store_remote_handles If true, send message with new entity handles to source processor
-     * \param final_ents Range containing all entities received
-     * \param wait_all If true, wait until all messages received/sent complete
-     */
-  MBErrorCode recv_entities(const int from_proc,
-                            const bool store_remote_handles,
-                            MBRange &final_ents,
-                            bool wait_all = true);
-  
-    /** \brief Exchange ghost cells with neighboring procs
-     * Neighboring processors are those sharing an interface 
-     * with this processor.  All entities of dimension ghost_dim
-     * within num_layers of interface, measured going through bridge_dim,
-     * are exchanged.  See MeshTopoUtil::get_bridge_adjacencies for description
-     * of bridge adjacencies.  If wait_all is false and store_remote_handles
-     * is true, MPI_Request objects are available in the sendReqs[2*MAX_SHARING_PROCS] 
-     * member array, with inactive requests marked as MPI_REQUEST_NULL.  If
-     * store_remote_handles or wait_all is false, this function returns after 
-     * all entities have been received and processed.
-     * \param ghost_dim Dimension of ghost entities to be exchanged
-     * \param bridge_dim Dimension of entities used to measure layers from interface
-     * \param num_layers Number of layers of ghosts requested
-     * \param store_remote_handles If true, send message with new entity handles to source processor
-     * \param wait_all If true, function does not return until all send buffers
-     *       are cleared.
-     */
-  MBErrorCode exchange_ghost_cells(int ghost_dim, int bridge_dim, 
-                                   int num_layers,
-                                   bool store_remote_handles,
-                                   bool wait_all = true);
-
-    /** \brief Static version of exchange_ghost_cells, exchanging info through
-     * buffers rather than messages
-     */
-  static MBErrorCode exchange_ghost_cells(MBParallelComm **pc,
-                                          unsigned int num_procs,
-                                          int ghost_dim, int bridge_dim,
-                                          int num_layers,
-                                          bool store_remote_handles);
-  
-    /** \brief Exchange tags for all shared and ghosted entities
-     * This function should be called collectively over the communicator for this MBParallelComm.
-     * If this version is called, all ghosted/shared entities should have a value for this
-     * tag (or the tag should have a default value).
-     * \param tags Vector of tag handles to be exchanged
-     */
-  MBErrorCode exchange_tags(std::vector<MBTag> &src_tags,
-                            std::vector<MBTag> &dst_tags,
-                            MBRange &entities);
-  
-    /** \brief Exchange tags for all shared and ghosted entities
-     * This function should be called collectively over the communicator for this MBParallelComm
-     * \param tag_name Name of tag to be exchanged
-     */
-  MBErrorCode exchange_tags(const char *tag_name,
-                            MBRange &entities);
-  
-    /** \brief Exchange tags for all shared and ghosted entities
-     * This function should be called collectively over the communicator for this MBParallelComm
-     * \param tagh Handle of tag to be exchanged
-     */
-  MBErrorCode exchange_tags(MBTag tagh,
-                            MBRange &entities);
-  
-    /** \brief Broadcast all entities resident on from_proc to other processors
-     * This function assumes remote handles are *not* being stored, since (usually)
-     * every processor will know about the whole mesh.
-     * \param from_proc Processor having the mesh to be broadcast
-     * \param entities On return, the entities sent or received in this call
-     * \param adjacencies If true, adjacencies are sent for equiv entities (currently unsupported)
-     * \param tags If true, all non-default-valued tags are sent for sent entities
-     */
-  MBErrorCode broadcast_entities(const int from_proc,
-                                 MBRange& entities,
-                                 const bool adjacencies = false,
-                                 const bool tags = true );
-
-    // ==================================
-    // \section INITIALIZATION OF PARALLEL DATA (resolve_shared_ents, etc.)
-    // ==================================
-
-    /** \brief Resolve shared entities between processors
-     *
-     * Resolve shared entities between processors for entities in proc_ents,
-     * by comparing global id tag values on vertices on skin of elements in
-     * proc_ents.  Shared entities are assigned a tag that's either
-     * PARALLEL_SHARED_PROC_TAG_NAME, which is 1 integer in length, or 
-     * PARALLEL_SHARED_PROCS_TAG_NAME, whose length depends on the maximum
-     * number of sharing processors.  Values in these tags denote the ranks
-     * of sharing processors, and the list ends with the value -1.
-     *
-     * If shared_dim is input as -1 or not input, a value one less than the
-     * maximum dimension of entities in proc_ents is used.
-     *
-     * \param proc_ents Entities for which to resolve shared entities
-     * \param shared_dim Maximum dimension of shared entities to look for
-     */
-  MBErrorCode resolve_shared_ents(MBEntityHandle this_set,
-                                  MBRange &proc_ents, 
-                                  int resolve_dim = -1,
-                                  int shared_dim = -1,
-                                  const MBTag* id_tag = 0);
-  
-    /** \brief Resolve shared entities between processors
-     *
-     * Same as resolve_shared_ents(MBRange&), except works for
-     * all entities in instance of dimension dim.  
-     *
-     * If shared_dim is input as -1 or not input, a value one less than the
-     * maximum dimension of entities is used.
-
-     * \param dim Dimension of entities in the partition
-     * \param shared_dim Maximum dimension of shared entities to look for
-     */
-  MBErrorCode resolve_shared_ents(MBEntityHandle this_set,
-                                  int resolve_dim = 3, 
-                                  int shared_dim = -1,
-                                  const MBTag* id_tag = 0);
-    
-  static MBErrorCode resolve_shared_ents(MBParallelComm **pc, 
-                                         const unsigned int np, 
-                                         const int to_dim);
-  
-    // ==================================
-    // \section GET PARALLEL DATA (shared/owned/iface entities, etc.)
-    // ==================================
-
-    /** \brief Get entities with the given pstatus bit(s) set
-     * Returns any entities whose pstatus tag value v satisfies (v & pstatus_val)
-     *
-     * \param dim Dimension of entities to be returned, or -1 if any
-     * \param pstatus_val pstatus value of desired entities
-     * \param pstatus_ents Entities returned from function
-     */
-  MBErrorCode get_pstatus_entities(int dim,
-                                   unsigned char pstatus_val,
-                                   MBRange &pstatus_ents);
-  
-    /** \brief Return the rank of the entity owner
-     */
-  MBErrorCode get_owner(MBEntityHandle entity,
-                        int &owner);
-  
-    /** \brief Return the owner processor and handle of a given entity
-     */
-  MBErrorCode get_owner_handle(MBEntityHandle entity,
-                               int &owner,
-                               MBEntityHandle &handle);
-
-    /** \brief Get the shared processors/handles for an entity
-     * Get the shared processors/handles for an entity.  Arrays must
-     * be large enough to receive data for all sharing procs.
-     * \param entity Entity being queried
-     * \param ps Pointer to sharing proc data
-     * \param hs Pointer to shared proc handle data
-     * \param pstat Reference to pstatus data returned from this function
-     */
-  MBErrorCode get_sharing_data(const MBEntityHandle entity,
-                               int *ps, 
-                               MBEntityHandle *hs,
-                               unsigned char &pstat,
-                               unsigned int &num_ps);
-
-    /** \brief Get the shared processors/handles for an entity
-     * Same as other version but with int num_ps
-     * \param entity Entity being queried
-     * \param ps Pointer to sharing proc data
-     * \param hs Pointer to shared proc handle data
-     * \param pstat Reference to pstatus data returned from this function
-     */
-  MBErrorCode get_sharing_data(const MBEntityHandle entity,
-                               int *ps, 
-                               MBEntityHandle *hs,
-                               unsigned char &pstat,
-                               int &num_ps);
-
-    /** \brief Get the intersection or union of all sharing processors
-     * Get the intersection or union of all sharing processors.  Processor set
-     * is cleared as part of this function.
-     * \param entities Entity list ptr
-     * \param num_entities Number of entities
-     * \param procs Processors returned
-     * \param op Either MBInterface::UNION or MBInterface::INTERSECT
-     */
-  MBErrorCode get_sharing_data(const MBEntityHandle *entities,
-                               int num_entities,
-                               std::set<int> &procs,
-                               int op = MBInterface::INTERSECT);
-  
-    /** \brief Get the intersection or union of all sharing processors
-     * Same as previous variant but with range as input
-     */
-  MBErrorCode get_sharing_data(const MBRange &entities,
-                               std::set<int> &procs,
-                               int op = MBInterface::INTERSECT);
-  
-    /** \brief Get entities on an inter-processor interface and of specified dimension
-     * If other_proc is -1, any interface entities are returned.  If dim is -1,
-     * entities of all dimensions on interface are returned.
-     * \param other_proc Rank of processor for which interface entities are requested
-     * \param shared_ents Entities returned from function
-     * \param dim Dimension of interface entities requested
-     * \param iface If true, return only entities on the interface
-     */
-  MBErrorCode get_shared_entities(int other_proc,
-                                  MBRange &shared_ents,
-                                  int dim = -1,
-                                  const bool iface = false,
-                                  const bool owned_filter = false);
-/*  
-    //! return partition sets; if tag_name is input, gets sets with
-    //! that tag name, otherwise uses PARALLEL_PARTITION tag
-  MBErrorCode get_partition_sets(MBEntityHandle this_set,
-                                 MBRange &part_sets,
-                                 const char *tag_name = NULL);
-*/
-    //! get processors with which this processor shares an interface
-  MBErrorCode get_interface_procs(std::set<unsigned int> &iface_procs,
-                                  const bool get_buffs = false);
-
-    //! get processors with which this processor communicates
-  MBErrorCode get_comm_procs(std::set<unsigned int> &procs);
-  
-    // ==================================
-    // \section LOW-LEVEL DATA (tags, sets on interface/partition, etc.)
-    // ==================================
-
-    //! Get proc config for this communication object
-  const MBProcConfig &proc_config() const {return procConfig;}
-  
-    //! Get proc config for this communication object
-  MBProcConfig &proc_config() {return procConfig;}
-  
-  unsigned rank() const { return proc_config().proc_rank(); }
-  unsigned size() const { return proc_config().proc_size(); }
-  MPI_Comm comm() const { return proc_config().proc_comm(); }
-  
-    //! return the tags used to indicate shared procs and handles
-  MBErrorCode get_shared_proc_tags(MBTag &sharedp_tag,
-                                   MBTag &sharedps_tag,
-                                   MBTag &sharedh_tag,
-                                   MBTag &sharedhs_tag,
-                                   MBTag &pstatus_tag);
-
-    //! return partition, interface set ranges
-  MBRange &partition_sets() {return partitionSets;}
-  const MBRange &partition_sets() const {return partitionSets;}
-  MBRange &interface_sets() {return interfaceSets;}
-  const MBRange &interface_sets() const {return interfaceSets;}
-      
-    //! return sharedp tag
-  MBTag sharedp_tag();
-  
-    //! return sharedps tag
-  MBTag sharedps_tag();
-  
-    //! return sharedh tag
-  MBTag sharedh_tag();
-  
-    //! return sharedhs tag
-  MBTag sharedhs_tag();
-  
-    //! return pstatus tag
-  MBTag pstatus_tag();
-
-    //! return pcomm tag; static because might not have a pcomm before going
-    //! to look for one on the interface
-  static MBTag pcomm_tag(MBInterface *impl,
-                         bool create_if_missing = true);
-  
-    //! return partitions set tag
-  MBTag partition_tag();
-  MBTag part_tag() { return partition_tag(); }
-
-    // ==================================
-    // \section IMESHP-RELATED FUNCTIONS
-    // ==================================
-
-    //! return all the entities in parts owned locally
-  MBErrorCode get_part_entities(MBRange &ents, int dim = -1);
-  
-  MBEntityHandle get_partitioning() const { return partitioningSet; }
-  MBErrorCode set_partitioning( MBEntityHandle h );
-  MBErrorCode get_global_part_count( int& count_out ) const;
-  MBErrorCode get_part_owner( int part_id, int& owner_out ) const;
-  MBErrorCode get_part_id( MBEntityHandle part, int& id_out ) const;
-  MBErrorCode get_part_handle( int id, MBEntityHandle& handle_out ) const;
-  MBErrorCode create_part( MBEntityHandle& part_out );
-  MBErrorCode destroy_part( MBEntityHandle part ) ;
-  MBErrorCode collective_sync_partition();
-  MBErrorCode get_part_neighbor_ids( MBEntityHandle part, 
-                                     int neighbors_out[MAX_SHARING_PROCS],
-                                     int& num_neighbors_out );
-  MBErrorCode get_interface_sets( MBEntityHandle part, 
-                                  MBRange& iface_sets_out,
-                                  int* adj_part_id = 0 );
-  MBErrorCode get_owning_part( MBEntityHandle entity, 
-                               int& owning_part_id_out,
-                               MBEntityHandle* owning_handle = 0 );
-  MBErrorCode get_sharing_parts( MBEntityHandle entity,
-                                 int part_ids_out[MAX_SHARING_PROCS],
-                                 int& num_part_ids_out,
-                                 MBEntityHandle remote_handles[MAX_SHARING_PROCS] = 0);
-  
-    // Propogate mesh modification amongst shared entities
-    // from the onwing processor to any procs with copies.
-  MBErrorCode update_shared_mesh();
-
-    /** Filter the entities by pstatus tag.  
-     * op is one of PSTATUS_ AND, OR, NOT; an entity is output if:
-     * AND: all bits set in pstatus_val are also set on entity
-     * OR: any bits set in pstatus_val also set on entity
-     * NOT: any bits set in pstatus_val are not set on entity
-     *
-     * Results returned in input list, unless result_ents is passed in non-null,
-     * in which case results are returned in result_ents.
-     *
-     * If ents is passed in empty, filter is done on shared entities in this
-     * pcomm instance, i.e. contents of sharedEnts.
-     *
-     *\param ents       Input entities to filter
-     *\param pstatus_val pstatus value to which entities are compared
-     *\param op Bitwise operation performed between pstatus values
-     *\param to_proc If non-negative and PSTATUS_SHARED is set on pstatus_val,
-     *               only entities shared with to_proc are returned
-     *\param result_ents If non-null, results of filter are put in the 
-     *       pointed-to range
-     */
-  MBErrorCode filter_pstatus( MBRange &ents,
-                              const unsigned char pstatus_val,
-                              const unsigned char op,
-                              int to_proc = -1,
-                              MBRange *returned_ents = NULL);
-
-    /** \brief Get entities on interfaces shared with another proc
-     *
-     * \param other_proc Other proc sharing the interface
-     * \param dim Dimension of entities to return, -1 if all dims
-     * \param iface_ents Returned entities
-     */
-  MBErrorCode get_iface_entities(int other_proc,
-                                 int dim,
-                                 MBRange &iface_ents);
-  
-  MBInterface* get_moab() const { return mbImpl; }
-
-  class Buffer {
-  public:
-    unsigned char *mem_ptr;
-    unsigned char *buff_ptr;
-    unsigned int alloc_size;
-    
-    Buffer(unsigned int sz = 0);
-    Buffer(const Buffer &);
-    ~Buffer();
-    void reset_buffer(size_t buff_pos = 0) {reset_ptr(buff_pos); reserve(INITIAL_BUFF_SIZE);}
-    void reset_ptr(size_t buff_pos = 0) {assert((!mem_ptr && !buff_pos)|| (alloc_size >= buff_pos)); buff_ptr = mem_ptr + buff_pos;}
-    void reserve(unsigned int new_size);
-    void set_stored_size() {*((int*)mem_ptr) = (int)(buff_ptr - mem_ptr);}
-    int get_stored_size() {return *((int*)mem_ptr);}
-          
-    void check_space(unsigned int addl_space);
-  };
-
-    //! public 'cuz we want to unit test these externally
-  MBErrorCode pack_buffer(MBRange &orig_ents, 
-                          const bool adjacencies,
-                          const bool tags,
-                          const bool store_remote_handles,
-                          const int to_proc,
-                          Buffer *buff);
-  
-  MBErrorCode unpack_buffer(unsigned char *buff_ptr,
-                            const bool store_remote_handles,
-                            const int from_proc,
-                            const int ind,
-                            std::vector<std::vector<MBEntityHandle> > &L1hloc,
-                            std::vector<std::vector<MBEntityHandle> > &L1hrem,
-                            std::vector<std::vector<int> > &L1p,
-                            std::vector<MBEntityHandle> &L2hloc, 
-                            std::vector<MBEntityHandle> &L2hrem,
-                            std::vector<unsigned int> &L2p,
-                            MBRange &new_ents);
-  
-  MBErrorCode pack_entities(MBRange &entities,
-                            Buffer *buff,
-                            const bool store_remote_handles,
-                            const int to_proc,
-                            const bool is_iface,
-                            std::vector<std::set<unsigned int> > *entprocs = NULL,
-                            MBRange *allsent = NULL);
-
-    //! unpack entities in buff_ptr
-  MBErrorCode unpack_entities(unsigned char *&buff_ptr,
-                              const bool store_remote_handles,
-                              const int from_ind,
-                              const bool is_iface,
-                              std::vector<std::vector<MBEntityHandle> > &L1hloc,
-                              std::vector<std::vector<MBEntityHandle> > &L1hrem,
-                              std::vector<std::vector<int> > &L1p,
-                              std::vector<MBEntityHandle> &L2hloc, 
-                              std::vector<MBEntityHandle> &L2hrem,
-                              std::vector<unsigned int> &L2p,
-                              MBRange &new_ents);
-  
-    //! Call exchange_all_shared_handles, then compare the results with tag data
-    //! on local shared entities.
-  MBErrorCode check_all_shared_handles();
-
-  static MBErrorCode check_all_shared_handles(MBParallelComm **pcs,
-                                              int num_pcs);
-  
-  struct SharedEntityData {
-    MBEntityHandle local;
-    MBEntityHandle remote;
-    int owner;
-  };
-
-  MBErrorCode pack_shared_handles(
-      std::vector<std::vector<SharedEntityData> > &send_data);
-
-    // check consistency of sharedEnts against their tags and their
-    // vertices' tags
-  MBErrorCode check_local_shared();
-  
-    // check contents of communicated shared entity data against tags
-  MBErrorCode check_my_shared_handles(
-      std::vector<std::vector<SharedEntityData> > &shents,
-                                      const char *prefix = NULL);
-  
-    //! set rank for this pcomm; USED FOR TESTING ONLY!
-  void set_rank(unsigned int r);
-  
-    //! set rank for this pcomm; USED FOR TESTING ONLY!
-  void set_size(unsigned int r);
-  
-    //! get (and possibly allocate) buffers for messages to/from to_proc; returns
-    //! index of to_proc in buffProcs vector; if is_new is non-NULL, sets to
-    //! whether new buffer was allocated
-    //! PUBLIC ONLY FOR TESTING!
-  int get_buffers(int to_proc, bool *is_new = NULL);
-
-    /* \brief Unpack message with remote handles
-     * PUBLIC ONLY FOR TESTING!
-     */
-  MBErrorCode unpack_remote_handles(unsigned int from_proc,
-                                    unsigned char *&buff_ptr,
-                                    std::vector<MBEntityHandle> &L2hloc,
-                                    std::vector<MBEntityHandle> &L2hrem,
-                                    std::vector<unsigned int> &L2p);
-  
-    /* \brief Pack message with remote handles
-     * PUBLIC ONLY FOR TESTING!
-     */
-  MBErrorCode pack_remote_handles(std::vector<MBEntityHandle> &L1hloc,
-                                  std::vector<MBEntityHandle> &L1hrem,
-                                  std::vector<int> &procs,
-                                  unsigned int to_proc,
-                                  Buffer *buff);
-  
-  MBErrorCode list_entities(const MBEntityHandle *ents, int num_ents);
-  
-  MBErrorCode list_entities(const MBRange &ents);
-  
-  static const unsigned int INITIAL_BUFF_SIZE;
-
-private:
-
-    // common initialization code, called from various constructors
-  void initialize();
-  
-  MBErrorCode set_sharing_data(MBEntityHandle ent, unsigned char pstatus,
-                               int old_nump, int new_nump,
-                               int *ps, MBEntityHandle *hs);
-  
-  MBErrorCode check_clean_iface(MBRange &allsent);
-  
-  void define_mpe();
-
-  MBErrorCode get_sent_ents(const bool is_iface,
-                            const int bridge_dim, const int ghost_dim,
-                            const int num_layers,
-                            MBRange *sent_ents, MBRange &allsent,
-                            std::vector<std::set<unsigned int> > &entprocs);
-  
-    /** \brief Set pstatus values on entities
-     *
-     * \param pstatus_ents Entities to be set
-     * \param pstatus_val Pstatus value to be set
-     * \param lower_dim_ents If true, lower-dimensional ents (incl. vertices) set too
-     *        (and created if they don't exist)
-     * \param verts_too If true, vertices also set
-     * \param operation If UNION, pstatus_val is OR-d with existing value, otherwise
-     *        existing value is over-written
-     */
-  MBErrorCode set_pstatus_entities(MBRange &pstatus_ents,
-                                   unsigned char pstatus_val,
-                                   bool lower_dim_ents = false,
-                                   bool verts_too = true,
-                                   int operation = MBInterface::UNION);
-
-    /** \brief Set pstatus values on entities (vector-based function)
-     *
-     * \param pstatus_ents Entities to be set
-     * \param pstatus_val Pstatus value to be set
-     * \param lower_dim_ents If true, lower-dimensional ents (incl. vertices) set too
-     *        (and created if they don't exist)
-     * \param verts_too If true, vertices also set
-     * \param operation If UNION, pstatus_val is OR-d with existing value, otherwise
-     *        existing value is over-written
-     */
-  MBErrorCode set_pstatus_entities(MBEntityHandle *pstatus_ents,
-                                   int num_ents,
-                                   unsigned char pstatus_val,
-                                   bool lower_dim_ents = false,
-                                   bool verts_too = true,
-                                   int operation = MBInterface::UNION);
-
-  int num_subranges(const MBRange &this_range);
-
-    //! estimate size required to pack entities
-  int estimate_ents_buffer_size(MBRange &entities,
-                                const bool store_remote_handles);
-  
-    //! estimate size required to pack sets
-  int estimate_sets_buffer_size(MBRange &entities,
-                                const bool store_remote_handles);
-  
-    //! send the indicated buffer, possibly sending size first
-  MBErrorCode send_buffer(const unsigned int to_proc,
-                          Buffer *send_buff,
-                          const int msg_tag,
-                          MPI_Request &send_req,
-                          MPI_Request &ack_recv_req,
-                          int *ack_buff,
-                          int &this_incoming,
-                          int next_mesg_tag = -1,
-                          Buffer *next_recv_buff = NULL,
-                          MPI_Request *next_recv_req = NULL,
-                          int *next_incoming = NULL);
-  
-    //! process incoming message; if longer than the initial size, post
-    //! recv for next part then send ack; if ack, send second part; else
-    //! indicate that we're done and buffer is ready for processing
-  MBErrorCode recv_buffer(int mesg_tag_expected,
-                          const MPI_Status &mpi_status,
-                          Buffer *recv_buff,
-                          MPI_Request &recv_2nd_req,
-                          MPI_Request &ack_req,
-                          int &this_incoming,
-                          Buffer *send_buff,
-                          MPI_Request &send_req,
-                          MPI_Request &sent_ack_req,
-                          bool &done,
-                          Buffer *next_buff = NULL,
-                          int next_tag = -1,
-                          MPI_Request *next_req = NULL,
-                          int *next_incoming = NULL);
-  
-    //! pack a range of entities with equal # verts per entity, along with
-    //! the range on the sending proc
-  MBErrorCode pack_entity_seq(const int nodes_per_entity,
-                              const bool store_remote_handles,
-                              const int to_proc,
-                              MBRange &these_ents,
-                              MBRange &entities,
-                              Buffer *buff);
-  
-  MBErrorCode print_buffer(unsigned char *buff_ptr, int mesg_type, int from_proc,
-                           bool sent);
-  
-    //! for all the entities in the received buffer; for each, save
-    //! entities in this instance which match connectivity, or zero if none found
-  MBErrorCode unpack_iface_entities(unsigned char *&buff_ptr, 
-                                    const int from_proc,
-                                    const int ind,
-                                    std::vector<MBEntityHandle> &recd_ents);
-  
-  MBErrorCode pack_sets(MBRange &entities,
-                        Buffer *buff,
-                        const bool store_handles,
-                        const int to_proc);
-  
-  MBErrorCode unpack_sets(unsigned char *&buff_ptr,
-                          MBRange &entities,
-                          const bool store_handles,
-                          const int to_proc);
-  
-  MBErrorCode pack_adjacencies(MBRange &entities,
-                               MBRange::const_iterator &start_rit,
-                               MBRange &whole_range,
-                               unsigned char *&buff_ptr,
-                               int &count,
-                               const bool just_count,
-                               const bool store_handles,
-                               const int to_proc);
-
-  MBErrorCode unpack_adjacencies(unsigned char *&buff_ptr,
-                                 MBRange &entities,
-                                 const bool store_handles,
-                                 const int from_proc);
-  
-
-    /* \brief Unpack message with remote handles (const pointer to buffer)
-     */
-  MBErrorCode unpack_remote_handles(unsigned int from_proc,
-                                    const unsigned char *buff_ptr,
-                                    std::vector<MBEntityHandle> &L2hloc,
-                                    std::vector<MBEntityHandle> &L2hrem,
-                                    std::vector<unsigned int> &L2p);
-  
-    //! given connectivity and type, find an existing entity, if there is one
-  MBErrorCode find_existing_entity(const bool is_iface,
-                                   const int owner_p,
-                                   const MBEntityHandle owner_h,
-                                   const int num_ents,
-                                   const MBEntityHandle *connect,
-                                   const int num_connect,
-                                   const MBEntityType this_type,
-                                   std::vector<MBEntityHandle> &L2hloc,
-                                   std::vector<MBEntityHandle> &L2hrem,
-                                   std::vector<unsigned int> &L2p,
-                                   MBEntityHandle &new_h);
-  
-  MBErrorCode build_sharedhps_list(const MBEntityHandle entity,
-                                   const unsigned char pstatus,
-                                   const int sharedp, 
-                                   const std::set<unsigned int> &entprocs,
-                                   unsigned int &num_ents,
-                                   int *tmp_procs,
-                                   MBEntityHandle *tmp_handles);
-  
-  /**\brief Get list of tags for which to exchange data
-   *
-   * Get tags and entities for which to exchange tag data.  This function
-   * was originally part of 'pack_tags' requested with the 
-   * 'all_possible_tags' parameter.
-   *
-   *\param all_entities  Input.  The set of entities for which data is to 
-   *                      be communicated.
-   *\param all_tags      Output.  Populated with the handles of tags to be
-   *                      sent.
-   *\param tag_ranges    Output.  For each corresponding tag in all_tags, the
-   *                      subset of 'all_entities' for which a tag value has
-   *                      been set.
-   */
-  MBErrorCode get_tag_send_list( const MBRange& all_entities,
-                                 std::vector<MBTag>& all_tags,
-                                 std::vector<MBRange>& tag_ranges );
-
-  /**\brief Serialize entity tag data
-   *
-   * This function operates in two passes.  The first phase,
-   * specified by 'just_count == true' calculates the necesary
-   * buffer size for the serialized data.  The second phase
-   * writes the actual binary serialized representation of the
-   * data to the passed buffer.
-   *
-   *\NOTE First two arguments are not used.  (Legacy interface?)
-   *
-   *\param entities      NOT USED
-   *\param start_rit     NOT USED
-   *\param whole_range   Should be the union of the sets of entities for 
-   *                     which tag values are to be serialized.  Also
-   *                     specifies ordering for indexes for tag values and
-   *                     serves as the superset from which to compose entity
-   *                     lists from individual tags if just_count and
-   *                     all_possible_tags are both true.
-   *\param buff_ptr      Buffer into which to write binary serailzed data
-   *\param count         Output:  The size of the serialized data is added
-   *                     to this parameter.  NOTE: Should probalby initialize
-   *                     to zero before calling.
-   *\param just_count    If true, just calculate the buffer size required to
-   *                     hold the serialized data.  Will also append to
-   *                     'all_tags' and 'tag_ranges' if all_possible_tags
-   *                     == true.
-   *\param store_handles The data for each tag is preceeded by a list of 
-   *                     MBEntityHandles designating the entity each of
-   *                     the subsequent tag values corresponds to.  This value
-   *                     may be one of:
-   *                     1) If store_handles == false:
-   *                        An invalid handle composed of {MBMAXTYE,idx}, where
-   *                        idx is the position of the entity in "whole_range".
-   *                     2) If store_hanldes == true and a valid remote
-   *                        handle exists, the remote handle.
-   *                     3) If store_hanldes == true and no valid remote 
-   *                        handle is defined for the entity, the same as 1).
-   *\param to_proc       If 'store_handles' is true, the processor rank for
-   *                     which to store the corresponding remote entity 
-   *                     handles.
-   *\param all_tags      List of tags to write
-   *\param tag_ranges    List of entities to serialize tag data, one
-   *                            for each corresponding tag handle in 'all_tags.
-   */
-  MBErrorCode pack_tags(MBRange &entities,
-                        const std::vector<MBTag> &src_tags,
-                        const std::vector<MBTag> &dst_tags,
-                        const std::vector<MBRange> &tag_ranges,
-                        Buffer *buff,
-                        const bool store_handles,
-                        const int to_proc);
-
-    /**\brief Calculate buffer size required to packtag data
-     *\param source_tag The tag for which data will be serialized
-     *\param entites    The entities for which tag values will be serialized
-     *\param count_out  Output: The required buffer size, in bytes.
-     */
-  MBErrorCode packed_tag_size( MBTag source_tag, 
-                               const MBRange& entities, 
-                               int& count_out );
-  
-  /**\brief Serialize tag data
-   *\param source_tag    The tag for which data will be serialized
-   *\param destination_tag Tag in which to store unpacked tag data.  Typically
-   *                     the same as source_tag.
-   *\param entites       The entities for which tag values will be serialized
-   *\param whole_range   Calculate entity indices as location in this range
-   *\param buff_ptr      Input/Output: As input, pointer to the start of the
-   *                     buffer in which to serialize data.  As output, the
-   *                     position just passed the serialized data.
-   *\param count_out     Output: The required buffer size, in bytes.
-   *\param store_handles The data for each tag is preceeded by a list of 
-   *                     MBEntityHandles designating the entity each of
-   *                     the subsequent tag values corresponds to.  This value
-   *                     may be one of:
-   *                     1) If store_handles == false:
-   *                        An invalid handle composed of {MBMAXTYE,idx}, where
-   *                        idx is the position of the entity in "whole_range".
-   *                     2) If store_hanldes == true and a valid remote
-   *                        handle exists, the remote handle.
-   *                     3) If store_hanldes == true and no valid remote 
-   *                        handle is defined for the entity, the same as 1).
-   *\param to_proc       If 'store_handles' is true, the processor rank for
-   *                     which to store the corresponding remote entity 
-   *                     handles.
-   */
-  MBErrorCode pack_tag( MBTag source_tag,
-                        MBTag destination_tag,
-                        const MBRange &entities,
-                        const MBRange &whole_range,
-                        Buffer *buff,
-                        const bool store_remote_handles,
-                        const int to_proc );
-
-  MBErrorCode unpack_tags(unsigned char *&buff_ptr,
-                          MBRange &entities,
-                          const bool store_handles,
-                          const int to_proc);
-  
-  MBErrorCode tag_shared_verts(tuple_list &shared_verts,
-                               MBRange *skin_ents,
-                               std::map<std::vector<int>, MBRange> &proc_nranges,
-                               MBRange &proc_verts);
-  
-  MBErrorCode tag_shared_ents(int resolve_dim,
-                              int shared_dim,
-                              MBRange *skin_ents,
-                              std::map<std::vector<int>, MBRange> &proc_nranges);
-
-    // each iterate in proc_nranges contains a set of procs and the entities *possibly*
-    // on the interface between those procs; this function makes sets for each,
-    // and tags the set with the procs sharing it; interface sets are optionally
-    // returned; NOTE: a subsequent step is used to verify entities on the interface
-    // and remove them if they're not shared
-  MBErrorCode create_interface_sets(std::map<std::vector<int>, MBRange> &proc_nranges,
-                                    int resolve_dim, int shared_dim);
-
-    // do the same but working straight from sharedEnts
-  MBErrorCode create_interface_sets(int resolve_dim, int shared_dim);
-
-    // after verifying shared entities, now parent/child links between sets can be established
-  MBErrorCode create_iface_pc_links();
-  
-    //! pack a range map with keys in this_range and values a contiguous series
-    //! of handles starting at actual_start
-  MBErrorCode pack_range_map(MBRange &this_range, MBEntityHandle actual_start,
-                             HandleMap &handle_map);
-
-    //! returns true if the set is an interface shared with to_proc
-  bool is_iface_proc(MBEntityHandle this_set, int to_proc);
-  
-    //! for any remote_handles set to zero, remove corresponding sent_ents from
-    //! iface_sets corresponding to from_proc
-  MBErrorCode update_iface_sets(MBRange &sent_ents,
-                                std::vector<MBEntityHandle> &remote_handles, 
-                                int from_proc);
-  
-    //! for specified bridge/ghost dimension, to_proc, and number
-    //! of layers, get the entities to be ghosted, and info on additional procs
-    //! needing to communicate with to_proc
-  MBErrorCode get_ghosted_entities(int bridge_dim,
-                                   int ghost_dim,
-                                   int to_proc, 
-                                   int num_layers,
-                                   MBRange &ghosted_ents);
-  
-    //! add vertices adjacent to entities in this list
-  MBErrorCode add_verts(MBRange &sent_ents);
-  
-  //! Every processor sends shared entity handle data to every other processor
-  //! that it shares entities with.  Passed back map is all received data,
-  //! indexed by processor ID. This function is intended to be used for 
-  //! debugging.
-  MBErrorCode exchange_all_shared_handles(  
-      std::vector<std::vector<SharedEntityData> > &send_data, 
-      std::vector<std::vector<SharedEntityData> > &result);
-  
-    //! replace handles in from_vec with corresponding handles on
-    //! to_proc (by checking shared[p/h]_tag and shared[p/h]s_tag;
-    //! if no remote handle and new_ents is non-null, substitute
-    //! instead CREATE_HANDLE(MBMAXTYPE, index) where index is handle's
-    //! position in new_ents
-  MBErrorCode get_remote_handles(const bool store_remote_handles,
-                                 MBEntityHandle *from_vec, 
-                                 MBEntityHandle *to_vec_tmp,
-                                 int num_ents, int to_proc,
-                                 const MBRange &new_ents);
-  
-    //! same as other version, except from_range and to_range should be
-    //! different here
-  MBErrorCode get_remote_handles(const bool store_remote_handles,
-                                 const MBRange &from_range, 
-                                 MBRange &to_range,
-                                 int to_proc,
-                                 const MBRange &new_ents);
-  
-    //! same as other version, except packs range into vector
-  MBErrorCode get_remote_handles(const bool store_remote_handles,
-                                 const MBRange &from_range, 
-                                 MBEntityHandle *to_vec,
-                                 int to_proc,
-                                 const MBRange &new_ents);
-
-  std::vector<unsigned int> &buff_procs();
-
-    //! goes through from_vec, and for any with type MBMAXTYPE, replaces with
-    //! new_ents value at index corresponding to id of entity in from_vec
-  MBErrorCode get_local_handles(MBEntityHandle *from_vec, 
-                                int num_ents,
-                                const MBRange &new_ents);
-
-    //! same as above except puts results in range
-  MBErrorCode get_local_handles(const MBRange &remote_handles,
-                                MBRange &local_handles,
-                                const MBRange &new_ents);
-  
-    //! same as above except gets new_ents from vector
-  MBErrorCode get_local_handles(MBEntityHandle *from_vec,
-                                int num_ents,
-                                const std::vector<MBEntityHandle> &new_ents);
-  
-  MBErrorCode update_remote_data(MBRange &local_range,
-                                 MBRange &remote_range,
-                                 int other_proc,
-                                 const unsigned char add_pstat);
-  
-  MBErrorCode update_remote_data(const MBEntityHandle new_h,
-                                 const int *ps,
-                                 const MBEntityHandle *hs,
-                                 const int num_ps,
-                                 const unsigned char add_pstat);
-  
-    /** \brief Set pstatus tag interface bit on entities in sets passed in
-     */
-  MBErrorCode tag_iface_entities();
-
-    //! add a pc to the iface instance tag PARALLEL_COMM
-  int add_pcomm(MBParallelComm *pc);
-  
-    //! remove a pc from the iface instance tag PARALLEL_COMM
-  void remove_pcomm(MBParallelComm *pc);
-  
-    //! check entities to make sure there are no zero-valued remote handles
-    //! where they shouldn't be
-  MBErrorCode check_sent_ents(MBRange &allsent);
-
-    //! MB interface associated with this writer
-  MBInterface *mbImpl;
-
-    //! Proc config object, keeps info on parallel stuff
-  MBProcConfig procConfig;
-  
-    //! Tag server, so we can get more info about tags
-  TagServer *tagServer;
-  
-    //! Sequence manager, to get more efficient access to entities
-  SequenceManager *sequenceManager;
-  
-    //! more data buffers, proc-specific
-  std::vector<Buffer*> localOwnedBuffs, remoteOwnedBuffs;
-
-    //! reset message buffers to their initial state
-  void reset_all_buffers();
-
-    //! delete all buffers, freeing up any memory held by them
-  void delete_all_buffers();
-
-    //! request objects, may be used if store_remote_handles is used
-  std::vector<MPI_Request> sendReqs;
-
-    //! processor rank for each buffer index
-  std::vector<unsigned int> buffProcs;
-
-    //! the partition, interface sets for this comm'n instance
-  MBRange partitionSets, interfaceSets;
-
-    //! all local entities shared with others, whether ghost or ghosted
-  MBRange sharedEnts;
-  
-    //! tags used to save sharing procs and handles
-  MBTag sharedpTag, sharedpsTag, sharedhTag, sharedhsTag, pstatusTag, 
-      ifaceSetsTag, partitionTag;
-    
-  int globalPartCount; //!< Cache of global part count
-  
-  MBEntityHandle partitioningSet; //!< entity set containing all parts
-
-  std::ofstream myFile;
-  
-  int pcommID;
-
-};
-
-inline MBParallelComm::Buffer::Buffer(const Buffer &other_buff) 
-{
-  alloc_size = other_buff.alloc_size;
-  mem_ptr = (unsigned char *)malloc(alloc_size);
-  memcpy(mem_ptr, other_buff.mem_ptr, alloc_size);
-  buff_ptr = mem_ptr + (other_buff.buff_ptr - other_buff.mem_ptr);
-}
-
-inline MBParallelComm::Buffer::Buffer(unsigned int new_size) 
-        : mem_ptr(NULL), buff_ptr(NULL), alloc_size(0)
-{
-  if (new_size) this->reserve(new_size);
-}
-
-inline MBParallelComm::Buffer::~Buffer() 
-{
-  if (mem_ptr) {
-    free(mem_ptr);
-    mem_ptr = NULL;
-  }
-}
-
-#define DEBUG_BUFFER 1
-
-inline void MBParallelComm::Buffer::reserve(unsigned int new_size) {
-  
-#ifdef DEBUG_BUFFER
-  int tmp_pos = 0;
-  if (mem_ptr) {
-    tmp_pos = buff_ptr - mem_ptr;
-  }
-  buff_ptr = (unsigned char *)malloc(new_size);
-  assert(0 <= tmp_pos && tmp_pos <= (int)alloc_size);  
-  if (tmp_pos) memcpy(buff_ptr, mem_ptr, tmp_pos);
-  if (mem_ptr) free(mem_ptr);
-  mem_ptr = buff_ptr;
-  alloc_size = new_size;
-  buff_ptr = mem_ptr + tmp_pos;
-#else    
-  if (mem_ptr && alloc_size < new_size) {
-    size_t tmp_pos = mem_ptr ? buff_ptr - mem_ptr : 0;
-    mem_ptr = (unsigned char *)realloc(mem_ptr, new_size);
-    alloc_size = new_size;
-    buff_ptr = mem_ptr + tmp_pos;
-  }
-  else if (!mem_ptr) {
-    mem_ptr = (unsigned char *)malloc(new_size);
-    alloc_size = new_size;
-    buff_ptr = mem_ptr;
-  } 
-#endif
-}
-
-inline void MBParallelComm::Buffer::check_space(unsigned int addl_space )
-{
-  assert(buff_ptr >= mem_ptr && buff_ptr <= mem_ptr+alloc_size);
-  unsigned int new_size = buff_ptr - mem_ptr + addl_space;
-  if (new_size > alloc_size) 
-    reserve(1.5*new_size);
-}
-
-inline void MBParallelComm::reset_all_buffers() 
-{
-  std::vector<Buffer*>::iterator vit;
-  for (vit = localOwnedBuffs.begin(); vit != localOwnedBuffs.end(); vit++)
-    (*vit)->reset_buffer();
-  for (vit = remoteOwnedBuffs.begin(); vit != remoteOwnedBuffs.end(); vit++)
-    (*vit)->reset_buffer();
-}
-
-inline void MBParallelComm::delete_all_buffers() 
-{
-  std::vector<Buffer*>::iterator vit;
-  for (vit = localOwnedBuffs.begin(); vit != localOwnedBuffs.end(); vit++)
-    delete (*vit);
-  localOwnedBuffs.clear();
-  
-  for (vit = remoteOwnedBuffs.begin(); vit != remoteOwnedBuffs.end(); vit++)
-    delete (*vit);
-  remoteOwnedBuffs.clear();
-}
-
-inline std::vector<unsigned int> &MBParallelComm::buff_procs() 
-{
-  return buffProcs;
-}
-
-inline MBErrorCode MBParallelComm::get_shared_proc_tags(MBTag &sharedp,
-                                                        MBTag &sharedps,
-                                                        MBTag &sharedh,
-                                                        MBTag &sharedhs,
-                                                        MBTag &pstatus) 
-{
-  sharedp = sharedp_tag();
-  sharedps = sharedps_tag();
-  sharedh = sharedh_tag();
-  sharedhs = sharedhs_tag();
-  pstatus = pstatus_tag();
-  
-  return MB_SUCCESS;
-}
-
-inline MBErrorCode MBParallelComm::exchange_tags(const char *tag_name,
-                                                 MBRange &entities)
-{
-    // get the tag handle
-  std::vector<MBTag> tags(1);
-  MBErrorCode result = mbImpl->tag_get_handle(tag_name, tags[0]);
-  if (MB_SUCCESS != result) return result;
-  else if (!tags[0]) return MB_TAG_NOT_FOUND;
-  
-  return exchange_tags(tags, tags, entities);
-}
-  
-inline MBErrorCode MBParallelComm::exchange_tags(MBTag tagh,
-                                                 MBRange &entities)
-{
-    // get the tag handle
-  std::vector<MBTag> tags;
-  tags.push_back(tagh);
-  
-  return exchange_tags(tags, tags, entities);
-}
-  
-inline MBErrorCode MBParallelComm::get_comm_procs(std::set<unsigned int> &procs) 
-{
-  MBErrorCode result = get_interface_procs(procs);
-  if (MB_SUCCESS != result) return result;
-
-  std::copy(buffProcs.begin(), buffProcs.end(), std::inserter(procs, procs.begin()));
-    
-  return MB_SUCCESS;
-}
-
-inline MBErrorCode MBParallelComm::get_owner(MBEntityHandle entity,
-                                             int &owner) 
-{
-  MBEntityHandle tmp_handle;
-  return get_owner_handle(entity, owner, tmp_handle);
-}
-
-    /* \brief Unpack message with remote handles (const pointer to buffer)
-     */
-inline MBErrorCode MBParallelComm::unpack_remote_handles(unsigned int from_proc,
-                                                         const unsigned char *buff_ptr,
-                                                         std::vector<MBEntityHandle> &L2hloc,
-                                                         std::vector<MBEntityHandle> &L2hrem,
-                                                         std::vector<unsigned int> &L2p) 
-{
-    // cast away const-ness, we won't be passing back a modified ptr
-  unsigned char *tmp_buff = const_cast<unsigned char*>(buff_ptr);
-  return unpack_remote_handles(from_proc, tmp_buff, L2hloc, L2hrem, L2p);
-}
-
-inline void MBParallelComm::set_rank(unsigned int r) 
-{
-  procConfig.proc_rank(r);
-  if (procConfig.proc_size() < r) procConfig.proc_size(r+1);
-}
-
-inline void MBParallelComm::set_size(unsigned int s) 
-{
-  procConfig.proc_size(s);
-}
-
-inline MBErrorCode MBParallelComm::get_sharing_data(const MBEntityHandle *entities,
-                                                    int num_entities,
-                                                    std::set<int> &procs,
-                                                    int op) 
-{
-  MBRange dum_range;
-    // cast away constness 'cuz the range is passed as const
-  MBEntityHandle *ents_cast = const_cast<MBEntityHandle*>(entities);
-  std::copy(ents_cast, ents_cast+num_entities, mb_range_inserter(dum_range));
-  return get_sharing_data(dum_range, procs, op);
-}
-
-inline MBErrorCode MBParallelComm::get_sharing_data(const MBEntityHandle entity,
-                                                    int *ps, 
-                                                    MBEntityHandle *hs,
-                                                    unsigned char &pstat,
-                                                    int &num_ps) 
-{
-  unsigned int dum_ps;
-  MBErrorCode result = get_sharing_data(entity, ps, hs, pstat, dum_ps);
-  if (MB_SUCCESS == result)
-    num_ps = dum_ps;
-  return result;
-}
-  
-#endif

Deleted: MOAB/trunk/src/parallel/moab/MBParallelData.hpp
===================================================================
--- MOAB/trunk/src/parallel/moab/MBParallelData.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/moab/MBParallelData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,55 +0,0 @@
-/**
- * \class MBParallelData
- * \brief Parallel data in MOAB
- * \author Tim Tautges
- *
- *  This class implements methods to retrieve information about 
- * the parallel mesh from MOAB.  Most of this data can be retrieved
- * directly from MOAB as sets and tags; this class provides convenience
- * methods implemented on top of other MOAB functions.
- *
- */
-
-#ifndef MB_PARALLEL_DATA_HPP
-#define MB_PARALLEL_DATA_HPP
-
-#include "MBForward.hpp"
-#include "MBRange.hpp"
-
-class MBParallelComm;
-
-class MBParallelData
-{
-public:
-
-    //! constructor; if non-null parallelcomm, that is used to
-    //! determine rank, otherwise rank is taken from impl
-  MBParallelData(MBInterface *impl, MBParallelComm *pcomm = NULL);
-
-    //! return partition sets; if tag_name is input, gets sets with
-    //! that tag name, otherwise uses PARALLEL_PARTITION tag
-  MBErrorCode get_partition_sets(MBRange &part_sets,
-                                 const char *tag_name = NULL);
-
-    //! get communication interface sets and the processors with which
-    //! this processor communicates; sets are sorted by processor
-  MBErrorCode get_interface_sets(std::vector<MBEntityHandle> &iface_sets,
-                                 std::vector<int> &iface_procs);
-  
-
-private:
-
-    //! interface instance to which this instance corresponds
-  MBInterface *mbImpl;
-
-    //! MBParallelComm object to which this is bound
-  MBParallelComm *parallelComm;
-  
-};
-
-inline MBParallelData::MBParallelData(MBInterface *impl, 
-                                      MBParallelComm *pcomm) 
-    : mbImpl(impl), parallelComm(pcomm) 
-{}
-
-#endif

Deleted: MOAB/trunk/src/parallel/moab/MBProcConfig.hpp
===================================================================
--- MOAB/trunk/src/parallel/moab/MBProcConfig.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/moab/MBProcConfig.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,77 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-#ifndef MB_PROC_CONFIG_HPP
-#define MB_PROC_CONFIG_HPP
-
-#include "MBTypes.h"
-#include "MBRange.hpp"
-
-class MBInterface;
-
-
-#ifdef USE_MPI
-#  include "MBmpi.h"
-#else
-  typedef int MPI_Comm;
-# define MPI_COMM_WORLD 0
-#endif
-
-struct crystal_data;
-
-/**\brief Multi-CPU information for parallel MOAB */
-class MBProcConfig {
-public:
-
-  MBProcConfig(MPI_Comm proc_comm = MPI_COMM_WORLD);
-  
-  ~MBProcConfig();
-  
-    //! Get the current processor number
-  unsigned proc_rank() const 
-    { return procRank; }
-      
-    //! Get the number of processors
-  unsigned proc_size() const 
-    { return procSize; }
-      
-    //! get a crystal router for this parallel job
-  crystal_data *crystal_router(bool construct_if_missing = true);
-
-    //! get/set the communicator for this proc config
-  MPI_Comm proc_comm() const {return procComm;}
-  void proc_comm(MPI_Comm this_comm) {procComm = this_comm;}
-
-    //! set rank/size; USED FOR TESTING ONLY!
-  void proc_rank(unsigned r) {procRank = r;}
-  void proc_size(unsigned s) {procSize = s;}
-
-private:
-
-    //! MPI communicator set for this instance
-  MPI_Comm procComm;
-
-    //! rank of this processor
-  unsigned procRank;
-  
-    //! number of processors
-  unsigned procSize;
-  
-    //! crystal router for this parallel job
-  crystal_data* crystalData;
-  
-};
-
-#endif

Deleted: MOAB/trunk/src/parallel/moab/MBmpi.h
===================================================================
--- MOAB/trunk/src/parallel/moab/MBmpi.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/moab/MBmpi.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,48 +0,0 @@
-#ifndef MB_MPI_H
-#define MB_MPI_H
-#include "MBmpi_config.h"
-
-#ifndef __cplusplus
-#  include <mpi.h>
-#elif !defined(MB_MPI_CXX_CONFLICT)
-#  ifndef MPICH_IGNORE_CXX_SEEK
-#    define MPICH_IGNORE_CXX_SEEK
-#  endif
-#  include <mpi.h>
-#else
-#  include <stdio.h>
-#  ifdef SEEK_SET
-#    undef SEEK_SET
-#    ifdef MB_SEEK_SET
-#      define MB_RESTORE_SEEK_SET
-#    endif
-#  endif
-#  ifdef SEEK_CUR
-#    undef SEEK_CUR
-#    ifdef MB_SEEK_CUR
-#      define MB_RESTORE_SEEK_CUR
-#    endif
-#  endif
-#  ifdef SEEK_END
-#    undef SEEK_END
-#    ifdef MB_SEEK_END
-#      define MB_RESTORE_SEEK_END
-#    endif
-#  endif
-#  include <mpi.h>
-#  ifdef MB_RESTORE_SEEK_SET
-#    undef MB_RESTORE_SEEK_SET
-#    define SEEK_SET MB_SEEK_SET
-#  endif
-#  ifdef MB_RESTORE_SEEK_CUR
-#    undef MB_RESTORE_SEEK_CUR
-#    define SEEK_CUR MB_SEEK_CUR
-#  endif
-#  ifdef MB_RESTORE_SEEK_END
-#    undef MB_RESTORE_SEEK_END
-#    define SEEK_END MB_SEEK_END
-#  endif
-#endif
-
-
-#endif

Deleted: MOAB/trunk/src/parallel/moab/MBmpi_config.h.in
===================================================================
--- MOAB/trunk/src/parallel/moab/MBmpi_config.h.in	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/moab/MBmpi_config.h.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,11 +0,0 @@
-/* MPICH_IGNORE_CXX_SEEK is not sufficient to avoid conflicts */
-#undef MB_MPI_CXX_CONFLICT
-
-/* "Value of C SEEK_CUR" */
-#undef MB_SEEK_CUR
-
-/* "Value of C SEEK_END" */
-#undef MB_SEEK_END
-
-/* "Value of C SEEK_SET" */
-#undef MB_SEEK_SET

Copied: MOAB/trunk/src/parallel/moab/ParallelComm.hpp (from rev 3583, MOAB/trunk/src/parallel/moab/MBParallelComm.hpp)
===================================================================
--- MOAB/trunk/src/parallel/moab/ParallelComm.hpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/moab/ParallelComm.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1262 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**
+ * \class ParallelComm
+ * \brief Parallel communications in MOAB
+ * \author Tim Tautges
+ *
+ *  This class implements methods to communicate mesh between processors
+ *
+ */
+
+#ifndef MOAB_PARALLEL_COMM_HPP
+#define MOAB_PARALLEL_COMM_HPP
+
+#include "moab/Forward.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
+#include "moab/ProcConfig.hpp"
+#include <map>
+#include <set>
+#include <vector>
+#include <iostream>
+#include <fstream>
+#include <assert.h>
+#include <stdlib.h>
+#include "math.h"
+#include "moab_mpi.h"
+
+extern "C" {
+  struct tuple_list;
+}
+
+namespace moab {
+
+class TagServer;
+class SequenceManager;
+template <typename KeyType, typename ValType, ValType NullVal> class RangeMap;
+typedef RangeMap<EntityHandle, EntityHandle, 0> HandleMap;
+
+#define MAX_SHARING_PROCS 64
+
+class ParallelComm 
+{
+public:
+
+    // ==================================
+    // \section CONSTRUCTORS/DESTRUCTORS/PCOMM MANAGEMENT
+    // ==================================
+
+    //! constructor
+  ParallelComm(Interface *impl,
+                 MPI_Comm comm = MPI_COMM_WORLD,
+                 int* pcomm_id_out = 0);
+
+    //! constructor taking packed buffer, for testing
+  ParallelComm(Interface *impl,
+                 std::vector<unsigned char> &tmp_buff,
+                 MPI_Comm comm = MPI_COMM_WORLD,
+                 int* pcomm_id_out = 0);
+
+    //! Get ID used to reference this PCOMM instance
+  int get_id() const { return pcommID; }
+
+    //! get the indexed pcomm object from the interface
+  static ParallelComm *get_pcomm(Interface *impl, const int index);
+  
+    //! Get ParallelComm instance associated with partition handle
+    //! Will create ParallelComm instance if a) one does not already
+    //! exist and b) a valid value for MPI_Comm is passed.
+  static ParallelComm *get_pcomm( Interface* impl, 
+                                    EntityHandle partitioning,
+                                    const MPI_Comm* comm = 0 );
+
+  static ErrorCode get_all_pcomm( Interface* impl,
+                                    std::vector<ParallelComm*>& list );
+
+    //! destructor
+  ~ParallelComm();
+  
+  static unsigned char PROC_SHARED, PROC_OWNER;
+  
+    // ==================================
+    // \section GLOBAL IDS
+    // ==================================
+
+    //! assign a global id space, for largest-dimension or all entities (and
+    //! in either case for vertices too)
+  ErrorCode assign_global_ids(EntityHandle this_set,
+                                const int dimension,
+                                const int start_id = 1,
+                                const bool largest_dim_only = true,
+                                const bool parallel = true);
+
+    //! check for global ids; based only on tag handle being there or not;
+    //! if it's not there, create them for the specified dimensions
+  ErrorCode check_global_ids(EntityHandle this_set,
+                               const int dimension, 
+                               const int start_id = 1,
+                               const bool largest_dim_only = true,
+                               const bool parallel = true);
+  
+    // ==================================
+    // \section HIGH-LEVEL COMMUNICATION (send/recv/bcast ents, exchange tags)
+    // ==================================
+
+    /** \brief send entities to another processor, optionally waiting until it's done
+     *
+     * Send entities to another processor, with adjs, sets, and tags.  
+     * If store_remote_handles is true, this call receives back handles assigned to
+     * entities sent to destination processor and stores them in sharedh_tag or 
+     * sharedhs_tag.
+     * \param to_proc Destination processor
+     * \param orig_ents Entities requested to send
+     * \param adjs If true, send adjacencies for equiv entities (currently unsupported)
+     * \param tags If true, send tag values for all tags assigned to entities
+     * \param store_remote_handles If true, also recv message with handles on destination processor
+     * \param final_ents Range containing all entities sent
+     * \param wait_all If true, wait until all messages received/sent complete
+     */
+  ErrorCode send_entities(const int to_proc,
+                            Range &orig_ents,
+                            const bool adjs,
+                            const bool tags,
+                            const bool store_remote_handles,
+                            Range &final_ents,
+                            bool wait_all = true);
+  
+    /** \brief Receive entities from another processor, optionally waiting until it's done
+     *
+     * Receive entities from another processor, with adjs, sets, and tags.  
+     * If store_remote_handles is true, this call sends back handles assigned to
+     * the entities received.
+     * \param from_proc Source processor
+     * \param store_remote_handles If true, send message with new entity handles to source processor
+     * \param final_ents Range containing all entities received
+     * \param wait_all If true, wait until all messages received/sent complete
+     */
+  ErrorCode recv_entities(const int from_proc,
+                            const bool store_remote_handles,
+                            Range &final_ents,
+                            bool wait_all = true);
+  
+    /** \brief Exchange ghost cells with neighboring procs
+     * Neighboring processors are those sharing an interface 
+     * with this processor.  All entities of dimension ghost_dim
+     * within num_layers of interface, measured going through bridge_dim,
+     * are exchanged.  See MeshTopoUtil::get_bridge_adjacencies for description
+     * of bridge adjacencies.  If wait_all is false and store_remote_handles
+     * is true, MPI_Request objects are available in the sendReqs[2*MAX_SHARING_PROCS] 
+     * member array, with inactive requests marked as MPI_REQUEST_NULL.  If
+     * store_remote_handles or wait_all is false, this function returns after 
+     * all entities have been received and processed.
+     * \param ghost_dim Dimension of ghost entities to be exchanged
+     * \param bridge_dim Dimension of entities used to measure layers from interface
+     * \param num_layers Number of layers of ghosts requested
+     * \param store_remote_handles If true, send message with new entity handles to source processor
+     * \param wait_all If true, function does not return until all send buffers
+     *       are cleared.
+     */
+  ErrorCode exchange_ghost_cells(int ghost_dim, int bridge_dim, 
+                                   int num_layers,
+                                   bool store_remote_handles,
+                                   bool wait_all = true);
+
+    /** \brief Static version of exchange_ghost_cells, exchanging info through
+     * buffers rather than messages
+     */
+  static ErrorCode exchange_ghost_cells(ParallelComm **pc,
+                                          unsigned int num_procs,
+                                          int ghost_dim, int bridge_dim,
+                                          int num_layers,
+                                          bool store_remote_handles);
+  
+    /** \brief Exchange tags for all shared and ghosted entities
+     * This function should be called collectively over the communicator for this ParallelComm.
+     * If this version is called, all ghosted/shared entities should have a value for this
+     * tag (or the tag should have a default value).
+     * \param tags Vector of tag handles to be exchanged
+     */
+  ErrorCode exchange_tags(std::vector<Tag> &src_tags,
+                            std::vector<Tag> &dst_tags,
+                            Range &entities);
+  
+    /** \brief Exchange tags for all shared and ghosted entities
+     * This function should be called collectively over the communicator for this ParallelComm
+     * \param tag_name Name of tag to be exchanged
+     */
+  ErrorCode exchange_tags(const char *tag_name,
+                            Range &entities);
+  
+    /** \brief Exchange tags for all shared and ghosted entities
+     * This function should be called collectively over the communicator for this ParallelComm
+     * \param tagh Handle of tag to be exchanged
+     */
+  ErrorCode exchange_tags(Tag tagh,
+                            Range &entities);
+  
+    /** \brief Broadcast all entities resident on from_proc to other processors
+     * This function assumes remote handles are *not* being stored, since (usually)
+     * every processor will know about the whole mesh.
+     * \param from_proc Processor having the mesh to be broadcast
+     * \param entities On return, the entities sent or received in this call
+     * \param adjacencies If true, adjacencies are sent for equiv entities (currently unsupported)
+     * \param tags If true, all non-default-valued tags are sent for sent entities
+     */
+  ErrorCode broadcast_entities(const int from_proc,
+                                 Range& entities,
+                                 const bool adjacencies = false,
+                                 const bool tags = true );
+
+    // ==================================
+    // \section INITIALIZATION OF PARALLEL DATA (resolve_shared_ents, etc.)
+    // ==================================
+
+    /** \brief Resolve shared entities between processors
+     *
+     * Resolve shared entities between processors for entities in proc_ents,
+     * by comparing global id tag values on vertices on skin of elements in
+     * proc_ents.  Shared entities are assigned a tag that's either
+     * PARALLEL_SHARED_PROC_TAG_NAME, which is 1 integer in length, or 
+     * PARALLEL_SHARED_PROCS_TAG_NAME, whose length depends on the maximum
+     * number of sharing processors.  Values in these tags denote the ranks
+     * of sharing processors, and the list ends with the value -1.
+     *
+     * If shared_dim is input as -1 or not input, a value one less than the
+     * maximum dimension of entities in proc_ents is used.
+     *
+     * \param proc_ents Entities for which to resolve shared entities
+     * \param shared_dim Maximum dimension of shared entities to look for
+     */
+  ErrorCode resolve_shared_ents(EntityHandle this_set,
+                                  Range &proc_ents, 
+                                  int resolve_dim = -1,
+                                  int shared_dim = -1,
+                                  const Tag* id_tag = 0);
+  
+    /** \brief Resolve shared entities between processors
+     *
+     * Same as resolve_shared_ents(Range&), except works for
+     * all entities in instance of dimension dim.  
+     *
+     * If shared_dim is input as -1 or not input, a value one less than the
+     * maximum dimension of entities is used.
+
+     * \param dim Dimension of entities in the partition
+     * \param shared_dim Maximum dimension of shared entities to look for
+     */
+  ErrorCode resolve_shared_ents(EntityHandle this_set,
+                                  int resolve_dim = 3, 
+                                  int shared_dim = -1,
+                                  const Tag* id_tag = 0);
+    
+  static ErrorCode resolve_shared_ents(ParallelComm **pc, 
+                                         const unsigned int np, 
+                                         const int to_dim);
+  
+    // ==================================
+    // \section GET PARALLEL DATA (shared/owned/iface entities, etc.)
+    // ==================================
+
+    /** \brief Get entities with the given pstatus bit(s) set
+     * Returns any entities whose pstatus tag value v satisfies (v & pstatus_val)
+     *
+     * \param dim Dimension of entities to be returned, or -1 if any
+     * \param pstatus_val pstatus value of desired entities
+     * \param pstatus_ents Entities returned from function
+     */
+  ErrorCode get_pstatus_entities(int dim,
+                                   unsigned char pstatus_val,
+                                   Range &pstatus_ents);
+  
+    /** \brief Return the rank of the entity owner
+     */
+  ErrorCode get_owner(EntityHandle entity,
+                        int &owner);
+  
+    /** \brief Return the owner processor and handle of a given entity
+     */
+  ErrorCode get_owner_handle(EntityHandle entity,
+                               int &owner,
+                               EntityHandle &handle);
+
+    /** \brief Get the shared processors/handles for an entity
+     * Get the shared processors/handles for an entity.  Arrays must
+     * be large enough to receive data for all sharing procs.
+     * \param entity Entity being queried
+     * \param ps Pointer to sharing proc data
+     * \param hs Pointer to shared proc handle data
+     * \param pstat Reference to pstatus data returned from this function
+     */
+  ErrorCode get_sharing_data(const EntityHandle entity,
+                               int *ps, 
+                               EntityHandle *hs,
+                               unsigned char &pstat,
+                               unsigned int &num_ps);
+
+    /** \brief Get the shared processors/handles for an entity
+     * Same as other version but with int num_ps
+     * \param entity Entity being queried
+     * \param ps Pointer to sharing proc data
+     * \param hs Pointer to shared proc handle data
+     * \param pstat Reference to pstatus data returned from this function
+     */
+  ErrorCode get_sharing_data(const EntityHandle entity,
+                               int *ps, 
+                               EntityHandle *hs,
+                               unsigned char &pstat,
+                               int &num_ps);
+
+    /** \brief Get the intersection or union of all sharing processors
+     * Get the intersection or union of all sharing processors.  Processor set
+     * is cleared as part of this function.
+     * \param entities Entity list ptr
+     * \param num_entities Number of entities
+     * \param procs Processors returned
+     * \param op Either Interface::UNION or Interface::INTERSECT
+     */
+  ErrorCode get_sharing_data(const EntityHandle *entities,
+                               int num_entities,
+                               std::set<int> &procs,
+                               int op = Interface::INTERSECT);
+  
+    /** \brief Get the intersection or union of all sharing processors
+     * Same as previous variant but with range as input
+     */
+  ErrorCode get_sharing_data(const Range &entities,
+                               std::set<int> &procs,
+                               int op = Interface::INTERSECT);
+  
+    /** \brief Get entities on an inter-processor interface and of specified dimension
+     * If other_proc is -1, any interface entities are returned.  If dim is -1,
+     * entities of all dimensions on interface are returned.
+     * \param other_proc Rank of processor for which interface entities are requested
+     * \param shared_ents Entities returned from function
+     * \param dim Dimension of interface entities requested
+     * \param iface If true, return only entities on the interface
+     */
+  ErrorCode get_shared_entities(int other_proc,
+                                  Range &shared_ents,
+                                  int dim = -1,
+                                  const bool iface = false,
+                                  const bool owned_filter = false);
+/*  
+    //! return partition sets; if tag_name is input, gets sets with
+    //! that tag name, otherwise uses PARALLEL_PARTITION tag
+  ErrorCode get_partition_sets(EntityHandle this_set,
+                                 Range &part_sets,
+                                 const char *tag_name = NULL);
+*/
+    //! get processors with which this processor shares an interface
+  ErrorCode get_interface_procs(std::set<unsigned int> &iface_procs,
+                                  const bool get_buffs = false);
+
+    //! get processors with which this processor communicates
+  ErrorCode get_comm_procs(std::set<unsigned int> &procs);
+  
+    // ==================================
+    // \section LOW-LEVEL DATA (tags, sets on interface/partition, etc.)
+    // ==================================
+
+    //! Get proc config for this communication object
+  const ProcConfig &proc_config() const {return procConfig;}
+  
+    //! Get proc config for this communication object
+  ProcConfig &proc_config() {return procConfig;}
+  
+  unsigned rank() const { return proc_config().proc_rank(); }
+  unsigned size() const { return proc_config().proc_size(); }
+  MPI_Comm comm() const { return proc_config().proc_comm(); }
+  
+    //! return the tags used to indicate shared procs and handles
+  ErrorCode get_shared_proc_tags(Tag &sharedp_tag,
+                                   Tag &sharedps_tag,
+                                   Tag &sharedh_tag,
+                                   Tag &sharedhs_tag,
+                                   Tag &pstatus_tag);
+
+    //! return partition, interface set ranges
+  Range &partition_sets() {return partitionSets;}
+  const Range &partition_sets() const {return partitionSets;}
+  Range &interface_sets() {return interfaceSets;}
+  const Range &interface_sets() const {return interfaceSets;}
+      
+    //! return sharedp tag
+  Tag sharedp_tag();
+  
+    //! return sharedps tag
+  Tag sharedps_tag();
+  
+    //! return sharedh tag
+  Tag sharedh_tag();
+  
+    //! return sharedhs tag
+  Tag sharedhs_tag();
+  
+    //! return pstatus tag
+  Tag pstatus_tag();
+
+    //! return pcomm tag; static because might not have a pcomm before going
+    //! to look for one on the interface
+  static Tag pcomm_tag(Interface *impl,
+                         bool create_if_missing = true);
+  
+    //! return partitions set tag
+  Tag partition_tag();
+  Tag part_tag() { return partition_tag(); }
+
+    // ==================================
+    // \section IMESHP-RELATED FUNCTIONS
+    // ==================================
+
+    //! return all the entities in parts owned locally
+  ErrorCode get_part_entities(Range &ents, int dim = -1);
+  
+  EntityHandle get_partitioning() const { return partitioningSet; }
+  ErrorCode set_partitioning( EntityHandle h );
+  ErrorCode get_global_part_count( int& count_out ) const;
+  ErrorCode get_part_owner( int part_id, int& owner_out ) const;
+  ErrorCode get_part_id( EntityHandle part, int& id_out ) const;
+  ErrorCode get_part_handle( int id, EntityHandle& handle_out ) const;
+  ErrorCode create_part( EntityHandle& part_out );
+  ErrorCode destroy_part( EntityHandle part ) ;
+  ErrorCode collective_sync_partition();
+  ErrorCode get_part_neighbor_ids( EntityHandle part, 
+                                     int neighbors_out[MAX_SHARING_PROCS],
+                                     int& num_neighbors_out );
+  ErrorCode get_interface_sets( EntityHandle part, 
+                                  Range& iface_sets_out,
+                                  int* adj_part_id = 0 );
+  ErrorCode get_owning_part( EntityHandle entity, 
+                               int& owning_part_id_out,
+                               EntityHandle* owning_handle = 0 );
+  ErrorCode get_sharing_parts( EntityHandle entity,
+                                 int part_ids_out[MAX_SHARING_PROCS],
+                                 int& num_part_ids_out,
+                                 EntityHandle remote_handles[MAX_SHARING_PROCS] = 0);
+  
+    // Propogate mesh modification amongst shared entities
+    // from the onwing processor to any procs with copies.
+  ErrorCode update_shared_mesh();
+
+    /** Filter the entities by pstatus tag.  
+     * op is one of PSTATUS_ AND, OR, NOT; an entity is output if:
+     * AND: all bits set in pstatus_val are also set on entity
+     * OR: any bits set in pstatus_val also set on entity
+     * NOT: any bits set in pstatus_val are not set on entity
+     *
+     * Results returned in input list, unless result_ents is passed in non-null,
+     * in which case results are returned in result_ents.
+     *
+     * If ents is passed in empty, filter is done on shared entities in this
+     * pcomm instance, i.e. contents of sharedEnts.
+     *
+     *\param ents       Input entities to filter
+     *\param pstatus_val pstatus value to which entities are compared
+     *\param op Bitwise operation performed between pstatus values
+     *\param to_proc If non-negative and PSTATUS_SHARED is set on pstatus_val,
+     *               only entities shared with to_proc are returned
+     *\param result_ents If non-null, results of filter are put in the 
+     *       pointed-to range
+     */
+  ErrorCode filter_pstatus( Range &ents,
+                              const unsigned char pstatus_val,
+                              const unsigned char op,
+                              int to_proc = -1,
+                              Range *returned_ents = NULL);
+
+    /** \brief Get entities on interfaces shared with another proc
+     *
+     * \param other_proc Other proc sharing the interface
+     * \param dim Dimension of entities to return, -1 if all dims
+     * \param iface_ents Returned entities
+     */
+  ErrorCode get_iface_entities(int other_proc,
+                                 int dim,
+                                 Range &iface_ents);
+  
+  Interface* get_moab() const { return mbImpl; }
+
+  class Buffer {
+  public:
+    unsigned char *mem_ptr;
+    unsigned char *buff_ptr;
+    unsigned int alloc_size;
+    
+    Buffer(unsigned int sz = 0);
+    Buffer(const Buffer &);
+    ~Buffer();
+    void reset_buffer(size_t buff_pos = 0) {reset_ptr(buff_pos); reserve(INITIAL_BUFF_SIZE);}
+    void reset_ptr(size_t buff_pos = 0) {assert((!mem_ptr && !buff_pos)|| (alloc_size >= buff_pos)); buff_ptr = mem_ptr + buff_pos;}
+    void reserve(unsigned int new_size);
+    void set_stored_size() {*((int*)mem_ptr) = (int)(buff_ptr - mem_ptr);}
+    int get_stored_size() {return *((int*)mem_ptr);}
+          
+    void check_space(unsigned int addl_space);
+  };
+
+    //! public 'cuz we want to unit test these externally
+  ErrorCode pack_buffer(Range &orig_ents, 
+                          const bool adjacencies,
+                          const bool tags,
+                          const bool store_remote_handles,
+                          const int to_proc,
+                          Buffer *buff);
+  
+  ErrorCode unpack_buffer(unsigned char *buff_ptr,
+                            const bool store_remote_handles,
+                            const int from_proc,
+                            const int ind,
+                            std::vector<std::vector<EntityHandle> > &L1hloc,
+                            std::vector<std::vector<EntityHandle> > &L1hrem,
+                            std::vector<std::vector<int> > &L1p,
+                            std::vector<EntityHandle> &L2hloc, 
+                            std::vector<EntityHandle> &L2hrem,
+                            std::vector<unsigned int> &L2p,
+                            Range &new_ents);
+  
+  ErrorCode pack_entities(Range &entities,
+                            Buffer *buff,
+                            const bool store_remote_handles,
+                            const int to_proc,
+                            const bool is_iface,
+                            std::vector<std::set<unsigned int> > *entprocs = NULL,
+                            Range *allsent = NULL);
+
+    //! unpack entities in buff_ptr
+  ErrorCode unpack_entities(unsigned char *&buff_ptr,
+                              const bool store_remote_handles,
+                              const int from_ind,
+                              const bool is_iface,
+                              std::vector<std::vector<EntityHandle> > &L1hloc,
+                              std::vector<std::vector<EntityHandle> > &L1hrem,
+                              std::vector<std::vector<int> > &L1p,
+                              std::vector<EntityHandle> &L2hloc, 
+                              std::vector<EntityHandle> &L2hrem,
+                              std::vector<unsigned int> &L2p,
+                              Range &new_ents);
+  
+    //! Call exchange_all_shared_handles, then compare the results with tag data
+    //! on local shared entities.
+  ErrorCode check_all_shared_handles();
+
+  static ErrorCode check_all_shared_handles(ParallelComm **pcs,
+                                              int num_pcs);
+  
+  struct SharedEntityData {
+    EntityHandle local;
+    EntityHandle remote;
+    int owner;
+  };
+
+  ErrorCode pack_shared_handles(
+      std::vector<std::vector<SharedEntityData> > &send_data);
+
+    // check consistency of sharedEnts against their tags and their
+    // vertices' tags
+  ErrorCode check_local_shared();
+  
+    // check contents of communicated shared entity data against tags
+  ErrorCode check_my_shared_handles(
+      std::vector<std::vector<SharedEntityData> > &shents,
+                                      const char *prefix = NULL);
+  
+    //! set rank for this pcomm; USED FOR TESTING ONLY!
+  void set_rank(unsigned int r);
+  
+    //! set rank for this pcomm; USED FOR TESTING ONLY!
+  void set_size(unsigned int r);
+  
+    //! get (and possibly allocate) buffers for messages to/from to_proc; returns
+    //! index of to_proc in buffProcs vector; if is_new is non-NULL, sets to
+    //! whether new buffer was allocated
+    //! PUBLIC ONLY FOR TESTING!
+  int get_buffers(int to_proc, bool *is_new = NULL);
+
+    /* \brief Unpack message with remote handles
+     * PUBLIC ONLY FOR TESTING!
+     */
+  ErrorCode unpack_remote_handles(unsigned int from_proc,
+                                    unsigned char *&buff_ptr,
+                                    std::vector<EntityHandle> &L2hloc,
+                                    std::vector<EntityHandle> &L2hrem,
+                                    std::vector<unsigned int> &L2p);
+  
+    /* \brief Pack message with remote handles
+     * PUBLIC ONLY FOR TESTING!
+     */
+  ErrorCode pack_remote_handles(std::vector<EntityHandle> &L1hloc,
+                                  std::vector<EntityHandle> &L1hrem,
+                                  std::vector<int> &procs,
+                                  unsigned int to_proc,
+                                  Buffer *buff);
+  
+  ErrorCode list_entities(const EntityHandle *ents, int num_ents);
+  
+  ErrorCode list_entities(const Range &ents);
+  
+  static const unsigned int INITIAL_BUFF_SIZE;
+
+private:
+
+    // common initialization code, called from various constructors
+  void initialize();
+  
+  ErrorCode set_sharing_data(EntityHandle ent, unsigned char pstatus,
+                               int old_nump, int new_nump,
+                               int *ps, EntityHandle *hs);
+  
+  ErrorCode check_clean_iface(Range &allsent);
+  
+  void define_mpe();
+
+  ErrorCode get_sent_ents(const bool is_iface,
+                            const int bridge_dim, const int ghost_dim,
+                            const int num_layers,
+                            Range *sent_ents, Range &allsent,
+                            std::vector<std::set<unsigned int> > &entprocs);
+  
+    /** \brief Set pstatus values on entities
+     *
+     * \param pstatus_ents Entities to be set
+     * \param pstatus_val Pstatus value to be set
+     * \param lower_dim_ents If true, lower-dimensional ents (incl. vertices) set too
+     *        (and created if they don't exist)
+     * \param verts_too If true, vertices also set
+     * \param operation If UNION, pstatus_val is OR-d with existing value, otherwise
+     *        existing value is over-written
+     */
+  ErrorCode set_pstatus_entities(Range &pstatus_ents,
+                                   unsigned char pstatus_val,
+                                   bool lower_dim_ents = false,
+                                   bool verts_too = true,
+                                   int operation = Interface::UNION);
+
+    /** \brief Set pstatus values on entities (vector-based function)
+     *
+     * \param pstatus_ents Entities to be set
+     * \param pstatus_val Pstatus value to be set
+     * \param lower_dim_ents If true, lower-dimensional ents (incl. vertices) set too
+     *        (and created if they don't exist)
+     * \param verts_too If true, vertices also set
+     * \param operation If UNION, pstatus_val is OR-d with existing value, otherwise
+     *        existing value is over-written
+     */
+  ErrorCode set_pstatus_entities(EntityHandle *pstatus_ents,
+                                   int num_ents,
+                                   unsigned char pstatus_val,
+                                   bool lower_dim_ents = false,
+                                   bool verts_too = true,
+                                   int operation = Interface::UNION);
+
+  int num_subranges(const Range &this_range);
+
+    //! estimate size required to pack entities
+  int estimate_ents_buffer_size(Range &entities,
+                                const bool store_remote_handles);
+  
+    //! estimate size required to pack sets
+  int estimate_sets_buffer_size(Range &entities,
+                                const bool store_remote_handles);
+  
+    //! send the indicated buffer, possibly sending size first
+  ErrorCode send_buffer(const unsigned int to_proc,
+                          Buffer *send_buff,
+                          const int msg_tag,
+                          MPI_Request &send_req,
+                          MPI_Request &ack_recv_req,
+                          int *ack_buff,
+                          int &this_incoming,
+                          int next_mesg_tag = -1,
+                          Buffer *next_recv_buff = NULL,
+                          MPI_Request *next_recv_req = NULL,
+                          int *next_incoming = NULL);
+  
+    //! process incoming message; if longer than the initial size, post
+    //! recv for next part then send ack; if ack, send second part; else
+    //! indicate that we're done and buffer is ready for processing
+  ErrorCode recv_buffer(int mesg_tag_expected,
+                          const MPI_Status &mpi_status,
+                          Buffer *recv_buff,
+                          MPI_Request &recv_2nd_req,
+                          MPI_Request &ack_req,
+                          int &this_incoming,
+                          Buffer *send_buff,
+                          MPI_Request &send_req,
+                          MPI_Request &sent_ack_req,
+                          bool &done,
+                          Buffer *next_buff = NULL,
+                          int next_tag = -1,
+                          MPI_Request *next_req = NULL,
+                          int *next_incoming = NULL);
+  
+    //! pack a range of entities with equal # verts per entity, along with
+    //! the range on the sending proc
+  ErrorCode pack_entity_seq(const int nodes_per_entity,
+                              const bool store_remote_handles,
+                              const int to_proc,
+                              Range &these_ents,
+                              Range &entities,
+                              Buffer *buff);
+  
+  ErrorCode print_buffer(unsigned char *buff_ptr, int mesg_type, int from_proc,
+                           bool sent);
+  
+    //! for all the entities in the received buffer; for each, save
+    //! entities in this instance which match connectivity, or zero if none found
+  ErrorCode unpack_iface_entities(unsigned char *&buff_ptr, 
+                                    const int from_proc,
+                                    const int ind,
+                                    std::vector<EntityHandle> &recd_ents);
+  
+  ErrorCode pack_sets(Range &entities,
+                        Buffer *buff,
+                        const bool store_handles,
+                        const int to_proc);
+  
+  ErrorCode unpack_sets(unsigned char *&buff_ptr,
+                          Range &entities,
+                          const bool store_handles,
+                          const int to_proc);
+  
+  ErrorCode pack_adjacencies(Range &entities,
+                               Range::const_iterator &start_rit,
+                               Range &whole_range,
+                               unsigned char *&buff_ptr,
+                               int &count,
+                               const bool just_count,
+                               const bool store_handles,
+                               const int to_proc);
+
+  ErrorCode unpack_adjacencies(unsigned char *&buff_ptr,
+                                 Range &entities,
+                                 const bool store_handles,
+                                 const int from_proc);
+  
+
+    /* \brief Unpack message with remote handles (const pointer to buffer)
+     */
+  ErrorCode unpack_remote_handles(unsigned int from_proc,
+                                    const unsigned char *buff_ptr,
+                                    std::vector<EntityHandle> &L2hloc,
+                                    std::vector<EntityHandle> &L2hrem,
+                                    std::vector<unsigned int> &L2p);
+  
+    //! given connectivity and type, find an existing entity, if there is one
+  ErrorCode find_existing_entity(const bool is_iface,
+                                   const int owner_p,
+                                   const EntityHandle owner_h,
+                                   const int num_ents,
+                                   const EntityHandle *connect,
+                                   const int num_connect,
+                                   const EntityType this_type,
+                                   std::vector<EntityHandle> &L2hloc,
+                                   std::vector<EntityHandle> &L2hrem,
+                                   std::vector<unsigned int> &L2p,
+                                   EntityHandle &new_h);
+  
+  ErrorCode build_sharedhps_list(const EntityHandle entity,
+                                   const unsigned char pstatus,
+                                   const int sharedp, 
+                                   const std::set<unsigned int> &entprocs,
+                                   unsigned int &num_ents,
+                                   int *tmp_procs,
+                                   EntityHandle *tmp_handles);
+  
+  /**\brief Get list of tags for which to exchange data
+   *
+   * Get tags and entities for which to exchange tag data.  This function
+   * was originally part of 'pack_tags' requested with the 
+   * 'all_possible_tags' parameter.
+   *
+   *\param all_entities  Input.  The set of entities for which data is to 
+   *                      be communicated.
+   *\param all_tags      Output.  Populated with the handles of tags to be
+   *                      sent.
+   *\param tag_ranges    Output.  For each corresponding tag in all_tags, the
+   *                      subset of 'all_entities' for which a tag value has
+   *                      been set.
+   */
+  ErrorCode get_tag_send_list( const Range& all_entities,
+                                 std::vector<Tag>& all_tags,
+                                 std::vector<Range>& tag_ranges );
+
+  /**\brief Serialize entity tag data
+   *
+   * This function operates in two passes.  The first phase,
+   * specified by 'just_count == true' calculates the necesary
+   * buffer size for the serialized data.  The second phase
+   * writes the actual binary serialized representation of the
+   * data to the passed buffer.
+   *
+   *\NOTE First two arguments are not used.  (Legacy interface?)
+   *
+   *\param entities      NOT USED
+   *\param start_rit     NOT USED
+   *\param whole_range   Should be the union of the sets of entities for 
+   *                     which tag values are to be serialized.  Also
+   *                     specifies ordering for indexes for tag values and
+   *                     serves as the superset from which to compose entity
+   *                     lists from individual tags if just_count and
+   *                     all_possible_tags are both true.
+   *\param buff_ptr      Buffer into which to write binary serailzed data
+   *\param count         Output:  The size of the serialized data is added
+   *                     to this parameter.  NOTE: Should probalby initialize
+   *                     to zero before calling.
+   *\param just_count    If true, just calculate the buffer size required to
+   *                     hold the serialized data.  Will also append to
+   *                     'all_tags' and 'tag_ranges' if all_possible_tags
+   *                     == true.
+   *\param store_handles The data for each tag is preceeded by a list of 
+   *                     EntityHandles designating the entity each of
+   *                     the subsequent tag values corresponds to.  This value
+   *                     may be one of:
+   *                     1) If store_handles == false:
+   *                        An invalid handle composed of {MBMAXTYPE,idx}, where
+   *                        idx is the position of the entity in "whole_range".
+   *                     2) If store_hanldes == true and a valid remote
+   *                        handle exists, the remote handle.
+   *                     3) If store_hanldes == true and no valid remote 
+   *                        handle is defined for the entity, the same as 1).
+   *\param to_proc       If 'store_handles' is true, the processor rank for
+   *                     which to store the corresponding remote entity 
+   *                     handles.
+   *\param all_tags      List of tags to write
+   *\param tag_ranges    List of entities to serialize tag data, one
+   *                            for each corresponding tag handle in 'all_tags.
+   */
+  ErrorCode pack_tags(Range &entities,
+                        const std::vector<Tag> &src_tags,
+                        const std::vector<Tag> &dst_tags,
+                        const std::vector<Range> &tag_ranges,
+                        Buffer *buff,
+                        const bool store_handles,
+                        const int to_proc);
+
+    /**\brief Calculate buffer size required to packtag data
+     *\param source_tag The tag for which data will be serialized
+     *\param entites    The entities for which tag values will be serialized
+     *\param count_out  Output: The required buffer size, in bytes.
+     */
+  ErrorCode packed_tag_size( Tag source_tag, 
+                               const Range& entities, 
+                               int& count_out );
+  
+  /**\brief Serialize tag data
+   *\param source_tag    The tag for which data will be serialized
+   *\param destination_tag Tag in which to store unpacked tag data.  Typically
+   *                     the same as source_tag.
+   *\param entites       The entities for which tag values will be serialized
+   *\param whole_range   Calculate entity indices as location in this range
+   *\param buff_ptr      Input/Output: As input, pointer to the start of the
+   *                     buffer in which to serialize data.  As output, the
+   *                     position just passed the serialized data.
+   *\param count_out     Output: The required buffer size, in bytes.
+   *\param store_handles The data for each tag is preceeded by a list of 
+   *                     EntityHandles designating the entity each of
+   *                     the subsequent tag values corresponds to.  This value
+   *                     may be one of:
+   *                     1) If store_handles == false:
+   *                        An invalid handle composed of {MBMAXTYPE,idx}, where
+   *                        idx is the position of the entity in "whole_range".
+   *                     2) If store_hanldes == true and a valid remote
+   *                        handle exists, the remote handle.
+   *                     3) If store_hanldes == true and no valid remote 
+   *                        handle is defined for the entity, the same as 1).
+   *\param to_proc       If 'store_handles' is true, the processor rank for
+   *                     which to store the corresponding remote entity 
+   *                     handles.
+   */
+  ErrorCode pack_tag( Tag source_tag,
+                        Tag destination_tag,
+                        const Range &entities,
+                        const Range &whole_range,
+                        Buffer *buff,
+                        const bool store_remote_handles,
+                        const int to_proc );
+
+  ErrorCode unpack_tags(unsigned char *&buff_ptr,
+                          Range &entities,
+                          const bool store_handles,
+                          const int to_proc);
+  
+  ErrorCode tag_shared_verts(tuple_list &shared_verts,
+                               Range *skin_ents,
+                               std::map<std::vector<int>, Range> &proc_nranges,
+                               Range &proc_verts);
+  
+  ErrorCode tag_shared_ents(int resolve_dim,
+                              int shared_dim,
+                              Range *skin_ents,
+                              std::map<std::vector<int>, Range> &proc_nranges);
+
+    // each iterate in proc_nranges contains a set of procs and the entities *possibly*
+    // on the interface between those procs; this function makes sets for each,
+    // and tags the set with the procs sharing it; interface sets are optionally
+    // returned; NOTE: a subsequent step is used to verify entities on the interface
+    // and remove them if they're not shared
+  ErrorCode create_interface_sets(std::map<std::vector<int>, Range> &proc_nranges,
+                                    int resolve_dim, int shared_dim);
+
+    // do the same but working straight from sharedEnts
+  ErrorCode create_interface_sets(int resolve_dim, int shared_dim);
+
+    // after verifying shared entities, now parent/child links between sets can be established
+  ErrorCode create_iface_pc_links();
+  
+    //! pack a range map with keys in this_range and values a contiguous series
+    //! of handles starting at actual_start
+  ErrorCode pack_range_map(Range &this_range, EntityHandle actual_start,
+                             HandleMap &handle_map);
+
+    //! returns true if the set is an interface shared with to_proc
+  bool is_iface_proc(EntityHandle this_set, int to_proc);
+  
+    //! for any remote_handles set to zero, remove corresponding sent_ents from
+    //! iface_sets corresponding to from_proc
+  ErrorCode update_iface_sets(Range &sent_ents,
+                                std::vector<EntityHandle> &remote_handles, 
+                                int from_proc);
+  
+    //! for specified bridge/ghost dimension, to_proc, and number
+    //! of layers, get the entities to be ghosted, and info on additional procs
+    //! needing to communicate with to_proc
+  ErrorCode get_ghosted_entities(int bridge_dim,
+                                   int ghost_dim,
+                                   int to_proc, 
+                                   int num_layers,
+                                   Range &ghosted_ents);
+  
+    //! add vertices adjacent to entities in this list
+  ErrorCode add_verts(Range &sent_ents);
+  
+  //! Every processor sends shared entity handle data to every other processor
+  //! that it shares entities with.  Passed back map is all received data,
+  //! indexed by processor ID. This function is intended to be used for 
+  //! debugging.
+  ErrorCode exchange_all_shared_handles(  
+      std::vector<std::vector<SharedEntityData> > &send_data, 
+      std::vector<std::vector<SharedEntityData> > &result);
+  
+    //! replace handles in from_vec with corresponding handles on
+    //! to_proc (by checking shared[p/h]_tag and shared[p/h]s_tag;
+    //! if no remote handle and new_ents is non-null, substitute
+    //! instead CREATE_HANDLE(MBMAXTYPE, index) where index is handle's
+    //! position in new_ents
+  ErrorCode get_remote_handles(const bool store_remote_handles,
+                                 EntityHandle *from_vec, 
+                                 EntityHandle *to_vec_tmp,
+                                 int num_ents, int to_proc,
+                                 const Range &new_ents);
+  
+    //! same as other version, except from_range and to_range should be
+    //! different here
+  ErrorCode get_remote_handles(const bool store_remote_handles,
+                                 const Range &from_range, 
+                                 Range &to_range,
+                                 int to_proc,
+                                 const Range &new_ents);
+  
+    //! same as other version, except packs range into vector
+  ErrorCode get_remote_handles(const bool store_remote_handles,
+                                 const Range &from_range, 
+                                 EntityHandle *to_vec,
+                                 int to_proc,
+                                 const Range &new_ents);
+
+  std::vector<unsigned int> &buff_procs();
+
+    //! goes through from_vec, and for any with type MBMAXTYPE, replaces with
+    //! new_ents value at index corresponding to id of entity in from_vec
+  ErrorCode get_local_handles(EntityHandle *from_vec, 
+                                int num_ents,
+                                const Range &new_ents);
+
+    //! same as above except puts results in range
+  ErrorCode get_local_handles(const Range &remote_handles,
+                                Range &local_handles,
+                                const Range &new_ents);
+  
+    //! same as above except gets new_ents from vector
+  ErrorCode get_local_handles(EntityHandle *from_vec,
+                                int num_ents,
+                                const std::vector<EntityHandle> &new_ents);
+  
+  ErrorCode update_remote_data(Range &local_range,
+                                 Range &remote_range,
+                                 int other_proc,
+                                 const unsigned char add_pstat);
+  
+  ErrorCode update_remote_data(const EntityHandle new_h,
+                                 const int *ps,
+                                 const EntityHandle *hs,
+                                 const int num_ps,
+                                 const unsigned char add_pstat);
+  
+    /** \brief Set pstatus tag interface bit on entities in sets passed in
+     */
+  ErrorCode tag_iface_entities();
+
+    //! add a pc to the iface instance tag PARALLEL_COMM
+  int add_pcomm(ParallelComm *pc);
+  
+    //! remove a pc from the iface instance tag PARALLEL_COMM
+  void remove_pcomm(ParallelComm *pc);
+  
+    //! check entities to make sure there are no zero-valued remote handles
+    //! where they shouldn't be
+  ErrorCode check_sent_ents(Range &allsent);
+
+    //! MB interface associated with this writer
+  Interface *mbImpl;
+
+    //! Proc config object, keeps info on parallel stuff
+  ProcConfig procConfig;
+  
+    //! Tag server, so we can get more info about tags
+  TagServer *tagServer;
+  
+    //! Sequence manager, to get more efficient access to entities
+  SequenceManager *sequenceManager;
+  
+    //! more data buffers, proc-specific
+  std::vector<Buffer*> localOwnedBuffs, remoteOwnedBuffs;
+
+    //! reset message buffers to their initial state
+  void reset_all_buffers();
+
+    //! delete all buffers, freeing up any memory held by them
+  void delete_all_buffers();
+
+    //! request objects, may be used if store_remote_handles is used
+  std::vector<MPI_Request> sendReqs;
+
+    //! processor rank for each buffer index
+  std::vector<unsigned int> buffProcs;
+
+    //! the partition, interface sets for this comm'n instance
+  Range partitionSets, interfaceSets;
+
+    //! all local entities shared with others, whether ghost or ghosted
+  Range sharedEnts;
+  
+    //! tags used to save sharing procs and handles
+  Tag sharedpTag, sharedpsTag, sharedhTag, sharedhsTag, pstatusTag, 
+      ifaceSetsTag, partitionTag;
+    
+  int globalPartCount; //!< Cache of global part count
+  
+  EntityHandle partitioningSet; //!< entity set containing all parts
+
+  std::ofstream myFile;
+  
+  int pcommID;
+
+};
+
+inline ParallelComm::Buffer::Buffer(const Buffer &other_buff) 
+{
+  alloc_size = other_buff.alloc_size;
+  mem_ptr = (unsigned char *)malloc(alloc_size);
+  memcpy(mem_ptr, other_buff.mem_ptr, alloc_size);
+  buff_ptr = mem_ptr + (other_buff.buff_ptr - other_buff.mem_ptr);
+}
+
+inline ParallelComm::Buffer::Buffer(unsigned int new_size) 
+        : mem_ptr(NULL), buff_ptr(NULL), alloc_size(0)
+{
+  if (new_size) this->reserve(new_size);
+}
+
+inline ParallelComm::Buffer::~Buffer() 
+{
+  if (mem_ptr) {
+    free(mem_ptr);
+    mem_ptr = NULL;
+  }
+}
+
+#define DEBUG_BUFFER 1
+
+inline void ParallelComm::Buffer::reserve(unsigned int new_size) {
+  
+#ifdef DEBUG_BUFFER
+  int tmp_pos = 0;
+  if (mem_ptr) {
+    tmp_pos = buff_ptr - mem_ptr;
+  }
+  buff_ptr = (unsigned char *)malloc(new_size);
+  assert(0 <= tmp_pos && tmp_pos <= (int)alloc_size);  
+  if (tmp_pos) memcpy(buff_ptr, mem_ptr, tmp_pos);
+  if (mem_ptr) free(mem_ptr);
+  mem_ptr = buff_ptr;
+  alloc_size = new_size;
+  buff_ptr = mem_ptr + tmp_pos;
+#else    
+  if (mem_ptr && alloc_size < new_size) {
+    size_t tmp_pos = mem_ptr ? buff_ptr - mem_ptr : 0;
+    mem_ptr = (unsigned char *)realloc(mem_ptr, new_size);
+    alloc_size = new_size;
+    buff_ptr = mem_ptr + tmp_pos;
+  }
+  else if (!mem_ptr) {
+    mem_ptr = (unsigned char *)malloc(new_size);
+    alloc_size = new_size;
+    buff_ptr = mem_ptr;
+  } 
+#endif
+}
+
+inline void ParallelComm::Buffer::check_space(unsigned int addl_space )
+{
+  assert(buff_ptr >= mem_ptr && buff_ptr <= mem_ptr+alloc_size);
+  unsigned int new_size = buff_ptr - mem_ptr + addl_space;
+  if (new_size > alloc_size) 
+    reserve(1.5*new_size);
+}
+
+inline void ParallelComm::reset_all_buffers() 
+{
+  std::vector<Buffer*>::iterator vit;
+  for (vit = localOwnedBuffs.begin(); vit != localOwnedBuffs.end(); vit++)
+    (*vit)->reset_buffer();
+  for (vit = remoteOwnedBuffs.begin(); vit != remoteOwnedBuffs.end(); vit++)
+    (*vit)->reset_buffer();
+}
+
+inline void ParallelComm::delete_all_buffers() 
+{
+  std::vector<Buffer*>::iterator vit;
+  for (vit = localOwnedBuffs.begin(); vit != localOwnedBuffs.end(); vit++)
+    delete (*vit);
+  localOwnedBuffs.clear();
+  
+  for (vit = remoteOwnedBuffs.begin(); vit != remoteOwnedBuffs.end(); vit++)
+    delete (*vit);
+  remoteOwnedBuffs.clear();
+}
+
+inline std::vector<unsigned int> &ParallelComm::buff_procs() 
+{
+  return buffProcs;
+}
+
+inline ErrorCode ParallelComm::get_shared_proc_tags(Tag &sharedp,
+                                                        Tag &sharedps,
+                                                        Tag &sharedh,
+                                                        Tag &sharedhs,
+                                                        Tag &pstatus) 
+{
+  sharedp = sharedp_tag();
+  sharedps = sharedps_tag();
+  sharedh = sharedh_tag();
+  sharedhs = sharedhs_tag();
+  pstatus = pstatus_tag();
+  
+  return MB_SUCCESS;
+}
+
+inline ErrorCode ParallelComm::exchange_tags(const char *tag_name,
+                                                 Range &entities)
+{
+    // get the tag handle
+  std::vector<Tag> tags(1);
+  ErrorCode result = mbImpl->tag_get_handle(tag_name, tags[0]);
+  if (MB_SUCCESS != result) return result;
+  else if (!tags[0]) return MB_TAG_NOT_FOUND;
+  
+  return exchange_tags(tags, tags, entities);
+}
+  
+inline ErrorCode ParallelComm::exchange_tags(Tag tagh,
+                                                 Range &entities)
+{
+    // get the tag handle
+  std::vector<Tag> tags;
+  tags.push_back(tagh);
+  
+  return exchange_tags(tags, tags, entities);
+}
+  
+inline ErrorCode ParallelComm::get_comm_procs(std::set<unsigned int> &procs) 
+{
+  ErrorCode result = get_interface_procs(procs);
+  if (MB_SUCCESS != result) return result;
+
+  std::copy(buffProcs.begin(), buffProcs.end(), std::inserter(procs, procs.begin()));
+    
+  return MB_SUCCESS;
+}
+
+inline ErrorCode ParallelComm::get_owner(EntityHandle entity,
+                                             int &owner) 
+{
+  EntityHandle tmp_handle;
+  return get_owner_handle(entity, owner, tmp_handle);
+}
+
+    /* \brief Unpack message with remote handles (const pointer to buffer)
+     */
+inline ErrorCode ParallelComm::unpack_remote_handles(unsigned int from_proc,
+                                                         const unsigned char *buff_ptr,
+                                                         std::vector<EntityHandle> &L2hloc,
+                                                         std::vector<EntityHandle> &L2hrem,
+                                                         std::vector<unsigned int> &L2p) 
+{
+    // cast away const-ness, we won't be passing back a modified ptr
+  unsigned char *tmp_buff = const_cast<unsigned char*>(buff_ptr);
+  return unpack_remote_handles(from_proc, tmp_buff, L2hloc, L2hrem, L2p);
+}
+
+inline void ParallelComm::set_rank(unsigned int r) 
+{
+  procConfig.proc_rank(r);
+  if (procConfig.proc_size() < r) procConfig.proc_size(r+1);
+}
+
+inline void ParallelComm::set_size(unsigned int s) 
+{
+  procConfig.proc_size(s);
+}
+
+inline ErrorCode ParallelComm::get_sharing_data(const EntityHandle *entities,
+                                                    int num_entities,
+                                                    std::set<int> &procs,
+                                                    int op) 
+{
+  Range dum_range;
+    // cast away constness 'cuz the range is passed as const
+  EntityHandle *ents_cast = const_cast<EntityHandle*>(entities);
+  std::copy(ents_cast, ents_cast+num_entities, range_inserter(dum_range));
+  return get_sharing_data(dum_range, procs, op);
+}
+
+inline ErrorCode ParallelComm::get_sharing_data(const EntityHandle entity,
+                                                    int *ps, 
+                                                    EntityHandle *hs,
+                                                    unsigned char &pstat,
+                                                    int &num_ps) 
+{
+  unsigned int dum_ps;
+  ErrorCode result = get_sharing_data(entity, ps, hs, pstat, dum_ps);
+  if (MB_SUCCESS == result)
+    num_ps = dum_ps;
+  return result;
+}
+
+} // namespace moab
+  
+#endif

Copied: MOAB/trunk/src/parallel/moab/ParallelData.hpp (from rev 3583, MOAB/trunk/src/parallel/moab/MBParallelData.hpp)
===================================================================
--- MOAB/trunk/src/parallel/moab/ParallelData.hpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/moab/ParallelData.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,59 @@
+/**
+ * \class ParallelData
+ * \brief Parallel data in MOAB
+ * \author Tim Tautges
+ *
+ *  This class implements methods to retrieve information about 
+ * the parallel mesh from MOAB.  Most of this data can be retrieved
+ * directly from MOAB as sets and tags; this class provides convenience
+ * methods implemented on top of other MOAB functions.
+ *
+ */
+
+#ifndef MOAB_PARALLEL_DATA_HPP
+#define MOAB_PARALLEL_DATA_HPP
+
+#include "moab/Forward.hpp"
+#include "moab/Range.hpp"
+
+namespace moab {
+
+class ParallelComm;
+
+class ParallelData
+{
+public:
+
+    //! constructor; if non-null parallelcomm, that is used to
+    //! determine rank, otherwise rank is taken from impl
+  ParallelData(Interface *impl, ParallelComm *pcomm = NULL);
+
+    //! return partition sets; if tag_name is input, gets sets with
+    //! that tag name, otherwise uses PARALLEL_PARTITION tag
+  ErrorCode get_partition_sets(Range &part_sets,
+                                 const char *tag_name = NULL);
+
+    //! get communication interface sets and the processors with which
+    //! this processor communicates; sets are sorted by processor
+  ErrorCode get_interface_sets(std::vector<EntityHandle> &iface_sets,
+                                 std::vector<int> &iface_procs);
+  
+
+private:
+
+    //! interface instance to which this instance corresponds
+  Interface *mbImpl;
+
+    //! ParallelComm object to which this is bound
+  ParallelComm *parallelComm;
+  
+};
+
+inline ParallelData::ParallelData(Interface *impl, 
+                                      ParallelComm *pcomm) 
+    : mbImpl(impl), parallelComm(pcomm) 
+{}
+
+};
+
+#endif

Copied: MOAB/trunk/src/parallel/moab/ProcConfig.hpp (from rev 3583, MOAB/trunk/src/parallel/moab/MBProcConfig.hpp)
===================================================================
--- MOAB/trunk/src/parallel/moab/ProcConfig.hpp	                        (rev 0)
+++ MOAB/trunk/src/parallel/moab/ProcConfig.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,80 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#ifndef MOAB_PROC_CONFIG_HPP
+#define MOAB_PROC_CONFIG_HPP
+
+#include "moab/Types.hpp"
+#include "moab/Range.hpp"
+
+#ifdef USE_MPI
+#  include "moab_mpi.h"
+#else
+  typedef int MPI_Comm;
+# define MPI_COMM_WORLD 0
+#endif
+
+struct crystal_data;
+
+namespace moab {
+
+class Interface;
+
+/**\brief Multi-CPU information for parallel MOAB */
+class ProcConfig {
+public:
+
+  ProcConfig(MPI_Comm proc_comm = MPI_COMM_WORLD);
+  
+  ~ProcConfig();
+  
+    //! Get the current processor number
+  unsigned proc_rank() const 
+    { return procRank; }
+      
+    //! Get the number of processors
+  unsigned proc_size() const 
+    { return procSize; }
+      
+    //! get a crystal router for this parallel job
+  crystal_data *crystal_router(bool construct_if_missing = true);
+
+    //! get/set the communicator for this proc config
+  MPI_Comm proc_comm() const {return procComm;}
+  void proc_comm(MPI_Comm this_comm) {procComm = this_comm;}
+
+    //! set rank/size; USED FOR TESTING ONLY!
+  void proc_rank(unsigned r) {procRank = r;}
+  void proc_size(unsigned s) {procSize = s;}
+
+private:
+
+    //! MPI communicator set for this instance
+  MPI_Comm procComm;
+
+    //! rank of this processor
+  unsigned procRank;
+  
+    //! number of processors
+  unsigned procSize;
+  
+    //! crystal router for this parallel job
+  crystal_data* crystalData;
+  
+};
+
+} // namespace moab
+
+#endif

Copied: MOAB/trunk/src/parallel/moab_mpi.h (from rev 3583, MOAB/trunk/src/parallel/moab/MBmpi.h)
===================================================================
--- MOAB/trunk/src/parallel/moab_mpi.h	                        (rev 0)
+++ MOAB/trunk/src/parallel/moab_mpi.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,48 @@
+#ifndef MOAB_MPI_H
+#define MOAB_MPI_H
+#include "moab_mpi_config.h"
+
+#ifndef __cplusplus
+#  include <mpi.h>
+#elif !defined(MB_MPI_CXX_CONFLICT)
+#  ifndef MPICH_IGNORE_CXX_SEEK
+#    define MPICH_IGNORE_CXX_SEEK
+#  endif
+#  include <mpi.h>
+#else
+#  include <stdio.h>
+#  ifdef SEEK_SET
+#    undef SEEK_SET
+#    ifdef MB_SEEK_SET
+#      define MB_RESTORE_SEEK_SET
+#    endif
+#  endif
+#  ifdef SEEK_CUR
+#    undef SEEK_CUR
+#    ifdef MB_SEEK_CUR
+#      define MB_RESTORE_SEEK_CUR
+#    endif
+#  endif
+#  ifdef SEEK_END
+#    undef SEEK_END
+#    ifdef MB_SEEK_END
+#      define MB_RESTORE_SEEK_END
+#    endif
+#  endif
+#  include <mpi.h>
+#  ifdef MB_RESTORE_SEEK_SET
+#    undef MB_RESTORE_SEEK_SET
+#    define SEEK_SET MB_SEEK_SET
+#  endif
+#  ifdef MB_RESTORE_SEEK_CUR
+#    undef MB_RESTORE_SEEK_CUR
+#    define SEEK_CUR MB_SEEK_CUR
+#  endif
+#  ifdef MB_RESTORE_SEEK_END
+#    undef MB_RESTORE_SEEK_END
+#    define SEEK_END MB_SEEK_END
+#  endif
+#endif
+
+
+#endif

Copied: MOAB/trunk/src/parallel/moab_mpi_config.h.in (from rev 3583, MOAB/trunk/src/parallel/moab/MBmpi_config.h.in)
===================================================================
--- MOAB/trunk/src/parallel/moab_mpi_config.h.in	                        (rev 0)
+++ MOAB/trunk/src/parallel/moab_mpi_config.h.in	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,11 @@
+/* MPICH_IGNORE_CXX_SEEK is not sufficient to avoid conflicts */
+#undef MB_MPI_CXX_CONFLICT
+
+/* "Value of C SEEK_CUR" */
+#undef MB_SEEK_CUR
+
+/* "Value of C SEEK_END" */
+#undef MB_SEEK_END
+
+/* "Value of C SEEK_SET" */
+#undef MB_SEEK_SET

Modified: MOAB/trunk/src/parallel/transfer.c
===================================================================
--- MOAB/trunk/src/parallel/transfer.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/src/parallel/transfer.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <math.h>
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include "errmem.h"
 #include "types.h"
 #include "minmax.h"

Modified: MOAB/trunk/test/CMakeLists.txt
===================================================================
--- MOAB/trunk/test/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,10 +5,6 @@
     ${MOAB_BINARY_DIR}/src
     ${MOAB_SOURCE_DIR}/src/parallel
     ${MOAB_BINARY_DIR}/src/parallel
-    ${MOAB_SOURCE_DIR}/src/moab
-    ${MOAB_BINARY_DIR}/src/moab
-    ${MOAB_SOURCE_DIR}/src/parallel/moab
-    ${MOAB_BINARY_DIR}/src/parallel/moab
   )
 
   add_executable( moab_test MBTest.cpp )
@@ -34,12 +30,6 @@
   target_link_libraries( scdseq_test MOAB )
   add_test( TestSCDSeq ${EXECUTABLE_OUTPUT_PATH}/scdseq_test )
 
-  add_executable( tqdcfr ${MOAB_SOURCE_DIR}/src/io/Tqdcfr.cpp )
-  set_source_files_properties( ${MOAB_SOURCE_DIR}/src/io/Tqdcfr.cpp
-    COMPILE_FLAGS "-DTEST_TQDCFR -DIS_BUILDING_MB ${MOAB_DEFINES}" )
-  target_link_libraries( tqdcfr MOAB )
-  add_test( TestTQDCFR ${EXECUTABLE_OUTPUT_PATH}/tqdcfr )
-
   add_executable( bsp_tree_test bsp_tree_test.cpp )
   set_source_files_properties( bsp_tree_test.cpp
     COMPILE_FLAGS "-DTEST ${MOAB_DEFINES}" )

Modified: MOAB/trunk/test/GeomUtilTests.cpp
===================================================================
--- MOAB/trunk/test/GeomUtilTests.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/GeomUtilTests.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,8 @@
-#include "MBCore.hpp"
-#include "MBGeomUtil.hpp"
+#include "moab/Core.hpp"
+#include "moab/GeomUtil.hpp"
 
-using namespace MBGeomUtil;
+using namespace moab;
+using namespace moab::GeomUtil;
 
 #include <iostream>
 
@@ -12,7 +13,7 @@
 #define ASSERT(B) CHECK(B)
 
 
-void assert_vectors_equal( const MBCartVect& a, const MBCartVect& b, 
+void assert_vectors_equal( const CartVect& a, const CartVect& b, 
                            const char* sa, const char* sb,
                            int lineno )
 {
@@ -27,20 +28,20 @@
   }
 }
 
-void test_box_plane_norm( MBCartVect norm, 
-                          MBCartVect min,
-                          MBCartVect max )
+void test_box_plane_norm( CartVect norm, 
+                          CartVect min,
+                          CartVect max )
 {
-  MBCartVect c_lower = min;
-  MBCartVect c_upper = max;
+  CartVect c_lower = min;
+  CartVect c_upper = max;
   for (int i = 0; i < 3; ++i)
     if (norm[i] < 0.0)
       std::swap(c_lower[i],c_upper[i]);
   
-  MBCartVect p_below = c_lower - norm;
-  MBCartVect p_lower = c_lower + norm;
-  MBCartVect p_upper = c_upper - norm;
-  MBCartVect p_above = c_upper + norm;
+  CartVect p_below = c_lower - norm;
+  CartVect p_lower = c_lower + norm;
+  CartVect p_upper = c_upper - norm;
+  CartVect p_above = c_upper + norm;
   
   double below = -(p_below % norm);
   double lower = -(p_lower % norm);
@@ -54,18 +55,18 @@
 }
 
 void test_box_plane_axis( int axis, double ns, 
-                          const MBCartVect& min, 
-                          const MBCartVect& max )
+                          const CartVect& min, 
+                          const CartVect& max )
 {
-  MBCartVect norm(0.0);
+  CartVect norm(0.0);
   norm[axis] = ns;
   test_box_plane_norm( norm, min, max );
 }
 
 void test_box_plane_edge( int axis1, int axis2, bool flip_axis2,
-                          MBCartVect min, MBCartVect max )
+                          CartVect min, CartVect max )
 {
-  MBCartVect norm(0.0);
+  CartVect norm(0.0);
   norm[axis1] = max[axis1] - min[axis1];
   if (flip_axis2)
     norm[axis2] = min[axis2] - max[axis2];
@@ -77,9 +78,9 @@
 }
 
 void test_box_plane_corner( int xdir, int ydir, int zdir, 
-                            MBCartVect min, MBCartVect max )
+                            CartVect min, CartVect max )
 {
-  MBCartVect norm(max - min);
+  CartVect norm(max - min);
   norm[0] *= xdir;
   norm[1] *= ydir;
   norm[2] *= zdir;
@@ -88,8 +89,8 @@
 
 void test_box_plane_overlap()
 {
-  const MBCartVect min( -1, -2, -3 );
-  const MBCartVect max(  6,  4,  2 );
+  const CartVect min( -1, -2, -3 );
+  const CartVect max(  6,  4,  2 );
   
     // test with planes orthogonal to Z axis
   test_box_plane_axis( 2, 2.0, min, max );
@@ -117,41 +118,41 @@
 class ElemOverlapTest {
   public:
   
-    virtual bool operator()( const MBCartVect* coords, 
-                             const MBCartVect& box_center, 
-                             const MBCartVect& box_dims ) const = 0;
+    virtual bool operator()( const CartVect* coords, 
+                             const CartVect& box_center, 
+                             const CartVect& box_dims ) const = 0;
 };
 class LinearElemOverlapTest : public ElemOverlapTest {
   public:
-    const MBEntityType type;
-    LinearElemOverlapTest(MBEntityType t) : type(t) {}
-    bool operator()( const MBCartVect* coords, 
-                     const MBCartVect& box_center, 
-                     const MBCartVect& box_dims ) const
+    const EntityType type;
+    LinearElemOverlapTest(EntityType t) : type(t) {}
+    bool operator()( const CartVect* coords, 
+                     const CartVect& box_center, 
+                     const CartVect& box_dims ) const
       { return box_linear_elem_overlap( coords, type, box_center, box_dims ); }
 };
 class TypeElemOverlapTest : public ElemOverlapTest {
   public:
-    bool (*func)( const MBCartVect*, const MBCartVect&, const MBCartVect& );
-    TypeElemOverlapTest( bool (*f)( const MBCartVect*, const MBCartVect&, const MBCartVect& ) )
+    bool (*func)( const CartVect*, const CartVect&, const CartVect& );
+    TypeElemOverlapTest( bool (*f)( const CartVect*, const CartVect&, const CartVect& ) )
       : func(f){}
-    bool operator()( const MBCartVect* coords, 
-                     const MBCartVect& box_center, 
-                     const MBCartVect& box_dims ) const
+    bool operator()( const CartVect* coords, 
+                     const CartVect& box_center, 
+                     const CartVect& box_dims ) const
       { return (*func)( coords, box_center, box_dims ); }
 };    
 
 void general_box_tri_overlap_test( const ElemOverlapTest& overlap )
 {
-  MBCartVect coords[3];
-  MBCartVect center, dims;
+  CartVect coords[3];
+  CartVect center, dims;
   
     // test box projection within triangle, z-plane
-  coords[0] = MBCartVect( 0, 0, 0 );
-  coords[1] = MBCartVect( 0, 4, 0 );
-  coords[2] = MBCartVect(-4, 0, 0 );
-  center = MBCartVect( -2, 1, 0 );
-  dims = MBCartVect( 1, 0.5, 3 );
+  coords[0] = CartVect( 0, 0, 0 );
+  coords[1] = CartVect( 0, 4, 0 );
+  coords[2] = CartVect(-4, 0, 0 );
+  center = CartVect( -2, 1, 0 );
+  dims = CartVect( 1, 0.5, 3 );
   ASSERT(  overlap( coords, center, dims ) );
     // move box below plane of triangle
   center[2] = -4;
@@ -161,11 +162,11 @@
   ASSERT( !overlap( coords, center, dims ) );
   
     // test box projection within triangle, x-plane
-  coords[0] = MBCartVect( 3, 3, 0 );
-  coords[1] = MBCartVect( 3, 3, 1 );
-  coords[2] = MBCartVect( 3, 0, 0 );
-  center = MBCartVect( 3, 2.5, .25 );
-  dims = MBCartVect( 0.001, 0.4, .2 );
+  coords[0] = CartVect( 3, 3, 0 );
+  coords[1] = CartVect( 3, 3, 1 );
+  coords[2] = CartVect( 3, 0, 0 );
+  center = CartVect( 3, 2.5, .25 );
+  dims = CartVect( 0.001, 0.4, .2 );
   ASSERT(  overlap( coords, center, dims ) );
     // move box below plane of triangle
   center[0] = 2;
@@ -175,568 +176,568 @@
   ASSERT( !overlap( coords, center, dims ) );
   
     // test tri slices corner at +x,+y,+z
-  coords[0] = MBCartVect(3,1,1);
-  coords[1] = MBCartVect(1,3,1);
-  coords[2] = MBCartVect(1,1,3);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect(3,1,1);
+  coords[1] = CartVect(1,3,1);
+  coords[2] = CartVect(1,1,3);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !overlap( coords, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0,0,0), CartVect(1,1,1) ) );
     // test tri slices corner at -x,-y,-z
-  coords[0] = MBCartVect(-1,1,1);
-  coords[1] = MBCartVect(1,-1,1);
-  coords[2] = MBCartVect(1,1,-1);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect(-1,1,1);
+  coords[1] = CartVect(1,-1,1);
+  coords[2] = CartVect(1,1,-1);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri below the corner
-  ASSERT( !overlap( coords, MBCartVect(2,2,2),MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2,2,2),CartVect(1,1,1) ) );
   
     // test tri slices corner at -x,+y,+z
-  coords[0] = MBCartVect( 0.5, 0.0, 2.5);
-  coords[1] = MBCartVect( 0.5, 2.5, 0.0);
-  coords[2] = MBCartVect(-0.5, 0.0, 0.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 0.5, 0.0, 2.5);
+  coords[1] = CartVect( 0.5, 2.5, 0.0);
+  coords[2] = CartVect(-0.5, 0.0, 0.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !overlap( coords, MBCartVect(2,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2,1,1), CartVect(1,1,1) ) );
   
     // test tri slices corner at +x,-y,-z
-  coords[0] = MBCartVect( 0.5, 0.0,-1.5);
-  coords[1] = MBCartVect( 0.5,-1.5, 0.0);
-  coords[2] = MBCartVect( 1.5, 0.0, 0.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 0.5, 0.0,-1.5);
+  coords[1] = CartVect( 0.5,-1.5, 0.0);
+  coords[2] = CartVect( 1.5, 0.0, 0.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !overlap( coords, MBCartVect(0,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0,1,1), CartVect(1,1,1) ) );
 
     // test tri slices corner at +x,-y,+z
-  coords[0] = MBCartVect( 1.0, 1.0, 2.5 );
-  coords[1] = MBCartVect( 2.5, 1.0, 1.0 );
-  coords[2] = MBCartVect( 1.0,-0.5, 1.0 );
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0, 2.5 );
+  coords[1] = CartVect( 2.5, 1.0, 1.0 );
+  coords[2] = CartVect( 1.0,-0.5, 1.0 );
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !overlap( coords, MBCartVect(-1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(-1,1,1), CartVect(1,1,1) ) );
 
     // test tri slices corner at -x,+y,-z  
-  coords[0] = MBCartVect( 1.0,  1.0,-0.5 );
-  coords[1] = MBCartVect(-0.5,  1.0, 1.0 );
-  coords[2] = MBCartVect( 1.0,  2.5, 1.0 );
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0,  1.0,-0.5 );
+  coords[1] = CartVect(-0.5,  1.0, 1.0 );
+  coords[2] = CartVect( 1.0,  2.5, 1.0 );
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !overlap( coords, MBCartVect(3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(3,1,1), CartVect(1,1,1) ) );
 
     // test tri slices corner at +x,+y,-z
-  coords[0] = MBCartVect(-0.1, 1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-0.1, 1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-0.1);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect(-0.1, 1.0, 1.0);
+  coords[1] = CartVect( 1.0,-0.1, 1.0);
+  coords[2] = CartVect( 1.0, 1.0,-0.1);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,3), CartVect(1,1,1) ) );
   
     // test tri slices corner at -x,-y,+z
-  coords[0] = MBCartVect( 2.1, 1.0, 1.0);
-  coords[1] = MBCartVect( 1.0, 2.1, 1.0);
-  coords[2] = MBCartVect( 1.0, 1.0, 2.1);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 2.1, 1.0, 1.0);
+  coords[1] = CartVect( 1.0, 2.1, 1.0);
+  coords[2] = CartVect( 1.0, 1.0, 2.1);
+  ASSERT(  box_tri_overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,-1), CartVect(1,1,1) ) );
   
     // box edge parallel to x at +y,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect( 1.0, 3.0, 3.0);
-  coords[2] = MBCartVect( 1.0, 3.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0, 3.0);
+  coords[1] = CartVect( 1.0, 3.0, 3.0);
+  coords[2] = CartVect( 1.0, 3.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,0.3), CartVect(1,1,1) ) );
   
     // box edge parallel to x at +y,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect( 1.0, 3.0,-1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 3.0, 1.0);
+  coords[1] = CartVect( 1.0, 3.0,-1.0);
+  coords[2] = CartVect( 1.0, 1.0,-1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,1.7), CartVect(1,1,1) ) );
   
     // box edge parallel to x at -y,-z passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-1.0,-1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0,-1.0, 1.0);
+  coords[1] = CartVect( 1.0,-1.0,-1.0);
+  coords[2] = CartVect( 1.0, 1.0,-1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,1.7), CartVect(1,1,1) ) );
   
     // box edge parallel to x at -y,+z passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-1.0, 3.0);
-  coords[2] = MBCartVect( 1.0, 1.0, 3.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0,-1.0, 1.0);
+  coords[1] = CartVect( 1.0,-1.0, 3.0);
+  coords[2] = CartVect( 1.0, 1.0, 3.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,0.3), CartVect(1,1,1) ) );
   
     // box edge parallel to y at +x,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect( 3.0, 1.0, 3.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0, 3.0);
+  coords[1] = CartVect( 3.0, 1.0, 3.0);
+  coords[2] = CartVect( 3.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,0.3), CartVect(1,1,1) ) );
   
     // box edge parallel to y at -x,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect(-1.0, 1.0, 3.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0, 3.0);
+  coords[1] = CartVect(-1.0, 1.0, 3.0);
+  coords[2] = CartVect(-1.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,0.3), CartVect(1,1,1) ) );
   
     // box edge parallel to y at +x,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0,-1.0);
-  coords[1] = MBCartVect( 3.0, 1.0,-1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0,-1.0);
+  coords[1] = CartVect( 3.0, 1.0,-1.0);
+  coords[2] = CartVect( 3.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,1.7), CartVect(1,1,1) ) );
   
     // box edge parallel to y at -x,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0,-1.0);
-  coords[1] = MBCartVect(-1.0, 1.0,-1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 1.0,-1.0);
+  coords[1] = CartVect(-1.0, 1.0,-1.0);
+  coords[2] = CartVect(-1.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1,1,1.7), CartVect(1,1,1) ) );
   
     // box edge parallel to z at +x,+y passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect( 3.0, 3.0, 1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 3.0, 1.0);
+  coords[1] = CartVect( 3.0, 3.0, 1.0);
+  coords[2] = CartVect( 3.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.3,1,1), CartVect(1,1,1) ) );
   
     // box edge parallel to z at +x,-y passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 3.0,-1.0, 1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0,-1.0, 1.0);
+  coords[1] = CartVect( 3.0,-1.0, 1.0);
+  coords[2] = CartVect( 3.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.3,1,1), CartVect(1,1,1) ) );
   
     // box edge parallel to z at -x,+y passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect(-1.0, 3.0, 1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0, 3.0, 1.0);
+  coords[1] = CartVect(-1.0, 3.0, 1.0);
+  coords[2] = CartVect(-1.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1.7,1,1), CartVect(1,1,1) ) );
   
     // box edge parallel to z at -x,-y passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect(-1.0,-1.0, 1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  coords[0] = CartVect( 1.0,-1.0, 1.0);
+  coords[1] = CartVect(-1.0,-1.0, 1.0);
+  coords[2] = CartVect(-1.0, 1.0, 1.0);
+  ASSERT(  overlap( coords, CartVect(1,1,1), CartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(1.7,1,1), CartVect(1,1,1) ) );
   
     // triangle penetrates +x face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 5.0, 3.0, 2.0 );
-  coords[2] = MBCartVect( 5.0, 1.0, 2.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect( 5.0, 3.0, 2.0 );
+  coords[2] = CartVect( 5.0, 1.0, 2.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(-1,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(-1,2,2), CartVect(2,2,2) ) );
   
     // triangle penetrates -x face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect(-1.0, 3.0, 2.0 );
-  coords[2] = MBCartVect(-1.0, 1.0, 2.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect(-1.0, 3.0, 2.0 );
+  coords[2] = CartVect(-1.0, 1.0, 2.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(5,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(5,2,2), CartVect(2,2,2) ) );
   
     // triangle penetrates +y face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 3.0, 5.0, 2.0 );
-  coords[2] = MBCartVect( 1.0, 5.0, 2.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect( 3.0, 5.0, 2.0 );
+  coords[2] = CartVect( 1.0, 5.0, 2.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(2,-1,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(2,-1,2), CartVect(2,2,2) ) );
   
     // triangle penetrates -y face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 3.0,-1.0, 2.0 );
-  coords[2] = MBCartVect( 1.0,-1.0, 2.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect( 3.0,-1.0, 2.0 );
+  coords[2] = CartVect( 1.0,-1.0, 2.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(2,5,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(2,5,2), CartVect(2,2,2) ) );
   
     // triangle penetrates +z face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 2.0, 3.0, 5.0 );
-  coords[2] = MBCartVect( 2.0, 1.0, 5.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect( 2.0, 3.0, 5.0 );
+  coords[2] = CartVect( 2.0, 1.0, 5.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(2,2,-1), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(2,2,-1), CartVect(2,2,2) ) );
   
     // triangle penetrates -z face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 2.0, 3.0,-1.0 );
-  coords[2] = MBCartVect( 2.0, 1.0,-1.0 );
-  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  coords[0] = CartVect( 2.0, 2.0, 2.0 );
+  coords[1] = CartVect( 2.0, 3.0,-1.0 );
+  coords[2] = CartVect( 2.0, 1.0,-1.0 );
+  ASSERT(  overlap( coords, CartVect(2,2,2), CartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !overlap( coords, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, CartVect(2,2,5), CartVect(2,2,2) ) );
 }
 
 void general_box_hex_overlap_test( const ElemOverlapTest& overlap )
 {
-  MBCartVect coords[8];
+  CartVect coords[8];
 
     // test against axis-aligned rectilinear hex
-  coords[0] = MBCartVect(-0.5,-0.5,-0.5);
-  coords[1] = MBCartVect( 0.5,-0.5,-0.5);
-  coords[2] = MBCartVect( 0.5, 0.5,-0.5);
-  coords[3] = MBCartVect(-0.5, 0.5,-0.5);
-  coords[4] = MBCartVect(-0.5,-0.5, 0.5);
-  coords[5] = MBCartVect( 0.5,-0.5, 0.5);
-  coords[6] = MBCartVect( 0.5, 0.5, 0.5);
-  coords[7] = MBCartVect(-0.5, 0.5, 0.5);
+  coords[0] = CartVect(-0.5,-0.5,-0.5);
+  coords[1] = CartVect( 0.5,-0.5,-0.5);
+  coords[2] = CartVect( 0.5, 0.5,-0.5);
+  coords[3] = CartVect(-0.5, 0.5,-0.5);
+  coords[4] = CartVect(-0.5,-0.5, 0.5);
+  coords[5] = CartVect( 0.5,-0.5, 0.5);
+  coords[6] = CartVect( 0.5, 0.5, 0.5);
+  coords[7] = CartVect(-0.5, 0.5, 0.5);
 
-  ASSERT( overlap( coords, MBCartVect( 0, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 0, 0), CartVect(1,1,1) ) );
 
-  ASSERT( overlap( coords, MBCartVect( 1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 0,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 0, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 0, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 0, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0,-1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 0,-1), CartVect(1,1,1) ) );
 
-  ASSERT( overlap( coords, MBCartVect( 1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1, 0), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 0, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 0, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 0,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 0,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0,-1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0,-1,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 0, 1,-1), CartVect(1,1,1) ) );
 
-  ASSERT( overlap( coords, MBCartVect( 1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect(-1,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( overlap( coords, MBCartVect( 1,-1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1, 1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1,-1), CartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1,-1), CartVect(1,1,1) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 0,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 0, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 0, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 0, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0,-3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 0,-3), CartVect(1,1,1) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3,-3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3,-3, 0), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 0, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 0, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 0,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 0,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0,-3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0,-3,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 3,-3), CartVect(1,1,1) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect(-3,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!overlap( coords, MBCartVect( 3,-3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3,-3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3,-3, 3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3, 3,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3, 3,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect(-3,-3,-3), CartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, CartVect( 3,-3,-3), CartVect(1,1,1) ) );
 
     // test against rectilinear hex rotated 45 degrees about z axis
   const double r = sqrt(2.0)/2.0;
-  coords[0] = MBCartVect( r, 0,-0.5);
-  coords[1] = MBCartVect( 0, r,-0.5);
-  coords[2] = MBCartVect(-r, 0,-0.5);
-  coords[3] = MBCartVect( 0,-r,-0.5);
-  coords[4] = MBCartVect( r, 0, 0.5);
-  coords[5] = MBCartVect( 0, r, 0.5);
-  coords[6] = MBCartVect(-r, 0, 0.5);
-  coords[7] = MBCartVect( 0,-r, 0.5);
+  coords[0] = CartVect( r, 0,-0.5);
+  coords[1] = CartVect( 0, r,-0.5);
+  coords[2] = CartVect(-r, 0,-0.5);
+  coords[3] = CartVect( 0,-r,-0.5);
+  coords[4] = CartVect( r, 0, 0.5);
+  coords[5] = CartVect( 0, r, 0.5);
+  coords[6] = CartVect(-r, 0, 0.5);
+  coords[7] = CartVect( 0,-r, 0.5);
 
-  ASSERT( overlap( coords, MBCartVect( 1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect( 0, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect( 0,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, CartVect( 1, 0, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, CartVect(-1, 0, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, CartVect( 0, 1, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, CartVect( 0,-1, 0 ), CartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect(-1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0,-1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 1, 0, 2 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect(-1, 0, 2 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 1, 2 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 0,-1, 2 ), CartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect(-2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0, 2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect( 0,-2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 2, 0, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect(-2, 0, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 0, 2, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 0,-2, 0 ), CartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 1, 1, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect(-1, 1, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect(-1,-1, 0 ), CartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, CartVect( 1,-1, 0 ), CartVect(0.5,0.5,0.5) ) );
 
-  ASSERT( overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1, 0 ), CartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1, 0 ), CartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1, 0 ), CartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1, 0 ), CartVect(0.75,0.75,0.5) ) );
 }
 
 void general_box_tet_overlap_test( const ElemOverlapTest& overlap )
 {
-  MBCartVect coords[4];
+  CartVect coords[4];
   
     // Octant I
-  coords[0] = MBCartVect(0,0,0);
-  coords[1] = MBCartVect(1,0,0);
-  coords[2] = MBCartVect(0,1,0);
-  coords[3] = MBCartVect(0,0,1);
+  coords[0] = CartVect(0,0,0);
+  coords[1] = CartVect(1,0,0);
+  coords[2] = CartVect(0,1,0);
+  coords[3] = CartVect(0,0,1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect(-1,-1,-1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1,-1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(0.2,0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(0.2,0.2,0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(0.5,0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(0.5,0.5,0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(0.5,0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(0.5,0.5,0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant II
-  coords[0] = MBCartVect(0,1,0);
-  coords[1] = MBCartVect(-1,0,0);
-  coords[2] = MBCartVect(0,0,0);
-  coords[3] = MBCartVect(0,0,1);
+  coords[0] = CartVect(0,1,0);
+  coords[1] = CartVect(-1,0,0);
+  coords[2] = CartVect(0,0,0);
+  coords[3] = CartVect(0,0,1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect( 1,-1,-1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1,-1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(-0.2,0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(-0.2,0.2,0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(-0.5,0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(-0.5,0.5,0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(-0.5,0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(-0.5,0.5,0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant III
-  coords[0] = MBCartVect(0,-1,0);
-  coords[1] = MBCartVect(0,0,0);
-  coords[2] = MBCartVect(-1,0,0);
-  coords[3] = MBCartVect(0,0,1);
+  coords[0] = CartVect(0,-1,0);
+  coords[1] = CartVect(0,0,0);
+  coords[2] = CartVect(-1,0,0);
+  coords[3] = CartVect(0,0,1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect( 1, 1,-1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1,-1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(-0.2,-0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(-0.2,-0.2,0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(-0.5,-0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(-0.5,-0.5,0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(-0.5,-0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(-0.5,-0.5,0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant IV
-  coords[0] = MBCartVect(1,0,0);
-  coords[1] = MBCartVect(0,-1,0);
-  coords[2] = MBCartVect(0,0,1);
-  coords[3] = MBCartVect(0,0,0);
+  coords[0] = CartVect(1,0,0);
+  coords[1] = CartVect(0,-1,0);
+  coords[2] = CartVect(0,0,1);
+  coords[3] = CartVect(0,0,0);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect(-1, 1,-1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1,-1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(0.2,-0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(0.2,-0.2,0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(0.5,-0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(0.5,-0.5,0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(0.5,-0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(0.5,-0.5,0.5), CartVect(0.15,0.15,0.15) ) );
    
     // Octant V
-  coords[0] = MBCartVect(0,0,0);
-  coords[1] = MBCartVect(0,1,0);
-  coords[2] = MBCartVect(1,0,0);
-  coords[3] = MBCartVect(0,0,-1);
+  coords[0] = CartVect(0,0,0);
+  coords[1] = CartVect(0,1,0);
+  coords[2] = CartVect(1,0,0);
+  coords[3] = CartVect(0,0,-1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect(-1,-1, 1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect(-1,-1, 1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(0.2,0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(0.2,0.2,-0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(0.5,0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(0.5,0.5,-0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(0.5,0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(0.5,0.5,-0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant VI
-  coords[0] = MBCartVect(-1,0,0);
-  coords[1] = MBCartVect(0,1,0);
-  coords[2] = MBCartVect(0,0,0);
-  coords[3] = MBCartVect(0,0,-1);
+  coords[0] = CartVect(-1,0,0);
+  coords[1] = CartVect(0,1,0);
+  coords[2] = CartVect(0,0,0);
+  coords[3] = CartVect(0,0,-1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect( 1,-1, 1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect( 1,-1, 1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(-0.2,0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(-0.2,0.2,-0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(-0.5,0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(-0.5,0.5,-0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(-0.5,0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(-0.5,0.5,-0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant VII
-  coords[0] = MBCartVect(0,0,0);
-  coords[1] = MBCartVect(0,-1,0);
-  coords[2] = MBCartVect(-1,0,0);
-  coords[3] = MBCartVect(0,0,-1);
+  coords[0] = CartVect(0,0,0);
+  coords[1] = CartVect(0,-1,0);
+  coords[2] = CartVect(-1,0,0);
+  coords[3] = CartVect(0,0,-1);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect( 1, 1, 1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect( 1, 1, 1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(-0.2,-0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(-0.2,-0.2,-0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(-0.5,-0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(-0.5,-0.5,-0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(-0.5,-0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(-0.5,-0.5,-0.5), CartVect(0.15,0.15,0.15) ) );
   
     // Octant VIII
-  coords[0] = MBCartVect(0,-1,0);
-  coords[1] = MBCartVect(1,0,0);
-  coords[2] = MBCartVect(0,0,-1);
-  coords[3] = MBCartVect(0,0,0);
+  coords[0] = CartVect(0,-1,0);
+  coords[1] = CartVect(1,0,0);
+  coords[2] = CartVect(0,0,-1);
+  coords[3] = CartVect(0,0,0);
     // tet entirely within box
-  ASSERT( overlap( coords, MBCartVect(-1, 1, 1), MBCartVect(3,3,3) ) );
+  ASSERT( overlap( coords, CartVect(-1, 1, 1), CartVect(3,3,3) ) );
     // box entirely within tet
-  ASSERT( overlap( coords, MBCartVect(0.2,-0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+  ASSERT( overlap( coords, CartVect(0.2,-0.2,-0.2), CartVect(0.1,0.1,0.1) ) );
     // box corner penetrates tet face
-  ASSERT( overlap( coords, MBCartVect(0.5,-0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+  ASSERT( overlap( coords, CartVect(0.5,-0.5,-0.5), CartVect(0.2,0.2,0.2) ) );
     // box corner does not penetrate face
-  ASSERT( !overlap( coords, MBCartVect(0.5,-0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  ASSERT( !overlap( coords, CartVect(0.5,-0.5,-0.5), CartVect(0.15,0.15,0.15) ) );
  
   
     // Box edge -x,-z
-  coords[0] = MBCartVect( 0, 0, 0);
-  coords[1] = MBCartVect( 2,-1, 0);
-  coords[2] = MBCartVect( 2, 1, 0);
-  coords[3] = MBCartVect( 0, 0, 2);
+  coords[0] = CartVect( 0, 0, 0);
+  coords[1] = CartVect( 2,-1, 0);
+  coords[2] = CartVect( 2, 1, 0);
+  coords[3] = CartVect( 0, 0, 2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(1.5,0.0,1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(1.5,0.0,1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(2.5,0.0,2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2.5,0.0,2.5), CartVect(1,1,1) ) );
   
     // Box edge -y,-z
-  coords[0] = MBCartVect( 1, 2, 0);
-  coords[1] = MBCartVect(-1, 2, 0);
-  coords[2] = MBCartVect( 0, 0, 0);
-  coords[3] = MBCartVect( 0, 0, 2);
+  coords[0] = CartVect( 1, 2, 0);
+  coords[1] = CartVect(-1, 2, 0);
+  coords[2] = CartVect( 0, 0, 0);
+  coords[3] = CartVect( 0, 0, 2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(0.0,1.5,1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(0.0,1.5,1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(0.0,2.5,2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.0,2.5,2.5), CartVect(1,1,1) ) );
   
     // Box edge +x,-z
-  coords[0] = MBCartVect(-2,-1, 0);
-  coords[1] = MBCartVect(-2, 1, 0);
-  coords[2] = MBCartVect( 0, 0, 2);
-  coords[3] = MBCartVect( 0, 0, 0);
+  coords[0] = CartVect(-2,-1, 0);
+  coords[1] = CartVect(-2, 1, 0);
+  coords[2] = CartVect( 0, 0, 2);
+  coords[3] = CartVect( 0, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(-1.5,0.0,1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1.5,0.0,1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(-2.5,0.0,2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(-2.5,0.0,2.5), CartVect(1,1,1) ) );
   
     // Box edge +y,-z
-  coords[0] = MBCartVect( 2,-1, 0);
-  coords[1] = MBCartVect( 0, 0, 0);
-  coords[2] = MBCartVect(-2,-1, 0);
-  coords[3] = MBCartVect( 0, 0, 2);
+  coords[0] = CartVect( 2,-1, 0);
+  coords[1] = CartVect( 0, 0, 0);
+  coords[2] = CartVect(-2,-1, 0);
+  coords[3] = CartVect( 0, 0, 2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(0.0,-1.5,1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(0.0,-1.5,1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(0.0,-2.5,2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.0,-2.5,2.5), CartVect(1,1,1) ) );
   
     // Box edge -x,+z
-  coords[0] = MBCartVect( 2,-1, 0);
-  coords[1] = MBCartVect( 0, 0, 0);
-  coords[2] = MBCartVect( 2, 1, 0);
-  coords[3] = MBCartVect( 0, 0,-2);
+  coords[0] = CartVect( 2,-1, 0);
+  coords[1] = CartVect( 0, 0, 0);
+  coords[2] = CartVect( 2, 1, 0);
+  coords[3] = CartVect( 0, 0,-2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(1.5,0.0,-1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(1.5,0.0,-1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(2.5,0.0,-2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2.5,0.0,-2.5), CartVect(1,1,1) ) );
   
     // Box edge -y,+z
-  coords[0] = MBCartVect(-1, 2, 0);
-  coords[1] = MBCartVect( 1, 2, 0);
-  coords[2] = MBCartVect( 0, 0, 0);
-  coords[3] = MBCartVect( 0, 0,-2);
+  coords[0] = CartVect(-1, 2, 0);
+  coords[1] = CartVect( 1, 2, 0);
+  coords[2] = CartVect( 0, 0, 0);
+  coords[3] = CartVect( 0, 0,-2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(0.0,1.5,-1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(0.0,1.5,-1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(0.0,2.5,-2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.0,2.5,-2.5), CartVect(1,1,1) ) );
   
     // Box edge +x,+z
-  coords[0] = MBCartVect(-2, 1, 0);
-  coords[1] = MBCartVect(-2,-1, 0);
-  coords[2] = MBCartVect( 0, 0,-2);
-  coords[3] = MBCartVect( 0, 0, 0);
+  coords[0] = CartVect(-2, 1, 0);
+  coords[1] = CartVect(-2,-1, 0);
+  coords[2] = CartVect( 0, 0,-2);
+  coords[3] = CartVect( 0, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(-1.5,0.0,-1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1.5,0.0,-1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(-2.5,0.0,-2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(-2.5,0.0,-2.5), CartVect(1,1,1) ) );
   
     // Box edge +y,+z
-  coords[0] = MBCartVect( 0, 0, 0);
-  coords[1] = MBCartVect( 2,-1, 0);
-  coords[2] = MBCartVect(-2,-1, 0);
-  coords[3] = MBCartVect( 0, 0,-2);
+  coords[0] = CartVect( 0, 0, 0);
+  coords[1] = CartVect( 2,-1, 0);
+  coords[2] = CartVect(-2,-1, 0);
+  coords[3] = CartVect( 0, 0,-2);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(0.0,-1.5,-1.5), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(0.0,-1.5,-1.5), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(0.0,-2.5,-2.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(0.0,-2.5,-2.5), CartVect(1,1,1) ) );
     
     // Box edge -x,-y
-  coords[0] = MBCartVect( 0, 0, 0);
-  coords[1] = MBCartVect( 0, 2,-1);
-  coords[2] = MBCartVect( 0, 2, 1);
-  coords[3] = MBCartVect( 2, 0, 0);
+  coords[0] = CartVect( 0, 0, 0);
+  coords[1] = CartVect( 0, 2,-1);
+  coords[2] = CartVect( 0, 2, 1);
+  coords[3] = CartVect( 2, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(1.5,1.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(1.5,1.5,0.0), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(2.5,2.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2.5,2.5,0.0), CartVect(1,1,1) ) );
     
     // Box edge +x,-y
-  coords[0] = MBCartVect( 0, 2,-1);
-  coords[1] = MBCartVect( 0, 0, 0);
-  coords[2] = MBCartVect( 0, 2, 1);
-  coords[3] = MBCartVect(-2, 0, 0);
+  coords[0] = CartVect( 0, 2,-1);
+  coords[1] = CartVect( 0, 0, 0);
+  coords[2] = CartVect( 0, 2, 1);
+  coords[3] = CartVect(-2, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(-1.5,1.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1.5,1.5,0.0), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(-2.5,2.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(-2.5,2.5,0.0), CartVect(1,1,1) ) );
     
     // Box edge -x,+y
-  coords[0] = MBCartVect( 0,-2, 1);
-  coords[1] = MBCartVect( 0,-2,-1);
-  coords[2] = MBCartVect( 0, 0, 0);
-  coords[3] = MBCartVect( 2, 0, 0);
+  coords[0] = CartVect( 0,-2, 1);
+  coords[1] = CartVect( 0,-2,-1);
+  coords[2] = CartVect( 0, 0, 0);
+  coords[3] = CartVect( 2, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(1.5,-1.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(1.5,-1.5,0.0), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(2.5,-2.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(2.5,-2.5,0.0), CartVect(1,1,1) ) );
     
     // Box edge +x,+y
-  coords[0] = MBCartVect( 0,-2,-1);
-  coords[1] = MBCartVect(-2, 0, 0);
-  coords[2] = MBCartVect( 0,-2, 1);
-  coords[3] = MBCartVect( 0, 0, 0);
+  coords[0] = CartVect( 0,-2,-1);
+  coords[1] = CartVect(-2, 0, 0);
+  coords[2] = CartVect( 0,-2, 1);
+  coords[3] = CartVect( 0, 0, 0);
     // box edge passes through tet
-  ASSERT( overlap( coords, MBCartVect(-1.5,-1.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, CartVect(-1.5,-1.5,0.0), CartVect(1,1,1) ) );
     // box edge does not pass through tet
-  ASSERT( !overlap( coords, MBCartVect(-2.5,-2.5,0.0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, CartVect(-2.5,-2.5,0.0), CartVect(1,1,1) ) );
   
   
     // Test tet edge through box 
-  coords[0] = MBCartVect( -0.13369421660900116, -2.9871494770050049,  0.0526076555252075 );
-  coords[1] = MBCartVect( -0.00350524857640266, -3.3236153125762939,  0.2924639880657196 );
-  coords[2] = MBCartVect(  0.16473215818405151, -2.9966945648193359, -0.1936169415712357 );
-  coords[3] = MBCartVect(  0.26740345358848572, -2.8492588996887207,  0.1519143134355545 );
-  ASSERT( overlap( coords, MBCartVect( -2.5, -2.8, -2.5 ), MBCartVect( 2.5, 0.31, 2.5 ) ) );
+  coords[0] = CartVect( -0.13369421660900116, -2.9871494770050049,  0.0526076555252075 );
+  coords[1] = CartVect( -0.00350524857640266, -3.3236153125762939,  0.2924639880657196 );
+  coords[2] = CartVect(  0.16473215818405151, -2.9966945648193359, -0.1936169415712357 );
+  coords[3] = CartVect(  0.26740345358848572, -2.8492588996887207,  0.1519143134355545 );
+  ASSERT( overlap( coords, CartVect( -2.5, -2.8, -2.5 ), CartVect( 2.5, 0.31, 2.5 ) ) );
 }
 
 void test_box_tri_overlap()
@@ -776,59 +777,59 @@
   double t;
 
     // define a triangle
-  const MBCartVect tri[3] = { MBCartVect(1.0, 0.0, 0.0), 
-                              MBCartVect(0.0, 1.0, 0.0),
-                              MBCartVect(0.0, 0.0, 1.0) };
+  const CartVect tri[3] = { CartVect(1.0, 0.0, 0.0), 
+                              CartVect(0.0, 1.0, 0.0),
+                              CartVect(0.0, 0.0, 1.0) };
   
     // try a ray through the center of the triangle
   xsect = ray_tri_intersect( tri, 
-                             MBCartVect( 0.0, 0.0, 0.0 ),
-                             MBCartVect( 1.0, 1.0, 1.0 ),
+                             CartVect( 0.0, 0.0, 0.0 ),
+                             CartVect( 1.0, 1.0, 1.0 ),
                              TOL, t );
   ASSERT(xsect);
   ASSERT_DOUBLES_EQUAL( 1.0/3.0, t );
   
     // try a same ray, but move base point above triangle
   xsect = ray_tri_intersect( tri, 
-                             MBCartVect( 1.0, 1.0, 1.0 ),
-                             MBCartVect( 1.0, 1.0, 1.0 ),
+                             CartVect( 1.0, 1.0, 1.0 ),
+                             CartVect( 1.0, 1.0, 1.0 ),
                              TOL, t );
   ASSERT(!xsect);
   
     // try a same ray the other direction with base point below triangle
   xsect = ray_tri_intersect( tri, 
-                             MBCartVect( 0.0, 0.0, 0.0 ),
-                             MBCartVect(-1.0,-1.0,-1.0 ),
+                             CartVect( 0.0, 0.0, 0.0 ),
+                             CartVect(-1.0,-1.0,-1.0 ),
                              TOL, t );
   ASSERT(!xsect);
   
   
     // try a ray that passes above the triangle
   xsect = ray_tri_intersect( tri, 
-                             MBCartVect( 1.0, 1.0, 1.0 ),
-                             MBCartVect(-1.0,-1.0, 1.0 ),
+                             CartVect( 1.0, 1.0, 1.0 ),
+                             CartVect(-1.0,-1.0, 1.0 ),
                              TOL, t );
   ASSERT(!xsect);
   
     // try a skew ray
   xsect = ray_tri_intersect( tri, 
-                             MBCartVect( 0.0, 0.0, 0.0 ),
-                             MBCartVect( 1.0, 1.0,-0.1 ),
+                             CartVect( 0.0, 0.0, 0.0 ),
+                             CartVect( 1.0, 1.0,-0.1 ),
                              TOL, t );
   ASSERT(!xsect);
 }
 
 void test_closest_location_on_tri()
 {
-  MBCartVect result, input;
+  CartVect result, input;
   
     // define a triangle
-  const MBCartVect tri[3] = { MBCartVect(1.0, 0.0, 0.0), 
-                              MBCartVect(0.0, 1.0, 0.0),
-                              MBCartVect(0.0, 0.0, 1.0) };
+  const CartVect tri[3] = { CartVect(1.0, 0.0, 0.0), 
+                              CartVect(0.0, 1.0, 0.0),
+                              CartVect(0.0, 0.0, 1.0) };
   
     // try point at triangle centroid
-  input = MBCartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 );
+  input = CartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 );
   closest_location_on_tri( input, tri, result );
   ASSERT_VECTORS_EQUAL( result, input );
   
@@ -852,14 +853,14 @@
   ASSERT_VECTORS_EQUAL( result, input );
   
     // try a point above the center of the triangle
-  input = MBCartVect(1.0,1.0,1.0);
+  input = CartVect(1.0,1.0,1.0);
   closest_location_on_tri( input, tri, result );
-  ASSERT_VECTORS_EQUAL( result, MBCartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 ) );
+  ASSERT_VECTORS_EQUAL( result, CartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 ) );
   
     // try a point below the center of the triangle
-  input = MBCartVect(0.0,0.0,0.0);
+  input = CartVect(0.0,0.0,0.0);
   closest_location_on_tri( input, tri, result );
-  ASSERT_VECTORS_EQUAL( result, MBCartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 ) );
+  ASSERT_VECTORS_EQUAL( result, CartVect( 1.0/3.0, 1.0/3.0, 1.0/3.0 ) );
   
     // try a point closest to each vertex and 'outside' of both adjacent edges.
   input = 2*tri[0];
@@ -884,60 +885,60 @@
   ASSERT_VECTORS_EQUAL( result, 0.5 * input );
   
     // define an equilateral triangle in the xy-plane
-  const MBCartVect tri_xy[3] = { MBCartVect( 0.0, sqrt(3.0)/2.0, 0.0), 
-                                 MBCartVect( 0.5, 0.0, 0.0),
-                                 MBCartVect(-0.5, 0.0, 0.0) };
+  const CartVect tri_xy[3] = { CartVect( 0.0, sqrt(3.0)/2.0, 0.0), 
+                                 CartVect( 0.5, 0.0, 0.0),
+                                 CartVect(-0.5, 0.0, 0.0) };
   
     // for each vertex, test point that is
     // - outside triangle
     // - closest to vertex
     // - 'inside' one of the adjacent edges
     // - 'outside' the other adjacent edge
-  closest_location_on_tri( MBCartVect(-0.3, 1.2, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect(-0.3, 1.2, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[0] );
-  closest_location_on_tri( MBCartVect( 0.3, 1.2, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect( 0.3, 1.2, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[0] );
-  closest_location_on_tri( MBCartVect( 1.0, 0.1, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect( 1.0, 0.1, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[1] );
-  closest_location_on_tri( MBCartVect( 0.6,-0.5, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect( 0.6,-0.5, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[1] );
-  closest_location_on_tri( MBCartVect(-0.6,-0.5, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect(-0.6,-0.5, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[2] );
-  closest_location_on_tri( MBCartVect(-1.0, 0.1, 0.0), tri_xy, result );
+  closest_location_on_tri( CartVect(-1.0, 0.1, 0.0), tri_xy, result );
   ASSERT_VECTORS_EQUAL( result, tri_xy[2] );
 }
 
 void test_closest_location_on_polygon()
 {
-  MBCartVect result, input;
+  CartVect result, input;
   
     // define a unit square in xy plane
-  const MBCartVect quad[4] = { MBCartVect( 0.0, 0.0, 0.0), 
-                               MBCartVect( 1.0, 0.0, 0.0),
-                               MBCartVect( 1.0, 1.0, 0.0),
-                               MBCartVect( 0.0, 1.0, 0.0) };
+  const CartVect quad[4] = { CartVect( 0.0, 0.0, 0.0), 
+                               CartVect( 1.0, 0.0, 0.0),
+                               CartVect( 1.0, 1.0, 0.0),
+                               CartVect( 0.0, 1.0, 0.0) };
   
     // test input in center of square
-  closest_location_on_polygon(  MBCartVect( 0.5, 0.5, 0.0 ), quad, 4, result );
-  ASSERT_VECTORS_EQUAL( result, MBCartVect( 0.5, 0.5, 0.0 ) );
+  closest_location_on_polygon(  CartVect( 0.5, 0.5, 0.0 ), quad, 4, result );
+  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
     // test above center of square  
-  closest_location_on_polygon(  MBCartVect( 0.5, 0.5, 1.0 ), quad, 4, result );
-  ASSERT_VECTORS_EQUAL( result, MBCartVect( 0.5, 0.5, 0.0 ) );
+  closest_location_on_polygon(  CartVect( 0.5, 0.5, 1.0 ), quad, 4, result );
+  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
     // test below center of square  
-  closest_location_on_polygon(  MBCartVect( 0.5, 0.5,-1.0 ), quad, 4, result );
-  ASSERT_VECTORS_EQUAL( result, MBCartVect( 0.5, 0.5, 0.0 ) );
+  closest_location_on_polygon(  CartVect( 0.5, 0.5,-1.0 ), quad, 4, result );
+  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
 
     // test points within square, but not at center
-  input = MBCartVect( 0.25, 0.25, 0 );
+  input = CartVect( 0.25, 0.25, 0 );
   closest_location_on_polygon( input, quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, input );
-  input = MBCartVect( 0.75, 0.25, 0 );
+  input = CartVect( 0.75, 0.25, 0 );
   closest_location_on_polygon( input, quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, input );
-  input = MBCartVect( 0.75, 0.75, 0 );
+  input = CartVect( 0.75, 0.75, 0 );
   closest_location_on_polygon( input, quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, input );
-  input = MBCartVect( 0.25, 0.75, 0 );
+  input = CartVect( 0.25, 0.75, 0 );
   closest_location_on_polygon( input, quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, input );
 
@@ -966,17 +967,17 @@
   ASSERT_VECTORS_EQUAL( result, input );
   
     // test at point outside and closest to each corner
-  closest_location_on_polygon( MBCartVect(-1.0,-1.0, 0.0 ), quad, 4, result );
+  closest_location_on_polygon( CartVect(-1.0,-1.0, 0.0 ), quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, quad[0] );
-  closest_location_on_polygon( MBCartVect( 2.0,-1.0, 0.0 ), quad, 4, result );
+  closest_location_on_polygon( CartVect( 2.0,-1.0, 0.0 ), quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, quad[1] );
-  closest_location_on_polygon( MBCartVect( 2.0, 2.0, 0.0 ), quad, 4, result );
+  closest_location_on_polygon( CartVect( 2.0, 2.0, 0.0 ), quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, quad[2] );
-  closest_location_on_polygon( MBCartVect(-1.0, 2.0, 0.0 ), quad, 4, result );
+  closest_location_on_polygon( CartVect(-1.0, 2.0, 0.0 ), quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, quad[3] );
   
     // test at point outside and closest to an edge
-  MBCartVect x(1.0,0.0,0.0), y(0.0,1.0,0.0);
+  CartVect x(1.0,0.0,0.0), y(0.0,1.0,0.0);
   input = 0.5 * quad[0] + 0.5 * quad[1];
   closest_location_on_polygon(  input-y, quad, 4, result );
   ASSERT_VECTORS_EQUAL( result, input );
@@ -997,16 +998,16 @@
   const double box_max = 2.0;
   const double box_wid = box_max - box_min;
   const double box_mid = 0.5 * (box_min + box_max);
-  const MBCartVect min( box_min );
-  const MBCartVect max( box_max );
-  const MBCartVect X(1,0,0), Y(0,1,0), Z(0,0,1);
-  MBCartVect pt;
+  const CartVect min( box_min );
+  const CartVect max( box_max );
+  const CartVect X(1,0,0), Y(0,1,0), Z(0,0,1);
+  CartVect pt;
   double start, end;
   bool r;
   
     // test line through box in +x direction
   double offset = 1;
-  pt = MBCartVect( box_min - offset, box_mid, box_mid );
+  pt = CartVect( box_min - offset, box_mid, box_mid );
   start = -HUGE_VAL; end = HUGE_VAL;
   r = segment_box_intersect( min, max, pt, X, start, end );
   ASSERT( r );
@@ -1040,7 +1041,7 @@
    
     // test line through box in -y direction
   offset = 1;
-  pt = MBCartVect( box_mid, box_min - offset, box_mid );
+  pt = CartVect( box_mid, box_min - offset, box_mid );
   start = -HUGE_VAL; end = HUGE_VAL;
   r = segment_box_intersect( min, max, pt, -Y, start, end );
   ASSERT( r );
@@ -1073,7 +1074,7 @@
  
     // test ray outside in Z direction, parallel to Z plane, and
     // intersecting in projections into other planes
-  pt = MBCartVect( box_mid, box_mid, box_max + 1 );
+  pt = CartVect( box_mid, box_mid, box_max + 1 );
   start = 0; end = box_wid;
   r = segment_box_intersect( min, max, pt,  X, start, end );
   ASSERT( !r );
@@ -1088,7 +1089,7 @@
   ASSERT( !r );
   
     // try the other side (less than the min Z);
-  pt = MBCartVect( box_mid, box_mid, box_min - 1 );
+  pt = CartVect( box_mid, box_mid, box_min - 1 );
   start = 0; end = box_wid;
   r = segment_box_intersect( min, max, pt,  X, start, end );
   ASSERT( !r );
@@ -1103,7 +1104,7 @@
   ASSERT( !r );
   
     // now move the ray such that it lies exactly on the side of the box
-  pt = MBCartVect( box_mid, box_mid, box_min );
+  pt = CartVect( box_mid, box_mid, box_min );
   start = 0; end = box_wid;
   r = segment_box_intersect( min, max, pt,  X, start, end );
   ASSERT( r );
@@ -1126,8 +1127,8 @@
   ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid );
   
     // try a skew line segment
-  pt = MBCartVect( box_min - 0.25 * box_wid, box_mid, box_mid );
-  MBCartVect dir( 1.0/sqrt(2.0), 1.0/sqrt(2.0), 0 );
+  pt = CartVect( box_min - 0.25 * box_wid, box_mid, box_mid );
+  CartVect dir( 1.0/sqrt(2.0), 1.0/sqrt(2.0), 0 );
   start = 0; end = 1.5 / sqrt(2.0) * box_wid;
   r = segment_box_intersect( min, max, pt, dir, start, end );
   ASSERT( r );
@@ -1135,7 +1136,7 @@
   ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt(2.0) );
   
     // try with skew line segment that just touches edge of box
-  pt = MBCartVect( box_min - 0.5 * box_wid, box_mid, box_mid );
+  pt = CartVect( box_min - 0.5 * box_wid, box_mid, box_mid );
   start = 0; end = 3.0 / sqrt(2.0) * box_wid;
   r = segment_box_intersect( min, max, pt, dir, start, end );
   ASSERT( r );
@@ -1143,7 +1144,7 @@
   ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt(2.0) );
 
     // try with skew line segment outside of box
-  pt = MBCartVect( box_min - 0.75 * box_wid, box_mid, box_mid );
+  pt = CartVect( box_min - 0.75 * box_wid, box_mid, box_mid );
   start = 0; end = 3.0 / sqrt(2.0) * box_wid;
   r = segment_box_intersect( min, max, pt, dir, start, end );
   ASSERT( !r );
@@ -1151,43 +1152,43 @@
 
 void test_closest_location_on_box()
 {
-  const MBCartVect min(0,0,0), max(1,2,3);
-  MBCartVect pt;
+  const CartVect min(0,0,0), max(1,2,3);
+  CartVect pt;
   
     // inside
-  closest_location_on_box( min, max, MBCartVect(0.5,0.5,0.5), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.5,0.5,0.5), pt );
+  closest_location_on_box( min, max, CartVect(0.5,0.5,0.5), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.5,0.5,0.5), pt );
   
     // closest to min x side
-  closest_location_on_box( min, max, MBCartVect(-1.0,0.5,0.5), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.0,0.5,0.5), pt );
+  closest_location_on_box( min, max, CartVect(-1.0,0.5,0.5), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.0,0.5,0.5), pt );
   
     // closest to max x side
-  closest_location_on_box( min, max, MBCartVect(2.0,0.5,0.5), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(1.0,0.5,0.5), pt );
+  closest_location_on_box( min, max, CartVect(2.0,0.5,0.5), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(1.0,0.5,0.5), pt );
   
     // closest to min y side
-  closest_location_on_box( min, max, MBCartVect(0.5,-1.0,0.5), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.5,0.0,0.5), pt );
+  closest_location_on_box( min, max, CartVect(0.5,-1.0,0.5), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.5,0.0,0.5), pt );
   
     // closest to max y side
-  closest_location_on_box( min, max, MBCartVect(0.5,2.5,0.5), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.5,2.0,0.5), pt );
+  closest_location_on_box( min, max, CartVect(0.5,2.5,0.5), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.5,2.0,0.5), pt );
   
     // closest to min z side
-  closest_location_on_box( min, max, MBCartVect(0.5,0.5,-0.1), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.5,0.5,0.0), pt );
+  closest_location_on_box( min, max, CartVect(0.5,0.5,-0.1), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.5,0.5,0.0), pt );
   
     // closest to max z side
-  closest_location_on_box( min, max, MBCartVect(0.5,0.5,100.0), pt );
-  ASSERT_VECTORS_EQUAL( MBCartVect(0.5,0.5,3.0), pt );
+  closest_location_on_box( min, max, CartVect(0.5,0.5,100.0), pt );
+  ASSERT_VECTORS_EQUAL( CartVect(0.5,0.5,3.0), pt );
   
     // closest to min corner
-  closest_location_on_box( min, max, MBCartVect(-1,-1,-1), pt );
+  closest_location_on_box( min, max, CartVect(-1,-1,-1), pt );
   ASSERT_VECTORS_EQUAL( min, pt );
   
     // closest to max corner
-  closest_location_on_box( min, max, MBCartVect(2,3,4), pt );
+  closest_location_on_box( min, max, CartVect(2,3,4), pt );
   ASSERT_VECTORS_EQUAL( max, pt );
 }
 

Modified: MOAB/trunk/test/MBTest.cpp
===================================================================
--- MOAB/trunk/test/MBTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/MBTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -35,25 +35,26 @@
 #include <assert.h>
 #include <math.h>
 #include <stdio.h>
-#include "MBInterface.hpp"
-#include "MBTagConventions.hpp"
-#include "MBRange.hpp"
-#include "MBSkinner.hpp"
-#include "MeshTopoUtil.hpp"
-#include "MBCN.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBCartVect.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Range.hpp"
+#include "moab/Skinner.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/MBCN.hpp"
+#include "OrientedBox.hpp"
+#include "moab/CartVect.hpp"
 
 #ifndef IS_BUILDING_MB
 #define IS_BUILDING_MB
 #endif
-#include "MBInternals.hpp"
-#include "MBCore.hpp"
+#include "Internals.hpp"
+#include "moab/Core.hpp"
 #include "SequenceManager.hpp"
 #include "EntitySequence.hpp"
-#include "MBRangeSeqIntersectIter.hpp"
+#include "RangeSeqIntersectIter.hpp"
 
 using namespace std;
+using namespace moab;
 
 #define STRINGIFY_(A) #A
 #define STRINGIFY(A) STRINGIFY_(A)
@@ -86,11 +87,11 @@
     @li Get coordinates of vertex 6 correctly
   */
 
-MBErrorCode mb_vertex_coordinate_test(MBInterface *MB)
+ErrorCode mb_vertex_coordinate_test(Interface *MB)
 {
   double coords[3];
-  MBEntityHandle handle;
-  MBErrorCode error;
+  EntityHandle handle;
+  ErrorCode error;
   int err;
 
     // coordinate 2 should be {1.5, -1.5, 3.5}
@@ -137,7 +138,7 @@
 
     // tag names must be defined by convention
 
-  MBRange vertices;
+  Range vertices;
   error = MB->get_entities_by_type(0,  MBVERTEX, vertices);
 
   if (error != MB_SUCCESS)
@@ -146,7 +147,7 @@
   int node_count = 0;
   double all_coords[3*47];
   double* coord_iter = all_coords;
-  for ( MBRange::iterator iter = vertices.begin();
+  for ( Range::iterator iter = vertices.begin();
         iter != vertices.end(); ++iter)
   {
     error = MB->get_coords(&(*iter), 1, coord_iter );
@@ -198,22 +199,22 @@
     @li Add, Set and correctly get a struct tag
   */
 
-MBErrorCode mb_vertex_tag_test(MBInterface *MB)
+ErrorCode mb_vertex_tag_test(Interface *MB)
 {
     // Add an int Vertex Tag to the database
 
   int tag_size = sizeof(int);
-  MBTag tag_id;
+  Tag tag_id;
 
     // Create a dense tag for all vertices
-  MBErrorCode error = MB->tag_create("int_tag", tag_size, MB_TAG_SPARSE, tag_id, 0);
+  ErrorCode error = MB->tag_create("int_tag", tag_size, MB_TAG_SPARSE, tag_id, 0);
   if (error != MB_SUCCESS)
     return error;
 
     // put a value in vertex 1 and retrieve
 
   int err;
-  MBEntityHandle handle = CREATE_HANDLE(MBVERTEX, 1, err);
+  EntityHandle handle = CREATE_HANDLE(MBVERTEX, 1, err);
   int input_value = 11;
   error = MB->tag_set_data(tag_id, &handle, 1, &input_value);
   if (MB_SUCCESS != error) return error;
@@ -332,7 +333,7 @@
   for (i=0; i<10; i++)
   {
     int err=0;
-    MBEntityHandle handle = CREATE_HANDLE(MBVERTEX, node_ids[i], err);
+    EntityHandle handle = CREATE_HANDLE(MBVERTEX, node_ids[i], err);
 
     if (err != 0)
       return MB_FAILURE;
@@ -371,7 +372,7 @@
     return MB_FAILURE;
 
     // get the tag handle of the last tag created above
-  MBTag int_tag_handle;
+  Tag int_tag_handle;
   error = MB->tag_get_handle (int_tag_name.c_str(), int_tag_handle);
   if (MB_SUCCESS != error) return error;
     
@@ -379,7 +380,7 @@
     return MB_FAILURE;
 
     // test tag_get_tags_on_entity and tag_delete_data
-  std::vector<MBTag> all_tags;
+  std::vector<Tag> all_tags;
   handle = CREATE_HANDLE(MBVERTEX, node_ids[0], err);
   error = MB->tag_get_tags_on_entity(handle, all_tags);
   if (MB_SUCCESS != error)
@@ -414,7 +415,7 @@
     return error;
 
     // delete the dense tag named bool_tag 
-  MBTag bool_tag_handle;
+  Tag bool_tag_handle;
   error = MB->tag_get_handle ("bool_tag", bool_tag_handle);
   if (error != MB_SUCCESS) return error;
 
@@ -432,13 +433,13 @@
     @li Get coordinates for 2 node bar elements
   */
 
-MBErrorCode mb_bar_connectivity_test(MBInterface *MB)
+ErrorCode mb_bar_connectivity_test(Interface *MB)
 {
 
-  std::vector<MBEntityHandle> conn;
-  MBErrorCode error;
+  std::vector<EntityHandle> conn;
+  ErrorCode error;
 
-  MBRange bars;
+  Range bars;
 
   error = MB->get_entities_by_type(0, MBEDGE, bars);
 
@@ -446,7 +447,7 @@
     return error;
 
     // get the connectivity of the second bar
-  MBEntityHandle handle = *(++bars.begin());
+  EntityHandle handle = *(++bars.begin());
 
   error = MB->get_connectivity(&handle, 1, conn);
   if (error != MB_SUCCESS )  
@@ -474,20 +475,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_tri_connectivity_test(MBInterface *MB)
+ErrorCode mb_tri_connectivity_test(Interface *MB)
 {
 
-  std::vector<MBEntityHandle> conn; 
-  MBErrorCode error;
+  std::vector<EntityHandle> conn; 
+  ErrorCode error;
 
-  MBRange tris;
+  Range tris;
   error = MB->get_entities_by_type(0, MBTRI, tris);
 
   if (error != MB_SUCCESS)
     return error;
 
     // get the connectivity of the second tri
-  MBEntityHandle handle = *(++tris.begin());
+  EntityHandle handle = *(++tris.begin());
 
   error = MB->get_connectivity(&handle, 1, conn);
   if (error != MB_SUCCESS )  
@@ -511,20 +512,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_quad_connectivity_test(MBInterface *MB)
+ErrorCode mb_quad_connectivity_test(Interface *MB)
 {
 
-  std::vector<MBEntityHandle> conn;
+  std::vector<EntityHandle> conn;
 
-  MBRange quads;
+  Range quads;
 
-  MBErrorCode error = MB->get_entities_by_type(0, MBQUAD, quads);
+  ErrorCode error = MB->get_entities_by_type(0, MBQUAD, quads);
 
   if (error != MB_SUCCESS)
     return error;
 
     // get the connectivity of the second quad
-  MBEntityHandle handle = *(++quads.begin());
+  EntityHandle handle = *(++quads.begin());
 
   error = MB->get_connectivity(&handle, 1, conn);
   if (error != MB_SUCCESS )  
@@ -551,20 +552,20 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_hex_connectivity_test(MBInterface *MB)
+ErrorCode mb_hex_connectivity_test(Interface *MB)
 {
 
-  std::vector<MBEntityHandle> conn;
+  std::vector<EntityHandle> conn;
 
-  MBRange hexes;
+  Range hexes;
 
-  MBErrorCode error = MB->get_entities_by_type(0,  MBHEX, hexes);
+  ErrorCode error = MB->get_entities_by_type(0,  MBHEX, hexes);
 
   if (error != MB_SUCCESS)
     return error;
 
     // get the connectivity of the second hex
-  MBEntityHandle handle = *(++hexes.begin());
+  EntityHandle handle = *(++hexes.begin());
 
   error = MB->get_connectivity(&handle, 1, conn);
   if (error != MB_SUCCESS )  
@@ -603,19 +604,19 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_tet_connectivity_test(MBInterface *MB)
+ErrorCode mb_tet_connectivity_test(Interface *MB)
 {
-  std::vector<MBEntityHandle> conn; 
+  std::vector<EntityHandle> conn; 
 
-  MBRange tets;
+  Range tets;
 
-  MBErrorCode error = MB->get_entities_by_type(0, MBTET, tets);
+  ErrorCode error = MB->get_entities_by_type(0, MBTET, tets);
 
   if (error != MB_SUCCESS)
     return error;
 
     // get the connectivity of the second tet
-  MBEntityHandle handle = *(++tets.begin());
+  EntityHandle handle = *(++tets.begin());
 
   error = MB->get_connectivity(&handle, 1, conn);
   if (error != MB_SUCCESS )  
@@ -641,21 +642,21 @@
 
   return MB_SUCCESS;
 }
-MBErrorCode mb_temporary_test( MBInterface *gMB )
+ErrorCode mb_temporary_test( Interface *gMB )
 {
 
   double array[3] = {0.0, 0.0, 0.0};
-  MBEntityHandle h_node1;
-  MBErrorCode result = gMB->create_vertex(array, h_node1);
+  EntityHandle h_node1;
+  ErrorCode result = gMB->create_vertex(array, h_node1);
   if (MB_SUCCESS != result)
     return result;
 
-  MBEntityHandle ordered_meshset1;
+  EntityHandle ordered_meshset1;
   result = gMB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, ordered_meshset1);
   if (MB_SUCCESS != result)
     return result;
 
-  MBEntityHandle ordered_meshset2;
+  EntityHandle ordered_meshset2;
   result = gMB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, ordered_meshset2);
   if (MB_SUCCESS != result)
     return result;
@@ -673,7 +674,7 @@
     return result;
 
   bool create_if_missing = false;
-  std::vector<MBEntityHandle> meshsets;
+  std::vector<EntityHandle> meshsets;
   result = gMB->get_adjacencies(&h_node1, 1, 4, create_if_missing, meshsets);
   if (MB_SUCCESS != result)
     return result;
@@ -684,11 +685,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_adjacent_vertex_test( MBInterface* mb )
+ErrorCode mb_adjacent_vertex_test( Interface* mb )
 {
-  MBErrorCode rval;
-  MBRange hexes, expt_vert, got_vert, some_hexes;
-  MBRange::const_iterator i, j;
+  ErrorCode rval;
+  Range hexes, expt_vert, got_vert, some_hexes;
+  Range::const_iterator i, j;
   int n;
   
     // get all hexes
@@ -704,7 +705,7 @@
     if (++n % 3)
       continue;
     some_hexes.insert( *i );
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int len;
     rval = mb->get_connectivity( *i, conn, len );
     if (MB_SUCCESS != rval)
@@ -714,7 +715,7 @@
   }
   
     // use get_adjacencies to get vertices
-  rval = mb->get_adjacencies( some_hexes, 0, false, got_vert, MBInterface::UNION );
+  rval = mb->get_adjacencies( some_hexes, 0, false, got_vert, Interface::UNION );
   if (MB_SUCCESS != rval) {
     std::cout << "get_adjacencies failed with error code " << rval << std::endl;
     return rval;
@@ -747,7 +748,7 @@
   return MB_SUCCESS;
 }
   
-MBErrorCode mb_adjacencies_test(MBInterface *mb) 
+ErrorCode mb_adjacencies_test(Interface *mb) 
 {
     // this test does the following:
     // 1. For each element, creates vertex-element adjacencies (only for
@@ -757,9 +758,9 @@
     //
     // assume mesh has already been read
 
-  MBEntityType seq_type;
-  MBErrorCode result = MB_SUCCESS;
-  MBRange handle_range;
+  EntityType seq_type;
+  ErrorCode result = MB_SUCCESS;
+  Range handle_range;
 
     // Some code to make the test simpler locally (this will cause other tests to
     // fail though, so watch out!)
@@ -772,11 +773,11 @@
     // this may be far from being the most efficient, but
     // it certainly does exercise the adjacency routines
 
-  MBRange::iterator iter;
-  MBRange::reverse_iterator riter;
+  Range::iterator iter;
+  Range::reverse_iterator riter;
 
     // first get the hexes
-  MBRange hexes;
+  Range hexes;
   result = mb->get_entities_by_type(0, MBHEX, hexes);
   if (MB_SUCCESS != result)
     return result;
@@ -794,8 +795,8 @@
 
 
     // get all the nodes that these hexes are connected to
-  MBRange nodes;
-  result = mb->get_adjacencies(hexes, 0, false, nodes, MBInterface::UNION);
+  Range nodes;
+  result = mb->get_adjacencies(hexes, 0, false, nodes, Interface::UNION);
   if (MB_SUCCESS != result)
     return result;
 
@@ -807,8 +808,8 @@
   }
 
     // find the interior nodes; assume a structured mesh
-  MBRange interior_nodes;
-  std::vector<MBEntityHandle> attached_hexes;
+  Range interior_nodes;
+  std::vector<EntityHandle> attached_hexes;
   for( iter = nodes.begin(); iter != nodes.end();)
   {
     attached_hexes.clear();
@@ -836,14 +837,14 @@
   }
 
     // get interior quads from interior nodes
-  MBRange interior_quads;
-  result = mb->get_adjacencies(interior_nodes, 2, true, interior_quads, MBInterface::UNION);
+  Range interior_quads;
+  result = mb->get_adjacencies(interior_nodes, 2, true, interior_quads, Interface::UNION);
   if (MB_SUCCESS != result) 
     return result;
 
     // get a list of quads generated adjacent to the exterior nodes
-  MBRange temp_quads, exterior_quads;
-  result = mb->get_adjacencies(nodes, 2, true, temp_quads, MBInterface::UNION);
+  Range temp_quads, exterior_quads;
+  result = mb->get_adjacencies(nodes, 2, true, temp_quads, Interface::UNION);
   if (MB_SUCCESS != result) 
     return result;
 
@@ -851,7 +852,7 @@
     // and we should be left with exterior quads
   std::set_difference(temp_quads.begin(), temp_quads.end(),
                       interior_quads.begin(), interior_quads.end(),
-                      mb_range_inserter(exterior_quads));
+                      range_inserter(exterior_quads));
 
     // check to make sure we have the right number of quads; for hexes, should be
     // .5(6*num_hexes - num_exterior_quads)
@@ -864,7 +865,7 @@
   if (MB_SUCCESS != result) 
     return result;
 
-  MBRange remaining_quads;
+  Range remaining_quads;
   result = mb->get_entities_by_type(0, MBQUAD, remaining_quads);
   if (MB_SUCCESS != result)
     return result;
@@ -898,34 +899,34 @@
 
 }
   
-MBErrorCode mb_adjacencies_create_delete_test(MBInterface *mb) 
+ErrorCode mb_adjacencies_create_delete_test(Interface *mb) 
 {
-  MBCore moab;
+  Core moab;
   mb = &moab;
-  MBErrorCode rval;
+  ErrorCode rval;
 
   double coords[] = { 0, 0, 0, 2, 0, 0, 1, 2, 0 };
-  MBRange verts;
+  Range verts;
   rval = mb->create_vertices( coords, 3, verts );
   if (MB_SUCCESS != rval)
     return rval;
   if (verts.size() != 3)
     return MB_FAILURE;
-  MBEntityHandle vert_arr[3];
+  EntityHandle vert_arr[3];
 
-  MBEntityHandle tri;
+  EntityHandle tri;
   std::copy( verts.begin(), verts.end(), vert_arr );
   rval = mb->create_element( MBTRI, vert_arr, 3, tri );
   if (MB_SUCCESS != rval)
     return rval;
   
   vert_arr[2] = vert_arr[0];
-  MBEntityHandle forward_edge, reverse_edge;
+  EntityHandle forward_edge, reverse_edge;
   rval = mb->create_element( MBEDGE, vert_arr, 2, forward_edge );
   if (MB_SUCCESS != rval)
     return rval;
     
-  std::vector<MBEntityHandle> results;
+  std::vector<EntityHandle> results;
   rval = mb->get_adjacencies( &forward_edge, 1, 2, false, results );
   if (results.size() != 1 || results.front() != tri) {
     std::cerr << "Adjacency query from forward edge to tri failed at "
@@ -974,15 +975,15 @@
   return MB_SUCCESS;
 }
 
-static MBErrorCode create_two_hex_full_mesh( MBInterface* mb,
-                                             MBEntityHandle vertices[12],
-                                             MBEntityHandle hexes[2],
-                                             MBEntityHandle hex1_faces[6],
-                                             MBEntityHandle hex2_faces[6],
-                                             MBEntityHandle hex1_edges[12],
-                                             MBEntityHandle hex2_edges[12] )
+static ErrorCode create_two_hex_full_mesh( Interface* mb,
+                                             EntityHandle vertices[12],
+                                             EntityHandle hexes[2],
+                                             EntityHandle hex1_faces[6],
+                                             EntityHandle hex2_faces[6],
+                                             EntityHandle hex1_edges[12],
+                                             EntityHandle hex2_edges[12] )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
  // create a simple mesh containing 2 hexes
   const double coords[] = { 0, 0, 0, 
                             1, 0, 0,
@@ -999,28 +1000,28 @@
   for (int i = 0; i < 12; ++i)
     if (MB_SUCCESS != mb->create_vertex( coords + 3*i, vertices[i] ))
       return MB_FAILURE;
-  MBEntityHandle hex1_conn[] = { vertices[6], vertices[7], vertices[1], vertices[0],
+  EntityHandle hex1_conn[] = { vertices[6], vertices[7], vertices[1], vertices[0],
                                  vertices[9], vertices[10],vertices[4], vertices[3] };
-  MBEntityHandle hex2_conn[] = { vertices[7], vertices[8], vertices[2], vertices[1],
+  EntityHandle hex2_conn[] = { vertices[7], vertices[8], vertices[2], vertices[1],
                                  vertices[10],vertices[11],vertices[5], vertices[4] };
-  MBEntityHandle shared_quad_conn[] = { vertices[7], vertices[1], vertices[4], vertices[10] };
-  MBEntityHandle hex1_face_conn[][4] = {
+  EntityHandle shared_quad_conn[] = { vertices[7], vertices[1], vertices[4], vertices[10] };
+  EntityHandle hex1_face_conn[][4] = {
     { vertices[6], vertices[7], vertices[10],vertices[9] },
     { vertices[7], vertices[6], vertices[0], vertices[1] },
     { vertices[1], vertices[0], vertices[3], vertices[4] },
     { vertices[9], vertices[10],vertices[4], vertices[3] },
     { vertices[3], vertices[0], vertices[6], vertices[9] } };
-  MBEntityHandle hex2_face_conn[][4] = {
+  EntityHandle hex2_face_conn[][4] = {
     { vertices[7], vertices[8], vertices[11],vertices[10] },
     { vertices[8], vertices[7], vertices[1], vertices[2] },
     { vertices[2], vertices[1], vertices[4], vertices[5] },
     { vertices[10],vertices[11],vertices[5], vertices[4] },
     { vertices[5], vertices[2], vertices[8], vertices[11] } };
-  MBEntityHandle shared_edge_conn[][2] = { { vertices[1], vertices[7] },
+  EntityHandle shared_edge_conn[][2] = { { vertices[1], vertices[7] },
                                            { vertices[7], vertices[10]},
                                            { vertices[10],vertices[4] },
                                            { vertices[4], vertices[1] } };
-  MBEntityHandle hex1_edge_conn[][2] = { { vertices[6], vertices[7] },
+  EntityHandle hex1_edge_conn[][2] = { { vertices[6], vertices[7] },
                                          { vertices[9], vertices[10] },
                                          { vertices[3], vertices[4] },
                                          { vertices[0], vertices[1] },
@@ -1028,7 +1029,7 @@
                                          { vertices[9], vertices[3] },
                                          { vertices[3], vertices[0] },
                                          { vertices[0], vertices[6] } };
-  MBEntityHandle hex2_edge_conn[][2] = { { vertices[7], vertices[8] },
+  EntityHandle hex2_edge_conn[][2] = { { vertices[7], vertices[8] },
                                          { vertices[10], vertices[11] },
                                          { vertices[4], vertices[5] },
                                          { vertices[1], vertices[2] },
@@ -1072,22 +1073,22 @@
 }
 
 
-MBErrorCode mb_upward_adjacencies_test(MBInterface *mb) 
+ErrorCode mb_upward_adjacencies_test(Interface *mb) 
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
   mb = &moab;
   
   // create a simple mesh containing 2 hexes
-  MBEntityHandle vertices[12], hexes[2], hex1_faces[6], hex2_faces[6], hex1_edges[12], hex2_edges[12];
+  EntityHandle vertices[12], hexes[2], hex1_faces[6], hex2_faces[6], hex1_edges[12], hex2_edges[12];
   rval = create_two_hex_full_mesh( mb, vertices, hexes, hex1_faces, hex2_faces, hex1_edges, hex2_edges );
   if (MB_SUCCESS != rval)
     return rval;
 
     // test adjacences from dim to 3
   for (int dim = 0; dim < 3; ++dim) {
-    std::vector<MBEntityHandle> hex1_ent, hex2_ent, shared;
-    const MBEntityHandle *list1, *list2;
+    std::vector<EntityHandle> hex1_ent, hex2_ent, shared;
+    const EntityHandle *list1, *list2;
     int n;
     switch (dim) {
       case 0:
@@ -1119,7 +1120,7 @@
     }
     
     for (size_t j = 0; j < shared.size(); ++j) {
-      std::vector<MBEntityHandle> adj;
+      std::vector<EntityHandle> adj;
       rval = mb->get_adjacencies( &shared[j], 1, 3, false, adj );
       if (MB_SUCCESS != rval)
         return rval;
@@ -1131,7 +1132,7 @@
     }
     
     for (size_t j = 0; j < hex1_ent.size(); ++j) {
-      std::vector<MBEntityHandle> adj;
+      std::vector<EntityHandle> adj;
       rval = mb->get_adjacencies( &hex1_ent[j], 1, 3, false, adj );
       if (MB_SUCCESS != rval)
         return rval;
@@ -1140,7 +1141,7 @@
     }
     
     for (size_t j = 0; j < hex2_ent.size(); ++j) {
-      std::vector<MBEntityHandle> adj;
+      std::vector<EntityHandle> adj;
       rval = mb->get_adjacencies( &hex2_ent[j], 1, 3, false, adj );
       if (MB_SUCCESS != rval)
         return rval;
@@ -1152,13 +1153,13 @@
     // For each edge, get adjacent faces, and for each face
     // get adjacent hexes.  Result should be the same as
     // direct query from edges to hexes
-  std::vector<MBEntityHandle> all_edges(24);
+  std::vector<EntityHandle> all_edges(24);
   std::copy( hex1_edges, hex1_edges+12, all_edges.begin() );
   std::copy( hex2_edges, hex2_edges+12, all_edges.begin()+12 );
   std::sort( all_edges.begin(), all_edges.end() );
   all_edges.erase( std::unique(all_edges.begin(), all_edges.end()), all_edges.end() );
   for (size_t j = 0; j < all_edges.size(); ++j) {
-    std::vector<MBEntityHandle> edge_hexes, edge_faces, face_hexes;
+    std::vector<EntityHandle> edge_hexes, edge_faces, face_hexes;
     rval = mb->get_adjacencies( &all_edges[j], 1, 3, false, edge_hexes );
     if (MB_SUCCESS != rval)
       return rval;
@@ -1166,7 +1167,7 @@
     if (MB_SUCCESS != rval)
       return rval;
     rval = mb->get_adjacencies( &edge_faces[0], edge_faces.size(), 3,
-                                false, face_hexes, MBInterface::UNION );
+                                false, face_hexes, Interface::UNION );
     if (MB_SUCCESS != rval)
       return rval;
     if (edge_hexes.size() != face_hexes.size())
@@ -1188,11 +1189,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode nothing_but_type( MBRange& range, MBEntityType type )
+ErrorCode nothing_but_type( Range& range, EntityType type )
 { 
 
     //make sure there's nothing but hexes in hex_ms
-  MBRange::iterator iter, end_iter;
+  Range::iterator iter, end_iter;
   iter = range.begin();
   end_iter = range.end();
 
@@ -1206,29 +1207,29 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode check_esets(MBInterface * MB, const int num_sets) 
+ErrorCode check_esets(Interface * MB, const int num_sets) 
 {
   int entity_sets_size;
-  MBErrorCode result = MB->get_number_entities_by_type(0, MBENTITYSET, entity_sets_size);
+  ErrorCode result = MB->get_number_entities_by_type(0, MBENTITYSET, entity_sets_size);
   if (MB_SUCCESS != result ||
       entity_sets_size != num_sets) return MB_FAILURE;
   
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_mesh_sets_test(MBInterface * MB, int flags)
+ErrorCode mb_mesh_sets_test(Interface * MB, int flags)
 {
 
-  MBRange temp_range;
-  std::vector<MBEntityHandle> temp_vector;
-  MBEntityType ent_type;
+  Range temp_range;
+  std::vector<EntityHandle> temp_vector;
+  EntityType ent_type;
 
-  MBEntityHandle ms_array[MBENTITYSET] = {0};
+  EntityHandle ms_array[MBENTITYSET] = {0};
   unsigned int number_array[MBENTITYSET] = {0};
   unsigned int num_dim_array[4] = { 0, 0, 0, 0 };
   int count, start_num_sets;
 
-  MBErrorCode result = MB->get_number_entities_by_type(0, MBENTITYSET, start_num_sets);
+  ErrorCode result = MB->get_number_entities_by_type(0, MBENTITYSET, start_num_sets);
   if (MB_SUCCESS != result) return result;
 
     //add entities to meshsets 
@@ -1361,7 +1362,7 @@
   }
 
     //----------TEST RECURSIVE OPERATIONS----------------//
-  MBEntityHandle recursive1, recursive2;
+  EntityHandle recursive1, recursive2;
   result = MB->create_meshset( MESHSET_SET, recursive1 );
   if( result != MB_SUCCESS )
     return result;
@@ -1483,7 +1484,7 @@
 
     //----------TEST BOOLEAN OPERATIONS----------------//
 
-  MBEntityHandle temp_ms1, temp_ms2; 
+  EntityHandle temp_ms1, temp_ms2; 
   result = MB->create_meshset(flags, temp_ms1);
   if(result  != MB_SUCCESS ) 
     return result;
@@ -1671,12 +1672,12 @@
   if (MB_SUCCESS != result) return result;
 
     //-------------Misc tests--------------
-  MBEntityHandle temp_ms3;
+  EntityHandle temp_ms3;
   result = MB->create_meshset(flags, temp_ms3);
   if(result  != MB_SUCCESS ) 
     return result;
 
-  MBEntityHandle handle_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10};
+  EntityHandle handle_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10};
   const int num_handle = sizeof(handle_array)/sizeof(handle_array[0]);
     //add ents to set
   result = MB->add_entities( temp_ms3, handle_array, num_handle );
@@ -1700,8 +1701,8 @@
   return MB_SUCCESS;
 }
 
-static bool compare_lists( std::vector<MBEntityHandle> vect,
-                           const MBEntityHandle* array, 
+static bool compare_lists( std::vector<EntityHandle> vect,
+                           const EntityHandle* array, 
                            int count,
                            bool ordered = true )
 {
@@ -1719,17 +1720,17 @@
 }
 
     //Test parent/child stuff in meshsets
-MBErrorCode mb_mesh_set_parent_child_test(MBInterface *MB)
+ErrorCode mb_mesh_set_parent_child_test(Interface *MB)
 {
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> list;
-  MBRange range;
-  MBRange::iterator iter;
+  ErrorCode rval;
+  std::vector<EntityHandle> list;
+  Range range;
+  Range::iterator iter;
   int count;
 
     // create a few mesh sets
   const int num_sets = 10;
-  MBEntityHandle sets[num_sets];
+  EntityHandle sets[num_sets];
   for (int i = 0; i < num_sets; ++i) {
     rval = MB->create_meshset( i % 2 ? MESHSET_SET : 0, sets[i] );
     if (MB_SUCCESS != rval) 
@@ -2209,33 +2210,33 @@
   return MB->delete_entities( sets, 9 );
 }
   
-MBErrorCode mb_mesh_sets_set_test( MBInterface* mb )
+ErrorCode mb_mesh_sets_set_test( Interface* mb )
 {
   return mb_mesh_sets_test( mb, MESHSET_SET );
 }
   
-MBErrorCode mb_mesh_sets_list_test( MBInterface* mb )
+ErrorCode mb_mesh_sets_list_test( Interface* mb )
 {
   return mb_mesh_sets_test( mb, MESHSET_ORDERED );
 } 
 
-// Verify that all query functions *append* to output MBRange
-MBErrorCode mb_mesh_set_appends( MBInterface* mb, int flags )
+// Verify that all query functions *append* to output Range
+ErrorCode mb_mesh_set_appends( Interface* mb, int flags )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // get all handles and subdivide into vertex and non-vertex ents
-  MBRange all_ents, verts, elems, results;
+  Range all_ents, verts, elems, results;
   rval = mb->get_entities_by_handle( 0, all_ents );
   if (MB_SUCCESS != rval)
     return rval;
-  MBRange::iterator ve = all_ents.upper_bound( MBVERTEX );
+  Range::iterator ve = all_ents.upper_bound( MBVERTEX );
   verts.merge( all_ents.begin(), ve );
   elems.merge( ve, all_ents.end() );
 
     // If we're not testing queries from the root set, 
     // create a set containing all the vertices
-  MBEntityHandle set = 0;
+  EntityHandle set = 0;
   if (flags != -1) {
     rval = mb->create_meshset( flags, set );
     if (MB_SUCCESS != rval)
@@ -2272,11 +2273,11 @@
     return MB_FAILURE;
   
     // choose a single entity for testing tag queries
-  MBEntityHandle entity = verts.front();
-  MBRange expected( elems );
+  EntityHandle entity = verts.front();
+  Range expected( elems );
   expected.insert( entity );
   
-  MBTag sparse, dense;
+  Tag sparse, dense;
   const int zero = 0, one = 1;
   const void* vals[] = {&one};
 
@@ -2295,7 +2296,7 @@
   rval = mb->get_entities_by_type_and_tag( set, 
                                            TYPE_FROM_HANDLE(entity),
                                            &sparse, 0, 1, 
-                                           results, MBInterface::UNION );
+                                           results, Interface::UNION );
   if (MB_SUCCESS != rval)
     return rval;
   if (results != expected)
@@ -2305,7 +2306,7 @@
   rval = mb->get_entities_by_type_and_tag( set, 
                                            TYPE_FROM_HANDLE(entity),
                                            &sparse, vals, 1, 
-                                           results, MBInterface::UNION );
+                                           results, Interface::UNION );
   if (MB_SUCCESS != rval)
     return rval;
   if (results != expected)
@@ -2326,7 +2327,7 @@
   rval = mb->get_entities_by_type_and_tag( set, 
                                            TYPE_FROM_HANDLE(entity),
                                            &dense, vals, 1, 
-                                           results, MBInterface::UNION );
+                                           results, Interface::UNION );
   if (MB_SUCCESS != rval)
     return rval;
   if (results != expected)
@@ -2335,36 +2336,36 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_mesh_set_set_appends( MBInterface* mb )
+ErrorCode mb_mesh_set_set_appends( Interface* mb )
 {
   return mb_mesh_set_appends( mb, MESHSET_SET );
 }
 
-MBErrorCode mb_mesh_set_list_appends( MBInterface* mb )
+ErrorCode mb_mesh_set_list_appends( Interface* mb )
 {
   return mb_mesh_set_appends( mb, MESHSET_ORDERED );
 }
 
-MBErrorCode mb_mesh_set_root_appends( MBInterface* mb )
+ErrorCode mb_mesh_set_root_appends( Interface* mb )
 {
   return mb_mesh_set_appends( mb, -1 );
 }
 
-MBErrorCode mb_mesh_set_set_replace_test( MBInterface*  )
+ErrorCode mb_mesh_set_set_replace_test( Interface*  )
 {
-  MBCore moab;
-  MBInterface* mb = &moab;
-  MBErrorCode rval;
-  MBRange r;
+  Core moab;
+  Interface* mb = &moab;
+  ErrorCode rval;
+  Range r;
     // create 10 vertices to put in set
   std::vector<double> coords(30);
   rval = mb->create_vertices( &coords[0], 10, r );
   CHKERR(rval);
-  std::vector<MBEntityHandle> verts(r.size());
+  std::vector<EntityHandle> verts(r.size());
   std::copy( r.begin(), r.end(), verts.begin() );
   r.clear();
     // create a set
-  MBEntityHandle set;
+  EntityHandle set;
   rval = mb->create_meshset( MESHSET_SET, set );
   CHKERR(rval);
     // put every other vertex in set
@@ -2374,14 +2375,14 @@
   CHKERR(rval);
   r.clear();
     // swap 3 of the vertices
-  MBEntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
-  MBEntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
+  EntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
+  EntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
   rval = mb->replace_entities( set, old_ents, new_ents, 3 );
   CHKERR(rval);
     // check new set contents
   rval = mb->get_entities_by_handle( set, r );
   CHKERR(rval);
-  MBRange r2;
+  Range r2;
   r2.insert( verts[0] );
   r2.insert( verts[1] );
   r2.insert( verts[9] );
@@ -2397,34 +2398,34 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_mesh_set_list_replace_test( MBInterface*  )
+ErrorCode mb_mesh_set_list_replace_test( Interface*  )
 {
-  MBCore moab;
-  MBInterface* mb = &moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface* mb = &moab;
+  ErrorCode rval;
     // create 10 vertices to put in set
-  MBRange r;
+  Range r;
   std::vector<double> coords(30);
   rval = mb->create_vertices( &coords[0], 10, r );
   CHKERR(rval);
-  std::vector<MBEntityHandle> verts(r.size());
+  std::vector<EntityHandle> verts(r.size());
   std::copy( r.begin(), r.end(), verts.begin() );
   r.clear();
     // create a set
-  MBEntityHandle set;
+  EntityHandle set;
   rval = mb->create_meshset( MESHSET_ORDERED, set );
   CHKERR(rval);
     // put all vertices in set, but add the first one a second time
-  std::vector<MBEntityHandle> list( verts );
+  std::vector<EntityHandle> list( verts );
   list.push_back( verts.front() );
   rval = mb->add_entities( set, &list[0], list.size() );
     // swap 3 of the vertices
-  MBEntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
-  MBEntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
+  EntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
+  EntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
   rval = mb->replace_entities( set, old_ents, new_ents, 3 );
   CHKERR(rval);
     // check new set contents
-  std::vector<MBEntityHandle> list2;
+  std::vector<EntityHandle> list2;
   rval = mb->get_entities_by_handle( set, list2 );
   CHKERR(rval);
   list[2] = verts[1];
@@ -2433,9 +2434,9 @@
   if (list != list2) {
     std::cerr << "Range does not contain expected values." << std::endl;
     std::cerr << "  Expected: ";
-    std::copy( list.begin(), list.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( list.begin(), list.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl << "  Actual  : ";
-    std::copy( list2.begin(), list2.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( list2.begin(), list2.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl;
     return MB_FAILURE;
   }
@@ -2449,9 +2450,9 @@
   if (list != list2) {
     std::cerr << "Range does not contain expected values." << std::endl;
     std::cerr << "  Expected: ";
-    std::copy( list.begin(), list.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( list.begin(), list.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl << "  Actual  : ";
-    std::copy( list2.begin(), list2.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( list2.begin(), list2.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl;
     return MB_FAILURE;
   }
@@ -2460,28 +2461,28 @@
 }
 
 /* Test the following changes to a meshset:
-  set       -> tracking
-  tracking  -> set
-  unordered -> ordered
-  ordered   -> unordered
+  set       MB-> tracking
+  tracking  MB-> set
+  unordered MB-> ordered
+  ordered   MB-> unordered
 */
-MBErrorCode mb_mesh_set_flag_test(MBInterface *mb) {
-  MBErrorCode rval;
+ErrorCode mb_mesh_set_flag_test(Interface *mb) {
+  ErrorCode rval;
     // create 10 vertices to put in set
-  MBRange verts;
+  Range verts;
   std::vector<double> coords(30);
   rval = mb->create_vertices( &coords[0], 10, verts );
   CHKERR(rval);
   
   // CHECK SET->TRACKING
   // create a set and add the verts
-  MBEntityHandle set;
+  EntityHandle set;
   rval = mb->create_meshset( MESHSET_SET, set );
   CHKERR(rval);
   rval = mb->add_entities( set, verts);
   CHKERR(rval);
   // the verts should not be tracking adjacencies
-  MBRange adj_sets;
+  Range adj_sets;
   rval = mb->get_adjacencies( verts, 4, false, adj_sets);
   CHKERR(rval);
   if(!adj_sets.empty()) {
@@ -2542,7 +2543,7 @@
   rval = mb->add_entities( set, &verts.front(), 1);
   CHKERR(rval);
   // unordered sets cannot hold duplicates so size shouldn't change
-  std::vector<MBEntityHandle> entities;
+  std::vector<EntityHandle> entities;
   rval = mb->get_entities_by_handle( set, entities );
   if(10 != entities.size()) {
     std::cerr << "set should not hold duplicate entities" << std::endl;
@@ -2599,9 +2600,9 @@
   // in mbtest1.g  (all other values are 0.
 static const unsigned int num_entities[MBMAXTYPE] = {47,12,18,8,22,8};
 
-MBErrorCode mb_delete_mesh_test(MBInterface *gMB)
+ErrorCode mb_delete_mesh_test(Interface *gMB)
 {
-  MBErrorCode error = MB_SUCCESS;
+  ErrorCode error = MB_SUCCESS;
 
     // Lets also test the global MB pointer (gMB) here.
   error = gMB->delete_mesh();
@@ -2615,7 +2616,7 @@
     return error;
 
 
-  MBRange entities;
+  Range entities;
   error = gMB->get_entities_by_type(0,  MBVERTEX, entities);
   if (error != MB_SUCCESS)
     return error;
@@ -2624,8 +2625,8 @@
   if ( entities.size() != num_entities[MBVERTEX] )
     return MB_FAILURE;
 
-  MBTag tag_handle = 0;
-  MBEntityType type;
+  Tag tag_handle = 0;
+  EntityType type;
     // step through each element type
   for (type = MBEDGE; type != MBENTITYSET; type++)
   {
@@ -2650,19 +2651,19 @@
 }
 
 
-MBErrorCode mb_meshset_tracking_test( MBInterface *MB )
+ErrorCode mb_meshset_tracking_test( Interface *MB )
 {
 
     //read in a file so you have some data in the database
   std::string file_name = TestDir + "/mbtest1.g";
-  MBErrorCode error = MB->load_mesh(file_name.c_str(), NULL, 0);
+  ErrorCode error = MB->load_mesh(file_name.c_str(), NULL, 0);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle ms1, ms2, ms3;
+  EntityHandle ms1, ms2, ms3;
 
     //create meshsets 
-  MBErrorCode result = MB->create_meshset( MESHSET_TRACK_OWNER | MESHSET_ORDERED, ms1 ) ;
+  ErrorCode result = MB->create_meshset( MESHSET_TRACK_OWNER | MESHSET_ORDERED, ms1 ) ;
   if(result != MB_SUCCESS )
     return result;
   result = MB->create_meshset( MESHSET_SET | MESHSET_TRACK_OWNER, ms2 ) ;
@@ -2673,29 +2674,29 @@
     return result;
 
     // get all hexes 
-  MBRange hexes;
+  Range hexes;
   result = MB->get_entities_by_type(0, MBHEX, hexes);
   if(result != MB_SUCCESS )
     return result;
 
     // get all tris 
-  MBRange tris;
+  Range tris;
   result = MB->get_entities_by_type(0, MBTRI, tris );
   if(result != MB_SUCCESS )
     return result;
 
     // get all tets 
-  MBRange temp_range;
+  Range temp_range;
   result = MB->get_entities_by_type(0, MBTET, temp_range);
   if(result != MB_SUCCESS )
     return result;
 
     //copy all the tets from the range into a vector 'tets'
-  std::vector<MBEntityHandle> tets( temp_range.size() );
+  std::vector<EntityHandle> tets( temp_range.size() );
   std::copy(temp_range.begin(), temp_range.end(), tets.begin() );
 
     //Quick check on 'get_entities_by_dimension()'
-  MBRange dim_3_range;
+  Range dim_3_range;
   result = MB->get_entities_by_dimension(0, 3, dim_3_range) ;
   if(result != MB_SUCCESS )
     return result;
@@ -2731,10 +2732,10 @@
   if(result != MB_SUCCESS )
     return result;
 
-  MBRange::iterator iter;
+  Range::iterator iter;
   iter = tris.begin();
 
-  std::vector< MBEntityHandle > temp_vec;
+  std::vector< EntityHandle > temp_vec;
 
     //ask a tri which meshsets it is in
   result = MB->get_adjacencies( &(*iter), 1, 4, false, temp_vec ) ;
@@ -2747,7 +2748,7 @@
 
     //ask a tet which meshsets it is in
   temp_vec.clear();
-  std::vector<MBEntityHandle>::iterator vec_iter = tets.begin();
+  std::vector<EntityHandle>::iterator vec_iter = tets.begin();
   result = MB->get_adjacencies( &(*vec_iter), 1, 4, false, temp_vec ) ;
   if(result != MB_SUCCESS )
     return result;
@@ -2859,32 +2860,32 @@
 
 }
 
-MBErrorCode mb_write_mesh_test(MBInterface *MB)
+ErrorCode mb_write_mesh_test(Interface *MB)
 {
   std::string file_name = "mb_write.g";
 
     // no need to get lists, write out the whole mesh
-  MBErrorCode result = MB->write_mesh(file_name.c_str());
+  ErrorCode result = MB->write_mesh(file_name.c_str());
   if(result != MB_SUCCESS )
     return result;
 
     //---------The following tests outputting meshsets that are in meshsets of blocks ---/
 
     //lets create a block meshset and put some entities and meshsets into it
-  MBEntityHandle block_ms;
+  EntityHandle block_ms;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, block_ms );
   if(result != MB_SUCCESS )
     return result;
 
     //make another meshset to put quads in, so SHELLs can be written out
-  MBEntityHandle block_of_shells;
+  EntityHandle block_of_shells;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, block_of_shells); 
   if(result != MB_SUCCESS )
     return result;
 
     //tag the meshset so it's a block, with id 100
   int id = 100;
-  MBTag tag_handle;
+  Tag tag_handle;
   result = MB->tag_get_handle( MATERIAL_SET_TAG_NAME, tag_handle ) ;
   if(result != MB_SUCCESS )
     return result;
@@ -2906,17 +2907,17 @@
     return result;
 
     //get some entities (tets) 
-  MBRange temp_range;
+  Range temp_range;
   result = MB->get_entities_by_type(0,  MBHEX, temp_range ) ;
   if(result != MB_SUCCESS )
     return result;
 
-  MBRange::iterator iter, end_iter;
+  Range::iterator iter, end_iter;
   iter = temp_range.begin();
   end_iter = temp_range.end();
 
     //add evens to 'block_ms'
-  std::vector<MBEntityHandle> temp_vec; 
+  std::vector<EntityHandle> temp_vec; 
   for(; iter != end_iter; iter++)
   {
     if( ID_FROM_HANDLE( *iter ) % 2 == 0 ) 
@@ -2928,7 +2929,7 @@
 
 
     //make another meshset
-  MBEntityHandle ms_of_block_ms;
+  EntityHandle ms_of_block_ms;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, ms_of_block_ms);
   if(result != MB_SUCCESS )
     return result;
@@ -2954,7 +2955,7 @@
     //---------------testing sidesets----------------/
 
     //lets create a sideset meshset and put some entities and meshsets into it
-  MBEntityHandle sideset_ms;
+  EntityHandle sideset_ms;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, sideset_ms );
   if(result != MB_SUCCESS )
     return result;
@@ -2990,7 +2991,7 @@
     return result;
 
     //make another meshset
-  MBEntityHandle ms_of_sideset_ms;
+  EntityHandle ms_of_sideset_ms;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, ms_of_sideset_ms);
   if(result != MB_SUCCESS )
     return result;
@@ -3015,7 +3016,7 @@
     //---------test sense on meshsets (reverse/foward)-------//
 
     //get all quads whose x-coord = 2.5 and put them into a meshset_a 
-  MBEntityHandle meshset_a;
+  EntityHandle meshset_a;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, meshset_a );
   if(result != MB_SUCCESS )
     return result;
@@ -3025,7 +3026,7 @@
   if(result != MB_SUCCESS )
     return result;
 
-  std::vector<MBEntityHandle> nodes, entity_vec;
+  std::vector<EntityHandle> nodes, entity_vec;
   std::copy(temp_range.begin(), temp_range.end(), std::back_inserter(entity_vec));
   result = MB->get_connectivity(&entity_vec[0], entity_vec.size(), nodes);
   if(result != MB_SUCCESS ) 
@@ -3038,7 +3039,7 @@
     return result;
   
   unsigned int k = 0;
-  for(MBRange::iterator it = temp_range.begin(); it != temp_range.end(); it++) {
+  for(Range::iterator it = temp_range.begin(); it != temp_range.end(); it++) {
     if( coords[12*k] == 2.5 && coords[12*k+3] == 2.5 &&
         coords[12*k+6] == 2.5 && coords[12*k+9] == 2.5 )
       temp_vec.push_back(*it);
@@ -3052,7 +3053,7 @@
     return result;
 
     //put these quads into a different meshset_b and tag them with a reverse sense tag
-  MBEntityHandle meshset_b;
+  EntityHandle meshset_b;
   result = MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, meshset_b );
   if(result != MB_SUCCESS ) 
     return result;
@@ -3089,7 +3090,7 @@
   temp_vec.clear();
   for(; iter != end_iter; iter++ )
   {
-    std::vector<MBEntityHandle> nodes;
+    std::vector<EntityHandle> nodes;
     result = MB->get_connectivity( &(*iter), 1, nodes );
     if(result != MB_SUCCESS)
       return result;
@@ -3117,7 +3118,7 @@
     }
   }
 
-  MBEntityHandle meshset_c;
+  EntityHandle meshset_c;
   MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, meshset_c );
     
   
@@ -3135,7 +3136,7 @@
 
 
     //create another meshset_abc, adding meshset_a, meshset_b, meshset_c 
-  MBEntityHandle meshset_abc;
+  EntityHandle meshset_abc;
   MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, meshset_abc );
 
   temp_vec.clear();
@@ -3162,7 +3163,7 @@
 
 
     //lets create a nodeset meshset and put some entities and meshsets into it
-  MBEntityHandle nodeset_ms;
+  EntityHandle nodeset_ms;
   MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, nodeset_ms );
 
     //tag the meshset so it's a nodeset, with id 119
@@ -3183,14 +3184,14 @@
 
 
     //get all the nodes of the tris
-  MBRange nodes_of_quads;
+  Range nodes_of_quads;
   iter = temp_range.begin();
   end_iter = temp_range.end();
 
 
   for(; iter != end_iter; iter++ )
   {
-    std::vector<MBEntityHandle> nodes;
+    std::vector<EntityHandle> nodes;
     result = MB->get_connectivity( &(*iter), 1, nodes);
     if(result != MB_SUCCESS)
       return result;
@@ -3214,7 +3215,7 @@
 
 
     //make another meshset
-  MBEntityHandle ms_of_nodeset_ms;
+  EntityHandle ms_of_nodeset_ms;
   MB->create_meshset(MESHSET_ORDERED | MESHSET_TRACK_OWNER, ms_of_nodeset_ms);
 
     //add some entities to it
@@ -3234,19 +3235,19 @@
 
     // no need to get lists, write out the whole mesh
   file_name = "mb_write2.g";
-  std::vector<MBEntityHandle> output_list;
+  std::vector<EntityHandle> output_list;
   output_list.push_back( block_ms );
   output_list.push_back( sideset_ms );
   output_list.push_back( meshset_abc );
   output_list.push_back( nodeset_ms );
   output_list.push_back( block_of_shells );
-  MBErrorCode error = MB->write_mesh(file_name.c_str(), &output_list[0], output_list.size());
+  ErrorCode error = MB->write_mesh(file_name.c_str(), &output_list[0], output_list.size());
 
   return error;
 }
 
 
-MBErrorCode mb_higher_order_test(MBInterface *MB)
+ErrorCode mb_higher_order_test(Interface *MB)
 {
   double nodes_array [7][3];
 
@@ -3274,8 +3275,8 @@
 
 
     //create the nodes
-  std::vector<MBEntityHandle> connectivity(8);
-  MBEntityHandle node_handle;
+  std::vector<EntityHandle> connectivity(8);
+  EntityHandle node_handle;
   int i;
   for( i=0; i<7; i++)
   {
@@ -3285,13 +3286,13 @@
   }
 
     //create the higher order tri
-  MBEntityHandle tri_handle;
-  MBErrorCode result = MB->create_element(MBTRI, &connectivity[0], 6, tri_handle);
+  EntityHandle tri_handle;
+  ErrorCode result = MB->create_element(MBTRI, &connectivity[0], 6, tri_handle);
   if(result != MB_SUCCESS)
     return result;
 
     //create the higher order tri
-  std::vector<MBEntityHandle> other_conn(3);
+  std::vector<EntityHandle> other_conn(3);
 
   double other_nodes[3][3];
   other_nodes[0][0] = 1.999;
@@ -3311,13 +3312,13 @@
     other_conn[i] = node_handle;
   }
 
-  MBEntityHandle other_tri_handle;
+  EntityHandle other_tri_handle;
   result = MB->create_element(MBTRI, &other_conn[0], 3, other_tri_handle);
   if(result != MB_SUCCESS)
     return result;
 
     //get the connectivity now
-  std::vector<MBEntityHandle> retrieved_conn; 
+  std::vector<EntityHandle> retrieved_conn; 
 
   result = MB->get_connectivity(&tri_handle, 1, retrieved_conn) ;
   if(result != MB_SUCCESS)
@@ -3337,7 +3338,7 @@
       return MB_FAILURE;
 
     // now let's just try getting the topological connectivity (the 3 corner vertices)
-  std::vector<MBEntityHandle> topo_conn; 
+  std::vector<EntityHandle> topo_conn; 
   result = MB->get_connectivity(&other_tri_handle, 1, topo_conn, true) ;
   if(result != MB_SUCCESS)
     return result;
@@ -3349,10 +3350,10 @@
     if (topo_conn[k] != retrieved_conn[k] )
       return MB_FAILURE;
 
-    // short check to make sure that MBCore::handle_from_id() works
+    // short check to make sure that Core::handle_from_id() works
   unsigned long handle_id = MB->id_from_handle( node_handle); 
 
-  MBEntityHandle test_handle; 
+  EntityHandle test_handle; 
   result = MB->handle_from_id( MBVERTEX, handle_id, test_handle ); 
   if(result != MB_SUCCESS)
     return result;
@@ -3387,13 +3388,13 @@
 
 }
 
-MBErrorCode mb_bit_tags_test(MBInterface* MB)
+ErrorCode mb_bit_tags_test(Interface* MB)
 {
 
-  MBTag bit_tag;
-  MBRange entities;
+  Tag bit_tag;
+  Range entities;
   MB->get_entities_by_type(0, MBVERTEX, entities);
-  MBErrorCode success = MB_SUCCESS;
+  ErrorCode success = MB_SUCCESS;
 
   if(MB->tag_create("bit on vertex", 3, MB_TAG_BIT, bit_tag, NULL) != MB_SUCCESS)
   {
@@ -3401,7 +3402,7 @@
     return MB_FAILURE;
   }
 
-  MBRange::iterator iter;
+  Range::iterator iter;
   unsigned char bits;
   for(iter = entities.begin();
       iter != entities.end(); ++iter)
@@ -3436,7 +3437,7 @@
       return MB_FAILURE;
 
   // test vector-based query for all vertices
-  std::vector<MBEntityHandle> verts(entities.begin(), entities.end());
+  std::vector<EntityHandle> verts(entities.begin(), entities.end());
   success = MB->tag_get_data( bit_tag, &verts[0], verts.size(), &data[0] );
   if (MB_SUCCESS != success) return success;
   i = data.begin();
@@ -3446,7 +3447,7 @@
   
   // test default value
   const unsigned char default_bits = '\005'; // 0000 0101
-  MBTag tag2;
+  Tag tag2;
   success = MB->tag_create( "bit with default", 4, MB_TAG_BIT, tag2, &default_bits );
   if (MB_SUCCESS != success) {
     cout << "Failed to create bit tag with default value" << std::endl;
@@ -3455,7 +3456,7 @@
   
   // set value to zero on a single vertex
   bits = 0;
-  MBEntityHandle zh = verts[verts.size()/2];
+  EntityHandle zh = verts[verts.size()/2];
   success = MB->tag_set_data( tag2, &zh, 1, &bits );
   if (MB_SUCCESS != success)
     return success;
@@ -3478,11 +3479,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_tags_test(MBInterface *MB)
+ErrorCode mb_tags_test(Interface *MB)
 {
 
-  MBTag stale_bits, stale_dense, stale_sparse;
-  MBErrorCode result = MB->tag_create("stale data", 5, MB_TAG_BIT, stale_bits, NULL);
+  Tag stale_bits, stale_dense, stale_sparse;
+  ErrorCode result = MB->tag_create("stale data", 5, MB_TAG_BIT, stale_bits, NULL);
   if (MB_SUCCESS != result)
     return result;
      
@@ -3495,7 +3496,7 @@
     return result;
 
   double coords[3] = { 0,0,0 };
-  MBEntityHandle stale_handle1, stale_handle2;
+  EntityHandle stale_handle1, stale_handle2;
   result = MB->create_vertex( coords, stale_handle1 );
   if (MB_SUCCESS != result)
     return result;
@@ -3559,7 +3560,7 @@
       return MB_FAILURE;
 
     def_data = 3;
-    MBErrorCode stale_result = MB->tag_get_data(stale_sparse, &stale_handle2, 1, &def_data);
+    ErrorCode stale_result = MB->tag_get_data(stale_sparse, &stale_handle2, 1, &def_data);
       // we are supposed to fail here
     if(stale_result != MB_TAG_NOT_FOUND)
       return MB_FAILURE;
@@ -3575,10 +3576,10 @@
 
 
     //get all blocks with material tag and with tag_value of 1 (should only be 1)
-  MBRange entities;
+  Range entities;
   int value = 1;
   const void *dum_ptr = &value;
-  MBTag material_tag;
+  Tag material_tag;
   result = MB->tag_get_handle( MATERIAL_SET_TAG_NAME, material_tag);
   if (MB_SUCCESS != result)
     return result;
@@ -3591,18 +3592,18 @@
     return MB_FAILURE;
  
     //add a dense tag to hexes
-  MBTag junk_tag;
+  Tag junk_tag;
   if(MB->tag_create( "junk_tag", sizeof(int), MB_TAG_DENSE, junk_tag, 0) 
      != MB_SUCCESS)
     return MB_FAILURE;    
 
     //Set the dense tag on 5 hexes to 3489 
-  MBRange test_range;
+  Range test_range;
   result = MB->get_entities_by_type(0,  MBHEX, test_range ) ;
   if(result != MB_SUCCESS)
     return result;
 
-  MBRange::iterator iter, end_iter;
+  Range::iterator iter, end_iter;
   iter = test_range.begin();
   end_iter = test_range.end();
 
@@ -3644,7 +3645,7 @@
 
     // test fetch by tag value again, this time limiting the results
     // to the contents of an entity set
-  MBEntityHandle meshset;
+  EntityHandle meshset;
   result = MB->create_meshset( MESHSET_SET, meshset );
   if (MB_SUCCESS != result)
     return result;
@@ -3675,7 +3676,7 @@
 
 
     // now try the query with an empty meshset, expecting to get back
-    // an empty MBRange
+    // an empty Range
 
   result = MB->create_meshset( MESHSET_SET, meshset );
   if (MB_SUCCESS != result)
@@ -3699,15 +3700,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_common_tag_test( MBTagType storage, MBInterface* mb )
+ErrorCode mb_common_tag_test( TagType storage, Interface* mb )
 {
   char tagname[64];
   sprintf( tagname, "t%d", rand() );
   
-  MBTag tag;
-  const MBEntityHandle def_val = ~(MBEntityHandle)0;
-  MBErrorCode rval = mb->tag_create( tagname, 
-                                     sizeof(MBEntityHandle), 
+  Tag tag;
+  const EntityHandle def_val = ~(EntityHandle)0;
+  ErrorCode rval = mb->tag_create( tagname, 
+                                     sizeof(EntityHandle), 
                                      storage, 
                                      MB_TYPE_HANDLE, 
                                      tag, 
@@ -3716,17 +3717,17 @@
     return rval;
   
   
-  MBRange entities;
+  Range entities;
   mb->get_entities_by_handle( 0, entities );
   if (entities.empty())
     return MB_FAILURE;
   
     // set tag on every other entity to be the entities handle
-  MBRange::const_iterator i;
+  Range::const_iterator i;
   bool odd = true;
   for (i = entities.begin(); i != entities.end(); ++i, odd = !odd) {
     if (odd) {
-      const MBEntityHandle h = *i;
+      const EntityHandle h = *i;
       rval = mb->tag_set_data( tag, &h, 1, &h );
       if (MB_SUCCESS != rval)
         return rval;
@@ -3736,7 +3737,7 @@
     // check values on every entity -- expect default for every other entity
   odd = true;
   for (i = entities.begin(); i != entities.end(); ++i, odd = !odd) {
-    MBEntityHandle val = 0;
+    EntityHandle val = 0;
     rval = mb->tag_get_data( tag, &*i, 1, &val );
     if (MB_SUCCESS != rval)
       return rval;
@@ -3752,7 +3753,7 @@
   }
   
     // set tag values on all entities
-  std::vector<MBEntityHandle> values( entities.size() );
+  std::vector<EntityHandle> values( entities.size() );
   std::copy( entities.begin(), entities.end(), values.begin() );
   rval = mb->tag_set_data( tag, entities, &values[0] );
   if (MB_SUCCESS != rval)
@@ -3760,7 +3761,7 @@
   
     // check values on every entity -- expect default for every other entity
   for (i = entities.begin(); i != entities.end(); ++i) {
-    MBEntityHandle val = 0;
+    EntityHandle val = 0;
     rval = mb->tag_get_data( tag, &*i, 1, &val );
     if (MB_SUCCESS != rval)
       return rval;
@@ -3770,10 +3771,10 @@
   
     // find each entity by tag value
   for (i = entities.begin(); i != entities.end(); ++i) {
-    const MBEntityHandle h = *i;
-    const MBEntityType type = mb->type_from_handle( h );
+    const EntityHandle h = *i;
+    const EntityType type = mb->type_from_handle( h );
     const void* const tag_vals[] = { &h };
-    MBRange result;
+    Range result;
     rval = mb->get_entities_by_type_and_tag( 0, type, &tag, tag_vals, 1, result );
     if (MB_SUCCESS != rval)
       return rval;
@@ -3787,21 +3788,21 @@
 }
 
 
-MBErrorCode mb_dense_tag_test( MBInterface* mb )
+ErrorCode mb_dense_tag_test( Interface* mb )
 {
   return mb_common_tag_test( MB_TAG_DENSE, mb );
 }
 
-MBErrorCode mb_sparse_tag_test( MBInterface* mb )
+ErrorCode mb_sparse_tag_test( Interface* mb )
 {
   return mb_common_tag_test( MB_TAG_SPARSE, mb );
 }
   
 // class to offset hex center nodes
-class OffsetHexCenterNodes : public MBInterface::HONodeAddedRemoved
+class OffsetHexCenterNodes : public Interface::HONodeAddedRemoved
 {
 public:
-  OffsetHexCenterNodes(MBInterface* mb, double x, double y, double z)
+  OffsetHexCenterNodes(Interface* mb, double x, double y, double z)
       : gMB(mb)
     { 
       mOffset[0] = x; mOffset[1] = y; mOffset[2] = z; 
@@ -3809,7 +3810,7 @@
     
   ~OffsetHexCenterNodes(){}
 
-  void node_added(MBEntityHandle node, MBEntityHandle)
+  void node_added(EntityHandle node, EntityHandle)
     {
       gMB->get_coords(&node, 1, mCoords);
       mCoords[0] += mOffset[0];
@@ -3819,17 +3820,17 @@
     }
 
     //do nothing
-  void node_removed( MBEntityHandle /*node*/) {}
+  void node_removed( EntityHandle /*node*/) {}
 
 private:
-  MBInterface* gMB;
+  Interface* gMB;
   double mCoords[3];
   double mOffset[3];
 };
 
-MBErrorCode mb_entity_conversion_test(MBInterface *MB)
+ErrorCode mb_entity_conversion_test(Interface *MB)
 {
-  MBErrorCode error = MB->delete_mesh();
+  ErrorCode error = MB->delete_mesh();
   if (error != MB_SUCCESS)
     return error;
 
@@ -3839,8 +3840,8 @@
   if (error != MB_SUCCESS)
     return error;
 
-  MBRange entities;
-  MBEntityHandle meshset;
+  Range entities;
+  EntityHandle meshset;
   MB->create_meshset(MESHSET_SET, meshset);
   
   MB->get_entities_by_type(0, MBHEX, entities);
@@ -4067,16 +4068,16 @@
     return error;
   
     // skin the model
-  for(MBRange::iterator tet_iter = entities.begin(); tet_iter != entities.end(); ++tet_iter)
+  for(Range::iterator tet_iter = entities.begin(); tet_iter != entities.end(); ++tet_iter)
   {
-    std::vector<MBEntityHandle> adj;
+    std::vector<EntityHandle> adj;
     error = MB->get_adjacencies(&(*tet_iter), 1, 2, true, adj);
     if (MB_SUCCESS != error)
       return error;
-    for(std::vector<MBEntityHandle>::iterator tri_iter = adj.begin();
+    for(std::vector<EntityHandle>::iterator tri_iter = adj.begin();
         tri_iter != adj.end(); ++tri_iter)
     {
-      std::vector<MBEntityHandle> up_adj;
+      std::vector<EntityHandle> up_adj;
       MB->get_adjacencies(&(*tri_iter), 1, 3, false, up_adj);
       if(up_adj.size() > 1) {
         error = MB->delete_entities(&(*tri_iter), 1);
@@ -4087,16 +4088,16 @@
   }
 
     // create a meshset of the skin
-  MBEntityHandle export_meshset;
+  EntityHandle export_meshset;
   MB->create_meshset( MESHSET_SET, export_meshset);
-  MBTag material_tag;
+  Tag material_tag;
   MB->tag_get_handle(MATERIAL_SET_TAG_NAME, material_tag);
   int block_id = 100;
   MB->tag_set_data(material_tag, &export_meshset, 1, &block_id);
   entities.clear();
   MB->get_entities_by_type(0, MBTRI, entities);
     // remove the first few tri's for fun
-  MBRange tmp_ents;
+  Range tmp_ents;
   tmp_ents.insert(*entities.begin());
   entities.erase(entities.begin());
   tmp_ents.insert(*entities.begin());
@@ -4112,8 +4113,8 @@
   MB->convert_entities(export_meshset, true, true, false);
 
     // make sure our first few tri's were untouched
-  std::vector<MBEntityHandle> conn(3);
-  for(MBRange::iterator kter=tmp_ents.begin(); kter != tmp_ents.end(); ++kter)
+  std::vector<EntityHandle> conn(3);
+  for(Range::iterator kter=tmp_ents.begin(); kter != tmp_ents.end(); ++kter)
   {
     MB->get_connectivity(&(*kter), 1, conn);
     if(conn.size() != 3)
@@ -4158,10 +4159,10 @@
 //! and only get 4 (not 5) edges.
 //!
 
-MBErrorCode mb_forced_adjacencies_test(MBInterface *MB)
+ErrorCode mb_forced_adjacencies_test(Interface *MB)
 {
     //! first clean up any existing mesh.
-  MBErrorCode error = MB->delete_mesh();
+  ErrorCode error = MB->delete_mesh();
   if (error != MB_SUCCESS)
     return error;
 
@@ -4184,7 +4185,7 @@
   double node_coord5[3] = {1., 1., 0.};
   double node_coord6[3] = {2., 1., 0.};
 
-  MBEntityHandle node1, node2, node3, node4, node5, node6;
+  EntityHandle node1, node2, node3, node4, node5, node6;
   error = MB->create_vertex(node_coord1, node1);
   if (error != MB_SUCCESS)
     return error;
@@ -4209,9 +4210,9 @@
   if (error != MB_SUCCESS)
     return error;
 
-  std::vector<MBEntityHandle> conn(4);
+  std::vector<EntityHandle> conn(4);
     //! create the first quad
-  MBEntityHandle              quad1;
+  EntityHandle              quad1;
   conn[0] = node1;
   conn[1] = node2;
   conn[2] = node5;
@@ -4221,7 +4222,7 @@
     return error;
 
     //! create the second quad
-  MBEntityHandle              quad2;
+  EntityHandle              quad2;
   conn[0] = node2;
   conn[1] = node3;
   conn[2] = node6;
@@ -4231,7 +4232,7 @@
     return error;
 
     //! create the edges
-  MBEntityHandle edge1;
+  EntityHandle edge1;
   conn.resize(2);
   conn[0] = node1;
   conn[1] = node2;
@@ -4239,49 +4240,49 @@
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge2;
+  EntityHandle edge2;
   conn[0] = node2;
   conn[1] = node3;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge2);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge3;
+  EntityHandle edge3;
   conn[0] = node1;
   conn[1] = node4;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge3);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge4;
+  EntityHandle edge4;
   conn[0] = node2;
   conn[1] = node5;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge4);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge5;
+  EntityHandle edge5;
   conn[0] = node2;
   conn[1] = node5;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge5);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge6;
+  EntityHandle edge6;
   conn[0] = node3;
   conn[1] = node6;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge6);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge7;
+  EntityHandle edge7;
   conn[0] = node4;
   conn[1] = node5;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge7);
   if (error != MB_SUCCESS)
     return error;
 
-  MBEntityHandle edge8;
+  EntityHandle edge8;
   conn[0] = node5;
   conn[1] = node6;
   error = MB->create_element(MBEDGE, &conn[0], 2, edge8);
@@ -4294,7 +4295,7 @@
     return MB_FAILURE;
 
     //! Now that the geometry is created start adding the adjacency information
-  std::vector<MBEntityHandle> edge_adjacencies1(4);
+  std::vector<EntityHandle> edge_adjacencies1(4);
   edge_adjacencies1[0] = edge1;
   edge_adjacencies1[1] = edge4;
   edge_adjacencies1[2] = edge7;
@@ -4307,7 +4308,7 @@
   if (error != MB_SUCCESS)
     return error;
 
-  std::vector<MBEntityHandle> edge_adjacencies2(4);
+  std::vector<EntityHandle> edge_adjacencies2(4);
   edge_adjacencies2[0] = edge2;
   edge_adjacencies2[1] = edge6;
   edge_adjacencies2[2] = edge8;
@@ -4317,7 +4318,7 @@
     return error;
 
     //! now get the adjacencies of each quad.
-  std::vector<MBEntityHandle> quad1_adjacencies;
+  std::vector<EntityHandle> quad1_adjacencies;
   error = MB->get_adjacencies(&(quad1), 1, 1, false, quad1_adjacencies);
   if (error != MB_SUCCESS)
     return error;
@@ -4329,7 +4330,7 @@
   if (quad1_adjacencies != edge_adjacencies1)
     return MB_FAILURE;
   
-  std::vector<MBEntityHandle> quad2_adjacencies;
+  std::vector<EntityHandle> quad2_adjacencies;
   error = MB->get_adjacencies(&(quad2), 1, 1, false, quad2_adjacencies);
   if (error != MB_SUCCESS)
     return error;
@@ -4341,7 +4342,7 @@
     return MB_FAILURE;
 
     //! try getting the adjacency of edge1 (should be quad1)
-  std::vector<MBEntityHandle> edge1_adjacencies;
+  std::vector<EntityHandle> edge1_adjacencies;
   error = MB->get_adjacencies(&(edge1), 1, 2, false, edge1_adjacencies);
   if (error != MB_SUCCESS)
     return error;
@@ -4355,7 +4356,7 @@
     return error;
 
     //! try getting the adjacency of edge6 (should be none)
-  std::vector<MBEntityHandle> edge6_adjacencies;
+  std::vector<EntityHandle> edge6_adjacencies;
   error = MB->get_adjacencies(&(edge6), 1, 2, false, edge6_adjacencies);
   if (error != MB_SUCCESS)
     return error;
@@ -4367,17 +4368,17 @@
     //! Now seal up the "gap" caused by edges 4 and 5.  Remove edge5
     //! from the adjacencies of quad2 and add edge 4 to quad2.
 
-  std::vector<MBEntityHandle> edge5_adjacencies(1, edge5);
+  std::vector<EntityHandle> edge5_adjacencies(1, edge5);
   error = MB->remove_adjacencies(quad2, &edge5_adjacencies[0], edge5_adjacencies.size());
   if (error != MB_SUCCESS)
     return error;
 
 
-  std::vector<MBEntityHandle> edge4_adjacencies(1, edge4);
+  std::vector<EntityHandle> edge4_adjacencies(1, edge4);
   error = MB->add_adjacencies(quad2, &edge4_adjacencies[0], edge4_adjacencies.size(), true);
   
     //! get the adjacencies of edge4 and it should return both quads.
-  std::vector<MBEntityHandle> quad_adjacencies;
+  std::vector<EntityHandle> quad_adjacencies;
   error = MB->get_adjacencies(&(edge4), 1, 2, false, quad_adjacencies);
   if (error != MB_SUCCESS)
     return error;
@@ -4401,7 +4402,7 @@
   return MB_SUCCESS;
 }
 
-/*bool lessnodesZ(const MBEntityHandle entity_handle1, const MBEntityHandle entity_handle2) 
+/*bool lessnodesZ(const EntityHandle entity_handle1, const EntityHandle entity_handle2) 
   {
   double coords1[3], coords2[3];
   gMB->get_coords(entity_handle1, coords1);
@@ -4410,10 +4411,10 @@
   return coords2[2] < coords1[2];
   }*/
 
-/*void sort_verts(MBRange vertices) 
+/*void sort_verts(Range vertices) 
   {
-  std::vector<MBEntityHandle> vert_vec(vertices.size());
-  MBRange::const_iterator iter;
+  std::vector<EntityHandle> vert_vec(vertices.size());
+  Range::const_iterator iter;
   for (iter = vertices.begin(); iter != vertices.end(); iter++) 
   vert_vec.push_back(*iter);
   vert_vec.sort(lessnodesZ);
@@ -4433,13 +4434,13 @@
 
   return false;
 }
-MBErrorCode find_coincident_nodes(MBInterface* gMB, MBRange vertices,
-                                  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > &coin_nodes)
+ErrorCode find_coincident_nodes(Interface* gMB, Range vertices,
+                                  std::vector< std::pair<EntityHandle,EntityHandle> > &coin_nodes)
 {
   double first_coords[3], second_coords[3];
-  MBRange::const_iterator iter, jter;
-  std::pair<MBEntityHandle, MBEntityHandle> coincident_pair;
-  MBErrorCode result;
+  Range::const_iterator iter, jter;
+  std::pair<EntityHandle, EntityHandle> coincident_pair;
+  ErrorCode result;
 
   for (iter = vertices.begin(); iter != vertices.end(); iter++)
   {
@@ -4467,13 +4468,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode find_coincident_elements(MBInterface* gMB, MBRange entities, int num_nodes,
-                                     std::vector< std::pair<MBEntityHandle,MBEntityHandle> > &coin)
+ErrorCode find_coincident_elements(Interface* gMB, Range entities, int num_nodes,
+                                     std::vector< std::pair<EntityHandle,EntityHandle> > &coin)
 {
   double coords1[8][3], coords2[8][3];
-  MBRange::iterator iter, jter;
-  std::vector<MBEntityHandle> conn(8);
-  std::pair<MBEntityHandle, MBEntityHandle> coincident_pair;
+  Range::iterator iter, jter;
+  std::vector<EntityHandle> conn(8);
+  std::pair<EntityHandle, EntityHandle> coincident_pair;
   int i = 0,/* j = 0,*/ ii = 0;
 
   for(iter = entities.begin(); iter != entities.end(); iter++)
@@ -4599,13 +4600,13 @@
 }
 
 
-MBErrorCode mb_merge_test(MBInterface *MB)
+ErrorCode mb_merge_test(Interface *MB)
 { 
   MB->delete_mesh();
   time_t begin_time = clock();
   unsigned int i;
-  MBErrorCode result;
-  MBSkinner MBSkinner_Obj(MB);
+  ErrorCode result;
+  Skinner Skinner_Obj(MB);
 
   std::string test_files[] = {std::string("cell1.gen"),
                               std::string("cell2.gen")};
@@ -4632,15 +4633,15 @@
 			      std::string("cell23.gen"),
 			      std::string("cell24.gen")};*/
 
-    /*std::vector<MBRange> entities(sizeof(test_files));
-      std::vector<MBRange> forward_lower(sizeof(test_files));
-      std::vector<MBRange> reverse_lower(sizeof(test_files));
-      std::vector<MBRange> nodes(sizeof(test_files));*/
-  MBRange entities;
-  MBRange forward_lower;
-  MBRange reverse_lower;
-  MBRange faces;
-  MBRange nodes;
+    /*std::vector<Range> entities(sizeof(test_files));
+      std::vector<Range> forward_lower(sizeof(test_files));
+      std::vector<Range> reverse_lower(sizeof(test_files));
+      std::vector<Range> nodes(sizeof(test_files));*/
+  Range entities;
+  Range forward_lower;
+  Range reverse_lower;
+  Range faces;
+  Range nodes;
 
   cout << "---Starting Merge Tests---" << endl << endl;
   for(i=0; i<(sizeof(test_files)/sizeof(std::string)); i++)
@@ -4653,14 +4654,14 @@
       //get Hexes from model
   }
   result = MB->get_entities_by_type(0, MBHEX, entities);
-  MBSkinner_Obj.find_skin(entities,false,forward_lower,&reverse_lower);
+  Skinner_Obj.find_skin(entities,false,forward_lower,&reverse_lower);
   cout <<"num hexes = "<<entities.size()<<"\n";
   cout <<"fl = "<<forward_lower.size()<<" rl = "<<reverse_lower.size()<<"\n";
   
-    //  MBRange::const_iterator iter;
+    //  Range::const_iterator iter;
   int dim = 0;
     //  int num_ents = 1;
-  result = MB->get_adjacencies(forward_lower, dim, true, nodes, MBInterface::UNION);
+  result = MB->get_adjacencies(forward_lower, dim, true, nodes, Interface::UNION);
   cout <<"nodes.size() = "<<nodes.size() <<"\n";
     
   if(result == MB_SUCCESS)
@@ -4672,28 +4673,28 @@
     //  result = MB->get_entities_by_type(0, MBQUAD, faces);
     //  cout <<"num faces = "<<faces.size() <<"\n";
 
-  std::vector<std::pair<MBEntityHandle, MBEntityHandle> > coin_nodes;
+  std::vector<std::pair<EntityHandle, EntityHandle> > coin_nodes;
     //  cout <<"Begining sort...\n";
     //  std::sort(nodes.begin(),nodes.end(),lessnodesZ);
     //  cout <<"Ending sort...\n";
   result = find_coincident_nodes(MB,nodes, coin_nodes);
   cout <<"coin_nodes.size() = "<<coin_nodes.size() <<"\n";
-  std::vector< std::pair<MBEntityHandle, MBEntityHandle> >::iterator n_iter;
+  std::vector< std::pair<EntityHandle, EntityHandle> >::iterator n_iter;
   for (n_iter=coin_nodes.begin(); n_iter != coin_nodes.end(); n_iter++) {
     result = MB->merge_entities((*n_iter).first, (*n_iter).second, false, true);
     if (MB_SUCCESS != result)
       return result;
   }
-    /*  std::vector<std::pair<MBEntityHandle, MBEntityHandle> > coin_faces;
+    /*  std::vector<std::pair<EntityHandle, EntityHandle> > coin_faces;
         int nodes_per_elt = 4;
         result = find_coincident_elements(forward_lower, nodes_per_elt, coin_faces);
         if (result != MB_SUCCESS) cout <<"find_coincident_elements fail!\n";
         cout <<"coin_faces.size() = "<<coin_faces.size() <<"\n";
-        std::vector< std::pair<MBEntityHandle, MBEntityHandle> >::iterator f_iter;
+        std::vector< std::pair<EntityHandle, EntityHandle> >::iterator f_iter;
         for (f_iter=coin_faces.begin(); f_iter != coin_faces.end(); f_iter++)
         MB->merge_entities((*f_iter).first, (*f_iter).second, true, true);*/
     /*
-      std::vector<std::pair<MBEntityHandle, MBEntityHandle> > coin_fl;
+      std::vector<std::pair<EntityHandle, EntityHandle> > coin_fl;
       nodes_per_elt = 4;
       result = find_coincident_elements(entities, nodes_per_elt, coin_fl);
       cout <<"coin_fl.size() = "<<coin_fl.size() <<"\n";
@@ -4713,11 +4714,11 @@
   return result;
 }
 
-MBErrorCode mb_merge_update_test(MBInterface*)
+ErrorCode mb_merge_update_test(Interface*)
 {
-  MBCore moab;
-  MBInterface* mb = &moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface* mb = &moab;
+  ErrorCode rval;
   
     // create two quads with a coincident edge pair
   double coords[] = { 0, 0, 0,
@@ -4728,10 +4729,10 @@
                       1, 0, 0,
                       2, 0, 0,
                       2, 1, 0 };
-  MBEntityHandle verts[8];
+  EntityHandle verts[8];
   for (int i = 0; i < 8; ++i) 
     mb->create_vertex( coords + 3*i, verts[i] );
-  MBEntityHandle quad1, quad2, edge1, edge2;
+  EntityHandle quad1, quad2, edge1, edge2;
   mb->create_element( MBQUAD, verts, 4, quad1 );
   mb->create_element( MBQUAD, verts+4, 4, quad2 );
   mb->create_element( MBEDGE, verts+1, 2, edge1 );
@@ -4739,7 +4740,7 @@
   
     // create two tracking sets containing the vertices
     // and edge of each quad
-  MBEntityHandle set1, set2;
+  EntityHandle set1, set2;
   mb->create_meshset( MESHSET_TRACK_OWNER|MESHSET_SET, set1 );
   mb->create_meshset( MESHSET_TRACK_OWNER|MESHSET_ORDERED, set2 );
   mb->add_entities( set1, verts, 4 );
@@ -4765,13 +4766,13 @@
   }
   
     // check that there is only one edge and that it has the correct connectivity
-  MBRange r;
+  Range r;
   mb->get_entities_by_type( 0, MBEDGE, r );
   if (r.size() != 1 || r.front() != edge1) {
     std::cerr << "Edge merge failed at " << __FILE__ << ":" << __LINE__ << std::endl;
     return MB_FAILURE;
   }
-  std::vector<MBEntityHandle> exp(verts+1, verts+3), act;
+  std::vector<EntityHandle> exp(verts+1, verts+3), act;
   mb->get_connectivity( &edge1, 1, act );
   if (exp != act) {
     std::cerr << "Incorrect conn for edge at " << __FILE__ << ":" << __LINE__ << std::endl;
@@ -4779,7 +4780,7 @@
   }
   
     // check that quad connectivity is as expected
-  exp = std::vector<MBEntityHandle>(verts, verts+4);
+  exp = std::vector<EntityHandle>(verts, verts+4);
   act.clear();
   mb->get_connectivity( &quad1, 1, act );
   if (exp != act) {
@@ -4799,7 +4800,7 @@
   }
   
     // check that set contents are correctly updated
-  exp = std::vector<MBEntityHandle>(verts, verts+4);
+  exp = std::vector<EntityHandle>(verts, verts+4);
   exp.push_back( edge1 );
   act.clear();
   mb->get_entities_by_handle( set1, act );
@@ -4808,9 +4809,9 @@
   if (exp != act) {
     std::cerr << "Incorrect set contents at " << __FILE__ << ":" << __LINE__ << std::endl;
     std::cerr << "  Expected: ";
-    std::copy( exp.begin(), exp.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( exp.begin(), exp.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl << "  Actual  : ";
-    std::copy( act.begin(), act.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( act.begin(), act.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl;
     return MB_FAILURE;
   }
@@ -4826,9 +4827,9 @@
   if (exp != act) {
     std::cerr << "Incorrect set contents at " << __FILE__ << ":" << __LINE__ << std::endl;
     std::cerr << "  Expected: ";
-    std::copy( exp.begin(), exp.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( exp.begin(), exp.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl << "  Actual  : ";
-    std::copy( act.begin(), act.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+    std::copy( act.begin(), act.end(), std::ostream_iterator<EntityHandle>(std::cerr, " ") );
     std::cerr << std::endl;
     return MB_FAILURE;
   }
@@ -4836,10 +4837,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_stress_test(MBInterface *MB)
+ErrorCode mb_stress_test(Interface *MB)
 {
     // delete the existing mesh
-  MBErrorCode error = MB->delete_mesh();
+  ErrorCode error = MB->delete_mesh();
   if (error != MB_SUCCESS)
     return error;
 
@@ -4874,14 +4875,14 @@
   cout << "\n        Transforming and copying elements" << endl;
   start = clock();
 
-  MBRange hexes;
+  Range hexes;
   error = MB->get_entities_by_type(0, MBHEX, hexes);
   if (error != MB_SUCCESS)
     return error;
 
 
-  std::vector<MBEntityHandle> conn;
-  MBRange::iterator iter;
+  std::vector<EntityHandle> conn;
+  Range::iterator iter;
   for (iter = hexes.begin(); iter != hexes.end(); iter++)
   {
     error = MB->get_connectivity(&(*iter), 1, conn);
@@ -4890,9 +4891,9 @@
 
     double coords[3];
     int i = 0;
-    std::vector<MBEntityHandle> vertex_handle(8);
-    MBEntityHandle element_handle;
-    std::vector<MBEntityHandle>::iterator jter;
+    std::vector<EntityHandle> vertex_handle(8);
+    EntityHandle element_handle;
+    std::vector<EntityHandle>::iterator jter;
 
     for (jter = conn.begin(); jter != conn.end(); jter++)
     {
@@ -4926,7 +4927,7 @@
   if (hexes.size() != 512000)
     return MB_FAILURE;
 
-  MBEntityHandle mesh_set;
+  EntityHandle mesh_set;
   error = MB->create_meshset( MESHSET_SET, mesh_set );
   if (error != MB_SUCCESS)
     return error;
@@ -4945,8 +4946,8 @@
   start = clock();
 
     // set the block tag
-  MBTag tag_handle;
-  MBErrorCode result = MB->tag_get_handle( MATERIAL_SET_TAG_NAME, tag_handle ) ;
+  Tag tag_handle;
+  ErrorCode result = MB->tag_get_handle( MATERIAL_SET_TAG_NAME, tag_handle ) ;
   if(result != MB_SUCCESS)
     return result;
 
@@ -4955,7 +4956,7 @@
   if(result != MB_SUCCESS)
     return result;
 
-  std::vector<MBEntityHandle> output_list;
+  std::vector<EntityHandle> output_list;
   output_list.push_back(mesh_set);
 
   file_name = "mb_stress_out.g";
@@ -4979,15 +4980,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_canon_number_test(MBInterface *MB) 
+ErrorCode mb_canon_number_test(Interface *MB) 
 {
     // various tests for canonical ordering
 
     // MBCN::AdjacentSubEntities
   std::vector<int> vec1, vec2;
-  MBErrorCode result;
+  ErrorCode result;
 
-  MBEntityType this_type;
+  EntityType this_type;
 
   for (this_type = MBEDGE; this_type != MBKNIFE; this_type++) {
     
@@ -5035,18 +5036,18 @@
 
     // create vertices to use later
   double xyz[3] = {0.0, 0.0, 0.0};
-  MBEntityHandle vertex_handles[8];
+  EntityHandle vertex_handles[8];
   for (int i = 0; i < 8; i++) {
     result = MB->create_vertex(xyz, vertex_handles[i]);
     assert(result == MB_SUCCESS);
   }
   int side, sense, offset;
   
-  MBEntityHandle this_entity;
+  EntityHandle this_entity;
   
   for (this_type = MBEDGE; this_type != MBKNIFE; this_type++) {
     
-      // skip remainder of the loop for POLYGONS and POLYHEDRA, which don't follow
+      // skip remainder of the loop for MBPOLYGONS and POLYHEDRA, which don't follow
       // the standard canonical ordering 
     if (this_type == MBPOLYGON || this_type == MBPOLYHEDRON)
       continue;
@@ -5062,7 +5063,7 @@
     }
 
       // now get the connectivity vector *
-    const MBEntityHandle *entity_vertices;
+    const EntityHandle *entity_vertices;
     int num_verts;
     result = MB->get_connectivity(this_entity, entity_vertices, num_verts);
     if (MB_SUCCESS != result || 
@@ -5115,7 +5116,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_poly_test(MBInterface *mb) 
+ErrorCode mb_poly_test(Interface *mb) 
 {
     // test polygon and polyhedron representation
     // create a couple of polygons; vertices first
@@ -5137,8 +5138,8 @@
     2, -1, 0,
     1.5, .5, 1};
 
-  MBEntityHandle verts[16];
-  MBErrorCode result;
+  EntityHandle verts[16];
+  ErrorCode result;
   int i;
   for (i = 0; i < 16; i++) {
     result = mb->create_vertex(&vert_pos[3*i], verts[i]);
@@ -5164,9 +5165,9 @@
   
   int num_connect_idx[] = {5, 4, 3, 3, 4, 10, 11, 4, 4};
   
-  MBEntityHandle polygons[9], temp_connect[12];
+  EntityHandle polygons[9], temp_connect[12];
   int idx = 0, nump = 0;
-  MBErrorCode tmp_result;
+  ErrorCode tmp_result;
   while (nump < 9) {
     for (i = 0; i < num_connect_idx[nump]; i++)
       temp_connect[i] = verts[connect_idx[idx+i]];
@@ -5187,7 +5188,7 @@
   if (MB_SUCCESS != result) return result;
   
     // ok, made 'em; now get all the vertices and make sure they're the same
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
   idx = 0;
   int j;
@@ -5214,10 +5215,10 @@
   if (MB_SUCCESS != result) return result;
 
     // check a different way, with ranges
-  MBRange vert_range, poly_range;
+  Range vert_range, poly_range;
   for (i = 0; i < 9; i++) poly_range.insert(polygons[i]);
   result = mb->get_adjacencies(poly_range, 0, false, vert_range, 
-                               MBInterface::UNION);
+                               Interface::UNION);
   if (MB_SUCCESS != result) {
     std::cout << "mb_poly_test: get_adjacencies failed for polygon " 
               << i << "." << std::endl;
@@ -5231,7 +5232,7 @@
   }
   
     // make a couple polyhedra
-  MBEntityHandle polyhedra[2];
+  EntityHandle polyhedra[2];
   result = mb->create_element(MBPOLYHEDRON, polygons, 7, polyhedra[0]);
   if (MB_SUCCESS != result) {
     std::cout << "mb_poly_test: create_element failed for polyhedron 1." << std::endl;
@@ -5248,7 +5249,7 @@
   }
   
     // now look for vertices common to both
-  std::vector<MBEntityHandle> temp_verts;
+  std::vector<EntityHandle> temp_verts;
   result = mb->get_adjacencies(polyhedra, 2, 0, false, temp_verts);
   if (MB_SUCCESS != result) {
     std::cout << "mb_poly_test: get_adjacencies failed for polyhedra." << std::endl;
@@ -5265,21 +5266,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_range_test(MBInterface *) 
+ErrorCode mb_range_test(Interface *MB) 
 {
 
-  MBRange r1, r2, rhs;
-  MBErrorCode result = MB_SUCCESS;
+  Range r1, r2, rhs;
+  ErrorCode result = MB_SUCCESS;
   int err;
 
-  MBEntityHandle h1 = CREATE_HANDLE(MBVERTEX, 1, err);
-  MBEntityHandle h4 = CREATE_HANDLE(MBVERTEX, 4, err);
-  MBEntityHandle h5 = CREATE_HANDLE(MBVERTEX, 5, err);
-  MBEntityHandle h9 = CREATE_HANDLE(MBVERTEX, 9, err);
-  MBEntityHandle h10 = CREATE_HANDLE(MBVERTEX, 10, err);
-  MBEntityHandle h15 = CREATE_HANDLE(MBVERTEX, 15, err);
-  MBEntityHandle h16 = CREATE_HANDLE(MBVERTEX, 16, err);
-  MBEntityHandle h20 = CREATE_HANDLE(MBVERTEX, 20, err);
+  EntityHandle h1 = CREATE_HANDLE(MBVERTEX, 1, err);
+  EntityHandle h4 = CREATE_HANDLE(MBVERTEX, 4, err);
+  EntityHandle h5 = CREATE_HANDLE(MBVERTEX, 5, err);
+  EntityHandle h9 = CREATE_HANDLE(MBVERTEX, 9, err);
+  EntityHandle h10 = CREATE_HANDLE(MBVERTEX, 10, err);
+  EntityHandle h15 = CREATE_HANDLE(MBVERTEX, 15, err);
+  EntityHandle h16 = CREATE_HANDLE(MBVERTEX, 16, err);
+  EntityHandle h20 = CREATE_HANDLE(MBVERTEX, 20, err);
 
     // equal start/end
   r1.insert(h1, h5);
@@ -5360,8 +5361,8 @@
   r2.clear();
   r1.insert(h1, h5);
   r1.insert(h10, h15);
-  MBRange::const_iterator i1 = r1.begin();
-  MBRange::const_iterator i2 = r1.end();
+  Range::const_iterator i1 = r1.begin();
+  Range::const_iterator i2 = r1.end();
   i1 += 2;
   i2 -= 2;
   r2.merge( i1, i2 );
@@ -5375,12 +5376,12 @@
   r1.insert( h1 );
   r1.insert( h4 );
   r1.insert( h5 );
-  MBRange::const_pair_iterator pair_iter = r1.const_pair_begin();
-  MBEntityHandle cpi_h1 = (*pair_iter).first;
-  MBEntityHandle cpi_h2 = (*pair_iter).second;
+  Range::const_pair_iterator pair_iter = r1.const_pair_begin();
+  EntityHandle cpi_h1 = (*pair_iter).first;
+  EntityHandle cpi_h2 = (*pair_iter).second;
   ++pair_iter;
-  MBEntityHandle cpi_h3 = (*pair_iter).first;
-  MBEntityHandle cpi_h4 = (*pair_iter).second;
+  EntityHandle cpi_h3 = (*pair_iter).first;
+  EntityHandle cpi_h4 = (*pair_iter).second;
   ++pair_iter;
   if (cpi_h1 != h1 || cpi_h2 != h1 || 
       cpi_h3 != h4 || cpi_h4 != h5 ||
@@ -5457,7 +5458,7 @@
   r1.insert(h4);
   r1.insert(h5);
   r2.insert(h4);
-  MBRange r3 = subtract( r1, r2);
+  Range r3 = subtract( r1, r2);
   if (r3.size() != 2 ||
       r3.find(h1) == r3.end() ||
       r3.find(h5) == r3.end() ||
@@ -5486,10 +5487,10 @@
   return result;
 }
 
-MBErrorCode mb_range_erase_test(MBInterface *) 
+ErrorCode mb_range_erase_test(Interface *MB) 
 {
-  MBRange range;
-  MBRange::iterator result;
+  Range range;
+  Range::iterator result;
   
     // test erase from first node
   range.clear();
@@ -5619,7 +5620,7 @@
   CHECK_EQUAL(  8u, *result );
   
     // test iterators before erase remain valid
-  MBRange::iterator a, b, c;
+  Range::iterator a, b, c;
   range.clear();
   range.insert( 5, 10 );
   range.insert( 12, 20 );
@@ -5651,7 +5652,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_topo_util_test(MBInterface *gMB) 
+ErrorCode mb_topo_util_test(Interface *gMB) 
 {
   MeshTopoUtil mtu(gMB);
 
@@ -5667,8 +5668,8 @@
       0.0, 2.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0
     };
       
-  MBEntityHandle grid_verts[18], grid_elems[4];
-  MBErrorCode result;
+  EntityHandle grid_verts[18], grid_elems[4];
+  ErrorCode result;
 #define RR if (result != MB_SUCCESS) return result
   int init_edges, init_faces;
   result = gMB->get_number_entities_by_dimension(0, 1, init_edges); RR;
@@ -5682,7 +5683,7 @@
     // make hexes
   int numv = 3, numv_sq = 9;
 #define VINDEX(i,j,k) (i + (j*numv) + (k*numv_sq))
-  MBEntityHandle connect[8];
+  EntityHandle connect[8];
   for (int j = 0; j < 2; j++) {
     for (int i = 0; i < 2; i++) {
       int vijk = VINDEX(i,j,0);
@@ -5698,8 +5699,8 @@
     }
   }
 
-  MBRange vert_range;
-  std::copy(grid_verts, grid_verts+18, mb_range_inserter(vert_range));
+  Range vert_range;
+  std::copy(grid_verts, grid_verts+18, range_inserter(vert_range));
   
     // generate aentities
   result = mtu.construct_aentities(vert_range); RR;
@@ -5728,8 +5729,8 @@
   RR;
 
     // get star faces
-  MBRange all_hexes, middle_edge;
-  std::copy(grid_elems, grid_elems+4, mb_range_inserter(all_hexes));
+  Range all_hexes, middle_edge;
+  std::copy(grid_elems, grid_elems+4, range_inserter(all_hexes));
     // get the shared edge
   result = gMB->get_adjacencies(all_hexes, 1, false, middle_edge);
   if (MB_SUCCESS != result || 1 != middle_edge.size()) {
@@ -5737,7 +5738,7 @@
     return MB_FAILURE;
   }
   
-  std::vector<MBEntityHandle> star_faces, star_hexes;
+  std::vector<EntityHandle> star_faces, star_hexes;
   bool bdy_edge;
   result = mtu.star_entities(*middle_edge.begin(), star_faces, bdy_edge, 0, &star_hexes);
   if (MB_SUCCESS != result || bdy_edge || star_faces.size() != 4 || star_hexes.size() != 4) {
@@ -5746,7 +5747,7 @@
   }
   
     // now try for a different edge, which has to be on the bdy
-  MBRange other_edges;
+  Range other_edges;
   all_hexes.clear(); all_hexes.insert(grid_elems[0]);
   result = gMB->get_adjacencies(all_hexes, 1, false, other_edges); RR;
   other_edges.erase(*middle_edge.begin());
@@ -5767,7 +5768,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_split_test(MBInterface *gMB) 
+ErrorCode mb_split_test(Interface *gMB) 
 {
   MeshTopoUtil mtu(gMB);
 
@@ -5787,8 +5788,8 @@
       0.0, 2.0, 2.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0
     };
       
-  MBEntityHandle grid_verts[27], grid_elems[8];
-  MBErrorCode result;
+  EntityHandle grid_verts[27], grid_elems[8];
+  ErrorCode result;
 #define RR if (result != MB_SUCCESS) return result
   int init_edges, init_faces, init_regions;
   result = gMB->get_number_entities_by_dimension(0, 1, init_edges); RR;
@@ -5803,7 +5804,7 @@
     // make hexes
   int numv = 3, numv_sq = 9;
 #define VINDEX(i,j,k) (i + (j*numv) + (k*numv_sq))
-  MBEntityHandle connect[8];
+  EntityHandle connect[8];
   for (int k = 0; k < 2; k++) {
     for (int j = 0; j < 2; j++) {
       for (int i = 0; i < 2; i++) {
@@ -5821,8 +5822,8 @@
     }
   }
   
-  MBRange vert_range;
-  std::copy(grid_verts, grid_verts+27, mb_range_inserter(vert_range));
+  Range vert_range;
+  std::copy(grid_verts, grid_verts+27, range_inserter(vert_range));
   
     // generate aentities
   result = mtu.construct_aentities(vert_range); RR;
@@ -5838,7 +5839,7 @@
 
     // split the faces between the 2 layers
     // first get the faces
-  MBRange split_faces, tmp_ents, tmp_faces;
+  Range split_faces, tmp_ents, tmp_faces;
   for (int i = 0; i < 4; i++) {
     tmp_ents.clear();
     tmp_ents.insert(grid_elems[i]);
@@ -5852,7 +5853,7 @@
     split_faces.insert(*tmp_faces.begin());
   }
 
-  MBRange new_faces, new_regions;
+  Range new_faces, new_regions;
 
     // NOTE: passing in non-NULL pointer for new_regions requests that region between the
     // split entities be filled with an element; in this case, since we're splitting faces,
@@ -5879,16 +5880,16 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_range_seq_intersect_test( MBInterface*) 
+ErrorCode mb_range_seq_intersect_test( Interface*) 
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   SequenceManager sequences;
-  MBRangeSeqIntersectIter iter( &sequences );
-  MBRange range;
+  RangeSeqIntersectIter iter( &sequences );
+  Range range;
 
     // create some entity sequences
   EntitySequence *ts1, *ts2, *ts3, *qs1;
-  MBEntityHandle th1, th2, th3, qh1;
+  EntityHandle th1, th2, th3, qh1;
   const int nt1 = 100, nt2 = 10, nt3 = 1, nq1 = 20;
   rval = sequences.create_entity_sequence( MBTRI, nt1, 3, 5, th1, ts1 );
   if (MB_SUCCESS != rval) return rval;
@@ -5903,7 +5904,7 @@
   if (th1 > th2 || th2 > th3 || th3 > qh1)
     return MB_FAILURE;
   
-    // construct an MBRange containing all valid handles;
+    // construct an Range containing all valid handles;
   range.clear();
   range.insert( ts1->start_handle(), ts1->end_handle() );
   range.insert( ts2->start_handle(), ts2->end_handle() );
@@ -6028,8 +6029,8 @@
    
     // Iterate over two subsets of the quad sequence
     
-  MBRange quads = range.subset_by_type( MBQUAD );
-  MBEntityHandle removed = qs1->start_handle() + nq1/2;
+  Range quads = range.subset_by_type( MBQUAD );
+  EntityHandle removed = qs1->start_handle() + nq1/2;
   if (quads.erase( removed ) == quads.end())
     return MB_FAILURE;
 
@@ -6062,9 +6063,9 @@
     // Iterate over everything, including a bunch of
     // invalid handles
 
-  MBRange big;
+  Range big;
   int junk;
-  MBEntityHandle last = CREATE_HANDLE(MBQUAD+1, 0, junk);
+  EntityHandle last = CREATE_HANDLE(MBQUAD+1, 0, junk);
   big.insert( ts1->start_handle() - 1, last );
 
     // first some invalid handles in the beginning of the range
@@ -6195,16 +6196,16 @@
   
   
     // Create some holes
-  MBEntityHandle ts1s  = ts1->start_handle();
-  MBEntityHandle dead1 = ts1->start_handle() + 1;
-  MBEntityHandle dead2 = ts1->start_handle() + 2;
-  MBEntityHandle ts1e  = ts1->end_handle();
-  MBEntityHandle dead3 = ts2->start_handle();
-  MBEntityHandle dead4 = ts2->end_handle();
-  MBEntityHandle qs1s  = qs1->start_handle();
-  MBEntityHandle qs1e  = qs1->end_handle();
-  MBEntityHandle dead5 = qs1->start_handle() + nq1/2;
-  MBEntityHandle dead6 = dead5+1;
+  EntityHandle ts1s  = ts1->start_handle();
+  EntityHandle dead1 = ts1->start_handle() + 1;
+  EntityHandle dead2 = ts1->start_handle() + 2;
+  EntityHandle ts1e  = ts1->end_handle();
+  EntityHandle dead3 = ts2->start_handle();
+  EntityHandle dead4 = ts2->end_handle();
+  EntityHandle qs1s  = qs1->start_handle();
+  EntityHandle qs1e  = qs1->end_handle();
+  EntityHandle dead5 = qs1->start_handle() + nq1/2;
+  EntityHandle dead6 = dead5+1;
   rval = sequences.delete_entity( dead1 );
   if (MB_SUCCESS != rval) return rval;
   rval = sequences.delete_entity( dead2 );
@@ -6489,19 +6490,19 @@
   return false;
 }
     
-std::ostream& operator<<( std::ostream& s, MBRange::const_iterator i ) {
+std::ostream& operator<<( std::ostream& s, Range::const_iterator i ) {
   return s << *i;
 }
 
-MBErrorCode mb_poly_adjacency_test( MBInterface* )
+ErrorCode mb_poly_adjacency_test( Interface* )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface *mbImpl = &moab;
+  ErrorCode rval;
+  Core moab;
+  Interface *mbImpl = &moab;
   
     // make a couple polygons and a polyhedron
   double coords[3] = {0,1,2};
-  MBEntityHandle verts[10], polygons[2], polyhedron;
+  EntityHandle verts[10], polygons[2], polyhedron;
   
   for (int i = 0; i < 10; i++) {
     rval = mbImpl->create_vertex(coords, verts[i]);
@@ -6519,7 +6520,7 @@
     return rval;
   
     // create the aentities
-  MBRange dum_range;
+  Range dum_range;
   for (int dim = 0; dim < 3; dim++) {
     dum_range.clear();
     rval = mbImpl->get_adjacencies(&polyhedron, 1, dim, true, dum_range);
@@ -6536,19 +6537,19 @@
   return moab.check_adjacencies();
 }
 
-MBErrorCode mb_memory_use_test( MBInterface* ) 
+ErrorCode mb_memory_use_test( Interface* ) 
 {
-  MBCore mb;
+  Core mb;
   unsigned long init_total, total_with_elem, total_with_tag, total_with_tag_data;
   mb.estimated_memory_use(0,0,0,&init_total);
   
   double coords[12] = { 1, 2, 0, 3, 4, 0, 5, 6, 0, 7, 8, 0 };
-  MBEntityHandle verts[4];
+  EntityHandle verts[4];
   for (int i = 0; i < 4; ++i)
     if (MB_SUCCESS != mb.create_vertex( coords + 3*i, verts[i] ))
       return MB_FAILURE;
   
-  MBEntityHandle elem;
+  EntityHandle elem;
   mb.create_element( MBQUAD, verts, 4, elem );
   
   mb.estimated_memory_use(0,0,0,&total_with_elem);
@@ -6556,10 +6557,10 @@
     return MB_FAILURE;
   
   unsigned long min, am;
-  MBRange r;
+  Range r;
   r.insert( elem );
   mb.estimated_memory_use( r, &min, &am );
-  if (min != 4*sizeof(MBEntityHandle))
+  if (min != 4*sizeof(EntityHandle))
     return MB_FAILURE;
   
   r.clear();
@@ -6569,7 +6570,7 @@
   if (min != 6*sizeof(double))
     return MB_FAILURE;
   
-  MBTag tag;
+  Tag tag;
   if (MB_SUCCESS != mb.tag_create( "TMP_TAG", sizeof(int), MB_TAG_SPARSE, tag, 0 ))
     return MB_FAILURE;
   mb.estimated_memory_use( r, &min, &am );
@@ -6594,53 +6595,53 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_skin_curve_test_common( bool use_adj );
+ErrorCode mb_skin_curve_test_common( bool use_adj );
 
-MBErrorCode mb_skin_curve_test( MBInterface* )
+ErrorCode mb_skin_curve_test( Interface* )
   { return mb_skin_curve_test_common( false ); }
 
-MBErrorCode mb_skin_curve_adj_test( MBInterface* )
+ErrorCode mb_skin_curve_adj_test( Interface* )
   { return mb_skin_curve_test_common( true ); }
 
-MBErrorCode mb_skin_surface_test_common( bool use_adj );
+ErrorCode mb_skin_surface_test_common( bool use_adj );
 
-MBErrorCode mb_skin_surface_test( MBInterface* )
+ErrorCode mb_skin_surface_test( Interface* )
   { return mb_skin_surface_test_common( false ); }
 
-MBErrorCode mb_skin_surface_adj_test( MBInterface* )
+ErrorCode mb_skin_surface_adj_test( Interface* )
   { return mb_skin_surface_test_common( true ); }
 
-MBErrorCode mb_skin_volume_test_common( bool use_adj );
+ErrorCode mb_skin_volume_test_common( bool use_adj );
 
-MBErrorCode mb_skin_volume_test( MBInterface* )
+ErrorCode mb_skin_volume_test( Interface* )
   { return mb_skin_volume_test_common( false ); }
 
-MBErrorCode mb_skin_volume_adj_test( MBInterface* )
+ErrorCode mb_skin_volume_adj_test( Interface* )
   { return mb_skin_volume_test_common( true ); }
 
-MBErrorCode mb_skin_curve_test_common( bool use_adj )
+ErrorCode mb_skin_curve_test_common( bool use_adj )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface *mb = &moab;
+  ErrorCode rval;
+  Core moab;
+  Interface *mb = &moab;
   
-  std::vector<MBEntityHandle> verts;
+  std::vector<EntityHandle> verts;
   for (unsigned i = 0; i < 10; ++i) {
     double coords[] = { i, 0, 0 };
-    MBEntityHandle h;
+    EntityHandle h;
     mb->create_vertex( coords, h );
     verts.push_back(h);
   }
-  MBRange edges;
+  Range edges;
   for (unsigned i = 1; i < verts.size(); ++i) {
-    MBEntityHandle conn[] = { verts[i-1], verts[i] };
-    MBEntityHandle h;
+    EntityHandle conn[] = { verts[i-1], verts[i] };
+    EntityHandle h;
     mb->create_element( MBEDGE, conn, 2, h );
     edges.insert(h);
   }
   
-  MBRange skin;
-  MBSkinner tool(mb);
+  Range skin;
+  Skinner tool(mb);
   rval = tool.find_skin( edges, 0, skin, use_adj );
   if (MB_SUCCESS != rval) {
     std::cerr << "Skinner failure at " __FILE__ ":" << __LINE__ << std::endl;
@@ -6661,8 +6662,8 @@
   
   
     // now test again with only one edge
-  MBEntityHandle edge = edges.front();
-  MBRange range(edge,edge);
+  EntityHandle edge = edges.front();
+  Range range(edge,edge);
   skin.clear();
   rval = tool.find_skin( range, 0, skin, use_adj );
   if (MB_SUCCESS != rval) {
@@ -6674,7 +6675,7 @@
     return MB_FAILURE;
   }
 
-  MBRange verts2;
+  Range verts2;
   mb->get_connectivity( &edge, 1, verts2 );
   if (skin.front() != verts2.front() ||
       skin.back()  != verts2.back()) {
@@ -6685,11 +6686,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_skin_surface_test_common( bool use_adj )
+ErrorCode mb_skin_surface_test_common( bool use_adj )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface *mb = &moab;
+  ErrorCode rval;
+  Core moab;
+  Interface *mb = &moab;
   
     /* Create 4 of 5 faces of a wedge: */
     /*
@@ -6711,28 +6712,28 @@
                                { 0, 2, 0 },
                                { 2, 2, 0 },
                                { 1, 2, 1 } };
-  MBEntityHandle verts[6];
+  EntityHandle verts[6];
   for (unsigned i = 0; i < 6; ++i)
     mb->create_vertex( coords[i], verts[i] );
 
-  MBEntityHandle faces[4];
-  MBEntityHandle tri[] = { verts[0], verts[1], verts[2] };
-  MBEntityHandle quad1[] = { verts[0], verts[1], verts[5], verts[3] };
-  MBEntityHandle quad2[] = { verts[1], verts[5], verts[4], verts[2] };
-  MBEntityHandle quad3[] = { verts[2], verts[4], verts[3], verts[0] };
+  EntityHandle faces[4];
+  EntityHandle tri[] = { verts[0], verts[1], verts[2] };
+  EntityHandle quad1[] = { verts[0], verts[1], verts[5], verts[3] };
+  EntityHandle quad2[] = { verts[1], verts[5], verts[4], verts[2] };
+  EntityHandle quad3[] = { verts[2], verts[4], verts[3], verts[0] };
   mb->create_element( MBTRI, tri, 3, faces[0] );
   mb->create_element( MBQUAD, quad1, 4, faces[1] );
   mb->create_element( MBQUAD, quad2, 4, faces[2] );
   mb->create_element( MBQUAD, quad3, 4, faces[3] );
-  MBRange source;
-  std::copy( faces, faces+4, mb_range_inserter(source) );
+  Range source;
+  std::copy( faces, faces+4, range_inserter(source) );
   
     // Now skin the mesh.  The only missing face is the 
     // back triangle (verts 3, 4, & 5) so the skin should
     // be the edges bordering that face.
   
-  MBRange skin;
-  MBSkinner tool(mb);
+  Range skin;
+  Skinner tool(mb);
   rval = tool.find_skin( source, 1, skin, use_adj );
   if (MB_SUCCESS != rval) {
     std::cerr << "Skinner failure at " __FILE__ ":" << __LINE__ << std::endl;
@@ -6744,7 +6745,7 @@
   }
 
     // Check each edge
-  std::vector<MBEntityHandle> conn[3];
+  std::vector<EntityHandle> conn[3];
   rval = mb->get_connectivity( &skin.front(), 1, conn[0] );
   rval = mb->get_connectivity( &*++skin.begin(), 1, conn[1] );
   rval = mb->get_connectivity( &skin.back(), 1, conn[2] );
@@ -6753,7 +6754,7 @@
       std::swap(conn[i][0], conn[i][1]);
 
   for (int i = 0; i < 3; ++i) {
-    MBEntityHandle s = verts[i+3], e = verts[(i+1)%3 + 3];
+    EntityHandle s = verts[i+3], e = verts[(i+1)%3 + 3];
     if (s > e)
       std::swap(s,e);
     int j = 0; 
@@ -6771,11 +6772,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_skin_volume_test_common( bool use_adj )
+ErrorCode mb_skin_volume_test_common( bool use_adj )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface *mb = &moab;
+  ErrorCode rval;
+  Core moab;
+  Interface *mb = &moab;
   
     /* A 2 adjacent hexes hexes */
     /*
@@ -6800,32 +6801,32 @@
                                { 0, 1, 1 },
                                { 1, 1, 1 },
                                { 2, 1, 1 } };
-  MBEntityHandle verts[12];
+  EntityHandle verts[12];
   for (unsigned i = 0; i < 12; ++i)
     mb->create_vertex( coords[i], verts[i] );
 
-  MBEntityHandle hex1c[] = { verts[0], verts[1], verts[4], verts[3],
+  EntityHandle hex1c[] = { verts[0], verts[1], verts[4], verts[3],
                           verts[6], verts[7], verts[10], verts[9] };
-  MBEntityHandle hex2c[] = { verts[1], verts[2], verts[5], verts[4],
+  EntityHandle hex2c[] = { verts[1], verts[2], verts[5], verts[4],
                           verts[7], verts[8], verts[11], verts[10] };
-  MBEntityHandle hex1, hex2;
+  EntityHandle hex1, hex2;
   mb->create_element( MBHEX, hex1c, 8, hex1 );
   mb->create_element( MBHEX, hex2c, 8, hex2 );
-  MBRange source;
+  Range source;
   source.insert( hex1 );
   source.insert( hex2 );
     
     // get all quads and shared face
-  MBRange tmp, all_faces;
-  mb->get_adjacencies( source, 2, true, all_faces, MBInterface::UNION );
-  mb->get_adjacencies( source, 2, true, tmp, MBInterface::INTERSECT );
+  Range tmp, all_faces;
+  mb->get_adjacencies( source, 2, true, all_faces, Interface::UNION );
+  mb->get_adjacencies( source, 2, true, tmp, Interface::INTERSECT );
   assert(tmp.size() == 1);
-  MBRange non_shared = subtract( all_faces, tmp );
+  Range non_shared = subtract( all_faces, tmp );
   
     // Now skin the mesh.  
   
-  MBRange skin;
-  MBSkinner tool(mb);
+  Range skin;
+  Skinner tool(mb);
   rval = tool.find_skin( source, 2, skin, use_adj );
   if (MB_SUCCESS != rval) {
     std::cerr << "Skinner failure at " __FILE__ ":" << __LINE__ << std::endl;
@@ -6847,10 +6848,10 @@
 // so we can test all the readers w/out knowing which
 // readers we have.
 const char* argv0 = 0;
-MBErrorCode mb_read_fail_test(MBInterface* mb)
+ErrorCode mb_read_fail_test(Interface* mb)
 {
   const char BAD_FILE_NAME[] = "non-existant-file.txt";
-  MBErrorCode rval;
+  ErrorCode rval;
   
   FILE* fptr = fopen(BAD_FILE_NAME,"r");
   if (fptr) {
@@ -6882,7 +6883,7 @@
     return MB_FAILURE; \
   } 
 
-MBErrorCode mb_enum_string_test( MBInterface* mb )
+ErrorCode mb_enum_string_test( Interface* mb )
 {
   TEST_ERROR_CODE( MB_SUCCESS );
   TEST_ERROR_CODE( MB_INDEX_OUT_OF_RANGE );
@@ -6908,12 +6909,12 @@
 int number_tests_failed = 0;
 #define RUN_TEST( A ) _run_test( (A), #A )
 
-typedef MBErrorCode (*TestFunc)(MBInterface*);
+typedef ErrorCode (*TestFunc)(Interface*);
 static void _run_test( TestFunc func, const char* func_str ) 
 {
-  MBErrorCode error;
-  MBCore moab;
-  MBInterface* iface = &moab;
+  ErrorCode error;
+  Core moab;
+  Interface* iface = &moab;
   
   std::string file_name = TestDir + "/mbtest1.g";
   error = iface->load_mesh( file_name.c_str() );
@@ -6949,21 +6950,21 @@
 
 
 // Test basic skinning using vert-to-elem adjacencies
-MBErrorCode mb_skin_verts_common( unsigned dim, bool skin_elems );
+ErrorCode mb_skin_verts_common( unsigned dim, bool skin_elems );
 
-MBErrorCode mb_skin_surf_verts_test( MBInterface* )
+ErrorCode mb_skin_surf_verts_test( Interface* )
   { return mb_skin_verts_common( 2, false ); }
 
-MBErrorCode mb_skin_vol_verts_test( MBInterface* )
+ErrorCode mb_skin_vol_verts_test( Interface* )
   { return mb_skin_verts_common( 3, false ); }
 
-MBErrorCode mb_skin_surf_verts_elems_test( MBInterface* )
+ErrorCode mb_skin_surf_verts_elems_test( Interface* )
   { return mb_skin_verts_common( 2, true ); }
 
-MBErrorCode mb_skin_vol_verts_elems_test( MBInterface* )
+ErrorCode mb_skin_vol_verts_elems_test( Interface* )
   { return mb_skin_verts_common( 3, true ); }
 
-MBErrorCode mb_skin_verts_common( unsigned dim, bool skin_elems )
+ErrorCode mb_skin_verts_common( unsigned dim, bool skin_elems )
 {
   const int INT = 10; // intervals+1
   const char* tmp_file = "structured.vtk";
@@ -6981,23 +6982,23 @@
       << "SPACING 1 1 1" << std::endl;
   str.close();
   
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
   rval = mb.load_file( tmp_file );
   remove( tmp_file );
   if (MB_SUCCESS != rval) 
     return rval;
   
-  MBRange ents;
+  Range ents;
   rval = mb.get_entities_by_dimension( 0, dim, ents );
   if (MB_SUCCESS != rval)
     return rval;
   if (ents.empty())
     return MB_FAILURE;
   
-  MBSkinner tool( &mb );
+  Skinner tool( &mb );
   
    // mesh is a structured quad/hex mesh, so we can
    // determine skin vertices from the number of
@@ -7005,13 +7006,13 @@
   unsigned interior_adj = 1;
   for (unsigned i = 0; i < dim; ++i)
     interior_adj *= 2;
-  MBRange expected, verts;
+  Range expected, verts;
   rval = mb.get_entities_by_dimension( 0, 0, verts );
   if (MB_SUCCESS != rval)
     return rval;
-  MBRange::iterator h = expected.begin();
-  std::vector<MBEntityHandle> adj;
-  for (MBRange::iterator v = verts.begin(); v != verts.end(); ++v) {
+  Range::iterator h = expected.begin();
+  std::vector<EntityHandle> adj;
+  for (Range::iterator v = verts.begin(); v != verts.end(); ++v) {
     adj.clear();
     rval = mb.get_adjacencies( &*v, 1, dim, false, adj );
     if (MB_SUCCESS != rval)
@@ -7021,12 +7022,12 @@
   }
   
     // Get skin vertices using skinner
-  MBRange actual;
+  Range actual;
   rval = tool.find_skin( ents, !skin_elems, actual );
   if (MB_SUCCESS != rval)
     return rval;
  
-  MBRange extra, missing;
+  Range extra, missing;
   if (!skin_elems) {
       // Check that we got expected result
     extra = subtract( actual, expected );
@@ -7052,8 +7053,8 @@
     
     // check that each skin vertex has the correct number of adjacent quads
   missing.clear(); extra.clear();
-  for (MBRange::iterator i = expected.begin(); i != expected.end(); ++i) {
-    std::vector<MBEntityHandle> elem, side;
+  for (Range::iterator i = expected.begin(); i != expected.end(); ++i) {
+    std::vector<EntityHandle> elem, side;
     rval = mb.get_adjacencies( &*i, 1, dim, false, elem );
     if (MB_SUCCESS != rval) return rval;
     rval = mb.get_adjacencies( &*i, 1, dim-1, false, side );
@@ -7083,8 +7084,8 @@
   
     // check that all returned elements are actually on the skin
   extra.clear();
-  for (MBRange::iterator i = actual.begin(); i != actual.end(); ++i) {
-    MBRange verts;
+  for (Range::iterator i = actual.begin(); i != actual.end(); ++i) {
+    Range verts;
     rval = mb.get_adjacencies( &*i, 1, 0, false, verts );
     if (MB_SUCCESS != rval)
       return rval;
@@ -7101,7 +7102,7 @@
 }
 
 // Test that skinning of polyhedra works
-MBErrorCode mb_skin_poly_test( MBInterface* )
+ErrorCode mb_skin_poly_test( Interface* )
 {
   /* Create a mesh composed of 8 hexagonal prisms and 
      two hexahedra by extruding the following cross section
@@ -7156,13 +7157,13 @@
                                { 5,  6,  7, 15, 18, 14 },
                                { 8,  9, 10, 12, 19, 15 } };
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBRange regions, faces, interior_faces;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  Range regions, faces, interior_faces;
 
     // create 48 vertices
-  MBEntityHandle verts[3][16];
+  EntityHandle verts[3][16];
   for (int i = 0; i < 3; ++i) {
     for (int j = 0; j < 16; ++j) {
       double coords[3] = { coords2D[j][0], coords2D[j][1], 2*i };
@@ -7172,9 +7173,9 @@
   }
   
     // create two hexahedra
-  MBEntityHandle hexes[2];
+  EntityHandle hexes[2];
   for (int i = 0; i < 2; ++i) {
-    MBEntityHandle conn[8] = { verts[i  ][15],
+    EntityHandle conn[8] = { verts[i  ][15],
                                verts[i  ][14],
                                verts[i  ][13],
                                verts[i  ][12],
@@ -7188,10 +7189,10 @@
   }
   
     // create hexagonal faces
-  MBEntityHandle hexagons[3][4];
+  EntityHandle hexagons[3][4];
   for (int i = 0; i < 3; ++i) {
     for (int j = 0; j < 4; ++j) {
-      MBEntityHandle conn[6];
+      EntityHandle conn[6];
       for (int k = 0; k < 6; ++k) 
         conn[k] = verts[i][polyconn[j][k]];
       rval = mb.create_element( MBPOLYGON, conn, 6, hexagons[i][j] );
@@ -7203,7 +7204,7 @@
   }
   
     // create quadrilateral faces
-  MBEntityHandle quads[2][20];
+  EntityHandle quads[2][20];
   for (int i = 0; i < 2; ++i) {
     for (int j = 0; j < 20; ++j) {
       int c1, c2;
@@ -7216,7 +7217,7 @@
       else {
         c1 = j-4; c2 = 12 + (j-15)%4;
       }
-      MBEntityHandle conn[4] = { verts[i  ][c1],
+      EntityHandle conn[4] = { verts[i  ][c1],
                                  verts[i  ][c2],
                                  verts[i+1][c2],
                                  verts[i+1][c1] };
@@ -7229,10 +7230,10 @@
   }
   
     // create polyhedra
-  MBEntityHandle poly[2][4];
+  EntityHandle poly[2][4];
   for (int i = 0; i < 2; ++i) {
     for (int j = 0; j < 4; ++j) {
-      MBEntityHandle conn[8];
+      EntityHandle conn[8];
       for (int k = 0; k < 6; ++k) 
         conn[k] = quads[i][polyside[j][k]];
       conn[6] = hexagons[  i][j];
@@ -7243,27 +7244,27 @@
     }
   }
   
-  MBRange interior_verts;
+  Range interior_verts;
   interior_verts.insert( verts[1][12] );
   interior_verts.insert( verts[1][13] );
   interior_verts.insert( verts[1][14] );
   interior_verts.insert( verts[1][15] );
   
-  MBSkinner tool(&mb);
-  MBRange skin;
+  Skinner tool(&mb);
+  Range skin;
   rval = tool.find_skin( regions, true, skin, 0, true, false );
   if (MB_SUCCESS != rval) {
     std::cout << "Vertex skinning failed with: " << mb.get_error_string(rval) << std::endl;
     return rval;
   }
   
-  MBRange all_verts, all_faces;
+  Range all_verts, all_faces;
   rval = mb.get_entities_by_dimension( 0, 0, all_verts );
   if (MB_SUCCESS != rval) return rval;
   rval = mb.get_entities_by_dimension( 0, 2, all_faces );
   if (MB_SUCCESS != rval) return rval;
   
-  MBRange expected = subtract( all_verts, interior_verts );
+  Range expected = subtract( all_verts, interior_verts );
   if (expected != skin) {
     std::cout << "Skinner returned incorrect vertices." << std::endl;
     return MB_FAILURE;
@@ -7295,10 +7296,10 @@
     std::cout << "Create face skinning failed with: " << mb.get_error_string(rval) << std::endl;
     return rval;
   }
-  MBRange all_faces2;
+  Range all_faces2;
   rval = mb.get_entities_by_dimension( 0, 2, all_faces2 );
   if (MB_SUCCESS != rval) return rval;
-  MBRange difference = subtract( all_faces2, all_faces );
+  Range difference = subtract( all_faces2, all_faces );
   if (difference.size() != 2) { // should have created two quads for hex top/bottom
     std::cout << "Skinner failed to create new quads or created to many." << std::endl;
     return MB_FAILURE;
@@ -7309,12 +7310,12 @@
     return MB_FAILURE;
   }
     // check that new faces are correct
-  MBEntityHandle expected_conn[2][4] = {
+  EntityHandle expected_conn[2][4] = {
     { verts[0][12],verts[0][13],verts[0][14],verts[0][15] },
     { verts[2][12],verts[2][13],verts[2][14],verts[2][15] } };
-  MBEntityHandle nq[2] = { difference.front(), difference.back() };
+  EntityHandle nq[2] = { difference.front(), difference.back() };
   for (int i = 0; i < 2; ++i) {
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int len;
     bool found = false;
     for (int j = 0; !found && j < 2; ++j) {
@@ -7343,7 +7344,7 @@
 }
 
 // Test that skinning of higher-order elements works
-MBErrorCode mb_skin_higher_order_faces_common( bool use_adj )
+ErrorCode mb_skin_higher_order_faces_common( bool use_adj )
 {
   /* Create mesh:
    
@@ -7356,45 +7357,45 @@
      10--11--12
   */
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   double coords[13][3] = { 
    {0,4,0}, {2,4,0}, {4,4,0}, {6,4,0}, {8,4,0},
    {0,2,0}, {2,2,0}, {4,2,0}, {5,2,0}, {6,2,0},
    {0,0,0}, {2,0,0}, {4,0,0} };
-  MBEntityHandle verts[13];
+  EntityHandle verts[13];
   for (int i = 0; i < 13; ++i) {
     rval = mb.create_vertex( coords[i], verts[i] );
     if (MB_SUCCESS != rval) return rval;
   }
   
-  MBEntityHandle qconn[9] = {
+  EntityHandle qconn[9] = {
     verts[0], verts[2], verts[12], verts[10],
     verts[1], verts[7], verts[11], verts[5],
     verts[6] };
-  MBEntityHandle tconn[7] = {
+  EntityHandle tconn[7] = {
     verts[2], verts[4], verts[12],
     verts[3], verts[9], verts[7],
     verts[8] };
-  MBEntityHandle quad, tri;
+  EntityHandle quad, tri;
   rval = mb.create_element( MBQUAD, qconn, 9, quad );
   if (MB_SUCCESS != rval) return rval;
   rval = mb.create_element( MBTRI, tconn, 7, tri );
   if (MB_SUCCESS != rval) return rval;
   
-  MBRange faces;
+  Range faces;
   faces.insert(quad);
   faces.insert(tri);
   
-  MBRange skin_verts;
+  Range skin_verts;
   const int skin_vert_idx[] = { 0, 1, 2, 3, 4, 5, 9, 10, 11, 12 };
   for (size_t i = 0; i < sizeof(skin_vert_idx)/sizeof(skin_vert_idx[0]); ++i)
     skin_verts.insert( verts[skin_vert_idx[i]] );
   
-  MBSkinner tool(&mb);
-  MBRange skin;
+  Skinner tool(&mb);
+  Range skin;
   
   rval = tool.find_skin( faces, true, skin, 0, use_adj, false );
   if (MB_SUCCESS != rval) {
@@ -7419,9 +7420,9 @@
     return MB_FAILURE;
   }
   int num_quadratic = 0;
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
-  for (MBRange::iterator i = skin.begin(); i != skin.end(); ++i) {
+  for (Range::iterator i = skin.begin(); i != skin.end(); ++i) {
     rval = mb.get_connectivity( *i, conn, len, false );
     if (MB_SUCCESS != rval) return rval;
     if (len == 3)
@@ -7438,7 +7439,7 @@
   
   for (int i = 0; i < 5; ++i) {
     bool found = false;
-    for (MBRange::iterator j = skin.begin(); j != skin.end(); ++j) {
+    for (Range::iterator j = skin.begin(); j != skin.end(); ++j) {
       mb.get_connectivity( *j, conn, len, false );
       if (conn[2] == verts[skin_edges[i][1]]) {
         found = true;
@@ -7458,13 +7459,13 @@
    
   return MB_SUCCESS;
 }
-MBErrorCode mb_skin_higher_order_faces_test( MBInterface* )
+ErrorCode mb_skin_higher_order_faces_test( Interface* )
   { return mb_skin_higher_order_faces_common( false ); }
-MBErrorCode mb_skin_adj_higher_order_faces_test( MBInterface* )
+ErrorCode mb_skin_adj_higher_order_faces_test( Interface* )
   { return mb_skin_higher_order_faces_common( true ); }
 
 // Test that skinning of higher-order elements works
-MBErrorCode mb_skin_higher_order_regions_common( bool use_adj )
+ErrorCode mb_skin_higher_order_regions_common( bool use_adj )
 {
   // create mesh containing two 27-node hexes
   /*
@@ -7477,13 +7478,13 @@
      0,0---1,0---2,0---3,0---4,0
   */
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBRange hexes;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  Range hexes;
   
   
-  MBEntityHandle verts[5][3][3];
+  EntityHandle verts[5][3][3];
   for (int i = 0; i < 5; ++i) 
     for (int j = 0; j < 3; ++j)
       for (int k = 0; k < 3; ++k) {
@@ -7505,9 +7506,9 @@
                         // mid-volume
                         {1,1,1} };
  
-  MBEntityHandle hexverts[2][27];
+  EntityHandle hexverts[2][27];
   for (int i = 0; i < 2; ++i) {
-    MBEntityHandle h;
+    EntityHandle h;
     for (int j = 0; j < 27; ++j)
       hexverts[i][j] = verts[ 2*i+hex_conn[j][0] ][ hex_conn[j][1] ][ hex_conn[j][2] ];
     rval = mb.create_element( MBHEX, hexverts[i], 27, h );
@@ -7516,13 +7517,13 @@
     hexes.insert( h );
   }
   
-  MBRange interior_verts;
+  Range interior_verts;
   interior_verts.insert( verts[1][1][1] ); // mid-node of hex 1
   interior_verts.insert( verts[3][1][1] ); // mid-node of hex 2
   interior_verts.insert( verts[2][1][1] ); // mid-node of shared face
   
-  MBSkinner tool(&mb);
-  MBRange skin;
+  Skinner tool(&mb);
+  Range skin;
 
   rval = tool.find_skin( hexes, true, skin, 0, use_adj, false );
   if (MB_SUCCESS != rval) {
@@ -7530,7 +7531,7 @@
               << std::endl;
     return rval;
   }
-  MBRange extra = intersect( skin, interior_verts );
+  Range extra = intersect( skin, interior_verts );
   if (!extra.empty()) {
     std::cout << "Skinner returned " << extra.size() << " interior vertices" 
               << std::endl;
@@ -7560,9 +7561,9 @@
   
   bool all_okay = true;
   bool faces[2][6] = { {0,0,0,0,0,0},{0,0,0,0,0,0} };
-  const MBEntityHandle *conn;
+  const EntityHandle *conn;
   int len;
-  for (MBRange::iterator it = skin.begin(); it != skin.end(); ++it) {
+  for (Range::iterator it = skin.begin(); it != skin.end(); ++it) {
     rval = mb.get_connectivity( *it, conn, len );
     if (MB_SUCCESS != rval) return rval;
     if (len != 9) {
@@ -7584,7 +7585,7 @@
       }
       
       int idx[9], len2;
-      MBEntityType sidetype;
+      EntityType sidetype;
       MBCN::SubEntityNodeIndices( MBHEX, 27, 2, side, sidetype, len2, idx );
       assert(sidetype == MBQUAD);
       assert(len2 == 9);
@@ -7627,15 +7628,15 @@
   return all_okay ? MB_SUCCESS : MB_FAILURE;
 }
 
-MBErrorCode mb_skin_higher_order_regions_test( MBInterface* )
+ErrorCode mb_skin_higher_order_regions_test( Interface* )
   { return mb_skin_higher_order_regions_common(false); }
-MBErrorCode mb_skin_adj_higher_order_regions_test( MBInterface* )
+ErrorCode mb_skin_adj_higher_order_regions_test( Interface* )
   { return mb_skin_higher_order_regions_common(true); }
 
 
-MBErrorCode mb_skin_reversed_common( int dim, bool use_adj )
+ErrorCode mb_skin_reversed_common( int dim, bool use_adj )
 {
-  MBEntityType type, subtype;
+  EntityType type, subtype;
   switch (dim) { 
     case 2: type = MBTRI; subtype = MBEDGE; break;
     case 3: type = MBTET; subtype = MBTRI;  break;
@@ -7650,48 +7651,48 @@
      0----1----2
   */
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBRange hexes;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  Range hexes;
    
   double coords[][3] = { { 0, 0, 0 },
                          { 1, 0, 0 },
                          { 2, 0, 0 },
                          { 1, 2, 0 },
                          { 1, 2, 2 } };
-  MBEntityHandle verts[5];
+  EntityHandle verts[5];
   const int nvtx = 2+dim;
   for (int i = 0; i < nvtx; ++i) {
     rval = mb.create_vertex( coords[i], verts[i] );
     if (MB_SUCCESS != rval) return rval;
   }
     // NOTE: order connectivity such that side 1 is shared!
-  MBEntityHandle conn[2][4] = { 
+  EntityHandle conn[2][4] = { 
     { verts[0], verts[1], verts[3], verts[4] },
     { verts[2], verts[3], verts[1], verts[4] } };
   const int conn_len = dim+1;
-  MBRange elems;
+  Range elems;
   for (int i = 0; i < 2; ++i) {
-    MBEntityHandle h;
+    EntityHandle h;
     rval = mb.create_element( type, conn[i], conn_len, h );
     if (MB_SUCCESS != rval) return rval;
     elems.insert(h);
   }
   
     // create one reversed side
-  MBEntityHandle side_conn[3];
+  EntityHandle side_conn[3];
   int side_indices[3] = {0,0,0};
   MBCN::SubEntityVertexIndices(type, dim-1, 0, side_indices );
   side_conn[0] = conn[0][side_indices[1]];
   side_conn[1] = conn[0][side_indices[0]];
   side_conn[2] = conn[0][side_indices[2]];
-  MBEntityHandle side;
+  EntityHandle side;
   rval = mb.create_element( subtype, side_conn, dim, side );
   if (MB_SUCCESS != rval) return rval;
   
-  MBRange forward, reverse;
-  MBSkinner tool(&mb);
+  Range forward, reverse;
+  Skinner tool(&mb);
   rval = tool.find_skin( elems, false, forward, &reverse, use_adj, true );
   if (MB_SUCCESS != rval) {
     std::cout << "Skinner failed." << std::endl;
@@ -7707,19 +7708,19 @@
   
   return MB_SUCCESS;
 }
-MBErrorCode mb_skin_faces_reversed_test( MBInterface* )
+ErrorCode mb_skin_faces_reversed_test( Interface* )
   { return mb_skin_reversed_common( 2, false ); }
-MBErrorCode mb_skin_adj_faces_reversed_test( MBInterface* )
+ErrorCode mb_skin_adj_faces_reversed_test( Interface* )
   { return mb_skin_reversed_common( 2, true ); }
-MBErrorCode mb_skin_regions_reversed_test( MBInterface* )
+ErrorCode mb_skin_regions_reversed_test( Interface* )
   { return mb_skin_reversed_common( 3, false ); }
-MBErrorCode mb_skin_adj_regions_reversed_test( MBInterface* )
+ErrorCode mb_skin_adj_regions_reversed_test( Interface* )
   { return mb_skin_reversed_common( 3, true ); }
 
 
-MBErrorCode mb_skin_subset_common( int dimension, bool use_adj )
+ErrorCode mb_skin_subset_common( int dimension, bool use_adj )
 {
-  MBEntityType type;
+  EntityType type;
   switch (dimension) { 
     case 2: type = MBTRI; break;
     case 3: type = MBPRISM; break;
@@ -7742,13 +7743,13 @@
           3
    */
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBRange expected_verts;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  Range expected_verts;
 
   const double coords2D[7][2] = { {0,2}, {1,1}, {1,-1}, {0,-2}, {-1,-1}, {-1,1}, {0,0} };
-  MBEntityHandle verts[2][7] = { {0,0,0,0,0,0,0}, {0,0,0,0,0,0,0} };
+  EntityHandle verts[2][7] = { {0,0,0,0,0,0,0}, {0,0,0,0,0,0,0} };
   for (int d = 1; d < dimension; ++d) {
     for (int i = 0; i < 7; ++i) {
       double coords[3] = { coords2D[i][0], coords2D[i][1], d-1 };
@@ -7759,21 +7760,21 @@
     }
   }
   
-  MBEntityHandle elems[6];
+  EntityHandle elems[6];
   for (int i = 0; i < 6; ++i) {
-    MBEntityHandle conn[6] = { verts[0][6], verts[0][(i+1)%6], verts[0][i],
+    EntityHandle conn[6] = { verts[0][6], verts[0][(i+1)%6], verts[0][i],
                                verts[1][6], verts[1][(i+1)%6], verts[1][i] };
     rval = mb.create_element( type, conn, MBCN::VerticesPerEntity(type), elems[i] );
     if (MB_SUCCESS != rval) return rval;
   }
   
-  MBRange input;
+  Range input;
   input.insert( elems[0] );
   input.insert( elems[1] );
   input.insert( elems[2] );
   
-  MBRange skin;
-  MBSkinner tool(&mb);
+  Range skin;
+  Skinner tool(&mb);
   rval = tool.find_skin( input, true, skin, 0, use_adj, false );
   if (MB_SUCCESS != rval) {
     std::cout << "Skinner failed to find skin vertices" << std::endl;
@@ -7790,7 +7791,7 @@
     return MB_FAILURE;
   }
     
-  std::vector<MBEntityHandle> sv( skin.begin(), skin.end() );
+  std::vector<EntityHandle> sv( skin.begin(), skin.end() );
   std::vector<int> counts( sv.size(), 0 );
   skin.clear();
   rval = tool.find_skin( input, false, skin, 0, use_adj, true );
@@ -7798,8 +7799,8 @@
     std::cout << "Skinner failed to find skin elements" << std::endl;
     return MB_FAILURE;
   }
-  for (MBRange::iterator i = skin.begin(); i != skin.end(); ++i) {
-    const MBEntityHandle *conn;
+  for (Range::iterator i = skin.begin(); i != skin.end(); ++i) {
+    const EntityHandle *conn;
     int len;
     rval = mb.get_connectivity( *i, conn, len );
     if (MB_SUCCESS != rval) return rval;
@@ -7827,21 +7828,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_skin_faces_subset_test( MBInterface* )
+ErrorCode mb_skin_faces_subset_test( Interface* )
   { return mb_skin_subset_common( 2, false ); }
-MBErrorCode mb_skin_adj_faces_subset_test( MBInterface* )
+ErrorCode mb_skin_adj_faces_subset_test( Interface* )
   { return mb_skin_subset_common( 2, true ); }
-MBErrorCode mb_skin_regions_subset_test( MBInterface* )
+ErrorCode mb_skin_regions_subset_test( Interface* )
   { return mb_skin_subset_common( 3, false ); }
-MBErrorCode mb_skin_adj_regions_subset_test( MBInterface* )
+ErrorCode mb_skin_adj_regions_subset_test( Interface* )
   { return mb_skin_subset_common( 3, true ); }
   
   
     
  
-MBErrorCode mb_skin_full_common( int dimension, bool use_adj )
+ErrorCode mb_skin_full_common( int dimension, bool use_adj )
 {
-  MBEntityType type;
+  EntityType type;
   switch (dimension) { 
     case 2: type = MBQUAD; break;
     case 3: type = MBHEX; break;
@@ -7856,13 +7857,13 @@
       0----1----2
   */
   
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
  
     // create vertices
   const double coords2D[6][2] = { {0,0}, {1,0}, {2,0}, {0,1}, {1,1}, {2,1} };
-  MBEntityHandle v[2][6] = { {0,0,0,0,0,0}, {0,0,0,0,0,0} };
+  EntityHandle v[2][6] = { {0,0,0,0,0,0}, {0,0,0,0,0,0} };
   for (int d = 1; d < dimension; ++d) {
     for (int i = 0; i < 6; ++i) {
       double coords[3] = { coords2D[i][0], coords2D[i][1], d-1 };
@@ -7872,10 +7873,10 @@
   }
   
     // create elements
-  MBRange input;
-  MBEntityHandle elems[2], econn[2][8];;
+  Range input;
+  EntityHandle elems[2], econn[2][8];;
   for (int i = 0; i < 2; ++i) {
-    MBEntityHandle conn[8] = { v[0][i], v[0][i+1], v[0][i+4], v[0][i+3],
+    EntityHandle conn[8] = { v[0][i], v[0][i+1], v[0][i+4], v[0][i+3],
                                v[1][i], v[1][i+1], v[1][i+4], v[1][i+3] };
     memcpy( econn[i], conn, sizeof(conn) );
     rval = mb.create_element( type, conn, MBCN::VerticesPerEntity(type), elems[i] );
@@ -7885,20 +7886,20 @@
   
     // create sides
     // NOTE: Shared side is element 0 side 1 and element 1 side 3
-  MBRange expected;
+  Range expected;
   for (int i = 0; i < MBCN::NumSubEntities( type, dimension-1 ); ++i) {
-    MBEntityType subtype;
+    EntityType subtype;
     int len;
     const short* indices = MBCN::SubEntityVertexIndices( type, dimension-1,
                                                          i, subtype, len );
-    MBEntityHandle conn[4];
+    EntityHandle conn[4];
     assert((size_t)len <= sizeof(conn)/sizeof(conn[0]));
     for (int j = 0; j < 2; ++j) {
       if (j == 1 && i == 3) // don't create shared face twice
         continue;
       for (int k = 0; k < len; ++k)
         conn[k] = econn[j][indices[k]];
-      MBEntityHandle h;
+      EntityHandle h;
       rval = mb.create_element( subtype, conn, len, h );
       if (MB_SUCCESS != rval) return rval;
       if (j != 0 || i != 1) // don't insert shared face
@@ -7906,8 +7907,8 @@
     }
   }
   
-  MBRange skin;
-  MBSkinner tool(&mb);
+  Range skin;
+  Skinner tool(&mb);
   rval = tool.find_skin( input, false, skin, 0, use_adj, true );
   if (MB_SUCCESS != rval) {
     std::cout << "Skinner failed to find skin elements" << std::endl;
@@ -7928,21 +7929,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode mb_skin_faces_full_test( MBInterface* )
+ErrorCode mb_skin_faces_full_test( Interface* )
   { return mb_skin_full_common( 2, false ); }
-MBErrorCode mb_skin_adj_faces_full_test( MBInterface* )
+ErrorCode mb_skin_adj_faces_full_test( Interface* )
   { return mb_skin_full_common( 2, true ); }
-MBErrorCode mb_skin_regions_full_test( MBInterface* )
+ErrorCode mb_skin_regions_full_test( Interface* )
   { return mb_skin_full_common( 3, false ); }
-MBErrorCode mb_skin_adj_regions_full_test( MBInterface* )
+ErrorCode mb_skin_adj_regions_full_test( Interface* )
   { return mb_skin_full_common( 3, true ); }
         
-MBErrorCode mb_skin_adjacent_surf_patches( MBInterface* )
+ErrorCode mb_skin_adjacent_surf_patches( Interface* )
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
-  MBSkinner tool(&mb);
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
+  Skinner tool(&mb);
   
   /* Mesh with vertices and quads numbered. 
      Groups are indicated by letters {A,B,C,D}
@@ -7963,7 +7964,7 @@
   */
   
   const int num_vtx = 30;
-  MBEntityHandle vtx[num_vtx];
+  EntityHandle vtx[num_vtx];
   for (int i = 0; i < 6; ++i) {
     for (int j = 0; j < 5; ++j) {
       double coords[3] = {i, j, 0};
@@ -7972,11 +7973,11 @@
     }
   }
   
-  MBEntityHandle quads[20];
+  EntityHandle quads[20];
   for (int i = 0; i < 5; ++i) {
     for (int j = 0; j < 4; ++j) {
       int v = 6*j+i;
-      MBEntityHandle conn[4] = { vtx[v+6], vtx[v+7], vtx[v+1], vtx[v+0] };
+      EntityHandle conn[4] = { vtx[v+6], vtx[v+7], vtx[v+1], vtx[v+0] };
       rval = mb.create_element( MBQUAD, conn, 4, quads[5*j+i] );
       if (MB_SUCCESS != rval) return rval;
     }
@@ -8014,8 +8015,8 @@
   const int* const shared[4] = { Ashared, Bshared, Cshared, Dshared };
   const int skin_size[4] = { Askin_size, Bskin_size, Cskin_size, Dskin_size };
   
-    // Create an MBRange for each group of quads
-  MBRange ranges[4];
+    // Create an Range for each group of quads
+  Range ranges[4];
   for (int grp = 0; grp < 4; ++grp) 
     for (int i = 0; i < gquads_size[grp]; ++i)
       ranges[grp].insert( quads[gquads[grp][i]] );
@@ -8033,13 +8034,13 @@
   for (int run = 0; run < 4; ++run) {
     const bool use_adj = run > 1;
     if (run == 3) {
-      MBRange dead;
+      Range dead;
       mb.get_entities_by_type( 0, MBEDGE, dead );
       mb.delete_entities( dead );
     }
     
       // test each group
-    MBRange edges[4];
+    Range edges[4];
     for (int grp = 0; grp < 4; ++grp) {
         // get the skin edges
       rval = tool.find_skin( ranges[grp], 1, edges[grp], use_adj );
@@ -8050,8 +8051,8 @@
       
         // check that we have the expected result
       std::vector<bool> seen(skin_size[grp], false);
-      for (MBRange::iterator e = edges[grp].begin(); e != edges[grp].end(); ++e) {
-        const MBEntityHandle* conn;
+      for (Range::iterator e = edges[grp].begin(); e != edges[grp].end(); ++e) {
+        const EntityHandle* conn;
         int len;
         rval = mb.get_connectivity( *e, conn, len );
         if (MB_SUCCESS != rval) return rval;

Modified: MOAB/trunk/test/Makefile.am
===================================================================
--- MOAB/trunk/test/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,19 +1,20 @@
-SUBDIRS = dual obb perf io 
+SUBDIRS = . io dual obb perf
 if HDF5_FILE
   SUBDIRS += h5file
 endif
 if PARALLEL
   SUBDIRS += parallel
 endif
+if OLD_HEADERS
+  SUBDIRS += oldinc
+endif
 
 LDADD = $(top_builddir)/src/libMOAB.la
 
 AM_CPPFLAGS += -DIS_BUILDING_MB \
                -DSRCDIR=$(srcdir) \
                -I$(top_builddir)/src \
-               -I$(top_srcdir)/src \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/moab
+               -I$(top_srcdir)/src 
 
 TESTS = moab_test \
         homxform_test \
@@ -111,7 +112,7 @@
 geom_util_test_SOURCES = TestUtil.hpp GeomUtilTests.cpp 
 geom_util_test_DEPENDENCIES = $(LDADD)
 
-xform_test_SOURCES = $(top_srcdir)/src/MBAffineXform.cpp
+xform_test_SOURCES = $(top_srcdir)/src/AffineXform.cpp
 xform_test_CPPFLAGS = -DTEST $(AM_CPPFLAGS) $(CPPFLAGS)
 xform_test_DEPENDENCIES = $(LDADD)
 

Modified: MOAB/trunk/test/OBBTest.cpp
===================================================================
--- MOAB/trunk/test/OBBTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/OBBTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,10 @@
-#include "MBOrientedBox.hpp"
-#include "MBCartVect.hpp"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "OrientedBox.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 
+using namespace moab;
+
 #include <assert.h>
 
 const double TOL = 1e-6;
@@ -22,8 +24,8 @@
 #define ASSERT_DOUBLES_EQUAL(A, B) assert_doubles_equal( (A), (B), #A, #B, __LINE__ )
 #define ASSERT(B) assert_bool( (B), #B, __LINE__ )
 
-static void assert_vector_element( const MBCartVect& a, const MBCartVect* b, const char* sa, const char* sb, int lineno );
-static void assert_vectors_equal( const MBCartVect& a, const MBCartVect& b, const char* sa, const char* sb, int lineno );
+static void assert_vector_element( const CartVect& a, const CartVect* b, const char* sa, const char* sb, int lineno );
+static void assert_vectors_equal( const CartVect& a, const CartVect& b, const char* sa, const char* sb, int lineno );
 static void assert_doubles_equal( double a, double b, const char* sa, const char* sb, int lineno );
 static void assert_bool( bool b, const char* sb, int lineno );
 
@@ -43,32 +45,32 @@
 /********************* Declare some boxes to test ***************************/
 
   // define unit box centered at origin
-const MBCartVect origin( 0.0, 0.0, 0.0 );
-const MBCartVect unitaxes[3] = { MBCartVect(0.5, 0.0, 0.0),
-                                 MBCartVect(0.0, 0.5, 0.0),
-                                 MBCartVect(0.0, 0.0, 0.5) };
-const MBOrientedBox unitbox( unitaxes, origin );
+const CartVect origin( 0.0, 0.0, 0.0 );
+const CartVect unitaxes[3] = { CartVect(0.5, 0.0, 0.0),
+                                 CartVect(0.0, 0.5, 0.0),
+                                 CartVect(0.0, 0.0, 0.5) };
+const OrientedBox unitbox( unitaxes, origin );
 
   // define axis-aligned unit box outside origin
-const MBCartVect unitcenter( 10, 20, 30 );
-const MBOrientedBox offsetbox( unitaxes, unitcenter );
+const CartVect unitcenter( 10, 20, 30 );
+const OrientedBox offsetbox( unitaxes, unitcenter );
 
   // define non-unit centered at origin
-const MBCartVect origaxes[3] = { 5*unitaxes[0],
+const CartVect origaxes[3] = { 5*unitaxes[0],
                                 10*unitaxes[1],
                                 .1*unitaxes[2] };
-const MBOrientedBox oblongbox( origaxes, origin );
+const OrientedBox oblongbox( origaxes, origin );
 
   // define non-axis-aligned unit box at origin
-const MBCartVect rotaxes[3] = { unit( MBCartVect( 1.0, 1.0, 0.0 ) ),
-                                unit( MBCartVect( 1.0,-1.0, 1.0 ) ),
-                                unit( MBCartVect( 1.0, 1.0, 0.0 )*MBCartVect( 1.0,-1.0, 1.0 ) ) };
-const MBOrientedBox rotbox( rotaxes, origin );
+const CartVect rotaxes[3] = { unit( CartVect( 1.0, 1.0, 0.0 ) ),
+                                unit( CartVect( 1.0,-1.0, 1.0 ) ),
+                                unit( CartVect( 1.0, 1.0, 0.0 )*CartVect( 1.0,-1.0, 1.0 ) ) };
+const OrientedBox rotbox( rotaxes, origin );
 
 /********************* Utility methods for tests ***************************/
 
 // return point at specified fraction between box center and specified box corner
-static MBCartVect scaled_corner( const MBOrientedBox& box, int corner, double factor )
+static CartVect scaled_corner( const OrientedBox& box, int corner, double factor )
 {
   static const int signs[][3] = { { 1, 1,-1},
                                   {-1, 1,-1},
@@ -85,7 +87,7 @@
 }
 
 // return point at specified fraction between box center and specified box face
-static MBCartVect scaled_face( const MBOrientedBox& box, int face, double factor )
+static CartVect scaled_face( const OrientedBox& box, int face, double factor )
 {
   assert(face >= 0 && face <= 6);
   int sign = face % 2 ? -1 : 1;
@@ -93,9 +95,9 @@
 }
 
 // get vector containing axis lengths, ordered from smallest to largest
-static void axis_dims( const MBCartVect axis[3], MBCartVect& dims )
+static void axis_dims( const CartVect axis[3], CartVect& dims )
 {
-  dims = MBCartVect(axis[0].length(), axis[1].length(), axis[2].length());
+  dims = CartVect(axis[0].length(), axis[1].length(), axis[2].length());
   if (dims[0] > dims[1]) 
     std::swap(dims[0], dims[1]);
   if (dims[1] > dims[2])
@@ -109,7 +111,7 @@
 
 static void test_basic()
 {
-  MBCartVect dims;
+  CartVect dims;
   
   axis_dims( unitaxes, dims );
   ASSERT_VECTORS_EQUAL( unitbox.center, origin );
@@ -403,7 +405,7 @@
 
 static void test_closest_point()
 {
-  MBCartVect result;
+  CartVect result;
   
     // start with unit box
     
@@ -772,7 +774,7 @@
 
 void test_ray_intersect()
 {
-  MBCartVect dir, pt;
+  CartVect dir, pt;
   
   // start with unit box
   
@@ -1153,8 +1155,8 @@
 
 void test_build_from_tri()
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
   int i;
   
   // define a planar patch of triangles
@@ -1212,15 +1214,15 @@
                       8,19,20 };
   
     // build triangle mesh
-  std::vector<MBEntityHandle> vertices(21);
+  std::vector<EntityHandle> vertices(21);
   for (i = 0; i < 21; ++i) {
     rval = moab.create_vertex( coords + 3*i, vertices[i] );
     ASSERT(MB_SUCCESS == rval);
   }
-  MBRange tris;
+  Range tris;
   for (i = 0; i < 28; ++i) {
-    MBEntityHandle tri;
-    MBEntityHandle c[3] = { vertices[conn[3*i  ]],
+    EntityHandle tri;
+    EntityHandle c[3] = { vertices[conn[3*i  ]],
                             vertices[conn[3*i+1]],
                             vertices[conn[3*i+2]] };
     rval = moab.create_element( MBTRI, c, 3, tri );
@@ -1229,22 +1231,22 @@
   }
   
     // create box from triangles
-  MBOrientedBox box;
-  rval = MBOrientedBox::compute_from_2d_cells( box, &moab, tris );
+  OrientedBox box;
+  rval = OrientedBox::compute_from_2d_cells( box, &moab, tris );
   ASSERT( MB_SUCCESS == rval );
   
     // compute range along each box axis for input vertices
-  const MBCartVect axis[3] = { box.scaled_axis(0),
+  const CartVect axis[3] = { box.scaled_axis(0),
                                box.scaled_axis(1),
                                box.scaled_axis(2) };
   double min[3], max[3];
-  MBCartVect v = MBCartVect(coords) - box.center;
+  CartVect v = CartVect(coords) - box.center;
   min[0] = max[0] = box.scaled_axis(0) % v;
   min[1] = max[1] = box.scaled_axis(1) % v;
   min[2] = max[2] = box.scaled_axis(2) % v;
   for (i = 1; i < 21; ++i) {
-    MBCartVect vi( coords + 3*i );
-    MBCartVect v = vi - box.center;
+    CartVect vi( coords + 3*i );
+    CartVect v = vi - box.center;
     for (int j = 0; j < 3; ++j) {
       double d = (axis[j] % v) / (axis[j] % axis[j]);
       if (d < min[j])
@@ -1254,7 +1256,7 @@
     }
   }
   
-  const MBCartVect size = 0.5 * box.dimensions();
+  const CartVect size = 0.5 * box.dimensions();
   
     // Vrify that all points are contained in box 
     // and that box fits points tightly.
@@ -1268,7 +1270,7 @@
     // verify that the box is flat along first axis
   ASSERT( box.dimensions()[0] <= TOL );
     // verify that other two axes are in XY plane
-  const MBCartVect z_axis(0.0,0.0,1.0);
+  const CartVect z_axis(0.0,0.0,1.0);
   ASSERT( fabs(box.axis[1] % z_axis) <= TOL );
   ASSERT( fabs(box.axis[2] % z_axis) <= TOL );
 }
@@ -1277,9 +1279,9 @@
 
 void test_build_from_pts()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface* const gMB = &moab;
+  ErrorCode rval;
+  Core moab;
+  Interface* const gMB = &moab;
   
   const double vertex_coords[] =
     { 0, 0, 0,
@@ -1295,11 +1297,11 @@
   assert (0 == num_double%3);
   
     // create some vertices
-  MBRange vertices;
+  Range vertices;
   double min[3] = { HUGE_VAL,  HUGE_VAL,  HUGE_VAL};
   double max[3] = {-HUGE_VAL, -HUGE_VAL, -HUGE_VAL};
   for (int i = 0; i < num_vertex; ++i) {
-    MBEntityHandle h;
+    EntityHandle h;
     rval = gMB->create_vertex( vertex_coords + 3*i, h );
     ASSERT( MB_SUCCESS == rval );
     vertices.insert(h);
@@ -1311,12 +1313,12 @@
   }
   
     // create box containing vertices
-  MBOrientedBox box;
-  rval = MBOrientedBox::compute_from_vertices( box, gMB, vertices );
+  OrientedBox box;
+  rval = OrientedBox::compute_from_vertices( box, gMB, vertices );
   ASSERT( MB_SUCCESS == rval );
   
   for (int i = 0; i < num_vertex; ++i) {
-    ASSERT( box.contained( MBCartVect(vertex_coords[3*i]), 1e-6 ) );
+    ASSERT( box.contained( CartVect(vertex_coords[3*i]), 1e-6 ) );
   }
   
     // define a set of points otside of the box to test
@@ -1338,33 +1340,33 @@
   double *outside[3] = {outside1, outside2, outside3};
     // test 'contained' method for all points
   for (int i = 0; i < 3; ++i) {
-    ASSERT( ! box.contained( MBCartVect(outside[i]), 1e-6 ) );
+    ASSERT( ! box.contained( CartVect(outside[i]), 1e-6 ) );
   } 
 }
 
 static void test_save()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBOrientedBox box;
+  ErrorCode rval;
+  Core moab;
+  OrientedBox box;
   
     // create a tag to store the data in
-  MBTag tag;
-  rval = MBOrientedBox::tag_handle( tag, &moab, "FOO" );
+  Tag tag;
+  rval = OrientedBox::tag_handle( tag, &moab, "FOO" );
   ASSERT( MB_SUCCESS == rval );
   
     // check tag size
   int size;
   rval= moab.tag_get_size( tag, size );
   ASSERT( MB_SUCCESS == rval );
-  ASSERT( size == sizeof(MBOrientedBox) );
+  ASSERT( size == sizeof(OrientedBox) );
 }
 
 
 /********************* Error Checking Code ***************************/
 
-static void assert_vector_element( const MBCartVect& a, 
-                                   const MBCartVect b[3], 
+static void assert_vector_element( const CartVect& a, 
+                                   const CartVect b[3], 
                                    const char* sa, 
                                    const char* sb, 
                                    int lineno )
@@ -1384,7 +1386,7 @@
 }
 
 
-void assert_vectors_equal( const MBCartVect& a, const MBCartVect& b, 
+void assert_vectors_equal( const CartVect& a, const CartVect& b, 
                            const char* sa, const char* sb,
                            int lineno )
 {

Modified: MOAB/trunk/test/TagTest.cpp
===================================================================
--- MOAB/trunk/test/TagTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/TagTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include "TestUtil.hpp"
 #include <stdlib.h>
 #include <algorithm>
 
+using namespace moab;
+
 void test_create_tag();
 void test_invalid_tag_size();
 void test_get_set_sparse_int();
@@ -71,28 +73,28 @@
 }
   
 
-void setup_mesh( MBInterface& mesh );
+void setup_mesh( Interface& mesh );
 
-MBTag test_create_tag( MBInterface& mb,
+Tag test_create_tag( Interface& mb,
                        const char* name,
                        unsigned bytes,
-                       MBTagType storage,
-                       MBDataType type,
+                       TagType storage,
+                       DataType type,
                        const void* defval,
-                       MBErrorCode expect = MB_SUCCESS );
+                       ErrorCode expect = MB_SUCCESS );
 
-MBTag test_create_var_len_tag( MBInterface& mb,
+Tag test_create_var_len_tag( Interface& mb,
                                const char* name,
-                               MBTagType storage,
-                               MBDataType type,
+                               TagType storage,
+                               DataType type,
                                const void* defval,
                                int defval_size,
-                               MBErrorCode expect = MB_SUCCESS );
+                               ErrorCode expect = MB_SUCCESS );
 
 void test_get_set( const char* name,
                    unsigned bytes,
-                   MBTagType storage, 
-                   MBDataType type, 
+                   TagType storage, 
+                   DataType type, 
                    const void* some_values, 
                    int num_values,
                    const void* default_value,
@@ -100,31 +102,31 @@
                    bool get_by_pointer = false );
 
 void test_get_set_variable_length( const char* name,
-                                   MBTagType storage, 
-                                   MBDataType type, 
+                                   TagType storage, 
+                                   DataType type, 
                                    const void** values,
                                    const int* lengths,
                                    int num_values,
                                    const void* default_value,
                                    int default_value_length );
 
-void test_mesh_value( MBInterface& mb,
+void test_mesh_value( Interface& mb,
                       const char* tag_name,
                       unsigned tag_size,
-                      MBTagType tag_storage,
-                      MBDataType tag_type,
+                      TagType tag_storage,
+                      DataType tag_type,
                       const void* value );
 
-MBTag test_create_tag( MBInterface& mb,
+Tag test_create_tag( Interface& mb,
                        const char* name,
                        unsigned bytes,
-                       MBTagType storage,
-                       MBDataType type,
+                       TagType storage,
+                       DataType type,
                        const void* defval,
-                       MBErrorCode expect  )
+                       ErrorCode expect  )
 {
-  MBErrorCode rval;
-  MBTag tag;
+  ErrorCode rval;
+  Tag tag;
   
   if (type == MB_TYPE_OPAQUE) 
     rval = mb.tag_create( name, bytes, storage, tag, defval );
@@ -142,7 +144,7 @@
   CHECK_ERR(rval);
   CHECK( n == name );
   
-  MBTag tag2;
+  Tag tag2;
   rval = mb.tag_get_handle( name, tag2 );
   CHECK_ERR(rval);
   CHECK_EQUAL( tag, tag2 );
@@ -152,12 +154,12 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( (int)bytes, s );
   
-  MBTagType t;
+  TagType t;
   rval = mb.tag_get_type( tag, t );
   CHECK_ERR(rval);
   CHECK_EQUAL( storage, t );
   
-  MBDataType d;
+  DataType d;
   rval = mb.tag_get_data_type( tag, d );
   CHECK_ERR(rval);
   CHECK_EQUAL( type, d );
@@ -183,16 +185,16 @@
 }
   
 
-MBTag test_create_var_len_tag( MBInterface& mb,
+Tag test_create_var_len_tag( Interface& mb,
                                const char* name,
-                               MBTagType storage,
-                               MBDataType type,
+                               TagType storage,
+                               DataType type,
                                const void* defval,
                                int defval_size,
-                               MBErrorCode expect  )
+                               ErrorCode expect  )
 {
-  MBErrorCode rval;
-  MBTag tag;
+  ErrorCode rval;
+  Tag tag;
   
   rval = mb.tag_create_variable_length( name, storage, type, tag, defval, defval_size );
   if (expect != MB_SUCCESS) {
@@ -206,7 +208,7 @@
   CHECK_ERR(rval);
   CHECK( n == name );
   
-  MBTag tag2;
+  Tag tag2;
   rval = mb.tag_get_handle( name, tag2 );
   CHECK_ERR(rval);
   CHECK_EQUAL( tag, tag2 );
@@ -217,12 +219,12 @@
   //CHECK_ERR(rval);
   //CHECK_EQUAL( MB_VARIABLE_LENGTH, s );
   
-  MBTagType t;
+  TagType t;
   rval = mb.tag_get_type( tag, t );
   CHECK_ERR(rval);
   CHECK_EQUAL( storage, t );
   
-  MBDataType d;
+  DataType d;
   rval = mb.tag_get_data_type( tag, d );
   CHECK_ERR(rval);
   CHECK_EQUAL( type, d );
@@ -251,7 +253,7 @@
 
 void test_create_tag()
 { 
-  MBCore mb;
+  Core mb;
   unsigned char defval[] = { 1, 2, 3, 4, 0, 0, 0, 0 };
    
     // opaque tags
@@ -269,7 +271,7 @@
   test_create_tag( mb, "dbl_tag_dense", 2*sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, defval2 );
     
     // handle tags
-  test_create_tag( mb, "h_tag_dense", sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE, defval );
+  test_create_tag( mb, "h_tag_dense", sizeof(EntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE, defval );
   
     // bit tags
   unsigned char def_bit_val = 0xBF;
@@ -279,7 +281,7 @@
 
 void test_create_variable_length_tag()
 { 
-  MBCore mb;
+  Core mb;
   unsigned char defval[] = { 1, 2, 3, 4, 0, 0, 0, 0 };
    
     // opaque tags
@@ -306,8 +308,8 @@
   // test that MOAB enforces the rule that the the size must be multiple of the type
 void test_invalid_tag_size()
 {
-  const MBErrorCode err = MB_INVALID_SIZE;
-  MBCore mb;
+  const ErrorCode err = MB_INVALID_SIZE;
+  Core mb;
 
     // double
   test_create_tag( mb, "std ",   0,                MB_TAG_DENSE , MB_TYPE_DOUBLE, 0, err );
@@ -327,10 +329,10 @@
     // handle
   test_create_tag( mb, "sth ",   0,                        MB_TAG_DENSE , MB_TYPE_HANDLE, 0, err );
   test_create_tag( mb, "sth0",   1,                        MB_TAG_SPARSE, MB_TYPE_HANDLE, 0, err );
-  test_create_tag( mb, "sth1",   sizeof(MBEntityHandle)-1, MB_TAG_DENSE , MB_TYPE_HANDLE, 0, err );
-  test_create_tag( mb, "sth2",   sizeof(MBEntityHandle)-2, MB_TAG_SPARSE, MB_TYPE_HANDLE, 0, err );
-  test_create_tag( mb, "sth3",   sizeof(MBEntityHandle)/2, MB_TAG_SPARSE, MB_TYPE_HANDLE, 0, err );
-  test_create_tag( mb, "sth4", 2*sizeof(MBEntityHandle)-1, MB_TAG_DENSE,  MB_TYPE_HANDLE, 0, err );
+  test_create_tag( mb, "sth1",   sizeof(EntityHandle)-1, MB_TAG_DENSE , MB_TYPE_HANDLE, 0, err );
+  test_create_tag( mb, "sth2",   sizeof(EntityHandle)-2, MB_TAG_SPARSE, MB_TYPE_HANDLE, 0, err );
+  test_create_tag( mb, "sth3",   sizeof(EntityHandle)/2, MB_TAG_SPARSE, MB_TYPE_HANDLE, 0, err );
+  test_create_tag( mb, "sth4", 2*sizeof(EntityHandle)-1, MB_TAG_DENSE,  MB_TYPE_HANDLE, 0, err );
 }
 
 // Given a list of sequential values in memory (pointed to by 'concat'), 
@@ -347,8 +349,8 @@
   // test get/set of tag values
 void test_get_set( const char* name,
                    unsigned bytes,
-                   MBTagType storage, 
-                   MBDataType type, 
+                   TagType storage, 
+                   DataType type, 
                    const void* some_values, 
                    int num_values,
                    const void* default_value,
@@ -358,38 +360,38 @@
   std::vector<unsigned char> data;
   
     // create mesh and tag
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   setup_mesh( mb );
-  MBTag tag = test_create_tag( mb, name, bytes, storage, type, default_value );
+  Tag tag = test_create_tag( mb, name, bytes, storage, type, default_value );
   
     // get some handles to work with
-  MBRange entities;
-  MBErrorCode rval = mb.get_entities_by_handle( 0, entities );
+  Range entities;
+  ErrorCode rval = mb.get_entities_by_handle( 0, entities );
   CHECK_ERR(rval);
   CHECK( !entities.empty() );
   
     // split handles into four groups
     // a) a single handle
     // b) some non-consecutive handles in an array
-    // c) some handles in an MBRange
+    // c) some handles in an Range
     // d) remaining handles (remaining in 'entities');
-  MBEntityHandle one_handle;
-  MBRange::iterator i = entities.begin() += entities.size()/2;
+  EntityHandle one_handle;
+  Range::iterator i = entities.begin() += entities.size()/2;
   one_handle = *i;
   entities.erase( i );
   
-  MBRange handle_range;
-  std::vector<MBEntityHandle> handle_list;
-  for (MBRange::const_pair_iterator i =  entities.const_pair_begin(); 
+  Range handle_range;
+  std::vector<EntityHandle> handle_list;
+  for (Range::const_pair_iterator i =  entities.const_pair_begin(); 
                                     i != entities.const_pair_end(); ++i) {
     if (i->first == i->second || i->second - i->first == 1) {
-      MBEntityHandle h1 = i->first, h2 = i->second;
+      EntityHandle h1 = i->first, h2 = i->second;
       ++i;
       handle_range.insert( h1, h2 );
     }
     else {
-      MBEntityHandle mid = (MBEntityHandle)(i->first + (i->second - i->first + 1) / 2);
+      EntityHandle mid = (EntityHandle)(i->first + (i->second - i->first + 1) / 2);
       handle_list.push_back( mid );
       handle_range.insert( mid+1, i->second );
     }
@@ -466,7 +468,7 @@
       CHECK( !memcmp( ptr, list[j], bytes ) );
   }
   
-    // try getting/setting for MBRange of handles
+    // try getting/setting for Range of handles
     
     // set data for range
   if (set_by_pointer) {
@@ -720,20 +722,20 @@
 void test_get_set_bit()
 {
     // create mesh and tag
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   setup_mesh( mb );
-  MBTag tag = test_create_tag( mb, "bit_val", 2, MB_TAG_BIT, MB_TYPE_BIT, 0 );
+  Tag tag = test_create_tag( mb, "bit_val", 2, MB_TAG_BIT, MB_TYPE_BIT, 0 );
   
     // get some handles to work with
-  MBRange entities;
-  MBErrorCode rval = mb.get_entities_by_handle( 0, entities );
+  Range entities;
+  ErrorCode rval = mb.get_entities_by_handle( 0, entities );
   CHECK_ERR(rval);
   CHECK( !entities.empty() );
   
     // set bits on every entity
   unsigned counter = 0;
-  for (MBRange::iterator i = entities.begin(); i != entities.end(); ++i) {
+  for (Range::iterator i = entities.begin(); i != entities.end(); ++i) {
     srand( counter++ );
     unsigned char bits = (unsigned char)(rand() & 3);
     rval = mb.tag_set_data( tag, &*i, 1, &bits );
@@ -745,12 +747,12 @@
     // test default value
   unsigned char defval = '\003';
   unsigned char zero = '\0';
-  MBTag tag2 = test_create_tag( mb, "bit_val2", 3, MB_TAG_BIT, MB_TYPE_BIT, &defval );
+  Tag tag2 = test_create_tag( mb, "bit_val2", 3, MB_TAG_BIT, MB_TYPE_BIT, &defval );
   CHECK( entities.size() >= 3 );
-  MBRange::iterator j = entities.begin();
-  MBEntityHandle h1 = *j; ++j;
-  MBEntityHandle h2 = *j; ++j;
-  MBEntityHandle h3 = *j; ++j;
+  Range::iterator j = entities.begin();
+  EntityHandle h1 = *j; ++j;
+  EntityHandle h2 = *j; ++j;
+  EntityHandle h3 = *j; ++j;
   rval = mb.tag_set_data( tag2, &h1, 1, &zero );
   CHECK_ERR(rval);
   rval = mb.tag_set_data( tag2, &h3, 1, &zero );
@@ -768,7 +770,7 @@
   
     // test default value for uninitialized data (tag not set for any entity)
   defval = '\002';
-  MBTag tag3 = test_create_tag( mb, "bit_val3", 2, MB_TAG_BIT, MB_TYPE_BIT, &defval );
+  Tag tag3 = test_create_tag( mb, "bit_val3", 2, MB_TAG_BIT, MB_TYPE_BIT, &defval );
   rval = mb.tag_get_data( tag3, &h2, 1, &byte );
   CHECK_ERR( rval );
   CHECK_EQUAL( defval, byte );
@@ -777,20 +779,20 @@
 void test_get_by_tag( )
 {
     // create mesh and tag
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   setup_mesh( mb );
-  MBTag tag = test_create_tag( mb, "sparse_count", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, 0 );
+  Tag tag = test_create_tag( mb, "sparse_count", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, 0 );
   
     // get some handles to work with
-  MBRange entities;
-  MBErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, entities );
+  Range entities;
+  ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, entities );
   CHECK_ERR(rval);
   CHECK( !entities.empty() );
 
     // get five handles
   CHECK( entities.size() > 6 );
-  MBEntityHandle arr[5] = { *(entities.begin() +=   entities.size()/6),
+  EntityHandle arr[5] = { *(entities.begin() +=   entities.size()/6),
                             *(entities.begin() += 2*entities.size()/6),
                             *(entities.begin() += 3*entities.size()/6),
                             *(entities.begin() += 4*entities.size()/6),
@@ -801,7 +803,7 @@
   const void* const valarr[1] = { 0 };
   
     // put some in a mesh set
-  MBEntityHandle set;
+  EntityHandle set;
   const int num_in_set = 3;
   rval = mb.create_meshset( 0, set );
   CHECK_ERR(rval);
@@ -827,11 +829,11 @@
   
   
     // try for whole mesh will null tag value array
-  MBRange found;
+  Range found;
   rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, found );
   CHECK_ERR( rval );
   CHECK_EQUAL( 5u, (unsigned)found.size() );
-  MBRange::iterator i = found.begin();
+  Range::iterator i = found.begin();
   CHECK_EQUAL( arr[0], *i ); ++i;
   CHECK_EQUAL( arr[1], *i ); ++i;
   CHECK_EQUAL( arr[2], *i ); ++i;
@@ -864,20 +866,20 @@
 void test_get_by_tag_value( )
 {
     // create mesh and tag
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   setup_mesh( mb );
-  MBTag tag = test_create_tag( mb, "sparse_count", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, 0 );
+  Tag tag = test_create_tag( mb, "sparse_count", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, 0 );
   
     // get some handles to work with
-  MBRange entities;
-  MBErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, entities );
+  Range entities;
+  ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, entities );
   CHECK_ERR(rval);
   CHECK( !entities.empty() );
 
     // get five handles
   CHECK( entities.size() > 6 );
-  MBEntityHandle arr[5] = { *(entities.begin() +=   entities.size()/6),
+  EntityHandle arr[5] = { *(entities.begin() +=   entities.size()/6),
                             *(entities.begin() += 2*entities.size()/6),
                             *(entities.begin() += 3*entities.size()/6),
                             *(entities.begin() += 4*entities.size()/6),
@@ -888,7 +890,7 @@
   const void* const valarr[1] = { values };
   
     // put some in a mesh set
-  MBEntityHandle set;
+  EntityHandle set;
   const int num_in_set = 3;
   rval = mb.create_meshset( 0, set );
   CHECK_ERR(rval);
@@ -908,11 +910,11 @@
   
   
     // try for whole mesh 
-  MBRange found;
+  Range found;
   rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, valarr, 1, found );
   CHECK_ERR( rval );
   CHECK_EQUAL( 5u, (unsigned)found.size() );
-  MBRange::iterator i = found.begin();
+  Range::iterator i = found.begin();
   CHECK_EQUAL( arr[0], *i ); ++i;
   CHECK_EQUAL( arr[1], *i ); ++i;
   CHECK_EQUAL( arr[2], *i ); ++i;
@@ -930,21 +932,21 @@
   CHECK_EQUAL( arr[2], *i ); ++i;
 }
 
-void test_mesh_value( MBInterface& mb,
+void test_mesh_value( Interface& mb,
                       const char* tag_name,
                       unsigned tag_size,
-                      MBTagType tag_storage,
-                      MBDataType tag_type,
+                      TagType tag_storage,
+                      DataType tag_type,
                       const void* value )
 {
     // create  tag
-  MBTag tag = test_create_tag( mb, tag_name, tag_size, tag_storage, tag_type, 0 );
+  Tag tag = test_create_tag( mb, tag_name, tag_size, tag_storage, tag_type, 0 );
   
   unsigned memcmp_size = tag_size;
   if (tag_storage == MB_TAG_BIT || tag_type == MB_TYPE_BIT)
     memcmp_size = 1;
   
-  MBErrorCode rval = mb.tag_set_data( tag, 0, 0, value );
+  ErrorCode rval = mb.tag_set_data( tag, 0, 0, value );
   CHECK_ERR(rval);
   std::vector<unsigned char> bytes(memcmp_size, 0);
   rval = mb.tag_get_data( tag, 0, 0, &bytes[0] );
@@ -954,7 +956,7 @@
     // test again, this time for default value
   std::string name2( tag_name );
   name2 += "_DEF";
-  MBTag tag2 = test_create_tag( mb, name2.c_str(), tag_size, tag_storage, tag_type, value );
+  Tag tag2 = test_create_tag( mb, name2.c_str(), tag_size, tag_storage, tag_type, value );
   bytes.clear();
   bytes.resize(memcmp_size, 0);
   rval = mb.tag_get_data( tag2, 0, 0, &bytes[0] );
@@ -964,7 +966,7 @@
 
 void test_mesh_value()
 {
-  MBCore moab;
+  Core moab;
   
   double dval = -0.5;
   test_mesh_value( moab, "mvd", sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, &dval );
@@ -972,32 +974,32 @@
   int sval = 42;
   test_mesh_value( moab, "mvs", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, &sval );
 
-  MBEntityHandle mval = 0;
-  test_mesh_value( moab, "mvm", sizeof(MBEntityHandle), MB_TAG_MESH, MB_TYPE_HANDLE, &mval );
+  EntityHandle mval = 0;
+  test_mesh_value( moab, "mvm", sizeof(EntityHandle), MB_TAG_MESH, MB_TYPE_HANDLE, &mval );
 
   unsigned char bits = '\002';
   test_mesh_value( moab, "mvb", 2, MB_TAG_BIT, MB_TYPE_BIT, &bits );
 }
 
-static void test_delete_type_tag( MBTagType storage )
+static void test_delete_type_tag( TagType storage )
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
   setup_mesh( mb );
   
     // create tag
   int default_val = 42;
   const char* tagname = "dead_tag";
-  MBTag tag = test_create_tag( mb, tagname, sizeof(int), storage, MB_TYPE_INTEGER, &default_val );
+  Tag tag = test_create_tag( mb, tagname, sizeof(int), storage, MB_TYPE_INTEGER, &default_val );
   
     // get an entity handle to work with
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR( rval );
   CHECK( !verts.empty() );
-  MBEntityHandle handle = verts.front();
+  EntityHandle handle = verts.front();
   
     // set tag value on entity
   int value = -5;
@@ -1018,24 +1020,24 @@
   std::string name;
   rval = mb.tag_get_name( tag, name );
   CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
-  MBTag tag2;
+  Tag tag2;
   rval = mb.tag_get_handle( tagname, tag2 );
   CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
   int size;
   rval = mb.tag_get_size( tag, size );
   CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
     // get get the type from the handle, so this still succeeds
-  //MBTagType storage2;
+  //TagType storage2;
   //rval = mb.tag_get_type( tag, storage2 );
   //CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
   rval = mb.tag_get_default_value( tag, &value );
   CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
   
     // check global list of tags
-  std::vector<MBTag> tags;
+  std::vector<Tag> tags;
   rval = mb.tag_get_tags( tags );
   CHECK_ERR( rval );
   CHECK( std::find( tags.begin(), tags.end(), tag ) == tags.end() );
@@ -1062,12 +1064,12 @@
 
 
 template <typename Container>  
-MBErrorCode set_bit_data( MBInterface& mb, 
-                          MBTag tag,
+ErrorCode set_bit_data( Interface& mb, 
+                          Tag tag,
                           const Container& handles,
                           const std::vector<unsigned char>& data )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   data.resize( handles.size() );
   std::vector<unsigned char>::const_iterator j = data.begin();
   for (typename Container::const_iterator i = handles.begin(); i != handles.end(); ++i, ++j) {
@@ -1077,43 +1079,43 @@
   }
 }
 
-static bool contains_tag( MBTag tag, const std::vector<MBTag>& list )
+static bool contains_tag( Tag tag, const std::vector<Tag>& list )
 {
   return std::find( list.begin(), list.end(), tag ) != list.end();
 }
 
 void test_get_entity_tags()
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
     // get 8 handles to work with
   setup_mesh( mb );
-  MBRange entities;
+  Range entities;
   rval = mb.get_entities_by_handle( 0, entities );
   CHECK_ERR( rval );
   CHECK( entities.size() >= 8 );
-  MBRange::iterator i = entities.begin();
-  MBEntityHandle sparse_ent       = *i; ++i;
-  MBEntityHandle dense_ent        = *i; ++i;
-  MBEntityHandle bit_ent          = *i; ++i;
-  MBEntityHandle sparse_dense_ent = *i; ++i;
-  MBEntityHandle sparse_bit_ent   = *i; ++i;
-  MBEntityHandle dense_bit_ent    = *i; ++i;
-  MBEntityHandle all_tag_ent      = *i; ++i;
-  MBEntityHandle no_tag_ent       = *i; ++i;
+  Range::iterator i = entities.begin();
+  EntityHandle sparse_ent       = *i; ++i;
+  EntityHandle dense_ent        = *i; ++i;
+  EntityHandle bit_ent          = *i; ++i;
+  EntityHandle sparse_dense_ent = *i; ++i;
+  EntityHandle sparse_bit_ent   = *i; ++i;
+  EntityHandle dense_bit_ent    = *i; ++i;
+  EntityHandle all_tag_ent      = *i; ++i;
+  EntityHandle no_tag_ent       = *i; ++i;
   
     // create three tags to work with
-  MBTag sparse, dense, bit;
+  Tag sparse, dense, bit;
   sparse = test_create_tag( mb, "sparse", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, 0 );
   dense  = test_create_tag( mb, "dense_", sizeof(int), MB_TAG_DENSE , MB_TYPE_INTEGER, 0 );
   bit    = test_create_tag( mb, "bit___", sizeof(int), MB_TAG_BIT   , MB_TYPE_BIT    , 0 );
   
     // set tags on handles
-  MBEntityHandle sparse_ents[4] = { sparse_ent, sparse_dense_ent, sparse_bit_ent, all_tag_ent };
-  MBEntityHandle  dense_ents[4] = { dense_ent, sparse_dense_ent, dense_bit_ent, all_tag_ent };
-  MBEntityHandle    bit_ents[4] = { bit_ent, sparse_bit_ent, dense_bit_ent, all_tag_ent };
+  EntityHandle sparse_ents[4] = { sparse_ent, sparse_dense_ent, sparse_bit_ent, all_tag_ent };
+  EntityHandle  dense_ents[4] = { dense_ent, sparse_dense_ent, dense_bit_ent, all_tag_ent };
+  EntityHandle    bit_ents[4] = { bit_ent, sparse_bit_ent, dense_bit_ent, all_tag_ent };
   int values[4] = { -1, -2, -3, -4 };
   rval = mb.tag_set_data(  sparse, sparse_ents, 4, &values );
   rval = mb.tag_set_data(   dense,  dense_ents, 4, &values );
@@ -1124,7 +1126,7 @@
   }
   
     // get tags on each entity
-  std::vector<MBTag> sparse_ent_tags, dense_ent_tags, bit_ent_tags, 
+  std::vector<Tag> sparse_ent_tags, dense_ent_tags, bit_ent_tags, 
                      sparse_dense_ent_tags, sparse_bit_ent_tags, dense_bit_ent_tags,
                      all_tag_ent_tags, no_tag_ent_tags;
   rval = mb.tag_get_tags_on_entity( sparse_ent, sparse_ent_tags );
@@ -1191,11 +1193,11 @@
 }
   
 
-void test_delete_tag_data( MBTagType storage, bool with_default_value )
+void test_delete_tag_data( TagType storage, bool with_default_value )
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
   setup_mesh( mb );
   
@@ -1203,12 +1205,12 @@
     // 1) entities for which the tag data will be deleted using the array-based function
     // 2) entities for which the tag data will be deleted using the range-based function
     // 3) entities for which the tag data will not be deleted
-  MBRange all_entities, del1_range, keep_range;
-  std::vector<MBEntityHandle> del1_list, del2_list, keep_list;
+  Range all_entities, del1_range, keep_range;
+  std::vector<EntityHandle> del1_list, del2_list, keep_list;
   rval = mb.get_entities_by_handle( 0, all_entities );
   CHECK_ERR( rval );
   int c = 0;
-  for (MBRange::iterator i = all_entities.begin(); i != all_entities.end(); ++i, ++c)  {
+  for (Range::iterator i = all_entities.begin(); i != all_entities.end(); ++i, ++c)  {
     switch (c%3) {
       case 0: del1_range.insert( *i ); break;
       case 1: keep_range.insert( *i ); break;
@@ -1221,10 +1223,10 @@
   std::copy( keep_range.begin(), keep_range.end(), keep_list.begin() );
  
     // create tag
-  MBEntityHandle first = all_entities.front();
-  MBEntityHandle* defval = with_default_value ? &first : 0;
+  EntityHandle first = all_entities.front();
+  EntityHandle* defval = with_default_value ? &first : 0;
   const char* tagname = "dead_tag";
-  MBTag tag = test_create_tag( mb, tagname, sizeof(MBEntityHandle), storage, 
+  Tag tag = test_create_tag( mb, tagname, sizeof(EntityHandle), storage, 
                                MB_TYPE_HANDLE, defval );
                                
     // set value for each entity to its handle
@@ -1242,44 +1244,44 @@
   CHECK_ERR(rval);
   
     // test that keep list is unaffected
-  std::vector<MBEntityHandle> tag_data( keep_range.size(), 0 );
+  std::vector<EntityHandle> tag_data( keep_range.size(), 0 );
   rval = mb.tag_get_data( tag, keep_range, &tag_data[0] );
   CHECK_ERR(rval);
   CHECK( tag_data == keep_list );
   
     // try to get data for deleted range
   tag_data.clear();
-  tag_data.resize( del1_range.size(), (MBEntityHandle)-1 );
+  tag_data.resize( del1_range.size(), (EntityHandle)-1 );
   rval = mb.tag_get_data( tag, del1_range, &tag_data[0] );
     // if we have a default value, should get that for deleted entities
   if (with_default_value) {
     CHECK_ERR(rval);
-    std::vector<MBEntityHandle> expected( del1_range.size(), *defval );
+    std::vector<EntityHandle> expected( del1_range.size(), *defval );
     CHECK( expected == tag_data );
   }
   else if (rval != MB_TAG_NOT_FOUND) {
       // dense and bit tags might return either MB_TAG_NOT_FOUND or zero bytes.
       // sparse tags should always return MB_TAG_NOT_FOUND
     CHECK( MB_TAG_SPARSE != storage );
-    std::vector<MBEntityHandle> expected( del1_range.size(), 0 );
+    std::vector<EntityHandle> expected( del1_range.size(), 0 );
     CHECK( expected == tag_data );
   }
   
     // try to get data for deleted list
   tag_data.clear();
-  tag_data.resize( del1_range.size(), (MBEntityHandle)-1 );
+  tag_data.resize( del1_range.size(), (EntityHandle)-1 );
   rval = mb.tag_get_data( tag, del1_range, &tag_data[0] );
     // if we have a default value, should get that for deleted entities
   if (with_default_value) {
     CHECK_ERR(rval);
-    std::vector<MBEntityHandle> expected( del1_range.size(), *defval );
+    std::vector<EntityHandle> expected( del1_range.size(), *defval );
     CHECK( expected == tag_data );
   }
   else if (rval != MB_TAG_NOT_FOUND) {
       // dense and bit tags might return either MB_TAG_NOT_FOUND or zero bytes.
       // sparse tags should always return MB_TAG_NOT_FOUND
     CHECK( MB_TAG_SPARSE != storage );
-    std::vector<MBEntityHandle> expected( del1_range.size(), 0 );
+    std::vector<EntityHandle> expected( del1_range.size(), 0 );
     CHECK( expected == tag_data );
   }
 }
@@ -1298,21 +1300,21 @@
 
 void test_delete_bit_data()
 { 
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
     // get an entity to set data on
   setup_mesh( mb );
-  MBRange entities;
+  Range entities;
   rval = mb.get_entities_by_handle( 0, entities );
   CHECK_ERR( rval );
   CHECK( !entities.empty() );
-  MBEntityHandle handle = entities.front();
+  EntityHandle handle = entities.front();
   
     // create two tags, one with a default value and one without
   unsigned char defval = '\006';  // 110
-  MBTag tag1, tag2;
+  Tag tag1, tag2;
   tag1 = test_create_tag( mb, "tag1", 2, MB_TAG_BIT, MB_TYPE_BIT, 0 );
   tag2 = test_create_tag( mb, "tag2", 3, MB_TAG_BIT, MB_TYPE_BIT, &defval );
   
@@ -1346,8 +1348,8 @@
 }
 
 void test_get_set_variable_length( const char* name,
-                                   MBTagType storage, 
-                                   MBDataType type, 
+                                   TagType storage, 
+                                   DataType type, 
                                    const void** values,
                                    const int* lengths,
                                    int num_values,
@@ -1358,39 +1360,39 @@
   std::vector<int> data_lens;
   
     // create mesh and tag
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   setup_mesh( mb );
-  MBTag tag = test_create_var_len_tag( mb, name,  storage, type, 
+  Tag tag = test_create_var_len_tag( mb, name,  storage, type, 
                            default_value, default_value_length );
   
     // get some handles to work with
-  MBRange entities;
-  MBErrorCode rval = mb.get_entities_by_handle( 0, entities );
+  Range entities;
+  ErrorCode rval = mb.get_entities_by_handle( 0, entities );
   CHECK_ERR(rval);
   CHECK( !entities.empty() );
   
     // split handles into four groups
     // a) a single handle
     // b) some non-consecutive handles in an array
-    // c) some handles in an MBRange
+    // c) some handles in an Range
     // d) remaining handles (remaining in 'entities');
-  MBEntityHandle one_handle;
-  MBRange::iterator i = entities.begin() += entities.size()/2;
+  EntityHandle one_handle;
+  Range::iterator i = entities.begin() += entities.size()/2;
   one_handle = *i;
   entities.erase( i );
   
-  MBRange handle_range;
-  std::vector<MBEntityHandle> handle_list;
-  for (MBRange::const_pair_iterator i =  entities.const_pair_begin(); 
+  Range handle_range;
+  std::vector<EntityHandle> handle_list;
+  for (Range::const_pair_iterator i =  entities.const_pair_begin(); 
                                     i != entities.const_pair_end(); ++i) {
     if (i->first == i->second || i->second - i->first == 1) {
-      MBEntityHandle h1 = i->first, h2 = i->second;
+      EntityHandle h1 = i->first, h2 = i->second;
       ++i;
       handle_range.insert( h1, h2 );
     }
     else {
-      MBEntityHandle mid = (MBEntityHandle)(i->first + (i->second - i->first + 1) / 2);
+      EntityHandle mid = (EntityHandle)(i->first + (i->second - i->first + 1) / 2);
       handle_list.push_back( mid );
       handle_range.insert( mid+1, i->second );
     }
@@ -1427,7 +1429,7 @@
     CHECK( !memcmp( values[i], data[i], lengths[i] ) );
   }
   
-    // try getting/setting for MBRange of handles
+    // try getting/setting for Range of handles
   
   data.resize( num_values );
   data_lens.resize( num_values );
@@ -1554,11 +1556,11 @@
 
 void test_get_set_variable_length_mesh()
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
-  MBTag tag = test_create_var_len_tag( mb, "vmesh", MB_TAG_MESH, MB_TYPE_INTEGER, 0, 0 );
+  Tag tag = test_create_var_len_tag( mb, "vmesh", MB_TAG_MESH, MB_TYPE_INTEGER, 0, 0 );
   int values1[] = { 6 };
   int values5[] = { 1, 2, 3, 4, 5 };
   
@@ -1591,27 +1593,27 @@
 
 void test_get_ents_with_default_value()
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
-  MBRange result;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
+  Range result;
 
     // create a bunch of vertices
   std::vector<double> coords(90,0.0);
-  MBRange verts;
+  Range verts;
   rval = mb.create_vertices( &coords[0], coords.size()/3, verts );
   CHECK_ERR( rval );
   CHECK_EQUAL( coords.size()/3, (size_t)verts.size() );
     // create one edge, which we should never get back from 
     // our queries with type == MBVERTEX
-  MBEntityHandle edge, ends[] = { verts.front(), verts.back() };
+  EntityHandle edge, ends[] = { verts.front(), verts.back() };
   rval = mb.create_element( MBEDGE, ends, 2, edge );
   CHECK_ERR(rval);
   
     // split vertices into four groups
-  MBRange sets[4];
+  Range sets[4];
   size_t s = 0;
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     sets[s].insert(*i);
     s = (s+1)%4;
   }
@@ -1619,7 +1621,7 @@
 
     // create a sparse tag and set some verts to non-default value
   int default_sparse = 5;
-  MBTag tag_sparse = test_create_tag( mb, "int", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, &default_sparse );
+  Tag tag_sparse = test_create_tag( mb, "int", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, &default_sparse );
   std::vector<int> sparse_vals(sets[0].size(), -1);
   rval = mb.tag_set_data( tag_sparse, sets[0], &sparse_vals[0] );
   CHECK_ERR(rval);
@@ -1634,7 +1636,7 @@
 
     // create a dense tag and set some verts to non-default value
   double default_dense = -1.0;
-  MBTag tag_dense = test_create_tag( mb, "double", sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, &default_dense );
+  Tag tag_dense = test_create_tag( mb, "double", sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, &default_dense );
   std::vector<double> dense_vals(sets[1].size(), 3.14159);
   rval = mb.tag_set_data( tag_dense, sets[1], &dense_vals[0] );
   CHECK_ERR(rval);
@@ -1650,7 +1652,7 @@
     // create a variable-length tag and set some verts to non-default value
   // SKIP THIS: NO API FOR QUERYING ENTITIES WITH VARIABLE-LENGTH VALUE
   //int default_vlen[] = { 1, 2, 3 };
-  //MBTag tag_vlen = test_create_var_len_tag( mb, "vlen", MB_TAG_SPARSE, MB_TYPE_INTEGER, default_vlen, sizeof(default_vlen) );
+  //Tag tag_vlen = test_create_var_len_tag( mb, "vlen", MB_TAG_SPARSE, MB_TYPE_INTEGER, default_vlen, sizeof(default_vlen) );
   //int other_vlen[] = { 4, 5, 6, 7 };
   //std::vector<const void*> vlen_ptrs( sets[2].size(), other_vlen );
   //std::vector<int> vlen_sizes( sets[2].size)(), sizeof(other_vlen) );
@@ -1662,9 +1664,9 @@
   result.clear();
   result.insert( sets[1].front() );
   ptrs[0] = &default_sparse;
-  rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag_sparse, ptrs, 1, result, MBInterface::INTERSECT );
+  rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag_sparse, ptrs, 1, result, Interface::INTERSECT );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)1, result.size() );
+  CHECK_EQUAL( (EntityHandle)1, result.size() );
   CHECK_EQUAL( sets[1].front(), result.front() );
   
   
@@ -1672,31 +1674,31 @@
   result.clear();
   result.insert( edge );
   ptrs[0] = &default_sparse;
-  rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag_sparse, ptrs, 1, result, MBInterface::UNION );
+  rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag_sparse, ptrs, 1, result, Interface::UNION );
   CHECK_ERR(rval);
   CHECK_EQUAL( edge, result.back() );
 }
 
 void test_bit_tag_big()
 {
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
   const size_t NUM_VTX = 30000;
 
     // create a lot of vertices
   std::vector<double> coords(3*NUM_VTX,0.0);
-  MBRange verts;
+  Range verts;
   rval = mb.create_vertices( &coords[0], NUM_VTX, verts );
   CHECK_ERR( rval );
   CHECK_EQUAL( NUM_VTX, (size_t)verts.size() );
 
     // create a bit tag
-  MBTag tag = test_create_tag( mb, "bb", 4, MB_TAG_BIT, MB_TYPE_BIT, 0);
+  Tag tag = test_create_tag( mb, "bb", 4, MB_TAG_BIT, MB_TYPE_BIT, 0);
     // for each vertex, store last four bits of handle as tag value
   std::vector<unsigned char> values(NUM_VTX);
   std::vector<unsigned char>::iterator it = values.begin();
-  for (MBRange::iterator j = verts.begin(); j != verts.end(); ++j, ++it)
+  for (Range::iterator j = verts.begin(); j != verts.end(); ++j, ++it)
     *it = (unsigned char)(*j & 0xF);
   rval = mb.tag_set_data( tag, verts, &values[0] );
   CHECK_ERR( rval );
@@ -1708,7 +1710,7 @@
   
     // retrieve individual values
   it = values.begin();
-  for (MBRange::iterator j = verts.begin(); j != verts.end(); ++j, ++it)
+  for (Range::iterator j = verts.begin(); j != verts.end(); ++j, ++it)
   {
     char value;
     rval = mb.tag_get_data( tag, &*j, 1, &value );
@@ -1718,8 +1720,8 @@
   
     // retrieve entities
   unsigned char value = 0xC;
-  MBRange expected, results;
-  for (MBRange::reverse_iterator j = verts.rbegin(); j != verts.rend(); ++j)
+  Range expected, results;
+  for (Range::reverse_iterator j = verts.rbegin(); j != verts.rend(); ++j)
     if ((unsigned char)(*j & 0xF) == value)
       expected.insert(*j);
   const void* vals[] = { &value };
@@ -1728,14 +1730,14 @@
   CHECK_EQUAL( expected, results );
   
     // test singe-bit tag
-  MBTag tag1 = test_create_tag( mb, "bb1", 1, MB_TAG_BIT, MB_TYPE_BIT, 0 );
+  Tag tag1 = test_create_tag( mb, "bb1", 1, MB_TAG_BIT, MB_TYPE_BIT, 0 );
     // set tag to 1 on all vertices
   values.clear();
   values.resize( NUM_VTX, '\001' );
   rval = mb.tag_set_data( tag1, verts, &values[0] );
   CHECK_ERR(rval);
     // retrieve values individually
-  for (MBRange::iterator j = verts.begin(); j != verts.end(); ++j)
+  for (Range::iterator j = verts.begin(); j != verts.end(); ++j)
   {
     char value;
     rval = mb.tag_get_data( tag1, &*j, 1, &value );
@@ -1743,7 +1745,7 @@
     CHECK_EQUAL( 1, (int)value );
   }
     // clear values individually
-  for (MBRange::iterator j = verts.begin(); j != verts.end(); ++j)
+  for (Range::iterator j = verts.begin(); j != verts.end(); ++j)
   {
     char value = '\0';
     rval = mb.tag_set_data( tag1, &*j, 1, &value );
@@ -1756,9 +1758,9 @@
   CHECK_EQUAL( values.size(), first_one );
 }
 
-void setup_mesh( MBInterface& mb )
+void setup_mesh( Interface& mb )
 {
-  MBRange vertex_handles;
+  Range vertex_handles;
   const double vertex_coords[] = { 0, 0, 0,  1, 0, 0,  2, 0, 0,
                                    0, 1, 0,  1, 1, 0,  2, 1, 0,
                                    0, 2, 0,  1, 2, 0,  2, 2, 0,
@@ -1771,13 +1773,13 @@
                                    0, 1, 2,  1, 1, 2,  2, 1, 2,
                                    0, 2, 2,  1, 2, 2,  2, 2, 2 };
   const unsigned num_vtx = sizeof(vertex_coords)/(3*sizeof(double));
-  MBErrorCode rval = mb.create_vertices( vertex_coords, num_vtx, vertex_handles );
+  ErrorCode rval = mb.create_vertices( vertex_coords, num_vtx, vertex_handles );
   CHECK_ERR(rval);
   CHECK_EQUAL( num_vtx, (unsigned)vertex_handles.size() );
   
   CHECK_EQUAL( 27u, num_vtx );
-  MBEntityHandle elements[8];
-  MBEntityHandle conn[8][8] = { {  0,  1,  4,  3,   9, 10, 13, 12 },
+  EntityHandle elements[8];
+  EntityHandle conn[8][8] = { {  0,  1,  4,  3,   9, 10, 13, 12 },
                                 {  1,  2,  5,  4,  10, 11, 14, 13 }, 
                                 {  3,  4,  7,  6,  12, 13, 16, 15 },
                                 {  4,  5,  8,  7,  13, 14, 17, 16 },
@@ -1793,7 +1795,7 @@
     // delete some stuff so there are multiple sequences
   rval = mb.delete_entities( elements + 2, 2 );
   CHECK_ERR(rval);
-  MBRange::iterator i = vertex_handles.begin();
+  Range::iterator i = vertex_handles.begin();
   i += 16;
   rval = mb.delete_entities( &*i, 1 );
   CHECK_ERR(rval);
@@ -1809,15 +1811,15 @@
  */
 void regression_one_entity_by_var_tag()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
   
-  MBEntityHandle vertex;
+  EntityHandle vertex;
   const double coords[] = { 0, 0, 0 };
   rval = moab.create_vertex( coords, vertex );
   CHECK_ERR(rval);
 
-  MBTag tag;
+  Tag tag;
   rval = moab.tag_create_variable_length( "testtag", MB_TAG_DENSE, MB_TYPE_INTEGER, tag );
   CHECK_ERR(rval);
   
@@ -1826,11 +1828,11 @@
   rval = moab.tag_set_data( tag, &vertex, 1, ptrarr, &taglen );
   CHECK_ERR(rval);
   
-  MBRange ents;
+  Range ents;
   rval = moab.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, ents );
   CHECK_ERR(rval);
   
-  CHECK_EQUAL( (MBEntityHandle)1, ents.size() );
+  CHECK_EQUAL( (EntityHandle)1, ents.size() );
   CHECK_EQUAL( vertex, ents.front() );
 }
 
@@ -1839,14 +1841,14 @@
  */
 void regression_tag_on_nonexistent_entity()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
   const int tagval = 0xdeadbeef;
   const void* valarr[1] = { &tagval };
   const int numval = sizeof(int);
   
     // create all three types of tags
-  MBTag dense, sparse, bit;
+  Tag dense, sparse, bit;
   rval = moab.tag_create( "test_dense", numval, MB_TAG_DENSE, MB_TYPE_INTEGER, dense, 0, false );
   CHECK_ERR(rval);
   rval = moab.tag_create( "test_sparse", numval, MB_TAG_SPARSE, MB_TYPE_INTEGER, sparse, 0, false );
@@ -1856,8 +1858,8 @@
   
     // for each tag type, check all four mechanisms for setting tag data
     // (fixed and variable length given array or range).
-  MBEntityHandle handle = (MBEntityHandle)1;
-  MBRange handles;
+  EntityHandle handle = (EntityHandle)1;
+  Range handles;
   handles.insert( handle );
   
   rval = moab.tag_set_data( dense,  &handle, 1, &tagval );
@@ -1885,11 +1887,11 @@
   CHECK_EQUAL( MB_ENTITY_NOT_FOUND, rval );
   
     // now add create an entity and try an adjacent handle
-  MBEntityHandle set;
+  EntityHandle set;
   rval = moab.create_meshset( 0, set );
   CHECK_ERR(rval);
   
-  handle = (MBEntityHandle)(set+1);
+  handle = (EntityHandle)(set+1);
   handles.clear();
   handles.insert( handle );
   

Modified: MOAB/trunk/test/TestTypeSequenceManager.cpp
===================================================================
--- MOAB/trunk/test/TestTypeSequenceManager.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/TestTypeSequenceManager.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,10 @@
 #include "TypeSequenceManager.hpp"
 #include "EntitySequence.hpp"
 #include "SequenceData.hpp"
-#include "MBEntityHandle.h"
 #include "TestUtil.hpp"
 
+using namespace moab;
+
 void test_basic();
 void test_lower_bound();
 void test_upper_bound();
@@ -36,7 +37,7 @@
 /* Compare expected sequence contents to actual contents.
  * Also does some consistency checks.
  */
-bool seqman_equal( const MBEntityHandle pair_array[][2],
+bool seqman_equal( const EntityHandle pair_array[][2],
                      unsigned num_pairs,
                      const TypeSequenceManager& seqman );
 
@@ -44,9 +45,9 @@
  * Insert a sequence into a sequence manager.  Delete passed
  * sequence (and optionally SequenceData) if insertion fails.
  */
-MBErrorCode insert_seq( TypeSequenceManager& seqman, 
-                        MBEntityHandle start_handle,
-                        MBEntityID count,
+ErrorCode insert_seq( TypeSequenceManager& seqman, 
+                        EntityHandle start_handle,
+                        EntityID count,
                         SequenceData* data,
                         bool del_data = false );
 
@@ -87,25 +88,25 @@
   private:
     int valsPerEnt;
   public: 
-    DumSeq( MBEntityHandle start, MBEntityID count, SequenceData* data, int vals_per_ent = 0 )
+    DumSeq( EntityHandle start, EntityID count, SequenceData* data, int vals_per_ent = 0 )
       : EntitySequence( start, count, data), valsPerEnt(vals_per_ent) {}
     DumSeq( SequenceData* data, int vals_per_ent = 0 )
       : EntitySequence( data->start_handle(), data->size(), data), valsPerEnt(vals_per_ent) {}
     
-    DumSeq( DumSeq& split_from, MBEntityHandle here )
+    DumSeq( DumSeq& split_from, EntityHandle here )
       : EntitySequence( split_from, here ), valsPerEnt(split_from.valsPerEnt) {}
     
     virtual ~DumSeq() {}
     
-    EntitySequence* split( MBEntityHandle here )
+    EntitySequence* split( EntityHandle here )
       { return new DumSeq(*this, here); }
     
-    SequenceData* create_data_subset( MBEntityHandle a, MBEntityHandle b ) const
+    SequenceData* create_data_subset( EntityHandle a, EntityHandle b ) const
       { return data()->subset( a, b, 0 ); }
     
     void get_const_memory_use( unsigned long& a, unsigned long& b) const
       { a = b = 0; }
-    unsigned long get_per_entity_memory_use( MBEntityHandle, MBEntityHandle) const
+    unsigned long get_per_entity_memory_use( EntityHandle, EntityHandle) const
       { return 0; }
     
     int values_per_entity() const
@@ -119,14 +120,14 @@
 }
 
 
-MBErrorCode insert_seq( TypeSequenceManager& seqman, 
-                        MBEntityHandle start_handle,
-                        MBEntityID count,
+ErrorCode insert_seq( TypeSequenceManager& seqman, 
+                        EntityHandle start_handle,
+                        EntityID count,
                         SequenceData* data,
                         bool del_data )
 {
   EntitySequence* seq = new DumSeq( start_handle, count, data );
-  MBErrorCode rval = seqman.insert_sequence( seq );
+  ErrorCode rval = seqman.insert_sequence( seq );
   if (MB_SUCCESS != rval) {
     delete seq;
     if (del_data)
@@ -145,7 +146,7 @@
                           EntitySequence*& seq3 )
 {
   CHECK( seqman.empty() );
-  CHECK_EQUAL( (MBEntityID)0, seqman.get_number_entities() );
+  CHECK_EQUAL( (EntityID)0, seqman.get_number_entities() );
   
   SequenceData* data = new SequenceData( 0, 1, 22000 );
   CHECK_ERR( insert_seq( seqman,    3,  5, data ) );
@@ -153,31 +154,31 @@
   CHECK_ERR( insert_seq( seqman, 1001,  1, data ) );
 
   CHECK( !seqman.empty() );
-  CHECK_EQUAL( (MBEntityID)18, seqman.get_number_entities() );
+  CHECK_EQUAL( (EntityID)18, seqman.get_number_entities() );
   
   TypeSequenceManager::iterator iter = seqman.begin();
   CHECK( iter != seqman.end() );
   seq1 = *iter;
-  CHECK_EQUAL( (MBEntityHandle)3, seq1->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)7, seq1->end_handle() );
+  CHECK_EQUAL( (EntityHandle)3, seq1->start_handle() );
+  CHECK_EQUAL( (EntityHandle)7, seq1->end_handle() );
   CHECK_EQUAL( data, seq1->data() );
-  CHECK_EQUAL( (MBEntityID)5, seq1->size() );
+  CHECK_EQUAL( (EntityID)5, seq1->size() );
   
   ++iter;
   CHECK( iter != seqman.end() );
   seq2 = *iter;
-  CHECK_EQUAL( (MBEntityHandle)100, seq2->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)111, seq2->end_handle() );
+  CHECK_EQUAL( (EntityHandle)100, seq2->start_handle() );
+  CHECK_EQUAL( (EntityHandle)111, seq2->end_handle() );
   CHECK_EQUAL( data, seq2->data() );
-  CHECK_EQUAL( (MBEntityID)12, seq2->size() );
+  CHECK_EQUAL( (EntityID)12, seq2->size() );
   
   ++iter;
   seq3 = *iter;
   CHECK( iter != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)1001, seq3->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)1001, seq3->end_handle() );
+  CHECK_EQUAL( (EntityHandle)1001, seq3->start_handle() );
+  CHECK_EQUAL( (EntityHandle)1001, seq3->end_handle() );
   CHECK_EQUAL( data, seq3->data() );
-  CHECK_EQUAL( (MBEntityID)1, seq3->size() );
+  CHECK_EQUAL( (EntityID)1, seq3->size() );
   
   ++iter;
   CHECK( iter == seqman.end() );
@@ -307,7 +308,7 @@
   CHECK_EQUAL( NULL, seq );
 }
 
-bool seqman_equal( const MBEntityHandle pair_array[][2],
+bool seqman_equal( const EntityHandle pair_array[][2],
                      unsigned num_pairs,
                      const TypeSequenceManager& seqman )
 {
@@ -386,13 +387,13 @@
   make_basic_sequence( seqman );
 
   CHECK( !seqman.empty() );
-  CHECK_EQUAL( (MBEntityID)18, seqman.get_number_entities() );
+  CHECK_EQUAL( (EntityID)18, seqman.get_number_entities() );
 
-  MBRange entities;
+  Range entities;
   seqman.get_entities( entities );
-  CHECK_EQUAL( (MBEntityHandle)18, entities.size() );
+  CHECK_EQUAL( (EntityHandle)18, entities.size() );
 
-  MBEntityHandle pairs[][2] = { {3, 7}, {100, 111}, {1001, 1001} };
+  EntityHandle pairs[][2] = { {3, 7}, {100, 111}, {1001, 1001} };
   CHECK( seqman_equal( pairs, 3, seqman ) );
 }
 
@@ -405,32 +406,32 @@
 
     // append a sequence
   CHECK_ERR( insert_seq( seqman, 1003, 1, data ) );
-  MBEntityHandle exp1[][2] = { { 3, 7}, {100, 111}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp1[][2] = { { 3, 7}, {100, 111}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp1, 4, seqman ) );
   
     // prepend a sequence
   CHECK_ERR( insert_seq( seqman, 1, 1, data ) );
-  MBEntityHandle exp2[][2] = { {1, 1}, { 3, 7}, {100, 111}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp2[][2] = { {1, 1}, { 3, 7}, {100, 111}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp2, 5, seqman ) );
   
     // insert sequence in middle
   CHECK_ERR( insert_seq( seqman, 150, 11, data ) );
-  MBEntityHandle exp3[][2] = { {1, 1}, { 3, 7}, {100, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp3[][2] = { {1, 1}, { 3, 7}, {100, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp3, 6, seqman ) );
   
     // merge sequence with predecessor
   CHECK_ERR( insert_seq( seqman, 8, 13, data ) );
-  MBEntityHandle exp4[][2] = { {1, 1}, { 3, 20}, {100, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp4[][2] = { {1, 1}, { 3, 20}, {100, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp4, 6, seqman ) );
   
     // merge sequence with following one
   CHECK_ERR( insert_seq( seqman, 87, 13, data ) );
-  MBEntityHandle exp5[][2] = { {1, 1}, { 3, 20}, {87, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp5[][2] = { {1, 1}, { 3, 20}, {87, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp5, 6, seqman ) );
   
     // merge sequence with two adjacent ones
   CHECK_ERR( insert_seq( seqman, 2, 1, data ) );
-  MBEntityHandle exp6[][2] = { {1, 20}, {87, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
+  EntityHandle exp6[][2] = { {1, 20}, {87, 111}, {150,160}, {1001, 1001}, {1003, 1003} };
   CHECK( seqman_equal( exp6, 5, seqman ) );
   
     // try to insert a sequence that overlaps on the end
@@ -455,7 +456,7 @@
     // is exactly the same size.
   SequenceData *data1 = new SequenceData( 0, 3, 7 );
   DumSeq* seq = new DumSeq( data1 );
-  MBErrorCode rval = seqman.insert_sequence( seq );
+  ErrorCode rval = seqman.insert_sequence( seq );
   if (MB_SUCCESS != rval) {
     delete seq;
     delete data1;
@@ -510,27 +511,27 @@
   delete data;
   
     // Make sure we're starting out with what we exoect
-  MBEntityHandle exp1[][2] = { { 3, 7}, {200, 299}, {400, 499} };
+  EntityHandle exp1[][2] = { { 3, 7}, {200, 299}, {400, 499} };
   CHECK( seqman_equal( exp1, 3, seqman ) );
   
     // Test fits within existing, and has same data
   CHECK_ERR( insert_seq( seqman, 600, 100, data2 ) );
-  MBEntityHandle exp2[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699} };
+  EntityHandle exp2[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699} };
   CHECK( seqman_equal( exp2, 4, seqman ) );
   
     // Test is entirely outside existing data
   CHECK_ERR( insert_seq( seqman, 2000, 2, new SequenceData( 0, 2000, 2001 ), true ) );
-  MBEntityHandle exp3[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699}, {2000, 2001} };
+  EntityHandle exp3[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699}, {2000, 2001} };
   CHECK( seqman_equal( exp3, 5, seqman ) );
   
     // Test abutts end of exising data
   CHECK_ERR( insert_seq( seqman, 1000, 6, new SequenceData( 0, 1000, 1005 ), true ) );
-  MBEntityHandle exp4[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699}, {1000,1005}, {2000, 2001} };
+  EntityHandle exp4[][2] = { { 3, 7}, {200, 299}, {400, 499}, {600, 699}, {1000,1005}, {2000, 2001} };
   CHECK( seqman_equal( exp4, 6, seqman ) );
  
     // Test abutts beginning of exising data
   CHECK_ERR( insert_seq( seqman, 50, 50, new SequenceData( 0, 50, 99 ), true ) );
-  MBEntityHandle exp5[][2] = { { 3, 7}, {50, 99}, {200, 299}, {400, 499}, {600, 699}, {1000,1005}, {2000, 2001} };
+  EntityHandle exp5[][2] = { { 3, 7}, {50, 99}, {200, 299}, {400, 499}, {600, 699}, {1000,1005}, {2000, 2001} };
   CHECK( seqman_equal( exp5, 7, seqman ) );
 }
 
@@ -546,7 +547,7 @@
   bool last;
   DumSeq junk( 3, 5, NULL );
   CHECK_EQUAL( MB_ENTITY_NOT_FOUND, seqman.remove_sequence( &junk, last ) );
-  MBEntityHandle exp1[][2] = { { 3, 7}, {100, 111}, {1001, 1001} };
+  EntityHandle exp1[][2] = { { 3, 7}, {100, 111}, {1001, 1001} };
   CHECK( seqman_equal( exp1, 3, seqman ) );
   
     // remove the middle sequence
@@ -569,7 +570,7 @@
 
 void test_replace_subsequence()
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   TypeSequenceManager seqman;
 
     // create an intial set
@@ -620,7 +621,7 @@
   delete data;
   
     // check that we're starting with what we expect
-  MBEntityHandle exp1[][2] = { {101, 200}, {301, 600}, {701, 800} };
+  EntityHandle exp1[][2] = { {101, 200}, {301, 600}, {701, 800} };
   CHECK( seqman_equal( exp1, 3, seqman ) );
   
     // split at start of sequence
@@ -632,7 +633,7 @@
     delete data;
   }
   CHECK_ERR( rval );
-  MBEntityHandle exp2[][2] = { {101, 105}, {106, 200}, {301, 600}, {701, 800} };
+  EntityHandle exp2[][2] = { {101, 105}, {106, 200}, {301, 600}, {701, 800} };
   CHECK( seqman_equal( exp2, 4, seqman ) );
   
     // split at end of sequence
@@ -644,7 +645,7 @@
     delete data;
   }
   CHECK_ERR( rval );
-  MBEntityHandle exp3[][2] = { {101, 105}, {106, 200}, {301, 600}, {701, 749}, {750,800} };
+  EntityHandle exp3[][2] = { {101, 105}, {106, 200}, {301, 600}, {701, 749}, {750,800} };
   CHECK( seqman_equal( exp3, 5, seqman ) );
   
     // split at middle of sequence
@@ -656,7 +657,7 @@
     delete data;
   }
   CHECK_ERR( rval );
-  MBEntityHandle exp4[][2] = { {101, 105}, {106, 200}, {301, 399}, {400,499}, {500,600}, {701, 749}, {750,800} };
+  EntityHandle exp4[][2] = { {101, 105}, {106, 200}, {301, 399}, {400,499}, {500,600}, {701, 749}, {750,800} };
   CHECK( seqman_equal( exp4, 7, seqman ) );
 }
 
@@ -666,7 +667,7 @@
   make_basic_sequence( seqman );
 
     // verify initial state
-  MBEntityHandle exp1[][2] = { {3, 7}, {100, 111}, {1001, 1001} };
+  EntityHandle exp1[][2] = { {3, 7}, {100, 111}, {1001, 1001} };
   CHECK( seqman_equal( exp1, 3, seqman ) );
 
     // try erasing invalid handles at start of existing sequence
@@ -678,32 +679,32 @@
   
     // erase from front of sequence
   CHECK_ERR( seqman.erase( 3, 6 ) );
-  MBEntityHandle exp2[][2] = { {7, 7}, {100, 111}, {1001, 1001} };
+  EntityHandle exp2[][2] = { {7, 7}, {100, 111}, {1001, 1001} };
   CHECK( seqman_equal( exp2, 3, seqman ) );
   
     // erase from end of sequence
   CHECK_ERR( seqman.erase( 110, 111 ) );
-  MBEntityHandle exp3[][2] = { {7, 7}, {100, 109}, {1001, 1001} };
+  EntityHandle exp3[][2] = { {7, 7}, {100, 109}, {1001, 1001} };
   CHECK( seqman_equal( exp3, 3, seqman ) );
   
     // erase from middle of sequence
   CHECK_ERR( seqman.erase( 105, 107 ) );
-  MBEntityHandle exp4[][2] = { {7, 7}, {100, 104}, {108,109}, {1001, 1001} };
+  EntityHandle exp4[][2] = { {7, 7}, {100, 104}, {108,109}, {1001, 1001} };
   CHECK( seqman_equal( exp4, 4, seqman ) );
   
     // erase sequence
   CHECK_ERR( seqman.erase( 7, 7 ) );
-  MBEntityHandle exp5[][2] = { {100, 104}, {108,109}, {1001, 1001} };
+  EntityHandle exp5[][2] = { {100, 104}, {108,109}, {1001, 1001} };
   CHECK( seqman_equal( exp5, 3, seqman ) );
   
     // erase sequence
   CHECK_ERR( seqman.erase( 108, 109 ) );
-  MBEntityHandle exp6[][2] = { {100, 104}, {1001, 1001} };
+  EntityHandle exp6[][2] = { {100, 104}, {1001, 1001} };
   CHECK( seqman_equal( exp6, 2, seqman ) );
   
     // erase sequence
   CHECK_ERR( seqman.erase( 100, 104 ) );
-  MBEntityHandle exp7[][2] = { {1001, 1001} };
+  EntityHandle exp7[][2] = { {1001, 1001} };
   CHECK( seqman_equal( exp7, 1, seqman ) );
   
     // erase sequence
@@ -722,8 +723,8 @@
   seq = seqman.find_free_handle( 0, MB_END_ID, append );
   CHECK( seq != seqman.end() );
     // expect the first available handle (2).
-  CHECK_EQUAL( (MBEntityHandle)3, (*seq)->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)7, (*seq)->  end_handle() );
+  CHECK_EQUAL( (EntityHandle)3, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)7, (*seq)->  end_handle() );
   CHECK( !append );
 
     // Expect end() if no adjacent sequence
@@ -734,8 +735,8 @@
   seq = seqman.find_free_handle( 8, 99, append );
   CHECK( seq != seqman.end() );
     // expect the first available handle (8).
-  CHECK_EQUAL( (MBEntityHandle)3, (*seq)->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)7, (*seq)->  end_handle() );
+  CHECK_EQUAL( (EntityHandle)3, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)7, (*seq)->  end_handle() );
   CHECK( append );
   
     // Try an unambigious case (above tests have multiple
@@ -743,8 +744,8 @@
     // handle).
   seq = seqman.find_free_handle( 8, 98, append );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)3, (*seq)->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)7, (*seq)->  end_handle() );
+  CHECK_EQUAL( (EntityHandle)3, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)7, (*seq)->  end_handle() );
   CHECK( append );
   
     // Try an unambigious case (above tests have multiple
@@ -752,16 +753,16 @@
     // handle).
   seq = seqman.find_free_handle( 9, 99, append );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)100, (*seq)->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)111, (*seq)->  end_handle() );
+  CHECK_EQUAL( (EntityHandle)100, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)111, (*seq)->  end_handle() );
   CHECK( !append );
   
     // Try a case where the expected result handle
     // is in the middle of the input range.
   seq = seqman.find_free_handle( 900, 1100, append );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)1001, (*seq)->start_handle() );
-  CHECK_EQUAL( (MBEntityHandle)1001, (*seq)->  end_handle() );
+  CHECK_EQUAL( (EntityHandle)1001, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)1001, (*seq)->  end_handle() );
     // Expect first available handle
   CHECK( !append );
 }
@@ -769,19 +770,19 @@
 
 void test_find_free_sequence()
 {
-  MBEntityHandle start;
+  EntityHandle start;
   SequenceData* data = 0;
-  MBEntityID data_size = 0;
+  EntityID data_size = 0;
   TypeSequenceManager seqman;
   make_basic_sequence( seqman ); // { [3,7], [100,111], [1001] }
   SequenceData* expdata = (*seqman.begin())->data();
   
   start = seqman.find_free_sequence( 2, 1, 3, data, data_size );
   CHECK_EQUAL( expdata, data );
-  CHECK_EQUAL( (MBEntityHandle)1, start );
+  CHECK_EQUAL( (EntityHandle)1, start );
   
   start = seqman.find_free_sequence( 3, 1, 7, data, data_size );
-  CHECK_EQUAL( (MBEntityHandle)0, start );
+  CHECK_EQUAL( (EntityHandle)0, start );
   CHECK_EQUAL( NULL, data );
   
   start = seqman.find_free_sequence( 30, 1, 120, data, data_size );
@@ -790,18 +791,18 @@
   
   start = seqman.find_free_sequence( 10, 92, 999, data, data_size );
   CHECK_EQUAL( expdata, data );
-  CHECK_EQUAL( (MBEntityHandle)112, start );
+  CHECK_EQUAL( (EntityHandle)112, start );
   
   start = seqman.find_free_sequence( 100, 1, 600, data, data_size );
   CHECK_EQUAL( expdata, data );
-  CHECK_EQUAL( (MBEntityHandle)112, start );
+  CHECK_EQUAL( (EntityHandle)112, start );
   
   start = seqman.find_free_sequence( 1000, 1, MB_END_ID, data, data_size );
   CHECK_EQUAL( expdata, data );
-  CHECK_EQUAL( (MBEntityHandle)1002, start );
+  CHECK_EQUAL( (EntityHandle)1002, start );
   
   start = seqman.find_free_sequence( 980, 1, 1800, data, data_size );
-  CHECK_EQUAL( (MBEntityHandle)0, start );
+  CHECK_EQUAL( (EntityHandle)0, start );
   CHECK_EQUAL( NULL, data );
 }
 
@@ -847,7 +848,7 @@
   // Begin tests
   TypeSequenceManager::iterator seq;
   SequenceData* data;
-  MBEntityHandle first, last;
+  EntityHandle first, last;
  
   // Test handle in use
 
@@ -866,52 +867,52 @@
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 600, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)601, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)601, (*seq)->start_handle() );
   CHECK_EQUAL( data1, data );
-  CHECK_EQUAL( (MBEntityHandle)600, first );
-  CHECK_EQUAL( (MBEntityHandle)600, last );
+  CHECK_EQUAL( (EntityHandle)600, first );
+  CHECK_EQUAL( (EntityHandle)600, last );
   
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2499, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)2500, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)2500, (*seq)->start_handle() );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)2499, first );
-  CHECK_EQUAL( (MBEntityHandle)2499, last );
+  CHECK_EQUAL( (EntityHandle)2499, first );
+  CHECK_EQUAL( (EntityHandle)2499, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2799, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)2800, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)2800, (*seq)->start_handle() );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)2799, first );
-  CHECK_EQUAL( (MBEntityHandle)2799, last );
+  CHECK_EQUAL( (EntityHandle)2799, first );
+  CHECK_EQUAL( (EntityHandle)2799, last );
  
   // Test append to sequence
   
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 501, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)1, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)1, (*seq)->start_handle() );
   CHECK_EQUAL( data1, data );
-  CHECK_EQUAL( (MBEntityHandle)501, first );
-  CHECK_EQUAL( (MBEntityHandle)501, last );
+  CHECK_EQUAL( (EntityHandle)501, first );
+  CHECK_EQUAL( (EntityHandle)501, last );
   
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2600, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)2500, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)2500, (*seq)->start_handle() );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)2600, first );
-  CHECK_EQUAL( (MBEntityHandle)2600, last );
+  CHECK_EQUAL( (EntityHandle)2600, first );
+  CHECK_EQUAL( (EntityHandle)2600, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 3000, seq, data, first, last ) );
   CHECK( seq != seqman.end() );
-  CHECK_EQUAL( (MBEntityHandle)2800, (*seq)->start_handle() );
+  CHECK_EQUAL( (EntityHandle)2800, (*seq)->start_handle() );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)3000, first );
-  CHECK_EQUAL( (MBEntityHandle)3000, last );
+  CHECK_EQUAL( (EntityHandle)3000, first );
+  CHECK_EQUAL( (EntityHandle)3000, last );
   
     // Test new sequence in existing SequenceData
 
@@ -919,29 +920,29 @@
   CHECK( seqman.is_free_handle( 502, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( data1, data );
-  CHECK_EQUAL( (MBEntityHandle)501, first );
-  CHECK_EQUAL( (MBEntityHandle)600, last );
+  CHECK_EQUAL( (EntityHandle)501, first );
+  CHECK_EQUAL( (EntityHandle)600, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 599, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( data1, data );
-  CHECK_EQUAL( (MBEntityHandle)501, first );
-  CHECK_EQUAL( (MBEntityHandle)600, last );
+  CHECK_EQUAL( (EntityHandle)501, first );
+  CHECK_EQUAL( (EntityHandle)600, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2001, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)2001, first );
-  CHECK_EQUAL( (MBEntityHandle)2499, last );
+  CHECK_EQUAL( (EntityHandle)2001, first );
+  CHECK_EQUAL( (EntityHandle)2499, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2498, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( data2, data );
-  CHECK_EQUAL( (MBEntityHandle)2001, first );
-  CHECK_EQUAL( (MBEntityHandle)2499, last );
+  CHECK_EQUAL( (EntityHandle)2001, first );
+  CHECK_EQUAL( (EntityHandle)2499, last );
 
     // Test new SequenceData 
 
@@ -949,36 +950,36 @@
   CHECK( seqman.is_free_handle( 1001, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( (SequenceData*)0, data );
-  CHECK_EQUAL( (MBEntityHandle)1001, first );
-  CHECK_EQUAL( (MBEntityHandle)2000, last );
+  CHECK_EQUAL( (EntityHandle)1001, first );
+  CHECK_EQUAL( (EntityHandle)2000, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 1500, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( (SequenceData*)0, data );
-  CHECK_EQUAL( (MBEntityHandle)1001, first );
-  CHECK_EQUAL( (MBEntityHandle)2000, last );
+  CHECK_EQUAL( (EntityHandle)1001, first );
+  CHECK_EQUAL( (EntityHandle)2000, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 2000, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( (SequenceData*)0, data );
-  CHECK_EQUAL( (MBEntityHandle)1001, first );
-  CHECK_EQUAL( (MBEntityHandle)2000, last );
+  CHECK_EQUAL( (EntityHandle)1001, first );
+  CHECK_EQUAL( (EntityHandle)2000, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 3001, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( (SequenceData*)0, data );
-  CHECK_EQUAL( (MBEntityHandle)3001, first );
-  CHECK_EQUAL( (MBEntityHandle)MB_END_ID, last );
+  CHECK_EQUAL( (EntityHandle)3001, first );
+  CHECK_EQUAL( (EntityHandle)MB_END_ID, last );
 
   seq = seqman.end(); data = 0; first = last = 0;
   CHECK( seqman.is_free_handle( 10000, seq, data, first, last ) );
   CHECK( seqman.end() == seq );
   CHECK_EQUAL( (SequenceData*)0, data );
-  CHECK_EQUAL( (MBEntityHandle)3001, first );
-  CHECK_EQUAL( (MBEntityHandle)MB_END_ID, last );
+  CHECK_EQUAL( (EntityHandle)3001, first );
+  CHECK_EQUAL( (EntityHandle)MB_END_ID, last );
 }
 
 // Regression test for bug fixed in SVN revision 1952.  
@@ -1003,14 +1004,14 @@
 //  sequence.
 void regression_svn1952()
 {
-  const MBEntityHandle last_handle = 50000;
+  const EntityHandle last_handle = 50000;
   TypeSequenceManager seqman;
   SequenceData* data = new SequenceData( 0, 41673, last_handle );
   CHECK_ERR( insert_seq( seqman, 41686, 1000, data, true  ) );
   
   SequenceData* result_data;
-  MBEntityID result_size;
-  MBEntityHandle result_handle;
+  EntityID result_size;
+  EntityHandle result_handle;
   result_handle = seqman.find_free_sequence( 1686, 4000, 2*last_handle, result_data, result_size );
   CHECK( result_handle > last_handle || result_handle + result_size <= 41673 );
   CHECK( result_handle + result_size <= 2*last_handle );
@@ -1029,8 +1030,8 @@
 void regression_svn1958()
 {
   const int data_size = 100;
-  const MBEntityHandle data_start = 100;
-  const MBEntityHandle data_end = data_start + data_size - 1;
+  const EntityHandle data_start = 100;
+  const EntityHandle data_end = data_start + data_size - 1;
   const int seq_offset = 2;
 
   TypeSequenceManager seqman;
@@ -1038,8 +1039,8 @@
   CHECK_ERR( insert_seq( seqman, data_start+seq_offset, data_size-seq_offset, data, true  ) );
   
   SequenceData* result_data;
-  MBEntityID result_size;
-  MBEntityHandle result_handle;
+  EntityID result_size;
+  EntityHandle result_handle;
   result_handle = seqman.find_free_sequence( data_start-1, 1, 100000, result_data, result_size );
   CHECK( result_handle > data_end || result_handle + result_size <= data_start );
 }
@@ -1055,8 +1056,8 @@
 void regression_svn1960()
 {
   const int data_size = 6000;
-  const MBEntityHandle data_start = 4000;
-  const MBEntityHandle data_end = data_start + data_size - 1;
+  const EntityHandle data_start = 4000;
+  const EntityHandle data_end = data_start + data_size - 1;
   const int seq_offset = 1000;
 
   TypeSequenceManager seqman;
@@ -1064,8 +1065,8 @@
   CHECK_ERR( insert_seq( seqman, data_start+seq_offset, data_size-seq_offset, data, true  ) );
   
   SequenceData* result_data;
-  MBEntityID result_size;
-  MBEntityHandle result_handle;
+  EntityID result_size;
+  EntityHandle result_handle;
   result_handle = seqman.find_free_sequence( data_start-2, 1, 100000, result_data, result_size );
   CHECK( result_handle + result_size <= data_start );
 }

Modified: MOAB/trunk/test/TestUtil.hpp
===================================================================
--- MOAB/trunk/test/TestUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/TestUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -215,13 +215,13 @@
 
 
 /* Make sure IS_BUILDING_MB is defined so we can include MBInternals.hpp */
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 #ifndef IS_BUILDING_MB
 #  define IS_BUILDING_MB
-#  include "MBInternals.hpp"
+#  include "Internals.hpp"
 #  undef IS_BUILDING_MB
 #else
-#  include "MBInternals.hpp"
+#  include "Internals.hpp"
 #endif
 
 typedef void (*test_func)(void);
@@ -356,25 +356,25 @@
 void check_equal( double A, double B, float eps, const char* sA, const char* sB, int line, const char* file )
   {  EQUAL_TEST_IMPL( fabs(A - B) <= eps, f ) }
 
-const char* mb_error_str( MBErrorCode err )
+const char* mb_error_str( moab::ErrorCode err )
 {
   switch (err) {
-    case MB_SUCCESS                 : return "Success";
-    case MB_INDEX_OUT_OF_RANGE      : return "Index Out of Range";
-    case MB_TYPE_OUT_OF_RANGE       : return "Type Out of Range";
-    case MB_MEMORY_ALLOCATION_FAILED: return "Memory Alloc. Failed";
-    case MB_ENTITY_NOT_FOUND        : return "Entity Not Found";
-    case MB_MULTIPLE_ENTITIES_FOUND : return "Multiple Entities Found";
-    case MB_TAG_NOT_FOUND           : return "Tag Not Found";
-    case MB_FILE_DOES_NOT_EXIST     : return "File Not Found";
-    case MB_FILE_WRITE_ERROR        : return "File Write Error";
-    case MB_NOT_IMPLEMENTED         : return "Not Implemented";
-    case MB_ALREADY_ALLOCATED       : return "Already Allocated";
-    case MB_VARIABLE_DATA_LENGTH    : return "Variable Data Length";
-    case MB_INVALID_SIZE            : return "Invalid Size";
-    case MB_UNSUPPORTED_OPERATION   : return "Unsupported Operation";
-    case MB_UNHANDLED_OPTION        : return "Unhandled Option";
-    case MB_FAILURE                 : return "Failure";
+    case moab::MB_SUCCESS                 : return "Success";
+    case moab::MB_INDEX_OUT_OF_RANGE      : return "Index Out of Range";
+    case moab::MB_TYPE_OUT_OF_RANGE       : return "Type Out of Range";
+    case moab::MB_MEMORY_ALLOCATION_FAILED: return "Memory Alloc. Failed";
+    case moab::MB_ENTITY_NOT_FOUND        : return "Entity Not Found";
+    case moab::MB_MULTIPLE_ENTITIES_FOUND : return "Multiple Entities Found";
+    case moab::MB_TAG_NOT_FOUND           : return "Tag Not Found";
+    case moab::MB_FILE_DOES_NOT_EXIST     : return "File Not Found";
+    case moab::MB_FILE_WRITE_ERROR        : return "File Write Error";
+    case moab::MB_NOT_IMPLEMENTED         : return "Not Implemented";
+    case moab::MB_ALREADY_ALLOCATED       : return "Already Allocated";
+    case moab::MB_VARIABLE_DATA_LENGTH    : return "Variable Data Length";
+    case moab::MB_INVALID_SIZE            : return "Invalid Size";
+    case moab::MB_UNSUPPORTED_OPERATION   : return "Unsupported Operation";
+    case moab::MB_UNHANDLED_OPTION        : return "Unhandled Option";
+    case moab::MB_FAILURE                 : return "Failure";
     default                         : return "(unknown)";
   }
 }
@@ -382,7 +382,7 @@
 
 // Special case for MBErrorCode, use mb_error_str() to print the 
 // string name of the error code.
-void check_equal( MBErrorCode A, MBErrorCode B, const char* sA, const char* sB, int line, const char* file )
+void check_equal( moab::ErrorCode A, moab::ErrorCode B, const char* sA, const char* sB, int line, const char* file )
 {
   if (A == B)
     return;
@@ -395,30 +395,30 @@
   flag_error(); 
 }
 
-const char* mb_type_str( MBEntityType type )
+const char* mb_type_str( moab::EntityType type )
 {
   switch(type) {
-    case MBVERTEX    : return "Vertex";
-    case MBEDGE      : return "Edge";
-    case MBTRI       : return "Triangle";
-    case MBQUAD      : return "Quadrilateral";
-    case MBPOLYGON   : return "Polygon";
-    case MBTET       : return "Tetrahedron";
-    case MBPYRAMID   : return "Pyramid";
-    case MBPRISM     : return "Prism (wedge)";
-    case MBKNIFE     : return "Knife";
-    case MBHEX       : return "Hexahedron";
-    case MBPOLYHEDRON: return "Polyhedron";
-    case MBENTITYSET : return "Entity (Mesh) Set";
-    case MBMAXTYPE   : return "(max type)";
+    case moab::MBVERTEX    : return "Vertex";
+    case moab::MBEDGE      : return "Edge";
+    case moab::MBTRI       : return "Triangle";
+    case moab::MBQUAD      : return "Quadrilateral";
+    case moab::MBPOLYGON   : return "Polygon";
+    case moab::MBTET       : return "Tetrahedron";
+    case moab::MBPYRAMID   : return "Pyramid";
+    case moab::MBPRISM     : return "Prism (wedge)";
+    case moab::MBKNIFE     : return "Knife";
+    case moab::MBHEX       : return "Hexahedron";
+    case moab::MBPOLYHEDRON: return "Polyhedron";
+    case moab::MBENTITYSET : return "Entity (Mesh) Set";
+    case moab::MBMAXTYPE   : return "(max type)";
     default          : return "(unknown)";
   }
 }
 
-const char* mb_type_str( MBEntityHandle a )
-  { return mb_type_str( TYPE_FROM_HANDLE(a) ); }
+const char* mb_type_str( moab::EntityHandle a )
+  { return mb_type_str( moab::TYPE_FROM_HANDLE(a) ); }
 /*
-void check_equal( MBEntityHandle A, MBEntityHandle B, const char* sA, const char* sB, int line, const char* file )
+void check_equal( moab::EntityHandle A, moab::EntityHandle B, const char* sA, const char* sB, int line, const char* file )
 {
   if (A == B)
     return;
@@ -536,14 +536,14 @@
   check_array_equal( &A[0], A.size(), &B[0], B.size(), sA, sB, line, file );
 }
 
-#ifdef MB_RANGE_HPP
+#ifdef MOAB_RANGE_HPP
 
-void check_equal( const MBRange& A, const MBRange& B, const char* sA, const char* sB, int line, const char* file )
+void check_equal( const moab::Range& A, const moab::Range& B, const char* sA, const char* sB, int line, const char* file )
 {
   if (A == B)
     return;
     
-  std::cout << "MBErrorCode Test Failed: " << sA << " == " << sB << std::endl;
+  std::cout << "moab::ErrorCode Test Failed: " << sA << " == " << sB << std::endl;
   std::cout << "  at line " << line << " of '" << file << "'" << std::endl;
   std::cout << "   Expected: " << A << std::endl;
   std::cout << "   Actual  : " << B << std::endl;

Modified: MOAB/trunk/test/Test_MBMeshSet.cpp
===================================================================
--- MOAB/trunk/test/Test_MBMeshSet.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/Test_MBMeshSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,10 @@
-#include "MBMeshSet.hpp"
+#include "MeshSet.hpp"
 #include "AEntityFactory.hpp"
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 
+using namespace moab;
+
 #include <iostream>
 
 //! test add_entities, get_entities, num_entities
@@ -19,32 +21,32 @@
 void test_intersect( unsigned flags1, unsigned flags2 );
 //! test unite_meshset
 void test_unite( unsigned flags1, unsigned flags2 );
-//! test MBMeshSet::contains_entities
+//! test MeshSet::contains_entities
 void test_contains_entities( unsigned flags );
 //! test clear_meshset
 void test_clear( unsigned flags );
 
 //! Create 10x10x10 hex mesh
-void make_mesh( MBInterface& iface );
+void make_mesh( Interface& iface );
 //! Create 10x10x10 hex mesh, return ranges of handles
-void make_mesh( MBInterface& iface, MBEntityHandle& vstart, MBEntityHandle& vend, MBEntityHandle& hstart, MBEntityHandle& hend );
-//! Print std::vector<MBEntityHandle>
-void print_handle_vect( const char* prefix, const std::vector<MBEntityHandle>& vect );
-//! Print MBRange
-void print_mbrange( const char* prefix, const MBRange& range );
+void make_mesh( Interface& iface, EntityHandle& vstart, EntityHandle& vend, EntityHandle& hstart, EntityHandle& hend );
+//! Print std::vector<EntityHandle>
+void print_handle_vect( const char* prefix, const std::vector<EntityHandle>& vect );
+//! Print Range
+void print_mbrange( const char* prefix, const Range& range );
 //! Compare set contents against passed vector, and if MESHSET_TRACK_OWNER then check adjacencies
-bool check_set_contents( MBCore& mb, MBEntityHandle set, const std::vector<MBEntityHandle>& expected );
+bool check_set_contents( Core& mb, EntityHandle set, const std::vector<EntityHandle>& expected );
 //! Compare result of get_entities_by_type to result of get_entities_by_handle
-bool check_set_contents( MBCore& mb, MBEntityType type, MBEntityHandle set, unsigned flags );
+bool check_set_contents( Core& mb, EntityType type, EntityHandle set, unsigned flags );
 //! Compare result of get_entities_by_dimension to result of get_entities_by_handle
-bool check_set_contents( MBCore& mb, int dim, MBEntityHandle set, unsigned flags );
+bool check_set_contents( Core& mb, int dim, EntityHandle set, unsigned flags );
 //! For each entry in range, if one or more occurances in vect, remove last occurance from vect.
-void remove_from_back( std::vector<MBEntityHandle>& vect, const MBRange& range );
+void remove_from_back( std::vector<EntityHandle>& vect, const Range& range );
 enum BoolOp { UNITE, INTERSECT, SUBTRACT };
 //! Perform boolean op on two entity sets and verify result
-bool test_boolean( MBCore& mb, BoolOp op, 
-                   unsigned flags1, const MBRange& set1_ents, 
-                   unsigned flags2, const MBRange& set2_ents );
+bool test_boolean( Core& mb, BoolOp op, 
+                   unsigned flags1, const Range& set1_ents, 
+                   unsigned flags2, const Range& set2_ents );
 
 void test_add_entities_ordered()          { test_add_entities( MESHSET_ORDERED ); }
 void test_add_entities_set()              { test_add_entities( MESHSET_SET     ); }
@@ -159,18 +161,18 @@
 }
 
 // Create 100x100x100 hex mesh
-void make_mesh( MBInterface& iface )
+void make_mesh( Interface& iface )
 {
   const int dim = 10;
 
     // create vertices
-  MBEntityHandle prev_handle = 0;
+  EntityHandle prev_handle = 0;
   for (int z = 0; z <= dim; ++z) {
     for (int y = 0; y <= dim; ++y) {
       for (int x = 0; x <= dim; ++x) {
         const double coords[] = {x, y, z};
-        MBEntityHandle new_handle = 0;
-        MBErrorCode rval = iface.create_vertex( coords, new_handle );
+        EntityHandle new_handle = 0;
+        ErrorCode rval = iface.create_vertex( coords, new_handle );
         CHECK_ERR(rval);
         CHECK_EQUAL( ++prev_handle, new_handle );
       }
@@ -184,11 +186,11 @@
   for (int z = 0; z < dim; ++z) {
     for (int y = 0; y < dim; ++y) {
       for (int x = 0; x < dim; ++x) {
-        const MBEntityHandle off = 1 + x + dim1*y + dimq*z;
-        const MBEntityHandle conn[] = { off,      off+1,      off+1+dim1,      off+dim1,
+        const EntityHandle off = 1 + x + dim1*y + dimq*z;
+        const EntityHandle conn[] = { off,      off+1,      off+1+dim1,      off+dim1,
                                         off+dimq, off+1+dimq, off+1+dim1+dimq, off+dim1+dimq };
-        MBEntityHandle new_handle = 0;
-        MBErrorCode rval = iface.create_element( MBHEX, conn, 8, new_handle );
+        EntityHandle new_handle = 0;
+        ErrorCode rval = iface.create_element( MBHEX, conn, 8, new_handle );
         CHECK_ERR(rval);
         CHECK_EQUAL( prev_handle++, new_handle );
       }
@@ -197,24 +199,24 @@
   
 }
 
-void make_mesh( MBInterface& mb, MBEntityHandle& first_vert, MBEntityHandle& last_vert, MBEntityHandle& first_hex, MBEntityHandle& last_hex )
+void make_mesh( Interface& mb, EntityHandle& first_vert, EntityHandle& last_vert, EntityHandle& first_hex, EntityHandle& last_hex )
 {
   make_mesh( mb );
   
     // Get handle ranges, and validate assumption that handles
     // are contiguous.
-  MBRange range;
-  MBErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, range );
+  Range range;
+  ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, range );
   CHECK_ERR(rval);
   first_vert = range.front();
   last_vert = range.back();
-  CHECK_EQUAL( (MBEntityHandle)1331, last_vert - first_vert + 1 );
+  CHECK_EQUAL( (EntityHandle)1331, last_vert - first_vert + 1 );
   range.clear();
   rval = mb.get_entities_by_type( 0, MBHEX, range );
   CHECK_ERR(rval);
   first_hex = range.front();
   last_hex = range.back();
-  CHECK_EQUAL( (MBEntityHandle)1000, last_hex - first_hex + 1 );
+  CHECK_EQUAL( (EntityHandle)1000, last_hex - first_hex + 1 );
 }
 
 
@@ -229,8 +231,8 @@
   }
   
   iter_type i = begin;
-  MBEntityType prev_type = TYPE_FROM_HANDLE(*i);
-  MBEntityHandle prev_ent = *i;
+  EntityType prev_type = TYPE_FROM_HANDLE(*i);
+  EntityHandle prev_ent = *i;
   str << ' ' << MBCN::EntityTypeName(prev_type) << ' ' << ID_FROM_HANDLE(*i);
   for (;;) {
     iter_type j = i;
@@ -254,24 +256,24 @@
   str << std::endl;
 }
 
-void print_handle_vect( const char* prefix, const std::vector<MBEntityHandle>& vect )
+void print_handle_vect( const char* prefix, const std::vector<EntityHandle>& vect )
 {
   print_handles(std::cout, prefix, vect.begin(), vect.end());
 }
 
-void print_mbrange( const char* prefix, const MBRange& range )
+void print_mbrange( const char* prefix, const Range& range )
 {
   print_handles(std::cout, prefix, range.begin(), range.end());
 }
 
 bool compare_set_contents( unsigned flags, 
-                           const std::vector<MBEntityHandle>& expected,
+                           const std::vector<EntityHandle>& expected,
                            int set_count,
-                           std::vector<MBEntityHandle>& vect,
-                           const MBRange& range )
+                           std::vector<EntityHandle>& vect,
+                           const Range& range )
 {
   
-  std::vector<MBEntityHandle> sorted( expected );
+  std::vector<EntityHandle> sorted( expected );
   std::sort( sorted.begin(), sorted.end() );
   sorted.erase( std::unique( sorted.begin(), sorted.end() ), sorted.end() );
   
@@ -315,15 +317,15 @@
   return true;
 }     
 
-bool check_set_contents( MBCore& mb, MBEntityHandle set, const std::vector<MBEntityHandle>& expected )
+bool check_set_contents( Core& mb, EntityHandle set, const std::vector<EntityHandle>& expected )
 {
   unsigned flags;
-  MBErrorCode rval = mb.get_meshset_options( set, flags );
+  ErrorCode rval = mb.get_meshset_options( set, flags );
   CHECK_ERR(rval);
   
   int count;
-  std::vector<MBEntityHandle> vect;
-  MBRange range;
+  std::vector<EntityHandle> vect;
+  Range range;
   rval = mb.get_entities_by_handle( set, vect, false );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_handle( set, range, false );
@@ -338,15 +340,15 @@
     return true;
   
     // get all entitites with an adjacency to the set
-  std::vector<MBEntityHandle> adj;
-  MBRange all, adjacent;
-  MBRange::iterator in = adjacent.begin();
+  std::vector<EntityHandle> adj;
+  Range all, adjacent;
+  Range::iterator in = adjacent.begin();
   mb.get_entities_by_handle( 0, all );
-  for (MBRange::iterator i = all.begin(); i != all.end(); ++i) {
+  for (Range::iterator i = all.begin(); i != all.end(); ++i) {
     adj.clear();
     rval = mb.a_entity_factory()->get_adjacencies( *i, adj );
     CHECK_ERR(rval);
-    std::vector<MBEntityHandle>::iterator j = std::lower_bound( adj.begin(), adj.end(), set );
+    std::vector<EntityHandle>::iterator j = std::lower_bound( adj.begin(), adj.end(), set );
     if (j != adj.end() && *j == set)
       in = adjacent.insert( in, *i, *i );
   }
@@ -361,16 +363,16 @@
   return true;
 }  
 
-bool check_set_contents( MBCore& mb, MBEntityType type, MBEntityHandle set, unsigned flags )
+bool check_set_contents( Core& mb, EntityType type, EntityHandle set, unsigned flags )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int count;
-  std::vector<MBEntityHandle> vect, expected;
-  MBRange range;
+  std::vector<EntityHandle> vect, expected;
+  Range range;
   
   rval = mb.get_entities_by_handle( set, expected, false );
   CHECK_ERR(rval);
-  std::vector<MBEntityHandle>::iterator i = expected.begin();
+  std::vector<EntityHandle>::iterator i = expected.begin();
   while (i != expected.end()) {
     if (TYPE_FROM_HANDLE(*i) != type)
       i = expected.erase( i );
@@ -387,16 +389,16 @@
   return compare_set_contents( flags, expected, count, vect, range );
 }  
 
-bool check_set_contents( MBCore& mb, int dim, MBEntityHandle set, unsigned flags )
+bool check_set_contents( Core& mb, int dim, EntityHandle set, unsigned flags )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int count;
-  std::vector<MBEntityHandle> vect, expected;
-  MBRange range;
+  std::vector<EntityHandle> vect, expected;
+  Range range;
   
   rval = mb.get_entities_by_handle( set, expected, false );
   CHECK_ERR(rval);
-  std::vector<MBEntityHandle>::iterator i = expected.begin();
+  std::vector<EntityHandle>::iterator i = expected.begin();
   while (i != expected.end()) {
     if (MBCN::Dimension(TYPE_FROM_HANDLE(*i)) != dim)
       i = expected.erase( i );
@@ -415,14 +417,14 @@
 
 void test_add_entities( unsigned flags )
 {
-  MBCore mb; make_mesh( mb );
+  Core mb; make_mesh( mb );
   
-  MBEntityHandle set;
-  MBErrorCode rval = mb.create_meshset( flags, set );
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset( flags, set );
   CHECK_ERR(rval);
   
-  std::vector<MBEntityHandle> contents, vect;
-  MBRange range;
+  std::vector<EntityHandle> contents, vect;
+  Range range;
   
   range.clear();
   range.insert( 11, 20 );
@@ -553,7 +555,7 @@
   CHECK( check_set_contents( mb, set, contents ) );
   
   vect.clear();
-  for (MBEntityHandle h = 1; h < 100; ++h) {
+  for (EntityHandle h = 1; h < 100; ++h) {
     vect.push_back(h);
     contents.push_back(h);
   }
@@ -611,14 +613,14 @@
   CHECK( check_set_contents( mb, set, contents ) );
 }
 
-void remove_from_back( std::vector<MBEntityHandle>& vect, const MBRange& range )
+void remove_from_back( std::vector<EntityHandle>& vect, const Range& range )
 {
-  for (MBRange::const_iterator r = range.begin(); r != range.end(); ++r) {
-    std::vector<MBEntityHandle>::reverse_iterator i = find( vect.rbegin(), vect.rend(), *r );
+  for (Range::const_iterator r = range.begin(); r != range.end(); ++r) {
+    std::vector<EntityHandle>::reverse_iterator i = find( vect.rbegin(), vect.rend(), *r );
     if (i != vect.rend())
       *i = 0;
   }
-  std::vector<MBEntityHandle>::iterator j = vect.begin(); 
+  std::vector<EntityHandle>::iterator j = vect.begin(); 
   while (j != vect.end()) {
     if (*j == 0)
       j = vect.erase(j);
@@ -629,14 +631,14 @@
 
 void test_remove_entities( unsigned flags )
 {
-  MBCore mb; make_mesh( mb );
+  Core mb; make_mesh( mb );
   
-  MBEntityHandle set;
-  MBErrorCode rval = mb.create_meshset( flags, set );
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset( flags, set );
   CHECK_ERR(rval);
   
-  std::vector<MBEntityHandle> contents;
-  MBRange range;
+  std::vector<EntityHandle> contents;
+  Range range;
   
   range.clear();
   range.insert( 1, 1000 );
@@ -809,7 +811,7 @@
   
   // test vector-based remove
   assert(contents.size() == 242);
-  std::vector<MBEntityHandle> remlist(5);
+  std::vector<EntityHandle> remlist(5);
   remlist[0] = contents[240]; contents.erase( contents.begin() + 240 );
   remlist[1] = contents[200]; contents.erase( contents.begin() + 200 );
   remlist[2] = contents[100]; contents.erase( contents.begin() + 100 );
@@ -837,7 +839,7 @@
   // [1000,2000]
   CHECK( check_set_contents( mb, set, contents ) );
   
-  MBRange remove;
+  Range remove;
   remove.insert( 1, 3 );
   remove.insert( 10, 100 );
   remove.insert( 110, 120 );
@@ -857,12 +859,12 @@
 
 void test_entities_by_type( unsigned flags )
 {
-  MBEntityHandle first_vert, last_vert, first_hex, last_hex;
-  MBCore mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
+  EntityHandle first_vert, last_vert, first_hex, last_hex;
+  Core mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
   
     // Create an entity set
-  MBEntityHandle set;
-  MBErrorCode rval = mb.create_meshset( flags, set );
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset( flags, set );
   CHECK_ERR(rval);
 
     // Test empty set
@@ -871,7 +873,7 @@
   CHECK( check_set_contents( mb, MBHEX   , set, flags ) );
   
     // Add stuff to set
-  MBRange range;
+  Range range;
   range.insert( first_vert      , first_vert +  10 );
   range.insert( first_vert + 100, first_vert + 110 );
   range.insert( first_hex  + 200, first_hex  + 299 );
@@ -887,12 +889,12 @@
 
 void test_entities_by_dimension( unsigned flags )
 {
-  MBEntityHandle first_vert, last_vert, first_hex, last_hex;
-  MBCore mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
+  EntityHandle first_vert, last_vert, first_hex, last_hex;
+  Core mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
   
     // Create an entity set
-  MBEntityHandle set;
-  MBErrorCode rval = mb.create_meshset( flags, set );
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset( flags, set );
   CHECK_ERR(rval);
 
     // Test empty set
@@ -902,7 +904,7 @@
   CHECK( check_set_contents( mb, 3, set, flags ) );
   
     // Add stuff to set
-  MBRange range;
+  Range range;
   range.insert( first_vert      , first_vert +  10 );
   range.insert( first_vert + 100, first_vert + 110 );
   range.insert( first_hex  + 200, first_hex  + 299 );
@@ -917,14 +919,14 @@
   CHECK( check_set_contents( mb, 3, set, flags ) );
 }
 
-bool test_boolean( MBCore& mb, BoolOp op, 
-                   unsigned flags1, const MBRange& set1_ents, 
-                   unsigned flags2, const MBRange& set2_ents )
+bool test_boolean( Core& mb, BoolOp op, 
+                   unsigned flags1, const Range& set1_ents, 
+                   unsigned flags2, const Range& set2_ents )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
    
   // make sets
-  MBEntityHandle set1, set2;
+  EntityHandle set1, set2;
   rval = mb.create_meshset( flags1, set1 );
   CHECK_ERR(rval);
   rval = mb.create_meshset( flags2, set2 );
@@ -934,8 +936,8 @@
   rval = mb.add_entities( set2, set2_ents );
   CHECK_ERR(rval);
   
-  MBRange tmp_range;
-  std::vector<MBEntityHandle> expected;
+  Range tmp_range;
+  std::vector<EntityHandle> expected;
   rval = MB_INDEX_OUT_OF_RANGE;
   switch (op) {
     case UNITE:
@@ -973,9 +975,9 @@
 
 void test_intersect( unsigned flags1, unsigned flags2 )
 {
-  MBRange empty, set1_ents, set2_ents;
-  MBEntityHandle first_vert, last_vert, first_hex, last_hex;
-  MBCore mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
+  Range empty, set1_ents, set2_ents;
+  EntityHandle first_vert, last_vert, first_hex, last_hex;
+  Core mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
 
     // define contents of first set
   set1_ents.insert( first_vert, first_vert + 10 );
@@ -999,9 +1001,9 @@
 
 void test_unite( unsigned flags1, unsigned flags2 )
 {
-  MBRange empty, set1_ents, set2_ents;
-  MBEntityHandle first_vert, last_vert, first_hex, last_hex;
-  MBCore mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
+  Range empty, set1_ents, set2_ents;
+  EntityHandle first_vert, last_vert, first_hex, last_hex;
+  Core mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
 
     // define contents of first set
   set1_ents.insert( first_vert, first_vert + 10 );
@@ -1026,9 +1028,9 @@
 
 void test_subtract( unsigned flags1, unsigned flags2 )
 {
-  MBRange empty, set1_ents, set2_ents;
-  MBEntityHandle first_vert, last_vert, first_hex, last_hex;
-  MBCore mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
+  Range empty, set1_ents, set2_ents;
+  EntityHandle first_vert, last_vert, first_hex, last_hex;
+  Core mb; make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
 
     // define contents of first set
   set1_ents.insert( first_vert, first_vert + 10 );
@@ -1055,38 +1057,38 @@
 void test_contains_entities( unsigned flags )
 {
   CHECK( !(flags&MESHSET_TRACK_OWNER) );
-  MBMeshSet set(flags);
+  MeshSet set(flags);
   bool result;
   
-  const MBEntityHandle entities[] = { 1,2,3,6,10,11,25,100 };
-  const int num_ents = sizeof(entities)/sizeof(MBEntityHandle);
-  MBErrorCode rval = set.add_entities( entities, num_ents, 0, 0 );
+  const EntityHandle entities[] = { 1,2,3,6,10,11,25,100 };
+  const int num_ents = sizeof(entities)/sizeof(EntityHandle);
+  ErrorCode rval = set.add_entities( entities, num_ents, 0, 0 );
   CHECK_ERR(rval);
   
-  result = set.contains_entities( entities, num_ents, MBInterface::UNION );
+  result = set.contains_entities( entities, num_ents, Interface::UNION );
   CHECK(result);
-  result = set.contains_entities( entities, num_ents, MBInterface::INTERSECT );
+  result = set.contains_entities( entities, num_ents, Interface::INTERSECT );
   CHECK(result);
   
-  result = set.contains_entities( entities, 1, MBInterface::UNION );
+  result = set.contains_entities( entities, 1, Interface::UNION );
   CHECK(result);
-  result = set.contains_entities( entities, 1, MBInterface::INTERSECT );
+  result = set.contains_entities( entities, 1, Interface::INTERSECT );
   CHECK(result);
   
-  const MBEntityHandle entities2[] = { 3,4,5 };
-  const int num_ents2 = sizeof(entities2)/sizeof(MBEntityHandle);
-  result = set.contains_entities( entities2, num_ents2, MBInterface::UNION );
+  const EntityHandle entities2[] = { 3,4,5 };
+  const int num_ents2 = sizeof(entities2)/sizeof(EntityHandle);
+  result = set.contains_entities( entities2, num_ents2, Interface::UNION );
   CHECK(result);
-  result = set.contains_entities( entities2, num_ents2, MBInterface::INTERSECT );
+  result = set.contains_entities( entities2, num_ents2, Interface::INTERSECT );
   CHECK(!result);
 }
 
 void test_clear( unsigned flags )
 {
-  std::vector<MBEntityHandle> contents(4);
-  MBCore mb; make_mesh( mb, contents[0], contents[1], contents[2], contents[3] );
-  MBEntityHandle set;
-  MBErrorCode rval = mb.create_meshset( flags, set );
+  std::vector<EntityHandle> contents(4);
+  Core mb; make_mesh( mb, contents[0], contents[1], contents[2], contents[3] );
+  EntityHandle set;
+  ErrorCode rval = mb.create_meshset( flags, set );
   CHECK_ERR(rval);
   rval = mb.add_entities( set, &contents[0], contents.size() );
   CHECK_ERR(rval);

Modified: MOAB/trunk/test/VarLenTagTest.cpp
===================================================================
--- MOAB/trunk/test/VarLenTagTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/VarLenTagTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,8 @@
 #include "TestUtil.hpp"
 #include "VarLenTag.hpp"
 
+using namespace moab;
+
 #include <iostream>
 
 void test_valid_struct();

Modified: MOAB/trunk/test/adaptive_kd_tree_tests.cpp
===================================================================
--- MOAB/trunk/test/adaptive_kd_tree_tests.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/adaptive_kd_tree_tests.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,15 +1,17 @@
-#include "MBCore.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBCartVect.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/GeomUtil.hpp"
+#include "moab/Range.hpp"
 #include "TestUtil.hpp"
 
+using namespace moab;
+
 #include <iostream>
 #include <algorithm>
 
 /* Utility method - compare two range boxes */
-bool box_equal( const MBAdaptiveKDTreeIter& iter, 
+bool box_equal( const AdaptiveKDTreeIter& iter, 
                 double x_min, double y_min, double z_min,
                 double x_max, double y_max, double z_max )
 {
@@ -21,15 +23,15 @@
          iter.box_max()[2] == z_max;
 }
 
-void build_triangles( MBInterface* moab, MBRange& tris,
+void build_triangles( Interface* moab, Range& tris,
                       int num_vert, const double* coords,
                       int num_tri,  const unsigned* conn )
 {
-  std::vector<MBEntityHandle> verts(num_vert);
+  std::vector<EntityHandle> verts(num_vert);
   for (int i = 0; i < num_vert; ++i)
     moab->create_vertex( coords + 3*i, verts[i] );
   
-  MBEntityHandle tri, tri_verts[3];
+  EntityHandle tri, tri_verts[3];
   for (int i = 0; i < num_tri; ++i) {
     tri_verts[0] = verts[conn[3*i  ]];
     tri_verts[1] = verts[conn[3*i+1]];
@@ -41,7 +43,7 @@
 }  
 
 /* Utility method - build a 2x2x2 box composed of four triagles on a side */
-void build_triangle_box_small( MBInterface* moab, MBRange& tris )
+void build_triangle_box_small( Interface* moab, Range& tris )
 {
   const double coords[] = { -1, -1, -1,
                              1, -1, -1,
@@ -65,7 +67,7 @@
 /* build 6x6x6 box centered at origin and composed of 18 triangles per side,
    Each side of the box is composed of a 3x3 grid of quads, where each
    quad is split diagonally to form two triangles. */
-void build_triangle_box_large( MBInterface* moab, MBRange& tris )
+void build_triangle_box_large( Interface* moab, Range& tris )
 {
   const double coords[] = { // corners
                             -3, -3, -3,
@@ -257,7 +259,7 @@
                             
 
 /* Utility method - build 2x2x2 octahedron (3D diamond)*/
-void build_triangle_octahedron( MBInterface* moab, MBRange& tris )
+void build_triangle_octahedron( Interface* moab, Range& tris )
 {
   const double coords[] = {  1,  0,  0,
                              0,  1,  0,
@@ -277,34 +279,34 @@
   build_triangles( moab, tris, 6, coords, 8, conn );
 }
 
-void test_valid_tree( MBAdaptiveKDTree* tool, MBEntityHandle root, 
-                      MBAdaptiveKDTree::Settings& settings,
-                      const MBRange& expected_tris )
+void test_valid_tree( AdaptiveKDTree* tool, EntityHandle root, 
+                      AdaptiveKDTree::Settings& settings,
+                      const Range& expected_tris )
 {
-  MBRange all_tris;
-  MBErrorCode rval;
-  MBAdaptiveKDTreeIter iter;
+  Range all_tris;
+  ErrorCode rval;
+  AdaptiveKDTreeIter iter;
   CHECK(MB_SUCCESS == tool->get_tree_iterator( root, iter ));
   do {
     CHECK( !settings.maxTreeDepth || iter.depth() <= settings.maxTreeDepth );
     
-    MBRange tris;
+    Range tris;
     CHECK( tool->moab()->get_entities_by_type( iter.handle(), MBTRI, tris ) == MB_SUCCESS );
     //CHECK( !tris.empty() );
     all_tris.merge( tris );
 
-    const MBCartVect min(iter.box_min()), max(iter.box_max());
-    const MBCartVect cen(0.5*(min+max)), hdim(0.5*(max-min));
+    const CartVect min(iter.box_min()), max(iter.box_max());
+    const CartVect cen(0.5*(min+max)), hdim(0.5*(max-min));
     
-    for (MBRange::iterator i = tris.begin(); i != tris.end(); ++i) {
-      MBEntityHandle tri = *i;
-      const MBEntityHandle* conn;
+    for (Range::iterator i = tris.begin(); i != tris.end(); ++i) {
+      EntityHandle tri = *i;
+      const EntityHandle* conn;
       int conn_len;
       CHECK( tool->moab()->get_connectivity( tri, conn, conn_len ) == MB_SUCCESS );
       CHECK( conn_len == 3 );
-      MBCartVect coords[3];
+      CartVect coords[3];
       CHECK( tool->moab()->get_coords( conn, 3, coords[0].array() ) == MB_SUCCESS );
-      CHECK( MBGeomUtil::box_tri_overlap( coords, cen, hdim ) );
+      CHECK( GeomUtil::box_tri_overlap( coords, cen, hdim ) );
     }
   } while (MB_SUCCESS == (rval = iter.step()));  
   
@@ -313,17 +315,17 @@
 }
 
 /* utility method - check that all tris share a vertex */
-void check_common_vertex( MBInterface* moab,
-                          const MBEntityHandle* tris,
+void check_common_vertex( Interface* moab,
+                          const EntityHandle* tris,
                           unsigned num_tri,
-                          MBCartVect point )
+                          CartVect point )
 {
   for (unsigned i = 0; i < num_tri; ++i)
     CHECK( MBTRI == moab->type_from_handle( tris[i] ) );
   
-  MBErrorCode rval;
-  MBCartVect tri_coords[3];
-  const MBEntityHandle* conn;
+  ErrorCode rval;
+  CartVect tri_coords[3];
+  const EntityHandle* conn;
   int conn_len;
   rval = moab->get_connectivity( tris[0], conn, conn_len );
   CHECK( MB_SUCCESS == rval );
@@ -332,7 +334,7 @@
   tri_coords[0] -= point;
   tri_coords[1] -= point;
   tri_coords[2] -= point;
-  MBEntityHandle vertex = 0;
+  EntityHandle vertex = 0;
   if (tri_coords[0] % tri_coords[0] < 1e-6)
     vertex = conn[0];
   else if (tri_coords[1] % tri_coords[1] < 1e-6)
@@ -347,14 +349,14 @@
 }                        
  
 /* utility method - check that all tris share a vertex */
-void check_point_in_triangles( MBInterface* moab,
-                               const MBEntityHandle* tris,
+void check_point_in_triangles( Interface* moab,
+                               const EntityHandle* tris,
                                unsigned num_tris,
-                               MBCartVect point )
+                               CartVect point )
 {
-  MBErrorCode rval;
-  MBCartVect tri_coords[3], tript;
-  const MBEntityHandle* conn;
+  ErrorCode rval;
+  CartVect tri_coords[3], tript;
+  const EntityHandle* conn;
   int conn_len;
 
   for (unsigned i = 0; i < num_tris; ++i) {
@@ -365,7 +367,7 @@
     rval = moab->get_coords( conn, 3, tri_coords[0].array() );
     CHECK( MB_SUCCESS == rval );
     
-    MBGeomUtil::closest_location_on_tri( point, tri_coords, tript );
+    GeomUtil::closest_location_on_tri( point, tri_coords, tript );
     tript -= point;
     CHECK( fabs(tript[0]) < 1e-6 );
     CHECK( fabs(tript[1]) < 1e-6 );
@@ -393,12 +395,12 @@
                     |                |
                     (2) X = -1      (4) X = 4
    */
-void create_simple_2d_tree( MBAdaptiveKDTree& tool, 
-                            MBEntityHandle& root,
-                            MBEntityHandle leaves[9] = 0 )
+void create_simple_2d_tree( AdaptiveKDTree& tool, 
+                            EntityHandle& root,
+                            EntityHandle leaves[9] = 0 )
 {
-  MBErrorCode rval;
-  MBAdaptiveKDTree::Plane plane;
+  ErrorCode rval;
+  AdaptiveKDTree::Plane plane;
 
     // create a single-node tree
   double min[3] = { -5, -4, -1 };
@@ -407,27 +409,27 @@
   CHECK( MB_SUCCESS == rval );
 
     // get iterator for tree
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK( MB_SUCCESS == rval );
   CHECK( box_equal(iter, -5, -4, -1, 5, 4, 1 ) );
    
    // split plane (1)
-  plane.norm = MBAdaptiveKDTree::Y;
+  plane.norm = AdaptiveKDTree::Y;
   plane.coord = 0.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
   CHECK( box_equal( iter, -5, -4, -1, 5, 0, 1 ) );
   
    // split plane (2)
-  plane.norm = MBAdaptiveKDTree::X;
+  plane.norm = AdaptiveKDTree::X;
   plane.coord = -1.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
   CHECK( box_equal( iter, -5, -4, -1, -1, 0, 1 ) );
   
    // split plane (3), leaf [1]
-  plane.norm = MBAdaptiveKDTree::Y;
+  plane.norm = AdaptiveKDTree::Y;
   plane.coord = -2.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
@@ -448,7 +450,7 @@
   CHECK( box_equal( iter, -1, -4, -1, 5, 0, 1 ) );
   
     // split plane (4) and leaf [3]
-  plane.norm = MBAdaptiveKDTree::X;
+  plane.norm = AdaptiveKDTree::X;
   plane.coord = 4.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
@@ -469,14 +471,14 @@
   CHECK( box_equal( iter, -5, 0, -1, 5, 4, 1 ) );
   
     // split plane (5)
-  plane.norm = MBAdaptiveKDTree::X;
+  plane.norm = AdaptiveKDTree::X;
   plane.coord = 0.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
   CHECK( box_equal( iter, -5, 0, -1, 0, 4, 1 ) );
   
     // split plane (6) and leaf [5]
-  plane.norm = MBAdaptiveKDTree::X;
+  plane.norm = AdaptiveKDTree::X;
   plane.coord = -3.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
@@ -497,7 +499,7 @@
   CHECK( box_equal( iter, 0, 0, -1, 5, 4, 1 ) );
   
     // split plane (7) and leaf [7]
-  plane.norm = MBAdaptiveKDTree::Y;
+  plane.norm = AdaptiveKDTree::Y;
   plane.coord = 3.0;
   rval = tool.split_leaf( iter, plane );
   CHECK( MB_SUCCESS == rval );
@@ -519,21 +521,21 @@
 
 void leaf_iterator_test()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface* mb = &moab;
-  MBAdaptiveKDTree tool(mb);
+  ErrorCode rval;
+  Core moab;
+  Interface* mb = &moab;
+  AdaptiveKDTree tool(mb);
 
 
     // create a single-node tree
-  MBEntityHandle root;
+  EntityHandle root;
   double min[3] = { -3, -2, -1 };
   double max[3] = {  1,  2,  3 };
   rval = tool.create_tree( min, max, root );
   CHECK( MB_SUCCESS == rval );
 
     // get iterator for tree
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK( MB_SUCCESS == rval );
   CHECK( box_equal(iter, -3, -2, -1, 1, 2, 3 ) );
@@ -550,12 +552,12 @@
   
   
     // construct a simple 2D tree for remaining tests
-  MBEntityHandle leaves[9];
+  EntityHandle leaves[9];
   create_simple_2d_tree( tool, root, leaves );
 
   
   /**** Now traverse tree again, and check neighbors of each leaf *****/
-  std::vector<MBAdaptiveKDTreeIter> list;
+  std::vector<AdaptiveKDTreeIter> list;
   
     // leaf [1]
   
@@ -565,12 +567,12 @@
   CHECK( iter.handle() == leaves[1] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::X, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::X, true, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::X, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::X, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.size() == 1 );
     // should be leaf [3]
@@ -578,12 +580,12 @@
   CHECK( list.front().handle() == leaves[3] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Y, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Y, true, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Y, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Y, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.size() == 1 );
     // should be leaf [2]
@@ -591,12 +593,12 @@
   CHECK( list.front().handle() == leaves[2] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Z, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Z, true, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Z, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Z, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
@@ -608,12 +610,12 @@
   CHECK( iter.handle() == leaves[2] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::X, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::X, true, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::X, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::X, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.size() == 1 );
     // should be leaf [3]
@@ -621,7 +623,7 @@
   CHECK( list.front().handle() == leaves[3] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Y, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Y, true, list );
   CHECK( MB_SUCCESS == rval );
     // should be leaf [1]
   CHECK( list.size() == 1 );
@@ -629,7 +631,7 @@
   CHECK( list.front().handle() == leaves[1] );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Y, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Y, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.size() == 2 );
     // should be leaf [5] and leaf[6]
@@ -641,12 +643,12 @@
   CHECK( box_equal( list[1], -3, 0, -1, 0, 4, 1 ) );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Z, true, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Z, true, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
   list.clear();
-  rval = iter.get_neighbors( MBAdaptiveKDTree::Z, false, list );
+  rval = iter.get_neighbors( AdaptiveKDTree::Z, false, list );
   CHECK( MB_SUCCESS == rval );
   CHECK( list.empty() );
   
@@ -690,16 +692,16 @@
 void test_tree_merge_nodes()
 {
     // build simple tree for tests
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface* mb = &moab;
-  MBAdaptiveKDTree tool(mb);
-  MBEntityHandle root;
-  MBEntityHandle leaves[9];
+  ErrorCode rval;
+  Core moab;
+  Interface* mb = &moab;
+  AdaptiveKDTree tool(mb);
+  EntityHandle root;
+  EntityHandle leaves[9];
   create_simple_2d_tree( tool, root, leaves );
 
     // get iterator for tree
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK( MB_SUCCESS == rval );
 
@@ -723,16 +725,16 @@
 
 void test_build_tree_bisect_triangles( )
 {
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBRange box_tris;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  Range box_tris;
   
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree::Settings settings;
   settings.maxEntPerLeaf = 1;
   settings.candidateSplitsPerDir = 1;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
-  MBEntityHandle root;
-  MBErrorCode rval;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
+  EntityHandle root;
+  ErrorCode rval;
   
   moab.delete_mesh(); box_tris.clear();
   build_triangle_box_small( &moab, box_tris );
@@ -761,17 +763,17 @@
   
 void test_closest_triangle()
 {
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBRange box_tris;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  Range box_tris;
   
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree::Settings settings;
   settings.maxEntPerLeaf = 1;
   settings.candidateSplitsPerDir = 1;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
-  MBEntityHandle root;
-  MBErrorCode rval;
-  MBEntityHandle tri;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
+  EntityHandle root;
+  ErrorCode rval;
+  EntityHandle tri;
   
   moab.delete_mesh(); box_tris.clear();
   build_triangle_box_small( &moab, box_tris );
@@ -785,7 +787,7 @@
     int y = i & 2 ? 1 : -1;
     int z = i & 4 ? 1 : -1;
     double coords[] = { 2.0*x, 2.0*y, 2.0*z };
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, coords, point.array(), tri );
     CHECK( MB_SUCCESS == rval );
       // check result position
@@ -797,18 +799,18 @@
   }
   
     // test location on each face
-  const MBCartVect facepts[] = { MBCartVect( -1.0, 0.5, 0.5 ),
-                                 MBCartVect(  1.0, 0.5, 0.5 ),
-                                 MBCartVect( 0.5, -1.0, 0.5 ),
-                                 MBCartVect( 0.5,  1.0, 0.5 ),
-                                 MBCartVect( 0.5, 0.5, -1.0 ),
-                                 MBCartVect( 0.5, 0.5,  1.0 ) };
+  const CartVect facepts[] = { CartVect( -1.0, 0.5, 0.5 ),
+                                 CartVect(  1.0, 0.5, 0.5 ),
+                                 CartVect( 0.5, -1.0, 0.5 ),
+                                 CartVect( 0.5,  1.0, 0.5 ),
+                                 CartVect( 0.5, 0.5, -1.0 ),
+                                 CartVect( 0.5, 0.5,  1.0 ) };
   for (unsigned i = 0; i < 6; ++i) {
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, facepts[i].array(), point.array(), tri );
     CHECK( MB_SUCCESS == rval );
       // check result position
-    const MBCartVect diff = facepts[i] - point;
+    const CartVect diff = facepts[i] - point;
     CHECK( fabs(diff[0]) < 1e-6 );
     CHECK( fabs(diff[1]) < 1e-6 );
     CHECK( fabs(diff[2]) < 1e-6 );
@@ -819,7 +821,7 @@
     // test a location really far from the tree
   {
     const double far[] = { 0.75, 0.75, 200 };
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, far, point.array(), tri );
     CHECK( MB_SUCCESS == rval );
     CHECK( fabs(point[0] - 0.75) < 1e-6 );    
@@ -842,7 +844,7 @@
     int y = i & 2 ? 1 : -1;
     int z = i & 4 ? 1 : -1;
     double coords[] = { 4.0*x, 4.0*y, 4.0*z };
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, coords, point.array(), tri );
     CHECK( MB_SUCCESS == rval );
       // check result position
@@ -854,18 +856,18 @@
   }
   
     // test location on each face
-  const MBCartVect facepts2[] = { MBCartVect( -3.0, 0.5, 0.5 ),
-                                 MBCartVect(  3.0, 0.5, 0.5 ),
-                                 MBCartVect( 0.5, -3.0, 0.5 ),
-                                 MBCartVect( 0.5,  3.0, 0.5 ),
-                                 MBCartVect( 0.5, 0.5, -3.0 ),
-                                 MBCartVect( 0.5, 0.5,  3.0 ) };
+  const CartVect facepts2[] = { CartVect( -3.0, 0.5, 0.5 ),
+                                 CartVect(  3.0, 0.5, 0.5 ),
+                                 CartVect( 0.5, -3.0, 0.5 ),
+                                 CartVect( 0.5,  3.0, 0.5 ),
+                                 CartVect( 0.5, 0.5, -3.0 ),
+                                 CartVect( 0.5, 0.5,  3.0 ) };
   for (unsigned i = 0; i < 6; ++i) {
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, facepts2[i].array(), point.array(), tri );
     CHECK( MB_SUCCESS == rval );
       // check result position
-    const MBCartVect diff = facepts2[i] - point;
+    const CartVect diff = facepts2[i] - point;
     CHECK( fabs(diff[0]) < 1e-6 );
     CHECK( fabs(diff[1]) < 1e-6 );
     CHECK( fabs(diff[2]) < 1e-6 );
@@ -876,7 +878,7 @@
     // test a location really far from the tree
   {
     const double far[] = { 2.75, 2.75, 200 };
-    MBCartVect point;
+    CartVect point;
     rval = tool.closest_triangle( root, far, point.array(), tri );
     CHECK( MB_SUCCESS == rval );
     CHECK( fabs(point[0] - 2.75) < 1e-6 );    
@@ -889,17 +891,17 @@
 
 void test_sphere_intersect_triangles()
 {
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBRange box_tris;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  Range box_tris;
   
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree::Settings settings;
   settings.maxEntPerLeaf = 1;
   settings.candidateSplitsPerDir = 1;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
-  MBEntityHandle root;
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> triangles;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
+  EntityHandle root;
+  ErrorCode rval;
+  std::vector<EntityHandle> triangles;
   
   moab.delete_mesh(); box_tris.clear();
   build_triangle_box_small( &moab, box_tris );
@@ -920,7 +922,7 @@
     CHECK( triangles.size() >= 3 );
     CHECK( triangles.size() <= 6 );
       // check point is at the same vertex for each triangle
-    check_common_vertex( tool.moab(), &triangles[0], triangles.size(), MBCartVect(center) );
+    check_common_vertex( tool.moab(), &triangles[0], triangles.size(), CartVect(center) );
   }
   
     // now do it all again with a lot more triangles
@@ -944,23 +946,23 @@
     CHECK( triangles.size() >= 3 );
     CHECK( triangles.size() <= 6 );
       // check point is at the same vertex for each triangle
-    check_common_vertex( tool.moab(), &triangles[0], triangles.size(), MBCartVect(center) );
+    check_common_vertex( tool.moab(), &triangles[0], triangles.size(), CartVect(center) );
   }
 }
 
 void test_ray_intersect_triangles()
 {
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBRange box_tris;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  Range box_tris;
   
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree::Settings settings;
   settings.maxEntPerLeaf = 1;
   settings.candidateSplitsPerDir = 1;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
-  MBEntityHandle root;
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> tris;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
+  EntityHandle root;
+  ErrorCode rval;
+  std::vector<EntityHandle> tris;
   std::vector<double> dists;
   
   moab.delete_mesh(); box_tris.clear();
@@ -970,8 +972,8 @@
   test_valid_tree( &tool, root, settings, box_tris );
   
     // test ray through box parallel to X axis
-  MBCartVect dir( 1, 0, 0 );
-  MBCartVect pt( -2, 0.75, 0.75 );
+  CartVect dir( 1, 0, 0 );
+  CartVect pt( -2, 0.75, 0.75 );
   tris.clear(); dists.clear();
   rval = tool.ray_intersect_triangles( root, 1e-6, dir.array(), pt.array(), tris, dists );
   CHECK( MB_SUCCESS == rval );
@@ -979,7 +981,7 @@
   CHECK( dists.size() == tris.size() );
   for ( unsigned i = 0; i < dists.size(); ++i ) {
     CHECK( fabs(dists[i] - 1) < 1e-6 || fabs(dists[i] - 3) < 1e-6 );
-    MBCartVect tript = pt + dists[i] * dir;
+    CartVect tript = pt + dists[i] * dir;
     check_point_in_triangles( &moab, &tris[i], 1, tript );
   }
    
@@ -1003,20 +1005,20 @@
   
     // test ray starting within box parallel to X axis
   tris.clear(); dists.clear();
-  pt = MBCartVect( 0, .75, .75 );
+  pt = CartVect( 0, .75, .75 );
   rval = tool.ray_intersect_triangles( root, 1e-6, dir.array(), pt.array(), tris, dists );
   CHECK( MB_SUCCESS == rval );
   CHECK( tris.size() == 2 );
   CHECK( dists.size() == tris.size() );
   for ( unsigned i = 0; i < dists.size(); ++i ) {
     CHECK( fabs(dists[i] - 1) < 1e-6 );
-    MBCartVect tript = pt + dists[i] * dir;
+    CartVect tript = pt + dists[i] * dir;
     check_point_in_triangles( &moab, &tris[i], 1, tript );
   }
   
     // test skew ray through box
-  dir = MBCartVect( 0.5*sqrt(2.0), 0.5*sqrt(2.0), 0.0 );
-  pt = MBCartVect( 0, -1.5, 0 );
+  dir = CartVect( 0.5*sqrt(2.0), 0.5*sqrt(2.0), 0.0 );
+  pt = CartVect( 0, -1.5, 0 );
   tris.clear(); dists.clear();
   rval = tool.ray_intersect_triangles( root, 1e-6, dir.array(), pt.array(), tris, dists );
   CHECK( MB_SUCCESS == rval );
@@ -1031,8 +1033,8 @@
   
   
     // test ray through box parallel to -Y axis
-  dir = MBCartVect( 0, -1, 0 );
-  pt = MBCartVect( 0, 2, 0 );
+  dir = CartVect( 0, -1, 0 );
+  pt = CartVect( 0, 2, 0 );
   tris.clear(); dists.clear();
   rval = tool.ray_intersect_triangles( root, 1e-6, dir.array(), pt.array(), tris, dists );
   CHECK( MB_SUCCESS == rval );
@@ -1040,13 +1042,13 @@
   CHECK( dists.size() == tris.size() );
   for ( unsigned i = 0; i < dists.size(); ++i ) {
     CHECK( fabs(dists[i] - 1) < 1e-6 || fabs(dists[i] - 3) < 1e-6 );
-    MBCartVect tript = pt + dists[i] * dir;
+    CartVect tript = pt + dists[i] * dir;
     check_point_in_triangles( &moab, &tris[i], 1, tript );
   }
   
     // test ray through box parallel to Z axis
-  dir = MBCartVect( 0, 0, 1 );
-  pt = MBCartVect( 0, 0, -2 );
+  dir = CartVect( 0, 0, 1 );
+  pt = CartVect( 0, 0, -2 );
   tris.clear(); dists.clear();
   rval = tool.ray_intersect_triangles( root, 1e-6, dir.array(), pt.array(), tris, dists );
   CHECK( MB_SUCCESS == rval );
@@ -1054,7 +1056,7 @@
   CHECK( dists.size() == tris.size() );
   for ( unsigned i = 0; i < dists.size(); ++i ) {
     CHECK( fabs(dists[i] - 1) < 1e-6 || fabs(dists[i] - 3) < 1e-6 );
-    MBCartVect tript = pt + dists[i] * dir;
+    CartVect tript = pt + dists[i] * dir;
     check_point_in_triangles( &moab, &tris[i], 1, tript );
   }
   
@@ -1066,20 +1068,20 @@
   CHECK( dists.size() == tris.size() );
   for ( unsigned i = 0; i < dists.size(); ++i ) {
     CHECK( fabs(dists[i] - 1) < 1e-6 );
-    MBCartVect tript = pt + dists[i] * dir;
+    CartVect tript = pt + dists[i] * dir;
     check_point_in_triangles( &moab, &tris[i], 1, tript );
   }
 }
 
 void test_leaf_volume()
 {
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBEntityHandle root;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  EntityHandle root;
   
   create_simple_2d_tree( tool, root );
-  MBAdaptiveKDTreeIter iter;
-  MBErrorCode rval = tool.get_tree_iterator( root, iter );
+  AdaptiveKDTreeIter iter;
+  ErrorCode rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   
   CHECK_REAL_EQUAL( 16.0, iter.volume(), 1e-12 ); // 1
@@ -1101,13 +1103,13 @@
 
 void test_leaf_sibling()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
-  MBEntityHandle root;
+  ErrorCode rval;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
+  EntityHandle root;
   
   create_simple_2d_tree( tool, root );
-  MBAdaptiveKDTreeIter iter1, iter2;
+  AdaptiveKDTreeIter iter1, iter2;
   rval = tool.get_tree_iterator( root, iter1 );
   CHECK_ERR(rval);
   rval = tool.get_tree_iterator( root, iter2 );
@@ -1162,57 +1164,57 @@
 
 void test_leaf_intersects_plane()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
+  ErrorCode rval;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
   
-  MBEntityHandle root;
+  EntityHandle root;
   const double min[3] = { -5, -4, -1 };
   const double max[3] = {  1,  2,  3 };
   rval = tool.create_tree( min, max, root );
   CHECK_ERR(rval);
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   
-  MBAdaptiveKDTree::Plane x1 = { min[0] - 1, MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x1 = { min[0] - 1, AdaptiveKDTree::X };
   CHECK( !iter.intersects( x1 ) );
-  MBAdaptiveKDTree::Plane x2 = { min[0]    , MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x2 = { min[0]    , AdaptiveKDTree::X };
   CHECK(  iter.intersects( x2 ) );
-  MBAdaptiveKDTree::Plane x3 = { min[0] + 1, MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x3 = { min[0] + 1, AdaptiveKDTree::X };
   CHECK(  iter.intersects( x3 ) );
-  MBAdaptiveKDTree::Plane x4 = { max[0] - 1, MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x4 = { max[0] - 1, AdaptiveKDTree::X };
   CHECK(  iter.intersects( x4 ) );
-  MBAdaptiveKDTree::Plane x5 = { max[0]    , MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x5 = { max[0]    , AdaptiveKDTree::X };
   CHECK(  iter.intersects( x5 ) );
-  MBAdaptiveKDTree::Plane x6 = { max[0] + 1, MBAdaptiveKDTree::X };
+  AdaptiveKDTree::Plane x6 = { max[0] + 1, AdaptiveKDTree::X };
   CHECK( !iter.intersects( x6 ) );
   
-  MBAdaptiveKDTree::Plane y1 = { min[1] - 1, MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y1 = { min[1] - 1, AdaptiveKDTree::Y };
   CHECK( !iter.intersects( y1 ) );
-  MBAdaptiveKDTree::Plane y2 = { min[1]    , MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y2 = { min[1]    , AdaptiveKDTree::Y };
   CHECK(  iter.intersects( y2 ) );
-  MBAdaptiveKDTree::Plane y3 = { min[1] + 1, MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y3 = { min[1] + 1, AdaptiveKDTree::Y };
   CHECK(  iter.intersects( y3 ) );
-  MBAdaptiveKDTree::Plane y4 = { max[1] - 1, MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y4 = { max[1] - 1, AdaptiveKDTree::Y };
   CHECK(  iter.intersects( y4 ) );
-  MBAdaptiveKDTree::Plane y5 = { max[1]    , MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y5 = { max[1]    , AdaptiveKDTree::Y };
   CHECK(  iter.intersects( y5 ) );
-  MBAdaptiveKDTree::Plane y6 = { max[1] + 1, MBAdaptiveKDTree::Y };
+  AdaptiveKDTree::Plane y6 = { max[1] + 1, AdaptiveKDTree::Y };
   CHECK( !iter.intersects( y6 ) );
   
-  MBAdaptiveKDTree::Plane z1 = { min[2] - 1, MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z1 = { min[2] - 1, AdaptiveKDTree::Z };
   CHECK( !iter.intersects( z1 ) );
-  MBAdaptiveKDTree::Plane z2 = { min[2]    , MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z2 = { min[2]    , AdaptiveKDTree::Z };
   CHECK(  iter.intersects( z2 ) );
-  MBAdaptiveKDTree::Plane z3 = { min[2] + 1, MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z3 = { min[2] + 1, AdaptiveKDTree::Z };
   CHECK(  iter.intersects( z3 ) );
-  MBAdaptiveKDTree::Plane z4 = { max[2] - 1, MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z4 = { max[2] - 1, AdaptiveKDTree::Z };
   CHECK(  iter.intersects( z4 ) );
-  MBAdaptiveKDTree::Plane z5 = { max[2]    , MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z5 = { max[2]    , AdaptiveKDTree::Z };
   CHECK(  iter.intersects( z5 ) );
-  MBAdaptiveKDTree::Plane z6 = { max[2] + 1, MBAdaptiveKDTree::Z };
+  AdaptiveKDTree::Plane z6 = { max[2] + 1, AdaptiveKDTree::Z };
   CHECK( !iter.intersects( z6 ) );
 }
 
@@ -1224,18 +1226,18 @@
     
 void test_leaf_intersects_ray()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBAdaptiveKDTree tool( &moab );
+  ErrorCode rval;
+  Core moab;
+  AdaptiveKDTree tool( &moab );
   double t_in, t_out;
   
-  MBEntityHandle root;
+  EntityHandle root;
   const double min[3] = { -5, -4, -1 };
   const double max[3] = {  1,  2,  3 };
   rval = tool.create_tree( min, max, root );
   CHECK_ERR(rval);
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   

Modified: MOAB/trunk/test/bsp_tree_poly_test.cpp
===================================================================
--- MOAB/trunk/test/bsp_tree_poly_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/bsp_tree_poly_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,9 @@
-#include "BSPTreePoly.hpp"
+#include "moab/BSPTreePoly.hpp"
 #include "TestUtil.hpp"
-#include "MBCartVect.hpp"
+#include "moab/CartVect.hpp"
 
+using namespace moab;
+
 void test_construct_from_hex();
 void test_cut_with_plane();
 void test_volume();
@@ -23,26 +25,26 @@
                               { 3, 2, 1, 0 },
                               { 4, 5, 6, 7 } };
 
-static void get_corners( MBCartVect corners[8] )
+static void get_corners( CartVect corners[8] )
 {
-  corners[0] = MBCartVect( 1, 1, 0 );
-  corners[1] = MBCartVect( 6, 1, 0 );
-  corners[2] = MBCartVect( 6, 3, 0 );
-  corners[3] = MBCartVect( 1, 3, 0 );
-  corners[4] = MBCartVect( 1, 1, 2 );
-  corners[5] = MBCartVect( 4, 1, 2 );
-  corners[6] = MBCartVect( 4, 3, 2 );
-  corners[7] = MBCartVect( 1, 3, 2 );
+  corners[0] = CartVect( 1, 1, 0 );
+  corners[1] = CartVect( 6, 1, 0 );
+  corners[2] = CartVect( 6, 3, 0 );
+  corners[3] = CartVect( 1, 3, 0 );
+  corners[4] = CartVect( 1, 1, 2 );
+  corners[5] = CartVect( 4, 1, 2 );
+  corners[6] = CartVect( 4, 3, 2 );
+  corners[7] = CartVect( 1, 3, 2 );
 }
 
 const BSPTreePoly::Face* find_face( const BSPTreePoly& poly,
-                                     const MBCartVect* coords,
+                                     const CartVect* coords,
                                      int num_corners,
                                      const int* face_indices = 0 )
 {
   std::vector<const BSPTreePoly::Face*>::iterator i;
   std::vector<const BSPTreePoly::Face*> faces;
-  std::vector<MBCartVect> corners;
+  std::vector<CartVect> corners;
   poly.get_faces( faces );
   for (i = faces.begin(); i != faces.end(); ++i) {
     corners.clear();
@@ -77,7 +79,7 @@
 {
   BSPTreePoly::reset_debug_ids();
 
-  MBCartVect corners[8];
+  CartVect corners[8];
   get_corners( corners );
   BSPTreePoly poly( corners );
   CHECK( poly.is_valid() );
@@ -98,7 +100,7 @@
 {
     // create a hexahedron
   BSPTreePoly::reset_debug_ids();
-  MBCartVect corners[8];
+  CartVect corners[8];
   get_corners( corners );
   BSPTreePoly poly( corners );
   CHECK( poly.is_valid() );
@@ -106,12 +108,12 @@
     // check that a plane entirely above the 
     // polyhedron (coincident with one face)
     // doesn't modify the polyhedron
-  bool r = poly.cut_polyhedron( MBCartVect(0,0,1), -2 );
+  bool r = poly.cut_polyhedron( CartVect(0,0,1), -2 );
   CHECK(!r);
   CHECK( poly.is_valid() );
   
     // cut in half with Z=1 plane
-  r = poly.cut_polyhedron( MBCartVect(0,0,1), -1 );
+  r = poly.cut_polyhedron( CartVect(0,0,1), -1 );
   CHECK(r);
   CHECK( poly.is_valid() );
   for (int i = 0; i < 8; ++i) {
@@ -139,7 +141,7 @@
   CHECK( poly.is_valid() );
   
     // cut off two corners using X=5 plane
-  r = poly.cut_polyhedron( MBCartVect(1,0,0), -5 );
+  r = poly.cut_polyhedron( CartVect(1,0,0), -5 );
   CHECK(r);
   CHECK( poly.is_valid() );
   
@@ -147,16 +149,16 @@
   poly.get_faces( faces );
   CHECK_EQUAL( (size_t)7, faces.size() );
   
-  MBCartVect new_vtx1( 5, 1, 1 );
-  MBCartVect new_vtx2( 5, 1, 0 );
-  MBCartVect new_vtx3( 5, 3, 0 );
-  MBCartVect new_vtx4( 5, 3, 1 );
+  CartVect new_vtx1( 5, 1, 1 );
+  CartVect new_vtx2( 5, 1, 0 );
+  CartVect new_vtx3( 5, 3, 0 );
+  CartVect new_vtx4( 5, 3, 1 );
   
-  MBCartVect face1[5] = { corners[0], new_vtx2, new_vtx1, corners[5], corners[4] };
-  MBCartVect face2[4] = { new_vtx1, new_vtx4, corners[6], corners[5] };
-  MBCartVect face3[5] = { new_vtx4, new_vtx3, corners[3], corners[7], corners[6] };
-  MBCartVect face5[4] = { corners[3], new_vtx3, new_vtx2, corners[0] };
-  MBCartVect face7[4] = { new_vtx1, new_vtx2, new_vtx3, new_vtx4 };
+  CartVect face1[5] = { corners[0], new_vtx2, new_vtx1, corners[5], corners[4] };
+  CartVect face2[4] = { new_vtx1, new_vtx4, corners[6], corners[5] };
+  CartVect face3[5] = { new_vtx4, new_vtx3, corners[3], corners[7], corners[6] };
+  CartVect face5[4] = { corners[3], new_vtx3, new_vtx2, corners[0] };
+  CartVect face7[4] = { new_vtx1, new_vtx2, new_vtx3, new_vtx4 };
   
   CHECK( 0 != find_face( poly, face1, 5 ) );
   CHECK( 0 != find_face( poly, face2, 4 ) );
@@ -169,7 +171,7 @@
 
 void test_volume()
 {
-  MBCartVect corners[8];
+  CartVect corners[8];
   get_corners( corners );
   BSPTreePoly poly( corners );
   CHECK( poly.is_valid() );

Modified: MOAB/trunk/test/bsp_tree_test.cpp
===================================================================
--- MOAB/trunk/test/bsp_tree_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/bsp_tree_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,11 +1,13 @@
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "TestUtil.hpp"
-#include "MBBSPTree.hpp"
-#include "MBCartVect.hpp"
-#include "BSPTreePoly.hpp"
-#include "MBRange.hpp"
+#include "moab/BSPTree.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/BSPTreePoly.hpp"
+#include "moab/Range.hpp"
 #include <algorithm>
 
+using namespace moab;
+
 void test_set_plane();
 void test_iterator();
 void test_box_iterator();
@@ -51,8 +53,8 @@
 
 
 // Make CHECK_EQUAL macro work for planes
-void check_equal( const MBBSPTree::Plane& p1, 
-                  const MBBSPTree::Plane& p2,
+void check_equal( const BSPTree::Plane& p1, 
+                  const BSPTree::Plane& p2,
                   const char* exp1, 
                   const char* exp2,
                   int line,
@@ -75,7 +77,7 @@
 
 void test_set_plane()
 {
-  MBBSPTree::Plane p;
+  BSPTree::Plane p;
   const double points[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
   p.set( points[0], points[1], points[2] );
   CHECK_REAL_EQUAL( 0.0, p.distance( points[0] ), 1e-10 );
@@ -85,11 +87,11 @@
 
 void test_iterator()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeIter iter;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeIter iter;
     
     // create a depth-1 tree
   rval = tool.create_tree( root );
@@ -103,7 +105,7 @@
   CHECK_EQUAL(  1u,   iter.depth() );
   
     // should fail if at root
-  MBBSPTree::Plane p;
+  BSPTree::Plane p;
   rval = iter.get_parent_split_plane( p );
   CHECK_EQUAL( MB_ENTITY_NOT_FOUND, rval );
   
@@ -124,7 +126,7 @@
   CHECK_ERR(rval);
   
     // insert a single split plane
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(2,0,0,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(2,0,0,0) );
   CHECK_ERR(rval);
   
     // check initial location
@@ -132,7 +134,7 @@
   CHECK( iter.handle() != root );
   
     // create new iterators at left and right ends
-  MBBSPTreeIter left, right;
+  BSPTreeIter left, right;
   rval = tool.get_tree_iterator( root, left );
   CHECK_ERR(rval);
   rval = tool.get_tree_end_iterator( root, right );
@@ -165,10 +167,10 @@
     // check plane
     // should have unit normal
   left.get_parent_split_plane( p );
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,0), p );
   p.norm[0] = 11;
   right.get_parent_split_plane( p );
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,0), p );
   
     // check step past ends
   rval = left.back();
@@ -245,11 +247,11 @@
 
 void test_box_iterator()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter iter;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter iter;
   const double min[3] = { -1, -2, -3 };
   const double max[3] = {  3,  2,  1 };
     
@@ -272,7 +274,7 @@
   CHECK( compare_hexes( expt, corners, 1e-6 ) );
   
     // should fail if at root
-  MBBSPTree::Plane p;
+  BSPTree::Plane p;
   rval = iter.get_parent_split_plane( p );
   CHECK_EQUAL( MB_ENTITY_NOT_FOUND, rval );
   
@@ -293,7 +295,7 @@
   CHECK_ERR(rval);
   
     // insert a single split plane
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(2,0,0,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(2,0,0,0) );
   CHECK_ERR(rval);
   
     // check initial location
@@ -301,7 +303,7 @@
   CHECK( iter.handle() != root );
   
     // create new iterators at left and right ends
-  MBBSPTreeIter left, right;
+  BSPTreeIter left, right;
   rval = tool.get_tree_iterator( root, left );
   CHECK_ERR(rval);
   rval = tool.get_tree_end_iterator( root, right );
@@ -361,10 +363,10 @@
     // check plane
     // should have unit normal
   left.get_parent_split_plane( p );
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,0), p );
   p.norm[0] = 11;
   right.get_parent_split_plane( p );
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,0), p );
   
     // check step past ends
   rval = left.back();
@@ -375,12 +377,12 @@
 
 void test_tree_create()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeIter iter;
-  MBBSPTree::Plane p;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeIter iter;
+  BSPTree::Plane p;
     
     // create a depth-1 tree
   rval = tool.create_tree( root );
@@ -394,17 +396,17 @@
   CHECK_EQUAL(  1u,   iter.depth() );
 
     // split with z=0
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,0,0.5,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,0,0.5,0) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 2u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,0,1,0), p );
+  CHECK_EQUAL( BSPTree::Plane(0,0,1,0), p );
 
     // split lower leaf with diagonal plane
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(1,1,0,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(1,1,0,0) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 3u, iter.depth() );
   
@@ -413,21 +415,21 @@
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(r,r,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(r,r,0,0), p );
   
     // step to upper leaf
   rval = iter.step();
   CHECK_ERR(rval);
   
     // split upper leaf with diagonal plane
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,1,0,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,1,0,0) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 4u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(-r,r,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(-r,r,0,0), p );
   
     // iterate over four leaves
   
@@ -437,7 +439,7 @@
   CHECK_EQUAL( 3u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(r,r,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(r,r,0,0), p );
   
     // second leaf
   rval = iter.step();
@@ -445,7 +447,7 @@
   CHECK_EQUAL( 4u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(-r,r,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(-r,r,0,0), p );
    
     // third leaf
   rval = iter.step();
@@ -453,7 +455,7 @@
   CHECK_EQUAL( 4u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(-r,r,0,0), p );
+  CHECK_EQUAL( BSPTree::Plane(-r,r,0,0), p );
    
     // fourth leaf
   rval = iter.step();
@@ -461,7 +463,7 @@
   CHECK_EQUAL( 2u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,0,1,0), p );
+  CHECK_EQUAL( BSPTree::Plane(0,0,1,0), p );
  
     // no more leaves
   rval = iter.step();
@@ -470,12 +472,12 @@
 
 void test_box_tree_create()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter iter;
-  MBBSPTree::Plane p;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter iter;
+  BSPTree::Plane p;
   const double min[3] = { -2, -2, -2 };
   const double max[3] = {  2,  2,  2 };
     
@@ -500,95 +502,95 @@
  
     // Try splits that should fail because they
     // do not intersect the leaf at all
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,0,1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,0,1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,0,1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,0,1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,1,0, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,1,0, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,1,0,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,1,0,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(1,0,0, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(1,0,0, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(1,0,0,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(1,0,0,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1,-1, 7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1,-1, 7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1,-1,-7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1,-1,-7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1,-1, 7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1,-1, 7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1,-1,-7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1,-1,-7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1,-1, 7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1,-1, 7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1,-1,-7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1,-1,-7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1,-1, 7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1,-1, 7) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1,-1,-7) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1,-1,-7) );
   CHECK_EQUAL( MB_FAILURE, rval );
   
  
     // Try a split that should fail because the
     // resulting leaf would not be a hexahedron.
     // Clip each corner twice using planes with opposing normals
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1,-1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1,-1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1, 1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1,-1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1,-1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1, 1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1, 1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1,-1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1,-1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1, 1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1, 1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1,-1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1,-1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1, 1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1, 1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1, 1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1, 1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1,-1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1,-1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1, 1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1, 1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1,-1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1,-1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1, 1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1,-1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1,-1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1, 1,-4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1, 1,-4) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1,-1, 4) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1,-1, 4) );
   CHECK_EQUAL( MB_FAILURE, rval );
     // Clip each edge
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1,-1, 0,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1,-1, 0,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1,-1, 0,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1,-1, 0,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 1, 0,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 1, 0,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 1, 0,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 1, 0,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 0,-1,-1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 0,-1,-1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 0, 1,-1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1,-1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 0, 1, 1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 0, 1, 1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 0,-1, 1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 0,-1, 1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 0,-1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 0,-1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 0,-1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0,-1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane( 1, 0, 1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane( 1, 0, 1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-1, 0, 1,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-1, 0, 1,-2) );
   CHECK_EQUAL( MB_FAILURE, rval );
  
     // verify that iterator is still valid after many failed splits
@@ -601,14 +603,14 @@
 
 
     // split with z=0
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,0,0.5,0) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,0,0.5,0) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 2u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,0,1,0), p );
+  CHECK_EQUAL( BSPTree::Plane(0,0,1,0), p );
   
     // check that box corners are correct
   aabox_corners( min, max, expt );
@@ -621,7 +623,7 @@
 
   
     // split with z=-1 and normal in opposite direction
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,0,-2,-2) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,0,-2,-2) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 3u, iter.depth() );
   for (unsigned i = 0; i < 8; ++i)
@@ -645,14 +647,14 @@
 
     
     // split at x = -1
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(-0.1,0,0,-0.1) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(-0.1,0,0,-0.1) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 4u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(-1,0,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(-1,0,0,-1), p );
   
     // check that leaf box is correct
   aabox_corners( -1, -2, -2, 2, 2, -1, expt );
@@ -662,14 +664,14 @@
 
 
     // split at x = 1
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(5,0,0,-5) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(5,0,0,-5) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 5u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,-1), p );
   
     // check that leaf box is correct
   aabox_corners( -1, -2, -2, 1, 2, -1, expt );
@@ -679,14 +681,14 @@
 
     
     // split at y = -1
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,-1,0,-1) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,-1,0,-1) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 6u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,-1,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,-1,0,-1), p );
   
     // check that leaf box is correct
   aabox_corners( -1, -1, -2, 1, 2, -1, expt );
@@ -696,14 +698,14 @@
 
 
     // split at y = 1
-  rval = tool.split_leaf( iter, MBBSPTree::Plane(0,1,0,-1) );
+  rval = tool.split_leaf( iter, BSPTree::Plane(0,1,0,-1) );
   CHECK_ERR(rval);
   CHECK_EQUAL( 7u, iter.depth() );
   
     // check that parent split plane is correct
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,1,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,1,0,-1), p );
   
     // check that leaf box is correct
   aabox_corners( -1, -1, -2, 1, 1, -1, expt );
@@ -719,7 +721,7 @@
   CHECK_EQUAL( 3u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,0,-1,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,0,-1,-1), p );
   aabox_corners( -2, -2, -1, 2, 2, 0, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -730,7 +732,7 @@
   CHECK_EQUAL( 7u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,1,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,1,0,-1), p );
   aabox_corners( -1, -1, -2, 1, 1, -1, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -741,7 +743,7 @@
   CHECK_EQUAL( 7u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,1,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,1,0,-1), p );
   aabox_corners( -1, 1, -2, 1, 2, -1, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -752,7 +754,7 @@
   CHECK_EQUAL( 6u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,-1,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(0,-1,0,-1), p );
   aabox_corners( -1, -2, -2, 1, -1, -1, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -763,7 +765,7 @@
   CHECK_EQUAL( 5u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(1,0,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(1,0,0,-1), p );
   aabox_corners( 1, -2, -2, 2, 2, -1, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -774,7 +776,7 @@
   CHECK_EQUAL( 4u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(-1,0,0,-1), p );
+  CHECK_EQUAL( BSPTree::Plane(-1,0,0,-1), p );
   aabox_corners( -2, -2, -2, -1, 2, -1, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -785,7 +787,7 @@
   CHECK_EQUAL( 2u, iter.depth() );
   rval = iter.get_parent_split_plane( p );
   CHECK_ERR(rval);
-  CHECK_EQUAL( MBBSPTree::Plane(0,0,1,0), p );
+  CHECK_EQUAL( BSPTree::Plane(0,0,1,0), p );
   aabox_corners( -2, -2, 0, 2, 2, 2, expt );
   rval = iter.get_box_corners( corners );
   CHECK_ERR( rval );
@@ -798,14 +800,14 @@
 
 void test_leaf_containing_point_bounded_tree()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeIter iter;
-  MBBSPTreeBoxIter b_iter;
-  MBBSPTree::Plane p;
-  MBEntityHandle h;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeIter iter;
+  BSPTreeBoxIter b_iter;
+  BSPTree::Plane p;
+  EntityHandle h;
   double expected[8][3], corners[8][3];
 
 
@@ -824,9 +826,9 @@
   0.0 +---------+--------------+
       0.0       0.4            1.0  */
 
-  const MBBSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
-  const MBBSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
-  const MBBSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
+  const BSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
+  const BSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
+  const BSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
   
   
   const double min[3] = { 0, 0, 0 };
@@ -841,21 +843,21 @@
   
   rval = tool.split_leaf( iter, AB_split );
   CHECK_ERR(rval);
-  const MBEntityHandle A = iter.handle();
+  const EntityHandle A = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
-  const MBEntityHandle B = iter.handle();
+  const EntityHandle B = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
   rval = tool.split_leaf( iter, CD_split );
   CHECK_ERR(rval);
-  const MBEntityHandle C = iter.handle();
+  const EntityHandle C = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
-  const MBEntityHandle D = iter.handle();
+  const EntityHandle D = iter.handle();
 
   
     // Test queries inside tree
@@ -946,13 +948,13 @@
 
 void test_leaf_containing_point_unbounded_tree()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeIter iter;
-  MBBSPTree::Plane p;
-  MBEntityHandle h;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeIter iter;
+  BSPTree::Plane p;
+  EntityHandle h;
 
 
 /*  Build Tree
@@ -971,9 +973,9 @@
                o (1,-2,0)
                 \
  */
-  const MBBSPTree::Plane  X_split( 2.0, 1.0, 0.0, 0.0);
-  const MBBSPTree::Plane AB_split( 0.0, 1.0, 0.0, 0.0);
-  const MBBSPTree::Plane CD_split( 1.0, 0.0, 0.0, 0.0);
+  const BSPTree::Plane  X_split( 2.0, 1.0, 0.0, 0.0);
+  const BSPTree::Plane AB_split( 0.0, 1.0, 0.0, 0.0);
+  const BSPTree::Plane CD_split( 1.0, 0.0, 0.0, 0.0);
   
   
   rval = tool.create_tree( root );
@@ -986,21 +988,21 @@
   
   rval = tool.split_leaf( iter, AB_split );
   CHECK_ERR(rval);
-  const MBEntityHandle A = iter.handle();
+  const EntityHandle A = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
-  const MBEntityHandle B = iter.handle();
+  const EntityHandle B = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
   rval = tool.split_leaf( iter, CD_split );
   CHECK_ERR(rval);
-  const MBEntityHandle C = iter.handle();
+  const EntityHandle C = iter.handle();
   
   rval = iter.step();
   CHECK_ERR(rval);
-  const MBEntityHandle D = iter.handle();
+  const EntityHandle D = iter.handle();
 
   
     // Test queries inside tree
@@ -1052,12 +1054,12 @@
 
 void test_merge_leaf()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter iter;
-  MBBSPTree::Plane p;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter iter;
+  BSPTree::Plane p;
   double expected[8][3], corners[8][3];
 
 
@@ -1076,9 +1078,9 @@
   0.0 +---------+--------------+
       0.0       0.4            1.0  */
 
-  const MBBSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
-  const MBBSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
-  const MBBSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
+  const BSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
+  const BSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
+  const BSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
   
   const double min[3] = { 0, 0, 0 };
   const double max[3] = { 1, 1, 1 };
@@ -1088,14 +1090,14 @@
   CHECK_ERR(rval);
   rval = tool.split_leaf( iter, X_split );
   CHECK_ERR(rval);
-  const MBEntityHandle AB = iter.handle();
+  const EntityHandle AB = iter.handle();
   rval = tool.split_leaf( iter, AB_split );
   CHECK_ERR(rval);
   rval = iter.step();
   CHECK_ERR(rval);
   rval = iter.step();
   CHECK_ERR(rval);
-  const MBEntityHandle CD = iter.handle();
+  const EntityHandle CD = iter.handle();
   rval = tool.split_leaf( iter, CD_split );
   CHECK_ERR(rval);
   rval = iter.step();
@@ -1136,13 +1138,13 @@
 }
 
 static std::vector<int>
-neighbors( const MBBSPTreeBoxIter& iter, 
-           const MBEntityHandle leaves[8], 
-           MBBSPTreeBoxIter::SideBits side, 
+neighbors( const BSPTreeBoxIter& iter, 
+           const EntityHandle leaves[8], 
+           BSPTreeBoxIter::SideBits side, 
            double epsilon ) 
 {
-  std::vector<MBBSPTreeBoxIter> list;
-  MBErrorCode rval = iter.get_neighbors( side, list, epsilon );
+  std::vector<BSPTreeBoxIter> list;
+  ErrorCode rval = iter.get_neighbors( side, list, epsilon );
   CHECK_ERR(rval);
   
   std::vector<int> results;
@@ -1154,12 +1156,12 @@
 
 void test_box_iter_neighbors()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter iter;
-  MBBSPTree::Plane p;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter iter;
+  BSPTree::Plane p;
 
 
 /*  Build Tree */
@@ -1177,7 +1179,7 @@
   CHECK_ERR(rval);
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
-  MBEntityHandle leaves[8];
+  EntityHandle leaves[8];
   
   /* +----------------------------------------+
      |                                        |
@@ -1185,7 +1187,7 @@
      |                                        |
      +----------------------------------------+ */
   
-  p = MBBSPTree::Plane( 1, 0, 0, -4 );
+  p = BSPTree::Plane( 1, 0, 0, -4 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
   
@@ -1195,7 +1197,7 @@
      |                   |                    |
      +----------------------------------------+ */
   
-  p = MBBSPTree::Plane( -1, 0, 0, 2 );
+  p = BSPTree::Plane( -1, 0, 0, 2 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1205,7 +1207,7 @@
      |         |         |                    |
      +----------------------------------------+ */
  
-  p = MBBSPTree::Plane( 0, 1, 0, -1 );
+  p = BSPTree::Plane( 0, 1, 0, -1 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1226,7 +1228,7 @@
      |         |    0    |                    |
      +----------------------------------------+ */
  
-  p = MBBSPTree::Plane( 0, -1, 0, 1 );
+  p = BSPTree::Plane( 0, -1, 0, 1 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1247,7 +1249,7 @@
      |    3    |    0    |                    |
      +----------------------------------------+ */
 
-  p = MBBSPTree::Plane( 0, 1, 0, -1 );
+  p = BSPTree::Plane( 0, 1, 0, -1 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1257,7 +1259,7 @@
      |    3    |    0    |         4*         |
      +----------------------------------------+ */
 
-  p = MBBSPTree::Plane( 1, 0, 0, -6 );
+  p = BSPTree::Plane( 1, 0, 0, -6 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1278,7 +1280,7 @@
      |    3    |    0    |     4    |    5    |
      +------------------------------+---------+ */
 
-  p = MBBSPTree::Plane( -1, 0, 0, 6 );
+  p = BSPTree::Plane( -1, 0, 0, 6 );
   rval = tool.split_leaf( iter, p );
   CHECK_ERR(rval);
    
@@ -1314,41 +1316,41 @@
   std::vector<int> expected;
   CHECK_EQUAL( leaves[0], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 3 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   expected.insert( expected.begin(), 2 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
   // See NOTE //  expected.push_back( 2 ); expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376,  1e-6 ) );
   expected.clear(); expected.push_back( 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
   
     // check neighbors of leaf 1
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[1], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 2 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   expected.push_back( 3 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
   // See NOTE //  expected.push_back( 3 ); expected.push_back( 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154,  1e-6 ) );
   expected.clear(); expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   expected.insert( expected.begin(), 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
     
   /* +---------+---------+--------------------+
      |    2    |    1    |     7    |    6    |
@@ -1360,35 +1362,35 @@
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[2], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 3 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
   // See NOTE // expected.insert( expected.begin(), 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154,  1e-6 ) );
   expected.clear(); expected.push_back( 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   expected.insert( expected.begin(), 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
 
     // check neighbors of leaf 3
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[3], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 2 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
   // See NOTE // expected.insert( expected.begin(), 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376,  1e-6 ) );
   expected.clear(); expected.push_back( 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   expected.push_back( 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
     
   /* +---------+---------+--------------------+
      |    2    |    1    |     7    |    6    |
@@ -1400,39 +1402,39 @@
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[4], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   expected.push_back( 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
   expected.insert( expected.begin(), 6 ); 
   // See NOTE // expected.insert( expected.begin(), 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376,  1e-6 ) );
   expected.clear(); expected.push_back( 5 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   // See NOTE // expected.push_back( 6 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
 
     // check neighbors of leaf 5
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[5], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   // See NOTE // expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 6 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, -1e-6 ) );
   expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376,  1e-6 ) );
     
   /* +---------+---------+--------------------+
      |    2    |    1    |     7    |    6    |
@@ -1444,49 +1446,49 @@
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[6], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 7 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   // See NOTE // expected.insert( expected.begin(), 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 5 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
   expected.insert( expected.begin(), 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154,  1e-6 ) );
 
     // check neighbors of leaf 7
   CHECK_ERR( iter.step() );
   CHECK_EQUAL( leaves[7], iter.handle() );
   expected.clear(); 
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B2376, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3210, 1e-6 ) );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B4567, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B2376, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3210, 1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B4567, 1e-6 ) );
   expected.push_back( 1 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047, -1e-6 ) );
   expected.insert( expected.begin(), 0 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B3047,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B3047,  1e-6 ) );
   expected.clear(); expected.push_back( 4 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154, -1e-6 ) );
   // See NOTE // expected.insert( expected.begin(), 0 ); 
   expected.push_back( 5 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B0154,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B0154,  1e-6 ) );
   expected.clear(); expected.push_back( 6 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265, -1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265, -1e-6 ) );
   // See NOTE // expected.insert( expected.begin(), 5 );
-  CHECK_EQUAL( expected, neighbors( iter, leaves, MBBSPTreeBoxIter::B1265,  1e-6 ) );
+  CHECK_EQUAL( expected, neighbors( iter, leaves, BSPTreeBoxIter::B1265,  1e-6 ) );
 }
 
 
 void test_leaf_sibling()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeIter iter;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeIter iter;
 
 
 /*  Build Tree
@@ -1504,9 +1506,9 @@
   0.0 +---------+--------------+
       0.0       0.4            1.0  */
 
-  const MBBSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
-  const MBBSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
-  const MBBSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
+  const BSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
+  const BSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
+  const BSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
   
   const double min[3] = { 0, 0, 0 };
   const double max[3] = { 1, 1, 1 };
@@ -1526,7 +1528,7 @@
   CHECK_ERR(rval);
   
     // create two iterators for testing
-  MBBSPTreeIter iter1, iter2;
+  BSPTreeIter iter1, iter2;
   rval = tool.get_tree_iterator( root, iter1 );
   CHECK_ERR(rval);
   rval = tool.get_tree_iterator( root, iter2 );
@@ -1581,13 +1583,13 @@
 
 void test_leaf_volume( bool box )
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter b_iter;
-  MBBSPTreeIter g_iter;
-  MBBSPTreeIter& iter = box ? b_iter : g_iter;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter b_iter;
+  BSPTreeIter g_iter;
+  BSPTreeIter& iter = box ? b_iter : g_iter;
 
 
 /*  Build Tree
@@ -1605,9 +1607,9 @@
   0.0 +---------+--------------+
       0.0       0.4            1.0  */
 
-  const MBBSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
-  const MBBSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
-  const MBBSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
+  const BSPTree::Plane  X_split(1.0, 0.0, 0.0,-0.4);
+  const BSPTree::Plane AB_split(0.0,-1.0, 0.0, 0.7);
+  const BSPTree::Plane CD_split(0.0,-1.0, 0.0, 0.3);
   
   const double min[3] = { 0, 0, 0 };
   const double max[3] = { 1, 1, 1 };
@@ -1642,12 +1644,12 @@
   
 void test_leaf_splits_intersects()
 {
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBErrorCode rval;
-  MBEntityHandle root;
-  MBBSPTreeBoxIter iter;
-  MBBSPTree::Plane p;
+  Core moab;
+  BSPTree tool( &moab );
+  ErrorCode rval;
+  EntityHandle root;
+  BSPTreeBoxIter iter;
+  BSPTree::Plane p;
   
   const double min[3] = { 0, 0, 0 };
   const double max[3] = { 1, 2, 3 };
@@ -1657,62 +1659,62 @@
   CHECK_ERR(rval);
   
   p.set( 1, 0, 0, 1 ); // x == -1
-  CHECK_EQUAL( MBBSPTreeBoxIter::MISS, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
   CHECK( !iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::MISS, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
   CHECK( !iter.intersects( p ) );
   
   p.set( 1, 0, 0, 0 ); // x == 0
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
  
   p.set( 1, 0, 0, -0.5 ); // x == 0.5
-  CHECK_EQUAL( MBBSPTreeBoxIter::SPLIT, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::SPLIT, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   
   p.set( 1, 0, 0, -1 ); // x == 1
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
  
   p.set( 1, 0, 0, -2 ); // x == 2
-  CHECK_EQUAL( MBBSPTreeBoxIter::MISS, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
   CHECK( !iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::MISS, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::MISS, iter.splits( p ) );
   CHECK( !iter.intersects( p ) );
   
   double pt1[3] = { 0, 0, 1.5 };
   double pt2[3] = { 1, 0, 1.5 };
   double pt3[3] = { 0, 1, 3.0 };
   p.set( pt1, pt2, pt3 );
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   
   double pt4[3] = { 0, 2, 2.8 };
   p.set( pt1, pt2, pt4 );
-  CHECK_EQUAL( MBBSPTreeBoxIter::SPLIT, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::SPLIT, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::SPLIT, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   
   double pta[3] = { 0.8, 0, 0 };
   double ptb[3] = { 0, 0.2, 3 };
   double ptc[3] = { 0.8, 2, 3 };
   p.set( pta, ptb, ptc );
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
   p.flip();
-  CHECK_EQUAL( MBBSPTreeBoxIter::NONHEX, iter.splits( p ) );
+  CHECK_EQUAL( BSPTreeBoxIter::NONHEX, iter.splits( p ) );
   CHECK( iter.intersects( p ) );
 }
   
@@ -1724,9 +1726,9 @@
     
 void test_leaf_intersects_ray_common( bool box )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBBSPTree tool( &moab );
+  ErrorCode rval;
+  Core moab;
+  BSPTree tool( &moab );
   double t_in, t_out;
   
   /** Start with only root box for initial testing **/
@@ -1747,7 +1749,7 @@
          o--------------------o
   (1,1,-1)                    (6,1,-1)
   */
-  MBEntityHandle root;
+  EntityHandle root;
   const double corners[][3] = { { 1, 1, -3 },
                                 { 6, 1, -3 },
                                 { 2, 5, -3 },
@@ -1759,9 +1761,9 @@
   rval = tool.create_tree( corners, root );
   CHECK_ERR(rval);
   
-  MBBSPTreeIter gen_iter;
-  MBBSPTreeBoxIter box_iter;
-  MBBSPTreeIter& iter = box ? static_cast<MBBSPTreeIter&>(box_iter) : gen_iter;
+  BSPTreeIter gen_iter;
+  BSPTreeBoxIter box_iter;
+  BSPTreeIter& iter = box ? static_cast<BSPTreeIter&>(box_iter) : gen_iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   
@@ -1815,10 +1817,10 @@
 
   /** Now split twice and test the bottom right corne **/
   
-  MBBSPTree::Plane Y3( MBBSPTree::Y, 3.0 );
+  BSPTree::Plane Y3( BSPTree::Y, 3.0 );
   rval = tool.split_leaf( iter, Y3 );
   CHECK_ERR(rval);
-  MBBSPTree::Plane X2( MBBSPTree::X, 2.0 );
+  BSPTree::Plane X2( BSPTree::X, 2.0 );
   rval = tool.split_leaf( iter, X2 );
   CHECK_ERR(rval);
   rval = iter.step();
@@ -1896,11 +1898,11 @@
   }
 }
 
-static MBEntityHandle build_tree( const double points[], int num_points, MBBSPTree& tool )
+static EntityHandle build_tree( const double points[], int num_points, BSPTree& tool )
 {
     // create points
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> pts(num_points);
+  ErrorCode rval;
+  std::vector<EntityHandle> pts(num_points);
   for (int i = 0; i < num_points; ++i) {
     rval = tool.moab()->create_vertex( points + 3*i, pts[i] );
     CHECK_ERR(rval);
@@ -1911,11 +1913,11 @@
   box( points, num_points, minpt, maxpt );
   
     // create initial (1-node) tree
-  MBEntityHandle root;
+  EntityHandle root;
   rval = tool.create_tree( minpt, maxpt, root );
   CHECK_ERR(rval);
   
-  MBBSPTreeIter iter;
+  BSPTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   
@@ -1923,8 +1925,8 @@
   CHECK_ERR(rval);
   
     // build tree
-  std::vector<MBEntityHandle> left_pts, right_pts;
-  std::vector<MBCartVect> coords(num_points), tmp_coords;
+  std::vector<EntityHandle> left_pts, right_pts;
+  std::vector<CartVect> coords(num_points), tmp_coords;
   std::vector<double> coeffs;
   for (; MB_SUCCESS == rval; rval = iter.step()) {
     pts.clear();
@@ -1937,21 +1939,21 @@
       CHECK_ERR(rval);
       
         // find two points far apart apart
-      std::vector<MBCartVect>* ptr;
+      std::vector<CartVect>* ptr;
       if (coords.size() < 10) 
         ptr = &coords;
       else {
         tmp_coords.resize(16);
-        MBCartVect pn, px;
+        CartVect pn, px;
         box( coords[0].array(), coords.size(), pn.array(), px.array() );
         tmp_coords[8] = pn;
-        tmp_coords[9] = MBCartVect( px[0], pn[1], pn[2] );
-        tmp_coords[10] = MBCartVect( px[0], px[1], pn[2] );
-        tmp_coords[11] = MBCartVect( pn[0], px[1], pn[2] );
-        tmp_coords[12] = MBCartVect( pn[0], pn[1], px[2] );
-        tmp_coords[13] = MBCartVect( px[0], pn[1], px[2] );
+        tmp_coords[9] = CartVect( px[0], pn[1], pn[2] );
+        tmp_coords[10] = CartVect( px[0], px[1], pn[2] );
+        tmp_coords[11] = CartVect( pn[0], px[1], pn[2] );
+        tmp_coords[12] = CartVect( pn[0], pn[1], px[2] );
+        tmp_coords[13] = CartVect( px[0], pn[1], px[2] );
         tmp_coords[14] = px;
-        tmp_coords[15] = MBCartVect( pn[0], px[1], px[2] );
+        tmp_coords[15] = CartVect( pn[0], px[1], px[2] );
         for (int i = 0; i < 8; ++i) {
           tmp_coords[i] = coords[0];
           for (size_t j = 1; j < coords.size(); ++j)
@@ -1981,7 +1983,7 @@
         break;
         
         // define normal orthogonal to line through two points
-      MBCartVect norm = (*ptr)[pt1] - (*ptr)[pt2];
+      CartVect norm = (*ptr)[pt1] - (*ptr)[pt2];
       norm.normalize();
       
         // find mean position for plane
@@ -2001,7 +2003,7 @@
           right_pts.push_back( pts[i] );
       }
       
-      rval = tool.split_leaf( iter, MBBSPTree::Plane( norm.array(), coeff ), left_pts, right_pts );
+      rval = tool.split_leaf( iter, BSPTree::Plane( norm.array(), coeff ), left_pts, right_pts );
       CHECK_ERR(rval);
       CHECK( !left_pts.empty() && !right_pts.empty() );
       pts.swap( left_pts );
@@ -2019,16 +2021,16 @@
   
     // verify that tree is constructed correctly
   for (int i = 0; i < num_points; ++i) {
-    MBCartVect pt( points + 3*i );
-    MBEntityHandle leaf;
+    CartVect pt( points + 3*i );
+    EntityHandle leaf;
     rval = tool.leaf_containing_point( root, pt.array(), leaf );
     CHECK_ERR(rval);
-    MBRange ents;
+    Range ents;
     rval = tool.moab()->get_entities_by_handle( leaf, ents );
     CHECK_ERR(rval);
     bool found = false;
-    for (MBRange::iterator j = ents.begin(); j != ents.end(); ++j) {
-      MBCartVect ent_coords;
+    for (Range::iterator j = ents.begin(); j != ents.end(); ++j) {
+      CartVect ent_coords;
       rval = tool.moab()->get_coords( &*j, 1, ent_coords.array() );
       CHECK_ERR(rval);
       if ((pt - ent_coords).length_squared() < 1e-6)
@@ -2067,17 +2069,17 @@
        1, 6, 0};
   const int num_pts = sizeof(points)/(3*sizeof(double));
 
-  MBErrorCode rval;
-  MBCore moab;
-  MBBSPTree tool( &moab );
-  MBEntityHandle root = build_tree( points, num_pts, tool );
+  ErrorCode rval;
+  Core moab;
+  BSPTree tool( &moab );
+  EntityHandle root = build_tree( points, num_pts, tool );
   
-  MBBSPTreeIter iter;
+  BSPTreeIter iter;
   rval = tool.get_tree_iterator( root, iter );
   CHECK_ERR(rval);
   
-  std::vector<MBEntityHandle> pts;
-  std::vector<MBCartVect> coords;
+  std::vector<EntityHandle> pts;
+  std::vector<CartVect> coords;
   
   for (; rval == MB_SUCCESS; rval = iter.step()) {
     BSPTreePoly poly;

Modified: MOAB/trunk/test/dual/Makefile.am
===================================================================
--- MOAB/trunk/test/dual/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/dual/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,5 @@
 
-AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab
+AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src 
 check_PROGRAMS = dual_test
 dual_test_SOURCES = dual_test.cpp
 LDADD = $(top_builddir)/src/libMOAB.la

Modified: MOAB/trunk/test/dual/dual_test.cpp
===================================================================
--- MOAB/trunk/test/dual/dual_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/dual/dual_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,14 +1,16 @@
 // tests dual construction code
  
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MeshTopoUtil.hpp"
-#include "DualTool.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/DualTool.hpp"
 #include <iostream>
 #include <string>
 
-MBInterface *gMB;
+using namespace moab;
 
+Interface *gMB;
+
 int main(int argc, char* argv[])
 {
   if (argc <= 1)
@@ -17,17 +19,17 @@
     return 0;
   }
 
-  gMB = new MBCore();
+  gMB = new Core();
 
     // read the mesh file
-  MBErrorCode result = gMB->load_mesh(argv[1]);
+  ErrorCode result = gMB->load_mesh(argv[1]);
   if (MB_SUCCESS != result) {
     std::cout << "Problems reading file " << argv[1] << "." << std::endl;
     return 0;
   }
 
     // make sure aentities are created
-  MBRange all_verts;
+  Range all_verts;
   result = gMB->get_entities_by_dimension(0, 0, all_verts);
   if (MB_SUCCESS != result) 
     std::cout << "Problem getting vertices." << std::endl;
@@ -63,7 +65,7 @@
   }
   
     // print information about the dual
-  MBRange dual_cells, dual_faces;
+  Range dual_cells, dual_faces;
   result = dt.get_dual_entities(0,0, 2, dual_faces);
   if (MB_SUCCESS != result)
     std::cout << "Problem getting dual faces." << std::endl;
@@ -79,8 +81,8 @@
               << std::endl;
 
     // print information about dual hyperplanes, if any
-  MBTag hp_tag;
-  MBRange hp_sets;
+  Tag hp_tag;
+  Range hp_sets;
   if (num_2d == num_quad) {
       // get sets with the right tag
     result = gMB->tag_get_handle(DualTool::DUAL_CURVE_TAG_NAME, hp_tag);

Modified: MOAB/trunk/test/h5file/Makefile.am
===================================================================
--- MOAB/trunk/test/h5file/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -7,11 +7,7 @@
                -I$(top_srcdir)/src/io/mhdf/include \
                -I$(top_builddir)/src \
                -I$(top_srcdir)/src/parallel \
-	       -I$(top_builddir)/src/parallel \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/parallel/moab \
-	       -I$(top_builddir)/src/parallel/moab
+	       -I$(top_builddir)/src/parallel 
             
 check_PROGRAMS = h5test h5legacy h5varlen h5sets_test h5regression h5partial
 

Modified: MOAB/trunk/test/h5file/h5file_test.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5file_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5file_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,13 +16,15 @@
 #include <stdio.h>
 #include <math.h>
 
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 
 #define filename "h5test.h5m"
 
+using namespace moab;
+
 // Dense tag name
 // Pick an ugly name to check special-char escaping in HDF5 file
 #define tagname "foo/\\/\\"
@@ -38,7 +40,7 @@
 const int SET_SET_ID    = 1105;
 
 
-MBInterface* iface;
+Interface* iface;
 
 void create();
 
@@ -48,10 +50,10 @@
 
 int main()
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   std::string msg;
   
-  iface = new MBCore();
+  iface = new Core();
   
   // create a dodecahedron and inscribed hex
   fprintf( stderr, "creating... " );
@@ -137,23 +139,23 @@
   return 0;
 }
 
-MBEntityHandle vtx( double x, double y, double z )
+EntityHandle vtx( double x, double y, double z )
 {
   const double p[3] = { x, y, z };
-  MBEntityHandle result;
+  EntityHandle result;
   if (MB_SUCCESS != iface->create_vertex( p, result ))
       moab_error( "create_vertex" );
   return result;
 }
 
-MBEntityHandle pent( MBEntityHandle* vtx_list, int i1, int i2, int i3, int i4, int i5 )
+EntityHandle pent( EntityHandle* vtx_list, int i1, int i2, int i3, int i4, int i5 )
 {
-  const MBEntityHandle conn[5] = { vtx_list[i1],
+  const EntityHandle conn[5] = { vtx_list[i1],
                                    vtx_list[i2],
                                    vtx_list[i3],
                                    vtx_list[i4],
                                    vtx_list[i5] };
-  MBEntityHandle result;
+  EntityHandle result;
   if (MB_SUCCESS != iface->create_element( MBPOLYGON, conn, 5, result ))
     moab_error( "create_element" );
   return result;
@@ -165,13 +167,13 @@
 // num_entities - length of 'entities'
 // reverse      - if true, add entities in reverse order
 // id           - value for global id on set
-MBEntityHandle make_set( unsigned int options,
-                         MBEntityHandle* entities,
+EntityHandle make_set( unsigned int options,
+                         EntityHandle* entities,
                          size_t num_entities,
                          bool reverse,
                          int id )
 {
-  MBEntityHandle handle;
+  EntityHandle handle;
   if (MB_SUCCESS != iface->create_meshset( options, handle ))
     moab_error( "create_meshset" );
   
@@ -187,8 +189,8 @@
       moab_error( "add_entities" );
   }
     
-  MBErrorCode rval;
-  MBTag id_tag;
+  ErrorCode rval;
+  Tag id_tag;
   rval = iface->tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   if (MB_TAG_NOT_FOUND == rval)
   {
@@ -231,13 +233,13 @@
   const double b = edge / 2.0;
   
   // list of vertex handles
-  MBEntityHandle vertices[20];
+  EntityHandle vertices[20];
   // list of pentagon handles
-  MBEntityHandle faces[12];
+  EntityHandle faces[12];
   // Dodecahedron handle
-  MBEntityHandle dodec;
+  EntityHandle dodec;
   // Inscribed Hex handle
-  MBEntityHandle hex;
+  EntityHandle hex;
   
   // Create vertices if inscribed cube
   vertices[ 0] = vtx( x-c, y+c, z+c );
@@ -293,7 +295,7 @@
   
   // Create a dense tag 
   int zero = 0;
-  MBTag tag;
+  Tag tag;
   if (MB_SUCCESS != iface->tag_create( tagname, 4, MB_TAG_DENSE, tag, &zero ))
     moab_error( "tag_create" );
   
@@ -303,7 +305,7 @@
       moab_error( "tag_set_data" );
       
   // Create bit tag
-  MBTag tag2;
+  Tag tag2;
   if (MB_SUCCESS != iface->tag_create( bitname, 2, MB_TAG_BIT, tag2, 0 ))
     moab_error( "tag_create" );
   
@@ -318,7 +320,7 @@
     moab_error( "tag_set_data" );
   
   // Create an integer array tag and set some values on the dodecahedron
-  MBTag itag;
+  Tag itag;
   if (MB_SUCCESS != iface->tag_create( intname, 2*sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, itag, 0 ))
     moab_error( "tag_create(MB_TYPE_INT)" );
   int idata[] = { 0xDEADBEEF, 0xDEFACED };
@@ -326,7 +328,7 @@
     moab_error( "tag_set_data(itag)" );
   
   // Create a double tag with a non-zero default value, and set on dodecahedron
-  MBTag dtag;
+  Tag dtag;
   double ddef = 3.14159;
   if (MB_SUCCESS != iface->tag_create( dblname, sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, dtag, &ddef ))
     moab_error( "tag_create(dtag)" );
@@ -335,28 +337,28 @@
     moab_error( "tag_set_data(dtag)" );
   
   // Create a tag containing entity handles, with default values
-  MBTag htag;
-  MBEntityHandle hdef[] = { hex, dodec, 0 };
-  if (MB_SUCCESS != iface->tag_create( handlename, 3*sizeof(MBEntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, htag, hdef ))
+  Tag htag;
+  EntityHandle hdef[] = { hex, dodec, 0 };
+  if (MB_SUCCESS != iface->tag_create( handlename, 3*sizeof(EntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, htag, hdef ))
     moab_error( "tag_create(htag)" );
   // Set global (mesh) value for tag
-  MBEntityHandle hgbl[] = { 0, hex, dodec };
+  EntityHandle hgbl[] = { 0, hex, dodec };
   if (MB_SUCCESS != iface->tag_set_data( htag, 0, 0, hgbl ))
     moab_error( "tag_set_data(hgbl)" );
   // Store first three entiries of dodec connectivity on dodec
-  MBEntityHandle hval[] = { faces[0], faces[1], faces[2] };
+  EntityHandle hval[] = { faces[0], faces[1], faces[2] };
   if (MB_SUCCESS != iface->tag_set_data( htag, &dodec, 1, hval ))
     moab_error( "tag_set_data(hgbl)" );
     
   // create some sets
-  MBEntityHandle face_set, vertex_set, region_set, empty_set, set_set;
-  MBEntityHandle regions[] = { dodec, hex };
+  EntityHandle face_set, vertex_set, region_set, empty_set, set_set;
+  EntityHandle regions[] = { dodec, hex };
   const unsigned empty_flags = MESHSET_ORDERED|MESHSET_TRACK_OWNER;
   face_set   = make_set( MESHSET_SET,     faces,    12, false, FACE_SET_ID    );
   vertex_set = make_set( MESHSET_ORDERED, vertices, 20, true,  VERTEX_SET_ID  );
   region_set = make_set( MESHSET_SET,     regions,   2, false, REGION_SET_ID  );
   empty_set  = make_set( empty_flags,     0,         0, true,  EMPTY_SET_ID   );
-  MBEntityHandle sets[] = {face_set, vertex_set, region_set, empty_set};
+  EntityHandle sets[] = {face_set, vertex_set, region_set, empty_set};
   set_set    = make_set( MESHSET_ORDERED, sets,      4, false, SET_SET_ID     );
   
   // create some set parent-child links
@@ -368,8 +370,8 @@
     moab_error( "add_parent_meshet" );
 }
 
-bool compare_conn( std::vector<MBEntityHandle>& conn1,
-                   std::vector<MBEntityHandle>& conn2 )
+bool compare_conn( std::vector<EntityHandle>& conn1,
+                   std::vector<EntityHandle>& conn2 )
 {
   unsigned i;
   
@@ -403,7 +405,7 @@
   
   std::vector<int> tags[2];
   tags[0].resize( conn1.size() ); tags[1].resize( conn2.size() );
-  MBTag tag;
+  Tag tag;
   if (MB_SUCCESS != iface->tag_get_handle( tagname, tag ))
     moab_error( "tag_get_handle" );
   if (MB_SUCCESS != iface->tag_get_data( tag, &conn1[0], conn1.size(), &tags[0][0] ) ||
@@ -433,18 +435,18 @@
 bool compare_sets( int id, const char* tag_name = 0 )
 {
   bool ok;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   // get sets
  
-  MBTag id_tag;
+  Tag id_tag;
   if (MB_SUCCESS != iface->tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag ))
   {
     fprintf(stderr, "Could not find global id tag in file.\n");
     return false;
   }
   
-  MBRange range;
+  Range range;
   const void* tag_data[] = { &id };
   rval = iface->get_entities_by_type_and_tag( 0, MBENTITYSET, &id_tag, tag_data, 1, range );
   if (MB_ENTITY_NOT_FOUND == rval || range.size() != 2)
@@ -455,8 +457,8 @@
   else if (MB_SUCCESS != rval)
     moab_error( "get_entities_by_type_and_tag" );
   
-  MBEntityHandle set1 = *range.begin();
-  MBEntityHandle set2 = *++range.begin();
+  EntityHandle set1 = *range.begin();
+  EntityHandle set2 = *++range.begin();
   
   
     // Compare set descriptions
@@ -489,7 +491,7 @@
     //  o If set is ordered, compare entity types in order
     //  o Otherwise compare counts of entity types in sets
 
-  std::vector<MBEntityHandle> list1, list2;
+  std::vector<EntityHandle> list1, list2;
   if (MB_SUCCESS != iface->get_entities_by_handle( set1, list1 ) ||
       MB_SUCCESS != iface->get_entities_by_handle( set2, list2 ))
     moab_error( "get_entities_by_handle" );
@@ -504,7 +506,7 @@
   
   if (tag_name) // compare contents using tag value
   {
-    MBTag tag;
+    Tag tag;
     if (MB_SUCCESS != iface->tag_get_handle( tag_name, tag ))
     {
       fprintf(stderr, "Could not find tag \"%s\" in file.\n", tag_name);
@@ -512,7 +514,7 @@
     }
     
       // Make sure tag is integer type
-    MBDataType type;
+    DataType type;
     if (MB_SUCCESS != iface->tag_get_data_type( tag, type ))
       moab_error( "tag_get_data_type" );
     if (MB_TYPE_INTEGER != type && MB_TYPE_OPAQUE != type)
@@ -565,7 +567,7 @@
       if (counts1[j] != counts2[j])
       {
         fprintf(stderr, "Sets with id %d have differing numbers of %s: %u and %u\n",
-                id, MBCN::EntityTypeName((MBEntityType)j), counts1[j], counts2[j] );
+                id, MBCN::EntityTypeName((EntityType)j), counts1[j], counts2[j] );
         ok = false;
       }
     if (!ok)
@@ -577,7 +579,7 @@
   
   ok = true;
   const char* words[] = { "children", "parents" };
-  std::vector<MBEntityHandle> adj1, adj2;
+  std::vector<EntityHandle> adj1, adj2;
   for (unsigned two = 0; two < 2; ++two)
   {
     adj1.clear(); adj2.clear();
@@ -634,12 +636,12 @@
   return ok;
 }
 
-bool compare_tags( MBEntityHandle dod[] )
+bool compare_tags( EntityHandle dod[] )
 {
-  MBTag tag;
+  Tag tag;
   int size;
-  MBDataType type;
-  MBTagType store;
+  DataType type;
+  TagType store;
 
 
     // Get integer tag handle and characterstics
@@ -654,7 +656,7 @@
     
     // check that integer tag has correct characteristics
   if (type != MB_TYPE_INTEGER) {
-    fprintf(stderr, "Incorrect MBDataType for integer tag.\n" );
+    fprintf(stderr, "Incorrect DataType for integer tag.\n" );
     return false;
   }
   if (size != 2*sizeof(int)) {
@@ -695,7 +697,7 @@
     
     // check that double tag has correct characteristics
   if (type != MB_TYPE_DOUBLE) {
-    fprintf(stderr, "Incorrect MBDataType for double tag.\n" );
+    fprintf(stderr, "Incorrect DataType for double tag.\n" );
     return false;
   }
   if (size != sizeof(double)) {
@@ -737,10 +739,10 @@
     
     // check that handle tag has correct characteristics
   if (type != MB_TYPE_HANDLE) {
-    fprintf(stderr, "Incorrect MBDataType for handle tag.\n" );
+    fprintf(stderr, "Incorrect DataType for handle tag.\n" );
     return false;
   }
-  if (size != 3*sizeof(MBEntityHandle)) {
+  if (size != 3*sizeof(EntityHandle)) {
     fprintf(stderr, "Incorrect size for handle tag.\n" );
     return false;
   }
@@ -753,7 +755,7 @@
     // default value will not change after tag is created.  As we
     // do multiple iterations of save/restore, we shouldn't expect
     // the dodecahedron handles to point to the most recent two.
-  MBEntityHandle hdata[6];
+  EntityHandle hdata[6];
   if (MB_SUCCESS != iface->tag_get_default_value( tag, hdata ))
     moab_error( "tag_get_default_value" );
   if (iface->type_from_handle(hdata[0]) != MBHEX ||
@@ -776,19 +778,19 @@
   }
  
     // check data on each dodecahedron
-  const MBEntityHandle *conn;
+  const EntityHandle *conn;
   int len;
   if (MB_SUCCESS != iface->tag_get_data( tag, dod, 2, hdata ))
     moab_error( "tag_get_data()" );
   if (MB_SUCCESS != iface->get_connectivity( dod[0], conn, len ))
     moab_error( "get_connectivity" );
-  if (memcmp(conn, hdata, 3*sizeof(MBEntityHandle))) {
+  if (memcmp(conn, hdata, 3*sizeof(EntityHandle))) {
     fprintf( stderr, "Incorrect values for handle tag data.\n" );
     return false;
   }
   if (MB_SUCCESS != iface->get_connectivity( dod[1], conn, len ))
     moab_error( "get_connectivity" );
-  if (memcmp(conn, hdata+3, 3*sizeof(MBEntityHandle))) {
+  if (memcmp(conn, hdata+3, 3*sizeof(EntityHandle))) {
     fprintf( stderr, "Incorrect values for handle tag data.\n" );
     return false;
   }
@@ -800,11 +802,11 @@
 
 bool compare()
 {
-  MBRange range;
-  MBEntityHandle hex[2];
-  MBEntityHandle dod[2];
-  MBTag elemtag;
-  MBRange::iterator iter;
+  Range range;
+  EntityHandle hex[2];
+  EntityHandle dod[2];
+  Tag elemtag;
+  Range::iterator iter;
   
   // get tag
   if (MB_SUCCESS != iface->tag_get_handle( bitname, elemtag ))
@@ -842,7 +844,7 @@
   dod[1] = *++iter;
   
   // compare hexes
-  std::vector<MBEntityHandle> conn[2];
+  std::vector<EntityHandle> conn[2];
   if (MB_SUCCESS != iface->get_connectivity( hex  , 1, conn[0] ) ||
       MB_SUCCESS != iface->get_connectivity( hex+1, 1, conn[1] ))
     moab_error( "get_connectivity" );
@@ -851,7 +853,7 @@
   
   // compare polyhedra
   
-  std::vector<MBEntityHandle> face[2];
+  std::vector<EntityHandle> face[2];
   conn[0].clear(); conn[1].clear();
   if (MB_SUCCESS != iface->get_connectivity( dod  , 1, conn[0], false ) ||
       MB_SUCCESS != iface->get_connectivity( dod+1, 1, conn[1], false ))

Modified: MOAB/trunk/test/h5file/h5legacy.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5legacy.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5legacy.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,17 +1,19 @@
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "TestUtil.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 
 #include <algorithm>
 #include <iostream>
 #include <stdlib.h>
 #include <math.h>
 
-void calc_centroid( MBInterface* iface, MBEntityHandle pent, double result[3] )
+using namespace moab;
+
+void calc_centroid( Interface* iface, EntityHandle pent, double result[3] )
 {
   int len;
-  const MBEntityHandle* conn;
-  MBErrorCode rval;
+  const EntityHandle* conn;
+  ErrorCode rval;
   rval = iface->get_connectivity( pent, conn, len );
   CHECK_ERR(rval);
   CHECK_EQUAL( 5, len );
@@ -30,16 +32,16 @@
 
 void test_moab_v3_poly_format()
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // load file containing a dodecahedron
   rval = mb.load_mesh( STRINGIFY(SRCDIR) "/v3_dodec.h5m" );
   CHECK_ERR(rval);
   
     // get entities from file
-  MBRange verts, faces, polyhedrons;
+  Range verts, faces, polyhedrons;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_type( 0, MBPOLYGON, faces );
@@ -48,13 +50,13 @@
   CHECK_ERR(rval);
   
     // check expected number of entities
-  CHECK_EQUAL( (MBEntityHandle)20, verts.size() );
-  CHECK_EQUAL( (MBEntityHandle)12, faces.size() );
-  CHECK_EQUAL( (MBEntityHandle)1,  polyhedrons.size() );
-  const MBEntityHandle polyhedron = polyhedrons.front();
+  CHECK_EQUAL( (EntityHandle)20, verts.size() );
+  CHECK_EQUAL( (EntityHandle)12, faces.size() );
+  CHECK_EQUAL( (EntityHandle)1,  polyhedrons.size() );
+  const EntityHandle polyhedron = polyhedrons.front();
   
     // check the polyhedron connectivity list
-  std::vector<MBEntityHandle> faces1, faces2;
+  std::vector<EntityHandle> faces1, faces2;
   std::copy( faces.begin(), faces.end(), std::back_inserter(faces1) );
   rval = mb.get_connectivity( &polyhedron, 1, faces2 );
   CHECK_ERR(rval);
@@ -66,12 +68,12 @@
     // the vertex coords.
   
     // get tag for saved values
-  MBTag centroid;
+  Tag centroid;
   rval = mb.tag_get_handle( "CENTROID", centroid );
   CHECK_ERR(rval);
   
     // for each face...
-  for (MBRange::iterator i = faces.begin(); i != faces.end(); ++i) {
+  for (Range::iterator i = faces.begin(); i != faces.end(); ++i) {
     double saved[3], calc[3];
     rval = mb.tag_get_data( centroid, &*i, 1, saved );
     CHECK_ERR(rval);

Modified: MOAB/trunk/test/h5file/h5partial.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5partial.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5partial.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,8 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include "TestUtil.hpp"
 #include "ReadHDF5.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/MBTagConventions.hpp"
 #include "FileOptions.hpp"
 #include <vector>
 #include <stdlib.h>
@@ -10,6 +10,8 @@
 #include <algorithm>
 #include <limits>
 
+using namespace moab;
+
 const char TEST_FILE[] = "partial.h5m";
 #define READ_OPTS "BUFFER_SIZE=256"
 const char ID_TAG_NAME[] = "test_id_tag";
@@ -19,14 +21,14 @@
 static void test_read_nodes_common( int num_read_sets );
 static void test_read_handle_tag_common( bool var_len );
 
-const int QUAD_INT = 20; 
+const int MBQUAD_INT = 20; 
 const int NUM_SETS = 10;
-const int SET_WIDTH = (QUAD_INT + NUM_SETS - 1) / NUM_SETS; // ceil(QUAD_INT/NUM_SETS)
+const int SET_WIDTH = (MBQUAD_INT + NUM_SETS - 1) / NUM_SETS; // ceil(MBQUAD_INT/NUM_SETS)
 const char LOGICAL_NAME[] = "logical";   // tag storing logical (i,j) coordinates
 const char CENTROID_NAME[] = "centroid"; // tag storing position of centroid (x,y,0)
-//! Create a regular QUAD_INT^2 element quad mesh with regularly
+//! Create a regular MBQUAD_INT^2 element quad mesh with regularly
 //! spaced coordinates in the range [1,100].  Group elements
-//! into 10 vertical strips QUAD_INT/10 elements wide.  Tag elements,
+//! into 10 vertical strips MBQUAD_INT/10 elements wide.  Tag elements,
 //! vertices and/or sets with ID in [1,10] stored in ID_TAG_NAME
 //! tag.  Write new mesh to TEST_FILE.
 void create_mesh( bool create_element_sets,
@@ -37,13 +39,13 @@
                   bool var_len_adj_elems = false );
 // Given a list of vertices adjacent to a quad strip, identify it as one of the 
 // NUM_SETS strips of quads written by create_mesh.
-int identify_set( MBInterface& mb, const MBRange& verts );
-int identify_set( MBInterface& mb, MBEntityHandle set );
+int identify_set( Interface& mb, const Range& verts );
+int identify_set( Interface& mb, EntityHandle set );
 
-static MBTag check_tag( MBInterface& mb, 
+static Tag check_tag( Interface& mb, 
                         const char* name,
-                        MBTagType storage,
-                        MBDataType type,
+                        TagType storage,
+                        DataType type,
                         int size );
 
 enum GatherTestMode { GATHER_SETS, GATHER_CONTENTS, GATHER_NONE };
@@ -185,18 +187,18 @@
 
 void test_read_nothing_common( bool non_existant )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
 
   // create a few nodes to write to file
   std::vector<double> coords( 3000 );
-  MBRange verts;
+  Range verts;
   rval= mb.create_vertices( &coords[0], coords.size()/3, verts );
   CHECK_ERR(rval);
   
   // create three entity sets
-  MBEntityHandle sets[3];
+  EntityHandle sets[3];
   rval = mb.create_meshset( MESHSET_SET, sets[0] );
   CHECK_ERR(rval);
   rval = mb.create_meshset( MESHSET_SET, sets[1] );
@@ -211,7 +213,7 @@
   CHECK_ERR(rval);
   
   // tag all three sets
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   int ids[3] = { 5, 7, 9 };
@@ -225,7 +227,7 @@
   CHECK_ERR(rval);
   
   // now read back in only the empty set
-  MBEntityHandle file_set;
+  EntityHandle file_set;
   int id = non_existant ? 8 : 7;
   rval = mb.create_meshset( MESHSET_SET, file_set );
   CHECK_ERR(rval);
@@ -239,13 +241,13 @@
   
   // the file should contain exactly two sets (the specified one and the new
   // file set, and nothing else.)
-  for (MBEntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
+  for (EntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
     int count = -1;
     rval = mb.get_number_entities_by_type( 0, t, count );
     CHECK_ERR(rval);
     CHECK_EQUAL( 0, count );
   }
-  MBRange setrange;
+  Range setrange;
   rval = mb.get_entities_by_type( 0, MBENTITYSET, setrange );
   CHECK_ERR(rval);
   CHECK_EQUAL( (non_existant ? 1 : 2), (int)setrange.size() );
@@ -263,14 +265,14 @@
 
 void test_read_nodes_common( int num_read_sets )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
     
     // create 1000 nodes
   const int num_sets = 2*num_read_sets;
-  std::vector<MBEntityHandle> verts(1000);
-  std::vector< std::vector<MBEntityHandle> > set_verts(num_sets);
+  std::vector<EntityHandle> verts(1000);
+  std::vector< std::vector<EntityHandle> > set_verts(num_sets);
   for (size_t i = 0; i < verts.size(); ++i) {
     double coords[3];
     int j = i % num_sets;
@@ -281,7 +283,7 @@
   }
   
     // create two sets, each containing half of the nodes
-  std::vector<MBEntityHandle> sets(num_sets);
+  std::vector<EntityHandle> sets(num_sets);
   for (int i = 0; i < num_sets; ++i) {
     rval = mb.create_meshset( MESHSET_ORDERED, sets[i] );
     CHECK_ERR(rval);
@@ -290,7 +292,7 @@
   }
  
     // tag both sets
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   std::vector<int> values( num_sets );
@@ -307,7 +309,7 @@
     // now read back in only the specified number of sets
   values.resize( num_read_sets );
   for (int i = 0; i < num_read_sets; ++i) values[i] = 2*(i+1);
-  MBEntityHandle file_set;
+  EntityHandle file_set;
   rval = mb.create_meshset( MESHSET_SET, file_set );
   CHECK_ERR(rval);
   rval = mb.load_file( TEST_FILE, &file_set, READ_OPTS, ID_TAG_NAME, &values[0], num_read_sets );
@@ -321,18 +323,18 @@
       expected += set_verts[i].size();
   CHECK_EQUAL( expected, count );
   
-  MBRange sets2;
+  Range sets2;
   rval = mb.get_entities_by_type( 0, MBENTITYSET, sets2 );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1+num_read_sets, (int)sets2.size() );
-  MBRange::iterator it = sets2.find( file_set );
+  Range::iterator it = sets2.find( file_set );
   CHECK( it != sets2.end() );
   sets2.erase( it );
   
   rval = mb.tag_get_handle( ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);  
   while (!sets2.empty()) {
-    MBEntityHandle set = sets2.pop_front();
+    EntityHandle set = sets2.pop_front();
     int id;
     rval = mb.tag_get_data( id_tag, &set, 1, &id );
     CHECK_ERR(rval);
@@ -340,7 +342,7 @@
     CHECK( id > 0 );
     CHECK( (unsigned)id <= set_verts.size() );
     
-    std::vector<MBEntityHandle> verts;
+    std::vector<EntityHandle> verts;
     rval = mb.get_entities_by_handle( set, verts );
     CHECK_ERR(rval);
     CHECK_EQUAL( set_verts[id-1].size(), verts.size() );
@@ -357,9 +359,9 @@
   }
 }
 
-//! Create a regular QUAD_INT^2 element quad mesh with regularly
+//! Create a regular MBQUAD_INT^2 element quad mesh with regularly
 //! spaced coordinates in the range [1,100].  Group elements
-//! into 10 vertical strips QUAD_INT/10 elements wide.  Tag elements,
+//! into 10 vertical strips MBQUAD_INT/10 elements wide.  Tag elements,
 //! vertices and/or sets with ID in [1,10] stored in ID_TAG_NAME
 //! tag.  Write new mesh to TEST_FILE.
 void create_mesh( bool create_element_sets,
@@ -369,12 +371,12 @@
                   const char* adj_elem_tag_name,
                   bool var_len_adj_elems )
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create tags
-  MBTag logical_tag, centroid_tag, id_tag;
+  Tag logical_tag, centroid_tag, id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   rval = mb.tag_create( LOGICAL_NAME, 2*sizeof(int), MB_TAG_DENSE, MB_TYPE_OPAQUE, logical_tag, 0 );
@@ -382,7 +384,7 @@
   rval = mb.tag_create( CENTROID_NAME, 3*sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, centroid_tag, 0 );
   CHECK_ERR(rval);
 
-  MBEntityHandle sets[NUM_SETS];
+  EntityHandle sets[NUM_SETS];
   if (create_element_sets || create_vertex_sets) {
     for (int i = 0; i < NUM_SETS; ++i) {
       rval = mb.create_meshset( MESHSET_ORDERED, sets[i] );
@@ -394,8 +396,8 @@
   }
 
     // create elements
-  MBEntityHandle verts[QUAD_INT+1][QUAD_INT+1], quads[QUAD_INT][QUAD_INT];
-  for (int i = 0; i <= QUAD_INT; ++i) for(int j = 0; j <= QUAD_INT; ++j) {
+  EntityHandle verts[MBQUAD_INT+1][MBQUAD_INT+1], quads[MBQUAD_INT][MBQUAD_INT];
+  for (int i = 0; i <= MBQUAD_INT; ++i) for(int j = 0; j <= MBQUAD_INT; ++j) {
     double coords[3] = { i, j, 0 };
     rval = mb.create_vertex( coords, verts[j][i] );
     CHECK_ERR(rval);
@@ -421,8 +423,8 @@
       }
     }
   }
-  for (int i = 0; i < QUAD_INT; ++i) for(int j = 0; j < QUAD_INT; ++j) {
-    MBEntityHandle conn[4] = { verts[j  ][i  ], 
+  for (int i = 0; i < MBQUAD_INT; ++i) for(int j = 0; j < MBQUAD_INT; ++j) {
+    EntityHandle conn[4] = { verts[j  ][i  ], 
                                verts[j  ][i+1],
                                verts[j+1][i+1],
                                verts[j+1][i  ] };
@@ -446,39 +448,39 @@
   }
   
   if (adj_elem_tag_name && !var_len_adj_elems) {
-    MBTag handle_tag;
+    Tag handle_tag;
     rval = mb.tag_create( adj_elem_tag_name, 
-                          4 * sizeof(MBEntityHandle), 
+                          4 * sizeof(EntityHandle), 
                           MB_TAG_DENSE,
                           MB_TYPE_HANDLE,
                           handle_tag,
                           0 );
     CHECK_ERR(rval);
-    for (int i = 0; i <= QUAD_INT; ++i) for(int j = 0; j <= QUAD_INT; ++j) {
-      MBEntityHandle val[4] = { (i > 0        && j > 0       ) ? quads[j-1][i-1] : 0,
-                                (i > 0        && j < QUAD_INT) ? quads[j  ][i-1] : 0,
-                                (i < QUAD_INT && j < QUAD_INT) ? quads[j  ][i  ] : 0,
-                                (i < QUAD_INT && j > 0       ) ? quads[j-1][i  ] : 0 };
+    for (int i = 0; i <= MBQUAD_INT; ++i) for(int j = 0; j <= MBQUAD_INT; ++j) {
+      EntityHandle val[4] = { (i > 0        && j > 0       ) ? quads[j-1][i-1] : 0,
+                                (i > 0        && j < MBQUAD_INT) ? quads[j  ][i-1] : 0,
+                                (i < MBQUAD_INT && j < MBQUAD_INT) ? quads[j  ][i  ] : 0,
+                                (i < MBQUAD_INT && j > 0       ) ? quads[j-1][i  ] : 0 };
       rval = mb.tag_set_data( handle_tag, &verts[j][i], 1, val );
       CHECK_ERR(rval);
     }
   }
   else if (adj_elem_tag_name && var_len_adj_elems) {
-    MBTag handle_tag;
+    Tag handle_tag;
     rval = mb.tag_create_variable_length( adj_elem_tag_name,
                                           MB_TAG_DENSE,
                                           MB_TYPE_HANDLE,
                                           handle_tag );
     CHECK_ERR(rval);
-    for (int i = 0; i <= QUAD_INT; ++i) for(int j = 0; j <= QUAD_INT; ++j) {
-      MBEntityHandle val[4];
+    for (int i = 0; i <= MBQUAD_INT; ++i) for(int j = 0; j <= MBQUAD_INT; ++j) {
+      EntityHandle val[4];
       int num = 0;
       if (i > 0        && j > 0       ) val[num++] = quads[j-1][i-1];
-      if (i > 0        && j < QUAD_INT) val[num++] = quads[j  ][i-1];
-      if (i < QUAD_INT && j < QUAD_INT) val[num++] = quads[j  ][i  ];
-      if (i < QUAD_INT && j > 0       ) val[num++] = quads[j-1][i  ];
+      if (i > 0        && j < MBQUAD_INT) val[num++] = quads[j  ][i-1];
+      if (i < MBQUAD_INT && j < MBQUAD_INT) val[num++] = quads[j  ][i  ];
+      if (i < MBQUAD_INT && j > 0       ) val[num++] = quads[j-1][i  ];
       const void* ptr = val;
-      num *= sizeof(MBEntityHandle);
+      num *= sizeof(EntityHandle);
       rval = mb.tag_set_data( handle_tag, &verts[j][i], 1, &ptr, &num );
       CHECK_ERR(rval);
     }
@@ -490,17 +492,17 @@
 
 // Given a list of vertices adjacent to a quad strip, identify it as one of the 
 // NUM_SETS strips of quads written by create_mesh.
-int identify_set( MBInterface& mb, const MBRange& verts )
+int identify_set( Interface& mb, const Range& verts )
 {
   const int COL = SET_WIDTH+1;
-  CHECK_EQUAL( (1+QUAD_INT)*COL, (int)verts.size() );
+  CHECK_EQUAL( (1+MBQUAD_INT)*COL, (int)verts.size() );
 
     // Get X range of vertices
   int min_x = std::numeric_limits<int>::max();
   int max_x = std::numeric_limits<int>::min();
-  for (MBRange::const_iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::const_iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
-    MBErrorCode rval = mb.get_coords( &*i, 1, coords );
+    ErrorCode rval = mb.get_coords( &*i, 1, coords );
     CHECK_ERR(rval);
       // Expect whole-valued coorindates
     int int_x = (int)coords[0];
@@ -515,35 +517,35 @@
   const int ID = min_x / SET_WIDTH + 1;
   
     // Now verify that all vertices correctly form a grid
-  MBEntityHandle grid[QUAD_INT+1][COL];
+  EntityHandle grid[MBQUAD_INT+1][COL];
   memset( grid, 0, sizeof(grid) );
-  for (MBRange::const_iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::const_iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
-    MBErrorCode rval = mb.get_coords( &*i, 1, coords );
+    ErrorCode rval = mb.get_coords( &*i, 1, coords );
     CHECK_ERR(rval);
       // Expect whole-valued coorindates
     int x = (int)coords[0] - (ID-1)*SET_WIDTH, y = (int)coords[1];
     CHECK( fabs( coords[1] - (double)y ) < 1e-12 );
     CHECK( fabs( coords[2] ) < 1e-12 );
-    CHECK( y >= 0 && y <= QUAD_INT );
-    CHECK_EQUAL( (MBEntityHandle)0, grid[y][x] );
+    CHECK( y >= 0 && y <= MBQUAD_INT );
+    CHECK_EQUAL( (EntityHandle)0, grid[y][x] );
     grid[y][x] = *i;
   }
   
   return ID;
 }
-int identify_set( MBInterface& mb, MBEntityHandle set )
+int identify_set( Interface& mb, EntityHandle set )
 {
-  MBErrorCode rval;
-  MBRange verts, elems;
+  ErrorCode rval;
+  Range verts, elems;
   rval = mb.get_entities_by_handle( set, elems );
   CHECK_ERR(rval);
-  MBRange::iterator it = elems.upper_bound( MBVERTEX );
+  Range::iterator it = elems.upper_bound( MBVERTEX );
   verts.merge( elems.begin(), it );
   elems.erase( elems.begin(), it );
   it = elems.lower_bound( MBENTITYSET );
   elems.erase( it, elems.end() );
-  rval = mb.get_adjacencies( elems, 0, false, verts, MBInterface::UNION );
+  rval = mb.get_adjacencies( elems, 0, false, verts, Interface::UNION );
   CHECK_ERR(rval);
   return identify_set( mb, verts );
 }
@@ -551,9 +553,9 @@
 //! Read in the elems contained in a set
 void test_read_one_set_elems()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( true, false, false, false );
   
@@ -562,7 +564,7 @@
     CHECK_ERR(rval);
     rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, &id, 1 );
     CHECK_ERR(rval);
-    MBRange verts;
+    Range verts;
     rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
     int act_id = identify_set( mb, verts );
     CHECK_EQUAL( id, act_id );
@@ -572,23 +574,23 @@
 //! Read in the elems contained in a sets
 void test_read_two_sets_elems()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( true, false, false, false );
   int ids[2] = { 2, 8 };
-  MBEntityHandle file_set;
+  EntityHandle file_set;
   rval = mb.create_meshset( MESHSET_SET, file_set );
   CHECK_ERR(rval);
   rval = mb.load_file( TEST_FILE, &file_set, READ_OPTS, ID_TAG_NAME, ids, 2 );
   CHECK_ERR(rval);
   
-  MBRange sets;
+  Range sets;
   rval = mb.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   CHECK_EQUAL( 3, (int)sets.size() );
-  MBRange::iterator it = sets.find( file_set );
+  Range::iterator it = sets.find( file_set );
   CHECK( it != sets.end() );
   sets.erase( it );
   
@@ -603,23 +605,23 @@
   }
 }
 
-MBTag check_tag( MBInterface& mb, 
+Tag check_tag( Interface& mb, 
                  const char* name,
-                 MBTagType storage,
-                 MBDataType type,
+                 TagType storage,
+                 DataType type,
                  int size )
 {
   
-  MBTag tag;
-  MBErrorCode rval = mb.tag_get_handle( name, tag );
+  Tag tag;
+  ErrorCode rval = mb.tag_get_handle( name, tag );
   CHECK_ERR(rval);
 
-  MBTagType storage1;
+  TagType storage1;
   rval = mb.tag_get_type( tag, storage1 );
   CHECK_ERR(rval);
   CHECK_EQUAL( storage, storage1 );
   
-  MBDataType type1;
+  DataType type1;
   rval = mb.tag_get_data_type( tag, type1 );
   CHECK_ERR(rval);
   CHECK_EQUAL( type, type1 );
@@ -640,21 +642,21 @@
 //! Test reading of sparse double tag data
 void test_read_double_tag()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( true, false, false, false );
   int ids[2] = { 1, 4 };
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, ids, 2 );
   CHECK_ERR(rval);
   
-  MBTag tag = check_tag( mb, CENTROID_NAME, MB_TAG_DENSE, MB_TYPE_DOUBLE, 3*sizeof(double) );
-  MBRange verts;
+  Tag tag = check_tag( mb, CENTROID_NAME, MB_TAG_DENSE, MB_TYPE_DOUBLE, 3*sizeof(double) );
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3], data[3];
     rval = mb.get_coords( &*i, 1, coords );
     CHECK_ERR(rval);
@@ -669,21 +671,21 @@
 //! Test reading of sparse opaque tag data
 void test_read_opaque_tag()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( true, false, false, false );
   int ids[2] = { 1, 4 };
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, ids, 2 );
   CHECK_ERR(rval);
 
-  MBTag tag = check_tag( mb, LOGICAL_NAME, MB_TAG_DENSE, MB_TYPE_OPAQUE, 2*sizeof(int) );
-  MBRange verts;
+  Tag tag = check_tag( mb, LOGICAL_NAME, MB_TAG_DENSE, MB_TYPE_OPAQUE, 2*sizeof(int) );
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
     int data[2];
     rval = mb.get_coords( &*i, 1, coords );
@@ -697,9 +699,9 @@
 
 static void test_read_handle_tag_common( bool var_len )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   const char tag_name[] = "VTX_ADJ";
   create_mesh( true, false, false, false, tag_name, var_len );
@@ -707,15 +709,15 @@
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, ids, 2 );
   CHECK_ERR(rval);
   
-  MBTag tag = check_tag( mb, tag_name, MB_TAG_DENSE, MB_TYPE_HANDLE, 
-                         var_len ? -1 : 4*sizeof(MBEntityHandle) );
-  MBRange verts;
+  Tag tag = check_tag( mb, tag_name, MB_TAG_DENSE, MB_TYPE_HANDLE, 
+                         var_len ? -1 : 4*sizeof(EntityHandle) );
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
-    std::vector<MBEntityHandle> adj, val;
-    rval = mb.get_adjacencies( &*i, 1, 2, false, adj, MBInterface::UNION );
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
+    std::vector<EntityHandle> adj, val;
+    rval = mb.get_adjacencies( &*i, 1, 2, false, adj, Interface::UNION );
     CHECK_ERR(rval);
     CHECK(!adj.empty());
     
@@ -723,8 +725,8 @@
     const void* ptr;
     rval = mb.tag_get_data( tag, &*i, 1, &ptr, &num );
     CHECK_ERR(rval);
-    CHECK_EQUAL( 0, num % (int)sizeof(MBEntityHandle) );
-    num /= sizeof(MBEntityHandle);
+    CHECK_EQUAL( 0, num % (int)sizeof(EntityHandle) );
+    num /= sizeof(EntityHandle);
     
     if (var_len) {
       CHECK( num > 0 );
@@ -735,8 +737,8 @@
     }
     
     val.clear();
-    const MBEntityHandle* dat = (const MBEntityHandle*)ptr;
-    for (const MBEntityHandle* end = dat+num; dat != end; ++dat)
+    const EntityHandle* dat = (const EntityHandle*)ptr;
+    for (const EntityHandle* end = dat+num; dat != end; ++dat)
       if (*dat)
         val.push_back(*dat);
 
@@ -750,16 +752,16 @@
 
 void test_read_tagged_elems()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( false, false, true, false );
   int id = 5;
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, &id, 1 );
   CHECK_ERR(rval);
   
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   int id2 = identify_set( mb, verts );
@@ -768,21 +770,21 @@
   int elems;
   rval = mb.get_number_entities_by_type( 0, MBQUAD, elems );
   CHECK_ERR(rval);
-  CHECK_EQUAL( QUAD_INT*QUAD_INT/NUM_SETS, elems );
+  CHECK_EQUAL( MBQUAD_INT*MBQUAD_INT/NUM_SETS, elems );
 }
 
 void test_read_tagged_nodes()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
   create_mesh( false, false, false, true );
   int id = 1; // NOTE: this test will only succeed for ID == 1 
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, &id, 1 );
   CHECK_ERR(rval);
   
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   int id2 = identify_set( mb, verts );
@@ -791,20 +793,20 @@
   int elems;
   rval = mb.get_number_entities_by_type( 0, MBQUAD, elems );
   CHECK_ERR(rval);
-  CHECK_EQUAL( QUAD_INT*QUAD_INT/NUM_SETS, elems );
+  CHECK_EQUAL( MBQUAD_INT*MBQUAD_INT/NUM_SETS, elems );
 }
 
 
 //! Read in the polyhedra contained in a set
 void test_read_one_set_polyhedra()
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
     // create a 2x2x1 block of hexes, splitting each hex face
     // into two triangles to form an 12-sided polyhedron
-  MBEntityHandle verts[18], hexes[4];
+  EntityHandle verts[18], hexes[4];
   double coords[18][3] = { {0, 0, 0},
                            {1, 0, 0},
                            {2, 0, 0},
@@ -832,19 +834,19 @@
     CHECK_ERR(rval);
   }
   for (int i = 0; i < 4; ++i) {
-    MBEntityHandle conn[8];
+    EntityHandle conn[8];
     for (int j = 0; j < 8; ++j)
       conn[j] = verts[hexconn[i][j]];
     rval = mb.create_element( MBHEX, conn, 8, hexes[i] );
     CHECK_ERR(rval);
   }
   
-  MBTag tri_tag;
-  rval = mb.tag_create( "tris", 2*sizeof(MBEntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tri_tag, 0 );
+  Tag tri_tag;
+  rval = mb.tag_create( "tris", 2*sizeof(EntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tri_tag, 0 );
   CHECK_ERR(rval);
   
-  std::vector<MBEntityHandle> quads;
-  MBEntityHandle tris[12], poly[4];
+  std::vector<EntityHandle> quads;
+  EntityHandle tris[12], poly[4];
   for (int i = 0; i < 4; ++i) {
     quads.clear();
     rval = mb.get_adjacencies( &hexes[i], 1, 2, true, quads );
@@ -856,12 +858,12 @@
       if (MB_SUCCESS == rval)
         continue;
       CHECK_EQUAL( MB_TAG_NOT_FOUND, rval );
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       int len;
       rval = mb.get_connectivity( quads[j], conn, len );
       CHECK_ERR(rval);
       CHECK_EQUAL( 4, len );
-      MBEntityHandle tri_conn[2][3] = {  { conn[0], conn[1], conn[2] },
+      EntityHandle tri_conn[2][3] = {  { conn[0], conn[1], conn[2] },
                                          { conn[2], conn[3], conn[0] } };
       rval = mb.create_element( MBTRI, tri_conn[0], 3, tris[2*j  ] ); CHECK_ERR(rval);
       rval = mb.create_element( MBTRI, tri_conn[1], 3, tris[2*j+1] ); CHECK_ERR(rval);
@@ -872,7 +874,7 @@
     CHECK_ERR(rval);
   }
   
-  MBRange all_tri;
+  Range all_tri;
   rval = mb.get_entities_by_type( 0, MBTRI, all_tri );
   CHECK_ERR(rval);
   CHECK_EQUAL( 40, (int)all_tri.size() );
@@ -880,13 +882,13 @@
   rval = mb.delete_entities( hexes, 4 ); CHECK_ERR(rval);
   rval = mb.delete_entities( &quads[0], quads.size() ); CHECK_ERR(rval);
   
-  MBEntityHandle sets[2];
+  EntityHandle sets[2];
   rval = mb.create_meshset( 0, sets[0] ); CHECK_ERR(rval);
   rval = mb.add_entities( sets[0], poly, 2 ); CHECK_ERR(rval);
   rval = mb.create_meshset( 0, sets[1] ); CHECK_ERR(rval);
   rval = mb.add_entities( sets[1], poly+2, 2 ); CHECK_ERR(rval);
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   int ids[2] = { 2, 3 };
@@ -900,17 +902,17 @@
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, ids, 1 );
   CHECK_ERR(rval);
   
-  MBRange rpoly;
+  Range rpoly;
   rval = mb.get_entities_by_type( 0, MBPOLYHEDRON, rpoly );
   CHECK_ERR(rval);
   CHECK_EQUAL( 2, (int)rpoly.size() );
   
-  MBRange polyverts;
-  rval = mb.get_adjacencies( rpoly, 0, false, polyverts, MBInterface::UNION );
+  Range polyverts;
+  rval = mb.get_adjacencies( rpoly, 0, false, polyverts, Interface::UNION );
   CHECK_ERR(rval);
   CHECK_EQUAL( 12, (int)polyverts.size() );
   
-  for (MBRange::iterator it = polyverts.begin(); it != polyverts.end(); ++it) {
+  for (Range::iterator it = polyverts.begin(); it != polyverts.end(); ++it) {
     double coords2[3];
     rval = mb.get_coords( &*it, 1, coords2 );
     CHECK_ERR(rval);
@@ -926,17 +928,17 @@
 //! set.  Test the later here.
 void test_read_set_sets()
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   
     // create sets and assign an ID to each
   const int len = 5;
-  MBEntityHandle set[2*len+2];
+  EntityHandle set[2*len+2];
   for (int i = 0; i < 2*len+2; ++i) {
     rval = mb.create_meshset( MESHSET_SET, set[i] );
     CHECK_ERR(rval);
@@ -948,7 +950,7 @@
     // make set containment as follows (values are assigned IDs):
   int cont_ids[2][len] = { { 3, 4, 5, 9, 10 }, { 6, 7, 8, 11, 12 } };
   for (int i = 0; i < 2; ++i) {
-    MBEntityHandle contents[len] = { set[cont_ids[i][0] - 1],
+    EntityHandle contents[len] = { set[cont_ids[i][0] - 1],
                                      set[cont_ids[i][1] - 1],
                                      set[cont_ids[i][2] - 1],
                                      set[cont_ids[i][3] - 1],
@@ -964,7 +966,7 @@
     rval = mb.delete_mesh();
     CHECK_ERR(rval);
     
-    MBEntityHandle file;
+    EntityHandle file;
     rval = mb.create_meshset( MESHSET_SET, file );
     CHECK_ERR(rval);
     int id = i+1;
@@ -972,10 +974,10 @@
     CHECK_ERR(rval);
     
       // check that the total number of sets read is as expected
-    MBRange sets;
+    Range sets;
     rval = mb.get_entities_by_type( 0, MBENTITYSET, sets );
     CHECK_ERR(rval);
-    MBRange::iterator it = sets.find( file );
+    Range::iterator it = sets.find( file );
     if (it != sets.end())
       sets.erase( it );
     CHECK_EQUAL( len+1, (int)sets.size() );
@@ -990,7 +992,7 @@
     CHECK_EQUAL( 1, (int)sets.size() );
       
       // check that it contains the expected sets
-    MBEntityHandle owner = sets.front();
+    EntityHandle owner = sets.front();
     sets.clear();
     rval = mb.get_entities_by_type( owner, MBENTITYSET, sets );
     CHECK_ERR(rval);
@@ -1006,27 +1008,27 @@
   }
 }
 
-static void check_children( bool contents, GatherTestMode mode, MBInterface& mb, int id, MBTag id_tag, MBEntityHandle file )
+static void check_children( bool contents, GatherTestMode mode, Interface& mb, int id, Tag id_tag, EntityHandle file )
 {
     // Increase number of expected sets by one if contents is true because
     // we always read immediately contained (depth 1) sets.
   const int exp_num_sets = (mode == GATHER_NONE) ? 1+contents : id;
   const int exp_num_edges = (mode == GATHER_CONTENTS) ? id : 1;
   
-  MBErrorCode rval;
-  MBRange range;
+  ErrorCode rval;
+  Range range;
   rval = mb.get_entities_by_type( 0, MBEDGE , range );
   CHECK_ERR(rval);
   CHECK_EQUAL( exp_num_edges, (int)range.size() );
   range.clear();
   rval = mb.get_entities_by_type( 0, MBENTITYSET , range );
   CHECK_ERR(rval);
-  MBRange::iterator it = range.find( file );
+  Range::iterator it = range.find( file );
   CHECK( it != range.end() );
   range.erase( it );
   CHECK_EQUAL( exp_num_sets, (int)range.size() );
   
-  MBEntityHandle set;
+  EntityHandle set;
   const void* val[] = {&id};
   range.clear();
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &id_tag, val, 1, range );
@@ -1053,7 +1055,7 @@
     CHECK_ERR(rval);
     if (mode == GATHER_CONTENTS || i == id) {
       CHECK_EQUAL( 1, (int)range.size() );
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       int len;
       rval = mb.get_connectivity( range.front(), conn, len );
       CHECK_ERR(rval);
@@ -1067,7 +1069,7 @@
       CHECK( range.empty() );
     }
     
-    std::vector<MBEntityHandle> children;
+    std::vector<EntityHandle> children;
     if (contents)
       rval = mb.get_entities_by_type( set, MBENTITYSET, children );
     else
@@ -1087,11 +1089,11 @@
 const char* set_read_opts[] = { "SETS", "CONTENTS", "NONE" };
 void test_gather_sets_common( bool contents, GatherTestMode mode )
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   
@@ -1101,7 +1103,7 @@
     // ID that is the X coordinate of the larger of the two vertices of the edge
     // contained in the set.
   const int INT = 64;
-  MBEntityHandle verts[INT+1], edges[INT], sets[INT];
+  EntityHandle verts[INT+1], edges[INT], sets[INT];
   double coords[] = { 0, 0, 0 };
   rval = mb.create_vertex( coords, verts[0] );
   CHECK_ERR(rval);
@@ -1131,7 +1133,7 @@
   rval = mb.write_file( TEST_FILE, "MOAB" );
   CHECK_ERR(rval);
  
-  MBEntityHandle file;
+  EntityHandle file;
   std::string opt( READ_OPTS );
   if (contents)
     opt += ";CHILDREN=NONE;SETS=";
@@ -1162,12 +1164,12 @@
 
 void test_gather_sets_ranged( bool contents, GatherTestMode mode )
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
-  MBRange verts;
-  MBTag id_tag;
+  Range verts;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   
@@ -1175,7 +1177,7 @@
     // have the same x-coordinate
   const int NUM_GRP_VTX = 20;
   const int NUM_GRP = 4;
-  MBEntityHandle sets[NUM_GRP];
+  EntityHandle sets[NUM_GRP];
   for (int i = 0; i < NUM_GRP; ++i) {
     double coords[3*NUM_GRP_VTX];
     for (int j = 0; j < NUM_GRP_VTX; ++j) {
@@ -1217,7 +1219,7 @@
     opt += ";SETS=NONE;CHILDREN=";
   opt += set_read_opts[mode];
 
-  MBEntityHandle file;
+  EntityHandle file;
   const int read_id = 3;
   rval = mb.delete_mesh(); CHECK_ERR(rval);
   rval = mb.create_meshset( MESHSET_SET, file ); CHECK_ERR(rval);
@@ -1225,7 +1227,7 @@
   CHECK_ERR(rval);
   
     // get any sets that were read it
-  MBRange read_sets;
+  Range read_sets;
   rval = mb.get_entities_by_type( file, MBENTITYSET, read_sets );
   CHECK_ERR(rval);
   
@@ -1235,7 +1237,7 @@
   verts.clear();
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
-  for (MBRange::iterator it = verts.begin(); it != verts.end(); ++it) {
+  for (Range::iterator it = verts.begin(); it != verts.end(); ++it) {
     double coords[3];
     rval = mb.get_coords( &*it, 1, coords );
     CHECK_ERR(rval);
@@ -1264,16 +1266,16 @@
   }
 }
 
-static void check_num_verts( MBInterface& mb, MBTag tag, int id, int num_vtx )
+static void check_num_verts( Interface& mb, Tag tag, int id, int num_vtx )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   const void* val[] = {&id};
-  MBRange range;
+  Range range;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, val, 1, range );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)range.size() );
 
-  MBEntityHandle set = range.front();
+  EntityHandle set = range.front();
   range.clear();
   rval = mb.get_entities_by_type( set, MBVERTEX, range );
   CHECK_ERR(rval);
@@ -1292,9 +1294,9 @@
     // such that adjacent sets share vertices.
   create_mesh( false, true, false, false );
   
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
     // read some sets
   const int ids[] = { 1, 5, 9 };
@@ -1302,31 +1304,31 @@
   rval = mb.load_file( TEST_FILE, 0, READ_OPTS, ID_TAG_NAME, ids, num_sets );
   CHECK_ERR(rval);
 
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
     // expect all sets adjacent to the specified sets because
     // they share vertices.
-  MBRange verts;
+  Range verts;
   for (int i = 0; i < num_sets; ++i) {
     if (ids[i] > 1)
-      check_num_verts( mb, id_tag, ids[i]-1, QUAD_INT+1 );
-    check_num_verts( mb, id_tag, ids[i], (QUAD_INT+1)*(SET_WIDTH+1) );
+      check_num_verts( mb, id_tag, ids[i]-1, MBQUAD_INT+1 );
+    check_num_verts( mb, id_tag, ids[i], (MBQUAD_INT+1)*(SET_WIDTH+1) );
     if (ids[i] < NUM_SETS)
-      check_num_verts( mb, id_tag, ids[i]+1, QUAD_INT+1 );
+      check_num_verts( mb, id_tag, ids[i]+1, MBQUAD_INT+1 );
   }
 }
 
 //! Test reading of explicit adjacencies
 void test_read_adjacencies()
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
     // create four hexes sharing an edge
-  MBEntityHandle verts[3][3][2], hexes[2][2];
+  EntityHandle verts[3][3][2], hexes[2][2];
   for (int k = 0; k < 2; ++k) {
     for (int j = 0; j < 3; ++j) {
       for (int i = 0; i < 3; ++i) {
@@ -1338,7 +1340,7 @@
   }
   for (int j = 0; j < 2; ++j) {
     for (int i = 0; i < 2; ++i) {
-      MBEntityHandle conn[] = { verts[i  ][j  ][0],
+      EntityHandle conn[] = { verts[i  ][j  ][0],
                                 verts[i+1][j  ][0],
                                 verts[i+1][j+1][0],
                                 verts[i  ][j+1][0],
@@ -1352,8 +1354,8 @@
   }
   
     // create two duplicate edges that connect the vertices common to all four hexes
-  MBEntityHandle edge_conn[2] = { verts[1][1][0], verts[1][1][1] };
-  MBEntityHandle edges[2];
+  EntityHandle edge_conn[2] = { verts[1][1][0], verts[1][1][1] };
+  EntityHandle edges[2];
   rval = mb.create_element( MBEDGE, edge_conn, 2, edges[0] ); CHECK_ERR(rval);
   rval = mb.create_element( MBEDGE, edge_conn, 2, edges[1] ); CHECK_ERR(rval);
     // mark one edge as adjacent to the left two hexes and the
@@ -1362,16 +1364,16 @@
   rval = mb.add_adjacencies( edges[1], hexes[1], 2, true ); CHECK_ERR(rval);
     // create two sets containing the front two and the rear two
     // hexes, respectively.
-  MBEntityHandle sets[2];
+  EntityHandle sets[2];
   rval = mb.create_meshset( MESHSET_SET, sets[0] ); CHECK_ERR(rval);
   rval = mb.create_meshset( MESHSET_SET, sets[1] ); CHECK_ERR(rval);
-  MBEntityHandle set1[4] = { hexes[0][0], hexes[1][0], edges[0], edges[1] };
-  MBEntityHandle set2[4] = { hexes[0][1], hexes[1][1], edges[0], edges[1] };
+  EntityHandle set1[4] = { hexes[0][0], hexes[1][0], edges[0], edges[1] };
+  EntityHandle set2[4] = { hexes[0][1], hexes[1][1], edges[0], edges[1] };
   rval = mb.add_entities( sets[0], set1, 4 ); CHECK_ERR(rval);
   rval = mb.add_entities( sets[1], set2, 4 ); CHECK_ERR(rval);
   
     // assign IDs to sets
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   int ids[2] = { 1, 2 };
@@ -1388,11 +1390,11 @@
   CHECK_ERR(rval);
   
     // expect two hexes and two edges
-  MBRange range;
+  Range range;
   rval = mb.get_entities_by_type( 0, MBHEX, range );
   CHECK_ERR(rval);
   CHECK_EQUAL( 2, (int)range.size() );
-  MBEntityHandle h1 = range.front(), h2 = range.back();
+  EntityHandle h1 = range.front(), h2 = range.back();
   range.clear();
   rval = mb.get_entities_by_type( 0, MBEDGE, range );
   CHECK_ERR(rval);
@@ -1403,12 +1405,12 @@
   rval = mb.get_adjacencies( &h1, 1, 1, false, range );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)range.size() ); 
-  MBEntityHandle e1 = range.front();
+  EntityHandle e1 = range.front();
   range.clear();
   rval = mb.get_adjacencies( &h2, 1, 1, false, range );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)range.size() ); 
-  MBEntityHandle e2 = range.front();
+  EntityHandle e2 = range.front();
   
   CHECK( e1 != e2 );
 }
@@ -1416,13 +1418,13 @@
 
 void test_read_sides()
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface& mb = instance;
+  ErrorCode rval;
+  Core instance;
+  Interface& mb = instance;
   
     // create 4x4 grid of quads with edges
   const int INT = 4;
-  MBEntityHandle verts[INT+1][INT+1];
+  EntityHandle verts[INT+1][INT+1];
   for (int j = 0; j <= INT; ++j) {
     for (int i = 0; i <= INT; ++i) {
       double coords[3] = { i, j, 0 };
@@ -1430,10 +1432,10 @@
       CHECK_ERR(rval);
     }
   }
-  MBEntityHandle quads[INT][INT];
+  EntityHandle quads[INT][INT];
   for (int j = 0; j < INT; ++j) {
     for (int i = 0; i < INT; ++i) {
-      MBEntityHandle conn[4] = { verts[INT-j][i],
+      EntityHandle conn[4] = { verts[INT-j][i],
                                  verts[INT-j][i+1],
                                  verts[INT-j-1][i+1],
                                  verts[INT-j-1][i] };
@@ -1441,13 +1443,13 @@
       CHECK_ERR(rval);
     }
   }
-  MBRange edges;
-  rval = mb.get_adjacencies( &quads[0][0], INT*INT, 1, true, edges, MBInterface::UNION );
+  Range edges;
+  rval = mb.get_adjacencies( &quads[0][0], INT*INT, 1, true, edges, Interface::UNION );
   CHECK_ERR(rval);
   CHECK_EQUAL( 40, (int)edges.size() );
   
     // group quads into two sets
-  MBEntityHandle sets[2];
+  EntityHandle sets[2];
   rval = mb.create_meshset( MESHSET_SET, sets[0] ); CHECK_ERR(rval);
   rval = mb.create_meshset( MESHSET_SET, sets[1] ); CHECK_ERR(rval);
   rval = mb.add_entities( sets[0], quads[0], INT ); CHECK_ERR(rval);
@@ -1456,7 +1458,7 @@
   rval = mb.add_entities( sets[1], quads[3], INT ); CHECK_ERR(rval);
   
     // assign IDS
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id_tag, 0 );
   CHECK_ERR(rval);
   int ids[2] = { 4, 5 };
@@ -1485,10 +1487,10 @@
   CHECK_EQUAL( 2*(INT+1) + INT*INT, count );
 
     // check edges adjacent to each quad
-  MBRange elems;
+  Range elems;
   rval = mb.get_entities_by_type( 0, MBQUAD, elems );
   CHECK_ERR(rval);
-  for (MBRange::iterator it = elems.begin(); it != elems.end(); ++it) {
+  for (Range::iterator it = elems.begin(); it != elems.end(); ++it) {
     edges.clear();
     rval = mb.get_adjacencies( &*it, 1, 1, false, edges );
     CHECK_ERR(rval);
@@ -1501,19 +1503,19 @@
 
 void write_id_test_file()
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create 12 entity sets
-  MBEntityHandle sets[12];
+  EntityHandle sets[12];
   for (int i = 0; i < 12; ++i) {
     rval = mb.create_meshset( MESHSET_SET, sets[i] );
     CHECK_ERR(rval);
   }
   
     // create tag handles
-  MBTag id = 0, gid = 0, dim = 0;
+  Tag id = 0, gid = 0, dim = 0;
   mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id, 0 );
   mb.tag_create( GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, dim, 0 );
   mb.tag_create( GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, gid, 0 );
@@ -1549,10 +1551,10 @@
 {
   write_id_test_file();
   
-  MBCore moab;
+  Core moab;
   ReadHDF5 reader(&moab);
   FileOptions opts("");
-  MBErrorCode rval;
+  ErrorCode rval;
   std::vector<int> values;
   rval = reader.read_tag_values( TEST_FILE, ID_TAG_NAME, opts, values );
   remove( TEST_FILE );
@@ -1568,12 +1570,12 @@
   write_id_test_file();
   
   const int three = 3;
-  MBReaderIface::IDTag vols = { GEOM_DIMENSION_TAG_NAME, &three, 1 };
+  ReaderIface::IDTag vols = { GEOM_DIMENSION_TAG_NAME, &three, 1 };
   
-  MBCore moab;
+  Core moab;
   ReadHDF5 reader(&moab);
   FileOptions opts("");
-  MBErrorCode rval;
+  ErrorCode rval;
   std::vector<int> values;
   rval = reader.read_tag_values( TEST_FILE, GLOBAL_ID_TAG_NAME, opts, values, &vols, 1 );
   remove( TEST_FILE );

Modified: MOAB/trunk/test/h5file/h5regression.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5regression.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5regression.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "TestUtil.hpp"
-#include "MBRange.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Range.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "WriteHDF5.hpp"
 #include "FileOptions.hpp"
 
@@ -10,6 +10,8 @@
 #include <stdlib.h>
 #include <math.h>
 
+using namespace moab;
+
 const char filename[] = "bad.h5m";
   
 void test_write_invalid_elem();
@@ -24,19 +26,19 @@
   
 void test_write_invalid_elem()
 {
-  MBCore mbcore;
-  MBInterface& moab = mbcore;
-  MBReadUtilIface* readtool = 0;
-  MBErrorCode rval;
+  Core mbcore;
+  Interface& moab = mbcore;
+  ReadUtilIface* readtool = 0;
+  ErrorCode rval;
   
   void* ptr = 0;
-  rval = moab.query_interface( "MBReadUtilIface", &ptr );
+  rval = moab.query_interface( "ReadUtilIface", &ptr );
   CHECK_ERR(rval);
   CHECK( ptr != 0 );
-  readtool = reinterpret_cast<MBReadUtilIface*>(ptr);
+  readtool = reinterpret_cast<ReadUtilIface*>(ptr);
   
     // create two nodes
-  MBEntityHandle first_node;
+  EntityHandle first_node;
   std::vector<double*> coords;
   rval = readtool->get_node_arrays( 3, 2, 1, first_node, coords );
   CHECK_ERR(rval);
@@ -46,8 +48,8 @@
   
     // create a triangle with an invalid node handle for its
     // third vertex
-  MBEntityHandle tri;
-  MBEntityHandle* conn = 0;
+  EntityHandle tri;
+  EntityHandle* conn = 0;
   rval = readtool->get_element_array( 1, 3, MBTRI, 1, tri, conn );
   CHECK_ERR(rval);
   conn[0] = first_node;   // valid

Modified: MOAB/trunk/test/h5file/h5sets_test.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5sets_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5sets_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,6 @@
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "TestUtil.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 
 #include <algorithm>
 #include <iostream>
@@ -8,12 +8,14 @@
 #include <stdlib.h>
 #include <math.h>
 
+using namespace moab;
+
 const char filename[] = "sets.h5m";
 bool keep_file = false;
 
-void read_write_file( MBInterface& output, MBInterface& input, MBEntityHandle* input_set = 0 )
+void read_write_file( Interface& output, Interface& input, EntityHandle* input_set = 0 )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   rval = output.write_file( filename );
   CHECK_ERR(rval);
   if (input_set) {
@@ -28,10 +30,10 @@
 
 void test_ranged_set_with_holes()
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
-  MBRange verts;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
+  Range verts;
   
   const int num_vtx = 40;
   std::vector<double> coords( 3*num_vtx, 0.0 );
@@ -39,28 +41,28 @@
   CHECK_ERR(rval);
   CHECK_EQUAL(num_vtx, (int)verts.size());
   
-  MBEntityHandle set;
+  EntityHandle set;
   rval = mb.create_meshset( MESHSET_SET, set );
   CHECK_ERR(rval);
   rval = mb.add_entities( set, verts );
   
-  std::vector<MBEntityHandle> dead_verts;
+  std::vector<EntityHandle> dead_verts;
   for (int i = num_vtx/4; i < num_vtx; i += num_vtx/4 ) {
-    MBRange::iterator j = verts.begin();
+    Range::iterator j = verts.begin();
     j += i;
     dead_verts.push_back( *j );
   }
   rval = mb.delete_entities( &dead_verts[0], dead_verts.size() );
   CHECK_ERR(rval);
   
-  MBCore moab2;
-  MBInterface& mb2 = moab2;
-  MBEntityHandle file_set;
+  Core moab2;
+  Interface& mb2 = moab2;
+  EntityHandle file_set;
   read_write_file( mb, mb2, &file_set );
-  MBRange sets;
+  Range sets;
   mb2.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_EQUAL( 2, (int)sets.size() );
-  MBEntityHandle other_set = sets.front() == file_set ? sets.back() : sets.front();
+  EntityHandle other_set = sets.front() == file_set ? sets.back() : sets.front();
   
   int num_vtx2 = -5;
   rval = mb2.get_number_entities_by_type( other_set, MBVERTEX, num_vtx2 );
@@ -70,29 +72,29 @@
 
 void test_file_set()
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
   double vtxcoords[] = { 0.0, 0.0, 0.0, 
                          1.0, 0.0, 0.0, 
                          0.0, 1.0, 0.0 };
-  MBRange verts;
+  Range verts;
   rval = moab.create_vertices( vtxcoords, 3, verts );
   CHECK_ERR(rval);
   CHECK_EQUAL( 3, (int)verts.size() );
   
-  MBEntityHandle tri;
-  MBEntityHandle conn[3];
+  EntityHandle tri;
+  EntityHandle conn[3];
   std::copy( verts.begin(), verts.end(), conn );
   rval = moab.create_element( MBTRI, conn, 3, tri );
   CHECK_ERR(rval);
   
-  MBEntityHandle set;
+  EntityHandle set;
   rval = moab.create_meshset( MESHSET_ORDERED, set );
   CHECK_ERR(rval);
   rval = moab.add_entities( set, &tri, 1 );
   CHECK_ERR(rval);
   
-  MBEntityHandle file;
+  EntityHandle file;
   read_write_file( moab, moab, &file );
   
   int count;
@@ -143,15 +145,15 @@
 }
 
 void recursive_build_tree( int max_depth,
-                           MBInterface& mb,
-                           MBTag tag,
-                           MBEntityHandle p,
+                           Interface& mb,
+                           Tag tag,
+                           EntityHandle p,
                            int depth,
                            int& idx )
 {
-  MBErrorCode rval = mb.tag_set_data( tag, &p, 1, &idx ); CHECK_ERR(rval);
+  ErrorCode rval = mb.tag_set_data( tag, &p, 1, &idx ); CHECK_ERR(rval);
   
-  MBRange verts;
+  Range verts;
   double coords[6][3];
   int num_vtx = coords_by_idx( idx, coords );
   rval = mb.create_vertices( &coords[0][0], num_vtx, verts );
@@ -160,7 +162,7 @@
   if (depth == max_depth)
     return;
 
-  MBEntityHandle l, r;
+  EntityHandle l, r;
   rval = mb.create_meshset( MESHSET_SET, l ); CHECK_ERR(rval);
   rval = mb.create_meshset( MESHSET_SET, r ); CHECK_ERR(rval);
   rval = mb.add_parent_child( p, l ); CHECK_ERR(rval);
@@ -171,17 +173,17 @@
 }
  
 void recursive_check_tree( int max_depth,
-                           MBInterface& mb,
-                           MBTag tag,
-                           MBEntityHandle p,
+                           Interface& mb,
+                           Tag tag,
+                           EntityHandle p,
                            int depth,
                            int& idx )
 {
   int id;
-  MBErrorCode rval = mb.tag_get_data( tag, &p, 1, &id); CHECK_ERR(rval);
+  ErrorCode rval = mb.tag_get_data( tag, &p, 1, &id); CHECK_ERR(rval);
   CHECK_EQUAL( idx, id );
   
-  MBRange verts;
+  Range verts;
   double coords[6][3];
   int num_vtx = coords_by_idx( idx, coords );
   rval = mb.get_entities_by_handle( p, verts );
@@ -214,7 +216,7 @@
  
   ++idx;
   
-  std::vector<MBEntityHandle> children, parents;
+  std::vector<EntityHandle> children, parents;
 
   rval = mb.get_child_meshsets( p, children ); CHECK_ERR(rval);
   if (depth == max_depth) {
@@ -223,8 +225,8 @@
   }
   
   CHECK_EQUAL( (size_t)2, children.size() );
-  MBEntityHandle l = children.front();
-  MBEntityHandle r = children.back();
+  EntityHandle l = children.front();
+  EntityHandle r = children.back();
   
   parents.clear();
   rval = mb.get_parent_meshsets( l, parents ); CHECK_ERR(rval);
@@ -242,14 +244,14 @@
 
 void test_tree( int max_depth ) 
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBEntityHandle root;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  EntityHandle root;
   
   // create tag in which to store number for each tree node,
   // in depth-first in-order search order.
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_get_handle( "GLOBAL_ID", tag ); CHECK_ERR(rval);
   
   // create a binary tree to a depth of 20 (about 1 million nodes)
@@ -272,11 +274,11 @@
   
   // get tree root
   rval = mb.tag_get_handle( "GLOBAL_ID", tag ); CHECK_ERR(rval);
-  MBRange roots;
+  Range roots;
   idx = 1;
   const void* vals[] = {&idx};
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, vals, 1, roots );
-  CHECK_EQUAL( (MBEntityHandle)1, roots.size() );
+  CHECK_EQUAL( (EntityHandle)1, roots.size() );
   root = roots.front();
   
   // check that tree is as we expect it

Modified: MOAB/trunk/test/h5file/h5varlen.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5varlen.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/h5file/h5varlen.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "TestUtil.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include <stdlib.h>
 #include <stdio.h>
 
+using namespace moab;
+
 static bool keep_files = false;
 
 void test_var_length_no_data();
@@ -26,13 +28,13 @@
 
 void test_var_length_handle_tag();
 
-void create_mesh( MBInterface& mb );
+void create_mesh( Interface& mb );
 
-void create_big_mesh( MBInterface& mb );
+void create_big_mesh( Interface& mb );
 
-void compare_tags( const char* name, MBInterface& mb1, MBInterface& mb2 );
+void compare_tags( const char* name, Interface& mb1, Interface& mb2 );
 
-void read_write( const char* filename, MBInterface& write, MBInterface& reader );
+void read_write( const char* filename, Interface& write, Interface& reader );
 
 #define CHECK_ERR_FILE( ERRCODE, FILENAME ) \
 do { \
@@ -67,10 +69,10 @@
 
 void test_var_length_no_data()
 {
-  MBErrorCode rval;
-  MBCore moab1, moab2;
-  MBInterface &mb1 = moab1, &mb2 = moab2;
-  MBTag tag;
+  ErrorCode rval;
+  Core moab1, moab2;
+  Interface &mb1 = moab1, &mb2 = moab2;
+  Tag tag;
   
   create_mesh( mb1 );
   rval = mb1.tag_create_variable_length( "test_tag", MB_TAG_DENSE, MB_TYPE_DOUBLE, tag );
@@ -80,17 +82,17 @@
   compare_tags( "test_tag", mb1, mb2 );
 }
 
-void test_var_length_data_common( const char* filename, MBInterface& mb1, bool opaque = false )
+void test_var_length_data_common( const char* filename, Interface& mb1, bool opaque = false )
 {
     // create tag
-  MBErrorCode rval;
-  MBTag tag;
-  MBDataType type = opaque ? MB_TYPE_OPAQUE : MB_TYPE_INTEGER;
+  ErrorCode rval;
+  Tag tag;
+  DataType type = opaque ? MB_TYPE_OPAQUE : MB_TYPE_INTEGER;
   rval = mb1.tag_create_variable_length( "test_tag", MB_TAG_SPARSE, type, tag );
   CHECK_ERR( rval );
   
     // get all entities
-  MBRange entities;
+  Range entities;
   rval = mb1.get_entities_by_handle( 0, entities );
   CHECK_ERR(rval);
   
@@ -98,11 +100,11 @@
     // Tag data will be list of integer data as follows:
     //   number of values (counting this value)
     //   step, 2*step, 3*step, ...
-  for (MBRange::const_iterator i = entities.begin(); i != entities.end(); ++i) {
-    MBEntityHandle h = *i;
+  for (Range::const_iterator i = entities.begin(); i != entities.end(); ++i) {
+    EntityHandle h = *i;
       // generate some data to write
     int num_values = h % 6 + 1;
-    MBEntityType type = mb1.type_from_handle(h);
+    EntityType type = mb1.type_from_handle(h);
     int step = (h%2) ? 1+(int)type : -1-(int)type;
     std::vector<int> tag_data( num_values, num_values );
     for (int j = 1; j < num_values; ++j)
@@ -115,8 +117,8 @@
   }
   
     // write and read tag data
-  MBCore moab;
-  MBInterface &mb2 = moab;
+  Core moab;
+  Interface &mb2 = moab;
   read_write( filename, mb1, mb2 );
   compare_tags( "test_tag", mb1, mb2 );
   
@@ -129,10 +131,10 @@
   entities.clear();
   mb2.get_entities_by_handle( 0, entities );
     // remove sets created during read/write process
-  MBRange sets;
+  Range sets;
   mb2.get_entities_by_type( 0, MBENTITYSET, sets );
   entities = subtract( entities, sets);
-  for (MBRange::const_iterator i = entities.begin(); i != entities.end(); ++i) {
+  for (Range::const_iterator i = entities.begin(); i != entities.end(); ++i) {
       // get data
     const void* ptrarr[] = { NULL };
     int size;
@@ -156,26 +158,26 @@
 
 void test_var_length_data()
 {
-  MBCore moab;
+  Core moab;
   create_mesh( moab );
   test_var_length_data_common( "test_var_length_data.h5m", moab );
 }
 
 void test_var_length_data_big()
 {
-  MBCore moab;
+  Core moab;
   create_big_mesh( moab );
   test_var_length_data_common( "test_var_length_data_big.h5m", moab );
 }
 
 
-void calculate_big_value( MBInterface& moab, MBEntityHandle vert, size_t size, double* data )
+void calculate_big_value( Interface& moab, EntityHandle vert, size_t size, double* data )
 {
     // Make values like Fibonacci numbers, except use X and Y coords
     // rather than 0 and 1 as first two values.
 
   CHECK( size >= 3 );
-  MBErrorCode rval = moab.get_coords( &vert, 1, data );
+  ErrorCode rval = moab.get_coords( &vert, 1, data );
   CHECK_ERR(rval);
 
   for (size_t j = 2; j < size; ++j)
@@ -186,20 +188,20 @@
 
 void test_var_length_big_data()
 {
-  MBErrorCode rval;
-  MBCore moab1, moab2;
-  MBInterface &mb1 = moab1, &mb2 = moab2;
-  MBTag tag;
+  ErrorCode rval;
+  Core moab1, moab2;
+  Interface &mb1 = moab1, &mb2 = moab2;
+  Tag tag;
   
   create_mesh( mb1 );
   rval = mb1.tag_create_variable_length( "test_tag", MB_TAG_SPARSE, MB_TYPE_DOUBLE, tag );
   CHECK_ERR( rval );
   
     // choose 3 vertices upon which to set data
-  MBRange range;
+  Range range;
   rval = mb1.get_entities_by_type( 0, MBVERTEX, range );
   CHECK_ERR(rval);
-  MBEntityHandle verts[3] = { range.front(), 
+  EntityHandle verts[3] = { range.front(), 
                               *(range.begin() += range.size()/3), 
                               *(range.begin() += 2*range.size()/3) };
   
@@ -220,14 +222,14 @@
   rval = mb2.tag_get_handle( "test_tag", tag );
   CHECK_ERR(rval);
   range.clear();
-  rval = mb2.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, range, MBInterface::UNION );
+  rval = mb2.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, range, Interface::UNION );
   CHECK_ERR(rval);
-  CHECK_EQUAL( range.size(), (MBEntityHandle)3 );
+  CHECK_EQUAL( range.size(), (EntityHandle)3 );
   
     // check tag values
-  for (MBRange::const_iterator i = range.begin(); i != range.end(); ++i) {
+  for (Range::const_iterator i = range.begin(); i != range.end(); ++i) {
       // calculate expected value
-    const MBEntityHandle h = *i;
+    const EntityHandle h = *i;
     calculate_big_value( mb2, h, data.size(), &data[0] );
     
       // get actual value
@@ -251,24 +253,24 @@
 
 void test_var_length_opaque()
 {
-  MBCore moab;
+  Core moab;
   create_mesh( moab );
   test_var_length_data_common( "test_var_length_opaque.h5m", moab, true );  
 }
 
 void test_global_value_common( bool mesh_value )
 {
-  MBCore moab;
-  MBInterface &mb = moab;
+  Core moab;
+  Interface &mb = moab;
   create_mesh( mb );
   
   // get three vertices
-  MBRange vertices;
-  MBErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, vertices );
+  Range vertices;
+  ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, vertices );
   CHECK_ERR(rval);
   CHECK( vertices.size() >= 3 );
-  MBEntityHandle handles[3];
-  MBRange::const_iterator i = vertices.begin();
+  EntityHandle handles[3];
+  Range::const_iterator i = vertices.begin();
   handles[0] = *i; ++i;
   handles[1] = *i; ++i;
   handles[2] = *i; ++i;
@@ -279,15 +281,15 @@
   CHECK_ERR( rval );
   
   // create tag to hold vertex data
-  MBTag handle_tag = 0;
+  Tag handle_tag = 0;
   void* default_val = mesh_value ? 0 : handles;
-  int default_val_size = mesh_value ? 0 : 3*sizeof(MBEntityHandle);
+  int default_val_size = mesh_value ? 0 : 3*sizeof(EntityHandle);
   rval = mb.tag_create_variable_length( "handle_tag", MB_TAG_DENSE, MB_TYPE_HANDLE, handle_tag, 
                                         default_val, default_val_size );
   CHECK_ERR( rval );
   
   // create tag to hold vertex coordinates
-  MBTag coord_tag = 0;
+  Tag coord_tag = 0;
   default_val = mesh_value ? 0 : coords;
   default_val_size = mesh_value ? 0 : 9*sizeof(double);
   rval = mb.tag_create_variable_length( "coord_tag", MB_TAG_SPARSE, MB_TYPE_DOUBLE, coord_tag, 
@@ -297,7 +299,7 @@
   
   // if doing mesh tag, set it
   if (mesh_value) {
-    int size = 3*sizeof(MBEntityHandle);
+    int size = 3*sizeof(EntityHandle);
     const void* ptrarr[] = { handles };
     rval = mb.tag_set_data( handle_tag, 0, 0, ptrarr, &size );
     CHECK_ERR(rval);
@@ -309,8 +311,8 @@
   }
   
     // write and read file
-  MBCore moab2;
-  MBInterface &mb2 = moab2;
+  Core moab2;
+  Interface &mb2 = moab2;
   read_write( mesh_value ? "test_var_length_mesh_data.h5m" : "test_var_length_default_data.h5m", mb, mb2 );
   compare_tags( "handle_tag", mb, mb2 );
   compare_tags( "coord_tag", mb, mb2 );
@@ -339,13 +341,13 @@
   }
   
     // check expected sizes
-  CHECK_EQUAL( 3*sizeof(MBEntityHandle), (size_t)handle_tag_size );
+  CHECK_EQUAL( 3*sizeof(EntityHandle), (size_t)handle_tag_size );
   CHECK_EQUAL( 9*sizeof(double), (size_t)coord_tag_size );
   CHECK( ptrs[0] != NULL );
   CHECK( ptrs[1] != NULL );
   
     // check valid handles
-  const MBEntityHandle* handle_vals = reinterpret_cast<const MBEntityHandle*>(ptrs[0]);
+  const EntityHandle* handle_vals = reinterpret_cast<const EntityHandle*>(ptrs[0]);
   CHECK( handle_vals[0] != 0 );
   CHECK( handle_vals[1] != 0 );
   CHECK( handle_vals[2] != 0 );
@@ -380,9 +382,9 @@
 
 void test_global_opaque_common( bool mesh_value )
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface &mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
   create_mesh( mb );
   
   const char data[] = { 'J', 'A', 'S', 'O', 'N' };
@@ -390,7 +392,7 @@
   CHECK_EQUAL( 5, datalen );
   
   // create tag 
-  MBTag tag = 0;
+  Tag tag = 0;
   const void* default_val = mesh_value ? 0 : data;
   int default_val_size = mesh_value ? 0 : datalen;
   rval = mb.tag_create_variable_length( "opaque_tag", MB_TAG_DENSE, MB_TYPE_OPAQUE, tag, 
@@ -405,8 +407,8 @@
   }
   
     // write and read file
-  MBCore moab2;
-  MBInterface &mb2 = moab2;
+  Core moab2;
+  Interface &mb2 = moab2;
   read_write( mesh_value ? "test_var_length_mesh_opaque.h5m" : "test_var_length_default_opaque.h5m", mb, mb2 );
   compare_tags( "opaque_tag", mb, mb2 );
   
@@ -450,30 +452,30 @@
   
 void test_var_length_handle_tag()
 {
-  MBErrorCode rval;
-  MBCore moab1, moab2;
-  MBInterface &mb1 = moab1, &mb2 = moab2;
-  MBTag tag;
-  MBRange::const_iterator  i;
+  ErrorCode rval;
+  Core moab1, moab2;
+  Interface &mb1 = moab1, &mb2 = moab2;
+  Tag tag;
+  Range::const_iterator  i;
   
   create_mesh( mb1 );
   rval = mb1.tag_create_variable_length( "test_tag", MB_TAG_SPARSE, MB_TYPE_HANDLE, tag );
   CHECK_ERR( rval );
   
     // Get all entities
-  MBRange range;
+  Range range;
   rval = mb1.get_entities_by_handle( 0, range );
   CHECK_ERR(rval);
 
     // For each entity, if it is a vertex store its own handle
     // in its tag.  Otherwise store the element connectivity list
     // in the tag.  Skip entity sets.
-  MBEntityHandle num_tagged_entities = 0;
+  EntityHandle num_tagged_entities = 0;
   for (i = range.begin(); i != range.end(); ++i) {
-    MBEntityHandle h = *i;
-    MBEntityType type = mb1.type_from_handle( h );
+    EntityHandle h = *i;
+    EntityType type = mb1.type_from_handle( h );
     if (type == MBVERTEX) {
-      const int size = sizeof(MBEntityHandle);
+      const int size = sizeof(EntityHandle);
       const void* ptr = &h;
       rval = mb1.tag_set_data( tag, &h, 1, &ptr, &size );
       CHECK_ERR(rval);
@@ -481,10 +483,10 @@
     }
     else if (type != MBENTITYSET) {
       int size = 0;
-      const MBEntityHandle* conn = 0;
+      const EntityHandle* conn = 0;
       rval = mb1.get_connectivity( h, conn, size );
       CHECK_ERR(rval);
-      size *= sizeof(MBEntityHandle);
+      size *= sizeof(EntityHandle);
       const void* ptr = conn;
       rval = mb1.tag_set_data( tag, &h, 1, &ptr, &size );
       CHECK_ERR(rval);
@@ -499,24 +501,24 @@
   rval = mb2.tag_get_handle( "test_tag", tag );
   CHECK_ERR(rval);
   range.clear();
-  for (MBEntityType t = MBVERTEX; t != MBENTITYSET; ++t) {
-    rval = mb2.get_entities_by_type_and_tag( 0, t, &tag, 0, 1, range, MBInterface::UNION );
+  for (EntityType t = MBVERTEX; t != MBENTITYSET; ++t) {
+    rval = mb2.get_entities_by_type_and_tag( 0, t, &tag, 0, 1, range, Interface::UNION );
     CHECK_ERR(rval);
   }
   CHECK_EQUAL( num_tagged_entities, range.size() );
   
     // check tag values
   for (i = range.begin(); i != range.end(); ++i) {
-    MBEntityHandle h = *i;
+    EntityHandle h = *i;
     
     const void* ptr;
     int size;
     rval = mb2.tag_get_data( tag, &h, 1, &ptr, &size );
     CHECK_ERR(rval);
     
-    CHECK_EQUAL( (size_t)0, (size_t)size % sizeof(MBEntityHandle) );
-    size /= sizeof(MBEntityHandle);
-    const MBEntityHandle* handles = reinterpret_cast<const MBEntityHandle*>(ptr);
+    CHECK_EQUAL( (size_t)0, (size_t)size % sizeof(EntityHandle) );
+    size /= sizeof(EntityHandle);
+    const EntityHandle* handles = reinterpret_cast<const EntityHandle*>(ptr);
     
     if (mb2.type_from_handle(h) == MBVERTEX) {
       CHECK_EQUAL( 1, size );
@@ -524,7 +526,7 @@
     }
     else {
       int len;
-      const MBEntityHandle* conn;
+      const EntityHandle* conn;
       rval = mb2.get_connectivity( h, conn, len );
       CHECK_ERR(rval);
       CHECK_EQUAL( len, size );
@@ -534,12 +536,12 @@
   }
 }
 
-void create_structured_quad_mesh( MBInterface& mb, int x, int y )
+void create_structured_quad_mesh( Interface& mb, int x, int y )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   const double z = 2.1;
-  std::vector<MBEntityHandle> verts((x+1)*(y+1));
+  std::vector<EntityHandle> verts((x+1)*(y+1));
   for (int i = 0; i <= x; ++i) {
     for (int j = 0; j<= y; ++j) {
       double coords[3] = { i, j, z };
@@ -548,10 +550,10 @@
     }
   }
   
-  std::vector<MBEntityHandle> elems(x*y);
+  std::vector<EntityHandle> elems(x*y);
   for (int i = 0; i < x; ++i) {
     for (int j = 0; j < y; ++j ) {
-      MBEntityHandle conn[4] = { verts[i +     (x+1)* j   ],
+      EntityHandle conn[4] = { verts[i +     (x+1)* j   ],
                                  verts[i + 1 + (x+1)* j   ],
                                  verts[i + 1 + (x+1)*(j+1)],
                                  verts[i +     (x+1)*(j+1)] };
@@ -561,20 +563,20 @@
   }
 }
 
-void create_mesh( MBInterface& mb )
+void create_mesh( Interface& mb )
 {
   create_structured_quad_mesh( mb, 2, 2 );
 }
 
-void create_big_mesh( MBInterface& mb )
+void create_big_mesh( Interface& mb )
 {
   create_structured_quad_mesh( mb, 300, 300 );
 }
 
-void compare_tags( const char* name, MBInterface& mb1, MBInterface& mb2 )
+void compare_tags( const char* name, Interface& mb1, Interface& mb2 )
 {
-  MBErrorCode rval;
-  MBTag tag1, tag2;
+  ErrorCode rval;
+  Tag tag1, tag2;
   rval = mb1.tag_get_handle( name, tag1 );
   CHECK_ERR(rval);
   rval = mb2.tag_get_handle( name, tag2 );
@@ -584,14 +586,14 @@
   CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, mb1.tag_get_size( tag1, size ) );
   CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, mb2.tag_get_size( tag2, size ) );
   
-  MBTagType storage1, storage2;
+  TagType storage1, storage2;
   rval = mb1.tag_get_type( tag1, storage1 );
   CHECK_ERR(rval);
   rval = mb2.tag_get_type( tag2, storage2 );
   CHECK_ERR(rval);
   CHECK_EQUAL( storage1, storage2 );
   
-  MBDataType type1, type2;
+  DataType type1, type2;
   rval = mb1.tag_get_data_type( tag1, type1 );
   CHECK_ERR(rval);
   rval = mb2.tag_get_data_type( tag2, type2 );
@@ -599,8 +601,8 @@
   
   const void *defval1, *defval2;
   int defsize1, defsize2;
-  MBErrorCode rval1 = mb1.tag_get_default_value( tag1, defval1, defsize1 );
-  MBErrorCode rval2 = mb2.tag_get_default_value( tag2, defval2, defsize2 );
+  ErrorCode rval1 = mb1.tag_get_default_value( tag1, defval1, defsize1 );
+  ErrorCode rval2 = mb2.tag_get_default_value( tag2, defval2, defsize2 );
   if (MB_SUCCESS == rval1) {
     CHECK_ERR(rval2);
  
@@ -614,9 +616,9 @@
   
 }
 
-void read_write( const char* filename, MBInterface& writer, MBInterface& reader )
+void read_write( const char* filename, Interface& writer, Interface& reader )
 {
-  MBErrorCode rval = writer.write_mesh( filename );
+  ErrorCode rval = writer.write_mesh( filename );
   if (!keep_files && MB_SUCCESS != rval)
     remove( filename );
   CHECK_ERR(rval);

Modified: MOAB/trunk/test/internals_test.cpp
===================================================================
--- MOAB/trunk/test/internals_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/internals_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #include <iostream>
 using namespace std;
 
-MBHandleUtils handleUtils(0,1);
+using namespace moab;
 
+HandleUtils handleUtils(0,1);
+
 bool internal_assert( bool c ) { return !c; }
 
 #define handle_test_assert( C ) \
@@ -12,20 +14,20 @@
     return false; \
   }
 
-bool handle_test( MBEntityType type, MBEntityID id, int proc, bool should_fail )
+bool handle_test( EntityType type, EntityID id, int proc, bool should_fail )
 {
   int err = 0;
-  MBEntityHandle handle = CREATE_HANDLE( type, handleUtils.create_id(id, proc), err );
+  EntityHandle handle = CREATE_HANDLE( type, handleUtils.create_id(id, proc), err );
   if (should_fail) {
     handle_test_assert( err )
     return true;
   }
   handle_test_assert( !err )
   
-  MBEntityType type_from_handle = TYPE_FROM_HANDLE(handle);
+  EntityType type_from_handle = TYPE_FROM_HANDLE(handle);
   handle_test_assert( type_from_handle == type )
   
-  MBEntityID id_from_handle = handleUtils.id_from_handle(handle);
+  EntityID id_from_handle = handleUtils.id_from_handle(handle);
   handle_test_assert( id_from_handle == id )
   
   int proc_from_handle = handleUtils.rank_from_handle(handle);
@@ -40,14 +42,14 @@
     return false; \
   }
 
-bool tag_test( MBTagId id, MBTagType prop )
+bool tag_test( TagId id, TagType prop )
 {
-  MBTag tag = TAG_HANDLE_FROM_ID( id, prop );
+  Tag tag = TAG_HANDLE_FROM_ID( id, prop );
   
   unsigned long id_from_handle = ID_FROM_TAG_HANDLE(tag);
   tag_test_assert( id_from_handle == id )
   
-  MBTagType prop_from_handle = PROP_FROM_TAG_HANDLE(tag);
+  TagType prop_from_handle = PROP_FROM_TAG_HANDLE(tag);
   tag_test_assert( prop_from_handle == prop )
   
   return true;
@@ -64,13 +66,13 @@
   
   ++tests;
   if (MB_TAG_LAST > num_prop) {
-    cout << "MB_TAG_PROP_WIDTH insufficient for size of MBTagType" << endl;
+    cout << "MB_TAG_PROP_WIDTH insufficient for size of TagType" << endl;
     ++errors;
   }
   
   ++tests;
   if (MBMAXTYPE > 1<<MB_TYPE_WIDTH) {
-    cout << "MB_TYPE_WIDTH insufficient for size of MBEntityType" << endl;
+    cout << "MB_TYPE_WIDTH insufficient for size of EntityType" << endl;
     ++errors;
   }
   
@@ -81,16 +83,16 @@
   
   for (int num_cpu = 0; num_cpu < num_cpus; ++num_cpu) {
     
-    handleUtils = MBHandleUtils( 0, cpus[num_cpu] );
+    handleUtils = HandleUtils( 0, cpus[num_cpu] );
     
     // init these after setting num_cpu, because max id depends on num cpu.
-    const MBEntityID ids[] = {0, 1, handleUtils.max_id()/2, handleUtils.max_id()-1, handleUtils.max_id()};
-    const MBTagId tids[] = {0, 1, MB_TAG_PROP_MASK/2, MB_TAG_PROP_MASK-1, MB_TAG_PROP_MASK};
+    const EntityID ids[] = {0, 1, handleUtils.max_id()/2, handleUtils.max_id()-1, handleUtils.max_id()};
+    const TagId tids[] = {0, 1, MB_TAG_PROP_MASK/2, MB_TAG_PROP_MASK-1, MB_TAG_PROP_MASK};
     const int num_ids = sizeof(ids)/sizeof(ids[0]);
     const int num_tids = sizeof(tids)/sizeof(tids[0]);
     
     for (unsigned cpu = 0; cpu < cpus[num_cpu]; ++cpu) {
-      for (MBEntityType type = MBVERTEX; type < MBMAXTYPE; ++type) 
+      for (EntityType type = MBVERTEX; type < MBMAXTYPE; ++type) 
         for (int id = 0; id < num_ids; ++id) {
         ++tests;
          if (!handle_test( type, ids[id], cpu, false )) {
@@ -103,7 +105,7 @@
       for (int prop = 0; prop < num_prop; ++prop)
         for (int id = 0; id < num_tids; ++id) {
           ++tests;
-          if (!tag_test( tids[id], (MBTagType)prop )) {
+          if (!tag_test( tids[id], (TagType)prop )) {
             cout << "Test of tag handle with prop=" << prop << ", id=" << tids[id]
                  << ", proc=" << cpu << ", and numproc=" << cpus[num_cpu] << endl;
             ++errors;
@@ -113,14 +115,14 @@
   }
   
     // test some stuff that should fail
-  handleUtils = MBHandleUtils(0, 16);
+  handleUtils = HandleUtils(0, 16);
   ++tests;
   if (!handle_test( MBVERTEX, MB_END_ID+1, 0, true)) {
     cout << "Failed to catch ID overflow" << endl;
     ++errors;
   }
   ++tests;
-  if (!handle_test( (MBEntityType)(MBMAXTYPE+1), 1, 0, true)) {
+  if (!handle_test( (EntityType)(MBMAXTYPE+1), 1, 0, true)) {
     cout << "Failed to catch type overflow" << endl;
     ++errors;
   }

Modified: MOAB/trunk/test/io/CMakeLists.txt
===================================================================
--- MOAB/trunk/test/io/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,10 +4,6 @@
     ${MOAB_BINARY_DIR}/src
     ${MOAB_SOURCE_DIR}/src/parallel
     ${MOAB_BINARY_DIR}/src/parallel
-    ${MOAB_SOURCE_DIR}/src/moab
-    ${MOAB_BINARY_DIR}/src/moab
-    ${MOAB_SOURCE_DIR}/src/parallel/moab
-    ${MOAB_BINARY_DIR}/src/parallel/moab
   )
 
   add_executable( tqdcfr ${MOAB_SOURCE_DIR}/src/io/Tqdcfr.cpp )

Modified: MOAB/trunk/test/io/Makefile.am
===================================================================
--- MOAB/trunk/test/io/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -16,11 +16,7 @@
                -I$(top_builddir)/src \
                -I$(top_srcdir)/src \
                -I$(top_srcdir)/src/io \
-               -I$(top_srcdir)/src/parallel \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_srcdir)/src/io/moab \
-               -I$(top_srcdir)/src/parallel/moab
+               -I$(top_srcdir)/src/parallel
 
 TESTS = tqdcfr \
         vtk_test \

Modified: MOAB/trunk/test/io/VtkTest.cpp
===================================================================
--- MOAB/trunk/test/io/VtkTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/VtkTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,8 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 
+using namespace moab;
+
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -152,31 +154,34 @@
   return fail_count;
 }
 
-#define CHECK(A) if (!(A)) return do_error( #A, __LINE__ )
+#define CHECK(A) if (is_error((A))) return do_error( #A, __LINE__ )
 static bool do_error( const char* string, int line )
 {
   fprintf(stderr, "Check failed at line %d: %s\n", line, string );
   return false;
 }
+static inline bool is_error( bool b )
+  { return !b; }
 
-#define MBCHECK(A) if (MB_SUCCESS != (A)) return do_mb_error( (A), __LINE__ )
-static bool do_mb_error( MBErrorCode err, int line )
+static bool do_error( ErrorCode err, int line )
 {
-  MBCore tmp_core;
+  Core tmp_core;
   fprintf(stderr, "API failed at line %d: %s (%d)\n", 
     line, tmp_core.get_error_string(err).c_str(), (int)err );
   return false;
 }
+static inline bool is_error( ErrorCode b )
+  { return MB_SUCCESS != b; }
 
-bool read_file( MBInterface* iface, const char* file );
-bool write_and_read( MBInterface* iface1, MBInterface* iface2 );
+bool read_file( Interface* iface, const char* file );
+bool write_and_read( Interface* iface1, Interface* iface2 );
 
 
 bool test_read_write_element( const double* coords, unsigned num_coords,
                               const int* vtk_conn, const int* moab_conn,
                               unsigned num_conn,
                               unsigned num_elem, unsigned vtk_type,
-                              MBEntityType moab_type );
+                              EntityType moab_type );
 
 bool test_edge2()
 {
@@ -727,9 +732,9 @@
   return test_structured_3d( file );
 }
 
-bool test_scalar_attrib(const char* vtk_type, MBDataType mb_type, int count);
-bool test_vector_attrib(const char* vtk_type, MBDataType mb_type);
-bool test_tensor_attrib(const char* vtk_type, MBDataType mb_type);
+bool test_scalar_attrib(const char* vtk_type, DataType mb_type, int count);
+bool test_vector_attrib(const char* vtk_type, DataType mb_type);
+bool test_tensor_attrib(const char* vtk_type, DataType mb_type);
 
 bool test_scalar_attrib_1_bit()
 {
@@ -950,31 +955,31 @@
 
 
 
-bool read_file( MBInterface* iface, const char* file )
+bool read_file( Interface* iface, const char* file )
 {
   char fname[] = "tmp_file.vtk";
   FILE* fptr = fopen( fname, "w" );
   fputs( file, fptr ); 
   fclose( fptr );
   
-  MBErrorCode rval = iface->load_mesh( fname );
+  ErrorCode rval = iface->load_mesh( fname );
   remove( fname );
-  MBCHECK(rval);
+  CHECK(rval);
   return true;
 }
 
-bool write_and_read( MBInterface* iface1, MBInterface* iface2 )
+bool write_and_read( Interface* iface1, Interface* iface2 )
 {
   const char fname[] = "tmp_file.vtk";
-  MBErrorCode rval1 = iface1->write_mesh( fname );
-  MBErrorCode rval2 = iface2->load_mesh( fname );
+  ErrorCode rval1 = iface1->write_mesh( fname );
+  ErrorCode rval2 = iface2->load_mesh( fname );
   remove( fname );
-  MBCHECK(rval1);
-  MBCHECK(rval2);
+  CHECK(rval1);
+  CHECK(rval2);
   return true;
 }
 
-bool compare_connectivity( MBEntityType ,
+bool compare_connectivity( EntityType ,
                            const int* conn1,
                            const int* conn2,
                            unsigned len )
@@ -985,40 +990,40 @@
   return true;
 }
 
-bool match_vertices_and_elements( MBInterface* iface,
-                                  MBEntityType moab_type,
+bool match_vertices_and_elements( Interface* iface,
+                                  EntityType moab_type,
                                   unsigned num_vert,
                                   unsigned num_elem,
                                   unsigned vert_per_elem,
                                   const double* coords,
                                   const int* connectivity,
-                                  MBEntityHandle* vert_handles,
-                                  MBEntityHandle* elem_handles )
+                                  EntityHandle* vert_handles,
+                                  EntityHandle* elem_handles )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // get vertices and check count
-  MBRange verts;
+  Range verts;
   rval = iface->get_entities_by_type( 0, MBVERTEX, verts );
-  MBCHECK(rval);
+  CHECK(rval);
   CHECK(verts.size() == num_vert);
   
     // get elements and check count
-  MBRange elems;
+  Range elems;
   rval = iface->get_entities_by_type( 0, moab_type, elems );
-  MBCHECK(rval);
+  CHECK(rval);
   CHECK(elems.size() == num_elem);
   
     // get vertex coordinates
-  std::vector<MBEntityHandle> vert_array(num_vert);
+  std::vector<EntityHandle> vert_array(num_vert);
   std::copy(verts.begin(), verts.end(), vert_array.begin());
   std::vector<double> mb_coords(3*num_vert);
   rval = iface->get_coords( &vert_array[0], num_vert, &mb_coords[0] );
-  MBCHECK(rval);
+  CHECK(rval);
   
     // compare vertex coordinates to construct map from 
-    // MBEntityHandle to index in input coordinate list
-  std::map<MBEntityHandle,int> vert_map;
+    // EntityHandle to index in input coordinate list
+  std::map<EntityHandle,int> vert_map;
   std::vector<bool> seen(num_vert, false);
   for (unsigned i = 0; i < num_vert; ++i) {
     double* vert_coords = &mb_coords[3*i];
@@ -1043,19 +1048,19 @@
   
     // check element connectivity
   seen.clear(); seen.resize( num_elem, false );
-  MBRange::iterator iter = elems.begin();
+  Range::iterator iter = elems.begin();
   for (unsigned i = 0; i < num_elem; ++i) {
       // get element connectivity
-    MBEntityHandle elem = *iter; ++iter;
-    std::vector<MBEntityHandle> elem_conn;
+    EntityHandle elem = *iter; ++iter;
+    std::vector<EntityHandle> elem_conn;
     rval = iface->get_connectivity( &elem, 1, elem_conn );
-    MBCHECK(rval);
+    CHECK(rval);
     CHECK( elem_conn.size() == vert_per_elem );
     
       // convert to input vertex ordering
     std::vector<int> elem_conn2(vert_per_elem);
     for (unsigned j = 0; j < vert_per_elem; ++j) {
-      std::map<MBEntityHandle,int>::iterator k = vert_map.find(elem_conn[j]);
+      std::map<EntityHandle,int>::iterator k = vert_map.find(elem_conn[j]);
       CHECK( k != vert_map.end() );
       elem_conn2[j] = k->second;
     }
@@ -1079,12 +1084,12 @@
 }
 
 
-bool check_elements( MBInterface* iface,
-                     MBEntityType moab_type, unsigned num_elem, unsigned vert_per_elem,
+bool check_elements( Interface* iface,
+                     EntityType moab_type, unsigned num_elem, unsigned vert_per_elem,
                      const double* coords, unsigned num_vert, 
                      const int* connectivity )
 {
-  std::vector<MBEntityHandle> junk1(num_vert), junk2(num_elem);
+  std::vector<EntityHandle> junk1(num_vert), junk2(num_elem);
   bool rval = match_vertices_and_elements( iface, moab_type, num_vert, num_elem, 
                                          vert_per_elem, coords, connectivity,
                                          &junk1[0], &junk2[0] );
@@ -1098,7 +1103,7 @@
                               const int* vtk_conn, const int* moab_conn,
                               unsigned num_conn,
                               unsigned num_elem, unsigned vtk_type,
-                              MBEntityType moab_type )
+                              EntityType moab_type )
       
 {
     // construct VTK file
@@ -1128,7 +1133,7 @@
     len += sprintf(file+len, "%u\n", vtk_type);
   
     // read VTK file and check results
-  MBCore instance1, instance2;
+  Core instance1, instance2;
   bool bval = read_file( &instance1, file ); CHECK(bval);
   bval = check_elements( &instance1, moab_type, num_elem, conn_len, coords, num_verts, moab_conn );
   CHECK(bval);
@@ -1144,7 +1149,7 @@
 bool test_structured_2d( const char* file )
 {
     // read VTK file and check results
-  MBCore instance;
+  Core instance;
   bool bval = read_file( &instance, file ); CHECK(bval);
   bval = check_elements( &instance, MBQUAD, 9, 4, grid_3x3, 16, quad_structured_conn );
   CHECK(bval);
@@ -1155,7 +1160,7 @@
 bool test_structured_3d( const char* file )
 {
     // read VTK file and check results
-  MBCore instance;
+  Core instance;
   bool bval = read_file( &instance, file ); CHECK(bval);
   bval = check_elements( &instance, MBHEX, 8, 8, grid_2x2x2, 27, hex_structured_conn );
   CHECK(bval);
@@ -1205,7 +1210,7 @@
                                1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 
                                0, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
 
-void write_data( char* file, size_t& len, MBDataType type, unsigned count, const int* vals )
+void write_data( char* file, size_t& len, DataType type, unsigned count, const int* vals )
 {
   switch(type) {
     case MB_TYPE_BIT:
@@ -1229,21 +1234,21 @@
   }
 }
 
-bool check_tag_values( MBInterface* iface,
-                       MBDataType tag_type, int tag_length,
-                       int num_entities, const MBEntityHandle* entities,
+bool check_tag_values( Interface* iface,
+                       DataType tag_type, int tag_length,
+                       int num_entities, const EntityHandle* entities,
                        const int* values )
 {
-  MBTag tag;
-  MBErrorCode rval = iface->tag_get_handle( "data", tag ); MBCHECK(rval);
+  Tag tag;
+  ErrorCode rval = iface->tag_get_handle( "data", tag ); CHECK(rval);
   
-  MBDataType act_type;
-  rval = iface->tag_get_data_type( tag, act_type ); MBCHECK(rval);
+  DataType act_type;
+  rval = iface->tag_get_data_type( tag, act_type ); CHECK(rval);
   CHECK( act_type == tag_type );
   
   int size, *intptr;
   double* dblptr;
-  rval = iface->tag_get_size( tag, size ); MBCHECK(rval);
+  rval = iface->tag_get_size( tag, size ); CHECK(rval);
   std::vector<unsigned char> data( size * num_entities );
   
   switch (tag_type) {
@@ -1251,7 +1256,7 @@
       CHECK( tag_length == size );
       for (int i = 0; i < num_entities; ++i) {
         unsigned char val;
-        rval = iface->tag_get_data( tag, entities + i, 1, &val ); MBCHECK(rval);
+        rval = iface->tag_get_data( tag, entities + i, 1, &val ); CHECK(rval);
         for (int j = 0; j < tag_length; ++j) {
           int bitval = !!(val & (1 << j));
           int expval = abs(*values) % 2;
@@ -1261,14 +1266,14 @@
       }
       break;
     case MB_TYPE_OPAQUE:
-      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); MBCHECK(rval);
+      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); CHECK(rval);
       CHECK( tag_length == size );
       for (int i = 0; i < num_entities; ++i) 
         for (int j = 0; j < tag_length; ++j, ++values) 
           CHECK( (unsigned)(*values % 256) == data[i*tag_length+j] );
       break;
     case MB_TYPE_INTEGER:
-      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); MBCHECK(rval);
+      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); CHECK(rval);
       CHECK( tag_length*sizeof(int) == (unsigned)size );
       intptr = reinterpret_cast<int*>(&data[0]);
       for (int i = 0; i < num_entities; ++i) 
@@ -1276,7 +1281,7 @@
           CHECK( *values == intptr[i*tag_length+j] );
       break;
     case MB_TYPE_DOUBLE:
-      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); MBCHECK(rval);
+      rval = iface->tag_get_data( tag, entities, num_entities, &data[0] ); CHECK(rval);
       CHECK( tag_length*sizeof(double) == (unsigned)size );
       dblptr = reinterpret_cast<double*>(&data[0]);
       for (int i = 0; i < num_entities; ++i) 
@@ -1291,9 +1296,9 @@
 }
 
 
-bool check_tag_values( MBInterface* iface, MBDataType type, int vals_per_ent )
+bool check_tag_values( Interface* iface, DataType type, int vals_per_ent )
 {
-  MBEntityHandle vert_handles[6], elem_handles[2];
+  EntityHandle vert_handles[6], elem_handles[2];
   bool rval = match_vertices_and_elements( iface, MBQUAD, 6, 2, 4, 
                            two_quad_mesh_coords, two_quad_mesh_conn,
                            vert_handles, elem_handles ); CHECK(rval);
@@ -1305,10 +1310,10 @@
   return rval;
 }
 
-bool check_tag_data( const char* file, MBDataType type, int vals_per_ent )
+bool check_tag_data( const char* file, DataType type, int vals_per_ent )
 {
   bool bval;
-  MBCore instance1, instance2;
+  Core instance1, instance2;
   
   bval = read_file( &instance1, file ); CHECK(bval);
   bval = check_tag_values( &instance1, type, vals_per_ent ); CHECK(bval);
@@ -1317,7 +1322,7 @@
   return true;
 }
 
-bool test_scalar_attrib(const char* vtk_type, MBDataType mb_type, int count)
+bool test_scalar_attrib(const char* vtk_type, DataType mb_type, int count)
 {
   char file[4096];
   strcpy( file, two_quad_mesh );
@@ -1334,7 +1339,7 @@
   return check_tag_data( file, mb_type, count );
 } 
 
-bool test_vector_attrib( const char* vtk_type, MBDataType mb_type )
+bool test_vector_attrib( const char* vtk_type, DataType mb_type )
 {
   char file[4096];
   strcpy( file, two_quad_mesh );
@@ -1349,7 +1354,7 @@
   return check_tag_data( file, mb_type, 3 );
 } 
 
-bool test_tensor_attrib( const char* vtk_type, MBDataType mb_type )
+bool test_tensor_attrib( const char* vtk_type, DataType mb_type )
 {
   char file[4096];
   strcpy( file, two_quad_mesh );
@@ -1366,12 +1371,12 @@
 
 bool test_subset( )
 {
-  MBCore moab_inst;
-  MBInterface& moab = moab_inst;
-  MBErrorCode rval;
+  Core moab_inst;
+  Interface& moab = moab_inst;
+  ErrorCode rval;
   
     // create 9 nodes in grid pattern
-  MBEntityHandle verts[9];
+  EntityHandle verts[9];
   const double coords[][3] = { { 0, 0, 0 },
                                { 1, 0, 0 },
                                { 2, 0, 0 },
@@ -1391,7 +1396,7 @@
                           { 1, 2, 5, 4 },
                           { 3, 4, 7, 6 },
                           { 4, 5, 8, 7 } };
-  MBEntityHandle econn[4], elems[4];
+  EntityHandle econn[4], elems[4];
   for (unsigned i = 0; i < 4; ++i) {
     for (unsigned j = 0; j < 4; ++j)
       econn[j] = verts[conn[i][j]];
@@ -1400,7 +1405,7 @@
   }
   
     // create 3 meshsets
-  MBEntityHandle sets[3];
+  EntityHandle sets[3];
   for (unsigned i = 0;i < 3; ++i) {
     rval = moab.create_meshset( 0, sets[i] );
     assert(MB_SUCCESS == rval);
@@ -1425,31 +1430,31 @@
   
     // write sets[0] to vtk file
   rval = moab.write_mesh(  "tmp_file.vtk", sets, 1 );
-  MBCHECK(rval);
+  CHECK(rval);
    
     // read data back in
   moab.delete_mesh();
   rval = moab.load_mesh( "tmp_file.vtk" );
   remove( "tmp_file.vtk" );
-  MBCHECK(rval);
+  CHECK(rval);
   
     // writer should have written all three sets,
     // so the resulting mesh should be elems[2], elems[3], 
     // and verts[2]
-  MBRange new_elems, new_verts;
+  Range new_elems, new_verts;
   rval = moab.get_entities_by_type( 0, MBQUAD, new_elems );
-  MBCHECK(rval);
+  CHECK(rval);
   CHECK( new_elems.size() == 2 );
   rval = moab.get_entities_by_type( 0, MBVERTEX, new_verts );
-  MBCHECK(rval);
+  CHECK(rval);
   CHECK( new_verts.size() == 7 );
   
     // vertex not in element closure should have coords of 2,0,0
-  MBRange elem_verts;
-  rval = moab.get_adjacencies( new_elems, 0, false, elem_verts, MBInterface::UNION );
-  MBCHECK(rval);
+  Range elem_verts;
+  rval = moab.get_adjacencies( new_elems, 0, false, elem_verts, Interface::UNION );
+  CHECK(rval);
   CHECK(elem_verts.size() == 6);
-  MBRange free_verts( subtract( new_verts, elem_verts ) );
+  Range free_verts( subtract( new_verts, elem_verts ) );
   CHECK(free_verts.size() == 1 );
   double vcoords[3];
   rval = moab.get_coords( free_verts, vcoords );

Modified: MOAB/trunk/test/io/cub_file_test.cc
===================================================================
--- MOAB/trunk/test/io/cub_file_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/cub_file_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,14 @@
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "Tqdcfr.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/MBTagConventions.hpp"
 #include "FileOptions.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 #include <math.h>
 #include <algorithm>
 
+using namespace moab;
+
 /**\brief Input test file: test.cub
  * Cubit 10.2 file.
  * File contains:
@@ -83,26 +85,26 @@
 static const char ho_file[] = "ho_test.cub";
 #endif
 
-void read_file( MBInterface& moab, const char* input_file );
+void read_file( Interface& moab, const char* input_file );
 
 
 // Check that adjacent lower-order entities have
 // higher-order nodes consitent with input entity.
-void check_adj_ho_nodes( MBInterface& moab,
-                         MBEntityHandle entity );
+void check_adj_ho_nodes( Interface& moab,
+                         EntityHandle entity );
 
 // Check that element has expected higher-order nodes
 // and that each higher-order node is at the center
 // of the sub-entity it is on.
-void check_ho_element( MBInterface& moab, 
-                       MBEntityHandle entity,
+void check_ho_element( Interface& moab, 
+                       EntityHandle entity,
                        int mid_nodes[4] );
 
 // Validate elements of specified type.
 // Looks for a block containing the specified entity type
 // and with the specified mid-node flags set in its
 // HAS_MID_NODES_TAG.
-void test_ho_elements( MBEntityType type, int num_nodes );
+void test_ho_elements( EntityType type, int num_nodes );
 
 void test_vertices();
 
@@ -168,9 +170,9 @@
   return result;
 }
 
-void read_file( MBInterface& moab, const char* input_file )
+void read_file( Interface& moab, const char* input_file )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   Tqdcfr reader( &moab );
   FileOptions opts("");
   rval = reader.load_file( input_file, 0, opts, 0, 0, 0 );
@@ -227,19 +229,19 @@
                                 10,  0,  0  // 45
                                 };
 
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, input_file_1 );
   
     // get vertex handles and check correct number of vertices
   const size_t num_nodes = sizeof(node_coords)/(3*sizeof(double));
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts ); CHECK_ERR(rval);
   CHECK_EQUAL( num_nodes, (size_t)verts.size() );
   
     // check global ids (should be 1 to 45 for vertices.)
-  MBTag gid_tag;
+  Tag gid_tag;
   rval = mb.tag_get_handle( "GLOBAL_ID", gid_tag ); CHECK_ERR(rval);
   std::vector<int> ids(num_nodes);
   rval = mb.tag_get_data( gid_tag, verts, &ids[0] ); CHECK_ERR(rval);
@@ -262,22 +264,22 @@
 
 
 void test_element( const char* filename,
-                   MBEntityType type, 
+                   EntityType type, 
                    int num_elem,
                    int node_per_elem,
                    const int* conn_list )
 {
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, filename );
   
-  MBRange elems;
+  Range elems;
   rval = mb.get_entities_by_type( 0, type, elems ); CHECK_ERR(rval);
   CHECK_EQUAL( num_elem, (int)elems.size() );
   
     // get global ids
-  MBTag gid_tag;
+  Tag gid_tag;
   rval = mb.tag_get_handle( "GLOBAL_ID", gid_tag ); CHECK_ERR(rval);
   std::vector<int> ids(num_elem);
   rval = mb.tag_get_data( gid_tag, elems, &ids[0] ); CHECK_ERR(rval);
@@ -290,8 +292,8 @@
   
     // check connectivity of each element
   std::vector<int> conn_ids(node_per_elem);
-  std::vector<MBEntityHandle> conn_h;
-  MBRange::iterator j = elems.begin();
+  std::vector<EntityHandle> conn_h;
+  Range::iterator j = elems.begin();
   for (int i = 0; i < num_elem; ++i, ++j) {
     conn_h.clear();
     rval = mb.get_connectivity( &*j, 1, conn_h ); CHECK_ERR(rval);
@@ -478,26 +480,26 @@
   return results;
 }
 
-int check_geometric_set( MBInterface& moab,
+int check_geometric_set( Interface& moab,
                          int dim, int id, 
                          const int* children, int num_children, 
                          std::vector<int> parents )
 {
-  MBErrorCode rval;
-  MBTag gid_tag, dim_tag;
+  ErrorCode rval;
+  Tag gid_tag, dim_tag;
   
   rval = moab.tag_get_handle( "GLOBAL_ID", gid_tag ); CHECK_ERR(rval);
   rval = moab.tag_get_handle( "GEOM_DIMENSION", dim_tag ); CHECK_ERR(rval);
   void* tag_vals[] = { &dim, &id };
-  MBTag tags[] = { dim_tag, gid_tag };
-  MBRange ents;
+  Tag tags[] = { dim_tag, gid_tag };
+  Range ents;
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, tags, tag_vals, 2, ents );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1u, (unsigned)ents.size() );
   
-  const MBEntityHandle geom = ents.front();
+  const EntityHandle geom = ents.front();
   std::vector<int> exp_rel, act_rel;
-  std::vector<MBEntityHandle> rel;
+  std::vector<EntityHandle> rel;
   
   if (num_children) {
     exp_rel.resize( num_children );
@@ -531,8 +533,8 @@
 
 void test_geometric_topology()
 {
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, input_file_1 );
   // expected geometric vertices, specified by global ID
   const int vertex_ids[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14 };
@@ -605,16 +607,16 @@
 
 void test_geometric_sets()
 {
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, input_file_1 );
-  MBTag gid_tag, dim_tag;
+  Tag gid_tag, dim_tag;
   rval = mb.tag_get_handle( "GLOBAL_ID", gid_tag ); CHECK_ERR(rval);
   rval = mb.tag_get_handle( "GEOM_DIMENSION", dim_tag ); CHECK_ERR(rval);
 
     // verify mesh entity counts
-  MBRange verts, curves, surfs, vols;
+  Range verts, curves, surfs, vols;
   int dim = 0;
   const void* vals[] = {&dim};
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, vals, 1, verts );
@@ -636,8 +638,8 @@
   
     // check that each vertex has a single node, and that the 
     // node is also contained in any parent curve
-  MBRange ents;
-  MBRange::iterator i;
+  Range ents;
+  Range::iterator i;
   for (i = verts.begin(); i != verts.end(); ++i) {
     ents.clear();
     rval = mb.get_entities_by_handle( *i, ents ); CHECK_ERR(rval);
@@ -675,7 +677,7 @@
   
     // Check that for each geometric entity, any contained vertices
     // are adjacent to some entity in one of its parents.
-  MBRange parents, geom, nodes, tmp;
+  Range parents, geom, nodes, tmp;
   for (int d = 0; d < 3; ++d) {
     const void* vals[] = {&d};
     rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, vals, 1, geom );
@@ -687,13 +689,13 @@
       parents.clear();
       rval = mb.get_entities_by_type( *i, MBVERTEX, nodes ); CHECK_ERR(rval);
       rval = mb.get_parent_meshsets( *i, parents ); CHECK_ERR(rval);
-      for (MBRange::iterator j = parents.begin(); j != parents.end(); ++j) {
+      for (Range::iterator j = parents.begin(); j != parents.end(); ++j) {
         tmp.clear();
         rval = mb.get_entities_by_dimension( *j, d+1, tmp ); CHECK_ERR(rval);
         ents.merge( tmp );
       }
       tmp.clear();
-      rval = mb.get_adjacencies( ents, 0, false, tmp, MBInterface::UNION );
+      rval = mb.get_adjacencies( ents, 0, false, tmp, Interface::UNION );
       CHECK_ERR(rval);
       nodes = subtract( nodes, tmp );
       CHECK( nodes.empty() );
@@ -704,24 +706,24 @@
 // expect one block containing entire mesh, with id == 1
 void test_blocks()
 {
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, input_file_1 );
-  MBTag mat_tag;
+  Tag mat_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, mat_tag ); CHECK_ERR(rval);
 
-  MBRange blocks;
+  Range blocks;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, blocks );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1u, (unsigned)blocks.size() );
-  MBEntityHandle block = blocks.front();
+  EntityHandle block = blocks.front();
   int id;
   rval = mb.tag_get_data( mat_tag, &block, 1, &id );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, id );
   
-  MBRange block_hexes, mesh_hexes;
+  Range block_hexes, mesh_hexes;
   rval = mb.get_entities_by_dimension( 0, 3, mesh_hexes ); CHECK_ERR(rval);
   rval = mb.get_entities_by_dimension( block, 3, block_hexes, true ); CHECK_ERR(rval);
   CHECK( mesh_hexes == block_hexes );  
@@ -738,22 +740,22 @@
                    const int* ids,
                    const std::vector<int> set_surfs[] )
 {
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, input_file_1 );
-  MBTag ss_tag, gid_tag, dim_tag;
+  Tag ss_tag, gid_tag, dim_tag;
   rval = mb.tag_get_handle( tag_name, ss_tag ); CHECK_ERR(rval);
   rval = mb.tag_get_handle( "GLOBAL_ID", gid_tag ); CHECK_ERR(rval);
   rval = mb.tag_get_handle( "GEOM_DIMENSION", dim_tag ); CHECK_ERR(rval);
 
     // check number of sidesets and IDs
-  MBRange sidesets;
+  Range sidesets;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &ss_tag, 0, 1, sidesets );
   CHECK_ERR(rval);
   CHECK_EQUAL( count, (unsigned)sidesets.size() );
-  std::vector<MBEntityHandle> handles(count,0);
-  for (MBRange::iterator i = sidesets.begin(); i != sidesets.end(); ++i) {
+  std::vector<EntityHandle> handles(count,0);
+  for (Range::iterator i = sidesets.begin(); i != sidesets.end(); ++i) {
     int id;
     rval = mb.tag_get_data( ss_tag, &*i, 1, &id ); CHECK_ERR(rval);
     unsigned idx;
@@ -767,9 +769,9 @@
 
     
     // get surface faces
-  std::vector<MBRange> exp(count);
-  MBRange surfs, tmp;
-  MBTag tags[] = { dim_tag, gid_tag };
+  std::vector<Range> exp(count);
+  Range surfs, tmp;
+  Tag tags[] = { dim_tag, gid_tag };
   for (unsigned i = 0; i < count; ++i) {
     exp[i].clear();
     surfs.clear();
@@ -787,7 +789,7 @@
   }
   
     // check each bc set
-  MBRange act;
+  Range act;
   for (unsigned i = 0; i < count; ++i) {
     act.clear();
     rval = mb.get_entities_by_dimension( handles[i], 2, act, true ); CHECK_ERR(rval);
@@ -821,25 +823,25 @@
   test_bc_sets( DIRICHLET_SET_TAG_NAME, 2, ids, surfs );
 }
 
-static MBEntityHandle find_side( MBInterface& moab, 
-                                 MBEntityHandle entity,
+static EntityHandle find_side( Interface& moab, 
+                                 EntityHandle entity,
                                  int side_dim,
                                  int side_num )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
-  std::vector<MBEntityHandle> adj;
+  std::vector<EntityHandle> adj;
   rval = moab.get_adjacencies( &entity, 1, side_dim, false, adj );
   CHECK_ERR(rval);
   
   int sub_ent_indices[4];
   MBCN::SubEntityVertexIndices( TYPE_FROM_HANDLE(entity), side_dim, side_num, 
                                 sub_ent_indices );
-  MBEntityType subtype = MBCN::SubEntityType( TYPE_FROM_HANDLE(entity),
+  EntityType subtype = MBCN::SubEntityType( TYPE_FROM_HANDLE(entity),
                                               side_dim, side_num );
   int sub_ent_corners = MBCN::VerticesPerEntity(subtype);
   
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int conn_len;
   rval = moab.get_connectivity( entity, conn, conn_len );
   CHECK_ERR(rval);
@@ -848,7 +850,7 @@
     if (TYPE_FROM_HANDLE(adj[i]) != subtype)
       continue;
   
-    const MBEntityHandle* sub_conn;
+    const EntityHandle* sub_conn;
     int sub_len;
     rval = moab.get_connectivity( adj[i], sub_conn, sub_len );
     CHECK_ERR(rval);
@@ -879,13 +881,13 @@
 }
       
   
-void check_adj_ho_nodes( MBInterface& moab,
-                         MBEntityHandle entity )
+void check_adj_ho_nodes( Interface& moab,
+                         EntityHandle entity )
 {
-    MBEntityType type = TYPE_FROM_HANDLE(entity);
-    const MBEntityHandle* conn;
+    EntityType type = TYPE_FROM_HANDLE(entity);
+    const EntityHandle* conn;
     int conn_len;
-    MBErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
+    ErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
     CHECK_ERR(rval);
     
     int ho[4];
@@ -895,11 +897,11 @@
         continue;
         
       for (int j = 0; j < MBCN::NumSubEntities( type, dim ); ++j) {
-        MBEntityHandle side = find_side( moab, entity, dim, j );
+        EntityHandle side = find_side( moab, entity, dim, j );
         if (!side)
           continue;
         
-        const MBEntityHandle* side_conn;
+        const EntityHandle* side_conn;
         int side_len;
         rval = moab.get_connectivity( side, side_conn, side_len );
         CHECK_ERR(rval);
@@ -914,15 +916,15 @@
 // Check that element has expected higher-order nodes
 // and that each higher-order node is at the center
 // of the sub-entity it is on.
-void check_ho_element( MBInterface& moab, 
-                       MBEntityHandle entity,
+void check_ho_element( Interface& moab, 
+                       EntityHandle entity,
                        int mid_nodes[4] )
 {
     // get element info
-  const MBEntityType type = TYPE_FROM_HANDLE(entity);
-  const MBEntityHandle* conn;
+  const EntityType type = TYPE_FROM_HANDLE(entity);
+  const EntityHandle* conn;
   int conn_len;
-  MBErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
+  ErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
   CHECK_ERR(rval);
   std::vector<double> coords(3*conn_len);
   rval = moab.get_coords( conn, conn_len, &coords[0] );
@@ -945,7 +947,7 @@
     int sub_conn[8], num_sub;
     if (sub_dim < MBCN::Dimension(type)) {
       MBCN::SubEntityVertexIndices( type, sub_dim, sub_num, sub_conn );
-      MBEntityType sub_type = MBCN::SubEntityType( type, sub_dim, sub_num );
+      EntityType sub_type = MBCN::SubEntityType( type, sub_dim, sub_num );
       num_sub = MBCN::VerticesPerEntity( sub_type );
     }
     else {
@@ -975,30 +977,30 @@
 // Looks for a block containing the specified entity type
 // and with the specified mid-node flags set in its
 // HAS_MID_NODES_TAG.
-void test_ho_elements( MBEntityType type, int num_nodes )
+void test_ho_elements( EntityType type, int num_nodes )
 {
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
+  Core mb_impl;
+  Interface& mb = mb_impl;
   read_file( mb, ho_file );
 
-  MBErrorCode rval;
-  MBTag ho_tag, block_tag;
+  ErrorCode rval;
+  Tag ho_tag, block_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, block_tag );
   CHECK_ERR(rval);
   rval = mb.tag_get_handle( HAS_MID_NODES_TAG_NAME, ho_tag );
   CHECK_ERR(rval);
   
   // get material sets with expected higher-order nodes
-  MBRange blocks;
+  Range blocks;
   int ho_flags[4];
   MBCN::HasMidNodes( type, num_nodes, ho_flags );
-  MBTag tags[2] = {ho_tag, block_tag};
+  Tag tags[2] = {ho_tag, block_tag};
   void* vals[2] = {ho_flags, NULL};
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, tags, vals, 2, blocks );
   CHECK_ERR(rval);
   
-  MBRange::iterator i;
-  MBRange entities;
+  Range::iterator i;
+  Range entities;
   for (i = blocks.begin(); i != blocks.end(); ++i) {
     rval = mb.get_entities_by_type( *i, type, entities, true );
     CHECK_ERR(rval);
@@ -1016,16 +1018,16 @@
 void test_multiple_files()
 {
     // load two surface meshes, one at z=+5 at z=-5.
-  MBErrorCode rval;
-  MBCore mb_impl;
-  MBInterface& mb = mb_impl;
-  MBRange file1_ents, file2_ents;
+  ErrorCode rval;
+  Core mb_impl;
+  Interface& mb = mb_impl;
+  Range file1_ents, file2_ents;
   read_file( mb, input_file_1 );
   mb.get_entities_by_handle( 0, file1_ents );
   read_file( mb, input_file_1 );
   mb.get_entities_by_handle( 0, file2_ents );
   file2_ents = subtract( file2_ents, file1_ents );
-  MBEntityHandle file1, file2;
+  EntityHandle file1, file2;
   mb.create_meshset( MESHSET_SET, file1 );
   mb.create_meshset( MESHSET_SET, file2 );
   mb.add_entities( file1, file1_ents );
@@ -1033,7 +1035,7 @@
   
     // first check that we get the same number of verts from 
     // each file and that they are distinct vertices
-  MBRange file1_verts, file2_verts;
+  Range file1_verts, file2_verts;
   rval = mb.get_entities_by_type( file1, MBVERTEX, file1_verts );
   CHECK_ERR(rval);
   CHECK( !file1_verts.empty() );
@@ -1045,7 +1047,7 @@
   
     // now check that we get the same number of elements from 
     // each file and that they are distinct
-  MBRange file1_elems, file2_elems;
+  Range file1_elems, file2_elems;
   rval = mb.get_entities_by_dimension( file1, 3, file1_elems );
   CHECK_ERR(rval);
   CHECK( !file1_elems.empty() );
@@ -1057,10 +1059,10 @@
 
     // now check that the connectivity for each element is
     // defined using the appropriate vertex instances
-  MBRange file1_elem_verts, file2_elem_verts;
-  rval = mb.get_adjacencies( file1_elems, 0, false, file1_elem_verts, MBInterface::UNION );
+  Range file1_elem_verts, file2_elem_verts;
+  rval = mb.get_adjacencies( file1_elems, 0, false, file1_elem_verts, Interface::UNION );
   CHECK_ERR(rval);
-  rval = mb.get_adjacencies( file2_elems, 0, false, file2_elem_verts, MBInterface::UNION );
+  rval = mb.get_adjacencies( file2_elems, 0, false, file2_elem_verts, Interface::UNION );
   CHECK_ERR(rval);
   CHECK_EQUAL( file1_elem_verts.size(), file2_elem_verts.size() );
   CHECK( intersect( file1_elem_verts,  file1_verts ) == file1_elem_verts );

Modified: MOAB/trunk/test/io/exodus_test.cc
===================================================================
--- MOAB/trunk/test/io/exodus_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/exodus_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 #define IS_BUILDING_MB
 #include "ReadNCDF.hpp"
 #include "WriteNCDF.hpp"
@@ -10,6 +10,8 @@
 #include <math.h>
 #include <algorithm>
 
+using namespace moab;
+
 /* Input test file: ho_test.g
  * 
  * File is expected to contain at least one block for every
@@ -23,18 +25,18 @@
 static const char ho_file[] = "ho_test.g";
 #endif
 
-void read_file( MBInterface& moab, 
+void read_file( Interface& moab, 
                 const char* input_file );
 
 // Check that element has expected higher-order nodes
 // and that each higher-order node is at the center
 // of the sub-entity it is on.
-void check_ho_element( MBInterface& moab, 
-                       MBEntityHandle entity,
+void check_ho_element( Interface& moab, 
+                       EntityHandle entity,
                        int mid_nodes[4] );
 
 void test_read_side( int sideset_id,
-                     MBEntityType sideset_type,
+                     EntityType sideset_type,
                      int sideset_nodes_per_elem,
                      bool shell_side = false );
 
@@ -42,7 +44,7 @@
 // Looks for a block containing the specified entity type
 // and with the specified mid-node flags set in its
 // HAS_MID_NODES_TAG.
-void test_ho_elements( MBEntityType type, int num_nodes );
+void test_ho_elements( EntityType type, int num_nodes );
 
 void test_types();
 
@@ -101,7 +103,7 @@
 }
 
 struct TestType {
-  MBEntityType moab_type;
+  EntityType moab_type;
   ExoIIElementType exo_type;
   int num_nodes;
   std::string name;
@@ -121,7 +123,7 @@
     case 1: CHECK_EQUAL( has_mid_nodes[1], ExoIIUtil::HasMidNodes[type.exo_type][1] );
   }
   
-  MBCore moab;
+  Core moab;
   ExoIIUtil tool(&moab);
   CHECK_EQUAL( type.exo_type, tool.element_name_to_type( type.name.c_str() ) );
   CHECK_EQUAL( type.name, std::string(tool.element_type_name( type.exo_type ) ) );
@@ -178,27 +180,27 @@
     check_type( types[i] );
 }
 
-void read_file( MBInterface& moab, 
+void read_file( Interface& moab, 
                 const char* input_file )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   ReadNCDF reader( &moab );
   FileOptions opts("");
   rval = reader.load_file( input_file, 0, opts, 0, 0, 0 );
   CHECK_ERR(rval);
 }
 
-void write_and_read( MBInterface& write_mb,
-                     MBInterface& read_mb,
-                     MBEntityHandle block = 0 )
+void write_and_read( Interface& write_mb,
+                     Interface& read_mb,
+                     EntityHandle block = 0 )
 {
   const char* tmp_file = "exodus_test_tmp.g";
-  MBErrorCode rval;
+  ErrorCode rval;
   ReadNCDF reader( &read_mb );
   WriteNCDF writer( &write_mb );
   FileOptions opts("");
   
-  MBEntityHandle* write_set_list = &block;
+  EntityHandle* write_set_list = &block;
   int write_set_list_len = 0;//(block != 0);
   std::vector<std::string> qa_records;
   rval = writer.write_file( tmp_file, true, opts, 
@@ -213,33 +215,33 @@
   CHECK_ERR(rval);
 }
 
-void check_ho_elements( MBInterface& moab, 
-                        MBEntityHandle block,
-                        MBEntityType type,
+void check_ho_elements( Interface& moab, 
+                        EntityHandle block,
+                        EntityType type,
                         int mid_nodes[4] )
 {
-  MBErrorCode rval;
-  MBRange elems;
+  ErrorCode rval;
+  Range elems;
   rval = moab.get_entities_by_handle( block, elems );
   CHECK_ERR(rval);
   CHECK(!elems.empty());
   CHECK(elems.all_of_type(type));
-  for (MBRange::const_iterator i = elems.begin(); i != elems.end(); ++i)
+  for (Range::const_iterator i = elems.begin(); i != elems.end(); ++i)
     check_ho_element( moab, *i, mid_nodes );
 }
 
 // Check that element has expected higher-order nodes
 // and that each higher-order node is at the center
 // of the sub-entity it is on.
-void check_ho_element( MBInterface& moab, 
-                       MBEntityHandle entity,
+void check_ho_element( Interface& moab, 
+                       EntityHandle entity,
                        int mid_nodes[4] )
 {
     // get element info
-  const MBEntityType type = TYPE_FROM_HANDLE(entity);
-  const MBEntityHandle* conn;
+  const EntityType type = TYPE_FROM_HANDLE(entity);
+  const EntityHandle* conn;
   int conn_len;
-  MBErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
+  ErrorCode rval = moab.get_connectivity( entity, conn, conn_len );
   CHECK_ERR(rval);
   std::vector<double> coords(3*conn_len);
   rval = moab.get_coords( conn, conn_len, &coords[0] );
@@ -262,7 +264,7 @@
     int sub_conn[8], num_sub;
     if (sub_dim < MBCN::Dimension(type)) {
       MBCN::SubEntityVertexIndices( type, sub_dim, sub_num, sub_conn );
-      MBEntityType sub_type = MBCN::SubEntityType( type, sub_dim, sub_num );
+      EntityType sub_type = MBCN::SubEntityType( type, sub_dim, sub_num );
       num_sub = MBCN::VerticesPerEntity( sub_type );
     }
     else {
@@ -289,24 +291,24 @@
 }
 
 
-MBEntityHandle find_block( MBInterface& mb, MBEntityType type, const int has_mid_nodes[4] )
+EntityHandle find_block( Interface& mb, EntityType type, const int has_mid_nodes[4] )
 {
 
-  MBErrorCode rval;
-  MBTag ho_tag, block_tag;
+  ErrorCode rval;
+  Tag ho_tag, block_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, block_tag );
   CHECK_ERR(rval);
   rval = mb.tag_get_handle( HAS_MID_NODES_TAG_NAME, ho_tag );
   CHECK_ERR(rval);
   
   // get material sets with expected higher-order nodes
-  MBRange blocks;
-  MBTag tags[2] = {ho_tag, block_tag};
+  Range blocks;
+  Tag tags[2] = {ho_tag, block_tag};
   const void* vals[2] = {has_mid_nodes, NULL};
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, tags, vals, 2, blocks );
   CHECK_ERR(rval);
   
-  for (MBRange::iterator i = blocks.begin(); i != blocks.end(); ++i) {
+  for (Range::iterator i = blocks.begin(); i != blocks.end(); ++i) {
     int n;
     rval = mb.get_number_entities_by_type( *i, type, n );
     CHECK_ERR(rval);
@@ -318,17 +320,17 @@
   return 0;
 }
 
-MBEntityHandle find_sideset( MBInterface& mb, 
+EntityHandle find_sideset( Interface& mb, 
                              int sideset_id,
-                             MBEntityType side_type )
+                             EntityType side_type )
 {
-  MBErrorCode rval;
-  MBTag ss_tag;
+  ErrorCode rval;
+  Tag ss_tag;
   rval = mb.tag_get_handle( NEUMANN_SET_TAG_NAME, ss_tag );
   CHECK_ERR(rval);
   
   const void* tag_vals[] = { &sideset_id };
-  MBRange side_sets;
+  Range side_sets;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &ss_tag, tag_vals, 1, side_sets );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)side_sets.size() );
@@ -339,17 +341,17 @@
 // Looks for a block containing the specified entity type
 // and with the specified mid-node flags set in its
 // HAS_MID_NODES_TAG.
-void test_ho_elements( MBEntityType type, int num_nodes )
+void test_ho_elements( EntityType type, int num_nodes )
 {
-  MBCore mb_impl1, mb_impl2;
-  MBInterface &mb1 = mb_impl1, &mb2 = mb_impl2;
+  Core mb_impl1, mb_impl2;
+  Interface &mb1 = mb_impl1, &mb2 = mb_impl2;
   int ho_flags[4];
   MBCN::HasMidNodes( type, num_nodes, ho_flags );
 
     // read file 
   read_file( mb1, ho_file );
     // test element connectivity order
-  MBEntityHandle block = find_block( mb1, type, ho_flags );
+  EntityHandle block = find_block( mb1, type, ho_flags );
   CHECK(block != 0);
   check_ho_elements( mb1, block, type, ho_flags );
   
@@ -362,17 +364,17 @@
 }
 
 void test_read_side( int id,
-                     MBEntityType sideset_type,
+                     EntityType sideset_type,
                      int sideset_nodes_per_elem,
                      bool shell_side )
 {
   // read test file
-  MBCore mb_impl;
-  MBInterface& moab = mb_impl;
+  Core mb_impl;
+  Interface& moab = mb_impl;
   read_file( moab, ho_file );
   
   // get side set 
-  MBEntityHandle set = find_sideset( moab, id, sideset_type );
+  EntityHandle set = find_sideset( moab, id, sideset_type );
   CHECK(set != 0);
   
   // check expected element connectivity
@@ -384,14 +386,14 @@
     return;
   
   // check that each element is on the boundary of the mesh
-  MBRange elems;
-  MBErrorCode rval = mb_impl.get_entities_by_handle( set, elems );
+  Range elems;
+  ErrorCode rval = mb_impl.get_entities_by_handle( set, elems );
   CHECK_ERR(rval);
   
   int dim = MBCN::Dimension( sideset_type );
-  for (MBRange::iterator i= elems.begin(); i != elems.end(); ++i) {
-    MBRange adj;
-    rval = mb_impl.get_adjacencies( &*i, 1, dim+1, false, adj, MBInterface::UNION );
+  for (Range::iterator i= elems.begin(); i != elems.end(); ++i) {
+    Range adj;
+    rval = mb_impl.get_adjacencies( &*i, 1, dim+1, false, adj, Interface::UNION );
     CHECK_ERR(rval);
     CHECK_EQUAL( 1, (int)adj.size() );
   }
@@ -403,12 +405,12 @@
                            const int* expected_vals,
                            int num_expected )
 {
-  MBCore mb;
+  Core mb;
   ReadNCDF reader(&mb);
   
   FileOptions opts("");
   std::vector<int> values;
-  MBErrorCode rval = reader.read_tag_values( file_name, tag_name, opts, values );
+  ErrorCode rval = reader.read_tag_values( file_name, tag_name, opts, values );
   CHECK_ERR(rval);
   
   std::vector<int> expected( expected_vals, expected_vals+num_expected );

Modified: MOAB/trunk/test/io/gmsh_test.cc
===================================================================
--- MOAB/trunk/test/io/gmsh_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/gmsh_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,14 @@
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 #include "ReadGmsh.hpp"
 #include "FileOptions.hpp"
 #include <math.h>
 #include <algorithm>
 
+using namespace moab;
+
 /* Input test file: gmsh2.msh
  * 
  * Example version 2.0 ASCII input file from Gmsh 2.4 manual.
@@ -22,7 +24,7 @@
 void test_read_material_set();
 void test_read_geom_set();
 
-void read_file( MBInterface& moab, const char* input_file );
+void read_file( Interface& moab, const char* input_file );
 
 int main()
 {
@@ -37,9 +39,9 @@
 }
 
 
-void read_file( MBInterface& moab, const char* input_file )
+void read_file( Interface& moab, const char* input_file )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   ReadGmsh reader( &moab );
   FileOptions opts("");
   rval = reader.load_file( input_file, 0, opts, 0, 0, 0 );
@@ -49,17 +51,17 @@
 void test_read_nodes()
 {
   const double eps = 1e-100;
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> nodes;
+  std::vector<EntityHandle> nodes;
   rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)6, nodes.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -120,17 +122,17 @@
 
 void test_read_quads()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> quads;
+  std::vector<EntityHandle> quads;
   rval = mb.get_entities_by_type( 0, MBQUAD, quads );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)2, quads.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -144,7 +146,7 @@
   }
   
   int vtx_ids[4];
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
   
   const int conn1[] = { 1, 2, 3, 4 };
@@ -170,27 +172,27 @@
 
 void test_read_material_set()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  MBTag mat_tag;
+  Tag mat_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, mat_tag );
   CHECK_ERR(rval);
   
-  MBRange sets;
+  Range sets;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)sets.size() );
-  MBEntityHandle set = sets.front();
+  EntityHandle set = sets.front();
   
   int id;
   rval = mb.tag_get_data( mat_tag, &set, 1, &id );
   CHECK_ERR(rval);
   CHECK_EQUAL( 99, id );
   
-  std::vector<MBEntityHandle> quads, contents;
+  std::vector<EntityHandle> quads, contents;
   rval = mb.get_entities_by_type( 0, MBQUAD, quads );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_handle( set, contents );
@@ -203,22 +205,22 @@
 
 void test_read_geom_set()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  MBTag dim_tag, id_tag;
+  Tag dim_tag, id_tag;
   rval = mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, dim_tag );
   CHECK_ERR(rval);
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
-  MBRange sets;
+  Range sets;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, 0, 1, sets );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)sets.size() );
-  MBEntityHandle set = sets.front();
+  EntityHandle set = sets.front();
   
   int dim;
   rval = mb.tag_get_data( dim_tag, &set, 1, &dim );
@@ -230,7 +232,7 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( 3, id );
   
-  std::vector<MBEntityHandle> quads, contents;
+  std::vector<EntityHandle> quads, contents;
   rval = mb.get_entities_by_type( 0, MBQUAD, quads );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_handle( set, contents );

Modified: MOAB/trunk/test/io/nastran_test.cc
===================================================================
--- MOAB/trunk/test/io/nastran_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/nastran_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,21 +1,23 @@
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 #define IS_BUILDING_MB
 #include "ReadNASTRAN.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include "FileOptions.hpp"
 #include <math.h>
 #include <algorithm>
 
+using namespace moab;
+
 #ifdef SRCDIR
 static const char example[] = STRINGIFY(SRCDIR) "/test.nas";
 #else
 static const char example[] = "test.nas";
 #endif
 
-void read_file( MBInterface& moab, const char* input_file );
+void read_file( Interface& moab, const char* input_file );
 void test_read_nodes();
 void test_read_tets();
 void test_read_prisms();
@@ -38,9 +40,9 @@
 }
 
 
-void read_file( MBInterface& moab, const char* input_file )
+void read_file( Interface& moab, const char* input_file )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   ReadNASTRAN reader( &moab );
   FileOptions opts("");
   rval = reader.load_file( input_file, 0, opts, 0, 0, 0 );
@@ -50,17 +52,17 @@
 void test_read_nodes()
 {
   const double eps = 1e-100;
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> nodes;
+  std::vector<EntityHandle> nodes;
   rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)19, nodes.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -214,17 +216,17 @@
 
 void test_read_tets()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> tets;
+  std::vector<EntityHandle> tets;
   rval = mb.get_entities_by_type( 0, MBTET, tets );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)2, tets.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -238,7 +240,7 @@
   }
   
   int vtx_ids[4];
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
   
   const int conn1[] = { 8, 9, 10, 11 };
@@ -264,17 +266,17 @@
 
 void test_read_prisms()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> prisms;
+  std::vector<EntityHandle> prisms;
   rval = mb.get_entities_by_type( 0, MBPRISM, prisms );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)2, prisms.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -288,7 +290,7 @@
   }
   
   int vtx_ids[6];
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
   
   const int conn1[] = { 2, 3, 4, 5, 6, 7 };
@@ -317,17 +319,17 @@
 
 void test_read_hexes()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  std::vector<MBEntityHandle> hexes;
+  std::vector<EntityHandle> hexes;
   rval = mb.get_entities_by_type( 0, MBHEX, hexes );
   CHECK_ERR(rval);
   CHECK_EQUAL( (size_t)1, hexes.size() );
   
-  MBTag id_tag;
+  Tag id_tag;
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
   CHECK_ERR(rval);
   
@@ -336,7 +338,7 @@
   CHECK_ERR(rval);
   
   int vtx_ids[8];
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
   
   const int conn1[] = { 12, 13, 14, 15, 16, 17, 18, 19 };
@@ -354,23 +356,23 @@
 // The tets are in material set 1.
 void test_read_material_set1()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  MBTag mat_tag;
+  Tag mat_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, mat_tag );
   CHECK_ERR(rval);
   
-  MBRange mat_set_one;  
+  Range mat_set_one;  
   const int one = 1;
   const void* const one_val[] = {&one};  
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, one_val, 1, mat_set_one );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)mat_set_one.size() );
   
-  std::vector<MBEntityHandle> tets, contents;
+  std::vector<EntityHandle> tets, contents;
   rval = mb.get_entities_by_type( 0, MBTET, tets );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_handle( mat_set_one.front(), contents );
@@ -383,23 +385,23 @@
 // The prisms are in material set 2.
 void test_read_material_set2()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   read_file( moab, example );
   
-  MBTag mat_tag;
+  Tag mat_tag;
   rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, mat_tag );
   CHECK_ERR(rval);
   
-  MBRange mat_set_two;  
+  Range mat_set_two;  
   const int two = 2;
   const void* const two_val[] = {&two};  
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, two_val, 1, mat_set_two );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)mat_set_two.size() );
   
-  std::vector<MBEntityHandle> prisms, contents;
+  std::vector<EntityHandle> prisms, contents;
   rval = mb.get_entities_by_type( 0, MBPRISM, prisms );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_handle( mat_set_two.front(), contents );

Modified: MOAB/trunk/test/io/stl_test.cc
===================================================================
--- MOAB/trunk/test/io/stl_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/stl_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,14 @@
 #include "TestUtil.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "ReadSTL.hpp"
 #include "WriteSTL.hpp"
 #include "FileOptions.hpp"
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include <math.h>
 #include <algorithm>
 
+using namespace moab;
+
 /* Input test file: test/sample.stl
  * 
  * Example ASCII STL file from: 
@@ -29,7 +31,7 @@
 void test_little_endian();
 void test_detect_byte_order();
 
-void read_file( MBInterface& moab, 
+void read_file( Interface& moab, 
                 const char* input_file,
                 const char* options = "" );
 void convert_file( const char* source_file,
@@ -37,7 +39,7 @@
                    const char* options = "" );
 // check that the mesh constains the simple tetrahedron defined
 // in test/sample.stl
-void check_mesh_is_tet( MBInterface& moab );
+void check_mesh_is_tet( Interface& moab );
 
 int main()
 {
@@ -56,25 +58,25 @@
   return result;
 }
 
-MBErrorCode read_file_( MBInterface& moab, const char* input_file, const char* options = "" )
+ErrorCode read_file_( Interface& moab, const char* input_file, const char* options = "" )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   ReadSTL reader( &moab );
   FileOptions opts(options);
   rval = reader.load_file( input_file, 0, opts, 0, 0, 0 );
   return rval;
 }
 
-void read_file( MBInterface& moab, const char* input_file, const char* options )
+void read_file( Interface& moab, const char* input_file, const char* options )
 {
-  MBErrorCode rval = read_file_( moab, input_file, options );
+  ErrorCode rval = read_file_( moab, input_file, options );
   CHECK_ERR(rval);
 }
 
 void convert_file( const char* input_file, const char* output_file, const char* options )
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
 
   ReadSTL reader( &moab );
   FileOptions opts_reader("");
@@ -90,7 +92,7 @@
 
 void test_read_ascii()
 {
-  MBCore moab;
+  Core moab;
   read_file( moab, sample, "ASCII" );
   check_mesh_is_tet( moab );
 }
@@ -98,7 +100,7 @@
 void test_write_ascii()
 {
   convert_file( sample, tmp_file, "ASCII" );
-  MBCore moab;
+  Core moab;
   read_file( moab, tmp_file, "ASCII" );
   remove( tmp_file );
   check_mesh_is_tet( moab );
@@ -106,8 +108,8 @@
 
 void test_type_option()
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
 
   rval = read_file_( moab, sample, "BINARY" );
   CHECK( MB_SUCCESS != rval );
@@ -121,7 +123,7 @@
 
 void test_detect_type()
 {
-  MBCore moab;
+  Core moab;
 
   read_file( moab, sample );
   
@@ -133,8 +135,8 @@
 
 void test_endian_option()
 {
-  MBErrorCode rval;
-  MBCore moab;
+  ErrorCode rval;
+  Core moab;
 
   convert_file( sample, tmp_file, "BINARY;BIG_ENDIAN" );
   rval = read_file_( moab, tmp_file, "BINARY;LITTLE_ENDIAN" );
@@ -149,7 +151,7 @@
 
 void test_big_endian()
 {
-  MBCore moab;
+  Core moab;
   convert_file( sample, tmp_file, "BINARY;BIG_ENDIAN" );
   read_file( moab, tmp_file, "BINARY;BIG_ENDIAN" );
   check_mesh_is_tet( moab );
@@ -158,7 +160,7 @@
 
 void test_little_endian()
 {
-  MBCore moab;
+  Core moab;
   convert_file( sample, tmp_file, "BINARY;LITTLE_ENDIAN" );
   read_file( moab, tmp_file, "BINARY;LITTLE_ENDIAN" );
   check_mesh_is_tet( moab );
@@ -167,7 +169,7 @@
 
 void test_detect_byte_order()
 {
-  MBCore moab;
+  Core moab;
 
   convert_file( sample, tmp_file, "BINARY;LITTLE_ENDIAN" );
   read_file( moab, tmp_file, "BINARY" );
@@ -179,10 +181,10 @@
 }
 
 
-void check_mesh_is_tet( MBInterface& moab )
+void check_mesh_is_tet( Interface& moab )
 {
-  MBErrorCode rval;
-  MBRange verts, tris, other;
+  ErrorCode rval;
+  Range verts, tris, other;
   rval = moab.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   rval = moab.get_entities_by_type( 0, MBTRI, tris );
@@ -200,8 +202,8 @@
                                      { 1, 0, 0 },
                                      { 0, 1, 0 },
                                      { 0, 0, 1 } };
-  MBEntityHandle vert_handles[4] = { 0, 0, 0, 0 };
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  EntityHandle vert_handles[4] = { 0, 0, 0, 0 };
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
     rval = moab.get_coords( &*i, 1, coords );
     CHECK_ERR(rval);
@@ -215,7 +217,7 @@
       }
       
       if (ds < 1e-6) {
-        CHECK_EQUAL( (MBEntityHandle)0, vert_handles[j] );
+        CHECK_EQUAL( (EntityHandle)0, vert_handles[j] );
         vert_handles[j] = *i;
         found = true;
         break;
@@ -228,9 +230,9 @@
                                 { 0, 2, 1 },
                                 { 0, 3, 2 },
                                 { 1, 2, 3 } };
-  MBEntityHandle tri_handles[4] = { 0, 0, 0, 0 };
-  for (MBRange::iterator i = tris.begin(); i != tris.end(); ++i) {
-    const MBEntityHandle* conn = 0;
+  EntityHandle tri_handles[4] = { 0, 0, 0, 0 };
+  for (Range::iterator i = tris.begin(); i != tris.end(); ++i) {
+    const EntityHandle* conn = 0;
     int len = 0;
     rval = moab.get_connectivity( *i, conn, len );
     CHECK_ERR(rval);
@@ -252,7 +254,7 @@
       
       if (expt_conn[j][(k+1)%3] == conn_idx[1] && 
           expt_conn[j][(k+2)%3] == conn_idx[2]) {
-        CHECK_EQUAL( (MBEntityHandle)0, tri_handles[j] );
+        CHECK_EQUAL( (EntityHandle)0, tri_handles[j] );
         tri_handles[j] = *i;
         found = true;
         break;

Modified: MOAB/trunk/test/io/test_exo.cpp
===================================================================
--- MOAB/trunk/test/io/test_exo.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/test_exo.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,13 +13,15 @@
  * 
  */
 
-#include "MBDefines.h"
-#include "MBCore.hpp"
+#include "moab/Defines.h"
+#include "moab/Core.hpp"
 #include "ReadWriteExoII.hpp"
-#include "MB_MBSet.hpp"
+#include "moab/_MBSet.hpp"
 
 #include <iostream>
 
+using namespace moab;
+
 std::ostream& operator<<(std::ostream& out, const std::vector<int> & v)
 {
   std::copy(v.begin(), v.end(), 
@@ -35,9 +37,9 @@
     return 1;
   }
 
-  MBCore mdb;
+  Core mdb;
   ReadWriteExoII reader(&mdb);
-  MBErrorCode result = reader.load_file(argv[1], NULL);
+  ErrorCode result = reader.load_file(argv[1], NULL);
 
   std::cout << "Result of reading file = " 
             << (MB_FAILURE == result ? "FAILURE." : "SUCCESS.")

Modified: MOAB/trunk/test/io/test_rms.cpp
===================================================================
--- MOAB/trunk/test/io/test_rms.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/io/test_rms.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,8 +14,10 @@
  */
 
 #include "TSTT_MB_QueryInterface.h"
-#include "MB_RMBSet.hpp"
+#include "moab/_RMBSet.hpp"
 
+using namespace moab;
+
 int compare_coords(double *xval, double *yval, double *zval,
                    double *nodex, double *nodey, double *nodez, 
                    const int num_nodes);

Modified: MOAB/trunk/test/kd_tree_test.cpp
===================================================================
--- MOAB/trunk/test/kd_tree_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/kd_tree_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,13 +1,13 @@
-#include "MBCore.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/Range.hpp"
 
 #include <math.h>
 #include <assert.h>
 #include <float.h>
 #include <cstdio>
 
-#include "MBCartVect.hpp"
+#include "moab/CartVect.hpp"
 
 #include <stdlib.h>
 #ifdef NDEBUG
@@ -15,22 +15,24 @@
 #  define assert(A) do { if (!(A)) abort(); } while(false)
 #endif
 
+using namespace moab;
+
 const unsigned INTERVALS = 4;
 const unsigned DEPTH = 7; // 3*log2(INTERVALS)+1
 const char* TAG_NAME = "TEST_DATA";
 
-void test_iterator_back( MBAdaptiveKDTree& tool, MBEntityHandle root );
-void test_point_search( MBAdaptiveKDTree& tool, MBEntityHandle root );
+void test_iterator_back( AdaptiveKDTree& tool, EntityHandle root );
+void test_point_search( AdaptiveKDTree& tool, EntityHandle root );
 
 int main()
 {
   // Initialize MOAB & create tree tool
-  MBCore moab;
-  MBAdaptiveKDTree tool(&moab);
+  Core moab;
+  AdaptiveKDTree tool(&moab);
   
   // Create tree root
-  MBErrorCode err;
-  MBEntityHandle root, leaf;
+  ErrorCode err;
+  EntityHandle root, leaf;
   const double tree_box_min_corner[] = { 0, 0, 0 };  
     // Make each leaf box be 1x1x1.
   const double tree_box_max_corner[] = { INTERVALS, INTERVALS, INTERVALS };
@@ -38,13 +40,13 @@
   assert(!err);
   
   // Use iterator to create tree to fixed depth of DEPTH
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   err = tool.get_tree_iterator( root, iter );
   assert(!err);
   while(err == MB_SUCCESS) { 
     if (iter.depth() < DEPTH) {
         // bisect leaves along alternating axes
-      MBAdaptiveKDTree::Plane split;
+      AdaptiveKDTree::Plane split;
       split.norm = iter.depth() % 3;  // alternate split axes;
       split.coord = 0.5 * (iter.box_min()[split.norm] + iter.box_max()[split.norm]);
       err = tool.split_leaf( iter, split ); // advances iter to first new leaf
@@ -58,7 +60,7 @@
   assert(MB_ENTITY_NOT_FOUND == err);
   
   // define a tag to use to store integer values on tree leaves
-  MBTag data;
+  Tag data;
   err = moab.tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, data, 0, false );
   assert(!err);
   
@@ -131,7 +133,7 @@
   assert(!err);
 
   // get root handle for tree
-  MBRange range;
+  Range range;
   err = tool.find_all_trees( range );
   assert(!err);
   assert(range.size() == 1);
@@ -193,15 +195,15 @@
 }
 
 
-void test_iterator_back( MBAdaptiveKDTree& tool, MBEntityHandle root )
+void test_iterator_back( AdaptiveKDTree& tool, EntityHandle root )
 {
-  MBAdaptiveKDTreeIter iter;
-  MBErrorCode rval = tool.get_tree_iterator( root, iter );
+  AdaptiveKDTreeIter iter;
+  ErrorCode rval = tool.get_tree_iterator( root, iter );
   assert( MB_SUCCESS == rval );
   
-  MBCartVect min( iter.box_min() );
-  MBCartVect max( iter.box_max() );
-  MBEntityHandle leaf = iter.handle();
+  CartVect min( iter.box_min() );
+  CartVect max( iter.box_max() );
+  EntityHandle leaf = iter.handle();
   
     // going back from first location should fail.
   rval = iter.back();
@@ -216,9 +218,9 @@
   
   while (MB_SUCCESS == iter.step()) {
       // Get values at current iterator location
-    MBCartVect next_min( iter.box_min() );
-    MBCartVect next_max( iter.box_max() );
-    MBEntityHandle next_leaf = iter.handle();
+    CartVect next_min( iter.box_min() );
+    CartVect next_max( iter.box_max() );
+    EntityHandle next_leaf = iter.handle();
   
       // step back to previous location
     rval = iter.back();
@@ -245,15 +247,15 @@
   }
 }
 
-void test_point_search( MBAdaptiveKDTree& tool, MBEntityHandle root )
+void test_point_search( AdaptiveKDTree& tool, EntityHandle root )
 {
-  MBErrorCode rval;
-  MBEntityHandle leaf;
-  MBAdaptiveKDTreeIter iter, iter2;
+  ErrorCode rval;
+  EntityHandle leaf;
+  AdaptiveKDTreeIter iter, iter2;
   
     // points to test
-  MBCartVect left( 0.5 );
-  MBCartVect right( MBCartVect(INTERVALS) - left );
+  CartVect left( 0.5 );
+  CartVect right( CartVect(INTERVALS) - left );
  
     // compare leaf search to iterator search
   rval = tool.leaf_containing_point( root, left.array(), leaf );

Modified: MOAB/trunk/test/kd_tree_time.cpp
===================================================================
--- MOAB/trunk/test/kd_tree_time.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/kd_tree_time.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,21 +1,23 @@
-#include "MBCore.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/Range.hpp"
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+using namespace moab;
+
 void usage( const char* argv0 )
 {
   fprintf(stderr, "usage: %s [-t] [-d <result_file>] <tree_file> <point_file> [<count>]\n", argv0);
   exit(1);
 }
 
-void print_file_stats( MBInterface& moab )
+void print_file_stats( Interface& moab )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int num_tri;
-  MBRange sets;
+  Range sets;
   unsigned long set_mem, set_am, tag_mem, tag_am;
   
   rval = moab.get_number_entities_by_type( 0, MBTRI, num_tri );
@@ -97,28 +99,28 @@
  
   printf("Loading tree..."); fflush( stdout );
   t = clock();
-  MBCore moab;
-  MBErrorCode rval = moab.load_mesh( tree_file, 0, 0 );
+  Core moab;
+  ErrorCode rval = moab.load_mesh( tree_file, 0, 0 );
   if (MB_SUCCESS != rval) {
     fprintf(stderr,"Failed to read file: %s\n", tree_file );
     return 2;
   }
   printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
   
-  MBRange range;
-  MBAdaptiveKDTree tool(&moab);
+  Range range;
+  AdaptiveKDTree tool(&moab);
   tool.find_all_trees(range);
   if (range.size() != 1) {
     fprintf(stderr,"%s : found %d kd-trees\n", argv[1], (int)range.size() );
     return 3;
   }
-  const MBEntityHandle root = range.front();
+  const EntityHandle root = range.front();
 
   print_file_stats( moab );
   
   printf("Running point queries..."); fflush( stdout );
   t = clock();
-  MBEntityHandle leaf;
+  EntityHandle leaf;
   double pt[3];
   for (unsigned long i = 0; i < count; ++i) {
     const double* coords = values + 3 * (i % length);
@@ -127,7 +129,7 @@
     else
       rval = tool.leaf_containing_point( root, coords, leaf );
     if (MB_SUCCESS != rval) {
-      fprintf(stderr, "Failure (MBErrorCode == %d) for point %d (%f, %f, %f)\n",
+      fprintf(stderr, "Failure (ErrorCode == %d) for point %d (%f, %f, %f)\n",
         (int)rval, (int)(count % length), coords[0], coords[1], coords[2] );
     }
     else if (rfile) {

Modified: MOAB/trunk/test/kd_tree_tool.cpp
===================================================================
--- MOAB/trunk/test/kd_tree_tool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/kd_tree_tool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,9 @@
-#include "MBCore.hpp"
-#include "MBCartVect.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/GeomUtil.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 #include <iostream>
 #include <iomanip>
 #include <cstdio>
@@ -16,30 +16,32 @@
 #include <fcntl.h>
 #endif 
 
+using namespace moab;
+
 const int MAX_TAG_VALUE = 32; // maximum value to use when tagging entities with tree cell number
 const char* TAG_NAME = "TREE_CELL";
 
 std::string clock_to_string( clock_t t );
 std::string mem_to_string( unsigned long mem );
 
-void build_tree( MBInterface* interface, const MBRange& elems,
-                 MBAdaptiveKDTree::Settings settings, 
+void build_tree( Interface* interface, const Range& elems,
+                 AdaptiveKDTree::Settings settings, 
                  unsigned meshset_flags );
-void build_grid( MBInterface* iface,
-                 MBAdaptiveKDTree::Settings settings,
+void build_grid( Interface* iface,
+                 AdaptiveKDTree::Settings settings,
                  unsigned meshset_flags,
                  const double dims[3] );
-void delete_existing_tree( MBInterface* interface );
-void print_stats( MBInterface* interface );
-void tag_elements( MBInterface* interface );
-void tag_vertices( MBInterface* interface );
-void write_tree_blocks( MBInterface* interface, const char* file );
+void delete_existing_tree( Interface* interface );
+void print_stats( Interface* interface );
+void tag_elements( Interface* interface );
+void tag_vertices( Interface* interface );
+void write_tree_blocks( Interface* interface, const char* file );
 
-static const char* ds( MBAdaptiveKDTree::CandidatePlaneSet scheme )
+static const char* ds( AdaptiveKDTree::CandidatePlaneSet scheme )
 {
   static const char def[] = " (default)";
   const static char non[] = "";
-  MBAdaptiveKDTree::Settings st;
+  AdaptiveKDTree::Settings st;
   return scheme == st.candidatePlaneSet ? def : non;
 }
   
@@ -50,16 +52,16 @@
     << "kd_tree_tool [-d <int>] -G <dims> [-s|-S] <output file>" << std::endl
     << "kd_tree_tool [-h]" << std::endl;
   if (!err) {
-    MBAdaptiveKDTree::Settings st;
+    AdaptiveKDTree::Settings st;
     s << "Tool to build adaptive kd-Tree" << std::endl;
     s << "  -d <int>  Specify maximum depth for tree. Default: " << st.maxTreeDepth << std::endl
       << "  -n <int>  Specify maximum entities per leaf. Default: " << st.maxEntPerLeaf << std::endl
       << "  -2        Build tree from surface elements. Default: yes" << std::endl
       << "  -3        Build tree from volume elements. Default: yes" << std::endl
-      << "  -u        Use 'SUBDIVISION' scheme for tree construction" << ds(MBAdaptiveKDTree::SUBDIVISION) << std::endl
-      << "  -p        Use 'SUBDIVISION_SNAP' tree construction algorithm." << ds(MBAdaptiveKDTree::SUBDIVISION_SNAP) << std::endl
-      << "  -m        Use 'VERTEX_MEDIAN' tree construction algorithm." << ds(MBAdaptiveKDTree::VERTEX_MEDIAN) << std::endl
-      << "  -v        Use 'VERTEX_SAMPLE' tree construction algorithm." << ds(MBAdaptiveKDTree::VERTEX_SAMPLE) << std::endl
+      << "  -u        Use 'SUBDIVISION' scheme for tree construction" << ds(AdaptiveKDTree::SUBDIVISION) << std::endl
+      << "  -p        Use 'SUBDIVISION_SNAP' tree construction algorithm." << ds(AdaptiveKDTree::SUBDIVISION_SNAP) << std::endl
+      << "  -m        Use 'VERTEX_MEDIAN' tree construction algorithm." << ds(AdaptiveKDTree::VERTEX_MEDIAN) << std::endl
+      << "  -v        Use 'VERTEX_SAMPLE' tree construction algorithm." << ds(AdaptiveKDTree::VERTEX_SAMPLE) << std::endl
       << "  -N <int>  Specify candidate split planes per axis.  Default: " << st.candidateSplitsPerDir << std::endl
       << "  -t        Tag elements will tree cell number." << std::endl
       << "  -T        Write tree boxes to file." << std::endl
@@ -160,7 +162,7 @@
   const char* input_file = 0;
   const char* output_file = 0;
   const char* tree_file = 0;
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree::Settings settings;
   unsigned meshset_flags = MESHSET_SET;
   bool tag_elems = false;
   clock_t load_time, build_time, stat_time, tag_time, write_time, block_time;
@@ -188,10 +190,10 @@
       case 's': meshset_flags = MESHSET_SET;                        break;
       case 'd': settings.maxTreeDepth  = parseint( i, argc, argv ); break;
       case 'n': settings.maxEntPerLeaf = parseint( i, argc, argv ); break;
-      case 'u': settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;      break;
-      case 'p': settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION_SNAP; break;
-      case 'm': settings.candidatePlaneSet = MBAdaptiveKDTree::VERTEX_MEDIAN;    break;
-      case 'v': settings.candidatePlaneSet = MBAdaptiveKDTree::VERTEX_SAMPLE;    break;
+      case 'u': settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;      break;
+      case 'p': settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION_SNAP; break;
+      case 'm': settings.candidatePlaneSet = AdaptiveKDTree::VERTEX_MEDIAN;    break;
+      case 'v': settings.candidatePlaneSet = AdaptiveKDTree::VERTEX_SAMPLE;    break;
       case 'N': settings.candidateSplitsPerDir = parseint( i, argc, argv );      break;
       case 't': tag_elems = true;                                   break;
       case 'T': tree_file = argv[++i];                              break;
@@ -208,9 +210,9 @@
   if (!surf_elems && !vol_elems)
     surf_elems = vol_elems = true;
   
-  MBErrorCode rval;
-  MBCore moab_core;
-  MBInterface* interface = &moab_core;
+  ErrorCode rval;
+  Core moab_core;
+  Interface* interface = &moab_core;
   
   if (make_grid) {
     load_time = 0;
@@ -234,14 +236,14 @@
 
     std::cout << "Building tree..." << std::endl;
     build_time = clock();
-    MBRange elems;
+    Range elems;
     if (!surf_elems) {
       interface->get_entities_by_dimension( 0, 3, elems );
     }
     else {
       interface->get_entities_by_dimension( 0, 2, elems );
       if (vol_elems) {
-        MBRange tmp;
+        Range tmp;
         interface->get_entities_by_dimension( 0, 3, tmp );
         elems.merge( tmp );
       }
@@ -304,15 +306,15 @@
 }
 
   
-void delete_existing_tree( MBInterface* interface )
+void delete_existing_tree( Interface* interface )
 {
-  MBRange trees;
-  MBAdaptiveKDTree tool(interface);
+  Range trees;
+  AdaptiveKDTree tool(interface);
 
   tool.find_all_trees( trees );
   if (!trees.empty())
     std::cout << "Destroying existing tree(s) contained in file" << std::endl;
-  for (MBRange::iterator i = trees.begin(); i != trees.end(); ++i)
+  for (Range::iterator i = trees.begin(); i != trees.end(); ++i)
     tool.delete_tree( *i );
   
   trees.clear();
@@ -323,20 +325,20 @@
   }
 }
   
-void build_tree( MBInterface* interface,
-                 const MBRange& elems, 
-                 MBAdaptiveKDTree::Settings settings, 
+void build_tree( Interface* interface,
+                 const Range& elems, 
+                 AdaptiveKDTree::Settings settings, 
                  unsigned meshset_flags )
 {
-  MBErrorCode rval;
-  MBEntityHandle root = 0;
+  ErrorCode rval;
+  EntityHandle root = 0;
   
   if (elems.empty()) {
     std::cerr << "No elements from which to build tree." << std::endl;
     exit(4);
   }
   
-  MBAdaptiveKDTree tool(interface, 0, meshset_flags);
+  AdaptiveKDTree tool(interface, 0, meshset_flags);
   rval = tool.build_tree( elems, root, &settings );
   if (MB_SUCCESS != rval || !root) {
     std::cerr << "Tree construction failed." << std::endl;
@@ -344,16 +346,16 @@
   }
 }  
   
-void build_grid( MBInterface* interface, 
-                 MBAdaptiveKDTree::Settings settings, 
+void build_grid( Interface* interface, 
+                 AdaptiveKDTree::Settings settings, 
                  unsigned meshset_flags,
                  const double dims[3] )
 {
-  MBErrorCode rval;
-  MBEntityHandle root = 0;
-  MBAdaptiveKDTree tool(interface, 0, meshset_flags);
-  MBAdaptiveKDTreeIter iter;
-  MBAdaptiveKDTree::Plane plane;
+  ErrorCode rval;
+  EntityHandle root = 0;
+  AdaptiveKDTree tool(interface, 0, meshset_flags);
+  AdaptiveKDTreeIter iter;
+  AdaptiveKDTree::Plane plane;
 
   double min[3] = { -0.5*dims[0], -0.5*dims[1], -0.5*dims[2] };
   double max[3] = {  0.5*dims[0],  0.5*dims[1],  0.5*dims[2] };
@@ -456,11 +458,11 @@
   ++count;
 }
   
-void print_stats( MBInterface* interface )
+void print_stats( Interface* interface )
 {
-  MBEntityHandle root;
-  MBRange range;
-  MBAdaptiveKDTree tool(interface);
+  EntityHandle root;
+  Range range;
+  AdaptiveKDTree tool(interface);
   
   tool.find_all_trees( range );
   if (range.size() != 1) {
@@ -474,10 +476,10 @@
   root = *range.begin();
   range.clear();
 
-  MBRange tree_sets, elem2d, elem3d, verts, all;
+  Range tree_sets, elem2d, elem3d, verts, all;
   //interface->get_child_meshsets( root, tree_sets, 0 );
   interface->get_entities_by_type( 0, MBENTITYSET, tree_sets );
-  tree_sets.erase( tree_sets.begin(), MBRange::lower_bound( tree_sets.begin(), tree_sets.end(), root ) );
+  tree_sets.erase( tree_sets.begin(), Range::lower_bound( tree_sets.begin(), tree_sets.end(), root ) );
   interface->get_entities_by_dimension( 0, 2, elem2d );
   interface->get_entities_by_dimension( 0, 3, elem3d );
   interface->get_entities_by_type( 0, MBVERTEX, verts );
@@ -508,7 +510,7 @@
   SimpleStat<unsigned> depth, size;
   SimpleStat<double> vol, surf;
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   tool.get_tree_iterator( root, iter );
   do {
     depth.add( iter.depth() );
@@ -556,17 +558,17 @@
 }
 
 
-static int hash_handle( MBEntityHandle handle )
+static int hash_handle( EntityHandle handle )
 {
-  MBEntityID h = ID_FROM_HANDLE(handle);
+  EntityID h = ID_FROM_HANDLE(handle);
   return (int)((h * 13 + 7) % MAX_TAG_VALUE) + 1;
 }   
 
-void tag_elements( MBInterface* moab )
+void tag_elements( Interface* moab )
 {
-  MBEntityHandle root;
-  MBRange range;
-  MBAdaptiveKDTree tool(moab);
+  EntityHandle root;
+  Range range;
+  AdaptiveKDTree tool(moab);
   
   tool.find_all_trees( range );
   if (range.size() != 1) {
@@ -580,11 +582,11 @@
   root = *range.begin();
   range.clear();
   
-  MBTag tag;
+  Tag tag;
   int zero = 0;
   moab->tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   tool.get_tree_iterator( root, iter );
   
   std::vector<int> tag_vals;
@@ -597,11 +599,11 @@
   } while (MB_SUCCESS == iter.step());
 }
 
-void tag_vertices( MBInterface* moab )
+void tag_vertices( Interface* moab )
 {
-  MBEntityHandle root;
-  MBRange range;
-  MBAdaptiveKDTree tool(moab);
+  EntityHandle root;
+  Range range;
+  AdaptiveKDTree tool(moab);
   
   tool.find_all_trees( range );
   if (range.size() != 1) {
@@ -615,11 +617,11 @@
   root = *range.begin();
   range.clear();
   
-  MBTag tag;
+  Tag tag;
   int zero = 0;
   moab->tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   tool.get_tree_iterator( root, iter );
   
   do {
@@ -627,24 +629,24 @@
     moab->get_entities_by_handle( iter.handle(), range );
     
     int tag_val = hash_handle(iter.handle());
-    MBRange verts;
-    moab->get_adjacencies( range, 0, false, verts, MBInterface::UNION );
-    for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
-      MBCartVect coords;
+    Range verts;
+    moab->get_adjacencies( range, 0, false, verts, Interface::UNION );
+    for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
+      CartVect coords;
       moab->get_coords( &*i, 1, coords.array() );
-      if (MBGeomUtil::box_point_overlap( MBCartVect(iter.box_min()),
-                                         MBCartVect(iter.box_max()),
+      if (GeomUtil::box_point_overlap( CartVect(iter.box_min()),
+                                         CartVect(iter.box_max()),
                                          coords, 1e-7 )) 
         moab->tag_set_data( tag, &*i, 1, &tag_val );
     }
   } while (MB_SUCCESS == iter.step());
 }
 
-void write_tree_blocks( MBInterface* interface, const char* file )
+void write_tree_blocks( Interface* interface, const char* file )
 {
-  MBEntityHandle root;
-  MBRange range;
-  MBAdaptiveKDTree tool(interface);
+  EntityHandle root;
+  Range range;
+  AdaptiveKDTree tool(interface);
   
   tool.find_all_trees( range );
   if (range.size() != 1) {
@@ -658,13 +660,13 @@
   root = *range.begin();
   range.clear();
   
-  MBCore moab2;
-  MBTag tag;
+  Core moab2;
+  Tag tag;
   int zero = 0;
   moab2.tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
   
   
-  MBAdaptiveKDTreeIter iter;
+  AdaptiveKDTreeIter iter;
   tool.get_tree_iterator( root, iter );
   
   do {
@@ -682,7 +684,7 @@
                           x2, y1, z2,
                           x2, y2, z2,
                           x1, y2, z2 };
-    MBEntityHandle verts[8], elem;
+    EntityHandle verts[8], elem;
     for (int i = 0; i < 8; ++i)
       moab2.create_vertex( coords + 3*i, verts[i] );
     moab2.create_element( MBHEX, verts, 8, elem );

Modified: MOAB/trunk/test/mbcn_test.cc
===================================================================
--- MOAB/trunk/test/mbcn_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/mbcn_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,8 @@
 #include "TestUtil.hpp"
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 
+using namespace moab;
+
 void test_dimension_pair();
 void test_type_names();
 void test_dimension();
@@ -38,7 +40,7 @@
 void test_opposite_side_tet();
 void test_opposite_side_hex();
 
-void test_has_mid_nodes( MBEntityType type );
+void test_has_mid_nodes( EntityType type );
 void test_has_mid_nodes_edge() { test_has_mid_nodes(MBEDGE); }
 void test_has_mid_nodes_tri()  { test_has_mid_nodes(MBTRI); }
 void test_has_mid_nodes_quad() { test_has_mid_nodes(MBQUAD); }
@@ -51,8 +53,8 @@
 void test_ho_node_parent();
 void test_ho_node_index();
 
-void test_sub_entity_nodes( MBEntityType parent, int sub_dimension );
-void test_sub_entity_nodes( MBEntityType parent, int num_nodes, int sub_dimension );
+void test_sub_entity_nodes( EntityType parent, int sub_dimension );
+void test_sub_entity_nodes( EntityType parent, int num_nodes, int sub_dimension );
 void test_sub_entity_nodes_tri_edges()  { test_sub_entity_nodes(MBTRI,     1 ); }
 void test_sub_entity_nodes_quad_edges() { test_sub_entity_nodes(MBQUAD,    1 ); }
 void test_sub_entity_nodes_tet_edges()  { test_sub_entity_nodes(MBTET,     1 ); }
@@ -133,7 +135,7 @@
   return result;
 }
 
-const MBEntityType elem_types[] = { MBTRI,
+const EntityType elem_types[] = { MBTRI,
                                     MBQUAD,
                                     MBTET,
                                     MBPYRAMID,
@@ -144,7 +146,7 @@
 
 void test_dimension_pair()
 {
-  MBDimensionPair dp;
+  DimensionPair dp;
   
   dp = MBCN::TypeDimensionMap[0];
   CHECK_EQUAL( MBVERTEX, dp.first );  
@@ -165,7 +167,7 @@
 
 void test_type_names()
 {
-  for (MBEntityType t = MBVERTEX; t != MBMAXTYPE; ++t) {
+  for (EntityType t = MBVERTEX; t != MBMAXTYPE; ++t) {
     const char* name = MBCN::EntityTypeName(t);
     CHECK_EQUAL( t, MBCN::EntityTypeFromName(name) );
   }
@@ -235,7 +237,7 @@
   CHECK_EQUAL( 6, MBCN::NumSubEntities(MBHEX, 2));
 }
 
-void do_test_sub_entity_type_2d( MBEntityType type )
+void do_test_sub_entity_type_2d( EntityType type )
 {
   for (int j = 0; j < MBCN::VerticesPerEntity(type); ++j) {
     CHECK_EQUAL( MBVERTEX, MBCN::SubEntityType(type, 0, j ) );
@@ -244,9 +246,9 @@
   CHECK_EQUAL( type, MBCN::SubEntityType(type, 2, 0) );
 }
 
-void do_test_sub_entity_type_3d( MBEntityType type,
+void do_test_sub_entity_type_3d( EntityType type,
                                  int num_faces,
-                                 const MBEntityType* face_types )
+                                 const EntityType* face_types )
 {
   for (int j = 0; j < MBCN::VerticesPerEntity(type); ++j) {
     CHECK_EQUAL( MBVERTEX, MBCN::SubEntityType(type, 0, j ) );
@@ -257,7 +259,7 @@
   }
 
   for (int j = 0; j < num_faces; ++j) {
-    MBEntityType sub_type = MBCN::SubEntityType( type, 2, j );
+    EntityType sub_type = MBCN::SubEntityType( type, 2, j );
     CHECK_EQUAL( face_types[j], sub_type );
   }
 
@@ -288,36 +290,36 @@
 
 void test_sub_entity_type_tet()
 {
-  const MBEntityType types[] = { MBTRI, MBTRI, MBTRI, MBTRI };
+  const EntityType types[] = { MBTRI, MBTRI, MBTRI, MBTRI };
   do_test_sub_entity_type_3d( MBTET, sizeof(types)/sizeof(types[0]), types );
 }
 
 void test_sub_entity_type_pyr()
 {
-  const MBEntityType types[] = { MBQUAD, MBTRI, MBTRI, MBTRI, MBTRI };
+  const EntityType types[] = { MBQUAD, MBTRI, MBTRI, MBTRI, MBTRI };
   do_test_sub_entity_type_3d( MBPYRAMID, sizeof(types)/sizeof(types[0]), types );
 }
 
 void test_sub_entity_type_pri()
 {
-  const MBEntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBTRI, MBTRI };
+  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBTRI, MBTRI };
   do_test_sub_entity_type_3d( MBPRISM, sizeof(types)/sizeof(types[0]), types );
 }
 
 void test_sub_entity_type_knife()
 {
-  const MBEntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
+  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
   do_test_sub_entity_type_3d( MBKNIFE, sizeof(types)/sizeof(types[0]), types );
 }
 
 void test_sub_entity_type_hex()
 {
-  const MBEntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
+  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
   do_test_sub_entity_type_3d( MBHEX, sizeof(types)/sizeof(types[0]), types );
 }
 
 
-void test_0d_sub_entity_indices( MBEntityType type, int num_vtx )
+void test_0d_sub_entity_indices( EntityType type, int num_vtx )
 {
   for (int i = 0; i < num_vtx; ++i) {
     // zero input array
@@ -330,7 +332,7 @@
   }
 }
 
-void test_1d_sub_entity_indices( MBEntityType type, int num_edges, 
+void test_1d_sub_entity_indices( EntityType type, int num_edges, 
                                  const int (*edge_indices)[2] )
 {
   for (int i = 0; i < num_edges; ++i) {
@@ -350,7 +352,7 @@
   }
 }
 
-void test_2d_sub_entity_indices( MBEntityType type, int num_faces,
+void test_2d_sub_entity_indices( EntityType type, int num_faces,
                                  const int (*face_indices)[5] )
 {
   for (int i = 0; i < num_faces; ++i) {
@@ -389,7 +391,7 @@
   }
 }
 
-void test_elem_as_sub_entity( MBEntityType type, int dim, int num_vertices )
+void test_elem_as_sub_entity( EntityType type, int dim, int num_vertices )
 { 
   int indices[9] = { -2, -2, -2, -2, -2, -2, -2, -2, -2 };
   MBCN::SubEntityVertexIndices( type, dim, 0, indices );
@@ -433,7 +435,7 @@
 
 void test_sub_entity_indices_tet()
 {
-  const MBEntityType type = MBTET;
+  const EntityType type = MBTET;
   const int num_vtx = 4;
   const int edges[][2] = { { 0, 1 },
                            { 1, 2 },
@@ -453,7 +455,7 @@
 
 void test_sub_entity_indices_pyr()
 {
-  const MBEntityType type = MBPYRAMID;
+  const EntityType type = MBPYRAMID;
   const int num_vtx = 5;
   const int edges[][2] = { { 0, 1 },
                            { 1, 2 },
@@ -476,7 +478,7 @@
 
 void test_sub_entity_indices_pri()
 {
-  const MBEntityType type = MBPRISM;
+  const EntityType type = MBPRISM;
   const int num_vtx = 6;
   const int edges[][2] = { { 0, 1 },
                            { 1, 2 },
@@ -500,7 +502,7 @@
 
 void test_sub_entity_indices_hex()
 {
-  const MBEntityType type = MBHEX;
+  const EntityType type = MBHEX;
   const int num_vtx = 8;
   const int edges[][2] = { { 0, 1 },
                            { 1, 2 },
@@ -526,7 +528,7 @@
   test_elem_as_sub_entity( type, 3, num_vtx );
 }
 
-static void do_test_side_number_1d( MBEntityType type, int idx )
+static void do_test_side_number_1d( EntityType type, int idx )
 {
   // define a random handle list
   const int elem_verts[] = { 7400, 6233, 3027, 0454, 6839, 5391, 7735, 3603 };
@@ -551,7 +553,7 @@
   CHECK(result_offset == 1 || result_sense == -1);
 }     
 
-static void do_test_side_number_2d( MBEntityType type, int idx )
+static void do_test_side_number_2d( EntityType type, int idx )
 {
   // define a random handle list
   const int elem_verts[] = { 7400, 6233, 3027, 0454, 6839, 5391, 7735, 3603 };
@@ -867,7 +869,7 @@
   CHECK_EQUAL( 4, idx );
 }
 
-void test_has_mid_nodes(MBEntityType type)
+void test_has_mid_nodes(EntityType type)
 {
   const int combinations[][4] = { { 0, 0, 0, 0 },
                                   { 0, 1, 0, 0 },
@@ -918,8 +920,8 @@
                                   { 0, 0, 1, 1 },
                                   { 0, 1, 1, 1 } };
   
-  for (const MBEntityType* t = elem_types; *t != MBMAXTYPE; ++t) {
-    const MBEntityType type = *t;
+  for (const EntityType* t = elem_types; *t != MBMAXTYPE; ++t) {
+    const EntityType type = *t;
     const int dim = MBCN::Dimension(type);
       // calculate number of valid combinations of ho node flags
     int num_comb = 1;
@@ -981,8 +983,8 @@
                                   { 0, 0, 1, 1 },
                                   { 0, 1, 1, 1 } };
   
-  for (const MBEntityType* t = elem_types; *t != MBMAXTYPE; ++t) {
-    const MBEntityType type = *t;
+  for (const EntityType* t = elem_types; *t != MBMAXTYPE; ++t) {
+    const EntityType type = *t;
     const int dim = MBCN::Dimension(type);
       // calculate number of valid combinations of ho node flags
     int num_comb = 1;
@@ -1027,7 +1029,7 @@
   } // for each type
 }
 
-void test_sub_entity_nodes( MBEntityType parent, int sub_dimension )
+void test_sub_entity_nodes( EntityType parent, int sub_dimension )
 {
   const int num_corner = MBCN::VerticesPerEntity( parent );
   const int num_edge   = MBCN::NumSubEntities( parent, 1 );
@@ -1051,7 +1053,7 @@
   }
 }
 
-void test_sub_entity_nodes( MBEntityType parent, int num_nodes, int sub_dimension )
+void test_sub_entity_nodes( EntityType parent, int num_nodes, int sub_dimension )
 {
   const int num_sub = MBCN::NumSubEntities( parent, sub_dimension );
   const int parent_ho = MBCN::HasMidNodes( parent, num_nodes );
@@ -1062,7 +1064,7 @@
     // first test the types
   for (int i = 0; i < num_sub; ++i) {
     int num, conn[MB_MAX_SUB_ENTITY_VERTICES];
-    MBEntityType type;
+    EntityType type;
     MBCN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
     CHECK_EQUAL( MBCN::SubEntityType(parent, sub_dimension, i), type );
   }
@@ -1070,7 +1072,7 @@
     // now test that they have the correct number of higher-order node
   for (int i = 0; i < num_sub; ++i) {
     int num, conn[MB_MAX_SUB_ENTITY_VERTICES];
-    MBEntityType type;
+    EntityType type;
     MBCN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
     const int ho = MBCN::HasMidNodes( type, num );
     CHECK_EQUAL( child_ho, ho );
@@ -1079,7 +1081,7 @@
     // now test the actual indices
   for (int i = 0; i < num_sub; ++i) {
     int num, conn[MB_MAX_SUB_ENTITY_VERTICES], corners[MB_MAX_SUB_ENTITY_VERTICES];
-    MBEntityType type;
+    EntityType type;
     MBCN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
     
       // check corner indices against SubEntityVertexIndices

Modified: MOAB/trunk/test/merge_test.cpp
===================================================================
--- MOAB/trunk/test/merge_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/merge_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,12 +3,13 @@
 #include <utility>
 #include <iostream>
 using namespace std;
+using namespace moab;
 
-#include "MBCore.hpp"
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
 
-MBInterface* gMB = 0;
+Interface* gMB = 0;
 
 class EntityCount
 {
@@ -22,8 +23,8 @@
 
   EntityCount();
 
-  MBErrorCode get_counts();
-  MBErrorCode create_adjacencies(MBRange &entities, int adj_dim);
+  ErrorCode get_counts();
+  ErrorCode create_adjacencies(Range &entities, int adj_dim);
   void copy_counts(EntityCount &count);
   void print();
 };
@@ -48,9 +49,9 @@
   tet = count.tet;
 }
 
-MBErrorCode EntityCount::get_counts()
+ErrorCode EntityCount::get_counts()
 {
-  MBRange entities;
+  Range entities;
   int do_create = edge == 0;
 
   if(gMB->get_entities_by_type(0, MBVERTEX, entities) != MB_SUCCESS)
@@ -110,11 +111,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode EntityCount::create_adjacencies(MBRange &entities, int adj_dim)
+ErrorCode EntityCount::create_adjacencies(Range &entities, int adj_dim)
 {
-  MBErrorCode result;
-  MBRange::iterator iter;
-  std::vector<MBEntityHandle> adjacencies;
+  ErrorCode result;
+  Range::iterator iter;
+  std::vector<EntityHandle> adjacencies;
   
   for (iter = entities.begin(); iter != entities.end(); iter++)
   {
@@ -155,13 +156,13 @@
 }
 
 // dumb n^2 coincident node algorithm
-MBErrorCode find_coincident_nodes(MBRange vertices,
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > &coin_nodes)
+ErrorCode find_coincident_nodes(Range vertices,
+  std::vector< std::pair<EntityHandle,EntityHandle> > &coin_nodes)
 {
   double first_coords[3], second_coords[3];
-  MBRange::iterator iter, jter;
-  std::pair<MBEntityHandle, MBEntityHandle> coincident_pair;
-  MBErrorCode result;
+  Range::iterator iter, jter;
+  std::pair<EntityHandle, EntityHandle> coincident_pair;
+  ErrorCode result;
 
   for (iter = vertices.begin(); iter != vertices.end(); iter++)
   {
@@ -189,13 +190,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode find_coincident_edges(MBRange entities,
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > &coin_edges)
+ErrorCode find_coincident_edges(Range entities,
+  std::vector< std::pair<EntityHandle,EntityHandle> > &coin_edges)
 {
   double coords1[3], coords2[3], coords3[3];
-  MBRange::iterator iter, jter;
-  std::vector<MBEntityHandle> conn(2);
-  std::pair<MBEntityHandle, MBEntityHandle> coincident_pair;
+  Range::iterator iter, jter;
+  std::vector<EntityHandle> conn(2);
+  std::pair<EntityHandle, EntityHandle> coincident_pair;
 
   for(iter = entities.begin(); iter != entities.end(); iter++)
   {
@@ -239,13 +240,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode find_coincident_elements(MBRange entities, int num_nodes,
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > &coin)
+ErrorCode find_coincident_elements(Range entities, int num_nodes,
+  std::vector< std::pair<EntityHandle,EntityHandle> > &coin)
 {
   double coords1[8][3], coords2[8][3];
-  MBRange::iterator iter, jter;
-  std::vector<MBEntityHandle> conn(8);
-  std::pair<MBEntityHandle, MBEntityHandle> coincident_pair;
+  Range::iterator iter, jter;
+  std::vector<EntityHandle> conn(8);
+  std::pair<EntityHandle, EntityHandle> coincident_pair;
   int i = 0, j = 0, ii = 0;
 
   for(iter = entities.begin(); iter != entities.end(); iter++)
@@ -306,11 +307,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode coincident_counts(EntityCount &curr_count,
+ErrorCode coincident_counts(EntityCount &curr_count,
                                EntityCount &diff_count)
 {
-  MBRange entities;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  Range entities;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
 
 
   if(curr_count.node > 0)
@@ -371,12 +372,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode merge_top_down(EntityCount &init_count,
+ErrorCode merge_top_down(EntityCount &init_count,
                             EntityCount &curr_count)
 {
-  MBRange entities;
+  Range entities;
   EntityCount diff_count;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
 
   // Find how many objects of each type need to be merged.
   if(coincident_counts(curr_count, diff_count) != MB_SUCCESS)
@@ -415,7 +416,7 @@
     find_coincident_edges(entities, coincident);
   }
 
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
     gMB->merge_entities((*iter).first, (*iter).second, false, true);
 
@@ -438,22 +439,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode merge_nodes(EntityCount &init_count, EntityCount &curr_count)
+ErrorCode merge_nodes(EntityCount &init_count, EntityCount &curr_count)
 {
   cout << "Merging Coincident Nodes:" << endl;
 
   // Get the list of vertices from the database.
-  MBRange vertices;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBVERTEX,  vertices);
+  Range vertices;
+  ErrorCode result = gMB->get_entities_by_type(0, MBVERTEX,  vertices);
   if(result != MB_SUCCESS)
     return result;
 
   // find the coincident node pairs
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident_nodes;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident_nodes;
   find_coincident_nodes(vertices, coincident_nodes);
 
   // merge the coincident nodes
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident_nodes.begin(); iter != coincident_nodes.end(); iter++)
   {
     cout << "   Coincident nodes: " << (*iter).first << "-"
@@ -491,23 +492,23 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode merge_edges(EntityCount &init_count, EntityCount &curr_count)
+ErrorCode merge_edges(EntityCount &init_count, EntityCount &curr_count)
 {
   cout << "Merging Coincident Edges:" << endl;
 
   // Get the list of entities from the database.
-  MBRange entities;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBEDGE,  entities);
+  Range entities;
+  ErrorCode result = gMB->get_entities_by_type(0, MBEDGE,  entities);
   if(result != MB_SUCCESS)
     return result;
 
   // find the coincident edge pairs
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident_edges;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident_edges;
   find_coincident_edges(entities, coincident_edges);
 
   // merge the coincident edges
   unsigned long id1, id2;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident_edges.begin(); iter != coincident_edges.end(); iter++)
   {
     id1 = gMB->id_from_handle((*iter).first);
@@ -544,24 +545,24 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode merge_2D_elem(EntityCount &init_count, EntityCount &curr_count)
+ErrorCode merge_2D_elem(EntityCount &init_count, EntityCount &curr_count)
 {
   cout << "Merging Coincident 2D Elements:" << endl;
 
   // Get the list of tris from the database.
-  MBRange entities;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBTRI,  entities);
+  Range entities;
+  ErrorCode result = gMB->get_entities_by_type(0, MBTRI,  entities);
   if(result != MB_SUCCESS)
     return result;
 
   // find the coincident tri pairs
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
   find_coincident_elements(entities, 3, coincident);
 
   // merge the coincident tris
   unsigned long id1, id2;
   unsigned int tri_diff = coincident.size();
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
   {
     id1 = gMB->id_from_handle((*iter).first);
@@ -626,26 +627,26 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode merge_3D_elem(EntityCount &init_count, EntityCount &curr_count)
+ErrorCode merge_3D_elem(EntityCount &init_count, EntityCount &curr_count)
 {
   cout << "Merging Coincident 3D Elements:" << endl;
 
 
   // Get the list of tets from the database.
-  MBRange entities;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBTET,  entities);
+  Range entities;
+  ErrorCode result = gMB->get_entities_by_type(0, MBTET,  entities);
   if(result != MB_SUCCESS)
 
     return result;
 
   // find the coincident tet pairs
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
   find_coincident_elements(entities, 4, coincident);
 
   // merge the coincident tets
   unsigned long id1, id2;
   unsigned int tet_diff = coincident.size();
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
   {
     id1 = gMB->id_from_handle((*iter).first);
@@ -710,7 +711,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode read_file(std::string &file_name, EntityCount &counts)
+ErrorCode read_file(std::string &file_name, EntityCount &counts)
 {
   // Make sure the database is empty.
   gMB->delete_mesh();
@@ -732,12 +733,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode write_file(std::string &file_name)
+ErrorCode write_file(std::string &file_name)
 {
   //get the block tag
-  MBErrorCode result;
-  MBRange block_range;
-  MBTag block_tag;
+  ErrorCode result;
+  Range block_range;
+  Tag block_tag;
 
   if(gMB->tag_get_handle("MATERIAL_SET", block_tag) == MB_SUCCESS)
   {
@@ -748,9 +749,9 @@
   }
 
   //transfer range contents into vectors
-  std::vector<MBEntityHandle> output_list;
+  std::vector<EntityHandle> output_list;
 
-  MBRange::iterator range_iter, end_iter;
+  Range::iterator range_iter, end_iter;
   range_iter = block_range.begin();
   end_iter = block_range.end();
 
@@ -777,7 +778,7 @@
   return result;
 }
 
-MBErrorCode process_td_auto_merge(std::string &file_name)
+ErrorCode process_td_auto_merge(std::string &file_name)
 {
   EntityCount init_count;
   EntityCount curr_count;
@@ -795,8 +796,8 @@
   curr_count.print();
 
   // Try auto merging from the top down.
-  MBRange entities;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  Range entities;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
 
   // Find how many objects of each type need to be merged.
   if(coincident_counts(curr_count, diff_count) != MB_SUCCESS)
@@ -841,7 +842,7 @@
   }
 
   cout << "Merging coincident entities(top down)..." << endl;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
     gMB->merge_entities((*iter).first, (*iter).second, true, true);
 
@@ -873,7 +874,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode process_mo_auto_merge(std::string &file_name)
+ErrorCode process_mo_auto_merge(std::string &file_name)
 {
   EntityCount init_count;
   EntityCount curr_count;
@@ -891,8 +892,8 @@
   curr_count.print();
 
   // Try auto merging from the middle out.
-  MBRange entities;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  Range entities;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
 
   // Find how many objects of each type need to be merged.
   if(coincident_counts(curr_count, diff_count) != MB_SUCCESS)
@@ -915,7 +916,7 @@
   }
 
   cout << "Merging coincident entities(middle out)..." << endl;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
 
     gMB->merge_entities((*iter).first, (*iter).second, true,true);
@@ -948,7 +949,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode process_bu_auto_merge(std::string &file_name)
+ErrorCode process_bu_auto_merge(std::string &file_name)
 {
   EntityCount init_count;
   EntityCount curr_count;
@@ -966,8 +967,8 @@
   curr_count.print();
 
   // Try auto merging from the bottom up.
-  MBRange entities;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> > coincident;
+  Range entities;
+  std::vector< std::pair<EntityHandle,EntityHandle> > coincident;
 
   // Find how many objects of each type need to be merged.
   if(coincident_counts(curr_count, diff_count) != MB_SUCCESS)
@@ -979,7 +980,7 @@
   find_coincident_nodes(entities, coincident);
 
   cout << "Merging coincident entities(bottom up)..." << endl;
-  std::vector< std::pair<MBEntityHandle,MBEntityHandle> >::iterator iter;
+  std::vector< std::pair<EntityHandle,EntityHandle> >::iterator iter;
   for(iter=coincident.begin(); iter != coincident.end(); iter++)
     gMB->merge_entities((*iter).first, (*iter).second, true, true);
 
@@ -1012,7 +1013,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode process_merge(std::string &file_name)
+ErrorCode process_merge(std::string &file_name)
 {
   EntityCount init_count;
   EntityCount curr_count;
@@ -1064,7 +1065,7 @@
 
 int main()
 {
-  MBErrorCode result;
+  ErrorCode result;
   std::string test_files[] = {std::string("test/2barcase1.g"),
                               std::string("test/2barcase2.g"),
                               std::string("test/2hexcase1.g"),
@@ -1085,7 +1086,7 @@
                               std::string("test/2tricase3.g")};
 
   // Create the MB database instance.
-  gMB = new MBCore();
+  gMB = new Core();
 
   // Loop through the list of test files.
   unsigned int i;

Modified: MOAB/trunk/test/obb/Makefile.am
===================================================================
--- MOAB/trunk/test/obb/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/obb/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,8 +2,7 @@
 TESTS = obb_test
 
 AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
-               -I$(top_srcdir)/src -I$(top_builddir)/src -I.. \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab 
+               -I$(top_srcdir)/src -I$(top_builddir)/src -I.. 
 
 LDADD = $(top_builddir)/src/libMOAB.la
 

Modified: MOAB/trunk/test/obb/obb_test.cpp
===================================================================
--- MOAB/trunk/test/obb/obb_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/obb/obb_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBTagConventions.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBCN.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
+#include "OrientedBox.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/GeomUtil.hpp"
+#include "moab/MBCN.hpp"
 
 #include <iostream>
 #include <sstream>
@@ -16,6 +16,8 @@
 #define STRINGIFY_(A) #A
 #define STRINGIFY(A) STRINGIFY_(A)
 
+using namespace moab;
+
 const char* NAME = "obb_test";
 const char* DEFAULT_FILES[] = { STRINGIFY(SRCDIR) "/../3k-tri-sphere.vtk",
                               //  STRINGIFY(SRCDIR) "../4k-tri-plane.vtk",
@@ -58,7 +60,7 @@
         << " -s force construction of surface tree" << std::endl
         << " -S do not build surface tree." << std::endl
         << "    (Default: surface tree if file contains multiple surfaces" << std::endl
-        << " -u  use unordered (MBRange) meshsets for tree nodes" << std::endl
+        << " -u  use unordered (Range) meshsets for tree nodes" << std::endl
         << " -U  use ordered (vector) meshsets for tree nodes" << std::endl
         << " Verbosity (-q sets to 0, each -v increments, default is 1):" << std::endl
         << "  0 - no output" << std::endl
@@ -67,7 +69,7 @@
         << "  3 - output errors for each node" << std::endl
         << "  4 - print tree" << std::endl
         << "  5 - print tree w/ contents of each node" << std::endl
-        << " See documentation for MBOrientedBoxTreeTool::Settings for " << std::endl
+        << " See documentation for OrientedBoxTreeTool::Settings for " << std::endl
         << " a description of tree generation settings." << std::endl
       ;
   exit( !!error );
@@ -104,12 +106,12 @@
 enum TriOption { DISABLE, ENABLE, AUTO };
 
 int verbosity = 1;
-MBOrientedBoxTreeTool::Settings settings;
+OrientedBoxTreeTool::Settings settings;
 double tolerance = 1e-6;
 bool write_cubit = false;
 bool write_vtk = false;
 bool write_ray_vtk = false;
-std::vector<MBCartVect> rays;
+std::vector<CartVect> rays;
 const char* save_file_name = 0;
 TriOption surfTree = AUTO;
 
@@ -166,7 +168,7 @@
   }
   
   if (verbosity) {
-    MBCore core;
+    Core core;
     std::string version;
     core.impl_version( & version );
     std::cout << version << std::endl;
@@ -209,7 +211,7 @@
 
 void parse_ray( int& i, int argc, char* argv[] )
 {
-  MBCartVect point, direction;
+  CartVect point, direction;
   if (6 != sscanf( get_option( i, argc, argv ), "%lf:%lf:%lf:%lf:%lf:%lf",
                    &point[0], &point[1], &point[2],
                    &direction[0], &direction[1], &direction[2] ))
@@ -220,24 +222,24 @@
 }
  
 
-class TreeValidator : public MBOrientedBoxTreeTool::Op
+class TreeValidator : public OrientedBoxTreeTool::Op
 {
   private:
-    MBInterface* const instance;
-    MBOrientedBoxTreeTool* const tool;
+    Interface* const instance;
+    OrientedBoxTreeTool* const tool;
     const bool printing;
     const double epsilon;
     bool surfaces;
     std::ostream& stream;
-    MBOrientedBoxTreeTool::Settings settings;
+    OrientedBoxTreeTool::Settings settings;
     
-    void print( MBEntityHandle handle, const char* string ) {
+    void print( EntityHandle handle, const char* string ) {
       if (printing)
         stream << instance->id_from_handle(handle) << ": "
                << string << std::endl;
     }
     
-    MBErrorCode error( MBEntityHandle handle, const char* string ) {
+    ErrorCode error( EntityHandle handle, const char* string ) {
       ++error_count;
       print( handle, string );
       return MB_SUCCESS;
@@ -262,17 +264,17 @@
     unsigned bad_outer_radius_count;
     unsigned missing_surface_count;
     unsigned multiple_surface_count;
-    std::set<MBEntityHandle> seen;
+    std::set<EntityHandle> seen;
     int surface_depth;
-    MBEntityHandle surface_handle;
+    EntityHandle surface_handle;
 
-    TreeValidator( MBInterface* instance_ptr, 
-                   MBOrientedBoxTreeTool* tool_ptr,
+    TreeValidator( Interface* instance_ptr, 
+                   OrientedBoxTreeTool* tool_ptr,
                    bool print_errors,
                    std::ostream& str,
                    double tol,
                    bool surfs,
-                   MBOrientedBoxTreeTool::Settings s )
+                   OrientedBoxTreeTool::Settings s )
       : instance(instance_ptr),
         tool(tool_ptr),
         printing(print_errors), 
@@ -306,22 +308,22 @@
                     +unsorted_axis_count+non_unit_count+duplicate_entity_count
                     +bad_outer_radius_count+missing_surface_count+multiple_surface_count; }
     
-    virtual MBErrorCode visit( MBEntityHandle node,
+    virtual ErrorCode visit( EntityHandle node,
                                int depth,
                                bool& descend );
                                
-    virtual MBErrorCode leaf( MBEntityHandle ) { return MB_SUCCESS; }
+    virtual ErrorCode leaf( EntityHandle ) { return MB_SUCCESS; }
 };
 
 
-MBErrorCode TreeValidator::visit( MBEntityHandle node,
+ErrorCode TreeValidator::visit( EntityHandle node,
                                   int depth,
                                   bool& descend )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   descend = true;
   
-  MBRange contents;
+  Range contents;
   rval = instance->get_entities_by_handle( node, contents );
   if (MB_SUCCESS != rval) 
     return error(node, "Error getting contents of tree node.  Corrupt tree?");
@@ -332,8 +334,8 @@
     if (depth <= surface_depth) 
       surface_depth = -1;
       
-    MBEntityHandle surface = 0;
-    MBRange::iterator surf_iter = contents.lower_bound( MBENTITYSET );
+    EntityHandle surface = 0;
+    Range::iterator surf_iter = contents.lower_bound( MBENTITYSET );
     if (surf_iter != contents.end()) {
       surface = *surf_iter;
       contents.erase( surf_iter );
@@ -351,12 +353,12 @@
     }
   }
   
-  std::vector<MBEntityHandle> children;
+  std::vector<EntityHandle> children;
   rval = tool->get_moab_instance()->get_child_meshsets( node, children );
   if (MB_SUCCESS != rval || (!children.empty() && children.size() != 2)) 
     return error(node, "Error getting children.  Corrupt tree?");
   
-  MBOrientedBox box;
+  OrientedBox box;
   rval = tool->box( node, box );
   if (MB_SUCCESS != rval) 
     return error(node, "Error getting oriented box from tree node.  Corrupt tree?");
@@ -385,7 +387,7 @@
   
   if (!children.empty()) {
     for (int i = 0; i < 2; ++i) {
-      MBOrientedBox other_box;
+      OrientedBox other_box;
       rval = tool->box( children[i], other_box );
       if (MB_SUCCESS != rval) 
         return error( children[i], " Error getting oriented box from tree node.  Corrupt tree?" );
@@ -415,15 +417,15 @@
   bool duplicate_element = false;
   int num_outside = 0;
   bool boundary[6] = { false, false, false, false, false, false };
-  for (MBRange::iterator it = contents.begin(); it != contents.end(); ++it) {
-    MBEntityType type = instance->type_from_handle( *it );
+  for (Range::iterator it = contents.begin(); it != contents.end(); ++it) {
+    EntityType type = instance->type_from_handle( *it );
     int dim = MBCN::Dimension( type );
     if (dim != 2) {
       bad_element = true;
       continue;
     }
     
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int conn_len;
     rval = instance->get_connectivity( *it, conn, conn_len );
     if (MB_SUCCESS != rval) {
@@ -431,7 +433,7 @@
       continue;
     }
     
-    std::vector<MBCartVect> coords(conn_len);
+    std::vector<CartVect> coords(conn_len);
     rval = instance->get_coords( conn, conn_len, coords[0].array() );
     if (MB_SUCCESS != rval) {
       bad_element_conn = true;
@@ -439,7 +441,7 @@
     }
     
     bool outside = false;
-    for (std::vector<MBCartVect>::iterator j = coords.begin(); j != coords.end(); ++j) {
+    for (std::vector<CartVect>::iterator j = coords.begin(); j != coords.end(); ++j) {
       if (!box.contained( *j, epsilon ))
         outside = true;
       else for (int d = 0; d < 3; ++d) {
@@ -451,8 +453,8 @@
           boundary[2*d+1] = true;
 #else
         double ln = box.axis[d].length();
-        MBCartVect v1 = *j - box.center - box.axis[d];
-        MBCartVect v2 = *j - box.center + box.axis[d];
+        CartVect v1 = *j - box.center - box.axis[d];
+        CartVect v2 = *j - box.center + box.axis[d];
         if (fabs(v1 % box.axis[d]) <= ln * epsilon)
           boundary[2*d] = true;
         if (fabs(v2 % box.axis[d]) <= ln * epsilon)
@@ -469,11 +471,11 @@
     }
   }
   
-  MBCartVect alength( box.axis[0].length(), box.axis[1].length(), box.axis[2].length() );
+  CartVect alength( box.axis[0].length(), box.axis[1].length(), box.axis[2].length() );
 #if MB_ORIENTED_BOX_UNIT_VECTORS
-  MBCartVect length = box.length;
+  CartVect length = box.length;
 #else
-  MBCartVect length = alength;
+  CartVect length = alength;
 #endif
   
   if (length[0] > length[1] || length[0] > length[2] || length[1] > length[2]) {
@@ -540,30 +542,30 @@
   return MB_SUCCESS;
 }
 
-class CubitWriter : public MBOrientedBoxTreeTool::Op
+class CubitWriter : public OrientedBoxTreeTool::Op
 {
   public:
     CubitWriter( FILE* file_ptr, 
-                 MBOrientedBoxTreeTool* tool_ptr )
+                 OrientedBoxTreeTool* tool_ptr )
       : file(file_ptr), tool(tool_ptr) {}
     
-    MBErrorCode visit ( MBEntityHandle node,
+    ErrorCode visit ( EntityHandle node,
                         int depth,
                         bool& descend );
-    MBErrorCode leaf( MBEntityHandle ) { return MB_SUCCESS; }
+    ErrorCode leaf( EntityHandle ) { return MB_SUCCESS; }
     
   private:
     FILE* file;
-    MBOrientedBoxTreeTool* tool;
+    OrientedBoxTreeTool* tool;
 };
 
-MBErrorCode CubitWriter::visit( MBEntityHandle node,
+ErrorCode CubitWriter::visit( EntityHandle node,
                                 int ,
                                 bool& descend )
 {
   descend = true;
-  MBOrientedBox box;
-  MBErrorCode rval = tool->box( node, box );
+  OrientedBox box;
+  ErrorCode rval = tool->box( node, box );
   if (rval != MB_SUCCESS)
     return rval;
 
@@ -572,11 +574,11 @@
     for (int j = 0; j < 2; ++j)
       for (int k = 0; k < 2; ++k) {
 #if MB_ORIENTED_BOX_UNIT_VECTORS
-        MBCartVect corner = box.center + box.length[0] * sign[i] * box.axis[0] +
+        CartVect corner = box.center + box.length[0] * sign[i] * box.axis[0] +
                                          box.length[1] * sign[j] * box.axis[1] +
                                          box.length[2] * sign[k] * box.axis[2];
 #else
-        MBCartVect corner = box.center + sign[i] * box.axis[0] +
+        CartVect corner = box.center + sign[i] * box.axis[0] +
                                          sign[j] * box.axis[1] +
                                          sign[k] * box.axis[2];
 #endif
@@ -598,31 +600,31 @@
   return MB_SUCCESS;
 }
 
-class VtkWriter : public MBOrientedBoxTreeTool::Op
+class VtkWriter : public OrientedBoxTreeTool::Op
 {
    public:
     VtkWriter( std::string base_name, 
-               MBInterface* interface )
+               Interface* interface )
       : baseName(base_name), instance(interface) {}
     
-    MBErrorCode visit ( MBEntityHandle node,
+    ErrorCode visit ( EntityHandle node,
                         int depth,
                         bool& descend );
                         
-    MBErrorCode leaf( MBEntityHandle node ) { return MB_SUCCESS; }
+    ErrorCode leaf( EntityHandle node ) { return MB_SUCCESS; }
     
   private:
     std::string baseName;
-    MBInterface* instance;
+    Interface* instance;
 };
 
-MBErrorCode VtkWriter::visit( MBEntityHandle node,
+ErrorCode VtkWriter::visit( EntityHandle node,
                               int ,
                               bool& descend )
 {
   descend = true;
   
-  MBErrorCode rval;
+  ErrorCode rval;
   int count;
   rval = instance->get_number_entities_by_handle( node, count );
   if (MB_SUCCESS != rval || 0 == count)
@@ -641,25 +643,25 @@
 }
 
   
-static bool do_ray_fire_test( MBOrientedBoxTreeTool& tool, 
-                              MBEntityHandle root_set,
+static bool do_ray_fire_test( OrientedBoxTreeTool& tool, 
+                              EntityHandle root_set,
                               const char* filename,
                               bool have_surface_tree );
                               
-static bool do_closest_point_test( MBOrientedBoxTreeTool& tool,
-                                   MBEntityHandle root_set,
+static bool do_closest_point_test( OrientedBoxTreeTool& tool,
+                                   EntityHandle root_set,
                                    bool have_surface_tree );
 
-static MBErrorCode save_tree( MBInterface* instance,
+static ErrorCode save_tree( Interface* instance,
                               const char* filename,
-                              MBEntityHandle tree_root );
+                              EntityHandle tree_root );
   
 static bool do_file( const char* filename )
 {
-  MBErrorCode rval;
-  MBCore instance;
-  MBInterface* const iface = &instance;
-  MBOrientedBoxTreeTool tool( iface );
+  ErrorCode rval;
+  Core instance;
+  Interface* const iface = &instance;
+  OrientedBoxTreeTool tool( iface );
   bool haveSurfTree = false;
   
   if (verbosity) 
@@ -675,9 +677,9 @@
   
     // IF building from surfaces, get surfaces.
     // If AUTO and less than two surfaces, don't build from surfaces.
-  MBRange surfaces;
+  Range surfaces;
   if (surfTree != DISABLE) {
-    MBTag surftag;
+    Tag surftag;
     rval = iface->tag_get_handle( GEOM_DIMENSION_TAG_NAME, surftag );
     if (MB_SUCCESS == rval) {
       int dim = 2;
@@ -698,8 +700,8 @@
     haveSurfTree = (ENABLE == surfTree) || (surfaces.size() > 1);
   }
   
-  MBEntityHandle root;
-  MBRange entities;
+  EntityHandle root;
+  Range entities;
   if (!haveSurfTree) {
     rval = iface->get_entities_by_dimension( 0, 2, entities );
     if (MB_SUCCESS != rval) {
@@ -729,9 +731,9 @@
       std::cout << "Building tree from " << surfaces.size() << " surfaces" << std::endl;
 
       // Build subtree for each surface, get list of all entities to use later
-    MBRange surf_trees, surf_tris;
-    MBEntityHandle surf_root;
-    for (MBRange::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+    Range surf_trees, surf_tris;
+    EntityHandle surf_root;
+    for (Range::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
       surf_tris.clear();
       rval= iface->get_entities_by_dimension( *s, 2, surf_tris );
       if (MB_SUCCESS != rval)
@@ -892,19 +894,19 @@
 struct RayTest {
   const char* description;
   unsigned expected_hits;
-  MBCartVect point, direction;
+  CartVect point, direction;
 };
 
-static bool do_ray_fire_test( MBOrientedBoxTreeTool& tool, 
-                              MBEntityHandle root_set,
+static bool do_ray_fire_test( OrientedBoxTreeTool& tool, 
+                              EntityHandle root_set,
                               const char* filename,
                               bool haveSurfTree )
 {
   if (verbosity > 1)
     std::cout << "beginning ray fire tests" << std::endl;
  
-  MBOrientedBox box;
-  MBErrorCode rval = tool.box( root_set, box );
+  OrientedBox box;
+  ErrorCode rval = tool.box( root_set, box );
   if (MB_SUCCESS != rval) {
     if (verbosity)
       std::cerr << "Error getting box for tree root set" << std::endl;
@@ -921,7 +923,7 @@
    { "skew miss",                 0, box.center + box.dimensions(),          box.dimensions() * box.axis[2] }
    };
   
-  MBOrientedBoxTreeTool::TrvStats stats;
+  OrientedBoxTreeTool::TrvStats stats;
 
   bool result = true;
   const size_t num_test = sizeof(tests)/sizeof(tests[0]);
@@ -934,7 +936,7 @@
     rval = tool.ray_intersect_triangles( intersections, root_set, tolerance, tests[i].point.array(), tests[i].direction.array(), 0, &stats );
     if (MB_SUCCESS != rval) {
       if (verbosity)
-        std::cout << "  Call to MBOrientedBoxTreeTool::ray_intersect_triangles failed." << std::endl;
+        std::cout << "  Call to OrientedBoxTreeTool::ray_intersect_triangles failed." << std::endl;
       result = false;
       continue;
     }
@@ -957,11 +959,11 @@
     
     const int NUM_NON_TOL_INT = 1;
     std::vector<double> intersections2;
-    std::vector<MBEntityHandle> surf_handles, facet_handles;
+    std::vector<EntityHandle> surf_handles, facet_handles;
     rval = tool.ray_intersect_sets( intersections2, surf_handles, facet_handles, root_set, tolerance, NUM_NON_TOL_INT, tests[i].point.array(), tests[i].direction.array(), 0, &stats );
     if (MB_SUCCESS != rval) {
       if (verbosity)
-        std::cout << "  Call to MBOrientedBoxTreeTool::ray_intersect_sets failed." << std::endl;
+        std::cout << "  Call to OrientedBoxTreeTool::ray_intersect_sets failed." << std::endl;
       result = false;
       continue;
     }
@@ -1028,7 +1030,7 @@
     std::cout << rays[i] << "+" << rays[i+1] << " : ";
     
     if (!haveSurfTree) {
-      MBRange leaves;
+      Range leaves;
       std::vector<double> intersections;
       rval = tool.ray_intersect_boxes( leaves, root_set, tolerance, rays[i].array(), rays[i+1].array(), 0, &stats );
       if (MB_SUCCESS != rval) {
@@ -1046,7 +1048,7 @@
         name += num;
         name += ".vtk";
 
-        std::vector<MBEntityHandle> sets(leaves.size());
+        std::vector<EntityHandle> sets(leaves.size());
         std::copy( leaves.begin(), leaves.end(), sets.begin() );
         tool.get_moab_instance()->write_mesh( name.c_str(), &sets[0], sets.size() );
         if (verbosity)
@@ -1072,14 +1074,14 @@
 
       if (!leaves.empty() && write_cubit && verbosity > 2) {
         std::cout << "  intersected boxes:";
-        for (MBRange::iterator i= leaves.begin(); i!= leaves.end(); ++i)
+        for (Range::iterator i= leaves.begin(); i!= leaves.end(); ++i)
           std::cout << " " << tool.get_moab_instance()->id_from_handle(*i);
         std::cout << std::endl;
       }
     }
     else {
       std::vector<double> intersections;
-      std::vector<MBEntityHandle> surfaces, facets;
+      std::vector<EntityHandle> surfaces, facets;
       rval = tool.ray_intersect_sets( intersections, surfaces, facets, root_set, tolerance, 1000, rays[i].array(), rays[i+1].array(), 0, &stats );
       if (MB_SUCCESS != rval) {
         std::cout << "FAILED" << std::endl;
@@ -1113,7 +1115,7 @@
       }
       
       
-      MBTag idtag;
+      Tag idtag;
       rval = tool.get_moab_instance()->tag_get_handle( GLOBAL_ID_TAG_NAME, idtag );
       if (MB_SUCCESS != rval) {
         std::cout << "NO GLOBAL_ID TAG." << std::endl;
@@ -1155,17 +1157,17 @@
 }
 
 
-MBErrorCode save_tree( MBInterface* instance,
+ErrorCode save_tree( Interface* instance,
                        const char* filename,
-                       MBEntityHandle tree_root )
+                       EntityHandle tree_root )
 {
-  MBErrorCode rval;
-  MBTag tag;
+  ErrorCode rval;
+  Tag tag;
   
   rval = instance->tag_get_handle( "OBB_ROOT", tag );
   if (MB_SUCCESS == rval) {
     int size;
-    MBDataType type;
+    DataType type;
     rval = instance->tag_get_size( tag, size );
     if (MB_SUCCESS != rval)
       return rval;
@@ -1173,11 +1175,11 @@
     if (MB_SUCCESS != rval)
       return rval;
 
-    if (size != sizeof(MBEntityHandle) || type != MB_TYPE_HANDLE)
+    if (size != sizeof(EntityHandle) || type != MB_TYPE_HANDLE)
       return MB_FAILURE;
   }
   else {
-    rval = instance->tag_create( "OBB_ROOT", sizeof(MBEntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tag, 0 );
+    rval = instance->tag_create( "OBB_ROOT", sizeof(EntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tag, 0 );
     if (MB_SUCCESS != rval)
       return rval;
   }
@@ -1189,12 +1191,12 @@
   return instance->write_mesh( filename );
 }
 
-static MBErrorCode tri_coords( MBInterface* moab,
-                               MBEntityHandle tri,
-                               MBCartVect coords[3] )
+static ErrorCode tri_coords( Interface* moab,
+                               EntityHandle tri,
+                               CartVect coords[3] )
 {
-  MBErrorCode rval;
-  const MBEntityHandle* conn;
+  ErrorCode rval;
+  const EntityHandle* conn;
   int len;
   
   rval = moab->get_connectivity( tri, conn, len, true );
@@ -1204,14 +1206,14 @@
   return rval;
 }
 
-static MBErrorCode closest_point_in_triangles( MBInterface* moab,
-                                        const MBCartVect& to_pos,
-                                        MBCartVect& result_pos,
-                                        MBEntityHandle& result_tri )
+static ErrorCode closest_point_in_triangles( Interface* moab,
+                                        const CartVect& to_pos,
+                                        CartVect& result_pos,
+                                        EntityHandle& result_tri )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
-  MBRange triangles;
+  Range triangles;
   rval = moab->get_entities_by_type( 0, MBTRI, triangles );
   if (MB_SUCCESS != rval)
     return rval;
@@ -1219,20 +1221,20 @@
   if (triangles.empty())
     return MB_FAILURE;
   
-  MBRange::iterator i = triangles.begin();
-  MBCartVect coords[3];
+  Range::iterator i = triangles.begin();
+  CartVect coords[3];
   rval = tri_coords( moab, *i, coords );
   if (MB_SUCCESS != rval) return rval;
   result_tri = *i;
-  MBGeomUtil::closest_location_on_tri( to_pos, coords, result_pos );
-  MBCartVect diff = to_pos - result_pos;
+  GeomUtil::closest_location_on_tri( to_pos, coords, result_pos );
+  CartVect diff = to_pos - result_pos;
   double shortest_dist_sqr = diff % diff;
   
   for (++i; i != triangles.end(); ++i) {
     rval = tri_coords( moab, *i, coords );
     if (MB_SUCCESS != rval) return rval;
-    MBCartVect pos;
-    MBGeomUtil::closest_location_on_tri( to_pos, coords, pos );
+    CartVect pos;
+    GeomUtil::closest_location_on_tri( to_pos, coords, pos );
     diff = to_pos - pos;
     double dsqr = diff % diff;
     if (dsqr < shortest_dist_sqr) {
@@ -1245,48 +1247,48 @@
   return MB_SUCCESS;
 }
   
-static bool tri_in_set( MBInterface* moab,
-                        MBEntityHandle set,
-                        MBEntityHandle tri )
+static bool tri_in_set( Interface* moab,
+                        EntityHandle set,
+                        EntityHandle tri )
 {
-  MBRange tris;
-  MBErrorCode rval = moab->get_entities_by_type( set, MBTRI, tris );
+  Range tris;
+  ErrorCode rval = moab->get_entities_by_type( set, MBTRI, tris );
   if (MB_SUCCESS != rval) return false;
-  MBRange::iterator i = tris.find( tri );
+  Range::iterator i = tris.find( tri );
   return i != tris.end();
 }
 
-static bool do_closest_point_test( MBOrientedBoxTreeTool& tool,
-                                   MBEntityHandle root_set,
+static bool do_closest_point_test( OrientedBoxTreeTool& tool,
+                                   EntityHandle root_set,
                                    bool have_surface_tree )
 {
   if (verbosity > 1)
     std::cout << "beginning closest point tests" << std::endl;
 
-  MBErrorCode rval;
-  MBInterface* moab = tool.get_moab_instance();
-  MBEntityHandle set;
-  MBEntityHandle* set_ptr = have_surface_tree ? &set : 0;
+  ErrorCode rval;
+  Interface* moab = tool.get_moab_instance();
+  EntityHandle set;
+  EntityHandle* set_ptr = have_surface_tree ? &set : 0;
   bool result = true;
   
     // get root box
-  MBOrientedBox box;
+  OrientedBox box;
   rval = tool.box( root_set, box );
   if (MB_SUCCESS != rval) {
     if (verbosity) std::cerr << "Invalid tree in do_closest_point_test\n";
     return false;
   }
 
-  MBOrientedBoxTreeTool::TrvStats stats;
+  OrientedBoxTreeTool::TrvStats stats;
   
     // chose some points to test
-  MBCartVect points[] = { box.center + box.scaled_axis(0),
+  CartVect points[] = { box.center + box.scaled_axis(0),
                           box.center + 2 * box.scaled_axis(1),
                           box.center + 0.5 * box.scaled_axis(2),
                           box.center + -2*box.scaled_axis(0)
                                      + -2*box.scaled_axis(1)
                                      + -2*box.scaled_axis(2),
-                          MBCartVect(100,100,100) };
+                          CartVect(100,100,100) };
   const int num_pts = sizeof(points)/sizeof(points[0]);
   
     // test each point
@@ -1294,8 +1296,8 @@
     if (verbosity >= 3) 
       std::cout << "Evaluating closest point to " << points[i] << std::endl;
     
-    MBCartVect n_result, t_result;
-    MBEntityHandle n_tri = 0, t_tri;
+    CartVect n_result, t_result;
+    EntityHandle n_tri = 0, t_tri;
     
       // find closest point the slow way
     rval = closest_point_in_triangles( moab, points[i], n_result, n_tri );
@@ -1314,12 +1316,12 @@
                                      &stats );
     if (MB_SUCCESS != rval) {
       if (verbosity)
-        std::cout << "MBOrientedBoxTreeTool:: closest_to_location( " << points[i] << " ) FAILED!" << std::endl;
+        std::cout << "OrientedBoxTreeTool:: closest_to_location( " << points[i] << " ) FAILED!" << std::endl;
       result = false;
       continue;
     }
     
-    MBCartVect diff = t_result - n_result;
+    CartVect diff = t_result - n_result;
     if ( diff.length() > tolerance ) {
       if (verbosity)
         std::cout << "Closest point to " << points[i] << " INCORRECT! (" 
@@ -1333,11 +1335,11 @@
         // already tested that it is the same location 
         // as the expected value.  We just have a case where
         // the point was on an edge or vertex.
-      MBCartVect coords[3];
-      MBCartVect diff(1,1,1);
+      CartVect coords[3];
+      CartVect diff(1,1,1);
       rval = tri_coords( moab, t_tri, coords );
       if (MB_SUCCESS == rval) {
-        MBGeomUtil::closest_location_on_tri( points[i], coords, n_result );
+        GeomUtil::closest_location_on_tri( points[i], coords, n_result );
         diff = n_result - t_result;
       }
       if ((diff % diff) > tolerance) {
@@ -1366,14 +1368,14 @@
 }
 
 #define IS_BUILDING_MB
-#include "MBInternals.hpp"
+#include "Internals.hpp"
     
-void print_mb_range( const MBRange& range )
+void print_mb_range( const Range& range )
 {
-  MBRange::const_pair_iterator i = range.const_pair_begin();
+  Range::const_pair_iterator i = range.const_pair_begin();
   for (; i != range.const_pair_end(); ++i) {
-    MBEntityType type1 = TYPE_FROM_HANDLE( i->first );
-    MBEntityType type2 = TYPE_FROM_HANDLE( i->second );
+    EntityType type1 = TYPE_FROM_HANDLE( i->first );
+    EntityType type2 = TYPE_FROM_HANDLE( i->second );
     int id1 = ID_FROM_HANDLE( i->first );
     int id2 = ID_FROM_HANDLE( i->second );
     std::cout << MBCN::EntityTypeName( type1 ) << " " << id1;

Modified: MOAB/trunk/test/obb/obb_time.cpp
===================================================================
--- MOAB/trunk/test/obb/obb_time.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/obb/obb_time.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
-#include "MBCore.hpp"
-#include "MBCartVect.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
+#include "moab/Core.hpp"
+#include "moab/CartVect.hpp"
+#include "OrientedBox.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
 #include <stdlib.h>
 #include <iostream>
 #include <cmath>
@@ -12,6 +12,8 @@
 const int NUM_RAYS = 40000;
 const int NUM_XSCT = 20000;
 
+using namespace moab;
+
 static void usage( )
 {
   std::cerr << "obb_time [-r <int>] [-i <int>] <filename>" << std::endl
@@ -26,10 +28,10 @@
   exit(1);
 }
 
-void generate_ray( const MBCartVect& sphere_center,
+void generate_ray( const CartVect& sphere_center,
                    double sphere_radius,
-                   MBCartVect& point,
-                   MBCartVect& dir )
+                   CartVect& point,
+                   CartVect& dir )
 {
   const int H = RAND_MAX/2;
   point[0] = (double)rand()/H - 1;
@@ -45,21 +47,21 @@
   point += sphere_center;
 }
 
-MBErrorCode read_tree( MBInterface* instance,
+ErrorCode read_tree( Interface* instance,
                        const char* filename,
-                       MBEntityHandle& tree_root_out )
+                       EntityHandle& tree_root_out )
 {
-  MBErrorCode rval = instance->load_mesh( filename );
+  ErrorCode rval = instance->load_mesh( filename );
   if (MB_SUCCESS != rval)
     return rval;
   
-  MBTag tag;
+  Tag tag;
   rval = instance->tag_get_handle( "OBB_ROOT", tag );
   if (MB_SUCCESS != rval)
     return rval;
   
   int size;
-  MBDataType type;
+  DataType type;
   rval = instance->tag_get_size( tag, size );
   if (MB_SUCCESS != rval)
     return rval;
@@ -67,7 +69,7 @@
   if (MB_SUCCESS != rval)
     return rval;
 
-  if (size != sizeof(MBEntityHandle) || type != MB_TYPE_HANDLE)
+  if (size != sizeof(EntityHandle) || type != MB_TYPE_HANDLE)
     return MB_FAILURE;
   
   return instance->tag_get_data( tag, 0, 0, &tree_root_out );
@@ -149,33 +151,33 @@
     usage();
   }
     
-  MBCore instance;
-  MBInterface* iface = &instance;
-  MBEntityHandle root;
-  MBErrorCode rval = read_tree( iface, filename, root );
+  Core instance;
+  Interface* iface = &instance;
+  EntityHandle root;
+  ErrorCode rval = read_tree( iface, filename, root );
   if (MB_SUCCESS != rval) {
     std::cerr << "Failed to read \"" <<filename<<'"'<<std::endl;
     return 2;
   }
   
-  MBOrientedBoxTreeTool tool(iface);
-  MBOrientedBox box;
+  OrientedBoxTreeTool tool(iface);
+  OrientedBox box;
   rval = tool.box( root, box );
   if (MB_SUCCESS != rval) {
     std::cerr << "Corrupt tree.  Cannot get box for root node." << std::endl;
     return 3;
   }
 
-  MBOrientedBoxTreeTool::TrvStats* stats = NULL;
+  OrientedBoxTreeTool::TrvStats* stats = NULL;
   if( do_trv_stats ){
-    stats = new MBOrientedBoxTreeTool::TrvStats;
+    stats = new OrientedBoxTreeTool::TrvStats;
   }
   
   const unsigned cached = 1000;
   std::vector<double> intersections;
-  std::vector<MBEntityHandle> sets, facets;
-  MBCartVect point, dir;
-  std::vector<MBCartVect> randrays;
+  std::vector<EntityHandle> sets, facets;
+  CartVect point, dir;
+  std::vector<CartVect> randrays;
   randrays.reserve( cached );
   int cached_idx = 0;
   
@@ -193,7 +195,7 @@
       break;
     
     ++rays;
-    MBCartVect point, dir;
+    CartVect point, dir;
     if (randrays.size() < cached) {
       generate_ray( box.center, box.outer_radius(), point, dir );
       ++gen;

Modified: MOAB/trunk/test/obb/obb_tree_tool.cpp
===================================================================
--- MOAB/trunk/test/obb/obb_tree_tool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/obb/obb_tree_tool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
 #define IS_BUILDING_MB
-#include "MBCore.hpp"
-#include "MBCartVect.hpp"
-#include "MBOrientedBoxTreeTool.hpp"
-#include "MBOrientedBox.hpp"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
+#include "OrientedBox.hpp"
+#include "Internals.hpp"
+#include "moab/Range.hpp"
 
 #include <iostream>
 #include <iomanip>
@@ -18,6 +18,8 @@
 #  include <fcntl.h>
 #endif
 
+using namespace moab;
+
 std::string clock_to_string( clock_t t );
 std::string mem_to_string( unsigned long mem );
 
@@ -26,14 +28,14 @@
 const char* const TREE_TAG = "OBB_ROOT";
 const char* root_tag = TREE_TAG;
 
-MBErrorCode get_root( MBInterface* moab, MBEntityHandle& root );
-MBEntityHandle build_tree( MBInterface* interface, 
-                           MBOrientedBoxTreeTool::Settings settings );
-void delete_existing_tree( MBInterface* interface );
-void print_stats( MBInterface* interface );
-void tag_triangles( MBInterface* interface );
-void tag_vertices( MBInterface* interface );
-void write_tree_blocks( MBInterface* interface, const char* file );
+ErrorCode get_root( Interface* moab, EntityHandle& root );
+EntityHandle build_tree( Interface* interface, 
+                           OrientedBoxTreeTool::Settings settings );
+void delete_existing_tree( Interface* interface );
+void print_stats( Interface* interface );
+void tag_triangles( Interface* interface );
+void tag_vertices( Interface* interface );
+void write_tree_blocks( Interface* interface, const char* file );
 
 static void usage( bool err = true )
 {
@@ -41,7 +43,7 @@
   s << "obb_tree_tool [-s|-S] [-d <int>] [-n <int>] <input file> <output file>" << std::endl
     << "obb_tree_tool [-h]" << std::endl;
   if (!err) {
-    MBOrientedBoxTreeTool::Settings st;
+    OrientedBoxTreeTool::Settings st;
     s << "Tool to build adaptive kd-Tree from triangles" << std::endl;
     s << "  -s        Use range-based sets for tree nodes" << std::endl
       << "  -S        Use vector-based sets for tree nodes" << std::endl
@@ -125,7 +127,7 @@
   const char* input_file = 0;
   const char* output_file = 0;
   const char* tree_file = 0;
-  MBOrientedBoxTreeTool::Settings settings;
+  OrientedBoxTreeTool::Settings settings;
   bool tag_tris = false;
   clock_t load_time, build_time, stat_time, tag_time, write_time, block_time;
   
@@ -161,9 +163,9 @@
   if (!output_file)
     usage();
   
-  MBErrorCode rval;
-  MBCore moab_core;
-  MBInterface* interface = &moab_core;
+  ErrorCode rval;
+  Core moab_core;
+  Interface* interface = &moab_core;
   
   load_time = clock();
   rval = interface->load_mesh( input_file );
@@ -234,10 +236,10 @@
   return 0;
 }
 
-MBErrorCode get_root( MBInterface* moab, MBEntityHandle& root )
+ErrorCode get_root( Interface* moab, EntityHandle& root )
 {
-  MBTag tag;
-  MBErrorCode rval;
+  Tag tag;
+  ErrorCode rval;
 
   rval = moab->tag_get_handle( root_tag, tag );
   if (MB_SUCCESS != rval)
@@ -247,10 +249,10 @@
   rval = moab->tag_get_size( tag, size );
   if (MB_SUCCESS != rval)
     return rval;
-  if (size != sizeof(MBEntityHandle))
+  if (size != sizeof(EntityHandle))
     return MB_TAG_NOT_FOUND;
   
-  MBDataType type;
+  DataType type;
   rval = moab->tag_get_data_type( tag, type );
   if (MB_SUCCESS != rval)
     return rval;
@@ -261,12 +263,12 @@
 }
 
   
-void delete_existing_tree( MBInterface* interface )
+void delete_existing_tree( Interface* interface )
 {
-  MBEntityHandle root;
-  MBErrorCode rval = get_root(interface, root);
+  EntityHandle root;
+  ErrorCode rval = get_root(interface, root);
   if (MB_SUCCESS == rval) {
-    MBOrientedBoxTreeTool tool(interface);
+    OrientedBoxTreeTool tool(interface);
     rval = tool.delete_tree( root );
     if (MB_SUCCESS != rval) {
       std::cerr << "Failed to destroy existing trees. Aborting" << std::endl;
@@ -275,11 +277,11 @@
   }
 }
   
-MBEntityHandle build_tree( MBInterface* interface, MBOrientedBoxTreeTool::Settings settings )
+EntityHandle build_tree( Interface* interface, OrientedBoxTreeTool::Settings settings )
 {
-  MBErrorCode rval;
-  MBEntityHandle root = 0;
-  MBRange triangles;
+  ErrorCode rval;
+  EntityHandle root = 0;
+  Range triangles;
   
   rval = interface->get_entities_by_type( 0, MBTRI, triangles );
   if (MB_SUCCESS != rval || triangles.empty()) {
@@ -287,7 +289,7 @@
     exit(4);
   }
   
-  MBOrientedBoxTreeTool tool( interface );
+  OrientedBoxTreeTool tool( interface );
   rval = tool.build( triangles, root, &settings );
   if (MB_SUCCESS != rval || !root) {
     std::cerr << "Tree construction failed." << std::endl;
@@ -295,8 +297,8 @@
   }
   
     // store tree root
-  MBTag roottag;
-  rval = interface->tag_create( root_tag, sizeof(MBEntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, roottag, 0, true );
+  Tag roottag;
+  rval = interface->tag_create( root_tag, sizeof(EntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, roottag, 0, true );
   if (MB_SUCCESS != rval) {
     std::cout << "Failed to create root tag: \"" << root_tag << '"' << std::endl;
     exit(2);
@@ -369,17 +371,17 @@
     sum( 0 ), sqr( 0 ), count( 0 )
   {}
 
-void print_stats( MBInterface* interface )
+void print_stats( Interface* interface )
 {
-  MBEntityHandle root;
-  MBRange range;
+  EntityHandle root;
+  Range range;
   get_root( interface, root );
-  MBOrientedBoxTreeTool tool(interface);
+  OrientedBoxTreeTool tool(interface);
 
-  MBRange tree_sets, triangles, verts;
+  Range tree_sets, triangles, verts;
   //interface->get_child_meshsets( root, tree_sets, 0 );
   interface->get_entities_by_type( 0, MBENTITYSET, tree_sets );
-  tree_sets.erase( tree_sets.begin(), MBRange::lower_bound( tree_sets.begin(), tree_sets.end(), root ) );
+  tree_sets.erase( tree_sets.begin(), Range::lower_bound( tree_sets.begin(), tree_sets.end(), root ) );
   interface->get_entities_by_type( 0, MBTRI, triangles );
   interface->get_entities_by_type( 0, MBVERTEX, verts );
   triangles.merge( verts );
@@ -413,27 +415,27 @@
 }
 
 
-static int hash_handle( MBEntityHandle handle )
+static int hash_handle( EntityHandle handle )
 {
-  MBEntityID h = ID_FROM_HANDLE(handle);
+  EntityID h = ID_FROM_HANDLE(handle);
   return (int)((h * 13 + 7) % MAX_TAG_VALUE) + 1;
 }   
 
-class TriTagger : public MBOrientedBoxTreeTool::Op
+class TriTagger : public OrientedBoxTreeTool::Op
 {
 private:
-  MBInterface* mMB;
-  MBTag mTag;
-  std::vector<MBEntityHandle> mHandles;
+  Interface* mMB;
+  Tag mTag;
+  std::vector<EntityHandle> mHandles;
   std::vector<int> mTagData;
 public:
-  TriTagger( MBTag tag, MBInterface* moab )
+  TriTagger( Tag tag, Interface* moab )
     : mMB(moab), mTag(tag) {}
 
-  MBErrorCode visit( MBEntityHandle, int, bool& descent )
+  ErrorCode visit( EntityHandle, int, bool& descent )
     { descent = true; return MB_SUCCESS; }
   
-  MBErrorCode leaf( MBEntityHandle node ) {
+  ErrorCode leaf( EntityHandle node ) {
     mHandles.clear();
     mMB->get_entities_by_handle( node, mHandles );
     mTagData.clear();
@@ -444,21 +446,21 @@
 };
     
 
-void tag_triangles( MBInterface* moab )
+void tag_triangles( Interface* moab )
 {
-  MBEntityHandle root;
-  MBErrorCode rval = get_root( moab, root );
+  EntityHandle root;
+  ErrorCode rval = get_root( moab, root );
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error: Failed to retreive tree." << std::endl;
     exit(5);
   }
 
-  MBTag tag;
+  Tag tag;
   int zero = 0;
   moab->tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
   TriTagger op( tag, moab );
   
-  MBOrientedBoxTreeTool tool(moab);
+  OrientedBoxTreeTool tool(moab);
   rval = tool.preorder_traverse( root, op );
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error tagging triangles" << std::endl;
@@ -467,22 +469,22 @@
 }
 
 
-class VtxTagger : public MBOrientedBoxTreeTool::Op
+class VtxTagger : public OrientedBoxTreeTool::Op
 {
 private:
-  MBInterface* mMB;
-  MBTag mTag;
-  std::vector<MBEntityHandle> mHandles;
-  std::vector<MBEntityHandle> mConn;
+  Interface* mMB;
+  Tag mTag;
+  std::vector<EntityHandle> mHandles;
+  std::vector<EntityHandle> mConn;
   std::vector<int> mTagData;
 public:
-  VtxTagger( MBTag tag, MBInterface* moab )
+  VtxTagger( Tag tag, Interface* moab )
     : mMB(moab), mTag(tag) {}
 
-  MBErrorCode visit( MBEntityHandle, int, bool& descent )
+  ErrorCode visit( EntityHandle, int, bool& descent )
     { descent = true; return MB_SUCCESS; }
   
-  MBErrorCode leaf( MBEntityHandle node ) {
+  ErrorCode leaf( EntityHandle node ) {
     mHandles.clear();
     mMB->get_entities_by_handle( node, mHandles );
     mConn.clear();
@@ -495,21 +497,21 @@
 };
     
 
-void tag_vertices( MBInterface* moab )
+void tag_vertices( Interface* moab )
 {
-  MBEntityHandle root;
-  MBErrorCode rval = get_root( moab, root );
+  EntityHandle root;
+  ErrorCode rval = get_root( moab, root );
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error: Failed to retreive tree." << std::endl;
     exit(5);
   }
 
-  MBTag tag;
+  Tag tag;
   int zero = 0;
   moab->tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
   VtxTagger op( tag, moab );
   
-  MBOrientedBoxTreeTool tool(moab);
+  OrientedBoxTreeTool tool(moab);
   rval = tool.preorder_traverse( root, op );
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error tagging vertices" << std::endl;
@@ -518,26 +520,26 @@
 }
 
 
-class LeafHexer : public MBOrientedBoxTreeTool::Op
+class LeafHexer : public OrientedBoxTreeTool::Op
 {
 private:
-  MBOrientedBoxTreeTool* mTool;
-  MBInterface* mOut;
-  MBTag mTag;
-  std::vector<MBEntityHandle> mHandles;
-  std::vector<MBEntityHandle> mConn;
+  OrientedBoxTreeTool* mTool;
+  Interface* mOut;
+  Tag mTag;
+  std::vector<EntityHandle> mHandles;
+  std::vector<EntityHandle> mConn;
   std::vector<int> mTagData;
 public:
-  LeafHexer( MBOrientedBoxTreeTool* tool, MBInterface* mb2, MBTag tag )
+  LeafHexer( OrientedBoxTreeTool* tool, Interface* mb2, Tag tag )
     : mTool(tool), mOut( mb2 ), mTag(tag) {}
 
-  MBErrorCode visit( MBEntityHandle, int, bool& descent )
+  ErrorCode visit( EntityHandle, int, bool& descent )
     { descent = true; return MB_SUCCESS; }
   
-  MBErrorCode leaf( MBEntityHandle node ) {
-    MBOrientedBox box;
-    MBErrorCode rval = mTool->box( node, box );
-    MBEntityHandle h;
+  ErrorCode leaf( EntityHandle node ) {
+    OrientedBox box;
+    ErrorCode rval = mTool->box( node, box );
+    EntityHandle h;
     rval = box.make_hex( h, mOut );
     if (MB_SUCCESS !=rval) return rval;
     int i = hash_handle( node );
@@ -545,21 +547,21 @@
   }
 };
 
-void write_tree_blocks( MBInterface* interface, const char* file )
+void write_tree_blocks( Interface* interface, const char* file )
 {
-  MBEntityHandle root;
-  MBErrorCode rval = get_root( interface, root );
+  EntityHandle root;
+  ErrorCode rval = get_root( interface, root );
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error: Failed to retreive tree." << std::endl;
     exit(5);
   }
   
-  MBCore moab2;
-  MBTag tag;
+  Core moab2;
+  Tag tag;
   int zero = 0;
   moab2.tag_create( TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &zero, true );
 
-  MBOrientedBoxTreeTool tool(interface);
+  OrientedBoxTreeTool tool(interface);
   LeafHexer op( &tool, &moab2, tag );
   rval = tool.preorder_traverse( root, op );
   if (MB_SUCCESS != rval) {

Added: MOAB/trunk/test/oldinc/Makefile.am
===================================================================
--- MOAB/trunk/test/oldinc/Makefile.am	                        (rev 0)
+++ MOAB/trunk/test/oldinc/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,9 @@
+AM_CPPFLAGS += -I$(top_srcdir)/src \
+               -I$(top_srcdir)/src/parallel \
+               -I$(top_srcdir)/src/oldinc \
+               -I$(top_builddir)/src \
+               -I$(top_builddir)/src/parallel
+LDADD = $(top_builddir)/src/libMOAB.la
+check_PROGRAMS = test_oldinc
+test_oldinc_SOURCES = test_oldinc.cpp
+

Added: MOAB/trunk/test/oldinc/test_oldinc.cpp
===================================================================
--- MOAB/trunk/test/oldinc/test_oldinc.cpp	                        (rev 0)
+++ MOAB/trunk/test/oldinc/test_oldinc.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,89 @@
+  // test forrwards
+#include "MBForward.hpp"  
+typedef MBRange Foo1;
+typedef MBInterface Foo2;
+typedef MBProcConfig Foo3;
+
+  // test types
+#include "MBEntityHandle.h"
+MBEntityHandle handle = 0;
+#include "MBTypes.h"
+MBEntityType type = MBVERTEX;
+MBTag tag = 0;
+MBErrorCode code = MB_SUCCESS;
+int i = MB_VARIABLE_LENGTH;
+MBTagType tagtype = MB_TAG_DENSE;
+MBDataType datatype = MB_TYPE_HANDLE;
+MBEntitySetProperty prop = MESHSET_SET;
+
+  // test version info
+#include "MBVersion.h"
+
+#ifndef MB_VERSION
+# error "MB_VERSION not defined"
+#endif
+
+#ifndef MB_VERSION_MAJOR
+# error "MB_VERSION_MAJOR not defined"
+#endif
+
+#ifndef MB_VERSION_MINOR
+# error "MB_VERSION_MINOR not defined"
+#endif
+
+#ifndef MB_VERSION_STRING
+# error "MB_VERSION_STRING not defined"
+#endif
+
+#include "MBUnknownInterface.hpp"
+#include "MBInterface.hpp"
+#include "MBRange.hpp"
+#include "MBUtil.hpp"
+
+#ifdef USE_MPI
+#  include "MBmpi.h"
+#  include "MBParallelData.hpp"
+#  include "MBParallelComm.hpp"
+#  include "MBProcConfig.hpp"
+#endif
+
+#include "MBCore.hpp"
+#include "MBReaderIface.hpp"
+#include "MBWriterIface.hpp"
+#include "MBReadUtilIface.hpp"
+#include "MBWriteUtilIface.hpp"
+#include "MBReaderWriterSet.hpp"
+
+#include "MBGeomUtil.hpp"
+#include "MBAdaptiveKDTree.hpp"
+#include "MBBSPTree.hpp"
+#include "MBOrientedBoxTreeTool.hpp"
+#include "MBSkinner.hpp"
+
+int main()
+{
+    // check that the expected types are defined
+  MBCore mb_core;
+  MBInterface& mb = mb_core;
+  MBRange range;
+  MBReaderIface* read_ptr;
+  MBWriterIface* write_ptr;
+  MBReadUtilIface* read_util;
+  MBWriteUtilIface* write_util;
+  MBReaderWriterSet* io_set_ptr;
+  
+  MBAdaptiveKDTree kdtree_tool(&mb);
+  MBBSPTree bsptree_tool(&mb);
+  MBOrientedBoxTreeTool obbtree_tool(&mb);
+  MBSkinner skin_tool(&mb);
+
+#ifdef WITH_MPI
+  MBParallelComm* pcomm_ptr;
+  MBProcConfig* pconf_ptr;
+#endif
+
+  return 0;
+}
+
+  
+  

Modified: MOAB/trunk/test/parallel/Makefile.am
===================================================================
--- MOAB/trunk/test/parallel/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,10 +5,7 @@
                -I.. -I$(srcdir)/.. \
                -I$(top_builddir)/src \
                -I$(top_srcdir)/src \
-               -I$(top_srcdir)/src/parallel \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_srcdir)/src/parallel/moab
+               -I$(top_srcdir)/src/parallel 
 
 # Run parallel tests in parallel
 if USE_MPIEXEC

Modified: MOAB/trunk/test/parallel/mbparallelcomm_test.cpp
===================================================================
--- MOAB/trunk/test/parallel/mbparallelcomm_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/mbparallelcomm_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,4 +1,4 @@
-/** test of MBParallelComm functionality
+/** test of ParallelComm functionality
  *
  * To run:
  *
@@ -6,17 +6,17 @@
  *
  */
 
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
 #include "ReadParallel.hpp"
 #include "FileOptions.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
 #include "ScdVertexData.hpp"
 #include "StructuredElementSeq.hpp"
 #include "SequenceManager.hpp"
-#include "MBError.hpp"
-#include "MBmpi.h"
+#include "Error.hpp"
+#include "moab_mpi.h"
 #include <iostream>
 #include <sstream>
 #include <assert.h>
@@ -25,6 +25,8 @@
 
 const bool debug = false;
 
+using namespace moab;
+
 #define ERROR(a, b) {std::cerr << a << std::endl; return b;}
 
 #define PRINT_LAST_ERROR {\
@@ -36,26 +38,26 @@
 #define RRA(a) if (MB_SUCCESS != result) {\
       std::string tmp_str; mbImpl->get_last_error(tmp_str);\
       tmp_str.append("\n"); tmp_str.append(a);\
-      dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(tmp_str); \
+      dynamic_cast<Core*>(mbImpl)->get_error_handler()->set_last_error(tmp_str); \
       return result;}
 
-MBErrorCode create_linear_mesh(MBInterface *mbImpl,
+ErrorCode create_linear_mesh(Interface *mbImpl,
                                int N, int M, int &nshared);
 
-MBErrorCode create_scd_mesh(MBInterface *mbImpl,
+ErrorCode create_scd_mesh(Interface *mbImpl,
                             int IJK, int &nshared);
 
-MBErrorCode read_file(MBInterface *mbImpl, std::vector<std::string> &filenames,
+ErrorCode read_file(Interface *mbImpl, std::vector<std::string> &filenames,
                       const char *tag_name, int tag_val, int distrib,
                       int parallel_option, int resolve_shared, int with_ghosts, 
                       int use_mpio, bool print_parallel);
 
-MBErrorCode test_packing(MBInterface *mbImpl, const char *filename);
+ErrorCode test_packing(Interface *mbImpl, const char *filename);
 
-MBErrorCode report_nsets(MBInterface *mbImpl);
+ErrorCode report_nsets(Interface *mbImpl);
 
-MBErrorCode report_iface_ents(MBInterface *mbImpl,
-                              std::vector<MBParallelComm *> &pcs);
+ErrorCode report_iface_ents(Interface *mbImpl,
+                              std::vector<ParallelComm *> &pcs);
 
 void print_usage(const char *);
 
@@ -73,10 +75,10 @@
   if (0 == rank) stime = MPI_Wtime();
 
     // create MOAB instance based on that
-  MBInterface *mbImpl = new MBCore;
+  Interface *mbImpl = new Core;
   if (NULL == mbImpl) return 1;
   
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
 
     // each interior proc has a vector of N+M vertices, sharing
     // M vertices each with lower- and upper-rank processors, except
@@ -100,7 +102,7 @@
   if (!strcmp(argv[npos], "-p")) print_parallel = true;
 
   while (npos != argc) {    
-    MBErrorCode tmp_result;
+    ErrorCode tmp_result;
     int nshared = -1;
     int this_opt = strtol(argv[npos++], NULL, 0);
     switch (this_opt) {
@@ -227,16 +229,16 @@
       << "*Note: if opt 3 is used, it must be the last one." << std::endl;
 }
 
-MBErrorCode report_nsets(MBInterface *mbImpl) 
+ErrorCode report_nsets(Interface *mbImpl) 
 {
     // get and report various numbers...
   int rank;
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   
-  MBRange matsets, geomsets, parsets;
+  Range matsets, geomsets, parsets;
   int nsets;
-  MBTag mtag = 0, gtag = 0, ptag = 0, gidtag;
-  MBErrorCode result = mbImpl->tag_get_handle("MATERIAL_SET", mtag);
+  Tag mtag = 0, gtag = 0, ptag = 0, gidtag;
+  ErrorCode result = mbImpl->tag_get_handle("MATERIAL_SET", mtag);
   result = mbImpl->tag_get_handle("GEOM_DIMENSION", gtag);
   result = mbImpl->tag_get_handle("PARALLEL_PARTITION", ptag);
   result = mbImpl->tag_get_handle("GLOBAL_ID", gidtag);
@@ -293,7 +295,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode read_file(MBInterface *mbImpl, 
+ErrorCode read_file(Interface *mbImpl, 
                       std::vector<std::string> &filenames,
                       const char *tag_name, int tag_val,
                       int distrib, int parallel_option, int resolve_shared,
@@ -337,13 +339,13 @@
   if (print_parallel) 
     options << ";PRINT_PARALLEL";
 
-  std::vector<MBParallelComm*> pcs(filenames.size());
+  std::vector<ParallelComm*> pcs(filenames.size());
   std::vector<ReadParallel*> rps(filenames.size());
-  MBErrorCode result;
+  ErrorCode result;
 
   if (1 < filenames.size()) {
     for (unsigned int i = 0; i < filenames.size(); i++) {
-      pcs[i] = new MBParallelComm(mbImpl);
+      pcs[i] = new ParallelComm(mbImpl);
       rps[i] = new ReadParallel(mbImpl, pcs[i]);
     
       result = rps[i]->load_file(filenames[i].c_str(), 0, 
@@ -357,7 +359,7 @@
       }
 
         // exchange tag
-      MBRange tmp_range;
+      Range tmp_range;
       result = pcs[i]->exchange_tags("GLOBAL_ID", tmp_range);
       if (MB_SUCCESS != result) {
         std::cerr << "Tag exchange didn't work." << std::endl;
@@ -369,7 +371,7 @@
   else {
     result = mbImpl->load_file(filenames[0].c_str(), 0, 
                                options.str().c_str());
-    pcs[0] = MBParallelComm::get_pcomm(mbImpl, 0);
+    pcs[0] = ParallelComm::get_pcomm(mbImpl, 0);
     assert(pcs[0]);
   }
     
@@ -378,11 +380,11 @@
   return result;
 }
 
-MBErrorCode test_packing(MBInterface *mbImpl, const char *filename) 
+ErrorCode test_packing(Interface *mbImpl, const char *filename) 
 {
     // read the mesh
-  MBEntityHandle file_set;
-  MBErrorCode result = mbImpl->create_meshset( MESHSET_SET, file_set );
+  EntityHandle file_set;
+  ErrorCode result = mbImpl->create_meshset( MESHSET_SET, file_set );
   RRA("create_meshset failed.");
 
   result = mbImpl->load_file(filename, &file_set, NULL);
@@ -393,21 +395,21 @@
   }
   
     // get 3d entities and pack a buffer with them
-  MBRange ents, new_ents, whole_range;
+  Range ents, new_ents, whole_range;
   result = mbImpl->get_entities_by_handle(file_set, ents);
   RRA("Getting 3d ents failed.");
   
   ents.insert(file_set);
   
-  MBParallelComm *pcomm = new MBParallelComm(mbImpl);
+  ParallelComm *pcomm = new ParallelComm(mbImpl);
 
-  MBParallelComm::Buffer buff;
+  ParallelComm::Buffer buff;
   result = pcomm->pack_buffer(ents, false, true, false, -1, &buff);
   RRA("Packing buffer count (non-stored handles) failed.");
 
-  std::vector<std::vector<MBEntityHandle> > L1hloc, L1hrem;
+  std::vector<std::vector<EntityHandle> > L1hloc, L1hrem;
   std::vector<std::vector<int> > L1p;
-  std::vector<MBEntityHandle> L2hloc, L2hrem;
+  std::vector<EntityHandle> L2hloc, L2hrem;
   std::vector<unsigned int> L2p;
   
   buff.reset_ptr();
@@ -418,17 +420,17 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode report_iface_ents(MBInterface *mbImpl,
-                              std::vector<MBParallelComm *> &pcs) 
+ErrorCode report_iface_ents(Interface *mbImpl,
+                              std::vector<ParallelComm *> &pcs) 
 {
-  MBRange iface_ents[6];
-  MBErrorCode result = MB_SUCCESS, tmp_result;
+  Range iface_ents[6];
+  ErrorCode result = MB_SUCCESS, tmp_result;
   
     // now figure out which vertices are shared
-  MBRange part_ents;
+  Range part_ents;
   for (unsigned int p = 0; p < pcs.size(); p++) {
     // get entities owned by this partition
-    for (MBRange::iterator rit = pcs[p]->partition_sets().begin();
+    for (Range::iterator rit = pcs[p]->partition_sets().begin();
 	 rit != pcs[p]->partition_sets().end(); rit++) {
       tmp_result = mbImpl->get_entities_by_dimension(*rit, 3, part_ents, true);
       if (MB_SUCCESS != tmp_result) result = tmp_result;
@@ -452,7 +454,7 @@
 
     // report # iface entities
   result = mbImpl->get_adjacencies(iface_ents[4], 0, false, iface_ents[5], 
-                                   MBInterface::UNION);
+                                   Interface::UNION);
 
   int rank;
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);

Modified: MOAB/trunk/test/parallel/mhdf_parallel.c
===================================================================
--- MOAB/trunk/test/parallel/mhdf_parallel.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/mhdf_parallel.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,7 +14,6 @@
  */
 
 #include "mhdf.h"
-#include "MBTypes.h"
 
 #include <time.h>
 #include <stdlib.h>
@@ -114,7 +113,7 @@
   const int total_num_hexes = NUM_PROC;
   long first_node, first_elem, first_set, count, ntag;
   unsigned long ucount;
-  long set_desc[4] = { 0, -1, -1, MESHSET_SET };
+  long set_desc[4] = { 0, -1, -1, 0 };
   hid_t handle, handles[2];
   mhdf_Status status;
   mhdf_FileHandle file;

Modified: MOAB/trunk/test/parallel/parallel_hdf5_test.cc
===================================================================
--- MOAB/trunk/test/parallel/parallel_hdf5_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/parallel_hdf5_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,16 +1,16 @@
-#include "MBRange.hpp"
+#include "moab/Range.hpp"
 #include "TestUtil.hpp"
 
-#include "MBCore.hpp"
-#include "MBParallelComm.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
-#include "MBParallelConventions.h"
+#include "moab/Core.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
+#include "moab/MBParallelConventions.h"
 
 #include <iostream>
 #include <sstream>
 #include <algorithm>
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include <unistd.h>
 #include <float.h>
 #include <stdio.h>
@@ -18,17 +18,19 @@
 #define STRINGIFY_(X) #X
 #define STRINGIFY(X) STRINGIFY_(X)
 
+using namespace moab;
+
 #ifdef SRCDIR
 const char* InputFile = STRINGIFY(SRCDIR) "/ptest.cub";
 #else
 const char* InputFile = "ptest.cub";
 #endif
 
-void load_and_partition( MBInterface& moab, const char* filename, bool print_debug = false );
+void load_and_partition( Interface& moab, const char* filename, bool print_debug = false );
 
-void save_and_load_on_root( MBInterface& moab, const char* tmp_filename );
+void save_and_load_on_root( Interface& moab, const char* tmp_filename );
 
-void check_identical_mesh( MBInterface& moab1, MBInterface& moab2 );
+void check_identical_mesh( Interface& moab1, Interface& moab2 );
 
 void test_write_elements();
 void test_write_shared_sets();
@@ -113,9 +115,9 @@
  * should aways be true.  Print for each geometric topology set
  * the list of processors it is shared with.
  */
-void print_partitioned_entities( MBInterface& moab, bool list_non_shared = false )
+void print_partitioned_entities( Interface& moab, bool list_non_shared = false )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int size, rank;
   std::vector<int> ent_procs(MAX_SHARING_PROCS), tmp_ent_procs(MAX_SHARING_PROCS);
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
@@ -124,13 +126,13 @@
     // expect shared entities to correspond to geometric sets
     
     // get tags for parallel data
-  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
+  Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
   const char* ptag_names[] = { PARALLEL_SHARED_PROC_TAG_NAME,
                                PARALLEL_SHARED_PROCS_TAG_NAME,
                                PARALLEL_SHARED_HANDLE_TAG_NAME,
                                PARALLEL_SHARED_HANDLES_TAG_NAME,
                                PARALLEL_STATUS_TAG_NAME };
-  MBTag* tag_ptrs[] = { &sharedp_tag, &sharedps_tag, &sharedh_tag, &sharedhs_tag, &pstatus_tag };
+  Tag* tag_ptrs[] = { &sharedp_tag, &sharedps_tag, &sharedh_tag, &sharedhs_tag, &pstatus_tag };
   const int ntags = sizeof(ptag_names)/sizeof(ptag_names[0]);
   for (int i = 0; i < ntags; ++i) {
     rval = moab.tag_get_handle( ptag_names[i], *tag_ptrs[i] ); CHECK_ERR(rval);
@@ -138,32 +140,32 @@
   
     // for each geometric entity, check which processor we are sharing
     // entities with
-  MBTag geom_tag, id_tag;
+  Tag geom_tag, id_tag;
   rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, geom_tag ); CHECK_ERR(rval);
   rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag ); CHECK_ERR(rval);
   const char* topo_names_s[] = { "Vertex", "Curve", "Surface", "Volume" };
 //  const char* topo_names_p[] = { "Vertices", "Curves", "Surfaces", "Volumes" };
   std::ostringstream buffer; // buffer output in an attempt to prevent lines from different processsors being mixed up.
   for (int t = 0; t < 4; ++t) {
-    MBRange geom;
+    Range geom;
     int dim = t;
     const void* ptr = &dim;
     rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, &ptr, 1, geom );
     CHECK_ERR(rval);
   
       // for each geometric entity of dimension 't'
-    for (MBRange::const_iterator i = geom.begin(); i != geom.end(); ++i) {
-      MBEntityHandle set = *i;
+    for (Range::const_iterator i = geom.begin(); i != geom.end(); ++i) {
+      EntityHandle set = *i;
       int id;
       rval = moab.tag_get_data( id_tag, &set, 1, &id ); CHECK_ERR(rval);
 
       buffer.clear();
 
         // get entities contained in this set but not its children
-      MBRange entities, tmp_entities, children, diff;
+      Range entities, tmp_entities, children, diff;
       rval = moab.get_entities_by_handle( set, entities ); CHECK_ERR(rval);
       rval = moab.get_child_meshsets( set, children ); CHECK_ERR(rval);
-      for (MBRange::const_iterator j = children.begin(); j != children.end(); ++j) {
+      for (Range::const_iterator j = children.begin(); j != children.end(); ++j) {
         tmp_entities.clear();
         rval = moab.get_entities_by_handle( *j, tmp_entities ); CHECK_ERR(rval);
         diff = subtract( entities, tmp_entities );
@@ -223,7 +225,7 @@
                  << "ERROR: no entities!" << std::endl;
         }
         else {
-          MBRange::const_iterator j = entities.begin();
+          Range::const_iterator j = entities.begin();
           rval = moab.tag_get_data( sharedps_tag, &*j, 1, &ent_procs[0] );
           CHECK_ERR(rval);
           for (++j; j != entities.end(); ++j) {
@@ -259,9 +261,9 @@
   }
 }
 
-void load_and_partition( MBInterface& moab, const char* filename, bool print )
+void load_and_partition( Interface& moab, const char* filename, bool print )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
   rval = moab.load_file( filename, 0, 
                          "PARALLEL=READ_DELETE;"
@@ -275,9 +277,9 @@
   CHECK_ERR(rval);
 }
 
-void save_and_load_on_root( MBInterface& moab, const char* tmp_filename )
+void save_and_load_on_root( Interface& moab, const char* tmp_filename )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int procnum;
   MPI_Comm_rank( MPI_COMM_WORLD, &procnum );
   
@@ -301,15 +303,15 @@
   }
 }
 
-void count_owned_entities( MBInterface& moab, int counts[MBENTITYSET] )
+void count_owned_entities( Interface& moab, int counts[MBENTITYSET] )
 {
-  MBErrorCode rval;
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm( &moab, 0 );
+  ErrorCode rval;
+  ParallelComm* pcomm = ParallelComm::get_pcomm( &moab, 0 );
   CHECK(0 != pcomm);
   std::fill( counts, counts+MBENTITYSET, 0u );
   
-  for (MBEntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
-    MBRange range;
+  for (EntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
+    Range range;
     rval = moab.get_entities_by_type( 0, t, range );
     CHECK_ERR(rval);
     if (!range.empty())
@@ -319,14 +321,14 @@
   }
 }
 
-void check_identical_mesh( MBInterface& mb1, MBInterface& mb2 )
+void check_identical_mesh( Interface& mb1, Interface& mb2 )
 {
-  MBErrorCode rval;
-  std::map<MBEntityHandle,MBEntityHandle> entmap;
+  ErrorCode rval;
+  std::map<EntityHandle,EntityHandle> entmap;
   
     // match vertices by coordinate
-  MBRange r1, r2;
-  MBRange::iterator i1, i2;
+  Range r1, r2;
+  Range::iterator i1, i2;
   rval = mb1.get_entities_by_type( 0, MBVERTEX, r1 );
   CHECK_ERR(rval);
   rval = mb2.get_entities_by_type( 0, MBVERTEX, r2 );
@@ -353,8 +355,8 @@
   }
   
     // match element connectivity
-  std::vector<MBEntityHandle> conn1, conn2;
-  for (MBEntityType t = MBEDGE; t < MBENTITYSET; ++t) {
+  std::vector<EntityHandle> conn1, conn2;
+  for (EntityType t = MBEDGE; t < MBENTITYSET; ++t) {
     r1.clear();
     rval = mb1.get_entities_by_type( 0, t, r1 );
     CHECK_ERR(rval);
@@ -373,7 +375,7 @@
         CHECK_ERR(rval);
         if (conn1.size() != conn2.size())
           continue;
-        for (std::vector<MBEntityHandle>::iterator j = conn2.begin(); j != conn2.end(); ++j)
+        for (std::vector<EntityHandle>::iterator j = conn2.begin(); j != conn2.end(); ++j)
           *j = entmap[*j];
         if (conn1 == conn2)
           break;
@@ -390,13 +392,13 @@
 {
   int proc_counts[MBENTITYSET], all_counts[MBENTITYSET], file_counts[MBENTITYSET];
   int err, rank;
-  MBErrorCode rval;
+  ErrorCode rval;
   err = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
   CHECK(!err);
   
     // load and partition a .cub file
-  MBCore moab_instance;
-  MBInterface& moab = moab_instance;
+  Core moab_instance;
+  Interface& moab = moab_instance;
   load_and_partition( moab, InputFile, false );
   
     // count number of owned entities of each type and sum over all procs
@@ -408,7 +410,7 @@
     // do parallel write and on root proc do serial read of written file
   save_and_load_on_root( moab, "test_write_elements.h5m" );
   if (rank == 0) {
-    for (MBEntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
+    for (EntityType t = MBVERTEX; t < MBENTITYSET; ++t) {
       rval = moab.get_number_entities_by_type( 0, t, file_counts[t] );
       CHECK_ERR(rval);
     }
@@ -420,13 +422,13 @@
   CHECK(!err);
   
   bool all_equal = true;
-  for (MBEntityType t = MBVERTEX; t < MBENTITYSET; ++t) 
+  for (EntityType t = MBVERTEX; t < MBENTITYSET; ++t) 
     if (file_counts[t] != all_counts[t])
       all_equal = false;
     
   if (rank == 0 && !all_equal) {
     std::cerr << "Type\tPartnd\tWritten" << std::endl;
-    for (MBEntityType t = MBVERTEX; t < MBENTITYSET; ++t) 
+    for (EntityType t = MBVERTEX; t < MBENTITYSET; ++t) 
       std::cerr << MBCN::EntityTypeName(t) << '\t' << all_counts[t] << '\t' << file_counts[t] << std::endl;
   }
   
@@ -435,19 +437,19 @@
     // on root processor, do serial read of original .cub file and compare
   
   if (rank == 0) {
-    MBCore moab2;
+    Core moab2;
     rval = moab2.load_file( InputFile );
     CHECK_ERR(rval);
     check_identical_mesh( moab, moab2 );
   }
 }
 
-bool check_sets_sizes( MBInterface& mb1, MBEntityHandle set1,
-                       MBInterface& mb2, MBEntityHandle set2 )
+bool check_sets_sizes( Interface& mb1, EntityHandle set1,
+                       Interface& mb2, EntityHandle set2 )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   bool result = true;
-  for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
+  for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
     int count1, count2;
     rval = mb1.get_number_entities_by_type( set1, t, count1 );
     CHECK_ERR(rval);
@@ -465,40 +467,40 @@
 void test_write_shared_sets()
 {
   int err, rank, size;
-  MBErrorCode rval;
+  ErrorCode rval;
   err = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
   CHECK(!err);
   err = MPI_Comm_size( MPI_COMM_WORLD, &size );
   CHECK(!err);
   
-  MBCore moab_instance;
-  MBInterface& moab = moab_instance;
+  Core moab_instance;
+  Interface& moab = moab_instance;
   load_and_partition( moab, InputFile );
   save_and_load_on_root( moab, "test_write_shared_sets.h5m" );
 
   if (rank != 0)
     return;
   
-  MBCore moab2_instance;
-  MBInterface& moab2 = moab2_instance;
+  Core moab2_instance;
+  Interface& moab2 = moab2_instance;
   rval = moab2.load_file( InputFile );
   CHECK_ERR(rval);
   
-  MBTag mattag1, mattag2;
+  Tag mattag1, mattag2;
   rval = moab.tag_get_handle( MATERIAL_SET_TAG_NAME, mattag1 );
   CHECK_ERR(rval);
   rval = moab2.tag_get_handle( MATERIAL_SET_TAG_NAME, mattag2 );
   CHECK_ERR(rval);
   
-  MBRange matsets;
+  Range matsets;
   rval = moab2.get_entities_by_type_and_tag( 0, MBENTITYSET, &mattag2, 0, 1, matsets );
   CHECK_ERR(rval);
-  for (MBRange::iterator i = matsets.begin(); i != matsets.end(); ++i) {
+  for (Range::iterator i = matsets.begin(); i != matsets.end(); ++i) {
     int block_id;
     rval = moab2.tag_get_data( mattag2, &*i, 1, &block_id );
     CHECK_ERR(rval);
     
-    MBRange tmpents;
+    Range tmpents;
     void* tagdata[] = {&block_id};
     rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &mattag1, tagdata, 1, tmpents );
     if (tmpents.size() != 1) 
@@ -512,17 +514,17 @@
 
 void test_var_length_parallel()
 {
-  MBRange::const_iterator i;
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBRange verts;
-  MBTag vartag;
+  Range::const_iterator i;
+  ErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  Range verts;
+  Tag vartag;
   const char* filename = "var-len-para.h5m";
   const char* tagname = "ParVar";
   
   // If this tag doesn't exist, writer will fail
-  MBTag junk_tag;
+  Tag junk_tag;
   mb.tag_create( PARALLEL_GID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, junk_tag, 0 );
 
   int numproc, rank;
@@ -543,7 +545,7 @@
   std::vector<int> data;
   rval = MB_SUCCESS;
   for (i = verts.begin(); i != verts.end(); ++i) {
-    MBEntityHandle h = *i;
+    EntityHandle h = *i;
     const int n = h % 7 + 1;
     data.resize( n+1 );
     data[0] = n;
@@ -551,7 +553,7 @@
       data[j+1] = rank + j;
     const int s = (n + 1) * sizeof(int);
     const void* ptrarr[] = { &data[0] };
-    MBErrorCode tmperr = mb.tag_set_data( vartag, &h, 1, ptrarr, &s );
+    ErrorCode tmperr = mb.tag_set_data( vartag, &h, 1, ptrarr, &s );
     if (MB_SUCCESS != tmperr)
       rval = tmperr;
   }
@@ -567,10 +569,10 @@
   // processors.  Running the tests on the pre-write mesh on
   // non-root processors allows us to verify that any problems
   // are due to the file API rather than some other bug.
-  MBErrorCode rval2 = rval = MB_SUCCESS;
+  ErrorCode rval2 = rval = MB_SUCCESS;
   if (!rank) {
-    moab.~MBCore();
-    new (&moab) MBCore;
+    moab.~Core();
+    new (&moab) Core;
     rval = mb.load_mesh( filename );
     if (!KeepTmpFiles) 
       remove( filename );
@@ -583,10 +585,10 @@
   int tag_size;
   rval = mb.tag_get_size( vartag, tag_size );
   CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, rval );
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( vartag, storage );
   CHECK_EQUAL( MB_TAG_DENSE, storage );
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( vartag, type);
   CHECK_EQUAL( MB_TYPE_INTEGER, type );
   
@@ -599,7 +601,7 @@
   // and count the number of vertices for each rank.
   std::vector<int> vtx_counts( numproc, 0 );
   for (i = verts.begin(); i != verts.end(); ++i) {
-    MBEntityHandle h = *i;
+    EntityHandle h = *i;
     int size = -1;
     const void* ptrarr[1] = { 0 };
     rval = mb.tag_get_data( vartag, &h, 1, ptrarr, &size );
@@ -635,11 +637,11 @@
                         const int* global_mesh_value = 0, 
                         const int* global_default_value = 0 )
 {
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
-  MBTag ijk_vert_tag = 0, ij_set_tag = 0, global_tag = 0;
+  Tag ijk_vert_tag = 0, ij_set_tag = 0, global_tag = 0;
   if (ijk_vert_tag_name) {
     rval = mb.tag_create( ijk_vert_tag_name, 3*sizeof(int), MB_TAG_DENSE, 
                           MB_TYPE_INTEGER, ijk_vert_tag, 0 );
@@ -662,7 +664,7 @@
   
   
   int iv = intervals+1, ii = num_cpu*intervals+1;
-  std::vector<MBEntityHandle> verts(iv*iv*ii);
+  std::vector<EntityHandle> verts(iv*iv*ii);
   int idx = 0;
   for (int i = 0; i < ii; ++i) {
     for (int j = 0; j < iv; ++j) {
@@ -680,7 +682,7 @@
       }
       
       if (ij_set_tag) {
-        MBEntityHandle set;
+        EntityHandle set;
         rval = mb.create_meshset( MESHSET_SET, set );
         CHECK_ERR(rval);
         rval = mb.add_entities( set, &verts[start], idx - start );
@@ -693,13 +695,13 @@
   }
   
   const int eb = intervals*intervals*intervals;
-  std::vector<MBEntityHandle> elems(num_cpu*eb);
+  std::vector<EntityHandle> elems(num_cpu*eb);
   idx = 0;
   for (int c = 0; c < num_cpu; ++c) {
     for (int i = c*intervals; i < (c+1)*intervals; ++i) {
       for (int j = 0; j < intervals; ++j) {
         for (int k = 0; k < intervals; ++k) {
-          MBEntityHandle conn[8] = { verts[iv*(iv* i +      j    ) + k    ],
+          EntityHandle conn[8] = { verts[iv*(iv* i +      j    ) + k    ],
                                      verts[iv*(iv*(i + 1) + j    ) + k    ],
                                      verts[iv*(iv*(i + 1) + j + 1) + k    ],
                                      verts[iv*(iv* i      + j + 1) + k    ],
@@ -715,11 +717,11 @@
     }
   }
   
-  MBTag part_tag;
+  Tag part_tag;
   rval = mb.tag_create( "PARTITION", sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, part_tag, 0 );
   CHECK_ERR(rval);
   
-  std::vector<MBEntityHandle> parts(num_cpu);
+  std::vector<EntityHandle> parts(num_cpu);
   for (int i = 0; i < num_cpu; ++i) {
     rval = mb.create_meshset( MESHSET_SET, parts[i] );
     CHECK_ERR(rval);
@@ -739,9 +741,9 @@
   int numproc, rank;
   MPI_Comm_size( MPI_COMM_WORLD, &numproc );
   MPI_Comm_rank( MPI_COMM_WORLD, &rank    );
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
     // if root processor, create hdf5 file for use in testing
   if (0 == rank) 
@@ -758,15 +760,15 @@
   CHECK_ERR(rval);
       
   
-  MBTag part_tag;
+  Tag part_tag;
   rval = mb.tag_get_handle( "PARTITION", part_tag );
   CHECK_ERR(rval);
   
-  MBRange parts;
+  Range parts;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &part_tag, 0, 1, parts );
   CHECK_ERR(rval);
   CHECK_EQUAL( 1, (int)parts.size() );
-  MBEntityHandle part = parts.front();
+  EntityHandle part = parts.front();
   int id;
   rval = mb.tag_get_data( part_tag, &part, 1, &id );
   CHECK_ERR(rval);
@@ -785,7 +787,7 @@
     // check that we have the correct vertices
   const double x_min = intervals*rank;
   const double x_max = intervals*(rank+1);
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   std::vector<double> coords(verts.size());
@@ -803,7 +805,7 @@
   int numproc, rank;
   MPI_Comm_size( MPI_COMM_WORLD, &numproc );
   MPI_Comm_rank( MPI_COMM_WORLD, &rank    );
-  MBErrorCode rval;
+  ErrorCode rval;
 
     // if root processor, create hdf5 file for use in testing
   if (0 == rank) 
@@ -816,8 +818,8 @@
   clock_t tmp_t;
   
     // Time true parallel read
-  MBCore moab;
-  MBInterface &mb = moab;
+  Core moab;
+  Interface &mb = moab;
   times[0] = MPI_Wtime();
   tmp_t    = clock();
   const char opt[] = "PARALLEL=READ_PART;PARTITION=PARTITION;PARTITION_BY_RANK";
@@ -828,8 +830,8 @@
   mb.delete_mesh();
     
     // Time read and delete
-  MBCore moab2;
-  MBInterface& mb2 = moab2;
+  Core moab2;
+  Interface& mb2 = moab2;
   times[2] = MPI_Wtime();
   tmp_t    = clock();
   const char opt2[] = "PARALLEL=READ_DELETE;PARTITION=PARTITION;PARTITION_BY_RANK";
@@ -840,8 +842,8 @@
   mb2.delete_mesh();
     
     // Time broadcast and delete
-  MBCore moab3;
-  MBInterface& mb3 = moab3;
+  Core moab3;
+  Interface& mb3 = moab3;
   times[4] = MPI_Wtime();
   tmp_t    = clock();
   const char opt3[] = "PARALLEL=BCAST_DELETE;PARTITION=PARTITION;PARTITION_BY_RANK";
@@ -874,9 +876,9 @@
   int numproc, rank;
   MPI_Comm_size( MPI_COMM_WORLD, &numproc );
   MPI_Comm_rank( MPI_COMM_WORLD, &rank    );
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
     // if root processor, create hdf5 file for use in testing
   if (0 == rank) 
@@ -891,7 +893,7 @@
   if (0 == rank && !KeepTmpFiles) remove( file_name );
   CHECK_ERR(rval);
       
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_get_handle( tag_name, tag );
   CHECK_ERR(rval);
   
@@ -900,24 +902,24 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( 3*(int)sizeof(int), size );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_DENSE, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TYPE_INTEGER, type );
   
-  MBRange verts, tagged;
+  Range verts, tagged;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, tagged );
   CHECK_ERR(rval);
   CHECK_EQUAL( verts, tagged );
   
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
     rval = mb.get_coords( &*i, 1, coords );
     CHECK_ERR(rval);
@@ -945,9 +947,9 @@
   int numproc, rank;
   MPI_Comm_size( MPI_COMM_WORLD, &numproc );
   MPI_Comm_rank( MPI_COMM_WORLD, &rank    );
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
   const int def_val = 0xdeadcad;
   const int global_val = -11;
 
@@ -964,7 +966,7 @@
   if (0 == rank && !KeepTmpFiles) remove( file_name );
   CHECK_ERR(rval);
       
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_get_handle( tag_name, tag );
   CHECK_ERR(rval);
   
@@ -973,12 +975,12 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( (int)sizeof(int), size );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_DENSE, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TYPE_INTEGER, type );
@@ -999,9 +1001,9 @@
   int numproc, rank;
   MPI_Comm_size( MPI_COMM_WORLD, &numproc );
   MPI_Comm_rank( MPI_COMM_WORLD, &rank    );
-  MBCore moab;
-  MBInterface &mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface &mb = moab;
+  ErrorCode rval;
 
     // if root processor, create hdf5 file for use in testing
   if (0 == rank) 
@@ -1016,7 +1018,7 @@
   if (0 == rank && !KeepTmpFiles) remove( file_name );
   CHECK_ERR(rval);
       
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_get_handle( tag_name, tag );
   CHECK_ERR(rval);
   
@@ -1025,23 +1027,23 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( 2*(int)sizeof(int), size );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_SPARSE, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TYPE_INTEGER, type );
   
   const int iv = DefaultReadIntervals + 1;
-  MBRange sets;
+  Range sets;
   rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, 0, 1, sets );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)(iv*iv), sets.size() );
+  CHECK_EQUAL( (EntityHandle)(iv*iv), sets.size() );
   
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
     int ij[2];
     rval = mb.tag_get_data( tag, &*i, 1, &ij );
     CHECK_ERR(rval);
@@ -1051,13 +1053,13 @@
     CHECK( ij[1] >= 0 );
     CHECK( ij[1] <= DefaultReadIntervals );
     
-    MBRange contents;
+    Range contents;
     rval = mb.get_entities_by_handle( *i, contents );
     CHECK_ERR(rval);
     CHECK(contents.all_of_type(MBVERTEX));
-    CHECK_EQUAL( (MBEntityHandle)iv, contents.size() );
+    CHECK_EQUAL( (EntityHandle)iv, contents.size() );
     
-    for (MBRange::iterator v = contents.begin(); v != contents.end(); ++v) {
+    for (Range::iterator v = contents.begin(); v != contents.end(); ++v) {
       double coords[3];
       rval = mb.get_coords( &*v, 1, coords );
       CHECK_ERR(rval);

Modified: MOAB/trunk/test/parallel/parallel_unit_tests.cpp
===================================================================
--- MOAB/trunk/test/parallel/parallel_unit_tests.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/parallel_unit_tests.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
 #include "ReadParallel.hpp"
 #include "FileOptions.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
-#include "MBmpi.h"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab_mpi.h"
 #include <iostream>
 #include <algorithm>
 #include <sstream>
@@ -17,9 +17,11 @@
 #define STRINGIFY_(X) #X
 #define STRINGIFY(X) STRINGIFY_(X)
 
+using namespace moab;
 
+
 #define CHKERR(a) do { \
-  MBErrorCode val = (a); \
+  ErrorCode val = (a); \
   if (MB_SUCCESS != val) { \
     std::cerr << "Error code  " << val << " at " << __FILE__ << ":" << __LINE__ << std::endl;\
     return val; \
@@ -28,7 +30,7 @@
 
 #define PCHECK(A) if (is_any_proc_error(!(A))) return report_error(__FILE__,__LINE__)
 
-MBErrorCode report_error( const char* file, int line )
+ErrorCode report_error( const char* file, int line )
 {
   std::cerr << "Failure at " << file << ':' << line << std::endl;
   return MB_FAILURE;
@@ -40,21 +42,21 @@
  
 // Get either all the entities in a set or only the entities of
 // a specific type, depending on whether or not type == MBMAXTYPE.
-MBErrorCode get_set_contents( MBInterface& moab, 
-                              MBEntityHandle set, 
-                              MBEntityType type,
-                              MBRange& contents_out );
+ErrorCode get_set_contents( Interface& moab, 
+                              EntityHandle set, 
+                              EntityType type,
+                              Range& contents_out );
 
 // Get processors an entity is shared with.
-MBErrorCode get_sharing_processors( MBInterface& moab,
-                                    MBEntityHandle entity,
+ErrorCode get_sharing_processors( Interface& moab,
+                                    EntityHandle entity,
                                     std::vector<int>& other_procs_out );
 
 // Get mesh entities owned by a geometric entity set.
-MBErrorCode get_geom_inclusive_mesh( MBInterface& moab,
-                                     MBEntityHandle set,
-                                     MBEntityType type,
-                                     MBRange& contents_out );
+ErrorCode get_geom_inclusive_mesh( Interface& moab,
+                                     EntityHandle set,
+                                     EntityType type,
+                                     Range& contents_out );
 
 // Create a parallel mesh
 //
@@ -90,10 +92,10 @@
 // 5-----10-----15-----20-----25-----30-----
 //
 // Element IDs will be [4*rank+1,4*rank+5]
-MBErrorCode parallel_create_mesh( MBInterface& mb,
+ErrorCode parallel_create_mesh( Interface& mb,
                                   int output_vertx_ids[9],
-                                  MBEntityHandle output_vertex_handles[9],
-                                  MBRange& output_elements );
+                                  EntityHandle output_vertex_handles[9],
+                                  Range& output_elements );
 
 // Test if is_my_error is non-zero on any processor in MPI_COMM_WORLD
 int is_any_proc_error( int is_my_error );
@@ -105,34 +107,34 @@
 // Check consistancy of sharing data.  (E.g. compare sharing procs for
 // vertices to that of adjacent elements, compare sharing data for 
 // interfaces with that of contained entities, etc.)
-MBErrorCode test_elements_on_several_procs( const char* filename );
+ErrorCode test_elements_on_several_procs( const char* filename );
 // Test correct ghosting of elements
-MBErrorCode test_ghost_elements_3_2_1( const char* filename );
-MBErrorCode test_ghost_elements_3_2_2( const char* filename );
-MBErrorCode test_ghost_elements_3_0_1( const char* filename );
-MBErrorCode test_ghost_elements_2_0_1( const char* filename );
+ErrorCode test_ghost_elements_3_2_1( const char* filename );
+ErrorCode test_ghost_elements_3_2_2( const char* filename );
+ErrorCode test_ghost_elements_3_0_1( const char* filename );
+ErrorCode test_ghost_elements_2_0_1( const char* filename );
 // Test exchange of tag data on ghost elements
-MBErrorCode test_ghost_tag_exchange( const char* filename );
+ErrorCode test_ghost_tag_exchange( const char* filename );
 // Bug where exchange_tags fails if dense tag cannot be queried
 // for all ghost entities (e.g. no default value)
-MBErrorCode regression_ghost_tag_exchange_no_default( const char* filename );
+ErrorCode regression_ghost_tag_exchange_no_default( const char* filename );
 // Test owners for interface entities
-MBErrorCode test_interface_owners( const char* );
+ErrorCode test_interface_owners( const char* );
 // Test data for shared interface entitites with one level of ghosting
-MBErrorCode regression_owners_with_ghosting( const char* );
+ErrorCode regression_owners_with_ghosting( const char* );
 // Verify all sharing data for vertices with one level of ghosting
-MBErrorCode test_ghosted_entity_shared_data( const char* );
+ErrorCode test_ghosted_entity_shared_data( const char* );
 /**************************************************************************
                               Main Method
  **************************************************************************/
 
 #define RUN_TEST(A, B) run_test( &A, #A, B )
 
-int run_test( MBErrorCode (*func)(const char*), 
+int run_test( ErrorCode (*func)(const char*), 
               const char* func_name,
               const char* file_name )
 {
-  MBErrorCode result = (*func)(file_name);
+  ErrorCode result = (*func)(file_name);
   int is_err = is_any_proc_error( (MB_SUCCESS != result) );
   int rank;
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
@@ -226,10 +228,10 @@
                      Utility Method Implementations
  **************************************************************************/
  
-MBErrorCode get_set_contents( MBInterface& moab,
-                              MBEntityHandle set,
-                              MBEntityType type,
-                              MBRange& contents_out )
+ErrorCode get_set_contents( Interface& moab,
+                              EntityHandle set,
+                              EntityType type,
+                              Range& contents_out )
 {
   if (type == MBMAXTYPE) 
     return moab.get_entities_by_handle( set, contents_out );
@@ -237,18 +239,18 @@
     return moab.get_entities_by_type( set, type, contents_out );
 }
 
-MBErrorCode get_sharing_processors( MBInterface& moab,
-                                    MBEntityHandle entity,
+ErrorCode get_sharing_processors( Interface& moab,
+                                    EntityHandle entity,
                                     std::vector<int>& other_procs_out )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // get tags for parallel data
-  MBTag sharedp_tag, sharedps_tag, pstatus_tag;
+  Tag sharedp_tag, sharedps_tag, pstatus_tag;
   const char* ptag_names[] = { PARALLEL_SHARED_PROC_TAG_NAME,
                                PARALLEL_SHARED_PROCS_TAG_NAME,
                                PARALLEL_STATUS_TAG_NAME };
-  MBTag* tag_ptrs[] = { &sharedp_tag, &sharedps_tag, &pstatus_tag };
+  Tag* tag_ptrs[] = { &sharedp_tag, &sharedps_tag, &pstatus_tag };
   const int ntags = sizeof(ptag_names)/sizeof(ptag_names[0]);
   for (int i = 0; i < ntags; ++i) {
     rval = moab.tag_get_handle( ptag_names[i], *tag_ptrs[i] ); 
@@ -277,18 +279,18 @@
   
                           
 
-MBErrorCode get_geom_inclusive_mesh( MBInterface& moab,
-                                     MBEntityHandle set,
-                                     MBEntityType type,
-                                     MBRange& contents_out )
+ErrorCode get_geom_inclusive_mesh( Interface& moab,
+                                     EntityHandle set,
+                                     EntityType type,
+                                     Range& contents_out )
 {
-  MBRange children, child_ents, tmp_range;
-  MBErrorCode rval;
+  Range children, child_ents, tmp_range;
+  ErrorCode rval;
   
   rval = get_set_contents( moab, set, type, contents_out ); CHKERR(rval);
   rval = moab.get_child_meshsets( set, children );    CHKERR(rval);
     
-  for (MBRange::iterator i = children.begin(); i != children.end(); ++i) {
+  for (Range::iterator i = children.begin(); i != children.end(); ++i) {
     child_ents.clear();
     rval = get_set_contents( moab, *i, type, child_ents );  CHKERR(rval);
     tmp_range = subtract( contents_out,  child_ents );
@@ -306,10 +308,10 @@
 }
 
 
-MBErrorCode parallel_create_mesh( MBInterface& mb,
+ErrorCode parallel_create_mesh( Interface& mb,
                                   int vtx_ids[9],
-                                  MBEntityHandle vtx_handles[9],
-                                  MBRange& range )
+                                  EntityHandle vtx_handles[9],
+                                  Range& range )
 {
     // Each processor will create four quads.
     // Groups of four quads will be arranged as follows:
@@ -364,8 +366,8 @@
                                x, y+1, 0,   x+1, y+1, 0,   x+2, y+1, 0,
                                x, y+2, 0,   x+1, y+2, 0,   x+2, y+2, 0 };
 
-  MBErrorCode rval;
-  MBTag id_tag;
+  ErrorCode rval;
+  Tag id_tag;
 
   rval = mb.create_vertices( coords, 9, range ); CHKERR(rval);
   assert(range.size() == 9);
@@ -374,14 +376,14 @@
   rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag ); CHKERR(rval);
   rval = mb.tag_set_data( id_tag, vtx_handles, 9, &ids ); CHKERR(rval);
 
-  const MBEntityHandle conn[4][4] = { 
+  const EntityHandle conn[4][4] = { 
                          { vtx_handles[0], vtx_handles[3], vtx_handles[4], vtx_handles[1] },
                          { vtx_handles[1], vtx_handles[4], vtx_handles[5], vtx_handles[2] },
                          { vtx_handles[3], vtx_handles[6], vtx_handles[7], vtx_handles[4] },
                          { vtx_handles[4], vtx_handles[7], vtx_handles[8], vtx_handles[5] } };
   for (int i = 0; i < 4; ++i) {
     const int id = 4*rank + i + 1;
-    MBEntityHandle h;
+    EntityHandle h;
     rval = mb.create_element( MBQUAD, conn[i], 4, h ); CHKERR(rval);
     range.insert(h);
     rval = mb.tag_set_data( id_tag, &h, 1, &id ); CHKERR(rval);
@@ -394,11 +396,11 @@
                            Test  Implementations
  **************************************************************************/
 
-MBErrorCode test_elements_on_several_procs( const char* filename )
+ErrorCode test_elements_on_several_procs( const char* filename )
 {
-  MBCore mb_instance;
-  MBInterface& moab = mb_instance;
-  MBErrorCode rval;
+  Core mb_instance;
+  Interface& moab = mb_instance;
+  ErrorCode rval;
   const char* geom_names[] = { "vertex", "curve", "surface", "volume", "unknown" };
   
   rval = moab.load_file( filename, 0, 
@@ -410,7 +412,7 @@
   
     // test contents of interface sets against sharedEnts structure in pcomm;
   int my_error = 0;
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm(&moab, 0);
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&moab, 0);
   rval = pcomm->check_all_shared_handles();
   if (MB_SUCCESS != rval) {
     my_error = 1;
@@ -424,22 +426,22 @@
   if (MB_SUCCESS != rval) my_error = 1;
   PCHECK(!my_error);
 
-  MBTag geom_tag, id_tag;
+  Tag geom_tag, id_tag;
   rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, geom_tag ); CHKERR(rval);
   rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag ); CHKERR(rval);  
   
     // search for geometric entity sets that contain a vertex
     // that is shared by more than two 
-  MBRange geom_ents, several_proc_ents, invalid_proc_ents;
+  Range geom_ents, several_proc_ents, invalid_proc_ents;
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, 0, 1, geom_ents );
   CHKERR(rval);
-  for (MBRange::iterator i = geom_ents.begin(); i != geom_ents.end(); ++i) {
-    MBRange verts;
+  for (Range::iterator i = geom_ents.begin(); i != geom_ents.end(); ++i) {
+    Range verts;
     rval = get_geom_inclusive_mesh( moab, *i, MBVERTEX, verts ); CHKERR(rval);
     if (verts.empty())
       continue;
     std::vector<int> procs;
-    MBRange::iterator j = verts.begin();
+    Range::iterator j = verts.begin();
     rval = get_sharing_processors( moab, *j, procs ); CHKERR(rval);
     if (procs.size() > 1)
       several_proc_ents.insert( *i );
@@ -459,7 +461,7 @@
     std::cerr << "Vertices owned by a single geometric entity are "
               << "not shared by the same set of processors for the "
               << "following geometric entities: ";
-    for (MBRange::iterator i = invalid_proc_ents.begin();  
+    for (Range::iterator i = invalid_proc_ents.begin();  
          i != invalid_proc_ents.end(); ++i) {
       int dim;
       int id;
@@ -480,13 +482,13 @@
     // now scan the list of geometric entities for
     // any for which the higher-dimension entities
     // don't match the vertices.
-  for (MBRange::iterator i = several_proc_ents.begin();
+  for (Range::iterator i = several_proc_ents.begin();
        i != several_proc_ents.end(); ++i) {
-    MBRange ents;
+    Range ents;
     rval = get_geom_inclusive_mesh( moab, *i, MBMAXTYPE, ents ); CHKERR(rval);
     std::vector<int> exp_procs, ent_procs;
     rval = get_sharing_processors( moab, ents.front(), exp_procs ); CHKERR(rval);
-    for (MBRange::iterator j = ents.upper_bound(MBVERTEX); j != ents.end(); ++j) {
+    for (Range::iterator j = ents.upper_bound(MBVERTEX); j != ents.end(); ++j) {
       rval = get_sharing_processors( moab, *j, ent_procs ); CHKERR(rval);
       if (ent_procs != exp_procs)
         invalid_proc_ents.insert( *i );
@@ -503,7 +505,7 @@
     std::cerr << "Elements owned by a single geometric entity are "
               << "not shared by the same set of processors for the "
               << "following geometric entities: ";
-    for (MBRange::iterator i = invalid_proc_ents.begin();  
+    for (Range::iterator i = invalid_proc_ents.begin();  
          i != invalid_proc_ents.end(); ++i) {
       int dim;
       int id;
@@ -525,11 +527,11 @@
 }
 
 
-MBErrorCode get_ghost_entities( MBParallelComm& pcomm,
-                                MBRange& ghost_ents )
+ErrorCode get_ghost_entities( ParallelComm& pcomm,
+                                Range& ghost_ents )
 {
-  MBRange all_ents;
-  MBErrorCode rval;
+  Range all_ents;
+  ErrorCode rval;
   
   
   rval = pcomm.get_moab()->get_entities_by_handle( 0, all_ents );
@@ -538,34 +540,34 @@
   rval = pcomm.get_moab()->tag_get_data( pcomm.pstatus_tag(), all_ents, &flags[0] );
   CHKERR(rval);
   
-  MBRange::iterator ins = ghost_ents.begin();
+  Range::iterator ins = ghost_ents.begin();
   std::vector<unsigned char>::const_iterator f = flags.begin();
-  for (MBRange::iterator i = all_ents.begin(); i != all_ents.end(); ++i, ++f) 
+  for (Range::iterator i = all_ents.begin(); i != all_ents.end(); ++i, ++f) 
     if ((*f & PSTATUS_NOT_OWNED) && !(*f & PSTATUS_INTERFACE))
       ins = ghost_ents.insert( ins, *i, *i );
   
   return MB_SUCCESS;
 }
 
-MBErrorCode get_expected_ghosts( MBInterface& moab,
+ErrorCode get_expected_ghosts( Interface& moab,
                                  const std::vector<int> partition_geom_ids[4],
                                  std::vector<int>& ghost_entity_ids,
                                  int ghost_dimension,
                                  int bridge_dimension,
                                  int num_layers )
 {
-  MBErrorCode rval;
-  MBTag tags[2];
+  ErrorCode rval;
+  Tag tags[2];
   rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, tags[0] ); CHKERR(rval);
   rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, tags[1] ); CHKERR(rval);  
 
     // get all interface sets, by ID
-  MBRange iface_sets;
+  Range iface_sets;
   for (int d = 0; d < 3; ++d) {
     for (size_t i = 0; i < partition_geom_ids[d].size(); ++i) {
         // get the entity set
       const void* tag_vals[2] = { &d, &(partition_geom_ids[d][i]) };
-      MBRange ents;
+      Range ents;
       rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET,
                                                 tags, tag_vals, 2, 
                                                 ents ); CHKERR(rval);
@@ -573,15 +575,15 @@
     }
   }
     // get all interface entities
-  MBRange all_iface_ents;
-  for (MBRange::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
+  Range all_iface_ents;
+  for (Range::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
     rval = moab.get_entities_by_handle( *i, all_iface_ents ); 
     CHKERR(rval);
   }
   
     // for each interface set
-  MBRange ghosts;
-  for (MBRange::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
+  Range ghosts;
+  for (Range::iterator i = iface_sets.begin(); i != iface_sets.end(); ++i) {
     if (num_layers < 1)
       break;
     
@@ -591,18 +593,18 @@
     CHKERR(rval);
      
       // get partitions adjacent to interface set
-    MBRange parents; parents.insert(*i);
+    Range parents; parents.insert(*i);
     for (int step = gdim; step < 3; ++step) {
-      MBRange old_parents;
+      Range old_parents;
       old_parents.swap(parents);
-      for (MBRange::iterator p = old_parents.begin(); p != old_parents.end(); ++p) {
+      for (Range::iterator p = old_parents.begin(); p != old_parents.end(); ++p) {
         rval = moab.get_parent_meshsets( *p, parents ); CHKERR(rval);
       }
     }
     
       // get entities in adjacent partitions, skip partitions owned by this proc
-    MBRange adj_proc_ents;
-    for (MBRange::iterator p = parents.begin(); p != parents.end(); ++p) {
+    Range adj_proc_ents;
+    for (Range::iterator p = parents.begin(); p != parents.end(); ++p) {
       int id;
       rval = moab.tag_get_data( tags[1], &*p, 1, &id ); CHKERR(rval);
       if (std::find(partition_geom_ids[3].begin(), partition_geom_ids[3].end(), id) 
@@ -613,21 +615,21 @@
     }
     
       // get sub-entities implicitly within partitions
-    MBRange tmprange;
+    Range tmprange;
     for (int d = 2; d >= 0; --d) {
-      rval = moab.get_adjacencies( adj_proc_ents, d, false, tmprange, MBInterface::UNION );
+      rval = moab.get_adjacencies( adj_proc_ents, d, false, tmprange, Interface::UNION );
       CHKERR(rval);
     }
     adj_proc_ents.merge( subtract( tmprange,  all_iface_ents ) );
     
       // get adjacent entities
-    MBRange iface_ghosts, iface_ents;
+    Range iface_ghosts, iface_ents;
     rval = moab.get_entities_by_dimension( *i, bridge_dimension, iface_ents ); CHKERR(rval);
     for (int n = 0; n < num_layers; ++n) {
       iface_ghosts.clear();
-      rval = moab.get_adjacencies( iface_ents, ghost_dimension, false, iface_ghosts, MBInterface::UNION ); CHKERR(rval);
+      rval = moab.get_adjacencies( iface_ents, ghost_dimension, false, iface_ghosts, Interface::UNION ); CHKERR(rval);
       iface_ents.clear();
-      rval = moab.get_adjacencies( iface_ghosts, bridge_dimension, true, iface_ents, MBInterface::UNION ); CHKERR(rval);
+      rval = moab.get_adjacencies( iface_ghosts, bridge_dimension, true, iface_ents, Interface::UNION ); CHKERR(rval);
     }
     
       // intersect with entities in adjacent partitions
@@ -641,14 +643,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode test_ghost_elements( const char* filename,
+ErrorCode test_ghost_elements( const char* filename,
                                  int ghost_dimension,
                                  int bridge_dimension,
                                  int num_layers )
 {
-  MBCore mb_instance;
-  MBInterface& moab = mb_instance;
-  MBErrorCode rval;
+  Core mb_instance;
+  Interface& moab = mb_instance;
+  ErrorCode rval;
 
   std::ostringstream file_opts;
   file_opts << "PARALLEL=READ_DELETE;"
@@ -662,13 +664,13 @@
   
   rval = moab.load_file( filename, 0, file_opts.str().c_str() );
   CHKERR(rval);
-  MBTag geom_tag, id_tag;
+  Tag geom_tag, id_tag;
   rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, geom_tag ); CHKERR(rval);
   rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag ); CHKERR(rval);  
   
     // Get partition sets
-  MBRange partition_geom[4];
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm(&moab, 0);
+  Range partition_geom[4];
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&moab, 0);
   partition_geom[3] = pcomm->partition_sets();
   PCHECK( !partition_geom[3].empty() );
 
@@ -676,14 +678,14 @@
   CHKERR(rval);
   
     // exchange id tags to allow comparison by id
-  MBRange tmp_ents;
+  Range tmp_ents;
   rval = pcomm->get_shared_entities(-1, tmp_ents, -1, false, true);
   rval = pcomm->exchange_tags(id_tag, tmp_ents);
   CHKERR(rval);
   
     // Get geometric surfaces
-  MBRange surfs, tmp;
-  for (MBRange::iterator i = partition_geom[3].begin(); i != partition_geom[3].end(); ++i) {
+  Range surfs, tmp;
+  for (Range::iterator i = partition_geom[3].begin(); i != partition_geom[3].end(); ++i) {
     tmp.clear();
     rval = moab.get_child_meshsets( *i, tmp ); CHKERR(rval);
     surfs.merge( tmp );
@@ -696,15 +698,15 @@
   
   int error = 0;
   std::ostringstream error_msg;
-  MBRange ents, iface_surfs, iface_curves, iface_vertices;
-  for (MBRange::iterator i = surfs.begin(); !error && i != surfs.end(); ++i) {
+  Range ents, iface_surfs, iface_curves, iface_vertices;
+  for (Range::iterator i = surfs.begin(); !error && i != surfs.end(); ++i) {
     ents.clear();
     rval = moab.get_entities_by_dimension( *i, ghost_dimension-1, ents ); CHKERR(rval);
     if (ents.empty())
       continue;
     
     std::vector<int> procs, tmp_procs;
-    MBRange::iterator j = ents.begin();
+    Range::iterator j = ents.begin();
     rval = get_sharing_processors( moab, *j, procs ); CHKERR(rval);
     for (++j; !error && j != ents.end(); ++j) {
       tmp_procs.clear();
@@ -748,7 +750,7 @@
     return MB_FAILURE;
   }
   
-  for (MBRange::iterator i = partition_geom[1].begin(); i != partition_geom[1].end(); ++i) {
+  for (Range::iterator i = partition_geom[1].begin(); i != partition_geom[1].end(); ++i) {
     ents.clear();
     rval = moab.get_child_meshsets( *i, ents ); CHKERR(rval);
     partition_geom[0].merge( ents );
@@ -762,15 +764,15 @@
   }
   
     // get the global IDs of the ghosted entities
-  MBRange ghost_ents;
+  Range ghost_ents;
   rval = get_ghost_entities( *pcomm, ghost_ents ); CHKERR(rval);
-  std::pair<MBRange::iterator,MBRange::iterator> vtx = ghost_ents.equal_range(MBVERTEX);
+  std::pair<Range::iterator,Range::iterator> vtx = ghost_ents.equal_range(MBVERTEX);
   ghost_ents.erase( vtx.first, vtx.second );
   std::vector<int> actual_ghost_ent_ids(ghost_ents.size());
   rval = moab.tag_get_data( id_tag, ghost_ents, &actual_ghost_ent_ids[0] ); CHKERR(rval);
   
     // read file in serial
-  MBCore moab2;
+  Core moab2;
   rval = moab2.load_file( filename );  
   PCHECK(MB_SUCCESS == rval);
   
@@ -787,15 +789,15 @@
   
     // check we only have the partitioned and ghosted entities
     // on this processor.
-  MBRange myents;
-  for (MBRange::iterator i = partition_geom[3].begin(); i != partition_geom[3].end(); ++i) {
+  Range myents;
+  for (Range::iterator i = partition_geom[3].begin(); i != partition_geom[3].end(); ++i) {
     ents.clear();
     rval = moab.get_entities_by_dimension( *i, 3, ents ); CHKERR(rval);
     myents.merge( ents );
   }
   if (ghost_dimension != 3) {
     ents.clear();
-    rval = moab.get_adjacencies( myents, ghost_dimension, false, ents, MBInterface::UNION );
+    rval = moab.get_adjacencies( myents, ghost_dimension, false, ents, Interface::UNION );
     PCHECK(MB_SUCCESS == rval);
     myents.swap(ents);
   }
@@ -813,32 +815,32 @@
 }
 
 
-MBErrorCode test_ghost_elements_3_2_1( const char* filename )
+ErrorCode test_ghost_elements_3_2_1( const char* filename )
 {
   return test_ghost_elements( filename, 3, 2, 1 );
 }
 
-MBErrorCode test_ghost_elements_3_2_2( const char* filename )
+ErrorCode test_ghost_elements_3_2_2( const char* filename )
 {
   return test_ghost_elements( filename, 3, 2, 2 );
 }
 
-MBErrorCode test_ghost_elements_3_0_1( const char* filename )
+ErrorCode test_ghost_elements_3_0_1( const char* filename )
 {
   return test_ghost_elements( filename, 3, 0, 1 );
 }
 
-MBErrorCode test_ghost_elements_2_0_1( const char* filename )
+ErrorCode test_ghost_elements_2_0_1( const char* filename )
 {
   return test_ghost_elements( filename, 2, 0, 1 );
 }
 
 
-MBErrorCode test_ghost_tag_exchange( const char* filename )
+ErrorCode test_ghost_tag_exchange( const char* filename )
 {
-  MBCore mb_instance;
-  MBInterface& moab = mb_instance;
-  MBErrorCode rval;
+  Core mb_instance;
+  Interface& moab = mb_instance;
+  ErrorCode rval;
 
   rval = moab.load_file( filename, 0, 
                          "PARALLEL=READ_DELETE;"
@@ -849,10 +851,10 @@
   CHKERR(rval);
   
     // Get ghost elements
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm(&moab, 0);
-  MBRange local, ghosts;
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&moab, 0);
+  Range local, ghosts;
   rval = moab.get_entities_by_dimension( 0, 3, local ); CHKERR(rval);
-  MBRange::iterator i = local.begin();
+  Range::iterator i = local.begin();
   while (i != local.end()) {
     int rank;
     rval = pcomm->get_owner( *i, rank ); CHKERR(rval);
@@ -866,18 +868,18 @@
   }
   
     // create a tag to exchange
-  MBTag dense_test_tag;
-  MBEntityHandle defval = 0;
-  rval = moab.tag_create( "TEST-TAG", sizeof(MBEntityHandle), MB_TAG_DENSE,
+  Tag dense_test_tag;
+  EntityHandle defval = 0;
+  rval = moab.tag_create( "TEST-TAG", sizeof(EntityHandle), MB_TAG_DENSE,
                            dense_test_tag, &defval ); CHKERR(rval);
     
     // for all entiites that I own, set tag to handle value
-  std::vector<MBEntityHandle> handles(local.size()), handles2;
+  std::vector<EntityHandle> handles(local.size()), handles2;
   std::copy( local.begin(), local.end(), handles.begin() );
   rval = moab.tag_set_data( dense_test_tag, local, &handles[0] ); CHKERR(rval);
   
     // exchange tag data
-  MBRange tmp_range;
+  Range tmp_range;
   rval = pcomm->exchange_tags( dense_test_tag, tmp_range ); CHKERR(rval);
   
     // make sure local values are unchanged
@@ -894,7 +896,7 @@
 
 
     // now do it all again for a sparse tag
-  MBTag sparse_test_tag;
+  Tag sparse_test_tag;
   rval = moab.tag_create( "TEST-TAG-2", sizeof(int), MB_TAG_DENSE,
                            MB_TYPE_INTEGER, sparse_test_tag, 0 ); CHKERR(rval);
     
@@ -926,11 +928,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode regression_ghost_tag_exchange_no_default( const char* filename )
+ErrorCode regression_ghost_tag_exchange_no_default( const char* filename )
 {
-  MBCore mb_instance;
-  MBInterface& moab = mb_instance;
-  MBErrorCode rval;
+  Core mb_instance;
+  Interface& moab = mb_instance;
+  ErrorCode rval;
 
   rval = moab.load_file( filename, 0, 
                          "PARALLEL=READ_DELETE;"
@@ -941,13 +943,13 @@
   CHKERR(rval);
   
     // create a tag to exchange
-  MBTag dense_test_tag;
-  rval = moab.tag_create( "TEST-TAG", sizeof(MBEntityHandle), MB_TAG_DENSE,
+  Tag dense_test_tag;
+  rval = moab.tag_create( "TEST-TAG", sizeof(EntityHandle), MB_TAG_DENSE,
                            dense_test_tag, 0 ); CHKERR(rval);
   
     // exchange tag data
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm(&moab, 0);
-  MBRange tmp_range;
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&moab, 0);
+  Range tmp_range;
   rval = pcomm->exchange_tags( dense_test_tag, tmp_range ); 
   PCHECK(MB_SUCCESS == rval);
   
@@ -1030,16 +1032,16 @@
   return error_count;
 }
 
-MBErrorCode test_interface_owners_common( int num_ghost_layers )
+ErrorCode test_interface_owners_common( int num_ghost_layers )
 {
-  MBErrorCode rval;  
-  MBCore moab_instance;
-  MBInterface& mb = moab_instance;
-  MBParallelComm pcomm( &mb );
+  ErrorCode rval;  
+  Core moab_instance;
+  Interface& mb = moab_instance;
+  ParallelComm pcomm( &mb );
   
     // build distributed quad mesh
-  MBRange quads;
-  MBEntityHandle verts[9];
+  Range quads;
+  EntityHandle verts[9];
   int ids[9];
   rval = parallel_create_mesh( mb, ids, verts, quads );  PCHECK(MB_SUCCESS == rval);
   rval = pcomm.resolve_shared_ents( 0, quads, 2, 1 ); PCHECK(MB_SUCCESS == rval);
@@ -1077,12 +1079,12 @@
 // Common implementation for both:
 //   test_interface
 //   regression_interface_with_ghosting
-MBErrorCode test_interface_owners( const char* )
+ErrorCode test_interface_owners( const char* )
 {
   return test_interface_owners_common(0);
 }
 
-MBErrorCode regression_owners_with_ghosting( const char* )
+ErrorCode regression_owners_with_ghosting( const char* )
 {
   return test_interface_owners_common(1);
 }
@@ -1091,23 +1093,23 @@
 struct VtxData {
   std::vector<int> procs;
   std::vector<int> owners;
-  std::vector<MBEntityHandle> handles;
+  std::vector<EntityHandle> handles;
 };
 
-MBErrorCode test_ghosted_entity_shared_data( const char* )
+ErrorCode test_ghosted_entity_shared_data( const char* )
 {
-  MBErrorCode rval;  
-  MBCore moab_instance;
-  MBInterface& mb = moab_instance;
-  MBParallelComm pcomm( &mb );
+  ErrorCode rval;  
+  Core moab_instance;
+  Interface& mb = moab_instance;
+  ParallelComm pcomm( &mb );
 
   int rank, size;
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
   MPI_Comm_size( MPI_COMM_WORLD, &size );
    
     // build distributed quad mesh
-  MBRange quads;
-  MBEntityHandle verts[9];
+  Range quads;
+  EntityHandle verts[9];
   int ids[9];
   rval = parallel_create_mesh( mb, ids, verts, quads );  PCHECK(MB_SUCCESS == rval);
   rval = pcomm.resolve_shared_ents( 0, quads, 2, 1 ); PCHECK(MB_SUCCESS == rval);

Modified: MOAB/trunk/test/parallel/parallel_write_test.cc
===================================================================
--- MOAB/trunk/test/parallel/parallel_write_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/parallel_write_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
-#include "MBCore.hpp"
-#include "MBParallelComm.hpp"
-#include "MBTagConventions.hpp"
-#include "MBmpi.h"
+#include "moab/Core.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab_mpi.h"
 #include <stdlib.h>
 #include <iostream>
 #include <time.h>
@@ -10,6 +10,8 @@
 #include <assert.h>
 #include <stdio.h>
 
+using namespace moab;
+
 #define TPRINT(A) tprint( (A) )
 static void tprint(const char* A) 
 {
@@ -32,7 +34,7 @@
 // along each edge.  Otherwise processor blocks will be arranged
 // within the subset of the grid that is the ceiling of the cubic
 // root of the comm size such that there are no disjoint regions.
-MBErrorCode generate_mesh( MBInterface& moab, int intervals );
+ErrorCode generate_mesh( Interface& moab, int intervals );
 
 const char args[] = "[-i <intervals>] [-o <filename>] [-g <filename>]";
 void help() {
@@ -155,9 +157,9 @@
     // Create mesh
 TPRINT("Generating mesh");
   double gen_time = MPI_Wtime();
-  MBCore mb;
-  MBInterface& moab = mb;
-  MBErrorCode rval = generate_mesh( moab, intervals );
+  Core mb;
+  Interface& moab = mb;
+  ErrorCode rval = generate_mesh( moab, intervals );
   if (MB_SUCCESS != rval) {
     std::cerr << "Mesh creation failed with error code: " << rval << std::endl;
     return (int)rval;
@@ -180,15 +182,15 @@
   }
 
   double res_time = MPI_Wtime();
-  MBRange hexes;
+  Range hexes;
   moab.get_entities_by_type( 0, MBHEX, hexes );
   if (!skip_resolve_shared) {
 TPRINT("Resolving shared entities");
       // Negotiate shared entities using vertex global IDs
-    MBParallelComm* pcomm = new MBParallelComm( &moab );
+    ParallelComm* pcomm = new ParallelComm( &moab );
     rval = pcomm->resolve_shared_ents( 0, hexes, 3, 0 );
     if (MB_SUCCESS != rval) {
-      std::cerr << "MBParallelComm::resolve_shared_ents failed" << std::endl;
+      std::cerr << "ParallelComm::resolve_shared_ents failed" << std::endl;
       return rval;
     }
   }
@@ -234,14 +236,14 @@
 
 #define IDX(i,j,k) ((num_interval+1)*((num_interval+1)*(k) + (j)) + (i))
 
-MBErrorCode generate_mesh( MBInterface& moab, int num_interval )
+ErrorCode generate_mesh( Interface& moab, int num_interval )
 {
   int rank, size;
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
   MPI_Comm_size( MPI_COMM_WORLD, &size );
   
-  MBErrorCode rval;
-  MBTag global_id;
+  ErrorCode rval;
+  Tag global_id;
   rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, global_id );
   if (MB_SUCCESS != rval)
     return rval;
@@ -276,15 +278,15 @@
   const int y_offset = my_y_block * num_interval;
   const int z_offset = my_z_block * num_interval;
   double step = 1.0 / num_interval;
-  std::vector<MBEntityHandle> vertices( (num_interval+1)*(num_interval+1)*(num_interval+1) );
-  std::vector<MBEntityHandle>::iterator v = vertices.begin();
+  std::vector<EntityHandle> vertices( (num_interval+1)*(num_interval+1)*(num_interval+1) );
+  std::vector<EntityHandle>::iterator v = vertices.begin();
   for (int k = 0; k <= num_interval; ++k) {
     for (int j = 0; j <= num_interval; ++j) {
       for (int i = 0; i <= num_interval; ++i) {
         double coords[] = { my_x_block + i*step,
                             my_y_block + j*step,
                             my_z_block + k*step };
-        MBEntityHandle h;
+        EntityHandle h;
         rval = moab.create_vertex( coords, h );
         if (MB_SUCCESS != rval)
           return rval;
@@ -307,7 +309,7 @@
     for (int j = 0; j < num_interval; ++j) {
       for (int i = 0; i < num_interval; ++i) {
         assert( IDX(i+1,j+1,k+1) < (int)vertices.size() );
-        const MBEntityHandle conn[] = { vertices[IDX(i,  j,  k  )],
+        const EntityHandle conn[] = { vertices[IDX(i,  j,  k  )],
                                         vertices[IDX(i+1,j,  k  )],
                                         vertices[IDX(i+1,j+1,k  )],
                                         vertices[IDX(i,  j+1,k  )],
@@ -315,7 +317,7 @@
                                         vertices[IDX(i+1,j,  k+1)],
                                         vertices[IDX(i+1,j+1,k+1)],
                                         vertices[IDX(i,  j+1,k+1)] };
-        MBEntityHandle elem;
+        EntityHandle elem;
         rval = moab.create_element( MBHEX, conn, 8, elem );
         if (MB_SUCCESS != rval)
           return rval;
@@ -326,9 +328,9 @@
     // create interface quads 
   for (int j = 0; j < num_interval; ++j) {
     for (int i = 0; i < num_interval; ++i) {
-      MBEntityHandle h;
+      EntityHandle h;
 
-      const MBEntityHandle conn1[] = { vertices[IDX(i,  j,  0)],
+      const EntityHandle conn1[] = { vertices[IDX(i,  j,  0)],
                                        vertices[IDX(i+1,j,  0)],
                                        vertices[IDX(i+1,j+1,0)],
                                        vertices[IDX(i,  j+1,0)] };
@@ -336,7 +338,7 @@
       if (MB_SUCCESS != rval)
         return rval;
 
-      const MBEntityHandle conn2[] = { vertices[IDX(i,  j,  num_interval)],
+      const EntityHandle conn2[] = { vertices[IDX(i,  j,  num_interval)],
                                        vertices[IDX(i+1,j,  num_interval)],
                                        vertices[IDX(i+1,j+1,num_interval)],
                                        vertices[IDX(i,  j+1,num_interval)] };
@@ -347,9 +349,9 @@
   }
   for (int k = 0; k < num_interval; ++k) {
     for (int i = 0; i < num_interval; ++i) {
-      MBEntityHandle h;
+      EntityHandle h;
 
-      const MBEntityHandle conn1[] = { vertices[IDX(i,  0,k  )],
+      const EntityHandle conn1[] = { vertices[IDX(i,  0,k  )],
                                        vertices[IDX(i+1,0,k  )],
                                        vertices[IDX(i+1,0,k+1)],
                                        vertices[IDX(i,  0,k+1)] };
@@ -357,7 +359,7 @@
       if (MB_SUCCESS != rval)
         return rval;
 
-      const MBEntityHandle conn2[] = { vertices[IDX(i,  num_interval,k  )],
+      const EntityHandle conn2[] = { vertices[IDX(i,  num_interval,k  )],
                                        vertices[IDX(i+1,num_interval,k  )],
                                        vertices[IDX(i+1,num_interval,k+1)],
                                        vertices[IDX(i,  num_interval,k+1)] };
@@ -368,9 +370,9 @@
   }
   for (int k = 0; k < num_interval; ++k) {
     for (int j = 0; j < num_interval; ++j) {
-      MBEntityHandle h;
+      EntityHandle h;
 
-      const MBEntityHandle conn1[] = { vertices[IDX(0,j,  k  )],
+      const EntityHandle conn1[] = { vertices[IDX(0,j,  k  )],
                                        vertices[IDX(0,j+1,k  )],
                                        vertices[IDX(0,j+1,k+1)],
                                        vertices[IDX(0,j,  k+1)] };
@@ -378,7 +380,7 @@
       if (MB_SUCCESS != rval)
         return rval;
 
-      const MBEntityHandle conn2[] = { vertices[IDX(num_interval,j,  k  )],
+      const EntityHandle conn2[] = { vertices[IDX(num_interval,j,  k  )],
                                        vertices[IDX(num_interval,j+1,k  )],
                                        vertices[IDX(num_interval,j+1,k+1)],
                                        vertices[IDX(num_interval,j,  k+1)] };

Modified: MOAB/trunk/test/parallel/pcomm_serial.cpp
===================================================================
--- MOAB/trunk/test/parallel/pcomm_serial.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/pcomm_serial.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,14 @@
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
 #include "FileOptions.hpp"
 #include "ReadParallel.hpp"
 #include "TestUtil.hpp"
 #include <vector>
 
+using namespace moab;
+
 void print_usage(char *argv) 
 {
   std::cout << "Usage: " << argv << " nprocs filename" << std::endl;
@@ -46,11 +48,11 @@
     return 1;
   }
   
-  MBErrorCode rval;
-  MBCore *moab = new MBCore[nprocs]();
-  std::vector<MBParallelComm *> pc(nprocs);
+  ErrorCode rval;
+  Core *moab = new Core[nprocs]();
+  std::vector<ParallelComm *> pc(nprocs);
   for (int i = 0; i < nprocs; i++) {
-    pc[i] = new MBParallelComm(&moab[i]);
+    pc[i] = new ParallelComm(&moab[i]);
     pc[i]->set_rank(i);
     pc[i]->set_size(nprocs);
   }
@@ -77,15 +79,15 @@
     CHECK_ERR(rval);
   }
   
-  rval = MBParallelComm::resolve_shared_ents(&pc[0], nprocs, 3);
+  rval = ParallelComm::resolve_shared_ents(&pc[0], nprocs, 3);
   CHECK_ERR(rval);
 
     // exchange interface cells
-  rval = MBParallelComm::exchange_ghost_cells(&pc[0], nprocs, -1, -1, 0, true);
+  rval = ParallelComm::exchange_ghost_cells(&pc[0], nprocs, -1, -1, 0, true);
   CHECK_ERR(rval);
   
     // now 1 layer of hex ghosts
-  rval = MBParallelComm::exchange_ghost_cells(&pc[0], nprocs, 3, 2, 1, true);
+  rval = ParallelComm::exchange_ghost_cells(&pc[0], nprocs, 3, 2, 1, true);
   CHECK_ERR(rval);
 
   for (int i = 0; i < nprocs; i++)

Modified: MOAB/trunk/test/parallel/pcomm_unit.cpp
===================================================================
--- MOAB/trunk/test/parallel/pcomm_unit.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/pcomm_unit.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,8 @@
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "ReadParallel.hpp"
 #include "FileOptions.hpp"
 #include "TestUtil.hpp"
@@ -11,8 +11,10 @@
 #include <set>
 #include <sstream>
 
+using namespace moab;
+
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 
 #define STRINGIFY_(X) #X
@@ -83,25 +85,25 @@
 }
 
 /* Utility method: pack mesh data, clear moab instance, and unpack */
-void pack_unpack_noremoteh( MBCore& moab, MBRange& entities )
+void pack_unpack_noremoteh( Core& moab, Range& entities )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   if (entities.empty()) {
     rval = moab.get_entities_by_handle( 0, entities );
     CHECK_ERR(rval);
   }
   
-  MBParallelComm *pcomm = new MBParallelComm( &moab );
+  ParallelComm *pcomm = new ParallelComm( &moab );
   std::vector<int> addl_procs;
 
     // get the necessary vertices too
-  MBRange tmp_range = entities.subset_by_type(MBENTITYSET);
+  Range tmp_range = entities.subset_by_type(MBENTITYSET);
   entities = subtract( entities, tmp_range);
-  rval = moab.get_adjacencies(entities, 0, false, entities, MBInterface::UNION);
+  rval = moab.get_adjacencies(entities, 0, false, entities, Interface::UNION);
   CHECK_ERR(rval);
   entities.merge(tmp_range);
   
-  MBParallelComm::Buffer buff(MBParallelComm::INITIAL_BUFF_SIZE);
+  ParallelComm::Buffer buff(ParallelComm::INITIAL_BUFF_SIZE);
   buff.reset_ptr(sizeof(int));
   rval = pcomm->pack_buffer( entities, false, true, false, 
                              -1, &buff);
@@ -109,15 +111,15 @@
   buff.set_stored_size();
   
   delete pcomm;
-  moab.~MBCore();
+  moab.~Core();
 
-  new (&moab) MBCore();
-  pcomm = new MBParallelComm( &moab);
+  new (&moab) Core();
+  pcomm = new ParallelComm( &moab);
   
   entities.clear();
-  std::vector<std::vector<MBEntityHandle> > L1hloc, L1hrem;
+  std::vector<std::vector<EntityHandle> > L1hloc, L1hrem;
   std::vector<std::vector<int> > L1p;
-  std::vector<MBEntityHandle> L2hloc, L2hrem;
+  std::vector<EntityHandle> L2hloc, L2hrem;
   std::vector<unsigned int> L2p;
   buff.reset_ptr(sizeof(int));
   rval = pcomm->unpack_buffer(buff.buff_ptr, false, -1, -1, L1hloc, L1hrem, L1p, L2hloc, 
@@ -126,14 +128,14 @@
 
   delete pcomm;
 }
-void pack_unpack_noremoteh( MBCore& moab )
+void pack_unpack_noremoteh( Core& moab )
 {
-  MBRange empty;
+  Range empty;
   pack_unpack_noremoteh( moab, empty );
 }
 
 /* Utility method -- check expected sizes */
-void check_sizes( MBInterface& moab,
+void check_sizes( Interface& moab,
                   int num_vtx,
                   int num_edge,
                   int num_tri,
@@ -147,7 +149,7 @@
                   int num_polyhedron )
 {
   int count;
-  MBErrorCode rval;
+  ErrorCode rval;
   
   rval = moab.get_number_entities_by_type( 0, MBVERTEX, count );
   CHECK_ERR(rval);
@@ -195,15 +197,15 @@
 }
 
 /* Create a simple mesh for use in tests */
-void create_simple_grid( MBInterface& moab, unsigned x, unsigned y, unsigned z );
-void create_simple_grid( MBInterface& moab, unsigned xyz = 3 )
+void create_simple_grid( Interface& moab, unsigned x, unsigned y, unsigned z );
+void create_simple_grid( Interface& moab, unsigned xyz = 3 )
 {
   create_simple_grid( moab, xyz, xyz, xyz );
 }
-void create_simple_grid( MBInterface& moab, unsigned x, unsigned y, unsigned z )
+void create_simple_grid( Interface& moab, unsigned x, unsigned y, unsigned z )
 {
-  MBErrorCode rval;
-  MBEntityHandle *verts = new MBEntityHandle[x*y*z];
+  ErrorCode rval;
+  EntityHandle *verts = new EntityHandle[x*y*z];
   for (unsigned k = 0; k < z; ++k)
     for (unsigned j = 0; j < y; ++j)
       for (unsigned i = 0; i < x; ++i) {
@@ -212,12 +214,12 @@
         CHECK_ERR(rval);
       }
   
-  MBEntityHandle *elems = new MBEntityHandle[(x-1)*(y-1)*(z-1)];
+  EntityHandle *elems = new EntityHandle[(x-1)*(y-1)*(z-1)];
   for (unsigned k = 0; k < (z-1); ++k)
     for (unsigned j = 0; j < (y-1); ++j)
       for (unsigned i = 0; i < (x-1); ++i) {
         const size_t idx = (size_t)i + (size_t)j*x + (size_t)k*x*y; 
-        const MBEntityHandle conn[8] = { verts[idx        ],
+        const EntityHandle conn[8] = { verts[idx        ],
                                          verts[idx      +1],
                                          verts[idx    +x+1],
                                          verts[idx    +x  ],
@@ -232,13 +234,13 @@
   delete [] elems;
 }
 
-MBErrorCode create_patch(MBInterface *moab, MBRange &verts, MBRange &quads,
+ErrorCode create_patch(Interface *moab, Range &verts, Range &quads,
                          unsigned int n, double *xyz, int *gids) 
 {
     // create vertices/quads in square array
-  MBErrorCode result = moab->create_vertices(xyz, n*n, verts);
+  ErrorCode result = moab->create_vertices(xyz, n*n, verts);
   if (MB_SUCCESS != result) return result;
-  std::vector<MBEntityHandle> connect;
+  std::vector<EntityHandle> connect;
   for (unsigned int j = 0; j < n-1; j++) {
     for (unsigned int i = 0; i < n-1; i++) {
       connect.push_back(verts[n*j+i]);
@@ -250,14 +252,14 @@
   
   unsigned int nquads = (n-1)*(n-1);
   for (unsigned int i = 0; i < nquads; i++) {
-    MBEntityHandle dum_quad;
+    EntityHandle dum_quad;
     result = moab->create_element(MBQUAD, &connect[4*i], 4, dum_quad);
     if (MB_SUCCESS != result) return result;
     quads.insert(dum_quad);
   }
   
     // global ids
-  MBTag gid_tag;
+  Tag gid_tag;
   int dum_default = -1;
   result = moab->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE,
                            MB_TYPE_INTEGER, gid_tag, &dum_default, true);
@@ -268,7 +270,7 @@
   return result;
 }
 
-MBErrorCode create_shared_grid_2d(MBParallelComm **pc, MBRange *verts, MBRange *quads) 
+ErrorCode create_shared_grid_2d(ParallelComm **pc, Range *verts, Range *quads) 
 {
 //          
 //        P2______
@@ -319,13 +321,13 @@
     create_patch(pc[i]->get_moab(), verts[i], quads[i], 3, xyztmp, &gids[9*i]);
   }
 
-  MBErrorCode rval = MBParallelComm::resolve_shared_ents(pc, 4, 2);
+  ErrorCode rval = ParallelComm::resolve_shared_ents(pc, 4, 2);
   CHECK_ERR(rval);
 
   return rval;
 }
 
-MBErrorCode create_shared_grid_3d(MBParallelComm **pc, MBRange *verts, MBRange *hexes) 
+ErrorCode create_shared_grid_3d(ParallelComm **pc, Range *verts, Range *hexes) 
 {
 //    
 //   4 _____   _____ 
@@ -364,8 +366,8 @@
     
   std::vector<int> gids;
   std::vector<double> xyz;
-  MBErrorCode rval;
-  MBTag gid_tag;
+  ErrorCode rval;
+  Tag gid_tag;
   int dum_default = -1;
 
   for (p = 0; p < P; p++) {
@@ -403,7 +405,7 @@
 
       // make elements
     nv = 0;
-    MBEntityHandle connect[8], dum_hex;
+    EntityHandle connect[8], dum_hex;
     for (k = ijkmin[p][2]; k < ijkmax[p][2]; k++) 
       for (j = ijkmin[p][1]; j < ijkmax[p][1]; j++) 
         for (i = ijkmin[p][0]; i < ijkmax[p][0]; i++) {
@@ -428,16 +430,16 @@
     rval = pc[p]->get_moab()->write_file(fname.str().c_str());
     if (MB_SUCCESS != rval) return rval;
   }
-  rval = MBParallelComm::resolve_shared_ents(pc, 4, 3);
+  rval = ParallelComm::resolve_shared_ents(pc, 4, 3);
   CHECK_ERR(rval);
   return rval;
 }
 
 void test_pack_vertices()
 {
-  MBCore moab;
-  MBErrorCode rval;
-  MBRange verts;
+  Core moab;
+  ErrorCode rval;
+  Range verts;
   
   const size_t num_verts = 4;
   const double coords[3*num_verts] = { -0.5, -1./3, 0.0,
@@ -471,13 +473,13 @@
 
 void test_pack_elements()
 {
-  MBCore moab;
-  MBErrorCode rval;
-  MBRange elems;
+  Core moab;
+  ErrorCode rval;
+  Range elems;
   
     // define some vertices
   const size_t num_verts = 12;
-  MBEntityHandle verts[num_verts];
+  EntityHandle verts[num_verts];
   const double hex_corners[3*num_verts] = { -1, -1, -1,
                                              1, -1, -1,
                                              1,  1, -1,
@@ -497,7 +499,7 @@
   
     // define two adjacent hexes
   const size_t num_hex = 2;
-  MBEntityHandle hexes[num_hex];
+  EntityHandle hexes[num_hex];
   rval = moab.create_element( MBHEX, verts, 8, hexes[0] );
   CHECK_ERR(rval);
   elems.insert( hexes[0] );
@@ -507,15 +509,15 @@
   
     // define a single quad on the adjacent sides of the hexes
   const size_t num_quad = 1;
-  MBEntityHandle quad;
+  EntityHandle quad;
   rval = moab.create_element( MBQUAD, verts+4, 4, quad );
   CHECK_ERR(rval);
   elems.insert( quad );
   
     // define a decomposition of the first hex into 5 tets
   const size_t num_tet = 5;
-  MBEntityHandle tets[num_tet];
-  MBEntityHandle tet_conn[num_tet][4] = 
+  EntityHandle tets[num_tet];
+  EntityHandle tet_conn[num_tet][4] = 
                                { { verts[0], verts[1], verts[3], verts[4] },
                                  { verts[1], verts[2], verts[3], verts[6] },
                                  { verts[1], verts[3], verts[4], verts[6] },
@@ -540,8 +542,8 @@
     // define the 4 shared faces of the above tets as tris
     // (the faces of the 3rd tet)
   const size_t num_tri = 4;
-  MBEntityHandle tris[num_tri];
-  MBEntityHandle tri_conn[num_tri][3] = { { verts[3], verts[1], verts[4] },
+  EntityHandle tris[num_tri];
+  EntityHandle tri_conn[num_tri][3] = { { verts[3], verts[1], verts[4] },
                                           { verts[1], verts[6], verts[4] },
                                           { verts[1], verts[3], verts[6] },
                                           { verts[3], verts[4], verts[6] } };
@@ -560,8 +562,8 @@
   
     // define a decomposition of the second hex into two wedges
   const size_t num_wedge = 2;
-  MBEntityHandle wedges[num_wedge];
-  MBEntityHandle wedge_conn[num_wedge][6] = {
+  EntityHandle wedges[num_wedge];
+  EntityHandle wedge_conn[num_wedge][6] = {
     { verts[4], verts[5], verts[7], verts[8], verts[9], verts[11] },
     { verts[5], verts[6], verts[7], verts[9], verts[10],verts[11] } };
   rval = moab.create_element( MBPRISM, wedge_conn[0], 6, wedges[0] );
@@ -572,7 +574,7 @@
   elems.insert( wedges[1] );
   
     // define a pyramid
-  MBEntityHandle pyr;
+  EntityHandle pyr;
   rval = moab.create_element( MBPYRAMID, verts, 5, pyr );
   CHECK_ERR(rval);
   elems.insert( pyr );
@@ -585,8 +587,8 @@
                      num_tet, 1, num_wedge, 0, num_hex, 0 );
 
     // get connectivity for two hexes and a quad
-  MBRange range;
-  const MBEntityHandle *conn1, *conn2, *conn3;
+  Range range;
+  const EntityHandle *conn1, *conn2, *conn3;
   int len1, len2, len3;
   rval = moab.get_entities_by_type( 0, MBHEX, range );
   CHECK_ERR(rval);
@@ -621,7 +623,7 @@
   CHECK_EQUAL( conn1[6], conn3[2] );
   CHECK_EQUAL( conn1[7], conn3[3] );
     // Check coordinates
-  const MBEntityHandle combined[12] = { conn1[0], conn1[1], conn1[2], conn1[3],
+  const EntityHandle combined[12] = { conn1[0], conn1[1], conn1[2], conn1[3],
                                         conn3[0], conn3[1], conn3[2], conn3[3],
                                         conn2[4], conn2[5], conn2[6], conn2[7] };
   double coords[36];
@@ -634,9 +636,9 @@
 
 void test_pack_higher_order()
 {
-  MBCore moab;
-  MBErrorCode rval;
-  MBRange elems;
+  Core moab;
+  ErrorCode rval;
+  Range elems;
   
     // define coordinates for a pyramid decomposed
     // into two 10-node tets
@@ -655,7 +657,7 @@
                                       .5, -.5, .5,
                                       .5,  .5, .5,
                                      -.5,  .5, .5 };
-  MBEntityHandle verts[num_vert];
+  EntityHandle verts[num_vert];
   for (size_t i = 0; i < num_vert; ++i) {
     rval = moab.create_vertex( coords + 3*i, verts[i] );
     CHECK_ERR(rval);
@@ -663,7 +665,7 @@
   
     // define two tets
   const size_t num_tet = 2;
-  MBEntityHandle tet_conn[2][10] = {
+  EntityHandle tet_conn[2][10] = {
    { verts[ 0], verts[ 4], verts[ 9], verts[2],
      verts[ 8], verts[12], verts[10],
      verts[ 1], verts[ 3], verts[11] }, 
@@ -671,7 +673,7 @@
      verts[10], verts[12], verts[ 8],
      verts[ 7], verts[13], verts[ 5] } };
      
-  MBEntityHandle tets[num_tet];
+  EntityHandle tets[num_tet];
   rval = moab.create_element( MBTET, tet_conn[0], 10, tets[0] );
   CHECK_ERR(rval);
   elems.insert( tets[0] );
@@ -681,10 +683,10 @@
    
     // define interior tri face
   const size_t num_tri = 1;
-  MBEntityHandle tri_conn[6] = 
+  EntityHandle tri_conn[6] = 
     { verts[0], verts[4], verts[9],
       verts[8], verts[12],verts[10] };
-  MBEntityHandle tri;
+  EntityHandle tri;
   rval = moab.create_element( MBTRI, tri_conn, 6, tri );
   CHECK_ERR(rval);
   elems.insert( tri );
@@ -696,8 +698,8 @@
   check_sizes( moab, num_vert, 0, num_tri, 0, 0, num_tet, 0, 0, 0, 0, 0 );
 
     // get connectivity for two tets and a tri
-  MBRange range;
-  const MBEntityHandle *conn1, *conn2, *conn3;
+  Range range;
+  const EntityHandle *conn1, *conn2, *conn3;
   int len1, len2, len3;
   rval = moab.get_entities_by_type( 0, MBTET, range );
   CHECK_ERR(rval);
@@ -737,7 +739,7 @@
   CHECK_EQUAL( conn1[6], conn3[5] );
   
     // order vertex handles corresponding to original coordinate list
-  const MBEntityHandle combined[num_vert] = {
+  const EntityHandle combined[num_vert] = {
     conn1[0], 
     conn1[7],
     conn1[3],
@@ -765,9 +767,9 @@
 
 void test_pack_poly()
 {
-  MBCore moab;
-  MBErrorCode rval;
-  MBRange elems;
+  Core moab;
+  ErrorCode rval;
+  Range elems;
   
     // define a pyramid w/ a octagonal base
   const double a = 0.5;
@@ -783,7 +785,7 @@
     -b,  a, 0,
     -b, -a, 0,
      0,  0, 1 };
-  MBEntityHandle verts[num_vert];
+  EntityHandle verts[num_vert];
   for (size_t i = 0; i < num_vert; ++i) {
     rval = moab.create_vertex( coords + 3*i, verts[i] );
     CHECK_ERR(rval);
@@ -791,23 +793,23 @@
   
     // define octagonal base
   const size_t num_polygon = 1;
-  MBEntityHandle octagon;
+  EntityHandle octagon;
   rval = moab.create_element( MBPOLYGON, verts, 8, octagon );
   CHECK_ERR(rval);
   
     // define triangular sides
   const size_t num_tri = num_vert-1;
-  MBEntityHandle tri[num_tri];
+  EntityHandle tri[num_tri];
   for (size_t i = 0; i < num_tri; ++i) {
-    const MBEntityHandle conn[3] = { verts[i], verts[(i+1)%num_tri], verts[num_tri] };
+    const EntityHandle conn[3] = { verts[i], verts[(i+1)%num_tri], verts[num_tri] };
     rval = moab.create_element( MBTRI, conn, 3, tri[i] );
     CHECK_ERR(rval);
   }
   
     // define the octagon-based pyramid
   const size_t num_polyhedron = 1;
-  MBEntityHandle polyhedron;
-  MBEntityHandle all_faces[num_vert];
+  EntityHandle polyhedron;
+  EntityHandle all_faces[num_vert];
   all_faces[0] = octagon;
   std::copy( tri, tri+num_tri, all_faces+1 );
   rval = moab.create_element( MBPOLYHEDRON, all_faces, num_vert, polyhedron );
@@ -817,7 +819,7 @@
   elems.clear();
   elems.insert( polyhedron );
   elems.insert( octagon );
-  std::copy( tri, tri+num_tri, mb_range_inserter(elems) );
+  std::copy( tri, tri+num_tri, range_inserter(elems) );
   pack_unpack_noremoteh( moab, elems );
   
     // check counts
@@ -825,7 +827,7 @@
                      0, 0, 0, 0, 0, num_polyhedron );
   
     // get entities
-  MBRange range;
+  Range range;
   rval = moab.get_entities_by_type( 0, MBPOLYHEDRON, range );
   CHECK_ERR(rval);
   CHECK_EQUAL( num_polyhedron, range.size() );
@@ -843,7 +845,7 @@
   CHECK_EQUAL( num_tri, range.size() );
   
     // check coords of octagon vertices
-  const MBEntityHandle* oct_conn;
+  const EntityHandle* oct_conn;
   int eight = 0;
   rval = moab.get_connectivity( octagon, oct_conn, eight );
   CHECK_ERR(rval);
@@ -856,24 +858,24 @@
   }
   
     // check faces of polyhedron
-  std::vector<MBEntityHandle> volconn;
+  std::vector<EntityHandle> volconn;
   rval = moab.get_connectivity( &polyhedron, 1, volconn );
   CHECK_ERR(rval);
   CHECK_EQUAL( num_tri + 1, volconn.size() );
   CHECK_EQUAL( volconn[0], octagon );
-  for (MBRange::iterator i = range.begin(); i != range.end(); ++i) {
+  for (Range::iterator i = range.begin(); i != range.end(); ++i) {
     CHECK( std::find(volconn.begin(), volconn.end(), *i) != volconn.end() );
   }
 }
 
 void test_pack_sets_simple()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
   create_simple_grid( moab, 3 );  
 
     // delete any existing sets
-  MBRange sets;
+  Range sets;
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   if (!sets.empty()) {
@@ -882,11 +884,11 @@
   }
   
     // get all entities
-  MBRange entities;
+  Range entities;
   rval = moab.get_entities_by_handle( 0, entities );
   CHECK_ERR(rval);
     // expect 8 elements and 27 vertices
-  CHECK_EQUAL( (MBEntityHandle)35, entities.size() );
+  CHECK_EQUAL( (EntityHandle)35, entities.size() );
   CHECK_EQUAL( 27u, entities.num_of_type( MBVERTEX ) );
   CHECK_EQUAL( 8u, entities.num_of_type( MBHEX ) );
   
@@ -897,7 +899,7 @@
     // 3) one with the other half of the elements, 
     // 4) one with a single vertex, 
     // 5) an empty set, 
-  MBEntityHandle all_set, half1_set, half2_set, vertex_set, empty_set;
+  EntityHandle all_set, half1_set, half2_set, vertex_set, empty_set;
   const unsigned int all_opt = MESHSET_SET | MESHSET_TRACK_OWNER,
                      half1_opt = MESHSET_SET,
                      half2_opt = MESHSET_SET,
@@ -919,7 +921,7 @@
   CHECK_ERR(rval);
   entities.insert( empty_set );
 
-  MBRange elems, verts, half;
+  Range elems, verts, half;
   rval = moab.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   rval = moab.get_entities_by_type( 0, MBHEX, elems );
@@ -936,7 +938,7 @@
   half.merge( elems.begin() += elems.size() / 2, elems.end() );
   rval = moab.add_entities( half2_set, half );
   CHECK_ERR(rval);
-  MBEntityHandle vert = verts.front();
+  EntityHandle vert = verts.front();
   rval = moab.add_entities( vertex_set, &vert, 1 );
   CHECK_ERR(rval);
   
@@ -954,13 +956,13 @@
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   
-  CHECK_EQUAL( (MBEntityHandle)27, verts.size() );
-  CHECK_EQUAL( (MBEntityHandle)8, elems.size() );
-  CHECK_EQUAL( (MBEntityHandle)5, sets.size() );
+  CHECK_EQUAL( (EntityHandle)27, verts.size() );
+  CHECK_EQUAL( (EntityHandle)8, elems.size() );
+  CHECK_EQUAL( (EntityHandle)5, sets.size() );
   
     // guess which is which
   empty_set = all_set = vertex_set = half1_set = half2_set = 0;
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
     int num_vtx, num_elem;
     rval = moab.get_number_entities_by_type( *i, MBVERTEX, num_vtx );
     CHECK_ERR(rval);
@@ -968,26 +970,26 @@
     CHECK_ERR(rval);
     if (num_vtx == 0) {
       if (num_elem == 0) {
-        CHECK_EQUAL( (MBEntityHandle)0, empty_set );
+        CHECK_EQUAL( (EntityHandle)0, empty_set );
         empty_set = *i;
       }
       else if (!half1_set) {
         half1_set = *i;
       }
       else {
-        CHECK_EQUAL( (MBEntityHandle)0, half2_set );
+        CHECK_EQUAL( (EntityHandle)0, half2_set );
         half2_set = *i;
       }
     }
     else if (num_vtx == 1) {
       CHECK_EQUAL( 0, num_elem );
-      CHECK_EQUAL( (MBEntityHandle)0, vertex_set );
+      CHECK_EQUAL( (EntityHandle)0, vertex_set );
       vertex_set = *i;
     }
     else {
       CHECK_EQUAL( 8, num_elem );
       CHECK_EQUAL( 27, num_vtx );
-      CHECK_EQUAL( (MBEntityHandle)0, all_set );
+      CHECK_EQUAL( (EntityHandle)0, all_set );
       all_set = *i;
     }
   }
@@ -1013,12 +1015,12 @@
 
 void test_pack_set_contents()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
   create_simple_grid( moab, 3 );  
 
     // delete any existing sets
-  MBRange sets;
+  Range sets;
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   if (!sets.empty()) {
@@ -1027,12 +1029,12 @@
   }
   
     // get all vertices
-  MBRange vertices;
+  Range vertices;
   rval = moab.get_entities_by_type( 0, MBVERTEX, vertices );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)27, vertices.size() );
+  CHECK_EQUAL( (EntityHandle)27, vertices.size() );
     // create meshset containing vertices
-  MBEntityHandle set;
+  EntityHandle set;
   rval = moab.create_meshset( MESHSET_SET, set );
   CHECK_ERR(rval);
   rval = moab.add_entities( set, vertices );
@@ -1040,7 +1042,7 @@
   
     // pack and unpack range containing only set handle.
     // Will fail unless we also pass in set contents explicitly
-  MBRange entities( vertices );
+  Range entities( vertices );
   entities.insert( set );
   pack_unpack_noremoteh( moab, entities );
   
@@ -1048,29 +1050,29 @@
   entities.clear();
   rval = moab.get_entities_by_type( 0, MBENTITYSET, entities );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)1, entities.size() );
+  CHECK_EQUAL( (EntityHandle)1, entities.size() );
   set = entities.front();
   
     // expect 27 vertices in mesh
   vertices.clear();
   rval = moab.get_entities_by_type( 0, MBVERTEX, vertices );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)27, vertices.size() );
+  CHECK_EQUAL( (EntityHandle)27, vertices.size() );
   
     // expect set to contain all 27 vertices
   vertices.clear();
   rval = moab.get_entities_by_type( set, MBVERTEX, vertices );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)27, vertices.size() );
+  CHECK_EQUAL( (EntityHandle)27, vertices.size() );
 }
 
 void test_pack_sets_of_sets()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
  
     // delete any existing sets
-  MBRange sets;
+  Range sets;
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   if (!sets.empty()) {
@@ -1080,7 +1082,7 @@
  
     // create three sets such that set2 contains set1, and set3 contains
     // both set1 and set2
-  MBEntityHandle set1, set2, set3;
+  EntityHandle set1, set2, set3;
   sets.clear();
   rval = moab.create_meshset( MESHSET_ORDERED, set1 );
   CHECK_ERR(rval);
@@ -1103,26 +1105,26 @@
   sets.clear();
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)3, sets.size() );
+  CHECK_EQUAL( (EntityHandle)3, sets.size() );
   
     // figure out which is which
   set1 = set2 = set3 = 0;
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
     int count;
     rval = moab.get_number_entities_by_type( *i, MBENTITYSET, count );
     CHECK_ERR(rval);
     CHECK( count >= 0 && count <= 2 );
     switch (count) {
       case 0:
-        CHECK_EQUAL( (MBEntityHandle)0, set1 );
+        CHECK_EQUAL( (EntityHandle)0, set1 );
         set1 = *i;
         break;
       case 1:
-        CHECK_EQUAL( (MBEntityHandle)0, set2 );
+        CHECK_EQUAL( (EntityHandle)0, set2 );
         set2 = *i;
         break;
       case 2:
-        CHECK_EQUAL( (MBEntityHandle)0, set3 );
+        CHECK_EQUAL( (EntityHandle)0, set3 );
         set3 = *i;
         break;
     }
@@ -1131,13 +1133,13 @@
     // check that set2 contains set1
   sets.clear();
   rval = moab.get_entities_by_type( set2, MBENTITYSET, sets );
-  CHECK_EQUAL( (MBEntityHandle)1, sets.size() );
+  CHECK_EQUAL( (EntityHandle)1, sets.size() );
   CHECK_EQUAL( set1, sets.front() );
   
     // check that set3 contains set1 and set2
   sets.clear();
   rval = moab.get_entities_by_type( set3, MBENTITYSET, sets );
-  CHECK_EQUAL( (MBEntityHandle)2, sets.size() );
+  CHECK_EQUAL( (EntityHandle)2, sets.size() );
   if (sets.front() == set1) {
     CHECK_EQUAL( set2, sets.back() );
   }
@@ -1149,11 +1151,11 @@
 
 void test_pack_set_parent_child()
 {
-  MBCore moab;
-  MBErrorCode rval;
+  Core moab;
+  ErrorCode rval;
  
     // delete any existing sets
-  MBRange sets;
+  Range sets;
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
   if (!sets.empty()) {
@@ -1164,7 +1166,7 @@
     // create three sets such that set3 has a child link to
     // set1, set2 has a parent link to set1, and such that set3 and
     // set2 are parent and child, respectively.
-  MBEntityHandle set1, set2, set3;
+  EntityHandle set1, set2, set3;
   sets.clear();
   rval = moab.create_meshset( MESHSET_ORDERED, set1 );
   CHECK_ERR(rval);
@@ -1205,11 +1207,11 @@
   sets.clear();
   rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (MBEntityHandle)3, sets.size() );
+  CHECK_EQUAL( (EntityHandle)3, sets.size() );
   
     // look for a set with two child links (set3)
   set1 = set2 = set3 = 0;
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
     int count;
     rval = moab.num_child_meshsets( *i, &count );
     CHECK_ERR(rval);
@@ -1221,10 +1223,10 @@
   CHECK( 0 != set3 );
   
     // check set relations
-  std::vector<MBEntityHandle> parents, children;
+  std::vector<EntityHandle> parents, children;
   rval = moab.get_child_meshsets( set3, children );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (std::vector<MBEntityHandle>::size_type)2, children.size() );
+  CHECK_EQUAL( (std::vector<EntityHandle>::size_type)2, children.size() );
   set1 = children[0];
   set2 = children[1];
   rval = moab.get_parent_meshsets( set1, parents );
@@ -1236,23 +1238,23 @@
   CHECK( children.empty() );
   rval = moab.get_parent_meshsets( set2, parents );
   CHECK_ERR(rval);
-  CHECK_EQUAL( (std::vector<MBEntityHandle>::size_type)2, parents.size() );
+  CHECK_EQUAL( (std::vector<EntityHandle>::size_type)2, parents.size() );
   CHECK_EQUAL( set1, parents[0] );
   CHECK_EQUAL( set3, parents[1] );
 }
 
 void test_pack_tag_data_sparse()
 {
-  MBRange::iterator i;
+  Range::iterator i;
   int size;
-  MBDataType type;
-  MBTagType storage;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  DataType type;
+  TagType storage;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
   create_simple_grid( mb, 3 );  
-  MBRange elems;
+  Range elems;
   rval = mb.get_entities_by_type( 0, MBHEX, elems );
   CHECK_ERR(rval);
   CHECK( !elems.empty() );
@@ -1261,7 +1263,7 @@
     // in the mesh, set the tag value to the floor of the x and y
     // coordinates of the first vertex in the elements connectivity list.
   const char sparse_2_int_tag_name[] = "test tag 1";
-  MBTag sparse_2_int_tag;
+  Tag sparse_2_int_tag;
   rval = mb.tag_create( sparse_2_int_tag_name,
                         2*sizeof(int),
                         MB_TAG_SPARSE,
@@ -1275,7 +1277,7 @@
     if (skip)
       continue;
     
-    const MBEntityHandle* conn =0;
+    const EntityHandle* conn =0;
     int len;
     rval = mb.get_connectivity( *i, conn, len );
     CHECK_ERR(rval);
@@ -1288,7 +1290,7 @@
   }
   
     // pack and unpack
-  MBRange ents;
+  Range ents;
   pack_unpack_noremoteh( moab, ents );
   elems.clear();
   rval = mb.get_entities_by_type( 0, MBHEX, elems );
@@ -1311,7 +1313,7 @@
   CHECK_EQUAL( MB_ENTITY_NOT_FOUND, rval );
   
     // check tag data for sparse_2_int_tag
-  MBRange tagged;
+  Range tagged;
   rval = mb.get_entities_by_type_and_tag( 0, MBHEX, 
                                           &sparse_2_int_tag, 0, 1,
                                           tagged );
@@ -1321,7 +1323,7 @@
     rval = mb.tag_get_data( sparse_2_int_tag, &*i, 1, intdata );
     CHECK_ERR(rval);
     
-    const MBEntityHandle* conn =0;
+    const EntityHandle* conn =0;
     int len;
     rval = mb.get_connectivity( *i, conn, len );
     CHECK_ERR(rval);
@@ -1337,16 +1339,16 @@
 
 void test_pack_tag_data_dense()
 {
-  MBRange::iterator i;
+  Range::iterator i;
   int size;
-  MBDataType type;
-  MBTagType storage;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  DataType type;
+  TagType storage;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
   create_simple_grid( mb, 3 );  
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
@@ -1355,7 +1357,7 @@
     // point value.  For each vertex, store the distance from the origin
     // in this tag.
   const char dense_1_double_tag_name[] = "test tag 2";
-  MBTag dense_1_double_tag;
+  Tag dense_1_double_tag;
   rval = mb.tag_create( dense_1_double_tag_name,
                         sizeof(double),
                         MB_TAG_DENSE,
@@ -1373,7 +1375,7 @@
   }
   
     // pack and unpack
-  MBRange ents;
+  Range ents;
   pack_unpack_noremoteh( moab, ents );
   verts.clear();
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
@@ -1410,16 +1412,16 @@
 
 void test_pack_tag_data_default_value()
 {
-  MBRange::iterator i;
+  Range::iterator i;
   int size;
-  MBDataType type;
-  MBTagType storage;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  DataType type;
+  TagType storage;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
   create_simple_grid( mb, 3 );  
-  MBRange verts, elems, sets;
+  Range verts, elems, sets;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
@@ -1430,23 +1432,23 @@
     // Define a dense, opaque tag with a default value of "DEFLT".
     // Set the tag on one element, one vertex,and one set to "TAGGD".
   const char dense_5_opaque_tag_name[] = "This is intentionally a very long tag name in an attempt to test for an arbitrary limitations on tag name length.";
-  MBTag dense_5_opaque_tag;
+  Tag dense_5_opaque_tag;
   rval = mb.tag_create( dense_5_opaque_tag_name,
                         5,
                         MB_TAG_DENSE,
                         dense_5_opaque_tag,
                         "DEFLT" );
   CHECK_ERR(rval);
-  MBEntityHandle set;
+  EntityHandle set;
   rval = mb.create_meshset( MESHSET_SET, set );
   CHECK_ERR(rval);
-  const MBEntityHandle handles[3] = { verts.front(), elems.front(), set };
+  const EntityHandle handles[3] = { verts.front(), elems.front(), set };
   const char data[] = "TAGGDTAGGDTAGGD";
   rval = mb.tag_set_data( dense_5_opaque_tag, handles, 3, data );
   CHECK_ERR(rval);
   
     // pack and unpack
-  MBRange ents;
+  Range ents;
   pack_unpack_noremoteh( moab, ents );
   elems.clear();
   verts.clear();
@@ -1507,21 +1509,21 @@
 
 void test_pack_bit_tag_data()
 {
-  MBRange::iterator i;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Range::iterator i;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create some mesh
   create_simple_grid( mb, 3 );  
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
  
     // Create a bit tag
   const char tag_name[] = "test bit";
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_create( tag_name, 3, MB_TAG_BIT, tag, 0 );
   CHECK_ERR(rval);
   
@@ -1541,7 +1543,7 @@
   }
   
     // pack and unpack
-  MBRange ents;
+  Range ents;
   pack_unpack_noremoteh( moab, ents );
   verts.clear();
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
@@ -1556,12 +1558,12 @@
   CHECK_ERR(rval);
   CHECK_EQUAL( 3, size );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_BIT, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_EQUAL( MB_TYPE_BIT, type );
 
@@ -1586,14 +1588,14 @@
 
 void test_pack_variable_length_tag()
 {
-  MBRange::iterator i;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Range::iterator i;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create some mesh
   create_simple_grid( mb, 3 );  
-  MBRange verts;
+  Range verts;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
@@ -1601,7 +1603,7 @@
     // create a variable-length tag 
   const char* tag_name = "var_int_tag";
   const int default_val[] = { 0xBEEF, 0xFEED, 0xDEAD, 0xBAD, 0xBEAD };
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_create_variable_length( tag_name, MB_TAG_DENSE, MB_TYPE_INTEGER,
                                         tag, default_val, sizeof(default_val) );
   CHECK_ERR(rval);
@@ -1636,12 +1638,12 @@
   rval = mb.tag_get_size( tag, size );
   CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, rval );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_DENSE, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_EQUAL( MB_TYPE_INTEGER, type );
 
@@ -1679,14 +1681,14 @@
 
 void test_pack_tag_handle_data()
 {
-  MBRange::iterator i;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Range::iterator i;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create some mesh
   create_simple_grid( mb, 3 );  
-  MBRange verts, elems;
+  Range verts, elems;
   rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
   CHECK_ERR(rval);
   CHECK( !verts.empty() );
@@ -1696,16 +1698,16 @@
  
     // create a tag
   const char* tag_name = "entity tag";
-  MBEntityHandle default_val[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-  MBTag tag;
-  rval = mb.tag_create( tag_name, 8*sizeof(MBEntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tag, &default_val );
+  EntityHandle default_val[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+  Tag tag;
+  rval = mb.tag_create( tag_name, 8*sizeof(EntityHandle), MB_TAG_SPARSE, MB_TYPE_HANDLE, tag, &default_val );
   CHECK_ERR(rval);
   
     // Store on each vertex the handles of the adjacent hexes, padded
     // with NULL handles.
-  MBEntityHandle tagdata[8*8];
+  EntityHandle tagdata[8*8];
   for (i = elems.begin(); i != elems.end(); ++i) {
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int len;
     rval = mb.get_connectivity( *i, conn, len );
     CHECK_ERR(rval);
@@ -1715,7 +1717,7 @@
     CHECK_ERR(rval);
     
     for (int j = 0; j < 8; ++j) {
-      MBEntityHandle* vdata = tagdata + 8*j;
+      EntityHandle* vdata = tagdata + 8*j;
       int idx = 0;
       while (vdata[idx]) {
         ++idx;
@@ -1741,26 +1743,26 @@
   int size;
   rval = mb.tag_get_size( tag, size );
   CHECK_ERR(rval);
-  CHECK_EQUAL( 8*sizeof(MBEntityHandle), (size_t)size );
+  CHECK_EQUAL( 8*sizeof(EntityHandle), (size_t)size );
   
-  MBTagType storage;
+  TagType storage;
   rval = mb.tag_get_type( tag, storage );
   CHECK_ERR(rval);
   CHECK_EQUAL( MB_TAG_SPARSE, storage );
   
-  MBDataType type;
+  DataType type;
   rval = mb.tag_get_data_type( tag, type );
   CHECK_EQUAL( MB_TYPE_HANDLE, type );
 
   rval = mb.tag_get_default_value( tag, tagdata );
   CHECK_ERR(rval);
   for (int j = 0; j < 8; ++j) {
-    CHECK_EQUAL( (MBEntityHandle)0, tagdata[j] );
+    CHECK_EQUAL( (EntityHandle)0, tagdata[j] );
   }
   
     // check tag values
   for (i = elems.begin(); i != elems.end(); ++i) {
-    const MBEntityHandle* conn;
+    const EntityHandle* conn;
     int len;
     rval = mb.get_connectivity( *i, conn, len );
     CHECK_ERR(rval);
@@ -1770,7 +1772,7 @@
     CHECK_ERR(rval);
     
     for (int j = 0; j < 8; ++j) {
-      MBEntityHandle* vdata = tagdata + 8*j;
+      EntityHandle* vdata = tagdata + 8*j;
       int idx = 0;
       while (vdata[idx] != *i) {
         ++idx;
@@ -1787,20 +1789,20 @@
     rval = mb.tag_get_data( tag, &*i, 1, tagdata );
     CHECK_ERR(rval);
     for (int j = 0; j < 8; ++j) {
-      CHECK_EQUAL( (MBEntityHandle)0, tagdata[j] );
+      CHECK_EQUAL( (EntityHandle)0, tagdata[j] );
     }
   }
 }
   
-MBErrorCode get_entities(MBInterface *mb,
-                         std::vector<MBEntityHandle> &ent_verts, 
+ErrorCode get_entities(Interface *mb,
+                         std::vector<EntityHandle> &ent_verts, 
                          int verts_per_entity, int dim, 
-                         MBRange &ents) 
+                         Range &ents) 
 {
   assert(!(ent_verts.size()%verts_per_entity));
   unsigned int num_ents = ent_verts.size() / verts_per_entity;
-  MBRange dum_ents;
-  MBErrorCode result;
+  Range dum_ents;
+  ErrorCode result;
   for (unsigned int i = 0; i < num_ents; i++) {
     result = mb->get_adjacencies(&ent_verts[verts_per_entity*i], verts_per_entity,
                                 dim, true, dum_ents);
@@ -1814,22 +1816,22 @@
   
 void test_pack_shared_entities_2d()
 {
-  MBCore moab[4];
-  MBParallelComm *pc[4];
+  Core moab[4];
+  ParallelComm *pc[4];
   for (unsigned int i = 0; i < 4; i++) {
-    pc[i] = new MBParallelComm(&moab[i]);
+    pc[i] = new ParallelComm(&moab[i]);
     pc[i]->set_rank(i);
   }
 
-  MBRange verts[4], quads[4];
-  MBErrorCode rval = create_shared_grid_2d(pc, verts, quads);
+  Range verts[4], quads[4];
+  ErrorCode rval = create_shared_grid_2d(pc, verts, quads);
 
     // exchange interface cells
-  rval = MBParallelComm::exchange_ghost_cells(pc, 4, -1, -1, 0, true);
+  rval = ParallelComm::exchange_ghost_cells(pc, 4, -1, -1, 0, true);
   CHECK_ERR(rval);
   
     // now 1 layer of hex ghosts
-  rval = MBParallelComm::exchange_ghost_cells(pc, 4, 2, 0, 1, true);
+  rval = ParallelComm::exchange_ghost_cells(pc, 4, 2, 0, 1, true);
   CHECK_ERR(rval);
 
   for (unsigned int i = 0; i < 4; i++)
@@ -1838,10 +1840,10 @@
 
 void test_pack_shared_entities_3d()
 {
-  MBCore moab[4];
-  MBParallelComm *pc[4];
+  Core moab[4];
+  ParallelComm *pc[4];
   for (unsigned int i = 0; i < 4; i++) {
-    pc[i] = new MBParallelComm(&moab[i]);
+    pc[i] = new ParallelComm(&moab[i]);
     pc[i]->set_rank(i);
     for (unsigned int j = 0; j < 4; j++) {
       if (j == i) continue;
@@ -1849,15 +1851,15 @@
     }
   }
 
-  MBRange verts[4], hexes[4];
-  MBErrorCode rval = create_shared_grid_3d(pc, verts, hexes);
+  Range verts[4], hexes[4];
+  ErrorCode rval = create_shared_grid_3d(pc, verts, hexes);
 
     // exchange interface cells
-  rval = MBParallelComm::exchange_ghost_cells(pc, 4, -1, -1, 0, true);
+  rval = ParallelComm::exchange_ghost_cells(pc, 4, -1, -1, 0, true);
   CHECK_ERR(rval);
   
     // now 1 layer of hex ghosts
-  rval = MBParallelComm::exchange_ghost_cells(pc, 4, 3, 0, 1, true);
+  rval = ParallelComm::exchange_ghost_cells(pc, 4, 3, 0, 1, true);
   CHECK_ERR(rval);
 
   for (unsigned int i = 0; i < 4; i++)
@@ -1866,15 +1868,15 @@
 
 void test_filter_pstatus()
 {
-  MBRange::iterator i;
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Range::iterator i;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   
     // create some mesh
   create_simple_grid( mb, 3 );  
-  std::vector<MBEntityHandle> verts;
-  MBRange dum_vertsr, vertsr;
+  std::vector<EntityHandle> verts;
+  Range dum_vertsr, vertsr;
   rval = mb.get_entities_by_type( 0, MBVERTEX, dum_vertsr );
   CHECK_ERR(rval);
   vertsr.insert(dum_vertsr[0], dum_vertsr[8]);
@@ -1882,7 +1884,7 @@
 
   CHECK( !verts.empty() );
  
-  MBParallelComm *pcomm = new MBParallelComm( &moab );
+  ParallelComm *pcomm = new ParallelComm( &moab );
 
   std::vector<int> procs(70, -1);
   for (unsigned int i = 0; i < 6; i++) procs[i] = i;
@@ -1919,7 +1921,7 @@
   CHECK_ERR(rval);
   
 
-  MBRange tmp_range = vertsr;
+  Range tmp_range = vertsr;
 
     // interface ents
   rval = pcomm->filter_pstatus(tmp_range, PSTATUS_INTERFACE, PSTATUS_AND);

Modified: MOAB/trunk/test/parallel/scdtest.cpp
===================================================================
--- MOAB/trunk/test/parallel/scdtest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/scdtest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,14 +3,14 @@
 #include <iostream>
 #include <cassert>
 
-#include <MBCore.hpp>
-#include <MBInterface.hpp>
-#include <MBParallelComm.hpp>
-#include <HomXform.hpp>
-#include <MBParallelConventions.h>
-#include <MBTagConventions.hpp>
+#include "moab/Core.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/HomXform.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/MBTagConventions.hpp"
 
 using namespace std;
+using namespace moab;
 
 // Number of cells in each direction:
 const int NC = 2;
@@ -26,8 +26,8 @@
 const double DSIZE = 10.0;
 
 // MOAB objects:
-MBInterface *mbint = NULL;
-MBParallelComm *mbpc = NULL;
+Interface *mbint = NULL;
+ParallelComm *mbpc = NULL;
 
 // Local domain starting and ending hex indexes:
 int is, js, ks;
@@ -40,7 +40,7 @@
 void set_local_domain_bounds();
 void create_hexes_and_verts();
 void resolve_and_exchange();
-void error(MBErrorCode err);
+void error(ErrorCode err);
 
 int main(int argc, char *argv[])
 {
@@ -52,8 +52,8 @@
     exit(1);
   }
   
-  mbint = new MBCore();
-  mbpc  = new MBParallelComm(mbint);
+  mbint = new Core();
+  mbpc  = new ParallelComm(mbint);
 
   set_local_domain_bounds();
   create_hexes_and_verts();
@@ -118,12 +118,12 @@
 
 void create_hexes_and_verts()
 {
-  MBCore *mbcore = dynamic_cast<MBCore*>(mbint);
+  Core *mbcore = dynamic_cast<Core*>(mbint);
   HomCoord coord_min(0,0,0);
   HomCoord coord_max(ie-is, je-js, ke-ks);
   EntitySequence* vertex_seq = NULL;
   EntitySequence* cell_seq = NULL;
-  MBEntityHandle vs, cs;
+  EntityHandle vs, cs;
 
   error(mbcore->create_scd_sequence(coord_min, coord_max, MBVERTEX, 1, vs, vertex_seq));
   error(mbcore->create_scd_sequence(coord_min, coord_max, MBHEX, 1, cs, cell_seq));
@@ -136,12 +136,12 @@
 
   // Set global id's:
   int gid;
-  MBTag global_id_tag;
+  Tag global_id_tag;
   error(mbint->tag_get_handle(GLOBAL_ID_TAG_NAME, global_id_tag));
-  MBEntityHandle handle = vs;
+  EntityHandle handle = vs;
   int i,j,k;
 
-  MBErrorCode err;
+  ErrorCode err;
 
   for(k = ks; k < ke + 1; k++)
     for(j = js; j < je + 1; j++)
@@ -167,20 +167,20 @@
 
 void resolve_and_exchange()
 {
-  MBEntityHandle entity_set;
+  EntityHandle entity_set;
 
   // Create the entity set:
   error(mbint->create_meshset(MESHSET_SET, entity_set));
 
   // Get a list of hexes:
-  MBRange range;
+  Range range;
   error(mbint->get_entities_by_type(0, MBHEX, range));
 
   // Add entities to the entity set:
   error(mbint->add_entities(entity_set, range));
 
   // Add the MATERIAL_SET tag to the entity set:
-  MBTag tag;
+  Tag tag;
   error(mbint->tag_get_handle(MATERIAL_SET_TAG_NAME, tag));
   error(mbint->tag_set_data(tag, &entity_set, 1, &rank));
 
@@ -196,7 +196,7 @@
   error(mbpc->exchange_ghost_cells(-1, 0, 1, true));
 }
 
-void error(MBErrorCode err)
+void error(ErrorCode err)
 {
   if(err != MB_SUCCESS) {
     cerr << "Error: MOAB function failed\n";

Modified: MOAB/trunk/test/parallel/uber_parallel_test.cpp
===================================================================
--- MOAB/trunk/test/parallel/uber_parallel_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/parallel/uber_parallel_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
 #include "ReadParallel.hpp"
 #include "FileOptions.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
-#include "MBmpi.h"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab_mpi.h"
 #include <iostream>
 #include <algorithm>
 #include <sstream>
@@ -14,12 +14,14 @@
 #endif
 
 
+using namespace moab;
+
 #define STRINGIFY_(X) #X
 #define STRINGIFY(X) STRINGIFY_(X)
 
 
 #define CHKERR(a) do { \
-  MBErrorCode val = (a); \
+  ErrorCode val = (a); \
   if (MB_SUCCESS != val) { \
     std::cerr << "Error code  " << val << " at " << __FILE__ << ":" << __LINE__ << std::endl;\
     return val; \
@@ -28,13 +30,13 @@
 
 #define PCHECK(A) if (is_any_proc_error(!(A))) return report_error(__FILE__,__LINE__)
 
-MBErrorCode report_error( const char* file, int line )
+ErrorCode report_error( const char* file, int line )
 {
   std::cerr << "Failure at " << file << ':' << line << std::endl;
   return MB_FAILURE;
 }
 
-MBErrorCode test_read(const char *filename, const char *option);
+ErrorCode test_read(const char *filename, const char *option);
 
 #define RUN_TEST(A, B, C) run_test( &A, #A, B, C)
 
@@ -45,12 +47,12 @@
   return err || result;
 }
 
-int run_test( MBErrorCode (*func)(const char*, const char*), 
+int run_test( ErrorCode (*func)(const char*, const char*), 
               const char* func_name,
               const char* file_name,
               const char *option)
 {
-  MBErrorCode result = (*func)(file_name, option);
+  ErrorCode result = (*func)(file_name, option);
   int is_err = is_any_proc_error( (MB_SUCCESS != result) );
   int rank;
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
@@ -120,16 +122,16 @@
   return num_errors;
 }
 
-MBErrorCode test_read(const char *filename, const char *option) 
+ErrorCode test_read(const char *filename, const char *option) 
 {
-  MBCore mb_instance;
-  MBInterface& moab = mb_instance;
-  MBErrorCode rval;
+  Core mb_instance;
+  Interface& moab = mb_instance;
+  ErrorCode rval;
 
   rval = moab.load_file( filename, 0, option);
   CHKERR(rval);
 
-  MBParallelComm* pcomm = MBParallelComm::get_pcomm(&moab, 0);
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&moab, 0);
 
   rval = pcomm->check_all_shared_handles();
   CHKERR(rval);

Modified: MOAB/trunk/test/perf/Makefile.am
===================================================================
--- MOAB/trunk/test/perf/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,7 @@
 
 AM_CPPFLAGS += -I$(top_srcdir)/src \
                -I$(top_srcdir)/src/io/mhdf/include \
-               -I$(top_builddir)/src \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_builddir)/src/moab
+               -I$(top_builddir)/src 
             
 LDADD = $(top_builddir)/src/libMOAB.la
 

Modified: MOAB/trunk/test/perf/adj_time.cpp
===================================================================
--- MOAB/trunk/test/perf/adj_time.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/adj_time.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include <iostream>
 #include <assert.h>
 #include <time.h>
 
+using namespace moab;
+
 #define STRINGIFY_(X) #X
 #define STRINGIFY(X) STRINGIFY_(X)
 #ifndef SRCDIR
@@ -14,9 +16,9 @@
 
 int main()
 {
-  MBErrorCode rval;
-  MBCore moab;
-  MBInterface& mb = moab;
+  ErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
   
     // load test file
   rval = mb.load_file( default_input_file );
@@ -26,7 +28,7 @@
   }
   
     // get all region elements
-  MBRange vols;
+  Range vols;
   rval = mb.get_entities_by_dimension( 0, 3, vols );
   if (MB_SUCCESS != rval)
     return 2;
@@ -34,16 +36,16 @@
     return 1;
   
     // create internal face elements
-  MBRange faces;
-  rval = mb.get_adjacencies( vols, 2, true, faces, MBInterface::UNION );
+  Range faces;
+  rval = mb.get_adjacencies( vols, 2, true, faces, Interface::UNION );
   if (MB_SUCCESS != rval)
     return 2;
   assert(faces.size() > vols.size());
   
     // time query of all adjacent volumes
-  std::vector<MBEntityHandle> adj;
+  std::vector<EntityHandle> adj;
   clock_t t_0 = clock();
-  for (MBRange::iterator i = faces.begin(); i != faces.end(); ++i) {
+  for (Range::iterator i = faces.begin(); i != faces.end(); ++i) {
     adj.clear();
     rval = mb.get_adjacencies( &*i, 1, 3, false, adj );
     if (MB_SUCCESS != rval)
@@ -56,7 +58,7 @@
   
     // time downward adjacency query from volumes to faces
   t_0 = clock();
-  for (MBRange::iterator i = vols.begin(); i != vols.end(); ++i) {
+  for (Range::iterator i = vols.begin(); i != vols.end(); ++i) {
     adj.clear();
     rval = mb.get_adjacencies( &*i, 1, 1, false, adj );
     if (MB_SUCCESS != rval)

Modified: MOAB/trunk/test/perf/cubit_perf.cpp
===================================================================
--- MOAB/trunk/test/perf/cubit_perf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/cubit_perf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -33,6 +33,8 @@
 #include "CubitNode.hpp"
 #include "NodeHex.hpp"
 
+using namespace moab;
+
 const double LENGTH = 1.0;
 
 extern "C" 

Modified: MOAB/trunk/test/perf/perf.cpp
===================================================================
--- MOAB/trunk/test/perf/perf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/perf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -33,18 +33,20 @@
 #include <stdio.h>
 #include <assert.h>
 #include <iostream>
-#include "MBCore.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Core.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "VertexSequence.hpp"
 #include "StructuredElementSeq.hpp"
 #include "EntitySequence.hpp"
 #include "SequenceManager.hpp"
-#include "HomXform.hpp"
+#include "moab/HomXform.hpp"
 
+using namespace moab;
+
 double LENGTH = 1.0;
 
 void testA(const int nelem, const double *coords);
-void testB(const int nelem, const double *coords, const MBEntityHandle *connect);
+void testB(const int nelem, const double *coords, const EntityHandle *connect);
 void testC(const int nelem, const double *coords);
 void print_time(const bool print_em, double &tot_time, double &utime, double &stime);
 void query_vert_to_elem();
@@ -239,13 +241,13 @@
             << std::endl;
 }
 
-void build_connect(const int nelem, const MBEntityHandle vstart, MBEntityHandle *&connect) 
+void build_connect(const int nelem, const EntityHandle vstart, EntityHandle *&connect) 
 {
     // allocate the memory
   int nume_tot = nelem*nelem*nelem;
-  connect = new MBEntityHandle[8*nume_tot];
+  connect = new EntityHandle[8*nume_tot];
 
-  MBEntityHandle vijk;
+  EntityHandle vijk;
   int numv = nelem + 1;
   int numv_sq = numv*numv;
   int idx = 0;
@@ -267,7 +269,7 @@
   }
 }
 
-MBInterface *gMB;
+Interface *gMB;
 int main(int argc, char* argv[])
 {
   int nelem = 20;
@@ -289,14 +291,14 @@
   std::cout << "number of elements: " << nelem << "; test " 
             << which_test << std::endl;
 
-  gMB = new MBCore();
+  gMB = new Core();
 
     // pre-build the coords array
   double *coords = NULL;
   build_coords(nelem, coords);
   assert(NULL != coords);
 
-  MBEntityHandle *connect = NULL;
+  EntityHandle *connect = NULL;
   build_connect(nelem, 1, connect);
 
   switch (which_test) {
@@ -321,12 +323,12 @@
 
 void query_elem_to_vert()
 {
-  MBRange all_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
-  const MBEntityHandle *connect;
+  Range all_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
+  const EntityHandle *connect;
   int num_connect;
   double dum_coords[24];
-  for (MBRange::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
+  for (Range::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
     result = gMB->get_connectivity(*eit, connect, num_connect);
     assert(MB_SUCCESS == result);
     result = gMB->get_coords(connect, num_connect, dum_coords);
@@ -344,11 +346,11 @@
 
 void query_vert_to_elem()
 {
-  MBRange all_verts;
-  std::vector<MBEntityHandle> neighbor_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBVERTEX, all_verts);
+  Range all_verts;
+  std::vector<EntityHandle> neighbor_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBVERTEX, all_verts);
   assert(MB_SUCCESS == result);
-  for (MBRange::iterator vit = all_verts.begin(); vit != all_verts.end(); vit++) {
+  for (Range::iterator vit = all_verts.begin(); vit != all_verts.end(); vit++) {
     neighbor_hexes.clear();
     result = gMB->get_adjacencies(&(*vit), 1, 3, false, neighbor_hexes);
     assert(MB_SUCCESS == result);
@@ -358,11 +360,11 @@
 void query_struct_elem_to_vert()
 {
     // assumes brick mapped mesh with handles starting at zero
-  MBRange all_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
+  Range all_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
   double dum_coords[24];
-  std::vector<MBEntityHandle> connect;
-  for (MBRange::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
+  std::vector<EntityHandle> connect;
+  for (Range::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
     result = gMB->get_connectivity(&(*eit), 1, connect);
     assert(MB_SUCCESS == result);
     result = gMB->get_coords(&connect[0], connect.size(), dum_coords);
@@ -410,12 +412,12 @@
   EntitySequence *dum_seq = NULL;
   ScdVertexData *vseq = NULL;
   StructuredElementSeq *eseq = NULL;
-  SequenceManager *seq_mgr = dynamic_cast<MBCore*>(gMB)->sequence_manager();
+  SequenceManager *seq_mgr = dynamic_cast<Core*>(gMB)->sequence_manager();
   HomCoord vseq_minmax[2] = {HomCoord(0,0,0), 
                              HomCoord(nelem, nelem, nelem)};
-  MBEntityHandle vstart, estart;
+  EntityHandle vstart, estart;
   
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq_minmax[0], vseq_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq_minmax[0], vseq_minmax[1],
                                                     MBVERTEX, 1, vstart, dum_seq);
   if (NULL != dum_seq) vseq = dynamic_cast<ScdVertexData*>(dum_seq->data());
   assert (MB_FAILURE != result && vstart != 0 && dum_seq != NULL && vseq != NULL);
@@ -432,7 +434,7 @@
   assert(MB_SUCCESS == result);
 
     // set the coordinates of the vertices
-  MBEntityHandle handle;
+  EntityHandle handle;
   int i;
   double dumv[3];
   int num_verts = (nelem + 1)*(nelem + 1)*(nelem + 1);
@@ -461,7 +463,7 @@
             << std::endl;
 }
 
-void testB(const int nelem, const double *coords, const MBEntityHandle *connect) 
+void testB(const int nelem, const double *coords, const EntityHandle *connect) 
 {
   double ttime0, ttime1, ttime2, ttime3, utime, stime;
   
@@ -469,17 +471,17 @@
 
   int num_verts = (nelem + 1)*(nelem + 1)*(nelem + 1);
   int num_elems = nelem*nelem*nelem;
-  MBEntityHandle vstart, estart;
+  EntityHandle vstart, estart;
 
   // get the read interface
   void* ptr = 0;
-  gMB->query_interface("MBReadUtilIface", &ptr);
-  MBReadUtilIface* readMeshIface = reinterpret_cast<MBReadUtilIface*>(ptr);
+  gMB->query_interface("ReadUtilIface", &ptr);
+  ReadUtilIface* readMeshIface = reinterpret_cast<ReadUtilIface*>(ptr);
   
   // create a sequence to hold the node coordinates
   // get the current number of entities and start at the next slot
   std::vector<double*> coord_arrays;
-  MBErrorCode result = readMeshIface->get_node_arrays(3, num_verts, 1, vstart, coord_arrays);
+  ErrorCode result = readMeshIface->get_node_arrays(3, num_verts, 1, vstart, coord_arrays);
   assert(MB_SUCCESS == result && 1 == vstart &&
          coord_arrays[0] && coord_arrays[1] && coord_arrays[2]);
     // memcpy the coordinate data into place
@@ -487,10 +489,10 @@
   memcpy(coord_arrays[1], &coords[num_verts], sizeof(double)*num_verts);
   memcpy(coord_arrays[2], &coords[2*num_verts], sizeof(double)*num_verts);
   
-  MBEntityHandle *conn = 0;
+  EntityHandle *conn = 0;
   result = readMeshIface->get_element_array(num_elems, 8, MBHEX, 1, estart, conn);
   assert(MB_SUCCESS == result);
-  memcpy(conn, connect, num_elems*8*sizeof(MBEntityHandle));
+  memcpy(conn, connect, num_elems*8*sizeof(EntityHandle));
   result = readMeshIface->update_adjacencies(estart, num_elems, 8, conn);
   assert(MB_SUCCESS == result);
 
@@ -525,12 +527,12 @@
   int numv_sq = numv*numv;
   int num_verts = numv*numv*numv;
   double dum_coords[3] = {coords[0], coords[num_verts], coords[2*num_verts]};
-  MBEntityHandle vstart;
+  EntityHandle vstart;
 
-  MBErrorCode result = gMB->create_vertex(dum_coords, vstart);
+  ErrorCode result = gMB->create_vertex(dum_coords, vstart);
   assert(MB_SUCCESS == result && 1 == vstart);
 
-  MBEntityHandle dum_vert, vijk;
+  EntityHandle dum_vert, vijk;
   int i;
   for (i = 1; i < num_verts; i++) {
     dum_coords[0] = coords[i]; 
@@ -540,7 +542,7 @@
     assert(MB_SUCCESS == result);
   }
 
-  MBEntityHandle dum_conn[8];
+  EntityHandle dum_conn[8];
   for (i=0; i < nelem; i++) {
     for (int j=0; j < nelem; j++) {
       for (int k=0; k < nelem; k++) {

Modified: MOAB/trunk/test/perf/point_in_elem.cpp
===================================================================
--- MOAB/trunk/test/perf/point_in_elem.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/point_in_elem.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,8 @@
-#include "MBCore.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBRange.hpp"
-#include "MBCartVect.hpp"
-#include "MBGeomUtil.hpp"
+#include "moab/Core.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/Range.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/GeomUtil.hpp"
 #include <iostream>
 #include <time.h>
 #include <stdlib.h>
@@ -10,8 +10,10 @@
 
 #define CHK(ErrorCode) do { if (MB_SUCCESS != (ErrorCode)) fail( (ErrorCode), __FILE__, __LINE__ ); } while(false)
 
-void fail( MBErrorCode error_code, const char* file_name, int line_number );
+using namespace moab;
 
+void fail( ErrorCode error_code, const char* file_name, int line_number );
+
 enum TreeType {  UseKDTree, UseNoTree, UseDefaultTree = UseKDTree };
 
 const char* default_str = "(default)";
@@ -45,18 +47,18 @@
   exit(0);
 }
 
-void generate_random_points( MBInterface& mesh, size_t num_points,
-                             std::vector<MBCartVect>& points,
-                             std::vector<MBEntityHandle>& point_elems );
+void generate_random_points( Interface& mesh, size_t num_points,
+                             std::vector<CartVect>& points,
+                             std::vector<EntityHandle>& point_elems );
 
-void do_kdtree_test( MBInterface& mesh, int tree_depth, int elem_per_leaf,
-                     long num_test, const std::vector<MBCartVect>& points,
-                     std::vector<MBEntityHandle>& point_elems,
+void do_kdtree_test( Interface& mesh, int tree_depth, int elem_per_leaf,
+                     long num_test, const std::vector<CartVect>& points,
+                     std::vector<EntityHandle>& point_elems,
                      clock_t& build_time, clock_t& test_time, size_t& depth );
 
-void do_linear_test( MBInterface& mesh, int tree_depth, int elem_per_leaf,
-                     long num_test, const std::vector<MBCartVect>& points,
-                     std::vector<MBEntityHandle>& point_elems,
+void do_linear_test( Interface& mesh, int tree_depth, int elem_per_leaf,
+                     long num_test, const std::vector<CartVect>& points,
+                     std::vector<EntityHandle>& point_elems,
                      clock_t& build_time, clock_t& test_time, size_t& depth );
 
 int main( int argc, char* argv[] )
@@ -113,9 +115,9 @@
   
     // LOAD MESH
     
-  MBCore moab;
-  MBInterface& mb = moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface& mb = moab;
+  ErrorCode rval;
   std::string init_msg, msg;
   mb.get_last_error( init_msg );
   rval = mb.load_file( input_file );
@@ -133,8 +135,8 @@
     num_unique = HARD_MAX_UNIQUE_POINTS;
   else if (num_unique < HARD_MIN_UNIQUE_POINTS)
     num_unique = num_points;
-  std::vector<MBCartVect> points;
-  std::vector<MBEntityHandle> elems;
+  std::vector<CartVect> points;
+  std::vector<EntityHandle> elems;
   generate_random_points( mb, num_unique, points, elems );
   
     // GET MEMORY USE BEFORE BUILDING TREE
@@ -145,7 +147,7 @@
     // RUN TIMING TEST
   clock_t build_time, test_time;
   size_t actual_depth;
-  std::vector<MBEntityHandle> results(points.size());
+  std::vector<EntityHandle> results(points.size());
   switch (type) {
     case UseKDTree: 
       do_kdtree_test( mb, tree_depth, elem_per_leaf, num_points, points, results, build_time, test_time, actual_depth );
@@ -181,7 +183,7 @@
 }
 
 
-void fail( MBErrorCode error_code, const char* file, int line )
+void fail( ErrorCode error_code, const char* file, int line )
 {
   std::cerr << "Internal error (error code " << error_code << ") at " << file << ":" << line << std::endl;
   abort();
@@ -196,16 +198,16 @@
                             {  1,  1,  1 },
                             { -1,  1,  1 } };
 
-MBCartVect random_point_in_hex( MBInterface& mb, MBEntityHandle hex )
+CartVect random_point_in_hex( Interface& mb, EntityHandle hex )
 {
   const double f = RAND_MAX/2;
-  MBCartVect xi( ((double)rand() - f)/f, 
+  CartVect xi( ((double)rand() - f)/f, 
                  ((double)rand() - f)/f, 
                  ((double)rand() - f)/f );
-  MBCartVect coords[8];
-  const MBEntityHandle* conn;
+  CartVect coords[8];
+  const EntityHandle* conn;
   int len;
-  MBErrorCode rval = mb.get_connectivity( hex, conn, len, true );
+  ErrorCode rval = mb.get_connectivity( hex, conn, len, true );
   if (len != 8 && MB_SUCCESS != rval) {
     std::cerr << "Invalid element" << std::endl;
     assert(false);
@@ -214,7 +216,7 @@
   rval = mb.get_coords( conn, 8, reinterpret_cast<double*>(coords) );
   CHK(rval);
   
-  MBCartVect point(0,0,0);
+  CartVect point(0,0,0);
   for (unsigned i = 0; i < 8; ++i) {
     double coeff = 0.125;
     for (unsigned j = 0; j < 3; ++j)
@@ -225,17 +227,17 @@
   return point;
 }
 
-void generate_random_points( MBInterface& mb, size_t num_points,
-                             std::vector<MBCartVect>& points,
-                             std::vector<MBEntityHandle>& point_elems )
+void generate_random_points( Interface& mb, size_t num_points,
+                             std::vector<CartVect>& points,
+                             std::vector<EntityHandle>& point_elems )
 {
-  MBRange elems;
-  MBErrorCode rval;
+  Range elems;
+  ErrorCode rval;
   rval = mb.get_entities_by_dimension( 0, 3, elems );
   CHK(rval);
   if (!elems.all_of_type(MBHEX)) {
     std::cerr << "Warning: ignoring non-hexahedral elements." << std::endl;
-    std::pair< MBRange::iterator, MBRange::iterator > p = elems.equal_range(MBHEX);
+    std::pair< Range::iterator, Range::iterator > p = elems.equal_range(MBHEX);
     elems.erase( p.second, elems.end() );
     elems.erase( elems.begin(), p.first );
   }
@@ -257,21 +259,21 @@
   }
 }
 
-void do_kdtree_test( MBInterface& mb, int tree_depth, int elem_per_leaf,
-                     long num_test, const std::vector<MBCartVect>& points,
-                     std::vector<MBEntityHandle>& point_elems,
+void do_kdtree_test( Interface& mb, int tree_depth, int elem_per_leaf,
+                     long num_test, const std::vector<CartVect>& points,
+                     std::vector<EntityHandle>& point_elems,
                      clock_t& build_time, clock_t& test_time, size_t& depth )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   clock_t init = clock();
-  MBAdaptiveKDTree tool( &mb );
-  MBEntityHandle root;
-  MBAdaptiveKDTree::Settings settings;
+  AdaptiveKDTree tool( &mb );
+  EntityHandle root;
+  AdaptiveKDTree::Settings settings;
   if (tree_depth > 0)
     settings.maxTreeDepth = tree_depth;
   if (elem_per_leaf > 0)
     settings.maxEntPerLeaf = elem_per_leaf;
-  MBRange all_hexes;
+  Range all_hexes;
   rval = mb.get_entities_by_type( 0, MBHEX, all_hexes );
   CHK(rval);
   rval = tool.build_tree( all_hexes, root, &settings );
@@ -279,11 +281,11 @@
   all_hexes.clear();
   build_time = clock() - init;
   
-  MBEntityHandle leaf;
-  std::vector<MBEntityHandle> hexes;
-  std::vector<MBEntityHandle>::iterator j;
-  MBCartVect coords[8];
-  const MBEntityHandle* conn;
+  EntityHandle leaf;
+  std::vector<EntityHandle> hexes;
+  std::vector<EntityHandle>::iterator j;
+  CartVect coords[8];
+  const EntityHandle* conn;
   int len;
   for (long i = 0; i < num_test; ++i) {
     const size_t idx = (size_t)i % points.size();
@@ -293,7 +295,7 @@
     for (j = hexes.begin(); j != hexes.end(); ++j) {
       rval = mb.get_connectivity( *j, conn, len, true ); CHK(rval);
       rval = mb.get_coords( conn, 8, reinterpret_cast<double*>(coords) ); CHK(rval);
-      if (MBGeomUtil::point_in_trilinear_hex( coords, points[idx], 1e-12 )) {
+      if (GeomUtil::point_in_trilinear_hex( coords, points[idx], 1e-12 )) {
         point_elems[idx] = *j;
         break;
       }
@@ -308,28 +310,28 @@
   depth = max_d;
 }
 
-void do_linear_test( MBInterface& mb, int , int ,
-                     long num_test, const std::vector<MBCartVect>& points,
-                     std::vector<MBEntityHandle>& point_elems,
+void do_linear_test( Interface& mb, int , int ,
+                     long num_test, const std::vector<CartVect>& points,
+                     std::vector<EntityHandle>& point_elems,
                      clock_t& build_time, clock_t& test_time, size_t& depth )
 {
   clock_t init = clock();
-  MBRange hexes;
-  MBErrorCode rval = mb.get_entities_by_type( 0, MBHEX, hexes );
+  Range hexes;
+  ErrorCode rval = mb.get_entities_by_type( 0, MBHEX, hexes );
   CHK(rval);
   depth = 0;
   point_elems.resize( points.size() );
   build_time = clock() - init;
   
-  MBCartVect coords[8];
-  const MBEntityHandle* conn;
+  CartVect coords[8];
+  const EntityHandle* conn;
   int len;
   for (long i = 0; i < num_test; ++i) {
     const size_t idx = (size_t)i % points.size();
-    for (MBRange::iterator h = hexes.begin(); h != hexes.end(); ++h) {
+    for (Range::iterator h = hexes.begin(); h != hexes.end(); ++h) {
       rval = mb.get_connectivity( *h, conn, len, true ); CHK(rval);
       rval = mb.get_coords( conn, 8, reinterpret_cast<double*>(coords) ); CHK(rval);
-      if (MBGeomUtil::point_in_trilinear_hex( coords, points[idx], 1e-12 )) {
+      if (GeomUtil::point_in_trilinear_hex( coords, points[idx], 1e-12 )) {
         point_elems[idx] = *h;
         break;
       }

Modified: MOAB/trunk/test/perf/seqperf.cpp
===================================================================
--- MOAB/trunk/test/perf/seqperf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/perf/seqperf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,8 +2,8 @@
 #include <assert.h>
 #include <iostream>
 #include <sstream>
-#include "MBCore.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Core.hpp"
+#include "moab/ReadUtilIface.hpp"
 
 #define PRINT_SEQUENCE_COUNT
 
@@ -17,6 +17,8 @@
 #  endif
 #endif
 
+using namespace moab;
+
   // constants
 const bool dump_mesh = false;        //!< write mesh to vtk file
 const int default_intervals = 25;    //!< defaul interval count for cubic structured hex mesh
@@ -31,10 +33,10 @@
 int queryCount;                      //!< number of times to do each query set
 
   // misc globals
-MBCore moab;                         //!< moab instance
-MBInterface& mb = moab;              //!< moab instance
-MBEntityHandle vertStart, elemStart; //!< first handle
-MBReadUtilIface *readTool = 0;       
+Core mb_core;                         //!< moab instance
+Interface& mb = mb_core;              //!< moab instance
+EntityHandle vertStart, elemStart; //!< first handle
+ReadUtilIface *readTool = 0;       
 long* queryVertPermutation = 0;      //!< pupulated by init(): "random" order for vertices
 long* queryElemPermutation = 0;      //!< pupulated by init(): "random" order for elements
 
@@ -65,8 +67,8 @@
 void init() 
 {
   void* ptr;
-  MBErrorCode rval = mb.query_interface( "MBReadUtilIface", &ptr );
-  readTool = static_cast<MBReadUtilIface*>(ptr);
+  ErrorCode rval = mb.query_interface( "ReadUtilIface", &ptr );
+  readTool = static_cast<ReadUtilIface*>(ptr);
   if (rval || !readTool) {
     assert(false);
     abort();
@@ -78,9 +80,9 @@
 
 
 void create_vertices_single( ); //!< create vertices one at a time
-void create_vertices_block( );  //!< create vertices in block using MBReadUtilIface
+void create_vertices_block( );  //!< create vertices in block using ReadUtilIface
 void create_elements_single( ); //!< create elements one at a time
-void create_elements_block( );  //!< create elements in block using MBReadUtilIface
+void create_elements_block( );  //!< create elements in block using ReadUtilIface
  
 void forward_order_query_vertices(int percent); //!< calculate mean of all vertex coordinates
 void reverse_order_query_vertices(int percent); //!< calculate mean of all vertex coordinates
@@ -106,7 +108,7 @@
 void create_missing_elements( int percent ); //!< re-create deleted elements
 
 #ifdef PRINT_SEQUENCE_COUNT
-unsigned get_number_sequences( MBEntityType type );
+unsigned get_number_sequences( EntityType type );
 #endif
 
 /* Build arrays of function pointers, indexed by the order the entities are traversed in */
@@ -139,7 +141,7 @@
 //! Coordinates for ith vertex in structured hex mesh
 inline void vertex_coords( long vert_index, double& x, double& y, double& z );
 //! Connectivity for ith hex in structured hex mesh
-inline void element_conn( long elem_index, MBEntityHandle conn[8] );
+inline void element_conn( long elem_index, EntityHandle conn[8] );
 //! True if passed index is one of the x% to be deleted
 inline bool deleted_vert( long index, int percent );
 //! True if passed index is one of the x% to be deleted
@@ -395,7 +397,7 @@
   return x + vs * (y + vs * z);
 }
 
-inline void element_conn( long elem_index, MBEntityHandle conn[8] )
+inline void element_conn( long elem_index, EntityHandle conn[8] )
 {
   const long x = elem_index % numSideInt;
   const long y = (elem_index / numSideInt) % numSideInt;
@@ -425,22 +427,22 @@
 {
   double coords[3];
   vertex_coords( 0, coords[0], coords[1], coords[2] );
-  MBErrorCode rval = mb.create_vertex( coords, vertStart );
+  ErrorCode rval = mb.create_vertex( coords, vertStart );
   assert(!rval);
   
-  MBEntityHandle h;
+  EntityHandle h;
   for (long i = 1; i < numVert; ++i) {
     vertex_coords( i, coords[0], coords[1], coords[2] );
     rval = mb.create_vertex( coords, h );
     assert(!rval);
-    assert(h - vertStart == (MBEntityHandle)i);
+    assert(h - vertStart == (EntityHandle)i);
   }
 }
 
 void create_vertices_block( )
 {
   std::vector<double*> arrays;
-  MBErrorCode rval = readTool->get_node_arrays( 3, numVert, 0, vertStart, arrays );
+  ErrorCode rval = readTool->get_node_arrays( 3, numVert, 0, vertStart, arrays );
   if (rval || arrays.size() != 3) {
     assert(false);
     abort();
@@ -454,28 +456,28 @@
 
 void create_elements_single( )
 {
-  MBEntityHandle conn[8];
+  EntityHandle conn[8];
   element_conn( 0, conn );
-  MBErrorCode rval = mb.create_element( MBHEX, conn, 8, elemStart );
+  ErrorCode rval = mb.create_element( MBHEX, conn, 8, elemStart );
   if (rval) {
     assert(false);
     abort();
   }
   
-  MBEntityHandle h;
+  EntityHandle h;
   for (long i = 1; i < numElem; ++i) {
     element_conn( i, conn );
     rval = mb.create_element( MBHEX, conn, 8, h );
     assert(!rval);
-    assert(h - elemStart == (MBEntityHandle)i);
+    assert(h - elemStart == (EntityHandle)i);
   }
 }
 
 
 void create_elements_block( )
 {
-  MBEntityHandle* conn = 0;
-  MBErrorCode rval = readTool->get_element_array( numElem, 8, MBHEX, 0, elemStart, conn );
+  EntityHandle* conn = 0;
+  ErrorCode rval = readTool->get_element_array( numElem, 8, MBHEX, 0, elemStart, conn );
   if (rval && !conn) {
     assert(false);
     abort();
@@ -487,12 +489,12 @@
  
 void forward_order_query_vertices(int percent)
 {
-  MBErrorCode r;
+  ErrorCode r;
   double coords[3];
   long x, y, z;
   const long vert_per_edge = numSideInt + 1;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100;
-  MBEntityHandle h = vertStart;
+  EntityHandle h = vertStart;
   for (z = 0; z < vert_per_edge; ++z) {
     for (y = 0; y < vert_per_edge; ++y) {
       for (x = 0; x < deleted_x; ++x, ++h) {
@@ -509,12 +511,12 @@
 
 void reverse_order_query_vertices(int percent)
 {
-  MBErrorCode r;
+  ErrorCode r;
   double coords[3];
   long x, y, z;
   const long vert_per_edge = numSideInt + 1;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100;
-  MBEntityHandle h = vertStart + numVert - 1;;
+  EntityHandle h = vertStart + numVert - 1;;
   for (z = vert_per_edge-1; z >= 0; --z) {
     for (y = vert_per_edge-1; y >= 0; --y) {
       h -= (vert_per_edge - deleted_x);
@@ -528,8 +530,8 @@
 
 void random_order_query_vertices(int percent)
 {
-  MBErrorCode r;
-  MBEntityHandle h;
+  ErrorCode r;
+  EntityHandle h;
   double coords[3];
   for (long i = 0; i < numVert; ++i) {
     if (!deleted_vert(queryVertPermutation[i],percent)) {
@@ -542,13 +544,13 @@
 
 void forward_order_query_elements(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   long x, y, z;
   const long elem_per_edge = numSideInt;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100 - 1;
-  MBEntityHandle h = elemStart;
+  EntityHandle h = elemStart;
   for (z = 0; z < elem_per_edge; ++z) {
     for (y = 0; y < elem_per_edge; ++y) {
       for (x = 0; x < deleted_x; ++x, ++h) {
@@ -563,13 +565,13 @@
 
 void reverse_order_query_elements(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   long x, y, z;
   const long elem_per_edge = numSideInt;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100 - 1;
-  MBEntityHandle h = elemStart + numElem - 1;;
+  EntityHandle h = elemStart + numElem - 1;;
   for (z = elem_per_edge-1; z >= 0; --z) {
     for (y = elem_per_edge-1; y >= 0; --y) {
       h -= (elem_per_edge - deleted_x);
@@ -584,8 +586,8 @@
 
 void  random_order_query_elements(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   for (long i = 0; i < numElem; ++i) {
     if (!deleted_elem( queryElemPermutation[i], percent )) {
@@ -619,14 +621,14 @@
 
 void forward_order_query_element_verts(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   long x, y, z;
   double coords[24];
   const long elem_per_edge = numSideInt;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100 - 1;
-  MBEntityHandle h = elemStart;
+  EntityHandle h = elemStart;
   for (z = 0; z < elem_per_edge; ++z) {
     for (y = 0; y < elem_per_edge; ++y) {
       for (x = 0; x < deleted_x; ++x, ++h) {
@@ -643,14 +645,14 @@
 
 void reverse_order_query_element_verts(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   long x, y, z;
   double coords[24];
   const long elem_per_edge = numSideInt;
   const long deleted_x = (numSideInt+1)*(100-percent) / 100 - 1;
-  MBEntityHandle h = elemStart + numElem - 1;;
+  EntityHandle h = elemStart + numElem - 1;;
   for (z = elem_per_edge-1; z >= 0; --z) {
     for (y = elem_per_edge-1; y >= 0; --y) {
       h -= (elem_per_edge - deleted_x);
@@ -667,8 +669,8 @@
 
 void  random_order_query_element_verts(int percent)
 {
-  MBErrorCode r;
-  const MBEntityHandle* conn;
+  ErrorCode r;
+  const EntityHandle* conn;
   int len;
   double coords[24];
   for (long i = 0; i < numElem; ++i) {
@@ -721,8 +723,8 @@
 
 void create_missing_vertices( int percent )
 {
-  MBEntityHandle h;
-  MBErrorCode rval;
+  EntityHandle h;
+  ErrorCode rval;
   double coords[3];
   for (long i = 0; i < numVert; ++i)
     if (deleted_vert( i, percent )) {
@@ -734,9 +736,9 @@
 
 void create_missing_elements( int percent )
 {
-  MBEntityHandle h;
-  MBErrorCode rval;
-  MBEntityHandle conn[8];
+  EntityHandle h;
+  ErrorCode rval;
+  EntityHandle conn[8];
   for (long i = 0; i < numElem; ++i)
     if (deleted_elem( i, percent )) {
       element_conn( i, conn );
@@ -751,8 +753,8 @@
 inline void delete_vert( long index, int percent )
 {
   if (deleted_vert(index, percent)) {
-    MBEntityHandle h = index + vertStart;
-    MBErrorCode rval = mb.delete_entities( &h, 1 );
+    EntityHandle h = index + vertStart;
+    ErrorCode rval = mb.delete_entities( &h, 1 );
     if (rval) {
       assert(false);
       abort();
@@ -763,8 +765,8 @@
 inline void delete_elem( long index, int percent )
 {
   if (deleted_elem(index, percent)) {
-    MBEntityHandle h = index + elemStart;
-    MBErrorCode rval = mb.delete_entities( &h, 1 );
+    EntityHandle h = index + elemStart;
+    ErrorCode rval = mb.delete_entities( &h, 1 );
     if (rval) {
       assert(false);
       abort();
@@ -773,12 +775,12 @@
 }
 
 #ifdef PRINT_SEQUENCE_COUNT
-unsigned get_number_sequences( MBEntityType type )
+unsigned get_number_sequences( EntityType type )
 {
 #ifdef MB_ENTITY_SEQUENCE_HPP
-  return moab.sequence_manager()->entity_map(type)->size();
+  return mb_core.sequence_manager()->entity_map(type)->size();
 #else
-  return moab.sequence_manager()->entity_map(type).get_sequence_count();
+  return mb_core.sequence_manager()->entity_map(type).get_sequence_count();
 #endif
 }
 #endif

Modified: MOAB/trunk/test/scdseq_test.cpp
===================================================================
--- MOAB/trunk/test/scdseq_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/scdseq_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -22,58 +22,60 @@
 #include "SequenceManager.hpp"
 #include "StructuredElementSeq.hpp"
 #include "VertexSequence.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 
 #include <iostream>
 #include <assert.h>
 
-int test_vertex_seq(MBCore *gMB);
-MBErrorCode check_vertex_sequence(const ScdVertexData *this_seq, 
+using namespace moab;
+
+int test_vertex_seq(Core *gMB);
+ErrorCode check_vertex_sequence(const ScdVertexData *this_seq, 
                                  const int imin, const int jmin, const int kmin, 
                                  const int imax, const int jmax, const int kmax, 
-                                 const MBEntityHandle this_start);
-MBErrorCode evaluate_vertex_sequence(ScdVertexData *this_seq);
+                                 const EntityHandle this_start);
+ErrorCode evaluate_vertex_sequence(ScdVertexData *this_seq);
 
-int test_element_seq(MBCore *gMB);
-MBErrorCode check_element_sequence(const StructuredElementSeq *this_seq, 
+int test_element_seq(Core *gMB);
+ErrorCode check_element_sequence(const StructuredElementSeq *this_seq, 
                                     const HomCoord &min_params,
                                     const HomCoord &max_params,
-                                    const MBEntityHandle this_start);
-MBErrorCode evaluate_element_sequence(StructuredElementSeq *this_seq);
-int eseq_test1a(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max);
-int eseq_test1b(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max);
-int eseq_test1c(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max);
-int eseq_test2a(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max);
-int eseq_test2b(MBCore *gMB);
-int eseq_test2c(MBCore *gMB);
-int eseq_test2d(MBCore *gMB);
+                                    const EntityHandle this_start);
+ErrorCode evaluate_element_sequence(StructuredElementSeq *this_seq);
+int eseq_test1a(Core *gMB, HomCoord tmp_min, HomCoord tmp_max);
+int eseq_test1b(Core *gMB, HomCoord tmp_min, HomCoord tmp_max);
+int eseq_test1c(Core *gMB, HomCoord tmp_min, HomCoord tmp_max);
+int eseq_test2a(Core *gMB, HomCoord tmp_min, HomCoord tmp_max);
+int eseq_test2b(Core *gMB);
+int eseq_test2c(Core *gMB);
+int eseq_test2d(Core *gMB);
 
-int create_1d_3_sequences(MBCore *gMB,
+int create_1d_3_sequences(Core *gMB,
                           HomCoord tmp_min, HomCoord tmp_max,
-                          ScdVertexData **vseq, MBEntityHandle *vstart,
-                          StructuredElementSeq **eseq, MBEntityHandle *estart);
+                          ScdVertexData **vseq, EntityHandle *vstart,
+                          StructuredElementSeq **eseq, EntityHandle *estart);
 
-int create_2d_3_sequences(MBCore *gMB,
-                          ScdVertexData **vseq, MBEntityHandle *vstart,
-                          StructuredElementSeq **eseq, MBEntityHandle *estart);
+int create_2d_3_sequences(Core *gMB,
+                          ScdVertexData **vseq, EntityHandle *vstart,
+                          StructuredElementSeq **eseq, EntityHandle *estart);
 
-int create_2dtri_3_sequences(MBCore *gMB,
+int create_2dtri_3_sequences(Core *gMB,
                              const int int1, const int int2, const int int3,
-                             ScdVertexData **vseq, MBEntityHandle *vstart,
-                             StructuredElementSeq **eseq, MBEntityHandle *estart);
-int create_3dtri_3_sequences(MBCore *gMB,
+                             ScdVertexData **vseq, EntityHandle *vstart,
+                             StructuredElementSeq **eseq, EntityHandle *estart);
+int create_3dtri_3_sequences(Core *gMB,
                              const int int1, const int int2, const int int3, const int int4,
-                             ScdVertexData **vseq, MBEntityHandle *vstart,
-                             StructuredElementSeq **eseq, MBEntityHandle *estart);
+                             ScdVertexData **vseq, EntityHandle *vstart,
+                             StructuredElementSeq **eseq, EntityHandle *estart);
 
 // first comes general-capability code used by various tests; main and test functions
 // come after these, starting with main
-MBErrorCode check_vertex_sequence(const ScdVertexData *this_seq, 
+ErrorCode check_vertex_sequence(const ScdVertexData *this_seq, 
                                    const int imin, const int jmin, const int kmin, 
                                    const int imax, const int jmax, const int kmax, 
-                                   const MBEntityHandle this_start) 
+                                   const EntityHandle this_start) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
     // check data stored in sequence with that in arg list
   if (imin != this_seq->i_min() ||
@@ -104,12 +106,12 @@
   return result;
 }
   
-MBErrorCode check_element_sequence(const StructuredElementSeq *this_seq, 
+ErrorCode check_element_sequence(const StructuredElementSeq *this_seq, 
                                     const HomCoord &min_params,
                                     const HomCoord &max_params,
-                                    const MBEntityHandle this_start) 
+                                    const EntityHandle this_start) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
     // check data stored in sequence with that in arg list
   if (min_params.i() != this_seq->i_min() ||
@@ -145,9 +147,9 @@
   return result;
 }
   
-MBErrorCode evaluate_vertex_sequence(ScdVertexData *this_seq) 
+ErrorCode evaluate_vertex_sequence(ScdVertexData *this_seq) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
     // first get the parametric extents
   int imin, jmin, kmin, imax, jmax, kmax, itmp, jtmp, ktmp;
@@ -155,15 +157,15 @@
   this_seq->max_params(imax, jmax, kmax);
 
     // then the start vertex
-  MBEntityHandle start_handle = this_seq->start_handle();
+  EntityHandle start_handle = this_seq->start_handle();
   
     // now evaluate all the vertices in forward and reverse
-  MBEntityHandle tmp_handle, tmp_handle2;
+  EntityHandle tmp_handle, tmp_handle2;
   for (int i = imin; i <= imax; i++) {
     for (int j = jmin; j <= jmax; j++) {
       for (int k = kmin; k <= kmax; k++) {
           // compute what the vertex handle is supposed to be
-        MBEntityHandle this_handle = start_handle + (i-imin) + (j-jmin)*(imax-imin+1) + 
+        EntityHandle this_handle = start_handle + (i-imin) + (j-jmin)*(imax-imin+1) + 
           (k-kmin)*(jmax-jmin+1)*(imax-imin+1);
 
           // get_vertex variants
@@ -183,7 +185,7 @@
         }
 
         itmp = jtmp = ktmp = 0xdeadbeef;
-        MBErrorCode tmp_result = this_seq->get_params(tmp_handle, itmp, jtmp, ktmp);
+        ErrorCode tmp_result = this_seq->get_params(tmp_handle, itmp, jtmp, ktmp);
         if (MB_SUCCESS != tmp_result || i != itmp || j != jtmp || k != ktmp) {
           std::cout << "vertex seq: get_params didn't work, i, j, k = " << i << ", " 
                     << j << ", " << k << "; itmp, jtmp, ktmp = " 
@@ -203,9 +205,9 @@
   return result;
 }
 
-MBErrorCode evaluate_element_sequence(StructuredElementSeq *this_seq) 
+ErrorCode evaluate_element_sequence(StructuredElementSeq *this_seq) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
     // first get the parametric extents
   int imin, jmin, kmin, imax, jmax, kmax, itmp, jtmp, ktmp;
@@ -213,7 +215,7 @@
   this_seq->max_params(imax, jmax, kmax);
 
     // now evaluate all the vertices and elements in forward and reverse
-  MBEntityHandle tmp_handle, tmp_handle2;
+  EntityHandle tmp_handle, tmp_handle2;
   for (int i = imin; i < imax; i++) {
     for (int j = jmin; j < jmax; j++) {
       for (int k = kmin; k < kmax; k++) {
@@ -242,7 +244,7 @@
         
           // get_params
         itmp = jtmp = ktmp = 0xdeadbeef;
-        MBErrorCode tmp_result = this_seq->get_params(tmp_handle, itmp, jtmp, ktmp);
+        ErrorCode tmp_result = this_seq->get_params(tmp_handle, itmp, jtmp, ktmp);
         if (MB_SUCCESS != tmp_result || i != itmp || j != jtmp || k != ktmp) {
           std::cout << "element seq: get_params didn't work, i, j, k = " << i << ", " 
                     << j << ", " << k << "; itmp, jtmp, ktmp = " 
@@ -266,8 +268,8 @@
 {
   int errors = 0;
 
-    // first we need to make a new MBCore
-  MBCore moab;
+    // first we need to make a new Core
+  Core moab;
   
     // test creating and evaluating vertex sequences
   errors += test_vertex_seq(&moab);
@@ -283,18 +285,18 @@
   return errors;
 }
 
-int test_vertex_seq(MBCore *gMB) 
+int test_vertex_seq(Core *gMB) 
 {
     // get the seq manager from gMB
   SequenceManager *seq_mgr = gMB->sequence_manager();
   
   int errors = 0;
-  MBEntityHandle oned_start, twod_start, threed_start;
+  EntityHandle oned_start, twod_start, threed_start;
   EntitySequence *dum_seq = NULL;
   ScdVertexData *oned_seq = NULL, *twod_seq = NULL, *threed_seq = NULL;
   
     // make a 1d sequence
-  MBErrorCode result = seq_mgr->create_scd_sequence(-10, 0, 0, 10, 0, 0,
+  ErrorCode result = seq_mgr->create_scd_sequence(-10, 0, 0, 10, 0, 0,
                                                      MBVERTEX, 1,
                                                      oned_start, dum_seq);
   if (NULL != dum_seq) oned_seq = dynamic_cast<ScdVertexData*>(dum_seq->data());
@@ -376,7 +378,7 @@
   return errors;
 }
 
-int test_element_seq(MBCore *gMB) 
+int test_element_seq(Core *gMB) 
 {
   int errors = 0;
   HomCoord TEST_MIN_PARAMS(0,0,0);
@@ -397,7 +399,7 @@
   return errors;
 }
 
-int eseq_test1a(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max) 
+int eseq_test1a(Core *gMB, HomCoord tmp_min, HomCoord tmp_max) 
 {
     // TEST 1a: 1d single vertex seq block, min/max = (-10,0,0)/(10,0,0)
     // create vertex seq
@@ -410,17 +412,17 @@
     // get the seq manager from gMB
   SequenceManager *seq_mgr = gMB->sequence_manager();
   
-  MBEntityHandle oned_start;
+  EntityHandle oned_start;
   EntitySequence *dum_seq;
   ScdVertexData *oned_seq = NULL;
-  MBErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
+  ErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                                      MBVERTEX, 1,
                                                      oned_start, dum_seq);
   if (NULL != dum_seq) oned_seq = dynamic_cast<ScdVertexData*>(dum_seq->data());
   assert (MB_FAILURE != result && oned_start != 0 && dum_seq != NULL && oned_seq != NULL);
 
     // now create the element sequence
-  MBEntityHandle eseq_start;
+  EntityHandle eseq_start;
   StructuredElementSeq *eseq = NULL;
   result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                         MBEDGE, 1,
@@ -455,7 +457,7 @@
   return errors;
 }
 
-int eseq_test1b(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max) 
+int eseq_test1b(Core *gMB, HomCoord tmp_min, HomCoord tmp_max) 
 {
     // TEST 1b: 2d single vertex seq block, min/max = (-10,-5,0)/(10,5,0)
 
@@ -467,17 +469,17 @@
     // get the seq manager from gMB
   SequenceManager *seq_mgr = gMB->sequence_manager();
   
-  MBEntityHandle twod_start;
+  EntityHandle twod_start;
   EntitySequence *dum_seq;
   ScdVertexData *twod_seq = NULL;
-  MBErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
+  ErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                                      MBVERTEX, 1,
                                                      twod_start, dum_seq);
   if (NULL != dum_seq) twod_seq = dynamic_cast<ScdVertexData*>(dum_seq->data());
   assert (MB_FAILURE != result && twod_start != 0 && dum_seq != NULL && twod_seq != NULL);
 
     // now create the element sequence
-  MBEntityHandle eseq_start;
+  EntityHandle eseq_start;
   StructuredElementSeq *eseq = NULL;
   result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                         MBQUAD, 1,
@@ -513,7 +515,7 @@
   return errors;
 }
 
-int eseq_test1c(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max) 
+int eseq_test1c(Core *gMB, HomCoord tmp_min, HomCoord tmp_max) 
 {
     // TEST 1c: 3d single vertex seq block, min/max = (-10,-5,-1)/(10,5,1)
 
@@ -522,17 +524,17 @@
     // get the seq manager from gMB
   SequenceManager *seq_mgr = gMB->sequence_manager();
   
-  MBEntityHandle threed_start;
+  EntityHandle threed_start;
   EntitySequence *dum_seq;
   ScdVertexData *threed_seq = NULL;
-  MBErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
+  ErrorCode result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                                      MBVERTEX, 1,
                                                      threed_start, dum_seq);
   if (NULL != dum_seq) threed_seq = dynamic_cast<ScdVertexData*>(dum_seq->data());
   assert (MB_FAILURE != result && threed_start != 0 && dum_seq != NULL && threed_seq != NULL);
 
     // now create the element sequence
-  MBEntityHandle eseq_start;
+  EntityHandle eseq_start;
   StructuredElementSeq *eseq = NULL;
   result = seq_mgr->create_scd_sequence(tmp_min, tmp_max,
                                         MBHEX, 1,
@@ -566,14 +568,14 @@
   return errors;
 }
 
-int eseq_test2a(MBCore *gMB, HomCoord tmp_min, HomCoord tmp_max) 
+int eseq_test2a(Core *gMB, HomCoord tmp_min, HomCoord tmp_max) 
 {
     // TEST 2a: 1d composite block, 0d difference between owning/sharing blocks
     // create vertex seq
   
   ScdVertexData *vseq[3];
   StructuredElementSeq *eseq[3];
-  MBEntityHandle vstart[3], estart[3];
+  EntityHandle vstart[3], estart[3];
   
   int errors = create_1d_3_sequences(gMB, tmp_min, tmp_max,
                                      vseq, vstart, eseq, estart);
@@ -591,7 +593,7 @@
 
     // check/evaluate element sequences
   for (int i = 0; i < 3; i++) {
-    MBErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
+    ErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
                                                  estart[i]);
     if (MB_SUCCESS != result) {
       std::cout << "1d composite element sequence " << i << " didn't pass check." << std::endl;
@@ -608,14 +610,14 @@
   return errors;
 }
 
-int eseq_test2b(MBCore *gMB) 
+int eseq_test2b(Core *gMB) 
 {
     // TEST 2b: 2d composite block, 0d difference between owning/sharing blocks
     // create vertex seq
   
   ScdVertexData *vseq[3];
   StructuredElementSeq *eseq[3];
-  MBEntityHandle vstart[3], estart[3];
+  EntityHandle vstart[3], estart[3];
   
   int errors = create_2d_3_sequences(gMB, vseq, vstart, eseq, estart);
   if (0 != errors) return errors;
@@ -634,7 +636,7 @@
 
     // check/evaluate element sequences
   for (int i = 0; i < 3; i++) {
-    MBErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
+    ErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
                                                  estart[i]);
     if (MB_SUCCESS != result) {
       std::cout << "2d composite element sequence " << i << " didn't pass check." << std::endl;
@@ -651,14 +653,14 @@
   return errors;
 }
 
-int eseq_test2c(MBCore *gMB) 
+int eseq_test2c(Core *gMB) 
 {
     // TEST 2c: 2d composite block, 0d difference between owning/sharing blocks,
     // tri-valent shared vertex between the three blocks
 
   ScdVertexData *vseq[3];
   StructuredElementSeq *eseq[3];
-  MBEntityHandle vstart[3], estart[3];
+  EntityHandle vstart[3], estart[3];
 
     // interval settings: only 3 of them
   int int1 = 5, int2 = 15, int3 = 25;
@@ -669,7 +671,7 @@
 
     // check/evaluate element sequences
   for (int i = 0; i < 3; i++) {
-    MBErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
+    ErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
                                                  estart[i]);
     if (MB_SUCCESS != result) {
       std::cout << "2d tri-composite element sequence " << i << " didn't pass check." << std::endl;
@@ -686,14 +688,14 @@
   return errors;
 }
 
-int eseq_test2d(MBCore *gMB) 
+int eseq_test2d(Core *gMB) 
 {
     // TEST 2d: 3d composite block, 0d difference between owning/sharing blocks,
     // tri-valent shared edge between the three blocks
 
   ScdVertexData *vseq[3];
   StructuredElementSeq *eseq[3];
-  MBEntityHandle vstart[3], estart[3];
+  EntityHandle vstart[3], estart[3];
 
     // interval settings: only 3 of them
   int int1 = 100, int2 = 100, int3 = 100, int4 = 100;
@@ -704,7 +706,7 @@
 
     // check/evaluate element sequences
   for (int i = 0; i < 3; i++) {
-    MBErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
+    ErrorCode result = check_element_sequence(eseq[i], eseq[i]->min_params(), eseq[i]->max_params(), 
                                                  estart[i]);
     if (MB_SUCCESS != result) {
       std::cout << "3d tri-composite element sequence " << i << " didn't pass check." << std::endl;
@@ -721,10 +723,10 @@
   return errors;
 }
 
-int create_1d_3_sequences(MBCore *gMB,
+int create_1d_3_sequences(Core *gMB,
                           HomCoord tmp_min, HomCoord tmp_max,
-                          ScdVertexData **vseq, MBEntityHandle *vstart,
-                          StructuredElementSeq **eseq, MBEntityHandle *estart) 
+                          ScdVertexData **vseq, EntityHandle *vstart,
+                          StructuredElementSeq **eseq, EntityHandle *estart) 
 {
   int errors = 0;
   
@@ -747,7 +749,7 @@
   
 
     // first vertex sequence 
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
                                                      MBVERTEX, 1,
                                                      vstart[0], dum_seq);
   if (NULL != dum_seq) vseq[0] = dynamic_cast<ScdVertexData*>(dum_seq->data());
@@ -859,9 +861,9 @@
   return errors;
 }
 
-int create_2d_3_sequences(MBCore *gMB,
-                          ScdVertexData **vseq, MBEntityHandle *vstart,
-                          StructuredElementSeq **eseq, MBEntityHandle *estart) 
+int create_2d_3_sequences(Core *gMB,
+                          ScdVertexData **vseq, EntityHandle *vstart,
+                          StructuredElementSeq **eseq, EntityHandle *estart) 
 {
     // create 3 rectangular esequences attached end to end and back (periodic); vsequences are 
     // assorted orientations, esequences have globally-consistent (periodic in i) parameter space
@@ -880,7 +882,7 @@
   vseq[0] = vseq[1] = vseq[2] = NULL;
 
     // first vertex sequence 
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
                                                      MBVERTEX, 1,
                                                      vstart[0], dum_seq);
   if (NULL != dum_seq) vseq[0] = dynamic_cast<ScdVertexData*>(dum_seq->data());
@@ -1037,10 +1039,10 @@
   return errors;
 }
 
-int create_2dtri_3_sequences(MBCore *gMB,
+int create_2dtri_3_sequences(Core *gMB,
                              const int int1, const int int2, const int int3,
-                             ScdVertexData **vseq, MBEntityHandle *vstart,
-                             StructuredElementSeq **eseq, MBEntityHandle *estart) 
+                             ScdVertexData **vseq, EntityHandle *vstart,
+                             StructuredElementSeq **eseq, EntityHandle *estart) 
 {
     // create 3 rectangular esequences arranged such that the all share a common (tri-valent) corner;
     // orient each region such that its origin is at the tri-valent corner and the k direction is
@@ -1066,7 +1068,7 @@
   vseq[0] = vseq[1] = vseq[2] = NULL;
 
     // first vertex sequence 
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
                                                      MBVERTEX, 1,
                                                      vstart[0], dum_seq);
   if (NULL != dum_seq) vseq[0] = dynamic_cast<ScdVertexData*>(dum_seq->data());
@@ -1216,10 +1218,10 @@
   return errors;
 }
 
-int create_3dtri_3_sequences(MBCore *gMB,
+int create_3dtri_3_sequences(Core *gMB,
                              const int int1, const int int2, const int int3, const int int4,
-                             ScdVertexData **vseq, MBEntityHandle *vstart,
-                             StructuredElementSeq **eseq, MBEntityHandle *estart) 
+                             ScdVertexData **vseq, EntityHandle *vstart,
+                             StructuredElementSeq **eseq, EntityHandle *estart) 
 {
     // create 3 brick esequences arranged such that the all share a common (tri-valent) edge;
     // orient each region similarly to the 2dtri_3_esequences test problem, swept into 3d in the 
@@ -1246,7 +1248,7 @@
   vseq[0] = vseq[1] = vseq[2] = NULL;
 
     // first vertex sequence 
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
                                                      MBVERTEX, 1,
                                                      vstart[0], dum_seq);
   if (NULL != dum_seq) vseq[0] = dynamic_cast<ScdVertexData*>(dum_seq->data());

Modified: MOAB/trunk/test/scdseq_timing.cpp
===================================================================
--- MOAB/trunk/test/scdseq_timing.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/scdseq_timing.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -17,12 +17,14 @@
 #include "ScdElementSeq.hpp"
 #include "EntitySequenceManager.hpp"
 #include "EntitySequence.hpp"
-#include "MBCore.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Core.hpp"
+#include "moab/ReadUtilIface.hpp"
 
 #include <iostream>
 #include <time.h>
 
+using namespace moab;
+
 /*
 // some timing/memory measurement includes; memory measurement
 // doesn't work on linux, so they're commented out for now to avoid
@@ -37,12 +39,12 @@
 #include <fcntl.h>
 */
 
-int create_3dtri_3_sequences(MBCore *gMB,
+int create_3dtri_3_sequences(Core *gMB,
                              const int intervals,
-                             MBEntityHandle *vstart, MBEntityHandle *estart);
-int create_3dtri_ucd_sequences(MBCore *gMB,
+                             EntityHandle *vstart, EntityHandle *estart);
+int create_3dtri_ucd_sequences(Core *gMB,
                                const int intervals,
-                               MBEntityHandle *vstart, MBEntityHandle *estart);
+                               EntityHandle *vstart, EntityHandle *estart);
 void print_time();
 
 
@@ -51,8 +53,8 @@
 {
   int errors = 0;
 
-    // first we need to make a new MBCore
-  MBCore *gMB = new MBCore();
+    // first we need to make a new Core
+  Core *gMB = new Core();
 
     // get the intervals
   if (argc < 2) {
@@ -77,10 +79,10 @@
     }
   }
   
-  MBEntityHandle estart[3], vstart[3];
+  EntityHandle estart[3], vstart[3];
   int total_elements = intervals*intervals*intervals;
-  std::vector<MBEntityHandle> connect;
-  MBErrorCode result;
+  std::vector<EntityHandle> connect;
+  ErrorCode result;
   clock_t start, stop;
   float time;
   char inp[1];
@@ -128,7 +130,7 @@
   if (do_ucd) {
 
       // now do the same thing, only unstructured
-    gMB = new MBCore();
+    gMB = new Core();
 
       // create the elements
     errors = create_3dtri_ucd_sequences(gMB, intervals, vstart, estart);
@@ -138,7 +140,7 @@
     }
 
       // get connectivity
-    std::vector<MBEntityHandle> connect;
+    std::vector<EntityHandle> connect;
     start = clock();
     for (int j = 0; j < 3; j++) {
       for (int i = 0; i < total_elements; i++) {
@@ -165,9 +167,9 @@
   }
 }
 
-int create_3dtri_3_sequences(MBCore *gMB,
+int create_3dtri_3_sequences(Core *gMB,
                              const int intervals,
-                             MBEntityHandle *vstart, MBEntityHandle *estart) 
+                             EntityHandle *vstart, EntityHandle *estart) 
 {
     // create 3 brick esequences arranged such that the all share a common (tri-valent) edge;
     // orient each region similarly to the 2dtri_3_esequences test problem, swept into 3d in the 
@@ -194,11 +196,11 @@
   EntitySequenceManager *seq_mgr = gMB->sequence_manager();
 
     // create three vertex sequences
-  MBEntitySequence *dum_seq;
+  EntitySequence *dum_seq;
   vseq[0] = vseq[1] = vseq[2] = NULL;
 
     // first vertex sequence 
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq0_minmax[0], vseq0_minmax[1],
                                                      MBVERTEX, 1,
                                                      vstart[0], dum_seq);
   if (NULL != dum_seq) vseq[0] = dynamic_cast<ScdVertexSeq*>(dum_seq);
@@ -351,12 +353,12 @@
   return errors;
 }
 
-int create_3dtri_ucd_sequences(MBCore *gMB, const int intervals, 
-                               MBEntityHandle *vstart, MBEntityHandle *estart) 
+int create_3dtri_ucd_sequences(Core *gMB, const int intervals, 
+                               EntityHandle *vstart, EntityHandle *estart) 
 {
   
-  MBReadUtilIface* readMeshIface;
-  std::string iface_name = "MBReadUtilIface";
+  ReadUtilIface* readMeshIface;
+  std::string iface_name = "ReadUtilIface";
   gMB->query_interface(iface_name, reinterpret_cast<void**>(&readMeshIface));
   
   int num_elements = intervals*intervals*intervals;
@@ -369,7 +371,7 @@
     arrays.clear();
   }
 
-  MBEntityHandle *conn[3];
+  EntityHandle *conn[3];
 
     // allocate 3 arrays to initialize connectivity data
   for (int i = 0; i < 3; i++) {

Modified: MOAB/trunk/test/test_adj.cpp
===================================================================
--- MOAB/trunk/test/test_adj.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/test/test_adj.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -25,26 +25,28 @@
 #endif
 
 #include <iostream>
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 
 #ifndef IS_BUILDING_MB
 #define IS_BUILDING_MB
 #endif
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 
+using namespace moab;
+
 int main()
 {
 
-  MBInterface* iface = new MBCore;
+  Interface* iface = new Core;
 
   iface->load_mesh( "../test/quad/quad1.gen" );
 
-  std::vector<MBEntityHandle> nodes;
+  std::vector<EntityHandle> nodes;
   int err;
-  MBEntityHandle h = CREATE_HANDLE(MBQUAD, MB_START_ID, err);
+  EntityHandle h = CREATE_HANDLE(MBQUAD, MB_START_ID, err);
   err = iface->get_adjacencies( &h, 1, 0, true, nodes);
 
-  std::vector<MBEntityHandle> tris;
+  std::vector<EntityHandle> tris;
   err = iface->get_adjacencies( &h, 1, 1, true, tris);
 
   //faces to nodes

Modified: MOAB/trunk/tools/Makefile.am
===================================================================
--- MOAB/trunk/tools/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,11 +2,7 @@
 AM_CPPFLAGS += -I$(top_srcdir)/src \
                -I$(top_builddir)/src \
                -I$(top_srcdir)/src/parallel \
-               -I$(top_builddir)/src/parallel \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/parallel/moab \
-               -I$(top_builddir)/src/parallel/moab 
+               -I$(top_builddir)/src/parallel
 
 LDADD = $(top_builddir)/src/libMOAB.la
 
@@ -139,7 +135,7 @@
 mbdepth_SOURCES = depth.cpp
 mbdepth_DEPENDENCIES = $(LDADD)
 
-spheredecomp_SOURCES = SphereDecomp.hpp SphereDecomp.cpp main.cpp
+spheredecomp_SOURCES = SphereDecomp.hpp SphereDecomp.cpp sphere_decomp.cpp
 spheredecomp_DEPENDENCIES = $(LDADD)
 
 mbsurfplot_SOURCES = surfplot.cpp

Modified: MOAB/trunk/tools/SphereDecomp.cpp
===================================================================
--- MOAB/trunk/tools/SphereDecomp.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/SphereDecomp.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
 #include "SphereDecomp.hpp"
-#include "MeshTopoUtil.hpp"
-#include "MBRange.hpp"
-#include "MBCN.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBCN.hpp"
 #include <math.h>
 #include <assert.h>
 #include <iostream>
@@ -10,24 +10,26 @@
 
 const char *SUBDIV_VERTICES_TAG_NAME = "subdiv_vertices";
 
-SphereDecomp::SphereDecomp(MBInterface *impl) 
+using namespace moab;
+
+SphereDecomp::SphereDecomp(Interface *impl) 
 {
   mbImpl = impl;
 }
 
-MBErrorCode SphereDecomp::build_sphere_mesh(const char *sphere_radii_tag_name,
-                                            MBEntityHandle *hex_set) 
+ErrorCode SphereDecomp::build_sphere_mesh(const char *sphere_radii_tag_name,
+                                            EntityHandle *hex_set) 
 {
-  MBErrorCode result = mbImpl->tag_get_handle(sphere_radii_tag_name, sphereRadiiTag); RR;
+  ErrorCode result = mbImpl->tag_get_handle(sphere_radii_tag_name, sphereRadiiTag); RR;
 
     // need to make sure all interior edges and faces are created
-  MBRange all_verts;
+  Range all_verts;
   result = mbImpl->get_entities_by_type(0, MBVERTEX, all_verts); RR;
   MeshTopoUtil mtu(mbImpl);
   result = mtu.construct_aentities(all_verts);
   
     // create tag to hold vertices
-  result = mbImpl->tag_create(SUBDIV_VERTICES_TAG_NAME, 9*sizeof(MBEntityHandle), 
+  result = mbImpl->tag_create(SUBDIV_VERTICES_TAG_NAME, 9*sizeof(EntityHandle), 
                            MB_TAG_DENSE, MB_TYPE_HANDLE, subdivVerticesTag, NULL); RR;
 
     // compute nodal positions for each dimension element
@@ -36,14 +38,14 @@
   result = compute_nodes(3); RR;
   
     // build hex elements
-  std::vector<MBEntityHandle> sphere_hexes, interstic_hexes;
+  std::vector<EntityHandle> sphere_hexes, interstic_hexes;
   result = build_hexes(sphere_hexes, interstic_hexes); 
 
   result = mbImpl->tag_delete(subdivVerticesTag); RR;
 
   if (NULL != hex_set) {
     if (0 == *hex_set) {
-      MBEntityHandle this_set;
+      EntityHandle this_set;
         // make a new set
       result = mbImpl->create_meshset(MESHSET_SET, this_set); RR;
       *hex_set = this_set;
@@ -59,26 +61,26 @@
   return result;
 }
 
-MBErrorCode SphereDecomp::compute_nodes(const int dim) 
+ErrorCode SphereDecomp::compute_nodes(const int dim) 
 {
     // get facets of that dimension
-  MBRange these_ents;
-  const MBEntityType the_types[4] = {MBVERTEX, MBEDGE, MBTRI, MBTET};
+  Range these_ents;
+  const EntityType the_types[4] = {MBVERTEX, MBEDGE, MBTRI, MBTET};
   
-  MBErrorCode result = mbImpl->get_entities_by_dimension(0, dim, these_ents); RR;
+  ErrorCode result = mbImpl->get_entities_by_dimension(0, dim, these_ents); RR;
   assert(mbImpl->type_from_handle(*these_ents.begin()) == the_types[dim] &&
          mbImpl->type_from_handle(*these_ents.rbegin()) == the_types[dim]);
   
-  MBEntityHandle subdiv_vertices[9];
+  EntityHandle subdiv_vertices[9];
   MeshTopoUtil mtu(mbImpl);
   double avg_pos[3], vert_pos[12], new_vert_pos[12], new_new_vert_pos[3];
   double radii[4], unitv[3];
   int num_verts = MBCN::VerticesPerEntity(the_types[dim]);
   
-  for (MBRange::iterator rit = these_ents.begin(); rit != these_ents.end(); rit++) {
+  for (Range::iterator rit = these_ents.begin(); rit != these_ents.end(); rit++) {
     
       // get vertices
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
     result = mbImpl->get_connectivity(*rit, connect, num_connect); RR;
 
@@ -111,7 +113,7 @@
         new_vert_pos[3*i+j] = vert_pos[3*i+j] + radii[i] * unitv[j];
 
       // create vertex at this position
-      MBErrorCode tmp_result = mbImpl->create_vertex(&new_vert_pos[3*i], subdiv_vertices[i]);
+      ErrorCode tmp_result = mbImpl->create_vertex(&new_vert_pos[3*i], subdiv_vertices[i]);
       if (MB_SUCCESS != tmp_result) result = tmp_result;
     }
     
@@ -133,41 +135,41 @@
   return result;
 }
 
-MBErrorCode SphereDecomp::build_hexes(std::vector<MBEntityHandle> &sphere_hexes,
-                        std::vector<MBEntityHandle> &interstic_hexes) 
+ErrorCode SphereDecomp::build_hexes(std::vector<EntityHandle> &sphere_hexes,
+                        std::vector<EntityHandle> &interstic_hexes) 
 {
     // build hexes inside each tet element separately
-  MBRange tets;
-  MBErrorCode result = mbImpl->get_entities_by_type(0, MBTET, tets); RR;
+  Range tets;
+  ErrorCode result = mbImpl->get_entities_by_type(0, MBTET, tets); RR;
   
-  for (MBRange::iterator vit = tets.begin(); vit != tets.end(); vit++) {
+  for (Range::iterator vit = tets.begin(); vit != tets.end(); vit++) {
     result = subdivide_tet(*vit, sphere_hexes, interstic_hexes); RR;
   }
   
   return MB_SUCCESS;
 }
 
-MBErrorCode SphereDecomp::subdivide_tet(MBEntityHandle tet, 
-                          std::vector<MBEntityHandle> &sphere_hexes,
-                          std::vector<MBEntityHandle> &interstic_hexes) 
+ErrorCode SphereDecomp::subdivide_tet(EntityHandle tet, 
+                          std::vector<EntityHandle> &sphere_hexes,
+                          std::vector<EntityHandle> &interstic_hexes) 
 {
     // 99: (#subdiv_verts/entity=9) * (#edges=6 + #faces=4 + 1=tet)
-  MBEntityHandle subdiv_verts[99];
+  EntityHandle subdiv_verts[99];
 
     // get tet connectivity
-  std::vector<MBEntityHandle> tet_conn;
-  MBErrorCode result = mbImpl->get_connectivity(&tet, 1, tet_conn); RR;
+  std::vector<EntityHandle> tet_conn;
+  ErrorCode result = mbImpl->get_connectivity(&tet, 1, tet_conn); RR;
   
   for (int dim = 1; dim <= 3; dim++) {
       // get entities of this dimension
-    std::vector<MBEntityHandle> ents;
+    std::vector<EntityHandle> ents;
     if (dim != 3) {
       result = mbImpl->get_adjacencies(&tet, 1, dim, false, ents); RR; 
     }
     else ents.push_back(tet);
     
       // for each, get subdiv verts & put into vector
-    for (std::vector<MBEntityHandle>::iterator vit = ents.begin(); vit != ents.end(); vit++) {
+    for (std::vector<EntityHandle>::iterator vit = ents.begin(); vit != ents.end(); vit++) {
       result = retrieve_subdiv_verts(tet, *vit, &tet_conn[0], dim, subdiv_verts); RR;
     }
   }
@@ -222,7 +224,7 @@
 #define FSV(a,b) subdiv_verts[54+a*9+b]
 #define TSV(a,b) subdiv_verts[90+a*9+b]
 
-  MBEntityHandle this_connect[8], this_hex;
+  EntityHandle this_connect[8], this_hex;
 
     // first, interstices hexes, three per vertex/spherical surface
 // V0:
@@ -412,12 +414,12 @@
   return result;
 }
 
-MBErrorCode SphereDecomp::retrieve_subdiv_verts(MBEntityHandle tet, MBEntityHandle this_ent,
-                                  const MBEntityHandle *tet_conn,
-                                  const int dim, MBEntityHandle *subdiv_verts) 
+ErrorCode SphereDecomp::retrieve_subdiv_verts(EntityHandle tet, EntityHandle this_ent,
+                                  const EntityHandle *tet_conn,
+                                  const int dim, EntityHandle *subdiv_verts) 
 {
     // get the subdiv verts for this entity
-  MBErrorCode result;
+  ErrorCode result;
   
     // if it's a tet, just put them on the end & return
   if (tet == this_ent) {
@@ -427,7 +429,7 @@
   
     // if it's a sub-entity, need to find index, relative orientation, and offset
     // get connectivity of sub-entity
-  std::vector<MBEntityHandle> this_conn;
+  std::vector<EntityHandle> this_conn;
   result = mbImpl->get_connectivity(&this_ent, 1, this_conn); RR;
   
     // get relative orientation
@@ -441,13 +443,13 @@
   
     // start of this entity's subdiv_verts; edges go first, then preceding sides, then this one;
     // this assumes 6 edges/tet
-  MBEntityHandle *subdiv_start = &subdiv_verts[((dim-1)*6 + side_no) * 9];
+  EntityHandle *subdiv_start = &subdiv_verts[((dim-1)*6 + side_no) * 9];
   
     // get subdiv_verts and put them into proper place
   result = mbImpl->tag_get_data(subdivVerticesTag, &this_ent, 1, subdiv_start);
 
     // could probably do this more elegantly, but isn't worth it
-#define SWITCH(a,b) {MBEntityHandle tmp_handle = a; a = b; b = tmp_handle;}
+#define SWITCH(a,b) {EntityHandle tmp_handle = a; a = b; b = tmp_handle;}
   switch (dim) {
     case 1:
       if (offset != 0 || sense == -1) {

Modified: MOAB/trunk/tools/SphereDecomp.hpp
===================================================================
--- MOAB/trunk/tools/SphereDecomp.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/SphereDecomp.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,45 +1,45 @@
 #ifndef SPHERE_DECOMP_HPP
 #define SPHERE_DECOMP_HPP
 
-#include "MBInterface.hpp"
+#include "moab/Interface.hpp"
 
 class SphereDecomp 
 {
 public:
-  SphereDecomp(MBInterface *impl);
+  SphereDecomp(moab::Interface *impl);
 
-  MBErrorCode build_sphere_mesh(const char *sphere_radii_tag_name, 
-                                MBEntityHandle *hex_set = NULL);
+  moab::ErrorCode build_sphere_mesh(const char *sphere_radii_tag_name, 
+                                moab::EntityHandle *hex_set = NULL);
   
 private:
 
     //! compute subdivision vertices on entities of specified dimension
-  MBErrorCode compute_nodes(const int dim);
+  moab::ErrorCode compute_nodes(const int dim);
 
     //! subdivide tets based on subdiv vertices, returning in lists according
     //! to whether they're inside or outside spheres
-  MBErrorCode build_hexes(std::vector<MBEntityHandle> &sphere_hexes,
-                          std::vector<MBEntityHandle> &interstic_hexes);
+  moab::ErrorCode build_hexes(std::vector<moab::EntityHandle> &sphere_hexes,
+                          std::vector<moab::EntityHandle> &interstic_hexes);
   
     //! subdivide an individual tet
-  MBErrorCode subdivide_tet(MBEntityHandle tet, 
-                            std::vector<MBEntityHandle> &sphere_hexes,
-                            std::vector<MBEntityHandle> &interstic_hexes);
+  moab::ErrorCode subdivide_tet(moab::EntityHandle tet, 
+                            std::vector<moab::EntityHandle> &sphere_hexes,
+                            std::vector<moab::EntityHandle> &interstic_hexes);
   
     //! retrieve the subdivision vertices for a given entity in a given tet,
     //! placing them in the array oriented wrt the tet
-  MBErrorCode retrieve_subdiv_verts(MBEntityHandle tet, MBEntityHandle this_ent,
-                                    const MBEntityHandle *tet_conn,
-                                    const int dim, MBEntityHandle *subdiv_verts);
+  moab::ErrorCode retrieve_subdiv_verts(moab::EntityHandle tet, moab::EntityHandle this_ent,
+                                    const moab::EntityHandle *tet_conn,
+                                    const int dim, moab::EntityHandle *subdiv_verts);
   
     //! tag used to hold sphere radii (assigned to vertices)
-  MBTag sphereRadiiTag;
+  moab::Tag sphereRadiiTag;
 
     //! used to store subdiv vertices for a given d>0 entity
-  MBTag subdivVerticesTag;
+  moab::Tag subdivVerticesTag;
   
     //! MOAB interface ptr
-  MBInterface *mbImpl;
+  moab::Interface *mbImpl;
   
 };
 #endif

Modified: MOAB/trunk/tools/convert.cpp
===================================================================
--- MOAB/trunk/tools/convert.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/convert.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -20,10 +20,10 @@
 #  endif
 #endif
 
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBReaderWriterSet.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/ReaderWriterSet.hpp"
 #include <iostream>
 #include <iomanip>
 #include <set>
@@ -36,7 +36,7 @@
 #endif
 #include <time.h>
 #ifdef USE_MPI
-#  include "MBmpi.h"
+#  include "moab_mpi.h"
 #endif
 #include <stdio.h>
 
@@ -47,6 +47,8 @@
 #define OTHER_ERROR 4
 #define ENT_NOT_FOUND 5
 
+using namespace moab;
+
 /* Tag to control ACIS dump from .cub file reader */
 const char acis_dump_file_tag_name[] = "__ACISDumpFile";
 
@@ -121,13 +123,13 @@
 } 
 
 
-void list_formats( MBInterface* );
+void list_formats( Interface* );
 bool parse_id_list( const char* string, std::set<int>&  );
 void print_id_list( const char*, std::ostream& stream, const std::set<int>& list );
 void reset_times();
 void write_times( std::ostream& stream );
-void remove_entities_from_sets( MBInterface* gMB, MBRange& dead_entities, MBRange& empty_sets );
-void remove_from_vector( std::vector<MBEntityHandle>& vect, const MBRange& ents_to_remove );
+void remove_entities_from_sets( Interface* gMB, Range& dead_entities, Range& empty_sets );
+void remove_from_vector( std::vector<EntityHandle>& vect, const Range& ents_to_remove );
 bool make_opts_string( std::vector<std::string> options, std::string& result );
 
 int main(int argc, char* argv[])
@@ -137,12 +139,12 @@
 #endif
 
 
-  MBInterface* gMB;
-  MBErrorCode result;
-  MBRange range;
+  Interface* gMB;
+  ErrorCode result;
+  Range range;
 
   int proc_id = 0;
-  gMB = new MBCore();
+  gMB = new Core();
 
   bool append_rank = false;
   int i, dim;
@@ -152,7 +154,7 @@
   const char* out = NULL;   // output file name
   bool verbose = false;
   std::set<int> geom[4], mesh[3];       // user-specified IDs 
-  std::vector<MBEntityHandle> set_list; // list of user-specified sets to write
+  std::vector<EntityHandle> set_list; // list of user-specified sets to write
   std::vector<std::string> write_opts, read_opts;
   const char* const mesh_tag_names[] = { DIRICHLET_SET_TAG_NAME,
                                          NEUMANN_SET_TAG_NAME,
@@ -301,7 +303,7 @@
   bool have_sets = have_geom;
   
     // Get geometry tags
-  MBTag dim_tag, id_tag;
+  Tag dim_tag, id_tag;
   if (have_geom) 
   {
     int size;
@@ -341,7 +343,7 @@
   if ( have_geom ) 
   {
     int id_val;
-    MBTag tags[] = { id_tag, dim_tag };
+    Tag tags[] = { id_tag, dim_tag };
     const void* vals[] = { &id_val, &dim };
     for (dim = 0; dim <= 3; ++dim) 
     {
@@ -376,7 +378,7 @@
     have_sets = true;
     
       // Get tag
-    MBTag tag;
+    Tag tag;
     result = gMB->tag_get_handle( mesh_tag_names[i], tag );
     if (MB_SUCCESS != result) 
     {
@@ -431,23 +433,23 @@
  
     // Generate any internal entities
   if (generate[1] || generate[2]) {
-    MBEntityHandle all_mesh = 0;
-    const MBEntityHandle* sets = &all_mesh;
+    EntityHandle all_mesh = 0;
+    const EntityHandle* sets = &all_mesh;
     int num_sets = 1;
     if (have_sets) {
       num_sets = set_list.size();
       sets = &set_list[0];
     }
     for (i = 0; i < num_sets; ++i) {
-      MBRange dim3, dim2, adj;
+      Range dim3, dim2, adj;
       gMB->get_entities_by_dimension( sets[i], 3, dim3, true );
       if (generate[1]) {
         gMB->get_entities_by_dimension( sets[i], 2, dim2, true );
-        gMB->get_adjacencies( dim3, 1, true, adj, MBInterface::UNION );
-        gMB->get_adjacencies( dim2, 1, true, adj, MBInterface::UNION );
+        gMB->get_adjacencies( dim3, 1, true, adj, Interface::UNION );
+        gMB->get_adjacencies( dim2, 1, true, adj, Interface::UNION );
       }
       if (generate[2]) {
-        gMB->get_adjacencies( dim3, 2, true, adj, MBInterface::UNION );
+        gMB->get_adjacencies( dim3, 2, true, adj, Interface::UNION );
       }
       if (sets[i])
         gMB->add_entities( sets[i], adj );
@@ -457,7 +459,7 @@
     // Delete any entities not of the dimensions to be exported
   if (bydim) {
       // Get list of dead elements
-    MBRange dead_entities , tmp_range;
+    Range dead_entities , tmp_range;
     for (dim = 1; dim <= 3; ++dim) {
       if (dims[dim])
         continue;
@@ -466,13 +468,13 @@
     }
       // Remove dead entities from all sets, and add all 
       // empty sets to list of dead entities.
-    MBRange empty_sets;
+    Range empty_sets;
     remove_entities_from_sets( gMB, dead_entities, empty_sets );
     while (!empty_sets.empty()) {
       if (!set_list.empty())
         remove_from_vector( set_list, empty_sets );
       dead_entities.merge( empty_sets );
-      MBRange tmp_range;
+      Range tmp_range;
       remove_entities_from_sets( gMB, empty_sets, tmp_range );
       empty_sets = subtract( tmp_range,  dead_entities );
     }
@@ -716,23 +718,23 @@
 }
 
 
-void list_formats( MBInterface* gMB )
+void list_formats( Interface* gMB )
 {
-  const char iface_name[] = "MBReaderWriterSet";
-  MBErrorCode err;
+  const char iface_name[] = "ReaderWriterSet";
+  ErrorCode err;
   void* void_ptr = 0;
-  MBReaderWriterSet* set;
-  MBReaderWriterSet::iterator i;
+  ReaderWriterSet* set;
+  ReaderWriterSet::iterator i;
   std::ostream& str = std::cout;
     
-    // get MBReaderWriterSet
+    // get ReaderWriterSet
   err = gMB->query_interface( iface_name, &void_ptr );
   if (err != MB_SUCCESS || !void_ptr) {
     std::cerr << "Internal error:  Interface \"" << iface_name 
               << "\" not available.\n";
     exit(OTHER_ERROR);
   }
-  set = (MBReaderWriterSet*)void_ptr;
+  set = (ReaderWriterSet*)void_ptr;
   
     // get field with for format description
   size_t w = 0;
@@ -765,13 +767,13 @@
   exit(0);
 }
 
-void remove_entities_from_sets( MBInterface* gMB, MBRange& dead_entities, MBRange& empty_sets )
+void remove_entities_from_sets( Interface* gMB, Range& dead_entities, Range& empty_sets )
 {
   empty_sets.clear();
-  MBRange sets;
+  Range sets;
   gMB->get_entities_by_type( 0, MBENTITYSET, sets );
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
-    MBRange set_contents;
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
+    Range set_contents;
     gMB->get_entities_by_handle( *i, set_contents, false );
     set_contents = intersect( set_contents, dead_entities );
     gMB->remove_entities( *i, set_contents );
@@ -782,10 +784,10 @@
   }
 }
 
-void remove_from_vector( std::vector<MBEntityHandle>& vect, const MBRange& ents_to_remove )
+void remove_from_vector( std::vector<EntityHandle>& vect, const Range& ents_to_remove )
 {
-  MBRange::const_iterator i;
-  std::vector<MBEntityHandle>::iterator j;
+  Range::const_iterator i;
+  std::vector<EntityHandle>::iterator j;
   for (i = ents_to_remove.begin(); i != ents_to_remove.end(); ++i) {
     j = std::find( vect.begin(), vect.end(), *i );
     if (j != vect.end())

Modified: MOAB/trunk/tools/dagmc/CMakeLists.txt
===================================================================
--- MOAB/trunk/tools/dagmc/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -6,8 +6,6 @@
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${MOAB_BINARY_DIR}/src
   ${MOAB_SOURCE_DIR}/src
-  ${MOAB_BINARY_DIR}/src/moab
-  ${MOAB_SOURCE_DIR}/src/moab
 )
 
 set( MOAB_DAGMC_LIB_SRCS

Modified: MOAB/trunk/tools/dagmc/DagMC.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/DagMC.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,9 @@
 #include "DagMC.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCartVect.hpp"
-#include "MBRange.hpp"
-#include "MBCore.hpp"
-#include "MBGeomUtil.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/Range.hpp"
+#include "moab/Core.hpp"
+#include "moab/GeomUtil.hpp"
 #include "FileOptions.hpp"
 
 #ifdef CGM
@@ -51,6 +51,8 @@
 
 #define MBI moab_instance()
 
+namespace moab {
+
 DagMC *DagMC::instance_ = NULL;
 
 const bool debug = false;
@@ -63,9 +65,9 @@
 }
   
 
-void DagMC::create_instance(MBInterface *mb_impl) 
+void DagMC::create_instance(Interface *mb_impl) 
 {
-  if (NULL == mb_impl) mb_impl = new MBCore();
+  if (NULL == mb_impl) mb_impl = new Core();
   instance_ = new DagMC(mb_impl);
 }
 
@@ -88,7 +90,7 @@
   }
 }
 
-DagMC::DagMC(MBInterface *mb_impl) 
+DagMC::DagMC(Interface *mb_impl) 
   : mbImpl(mb_impl), obbTree(mb_impl), have_cgm_geom(false)
 {
     // This is the correct place to uniquely define default values for the dagmc settings
@@ -117,10 +119,10 @@
   
   geomTag = get_tag( GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER );
 
-  obbTag = get_tag( MB_OBB_TREE_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
+  obbTag = get_tag( MB_OBB_TREE_TAG_NAME, sizeof(EntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
   
     // get sense of surfaces wrt volumes
-  senseTag = get_tag( "GEOM_SENSE_2", 2*sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
+  senseTag = get_tag( "GEOM_SENSE_2", 2*sizeof(EntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
 
   int matid = 0;
   const void *def_matid = &matid;
@@ -135,13 +137,13 @@
 
 }
 
-MBErrorCode DagMC::ray_fire(const MBEntityHandle vol, const MBEntityHandle last_surf_hit, 
+ErrorCode DagMC::ray_fire(const EntityHandle vol, const EntityHandle last_surf_hit, 
                              const int num_pts,
                              const double uuu, const double vvv, const double www,
                              const double xxx, const double yyy, const double zzz,
                              const double huge_val,
-                             double &dist_traveled, MBEntityHandle &next_surf_hit, 
-                             MBOrientedBoxTreeTool::TrvStats* stats ) 
+                             double &dist_traveled, EntityHandle &next_surf_hit, 
+                             OrientedBoxTreeTool::TrvStats* stats ) 
 {
   if (debug) {
     std::cout << "Vol " << id_by_index(3, index_by_handle(vol)) << ", xyz = " 
@@ -152,13 +154,13 @@
   
   assert(vol - setOffset < rootSets.size());
   
-  MBEntityHandle root = rootSets[vol - setOffset];
-  MBErrorCode rval;
+  EntityHandle root = rootSets[vol - setOffset];
+  ErrorCode rval;
     // delcare some stuff static so we don't need to re-created
     // it for every call
   std::vector<double> &distances = distList;
-  std::vector<MBEntityHandle> &surfaces = surfList;
-  std::vector<MBEntityHandle> &facets = facetList;
+  std::vector<EntityHandle> &surfaces = surfList;
+  std::vector<EntityHandle> &facets = facetList;
   
   
     // do ray fire
@@ -395,21 +397,21 @@
 
 // helper function for point_in_volume_slow.  calculate area of a polygon 
 // projected into a unit-sphere space
-MBErrorCode DagMC::poly_solid_angle( MBEntityHandle face, const MBCartVect& point, double& area )
+ErrorCode DagMC::poly_solid_angle( EntityHandle face, const CartVect& point, double& area )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // Get connectivity
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len;
   rval = MBI->get_connectivity( face, conn, len, true );
   if (MB_SUCCESS != rval)
     return rval;
   
     // Allocate space to store vertices
-  MBCartVect coords_static[4];
-  std::vector<MBCartVect> coords_dynamic;
-  MBCartVect* coords = coords_static;
+  CartVect coords_static[4];
+  std::vector<CartVect> coords_dynamic;
+  CartVect* coords = coords_static;
   if ((unsigned)len > (sizeof(coords_static)/sizeof(coords_static[0]))) {
     coords_dynamic.resize(len);
     coords = &coords_dynamic[0];
@@ -421,7 +423,7 @@
     return rval;
   
     // calculate normal
-  MBCartVect norm(0.0), v1, v0 = coords[1] - coords[0];
+  CartVect norm(0.0), v1, v0 = coords[1] - coords[0];
   for (int i = 2; i < len; ++i) {
     v1 = coords[i] - coords[0];
     norm += v0 * v1;
@@ -431,7 +433,7 @@
     // calculate area
   double s, ang;
   area = 0.0;
-  MBCartVect r, n1, n2, b, a = coords[len-1] - coords[0];
+  CartVect r, n1, n2, b, a = coords[len-1] - coords[0];
   for (int i = 0; i < len; ++i) {
     r = coords[i] - point;
     b = coords[(i+1)%len] - coords[i];
@@ -452,16 +454,16 @@
   
   
 // use spherical area test to determine inside/outside of a polyhedron.
-MBErrorCode DagMC::point_in_volume_slow( MBEntityHandle volume,
+ErrorCode DagMC::point_in_volume_slow( EntityHandle volume,
                                   double x, double y, double z,
                                   int& result )
 {
-  MBErrorCode rval;
-  MBRange faces;
-  std::vector<MBEntityHandle> surfs;
+  ErrorCode rval;
+  Range faces;
+  std::vector<EntityHandle> surfs;
   std::vector<int> senses;
   double sum = 0.0;
-  const MBCartVect point(x,y,z);
+  const CartVect point(x,y,z);
   
   rval = MBI->get_child_meshsets( volume, surfs );
   if (MB_SUCCESS != rval)
@@ -482,7 +484,7 @@
     if (MB_SUCCESS != rval)
       return rval;
     
-    for (MBRange::iterator j = faces.begin(); j != faces.end(); ++j) {
+    for (Range::iterator j = faces.begin(); j != faces.end(); ++j) {
       rval = poly_solid_angle( *j, point, face_area );
       if (MB_SUCCESS != rval)
         return rval;
@@ -502,19 +504,19 @@
 // result= 1 -> inside volume or entering volume
 // result= 0 -> outside volume or leaving volume
 // result=-1 -> on boundary with null or tangent uvw
-MBErrorCode DagMC::boundary_case( MBEntityHandle volume, int& result, 
+ErrorCode DagMC::boundary_case( EntityHandle volume, int& result, 
 				  double u, double v, double w,
-				  MBEntityHandle facet,
-				  MBEntityHandle surface)
+				  EntityHandle facet,
+				  EntityHandle surface)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
   // test to see if uvx is provided
   if ( u <= 1.0 && v <= 1.0 && w <= 1.0 ) {
 
-    const MBCartVect ray_vector(u, v, w);
-    MBCartVect coords[3], normal(0.0);
-    const MBEntityHandle *conn;
+    const CartVect ray_vector(u, v, w);
+    CartVect coords[3], normal(0.0);
+    const EntityHandle *conn;
     int len, sense_out;
    
     rval = mbImpl->get_connectivity( facet, conn, len );
@@ -567,22 +569,22 @@
 // that edge is at a concavity wrt the volume.  If the point is closest
 // to a vertex in the facetting, it relies on the fact that the closest
 // vertex cannot be a saddle: it must be a strict concavity or convexity.
-MBErrorCode DagMC::point_in_volume( MBEntityHandle volume, 
+ErrorCode DagMC::point_in_volume( EntityHandle volume, 
                              double x, double y, double z,
                              int& result,
 			     double u, double v, double w)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   const double epsilon = discardDistTol;
 
     // Get OBB Tree for volume
   assert(volume - setOffset < rootSets.size());
-  MBEntityHandle root = rootSets[volume - setOffset];
+  EntityHandle root = rootSets[volume - setOffset];
 
     // Get closest point in triangulation
-  const MBCartVect point(x,y,z);
-  MBEntityHandle facet, surface;
-  MBCartVect closest, diff;
+  const CartVect point(x,y,z);
+  EntityHandle facet, surface;
+  CartVect closest, diff;
   rval = obbTree.closest_to_location( point.array(), root, closest.array(), facet, &surface );
   if (MB_SUCCESS != rval)  return rval;
   
@@ -593,16 +595,16 @@
   }
   
     // Get triangles at closest point
-  std::vector<MBEntityHandle> &tris = triList, &surfs = surfList;
+  std::vector<EntityHandle> &tris = triList, &surfs = surfList;
   tris.clear();
   surfs.clear();
   rval = obbTree.sphere_intersect_triangles( closest.array(), epsilon, root, tris, &surfs );
   if (MB_SUCCESS != rval) return rval;
   
     // One-triangle case : determine if point is above or below triangle
-  const MBEntityHandle* conn;
+  const EntityHandle* conn;
   int len, sense;
-  MBCartVect coords[3], normal;
+  CartVect coords[3], normal;
   if (tris.size() == 1) {
     rval = MBI->get_connectivity( tris.front(), conn, len );
     if (MB_SUCCESS != rval || len != 3) 
@@ -703,17 +705,17 @@
 }
 
 // detemine distance to nearest surface
-MBErrorCode DagMC::closest_to_location( MBEntityHandle volume, double* coords, double& result)
+ErrorCode DagMC::closest_to_location( EntityHandle volume, double* coords, double& result)
 {
     // Get OBB Tree for volume
   assert(volume - setOffset < rootSets.size());
-  MBEntityHandle root = rootSets[volume - setOffset];
+  EntityHandle root = rootSets[volume - setOffset];
 
     // Get closest triangles in volume
-  const MBCartVect point(coords);
-  MBCartVect nearest;
-  MBEntityHandle facet_out;
-  MBErrorCode rval = obbTree.closest_to_location( point.array(), root, nearest.array(), facet_out );
+  const CartVect point(coords);
+  CartVect nearest;
+  EntityHandle facet_out;
+  ErrorCode rval = obbTree.closest_to_location( point.array(), root, nearest.array(), facet_out );
   if (MB_SUCCESS != rval) return rval;
 
   // calculate distance between point and nearest facet
@@ -727,10 +729,10 @@
 
 
 // calculate volume of polyhedron
-MBErrorCode DagMC::measure_volume( MBEntityHandle volume, double& result )
+ErrorCode DagMC::measure_volume( EntityHandle volume, double& result )
 {
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> surfaces, surf_volumes;
+  ErrorCode rval;
+  std::vector<EntityHandle> surfaces, surf_volumes;
   result = 0.0;
   
    // don't try to calculate volume of implicit complement
@@ -758,7 +760,7 @@
       continue;
     
       // get triangles in surface
-    MBRange triangles;
+    Range triangles;
     rval = MBI->get_entities_by_dimension( surfaces[i], 2, triangles );
     if (MB_SUCCESS != rval) 
       return rval;
@@ -773,10 +775,10 @@
     
       // calculate signed volume beneath surface (x 6.0)
     double surf_sum = 0.0;
-    const MBEntityHandle *conn;
+    const EntityHandle *conn;
     int len;
-    MBCartVect coords[3];
-    for (MBRange::iterator j = triangles.begin(); j != triangles.end(); ++j) {
+    CartVect coords[3];
+    for (Range::iterator j = triangles.begin(); j != triangles.end(); ++j) {
       rval = MBI->get_connectivity( *j, conn, len, true );
       if (MB_SUCCESS != rval) return rval;
       assert(3 == len);
@@ -795,11 +797,11 @@
 }
 
 // sum area of elements in surface
-MBErrorCode DagMC::measure_area( MBEntityHandle surface, double& result )
+ErrorCode DagMC::measure_area( EntityHandle surface, double& result )
 {
     // get triangles in surface
-  MBRange triangles;
-  MBErrorCode rval = MBI->get_entities_by_dimension( surface, 2, triangles );
+  Range triangles;
+  ErrorCode rval = MBI->get_entities_by_dimension( surface, 2, triangles );
   if (MB_SUCCESS != rval) 
     return rval;
   if (!triangles.all_of_type(MBTRI)) {
@@ -813,10 +815,10 @@
 
     // calculate sum of area of triangles
   result = 0.0;
-  const MBEntityHandle *conn;
+  const EntityHandle *conn;
   int len;
-  MBCartVect coords[3];
-  for (MBRange::iterator j = triangles.begin(); j != triangles.end(); ++j) {
+  CartVect coords[3];
+  for (Range::iterator j = triangles.begin(); j != triangles.end(); ++j) {
     rval = MBI->get_connectivity( *j, conn, len, true );
     if (MB_SUCCESS != rval) return rval;
     assert(3 == len);
@@ -833,9 +835,9 @@
 }
 
 // get sense of surface(s) wrt volume
-MBErrorCode DagMC::surface_sense( MBEntityHandle volume, 
+ErrorCode DagMC::surface_sense( EntityHandle volume, 
                            int num_surfaces,
-                           const MBEntityHandle* surfaces,
+                           const EntityHandle* surfaces,
                            int* senses_out )
 {
 
@@ -843,17 +845,17 @@
      All surfaces that interact with the implicit complement should have
      a null handle in the direction of the implicit complement. */
   if (volume == impl_compl_handle)
-    volume = (MBEntityHandle) 0;
+    volume = (EntityHandle) 0;
 
-  std::vector<MBEntityHandle> surf_volumes( 2*num_surfaces );
-  MBErrorCode rval = MBI->tag_get_data( sense_tag(), surfaces, num_surfaces, &surf_volumes[0] );
+  std::vector<EntityHandle> surf_volumes( 2*num_surfaces );
+  ErrorCode rval = MBI->tag_get_data( sense_tag(), surfaces, num_surfaces, &surf_volumes[0] );
   if (MB_SUCCESS != rval)  return rval;
   
-  const MBEntityHandle* end = surfaces + num_surfaces;
-  std::vector<MBEntityHandle>::const_iterator surf_vols = surf_volumes.begin();
+  const EntityHandle* end = surfaces + num_surfaces;
+  std::vector<EntityHandle>::const_iterator surf_vols = surf_volumes.begin();
   while (surfaces != end) {
-    MBEntityHandle forward = *surf_vols; ++surf_vols;
-    MBEntityHandle reverse = *surf_vols; ++surf_vols;
+    EntityHandle forward = *surf_vols; ++surf_vols;
+    EntityHandle reverse = *surf_vols; ++surf_vols;
     if (volume == forward) 
       *senses_out = (volume != reverse); // zero if both, otherwise 1
     else if (volume == reverse)
@@ -869,19 +871,19 @@
 }
 
 // get sense of surface(s) wrt volume
-MBErrorCode DagMC::surface_sense( MBEntityHandle volume, 
-                                  MBEntityHandle surface,
+ErrorCode DagMC::surface_sense( EntityHandle volume, 
+                                  EntityHandle surface,
                                   int& sense_out )
 {
   /* The sense tags do not reference the implicit complement handle.
      All surfaces that interact with the implicit complement should have
      a null handle in the direction of the implicit complement. */
   if (volume == impl_compl_handle)
-    volume = (MBEntityHandle) 0;
+    volume = (EntityHandle) 0;
 
     // get sense of surfaces wrt volumes
-  MBEntityHandle surf_volumes[2];
-  MBErrorCode rval = MBI->tag_get_data( sense_tag(), &surface, 1, surf_volumes );
+  EntityHandle surf_volumes[2];
+  ErrorCode rval = MBI->tag_get_data( sense_tag(), &surface, 1, surf_volumes );
   if (MB_SUCCESS != rval)  return rval;
   
   if (surf_volumes[0] == volume)
@@ -894,10 +896,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DagMC::load_file(const char* cfile,
+ErrorCode DagMC::load_file(const char* cfile,
 			     const double facet_tolerance)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
 #ifdef CGM
   // cgm must be initialized so we can check it for CAD data after the load
@@ -942,12 +944,12 @@
 
 }
 
-MBErrorCode DagMC::init_OBBTree() 
+ErrorCode DagMC::init_OBBTree() 
 {
 
-  MBErrorCode rval;
+  ErrorCode rval;
 
-  MBRange surfs, vols;
+  Range surfs, vols;
   const int three = 3;
   const void* const three_val[] = {&three};
   rval = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &geomTag, 
@@ -991,10 +993,10 @@
 }
 
 
-MBErrorCode DagMC::write_mesh(const char* ffile,
+ErrorCode DagMC::write_mesh(const char* ffile,
 			      const int flen)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   
     // write out a mesh file if requested
   if (ffile && 0 < flen) {
@@ -1011,21 +1013,21 @@
 
 bool DagMC::have_obb_tree()
 {
-  MBRange entities;
-  MBErrorCode rval = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET,
+  Range entities;
+  ErrorCode rval = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET,
                                                            &obbTag, 0, 1,
                                                            entities );
   return MB_SUCCESS == rval && !entities.empty();
 }                                                    
 
-MBEntityHandle DagMC::entity_by_id( int dimension, int id )
+EntityHandle DagMC::entity_by_id( int dimension, int id )
 {
   assert(0 <= dimension && 3 >= dimension);
-  const MBTag tags[] = { idTag, geomTag };
+  const Tag tags[] = { idTag, geomTag };
   const void* const vals[] = { &id, &dimension };
-  MBErrorCode rval;
+  ErrorCode rval;
   
-  MBRange results;
+  Range results;
   rval = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, tags, vals, 2, results );
   if (MB_SUCCESS != rval || results.empty())
     return 0;
@@ -1035,7 +1037,7 @@
 
 int DagMC::id_by_index( int dimension, int index )
 {
-  MBEntityHandle h = entity_by_index( dimension, index );
+  EntityHandle h = entity_by_index( dimension, index );
   if (!h)
     return 0;
   
@@ -1062,7 +1064,7 @@
 
 
 
-MBErrorCode DagMC::write_mcnp(std::string ifile, const bool overwrite) 
+ErrorCode DagMC::write_mcnp(std::string ifile, const bool overwrite) 
 {
   std::map<std::string,int> tallyKeywords;
   
@@ -1073,7 +1075,7 @@
   tallyKeywords["cell.fission"] = 7;
   tallyKeywords["pulse.height"] = 8;
 
-  std::vector<MBEntityHandle>::iterator iter;
+  std::vector<EntityHandle>::iterator iter;
 
   if (!overwrite) {
       // if not overwriting, test for file, and if it exists, just return;
@@ -1093,10 +1095,10 @@
   std::cout << " # groups: " << group_handles().size()-1 << std::endl;
   std::cout << "# tallies: " << tallyList.size() << std::endl;
 
-  MBRange grp_sets, grp_ents;
-  MBErrorCode rval;
+  Range grp_sets, grp_ents;
+  ErrorCode rval;
 
-  MBRange surfs, vols;
+  Range surfs, vols;
 
 
   // write cell information (skip first entry)             
@@ -1157,7 +1159,7 @@
     
     std::stringstream tallyCard;
     
-    MBEntityHandle group = group_handles()[*grp];
+    EntityHandle group = group_handles()[*grp];
     grp_names.clear();
     bool success = get_group_names(group, grp_names);
     if (!success)
@@ -1216,13 +1218,13 @@
 
     // get entities of correct dimension
     const void* dim_val[] = {&dim};
-    MBRange ents;
+    Range ents;
     rval = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &geomTag, dim_val, 1, ents );
     if (MB_SUCCESS != rval)
       return rval;
-    MBRange  grp_ents = intersect(grp_sets,ents);
+    Range  grp_ents = intersect(grp_sets,ents);
 
-    for (MBRange::iterator ent = grp_ents.begin(); ent != grp_ents.end(); ent++)
+    for (Range::iterator ent = grp_ents.begin(); ent != grp_ents.end(); ent++)
       tallyCard << " " << get_entity_id(*ent);
 
     tallyCard << " T";
@@ -1257,22 +1259,22 @@
 //    b) check for b.c. -> get list of surfaces and tag b.c.
 //    c) check for graveyard -> tag imp
 
-MBErrorCode DagMC::parse_metadata()
+ErrorCode DagMC::parse_metadata()
 {
   std::vector<std::string> grp_names;
   std::vector<std::string> tokens;
   std::map<std::string,int> keywords;
 
-  MBEntityHandle group;
-  MBRange grp_sets, grp_ents;
-  MBErrorCode rval;
+  EntityHandle group;
+  Range grp_sets, grp_ents;
+  ErrorCode rval;
 
-  MBRange vols, surfs;
+  Range vols, surfs;
 
   std::copy(vol_handles().begin()+1,  vol_handles().end(),
-	    mb_range_inserter(vols));
+	    range_inserter(vols));
   std::copy(surf_handles().begin()+1, surf_handles().end(),
-	    mb_range_inserter(surfs));
+	    range_inserter(surfs));
 
   keywords["mat"]           = MAT_GROUP;
   keywords["spec.reflect"]  = BC_SPEC;
@@ -1390,13 +1392,13 @@
   return s.str();
 }
 
-bool DagMC::get_group_names(MBEntityHandle group_set, 
+bool DagMC::get_group_names(EntityHandle group_set, 
                              std::vector<std::string> &grp_names) 
 {
     // get names
   char name0[NAME_TAG_SIZE];
   std::fill(name0, name0+NAME_TAG_SIZE, '\0');
-  MBErrorCode result = MBI->tag_get_data(name_tag(), &group_set, 1,
+  ErrorCode result = MBI->tag_get_data(name_tag(), &group_set, 1,
                                                      &name0);
   if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) return false;
 
@@ -1406,7 +1408,7 @@
   while (true) {
     sprintf(name0, "%s%s%d", "EXTRA_", NAME_TAG_NAME, extra_num);
     extra_num++;
-    MBTag this_tag = get_tag(name0, NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE, 
+    Tag this_tag = get_tag(name0, NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE, 
                              false);
     if (0 == this_tag) break;
     std::fill(name0, name0+NAME_TAG_SIZE, '\0');
@@ -1419,12 +1421,12 @@
   return true;
 }
 
-MBTag DagMC::get_tag( const char* name, int size, MBTagType store, 
-		      MBDataType type, const void* def_value,
+Tag DagMC::get_tag( const char* name, int size, TagType store, 
+		      DataType type, const void* def_value,
 		      bool create_if_missing) 
 {
-  MBTag retval = 0;
-  MBErrorCode result = MBI->tag_create(name, size, store, type,
+  Tag retval = 0;
+  ErrorCode result = MBI->tag_create(name, size, store, type,
                                                    retval, def_value, create_if_missing);
   if (create_if_missing && MB_SUCCESS != result) 
     std::cerr << "Couldn't find nor create tag named " << name << std::endl;
@@ -1432,29 +1434,29 @@
   return retval;
 }
 
-int DagMC::get_entity_id(MBEntityHandle this_ent) 
+int DagMC::get_entity_id(EntityHandle this_ent) 
 {
   int id = 0;
-  MBErrorCode result = MBI->tag_get_data(idTag, &this_ent, 1, &id);
+  ErrorCode result = MBI->tag_get_data(idTag, &this_ent, 1, &id);
   if (MB_TAG_NOT_FOUND == result)
     id = MBI->id_from_handle(this_ent);
     
   return id;
 }
 
-MBErrorCode DagMC::get_angle(MBEntityHandle surf, 
+ErrorCode DagMC::get_angle(EntityHandle surf, 
                               double xxx, double yyy, double zzz, double *ang)
 {
-  MBEntityHandle root = rootSets[surf - setOffset];
+  EntityHandle root = rootSets[surf - setOffset];
   
   const double in_pt[] = { xxx, yyy, zzz };
-  std::vector<MBEntityHandle> &facets = triList;
+  std::vector<EntityHandle> &facets = triList;
   facets.clear();
-  MBErrorCode rval = obbTree.closest_to_location( in_pt, root, add_dist_tol(), facets );
+  ErrorCode rval = obbTree.closest_to_location( in_pt, root, add_dist_tol(), facets );
   assert(MB_SUCCESS == rval);
   
-  MBCartVect coords[3], normal(0.0);
-  const MBEntityHandle *conn;
+  CartVect coords[3], normal(0.0);
+  const EntityHandle *conn;
   int len;
   for (unsigned i = 0; i < facets.size(); ++i) {
     rval = mbImpl->get_connectivity( facets[i], conn, len );
@@ -1475,11 +1477,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DagMC::CAD_ray_intersect(const double *point, 
+ErrorCode DagMC::CAD_ray_intersect(const double *point, 
                                       const double *dir, 
                                       const double huge_val,
                                       std::vector<double> &distances,
-                                      std::vector<MBEntityHandle> &surfaces, 
+                                      std::vector<EntityHandle> &surfaces, 
                                       double &len) 
 {
 #ifdef CGM
@@ -1487,7 +1489,7 @@
   return MB_NOT_IMPLEMENTED;
 #else
   std::vector<double>::iterator dit = distances.begin();
-  std::vector<MBEntityHandle>::iterator sit = surfaces.begin();
+  std::vector<EntityHandle>::iterator sit = surfaces.begin();
   static DLIList<double> ray_params;
   
   for (; dit != distances.end(); dit++, sit++) {
@@ -1517,7 +1519,7 @@
         double tmp_dist = *dit;
         *dit = *(dit+1);
         *(dit+1) = tmp_dist;
-        MBEntityHandle tmp_hand = *sit;
+        EntityHandle tmp_hand = *sit;
         *sit = *(sit+1);
         *(sit+1) = tmp_hand;
         done = false;
@@ -1534,15 +1536,15 @@
 #endif
 }
 
-MBErrorCode DagMC::build_indices(MBRange &surfs, MBRange &vols)
+ErrorCode DagMC::build_indices(Range &surfs, Range &vols)
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
 
     // surf/vol offsets are just first handles
   setOffset = (*surfs.begin() < *vols.begin() ? *surfs.begin() : *vols.begin());
   setOffset = (impl_compl_handle < setOffset ? impl_compl_handle : setOffset);
     // max
-  MBEntityHandle tmp_offset = (surfs.back() > vols.back() ? 
+  EntityHandle tmp_offset = (surfs.back() > vols.back() ? 
                                surfs.back() : vols.back());
   tmp_offset = (impl_compl_handle > tmp_offset ? 
                 impl_compl_handle : tmp_offset);
@@ -1553,11 +1555,11 @@
     // store surf/vol handles lists (surf/vol by index) and
     // index by handle lists
   surf_handles().resize( surfs.size() + 1 );
-  std::vector<MBEntityHandle>::iterator iter = surf_handles().begin();
+  std::vector<EntityHandle>::iterator iter = surf_handles().begin();
   *(iter++) = 0;
   std::copy( surfs.begin(), surfs.end(), iter );
   int idx = 1;
-  for (MBRange::iterator rit = surfs.begin(); rit != surfs.end(); rit++)
+  for (Range::iterator rit = surfs.begin(); rit != surfs.end(); rit++)
     entIndices[*rit-setOffset] = idx++;
   
   vol_handles().resize( vols.size() + 1 );
@@ -1567,7 +1569,7 @@
   vol_handles().push_back(impl_compl_handle);
   idx = 1;
   int max_id = -1;
-  for (MBRange::iterator rit = vols.begin(); rit != vols.end(); rit++)    {
+  for (Range::iterator rit = vols.begin(); rit != vols.end(); rit++)    {
     entIndices[*rit-setOffset] = idx++;
     int result=0;
     MBI->tag_get_data( idTag, &*rit, 1, &result );
@@ -1594,7 +1596,7 @@
     rval = MBI->tag_get_data(id_tag(), surfs, &ids[0]);
     if (MB_SUCCESS != rval) return MB_FAILURE;
     int i = 0;
-    MBRange::iterator rit = surfs.begin();
+    Range::iterator rit = surfs.begin();
     for (; rit != surfs.end(); rit++, i++) {
       RefEntity *this_surf = GeometryQueryTool::instance()->
         get_ref_face(ids[i]);
@@ -1616,13 +1618,13 @@
 #endif  
 
     // get group handles
-  MBTag category_tag = get_tag(CATEGORY_TAG_NAME, CATEGORY_TAG_LENGTH, 
+  Tag category_tag = get_tag(CATEGORY_TAG_NAME, CATEGORY_TAG_LENGTH, 
                                MB_TAG_SPARSE, MB_TYPE_OPAQUE);
   char group_category[CATEGORY_TAG_SIZE];
   std::fill(group_category, group_category+CATEGORY_TAG_SIZE, '\0');
   sprintf(group_category, "%s", "Group");
   const void* const group_val[] = {&group_category};
-  MBRange groups;
+  Range groups;
   rval = MBI->get_entities_by_type_and_tag(0, MBENTITYSET, &category_tag, 
 					   group_val, 1, groups);
   if (MB_SUCCESS != rval)
@@ -1632,11 +1634,11 @@
   std::copy(groups.begin(), groups.end(), &group_handles()[1]);
 
     // populate root sets vector
-  std::vector<MBEntityHandle> rsets;
+  std::vector<EntityHandle> rsets;
   rsets.resize(surfs.size());
   rval = MBI->tag_get_data(obb_tag(), surfs, &rsets[0]);
   if (MB_SUCCESS != rval) return MB_FAILURE;
-  MBRange::iterator rit;
+  Range::iterator rit;
   int i;
   for (i = 0, rit = surfs.begin(); rit != surfs.end(); rit++, i++)
     rootSets[*rit-setOffset] = rsets[i];
@@ -1657,13 +1659,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DagMC::build_obbs(MBRange &surfs, MBRange &vols) 
+ErrorCode DagMC::build_obbs(Range &surfs, Range &vols) 
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   
-  for (MBRange::iterator i = surfs.begin(); i != surfs.end(); ++i) {
-    MBEntityHandle root;
-    MBRange tris;
+  for (Range::iterator i = surfs.begin(); i != surfs.end(); ++i) {
+    EntityHandle root;
+    Range tris;
     rval = MBI->get_entities_by_dimension( *i, 2, tris );
     if (MB_SUCCESS != rval) 
       return rval;
@@ -1680,17 +1682,17 @@
       return rval;
   }
   
-  for (MBRange::iterator i = vols.begin(); i != vols.end(); ++i) {
+  for (Range::iterator i = vols.begin(); i != vols.end(); ++i) {
       // get all surfaces in volume
-    MBRange tmp_surfs;
+    Range tmp_surfs;
     rval = MBI->get_child_meshsets( *i, tmp_surfs );
     if (MB_SUCCESS != rval)
       return rval;
     
       // get OBB trees for each surface
-    MBEntityHandle root;
-    MBRange trees;
-    for (MBRange::iterator j = tmp_surfs.begin();  j != tmp_surfs.end(); ++j) {
+    EntityHandle root;
+    Range trees;
+    for (Range::iterator j = tmp_surfs.begin();  j != tmp_surfs.end(); ++j) {
         // skip any surfaces that are non-manifold in the volume
         // because point containment code will get confused by them
       int sense;
@@ -1728,15 +1730,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DagMC::build_obb_impl_compl(MBRange &surfs) 
+ErrorCode DagMC::build_obb_impl_compl(Range &surfs) 
 {
-  MBEntityHandle comp_root, surf_obb_root;
-  MBRange comp_tree;
-  MBErrorCode rval;
-  std::vector<MBEntityHandle> parent_vols;
+  EntityHandle comp_root, surf_obb_root;
+  Range comp_tree;
+  ErrorCode rval;
+  std::vector<EntityHandle> parent_vols;
   
     // search through all surfaces  
-  for (MBRange::iterator surf_i = surfs.begin(); surf_i != surfs.end(); ++surf_i) {
+  for (Range::iterator surf_i = surfs.begin(); surf_i != surfs.end(); ++surf_i) {
     
     parent_vols.clear();
       // get parents of each surface
@@ -1771,13 +1773,13 @@
 
 }
 
-MBErrorCode DagMC::getobb(MBEntityHandle volume, double minPt[3],
+ErrorCode DagMC::getobb(EntityHandle volume, double minPt[3],
                           double maxPt[3])
 {
   double center[3], axis1[3], axis2[3], axis3[3];
  
     // get center point and vectors to OBB faces
-  MBErrorCode rval = getobb(volume, center, axis1, axis2, axis3);
+  ErrorCode rval = getobb(volume, center, axis1, axis2, axis3);
   if (MB_SUCCESS != rval)
     return rval;
      
@@ -1791,22 +1793,22 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DagMC::getobb(MBEntityHandle volume, double center[3], double axis1[3],
+ErrorCode DagMC::getobb(EntityHandle volume, double center[3], double axis1[3],
                           double axis2[3], double axis3[3])
 {
-    //find MBEntityHandle node_set for use in box
-  MBEntityHandle root = rootSets[volume - setOffset];
+    //find EntityHandle node_set for use in box
+  EntityHandle root = rootSets[volume - setOffset];
   
     // call box to get center and vectors to faces
   return obbTree.box(root, center, axis1, axis2, axis3);
   
 }
 
-MBErrorCode DagMC::get_impl_compl()
+ErrorCode DagMC::get_impl_compl()
 {
-  MBRange entities;
+  Range entities;
   const void* const tagdata[] = {implComplName};
-  MBErrorCode rval = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET,
+  ErrorCode rval = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET,
                                                            &nameTag, tagdata, 1,
                                                            entities );
   // query error
@@ -1843,5 +1845,7 @@
   }
   
   
-}                                                    
+}
 
+} // namespace moab
+

Modified: MOAB/trunk/tools/dagmc/DagMC.hpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/DagMC.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,21 +1,23 @@
 #ifndef MOABMC_HPP
 #define MOABMC_HPP
 
-#include "MBInterface.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBTagConventions.hpp"
 
 #include <vector>
 #include <string>
 #include <assert.h>
 
-#include "MBOrientedBoxTreeTool.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
 
-class MBCartVect;
-
 #ifdef CGM
 class RefEntity;
 #endif
 
+namespace moab {
+
+class CartVect;
+
 #define DAGMC_VERSION 0.99
 #define DAGMC_VERSION_STRING "0.99"
 #define DAGMC_INTERFACE_REVISION "$Rev$"
@@ -23,73 +25,73 @@
 class DagMC 
 {
 public:
-  static DagMC *instance(MBInterface *mb_impl = NULL);
+  static DagMC *instance(Interface *mb_impl = NULL);
   
   ~DagMC();
   
     // Return the version of this library
   float version(std::string *version_string = NULL);
 
-  MBErrorCode ray_fire(const MBEntityHandle cell, const MBEntityHandle last_surf_hit, 
+  ErrorCode ray_fire(const EntityHandle cell, const EntityHandle last_surf_hit, 
                        const int num_pts,
                        const double uuu, const double vvv, const double www,
                        const double xxx, const double yyy, const double zzz,
                        const double huge_val,
-                       double &dist_traveled, MBEntityHandle &next_surf_hit,
-                       MBOrientedBoxTreeTool::TrvStats* stats = NULL );
+                       double &dist_traveled, EntityHandle &next_surf_hit,
+                       OrientedBoxTreeTool::TrvStats* stats = NULL );
 
     // Test if point is inside or outside of a volume using unit sphere area method
     // Requires sense of surfaces wrt volume.
     // Return values: {0 : outside, 1: inside, -1: on boundary}
-  MBErrorCode point_in_volume_slow( MBEntityHandle volume, 
+  ErrorCode point_in_volume_slow( EntityHandle volume, 
                                     double x, double y, double z,
                                     int& result );
 
     // Test if point is inside or outside of a volume using an OBB tree
     // Requires sense of surfaces wrt volume.
     // Return values: {0 : outside, 1: inside, -1: on boundary}
-  MBErrorCode point_in_volume( MBEntityHandle volume, 
+  ErrorCode point_in_volume( EntityHandle volume, 
                                double x, double y, double z,
                                int& result,
                                double u, double v, double w);
 
     // Find the distance to the nearest surface
-  MBErrorCode closest_to_location( MBEntityHandle volume,
+  ErrorCode closest_to_location( EntityHandle volume,
                                    double* point,
                                    double& result);
 
     // Calculate the volume contained in a 'volume'
-  MBErrorCode measure_volume( MBEntityHandle volume, double& result );
+  ErrorCode measure_volume( EntityHandle volume, double& result );
 
     // Calculate sum of area of triangles
-  MBErrorCode measure_area( MBEntityHandle surface, double& result );
+  ErrorCode measure_area( EntityHandle surface, double& result );
 
     // Get the sense of surfaces wrt a volume.  Sense values are:
     // {-1 -> reversed, 0 -> both, 1 -> forward}
-  MBErrorCode surface_sense( MBEntityHandle volume, 
+  ErrorCode surface_sense( EntityHandle volume, 
                              int num_surfaces,
-                             const MBEntityHandle* surfaces,
+                             const EntityHandle* surfaces,
                              int* senses_out );
 
     // Get the sense of surfaces wrt a volume.  Sense values are:
     // {-1 -> reversed, 0 -> both, 1 -> forward}
-  MBErrorCode surface_sense( MBEntityHandle volume, MBEntityHandle surface, int& sense_out );
+  ErrorCode surface_sense( EntityHandle volume, EntityHandle surface, int& sense_out );
 
     // load mesh
-  MBErrorCode load_file(const char* cfile,
+  ErrorCode load_file(const char* cfile,
 			const double facet_tolerance = 0);
 
-  MBErrorCode write_mesh(const char* ffile,
+  ErrorCode write_mesh(const char* ffile,
 			 const int flen);
 
 
     // initialize data structures and OBB tree
-  MBErrorCode init_OBBTree();
+  ErrorCode init_OBBTree();
 
-    // map between MBEntityHandle, base-1 index, and GLOBAL_ID
-  MBEntityHandle entity_by_index( int dimension, int index );
-  MBEntityHandle entity_by_id( int dimension, int id );
-  int index_by_handle( MBEntityHandle handle );
+    // map between EntityHandle, base-1 index, and GLOBAL_ID
+  EntityHandle entity_by_index( int dimension, int index );
+  EntityHandle entity_by_id( int dimension, int id );
+  int index_by_handle( EntityHandle handle );
   int id_by_index( int dimension, int index );
 
     // get number of geometric sets corresponding to geometry
@@ -110,54 +112,54 @@
   char *get_spec_reflect();
   char *get_white_reflect();
 
-  MBOrientedBoxTreeTool *obb_tree() {return &obbTree;}
+  OrientedBoxTreeTool *obb_tree() {return &obbTree;}
 
     // Get the tag used to associate OBB trees with geometry in load_file(..).
-  MBTag obb_tag() {return obbTag;}
+  Tag obb_tag() {return obbTag;}
 
-  MBTag geom_tag() {return geomTag;}
+  Tag geom_tag() {return geomTag;}
 
-  MBTag id_tag() {return idTag;}
+  Tag id_tag() {return idTag;}
 
-  MBTag name_tag() {return nameTag;}
+  Tag name_tag() {return nameTag;}
   
-  MBTag sense_tag() { return senseTag; }
+  Tag sense_tag() { return senseTag; }
 
   double distance_limit() {return distanceLimit;}
   void distance_limit(double this_limit) {distanceLimit = this_limit;}
   
-  std::vector<MBEntityHandle>& surf_handles() {return entHandles[2];}
+  std::vector<EntityHandle>& surf_handles() {return entHandles[2];}
       
-  std::vector<MBEntityHandle>& vol_handles() {return entHandles[3];}
+  std::vector<EntityHandle>& vol_handles() {return entHandles[3];}
       
-  std::vector<MBEntityHandle>& group_handles() {return entHandles[4];}
+  std::vector<EntityHandle>& group_handles() {return entHandles[4];}
       
-  MBErrorCode write_mcnp(std::string ifile, const bool overwrite = true);
-  MBErrorCode parse_metadata();
+  ErrorCode write_mcnp(std::string ifile, const bool overwrite = true);
+  ErrorCode parse_metadata();
   void tokenize( const std::string& str,
 			std::vector<std::string>& tokens,
 			const char* delimiters );
   
-  MBErrorCode poly_solid_angle( MBEntityHandle face, const MBCartVect& point, double& area );
+  ErrorCode poly_solid_angle( EntityHandle face, const CartVect& point, double& area );
 
-  MBErrorCode get_angle(MBEntityHandle surf, 
+  ErrorCode get_angle(EntityHandle surf, 
                         double xxx, double yyy, double zzz, double *ang);
 
 
     // get the corners of the OBB for a given volume
-  MBErrorCode getobb(MBEntityHandle volume, double minPt[3], double maxPt[3]);
+  ErrorCode getobb(EntityHandle volume, double minPt[3], double maxPt[3]);
 
     // get the center point and three vectors for the OBB of a given volume
-  MBErrorCode getobb(MBEntityHandle volume, double center[3], 
+  ErrorCode getobb(EntityHandle volume, double center[3], 
                      double axis1[3], double axis2[3], double axis3[3]);
 
     // get the root of the obbtree for a given entity
-  MBErrorCode get_root(MBEntityHandle vol_or_surf, MBEntityHandle &root);
+  ErrorCode get_root(EntityHandle vol_or_surf, EntityHandle &root);
 
-  int get_entity_id(MBEntityHandle this_ent);
+  int get_entity_id(EntityHandle this_ent);
 
     // Get the instance of MOAB used by functions in this file.
-  MBInterface* moab_instance() {return mbImpl;}
+  Interface* moab_instance() {return mbImpl;}
 
   double add_dist_tol() {return addDistTol;}
 
@@ -171,17 +173,17 @@
 
   bool use_cad() {return useCAD;}
 
-  MBErrorCode CAD_ray_intersect(const double *point, 
+  ErrorCode CAD_ray_intersect(const double *point, 
                                 const double *dir, 
                                 const double huge_val,
                                 std::vector<double> &distances,
-                                std::vector<MBEntityHandle> &surfaces, 
+                                std::vector<EntityHandle> &surfaces, 
                                 double &len);
 
-  MBErrorCode boundary_case( MBEntityHandle volume, int& result, 
+  ErrorCode boundary_case( EntityHandle volume, int& result, 
                              double u, double v, double w,
-                             MBEntityHandle facet,
-                             MBEntityHandle surface);
+                             EntityHandle facet,
+                             EntityHandle surface);
   
     /** Get subversion revision of this file (DagMC.hpp) */
   static unsigned int interface_revision();
@@ -189,21 +191,21 @@
 private:
   bool have_obb_tree();
 
-  MBErrorCode get_impl_compl();
+  ErrorCode get_impl_compl();
   
-  MBTag get_tag( const char* name, int size, MBTagType store, MBDataType type,
+  Tag get_tag( const char* name, int size, TagType store, DataType type,
                  const void* def_value = NULL, bool create_if_missing = true);
 
-  bool get_group_names(MBEntityHandle group_set, std::vector<std::string> &grp_names);
+  bool get_group_names(EntityHandle group_set, std::vector<std::string> &grp_names);
   
-  static void create_instance(MBInterface *mb_impl = NULL);
+  static void create_instance(Interface *mb_impl = NULL);
   
     // build internal index vectors that speed up handle-by-id, etc.
-  MBErrorCode build_indices(MBRange &surfs, MBRange &vols);
+  ErrorCode build_indices(Range &surfs, Range &vols);
   
     // build obb structure
-  MBErrorCode build_obbs(MBRange &surfs, MBRange &vols);
-  MBErrorCode build_obb_impl_compl(MBRange &surfs);
+  ErrorCode build_obbs(Range &surfs, Range &vols);
+  ErrorCode build_obb_impl_compl(Range &surfs);
   
   // attempt to set useCAD, first checking for availability
   void set_useCAD( bool use_cad ); 
@@ -221,12 +223,12 @@
 
   std::string itos(int ival);
 
-  MBInterface *mbImpl;
+  Interface *mbImpl;
 
-  MBOrientedBoxTreeTool obbTree;
-  MBTag obbTag, geomTag, idTag, nameTag, senseTag;
+  OrientedBoxTreeTool obbTree;
+  Tag obbTag, geomTag, idTag, nameTag, senseTag;
   // metadata
-  MBTag matTag, densTag, bcTag, impTag, tallyTag;
+  Tag matTag, densTag, bcTag, impTag, tallyTag;
   
   Option options[6];
 
@@ -234,9 +236,9 @@
   char whiteReflectName[NAME_TAG_SIZE];
   char implComplName[NAME_TAG_SIZE];
 
-  std::vector<MBEntityHandle> entHandles[5];
+  std::vector<EntityHandle> entHandles[5];
 
-  MBEntityHandle impl_compl_handle;
+  EntityHandle impl_compl_handle;
 
   double discardDistTol;
   double addDistTol;
@@ -251,11 +253,11 @@
     // store some lists indexed by handle
     // this is the lowest-valued handle among entity sets representing
     // surfaces & volumes
-  MBEntityHandle setOffset;
+  EntityHandle setOffset;
 
     // list of obbTree root sets for surfaces and volumes, 
     // indexed by [surf_or_vol_handle - setOffset]
-  std::vector<MBEntityHandle> rootSets;
+  std::vector<EntityHandle> rootSets;
 
     // entity index (contiguous 1-N indices) indexed like rootSets are
   std::vector<int> entIndices;
@@ -266,12 +268,12 @@
 
 #endif
   
-  DagMC(MBInterface *mb_impl);
+  DagMC(Interface *mb_impl);
   
   static DagMC *instance_;
   
     // temporary storage so functions don't have to reallocate vectors
-  std::vector<MBEntityHandle> triList, surfList, facetList;
+  std::vector<EntityHandle> triList, surfList, facetList;
   std::vector<double> distList;
 };
 
@@ -292,14 +294,14 @@
   return whiteReflectName;
 }
 
-inline DagMC *DagMC::instance(MBInterface *mb_impl) 
+inline DagMC *DagMC::instance(Interface *mb_impl) 
 {
   if (NULL == instance_) create_instance(mb_impl);
   
   return instance_;
 }
 
-inline int DagMC::index_by_handle( MBEntityHandle handle )
+inline int DagMC::index_by_handle( EntityHandle handle )
 {
   assert(handle-setOffset < entIndices.size());
   return entIndices[handle-setOffset];
@@ -312,19 +314,21 @@
   return entHandles[dimension].size() - 1;
 }
 
-inline MBEntityHandle DagMC::entity_by_index( int dimension, int index )
+inline EntityHandle DagMC::entity_by_index( int dimension, int index )
 {
   assert(2 <= dimension && 3 >= dimension && (unsigned) index < entHandles[dimension].size());
   return entHandles[dimension][index];
 }
 
     // get the root of the obbtree for a given entity
-inline MBErrorCode DagMC::get_root(MBEntityHandle vol_or_surf, MBEntityHandle &root) 
+inline ErrorCode DagMC::get_root(EntityHandle vol_or_surf, EntityHandle &root) 
 {
   unsigned int index = vol_or_surf - setOffset;
   root = (index < rootSets.size() ? rootSets[index] : 0);
   return (root ? MB_SUCCESS : MB_INDEX_OUT_OF_RANGE);
 }
 
+} // namespace moab
+
 #endif
 

Modified: MOAB/trunk/tools/dagmc/Makefile.am
===================================================================
--- MOAB/trunk/tools/dagmc/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,5 +1,4 @@
-AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab
+AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src 
 
 lib_LTLIBRARIES = libdagmc.la
 libdagmc_la_SOURCES = DagMC.cpp

Modified: MOAB/trunk/tools/dagmc/cub2h5m.cc
===================================================================
--- MOAB/trunk/tools/dagmc/cub2h5m.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/cub2h5m.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,11 +1,11 @@
 #include "GeometryQueryTool.hpp"
 #include "InitCGMA.hpp"
 #include "CGMApp.hpp"
-#include "MBCore.hpp"
-#include "MBCartVect.hpp"
+#include "moab/Core.hpp"
+#include "moab/CartVect.hpp"
 #include "cubfile.h"
 #include "FileOptions.hpp"
-#include "MBSkinner.hpp"
+#include "moab/Skinner.hpp"
 #include "quads_to_tris.hpp"
 #include <limits>
 #include <cstdlib>
@@ -17,25 +17,27 @@
 #define GF_ACIS_BIN_FILE_TYPE "ACIS_SAB"
 #define GF_OCC_BREP_FILE_TYPE "OCC"
 
+using namespace moab;
+
 // DAGMC cannot build an OBB tree if all of a volume's surfaces have no facets.
 // To prevent this, remove the cgm surface set if the cub surface set exists,
 // but had its faced removed (due to dead elements). Remember that the cgm_file_set
 // is not TRACKING.
-MBErrorCode remove_empty_cgm_surfs_and_vols( MBInterface *MBI, 
-                                          const MBEntityHandle cgm_file_set, 
-                                          const MBTag idTag, 
-                                          const MBTag dimTag, 
+ErrorCode remove_empty_cgm_surfs_and_vols( Interface *MBI, 
+                                          const EntityHandle cgm_file_set, 
+                                          const Tag idTag, 
+                                          const Tag dimTag, 
                                           const bool debug ) {
 
-  MBErrorCode result;
+  ErrorCode result;
   const int two = 2;
   const void* const two_val[] = {&two};
-  MBRange cgm_surfs;
+  Range cgm_surfs;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 						 two_val, 1, cgm_surfs );
   if(MB_SUCCESS != result) return result;    
 
-  for(MBRange::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
+  for(Range::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
     int n_tris;
     result = MBI->get_number_entities_by_type( *i, MBTRI, n_tris );
     if(MB_SUCCESS != result) return result;                              
@@ -45,17 +47,17 @@
       result = MBI->tag_get_data(idTag, &(*i), 1, &surf_id);
       assert(MB_SUCCESS == result);
 
-      MBRange parent_vols;
+      Range parent_vols;
       result = MBI->get_parent_meshsets( *i, parent_vols );
       assert(MB_SUCCESS == result);
-      for(MBRange::iterator j=parent_vols.begin(); j!=parent_vols.end(); ++j) {  
+      for(Range::iterator j=parent_vols.begin(); j!=parent_vols.end(); ++j) {  
         result = MBI->remove_parent_child( *j, *i );
         assert(MB_SUCCESS == result);
       }  
-      MBRange child_curves;
+      Range child_curves;
       result = MBI->get_child_meshsets( *i, child_curves );
       assert(MB_SUCCESS == result);
-      for(MBRange::iterator j=child_curves.begin(); j!=child_curves.end(); ++j) {  
+      for(Range::iterator j=child_curves.begin(); j!=child_curves.end(); ++j) {  
         result = MBI->remove_parent_child( *i, *j );
         assert(MB_SUCCESS == result);
       }  
@@ -65,10 +67,10 @@
       // Is the set contained anywhere else? If the surface is in a CUBIT group, 
       // such as "unmerged_surfs" it will cause write_mesh to fail. This should 
       // be a MOAB bug.
-      MBRange all_sets;
+      Range all_sets;
       result = MBI->get_entities_by_type( 0, MBENTITYSET, all_sets );
       assert(MB_SUCCESS == result);
-      for(MBRange::iterator j=all_sets.begin(); j!=all_sets.end(); ++j) {
+      for(Range::iterator j=all_sets.begin(); j!=all_sets.end(); ++j) {
         if(MBI->contains_entities( *j, &(*i), 1 )) {
           result = MBI->remove_entities( *j, &(*i), 1 );
           assert(MB_SUCCESS == result);
@@ -86,12 +88,12 @@
   // get all volumes
   const int three = 3;
   const void* const three_val[] = {&three};
-  MBRange cgm_vols;
+  Range cgm_vols;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 						 three_val, 1, cgm_vols );
   if(MB_SUCCESS != result) return result;    
 
-  for(MBRange::iterator i=cgm_vols.begin(); i!=cgm_vols.end(); ++i) {
+  for(Range::iterator i=cgm_vols.begin(); i!=cgm_vols.end(); ++i) {
     // get the volume's number of surfaces
     int n_surfs;
     result = MBI->num_child_meshsets( *i, &n_surfs );
@@ -105,10 +107,10 @@
       // Is the set contained anywhere else? If the surface is in a CUBIT group, 
       // such as "unmerged_surfs" it will cause write_mesh to fail. This should 
       // be a MOAB bug.
-      MBRange all_sets;
+      Range all_sets;
       result = MBI->get_entities_by_type( 0, MBENTITYSET, all_sets );
       assert(MB_SUCCESS == result);
-      for(MBRange::iterator j=all_sets.begin(); j!=all_sets.end(); ++j) {
+      for(Range::iterator j=all_sets.begin(); j!=all_sets.end(); ++j) {
         if(MBI->contains_entities( *j, &(*i), 1 )) {
           result = MBI->remove_entities( *j, &(*i), 1 );
           assert(MB_SUCCESS == result);
@@ -127,15 +129,15 @@
 
 // Given parent volume senses, an id, and a set handle, this function creates a
 // new surface set with dimension, geometry category, id, and sense tags.
-MBErrorCode build_new_surface( MBInterface *MBI,
-                               MBEntityHandle &new_surf,
-                               const MBEntityHandle forward_parent_vol,
-                               const MBEntityHandle reverse_parent_vol,
+ErrorCode build_new_surface( Interface *MBI,
+                               EntityHandle &new_surf,
+                               const EntityHandle forward_parent_vol,
+                               const EntityHandle reverse_parent_vol,
                                const int new_surf_id,
-                               const MBTag dimTag, const MBTag idTag, 
-                               const MBTag categoryTag, const MBTag senseTag ) {
+                               const Tag dimTag, const Tag idTag, 
+                               const Tag categoryTag, const Tag senseTag ) {
  
-  MBErrorCode result;
+  ErrorCode result;
   result = MBI->create_meshset( 0, new_surf );
   if(MB_SUCCESS != result) return result;
   if(0 != forward_parent_vol) {
@@ -154,7 +156,7 @@
   const char geom_category[CATEGORY_TAG_SIZE] = {"Surface\0"};
   result = MBI->tag_set_data( categoryTag, &new_surf, 1, &geom_category );
   if(MB_SUCCESS != result) return result;
-  MBEntityHandle vols[2] = { forward_parent_vol, reverse_parent_vol };
+  EntityHandle vols[2] = { forward_parent_vol, reverse_parent_vol };
   result = MBI->tag_set_data( senseTag, &new_surf, 1, vols );
   if(MB_SUCCESS != result) return result;
 
@@ -164,51 +166,51 @@
 
 // Given a face, orient it outward wrt its adjacent mesh element.
 // Each face must be adjacent to exactly one mesh element.
-MBErrorCode orient_faces_outward( MBInterface *MBI, const MBRange faces,
+ErrorCode orient_faces_outward( Interface *MBI, const Range faces,
                                   const bool debug ) {
 
-  MBErrorCode result;
-  for(MBRange::const_iterator i=faces.begin(); i!=faces.end(); ++i) {
-    MBRange adj_elem;
+  ErrorCode result;
+  for(Range::const_iterator i=faces.begin(); i!=faces.end(); ++i) {
+    Range adj_elem;
     result = MBI->get_adjacencies( &(*i), 1, 3, false, adj_elem );
     if(MB_SUCCESS != result) return result;
     if(1 != adj_elem.size()) return MB_INVALID_SIZE;
         
     // get center of element
-    const MBEntityHandle *elem_conn;
+    const EntityHandle *elem_conn;
     int n_nodes;   
     result = MBI->get_connectivity( adj_elem.front(), elem_conn, n_nodes );
     if(MB_SUCCESS != result) return result;
-    MBCartVect elem_coords[n_nodes];
+    CartVect elem_coords[n_nodes];
     result = MBI->get_coords( elem_conn, n_nodes, elem_coords[0].array() );
     if(MB_SUCCESS != result) return result;
-    MBCartVect elem_center(0.0);
+    CartVect elem_center(0.0);
     for(int j=0; j<n_nodes; ++j) elem_center += elem_coords[j];
     elem_center /= n_nodes;
 
     // get the center of the face
-    const MBEntityHandle *face_conn;
+    const EntityHandle *face_conn;
     result = MBI->get_connectivity( *i, face_conn, n_nodes );
     if(MB_SUCCESS != result) return result;
-    MBCartVect face_coords[n_nodes];
+    CartVect face_coords[n_nodes];
     result = MBI->get_coords( face_conn, n_nodes, face_coords[0].array() );
     if(MB_SUCCESS != result) return result;
     assert(4 == n_nodes);
-    MBCartVect face_center(0.0);
+    CartVect face_center(0.0);
     for(int j=0; j<n_nodes; ++j) face_center += face_coords[j];
     face_center /= n_nodes;
     if(debug) std::cout << "      center of mesh face exposed by dead element=" 
                         << face_center << std::endl;
 
     // get the normal of the face
-    MBCartVect face_normal, a, b;
+    CartVect face_normal, a, b;
     a = face_coords[2] - face_coords[1];
     b = face_coords[0] - face_coords[1];
     face_normal = a*b;
     face_normal.normalize();
 
     // get the direction into the element
-    MBCartVect elem_dir = elem_center - face_center;
+    CartVect elem_dir = elem_center - face_center;
     elem_dir.normalize();
 
     // the dot product of the face_normal and elem_dir should be ~-1 if the face
@@ -217,7 +219,7 @@
     
     // If the face is not oriented outward wrt the element, reverse it
     if(0 < dot_prod) {
-      MBEntityHandle new_face_conn[4] = { face_conn[3], face_conn[2], 
+      EntityHandle new_face_conn[4] = { face_conn[3], face_conn[2], 
                                           face_conn[1], face_conn[0] };
       result = MBI->set_connectivity( *i, new_face_conn, 4 );
       if(MB_SUCCESS != result) return result;
@@ -229,8 +231,8 @@
 /* qsort int comparison function */
 int handle_compare(const void *a, const void *b)
 {
-  const MBEntityHandle *ia = (const MBEntityHandle *)a; // casting pointer types
-  const MBEntityHandle *ib = (const MBEntityHandle *)b;
+  const EntityHandle *ia = (const EntityHandle *)a; // casting pointer types
+  const EntityHandle *ib = (const EntityHandle *)b;
   return *ia  - *ib; 
   /* integer comparison: returns negative if b > a 
      and positive if a > b */
@@ -238,8 +240,8 @@
 
 // qsort face comparison function. assume each face has 4 nodes
 int compare_face(const void *a, const void *b) {                                       
-  MBEntityHandle *ia = (MBEntityHandle *)a;                                                  
-  MBEntityHandle *ib = (MBEntityHandle *)b;                                                  
+  EntityHandle *ia = (EntityHandle *)a;                                                  
+  EntityHandle *ib = (EntityHandle *)b;                                                  
   if(*ia == *ib) {
     if(*(ia+1) == *(ib+1)) {
       if(*(ia+2) == *(ib+2)) {
@@ -256,42 +258,42 @@
 }  
 
 // Use this to get quad faces from hex elems.
-MBErrorCode skin_hex_elems(MBInterface *MBI, MBRange elems, const int dim, 
-                           MBRange &faces ) {
+ErrorCode skin_hex_elems(Interface *MBI, Range elems, const int dim, 
+                           Range &faces ) {
   // get faces of each hex
   const int nodes_per_face = 4;
   const unsigned int faces_per_elem = 6;
   unsigned int n_faces = faces_per_elem*elems.size();
-  MBEntityHandle f[n_faces][nodes_per_face];
-  MBErrorCode result;
+  EntityHandle f[n_faces][nodes_per_face];
+  ErrorCode result;
   int counter = 0;
-  for(MBRange::iterator i=elems.begin(); i!=elems.end(); ++i) {
-    MBRange elem_faces;
+  for(Range::iterator i=elems.begin(); i!=elems.end(); ++i) {
+    Range elem_faces;
     result = MBI->get_adjacencies( &(*i), 1, 2, true, elem_faces );
     if(MB_SUCCESS != result) return result;
     if(faces_per_elem != elem_faces.size()) return MB_INVALID_SIZE;
-    for(MBRange::iterator j=elem_faces.begin(); j!=elem_faces.end(); ++j) {
-      const MBEntityHandle *conn;
+    for(Range::iterator j=elem_faces.begin(); j!=elem_faces.end(); ++j) {
+      const EntityHandle *conn;
       int n_nodes;
-      MBErrorCode result = MBI->get_connectivity( *j, conn, n_nodes );
+      ErrorCode result = MBI->get_connectivity( *j, conn, n_nodes );
       if(MB_SUCCESS != result) return result;
       if(nodes_per_face != n_nodes) return MB_INVALID_SIZE;
       // Sort the node handles of the face
       for(int k=0; k<nodes_per_face; ++k) f[counter][k] = conn[k];
-      qsort( &f[counter][0], nodes_per_face, sizeof(MBEntityHandle), handle_compare );
+      qsort( &f[counter][0], nodes_per_face, sizeof(EntityHandle), handle_compare );
       ++counter;
     }
   }
   
   // Sort the faces by the first node handle, then second node, then third node...
-  qsort( &f[0][0], n_faces, nodes_per_face*sizeof(MBEntityHandle), compare_face );
+  qsort( &f[0][0], n_faces, nodes_per_face*sizeof(EntityHandle), compare_face );
 
   // if a face has 1 or more duplicates, it is not on the skin
   faces.clear();
   for(unsigned int i=0; i<n_faces; ++i) {
     // if the last face is tested, it must be on the skin
     if(n_faces-1 == i) {
-      MBRange face_handle;
+      Range face_handle;
       result = MBI->get_adjacencies( &(f[i][0]), nodes_per_face, 2, false, face_handle );
       if(MB_SUCCESS != result) return result;
       if(1 != face_handle.size()) return MB_INVALID_SIZE;
@@ -307,7 +309,7 @@
       }
       // otherwise it is on the skin
     } else {
-      MBRange face_handle;
+      Range face_handle;
       result = MBI->get_adjacencies( &(f[i][0]), nodes_per_face, 2, false, face_handle );
       if(MB_SUCCESS != result) return result;
       if(1 != face_handle.size()) return MB_INVALID_SIZE;
@@ -394,24 +396,24 @@
 }
 
 // Given four nodes, calculate the tet volume.
-inline static double tet_volume( const MBCartVect& v0,
-                                 const MBCartVect& v1,
-                                 const MBCartVect& v2, 
-                                 const MBCartVect& v3 )
+inline static double tet_volume( const CartVect& v0,
+                                 const CartVect& v1,
+                                 const CartVect& v2, 
+                                 const CartVect& v3 )
 {
   return 1./6. * ( ((v1 - v0) * (v2 - v0)) % (v3 - v0) );
 }
 
 // Measure and tet volume are taken from measure.cpp
-double measure(MBInterface *MBI, const MBEntityHandle element) {
-  MBEntityType type = MBI->type_from_handle( element );
+double measure(Interface *MBI, const EntityHandle element) {
+  EntityType type = MBI->type_from_handle( element );
 
-  const MBEntityHandle *conn;
+  const EntityHandle *conn;
   int num_vertices;
-  MBErrorCode result = MBI->get_connectivity( element, conn, num_vertices );
+  ErrorCode result = MBI->get_connectivity( element, conn, num_vertices );
   if(MB_SUCCESS != result) return result;
 
-  MBCartVect coords[num_vertices];
+  CartVect coords[num_vertices];
   result = MBI->get_coords( conn, num_vertices, coords[0].array() );
   if(MB_SUCCESS != result) return result;
 
@@ -425,7 +427,7 @@
       num_vertices = 4;
     case MBPOLYGON:
       {
-	MBCartVect mid(0,0,0);
+	CartVect mid(0,0,0);
 	for (int i = 0; i < num_vertices; ++i)
 	  mid += coords[i];
 	mid /= num_vertices;
@@ -465,19 +467,19 @@
    Special Case: If the surface is planar, and the plane includes the origin,
    the signed volume will be ~0. If the signed volume is ~0 then offset everything
    by a random amount and try again. */
-MBErrorCode get_signed_volume( MBInterface *MBI, 
-                               const MBEntityHandle surf_set,
-                               const MBCartVect offset, 
+ErrorCode get_signed_volume( Interface *MBI, 
+                               const EntityHandle surf_set,
+                               const CartVect offset, 
                                double &signed_volume) {
-  MBErrorCode rval;
-  MBRange tris;
+  ErrorCode rval;
+  Range tris;
   rval = MBI->get_entities_by_type( surf_set, MBTRI, tris ); 
   if(MB_SUCCESS != rval) return rval;
   signed_volume = 0.0;                                                                 
-  const MBEntityHandle *conn;                                                            
+  const EntityHandle *conn;                                                            
   int len;                                                                               
-  MBCartVect coords[3];                                                                  
-  for (MBRange::iterator j = tris.begin(); j != tris.end(); ++j) {             
+  CartVect coords[3];                                                                  
+  for (Range::iterator j = tris.begin(); j != tris.end(); ++j) {             
     rval = MBI->get_connectivity( *j, conn, len, true );                                 
     if(MB_SUCCESS != rval) return rval;                                                 
     if(3 != len) return MB_INVALID_SIZE;                                                                    
@@ -503,26 +505,26 @@
 // represent the quads in the cub surface. Calculate the signed volume of both
 // the cgm and cub surface. If they are different, change the cgm sense so that
 // it matches the sense of the cub surface.
-MBErrorCode fix_surface_senses( MBInterface *MBI, 
-                                const MBEntityHandle cgm_file_set, 
-                                const MBEntityHandle cub_file_set,
-                                const MBTag idTag, const MBTag dimTag, const MBTag senseTag,
+ErrorCode fix_surface_senses( Interface *MBI, 
+                                const EntityHandle cgm_file_set, 
+                                const EntityHandle cub_file_set,
+                                const Tag idTag, const Tag dimTag, const Tag senseTag,
                                 const bool debug ) {
-  MBErrorCode result;
+  ErrorCode result;
   const int two = 2;
   const void* const two_val[] = {&two};
-  MBRange cgm_surfs;
+  Range cgm_surfs;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 						 two_val, 1, cgm_surfs );
   if(MB_SUCCESS != result) return result;    
-  for(MBRange::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); i++) {
+  for(Range::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); i++) {
     int surf_id;
     result = MBI->tag_get_data(idTag, &(*i), 1, &surf_id);
     if(MB_SUCCESS != result) return result;    
             
     // Find the meshed surface set with the same id
-    MBRange cub_surf;
-    const MBTag tags[] = {idTag, dimTag};
+    Range cub_surf;
+    const Tag tags[] = {idTag, dimTag};
     const void* const tag_vals[] = { &surf_id, &two };
     result = MBI->get_entities_by_type_and_tag(cub_file_set, MBENTITYSET, tags,
 						   tag_vals, 2, cub_surf );
@@ -535,10 +537,10 @@
     }
 
     // Get tris that represent the quads of the cub surf
-    MBRange quads;
+    Range quads;
     result = MBI->get_entities_by_type( cub_surf.front(), MBQUAD, quads ); 
     if(MB_SUCCESS != result) return result;  
-    MBRange cub_tris; 
+    Range cub_tris; 
     result = make_tris_from_quads( MBI, quads, cub_tris );
 
     // Add the tris to the same surface meshset as the quads are inside.            
@@ -556,7 +558,7 @@
     for(int j=0; j<n_attempts; ++j) {
       cgm_signed_vol = 0;
       cub_signed_vol = 0;
-      MBCartVect offset(std::rand()%max_random, std::rand()%max_random, std::rand()%max_random);
+      CartVect offset(std::rand()%max_random, std::rand()%max_random, std::rand()%max_random);
       result = get_signed_volume( MBI,               *i, offset, cgm_signed_vol ); 
       if(MB_SUCCESS != result) return result;                                      
       result = get_signed_volume( MBI, cub_surf.front(), offset, cub_signed_vol ); 
@@ -574,7 +576,7 @@
     // representations have the same signed volume.
     if( (cgm_signed_vol<0 && cub_signed_vol>0) ||
 	(cgm_signed_vol>0 && cub_signed_vol<0) ) {
-      MBEntityHandle cgm_surf_volumes[2], reversed_cgm_surf_volumes[2];
+      EntityHandle cgm_surf_volumes[2], reversed_cgm_surf_volumes[2];
       result = MBI->tag_get_data( senseTag, &(*i), 1, cgm_surf_volumes );
       if(MB_SUCCESS != result) return result;  
       if(MB_SUCCESS != result) return result;    
@@ -594,28 +596,28 @@
   // cgm_surf, if there exists a cub_surf with the same id, replace the cgm tris
   // with cub_tris (created from the quads). Note the a surface that is not 
   // meshed (in cub file) will not be effected.
-MBErrorCode replace_faceted_cgm_surfs( MBInterface *MBI,
-                                       const MBEntityHandle cgm_file_set, 
-                                       const MBEntityHandle cub_file_set, 
-                                       const MBTag idTag, const MBTag dimTag, 
+ErrorCode replace_faceted_cgm_surfs( Interface *MBI,
+                                       const EntityHandle cgm_file_set, 
+                                       const EntityHandle cub_file_set, 
+                                       const Tag idTag, const Tag dimTag, 
                                        const bool debug ) {
-  MBErrorCode result;
+  ErrorCode result;
   const int two = 2;
   const void* const two_val[] = {&two};
-  MBRange cgm_surfs;
+  Range cgm_surfs;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 						 two_val, 1, cgm_surfs );
   if(MB_SUCCESS != result) return result;    
 
-  for(MBRange::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
+  for(Range::iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
     int surf_id;
     result = MBI->tag_get_data(idTag, &(*i), 1, &surf_id);
     if(MB_SUCCESS != result) return result;    
     if(debug) std::cout << "surf_id=" << surf_id << std::endl;
             
     // Find the meshed surface set with the same id
-    MBRange cub_surf;
-    const MBTag tags[] = {idTag, dimTag};
+    Range cub_surf;
+    const Tag tags[] = {idTag, dimTag};
     const void* const tag_vals[] = { &surf_id, &two };
     result = MBI->get_entities_by_type_and_tag(cub_file_set, MBENTITYSET, tags,
 						   tag_vals, 2, cub_surf );
@@ -628,17 +630,17 @@
     }
 
     // Get tris that represent the quads of the cub surf
-    MBRange quads;
+    Range quads;
     result = MBI->get_entities_by_type( cub_surf.front(), MBQUAD, quads ); 
     if(MB_SUCCESS != result) return result;  
 
-    MBRange cub_tris; 
+    Range cub_tris; 
     result = make_tris_from_quads( MBI, quads, cub_tris );
     if(MB_SUCCESS != result) return result;	
 
     // Remove the tris from the cgm surf. Don't forget to remove them from the
     // cgm_file_set because it is not TRACKING.
-    MBRange cgm_tris;
+    Range cgm_tris;
     result = MBI->get_entities_by_type( *i, MBTRI, cgm_tris );
     if(MB_SUCCESS != result) return result;                              
     result = MBI->remove_entities( *i, cgm_tris );                     
@@ -662,18 +664,18 @@
 // IF MODIFYING THIS CODE, BE AWARE THAT DEAD ELEMENTS CAN BE ADJACENT TO MORE
 // THAN ONE SURFACE, MAKING THE ASSOCIATION BETWEEN NEWLY EXPOSED AND EXISTING
 // SURFACES AMBIGUOUS.
-MBErrorCode add_dead_elems_to_impl_compl( MBInterface *MBI, 
-                                          const MBEntityHandle cgm_file_set,
-                                          const MBEntityHandle cub_file_set,
-                                          const MBTag idTag, const MBTag dimTag,
-                                          const MBTag categoryTag, const MBTag senseTag,
+ErrorCode add_dead_elems_to_impl_compl( Interface *MBI, 
+                                          const EntityHandle cgm_file_set,
+                                          const EntityHandle cub_file_set,
+                                          const Tag idTag, const Tag dimTag,
+                                          const Tag categoryTag, const Tag senseTag,
                                           const bool debug ) {
 
   // Get the cgm surfaces
-  MBErrorCode result;
+  ErrorCode result;
   const int two = 2;
   const void* const two_val[] = {&two};
-  MBRange cgm_surfs;
+  Range cgm_surfs;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 					     two_val, 1, cgm_surfs );
   if(MB_SUCCESS != result) return result;    
@@ -681,7 +683,7 @@
   // Get the maximum surface id. This is so that new surfaces do not have
   // duplicate ids.
   int max_surf_id = -1;
-  for(MBRange::const_iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
+  for(Range::const_iterator i=cgm_surfs.begin(); i!=cgm_surfs.end(); ++i) {
     int surf_id;
     result = MBI->tag_get_data( idTag, &(*i), 1, &surf_id );
     if(MB_SUCCESS != result) return result;
@@ -692,13 +694,13 @@
   // For each cgm volume, does a cub volume with the same id exist?
   const int three = 3;
   const void* const three_val[] = {&three};
-  MBRange cgm_vols;
+  Range cgm_vols;
   result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, &dimTag,
 					     three_val, 1, cgm_vols );
   if(MB_SUCCESS != result) return result;
 
   // get the corresponding cub volume
-  for(MBRange::iterator i=cgm_vols.begin(); i!=cgm_vols.end(); i++) {
+  for(Range::iterator i=cgm_vols.begin(); i!=cgm_vols.end(); i++) {
     int vol_id;
     result = MBI->tag_get_data(idTag, &(*i), 1, &vol_id);
     assert(MB_SUCCESS == result);
@@ -706,8 +708,8 @@
     std::cout << "  Volume " << vol_id;
             
     // Find the meshed vol set with the same id
-    MBRange cub_vol;
-    const MBTag tags[] = {idTag, dimTag};
+    Range cub_vol;
+    const Tag tags[] = {idTag, dimTag};
     const void* const tag_vals[] = { &vol_id, &three };
     result = MBI->get_entities_by_type_and_tag(cub_file_set, MBENTITYSET, tags,
 					       tag_vals, 2, cub_vol );
@@ -721,15 +723,15 @@
     }
 
     // get the mesh elements of the volume.
-    MBRange elems;
+    Range elems;
     result = MBI->get_entities_by_type( cub_vol.front(), MBHEX, elems ); 
     assert(MB_SUCCESS == result);
     if(MB_SUCCESS != result) return result;  
     if(debug) std::cout << "    found " << elems.size() << " hex elems" << std::endl;
 
     // skin the volumes
-    MBSkinner tool(MBI);
-    MBRange skin_faces;
+    Skinner tool(MBI);
+    Range skin_faces;
     result = tool.find_skin( elems, 2, skin_faces, true );
     assert(MB_SUCCESS == result);
     if(MB_SUCCESS != result) return result;
@@ -747,17 +749,17 @@
     //                       they are now adjacent to this volume
 
     // get cub child surfaces.
-    MBRange cub_surfs;
+    Range cub_surfs;
     result = MBI->get_child_meshsets( cub_vol.front(), cub_surfs );
     assert(MB_SUCCESS == result);
     if(MB_SUCCESS != result) return result;
-    for(MBRange::iterator j=cub_surfs.begin(); j!=cub_surfs.end(); ++j) {
+    for(Range::iterator j=cub_surfs.begin(); j!=cub_surfs.end(); ++j) {
       int surf_id;
       result = MBI->tag_get_data( idTag, &(*j), 1, &surf_id );
       assert(MB_SUCCESS == result);
       if(MB_SUCCESS != result) return result;
       // get the quads on each surface
-      MBRange cub_faces;
+      Range cub_faces;
       result = MBI->get_entities_by_type( *j, MBQUAD, cub_faces );
       assert(MB_SUCCESS == result);
       if(MB_SUCCESS != result) return result;
@@ -767,9 +769,9 @@
 	// return MB_ENTITY_NOT_FOUND;
       }
       // get the faces common to both the skin and this surface
-      MBRange common_faces = intersect( cub_faces, skin_faces );
+      Range common_faces = intersect( cub_faces, skin_faces );
       // find the surface faces not on the skin - these are old and need removed
-      MBRange old_faces = subtract( cub_faces, common_faces );
+      Range old_faces = subtract( cub_faces, common_faces );
       result = MBI->remove_entities( *j, old_faces );
       assert(MB_SUCCESS == result);
       if(MB_SUCCESS != result) return result;
@@ -782,8 +784,8 @@
 		<< " old faces removed" << std::endl;
       // Place the old faces in a new surface, because they may still be adjacent
       // to 3D mesh in another volume. Get the parent vols of the surface.
-      MBRange cgm_surf;
-      const MBTag tags[] = {idTag, dimTag};
+      Range cgm_surf;
+      const Tag tags[] = {idTag, dimTag};
       const void* const tag_vals[] = { &surf_id, &two };
       result = MBI->get_entities_by_type_and_tag(cgm_file_set, MBENTITYSET, tags,
 						 tag_vals, 2, cgm_surf );
@@ -793,7 +795,7 @@
 	std::cout << "invalid size" << std::endl;
         return MB_INVALID_SIZE;
       }
-      MBEntityHandle cgm_vols[2], cub_vols[2];
+      EntityHandle cgm_vols[2], cub_vols[2];
       result = MBI->tag_get_data( senseTag, cgm_surf, &cgm_vols );
       assert(MB_SUCCESS == result);
       if(MB_SUCCESS != result) return result;
@@ -817,7 +819,7 @@
 	continue;
       }
       // build the new surface.
-      MBEntityHandle new_cgm_surf, new_cub_surf;
+      EntityHandle new_cgm_surf, new_cub_surf;
       ++max_surf_id;
       result = build_new_surface( MBI, new_cgm_surf,
 				  cgm_vols[0], cgm_vols[1], max_surf_id,
@@ -848,7 +850,7 @@
     }
 
     // the remaining skin faces are newly exposed faces
-    MBRange new_faces = skin_faces;
+    Range new_faces = skin_faces;
 
     // new skin faces must be assigned to a surface
     if(new_faces.empty()) continue;
@@ -861,7 +863,7 @@
     if(MB_SUCCESS != result) return result;
 
     // Create the new surface.
-    MBEntityHandle new_cgm_surf, new_cub_surf;
+    EntityHandle new_cgm_surf, new_cub_surf;
     ++max_surf_id;
     result = build_new_surface( MBI, new_cgm_surf,
 				*i, 0, max_surf_id,
@@ -912,7 +914,7 @@
 // load cgm file
 // for each surface
 //   convert cub surf quads to tris
-//   get signed volume from cgm and cub surf         MUST COME BEFORE COORD UPDATE, NEEDS TRIS
+//   get signed volume from cgm and cub surf         MUST COME BEFORE COORD UPDATE, NEEDS MBTRIS
 //   reverse cgm surface sense if needed
 //   replace cgm surf tris with cub surf tris
 // measure volume of predeformed cub elements
@@ -1004,9 +1006,9 @@
   }
 
   // Read the mesh from the cub file with Tqcdfr 
-  MBCore *MBI = new MBCore();
-  MBErrorCode result;
-  MBEntityHandle cub_file_set;
+  Core *MBI = new Core();
+  ErrorCode result;
+  EntityHandle cub_file_set;
   result = MBI->create_meshset( 0, cub_file_set );
   if(MB_SUCCESS != result) return result;
   //char cub_options[256] = "120";
@@ -1020,7 +1022,7 @@
   sprintf(cgm_options,
 	  "CGM_ATTRIBS=yes;FACET_DISTANCE_TOLERANCE=%g;FACET_NORMAL_TOLERANCE=%d;MAX_FACET_EDGE_LENGTH=%g;",
 	  dist_tol,norm_tol,len_tol); 
-  MBEntityHandle cgm_file_set;
+  EntityHandle cgm_file_set;
   result = MBI->create_meshset( 0, cgm_file_set );
   if(MB_SUCCESS != result) return result;
   result = MBI->load_file(sat_name, &cgm_file_set, cgm_options,NULL,0,0);
@@ -1028,7 +1030,7 @@
   std::cout << "CAD file read." << std::endl;
     
   // Create tags
-  MBTag dimTag, idTag, categoryTag, senseTag;
+  Tag dimTag, idTag, categoryTag, senseTag;
   result = MBI->tag_create(GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_DENSE, 
 			       MB_TYPE_INTEGER, dimTag, NULL, true );
   if(MB_SUCCESS != result) return result;
@@ -1038,7 +1040,7 @@
   result = MBI->tag_create(CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, MB_TAG_SPARSE, 
 			       MB_TYPE_OPAQUE, categoryTag, NULL, true );
   if(MB_SUCCESS != result) return result;
-  result = MBI->tag_create("GEOM_SENSE_2", 2*sizeof(MBEntityHandle), MB_TAG_DENSE, 
+  result = MBI->tag_create("GEOM_SENSE_2", 2*sizeof(EntityHandle), MB_TAG_DENSE, 
 			       MB_TYPE_HANDLE, senseTag, NULL, true );
   if(MB_SUCCESS != result) return result;
     
@@ -1051,7 +1053,7 @@
   std::cout << "Fixed CAD surface senses to match meshed surface senses." << std::endl;
 
   // Get the 3D elements in the cub file and measure their volume.
-  MBRange orig_elems;
+  Range orig_elems;
   std::vector<double> orig_size;
   if(determine_volume_change) {
     result = MBI->get_entities_by_dimension( 0, 3, orig_elems );   
@@ -1066,11 +1068,11 @@
   // sets to track ownership so that dead elements will be deleted from the sets.
   const int three = 3;
   const void* const three_val[] = {&three};
-  MBRange cub_vols;
+  Range cub_vols;
   result = MBI->get_entities_by_type_and_tag(cub_file_set, MBENTITYSET, &dimTag,
 						 three_val, 1, cub_vols );
   if(MB_SUCCESS != result) return result;
-  for(MBRange::const_iterator i=cub_vols.begin(); i!=cub_vols.end(); ++i) {
+  for(Range::const_iterator i=cub_vols.begin(); i!=cub_vols.end(); ++i) {
     result = MBI->set_meshset_options( *i, MESHSET_TRACK_OWNER );
     if(MB_SUCCESS != result) return result;
   }
@@ -1107,7 +1109,7 @@
   if(determine_volume_change) {
     // Dead elements have been removed by the deformation. Get the elements that 
     // still exist.
-    MBRange defo_elems;
+    Range defo_elems;
     result = MBI->get_entities_by_dimension( 0, 3, defo_elems );   
     if(MB_SUCCESS != result) return result;
     

Modified: MOAB/trunk/tools/dagmc/cubfile.c
===================================================================
--- MOAB/trunk/tools/dagmc/cubfile.c	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/cubfile.c	2010-03-12 21:30:42 UTC (rev 3604)
@@ -12,9 +12,8 @@
  */
 
 #include <stdlib.h>
+#include <stdint.h>
 
-#include "MBEntityHandle.h" // for MOAB_HAVE_STDINT_H
-
 #ifdef _MSC_VER /* windows */
 #  include <BaseTsd.h>
 #endif

Modified: MOAB/trunk/tools/dagmc/main.cc
===================================================================
--- MOAB/trunk/tools/dagmc/main.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/main.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
 #include "GeometryQueryTool.hpp"
 #include "InitCGMA.hpp"
 #include "CGMApp.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "cubfile.h"
 
 #define GF_CUBIT_FILE_TYPE    "CUBIT"
@@ -11,6 +11,8 @@
 #define GF_ACIS_BIN_FILE_TYPE "ACIS_SAB"
 #define GF_OCC_BREP_FILE_TYPE "OCC"
 
+using namespace moab;
+
 /* Get the type of a file.
    Return value is one of the above constants
  */
@@ -127,9 +129,9 @@
 	  actuate_attribs?"yes":"no",dist_tol,norm_tol,len_tol);
       
     // Intitalize MOAB
-  MBCore moab;
-  MBInterface* iface = &moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface* iface = &moab;
+  ErrorCode rval;
 
 // If CUB file, extract ACIS geometry
   if (!strcmp( file_type, "CUBIT" )) {

Modified: MOAB/trunk/tools/dagmc/pt_vol_test.cc
===================================================================
--- MOAB/trunk/tools/dagmc/pt_vol_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/pt_vol_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,7 @@
-#include "MBInterface.hpp"
-#include "MBCore.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Core.hpp"
 #include "DagMC.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/MBTagConventions.hpp"
 
 #include <vector>
 #include <iostream>
@@ -11,13 +11,13 @@
 
 #define CHKERR if (MB_SUCCESS != rval) return rval
 
+using namespace moab;
 
-
-MBErrorCode test_pt_volume(DagMC &dagmc, int volID, double xxx, double yyy, double zzz, int &inside)
+ErrorCode test_pt_volume(DagMC &dagmc, int volID, double xxx, double yyy, double zzz, int &inside)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
-  MBEntityHandle vol = dagmc.entity_by_id(3,volID);
+  EntityHandle vol = dagmc.entity_by_id(3,volID);
 
   double u, v, w;
   u=v=w=0;
@@ -28,11 +28,11 @@
 
 }
 
-MBErrorCode test_pt_volume_slow(DagMC &dagmc, int volID, double xxx, double yyy, double zzz, int &inside)
+ErrorCode test_pt_volume_slow(DagMC &dagmc, int volID, double xxx, double yyy, double zzz, int &inside)
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
-  MBEntityHandle vol = dagmc.entity_by_id(3,volID);
+  EntityHandle vol = dagmc.entity_by_id(3,volID);
 
   rval = dagmc.point_in_volume_slow( vol, xxx, yyy, zzz, inside);
   CHKERR;
@@ -43,7 +43,7 @@
 
 int main( int argc, char* argv[] )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
 
   if (argc < 6) {
     std::cerr << "Usage: " << argv[0] << " <mesh_filename> "

Modified: MOAB/trunk/tools/dagmc/quads_to_tris.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/quads_to_tris.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/quads_to_tris.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -15,23 +15,25 @@
 
 #include "quads_to_tris.hpp"
 
+using namespace moab;
+
 // Generic function to create two tris from a quad. This can be improved later.
-MBErrorCode make_tris_from_quad( MBInterface *MBI,
-                                 MBEntityHandle quad,  /* intput */
-                                 MBEntityHandle &tri0, /* output */
-				 MBEntityHandle &tri1  /* output */) {
+ErrorCode make_tris_from_quad( Interface *MBI,
+                                 EntityHandle quad,  /* intput */
+                                 EntityHandle &tri0, /* output */
+				 EntityHandle &tri1  /* output */) {
   
   // get connectivity (ordered counterclockwise for 2D elements in MOAB)
-  MBErrorCode result;    
-  const MBEntityHandle *quad_conn;
+  ErrorCode result;    
+  const EntityHandle *quad_conn;
   int n_verts=0;
   result = MBI->get_connectivity( quad, quad_conn, n_verts );
     assert( 4 == n_verts );
     assert( MB_SUCCESS == result);
    
   // make tris from quad
-  MBEntityHandle tri0_conn[] = {quad_conn[0], quad_conn[1], quad_conn[3]};
-  MBEntityHandle tri1_conn[] = {quad_conn[1], quad_conn[2], quad_conn[3]};
+  EntityHandle tri0_conn[] = {quad_conn[0], quad_conn[1], quad_conn[3]};
+  EntityHandle tri1_conn[] = {quad_conn[1], quad_conn[2], quad_conn[3]};
   result = MBI->create_element(MBTRI, tri0_conn, 3, tri0);
     assert( MB_SUCCESS == result);
   result = MBI->create_element(MBTRI, tri1_conn, 3, tri1);
@@ -40,13 +42,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode make_tris_from_quads( MBInterface *MBI,
-                                  const MBRange quads,
-                                  MBRange &tris ) {
-  MBErrorCode result;
+ErrorCode make_tris_from_quads( Interface *MBI,
+                                  const Range quads,
+                                  Range &tris ) {
+  ErrorCode result;
   tris.clear();
-  for(MBRange::const_iterator i=quads.begin(); i!=quads.end(); ++i) {
-    MBEntityHandle tri0, tri1;
+  for(Range::const_iterator i=quads.begin(); i!=quads.end(); ++i) {
+    EntityHandle tri0, tri1;
     result = make_tris_from_quad( MBI, *i, tri0, tri1 );
     assert(MB_SUCCESS == result);
     tris.insert( tri0 );
@@ -55,11 +57,11 @@
   return MB_SUCCESS;
 }  
 
-MBErrorCode quads_to_tris( MBInterface *MBI, MBEntityHandle input_meshset ) {
+ErrorCode quads_to_tris( Interface *MBI, EntityHandle input_meshset ) {
 
   // create a geometry tag to find the surfaces with
-  MBErrorCode result;
-  MBTag geom_tag, id_tag;
+  ErrorCode result;
+  Tag geom_tag, id_tag;
   result = MBI->tag_create( GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_DENSE,
                             MB_TYPE_INTEGER, geom_tag, 0, true );
     assert( MB_SUCCESS==result || MB_ALREADY_ALLOCATED==result);
@@ -70,7 +72,7 @@
     assert( MB_SUCCESS==result || MB_ALREADY_ALLOCATED==result);
 
   // get all surface meshsets
-  MBRange surface_meshsets;
+  Range surface_meshsets;
   int dim = 2;
   void* input_dim[] = {&dim};
   result = MBI->get_entities_by_type_and_tag( input_meshset, MBENTITYSET, &geom_tag,
@@ -81,7 +83,7 @@
   // ******************************************************************
   // Loop over every surface meshset and grab each surface's quads.
   // ******************************************************************
-  for( MBRange::iterator i=surface_meshsets.begin(); i!=surface_meshsets.end(); i++ ) {
+  for( Range::iterator i=surface_meshsets.begin(); i!=surface_meshsets.end(); i++ ) {
 
     // get the surface id of the surface meshset
     int surf_id=0;
@@ -90,7 +92,7 @@
     std::cout << "  Surface " << surf_id << " has ";
 
     // get all quads of the surface
-    MBRange quads;
+    Range quads;
     result = MBI->get_entities_by_type( *i, MBQUAD, quads );
       assert( MB_SUCCESS == result );
     std::cout << quads.size() << " quads." << std::endl;
@@ -98,10 +100,10 @@
     // ******************************************************************
     // For each quad, make two triangles then delete the quad.
     // ******************************************************************
-    for(MBRange::iterator j=quads.begin(); j!=quads.end(); j++ ) {
+    for(Range::iterator j=quads.begin(); j!=quads.end(); j++ ) {
     
       // make the tris
-      MBEntityHandle tri0 = 0, tri1 = 0;
+      EntityHandle tri0 = 0, tri1 = 0;
       result = make_tris_from_quad( MBI, *j, tri0, tri1 );
         assert( MB_SUCCESS == result );
       

Modified: MOAB/trunk/tools/dagmc/quads_to_tris.hpp
===================================================================
--- MOAB/trunk/tools/dagmc/quads_to_tris.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/quads_to_tris.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -6,15 +6,15 @@
 
 #include <iostream>
 #include <assert.h>
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Range.hpp"
 
-MBErrorCode make_tris_from_quad( MBInterface *MBI,
-                                 MBEntityHandle quad,  /* input  */
-                                 MBEntityHandle &tri0, /* output */
-				 MBEntityHandle &tri1  /* output */);
+moab::ErrorCode make_tris_from_quad( moab::Interface *MBI,
+                                 moab::EntityHandle quad,  /* input  */
+                                 moab::EntityHandle &tri0, /* output */
+				 moab::EntityHandle &tri1  /* output */);
 
-MBErrorCode make_tris_from_quads( MBInterface *MBI, const MBRange quads, MBRange &tris ) ;
+moab::ErrorCode make_tris_from_quads( moab::Interface *MBI, const moab::Range quads, moab::Range &tris ) ;
 
-MBErrorCode quads_to_tris( MBInterface *MBI, MBEntityHandle input_meshset );
+moab::ErrorCode quads_to_tris( moab::Interface *MBI, moab::EntityHandle input_meshset );

Modified: MOAB/trunk/tools/dagmc/quads_to_tris_driver.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/quads_to_tris_driver.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/quads_to_tris_driver.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,12 +1,13 @@
 #include <iostream>
 #include <assert.h>
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include "quads_to_tris.hpp"
 
+using namespace moab;
+
 #define MBI mb_instance()
-MBInterface* mb_instance();
+Interface* mb_instance();
 
-
 // Read a DAGMC-style file of quads and convert it to tris
 // Input argument is the input filename.
 // Output file will be called input_filename_tris.h5m.
@@ -20,7 +21,7 @@
   }
 
   // load file from input argument
-  MBErrorCode result;
+  ErrorCode result;
   std::string filename = argv[1];
   result = MBI->load_file( filename.c_str() );
     assert( MB_SUCCESS == result );
@@ -39,7 +40,7 @@
 
   return 0;
 }
-MBInterface* mb_instance() {
-  static MBCore inst;
+Interface* mb_instance() {
+  static Core inst;
   return &inst;
 }

Modified: MOAB/trunk/tools/dagmc/ray_fire_test.cc
===================================================================
--- MOAB/trunk/tools/dagmc/ray_fire_test.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/ray_fire_test.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,8 @@
-#include "MBInterface.hpp"
-#include "MBCore.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Core.hpp"
 #include "DagMC.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCartVect.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/CartVect.hpp"
 
 #include <vector>
 #include <iostream>
@@ -26,6 +26,8 @@
 #endif
 #endif
 
+using namespace moab;
+
 // define following macro for verbose debugging of random ray generation
 //#define DEBUG
 
@@ -33,7 +35,7 @@
                   double &sys_time, double &tot_mem);
 
 void dump_pyfile( char* filename, double timewith, double timewithout, double tmem, DagMC& dagmc,
-		  MBOrientedBoxTreeTool::TrvStats* trv_stats, MBEntityHandle tree_root );
+		  OrientedBoxTreeTool::TrvStats* trv_stats, EntityHandle tree_root );
 
 static const double PI = acos(-1.0);
 static const double denom = 1.0 / ((double) RAND_MAX);
@@ -50,10 +52,10 @@
 }
 
 /* program global data, including settings with their defaults*/
-typedef struct{ MBCartVect p; MBCartVect v; } ray_t;
+typedef struct{ CartVect p; CartVect v; } ray_t;
 std::vector< ray_t > rays; // list of user-specified rays (given with -f flag)
 
-static MBCartVect ray_source(0,0,0);
+static CartVect ray_source(0,0,0);
 
 static double facet_tol = 1e-4;
 static double source_rad = 0;
@@ -134,7 +136,7 @@
   return val;
 }
 
-static MBCartVect parse_vector( int& i, int argc, char* argv[] ){
+static CartVect parse_vector( int& i, int argc, char* argv[] ){
   double params[3]; bool err = false;
   for( int j = 0; j<3 && !err; ++j ){
     if( ++i == argc ){
@@ -150,7 +152,7 @@
       usage( "Expected vector specified as <x> <y> <z>", 0, argv[0] );
   }
 
-  return MBCartVect(params);
+  return CartVect(params);
 }
 
 static void parse_ray( int& i, int argc, char* argv[] )
@@ -170,7 +172,7 @@
       usage( "Expected ray specified as <x> <y> <z> <u> <v> <w>", 0, argv[0] );
   }
 
-  MBCartVect point(params), direction(params+3); 
+  CartVect point(params), direction(params+3); 
   direction.normalize(); 
   ray_t ray; ray.p = point; ray.v = direction;
   rays.push_back( ray );
@@ -235,12 +237,12 @@
     usage("No filename specified", 0, argv[0] );
   }
      
-  MBErrorCode rval;
-  MBEntityHandle surf = 0, vol = 0;
+  ErrorCode rval;
+  EntityHandle surf = 0, vol = 0;
   double x, y, z, u, v, w, dist;
 
-  MBOrientedBoxTreeTool::TrvStats* trv_stats = NULL;
-  if( do_trv_stats ){ trv_stats = new MBOrientedBoxTreeTool::TrvStats; }
+  OrientedBoxTreeTool::TrvStats* trv_stats = NULL;
+  if( do_trv_stats ){ trv_stats = new OrientedBoxTreeTool::TrvStats; }
 
   /* Initialize DAGMC and find the appropriate volume */
   std::cout << "Initializing DagMC, facet_tol = " << facet_tol << std::endl;
@@ -369,8 +371,8 @@
             << tmem2 << " bytes (" << tmem2/(1024*1024) << " MB)" << std::endl;
 
   /* Gather OBB tree stats and make final reports */
-  MBEntityHandle root;
-  MBErrorCode result = dagmc.get_root(vol, root);
+  EntityHandle root;
+  ErrorCode result = dagmc.get_root(vol, root);
   if (MB_SUCCESS != result) {
     std::cerr << "Trouble getting tree stats." << std::endl;
     return 2;
@@ -461,7 +463,7 @@
 }
 
 
-class HistogramBuilder : public MBOrientedBoxTreeTool::Op {
+class HistogramBuilder : public OrientedBoxTreeTool::Op {
 
 protected:
   int last_depth;
@@ -477,7 +479,7 @@
   std::vector<int> node_counts;
   std::vector<int> leaf_counts;
 
-  virtual MBErrorCode visit( MBEntityHandle node, int depth, bool& descend ){
+  virtual ErrorCode visit( EntityHandle node, int depth, bool& descend ){
     ensure_depth( depth );
     last_depth = depth;
 
@@ -487,13 +489,13 @@
     return MB_SUCCESS;
   }
        
-  virtual MBErrorCode leaf( MBEntityHandle node ){
+  virtual ErrorCode leaf( EntityHandle node ){
     leaf_counts[last_depth] += 1;
     return MB_SUCCESS;
   }
 };
 
-void write_obbtree_histogram( MBEntityHandle root, MBOrientedBoxTreeTool& tree, std::ostream& out ){
+void write_obbtree_histogram( EntityHandle root, OrientedBoxTreeTool& tree, std::ostream& out ){
 
   HistogramBuilder hb;
   tree.preorder_traverse( root, hb ); 
@@ -509,7 +511,7 @@
 #define DICT_VAL(X) out << "'" #X "':" << X << "," << std::endl;
 #define DICT_VAL_STR(X) out << "'" #X  "':'" << X << "'," << std::endl;
 void dump_pyfile( char* filename, double timewith, double timewithout, double tmem, DagMC& dagmc,
-		  MBOrientedBoxTreeTool::TrvStats* trv_stats, MBEntityHandle tree_root ){
+		  OrientedBoxTreeTool::TrvStats* trv_stats, EntityHandle tree_root ){
   std::ofstream out(pyfile);
   out.precision( 14 );
 

Modified: MOAB/trunk/tools/dagmc/test_geom.cc
===================================================================
--- MOAB/trunk/tools/dagmc/test_geom.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/dagmc/test_geom.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,8 @@
-#include "MBInterface.hpp"
-#include "MBCore.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Core.hpp"
 #include "DagMC.hpp"
-#include "MBTagConventions.hpp"
-#include "MBRange.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Range.hpp"
 
 #include <vector>
 #include <iostream>
@@ -15,27 +15,29 @@
 
 const double ROOT2 = 1.4142135623730951;
 
+using namespace moab;
+
 // Create file containing geometry for 2x2x2 cube 
 // centered at origin and having a convex +Z face
 // (center of face at origin).
-MBErrorCode write_geometry( const char* output_file_name );
+ErrorCode write_geometry( const char* output_file_name );
 
-MBErrorCode test_ray_fire( DagMC& );
+ErrorCode test_ray_fire( DagMC& );
 
-MBErrorCode test_point_in_volume( DagMC& );
+ErrorCode test_point_in_volume( DagMC& );
 
-MBErrorCode test_measure_volume( DagMC& );
+ErrorCode test_measure_volume( DagMC& );
 
-MBErrorCode test_measure_area( DagMC& );
+ErrorCode test_measure_area( DagMC& );
 
-MBErrorCode test_surface_sense( DagMC& );
+ErrorCode test_surface_sense( DagMC& );
 
 
-MBErrorCode write_geometry( const char* output_file_name )
+ErrorCode write_geometry( const char* output_file_name )
 {
-  MBErrorCode rval;
-  MBCore moab_instance;
-  MBInterface& moab = moab_instance;
+  ErrorCode rval;
+  Core moab_instance;
+  Interface& moab = moab_instance;
   
     // Define a 2x2x2 cube centered at orgin
     // with concavity in +Z face.
@@ -64,13 +66,13 @@
   const unsigned num_verts = sizeof(coords) / (3*sizeof(double));
   const unsigned num_tris = sizeof(connectivity) / (3*sizeof(int));
   const unsigned num_surfs = sizeof(tris_per_surf) / sizeof(unsigned);
-  MBEntityHandle verts[num_verts], tris[num_tris], surfs[num_surfs];
+  EntityHandle verts[num_verts], tris[num_tris], surfs[num_surfs];
   for (unsigned i = 0; i < num_verts; ++i) {
     rval = moab.create_vertex( coords + 3*i, verts[i] ); 
     CHKERR;
   }
   for (unsigned i = 0; i < num_tris; ++i) {
-    const MBEntityHandle conn[] = { verts[connectivity[3*i  ]], 
+    const EntityHandle conn[] = { verts[connectivity[3*i  ]], 
                                     verts[connectivity[3*i+1]], 
                                     verts[connectivity[3*i+2]] };
     rval = moab.create_element( MBTRI, conn, 3, tris[i] );
@@ -78,7 +80,7 @@
   }
   
     // create CAD topology
-  MBEntityHandle* tri_iter = tris;
+  EntityHandle* tri_iter = tris;
   for (unsigned i = 0; i < num_surfs; ++i) {
     rval = moab.create_meshset( MESHSET_SET, surfs[i] );
     CHKERR;
@@ -87,7 +89,7 @@
     tri_iter += tris_per_surf[i];
   }
   
-  MBTag dim_tag, id_tag, sense_tag;
+  Tag dim_tag, id_tag, sense_tag;
   rval = moab.tag_create( GEOM_DIMENSION_TAG_NAME,
                           sizeof(int),
                           MB_TAG_SPARSE,
@@ -101,7 +103,7 @@
                           id_tag, 0, true );
   CHKERR;
   rval = moab.tag_create( "GEOM_SENSE_2",
-                           2*sizeof(MBEntityHandle),
+                           2*sizeof(EntityHandle),
                            MB_TAG_SPARSE,
                            MB_TYPE_HANDLE,
                            sense_tag, 0, true );
@@ -115,7 +117,7 @@
   rval = moab.tag_set_data( id_tag, surfs, num_surfs, &ids[0] );
   CHKERR;
 
-  MBEntityHandle volume;
+  EntityHandle volume;
   rval = moab.create_meshset( MESHSET_SET, volume );
   CHKERR;
   for (unsigned i = 0; i < num_surfs; ++i) {
@@ -123,7 +125,7 @@
     CHKERR;
   }
   
-  std::vector<MBEntityHandle> senses( 2*num_surfs, 0 );
+  std::vector<EntityHandle> senses( 2*num_surfs, 0 );
   for (size_t i = 0; i < senses.size(); i += 2)
     senses[i] = volume;
   rval = moab.tag_set_data( sense_tag, surfs, num_surfs, &senses[0] );
@@ -163,7 +165,7 @@
 
 int main( int argc, char* argv[] )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   const char* filename = "test_geom.h5m";
   
   rval = write_geometry( filename );
@@ -197,13 +199,13 @@
   return errors;
 }
 
-MBErrorCode test_surface_sense( DagMC& dagmc )
+ErrorCode test_surface_sense( DagMC& dagmc )
 {
-  MBErrorCode rval;
-  MBInterface& moab = *dagmc.moab_instance();
+  ErrorCode rval;
+  Interface& moab = *dagmc.moab_instance();
 
-  MBTag dim_tag = dagmc.geom_tag();
-  MBRange surfs, vols;
+  Tag dim_tag = dagmc.geom_tag();
+  Range surfs, vols;
   const int two = 2, three = 3;
   const void* ptrs[] = { &two, &three };
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, ptrs, 1, surfs );
@@ -220,7 +222,7 @@
     return MB_FAILURE;
   }
   
-  for (MBRange::iterator i = surfs.begin(); i != surfs.end(); ++i) {
+  for (Range::iterator i = surfs.begin(); i != surfs.end(); ++i) {
     int sense = 0;
     rval = dagmc.surface_sense( vols.front(), 1, &*i, &sense );
     if (MB_SUCCESS != rval || sense != 1) {
@@ -232,13 +234,13 @@
   return MB_SUCCESS;
 }  
 
-MBErrorCode test_measure_volume( DagMC& dagmc )
+ErrorCode test_measure_volume( DagMC& dagmc )
 {
-  MBErrorCode rval;
-  MBInterface& moab = *dagmc.moab_instance();
+  ErrorCode rval;
+  Interface& moab = *dagmc.moab_instance();
   
-  MBTag dim_tag = dagmc.geom_tag();
-  MBRange vols;
+  Tag dim_tag = dagmc.geom_tag();
+  Range vols;
   const int three = 3;
   const void* ptr = &three;
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, &ptr, 1, vols );
@@ -264,13 +266,13 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode test_measure_area( DagMC& dagmc )
+ErrorCode test_measure_area( DagMC& dagmc )
 {
-  MBErrorCode rval;
-  MBInterface& moab = *dagmc.moab_instance();
+  ErrorCode rval;
+  Interface& moab = *dagmc.moab_instance();
 
-  MBTag dim_tag = dagmc.geom_tag();
-  MBRange surfs;
+  Tag dim_tag = dagmc.geom_tag();
+  Range surfs;
   const int two = 2;
   const void* ptr = &two;
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, &ptr, 1, surfs );
@@ -287,7 +289,7 @@
   
     // expect area of 4 for all faces except face 6.
     // face 6 should have area == 4*sqrt(2)
-  MBRange::iterator iter = surfs.begin();
+  Range::iterator iter = surfs.begin();
   for (unsigned i = 0; i < 6; ++i, ++iter) {
     double expected = 4.0;
     if (ids[i] == 6)
@@ -315,7 +317,7 @@
   double distance;
 };
 
-MBErrorCode test_ray_fire( DagMC& dagmc )
+ErrorCode test_ray_fire( DagMC& dagmc )
 {
   const struct ray_fire tests[] = {
   /* src    origin               direction                 dest dist */
@@ -325,11 +327,11 @@
     { 1, { 0.5, 0.5, -1. }, {  0.0, 0.0, 1.0 },             6, 1.5   },
     { 2, { 1.0, 0.0, 0.5 }, { -1.0, 0.0, 0.0 },             6, 0.5   } };
 
-  MBErrorCode rval;
-  MBInterface& moab = *dagmc.moab_instance();
+  ErrorCode rval;
+  Interface& moab = *dagmc.moab_instance();
 
-  MBTag dim_tag = dagmc.geom_tag();
-  MBRange surfs, vols;
+  Tag dim_tag = dagmc.geom_tag();
+  Range surfs, vols;
   const int two = 2, three = 3;
   const void* ptrs[] = { &two, &three };
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, ptrs, 1, surfs );
@@ -349,7 +351,7 @@
   int ids[6];
   rval = moab.tag_get_data( dagmc.id_tag(), surfs, ids );
   CHKERR;
-  MBEntityHandle surf[6];
+  EntityHandle surf[6];
   std::copy( surfs.begin(), surfs.end(), surf );
   
   const int num_test = sizeof(tests) / sizeof(tests[0]);
@@ -360,7 +362,7 @@
       std::cerr << "Surface " << tests[i].prev_surf << " not found." << std::endl;
       return MB_FAILURE;
     }
-    const MBEntityHandle src_surf = surf[idx];
+    const EntityHandle src_surf = surf[idx];
     
     ptr = std::find( ids, ids+6, tests[i].hit_surf );
     idx = ptr - ids;
@@ -368,10 +370,10 @@
       std::cerr << "Surface " << tests[i].hit_surf << " not found." << std::endl;
       return MB_FAILURE;
     }
-    const MBEntityHandle hit_surf = surf[idx];
+    const EntityHandle hit_surf = surf[idx];
     
     double dist;
-    MBEntityHandle result;
+    EntityHandle result;
     rval = dagmc.ray_fire( vols.front(), 
                            src_surf, 
                            2, 
@@ -385,7 +387,7 @@
                            dist, result );
     
     if (result != hit_surf || fabs(dist - tests[i].distance) > 1e-6) {
-      MBEntityHandle *p = std::find( surf, surf+6, result );
+      EntityHandle *p = std::find( surf, surf+6, result );
       idx = p - surf;
       int id = idx > 5 ? 0 : ids[idx];
       
@@ -410,7 +412,7 @@
 
 struct PointInVol { double coords[3]; int result; };
 
-MBErrorCode test_point_in_volume( DagMC& dagmc )
+ErrorCode test_point_in_volume( DagMC& dagmc )
 {
   const char* const NAME_ARR[] = { "Boundary", "Outside", "Inside" };
   const char* const* names = NAME_ARR + 1;
@@ -438,11 +440,11 @@
     { { 0.0, 0.0,-1.0 }, BOUNDARY} };
   const int num_test = sizeof(tests) / sizeof(tests[0]);
 
-  MBErrorCode rval;
-  MBInterface& moab = *dagmc.moab_instance();
+  ErrorCode rval;
+  Interface& moab = *dagmc.moab_instance();
 
-  MBTag dim_tag = dagmc.geom_tag();
-  MBRange vols;
+  Tag dim_tag = dagmc.geom_tag();
+  Range vols;
   const int three = 3;
   const void* ptr = &three;
   rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, &ptr, 1, vols );
@@ -451,7 +453,7 @@
     std::cerr << "ERROR: Expected 1 volume in input, found " << vols.size() << std::endl;
     return MB_FAILURE;
   }
-  const MBEntityHandle vol = vols.front();
+  const EntityHandle vol = vols.front();
 
   for (int i = 0; i < num_test; ++i) {
     int result;

Modified: MOAB/trunk/tools/depth.cpp
===================================================================
--- MOAB/trunk/tools/depth.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/depth.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,11 @@
-#include "MBRange.hpp"
-#include "MBCore.hpp"
-#include "MBSkinner.hpp"
+#include "moab/Range.hpp"
+#include "moab/Core.hpp"
+#include "moab/Skinner.hpp"
 #include <iostream>
 #include <stdlib.h>
 
+using namespace moab;
+
 enum {
   NO_ERROR= 0,
   SYNTAX_ERROR = 1,
@@ -28,7 +30,7 @@
   exit(NO_ERROR);
 }
 
-void check( MBErrorCode rval )
+void check( ErrorCode rval )
 {
   if (MB_SUCCESS != rval) {
     std::cerr << "Internal error.  Aborting." << std::endl;
@@ -36,7 +38,7 @@
   }
 }
 
-void tag_depth( MBInterface& moab, MBTag tag );
+void tag_depth( Interface& moab, Tag tag );
 
 int main( int argc, char* argv[] )
 {
@@ -72,11 +74,11 @@
     usage(argv[0]);
   }
 
-  MBCore moab;
-  MBInterface& mb = moab;
+  Core moab;
+  Interface& mb = moab;
   
-  MBEntityHandle file;
-  MBErrorCode rval;
+  EntityHandle file;
+  ErrorCode rval;
   rval = mb.create_meshset( MESHSET_SET, file ); check(rval);
   rval = mb.load_file( input, &file );
   if (MB_SUCCESS != rval) {
@@ -85,7 +87,7 @@
   }
   
   int init_val = -1;
-  MBTag tag;
+  Tag tag;
   rval = mb.tag_create( tagname, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &init_val );
   if (MB_ALREADY_ALLOCATED == rval) {
     rval = mb.tag_delete( tag ); check(rval);
@@ -106,25 +108,25 @@
   return NO_ERROR;
 }
 
-MBErrorCode get_adjacent_elems( MBInterface& mb, const MBRange& verts, MBRange& elems )
+ErrorCode get_adjacent_elems( Interface& mb, const Range& verts, Range& elems )
 {
   elems.clear();
-  MBErrorCode rval;
+  ErrorCode rval;
   for (int dim = 3; dim > 0; --dim) {
-    rval = mb.get_adjacencies( verts, dim, false, elems, MBInterface::UNION );
+    rval = mb.get_adjacencies( verts, dim, false, elems, Interface::UNION );
     if (MB_SUCCESS != rval)
       break;
   }
   return rval;
 }
 
-void tag_depth( MBInterface& mb, MBTag tag )
+void tag_depth( Interface& mb, Tag tag )
 {
-  MBErrorCode rval;
+  ErrorCode rval;
   int dim;
   
-  MBSkinner tool(&mb);
-  MBRange verts, elems;
+  Skinner tool(&mb);
+  Range verts, elems;
   dim = 3;
   while (elems.empty()) {
     rval = mb.get_entities_by_dimension( 0, dim, elems ); check(rval);
@@ -142,13 +144,13 @@
     rval = mb.tag_set_data( tag, elems, &data[0] ); check(rval);
     
     verts.clear();
-    rval = mb.get_adjacencies( elems, 0, false, verts, MBInterface::UNION );
+    rval = mb.get_adjacencies( elems, 0, false, verts, Interface::UNION );
     check(rval);
     
-    MBRange tmp;
+    Range tmp;
     rval = get_adjacent_elems( mb, verts, tmp ); check(rval);
     elems.clear();
-    for (MBRange::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i) {
+    for (Range::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i) {
       rval = mb.tag_get_data( tag, &*i, 1, &val ); check(rval);
       if (val == -1)
         elems.insert( *i );

Modified: MOAB/trunk/tools/gsets.cc
===================================================================
--- MOAB/trunk/tools/gsets.cc	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/gsets.cc	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,20 +1,22 @@
 #include <iostream>
 #include <stdlib.h>
-#include "MBRange.hpp"
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "GeomTopoTool.hpp"
+#include "moab/Range.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/GeomTopoTool.hpp"
 
-MBTag geomTag = 0;
-MBTag blockTag = 0;
-MBTag sideTag = 0;
-MBTag nodeTag = 0;
-MBTag nameTag = 0;
-MBTag idTag = 0;
+using namespace moab;
+
+Tag geomTag = 0;
+Tag blockTag = 0;
+Tag sideTag = 0;
+Tag nodeTag = 0;
+Tag nameTag = 0;
+Tag idTag = 0;
 bool printAnonSets = false;
 bool printSVSense = false;
 
-MBCore mb;
+Core mb;
 GeomTopoTool geomTool(&mb);
 
 void usage( const char* name, bool brief = true ) {
@@ -46,9 +48,9 @@
 
 enum Link { NONE = 0, SOLID, DASHED };
 void write_dot( Link contained, Link children );
-void dot_nodes( std::ostream& s, MBRange& sets_out );
-void dot_children( std::ostream& s, const MBRange& sets, bool dashed );
-void dot_contained( std::ostream& s, const MBRange& sets, bool dashed );
+void dot_nodes( std::ostream& s, Range& sets_out );
+void dot_children( std::ostream& s, const Range& sets, bool dashed );
+void dot_contained( std::ostream& s, const Range& sets, bool dashed );
 
 int main( int argc, char* argv[] )
 {
@@ -105,7 +107,7 @@
     return 1;
   }
 
-  MBTag t;
+  Tag t;
   if (printGeomSets) {
     if (MB_SUCCESS == mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, t )) {
       geomTag = t;
@@ -137,7 +139,7 @@
   
 void write_dot( Link contained, Link children )
 {
-  MBRange sets;
+  Range sets;
   std::cout << "digraph {" << std::endl;
   dot_nodes( std::cout, sets );
   std::cout << std::endl;
@@ -148,8 +150,8 @@
   std::cout << "}" << std::endl;
 }
 
-void dot_get_sets( MBRange& curr_sets, MBRange& result_sets, 
-                   MBTag tag, void* tag_val = 0 )
+void dot_get_sets( Range& curr_sets, Range& result_sets, 
+                   Tag tag, void* tag_val = 0 )
 {
   if (!tag)
     return;
@@ -160,7 +162,7 @@
   curr_sets.merge( result_sets );
 }
 
-void dot_write_node( std::ostream& s, MBEntityHandle h, 
+void dot_write_node( std::ostream& s, EntityHandle h, 
                      const char* label, int* id = 0 )
 {
   s << 's' << mb.id_from_handle(h) << " [label = \"" << label;
@@ -170,21 +172,21 @@
 }
 
 void dot_write_id_nodes( std::ostream& s,
-                         const MBRange& entites,
-                         MBTag id_tag,
+                         const Range& entites,
+                         Tag id_tag,
                          const char* type_name )
 {
   int id;
-  for (MBRange::iterator i = entites.begin(); i != entites.end(); ++i)
+  for (Range::iterator i = entites.begin(); i != entites.end(); ++i)
     if (MB_SUCCESS == mb.tag_get_data( id_tag, &*i, 1, &id )) 
       dot_write_node( s, *i, type_name, &id );
 }
 
-void dot_nodes( std::ostream& s, MBRange& sets )
+void dot_nodes( std::ostream& s, Range& sets )
 {
-  MBRange vol_sets, surf_sets, curv_sets, vert_sets;
-  MBRange block_sets, side_sets, node_sets;
-  MBRange named_sets, other_sets;
+  Range vol_sets, surf_sets, curv_sets, vert_sets;
+  Range block_sets, side_sets, node_sets;
+  Range named_sets, other_sets;
 
   dot_get_sets( sets, named_sets, nameTag );
     
@@ -203,7 +205,7 @@
 
   if (printAnonSets) {
     mb.get_entities_by_type( 0, MBENTITYSET, other_sets );
-    MBRange xsect = subtract( other_sets,  sets );
+    Range xsect = subtract( other_sets,  sets );
     sets.swap(other_sets);
     other_sets.swap(xsect);
   }
@@ -216,7 +218,7 @@
   dot_write_id_nodes( s, side_sets, sideTag, "Neumann Set" );
   dot_write_id_nodes( s, node_sets, nodeTag, "Dirichlet Set" );
   
-  MBRange::iterator i;
+  Range::iterator i;
   char name[NAME_TAG_SIZE+1];
   for (i = named_sets.begin(); i != named_sets.end(); ++i) {
     if (MB_SUCCESS == mb.tag_get_data( nameTag, &*i, 1, name )) {
@@ -231,8 +233,8 @@
 }
 
 void dot_down_link( std::ostream& s,
-                    MBEntityHandle parent,
-                    MBEntityHandle child,
+                    EntityHandle parent,
+                    EntityHandle child,
                     bool dashed,
                     const char* label = 0 )
 {
@@ -249,17 +251,17 @@
 
 
 void dot_children( std::ostream& s, 
-                   const MBRange& sets,
+                   const Range& sets,
                    bool dashed )
 {
   bool forward;
   const char *fstr = "forward", *rstr = "reverse";
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
-    MBRange parents;
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
+    Range parents;
     mb.get_parent_meshsets( *i, parents );
     parents = intersect( parents,  sets );
     
-    for (MBRange::iterator j = parents.begin(); j != parents.end(); ++j) {
+    for (Range::iterator j = parents.begin(); j != parents.end(); ++j) {
       const char* linklabel = 0;
       if (printSVSense && MB_SUCCESS == geomTool.get_sense( *i, *j, forward ))
         linklabel = forward ? fstr : rstr;
@@ -270,15 +272,15 @@
 
 
 void dot_contained( std::ostream& s, 
-                    const MBRange& sets,
+                    const Range& sets,
                     bool dashed )
 {
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i) {
-    MBRange contained;
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i) {
+    Range contained;
     mb.get_entities_by_type(*i, MBENTITYSET, contained );
     contained = intersect( contained,  sets );
     
-    for (MBRange::iterator j = contained.begin(); j != contained.end(); ++j)
+    for (Range::iterator j = contained.begin(); j != contained.end(); ++j)
       dot_down_link( s, *i, *j, dashed );
   }
 }

Deleted: MOAB/trunk/tools/main.cpp
===================================================================
--- MOAB/trunk/tools/main.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/main.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,52 +0,0 @@
-/*
- * Sphere decomp tool.  Meshes a group of spheres and the interstices between with
- * hex elements, by triangulating the vertices corresponding to sphere centers
- * and subdividing those tets.  For a description of the subdivision template used,
- * see comments in the subdivide_tet function below.
- */
-
-#include "MBCore.hpp"
-#include "SphereDecomp.hpp"
-#include <iostream>
-
-const char *SPHERE_RADII_TAG_NAME = "SPHERE_RADII";
-
-#define RR if (MB_SUCCESS != result) return result
-
-int main(int argc, char *argv[]) 
-{
-  if (argc < 3) {
-    std::cout << "Usage: " << argv[0] << " <input_mesh> <output_mesh>" << std::endl;
-    return 0;
-  }
-  
-    // create MOAB
-  MBInterface *mbImpl = new MBCore();
-  
-    // read in mesh
-  MBErrorCode result = mbImpl->load_mesh(argv[1]); 
-  if (MB_SUCCESS != result) {
-    std::cout << "Problems loading mesh." << std::endl;
-    return 1;
-  }
-
-  MBTag sphere_radii_tag = 0;
-  double dum_val = 0.1;
-  result = mbImpl->tag_create(SPHERE_RADII_TAG_NAME, sizeof(double), 
-                              MB_TAG_DENSE, MB_TYPE_DOUBLE, sphere_radii_tag, &dum_val); 
-  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) {
-    std::cout << "Problem allocating SPHERE_RADII tag." << std::endl;
-    return 1;
-  }
-
-  SphereDecomp sd(mbImpl);
-
-  MBEntityHandle this_set = 0;
-  result = sd.build_sphere_mesh(SPHERE_RADII_TAG_NAME, &this_set); RR;
-  
-    // write mesh
-  result = mbImpl->write_mesh(argv[2], &this_set, 1); RR;
-  
-  return 0;
-}
-

Modified: MOAB/trunk/tools/makeops.cpp
===================================================================
--- MOAB/trunk/tools/makeops.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/makeops.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,25 +3,27 @@
  *
  */
 
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include <iostream>
 
-MBInterface *gMB = NULL;
+using namespace moab;
 
-MBErrorCode make_atomic_pillow();
-MBErrorCode make_face_shrink();
-MBErrorCode make_face_open_collapse();
-MBErrorCode make_chord_push();
-MBErrorCode make_triple_chord_push();
-MBErrorCode make_triple_hex_push();
+Interface *gMB = NULL;
 
+ErrorCode make_atomic_pillow();
+ErrorCode make_face_shrink();
+ErrorCode make_face_open_collapse();
+ErrorCode make_chord_push();
+ErrorCode make_triple_chord_push();
+ErrorCode make_triple_hex_push();
+
 enum OperationType {ATOMIC_PILLOW = 0, 
                     FACE_OPEN_COLLAPSE, 
                     FACE_SHRINK, 
                     CHORD_PUSH, 
-                    TRIPLE_CHORD_PUSH, 
-                    TRIPLE_HEX_PUSH,
+                    MBTRIPLE_CHORD_PUSH, 
+                    MBTRIPLE_HEX_PUSH,
                     UNDEFINED};
 
 const char *OperationNames[] = {"atomic_pillow", 
@@ -34,7 +36,7 @@
 
 int main(int argc, char **argv) 
 {
-  gMB = new MBCore();
+  gMB = new Core();
   const char *extensions[] = 
     {
       ".g",
@@ -66,13 +68,13 @@
     else if (!strcmp("-cp", argv[current_arg])) 
       op_types.push_back(CHORD_PUSH);
     else if (!strcmp("-tcp", argv[current_arg])) 
-      op_types.push_back(TRIPLE_CHORD_PUSH);
+      op_types.push_back(MBTRIPLE_CHORD_PUSH);
     else if (!strcmp("-thp", argv[current_arg])) 
-      op_types.push_back(TRIPLE_HEX_PUSH);
+      op_types.push_back(MBTRIPLE_HEX_PUSH);
     current_arg++;
   }
   
-  MBErrorCode result = MB_SUCCESS, tmp_result = MB_FAILURE;
+  ErrorCode result = MB_SUCCESS, tmp_result = MB_FAILURE;
 
   for (std::vector<OperationType>::iterator vit = op_types.begin(); 
        vit != op_types.end(); vit++) {
@@ -85,11 +87,11 @@
     else if (*vit == CHORD_PUSH) {
       tmp_result = make_chord_push();
     }
-    else if (*vit == TRIPLE_CHORD_PUSH) {
+    else if (*vit == MBTRIPLE_CHORD_PUSH) {
       tmp_result = make_triple_chord_push();
     }
 
-    else if (*vit == TRIPLE_HEX_PUSH) {
+    else if (*vit == MBTRIPLE_HEX_PUSH) {
       tmp_result = make_triple_hex_push();
     }
     else if (*vit == FACE_SHRINK) {
@@ -110,7 +112,7 @@
   return (result == MB_SUCCESS ? 0 : 1);
 }
 
-MBErrorCode make_atomic_pillow() 
+ErrorCode make_atomic_pillow() 
 {
     // make atomic pillow configuration
     // make all vertices
@@ -131,15 +133,15 @@
     4, 5, 6, 7, 0, 1, 2, 3
   };
 
-  MBErrorCode result;
-  MBEntityHandle vtx_handles[8];
+  ErrorCode result;
+  EntityHandle vtx_handles[8];
   
   for (int i = 0; i < 8; i++) {
     result = gMB->create_vertex(&vtx_coord[3*i], vtx_handles[i]);
     if (MB_SUCCESS != result) return MB_FAILURE;
   }
   
-  MBEntityHandle conn[8], elems[4];
+  EntityHandle conn[8], elems[4];
 
     // make the two hexes
   for (int i = 0; i < 8; i++)
@@ -171,7 +173,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode make_face_shrink() 
+ErrorCode make_face_shrink() 
 {
     // make face shrink configuration
     // make all vertices
@@ -204,8 +206,8 @@
     12, 15, 14, 13, 8, 11, 10, 9
   };
 
-  MBErrorCode result;
-  MBEntityHandle vtx_handles[16];
+  ErrorCode result;
+  EntityHandle vtx_handles[16];
   
   for (int i = 0; i < 16; i++) {
     result = gMB->create_vertex(&vtx_coord[3*i], vtx_handles[i]);
@@ -213,7 +215,7 @@
   }
   
     // make all elements at once
-  MBEntityHandle conn[8], elems[6];
+  EntityHandle conn[8], elems[6];
 
   for (int j = 0; j < 6; j++) {
     for (int i = 0; i < 8; i++)
@@ -226,12 +228,12 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode make_face_open_collapse() 
+ErrorCode make_face_open_collapse() 
 {
   return MB_FAILURE;
 }
 
-MBErrorCode make_chord_push() 
+ErrorCode make_chord_push() 
 {
     // make chord push configuration
     // make all vertices
@@ -279,15 +281,15 @@
     0, 4, 11, 7
   };
 
-  MBErrorCode result;
-  MBEntityHandle vtx_handles[16];
+  ErrorCode result;
+  EntityHandle vtx_handles[16];
   
   for (int i = 0; i < 16; i++) {
     result = gMB->create_vertex(&vtx_coord[3*i], vtx_handles[i]);
     if (MB_SUCCESS != result) return MB_FAILURE;
   }
   
-  MBEntityHandle conn[8], elems[12];
+  EntityHandle conn[8], elems[12];
 
     // make the five hexes
   for (int i = 0; i < 5; i++) {
@@ -369,7 +371,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode make_triple_chord_push() 
+ErrorCode make_triple_chord_push() 
 {
     // make chord push configuration
     // make all vertices
@@ -410,15 +412,15 @@
     2, 1, 15, 3, 14, 6, 5, 4
   };
 
-  MBErrorCode result;
-  MBEntityHandle vtx_handles[16];
+  ErrorCode result;
+  EntityHandle vtx_handles[16];
   
   for (int i = 0; i < 16; i++) {
     result = gMB->create_vertex(&vtx_coord[3*i], vtx_handles[i]);
     if (MB_SUCCESS != result) return MB_FAILURE;
   }
   
-  MBEntityHandle conn[8], elems[12];
+  EntityHandle conn[8], elems[12];
 
     // make the five hexes
   for (int i = 0; i < 5; i++) {
@@ -431,7 +433,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode make_triple_hex_push() 
+ErrorCode make_triple_hex_push() 
 {
   return MB_FAILURE;
 }

Modified: MOAB/trunk/tools/mbchaco/ComputePartition.cpp
===================================================================
--- MOAB/trunk/tools/mbchaco/ComputePartition.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbchaco/ComputePartition.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -23,15 +23,17 @@
 
 #include "ComputePartition.hpp"
 #define IS_BUILDING_MB
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #undef IS_BUILDING_MB
-#include "MBRange.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MeshTopoUtil.hpp"
+#include "moab/Range.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "moab/MeshTopoUtil.hpp"
 
 #include "defs.h"
 #include "params.h"
 
+using namespace moab;
+
 extern char *PARAMS_FILENAME;	/* name of file with parameter updates */
 extern double EIGEN_TOLERANCE;	/* tolerance for eigen calculations */
 extern long RANDOM_SEED;	/* seed for random number generators */
@@ -63,7 +65,7 @@
 
 #define RR if (MB_SUCCESS != result) return result
 
-MBErrorCode ComputePartition::compute_partition(const int nprocs, 
+ErrorCode ComputePartition::compute_partition(const int nprocs, 
                                                 const char *filename, 
                                                 const bool write_file,
                                                 const char *out_file) 
@@ -75,18 +77,18 @@
   
   if (NULL == mbImpl) {
       // instantiate MOAB & read the mesh
-    mbImpl = new MBCore();
+    mbImpl = new Core();
     new_moab = true;
   
     if (NULL == mbImpl) return MB_FAILURE;
   }
   
-  MBErrorCode result = mbImpl->load_mesh(filename); RR;
+  ErrorCode result = mbImpl->load_mesh(filename); RR;
   
     // assemble the graph
   short *assignment;
   std::vector<int> adjacencies, start;
-  MBRange elems;
+  Range elems;
   
   result = assemble_graph(3, adjacencies, start, elems); RR;
 
@@ -120,7 +122,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ComputePartition::drive_chaco(const int nprocs,
+ErrorCode ComputePartition::drive_chaco(const int nprocs,
                                           std::vector<int> &adjacencies, 
                                           std::vector<int> &start, 
                                           short *&assignment) 
@@ -198,26 +200,26 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ComputePartition::assemble_graph(const int dimension, 
+ErrorCode ComputePartition::assemble_graph(const int dimension, 
                                              std::vector<int> &adjacencies, 
                                              std::vector<int> &start, 
-                                             MBRange &elems) 
+                                             Range &elems) 
 {
     // assemble a graph with vertices equal to elements of specified dimension, edges
     // signified by list of other elements to which an element is connected
 
     // get the elements of that dimension
-  MBErrorCode result = mbImpl->get_entities_by_dimension(0, dimension, elems);
+  ErrorCode result = mbImpl->get_entities_by_dimension(0, dimension, elems);
   if (MB_SUCCESS != result || elems.empty()) return result;
   
     // get a tag for graph vertex number
-  MBTag gvert_id;
+  Tag gvert_id;
   result = mbImpl->tag_create("__graph_vertex_id", 4, MB_TAG_DENSE, gvert_id, NULL);
   if (MB_SUCCESS != result) return result;
   
     // assign increasing graph vertex ids
-  MBWriteUtilIface *iface = NULL;
-  result = mbImpl->query_interface("MBWriteUtilIface", reinterpret_cast<void**>(&iface));
+  WriteUtilIface *iface = NULL;
+  result = mbImpl->query_interface("WriteUtilIface", reinterpret_cast<void**>(&iface));
   if (MB_SUCCESS != result || NULL == iface) return (MB_SUCCESS != result ? result : MB_FAILURE);
 
 #define START_ID 1
@@ -227,12 +229,12 @@
     // now assemble the graph, calling MeshTopoUtil to get bridge adjacencies through d-1 dimensional
     // neighbors
   MeshTopoUtil mtu(mbImpl);
-  MBRange adjs;
+  Range adjs;
     // can use a fixed-size array 'cuz the number of lower-dimensional neighbors is limited
     // by MBCN
   int neighbors[MB_MAX_SUB_ENTITIES];
   
-  for (MBRange::iterator rit = elems.begin(); rit != elems.end(); rit++) {
+  for (Range::iterator rit = elems.begin(); rit != elems.end(); rit++) {
 
       // get bridge adjacencies
     adjs.clear();
@@ -263,21 +265,21 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode ComputePartition::write_partition(const int nprocs, MBRange &elems, 
+ErrorCode ComputePartition::write_partition(const int nprocs, Range &elems, 
                                               const short *assignment) 
 {
     // first, create partition sets and store in vector
-  MBEntityHandle *part_sets = new MBEntityHandle[nprocs];
+  EntityHandle *part_sets = new EntityHandle[nprocs];
   if (NULL == part_sets) return MB_FAILURE;
   
-  MBErrorCode result;
+  ErrorCode result;
   for (int i = 0; i < nprocs; i++) {
     result = mbImpl->create_meshset(MESHSET_SET, part_sets[i]); RR;
   }
   
     // write a tag to those sets denoting they're partition sets, with a value of the
     // proc number
-  MBTag part_set_tag;
+  Tag part_set_tag;
   int dum_id = -1;
   result = mbImpl->tag_create("PARALLEL_PARTITION", 4, MB_TAG_SPARSE, part_set_tag, &dum_id); RR;
   
@@ -288,7 +290,7 @@
   
 
     // assign entities to the relevant sets
-  MBRange::iterator rit;
+  Range::iterator rit;
   int i;
   int *tag_data = new int[elems.size()];
   for (rit = elems.begin(), i = 0; rit != elems.end(); rit++, i++) {
@@ -298,7 +300,7 @@
   }
 
     // allocate integer-size partitions
-  MBTag elem_part_set_tag;
+  Tag elem_part_set_tag;
   dum_id = -1;
   result = mbImpl->tag_create("ELEM_PARALLEL_PARTITION", 4, MB_TAG_SPARSE, MB_TYPE_INTEGER,
                               elem_part_set_tag, &dum_id); RR;

Modified: MOAB/trunk/tools/mbchaco/ComputePartition.hpp
===================================================================
--- MOAB/trunk/tools/mbchaco/ComputePartition.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbchaco/ComputePartition.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -23,44 +23,46 @@
 
 #include <vector>
 
-#include "MBInterface.hpp"
+#include "moab/Interface.hpp"
 
+using namespace moab;
+
 class ComputePartition 
 {
 
 public:
-  ComputePartition(MBInterface *impl = NULL, const bool use_coords = false) 
+  ComputePartition(Interface *impl = NULL, const bool use_coords = false) 
       : mbImpl(impl), newMoab(false), useCoords(use_coords)
     {}
 
   ~ComputePartition() {}
 
     // compute a partition; NULL filename means MOAB already contains the mesh
-  MBErrorCode compute_partition(const int nprocs, const char *filename = NULL, 
+  ErrorCode compute_partition(const int nprocs, const char *filename = NULL, 
                                 const bool write_file = false, const char *out_file = NULL);
   
 private:
 
-  MBInterface *mbImpl;
+  Interface *mbImpl;
 
   bool newMoab;
   
   bool useCoords;
 
-  MBErrorCode drive_chaco(const int nprocs,
+  ErrorCode drive_chaco(const int nprocs,
                           std::vector<int> &adjacencies, 
                           std::vector<int> &start, 
                           short *&assignment);
   
     // given the dimension, assemble the graph and store in adjacencies and start
-  MBErrorCode assemble_graph(const int dimension, 
+  ErrorCode assemble_graph(const int dimension, 
                              std::vector<int> &adjacencies, 
                              std::vector<int> &start, 
-                             MBRange &elems);
+                             Range &elems);
   
     // given a processor assignment returned from Chaco, write that as a processor
     // assignment to MOAB
-  MBErrorCode write_partition(const int nprocs, MBRange &elems, 
+  ErrorCode write_partition(const int nprocs, Range &elems, 
                               const short *assignment);
 };
 

Modified: MOAB/trunk/tools/mbchaco/Makefile.am
===================================================================
--- MOAB/trunk/tools/mbchaco/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbchaco/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,5 +1,4 @@
-AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src $(CHACO_INCLUDES) \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab
+AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src $(CHACO_INCLUDES)
 bin_PROGRAMS = mbchaco
 mbchaco_SOURCES = ComputePartition.hpp ComputePartition.cpp main.cpp
 LDADD = $(top_builddir)/src/libMOAB.la $(CHACO_LIBS)

Modified: MOAB/trunk/tools/mbcoupler/CMakeLists.txt
===================================================================
--- MOAB/trunk/tools/mbcoupler/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -3,8 +3,8 @@
 )
 
 set( MBCOUPLER_SRCS
-  MBCoupler.cpp
-  MBElemUtil.cpp
+  Coupler.cpp
+  ElemUtil.cpp
   errmem.c
   findpt.c
   poly.c

Copied: MOAB/trunk/tools/mbcoupler/Coupler.cpp (from rev 3583, MOAB/trunk/tools/mbcoupler/MBCoupler.cpp)
===================================================================
--- MOAB/trunk/tools/mbcoupler/Coupler.cpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/Coupler.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,512 @@
+#include "Coupler.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/GeomUtil.hpp"
+#include "ElemUtil.hpp"
+#include "moab/MBCN.hpp"
+#include "iostream"
+
+extern "C" 
+{
+#include "types.h"
+#include "errmem.h"
+#include "minmax.h"
+#include "sort.h"
+#include "tuple_list.h"
+#include "crystal.h"
+#include "transfer.h"
+}
+
+#include "assert.h"
+
+namespace moab {
+
+Coupler::Coupler(Interface *impl,
+                     ParallelComm *pc,
+                     Range &local_elems,
+                     int coupler_id,
+                     bool init_tree)
+    : mbImpl(impl), myPc(pc), myId(coupler_id), numIts(3)
+{
+  assert(NULL != impl && NULL != myPc);
+
+    // keep track of the local points, at least for now
+  myRange = local_elems;
+
+    // now initialize the tree
+  if (init_tree) initialize_tree();
+
+
+
+
+    // initialize tuple lists to indicate not initialized
+  mappedPts = NULL;
+  targetPts = NULL;
+}
+
+  /* destructor
+   */
+Coupler::~Coupler()
+{}
+
+
+ErrorCode Coupler::initialize_tree()
+{
+  
+  Range local_ents;
+  AdaptiveKDTree::Settings settings;
+  settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
+  allBoxes.resize(6*myPc->proc_config().proc_size());
+
+    //get entities on the local part
+  ErrorCode result = myPc->get_part_entities(local_ents, 3);
+  if (MB_SUCCESS != result) {
+    std::cout << "Problems getting entities by dimension" << std::endl;
+    return result;
+  }
+
+    // build the tree for local processor
+  for (int i = 0; i < numIts; i++) {
+    myTree = new AdaptiveKDTree(mbImpl);
+    result = myTree->build_tree(local_ents, localRoot, &settings);
+    if (MB_SUCCESS != result) {
+      std::cout << "Problems building tree";
+      if (numIts != i) {
+        delete myTree;
+        settings.maxEntPerLeaf *= 2;
+        std::cout << "; increasing elements/leaf to " 
+                  << settings.maxEntPerLeaf << std::endl;;
+      }
+      else {
+        std::cout << "; exiting" << std::endl;
+        return result;
+      }
+    }
+  }
+
+    // get the bounding box for local tree
+  allBoxes.resize(6*myPc->proc_config().proc_size());
+  unsigned int my_rank = myPc->proc_config().proc_rank();
+  result = myTree->get_tree_box(localRoot, &allBoxes[6*my_rank], &allBoxes[6*my_rank+3]);
+
+    // now communicate to get all boxes
+  int mpi_err = MPI_Allgather(&allBoxes[6*my_rank], 6, MPI_DOUBLE,
+                              &allBoxes[0], 6, MPI_DOUBLE, 
+                              myPc->proc_config().proc_comm());
+
+#ifndef NDEBUG
+  double min[3] = {0,0,0}, max[3] = {0,0,0};
+  unsigned int dep;
+  myTree->get_info(localRoot, min, max, dep);
+  std::cout << "Proc " << my_rank << ": box min/max, tree depth = ("
+            << min[0] << "," << min[1] << "," << min[2] << "), ("
+            << max[0] << "," << max[1] << "," << max[2] << "), "
+            << dep << std::endl;
+#endif  
+
+  if (MPI_SUCCESS == mpi_err) return MB_SUCCESS;
+  else return MB_FAILURE;
+}
+
+ErrorCode Coupler::locate_points(double *xyz, int num_points,
+                                     tuple_list *tl,
+                                     bool store_local)
+{
+  assert(tl || store_local);
+
+    // allocate tuple_list to hold point data: (p, i, , xyz), i = point index
+  tuple_list target_pts;
+  tuple_list_init_max(&target_pts, 2, 0, 0, 3, num_points);
+
+    // initialize source_pts and local_pts
+  tuple_list source_pts;
+  mappedPts = new tuple_list;
+  tuple_list_init_max(&source_pts, 3, 0, 0, 0, target_pts.max); 
+  tuple_list_init_max(mappedPts, 0, 0, 1, 3, target_pts.max); 
+
+  mappedPts->n = 0;
+  source_pts.n = 0;
+  ErrorCode result;
+
+    // keep track of which points have been located
+  std::vector<unsigned char> located_pts(num_points, 0);
+
+    // for each point, find box(es) containing the point,
+    // appending results to tuple_list;
+    // keep local points separately, in local_pts, which has pairs
+    // of <local_index, mapped_index>, where mapped_index is the index
+    // of <local_index, mapped_index>, where mapped_index is the index
+    // into the mappedPts tuple list
+
+  unsigned int my_rank = myPc->proc_config().proc_rank();
+  bool point_located;
+  
+  for (int i = 0; i < 3*num_points; i+=3) 
+  {
+      // test point locally first
+    result = test_local_box(xyz+i, my_rank, i/3, i/3, point_located);
+    if (MB_SUCCESS != result) return result;
+    if (point_located) {
+      located_pts[i/3] = 0x1;
+      continue;
+    }
+
+      // if not located locally, test other procs' boxes
+    for (unsigned int j = 0; j < myPc->proc_config().proc_size(); j++)
+    {
+      if (j == my_rank) continue;
+      
+        // test if point is in proc's box
+      if (allBoxes[6*j] <= xyz[i] && xyz[i] <= allBoxes[6*j+3] && 
+          allBoxes[6*j+1] <= xyz[i+1] && xyz[i+1] <= allBoxes[6*j+4] && 
+          allBoxes[6*j+2] <= xyz[i+2] && xyz[i+2] <= allBoxes[6*j+5])
+      {
+          // if in this proc's box, will send to proc to test further
+          // check size, grow if we're at max
+        if (target_pts.n == target_pts.max)
+          tuple_list_grow(&target_pts);
+  
+        target_pts.vi[2*target_pts.n] = j;
+        target_pts.vi[2*target_pts.n+1] = i/3;
+        target_pts.vr[3*target_pts.n] = xyz[i];
+        target_pts.vr[3*target_pts.n+1] = xyz[i+1];
+        target_pts.vr[3*target_pts.n+2] = xyz[i+2];
+        target_pts.n++;
+      }
+    }
+  }
+
+    // perform scatter/gather, to gather points to source mesh procs
+  gs_transfer(1, &target_pts, 0, myPc->proc_config().crystal_router());
+
+    // after scatter/gather:
+    // target_pts.n = # points local proc has to map
+    // target_pts.vi[2*i] = proc sending point i
+    // target_pts.vi[2*i+1] = index of point i on sending proc
+    // target_pts.vr[3*i..3*i+2] = xyz of point i
+    //
+    // Mapping builds the tuple list:
+    // source_pts.n = target_pts.n
+    // source_pts.vi[3*i] = target_pts.vi[2*i] = sending proc
+    // source_pts.vi[3*i+1] = index of point i on sending proc
+    // source_pts.vi[3*i+2] = index of mapped point (-1 if not mapped)
+    //
+    // Also, mapping builds local tuple_list mappedPts:
+    // mappedPts->n = # mapped points
+    // mappedPts->vul[i] = local handle of mapped entity
+    // mappedPts->vr[3*i..3*i+2] = natural coordinates in mapped entity
+
+    // test target points against my elements
+  for (unsigned i = 0; i < target_pts.n; i++) 
+  {
+    result = test_local_box(target_pts.vr+3*i, 
+                            target_pts.vi[2*i], target_pts.vi[2*i+1], i, 
+                            point_located, &source_pts);
+    if (MB_SUCCESS != result) return result;
+  }
+
+  // no longer need target_pts
+  tuple_list_free(&target_pts);
+
+    // send target points back to target procs
+  gs_transfer(1, &source_pts, 0, myPc->proc_config().crystal_router());
+
+  // store proc/index tuples in targetPts, and/or pass back to application;
+  // the tuple this gets stored to looks like:
+  // tl.n = # mapped points
+  // tl.vi[3*i] = remote proc mapping point
+  // tl.vi[3*i+1] = local index of mapped point
+  // tl.vi[3*i+2] = remote index of mapped point
+  //
+  // Local index is mapped into either myRange, holding the handles of
+  // local mapped entities, or myXyz, holding locations of mapped pts
+
+  // count non-negatives
+  int num_pts = 0;
+  for (unsigned int i = 0; i < source_pts.n; i++)
+    if (-1 != source_pts.vi[3*i+2]) num_pts++;
+
+    // store information about located points
+  targetPts = new tuple_list;
+  tuple_list *tl_tmp = targetPts;
+  if (!store_local) tl_tmp = tl;
+  tuple_list_init_max(tl_tmp, 3, 0, 0, 1, num_pts);
+  for (unsigned int i = 0; i < source_pts.n; i++) {
+    if (-1 != source_pts.vi[3*i+2] && !located_pts[3*i+1]) {
+      tl_tmp->vi[3*i] = source_pts.vi[3*i];
+      tl_tmp->vi[3*i+1] = source_pts.vi[3*i+1];
+      tl_tmp->vi[3*i+2] = source_pts.vi[3*i+2];
+      tl_tmp->n++;
+    }
+  }
+
+  assert(tl_tmp->n + localMappedPts.size()/2 == (unsigned int) num_points);
+  
+    // no longer need source_pts
+  tuple_list_free(&source_pts);
+
+    // copy into tl if passed in and storing locally
+  if (tl && store_local) {
+    tuple_list_init_max(tl, 3, 0, 0, 1, num_pts);
+    memcpy(tl->vi, tl_tmp->vi, 3*tl_tmp->n*sizeof(int));
+    tl->n = tl_tmp->n;
+  }
+
+    // done
+  return MB_SUCCESS;
+}
+
+ErrorCode Coupler::test_local_box(double *xyz, 
+                                      int from_proc, int remote_index, int index, 
+                                      bool &point_located,
+                                      tuple_list *tl)
+{
+  
+  std::vector<EntityHandle> entities;
+  std::vector<CartVect> nat_coords;
+          
+  ErrorCode result = nat_param(xyz, entities, nat_coords);
+  if (MB_SUCCESS != result) return result;
+
+    // if we didn't find any ents and we're looking locally, nothing more to do
+  if (entities.empty() && !tl) 
+    return result;
+  
+    // grow if we know we'll exceed size
+  if (mappedPts->n+entities.size() >= mappedPts->max)
+    tuple_list_grow(mappedPts);
+
+  if (entities.empty() && tl) {
+    tl->vi[3*index] = from_proc;
+    tl->vi[3*index+1] = remote_index;
+    tl->vi[3*index+2] = -1;
+    point_located = false;
+    return MB_SUCCESS;
+  }
+  
+  std::vector<EntityHandle>::iterator eit = entities.begin();
+  std::vector<CartVect>::iterator ncit = nat_coords.begin();
+  for (; eit != entities.end(); eit++, ncit++) {
+      // store in tuple mappedPts
+    mappedPts->vr[3*mappedPts->n] = (*ncit)[0];
+    mappedPts->vr[3*mappedPts->n+1] = (*ncit)[1];
+    mappedPts->vr[3*mappedPts->n+2] = (*ncit)[2];
+    mappedPts->vul[mappedPts->n] = *eit;
+    mappedPts->n++;
+
+      // also store local point, mapped point indices
+    if (tl) 
+    {
+      if (tl->n == tl->max) tuple_list_grow(tl);
+
+        // store in tuple source_pts
+      tl->vi[3*tl->n] = from_proc;
+      tl->vi[3*tl->n+1] = remote_index;
+      tl->vi[3*tl->n+2] = mappedPts->n-1;
+      tl->n++;
+    }
+    else {
+      localMappedPts.push_back(index);
+      localMappedPts.push_back(mappedPts->n-1);
+    }
+  }
+
+  point_located = true;
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode Coupler::interpolate(Coupler::Method method,
+                                   std::string &interp_tag,
+                                   double *interp_vals,
+                                   tuple_list *tl,
+                                   bool normalize)
+{
+  Tag tag;
+  ErrorCode result = mbImpl->tag_get_handle(interp_tag.c_str(), tag);
+  if (MB_SUCCESS != result) return result;
+  return interpolate(method, tag, interp_vals, tl, normalize);
+}
+  
+ErrorCode Coupler::interpolate(Coupler::Method method,
+                                   Tag tag,
+                                   double *interp_vals,
+                                   tuple_list *tl,
+                                   bool normalize)
+{
+  if (!((LINEAR_FE == method) || (PLAIN_FE == method)))
+    return MB_FAILURE;
+
+  tuple_list *tl_tmp = (tl ? tl : targetPts);
+
+    // remote pts first
+  
+    // scatter/gather interpolation points
+  gs_transfer(1, tl_tmp, 0, myPc->proc_config().crystal_router());
+
+    // perform interpolation on local source mesh; put results into
+    // tl_tmp->vr[i]
+  ErrorCode result;
+
+  for (unsigned int i = 0; i < tl_tmp->n; i++) {
+    int mindex = tl_tmp->vi[3*i+2];
+
+    result = MB_FAILURE;
+    if(LINEAR_FE == method){
+      result = interp_field_for_hex(mappedPts->vul[mindex],
+				    CartVect(mappedPts->vr+3*mindex), 
+				    tag, tl_tmp->vr[i]);
+    }else if (PLAIN_FE == method){
+      result = plain_field_map(mappedPts->vul[mindex],
+			       tag, tl_tmp->vr[i]);
+    }
+
+    if (MB_SUCCESS != result) return result;
+  }
+  
+    // scatter/gather interpolation data
+  gs_transfer(1, tl_tmp, 0, myPc->proc_config().crystal_router());
+
+  if (!tl) {
+      // mapped whole targetPts tuple; put into proper place in interp_vals
+    for (unsigned int i = 0; i < tl_tmp->n; i++)
+      interp_vals[tl_tmp->vi[3*i+1]] = tl_tmp->vr[i];
+
+      // now do locally-contained pts, since we're mapping everything
+    for (std::vector<unsigned int>::iterator vit = localMappedPts.begin();
+         vit != localMappedPts.end(); vit += 2) {
+      int mindex = *(vit+1);
+
+      result = MB_FAILURE;
+      if(LINEAR_FE == method){
+	result = interp_field_for_hex(mappedPts->vul[mindex],
+				      CartVect(mappedPts->vr+3*mindex), 
+				      tag, interp_vals[*vit]);
+      }else if (PLAIN_FE == method){
+	result = plain_field_map(mappedPts->vul[mindex],
+				 tag, interp_vals[*vit]);
+      }
+
+      if (MB_SUCCESS != result) return result;
+
+    }
+  }
+  
+    // done
+  return MB_SUCCESS;
+}
+
+ErrorCode Coupler::nat_param(double xyz[3], 
+                                 std::vector<EntityHandle> &entities, 
+                                 std::vector<CartVect> &nat_coords)
+{
+  AdaptiveKDTreeIter treeiter;
+  ErrorCode result = myTree->get_tree_iterator(localRoot, treeiter); 
+  if (MB_SUCCESS != result) {
+    std::cout << "Problems getting iterator" << std::endl;
+    return result;
+  }
+
+  result = myTree->leaf_containing_point(localRoot, xyz, treeiter);
+  if (MB_SUCCESS != result) {
+    std::cout << "Problems getting leaf " << std::endl;
+    return result;
+  }
+
+    // find natural coordinates of point in element(s) in that leaf
+  CartVect tmp_nat_coords; 
+  Range range_leaf;
+  result = mbImpl->get_entities_by_dimension(treeiter.handle(), 3, range_leaf, false);
+  if(result != MB_SUCCESS) std::cout << "Problem getting leaf in a range" << std::endl;
+
+    // loop over the range_leaf 
+  for(Range::iterator iter = range_leaf.begin(); iter != range_leaf.end(); iter++)
+  {
+    const EntityHandle *connect;
+    int num_connect;
+
+      //get connectivity
+    result = mbImpl->get_connectivity(*iter, connect, num_connect, true);
+
+      //get coordinates of the vertices
+    std::vector<CartVect> coords_vert(num_connect);
+    std::vector<double> coords(3*num_connect);
+    result = mbImpl->get_coords(connect, num_connect, &coords[0]);
+	
+    for(int j = 0; j < num_connect; j++)
+    {
+      coords_vert[j][0] = coords[3*j];
+      coords_vert[j][1] = coords[3*j+1];
+      coords_vert[j][2] = coords[3*j+2];
+    }
+
+      //test to find out in which hex the point is
+		
+      // get natural coordinates
+    if (ElemUtil::nat_coords_trilinear_hex(&coords_vert[0], CartVect(xyz), 
+                                             tmp_nat_coords, 1e-10)) {
+      entities.push_back(*iter);
+      nat_coords.push_back(tmp_nat_coords);
+      return MB_SUCCESS;
+    }
+  }
+  
+  return MB_SUCCESS;
+}
+
+ErrorCode Coupler::interp_field_for_hex(EntityHandle elem,
+                                            CartVect nat_coord, 
+                                            Tag tag,
+                                            double &field)
+{
+    //set the vertices coordinates in the natural system
+
+  const double xi[8] = {-1,1,1,-1,-1,1,1,-1};
+  const double etha[8] = {-1,-1,1,1,-1,-1,1,1};
+  const double mu[8] = {-1,-1,-1,-1,1,1,1,1};
+  double vfields[MB_MAX_SUB_ENTITIES*MB_MAX_SUB_ENTITY_VERTICES];
+
+    // get the tag values at the vertices
+  const EntityHandle *connect;
+  int num_connect;
+  ErrorCode result = mbImpl->get_connectivity(elem, connect, num_connect);
+  if (MB_SUCCESS != result) return result;
+  result = mbImpl->tag_get_data(tag, connect, num_connect, vfields);
+  if (MB_SUCCESS != result) return result;
+  
+    //function for the interpolation
+  field = 0;
+
+    //calculate the field
+
+    // just hexes for now
+  assert(num_connect <= 8);
+  
+  for(int i = 0; i < num_connect; i++)
+  {
+    field += 0.125 * vfields[i] *
+      (1+xi[i]*nat_coord[0]) * (1+etha[i]*nat_coord[1]) * (1+mu[i]*nat_coord[2]);
+  }
+
+  return MB_SUCCESS;
+}
+
+
+//Simplest "interpolation" for element-based source fields. Set the value of the field
+//at the target point to that of the field in the source element it lies in.
+ErrorCode Coupler::plain_field_map(EntityHandle elem,
+				       Tag tag,
+				       double &field)
+{
+  double tempField;
+
+  // get the tag values at the vertices
+  ErrorCode result = mbImpl->tag_get_data(tag, &elem, 1, &tempField);
+  if (MB_SUCCESS != result) return result;
+
+  field = tempField;
+
+  return MB_SUCCESS;
+}
+
+} // namespace moab


Property changes on: MOAB/trunk/tools/mbcoupler/Coupler.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MOAB/trunk/tools/mbcoupler/Coupler.hpp (from rev 3583, MOAB/trunk/tools/mbcoupler/MBCoupler.hpp)
===================================================================
--- MOAB/trunk/tools/mbcoupler/Coupler.hpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/Coupler.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,221 @@
+/** 
+ * \class Coupler
+ * \author Tim Tautges
+ *
+ * \brief This class couples data between meshes.
+ *
+ * The coupler interpolates solution data at a set of points.  Data
+ * being interpolated resides on a source mesh, in a tag.
+ * Applications calling this coupler send in entities, usually points
+ * or vertices, and receive back the tag value interpolated at those
+ * points.  Entities in the source mesh containing those points 
+ * do not have to reside on the same processor.
+ *
+ * To use, an application should:
+ * - instantiate this coupler by calling the constructor collectively
+ *   on all processors in the communicator
+ * - call locate_points, which locates the points to be interpolated and
+ *   (optionally) caches the results in this object
+ * - call interpolate, which does the interpolation
+ *
+ * Multiple interpolations can be done after locating the points.
+ *
+ */
+#ifndef COUPLER_HPP
+#define COUPLER_HPP
+
+#include "moab/Range.hpp"
+#include "moab/Interface.hpp"
+#include "moab/CartVect.hpp"
+
+extern "C" 
+{
+  struct tuple_list;
+}
+
+namespace moab {
+
+class ParallelComm;
+
+class AdaptiveKDTree;
+
+class Coupler
+{
+public:
+
+  enum Method {LINEAR_FE, PLAIN_FE};
+
+    /* constructor
+     * Constructor, which also optionally initializes the coupler
+     * \param pc ParallelComm object to be used with this coupler
+     * \param local_elems Local elements in the source mesh
+     * \param coupler_id Id of this coupler, should be the same over all procs
+     * \param init_tree If true, initializes kdtree inside the constructor
+     */
+  Coupler(Interface *impl,
+            ParallelComm *pc,
+            Range &local_elems,
+            int coupler_id,
+            bool init_tree = true);
+
+    /* destructor
+     */
+  virtual ~Coupler();
+  
+    /* \brief Locate points on the source mesh
+     * This function finds the element/processor/natural coordinates 
+     * containing each point, optionally storing the results locally.
+     * \param xyz Point locations (interleaved) being located
+     * \param tl Tuple list containing the results, with each tuple
+     *           consisting of (p, i), p = proc, i = index on that proc
+     * \param store_local If true, stores the tuple list on the Coupler instance
+     *
+     */
+  ErrorCode locate_points(double *xyz, int num_points,
+                            tuple_list *tl = NULL,
+                            bool store_local = true);
+  
+    /* \brief Locate entities on the source mesh
+     * This function finds the element/processor/natural coordinates 
+     * containing each entity, optionally storing the results locally.
+     * \param ents Entities being located
+     * \param tl Tuple list containing the results, with each tuple
+     *           consisting of (p, i), p = proc, i = index on that proc
+     * \param store_local If true, stores the tuple list on the Coupler instance
+     *
+     */
+  ErrorCode locate_points(Range &ents,
+                            tuple_list *tl = NULL,
+                            bool store_local = true);
+  
+    /* \brief Interpolate data from the source mesh onto points
+     * All entities/points or, if tuple_list is input, only those points
+     * are interpolated from the source mesh.  Application should
+     * allocate enough memory in interp_vals to hold interpolation results.
+     * 
+     * If normalization is requested, technique used depends on the coupling
+     * method.
+     *
+     * \param method Interpolation/normalization method
+     * \param tag Tag on source mesh holding data to be interpolated
+     * \param interp_vals Memory holding interpolated data
+     * \param tl Tuple list of points to be interpolated; if NULL, all locations
+     *       stored in this object are interpolated
+     * \param normalize If true, normalization is done according to method
+     */
+  ErrorCode interpolate(Coupler::Method method,
+                          Tag tag,
+                          double *interp_vals,
+                          tuple_list *tl = NULL,
+                          bool normalize = true);
+
+    /* \brief Interpolate data from the source mesh onto points
+     * All entities/points or, if tuple_list is input, only those points
+     * are interpolated from the source mesh.  Application should
+     * allocate enough memory in interp_vals to hold interpolation results.
+     * 
+     * If normalization is requested, technique used depends on the coupling
+     * method.
+     *
+     * \param method Interpolation/normalization method
+     * \param tag_name Name of tag on source mesh holding data to be interpolated
+     * \param interp_vals Memory holding interpolated data
+     * \param tl Tuple list of points to be interpolated; if NULL, all locations
+     *       stored in this object are interpolated
+     * \param normalize If true, normalization is done according to method
+     */
+  ErrorCode interpolate(Coupler::Method method,
+                          std::string &tag_name,
+                          double *interp_vals,
+                          tuple_list *tl = NULL,
+                          bool normalize = true);
+
+private:
+
+    // given a coordinate position, find all entities containing
+    // the point and the natural coords in those ents
+  ErrorCode nat_param(double xyz[3], 
+                        std::vector<EntityHandle> &entities, 
+                        std::vector<CartVect> &nat_coords);
+  
+  ErrorCode interp_field_for_hex(EntityHandle elem,
+                                   CartVect nat_coord, 
+                                   Tag tag,
+                                   double &field);
+
+  ErrorCode plain_field_map(EntityHandle elem,
+			      Tag tag,
+			      double &field);
+  
+  ErrorCode test_local_box(double *xyz, 
+                             int from_proc, int remote_index, int index, 
+                             bool &point_located,
+                             tuple_list *tl = NULL);
+  
+    /* \brief MOAB instance
+     */
+  Interface *mbImpl;
+  
+    /* \brief Initialize the kdtree, locally and across communicator
+     */
+  ErrorCode initialize_tree();
+
+    /* \brief Kdtree for local mesh
+     */
+  AdaptiveKDTree *myTree;
+  
+    /* \brief Local root of the kdtree
+     */
+  EntityHandle localRoot;
+
+    /* \brief Min/max bounding boxes for all proc tree roots
+     */
+  std::vector<double> allBoxes;
+  
+    /* \brief ParallelComm object for this coupler
+     */
+  ParallelComm *myPc;
+  
+    /* \brief Id of this coupler
+     */
+  int myId;
+  
+    /* \brief Range of locations interpolated onto
+     */
+  Range myRange;
+
+    /* \brief List of locally mapped tuples
+     * Tuples contain the following:
+     * n = # mapped points
+     * vul[i] = local handle of mapped entity
+     * vr[3*i..3*i+2] = natural coordinates in mapped entity
+     */
+  tuple_list *mappedPts;
+  
+    /* \brief Tuple list of target points and interpolated data
+     * Tuples contain the following:
+     * n = # target points
+     * vi[3*i] = remote proc mapping target point
+     * vi[3*i+1] = local index of target point
+     * vi[3*i+2] = remote index of target point
+     * vr[i] = interpolated data (used by interpolate function)
+     */
+  tuple_list *targetPts;
+
+    /* \brief Locally mapped points
+     * Points whose source and target are both local; these
+     * points consist of two indices, <target_index, mapped_index>,
+     * where target_index is the index in the target points array
+     * and mapped_index is the corresponding index into mappedPts
+     */
+  std::vector<unsigned int> localMappedPts;
+
+    /* \brief Number of iterations of tree building before failing
+     *
+     */
+  int numIts;
+};
+
+} // namespace moab
+
+#endif


Property changes on: MOAB/trunk/tools/mbcoupler/Coupler.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MOAB/trunk/tools/mbcoupler/ElemUtil.cpp (from rev 3583, MOAB/trunk/tools/mbcoupler/MBElemUtil.cpp)
===================================================================
--- MOAB/trunk/tools/mbcoupler/ElemUtil.cpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/ElemUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,299 @@
+#include <iostream>
+#include <limits>
+#include <assert.h>
+
+#include "ElemUtil.hpp"
+#include "Matrix3.hpp"
+#include "types.h"
+
+namespace moab { 
+namespace ElemUtil {
+
+/**\brief Class representing a 3-D mapping function (e.g. shape function for volume element) */
+class VolMap {
+  public:
+      /**\brief Return $\vec \xi$ corresponding to logical center of element */
+    virtual CartVect center_xi() const = 0;
+      /**\brief Evaluate mapping function (calculate $\vec x = F($\vec \xi)$ )*/
+    virtual CartVect evaluate( const CartVect& xi ) const = 0;
+      /**\brief Evaluate Jacobian of mapping function */
+    virtual Matrix3 jacobian( const CartVect& xi ) const = 0;
+      /**\brief Evaluate inverse of mapping function (calculate $\vec \xi = F^-1($\vec x)$ )*/
+    bool solve_inverse( const CartVect& x, CartVect& xi, double tol ) const ;
+};
+
+bool VolMap::solve_inverse( const CartVect& x, CartVect& xi, double tol ) const
+{
+  const double error_tol_sqr = tol*tol;
+  double det;
+  xi = center_xi();
+  CartVect delta = evaluate(xi) - x;
+  Matrix3 J;
+  while (delta % delta > error_tol_sqr) {
+    J = jacobian(xi);
+    det = J.determinant();
+    if (det < std::numeric_limits<double>::epsilon())
+      return false;
+    xi -= J.inverse(1.0/det) * delta;
+    delta = evaluate( xi ) - x;
+  }
+  return true;
+}
+
+/**\brief Shape function for trilinear hexahedron */
+class LinearHexMap : public VolMap {
+  public:
+    LinearHexMap( const CartVect* corner_coords ) : corners(corner_coords) {}
+    virtual CartVect center_xi() const;
+    virtual CartVect evaluate( const CartVect& xi ) const;
+    virtual Matrix3 jacobian( const CartVect& xi ) const;
+  private:
+    const CartVect* corners;
+    static const double corner_xi[8][3];
+};
+
+const double LinearHexMap::corner_xi[8][3] = { { -1, -1, -1 },
+                                               {  1, -1, -1 },
+                                               {  1,  1, -1 },
+                                               { -1,  1, -1 },
+                                               { -1, -1,  1 },
+                                               {  1, -1,  1 },
+                                               {  1,  1,  1 },
+                                               { -1,  1,  1 } };
+CartVect LinearHexMap::center_xi() const
+  { return CartVect(0.0); }
+
+CartVect LinearHexMap::evaluate( const CartVect& xi ) const
+{
+  CartVect x(0.0);
+  for (unsigned i = 0; i < 8; ++i) {
+    const double N_i = (1 + xi[0]*corner_xi[i][0])
+                     * (1 + xi[1]*corner_xi[i][1])
+                     * (1 + xi[2]*corner_xi[i][2]);
+    x += N_i * corners[i];
+  }
+  x *= 0.125;
+  return x;
+}
+
+Matrix3 LinearHexMap::jacobian( const CartVect& xi ) const
+{
+  Matrix3 J(0.0);
+  for (unsigned i = 0; i < 8; ++i) {
+    const double   xi_p = 1 + xi[0]*corner_xi[i][0];
+    const double  eta_p = 1 + xi[1]*corner_xi[i][1];
+    const double zeta_p = 1 + xi[2]*corner_xi[i][2];
+    const double dNi_dxi   = corner_xi[i][0] * eta_p * zeta_p;
+    const double dNi_deta  = corner_xi[i][1] *  xi_p * zeta_p;
+    const double dNi_dzeta = corner_xi[i][2] *  xi_p *  eta_p;
+    J(0,0) += dNi_dxi   * corners[i][0];
+    J(1,0) += dNi_dxi   * corners[i][1];
+    J(2,0) += dNi_dxi   * corners[i][2];
+    J(0,1) += dNi_deta  * corners[i][0];
+    J(1,1) += dNi_deta  * corners[i][1];
+    J(2,1) += dNi_deta  * corners[i][2];
+    J(0,2) += dNi_dzeta * corners[i][0];
+    J(1,2) += dNi_dzeta * corners[i][1];
+    J(2,2) += dNi_dzeta * corners[i][2];
+  }
+  return J *= 0.125;
+}
+
+bool nat_coords_trilinear_hex( const CartVect* corner_coords,
+                               const CartVect& x,
+                               CartVect& xi,
+                               double tol )
+{
+  return LinearHexMap( corner_coords ).solve_inverse( x, xi, tol );
+}
+
+
+//
+// nat_coords_trilinear_hex2
+//  Duplicate functionality of nat_coords_trilinear_hex using hex_findpt
+// 
+void nat_coords_trilinear_hex2(const CartVect hex[8], 
+                               const CartVect& xyz,
+                               CartVect &ncoords,
+                               double etol)       
+
+{
+  const int ndim = 3;
+  const int nverts = 8;
+  const int vertMap[nverts] = {0,1,3,2, 4,5,7,6}; //Map from nat to lex ordering
+
+  const int n = 2; //linear
+  real coords[ndim*nverts]; //buffer
+
+  real *xm[ndim];
+  for(int i=0; i<ndim; i++)
+    xm[i] = coords + i*nverts;
+    
+  //stuff hex into coords
+  for(int i=0; i<nverts; i++){
+    real vcoord[ndim];
+    hex[i].get(vcoord);
+   
+    for(int d=0; d<ndim; d++)
+      coords[d*nverts + vertMap[i]] = vcoord[d];
+    
+  }
+
+  double dist = 0.0;
+  ElemUtil::hex_findpt(xm, n, xyz, ncoords, dist);
+  if (3*EPS < dist) {
+      // outside element, set extremal values to something outside range
+    for (int j = 0; j < 3; j++) {
+      if (ncoords[j] < (-1.0-etol) || ncoords[j] > (1.0+etol))
+        ncoords[j] *= 10;
+    }
+  }
+  
+}
+
+bool point_in_trilinear_hex(const CartVect *hex, 
+                            const CartVect& xyz,
+                            double etol) 
+{
+  CartVect xi;
+  return nat_coords_trilinear_hex( hex, xyz, xi, etol )
+      && fabs(xi[0])-1 < etol 
+      && fabs(xi[1])-1 < etol 
+      && fabs(xi[2])-1 < etol;
+}
+
+
+bool point_in_trilinear_hex(const CartVect *hex, 
+                            const CartVect& xyz, 
+                            const CartVect& box_min, 
+                            const CartVect& box_max,
+                            double etol) 
+{
+    // all values scaled by 2 (eliminates 3 flops)
+  const CartVect mid = box_max + box_min;
+  const CartVect dim = box_max - box_min;
+  const CartVect pt = 2*xyz - mid;
+  return fabs(pt[0]) - dim[0] < etol &&
+         fabs(pt[1]) - dim[1] < etol &&
+         fabs(pt[2]) - dim[2] < etol &&
+         point_in_trilinear_hex( hex, xyz, etol );
+}
+
+
+
+// Wrapper to James Lottes' findpt routines
+// hex_findpt
+// Find the parametric coordinates of an xyz point inside
+// a 3d hex spectral element with n nodes per dimension
+// xm: coordinates fields, value of x,y,z for each of then n*n*n gauss-lobatto nodes. Nodes are in lexicographical order (x is fastest-changing)
+// n: number of nodes per dimension -- n=2 for a linear element
+// xyz: input, point to find
+// rst: output: parametric coords of xyz inside the element. If xyz is outside the element, rst will be the coords of the closest point
+// dist: output: distance between xyz and the point with parametric coords rst
+extern "C"{
+#include "types.h"
+#include "poly.h"
+#include "tensor.h"
+#include "findpt.h"
+#include "extrafindpt.h"
+#include "errmem.h"
+}
+
+void hex_findpt(real *xm[3],
+                int n,
+                CartVect xyz,
+                CartVect &rst,
+                double &dist)       
+{
+
+  //compute stuff that only depends on the order -- could be cached
+  real *z[3];
+  lagrange_data ld[3];
+  opt_data_3 data;
+
+  //triplicates
+  for(int d=0; d<3; d++){
+    z[d] = tmalloc(real, n);
+    lobatto_nodes(z[d], n); 
+    lagrange_setup(&ld[d], z[d], n);
+  }
+
+  opt_alloc_3(&data, ld);
+
+  //find nearest point
+  real x_star[3];
+  xyz.get(x_star);
+
+  real r[3] = {0, 0, 0 }; // initial guess for parametric coords
+  unsigned c = opt_no_constraints_3;
+  dist = opt_findpt_3(&data, (const real **)xm, x_star, r, &c);
+  //c tells us if we landed inside the element or exactly on a face, edge, or node
+
+  //copy parametric coords back
+  rst = r;
+
+  //Clean-up (move to destructor if we decide to cache)
+  opt_free_3(&data);  
+  for(int d=0; d<3; ++d) 
+    lagrange_free(&ld[d]);
+  for(int d=0; d<3; ++d) 
+    free(z[d]);
+}
+
+
+
+
+// hex_eval
+// Evaluate a field in a 3d hex spectral element with n nodes per dimension, at some given parametric coordinates
+// field: field values for each of then n*n*n gauss-lobatto nodes. Nodes are in lexicographical order (x is fastest-changing)
+// n: number of nodes per dimension -- n=2 for a linear element
+// rst: input: parametric coords of the point where we want to evaluate the field
+// value: output: value of field at rst
+
+void hex_eval(real *field,
+	      int n,
+	      CartVect rstCartVec,
+	      double &value)       
+{
+  int d;
+  real rst[3];
+  rstCartVec.get(rst);
+
+  //can cache stuff below
+  lagrange_data ld[3]; 
+  real *z[3];
+  for(d=0;d<3;++d){
+    z[d] = tmalloc(real, n);
+    lobatto_nodes(z[d], n);
+    lagrange_setup(&ld[d], z[d], n);
+  } 
+
+  //cut and paste -- see findpt.c
+  const unsigned 
+    nf = n*n,
+    ne = n,
+    nw = 2*n*n + 3*n;
+  real *od_work = tmalloc(real, 6*nf + 9*ne + nw);
+
+  //piece that we shouldn't want to cache
+  for(d=0; d<3; d++){
+    lagrange_0(&ld[d], rst[d]);
+  }
+  
+  value = tensor_i3(ld[0].J,ld[0].n,
+		    ld[1].J,ld[1].n,
+		    ld[2].J,ld[2].n,
+		    field,
+		    od_work);
+
+  //all this could be cached
+  for(d=0; d<3; d++){
+    free(z[d]);
+    lagrange_free(&ld[d]); 
+  }
+  free(od_work);
+}
+
+} // namespace ElemUtil
+
+} // namespace moab


Property changes on: MOAB/trunk/tools/mbcoupler/ElemUtil.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MOAB/trunk/tools/mbcoupler/ElemUtil.hpp (from rev 3583, MOAB/trunk/tools/mbcoupler/MBElemUtil.hpp)
===================================================================
--- MOAB/trunk/tools/mbcoupler/ElemUtil.hpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/ElemUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,46 @@
+#ifndef MOAB_ELEM_UTIL_HPP
+#define MOAB_ELEM_UTIL_HPP
+
+#include "moab/Core.hpp"
+#include "moab/CartVect.hpp"
+
+namespace moab {
+namespace ElemUtil {
+
+  bool nat_coords_trilinear_hex(const CartVect* hex_corners, 
+                                const CartVect& x, 
+                                CartVect& xi,
+                                double tol);
+  bool point_in_trilinear_hex(const CartVect *hex_corners, 
+                              const CartVect& xyz,
+                              double etol);
+  
+  bool point_in_trilinear_hex(const CartVect *hex_corners, 
+                              const CartVect& xyz, 
+                              const CartVect& box_min, 
+                              const CartVect& box_max,
+                              double etol);
+
+    //wrapper to hex_findpt
+  void nat_coords_trilinear_hex2(const CartVect* hex_corners, 
+                                 const CartVect& x, 
+                                 CartVect& xi,
+                                 double til);
+
+
+
+  void hex_findpt(double *xm[3],
+                  int n,
+                  CartVect xyz, 
+                  CartVect& rst,
+                  double& dist);
+
+  void hex_eval(double *field,
+		int n,
+		CartVect rst,
+		double &value);
+} // namespace ElemUtil
+ 
+} // namespace moab
+
+#endif MOAB_ELEM_UTIL_HPP


Property changes on: MOAB/trunk/tools/mbcoupler/ElemUtil.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Modified: MOAB/trunk/tools/mbcoupler/ElemUtilTest.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/ElemUtilTest.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/ElemUtilTest.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,7 +1,9 @@
 #include "TestUtil.hpp"
-#include "MBElemUtil.hpp"
+#include "ElemUtil.hpp"
 #include <iostream>
 
+using namespace moab;
+
 void test_hex_nat_coords();
 
 int main()
@@ -11,29 +13,29 @@
   return rval;
 }
 
-const MBCartVect cube_corners[8] = { MBCartVect( 0, 0, 0 ),
-                                     MBCartVect( 1, 0, 0 ),
-                                     MBCartVect( 1, 1, 0 ),
-                                     MBCartVect( 0, 1, 0 ),
-                                     MBCartVect( 0, 0, 1 ),
-                                     MBCartVect( 1, 0, 1 ),
-                                     MBCartVect( 1, 1, 1 ),
-                                     MBCartVect( 0, 1, 1 ) };
+const CartVect cube_corners[8] = { CartVect( 0, 0, 0 ),
+                                     CartVect( 1, 0, 0 ),
+                                     CartVect( 1, 1, 0 ),
+                                     CartVect( 0, 1, 0 ),
+                                     CartVect( 0, 0, 1 ),
+                                     CartVect( 1, 0, 1 ),
+                                     CartVect( 1, 1, 1 ),
+                                     CartVect( 0, 1, 1 ) };
                                     
 
-const MBCartVect hex_corners[8] = { MBCartVect( 1.0, 0.0, 0.0 ),
-                                    MBCartVect( 1.0, 1.0, 0.3 ),
-                                    MBCartVect( 0.0, 2.0, 0.6 ),
-                                    MBCartVect( 0.2, 1.1, 0.4 ),
-                                    MBCartVect( 1.5, 0.3, 1.0 ),
-                                    MBCartVect( 1.5, 1.3, 1.0 ),
-                                    MBCartVect( 0.5, 2.3, 1.0 ),
-                                    MBCartVect( 0.7, 1.4, 1.0 ) };
+const CartVect hex_corners[8] = { CartVect( 1.0, 0.0, 0.0 ),
+                                    CartVect( 1.0, 1.0, 0.3 ),
+                                    CartVect( 0.0, 2.0, 0.6 ),
+                                    CartVect( 0.2, 1.1, 0.4 ),
+                                    CartVect( 1.5, 0.3, 1.0 ),
+                                    CartVect( 1.5, 1.3, 1.0 ),
+                                    CartVect( 0.5, 2.3, 1.0 ),
+                                    CartVect( 0.7, 1.4, 1.0 ) };
 
 /** shape function for trilinear hex */
-MBCartVect hex_map( const MBCartVect& xi, const MBCartVect* corners )
+CartVect hex_map( const CartVect& xi, const CartVect* corners )
 {
-  MBCartVect x(0.0);
+  CartVect x(0.0);
   x += (1 - xi[0]) * (1 - xi[1]) * (1 - xi[2]) * corners[0];
   x += (1 + xi[0]) * (1 - xi[1]) * (1 - xi[2]) * corners[1];
   x += (1 + xi[0]) * (1 + xi[1]) * (1 - xi[2]) * corners[2];
@@ -45,7 +47,7 @@
   return x *= 0.125;
 }
 
-static void hex_bounding_box( const MBCartVect* corners, MBCartVect& min, MBCartVect& max  )
+static void hex_bounding_box( const CartVect* corners, CartVect& min, CartVect& max  )
 {
   min = max = corners[0];
   for (unsigned i = 1; i < 8; ++i)
@@ -56,7 +58,7 @@
         max[d] = corners[i][d];
 }
 
-static bool in_range( const MBCartVect& xi )
+static bool in_range( const CartVect& xi )
   { return fabs(xi[0]) <= 1 
         && fabs(xi[1]) <= 1 
         && fabs(xi[2]) <= 1; 
@@ -64,7 +66,7 @@
 
 void test_hex_nat_coords()
 {
-  MBCartVect xi, result_xi;
+  CartVect xi, result_xi;
   bool valid;
   const double EPS = 1e-6;
   
@@ -72,8 +74,8 @@
   for (xi[0] = -1; xi[0] <= 1; xi[0] += 0.2) {
     for (xi[1] = -1; xi[1] <= 1; xi[1] += 0.2) {
       for (xi[2] = -1; xi[2] <= 1; xi[2] += 0.2) {
-        const MBCartVect pt = hex_map(xi, cube_corners);
-        valid = MBElemUtil::nat_coords_trilinear_hex( cube_corners, pt, result_xi, EPS/10 );
+        const CartVect pt = hex_map(xi, cube_corners);
+        valid = ElemUtil::nat_coords_trilinear_hex( cube_corners, pt, result_xi, EPS/10 );
         CHECK(valid);
         CHECK_REAL_EQUAL( xi[0], result_xi[0], EPS );
         CHECK_REAL_EQUAL( xi[1], result_xi[1], EPS );
@@ -86,8 +88,8 @@
   for (xi[0] = -1; xi[0] <= 1; xi[0] += 0.2) {
     for (xi[1] = -1; xi[1] <= 1; xi[1] += 0.2) {
       for (xi[2] = -1; xi[2] <= 1; xi[2] += 0.2) {
-        const MBCartVect pt = hex_map(xi, hex_corners);
-        valid = MBElemUtil::nat_coords_trilinear_hex( hex_corners, pt, result_xi, EPS/10 );
+        const CartVect pt = hex_map(xi, hex_corners);
+        valid = ElemUtil::nat_coords_trilinear_hex( hex_corners, pt, result_xi, EPS/10 );
         CHECK(valid);
         CHECK_REAL_EQUAL( xi[0], result_xi[0], EPS );
         CHECK_REAL_EQUAL( xi[1], result_xi[1], EPS );
@@ -97,7 +99,7 @@
   }
   
     // test points outside of element
-  MBCartVect x, min, max;
+  CartVect x, min, max;
   hex_bounding_box( cube_corners, min, max );
   for (x[0] = -1; x[0] <= 2; x[0] += 0.4) {
     for (x[1] = -1; x[1] <= 2; x[1] += 0.4) {
@@ -107,7 +109,7 @@
                    && x[2] >= min[2] && x[2] <= max[2];
         if (in_box)
           continue;
-        valid = MBElemUtil::nat_coords_trilinear_hex( cube_corners, x, result_xi, EPS/10 );
+        valid = ElemUtil::nat_coords_trilinear_hex( cube_corners, x, result_xi, EPS/10 );
 //std::cout << (valid ? 'y' : 'n');
         CHECK(!valid || !in_range(result_xi));
       }
@@ -124,7 +126,7 @@
                    && x[2] >= min[2] && x[2] <= max[2];
         if (in_box)
           continue;
-        valid = MBElemUtil::nat_coords_trilinear_hex( hex_corners, x, result_xi, EPS/10 );
+        valid = ElemUtil::nat_coords_trilinear_hex( hex_corners, x, result_xi, EPS/10 );
 //std::cout << (valid ? 'y' : 'n');
         CHECK(!valid || !in_range(result_xi));
       }

Deleted: MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,508 +0,0 @@
-#include "MBCoupler.hpp"
-#include "MBParallelComm.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBElemUtil.hpp"
-#include "MBCN.hpp"
-#include "iostream"
-
-extern "C" 
-{
-#include "types.h"
-#include "errmem.h"
-#include "minmax.h"
-#include "sort.h"
-#include "tuple_list.h"
-#include "crystal.h"
-#include "transfer.h"
-}
-
-#include "assert.h"
-
-MBCoupler::MBCoupler(MBInterface *impl,
-                     MBParallelComm *pc,
-                     MBRange &local_elems,
-                     int coupler_id,
-                     bool init_tree)
-    : mbImpl(impl), myPc(pc), myId(coupler_id), numIts(3)
-{
-  assert(NULL != impl && NULL != myPc);
-
-    // keep track of the local points, at least for now
-  myRange = local_elems;
-
-    // now initialize the tree
-  if (init_tree) initialize_tree();
-
-
-
-
-    // initialize tuple lists to indicate not initialized
-  mappedPts = NULL;
-  targetPts = NULL;
-}
-
-  /* destructor
-   */
-MBCoupler::~MBCoupler()
-{}
-
-
-MBErrorCode MBCoupler::initialize_tree()
-{
-  
-  MBRange local_ents;
-  MBAdaptiveKDTree::Settings settings;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
-  allBoxes.resize(6*myPc->proc_config().proc_size());
-
-    //get entities on the local part
-  MBErrorCode result = myPc->get_part_entities(local_ents, 3);
-  if (MB_SUCCESS != result) {
-    std::cout << "Problems getting entities by dimension" << std::endl;
-    return result;
-  }
-
-    // build the tree for local processor
-  for (int i = 0; i < numIts; i++) {
-    myTree = new MBAdaptiveKDTree(mbImpl);
-    result = myTree->build_tree(local_ents, localRoot, &settings);
-    if (MB_SUCCESS != result) {
-      std::cout << "Problems building tree";
-      if (numIts != i) {
-        delete myTree;
-        settings.maxEntPerLeaf *= 2;
-        std::cout << "; increasing elements/leaf to " 
-                  << settings.maxEntPerLeaf << std::endl;;
-      }
-      else {
-        std::cout << "; exiting" << std::endl;
-        return result;
-      }
-    }
-  }
-
-    // get the bounding box for local tree
-  allBoxes.resize(6*myPc->proc_config().proc_size());
-  unsigned int my_rank = myPc->proc_config().proc_rank();
-  result = myTree->get_tree_box(localRoot, &allBoxes[6*my_rank], &allBoxes[6*my_rank+3]);
-
-    // now communicate to get all boxes
-  int mpi_err = MPI_Allgather(&allBoxes[6*my_rank], 6, MPI_DOUBLE,
-                              &allBoxes[0], 6, MPI_DOUBLE, 
-                              myPc->proc_config().proc_comm());
-
-#ifndef NDEBUG
-  double min[3] = {0,0,0}, max[3] = {0,0,0};
-  unsigned int dep;
-  myTree->get_info(localRoot, min, max, dep);
-  std::cout << "Proc " << my_rank << ": box min/max, tree depth = ("
-            << min[0] << "," << min[1] << "," << min[2] << "), ("
-            << max[0] << "," << max[1] << "," << max[2] << "), "
-            << dep << std::endl;
-#endif  
-
-  if (MPI_SUCCESS == mpi_err) return MB_SUCCESS;
-  else return MB_FAILURE;
-}
-
-MBErrorCode MBCoupler::locate_points(double *xyz, int num_points,
-                                     tuple_list *tl,
-                                     bool store_local)
-{
-  assert(tl || store_local);
-
-    // allocate tuple_list to hold point data: (p, i, , xyz), i = point index
-  tuple_list target_pts;
-  tuple_list_init_max(&target_pts, 2, 0, 0, 3, num_points);
-
-    // initialize source_pts and local_pts
-  tuple_list source_pts;
-  mappedPts = new tuple_list;
-  tuple_list_init_max(&source_pts, 3, 0, 0, 0, target_pts.max); 
-  tuple_list_init_max(mappedPts, 0, 0, 1, 3, target_pts.max); 
-
-  mappedPts->n = 0;
-  source_pts.n = 0;
-  MBErrorCode result;
-
-    // keep track of which points have been located
-  std::vector<unsigned char> located_pts(num_points, 0);
-
-    // for each point, find box(es) containing the point,
-    // appending results to tuple_list;
-    // keep local points separately, in local_pts, which has pairs
-    // of <local_index, mapped_index>, where mapped_index is the index
-    // of <local_index, mapped_index>, where mapped_index is the index
-    // into the mappedPts tuple list
-
-  unsigned int my_rank = myPc->proc_config().proc_rank();
-  bool point_located;
-  
-  for (int i = 0; i < 3*num_points; i+=3) 
-  {
-      // test point locally first
-    result = test_local_box(xyz+i, my_rank, i/3, i/3, point_located);
-    if (MB_SUCCESS != result) return result;
-    if (point_located) {
-      located_pts[i/3] = 0x1;
-      continue;
-    }
-
-      // if not located locally, test other procs' boxes
-    for (unsigned int j = 0; j < myPc->proc_config().proc_size(); j++)
-    {
-      if (j == my_rank) continue;
-      
-        // test if point is in proc's box
-      if (allBoxes[6*j] <= xyz[i] && xyz[i] <= allBoxes[6*j+3] && 
-          allBoxes[6*j+1] <= xyz[i+1] && xyz[i+1] <= allBoxes[6*j+4] && 
-          allBoxes[6*j+2] <= xyz[i+2] && xyz[i+2] <= allBoxes[6*j+5])
-      {
-          // if in this proc's box, will send to proc to test further
-          // check size, grow if we're at max
-        if (target_pts.n == target_pts.max)
-          tuple_list_grow(&target_pts);
-  
-        target_pts.vi[2*target_pts.n] = j;
-        target_pts.vi[2*target_pts.n+1] = i/3;
-        target_pts.vr[3*target_pts.n] = xyz[i];
-        target_pts.vr[3*target_pts.n+1] = xyz[i+1];
-        target_pts.vr[3*target_pts.n+2] = xyz[i+2];
-        target_pts.n++;
-      }
-    }
-  }
-
-    // perform scatter/gather, to gather points to source mesh procs
-  gs_transfer(1, &target_pts, 0, myPc->proc_config().crystal_router());
-
-    // after scatter/gather:
-    // target_pts.n = # points local proc has to map
-    // target_pts.vi[2*i] = proc sending point i
-    // target_pts.vi[2*i+1] = index of point i on sending proc
-    // target_pts.vr[3*i..3*i+2] = xyz of point i
-    //
-    // Mapping builds the tuple list:
-    // source_pts.n = target_pts.n
-    // source_pts.vi[3*i] = target_pts.vi[2*i] = sending proc
-    // source_pts.vi[3*i+1] = index of point i on sending proc
-    // source_pts.vi[3*i+2] = index of mapped point (-1 if not mapped)
-    //
-    // Also, mapping builds local tuple_list mappedPts:
-    // mappedPts->n = # mapped points
-    // mappedPts->vul[i] = local handle of mapped entity
-    // mappedPts->vr[3*i..3*i+2] = natural coordinates in mapped entity
-
-    // test target points against my elements
-  for (unsigned i = 0; i < target_pts.n; i++) 
-  {
-    result = test_local_box(target_pts.vr+3*i, 
-                            target_pts.vi[2*i], target_pts.vi[2*i+1], i, 
-                            point_located, &source_pts);
-    if (MB_SUCCESS != result) return result;
-  }
-
-  // no longer need target_pts
-  tuple_list_free(&target_pts);
-
-    // send target points back to target procs
-  gs_transfer(1, &source_pts, 0, myPc->proc_config().crystal_router());
-
-  // store proc/index tuples in targetPts, and/or pass back to application;
-  // the tuple this gets stored to looks like:
-  // tl.n = # mapped points
-  // tl.vi[3*i] = remote proc mapping point
-  // tl.vi[3*i+1] = local index of mapped point
-  // tl.vi[3*i+2] = remote index of mapped point
-  //
-  // Local index is mapped into either myRange, holding the handles of
-  // local mapped entities, or myXyz, holding locations of mapped pts
-
-  // count non-negatives
-  int num_pts = 0;
-  for (unsigned int i = 0; i < source_pts.n; i++)
-    if (-1 != source_pts.vi[3*i+2]) num_pts++;
-
-    // store information about located points
-  targetPts = new tuple_list;
-  tuple_list *tl_tmp = targetPts;
-  if (!store_local) tl_tmp = tl;
-  tuple_list_init_max(tl_tmp, 3, 0, 0, 1, num_pts);
-  for (unsigned int i = 0; i < source_pts.n; i++) {
-    if (-1 != source_pts.vi[3*i+2] && !located_pts[3*i+1]) {
-      tl_tmp->vi[3*i] = source_pts.vi[3*i];
-      tl_tmp->vi[3*i+1] = source_pts.vi[3*i+1];
-      tl_tmp->vi[3*i+2] = source_pts.vi[3*i+2];
-      tl_tmp->n++;
-    }
-  }
-
-  assert(tl_tmp->n + localMappedPts.size()/2 == (unsigned int) num_points);
-  
-    // no longer need source_pts
-  tuple_list_free(&source_pts);
-
-    // copy into tl if passed in and storing locally
-  if (tl && store_local) {
-    tuple_list_init_max(tl, 3, 0, 0, 1, num_pts);
-    memcpy(tl->vi, tl_tmp->vi, 3*tl_tmp->n*sizeof(int));
-    tl->n = tl_tmp->n;
-  }
-
-    // done
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCoupler::test_local_box(double *xyz, 
-                                      int from_proc, int remote_index, int index, 
-                                      bool &point_located,
-                                      tuple_list *tl)
-{
-  
-  std::vector<MBEntityHandle> entities;
-  std::vector<MBCartVect> nat_coords;
-          
-  MBErrorCode result = nat_param(xyz, entities, nat_coords);
-  if (MB_SUCCESS != result) return result;
-
-    // if we didn't find any ents and we're looking locally, nothing more to do
-  if (entities.empty() && !tl) 
-    return result;
-  
-    // grow if we know we'll exceed size
-  if (mappedPts->n+entities.size() >= mappedPts->max)
-    tuple_list_grow(mappedPts);
-
-  if (entities.empty() && tl) {
-    tl->vi[3*index] = from_proc;
-    tl->vi[3*index+1] = remote_index;
-    tl->vi[3*index+2] = -1;
-    point_located = false;
-    return MB_SUCCESS;
-  }
-  
-  std::vector<MBEntityHandle>::iterator eit = entities.begin();
-  std::vector<MBCartVect>::iterator ncit = nat_coords.begin();
-  for (; eit != entities.end(); eit++, ncit++) {
-      // store in tuple mappedPts
-    mappedPts->vr[3*mappedPts->n] = (*ncit)[0];
-    mappedPts->vr[3*mappedPts->n+1] = (*ncit)[1];
-    mappedPts->vr[3*mappedPts->n+2] = (*ncit)[2];
-    mappedPts->vul[mappedPts->n] = *eit;
-    mappedPts->n++;
-
-      // also store local point, mapped point indices
-    if (tl) 
-    {
-      if (tl->n == tl->max) tuple_list_grow(tl);
-
-        // store in tuple source_pts
-      tl->vi[3*tl->n] = from_proc;
-      tl->vi[3*tl->n+1] = remote_index;
-      tl->vi[3*tl->n+2] = mappedPts->n-1;
-      tl->n++;
-    }
-    else {
-      localMappedPts.push_back(index);
-      localMappedPts.push_back(mappedPts->n-1);
-    }
-  }
-
-  point_located = true;
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCoupler::interpolate(MBCoupler::Method method,
-                                   std::string &interp_tag,
-                                   double *interp_vals,
-                                   tuple_list *tl,
-                                   bool normalize)
-{
-  MBTag tag;
-  MBErrorCode result = mbImpl->tag_get_handle(interp_tag.c_str(), tag);
-  if (MB_SUCCESS != result) return result;
-  return interpolate(method, tag, interp_vals, tl, normalize);
-}
-  
-MBErrorCode MBCoupler::interpolate(MBCoupler::Method method,
-                                   MBTag tag,
-                                   double *interp_vals,
-                                   tuple_list *tl,
-                                   bool normalize)
-{
-  if (!((LINEAR_FE == method) || (PLAIN_FE == method)))
-    return MB_FAILURE;
-
-  tuple_list *tl_tmp = (tl ? tl : targetPts);
-
-    // remote pts first
-  
-    // scatter/gather interpolation points
-  gs_transfer(1, tl_tmp, 0, myPc->proc_config().crystal_router());
-
-    // perform interpolation on local source mesh; put results into
-    // tl_tmp->vr[i]
-  MBErrorCode result;
-
-  for (unsigned int i = 0; i < tl_tmp->n; i++) {
-    int mindex = tl_tmp->vi[3*i+2];
-
-    result = MB_FAILURE;
-    if(LINEAR_FE == method){
-      result = interp_field_for_hex(mappedPts->vul[mindex],
-				    MBCartVect(mappedPts->vr+3*mindex), 
-				    tag, tl_tmp->vr[i]);
-    }else if (PLAIN_FE == method){
-      result = plain_field_map(mappedPts->vul[mindex],
-			       tag, tl_tmp->vr[i]);
-    }
-
-    if (MB_SUCCESS != result) return result;
-  }
-  
-    // scatter/gather interpolation data
-  gs_transfer(1, tl_tmp, 0, myPc->proc_config().crystal_router());
-
-  if (!tl) {
-      // mapped whole targetPts tuple; put into proper place in interp_vals
-    for (unsigned int i = 0; i < tl_tmp->n; i++)
-      interp_vals[tl_tmp->vi[3*i+1]] = tl_tmp->vr[i];
-
-      // now do locally-contained pts, since we're mapping everything
-    for (std::vector<unsigned int>::iterator vit = localMappedPts.begin();
-         vit != localMappedPts.end(); vit += 2) {
-      int mindex = *(vit+1);
-
-      result = MB_FAILURE;
-      if(LINEAR_FE == method){
-	result = interp_field_for_hex(mappedPts->vul[mindex],
-				      MBCartVect(mappedPts->vr+3*mindex), 
-				      tag, interp_vals[*vit]);
-      }else if (PLAIN_FE == method){
-	result = plain_field_map(mappedPts->vul[mindex],
-				 tag, interp_vals[*vit]);
-      }
-
-      if (MB_SUCCESS != result) return result;
-
-    }
-  }
-  
-    // done
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCoupler::nat_param(double xyz[3], 
-                                 std::vector<MBEntityHandle> &entities, 
-                                 std::vector<MBCartVect> &nat_coords)
-{
-  MBAdaptiveKDTreeIter treeiter;
-  MBErrorCode result = myTree->get_tree_iterator(localRoot, treeiter); 
-  if (MB_SUCCESS != result) {
-    std::cout << "Problems getting iterator" << std::endl;
-    return result;
-  }
-
-  result = myTree->leaf_containing_point(localRoot, xyz, treeiter);
-  if (MB_SUCCESS != result) {
-    std::cout << "Problems getting leaf " << std::endl;
-    return result;
-  }
-
-    // find natural coordinates of point in element(s) in that leaf
-  MBCartVect tmp_nat_coords; 
-  MBRange range_leaf;
-  result = mbImpl->get_entities_by_dimension(treeiter.handle(), 3, range_leaf, false);
-  if(result != MB_SUCCESS) std::cout << "Problem getting leaf in a range" << std::endl;
-
-    // loop over the range_leaf 
-  for(MBRange::iterator iter = range_leaf.begin(); iter != range_leaf.end(); iter++)
-  {
-    const MBEntityHandle *connect;
-    int num_connect;
-
-      //get connectivity
-    result = mbImpl->get_connectivity(*iter, connect, num_connect, true);
-
-      //get coordinates of the vertices
-    std::vector<MBCartVect> coords_vert(num_connect);
-    std::vector<double> coords(3*num_connect);
-    result = mbImpl->get_coords(connect, num_connect, &coords[0]);
-	
-    for(int j = 0; j < num_connect; j++)
-    {
-      coords_vert[j][0] = coords[3*j];
-      coords_vert[j][1] = coords[3*j+1];
-      coords_vert[j][2] = coords[3*j+2];
-    }
-
-      //test to find out in which hex the point is
-		
-      // get natural coordinates
-    if (MBElemUtil::nat_coords_trilinear_hex(&coords_vert[0], MBCartVect(xyz), 
-                                             tmp_nat_coords, 1e-10)) {
-      entities.push_back(*iter);
-      nat_coords.push_back(tmp_nat_coords);
-      return MB_SUCCESS;
-    }
-  }
-  
-  return MB_SUCCESS;
-}
-
-MBErrorCode MBCoupler::interp_field_for_hex(MBEntityHandle elem,
-                                            MBCartVect nat_coord, 
-                                            MBTag tag,
-                                            double &field)
-{
-    //set the vertices coordinates in the natural system
-
-  const double xi[8] = {-1,1,1,-1,-1,1,1,-1};
-  const double etha[8] = {-1,-1,1,1,-1,-1,1,1};
-  const double mu[8] = {-1,-1,-1,-1,1,1,1,1};
-  double vfields[MB_MAX_SUB_ENTITIES*MB_MAX_SUB_ENTITY_VERTICES];
-
-    // get the tag values at the vertices
-  const MBEntityHandle *connect;
-  int num_connect;
-  MBErrorCode result = mbImpl->get_connectivity(elem, connect, num_connect);
-  if (MB_SUCCESS != result) return result;
-  result = mbImpl->tag_get_data(tag, connect, num_connect, vfields);
-  if (MB_SUCCESS != result) return result;
-  
-    //function for the interpolation
-  field = 0;
-
-    //calculate the field
-
-    // just hexes for now
-  assert(num_connect <= 8);
-  
-  for(int i = 0; i < num_connect; i++)
-  {
-    field += 0.125 * vfields[i] *
-      (1+xi[i]*nat_coord[0]) * (1+etha[i]*nat_coord[1]) * (1+mu[i]*nat_coord[2]);
-  }
-
-  return MB_SUCCESS;
-}
-
-
-//Simplest "interpolation" for element-based source fields. Set the value of the field
-//at the target point to that of the field in the source element it lies in.
-MBErrorCode MBCoupler::plain_field_map(MBEntityHandle elem,
-				       MBTag tag,
-				       double &field)
-{
-  double tempField;
-
-  // get the tag values at the vertices
-  MBErrorCode result = mbImpl->tag_get_data(tag, &elem, 1, &tempField);
-  if (MB_SUCCESS != result) return result;
-
-  field = tempField;
-
-  return MB_SUCCESS;
-}

Deleted: MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,217 +0,0 @@
-/** 
- * \class MBCoupler
- * \author Tim Tautges
- *
- * \brief This class couples data between meshes.
- *
- * The coupler interpolates solution data at a set of points.  Data
- * being interpolated resides on a source mesh, in a tag.
- * Applications calling this coupler send in entities, usually points
- * or vertices, and receive back the tag value interpolated at those
- * points.  Entities in the source mesh containing those points 
- * do not have to reside on the same processor.
- *
- * To use, an application should:
- * - instantiate this coupler by calling the constructor collectively
- *   on all processors in the communicator
- * - call locate_points, which locates the points to be interpolated and
- *   (optionally) caches the results in this object
- * - call interpolate, which does the interpolation
- *
- * Multiple interpolations can be done after locating the points.
- *
- */
-#ifndef MBCOUPLER_HPP
-#define MBCOUPLER_HPP
-
-class MBParallelComm;
-
-#include "MBRange.hpp"
-#include "MBInterface.hpp"
-#include "MBCartVect.hpp"
-
-extern "C" 
-{
-  struct tuple_list;
-}
-
-class MBAdaptiveKDTree;
-
-class MBCoupler
-{
-public:
-
-  enum Method {LINEAR_FE, PLAIN_FE};
-
-    /* constructor
-     * Constructor, which also optionally initializes the coupler
-     * \param pc MBParallelComm object to be used with this coupler
-     * \param local_elems Local elements in the source mesh
-     * \param coupler_id Id of this coupler, should be the same over all procs
-     * \param init_tree If true, initializes kdtree inside the constructor
-     */
-  MBCoupler(MBInterface *impl,
-            MBParallelComm *pc,
-            MBRange &local_elems,
-            int coupler_id,
-            bool init_tree = true);
-
-    /* destructor
-     */
-  virtual ~MBCoupler();
-  
-    /* \brief Locate points on the source mesh
-     * This function finds the element/processor/natural coordinates 
-     * containing each point, optionally storing the results locally.
-     * \param xyz Point locations (interleaved) being located
-     * \param tl Tuple list containing the results, with each tuple
-     *           consisting of (p, i), p = proc, i = index on that proc
-     * \param store_local If true, stores the tuple list on the MBCoupler instance
-     *
-     */
-  MBErrorCode locate_points(double *xyz, int num_points,
-                            tuple_list *tl = NULL,
-                            bool store_local = true);
-  
-    /* \brief Locate entities on the source mesh
-     * This function finds the element/processor/natural coordinates 
-     * containing each entity, optionally storing the results locally.
-     * \param ents Entities being located
-     * \param tl Tuple list containing the results, with each tuple
-     *           consisting of (p, i), p = proc, i = index on that proc
-     * \param store_local If true, stores the tuple list on the MBCoupler instance
-     *
-     */
-  MBErrorCode locate_points(MBRange &ents,
-                            tuple_list *tl = NULL,
-                            bool store_local = true);
-  
-    /* \brief Interpolate data from the source mesh onto points
-     * All entities/points or, if tuple_list is input, only those points
-     * are interpolated from the source mesh.  Application should
-     * allocate enough memory in interp_vals to hold interpolation results.
-     * 
-     * If normalization is requested, technique used depends on the coupling
-     * method.
-     *
-     * \param method Interpolation/normalization method
-     * \param tag Tag on source mesh holding data to be interpolated
-     * \param interp_vals Memory holding interpolated data
-     * \param tl Tuple list of points to be interpolated; if NULL, all locations
-     *       stored in this object are interpolated
-     * \param normalize If true, normalization is done according to method
-     */
-  MBErrorCode interpolate(MBCoupler::Method method,
-                          MBTag tag,
-                          double *interp_vals,
-                          tuple_list *tl = NULL,
-                          bool normalize = true);
-
-    /* \brief Interpolate data from the source mesh onto points
-     * All entities/points or, if tuple_list is input, only those points
-     * are interpolated from the source mesh.  Application should
-     * allocate enough memory in interp_vals to hold interpolation results.
-     * 
-     * If normalization is requested, technique used depends on the coupling
-     * method.
-     *
-     * \param method Interpolation/normalization method
-     * \param tag_name Name of tag on source mesh holding data to be interpolated
-     * \param interp_vals Memory holding interpolated data
-     * \param tl Tuple list of points to be interpolated; if NULL, all locations
-     *       stored in this object are interpolated
-     * \param normalize If true, normalization is done according to method
-     */
-  MBErrorCode interpolate(MBCoupler::Method method,
-                          std::string &tag_name,
-                          double *interp_vals,
-                          tuple_list *tl = NULL,
-                          bool normalize = true);
-
-private:
-
-    // given a coordinate position, find all entities containing
-    // the point and the natural coords in those ents
-  MBErrorCode nat_param(double xyz[3], 
-                        std::vector<MBEntityHandle> &entities, 
-                        std::vector<MBCartVect> &nat_coords);
-  
-  MBErrorCode interp_field_for_hex(MBEntityHandle elem,
-                                   MBCartVect nat_coord, 
-                                   MBTag tag,
-                                   double &field);
-
-  MBErrorCode plain_field_map(MBEntityHandle elem,
-			      MBTag tag,
-			      double &field);
-  
-  MBErrorCode test_local_box(double *xyz, 
-                             int from_proc, int remote_index, int index, 
-                             bool &point_located,
-                             tuple_list *tl = NULL);
-  
-    /* \brief MOAB instance
-     */
-  MBInterface *mbImpl;
-  
-    /* \brief Initialize the kdtree, locally and across communicator
-     */
-  MBErrorCode initialize_tree();
-
-    /* \brief Kdtree for local mesh
-     */
-  MBAdaptiveKDTree *myTree;
-  
-    /* \brief Local root of the kdtree
-     */
-  MBEntityHandle localRoot;
-
-    /* \brief Min/max bounding boxes for all proc tree roots
-     */
-  std::vector<double> allBoxes;
-  
-    /* \brief MBParallelComm object for this coupler
-     */
-  MBParallelComm *myPc;
-  
-    /* \brief Id of this coupler
-     */
-  int myId;
-  
-    /* \brief Range of locations interpolated onto
-     */
-  MBRange myRange;
-
-    /* \brief List of locally mapped tuples
-     * Tuples contain the following:
-     * n = # mapped points
-     * vul[i] = local handle of mapped entity
-     * vr[3*i..3*i+2] = natural coordinates in mapped entity
-     */
-  tuple_list *mappedPts;
-  
-    /* \brief Tuple list of target points and interpolated data
-     * Tuples contain the following:
-     * n = # target points
-     * vi[3*i] = remote proc mapping target point
-     * vi[3*i+1] = local index of target point
-     * vi[3*i+2] = remote index of target point
-     * vr[i] = interpolated data (used by interpolate function)
-     */
-  tuple_list *targetPts;
-
-    /* \brief Locally mapped points
-     * Points whose source and target are both local; these
-     * points consist of two indices, <target_index, mapped_index>,
-     * where target_index is the index in the target points array
-     * and mapped_index is the corresponding index into mappedPts
-     */
-  std::vector<unsigned int> localMappedPts;
-
-    /* \brief Number of iterations of tree building before failing
-     *
-     */
-  int numIts;
-};
-
-#endif

Deleted: MOAB/trunk/tools/mbcoupler/MBElemUtil.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBElemUtil.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/MBElemUtil.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,297 +0,0 @@
-#include <iostream>
-#include <limits>
-#include <assert.h>
-
-#include "MBElemUtil.hpp"
-#include "MBMatrix3.hpp"
-#include "types.h"
-
-namespace MBElemUtil {
-
-/**\brief Class representing a 3-D mapping function (e.g. shape function for volume element) */
-class VolMap {
-  public:
-      /**\brief Return $\vec \xi$ corresponding to logical center of element */
-    virtual MBCartVect center_xi() const = 0;
-      /**\brief Evaluate mapping function (calculate $\vec x = F($\vec \xi)$ )*/
-    virtual MBCartVect evaluate( const MBCartVect& xi ) const = 0;
-      /**\brief Evaluate Jacobian of mapping function */
-    virtual MBMatrix3 jacobian( const MBCartVect& xi ) const = 0;
-      /**\brief Evaluate inverse of mapping function (calculate $\vec \xi = F^-1($\vec x)$ )*/
-    bool solve_inverse( const MBCartVect& x, MBCartVect& xi, double tol ) const ;
-};
-
-bool VolMap::solve_inverse( const MBCartVect& x, MBCartVect& xi, double tol ) const
-{
-  const double error_tol_sqr = tol*tol;
-  double det;
-  xi = center_xi();
-  MBCartVect delta = evaluate(xi) - x;
-  MBMatrix3 J;
-  while (delta % delta > error_tol_sqr) {
-    J = jacobian(xi);
-    det = J.determinant();
-    if (det < std::numeric_limits<double>::epsilon())
-      return false;
-    xi -= J.inverse(1.0/det) * delta;
-    delta = evaluate( xi ) - x;
-  }
-  return true;
-}
-
-/**\brief Shape function for trilinear hexahedron */
-class LinearHexMap : public VolMap {
-  public:
-    LinearHexMap( const MBCartVect* corner_coords ) : corners(corner_coords) {}
-    virtual MBCartVect center_xi() const;
-    virtual MBCartVect evaluate( const MBCartVect& xi ) const;
-    virtual MBMatrix3 jacobian( const MBCartVect& xi ) const;
-  private:
-    const MBCartVect* corners;
-    static const double corner_xi[8][3];
-};
-
-const double LinearHexMap::corner_xi[8][3] = { { -1, -1, -1 },
-                                               {  1, -1, -1 },
-                                               {  1,  1, -1 },
-                                               { -1,  1, -1 },
-                                               { -1, -1,  1 },
-                                               {  1, -1,  1 },
-                                               {  1,  1,  1 },
-                                               { -1,  1,  1 } };
-MBCartVect LinearHexMap::center_xi() const
-  { return MBCartVect(0.0); }
-
-MBCartVect LinearHexMap::evaluate( const MBCartVect& xi ) const
-{
-  MBCartVect x(0.0);
-  for (unsigned i = 0; i < 8; ++i) {
-    const double N_i = (1 + xi[0]*corner_xi[i][0])
-                     * (1 + xi[1]*corner_xi[i][1])
-                     * (1 + xi[2]*corner_xi[i][2]);
-    x += N_i * corners[i];
-  }
-  x *= 0.125;
-  return x;
-}
-
-MBMatrix3 LinearHexMap::jacobian( const MBCartVect& xi ) const
-{
-  MBMatrix3 J(0.0);
-  for (unsigned i = 0; i < 8; ++i) {
-    const double   xi_p = 1 + xi[0]*corner_xi[i][0];
-    const double  eta_p = 1 + xi[1]*corner_xi[i][1];
-    const double zeta_p = 1 + xi[2]*corner_xi[i][2];
-    const double dNi_dxi   = corner_xi[i][0] * eta_p * zeta_p;
-    const double dNi_deta  = corner_xi[i][1] *  xi_p * zeta_p;
-    const double dNi_dzeta = corner_xi[i][2] *  xi_p *  eta_p;
-    J(0,0) += dNi_dxi   * corners[i][0];
-    J(1,0) += dNi_dxi   * corners[i][1];
-    J(2,0) += dNi_dxi   * corners[i][2];
-    J(0,1) += dNi_deta  * corners[i][0];
-    J(1,1) += dNi_deta  * corners[i][1];
-    J(2,1) += dNi_deta  * corners[i][2];
-    J(0,2) += dNi_dzeta * corners[i][0];
-    J(1,2) += dNi_dzeta * corners[i][1];
-    J(2,2) += dNi_dzeta * corners[i][2];
-  }
-  return J *= 0.125;
-}
-
-bool nat_coords_trilinear_hex( const MBCartVect* corner_coords,
-                               const MBCartVect& x,
-                               MBCartVect& xi,
-                               double tol )
-{
-  return LinearHexMap( corner_coords ).solve_inverse( x, xi, tol );
-}
-
-
-//
-// nat_coords_trilinear_hex2
-//  Duplicate functionality of nat_coords_trilinear_hex using hex_findpt
-// 
-void nat_coords_trilinear_hex2(const MBCartVect hex[8], 
-                               const MBCartVect& xyz,
-                               MBCartVect &ncoords,
-                               double etol)       
-
-{
-  const int ndim = 3;
-  const int nverts = 8;
-  const int vertMap[nverts] = {0,1,3,2, 4,5,7,6}; //Map from nat to lex ordering
-
-  const int n = 2; //linear
-  real coords[ndim*nverts]; //buffer
-
-  real *xm[ndim];
-  for(int i=0; i<ndim; i++)
-    xm[i] = coords + i*nverts;
-    
-  //stuff hex into coords
-  for(int i=0; i<nverts; i++){
-    real vcoord[ndim];
-    hex[i].get(vcoord);
-   
-    for(int d=0; d<ndim; d++)
-      coords[d*nverts + vertMap[i]] = vcoord[d];
-    
-  }
-
-  double dist = 0.0;
-  MBElemUtil::hex_findpt(xm, n, xyz, ncoords, dist);
-  if (3*EPS < dist) {
-      // outside element, set extremal values to something outside range
-    for (int j = 0; j < 3; j++) {
-      if (ncoords[j] < (-1.0-etol) || ncoords[j] > (1.0+etol))
-        ncoords[j] *= 10;
-    }
-  }
-  
-}
-
-bool point_in_trilinear_hex(const MBCartVect *hex, 
-                            const MBCartVect& xyz,
-                            double etol) 
-{
-  MBCartVect xi;
-  return nat_coords_trilinear_hex( hex, xyz, xi, etol )
-      && fabs(xi[0])-1 < etol 
-      && fabs(xi[1])-1 < etol 
-      && fabs(xi[2])-1 < etol;
-}
-
-
-bool point_in_trilinear_hex(const MBCartVect *hex, 
-                            const MBCartVect& xyz, 
-                            const MBCartVect& box_min, 
-                            const MBCartVect& box_max,
-                            double etol) 
-{
-    // all values scaled by 2 (eliminates 3 flops)
-  const MBCartVect mid = box_max + box_min;
-  const MBCartVect dim = box_max - box_min;
-  const MBCartVect pt = 2*xyz - mid;
-  return fabs(pt[0]) - dim[0] < etol &&
-         fabs(pt[1]) - dim[1] < etol &&
-         fabs(pt[2]) - dim[2] < etol &&
-         point_in_trilinear_hex( hex, xyz, etol );
-}
-
-
-
-// Wrapper to James Lottes' findpt routines
-// hex_findpt
-// Find the parametric coordinates of an xyz point inside
-// a 3d hex spectral element with n nodes per dimension
-// xm: coordinates fields, value of x,y,z for each of then n*n*n gauss-lobatto nodes. Nodes are in lexicographical order (x is fastest-changing)
-// n: number of nodes per dimension -- n=2 for a linear element
-// xyz: input, point to find
-// rst: output: parametric coords of xyz inside the element. If xyz is outside the element, rst will be the coords of the closest point
-// dist: output: distance between xyz and the point with parametric coords rst
-extern "C"{
-#include "types.h"
-#include "poly.h"
-#include "tensor.h"
-#include "findpt.h"
-#include "extrafindpt.h"
-#include "errmem.h"
-}
-
-void hex_findpt(real *xm[3],
-                int n,
-                MBCartVect xyz,
-                MBCartVect &rst,
-                double &dist)       
-{
-
-  //compute stuff that only depends on the order -- could be cached
-  real *z[3];
-  lagrange_data ld[3];
-  opt_data_3 data;
-
-  //triplicates
-  for(int d=0; d<3; d++){
-    z[d] = tmalloc(real, n);
-    lobatto_nodes(z[d], n); 
-    lagrange_setup(&ld[d], z[d], n);
-  }
-
-  opt_alloc_3(&data, ld);
-
-  //find nearest point
-  real x_star[3];
-  xyz.get(x_star);
-
-  real r[3] = {0, 0, 0 }; // initial guess for parametric coords
-  unsigned c = opt_no_constraints_3;
-  dist = opt_findpt_3(&data, (const real **)xm, x_star, r, &c);
-  //c tells us if we landed inside the element or exactly on a face, edge, or node
-
-  //copy parametric coords back
-  rst = r;
-
-  //Clean-up (move to destructor if we decide to cache)
-  opt_free_3(&data);  
-  for(int d=0; d<3; ++d) 
-    lagrange_free(&ld[d]);
-  for(int d=0; d<3; ++d) 
-    free(z[d]);
-}
-
-
-
-
-// hex_eval
-// Evaluate a field in a 3d hex spectral element with n nodes per dimension, at some given parametric coordinates
-// field: field values for each of then n*n*n gauss-lobatto nodes. Nodes are in lexicographical order (x is fastest-changing)
-// n: number of nodes per dimension -- n=2 for a linear element
-// rst: input: parametric coords of the point where we want to evaluate the field
-// value: output: value of field at rst
-
-void hex_eval(real *field,
-	      int n,
-	      MBCartVect rstCartVec,
-	      double &value)       
-{
-  int d;
-  real rst[3];
-  rstCartVec.get(rst);
-
-  //can cache stuff below
-  lagrange_data ld[3]; 
-  real *z[3];
-  for(d=0;d<3;++d){
-    z[d] = tmalloc(real, n);
-    lobatto_nodes(z[d], n);
-    lagrange_setup(&ld[d], z[d], n);
-  } 
-
-  //cut and paste -- see findpt.c
-  const unsigned 
-    nf = n*n,
-    ne = n,
-    nw = 2*n*n + 3*n;
-  real *od_work = tmalloc(real, 6*nf + 9*ne + nw);
-
-  //piece that we shouldn't want to cache
-  for(d=0; d<3; d++){
-    lagrange_0(&ld[d], rst[d]);
-  }
-  
-  value = tensor_i3(ld[0].J,ld[0].n,
-		    ld[1].J,ld[1].n,
-		    ld[2].J,ld[2].n,
-		    field,
-		    od_work);
-
-  //all this could be cached
-  for(d=0; d<3; d++){
-    free(z[d]);
-    lagrange_free(&ld[d]); 
-  }
-  free(od_work);
-}
-
-} // namespace MBElemUtil
-

Deleted: MOAB/trunk/tools/mbcoupler/MBElemUtil.hpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBElemUtil.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/MBElemUtil.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,38 +0,0 @@
-#include "MBCore.hpp"
-#include "MBCartVect.hpp"
-
-namespace MBElemUtil {
-
-  bool nat_coords_trilinear_hex(const MBCartVect* hex_corners, 
-                                const MBCartVect& x, 
-                                MBCartVect& xi,
-                                double tol);
-  bool point_in_trilinear_hex(const MBCartVect *hex_corners, 
-                              const MBCartVect& xyz,
-                              double etol);
-  
-  bool point_in_trilinear_hex(const MBCartVect *hex_corners, 
-                              const MBCartVect& xyz, 
-                              const MBCartVect& box_min, 
-                              const MBCartVect& box_max,
-                              double etol);
-
-    //wrapper to hex_findpt
-  void nat_coords_trilinear_hex2(const MBCartVect* hex_corners, 
-                                 const MBCartVect& x, 
-                                 MBCartVect& xi,
-                                 double til);
-
-
-
-  void hex_findpt(double *xm[3],
-                  int n,
-                  MBCartVect xyz, 
-                  MBCartVect& rst,
-                  double& dist);
-
-  void hex_eval(double *field,
-		int n,
-		MBCartVect rst,
-		double &value);
-} // namespace MBElemUtil

Modified: MOAB/trunk/tools/mbcoupler/Makefile.am
===================================================================
--- MOAB/trunk/tools/mbcoupler/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,9 +1,6 @@
 AM_CPPFLAGS += -I$(top_srcdir)/src \
                -I$(top_builddir)/src \
                -I$(top_srcdir)/src/parallel \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_builddir)/src/moab \
-               -I$(top_srcdir)/src/parallel/moab \
                -I$(top_srcdir)/test
 
 lib_LTLIBRARIES = libmbcoupler.la
@@ -12,7 +9,7 @@
 LDADD = libmbcoupler.la 
 
 libmbcoupler_la_SOURCES = \
-   MBElemUtil.cpp \
+   ElemUtil.cpp \
    poly.c   \
    poly.h   \
    tensor.c \
@@ -24,11 +21,11 @@
    findpt.h \
    minmax.h \
    types.h \
-   MBCoupler.cpp
+   Coupler.cpp
 
 libmbcoupler_la_include_HEADERS = \
-   MBElemUtil.hpp \
-   MBCoupler.hpp
+   ElemUtil.hpp \
+   Coupler.hpp
 
 libmbcoupler_la_includedir = $(includedir)
 

Modified: MOAB/trunk/tools/mbcoupler/addfield.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/addfield.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/addfield.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,12 @@
 #include <iostream>
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 #include <math.h>
 #include <cstdlib>
 using namespace std;
 
 
+namespace moab {
+
 //make a nice picture. tweak here
 //217: x,y -> [-8, 8] /// z -> [-65, 65]
 double physField(double x, double y, double z, double factor){
@@ -22,8 +24,8 @@
 
 
 //get some sort of element center
-void getHexPos(MBInterface *mbi, MBEntityHandle *hex, double &x, double &y, double &z){
-  std::vector<MBEntityHandle> connect;
+void getHexPos(Interface *mbi, EntityHandle *hex, double &x, double &y, double &z){
+  std::vector<EntityHandle> connect;
  
   mbi->get_connectivity(hex, 1, connect);
   double pos[3]={0,0,0};
@@ -31,7 +33,7 @@
   int numVerts = connect.size();
   for(int i=0; i<numVerts; i++){
     double tempPos[3];
-    MBEntityHandle vert(connect[i]);
+    EntityHandle vert(connect[i]);
 
     mbi->get_coords(&vert, 1, tempPos);
 
@@ -46,20 +48,20 @@
 }
 
 
-void putElementField(MBInterface *mbi, char *tagname, double factor){
-  MBRange hexes;
+void putElementField(Interface *mbi, char *tagname, double factor){
+  Range hexes;
 
   mbi->get_entities_by_type(0, MBHEX, hexes);
 
   const double defVal = 0.;
-  MBTag fieldTag;
+  Tag fieldTag;
   mbi->tag_create(tagname, sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, fieldTag, &defVal);
  
   int numHexes = hexes.size();
 
   for(int i=0; i<numHexes; i++){
       //cout << hexes[i] << endl;
-    MBEntityHandle hex = hexes[i];
+    EntityHandle hex = hexes[i];
 
     double x,y,z;
     getHexPos(mbi, &hex, x,y,z);
@@ -72,18 +74,18 @@
 }
 
 
-void putVertexField(MBInterface *mbi, char *tagname, double factor){
-  MBRange verts;
+void putVertexField(Interface *mbi, char *tagname, double factor){
+  Range verts;
 
   mbi->get_entities_by_type(0, MBVERTEX, verts);
 
   const double defVal = 0.;
-  MBTag fieldTag;
+  Tag fieldTag;
   mbi->tag_create(tagname, sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, fieldTag, &defVal);
  
   int numVerts = verts.size();
   for(int i=0; i<numVerts; i++){
-    MBEntityHandle vert = verts[i]; //?
+    EntityHandle vert = verts[i]; //?
 
     double vertPos[3];
     mbi->get_coords(&vert, 1, vertPos);
@@ -100,7 +102,7 @@
 
 //Using moab instead of imesh for dev speed
 int main(int argc, char **argv){
-  MBInterface *mbi = new MBCore();
+  Interface *mbi = new Core();
 
   if (argc < 3){
     cout << "Usage: " << argv[0] << " <infile> <outfile> [factor]\n"
@@ -116,7 +118,7 @@
   putVertexField(mbi, "vertex_field", factor);
   putElementField(mbi, "element_field", factor);
 
-  MBErrorCode result = mbi->write_mesh(argv[2]);
+  ErrorCode result = mbi->write_mesh(argv[2]);
   if (MB_SUCCESS == result) cout << "wrote " << argv[2] << endl;
   else cout << "Failed to write " << argv[2] << endl;
 
@@ -128,3 +130,6 @@
 
   return 1;
 }
+
+} // namespace moab
+

Modified: MOAB/trunk/tools/mbcoupler/findpt_test.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/findpt_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/findpt_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,10 @@
 #include <iostream>
-#include "MBElemUtil.hpp"
+#include "ElemUtil.hpp"
 
 using namespace std;
-using namespace MBElemUtil;
+using namespace moab;
+using namespace ElemUtil;
 
-
 extern "C"{
 #include "errmem.h" //for tmalloc, convenient but not C++
 #include "types.h"
@@ -14,8 +14,8 @@
 void test_hex_findpt()
 {
 
-    MBCartVect xyz(.5,.3,.4);
-    MBCartVect rst;
+    CartVect xyz(.5,.3,.4);
+    CartVect rst;
     double dist;
 
     double *xm[3]; //element coord fields, lex ordering
@@ -53,7 +53,7 @@
 
 void test_hex_eval()
 {
-    MBCartVect rst(.5,.3,.4);
+    CartVect rst(.5,.3,.4);
     double value;
 
     const int n=2; //number of nodes per direction (min is 2, for linear element)
@@ -80,20 +80,20 @@
 
 void test_nat_coords_trilinear_hex2()
 {
-  MBCartVect hex[8];
-  MBCartVect xyz(.5,.3,.4);
-  MBCartVect ncoords;;
+  CartVect hex[8];
+  CartVect xyz(.5,.3,.4);
+  CartVect ncoords;;
   double etol;
   
   //Make our sample hex the unit cube [0,1]**3
-  hex[0] = MBCartVect(0,0,0);
-  hex[1] = MBCartVect(1,0,0);
-  hex[2] = MBCartVect(1,1,0);
-  hex[3] = MBCartVect(0,1,0);
-  hex[4] = MBCartVect(0,0,1);
-  hex[5] = MBCartVect(1,0,1);
-  hex[6] = MBCartVect(1,1,1);
-  hex[7] = MBCartVect(0,1,1);
+  hex[0] = CartVect(0,0,0);
+  hex[1] = CartVect(1,0,0);
+  hex[2] = CartVect(1,1,0);
+  hex[3] = CartVect(0,1,0);
+  hex[4] = CartVect(0,0,1);
+  hex[5] = CartVect(1,0,1);
+  hex[6] = CartVect(1,1,1);
+  hex[7] = CartVect(0,1,1);
 
   etol = .1 ; //ignored by nat_coords
 

Modified: MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,20 +1,22 @@
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBCore.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBParallelConventions.h"
+#include "moab/Core.hpp"
 #include "FileOptions.hpp"
 #include "ReadParallel.hpp"
-#include "MBCoupler.hpp"
-#include "MBmpi.h"
+#include "Coupler.hpp"
+#include "moab_mpi.h"
 #include <iostream>
 #include <sstream>
 #include <assert.h>
 
+using namespace moab;
+
 bool debug = false;
 
 #define RRA(a) if (MB_SUCCESS != result) {\
       std::string tmp_str; mbImpl->get_last_error(tmp_str);\
       tmp_str.append("\n"); tmp_str.append(a);\
-      dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(tmp_str.c_str()); \
+      dynamic_cast<Core*>(mbImpl)->get_error_handler()->set_last_error(tmp_str.c_str()); \
       return result;}
 
 #define PRINT_LAST_ERROR \
@@ -27,19 +29,19 @@
       return result;\
     }
 
-MBErrorCode get_file_options(int argc, char **argv, 
+ErrorCode get_file_options(int argc, char **argv, 
                              std::vector<const char *> &filenames,
                              std::string &tag_name,
                              std::string &out_fname,
                              std::string &opts);
 
-MBErrorCode report_iface_ents(MBInterface *mbImpl,
-                              std::vector<MBParallelComm *> &pcs,
+ErrorCode report_iface_ents(Interface *mbImpl,
+                              std::vector<ParallelComm *> &pcs,
                               bool print_results);
 
-MBErrorCode test_interpolation(MBInterface *mbImpl, 
+ErrorCode test_interpolation(Interface *mbImpl, 
                                std::string &interp_tag,
-                               std::vector<MBParallelComm *> &pcs,
+                               std::vector<ParallelComm *> &pcs,
                                std::vector<ReadParallel *> rps,
                                double &instant_time,
                                double &pointloc_time,
@@ -76,10 +78,10 @@
   if (0 == rank) stime = MPI_Wtime();
 
     // create MOAB instance based on that
-  MBInterface *mbImpl = new MBCore(rank, nprocs);
+  Interface *mbImpl = new Core(rank, nprocs);
   if (NULL == mbImpl) return 1;
   
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
 
   std::vector<const char *> filenames;
   std::string opts, interp_tag, out_fname;
@@ -87,11 +89,11 @@
   
 
     // read in mesh(es)
-  std::vector<MBParallelComm *> pcs(filenames.size()); 
+  std::vector<ParallelComm *> pcs(filenames.size()); 
   std::vector<ReadParallel *> rps(filenames.size()); 
 
   for (unsigned int i = 0; i < filenames.size(); i++) {
-    pcs[i] = new MBParallelComm(mbImpl);
+    pcs[i] = new ParallelComm(mbImpl);
     rps[i] = new ReadParallel(mbImpl, pcs[i]);
     
     result = rps[i]->load_file(filenames[i], 0, FileOptions(opts.c_str()));
@@ -140,12 +142,12 @@
   return 0;
 }
 
-MBErrorCode report_iface_ents(MBInterface *mbImpl,
-                              std::vector<MBParallelComm *> &pcs,
+ErrorCode report_iface_ents(Interface *mbImpl,
+                              std::vector<ParallelComm *> &pcs,
                               const bool print_results) 
 {
-  MBRange iface_ents[6];
-  MBErrorCode result = MB_SUCCESS, tmp_result;
+  Range iface_ents[6];
+  ErrorCode result = MB_SUCCESS, tmp_result;
   
     // now figure out which vertices are shared
   for (unsigned int p = 0; p < pcs.size(); p++) {
@@ -167,7 +169,7 @@
 
     // report # iface entities
   result = mbImpl->get_adjacencies(iface_ents[4], 0, false, iface_ents[5], 
-                                   MBInterface::UNION);
+                                   Interface::UNION);
 
   int rank;
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -184,7 +186,7 @@
   return result;
 }
 
-MBErrorCode get_file_options(int argc, char **argv, 
+ErrorCode get_file_options(int argc, char **argv, 
                              std::vector<const char *> &filenames,
                              std::string &interp_tag,
                              std::string &out_fname,
@@ -235,33 +237,33 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode test_interpolation(MBInterface *mbImpl, 
+ErrorCode test_interpolation(Interface *mbImpl, 
                                std::string &interp_tag,
-                               std::vector<MBParallelComm *> &pcs,
+                               std::vector<ParallelComm *> &pcs,
                                std::vector<ReadParallel *> rps,
                                double &instant_time,
                                double &pointloc_time,
                                double &interp_time) 
 {
     // source is 1st mesh, target is 2nd
-  MBRange src_elems, targ_elems;
-  MBErrorCode result = pcs[0]->get_part_entities(src_elems, 3);
+  Range src_elems, targ_elems;
+  ErrorCode result = pcs[0]->get_part_entities(src_elems, 3);
   PRINT_LAST_ERROR;
 
   double start_time = MPI_Wtime();
 
     // instantiate a coupler, which also initializes the tree
-  MBCoupler mbc(mbImpl, pcs[0], src_elems, 0);
+  Coupler mbc(mbImpl, pcs[0], src_elems, 0);
 
   instant_time = MPI_Wtime();
 
     // get points from the target mesh to interpolate
-  MBRange targ_verts, tmp_verts;
+  Range targ_verts, tmp_verts;
 
     // first get all vertices adj to partition entities in target mesh
   result = pcs[1]->get_part_entities(targ_elems, 3);
   result = mbImpl->get_adjacencies(targ_elems, 0, false, targ_verts, 
-                                   MBInterface::UNION);
+                                   Interface::UNION);
   PRINT_LAST_ERROR;
 
     // then get non-owned verts and subtract 
@@ -284,9 +286,9 @@
   std::vector<double> field(targ_verts.size());
 
   if(interp_tag == "vertex_field"){
-    result = mbc.interpolate(MBCoupler::LINEAR_FE, interp_tag, &field[0]);
+    result = mbc.interpolate(Coupler::LINEAR_FE, interp_tag, &field[0]);
   }else if(interp_tag == "element_field"){
-    result = mbc.interpolate(MBCoupler::PLAIN_FE, interp_tag, &field[0]);
+    result = mbc.interpolate(Coupler::PLAIN_FE, interp_tag, &field[0]);
   }else{
     std::cout << "Using tag name to determine type of sourge field at the moment... Use either vertex_field or element_field\n";
     result = MB_FAILURE;
@@ -300,7 +302,7 @@
   instant_time -= start_time;
 
     // set field values as tag on target vertices
-  MBTag tag;
+  Tag tag;
   result = mbImpl->tag_get_handle(interp_tag.c_str(), tag); PRINT_LAST_ERROR;
   result = mbImpl->tag_set_data(tag, targ_verts, &field[0]); PRINT_LAST_ERROR;
 

Modified: MOAB/trunk/tools/mbperf/Makefile.am
===================================================================
--- MOAB/trunk/tools/mbperf/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbperf/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -13,9 +13,7 @@
             -I$(top_srcdir)/itaps \
             -I$(top_srcdir)/itaps/imesh \
             -I$(top_builddir)/itaps \
-            -I$(top_builddir)/itaps/imesh \
-            -I$(top_srcdir)/src/moab \
-            -I$(top_builddir)/src/moab
+            -I$(top_builddir)/itaps/imesh 
 
 bin_PROGRAMS = mbperf $(imesh_progs)
 

Modified: MOAB/trunk/tools/mbperf/cubit_perf.cpp
===================================================================
--- MOAB/trunk/tools/mbperf/cubit_perf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbperf/cubit_perf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -35,6 +35,8 @@
 
 const double LENGTH = 1.0;
 
+using namespace moab;
+
 extern "C" 
 {
   void __ctype_toupper() 

Modified: MOAB/trunk/tools/mbperf/mbperf.cpp
===================================================================
--- MOAB/trunk/tools/mbperf/mbperf.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbperf/mbperf.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,16 +37,18 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <assert.h>
-#include "MBCore.hpp"
-#include "MBReadUtilIface.hpp"
+#include "moab/Core.hpp"
+#include "moab/ReadUtilIface.hpp"
 #include "ScdVertexData.hpp"
 #include "VertexSequence.hpp"
 #include "StructuredElementSeq.hpp"
 #include "EntitySequence.hpp"
 #include "SequenceManager.hpp"
-#include "HomXform.hpp"
-#include "MBSkinner.hpp"
+#include "moab/HomXform.hpp"
+#include "moab/Skinner.hpp"
 
+using namespace moab;
+
 double LENGTH = 1.0;
 const int DEFAULT_INTERVALS = 50;
 
@@ -56,12 +58,12 @@
 void testC(const int nelem, const int );
 void print_time(const bool print_em, double &tot_time, double &utime, double &stime,
                 double &mem);
-void query_vert_to_elem(MBInterface*);
-void query_elem_to_vert(MBInterface*);
-void query_struct_elem_to_vert(MBInterface*);
+void query_vert_to_elem(Interface*);
+void query_elem_to_vert(Interface*);
+void query_struct_elem_to_vert(Interface*);
 void get_time_mem(double &tot_time, double &user_time,
                   double &sys_time, double &tot_mem);
-void bulk_construct_mesh( MBInterface* gMB, const int nelem );
+void bulk_construct_mesh( Interface* gMB, const int nelem );
 void create_regular_mesh( int interval, int dimension );
 void skin_common( int interval, int dim, bool use_adj );
 void skin(const int intervals, const int dim) 
@@ -261,9 +263,9 @@
             << mem1/1.0e6 << " MB." << std::endl;
 }
 
-void build_connect(const int nelem, const MBEntityHandle vstart, MBEntityHandle *connect) 
+void build_connect(const int nelem, const EntityHandle vstart, EntityHandle *connect) 
 {
-  MBEntityHandle vijk;
+  EntityHandle vijk;
   int numv = nelem + 1;
   int numv_sq = numv*numv;
   int idx = 0;
@@ -403,14 +405,14 @@
   return 0;
 }
 
-void query_elem_to_vert(MBInterface* gMB)
+void query_elem_to_vert(Interface* gMB)
 {
-  MBRange all_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
-  const MBEntityHandle *connect;
+  Range all_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
+  const EntityHandle *connect;
   int num_connect;
   double dum_coords[24];
-  for (MBRange::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
+  for (Range::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
     result = gMB->get_connectivity(*eit, connect, num_connect);
     assert(MB_SUCCESS == result);
     result = gMB->get_coords(connect, num_connect, dum_coords);
@@ -426,27 +428,27 @@
   }
 }
 
-void query_vert_to_elem(MBInterface* gMB)
+void query_vert_to_elem(Interface* gMB)
 {
-  MBRange all_verts;
-  std::vector<MBEntityHandle> neighbor_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBVERTEX, all_verts);
+  Range all_verts;
+  std::vector<EntityHandle> neighbor_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBVERTEX, all_verts);
   assert(MB_SUCCESS == result);
-  for (MBRange::iterator vit = all_verts.begin(); vit != all_verts.end(); vit++) {
+  for (Range::iterator vit = all_verts.begin(); vit != all_verts.end(); vit++) {
     neighbor_hexes.clear();
     result = gMB->get_adjacencies(&(*vit), 1, 3, false, neighbor_hexes);
     assert(MB_SUCCESS == result);
   }
 }
 
-void query_struct_elem_to_vert(MBInterface* gMB)
+void query_struct_elem_to_vert(Interface* gMB)
 {
     // assumes brick mapped mesh with handles starting at zero
-  MBRange all_hexes;
-  MBErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
+  Range all_hexes;
+  ErrorCode result = gMB->get_entities_by_type(0, MBHEX, all_hexes);
   double dum_coords[24];
-  std::vector<MBEntityHandle> connect;
-  for (MBRange::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
+  std::vector<EntityHandle> connect;
+  for (Range::iterator eit = all_hexes.begin(); eit != all_hexes.end(); eit++) {
     result = gMB->get_connectivity(&(*eit), 1, connect);
     assert(MB_SUCCESS == result);
     result = gMB->get_coords(&connect[0], connect.size(), dum_coords);
@@ -531,8 +533,8 @@
 
 void testA( const int nelem, const int  ) 
 {
-  MBCore moab;
-  MBInterface* gMB = &moab;
+  Core moab;
+  Interface* gMB = &moab;
   double ttime0, ttime1, ttime2, ttime3, utime, stime, mem;
   
   print_time(false, ttime0, utime, stime, mem);
@@ -546,9 +548,9 @@
   SequenceManager *seq_mgr = moab.sequence_manager();
   HomCoord vseq_minmax[2] = {HomCoord(0,0,0), 
                              HomCoord(nelem, nelem, nelem)};
-  MBEntityHandle vstart, estart;
+  EntityHandle vstart, estart;
   
-  MBErrorCode result = seq_mgr->create_scd_sequence(vseq_minmax[0], vseq_minmax[1],
+  ErrorCode result = seq_mgr->create_scd_sequence(vseq_minmax[0], vseq_minmax[1],
                                                     MBVERTEX, 1, vstart, dum_seq);
   if (NULL != dum_seq) vseq = dynamic_cast<ScdVertexData*>(dum_seq->data());
   assert (MB_FAILURE != result && vstart != 0 && dum_seq != NULL && vseq != NULL);
@@ -569,7 +571,7 @@
   build_coords(nelem, coords);
 
     // set the coordinates of the vertices
-  MBEntityHandle handle;
+  EntityHandle handle;
   int i;
   double dumv[3];
   int num_verts = (nelem + 1)*(nelem + 1)*(nelem + 1);
@@ -601,21 +603,21 @@
             << std::endl;
 }
 
-void bulk_construct_mesh( MBInterface* gMB, const int nelem )
+void bulk_construct_mesh( Interface* gMB, const int nelem )
 {
   int num_verts = (nelem + 1)*(nelem + 1)*(nelem + 1);
   int num_elems = nelem*nelem*nelem;
-  MBEntityHandle vstart, estart;
+  EntityHandle vstart, estart;
 
   void *ptr = 0;
   // get the read interface
-  gMB->query_interface("MBReadUtilIface", &ptr);
-  MBReadUtilIface* readMeshIface = static_cast<MBReadUtilIface*>(ptr);
+  gMB->query_interface("ReadUtilIface", &ptr);
+  ReadUtilIface* readMeshIface = static_cast<ReadUtilIface*>(ptr);
 
   // create a sequence to hold the node coordinates
   // get the current number of entities and start at the next slot
   std::vector<double*> coord_arrays;
-  MBErrorCode result = readMeshIface->get_node_arrays(3, num_verts, 1, vstart, coord_arrays);
+  ErrorCode result = readMeshIface->get_node_arrays(3, num_verts, 1, vstart, coord_arrays);
   assert(MB_SUCCESS == result && 1 == vstart &&
          coord_arrays[0] && coord_arrays[1] && coord_arrays[2]);
     // memcpy the coordinate data into place
@@ -625,7 +627,7 @@
   memcpy(coord_arrays[1], &coords[num_verts], sizeof(double)*num_verts);
   memcpy(coord_arrays[2], &coords[2*num_verts], sizeof(double)*num_verts);
   
-  MBEntityHandle *conn = 0;
+  EntityHandle *conn = 0;
   result = readMeshIface->get_element_array(num_elems, 8, MBHEX, 1, estart, conn);
   assert(MB_SUCCESS == result);
   build_connect(nelem, vstart, conn);
@@ -635,8 +637,8 @@
 
 void testB(const int nelem, const int ) 
 {
-  MBCore moab;
-  MBInterface* gMB = &moab;
+  Core moab;
+  Interface* gMB = &moab;
   double ttime0, ttime1, ttime2, ttime3, utime, stime, mem;
   
   print_time(false, ttime0, utime, stime, mem);
@@ -668,8 +670,8 @@
 
 void testC(const int nelem, const int ) 
 {
-  MBCore moab;
-  MBInterface* gMB = &moab;
+  Core moab;
+  Interface* gMB = &moab;
   double ttime0, ttime1, ttime2, ttime3, utime, stime, mem;
   
   print_time(false, ttime0, utime, stime, mem);
@@ -683,12 +685,12 @@
   int numv_sq = numv*numv;
   int num_verts = numv*numv*numv;
   double dum_coords[3] = {coords[0], coords[num_verts], coords[2*num_verts]};
-  MBEntityHandle vstart;
+  EntityHandle vstart;
 
-  MBErrorCode result = gMB->create_vertex(dum_coords, vstart);
+  ErrorCode result = gMB->create_vertex(dum_coords, vstart);
   assert(MB_SUCCESS == result && 1 == vstart);
 
-  MBEntityHandle dum_vert, vijk;
+  EntityHandle dum_vert, vijk;
   int i;
   for (i = 1; i < num_verts; i++) {
     dum_coords[0] = coords[i]; 
@@ -698,7 +700,7 @@
     assert(MB_SUCCESS == result);
   }
 
-  MBEntityHandle dum_conn[8];
+  EntityHandle dum_conn[8];
   for (i=0; i < nelem; i++) {
     for (int j=0; j < nelem; j++) {
       for (int k=0; k < nelem; k++) {
@@ -740,7 +742,7 @@
 }
 
 
-void create_regular_mesh( MBInterface* gMB, int interval, int dim )
+void create_regular_mesh( Interface* gMB, int interval, int dim )
 {
   if (dim < 1 || dim > 3 || interval < 1) {
     std::cerr << "Invalid arguments" << std::endl;
@@ -753,12 +755,12 @@
 
   void *ptr = 0;
   // get the read interface
-  gMB->query_interface("MBReadUtilIface", &ptr);
-  MBReadUtilIface* readMeshIface = static_cast<MBReadUtilIface*>(ptr);
+  gMB->query_interface("ReadUtilIface", &ptr);
+  ReadUtilIface* readMeshIface = static_cast<ReadUtilIface*>(ptr);
   
-  MBEntityHandle vstart;
+  EntityHandle vstart;
   std::vector<double*> arrays;
-  MBErrorCode rval = readMeshIface->get_node_arrays(3, num_vert, 1, vstart, arrays);
+  ErrorCode rval = readMeshIface->get_node_arrays(3, num_vert, 1, vstart, arrays);
   if (MB_SUCCESS != rval || arrays.size() < 3) {
     std::cerr << "Vertex creation failed" << std::endl;
     exit(2);
@@ -778,9 +780,9 @@
   const long vert_per_elem = 1 << dim; // 2^dim
   const long intervals[3] = { interval, dim>1?interval:1, dim>2?interval:1 };
   const long num_elem = intervals[0]*intervals[1]*intervals[2];
-  const MBEntityType type = (dim == 1) ? MBEDGE : (dim == 2) ? MBQUAD : MBHEX;
+  const EntityType type = (dim == 1) ? MBEDGE : (dim == 2) ? MBQUAD : MBHEX;
   
-  MBEntityHandle estart, *conn = 0;
+  EntityHandle estart, *conn = 0;
   rval = readMeshIface->get_element_array( num_elem, vert_per_elem, type, 0, estart, conn );
   if (MB_SUCCESS != rval || !conn) {
     std::cerr << "Element creation failed" << std::endl;
@@ -793,7 +795,7 @@
   const long corners[8] = { 0, 1, 1+dims[0], dims[0], c, c+1, c+1+dims[0], c+dims[0] };
                              
     // Populate element list
-  MBEntityHandle* iter = conn;
+  EntityHandle* iter = conn;
   for (long z = 0; z < intervals[2]; ++z)
     for (long y = 0; y < intervals[1]; ++y)
       for (long x = 0; x < intervals[0]; ++x)
@@ -813,19 +815,19 @@
 
 void skin_common( int interval, int dim, bool use_adj ) 
 {
-  MBCore moab;
-  MBInterface* gMB = &moab;
-  MBErrorCode rval;
+  Core moab;
+  Interface* gMB = &moab;
+  ErrorCode rval;
   double d;
   clock_t t, tt;
 
   create_regular_mesh( gMB, interval, dim );
 
-  MBRange skin, verts, elems;
+  Range skin, verts, elems;
   rval = gMB->get_entities_by_dimension( 0, dim, elems );
   assert(MB_SUCCESS == rval); assert(!elems.empty());
 
-  MBSkinner tool(gMB);
+  Skinner tool(gMB);
   
   t = clock();
   rval = tool.find_skin( elems, true, verts, 0, use_adj, false );
@@ -841,11 +843,11 @@
   long blocksize = elems.size() / 1000;
   if (!blocksize) blocksize = 1;
   long numblocks = elems.size()/blocksize;
-  MBRange::iterator it = elems.begin();
+  Range::iterator it = elems.begin();
   for (long i = 0; i < numblocks; ++i) {
     verts.clear();
-    MBRange::iterator end = it + blocksize;
-    MBRange blockelems;
+    Range::iterator end = it + blocksize;
+    Range blockelems;
     blockelems.merge( it, end );
     it = end;
     tt = clock();
@@ -865,7 +867,7 @@
         // create all interior faces
       skin.clear();
       t = clock();
-      gMB->get_adjacencies( elems, dim-1, true, skin, MBInterface::UNION );
+      gMB->get_adjacencies( elems, dim-1, true, skin, Interface::UNION );
       t = clock() - t;
       d = ((double)t)/CLOCKS_PER_SEC;
       std::cout << "Created " << skin.size() << " entities of dimension-1 in " << d << " seconds" << std::endl;
@@ -886,8 +888,8 @@
     it = elems.begin();
     for (long i = 0; i < numblocks; ++i) {
       skin.clear();
-      MBRange::iterator end = it + blocksize;
-      MBRange blockelems;
+      Range::iterator end = it + blocksize;
+      Range blockelems;
       blockelems.merge( it, end );
       it = end;
       tt = clock();

Modified: MOAB/trunk/tools/mbzoltan/MBZoltan.cpp
===================================================================
--- MOAB/trunk/tools/mbzoltan/MBZoltan.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbzoltan/MBZoltan.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -24,16 +24,18 @@
 #include <assert.h>
 
 #include "MBZoltan.hpp"
-#include "MBInterface.hpp"
-#include "MBInternals.hpp"
-#include "MBParallelComm.hpp"
-#include "MBRange.hpp"
-#include "MBWriteUtilIface.hpp"
-#include "MeshTopoUtil.hpp"
-#include "MBParallelComm.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "Internals.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/Range.hpp"
+#include "moab/WriteUtilIface.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/MBCN.hpp"
 
+using namespace moab;
+
 #define RR if (MB_SUCCESS != result) return result
 
 static double *Points=NULL;
@@ -45,7 +47,7 @@
 
 const bool debug = false;
 
-MBZoltan::MBZoltan( MBInterface *impl , 
+MBZoltan::MBZoltan( Interface *impl , 
                     const bool use_coords,
                     int argc, 
                     char **argv ) 
@@ -56,9 +58,9 @@
                      argcArg(argc), 
                      argvArg(argv)
 {
-  mbpc = MBParallelComm::get_pcomm(mbImpl, 0);
+  mbpc = ParallelComm::get_pcomm(mbImpl, 0);
   if (!mbpc)
-    mbpc = new MBParallelComm( impl, MPI_COMM_WORLD, 0 );
+    mbpc = new ParallelComm( impl, MPI_COMM_WORLD, 0 );
 }
 
 MBZoltan::~MBZoltan() 
@@ -66,7 +68,7 @@
   if (NULL == myZZ) delete myZZ;
 }
 
-MBErrorCode MBZoltan::balance_mesh(const char *zmethod,
+ErrorCode MBZoltan::balance_mesh(const char *zmethod,
                                    const char *other_method,
                                    const bool write_as_sets,
                                    const bool write_as_tags) 
@@ -85,11 +87,11 @@
   std::vector<double> pts; // x[0], y[0], z[0], ... from MOAB
   std::vector<int> ids; // point ids from MOAB
   std::vector<int> adjs, length;
-  MBRange elems;
+  Range elems;
 
   // Get a mesh from MOAB and divide it across processors.
 
-  MBErrorCode result;
+  ErrorCode result;
   
   if (mbpc->proc_config().proc_rank() == 0) {
     result = assemble_graph(3, pts, ids, adjs, length, elems); RR;
@@ -182,7 +184,7 @@
                    exportProcs, &assignment);
   
   if (mbpc->proc_config().proc_rank() == 0) {
-    MBErrorCode result = write_partition(mbpc->proc_config().proc_size(), elems, assignment,
+    ErrorCode result = write_partition(mbpc->proc_config().proc_size(), elems, assignment,
                                          write_as_sets, write_as_tags);
 
     if (MB_SUCCESS != result) return result;
@@ -209,7 +211,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MBZoltan::partition_mesh(const int nparts,
+ErrorCode MBZoltan::partition_mesh(const int nparts,
                                      const char *zmethod,
                                      const char *other_method,
                                      const bool write_as_sets,
@@ -237,11 +239,11 @@
   std::vector<double> pts; // x[0], y[0], z[0], ... from MOAB
   std::vector<int> ids; // point ids from MOAB
   std::vector<int> adjs, length;
-  MBRange elems;
+  Range elems;
 
   // Get a mesh from MOAB and divide it across processors.
 
-  MBErrorCode result;
+  ErrorCode result;
   
   result = assemble_graph(part_dim, pts, ids, adjs, length, elems); RR;
   
@@ -334,18 +336,18 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MBZoltan::assemble_graph(const int dimension,
+ErrorCode MBZoltan::assemble_graph(const int dimension,
                                      std::vector<double> &coords,
                                      std::vector<int> &moab_ids,
                                      std::vector<int> &adjacencies, 
                                      std::vector<int> &length,
-                                     MBRange &elems) 
+                                     Range &elems) 
 {
     // assemble a graph with vertices equal to elements of specified dimension, edges
     // signified by list of other elements to which an element is connected
 
     // get the elements of that dimension
-  MBErrorCode result = mbImpl->get_entities_by_dimension(0, dimension, elems);
+  ErrorCode result = mbImpl->get_entities_by_dimension(0, dimension, elems);
   if (MB_SUCCESS != result || elems.empty()) return result;
   
     // assign global ids
@@ -354,7 +356,7 @@
     // now assemble the graph, calling MeshTopoUtil to get bridge adjacencies through d-1 dimensional
     // neighbors
   MeshTopoUtil mtu(mbImpl);
-  MBRange adjs;
+  Range adjs;
     // can use a fixed-size array 'cuz the number of lower-dimensional neighbors is limited
     // by MBCN
   int neighbors[5*MB_MAX_SUB_ENTITIES];
@@ -362,12 +364,12 @@
   int moab_id;
   
     // get the global id tag hanlde
-  MBTag gid;
+  Tag gid;
   result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, 4, MB_TAG_DENSE, MB_TYPE_INTEGER,
                               gid, NULL, true);
   if (MB_SUCCESS != result) return result;
   
-  for (MBRange::iterator rit = elems.begin(); rit != elems.end(); rit++) {
+  for (Range::iterator rit = elems.begin(); rit != elems.end(); rit++) {
 
       // get bridge adjacencies
     adjs.clear();
@@ -415,24 +417,24 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode MBZoltan::write_partition(const int nparts,
-                                      MBRange &elems, 
+ErrorCode MBZoltan::write_partition(const int nparts,
+                                      Range &elems, 
                                       const int *assignment,
                                       const bool write_as_sets,
                                       const bool write_as_tags) 
 {
-  MBErrorCode result;
+  ErrorCode result;
 
     // get the partition set tag
-  MBTag part_set_tag;
+  Tag part_set_tag;
   int dum_id = -1;
   result = mbImpl->tag_create("PARALLEL_PARTITION", 4, MB_TAG_SPARSE, MB_TYPE_INTEGER, part_set_tag, &dum_id,
                               true); RR;
   
     // get any sets already with this tag, and clear them
-  MBRange tagged_sets;
+  Range tagged_sets;
   result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &part_set_tag, NULL, 1,
-                                                tagged_sets, MBInterface::UNION); RR;
+                                                tagged_sets, Interface::UNION); RR;
   if (!tagged_sets.empty()) {
     result = mbImpl->clear_meshset(tagged_sets); RR;
     if (!write_as_sets) {
@@ -442,14 +444,14 @@
 
   if (write_as_sets) {
       // first, create partition sets and store in vector
-    MBEntityHandle *part_sets = new MBEntityHandle[nparts];
+    EntityHandle *part_sets = new EntityHandle[nparts];
     if (NULL == part_sets) return MB_FAILURE;
   
     if (nparts > (int) tagged_sets.size()) {
         // too few partition sets - create missing ones
       int num_new = nparts - tagged_sets.size();
       for (int i = 0; i < num_new; i++) {
-        MBEntityHandle new_set;
+        EntityHandle new_set;
         result = mbImpl->create_meshset(MESHSET_SET, new_set); RR;
         tagged_sets.insert(new_set);
       }
@@ -458,13 +460,13 @@
         // too many partition sets - delete extras
       int num_del = tagged_sets.size() - nparts;
       for (int i = 0; i < num_del; i++) {
-        MBEntityHandle old_set = tagged_sets.pop_back();
+        EntityHandle old_set = tagged_sets.pop_back();
         result = mbImpl->delete_entities(&old_set, 1); RR;
       }
     }
   
       // assign partition sets to vector
-    MBRange::iterator rit = tagged_sets.begin();
+    Range::iterator rit = tagged_sets.begin();
     int i = 0;
     for (; i < nparts; rit++, i++) part_sets[i] = *rit;
   

Modified: MOAB/trunk/tools/mbzoltan/MBZoltan.hpp
===================================================================
--- MOAB/trunk/tools/mbzoltan/MBZoltan.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbzoltan/MBZoltan.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -14,7 +14,7 @@
  */
 
 /**
- * MBZoltan: class to get a mesh from MOAB and write a Zoltan partition set for
+ * Zoltan: class to get a mesh from MOAB and write a Zoltan partition set for
  * that mesh back into MOAB and to a file
  *
  */
@@ -23,7 +23,7 @@
 #define MB_ZOLTAN_HPP
 
 #include <stdlib.h>
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #include "zoltan_cpp.h"
 
 extern "C" 
@@ -57,29 +57,34 @@
 }
 
 #include <vector>
-#include "MBTypes.h"
+#include "moab/Types.hpp"
 
-  class MBParallelComm;
-  class MBInterface;
-  class MBRange;
+namespace moab {
 
+  class ParallelComm;
+  class Interface;
+  class Range;
+}
+
+using namespace moab;
+
   class MBZoltan 
   {
 
   public:
-    MBZoltan( MBInterface *impl = NULL, 
+    MBZoltan( Interface *impl = NULL, 
               const bool use_coords = false,
               int argc = 0, 
               char **argv = NULL );
 
     ~MBZoltan();
 
-    MBErrorCode balance_mesh(const char *zmethod,
+    ErrorCode balance_mesh(const char *zmethod,
                              const char *other_method,
                              const bool write_as_sets = true,
                              const bool write_as_tags = false);
     
-    MBErrorCode partition_mesh(const int nparts,
+    ErrorCode partition_mesh(const int nparts,
                                const char *zmethod,
                                const char *other_method,
                                const bool write_as_sets = true,
@@ -88,16 +93,16 @@
     
     int get_mesh(std::vector<double> &pts, std::vector<int> &ids,
                  std::vector<int> &adjs, std::vector<int> &length,
-                 MBRange &elems);
+                 Range &elems);
 
       // given a processor assignment returned from Zoltan, write that as a
       // processor assignment to MOAB
-    MBErrorCode write_partition(const int nparts, MBRange &elems, 
+    ErrorCode write_partition(const int nparts, Range &elems, 
                                 const int *assignment,
                                 const bool write_as_sets,
                                 const bool write_as_tags);
 
-    MBErrorCode write_file(const char *filename, const char *out_file);
+    ErrorCode write_file(const char *filename, const char *out_file);
   
     void SetOCTPART_Parameters(const char *oct_method);
   
@@ -113,9 +118,9 @@
   
   private:
 
-    MBInterface *mbImpl;
+    Interface *mbImpl;
 
-    MBParallelComm *mbpc;
+    ParallelComm *mbpc;
 
     Zoltan *myZZ;
   
@@ -140,12 +145,12 @@
   
       // given the dimension, assemble the vertices and store in coords and
       // moab_ids
-    MBErrorCode assemble_graph(const int dimension, 
+    ErrorCode assemble_graph(const int dimension, 
                                std::vector<double> &coords,
                                std::vector<int> &moab_ids,
                                std::vector<int> &adjacencies, 
                                std::vector<int> &length,
-                               MBRange &elems);
+                               Range &elems);
 
     void mbFinalizePoints(int npts, int numExport,
                           ZOLTAN_ID_PTR exportLocalIDs, int *exportProcs,

Modified: MOAB/trunk/tools/mbzoltan/Makefile.am
===================================================================
--- MOAB/trunk/tools/mbzoltan/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbzoltan/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -4,9 +4,6 @@
                -I$(top_srcdir)/src \
                -I$(top_srcdir)/src/parallel \
                -I$(top_builddir)/src \
-               -I$(top_srcdir)/src/moab \
-               -I$(top_srcdir)/src/parallel/moab \
-               -I$(top_builddir)/src/moab \
                $(ZOLTAN_INC_FLAGS)
 bin_PROGRAMS = mbzoltan
 mbzoltan_SOURCES = MBZoltan.cpp MBZoltan.hpp main.cpp

Modified: MOAB/trunk/tools/mbzoltan/main.cpp
===================================================================
--- MOAB/trunk/tools/mbzoltan/main.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mbzoltan/main.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -9,7 +9,7 @@
 //
 
 #include "MBZoltan.hpp"
-#include "MBCore.hpp"
+#include "moab/Core.hpp"
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -49,10 +49,10 @@
   err = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     // create MOAB instance based on that
-  MBInterface *mbImpl = new MBCore(rank, nprocs);
+  moab::Interface *mbImpl = new moab::Core(rank, nprocs);
   if (NULL == mbImpl) return 1;
   
-  MBErrorCode result = mbImpl->load_mesh(argv[2]); RR;
+  moab::ErrorCode result = mbImpl->load_mesh(argv[2]); RR;
   
   MBZoltan *mbz = new MBZoltan(mbImpl, false, argc, argv);
 

Modified: MOAB/trunk/tools/mcnpmit/Makefile.am
===================================================================
--- MOAB/trunk/tools/mcnpmit/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mcnpmit/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,8 +1,7 @@
 LDADD = $(top_builddir)/src/libMOAB.la \
         $(top_builddir)/tools/mbcoupler/libmbcoupler.la
 
-AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/tools/mbcoupler \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab
+AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/tools/mbcoupler
 
 bin_PROGRAMS = mcnpmit
 mcnpmit_SOURCES = mcnpmit.hpp mcnpmit.cpp main.cpp

Modified: MOAB/trunk/tools/mcnpmit/main.cpp
===================================================================
--- MOAB/trunk/tools/mcnpmit/main.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mcnpmit/main.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -7,23 +7,23 @@
 
 #include "mcnpmit.hpp"
 
-#include "MBCartVect.hpp"
-#include "MBCore.hpp"
-#include "MBTagConventions.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBGeomUtil.hpp"
-#include "MBElemUtil.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/Core.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/GeomUtil.hpp"
+#include "ElemUtil.hpp"
 
 #define MBI mb_instance()
 
 McnpData* mc_instance();
-MBInterface* mb_instance();
+moab::Interface* mb_instance();
 MCNPError read_files(int, char**);
 MCNPError next_double(std::string, double&, int&);
 MCNPError next_int(std::string, int&, int&);
 
 MCNPError result;
-MBTag     coord_tag, rotation_tag, cfd_heating_tag, cfd_error_tag;
+moab::Tag     coord_tag, rotation_tag, cfd_heating_tag, cfd_error_tag;
 
 std::string h5m_filename;
 std::string CAD_filename;
@@ -58,19 +58,19 @@
   load_time = clock() - start_time;
 
   // Make the KD-Tree
-  MBErrorCode                MBresult;
-  MBAdaptiveKDTree           kdtree(MBI);
-  MBEntityHandle             root;
-  MBAdaptiveKDTree::Settings settings;
-  settings.candidatePlaneSet = MBAdaptiveKDTree::SUBDIVISION;
+  moab::ErrorCode                MBresult;
+  moab::AdaptiveKDTree           kdtree(MBI);
+  moab::EntityHandle             root;
+  moab::AdaptiveKDTree::Settings settings;
+  settings.candidatePlaneSet = moab::AdaptiveKDTree::SUBDIVISION;
 
-  MBI->tag_create("CoordTag", sizeof(int), MB_TAG_DENSE, coord_tag, 0);
-  MBI->tag_create("RotationTag", 16*sizeof(double), MB_TAG_DENSE, rotation_tag, 0);
+  MBI->tag_create("CoordTag", sizeof(int), moab::MB_TAG_DENSE, coord_tag, 0);
+  MBI->tag_create("RotationTag", 16*sizeof(double), moab::MB_TAG_DENSE, rotation_tag, 0);
 
   if (skip_build) {
     MBresult = MBI->load_mesh(h5m_filename.c_str());
 
-    if (MB_SUCCESS == MBresult) {
+    if (moab::MB_SUCCESS == MBresult) {
       std::cout << std::endl << "Read in mesh from h5m file." << std::endl << std::endl;
       std::cout << "Querying mesh file..." << std::endl;
     }
@@ -78,12 +78,12 @@
       std::cout << "Failure reading h5m file!" << std::endl;
       std::cerr  << "Error code: " << MBI->get_error_string(MBresult) << " (" << MBresult << ")" << std::endl;
       std::string message;
-      if (MB_SUCCESS == MBI->get_last_error(message) && !message.empty())
+      if (moab::MB_SUCCESS == MBI->get_last_error(message) && !message.empty())
 	std::cerr << "Error message: " << message << std::endl;
       return 1;
     }
 
-    MBRange tmprange;
+    moab::Range tmprange;
     kdtree.find_all_trees( tmprange );
     root = tmprange[0];
     
@@ -91,7 +91,7 @@
   else {
     std::cout << "Building KD-Tree..." << std::endl;      
     MBresult = kdtree.build_tree( MCNP -> elem_handles, root, &settings);
-    if (MBresult == MB_SUCCESS) {
+    if (MBresult == moab::MB_SUCCESS) {
 
       MBI->tag_set_data(coord_tag, &root, 1, &(MCNP->coord_system));
       MBI->tag_set_data(rotation_tag, &root, 1, &(MCNP->rotation_matrix));
@@ -105,7 +105,7 @@
       std::cout << "Error building KD-Tree!" << std::endl << std::endl;
       std::cerr  << "Error code: " << MBI->get_error_string(MBresult) << " (" << MBresult << ")" << std::endl;
       std::string message;
-      if (MB_SUCCESS == MBI->get_last_error(message) && !message.empty())
+      if (moab::MB_SUCCESS == MBI->get_last_error(message) && !message.empty())
 	std::cerr << "Error message: " << message << std::endl;
       return 1;
       return 1;
@@ -137,8 +137,8 @@
 
   // Used only when reading a mesh file to get vertex info
   double *cfd_coords;
-  MBRange::iterator cfd_iter;
-  MBEntityHandle meshset;
+  moab::Range::iterator cfd_iter;
+  moab::EntityHandle meshset;
 
   if (read_qnv) {      
     cadfile.open( CAD_filename.c_str() );
@@ -150,19 +150,19 @@
 
     meshset = 0;
     MBresult = MBI->load_file( CAD_filename.c_str(), &meshset );
-    assert( MB_SUCCESS == MBresult );
+    assert( moab::MB_SUCCESS == MBresult );
     assert( 0 != meshset );
 
-    MBRange cfd_verts;
-    MBresult = MBI->get_entities_by_type( meshset, MBVERTEX, cfd_verts, true);
+    moab::Range cfd_verts;
+    MBresult = MBI->get_entities_by_type( meshset, moab::MBVERTEX, cfd_verts, true);
     num_pts = cfd_verts.size();
 
     cfd_coords = new double [ 3 * num_pts ];
     MBresult = MBI->get_coords( cfd_verts , cfd_coords );  
 
     cfd_iter = cfd_verts.begin();
-    MBresult = MBI->tag_create("heating_tag", sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, cfd_heating_tag, 0); 
-    MBresult = MBI->tag_create("error_tag", sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, cfd_error_tag, 0);
+    MBresult = MBI->tag_create("heating_tag", sizeof(double), moab::MB_TAG_DENSE, moab::MB_TYPE_DOUBLE, cfd_heating_tag, 0); 
+    MBresult = MBI->tag_create("error_tag", sizeof(double), moab::MB_TAG_DENSE, moab::MB_TYPE_DOUBLE, cfd_error_tag, 0);
 
     std::cout << std::endl << "Read in mesh with query points." << std::endl << std::endl;
 
@@ -174,20 +174,20 @@
   double     taldata;
   double     errdata;
 
-  MBCartVect testvc;
+  moab::CartVect testvc;
 
   bool found = false;
 
-  MBAdaptiveKDTreeIter    treeiter;
+  moab::AdaptiveKDTreeIter    treeiter;
   kdtree.get_tree_iterator( root, treeiter );
 
   // MBRange verts;
-  std::vector<MBEntityHandle> verts;
-  MBRange range;
-  MBCartVect box_max, box_min;
+  std::vector<moab::EntityHandle> verts;
+  moab::Range range;
+  moab::CartVect box_max, box_min;
 
-  MBCartVect hexverts[8];
-  MBCartVect tmp_cartvect;
+  moab::CartVect hexverts[8];
+  moab::CartVect tmp_cartvect;
   std::vector<double> coords;
 
   double tal_sum     = 0.0,
@@ -229,7 +229,7 @@
 
     // Find the leaf containing the point
     MBresult = kdtree.leaf_containing_point( root, transformed_pt, treeiter);
-    if (MB_SUCCESS != MBresult) {
+    if (moab::MB_SUCCESS != MBresult) {
       double x, y, z;
       if (CARTESIAN == coord_sys) {
         x = testvc[0];
@@ -242,7 +242,7 @@
         z = testvc[1];
       } 
       else {
-        assert(MB_SUCCESS == MBresult);
+        assert(moab::MB_SUCCESS == MBresult);
       }
       std::cout << "No leaf found, MCNP coord xyz=" << x << " " << y << " " << z << std::endl;
       cfd_iter++;
@@ -250,23 +250,23 @@
     }
 
     range.clear();
-    MBresult = MBI -> get_entities_by_type( treeiter.handle(), MBHEX, range );
-    assert(MBresult == MB_SUCCESS);
+    MBresult = MBI -> get_entities_by_type( treeiter.handle(), moab::MBHEX, range );
+    assert(MBresult == moab::MB_SUCCESS);
 
     // davg += (double) range.size();
     // if (range.size() > nmax) nmax = range.size();
     // if (range.size() < nmin) nmin = range.size();
 
-    for (MBRange::iterator rit = range.begin(); rit != range.end(); rit++) {
+    for (moab::Range::iterator rit = range.begin(); rit != range.end(); rit++) {
       verts.clear();
-      const MBEntityHandle *connect;
+      const moab::EntityHandle *connect;
       int num_connect;
       MBresult = MBI -> get_connectivity( *rit, connect, num_connect, true); 
-      assert(MBresult == MB_SUCCESS);
+      assert(MBresult == moab::MB_SUCCESS);
 
       coords.resize(3*num_connect);
       MBresult = MBI -> get_coords( connect, num_connect, &coords[0]);
-      assert(MBresult == MB_SUCCESS);
+      assert(MBresult == moab::MB_SUCCESS);
 
       for (unsigned int j = 0; j < (unsigned int) num_connect; j++) {
 	  hexverts[j][0] = coords[3*j];
@@ -274,7 +274,7 @@
 	  hexverts[j][2] = coords[3*j+2];
       }
 
-      if (MBElemUtil::point_in_trilinear_hex(hexverts, testvc, 1.e-6)) {
+      if (moab::ElemUtil::point_in_trilinear_hex(hexverts, testvc, 1.e-6)) {
     	MBresult = MBI -> tag_get_data( MCNP->tally_tag, &(*rit), 1, &taldata);
 	MBresult = MBI -> tag_get_data( MCNP->relerr_tag, &(*rit), 1, &errdata);
 
@@ -449,8 +449,8 @@
   return &inst;
 }
 
-MBInterface* mb_instance()
+moab::Interface* mb_instance()
 {
-  static MBCore inst;
+  static moab::Core inst;
   return &inst;
 }

Modified: MOAB/trunk/tools/mcnpmit/mcnpmit.cpp
===================================================================
--- MOAB/trunk/tools/mcnpmit/mcnpmit.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mcnpmit/mcnpmit.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,10 +2,10 @@
 #include <fstream>
 #include <cstdlib>
 #include "mcnpmit.hpp"
-#include "MBCartVect.hpp"
+#include "moab/CartVect.hpp"
 #include "math.h"
 
-MBInterface* mb_instance();
+moab::Interface* mb_instance();
 
 MCNPError next_number(std::string, double&, int&);
 int how_many_numbers(std::string);
@@ -73,9 +73,9 @@
 MCNPError McnpData::read_mcnpfile(bool skip_mesh) {
 
       MCNPError result;
-      MBErrorCode MBresult;
+      moab::ErrorCode MBresult;
       int nelems;
-      MBCartVect tvect;
+      moab::CartVect tvect;
 
       std::vector<double> xvec[3];
 
@@ -143,10 +143,10 @@
             break;
             case 4:           // Read in tally data, make, and tag elements
                   mode++;
-                  MBEntityHandle elemhandle;
+                  moab::EntityHandle elemhandle;
 
-                  MBEntityHandle vstart, vijk;
-                  MBEntityHandle connect[8];
+                  moab::EntityHandle vstart, vijk;
+                  moab::EntityHandle connect[8];
                   // double d[3];
 
                   // vstart = MCNP_vertices.front();
@@ -168,8 +168,8 @@
                         connect[6] = vijk + 1 + nv[0] + nv[0]*nv[1];
                         connect[7] = vijk + nv[0] + nv[0]*nv[1];
 
-                        MBresult = MBI->create_element(MBHEX, connect, 8, elemhandle);
-                        if (MBresult != MB_SUCCESS) return MCNP_FAILURE;
+                        MBresult = MBI->create_element(moab::MBHEX, connect, 8, elemhandle);
+                        if (MBresult != moab::MB_SUCCESS) return MCNP_FAILURE;
                         elem_handles.insert(elemhandle);
 
                         mcnpfile.getline(line, 10000);
@@ -261,7 +261,7 @@
       // double v[3];
       // MBEntityHandle dumhandle;
       // MBEntityHandle vstart, vijk;
-      MBErrorCode MBresult;
+      moab::ErrorCode MBresult;
 
       unsigned int num_verts = n[0]*n[1]*n[2];
       double       *coords;
@@ -310,22 +310,22 @@
 
 MCNPError McnpData::initialize_tags() {
 
-      MBErrorCode rval;
+      moab::ErrorCode rval;
 
-      rval = MBI->tag_create(TALLY_TAG, sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, tally_tag, 0);
-      rval = MBI->tag_create(ERROR_TAG, sizeof(double), MB_TAG_DENSE, MB_TYPE_DOUBLE, relerr_tag, 0);
+      rval = MBI->tag_create(TALLY_TAG, sizeof(double), moab::MB_TAG_DENSE, moab::MB_TYPE_DOUBLE, tally_tag, 0);
+      rval = MBI->tag_create(ERROR_TAG, sizeof(double), moab::MB_TAG_DENSE, moab::MB_TYPE_DOUBLE, relerr_tag, 0);
 
       return MCNP_SUCCESS;
 
 }
 
-MCNPError McnpData::extract_tally_data(std::string s, MBEntityHandle handle) {
+MCNPError McnpData::extract_tally_data(std::string s, moab::EntityHandle handle) {
 
       int fpos = 0;
       double d = 0;
 
       MCNPError result;
-      MBErrorCode MBresult;
+      moab::ErrorCode MBresult;
 
       // Discard first three lines
       for (int i = 0; i < 3; i++) {
@@ -336,13 +336,13 @@
       result = next_number(s, d, fpos);
       if (result == MCNP_FAILURE) return MCNP_FAILURE;
       MBresult = MBI -> tag_set_data(tally_tag, &handle, 1, &d);
-      if (MBresult != MB_SUCCESS) return MCNP_FAILURE; 
+      if (MBresult != moab::MB_SUCCESS) return MCNP_FAILURE; 
 
       // Need to read in relative error entry and tag ...
       result = next_number(s, d, fpos);
       if (result == MCNP_FAILURE) return MCNP_FAILURE;
       MBresult = MBI -> tag_set_data(relerr_tag, &handle, 1, &d);
-      if (MBresult != MB_SUCCESS) return MCNP_FAILURE; 
+      if (MBresult != moab::MB_SUCCESS) return MCNP_FAILURE; 
 
       return MCNP_SUCCESS;
 }

Modified: MOAB/trunk/tools/mcnpmit/mcnpmit.hpp
===================================================================
--- MOAB/trunk/tools/mcnpmit/mcnpmit.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/mcnpmit/mcnpmit.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,5 +1,5 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
 #include <iostream>
 #define MCNP mc_instance()
 #define BOXMIN_TAG "BOXMIN_TAG"
@@ -24,15 +24,15 @@
             double rotation_matrix[16];
 
             // Vertices and elements
-            std::vector<MBEntityHandle> MCNP_vertices;
-            std::vector<MBEntityHandle> MCNP_elems;
-            MBRange                     vert_handles;
-            MBRange                     elem_handles;
+            std::vector<moab::EntityHandle> MCNP_vertices;
+            std::vector<moab::EntityHandle> MCNP_elems;
+            moab::Range                 vert_handles;
+            moab::Range                 elem_handles;
 
             // Tally data
-            MBTag box_min_tag, box_max_tag;
-            MBTag tally_tag;
-            MBTag relerr_tag;
+            moab::Tag box_min_tag, box_max_tag;
+            moab::Tag tally_tag;
+            moab::Tag relerr_tag;
 
             // MCNP Meshtal file name
             std::string MCNP_filename;
@@ -56,7 +56,7 @@
             MCNPError make_elements(std::vector<double> [3], int*);
             MCNPError make_adjacencies(int*);
             MCNPError initialize_tags();
-            MCNPError extract_tally_data(std::string, MBEntityHandle);
+            MCNPError extract_tally_data(std::string, moab::EntityHandle);
 
             // Transformation routine
             MCNPError transform_point(double*, double*, int, double*);

Modified: MOAB/trunk/tools/measure.cpp
===================================================================
--- MOAB/trunk/tools/measure.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/measure.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -150,20 +150,20 @@
   return (*start - *end).len();
 }
 
-double measure( MBEntityType type,
+double measure( moab::EntityType type,
                 int num_vertices,
                 const double* vertex_coordinates )
 {
   const CartVect* coords = reinterpret_cast<const CartVect*>(vertex_coordinates);
   switch( type )
   {
-    case MBEDGE:
+    case moab::MBEDGE:
       return (coords[0] - coords[1]).len();
-    case MBTRI:
+    case moab::MBTRI:
       return 0.5 * ((coords[1] - coords[0]) * (coords[2] - coords[0])).len();
-    case MBQUAD:
+    case moab::MBQUAD:
       num_vertices = 4;
-    case MBPOLYGON:
+    case moab::MBPOLYGON:
     {
       CartVect mid(0,0,0);
       for (int i = 0; i < num_vertices; ++i)
@@ -178,16 +178,16 @@
       }
       return 0.5 * sum;
     }
-    case MBTET:
+    case moab::MBTET:
       return tet_volume( coords[0], coords[1], coords[2], coords[3] ) ;
-    case MBPYRAMID:
+    case moab::MBPYRAMID:
       return tet_volume( coords[0], coords[1], coords[2], coords[4] ) +
              tet_volume( coords[0], coords[2], coords[3], coords[4] ) ;
-    case MBPRISM:
+    case moab::MBPRISM:
       return tet_volume( coords[0], coords[1], coords[2], coords[5] ) +
              tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
              tet_volume( coords[1], coords[4], coords[5], coords[0] ) ;
-    case MBHEX:
+    case moab::MBHEX:
       return tet_volume( coords[0], coords[1], coords[3], coords[4] ) +
              tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
              tet_volume( coords[4], coords[5], coords[1], coords[6] ) +

Modified: MOAB/trunk/tools/measure.hpp
===================================================================
--- MOAB/trunk/tools/measure.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/measure.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,11 +1,11 @@
 #ifndef MEASURE_HPP
 
-#include "MBCN.hpp"
+#include "moab/MBCN.hpp"
 
 double edge_length( const double* start_vtx_coords,
                     const double* end_vtx_coords );
 
-double measure( MBEntityType type,
+double measure( moab::EntityType type,
                 int num_vertices,
                 const double* vertex_coordinatee );
 

Modified: MOAB/trunk/tools/parse.cpp
===================================================================
--- MOAB/trunk/tools/parse.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/parse.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+using namespace moab;
 
 void tag_syntax( std::ostream& s )
 {
@@ -42,7 +43,7 @@
 
   // Parse tag value from a string (vals).  The passed size
   // is the size returned by MOAB (num values * sizeof(type)).
-void* parse_values( const char* vals, MBDataType type, int size );
+void* parse_values( const char* vals, DataType type, int size );
 
   // Parse opque tag data as either a hexidecimal number or
   // an ASCII string.
@@ -214,14 +215,14 @@
 
 
 
-void* parse_values( const char* vals, MBDataType type, int size )
+void* parse_values( const char* vals, DataType type, int size )
 {
   switch( type ) {
     case MB_TYPE_OPAQUE:  return parse_opaque_value               ( vals, size );
     case MB_TYPE_INTEGER: return parse_values_typed<          int>( vals, size );
     case MB_TYPE_DOUBLE:  return parse_values_typed<       double>( vals, size );
     case MB_TYPE_BIT:     return parse_values_typed<      bittype>( vals, size );
-    case MB_TYPE_HANDLE:  return parse_values_typed<MBEntityHandle>(vals, size );
+    case MB_TYPE_HANDLE:  return parse_values_typed<EntityHandle>(vals, size );
     default:
       std::cerr << "Unknown tag data type: " << (int)type << std::endl;
       return 0;
@@ -230,7 +231,7 @@
 
 
 
-int parse_tag_spec( char* name, TagSpec& result, MBInterface* iface )
+int parse_tag_spec( char* name, TagSpec& result, Interface* iface )
 {
     //  Separate optional tag value from tag name
   char* val = strrchr( name, '=' );
@@ -248,7 +249,7 @@
   } 
   
     // Get tag
-  MBErrorCode rval = iface->tag_get_handle( name, result.handle );
+  ErrorCode rval = iface->tag_get_handle( name, result.handle );
   if (MB_TAG_NOT_FOUND == rval)
   {
     std::cerr << "Tag not found: " << name << std::endl;
@@ -264,7 +265,7 @@
   result.value = 0;
   if (val)
   {
-    MBDataType type;
+    DataType type;
     rval = iface->tag_get_data_type( result.handle, type );
     if (MB_SUCCESS != rval)
     {
@@ -291,7 +292,7 @@
   
   
 
-int parse_tag_create( char* name, TagSpec& result, MBInterface* iface )
+int parse_tag_create( char* name, TagSpec& result, Interface* iface )
 {
     // split at '=' signs
   
@@ -326,7 +327,7 @@
   }
   *size_str = '\0';
   ++size_str;
-  MBDataType type;
+  DataType type;
   int tsize;
   if (!strcmp(type_str,"int"))
   {
@@ -346,7 +347,7 @@
   else if (!strcmp(type_str,"handle"))
   {
     type = MB_TYPE_HANDLE;
-    tsize = sizeof(MBEntityHandle);
+    tsize = sizeof(EntityHandle);
   }
   else if (!strcmp(type_str,"opaque"))
   {
@@ -379,7 +380,7 @@
   if (MB_SUCCESS == iface->tag_get_handle( name, result.handle ))
   {
       // make sure it matches
-    MBDataType etype;
+    DataType etype;
     int esize;
     if (MB_SUCCESS != iface->tag_get_data_type( result.handle, etype ) ||
         MB_SUCCESS != iface->tag_get_size( result.handle, esize ))
@@ -397,7 +398,7 @@
     std::vector<unsigned char> value(esize);
     if (result.value)
     {
-      MBErrorCode rval = iface->tag_get_default_value( result.handle, &value[0] );
+      ErrorCode rval = iface->tag_get_default_value( result.handle, &value[0] );
       if (rval != MB_ENTITY_NOT_FOUND && rval != MB_SUCCESS)
       {
         std::cerr << "Error checking default value of tag: " << name << std::endl;
@@ -412,7 +413,7 @@
   }
   else
   {
-    MBErrorCode rval = iface->tag_create( name, 
+    ErrorCode rval = iface->tag_create( name, 
                                    tsize*count, 
                                    type == MB_TYPE_BIT ? MB_TAG_BIT : MB_TAG_SPARSE,
                                    type,

Modified: MOAB/trunk/tools/parse.hpp
===================================================================
--- MOAB/trunk/tools/parse.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/parse.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -2,22 +2,22 @@
 #define PARSE_HPP
 
 #include <iosfwd>
-#include "MBInterface.hpp"
+#include "moab/Interface.hpp"
 
 // A structure containing the parsed CL tag specification.
 struct TagSpec
 {
-  MBTag handle;  // Tag handle
+  moab::Tag handle;  // Tag handle
   void* value;   // Tag value (malloc'd) or NULL if no value specified
 };
 
 // Parse a tag specified in the form: tagname=value,
 // where the "=value" portion is optional.  Returns 0 on
 // success.
-int parse_tag_spec( char* string, TagSpec& result, MBInterface* iface );
+int parse_tag_spec( char* string, TagSpec& result, moab::Interface* iface );
 
 // Parse a string specifying a new tag to create, and create it.
-int parse_tag_create( char* string, TagSpec& result, MBInterface* iface );
+int parse_tag_create( char* string, TagSpec& result, moab::Interface* iface );
 
 // Print description of syntax accepted in the string passed to
 // parse_tag_spec.

Modified: MOAB/trunk/tools/propagate_tags.cpp
===================================================================
--- MOAB/trunk/tools/propagate_tags.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/propagate_tags.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -29,15 +29,17 @@
 
 #include "parse.hpp"
 
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBInterface.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/Interface.hpp"
 #define IS_BUILDING_MB
-#include "MBInternals.hpp"
+#include "Internals.hpp"
 #undef IS_BUILDING_MB
 
+using namespace moab;
+
 #define CALL(A,B) \
-  do { MBErrorCode _r = iface->A B ; \
+  do { ErrorCode _r = iface->A B ; \
        if (MB_SUCCESS != _r) { \
          std::cerr << #A << #B << " failed at " << __FILE__ << ":" << __LINE__ << std::endl; \
          exit( 5 ); }\
@@ -45,7 +47,7 @@
   while (false)
 
 
-MBInterface* iface = 0;
+Interface* iface = 0;
 const char* exe_name = 0;
 
 void usage( bool error = true )
@@ -133,7 +135,7 @@
 
 int main( int argc, char* argv[] )
 {
-  MBCore mb_core;
+  Core mb_core;
   exe_name = argv[0];
   iface = &mb_core;
 
@@ -192,7 +194,7 @@
   bool node_from_elem_spec = false;
   bool have_data_tag = false;
   const char* write_tag_name = 0;
-  MBTag write_tag = 0;
+  Tag write_tag = 0;
   TagSpec data_tag = { 0, 0 };
   typedef std::vector<TagSpec> TagVect;
   TagVect ident_tags;
@@ -291,10 +293,10 @@
     // create it.
   else
   {
-    MBDataType data_type;
+    DataType data_type;
     CALL( tag_get_data_type, (data_tag.handle, data_type) );
     
-    MBErrorCode rval = iface->tag_get_handle( write_tag_name, write_tag );
+    ErrorCode rval = iface->tag_get_handle( write_tag_name, write_tag );
     if (MB_FAILURE == rval)
     {
       std::cerr << "Unknown error retrieving handle for tag: " << write_tag_name << std::endl;
@@ -306,7 +308,7 @@
     }
     else
     {
-      MBDataType write_type;
+      DataType write_type;
       int write_size;
       CALL( tag_get_data_type, (write_tag, write_type) );
       CALL( tag_get_size, (write_tag, write_size) );
@@ -327,7 +329,7 @@
   /**************** Done processing input -- do actual work ****************/
  
     // Get list of sets with identifying tags
-  MBRange sets, temp;
+  Range sets, temp;
   for (TagVect::iterator i = ident_tags.begin(); i != ident_tags.end(); ++i)
   {
     const void* value[] = { i->value };
@@ -338,10 +340,10 @@
   
     // For each set, set tag on contained entities
   std::vector<unsigned char> tag_data(data_size);
-  for (MBRange::iterator i = sets.begin(); i != sets.end(); ++i)
+  for (Range::iterator i = sets.begin(); i != sets.end(); ++i)
   {
       // Get tag value
-    MBErrorCode rval = iface->tag_get_data( data_tag.handle, &*i, 1, &tag_data[0] );
+    ErrorCode rval = iface->tag_get_data( data_tag.handle, &*i, 1, &tag_data[0] );
     if (MB_TAG_NOT_FOUND == rval)
     {
       if (!data_tag.value)
@@ -358,24 +360,24 @@
     }
     
       // Get entities
-    MBRange entities;
+    Range entities;
     CALL( get_entities_by_handle, (*i, entities, true) );
     int junk;
-    MBRange::iterator eb = entities.lower_bound( entities.begin(), 
+    Range::iterator eb = entities.lower_bound( entities.begin(), 
                                                  entities.end(),
                                                  CREATE_HANDLE(MBEDGE,0,junk) );
     if (elems_spec) 
-      for (MBRange::iterator j = eb; j != entities.end(); ++j)
+      for (Range::iterator j = eb; j != entities.end(); ++j)
         CALL( tag_set_data, (write_tag, &*j, 1, &tag_data[0]) );
     if (nodes_spec)
-      for (MBRange::iterator j = entities.begin(); j != eb; ++j)
+      for (Range::iterator j = entities.begin(); j != eb; ++j)
         CALL( tag_set_data, (write_tag, &*j, 1, &tag_data[0]) );
     if (node_from_elem_spec) {
-      MBRange elems;
+      Range elems;
       elems.merge( eb, entities.end() );
       entities.clear();
-      CALL( get_adjacencies, (elems, 0, false, entities, MBInterface::UNION) );
-      for (MBRange::iterator j = entities.begin(); j != entities.end(); ++j)
+      CALL( get_adjacencies, (elems, 0, false, entities, Interface::UNION) );
+      for (Range::iterator j = entities.begin(); j != entities.end(); ++j)
         CALL( tag_set_data, (write_tag, &*j, 1, &tag_data[0]) );
     }
   }

Modified: MOAB/trunk/tools/qvdual/CropTool.cpp
===================================================================
--- MOAB/trunk/tools/qvdual/CropTool.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/qvdual/CropTool.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -9,6 +9,8 @@
 
 #include "assert.h"
 
+using namespace moab;
+
 CropTool::CropTool()
 {
   func_types[0] = func_types[1] = func_types[2] = NONE;

Modified: MOAB/trunk/tools/qvdual/DrawDual.cpp
===================================================================
--- MOAB/trunk/tools/qvdual/DrawDual.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/qvdual/DrawDual.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,10 +1,9 @@
-#include "DrawDual.hpp"
+#include "moab/DrawDual.hpp"
 #include "SheetDiagramPopup.h"
-#include "MeshTopoUtil.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCartVect.hpp"
-#include "MBCN.hpp"
-#include "DualTool.hpp"
+#include "moab/MeshTopoUtil.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/CartVect.hpp"
+#include "moab/MBCN.hpp"
 #include "vtkMOABUtils.h"
 #include "vtkPolyData.h"
 #include "vtkPolyDataMapper2D.h"
@@ -61,17 +60,19 @@
 const int CENT_X = 0;
 const int CENT_Y = 0;
 
+using namespace moab;
+
 #define MBI vtkMOABUtils::mbImpl
 #define RR if (MB_SUCCESS != result) return result
-#define SWAP(a,b) {MBEntityHandle tmp_ent = a; a = b; b = tmp_ent;}
+#define SWAP(a,b) {EntityHandle tmp_ent = a; a = b; b = tmp_ent;}
 
 vtkCellPicker *DrawDual::dualPicker = NULL;
 
-MBTag DrawDual::dualCurveTagHandle = 0;
-MBTag DrawDual::dualSurfaceTagHandle = 0;
+Tag DrawDual::dualCurveTagHandle = 0;
+Tag DrawDual::dualSurfaceTagHandle = 0;
 
 DrawDual *DrawDual::gDrawDual = NULL;
-MBRange DrawDual::pickRange;
+Range DrawDual::pickRange;
 
 bool DrawDual::useGraphviz = false;
 
@@ -79,11 +80,11 @@
     : pickLine1(pickline1), pickLine2(pickline2)
 {
     // make sure we have basic tags we need
-  MBErrorCode result = MBI->tag_get_handle(DualTool::DUAL_ENTITY_TAG_NAME, 
+  ErrorCode result = MBI->tag_get_handle(DualTool::DUAL_ENTITY_TAG_NAME, 
                                            dualEntityTagHandle);
   if (MB_TAG_NOT_FOUND == result) {
-    MBEntityHandle dum = 0;
-    result = MBI->tag_create(DualTool::DUAL_ENTITY_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_DENSE,
+    EntityHandle dum = 0;
+    result = MBI->tag_create(DualTool::DUAL_ENTITY_TAG_NAME, sizeof(EntityHandle), MB_TAG_DENSE,
                              dualEntityTagHandle, &dum);
     assert(MB_SUCCESS == result && 0 != dualEntityTagHandle);
   }
@@ -120,16 +121,16 @@
 DrawDual::~DrawDual() 
 {
   if (0 != gvEntityHandle) {
-    MBRange ents;
+    Range ents;
     MBI->get_entities_by_type_and_tag(0, MBVERTEX, &gvEntityHandle,
-                                      NULL, 1, ents, MBInterface::UNION);
+                                      NULL, 1, ents, Interface::UNION);
     MBI->get_entities_by_type_and_tag(0, MBEDGE, &gvEntityHandle,
-                                      NULL, 1, ents, MBInterface::UNION);
+                                      NULL, 1, ents, Interface::UNION);
     MBI->get_entities_by_type_and_tag(0, MBPOLYGON, &gvEntityHandle,
-                                      NULL, 1, ents, MBInterface::UNION);
+                                      NULL, 1, ents, Interface::UNION);
     std::vector<GVEntity*> gvents(ents.size());
     std::fill(gvents.begin(), gvents.end(), (GVEntity*)NULL);
-    MBErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, &gvents[0]);
+    ErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, &gvents[0]);
     if (MB_SUCCESS == result) {
       for (unsigned int i = 0; i < gvents.size(); i++) 
         delete gvents[i];
@@ -208,7 +209,7 @@
                                rwi->GetEventPosition()[1]);
       rwi->StartPickCallback();
       vtkRenderer *ren = style->GetCurrentRenderer();
-      MBEntityHandle dual_surf = gDrawDual->get_dual_surf(ren);
+      EntityHandle dual_surf = gDrawDual->get_dual_surf(ren);
       if (0 == dual_surf) return;
 
       int ix = rwi->GetEventPosition()[0], 
@@ -226,8 +227,8 @@
                   << y << " (world)"
                   << std::endl;
 
-      MBRange picked_ents;
-      MBErrorCode result = gDrawDual->process_pick(dual_surf, 
+      Range picked_ents;
+      ErrorCode result = gDrawDual->process_pick(dual_surf, 
                                                    x, y,
                                                    picked_ents);
       if (MB_SUCCESS != result) return;
@@ -249,7 +250,7 @@
 
 void DrawDual::process_pick(vtkRenderer *ren) 
 {
-  MBRange picked_ents;
+  Range picked_ents;
 
   bool old_picking = false;
   if (old_picking) {
@@ -262,21 +263,21 @@
   
     vtkActor *tmp_actor;
       //vtkActor *picked_actor = NULL;
-      //MBEntityHandle picked_sheet = 0, picked_chord = 0;
+      //EntityHandle picked_sheet = 0, picked_chord = 0;
   
     actors->InitTraversal();
     while ((tmp_actor = actors->GetNextItem())) {
-      MBEntityHandle this_set = vtkMOABUtils::propSetMap[tmp_actor];
+      EntityHandle this_set = vtkMOABUtils::propSetMap[tmp_actor];
       if (0 == this_set || -1 == dualPicker->GetCellId()) continue;
 
         // get whether it's a dual surface or dual curve
-      MBEntityHandle dum_handle = 0;
-      MBErrorCode result = MBI->tag_get_data(dualCurveTagHandle, &this_set, 1, 
+      EntityHandle dum_handle = 0;
+      ErrorCode result = MBI->tag_get_data(dualCurveTagHandle, &this_set, 1, 
                                              &dum_handle);
 
       std::cout << "Picked point " << dualPicker->GetCellId() << std::endl;
     
-      MBEntityHandle picked_ent;
+      EntityHandle picked_ent;
       if (MB_TAG_NOT_FOUND == result || 0 == dum_handle)
           // must be a sheet
         picked_ent = gDrawDual->get_picked_cell(this_set, 2, dualPicker->GetCellId());
@@ -287,10 +288,10 @@
     }
   }
   else {
-    MBEntityHandle dual_surf = gDrawDual->get_dual_surf(ren);
+    EntityHandle dual_surf = gDrawDual->get_dual_surf(ren);
     if (0 == dual_surf) return;
     
-    MBErrorCode result = gDrawDual->process_pick(dual_surf, 
+    ErrorCode result = gDrawDual->process_pick(dual_surf, 
                                                  dualPicker->GetPickPosition()[0], 
                                                  dualPicker->GetPickPosition()[1], 
                                                  picked_ents);
@@ -302,7 +303,7 @@
 
   gDrawDual->print_picked_ents(picked_ents);
   
-//    MBRange::iterator pit = pickRange.find(picked_ent);
+//    Range::iterator pit = pickRange.find(picked_ent);
 //    if (pit == pickRange.end()) pickRange.insert(picked_ent);
 //    else pickRange.erase(pit);
   
@@ -311,19 +312,19 @@
 
 }
 
-void DrawDual::print_picked_ents(MBRange &picked_ents, bool from_return) 
+void DrawDual::print_picked_ents(Range &picked_ents, bool from_return) 
 {
-  for (MBRange::iterator rit = picked_ents.begin(); rit != picked_ents.end(); rit++) {
-    MBEntityHandle picked_ent = *rit;
+  for (Range::iterator rit = picked_ents.begin(); rit != picked_ents.end(); rit++) {
+    EntityHandle picked_ent = *rit;
     
       // get the vertices
     std::ostringstream oss;
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
-    MBErrorCode result = MBI->get_connectivity(picked_ent, connect, num_connect);
+    ErrorCode result = MBI->get_connectivity(picked_ent, connect, num_connect);
     if (MB_SUCCESS != result) return;
     bool first = true;
-    MBEntityHandle primals[20];
+    EntityHandle primals[20];
     std::vector<int> ids;
   
     assert(num_connect < 20);
@@ -335,7 +336,7 @@
     result = MBI->tag_get_data(vtkMOABUtils::globalId_tag(), primals, num_connect, &ids[0]);
     for (int i = 0; i < num_connect; i++) {
       if (!first) oss << "-";
-      MBEntityType this_type = MBI->type_from_handle(primals[i]);
+      EntityType this_type = MBI->type_from_handle(primals[i]);
       if (this_type == MBHEX) oss << "h";
       else if (this_type == MBQUAD) oss << "f";
       else oss << "u";
@@ -371,7 +372,7 @@
 void DrawDual::update_high_polydatas() 
 {
     // go through each graph window and rebuild picked entities
-  std::map<MBEntityHandle, GraphWindows>::iterator mit;
+  std::map<EntityHandle, GraphWindows>::iterator mit;
   for (mit = surfDrawrings.begin(); mit != surfDrawrings.end(); mit++) {
       // reset or initialize
     if (NULL == mit->second.pickActor) {
@@ -388,15 +389,15 @@
   }
 
     // now go through highlight entities, adding to highlight poly in each window
-  MBErrorCode result;
-  std::vector<MBEntityHandle> dual_sets;
-  std::vector<MBEntityHandle>::iterator vit;
+  ErrorCode result;
+  std::vector<EntityHandle> dual_sets;
+  std::vector<EntityHandle>::iterator vit;
   GVEntity **gvents;
   
   result = MBI->tag_get_data(gvEntityHandle, pickRange, &gvents); 
   if (MB_SUCCESS != result) return;
   unsigned int i, j;
-  MBRange::iterator rit;
+  Range::iterator rit;
   vtkIdList *id_list = vtkIdList::New();
   id_list->Allocate(1);
   
@@ -426,13 +427,13 @@
   id_list->FastDelete();
 }
 
-MBEntityHandle DrawDual::get_picked_cell(MBEntityHandle cell_set,
+EntityHandle DrawDual::get_picked_cell(EntityHandle cell_set,
                                          const int dim,
                                          const int picked_cell) 
 {
     // get the cells in the set
-  MBRange cells;
-  MBErrorCode result;
+  Range cells;
+  ErrorCode result;
   if (1 == dim)
     result = vtkMOABUtils::dualTool->get_dual_entities(cell_set, NULL, &cells, NULL, NULL, NULL);
   else if (2 == dim)
@@ -442,17 +443,17 @@
   
   if (MB_SUCCESS != result) return 0;
   
-  MBRange::iterator rit = cells.begin();
+  Range::iterator rit = cells.begin();
   
   for (int i = 0; i < picked_cell; i++, rit++);
   
   return *rit;
 }
 
-bool DrawDual::print_dual_surfs(MBRange &dual_surfs,
+bool DrawDual::print_dual_surfs(Range &dual_surfs,
                                 const bool /*use_offsets*/) 
 {
-  MBErrorCode success = MB_SUCCESS;
+  ErrorCode success = MB_SUCCESS;
   int offset = 0;
 
       // create vtkWindowToImageFilter
@@ -469,7 +470,7 @@
   success = vtkMOABUtils::MBI->tag_get_data(vtkMOABUtils::globalId_tag(), 
                                             dual_surfs, &surf_ids[0]);
   if (MB_SUCCESS != success) return success;
-  MBRange::iterator rit;
+  Range::iterator rit;
   int i;
   
   for (rit = dual_surfs.begin(), i = 0; 
@@ -477,8 +478,8 @@
 
     GraphWindows &this_gw = surfDrawrings[*rit];
 
-    MBEntityHandle dum_handle = 0;
-    MBErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*rit), 1, 
+    EntityHandle dum_handle = 0;
+    ErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*rit), 1, 
                                            &dum_handle);
     if (MB_TAG_NOT_FOUND == tmp_success || dum_handle == 0) continue;
   
@@ -505,14 +506,14 @@
   return (MB_SUCCESS == success ? true : false);
 }
 
-bool DrawDual::draw_dual_surfs(MBRange &dual_surfs,
+bool DrawDual::draw_dual_surfs(Range &dual_surfs,
                                const bool /*use_offsets*/) 
 {
-  MBErrorCode success = MB_SUCCESS;
+  ErrorCode success = MB_SUCCESS;
   int offset = 0;
-  for (MBRange::reverse_iterator rit = dual_surfs.rbegin(); rit != dual_surfs.rend(); rit++) {
-    MBEntityHandle dum_handle = 0;
-    MBErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*rit), 1, 
+  for (Range::reverse_iterator rit = dual_surfs.rbegin(); rit != dual_surfs.rend(); rit++) {
+    EntityHandle dum_handle = 0;
+    ErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*rit), 1, 
                                            &dum_handle);
     if (MB_TAG_NOT_FOUND == tmp_success || dum_handle == 0) continue;
   
@@ -524,15 +525,15 @@
   return (MB_SUCCESS == success ? true : false);
 }
 
-bool DrawDual::draw_dual_surfs(std::vector<MBEntityHandle> &dual_surfs,
+bool DrawDual::draw_dual_surfs(std::vector<EntityHandle> &dual_surfs,
                                const bool /*use_offsets*/) 
 {
-  MBErrorCode success = MB_SUCCESS;
+  ErrorCode success = MB_SUCCESS;
   int offset = 0;
-  for (std::vector<MBEntityHandle>::reverse_iterator vit = dual_surfs.rbegin();
+  for (std::vector<EntityHandle>::reverse_iterator vit = dual_surfs.rbegin();
        vit != dual_surfs.rend(); vit++) {
-    MBEntityHandle dum_handle = 0;
-    MBErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*vit), 1, 
+    EntityHandle dum_handle = 0;
+    ErrorCode tmp_success = MBI->tag_get_data(dualSurfaceTagHandle, &(*vit), 1, 
                                            &dum_handle);
     if (MB_TAG_NOT_FOUND == tmp_success || dum_handle == 0) continue;
   
@@ -544,7 +545,7 @@
   return (MB_SUCCESS == success ? true : false);
 }
 
-MBErrorCode DrawDual::draw_dual_surf(MBEntityHandle dual_surf,
+ErrorCode DrawDual::draw_dual_surf(EntityHandle dual_surf,
                                      int offset_num) 
 {
     // draw this dual surface
@@ -557,15 +558,15 @@
   this_gw.sheetDiagram->show();
 
     // get the cells and vertices on this dual surface
-  MBRange dcells, dedges, dverts, face_verts, loop_edges;
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
+  Range dcells, dedges, dverts, face_verts, loop_edges;
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
                                                    &dverts, &face_verts, &loop_edges);
   if (MB_SUCCESS != result) return result;
 
   if (dcells.empty() || dedges.empty() || dverts.empty()) return MB_FAILURE;
   
     // 1. gather/construct data for graphviz
-  MBErrorCode success = construct_graphviz_data(dual_surf, dcells, dedges, dverts, 
+  ErrorCode success = construct_graphviz_data(dual_surf, dcells, dedges, dverts, 
                                                 face_verts, loop_edges);
   if (MB_SUCCESS != success) return success;
 
@@ -641,19 +642,19 @@
   return success;
 }
 
-MBErrorCode DrawDual::fixup_degen_bchords(MBEntityHandle dual_surf) 
+ErrorCode DrawDual::fixup_degen_bchords(EntityHandle dual_surf) 
 {
     // make sure the mid-pt of degenerate blind chord segments is on the correct
     // side of the other chord it splits
-  MBRange dcells, dedges, dverts, face_verts, loop_edges;
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
+  Range dcells, dedges, dverts, face_verts, loop_edges;
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
                                                    &dverts, &face_verts, &loop_edges); RR;
   
-  MBRange tmp_edges, degen_2cells;
+  Range tmp_edges, degen_2cells;
 
   double avg_pos0[3], avg_pos1[3], dum_pos0[3], dum_pos1[3], dum_pos2[3];
     
-  for (MBRange::iterator rit = dcells.begin(); rit != dcells.end(); rit++) {
+  for (Range::iterator rit = dcells.begin(); rit != dcells.end(); rit++) {
       // first, find if it's degenerate
     tmp_edges.clear();
     result = MBI->get_adjacencies(&(*rit), 1, 1, false, tmp_edges); RR;
@@ -670,21 +671,21 @@
   
   while (!degen_2cells.empty()) {
       // grab the first one off the list
-    MBEntityHandle tcell1 = *degen_2cells.begin();
+    EntityHandle tcell1 = *degen_2cells.begin();
 
       // look for any adjacent degenerate 2cells also on the list
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
-    MBRange adj_2cells;
+    Range adj_2cells;
     result = MBI->get_connectivity(tcell1, connect, num_connect); RR;
     result = MBI->get_adjacencies(connect, num_connect, 2, false, adj_2cells); RR;
     adj_2cells = intersect( degen_2cells, adj_2cells);
     if (!adj_2cells.empty()) degen_2cells = subtract( degen_2cells, adj_2cells);
     
       // ok, have all the adjacent degen 2cells; get the 1cells
-    MBRange adj_1cells;
+    Range adj_1cells;
     result = vtkMOABUtils::mbImpl->get_adjacencies(adj_2cells, 1, false, adj_1cells, 
-                                                   MBInterface::UNION);
+                                                   Interface::UNION);
     if (MB_SUCCESS != result) return result;
 
       // decide whether this sheet is blind or not
@@ -695,13 +696,13 @@
       assert(3 == adj_1cells.size());
         // blind chord intersecting another chord
         // get the middle edge and chord, and the next 2 verts along the chord
-      MBRange dum;
+      Range dum;
       result = MBI->get_adjacencies(adj_2cells, 1, false, dum); RR;
       assert(1 == dum.size());
-      MBEntityHandle middle_edge = *dum.begin();
-      MBEntityHandle chord = vtkMOABUtils::dualTool->get_dual_hyperplane(middle_edge);
+      EntityHandle middle_edge = *dum.begin();
+      EntityHandle chord = vtkMOABUtils::dualTool->get_dual_hyperplane(middle_edge);
       assert(0 != chord);
-      MBEntityHandle verts[2];
+      EntityHandle verts[2];
       result = vtkMOABUtils::dualTool->get_opposite_verts(middle_edge, chord, verts); RR;
 
         // get the gv points for the four vertices
@@ -732,14 +733,14 @@
 
         // now fix the other 2 dedges
       adj_1cells.erase(middle_edge);
-      for (MBRange::iterator rit = adj_1cells.begin(); rit != adj_1cells.end(); rit++) {
+      for (Range::iterator rit = adj_1cells.begin(); rit != adj_1cells.end(); rit++) {
           // get the other 2cell
-        MBRange dum = dcells;
+        Range dum = dcells;
         result = MBI->get_adjacencies(&(*rit), 1, 2, false, dum);
         dum = subtract( dum, adj_2cells);
         assert(1 == dum.size());
           // get the vertices and points of them, and average their positions
-        const MBEntityHandle *connect2;
+        const EntityHandle *connect2;
         result = MBI->get_connectivity(*dum.begin(), connect2, num_connect); RR;
         std::vector<void*> tc_points(num_connect);
         get_graph_points(connect2, num_connect, dual_surf, &tc_points[0]);
@@ -761,7 +762,7 @@
       assert(adj_1cells.size() == 2);
 
         // get vertices making up degen 2cell and their avg position
-      const MBEntityHandle *connect;
+      const EntityHandle *connect;
       result = MBI->get_connectivity(*adj_2cells.begin(), connect, num_connect); RR;
       std::vector<void*> tc_points(num_connect);
       get_graph_points(connect, num_connect, dual_surf, &tc_points[0]);
@@ -773,14 +774,14 @@
 
         // for each 1cell, get the vertices on the adjacent non-degen 2cell 
         // and points of them, and average their positions
-      for (MBRange::iterator rit = adj_1cells.begin(); rit != adj_1cells.end(); rit++) {
+      for (Range::iterator rit = adj_1cells.begin(); rit != adj_1cells.end(); rit++) {
           // get the other 2cell
-        MBRange dum = dcells;
+        Range dum = dcells;
         result = MBI->get_adjacencies(&(*rit), 1, 2, false, dum);
         dum = subtract( dum, adj_2cells);
         assert(1 == dum.size());
           // get the vertices and points of them, and average their positions
-        const MBEntityHandle *connect;
+        const EntityHandle *connect;
         result = MBI->get_connectivity(*dum.begin(), connect, num_connect); RR;
         std::vector<void*> tc_points(num_connect);
         get_graph_points(connect, num_connect, dual_surf, &tc_points[0]);
@@ -801,27 +802,27 @@
         // pillow sheet, right after atomic pillow; just place 1cell mid-pts so
         // we can see them
         // get # chords, since drawing method depends on that
-      MBRange chords;
+      Range chords;
       result = MBI->get_child_meshsets(dual_surf, chords);
       if (MB_SUCCESS != result) return result;
       
       if (2 == chords.size()) {
         
-        const MBEntityHandle *connect;
+        const EntityHandle *connect;
         int num_connect;
         result = MBI->get_connectivity(*adj_1cells.begin(), connect, num_connect); RR;
         void *vert_pts[2], *edge_pts[4];
         get_graph_points(connect, 2, dual_surf, vert_pts);
-        std::vector<MBEntityHandle> edges;
+        std::vector<EntityHandle> edges;
         std::copy(adj_1cells.begin(), adj_1cells.end(), std::back_inserter(edges));
 
           // check that 1cells are in proper order, i.e. they share 2cell with adj 1cell
-        MBRange dum;
+        Range dum;
         result = MBI->get_adjacencies(&edges[0], 2, 2, false, dum); RR;
         dum = intersect( dum, adj_2cells);
         if (dum.empty()) {
             // not adjacent - switch list order
-          MBEntityHandle dum_h = edges[1];
+          EntityHandle dum_h = edges[1];
           edges[1] = edges[2];
           edges[2] = dum_h;
         }
@@ -838,8 +839,8 @@
       }
       else if (3 == chords.size()) {
           // get the middle chord
-        MBEntityHandle middle_chord = 0;
-        for (MBRange::iterator rit = chords.begin(); rit != chords.end(); rit++) {
+        EntityHandle middle_chord = 0;
+        for (Range::iterator rit = chords.begin(); rit != chords.end(); rit++) {
           int num_ents;
           result = MBI->get_number_entities_by_type(*rit, MBEDGE, num_ents);
           if (MB_SUCCESS != result) return result;
@@ -853,13 +854,13 @@
         chords.erase(middle_chord);
 
           // get the edges on each of the non-middle chords
-        std::vector<MBEntityHandle> chord_edges[2];
+        std::vector<EntityHandle> chord_edges[2];
         result = MBI->get_entities_by_handle(*chords.begin(), chord_edges[0]); RR;
         result = MBI->get_entities_by_handle(*chords.rbegin(), chord_edges[1]); RR;
 
           // align them such that chord_edges[0][0] and chord_edges[1][0] do not share a 2cell 
           // on this sheet; arbitrarily choose chord_edges[0][0] to be left-most
-        MBEntityHandle shared_2cell = mtu.common_entity(chord_edges[0][0], chord_edges[1][0], 2);
+        EntityHandle shared_2cell = mtu.common_entity(chord_edges[0][0], chord_edges[1][0], 2);
         if (0 != shared_2cell && vtkMOABUtils::dualTool->get_dual_hyperplane(shared_2cell) == dual_surf) {
           shared_2cell = chord_edges[0][0];
           chord_edges[0][0] = chord_edges[0][1];
@@ -877,9 +878,9 @@
             // get the edge on the middle chord between chord_edges[i][0] and chord_edges[i][1]; that will
             // be the intersection of edges on middle chord and edges adjacent to vertices
             // bounding chord_edges[i][0]
-          MBRange middle_edges;
+          Range middle_edges;
           result = MBI->get_entities_by_handle(middle_chord, middle_edges); RR;
-          const MBEntityHandle *connect;
+          const EntityHandle *connect;
           int num_connect;
           result = MBI->get_connectivity(*chord_edges[i].begin(), connect, num_connect); RR;
           result = MBI->get_adjacencies(connect, num_connect, 1, false, middle_edges); RR;
@@ -920,7 +921,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::get_graphpoint_pos(void *point, double *pos) 
+ErrorCode DrawDual::get_graphpoint_pos(void *point, double *pos) 
 {
   if (useGraphviz) {
     Agnode_t *this_node = (Agnode_t*) point;
@@ -929,15 +930,15 @@
     pos[2] = 0.0;
   }
   else {
-    MBEntityHandle this_node = (MBEntityHandle) point;
-    MBErrorCode result = MBI->get_coords(&this_node, 1, pos);
+    EntityHandle this_node = (EntityHandle) point;
+    ErrorCode result = MBI->get_coords(&this_node, 1, pos);
     if (MB_SUCCESS != result) return result;
   }
 
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::set_graphpoint_pos(void *point, double *pos) 
+ErrorCode DrawDual::set_graphpoint_pos(void *point, double *pos) 
 {
   if (useGraphviz) {
     Agnode_t *this_node = (Agnode_t*) point;
@@ -946,26 +947,26 @@
   }
   else {
     pos[2] = 0.0;
-    MBEntityHandle this_node = (MBEntityHandle) point;
-    MBErrorCode result = MBI->set_coords(&this_node, 1, pos);
+    EntityHandle this_node = (EntityHandle) point;
+    ErrorCode result = MBI->set_coords(&this_node, 1, pos);
     if (MB_SUCCESS != result) return result;
   }
 
   return MB_SUCCESS;
 }
  
-MBErrorCode DrawDual::make_vtk_data(MBEntityHandle dual_surf,
+ErrorCode DrawDual::make_vtk_data(EntityHandle dual_surf,
                                     vtkPolyData *pd,
                                     vtkRenderer *this_ren)
 {
     // get the cells and vertices on this dual surface
-  MBRange dcells, dverts, dverts_loop, dedges, dedges_loop;
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
+  Range dcells, dverts, dverts_loop, dedges, dedges_loop;
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, &dedges, 
                                                    &dverts, &dverts_loop, &dedges_loop);
   if (MB_SUCCESS != result) return result;
 
     // get the GVEntity for each entity
-  std::map<MBEntityHandle, GVEntity *> vert_gv_map;
+  std::map<EntityHandle, GVEntity *> vert_gv_map;
   
     // allocate cells and points; start by getting the point and cell arrays
   result = allocate_points(dual_surf, pd, dverts, dedges, vert_gv_map);
@@ -995,20 +996,20 @@
   color_ids->FastDelete();
 
     // make the 1d cells chord by chord
-  std::vector<MBEntityHandle> chords;
+  std::vector<EntityHandle> chords;
   result = MBI->get_child_meshsets(dual_surf, chords);
   if (MB_SUCCESS != result) return result;
 
-  for (std::vector<MBEntityHandle>::iterator vit = chords.begin();
+  for (std::vector<EntityHandle>::iterator vit = chords.begin();
        vit != chords.end(); vit++) {
       // set color of chord to other sheet's color
-    MBEntityHandle color_set = other_sheet(*vit, dual_surf);
+    EntityHandle color_set = other_sheet(*vit, dual_surf);
     result = vtkMOABUtils::MBI->tag_get_data(vtkMOABUtils::globalId_tag(), &color_set,
                                              1, &global_id);
     if (MB_SUCCESS != result) return result;
 
       // get edges in this chord
-    MBRange dedges;
+    Range dedges;
     result = vtkMOABUtils::dualTool->get_dual_entities(*vit, NULL, &dedges, NULL, NULL, NULL);
     if (MB_SUCCESS != result) return result;
     
@@ -1039,24 +1040,24 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::make_vtk_cells(const MBRange &cell_range, const int dim,
+ErrorCode DrawDual::make_vtk_cells(const Range &cell_range, const int dim,
                                      const float color_index,
-                                     const MBEntityHandle dual_surf,
-                                     std::map<MBEntityHandle, GVEntity *> &vert_gv_map,
+                                     const EntityHandle dual_surf,
+                                     std::map<EntityHandle, GVEntity *> &vert_gv_map,
                                      vtkPolyData *pd,
                                      vtkFloatArray *color_ids) 
 {
-  std::vector<MBEntityHandle> cell_verts;
+  std::vector<EntityHandle> cell_verts;
   std::vector<GVEntity *> gv_cells(cell_range.size());
   int cell_num;
-  MBRange::iterator rit;
+  Range::iterator rit;
   vtkIdType cell_points[20];
   static int vtk_cell_type[] = {VTK_VERTEX, VTK_LINE, VTK_POLYGON};
 
-  MBErrorCode result = MBI->tag_get_data(gvEntityHandle, cell_range, &gv_cells[0]);
+  ErrorCode result = MBI->tag_get_data(gvEntityHandle, cell_range, &gv_cells[0]);
   if (MB_SUCCESS != result) return result;
 
-  MBRange cell_edges, shared_edges, tmp_verts;
+  Range cell_edges, shared_edges, tmp_verts;
   for (rit = cell_range.begin(), cell_num = 0; 
        rit != cell_range.end(); rit++, cell_num++) {
       // get the vertices in this cell; must be done through vector for polygons
@@ -1092,7 +1093,7 @@
         assert(!shared_edges.empty());
           // get the mid-pt of this edge and include in list; if we're inside a 2-edge
           // cell and we're on the 2nd vertex, take the 2nd edge
-        MBEntityHandle this_edge = *shared_edges.begin();
+        EntityHandle this_edge = *shared_edges.begin();
         if (cell_verts.size() == 2 && i != 0) this_edge = *shared_edges.rbegin();
         this_gv = vert_gv_map[this_edge];
         assert(this_gv != NULL);
@@ -1133,11 +1134,11 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::allocate_points(MBEntityHandle dual_surf,
+ErrorCode DrawDual::allocate_points(EntityHandle dual_surf,
                                       vtkPolyData *pd,
-                                      MBRange &verts,
-                                      MBRange &edges,
-                                      std::map<MBEntityHandle, GVEntity*> &vert_gv_map) 
+                                      Range &verts,
+                                      Range &edges,
+                                      std::map<EntityHandle, GVEntity*> &vert_gv_map) 
 {
   vtkPoints *points = pd->GetPoints();
   if (NULL == points) {
@@ -1151,14 +1152,14 @@
   gv_verts.resize(verts.size());
   
     // get the gventities
-  MBErrorCode result = MBI->tag_get_data(gvEntityHandle, verts, &gv_verts[0]);
+  ErrorCode result = MBI->tag_get_data(gvEntityHandle, verts, &gv_verts[0]);
   if (MB_SUCCESS != result) {
     std::cout << "Couldn't get gv vertex data." << std::endl;
     return result;
   }
 
   unsigned int i;
-  MBRange::iterator rit;
+  Range::iterator rit;
   char dum_str[80];
   Agsym_t *asym_pos = (useGraphviz ? get_asym(dual_surf, 0, "pos") : NULL);
   double dum_pos[3];
@@ -1217,15 +1218,15 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::get_xform(MBEntityHandle dual_surf, Agsym_t *asym_pos, 
+ErrorCode DrawDual::get_xform(EntityHandle dual_surf, Agsym_t *asym_pos, 
                                 double &x_xform, double &y_xform)
 {
-  MBRange face_verts, face_verts_dum;
+  Range face_verts, face_verts_dum;
 
   x_xform = y_xform = 1.0;
   return MB_SUCCESS;
 
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, NULL, NULL, 
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, NULL, NULL, 
                                                    &face_verts_dum, &face_verts, NULL);
   if (MB_SUCCESS != result) return result;
   
@@ -1278,12 +1279,12 @@
   return vtkPolyData::SafeDownCast(acoll->GetNextActor()->GetMapper()->GetInput());
 }
 
-void DrawDual::get_clean_pd(MBEntityHandle dual_surf,
+void DrawDual::get_clean_pd(EntityHandle dual_surf,
                             SheetDiagramPopup *&this_sdpopup,
                             vtkPolyData *&pd)
 {
   if (NULL != this_sdpopup) {
-    MBErrorCode result = reset_drawing_data(dual_surf);
+    ErrorCode result = reset_drawing_data(dual_surf);
     if (MB_SUCCESS != result) {
       std::cerr << "Trouble resetting drawing data for sheet." << std::endl;
     }
@@ -1398,10 +1399,10 @@
   pd->Initialize();
 }
 
-MBErrorCode DrawDual::construct_graphviz_data(MBEntityHandle dual_surf,
-                                              MBRange &dcells, MBRange &dedges,
-                                              MBRange &dverts, MBRange &face_verts,
-                                              MBRange &loop_edges) 
+ErrorCode DrawDual::construct_graphviz_data(EntityHandle dual_surf,
+                                              Range &dcells, Range &dedges,
+                                              Range &dverts, Range &face_verts,
+                                              Range &loop_edges) 
 {
     // gather/construct the data for graphviz
 
@@ -1418,7 +1419,7 @@
     // for each vertex, allocate a graphviz point if it doesn't already have one
   Agsym_t *asym_pos = (useGraphviz ? get_asym(dual_surf, 0, "pos") : NULL);
 
-  MBErrorCode result = construct_graphviz_points(dual_surf, dverts, asym_pos); RR;
+  ErrorCode result = construct_graphviz_points(dual_surf, dverts, asym_pos); RR;
   
     // for each edge, allocate a graphviz edge if it doesn't already have one
   result = construct_graphviz_edges(dual_surf, dedges, face_verts, asym_pos); RR;
@@ -1426,14 +1427,14 @@
   return result;
 }
 
-MBErrorCode DrawDual::construct_graphviz_edges(MBEntityHandle dual_surf, 
-                                               MBRange &dedges, 
-                                               MBRange &loop_verts, 
+ErrorCode DrawDual::construct_graphviz_edges(EntityHandle dual_surf, 
+                                               Range &dedges, 
+                                               Range &loop_verts, 
                                                Agsym_t *asym_pos) 
 {
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   char dum_str[80];
   GraphWindows &this_gw = surfDrawrings[dual_surf];
     //Agsym_t *asym_weight = (useGraphviz ? get_asym(dual_surf, 1, "weight") : NULL), 
@@ -1442,7 +1443,7 @@
   result = MBI->tag_get_data(gvEntityHandle, dedges, &dedge_gv[0]); RR;
   GVEntity *dvert_gv[2];
  
-  MBRange::iterator rit;
+  Range::iterator rit;
   int i;
   for (rit = dedges.begin(), i = 0; rit != dedges.end(); rit++, i++) {
 
@@ -1476,7 +1477,7 @@
       sprintf(dum_str, "%d", (int)*rit);
 
         // first, check to see if it's degenerate; if so, add a mid-pt
-      MBRange tmp_edges;
+      Range tmp_edges;
       result = MBI->get_adjacencies(connect, 2, 1, false, tmp_edges);
       if (MB_SUCCESS == result && tmp_edges.size() > 1) {
         if (useGraphviz) {
@@ -1498,22 +1499,22 @@
         else {
             // add a vertex for the edge
           sprintf(dum_str, "%up", (unsigned int) MBI->id_from_handle(*rit));
-          MBEntityHandle mid_vert, edge1, edge2, edge_verts[2];
+          EntityHandle mid_vert, edge1, edge2, edge_verts[2];
           double dum_pos[] = {CENT_X, CENT_Y, 0.0};
           result = MBI->create_vertex(dum_pos, mid_vert);
           if (MB_SUCCESS != result) return result;
           this_gv->gvizPoints[dsindex] = (void*)mid_vert;
       
-          edge_verts[0] = (MBEntityHandle) dvert_gv[0]->gvizPoints[index0];
-          edge_verts[1] = (MBEntityHandle) mid_vert;
+          edge_verts[0] = (EntityHandle) dvert_gv[0]->gvizPoints[index0];
+          edge_verts[1] = (EntityHandle) mid_vert;
           result = MBI->create_element(MBEDGE, edge_verts, 2, edge1);
           if (MB_SUCCESS != result) return result;
           this_gv->gvizEdges[dsindex] = (void*)edge1;
           result = MBI->tag_set_data(dualCurveTagHandle, &edge1, 1, &(*rit));
           if (MB_SUCCESS != result) return result;
         
-          edge_verts[0] = (MBEntityHandle) mid_vert;
-          edge_verts[1] = (MBEntityHandle) dvert_gv[1]->gvizPoints[index1];
+          edge_verts[0] = (EntityHandle) mid_vert;
+          edge_verts[1] = (EntityHandle) dvert_gv[1]->gvizPoints[index1];
           result = MBI->create_element(MBEDGE, edge_verts, 2, edge2);
           if (MB_SUCCESS != result) return result;
           this_gv->gvizEdges[dsindex+2] = (void*)edge2;
@@ -1529,9 +1530,9 @@
           this_gv->gvizEdges[dsindex] = this_gved;
         }
         else {
-          MBEntityHandle edge_verts[2], edge1;
-          edge_verts[0] = (MBEntityHandle) dvert_gv[0]->gvizPoints[index0];
-          edge_verts[1] = (MBEntityHandle) dvert_gv[1]->gvizPoints[index1];
+          EntityHandle edge_verts[2], edge1;
+          edge_verts[0] = (EntityHandle) dvert_gv[0]->gvizPoints[index0];
+          edge_verts[1] = (EntityHandle) dvert_gv[1]->gvizPoints[index1];
           result = MBI->create_element(MBEDGE, edge_verts, 2, edge1);
           if (MB_SUCCESS != result) return result;
           this_gv->gvizEdges[dsindex] = (void*) edge1;
@@ -1542,7 +1543,7 @@
 
         // check to see if it's an interior edge connected to the loop, and
         // adjust its weight and length if so
-      MBRange::iterator firstv = loop_verts.find(connect[0]),
+      Range::iterator firstv = loop_verts.find(connect[0]),
         lastv = loop_verts.find(connect[1]),
         endloop = loop_verts.end();
       if ((firstv == endloop && lastv != endloop) ||
@@ -1559,13 +1560,13 @@
   return result;
 }
 
-MBErrorCode DrawDual::construct_graphviz_points(MBEntityHandle dual_surf, 
-                                                MBRange &dverts, 
+ErrorCode DrawDual::construct_graphviz_points(EntityHandle dual_surf, 
+                                                Range &dverts, 
                                                 Agsym_t *asym_pos) 
 {
-  MBRange::iterator rit;
+  Range::iterator rit;
   int i;
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   GraphWindows &this_gw = surfDrawrings[dual_surf];
   char dum_str[80];
   std::vector<GVEntity*> dvert_gv(dverts.size());
@@ -1597,7 +1598,7 @@
       }
       else {
           // use an MBVertex instead
-        MBEntityHandle new_vertex;
+        EntityHandle new_vertex;
         double dum_pos[] = {CENT_X, CENT_Y, 0.0};
         result = MBI->create_vertex(dum_pos, new_vertex);
         if (MB_SUCCESS != result) return result;
@@ -1611,7 +1612,7 @@
   return result;
 }
 
-Agsym_t *DrawDual::get_asym(MBEntityHandle dual_surf, const int dim,
+Agsym_t *DrawDual::get_asym(EntityHandle dual_surf, const int dim,
                             const char *name, const char *def_val) 
 {
   Agsym_t *asym = NULL;
@@ -1641,18 +1642,18 @@
   return asym;
 }
 
-MBErrorCode DrawDual::compute_fixed_points(MBEntityHandle dual_surf, MBRange &dverts,
-                                           MBRange &face_verts, MBRange &loop_edges) 
+ErrorCode DrawDual::compute_fixed_points(EntityHandle dual_surf, Range &dverts,
+                                           Range &face_verts, Range &loop_edges) 
 {
-  std::vector<std::vector<MBEntityHandle> > loops;
-  MBRange new_face_verts(face_verts);
+  std::vector<std::vector<EntityHandle> > loops;
+  Range new_face_verts(face_verts);
 
   while (!new_face_verts.empty()) {
       // get the next first vertex on the loop
-    MBEntityHandle this_v = *new_face_verts.begin();
-    MBEntityHandle first_v = 0, last_v = 0;
-    std::vector<MBEntityHandle> loop_vs;
-    MBRange temp_face_verts;
+    EntityHandle this_v = *new_face_verts.begin();
+    EntityHandle first_v = 0, last_v = 0;
+    std::vector<EntityHandle> loop_vs;
+    Range temp_face_verts;
 
     if (new_face_verts.size() == 2) {
         // quick way to do this, assuming both vertices are on the loop
@@ -1669,7 +1670,7 @@
         // put this vertex on the loop, then get the next one
       loop_vs.push_back(this_v);
       temp_face_verts.insert(this_v);
-      MBEntityHandle temp_v = this_v;
+      EntityHandle temp_v = this_v;
       this_v = vtkMOABUtils::dualTool->next_loop_vertex(last_v, this_v, dual_surf);
       assert(0 != this_v);
       last_v = temp_v;
@@ -1679,7 +1680,7 @@
     loops.push_back(loop_vs);
     
       // ok, we've got them all; first, remove them from face_verts
-    MBRange temp_range = subtract( new_face_verts, temp_face_verts);
+    Range temp_range = subtract( new_face_verts, temp_face_verts);
     new_face_verts.swap(temp_range);
   }
   
@@ -1695,7 +1696,7 @@
   
   char tmp_pos[80];
   int loop_num, num_loops = loops.size();
-  std::vector<std::vector<MBEntityHandle> >::iterator mit;
+  std::vector<std::vector<EntityHandle> >::iterator mit;
   if (my_debug) std::cout << "Loop points: " << std::endl;
   for (mit = loops.begin(), loop_num = 0; mit != loops.end(); mit++, loop_num++) {
 
@@ -1714,7 +1715,7 @@
 
         // now set that position on the node
       GVEntity *this_gv;
-      MBErrorCode result = MBI->tag_get_data(gvEntityHandle, &((*mit)[i]), 1, &this_gv); RR;
+      ErrorCode result = MBI->tag_get_data(gvEntityHandle, &((*mit)[i]), 1, &this_gv); RR;
       
       int index = this_gv->get_index(dual_surf);
       assert(index >= 0);
@@ -1733,7 +1734,7 @@
         ND_pinned(this_gpt) = true;
       }
       else {
-        MBEntityHandle this_vert = (MBEntityHandle) this_gv->gvizPoints[index];
+        EntityHandle this_vert = (EntityHandle) this_gv->gvizPoints[index];
         double dum_pos[] = {xpos_pts, ypos_pts, 0.0};
         result = MBI->set_coords(&this_vert, 1, dum_pos);
         if (MB_SUCCESS != result) return result;
@@ -1749,9 +1750,9 @@
 
       int offset = 0;
         // put one at pi/2, the other at 3pi/2
-      for (MBRange::iterator rit = loop_edges.begin(); rit != loop_edges.end(); rit++) {
+      for (Range::iterator rit = loop_edges.begin(); rit != loop_edges.end(); rit++) {
         GVEntity *this_gv;
-        MBErrorCode result = MBI->tag_get_data(gvEntityHandle, &(*rit), 1, &this_gv);
+        ErrorCode result = MBI->tag_get_data(gvEntityHandle, &(*rit), 1, &this_gv);
         if (MB_SUCCESS != result) continue;
         int index = this_gv->get_index(dual_surf);
         assert(index >= 0 && this_gv->gvizPoints[index] != NULL);
@@ -1769,7 +1770,7 @@
           ND_pinned(this_gpt) = true;
         }
         else {
-          MBEntityHandle this_vert = (MBEntityHandle) this_gv->gvizPoints[index];
+          EntityHandle this_vert = (EntityHandle) this_gv->gvizPoints[index];
           double dum_pos[] = {xpos_pts, ypos_pts, 0.0};
           result = MBI->set_coords(&this_vert, 1, dum_pos);
           if (MB_SUCCESS != result) return result;
@@ -1785,14 +1786,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::compute_pillow_fixed_points(MBEntityHandle dual_surf, 
-                                                  MBRange &face_verts, 
-                                                  MBRange &face_edges) 
+ErrorCode DrawDual::compute_pillow_fixed_points(EntityHandle dual_surf, 
+                                                  Range &face_verts, 
+                                                  Range &face_edges) 
 {
     // find the points we'll call fixed for this sheet
     // first, get the chords, in an ordered list
-  std::vector<MBEntityHandle> chords;
-  MBErrorCode result = MBI->get_child_meshsets(dual_surf, chords);
+  std::vector<EntityHandle> chords;
+  ErrorCode result = MBI->get_child_meshsets(dual_surf, chords);
   if (MB_SUCCESS != result) return result;
 
     // if there are only two, don't bother, they'll get fixed up later
@@ -1800,17 +1801,17 @@
   
     // if more, get the first two vertices on the first chord, then a 3rd
     // from another that's not in the 1st set
-  MBRange tmp_range;
+  Range tmp_range;
   result = MBI->get_entities_by_dimension(chords[0], 1, tmp_range); RR;
-  const MBEntityHandle *connect;
+  const EntityHandle *connect;
   int num_connect;
   result = MBI->get_connectivity(*tmp_range.begin(), connect, num_connect); RR;
   face_verts.insert(connect[0]);
   face_verts.insert(connect[1]);
   tmp_range.clear();
-  MBRange tmp_verts;
+  Range tmp_verts;
   result = MBI->get_entities_by_dimension(chords[1], 1, tmp_range); RR;
-  result = MBI->get_adjacencies(tmp_range, 0, false, tmp_verts, MBInterface::UNION); RR;
+  result = MBI->get_adjacencies(tmp_range, 0, false, tmp_verts, Interface::UNION); RR;
   tmp_verts = subtract( tmp_verts, face_verts);
   assert(!tmp_verts.empty());
   face_verts.insert(*tmp_verts.begin());
@@ -1826,7 +1827,7 @@
   dum_pos[7] = dum_pos[4];
   dum_pos[2] = dum_pos[5] = dum_pos[8] = 0.0;
 
-  std::vector<MBEntityHandle> graph_points(face_verts.size());
+  std::vector<EntityHandle> graph_points(face_verts.size());
   get_graph_points(face_verts, dual_surf, (void**) &graph_points[0]);
   result = MBI->set_coords(&graph_points[0], face_verts.size(), dum_pos); RR;
   
@@ -1857,7 +1858,7 @@
   ypos_pts += CENT_Y;
 }
 
-MBErrorCode DrawDual::draw_labels(MBEntityHandle dual_surf, vtkPolyData *pd,
+ErrorCode DrawDual::draw_labels(EntityHandle dual_surf, vtkPolyData *pd,
                                   vtkPolyData *new_pd) 
 {
     // get the renderer you'll be writing the text to
@@ -1868,7 +1869,7 @@
     // sheet id first
   char set_name[CATEGORY_TAG_SIZE];
   int dum;
-  MBErrorCode result = vtkMOABUtils::MBI->tag_get_data(vtkMOABUtils::globalId_tag(),
+  ErrorCode result = vtkMOABUtils::MBI->tag_get_data(vtkMOABUtils::globalId_tag(),
                                                        &dual_surf, 1, &dum);
   if (MB_SUCCESS != result) return result;
   sprintf(set_name, "%d\n", dum);
@@ -1911,14 +1912,14 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::label_other_sheets(MBEntityHandle dual_surf,
+ErrorCode DrawDual::label_other_sheets(EntityHandle dual_surf,
                                          vtkPolyData *pd,
                                          vtkPolyData *&new_pd) 
 {
     // gather the chord sets
-  std::vector<MBEntityHandle> chords, chord_surfs;
-  MBRange dedges, dverts, dverts_loop;
-  MBErrorCode result = MBI->get_child_meshsets(dual_surf, chords);
+  std::vector<EntityHandle> chords, chord_surfs;
+  Range dedges, dverts, dverts_loop;
+  ErrorCode result = MBI->get_child_meshsets(dual_surf, chords);
   if (MB_SUCCESS != result || 0 == chords.size()) return result;
 
     // start a new polydata with points for labeling
@@ -1934,15 +1935,15 @@
   id_array->SetName("LoopVertexIds");
 
     // for each chord:
-  MBErrorCode tmp_result;
-  std::vector<MBEntityHandle>::iterator vit1;
-  MBRange::iterator rit;
+  ErrorCode tmp_result;
+  std::vector<EntityHandle>::iterator vit1;
+  Range::iterator rit;
   std::vector<GVEntity*> gv_edges;
   for (vit1 = chords.begin(); vit1 != chords.end(); vit1++) {
 
       // get a color for this chord; make it the color of the "other" sheet, unless
       // it's this sheet, in which case it's black
-    MBEntityHandle color_set = other_sheet(*vit1, dual_surf);
+    EntityHandle color_set = other_sheet(*vit1, dual_surf);
     double red, green, blue;
     int global_id;
     if (0 == color_set) red = green = blue = 0.0;
@@ -1968,7 +1969,7 @@
     
     int edge_vtk_vs[2];
     GVEntity *gv_verts[2];
-    const MBEntityHandle *edge_vs;
+    const EntityHandle *edge_vs;
     int num_edge_vs;
     int edge_num;
     int index;
@@ -2009,7 +2010,7 @@
   return result;
 }
 
-void DrawDual::label_interior_verts(MBEntityHandle dual_surf,
+void DrawDual::label_interior_verts(EntityHandle dual_surf,
                                     vtkPolyData *pd,
                                     vtkRenderer *ren) 
 {
@@ -2018,9 +2019,9 @@
     // in vtk to extract just vertices, so we label all the vertices here
     // 
     // get the cells and vertices on this dual surface
-  MBRange dcells, dverts, face_verts;
+  Range dcells, dverts, face_verts;
 
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, NULL, 
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, &dcells, NULL, 
                                                    &dverts, &face_verts, NULL);
   if (MB_SUCCESS != result) return;
   
@@ -2088,12 +2089,12 @@
   lda->FastDelete();
 }
 
-MBEntityHandle DrawDual::other_sheet(const MBEntityHandle this_chord,
-                                     const MBEntityHandle dual_surf) 
+EntityHandle DrawDual::other_sheet(const EntityHandle this_chord,
+                                     const EntityHandle dual_surf) 
 {
-  static std::vector<MBEntityHandle> chord_surfs;
-  MBEntityHandle val = dual_surf;
-  MBErrorCode result = MBI->get_parent_meshsets(this_chord, chord_surfs);
+  static std::vector<EntityHandle> chord_surfs;
+  EntityHandle val = dual_surf;
+  ErrorCode result = MBI->get_parent_meshsets(this_chord, chord_surfs);
   if (MB_SUCCESS == result && !chord_surfs.empty()) {
     if (chord_surfs[0] != dual_surf) val = chord_surfs[0];
     else if (chord_surfs.size() > 1 && chord_surfs[1] != dual_surf)
@@ -2106,13 +2107,13 @@
   return val;
 }
 
-MBErrorCode DrawDual::get_primal_ids(const MBRange &ents, std::vector<int> &ids)
+ErrorCode DrawDual::get_primal_ids(const Range &ents, std::vector<int> &ids)
 {
     // get the ids of these verts, equal to entity ids of their primal entities
-  static std::vector<MBEntityHandle> primals;
+  static std::vector<EntityHandle> primals;
   primals.resize(ents.size());
   ids.resize(ents.size());
-  MBErrorCode result = MBI->tag_get_data(dualEntityTagHandle, ents, &primals[0]);
+  ErrorCode result = MBI->tag_get_data(dualEntityTagHandle, ents, &primals[0]);
   if (MB_SUCCESS != result) {
     for (unsigned int i = 0; i < ents.size(); i++) ids[i] = 0;
   }
@@ -2129,10 +2130,10 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::reset_drawn_sheets(MBRange *drawn_sheets) 
+ErrorCode DrawDual::reset_drawn_sheets(Range *drawn_sheets) 
 {
-  MBErrorCode result = MB_SUCCESS, tmp_result;
-  for (std::map<MBEntityHandle,GraphWindows>::iterator mit = surfDrawrings.begin();
+  ErrorCode result = MB_SUCCESS, tmp_result;
+  for (std::map<EntityHandle,GraphWindows>::iterator mit = surfDrawrings.begin();
        mit != surfDrawrings.end(); mit++) {
     if (NULL != drawn_sheets &&
         NULL != (*mit).second.sheetDiagram) 
@@ -2144,9 +2145,9 @@
   return tmp_result;
 }
 
-MBErrorCode DrawDual::GraphWindows::reset(MBEntityHandle dual_surf) 
+ErrorCode DrawDual::GraphWindows::reset(EntityHandle dual_surf) 
 {
-  MBErrorCode result = MB_SUCCESS;
+  ErrorCode result = MB_SUCCESS;
   
   if (sheetDiagram) {
     result = gDrawDual->reset_drawing_data(dual_surf);
@@ -2162,7 +2163,7 @@
   return result;
 }
 
-MBErrorCode DrawDual::reset_drawing_data(MBEntityHandle dual_surf) 
+ErrorCode DrawDual::reset_drawing_data(EntityHandle dual_surf) 
 {
     // deleting a sheet drawing; reset the data on moab tags so it'll draw right
     // next time
@@ -2177,11 +2178,11 @@
   assert(NULL != acoll);
   acoll->InitTraversal();
   vtkActor *tmp_actor;
-  MBRange saved_sets;
+  Range saved_sets;
 
     // get all actors, check sets in propSetMap; save set, remove actor from map
   while ((tmp_actor = acoll->GetNextItem())) {
-    std::map<vtkProp*,MBEntityHandle>::iterator mit = 
+    std::map<vtkProp*,EntityHandle>::iterator mit = 
       vtkMOABUtils::propSetMap.find(tmp_actor);
     if (mit == vtkMOABUtils::propSetMap.end()) continue;
     saved_sets.insert((*mit).second);
@@ -2190,16 +2191,16 @@
   
     // for dual surface set:
     // get 0-, 1-, 2-cells, GVEntity for each
-  MBRange tcells, all_cells;
-  MBErrorCode result = MBI->get_entities_by_type(dual_surf, MBPOLYGON,
+  Range tcells, all_cells;
+  ErrorCode result = MBI->get_entities_by_type(dual_surf, MBPOLYGON,
                                                  tcells);
   if (MB_SUCCESS != result) return result;
-  result = MBI->get_adjacencies(tcells, 0, false, all_cells, MBInterface::UNION);
+  result = MBI->get_adjacencies(tcells, 0, false, all_cells, Interface::UNION);
   if (MB_SUCCESS != result) return result;
-  result = MBI->get_adjacencies(tcells, 1, false, all_cells, MBInterface::UNION);
+  result = MBI->get_adjacencies(tcells, 1, false, all_cells, Interface::UNION);
   if (MB_SUCCESS != result) return result;
   
-  for (MBRange::const_reverse_iterator rit = all_cells.rbegin(); rit != all_cells.rend(); rit++) {
+  for (Range::const_reverse_iterator rit = all_cells.rbegin(); rit != all_cells.rend(); rit++) {
       // get the GVEntity
     GVEntity *gv_ent;
     result = MBI->tag_get_data(gvEntityHandle, &(*rit), 1, &gv_ent);
@@ -2238,7 +2239,7 @@
       if (useGraphviz)
         free(gvizPoints[index]);
       else 
-        MBI->delete_entities((MBEntityHandle*)&gvizPoints[index], 1);
+        MBI->delete_entities((EntityHandle*)&gvizPoints[index], 1);
       gvizPoints[index] = NULL;
     }
   }
@@ -2250,7 +2251,7 @@
         free(gvizEdges[index]);
       else {
         assert(gvizEdges[index]);
-        MBI->delete_entities((MBEntityHandle*)&gvizEdges[index], 1);
+        MBI->delete_entities((EntityHandle*)&gvizEdges[index], 1);
       }
       gvizEdges[index] = NULL;
     }
@@ -2261,9 +2262,9 @@
       }
       else {
         assert(gvizEdges[index+2]);
-        MBI->delete_entities((MBEntityHandle*)&gvizEdges[index+2], 1);
+        MBI->delete_entities((EntityHandle*)&gvizEdges[index+2], 1);
         if (gvizPoints[index])
-          MBI->delete_entities((MBEntityHandle*)&gvizPoints[index], 1);
+          MBI->delete_entities((EntityHandle*)&gvizPoints[index], 1);
       }
       gvizEdges[index+2] = NULL;
       gvizPoints[index] = NULL;
@@ -2273,11 +2274,11 @@
   myActors[index] = NULL;
 }
   
-void DrawDual::get_graph_points(const MBEntityHandle *ents, const int num_ents, 
-                                MBEntityHandle dual_surf, void **points) 
+void DrawDual::get_graph_points(const EntityHandle *ents, const int num_ents, 
+                                EntityHandle dual_surf, void **points) 
 {
   std::vector<GVEntity *> gvs(num_ents);
-  MBErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, num_ents, &gvs[0]);
+  ErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, num_ents, &gvs[0]);
   if (MB_SUCCESS != result) return;
   
   for (int i = 0; i < num_ents; i++) {
@@ -2288,11 +2289,11 @@
   }
 }
 
-void DrawDual::get_graph_points(MBRange ents,
-                                MBEntityHandle dual_surf, void **points) 
+void DrawDual::get_graph_points(Range ents,
+                                EntityHandle dual_surf, void **points) 
 {
   std::vector<GVEntity *> gvs(ents.size());
-  MBErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, &gvs[0]);
+  ErrorCode result = MBI->tag_get_data(gvEntityHandle, ents, &gvs[0]);
   if (MB_SUCCESS != result) return;
   
   for (unsigned int i = 0; i < ents.size(); i++) {
@@ -2302,15 +2303,15 @@
   }
 }
 
-MBErrorCode DrawDual::smooth_dual_surf(MBEntityHandle dual_surf, 
-                                       MBRange &dcells,
-                                       MBRange &dedges, MBRange &dverts,
-                                       MBRange &face_verts, MBRange &loop_edges) 
+ErrorCode DrawDual::smooth_dual_surf(EntityHandle dual_surf, 
+                                       Range &dcells,
+                                       Range &dedges, Range &dverts,
+                                       Range &face_verts, Range &loop_edges) 
 {
     // compute the starting positions of the boundary points, and fix them;
     // has to come after construct_graphviz_edges 'cuz we need edge gventities for 2-pt loops
     // copy face_verts 'cuz compute_fixed_points may add face verts for pillow sheets
-  MBErrorCode result = compute_fixed_points(dual_surf, dverts, 
+  ErrorCode result = compute_fixed_points(dual_surf, dverts, 
                                             face_verts, loop_edges); RR;
 
   const int num_its = 10;
@@ -2319,25 +2320,25 @@
   double tmp_coords[12];
   MeshTopoUtil mtu(vtkMOABUtils::mbImpl);
 
-  std::vector<MBEntityHandle> graph_points(dverts.size());
+  std::vector<EntityHandle> graph_points(dverts.size());
   get_graph_points(dverts, dual_surf, (void**) &graph_points[0]);
 
     // get any edge-adjacent points which are valence-2 and add to list of
     // smooth points; these are edge mid-pts, which should be smoothed so they
     // don't remain at the center
   for (unsigned int j = 0; j < dverts.size(); j++) {
-      MBEntityHandle this_point = graph_points[j];
+      EntityHandle this_point = graph_points[j];
       
         // get all neighbor verts
-      MBRange nverts, tmp_edges;
+      Range nverts, tmp_edges;
       result = mtu.get_bridge_adjacencies(this_point, 1, 0, nverts); RR;
       if (!(4 == nverts.size() || 3 == nverts.size())) {
         std::cerr << "Smoothing sheet failed; dumping file." << std::endl;
         vtkMOABUtils::dualTool->delete_whole_dual();
-        MBEntityHandle save_set;
-        MBErrorCode result = vtkMOABUtils::mbImpl->create_meshset(MESHSET_SET, save_set);
+        EntityHandle save_set;
+        ErrorCode result = vtkMOABUtils::mbImpl->create_meshset(MESHSET_SET, save_set);
         if (MB_SUCCESS != result) return MB_FAILURE;
-        MBRange hexes;
+        Range hexes;
         result = vtkMOABUtils::mbImpl->get_entities_by_type(0, MBHEX, hexes);
         if (MB_SUCCESS != result) return MB_FAILURE;
         result = vtkMOABUtils::mbImpl->add_entities(save_set, hexes);
@@ -2346,7 +2347,7 @@
         return MB_FAILURE;
       }
       
-      for (MBRange::iterator rit = nverts.begin(); rit != nverts.end(); rit++) {
+      for (Range::iterator rit = nverts.begin(); rit != nverts.end(); rit++) {
         tmp_edges.clear();
         result = MBI->get_adjacencies(&(*rit), 1, 1, false, tmp_edges); RR;
         if (2 == tmp_edges.size() && 
@@ -2368,10 +2369,10 @@
 
     
     for (unsigned int j = 0; j < graph_points.size(); j++) {
-      MBEntityHandle this_point = graph_points[j];
+      EntityHandle this_point = graph_points[j];
       
         // get all neighbor verts
-      MBRange nverts;
+      Range nverts;
       result = mtu.get_bridge_adjacencies(this_point, 1, 0, nverts); RR;
       assert(4 == nverts.size() || 3 == nverts.size() || 2 == nverts.size());
       
@@ -2409,18 +2410,18 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode DrawDual::process_pick(MBEntityHandle dual_surf, 
+ErrorCode DrawDual::process_pick(EntityHandle dual_surf, 
                                    const double x, const double y,
-                                   MBRange &picked_ents) 
+                                   Range &picked_ents) 
 {
     // get vertices on interior of 3d sheet
-  MBRange int_verts, face_verts;
-  MBErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, NULL, NULL, 
+  Range int_verts, face_verts;
+  ErrorCode result = vtkMOABUtils::dualTool->get_dual_entities(dual_surf, NULL, NULL, 
                                                    &int_verts, &face_verts, NULL);
   int_verts = subtract( int_verts, face_verts);
   
     // get vertices on sheet drawing for that sheet, and their positions
-  std::vector<MBEntityHandle> int_points(int_verts.size());
+  std::vector<EntityHandle> int_points(int_verts.size());
   get_graph_points(int_verts, dual_surf, (void**) &int_points[0]);
   std::vector<double> point_coords(3*int_verts.size());
   result = MBI->get_coords(&int_points[0], int_points.size(), 
@@ -2428,7 +2429,7 @@
   
     // get the closest point to those
   double dist, closest_coords[3];
-  MBEntityHandle closest_point;
+  EntityHandle closest_point;
   for (unsigned int i = 0; i < int_verts.size(); i++) {
     double this_dist = (point_coords[3*i] - x)*(point_coords[3*i] - x) +
       (point_coords[3*i+1] - y)*(point_coords[3*i+1] - y);
@@ -2440,8 +2441,8 @@
   }
   
     // get connected edges, points, in star order
-  std::vector<MBEntityHandle> conn_edges(4);
-  MBEntityHandle dual_edges_3d[4], dual_curves[4], conn_verts[4];
+  std::vector<EntityHandle> conn_edges(4);
+  EntityHandle dual_edges_3d[4], dual_curves[4], conn_verts[4];
   result = MBI->get_adjacencies(&closest_point, 1, 1, false, conn_edges); RR;
   assert(4 == conn_edges.size());
     // conn_edges are on sheet diag; each points to 3d dual edge through curve tag,
@@ -2473,7 +2474,7 @@
 
     // get connected points & their coords
   for (int i = 0; i < 4; i++) {
-    const MBEntityHandle *connect;
+    const EntityHandle *connect;
     int num_connect;
     result = MBI->get_connectivity(conn_edges[i], connect, num_connect); RR;
     if (connect[0] == closest_point) conn_verts[i] = connect[1];
@@ -2483,12 +2484,12 @@
   
   double conn_coords[12];
   result = MBI->get_coords(conn_verts, 4, conn_coords); RR;
-  MBCartVect pick_closest(x - closest_coords[0], y - closest_coords[1], 0.0);
-  MBCartVect conn_vects[4];
+  CartVect pick_closest(x - closest_coords[0], y - closest_coords[1], 0.0);
+  CartVect conn_vects[4];
 
     // pre-compute normalized vectors from closest to each connected vertex
   for (int i = 0; i < 4; i++) {
-    conn_vects[i] = MBCartVect(conn_coords[3*i]-closest_coords[0],
+    conn_vects[i] = CartVect(conn_coords[3*i]-closest_coords[0],
                                conn_coords[3*i+1]-closest_coords[1], 0.0);
     conn_vects[i].normalize();
   }
@@ -2506,8 +2507,8 @@
     else if (0.0 < this_dot &&
              (conn_vects[i] * pick_closest) % (conn_vects[(i+1)%4] * pick_closest)
              < 0.0) {
-      MBRange common_2cell;
-      MBEntityHandle edges[2] = {dual_edges_3d[i], dual_edges_3d[(i+1)%4]};
+      Range common_2cell;
+      EntityHandle edges[2] = {dual_edges_3d[i], dual_edges_3d[(i+1)%4]};
       result = MBI->get_adjacencies(edges, 2, 2, false, common_2cell);
       assert(common_2cell.size() > 0);
       picked_ents.insert(*common_2cell.begin());
@@ -2517,9 +2518,9 @@
   return MB_SUCCESS;
 }
 
-MBEntityHandle DrawDual::get_dual_surf(vtkRenderer *this_ren) 
+EntityHandle DrawDual::get_dual_surf(vtkRenderer *this_ren) 
 {
-  std::map<MBEntityHandle, GraphWindows>::iterator mit;
+  std::map<EntityHandle, GraphWindows>::iterator mit;
   
   for (mit = surfDrawrings.begin(); mit != surfDrawrings.end(); mit++) {
     vtkRenderer *gw_ren = NULL;

Modified: MOAB/trunk/tools/qvdual/DrawDual.hpp
===================================================================
--- MOAB/trunk/tools/qvdual/DrawDual.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/qvdual/DrawDual.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -7,8 +7,8 @@
 
 class SheetDiagramPopup;
 
-#include "MBInterface.hpp"
-#include "MBRange.hpp"
+#include "moab/Interface.hpp"
+#include "moab/Range.hpp"
 #include <map>
 #include <vector>
 
@@ -24,30 +24,32 @@
 class Agsym_t;
 class QLineEdit;
 
+using namespace moab;
+
 class DrawDual
 {
 public:
   DrawDual(QLineEdit *pickline1, QLineEdit *pickline2);
   ~DrawDual();
 
-  bool draw_dual_surfs(MBRange &dual_surfs,
+  bool draw_dual_surfs(Range &dual_surfs,
                        const bool use_offsets = false);
-  bool print_dual_surfs(MBRange &dual_surfs,
+  bool print_dual_surfs(Range &dual_surfs,
                         const bool use_offsets = false);
-  bool draw_dual_surfs(std::vector<MBEntityHandle> &dual_surfs,
+  bool draw_dual_surfs(std::vector<EntityHandle> &dual_surfs,
                        const bool use_offsets = false);
-  MBErrorCode draw_dual_surf(MBEntityHandle dual_surf,
+  ErrorCode draw_dual_surf(EntityHandle dual_surf,
                              int offset_num = 0);
   
-  MBEntityHandle lastPickedEnt; // last picked entity
-  MBEntityHandle secondLastPickedEnt; // second last picked entity
+  EntityHandle lastPickedEnt; // last picked entity
+  EntityHandle secondLastPickedEnt; // second last picked entity
 
     //! reset the drawing data for a sheet
-  MBErrorCode reset_drawing_data(MBEntityHandle dual_surf);
+  ErrorCode reset_drawing_data(EntityHandle dual_surf);
 
-  MBErrorCode reset_drawn_sheets(MBRange *drawn_sheets = NULL);
+  ErrorCode reset_drawn_sheets(Range *drawn_sheets = NULL);
   
-  void print_picked_ents(MBRange &picked_ents,
+  void print_picked_ents(Range &picked_ents,
                          bool from_return = false);
 
 private:
@@ -61,8 +63,8 @@
   {
   public:
     int numGvizEntities;
-    MBEntityHandle dualSurfs[3];
-    MBEntityHandle moabEntity;
+    EntityHandle dualSurfs[3];
+    EntityHandle moabEntity;
     int pointPos[3][2];
     int vtkEntityIds[4]; // extra pt for edge mid-pts
     vtkActor *myActors[3];
@@ -83,7 +85,7 @@
         gvizEdges[0] = gvizEdges[1] = gvizEdges[2] = gvizEdges[3] = NULL;
       }
     void reset(const int index);
-    int get_index(const MBEntityHandle dual_surf) 
+    int get_index(const EntityHandle dual_surf) 
       {
         if (dual_surf == dualSurfs[0]) return 0;
         else if (dual_surf == dualSurfs[1]) return 1;
@@ -103,23 +105,23 @@
     vtkActor *pickActor;
 
     GraphWindows() : gvizGraph(NULL), sheetDiagram(NULL), pickActor(NULL) {}
-    MBErrorCode reset(MBEntityHandle dual_surf);
+    ErrorCode reset(EntityHandle dual_surf);
   };
   
     //! make sure all dual vertices and edges have graphviz nodes and edges
-  MBErrorCode construct_graphviz_data(MBEntityHandle dual_surf,
-                                      MBRange &dcells, MBRange &dedges,
-                                      MBRange &dverts, MBRange &face_verts,
-                                      MBRange &loop_edges);
+  ErrorCode construct_graphviz_data(EntityHandle dual_surf,
+                                      Range &dcells, Range &dedges,
+                                      Range &dverts, Range &face_verts,
+                                      Range &loop_edges);
   
     //! given the loop vertices, compute and fix their points
-  MBErrorCode compute_fixed_points(MBEntityHandle dual_surf, MBRange &dverts,
-                                   MBRange &face_verts, MBRange &loop_edges);
+  ErrorCode compute_fixed_points(EntityHandle dual_surf, Range &dverts,
+                                   Range &face_verts, Range &loop_edges);
 
     //! compute fixed points for a pillow sheet
-  MBErrorCode compute_pillow_fixed_points(MBEntityHandle dual_surf, 
-                                          MBRange &face_verts, 
-                                          MBRange &face_edges);
+  ErrorCode compute_pillow_fixed_points(EntityHandle dual_surf, 
+                                          Range &face_verts, 
+                                          Range &face_edges);
   
     //! compute the position on the loop, accounting for multiple loops
   void get_loop_vertex_pos(unsigned int vert_num, 
@@ -128,15 +130,15 @@
                            double angle, int &xpos_pts, int &ypos_pts);
   
     //! construct the points & cells for the vtkPolyData from the MOAB/graphviz data
-  MBErrorCode make_vtk_data(MBEntityHandle dual_surf,
+  ErrorCode make_vtk_data(EntityHandle dual_surf,
                             vtkPolyData *pd,
                             vtkRenderer *this_ren);
 
     //! construct dim-dimensional cells
-  MBErrorCode make_vtk_cells(const MBRange &cell_range, const int dim,
+  ErrorCode make_vtk_cells(const Range &cell_range, const int dim,
                              const float color_index,
-                             const MBEntityHandle dual_surf,
-                             std::map<MBEntityHandle, GVEntity *> &vert_gv_map,
+                             const EntityHandle dual_surf,
+                             std::map<EntityHandle, GVEntity *> &vert_gv_map,
                              vtkPolyData *pd,
                              vtkFloatArray *color_ids);
   
@@ -144,32 +146,32 @@
   vtkPolyData *get_polydata(SheetDiagramPopup *this_sdpopup);
   
     //! get a clean polydata for this widget
-  void get_clean_pd(MBEntityHandle dual_surf,
+  void get_clean_pd(EntityHandle dual_surf,
                     SheetDiagramPopup *&this_sdpopup, vtkPolyData *&pd);
 
     //! draw various labels with the sheet
-  MBErrorCode draw_labels(MBEntityHandle dual_surf,
+  ErrorCode draw_labels(EntityHandle dual_surf,
                           vtkPolyData *pd,
                           vtkPolyData *new_pd);
 
-  MBErrorCode label_other_sheets(MBEntityHandle dual_surf,
+  ErrorCode label_other_sheets(EntityHandle dual_surf,
                                  vtkPolyData *pd,
                                  vtkPolyData *&new_pd);
   
-  void label_interior_verts(MBEntityHandle dual_surf,
+  void label_interior_verts(EntityHandle dual_surf,
                             vtkPolyData *pd,
                             vtkRenderer *ren);
   
-  MBEntityHandle other_sheet(const MBEntityHandle this_chord,
-                             const MBEntityHandle dual_surf);
+  EntityHandle other_sheet(const EntityHandle this_chord,
+                             const EntityHandle dual_surf);
   
-  MBErrorCode get_primal_ids(const MBRange &ents, std::vector<int> &ids);
+  ErrorCode get_primal_ids(const Range &ents, std::vector<int> &ids);
   
-  MBErrorCode allocate_points(MBEntityHandle dual_surf,
+  ErrorCode allocate_points(EntityHandle dual_surf,
                               vtkPolyData *pd,
-                              MBRange &verts,
-                              MBRange &loop_edges,
-                              std::map<MBEntityHandle, GVEntity*> &vert_gv_map);
+                              Range &verts,
+                              Range &loop_edges,
+                              std::map<EntityHandle, GVEntity*> &vert_gv_map);
   
   static void add_picker(vtkRenderer *this_ren);
   
@@ -182,18 +184,18 @@
 
     //! given a dual surface and the pick point (in world coords), return a list 
     //! of picked entities on that sheet drawing
-  MBErrorCode process_pick(MBEntityHandle dual_surf, 
+  ErrorCode process_pick(EntityHandle dual_surf, 
                            const double x, const double y,
-                           MBRange &picked_ents);
+                           Range &picked_ents);
   
     //! map of dual surfaces and windows they're drawn in
-  std::map<MBEntityHandle, GraphWindows> surfDrawrings;
+  std::map<EntityHandle, GraphWindows> surfDrawrings;
   
   
     //! cache some of the tags we use
-  MBTag gvEntityHandle, dualEntityTagHandle;
+  Tag gvEntityHandle, dualEntityTagHandle;
 
-  static MBTag dualSurfaceTagHandle, dualCurveTagHandle;
+  static Tag dualSurfaceTagHandle, dualCurveTagHandle;
 
     //! gviz graphics context, seems to be needed for layout
   void *gvizGvc;
@@ -205,54 +207,54 @@
   static vtkCellPicker *dualPicker;
 
     //! entities which are currently picked
-  static MBRange pickRange;
+  static Range pickRange;
 
-  MBEntityHandle get_picked_cell(MBEntityHandle cell_set,
+  EntityHandle get_picked_cell(EntityHandle cell_set,
                                  const int dim,
                                  const int picked_cell);
 
   void update_high_polydatas();
   
-  MBErrorCode get_xform(MBEntityHandle dual_surf, Agsym_t *asym_pos, 
+  ErrorCode get_xform(EntityHandle dual_surf, Agsym_t *asym_pos, 
                         double &x_xform, double &y_xform);
   
-  MBErrorCode construct_graphviz_points(MBEntityHandle dual_surf, 
-                                        MBRange &dverts, 
+  ErrorCode construct_graphviz_points(EntityHandle dual_surf, 
+                                        Range &dverts, 
                                         Agsym_t *asym_pos);
   
-  MBErrorCode construct_graphviz_edges(MBEntityHandle dual_surf, 
-                                       MBRange &dedges, 
-                                       MBRange &loop_verts, 
+  ErrorCode construct_graphviz_edges(EntityHandle dual_surf, 
+                                       Range &dedges, 
+                                       Range &loop_verts, 
                                        Agsym_t *asym_pos);
   
-  Agsym_t *get_asym(MBEntityHandle dual_surf, const int dim,
+  Agsym_t *get_asym(EntityHandle dual_surf, const int dim,
                     const char *name, const char *def_val = NULL);
   
-  MBErrorCode fixup_degen_bchords(MBEntityHandle dual_surf);
+  ErrorCode fixup_degen_bchords(EntityHandle dual_surf);
 
     //! given some entities, get the corresponding gviz points on the sheet
-  void get_points(const MBEntityHandle *ents, const int num_ents, 
+  void get_points(const EntityHandle *ents, const int num_ents, 
                   const bool extra,
-                  MBEntityHandle dual_surf, Agnode_t **points);
+                  EntityHandle dual_surf, Agnode_t **points);
 
     //! smooth the points in the dual surface using length-weighted laplacian smoothing
-  MBErrorCode smooth_dual_surf(MBEntityHandle dual_surf,
-                               MBRange &dcells, MBRange &dedges,
-                               MBRange &dverts, MBRange &face_verts,
-                               MBRange &loop_edges);
+  ErrorCode smooth_dual_surf(EntityHandle dual_surf,
+                               Range &dcells, Range &dedges,
+                               Range &dverts, Range &face_verts,
+                               Range &loop_edges);
   
-  MBErrorCode set_graphpoint_pos(void *point, double *pos);
+  ErrorCode set_graphpoint_pos(void *point, double *pos);
   
-  MBErrorCode get_graphpoint_pos(void *point, double *pos);
+  ErrorCode get_graphpoint_pos(void *point, double *pos);
   
-  void get_graph_points(const MBEntityHandle *ents, const int gnum_ents, 
-                        MBEntityHandle dual_surf, void **points);
+  void get_graph_points(const EntityHandle *ents, const int gnum_ents, 
+                        EntityHandle dual_surf, void **points);
 
-  void get_graph_points(MBRange ents,
-                        MBEntityHandle dual_surf, void **points);
+  void get_graph_points(Range ents,
+                        EntityHandle dual_surf, void **points);
 
     //! given a renderer, return the sheet that this renderer renders
-  MBEntityHandle get_dual_surf(vtkRenderer *this_ren);
+  EntityHandle get_dual_surf(vtkRenderer *this_ren);
 };
 
 

Modified: MOAB/trunk/tools/qvdual/Makefile.am
===================================================================
--- MOAB/trunk/tools/qvdual/Makefile.am	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/qvdual/Makefile.am	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,5 +1,4 @@
-AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src $(QVDUAL_INCLUDES) \
-               -I$(top_srcdir)/src/moab -I$(top_builddir)/src/moab
+AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src $(QVDUAL_INCLUDES)
 bin_PROGRAMS = qvdual
 qvdual_SOURCES = \
   CropTool.cpp \

Modified: MOAB/trunk/tools/qvdual/uiQVDual.ui.h
===================================================================
--- MOAB/trunk/tools/qvdual/uiQVDual.ui.h	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/qvdual/uiQVDual.ui.h	2010-03-12 21:30:42 UTC (rev 3604)
@@ -28,7 +28,7 @@
 #include "vtkObjectFactory.h"
 #include "vtkUnstructuredGrid.h"
 #include "vtkMOABUtils.h"
-#include "MeshTopoUtil.hpp"
+#include "moab/MeshTopoUtil.hpp"
 #include "vtkPolyDataMapper.h"
 #include "vtkDataSetMapper.h"
 #include "vtkActor.h"
@@ -553,7 +553,7 @@
   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
 
-  std::copy(children.begin(), children.end(), mb_range_inserter(selected));
+  std::copy(children.begin(), children.end(), range_inserter(selected));
   
   unselected.clear();
   vtkMOABUtils::change_set_visibility(selected, unselected);
@@ -571,7 +571,7 @@
   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
 
-  std::copy(children.begin(), children.end(), mb_range_inserter(selected));
+  std::copy(children.begin(), children.end(), range_inserter(selected));
   
   vtkMOABUtils::change_set_visibility(selected, unselected);
 
@@ -612,7 +612,7 @@
   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
 
-  std::copy(children.begin(), children.end(), mb_range_inserter(selected));
+  std::copy(children.begin(), children.end(), range_inserter(selected));
   
   unselected.clear();
   vtkMOABUtils::change_set_visibility(unselected, selected);

Modified: MOAB/trunk/tools/refiner/CMakeLists.txt
===================================================================
--- MOAB/trunk/tools/refiner/CMakeLists.txt	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/CMakeLists.txt	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,14 +1,14 @@
 set ( MOAB_REFINER_SRCS 
-  MBEdgeSizeEvaluator.cpp
-  MBEdgeSizeSimpleImplicit.cpp
-  MBEntityRefiner.cpp
-  MBMeshOutputFunctor.cpp
-  MBMeshRefiner.cpp
-  MBProcessSet.cpp
-  MBRefinerTagManager.cpp
-  MBSimplexTemplateRefiner.cpp
-  MBSimplexTemplateTagAssigner.cpp
-  MBSplitVertices.cpp
+  EdgeSizeEvaluator.cpp
+  EdgeSizeSimpleImplicit.cpp
+  EntityRefiner.cpp
+  MeshOutputFunctor.cpp
+  MeshRefiner.cpp
+  ProcessSet.cpp
+  RefinerTagManager.cpp
+  SimplexTemplateRefiner.cpp
+  SimplexTemplateTagAssigner.cpp
+  SplitVertices.cpp
   )
 
 set_source_files_properties(

Copied: MOAB/trunk/tools/refiner/EdgeSizeEvaluator.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/EdgeSizeEvaluator.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EdgeSizeEvaluator.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,36 @@
+#include "MBEdgeSizeEvaluator.hpp"
+
+#include "MBRefinerTagManager.hpp"
+#include "MBInterface.hpp"
+
+#include <assert.h>
+
+/// Construct an evaluator.
+MBEdgeSizeEvaluator::MBEdgeSizeEvaluator()
+{
+  this->tag_manager = 0;
+}
+
+/// Destruction is virtual so subclasses may clean up after refinement.
+MBEdgeSizeEvaluator::~MBEdgeSizeEvaluator()
+{
+}
+
+/**\fn bool MBEdgeSizeEvaluator::evaluate_edge( \
+  *         const double* p0, const void* t0, double* p1, void* t1, const double* p2, const void* t2 )
+  *\brief Returns true if the edge \a p0 - \a p2 should be subdivided, false otherwise.
+  *
+  * The arguments \a p0, \a p1, and \a p2 are all pointers to arrays of 6 doubles each
+  * while the arguments \a t0, \a t1, and \a t2 are all pointers to arrays of tag data
+  * defined at the corresponding point. While the endpoints \a p0 and \a p2 are
+  * immutable, the mid-edge point coordinates \a p1 and tag data \a t1 may be altered by
+  * evaluate_edge(). Altered values will be ignored if evaluate_edge() returns false.
+  * Be careful to ensure that all calls to evaluate_edge() perform identical modifications
+  * given identical input values!
+  *
+  * A list of tags passed in \a t0, \a t1, and \a t2 is stored in the vertex_tags member.
+  * The vertex_size member stores the total length of data associated with each pointer (in bytes).
+  * Subclasses may access vertex_tags and vertexSize directly; the refiner uses public methods to
+  * populate vertex_tags before evaluate_edge() is called.
+  */
+

Copied: MOAB/trunk/tools/refiner/EdgeSizeEvaluator.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/EdgeSizeEvaluator.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EdgeSizeEvaluator.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,53 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class EdgeSizeEvaluator
+  *
+  * This is an abstract class that embodies the rule used during edge-based mesh
+  * refinement to decide whether an edge should be subdivided or not.
+  * Subclasses must implement the pure virtual evaluate_edge() function.
+  *
+  * \author David Thompson
+  *
+  * \date 19 November 2007
+  */
+#ifndef MOAB_EDGE_SIZE_EVALUATOR_HPP
+#define MOAB_EDGE_SIZE_EVALUATOR_HPP
+
+#include "moab/RefinerTagManager.hpp"
+
+namespace moab {
+
+class MB_DLL_EXPORT EdgeSizeEvaluator
+{
+public:
+  EdgeSizeEvaluator();
+  virtual ~EdgeSizeEvaluator();
+
+  virtual bool evaluate_edge(
+    const double* p0, const void* t0,
+    double* p1, void* t1,
+    const double* p2, const void* t2 ) = 0;
+
+  void set_tag_manager( RefinerTagManager* tmgr ) { this->tag_manager = tmgr; }
+  RefinerTagManager* get_tag_manager() { return this->tag_manager; }
+
+protected:
+  RefinerTagManager* tag_manager;
+};
+
+}
+
+#endif // MOAB_EDGE_SIZE_EVALUATOR_HPP

Copied: MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,83 @@
+#include "moab/EdgeSizeSimpleImplicit.hpp"
+
+namespace moab { 
+
+EdgeSizeSimpleImplicit::EdgeSizeSimpleImplicit()
+{
+  int i;
+  // Default to the plane: x = 0.
+  this->coeffC = 0.;
+  for ( i = 0; i < 3; ++i )
+    {
+    this->coeffB[i] = this->coeffA[i] = this->coeffA[i+3] = 0.;
+    }
+  this->coeffB[0] = 1.;
+  // Default to a scaling ratio of 1.
+  this->ratio = 1.;
+}
+
+EdgeSizeSimpleImplicit::~EdgeSizeSimpleImplicit()
+{
+}
+
+bool EdgeSizeSimpleImplicit::evaluate_edge(
+  const double* p0, const void* t0,
+  double* p1, void* t1,
+  const double* p2, const void* t2 )
+{
+  (void)t0;
+  (void)t1;
+  (void)t2;
+  double L2 = 0.;
+  double delta;
+  int i;
+  for ( i = 0; i < 3; ++i )
+    {
+    delta = p2[i+3] - p0[i+3];
+    L2 += delta * delta;
+    }
+  // parametric coords in p1[{0,1,2}]
+  double x = p1[3];
+  double y = p1[4];
+  double z = p1[5];
+  double F2 =
+    this->coeffA[0] * x * x + 2. * this->coeffA[1] * x * y + 2. * this->coeffA[2] * x * z +
+    this->coeffA[3] * y * y + 2. * this->coeffA[4] * y * z +
+    this->coeffA[5] * z * z +
+    this->coeffB[0] * x + this->coeffB[1] * y + this->coeffB[2] * z +
+    this->coeffC;
+  F2 = F2 * F2; // square it
+  double r2 = this->ratio * this->ratio;
+  if ( 4. * F2 / L2 < r2 )
+    return true; // Midpoint is close to surface => split edge
+
+  return false; // Don't split edge
+}
+
+void EdgeSizeSimpleImplicit::set_implicit_function( double* coeffs )
+{
+  int i;
+  // Default to the plane: x = 0.
+  for ( i = 0; i < 3; ++i )
+    {
+    this->coeffA[i  ] = coeffs[i];
+    this->coeffA[i+3] = coeffs[i + 3];
+    this->coeffB[i  ] = coeffs[i + 6];
+    }
+  this->coeffC = coeffs[9];
+}
+
+void EdgeSizeSimpleImplicit::get_implicit_function( double*& coeffs )
+{
+  int i;
+  // Default to the plane: x = 0.
+  for ( i = 0; i < 3; ++i )
+    {
+    coeffs[i] = this->coeffA[i  ];
+    coeffs[i + 3] = this->coeffA[i+3];
+    coeffs[i + 6] = this->coeffB[i  ];
+    }
+  coeffs[9] = this->coeffC;
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EdgeSizeSimpleImplicit.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,71 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class EdgeSizeSimpleImplicit
+  *
+  * This is an simple example edge evaluator tha subdivides edges based
+  * on their midpoint's distance to a simple, fixed-form implicit surface
+  * written as \f$ x^T A x + B x + C \f$ where \f$x\f$ is a column vector of
+  * holding the edge midpoint coordinates, \f$A\f$ is a symmetric 3x3 matrix,
+  * \f$B\f$ is a 1x3 row vector, and \f$C\f$ is a scalar.
+  * Whenever the implicit function divided by half of the edge length is smaller than
+  * some minimum ratio (which defaults to 1), the edge is marked for subdivision.
+  *
+  * \author David Thompson
+  *
+  * \date 19 November 2007
+  */
+#ifndef MOAB_EDGE_SIZE_SIMPLE_IMPLICIT_HPP
+#define MOAB_EDGE_SIZE_SIMPLE_IMPLICIT_HPP
+
+#include "moab/EdgeSizeEvaluator.hpp"
+
+namespace moab {
+
+class MB_DLL_EXPORT EdgeSizeSimpleImplicit : public EdgeSizeEvaluator
+{
+public:
+  /// Construct an evaluator.
+  EdgeSizeSimpleImplicit();
+  /// Destruction is virtual so subclasses may clean up after refinement.
+  virtual ~EdgeSizeSimpleImplicit();
+
+  /** \brief Given an edge of length L, true when edge midpoint is within $\alpha^2$ of $\left(\frac{2f(x,y,z)}{L}\right)^2$.
+    */
+  virtual bool evaluate_edge(
+    const double* p0, const void* t0,
+    double* p1, void* t1,
+    const double* p2, const void* t2 );
+
+  /// Set the 10 coefficients of the implicit function. The vector contains the entries of A, followed by B, followed by C.
+  virtual void set_implicit_function( double* coeffs );
+  /// Get the 10 coefficients of the implicit function. The vector contains the entries of A, followed by B, followed by C.
+  void get_implicit_function( double*& coeffs );
+
+  /// Set the threshold ratio of function value to half-edge length that triggers subdivision.
+  virtual void set_ratio( double r ) { this->ratio = r; }
+  /// Get the threshold ratio of function value to half-edge length that triggers subdivision.
+  double get_ratio() { return this->ratio; }
+
+protected:
+  double coeffA[6];
+  double coeffB[3];
+  double coeffC;
+  double ratio;
+};
+
+} // namespace moab 
+
+#endif // MOAB_EDGE_SIZE_SIMPLE_IMPLICIT_HPP

Copied: MOAB/trunk/tools/refiner/EntityRefiner.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBEntityRefiner.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/EntityRefiner.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EntityRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,236 @@
+#include "moab/EntityRefiner.hpp"
+
+#include "moab/EdgeSizeEvaluator.hpp"
+#include "moab/Interface.hpp"
+
+namespace moab {
+
+/// Construct an entity refiner.
+EntityRefiner::EntityRefiner()
+{  
+  this->mesh_in = 0;
+  this->edge_size_evaluator = 0;
+  this->output_functor = 0;
+  // By default, allow at most one subdivision per edge
+  this->minimum_number_of_subdivisions = 0;
+  this->maximum_number_of_subdivisions = 1;
+}
+
+/// Destruction is virtual so subclasses may clean up after refinement.
+EntityRefiner::~EntityRefiner()
+{
+  if ( this->edge_size_evaluator )
+    delete this->edge_size_evaluator;
+}
+
+/**\brief Prepare to start refining entities on a given mesh.
+  * This is called once before refine_entity() is ever invoked.
+  * The tag manager specifies the input and output meshes upon which the refiner will act.
+  *
+  * This function returns false if calling refine_entity() immediately
+  * afterwards would cause a failure (due, for example, to a NULL edge_size_evaluator).
+  * Otherwise it returns true.
+  */
+bool EntityRefiner::prepare( RefinerTagManager* tmgr, EntityRefinerOutputFunctor* ofunc )
+{
+  bool rval = true;
+  if ( this->edge_size_evaluator )
+    {
+    this->edge_size_evaluator->set_tag_manager( tmgr );
+    }
+  else
+    {
+    rval = false;
+    }
+  this->set_output_functor( ofunc );
+  this->mesh_in = tmgr->get_input_mesh();
+  this->update_heap_size();
+  return rval;
+}
+
+/**\fn bool EntityRefiner::refine_entity( EntityHandle )
+  *\brief Method implemented by subclasses to create decompositions of entities using edge subdivisions.
+  */
+
+/**\fn int EntityRefiner::get_heap_size_bound( int max_recursions ) const
+  *\brief When an entity is refined, what is the maximum number of new vertices that will be created?
+  *
+  * This must be the maximum number of initial corner vertices for any entity type (hex, tet, etc.)
+  * to be processed plus the maximum number of new vertices that might be created at edge or face
+  * mid-points during the refinement of a single entity.
+  */
+
+/**\brief Set the object that specifies which edges of a given entity should be subdivided.
+  *
+  * The entity refiner takes ownership of edge size evaluator and will delete it when
+  * a new value is set or when the entity refiner is destroyed.
+  *
+  * @param ese The new edge size evaluator object.
+  * @retval Returns true if the value was changed and false otherwise.
+  */
+bool EntityRefiner::set_edge_size_evaluator( EdgeSizeEvaluator* ese )
+{
+  if ( ! ese || ese == this->edge_size_evaluator )
+    return false;
+
+  if ( this->edge_size_evaluator )
+    {
+    delete this->edge_size_evaluator;
+    }
+  this->edge_size_evaluator = ese;
+
+  return true;
+}
+
+/**\fn EdgeSizeEvaluator* EntityRefiner::get_edge_size_evaluator()
+  *\brief Return a pointer to the object that specifies which edges of a given entity should be subdivided.
+  *
+  * This may return NULL if no value has been previously specified.
+  *
+  * @retval A pointer to an edge size evaluator object or NULL.
+  */
+
+/**\brief Set the functor through which output entities are streamed.
+  *
+  * Any previously assigned functor will be deleted when a new functor is set.
+  * 
+  * @retvalReturns true if the value was changed and false otherwise.
+  */
+bool EntityRefiner::set_output_functor( EntityRefinerOutputFunctor* func_obj )
+{
+  if ( ! func_obj || func_obj == this->output_functor )
+    return false;
+
+  if ( this->output_functor )
+    {
+    delete this->output_functor;
+    }
+  this->output_functor = func_obj;
+  return true;
+}
+
+/**\fn EntityRefinerOutputFunctor* EntityRefiner::get_output_functor()
+  *\brief Return the functor used to stream output.
+  *
+  * @retval A pointer to the functor. This may be NULL.
+  */
+
+/**\brief Set the minimum number of recursive subdivisions that should occur, regardless of the edge_size_evaluator's response.
+  *
+  * This is useful for forcing global refinement.
+  *
+  * @retval True if the number of subdivisions was changed; false otherwise.
+  */
+bool EntityRefiner::set_minimum_number_of_subdivisions( int mn )
+{
+  if ( mn < 0 || mn == this->minimum_number_of_subdivisions )
+    {
+    return false;
+    }
+
+  this->minimum_number_of_subdivisions = mn;
+  return true;
+}
+
+/**\fn int EntityRefiner::get_minimum_number_of_subdivisions() const
+  *\brief Return the minimum number of recursive edge subdivisions guaranteed to take place, regardless of the edge size evaluator.
+  *
+  * This may any non-negative integer.
+  *
+  * @retval The guaranteed minimum number of subdivisions that will take place on each and every edge of the mesh.
+  */
+
+/**\brief Set the maximum number of recursive subdivisions that should occur, regardless of the edge_size_evaluator's response.
+  *
+  * This is useful for preventing infinite recursion.
+  * A value of 0 is allowed although not terribly practical.
+  *
+  * @retval True if the number of subdivisions was changed; false otherwise.
+  */
+bool EntityRefiner::set_maximum_number_of_subdivisions( int mx )
+{
+  if ( mx < 0 || mx == this->maximum_number_of_subdivisions )
+    {
+    return false;
+    }
+
+  this->maximum_number_of_subdivisions = mx;
+  this->update_heap_size();
+  return true;
+}
+
+/**\fn int EntityRefiner::get_maximum_number_of_subdivisions() const
+  *\brief Return the maximum number of recursive edge subdivisions guaranteed to take place, regardless of the edge size evaluator.
+  *
+  * This may any non-negative integer.
+  *
+  * @retval The guaranteed maximum number of subdivisions that will take place on each and every edge of the mesh.
+  */
+
+/**\brief This is called when the edge size evaluator or maximum number of subdivisions is changed
+  *       to make sure the heaps are properly sized.
+  *
+  * Tag heap size cannot be computed if the edge_size_evaluator is NULL.
+  */
+void EntityRefiner::update_heap_size()
+{
+  unsigned long n = this->get_heap_size_bound( this->maximum_number_of_subdivisions );
+  this->coord_heap.resize( 6 * n );
+  if ( this->edge_size_evaluator )
+    {
+    unsigned long m = this->edge_size_evaluator->get_tag_manager()->get_vertex_tag_size();
+    this->tag_heap.resize( m * n );
+    }
+}
+
+/**\brief Subclasses should call this on entry to refine_entity().
+  *
+  * When called, future calls to heap_coord_storage() and heap_tag_storage() will
+  * re-use the allocated storage starting from the beginning.
+  */
+void EntityRefiner::reset_heap_pointers()
+{
+  this->current_coord = this->coord_heap.begin();
+  this->current_tag = this->tag_heap.begin();
+}
+
+/**\brief Return a pointer to temporary storage for edge midpoint vertex coordinates inside refine_entity().
+  *
+  * The returned pointer references 6 uninitialized double values to hold parametric coordinates and world coordinates.
+  */
+double* EntityRefiner::heap_coord_storage()
+{
+  double* rval;
+  if ( this->current_coord != this->coord_heap.end() )
+    {
+    rval = &(*this->current_coord);
+    this->current_coord += 6;
+    }
+  else
+    {
+    rval = 0;
+    }
+  return rval;
+}
+
+/**\brief Return a pointer to temporary storage for edge midpoint vertex coordinates inside refine_entity().
+  *
+  * The returned pointer references enough bytes to store all the tags for a vertex as reported by the
+  * current edge size evaluator's EdgeSizeEvaluator::get_vertex_tag_size().
+  */
+void* EntityRefiner::heap_tag_storage()
+{
+  void* rval;
+  if ( this->edge_size_evaluator && this->current_tag != this->tag_heap.end() )
+    {
+    rval = (void*) &(*this->current_tag);
+    this->current_tag += this->edge_size_evaluator->get_tag_manager()->get_vertex_tag_size();
+    }
+  else
+    {
+    rval = 0;
+    }
+  return rval;
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/EntityRefiner.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBEntityRefiner.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/EntityRefiner.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/EntityRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,178 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/** \class EntityRefiner
+  *
+  * This is an abstract class that contains the method used for per-entity refinement.
+  * Subclasses must implement the pure virtual refine_entity() function and
+  * may implement the vertices_per_split() function.
+  * This class constructor requires a non-NULL pointer to a mesh so that, given an
+  * entity handle, it can look up vertex coordinates and tags to prepare arguments for
+  * the refine_entity() method.
+  *
+  * Although the MeshRefiner class may not initially support it, entity refiners
+  * are required to support some level of recursion.
+  * The maximum number of recursive calls allowed may be set with
+  * EntityRefiner::set_maximum_number_of_subdivisions().
+  * As a convenience, some of the framework for recursion is provided by the
+  * EntityRefiner class.
+  *
+  * Specifically, EntityRefiner stores a pair of heap arrays
+  * to hold edge midpoint vertex coordinates and tag values pre-allocated to the
+  * maximum recursion depth so that no repeated allocation and deallocation
+  * needs to take place during refinement.
+  * To use these heaps, subclasses should call reset_heap_pointers() upon entry to
+  * EntityRefiner::refine_entity().
+  * Then, when the edge size evaluator requires an edge to be split, subclasses
+  * should call heap_coord_storage() and heap_tag_storage() to obtain pointers as
+  * required.
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 24 December 2007
+  */
+
+/**\class EntityRefinerOutputFunctor
+  *
+  * This is an abstract class used by EntityRefiner to output entities that are the product of refinement.
+  * The parenthesis operator is overloaded with two forms:
+  * one used for appending a vertex to an entity,
+  * the other used to finalize the creation of the entity by specifying its type.
+  *
+  * You are also responsible for implementing the map_vertex() function to map an input vertex handle
+  * into an output vertex handle (which may then be appended to an entity using the first form
+  * of the parenthesis operator above).
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 26 December 2007
+  */
+#ifndef MOAB_ENTITY_REFINER_HPP
+#define MOAB_ENTITY_REFINER_HPP
+
+#include "moab/Types.h" // for MB_DLL_EXPORT
+
+#include <vector>
+
+namespace moab {
+
+class Interface;
+class EdgeSizeEvaluator;
+class RefinerTagManager;
+
+class MB_DLL_EXPORT EntityRefinerOutputFunctor
+{
+public:
+  virtual ~EntityRefinerOutputFunctor() { }
+  /// Map an input vertex to the output mesh. This should return the same value when given the same input across multiple calls.
+  virtual EntityHandle map_vertex( EntityHandle vhash, const double* vcoords, const void* vtags ) = 0;
+  /**\brief Create a new vertex along an edge.
+    *
+    * @param[in] h0 An edge endpoint handle on the output mesh.
+    * @param[in] h1 An edge endpoint handle on the output mesh.
+    * @param[in] vcoords The location of the midpoint in world coordinates.
+    * @param[in] vtags Field values at the midpoint.
+    * @retval    A handle for the midpoint on the output mesh.
+    */
+  EntityHandle operator () ( EntityHandle h0, EntityHandle h1, const double* vcoords, const void* vtags )
+    {
+    EntityHandle harr[2];
+    harr[0] = h0;
+    harr[1] = h1;
+    return (*this)( 2, harr, vcoords, vtags );
+    }
+  /**\brief Create a new vertex on a triangular face.
+    *
+    * @param[in] h0 A triangle corner handle on the output mesh.
+    * @param[in] h1 A triangle corner handle on the output mesh.
+    * @param[in] h2 A triangle corner handle on the output mesh.
+    * @param[in] vcoords The location of the mid-face point in world coordinates.
+    * @param[in] vtags Field values at the mid-face point.
+    * @retval    A handle for the mid-face point on the output mesh.
+    */
+  virtual EntityHandle operator () ( EntityHandle h0, EntityHandle h1, EntityHandle h2, const double* vcoords, const void* vtags )
+    {
+    EntityHandle harr[3];
+    harr[0] = h0;
+    harr[1] = h1;
+    harr[2] = h2;
+    return (*this)( 3, harr, vcoords, vtags );
+    }
+  /**\brief Create a new vertex along a \f$k\f$-facet.
+    *
+    * @param[in] nhash The number of corner vertices (i.e, \f$k\f$ ).
+    * @param[in] hash An array of corner handles on the output mesh.
+    * @param[in] vcoords The location of the new point in world coordinates.
+    * @param[in] vtags Field values at the new point.
+    * @retval    A handle for the new point on the output mesh.
+    */
+  virtual EntityHandle operator () ( int nhash, EntityHandle* hash, const double* vcoords, const void* vtags ) = 0;
+  /**\brief Append an output vertex to the list of vertices defining a new entity.
+    *
+    * @param[in] vhash A vertex of the output mesh.
+    */
+  virtual void operator () ( EntityHandle vhash ) = 0;
+  /**\brief Create a new entity from all previously appended output vertices.
+    *
+    * This resets the list of appended vertices.
+    * @param[in] etyp The type of entity to create.
+    */
+  virtual void operator () ( EntityType etyp ) = 0;
+};
+
+class MB_DLL_EXPORT EntityRefiner
+{
+public:
+  EntityRefiner();
+  virtual ~EntityRefiner();
+
+  virtual bool prepare( RefinerTagManager* tmgr, EntityRefinerOutputFunctor* ofunc );
+  virtual bool refine_entity( EntityType typ, EntityHandle ent ) = 0;
+  virtual unsigned long get_heap_size_bound( int max_recursions ) const = 0;
+
+  virtual bool set_edge_size_evaluator( EdgeSizeEvaluator* );
+  EdgeSizeEvaluator* get_edge_size_evaluator() { return this->edge_size_evaluator; }
+
+  virtual bool set_output_functor( EntityRefinerOutputFunctor* func_obj );
+  EntityRefinerOutputFunctor* get_output_functor() { return this->output_functor; }
+
+  virtual bool set_minimum_number_of_subdivisions( int mn );
+  int get_minimum_number_of_subdivisions() const { return this->minimum_number_of_subdivisions; }
+
+  virtual bool set_maximum_number_of_subdivisions( int mx );
+  int get_maximum_number_of_subdivisions() const { return this->maximum_number_of_subdivisions; }
+
+protected:
+  Interface* mesh_in;
+  EdgeSizeEvaluator* edge_size_evaluator;
+  EntityRefinerOutputFunctor* output_functor;
+  int minimum_number_of_subdivisions;
+  int maximum_number_of_subdivisions;
+  std::vector<double> coord_heap;
+  std::vector<double>::iterator current_coord;
+  std::vector<char> tag_heap;
+  std::vector<char>::iterator current_tag;
+
+  void update_heap_size();
+  void reset_heap_pointers();
+  double* heap_coord_storage();
+  void* heap_tag_storage();
+};
+
+} // namespace moab 
+
+#endif // MOAB_ENTITY_REFINER_HPP

Deleted: MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,36 +0,0 @@
-#include "MBEdgeSizeEvaluator.hpp"
-
-#include "MBRefinerTagManager.hpp"
-#include "MBInterface.hpp"
-
-#include <assert.h>
-
-/// Construct an evaluator.
-MBEdgeSizeEvaluator::MBEdgeSizeEvaluator()
-{
-  this->tag_manager = 0;
-}
-
-/// Destruction is virtual so subclasses may clean up after refinement.
-MBEdgeSizeEvaluator::~MBEdgeSizeEvaluator()
-{
-}
-
-/**\fn bool MBEdgeSizeEvaluator::evaluate_edge( \
-  *         const double* p0, const void* t0, double* p1, void* t1, const double* p2, const void* t2 )
-  *\brief Returns true if the edge \a p0 - \a p2 should be subdivided, false otherwise.
-  *
-  * The arguments \a p0, \a p1, and \a p2 are all pointers to arrays of 6 doubles each
-  * while the arguments \a t0, \a t1, and \a t2 are all pointers to arrays of tag data
-  * defined at the corresponding point. While the endpoints \a p0 and \a p2 are
-  * immutable, the mid-edge point coordinates \a p1 and tag data \a t1 may be altered by
-  * evaluate_edge(). Altered values will be ignored if evaluate_edge() returns false.
-  * Be careful to ensure that all calls to evaluate_edge() perform identical modifications
-  * given identical input values!
-  *
-  * A list of tags passed in \a t0, \a t1, and \a t2 is stored in the vertex_tags member.
-  * The vertex_size member stores the total length of data associated with each pointer (in bytes).
-  * Subclasses may access vertex_tags and vertexSize directly; the refiner uses public methods to
-  * populate vertex_tags before evaluate_edge() is called.
-  */
-

Deleted: MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEdgeSizeEvaluator.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,49 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBEdgeSizeEvaluator
-  *
-  * This is an abstract class that embodies the rule used during edge-based mesh
-  * refinement to decide whether an edge should be subdivided or not.
-  * Subclasses must implement the pure virtual evaluate_edge() function.
-  *
-  * \author David Thompson
-  *
-  * \date 19 November 2007
-  */
-#ifndef MB_EDGESIZEEVALUATOR_H
-#define MB_EDGESIZEEVALUATOR_H
-
-#include "MBRefinerTagManager.hpp"
-
-class MB_DLL_EXPORT MBEdgeSizeEvaluator
-{
-public:
-  MBEdgeSizeEvaluator();
-  virtual ~MBEdgeSizeEvaluator();
-
-  virtual bool evaluate_edge(
-    const double* p0, const void* t0,
-    double* p1, void* t1,
-    const double* p2, const void* t2 ) = 0;
-
-  void set_tag_manager( MBRefinerTagManager* tmgr ) { this->tag_manager = tmgr; }
-  MBRefinerTagManager* get_tag_manager() { return this->tag_manager; }
-
-protected:
-  MBRefinerTagManager* tag_manager;
-};
-
-#endif // MB_EDGESIZEEVALUATOR_H

Deleted: MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,80 +0,0 @@
-#include "MBEdgeSizeSimpleImplicit.hpp"
-
-MBEdgeSizeSimpleImplicit::MBEdgeSizeSimpleImplicit()
-{
-  int i;
-  // Default to the plane: x = 0.
-  this->coeffC = 0.;
-  for ( i = 0; i < 3; ++i )
-    {
-    this->coeffB[i] = this->coeffA[i] = this->coeffA[i+3] = 0.;
-    }
-  this->coeffB[0] = 1.;
-  // Default to a scaling ratio of 1.
-  this->ratio = 1.;
-}
-
-MBEdgeSizeSimpleImplicit::~MBEdgeSizeSimpleImplicit()
-{
-}
-
-bool MBEdgeSizeSimpleImplicit::evaluate_edge(
-  const double* p0, const void* t0,
-  double* p1, void* t1,
-  const double* p2, const void* t2 )
-{
-  (void)t0;
-  (void)t1;
-  (void)t2;
-  double L2 = 0.;
-  double delta;
-  int i;
-  for ( i = 0; i < 3; ++i )
-    {
-    delta = p2[i+3] - p0[i+3];
-    L2 += delta * delta;
-    }
-  // parametric coords in p1[{0,1,2}]
-  double x = p1[3];
-  double y = p1[4];
-  double z = p1[5];
-  double F2 =
-    this->coeffA[0] * x * x + 2. * this->coeffA[1] * x * y + 2. * this->coeffA[2] * x * z +
-    this->coeffA[3] * y * y + 2. * this->coeffA[4] * y * z +
-    this->coeffA[5] * z * z +
-    this->coeffB[0] * x + this->coeffB[1] * y + this->coeffB[2] * z +
-    this->coeffC;
-  F2 = F2 * F2; // square it
-  double r2 = this->ratio * this->ratio;
-  if ( 4. * F2 / L2 < r2 )
-    return true; // Midpoint is close to surface => split edge
-
-  return false; // Don't split edge
-}
-
-void MBEdgeSizeSimpleImplicit::set_implicit_function( double* coeffs )
-{
-  int i;
-  // Default to the plane: x = 0.
-  for ( i = 0; i < 3; ++i )
-    {
-    this->coeffA[i  ] = coeffs[i];
-    this->coeffA[i+3] = coeffs[i + 3];
-    this->coeffB[i  ] = coeffs[i + 6];
-    }
-  this->coeffC = coeffs[9];
-}
-
-void MBEdgeSizeSimpleImplicit::get_implicit_function( double*& coeffs )
-{
-  int i;
-  // Default to the plane: x = 0.
-  for ( i = 0; i < 3; ++i )
-    {
-    coeffs[i] = this->coeffA[i  ];
-    coeffs[i + 3] = this->coeffA[i+3];
-    coeffs[i + 6] = this->coeffB[i  ];
-    }
-  coeffs[9] = this->coeffC;
-}
-

Deleted: MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEdgeSizeSimpleImplicit.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,67 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBEdgeSizeSimpleImplicit
-  *
-  * This is an simple example edge evaluator tha subdivides edges based
-  * on their midpoint's distance to a simple, fixed-form implicit surface
-  * written as \f$ x^T A x + B x + C \f$ where \f$x\f$ is a column vector of
-  * holding the edge midpoint coordinates, \f$A\f$ is a symmetric 3x3 matrix,
-  * \f$B\f$ is a 1x3 row vector, and \f$C\f$ is a scalar.
-  * Whenever the implicit function divided by half of the edge length is smaller than
-  * some minimum ratio (which defaults to 1), the edge is marked for subdivision.
-  *
-  * \author David Thompson
-  *
-  * \date 19 November 2007
-  */
-#ifndef MB_EDGESIZESIMPLEIMPLICIT_H
-#define MB_EDGESIZESIMPLEIMPLICIT_H
-
-#include "MBEdgeSizeEvaluator.hpp"
-
-class MB_DLL_EXPORT MBEdgeSizeSimpleImplicit : public MBEdgeSizeEvaluator
-{
-public:
-  /// Construct an evaluator.
-  MBEdgeSizeSimpleImplicit();
-  /// Destruction is virtual so subclasses may clean up after refinement.
-  virtual ~MBEdgeSizeSimpleImplicit();
-
-  /** \brief Given an edge of length L, true when edge midpoint is within $\alpha^2$ of $\left(\frac{2f(x,y,z)}{L}\right)^2$.
-    */
-  virtual bool evaluate_edge(
-    const double* p0, const void* t0,
-    double* p1, void* t1,
-    const double* p2, const void* t2 );
-
-  /// Set the 10 coefficients of the implicit function. The vector contains the entries of A, followed by B, followed by C.
-  virtual void set_implicit_function( double* coeffs );
-  /// Get the 10 coefficients of the implicit function. The vector contains the entries of A, followed by B, followed by C.
-  void get_implicit_function( double*& coeffs );
-
-  /// Set the threshold ratio of function value to half-edge length that triggers subdivision.
-  virtual void set_ratio( double r ) { this->ratio = r; }
-  /// Get the threshold ratio of function value to half-edge length that triggers subdivision.
-  double get_ratio() { return this->ratio; }
-
-protected:
-  double coeffA[6];
-  double coeffB[3];
-  double coeffC;
-  double ratio;
-};
-
-#endif // MB_EDGESIZESIMPLEIMPLICIT_H

Deleted: MOAB/trunk/tools/refiner/MBEntityRefiner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEntityRefiner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEntityRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,233 +0,0 @@
-#include "MBEntityRefiner.hpp"
-
-#include "MBEdgeSizeEvaluator.hpp"
-#include "MBInterface.hpp"
-
-/// Construct an entity refiner.
-MBEntityRefiner::MBEntityRefiner()
-{  
-  this->mesh_in = 0;
-  this->edge_size_evaluator = 0;
-  this->output_functor = 0;
-  // By default, allow at most one subdivision per edge
-  this->minimum_number_of_subdivisions = 0;
-  this->maximum_number_of_subdivisions = 1;
-}
-
-/// Destruction is virtual so subclasses may clean up after refinement.
-MBEntityRefiner::~MBEntityRefiner()
-{
-  if ( this->edge_size_evaluator )
-    delete this->edge_size_evaluator;
-}
-
-/**\brief Prepare to start refining entities on a given mesh.
-  * This is called once before refine_entity() is ever invoked.
-  * The tag manager specifies the input and output meshes upon which the refiner will act.
-  *
-  * This function returns false if calling refine_entity() immediately
-  * afterwards would cause a failure (due, for example, to a NULL edge_size_evaluator).
-  * Otherwise it returns true.
-  */
-bool MBEntityRefiner::prepare( MBRefinerTagManager* tmgr, MBEntityRefinerOutputFunctor* ofunc )
-{
-  bool rval = true;
-  if ( this->edge_size_evaluator )
-    {
-    this->edge_size_evaluator->set_tag_manager( tmgr );
-    }
-  else
-    {
-    rval = false;
-    }
-  this->set_output_functor( ofunc );
-  this->mesh_in = tmgr->get_input_mesh();
-  this->update_heap_size();
-  return rval;
-}
-
-/**\fn bool MBEntityRefiner::refine_entity( MBEntityHandle )
-  *\brief Method implemented by subclasses to create decompositions of entities using edge subdivisions.
-  */
-
-/**\fn int MBEntityRefiner::get_heap_size_bound( int max_recursions ) const
-  *\brief When an entity is refined, what is the maximum number of new vertices that will be created?
-  *
-  * This must be the maximum number of initial corner vertices for any entity type (hex, tet, etc.)
-  * to be processed plus the maximum number of new vertices that might be created at edge or face
-  * mid-points during the refinement of a single entity.
-  */
-
-/**\brief Set the object that specifies which edges of a given entity should be subdivided.
-  *
-  * The entity refiner takes ownership of edge size evaluator and will delete it when
-  * a new value is set or when the entity refiner is destroyed.
-  *
-  * @param ese The new edge size evaluator object.
-  * @retval Returns true if the value was changed and false otherwise.
-  */
-bool MBEntityRefiner::set_edge_size_evaluator( MBEdgeSizeEvaluator* ese )
-{
-  if ( ! ese || ese == this->edge_size_evaluator )
-    return false;
-
-  if ( this->edge_size_evaluator )
-    {
-    delete this->edge_size_evaluator;
-    }
-  this->edge_size_evaluator = ese;
-
-  return true;
-}
-
-/**\fn MBEdgeSizeEvaluator* MBEntityRefiner::get_edge_size_evaluator()
-  *\brief Return a pointer to the object that specifies which edges of a given entity should be subdivided.
-  *
-  * This may return NULL if no value has been previously specified.
-  *
-  * @retval A pointer to an edge size evaluator object or NULL.
-  */
-
-/**\brief Set the functor through which output entities are streamed.
-  *
-  * Any previously assigned functor will be deleted when a new functor is set.
-  * 
-  * @retvalReturns true if the value was changed and false otherwise.
-  */
-bool MBEntityRefiner::set_output_functor( MBEntityRefinerOutputFunctor* func_obj )
-{
-  if ( ! func_obj || func_obj == this->output_functor )
-    return false;
-
-  if ( this->output_functor )
-    {
-    delete this->output_functor;
-    }
-  this->output_functor = func_obj;
-  return true;
-}
-
-/**\fn MBEntityRefinerOutputFunctor* MBEntityRefiner::get_output_functor()
-  *\brief Return the functor used to stream output.
-  *
-  * @retval A pointer to the functor. This may be NULL.
-  */
-
-/**\brief Set the minimum number of recursive subdivisions that should occur, regardless of the edge_size_evaluator's response.
-  *
-  * This is useful for forcing global refinement.
-  *
-  * @retval True if the number of subdivisions was changed; false otherwise.
-  */
-bool MBEntityRefiner::set_minimum_number_of_subdivisions( int mn )
-{
-  if ( mn < 0 || mn == this->minimum_number_of_subdivisions )
-    {
-    return false;
-    }
-
-  this->minimum_number_of_subdivisions = mn;
-  return true;
-}
-
-/**\fn int MBEntityRefiner::get_minimum_number_of_subdivisions() const
-  *\brief Return the minimum number of recursive edge subdivisions guaranteed to take place, regardless of the edge size evaluator.
-  *
-  * This may any non-negative integer.
-  *
-  * @retval The guaranteed minimum number of subdivisions that will take place on each and every edge of the mesh.
-  */
-
-/**\brief Set the maximum number of recursive subdivisions that should occur, regardless of the edge_size_evaluator's response.
-  *
-  * This is useful for preventing infinite recursion.
-  * A value of 0 is allowed although not terribly practical.
-  *
-  * @retval True if the number of subdivisions was changed; false otherwise.
-  */
-bool MBEntityRefiner::set_maximum_number_of_subdivisions( int mx )
-{
-  if ( mx < 0 || mx == this->maximum_number_of_subdivisions )
-    {
-    return false;
-    }
-
-  this->maximum_number_of_subdivisions = mx;
-  this->update_heap_size();
-  return true;
-}
-
-/**\fn int MBEntityRefiner::get_maximum_number_of_subdivisions() const
-  *\brief Return the maximum number of recursive edge subdivisions guaranteed to take place, regardless of the edge size evaluator.
-  *
-  * This may any non-negative integer.
-  *
-  * @retval The guaranteed maximum number of subdivisions that will take place on each and every edge of the mesh.
-  */
-
-/**\brief This is called when the edge size evaluator or maximum number of subdivisions is changed
-  *       to make sure the heaps are properly sized.
-  *
-  * Tag heap size cannot be computed if the edge_size_evaluator is NULL.
-  */
-void MBEntityRefiner::update_heap_size()
-{
-  unsigned long n = this->get_heap_size_bound( this->maximum_number_of_subdivisions );
-  this->coord_heap.resize( 6 * n );
-  if ( this->edge_size_evaluator )
-    {
-    unsigned long m = this->edge_size_evaluator->get_tag_manager()->get_vertex_tag_size();
-    this->tag_heap.resize( m * n );
-    }
-}
-
-/**\brief Subclasses should call this on entry to refine_entity().
-  *
-  * When called, future calls to heap_coord_storage() and heap_tag_storage() will
-  * re-use the allocated storage starting from the beginning.
-  */
-void MBEntityRefiner::reset_heap_pointers()
-{
-  this->current_coord = this->coord_heap.begin();
-  this->current_tag = this->tag_heap.begin();
-}
-
-/**\brief Return a pointer to temporary storage for edge midpoint vertex coordinates inside refine_entity().
-  *
-  * The returned pointer references 6 uninitialized double values to hold parametric coordinates and world coordinates.
-  */
-double* MBEntityRefiner::heap_coord_storage()
-{
-  double* rval;
-  if ( this->current_coord != this->coord_heap.end() )
-    {
-    rval = &(*this->current_coord);
-    this->current_coord += 6;
-    }
-  else
-    {
-    rval = 0;
-    }
-  return rval;
-}
-
-/**\brief Return a pointer to temporary storage for edge midpoint vertex coordinates inside refine_entity().
-  *
-  * The returned pointer references enough bytes to store all the tags for a vertex as reported by the
-  * current edge size evaluator's MBEdgeSizeEvaluator::get_vertex_tag_size().
-  */
-void* MBEntityRefiner::heap_tag_storage()
-{
-  void* rval;
-  if ( this->edge_size_evaluator && this->current_tag != this->tag_heap.end() )
-    {
-    rval = (void*) &(*this->current_tag);
-    this->current_tag += this->edge_size_evaluator->get_tag_manager()->get_vertex_tag_size();
-    }
-  else
-    {
-    rval = 0;
-    }
-  return rval;
-}
-

Deleted: MOAB/trunk/tools/refiner/MBEntityRefiner.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBEntityRefiner.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBEntityRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,174 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/** \class MBEntityRefiner
-  *
-  * This is an abstract class that contains the method used for per-entity refinement.
-  * Subclasses must implement the pure virtual refine_entity() function and
-  * may implement the vertices_per_split() function.
-  * This class constructor requires a non-NULL pointer to a mesh so that, given an
-  * entity handle, it can look up vertex coordinates and tags to prepare arguments for
-  * the refine_entity() method.
-  *
-  * Although the MBMeshRefiner class may not initially support it, entity refiners
-  * are required to support some level of recursion.
-  * The maximum number of recursive calls allowed may be set with
-  * MBEntityRefiner::set_maximum_number_of_subdivisions().
-  * As a convenience, some of the framework for recursion is provided by the
-  * MBEntityRefiner class.
-  *
-  * Specifically, MBEntityRefiner stores a pair of heap arrays
-  * to hold edge midpoint vertex coordinates and tag values pre-allocated to the
-  * maximum recursion depth so that no repeated allocation and deallocation
-  * needs to take place during refinement.
-  * To use these heaps, subclasses should call reset_heap_pointers() upon entry to
-  * MBEntityRefiner::refine_entity().
-  * Then, when the edge size evaluator requires an edge to be split, subclasses
-  * should call heap_coord_storage() and heap_tag_storage() to obtain pointers as
-  * required.
-  *
-  * \author David Thompson
-  * \author Philippe Pebay
-  *
-  * \date 24 December 2007
-  */
-
-/**\class MBEntityRefinerOutputFunctor
-  *
-  * This is an abstract class used by MBEntityRefiner to output entities that are the product of refinement.
-  * The parenthesis operator is overloaded with two forms:
-  * one used for appending a vertex to an entity,
-  * the other used to finalize the creation of the entity by specifying its type.
-  *
-  * You are also responsible for implementing the map_vertex() function to map an input vertex handle
-  * into an output vertex handle (which may then be appended to an entity using the first form
-  * of the parenthesis operator above).
-  *
-  * \author David Thompson
-  * \author Philippe Pebay
-  *
-  * \date 26 December 2007
-  */
-#ifndef MB_ENTITYREFINER_H
-#define MB_ENTITYREFINER_H
-
-#include "MBTypes.h" // for MB_DLL_EXPORT
-
-#include <vector>
-
-class MBInterface;
-class MBEdgeSizeEvaluator;
-class MBRefinerTagManager;
-
-class MB_DLL_EXPORT MBEntityRefinerOutputFunctor
-{
-public:
-  virtual ~MBEntityRefinerOutputFunctor() { }
-  /// Map an input vertex to the output mesh. This should return the same value when given the same input across multiple calls.
-  virtual MBEntityHandle map_vertex( MBEntityHandle vhash, const double* vcoords, const void* vtags ) = 0;
-  /**\brief Create a new vertex along an edge.
-    *
-    * @param[in] h0 An edge endpoint handle on the output mesh.
-    * @param[in] h1 An edge endpoint handle on the output mesh.
-    * @param[in] vcoords The location of the midpoint in world coordinates.
-    * @param[in] vtags Field values at the midpoint.
-    * @retval    A handle for the midpoint on the output mesh.
-    */
-  MBEntityHandle operator () ( MBEntityHandle h0, MBEntityHandle h1, const double* vcoords, const void* vtags )
-    {
-    MBEntityHandle harr[2];
-    harr[0] = h0;
-    harr[1] = h1;
-    return (*this)( 2, harr, vcoords, vtags );
-    }
-  /**\brief Create a new vertex on a triangular face.
-    *
-    * @param[in] h0 A triangle corner handle on the output mesh.
-    * @param[in] h1 A triangle corner handle on the output mesh.
-    * @param[in] h2 A triangle corner handle on the output mesh.
-    * @param[in] vcoords The location of the mid-face point in world coordinates.
-    * @param[in] vtags Field values at the mid-face point.
-    * @retval    A handle for the mid-face point on the output mesh.
-    */
-  virtual MBEntityHandle operator () ( MBEntityHandle h0, MBEntityHandle h1, MBEntityHandle h2, const double* vcoords, const void* vtags )
-    {
-    MBEntityHandle harr[3];
-    harr[0] = h0;
-    harr[1] = h1;
-    harr[2] = h2;
-    return (*this)( 3, harr, vcoords, vtags );
-    }
-  /**\brief Create a new vertex along a \f$k\f$-facet.
-    *
-    * @param[in] nhash The number of corner vertices (i.e, \f$k\f$ ).
-    * @param[in] hash An array of corner handles on the output mesh.
-    * @param[in] vcoords The location of the new point in world coordinates.
-    * @param[in] vtags Field values at the new point.
-    * @retval    A handle for the new point on the output mesh.
-    */
-  virtual MBEntityHandle operator () ( int nhash, MBEntityHandle* hash, const double* vcoords, const void* vtags ) = 0;
-  /**\brief Append an output vertex to the list of vertices defining a new entity.
-    *
-    * @param[in] vhash A vertex of the output mesh.
-    */
-  virtual void operator () ( MBEntityHandle vhash ) = 0;
-  /**\brief Create a new entity from all previously appended output vertices.
-    *
-    * This resets the list of appended vertices.
-    * @param[in] etyp The type of entity to create.
-    */
-  virtual void operator () ( MBEntityType etyp ) = 0;
-};
-
-class MB_DLL_EXPORT MBEntityRefiner
-{
-public:
-  MBEntityRefiner();
-  virtual ~MBEntityRefiner();
-
-  virtual bool prepare( MBRefinerTagManager* tmgr, MBEntityRefinerOutputFunctor* ofunc );
-  virtual bool refine_entity( MBEntityType typ, MBEntityHandle ent ) = 0;
-  virtual unsigned long get_heap_size_bound( int max_recursions ) const = 0;
-
-  virtual bool set_edge_size_evaluator( MBEdgeSizeEvaluator* );
-  MBEdgeSizeEvaluator* get_edge_size_evaluator() { return this->edge_size_evaluator; }
-
-  virtual bool set_output_functor( MBEntityRefinerOutputFunctor* func_obj );
-  MBEntityRefinerOutputFunctor* get_output_functor() { return this->output_functor; }
-
-  virtual bool set_minimum_number_of_subdivisions( int mn );
-  int get_minimum_number_of_subdivisions() const { return this->minimum_number_of_subdivisions; }
-
-  virtual bool set_maximum_number_of_subdivisions( int mx );
-  int get_maximum_number_of_subdivisions() const { return this->maximum_number_of_subdivisions; }
-
-protected:
-  MBInterface* mesh_in;
-  MBEdgeSizeEvaluator* edge_size_evaluator;
-  MBEntityRefinerOutputFunctor* output_functor;
-  int minimum_number_of_subdivisions;
-  int maximum_number_of_subdivisions;
-  std::vector<double> coord_heap;
-  std::vector<double>::iterator current_coord;
-  std::vector<char> tag_heap;
-  std::vector<char>::iterator current_tag;
-
-  void update_heap_size();
-  void reset_heap_pointers();
-  double* heap_coord_storage();
-  void* heap_tag_storage();
-};
-
-#endif // MB_ENTITYREFINER_H

Deleted: MOAB/trunk/tools/refiner/MBMeshOutputFunctor.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBMeshOutputFunctor.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBMeshOutputFunctor.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,294 +0,0 @@
-#include "MBMeshOutputFunctor.hpp"
-
-#include "MBSplitVertices.hpp"
-#include "MBParallelComm.hpp"
-#include "MBRefinerTagManager.hpp"
-
-#include <iostream>
-#include <set>
-#include <iterator>
-#include <algorithm>
-
-#undef MB_DEBUG
-
-MBMeshOutputFunctor::MBMeshOutputFunctor( MBRefinerTagManager* tag_mgr )
-{
-  this->mesh_in  = tag_mgr->get_input_mesh();
-  this->mesh_out = tag_mgr->get_output_mesh();
-  this->input_is_output = ( this->mesh_in == this->mesh_out );
-  this->tag_manager = tag_mgr;
-  this->destination_set = 0; // don't place output entities in a set by default.
-
-  // When the input mesh and the output mesh are different, this map serves
-  // as a dictionary from input vertices to output vertices.
-  this->vertex_map = new MBSplitVertices<1>( this->tag_manager );
-
-  // Hold information about newly-created vertices on subdivided edges and faces.
-  this->split_vertices.resize( 4 );
-  this->split_vertices[0] = 0; // Vertices (0-faces) cannot be split
-  this->split_vertices[1] = new MBSplitVertices<1>( this->tag_manager );
-  this->split_vertices[2] = new MBSplitVertices<2>( this->tag_manager );
-  this->split_vertices[3] = new MBSplitVertices<3>( this->tag_manager );
-
-  // Hold information about newly-created mesh entities (other than split vertices)
-  // This is necessary in order for global IDs to be assigned consistently across processes.
-  this->new_entities.resize( 5 );
-  this->new_entities[0] = new MBEntitySource( 1, this->tag_manager );
-  this->new_entities[1] = new MBEntitySource( 2, this->tag_manager );
-  this->new_entities[2] = new MBEntitySource( 3, this->tag_manager );
-  this->new_entities[3] = new MBEntitySource( 4, this->tag_manager );
-  this->new_entities[4] = new MBEntitySource( 5, this->tag_manager );
-}
-
-MBMeshOutputFunctor::~MBMeshOutputFunctor()
-{
-  delete this->vertex_map;
-  for ( int i = 1; i < 4; ++ i )
-    delete this->split_vertices[i];
-  for ( int i = 0; i < 5; ++ i )
-    delete this->new_entities[i];
-}
-
-void MBMeshOutputFunctor::print_vert_crud(
-  MBEntityHandle vout, int nvhash, MBEntityHandle* vhash, const double* vcoords, const void* vtags )
-{
-  std::cout << "+ {";
-  for ( int i = 0; i < nvhash; ++ i )
-    std::cout << " " << vhash[i];
-  std::cout << " } -> " << vout << " ";
-
-  std::cout << "[ " << vcoords[0];
-  for ( int i = 1; i < 6; ++i )
-    std::cout << ", " << vcoords[i];
-  std::cout << " ] ";
-
-#if 0
-  double* x = (double*)vtags;
-  int* m = (int*)( (char*)vtags + 2 * sizeof( double ) );
-  std::cout << "< " << x[0]
-    << ", " << x[1];
-  for ( int i = 0; i < 4; ++i )
-    std::cout << ", " << m[i];
-#endif // 0
-
-  std::cout << " >\n";
-  //std::cout << "##############################\n";
-  //this->mesh_out->list_entities( 0, 1 );
-  //std::cout << "##############################\n";
-}
-
-void MBMeshOutputFunctor::assign_global_ids( MBParallelComm* comm )
-{
-  // First, we must gather the number of entities in each
-  // partition (for all partitions, not just those resident locally).
-  int lnparts = this->proc_partition_counts.size();
-  std::vector<unsigned char> lpdefns;
-  std::vector<int> lpsizes;
-  lpdefns.resize( MBProcessSet::SHARED_PROC_BYTES * lnparts );
-  lpsizes.resize( lnparts );
-#ifdef MB_DEBUG
-  std::cout << "**** Partition Counts ****\n";
-#endif // MB_DEBUG
-  int i = 0;
-  std::map<MBProcessSet,int>::iterator it;
-  for ( it = this->proc_partition_counts.begin(); it != this->proc_partition_counts.end(); ++ it, ++ i )
-    {
-    for ( int j = 0; j < MBProcessSet::SHARED_PROC_BYTES; ++ j )
-      lpdefns[MBProcessSet::SHARED_PROC_BYTES * i + j] = it->first.data()[j];
-    lpsizes[i] = it->second;
-#ifdef MB_DEBUG
-    std::cout << "Partition " << it->first << ": " << it->second << "\n";
-#endif // MB_DEBUG
-    }
-
-  if ( ! comm )
-    return;
-
-  std::vector<int> nparts;
-  std::vector<int> dparts;
-  unsigned long prank = comm->proc_config().proc_rank();
-  unsigned long psize = comm->proc_config().proc_size();
-  nparts.resize( psize );
-  dparts.resize( psize + 1 );
-  MPI_Allgather( &lnparts, 1, MPI_INT, &nparts[0], 1, MPI_INT, comm->proc_config().proc_comm() );
-  unsigned long ndefs = 0;
-  for ( int rank = 1; rank <= psize; ++ rank )
-    {
-    dparts[rank] = nparts[rank - 1] + dparts[rank - 1];
-#ifdef MB_DEBUG
-    std::cout << "Proc " << rank << ": " << nparts[rank-1] << " partitions, offset: " << dparts[rank] << "\n";
-#endif // MB_DEBUG
-    }
-  std::vector<unsigned char> part_defns;
-  std::vector<int> part_sizes;
-  part_defns.resize( MBProcessSet::SHARED_PROC_BYTES * dparts[psize] );
-  part_sizes.resize( dparts[psize] );
-  MPI_Allgatherv(
-    &lpsizes[0], lnparts, MPI_INT,
-    &part_sizes[0], &nparts[0], &dparts[0], MPI_INT, comm->proc_config().proc_comm() );
-  for ( int rank = 0; rank < psize; ++ rank )
-    {
-    nparts[rank] *= MBProcessSet::SHARED_PROC_BYTES;
-    dparts[rank] *= MBProcessSet::SHARED_PROC_BYTES;
-    }
-  MPI_Allgatherv(
-    &lpdefns[0], MBProcessSet::SHARED_PROC_BYTES * lnparts, MPI_UNSIGNED_CHAR,
-    &part_defns[0], &nparts[0], &dparts[0], MPI_UNSIGNED_CHAR, comm->proc_config().proc_comm() );
-
-  // Now that we have the number of new entities in every partition, we
-  // can deterministically assign the same GID to the same entity even
-  // when shared across processors because we have an ordering that is
-  // identical on all processes -- the vertex splits.
-  for ( int i = 0; i < dparts[psize]; ++ i )
-    {
-    MBProcessSet pset( &part_defns[MBProcessSet::SHARED_PROC_BYTES * i] );
-    std::map<MBProcessSet,int>::iterator it = this->proc_partition_counts.find( pset );
-    if ( it != this->proc_partition_counts.end() )
-      {
-#ifdef MB_DEBUG
-      std::cout << "Partition " << pset << ( it->second == part_sizes[i] ? " matches" : " broken" ) << ".\n";
-#endif // MB_DEBUG
-      }
-    else
-      {
-      this->proc_partition_counts[pset] = part_sizes[i];
-      }
-    }
-  std::map<MBProcessSet,int> gids;
-  std::map<MBProcessSet,int>::iterator pcit;
-  MBEntityHandle start_gid = 100; // FIXME: Get actual maximum GID across all processes and add 1
-  for ( pcit = this->proc_partition_counts.begin(); pcit != this->proc_partition_counts.end(); ++ pcit )
-    {
-    gids[pcit->first] = start_gid;
-    start_gid += pcit->second;
-#ifdef MB_DEBUG
-    std::cout << "Partition " << pcit->first << ": " << pcit->second << " # [" << gids[pcit->first] << "]\n";
-#endif // MB_DEBUG
-    }
-  std::vector<MBSplitVerticesBase*>::iterator vit;
-  vit = this->split_vertices.begin();
-  ++ vit; // Skip split_vertices[0] since it's empty.
-  ++ vit; // Skip split_vertices[1] since those entries already have global IDs... they exist in the input mesh.
-  for ( /* skip */; vit != this->split_vertices.end(); ++ vit )
-    {
-    (*vit)->assign_global_ids( gids );
-    }
-  std::vector<MBEntitySource*>::iterator sit;
-  for ( sit = this->new_entities.begin(); sit != this->new_entities.end(); ++ sit )
-    {
-    if ( *sit )
-      (*sit)->assign_global_ids( gids );
-    }
-}
-
-void MBMeshOutputFunctor::exchange_handles( MBParallelComm* comm )
-{
-}
-
-void MBMeshOutputFunctor::assign_tags( MBEntityHandle vhandle, const void* vtags )
-{
-  if ( ! vhandle )
-    return; // Ignore bad vertices
-
-  int num_tags = this->tag_manager->get_number_of_vertex_tags();
-  MBTag tag_handle;
-  int tag_offset;
-  for ( int i = 0; i < num_tags; ++i )
-    {
-    this->tag_manager->get_output_vertex_tag( i, tag_handle, tag_offset );
-    this->mesh_out->tag_set_data( tag_handle, &vhandle, 1, vtags );
-    }
-}
-
-MBEntityHandle MBMeshOutputFunctor::map_vertex( MBEntityHandle vhash, const double* vcoords, const void* vtags )
-{
-  if ( this->input_is_output )
-    { // Don't copy the original vertex!
-#ifdef MB_DEBUG
-    this->print_vert_crud( vhash, 1, &vhash, vcoords, vtags );
-#endif // MB_DEBUG
-    return vhash;
-    }
-  MBEntityHandle vertex_handle;
-  bool newly_created = this->vertex_map->find_or_create(
-    &vhash, vcoords, vertex_handle, this->proc_partition_counts, false );
-  if ( newly_created )
-    {
-    std::vector<int> gid;
-    this->assign_tags( vertex_handle, vtags );
-    if ( this->tag_manager->get_input_gids( 1, &vhash, gid ) == MB_SUCCESS )
-      {
-      this->tag_manager->set_gid( vertex_handle, gid[0] );
-      }
-    }
-  if ( ! vertex_handle )
-    {
-    std::cerr << "Could not insert vertex into new mesh!\n";
-    }
-#ifdef MB_DEBUG
-  this->print_vert_crud( vertex_handle, 1, &vhash, vcoords, vtags );
-  std::cout << "\nMap vert: " << vhash << " to: " << vertex_handle << "\n";
-#endif // MB_DEBUG
-  return vertex_handle;
-}
-
-MBEntityHandle MBMeshOutputFunctor::operator () ( int nvhash, MBEntityHandle* vhash, const double* vcoords, const void* vtags )
-{
-  MBEntityHandle vertex_handle;
-  if ( nvhash < 4 )
-    {
-    bool newly_created = this->split_vertices[nvhash]->find_or_create(
-      vhash, vcoords, vertex_handle, this->proc_partition_counts, true );
-    if ( newly_created )
-      {
-      this->assign_tags( vertex_handle, vtags );
-      }
-    if ( ! vertex_handle )
-      {
-      std::cerr << "Could not insert mid-edge vertex!\n";
-      }
-#ifdef MB_DEBUG
-    std::cout << "(-" << nvhash << "-) ";
-    this->print_vert_crud( vertex_handle, nvhash, vhash, vcoords, vtags );
-#endif // MB_DEBUG
-    }
-  else
-    {
-    vertex_handle = 0;
-    std::cerr << "Not handling splits on faces with " << nvhash << " corners yet.\n";
-    }
-  return vertex_handle;
-}
-
-void MBMeshOutputFunctor::operator () ( MBEntityHandle h )
-{
-#ifdef MB_DEBUG
-  std::cout << h << " ";
-#endif // MB_DEBUG
-  if ( ! this->input_is_output )
-    {
-    // FIXME: Copy to output mesh
-    }
-  this->elem_vert.push_back( h );
-}
-
-void MBMeshOutputFunctor::operator () ( MBEntityType etyp )
-{
-  MBEntityHandle elem_handle;
-  int nconn = this->elem_vert.size();
-  bool newly_created = this->new_entities[nconn]->create_element(
-    etyp, nconn, &this->elem_vert[0], elem_handle, this->proc_partition_counts );
-  if ( newly_created )
-    {
-#ifdef MB_DEBUG
-    std::cout << " *** ";
-#endif // MB_DEBUG
-    // FIXME: Handle tag assignment for elements as well as vertices
-    this->tag_manager->assign_element_tags( elem_handle );
-    }
-#ifdef MB_DEBUG
-  std::cout << "---------> " << elem_handle << " ( " << etyp << " )\n\n";
-#endif // MB_DEBUG
-  this->elem_vert.clear();
-}
-

Deleted: MOAB/trunk/tools/refiner/MBMeshOutputFunctor.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBMeshOutputFunctor.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBMeshOutputFunctor.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,73 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBMeshOutputFunctor
-  *\brief Implements the abstract MBEntityRefinerOutputFunctor class.
-  *
-  * This class is a concrete implementation of the MBEntityRefinerOutputFunctor.
-  * It creates new vertices and regions in a new or existing mesh as
-  * the input entities are streamed through the refiner.
-  *
-  * \author David Thompson
-  * \author Philippe Pebay
-  *
-  * \date 28 July 2008
-  */
-#ifndef MB_MESHOUTPUTFUNCTOR_HPP
-#define MB_MESHOUTPUTFUNCTOR_HPP
-
-#include "MBTypes.h"
-#include "MBEntityRefiner.hpp"
-#include "MBProcessSet.hpp"
-
-#include <vector>
-#include <map>
-
-#include <string.h>
-
-class MBSplitVerticesBase;
-class MBEntitySource;
-class MBParallelComm;
-
-class MBMeshOutputFunctor : public MBEntityRefinerOutputFunctor
-{
-public:
-  MBMeshOutputFunctor( MBRefinerTagManager* tag_mgr );
-  ~MBMeshOutputFunctor();
-
-  void print_vert_crud( MBEntityHandle vout, int nvhash, MBEntityHandle* vhash, const double* vcoords, const void* vtags );
-  void assign_global_ids( MBParallelComm* comm );
-  void exchange_handles( MBParallelComm* comm );
-
-  void assign_tags( MBEntityHandle vhandle, const void* vtags );
-
-  virtual MBEntityHandle map_vertex( MBEntityHandle vhash, const double* vcoords, const void* vtags );
-  virtual MBEntityHandle operator () ( int nvhash, MBEntityHandle* vhash, const double* vcoords, const void* vtags );
-  virtual void operator () ( MBEntityHandle h );
-  virtual void operator () ( MBEntityType etyp );
-
-  MBInterface* mesh_in;
-  MBInterface* mesh_out;
-  bool input_is_output;
-  MBSplitVerticesBase* vertex_map;
-  std::vector<MBSplitVerticesBase*> split_vertices;
-  std::vector<MBEntitySource*> new_entities;
-  std::vector<MBEntityHandle> elem_vert;
-  MBRefinerTagManager* tag_manager;
-  MBEntityHandle destination_set;
-  std::map<MBProcessSet,int> proc_partition_counts;
-};
-
-#endif // MB_MESHOUTPUTFUNCTOR_HPP

Deleted: MOAB/trunk/tools/refiner/MBMeshRefiner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBMeshRefiner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBMeshRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,140 +0,0 @@
-#include "MBMeshRefiner.hpp"
-
-#include "MBEdgeSizeEvaluator.hpp"
-#include "MBEntityRefiner.hpp"
-#include "MBInterface.hpp"
-#include "MBRefinerTagManager.hpp"
-#include "MBMeshOutputFunctor.hpp"
-
-#ifdef USE_MPI
-#include "MBParallelComm.hpp"
-#include "MBmpi.h"
-#else // USE_MPI
-typedef int MPI_Comm;
-#endif // USE_MPI
-
-/**\brief Construct a mesh refiner.
-  * The input and output mesh pointers may be identical.
-  * Existing elements will <b>not</b> be removed from the input mesh
-  * as they are refined, so the adjacencies for entitities may appear
-  * strange after refinement.
-  */
-MBMeshRefiner::MBMeshRefiner( MBInterface* imesh, MBInterface* omesh )
-{  
-  this->mesh_in = imesh;
-  this->mesh_out = omesh;
-  this->tag_manager = new MBRefinerTagManager( this->mesh_in, this->mesh_out );
-  this->output_functor = new MBMeshOutputFunctor( this->tag_manager );
-  this->entity_refiner = 0;
-  this->comm = MBParallelComm::get_pcomm( this->mesh_out, 0 );
-}
-
-/**\brief Destroy a mesh refiner.
-  *
-  * Note that any MBEntityRefiner object associated with the mesh refiner will be deleted inside this destructor.
-  * Destruction is virtual so subclasses may clean up after refinement.
-  */
-MBMeshRefiner::~MBMeshRefiner()
-{
-  delete this->tag_manager;
-  delete this->output_functor;
-  if ( this->entity_refiner )
-    delete this->entity_refiner;
-}
-
-/**\brief Specify which techniqe will be used to refine entities in the mesh.
-  * The entity refiner object you specify is ``owned'' by the mesh refiner after this call;
-  * the entity refiner will be deleted when this mesh refiner is destroyed.
-  * You should not delete the entity refiner yourself.
-  */
-bool MBMeshRefiner::set_entity_refiner( MBEntityRefiner* er )
-{
-  if ( ! er || er == this->entity_refiner )
-    return false;
-
-  this->entity_refiner = er;
-  return true;
-}
-
-/**\brief A convenience method to reset the list of tags to be copied to output vertices.
-  * This simply calls the method of the same name on the tag manager.
-  */
-void MBMeshRefiner::reset_vertex_tags()
-{
-  this->tag_manager->reset_vertex_tags();
-}
-
-/**\brief A convenience method to add a tag to be copied/interpolated from input vertices to output vertices.
-  * This simply calls the method of the same name on the tag manager.
-  */
-int MBMeshRefiner::add_vertex_tag( MBTag tag_handle )
-{
-  return this->tag_manager->add_vertex_tag( tag_handle );
-}
-
-struct MBMeshRefinerIterator {
-  MBRange subset;
-  MBEntityHandle destination_set;
-};
-
-/**\brief Refine entities in a mesh set.
-  * This will recursively descend any mesh sets contained in the \a range.
-  * It returns false when not able to refine (because no entity refiner is
-  * set or no edge size evaluator has been set on the entity refiner) and
-  * true otherwise.
-  */
-bool MBMeshRefiner::refine( MBRange& range )
-{
-  this->tag_manager->create_output_tags();
-  if ( ! this->entity_refiner->prepare( this->tag_manager, this->output_functor ) )
-    { // Oops, perhaps the edge_size_evaluator was not set?
-    return false;
-    }
-
-  MBMeshRefinerIterator entry;
-  std::vector<MBMeshRefinerIterator> work;
-
-  entry.subset = range;
-  entry.destination_set = 0;
-  work.push_back( entry );
-
-  while ( ! work.empty() )
-    {
-    entry = work.back();
-    work.pop_back();
-    this->output_functor->destination_set = entry.destination_set;
-    for ( MBRange::const_iterator it = entry.subset.begin(); it != entry.subset.end(); ++ it )
-      {
-      MBEntityType etyp = this->mesh_in->type_from_handle( *it );
-      if ( etyp == MBENTITYSET )
-        {
-        MBRange set_ents;
-        if ( this->mesh_in->get_entities_by_handle( *it, set_ents, false ) == MB_SUCCESS )
-          {
-          // Create a matching set on the output mesh.
-          MBMeshRefinerIterator set_work;
-          unsigned int set_work_opts;
-          this->mesh_in->get_meshset_options( *it, set_work_opts );
-          this->mesh_out->create_meshset( set_work_opts, set_work.destination_set );
-          set_work.subset = set_ents;
-          work.push_back( set_work );
-          // Copy any per-element tag values the user has requested to the output set.
-          this->tag_manager->set_element_tags_from_ent( *it );
-          this->tag_manager->assign_element_tags( set_work.destination_set );
-          // Copy the global ID to the new set (assuming it exists).
-          this->tag_manager->copy_gid( *it, set_work.destination_set );
-          }
-        }
-      else
-        {
-        this->tag_manager->set_element_tags_from_ent( *it );
-        this->tag_manager->set_element_procs_from_ent( *it );
-        this->entity_refiner->refine_entity( etyp, *it );
-        }
-      }
-    }
-  this->output_functor->assign_global_ids( this->comm );
-
-  return true;
-}
-

Deleted: MOAB/trunk/tools/refiner/MBMeshRefiner.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBMeshRefiner.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBMeshRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,68 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBMeshRefiner
-  *\brief Refine a mesh using a streaming operation.
-  *
-  * This is an class that contains the method used for mesh refinement.
-  *
-  * \author Philippe Pebay
-  * \author David Thompson
-  *
-  * \date 19 November 2007
-  */
-#ifndef MB_MESHREFINER_H
-#define MB_MESHREFINER_H
-
-#include "MBTypes.h" // for MB_DLL_EXPORT
-#include "MBRange.hpp"
-
-#include <vector>
-
-class MBInterface;
-class MBEntityRefiner;
-class MBParallelComm;
-class MBRefinerTagManager;
-class MBMeshOutputFunctor;
-
-class MB_DLL_EXPORT MBMeshRefiner
-{
-public:
-  MBMeshRefiner( MBInterface* imesh, MBInterface* omesh );
-  virtual ~MBMeshRefiner();
-
-  bool set_entity_refiner( MBEntityRefiner* );
-  MBEntityRefiner* get_entity_refiner() { return this->entity_refiner; }
-
-  bool set_comm( MBParallelComm* c ) { if ( ! c || this->comm == c ) return false; this->comm = c; return true; }
-  MBParallelComm* get_comm() { return this->comm; }
-
-  MBRefinerTagManager* get_tag_manager() { return this->tag_manager; }
-  const MBRefinerTagManager* get_tag_manager() const { return this->tag_manager; }
-  void reset_vertex_tags();
-  int add_vertex_tag( MBTag tag_handle );
-
-  virtual bool refine( MBRange& );
-
-protected:
-  MBInterface* mesh_in;
-  MBInterface* mesh_out;
-  MBEntityRefiner* entity_refiner;
-  MBRefinerTagManager* tag_manager;
-  MBMeshOutputFunctor* output_functor;
-  MBParallelComm* comm;
-};
-
-#endif // MB_MESHREFINER_H

Deleted: MOAB/trunk/tools/refiner/MBProcessSet.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBProcessSet.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBProcessSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,138 +0,0 @@
-#include "MBProcessSet.hpp"
-
-#include <assert.h>
-
-MBProcessSet::MBProcessSet()
-{
-  this->clear();
-}
-
-MBProcessSet::MBProcessSet( const unsigned char* psetbits )
-{
-  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
-    this->processes[i] = psetbits[i];
-}
-
-MBProcessSet::~MBProcessSet()
-{
-}
-
-void MBProcessSet::unite( const MBProcessSet& other )
-{
-  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
-    {
-    this->processes[i] |= other.processes[i];
-    }
-}
-
-void MBProcessSet::intersect( const MBProcessSet& other )
-{
-  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
-    {
-    this->processes[i] &= other.processes[i];
-    }
-}
-
-void MBProcessSet::clear()
-{
-  memset( this->processes, 0, SHARED_PROC_BYTES );
-}
-
-/**\brief Add a process to this process set.
-  *
-  * This does not verify that \a proc is within the range [0,MAX_SHARING_PROCS[ .
-  * You are responsible for that.
-  */
-void MBProcessSet::set_process_member( int proc )
-{
-  int byte = proc / 8;
-  int bitmask = 1 << ( proc % 8 );
-  this->processes[byte] |= bitmask;
-}
-
-/**\brief Add each process in the input vector to this process set.
-  *
-  * This is a convenience routine that calls set_process_member() for each entry in the vector.
-  * This does not verify that \a proc is within the range [0,MAX_SHARING_PROCS[ .
-  * You are responsible for that.
-  */
-void MBProcessSet::set_process_members( const std::vector<int>& procs )
-{
-  for ( std::vector<int>::const_iterator it = procs.begin(); it != procs.end() && *it != -1; ++ it )
-    {
-    this->set_process_member( *it );
-    }
-}
-
-/**\brief Retrieve a vector containing processes in this set.
-  *
-  * @param [in] rank The rank of the local process. This integer will not be included in the output list.
-  * @param [out] procs The vector in which the list of sharing processes is listed.
-  * @return   True when \a rank is the owning process and false otherwise.
-  */
-bool MBProcessSet::get_process_members( int rank, std::vector<int>& procs )
-{
-  int i = 0;
-  assert( rank >= 0 );
-  procs.clear();
-  bool rank_owner = false;
-  for ( int byte = 0; byte < SHARED_PROC_BYTES; ++ byte )
-    {
-    i = byte * 8;
-    for ( unsigned char val = this->processes[byte]; val; ++ i, val >>= 1 )
-      {
-      if ( val & 0x1 )
-        {
-        if ( i != rank )
-          {
-          //std::cout << " " << i;
-          procs.push_back( i );
-          }
-        else if ( ! procs.size() )
-          {
-          rank_owner = true;
-          }
-        }
-      }
-    }
-  for ( i = procs.size(); i < MAX_SHARING_PROCS; ++ i )
-    {
-    procs.push_back( -1 ); // pad with invalid values
-    }
-  return rank_owner;
-}
-
-bool MBProcessSet::is_process_member( int i ) const
-{
-  int byte = i / 8;
-  int bitmask = 1 << ( i % 8 );
-  return ( this->processes[byte] & bitmask ) ? true : false;
-}
-
-const unsigned char* MBProcessSet::data() const
-{
-  return this->processes;
-}
-
-bool MBProcessSet::operator < ( const MBProcessSet& other ) const
-{
-  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
-    {
-    if ( this->processes[i] < other.processes[i] )
-      return true;
-    else if ( this->processes[i] > other.processes[i] )
-      return false;
-    }
-  return false; // equality
-}
-
-std::ostream& operator << ( std::ostream& os, const MBProcessSet& pset )
-{
-  for ( int i = 0; i < MAX_SHARING_PROCS; ++ i )
-    {
-    os << ( pset.is_process_member( i ) ? "1" : "0" );
-    }
-  return os;
-}
-
-

Deleted: MOAB/trunk/tools/refiner/MBProcessSet.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBProcessSet.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBProcessSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,66 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBProcessSet
-  *\brief Represent a set of processes using a bit vector.
-  *
-  * This is used by the mesh refiner when determining where to record
-  * split vertices so that labeling can be inferred across process
-  * boundaries without communicating anything other than the number of
-  * entities in a given partition.
-  */
-#ifndef MB_PROCESSSET_HPP
-#define MB_PROCESSSET_HPP
-
-#include "MBTypes.h"
-#include "MBParallelComm.hpp"
-
-#include <iostream>
-#include <vector>
-
-class MBProcessSet
-{
-public:
-  enum
-    {
-    SHARED_PROC_BYTES = (MAX_SHARING_PROCS / 8 + (MAX_SHARING_PROCS % 8 ? 1 : 0))
-    };
-
-  MBProcessSet();
-  MBProcessSet( const unsigned char* psetbits );
-  ~MBProcessSet();
-
-  void unite( const MBProcessSet& other );
-  void intersect( const MBProcessSet& other );
-
-  void clear();
-
-  void set_process_member( int i );
-  void set_process_members( const std::vector<int>& procs );
-
-  bool get_process_members( int rank, std::vector<int>& procs );
-  bool is_process_member( int i ) const;
-
-  const unsigned char* data() const;
-
-  bool operator < ( const MBProcessSet& other ) const;
-
-  friend std::ostream& operator << ( std::ostream& os, const MBProcessSet& pset );
-
-protected:
-  unsigned char processes[SHARED_PROC_BYTES];
-};
-
-#endif /* MB_PROCESSSET_HPP */

Deleted: MOAB/trunk/tools/refiner/MBRefiner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBRefiner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,1573 +0,0 @@
-/*
- * Copyright 2003 Sandia Corporation.
- * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
- * license for use of this work by or on behalf of the
- * U.S. Government. Redistribution and use in source and binary forms, with
- * or without modification, are permitted provided that this Notice and any
- * statement of authorship are reproduced on all copies.
- */
-
-#include "MBRefiner.h"
-#include "MBEdgeEvaluator.h"
-
-#include "verdict.h"
-
-// how's this for avoiding namespace conflicts?! 8-)
-static vtkTetra* argyle = 0;
-static int argyleRef = 0;
-static vtkPoints* goCallTheCops;
-
-
-#undef UGLY_ASPECT_RATIO_HACK
-#undef DBG_MIDPTS
-
-#include <stack>
-#include <algorithm>
-
-#ifdef PARAVIEW_DEBUG_TESSELLATOR
-#  define VTK_TESSELLATOR_INCR_CASE_COUNT(cs) this->CaseCounts[cs]++
-#  define VTK_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc) this->SubcaseCounts[cs][sc]++
-#else // PARAVIEW_DEBUG_TESSELLATOR
-#  define VTK_TESSELLATOR_INCR_CASE_COUNT(cs)
-#  define VTK_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc)
-#endif // PARAVIEW_DEBUG_TESSELLATOR
-
-MBRefiner::MBRefiner()
-{
-  this->PrivateData = 0;
-  this->ConstPrivateData = 0;
-  this->Algorithm = 0;
-  this->Callback1 = 0;
-  this->Callback2 = 0;
-  this->Callback3 = 0;
-  this->MaximumNumberOfSubdivisions = 3;
-  for ( int i=0; i<4; ++i )
-    {
-    this->EmbeddingDimension[i] = i;
-    this->PointDimension[i] = i+3; // By default, FieldSize = 0
-    }
-  if ( ! argyle )
-    {
-    argyle = vtkTetra::New();
-    argyleRef = 1;
-    goCallTheCops = argyle->GetPoints();
-    }
-  else
-    {
-    ++argyleRef;
-    }
-}
-
-MBRefiner::~MBRefiner()
-{
-  if ( this->Algorithm )
-    this->Algorithm->UnRegister( this );
-  if ( ! (--argyleRef) )
-    {
-    argyle->Delete();
-    argyle = 0;
-    }
-}
-
-void MBRefiner::SetEmbeddingDimension( int k, int d )
-{
-  if ( d > 8 )
-    {
-    MBErrorMacro( "Embedding dimension may not be > 8. (You asked for " << d << "). Truncating to 8." );
-    d = 8;
-    }
-
-  if ( k == 0 || k < -1 || k >= 4 )
-    {
-    vtkWarningMacro( "Invalid argument k=" << k );
-    return;
-    }
-
-  if ( k < 0 )
-    {
-    for ( k=0; k<4; k++ )
-      if ( this->EmbeddingDimension[k] != d )
-        {
-        this->PointDimension[k] += d - this->EmbeddingDimension[k] ;
-        this->EmbeddingDimension[k] = d;
-        this->Modified();
-        }
-    return;
-    }
-  if ( this->EmbeddingDimension[k] != d )
-    {
-    this->PointDimension[k] += d - this->EmbeddingDimension[k] ;
-    this->EmbeddingDimension[k] = d;
-    this->Modified();
-    }
-}
-
-void MBRefiner::SetFieldSize( int k, int s )
-{
-  if ( s > MBRefiner::MaxFieldSize )
-    {
-    MBErrorMacro( "Embedding dimension may not be > " << MaxFieldSize << ". (You asked for " << s << "). Truncating to " << MaxFieldSize );
-    s = MBRefiner::MaxFieldSize;
-    }
-
-  if ( k == 0 || k < -1 || k >= 4 )
-    {
-    vtkWarningMacro( "Invalid argument k=" << k );
-    return;
-    }
-
-  if ( k < 0 )
-    {
-    // Use field size for all facet types (point, line, triangle, tet, ...)
-    for ( k=0; k<4; k++ )
-      if ( this->PointDimension[k] != s + this->EmbeddingDimension[k] + 3 )
-        {
-        this->PointDimension[k] = s + this->EmbeddingDimension[k] + 3;
-        this->Modified();
-        }
-    return;
-    }
-
-  if ( this->PointDimension[k] != s + this->EmbeddingDimension[k] + 3 )
-    {
-    this->PointDimension[k] = s + this->EmbeddingDimension[k] + 3;
-    this->Modified();
-    }
-}
-
-void MBRefiner::SetMaximumNumberOfSubdivisions( int num_subdiv_in )
-{
-  if ( this->MaximumNumberOfSubdivisions == num_subdiv_in )
-    return;
-
-  if ( num_subdiv_in < 0 )
-    {
-    MBErrorMacro( "MaximumNumberOfSubdivisions must be 0 or greater (you requested " << num_subdiv_in << ")" );
-    return;
-    }
-
-  this->MaximumNumberOfSubdivisions = num_subdiv_in;
-  this->Modified();
-}
-
-void MBRefiner::SetTriangleCallback( TriangleProcessorFunction f )
-{
-  this->Callback2 = f;
-}
-
-MBRefiner::TriangleProcessorFunction MBRefiner::GetTriangleCallback() const
-{
-  return this->Callback2;
-}
-
-void MBRefiner::SetTetrahedronCallback( TetrahedronProcessorFunction f )
-{
-  this->Callback3 = f;
-}
-
-MBRefiner::TetrahedronProcessorFunction MBRefiner::GetTetrahedronCallback() const
-{
-  return this->Callback3;
-}
-
-void MBRefiner::SetEdgeCallback( EdgeProcessorFunction f )
-{
-  this->Callback1 = f;
-}
-
-MBRefiner::EdgeProcessorFunction MBRefiner::GetEdgeCallback() const
-{
-  return this->Callback1;
-}
-
-void MBRefiner::SetPrivateData( void* Private )
-{
-  this->PrivateData = Private;
-}
-
-void* MBRefiner::GetPrivateData() const
-{
-  return this->PrivateData;
-}
-
-void MBRefiner::SetConstPrivateData( const void* ConstPrivate )
-{
-  this->ConstPrivateData = ConstPrivate;
-}
-
-const void* MBRefiner::GetConstPrivateData() const
-{
-  return this->ConstPrivateData;
-}
-
-void MBRefiner::SetSubdivisionAlgorithm( vtkSubdivisionAlgorithm* a )
-{
-  if ( a != this->Algorithm )
-    {
-    if ( this->Algorithm )
-      this->Algorithm->UnRegister( this );
-
-    this->Algorithm = a;
-    this->Modified();
-
-    if ( this->Algorithm )
-      this->Algorithm->Register( this );
-    }
-}
-
-// Returns true if || a0a1 || < || b0b1 ||
-// We use this to test which triangulation has the best
-// aspect ratio when there are 2 to choose from.
-bool compare_Hopf_cross_string_dist( const double* a0, const double* a1, const double* b0, const double* b1 )
-{
-  double SqMagA = 0.;
-  double SqMagB = 0.;
-  for (int i=0; i<3; i++)
-    {
-    double tmp;
-    tmp = a0[i] - a1[i];
-    SqMagA += tmp*tmp;
-    tmp = b0[i] - b1[i];
-    SqMagB += tmp*tmp;
-    }
-  return SqMagA < SqMagB;
-}
-
-
-int MBRefiner::BestTets( int* connOffsets, double** verts, int permOffset, int sgn ) const
-{
-  int bestOffset = -1;
-  double bestQuality = 0.;
-  double currQuality;
-
-  while ( *connOffsets >= 0 )
-    {
-    int nTets = TetrahedralDecompositions[*connOffsets];
-    vtkIdType* conn = &TetrahedralDecompositions[*connOffsets +1];
-    int v;
-    currQuality = 0.;
-    for (v=0; v<nTets; ++v)
-      {
-      goCallTheCops->SetPoint( 0, verts[ MBRefiner::PermutationsFromIndex[ permOffset ][ conn[sgn < 0 ? 1:0]] ] );
-      goCallTheCops->SetPoint( 1, verts[ MBRefiner::PermutationsFromIndex[ permOffset ][ conn[sgn < 0 ? 0:1]] ] );
-      goCallTheCops->SetPoint( 2, verts[ MBRefiner::PermutationsFromIndex[ permOffset ][ conn[2]] ] );
-      goCallTheCops->SetPoint( 3, verts[ MBRefiner::PermutationsFromIndex[ permOffset ][ conn[3]] ] );
-      currQuality += vtkMeshQuality::TetAspectFrobenius( argyle );
-      conn += 4;
-      }
-    currQuality /= nTets;
-    //std::cout << currQuality << " " << *connOffsets << " ";
-    if ( bestQuality > currQuality || bestOffset < 0 )
-      {
-      bestQuality = currQuality;
-      bestOffset = *connOffsets;
-      }
-      ++connOffsets;
-    }
-    //std::cout << "Choose " << bestOffset << "\n";
-  return bestOffset;
-}
-
-
-void MBRefiner::AdaptivelySample1Facet( double* v0, double* v1, int maxDepth ) const
-{
-  int edgeCode = 0;
-
-  double midpt0[11+MBRefiner::MaxFieldSize];
-  // make valgrind happy
-  std::fill(midpt0,midpt0+this->PointDimension[1],0.);
-
-  if ( maxDepth-- > 0 )
-    {
-      for ( int i=0; i<this->PointDimension[1]; i++ )
-        midpt0[i] = (v0[i] + v1[i])/2.;
-
-      if ( this->Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[1] ) )
-        edgeCode += 1;
-    }
-
-  switch (edgeCode) {
-    // No edges to subdivide
-    case 0:
-      Callback1( v0, v1, this->Algorithm, this->PrivateData, this->ConstPrivateData );
-      break ;
-
-      // One edge to subdivide
-    case 1:
-      this->AdaptivelySample1Facet( v0, midpt0, maxDepth );
-      this->AdaptivelySample1Facet( midpt0, v1, maxDepth );
-      break;
-  }
-}
-
-void MBRefiner::AdaptivelySample2Facet( double* v0, double* v1, double* v2, int maxDepth, int move ) const
-{
-  int edgeCode = 0;
-
-  double midpt0[11+MBRefiner::MaxFieldSize];
-  double midpt1[11+MBRefiner::MaxFieldSize];
-  double midpt2[11+MBRefiner::MaxFieldSize];
-
-  // Make valgrind happy
-  std::fill(midpt0,midpt0+this->PointDimension[2],0.);
-  std::fill(midpt1,midpt1+this->PointDimension[2],0.);
-  std::fill(midpt2,midpt2+this->PointDimension[2],0.);
-
-  if ( maxDepth-- > 0 )
-    {
-
-    for ( int i=0; i<this->PointDimension[2]; i++ )
-      {
-      midpt0[i] = (v0[i] + v1[i])/2.;
-      midpt1[i] = (v1[i] + v2[i])/2.;
-      midpt2[i] = (v2[i] + v0[i])/2.;
-      }
-
-    if ( (move & 1) && Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[2] ) )
-      edgeCode += 1;
-    if ( (move & 2) && Algorithm->EvaluateEdge( v1, midpt1, v2, 3+this->EmbeddingDimension[2] ) )
-      edgeCode += 2;
-    if ( (move & 4) && Algorithm->EvaluateEdge( v2, midpt2, v0, 3+this->EmbeddingDimension[2] ) )
-      edgeCode += 4;
-#ifdef UGLY_ASPECT_RATIO_HACK
-    double dist0=0.;
-    double dist1=0.;
-    double dist2=0.;
-    double tmp;
-    for ( int j=0; j<3; ++j )
-      {
-      tmp = v0[j] - v1[j];
-      dist0 += tmp*tmp;
-      tmp = v1[j] - v2[j];
-      dist1 += tmp*tmp;
-      tmp = v2[j] - v0[j];
-      dist2 += tmp*tmp;
-      }
-
-    if ( edgeCode & 1 ) dist0 /= 2.;
-    if ( edgeCode & 2 ) dist1 /= 2.;
-    if ( edgeCode & 4 ) dist2 /= 2.;
-
-#define MAR2 2.25
-    if ( (!(edgeCode & 1)) && (move&1) && ((dist0/dist1 > MAR2) || (dist0/dist2 > MAR2)) )
-      {
-      edgeCode += 1;
-      move &= 6;
-      }
-    if ( (!(edgeCode & 2)) && (move&2) && ((dist1/dist0 > MAR2) || (dist1/dist2 > MAR2)) )
-      {
-      edgeCode += 2;
-      move &= 5;
-      }
-    if ( (!(edgeCode & 4)) && (move&4) && ((dist2/dist1 > MAR2) || (dist2/dist0 > MAR2)) )
-      {
-      edgeCode += 4;
-      move &= 3;
-      }
-#endif // UGLY_ASPECT_RATIO_HACK
-    }
-
-#ifdef DBG_MIDPTS
-  if ( maxDepth == 0 )
-    {
-    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n",
-      0, v0[0], v0[1], v0[2], v0[3], v0[4], v0[5],
-      1, v1[0], v1[1], v1[2], v1[3], v1[4], v1[5],
-         midpt0[0], midpt0[1], midpt0[2], midpt0[3], midpt0[4], midpt0[5]
-    );
-
-    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n",
-      1, v1[0], v1[1], v1[2], v1[3], v1[4], v1[5],
-      2, v2[0], v2[1], v2[2], v2[3], v2[4], v2[5],
-         midpt1[0], midpt1[1], midpt1[2], midpt1[3], midpt1[4], midpt1[5]
-    );
-
-    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n\n",
-      2, v2[0], v2[1], v2[2], v2[3], v2[4], v2[5],
-      0, v0[0], v0[1], v0[2], v0[3], v0[4], v0[5],
-         midpt2[0], midpt2[1], midpt2[2], midpt2[3], midpt2[4], midpt2[5]
-    );
-    }
-#endif // DBG_MIDPTS
-
-  switch (edgeCode)
-    {
-    // No edges to subdivide
-  case 0:
-    Callback2( v0, v1, v2, this->Algorithm, this->PrivateData, this->ConstPrivateData );
-    break ;
-
-    // One edge to subdivide
-  case 1:
-    this->AdaptivelySample2Facet( v0, midpt0, v2, maxDepth, move | 2 );
-    this->AdaptivelySample2Facet( midpt0, v1, v2, maxDepth, move | 4 );
-    break;
-  case 2:
-    this->AdaptivelySample2Facet( v0, v1, midpt1, maxDepth, move | 4 );
-    this->AdaptivelySample2Facet( v0, midpt1, v2, maxDepth, move | 1 );
-    break;
-  case 4:
-    this->AdaptivelySample2Facet( v0, v1, midpt2, maxDepth, move | 2 );
-    this->AdaptivelySample2Facet( midpt2, v1, v2, maxDepth, move | 1 );
-    break;
-
-    // Two edges to subdivide
-  case 3:
-    this->AdaptivelySample2Facet( midpt0, v1, midpt1, maxDepth, move | 4 );
-    if ( compare_Hopf_cross_string_dist( v2, midpt0, v0, midpt1 ) )
-      {
-      this->AdaptivelySample2Facet( midpt0, midpt1,   v2  , maxDepth, move | 5 );
-      this->AdaptivelySample2Facet(   v0,   midpt0,   v2  , maxDepth, move | 2 );
-      }
-    else
-      {
-      this->AdaptivelySample2Facet(   v0  , midpt0, midpt1, maxDepth, move | 6 );
-      this->AdaptivelySample2Facet(   v0,   midpt1,   v2  , maxDepth, move | 1 );
-      }
-    break;
-  case 5:
-    this->AdaptivelySample2Facet( v0, midpt0, midpt2, maxDepth, move | 2 );
-    if ( compare_Hopf_cross_string_dist( v2, midpt0, v1, midpt2 ) )
-      {
-      this->AdaptivelySample2Facet( midpt0,   v1,     v2  , maxDepth, move | 4 );
-      this->AdaptivelySample2Facet( midpt2, midpt0,   v2  , maxDepth, move | 3 );
-      }
-    else
-      {
-      this->AdaptivelySample2Facet( midpt0,   v1,   midpt2, maxDepth, move | 6 );
-      this->AdaptivelySample2Facet( midpt2,   v1,     v2,   maxDepth, move | 1 );
-      }
-    break;
-  case 6:
-    this->AdaptivelySample2Facet( midpt2, midpt1, v2, maxDepth, move | 1 );
-    if ( compare_Hopf_cross_string_dist( v0, midpt1, v1, midpt2 ) )
-      {
-      this->AdaptivelySample2Facet(   v0,   midpt1, midpt2, maxDepth, move | 3 );
-      this->AdaptivelySample2Facet(   v0,     v1,   midpt1, maxDepth, move | 4 );
-      }
-    else
-      {
-      this->AdaptivelySample2Facet(   v0,     v1,   midpt2, maxDepth, move | 2 );
-      this->AdaptivelySample2Facet( midpt2,   v1,   midpt1, maxDepth, move | 5 );
-      }
-    break;
-
-    // Three edges to subdivide
-  case 7:
-    this->AdaptivelySample2Facet( midpt0, midpt1, midpt2, maxDepth, 7 );
-    this->AdaptivelySample2Facet(   v0  , midpt0, midpt2, maxDepth, move | 2 );
-    this->AdaptivelySample2Facet( midpt0,   v1  , midpt1, maxDepth, move | 4 );
-    this->AdaptivelySample2Facet( midpt2, midpt1,   v2  , maxDepth, move | 1 );
-    break;
-    }
-}
-
-void MBRefiner::AdaptivelySample3Facet( double* v0, double* v1, double* v2, double* v3, int maxDepth ) const
-{
-  int edgeCode = 0;
-
-  double midpt0[11+MBRefiner::MaxFieldSize];
-  double midpt1[11+MBRefiner::MaxFieldSize];
-  double midpt2[11+MBRefiner::MaxFieldSize];
-  double midpt3[11+MBRefiner::MaxFieldSize];
-  double midpt4[11+MBRefiner::MaxFieldSize];
-  double midpt5[11+MBRefiner::MaxFieldSize];
-#ifdef ALLOW_TET_INTERIOR_PT
-  double midpt6[11+MBRefiner::MaxFieldSize];
-#endif // ALLOW_TET_INTERIOR_PT
-  double facept0[11+MBRefiner::MaxFieldSize];
-  double facept1[11+MBRefiner::MaxFieldSize];
-  double facept2[11+MBRefiner::MaxFieldSize];
-  double facept3[11+MBRefiner::MaxFieldSize];
-
-  // Make valgrind happy
-  std::fill(midpt0,midpt0+this->PointDimension[3],0.);
-  std::fill(midpt1,midpt1+this->PointDimension[3],0.);
-  std::fill(midpt2,midpt2+this->PointDimension[3],0.);
-  std::fill(midpt3,midpt3+this->PointDimension[3],0.);
-  std::fill(midpt4,midpt4+this->PointDimension[3],0.);
-  std::fill(midpt5,midpt5+this->PointDimension[3],0.);
-#ifdef ALLOW_TET_INTERIOR_PT
-  std::fill(midpt6,midpt6+this->PointDimension[3],0.);
-#endif // ALLOW_TET_INTERIOR_PT
-
-  double edgeLength2[6];
-  if ( maxDepth-- > 0 )
-    {
-    for ( int i=0; i<this->PointDimension[3]; i++ )
-      {
-      midpt0[i] = (v0[i] + v1[i])/2.;
-      midpt1[i] = (v1[i] + v2[i])/2.;
-      midpt2[i] = (v2[i] + v0[i])/2.;
-      midpt3[i] = (v0[i] + v3[i])/2.;
-      midpt4[i] = (v1[i] + v3[i])/2.;
-      midpt5[i] = (v2[i] + v3[i])/2.;
-#ifdef ALLOW_TET_INTERIOR_PT
-      midpt6[i] = (v1[i]+v2[i]-2*v0[i])/4. + (v3[i]-v0[i])/3. + v0[i];
-#endif // ALLOW_TET_INTERIOR_PT
-      }
-
-    if ( Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |=  1;
-    if ( Algorithm->EvaluateEdge( v1, midpt1, v2, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |=  2;
-    if ( Algorithm->EvaluateEdge( v2, midpt2, v0, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |=  4;
-
-    if ( Algorithm->EvaluateEdge( v0, midpt3, v3, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |=  8;
-    if ( Algorithm->EvaluateEdge( v1, midpt4, v3, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |= 16;
-    if ( Algorithm->EvaluateEdge( v2, midpt5, v3, 3+this->EmbeddingDimension[3] ) )
-      edgeCode |= 32;
-
-    edgeLength2[0] = edgeLength2[1] = edgeLength2[2] = edgeLength2[3]
-      = edgeLength2[4] = edgeLength2[5] = 0;
-    for ( int c=0; c<3; ++c )
-      {
-      double tmp;
-      tmp = v1[c] - v0[c];
-      edgeLength2[0] += tmp*tmp;
-      tmp = v2[c] - v1[c];
-      edgeLength2[1] += tmp*tmp;
-      tmp = v2[c] - v0[c];
-      edgeLength2[2] += tmp*tmp;
-      tmp = v3[c] - v0[c];
-      edgeLength2[3] += tmp*tmp;
-      tmp = v3[c] - v1[c];
-      edgeLength2[4] += tmp*tmp;
-      tmp = v3[c] - v2[c];
-      edgeLength2[5] += tmp*tmp;
-      }
-
-#ifdef ALLOW_TET_INTERIOR_PT
-    // Find the longest/shortest edges
-    double shortest = edgeLength2[0];
-    double longest = edgeLength2[0];
-    for ( int e=1; e<6; e++ )
-      {
-      if ( edgeLength2[e] < shortest )
-        shortest = edgeLength2[e];
-      if ( edgeLength2[e] > longest )
-        longest = edgeLength2[e];
-      }
-    // Divide at center if aspect ratio is > 4:1 (remember these are squares of edge lengths):
-    if ( shortest / longest < 1./16. )
-      edgeCode |= 64;
-#if 0
-    // Dunno if we need to have the subdivision algorithm evaluate it, but I suspect
-    // it wouldn't be a bad idea.
-    if ( Algorithm->EvaluatePoint( midpt6 ) )
-      edgeCode |= 64;
-#endif // 0
-#endif // ALLOW_TET_INTERIOR_PT
-    }
-
-  if ( edgeCode == 0 )
-    {
-    // No edges to subdivide
-    Callback3( v0, v1, v2, v3, this->Algorithm, this->PrivateData, this->ConstPrivateData );
-    }
-  else
-    {
-    // Do the subdivision
-#ifdef ALLOW_TET_INTERIOR_PT
-    double* vertices[11] =
-    {
-      v0, v1, v2, v3,     midpt0, midpt1, midpt2, midpt3, midpt4, midpt5, midpt6
-    };
-#else // ALLOW_TET_INTERIOR_PT
-    double* vertices[10] =
-    {
-      v0, v1, v2, v3,     midpt0, midpt1, midpt2, midpt3, midpt4, midpt5
-    };
-#endif // ALLOW_TET_INTERIOR_PT
-
-    // Generate tetrahedra that are compatible except when edge
-    // lengths are equal on indeterminately subdivided faces.
-    double* permuted[14];
-    double permlen[6]; // permuted edge lengths
-    int C = MBRefiner::EdgeCodesToCaseCodesPlusPermutation[ edgeCode ][0];
-    int P = MBRefiner::EdgeCodesToCaseCodesPlusPermutation[ edgeCode ][1];
-    int i;
-
-    // 1. Permute the tetrahedron into our canonical configuration
-    for ( i=0; i<4; ++i )
-      {
-      permuted[i] = vertices[ MBRefiner::PermutationsFromIndex[P][i] ];
-      }
-    for ( i=4; i<10; ++i )
-      {
-      // permute the edge lengths, too
-      permuted[i] = vertices[ MBRefiner::PermutationsFromIndex[P][i] ];
-      permlen[i-4]  = edgeLength2[ MBRefiner::PermutationsFromIndex[P][i] - 4 ];
-      }
-    // Add our local (heap) storage for face points to the list.
-    permuted[10] = facept0;
-    permuted[11] = facept1;
-    permuted[12] = facept2;
-    permuted[13] = facept3;
-
-    int comparisonBits;
-    std::stack<vtkIdType*> outputTets;
-    std::stack<vtkIdType*> outputPerm;
-    std::stack<int>        outputSign;
-
-    // cout << "Case " << C << "  Permutation " << P << endl;
-    // 2. Generate tetrahedra based on the configuration.
-    //    Note that case 0 is handled above (edgeCode == 0).
-    switch (C)
-      {
-
-    case 1: // Ruprecht-Müller Case 1
-      VTK_TESSELLATOR_INCR_CASE_COUNT(0);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 0 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(0,0);
-      break;
-    case 2: // Ruprecht-Müller Case 2a
-      comparisonBits = 
-        (permlen[0] <= permlen[1] ? 1 : 0) | (permlen[0] >= permlen[1] ? 2 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[0][i] + permuted[2][i])*0.375 + permuted[1][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(1);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 9 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,0);
-      switch (comparisonBits)
-        {
-        case 2: // 0>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 14 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,1);
-          break;
-        case 1: // 1>0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 14 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[13] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,2);
-          break;
-        case 3: // 0=1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 23 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,3);
-          break;
-        }
-      break;
-    case 3: // Ruprecht-Müller Case 2b
-      VTK_TESSELLATOR_INCR_CASE_COUNT(2);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 40 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(2,0);
-      break;
-    case 4: // Ruprecht-Müller Case 3a
-      comparisonBits = 
-        (permlen[0] <= permlen[3] ? 1 : 0) | (permlen[0] >= permlen[3] ? 2 : 0) |
-        (permlen[2] <= permlen[3] ? 4 : 0) | (permlen[2] >= permlen[3] ? 8 : 0) |
-        (permlen[0] <= permlen[2] ? 16 : 0) | (permlen[0] >= permlen[2] ? 32 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[1][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[13][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 48) == 48 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(3);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 57 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,0);
-      switch (comparisonBits)
-        {
-        case 42: // 0>2>3<0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,1);
-          break;
-        case 25: // 2>3>0<2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[11] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,2);
-          break;
-        case 37: // 3>0>2<3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[3] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,3);
-          break;
-        case 21: // 3>2>0<3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[22] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,4);
-          break;
-        case 26: // 2>0>3<2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[12] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,5);
-          break;
-        case 38: // 0>3>2<0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 62 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,6);
-          break;
-        case 58: // 0=2>3<0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 75 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,7);
-          break;
-        case 29: // 2=3>0<2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 75 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[11] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,8);
-          break;
-        case 39: // 0=3>2<0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 75 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[3] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,9);
-          break;
-        case 53: // 3>0=2<3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 96 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,10);
-          break;
-        case 46: // 0>2=3<0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 96 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[11] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,11);
-          break;
-        case 27: // 2>0=3<2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 96 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[3] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,12);
-          break;
-        case 63: // 0=2=3=0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 117 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,13);
-          break;
-        }
-      break;
-    case 5: // Ruprecht-Müller Case 3b
-      VTK_TESSELLATOR_INCR_CASE_COUNT(4);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 162 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(4,0);
-      break;
-    case 6: // Ruprecht-Müller Case 3c
-      comparisonBits = 
-        (permlen[0] <= permlen[1] ? 1 : 0) | (permlen[0] >= permlen[1] ? 2 : 0) |
-        (permlen[0] <= permlen[3] ? 4 : 0) | (permlen[0] >= permlen[3] ? 8 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[0][i] + permuted[2][i])*0.375 + permuted[1][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[1][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(5);
-      switch (comparisonBits)
-        {
-        case 10: // 0>1,0>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 179 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,0);
-          break;
-        case 5: // 1>0,3>0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 200 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,1);
-          break;
-        case 6: // 0>1,3>0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 221 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,2);
-          break;
-        case 9: // 1>0,0>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 242 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,3);
-          break;
-        case 11: // 0=1,0>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 263 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,4);
-          break;
-        case 14: // 0=3,0>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 263 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,5);
-          break;
-        case 7: // 3>0,0=1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 292 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,6);
-          break;
-        case 13: // 1>0,0=3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 292 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,7);
-          break;
-        case 15: // 0=1,0=3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 321 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,8);
-          break;
-        }
-      break;
-    case 7: // Ruprecht-Müller Case 3d
-      comparisonBits = 
-        (permlen[0] <= permlen[2] ? 1 : 0) | (permlen[0] >= permlen[2] ? 2 : 0) |
-        (permlen[0] <= permlen[4] ? 4 : 0) | (permlen[0] >= permlen[4] ? 8 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[0][i] + permuted[3][i])*0.375 + permuted[1][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(6);
-      switch (comparisonBits)
-        {
-        case 10: // 0>4,0>2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 362 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,0);
-          break;
-        case 5: // 4>0,2>0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 383 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,1);
-          break;
-        case 9: // 0>4,2>0
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 404 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,2);
-          break;
-        case 6: // 4>0,0>2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 425 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,3);
-          break;
-        case 14: // 0=4,0>2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 446 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,4);
-          break;
-        case 11: // 0=2,0>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 446 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,5);
-          break;
-        case 13: // 2>0,0=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 475 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,6);
-          break;
-        case 7: // 4>0,0=2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 475 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,7);
-          break;
-        case 15: // 0=4,0=2
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 504 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,8);
-          break;
-        }
-      break;
-    case 8: // Ruprecht-Müller Case 4a
-      comparisonBits = 
-        (permlen[4] <= permlen[5] ? 1 : 0) | (permlen[4] >= permlen[5] ? 2 : 0) |
-        (permlen[3] <= permlen[4] ? 4 : 0) | (permlen[3] >= permlen[4] ? 8 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[12][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[3][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(7);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 545 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,0);
-      switch (comparisonBits)
-        {
-        case 5: // 5>4>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 554 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,1);
-          break;
-        case 10: // 3>4>5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 554 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[13] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,2);
-          break;
-        case 6: // 3<4>5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 571 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,3);
-          break;
-        case 9: // 3>4<5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 588 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,4);
-          break;
-        case 14: // 3=4>5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 605 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,5);
-          break;
-        case 7: // 4=5,4>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 605 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[13] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,6);
-          break;
-        case 13: // 5>4,3=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 630 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,7);
-          break;
-        case 11: // 3>4=5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 630 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[13] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,8);
-          break;
-        case 15: // 3=4=5
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 655 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,9);
-          break;
-        }
-      break;
-    case 9: // Ruprecht-Müller Case 4b
-      comparisonBits = 
-        (permlen[1] <= permlen[2] ? 1 : 0) | (permlen[1] >= permlen[2] ? 2 : 0) |
-        (permlen[2] <= permlen[3] ? 4 : 0) | (permlen[2] >= permlen[3] ? 8 : 0) |
-        (permlen[3] <= permlen[4] ? 16 : 0) | (permlen[3] >= permlen[4] ? 32 : 0) |
-        (permlen[1] <= permlen[4] ? 64 : 0) | (permlen[1] >= permlen[4] ? 128 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[1][i] + permuted[0][i])*0.375 + permuted[2][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[13][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 48) == 48 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 192) == 192 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[12][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[1][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(8);
-      switch (comparisonBits)
-        {
-        case 85: // 2>1,3>2,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,0);
-          break;
-        case 102: // 1>2,3>2,3>4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,1);
-          break;
-        case 170: // 1>2,2>3,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,2);
-          break;
-        case 153: // 2>1,2>3,4>3,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,3);
-          break;
-        case 90: // 1>2,2>3,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[9] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,4);
-          break;
-        case 105: // 2>1,2>3,3>4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[7] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,5);
-          break;
-        case 165: // 2>1,3>2,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[19] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,6);
-          break;
-        case 150: // 1>2,3>2,4>3,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 688 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[23] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,7);
-          break;
-        case 101: // 2>1,3>2,3>4,4>1
-          {
-            int alternates[] = { 713, 738, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,8);
-          break;
-        case 86: // 1>2,3>2,4>3,4>1
-          {
-            int alternates[] = {713, 738, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,9);
-          break;
-        case 154: // 1>2,2>3,4>3,1>4
-          {
-            int alternates[] = {713, 738, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 5, 1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,10);
-          break;
-        case 169: // 2>1,2>3,3>4,1>4
-          {
-            int alternates[] = {713, 738, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 15, -1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,11);
-          break;
-        case 89: // 2>1,2>3,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 763 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,12);
-          break;
-        case 166: // 1>2,3>2,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 763 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,13);
-          break;
-        case 103: // 1=2,3>2,3>4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,14);
-          break;
-        case 87: // 1=2,3>2,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,15);
-          break;
-        case 185: // 2>1,2>3,3=4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,16);
-          break;
-        case 186: // 1>2,2>3,3=4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,17);
-          break;
-        case 158: // 1>2,2=3,4>3,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[9] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,18);
-          break;
-        case 229: // 2>1,3>2,3>4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[7] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,19);
-          break;
-        case 233: // 2>1,2>3,3>4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[19] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,20);
-          break;
-        case 94: // 1>2,2=3,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 788 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[23] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,21);
-          break;
-        case 155: // 1=2,2>3,4>3,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,22);
-          break;
-        case 171: // 1=2,2>3,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,23);
-          break;
-        case 118: // 1>2,3>2,3=4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,24);
-          break;
-        case 117: // 2>1,3>2,3=4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,25);
-          break;
-        case 109: // 2>1,2=3,3>4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[9] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,26);
-          break;
-        case 218: // 1>2,2>3,4>3,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[7] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,27);
-          break;
-        case 214: // 1>2,3>2,4>3,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[19] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,28);
-          break;
-        case 173: // 2>1,2=3,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 825 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[23] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,29);
-          break;
-        case 91: // 1=2,2>3,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,30);
-          break;
-        case 167: // 1=2,3>2,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,31);
-          break;
-        case 182: // 1>2,3>2,3=4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,32);
-          break;
-        case 121: // 2>1,2>3,3=4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,33);
-          break;
-        case 93: // 2>1,2=3,4>3,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[9] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,34);
-          break;
-        case 217: // 2>1,2>3,4>3,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[7] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,35);
-          break;
-        case 230: // 1>2,3>2,3>4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[19] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,36);
-          break;
-        case 174: // 1>2,2=3,3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 862 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[23] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,37);
-          break;
-        case 119: // 1=2,3>2,3=4,4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 899 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,38);
-          break;
-        case 187: // 1=2>3=4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 899 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,39);
-          break;
-        case 222: // 1>2,2=3,4>3,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 899 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[9] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,40);
-          break;
-        case 237: // 2>1,2=3,3>4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 899 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[7] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,41);
-          break;
-        case 95: // 4>1=2=3,4>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 944 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,42);
-          break;
-        case 231: // 1=2,3>2,3>4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 944 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,43);
-          break;
-        case 190: // 1>2=3=4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 944 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,44);
-          break;
-        case 249: // 2>1,2>3,3=4,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 944 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,45);
-          break;
-        case 175: // 1=2=3>4,1>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 993 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,46);
-          break;
-        case 219: // 1=2>3,4>3,1=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 993 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,47);
-          break;
-        case 125: // 2>1,2=3=4>1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 993 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,48);
-          break;
-        case 246: // 1>2,3>2,3=4=1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 993 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,49);
-          break;
-        case 255: // 1=2=3=4=1
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 1042 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,50);
-          break;
-        }
-      break;
-    case 10: // Ruprecht-Müller Case 5
-      comparisonBits = 
-        (permlen[1] <= permlen[2] ? 1 : 0) | (permlen[1] >= permlen[2] ? 2 : 0) |
-        (permlen[3] <= permlen[4] ? 4 : 0) | (permlen[3] >= permlen[4] ? 8 : 0) |
-        0;
-      if ( (comparisonBits & 3) == 3 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[10][i] = (permuted[1][i] + permuted[0][i])*0.375 + permuted[2][i]/4.;
-          }
-        }
-      if ( (comparisonBits & 12) == 12 )
-        {
-        // Compute face point
-        for ( i=0; i<this->PointDimension[3]; i++ )
-          {
-          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
-          }
-        }
-      VTK_TESSELLATOR_INCR_CASE_COUNT(9);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 1107 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,0);
-      switch (comparisonBits)
-        {
-        case 10: // 1>2,3>4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 1116 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,1);
-          break;
-        case 5: // 2>1,4>3
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 1116 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,2);
-          break;
-        case 6: // 1>2,4>3
-          {
-            int alternates[] = { 1137, 1158, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,3);
-          break;
-        case 9: // 2>1,3>4
-          {
-            int alternates[] = {1137, 1158, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,4);
-          break;
-        case 11: // 1=2,3>4
-          {
-            int alternates[] = { 1179, 1212, 1245, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,5);
-          break;
-        case 7: // 1=2,4>3
-          {
-            int alternates[] = {1179, 1212, 1245, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[14] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,6);
-          break;
-        case 14: // 3=4,1>2
-          {
-            int alternates[] = {1179, 1212, 1245, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 5, 1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[5] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,7);
-          break;
-        case 13: // 3=4,2>1
-          {
-            int alternates[] = {1179, 1212, 1245, -1 };
-            outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 15, -1 ) );
-          }
-          outputPerm.push( MBRefiner::PermutationsFromIndex[15] );
-          outputSign.push( -1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,8);
-          break;
-        case 15: // 1=2,3=4
-          outputTets.push( MBRefiner::TetrahedralDecompositions + 1278 );
-          outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-          outputSign.push( 1 );
-          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,9);
-          break;
-        }
-      break;
-    case 11: // Ruprecht-Müller Case 6
-      VTK_TESSELLATOR_INCR_CASE_COUNT(10);
-      outputTets.push( MBRefiner::TetrahedralDecompositions + 1319 );
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(10,0);
-        {
-        int alternates[] = { 1336, 1353, 1370, -1 };
-        outputTets.push( MBRefiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
-        }
-      outputPerm.push( MBRefiner::PermutationsFromIndex[0] );
-      outputSign.push( 1 );
-      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(10,1);
-      break;
-      }
-
-    vtkIdType* tets;
-    vtkIdType  ntets;
-    vtkIdType* perm;
-    int        sgn;
-#ifdef PARAVIEW_DEBUG_TESSELLATOR
-    if ( outputTets.empty() )
-    {
-    cout << "Argh! Case " << C << " Perm " << P << " has no output!" << endl;
-    }
-#endif // PARAVIEW_DEBUG_TESSELLATOR
-    while ( ! outputTets.empty() )
-      {
-      tets = outputTets.top();
-      ntets = *tets;
-      tets++;
-      perm = outputPerm.top();
-      sgn = outputSign.top();
-
-      outputTets.pop();
-      outputPerm.pop();
-      outputSign.pop();
-
-      int t;
-      if ( sgn > 0 )
-        {
-        for ( t = 0; t < ntets; ++t )
-          {
-          this->AdaptivelySample3Facet(
-            permuted[ perm[ tets[0] ] ], permuted[ perm[ tets[1] ] ],
-            permuted[ perm[ tets[2] ] ], permuted[ perm[ tets[3] ] ],
-            maxDepth );
-          tets += 4;
-          }
-        }
-      else
-        {
-        // we have an inverted tet... reverse the first 2 vertices
-        // so the orientation is positive.
-        for ( t = 0; t < ntets; ++t )
-          {
-          this->AdaptivelySample3Facet(
-            permuted[ perm[ tets[1] ] ], permuted[ perm[ tets[0] ] ],
-            permuted[ perm[ tets[2] ] ], permuted[ perm[ tets[3] ] ],
-            maxDepth );
-          tets += 4;
-          }
-        }
-      }
-    }
-}
-

Deleted: MOAB/trunk/tools/refiner/MBRefinerTagManager.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBRefinerTagManager.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBRefinerTagManager.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,522 +0,0 @@
-#include "MBRefinerTagManager.hpp"
-
-#include "MBInterface.hpp"
-#include "MBParallelComm.hpp"
-#include "MBParallelConventions.h"
-#include "MBTagConventions.hpp"
-
-#include <iostream>
-#include <stdexcept>
-#include <assert.h>
-
-#undef MB_DEBUG
-
-/// Construct an evaluator.
-MBRefinerTagManager::MBRefinerTagManager( MBInterface* in_mesh, MBInterface* out_mesh )
-  : shared_procs_in( 5 * MAX_SHARING_PROCS, -1 ), shared_procs_out( MAX_SHARING_PROCS, -1 )
-{
-  assert( in_mesh );
-  if ( ! out_mesh )
-    out_mesh = in_mesh;
-
-  this->input_mesh = in_mesh;
-  this->output_mesh = out_mesh;
-  this->reset_vertex_tags();
-  this->reset_element_tags();
-  MBParallelComm* ipcomm = MBParallelComm::get_pcomm( this->input_mesh, 0 );
-  MBParallelComm* opcomm = 0;
-  if ( this->output_mesh != this->input_mesh )
-    {
-    opcomm = MBParallelComm::get_pcomm( this->output_mesh, 0 );
-    if ( ! opcomm )
-      {
-#ifdef MB_DEBUG
-      std::cout << "Creating opcomm: " << opcomm << "\n";
-#endif // MB_DEBUG
-      opcomm = new MBParallelComm( this->output_mesh, MPI_COMM_WORLD );
-      }
-    }
-  else
-    {
-    opcomm = ipcomm;
-    }
-
-  if ( ipcomm )
-    {
-    ipcomm->get_shared_proc_tags(
-      this->tag_ipsproc, this->tag_ipsprocs,
-      this->tag_ipshand, this->tag_ipshands,
-      this->tag_ipstatus );
-    }
-  else
-    {
-    this->tag_ipsproc = this->tag_ipsprocs = 0;
-    this->tag_ipshand = this->tag_ipshands = 0;
-    this->tag_ipstatus = 0;
-    }
-
-  if ( opcomm )
-    {
-    opcomm->get_shared_proc_tags(
-      this->tag_opsproc, this->tag_opsprocs,
-      this->tag_opshand, this->tag_opshands,
-      this->tag_opstatus );
-    }
-  else
-    {
-    this->tag_opsproc = this->tag_opsprocs = 0;
-    this->tag_opshand = this->tag_opshands = 0;
-    this->tag_opstatus = 0;
-    }
-
-  this->rank =
-    ipcomm ? ipcomm->proc_config().proc_rank() :
-    ( opcomm ? opcomm->proc_config().proc_rank() : 0 );
-
-  // Create the mesh global ID tags if they aren't already there.
-  int zero = 0;
-  MBErrorCode result;
-  result = this->input_mesh->tag_create(
-    GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, this->tag_igid, &zero, true );
-  if ( result != MB_SUCCESS && result != MB_ALREADY_ALLOCATED )
-    {
-    throw new std::logic_error( "Unable to find input mesh global ID tag \"" GLOBAL_ID_TAG_NAME "\"" );
-    }
-  result = this->output_mesh->tag_create(
-    GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, this->tag_ogid, &zero, true );
-  if ( result != MB_SUCCESS && result != MB_ALREADY_ALLOCATED )
-    {
-    throw new std::logic_error( "Unable to find/create output mesh global ID tag \"" GLOBAL_ID_TAG_NAME "\"" );
-    }
-
-#ifdef MB_DEBUG
-  std::cout
-    << "psproc:  " << this->tag_ipsproc  << ", " << this->tag_opsproc << "\n"
-    << "psprocs: " << this->tag_ipsprocs << ", " << this->tag_opsprocs << "\n"
-    << "pshand:  " << this->tag_ipshand  << ", " << this->tag_opshand << "\n"
-    << "pshands: " << this->tag_ipshands << ", " << this->tag_opshands << "\n"
-    << "pstatus: " << this->tag_ipstatus << ", " << this->tag_opstatus << "\n"
-    << "gid:     " << this->tag_igid     << ", " << this->tag_ogid     << "\n";
-#endif // MB_DEBUG
-}
-
-/// Destruction is virtual so subclasses may clean up after refinement.
-MBRefinerTagManager::~MBRefinerTagManager()
-{
-}
-
-/**\fn bool MBRefinerTagManager::evaluate_edge( \
-  *         const double* p0, const void* t0, double* p1, void* t1, const double* p2, const void* t2 )
-  *\brief Returns true if the edge \a p0 - \a p2 should be subdivided, false otherwise.
-  *
-  * The arguments \a p0, \a p1, and \a p2 are all pointers to arrays of 6 doubles each
-  * while the arguments \a t0, \a t1, and \a t2 are all pointers to arrays of tag data
-  * defined at the corresponding point. While the endpoints \a p0 and \a p2 are
-  * immutable, the mid-edge point coordinates \a p1 and tag data \a t1 may be altered by
-  * evaluate_edge(). Altered values will be ignored if evaluate_edge() returns false.
-  * Be careful to ensure that all calls to evaluate_edge() perform identical modifications
-  * given identical input values!
-  *
-  * A list of tags passed in \a t0, \a t1, and \a t2 is stored in the \a input_vertex_tags member.
-  * (for tag handles defined on the input mesh) and the \a output_vertex_tags (for the same tag handles
-  * defined on the output mesh).
-  * The vertex_size member stores the total length of data associated with each pointer (in bytes).
-  * Subclasses may access input_vertex_tags, output_vertex_tags, and vertex_size directly;
-  * the refiner uses public methods to set them before any entities are evaluated for subdivision.
-  * The output_vertex_tags member is populated when the refiner calls create_output_tags().
-  * When the input mesh and output mesh pointers are identical, this simply copies input_vertex_tags
-  * to output_vertex_tags.
-  * When the pointers are distinct, tags are created on the output mesh.
-  */
-
-/// Clear the list of tag values that will appear past the vertex coordinates in \a p0, \a p1, and \a p2.
-void MBRefinerTagManager::reset_vertex_tags()
-{
-  this->vertex_size = 0;
-  this->input_vertex_tags.clear();
-  this->output_vertex_tags.clear();
-}
-
-/** Add a tag to the list of tag values that will appear past the vertex coordinates.
-  * The return value is the offset into each vertex coordinate pointer (\a p0, \a p1, \a p2) where the
-  * tag value(s) will be stored.
-  */
-int MBRefinerTagManager::add_vertex_tag( MBTag tag_handle )
-{
-  int offset = this->vertex_size; // old size is offset of tag being added
-  int tag_size;
-  MBTagType tagType;
-  if ( this->input_mesh->tag_get_size( tag_handle, tag_size ) != MB_SUCCESS )
-    return -1;
-
-  if ( this->input_mesh->tag_get_type( tag_handle, tagType ) != MB_SUCCESS )
-    return -1;
-
-  if ( tagType == MB_TAG_BIT )
-    {
-    // Pad any bit tags to a size in full bytes.
-    tag_size = ( tag_size % 8 ? 1 : 0 ) + ( tag_size / 8 );
-    }
-
-  // Now pad so that the next tag will be word-aligned:
-  while ( tag_size % sizeof(int) )
-    ++tag_size;
-
-  this->vertex_size += tag_size;
-
-  this->input_vertex_tags.push_back( std::pair< MBTag, int >( tag_handle, offset ) );
-  return offset;
-}
-
-/**\fn int MBRefinerTagManager::get_vertex_tag_size()
-  *\brief Return the number of bytes to allocate for tag data per point.
-  */
-
-/**\fn int MBRefinerTagManager::get_number_of_vertex_tags() const
-  *\brief Return the number of tags that will be output with each new vertex.
-  */
-
-/// Clear the list of tag values that will appear past the element coordinates in \a p0, \a p1, and \a p2.
-void MBRefinerTagManager::reset_element_tags()
-{
-  this->element_size = 0;
-  this->input_element_tags.clear();
-  this->output_element_tags.clear();
-  this->element_tag_data.clear();
-}
-
-/** Add a tag to the list of tag values that will appear past the element coordinates.
-  * The return value is the offset into each element coordinate pointer (\a p0, \a p1, \a p2) where the
-  * tag value(s) will be stored.
-  */
-int MBRefinerTagManager::add_element_tag( MBTag tag_handle )
-{
-  int offset = this->element_size; // old size is offset of tag being added
-  int tag_size;
-  MBTagType tagType;
-  if ( this->input_mesh->tag_get_size( tag_handle, tag_size ) != MB_SUCCESS )
-    return -1;
-
-  if ( this->input_mesh->tag_get_type( tag_handle, tagType ) != MB_SUCCESS )
-    return -1;
-
-  if ( tagType == MB_TAG_BIT )
-    {
-    // Pad any bit tags to a size in full bytes.
-    tag_size = ( tag_size % 8 ? 1 : 0 ) + ( tag_size / 8 );
-    }
-
-  // Now pad so that the next tag will be word-aligned:
-  while ( tag_size % sizeof(int) )
-    ++tag_size;
-
-  this->element_size += tag_size;
-  this->element_tag_data.resize( this->element_size );
-
-  this->input_element_tags.push_back( std::pair< MBTag, int >( tag_handle, offset ) );
-  return offset;
-}
-
-/**\fn int MBRefinerTagManager::get_element_tag_size()
-  *\brief Return the number of bytes to allocate for tag data per point.
-  */
-
-/**\fn int MBRefinerTagManager::get_number_of_element_tags() const
-  *\brief Return the number of tags that will be output with each new element.
-  */
-
-/**\brief Populate the list of output tags to match the list of input tags.
-  *
-  * When the input mesh and output mesh pointers are identical, this simply copies the list of input tags.
-  * When the two meshes are distinct, the corresponding tags are created on the output mesh.
-  */
-void MBRefinerTagManager::create_output_tags()
-{
-  if ( this->input_mesh == this->output_mesh )
-    {
-    this->output_vertex_tags = this->input_vertex_tags;
-    this->output_element_tags = this->input_element_tags;
-    return;
-    }
-
-  std::vector< std::pair< MBTag, int > >::iterator it;
-  for ( it = this->input_vertex_tags.begin(); it != this->input_vertex_tags.end(); ++ it )
-    {
-    this->create_tag_internal( it->first, it->second );
-    }
-}
-
-/**\brief Return the tag handle and its offset in the array of tag data of each vertex.
-  *
-  * @param[in] i An index into the list of tags for the vertex.
-  * @param[out] tag The tag handle on the input mesh for the $i$-th vertex tag.
-  * @param[out] byte_offset The offset (in bytes) of the start of this tag's data in a vertex tag record.
-  */
-void MBRefinerTagManager::get_input_vertex_tag( int i, MBTag& tag, int& byte_offset )
-{
-  std::vector< std::pair< MBTag, int > >::iterator it = this->input_vertex_tags.begin() + i;
-  tag = it->first;
-  byte_offset = it->second;
-}
-
-/**\brief Return the tag handle and its offset in the array of tag data of each vertex.
-  *
-  * @param[in] i An index into the list of tags for the vertex.
-  * @param[out] tag The tag handle on the output mesh for the $i$-th vertex tag.
-  * @param[out] byte_offset The offset (in bytes) of the start of this tag's data in a vertex tag record.
-  */
-void MBRefinerTagManager::get_output_vertex_tag( int i, MBTag& tag, int& byte_offset )
-{
-  std::vector< std::pair< MBTag, int > >::iterator it = this->output_vertex_tags.begin() + i;
-  tag = it->first;
-  byte_offset = it->second;
-}
-
-/**\brief Retrieve the global ID of each input entity and push it onto the output vector.
-  *
-  * The \a gids array is emptied by this call before any new values are added.
-  * Note that this routine fetches global IDs from the input mesh, not the output mesh;
-  * your entity handles must be from the input mesh.
-  *
-  * @param[in] ents An array of entities in the input mesh whose global IDs you desire
-  * @param[in] n The number of entities in the \a ents array.
-  * @param[out] gids A vector to contain the resulting global IDs.
-  * @retval A MOAB error code as supplied by the MBInterface::tag_get_data() call.
-  */
-int MBRefinerTagManager::get_input_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids )
-{
-  int stat;
-  gids.clear();
-  for ( int i = 0; i < n; ++ i )
-    {
-    int gid = -1;
-    stat |= this->input_mesh->tag_get_data( this->tag_igid, ents + i, 1, &gid );
-    gids.push_back( gid );
-    }
-  return stat;
-}
-
-/**\brief Retrieve the global ID of each output entity and push it onto the output vector.
-  *
-  * The \a gids array is emptied by this call before any new values are added.
-  * Note that this routine fetches global IDs from the output mesh, not the input mesh;
-  * your entity handles must be from the output mesh.
-  * Also, be aware that many output entities will not have global IDs assigned;
-  * only those vertices which exist in the input mesh are guaranteed to have global IDs
-  * assigned to them -- vertices that only exist in the output mesh and all higher-dimensional
-  * output entities have no global IDs assigned until after a complete subdivision pass has been made.
-  *
-  * @param[in] ents An array of entities in the output mesh whose global IDs you desire
-  * @param[in] n The number of entities in the \a ents array.
-  * @param[out] gids A vector to contain the resulting global IDs.
-  * @retval A MOAB error code as supplied by the MBInterface::tag_get_data() call.
-  */
-int MBRefinerTagManager::get_output_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids )
-{
-  int stat;
-  gids.clear();
-  for ( int i = 0; i < n; ++ i )
-    {
-    int gid = -1;
-    stat |= this->output_mesh->tag_get_data( this->tag_igid, ents + i, 1, &gid );
-    gids.push_back( gid );
-    }
-  return stat;
-}
-
-/**\brief Assign a global ID to an output entity.
-  *
-  * @param[in] ent The entity whose ID will be set
-  * @param[out] id The global ID
-  * @retval An error code as returned by MBInterface::tag_set_data().
-  */
-int MBRefinerTagManager::set_gid( MBEntityHandle ent, int gid )
-{
-  return this->output_mesh->tag_set_data( this->tag_ogid, &ent, 1, &gid );
-}
-
-/**\brief Copy a global ID from an entity of the input mesh to an entity of the output mesh.
-  *
-  * @param[in] ent_input An entity on the input mesh with a global ID.
-  * @param[in] ent_output An entity on the output mesh whose global ID should be set.
-  * @retval               Normally MB_SUCCESS, but returns other values if tag_get_data or tag_set_data fail.
-  */
-int MBRefinerTagManager::copy_gid( MBEntityHandle ent_input, MBEntityHandle ent_output )
-{
-  int gid = -1;
-  int status;
-  if ( ( status =  this->input_mesh->tag_get_data( this->tag_igid, &ent_input, 1, &gid ) ) == MB_SUCCESS )
-    {
-    status = this->output_mesh->tag_set_data( this->tag_ogid, &ent_output, 1, &gid );
-    }
-  return status;
-}
-
-/**\brief Set parallel status and sharing process list on an entity.
-  *
-  * This sets tag values for the PARALLEL_STATUS and one of PARALLEL_SHARED_PROC or PARALLEL_SHARED_PROCS tags
-  * if \a procs contains any processes (the current process is assumed <b>not</b> to be set in \a procs).
-  *
-  * @param[in] ent_handle The entity whose information will be set
-  * @param[in] procs The set of sharing processes.
-  */
-void MBRefinerTagManager::set_sharing( MBEntityHandle ent_handle, MBProcessSet& procs )
-{
-  int pstat;
-  if ( procs.get_process_members( this->rank, this->shared_procs_out ) )
-    pstat = PSTATUS_SHARED | PSTATUS_INTERFACE;
-  else
-    pstat = PSTATUS_SHARED | PSTATUS_INTERFACE | PSTATUS_NOT_OWNED;
-  if ( this->shared_procs_out[0] >= 0 )
-    {
-    // assert( MAX_SHARING_PROCS > 1 );
-    // Since get_process_members pads to MAX_SHARING_PROCS, this will be work:
-    if ( this->shared_procs_out[1] <= 0 )
-      {
-      //std::cout << "  (proc )";
-      this->output_mesh->tag_set_data( this->tag_opsproc, &ent_handle, 1, &this->shared_procs_out[0] );
-      this->output_mesh->tag_set_data( this->tag_opstatus, &ent_handle, 1, &pstat );
-      }
-    else
-      {
-      //std::cout << "  (procS)";
-      this->output_mesh->tag_set_data( this->tag_opsprocs, &ent_handle, 1, &this->shared_procs_out[0] );
-      this->output_mesh->tag_set_data( this->tag_opstatus, &ent_handle, 1, &pstat );
-      }
-    }
-  else
-    {
-    //std::cout << "  (none )";
-    }
-  //std::cout << " new pstat: " << pstat << "\n";
-}
-
-/**\brief Determine the subset of processes which all share the specified entities.
-  *
-  * This is used to determine which processes an output entity should reside on when
-  * it is defined using several input entities (such as vertices).
-  */
-void MBRefinerTagManager::get_common_processes(
-  int num, const MBEntityHandle* src, MBProcessSet& common_shared_procs, bool on_output_mesh )
-{
-  MBInterface* mesh;
-  MBTag psproc;
-  MBTag psprocs;
-  if ( on_output_mesh )
-    {
-    mesh = this->output_mesh;
-    psproc = this->tag_opsproc;
-    psprocs = this->tag_opsprocs;
-    }
-  else
-    {
-    mesh = this->input_mesh;
-    psproc = this->tag_ipsproc;
-    psprocs = this->tag_ipsprocs;
-    }
-  bool first_ent = true;
-  common_shared_procs.clear();
-  for ( int i = 0; i < num; ++ i )
-    {
-    MBEntityHandle ent_in = src[i];
-    //std::cout << "<(" << ent_in << ")>";
-    int stat;
-    bool got = false;
-    this->current_shared_procs.clear();
-    stat = mesh->tag_get_data( psproc, &ent_in, 1, &this->shared_procs_in[0] );
-    if ( stat == MB_SUCCESS && this->shared_procs_in[0] != -1 )
-      {
-      got = true;
-      //std::cout << " s" << this->rank << " s" << this->shared_procs_in[0] << " | ";
-      this->shared_procs_in[1] = -1;
-      }
-    stat = mesh->tag_get_data( psprocs, &ent_in, 1, &this->shared_procs_in[0] );
-    if ( stat == MB_SUCCESS && this->shared_procs_in[0] != -1 )
-      {
-      got = true;
-      int i;
-      /*
-      for ( i = 0; i < MAX_SHARING_PROCS && this->shared_procs_in[i] != -1; ++ i )
-        std::cout << " m" << this->shared_procs_in[i];
-      std::cout << " | ";
-      */
-      }
-    if ( got )
-      {
-      this->current_shared_procs.set_process_members( this->shared_procs_in );
-      this->current_shared_procs.set_process_member( this->rank );
-      if ( first_ent )
-        {
-        common_shared_procs.unite( this->current_shared_procs );
-        first_ent = false;
-        }
-      else
-        {
-        common_shared_procs.intersect( this->current_shared_procs );
-        }
-      }
-    else
-      {
-      // not shared, but everthing exists on this process, so make sure that bit is set...
-      common_shared_procs.set_process_member( this->rank );
-      }
-    }
-#ifdef MB_DEBUG
-  std::cout << "    Common procs " << common_shared_procs;
-  std::cout << "\n";
-#endif // MB_DEBUG
-}
-
-void MBRefinerTagManager::create_tag_internal( MBTag tag_in, int offset )
-{
-  std::pair< MBTag, int > tag_rec;
-  std::vector< char > tag_default;
-  std::string tag_name;
-  MBTagType tag_type;
-  MBDataType tag_data_type;
-  int tag_size;
-
-  tag_rec.second = offset;
-  this->input_mesh->tag_get_name( tag_in, tag_name );
-  this->input_mesh->tag_get_size( tag_in, tag_size );
-  this->input_mesh->tag_get_type( tag_in, tag_type );
-  this->input_mesh->tag_get_data_type( tag_in, tag_data_type );
-  this->input_mesh->tag_get_default_value( tag_in, (void*) &tag_default[0] );
-  tag_default.resize( tag_size );
-  MBErrorCode res = this->output_mesh->tag_create(
-    tag_name.c_str(), tag_size, tag_type, tag_data_type, tag_rec.first, (void*) &tag_default[0], true );
-#ifdef MB_DEBUG
-  std::cout
-    << "Creating output tag: \"" << tag_name.c_str() << "\" handle: " << tag_rec.first
-    << " input handle: " << tag_in << "\n";
-#endif // MB_DEBUG
-  if ( res == MB_FAILURE )
-    {
-    std::cerr
-      << "Could not create output tag name: \"" << tag_name.c_str() << "\" type: "
-      << tag_type << " data type: " << tag_data_type << "\n";
-    }
-  else
-    {
-    this->output_vertex_tags.push_back( tag_rec );
-    }
-}
-
-void MBRefinerTagManager::set_element_tags_from_ent( MBEntityHandle ent_input )
-{
-  std::vector< std::pair< MBTag, int > >::iterator it;
-  for ( it = this->input_element_tags.begin(); it != this->input_element_tags.end(); ++ it )
-    {
-    this->input_mesh->tag_get_data( it->first, &ent_input, 1, &this->element_tag_data[it->second] );
-    }
-}
-
-void MBRefinerTagManager::assign_element_tags( MBEntityHandle ent_output )
-{
-  std::vector< std::pair< MBTag, int > >::iterator it;
-  for ( it = this->output_element_tags.begin(); it != this->output_element_tags.end(); ++ it )
-    {
-    this->output_mesh->tag_set_data( it->first, &ent_output, 1, &this->element_tag_data[it->second] );
-    }
-}
-

Deleted: MOAB/trunk/tools/refiner/MBRefinerTagManager.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBRefinerTagManager.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBRefinerTagManager.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,123 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBRefinerTagManager
-  *
-  * This a class that manages which tags an edge refiner should include
-  * on output vertices created during mesh refinement.
-  * The 
-  *
-  * \author David Thompson
-  *
-  * \date 12 June 2008
-  */
-#ifndef MB_REFINERTAGMANAGER_H
-#define MB_REFINERTAGMANAGER_H
-
-#include "MBTypes.h" // for MB_DLL_EXPORT
-
-#include "MBProcessSet.hpp"
-
-#include <vector>
-
-class MBInterface;
-
-class MB_DLL_EXPORT MBRefinerTagManager
-{
-public:
-  MBRefinerTagManager( MBInterface* in_mesh, MBInterface* out_mesh );
-  virtual ~MBRefinerTagManager();
-
-  void reset_vertex_tags();
-  int add_vertex_tag( MBTag tag_handle );
-  int get_vertex_tag_size() const { return this->vertex_size; }
-  int get_number_of_vertex_tags() const { return this->input_vertex_tags.size(); }
-
-  void reset_element_tags();
-  int add_element_tag( MBTag tag_handle );
-  int get_element_tag_size() const { return this->element_size; }
-  int get_number_of_element_tags() const { return this->input_element_tags.size(); }
-
-  void create_output_tags();
-
-  void get_input_vertex_tag( int i, MBTag& tag, int& byte_offset );
-  void get_output_vertex_tag( int i, MBTag& tag, int& byte_offset );
-
-  void get_input_element_tag( int i, MBTag& tag, int& byte_offset );
-  void get_output_element_tag( int i, MBTag& tag, int& byte_offset );
-
-  MBInterface* get_input_mesh() { return this->input_mesh; }
-  MBInterface* get_output_mesh() { return this->output_mesh; }
-
-  MBTag input_parallel_status() { return this->tag_ipstatus; }
-  MBTag input_shared_proc() { return this->tag_ipsproc; }
-  MBTag input_shared_procs() { return this->tag_ipsprocs; }
-
-  int get_input_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids );
-  int get_output_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids );
-  int set_gid( MBEntityHandle ent, int gid );
-  int copy_gid( MBEntityHandle ent_input, MBEntityHandle ent_output );
-
-  void set_sharing( MBEntityHandle ent_handle, MBProcessSet& procs );
-  void get_common_processes( int num, const MBEntityHandle* src, MBProcessSet& common_shared_procs, bool on_output_mesh = true );
-
-  void set_element_tags_from_ent( MBEntityHandle ent_input );
-  void assign_element_tags( MBEntityHandle ent_output );
-
-  void set_element_procs_from_ent( MBEntityHandle ent_input )
-    {
-    this->get_common_processes( 1, &ent_input, this->current_element_procs, false );
-    }
-  MBProcessSet& get_element_procs()
-    {
-    return this->current_element_procs;
-    }
-  void set_element_sharing( MBEntityHandle ent_output )
-    {
-    this->set_sharing( ent_output, this->current_element_procs );
-    }
-
-protected:
-  void create_tag_internal( MBTag, int );
-
-  std::vector< std::pair< MBTag, int > > input_vertex_tags;
-  std::vector< std::pair< MBTag, int > > output_vertex_tags;
-  std::vector< std::pair< MBTag, int > > input_element_tags;
-  std::vector< std::pair< MBTag, int > > output_element_tags;
-  int vertex_size;
-  int element_size;
-  MBInterface* input_mesh;
-  MBInterface* output_mesh;
-  MBTag tag_ipstatus; // Handle for PARALLEL_STATUS on mesh_in
-  MBTag tag_ipsprocs; // Handle for PARALLEL_SHARED_PROCS on mesh_in
-  MBTag tag_ipsproc;  // Handle for PARALLEL_SHARED_PROC on mesh_in
-  MBTag tag_ipshands; // Handle for PARALLEL_SHARED_HANDLES on mesh_in
-  MBTag tag_ipshand;  // Handle for PARALLEL_SHARED_HANDLE on mesh_in
-  MBTag tag_igid;     // Handle for global IDs on mesh_in
-  MBTag tag_opstatus; // Handle for PARALLEL_STATUS on mesh_out
-  MBTag tag_opsprocs; // Handle for PARALLEL_SHARED_PROCS on mesh_out
-  MBTag tag_opsproc;  // Handle for PARALLEL_SHARED_PROC on mesh_out
-  MBTag tag_opshands; // Handle for PARALLEL_SHARED_HANDLES on mesh_out
-  MBTag tag_opshand;  // Handle for PARALLEL_SHARED_HANDLE on mesh_out
-  MBTag tag_ogid;     // Handle for global IDs on mesh_out
-  int rank;
-  std::vector<int> shared_procs_in; // Used to hold procs sharing an input vert.
-  std::vector<int> shared_procs_out; // Used to hold procs sharing an output entity.
-  MBProcessSet current_shared_procs; // Holds process list as it is being accumulated
-  MBProcessSet current_element_procs; // The list of processes which should share an output element.
-  std::vector<char> element_tag_data; // Holds tag data for per-element tags
-};
-
-#endif // MB_REFINERTAGMANAGER_H

Deleted: MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,2321 +0,0 @@
-#include "MBSimplexTemplateRefiner.hpp"
-
-#include "MBEdgeSizeEvaluator.hpp"
-#include "MBRefinerTagManager.hpp"
-
-#include "MBInterface.hpp"
-
-#include <iostream>
-#include <stack>
-
-// Static arrays holding parametric coordinates of element vertices
-static double MBVertexParametric[] = { 0., 0., 0. };
-static double MBEdgeParametric[]   = { 0., 0., 0.,   1., 0., 0. };
-static double MBTriParametric[]    = { 0., 0., 0.,   1., 0., 0.,   0., 1., 0. };
-static double MBTetParametric[]    = { 0., 0., 0.,   1., 0., 0.,   0., 1., 0.,   0., 0., 1. };
-
-#ifdef MB_DEBUG_TESSELLATOR
-#  define MB_TESSELLATOR_INCR_CASE_COUNT(cs) this->case_counts[cs]++
-#  define MB_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc) this->subcase_counts[cs][sc]++
-#else // MB_DEBUG_TESSELLATOR
-#  define MB_TESSELLATOR_INCR_CASE_COUNT(cs)
-#  define MB_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc)
-#endif // MB_DEBUG_TESSELLATOR
-
-/// Construct a template refiner.
-MBSimplexTemplateRefiner::MBSimplexTemplateRefiner()
-{
-  this->tag_manager = 0;
-  this->tag_assigner = new MBSimplexTemplateTagAssigner( this );
-  this->corner_coords.resize( 6 * 8 ); // Hex has 8 verts w/ 6 coordinates each
-  this->corner_tags.resize( 8 ); // Hex has 8 verts (this is a pointer, not the actual tag data)
-  this->corner_handles.resize( 8 ); // Hex has 8 verts (this is a pointer, not actual hash data)
-  this->input_is_output = false; // Until we know better
-}
-
-/// Empty destructor for good form.
-MBSimplexTemplateRefiner::~MBSimplexTemplateRefiner()
-{
-  delete this->tag_assigner;
-}
-
-/**\brief Stream a single mesh entity through the refiner.
-  */
-bool MBSimplexTemplateRefiner::refine_entity( MBEntityType etyp, MBEntityHandle entity )
-{
-  this->reset_heap_pointers();
-  bool rval = true;
-  const MBEntityHandle* conn;
-  int num_nodes;
-  MBInterface* imesh = this->tag_manager->get_input_mesh();
-  if ( imesh->get_connectivity( entity, conn, num_nodes ) != MB_SUCCESS )
-    {
-    return false;
-    }
-  this->corner_coords.resize( 6 * num_nodes );
-  this->corner_tags.resize( num_nodes );
-  this->corner_handles.resize( num_nodes );
-
-  // Have to make num_nodes calls to get_coords() because we need xyz interleaved with rst coords.
-  MBTag tag_handle;
-  int tag_offset;
-  void* tag_data;
-  for ( int n = 0; n < num_nodes; ++ n )
-    {
-    if ( imesh->get_coords( &conn[n], 1, &corner_coords[6 * n + 3] ) != MB_SUCCESS )
-      {
-      return false;
-      }
-    tag_data = this->heap_tag_storage();
-    for ( int i = 0; i < this->tag_manager->get_number_of_vertex_tags(); ++ i )
-      {
-      this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
-      if ( imesh->tag_get_data( tag_handle, &conn[n], 1, (char*)tag_data + tag_offset ) != MB_SUCCESS )
-        {
-        return false;
-        }
-      }
-    if ( this->input_is_output )
-      {
-      this->corner_handles[n] = conn[n];
-      }
-    else
-      {
-      this->corner_handles[n] = this->output_functor->map_vertex( conn[n], &corner_coords[6 * n], tag_data );
-#if 0
-      std::cout << "#+# " << this->corner_handles[n] << " < "
-        << corner_coords[ 6 * n + 3 ] << ", "
-        << corner_coords[ 6 * n + 4 ] << ", "
-        << corner_coords[ 6 * n + 5 ] << ">\n";
-#endif // 0
-      }
-    this->corner_tags[n] = tag_data;
-    }
-
-  switch ( etyp )
-    {
-    case MBVERTEX:
-      this->assign_parametric_coordinates( 1, MBVertexParametric, &this->corner_coords[0] );
-      this->refine_0_simplex( &this->corner_coords[0], this->corner_tags[0], this->corner_handles[0] );
-      rval = false;
-      break;
-    case MBEDGE:
-      this->assign_parametric_coordinates( 2, MBEdgeParametric, &this->corner_coords[0] );
-      rval = this->refine_1_simplex( this->maximum_number_of_subdivisions,
-        &this->corner_coords[0], this->corner_tags[0], this->corner_handles[0],
-        &this->corner_coords[6], this->corner_tags[1], this->corner_handles[1] );
-      break;
-    case MBTRI:
-      this->assign_parametric_coordinates( 3, MBTriParametric, &this->corner_coords[0] );
-      rval = this->refine_2_simplex( this->maximum_number_of_subdivisions, 7,
-        &this->corner_coords[ 0], this->corner_tags[0], this->corner_handles[0],
-        &this->corner_coords[ 6], this->corner_tags[1], this->corner_handles[1],
-        &this->corner_coords[12], this->corner_tags[2], this->corner_handles[2] );
-      break;
-    case MBQUAD:
-      std::cerr << "Quadrilaterals not handled yet\n";
-      rval = false;
-      break;
-    case MBPOLYGON:
-      std::cerr << "Polygons not handled yet\n";
-      rval = false;
-      break;
-    case MBTET:
-      this->assign_parametric_coordinates( 4, MBTetParametric, &this->corner_coords[0] );
-      rval = this->refine_3_simplex( this->maximum_number_of_subdivisions,
-        &this->corner_coords[ 0], this->corner_tags[0], this->corner_handles[0],
-        &this->corner_coords[ 6], this->corner_tags[1], this->corner_handles[1],
-        &this->corner_coords[12], this->corner_tags[2], this->corner_handles[2],
-        &this->corner_coords[18], this->corner_tags[3], this->corner_handles[3]
-      );
-      break;
-    case MBPYRAMID:
-      std::cerr << "Pyramid schemes not handled yet\n";
-      rval = false;
-      break;
-    case MBPRISM:
-      std::cerr << "Prisms not handled yet\n";
-      rval = false;
-      break;
-    case MBKNIFE:
-      std::cerr << "Knifahedra not handled yet\n";
-      rval = false;
-      break;
-    case MBHEX:
-      std::cerr << "Hexahedra not handled yet\n";
-      rval = false;
-      break;
-    case MBPOLYHEDRON:
-      std::cerr << "Polyhedra not handled yet\n";
-      rval = false;
-      break;
-    case MBENTITYSET:
-      std::cerr <<
-        "How should entity sets be handled? We might iterate over its entries or skip it."
-        "Must coordinate with MBMeshRefiner's loop over entities...\n";
-      rval = false;
-      break;
-    case MBMAXTYPE:
-      rval = false;
-      break;
-    }
-  return rval;
-}
-
-/**\brief Set the function object used to decide which tag values an edge or face midpoint is assigned.
-  *
-  * This will change the tag assigner's edge size evaluator to match the refiner's.
-  * @param[in] ta The new tag assigner. This must be non-NULL.
-  * @retval True if the tag assigner was changed and false otherwise.
-  */
-bool MBSimplexTemplateRefiner::set_tag_assigner( MBSimplexTemplateTagAssigner* ta )
-{ 
-  if ( ! ta || ta == this->tag_assigner )
-    return false;
-
-  this->tag_assigner = ta; 
-  return true;
-}
-
-
-/**\brief Set the function object used to decide whether an edge is subdivided or not.
-  */
-bool MBSimplexTemplateRefiner::prepare( MBRefinerTagManager* tmgr, MBEntityRefinerOutputFunctor* ofunc )
-{ 
-  this->tag_manager = tmgr;
-  this->tag_assigner->set_tag_manager( tmgr );
-  this->input_is_output = ( this->tag_manager->get_input_mesh() == this->tag_manager->get_output_mesh() );
-  //this->tag_assigner->set_edge_size_evaluator( this->edge_size_evaluator );
-  return this->MBEntityRefiner::prepare( tmgr, ofunc );
-}
-
-/**\fn unsigned long MBSimplexTemplateRefiner::get_heap_size_bound( int max_recursions ) const
-  *\brief Bound on the number of new vertices used to allocate the heap.
-  *
-  * This bound is based on a hexahedron that is divided into 48 tetrahedra (a point is added to
-  * the center of each face so that compatible boundaries are guaranteed on neighboring hexahedra),
-  * each of which has 4 edges.
-  */
-
-/**\brief "Refine" a vertex by passing it through to the output.
-  *
-  * FIXME: There is some question as to whether this should pass vertices through
-  * since there does not appear to be a distinction between vertices as points
-  * in space and vertices as degrees-of-freedom in a mesh (i.e. a vertex that is
-  * treated as a lumped-parameter model).
-  */
-void MBSimplexTemplateRefiner::refine_0_simplex( const double* v0, const void* t0, MBEntityHandle h0 )
-{
-  // Ignore these arguments... the caller is responsible for calling the output functor to ensure the
-  // vertex exists on the output.
-  (void) v0;
-  (void) t0;
-
-  (*this->output_functor)( h0 );
-  (*this->output_functor)( MBVERTEX );
-}
-
-/**\brief Refine an edge.
-  */
-bool MBSimplexTemplateRefiner::refine_1_simplex(
-  int max_depth,
-  const double* v0, const void* t0, MBEntityHandle h0,
-  const double* v1, const void* t1, MBEntityHandle h1 )
-{
-  bool edge_code = false;
-
-  double* midptc;
-  void* midptt;
-  // NB: If support for multiple recursive subdivisions (without a merge in between) is required,
-  //     this will have to change as it assumes that h0 and h1 have only a single entry.
-  MBEntityHandle midpth = 0;
-
-  if ( max_depth-- > 0 )
-    {
-    midptc = this->heap_coord_storage();
-    midptt = this->heap_tag_storage();
-    int i;
-    // make valgrind happy
-    //vtkstd::fill( midpt0, midpt0 + 6, 0. );
-    for ( i = 0; i < 6; i++ )
-      midptc[i] = ( v0[i] + v1[i] ) / 2.;
-
-    (*this->tag_assigner)( v0, t0, h0, midptc, midptt, v1, t1, h1 );
-    edge_code = this->edge_size_evaluator->evaluate_edge( v0, t0, midptc, midptt, v1, t1 );
-    if ( edge_code )
-      {
-      midpth = (*this->output_functor)( h0, h1, midptc, midptt );
-      }
-    }
-
-  switch ( edge_code )
-    {
-    // No edges to subdivide
-  case 0:
-    (*this->output_functor)( h0 );
-    (*this->output_functor)( h1 );
-    (*this->output_functor)( MBEDGE );
-    break ;
-
-    // One edge to subdivide
-  case 1:
-    this->refine_1_simplex( max_depth, v0, t0, h0, midptc, midptt, midpth );
-    this->refine_1_simplex( max_depth, midptc, midptt, midpth, v1, t1, h1 );
-    break;
-    }
-
-  return edge_code;
-}
-
-/**\brief Refine a triangle.
-  */
-bool MBSimplexTemplateRefiner::refine_2_simplex(
-  int max_depth, int move,
-  const double* v0, const void* t0, MBEntityHandle h0,
-  const double* v1, const void* t1, MBEntityHandle h1,
-  const double* v2, const void* t2, MBEntityHandle h2 )
-{
-  int edge_code = 0;
-
-  double* midpt0c;
-  double* midpt1c;
-  double* midpt2c;
-  void* midpt0t;
-  void* midpt1t;
-  void* midpt2t;
-  MBEntityHandle midpt0h;
-  MBEntityHandle midpt1h;
-  MBEntityHandle midpt2h;
-
-  if ( max_depth-- > 0 )
-    {
-    int i;
-    midpt0c = this->heap_coord_storage();
-    midpt1c = this->heap_coord_storage();
-    midpt2c = this->heap_coord_storage();
-    midpt0t = this->heap_tag_storage();
-    midpt1t = this->heap_tag_storage();
-    midpt2t = this->heap_tag_storage();
-    midpt0h = 0;
-    midpt1h = 0;
-    midpt2h = 0;
-    for ( i = 0; i < 6; ++i )
-      {
-      midpt0c[i] = ( v0[i] + v1[i] ) / 2.;
-      midpt1c[i] = ( v1[i] + v2[i] ) / 2.;
-      midpt2c[i] = ( v2[i] + v0[i] ) / 2.;
-      }
-    (*this->tag_assigner)( v0, t0, h0, midpt0c, midpt0t, v1, t1, h1 );
-    (*this->tag_assigner)( v1, t1, h1, midpt1c, midpt1t, v2, t2, h2 );
-    (*this->tag_assigner)( v2, t2, h2, midpt2c, midpt2t, v0, t0, h0 );
-    if ( ( move & 1 ) && this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
-      {
-      edge_code += 1;
-      midpt0h = (*this->output_functor)( h0, h1, midpt0c, midpt0t );
-      }
-    if ( ( move & 2 ) && this->edge_size_evaluator->evaluate_edge( v1, t1, midpt1c, midpt1t, v2, t2 ) )
-      {
-      edge_code += 2;
-      midpt1h = (*this->output_functor)( h1, h2, midpt1c, midpt1t );
-      }
-    if ( ( move & 4 ) && this->edge_size_evaluator->evaluate_edge( v2, t2, midpt2c, midpt2t, v0, t0 ) )
-      {
-      edge_code += 4;
-      midpt2h = (*this->output_functor)( h2, h0, midpt2c, midpt2t );
-      }
-    }
-
-  switch ( edge_code )
-    {
-    // No edges to subdivide
-  case 0:
-    (*this->output_functor)( h0 );
-    (*this->output_functor)( h1 );
-    (*this->output_functor)( h2 );
-    (*this->output_functor)( MBTRI );
-    break ;
-
-    // One edge to subdivide
-  case 1:
-    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0,  midpt0c, midpt0t, midpt0h, v2, t2, h2 );
-    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h, v1, t1, h1,  v2, t2, h2 );
-    break;
-  case 2:
-    this->refine_2_simplex( max_depth, move | 4, v0, t0, h0, v1, t1, h1, midpt1c, midpt1t, midpt1h );
-    this->refine_2_simplex( max_depth, move | 1, v0, t0, h0, midpt1c, midpt1t, midpt1h, v2, t2, h2 );
-    break;
-  case 4:
-    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0, v1, t1, h1, midpt2c, midpt2t, midpt2h );
-    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, v1, t1, h1, v2, t2, h2 );
-    break;
-
-    // Two edges to subdivide
-  case 3:
-    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h, v1, t1, h1, midpt1c, midpt1t, midpt1h );
-    if ( this->compare_Hopf_cross_string_dist( v2, midpt0c, v0, midpt1c ) )
-      {
-      this->refine_2_simplex( max_depth, move | 5, midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h,   v2,      t2,      h2   );
-      this->refine_2_simplex( max_depth, move | 2,   v0,      t0,      h0,    midpt0c, midpt0t, midpt0h,   v2,      t2,      h2   );
-      }
-    else                                         
-      {
-      this->refine_2_simplex( max_depth, move | 6,   v0,      t0,      h0,   midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h );
-      this->refine_2_simplex( max_depth, move | 1,   v0,      t0,      h0,   midpt1c, midpt1t, midpt1h,   v2,      t2,      h2    );
-      }
-    break;
-  case 5:
-    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0, midpt0c, midpt0t, midpt0h, midpt2c, midpt2t, midpt2h );
-    if ( this->compare_Hopf_cross_string_dist( v2, midpt0c, v1, midpt2c ) )
-      {
-      this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h,   v1,      t1,      h1,       v2,      t2,    h2   );
-      this->refine_2_simplex( max_depth, move | 3, midpt2c, midpt2t, midpt2h, midpt0c, midpt0t, midpt0h,    v2,      t2,    h2   );
-      }
-    else
-      {
-      this->refine_2_simplex( max_depth, move | 6, midpt0c, midpt0t, midpt0h,   v1,      t1,      h1,   midpt2c, midpt2t, midpt2h );
-      this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h,   v1,      t1,      h1,      v2,      t2,     h2   );
-      }
-    break;
-  case 6:
-    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, midpt1c, midpt1t, midpt1h, v2, t2, h2 );
-    if ( this->compare_Hopf_cross_string_dist( v0, midpt1c, v1, midpt2c ) )
-      {
-      this->refine_2_simplex( max_depth, move | 3,   v0,      t0,     h0,    midpt1c, midpt1t, midpt1h, midpt2c, midpt2t, midpt2h );
-      this->refine_2_simplex( max_depth, move | 4,   v0,      t0,     h0,      v1,      t1,      h1,    midpt1c, midpt1t, midpt1h );
-      }
-    else
-      {
-      this->refine_2_simplex( max_depth, move | 2,   v0,      t0,      h0,      v1,      t1,     h1,    midpt2c, midpt2t, midpt2h );
-      this->refine_2_simplex( max_depth, move | 5, midpt2c, midpt2t, midpt2h,   v1,      t1,     h1,    midpt1c, midpt1t, midpt1h );
-      }
-    break;
-
-    // Three edges to subdivide
-  case 7:
-    this->refine_2_simplex( max_depth,        7, midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h, midpt2c, midpt2t, midpt2h );
-    this->refine_2_simplex( max_depth, move | 2,   v0   ,   t0   ,   h0   , midpt0c, midpt0t, midpt0h, midpt2c, midpt2t, midpt2h );
-    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h,   v1   ,   t1   ,   h1   , midpt1c, midpt1t, midpt1h );
-    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, midpt1c, midpt1t, midpt1h,   v2   ,   t2   ,   h2    );
-    break;
-    }
-
-  return true;
-}
-
-/**\brief Refine a tetrahedron.
-  */
-bool MBSimplexTemplateRefiner::refine_3_simplex(
-  int max_depth,
-  double* v0, void* t0, MBEntityHandle h0,
-  double* v1, void* t1, MBEntityHandle h1,
-  double* v2, void* t2, MBEntityHandle h2,
-  double* v3, void* t3, MBEntityHandle h3 )
-{
-  int edge_code = 0;
-
-  double* midpt0c;
-  double* midpt1c;
-  double* midpt2c;
-  double* midpt3c;
-  double* midpt4c;
-  double* midpt5c;
-
-  void* midpt0t;
-  void* midpt1t;
-  void* midpt2t;
-  void* midpt3t;
-  void* midpt4t;
-  void* midpt5t;
-
-  MBEntityHandle midpt0h;
-  MBEntityHandle midpt1h;
-  MBEntityHandle midpt2h;
-  MBEntityHandle midpt3h;
-  MBEntityHandle midpt4h;
-  MBEntityHandle midpt5h;
-
-  if ( max_depth-- > 0 )
-    {
-    midpt0c = this->heap_coord_storage();
-    midpt1c = this->heap_coord_storage();
-    midpt2c = this->heap_coord_storage();
-    midpt3c = this->heap_coord_storage();
-    midpt4c = this->heap_coord_storage();
-    midpt5c = this->heap_coord_storage();
-
-    midpt0t = this->heap_tag_storage();
-    midpt1t = this->heap_tag_storage();
-    midpt2t = this->heap_tag_storage();
-    midpt3t = this->heap_tag_storage();
-    midpt4t = this->heap_tag_storage();
-    midpt5t = this->heap_tag_storage();
-
-    for ( int i = 0; i < 6; ++ i )
-      {
-      midpt0c[i] = ( v0[i] + v1[i] ) * .5;
-      midpt1c[i] = ( v1[i] + v2[i] ) * .5;
-      midpt2c[i] = ( v2[i] + v0[i] ) * .5;
-      midpt3c[i] = ( v0[i] + v3[i] ) * .5;
-      midpt4c[i] = ( v1[i] + v3[i] ) * .5;
-      midpt5c[i] = ( v2[i] + v3[i] ) * .5;
-      }
-
-    (*this->tag_assigner)( v0, t0, h0, midpt0c, midpt0t, v1, t1, h1 );
-    (*this->tag_assigner)( v1, t1, h1, midpt1c, midpt1t, v2, t2, h2 );
-    (*this->tag_assigner)( v2, t2, h2, midpt2c, midpt2t, v0, t0, h0 );
-    (*this->tag_assigner)( v0, t0, h0, midpt3c, midpt3t, v3, t3, h3 );
-    (*this->tag_assigner)( v1, t1, h1, midpt4c, midpt4t, v3, t3, h3 );
-    (*this->tag_assigner)( v2, t2, h2, midpt5c, midpt5t, v3, t3, h3 );
-
-    if ( this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
-      {
-      edge_code |=  1;
-      midpt0h = (*this->output_functor)( h0, h1, midpt0c, midpt0t );
-      }
-    if ( this->edge_size_evaluator->evaluate_edge( v1, t1, midpt1c, midpt1t, v2, t2 ) )
-      {
-      edge_code |=  2;
-      midpt1h = (*this->output_functor)( h1, h2, midpt1c, midpt1t );
-      }
-    if ( this->edge_size_evaluator->evaluate_edge( v2, t2, midpt2c, midpt2t, v0, t0 ) )
-      {
-      edge_code |=  4;
-      midpt2h = (*this->output_functor)( h2, h0, midpt2c, midpt2t );
-      }
-    if ( this->edge_size_evaluator->evaluate_edge( v0, t0, midpt3c, midpt3t, v3, t3 ) )
-      {
-      edge_code |=  8;
-      midpt3h = (*this->output_functor)( h0, h3, midpt3c, midpt3t );
-      }
-    if ( this->edge_size_evaluator->evaluate_edge( v1, t1, midpt4c, midpt4t, v3, t3 ) )
-      {
-      edge_code |= 16;
-      midpt4h = (*this->output_functor)( h1, h3, midpt4c, midpt4t );
-      }
-    if ( this->edge_size_evaluator->evaluate_edge( v2, t2, midpt5c, midpt5t, v3, t3 ) )
-      {
-      edge_code |= 32;
-      midpt5h = (*this->output_functor)( h2, h3, midpt5c, midpt5t );
-      }
-    }
-
-  double edge_length2[6];
-  for ( int ei = 0; ei < 6; ++ ei )
-    edge_length2[ei] = 0.;
-
-  for ( int c = 0; c < 3; ++ c )
-    {
-    double tmp;
-    tmp = v1[c] - v0[c];
-    edge_length2[0] += tmp * tmp;
-    tmp = v2[c] - v1[c];
-    edge_length2[1] += tmp * tmp;
-    tmp = v2[c] - v0[c];
-    edge_length2[2] += tmp * tmp;
-    tmp = v3[c] - v0[c];
-    edge_length2[3] += tmp * tmp;
-    tmp = v3[c] - v1[c];
-    edge_length2[4] += tmp * tmp;
-    tmp = v3[c] - v2[c];
-    edge_length2[5] += tmp * tmp;
-    }
-
-  if ( ! edge_code )
-    {
-    // No edges to subdivide
-    (*this->output_functor)( h0 );
-    (*this->output_functor)( h1 );
-    (*this->output_functor)( h2 );
-    (*this->output_functor)( h3 );
-    (*this->output_functor)( MBTET );
-
-    return false;
-    }
-
-  double* facept0c;
-  double* facept1c;
-  double* facept2c;
-  double* facept3c;
-  facept0c = this->heap_coord_storage();
-  facept1c = this->heap_coord_storage();
-  facept2c = this->heap_coord_storage();
-  facept3c = this->heap_coord_storage();
-  double* vertex_coords[14] = {
-    v0, v1, v2, v3, 
-    midpt0c, midpt1c, midpt2c, 
-    midpt3c, midpt4c, midpt5c,
-    facept0c, facept1c, facept2c, facept3c
-  };
-
-  void* facept0t = this->heap_tag_storage();
-  void* facept1t = this->heap_tag_storage();
-  void* facept2t = this->heap_tag_storage();
-  void* facept3t = this->heap_tag_storage();
-  void* vertex_tags[14] = {
-    t0, t1, t2, t3, 
-    midpt0t, midpt1t, midpt2t, 
-    midpt3t, midpt4t, midpt5t,
-    facept0t, facept1t, facept2t, facept3t
-  };
-
-  MBEntityHandle vertex_hash[14] = {
-    h0, h1, h2, h3,
-    midpt0h, midpt1h, midpt2h,
-    midpt3h, midpt4h, midpt5h,
-    0, 0, 0, 0
-  };
-
-  // Generate tetrahedra that are compatible except when edge
-  // lengths are equal on indeterminately subdivided faces.
-  double* permuted_coords[14];
-  void* permuted_tags[14];
-  MBEntityHandle permuted_hash[14];
-  double permlen[6]; // permuted edge lengths
-  int C = MBSimplexTemplateRefiner::template_index[edge_code][0];
-  int P = MBSimplexTemplateRefiner::template_index[edge_code][1];
-  
-  // 1. Permute the tetrahedron into our canonical configuration
-  for ( int i = 0; i < 14; ++ i )
-    {
-    permuted_coords[i] = vertex_coords[MBSimplexTemplateRefiner::permutations_from_index[P][i]];
-    permuted_tags[i] = vertex_tags[MBSimplexTemplateRefiner::permutations_from_index[P][i]];
-    permuted_hash[i] = vertex_hash[MBSimplexTemplateRefiner::permutations_from_index[P][i]];
-    }
-
-  for ( int i = 4 ; i < 10; ++ i )
-    {
-    // permute edge lengths too
-    permlen[i-4]  = edge_length2[MBSimplexTemplateRefiner::permutations_from_index[P][i] - 4];
-    }
-
-  int comparison_bits;
-  std::stack<int*> output_tets;
-  std::stack<int*> output_perm;
-  std::stack<int>  output_sign;
-
-  // cout << "Case " << C << "  Permutation " << P << endl;
-  // 2. Generate tetrahedra based on the configuration.
-  //    Note that case 0 is handled above (edgeCode == 0).
-  
-  switch ( C )
-    {
-    case 1: // Ruprecht-Müller Case 1
-      MB_TESSELLATOR_INCR_CASE_COUNT(0);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 0 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(0,0);
-      break;
-    case 2: // Ruprecht-Müller Case 2a
-      comparison_bits = 
-        ( permlen[0] <= permlen[1] ? 1 : 0 ) | ( permlen[0] >= permlen[1] ? 2 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[0][i] + permuted_coords[2][i] ) * .375 + permuted_coords[1][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[2], permuted_tags[1], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[2], permuted_hash[1], permuted_coords[10], permuted_tags[10] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(1);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 9 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,0);
-      switch ( comparison_bits )
-        {
-        case 2: // 0>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 14 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,1);
-          break;
-        case 1: // 1>0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 14 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[13] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,2);
-          break;
-        case 3: // 0=1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 23 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,3);
-          break;
-        }
-      break;
-    case 3: // Ruprecht-Müller Case 2b
-      MB_TESSELLATOR_INCR_CASE_COUNT(2);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 40 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(2,0);
-      break;
-    case 4: // Ruprecht-Müller Case 3a
-      comparison_bits = 
-        ( permlen[0] <= permlen[3] ? 1 : 0 ) | ( permlen[0] >= permlen[3] ? 2 : 0 ) |
-        ( permlen[2] <= permlen[3] ? 4 : 0 ) | ( permlen[2] >= permlen[3] ? 8 : 0 ) |
-        ( permlen[0] <= permlen[2] ? 16 : 0 ) | ( permlen[0] >= permlen[2] ? 32 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[1][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[3], permuted_tags[0], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[3], permuted_hash[0], permuted_coords[11], permuted_tags[11] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[13][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[0], permuted_tags[13] );
-        permuted_hash[13] = (*this->output_functor)(
-          permuted_hash[2], permuted_hash[3], permuted_hash[0], permuted_coords[13], permuted_tags[13] );
-        }
-      if ( ( comparison_bits & 48 ) == 48 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[0], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[2], permuted_hash[0], permuted_coords[10] , permuted_tags[10] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(3);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 57 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,0);
-      switch ( comparison_bits )
-        {
-        case 42: // 0>2>3<0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,1);
-          break;
-        case 25: // 2>3>0<2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[11] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,2);
-          break;
-        case 37: // 3>0>2<3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[3] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,3);
-          break;
-        case 21: // 3>2>0<3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[22] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,4);
-          break;
-        case 26: // 2>0>3<2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[12] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,5);
-          break;
-        case 38: // 0>3>2<0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 62 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,6);
-          break;
-        case 58: // 0=2>3<0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 75 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,7);
-          break;
-        case 29: // 2=3>0<2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 75 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[11] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,8);
-          break;
-        case 39: // 0=3>2<0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 75 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[3] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,9);
-          break;
-        case 53: // 3>0=2<3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 96 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,10);
-          break;
-        case 46: // 0>2=3<0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 96 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[11] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,11);
-          break;
-        case 27: // 2>0=3<2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 96 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[3] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,12);
-          break;
-        case 63: // 0=2=3=0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 117 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,13);
-          break;
-        }
-      break;
-    case 5: // Ruprecht-Müller Case 3b
-      MB_TESSELLATOR_INCR_CASE_COUNT(4);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 162 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(4,0);
-      break;
-    case 6: // Ruprecht-Müller Case 3c
-      comparison_bits = 
-        ( permlen[0] <= permlen[1] ? 1 : 0 ) | ( permlen[0] >= permlen[1] ? 2 : 0 ) |
-        ( permlen[0] <= permlen[3] ? 4 : 0 ) | ( permlen[0] >= permlen[3] ? 8 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[0][i] + permuted_coords[2][i] ) * .375 + permuted_coords[1][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[2], permuted_tags[1], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[2], permuted_hash[1], permuted_coords[10], permuted_tags[10] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[1][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[3], permuted_tags[0], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[3], permuted_hash[0], permuted_coords[11], permuted_tags[11] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(5);
-      switch ( comparison_bits )
-        {
-        case 10: // 0>1,0>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 179 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,0);
-          break;
-        case 5: // 1>0,3>0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 200 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,1);
-          break;
-        case 6: // 0>1,3>0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 221 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,2);
-          break;
-        case 9: // 1>0,0>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 242 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,3);
-          break;
-        case 11: // 0=1,0>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 263 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,4);
-          break;
-        case 14: // 0=3,0>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 263 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,5);
-          break;
-        case 7: // 3>0,0=1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 292 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,6);
-          break;
-        case 13: // 1>0,0=3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 292 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,7);
-          break;
-        case 15: // 0=1,0=3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 321 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,8);
-          break;
-        }
-      break;
-    case 7: // Ruprecht-Müller Case 3d
-      comparison_bits = 
-        ( permlen[0] <= permlen[2] ? 1 : 0 ) | ( permlen[0] >= permlen[2] ? 2 : 0 ) |
-        ( permlen[0] <= permlen[4] ? 4 : 0 ) | ( permlen[0] >= permlen[4] ? 8 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[0], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[2], permuted_hash[0], permuted_coords[10], permuted_tags[10] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[3][i] ) * .375 + permuted_coords[1][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[3], permuted_tags[1], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[3], permuted_hash[1], permuted_coords[11], permuted_tags[11] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(6);
-      switch ( comparison_bits )
-        {
-        case 10: // 0>4,0>2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 362 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,0);
-          break;
-        case 5: // 4>0,2>0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 383 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,1);
-          break;
-        case 9: // 0>4,2>0
-          output_tets.push( MBSimplexTemplateRefiner::templates + 404 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,2);
-          break;
-        case 6: // 4>0,0>2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 425 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,3);
-          break;
-        case 14: // 0=4,0>2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 446 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,4);
-          break;
-        case 11: // 0=2,0>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 446 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,5);
-          break;
-        case 13: // 2>0,0=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 475 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,6);
-          break;
-        case 7: // 4>0,0=2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 475 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,7);
-          break;
-        case 15: // 0=4,0=2
-          output_tets.push( MBSimplexTemplateRefiner::templates + 504 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,8);
-          break;
-        }
-      break;
-    case 8: // Ruprecht-Müller Case 4a
-      comparison_bits = 
-        ( permlen[4] <= permlen[5] ? 1 : 0 ) | ( permlen[4] >= permlen[5] ? 2 : 0 ) |
-        ( permlen[3] <= permlen[4] ? 4 : 0 ) | ( permlen[3] >= permlen[4] ? 8 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[12][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[3][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[3], permuted_tags[12] );
-        permuted_hash[12] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[2], permuted_hash[3], permuted_coords[12], permuted_tags[12] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(7);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 545 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,0);
-      switch ( comparison_bits )
-        {
-        case 5: // 5>4>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 554 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,1);
-          break;
-        case 10: // 3>4>5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 554 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[13] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,2);
-          break;
-        case 6: // 3<4>5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 571 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,3);
-          break;
-        case 9: // 3>4<5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 588 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,4);
-          break;
-        case 14: // 3=4>5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 605 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,5);
-          break;
-        case 7: // 4=5,4>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 605 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[13] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,6);
-          break;
-        case 13: // 5>4,3=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 630 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,7);
-          break;
-        case 11: // 3>4=5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 630 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[13] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,8);
-          break;
-        case 15: // 3=4=5
-          output_tets.push( MBSimplexTemplateRefiner::templates + 655 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,9);
-          break;
-        }
-      break;
-    case 9: // Ruprecht-Müller Case 4b
-      comparison_bits = 
-        ( permlen[1] <= permlen[2] ? 1 : 0 ) | ( permlen[1] >= permlen[2] ? 2 : 0 ) |
-        ( permlen[2] <= permlen[3] ? 4 : 0 ) | ( permlen[2] >= permlen[3] ? 8 : 0 ) |
-        ( permlen[3] <= permlen[4] ? 16 : 0 ) | ( permlen[3] >= permlen[4] ? 32 : 0 ) |
-        ( permlen[1] <= permlen[4] ? 64 : 0 ) | ( permlen[1] >= permlen[4] ? 128 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[0][i] ) * .375 + permuted_coords[2][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[0], permuted_tags[2], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[0], permuted_hash[2], permuted_coords[10], permuted_tags[10] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[13][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[0], permuted_tags[13] );
-        permuted_hash[13] = (*this->output_functor)(
-          permuted_hash[2], permuted_hash[3], permuted_hash[0], permuted_coords[13], permuted_tags[13] );
-        }
-      if ( ( comparison_bits & 48 ) == 48 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
-        }
-      if ( ( comparison_bits & 192 ) == 192 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[12][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[1][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[1], permuted_tags[12] );
-        permuted_hash[12] = (*this->output_functor)(
-          permuted_hash[2], permuted_hash[3], permuted_hash[1], permuted_coords[12], permuted_tags[12] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(8);
-      switch ( comparison_bits )
-        {
-        case 85: // 2>1,3>2,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,0);
-          break;
-        case 102: // 1>2,3>2,3>4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,1);
-          break;
-        case 170: // 1>2,2>3,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,2);
-          break;
-        case 153: // 2>1,2>3,4>3,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,3);
-          break;
-        case 90: // 1>2,2>3,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[9] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,4);
-          break;
-        case 105: // 2>1,2>3,3>4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[7] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,5);
-          break;
-        case 165: // 2>1,3>2,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[19] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,6);
-          break;
-        case 150: // 1>2,3>2,4>3,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 688 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[23] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,7);
-          break;
-        case 101: // 2>1,3>2,3>4,4>1
-          {
-          int alternates[] = { 713, 738, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,8);
-          break;
-        case 86: // 1>2,3>2,4>3,4>1
-          {
-          int alternates[] = {713, 738, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,9);
-          break;
-        case 154: // 1>2,2>3,4>3,1>4
-          {
-          int alternates[] = {713, 738, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 5, 1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,10);
-          break;
-        case 169: // 2>1,2>3,3>4,1>4
-          {
-          int alternates[] = {713, 738, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 15, -1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,11);
-          break;
-        case 89: // 2>1,2>3,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 763 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,12);
-          break;
-        case 166: // 1>2,3>2,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 763 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,13);
-          break;
-        case 103: // 1=2,3>2,3>4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,14);
-          break;
-        case 87: // 1=2,3>2,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,15);
-          break;
-        case 185: // 2>1,2>3,3=4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,16);
-          break;
-        case 186: // 1>2,2>3,3=4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,17);
-          break;
-        case 158: // 1>2,2=3,4>3,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[9] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,18);
-          break;
-        case 229: // 2>1,3>2,3>4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[7] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,19);
-          break;
-        case 233: // 2>1,2>3,3>4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[19] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,20);
-          break;
-        case 94: // 1>2,2=3,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 788 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[23] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,21);
-          break;
-        case 155: // 1=2,2>3,4>3,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,22);
-          break;
-        case 171: // 1=2,2>3,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,23);
-          break;
-        case 118: // 1>2,3>2,3=4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,24);
-          break;
-        case 117: // 2>1,3>2,3=4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,25);
-          break;
-        case 109: // 2>1,2=3,3>4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[9] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,26);
-          break;
-        case 218: // 1>2,2>3,4>3,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[7] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,27);
-          break;
-        case 214: // 1>2,3>2,4>3,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[19] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,28);
-          break;
-        case 173: // 2>1,2=3,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 825 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[23] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,29);
-          break;
-        case 91: // 1=2,2>3,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,30);
-          break;
-        case 167: // 1=2,3>2,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,31);
-          break;
-        case 182: // 1>2,3>2,3=4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,32);
-          break;
-        case 121: // 2>1,2>3,3=4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,33);
-          break;
-        case 93: // 2>1,2=3,4>3,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[9] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,34);
-          break;
-        case 217: // 2>1,2>3,4>3,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[7] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,35);
-          break;
-        case 230: // 1>2,3>2,3>4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[19] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,36);
-          break;
-        case 174: // 1>2,2=3,3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 862 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[23] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,37);
-          break;
-        case 119: // 1=2,3>2,3=4,4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 899 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,38);
-          break;
-        case 187: // 1=2>3=4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 899 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,39);
-          break;
-        case 222: // 1>2,2=3,4>3,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 899 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[9] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,40);
-          break;
-        case 237: // 2>1,2=3,3>4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 899 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[7] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,41);
-          break;
-        case 95: // 4>1=2=3,4>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 944 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,42);
-          break;
-        case 231: // 1=2,3>2,3>4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 944 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,43);
-          break;
-        case 190: // 1>2=3=4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 944 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,44);
-          break;
-        case 249: // 2>1,2>3,3=4,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 944 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,45);
-          break;
-        case 175: // 1=2=3>4,1>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 993 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,46);
-          break;
-        case 219: // 1=2>3,4>3,1=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 993 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,47);
-          break;
-        case 125: // 2>1,2=3=4>1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 993 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,48);
-          break;
-        case 246: // 1>2,3>2,3=4=1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 993 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,49);
-          break;
-        case 255: // 1=2=3=4=1
-          output_tets.push( MBSimplexTemplateRefiner::templates + 1042 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,50);
-          break;
-        }
-      break;
-    case 10: // Ruprecht-Müller Case 5
-      comparison_bits = 
-        ( permlen[1] <= permlen[2] ? 1 : 0 ) | ( permlen[1] >= permlen[2] ? 2 : 0 ) |
-        ( permlen[3] <= permlen[4] ? 4 : 0 ) | ( permlen[3] >= permlen[4] ? 8 : 0 ) |
-        0;
-      if ( ( comparison_bits & 3 ) == 3 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[0][i] ) * .375 + permuted_coords[2][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[1], permuted_tags[0], permuted_tags[2], permuted_tags[10] );
-        permuted_hash[10] = (*this->output_functor)(
-          permuted_hash[1], permuted_hash[0], permuted_hash[2], permuted_coords[10], permuted_tags[10] );
-        }
-      if ( ( comparison_bits & 12 ) == 12 )
-        {
-        // Compute face point and tag
-        for ( int i = 0; i < 6; ++ i )
-          {
-          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
-          }
-        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
-        permuted_hash[11] = (*this->output_functor)(
-          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
-        }
-      MB_TESSELLATOR_INCR_CASE_COUNT(9);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 1107 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,0);
-      switch ( comparison_bits )
-        {
-        case 10: // 1>2,3>4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 1116 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,1);
-          break;
-        case 5: // 2>1,4>3
-          output_tets.push( MBSimplexTemplateRefiner::templates + 1116 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,2);
-          break;
-        case 6: // 1>2,4>3
-          {
-          int alternates[] = { 1137, 1158, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,3);
-          break;
-        case 9: // 2>1,3>4
-          {
-          int alternates[] = {1137, 1158, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,4);
-          break;
-        case 11: // 1=2,3>4
-          {
-          int alternates[] = { 1179, 1212, 1245, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,5);
-          break;
-        case 7: // 1=2,4>3
-          {
-          int alternates[] = {1179, 1212, 1245, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[14] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,6);
-          break;
-        case 14: // 3=4,1>2
-          {
-          int alternates[] = {1179, 1212, 1245, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 5, 1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[5] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,7);
-          break;
-        case 13: // 3=4,2>1
-          {
-          int alternates[] = {1179, 1212, 1245, -1 };
-          output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 15, -1 ) );
-          }
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[15] );
-          output_sign.push( -1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,8);
-          break;
-        case 15: // 1=2,3=4
-          output_tets.push( MBSimplexTemplateRefiner::templates + 1278 );
-          output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-          output_sign.push( 1 );
-          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,9);
-          break;
-        }
-      break;
-    case 11: // Ruprecht-Müller Case 6
-      MB_TESSELLATOR_INCR_CASE_COUNT(10);
-      output_tets.push( MBSimplexTemplateRefiner::templates + 1319 );
-      output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-      output_sign.push( 1 );
-      MB_TESSELLATOR_INCR_SUBCASE_COUNT(10,0);
-        {
-        int alternates[] = { 1336, 1353, 1370, -1 };
-        output_tets.push( MBSimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
-        }
-        output_perm.push( MBSimplexTemplateRefiner::permutations_from_index[0] );
-        output_sign.push( 1 );
-        MB_TESSELLATOR_INCR_SUBCASE_COUNT(10,1);
-        break;
-    }
-
-  int* tets;
-  int  ntets;
-  int* perm;
-  int  sgn;
-#ifdef MB_DEBUG_TESSELLATOR
-  if ( output_tets.empty() )
-    {
-    cout << "Argh! Case " << C << " Perm " << P << " has no output!" << endl;
-    }
-#endif // MB_DEBUG_TESSELLATOR
-  while ( ! output_tets.empty() )
-    {
-    tets = output_tets.top();
-    ntets = *tets;
-    tets++;
-    perm = output_perm.top();
-    sgn = output_sign.top();
-
-    output_tets.pop();
-    output_perm.pop();
-    output_sign.pop();
-
-    int t;
-    if ( sgn > 0 )
-      {
-      for ( t = 0; t < ntets; ++t )
-        {
-        this->refine_3_simplex( max_depth,
-          permuted_coords[perm[tets[0]]], permuted_tags[perm[tets[0]]], permuted_hash[perm[tets[0]]],
-          permuted_coords[perm[tets[1]]], permuted_tags[perm[tets[1]]], permuted_hash[perm[tets[1]]],
-          permuted_coords[perm[tets[2]]], permuted_tags[perm[tets[2]]], permuted_hash[perm[tets[2]]],
-          permuted_coords[perm[tets[3]]], permuted_tags[perm[tets[3]]], permuted_hash[perm[tets[3]]]
-          );
-        tets += 4;
-        }
-      }
-    else
-      {
-      // we have an inverted tet... reverse the first 2 vertices
-      // so the orientation is positive.
-      for ( t = 0; t < ntets; ++t )
-        {
-        this->refine_3_simplex( max_depth,
-          permuted_coords[perm[tets[1]]], permuted_tags[perm[tets[1]]], permuted_hash[perm[tets[1]]],
-          permuted_coords[perm[tets[0]]], permuted_tags[perm[tets[0]]], permuted_hash[perm[tets[0]]],
-          permuted_coords[perm[tets[2]]], permuted_tags[perm[tets[2]]], permuted_hash[perm[tets[2]]],
-          permuted_coords[perm[tets[3]]], permuted_tags[perm[tets[3]]], permuted_hash[perm[tets[3]]]
-        );
-        tets += 4;
-        }
-      }
-    }
-
-  return true;
-}
-
-/**\brief This is used by refine_entity to assign parametric coordinates to corners of each element.
-  */
-void MBSimplexTemplateRefiner::assign_parametric_coordinates( int num_nodes, const double* src, double* tgt )
-{
-  for ( int i = 0; i < num_nodes; ++i, src +=3, tgt += 6 )
-    for ( int j = 0; j < 3; ++j )
-      tgt[j] = src[j];
-}
-
-/**\brief Returns true if || a0a1 || < || b0b1 ||
-  *
-  * We use this to test which triangulation has the best
-  * aspect ratio when there are 2 to choose from.
-  */
-bool MBSimplexTemplateRefiner::compare_Hopf_cross_string_dist(
-  const double* a0, const double* a1, const double* b0, const double* b1 )
-{   
-  double sq_mag_a = 0.;
-  double sq_mag_b = 0.;
-  for ( int i = 0; i < 3; ++ i )
-    {
-    double tmp;
-    tmp = a0[i] - a1[i];
-    sq_mag_a += tmp*tmp;
-    tmp = b0[i] - b1[i];
-    sq_mag_b += tmp*tmp;
-    } 
-  return sq_mag_a < sq_mag_b;
-}
-
-/*
- * The array below is indexed by the edge code for a tetrahedron.
- * Looking up a row with a tet's edge code will return C and P.
- * C is a configuration number and P is a permutation index. 
- *
- * C is based on the case number from Ruprecht and
- * Müller's (1998) paper on adaptive tetrahedra. (The case
- * numbers are shown to the left of the row in the column
- * labeled case. The only difference is that we introduce
- * a case 3d which is part of case 3c in the paper.)
- *
- * P is an index into the permutations_from_index array below,
- * and is used to transform the current tetrahedron into
- * the canonical configuration associated with C.
- *
- * The 6-digit binary number to the left (which is shown in
- * the horribly UNconventional LSB->MSB order) is the edge
- * code for the row. The 6 digits correspond to the 6 edges
- * of the tetrahedron; a '0' implies no subdivision while
- * a '1' implies subdivision should occur. The ordering of
- * the bits is
- *
- * Edge 0-1, Edge 1-2, Edge 2-0, Edge 0-3, Edge 1-3, Edge 2-3,
- *
- * where the numbers are vertices of the tetrahedron 0-1-2-3.
- * Note that Tet 0-1-2-3 must be positive (i.e., the plane
- * specified by Triangle 0-1-2 must have a normal pointing
- * towards vertex 3, and Triangle 0-1-2's normal must be
- * calculated using the cross-product (Edge 0-1) x (Edge 0-2)).
- *
- * ===========
- * References:
- * (Ruprect and Müller, 1998) A Scheme for Edge-based Adaptive
- *   Tetrahedron Subdivision, Mathematical Visualization (eds.
- *   Hege and Polthier), pp. 61--70. Springer-Verlag. 1998.
- */
-int MBSimplexTemplateRefiner::template_index[64][2] =
-{
-  /*      code case      C    P */
-  /* 000000  0  0  */ {  0,   0 },
-  /* 100000  1  1  */ {  1,   0 },
-  /* 010000  2  1  */ {  1,   1 },
-  /* 110000  3  2a */ {  2,   0 },
-  /* 001000  4  1  */ {  1,   2 },
-  /* 101000  5  2a */ {  2,   2 },
-  /* 011000  6  2a */ {  2,   1 },
-  /* 111000  7  3b */ {  5,  11 },
-  /* 000100  8  1  */ {  1,  10 },
-  /* 100100  9  2a */ {  2,   5 },
-  /* 010100 10  2b */ {  3,   1 },
-  /* 110100 11  3c */ {  6,   0 },
-  /* 001100 12  2a */ {  2,  10 },
-  /* 101100 13  3a */ {  4,   0 },
-  /* 011100 14  3d */ {  7,   2 },
-  /* 111100 15  4a */ {  8,   6 },
-  /* 000010 16  1  */ {  1,   6 },
-  /* 100010 17  2a */ {  2,   4 },
-  /* 010010 18  2a */ {  2,   8 },
-  /* 110010 19  3a */ {  4,   1 },
-  /* 001010 20  2b */ {  3,   2 },
-  /* 101010 21  3d */ {  7,   0 },
-  /* 011010 22  3c */ {  6,   1 },
-  /* 111010 23  4a */ {  8,   9 },
-  /* 000110 24  2a */ {  2,   3 },
-  /* 100110 25  3b */ {  5,   0 },
-  /* 010110 26  3d */ {  7,   4 },
-  /* 110110 27  4a */ {  8,  11 },
-  /* 001110 28  3c */ {  6,  10 },
-  /* 101110 29  4a */ {  8,   7 },
-  /* 011110 30  4b */ {  9,   0 },
-  /* 111110 31  5  */ { 10,   7 },
-  /* 000001 32  1  */ {  1,   7 },
-  /* 100001 33  2b */ {  3,   0 },
-  /* 010001 34  2a */ {  2,   7 },
-  /* 110001 35  3d */ {  7,   1 },
-  /* 001001 36  2a */ {  2,  11 },
-  /* 101001 37  3c */ {  6,   2 },
-  /* 011001 38  3a */ {  4,   2 },
-  /* 111001 39  4a */ {  8,   3 },
-  /* 000101 40  2a */ {  2,   9 },
-  /* 100101 41  3d */ {  7,  10 },
-  /* 010101 42  3c */ {  6,   7 },
-  /* 110101 43  4b */ {  9,   2 },
-  /* 001101 44  3b */ {  5,   7 },
-  /* 101101 45  4a */ {  8,   8 },
-  /* 011101 46  4a */ {  8,   4 },
-  /* 111101 47  5  */ { 10,   6 },
-  /* 000011 48  2a */ {  2,   6 },
-  /* 100011 49  3c */ {  6,   4 },
-  /* 010011 50  3b */ {  5,   1 },
-  /* 110011 51  4a */ {  8,  10 },
-  /* 001011 52  3d */ {  7,   7 },
-  /* 101011 53  4b */ {  9,   1 },
-  /* 011011 54  4a */ {  8,   5 },
-  /* 111011 55  5  */ { 10,  10 },
-  /* 000111 56  3a */ {  4,  10 },
-  /* 100111 57  4a */ {  8,   1 },
-  /* 010111 58  4a */ {  8,   2 },
-  /* 110111 59  5  */ { 10,   2 },
-  /* 001111 60  4a */ {  8,   0 },
-  /* 101111 61  5  */ { 10,   1 },
-  /* 011111 62  5  */ { 10,   0 },
-  /* 111111 63  6  */ { 11,   0 },
-};
-
-
-/* Does this mean anything? If so, then you are either 
- * superstitious or much more clever than I (or both?).
- */
-/* permutation index, P:  0  1  2  3  4  5  6  7  8  9 10 11 */
-/* number of references: 12  9  9  3  4  2  5  6  2  3  7  2 */
-
-
-/*
- * The array below is a list of all the _positive_
- * permutations of Tetrahedron 0-1-2-3. Given a
- * permutation index, it returns a row of 14 values:
- * these are the vertex numbers of the permuted
- * tetrahedron. The first 4 values are the permuted
- * corner indices, the next 6 values are the
- * permuted edge midpoint indices, and the final
- * entries reference mid-face points inserted
- * to maintain a compatible tetrahedralization.
- *
- * There are 24 entries, 6 for each of the 4 faces of
- * the tetrahedron.
- */
-int MBSimplexTemplateRefiner::permutations_from_index[24][14] =
-{
-  /* corners      midpoints          face points   */
-  /* POSITIVE ARRANGEMENTS                         */
-  { 0, 1, 2, 3,   4, 5, 6, 7, 8, 9,  10, 11, 12, 13 }, /* Face 0-1-2 */
-  { 1, 2, 0, 3,   5, 6, 4, 8, 9, 7,  10, 12, 13, 11 },
-  { 2, 0, 1, 3,   6, 4, 5, 9, 7, 8,  10, 13, 11, 12 },
-
-  { 0, 3, 1, 2,   7, 8, 4, 6, 9, 5,  11, 13, 12, 10 }, /* Face 0-3-1 */
-  { 3, 1, 0, 2,   8, 4, 7, 9, 5, 6,  11, 12, 10, 13 },
-  { 1, 0, 3, 2,   4, 7, 8, 5, 6, 9,  11, 10, 13, 12 },
-
-  { 1, 3, 2, 0,   8, 9, 5, 4, 7, 6,  12, 11, 13, 10 }, /* Face 1-3-2 */
-  { 3, 2, 1, 0,   9, 5, 8, 7, 6, 4,  12, 13, 10, 11 },
-  { 2, 1, 3, 0,   5, 8, 9, 6, 4, 7,  12, 10, 11, 13 },
-
-  { 2, 3, 0, 1,   9, 7, 6, 5, 8, 4,  13, 12, 11, 10 }, /* Face 2-3-0 */
-  { 3, 0, 2, 1,   7, 6, 9, 8, 4, 5,  13, 11, 10, 12 },
-  { 0, 2, 3, 1,   6, 9, 7, 4, 5, 8,  13, 10, 12, 11 },
-
-  /* NEGATIVE ARRANGEMENTS                         */
-  { 0, 2, 1, 3,   6, 5, 4, 7, 9, 8,  10, 13, 12, 11 }, /* Face 0-1-2 */
-  { 2, 1, 0, 3,   5, 4, 6, 9, 8, 7,  10, 12, 11, 13 },
-  { 1, 0, 2, 3,   4, 6, 5, 8, 7, 9,  10, 11, 13, 12 },
-
-  { 0, 1, 3, 2,   4, 8, 7, 6, 5, 9,  11, 10, 12, 13 }, /* Face 0-3-1 */
-  { 1, 3, 0, 2,   8, 7, 4, 5, 9, 6,  11, 12, 13, 10 },
-  { 3, 0, 1, 2,   7, 4, 8, 9, 6, 5,  11, 13, 10, 12 },
-
-  { 1, 2, 3, 0,   5, 9, 8, 4, 6, 7,  12, 10, 13, 11 }, /* Face 1-3-2 */
-  { 2, 3, 1, 0,   9, 8, 5, 6, 7, 4,  12, 13, 11, 10 },
-  { 3, 1, 2, 0,   8, 5, 9, 7, 4, 6,  12, 11, 10, 13 },
-
-  { 2, 0, 3, 1,   6, 7, 9, 5, 4, 8,  13, 10, 11, 12 }, /* Face 2-3-0 */
-  { 0, 3, 2, 1,   7, 9, 6, 4, 8, 5,  13, 11, 12, 10 },
-  { 3, 2, 0, 1,   9, 6, 7, 8, 5, 4,  13, 12, 10, 11 }
-};
-
-/*
- * Below is a list of output tetrahedra. The array is
- * generated by TessellatorGenerator.py
- * which also generates the code that references it.
- * Each set of tetrahedra begins with a single integer
- * that is the number of tetrahedra for that particular
- * case. It is followed by 5 integers for each output
- * tetrahedron; the first four numbers on each row are
- * indices of the output tetrahedron. The final number
- * is a bit vector specifying which edges of the
- * tetrahedron are internal to the parent tetrahedron
- * being decomposed.
- *
- * Multiple lists of output tetrahedra may be
- * combined to create the tessellation of a single
- * input tetrahedron.
- */
-
-int MBSimplexTemplateRefiner::templates[] = 
-{
-// case 1_0
-   2,
-   0,  4,  2,  3,
-   4,  1,  2,  3,
-
-// case 2a_0
-   1,
-   3,  4,  5,  1,
-
-// case 2a, 0>1
-   2,
-   0,  4,  2,  3,
-   4,  5,  2,  3,
-
-// case 2a, 0=1
-   4,
-  10,  3,  0,  4,
-  10,  3,  4,  5,
-  10,  3,  5,  2,
-  10,  3,  2,  0,
-
-// case 2b_0
-   4,
-   0,  4,  9,  3,
-   4,  1,  9,  3,
-   0,  4,  2,  9,
-   4,  1,  2,  9,
-
-// case 3a_0
-   1,
-   4,  7,  6,  0,
-
-// case 3a, 0>2>3<0
-   3,
-   1,  3,  2,  4,
-   4,  6,  3,  2,
-   4,  6,  7,  3,
-
-// case 3a, 0=2>3<0
-   5,
-   4,  6,  7,  3,
-  10,  1,  2,  3,
-  10,  2,  6,  3,
-  10,  6,  4,  3,
-  10,  4,  1,  3,
-
-// case 3a, 3>0=2<3
-   5,
-   1,  3,  2,  7,
-  10,  1,  2,  7,
-  10,  2,  6,  7,
-  10,  6,  4,  7,
-  10,  4,  1,  7,
-
-// case 3a, 0=2=3=0
-  11,
-   2,  6, 10, 13,
-   3,  7, 13, 11,
-   4,  1, 10, 11,
-  11,  6, 10,  4,
-  11,  6, 13, 10,
-  11,  6,  7, 13,
-  11,  6,  4,  7,
-   2, 10, 11, 13,
-   1, 10, 11,  2,
-   2, 11,  3, 13,
-   3,  2,  1, 11,
-
-// case 3b_0
-   4,
-   0,  7,  4,  2,
-   4,  7,  8,  2,
-   4,  8,  1,  2,
-   7,  3,  8,  2,
-
-// case 3c, 0>1,0>3
-   5,
-   4,  2,  7,  5,
-   4,  2,  0,  7,
-   4,  3,  1,  5,
-   4,  3,  5,  7,
-   3,  5,  7,  2,
-
-// case 3c, 1>0,3>0
-   5,
-   0,  5,  2,  7,
-   0,  5,  7,  4,
-   7,  1,  4,  5,
-   7,  1,  5,  3,
-   3,  5,  7,  2,
-
-// case 3c, 0>1,3>0
-   5,
-   4,  2,  7,  5,
-   4,  2,  0,  7,
-   7,  1,  4,  5,
-   7,  1,  5,  3,
-   3,  5,  7,  2,
-
-// case 3c, 1>0,0>3
-   5,
-   0,  5,  2,  7,
-   0,  5,  7,  4,
-   4,  3,  1,  5,
-   4,  3,  5,  7,
-   3,  5,  7,  2,
-
-// case 3c, 0=1,0>3
-   7,
-   4,  1,  5,  3,
-  10,  0,  4,  7,
-  10,  2,  0,  7,
-  10,  7,  4,  3,
-  10,  2,  7,  3,
-  10,  5,  2,  3,
-  10,  4,  5,  3,
-
-// case 3c, 3>0,0=1
-   7,
-   7,  1,  5,  3,
-   7,  5,  2,  3,
-  10,  0,  4,  7,
-  10,  2,  0,  7,
-  10,  5,  2,  7,
-  10,  4,  5,  7,
-   1,  5,  4,  7,
-
-// case 3c, 0=1,0=3
-  10,
-   4,  1,  5, 11,
-  11,  1,  5,  3,
-  10,  0,  4,  7,
-  10,  2,  0,  7,
-  10,  5,  2,  3,
-  10,  2,  7,  3,
-  10,  7,  4, 11,
-  10,  7, 11,  3,
-  10,  4,  5, 11,
-  10, 11,  5,  3,
-
-// case 3d, 0>4,0>2
-   5,
-   4,  3,  6,  0,
-   4,  3,  8,  6,
-   4,  2,  8,  1,
-   4,  2,  6,  8,
-   2,  3,  6,  8,
-
-// case 3d, 4>0,2>0
-   5,
-   8,  0,  6,  4,
-   8,  0,  3,  6,
-   6,  1,  8,  4,
-   6,  1,  2,  8,
-   2,  3,  6,  8,
-
-// case 3d, 0>4,2>0
-   5,
-   4,  3,  6,  0,
-   4,  3,  8,  6,
-   6,  1,  8,  4,
-   6,  1,  2,  8,
-   2,  3,  6,  8,
-
-// case 3d, 4>0,0>2
-   5,
-   8,  0,  6,  4,
-   8,  0,  3,  6,
-   4,  2,  8,  1,
-   4,  2,  6,  8,
-   2,  3,  6,  8,
-
-// case 3d, 0=4,0>2
-   7,
-   4,  1,  2,  8,
-  11,  4,  0,  6,
-  11,  0,  3,  6,
-  11,  2,  4,  6,
-  11,  3,  2,  6,
-  11,  3,  8,  2,
-  11,  8,  4,  2,
-
-// case 3d, 2>0,0=4
-   7,
-   6,  2,  8,  1,
-   6,  8,  2,  3,
-  11,  4,  0,  6,
-  11,  0,  3,  6,
-   8, 11,  3,  6,
-   8,  4, 11,  6,
-   1,  6,  4,  8,
-
-// case 3d, 0=4,0=2
-  10,
-   4,  1, 10,  8,
-  10,  2,  8,  1,
-  11,  4,  0,  6,
-  11,  0,  3,  6,
-  11,  3,  8,  2,
-  11,  3,  2,  6,
-  11, 10,  4,  6,
-  11, 10,  6,  2,
-   8,  4, 11, 10,
-  11, 10,  2,  8,
-
-// case 4a_0
-   2,
-   7,  8,  9,  3,
-   7,  9,  8,  6,
-
-// case 4a, 5>4>3
-   4,
-   8,  0,  6,  1,
-   8,  0,  7,  6,
-   9,  1,  6,  2,
-   9,  1,  8,  6,
-
-// case 4a, 3<4>5
-   4,
-   8,  0,  6,  1,
-   8,  0,  7,  6,
-   8,  2,  6,  9,
-   8,  2,  1,  6,
-
-// case 4a, 3>4<5
-   4,
-   6,  9,  8,  1,
-   6,  9,  1,  2,
-   6,  7,  0,  1,
-   6,  7,  1,  8,
-
-// case 4a, 3=4>5
-   6,
-   6,  7,  0, 11,
-   6,  0,  1, 11,
-   6,  7, 11,  8,
-   6, 11,  1,  8,
-   1,  2,  6,  8,
-   2,  6,  8,  9,
-
-// case 4a, 5>4,3=4
-   6,
-   6,  7,  0, 11,
-   6,  0,  1, 11,
-   6,  7, 11,  8,
-   6, 11,  1,  8,
-   1,  2,  6,  9,
-   1,  6,  8,  9,
-
-// case 4a, 3=4=5
-   8,
-   6,  7,  0, 11,
-   6,  0,  1, 11,
-   6,  7, 11,  8,
-   6, 11,  1,  8,
-   6,  1,  2, 12,
-   6,  2,  9, 12,
-   6,  9,  8, 12,
-   6,  8,  1, 12,
-
-// case 4b, 2>1,3>2,4>3,4>1
-   6,
-   6,  8,  1,  5,
-   6,  8,  0,  1,
-   6,  8,  7,  0,
-   6,  8,  2,  7,
-   7,  8,  2,  3,
-   6,  8,  5,  2,
-
-// case 4b, 2>1,3>2,3>4,4>1
-   6,
-   6,  8,  1,  5,
-   6,  8,  7,  1,
-   6,  7,  0,  1,
-   8,  7,  3,  2,
-   6,  8,  5,  2,
-   6,  8,  2,  7,
-
-// case 4b, 2>1,3>2,3>4,4>1, a
-   6,
-   7,  8,  1,  5,
-   6,  5,  7,  1,
-   6,  7,  0,  1,
-   8,  7,  3,  2,
-   7,  8,  5,  2,
-   6,  5,  2,  7,
-
-// case 4b, 2>1,2>3,4>3,4>1
-   6,
-   6,  8,  5,  2,
-   6,  8,  2,  3,
-   6,  8,  3,  7,
-   6,  8,  7,  0,
-   6,  8,  0,  1,
-   6,  8,  1,  5,
-
-// case 4b, 1=2,3>2,3>4,4>1
-   9,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  7,
-  10,  7,  1,  8,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6,  2,  7,  8,
-   6,  5,  2,  8,
-   7,  8,  2,  3,
-
-// case 4b, 1=2,2>3,4>3,1>4
-   9,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  8,
-  10,  7,  0,  8,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6,  3,  7,  8,
-   6,  5,  3,  8,
-   6,  5,  2,  3,
-
-// case 4b, 1=2,2>3,4>3,4>1
-   9,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  8,
-  10,  7,  0,  8,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6,  3,  7,  8,
-   6,  5,  2,  8,
-   6,  2,  3,  8,
-
-// case 4b, 1=2,3>2,3=4,4>1
-  11,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1, 11,
-  10, 11,  1,  8,
-  10,  0, 11,  7,
-  10,  7, 11,  8,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6,  2,  7,  8,
-   6,  5,  2,  8,
-   7,  8,  2,  3,
-
-// case 4b, 4>1=2=3,4>3
-  12,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  8,
-  10,  7,  0,  8,
-  13,  6,  2,  5,
-  13,  3,  7,  8,
-  13,  2,  3,  8,
-  13,  2,  8,  5,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6, 13,  7,  8,
-   6,  5, 13,  8,
-
-// case 4b, 1=2=3>4,1>4
-  12,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  7,
-  10,  7,  1,  8,
-  13,  6,  2,  5,
-  13,  3,  7,  8,
-  13,  2,  3,  5,
-  13,  3,  8,  5,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6, 13,  7,  8,
-   6,  5, 13,  8,
-
-// case 4b, 1=2=3=4=1
-  16,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1, 11,
-  10, 11,  1,  8,
-  10,  0, 11,  7,
-  10,  7, 11,  8,
-  13,  6,  2,  5,
-  13,  3,  7,  8,
-  13,  2,  3, 12,
-  13,  2, 12,  5,
-  13, 12,  3,  8,
-  13, 12,  5,  8,
-   6,  7, 10,  8,
-   6, 10,  5,  8,
-   6,  5, 13,  8,
-   6, 13,  7,  8,
-
-// case 5_0
-   2,
-   7,  8,  9,  3,
-   6,  5,  2,  9,
-
-// case 5, 1>2,3>4
-   5,
-   5,  7,  1,  8,
-   5,  7,  0,  1,
-   5,  7,  6,  0,
-   5,  7,  9,  6,
-   5,  7,  8,  9,
-
-// case 5, 1>2,4>3
-   5,
-   0,  5,  6,  7,
-   0,  5,  7,  8,
-   0,  5,  8,  1,
-   5,  7,  9,  6,
-   5,  7,  8,  9,
-
-// case 5, 1>2,4>3, a
-   5,
-   0,  5,  6,  8,
-   0,  6,  7,  8,
-   0,  5,  8,  1,
-   5,  8,  9,  6,
-   6,  7,  8,  9,
-
-// case 5, 1=2,3>4
-   8,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  7,
-  10,  7,  1,  8,
-  10,  8,  5,  9,
-  10,  6,  7,  9,
-  10,  7,  8,  9,
-  10,  5,  6,  9,
-
-// case 5, 1=2,3>4, a
-   8,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  7,
-  10,  7,  1,  8,
-   7,  8,  5,  9,
-  10,  6,  7,  5,
-  10,  7,  8,  5,
-   5,  9,  6,  7,
-
-// case 5, 1=2,3>4, b
-   8,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1,  7,
-  10,  7,  1,  8,
-   6,  8,  5,  9,
-  10,  6,  7,  8,
-  10,  6,  8,  5,
-   8,  9,  6,  7,
-
-// case 5, 1=2,3=4
-  10,
-  10,  6,  0,  7,
-  10,  1,  5,  8,
-  10,  0,  1, 11,
-  10, 11,  1,  8,
-  10,  0, 11,  7,
-  10,  7, 11,  8,
-  10,  8,  5,  9,
-  10,  6,  7,  9,
-  10,  7,  8,  9,
-  10,  5,  6,  9,
-
-// case 6_0
-   4,
-   7,  8,  9,  3,
-   6,  5,  2,  9,
-   4,  1,  5,  8,
-   0,  4,  6,  7,
-
-// case 6_1
-   4,
-   6,  4,  5,  8,
-   6,  5,  9,  8,
-   6,  9,  7,  8,
-   6,  7,  4,  8,
-
-// case 6_1, a
-   4,
-   5,  8,  9,  7,
-   5,  9,  6,  7,
-   5,  6,  4,  7,
-   5,  4,  8,  7,
-
-// case 6_1, b
-   4,
-   4,  5,  6,  9,
-   4,  6,  7,  9,
-   4,  7,  8,  9,
-   4,  8,  5,  9,
-
-};
-

Deleted: MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,84 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBSimplexTemplateRefiner
-  *
-  * This is a concrete subclass of MBEntityRefiner that implements
-  * refinement using templates applied to simplices.
-  * Entities that are not simplices are divided into tetrahedra,
-  * triangles, or lines before being processed.
-  * Points are passed through unchanged.
-  *
-  * \author David Thompson
-  * \author Philippe Pebay
-  *
-  * \date 24 December 2007
-  */
-#ifndef MB_SIMPLEXTEMPLATEREFINER_H
-#define MB_SIMPLEXTEMPLATEREFINER_H
-
-#include "MBEntityRefiner.hpp"
-#include "MBSimplexTemplateTagAssigner.hpp"
-
-#include "MBTypes.h" // for MB_DLL_EXPORT
-
-class MBRefinerTagManager;
-
-class MB_DLL_EXPORT MBSimplexTemplateRefiner : public MBEntityRefiner
-{
-public:
-  MBSimplexTemplateRefiner();
-  virtual ~MBSimplexTemplateRefiner();
-
-  virtual bool refine_entity( MBEntityType etyp, MBEntityHandle entity );
-  virtual unsigned long get_heap_size_bound( int max_recursions ) const { return 48 * 4 * ( 1 << max_recursions ) + 8; }
-
-  virtual bool set_tag_assigner( MBSimplexTemplateTagAssigner* ta );
-  MBSimplexTemplateTagAssigner* get_tag_assigner() const { return this->tag_assigner; }
-
-  virtual bool prepare( MBRefinerTagManager* tmgr, MBEntityRefinerOutputFunctor* ofunc );
-
-protected:
-  MBSimplexTemplateTagAssigner* tag_assigner;
-  MBRefinerTagManager* tag_manager;
-  std::vector<double> corner_coords;
-  std::vector<void*> corner_tags;
-  std::vector<MBEntityHandle> corner_handles;
-  bool input_is_output;
-
-  static int template_index[64][2];
-  static int permutations_from_index[24][14];
-  static int templates[];
-
-  void refine_0_simplex( const double* v0, const void* t0, MBEntityHandle h0 );
-  bool refine_1_simplex( int max_depth,
-                         const double* v0, const void* t0, MBEntityHandle h0,
-                         const double* v1, const void* t1, MBEntityHandle h1 );
-  bool refine_2_simplex( int max_depth, int move,
-                         const double* v0, const void* t0, MBEntityHandle h0,
-                         const double* v1, const void* t1, MBEntityHandle h1,
-                         const double* v2, const void* t2, MBEntityHandle h2 );
-  bool refine_3_simplex( int max_depth,
-                         double* v0, void* t0, MBEntityHandle h0,
-                         double* v1, void* t1, MBEntityHandle h1,
-                         double* v2, void* t2, MBEntityHandle h2,
-                         double* v3, void* t3, MBEntityHandle h3 );
-
-  int best_tets( int* alternates, double*[14], int, int ) { return alternates[0]; }
-  void assign_parametric_coordinates( int num_nodes, const double* src, double* tgt );
-  static bool compare_Hopf_cross_string_dist( const double* v00, const double* v01, const double* v10, const double* v11 );
-};
-#endif // MB_SIMPLEXTEMPLATEREFINER_H
-

Deleted: MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,103 +0,0 @@
-#include "MBSimplexTemplateTagAssigner.hpp"
-
-#include "MBEdgeSizeEvaluator.hpp"
-#include "MBInterface.hpp"
-#include "MBRefinerTagManager.hpp"
-#include "MBSimplexTemplateRefiner.hpp"
-
-#include <vector>
-
-#include <math.h>
-
-using namespace std;
-
-/// Construct a template tag assigner.
-MBSimplexTemplateTagAssigner::MBSimplexTemplateTagAssigner( MBSimplexTemplateRefiner* r )
-{
-  this->mesh_refiner = r;
-  this->tag_manager = 0;
-}
-
-/// Empty destructor for good form.
-MBSimplexTemplateTagAssigner::~MBSimplexTemplateTagAssigner()
-{
-}
-
-/**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag values.
-  *
-  * Normally, this function will be invoked by the MBEntityRefiner before evaluate_edge is called.
-  * However, if evaluate_edge() changes the parametric coordinates of the midpoint,
-  * it should call evaluate_tags_at_midpoint() again to update any tag values;
-  * that is why this function is a member of MBEdgeSizeEvaluator and not MBEntityRefiner.
-  *
-  * @param[in] c0 Pointer to endpoint 0 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[in] t0 Pointer to endpoint 0 tag values.
-  * @param[in] cm Pointer to midpoint coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[out] tm Pointer to midpoint tag values.
-  * @param[in] c1 Pointer to endpoint 1 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[in] t1 Pointer to endpoint 1 tag values.
-  */
-void MBSimplexTemplateTagAssigner::operator () (
-  const double* c0, const void* t0, MBEntityHandle h0,
-  const double* cm, void* tm, 
-  const double* c1, const void* t1, MBEntityHandle h1 )
-{
-  double c0m_squared = 0.;
-  double c01_squared = 0.;
-  for ( int i = 0; i < 3; ++i )
-    {
-    double tmp = cm[i] - c0[i];
-    c0m_squared += tmp * tmp;
-    tmp = c1[i] - c0[i];
-    c01_squared += tmp * tmp;
-    }
-  double lambda = sqrt( c0m_squared / c01_squared );
-  double one_minus_lambda = 1. - lambda;
-
-  MBDataType data_type;
-  int tag_size;
-  int num_components;
-  int num_tags = this->tag_manager->get_number_of_vertex_tags();
-  MBTag tag_handle;
-  int tag_offset;
-  for ( int i = 0; i < num_tags; ++i )
-    {
-    this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
-    this->tag_manager->get_input_mesh()->tag_get_data_type( tag_handle, data_type );
-    this->tag_manager->get_input_mesh()->tag_get_size( tag_handle, tag_size );
-    
-    switch ( data_type )
-      {
-      case MB_TYPE_DOUBLE:
-        {
-        num_components = tag_size / sizeof( double );
-        double* t0i = (double*) ( (char*)t0 + tag_offset );
-        double* tmi = (double*) ( (char*)tm + tag_offset );
-        double* t1i = (double*) ( (char*)t1 + tag_offset );
-        for ( int i = 0; i < num_components; ++ i )
-          tmi[i] = one_minus_lambda * t0i[i] + lambda * t1i[i];
-        }
-        break;
-      default:
-        memcpy( (char*)tm + tag_offset, (char*)( h0 < h1 ? t0 : t1 ) + tag_offset, tag_size );
-        break;
-      }
-    }
-}
-
-void MBSimplexTemplateTagAssigner::operator () ( const void* t0,
-                                                 const void* t1,
-                                                 const void* t2,
-                                                 void* tp )
-{
-  (void)t0;
-  (void)t1;
-  (void)t2;
-  (void)tp;
-}
-
-void MBSimplexTemplateTagAssigner::set_tag_manager( MBRefinerTagManager* tmgr )
-{
-  this->tag_manager = tmgr;
-}
-

Deleted: MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,55 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBSimplexTemplateTagAssigner
-  *
-  * This is an class that embodies the process of assigning tag
-  * values to new vertices based on some pre-existing neighbors in a 
-  * simplicial mesh.
-  *
-  * \author David Thompson
-  * \author Philippe Pebay
-  *
-  * \date 28 December 2007
-  */
-#ifndef MB_SIMPLEXTEMPLATETAGASSIGNER_H
-#define MB_SIMPLEXTEMPLATETAGASSIGNER_H
-
-#include "MBTypes.h" // for MB_DLL_EXPORT
-
-class MBRefinerTagManager;
-class MBSimplexTemplateRefiner;
-
-class MB_DLL_EXPORT MBSimplexTemplateTagAssigner
-{
-public:
-  MBSimplexTemplateTagAssigner( MBSimplexTemplateRefiner* );
-  virtual ~MBSimplexTemplateTagAssigner();
-  
-  virtual void operator () ( const double* c0, const void* t0, MBEntityHandle h0,
-                             const double* cm, void* tm,
-                             const double* c1, const void* t1, MBEntityHandle h1 );
-  virtual void operator () ( const void* t0,
-                             const void* t1,
-                             const void* t2,
-                             void* tp );
-  virtual void set_tag_manager( MBRefinerTagManager* tmgr );
-
-protected:
-  MBSimplexTemplateRefiner* mesh_refiner;
-  MBRefinerTagManager* tag_manager;
-};
-
-#endif // MB_SIMPLEXTEMPLATETAGASSIGNER_H

Deleted: MOAB/trunk/tools/refiner/MBSplitVertices.cpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSplitVertices.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSplitVertices.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,67 +0,0 @@
-#include "MBSplitVertices.hpp"
-#include "MBRefinerTagManager.hpp"
-
-#include "MBParallelConventions.h"
-
-MBSplitVerticesBase::MBSplitVerticesBase( MBRefinerTagManager* tag_mgr )
-{
-  this->tag_manager = tag_mgr;
-  this->mesh_out = tag_mgr->get_output_mesh();
-}
-
-MBSplitVerticesBase::~MBSplitVerticesBase()
-{
-}
-
-MBEntitySource::MBEntitySource( int nc, MBRefinerTagManager* tag_mgr )
-{
-  this->tag_manager = tag_mgr;
-  this->mesh_out = tag_mgr->get_output_mesh();
-  this->num_corners = nc;
-}
-
-MBEntitySource::~MBEntitySource()
-{
-}
-
-bool MBEntitySource::create_element(
-  MBEntityType etyp, int nconn, const MBEntityHandle* elem_verts, MBEntityHandle& elem_handle,
-  std::map<MBProcessSet,int>& proc_partition_counts )
-{
-  // Get the global IDs of the input vertices
-  int stat;
-  proc_partition_counts[this->tag_manager->get_element_procs()]++;
-  if ( this->mesh_out->create_element( etyp, elem_verts, nconn, elem_handle ) != MB_SUCCESS )
-    {
-    return false;
-    }
-  this->push_back( MBEntitySourceRecord( this->num_corners, elem_handle, this->tag_manager->get_element_procs() ) );
-  this->tag_manager->set_sharing( elem_handle, this->tag_manager->get_element_procs() );
-  return true;
-}
-
-void MBEntitySource::assign_global_ids( std::map<MBProcessSet,int>& gids )
-{
-  std::vector<MBEntityHandle> adjacencies;
-  adjacencies.resize( this->num_corners );
-  std::vector<MBEntitySourceRecord>::iterator it;
-  int stat;
-  for ( it = this->begin(); it != this->end(); ++ it )
-    {
-    int num_nodes;
-    const MBEntityHandle* conn;
-    this->mesh_out->get_connectivity( it->handle, conn, num_nodes );
-    stat = this->tag_manager->get_output_gids( this->num_corners, conn, it->ids );
-    std::sort( it->ids.begin(), it->ids.end() );
-    }
-  std::sort( this->begin(), this->end() );
-  for ( it = this->begin(); it != this->end(); ++ it )
-    {
-    int gid = gids[it->process_set] ++;
-    this->tag_manager->set_gid( it->handle, gid );
-#ifdef MB_DEBUG
-    std::cout << "Assigning entity: " << it->handle << " GID: " << gid << "\n";
-#endif // MB_DEBUG
-    }
-}
-

Deleted: MOAB/trunk/tools/refiner/MBSplitVertices.hpp
===================================================================
--- MOAB/trunk/tools/refiner/MBSplitVertices.hpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/MBSplitVertices.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,256 +0,0 @@
-/*
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- * 
- * Copyright 2007 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- */
-
-/**\class MBSplitVertices
-  *\brief A dictionary of new vertices.
-  *
-  * An array of existing vertex ids used as a key in a dictionary of new vertices.
-  */
-#ifndef MB_SPLITVERTICES_HPP
-#define MB_SPLITVERTICES_HPP
-
-#include "MBTypes.h"
-#include "MBProcessSet.hpp"
-#include "MBTagConventions.hpp"
-
-#include <map>
-#include <vector>
-#include <algorithm>
-
-#undef MB_DEBUG
-
-class MBRefinerTagManager;
-
-template< int _n >
-class MBSplitVertexIndex
-{
-public:
-  MBSplitVertexIndex() { }
-  MBSplitVertexIndex( const int* src )
-    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src[i]; std::sort( this->ids, this->ids + _n ); }
-  MBSplitVertexIndex( const MBSplitVertexIndex<_n>& src )
-    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src.ids[i]; this->process_set = src.process_set; }
-  MBSplitVertexIndex& operator = ( const MBSplitVertexIndex<_n>& src )
-    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src.ids[i]; this->process_set = src.process_set; return *this; }
-
-  void set_common_processes( const MBProcessSet& procs )
-    { this->process_set = procs; }
-  MBProcessSet& common_processes()
-    { return this->process_set; }
-  const MBProcessSet& common_processes() const
-    { return this->process_set; }
-
-  bool operator < ( const MBSplitVertexIndex<_n>& other ) const
-    {
-    // Ignore the process set. Only program errors lead to mismatched process sets with identical ids.
-    for ( int i = 0; i < _n; ++ i )
-      if ( this->ids[i] < other.ids[i] )
-        return true;
-      else if ( this->ids[i] > other.ids[i] )
-        return false;
-    return false;
-    }
-
-  int ids[_n + 1];
-  MBProcessSet process_set;
-};
-
-template< int _n >
-std::ostream& operator << ( std::ostream& os, const MBSplitVertexIndex<_n>& idx )
-{
-  for ( int i = 0; i < _n; ++ i )
-    {
-    os << idx.ids[i] << " ";
-    }
-  os << "(" << idx.process_set << ")";
-  return os;
-}
-
-class MBEntitySourceRecord
-{
-public:
-  MBEntitySourceRecord() { }
-  MBEntitySourceRecord( int nc, MBEntityHandle ent, const MBProcessSet& procs )
-    { this->ids.resize( nc ); this->handle = ent; this->process_set = procs; }
-  MBEntitySourceRecord( const MBEntitySourceRecord& src )
-    { this->handle = src.handle; this->process_set = src.process_set; this->ids = src.ids; }
-  MBEntitySourceRecord& operator = ( const MBEntitySourceRecord& src )
-    { this->handle = src.handle; this->process_set = src.process_set; this->ids = src.ids; return *this; }
-
-  void set_common_processes( const MBProcessSet& procs )
-    { this->process_set = procs; }
-  MBProcessSet& common_processes()
-    { return this->process_set; }
-  const MBProcessSet& common_processes() const
-    { return this->process_set; }
-
-  bool operator < ( const MBEntitySourceRecord& other ) const
-    {
-    //assert( this->ids.size() == other.ids.size() );
-    std::vector<int>::size_type N = this->ids.size();
-    std::vector<int>::size_type i;
-    // Ignore the process set. Only program errors lead to mismatched process sets with identical ids.
-    for ( i = 0; i < N; ++ i )
-      if ( this->ids[i] < other.ids[i] )
-        return true;
-      else if ( this->ids[i] > other.ids[i] )
-        return false;
-    return false;
-    }
-
-  std::vector<int> ids;
-  MBProcessSet process_set;
-  MBEntityHandle handle;
-};
-
-
-/** A non-templated base class that the MBSplitVertices template subclasses all share.
-  *
-  * All methods that need to be accessed by other classes should be
-  * declared by the base class so that no knowledge of template parameters
-  * is required.
-  */
-class MBSplitVerticesBase
-{
-public:
-  MBSplitVerticesBase( MBRefinerTagManager* tag_mgr );
-  virtual ~MBSplitVerticesBase();
-
-  virtual bool find_or_create(
-    const MBEntityHandle* split_src, const double* coords, MBEntityHandle& vert_handle,
-    std::map<MBProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh ) = 0;
-
-  virtual void assign_global_ids( std::map<MBProcessSet,int>& gids ) = 0;
-
-  MBInterface* mesh_out; // Output mesh. Needed for new vertex set in vert_handle
-  MBRefinerTagManager* tag_manager;
-  std::vector<int> split_gids; // Used to hold global IDs of split vertices
-  MBProcessSet common_shared_procs; // Holds intersection of several shared_procs_ins.
-};
-
-/** A vector of pre-existing entities to a new mesh entity.
-  *
-  * This is used as a dictionary to determine whether a new vertex should be
-  * created on the given n-simplex (n being the template parameter) or whether
-  * it has already been created as part of the refinement of a neighboring entity.
-  */
-class MBEntitySource : public std::vector<MBEntitySourceRecord>
-{
-public:
-  typedef std::vector<MBEntitySourceRecord> VecType;
-  typedef std::vector<MBEntitySourceRecord>::iterator VecIteratorType;
-
-  MBEntitySource( int num_corners, MBRefinerTagManager* tag_mgr );
-  ~MBEntitySource();
-  bool create_element(
-    MBEntityType etyp, int nconn, const MBEntityHandle* split_src, MBEntityHandle& elem_handle,
-    std::map<MBProcessSet,int>& proc_partition_counts );
-
-  void assign_global_ids( std::map<MBProcessSet,int>& gids );
-
-  MBInterface* mesh_out; // Output mesh. Needed for new vertex set in vert_handle
-  MBRefinerTagManager* tag_manager;
-  MBProcessSet common_shared_procs; // Holds intersection of several shared_procs_ins.
-  int num_corners;
-};
-
-
-/** A map from a set of pre-existing vertices to a new mesh vertex.
-  *
-  * This is used as a dictionary to determine whether a new vertex should be
-  * created on the given n-simplex (n being the template parameter) or whether
-  * it has already been created as part of the refinement of a neighboring entity.
-  */
-template< int _n >
-class MBSplitVertices : public std::map<MBSplitVertexIndex<_n>,MBEntityHandle>, public MBSplitVerticesBase
-{
-public:
-  typedef std::map<MBSplitVertexIndex<_n>,MBEntityHandle> MapType;
-  typedef typename std::map<MBSplitVertexIndex<_n>,MBEntityHandle>::iterator MapIteratorType;
-
-  MBSplitVertices( MBRefinerTagManager* tag_mgr );
-  virtual ~MBSplitVertices();
-  virtual bool find_or_create(
-    const MBEntityHandle* split_src, const double* coords, MBEntityHandle& vert_handle,
-    std::map<MBProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh );
-
-  virtual void assign_global_ids( std::map<MBProcessSet,int>& gids );
-};
-
-// ------------------------- Template member definitions ----------------------
-template< int _n >
-MBSplitVertices<_n>::MBSplitVertices( MBRefinerTagManager* tag_mgr )
-  : MBSplitVerticesBase( tag_mgr )
-{
-  this->split_gids.resize( _n );
-}
-
-template< int _n >
-MBSplitVertices<_n>::~MBSplitVertices()
-{
-}
-
-template< int _n >
-bool MBSplitVertices<_n>::find_or_create(
-  const MBEntityHandle* split_src, const double* coords, MBEntityHandle& vert_handle,
-  std::map<MBProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh )
-{
-  // Get the global IDs of the input vertices
-  int stat;
-  if ( handles_on_output_mesh )
-    {
-    stat = this->tag_manager->get_output_gids( _n, split_src, this->split_gids );
-    }
-  else
-    {
-    stat = this->tag_manager->get_input_gids( _n, split_src, this->split_gids );
-    }
-  MBSplitVertexIndex<_n> key( &this->split_gids[0] );
-  MapIteratorType it = this->find( key );
-  if ( it == this->end() )
-    {
-#ifdef MB_DEBUG
-    std::cout << " wrt output: " << handles_on_output_mesh << " ";
-#endif // MB_DEBUG
-    this->tag_manager->get_common_processes( _n, split_src, this->common_shared_procs, handles_on_output_mesh );
-    proc_partition_counts[this->common_shared_procs]++;
-    key.set_common_processes( this->common_shared_procs );
-    if ( this->mesh_out->create_vertex( coords + 3, vert_handle ) != MB_SUCCESS )
-      {
-      return false;
-      }
-    (*this)[key] = vert_handle;
-    this->tag_manager->set_sharing( vert_handle, this->common_shared_procs );
-    return true;
-    }
-  vert_handle = it->second;
-  return false;
-}
-
-template< int _n >
-void MBSplitVertices<_n>::assign_global_ids( std::map<MBProcessSet,int>& gids )
-{
-  typename std::map<MBSplitVertexIndex<_n>,MBEntityHandle>::iterator it;
-  for ( it = this->begin(); it != this->end(); ++ it )
-    {
-    int gid = gids[it->first.process_set] ++;
-    this->tag_manager->set_gid( it->second, gid );
-#ifdef MB_DEBUG
-    std::cout << "Assigning entity: " << it->first << " GID: " << gid << "\n";
-#endif // MB_DEBUG
-    }
-}
-
-#endif /* MB_SPLITVERTICES_HPP */

Copied: MOAB/trunk/tools/refiner/MeshOutputFunctor.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBMeshOutputFunctor.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/MeshOutputFunctor.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/MeshOutputFunctor.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,298 @@
+#include "moab/MeshOutputFunctor.hpp"
+
+#include "moab/SplitVertices.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/RefinerTagManager.hpp"
+
+#include <iostream>
+#include <set>
+#include <iterator>
+#include <algorithm>
+
+#undef MB_DEBUG
+
+namespace maob {
+
+MeshOutputFunctor::MeshOutputFunctor( RefinerTagManager* tag_mgr )
+{
+  this->mesh_in  = tag_mgr->get_input_mesh();
+  this->mesh_out = tag_mgr->get_output_mesh();
+  this->input_is_output = ( this->mesh_in == this->mesh_out );
+  this->tag_manager = tag_mgr;
+  this->destination_set = 0; // don't place output entities in a set by default.
+
+  // When the input mesh and the output mesh are different, this map serves
+  // as a dictionary from input vertices to output vertices.
+  this->vertex_map = new SplitVertices<1>( this->tag_manager );
+
+  // Hold information about newly-created vertices on subdivided edges and faces.
+  this->split_vertices.resize( 4 );
+  this->split_vertices[0] = 0; // Vertices (0-faces) cannot be split
+  this->split_vertices[1] = new SplitVertices<1>( this->tag_manager );
+  this->split_vertices[2] = new SplitVertices<2>( this->tag_manager );
+  this->split_vertices[3] = new SplitVertices<3>( this->tag_manager );
+
+  // Hold information about newly-created mesh entities (other than split vertices)
+  // This is necessary in order for global IDs to be assigned consistently across processes.
+  this->new_entities.resize( 5 );
+  this->new_entities[0] = new EntitySource( 1, this->tag_manager );
+  this->new_entities[1] = new EntitySource( 2, this->tag_manager );
+  this->new_entities[2] = new EntitySource( 3, this->tag_manager );
+  this->new_entities[3] = new EntitySource( 4, this->tag_manager );
+  this->new_entities[4] = new EntitySource( 5, this->tag_manager );
+}
+
+MeshOutputFunctor::~MeshOutputFunctor()
+{
+  delete this->vertex_map;
+  for ( int i = 1; i < 4; ++ i )
+    delete this->split_vertices[i];
+  for ( int i = 0; i < 5; ++ i )
+    delete this->new_entities[i];
+}
+
+void MeshOutputFunctor::print_vert_crud(
+  EntityHandle vout, int nvhash, EntityHandle* vhash, const double* vcoords, const void* vtags )
+{
+  std::cout << "+ {";
+  for ( int i = 0; i < nvhash; ++ i )
+    std::cout << " " << vhash[i];
+  std::cout << " } -> " << vout << " ";
+
+  std::cout << "[ " << vcoords[0];
+  for ( int i = 1; i < 6; ++i )
+    std::cout << ", " << vcoords[i];
+  std::cout << " ] ";
+
+#if 0
+  double* x = (double*)vtags;
+  int* m = (int*)( (char*)vtags + 2 * sizeof( double ) );
+  std::cout << "< " << x[0]
+    << ", " << x[1];
+  for ( int i = 0; i < 4; ++i )
+    std::cout << ", " << m[i];
+#endif // 0
+
+  std::cout << " >\n";
+  //std::cout << "##############################\n";
+  //this->mesh_out->list_entities( 0, 1 );
+  //std::cout << "##############################\n";
+}
+
+void MeshOutputFunctor::assign_global_ids( ParallelComm* comm )
+{
+  // First, we must gather the number of entities in each
+  // partition (for all partitions, not just those resident locally).
+  int lnparts = this->proc_partition_counts.size();
+  std::vector<unsigned char> lpdefns;
+  std::vector<int> lpsizes;
+  lpdefns.resize( ProcessSet::SHARED_PROC_BYTES * lnparts );
+  lpsizes.resize( lnparts );
+#ifdef MB_DEBUG
+  std::cout << "**** Partition Counts ****\n";
+#endif // MB_DEBUG
+  int i = 0;
+  std::map<ProcessSet,int>::iterator it;
+  for ( it = this->proc_partition_counts.begin(); it != this->proc_partition_counts.end(); ++ it, ++ i )
+    {
+    for ( int j = 0; j < ProcessSet::SHARED_PROC_BYTES; ++ j )
+      lpdefns[ProcessSet::SHARED_PROC_BYTES * i + j] = it->first.data()[j];
+    lpsizes[i] = it->second;
+#ifdef MB_DEBUG
+    std::cout << "Partition " << it->first << ": " << it->second << "\n";
+#endif // MB_DEBUG
+    }
+
+  if ( ! comm )
+    return;
+
+  std::vector<int> nparts;
+  std::vector<int> dparts;
+  unsigned long prank = comm->proc_config().proc_rank();
+  unsigned long psize = comm->proc_config().proc_size();
+  nparts.resize( psize );
+  dparts.resize( psize + 1 );
+  MPI_Allgather( &lnparts, 1, MPI_INT, &nparts[0], 1, MPI_INT, comm->proc_config().proc_comm() );
+  unsigned long ndefs = 0;
+  for ( int rank = 1; rank <= psize; ++ rank )
+    {
+    dparts[rank] = nparts[rank - 1] + dparts[rank - 1];
+#ifdef MB_DEBUG
+    std::cout << "Proc " << rank << ": " << nparts[rank-1] << " partitions, offset: " << dparts[rank] << "\n";
+#endif // MB_DEBUG
+    }
+  std::vector<unsigned char> part_defns;
+  std::vector<int> part_sizes;
+  part_defns.resize( ProcessSet::SHARED_PROC_BYTES * dparts[psize] );
+  part_sizes.resize( dparts[psize] );
+  MPI_Allgatherv(
+    &lpsizes[0], lnparts, MPI_INT,
+    &part_sizes[0], &nparts[0], &dparts[0], MPI_INT, comm->proc_config().proc_comm() );
+  for ( int rank = 0; rank < psize; ++ rank )
+    {
+    nparts[rank] *= ProcessSet::SHARED_PROC_BYTES;
+    dparts[rank] *= ProcessSet::SHARED_PROC_BYTES;
+    }
+  MPI_Allgatherv(
+    &lpdefns[0], ProcessSet::SHARED_PROC_BYTES * lnparts, MPI_UNSIGNED_CHAR,
+    &part_defns[0], &nparts[0], &dparts[0], MPI_UNSIGNED_CHAR, comm->proc_config().proc_comm() );
+
+  // Now that we have the number of new entities in every partition, we
+  // can deterministically assign the same GID to the same entity even
+  // when shared across processors because we have an ordering that is
+  // identical on all processes -- the vertex splits.
+  for ( int i = 0; i < dparts[psize]; ++ i )
+    {
+    ProcessSet pset( &part_defns[ProcessSet::SHARED_PROC_BYTES * i] );
+    std::map<ProcessSet,int>::iterator it = this->proc_partition_counts.find( pset );
+    if ( it != this->proc_partition_counts.end() )
+      {
+#ifdef MB_DEBUG
+      std::cout << "Partition " << pset << ( it->second == part_sizes[i] ? " matches" : " broken" ) << ".\n";
+#endif // MB_DEBUG
+      }
+    else
+      {
+      this->proc_partition_counts[pset] = part_sizes[i];
+      }
+    }
+  std::map<ProcessSet,int> gids;
+  std::map<ProcessSet,int>::iterator pcit;
+  EntityHandle start_gid = 100; // FIXME: Get actual maximum GID across all processes and add 1
+  for ( pcit = this->proc_partition_counts.begin(); pcit != this->proc_partition_counts.end(); ++ pcit )
+    {
+    gids[pcit->first] = start_gid;
+    start_gid += pcit->second;
+#ifdef MB_DEBUG
+    std::cout << "Partition " << pcit->first << ": " << pcit->second << " # [" << gids[pcit->first] << "]\n";
+#endif // MB_DEBUG
+    }
+  std::vector<SplitVerticesBase*>::iterator vit;
+  vit = this->split_vertices.begin();
+  ++ vit; // Skip split_vertices[0] since it's empty.
+  ++ vit; // Skip split_vertices[1] since those entries already have global IDs... they exist in the input mesh.
+  for ( /* skip */; vit != this->split_vertices.end(); ++ vit )
+    {
+    (*vit)->assign_global_ids( gids );
+    }
+  std::vector<EntitySource*>::iterator sit;
+  for ( sit = this->new_entities.begin(); sit != this->new_entities.end(); ++ sit )
+    {
+    if ( *sit )
+      (*sit)->assign_global_ids( gids );
+    }
+}
+
+void MeshOutputFunctor::exchange_handles( ParallelComm* comm )
+{
+}
+
+void MeshOutputFunctor::assign_tags( EntityHandle vhandle, const void* vtags )
+{
+  if ( ! vhandle )
+    return; // Ignore bad vertices
+
+  int num_tags = this->tag_manager->get_number_of_vertex_tags();
+  Tag tag_handle;
+  int tag_offset;
+  for ( int i = 0; i < num_tags; ++i )
+    {
+    this->tag_manager->get_output_vertex_tag( i, tag_handle, tag_offset );
+    this->mesh_out->tag_set_data( tag_handle, &vhandle, 1, vtags );
+    }
+}
+
+EntityHandle MeshOutputFunctor::map_vertex( EntityHandle vhash, const double* vcoords, const void* vtags )
+{
+  if ( this->input_is_output )
+    { // Don't copy the original vertex!
+#ifdef MB_DEBUG
+    this->print_vert_crud( vhash, 1, &vhash, vcoords, vtags );
+#endif // MB_DEBUG
+    return vhash;
+    }
+  EntityHandle vertex_handle;
+  bool newly_created = this->vertex_map->find_or_create(
+    &vhash, vcoords, vertex_handle, this->proc_partition_counts, false );
+  if ( newly_created )
+    {
+    std::vector<int> gid;
+    this->assign_tags( vertex_handle, vtags );
+    if ( this->tag_manager->get_input_gids( 1, &vhash, gid ) == MB_SUCCESS )
+      {
+      this->tag_manager->set_gid( vertex_handle, gid[0] );
+      }
+    }
+  if ( ! vertex_handle )
+    {
+    std::cerr << "Could not insert vertex into new mesh!\n";
+    }
+#ifdef MB_DEBUG
+  this->print_vert_crud( vertex_handle, 1, &vhash, vcoords, vtags );
+  std::cout << "\nMap vert: " << vhash << " to: " << vertex_handle << "\n";
+#endif // MB_DEBUG
+  return vertex_handle;
+}
+
+EntityHandle MeshOutputFunctor::operator () ( int nvhash, EntityHandle* vhash, const double* vcoords, const void* vtags )
+{
+  EntityHandle vertex_handle;
+  if ( nvhash < 4 )
+    {
+    bool newly_created = this->split_vertices[nvhash]->find_or_create(
+      vhash, vcoords, vertex_handle, this->proc_partition_counts, true );
+    if ( newly_created )
+      {
+      this->assign_tags( vertex_handle, vtags );
+      }
+    if ( ! vertex_handle )
+      {
+      std::cerr << "Could not insert mid-edge vertex!\n";
+      }
+#ifdef MB_DEBUG
+    std::cout << "(-" << nvhash << "-) ";
+    this->print_vert_crud( vertex_handle, nvhash, vhash, vcoords, vtags );
+#endif // MB_DEBUG
+    }
+  else
+    {
+    vertex_handle = 0;
+    std::cerr << "Not handling splits on faces with " << nvhash << " corners yet.\n";
+    }
+  return vertex_handle;
+}
+
+void MeshOutputFunctor::operator () ( EntityHandle h )
+{
+#ifdef MB_DEBUG
+  std::cout << h << " ";
+#endif // MB_DEBUG
+  if ( ! this->input_is_output )
+    {
+    // FIXME: Copy to output mesh
+    }
+  this->elem_vert.push_back( h );
+}
+
+void MeshOutputFunctor::operator () ( EntityType etyp )
+{
+  EntityHandle elem_handle;
+  int nconn = this->elem_vert.size();
+  bool newly_created = this->new_entities[nconn]->create_element(
+    etyp, nconn, &this->elem_vert[0], elem_handle, this->proc_partition_counts );
+  if ( newly_created )
+    {
+#ifdef MB_DEBUG
+    std::cout << " *** ";
+#endif // MB_DEBUG
+    // FIXME: Handle tag assignment for elements as well as vertices
+    this->tag_manager->assign_element_tags( elem_handle );
+    }
+#ifdef MB_DEBUG
+  std::cout << "---------> " << elem_handle << " ( " << etyp << " )\n\n";
+#endif // MB_DEBUG
+  this->elem_vert.clear();
+}
+
+} // namespace moab
+

Copied: MOAB/trunk/tools/refiner/MeshOutputFunctor.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBMeshOutputFunctor.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/MeshOutputFunctor.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/MeshOutputFunctor.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,77 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class MeshOutputFunctor
+  *\brief Implements the abstract EntityRefinerOutputFunctor class.
+  *
+  * This class is a concrete implementation of the EntityRefinerOutputFunctor.
+  * It creates new vertices and regions in a new or existing mesh as
+  * the input entities are streamed through the refiner.
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 28 July 2008
+  */
+#ifndef MOAB_MESH_OUTPUT_FUNCTOR_HPP
+#define MOAB_MESH_OUTPUT_FUNCTOR_HPP
+
+#include "moab/Types.h"
+#include "moab/EntityRefiner.hpp"
+#include "moab/ProcessSet.hpp"
+
+#include <vector>
+#include <map>
+
+#include <string.h>
+
+namespace moab {
+
+class SplitVerticesBase;
+class EntitySource;
+class ParallelComm;
+
+class MeshOutputFunctor : public EntityRefinerOutputFunctor
+{
+public:
+  MeshOutputFunctor( RefinerTagManager* tag_mgr );
+  ~MeshOutputFunctor();
+
+  void print_vert_crud( EntityHandle vout, int nvhash, EntityHandle* vhash, const double* vcoords, const void* vtags );
+  void assign_global_ids( ParallelComm* comm );
+  void exchange_handles( ParallelComm* comm );
+
+  void assign_tags( EntityHandle vhandle, const void* vtags );
+
+  virtual EntityHandle map_vertex( EntityHandle vhash, const double* vcoords, const void* vtags );
+  virtual EntityHandle operator () ( int nvhash, EntityHandle* vhash, const double* vcoords, const void* vtags );
+  virtual void operator () ( EntityHandle h );
+  virtual void operator () ( EntityType etyp );
+
+  Interface* mesh_in;
+  Interface* mesh_out;
+  bool input_is_output;
+  SplitVerticesBase* vertex_map;
+  std::vector<SplitVerticesBase*> split_vertices;
+  std::vector<EntitySource*> new_entities;
+  std::vector<EntityHandle> elem_vert;
+  RefinerTagManager* tag_manager;
+  EntityHandle destination_set;
+  std::map<ProcessSet,int> proc_partition_counts;
+};
+
+} // namespace moab 
+
+#endif // MOAB_MESH_OUTPUT_FUNCTOR_HPP

Copied: MOAB/trunk/tools/refiner/MeshRefiner.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBMeshRefiner.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/MeshRefiner.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/MeshRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,143 @@
+#include "moab/MeshRefiner.hpp"
+
+#include "moab/EdgeSizeEvaluator.hpp"
+#include "moab/EntityRefiner.hpp"
+#include "moab/Interface.hpp"
+#include "moab/RefinerTagManager.hpp"
+#include "moab/MeshOutputFunctor.hpp"
+
+#ifdef USE_MPI
+#include "moab/ParallelComm.hpp"
+#include "moab_mpi.h"
+#else // USE_MPI
+typedef int MPI_Comm;
+#endif // USE_MPI
+
+namespace moab {
+
+/**\brief Construct a mesh refiner.
+  * The input and output mesh pointers may be identical.
+  * Existing elements will <b>not</b> be removed from the input mesh
+  * as they are refined, so the adjacencies for entitities may appear
+  * strange after refinement.
+  */
+MeshRefiner::MeshRefiner( Interface* imesh, Interface* omesh )
+{  
+  this->mesh_in = imesh;
+  this->mesh_out = omesh;
+  this->tag_manager = new RefinerTagManager( this->mesh_in, this->mesh_out );
+  this->output_functor = new MeshOutputFunctor( this->tag_manager );
+  this->entity_refiner = 0;
+  this->comm = ParallelComm::get_pcomm( this->mesh_out, 0 );
+}
+
+/**\brief Destroy a mesh refiner.
+  *
+  * Note that any EntityRefiner object associated with the mesh refiner will be deleted inside this destructor.
+  * Destruction is virtual so subclasses may clean up after refinement.
+  */
+MeshRefiner::~MeshRefiner()
+{
+  delete this->tag_manager;
+  delete this->output_functor;
+  if ( this->entity_refiner )
+    delete this->entity_refiner;
+}
+
+/**\brief Specify which techniqe will be used to refine entities in the mesh.
+  * The entity refiner object you specify is ``owned'' by the mesh refiner after this call;
+  * the entity refiner will be deleted when this mesh refiner is destroyed.
+  * You should not delete the entity refiner yourself.
+  */
+bool MeshRefiner::set_entity_refiner( EntityRefiner* er )
+{
+  if ( ! er || er == this->entity_refiner )
+    return false;
+
+  this->entity_refiner = er;
+  return true;
+}
+
+/**\brief A convenience method to reset the list of tags to be copied to output vertices.
+  * This simply calls the method of the same name on the tag manager.
+  */
+void MeshRefiner::reset_vertex_tags()
+{
+  this->tag_manager->reset_vertex_tags();
+}
+
+/**\brief A convenience method to add a tag to be copied/interpolated from input vertices to output vertices.
+  * This simply calls the method of the same name on the tag manager.
+  */
+int MeshRefiner::add_vertex_tag( Tag tag_handle )
+{
+  return this->tag_manager->add_vertex_tag( tag_handle );
+}
+
+struct MeshRefinerIterator {
+  Range subset;
+  EntityHandle destination_set;
+};
+
+/**\brief Refine entities in a mesh set.
+  * This will recursively descend any mesh sets contained in the \a range.
+  * It returns false when not able to refine (because no entity refiner is
+  * set or no edge size evaluator has been set on the entity refiner) and
+  * true otherwise.
+  */
+bool MeshRefiner::refine( Range& range )
+{
+  this->tag_manager->create_output_tags();
+  if ( ! this->entity_refiner->prepare( this->tag_manager, this->output_functor ) )
+    { // Oops, perhaps the edge_size_evaluator was not set?
+    return false;
+    }
+
+  MeshRefinerIterator entry;
+  std::vector<MeshRefinerIterator> work;
+
+  entry.subset = range;
+  entry.destination_set = 0;
+  work.push_back( entry );
+
+  while ( ! work.empty() )
+    {
+    entry = work.back();
+    work.pop_back();
+    this->output_functor->destination_set = entry.destination_set;
+    for ( Range::const_iterator it = entry.subset.begin(); it != entry.subset.end(); ++ it )
+      {
+      EntityType etyp = this->mesh_in->type_from_handle( *it );
+      if ( etyp == MBENTITYSET )
+        {
+        Range set_ents;
+        if ( this->mesh_in->get_entities_by_handle( *it, set_ents, false ) == MB_SUCCESS )
+          {
+          // Create a matching set on the output mesh.
+          MeshRefinerIterator set_work;
+          unsigned int set_work_opts;
+          this->mesh_in->get_meshset_options( *it, set_work_opts );
+          this->mesh_out->create_meshset( set_work_opts, set_work.destination_set );
+          set_work.subset = set_ents;
+          work.push_back( set_work );
+          // Copy any per-element tag values the user has requested to the output set.
+          this->tag_manager->set_element_tags_from_ent( *it );
+          this->tag_manager->assign_element_tags( set_work.destination_set );
+          // Copy the global ID to the new set (assuming it exists).
+          this->tag_manager->copy_gid( *it, set_work.destination_set );
+          }
+        }
+      else
+        {
+        this->tag_manager->set_element_tags_from_ent( *it );
+        this->tag_manager->set_element_procs_from_ent( *it );
+        this->entity_refiner->refine_entity( etyp, *it );
+        }
+      }
+    }
+  this->output_functor->assign_global_ids( this->comm );
+
+  return true;
+}
+
+} // namespace moab 

Copied: MOAB/trunk/tools/refiner/MeshRefiner.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBMeshRefiner.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/MeshRefiner.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/MeshRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,72 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class MeshRefiner
+  *\brief Refine a mesh using a streaming operation.
+  *
+  * This is an class that contains the method used for mesh refinement.
+  *
+  * \author Philippe Pebay
+  * \author David Thompson
+  *
+  * \date 19 November 2007
+  */
+#ifndef MOAB_MESH_REFINER_HPP
+#define MOAB_MESH_REFINER_HPP
+
+#include "moab/Types.h" // for MB_DLL_EXPORT
+#include "moab/Range.hpp"
+
+#include <vector>
+
+namespace moab {
+
+class Interface;
+class EntityRefiner;
+class ParallelComm;
+class RefinerTagManager;
+class MeshOutputFunctor;
+
+class MB_DLL_EXPORT MeshRefiner
+{
+public:
+  MeshRefiner( Interface* imesh, Interface* omesh );
+  virtual ~MeshRefiner();
+
+  bool set_entity_refiner( EntityRefiner* );
+  EntityRefiner* get_entity_refiner() { return this->entity_refiner; }
+
+  bool set_comm( ParallelComm* c ) { if ( ! c || this->comm == c ) return false; this->comm = c; return true; }
+  ParallelComm* get_comm() { return this->comm; }
+
+  RefinerTagManager* get_tag_manager() { return this->tag_manager; }
+  const RefinerTagManager* get_tag_manager() const { return this->tag_manager; }
+  void reset_vertex_tags();
+  int add_vertex_tag( Tag tag_handle );
+
+  virtual bool refine( Range& );
+
+protected:
+  Interface* mesh_in;
+  Interface* mesh_out;
+  EntityRefiner* entity_refiner;
+  RefinerTagManager* tag_manager;
+  MeshOutputFunctor* output_functor;
+  ParallelComm* comm;
+};
+
+} // namespace moab
+
+#endif // MOAB_MESH_REFINER_HPP

Copied: MOAB/trunk/tools/refiner/ProcessSet.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBProcessSet.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/ProcessSet.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/ProcessSet.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,141 @@
+#include "moab/ProcessSet.hpp"
+
+#include <assert.h>
+
+namespace moab {
+
+ProcessSet::ProcessSet()
+{
+  this->clear();
+}
+
+ProcessSet::ProcessSet( const unsigned char* psetbits )
+{
+  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
+    this->processes[i] = psetbits[i];
+}
+
+ProcessSet::~ProcessSet()
+{
+}
+
+void ProcessSet::unite( const ProcessSet& other )
+{
+  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
+    {
+    this->processes[i] |= other.processes[i];
+    }
+}
+
+void ProcessSet::intersect( const ProcessSet& other )
+{
+  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
+    {
+    this->processes[i] &= other.processes[i];
+    }
+}
+
+void ProcessSet::clear()
+{
+  memset( this->processes, 0, SHARED_PROC_BYTES );
+}
+
+/**\brief Add a process to this process set.
+  *
+  * This does not verify that \a proc is within the range [0,MAX_SHARING_PROCS[ .
+  * You are responsible for that.
+  */
+void ProcessSet::set_process_member( int proc )
+{
+  int byte = proc / 8;
+  int bitmask = 1 << ( proc % 8 );
+  this->processes[byte] |= bitmask;
+}
+
+/**\brief Add each process in the input vector to this process set.
+  *
+  * This is a convenience routine that calls set_process_member() for each entry in the vector.
+  * This does not verify that \a proc is within the range [0,MAX_SHARING_PROCS[ .
+  * You are responsible for that.
+  */
+void ProcessSet::set_process_members( const std::vector<int>& procs )
+{
+  for ( std::vector<int>::const_iterator it = procs.begin(); it != procs.end() && *it != -1; ++ it )
+    {
+    this->set_process_member( *it );
+    }
+}
+
+/**\brief Retrieve a vector containing processes in this set.
+  *
+  * @param [in] rank The rank of the local process. This integer will not be included in the output list.
+  * @param [out] procs The vector in which the list of sharing processes is listed.
+  * @return   True when \a rank is the owning process and false otherwise.
+  */
+bool ProcessSet::get_process_members( int rank, std::vector<int>& procs )
+{
+  int i = 0;
+  assert( rank >= 0 );
+  procs.clear();
+  bool rank_owner = false;
+  for ( int byte = 0; byte < SHARED_PROC_BYTES; ++ byte )
+    {
+    i = byte * 8;
+    for ( unsigned char val = this->processes[byte]; val; ++ i, val >>= 1 )
+      {
+      if ( val & 0x1 )
+        {
+        if ( i != rank )
+          {
+          //std::cout << " " << i;
+          procs.push_back( i );
+          }
+        else if ( ! procs.size() )
+          {
+          rank_owner = true;
+          }
+        }
+      }
+    }
+  for ( i = procs.size(); i < MAX_SHARING_PROCS; ++ i )
+    {
+    procs.push_back( -1 ); // pad with invalid values
+    }
+  return rank_owner;
+}
+
+bool ProcessSet::is_process_member( int i ) const
+{
+  int byte = i / 8;
+  int bitmask = 1 << ( i % 8 );
+  return ( this->processes[byte] & bitmask ) ? true : false;
+}
+
+const unsigned char* ProcessSet::data() const
+{
+  return this->processes;
+}
+
+bool ProcessSet::operator < ( const ProcessSet& other ) const
+{
+  for ( int i = 0; i < SHARED_PROC_BYTES; ++ i )
+    {
+    if ( this->processes[i] < other.processes[i] )
+      return true;
+    else if ( this->processes[i] > other.processes[i] )
+      return false;
+    }
+  return false; // equality
+}
+
+std::ostream& operator << ( std::ostream& os, const ProcessSet& pset )
+{
+  for ( int i = 0; i < MAX_SHARING_PROCS; ++ i )
+    {
+    os << ( pset.is_process_member( i ) ? "1" : "0" );
+    }
+  return os;
+}
+
+} // namespace moab
+

Copied: MOAB/trunk/tools/refiner/ProcessSet.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBProcessSet.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/ProcessSet.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/ProcessSet.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,70 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class ProcessSet
+  *\brief Represent a set of processes using a bit vector.
+  *
+  * This is used by the mesh refiner when determining where to record
+  * split vertices so that labeling can be inferred across process
+  * boundaries without communicating anything other than the number of
+  * entities in a given partition.
+  */
+#ifndef MOAB_PROCESS_SET_HPP
+#define MOAB_PROCESS_SET_HPP
+
+#include "moab/Types.h"
+#include "moab/ParallelComm.hpp"
+
+#include <iostream>
+#include <vector>
+
+namespace moab {
+
+class ProcessSet
+{
+public:
+  enum
+    {
+    SHARED_PROC_BYTES = (MAX_SHARING_PROCS / 8 + (MAX_SHARING_PROCS % 8 ? 1 : 0))
+    };
+
+  ProcessSet();
+  ProcessSet( const unsigned char* psetbits );
+  ~ProcessSet();
+
+  void unite( const ProcessSet& other );
+  void intersect( const ProcessSet& other );
+
+  void clear();
+
+  void set_process_member( int i );
+  void set_process_members( const std::vector<int>& procs );
+
+  bool get_process_members( int rank, std::vector<int>& procs );
+  bool is_process_member( int i ) const;
+
+  const unsigned char* data() const;
+
+  bool operator < ( const ProcessSet& other ) const;
+
+  friend std::ostream& operator << ( std::ostream& os, const ProcessSet& pset );
+
+protected:
+  unsigned char processes[SHARED_PROC_BYTES];
+};
+
+} // namespace moab
+
+#endif /* MOAB_PROCESS_SET_HPP */

Copied: MOAB/trunk/tools/refiner/Refiner.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBRefiner.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/Refiner.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/Refiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,1576 @@
+/*
+ * Copyright 2003 Sandia Corporation.
+ * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
+ * license for use of this work by or on behalf of the
+ * U.S. Government. Redistribution and use in source and binary forms, with
+ * or without modification, are permitted provided that this Notice and any
+ * statement of authorship are reproduced on all copies.
+ */
+
+#include "moab/Refiner.h"
+#include "moab/EdgeEvaluator.h"
+
+#include "verdict.h"
+
+namespace moab {
+
+// how's this for avoiding namespace conflicts?! 8-)
+static vtkTetra* argyle = 0;
+static int argyleRef = 0;
+static vtkPoints* goCallTheCops;
+
+
+#undef UGLY_ASPECT_RATIO_HACK
+#undef DBG_MIDPTS
+
+#include <stack>
+#include <algorithm>
+
+#ifdef PARAVIEW_DEBUG_TESSELLATOR
+#  define VTK_TESSELLATOR_INCR_CASE_COUNT(cs) this->CaseCounts[cs]++
+#  define VTK_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc) this->SubcaseCounts[cs][sc]++
+#else // PARAVIEW_DEBUG_TESSELLATOR
+#  define VTK_TESSELLATOR_INCR_CASE_COUNT(cs)
+#  define VTK_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc)
+#endif // PARAVIEW_DEBUG_TESSELLATOR
+
+Refiner::Refiner()
+{
+  this->PrivateData = 0;
+  this->ConstPrivateData = 0;
+  this->Algorithm = 0;
+  this->Callback1 = 0;
+  this->Callback2 = 0;
+  this->Callback3 = 0;
+  this->MaximumNumberOfSubdivisions = 3;
+  for ( int i=0; i<4; ++i )
+    {
+    this->EmbeddingDimension[i] = i;
+    this->PointDimension[i] = i+3; // By default, FieldSize = 0
+    }
+  if ( ! argyle )
+    {
+    argyle = vtkTetra::New();
+    argyleRef = 1;
+    goCallTheCops = argyle->GetPoints();
+    }
+  else
+    {
+    ++argyleRef;
+    }
+}
+
+Refiner::~Refiner()
+{
+  if ( this->Algorithm )
+    this->Algorithm->UnRegister( this );
+  if ( ! (--argyleRef) )
+    {
+    argyle->Delete();
+    argyle = 0;
+    }
+}
+
+void Refiner::SetEmbeddingDimension( int k, int d )
+{
+  if ( d > 8 )
+    {
+    ErrorMacro( "Embedding dimension may not be > 8. (You asked for " << d << "). Truncating to 8." );
+    d = 8;
+    }
+
+  if ( k == 0 || k < -1 || k >= 4 )
+    {
+    vtkWarningMacro( "Invalid argument k=" << k );
+    return;
+    }
+
+  if ( k < 0 )
+    {
+    for ( k=0; k<4; k++ )
+      if ( this->EmbeddingDimension[k] != d )
+        {
+        this->PointDimension[k] += d - this->EmbeddingDimension[k] ;
+        this->EmbeddingDimension[k] = d;
+        this->Modified();
+        }
+    return;
+    }
+  if ( this->EmbeddingDimension[k] != d )
+    {
+    this->PointDimension[k] += d - this->EmbeddingDimension[k] ;
+    this->EmbeddingDimension[k] = d;
+    this->Modified();
+    }
+}
+
+void Refiner::SetFieldSize( int k, int s )
+{
+  if ( s > Refiner::MaxFieldSize )
+    {
+    ErrorMacro( "Embedding dimension may not be > " << MaxFieldSize << ". (You asked for " << s << "). Truncating to " << MaxFieldSize );
+    s = Refiner::MaxFieldSize;
+    }
+
+  if ( k == 0 || k < -1 || k >= 4 )
+    {
+    vtkWarningMacro( "Invalid argument k=" << k );
+    return;
+    }
+
+  if ( k < 0 )
+    {
+    // Use field size for all facet types (point, line, triangle, tet, ...)
+    for ( k=0; k<4; k++ )
+      if ( this->PointDimension[k] != s + this->EmbeddingDimension[k] + 3 )
+        {
+        this->PointDimension[k] = s + this->EmbeddingDimension[k] + 3;
+        this->Modified();
+        }
+    return;
+    }
+
+  if ( this->PointDimension[k] != s + this->EmbeddingDimension[k] + 3 )
+    {
+    this->PointDimension[k] = s + this->EmbeddingDimension[k] + 3;
+    this->Modified();
+    }
+}
+
+void Refiner::SetMaximumNumberOfSubdivisions( int num_subdiv_in )
+{
+  if ( this->MaximumNumberOfSubdivisions == num_subdiv_in )
+    return;
+
+  if ( num_subdiv_in < 0 )
+    {
+    ErrorMacro( "MaximumNumberOfSubdivisions must be 0 or greater (you requested " << num_subdiv_in << ")" );
+    return;
+    }
+
+  this->MaximumNumberOfSubdivisions = num_subdiv_in;
+  this->Modified();
+}
+
+void Refiner::SetTriangleCallback( TriangleProcessorFunction f )
+{
+  this->Callback2 = f;
+}
+
+Refiner::TriangleProcessorFunction Refiner::GetTriangleCallback() const
+{
+  return this->Callback2;
+}
+
+void Refiner::SetTetrahedronCallback( TetrahedronProcessorFunction f )
+{
+  this->Callback3 = f;
+}
+
+Refiner::TetrahedronProcessorFunction Refiner::GetTetrahedronCallback() const
+{
+  return this->Callback3;
+}
+
+void Refiner::SetEdgeCallback( EdgeProcessorFunction f )
+{
+  this->Callback1 = f;
+}
+
+Refiner::EdgeProcessorFunction Refiner::GetEdgeCallback() const
+{
+  return this->Callback1;
+}
+
+void Refiner::SetPrivateData( void* Private )
+{
+  this->PrivateData = Private;
+}
+
+void* Refiner::GetPrivateData() const
+{
+  return this->PrivateData;
+}
+
+void Refiner::SetConstPrivateData( const void* ConstPrivate )
+{
+  this->ConstPrivateData = ConstPrivate;
+}
+
+const void* Refiner::GetConstPrivateData() const
+{
+  return this->ConstPrivateData;
+}
+
+void Refiner::SetSubdivisionAlgorithm( vtkSubdivisionAlgorithm* a )
+{
+  if ( a != this->Algorithm )
+    {
+    if ( this->Algorithm )
+      this->Algorithm->UnRegister( this );
+
+    this->Algorithm = a;
+    this->Modified();
+
+    if ( this->Algorithm )
+      this->Algorithm->Register( this );
+    }
+}
+
+// Returns true if || a0a1 || < || b0b1 ||
+// We use this to test which triangulation has the best
+// aspect ratio when there are 2 to choose from.
+bool compare_Hopf_cross_string_dist( const double* a0, const double* a1, const double* b0, const double* b1 )
+{
+  double SqMagA = 0.;
+  double SqMagB = 0.;
+  for (int i=0; i<3; i++)
+    {
+    double tmp;
+    tmp = a0[i] - a1[i];
+    SqMagA += tmp*tmp;
+    tmp = b0[i] - b1[i];
+    SqMagB += tmp*tmp;
+    }
+  return SqMagA < SqMagB;
+}
+
+
+int Refiner::BestTets( int* connOffsets, double** verts, int permOffset, int sgn ) const
+{
+  int bestOffset = -1;
+  double bestQuality = 0.;
+  double currQuality;
+
+  while ( *connOffsets >= 0 )
+    {
+    int nTets = TetrahedralDecompositions[*connOffsets];
+    vtkIdType* conn = &TetrahedralDecompositions[*connOffsets +1];
+    int v;
+    currQuality = 0.;
+    for (v=0; v<nTets; ++v)
+      {
+      goCallTheCops->SetPoint( 0, verts[ Refiner::PermutationsFromIndex[ permOffset ][ conn[sgn < 0 ? 1:0]] ] );
+      goCallTheCops->SetPoint( 1, verts[ Refiner::PermutationsFromIndex[ permOffset ][ conn[sgn < 0 ? 0:1]] ] );
+      goCallTheCops->SetPoint( 2, verts[ Refiner::PermutationsFromIndex[ permOffset ][ conn[2]] ] );
+      goCallTheCops->SetPoint( 3, verts[ Refiner::PermutationsFromIndex[ permOffset ][ conn[3]] ] );
+      currQuality += vtkMeshQuality::TetAspectFrobenius( argyle );
+      conn += 4;
+      }
+    currQuality /= nTets;
+    //std::cout << currQuality << " " << *connOffsets << " ";
+    if ( bestQuality > currQuality || bestOffset < 0 )
+      {
+      bestQuality = currQuality;
+      bestOffset = *connOffsets;
+      }
+      ++connOffsets;
+    }
+    //std::cout << "Choose " << bestOffset << "\n";
+  return bestOffset;
+}
+
+
+void Refiner::AdaptivelySample1Facet( double* v0, double* v1, int maxDepth ) const
+{
+  int edgeCode = 0;
+
+  double midpt0[11+Refiner::MaxFieldSize];
+  // make valgrind happy
+  std::fill(midpt0,midpt0+this->PointDimension[1],0.);
+
+  if ( maxDepth-- > 0 )
+    {
+      for ( int i=0; i<this->PointDimension[1]; i++ )
+        midpt0[i] = (v0[i] + v1[i])/2.;
+
+      if ( this->Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[1] ) )
+        edgeCode += 1;
+    }
+
+  switch (edgeCode) {
+    // No edges to subdivide
+    case 0:
+      Callback1( v0, v1, this->Algorithm, this->PrivateData, this->ConstPrivateData );
+      break ;
+
+      // One edge to subdivide
+    case 1:
+      this->AdaptivelySample1Facet( v0, midpt0, maxDepth );
+      this->AdaptivelySample1Facet( midpt0, v1, maxDepth );
+      break;
+  }
+}
+
+void Refiner::AdaptivelySample2Facet( double* v0, double* v1, double* v2, int maxDepth, int move ) const
+{
+  int edgeCode = 0;
+
+  double midpt0[11+Refiner::MaxFieldSize];
+  double midpt1[11+Refiner::MaxFieldSize];
+  double midpt2[11+Refiner::MaxFieldSize];
+
+  // Make valgrind happy
+  std::fill(midpt0,midpt0+this->PointDimension[2],0.);
+  std::fill(midpt1,midpt1+this->PointDimension[2],0.);
+  std::fill(midpt2,midpt2+this->PointDimension[2],0.);
+
+  if ( maxDepth-- > 0 )
+    {
+
+    for ( int i=0; i<this->PointDimension[2]; i++ )
+      {
+      midpt0[i] = (v0[i] + v1[i])/2.;
+      midpt1[i] = (v1[i] + v2[i])/2.;
+      midpt2[i] = (v2[i] + v0[i])/2.;
+      }
+
+    if ( (move & 1) && Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[2] ) )
+      edgeCode += 1;
+    if ( (move & 2) && Algorithm->EvaluateEdge( v1, midpt1, v2, 3+this->EmbeddingDimension[2] ) )
+      edgeCode += 2;
+    if ( (move & 4) && Algorithm->EvaluateEdge( v2, midpt2, v0, 3+this->EmbeddingDimension[2] ) )
+      edgeCode += 4;
+#ifdef UGLY_ASPECT_RATIO_HACK
+    double dist0=0.;
+    double dist1=0.;
+    double dist2=0.;
+    double tmp;
+    for ( int j=0; j<3; ++j )
+      {
+      tmp = v0[j] - v1[j];
+      dist0 += tmp*tmp;
+      tmp = v1[j] - v2[j];
+      dist1 += tmp*tmp;
+      tmp = v2[j] - v0[j];
+      dist2 += tmp*tmp;
+      }
+
+    if ( edgeCode & 1 ) dist0 /= 2.;
+    if ( edgeCode & 2 ) dist1 /= 2.;
+    if ( edgeCode & 4 ) dist2 /= 2.;
+
+#define MAR2 2.25
+    if ( (!(edgeCode & 1)) && (move&1) && ((dist0/dist1 > MAR2) || (dist0/dist2 > MAR2)) )
+      {
+      edgeCode += 1;
+      move &= 6;
+      }
+    if ( (!(edgeCode & 2)) && (move&2) && ((dist1/dist0 > MAR2) || (dist1/dist2 > MAR2)) )
+      {
+      edgeCode += 2;
+      move &= 5;
+      }
+    if ( (!(edgeCode & 4)) && (move&4) && ((dist2/dist1 > MAR2) || (dist2/dist0 > MAR2)) )
+      {
+      edgeCode += 4;
+      move &= 3;
+      }
+#endif // UGLY_ASPECT_RATIO_HACK
+    }
+
+#ifdef DBG_MIDPTS
+  if ( maxDepth == 0 )
+    {
+    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n",
+      0, v0[0], v0[1], v0[2], v0[3], v0[4], v0[5],
+      1, v1[0], v1[1], v1[2], v1[3], v1[4], v1[5],
+         midpt0[0], midpt0[1], midpt0[2], midpt0[3], midpt0[4], midpt0[5]
+    );
+
+    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n",
+      1, v1[0], v1[1], v1[2], v1[3], v1[4], v1[5],
+      2, v2[0], v2[1], v2[2], v2[3], v2[4], v2[5],
+         midpt1[0], midpt1[1], midpt1[2], midpt1[3], midpt1[4], midpt1[5]
+    );
+
+    fprintf( stderr, "midpoint of v%d (%g %g %g/%g %g %g)-v%d (%g %g %g/%g %g %g) = (%g %g %g/%g %g %g)\n\n",
+      2, v2[0], v2[1], v2[2], v2[3], v2[4], v2[5],
+      0, v0[0], v0[1], v0[2], v0[3], v0[4], v0[5],
+         midpt2[0], midpt2[1], midpt2[2], midpt2[3], midpt2[4], midpt2[5]
+    );
+    }
+#endif // DBG_MIDPTS
+
+  switch (edgeCode)
+    {
+    // No edges to subdivide
+  case 0:
+    Callback2( v0, v1, v2, this->Algorithm, this->PrivateData, this->ConstPrivateData );
+    break ;
+
+    // One edge to subdivide
+  case 1:
+    this->AdaptivelySample2Facet( v0, midpt0, v2, maxDepth, move | 2 );
+    this->AdaptivelySample2Facet( midpt0, v1, v2, maxDepth, move | 4 );
+    break;
+  case 2:
+    this->AdaptivelySample2Facet( v0, v1, midpt1, maxDepth, move | 4 );
+    this->AdaptivelySample2Facet( v0, midpt1, v2, maxDepth, move | 1 );
+    break;
+  case 4:
+    this->AdaptivelySample2Facet( v0, v1, midpt2, maxDepth, move | 2 );
+    this->AdaptivelySample2Facet( midpt2, v1, v2, maxDepth, move | 1 );
+    break;
+
+    // Two edges to subdivide
+  case 3:
+    this->AdaptivelySample2Facet( midpt0, v1, midpt1, maxDepth, move | 4 );
+    if ( compare_Hopf_cross_string_dist( v2, midpt0, v0, midpt1 ) )
+      {
+      this->AdaptivelySample2Facet( midpt0, midpt1,   v2  , maxDepth, move | 5 );
+      this->AdaptivelySample2Facet(   v0,   midpt0,   v2  , maxDepth, move | 2 );
+      }
+    else
+      {
+      this->AdaptivelySample2Facet(   v0  , midpt0, midpt1, maxDepth, move | 6 );
+      this->AdaptivelySample2Facet(   v0,   midpt1,   v2  , maxDepth, move | 1 );
+      }
+    break;
+  case 5:
+    this->AdaptivelySample2Facet( v0, midpt0, midpt2, maxDepth, move | 2 );
+    if ( compare_Hopf_cross_string_dist( v2, midpt0, v1, midpt2 ) )
+      {
+      this->AdaptivelySample2Facet( midpt0,   v1,     v2  , maxDepth, move | 4 );
+      this->AdaptivelySample2Facet( midpt2, midpt0,   v2  , maxDepth, move | 3 );
+      }
+    else
+      {
+      this->AdaptivelySample2Facet( midpt0,   v1,   midpt2, maxDepth, move | 6 );
+      this->AdaptivelySample2Facet( midpt2,   v1,     v2,   maxDepth, move | 1 );
+      }
+    break;
+  case 6:
+    this->AdaptivelySample2Facet( midpt2, midpt1, v2, maxDepth, move | 1 );
+    if ( compare_Hopf_cross_string_dist( v0, midpt1, v1, midpt2 ) )
+      {
+      this->AdaptivelySample2Facet(   v0,   midpt1, midpt2, maxDepth, move | 3 );
+      this->AdaptivelySample2Facet(   v0,     v1,   midpt1, maxDepth, move | 4 );
+      }
+    else
+      {
+      this->AdaptivelySample2Facet(   v0,     v1,   midpt2, maxDepth, move | 2 );
+      this->AdaptivelySample2Facet( midpt2,   v1,   midpt1, maxDepth, move | 5 );
+      }
+    break;
+
+    // Three edges to subdivide
+  case 7:
+    this->AdaptivelySample2Facet( midpt0, midpt1, midpt2, maxDepth, 7 );
+    this->AdaptivelySample2Facet(   v0  , midpt0, midpt2, maxDepth, move | 2 );
+    this->AdaptivelySample2Facet( midpt0,   v1  , midpt1, maxDepth, move | 4 );
+    this->AdaptivelySample2Facet( midpt2, midpt1,   v2  , maxDepth, move | 1 );
+    break;
+    }
+}
+
+void Refiner::AdaptivelySample3Facet( double* v0, double* v1, double* v2, double* v3, int maxDepth ) const
+{
+  int edgeCode = 0;
+
+  double midpt0[11+Refiner::MaxFieldSize];
+  double midpt1[11+Refiner::MaxFieldSize];
+  double midpt2[11+Refiner::MaxFieldSize];
+  double midpt3[11+Refiner::MaxFieldSize];
+  double midpt4[11+Refiner::MaxFieldSize];
+  double midpt5[11+Refiner::MaxFieldSize];
+#ifdef ALLOW_TET_INTERIOR_PT
+  double midpt6[11+Refiner::MaxFieldSize];
+#endif // ALLOW_TET_INTERIOR_PT
+  double facept0[11+Refiner::MaxFieldSize];
+  double facept1[11+Refiner::MaxFieldSize];
+  double facept2[11+Refiner::MaxFieldSize];
+  double facept3[11+Refiner::MaxFieldSize];
+
+  // Make valgrind happy
+  std::fill(midpt0,midpt0+this->PointDimension[3],0.);
+  std::fill(midpt1,midpt1+this->PointDimension[3],0.);
+  std::fill(midpt2,midpt2+this->PointDimension[3],0.);
+  std::fill(midpt3,midpt3+this->PointDimension[3],0.);
+  std::fill(midpt4,midpt4+this->PointDimension[3],0.);
+  std::fill(midpt5,midpt5+this->PointDimension[3],0.);
+#ifdef ALLOW_TET_INTERIOR_PT
+  std::fill(midpt6,midpt6+this->PointDimension[3],0.);
+#endif // ALLOW_TET_INTERIOR_PT
+
+  double edgeLength2[6];
+  if ( maxDepth-- > 0 )
+    {
+    for ( int i=0; i<this->PointDimension[3]; i++ )
+      {
+      midpt0[i] = (v0[i] + v1[i])/2.;
+      midpt1[i] = (v1[i] + v2[i])/2.;
+      midpt2[i] = (v2[i] + v0[i])/2.;
+      midpt3[i] = (v0[i] + v3[i])/2.;
+      midpt4[i] = (v1[i] + v3[i])/2.;
+      midpt5[i] = (v2[i] + v3[i])/2.;
+#ifdef ALLOW_TET_INTERIOR_PT
+      midpt6[i] = (v1[i]+v2[i]-2*v0[i])/4. + (v3[i]-v0[i])/3. + v0[i];
+#endif // ALLOW_TET_INTERIOR_PT
+      }
+
+    if ( Algorithm->EvaluateEdge( v0, midpt0, v1, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |=  1;
+    if ( Algorithm->EvaluateEdge( v1, midpt1, v2, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |=  2;
+    if ( Algorithm->EvaluateEdge( v2, midpt2, v0, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |=  4;
+
+    if ( Algorithm->EvaluateEdge( v0, midpt3, v3, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |=  8;
+    if ( Algorithm->EvaluateEdge( v1, midpt4, v3, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |= 16;
+    if ( Algorithm->EvaluateEdge( v2, midpt5, v3, 3+this->EmbeddingDimension[3] ) )
+      edgeCode |= 32;
+
+    edgeLength2[0] = edgeLength2[1] = edgeLength2[2] = edgeLength2[3]
+      = edgeLength2[4] = edgeLength2[5] = 0;
+    for ( int c=0; c<3; ++c )
+      {
+      double tmp;
+      tmp = v1[c] - v0[c];
+      edgeLength2[0] += tmp*tmp;
+      tmp = v2[c] - v1[c];
+      edgeLength2[1] += tmp*tmp;
+      tmp = v2[c] - v0[c];
+      edgeLength2[2] += tmp*tmp;
+      tmp = v3[c] - v0[c];
+      edgeLength2[3] += tmp*tmp;
+      tmp = v3[c] - v1[c];
+      edgeLength2[4] += tmp*tmp;
+      tmp = v3[c] - v2[c];
+      edgeLength2[5] += tmp*tmp;
+      }
+
+#ifdef ALLOW_TET_INTERIOR_PT
+    // Find the longest/shortest edges
+    double shortest = edgeLength2[0];
+    double longest = edgeLength2[0];
+    for ( int e=1; e<6; e++ )
+      {
+      if ( edgeLength2[e] < shortest )
+        shortest = edgeLength2[e];
+      if ( edgeLength2[e] > longest )
+        longest = edgeLength2[e];
+      }
+    // Divide at center if aspect ratio is > 4:1 (remember these are squares of edge lengths):
+    if ( shortest / longest < 1./16. )
+      edgeCode |= 64;
+#if 0
+    // Dunno if we need to have the subdivision algorithm evaluate it, but I suspect
+    // it wouldn't be a bad idea.
+    if ( Algorithm->EvaluatePoint( midpt6 ) )
+      edgeCode |= 64;
+#endif // 0
+#endif // ALLOW_TET_INTERIOR_PT
+    }
+
+  if ( edgeCode == 0 )
+    {
+    // No edges to subdivide
+    Callback3( v0, v1, v2, v3, this->Algorithm, this->PrivateData, this->ConstPrivateData );
+    }
+  else
+    {
+    // Do the subdivision
+#ifdef ALLOW_TET_INTERIOR_PT
+    double* vertices[11] =
+    {
+      v0, v1, v2, v3,     midpt0, midpt1, midpt2, midpt3, midpt4, midpt5, midpt6
+    };
+#else // ALLOW_TET_INTERIOR_PT
+    double* vertices[10] =
+    {
+      v0, v1, v2, v3,     midpt0, midpt1, midpt2, midpt3, midpt4, midpt5
+    };
+#endif // ALLOW_TET_INTERIOR_PT
+
+    // Generate tetrahedra that are compatible except when edge
+    // lengths are equal on indeterminately subdivided faces.
+    double* permuted[14];
+    double permlen[6]; // permuted edge lengths
+    int C = Refiner::EdgeCodesToCaseCodesPlusPermutation[ edgeCode ][0];
+    int P = Refiner::EdgeCodesToCaseCodesPlusPermutation[ edgeCode ][1];
+    int i;
+
+    // 1. Permute the tetrahedron into our canonical configuration
+    for ( i=0; i<4; ++i )
+      {
+      permuted[i] = vertices[ Refiner::PermutationsFromIndex[P][i] ];
+      }
+    for ( i=4; i<10; ++i )
+      {
+      // permute the edge lengths, too
+      permuted[i] = vertices[ Refiner::PermutationsFromIndex[P][i] ];
+      permlen[i-4]  = edgeLength2[ Refiner::PermutationsFromIndex[P][i] - 4 ];
+      }
+    // Add our local (heap) storage for face points to the list.
+    permuted[10] = facept0;
+    permuted[11] = facept1;
+    permuted[12] = facept2;
+    permuted[13] = facept3;
+
+    int comparisonBits;
+    std::stack<vtkIdType*> outputTets;
+    std::stack<vtkIdType*> outputPerm;
+    std::stack<int>        outputSign;
+
+    // cout << "Case " << C << "  Permutation " << P << endl;
+    // 2. Generate tetrahedra based on the configuration.
+    //    Note that case 0 is handled above (edgeCode == 0).
+    switch (C)
+      {
+
+    case 1: // Ruprecht-Müller Case 1
+      VTK_TESSELLATOR_INCR_CASE_COUNT(0);
+      outputTets.push( Refiner::TetrahedralDecompositions + 0 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(0,0);
+      break;
+    case 2: // Ruprecht-Müller Case 2a
+      comparisonBits = 
+        (permlen[0] <= permlen[1] ? 1 : 0) | (permlen[0] >= permlen[1] ? 2 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[0][i] + permuted[2][i])*0.375 + permuted[1][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(1);
+      outputTets.push( Refiner::TetrahedralDecompositions + 9 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,0);
+      switch (comparisonBits)
+        {
+        case 2: // 0>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 14 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,1);
+          break;
+        case 1: // 1>0
+          outputTets.push( Refiner::TetrahedralDecompositions + 14 );
+          outputPerm.push( Refiner::PermutationsFromIndex[13] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,2);
+          break;
+        case 3: // 0=1
+          outputTets.push( Refiner::TetrahedralDecompositions + 23 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(1,3);
+          break;
+        }
+      break;
+    case 3: // Ruprecht-Müller Case 2b
+      VTK_TESSELLATOR_INCR_CASE_COUNT(2);
+      outputTets.push( Refiner::TetrahedralDecompositions + 40 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(2,0);
+      break;
+    case 4: // Ruprecht-Müller Case 3a
+      comparisonBits = 
+        (permlen[0] <= permlen[3] ? 1 : 0) | (permlen[0] >= permlen[3] ? 2 : 0) |
+        (permlen[2] <= permlen[3] ? 4 : 0) | (permlen[2] >= permlen[3] ? 8 : 0) |
+        (permlen[0] <= permlen[2] ? 16 : 0) | (permlen[0] >= permlen[2] ? 32 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[1][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[13][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 48) == 48 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(3);
+      outputTets.push( Refiner::TetrahedralDecompositions + 57 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,0);
+      switch (comparisonBits)
+        {
+        case 42: // 0>2>3<0
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,1);
+          break;
+        case 25: // 2>3>0<2
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[11] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,2);
+          break;
+        case 37: // 3>0>2<3
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[3] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,3);
+          break;
+        case 21: // 3>2>0<3
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[22] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,4);
+          break;
+        case 26: // 2>0>3<2
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[12] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,5);
+          break;
+        case 38: // 0>3>2<0
+          outputTets.push( Refiner::TetrahedralDecompositions + 62 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,6);
+          break;
+        case 58: // 0=2>3<0
+          outputTets.push( Refiner::TetrahedralDecompositions + 75 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,7);
+          break;
+        case 29: // 2=3>0<2
+          outputTets.push( Refiner::TetrahedralDecompositions + 75 );
+          outputPerm.push( Refiner::PermutationsFromIndex[11] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,8);
+          break;
+        case 39: // 0=3>2<0
+          outputTets.push( Refiner::TetrahedralDecompositions + 75 );
+          outputPerm.push( Refiner::PermutationsFromIndex[3] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,9);
+          break;
+        case 53: // 3>0=2<3
+          outputTets.push( Refiner::TetrahedralDecompositions + 96 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,10);
+          break;
+        case 46: // 0>2=3<0
+          outputTets.push( Refiner::TetrahedralDecompositions + 96 );
+          outputPerm.push( Refiner::PermutationsFromIndex[11] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,11);
+          break;
+        case 27: // 2>0=3<2
+          outputTets.push( Refiner::TetrahedralDecompositions + 96 );
+          outputPerm.push( Refiner::PermutationsFromIndex[3] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,12);
+          break;
+        case 63: // 0=2=3=0
+          outputTets.push( Refiner::TetrahedralDecompositions + 117 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(3,13);
+          break;
+        }
+      break;
+    case 5: // Ruprecht-Müller Case 3b
+      VTK_TESSELLATOR_INCR_CASE_COUNT(4);
+      outputTets.push( Refiner::TetrahedralDecompositions + 162 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(4,0);
+      break;
+    case 6: // Ruprecht-Müller Case 3c
+      comparisonBits = 
+        (permlen[0] <= permlen[1] ? 1 : 0) | (permlen[0] >= permlen[1] ? 2 : 0) |
+        (permlen[0] <= permlen[3] ? 4 : 0) | (permlen[0] >= permlen[3] ? 8 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[0][i] + permuted[2][i])*0.375 + permuted[1][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[1][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(5);
+      switch (comparisonBits)
+        {
+        case 10: // 0>1,0>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 179 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,0);
+          break;
+        case 5: // 1>0,3>0
+          outputTets.push( Refiner::TetrahedralDecompositions + 200 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,1);
+          break;
+        case 6: // 0>1,3>0
+          outputTets.push( Refiner::TetrahedralDecompositions + 221 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,2);
+          break;
+        case 9: // 1>0,0>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 242 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,3);
+          break;
+        case 11: // 0=1,0>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 263 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,4);
+          break;
+        case 14: // 0=3,0>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 263 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,5);
+          break;
+        case 7: // 3>0,0=1
+          outputTets.push( Refiner::TetrahedralDecompositions + 292 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,6);
+          break;
+        case 13: // 1>0,0=3
+          outputTets.push( Refiner::TetrahedralDecompositions + 292 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,7);
+          break;
+        case 15: // 0=1,0=3
+          outputTets.push( Refiner::TetrahedralDecompositions + 321 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(5,8);
+          break;
+        }
+      break;
+    case 7: // Ruprecht-Müller Case 3d
+      comparisonBits = 
+        (permlen[0] <= permlen[2] ? 1 : 0) | (permlen[0] >= permlen[2] ? 2 : 0) |
+        (permlen[0] <= permlen[4] ? 4 : 0) | (permlen[0] >= permlen[4] ? 8 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[0][i] + permuted[3][i])*0.375 + permuted[1][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(6);
+      switch (comparisonBits)
+        {
+        case 10: // 0>4,0>2
+          outputTets.push( Refiner::TetrahedralDecompositions + 362 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,0);
+          break;
+        case 5: // 4>0,2>0
+          outputTets.push( Refiner::TetrahedralDecompositions + 383 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,1);
+          break;
+        case 9: // 0>4,2>0
+          outputTets.push( Refiner::TetrahedralDecompositions + 404 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,2);
+          break;
+        case 6: // 4>0,0>2
+          outputTets.push( Refiner::TetrahedralDecompositions + 425 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,3);
+          break;
+        case 14: // 0=4,0>2
+          outputTets.push( Refiner::TetrahedralDecompositions + 446 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,4);
+          break;
+        case 11: // 0=2,0>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 446 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,5);
+          break;
+        case 13: // 2>0,0=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 475 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,6);
+          break;
+        case 7: // 4>0,0=2
+          outputTets.push( Refiner::TetrahedralDecompositions + 475 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,7);
+          break;
+        case 15: // 0=4,0=2
+          outputTets.push( Refiner::TetrahedralDecompositions + 504 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(6,8);
+          break;
+        }
+      break;
+    case 8: // Ruprecht-Müller Case 4a
+      comparisonBits = 
+        (permlen[4] <= permlen[5] ? 1 : 0) | (permlen[4] >= permlen[5] ? 2 : 0) |
+        (permlen[3] <= permlen[4] ? 4 : 0) | (permlen[3] >= permlen[4] ? 8 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[12][i] = (permuted[1][i] + permuted[2][i])*0.375 + permuted[3][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(7);
+      outputTets.push( Refiner::TetrahedralDecompositions + 545 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,0);
+      switch (comparisonBits)
+        {
+        case 5: // 5>4>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 554 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,1);
+          break;
+        case 10: // 3>4>5
+          outputTets.push( Refiner::TetrahedralDecompositions + 554 );
+          outputPerm.push( Refiner::PermutationsFromIndex[13] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,2);
+          break;
+        case 6: // 3<4>5
+          outputTets.push( Refiner::TetrahedralDecompositions + 571 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,3);
+          break;
+        case 9: // 3>4<5
+          outputTets.push( Refiner::TetrahedralDecompositions + 588 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,4);
+          break;
+        case 14: // 3=4>5
+          outputTets.push( Refiner::TetrahedralDecompositions + 605 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,5);
+          break;
+        case 7: // 4=5,4>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 605 );
+          outputPerm.push( Refiner::PermutationsFromIndex[13] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,6);
+          break;
+        case 13: // 5>4,3=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 630 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,7);
+          break;
+        case 11: // 3>4=5
+          outputTets.push( Refiner::TetrahedralDecompositions + 630 );
+          outputPerm.push( Refiner::PermutationsFromIndex[13] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,8);
+          break;
+        case 15: // 3=4=5
+          outputTets.push( Refiner::TetrahedralDecompositions + 655 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(7,9);
+          break;
+        }
+      break;
+    case 9: // Ruprecht-Müller Case 4b
+      comparisonBits = 
+        (permlen[1] <= permlen[2] ? 1 : 0) | (permlen[1] >= permlen[2] ? 2 : 0) |
+        (permlen[2] <= permlen[3] ? 4 : 0) | (permlen[2] >= permlen[3] ? 8 : 0) |
+        (permlen[3] <= permlen[4] ? 16 : 0) | (permlen[3] >= permlen[4] ? 32 : 0) |
+        (permlen[1] <= permlen[4] ? 64 : 0) | (permlen[1] >= permlen[4] ? 128 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[1][i] + permuted[0][i])*0.375 + permuted[2][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[13][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[0][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 48) == 48 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 192) == 192 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[12][i] = (permuted[2][i] + permuted[3][i])*0.375 + permuted[1][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(8);
+      switch (comparisonBits)
+        {
+        case 85: // 2>1,3>2,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,0);
+          break;
+        case 102: // 1>2,3>2,3>4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,1);
+          break;
+        case 170: // 1>2,2>3,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,2);
+          break;
+        case 153: // 2>1,2>3,4>3,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,3);
+          break;
+        case 90: // 1>2,2>3,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[9] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,4);
+          break;
+        case 105: // 2>1,2>3,3>4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[7] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,5);
+          break;
+        case 165: // 2>1,3>2,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[19] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,6);
+          break;
+        case 150: // 1>2,3>2,4>3,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 688 );
+          outputPerm.push( Refiner::PermutationsFromIndex[23] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,7);
+          break;
+        case 101: // 2>1,3>2,3>4,4>1
+          {
+            int alternates[] = { 713, 738, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,8);
+          break;
+        case 86: // 1>2,3>2,4>3,4>1
+          {
+            int alternates[] = {713, 738, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,9);
+          break;
+        case 154: // 1>2,2>3,4>3,1>4
+          {
+            int alternates[] = {713, 738, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 5, 1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,10);
+          break;
+        case 169: // 2>1,2>3,3>4,1>4
+          {
+            int alternates[] = {713, 738, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 15, -1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,11);
+          break;
+        case 89: // 2>1,2>3,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 763 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,12);
+          break;
+        case 166: // 1>2,3>2,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 763 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,13);
+          break;
+        case 103: // 1=2,3>2,3>4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,14);
+          break;
+        case 87: // 1=2,3>2,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,15);
+          break;
+        case 185: // 2>1,2>3,3=4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,16);
+          break;
+        case 186: // 1>2,2>3,3=4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,17);
+          break;
+        case 158: // 1>2,2=3,4>3,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[9] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,18);
+          break;
+        case 229: // 2>1,3>2,3>4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[7] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,19);
+          break;
+        case 233: // 2>1,2>3,3>4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[19] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,20);
+          break;
+        case 94: // 1>2,2=3,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 788 );
+          outputPerm.push( Refiner::PermutationsFromIndex[23] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,21);
+          break;
+        case 155: // 1=2,2>3,4>3,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,22);
+          break;
+        case 171: // 1=2,2>3,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,23);
+          break;
+        case 118: // 1>2,3>2,3=4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,24);
+          break;
+        case 117: // 2>1,3>2,3=4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,25);
+          break;
+        case 109: // 2>1,2=3,3>4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[9] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,26);
+          break;
+        case 218: // 1>2,2>3,4>3,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[7] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,27);
+          break;
+        case 214: // 1>2,3>2,4>3,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[19] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,28);
+          break;
+        case 173: // 2>1,2=3,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 825 );
+          outputPerm.push( Refiner::PermutationsFromIndex[23] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,29);
+          break;
+        case 91: // 1=2,2>3,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,30);
+          break;
+        case 167: // 1=2,3>2,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,31);
+          break;
+        case 182: // 1>2,3>2,3=4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,32);
+          break;
+        case 121: // 2>1,2>3,3=4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,33);
+          break;
+        case 93: // 2>1,2=3,4>3,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[9] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,34);
+          break;
+        case 217: // 2>1,2>3,4>3,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[7] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,35);
+          break;
+        case 230: // 1>2,3>2,3>4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[19] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,36);
+          break;
+        case 174: // 1>2,2=3,3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 862 );
+          outputPerm.push( Refiner::PermutationsFromIndex[23] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,37);
+          break;
+        case 119: // 1=2,3>2,3=4,4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 899 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,38);
+          break;
+        case 187: // 1=2>3=4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 899 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,39);
+          break;
+        case 222: // 1>2,2=3,4>3,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 899 );
+          outputPerm.push( Refiner::PermutationsFromIndex[9] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,40);
+          break;
+        case 237: // 2>1,2=3,3>4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 899 );
+          outputPerm.push( Refiner::PermutationsFromIndex[7] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,41);
+          break;
+        case 95: // 4>1=2=3,4>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 944 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,42);
+          break;
+        case 231: // 1=2,3>2,3>4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 944 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,43);
+          break;
+        case 190: // 1>2=3=4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 944 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,44);
+          break;
+        case 249: // 2>1,2>3,3=4,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 944 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,45);
+          break;
+        case 175: // 1=2=3>4,1>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 993 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,46);
+          break;
+        case 219: // 1=2>3,4>3,1=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 993 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,47);
+          break;
+        case 125: // 2>1,2=3=4>1
+          outputTets.push( Refiner::TetrahedralDecompositions + 993 );
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,48);
+          break;
+        case 246: // 1>2,3>2,3=4=1
+          outputTets.push( Refiner::TetrahedralDecompositions + 993 );
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,49);
+          break;
+        case 255: // 1=2=3=4=1
+          outputTets.push( Refiner::TetrahedralDecompositions + 1042 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(8,50);
+          break;
+        }
+      break;
+    case 10: // Ruprecht-Müller Case 5
+      comparisonBits = 
+        (permlen[1] <= permlen[2] ? 1 : 0) | (permlen[1] >= permlen[2] ? 2 : 0) |
+        (permlen[3] <= permlen[4] ? 4 : 0) | (permlen[3] >= permlen[4] ? 8 : 0) |
+        0;
+      if ( (comparisonBits & 3) == 3 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[10][i] = (permuted[1][i] + permuted[0][i])*0.375 + permuted[2][i]/4.;
+          }
+        }
+      if ( (comparisonBits & 12) == 12 )
+        {
+        // Compute face point
+        for ( i=0; i<this->PointDimension[3]; i++ )
+          {
+          permuted[11][i] = (permuted[0][i] + permuted[1][i])*0.375 + permuted[3][i]/4.;
+          }
+        }
+      VTK_TESSELLATOR_INCR_CASE_COUNT(9);
+      outputTets.push( Refiner::TetrahedralDecompositions + 1107 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,0);
+      switch (comparisonBits)
+        {
+        case 10: // 1>2,3>4
+          outputTets.push( Refiner::TetrahedralDecompositions + 1116 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,1);
+          break;
+        case 5: // 2>1,4>3
+          outputTets.push( Refiner::TetrahedralDecompositions + 1116 );
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,2);
+          break;
+        case 6: // 1>2,4>3
+          {
+            int alternates[] = { 1137, 1158, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,3);
+          break;
+        case 9: // 2>1,3>4
+          {
+            int alternates[] = {1137, 1158, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,4);
+          break;
+        case 11: // 1=2,3>4
+          {
+            int alternates[] = { 1179, 1212, 1245, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,5);
+          break;
+        case 7: // 1=2,4>3
+          {
+            int alternates[] = {1179, 1212, 1245, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 14, -1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[14] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,6);
+          break;
+        case 14: // 3=4,1>2
+          {
+            int alternates[] = {1179, 1212, 1245, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 5, 1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[5] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,7);
+          break;
+        case 13: // 3=4,2>1
+          {
+            int alternates[] = {1179, 1212, 1245, -1 };
+            outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 15, -1 ) );
+          }
+          outputPerm.push( Refiner::PermutationsFromIndex[15] );
+          outputSign.push( -1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,8);
+          break;
+        case 15: // 1=2,3=4
+          outputTets.push( Refiner::TetrahedralDecompositions + 1278 );
+          outputPerm.push( Refiner::PermutationsFromIndex[0] );
+          outputSign.push( 1 );
+          VTK_TESSELLATOR_INCR_SUBCASE_COUNT(9,9);
+          break;
+        }
+      break;
+    case 11: // Ruprecht-Müller Case 6
+      VTK_TESSELLATOR_INCR_CASE_COUNT(10);
+      outputTets.push( Refiner::TetrahedralDecompositions + 1319 );
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(10,0);
+        {
+        int alternates[] = { 1336, 1353, 1370, -1 };
+        outputTets.push( Refiner::TetrahedralDecompositions + this->BestTets( alternates, permuted, 0, 1 ) );
+        }
+      outputPerm.push( Refiner::PermutationsFromIndex[0] );
+      outputSign.push( 1 );
+      VTK_TESSELLATOR_INCR_SUBCASE_COUNT(10,1);
+      break;
+      }
+
+    vtkIdType* tets;
+    vtkIdType  ntets;
+    vtkIdType* perm;
+    int        sgn;
+#ifdef PARAVIEW_DEBUG_TESSELLATOR
+    if ( outputTets.empty() )
+    {
+    cout << "Argh! Case " << C << " Perm " << P << " has no output!" << endl;
+    }
+#endif // PARAVIEW_DEBUG_TESSELLATOR
+    while ( ! outputTets.empty() )
+      {
+      tets = outputTets.top();
+      ntets = *tets;
+      tets++;
+      perm = outputPerm.top();
+      sgn = outputSign.top();
+
+      outputTets.pop();
+      outputPerm.pop();
+      outputSign.pop();
+
+      int t;
+      if ( sgn > 0 )
+        {
+        for ( t = 0; t < ntets; ++t )
+          {
+          this->AdaptivelySample3Facet(
+            permuted[ perm[ tets[0] ] ], permuted[ perm[ tets[1] ] ],
+            permuted[ perm[ tets[2] ] ], permuted[ perm[ tets[3] ] ],
+            maxDepth );
+          tets += 4;
+          }
+        }
+      else
+        {
+        // we have an inverted tet... reverse the first 2 vertices
+        // so the orientation is positive.
+        for ( t = 0; t < ntets; ++t )
+          {
+          this->AdaptivelySample3Facet(
+            permuted[ perm[ tets[1] ] ], permuted[ perm[ tets[0] ] ],
+            permuted[ perm[ tets[2] ] ], permuted[ perm[ tets[3] ] ],
+            maxDepth );
+          tets += 4;
+          }
+        }
+      }
+    }
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/RefinerTagManager.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBRefinerTagManager.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/RefinerTagManager.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/RefinerTagManager.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,525 @@
+#include "moab/RefinerTagManager.hpp"
+
+#include "moab/Interface.hpp"
+#include "moab/ParallelComm.hpp"
+#include "moab/ParallelConventions.h"
+#include "moab/MBTagConventions.hpp"
+
+#include <iostream>
+#include <stdexcept>
+#include <assert.h>
+
+#undef MB_DEBUG
+
+namespace moab {
+
+/// Construct an evaluator.
+RefinerTagManager::RefinerTagManager( Interface* in_mesh, Interface* out_mesh )
+  : shared_procs_in( 5 * MAX_SHARING_PROCS, -1 ), shared_procs_out( MAX_SHARING_PROCS, -1 )
+{
+  assert( in_mesh );
+  if ( ! out_mesh )
+    out_mesh = in_mesh;
+
+  this->input_mesh = in_mesh;
+  this->output_mesh = out_mesh;
+  this->reset_vertex_tags();
+  this->reset_element_tags();
+  ParallelComm* ipcomm = ParallelComm::get_pcomm( this->input_mesh, 0 );
+  ParallelComm* opcomm = 0;
+  if ( this->output_mesh != this->input_mesh )
+    {
+    opcomm = ParallelComm::get_pcomm( this->output_mesh, 0 );
+    if ( ! opcomm )
+      {
+#ifdef MB_DEBUG
+      std::cout << "Creating opcomm: " << opcomm << "\n";
+#endif // MB_DEBUG
+      opcomm = new ParallelComm( this->output_mesh, MPI_COMM_WORLD );
+      }
+    }
+  else
+    {
+    opcomm = ipcomm;
+    }
+
+  if ( ipcomm )
+    {
+    ipcomm->get_shared_proc_tags(
+      this->tag_ipsproc, this->tag_ipsprocs,
+      this->tag_ipshand, this->tag_ipshands,
+      this->tag_ipstatus );
+    }
+  else
+    {
+    this->tag_ipsproc = this->tag_ipsprocs = 0;
+    this->tag_ipshand = this->tag_ipshands = 0;
+    this->tag_ipstatus = 0;
+    }
+
+  if ( opcomm )
+    {
+    opcomm->get_shared_proc_tags(
+      this->tag_opsproc, this->tag_opsprocs,
+      this->tag_opshand, this->tag_opshands,
+      this->tag_opstatus );
+    }
+  else
+    {
+    this->tag_opsproc = this->tag_opsprocs = 0;
+    this->tag_opshand = this->tag_opshands = 0;
+    this->tag_opstatus = 0;
+    }
+
+  this->rank =
+    ipcomm ? ipcomm->proc_config().proc_rank() :
+    ( opcomm ? opcomm->proc_config().proc_rank() : 0 );
+
+  // Create the mesh global ID tags if they aren't already there.
+  int zero = 0;
+  ErrorCode result;
+  result = this->input_mesh->tag_create(
+    GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, this->tag_igid, &zero, true );
+  if ( result != MB_SUCCESS && result != MB_ALREADY_ALLOCATED )
+    {
+    throw new std::logic_error( "Unable to find input mesh global ID tag \"" GLOBAL_ID_TAG_NAME "\"" );
+    }
+  result = this->output_mesh->tag_create(
+    GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, this->tag_ogid, &zero, true );
+  if ( result != MB_SUCCESS && result != MB_ALREADY_ALLOCATED )
+    {
+    throw new std::logic_error( "Unable to find/create output mesh global ID tag \"" GLOBAL_ID_TAG_NAME "\"" );
+    }
+
+#ifdef MB_DEBUG
+  std::cout
+    << "psproc:  " << this->tag_ipsproc  << ", " << this->tag_opsproc << "\n"
+    << "psprocs: " << this->tag_ipsprocs << ", " << this->tag_opsprocs << "\n"
+    << "pshand:  " << this->tag_ipshand  << ", " << this->tag_opshand << "\n"
+    << "pshands: " << this->tag_ipshands << ", " << this->tag_opshands << "\n"
+    << "pstatus: " << this->tag_ipstatus << ", " << this->tag_opstatus << "\n"
+    << "gid:     " << this->tag_igid     << ", " << this->tag_ogid     << "\n";
+#endif // MB_DEBUG
+}
+
+/// Destruction is virtual so subclasses may clean up after refinement.
+RefinerTagManager::~RefinerTagManager()
+{
+}
+
+/**\fn bool RefinerTagManager::evaluate_edge( \
+  *         const double* p0, const void* t0, double* p1, void* t1, const double* p2, const void* t2 )
+  *\brief Returns true if the edge \a p0 - \a p2 should be subdivided, false otherwise.
+  *
+  * The arguments \a p0, \a p1, and \a p2 are all pointers to arrays of 6 doubles each
+  * while the arguments \a t0, \a t1, and \a t2 are all pointers to arrays of tag data
+  * defined at the corresponding point. While the endpoints \a p0 and \a p2 are
+  * immutable, the mid-edge point coordinates \a p1 and tag data \a t1 may be altered by
+  * evaluate_edge(). Altered values will be ignored if evaluate_edge() returns false.
+  * Be careful to ensure that all calls to evaluate_edge() perform identical modifications
+  * given identical input values!
+  *
+  * A list of tags passed in \a t0, \a t1, and \a t2 is stored in the \a input_vertex_tags member.
+  * (for tag handles defined on the input mesh) and the \a output_vertex_tags (for the same tag handles
+  * defined on the output mesh).
+  * The vertex_size member stores the total length of data associated with each pointer (in bytes).
+  * Subclasses may access input_vertex_tags, output_vertex_tags, and vertex_size directly;
+  * the refiner uses public methods to set them before any entities are evaluated for subdivision.
+  * The output_vertex_tags member is populated when the refiner calls create_output_tags().
+  * When the input mesh and output mesh pointers are identical, this simply copies input_vertex_tags
+  * to output_vertex_tags.
+  * When the pointers are distinct, tags are created on the output mesh.
+  */
+
+/// Clear the list of tag values that will appear past the vertex coordinates in \a p0, \a p1, and \a p2.
+void RefinerTagManager::reset_vertex_tags()
+{
+  this->vertex_size = 0;
+  this->input_vertex_tags.clear();
+  this->output_vertex_tags.clear();
+}
+
+/** Add a tag to the list of tag values that will appear past the vertex coordinates.
+  * The return value is the offset into each vertex coordinate pointer (\a p0, \a p1, \a p2) where the
+  * tag value(s) will be stored.
+  */
+int RefinerTagManager::add_vertex_tag( Tag tag_handle )
+{
+  int offset = this->vertex_size; // old size is offset of tag being added
+  int tag_size;
+  TagType tagType;
+  if ( this->input_mesh->tag_get_size( tag_handle, tag_size ) != MB_SUCCESS )
+    return -1;
+
+  if ( this->input_mesh->tag_get_type( tag_handle, tagType ) != MB_SUCCESS )
+    return -1;
+
+  if ( tagType == MB_TAG_BIT )
+    {
+    // Pad any bit tags to a size in full bytes.
+    tag_size = ( tag_size % 8 ? 1 : 0 ) + ( tag_size / 8 );
+    }
+
+  // Now pad so that the next tag will be word-aligned:
+  while ( tag_size % sizeof(int) )
+    ++tag_size;
+
+  this->vertex_size += tag_size;
+
+  this->input_vertex_tags.push_back( std::pair< Tag, int >( tag_handle, offset ) );
+  return offset;
+}
+
+/**\fn int RefinerTagManager::get_vertex_tag_size()
+  *\brief Return the number of bytes to allocate for tag data per point.
+  */
+
+/**\fn int RefinerTagManager::get_number_of_vertex_tags() const
+  *\brief Return the number of tags that will be output with each new vertex.
+  */
+
+/// Clear the list of tag values that will appear past the element coordinates in \a p0, \a p1, and \a p2.
+void RefinerTagManager::reset_element_tags()
+{
+  this->element_size = 0;
+  this->input_element_tags.clear();
+  this->output_element_tags.clear();
+  this->element_tag_data.clear();
+}
+
+/** Add a tag to the list of tag values that will appear past the element coordinates.
+  * The return value is the offset into each element coordinate pointer (\a p0, \a p1, \a p2) where the
+  * tag value(s) will be stored.
+  */
+int RefinerTagManager::add_element_tag( Tag tag_handle )
+{
+  int offset = this->element_size; // old size is offset of tag being added
+  int tag_size;
+  TagType tagType;
+  if ( this->input_mesh->tag_get_size( tag_handle, tag_size ) != MB_SUCCESS )
+    return -1;
+
+  if ( this->input_mesh->tag_get_type( tag_handle, tagType ) != MB_SUCCESS )
+    return -1;
+
+  if ( tagType == MB_TAG_BIT )
+    {
+    // Pad any bit tags to a size in full bytes.
+    tag_size = ( tag_size % 8 ? 1 : 0 ) + ( tag_size / 8 );
+    }
+
+  // Now pad so that the next tag will be word-aligned:
+  while ( tag_size % sizeof(int) )
+    ++tag_size;
+
+  this->element_size += tag_size;
+  this->element_tag_data.resize( this->element_size );
+
+  this->input_element_tags.push_back( std::pair< Tag, int >( tag_handle, offset ) );
+  return offset;
+}
+
+/**\fn int RefinerTagManager::get_element_tag_size()
+  *\brief Return the number of bytes to allocate for tag data per point.
+  */
+
+/**\fn int RefinerTagManager::get_number_of_element_tags() const
+  *\brief Return the number of tags that will be output with each new element.
+  */
+
+/**\brief Populate the list of output tags to match the list of input tags.
+  *
+  * When the input mesh and output mesh pointers are identical, this simply copies the list of input tags.
+  * When the two meshes are distinct, the corresponding tags are created on the output mesh.
+  */
+void RefinerTagManager::create_output_tags()
+{
+  if ( this->input_mesh == this->output_mesh )
+    {
+    this->output_vertex_tags = this->input_vertex_tags;
+    this->output_element_tags = this->input_element_tags;
+    return;
+    }
+
+  std::vector< std::pair< Tag, int > >::iterator it;
+  for ( it = this->input_vertex_tags.begin(); it != this->input_vertex_tags.end(); ++ it )
+    {
+    this->create_tag_internal( it->first, it->second );
+    }
+}
+
+/**\brief Return the tag handle and its offset in the array of tag data of each vertex.
+  *
+  * @param[in] i An index into the list of tags for the vertex.
+  * @param[out] tag The tag handle on the input mesh for the $i$-th vertex tag.
+  * @param[out] byte_offset The offset (in bytes) of the start of this tag's data in a vertex tag record.
+  */
+void RefinerTagManager::get_input_vertex_tag( int i, Tag& tag, int& byte_offset )
+{
+  std::vector< std::pair< Tag, int > >::iterator it = this->input_vertex_tags.begin() + i;
+  tag = it->first;
+  byte_offset = it->second;
+}
+
+/**\brief Return the tag handle and its offset in the array of tag data of each vertex.
+  *
+  * @param[in] i An index into the list of tags for the vertex.
+  * @param[out] tag The tag handle on the output mesh for the $i$-th vertex tag.
+  * @param[out] byte_offset The offset (in bytes) of the start of this tag's data in a vertex tag record.
+  */
+void RefinerTagManager::get_output_vertex_tag( int i, Tag& tag, int& byte_offset )
+{
+  std::vector< std::pair< Tag, int > >::iterator it = this->output_vertex_tags.begin() + i;
+  tag = it->first;
+  byte_offset = it->second;
+}
+
+/**\brief Retrieve the global ID of each input entity and push it onto the output vector.
+  *
+  * The \a gids array is emptied by this call before any new values are added.
+  * Note that this routine fetches global IDs from the input mesh, not the output mesh;
+  * your entity handles must be from the input mesh.
+  *
+  * @param[in] ents An array of entities in the input mesh whose global IDs you desire
+  * @param[in] n The number of entities in the \a ents array.
+  * @param[out] gids A vector to contain the resulting global IDs.
+  * @retval A MOAB error code as supplied by the Interface::tag_get_data() call.
+  */
+int RefinerTagManager::get_input_gids( int n, const EntityHandle* ents, std::vector<int>& gids )
+{
+  int stat;
+  gids.clear();
+  for ( int i = 0; i < n; ++ i )
+    {
+    int gid = -1;
+    stat |= this->input_mesh->tag_get_data( this->tag_igid, ents + i, 1, &gid );
+    gids.push_back( gid );
+    }
+  return stat;
+}
+
+/**\brief Retrieve the global ID of each output entity and push it onto the output vector.
+  *
+  * The \a gids array is emptied by this call before any new values are added.
+  * Note that this routine fetches global IDs from the output mesh, not the input mesh;
+  * your entity handles must be from the output mesh.
+  * Also, be aware that many output entities will not have global IDs assigned;
+  * only those vertices which exist in the input mesh are guaranteed to have global IDs
+  * assigned to them -- vertices that only exist in the output mesh and all higher-dimensional
+  * output entities have no global IDs assigned until after a complete subdivision pass has been made.
+  *
+  * @param[in] ents An array of entities in the output mesh whose global IDs you desire
+  * @param[in] n The number of entities in the \a ents array.
+  * @param[out] gids A vector to contain the resulting global IDs.
+  * @retval A MOAB error code as supplied by the Interface::tag_get_data() call.
+  */
+int RefinerTagManager::get_output_gids( int n, const EntityHandle* ents, std::vector<int>& gids )
+{
+  int stat;
+  gids.clear();
+  for ( int i = 0; i < n; ++ i )
+    {
+    int gid = -1;
+    stat |= this->output_mesh->tag_get_data( this->tag_igid, ents + i, 1, &gid );
+    gids.push_back( gid );
+    }
+  return stat;
+}
+
+/**\brief Assign a global ID to an output entity.
+  *
+  * @param[in] ent The entity whose ID will be set
+  * @param[out] id The global ID
+  * @retval An error code as returned by Interface::tag_set_data().
+  */
+int RefinerTagManager::set_gid( EntityHandle ent, int gid )
+{
+  return this->output_mesh->tag_set_data( this->tag_ogid, &ent, 1, &gid );
+}
+
+/**\brief Copy a global ID from an entity of the input mesh to an entity of the output mesh.
+  *
+  * @param[in] ent_input An entity on the input mesh with a global ID.
+  * @param[in] ent_output An entity on the output mesh whose global ID should be set.
+  * @retval               Normally MB_SUCCESS, but returns other values if tag_get_data or tag_set_data fail.
+  */
+int RefinerTagManager::copy_gid( EntityHandle ent_input, EntityHandle ent_output )
+{
+  int gid = -1;
+  int status;
+  if ( ( status =  this->input_mesh->tag_get_data( this->tag_igid, &ent_input, 1, &gid ) ) == MB_SUCCESS )
+    {
+    status = this->output_mesh->tag_set_data( this->tag_ogid, &ent_output, 1, &gid );
+    }
+  return status;
+}
+
+/**\brief Set parallel status and sharing process list on an entity.
+  *
+  * This sets tag values for the PARALLEL_STATUS and one of PARALLEL_SHARED_PROC or PARALLEL_SHARED_PROCS tags
+  * if \a procs contains any processes (the current process is assumed <b>not</b> to be set in \a procs).
+  *
+  * @param[in] ent_handle The entity whose information will be set
+  * @param[in] procs The set of sharing processes.
+  */
+void RefinerTagManager::set_sharing( EntityHandle ent_handle, ProcessSet& procs )
+{
+  int pstat;
+  if ( procs.get_process_members( this->rank, this->shared_procs_out ) )
+    pstat = PSTATUS_SHARED | PSTATUS_INTERFACE;
+  else
+    pstat = PSTATUS_SHARED | PSTATUS_INTERFACE | PSTATUS_NOT_OWNED;
+  if ( this->shared_procs_out[0] >= 0 )
+    {
+    // assert( MAX_SHARING_PROCS > 1 );
+    // Since get_process_members pads to MAX_SHARING_PROCS, this will be work:
+    if ( this->shared_procs_out[1] <= 0 )
+      {
+      //std::cout << "  (proc )";
+      this->output_mesh->tag_set_data( this->tag_opsproc, &ent_handle, 1, &this->shared_procs_out[0] );
+      this->output_mesh->tag_set_data( this->tag_opstatus, &ent_handle, 1, &pstat );
+      }
+    else
+      {
+      //std::cout << "  (procS)";
+      this->output_mesh->tag_set_data( this->tag_opsprocs, &ent_handle, 1, &this->shared_procs_out[0] );
+      this->output_mesh->tag_set_data( this->tag_opstatus, &ent_handle, 1, &pstat );
+      }
+    }
+  else
+    {
+    //std::cout << "  (none )";
+    }
+  //std::cout << " new pstat: " << pstat << "\n";
+}
+
+/**\brief Determine the subset of processes which all share the specified entities.
+  *
+  * This is used to determine which processes an output entity should reside on when
+  * it is defined using several input entities (such as vertices).
+  */
+void RefinerTagManager::get_common_processes(
+  int num, const EntityHandle* src, ProcessSet& common_shared_procs, bool on_output_mesh )
+{
+  Interface* mesh;
+  Tag psproc;
+  Tag psprocs;
+  if ( on_output_mesh )
+    {
+    mesh = this->output_mesh;
+    psproc = this->tag_opsproc;
+    psprocs = this->tag_opsprocs;
+    }
+  else
+    {
+    mesh = this->input_mesh;
+    psproc = this->tag_ipsproc;
+    psprocs = this->tag_ipsprocs;
+    }
+  bool first_ent = true;
+  common_shared_procs.clear();
+  for ( int i = 0; i < num; ++ i )
+    {
+    EntityHandle ent_in = src[i];
+    //std::cout << "<(" << ent_in << ")>";
+    int stat;
+    bool got = false;
+    this->current_shared_procs.clear();
+    stat = mesh->tag_get_data( psproc, &ent_in, 1, &this->shared_procs_in[0] );
+    if ( stat == MB_SUCCESS && this->shared_procs_in[0] != -1 )
+      {
+      got = true;
+      //std::cout << " s" << this->rank << " s" << this->shared_procs_in[0] << " | ";
+      this->shared_procs_in[1] = -1;
+      }
+    stat = mesh->tag_get_data( psprocs, &ent_in, 1, &this->shared_procs_in[0] );
+    if ( stat == MB_SUCCESS && this->shared_procs_in[0] != -1 )
+      {
+      got = true;
+      int i;
+      /*
+      for ( i = 0; i < MAX_SHARING_PROCS && this->shared_procs_in[i] != -1; ++ i )
+        std::cout << " m" << this->shared_procs_in[i];
+      std::cout << " | ";
+      */
+      }
+    if ( got )
+      {
+      this->current_shared_procs.set_process_members( this->shared_procs_in );
+      this->current_shared_procs.set_process_member( this->rank );
+      if ( first_ent )
+        {
+        common_shared_procs.unite( this->current_shared_procs );
+        first_ent = false;
+        }
+      else
+        {
+        common_shared_procs.intersect( this->current_shared_procs );
+        }
+      }
+    else
+      {
+      // not shared, but everthing exists on this process, so make sure that bit is set...
+      common_shared_procs.set_process_member( this->rank );
+      }
+    }
+#ifdef MB_DEBUG
+  std::cout << "    Common procs " << common_shared_procs;
+  std::cout << "\n";
+#endif // MB_DEBUG
+}
+
+void RefinerTagManager::create_tag_internal( Tag tag_in, int offset )
+{
+  std::pair< Tag, int > tag_rec;
+  std::vector< char > tag_default;
+  std::string tag_name;
+  TagType tag_type;
+  DataType tag_data_type;
+  int tag_size;
+
+  tag_rec.second = offset;
+  this->input_mesh->tag_get_name( tag_in, tag_name );
+  this->input_mesh->tag_get_size( tag_in, tag_size );
+  this->input_mesh->tag_get_type( tag_in, tag_type );
+  this->input_mesh->tag_get_data_type( tag_in, tag_data_type );
+  this->input_mesh->tag_get_default_value( tag_in, (void*) &tag_default[0] );
+  tag_default.resize( tag_size );
+  ErrorCode res = this->output_mesh->tag_create(
+    tag_name.c_str(), tag_size, tag_type, tag_data_type, tag_rec.first, (void*) &tag_default[0], true );
+#ifdef MB_DEBUG
+  std::cout
+    << "Creating output tag: \"" << tag_name.c_str() << "\" handle: " << tag_rec.first
+    << " input handle: " << tag_in << "\n";
+#endif // MB_DEBUG
+  if ( res == MB_FAILURE )
+    {
+    std::cerr
+      << "Could not create output tag name: \"" << tag_name.c_str() << "\" type: "
+      << tag_type << " data type: " << tag_data_type << "\n";
+    }
+  else
+    {
+    this->output_vertex_tags.push_back( tag_rec );
+    }
+}
+
+void RefinerTagManager::set_element_tags_from_ent( EntityHandle ent_input )
+{
+  std::vector< std::pair< Tag, int > >::iterator it;
+  for ( it = this->input_element_tags.begin(); it != this->input_element_tags.end(); ++ it )
+    {
+    this->input_mesh->tag_get_data( it->first, &ent_input, 1, &this->element_tag_data[it->second] );
+    }
+}
+
+void RefinerTagManager::assign_element_tags( EntityHandle ent_output )
+{
+  std::vector< std::pair< Tag, int > >::iterator it;
+  for ( it = this->output_element_tags.begin(); it != this->output_element_tags.end(); ++ it )
+    {
+    this->output_mesh->tag_set_data( it->first, &ent_output, 1, &this->element_tag_data[it->second] );
+    }
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/RefinerTagManager.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBRefinerTagManager.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/RefinerTagManager.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/RefinerTagManager.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,127 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2004 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class RefinerTagManager
+  *
+  * This a class that manages which tags an edge refiner should include
+  * on output vertices created during mesh refinement.
+  * The 
+  *
+  * \author David Thompson
+  *
+  * \date 12 June 2008
+  */
+#ifndef MOAB_REFINER_TAG_MANAGER_HPP
+#define MOAB_REFINER_TAG_MANAGER_HPP
+
+#include "moab/Types.h" // for MB_DLL_EXPORT
+
+#include "moab/ProcessSet.hpp"
+
+#include <vector>
+
+namespace moab {
+
+class Interface;
+
+class MB_DLL_EXPORT RefinerTagManager
+{
+public:
+  RefinerTagManager( Interface* in_mesh, Interface* out_mesh );
+  virtual ~RefinerTagManager();
+
+  void reset_vertex_tags();
+  int add_vertex_tag( Tag tag_handle );
+  int get_vertex_tag_size() const { return this->vertex_size; }
+  int get_number_of_vertex_tags() const { return this->input_vertex_tags.size(); }
+
+  void reset_element_tags();
+  int add_element_tag( Tag tag_handle );
+  int get_element_tag_size() const { return this->element_size; }
+  int get_number_of_element_tags() const { return this->input_element_tags.size(); }
+
+  void create_output_tags();
+
+  void get_input_vertex_tag( int i, Tag& tag, int& byte_offset );
+  void get_output_vertex_tag( int i, Tag& tag, int& byte_offset );
+
+  void get_input_element_tag( int i, Tag& tag, int& byte_offset );
+  void get_output_element_tag( int i, Tag& tag, int& byte_offset );
+
+  Interface* get_input_mesh() { return this->input_mesh; }
+  Interface* get_output_mesh() { return this->output_mesh; }
+
+  Tag input_parallel_status() { return this->tag_ipstatus; }
+  Tag input_shared_proc() { return this->tag_ipsproc; }
+  Tag input_shared_procs() { return this->tag_ipsprocs; }
+
+  int get_input_gids( int n, const EntityHandle* ents, std::vector<int>& gids );
+  int get_output_gids( int n, const EntityHandle* ents, std::vector<int>& gids );
+  int set_gid( EntityHandle ent, int gid );
+  int copy_gid( EntityHandle ent_input, EntityHandle ent_output );
+
+  void set_sharing( EntityHandle ent_handle, ProcessSet& procs );
+  void get_common_processes( int num, const EntityHandle* src, ProcessSet& common_shared_procs, bool on_output_mesh = true );
+
+  void set_element_tags_from_ent( EntityHandle ent_input );
+  void assign_element_tags( EntityHandle ent_output );
+
+  void set_element_procs_from_ent( EntityHandle ent_input )
+    {
+    this->get_common_processes( 1, &ent_input, this->current_element_procs, false );
+    }
+  ProcessSet& get_element_procs()
+    {
+    return this->current_element_procs;
+    }
+  void set_element_sharing( EntityHandle ent_output )
+    {
+    this->set_sharing( ent_output, this->current_element_procs );
+    }
+
+protected:
+  void create_tag_internal( Tag, int );
+
+  std::vector< std::pair< Tag, int > > input_vertex_tags;
+  std::vector< std::pair< Tag, int > > output_vertex_tags;
+  std::vector< std::pair< Tag, int > > input_element_tags;
+  std::vector< std::pair< Tag, int > > output_element_tags;
+  int vertex_size;
+  int element_size;
+  Interface* input_mesh;
+  Interface* output_mesh;
+  Tag tag_ipstatus; // Handle for PARALLEL_STATUS on mesh_in
+  Tag tag_ipsprocs; // Handle for PARALLEL_SHARED_PROCS on mesh_in
+  Tag tag_ipsproc;  // Handle for PARALLEL_SHARED_PROC on mesh_in
+  Tag tag_ipshands; // Handle for PARALLEL_SHARED_HANDLES on mesh_in
+  Tag tag_ipshand;  // Handle for PARALLEL_SHARED_HANDLE on mesh_in
+  Tag tag_igid;     // Handle for global IDs on mesh_in
+  Tag tag_opstatus; // Handle for PARALLEL_STATUS on mesh_out
+  Tag tag_opsprocs; // Handle for PARALLEL_SHARED_PROCS on mesh_out
+  Tag tag_opsproc;  // Handle for PARALLEL_SHARED_PROC on mesh_out
+  Tag tag_opshands; // Handle for PARALLEL_SHARED_HANDLES on mesh_out
+  Tag tag_opshand;  // Handle for PARALLEL_SHARED_HANDLE on mesh_out
+  Tag tag_ogid;     // Handle for global IDs on mesh_out
+  int rank;
+  std::vector<int> shared_procs_in; // Used to hold procs sharing an input vert.
+  std::vector<int> shared_procs_out; // Used to hold procs sharing an output entity.
+  ProcessSet current_shared_procs; // Holds process list as it is being accumulated
+  ProcessSet current_element_procs; // The list of processes which should share an output element.
+  std::vector<char> element_tag_data; // Holds tag data for per-element tags
+};
+
+} // namespace moab
+
+#endif // MOAB_REFINER_TAG_MANAGER_HPP

Copied: MOAB/trunk/tools/refiner/SimplexTemplateRefiner.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/SimplexTemplateRefiner.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SimplexTemplateRefiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,2325 @@
+#include "moab/SimplexTemplateRefiner.hpp"
+
+#include "moab/EdgeSizeEvaluator.hpp"
+#include "moab/RefinerTagManager.hpp"
+
+#include "moab/Interface.hpp"
+
+#include <iostream>
+#include <stack>
+
+// Static arrays holding parametric coordinates of element vertices
+static double MBVertexParametric[] = { 0., 0., 0. };
+static double MBEdgeParametric[]   = { 0., 0., 0.,   1., 0., 0. };
+static double MBTriParametric[]    = { 0., 0., 0.,   1., 0., 0.,   0., 1., 0. };
+static double MBTetParametric[]    = { 0., 0., 0.,   1., 0., 0.,   0., 1., 0.,   0., 0., 1. };
+
+#ifdef MB_DEBUG_TESSELLATOR
+#  define MB_TESSELLATOR_INCR_CASE_COUNT(cs) this->case_counts[cs]++
+#  define MB_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc) this->subcase_counts[cs][sc]++
+#else // MB_DEBUG_TESSELLATOR
+#  define MB_TESSELLATOR_INCR_CASE_COUNT(cs)
+#  define MB_TESSELLATOR_INCR_SUBCASE_COUNT(cs,sc)
+#endif // MB_DEBUG_TESSELLATOR
+
+namespace moab {
+
+/// Construct a template refiner.
+SimplexTemplateRefiner::SimplexTemplateRefiner()
+{
+  this->tag_manager = 0;
+  this->tag_assigner = new SimplexTemplateTagAssigner( this );
+  this->corner_coords.resize( 6 * 8 ); // Hex has 8 verts w/ 6 coordinates each
+  this->corner_tags.resize( 8 ); // Hex has 8 verts (this is a pointer, not the actual tag data)
+  this->corner_handles.resize( 8 ); // Hex has 8 verts (this is a pointer, not actual hash data)
+  this->input_is_output = false; // Until we know better
+}
+
+/// Empty destructor for good form.
+SimplexTemplateRefiner::~SimplexTemplateRefiner()
+{
+  delete this->tag_assigner;
+}
+
+/**\brief Stream a single mesh entity through the refiner.
+  */
+bool SimplexTemplateRefiner::refine_entity( EntityType etyp, EntityHandle entity )
+{
+  this->reset_heap_pointers();
+  bool rval = true;
+  const EntityHandle* conn;
+  int num_nodes;
+  Interface* imesh = this->tag_manager->get_input_mesh();
+  if ( imesh->get_connectivity( entity, conn, num_nodes ) != MB_SUCCESS )
+    {
+    return false;
+    }
+  this->corner_coords.resize( 6 * num_nodes );
+  this->corner_tags.resize( num_nodes );
+  this->corner_handles.resize( num_nodes );
+
+  // Have to make num_nodes calls to get_coords() because we need xyz interleaved with rst coords.
+  Tag tag_handle;
+  int tag_offset;
+  void* tag_data;
+  for ( int n = 0; n < num_nodes; ++ n )
+    {
+    if ( imesh->get_coords( &conn[n], 1, &corner_coords[6 * n + 3] ) != MB_SUCCESS )
+      {
+      return false;
+      }
+    tag_data = this->heap_tag_storage();
+    for ( int i = 0; i < this->tag_manager->get_number_of_vertex_tags(); ++ i )
+      {
+      this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
+      if ( imesh->tag_get_data( tag_handle, &conn[n], 1, (char*)tag_data + tag_offset ) != MB_SUCCESS )
+        {
+        return false;
+        }
+      }
+    if ( this->input_is_output )
+      {
+      this->corner_handles[n] = conn[n];
+      }
+    else
+      {
+      this->corner_handles[n] = this->output_functor->map_vertex( conn[n], &corner_coords[6 * n], tag_data );
+#if 0
+      std::cout << "#+# " << this->corner_handles[n] << " < "
+        << corner_coords[ 6 * n + 3 ] << ", "
+        << corner_coords[ 6 * n + 4 ] << ", "
+        << corner_coords[ 6 * n + 5 ] << ">\n";
+#endif // 0
+      }
+    this->corner_tags[n] = tag_data;
+    }
+
+  switch ( etyp )
+    {
+    case MBVERTEX:
+      this->assign_parametric_coordinates( 1, MBVertexParametric, &this->corner_coords[0] );
+      this->refine_0_simplex( &this->corner_coords[0], this->corner_tags[0], this->corner_handles[0] );
+      rval = false;
+      break;
+    case MBEDGE:
+      this->assign_parametric_coordinates( 2, MBEdgeParametric, &this->corner_coords[0] );
+      rval = this->refine_1_simplex( this->maximum_number_of_subdivisions,
+        &this->corner_coords[0], this->corner_tags[0], this->corner_handles[0],
+        &this->corner_coords[6], this->corner_tags[1], this->corner_handles[1] );
+      break;
+    case MBTRI:
+      this->assign_parametric_coordinates( 3, MBTriParametric, &this->corner_coords[0] );
+      rval = this->refine_2_simplex( this->maximum_number_of_subdivisions, 7,
+        &this->corner_coords[ 0], this->corner_tags[0], this->corner_handles[0],
+        &this->corner_coords[ 6], this->corner_tags[1], this->corner_handles[1],
+        &this->corner_coords[12], this->corner_tags[2], this->corner_handles[2] );
+      break;
+    case MBQUAD:
+      std::cerr << "Quadrilaterals not handled yet\n";
+      rval = false;
+      break;
+    case MBPOLYGON:
+      std::cerr << "Polygons not handled yet\n";
+      rval = false;
+      break;
+    case MBTET:
+      this->assign_parametric_coordinates( 4, MBTetParametric, &this->corner_coords[0] );
+      rval = this->refine_3_simplex( this->maximum_number_of_subdivisions,
+        &this->corner_coords[ 0], this->corner_tags[0], this->corner_handles[0],
+        &this->corner_coords[ 6], this->corner_tags[1], this->corner_handles[1],
+        &this->corner_coords[12], this->corner_tags[2], this->corner_handles[2],
+        &this->corner_coords[18], this->corner_tags[3], this->corner_handles[3]
+      );
+      break;
+    case MBPYRAMID:
+      std::cerr << "Pyramid schemes not handled yet\n";
+      rval = false;
+      break;
+    case MBPRISM:
+      std::cerr << "Prisms not handled yet\n";
+      rval = false;
+      break;
+    case MBKNIFE:
+      std::cerr << "Knifahedra not handled yet\n";
+      rval = false;
+      break;
+    case MBHEX:
+      std::cerr << "Hexahedra not handled yet\n";
+      rval = false;
+      break;
+    case MBPOLYHEDRON:
+      std::cerr << "Polyhedra not handled yet\n";
+      rval = false;
+      break;
+    case MBENTITYSET:
+      std::cerr <<
+        "How should entity sets be handled? We might iterate over its entries or skip it."
+        "Must coordinate with MeshRefiner's loop over entities...\n";
+      rval = false;
+      break;
+    case MBMAXTYPE:
+      rval = false;
+      break;
+    }
+  return rval;
+}
+
+/**\brief Set the function object used to decide which tag values an edge or face midpoint is assigned.
+  *
+  * This will change the tag assigner's edge size evaluator to match the refiner's.
+  * @param[in] ta The new tag assigner. This must be non-NULL.
+  * @retval True if the tag assigner was changed and false otherwise.
+  */
+bool SimplexTemplateRefiner::set_tag_assigner( SimplexTemplateTagAssigner* ta )
+{ 
+  if ( ! ta || ta == this->tag_assigner )
+    return false;
+
+  this->tag_assigner = ta; 
+  return true;
+}
+
+
+/**\brief Set the function object used to decide whether an edge is subdivided or not.
+  */
+bool SimplexTemplateRefiner::prepare( RefinerTagManager* tmgr, EntityRefinerOutputFunctor* ofunc )
+{ 
+  this->tag_manager = tmgr;
+  this->tag_assigner->set_tag_manager( tmgr );
+  this->input_is_output = ( this->tag_manager->get_input_mesh() == this->tag_manager->get_output_mesh() );
+  //this->tag_assigner->set_edge_size_evaluator( this->edge_size_evaluator );
+  return this->EntityRefiner::prepare( tmgr, ofunc );
+}
+
+/**\fn unsigned long SimplexTemplateRefiner::get_heap_size_bound( int max_recursions ) const
+  *\brief Bound on the number of new vertices used to allocate the heap.
+  *
+  * This bound is based on a hexahedron that is divided into 48 tetrahedra (a point is added to
+  * the center of each face so that compatible boundaries are guaranteed on neighboring hexahedra),
+  * each of which has 4 edges.
+  */
+
+/**\brief "Refine" a vertex by passing it through to the output.
+  *
+  * FIXME: There is some question as to whether this should pass vertices through
+  * since there does not appear to be a distinction between vertices as points
+  * in space and vertices as degrees-of-freedom in a mesh (i.e. a vertex that is
+  * treated as a lumped-parameter model).
+  */
+void SimplexTemplateRefiner::refine_0_simplex( const double* v0, const void* t0, EntityHandle h0 )
+{
+  // Ignore these arguments... the caller is responsible for calling the output functor to ensure the
+  // vertex exists on the output.
+  (void) v0;
+  (void) t0;
+
+  (*this->output_functor)( h0 );
+  (*this->output_functor)( MBVERTEX );
+}
+
+/**\brief Refine an edge.
+  */
+bool SimplexTemplateRefiner::refine_1_simplex(
+  int max_depth,
+  const double* v0, const void* t0, EntityHandle h0,
+  const double* v1, const void* t1, EntityHandle h1 )
+{
+  bool edge_code = false;
+
+  double* midptc;
+  void* midptt;
+  // NB: If support for multiple recursive subdivisions (without a merge in between) is required,
+  //     this will have to change as it assumes that h0 and h1 have only a single entry.
+  EntityHandle midpth = 0;
+
+  if ( max_depth-- > 0 )
+    {
+    midptc = this->heap_coord_storage();
+    midptt = this->heap_tag_storage();
+    int i;
+    // make valgrind happy
+    //vtkstd::fill( midpt0, midpt0 + 6, 0. );
+    for ( i = 0; i < 6; i++ )
+      midptc[i] = ( v0[i] + v1[i] ) / 2.;
+
+    (*this->tag_assigner)( v0, t0, h0, midptc, midptt, v1, t1, h1 );
+    edge_code = this->edge_size_evaluator->evaluate_edge( v0, t0, midptc, midptt, v1, t1 );
+    if ( edge_code )
+      {
+      midpth = (*this->output_functor)( h0, h1, midptc, midptt );
+      }
+    }
+
+  switch ( edge_code )
+    {
+    // No edges to subdivide
+  case 0:
+    (*this->output_functor)( h0 );
+    (*this->output_functor)( h1 );
+    (*this->output_functor)( MBEDGE );
+    break ;
+
+    // One edge to subdivide
+  case 1:
+    this->refine_1_simplex( max_depth, v0, t0, h0, midptc, midptt, midpth );
+    this->refine_1_simplex( max_depth, midptc, midptt, midpth, v1, t1, h1 );
+    break;
+    }
+
+  return edge_code;
+}
+
+/**\brief Refine a triangle.
+  */
+bool SimplexTemplateRefiner::refine_2_simplex(
+  int max_depth, int move,
+  const double* v0, const void* t0, EntityHandle h0,
+  const double* v1, const void* t1, EntityHandle h1,
+  const double* v2, const void* t2, EntityHandle h2 )
+{
+  int edge_code = 0;
+
+  double* midpt0c;
+  double* midpt1c;
+  double* midpt2c;
+  void* midpt0t;
+  void* midpt1t;
+  void* midpt2t;
+  EntityHandle midpt0h;
+  EntityHandle midpt1h;
+  EntityHandle midpt2h;
+
+  if ( max_depth-- > 0 )
+    {
+    int i;
+    midpt0c = this->heap_coord_storage();
+    midpt1c = this->heap_coord_storage();
+    midpt2c = this->heap_coord_storage();
+    midpt0t = this->heap_tag_storage();
+    midpt1t = this->heap_tag_storage();
+    midpt2t = this->heap_tag_storage();
+    midpt0h = 0;
+    midpt1h = 0;
+    midpt2h = 0;
+    for ( i = 0; i < 6; ++i )
+      {
+      midpt0c[i] = ( v0[i] + v1[i] ) / 2.;
+      midpt1c[i] = ( v1[i] + v2[i] ) / 2.;
+      midpt2c[i] = ( v2[i] + v0[i] ) / 2.;
+      }
+    (*this->tag_assigner)( v0, t0, h0, midpt0c, midpt0t, v1, t1, h1 );
+    (*this->tag_assigner)( v1, t1, h1, midpt1c, midpt1t, v2, t2, h2 );
+    (*this->tag_assigner)( v2, t2, h2, midpt2c, midpt2t, v0, t0, h0 );
+    if ( ( move & 1 ) && this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
+      {
+      edge_code += 1;
+      midpt0h = (*this->output_functor)( h0, h1, midpt0c, midpt0t );
+      }
+    if ( ( move & 2 ) && this->edge_size_evaluator->evaluate_edge( v1, t1, midpt1c, midpt1t, v2, t2 ) )
+      {
+      edge_code += 2;
+      midpt1h = (*this->output_functor)( h1, h2, midpt1c, midpt1t );
+      }
+    if ( ( move & 4 ) && this->edge_size_evaluator->evaluate_edge( v2, t2, midpt2c, midpt2t, v0, t0 ) )
+      {
+      edge_code += 4;
+      midpt2h = (*this->output_functor)( h2, h0, midpt2c, midpt2t );
+      }
+    }
+
+  switch ( edge_code )
+    {
+    // No edges to subdivide
+  case 0:
+    (*this->output_functor)( h0 );
+    (*this->output_functor)( h1 );
+    (*this->output_functor)( h2 );
+    (*this->output_functor)( MBTRI );
+    break ;
+
+    // One edge to subdivide
+  case 1:
+    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0,  midpt0c, midpt0t, midpt0h, v2, t2, h2 );
+    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h, v1, t1, h1,  v2, t2, h2 );
+    break;
+  case 2:
+    this->refine_2_simplex( max_depth, move | 4, v0, t0, h0, v1, t1, h1, midpt1c, midpt1t, midpt1h );
+    this->refine_2_simplex( max_depth, move | 1, v0, t0, h0, midpt1c, midpt1t, midpt1h, v2, t2, h2 );
+    break;
+  case 4:
+    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0, v1, t1, h1, midpt2c, midpt2t, midpt2h );
+    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, v1, t1, h1, v2, t2, h2 );
+    break;
+
+    // Two edges to subdivide
+  case 3:
+    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h, v1, t1, h1, midpt1c, midpt1t, midpt1h );
+    if ( this->compare_Hopf_cross_string_dist( v2, midpt0c, v0, midpt1c ) )
+      {
+      this->refine_2_simplex( max_depth, move | 5, midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h,   v2,      t2,      h2   );
+      this->refine_2_simplex( max_depth, move | 2,   v0,      t0,      h0,    midpt0c, midpt0t, midpt0h,   v2,      t2,      h2   );
+      }
+    else                                         
+      {
+      this->refine_2_simplex( max_depth, move | 6,   v0,      t0,      h0,   midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h );
+      this->refine_2_simplex( max_depth, move | 1,   v0,      t0,      h0,   midpt1c, midpt1t, midpt1h,   v2,      t2,      h2    );
+      }
+    break;
+  case 5:
+    this->refine_2_simplex( max_depth, move | 2, v0, t0, h0, midpt0c, midpt0t, midpt0h, midpt2c, midpt2t, midpt2h );
+    if ( this->compare_Hopf_cross_string_dist( v2, midpt0c, v1, midpt2c ) )
+      {
+      this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h,   v1,      t1,      h1,       v2,      t2,    h2   );
+      this->refine_2_simplex( max_depth, move | 3, midpt2c, midpt2t, midpt2h, midpt0c, midpt0t, midpt0h,    v2,      t2,    h2   );
+      }
+    else
+      {
+      this->refine_2_simplex( max_depth, move | 6, midpt0c, midpt0t, midpt0h,   v1,      t1,      h1,   midpt2c, midpt2t, midpt2h );
+      this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h,   v1,      t1,      h1,      v2,      t2,     h2   );
+      }
+    break;
+  case 6:
+    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, midpt1c, midpt1t, midpt1h, v2, t2, h2 );
+    if ( this->compare_Hopf_cross_string_dist( v0, midpt1c, v1, midpt2c ) )
+      {
+      this->refine_2_simplex( max_depth, move | 3,   v0,      t0,     h0,    midpt1c, midpt1t, midpt1h, midpt2c, midpt2t, midpt2h );
+      this->refine_2_simplex( max_depth, move | 4,   v0,      t0,     h0,      v1,      t1,      h1,    midpt1c, midpt1t, midpt1h );
+      }
+    else
+      {
+      this->refine_2_simplex( max_depth, move | 2,   v0,      t0,      h0,      v1,      t1,     h1,    midpt2c, midpt2t, midpt2h );
+      this->refine_2_simplex( max_depth, move | 5, midpt2c, midpt2t, midpt2h,   v1,      t1,     h1,    midpt1c, midpt1t, midpt1h );
+      }
+    break;
+
+    // Three edges to subdivide
+  case 7:
+    this->refine_2_simplex( max_depth,        7, midpt0c, midpt0t, midpt0h, midpt1c, midpt1t, midpt1h, midpt2c, midpt2t, midpt2h );
+    this->refine_2_simplex( max_depth, move | 2,   v0   ,   t0   ,   h0   , midpt0c, midpt0t, midpt0h, midpt2c, midpt2t, midpt2h );
+    this->refine_2_simplex( max_depth, move | 4, midpt0c, midpt0t, midpt0h,   v1   ,   t1   ,   h1   , midpt1c, midpt1t, midpt1h );
+    this->refine_2_simplex( max_depth, move | 1, midpt2c, midpt2t, midpt2h, midpt1c, midpt1t, midpt1h,   v2   ,   t2   ,   h2    );
+    break;
+    }
+
+  return true;
+}
+
+/**\brief Refine a tetrahedron.
+  */
+bool SimplexTemplateRefiner::refine_3_simplex(
+  int max_depth,
+  double* v0, void* t0, EntityHandle h0,
+  double* v1, void* t1, EntityHandle h1,
+  double* v2, void* t2, EntityHandle h2,
+  double* v3, void* t3, EntityHandle h3 )
+{
+  int edge_code = 0;
+
+  double* midpt0c;
+  double* midpt1c;
+  double* midpt2c;
+  double* midpt3c;
+  double* midpt4c;
+  double* midpt5c;
+
+  void* midpt0t;
+  void* midpt1t;
+  void* midpt2t;
+  void* midpt3t;
+  void* midpt4t;
+  void* midpt5t;
+
+  EntityHandle midpt0h;
+  EntityHandle midpt1h;
+  EntityHandle midpt2h;
+  EntityHandle midpt3h;
+  EntityHandle midpt4h;
+  EntityHandle midpt5h;
+
+  if ( max_depth-- > 0 )
+    {
+    midpt0c = this->heap_coord_storage();
+    midpt1c = this->heap_coord_storage();
+    midpt2c = this->heap_coord_storage();
+    midpt3c = this->heap_coord_storage();
+    midpt4c = this->heap_coord_storage();
+    midpt5c = this->heap_coord_storage();
+
+    midpt0t = this->heap_tag_storage();
+    midpt1t = this->heap_tag_storage();
+    midpt2t = this->heap_tag_storage();
+    midpt3t = this->heap_tag_storage();
+    midpt4t = this->heap_tag_storage();
+    midpt5t = this->heap_tag_storage();
+
+    for ( int i = 0; i < 6; ++ i )
+      {
+      midpt0c[i] = ( v0[i] + v1[i] ) * .5;
+      midpt1c[i] = ( v1[i] + v2[i] ) * .5;
+      midpt2c[i] = ( v2[i] + v0[i] ) * .5;
+      midpt3c[i] = ( v0[i] + v3[i] ) * .5;
+      midpt4c[i] = ( v1[i] + v3[i] ) * .5;
+      midpt5c[i] = ( v2[i] + v3[i] ) * .5;
+      }
+
+    (*this->tag_assigner)( v0, t0, h0, midpt0c, midpt0t, v1, t1, h1 );
+    (*this->tag_assigner)( v1, t1, h1, midpt1c, midpt1t, v2, t2, h2 );
+    (*this->tag_assigner)( v2, t2, h2, midpt2c, midpt2t, v0, t0, h0 );
+    (*this->tag_assigner)( v0, t0, h0, midpt3c, midpt3t, v3, t3, h3 );
+    (*this->tag_assigner)( v1, t1, h1, midpt4c, midpt4t, v3, t3, h3 );
+    (*this->tag_assigner)( v2, t2, h2, midpt5c, midpt5t, v3, t3, h3 );
+
+    if ( this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
+      {
+      edge_code |=  1;
+      midpt0h = (*this->output_functor)( h0, h1, midpt0c, midpt0t );
+      }
+    if ( this->edge_size_evaluator->evaluate_edge( v1, t1, midpt1c, midpt1t, v2, t2 ) )
+      {
+      edge_code |=  2;
+      midpt1h = (*this->output_functor)( h1, h2, midpt1c, midpt1t );
+      }
+    if ( this->edge_size_evaluator->evaluate_edge( v2, t2, midpt2c, midpt2t, v0, t0 ) )
+      {
+      edge_code |=  4;
+      midpt2h = (*this->output_functor)( h2, h0, midpt2c, midpt2t );
+      }
+    if ( this->edge_size_evaluator->evaluate_edge( v0, t0, midpt3c, midpt3t, v3, t3 ) )
+      {
+      edge_code |=  8;
+      midpt3h = (*this->output_functor)( h0, h3, midpt3c, midpt3t );
+      }
+    if ( this->edge_size_evaluator->evaluate_edge( v1, t1, midpt4c, midpt4t, v3, t3 ) )
+      {
+      edge_code |= 16;
+      midpt4h = (*this->output_functor)( h1, h3, midpt4c, midpt4t );
+      }
+    if ( this->edge_size_evaluator->evaluate_edge( v2, t2, midpt5c, midpt5t, v3, t3 ) )
+      {
+      edge_code |= 32;
+      midpt5h = (*this->output_functor)( h2, h3, midpt5c, midpt5t );
+      }
+    }
+
+  double edge_length2[6];
+  for ( int ei = 0; ei < 6; ++ ei )
+    edge_length2[ei] = 0.;
+
+  for ( int c = 0; c < 3; ++ c )
+    {
+    double tmp;
+    tmp = v1[c] - v0[c];
+    edge_length2[0] += tmp * tmp;
+    tmp = v2[c] - v1[c];
+    edge_length2[1] += tmp * tmp;
+    tmp = v2[c] - v0[c];
+    edge_length2[2] += tmp * tmp;
+    tmp = v3[c] - v0[c];
+    edge_length2[3] += tmp * tmp;
+    tmp = v3[c] - v1[c];
+    edge_length2[4] += tmp * tmp;
+    tmp = v3[c] - v2[c];
+    edge_length2[5] += tmp * tmp;
+    }
+
+  if ( ! edge_code )
+    {
+    // No edges to subdivide
+    (*this->output_functor)( h0 );
+    (*this->output_functor)( h1 );
+    (*this->output_functor)( h2 );
+    (*this->output_functor)( h3 );
+    (*this->output_functor)( MBTET );
+
+    return false;
+    }
+
+  double* facept0c;
+  double* facept1c;
+  double* facept2c;
+  double* facept3c;
+  facept0c = this->heap_coord_storage();
+  facept1c = this->heap_coord_storage();
+  facept2c = this->heap_coord_storage();
+  facept3c = this->heap_coord_storage();
+  double* vertex_coords[14] = {
+    v0, v1, v2, v3, 
+    midpt0c, midpt1c, midpt2c, 
+    midpt3c, midpt4c, midpt5c,
+    facept0c, facept1c, facept2c, facept3c
+  };
+
+  void* facept0t = this->heap_tag_storage();
+  void* facept1t = this->heap_tag_storage();
+  void* facept2t = this->heap_tag_storage();
+  void* facept3t = this->heap_tag_storage();
+  void* vertex_tags[14] = {
+    t0, t1, t2, t3, 
+    midpt0t, midpt1t, midpt2t, 
+    midpt3t, midpt4t, midpt5t,
+    facept0t, facept1t, facept2t, facept3t
+  };
+
+  EntityHandle vertex_hash[14] = {
+    h0, h1, h2, h3,
+    midpt0h, midpt1h, midpt2h,
+    midpt3h, midpt4h, midpt5h,
+    0, 0, 0, 0
+  };
+
+  // Generate tetrahedra that are compatible except when edge
+  // lengths are equal on indeterminately subdivided faces.
+  double* permuted_coords[14];
+  void* permuted_tags[14];
+  EntityHandle permuted_hash[14];
+  double permlen[6]; // permuted edge lengths
+  int C = SimplexTemplateRefiner::template_index[edge_code][0];
+  int P = SimplexTemplateRefiner::template_index[edge_code][1];
+  
+  // 1. Permute the tetrahedron into our canonical configuration
+  for ( int i = 0; i < 14; ++ i )
+    {
+    permuted_coords[i] = vertex_coords[SimplexTemplateRefiner::permutations_from_index[P][i]];
+    permuted_tags[i] = vertex_tags[SimplexTemplateRefiner::permutations_from_index[P][i]];
+    permuted_hash[i] = vertex_hash[SimplexTemplateRefiner::permutations_from_index[P][i]];
+    }
+
+  for ( int i = 4 ; i < 10; ++ i )
+    {
+    // permute edge lengths too
+    permlen[i-4]  = edge_length2[SimplexTemplateRefiner::permutations_from_index[P][i] - 4];
+    }
+
+  int comparison_bits;
+  std::stack<int*> output_tets;
+  std::stack<int*> output_perm;
+  std::stack<int>  output_sign;
+
+  // cout << "Case " << C << "  Permutation " << P << endl;
+  // 2. Generate tetrahedra based on the configuration.
+  //    Note that case 0 is handled above (edgeCode == 0).
+  
+  switch ( C )
+    {
+    case 1: // Ruprecht-Müller Case 1
+      MB_TESSELLATOR_INCR_CASE_COUNT(0);
+      output_tets.push( SimplexTemplateRefiner::templates + 0 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(0,0);
+      break;
+    case 2: // Ruprecht-Müller Case 2a
+      comparison_bits = 
+        ( permlen[0] <= permlen[1] ? 1 : 0 ) | ( permlen[0] >= permlen[1] ? 2 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[0][i] + permuted_coords[2][i] ) * .375 + permuted_coords[1][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[2], permuted_tags[1], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[2], permuted_hash[1], permuted_coords[10], permuted_tags[10] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(1);
+      output_tets.push( SimplexTemplateRefiner::templates + 9 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,0);
+      switch ( comparison_bits )
+        {
+        case 2: // 0>1
+          output_tets.push( SimplexTemplateRefiner::templates + 14 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,1);
+          break;
+        case 1: // 1>0
+          output_tets.push( SimplexTemplateRefiner::templates + 14 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[13] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,2);
+          break;
+        case 3: // 0=1
+          output_tets.push( SimplexTemplateRefiner::templates + 23 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(1,3);
+          break;
+        }
+      break;
+    case 3: // Ruprecht-Müller Case 2b
+      MB_TESSELLATOR_INCR_CASE_COUNT(2);
+      output_tets.push( SimplexTemplateRefiner::templates + 40 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(2,0);
+      break;
+    case 4: // Ruprecht-Müller Case 3a
+      comparison_bits = 
+        ( permlen[0] <= permlen[3] ? 1 : 0 ) | ( permlen[0] >= permlen[3] ? 2 : 0 ) |
+        ( permlen[2] <= permlen[3] ? 4 : 0 ) | ( permlen[2] >= permlen[3] ? 8 : 0 ) |
+        ( permlen[0] <= permlen[2] ? 16 : 0 ) | ( permlen[0] >= permlen[2] ? 32 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[1][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[3], permuted_tags[0], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[3], permuted_hash[0], permuted_coords[11], permuted_tags[11] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[13][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[0], permuted_tags[13] );
+        permuted_hash[13] = (*this->output_functor)(
+          permuted_hash[2], permuted_hash[3], permuted_hash[0], permuted_coords[13], permuted_tags[13] );
+        }
+      if ( ( comparison_bits & 48 ) == 48 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[0], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[2], permuted_hash[0], permuted_coords[10] , permuted_tags[10] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(3);
+      output_tets.push( SimplexTemplateRefiner::templates + 57 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,0);
+      switch ( comparison_bits )
+        {
+        case 42: // 0>2>3<0
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,1);
+          break;
+        case 25: // 2>3>0<2
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[11] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,2);
+          break;
+        case 37: // 3>0>2<3
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[3] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,3);
+          break;
+        case 21: // 3>2>0<3
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[22] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,4);
+          break;
+        case 26: // 2>0>3<2
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[12] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,5);
+          break;
+        case 38: // 0>3>2<0
+          output_tets.push( SimplexTemplateRefiner::templates + 62 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,6);
+          break;
+        case 58: // 0=2>3<0
+          output_tets.push( SimplexTemplateRefiner::templates + 75 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,7);
+          break;
+        case 29: // 2=3>0<2
+          output_tets.push( SimplexTemplateRefiner::templates + 75 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[11] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,8);
+          break;
+        case 39: // 0=3>2<0
+          output_tets.push( SimplexTemplateRefiner::templates + 75 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[3] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,9);
+          break;
+        case 53: // 3>0=2<3
+          output_tets.push( SimplexTemplateRefiner::templates + 96 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,10);
+          break;
+        case 46: // 0>2=3<0
+          output_tets.push( SimplexTemplateRefiner::templates + 96 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[11] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,11);
+          break;
+        case 27: // 2>0=3<2
+          output_tets.push( SimplexTemplateRefiner::templates + 96 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[3] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,12);
+          break;
+        case 63: // 0=2=3=0
+          output_tets.push( SimplexTemplateRefiner::templates + 117 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(3,13);
+          break;
+        }
+      break;
+    case 5: // Ruprecht-Müller Case 3b
+      MB_TESSELLATOR_INCR_CASE_COUNT(4);
+      output_tets.push( SimplexTemplateRefiner::templates + 162 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(4,0);
+      break;
+    case 6: // Ruprecht-Müller Case 3c
+      comparison_bits = 
+        ( permlen[0] <= permlen[1] ? 1 : 0 ) | ( permlen[0] >= permlen[1] ? 2 : 0 ) |
+        ( permlen[0] <= permlen[3] ? 4 : 0 ) | ( permlen[0] >= permlen[3] ? 8 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[0][i] + permuted_coords[2][i] ) * .375 + permuted_coords[1][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[2], permuted_tags[1], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[2], permuted_hash[1], permuted_coords[10], permuted_tags[10] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[1][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[3], permuted_tags[0], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[3], permuted_hash[0], permuted_coords[11], permuted_tags[11] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(5);
+      switch ( comparison_bits )
+        {
+        case 10: // 0>1,0>3
+          output_tets.push( SimplexTemplateRefiner::templates + 179 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,0);
+          break;
+        case 5: // 1>0,3>0
+          output_tets.push( SimplexTemplateRefiner::templates + 200 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,1);
+          break;
+        case 6: // 0>1,3>0
+          output_tets.push( SimplexTemplateRefiner::templates + 221 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,2);
+          break;
+        case 9: // 1>0,0>3
+          output_tets.push( SimplexTemplateRefiner::templates + 242 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,3);
+          break;
+        case 11: // 0=1,0>3
+          output_tets.push( SimplexTemplateRefiner::templates + 263 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,4);
+          break;
+        case 14: // 0=3,0>1
+          output_tets.push( SimplexTemplateRefiner::templates + 263 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,5);
+          break;
+        case 7: // 3>0,0=1
+          output_tets.push( SimplexTemplateRefiner::templates + 292 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,6);
+          break;
+        case 13: // 1>0,0=3
+          output_tets.push( SimplexTemplateRefiner::templates + 292 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,7);
+          break;
+        case 15: // 0=1,0=3
+          output_tets.push( SimplexTemplateRefiner::templates + 321 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(5,8);
+          break;
+        }
+      break;
+    case 7: // Ruprecht-Müller Case 3d
+      comparison_bits = 
+        ( permlen[0] <= permlen[2] ? 1 : 0 ) | ( permlen[0] >= permlen[2] ? 2 : 0 ) |
+        ( permlen[0] <= permlen[4] ? 4 : 0 ) | ( permlen[0] >= permlen[4] ? 8 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[0], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[2], permuted_hash[0], permuted_coords[10], permuted_tags[10] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[3][i] ) * .375 + permuted_coords[1][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[3], permuted_tags[1], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[3], permuted_hash[1], permuted_coords[11], permuted_tags[11] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(6);
+      switch ( comparison_bits )
+        {
+        case 10: // 0>4,0>2
+          output_tets.push( SimplexTemplateRefiner::templates + 362 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,0);
+          break;
+        case 5: // 4>0,2>0
+          output_tets.push( SimplexTemplateRefiner::templates + 383 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,1);
+          break;
+        case 9: // 0>4,2>0
+          output_tets.push( SimplexTemplateRefiner::templates + 404 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,2);
+          break;
+        case 6: // 4>0,0>2
+          output_tets.push( SimplexTemplateRefiner::templates + 425 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,3);
+          break;
+        case 14: // 0=4,0>2
+          output_tets.push( SimplexTemplateRefiner::templates + 446 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,4);
+          break;
+        case 11: // 0=2,0>4
+          output_tets.push( SimplexTemplateRefiner::templates + 446 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,5);
+          break;
+        case 13: // 2>0,0=4
+          output_tets.push( SimplexTemplateRefiner::templates + 475 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,6);
+          break;
+        case 7: // 4>0,0=2
+          output_tets.push( SimplexTemplateRefiner::templates + 475 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,7);
+          break;
+        case 15: // 0=4,0=2
+          output_tets.push( SimplexTemplateRefiner::templates + 504 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(6,8);
+          break;
+        }
+      break;
+    case 8: // Ruprecht-Müller Case 4a
+      comparison_bits = 
+        ( permlen[4] <= permlen[5] ? 1 : 0 ) | ( permlen[4] >= permlen[5] ? 2 : 0 ) |
+        ( permlen[3] <= permlen[4] ? 4 : 0 ) | ( permlen[3] >= permlen[4] ? 8 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[12][i] = ( permuted_coords[1][i] + permuted_coords[2][i] ) * .375 + permuted_coords[3][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[2], permuted_tags[3], permuted_tags[12] );
+        permuted_hash[12] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[2], permuted_hash[3], permuted_coords[12], permuted_tags[12] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(7);
+      output_tets.push( SimplexTemplateRefiner::templates + 545 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,0);
+      switch ( comparison_bits )
+        {
+        case 5: // 5>4>3
+          output_tets.push( SimplexTemplateRefiner::templates + 554 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,1);
+          break;
+        case 10: // 3>4>5
+          output_tets.push( SimplexTemplateRefiner::templates + 554 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[13] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,2);
+          break;
+        case 6: // 3<4>5
+          output_tets.push( SimplexTemplateRefiner::templates + 571 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,3);
+          break;
+        case 9: // 3>4<5
+          output_tets.push( SimplexTemplateRefiner::templates + 588 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,4);
+          break;
+        case 14: // 3=4>5
+          output_tets.push( SimplexTemplateRefiner::templates + 605 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,5);
+          break;
+        case 7: // 4=5,4>3
+          output_tets.push( SimplexTemplateRefiner::templates + 605 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[13] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,6);
+          break;
+        case 13: // 5>4,3=4
+          output_tets.push( SimplexTemplateRefiner::templates + 630 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,7);
+          break;
+        case 11: // 3>4=5
+          output_tets.push( SimplexTemplateRefiner::templates + 630 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[13] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,8);
+          break;
+        case 15: // 3=4=5
+          output_tets.push( SimplexTemplateRefiner::templates + 655 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(7,9);
+          break;
+        }
+      break;
+    case 9: // Ruprecht-Müller Case 4b
+      comparison_bits = 
+        ( permlen[1] <= permlen[2] ? 1 : 0 ) | ( permlen[1] >= permlen[2] ? 2 : 0 ) |
+        ( permlen[2] <= permlen[3] ? 4 : 0 ) | ( permlen[2] >= permlen[3] ? 8 : 0 ) |
+        ( permlen[3] <= permlen[4] ? 16 : 0 ) | ( permlen[3] >= permlen[4] ? 32 : 0 ) |
+        ( permlen[1] <= permlen[4] ? 64 : 0 ) | ( permlen[1] >= permlen[4] ? 128 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[0][i] ) * .375 + permuted_coords[2][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[0], permuted_tags[2], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[0], permuted_hash[2], permuted_coords[10], permuted_tags[10] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[13][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[0][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[0], permuted_tags[13] );
+        permuted_hash[13] = (*this->output_functor)(
+          permuted_hash[2], permuted_hash[3], permuted_hash[0], permuted_coords[13], permuted_tags[13] );
+        }
+      if ( ( comparison_bits & 48 ) == 48 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
+        }
+      if ( ( comparison_bits & 192 ) == 192 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[12][i] = ( permuted_coords[2][i] + permuted_coords[3][i] ) * .375 + permuted_coords[1][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[2], permuted_tags[3], permuted_tags[1], permuted_tags[12] );
+        permuted_hash[12] = (*this->output_functor)(
+          permuted_hash[2], permuted_hash[3], permuted_hash[1], permuted_coords[12], permuted_tags[12] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(8);
+      switch ( comparison_bits )
+        {
+        case 85: // 2>1,3>2,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,0);
+          break;
+        case 102: // 1>2,3>2,3>4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,1);
+          break;
+        case 170: // 1>2,2>3,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,2);
+          break;
+        case 153: // 2>1,2>3,4>3,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,3);
+          break;
+        case 90: // 1>2,2>3,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[9] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,4);
+          break;
+        case 105: // 2>1,2>3,3>4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[7] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,5);
+          break;
+        case 165: // 2>1,3>2,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[19] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,6);
+          break;
+        case 150: // 1>2,3>2,4>3,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 688 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[23] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,7);
+          break;
+        case 101: // 2>1,3>2,3>4,4>1
+          {
+          int alternates[] = { 713, 738, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,8);
+          break;
+        case 86: // 1>2,3>2,4>3,4>1
+          {
+          int alternates[] = {713, 738, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,9);
+          break;
+        case 154: // 1>2,2>3,4>3,1>4
+          {
+          int alternates[] = {713, 738, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 5, 1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,10);
+          break;
+        case 169: // 2>1,2>3,3>4,1>4
+          {
+          int alternates[] = {713, 738, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 15, -1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,11);
+          break;
+        case 89: // 2>1,2>3,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 763 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,12);
+          break;
+        case 166: // 1>2,3>2,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 763 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,13);
+          break;
+        case 103: // 1=2,3>2,3>4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,14);
+          break;
+        case 87: // 1=2,3>2,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,15);
+          break;
+        case 185: // 2>1,2>3,3=4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,16);
+          break;
+        case 186: // 1>2,2>3,3=4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,17);
+          break;
+        case 158: // 1>2,2=3,4>3,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[9] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,18);
+          break;
+        case 229: // 2>1,3>2,3>4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[7] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,19);
+          break;
+        case 233: // 2>1,2>3,3>4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[19] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,20);
+          break;
+        case 94: // 1>2,2=3,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 788 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[23] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,21);
+          break;
+        case 155: // 1=2,2>3,4>3,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,22);
+          break;
+        case 171: // 1=2,2>3,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,23);
+          break;
+        case 118: // 1>2,3>2,3=4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,24);
+          break;
+        case 117: // 2>1,3>2,3=4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,25);
+          break;
+        case 109: // 2>1,2=3,3>4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[9] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,26);
+          break;
+        case 218: // 1>2,2>3,4>3,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[7] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,27);
+          break;
+        case 214: // 1>2,3>2,4>3,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[19] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,28);
+          break;
+        case 173: // 2>1,2=3,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 825 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[23] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,29);
+          break;
+        case 91: // 1=2,2>3,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,30);
+          break;
+        case 167: // 1=2,3>2,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,31);
+          break;
+        case 182: // 1>2,3>2,3=4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,32);
+          break;
+        case 121: // 2>1,2>3,3=4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,33);
+          break;
+        case 93: // 2>1,2=3,4>3,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[9] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,34);
+          break;
+        case 217: // 2>1,2>3,4>3,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[7] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,35);
+          break;
+        case 230: // 1>2,3>2,3>4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[19] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,36);
+          break;
+        case 174: // 1>2,2=3,3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 862 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[23] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,37);
+          break;
+        case 119: // 1=2,3>2,3=4,4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 899 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,38);
+          break;
+        case 187: // 1=2>3=4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 899 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,39);
+          break;
+        case 222: // 1>2,2=3,4>3,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 899 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[9] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,40);
+          break;
+        case 237: // 2>1,2=3,3>4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 899 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[7] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,41);
+          break;
+        case 95: // 4>1=2=3,4>3
+          output_tets.push( SimplexTemplateRefiner::templates + 944 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,42);
+          break;
+        case 231: // 1=2,3>2,3>4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 944 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,43);
+          break;
+        case 190: // 1>2=3=4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 944 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,44);
+          break;
+        case 249: // 2>1,2>3,3=4,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 944 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,45);
+          break;
+        case 175: // 1=2=3>4,1>4
+          output_tets.push( SimplexTemplateRefiner::templates + 993 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,46);
+          break;
+        case 219: // 1=2>3,4>3,1=4
+          output_tets.push( SimplexTemplateRefiner::templates + 993 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,47);
+          break;
+        case 125: // 2>1,2=3=4>1
+          output_tets.push( SimplexTemplateRefiner::templates + 993 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,48);
+          break;
+        case 246: // 1>2,3>2,3=4=1
+          output_tets.push( SimplexTemplateRefiner::templates + 993 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,49);
+          break;
+        case 255: // 1=2=3=4=1
+          output_tets.push( SimplexTemplateRefiner::templates + 1042 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(8,50);
+          break;
+        }
+      break;
+    case 10: // Ruprecht-Müller Case 5
+      comparison_bits = 
+        ( permlen[1] <= permlen[2] ? 1 : 0 ) | ( permlen[1] >= permlen[2] ? 2 : 0 ) |
+        ( permlen[3] <= permlen[4] ? 4 : 0 ) | ( permlen[3] >= permlen[4] ? 8 : 0 ) |
+        0;
+      if ( ( comparison_bits & 3 ) == 3 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[10][i] = ( permuted_coords[1][i] + permuted_coords[0][i] ) * .375 + permuted_coords[2][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[1], permuted_tags[0], permuted_tags[2], permuted_tags[10] );
+        permuted_hash[10] = (*this->output_functor)(
+          permuted_hash[1], permuted_hash[0], permuted_hash[2], permuted_coords[10], permuted_tags[10] );
+        }
+      if ( ( comparison_bits & 12 ) == 12 )
+        {
+        // Compute face point and tag
+        for ( int i = 0; i < 6; ++ i )
+          {
+          permuted_coords[11][i] = ( permuted_coords[0][i] + permuted_coords[1][i] ) * .375 + permuted_coords[3][i] * .25;
+          }
+        (*this->tag_assigner)( permuted_tags[0], permuted_tags[1], permuted_tags[3], permuted_tags[11] );
+        permuted_hash[11] = (*this->output_functor)(
+          permuted_hash[0], permuted_hash[1], permuted_hash[3], permuted_coords[11], permuted_tags[11] );
+        }
+      MB_TESSELLATOR_INCR_CASE_COUNT(9);
+      output_tets.push( SimplexTemplateRefiner::templates + 1107 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,0);
+      switch ( comparison_bits )
+        {
+        case 10: // 1>2,3>4
+          output_tets.push( SimplexTemplateRefiner::templates + 1116 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,1);
+          break;
+        case 5: // 2>1,4>3
+          output_tets.push( SimplexTemplateRefiner::templates + 1116 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,2);
+          break;
+        case 6: // 1>2,4>3
+          {
+          int alternates[] = { 1137, 1158, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,3);
+          break;
+        case 9: // 2>1,3>4
+          {
+          int alternates[] = {1137, 1158, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,4);
+          break;
+        case 11: // 1=2,3>4
+          {
+          int alternates[] = { 1179, 1212, 1245, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,5);
+          break;
+        case 7: // 1=2,4>3
+          {
+          int alternates[] = {1179, 1212, 1245, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 14, -1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[14] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,6);
+          break;
+        case 14: // 3=4,1>2
+          {
+          int alternates[] = {1179, 1212, 1245, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 5, 1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[5] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,7);
+          break;
+        case 13: // 3=4,2>1
+          {
+          int alternates[] = {1179, 1212, 1245, -1 };
+          output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 15, -1 ) );
+          }
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[15] );
+          output_sign.push( -1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,8);
+          break;
+        case 15: // 1=2,3=4
+          output_tets.push( SimplexTemplateRefiner::templates + 1278 );
+          output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+          output_sign.push( 1 );
+          MB_TESSELLATOR_INCR_SUBCASE_COUNT(9,9);
+          break;
+        }
+      break;
+    case 11: // Ruprecht-Müller Case 6
+      MB_TESSELLATOR_INCR_CASE_COUNT(10);
+      output_tets.push( SimplexTemplateRefiner::templates + 1319 );
+      output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+      output_sign.push( 1 );
+      MB_TESSELLATOR_INCR_SUBCASE_COUNT(10,0);
+        {
+        int alternates[] = { 1336, 1353, 1370, -1 };
+        output_tets.push( SimplexTemplateRefiner::templates + this->best_tets( alternates, permuted_coords, 0, 1 ) );
+        }
+        output_perm.push( SimplexTemplateRefiner::permutations_from_index[0] );
+        output_sign.push( 1 );
+        MB_TESSELLATOR_INCR_SUBCASE_COUNT(10,1);
+        break;
+    }
+
+  int* tets;
+  int  ntets;
+  int* perm;
+  int  sgn;
+#ifdef MB_DEBUG_TESSELLATOR
+  if ( output_tets.empty() )
+    {
+    cout << "Argh! Case " << C << " Perm " << P << " has no output!" << endl;
+    }
+#endif // MB_DEBUG_TESSELLATOR
+  while ( ! output_tets.empty() )
+    {
+    tets = output_tets.top();
+    ntets = *tets;
+    tets++;
+    perm = output_perm.top();
+    sgn = output_sign.top();
+
+    output_tets.pop();
+    output_perm.pop();
+    output_sign.pop();
+
+    int t;
+    if ( sgn > 0 )
+      {
+      for ( t = 0; t < ntets; ++t )
+        {
+        this->refine_3_simplex( max_depth,
+          permuted_coords[perm[tets[0]]], permuted_tags[perm[tets[0]]], permuted_hash[perm[tets[0]]],
+          permuted_coords[perm[tets[1]]], permuted_tags[perm[tets[1]]], permuted_hash[perm[tets[1]]],
+          permuted_coords[perm[tets[2]]], permuted_tags[perm[tets[2]]], permuted_hash[perm[tets[2]]],
+          permuted_coords[perm[tets[3]]], permuted_tags[perm[tets[3]]], permuted_hash[perm[tets[3]]]
+          );
+        tets += 4;
+        }
+      }
+    else
+      {
+      // we have an inverted tet... reverse the first 2 vertices
+      // so the orientation is positive.
+      for ( t = 0; t < ntets; ++t )
+        {
+        this->refine_3_simplex( max_depth,
+          permuted_coords[perm[tets[1]]], permuted_tags[perm[tets[1]]], permuted_hash[perm[tets[1]]],
+          permuted_coords[perm[tets[0]]], permuted_tags[perm[tets[0]]], permuted_hash[perm[tets[0]]],
+          permuted_coords[perm[tets[2]]], permuted_tags[perm[tets[2]]], permuted_hash[perm[tets[2]]],
+          permuted_coords[perm[tets[3]]], permuted_tags[perm[tets[3]]], permuted_hash[perm[tets[3]]]
+        );
+        tets += 4;
+        }
+      }
+    }
+
+  return true;
+}
+
+/**\brief This is used by refine_entity to assign parametric coordinates to corners of each element.
+  */
+void SimplexTemplateRefiner::assign_parametric_coordinates( int num_nodes, const double* src, double* tgt )
+{
+  for ( int i = 0; i < num_nodes; ++i, src +=3, tgt += 6 )
+    for ( int j = 0; j < 3; ++j )
+      tgt[j] = src[j];
+}
+
+/**\brief Returns true if || a0a1 || < || b0b1 ||
+  *
+  * We use this to test which triangulation has the best
+  * aspect ratio when there are 2 to choose from.
+  */
+bool SimplexTemplateRefiner::compare_Hopf_cross_string_dist(
+  const double* a0, const double* a1, const double* b0, const double* b1 )
+{   
+  double sq_mag_a = 0.;
+  double sq_mag_b = 0.;
+  for ( int i = 0; i < 3; ++ i )
+    {
+    double tmp;
+    tmp = a0[i] - a1[i];
+    sq_mag_a += tmp*tmp;
+    tmp = b0[i] - b1[i];
+    sq_mag_b += tmp*tmp;
+    } 
+  return sq_mag_a < sq_mag_b;
+}
+
+/*
+ * The array below is indexed by the edge code for a tetrahedron.
+ * Looking up a row with a tet's edge code will return C and P.
+ * C is a configuration number and P is a permutation index. 
+ *
+ * C is based on the case number from Ruprecht and
+ * Müller's (1998) paper on adaptive tetrahedra. (The case
+ * numbers are shown to the left of the row in the column
+ * labeled case. The only difference is that we introduce
+ * a case 3d which is part of case 3c in the paper.)
+ *
+ * P is an index into the permutations_from_index array below,
+ * and is used to transform the current tetrahedron into
+ * the canonical configuration associated with C.
+ *
+ * The 6-digit binary number to the left (which is shown in
+ * the horribly UNconventional LSB->MSB order) is the edge
+ * code for the row. The 6 digits correspond to the 6 edges
+ * of the tetrahedron; a '0' implies no subdivision while
+ * a '1' implies subdivision should occur. The ordering of
+ * the bits is
+ *
+ * Edge 0-1, Edge 1-2, Edge 2-0, Edge 0-3, Edge 1-3, Edge 2-3,
+ *
+ * where the numbers are vertices of the tetrahedron 0-1-2-3.
+ * Note that Tet 0-1-2-3 must be positive (i.e., the plane
+ * specified by Triangle 0-1-2 must have a normal pointing
+ * towards vertex 3, and Triangle 0-1-2's normal must be
+ * calculated using the cross-product (Edge 0-1) x (Edge 0-2)).
+ *
+ * ===========
+ * References:
+ * (Ruprect and Müller, 1998) A Scheme for Edge-based Adaptive
+ *   Tetrahedron Subdivision, Mathematical Visualization (eds.
+ *   Hege and Polthier), pp. 61--70. Springer-Verlag. 1998.
+ */
+int SimplexTemplateRefiner::template_index[64][2] =
+{
+  /*      code case      C    P */
+  /* 000000  0  0  */ {  0,   0 },
+  /* 100000  1  1  */ {  1,   0 },
+  /* 010000  2  1  */ {  1,   1 },
+  /* 110000  3  2a */ {  2,   0 },
+  /* 001000  4  1  */ {  1,   2 },
+  /* 101000  5  2a */ {  2,   2 },
+  /* 011000  6  2a */ {  2,   1 },
+  /* 111000  7  3b */ {  5,  11 },
+  /* 000100  8  1  */ {  1,  10 },
+  /* 100100  9  2a */ {  2,   5 },
+  /* 010100 10  2b */ {  3,   1 },
+  /* 110100 11  3c */ {  6,   0 },
+  /* 001100 12  2a */ {  2,  10 },
+  /* 101100 13  3a */ {  4,   0 },
+  /* 011100 14  3d */ {  7,   2 },
+  /* 111100 15  4a */ {  8,   6 },
+  /* 000010 16  1  */ {  1,   6 },
+  /* 100010 17  2a */ {  2,   4 },
+  /* 010010 18  2a */ {  2,   8 },
+  /* 110010 19  3a */ {  4,   1 },
+  /* 001010 20  2b */ {  3,   2 },
+  /* 101010 21  3d */ {  7,   0 },
+  /* 011010 22  3c */ {  6,   1 },
+  /* 111010 23  4a */ {  8,   9 },
+  /* 000110 24  2a */ {  2,   3 },
+  /* 100110 25  3b */ {  5,   0 },
+  /* 010110 26  3d */ {  7,   4 },
+  /* 110110 27  4a */ {  8,  11 },
+  /* 001110 28  3c */ {  6,  10 },
+  /* 101110 29  4a */ {  8,   7 },
+  /* 011110 30  4b */ {  9,   0 },
+  /* 111110 31  5  */ { 10,   7 },
+  /* 000001 32  1  */ {  1,   7 },
+  /* 100001 33  2b */ {  3,   0 },
+  /* 010001 34  2a */ {  2,   7 },
+  /* 110001 35  3d */ {  7,   1 },
+  /* 001001 36  2a */ {  2,  11 },
+  /* 101001 37  3c */ {  6,   2 },
+  /* 011001 38  3a */ {  4,   2 },
+  /* 111001 39  4a */ {  8,   3 },
+  /* 000101 40  2a */ {  2,   9 },
+  /* 100101 41  3d */ {  7,  10 },
+  /* 010101 42  3c */ {  6,   7 },
+  /* 110101 43  4b */ {  9,   2 },
+  /* 001101 44  3b */ {  5,   7 },
+  /* 101101 45  4a */ {  8,   8 },
+  /* 011101 46  4a */ {  8,   4 },
+  /* 111101 47  5  */ { 10,   6 },
+  /* 000011 48  2a */ {  2,   6 },
+  /* 100011 49  3c */ {  6,   4 },
+  /* 010011 50  3b */ {  5,   1 },
+  /* 110011 51  4a */ {  8,  10 },
+  /* 001011 52  3d */ {  7,   7 },
+  /* 101011 53  4b */ {  9,   1 },
+  /* 011011 54  4a */ {  8,   5 },
+  /* 111011 55  5  */ { 10,  10 },
+  /* 000111 56  3a */ {  4,  10 },
+  /* 100111 57  4a */ {  8,   1 },
+  /* 010111 58  4a */ {  8,   2 },
+  /* 110111 59  5  */ { 10,   2 },
+  /* 001111 60  4a */ {  8,   0 },
+  /* 101111 61  5  */ { 10,   1 },
+  /* 011111 62  5  */ { 10,   0 },
+  /* 111111 63  6  */ { 11,   0 },
+};
+
+
+/* Does this mean anything? If so, then you are either 
+ * superstitious or much more clever than I (or both?).
+ */
+/* permutation index, P:  0  1  2  3  4  5  6  7  8  9 10 11 */
+/* number of references: 12  9  9  3  4  2  5  6  2  3  7  2 */
+
+
+/*
+ * The array below is a list of all the _positive_
+ * permutations of Tetrahedron 0-1-2-3. Given a
+ * permutation index, it returns a row of 14 values:
+ * these are the vertex numbers of the permuted
+ * tetrahedron. The first 4 values are the permuted
+ * corner indices, the next 6 values are the
+ * permuted edge midpoint indices, and the final
+ * entries reference mid-face points inserted
+ * to maintain a compatible tetrahedralization.
+ *
+ * There are 24 entries, 6 for each of the 4 faces of
+ * the tetrahedron.
+ */
+int SimplexTemplateRefiner::permutations_from_index[24][14] =
+{
+  /* corners      midpoints          face points   */
+  /* POSITIVE ARRANGEMENTS                         */
+  { 0, 1, 2, 3,   4, 5, 6, 7, 8, 9,  10, 11, 12, 13 }, /* Face 0-1-2 */
+  { 1, 2, 0, 3,   5, 6, 4, 8, 9, 7,  10, 12, 13, 11 },
+  { 2, 0, 1, 3,   6, 4, 5, 9, 7, 8,  10, 13, 11, 12 },
+
+  { 0, 3, 1, 2,   7, 8, 4, 6, 9, 5,  11, 13, 12, 10 }, /* Face 0-3-1 */
+  { 3, 1, 0, 2,   8, 4, 7, 9, 5, 6,  11, 12, 10, 13 },
+  { 1, 0, 3, 2,   4, 7, 8, 5, 6, 9,  11, 10, 13, 12 },
+
+  { 1, 3, 2, 0,   8, 9, 5, 4, 7, 6,  12, 11, 13, 10 }, /* Face 1-3-2 */
+  { 3, 2, 1, 0,   9, 5, 8, 7, 6, 4,  12, 13, 10, 11 },
+  { 2, 1, 3, 0,   5, 8, 9, 6, 4, 7,  12, 10, 11, 13 },
+
+  { 2, 3, 0, 1,   9, 7, 6, 5, 8, 4,  13, 12, 11, 10 }, /* Face 2-3-0 */
+  { 3, 0, 2, 1,   7, 6, 9, 8, 4, 5,  13, 11, 10, 12 },
+  { 0, 2, 3, 1,   6, 9, 7, 4, 5, 8,  13, 10, 12, 11 },
+
+  /* NEGATIVE ARRANGEMENTS                         */
+  { 0, 2, 1, 3,   6, 5, 4, 7, 9, 8,  10, 13, 12, 11 }, /* Face 0-1-2 */
+  { 2, 1, 0, 3,   5, 4, 6, 9, 8, 7,  10, 12, 11, 13 },
+  { 1, 0, 2, 3,   4, 6, 5, 8, 7, 9,  10, 11, 13, 12 },
+
+  { 0, 1, 3, 2,   4, 8, 7, 6, 5, 9,  11, 10, 12, 13 }, /* Face 0-3-1 */
+  { 1, 3, 0, 2,   8, 7, 4, 5, 9, 6,  11, 12, 13, 10 },
+  { 3, 0, 1, 2,   7, 4, 8, 9, 6, 5,  11, 13, 10, 12 },
+
+  { 1, 2, 3, 0,   5, 9, 8, 4, 6, 7,  12, 10, 13, 11 }, /* Face 1-3-2 */
+  { 2, 3, 1, 0,   9, 8, 5, 6, 7, 4,  12, 13, 11, 10 },
+  { 3, 1, 2, 0,   8, 5, 9, 7, 4, 6,  12, 11, 10, 13 },
+
+  { 2, 0, 3, 1,   6, 7, 9, 5, 4, 8,  13, 10, 11, 12 }, /* Face 2-3-0 */
+  { 0, 3, 2, 1,   7, 9, 6, 4, 8, 5,  13, 11, 12, 10 },
+  { 3, 2, 0, 1,   9, 6, 7, 8, 5, 4,  13, 12, 10, 11 }
+};
+
+/*
+ * Below is a list of output tetrahedra. The array is
+ * generated by TessellatorGenerator.py
+ * which also generates the code that references it.
+ * Each set of tetrahedra begins with a single integer
+ * that is the number of tetrahedra for that particular
+ * case. It is followed by 5 integers for each output
+ * tetrahedron; the first four numbers on each row are
+ * indices of the output tetrahedron. The final number
+ * is a bit vector specifying which edges of the
+ * tetrahedron are internal to the parent tetrahedron
+ * being decomposed.
+ *
+ * Multiple lists of output tetrahedra may be
+ * combined to create the tessellation of a single
+ * input tetrahedron.
+ */
+
+int SimplexTemplateRefiner::templates[] = 
+{
+// case 1_0
+   2,
+   0,  4,  2,  3,
+   4,  1,  2,  3,
+
+// case 2a_0
+   1,
+   3,  4,  5,  1,
+
+// case 2a, 0>1
+   2,
+   0,  4,  2,  3,
+   4,  5,  2,  3,
+
+// case 2a, 0=1
+   4,
+  10,  3,  0,  4,
+  10,  3,  4,  5,
+  10,  3,  5,  2,
+  10,  3,  2,  0,
+
+// case 2b_0
+   4,
+   0,  4,  9,  3,
+   4,  1,  9,  3,
+   0,  4,  2,  9,
+   4,  1,  2,  9,
+
+// case 3a_0
+   1,
+   4,  7,  6,  0,
+
+// case 3a, 0>2>3<0
+   3,
+   1,  3,  2,  4,
+   4,  6,  3,  2,
+   4,  6,  7,  3,
+
+// case 3a, 0=2>3<0
+   5,
+   4,  6,  7,  3,
+  10,  1,  2,  3,
+  10,  2,  6,  3,
+  10,  6,  4,  3,
+  10,  4,  1,  3,
+
+// case 3a, 3>0=2<3
+   5,
+   1,  3,  2,  7,
+  10,  1,  2,  7,
+  10,  2,  6,  7,
+  10,  6,  4,  7,
+  10,  4,  1,  7,
+
+// case 3a, 0=2=3=0
+  11,
+   2,  6, 10, 13,
+   3,  7, 13, 11,
+   4,  1, 10, 11,
+  11,  6, 10,  4,
+  11,  6, 13, 10,
+  11,  6,  7, 13,
+  11,  6,  4,  7,
+   2, 10, 11, 13,
+   1, 10, 11,  2,
+   2, 11,  3, 13,
+   3,  2,  1, 11,
+
+// case 3b_0
+   4,
+   0,  7,  4,  2,
+   4,  7,  8,  2,
+   4,  8,  1,  2,
+   7,  3,  8,  2,
+
+// case 3c, 0>1,0>3
+   5,
+   4,  2,  7,  5,
+   4,  2,  0,  7,
+   4,  3,  1,  5,
+   4,  3,  5,  7,
+   3,  5,  7,  2,
+
+// case 3c, 1>0,3>0
+   5,
+   0,  5,  2,  7,
+   0,  5,  7,  4,
+   7,  1,  4,  5,
+   7,  1,  5,  3,
+   3,  5,  7,  2,
+
+// case 3c, 0>1,3>0
+   5,
+   4,  2,  7,  5,
+   4,  2,  0,  7,
+   7,  1,  4,  5,
+   7,  1,  5,  3,
+   3,  5,  7,  2,
+
+// case 3c, 1>0,0>3
+   5,
+   0,  5,  2,  7,
+   0,  5,  7,  4,
+   4,  3,  1,  5,
+   4,  3,  5,  7,
+   3,  5,  7,  2,
+
+// case 3c, 0=1,0>3
+   7,
+   4,  1,  5,  3,
+  10,  0,  4,  7,
+  10,  2,  0,  7,
+  10,  7,  4,  3,
+  10,  2,  7,  3,
+  10,  5,  2,  3,
+  10,  4,  5,  3,
+
+// case 3c, 3>0,0=1
+   7,
+   7,  1,  5,  3,
+   7,  5,  2,  3,
+  10,  0,  4,  7,
+  10,  2,  0,  7,
+  10,  5,  2,  7,
+  10,  4,  5,  7,
+   1,  5,  4,  7,
+
+// case 3c, 0=1,0=3
+  10,
+   4,  1,  5, 11,
+  11,  1,  5,  3,
+  10,  0,  4,  7,
+  10,  2,  0,  7,
+  10,  5,  2,  3,
+  10,  2,  7,  3,
+  10,  7,  4, 11,
+  10,  7, 11,  3,
+  10,  4,  5, 11,
+  10, 11,  5,  3,
+
+// case 3d, 0>4,0>2
+   5,
+   4,  3,  6,  0,
+   4,  3,  8,  6,
+   4,  2,  8,  1,
+   4,  2,  6,  8,
+   2,  3,  6,  8,
+
+// case 3d, 4>0,2>0
+   5,
+   8,  0,  6,  4,
+   8,  0,  3,  6,
+   6,  1,  8,  4,
+   6,  1,  2,  8,
+   2,  3,  6,  8,
+
+// case 3d, 0>4,2>0
+   5,
+   4,  3,  6,  0,
+   4,  3,  8,  6,
+   6,  1,  8,  4,
+   6,  1,  2,  8,
+   2,  3,  6,  8,
+
+// case 3d, 4>0,0>2
+   5,
+   8,  0,  6,  4,
+   8,  0,  3,  6,
+   4,  2,  8,  1,
+   4,  2,  6,  8,
+   2,  3,  6,  8,
+
+// case 3d, 0=4,0>2
+   7,
+   4,  1,  2,  8,
+  11,  4,  0,  6,
+  11,  0,  3,  6,
+  11,  2,  4,  6,
+  11,  3,  2,  6,
+  11,  3,  8,  2,
+  11,  8,  4,  2,
+
+// case 3d, 2>0,0=4
+   7,
+   6,  2,  8,  1,
+   6,  8,  2,  3,
+  11,  4,  0,  6,
+  11,  0,  3,  6,
+   8, 11,  3,  6,
+   8,  4, 11,  6,
+   1,  6,  4,  8,
+
+// case 3d, 0=4,0=2
+  10,
+   4,  1, 10,  8,
+  10,  2,  8,  1,
+  11,  4,  0,  6,
+  11,  0,  3,  6,
+  11,  3,  8,  2,
+  11,  3,  2,  6,
+  11, 10,  4,  6,
+  11, 10,  6,  2,
+   8,  4, 11, 10,
+  11, 10,  2,  8,
+
+// case 4a_0
+   2,
+   7,  8,  9,  3,
+   7,  9,  8,  6,
+
+// case 4a, 5>4>3
+   4,
+   8,  0,  6,  1,
+   8,  0,  7,  6,
+   9,  1,  6,  2,
+   9,  1,  8,  6,
+
+// case 4a, 3<4>5
+   4,
+   8,  0,  6,  1,
+   8,  0,  7,  6,
+   8,  2,  6,  9,
+   8,  2,  1,  6,
+
+// case 4a, 3>4<5
+   4,
+   6,  9,  8,  1,
+   6,  9,  1,  2,
+   6,  7,  0,  1,
+   6,  7,  1,  8,
+
+// case 4a, 3=4>5
+   6,
+   6,  7,  0, 11,
+   6,  0,  1, 11,
+   6,  7, 11,  8,
+   6, 11,  1,  8,
+   1,  2,  6,  8,
+   2,  6,  8,  9,
+
+// case 4a, 5>4,3=4
+   6,
+   6,  7,  0, 11,
+   6,  0,  1, 11,
+   6,  7, 11,  8,
+   6, 11,  1,  8,
+   1,  2,  6,  9,
+   1,  6,  8,  9,
+
+// case 4a, 3=4=5
+   8,
+   6,  7,  0, 11,
+   6,  0,  1, 11,
+   6,  7, 11,  8,
+   6, 11,  1,  8,
+   6,  1,  2, 12,
+   6,  2,  9, 12,
+   6,  9,  8, 12,
+   6,  8,  1, 12,
+
+// case 4b, 2>1,3>2,4>3,4>1
+   6,
+   6,  8,  1,  5,
+   6,  8,  0,  1,
+   6,  8,  7,  0,
+   6,  8,  2,  7,
+   7,  8,  2,  3,
+   6,  8,  5,  2,
+
+// case 4b, 2>1,3>2,3>4,4>1
+   6,
+   6,  8,  1,  5,
+   6,  8,  7,  1,
+   6,  7,  0,  1,
+   8,  7,  3,  2,
+   6,  8,  5,  2,
+   6,  8,  2,  7,
+
+// case 4b, 2>1,3>2,3>4,4>1, a
+   6,
+   7,  8,  1,  5,
+   6,  5,  7,  1,
+   6,  7,  0,  1,
+   8,  7,  3,  2,
+   7,  8,  5,  2,
+   6,  5,  2,  7,
+
+// case 4b, 2>1,2>3,4>3,4>1
+   6,
+   6,  8,  5,  2,
+   6,  8,  2,  3,
+   6,  8,  3,  7,
+   6,  8,  7,  0,
+   6,  8,  0,  1,
+   6,  8,  1,  5,
+
+// case 4b, 1=2,3>2,3>4,4>1
+   9,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  7,
+  10,  7,  1,  8,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6,  2,  7,  8,
+   6,  5,  2,  8,
+   7,  8,  2,  3,
+
+// case 4b, 1=2,2>3,4>3,1>4
+   9,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  8,
+  10,  7,  0,  8,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6,  3,  7,  8,
+   6,  5,  3,  8,
+   6,  5,  2,  3,
+
+// case 4b, 1=2,2>3,4>3,4>1
+   9,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  8,
+  10,  7,  0,  8,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6,  3,  7,  8,
+   6,  5,  2,  8,
+   6,  2,  3,  8,
+
+// case 4b, 1=2,3>2,3=4,4>1
+  11,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1, 11,
+  10, 11,  1,  8,
+  10,  0, 11,  7,
+  10,  7, 11,  8,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6,  2,  7,  8,
+   6,  5,  2,  8,
+   7,  8,  2,  3,
+
+// case 4b, 4>1=2=3,4>3
+  12,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  8,
+  10,  7,  0,  8,
+  13,  6,  2,  5,
+  13,  3,  7,  8,
+  13,  2,  3,  8,
+  13,  2,  8,  5,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6, 13,  7,  8,
+   6,  5, 13,  8,
+
+// case 4b, 1=2=3>4,1>4
+  12,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  7,
+  10,  7,  1,  8,
+  13,  6,  2,  5,
+  13,  3,  7,  8,
+  13,  2,  3,  5,
+  13,  3,  8,  5,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6, 13,  7,  8,
+   6,  5, 13,  8,
+
+// case 4b, 1=2=3=4=1
+  16,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1, 11,
+  10, 11,  1,  8,
+  10,  0, 11,  7,
+  10,  7, 11,  8,
+  13,  6,  2,  5,
+  13,  3,  7,  8,
+  13,  2,  3, 12,
+  13,  2, 12,  5,
+  13, 12,  3,  8,
+  13, 12,  5,  8,
+   6,  7, 10,  8,
+   6, 10,  5,  8,
+   6,  5, 13,  8,
+   6, 13,  7,  8,
+
+// case 5_0
+   2,
+   7,  8,  9,  3,
+   6,  5,  2,  9,
+
+// case 5, 1>2,3>4
+   5,
+   5,  7,  1,  8,
+   5,  7,  0,  1,
+   5,  7,  6,  0,
+   5,  7,  9,  6,
+   5,  7,  8,  9,
+
+// case 5, 1>2,4>3
+   5,
+   0,  5,  6,  7,
+   0,  5,  7,  8,
+   0,  5,  8,  1,
+   5,  7,  9,  6,
+   5,  7,  8,  9,
+
+// case 5, 1>2,4>3, a
+   5,
+   0,  5,  6,  8,
+   0,  6,  7,  8,
+   0,  5,  8,  1,
+   5,  8,  9,  6,
+   6,  7,  8,  9,
+
+// case 5, 1=2,3>4
+   8,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  7,
+  10,  7,  1,  8,
+  10,  8,  5,  9,
+  10,  6,  7,  9,
+  10,  7,  8,  9,
+  10,  5,  6,  9,
+
+// case 5, 1=2,3>4, a
+   8,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  7,
+  10,  7,  1,  8,
+   7,  8,  5,  9,
+  10,  6,  7,  5,
+  10,  7,  8,  5,
+   5,  9,  6,  7,
+
+// case 5, 1=2,3>4, b
+   8,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1,  7,
+  10,  7,  1,  8,
+   6,  8,  5,  9,
+  10,  6,  7,  8,
+  10,  6,  8,  5,
+   8,  9,  6,  7,
+
+// case 5, 1=2,3=4
+  10,
+  10,  6,  0,  7,
+  10,  1,  5,  8,
+  10,  0,  1, 11,
+  10, 11,  1,  8,
+  10,  0, 11,  7,
+  10,  7, 11,  8,
+  10,  8,  5,  9,
+  10,  6,  7,  9,
+  10,  7,  8,  9,
+  10,  5,  6,  9,
+
+// case 6_0
+   4,
+   7,  8,  9,  3,
+   6,  5,  2,  9,
+   4,  1,  5,  8,
+   0,  4,  6,  7,
+
+// case 6_1
+   4,
+   6,  4,  5,  8,
+   6,  5,  9,  8,
+   6,  9,  7,  8,
+   6,  7,  4,  8,
+
+// case 6_1, a
+   4,
+   5,  8,  9,  7,
+   5,  9,  6,  7,
+   5,  6,  4,  7,
+   5,  4,  8,  7,
+
+// case 6_1, b
+   4,
+   4,  5,  6,  9,
+   4,  6,  7,  9,
+   4,  7,  8,  9,
+   4,  8,  5,  9,
+
+};
+
+} // namespace moab 
+

Copied: MOAB/trunk/tools/refiner/SimplexTemplateRefiner.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBSimplexTemplateRefiner.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/SimplexTemplateRefiner.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SimplexTemplateRefiner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,89 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class SimplexTemplateRefiner
+  *
+  * This is a concrete subclass of EntityRefiner that implements
+  * refinement using templates applied to simplices.
+  * Entities that are not simplices are divided into tetrahedra,
+  * triangles, or lines before being processed.
+  * Points are passed through unchanged.
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 24 December 2007
+  */
+#ifndef MB_SIMPLEX_TEMPLATE_REFINER_HPP
+#define MB_SIMPLEX_TEMPLATE_REFINER_HPP
+
+#include "moab/EntityRefiner.hpp"
+#include "moab/SimplexTemplateTagAssigner.hpp"
+
+#include "moab/Types.h" // for MB_DLL_EXPORT
+
+namespace moab { 
+
+class RefinerTagManager;
+
+class MB_DLL_EXPORT SimplexTemplateRefiner : public EntityRefiner
+{
+public:
+  SimplexTemplateRefiner();
+  virtual ~SimplexTemplateRefiner();
+
+  virtual bool refine_entity( EntityType etyp, EntityHandle entity );
+  virtual unsigned long get_heap_size_bound( int max_recursions ) const { return 48 * 4 * ( 1 << max_recursions ) + 8; }
+
+  virtual bool set_tag_assigner( SimplexTemplateTagAssigner* ta );
+  SimplexTemplateTagAssigner* get_tag_assigner() const { return this->tag_assigner; }
+
+  virtual bool prepare( RefinerTagManager* tmgr, EntityRefinerOutputFunctor* ofunc );
+
+protected:
+  SimplexTemplateTagAssigner* tag_assigner;
+  RefinerTagManager* tag_manager;
+  std::vector<double> corner_coords;
+  std::vector<void*> corner_tags;
+  std::vector<EntityHandle> corner_handles;
+  bool input_is_output;
+
+  static int template_index[64][2];
+  static int permutations_from_index[24][14];
+  static int templates[];
+
+  void refine_0_simplex( const double* v0, const void* t0, EntityHandle h0 );
+  bool refine_1_simplex( int max_depth,
+                         const double* v0, const void* t0, EntityHandle h0,
+                         const double* v1, const void* t1, EntityHandle h1 );
+  bool refine_2_simplex( int max_depth, int move,
+                         const double* v0, const void* t0, EntityHandle h0,
+                         const double* v1, const void* t1, EntityHandle h1,
+                         const double* v2, const void* t2, EntityHandle h2 );
+  bool refine_3_simplex( int max_depth,
+                         double* v0, void* t0, EntityHandle h0,
+                         double* v1, void* t1, EntityHandle h1,
+                         double* v2, void* t2, EntityHandle h2,
+                         double* v3, void* t3, EntityHandle h3 );
+
+  int best_tets( int* alternates, double*[14], int, int ) { return alternates[0]; }
+  void assign_parametric_coordinates( int num_nodes, const double* src, double* tgt );
+  static bool compare_Hopf_cross_string_dist( const double* v00, const double* v01, const double* v10, const double* v11 );
+};
+
+} // namespace moab 
+
+#endif // MB_SIMPLEX_TEMPLATE_REFINER_HPP
+

Copied: MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,106 @@
+#include "moab/SimplexTemplateTagAssigner.hpp"
+
+#include "moab/EdgeSizeEvaluator.hpp"
+#include "moab/Interface.hpp"
+#include "moab/RefinerTagManager.hpp"
+#include "moab/SimplexTemplateRefiner.hpp"
+
+#include <vector>
+
+#include <math.h>
+
+namespace moab {
+
+using namespace std;
+
+/// Construct a template tag assigner.
+SimplexTemplateTagAssigner::SimplexTemplateTagAssigner( SimplexTemplateRefiner* r )
+{
+  this->mesh_refiner = r;
+  this->tag_manager = 0;
+}
+
+/// Empty destructor for good form.
+SimplexTemplateTagAssigner::~SimplexTemplateTagAssigner()
+{
+}
+
+/**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag values.
+  *
+  * Normally, this function will be invoked by the EntityRefiner before evaluate_edge is called.
+  * However, if evaluate_edge() changes the parametric coordinates of the midpoint,
+  * it should call evaluate_tags_at_midpoint() again to update any tag values;
+  * that is why this function is a member of EdgeSizeEvaluator and not EntityRefiner.
+  *
+  * @param[in] c0 Pointer to endpoint 0 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[in] t0 Pointer to endpoint 0 tag values.
+  * @param[in] cm Pointer to midpoint coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[out] tm Pointer to midpoint tag values.
+  * @param[in] c1 Pointer to endpoint 1 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[in] t1 Pointer to endpoint 1 tag values.
+  */
+void SimplexTemplateTagAssigner::operator () (
+  const double* c0, const void* t0, EntityHandle h0,
+  const double* cm, void* tm, 
+  const double* c1, const void* t1, EntityHandle h1 )
+{
+  double c0m_squared = 0.;
+  double c01_squared = 0.;
+  for ( int i = 0; i < 3; ++i )
+    {
+    double tmp = cm[i] - c0[i];
+    c0m_squared += tmp * tmp;
+    tmp = c1[i] - c0[i];
+    c01_squared += tmp * tmp;
+    }
+  double lambda = sqrt( c0m_squared / c01_squared );
+  double one_minus_lambda = 1. - lambda;
+
+  DataType data_type;
+  int tag_size;
+  int num_components;
+  int num_tags = this->tag_manager->get_number_of_vertex_tags();
+  Tag tag_handle;
+  int tag_offset;
+  for ( int i = 0; i < num_tags; ++i )
+    {
+    this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
+    this->tag_manager->get_input_mesh()->tag_get_data_type( tag_handle, data_type );
+    this->tag_manager->get_input_mesh()->tag_get_size( tag_handle, tag_size );
+    
+    switch ( data_type )
+      {
+      case MB_TYPE_DOUBLE:
+        {
+        num_components = tag_size / sizeof( double );
+        double* t0i = (double*) ( (char*)t0 + tag_offset );
+        double* tmi = (double*) ( (char*)tm + tag_offset );
+        double* t1i = (double*) ( (char*)t1 + tag_offset );
+        for ( int i = 0; i < num_components; ++ i )
+          tmi[i] = one_minus_lambda * t0i[i] + lambda * t1i[i];
+        }
+        break;
+      default:
+        memcpy( (char*)tm + tag_offset, (char*)( h0 < h1 ? t0 : t1 ) + tag_offset, tag_size );
+        break;
+      }
+    }
+}
+
+void SimplexTemplateTagAssigner::operator () ( const void* t0,
+                                                 const void* t1,
+                                                 const void* t2,
+                                                 void* tp )
+{
+  (void)t0;
+  (void)t1;
+  (void)t2;
+  (void)tp;
+}
+
+void SimplexTemplateTagAssigner::set_tag_manager( RefinerTagManager* tmgr )
+{
+  this->tag_manager = tmgr;
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBSimplexTemplateTagAssigner.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SimplexTemplateTagAssigner.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,59 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class SimplexTemplateTagAssigner
+  *
+  * This is an class that embodies the process of assigning tag
+  * values to new vertices based on some pre-existing neighbors in a 
+  * simplicial mesh.
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 28 December 2007
+  */
+#ifndef MOAB_SIMPEX_TEMPLATE_TAG_ASSIGNER_HPP
+#define MOAB_SIMPEX_TEMPLATE_TAG_ASSIGNER_HPP
+
+#include "moab/Types.h" // for MB_DLL_EXPORT
+
+namespace moab {
+
+class RefinerTagManager;
+class SimplexTemplateRefiner;
+
+class MB_DLL_EXPORT SimplexTemplateTagAssigner
+{
+public:
+  SimplexTemplateTagAssigner( SimplexTemplateRefiner* );
+  virtual ~SimplexTemplateTagAssigner();
+  
+  virtual void operator () ( const double* c0, const void* t0, EntityHandle h0,
+                             const double* cm, void* tm,
+                             const double* c1, const void* t1, EntityHandle h1 );
+  virtual void operator () ( const void* t0,
+                             const void* t1,
+                             const void* t2,
+                             void* tp );
+  virtual void set_tag_manager( RefinerTagManager* tmgr );
+
+protected:
+  SimplexTemplateRefiner* mesh_refiner;
+  RefinerTagManager* tag_manager;
+};
+
+} // namespace moab
+
+#endif // MOAB_SIMPEX_TEMPLATE_TAG_ASSIGNER_HPP

Copied: MOAB/trunk/tools/refiner/SplitVertices.cpp (from rev 3583, MOAB/trunk/tools/refiner/MBSplitVertices.cpp)
===================================================================
--- MOAB/trunk/tools/refiner/SplitVertices.cpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SplitVertices.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,70 @@
+#include "moab/SplitVertices.hpp"
+#include "moab/RefinerTagManager.hpp"
+
+#include "moab/ParallelConventions.h"
+
+namespace moab {
+
+SplitVerticesBase::SplitVerticesBase( RefinerTagManager* tag_mgr )
+{
+  this->tag_manager = tag_mgr;
+  this->mesh_out = tag_mgr->get_output_mesh();
+}
+
+SplitVerticesBase::~SplitVerticesBase()
+{
+}
+
+EntitySource::EntitySource( int nc, RefinerTagManager* tag_mgr )
+{
+  this->tag_manager = tag_mgr;
+  this->mesh_out = tag_mgr->get_output_mesh();
+  this->num_corners = nc;
+}
+
+EntitySource::~EntitySource()
+{
+}
+
+bool EntitySource::create_element(
+  EntityType etyp, int nconn, const EntityHandle* elem_verts, EntityHandle& elem_handle,
+  std::map<ProcessSet,int>& proc_partition_counts )
+{
+  // Get the global IDs of the input vertices
+  int stat;
+  proc_partition_counts[this->tag_manager->get_element_procs()]++;
+  if ( this->mesh_out->create_element( etyp, elem_verts, nconn, elem_handle ) != MB_SUCCESS )
+    {
+    return false;
+    }
+  this->push_back( EntitySourceRecord( this->num_corners, elem_handle, this->tag_manager->get_element_procs() ) );
+  this->tag_manager->set_sharing( elem_handle, this->tag_manager->get_element_procs() );
+  return true;
+}
+
+void EntitySource::assign_global_ids( std::map<ProcessSet,int>& gids )
+{
+  std::vector<EntityHandle> adjacencies;
+  adjacencies.resize( this->num_corners );
+  std::vector<EntitySourceRecord>::iterator it;
+  int stat;
+  for ( it = this->begin(); it != this->end(); ++ it )
+    {
+    int num_nodes;
+    const EntityHandle* conn;
+    this->mesh_out->get_connectivity( it->handle, conn, num_nodes );
+    stat = this->tag_manager->get_output_gids( this->num_corners, conn, it->ids );
+    std::sort( it->ids.begin(), it->ids.end() );
+    }
+  std::sort( this->begin(), this->end() );
+  for ( it = this->begin(); it != this->end(); ++ it )
+    {
+    int gid = gids[it->process_set] ++;
+    this->tag_manager->set_gid( it->handle, gid );
+#ifdef MB_DEBUG
+    std::cout << "Assigning entity: " << it->handle << " GID: " << gid << "\n";
+#endif // MB_DEBUG
+    }
+}
+
+} // namespace moab

Copied: MOAB/trunk/tools/refiner/SplitVertices.hpp (from rev 3583, MOAB/trunk/tools/refiner/MBSplitVertices.hpp)
===================================================================
--- MOAB/trunk/tools/refiner/SplitVertices.hpp	                        (rev 0)
+++ MOAB/trunk/tools/refiner/SplitVertices.hpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,260 @@
+/*
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ * 
+ * Copyright 2007 Sandia Corporation.  Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+/**\class SplitVertices
+  *\brief A dictionary of new vertices.
+  *
+  * An array of existing vertex ids used as a key in a dictionary of new vertices.
+  */
+#ifndef MOAB_SPLIT_VERTICES_HPP
+#define MOAB_SPLIT_VERTICES_HPP
+
+#include "moab/Types.h"
+#include "moab/ProcessSet.hpp"
+#include "moab/MBTagConventions.hpp"
+
+#include <map>
+#include <vector>
+#include <algorithm>
+
+#undef MB_DEBUG
+
+namespace moab { 
+
+class RefinerTagManager;
+
+template< int _n >
+class SplitVertexIndex
+{
+public:
+  SplitVertexIndex() { }
+  SplitVertexIndex( const int* src )
+    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src[i]; std::sort( this->ids, this->ids + _n ); }
+  SplitVertexIndex( const SplitVertexIndex<_n>& src )
+    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src.ids[i]; this->process_set = src.process_set; }
+  SplitVertexIndex& operator = ( const SplitVertexIndex<_n>& src )
+    { for ( int i = 0; i < _n; ++ i ) this->ids[i] = src.ids[i]; this->process_set = src.process_set; return *this; }
+
+  void set_common_processes( const ProcessSet& procs )
+    { this->process_set = procs; }
+  ProcessSet& common_processes()
+    { return this->process_set; }
+  const ProcessSet& common_processes() const
+    { return this->process_set; }
+
+  bool operator < ( const SplitVertexIndex<_n>& other ) const
+    {
+    // Ignore the process set. Only program errors lead to mismatched process sets with identical ids.
+    for ( int i = 0; i < _n; ++ i )
+      if ( this->ids[i] < other.ids[i] )
+        return true;
+      else if ( this->ids[i] > other.ids[i] )
+        return false;
+    return false;
+    }
+
+  int ids[_n + 1];
+  ProcessSet process_set;
+};
+
+template< int _n >
+std::ostream& operator << ( std::ostream& os, const SplitVertexIndex<_n>& idx )
+{
+  for ( int i = 0; i < _n; ++ i )
+    {
+    os << idx.ids[i] << " ";
+    }
+  os << "(" << idx.process_set << ")";
+  return os;
+}
+
+class EntitySourceRecord
+{
+public:
+  EntitySourceRecord() { }
+  EntitySourceRecord( int nc, EntityHandle ent, const ProcessSet& procs )
+    { this->ids.resize( nc ); this->handle = ent; this->process_set = procs; }
+  EntitySourceRecord( const EntitySourceRecord& src )
+    { this->handle = src.handle; this->process_set = src.process_set; this->ids = src.ids; }
+  EntitySourceRecord& operator = ( const EntitySourceRecord& src )
+    { this->handle = src.handle; this->process_set = src.process_set; this->ids = src.ids; return *this; }
+
+  void set_common_processes( const ProcessSet& procs )
+    { this->process_set = procs; }
+  ProcessSet& common_processes()
+    { return this->process_set; }
+  const ProcessSet& common_processes() const
+    { return this->process_set; }
+
+  bool operator < ( const EntitySourceRecord& other ) const
+    {
+    //assert( this->ids.size() == other.ids.size() );
+    std::vector<int>::size_type N = this->ids.size();
+    std::vector<int>::size_type i;
+    // Ignore the process set. Only program errors lead to mismatched process sets with identical ids.
+    for ( i = 0; i < N; ++ i )
+      if ( this->ids[i] < other.ids[i] )
+        return true;
+      else if ( this->ids[i] > other.ids[i] )
+        return false;
+    return false;
+    }
+
+  std::vector<int> ids;
+  ProcessSet process_set;
+  EntityHandle handle;
+};
+
+
+/** A non-templated base class that the SplitVertices template subclasses all share.
+  *
+  * All methods that need to be accessed by other classes should be
+  * declared by the base class so that no knowledge of template parameters
+  * is required.
+  */
+class SplitVerticesBase
+{
+public:
+  SplitVerticesBase( RefinerTagManager* tag_mgr );
+  virtual ~SplitVerticesBase();
+
+  virtual bool find_or_create(
+    const EntityHandle* split_src, const double* coords, EntityHandle& vert_handle,
+    std::map<ProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh ) = 0;
+
+  virtual void assign_global_ids( std::map<ProcessSet,int>& gids ) = 0;
+
+  Interface* mesh_out; // Output mesh. Needed for new vertex set in vert_handle
+  RefinerTagManager* tag_manager;
+  std::vector<int> split_gids; // Used to hold global IDs of split vertices
+  ProcessSet common_shared_procs; // Holds intersection of several shared_procs_ins.
+};
+
+/** A vector of pre-existing entities to a new mesh entity.
+  *
+  * This is used as a dictionary to determine whether a new vertex should be
+  * created on the given n-simplex (n being the template parameter) or whether
+  * it has already been created as part of the refinement of a neighboring entity.
+  */
+class EntitySource : public std::vector<EntitySourceRecord>
+{
+public:
+  typedef std::vector<EntitySourceRecord> VecType;
+  typedef std::vector<EntitySourceRecord>::iterator VecIteratorType;
+
+  EntitySource( int num_corners, RefinerTagManager* tag_mgr );
+  ~EntitySource();
+  bool create_element(
+    EntityType etyp, int nconn, const EntityHandle* split_src, EntityHandle& elem_handle,
+    std::map<ProcessSet,int>& proc_partition_counts );
+
+  void assign_global_ids( std::map<ProcessSet,int>& gids );
+
+  Interface* mesh_out; // Output mesh. Needed for new vertex set in vert_handle
+  RefinerTagManager* tag_manager;
+  ProcessSet common_shared_procs; // Holds intersection of several shared_procs_ins.
+  int num_corners;
+};
+
+
+/** A map from a set of pre-existing vertices to a new mesh vertex.
+  *
+  * This is used as a dictionary to determine whether a new vertex should be
+  * created on the given n-simplex (n being the template parameter) or whether
+  * it has already been created as part of the refinement of a neighboring entity.
+  */
+template< int _n >
+class SplitVertices : public std::map<SplitVertexIndex<_n>,EntityHandle>, public SplitVerticesBase
+{
+public:
+  typedef std::map<SplitVertexIndex<_n>,EntityHandle> MapType;
+  typedef typename std::map<SplitVertexIndex<_n>,EntityHandle>::iterator MapIteratorType;
+
+  SplitVertices( RefinerTagManager* tag_mgr );
+  virtual ~SplitVertices();
+  virtual bool find_or_create(
+    const EntityHandle* split_src, const double* coords, EntityHandle& vert_handle,
+    std::map<ProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh );
+
+  virtual void assign_global_ids( std::map<ProcessSet,int>& gids );
+};
+
+// ------------------------- Template member definitions ----------------------
+template< int _n >
+SplitVertices<_n>::SplitVertices( RefinerTagManager* tag_mgr )
+  : SplitVerticesBase( tag_mgr )
+{
+  this->split_gids.resize( _n );
+}
+
+template< int _n >
+SplitVertices<_n>::~SplitVertices()
+{
+}
+
+template< int _n >
+bool SplitVertices<_n>::find_or_create(
+  const EntityHandle* split_src, const double* coords, EntityHandle& vert_handle,
+  std::map<ProcessSet,int>& proc_partition_counts, bool handles_on_output_mesh )
+{
+  // Get the global IDs of the input vertices
+  int stat;
+  if ( handles_on_output_mesh )
+    {
+    stat = this->tag_manager->get_output_gids( _n, split_src, this->split_gids );
+    }
+  else
+    {
+    stat = this->tag_manager->get_input_gids( _n, split_src, this->split_gids );
+    }
+  SplitVertexIndex<_n> key( &this->split_gids[0] );
+  MapIteratorType it = this->find( key );
+  if ( it == this->end() )
+    {
+#ifdef MB_DEBUG
+    std::cout << " wrt output: " << handles_on_output_mesh << " ";
+#endif // MB_DEBUG
+    this->tag_manager->get_common_processes( _n, split_src, this->common_shared_procs, handles_on_output_mesh );
+    proc_partition_counts[this->common_shared_procs]++;
+    key.set_common_processes( this->common_shared_procs );
+    if ( this->mesh_out->create_vertex( coords + 3, vert_handle ) != MB_SUCCESS )
+      {
+      return false;
+      }
+    (*this)[key] = vert_handle;
+    this->tag_manager->set_sharing( vert_handle, this->common_shared_procs );
+    return true;
+    }
+  vert_handle = it->second;
+  return false;
+}
+
+template< int _n >
+void SplitVertices<_n>::assign_global_ids( std::map<ProcessSet,int>& gids )
+{
+  typename std::map<SplitVertexIndex<_n>,EntityHandle>::iterator it;
+  for ( it = this->begin(); it != this->end(); ++ it )
+    {
+    int gid = gids[it->first.process_set] ++;
+    this->tag_manager->set_gid( it->second, gid );
+#ifdef MB_DEBUG
+    std::cout << "Assigning entity: " << it->first << " GID: " << gid << "\n";
+#endif // MB_DEBUG
+    }
+}
+
+} // namespace moab 
+
+#endif /* MOAB_SPLIT_VERTICES_HPP */

Modified: MOAB/trunk/tools/refiner/test_mesh_refiner.cpp
===================================================================
--- MOAB/trunk/tools/refiner/test_mesh_refiner.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/refiner/test_mesh_refiner.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -9,7 +9,7 @@
 #include "MBParallelComm.hpp"
 #include "ReadParallel.hpp"
 #include "FileOptions.hpp"
-#include "MBmpi.h"
+#include "moab_mpi.h"
 #endif // USE_MPI
 
 #include <iostream>

Modified: MOAB/trunk/tools/size.cpp
===================================================================
--- MOAB/trunk/tools/size.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/size.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -37,11 +37,13 @@
 #include <assert.h>
 #include <float.h>
 
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
-#include "MBInterface.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Interface.hpp"
 
+using namespace moab;
+
 #include "measure.hpp"
 
 void usage( const char* exe )
@@ -56,7 +58,7 @@
 }
 
 
-MBCore moab;
+Core mb;
 
 
 struct stat_set 
@@ -120,31 +122,31 @@
 };
 
 
-MBErrorCode gather_set_stats( MBEntityHandle set, set_stats& stats )
+ErrorCode gather_set_stats( EntityHandle set, set_stats& stats )
 {
-  MBErrorCode rval = MB_SUCCESS;
+  ErrorCode rval = MB_SUCCESS;
   
   int count;
-  rval = moab.get_number_entities_by_type( set, MBVERTEX, count );
+  rval = mb.get_number_entities_by_type( set, MBVERTEX, count );
   if (MB_SUCCESS != rval) return rval;
   stats.nodes = count;
   
   int edge_vtx_idx[2];
-  std::vector<MBEntityHandle> conn;
+  std::vector<EntityHandle> conn;
   std::vector<double> coords;
-  for (MBEntityType type = MBEDGE; type < MBENTITYSET; ++type)
+  for (EntityType type = MBEDGE; type < MBENTITYSET; ++type)
   {
     int num_edges = MBCN::NumSubEntities( type, 1 );
     
-    MBRange range;
-    rval = moab.get_entities_by_type( set, type, range, true );
+    Range range;
+    rval = mb.get_entities_by_type( set, type, range, true );
     if (MB_SUCCESS != rval) return rval;
-    for (MBRange::iterator i = range.begin(); i != range.end(); ++i)
+    for (Range::iterator i = range.begin(); i != range.end(); ++i)
     {
-      rval = moab.get_connectivity( &*i, 1, conn, true );
+      rval = mb.get_connectivity( &*i, 1, conn, true );
       if (MB_SUCCESS != rval) return rval;
       coords.resize( 3*conn.size() );
-      rval = moab.get_coords( &conn[0], conn.size(), &coords[0] );
+      rval = mb.get_coords( &conn[0], conn.size(), &coords[0] );
       if (MB_SUCCESS != rval) return rval;
       stats.stats[type].add( measure( type, conn.size(), &coords[0] ) );
       
@@ -207,7 +209,7 @@
   if (count_width < node_count_width)
     count_width = node_count_width;
   
-  for (MBEntityType i = MBEDGE; i < MBMAXTYPE; ++i)
+  for (EntityType i = MBEDGE; i < MBMAXTYPE; ++i)
   {
     stat_set& s = (i == MBMAXTYPE) ? stats.edge_uses : stats.stats[i];
 
@@ -285,7 +287,7 @@
   printf( "%*s ", val_width, dashes(val_width) );
   printf( "%*s\n", val_width, dashes(val_width) );
   
-  for (MBEntityType i = MBEDGE; i <= MBMAXTYPE; ++i)
+  for (EntityType i = MBEDGE; i <= MBMAXTYPE; ++i)
   {
     stat_set& s = (i == MBMAXTYPE) ? stats.edge_uses : stats.stats[i];
     
@@ -355,7 +357,7 @@
        f != file_list.end(); ++f)
   {
     printf("File %s:\n", f->c_str() );
-    if (MB_SUCCESS != moab.load_mesh( f->c_str(), 0, 0 ))
+    if (MB_SUCCESS != mb.load_mesh( f->c_str(), 0, 0 ))
     {
       fprintf(stderr, "Error reading file: %s\n", f->c_str() );
       return 1;
@@ -373,9 +375,9 @@
     
     if (geom_owners)
     {
-      MBRange entities;
-      MBTag dim_tag = 0, id_tag = 0;
-      MBErrorCode rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, dim_tag );
+      Range entities;
+      Tag dim_tag = 0, id_tag = 0;
+      ErrorCode rval = mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, dim_tag );
       if (MB_TAG_NOT_FOUND == rval) 
       {
         fprintf( stderr, "No geometry tag defined.\n" );
@@ -386,7 +388,7 @@
         return 2;
       }
       
-      rval = moab.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
+      rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
       if (MB_TAG_NOT_FOUND == rval) 
       {
         fprintf( stderr, "No ID tag defined.\n" );
@@ -399,7 +401,7 @@
       
       if (dim_tag && id_tag)
       {
-        if (MB_SUCCESS != moab.get_entities_by_type_and_tag( 0, 
+        if (MB_SUCCESS != mb.get_entities_by_type_and_tag( 0, 
                                                         MBENTITYSET, 
                                                         &dim_tag,
                                                         0,
@@ -415,11 +417,11 @@
         fprintf( stderr, "No geometry entities defined in file.\n" );
       }
       
-      for (MBRange::iterator i = entities.begin(); i != entities.end(); ++i)
+      for (Range::iterator i = entities.begin(); i != entities.end(); ++i)
       {
         int id = 0, dim = 0;
-        if (MB_SUCCESS != moab.tag_get_data( dim_tag, &*i, 1, &dim ) ||
-            MB_SUCCESS != moab.tag_get_data(  id_tag, &*i, 1,  &id ))
+        if (MB_SUCCESS != mb.tag_get_data( dim_tag, &*i, 1, &dim ) ||
+            MB_SUCCESS != mb.tag_get_data(  id_tag, &*i, 1,  &id ))
         {
           fprintf( stderr, "Error retreiving tag data for geometry entity.\n");
           continue;
@@ -443,9 +445,9 @@
     {
       for (int t = 0; t < 3; ++t)
       {
-        MBRange entities;
-        MBTag tag = 0;
-        MBErrorCode rval = moab.tag_get_handle( mesh_type_tags[t], tag );
+        Range entities;
+        Tag tag = 0;
+        ErrorCode rval = mb.tag_get_handle( mesh_type_tags[t], tag );
         if (MB_TAG_NOT_FOUND == rval) 
         {
           continue;
@@ -456,7 +458,7 @@
           return 2;
         }
       
-        if (MB_SUCCESS != moab.get_entities_by_type_and_tag( 0, 
+        if (MB_SUCCESS != mb.get_entities_by_type_and_tag( 0, 
                                                         MBENTITYSET, 
                                                         &tag,
                                                         0,
@@ -467,10 +469,10 @@
           continue;
         }
       
-        for (MBRange::iterator i = entities.begin(); i != entities.end(); ++i)
+        for (Range::iterator i = entities.begin(); i != entities.end(); ++i)
         {
           int id = 0;
-          if (MB_SUCCESS != moab.tag_get_data( tag, &*i, 1, &id ))
+          if (MB_SUCCESS != mb.tag_get_data( tag, &*i, 1, &id ))
           {
             fprintf( stderr, "Error retreiving tag data for %s entity.\n", mesh_type_names[t]);
             continue;
@@ -486,11 +488,11 @@
       }
     }
 
-    if (just_list) moab.list_entities(0, 1);
+    if (just_list) mb.list_entities(0, 1);
    
-    if (just_list_basic) moab.list_entities(0, 0);
+    if (just_list_basic) mb.list_entities(0, 0);
     
-    moab.delete_mesh();
+    mb.delete_mesh();
   }
   
   if (file_list.size() > 1)

Modified: MOAB/trunk/tools/skin.cpp
===================================================================
--- MOAB/trunk/tools/skin.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/skin.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -12,14 +12,16 @@
 #include <sys/stat.h>
 #endif
 #include <fcntl.h>
-#include "MBInterface.hpp"
-#include "MBTagConventions.hpp"
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBSkinner.hpp"
-#include "MBAdaptiveKDTree.hpp"
-#include "MBCN.hpp"
+#include "moab/Interface.hpp"
+#include "moab/MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/Skinner.hpp"
+#include "moab/AdaptiveKDTree.hpp"
+#include "moab/MBCN.hpp"
 
+using namespace moab;
+
 void get_time_mem(double &tot_time, double &tot_mem);
 
 // Different platforms follow different conventions for usage
@@ -40,8 +42,8 @@
  std::cerr << "Internal error at line " << __LINE__ << std::endl; \
  return 3; } } while(false)
 
-MBErrorCode merge_duplicate_vertices( MBInterface&, double epsilon );
-MBErrorCode min_edge_length( MBInterface&, double& result );
+ErrorCode merge_duplicate_vertices( Interface&, double epsilon );
+ErrorCode min_edge_length( Interface&, double& result );
 
 void usage( const char* argv0, bool help = false ) 
 {
@@ -146,9 +148,9 @@
   }
 
   
-  MBErrorCode result;
-  MBCore mbimpl;
-  MBInterface* iface = &mbimpl;
+  ErrorCode result;
+  Core mbimpl;
+  Interface* iface = &mbimpl;
   
   if (print_perf) {
     double tmp_time1, tmp_mem1;
@@ -188,7 +190,7 @@
   
     // get entities of largest dimension
   int dim = 4;
-  MBRange entities;
+  Range entities;
   while (entities.empty() && dim > 1)
   {
     dim--;
@@ -196,8 +198,8 @@
     CHKERROR(result);
   }
 
-  MBRange skin_ents;
-  MBTag matset_tag = 0, neuset_tag = 0;
+  Range skin_ents;
+  Tag matset_tag = 0, neuset_tag = 0;
   result = iface->tag_get_handle(MATERIAL_SET_TAG_NAME, matset_tag);
   result = iface->tag_get_handle(NEUMANN_SET_TAG_NAME, neuset_tag);
 
@@ -212,7 +214,7 @@
     for (std::vector<int>::iterator vit = matsets.begin(); vit != matsets.end(); vit++) {
       int this_matset = *vit;
       const void *this_matset_ptr = &this_matset;
-      MBRange this_range, ent_range;
+      Range this_range, ent_range;
       result = iface->get_entities_by_type_and_tag(0, MBENTITYSET, &matset_tag,
                                                     &this_matset_ptr, 1, this_range);
       if (MB_SUCCESS != result) {
@@ -237,7 +239,7 @@
 
   if (use_vert_elem_adjs) {
       // make a call which we know will generate vert-elem adjs
-    MBRange dum_range;
+    Range dum_range;
     result = iface->get_adjacencies(&(*skin_ents.begin()), 1, 1, false,
                                     dum_range);
   }
@@ -250,10 +252,10 @@
   }
 
     // skin the mesh
-  MBRange forward_lower, reverse_lower;
-  MBSkinner tool( iface );
+  Range forward_lower, reverse_lower;
+  Skinner tool( iface );
   result = tool.find_skin( skin_ents, false, forward_lower, &reverse_lower );
-  MBRange boundary;
+  Range boundary;
   boundary.merge( forward_lower );
   boundary.merge( reverse_lower );
   if (MB_SUCCESS != result || boundary.empty())
@@ -264,12 +266,12 @@
 
   if (write_tag) {
       // get tag handle
-    MBTag tag;
+    Tag tag;
     result = iface->tag_get_handle( fixed_tag, tag );
     if (result == MB_SUCCESS)
     {
       int size;
-      MBDataType type;
+      DataType type;
       iface->tag_get_size(tag, size);
       iface->tag_get_data_type(tag, type);
     
@@ -292,8 +294,8 @@
   
       // Set tags
     std::vector<int> ones;
-    MBRange bverts;
-    result = iface->get_adjacencies(boundary, 0, false, bverts, MBInterface::UNION);
+    Range bverts;
+    result = iface->get_adjacencies(boundary, 0, false, bverts, Interface::UNION);
     if (MB_SUCCESS != result) {
       std::cerr << "Trouble getting vertices on boundary." << std::endl;
       return 1;
@@ -313,7 +315,7 @@
     
 
       // always create a forward neumann set, assuming we have something in the set
-    MBEntityHandle forward_neuset = 0;
+    EntityHandle forward_neuset = 0;
     result = iface->create_meshset(MESHSET_SET, forward_neuset);
     if (MB_SUCCESS != result || 0 == forward_neuset) return 1;
     result = iface->tag_set_data(neuset_tag, &forward_neuset, 1, &neuset_num);
@@ -324,13 +326,13 @@
       if (MB_SUCCESS != result) return 1;
     }
     if (!reverse_lower.empty()) {
-      MBEntityHandle reverse_neuset = 1;
+      EntityHandle reverse_neuset = 1;
       result = iface->create_meshset(MESHSET_SET, reverse_neuset);
       if (MB_SUCCESS != result || 0 == forward_neuset) return 1;
 
       result = iface->add_entities(reverse_neuset, reverse_lower);
       if (MB_SUCCESS != result) return 1;
-      MBTag sense_tag;
+      Tag sense_tag;
       result = iface->tag_get_handle("SENSE", sense_tag);
       if (result == MB_TAG_NOT_FOUND) {
         int dum_sense = 0;
@@ -358,7 +360,7 @@
   }
   else if (NULL != output_file) {
       // write only skin; write them as one set
-    MBEntityHandle skin_set;
+    EntityHandle skin_set;
     result = iface->create_meshset(MESHSET_SET, skin_set);
     if (MB_SUCCESS != result) return 1;
     result = iface->add_entities(skin_set, forward_lower);
@@ -366,7 +368,7 @@
     result = iface->add_entities(skin_set, reverse_lower);
     if (MB_SUCCESS != result) return 1;
 
-    MBRange this_range, ent_range;
+    Range this_range, ent_range;
     result = iface->get_entities_by_type_and_tag(0, MBENTITYSET, &matset_tag,
                                                   NULL, 0, this_range);
     if (!this_range.empty()) iface->delete_entities(this_range);
@@ -459,23 +461,23 @@
   
   
   
-MBErrorCode min_edge_length( MBInterface& moab, double& result )
+ErrorCode min_edge_length( Interface& moab, double& result )
 {
   double sqr_result = std::numeric_limits<double>::max();
   
-  MBErrorCode rval;
-  MBRange entities;
+  ErrorCode rval;
+  Range entities;
   rval = moab.get_entities_by_handle( 0, entities );
   if (MB_SUCCESS != rval) return rval;
-  MBRange::iterator i = entities.upper_bound( MBVERTEX );
+  Range::iterator i = entities.upper_bound( MBVERTEX );
   entities.erase( entities.begin(), i );
   i = entities.lower_bound( MBENTITYSET );
   entities.erase( i, entities.end() );
   
-  std::vector<MBEntityHandle> storage;
+  std::vector<EntityHandle> storage;
   for (i = entities.begin(); i != entities.end(); ++i) {
-    MBEntityType t = moab.type_from_handle( *i );
-    const MBEntityHandle* conn;
+    EntityType t = moab.type_from_handle( *i );
+    const EntityHandle* conn;
     int conn_len, indices[2];
     rval = moab.get_connectivity( *i, conn, conn_len, true, &storage );
     if (MB_SUCCESS != rval) return rval;
@@ -483,7 +485,7 @@
     int num_edges = MBCN::NumSubEntities( t, 1 );
     for (int j = 0; j < num_edges; ++j) {
       MBCN::SubEntityVertexIndices( t, 1, j, indices );
-      MBEntityHandle v[2] = { conn[indices[0]], conn[indices[1]] };
+      EntityHandle v[2] = { conn[indices[0]], conn[indices[1]] };
       if (v[0] == v[1])
         continue;
       
@@ -506,25 +508,25 @@
   
   
   
-MBErrorCode merge_duplicate_vertices( MBInterface& moab, const double epsilon )
+ErrorCode merge_duplicate_vertices( Interface& moab, const double epsilon )
 {
-  MBErrorCode rval;
-  MBRange verts;
+  ErrorCode rval;
+  Range verts;
   rval = moab.get_entities_by_type( 0, MBVERTEX, verts );
   if (MB_SUCCESS != rval)
     return rval;
   
-  MBAdaptiveKDTree tree( &moab );
-  MBEntityHandle root;
+  AdaptiveKDTree tree( &moab );
+  EntityHandle root;
   rval = tree.build_tree( verts, root );
   if (MB_SUCCESS != rval) {
     fprintf(stderr,"Failed to build kD-tree.\n");
     return rval;
   }
   
-  std::set<MBEntityHandle> dead_verts;
-  std::vector<MBEntityHandle> leaves;
-  for (MBRange::iterator i = verts.begin(); i != verts.end(); ++i) {
+  std::set<EntityHandle> dead_verts;
+  std::vector<EntityHandle> leaves;
+  for (Range::iterator i = verts.begin(); i != verts.end(); ++i) {
     double coords[3];
     rval = moab.get_coords( &*i, 1, coords );
     if (MB_SUCCESS != rval) return rval;
@@ -533,21 +535,21 @@
     rval = tree.leaves_within_distance( root, coords, epsilon, leaves );
     if (MB_SUCCESS != rval) return rval;
     
-    MBRange near;
-    for (std::vector<MBEntityHandle>::iterator j = leaves.begin(); j != leaves.end(); ++j) {
-      MBRange tmp;
+    Range near;
+    for (std::vector<EntityHandle>::iterator j = leaves.begin(); j != leaves.end(); ++j) {
+      Range tmp;
       rval = moab.get_entities_by_type( *j, MBVERTEX, tmp );
       if (MB_SUCCESS != rval)
         return rval;
       near.merge( tmp.begin(), tmp.end() );
     }
     
-    MBRange::iterator v = near.find( *i );
+    Range::iterator v = near.find( *i );
     assert( v != near.end() );
     near.erase( v );
     
-    MBEntityHandle merge = 0;
-    for (MBRange::iterator j = near.begin(); j != near.end(); ++j) {
+    EntityHandle merge = 0;
+    for (Range::iterator j = near.begin(); j != near.end(); ++j) {
       if (*j < *i && dead_verts.find( *j ) != dead_verts.end())
         continue;
       

Copied: MOAB/trunk/tools/sphere_decomp.cpp (from rev 3583, MOAB/trunk/tools/main.cpp)
===================================================================
--- MOAB/trunk/tools/sphere_decomp.cpp	                        (rev 0)
+++ MOAB/trunk/tools/sphere_decomp.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -0,0 +1,52 @@
+/*
+ * Sphere decomp tool.  Meshes a group of spheres and the interstices between with
+ * hex elements, by triangulating the vertices corresponding to sphere centers
+ * and subdividing those tets.  For a description of the subdivision template used,
+ * see comments in the subdivide_tet function below.
+ */
+
+#include "moab/Core.hpp"
+#include "SphereDecomp.hpp"
+#include <iostream>
+
+const char *SPHERE_RADII_TAG_NAME = "SPHERE_RADII";
+
+#define RR if (moab::MB_SUCCESS != result) return result
+
+int main(int argc, char *argv[]) 
+{
+  if (argc < 3) {
+    std::cout << "Usage: " << argv[0] << " <input_mesh> <output_mesh>" << std::endl;
+    return 0;
+  }
+  
+    // create MOAB
+  moab::Interface *mbImpl = new moab::Core();
+  
+    // read in mesh
+  moab::ErrorCode result = mbImpl->load_mesh(argv[1]); 
+  if (moab::MB_SUCCESS != result) {
+    std::cout << "Problems loading mesh." << std::endl;
+    return 1;
+  }
+
+  moab::Tag sphere_radii_tag = 0;
+  double dum_val = 0.1;
+  result = mbImpl->tag_create(SPHERE_RADII_TAG_NAME, sizeof(double), 
+                              moab::MB_TAG_DENSE, moab::MB_TYPE_DOUBLE, sphere_radii_tag, &dum_val); 
+  if (moab::MB_SUCCESS != result && moab::MB_ALREADY_ALLOCATED != result) {
+    std::cout << "Problem allocating SPHERE_RADII tag." << std::endl;
+    return 1;
+  }
+
+  SphereDecomp sd(mbImpl);
+
+  moab::EntityHandle this_set = 0;
+  result = sd.build_sphere_mesh(SPHERE_RADII_TAG_NAME, &this_set); RR;
+  
+    // write mesh
+  result = mbImpl->write_mesh(argv[2], &this_set, 1); RR;
+  
+  return 0;
+}
+


Property changes on: MOAB/trunk/tools/sphere_decomp.cpp
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:mergeinfo
   + 
Added: svn:eol-style
   + native

Modified: MOAB/trunk/tools/surfplot.cpp
===================================================================
--- MOAB/trunk/tools/surfplot.cpp	2010-03-12 19:25:45 UTC (rev 3603)
+++ MOAB/trunk/tools/surfplot.cpp	2010-03-12 21:30:42 UTC (rev 3604)
@@ -1,6 +1,6 @@
-#include "MBCore.hpp"
-#include "MBRange.hpp"
-#include "MBTagConventions.hpp"
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/MBTagConventions.hpp"
 #include <iostream>
 #include <fstream>
 #include <limits>
@@ -168,10 +168,12 @@
   SVG
 };
 
+using namespace moab;
+
 int main(int argc, char* argv[])
 {
-  MBInterface* moab = new MBCore();
-  MBErrorCode result;
+  Interface* moab = new Core();
+  ErrorCode result;
   std::vector<CartVect3D>::iterator iter;
   FileType type = GNUPLOT;
 
@@ -212,7 +214,7 @@
   }
   
     // Get tag handles
-  MBTag tags[2];
+  Tag tags[2];
   result = moab->tag_get_handle( GEOM_DIMENSION_TAG_NAME, tags[0] );
   if (MB_SUCCESS != result) {
     std::cerr << "No geometry tag.\n";
@@ -227,7 +229,7 @@
     // Find entityset for surface.
   int dimension = 2; // surface
   const void* tag_values[] = { &dimension, &surface_id };
-  MBRange surfaces;
+  Range surfaces;
   moab->get_entities_by_type_and_tag( 0, MBENTITYSET,
                                       tags, tag_values,
                                       2, surfaces );
@@ -237,10 +239,10 @@
               << std::endl;
     return SURFACE_NOT_FOUND;
   }
-  MBEntityHandle surface = *surfaces.begin();
+  EntityHandle surface = *surfaces.begin();
   
     // Get surface mesh
-  MBRange elements;
+  Range elements;
   result = moab->get_entities_by_dimension( surface, dimension, elements );
   if (MB_SUCCESS != result) {
     std::cerr << "Internal error\n";
@@ -249,9 +251,9 @@
   
     // Calculate average corner normal in surface mesh
   CartVect3D normal(0,0,0);
-  std::vector<MBEntityHandle> vertices;
+  std::vector<EntityHandle> vertices;
   std::vector<CartVect3D> coords;
-  for (MBRange::iterator i = elements.begin(); i != elements.end(); ++i)
+  for (Range::iterator i = elements.begin(); i != elements.end(); ++i)
   {
     vertices.clear();
     result = moab->get_connectivity( &*i, 1, vertices, true );
@@ -278,15 +280,15 @@
 
   
     // Get edges from elements
-  MBRange edge_range;
-  result = moab->get_adjacencies( elements, 1, true, edge_range, MBInterface::UNION );
+  Range edge_range;
+  result = moab->get_adjacencies( elements, 1, true, edge_range, Interface::UNION );
   if (MB_SUCCESS != result) {
     std::cerr << "Internal error\n";
     return OTHER_ERROR;
   }
   
     // Get vertex coordinates for each edge
-  std::vector<MBEntityHandle> edges( edge_range.size() );
+  std::vector<EntityHandle> edges( edge_range.size() );
   std::copy( edge_range.begin(), edge_range.end(), edges.begin() );
   vertices.clear();
   result = moab->get_connectivity( &edges[0], edges.size(), vertices, true );



More information about the moab-dev mailing list