[MOAB-dev] commit/MOAB: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri May 9 21:27:59 CDT 2014


2 new commits in MOAB:

https://bitbucket.org/fathomteam/moab/commits/1d0f01506089/
Changeset:   1d0f01506089
Branch:      None
User:        iulian07
Date:        2014-05-10 01:05:49
Summary:     add some examples/tools for nc data

VisTags can output tags that are size 1, and so are plotable with visit
ReadWriteTest can be used as a stress test for reading/writing in
parallel of nc data

Affected #:  3 files

diff --git a/examples/ReadWriteTest.cpp b/examples/ReadWriteTest.cpp
new file mode 100644
index 0000000..3ae6567
--- /dev/null
+++ b/examples/ReadWriteTest.cpp
@@ -0,0 +1,112 @@
+/** @example ReadWriteTest.cpp \n
+ * \brief Read mesh into MOAB and write some back \n
+ *
+ * <b>To run</b>: mpiexec -np 4 ReadWriteTest [input] [output] -O <read_opts> -o <write_opts>\n
+ *
+ * used for stress test of reader/writer
+ *  report times to read and write
+ *
+ *  example ReadWriteTest ../MeshFiles/io/fv26x46x72.t.3.nc out.nc  \
+ *  -O PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U;  \
+ *  -o PARALLEL=WRITE_PART;VARIABLE=T,U
+ */
+
+#include "moab/ParallelComm.hpp"
+#include "MBParallelConventions.h"
+#include "moab/Core.hpp"
+#include <iostream>
+#include <time.h>
+
+using namespace moab;
+using namespace std;
+
+
+int main(int argc, char **argv)
+{
+  MPI_Init(&argc, &argv);
+
+  string options;
+
+  // Need option handling here for input filename
+  if (argc < 3 ){
+   return 1;
+  }
+
+  char * input_file = argv[1];
+  char * output_file = argv[2];
+  char * read_opts = NULL;
+  char * write_opts = NULL; // tags to write, separated by commas; it is the name of the tag
+
+  if (argc>3)
+  {
+    int index=3;
+    while (index<argc)
+    {
+      if (!strcmp( argv[index], "-O")) // this is for reading options, optional
+      {
+        read_opts=argv[++index];
+      }
+      if (!strcmp( argv[index], "-o"))
+      {
+        write_opts=argv[++index];
+      }
+      index++;
+    }
+  }
+
+
+  // Get MOAB instance and read the file with the specified options
+  Interface* mb = new Core;
+  if (NULL == mb)
+    return 1;
+
+  // Get the ParallelComm instance
+  ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
+  int nprocs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
+
+
+  EntityHandle set;
+  ErrorCode rval = mb->create_meshset(MESHSET_SET, set);
+
+  clock_t tt = clock();
+
+  if (rank == 0)
+    cout << "Reading file " << input_file << "\n  with options: " << read_opts << endl
+         << " on " << nprocs << " processors\n";
+
+  rval = mb->load_file(input_file, &set, read_opts);
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
+
+  if (0==rank)
+  {
+      std::cout << "Time:  "
+            << (clock() - tt) / (double) CLOCKS_PER_SEC << " seconds" << std::endl;
+      tt = clock();
+  }
+
+  rval = mb->write_file(output_file, 0, write_opts, &set, 1);
+  if (rval != MB_SUCCESS)
+  {
+    delete mb;
+    return 1;
+  }
+
+  if (0 == rank)
+  {
+    cout << "Writing file " << output_file << "\n  with options: " << write_opts << endl;
+    cout << "Time:  " << (clock() - tt) / (double) CLOCKS_PER_SEC
+        << " seconds" << std::endl;
+    tt = clock();
+  }
+
+
+  delete mb;
+
+  MPI_Finalize();
+
+  return 0;
+}

