Exemple #1
0
int_f
nh5soffset_simple_c ( hid_t_f *space_id , hssize_t_f *offset)
{
  int ret_value = -1;
  hid_t c_space_id;
  int rank;
  hssize_t *c_offset;
  herr_t  status;
  int i;

  c_space_id = *space_id;
  rank = H5Sget_simple_extent_ndims(c_space_id);
  if (rank < 0) return ret_value;

  c_offset = malloc(sizeof(hssize_t)*rank);
  if (!c_offset) return ret_value;

  /*
   * Reverse dimensions due to C-FORTRAN storage order.
   */
  for (i=0; i < rank; i++) c_offset[i] = offset[rank - i - 1];

  status = H5Soffset_simple(c_space_id, c_offset);
  if ( status >= 0  ) ret_value = 0;
  HDfree(c_offset);
  return ret_value;
}
Exemple #2
0
static herr_t
dset_read(int local_dim, file_descr *fd, parameters *parms, void *buffer,
    const char *buffer2)
{
    int cur_dim = order[local_dim]-1;
    hsize_t i;
    int j;
    herr_t hrc;
    int         ret_code = SUCCESS;

    /* iterate on the current dimension */
    for (i=0; i < parms->dset_size[cur_dim]; i += parms->buf_size[cur_dim]){

        h5offset[cur_dim] = (hssize_t)i;
        offset[cur_dim] = (HDoff_t)i;

        /* if traverse in order array is incomplete, recurse */
        if (local_dim > 0){

            ret_code = dset_read(local_dim-1, fd, parms, buffer, buffer2);

        /* otherwise, write buffer into dataset */
        }else{

            switch (parms->io_type) {

            case POSIXIO:
                for (j=0; j<parms->rank; j++) {
                   buf_offset[j] = 0;
                }
                buf_p = (unsigned char*)buffer;
                posix_buffer_read(0, fd, parms, buffer);
                break;

            case HDF5:
                hrc = H5Soffset_simple(h5dset_space_id, h5offset);
                VRFY((hrc >= 0), "H5Soffset_simple");
                /* Read the buffer out */
                hrc = H5Dread(h5ds_id, ELMT_H5_TYPE, h5mem_space_id,
                    h5dset_space_id, h5dxpl, buffer);
                VRFY((hrc >= 0), "H5Dread");
                break;
				
            default:
                /* unknown request */
                HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)parms->io_type);
                HDassert(0 && "Unknown IO type");
                break;
            } /* switch (parms->io_type) */
        }
    }
done:
    return ret_code;
}
Exemple #3
0
/*
 * Function:        dset_write
 * Purpose:         Write buffer into the dataset.
 * Return:          SUCCESS or FAIL
 * Programmer:      Christian Chilan, April, 2008
 * Modifications:
 */
static herr_t
dset_write(int local_dim, file_descr *fd, parameters *parms, void *buffer)
{
    int cur_dim = order[local_dim]-1;
    int         ret_code = SUCCESS;
    int         k;
    hsize_t  dims[MAX_DIMS], maxdims[MAX_DIMS];
    hsize_t i;
    int j;
    herr_t hrc;

    /* iterates according to the dimensions in order array */
    for (i=0; i < parms->dset_size[cur_dim]; i += parms->buf_size[cur_dim]){

        h5offset[cur_dim] = (hssize_t)i;
        offset[cur_dim] = (HDoff_t)i;

        if (local_dim > 0){

            dset_write(local_dim-1, fd, parms, buffer);

        }else{

            switch (parms->io_type) {

            case POSIXIO:
                /* initialize POSIX offset in the buffer */
                for(j = 0; j < parms->rank; j++)
                    buf_offset[j] = 0;
                buf_p = (unsigned char *)buffer;
                /* write POSIX buffer */
                posix_buffer_write(0, fd, parms, buffer);
                break;

            case HDF5:
                /* if dimensions are extendable, extend them as needed during access */
                if (parms->h5_use_chunks && parms->h5_extendable) {

                    hrc=H5Sget_simple_extent_dims(h5dset_space_id,dims,maxdims);
                    VRFY((hrc >= 0), "H5Sget_simple_extent_dims");

                    for (k=0; k < parms->rank; k++){

                        HDassert(h5offset[k] >= 0);
                        if (dims[k] <= (hsize_t)h5offset[k]) {
                            dims[k] = dims[k]+h5count[k];
                            hrc=H5Sset_extent_simple(h5dset_space_id,parms->rank,dims,maxdims);
                            VRFY((hrc >= 0), "H5Sset_extent_simple");
                            hrc=H5Dset_extent(h5ds_id,dims);
                            VRFY((hrc >= 0), "H5Dextend");
                        }
                    }
                }
                /* applies offset */
                hrc = H5Soffset_simple(h5dset_space_id, h5offset);
                VRFY((hrc >= 0), "H5Soffset_simple");

                /* Write the buffer out */
                hrc=H5Sget_simple_extent_dims(h5dset_space_id,dims,maxdims);
                hrc = H5Dwrite(h5ds_id, ELMT_H5_TYPE, h5mem_space_id,
                    h5dset_space_id, h5dxpl, buffer);
                VRFY((hrc >= 0), "H5Dwrite");

                break;
				
            default:
                /* unknown request */
                HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)parms->io_type);
                HDassert(0 && "Unknown IO type");
                break;
            } /* switch (parms->io_type) */
        }
    }
done:
    return ret_code;
}