当前位置: 首页>>代码示例>>C++>>正文


C++ FileIO::getLine方法代码示例

本文整理汇总了C++中FileIO::getLine方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::getLine方法的具体用法?C++ FileIO::getLine怎么用?C++ FileIO::getLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO::getLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **args) {
  
  int nx, ny, nz;

  cout << "Enter nx ny nz: ";
  cin >> nx;
  cin >> ny;
  cin >> nz;
//  nx = 1;
//  ny = 2;
//  nz = 3;

  int n = nx*ny*nz;

  int sample_nx, sample_ny, sample_nz;
  sample_nx = 32;
  sample_ny = 32;
  sample_nz = 32;
  double x_scale = ((double)nx)/((double)sample_nx);
  double y_scale = ((double)ny)/((double)sample_ny);
  double z_scale = ((double)nz)/((double)sample_nz);
  int sample_n = sample_nx*sample_ny*sample_nz;

  char filename[1024];
  sprintf(filename,"parameters-%d.h5",nx);

  HDF *file = new HDF(filename,1);
  int compress = 0;

  file->createFileSpace(1,n,NULL,NULL);
  printf("Cell Ids\n");
  file->createDataSet("Cell Ids",H5T_NATIVE_INT,compress);

  int *cell_ids = new int[n];
  for (int i=0; i<n; i++)
    cell_ids[i] = i+1;

  file->setHyperSlab(n);
  file->createMemorySpace(1,n,NULL,NULL);
  file->writeInt(cell_ids);

  delete [] cell_ids;
  cell_ids = NULL;

  file->closeDataSet();
 // file->closeDataSpaces();

  printf("Permeability\n");
  file->createDataSet("Permeability",H5T_NATIVE_DOUBLE,compress);

  double *values = new double[n];
  for (int i=0; i<n; i++) values[i] = 0.;

  double *sample_values = new double[sample_n];
  for (int i=0; i<sample_n; i++) sample_values[i] = 0.;

//  strcpy(filename,"permeability.final");
  strcpy(filename,"permeability.sample");
  FileIO *datafile = new FileIO(filename);
//  for (int i=0; i<n; i++) {
  for (int i=0; i<sample_n; i++) {
    datafile->getLine();
//    datafile->readDouble(&values[i]);
    datafile->readDouble(&sample_values[i]);
  }
  delete datafile;

  int count = 0;
  for (int k=0; k<nz; k++) {
    int kk = (int)(((double)k)/z_scale);
    for (int j=0; j<ny; j++) {
      int jj = (int)(((double)j)/y_scale);
      for (int i=0; i<nx; i++) {
        int ii = (int)(((double)i)/x_scale);
        int index = ii + jj*sample_nx + kk*sample_nx*sample_ny;
        values[count++] = sample_values[index];
      }
    }
  }

  file->setHyperSlab(n);
  file->createMemorySpace(1,n,NULL,NULL);
  file->writeDouble(values);

  file->closeDataSet();
 // file->closeDataSpaces();

  // use same data space
  printf("Porosity\n");
  file->createDataSet("Porosity",H5T_NATIVE_DOUBLE,compress);

  for (int i=0; i<sample_n; i++) sample_values[i] = 0.;

//  strcpy(filename,"porosity.final");
  strcpy(filename,"porosity.sample");
  datafile = new FileIO(filename);
  for (int i=0; i<n; i++) values[i] = 0.;
//  for (int i=0; i<n; i++) {
  for (int i=0; i<sample_n; i++) {
    datafile->getLine();
//.........这里部分代码省略.........
开发者ID:bishtg,项目名称:pflotran-for-testing,代码行数:101,代码来源:DataLoader.cpp

示例2: strcpy

MAD::MAD(Grid **grid_) {

  ifc_polygon = NULL;
  river_polygon = NULL;
  ascii_grids = NULL;
  spp_polygon = NULL;

  PetscReal mx = 1.;
  PetscReal my = 1.;
  PetscReal mz = 1.;

  PetscInt nx, ny, nz;

  char filename[1024];
  PetscBool option_found;
  strcpy(filename,"mdt.in");
  PetscOptionsGetString(PETSC_NULL,"-mdtin",filename,1024,&option_found);

  FileIO *file = new FileIO(filename);
  file->getLine();
  file->readInt(&nx);
  file->readInt(&ny);
  file->readInt(&nz);
  delete file;

  PetscReal dx;
  PetscReal dy;
  PetscReal dz;// */

  PetscReal len_x = 120.;
  PetscReal len_y = 122;
  PetscReal len_z = 60.;

  dx = len_x/(PetscReal)nx;
  dy = len_y/(PetscReal)ny;
  dz = len_z/(PetscReal)nz;

  PetscInt n = nx*ny*nz;

  PetscPrintf(PETSC_COMM_WORLD,"nx = %d, dx = %f, lenx = %f\n",nx,dx,nx*dx);
  PetscPrintf(PETSC_COMM_WORLD,"ny = %d, dy = %f, leny = %f\n",ny,dy,ny*dy);
  PetscPrintf(PETSC_COMM_WORLD,"nz = %d, dz = %f, lenz = %f\n",nz,dz,nz*dz);
  *grid_ = new Grid(nx,ny,nz);
  Grid *grid = *grid_;

// grid spacing with a bias
#if 0
  PetscReal sum_x = 0.;
  PetscReal sum_y = 0.;
  dx = 0.8470329472543
  PetscReal *dx_array = new double[nx];
  PetscReal *dy_array = new double[ny];
  PetscReal *dz_array = new double[nz];
  for (int i=0; i<nx; i++)
    dx_array[i] = 10.;
  for (int i=0; i<ny; i++)
    dy_array[i] = 10.;
  for (int i=0; i<nz; i++)
    dz_array[i] = 0.25;

  for (int i=11; i<19; i++) {
    dx_array[i] = 10.*pow(1.30242241518419,(double)(10-i));
    sum_x += dx_array[i];
  }

  for (int i=19; i<89; i++) {
    dx_array[i] = 1.;
    sum_x += dx_array[i];
  }

  for (int i=89; i<97; i++) {
    dx_array[i] = 10.*pow(1.30242241518419,(double)(i-97));
    sum_x += dx_array[i];
  }

  for (int i=97; i<9; i++) {
    dy_array[110+i] = 10.*pow(1.353088,i+1.);
    dy_array[9-i] = 10.*pow(1.353088,i+1.);
    sum_y += dy_array[9-i];
  }
  grid->setGridSpacing(dx_array,dy_array,dz_array);
#else
  grid->setGridSpacing(dx,dy,dz);
#endif

//  grid->setOrigin(593618.9,114565.1,70.);
  grid->setRotation(34.); // must come before ->setOrigin()
  grid->setOrigin(594237.2891,115984.7447,70.);

//  grid->computeCoordinates();
//  grid->computeConnectivity();
  grid->computeCellMapping();
  grid->setUpCells();
  grid->computeVertexMapping();
  grid->setUpVertices();
  grid->mapVerticesToCells();

  ifc_polygon = new Polygon();
  ifc_polygon->createIFCPolygon();

//.........这里部分代码省略.........
开发者ID:bishtg,项目名称:pflotran-for-testing,代码行数:101,代码来源:MAD.cpp


注:本文中的FileIO::getLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。