예제 #1
0
int test()
{
#ifdef CH_USE_HDF5

  int error;
  HDF5Handle testFile;

  CH_assert(!testFile.isOpen());

  error = testFile.open("data.h5", HDF5Handle::CREATE);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "File creation failed "<<error<<endl;
      return error;
    }

  CH_assert(testFile.isOpen());

  Box domain(IntVect::Zero, 20*IntVect::Unit);

  DisjointBoxLayout plan1, plan2;
  {
    IntVectSet tags;

    IntVect center = 10*IntVect::Unit;

    setCircleTags(tags, 6, 1, center); //circle/sphere

    buildDisjointBoxLayout(plan1, tags, domain);

    tags.makeEmpty();

    setCircleTags(tags, 5, 2, center);

    buildDisjointBoxLayout(plan2, tags, domain);
  }
  if ( verbose )
  {
    pout() << "plan1: " << procID() << "...." << plan1 << endl;
    pout() << "plan2: " << procID() << "...." << plan2 << endl;
  }

  //test LayoutData<Real> specialization
  LayoutData<Real>  specialReal(plan1);


  LayoutData<Moment>   vlPlan(plan1);


  LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit);

  LevelData<BaseFab<int> > level2;

  level2.define(level1);

  level2.define(plan2, 1);

  for (DataIterator i(level2.dataIterator()); i.ok(); ++i)
  {
    level2[i()].setVal(2);
  }

  level1.apply(values::setVal1);

  level2.apply(values::setVal2);

  HDF5HeaderData set1;
  Real dx=0.004;
  Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4)));
  Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4)));
  int currentStep = 2332;

  set1.m_string["name"] = "set1";
  set1.m_real["dx"] = dx;
  set1.m_int["currentStep"] = currentStep;
  set1.m_intvect["some intvect or other"] = b1.smallEnd();
  set1.m_box["b1"] = b1;
  set1.m_box["b2"] = b2;

  testFile.setGroupToLevel(1);

  error = write(testFile, plan1);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box write failed "<<error<<endl;
      return error;
    }

  error = write(testFile, level1, "level1 state vector");
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(2);

  error = write(testFile, plan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box2 write failed "<<error<<endl;
      return error;
    }

  error = write(testFile, level2, "level2 state vector");
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl;
      return error;
    }

  LevelData<FArrayBox> state(plan2, 3);

  state.apply(values::setVal3);
  testFile.setGroupToLevel(0);
  set1.writeToFile(testFile);

  error = write(testFile, plan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box2 write failed "<<error<<endl;
      return error;
    }

  testFile.setGroup("/");

  error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl;
      return error;
    }

  set1.writeToFile(testFile);
  set1.writeToFile(testFile);

  testFile.close();

 CH_assert(!testFile.isOpen());

  // test the utility functions ReadUGHDF5 and WriteUGHDF5

  WriteUGHDF5("UGIO.hdf5", plan2, state, domain);

  ReadUGHDF5("UGIO.hdf5", plan2, state, domain);
  //========================================================================
  //
  //  now, read this data back in
  //
  //========================================================================

  BoxLayoutData<BaseFab<int> > readlevel1, readlevel2;

  error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "File open failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(2);
  Vector<Box> boxes;
  error = read(testFile, boxes);

  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }
  boxes.sort();
  Vector<int> assign;
  error = LoadBalance(assign, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl;
      return error;
    }
  BoxLayout readplan2(boxes, assign);
  readplan2.close();
  error = read(testFile, readlevel2, "level2 state vector", readplan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(1);
  error = read(testFile, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }

  error = LoadBalance(assign, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl;
      return error;
    }
  BoxLayout readplan1(boxes, assign);
  readplan1.close();
  if ( verbose )
  {
    pout() << "readplan1: " << procID() << "...." << readplan1 << endl;
    pout() << "readplan2: " << procID() << "...." << readplan2 << endl;
  }
  error = read(testFile, readlevel1, "level1 state vector", readplan1);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl;
      return error;
    }

  if ( verbose )
    pout() << plan1<<readplan1<<endl;

  // real test of IO, make sure the data is the same coming and going

  DataIterator l1  = level1.dataIterator();
  DataIterator rl1 = readlevel1.dataIterator();
  DataIterator l2  = level2.dataIterator();
  DataIterator rl2 = readlevel2.dataIterator();

  if (level1.boxLayout().size() != readlevel1.boxLayout().size())
    {
      if ( verbose )
        pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl;
      return 1;
    }
  if (level2.boxLayout().size() != readlevel2.boxLayout().size())
    {
      if ( verbose )
        pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl;
      return 1;
    }

  // we can assume that BoxLayout IO is tested in HDF5boxIO
  BaseFab<int>* before, *after;
  for (; l1.ok(); ++l1, ++rl1)
    {

      before = &(level1[l1()]); after = &(readlevel1[rl1()]);
      for (int c=0; c<before->nComp(); ++c)
        {
          for (BoxIterator it(level1.box(l1())); it.ok(); ++it)
            {
              if ((*before)(it(), c) != (*after)(it(), c))
                {
                  if ( verbose )
                    pout() << indent2 << "l1 != readl1 read failed "<<error<<endl;
                  return 2;
                }
            }
        }
    }

  for (; l2.ok(); ++l2, ++rl2)
    {

      before = &(level2[l2()]); after = &(readlevel2[rl2()]);
      for (int c=0; c<before->nComp(); ++c)
        {
          for (BoxIterator it(level2.box(l2())); it.ok(); ++it)
            {
              if ((*before)(it(), c) != (*after)(it(), c))
                {
                  if ( verbose )
                    pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl;
                  return 3;
                }
            }
        }
    }

  LevelData<FArrayBox> readState;
  Real dt, time;
  int refRatio;

  testFile.setGroup("/");

  error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "readLevel failed "<<error<<endl;
      return error;
    }

