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


C++ H5Fcreate函数代码示例

本文整理汇总了C++中H5Fcreate函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Fcreate函数的具体用法?C++ H5Fcreate怎么用?C++ H5Fcreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

int
main()
{
   printf("\n*** Checking HDF5 dimscales detach.\n");
   printf("*** Creating a file with two vars with one dimension scale...");
   {
      hid_t fileid, grpid, spaceid, var1_id, var2_id, dimscaleid, cparmsid;
      hid_t fcpl_id, fapl_id, create_propid, access_propid;
      hsize_t dims[NDIMS] = {DIM_LEN};
      char dimscale_wo_var[STR_LEN];
      float data = 42;

      /* Create file. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
      if (H5Pset_cache(fapl_id, 0, CHUNK_CACHE_NELEMS, CHUNK_CACHE_SIZE,
		       CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_18, H5F_LIBVER_18) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;

      /* Create dimension scale. */
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
      if ((dimscaleid = H5Dcreate1(grpid, DIMSCALE_NAME, H5T_IEEE_F32BE,
				   spaceid, create_propid)) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, DIM_LEN);
      if (H5DSset_scale(dimscaleid, dimscale_wo_var) < 0) ERR;

      /* Create a variable that uses this dimension scale. */
      if ((access_propid = H5Pcreate(H5P_DATASET_ACCESS)) < 0) ERR;
      if (H5Pset_chunk_cache(access_propid, CHUNK_CACHE_NELEMS,
   			     CHUNK_CACHE_SIZE, CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_fill_value(create_propid, H5T_NATIVE_FLOAT, &data) < 0) ERR;
      if (H5Pset_layout(create_propid, H5D_CONTIGUOUS) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(NDIMS, dims, dims)) < 0) ERR;
      if ((var1_id = H5Dcreate2(grpid, VAR1_NAME, H5T_NATIVE_FLOAT, spaceid, 
				H5P_DEFAULT, create_propid, access_propid)) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      if (H5Pclose(access_propid) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5DSattach_scale(var1_id, dimscaleid, 0) < 0) ERR;

      /* Create another variable that uses this dimension scale. */
      if ((access_propid = H5Pcreate(H5P_DATASET_ACCESS)) < 0) ERR;
      if (H5Pset_chunk_cache(access_propid, CHUNK_CACHE_NELEMS,
   			     CHUNK_CACHE_SIZE, CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_fill_value(create_propid, H5T_NATIVE_FLOAT, &data) < 0) ERR;
      if (H5Pset_layout(create_propid, H5D_CONTIGUOUS) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(NDIMS, dims, dims)) < 0) ERR;
      if ((var2_id = H5Dcreate2(grpid, VAR2_NAME, H5T_NATIVE_FLOAT, spaceid, 
				H5P_DEFAULT, create_propid, access_propid)) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      if (H5Pclose(access_propid) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5DSattach_scale(var2_id, dimscaleid, 0) < 0) ERR;

      /* Now detach the scales and remove the dimscale. This doesn't
       * work if I reverse the order of the statements. */
      if (H5DSdetach_scale(var2_id, dimscaleid, 0) < 0) ERR;     
      if (H5DSdetach_scale(var1_id, dimscaleid, 0) < 0) ERR;      

      /* Fold up our tents. */
      if (H5Dclose(var1_id) < 0) ERR;
      if (H5Dclose(dimscaleid) < 0) ERR;
      if (H5Gclose(grpid) < 0) ERR;
      if (H5Fclose(fileid) < 0) ERR;

      /* /\* Now read the file and check it. *\/ */
      /* { */
      /* 	 hid_t fileid, spaceid = 0, datasetid = 0; */
      /* 	 hsize_t num_obj, i; */
      /* 	 int obj_class; */
      /* 	 char obj_name[STR_LEN + 1]; */
      /* 	 char dimscale_name[STR_LEN+1]; */
      /* 	 htri_t is_scale; */
      /* 	 char label[STR_LEN+1]; */
      /* 	 int num_scales; */
      /* 	 hsize_t dims[1], maxdims[1]; */
      /* 	 H5G_stat_t statbuf; */
      /* 	 HDF5_OBJID_T dimscale_obj, vars_dimscale_obj; */
      /* 	 struct nc_hdf5_link_info link_info; */
      /* 	 hsize_t idx = 0; */
//.........这里部分代码省略.........
开发者ID:U-238,项目名称:gempak,代码行数:101,代码来源:tst_h_dimscales4.c

示例2: h5block_init

/* initializes hdf5 struct and writes some of the initially known
   problem properties such as state variable names into hdf5 file*/
hdf5block_t* /*freshly allocated struct with ids and size parameters*/
h5block_init(char *output_file, /*will create this file for writing*/
	     ode_model_parameters *omp, /*contains MCMC problem description*/
	     size_t Samples, /* MCMC sample size*/
	     const char **x_name, /*ODE model State Variable names, array of strings*/
	     const char **p_name, /*ODE model parameter names, array of strings*/
	     const char **f_name)/*ODE model output function names, array of strings*/
{
  hsize_t *size=malloc(sizeof(hsize_t)*2);
  hsize_t *chunk_size=malloc(sizeof(hsize_t)*2);
  hid_t file_id = H5Fcreate(output_file, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
  assert(file_id>0);
  int D=get_number_of_MCMC_variables(omp);
  int N=get_number_of_state_variables(omp);
  int P=get_number_of_model_parameters(omp);
  int F=get_number_of_model_outputs(omp);
  
  char *x_names=flatten(x_name, (size_t) N, "; ");
  char *p_names=flatten(p_name, (size_t) P, "; ");
  char *f_names=flatten(f_name, (size_t) F, "; ");

  herr_t NameWriteError=0;
  NameWriteError&=H5LTmake_dataset_string(file_id,"StateVariableNames",x_names);
  NameWriteError&=H5LTmake_dataset_string(file_id,"ParameterNames",p_names);
  NameWriteError&=H5LTmake_dataset_string(file_id,"OutputFunctionNames",f_names);
  if (NameWriteError){
    fprintf(stderr,"[h5block_init] writing (x,p,f)-names into hdf5 file failed.");
  }/* else {
    printf("# [main] all names have been written to file «%s».\n",output_file);
    }*/
  free(x_names);
  free(p_names);
  free(f_names);
  
  hid_t para_property_id = H5Pcreate(H5P_DATASET_CREATE);
  hid_t post_property_id = H5Pcreate(H5P_DATASET_CREATE);
  
  /* here we set a «chunk size», which will coincide with the hyperslabs we select to write output*/
  // parameter sample chunk size:
  chunk_size[0]=CHUNK;
  chunk_size[1]=D;
  H5Pset_chunk(para_property_id, 2, chunk_size);
  hid_t para_chunk_id=H5Screate_simple(2, chunk_size, NULL); // a dataspace to write chunks/hyperslabs
  
  // posterior probability distribution chunk size:
  chunk_size[0]=CHUNK;
  chunk_size[1]=1;
  H5Pset_chunk(post_property_id, 2, chunk_size);
  hid_t post_chunk_id=H5Screate_simple(2, chunk_size, NULL);
  // hyperslab selection
  hsize_t *offset, *stride, *count, *block;
  offset=malloc(sizeof(hsize_t)*2);
  stride=malloc(sizeof(hsize_t)*2);
  count=malloc(sizeof(hsize_t)*2);
  block=malloc(sizeof(hsize_t)*2);  
  // hsize_t offset[2]={0,0}, stride[2]={1,1}, count[2]={1,1}, block[2];
  int i;
  for (i=0;i<2;i++) offset[i]=0;
  for (i=0;i<2;i++) stride[i]=1;
  for (i=0;i<2;i++)  count[i]=1;  
  block[0]=CHUNK;
  block[1]=D;

  // hdf5 file setup
  size[0]=Samples;
  size[1]=D;
  hid_t para_dataspace_id=H5Screate_simple(2, size, NULL);
  size[0]=Samples;
  size[1]=1;
  hid_t post_dataspace_id=H5Screate_simple(2, size, NULL);
    assert(post_dataspace_id>0 && para_dataspace_id>0);
  
  hid_t parameter_set_id = H5Dcreate2(file_id, "LogParameters", H5T_NATIVE_DOUBLE, para_dataspace_id, H5P_DEFAULT, para_property_id, H5P_DEFAULT);
  hid_t posterior_set_id = H5Dcreate2(file_id, "LogPosterior", H5T_NATIVE_DOUBLE, post_dataspace_id, H5P_DEFAULT, post_property_id, H5P_DEFAULT);
  assert(parameter_set_id>0 && posterior_set_id>0);
  //copy ids to struct
  hdf5block_t *h5block;
  h5block = malloc(sizeof(hdf5block_t));
  h5block->file_id = file_id;
  h5block->para_property_id = para_property_id;
  h5block->post_property_id = post_property_id;
  h5block->para_chunk_id = para_chunk_id;
  h5block->post_chunk_id = post_chunk_id;
  h5block->para_dataspace_id = para_dataspace_id;
  h5block->post_dataspace_id = post_dataspace_id;
  h5block->parameter_set_id = parameter_set_id;
  h5block->posterior_set_id = posterior_set_id;
  h5block->size = size;
  h5block->chunk_size = chunk_size;
  h5block->offset = offset;
  h5block->stride = stride;
  h5block->count = count;
  h5block->block = block;
  return h5block;
}
开发者ID:a-kramer,项目名称:mcmc_clib,代码行数:97,代码来源:ode_smmala.c

示例3: main

int main( void )
{
  Particle dst_buf[NRECORDS];
  /* Calculate the size and the offsets of our struct members in memory */
  size_t dst_size =  sizeof( Particle );
  size_t dst_offset[NFIELDS] = { HOFFSET( Particle, name ),
				 HOFFSET( Particle, lati ),
				 HOFFSET( Particle, longi ),
				 HOFFSET( Particle, pressure ),
				 HOFFSET( Particle, temperature )};
  size_t dst_sizes[NFIELDS] = { sizeof( dst_buf[0].name),
				sizeof( dst_buf[0].lati),
				sizeof( dst_buf[0].longi),
				sizeof( dst_buf[0].pressure),
				sizeof( dst_buf[0].temperature)};
  size_t field_offset_pos[2] = { HOFFSET( Position, lati ),
				 HOFFSET( Position, longi )};
  hid_t      field_type[NFIELDS];
  hid_t      string_type;
  hid_t      fileID;
  hsize_t    chunk_size = 10;
  Particle   fill_data[1] =
    { {"no data",-1,-1, -99.0f, -99.0} };  /* Fill value particle */
  hsize_t    start;                        /* Record to start reading/writing */
  hsize_t    nrecords;                     /* Number of records to read/write */
  int        compress  = 0;
  int        n;
  herr_t     status;
  Particle  *p_data = NULL;               /* Initially no data */
  float      pressure_in [NRECORDS_ADD] = /* Define new values for the field "Pressure"  */
    { 0.0f,1.0f,2.0f};
  Position   position_in[NRECORDS_ADD] = {/* Define new values for "Latitude,Longitude"  */
    {0,0},
    {10,10},
    {20,20}};
  NamePressure   namepre_in[NRECORDS_ADD] =/* Define new values for "Name,Pressure"  */
    { {"zero",0.0f},
      {"one",   1.0f},
      {"two",   2.0f},
    };
  size_t field_sizes_pos[2]=
    {
      sizeof(position_in[0].longi),
      sizeof(position_in[0].lati)
    };
  size_t field_sizes_pre[1]=
    {
      sizeof(namepre_in[0].pressure)
    };
  
  /* Initialize the field field_type */
  string_type = H5Tcopy( H5T_C_S1 );
  H5Tset_size( string_type, 16 );
  field_type[0] = string_type;
  field_type[1] = H5T_NATIVE_INT;
  field_type[2] = H5T_NATIVE_INT;
  field_type[3] = H5T_NATIVE_FLOAT;
  field_type[4] = H5T_NATIVE_DOUBLE;
  
  /*__________________________________________________________________
    Create a new file using default properties.
  */

  fileID = H5Fcreate ("h5_table_04.h5",
		       H5F_ACC_TRUNC,
		       H5P_DEFAULT,
		       H5P_DEFAULT);
  
  /*__________________________________________________________________
    Make the table
  */

  status = H5TBmake_table ("Table Title",
			   fileID,
			   TABLE_NAME,
			   NFIELDS,
			   NRECORDS,
			   dst_size,
			   field_names,
			   dst_offset,
			   field_type,
			   chunk_size,
			   fill_data,
			   compress,
			   p_data);

  /*__________________________________________________________________
    Write the pressure field starting at record 2.
  */

  start    = 2;
  nrecords = NRECORDS_ADD;
  status   = H5TBwrite_fields_name (fileID,
				    TABLE_NAME,
				    "Pressure",
				    start,
				    nrecords,
				    sizeof( float ),
				    0,
				    field_sizes_pre,
//.........这里部分代码省略.........
开发者ID:SterVeen,项目名称:DAL1,代码行数:101,代码来源:h5_table_04.c

示例4: test_core

/*-------------------------------------------------------------------------
 * Function:    test_core
 *
 * Purpose:     Tests the file handle interface for CORE driver
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Tuesday, Sept 24, 2002
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_core(void)
{
    hid_t       file=(-1), fapl, access_fapl = -1;
    char        filename[1024];
    void        *fhandle=NULL;
    hsize_t     file_size;
    int    *points = NULL, *check = NULL, *p1, *p2;
    hid_t  dset1=-1, space1=-1;
    hsize_t  dims1[2];
    int    i, j, n;

    TESTING("CORE file driver");

    /* Set property list and file name for CORE driver */
    fapl = h5_fileaccess();
    if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
        TEST_ERROR;
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);

    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;

    /* Retrieve the access property list... */
    if ((access_fapl = H5Fget_access_plist(file)) < 0)
        TEST_ERROR;

    /* Check that the driver is correct */
    if(H5FD_CORE != H5Pget_driver(access_fapl))
        TEST_ERROR;

    /* ...and close the property list */
    if (H5Pclose(access_fapl) < 0)
        TEST_ERROR;

    if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle) < 0)
        TEST_ERROR;
    if(fhandle==NULL)
    {
        printf("fhandle==NULL\n");
               TEST_ERROR;
    }

    /* Check file size API */
    if(H5Fget_filesize(file, &file_size) < 0)
        TEST_ERROR;

    /* There is no garantee the size of metadata in file is constant.
     * Just try to check if it's reasonable.  Why is this 4KB?
     */
    if(file_size<2*KB || file_size>6*KB)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;


    /* Open the file with backing store off for read and write.
     * Changes won't be saved in file. */
    if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, FALSE) < 0)
        TEST_ERROR;

    if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
        TEST_ERROR;

    /* Allocate memory for data set. */
    if(NULL == (points = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
        TEST_ERROR;
    if(NULL == (check = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
        TEST_ERROR;

    /* Initialize the dset1 */
    p1 = points;
    for(i = n = 0; i < DSET1_DIM1; i++)
        for(j = 0; j < DSET1_DIM2; j++)
            *p1++ = n++;

    /* Create the data space1 */
    dims1[0] = DSET1_DIM1;
    dims1[1] = DSET1_DIM2;
    if((space1 = H5Screate_simple(2, dims1, NULL)) < 0)
        TEST_ERROR;

    /* Create the dset1 */
    if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;

//.........这里部分代码省略.........
开发者ID:FilipeMaia,项目名称:hdf5,代码行数:101,代码来源:vfd.c

示例5: test_sec2

/*-------------------------------------------------------------------------
 * Function:    test_sec2
 *
 * Purpose:     Tests the file handle interface for SEC2 driver
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Tuesday, Sept 24, 2002
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_sec2(void)
{
  hid_t        file            = -1;
  hid_t        fapl            = -1;
  hid_t        access_fapl     = -1;
    char         filename[1024];
    int          *fhandle        = NULL;
    hsize_t      file_size       = 0;

    TESTING("SEC2 file driver");

    /* Set property list and file name for SEC2 driver. */
    fapl = h5_fileaccess();
    if(H5Pset_fapl_sec2(fapl) < 0)
        TEST_ERROR;
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);

    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;

    /* Retrieve the access property list... */
    if((access_fapl = H5Fget_access_plist(file)) < 0)
        TEST_ERROR;

    /* Check that the driver is correct */
    if(H5FD_SEC2 != H5Pget_driver(access_fapl))
        TEST_ERROR;

    /* ...and close the property list */
    if(H5Pclose(access_fapl) < 0)
        TEST_ERROR;

    /* Check file handle API */
    if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle) < 0)
        TEST_ERROR;
    if(*fhandle < 0)
        TEST_ERROR;

    /* Check file size API */
    if(H5Fget_filesize(file, &file_size) < 0)
        TEST_ERROR;

    /* There is no guarantee the size of metadata in file is constant.
     * Just try to check if it's reasonable.  It's 2KB right now.
     */
    if(file_size < 1 * KB || file_size > 4 * KB)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;

    h5_cleanup(FILENAME, fapl);
    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Fclose(file);
    } H5E_END_TRY;
    return -1;
}
开发者ID:FilipeMaia,项目名称:hdf5,代码行数:76,代码来源:vfd.c

示例6: main

int
main (void)
{
    hid_t       file,  dataset2;        /* file and dataset handles */
    hid_t       datatype16;             /* handles */
    hid_t 	dataspace2;     /* handles */
    hsize_t     dimsf2[2];       /* dataset dimensions */
    hid_t       aid;           /* dataspace identifiers */
    hid_t       attr2;         /* attribute identifiers */
    herr_t      status;
    int16_t     data2[SIZE][SIZE]; /* data to write*/
    int         i, j, n;

    n = 0;
    for(i = 0; i < SIZE; i++)
	for(j = 0; j < SIZE; j++)
	    data2[i][j] = n++;
    /*
     * Assigns minimal and maximal values of int16 to data2 and 
     * they will be used to check boudary values.
     */
    data2[0][0] = -32768;
    data2[1][1] =  32767; 

    /*
     * Create a new file using H5F_ACC_TRUNC access,
     * default file creation properties, and default file
     * access properties.
     */
    file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Set each dimension size to 0.
     */
    dimsf2[0] = 0;
    dimsf2[1] = 0;

    dataspace2 = H5Screate_simple(2, dimsf2, NULL);

    /*
     * Define datatype for the data in the file.
     */

    datatype16  = H5Tcopy(H5T_NATIVE_SHORT);
    /*
     * Create a new dataset within the file using defined dataspace and
     * datatype and default dataset creation properties.
     */
    dataset2 = H5Dcreate2(file, "dataset_2d", datatype16, dataspace2, 
                          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Write the data although it has no effect because each dim size is 0.
     */
    status = H5Dwrite(dataset2, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, 
       H5P_DEFAULT, data2); 

    /*
     * Create 2D attributes.
     */
    attr2   = H5Acreate2(dataset2, "attribute_2d", datatype16, dataspace2, 
                         H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Write the data although it has no effect because each dim size is 0.
     */
    status  = H5Awrite(attr2, datatype16, data2);
    H5Aclose(attr2);

    /*
     * Close/release resources.
     */
    H5Dclose(dataset2);
    H5Tclose(datatype16);
    H5Sclose(dataspace2);
    H5Fclose(file);

    return 0;
}
开发者ID:OPENDAP,项目名称:hdf5_handler,代码行数:79,代码来源:t_space_zero.c

示例7: arma_H5Fcreate

 hid_t arma_H5Fcreate(const char* name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
   {
   return H5Fcreate(name, flags, fcpl_id, fapl_id);
   }
开发者ID:bingo4508,项目名称:Deep-Learning,代码行数:4,代码来源:wrapper.cpp

示例8: main

int main(void)
{
    hid_t       file=(-1), fapl, space=(-1), dset=(-1);
    char        dname[]="dataset";
    int         i, j;
    int         buf[FAMILY_NUMBER][FAMILY_SIZE];
    hsize_t     dims[2]={FAMILY_NUMBER, FAMILY_SIZE};

    /* Set property list and file name for FAMILY driver */
    if ((fapl=H5Pcreate(H5P_FILE_ACCESS)) < 0) {
        perror ("H5Pcreate");
        exit (1);
    }

    if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) {
        perror ("H5Pset_fapl_family");
        exit (1);
    }

    if((file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) {
        perror("H5Fcreate");
        exit(1);
    }

    /* Create and write dataset */
    if((space = H5Screate_simple(2, dims, NULL)) < 0) {
        perror("H5Screate_simple");
        exit(1);
    }


    if((dset = H5Dcreate2(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        perror("H5Dcreate2");
        exit(1);
    }


    for(i = 0; i<FAMILY_NUMBER; i++)
        for(j = 0; j<FAMILY_SIZE; j++)
            buf[i][j] = i * 10000 + j;

    if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) {
        perror("H5Dwrite");
        exit(1);
    }


    if(H5Sclose(space) < 0) {
        perror ("H5Sclose");
        exit (1);
    }

    if(H5Dclose(dset) < 0) {
        perror ("H5Dclose");
        exit (1);
    }

    if(H5Pclose(fapl) < 0) {
        perror ("H5Pclose");
        exit (1);
    }

    if(H5Fclose(file) < 0) {
        perror ("H5Fclose");
        exit (1);
    }

    puts(" PASSED"); fflush(stdout);

    return 0;
}
开发者ID:ihutch,项目名称:sceptic3D,代码行数:71,代码来源:h5repart_gentest.c

示例9: main

int
main (void)
{
    hid_t        file, src_space, vspace,
                 dset;                       /* Handles */
    hid_t        dcpl;
    herr_t       status;
    hsize_t      vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
                 vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM1},
                 dims[3] = {DIM0, DIM1, DIM2},
                 start[3],                   /* Hyperslab parameters */
                 stride[3],
                 count[3],
                 block[3];
    hsize_t      start_out[3],               /* Hyperslab parameter out */
                 stride_out[3],
                 count_out[3],
                 block_out[3];
    int          i;
    H5D_layout_t layout;                     /* Storage layout */
    size_t       num_map;                    /* Number of mappings */
    ssize_t      len;                        /* Length of the string; also a return value */
    char         *filename;
    char         *dsetname;


    file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* Create VDS dataspace.  */
    vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);

    /* Create dataspaces for the source dataset. */
    src_space = H5Screate_simple (RANK, dims, NULL);

    /* Create VDS creation property */
    dcpl = H5Pcreate (H5P_DATASET_CREATE);
     
    /* Initialize hyperslab values */

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    stride[0] = DIM0;
    stride[1] = 1;
    stride[2] = 1;
    count[0] = H5S_UNLIMITED;
    count[1] = 1;
    count[2] = 1;
    block[0] = DIM0;
    block[1] = DIM1;
    block[2] = DIM2;

   /* 
    * Build the mappings 
    *
    */
      status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
      status = H5Pset_virtual (dcpl, vspace, "f-%b.h5", "/A", src_space);
   


   /* Create a virtual dataset */
      dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
                  dcpl, H5P_DEFAULT);
      status = H5Sclose (vspace);
      status = H5Sclose (src_space);
      status = H5Dclose (dset);
      status = H5Fclose (file);    
     

    /*
     * Now we begin the read section of this example.
     */

    /*
     * Open file and dataset using the default properties.
     */
    file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);

    /*
     * Get creation property list and mapping properties.
     */
    dcpl = H5Dget_create_plist (dset);

    /*
     * Get storage layout.
     */
    layout = H5Pget_layout (dcpl);

    if (H5D_VIRTUAL == layout) 
        printf(" Dataset has a virtual layout \n");
    else
        printf(" Wrong layout found \n");

     /*
      * Find number of mappings.
      */
     status = H5Pget_virtual_count (dcpl, &num_map);
     printf(" Number of mappings is %d\n", (int)num_map);
//.........这里部分代码省略.........
开发者ID:ElaraFX,项目名称:hdf5,代码行数:101,代码来源:h5_vds-eiger.c

示例10: main

int
main()
{
   printf("\n*** Checking HDF5 dimscales some more.\n");
   printf("*** Creating a file with one var with one dimension scale...");
   
   {
      hid_t fileid, spaceid, datasetid, dimscaleid, cparmsid;
      hsize_t dims[NDIMS] = {DIM1_LEN}, maxdims[NDIMS] = {H5S_UNLIMITED};

      /* Create file. */
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
			      H5P_DEFAULT)) < 0) ERR;

      /* Create the space that will be used both for the dimscale and
       * the 1D dataset that will attach it. */
      if ((spaceid = H5Screate_simple(NDIMS, dims, maxdims)) < 0) ERR;

      /* Modify dataset creation properties, i.e. enable chunking. */
      dims[0] = 1;
      if ((cparmsid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_chunk(cparmsid, NDIMS, dims) < 0) ERR;

      /* Create our dimension scale, as an unlimited dataset. */
      if ((dimscaleid = H5Dcreate(fileid, DIMSCALE_NAME, H5T_NATIVE_INT,
				  spaceid, cparmsid)) < 0) ERR;
      if (H5DSset_scale(dimscaleid, NAME_ATTRIBUTE) < 0) ERR;

      /* Create a variable which uses it. */
      if ((datasetid = H5Dcreate(fileid, VAR1_NAME, H5T_NATIVE_INT,
				 spaceid, cparmsid)) < 0) ERR;
      if (H5DSattach_scale(datasetid, dimscaleid, 0) < 0) ERR;
      if (H5DSset_label(datasetid, 0, DIMSCALE_LABEL) < 0) ERR;

      /* Fold up our tents. */
      if (H5Dclose(dimscaleid) < 0 ||
	  H5Dclose(datasetid) < 0 ||
	  H5Sclose(spaceid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** Checking that one var, one dimscale file can be read...");

   {
      hid_t fileid, spaceid = 0, datasetid = 0;
      hsize_t num_obj, i;
      int obj_class;
      char obj_name[NC_MAX_NAME + 1];
      char dimscale_name[NC_MAX_NAME+1];
      htri_t is_scale;
      char label[NC_MAX_NAME+1];
      int num_scales;
      hsize_t dims[1], maxdims[1];
      H5G_stat_t statbuf;
      HDF5_OBJID_T dimscale_obj, vars_dimscale_obj;

      /* Open the file. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
      
      /* Loop through objects in the root group. */
      if (H5Gget_num_objs(fileid, &num_obj) < 0) ERR;
      for (i=0; i<num_obj; i++)
      {
	 /* Get the type (i.e. group, dataset, etc.), and the name of
	  * the object. */
	 if ((obj_class = H5Gget_objtype_by_idx(fileid, i)) < 0) ERR;
	 if (H5Gget_objname_by_idx(fileid, i, obj_name, NC_MAX_NAME) < 0) ERR;

	 /*printf("\nEncountered: HDF5 object obj_class %d obj_name %s\n",
	   obj_class, obj_name);*/

	 /* Deal with object based on its obj_class. */
	 switch(obj_class)
	 {
	    case H5G_GROUP:
	       break;
	    case H5G_DATASET:
	       /* Open the dataset. */
	       if ((datasetid = H5Dopen1(fileid, obj_name)) < 0) ERR;

	       /* This should be an unlimited dataset. */
	       if ((spaceid = H5Dget_space(datasetid)) < 0) ERR;
	       if (H5Sget_simple_extent_dims(spaceid, dims, maxdims) < 0) ERR;
	       if (maxdims[0] != H5S_UNLIMITED) ERR;

	       /* Is this a dimscale? */
	       if ((is_scale = H5DSis_scale(datasetid)) < 0) ERR;
	       if (is_scale && strcmp(obj_name, DIMSCALE_NAME)) ERR;
	       if (is_scale)
	       {
		  /* A dimscale comes with a NAME attribute, in
		   * addition to its real name. */
		  if (H5DSget_scale_name(datasetid, dimscale_name, NC_MAX_NAME) < 0) ERR;
		  if (strcmp(dimscale_name, NAME_ATTRIBUTE)) ERR;

		  /* fileno and objno uniquely identify an object and a
		   * HDF5 file. */
		  if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR;
		  dimscale_obj.fileno[0] = statbuf.fileno[0];
//.........这里部分代码省略.........
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:101,代码来源:tst_h_dimscales2.c

示例11: create_file

int create_file(char * name){
    hid_t file_id;
    file_id = H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    return 0;
}
开发者ID:sunny1988,项目名称:fdtd-cuda,代码行数:5,代码来源:h5save.c

示例12: main

int main( void )
{
 typedef struct Particle 
 {
  char   name[16];
  int    lati;
  int    longi;
  float  pressure;
  double temperature; 
 } Particle;

 /* Define a subset of Particle, with latitude and longitude fields */
 typedef struct Position 
 {
  int    lati;
  int    longi;
 } Position;

 /* Define a subset of Particle, with name and pressure fields */
 typedef struct NamePressure 
 {
  char   name[16];
  float  pressure;
 } NamePressure;
 
 /* Calculate the type_size and the offsets of our struct members */
 Particle  dst_buf[NRECORDS];
 size_t dst_size =  sizeof( Particle );
 size_t dst_offset[NFIELDS] = { HOFFSET( Particle, name ),
                                HOFFSET( Particle, lati ),
                                HOFFSET( Particle, longi ),
                                HOFFSET( Particle, pressure ),
                                HOFFSET( Particle, temperature )};
 size_t dst_sizes[NFIELDS] = { sizeof( dst_buf[0].name),
                               sizeof( dst_buf[0].lati),
                               sizeof( dst_buf[0].longi),
                               sizeof( dst_buf[0].pressure),
                               sizeof( dst_buf[0].temperature)};

 size_t field_offset_pos[2] = { HOFFSET( Position, lati ),
                                HOFFSET( Position, longi )};
 
 /* Initially no data */
 Particle  *p_data = NULL;

 /* Define field information */
 const char *field_names[NFIELDS]  = 
 { "Name","Latitude", "Longitude", "Pressure", "Temperature" };
 hid_t      field_type[NFIELDS];
 hid_t      string_type;
 hid_t      file_id;
 hsize_t    chunk_size = 10;
  Particle   fill_data[1] = 
 { {"no data",-1,-1, -99.0f, -99.0} };   /* Fill value particle */ 
 int        compress  = 0;
 hsize_t    nfields;
 hsize_t    start;                       /* Record to start reading/writing */
 hsize_t    nrecords;                    /* Number of records to read/write */
 herr_t     status; 
 int        i;

 /* Define new values for the field "Pressure"  */
 float      pressure_in  [NRECORDS_ADD] =
 { 0.0f,1.0f,2.0f};
 int        field_index_pre[1]     = { 3 };
 int        field_index_pos[2]     = { 1,2 };

 /* Define new values for the fields "Latitude,Longitude"  */
 Position   position_in[NRECORDS_ADD] = { {0,0},
 {10,10},
 {20,20} };

 size_t field_sizes_pos[2]=
 {
  sizeof(position_in[0].longi),
  sizeof(position_in[0].lati)
 };
 
 size_t field_sizes_pre[1]=
 { 
  sizeof(float)
 };

 /* Initialize the field field_type */
 string_type = H5Tcopy( H5T_C_S1 );
 H5Tset_size( string_type, 16 );
 field_type[0] = string_type;
 field_type[1] = H5T_NATIVE_INT;
 field_type[2] = H5T_NATIVE_INT;
 field_type[3] = H5T_NATIVE_FLOAT;
 field_type[4] = H5T_NATIVE_DOUBLE;
 
 /* Create a new file using default properties. */
 file_id = H5Fcreate( "ex_table_05.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );

 /* Make the table */
 status=H5TBmake_table( "Table Title", file_id, TABLE_NAME,NFIELDS,NRECORDS, 
                         dst_size,field_names, dst_offset, field_type, 
                         chunk_size, fill_data, compress, p_data  );

//.........这里部分代码省略.........
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:101,代码来源:ex_table_05.c

示例13: main

int
main(void)
{
    hid_t src_sid       = -1;   /* source dataset's dataspace ID            */
    hid_t src_dcplid    = -1;   /* source dataset property list ID          */

    hid_t vds_sid       = -1;   /* VDS dataspace ID                         */
    hid_t vds_dcplid    = -1;   /* VDS dataset property list ID             */

    hid_t fid           = -1;   /* HDF5 file ID                             */
    hid_t did           = -1;   /* dataset ID                               */
    hid_t msid          = -1;   /* memory dataspace ID                      */
    hid_t fsid          = -1;   /* file dataspace ID                        */

    hsize_t extent[RANK];       /* source dataset extents                   */
    hsize_t start[RANK];        /* starting point for hyperslab             */
    hsize_t stride[RANK];       /* hypserslab stride                        */
    hsize_t count[RANK];        /* hypserslab count                         */
    int map_start       = -1;   /* starting point in the VDS map            */

    int *buffer         = NULL; /* data buffer                              */
    int value           = -1;   /* value written to datasets                */

    hsize_t n           = 0;    /* number of elements in a plane            */

    int i;                      /* iterator                                 */
    int j;                      /* iterator                                 */
    int k;                      /* iterator                                 */

    /* Start by creating the virtual dataset (VDS) dataspace and creation
     * property list. The individual source datasets are then created
     * and the VDS map (stored in the VDS property list) is updated.
     */

    /* Create VDS dcpl */
    if((vds_dcplid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
        UC_ERROR
    if(H5Pset_fill_value(vds_dcplid, UC_5_VDS_DATATYPE,
                &UC_5_VDS_FILL_VALUE) < 0)
        UC_ERROR

    /* Create VDS dataspace */
    if((vds_sid = H5Screate_simple(RANK, UC_5_VDS_DIMS,
                    UC_5_VDS_MAX_DIMS)) < 0)
        UC_ERROR

    /*********************************
     * Map source files and datasets *
     *********************************/

    /* Hyperslab array setup */
    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    map_start = 0;

    stride[0] = UC_5_N_SOURCES;
    stride[1] = 1;
    stride[2] = 1;

    count[0] = H5S_UNLIMITED;
    count[1] = 1;
    count[2] = 1;

    extent[0] = UC_5_SRC_PLANES;
    extent[1] = UC_5_HEIGHT;
    extent[2] = UC_5_WIDTH;

    for(i = 0; i < UC_5_N_SOURCES; i++) {

        /* source dataset dcpl */
        if((src_dcplid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
            UC_ERROR
        if(H5Pset_chunk(src_dcplid, RANK, UC_5_PLANE) < 0)
            UC_ERROR
        if(H5Pset_fill_value(src_dcplid, UC_5_SOURCE_DATATYPE,
                    &UC_5_FILL_VALUES[i]) < 0)
            UC_ERROR
        if(H5Pset_deflate(src_dcplid, COMPRESSION_LEVEL) < 0)
            UC_ERROR

        /* Create source file, dataspace, and dataset */
        if((fid = H5Fcreate(UC_5_FILE_NAMES[i], H5F_ACC_TRUNC,
                        H5P_DEFAULT, H5P_DEFAULT)) < 0)
            UC_ERROR
        if((src_sid = H5Screate_simple(RANK, UC_5_SOURCE_DIMS,
                        UC_5_SOURCE_MAX_DIMS)) < 0)
            UC_ERROR
        if((did = H5Dcreate2(fid, UC_5_SOURCE_DSET_NAME,
                        UC_5_SOURCE_DATATYPE, src_sid,
                        H5P_DEFAULT, src_dcplid, H5P_DEFAULT)) < 0)
            UC_ERROR

        /* Set the dataset's extent */
        if(H5Dset_extent(did, extent) < 0)
            UC_ERROR

        /* Create a data buffer that represents a plane */
        n = UC_5_PLANE[1] * UC_5_PLANE[2];
        if(NULL == (buffer = (int *)malloc(n * sizeof(int))))
//.........这里部分代码省略.........
开发者ID:ElaraFX,项目名称:hdf5,代码行数:101,代码来源:UC_5_stride_gen.c

示例14: main

int main( void )
{
 typedef struct Particle
 {
  char   name[16];
  int    lati;
  int    longi;
  float  pressure;
  double temperature;
 } Particle;

 /* Calculate the size and the offsets of our struct members in memory */
 size_t dst_size =  sizeof( Particle );
 size_t dst_offset[NFIELDS] = { HOFFSET( Particle, name ),
                                HOFFSET( Particle, lati ),
                                HOFFSET( Particle, longi ),
                                HOFFSET( Particle, pressure ),
                                HOFFSET( Particle, temperature )};

  /* Define field information */
  const char *field_names[NFIELDS]  =
  { "Name","Latitude", "Longitude", "Pressure", "Temperature" };
  hid_t      field_type[NFIELDS];
  hid_t      string_type;
  hid_t      file_id;
  hsize_t    chunk_size = 10;
  Particle   fill_data[1] =
  { {"no data",-1,-1, -99.0f, -99.0} };   /* Fill value particle */
  int        compress  = 0;
  hsize_t    nfields_out;
  hsize_t    nrecords_out;

  /* Initialize field_type */
  string_type = H5Tcopy( H5T_C_S1 );
  H5Tset_size( string_type, 16 );
  field_type[0] = string_type;
  field_type[1] = H5T_NATIVE_INT;
  field_type[2] = H5T_NATIVE_INT;
  field_type[3] = H5T_NATIVE_FLOAT;
  field_type[4] = H5T_NATIVE_DOUBLE;

 /* Create a new file using default properties. */
 file_id = H5Fcreate( "ex_table_06.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );

 /* Make a table */
 H5TBmake_table( "Table Title",file_id,TABLE_NAME,NFIELDS,NRECORDS,dst_size,
                       field_names, dst_offset, field_type,
                       chunk_size, fill_data, compress, NULL);

 /* Get table info  */
 H5TBget_table_info (file_id,TABLE_NAME, &nfields_out, &nrecords_out );

 /* print */
 printf ("Table has %d fields and %d records\n",(int)nfields_out,(int)nrecords_out);

  /* close type */
 H5Tclose( string_type );

 /* close the file */
 H5Fclose( file_id );

 return 0;


}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:65,代码来源:ex_table_06.c

示例15: output

int
output (Array3D < zone > grid, Array3D < zone > fx, Array3D < zone > fy,
	int time, char *filename)
{

#ifdef USE_HDF5
  hid_t file, dataset;		/* file and dataset handles */
  hid_t datatype, dataspace;	/* handles */
  hsize_t dimsf[2];		/* dataset dimensions */
  herr_t status;
  double data[nx][ny];
  char *names[] =
    { "Density", "Velx", "Vely", "Velz", "Energy", "Bx", "By", "Bz" };
  int ll = 0;
  stringstream hdf5_stream_filename;
  string hdf5_filename;
#endif


  ofstream fout;
  ofstream gout;
  double gammam1 = gammag - 1;
  double rl, ri;
  double px;
  double py;
  double pz;
  double pressure;
  double bx;
  double by;
  double bz;
  double bsquared;
  double et, ul, vl, wl, ke, al;
  int ii = 0;
  int jj = 0;
  int kk = 0;
  char outputdir[50] = "output/";
//      char            filename[50] = "out_2d_";
  stringstream s;
  stringstream stream_filename;
  stringstream stream_temp_b;
  string str_file_tag;
  string str_output_filename;
  string str_input_filename;


  double ki = 24296.3696;
  double mp = 1.67262158;
  double mpi = 1.0 / mp;
  double nt = 0;
  double nt2 = 0;
  double temperature = 0;

  s.clear ();
  s.width (5);
  s.fill ('0');
  s << time;
  s >> str_file_tag;
  stream_filename.clear ();
  stream_filename << outputdir << filename << str_file_tag;
  stream_filename >> str_input_filename;

#ifdef USE_HDF5
  hdf5_stream_filename << outputdir << "hdf5_" << filename << str_file_tag <<
    ".h5";
  hdf5_stream_filename >> hdf5_filename;
  file =
    H5Fcreate (hdf5_filename.c_str (), H5F_ACC_TRUNC, H5P_DEFAULT,
	       H5P_DEFAULT);

  for (ll = 0; ll < ne; ll++)
    {
      dimsf[0] = nx;
      dimsf[1] = ny;
      dataspace = H5Screate_simple (RANK, dimsf, NULL);
      /*
       * Define datatype for the data in the file.
       * We will store little endian DOUBLE numbers.
       */
      datatype = H5Tcopy (H5T_NATIVE_DOUBLE);
      status = H5Tset_order (datatype, H5T_ORDER_LE);
      /*
       * Create a new dataset within the file using defined dataspace and
       * datatype and default dataset creation properties.
       */
      dataset = H5Dcreate (file, names[ll], datatype, dataspace, H5P_DEFAULT);

      for (jj = 0; jj < ny; jj++)
	{
	  for (ii = 0; ii < nx; ii++)
	    data[ii][jj] = grid[ii][jj][kk].array[ll];
	}
      /*
       * Write the data to the dataset using default transfer properties.
       */
      status = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
			 H5P_DEFAULT, data);

      /*
       * Close/release resources.
       */
//.........这里部分代码省略.........
开发者ID:garethcmurphy,项目名称:mhdvanleer,代码行数:101,代码来源:output.cpp


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