1/** @example LoadPartial.cpp \n
2 * \brief Load a part of a file \n
3 * <b>To run</b>: LoadPartial [file] [tag_name] [val1] [val2] ...\n
4 *
5 * In this example, it is shown how to load only a part of one file; the file must be organized in
6 * sets. (cherry-picking only the sets we want) The sets to load are identified by a tag name and
7 * the tag values for the sets of interest. This procedure is used when reading in parallel, as
8 * each processor will load only its part of the file, identified either by partition or by
9 * material/block sets by default, this example will load parallel partition sets with values 1, 2,
10 * and 5 from ../MeshFiles/unittest/64bricks_1khex.h5m The example will always write the output to a
11 * file name part.h5m
12 */1314#include<iostream>15#include<vector>1617// Include header for MOAB instance and tag conventions for18#include"moab/Core.hpp"19#include"MBTagConventions.hpp"2021#define NTAGVALS 32223usingnamespace moab;
24usingnamespace std;
2526// Function to parse input parameters27ErrorCode get_file_options( int argc, char** argv, string& filename, string& tagName, vector< int >& tagValues )
28 {
29// Get mesh filename30if( argc > 1 )
31 filename = string( argv[1] );
32else33 filename = string( MESH_DIR ) + string( "/64bricks_512hex_256part.h5m" );
3435// Get tag selection options36if( argc > 2 )
37 tagName = string( argv[2] );
38else39 tagName = "USERTAG";
4041if( argc > 3 )
42 {
43 tagValues.resize( argc - 3, 0 );
44for( int i = 3; i < argc; ++i )
45 tagValues[i - 3] = atoi( argv[i] );
46 }
47else48 {
49for( unsigned i = 0; i < tagValues.size(); ++i )
50 tagValues[i] = 2 * i + 1;
51 }
5253if( argc > 1 && argc < 4 ) // print usage54 cout << " usage is " << argv[0] << " <file> <tag_name> <value1> <value2> .. \n";
55return MB_SUCCESS;
56 }
5758intmain( int argc, char** argv )
59 {
60// Get MOAB instance61 Interface* mb = new( std::nothrow ) Core;
62if( NULL == mb ) return1;
6364 std::string filename, tagname;
65vector< int > tagvals( NTAGVALS ); // Allocate for a maximum of 5 tag values66 ErrorCode rval = get_file_options( argc, argv, filename, tagname, tagvals );MB_CHK_ERR( rval );
6768#ifdef MOAB_HAVE_HDF569// This file is in the mesh files directory70 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" );
7172// If HANDLEID tag present, convert to long, and see what we read from file73 Tag handleid_tag;
74 rval = mb->tag_get_handle( "HANDLEID", handleid_tag );
75if( MB_SUCCESS == rval )
76 {
77// Convert a few values for a few vertices78 Range verts;
79 rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_SET_ERR( rval, "Failed to get vertices" );
80vector< long > valsTag( verts.size() );
81 rval = mb->tag_get_data( handleid_tag, verts, &valsTag[0] );
82if( MB_SUCCESS == rval ) cout << "First 2 long values recovered: " << valsTag[0] << " " << valsTag[1] << "\n";
83 }
8485 rval = mb->write_file( "part.h5m" );MB_CHK_SET_ERR( rval, "Failed to write partial file" );
86 cout << "Wrote successfully part.h5m.\n";
8788#else89 std::cout << "Configure MOAB with HDF5 to build and use this example correctly.\n";
90#endif91delete mb;
92return0;
93 }