moab
ListSetsNTagsCXX.cpp
Go to the documentation of this file.
00001 
00009 #include <iostream>
00010 #include <cstdlib>
00011 #include <cstring>
00012 #include <vector>
00013 #include "iMesh.h"
00014 
00015 #define ERRORR(a) {if (iBase_SUCCESS != err) {std::cout << a << std::endl; return err;}}
00016 
00017 int main( int argc, char *argv[] )
00018 {
00019   const char *filename;
00020   bool read_par = false;
00021   if (argc < 2 || !strcmp(argv[1], "-h")) {
00022     std::cout << "Usage: " << argv[0] << " <filename> [-p]" << std::endl;
00023     return 0;
00024   }
00025   else {
00026       // Check command line arg
00027     filename = argv[1];
00028 
00029     if (argc > 2 && !strcmp(argv[2], "-p")) read_par = true;
00030   }
00031   
00032     // create the Mesh instance
00033   iMesh_Instance mesh;
00034   int err;
00035   iMesh_newMesh(NULL, &mesh, &err, 0);
00036   ERRORR("Error creating new mesh.\n");
00037   
00038   
00039   iBase_EntitySetHandle root_set;
00040   iMesh_getRootSet(mesh, &root_set, &err);
00041   ERRORR("Couldn't get root set.");
00042   
00043     // load the mesh
00044   if (read_par) {
00045     const char *opt = " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION moab:PARTITION_DISTRIBUTE moab:PARALLEL_RESOLVE_SHARED_ENTS moab:DEBUG_PIO=2 moab:DEBUG_IO=2 moab:SETS=SETS ";
00046     iMesh_load(mesh, root_set, filename, opt, &err, strlen(filename), strlen(opt));
00047   }
00048   else
00049     iMesh_load(mesh, root_set, filename, NULL, &err, strlen(filename), 0);
00050   ERRORR("Couldn't load mesh.");
00051 
00052     // get all sets
00053   iBase_EntitySetHandle *sets = NULL;
00054   int sets_alloc = 0, sets_size;
00055   iMesh_getEntSets(mesh, root_set, 1, &sets, &sets_alloc, &sets_size, &err);
00056   ERRORR("Couldn't get all sets.");
00057 
00058     // iterate through them, checking whether they have tags
00059   iBase_TagHandle *tags = NULL;
00060   int tags_alloc = 0, tags_size;
00061   int i, j;
00062   for (i = 0; i < sets_size; i++) {
00063       // get connectivity
00064     iMesh_getAllEntSetTags(mesh, sets[i], &tags, &tags_alloc, &tags_size, &err);
00065     ERRORR("Failed to get ent set tags.");
00066 
00067     if (0 != tags_size) {
00068       std::cout << "Set " << sets[i] << "; Tags:" << std::endl;
00069       
00070         // list tag names on this set
00071       for (j = 0; j < tags_size; j++) {
00072         char tname[128];
00073         std::vector<int> int_val;
00074         std::vector<double> dbl_val;
00075         iMesh_getTagName(mesh, tags[j], tname, &err, sizeof(tname));
00076         tname[sizeof(tname)-1] = '\0';
00077         int tag_type, tag_size;
00078         iMesh_getTagType(mesh, tags[j], &tag_type, &err);
00079         ERRORR("Failed to get tag type.");
00080         iMesh_getTagType(mesh, tags[j], &tag_size, &err);
00081         ERRORR("Failed to get tag size.");
00082         if (iBase_INTEGER == tag_type) {
00083           int_val.resize(tag_size);
00084           iMesh_getEntSetIntData(mesh, sets[i], tags[j], &int_val[0], &err);
00085           ERRORR("Failed to get int data type.");
00086           std::cout << tname << " = " << int_val[0] ;
00087           if (tag_size > 1) 
00088             for (int k = 1; k < tag_size; i++) std::cout << ", " << int_val[k];
00089           std::cout << std::endl;
00090         }
00091         else if (iBase_DOUBLE == tag_type) {
00092           dbl_val.resize(tag_size);
00093           iMesh_getEntSetDblData(mesh, sets[i], tags[j], &dbl_val[0], &err);
00094           std::cout << tname << " = " << dbl_val[0] ;
00095           if (tag_size > 1) 
00096             for (int k = 1; k < tag_size; i++) std::cout << ", " << dbl_val[k];
00097           std::cout << std::endl;
00098         }
00099         else std::cout << tname << " (opaque) " << std::endl;
00100       }
00101     }
00102     std::cout << std::endl;
00103     
00104     free(tags);
00105     tags = NULL;
00106     tags_alloc = 0;
00107   }
00108   
00109   free(sets);
00110 
00111   iMesh_dtor(mesh, &err);
00112   ERRORR("Failed to destruct interface.");
00113   
00114   return 0;
00115 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines