コード例 #1
0
ファイル: H5Sf.c プロジェクト: MattNapsAlot/rHDF5
int_f
nh5sget_select_hyper_nblocks_c( hid_t_f *space_id , hssize_t_f * num_blocks)
{
  int ret_value = 0;
  hid_t c_space_id;
  hssize_t c_num_blocks;

  c_space_id = *space_id;
  c_num_blocks = H5Sget_select_hyper_nblocks(c_space_id);
  if ( c_num_blocks < 0  ) ret_value = -1;

  *num_blocks = (hssize_t_f)c_num_blocks;
  return ret_value;
}
コード例 #2
0
/*-------------------------------------------------------------------------
 * Function:    h5tools_str_dump_region_blocks
 *
 * Purpose: Prints information about a dataspace region by appending
 *          the information to the specified string.
 *
 * Return:  none
 *
 * In/Out:
 *      h5tools_context_t *ctx
 *      h5tools_str_t     *str
 *-------------------------------------------------------------------------
 */
void
h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region,
        const h5tool_format_t *info, h5tools_context_t *ctx)
{
    hssize_t   nblocks;
    hsize_t    alloc_size;
    hsize_t   *ptdata;
    int        ndims = H5Sget_simple_extent_ndims(region);

    /*
     * This function fails if the region does not have blocks.
     */
    H5E_BEGIN_TRY {
        nblocks = H5Sget_select_hyper_nblocks(region);
    } H5E_END_TRY;

    /* Print block information */
    if (nblocks > 0) {
        int i;

        alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]);
        assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/
        ptdata = malloc((size_t) alloc_size);
        H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t);
        H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata);

        for (i = 0; i < nblocks; i++) {
            int j;

            h5tools_str_append(str, info->dset_blockformat_pre, i ? "," OPTIONAL_LINE_BREAK " " : "",
                               (unsigned long)i);

            /* Start coordinates and opposite corner */
            for (j = 0; j < ndims; j++)
                h5tools_str_append(str, "%s%lu", j ? "," : "(",
                                    (unsigned long) ptdata[i * 2 * ndims + j]);

            for (j = 0; j < ndims; j++)
                h5tools_str_append(str, "%s%lu", j ? "," : ")-(",
                                    (unsigned long) ptdata[i * 2 * ndims + j + ndims]);

            h5tools_str_append(str, ")");
        }

        free(ptdata);
    } /* end if (nblocks > 0) */
}
コード例 #3
0
int 
main(void)
{
    hid_t		fid1;		/* HDF5 File IDs		*/
    hid_t		dset1,	/* Dataset ID			*/
                dset2;      /* Dereferenced dataset ID */
    hid_t		sid1,       /* Dataspace ID	#1		*/
                sid2;       /* Dataspace ID	#2		*/
    hsize_t *   coords;             /* Coordinate buffer */
    hsize_t		low[SPACE2_RANK];   /* Selection bounds */
    hsize_t		high[SPACE2_RANK];     /* Selection bounds */
    hdset_reg_ref_t      *rbuf;      /* buffer to to read disk */
    int    *drbuf;      /* Buffer for reading numeric data from disk */
    int        i, j;          /* counting variables */
    herr_t		ret;		/* Generic return value		*/

    /* Output message about test being performed */

    /* Allocate write & read buffers */
    rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
    drbuf=calloc(sizeof(int),SPACE2_DIM1*SPACE2_DIM2);

    /* Open the file */
    fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);

    /* Open the dataset */
    dset1=H5Dopen(fid1,"/Dataset1");

    /* Read selection from disk */
    ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);

    /* Try to open objects */
    dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);

    /* Check information in referenced dataset */
    sid1 = H5Dget_space(dset2);

    ret=H5Sget_simple_extent_npoints(sid1);
    printf(" Number of elements in the dataset is : %d\n",ret);

    /* Read from disk */
    ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);

    for(i=0; i<SPACE2_DIM1; i++) {
        for (j=0; j<SPACE2_DIM2; j++) printf (" %d ", drbuf[i*SPACE2_DIM2+j]);
        printf("\n"); }

    /* Get the hyperslab selection */
    sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);

    /* Verify correct hyperslab selected */
    ret = H5Sget_select_npoints(sid2);
    printf(" Number of elements in the hyperslab is : %d \n", ret);
    ret = H5Sget_select_hyper_nblocks(sid2);
    coords=malloc(ret*SPACE2_RANK*sizeof(hsize_t)*2); /* allocate space for the hyperslab blocks */
    ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
    printf(" Hyperslab coordinates are : \n");
    printf (" ( %lu , %lu ) ( %lu , %lu ) \n", \
(unsigned long)coords[0],(unsigned long)coords[1],(unsigned long)coords[2],(unsigned long)coords[3]); 
    free(coords);
    ret = H5Sget_select_bounds(sid2,low,high);

    /* Close region space */
    ret = H5Sclose(sid2);

    /* Get the element selection */
    sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);

    /* Verify correct elements selected */
    ret = H5Sget_select_elem_npoints(sid2);
    printf(" Number of selected elements is : %d\n", ret);

    /* Allocate space for the element points */
    coords= malloc(ret*SPACE2_RANK*sizeof(hsize_t)); 
    ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
    printf(" Coordinates of selected elements are : \n");
    for (i=0; i<2*NPOINTS; i=i+2) 
         printf(" ( %lu , %lu ) \n", (unsigned long)coords[i],(unsigned long)coords[i+1]); 
          
    free(coords);
    ret = H5Sget_select_bounds(sid2,low,high);

    /* Close region space */
    ret = H5Sclose(sid2);

    /* Close first space */
    ret = H5Sclose(sid1);

    /* Close dereferenced Dataset */
    ret = H5Dclose(dset2);

    /* Close Dataset */
    ret = H5Dclose(dset1);

    /* Close file */
    ret = H5Fclose(fid1);

    /* Free memory buffers */
    free(rbuf);
    free(drbuf);
    return 0;
}   
コード例 #4
0
void H5ReferenceData::printData(std::ostream & os, const unsigned int pos, const unsigned int indentLevel) const
{
    char * cdata = static_cast<char *>(data) + offset + pos * (stride ? stride : dataSize);
    void ** ref = &(((void **)cdata)[0]);
    hid_t file = getFile().getH5Id();
    hid_t obj = H5Rdereference(file, datasetReference ? H5R_DATASET_REGION : H5R_OBJECT, ref);
    if (obj < 0)
    {
        os << "NULL";
        return;
    }

    ssize_t size = H5Rget_name(file, datasetReference ? H5R_DATASET_REGION : H5R_OBJECT, ref, 0, 0);
    char * name = 0;
    H5O_info_t info;

    if (size != -1)
    {
        name = new char[size + 1];
        H5Rget_name(file, datasetReference ? H5R_DATASET_REGION : H5R_OBJECT, ref, name, size + 1);

        if (datasetReference == H5R_OBJECT)
        {
            H5Oget_info(obj, &info);
            H5Oclose(obj);

            switch (info.type)
            {
                case H5O_TYPE_GROUP:
                    os << "GROUP ";
                    break;
                case H5O_TYPE_DATASET:
                    os << "DATASET ";
                    break;
                case H5O_TYPE_NAMED_DATATYPE:
                    os << "DATATYPE ";
                    break;
                case H5O_TYPE_UNKNOWN:
                default:
                    if (size != -1)
                    {
                        delete[] name;
                    }
                    throw H5Exception(__LINE__, __FILE__, _("Unknown HDF5 object"));
            }

            os << (haddr_t)(*ref) << " " << name;
        }
        else
        {
            hid_t space = H5Rget_region(file, H5R_DATASET_REGION, ref);
            hssize_t npoints = H5Sget_select_elem_npoints(space);
            hsize_t ndims = H5Sget_simple_extent_dims(space, 0, 0);
            H5Oclose(obj);

            os << "DATASET " << name << " {";

            if (npoints >= 0)
            {
                const hsize_t N = ndims * npoints;
                hsize_t * buf = new hsize_t[N];
                herr_t err =  H5Sget_select_elem_pointlist(space, 0, npoints, buf);
                for (hssize_t i = 0; i < (hssize_t)N; i += ndims)
                {
                    os << "(";
                    for (unsigned int j = 0; j < ndims - 1; j++)
                    {
                        os << buf[i + j] << ",";
                    }
                    os << buf[i + ndims - 1] << ")";

                    if (i != N - ndims)
                    {
                        os << ", ";
                    }
                    else
                    {
                        os << "}";
                    }
                }
                delete[] buf;
            }
            else
            {
                hssize_t nblocks = H5Sget_select_hyper_nblocks(space);
                if (nblocks >= 0)
                {
                    const hsize_t N = 2 * ndims * nblocks;
                    hsize_t * buf = new hsize_t[N];
                    herr_t err = H5Sget_select_hyper_blocklist(space, 0, nblocks, buf);
                    for (hssize_t i = 0; i < (hssize_t)N; i += 2 * ndims)
                    {
                        os << "(";
                        for (unsigned int j = 0; j < ndims - 1; j++)
                        {
                            os << buf[i + j] << ",";
                        }
                        os << buf[i + ndims - 1] << ")-(";
                        for (unsigned int j = 0; j < ndims - 1; j++)
                        {
                            os << buf[i + ndims + j] << ",";
                        }
                        os << buf[i + 2 * ndims - 1] << ")";

                        if (i != N - 2 * ndims)
                        {
                            os << ", ";
                        }
                        else
                        {
                            os << "}";
                        }
                    }

                    delete[] buf;
                }
            }

            H5Sclose(space);
        }

        delete[] name;
    }
}
コード例 #5
0
ファイル: dat1GetBounds.c プロジェクト: Starlink/hds-v5
int
dat1GetBounds( const HDSLoc * locator, hdsdim lower[DAT__MXDIM],
               hdsdim upper[DAT__MXDIM], hdsbool_t * issubset,
               int *actdim, int * status ) {
  int rank = 0;
  hssize_t nblocks = 0;
  hsize_t *blockbuf = NULL;

  *actdim = 0;
  *issubset = 0;
  if (*status != SAI__OK) return *status;



   /* If the supplied locator has a dataspace, then use the bounds of the
      data space. This is done even if the object is a structure, since
      vectorised structure arrays will have a dataspace describing their
      vectorised extent. */
  if( locator->dataspace_id ) {
    int i;
    hsize_t h5lower[DAT__MXDIM];
    hsize_t h5upper[DAT__MXDIM];
    hsize_t h5dims[DAT__MXDIM];

    CALLHDFE( int,
              rank,
              H5Sget_simple_extent_dims( locator->dataspace_id, h5dims, NULL ),
              DAT__DIMIN,
              emsRep("datshape_1", "datShape: Error obtaining shape of object",
                     status)
              );

    /* If we are using datSlice then there should be one (and only one) hyperslab
       for the dataspace and we need to handle that. Should be same dimensionality
       as above. Negative number indicates there were no hyperslabs. */
    if( H5Sget_select_type( locator->dataspace_id ) == H5S_SEL_HYPERSLABS ) {
       nblocks = H5Sget_select_hyper_nblocks( locator->dataspace_id );
    } else {
       nblocks = 0;
    }

    if (nblocks == 1) {
      herr_t h5err = 0;

      *issubset = 1;

      blockbuf = MEM_MALLOC( nblocks * rank * 2 * sizeof(*blockbuf) );

      CALLHDF( h5err,
               H5Sget_select_hyper_blocklist( locator->dataspace_id, 0, 1, blockbuf ),
               DAT__DIMIN,
               emsRep("datShape_2", "datShape: Error obtaining shape of slice", status )
               );

      /* We only go through one block. The buffer is returned in form:
         ndim start coordinates, then ndim opposite corner coordinates
         and repeats for each block (if we had more than one block).
      */
      for (i = 0; i<rank; i++) {
        hsize_t start;
        hsize_t opposite;
        start = blockbuf[i];
        opposite = blockbuf[i+rank];
        /* So update the shape to account for the slice: HDS is 1-based */
        h5lower[i] = start + 1;
        h5upper[i] = opposite + 1;
      }

    } else if (nblocks > 1) {
      if (*status == SAI__OK) {
        *status = DAT__WEIRD;
        emsRepf("datShape_2", "Unexpectedly got %zd hyperblocks from locator. Expected 1."
                " (possible programming error)", status, (ssize_t)nblocks);
        goto CLEANUP;
      }
    } else {
      /* No hyperblock */
      for (i=0; i<rank; i++) {
        h5lower[i] = 1;    /* HDS value 1-based */
        h5upper[i] = h5dims[i];
      }

    }

   dat1ExportDims( rank, h5lower, lower, status );
   dat1ExportDims( rank, h5upper, upper, status );

  /* If no dataspace ia available, and the locator is a structure
     array... */
  } else if (dat1IsStructure( locator, status ) ) {