[MOAB-dev] r1255 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Fri Aug 24 18:03:49 CDT 2007


Author: kraftche
Date: 2007-08-24 18:03:49 -0500 (Fri, 24 Aug 2007)
New Revision: 1255

Modified:
   MOAB/trunk/FileOptions.cpp
   MOAB/trunk/FileOptions.hpp
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBReaderIface.hpp
   MOAB/trunk/MBReaderWriterSet.cpp
   MOAB/trunk/MBWriterIface.hpp
   MOAB/trunk/ReadGmsh.cpp
   MOAB/trunk/ReadGmsh.hpp
   MOAB/trunk/ReadHDF5.cpp
   MOAB/trunk/ReadHDF5.hpp
   MOAB/trunk/ReadNCDF.cpp
   MOAB/trunk/ReadNCDF.hpp
   MOAB/trunk/ReadSTL.cpp
   MOAB/trunk/ReadSTL.hpp
   MOAB/trunk/ReadVtk.cpp
   MOAB/trunk/ReadVtk.hpp
   MOAB/trunk/Tqdcfr.cpp
   MOAB/trunk/Tqdcfr.hpp
   MOAB/trunk/WriteAns.cpp
   MOAB/trunk/WriteAns.hpp
   MOAB/trunk/WriteGMV.cpp
   MOAB/trunk/WriteGMV.hpp
   MOAB/trunk/WriteGmsh.cpp
   MOAB/trunk/WriteGmsh.hpp
   MOAB/trunk/WriteHDF5.cpp
   MOAB/trunk/WriteHDF5.hpp
   MOAB/trunk/WriteNCDF.cpp
   MOAB/trunk/WriteNCDF.hpp
   MOAB/trunk/WriteSLAC.cpp
   MOAB/trunk/WriteSLAC.hpp
   MOAB/trunk/WriteSTL.cpp
   MOAB/trunk/WriteSTL.hpp
   MOAB/trunk/WriteTemplate.cpp
   MOAB/trunk/WriteTemplate.hpp
   MOAB/trunk/WriteVtk.cpp
   MOAB/trunk/WriteVtk.hpp
Log:
o Change behavior of FileOptions: don't remove options from the list once
  they've been processed.  Doesn't work so good for reader-specific options
  when trying all the registered readers.
o Pass FileOptions instance to all readers and writers
o Combine ReadASCIISTL and ReadBinarySTL into ReadSTL
o Combine WriteASCIISTL and WriteBinarySTL into WriteSTL.
o Get rid of made-up "stlb" file extension to request binary STL files.
  Reader can auto-detect file type.  Use option "BINARY" to file to 
  control write type (or to force read type.)
o Replace tag convention with option to control byte order for binary
  STL files.  Options are "LITTLE_ENDIAN" and "BIG_ENDIAN".  Default 
  for write is LITTLE_ENDIAN.  Default for read is auto-detect, with
  fallback to LITTLE_ENDIAN if ambiguous.
o Get rid if tag convention to control SAT file dumped by Tqdcfr.  Make
  Tqdcfr dump no SAT files by default.  Add option "SAT_FILE=<filename>"
  to request dump of SAT file.





Modified: MOAB/trunk/FileOptions.cpp
===================================================================
--- MOAB/trunk/FileOptions.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/FileOptions.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -49,32 +49,62 @@
     // input string is empty.
   if (!strempty(str))
   {
-  
-      // tokenize at separator character
+       // tokenize at separator character
     mData = strdup( str );
     for (char* i = strtok( mData, separator ); i; i = strtok( 0, separator )) 
       if (!strempty(i)) // skip empty strings
         mOptions.push_back( i );
   }
-  
-  lastOpt = mOptions.end();  
 }
 
+FileOptions::FileOptions( const FileOptions& copy ) :
+  mData(0), mOptions( copy.mOptions.size() )
+{
+  if (!copy.mOptions.empty()) {
+    const char* last = copy.mOptions.back();
+    const char* endptr = last + strlen(last) + 1;
+    size_t len = endptr - copy.mData;
+    mData = (char*)malloc( len );
+    memcpy( mData, copy.mData, len );
+    for (size_t i = 0; i < mOptions.size(); ++i)
+      mOptions[i] = mData + (copy.mOptions[i] - copy.mData);
+  }
+}
+
+FileOptions& FileOptions::operator=( const FileOptions& copy )
+{
+  free( mData );
+  mData = 0;
+  mOptions.resize( copy.mOptions.size() );
+
+  if (!copy.mOptions.empty()) {
+    const char* last = copy.mOptions.back();
+    const char* endptr = last + strlen(last) + 1;
+    size_t len = endptr - copy.mData;
+    mData = (char*)malloc( len );
+    memcpy( mData, copy.mData, len );
+    for (size_t i = 0; i < mOptions.size(); ++i)
+      mOptions[i] = mData + (copy.mOptions[i] - copy.mData);
+  }
+    
+  return *this;
+}
+
 FileOptions::~FileOptions()
 {
   free( mData );
 }
 
-MBErrorCode FileOptions::get_null_option( const char* name, bool remove )
+MBErrorCode FileOptions::get_null_option( const char* name ) const
 {
   const char* s;
   MBErrorCode rval = get_option( name, s );
   if (MB_SUCCESS != rval)
     return rval;
-  return strempty(s) ? remove_last_option(remove) : MB_TYPE_OUT_OF_RANGE;
+  return strempty(s) ? MB_SUCCESS : MB_TYPE_OUT_OF_RANGE;
 }
 
