Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
LoadPartial.cpp File Reference
#include <iostream>
#include <vector>
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
+ Include dependency graph for LoadPartial.cpp:

Go to the source code of this file.

Defines

#define NTAGVALS   3

Functions

ErrorCode get_file_options (int argc, char **argv, string &filename, string &tagName, vector< int > &tagValues)
int main (int argc, char **argv)

Define Documentation

#define NTAGVALS   3
Examples:
LoadPartial.cpp.

Definition at line 21 of file LoadPartial.cpp.

Referenced by main().


Function Documentation

ErrorCode get_file_options ( int  argc,
char **  argv,
string &  filename,
string &  tagName,
vector< int > &  tagValues 
)

Definition at line 27 of file LoadPartial.cpp.

References MB_SUCCESS, and MESH_DIR.

{
    // Get mesh filename
    if( argc > 1 )
        filename = string( argv[1] );
    else
        filename = string( MESH_DIR ) + string( "/64bricks_512hex_256part.h5m" );

    // Get tag selection options
    if( argc > 2 )
        tagName = string( argv[2] );
    else
        tagName = "USERTAG";

    if( argc > 3 )
    {
        tagValues.resize( argc - 3, 0 );
        for( int i = 3; i < argc; ++i )
            tagValues[i - 3] = atoi( argv[i] );
    }
    else
    {
        for( unsigned i = 0; i < tagValues.size(); ++i )
            tagValues[i] = 2 * i + 1;
    }

    if( argc > 1 && argc < 4 )  // print usage
        cout << " usage is " << argv[0] << " <file> <tag_name> <value1> <value2> .. \n";
    return MB_SUCCESS;
}
int main ( int  argc,
char **  argv 
)

Definition at line 58 of file LoadPartial.cpp.

References ErrorCode, moab::Interface::get_entities_by_type(), moab::point_locator::io::get_file_options(), moab::Interface::load_file(), mb, MB_CHK_ERR, MB_CHK_SET_ERR, MB_SUCCESS, MBVERTEX, NTAGVALS, PARALLEL_PARTITION_TAG_NAME, moab::Range::size(), moab::Interface::tag_get_data(), moab::Interface::tag_get_handle(), and moab::Interface::write_file().

{
    // Get MOAB instance
    Interface* mb = new( std::nothrow ) Core;
    if( NULL == mb ) return 1;

    std::string filename, tagname;
    vector< int > tagvals( NTAGVALS );  // Allocate for a maximum of 5 tag values
    ErrorCode rval = get_file_options( argc, argv, filename, tagname, tagvals );MB_CHK_ERR( rval );

#ifdef MOAB_HAVE_HDF5
    // This file is in the mesh files directory
    rval = mb->load_file( filename.c_str(), 0, 0, PARALLEL_PARTITION_TAG_NAME, tagvals.data(), (int)tagvals.size() );MB_CHK_SET_ERR( rval, "Failed to read" );

    // If HANDLEID tag present, convert to long, and see what we read from file
    Tag handleid_tag;
    rval = mb->tag_get_handle( "HANDLEID", handleid_tag );
    if( MB_SUCCESS == rval )
    {
        // Convert a few values for a few vertices
        Range verts;
        rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_SET_ERR( rval, "Failed to get vertices" );
        vector< long > valsTag( verts.size() );
        rval = mb->tag_get_data( handleid_tag, verts, &valsTag[0] );
        if( MB_SUCCESS == rval ) cout << "First 2 long values recovered: " << valsTag[0] << " " << valsTag[1] << "\n";
    }

    rval = mb->write_file( "part.h5m" );MB_CHK_SET_ERR( rval, "Failed to write partial file" );
    cout << "Wrote successfully part.h5m.\n";

#else
    std::cout << "Configure MOAB with HDF5 to build and use this example correctly.\n";
#endif
    delete mb;
    return 0;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines