Add point cloud data this tool will take an existing h5m fine atm mesh file and add data from an h5m type file with point cloud mesh will support mainly showing the data with Visit
example of usage: ./mbaddpcdata -i wholeFineATM.h5m -s wholeLND_proj01.h5m -o atm_a2l.h5m -v a2lTbot_proj
it should work also for pentagon file style data ./mbaddpcdata -i <MOABsource>/MeshFiles/unittest/penta3d.h5m -s wholeLND_proj01.h5m -o atm_a2l.h5m -v a2lTbot_proj -p 1
Basically, will output a new h5m file (atm_a2l.h5m), which has an extra tag, corresponding to the variable a2lTbot_proj from the file wholeLND_proj01.h5m; matching is based on the global ids between what we think is the order on the original file (wholeFineATM.h5m) and the order of surfdata_ne11np4_simyr1850_c160614.nc
file wholeFineATM.h5m is obtained from a coupled run in e3sm, with the ne 11, np 4,
#include <cmath>
#include <sstream>
int main(
int argc,
char* argv[] )
{
std::string inputfile, outfile( "out.h5m" ), sourcefile, variable_name;
int dual_mesh = 0;
opts.
addOpt< std::string >(
"input,i",
"input mesh filename", &inputfile );
opts.
addOpt< std::string >(
"source,s",
"h5m file aligned with the mesh input file", &sourcefile );
opts.
addOpt< std::string >(
"output,o",
"output mesh filename", &outfile );
opts.
addOpt< std::string >(
"var,v",
"variable to extract and add to output file", &variable_name );
opts.
addOpt<
int >(
"pentagon,p",
"switch for dual mesh ", &dual_mesh );
std::cout << "input file: " << inputfile << "\n";
std::cout << "source file: " << sourcefile << "\n";
std::cout << "variable to copy: " << variable_name << "\n";
std::cout << "output file: " << outfile << "\n";
if( inputfile.empty() )
{
return 0;
}
Core* mb2 = new Core();
rval = mb2->load_file( sourcefile.c_str() );
MB_CHK_SET_ERR( rval,
"can't load source file" );
rval = mb2->tag_get_handle( variable_name.c_str(), sourceTag );
MB_CHK_SET_ERR( rval,
"can't get tag from file" );
int sizeTag = 0;
rval = mb2->tag_get_length( sourceTag, sizeTag );
MB_CHK_SET_ERR( rval,
"can't get size of tag " );
rval = mb2->tag_get_data_type( sourceTag, type );
MB_CHK_SET_ERR( rval,
"can't get type of tag " );
int sizeInBytes = 0;
rval = mb2->tag_get_bytes( sourceTag, sizeInBytes );
MB_CHK_SET_ERR( rval,
"can't get size in bytes of tag " );
void* defVal;
int defInt = -100000;
double defDouble = -1.e10;
{
defVal = (void*)( &defInt );
}
{
defVal = (void*)( &defDouble );
}
rval = mb2->tag_get_handle(
"GLOBAL_ID", gid2 );
MB_CHK_SET_ERR( rval,
"can't get GLOBAL_ID tag on source mesh " );
Range iniVerts;
if( 0 != dual_mesh )
{
}
std::vector< int > gids;
gids.resize( iniVerts.size() );
std::map< int, EntityHandle > fromGidToEh;
int i = 0;
for(
Range::iterator vit = iniVerts.begin(); vit != iniVerts.end(); vit++, i++ )
{
fromGidToEh[gids[i]] = *vit;
}
char* valTag = new char[sizeInBytes];
std::cout << " size of tag in bytes:" << sizeInBytes << "\n";
Range sourceVerts;
rval = mb2->get_entities_by_dimension( 0, 0, sourceVerts );
MB_CHK_SET_ERR( rval,
"can't get verts on source mesh " );
for(
Range::iterator sit = sourceVerts.begin(); sit != sourceVerts.end(); sit++ )
{
int globalId = 0;
rval = mb2->tag_get_data( gid2, &sourceHandle, 1, &globalId );
MB_CHK_SET_ERR( rval,
"can't get id on source mesh " );
rval = mb2->tag_get_data( sourceTag, &sourceHandle, 1, (
void*)valTag );
MB_CHK_SET_ERR( rval,
"can't get value on source tag " );
}
delete[] valTag;
delete mb2;
return 0;
}