#ifndef CH_MPI
  // OK, now try to read one FArrayBox at a time
  // problem with DataIterator and running the out-of-core in parallel, so
  // have to think about that for now  BVS.
  FArrayBox readFAB;
  Interval  interval(1,2);
  testFile.setGroup("/");
  int index=0;
  for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit)
        {
          FArrayBox& fab = state[dit()];
          readFArrayBox(testFile, readFAB, 0, index, interval);
          for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it)
                {
                  if (readFAB(it(), 0) != fab(it(), 1))
                        {
                          if ( verbose )
                                pout() << indent2 << "state != after for out-of-core "<<error<<endl;
                          return 3;
                        }
                }
        }

#endif

  testFile.close();

 CH_assert(!testFile.isOpen());

#endif // CH_USE_HDF5

  return 0;
}
예제 #2
0
void KstCurveDialogI::new_I() {
  KstWriteLocker ml(&KST::vectorList.lock());
  KstVectorList::Iterator VX, VY;
  KstVectorList::Iterator EX, EY;
  KstVCurvePtr curve;
  KstPlot *plot;

  if (_xVector->selectedVector().isEmpty()) {
    KMessageBox::sorry(0L, i18n("New curve not made: define vectors first."));
    return;
  }

  /* find VX and VY */
  VX = KST::vectorList.findTag(_xVector->selectedVector());
  VY = KST::vectorList.findTag(_yVector->selectedVector());
  EX = KST::vectorList.findTag(_xError->selectedVector());
  EY = KST::vectorList.findTag(_yError->selectedVector());
  if (VX == KST::vectorList.end() || VY == KST::vectorList.end()) {
    kdFatal() << "Bug in kst: the XVector field in plotDialog refers to "
              << "a non existant vector...." << endl;
  }

  KstReadLocker rl1(*VX), rl2(*VY);

  QString tag_name = Select->currentText();
  tag_name.replace(i18n("<New_Curve>"), (*VY)->tagName());

  /* verify that the curve name is unique */
  if (KST::dataTagNameNotUnique(tag_name)) {
    return;
  }

  /* create the curve */
  curve = new KstVCurve(tag_name, *VX, *VY,
                        EX != KST::vectorList.end() ? *EX : KstVectorPtr(0L),
                        EY != KST::vectorList.end() ? *EY : KstVectorPtr(0L),
                        _curveAppearance->color());
  curve->setHasPoints(_curveAppearance->showPoints());
  curve->setHasLines(_curveAppearance->showLines());
  curve->Point.setType(_curveAppearance->pointType());

  if (_curvePlacement->existingPlot()) {
    /* assign curve to plot */
    plot = KST::plotList.FindKstPlot(_curvePlacement->plotName());
    plot->addCurve(curve);
  }

  if (_curvePlacement->newPlot()) {
    /* assign curve to plot */
    plot = KST::plotList.addPlot(QString::null, _curvePlacement->columns());
    _curvePlacement->appendPlot(plot->tagName(), true);
    plot->addCurve(curve);
    plot->GenerateDefaultLabels();
  }

  KST::dataObjectList.lock().readLock();
  KST::dataObjectList.append(curve.data());
  KST::dataObjectList.lock().writeUnlock();
  curve = 0L;
  emit modified();
}