[MOAB-dev] r1251 - in MOAB/trunk: . tools/converter

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Fri Aug 24 12:16:31 CDT 2007


Author: kraftche
Date: 2007-08-24 12:16:31 -0500 (Fri, 24 Aug 2007)
New Revision: 1251

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/MBInterface.hpp
   MOAB/trunk/MBReaderWriterSet.cpp
   MOAB/trunk/MBReaderWriterSet.hpp
   MOAB/trunk/tools/converter/convert.cpp
Log:
o Add new FILE I/O API - not all features implemented yet
o Record a name for each known file format
o Implement specification of output file type by format name
o Add "-f <format>" flag to mbconvert





Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/MBCore.cpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -55,6 +55,7 @@
 #include "MBTagConventions.hpp"
 #include "ExoIIUtil.hpp"
 #include "EntitySequence.hpp"
+#include "FileOptions.hpp"
 #ifdef LINUX
 # include <dlfcn.h>
 # include <dirent.h>
@@ -324,9 +325,36 @@
                                 const int* block_id_list,
                                 const int num_blocks )
 {
+  MBEntityHandle file_set;
+  return load_file( file_name, file_set, 0, MATERIAL_SET_TAG_NAME, block_id_list, num_blocks );
+}
+
+MBErrorCode MBCore::load_file( const char* file_name,
+                               MBEntityHandle& file_set,
+                               const char* options,
+                               const char* set_tag_name,
+                               const int* set_tag_values,
+                               int num_set_tag_values )
+{
+  if (num_set_tag_values < 0)
+    return MB_INDEX_OUT_OF_RANGE;
+   
+    // feature not implemented yet
+  file_set = 0;
+  
   MBErrorCode rval;
   const MBReaderWriterSet* set = reader_writer_set();
   
+    // convert from to old block-based reader interface
+  const int* block_id_list = 0;
+  int num_blocks = 0;
+  if (set_tag_name) {
+    if (strcmp(set_tag_name, MATERIAL_SET_TAG_NAME ))
+      return MB_NOT_IMPLEMENTED;
+    block_id_list = set_tag_values;
+    num_blocks = num_set_tag_values;
+  }
+  
     // Try using the file extension to select a reader
   MBReaderIface* reader = set->get_file_extension_reader( file_name );
   if (reader)
@@ -337,7 +365,7 @@
   }
   
     // Try all the readers
-  MBReaderWriterSet::iter_type iter;
+  MBReaderWriterSet::iterator iter;
   for (iter = set->begin(); iter != set->end(); ++iter)
   {
     MBReaderIface* reader = iter->make_reader( this );
@@ -352,34 +380,86 @@
 
   return MB_FAILURE; 
 }
+  
 
+
 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;
-  const MBReaderWriterSet* set = reader_writer_set();
-  std::vector<std::string> qa_records;
-  const bool overwrite = true;
+  
+  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);
 
