![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
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[]) |
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 35 of file cleanTags.cpp.
References ProgOptions::addOpt(), ErrorCode, moab::Interface::load_file(), mb, MB_CHK_ERR, MB_SUCCESS, ProgOptions::parseCommandLine(), split, moab::Interface::tag_delete(), moab::Interface::tag_get_handle(), moab::Interface::tag_get_name(), moab::Interface::tag_get_tags(), and moab::Interface::write_file().
{
ProgOptions opts;
string inputfile, outputfile, deleteTags, keepTags;
opts.addOpt< string >( "input,i", "input filename ", &inputfile );
opts.addOpt< string >( "output,o", "output file", &outputfile );
opts.addOpt< string >( "deleteTags,d", "delete tags ", &deleteTags );
opts.addOpt< string >( "keepTags,k", "keep tags ", &keepTags );
opts.parseCommandLine( argc, argv );
Core core;
Interface* mb = &core;
ErrorCode rval;
rval = mb->load_file( inputfile.c_str() );MB_CHK_ERR( rval );
vector< Tag > existingTags;
rval = mb->tag_get_tags( existingTags );MB_CHK_ERR( rval );
vector< string > tagsToDelete;
if( !keepTags.empty() )
{
vector< string > tagsToKeep = split( keepTags, string( ":" ) );
for( size_t i = 0; i < existingTags.size(); i++ )
{
string tname;
rval = mb->tag_get_name( existingTags[i], tname );MB_CHK_ERR( rval );
bool deleteTag = false;
for( size_t k = 0; k < tagsToKeep.size() && !deleteTag; k++ )
{
if( tname.compare( tagsToKeep[k] ) == 0 ) deleteTag = true;
}
if( !deleteTag ) tagsToDelete.push_back( tname );
}
}
if( !deleteTags.empty() )
{
tagsToDelete = split( deleteTags, string( ":" ) );
}
for( size_t i = 0; i < tagsToDelete.size(); i++ )
{
Tag tag;
rval = mb->tag_get_handle( tagsToDelete[i].c_str(), tag );
if( rval == MB_SUCCESS && tag != NULL )
{
rval = mb->tag_delete( tag );MB_CHK_ERR( rval );
}
}
cout << "write file " << outputfile << endl;
rval = mb->write_file( outputfile.c_str() );MB_CHK_ERR( rval );
return 0;
}
vector< string > split | ( | const string & | i_str, |
const string & | i_delim | ||
) |
Definition at line 18 of file cleanTags.cpp.
{
vector< string > result;
size_t found = i_str.find( i_delim );
size_t startIndex = 0;
while( found != string::npos )
{
result.push_back( string( i_str.begin() + startIndex, i_str.begin() + found ) );
startIndex = found + i_delim.size();
found = i_str.find( i_delim, startIndex );
}
if( startIndex != i_str.size() ) result.push_back( string( i_str.begin() + startIndex, i_str.end() ) );
return result;
}