Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
cleanTags.cpp File Reference
#include "moab/MOABConfig.h"
#include "moab/ProgOptions.hpp"
#include "moab/Core.hpp"
+ Include dependency graph for cleanTags.cpp:

Go to the source code of this file.

Functions

vector< string > split (const string &i_str, const string &i_delim)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file cleanTags.cpp.

36 {
37  ProgOptions opts;
38 
39  string inputfile, outputfile, deleteTags, keepTags;
40  opts.addOpt< string >( "input,i", "input filename ", &inputfile );
41  opts.addOpt< string >( "output,o", "output file", &outputfile );
42 
43  opts.addOpt< string >( "deleteTags,d", "delete tags ", &deleteTags );
44  opts.addOpt< string >( "keepTags,k", "keep tags ", &keepTags );
45  opts.parseCommandLine( argc, argv );
46 
47  Core core;
48  Interface* mb = &core;
49 
50  MB_CHK_ERR( mb->load_file( inputfile.c_str() ) );
51 
52  vector< Tag > existingTags;
53  MB_CHK_ERR( mb->tag_get_tags( existingTags ) );
54 
55  vector< string > tagsToDelete;
56  if( !keepTags.empty() )
57  {
58  vector< string > tagsToKeep = split( keepTags, string( ":" ) );
59  for( size_t i = 0; i < existingTags.size(); i++ )
60  {
61  string tname;
62  MB_CHK_ERR( mb->tag_get_name( existingTags[i], tname ) );
63  bool deleteTag = false;
64  for( size_t k = 0; k < tagsToKeep.size() && !deleteTag; k++ )
65  {
66  if( tname.compare( tagsToKeep[k] ) == 0 ) deleteTag = true;
67  }
68  if( !deleteTag ) tagsToDelete.push_back( tname );
69  }
70  }
71 
72  if( !deleteTags.empty() )
73  {
74  tagsToDelete = split( deleteTags, string( ":" ) );
75  }
76 
77  for( size_t i = 0; i < tagsToDelete.size(); i++ )
78  {
79  Tag tag;
80  if( mb->tag_get_handle( tagsToDelete[i].c_str(), tag ) == MB_SUCCESS && tag != nullptr )
81  {
82  MB_CHK_ERR( mb->tag_delete( tag ) );
83  }
84  }
85 
86  cout << "writing file " << outputfile << endl;
87  MB_CHK_ERR( mb->write_file( outputfile.c_str() ) );
88 
89  return 0;
90 }

References ProgOptions::addOpt(), moab::Core::load_file(), mb, MB_CHK_ERR, MB_SUCCESS, ProgOptions::parseCommandLine(), split(), moab::Core::tag_delete(), moab::Core::tag_get_handle(), moab::Core::tag_get_name(), moab::Core::tag_get_tags(), and moab::Core::write_file().

◆ split()

vector< string > split ( const string &  i_str,
const string &  i_delim 
)

Definition at line 18 of file cleanTags.cpp.

19 {
20  vector< string > result;
21 
22  size_t found = i_str.find( i_delim );
23  size_t startIndex = 0;
24 
25  while( found != string::npos )
26  {
27  result.push_back( string( i_str.begin() + startIndex, i_str.begin() + found ) );
28  startIndex = found + i_delim.size();
29  found = i_str.find( i_delim, startIndex );
30  }
31  if( startIndex != i_str.size() ) result.push_back( string( i_str.begin() + startIndex, i_str.end() ) );
32  return result;
33 }

Referenced by moab::SequenceManager::check_valid_entities(), moab::Element_tree< _Entity_handles, _Box, _Moab, _Parametrizer >::compute_split(), moab::SequenceManager::delete_entities(), moab::AdaptiveKDTree::find_close_triangle(), main(), moab::anonymous_namespace{bvh_tree.hpp}::_bvh::_Split_data::operator=(), moab::anonymous_namespace{element_tree.hpp}::_element_tree::_Partition_data< Box >::operator=(), and moab::anonymous_namespace{element_tree.hpp}::_element_tree::_Node< _Entity_handles, _Entities >::operator=().