Esempio n. 1
0
//-*****************************************************************************
void
CopyWrittenArray( hid_t iGroup,
                  const std::string &iName,
                  WrittenArraySampleIDPtr iRef )
{
    ABCA_ASSERT( ( bool )iRef,
                  "CopyWrittenArray() passed a bogus ref" );

    hid_t fid = H5Iget_file_id(iGroup);
    ABCA_ASSERT( fid >= 0,
                "CopyWrittenArray() Could not get file ID from iGroup" );

    hid_t did = H5Dopen( fid,
        iRef->getObjectLocation().c_str(), H5P_DEFAULT );
    DsetCloser dcloser(did);

    // We have a reference. Create a link to it.
    // We are manually getting the source dataset instead of using
    // fid and iName because of a bug in HDF5 1.8.5 and earlier.
    // Files written using that approach would sometimes be corrupted.
    herr_t status = H5Lcreate_hard( did,
                                    ".",
                                    iGroup,
                                    iName.c_str(),
                                    H5P_DEFAULT,
                                    H5P_DEFAULT );

    H5Fclose( fid );
    ABCA_ASSERT( status >= 0,
                 "H5Lcreate_hard failed!" << std::endl
                  << "Dset obj id: " << did << std::endl
                  << "Link loc id: " << iGroup << std::endl
                  << "Link name: " << iName );
}
Esempio n. 2
0
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Iget_1file_1id
    (JNIEnv *env, jclass clss, jlong obj_id)
{
    hid_t file_id = -1;

    file_id = H5Iget_file_id((hid_t)obj_id);
    if (file_id < 0)
        h5libraryError(env);

    return (jlong) file_id;
} /* end Java_hdf_hdf5lib_H5_H5Iget_1file_1id */
Esempio n. 3
0
File: H5If.c Progetto: ElaraFX/hdf5
/****if* H5If/h5iget_file_id_c
 * NAME
 *  h5iget_file_id_c
 * PURPOSE
 *  Call H5Iget_file_id to obtain file identifier from object identifier
 * INPUTS
 *  obj_id - object identifier
 * OUTPUTS
 *  file_id - file identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Tuesday, August 24, 2004
 *
 * SOURCE
*/
int_f
h5iget_file_id_c(hid_t_f *obj_id, hid_t_f *file_id)
/******/
{
     int ret_value;
     hid_t c_file_id;

     /*
      * Call H5Iget_file_id
      */
     if ((c_file_id = H5Iget_file_id(*obj_id)) < 0)
         HGOTO_DONE(FAIL);

    /* Set output & return values */
    *file_id=(hid_t_f)c_file_id;
    ret_value=0;

done:
      return ret_value;
}
Esempio n. 4
0
 hid_t file() const {
     MPQC_FILE_THREADSAFE;
     return H5Iget_file_id(id_);
 }
Esempio n. 5
0
/* Test basic functionality of registering and deleting types and IDs */
static int basic_id_test(void)
{
    H5I_type_t myType = H5I_BADID;
    hid_t arrayID = H5I_INVALID_HID;
    void* testObj = NULL;
    void* testPtr = NULL;
    char nameString[10];
    hid_t testID;
    ssize_t testSize = -1;
    herr_t err;
    int num_ref;
    hsize_t num_members;


    /* Try to register an ID with ficticious types */
    H5E_BEGIN_TRY
    arrayID = H5Iregister((H5I_type_t) 420, testObj);
    H5E_END_TRY

    VERIFY(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID != H5I_INVALID_HID)
        goto out;

    H5E_BEGIN_TRY
    arrayID = H5Iregister((H5I_type_t) -1, testObj);
    H5E_END_TRY

    VERIFY(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID != H5I_INVALID_HID)
        goto out;

    /* Try to access IDs with ficticious types */
    H5E_BEGIN_TRY
    testPtr = H5Iobject_verify((hid_t)100, (H5I_type_t) 0);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = H5Iobject_verify((hid_t)700, (H5I_type_t) 700);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    /* Register a type */
    myType = H5Iregister_type((size_t)64, 0, (H5I_free_t) free );

    CHECK(myType, H5I_BADID, "H5Iregister_type");
    if(myType == H5I_BADID)
        goto out;

    /* Register an ID and retrieve the object it points to.
     * Once the ID has been registered, testObj will be freed when
         * its ID type is destroyed. */
    testObj = HDmalloc(7 * sizeof(int));
    arrayID = H5Iregister(myType, testObj);

    CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID == H5I_INVALID_HID)
    {
        HDfree(testObj);
        goto out;
    }

    testPtr = (int *) H5Iobject_verify(arrayID, myType);

    VERIFY(testPtr, testObj, "H5Iobject_verify");
    if(testPtr != testObj)
        goto out;

    /* Ensure that H5Iget_file_id and H5Iget_name() fail, since this
         * is an hid_t for the wrong kind of object */
    H5E_BEGIN_TRY
    testID = H5Iget_file_id(arrayID);
    H5E_END_TRY

    VERIFY(testID, H5I_INVALID_HID, "H5Iget_file_id");
    if(testID != H5I_INVALID_HID)
        goto out;

    H5E_BEGIN_TRY
    testSize = H5Iget_name(arrayID, nameString, (size_t)9);
    H5E_END_TRY

    VERIFY(testSize, -1, "H5Iget_name");
    if(testSize != -1)
        goto out;

    /* Make sure H5Iremove_verify catches objects of the wrong type */
    H5E_BEGIN_TRY
    testPtr = (int*) H5Iremove_verify(arrayID, (H5I_type_t) 0);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iremove_verify");
    if(testPtr != NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = (int*) H5Iremove_verify(arrayID, (H5I_type_t) ((int) myType-1));
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iremove_verify");
    if(testPtr != NULL)
        goto out;

    /* Remove an ID and make sure we can't access it */
    testPtr = (int*) H5Iremove_verify(arrayID, myType);

    CHECK(testPtr, NULL, "H5Iremove_verify");
    if(testPtr == NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = (int*) H5Iobject_verify(arrayID, myType);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    /* Delete the type and make sure we can't access objects within it */
    arrayID = H5Iregister(myType, testObj);

    err = H5Idestroy_type(myType);
    VERIFY(err, 0, "H5Idestroy_type");
    if( err != 0)
        goto out;
    VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists");
    if(H5Itype_exists(myType) != 0)
        goto out;

    H5E_BEGIN_TRY
    VERIFY(H5Inmembers(myType, NULL), -1, "H5Inmembers");
    if(H5Inmembers(myType, NULL) != -1)
        goto out;
    H5E_END_TRY

    /* Register another type and another object in that type */
    myType = H5Iregister_type((size_t)64, 0, (H5I_free_t) free );

    CHECK(myType, H5I_BADID, "H5Iregister_type");
    if(myType == H5I_BADID)
        goto out;

    /* The memory that testObj pointed to should already have been
     * freed when the previous type was destroyed.  Allocate new
     * memory for it.
         */
    testObj = HDmalloc(7 * sizeof(int));
    arrayID = H5Iregister(myType, testObj);

    CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID == H5I_INVALID_HID)
    {
        HDfree(testObj);
        goto out;
    }

    err = H5Inmembers(myType, &num_members);
    CHECK(err, -1, "H5Inmembers");
    if (err < 0)
        goto out;
    VERIFY(num_members, 1, "H5Inmembers");
    if(num_members != 1)
        goto out;

    /* Increment references to type and ensure that dec_type_ref
    	doesn't destroy the type */
    num_ref = H5Iinc_type_ref(myType);
    VERIFY(num_ref, 2, "H5Iinc_type_ref");
    if( num_ref != 2)
        goto out;
    num_ref = H5Idec_type_ref(myType);
    VERIFY(num_ref, 1, "H5Idec_type_ref");
    if(num_ref != 1)
        goto out;
    err = H5Inmembers(myType, &num_members);
    CHECK(err, -1, "H5Inmembers");
    if (err < 0)
        goto out;
    VERIFY(num_members, 1, "H5Inmembers");
    if(num_members != 1)
        goto out;

    /* This call to dec_type_ref should destroy the type */
    num_ref = H5Idec_type_ref(myType);
    VERIFY(num_ref, 0, "H5Idec_type_ref");
    if(num_ref != 0)
        goto out;
    VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists");
    if (H5Itype_exists(myType) != 0)
        goto out;

    H5E_BEGIN_TRY
    err = H5Inmembers(myType, &num_members);
    if(err >= 0)
        goto out;
    H5E_END_TRY

    return 0;

out:
    /* Clean up type if it has been allocated and free memory used
         * by testObj */
    if(myType >= 0)
        H5Idestroy_type(myType);

    return -1;
}
Esempio n. 6
0
 File Object::file () const {
   return File (Exception::check ("H5Iget_file_id", H5Iget_file_id (handle ())));
 }
Esempio n. 7
0
hid_t HdfGroup::file_id() const { return H5Iget_file_id( d->id ); }
Esempio n. 8
0
/*-------------------------------------------------------------------------
 * Function: copy_attr
 *
 * Purpose: copy attributes located in LOC_IN, which is obtained either from
 * loc_id = H5Gopen2( fid, name);
 * loc_id = H5Dopen2( fid, name);
 * loc_id = H5Topen2( fid, name);
 *
 * Return: 0, ok, -1 no
 *-------------------------------------------------------------------------
 */
int
copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
        trav_table_t *travt, pack_opt_t *options)
{
    int         ret_value = 0;
    hid_t       attr_id = -1;  /* attr ID */
    hid_t       attr_out = -1; /* attr ID */
    hid_t       space_id = -1; /* space ID */
    hid_t       ftype_id = -1; /* file type ID */
    hid_t       wtype_id = -1; /* read/write type ID */
    size_t      msize;         /* size of type */
    void       *buf = NULL;    /* data buffer */
    hsize_t     nelmts;        /* number of elements in dataset */
    int         rank;          /* rank of dataset */
    htri_t      is_named;      /* Whether the datatype is named */
    hsize_t     dims[H5S_MAX_RANK];/* dimensions of dataset */
    char        name[255];
    H5O_info_t  oinfo;         /* object info */
    int         j;
    unsigned    u;
    hbool_t     is_ref = 0;
    H5T_class_t type_class = -1;

    if (H5Oget_info(loc_in, &oinfo) < 0)
        HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed");

    /*-------------------------------------------------------------------------
     * copy all attributes
     *-------------------------------------------------------------------------
     */
    for (u = 0; u < (unsigned) oinfo.num_attrs; u++) {
        /* open attribute */
        if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed");

        /* get name */
        if (H5Aget_name(attr_id, (size_t) 255, name) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");

        /* get the file datatype  */
        if ((ftype_id = H5Aget_type(attr_id)) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed");

        /* Check if the datatype is committed */
        if ((is_named = H5Tcommitted(ftype_id)) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed");
        if (is_named && travt) {
            hid_t fidout = -1;

            /* Create out file id */
            if ((fidout = H5Iget_file_id(loc_out)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iget_file_id failed");

            /* Copy named dt */
            if ((wtype_id = copy_named_datatype(ftype_id, fidout, named_dt_head_p, travt, options)) < 0) {
                H5Fclose(fidout);
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed");
            } /* end if */

            if (H5Fclose(fidout) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed");
        } /* end if */
        else {
            if (options->use_native == 1)
                wtype_id = H5Tget_native_type(ftype_id, H5T_DIR_DEFAULT);
            else
                wtype_id = H5Tcopy(ftype_id);
        } /* end else */

        /* get the dataspace handle  */
        if ((space_id = H5Aget_space(attr_id)) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed");

        /* get dimensions  */
        if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");

        nelmts = 1;
        for (j = 0; j < rank; j++)
            nelmts *= dims[j];

        if ((msize = H5Tget_size(wtype_id)) == 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");

        /*-------------------------------------------------------------------------
         * object references are a special case. We cannot just copy the buffers,
         * but instead we recreate the reference.
         * This is done on a second sweep of the file that just copies the referenced
         * objects at copy_refs_attr()
         *-------------------------------------------------------------------------
         */
        type_class = H5Tget_class(wtype_id);
        is_ref = (type_class == H5T_REFERENCE);
        if (type_class == H5T_VLEN || type_class == H5T_ARRAY) {
            hid_t base_type = -1;

            base_type = H5Tget_super(ftype_id);
            is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
            if (H5Tclose(base_type) < 0)
                H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed");
        }

        if (type_class == H5T_COMPOUND) {
            int nmembers = H5Tget_nmembers(wtype_id);

            for (j = 0; j < nmembers; j++) {
                hid_t mtid = H5Tget_member_type(wtype_id, (unsigned)j);
                H5T_class_t mtclass = H5Tget_class(mtid);
                if (H5Tclose(mtid) < 0)
                    H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose mtid failed");

                if (mtclass == H5T_REFERENCE) {
                    is_ref = 1;
                    break;
                }
            } /* for (j=0; i<nmembers; j++) */
        } /* if (type_class == H5T_COMPOUND) */

        if (!is_ref) {
            /*-------------------------------------------------------------------------
             * read to memory
             *-------------------------------------------------------------------------
             */

            buf = (void *)HDmalloc((size_t)(nelmts * msize));
            if (buf == NULL) {
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
            } /* end if */
            if (H5Aread(attr_id, wtype_id, buf) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");

            /*-------------------------------------------------------------------------
             * copy
             *-------------------------------------------------------------------------
             */

            if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed on ,%s>", name);
            if (H5Awrite(attr_out, wtype_id, buf) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed");

            /*close*/
            if (H5Aclose(attr_out) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");

            /* Check if we have VL data and string in the attribute's  datatype that must
             * be reclaimed */
            if (TRUE == h5tools_detect_vlen(wtype_id))
                H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
            HDfree(buf);
            buf = NULL;
        } /*H5T_REFERENCE*/

        if (options->verbose)
            printf(FORMAT_OBJ_ATTR, "attr", name);

        /*-------------------------------------------------------------------------
         * close
         *-------------------------------------------------------------------------
         */
        if (H5Sclose(space_id) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
        space_id = -1;
        if (H5Tclose(wtype_id) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
        wtype_id = -1;
        if (H5Tclose(ftype_id) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
        ftype_id = -1;
        if (H5Aclose(attr_id) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
        attr_id = -1;
    } /* for u */

done:
    H5E_BEGIN_TRY {
        if (buf) {
            /* Check if we have VL data and string in the attribute's  datatype that must
            * be reclaimed */
            if (TRUE == h5tools_detect_vlen(wtype_id))
                H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);

            /* Free buf */
            HDfree(buf);
        } /* end if */

        H5Aclose(attr_out);
        H5Sclose(space_id);
        H5Tclose(wtype_id);
        H5Tclose(ftype_id);
        H5Aclose(attr_id);
    } H5E_END_TRY;

    return ret_value;
} /* end copy_attr() */