-MBErrorCode FileOptions::get_int_option( const char* name, int& value, bool remove ) 
+MBErrorCode FileOptions::get_int_option( const char* name, int& value ) const
 {
   const char* s;
   MBErrorCode rval = get_option( name, s );
@@ -96,10 +126,10 @@
   if (pval != (long int)value)
     return MB_TYPE_OUT_OF_RANGE;
   
-  return remove_last_option(remove);
+  return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_real_option ( const char* name, double& value, bool remove ) 
+MBErrorCode FileOptions::get_real_option ( const char* name, double& value ) const
 {
   const char* s;
   MBErrorCode rval = get_option( name, s );
@@ -116,10 +146,10 @@
   if (!strempty(endptr)) // syntax error
     return MB_TYPE_OUT_OF_RANGE;
   
-  return remove_last_option(remove);
+  return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_str_option( const char* name, std::string& value, bool remove )
+MBErrorCode FileOptions::get_str_option( const char* name, std::string& value ) const
 {
   const char* s;
   MBErrorCode rval = get_option( name, s );
@@ -128,10 +158,10 @@
   if (strempty(s))
     return MB_TYPE_OUT_OF_RANGE;
   value = s;
-  return remove_last_option(remove);
+  return MB_SUCCESS;
 }
 
-MBErrorCode FileOptions::get_option( const char* name, std::string& value, bool remove )
+MBErrorCode FileOptions::get_option( const char* name, std::string& value ) const
 {
   const char* s;
   MBErrorCode rval = get_option( name, s );
@@ -139,12 +169,12 @@
     return rval;
   
   value = s;
-  return remove_last_option(remove);
+  return MB_SUCCESS;
 }  
 
-MBErrorCode FileOptions::get_option( const char* name, const char*& value )
+MBErrorCode FileOptions::get_option( const char* name, const char*& value ) const
 {
-  std::vector<const char*>::iterator i;
+  std::vector<const char*>::const_iterator i;
   for (i = mOptions.begin(); i != mOptions.end(); ++i) {
     const char* opt = *i;
     if (compare( name, opt )) {
@@ -154,12 +184,10 @@
       if (*value == '=') 
         ++value;
         
-      lastOpt = i;
       return MB_SUCCESS;
     }
   }
   
-  lastOpt = mOptions.end();
   return MB_ENTITY_NOT_FOUND;
 }
 
@@ -175,17 +203,6 @@
   return strempty(name) && (strempty(option) || *option == '=');
 }
 
-
-MBErrorCode FileOptions::remove_last_option( bool doit )
-{
-  if (lastOpt == mOptions.end())
-    return MB_FAILURE;
-  if (doit)
-    mOptions.erase( lastOpt );
-  lastOpt = mOptions.end();
-  return MB_SUCCESS;
-}
-
 void FileOptions::get_options( std::vector<std::string>& list ) const
 {
   list.clear();
@@ -219,7 +236,7 @@
   MBErrorCode rval;
   
     // test basic get_option method without deleting entry
-  rval = tool.get_option( "STR1", s, false );
+  rval = tool.get_option( "STR1", s );
   CHECK(rval);
   EQUAL( s, "ABC" );
   
@@ -228,10 +245,6 @@
   CHECK(rval);
   EQUAL( s, "ABC" );
   
-    // test that the entry was removed
-  rval = tool.get_option( "STR1", s );
-  EQUAL( rval, MB_ENTITY_NOT_FOUND );
-  
     // test basig get_option method with a null option
   rval = tool.get_option( "NUL2", s );
   CHECK( rval );
@@ -243,7 +256,7 @@
   CHECK( rval );
   
     // try null option method on non-null value
-  rval = tool.get_null_option( "INT1", false) ;
+  rval = tool.get_null_option( "INT1" ) ;
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE) ;
   
 
@@ -257,11 +270,11 @@
   EQUAL( i, 2 );
   
     // test integer option on non-integer value
-  rval = tool.get_int_option( "dbl2", i, false );
+  rval = tool.get_int_option( "dbl2", i );
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
   
     // test integer option on null value
-  rval = tool.get_int_option( "NUL3", i, false );
+  rval = tool.get_int_option( "NUL3", i);
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
   
     // test double option
@@ -278,12 +291,12 @@
   EQUAL( d, 3.0 );
   
     // test real option on non-real value
-  rval = tool.get_real_option( "str2", d, false );
+  rval = tool.get_real_option( "str2", d );
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
   
   
     // test real option on null value
-  rval = tool.get_real_option( "NUL3", d, false );
+  rval = tool.get_real_option( "NUL3", d );
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
   
     // test get a simple string option
@@ -297,21 +310,11 @@
   EQUAL( s, "once upon a time" );
   
     // try to get a string value for a null option
-  rval = tool.get_str_option( "nul3", s, false );
+  rval = tool.get_str_option( "nul3", s );
   EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
   
-  
-    // should be two options still in list: NUL3 and STR3
-  bool e = tool.empty();
-  EQUAL( e, false );
-  unsigned l = tool.size();
-  EQUAL( l, 2u );
-  std::vector<std::string> list;
-  tool.get_options( list );
-  EQUAL( list[0], "NUL3" );
-  EQUAL( list[1], "str3==fubar=" );
-  
-    // remove remaining options
+    // test options using generic get_option method
+    
   rval = tool.get_option( "NUL3", s );
   CHECK( rval );
   EQUAL( s.empty(), true );
@@ -320,15 +323,9 @@
   CHECK( rval );
   EQUAL( s, "=fubar=" );
   
-    // should be no remaining options
-  e = tool.empty();
-  EQUAL( e, true );
-  l = tool.size();
-  EQUAL( l, 0 );
-  list.clear();
-  tool.get_options( list );
-  e = list.empty();
-  EQUAL( e, true );
+    // test size of options string
+  unsigned l = tool.size();
+  EQUAL( l, 12u );
   
   
     // test alternate separator
@@ -343,12 +340,60 @@
   
   rval = tool2.get_option( "opt2", s );
   CHECK( rval );
+  bool e = s.empty();
+  EQUAL( e, true );
+  
+  l = tool2.size();
+  EQUAL( l, 2 );
+  
+    
+    // test empty options string
+    
+  FileOptions tool3( ";;;;" );
+  e = tool3.empty();
+  EQUAL( e, true );
+  l = tool3.size();
+  EQUAL( l, 0 );
+  
+  FileOptions tool4(NULL);
+  e = tool4.empty();
+  EQUAL( e, true );
+  l = tool4.size();
+  EQUAL( l, 0 );
+  
+  FileOptions tool5(";+");
+  e = tool5.empty();
+  EQUAL( e, true );
+  l = tool5.size();
+  EQUAL( l, 0 );
+  
+    // test copy constructor
+  
+  FileOptions tool6( tool2 );
+  
+  rval = tool6.get_option( "opt1", s );
+  CHECK( rval );
+  EQUAL( s, "ABC" );
+  
+  rval = tool6.get_option( "opt2", s );
+  CHECK( rval );
   e = s.empty();
   EQUAL( e, true );
   
-  e = tool2.empty();
+  l = tool6.size();
+  EQUAL( l, 2 );
+  
+  FileOptions tool7( tool5 );
+  e = tool7.empty();
   EQUAL( e, true );
+  l = tool7.size();
+  EQUAL( l, 0 );
   
+    // test assignment operator
+  
+  FileOptions tool8( tool2 );
+  tool8 = tool;
+  EQUAL( tool8.size(), tool.size() );
     
   return 0;
 }

