Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
TagIterateC.cpp File Reference
#include "iMesh.h"
#include "iMesh_extensions.h"
#include <cstdio>
#include <cstring>
+ Include dependency graph for TagIterateC.cpp:

Go to the source code of this file.

Macros

#define CHKERR(e, m)
 

Functions

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

Macro Definition Documentation

◆ CHKERR

#define CHKERR (   e,
 
)
Value:
if( iBase_SUCCESS != ( e ) ) \
{ \
printf( m ); \
return 1; \
}

Definition at line 11 of file TagIterateC.cpp.

Function Documentation

◆ main()

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

Definition at line 18 of file TagIterateC.cpp.

19 {
20  iMesh_Instance mesh;
21  iBase_EntitySetHandle root_set;
22  int err;
23  const char* filename;
24  iBase_EntityArrIterator iter;
25  iBase_TagHandle tagh;
26  int count, atend;
27  double* tag_data;
28  int num_regions;
29 
30  if( argc == 2 )
31  {
32  filename = argv[1];
33  }
34  else
35  {
36  printf( "Usage: %s <mesh_filename>\n", argv[0] );
37  return 0;
38  }
39 
40  /* initialize the Mesh */
41  iMesh_newMesh( NULL, &mesh, &err, 0 );CHKERR( err, "Failed to create a mesh instance.\n" );
42  iMesh_getRootSet( mesh, &root_set, &err );CHKERR( err, "Failed to return a root set.\n" );
43 
44  iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 );
45 
46  /* get the number of regions in the mesh */
47  iMesh_getNumOfType( mesh, root_set, iBase_REGION, &num_regions, &err );CHKERR( err, "Failed to get number of regions." );
48 
49  /* get an iterator to all regions in the model */
50  iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );CHKERR( err, "Failed to create iterator over regions." );
51 
52  /* create a tag to put on the regions */
53  iMesh_createTagWithOptions( mesh, "dumtag", "moab:TAG_STORAGE_TYPE=DENSE moab:TAG_DEFAULT_VALUE=0.0", 1,
54  iBase_DOUBLE, &tagh, &err, 6, 54 );CHKERR( err, "Failed to create a tag.\n" );
55 
56  atend = 0;
57 
58  while( !atend )
59  {
60 
61  /* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet
62  */
63  iMesh_tagIterate( mesh, tagh, iter, &tag_data, &count, &err );CHKERR( err, "Failed to create a tag.\n" );
64 
65  /* step the iterator over count entities */
66  iMesh_stepEntArrIter( mesh, iter, count, &atend, &err );CHKERR( err, "Failed to step iterator.\n" );
67 
68  /* operate on tag data, or store it for later */
69  }
70 
71  iMesh_dtor( mesh, &err );CHKERR( err, "Failed to destroy iMesh instance.\n" );
72 
73  return 0;
74 }

References CHKERR.