diff --git a/examples/VisTags.cpp b/examples/VisTags.cpp
new file mode 100644
index 0000000..efba608
--- /dev/null
+++ b/examples/VisTags.cpp
@@ -0,0 +1,181 @@
+/** @example VisTags.cpp \n
+ * \brief tool for visualizing multi level tags  \n
+ * <b>To run</b>: VisTags  <inp_file><outfile> -O <read_opts> -t <tags> -l <levels>  -d <dim> \n
+ *
+ * In this example, it is shown how to create some simple tags for those tags that come from 
+ *  climate data, multiple levels.
+ *  you can read directly nc data, or *.h5m file that will have the tag with multi levels
+ *   output will be a vtk file with dense tags of form tag_name_<level> 
+ * the tag name might contain a time index too, like T0 or U0
+ * <tag> is a list of tags, separated by commas, no spaces
+ * <levels> is a list of levels, separated by commas, no spaces
+ *  dimension of entities with the tags will be specified with -d (default 2)
+ *
+ * an example of use
+ *
+ * VisTags gcrm_rc.nc  out.vtk -O VARIABLE=u -t u0,u1 -l 0,1,2 -d 2
+ * (we knew that it had variable u in the file, that it had 256 levels, that there are 2 time
+ *  steps, etc)
+ *
+ * or
+ *  VisTags gcrm_rc.nc  out.vtk  -t u0 -l 0,1,2 -d 2
+ *  (it will read all variables, but we need to know that u0 will be created as a tag)
+ *
+ *  the out.vtk file will contain u0_0, u0_1, as simple dense double tags
+ */
+
+#include <iostream>
+#include <vector>
+#include <sstream>
+#include <string>
+
+// Include header for MOAB instance and tag conventions for
+#include "moab/Core.hpp" 
+#include "MBTagConventions.hpp"
+#include "moab/FileOptions.hpp"
+
+
+int main(int argc, char **argv) {
+
+    // instantiate & load a file 
+    moab::Interface *mb = new moab::Core();
+
+    moab::ErrorCode rval;
+    if (argc <= 1) 
+       return 0;
+
+    int dimension = 2;
+    char * file_input = argv[1];
+    char * file_output = argv[2];
+    char * read_opts = NULL;
+    char * tags = NULL; // tags to write, separated by commas; it is the name of the tag
+    // in moab, it may have index after reading (T0, T1, etc)
+    char * levels = NULL; // levels, separated by commas, no spaces ( like 0,1,19 )
+    if (argc>3)
+    {
+      int index=3;
+      while (index<argc)
+      {
+        if (!strcmp( argv[index], "-O")) // this is for reading options, optional
+        {
+          read_opts=argv[++index];
+        }
+        if (!strcmp( argv[index], "-t"))
+        {
+          tags=argv[++index];
+        }
+        if (!strcmp( argv[index], "-l"))
+        {
+          levels=argv[++index];
+        }
+        if (!strcmp( argv[index], "-d"))
+        {
+          dimension=atoi(argv[++index]);
+        }
+        index++;
+      }
+    }
+    std::ostringstream opts;
+    opts << ";;TAGS=" << tags << ";LEVELS=" << levels << "\0" ;
+    moab::FileOptions fo(opts.str().c_str());
+
+    std::vector<std::string> tagsNames;
+    std::vector<int>  levelsArray;
+    fo.get_strs_option("TAGS", tagsNames);
+    fo.get_ints_option("LEVELS", levelsArray);
+
+    // now create double tags for entities of dimension
+
+    rval = mb->load_file(file_input, 0, read_opts);
+    if (rval != moab::MB_SUCCESS) {
+      std::cout <<"not loading file\n";
+      return 1;
+    }
+    moab::Range ents;
+    rval = mb->get_entities_by_dimension(0, dimension, ents);
+    if (rval != moab::MB_SUCCESS) {
+      std::cout <<"not getting ents\n";
+      return 1;
+    }
+    for (size_t i=0; i<tagsNames.size(); i++)
+    {
+      std::string tagName = tagsNames[i];
+      moab::Tag tagh;
+      rval = mb->tag_get_handle(tagName.c_str(), tagh);
+
+      if (rval != moab::MB_SUCCESS) {
+        std::cout <<"not getting tag " << tagName.c_str()<<"\n";
+        continue;
+      }
+      int len=0;
+      rval = mb->tag_get_length(tagh, len);
+      if (rval != moab::MB_SUCCESS) {
+        std::cout <<"not getting tag len" << tagName.c_str()<<"\n";
+        continue;
+      }
+      moab::DataType type;
+      rval = mb->tag_get_data_type(tagh, type) ;
+      if (rval != moab::MB_SUCCESS) {
+        std::cout <<"not getting tag type " << tagName.c_str()<<"\n";
+        continue;
+      }
+      int count;
+      void * dataptr;// assume double tags, for simplicity
+      rval = mb->tag_iterate( tagh,
+          ents.begin(),
+          ents.end(),
+          count,
+          dataptr);
+      if (rval != moab::MB_SUCCESS || count != (int)ents.size()) {
+        std::cout <<"not getting tag iterate right " << tagName.c_str()<<"\n";
+        continue;
+      }
+
+      // now create a new tag, with a new name, concatenated, and copy data there , for each level
+      for (size_t j=0; j<levelsArray.size();j++)
+      {
+        int level=levelsArray[j];
+        if (level >= len)
+        {
+          std::cout << "level too big at "<< level << "\n";
+          continue;
+        }
+        std::ostringstream newTagName;
+        newTagName << tagName <<"_" << level  ;
+        moab::Tag newTagh;
+        rval = mb->tag_get_handle(newTagName.str().c_str(), 1, type, newTagh,
+            moab::MB_TAG_DENSE | moab::MB_TAG_CREAT);
+        if (rval != moab::MB_SUCCESS ) {
+          std::cout <<"not getting new tag " << newTagName.str() <<"\n";
+          continue;
+        }
+        void * newDataPtr;
+        rval = mb->tag_iterate( newTagh,
+                            ents.begin(),
+                            ents.end(),
+                            count,
+                            newDataPtr);
+        if (rval != moab::MB_SUCCESS  || count !=(int) ents.size()) {
+          std::cout <<"not getting new tag iterate" << newTagName.str() <<"\n";
+          continue;
+        }
+        if (type==moab::MB_TYPE_DOUBLE)
+        {
+          double * ptrD = (double*) newDataPtr;
+          double *oldData = (double*)dataptr;
+          for (int k=0; k<count; k++, ptrD++)
+          {
+            *ptrD = oldData[level+count*k];
+          }
+        }
+      }
+      mb->tag_delete(tagh);// no need for the tag anymore, write it to the new file
+    }
+
+    rval = mb->write_file(file_output);
+    if (rval != moab::MB_SUCCESS)
+      std::cout <<"can't write file " << file_output << "\n";
+    else
+      std::cout <<"successfully wrote file " << file_output<< "\n";
+    return 0;
+} 