Modified: MOAB/trunk/FileOptions.hpp
===================================================================
--- MOAB/trunk/FileOptions.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/FileOptions.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -42,30 +42,31 @@
    */
   FileOptions( const char* option_string );
   
+  FileOptions( const FileOptions& copy );
+  FileOptions& operator=( const FileOptions& copy );
+  
   ~FileOptions();
   
   /**\brief Check for option with no value 
    *
    * Check for and remove an option w/out a value.
    *\param name The option name
-   *\param remove If true (default), remove the option from the list.
    *\return - MB_SUCCESS if option is found
    *        - 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, bool remove = true );
+  MBErrorCode get_null_option( const char* name ) const;
   
   /**\brief Check for option with an integer value.
    *
    * Check for and remove an option with an integer value
    *\param name The option name
    *\param value Output. The value.
-   *\param remove If true (default), remove the option from the list.
    *\return - MB_SUCCESS if option is found
    *        - 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, bool remove = true );
+  MBErrorCode get_int_option( const char* name, int& value ) const;
   
   /**\brief Check for option with a double value.
    *
@@ -77,7 +78,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, bool remove = true );
+  MBErrorCode get_real_option( const char* name, double& value ) const;
   
   /**\brief Check for option with any value.
    *
@@ -89,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, bool remove = true );
+  MBErrorCode get_str_option( const char* name, std::string& value ) const;
   
   /**\brief Check for option 
    *
@@ -99,7 +100,7 @@
    *\param remove If true (default), remove the option from teh list.
    *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
    */
-  MBErrorCode get_option( const char* name, std::string& value, bool remove = true );
+  MBErrorCode get_option( const char* name, std::string& value ) const;
    
   /**\brief Check for option for which the value is an ID list
    *
@@ -117,22 +118,18 @@
    */
   //MBErrorCode get_id_list_option( const char* name, std::vector<unsigned>& value, bool remove = true );
   
-  /** number of remaining options */
+  /** number of options */
   inline unsigned size() const 
     { return mOptions.size(); }
   
-  /** true if no remaining options */
+  /** true if no options */
   inline bool empty() const 
     { return mOptions.empty(); }
   
-  /** Get list of remaining options by name */
+  /** Get list of options */
   void get_options( std::vector<std::string>& list ) const;
   
 private:
-
-    /* Don't allow copying */
-  FileOptions( const FileOptions& other );
-  void operator=( const FileOptions& other );
   
   /**\brief Check for option 
    *
@@ -142,13 +139,10 @@
    *\param remove If true (default), remove the option from teh list.
    *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
    */
-  MBErrorCode get_option( const char* name, const char*& value);
+  MBErrorCode get_option( const char* name, const char*& value) const;
 
-  MBErrorCode remove_last_option(bool remove_arg);  
-
   char* mData;
   std::vector<const char*> mOptions;
-  std::vector<const char*>::iterator lastOpt;
 
     /** Case-insensitive compare of name with option value. */
   static bool compare( const char* name, const char* option );

Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/MBCore.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -356,29 +356,31 @@
   }
   
     // Try using the file extension to select a reader
+  FileOptions opts(options);
   MBReaderIface* reader = set->get_file_extension_reader( file_name );
   if (reader)
   { 
-    rval = reader->load_file( file_name, file_set, block_id_list, num_blocks );
+    rval = reader->load_file( file_name, file_set, opts, block_id_list, num_blocks );
     delete reader;
-    return rval;
   }
-  
-    // Try all the readers
-  MBReaderWriterSet::iterator iter;
-  for (iter = set->begin(); iter != set->end(); ++iter)
-  {
-    MBReaderIface* reader = iter->make_reader( this );
-    if (NULL != reader)
+  else
+  {  
+      // Try all the readers
+    MBReaderWriterSet::iterator iter;
+    for (iter = set->begin(); iter != set->end(); ++iter)
     {
-      rval = reader->load_file( file_name, file_set, block_id_list, num_blocks );
-      delete reader;
-      if (MB_SUCCESS == rval)
-        return MB_SUCCESS;
+      MBReaderIface* reader = iter->make_reader( this );
+      if (NULL != reader)
+      {
+        rval = reader->load_file( file_name, file_set, opts, block_id_list, num_blocks );
+        delete reader;
+        if (MB_SUCCESS == rval)
+          break;
+      }
     }
   }
 
-  return MB_FAILURE; 
+  return rval; 
 }
   
 
@@ -452,7 +454,7 @@
   
     // write the file
   std::vector<std::string> qa_records;
-  rval = writer->write_file(file_name, overwrite, &list[0], list.size(), qa_records );
+  rval = writer->write_file(file_name, overwrite, opts, &list[0], list.size(), qa_records );
   delete writer;
   
   return rval;

Modified: MOAB/trunk/MBReaderIface.hpp
===================================================================
--- MOAB/trunk/MBReaderIface.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/MBReaderIface.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -26,6 +26,8 @@
 
 #include "MBTypes.h"
 
+class FileOptions;
+
 class MBReaderIface
 {
   public:
@@ -46,6 +48,7 @@
      */
     virtual MBErrorCode load_file( const char* file_name,
                                    MBEntityHandle& file_set,
+                                   const FileOptions& opts,
                                    const int* material_set_list,
                                    const int material_set_list_len ) = 0;
 };

Modified: MOAB/trunk/MBReaderWriterSet.cpp
===================================================================
--- MOAB/trunk/MBReaderWriterSet.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/MBReaderWriterSet.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -70,7 +70,7 @@
   const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
   register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );
   
-  register_factory( ReadSTL::ascii_instance, WriteSTL::ascii_instance, "Stereo Lithography File (STL)", "stl", "STL" );
+  register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );
 }
 
 

Modified: MOAB/trunk/MBWriterIface.hpp
===================================================================
--- MOAB/trunk/MBWriterIface.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/MBWriterIface.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -28,6 +28,8 @@
 #include <string>
 #include "MBTypes.h"
 