-  MBWriterIface* writer = set->get_file_extension_writer( file_name );
-  if (writer == NULL)
-  {
-    DefaultWriter exowriter(this);
-    rval = exowriter.write_file(file_name, overwrite, output_list, num_sets, qa_records, 0);
+    // 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
-  {
-    rval = writer->write_file(file_name, overwrite, output_list, num_sets, qa_records );
-    delete writer;
+    writer = i->make_writer( this );
+  
+  if (!writer) {
+    mError->set_last_error( "File format supported for reading only.\n" );
+    return MB_NOT_IMPLEMENTED;
   }
   
-  return rval; 
+    // write the file
+  std::vector<std::string> qa_records;
+  rval = writer->write_file(file_name, overwrite, &list[0], list.size(), qa_records );
+  delete writer;
+  
+  return rval;
 }
+   
+  
 
-
-
-
 //! deletes all mesh entities from this datastore
 MBErrorCode MBCore::delete_mesh()
 {

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/MBCore.hpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -87,11 +87,35 @@
   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,
+                                 MBEntityHandle& file_set,
+                                 const char* options = 0,
+                                 const char* set_tag_name = 0,
+                                 const int* set_tag_values = 0,
+                                 int num_set_tag_values = 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();
 
@@ -816,6 +840,7 @@
     //! return set of registered IO tools
   MBReaderWriterSet* reader_writer_set() { return readerWriterSet; }
 
+  MBError* get_error_handler() { return mError; }
 
 //-----------------MeshSet Interface Functions------------------//
 

Modified: MOAB/trunk/MBInterface.hpp
===================================================================
--- MOAB/trunk/MBInterface.hpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/MBInterface.hpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -167,30 +167,66 @@
     //@{
 
     //! 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.
+    /** 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 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 
+        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.  Typical options
+   *               include the file type, parallel options, and options
+   *               specific to certain file formats.
+   *\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,
+                                 MBEntityHandle& file_set,
+                                 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.
+    /** 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 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
@@ -201,6 +237,70 @@
                                  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;
 

Modified: MOAB/trunk/MBReaderWriterSet.cpp
===================================================================
--- MOAB/trunk/MBReaderWriterSet.cpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/MBReaderWriterSet.cpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -46,40 +46,31 @@
   : mbCore( mdb ), mbError( handler ) 
 {
 #ifdef HDF5_FILE
-  const char* hdf5_list[] = { "h5m", "mhdf", NULL };
-  register_factory(  ReadHDF5::factory, WriteHDF5::factory, "MOAB native (HDF5)", hdf5_list );
+  const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
+  register_factory(  ReadHDF5::factory, WriteHDF5::factory, "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
 #endif
 
 #ifdef NETCDF_FILE
-  const char* exo_list[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
-  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_list );
+  const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
+  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
 #endif
   
-  const char* vtk_list[] = { "vtk", NULL };
-  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", vtk_list );
+  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );
   
-  const char* cub_list[] = { "cub", NULL };
-  register_factory( Tqdcfr::factory, NULL, "Cubit", cub_list );
+  register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );
 
 #ifdef NETCDF_FILE  
-  const char* slac_list[] = { "slac", NULL };
-  register_factory( NULL, WriteSLAC::factory, "SLAC", slac_list );
+  register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
 #endif
 
-  const char* gmv_list[] = { "gmv", NULL };
-  register_factory( NULL, WriteGMV::factory, "GMV", gmv_list );
+  register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );
   
-  const char* ans_list[] = { "ans", NULL };
-  register_factory( NULL, WriteAns::factory, "Ansys", ans_list );
+  register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );
   
-  const char* gmsh_list[] = { "msh", "gmsh", NULL };
-  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_list );
+  const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
+  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );
   
-  const char* stl_list[] = { "stl", NULL };
-  register_factory( ReadSTL::ascii_instance, WriteSTL::ascii_instance, "Stereo Lithography File (STL)", stl_list );
-  
-  const char* stlb_list[] = { "stlb", NULL };
-  register_factory( ReadSTL::binary_instance, WriteSTL::binary_instance, "Binary Stereo Lithography (STL)", stlb_list );
+  register_factory( ReadSTL::ascii_instance, WriteSTL::ascii_instance, "Stereo Lithography File (STL)", "stl", "STL" );
 }
 
 
@@ -90,16 +81,17 @@
 MBErrorCode MBReaderWriterSet::register_factory( reader_factory_t reader,
                                                  writer_factory_t writer,
                                                  const char* description,
-                                                 const char** extensions )
+                                                 const char* const* extensions,
+                                                 const char* name )
 {
   if (!reader && !writer)
     return MB_FAILURE;
   
     // count extensions and check for duplicates
-  const char** iter;
+  const char* const* iter;
   for (iter = extensions; *iter; ++iter)
   {
-    iter_type h = handler_from_extension( *iter );
+    iterator h = handler_from_extension( *iter );
     if (h != end())
     {
       if (NULL != reader && h->have_reader())
@@ -112,15 +104,26 @@
                                  *iter, h->description().c_str(), description );
     }
   }
-  handlerList.push_back( Handler(reader, writer, description, extensions, iter - extensions) );
+  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 );
-  iter_type handler = handler_from_extension( ext, true, false );
+  iterator handler = handler_from_extension( ext, true, false );
   return handler == end() ? NULL : handler->make_reader(mbCore);
 }
 
@@ -128,7 +131,7 @@
                                   const std::string& filename ) const
 {
   std::string ext = extension_from_filename( filename );
-  iter_type handler = handler_from_extension( ext, false, true );
+  iterator handler = handler_from_extension( ext, false, true );
   return handler == end() ? NULL : handler->make_writer(mbCore);
 }
 
@@ -144,10 +147,11 @@
 
 MBReaderWriterSet::Handler::Handler( reader_factory_t read_f, 
                                      writer_factory_t write_f,
+                                     const char* name,
                                      const char* desc, 
-                                     const char** ext, 
+                                     const char* const* ext, 
                                      int num_ext )
- : mReader(read_f), mWriter(write_f), mDescription(desc), mExtensions(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];
@@ -157,12 +161,12 @@
 #define strcasecmp(A,B) _stricmp( A, B )
 #endif
 
-MBReaderWriterSet::iter_type 
+MBReaderWriterSet::iterator 
 MBReaderWriterSet::handler_from_extension( const std::string& ext,
                                            bool with_reader,
                                            bool with_writer ) const
 {
-  iter_type iter;
+  iterator iter;
   std::vector<std::string>::const_iterator siter;
   
     // try case-sensitive compare
@@ -191,4 +195,21 @@
   
   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';
+}
+
+

Modified: MOAB/trunk/MBReaderWriterSet.hpp
===================================================================
--- MOAB/trunk/MBReaderWriterSet.hpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/MBReaderWriterSet.hpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -53,12 +53,19 @@
      *\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** extensions );
-    
+                                  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.
@@ -75,6 +82,20 @@
      */
     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
      */
@@ -88,10 +109,12 @@
       
       Handler( reader_factory_t read_f,
                writer_factory_t write_f,
+               const char* name,
                const char* desc, 
-               const char** ext, 
+               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; }
@@ -105,26 +128,30 @@
       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 mDescription;
+      std::string mName, mDescription;
       std::vector<std::string> mExtensions;
     };
     
-    typedef std::list<Handler>::const_iterator iter_type;
+    typedef std::list<Handler>::const_iterator iterator;
     
-    inline iter_type begin() const { return handlerList.begin(); }
+    inline iterator begin() const { return handlerList.begin(); }
     
-    inline iter_type end()   const { return handlerList.end();   }
+    inline iterator end()   const { return handlerList.end();   }
     
     
-    iter_type handler_from_extension( const std::string& extension,
+    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;

Modified: MOAB/trunk/tools/converter/convert.cpp
===================================================================
--- MOAB/trunk/tools/converter/convert.cpp	2007-08-23 20:29:06 UTC (rev 1250)
+++ MOAB/trunk/tools/converter/convert.cpp	2007-08-24 17:16:31 UTC (rev 1251)
@@ -48,7 +48,8 @@
 void print_usage( const char* name, std::ostream& stream )
 {
   stream << "Usage: " << name << 
-    " [-a <sat_file>|-A] [-t] [subset options] <input_file> <output_file>" << std::endl
+    " [-a <sat_file>|-A] [-t] [subset options] [-f format] <input_file> <output_file>" << std::endl
+    << "\t-f <format>    - Specify output file format" << std::endl
     << "\t-a <acis_file> - ACIS SAT file dumped by .cub reader" << std::endl
     << "\t-A             - .cub file reader should not dump a SAT file" << std::endl
     << "\t-t             - Time read and write of files." << std::endl
@@ -125,6 +126,7 @@
 
   int i, dim;
   bool dims[4] = {false, false, false, false};
+  const char* format = NULL; // output file format
   const char* in = NULL;    // input file name
   const char* out = NULL;   // output file name
   const char* acis = NULL;  // file to which to write geom data from .cub files.
@@ -186,6 +188,7 @@
           pval = false;
           switch ( argv[i-1][1] )
           {
+            case 'f': format = argv[i]; pval = true;            break;
             case 'a': acis = argv[i]; pval = true;              break;
             case 'v': pval = parse_id_list( argv[i], geom[3] ); break;
             case 's': pval = parse_id_list( argv[i], geom[2] ); break;
@@ -464,10 +467,10 @@
   
     // Write the output file
   reset_times();
-  if (have_sets)
-    result = gMB->write_mesh( out, &set_list[0], set_list.size() );
+  if (have_sets) 
+    result = gMB->write_file( out, format, 0, &set_list[0], set_list.size() );
   else
-    result = gMB->write_mesh( out );
+    result = gMB->write_file( out, format );
   if (MB_SUCCESS != result)
   { 
     std::cerr << "Failed to write \"" << out << "\"." << std::endl; 
@@ -632,7 +635,7 @@
   MBErrorCode err;
   void* void_ptr = 0;
   MBReaderWriterSet* set;
-  MBReaderWriterSet::iter_type i;
+  MBReaderWriterSet::iterator i;
   std::ostream& str = std::cout;
     
     // get MBReaderWriterSet
@@ -651,9 +654,9 @@
       w = i->description().length();
   
     // write table header
-  str << std::setw(w) << std::left << "Format"
+  str << "Format  " << std::setw(w) << std::left << "Description"
       << "  Read  Write  File Name Suffixes\n"
-      << std::setw(w) << std::setfill('-') << "" << std::setfill(' ')
+      << "------  " << std::setw(w) << std::setfill('-') << "" << std::setfill(' ')
       << "  ----  -----  ------------------\n";
       
     // write table data
@@ -661,7 +664,8 @@
   {
     std::vector<std::string> ext;
     i->get_extensions( ext );
-    str << std::setw(w) << std::left << i->description() << "  "
+    str << std::setw(6) << i->name() << "  " 
+        << std::setw(w) << std::left << i->description() << "  "
         << (i->have_reader() ?  " yes" :  "  no") << "  "
         << (i->have_writer() ? "  yes" : "   no") << " ";
     for (std::vector<std::string>::iterator j = ext.begin(); j != ext.end(); ++j)




More information about the moab-dev mailing list