diff --git a/examples/makefile b/examples/makefile
index 41dc577..00d889b 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -65,6 +65,15 @@ PushParMeshIntoMoabF90: PushParMeshIntoMoabF90.o
 DeformMeshRemap: DeformMeshRemap.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} -lmbcoupler ${MOAB_LIBS_LINK}
 
+VisTags: VisTags.o ${MOAB_LIBDIR}/libMOAB.la
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} 
+
+ReadWriteTest: ReadWriteTest.o ${MOAB_LIBDIR}/libMOAB.la
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} 
+	
+ptest: ptest.o ${MOAB_LIBDIR}/libMOAB.la
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+
 clean:
 	rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES}
 


https://bitbucket.org/fathomteam/moab/commits/781b7e73d6f6/
Changeset:   781b7e73d6f6
Branch:      master
User:        iulian07
Date:        2014-05-10 04:19:10
Summary:     mpas file can have vars without any dimensions

ignore them for processing, we assume we will not write them, anyway
we need to see what is the issue

Affected #:  1 file

diff --git a/src/io/WriteNC.cpp b/src/io/WriteNC.cpp
index 21a2c19..18ce891 100644
--- a/src/io/WriteNC.cpp
+++ b/src/io/WriteNC.cpp
@@ -349,7 +349,14 @@ ErrorCode WriteNC::process_conventional_tags(EntityHandle fileSet)
       Tag dims_tag = 0;
       std::string dim_names = "__" + var_name + "_DIMS";
       rval = mbImpl->tag_get_handle(dim_names.c_str(), 0, MB_TYPE_OPAQUE, dims_tag, MB_TAG_ANY);
-      // FIXME: Doesn't handle variables with 0 dimension
+
+      if (moab::MB_TAG_NOT_FOUND==rval)
+      {
+        dbgOut.tprintf(2, "tag : %s not found, continue \n", dim_names.c_str());
+        start = i + 1;
+        idxVar++;
+        continue;
+      }
       ERRORR(rval, "Failed to get tag for a variable dimensions.");
       rval = mbImpl->tag_get_length(dims_tag, sz);
       ERRORR(rval, " size of dimensions for variable");

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list