+class FileOptions;
+
 class MBWriterIface
 {
   public:
@@ -55,6 +57,7 @@
      */
     virtual MBErrorCode write_file( const char* file_name,
                                     const bool overwrite,
+                                    const FileOptions& opts,
                                     const MBEntityHandle* meshset_list,
                                     const int num_sets,
                                     std::vector<std::string>& qa_records,

Modified: MOAB/trunk/ReadGmsh.cpp
===================================================================
--- MOAB/trunk/ReadGmsh.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadGmsh.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -78,6 +78,7 @@
 
 MBErrorCode ReadGmsh::load_file( const char* filename, 
                                  MBEntityHandle& file_set,
+                                 const FileOptions& ,
                                  const int* blocks,
                                  const int num_blocks )
 {

Modified: MOAB/trunk/ReadGmsh.hpp
===================================================================
--- MOAB/trunk/ReadGmsh.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadGmsh.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -40,6 +40,7 @@
 
   MBErrorCode load_file(const char *file_name,
                         MBEntityHandle& file_set,
+                        const FileOptions& opts,
                         const int* material_set_list,
                         const int num_material_sets );
   

Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadHDF5.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -107,7 +107,11 @@
   H5Tclose( handleType );
 }
 
-MBErrorCode ReadHDF5::load_file( const char* filename, MBEntityHandle& file_set, const int*, const int num_blocks )
+MBErrorCode ReadHDF5::load_file( const char* filename, 
+                                 MBEntityHandle& file_set, 
+                                 const FileOptions&,
+                                 const int*, 
+                                 const int num_blocks )
 {
   MBErrorCode rval;
   mhdf_Status status;

Modified: MOAB/trunk/ReadHDF5.hpp
===================================================================
--- MOAB/trunk/ReadHDF5.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadHDF5.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -48,6 +48,7 @@
    */
   MBErrorCode load_file( const char* filename,
                          MBEntityHandle& file_set,
+                         const FileOptions& opts,
                          const int* material_set_list,
                          int material_set_count  );
 

Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadNCDF.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -407,6 +407,7 @@
 
 MBErrorCode ReadNCDF::load_file(const char *exodus_file_name,
                                   MBEntityHandle& file_set,
+                                  const FileOptions&,
                                   const int *blocks_to_load,
                                   const int num_blocks) 
 {

Modified: MOAB/trunk/ReadNCDF.hpp
===================================================================
--- MOAB/trunk/ReadNCDF.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadNCDF.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -65,6 +65,7 @@
     //! load an ExoII file
   MBErrorCode load_file(const char *exodus_file_name,
                          MBEntityHandle& file_set,
+                         const FileOptions& opts,
                          const int* blocks_to_load,
                          const int num_blocks);
   

Modified: MOAB/trunk/ReadSTL.cpp
===================================================================
--- MOAB/trunk/ReadSTL.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadSTL.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -25,6 +25,7 @@
 #include "MBInterface.hpp"
 #include "MBReadUtilIface.hpp"
 #include "MBRange.hpp"
+#include "FileOptions.hpp"
 
 #include <inttypes.h>  // for int32_t
 #include <errno.h>
@@ -80,11 +81,12 @@
 
 MBErrorCode ReadSTL::load_file( const char* filename,
                                 MBEntityHandle& file_set, 
+                                const FileOptions& opts,
                                 const int* blocks, 
                                 const int num_blocks )
 {
   mCurrentMeshHandle = 0;
-  const MBErrorCode result = load_file_impl( filename, blocks, num_blocks );
+  const MBErrorCode result = load_file_impl( filename, opts, blocks, num_blocks );
   
     // If file read has failed, destroy anything that was
     // created during the read.
@@ -105,14 +107,49 @@
 // pure-virtual function implemented in subclasses to read
 // the data from the file.
 MBErrorCode ReadSTL::load_file_impl(const char *filename,
+                                    const FileOptions& opts,
                                     const int*, const int) 
 {
   MBErrorCode result;
 
   std::vector<ReadSTL::Triangle> triangles;
  
-  result = this->read_triangles( filename, triangles );
-  if (MB_SUCCESS != result) return result; 
+  bool is_ascii = false, is_binary = false;
+  if (MB_SUCCESS == opts.get_null_option( "ASCII" ))
+    is_ascii = true;
+  if (MB_SUCCESS == opts.get_null_option( "BINARY" ))
+    is_binary = true;
+  if (is_ascii && is_binary) {
+    readMeshIface->report_error( "Conflicting options: BINARY ASCII\n" );
+    return MB_FAILURE;
+  }
+  
+  bool big_endian = false, little_endian = false;
+  if (MB_SUCCESS == opts.get_null_option( "BIG_ENDIAN" ))
+    big_endian = true;
+  if (MB_SUCCESS == opts.get_null_option( "LITTLE_ENDIAN" ))
+    little_endian = true;
+  if (big_endian && little_endian) {
+    readMeshIface->report_error( "Conflicting options: BIG_ENDIAN LITTLE_ENDIAN\n" );
+    return MB_FAILURE;
+  }
+  ByteOrder byte_order =    big_endian ? STL_BIG_ENDIAN 
+                       : little_endian ? STL_LITTLE_ENDIAN 
+                       :                 STL_UNKNOWN_BYTE_ORDER;
+ 
+  if (is_ascii) 
+    result = ascii_read_triangles( filename, triangles );
+  else if (is_binary)
+    result = binary_read_triangles( filename, byte_order, triangles );
+  else {
+      // try ASCII first
+    result = ascii_read_triangles( filename, triangles );
+    if (MB_SUCCESS != result) 
+        // ASCII failed, try binary
+      result = binary_read_triangles( filename, byte_order, triangles );
+  }
+  if (MB_SUCCESS != result)
+    return result;
 
     // make a meshset for this mesh
   result = mdbImpl->create_meshset(MESHSET_SET, mCurrentMeshHandle);
@@ -203,7 +240,7 @@
 
 
 // Read ASCII file
-MBErrorCode ReadASCIISTL::read_triangles( const char* name,
+MBErrorCode ReadSTL::ascii_read_triangles( const char* name,
                                           std::vector<ReadSTL::Triangle>& tris )
 {
   FILE* file = fopen( name, "r" );
@@ -281,7 +318,8 @@
 };
 
 // Read a binary STL file
-MBErrorCode ReadBinarySTL::read_triangles( const char* name,
+MBErrorCode ReadSTL::binary_read_triangles( const char* name,
+                                           ReadSTL::ByteOrder byte_order,
                                            std::vector<ReadSTL::Triangle>& tris )
 {
   FILE* file = fopen( name, "rb" );
@@ -300,22 +338,10 @@
     return MB_FILE_WRITE_ERROR;
   }
   
-  bool swap_bytes = !is_platform_little_endian();  // default to little endian
-
-    // Check for tag specifying file byte order
-  MBTag bo_tag = 0;
-  MBErrorCode rval = mdbImpl->tag_get_handle( "__STL_BYTE_ORDER", bo_tag );
-  if (MB_SUCCESS == rval)
-  {
-    int value;
-    rval = mdbImpl->tag_get_data( bo_tag, 0, 1, &value );
-    if (MB_SUCCESS != rval) 
-      return rval;
-    bool is_file_little_endian = (0 == value);
-    swap_bytes = (is_platform_little_endian() != is_file_little_endian);
-  } 
-  else if (MB_TAG_NOT_FOUND != rval)
-    return rval;
+    // 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 = !is_platform_little_endian();
+  bool swap_bytes = (want_big_endian == am_big_endian);
   
     // Compare the number of triangles to the length of the file.  
     // The file must contain an 80-byte description, a 4-byte 
@@ -343,7 +369,7 @@
         // Unless the byte order was specified explicitly in the 
         // tag, try the opposite byte order.
       unsigned long num_tri_swap = byte_swap( (uint32_t)num_tri );
-      if (bo_tag || // If byte order was specified in tag, fail now
+      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
           84 + 50 * num_tri_swap != (unsigned long)filesize)
       {
@@ -383,8 +409,5 @@
 }
 
 
-MBReaderIface* ReadSTL::ascii_instance( MBInterface* iface )
-  { return new ReadASCIISTL(iface); }
-
-MBReaderIface* ReadSTL::binary_instance( MBInterface* iface )
-  { return new ReadBinarySTL(iface); }
+MBReaderIface* ReadSTL::factory( MBInterface* iface )
+  { return new ReadSTL(iface); }

Modified: MOAB/trunk/ReadSTL.hpp
===================================================================
--- MOAB/trunk/ReadSTL.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadSTL.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -66,15 +66,14 @@
    
 public:
 
-    //! factory method for binary STL reader
-  static MBReaderIface* binary_instance( MBInterface* );
-    //! factory method for ASCII STL reader.
-  static MBReaderIface* ascii_instance( MBInterface* );
+    //! factory method for STL reader
+  static MBReaderIface* factory( MBInterface* );
 
     //! 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,
                         MBEntityHandle& file_set,
+                        const FileOptions& opts,
                         const int* material_set_list,
                         const int num_material_sets );
   
@@ -96,15 +95,20 @@
   struct Triangle {
     Point points[3];
   };
+  
+  enum ByteOrder { STL_BIG_ENDIAN, STL_LITTLE_ENDIAN, STL_UNKNOWN_BYTE_ORDER };
 
 protected:
-  
-    // I/O-specific part of reader.  Read list of triangles
-    // from file.
-  virtual MBErrorCode read_triangles( const char* name, 
-                                      std::vector<Triangle>& tris_out 
-                                    ) = 0;
 
+    // I/O specific part of reader - read ASCII file
+  MBErrorCode 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, 
+                                     ByteOrder byte_order,
+                                     std::vector<Triangle>& tris_out );
+
   MBReadUtilIface* readMeshIface;
 
     //! interface instance
@@ -113,8 +117,9 @@
 private:
 
     //! Generic file loading code for both binary and ASCII readers.
-    //! Calls reader-specific read_triangles function to do actual I/O.
+    //! Calls reader-specific *_read_triangles function to do actual I/O.
   MBErrorCode load_file_impl(const char *file_name,
+                             const FileOptions& opts,
                              const int* material_set_list,
                              const int num_material_sets );
 
@@ -122,34 +127,4 @@
   MBEntityHandle mCurrentMeshHandle;
 };
 
-
-//! Specialize ReadSTL for reading ASCII STL files
-class ReadASCIISTL : public ReadSTL
-{
-public:
-  
-  ReadASCIISTL(MBInterface* impl = NULL) : ReadSTL(impl) {}
-
-  virtual ~ReadASCIISTL() {}
-  
-protected:
-
-  MBErrorCode read_triangles( const char* name, std::vector<Triangle>& tris_out );
-};
-
-
-//! Specialize ReadSTL for reading binary STL files
-class ReadBinarySTL : public ReadSTL
-{
-public:
-
-  ReadBinarySTL(MBInterface* impl = NULL) : ReadSTL(impl) {}
-
-  virtual ~ReadBinarySTL() { }
-  
-protected:
-  
-  MBErrorCode read_triangles( const char* name, std::vector<Triangle>& tris_out );
-};
-
 #endif

Modified: MOAB/trunk/ReadVtk.cpp
===================================================================
--- MOAB/trunk/ReadVtk.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadVtk.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -54,6 +54,7 @@
 
 MBErrorCode ReadVtk::load_file(const char *filename,
                                MBEntityHandle& file_set,
+                               const FileOptions&,
                                const int*, const int) 
 {
   MBErrorCode result;

Modified: MOAB/trunk/ReadVtk.hpp
===================================================================
--- MOAB/trunk/ReadVtk.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/ReadVtk.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -32,6 +32,7 @@
     //! load a file
   MBErrorCode load_file(const char *file_name,
                         MBEntityHandle& file_set,
+                        const FileOptions&,
                         const int* material_set_list,
                         const int num_material_sets );
   

Modified: MOAB/trunk/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/Tqdcfr.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/Tqdcfr.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -21,14 +21,13 @@
 #include "MBTagConventions.hpp"
 #include "MBCN.hpp"
 #include "MBInternals.hpp"
+#include "FileOptions.hpp"
 
 #include <iostream>
 #include <assert.h>
 
 const bool debug = false;
 const int ACIS_DIMS[] = {-1, 3, -1, 2, -1, -1, 1, 0, -1, -1};
-const char default_acis_dump_file[] = "dumped_acis.sat";
-const char acis_dump_file_tag_name[] = "__ACISDumpFile";
 const char Tqdcfr::geom_categories[][CATEGORY_TAG_SIZE] = 
 {"Vertex\0", "Curve\0", "Surface\0", "Volume\0"};
 const MBEntityType Tqdcfr::group_type_to_mb_type[] = {
@@ -171,6 +170,7 @@
   
 MBErrorCode Tqdcfr::load_file(const char *file_name,
                               MBEntityHandle& file_set,
+                              const FileOptions& opts,
                               const int*, const int) 
 {
   MBErrorCode result;
@@ -241,7 +241,10 @@
     // ***********************
     // read acis records...
     // ***********************
-  result = read_acis_records(); RR;
+  std::string sat_file_name;
+  if (MB_SUCCESS != opts.get_str_option( "SAT_FILE", sat_file_name))
+    sat_file_name.clear();
+  result = read_acis_records( sat_file_name.empty() ? NULL : sat_file_name.c_str() ); RR;
 
     // ***********************
     // read groups...
@@ -1778,7 +1781,7 @@
   return MB_SUCCESS;
 }
 
-MBErrorCode Tqdcfr::read_acis_records() 
+MBErrorCode Tqdcfr::read_acis_records( const char* sat_filename ) 
 {
 
     // get the acis model location
@@ -1797,18 +1800,12 @@
   
   std::vector<AcisRecord> records;
 
-    // get name for acis dump file
-  MBTag acis_file_tag;
-  MBErrorCode rval;
-  rval = mdbImpl->tag_get_handle( acis_dump_file_tag_name, acis_file_tag );
-  const char* filename = default_acis_dump_file;
-  if (MB_SUCCESS == rval)
-    mdbImpl->tag_get_data( acis_file_tag, 0, 0, &filename );
-  
   acisDumpFile = NULL;
-  if (filename && *filename)
+  if (sat_filename)
   {
-    acisDumpFile = fopen( filename, "w+" );
+    acisDumpFile = fopen( sat_filename, "w+" );
+    if (NULL == acisDumpFile)
+      return MB_FAILURE;
   }
 
     // position the file at the start of the acis model
@@ -2426,9 +2423,10 @@
   MBCore my_impl;
   Tqdcfr my_tqd(&my_impl);
   MBEntityHandle file_set;
+  FileOptions opts(NULL);
+  
+  MBErrorCode result = my_tqd.load_file(file, file_set, opts, 0, 0);
 
-  MBErrorCode result = my_tqd.load_file(file, file_set, 0, 0);
-
   if (MB_SUCCESS == result)
     std::cout << "Success." << std::endl;
   else 

Modified: MOAB/trunk/Tqdcfr.hpp
===================================================================
--- MOAB/trunk/Tqdcfr.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/Tqdcfr.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -286,6 +286,7 @@
     // read cub file
   MBErrorCode load_file(const char *file_name,
                         MBEntityHandle& file_set,
+                        const FileOptions& opts,
                         const int* block_list,
                         int num_blocks );
   MBErrorCode read_nodeset(ModelEntry *model,
@@ -328,7 +329,7 @@
 
   MBErrorCode convert_nodesets_sidesets();
 
-  MBErrorCode read_acis_records();
+  MBErrorCode read_acis_records( const char* sat_file_name = 0 );
   
   MBErrorCode parse_acis_attribs(const int entity_rec_num,
                           std::vector<AcisRecord> &records);

Modified: MOAB/trunk/WriteAns.cpp
===================================================================
--- MOAB/trunk/WriteAns.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteAns.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -86,6 +86,7 @@
 
 MBErrorCode WriteAns::write_file(const char *file_name, 
                                       const bool /* overwrite (commented out to remove warning) */,
+                                      const FileOptions&,
                                       const MBEntityHandle *ent_handles,
                                       const int num_sets,
                                       std::vector<std::string>&, int )

Modified: MOAB/trunk/WriteAns.hpp
===================================================================
--- MOAB/trunk/WriteAns.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteAns.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -59,6 +59,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                           const MBEntityHandle *output_list,
                           const int num_sets,
                           std::vector<std::string>& qa_list,

Modified: MOAB/trunk/WriteGMV.cpp
===================================================================
--- MOAB/trunk/WriteGMV.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteGMV.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -132,6 +132,7 @@
 
 MBErrorCode WriteGMV::write_file( const char* filename,
                                   const bool ,
+                                  const FileOptions& opts,
                                   const MBEntityHandle* output_sets,
                                   const int num_output_sets,
                                   std::vector<std::string>& ,

Modified: MOAB/trunk/WriteGMV.hpp
===================================================================
--- MOAB/trunk/WriteGMV.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteGMV.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -49,6 +49,7 @@
 
   MBErrorCode write_file( const char* filename,
                           const bool overwite,
+                          const FileOptions& opts,
                           const MBEntityHandle* output_sets,
                           const int num_output_sets,
                           std::vector<std::string>& qa_list,

Modified: MOAB/trunk/WriteGmsh.cpp
===================================================================
--- MOAB/trunk/WriteGmsh.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteGmsh.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -48,6 +48,7 @@
     //! writes out a file
 MBErrorCode WriteGmsh::write_file(const char *file_name,
                                   const bool overwrite,
+                                  const FileOptions&,
                                   const MBEntityHandle *output_list,
                                   const int num_sets,
                                   std::vector<std::string>& ,

Modified: MOAB/trunk/WriteGmsh.hpp
===================================================================
--- MOAB/trunk/WriteGmsh.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteGmsh.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -53,6 +53,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                          const MBEntityHandle *output_list,
                          const int num_sets,
                          std::vector<std::string>& qa_list,

Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteHDF5.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -312,6 +312,7 @@
 
 MBErrorCode WriteHDF5::write_file( const char* filename,
                                    bool overwrite,
+                                   const FileOptions& ,
                                    const MBEntityHandle* set_array,
                                    const int num_sets,
                                    std::vector<std::string>& qa_records,

Modified: MOAB/trunk/WriteHDF5.hpp
===================================================================
--- MOAB/trunk/WriteHDF5.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteHDF5.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -61,6 +61,7 @@
    */
   MBErrorCode write_file( const char* filename,
                           bool overwrite,
+                          const FileOptions& opts,
                           const MBEntityHandle* export_sets,
                           const int export_set_count,
                           std::vector<std::string>& qa_records,

Modified: MOAB/trunk/WriteNCDF.cpp
===================================================================
--- MOAB/trunk/WriteNCDF.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteNCDF.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -146,6 +146,7 @@
 
 MBErrorCode WriteNCDF::write_file(const char *exodus_file_name, 
                                     const bool overwrite,
+                                    const FileOptions&,
                                     const MBEntityHandle *ent_handles,
                                     const int num_sets,
                                     std::vector<std::string> &qa_records,

Modified: MOAB/trunk/WriteNCDF.hpp
===================================================================
--- MOAB/trunk/WriteNCDF.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteNCDF.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -98,6 +98,7 @@
     //! writes out an ExoII file
   MBErrorCode write_file(const char *exodus_file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                           const MBEntityHandle *output_list,
                           const int num_sets,
                           std::vector<std::string> &qa_records, 

Modified: MOAB/trunk/WriteSLAC.cpp
===================================================================
--- MOAB/trunk/WriteSLAC.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteSLAC.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -124,6 +124,7 @@
 
 MBErrorCode WriteSLAC::write_file(const char *file_name, 
                                   const bool overwrite,
+                                  const FileOptions&,
                                   const MBEntityHandle *ent_handles,
                                   const int num_sets,
                                   std::vector<std::string>&, int )

Modified: MOAB/trunk/WriteSLAC.hpp
===================================================================
--- MOAB/trunk/WriteSLAC.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteSLAC.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -61,6 +61,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                           const MBEntityHandle *output_list,
                           const int num_sets,
                           std::vector<std::string>& qa_list,

Modified: MOAB/trunk/WriteSTL.cpp
===================================================================
--- MOAB/trunk/WriteSTL.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteSTL.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -25,6 +25,7 @@
 #include "MBInterface.hpp"
 #include "MBRange.hpp"
 #include "MBWriteUtilIface.hpp"
+#include "FileOptions.hpp"
 
 #include <stdio.h>
 #include <sys/types.h>
@@ -73,12 +74,9 @@
 }
 
 
-MBWriterIface *WriteSTL::ascii_instance( MBInterface* iface )
-  { return new WriteASCIISTL( iface ); }
+MBWriterIface *WriteSTL::factory( MBInterface* iface )
+  { return new WriteSTL( iface ); }
 
-MBWriterIface *WriteSTL::binary_instance( MBInterface* iface )
-  { return new WriteBinarySTL( iface ); }
-
 WriteSTL::WriteSTL(MBInterface *impl) 
     : mbImpl(impl)
 {
@@ -93,6 +91,7 @@
 
 MBErrorCode WriteSTL::write_file(const char *file_name, 
                                  const bool overwrite,
+                                 const FileOptions& opts,
                                  const MBEntityHandle *ent_handles,
                                  const int num_sets,
                                  std::vector<std::string>& qa_list, 
@@ -109,18 +108,43 @@
   rval = get_triangles( ent_handles, num_sets, triangles );
   if (MB_SUCCESS != rval)
     return rval;
+
+ 
+  bool is_ascii = false, is_binary = false;
+  if (MB_SUCCESS == opts.get_null_option( "ASCII" ))
+    is_ascii = true;
+  if (MB_SUCCESS == opts.get_null_option( "BINARY" ))
+    is_binary = true;
+  if (is_ascii && is_binary) {
+    mWriteIface->report_error( "Conflicting options: BINARY ASCII\n" );
+    return MB_FAILURE;
+  }
+  
+  bool big_endian = false, little_endian = false;
+  if (MB_SUCCESS == opts.get_null_option( "BIG_ENDIAN" ))
+    big_endian = true;
+  if (MB_SUCCESS == opts.get_null_option( "LITTLE_ENDIAN" ))
+    little_endian = true;
+  if (big_endian && little_endian) {
+    mWriteIface->report_error( "Conflicting options: BIG_ENDIAN LITTLE_ENDIAN\n" );
+    return MB_FAILURE;
+  }
+  ByteOrder byte_order = big_endian ? STL_BIG_ENDIAN : little_endian ? STL_LITTLE_ENDIAN : STL_UNKNOWN_BYTE_ORDER;
     
-  FILE* file = open_file( file_name, overwrite );
+  FILE* file = open_file( file_name, overwrite, is_binary );
   if (!file)
     return MB_FILE_DOES_NOT_EXIST; 
   
-  rval = write_triangles( file, header, triangles );
+  if (is_binary)
+    rval = binary_write_triangles( file, header, byte_order, triangles );
+  else
+    rval = ascii_write_triangles( file, header, triangles );
   fclose( file );
   return rval;
 }
 
 
-FILE* WriteSTL::open_file( const char* name, bool overwrite )
+FILE* WriteSTL::open_file( const char* name, bool overwrite, bool binary )
 {
     // Open file with write access, and create it if it doesn't exist.
   int flags = O_WRONLY|O_CREAT;
@@ -135,7 +159,7 @@
     // flags (i.e. we're building on windows), then set it
     // if we're writing a binary file.
 #ifdef O_BINARY
-  if (need_binary_io())
+  if (binary)
     flags |= O_BINARY;
 #endif
 
@@ -154,7 +178,7 @@
     mWriteIface->report_error( "%s: %s\n", name, strerror(errno) );
     return 0;
   }
-  FILE* result = fdopen( fd, need_binary_io() ? "wb": "w" );
+  FILE* result = fdopen( fd, binary ? "wb": "w" );
   if (!result)
     close( fd );
   
@@ -236,9 +260,9 @@
 }
 
 
-MBErrorCode WriteASCIISTL::write_triangles( FILE* file,
-                                            const char header[81],
-                                            const MBRange& triangles )
+MBErrorCode WriteSTL::ascii_write_triangles( FILE* file,
+                                             const char header[81],
+                                             const MBRange& triangles )
 {
   const char solid_name[] = "MOAB";
   
@@ -273,7 +297,7 @@
     if (MB_SUCCESS != rval)
       return rval;
    
-    fprintf( file, "facet normal %e %e %e\n", n[0], n[1], n[2] );
+    fprintf( file,"facet normal %e %e %e\n", n[0], n[1], n[2] );
     fprintf( file,"outer loop\n" );
     fprintf( file,"vertex %e %e %e\n", v1[0], v1[1], v1[2] );
     fprintf( file,"vertex %e %e %e\n", v2[0], v2[1], v2[2] );
@@ -302,30 +326,19 @@
   vect[2] = byte_swap( vect[2] );
 }
 
-MBErrorCode WriteBinarySTL::write_triangles( FILE* file,
+MBErrorCode WriteSTL::binary_write_triangles( FILE* file,
                                              const char header[81],
+                                             ByteOrder byte_order,
                                              const MBRange& triangles )
 {
   MBErrorCode rval;
   if (fwrite( header, 80, 1, file ) != 1)
     return MB_FILE_WRITE_ERROR;
   
-  bool swap_bytes = !is_platform_little_endian();  // default to little endian
-
-    // Check for tag specifying file byte order
-  MBTag bo_tag = 0;
-  rval = mbImpl->tag_get_handle( "__STL_BYTE_ORDER", bo_tag );
-  if (MB_SUCCESS == rval)
-  {
-    int value;
-    rval = mbImpl->tag_get_data( bo_tag, 0, 1, &value );
-    if (MB_SUCCESS != rval) 
-      return rval;
-    bool is_file_little_endian = (0 == value);
-    swap_bytes = (is_platform_little_endian() != is_file_little_endian);
-  } 
-  else if (MB_TAG_NOT_FOUND != rval)
-    return rval;
+    // 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 = !is_platform_little_endian();
+  const bool swap_bytes = (want_big_endian == am_big_endian);
     
   if (triangles.size() > INT_MAX) // can't write that many triangles
     return MB_FAILURE;  

Modified: MOAB/trunk/WriteSTL.hpp
===================================================================
--- MOAB/trunk/WriteSTL.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteSTL.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -44,10 +44,8 @@
  
 public:
   
-    //! factory method for binary STL writer
-  static MBWriterIface* binary_instance( MBInterface* );
-    //! factory method for ASCII STL writer.
-  static MBWriterIface* ascii_instance( MBInterface* );
+    //! factory method forSTL writer
+  static MBWriterIface* factory( MBInterface* );
 
    //! Constructor
   WriteSTL(MBInterface *impl);
@@ -58,6 +56,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                          const MBEntityHandle *output_list,
                          const int num_sets,
                          std::vector<std::string>& qa_list,
@@ -65,17 +64,18 @@
 
 protected:
   
+  enum ByteOrder { STL_BIG_ENDIAN, STL_LITTLE_ENDIAN, STL_UNKNOWN_BYTE_ORDER };
+  
     //! Write list of triangles to an STL file.  
-    //! Subclasses provide format-specific implementations 
-    //! of this function.
-  virtual MBErrorCode write_triangles( FILE* file,
-                                       const char header[82],
-                                       const MBRange& triangles ) = 0;
+  MBErrorCode ascii_write_triangles( FILE* file,
+                                     const char header[82],
+                                     const MBRange& triangles );
+    //! Write list of triangles to an STL file.  
+  MBErrorCode binary_write_triangles( FILE* file,
+                                      const char header[82],
+                                      ByteOrder byte_order,
+                                      const MBRange& triangles );
 
-    //! Allow subclasses to request that file be opened in "binary"
-    //! mode (a windows thing).
-  virtual bool need_binary_io() const = 0;
-
     //! Given an array of vertex coordinates for a triangle,
     //! pass back individual point coordinates as floats and 
     //! calculate triangle normal.
@@ -103,47 +103,8 @@
   
     //! Open a file, respecting passed overwrite value and
     //! subclass-specified value for need_binary_io().
-  FILE* open_file( const char* name, bool overwrite );
+  FILE* open_file( const char* name, bool overwrite, bool binary );
 };
 
 
-//! Specialize WriteSTL for writing ASCII STL Files.
-class WriteASCIISTL : public WriteSTL
-{
- 
-public:
-
-  WriteASCIISTL(MBInterface *impl) : WriteSTL(impl) {}
-
-  virtual ~WriteASCIISTL() {}
-
-protected:
-
-  virtual bool need_binary_io() const { return false; }
-  
-  virtual MBErrorCode write_triangles( FILE* file,
-                                       const char header[81],
-                                       const MBRange& triangles );
-};
-
-
-//! Specialize WriteSTL for writing binary STL Files.
-class WriteBinarySTL : public WriteSTL
-{
- 
-public:
-
-  WriteBinarySTL(MBInterface *impl) : WriteSTL(impl) {}
-
-  virtual ~WriteBinarySTL() {}
-
-protected:
-
-  virtual bool need_binary_io() const { return true; }
-  
-  virtual MBErrorCode write_triangles( FILE* file,
-                                       const char header[81],
-                                       const MBRange& triangles );
-};
-
 #endif

Modified: MOAB/trunk/WriteTemplate.cpp
===================================================================
--- MOAB/trunk/WriteTemplate.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteTemplate.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -118,6 +118,7 @@
 
 MBErrorCode WriteTEMPLATE::write_file(const char *file_name, 
                                       const bool /* overwrite (commented out to remove warning) */,
+                                      const FileOptions& opts,
                                       const MBEntityHandle *ent_handles,
                                       const int num_sets,
                                       std::vector<std::string>&, int )

Modified: MOAB/trunk/WriteTemplate.hpp
===================================================================
--- MOAB/trunk/WriteTemplate.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteTemplate.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -60,6 +60,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                           const MBEntityHandle *output_list,
                           const int num_sets,
                           std::vector<std::string>& qa_list,

Modified: MOAB/trunk/WriteVtk.cpp
===================================================================
--- MOAB/trunk/WriteVtk.cpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteVtk.cpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -70,6 +70,7 @@
 
 MBErrorCode WriteVtk::write_file(const char *file_name, 
                                  const bool overwrite,
+                                 const FileOptions&,
                                  const MBEntityHandle *output_list,
                                  const int num_sets,
                                  std::vector<std::string>& ,

Modified: MOAB/trunk/WriteVtk.hpp
===================================================================
--- MOAB/trunk/WriteVtk.hpp	2007-08-24 20:44:55 UTC (rev 1254)
+++ MOAB/trunk/WriteVtk.hpp	2007-08-24 23:03:49 UTC (rev 1255)
@@ -41,6 +41,7 @@
     //! writes out a file
   MBErrorCode write_file(const char *file_name,
                          const bool overwrite,
+                         const FileOptions& opts,
                          const MBEntityHandle *output_list,
                          const int num_sets,
                          std::vector<std::string>& qa_list,




More information about the moab-dev mailing list