lib/test/BoxTools/HDF5boxIO.cpp
// returns 0 on all tests passed.
returns 0 on all tests passed.
returns 0 on all tests passed .
int test()
{
#ifdef CH_USE_HDF5
  int error;
  HDF5Handle testFile;
  CH_assert(!testFile.isOpen());
  error = testFile.open("boxIO.h5", HDF5Handle::CREATE);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "File creation failed "<<error<<endl;
      return error;
    }
 CH_assert(testFile.isOpen());
  DisjointBoxLayout plan1, plan2;
  {
    Box domain(IntVect::Zero, 20*IntVect::Unit);
    IntVectSet tags;
    IntVect center = 10*IntVect::Unit;
    setCircleTags(tags, 6, 3, center); 
    buildDisjointBoxLayout(plan1, tags, domain);
    tags.makeEmpty();
    setCircleTags(tags, 5, 2, center);
    buildDisjointBoxLayout(plan2, tags, domain);
  }
  testFile.setGroupToLevel(0);
  error = write(testFile, plan1);
   if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box write failed "<<error<<endl;
      return error;
    }
  testFile.setGroupToLevel(1);
  error = write(testFile, plan2);
    if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box write failed "<<error<<endl;
      return error;
    }
  testFile.close();
 CH_assert(!testFile.isOpen());
  DisjointBoxLayout readplan1, readplan2;
  testFile.open("boxIO.h5", HDF5Handle::OPEN_RDONLY);
  testFile.setGroupToLevel(1);
  Vector<Box> boxes;
  Vector<int> assignments;
  error = read(testFile, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }
  LoadBalance(assignments, boxes);
  readplan2.define(boxes, assignments);
  testFile.setGroupToLevel(0);
  error = read(testFile, boxes);
   if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }
   LoadBalance(assignments, boxes);
   readplan1.define(boxes, assignments);
   LayoutIterator p1 = plan1.layoutIterator();
   LayoutIterator rp1 = readplan1.layoutIterator();
   LayoutIterator p2 = plan2.layoutIterator();
   LayoutIterator rp2 = readplan2.layoutIterator();
   if (plan1.size() != readplan1.size())
     {
       if ( verbose )
         pout() << indent2 << "plan1 size different on read "<<endl;
       return 1;
     }
   for (;p1.ok(); ++p1, ++rp1)
     {
       if (plan1.get(p1()) != readplan1.get(rp1()))
         {
           if ( verbose )
             {
               pout() << indent2 << "plan1 != readplan1  on read \n";
               pout()<<plan1<<"\n\n"<<readplan1<<endl;
             }
           return 2;
         }
     }
   if (plan2.size() != readplan2.size())
     {
       if ( verbose )
         pout() << indent2 << "plan2 size different on read "<<endl;
       return 1;
     }
   for (;p2.ok(); ++p2, ++rp2)
     {
       if (plan2.get(p2()) != readplan2.get(rp2()))
         {
           if ( verbose )
             {
               pout() << indent2 << "plan2 != readplan2  on read \n";
               pout()<<plan2<<"\n\n"<<readplan2<<endl;
             }
           return 2;
         }
     }
   testFile.close();
#endif
   return 0;
}
int test ( ) { #ifdef CH_USE_HDF5 int error ; HDF5Handle testFile ; CH_assert ( ! testFile . isOpen ( ) ) ; error = testFile . open ( " " , HDF5Handle :: CREATE ) ; if ( error != 0 ) { if ( verbose ) pout ( ) << indent2 << " " << error << endl ; return error ; } CH_assert ( testFile . isOpen ( ) ) ; DisjointBoxLayout plan1 , plan2 ; { Box domain ( IntVect :: Zero , 20 * IntVect :: Unit ) ; IntVectSet tags ; IntVect center = 10 * IntVect :: Unit ; setCircleTags ( tags , 6 , 3 , center ) ; buildDisjointBoxLayout ( plan1 , tags , domain ) ; tags . makeEmpty ( ) ; setCircleTags ( tags , 5 , 2 , center ) ; buildDisjointBoxLayout ( plan2 , tags , domain ) ; } testFile . setGroupToLevel ( 0 ) ; error = write ( testFile , plan1 ) ; if ( error != 0 ) { if ( verbose ) pout ( ) << indent2 << " " << error << endl ; return error ; } testFile . setGroupToLevel ( 1 ) ; error = write ( testFile , plan2 ) ; if ( error != 0 ) { if ( verbose ) pout ( ) << indent2 << " " << error << endl ; return error ; } testFile . close ( ) ; CH_assert ( ! testFile . isOpen ( ) ) ; DisjointBoxLayout readplan1 , readplan2 ; testFile . open ( " " , HDF5Handle :: OPEN_RDONLY ) ; testFile . setGroupToLevel ( 1 ) ; Vector < Box > boxes ; Vector < int > assignments ; error = read ( testFile , boxes ) ; if ( error != 0 ) { if ( verbose ) pout ( ) << indent2 << " " << error << endl ; return error ; } LoadBalance ( assignments , boxes ) ; readplan2 . define ( boxes , assignments ) ; testFile . setGroupToLevel ( 0 ) ; error = read ( testFile , boxes ) ; if ( error != 0 ) { if ( verbose ) pout ( ) << indent2 << " " << error << endl ; return error ; } LoadBalance ( assignments , boxes ) ; readplan1 . define ( boxes , assignments ) ; LayoutIterator p1 = plan1 . layoutIterator ( ) ; LayoutIterator rp1 = readplan1 . layoutIterator ( ) ; LayoutIterator p2 = plan2 . layoutIterator ( ) ; LayoutIterator rp2 = readplan2 . layoutIterator ( ) ; if ( plan1 . size ( ) != readplan1 . size ( ) ) { if ( verbose ) pout ( ) << indent2 << " " << endl ; return 1 ; } for ( ; p1 . ok ( ) ; ++ p1 , ++ rp1 ) { if ( plan1 . get ( p1 ( ) ) != readplan1 . get ( rp1 ( ) ) ) { if ( verbose ) { pout ( ) << indent2 << " \n " ; pout ( ) << plan1 << " \n \n " << readplan1 << endl ; } return 2 ; } } if ( plan2 . size ( ) != readplan2 . size ( ) ) { if ( verbose ) pout ( ) << indent2 << " " << endl ; return 1 ; } for ( ; p2 . ok ( ) ; ++ p2 , ++ rp2 ) { if ( plan2 . get ( p2 ( ) ) != readplan2 . get ( rp2 ( ) ) ) { if ( verbose ) { pout ( ) << indent2 << " \n " ; pout ( ) << plan2 << " \n \n " << readplan2 << endl ; } return 2 ; } } testFile . close ( ) ; #endif return 0 ; }
returns 0 on all tests passed.
returns 0 on all tests passed .
//circle/sphere //==================================================================== // now the test: