コード例 #1
0
ファイル: h5oImp.c プロジェクト: soumagne/hdf5
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Ocopy
 * Signature: (JLjava/lang/String;JLjava/lang/String;JJ)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Ocopy
    (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name,
        jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id)
{
    const char *lCurName = NULL;
    const char *lDstName = NULL;
    herr_t      status = FAIL;

    UNUSED(clss);

    if (NULL == cur_name)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ocopy: src name is NULL");
    if (NULL == dst_name)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ocopy: dst name is NULL");

    PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Ocopy: src name not pinned");
    PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Ocopy: dest name not pinned");

    if ((status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

done:
    if (lDstName)
        UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName);
    if (lCurName)
        UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName);
} /* end Java_hdf_hdf5lib_H5_H5Ocopy */
コード例 #2
0
/* ***if* H5Of/H5Ocopy_c
 * NAME
 *  H5Ocopy_c
 * PURPOSE
 *  Calls H5Ocopy
 * INPUTS  
 *  src_loc_id   - Object identifier indicating the location of the source object to be copied 
 *  src_name     - Name of the source object to be copied 
 *  src_name_len - Length of src_name
 *  dst_loc_id   - Location identifier specifying the destination 
 *  dst_name     - Name to be assigned to the new copy 
 *  dst_name_len - Length of dst_name
 *  ocpypl_id    - Object copy property list
 *  lcpl_id      - Link creation property list for the new hard link
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  March 14, 2012
 * SOURCE
*/
int_f
nh5ocopy_c (hid_t_f *src_loc_id, _fcd src_name, size_t_f *src_name_len,
	    hid_t_f *dst_loc_id, _fcd dst_name, size_t_f *dst_name_len, 
	    hid_t_f *ocpypl_id, hid_t_f *lcpl_id )
/******/
{
  char *c_src_name = NULL;  /* Buffer to hold C string */
  char *c_dst_name = NULL;  /* Buffer to hold C string */
  
  int_f ret_value = 0;      /* Return value */
  
  /*
   * Convert FORTRAN name to C name
   */
  if((c_src_name = HD5f2cstring(src_name, (size_t)*src_name_len)) == NULL)
    HGOTO_DONE(FAIL);
  if((c_dst_name = HD5f2cstring(dst_name, (size_t)*dst_name_len)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Ocopy function.
   */
  if(H5Ocopy( (hid_t)*src_loc_id, c_src_name, (hid_t)*dst_loc_id, c_dst_name, 
	      (hid_t)*ocpypl_id, (hid_t)*lcpl_id) < 0)
    HGOTO_DONE(FAIL);

 done:
  if(c_src_name)
    HDfree(c_src_name);
  if(c_dst_name)
    HDfree(c_dst_name);

  return ret_value;

}
コード例 #3
0
ファイル: h5oImp.c プロジェクト: ngcurrier/ProteusCFD
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Ocopy
 * Signature: (JLjava/lang/String;JLjava/lang/String;JJ)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Ocopy
    (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name,
        jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id)
{
    herr_t      status = -1;
    const char *lCurName;
    const char *lDstName;

    PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName);
    if (lCurName != NULL && lDstName != NULL) {
        status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id);

        UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName);

        if (status < 0)
            h5libraryError(env);
    }
} /* end Java_hdf_hdf5lib_H5_H5Ocopy */
コード例 #4
0
ファイル: datCopy.c プロジェクト: Starlink/hds-v5
int
datCopy( const HDSLoc *locator1, const HDSLoc *locator2,
         const char *name_str, int *status) {

  char sourcename[DAT__SZNAM+1];
  char cleanname[DAT__SZNAM+1];
  hid_t parent_id = -1;
  hid_t objid = -1;

  if (*status != SAI__OK) return *status;

  /* Validate input locators. */
  dat1ValidateLocator( "datCopy", 1, locator1, 1, status );
  dat1ValidateLocator( "datCopy", 1, locator2, 0, status );

  dau1CheckName( name_str, 1, cleanname, sizeof(cleanname), status );
  if (*status != SAI__OK) return *status;

  /* Have to give the source name as "." doesn't seem to be allowed.
     so get the name and the parent locator. */
  objid = dat1RetrieveIdentifier( locator1, status );

  /* If we are at the root group we can not get a parent so just use
     the "/" name instead */
  parent_id = dat1GetParentID( objid, 1, status );
  if (*status == DAT__OBJIN) {
    emsAnnul(status);
    star_strlcpy( sourcename, "/", sizeof(sourcename));
    parent_id = -1;
  } else {
    datName( locator1, sourcename, status );
  }
  CALLHDFQ(H5Ocopy( (parent_id == -1 ? objid : parent_id), sourcename,
                    locator2->group_id, cleanname, H5P_DEFAULT, H5P_DEFAULT));

 CLEANUP:
  if (parent_id) H5Gclose(parent_id);
  return *status;

}
コード例 #5
0
ファイル: ohdr.c プロジェクト: MichaelToal/hdf5
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:     Exercise private object header behavior and routines
 *
 * Return:	Success:        0
 *		Failure:        1
 *
 * Programmer:	Robb Matzke
 *              Tuesday, November 24, 1998
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl = -1, file = -1;
    hid_t	dset = -1;
    H5F_t	*f = NULL;
    char	filename[1024];
    H5O_hdr_info_t hdr_info;            /* Object info */
    H5O_loc_t	oh_loc, oh_loc2;        /* Object header locations */
    time_t	time_new, ro;
    int         chunkno;                /* Chunk index for message */
    int		i;                      /* Local index variable */
    hbool_t     b;                      /* Index for "new format" loop */
    herr_t      ret;                    /* Generic return value */

    /* Reset library */
    h5_reset();
    fapl = h5_fileaccess();
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);

    /* Loop over old & new formats */
    for(b = FALSE; b <= TRUE; b++) {
        /* Display info about testing */
        if(b)
            HDputs("Using new file format:");
        else
            HDputs("Using default file format:");

        /* Set the format to use for the file */
        if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0)
            FAIL_STACK_ERROR

	/* test on object continuation block */
	if(test_cont(filename, fapl) < 0)
            FAIL_STACK_ERROR

        /* Create the file to operate on */
        if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
            TEST_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR
        if (H5AC_ignore_tags(f) < 0) {
	    H5_FAILED();
	    H5Eprint2(H5E_DEFAULT, stdout);
	    goto error;
        }


        /*
         * Test object header creation
         * (using default group creation property list only because it's convenient)
         */
        TESTING("object header creation");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* create a new message */
        TESTING("message creation");
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        PASSED();


        /*
         * Test modification of an existing message.
         */
        TESTING("message modification");
        time_new = 33333333;
        if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR

        /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total >=256)
            TEST_ERROR

        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows in core.
         * (Use 'old' MTIME message here, because it is large enough to be
         *  replaced with a continuation message (the new one is too small)
         *  and the library doesn't understand how to migrate more than one
         *  message from an object header currently - QAK - 10/8/03)
         */
        TESTING("object header overflow in memory");
        for(i = 0; i < 40; i++) {
            time_new = (i + 1) * 1000 + 1000000;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR

        /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total < 256)
            TEST_ERROR

        PASSED();

        /* Close & re-open file & object header */
        /* (makes certain that an object header in the new format that transitions
         *  between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding
         *  works correctly - QAK)
         */
        TESTING("close & re-open object header");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        if(H5Fclose(file) < 0)
            FAIL_STACK_ERROR
        if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
            FAIL_STACK_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR
        if (H5AC_ignore_tags(f) < 0)
            FAIL_STACK_ERROR
        oh_loc.file = f;
        if(H5O_open(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows on disk.
         */
        TESTING("object header overflow on disk");
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        PASSED();

        /*
         * Delete all time messages.
         */
        TESTING("message deletion");
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        PASSED();


        /*
         * Constant message handling.
         * (can't write to them, but should be able to remove them)
         */
        TESTING("constant message handling");
        time_new = 22222222;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        time_new = 33333333;
        H5E_BEGIN_TRY {
            ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* release resources */
        TESTING("object header closing");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test moving message to first chunk
         */
        TESTING("locking messages");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Add message to lock to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to lock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Delete all the other messages, which would move the message into
         * chunk #0, if it wasn't locked
         */
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to unlock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        /* Open first object header */
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Add message to move to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        /* (would normally move locked message to new chunk) */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        PASSED();


        /* Test reading datasets with undefined object header messages
         * and the various "fail/mark if unknown" object header message flags
         */
        HDputs("Accessing objects with unknown header messages:");
        {
            hid_t file2;                    /* File ID for 'bogus' object file */
            hid_t sid;                      /* Dataspace ID */
            hid_t aid;                      /* Attribute ID */
            const char *testfile = H5_get_srcdir_filename(FILE_BOGUS);

            TESTING("object with unknown header message and no flags set");

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Open the dataset with the unknown header message, but no extra flags */
            if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object in r/o file with unknown header message & 'fail if unknown and open for write' flag set");

            /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object in r/o file with unknown header message & 'fail if unknown always' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */

            PASSED();

            TESTING("object with unknown header message & 'mark if unknown' flag set");

            /* Copy object with "mark if unknown" flag on message into file that can be modified */
            if(H5Ocopy(file2, "/Dataset4", file, "/Dataset4", H5P_DEFAULT, H5P_DEFAULT) < 0)
                TEST_ERROR

            /* Close the file we created (to flush changes to file) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created, with read-only permissions */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was _NOT_ marked */
            if(H5O_check_msg_marked_test(dset, FALSE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Create data space */
            if((sid = H5Screate(H5S_SCALAR)) < 0)
                FAIL_STACK_ERROR

            /* Create an attribute, to get the object header into write access */
            if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
                FAIL_STACK_ERROR

            /* Close dataspace */
            if(H5Sclose(sid) < 0)
                FAIL_STACK_ERROR

            /* Close attribute */
            if(H5Aclose(aid) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Re-open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was marked */
            if(H5O_check_msg_marked_test(dset, TRUE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file with the bogus objects */
            if(H5Fclose(file2) < 0)
                TEST_ERROR

            PASSED();

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
                TEST_ERROR

            TESTING("object in r/w file with unknown header message & 'fail if unknown and open for write' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */

            PASSED();

            TESTING("object in r/w file with unknown header message & 'fail if unknown always' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */
コード例 #6
0
void MAJ_236_300_champs(med_idt fid)
{
  med_err lret,ret;
  /*   med_idt         _datagroup=0; */
  med_field_type   typcha;
  char nomcha    [MED_NAME_SIZE+1]="";
  char _meshname [MED_NAME_SIZE+1]="";
  char _dtunit   [MED_SNAME_SIZE+1]="";
  char *comp= NULL, *unit= NULL;
  med_int   ncomp,ncha;
  med_int  _ncstp=0;
  med_bool _local=MED_FALSE;
  htri_t   _datasetexist;
  char _pathi[MED_TAILLE_CHA+1+MED_NAME_SIZE+1]=MED_CHA;
  char _pathf[MED_TAILLE_CHA+2+MED_NAME_SIZE+1]="/CHA_/";
  char _pathtmp[MED_TAILLE_CHA+3]="/CHA__/";
  int i,j;

  char nomlien[MED_NAME_SIZE+1]="";
  char * lien = NULL;
  med_int nln,nval;

  med_int  _nloc,_intgeotype,_sdim;
  char     _pathloc[MED_TAILLE_GAUSS+MED_NAME_SIZE+1]=MED_GAUSS;

  med_int  _npar,_numdt,_numit;
  char     _pathpari[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
  char     _pathparf[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
  int      _pathparlen;
  med_size _n=0;
  char     _cpstnamei[2*MED_MAX_PARA+1]="";
  char     _cpstnamef[2*MED_MAX_PARA+1]="";
  char     _uniname[MED_SNAME_SIZE+1]="";
/*   hid_t    _lac_plist_id; */
  hid_t    _lcp_plist_id;
  hid_t    _ocp_plist_id;
  med_bool _createunt = MED_TRUE;

  MAJ_version_num(fid,2,3,6);

  /* MAJ des varaibles scalaires */
  _npar = MEDnParameter(fid);
  if (_npar > 0) {
    fprintf(stdout,"  >>> Normalisation des paramètres scalaires\n");
    _pathparf[MED_TAILLE_NUM_DATA-2]='_';
/*     _lac_plist_id = H5Pcreate( H5P_LINK_ACCESS ); */
    _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY );
    _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE );
    H5Pset_create_intermediate_group( _lcp_plist_id, 1 );
    H5Pset_copy_object( _ocp_plist_id, H5O_COPY_SHALLOW_HIERARCHY_FLAG);
  }

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

    MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,i, &_pathpari[MED_TAILLE_NUM_DATA]) < 0,
		     MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);


    strcpy(&_pathparf[MED_TAILLE_NUM_DATA],&_pathpari[MED_TAILLE_NUM_DATA]);
/*     SSCRUTE(_pathparf); */
/*     SSCRUTE(_pathpari); */

    /*Copie le group avec ses attributs et les objets de premier niveau.*/
    ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id);
/*     ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
    EXIT_IF(ret < 0,"Copie du datagroup",_pathpari);

    _pathparlen=strlen(_pathpari);
    _pathpari[_pathparlen]='/';_pathparf[_pathparlen]='/';
    ++_pathparlen;
    _pathpari[_pathparlen]='\0';_pathparf[_pathparlen]='\0';

/*     SSCRUTE(_pathparf); */
/*     SSCRUTE(_pathpari); */

    ret =_MEDnObjects(fid,_pathpari, &_n);
    MED_ERR_EXIT_IF( (ret == (MED_ERR_COUNT + MED_ERR_DATAGROUP)), MED_ERR_COUNT,MED_ERR_PARAMETER,_pathpari);

    for (j=0 ; j < _n ; ++j ) {
      MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,j, &_pathpari[_pathparlen]) < 0,
		       MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);

      MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NOR,
						MED_INTERNAL_INT,(unsigned char * const ) &_numit) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NOR);

      MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NDT,
						MED_INTERNAL_INT,(unsigned char * const ) &_numdt) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
      
      MED_ERR_EXIT_IF (_MEDattributeStringRdByName(fid,_pathpari,MED_NOM_UNI,
						MED_SNAME_SIZE,_uniname) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
      
      _MEDgetComputationStepName(MED_SORT_DTIT,_numdt,_numit,&_pathparf[_pathparlen]);
/*       strcat(_pathpari,"/"); */
/*       strcat(_pathparf,"/"); */
/*       SSCRUTE(_pathparf); */
/*       SSCRUTE(_pathpari); */

/*       ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id); */
/*       ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
/*       H5Eprint1(stderr); */
/*       EXIT_IF(ret < 0,"Copie d'une étape de calcul du paramètre scalaire ",_pathpari); */

      /*On modifie temporairement _pathpari pour pointer dans _pathparf*/
      _pathpari[MED_TAILLE_NUM_DATA-2]='_';
/*       SSCRUTE(_pathparf); */
/*       SSCRUTE(_pathpari); */
      ret = H5Gmove(fid, _pathpari, _pathparf  );
      EXIT_IF(ret < 0,"Renommage de l'étape de calcul",_pathpari);
      _pathpari[MED_TAILLE_NUM_DATA-2]='A';


      MED_ERR_EXIT_IF(H5Adelete_by_name( fid, _pathparf, MED_NOM_UNI, H5P_DEFAULT ) < 0,
		      MED_ERR_DELETE,MED_ERR_ATTRIBUTE,_pathparf);

      _pathparf[_pathparlen]='\0';
      _pathpari[_pathparlen]='\0';
      if ( _createunt ) {
	MED_ERR_EXIT_IF (_MEDattributeStringWrByName(fid,_pathparf,MED_NOM_UNT, MED_SNAME_SIZE,_uniname) < 0,
			 MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNT);
	_createunt = MED_FALSE;
      }
    }
    _createunt = MED_TRUE;
    _pathpari[MED_TAILLE_NUM_DATA]='\0';
  }

  if ( _npar > 0 ) {

    _pathpari[MED_TAILLE_NUM_DATA]='\0';
    _pathparf[MED_TAILLE_NUM_DATA]='\0';
    MED_ERR_EXIT_IF ( H5Ldelete(fid,_pathpari,H5P_DEFAULT) < 0 ,
		      MED_ERR_DELETE,MED_ERR_LINK,_pathpari);

    ret = H5Gmove(fid, _pathparf, _pathpari  );
    EXIT_IF(ret < 0,"Renommage du group de paramètres scalaires",_pathparf);

  }

  /* MAJ des localisations */
  _nloc = MEDnLocalization(fid);
/*   ISCRUTE(_nloc); */
  if (_nloc > 0)
    fprintf(stdout,"  >>> Normalisation des localisations des points d'intégration\n");
  for (i=0 ; i < _nloc ; i++ ) {

/*     SSCRUTE(_pathloc); */
    MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathloc ,i, &_pathloc[MED_TAILLE_GAUSS]) < 0,
		     MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathloc);
/*     SSCRUTE(_pathloc); */
    MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathloc,MED_NOM_GEO,
					      MED_INTERNAL_INT,(unsigned char * const ) &_intgeotype) < 0,
		     MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    _sdim = (_intgeotype/100);

    MED_ERR_EXIT_IF (_MEDattributeNumWrByName(fid,_pathloc,MED_NOM_DIM,
					      MED_INTERNAL_INT,(const unsigned char * const) &_sdim) < 0,
		     MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_DIM);

    MED_ERR_EXIT_IF ( _MEDattributeStringWrByName(fid,_pathloc,MED_NOM_INM,MED_NAME_SIZE,"") < 0,
		      MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_INM);
    _pathloc[MED_TAILLE_GAUSS]='\0';

  }

  /* MAJ des liens */
  nln = MEDnLink(fid);
  if (nln > 0)
    fprintf(stdout,"  >>> Normalisation des liens\n");
  for (i=1 ; i <= nln ; i++ ) {


    ret =  MEDlinkInfo(fid, i, nomlien, &nval);
    EXIT_IF(ret,"Erreur a la demande d'information sur le lien",NULL);

/*     printf("\t- Lien n°%i de nom |%s| et de taille "IFORMAT"\n",i,nomlien,nval); */

    lien = (char *) malloc((nval+1)*sizeof(char));
    EXIT_IF(lien == NULL,NULL,NULL);

    ret = MEDlinkRd(fid, nomlien, lien );
    EXIT_IF(ret,"Erreur a la lecture du lien : ",nomlien);

    MAJ_version_num(fid,3,0,8);
    ret = MED30linkWr(fid,nomlien,lien);
    EXIT_IF(ret,"Erreur a l'écrtiure du lien : ",nomlien);
    MAJ_version_num(fid,2,3,6);
 
    lien[nval] = '\0';
/*     printf("\t\t|%s|\n\n",lien); */

    free(lien);
  }

  /* combien de champs dans le fichier */
  ncha = MEDnField(fid);
  EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL);

  /* MAJ des champs */
  for (i =0;i<ncha;i++) {
    lret = 0;

    /* Lecture du nombre de composantes */
    ncomp = MEDfieldnComponent(fid,i+1);
    if (ncomp < 0) {
      MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp);
      exit(1);
    }

    /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/
    comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
    EXIT_IF(comp == NULL,NULL,NULL);
    unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
    EXIT_IF(unit == NULL,NULL,NULL);

    /*     ret = MED231champInfoEtRen(fid,i+1,nomcha,&typcha,comp,unit,ncomp); */
    ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp);
    MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha);

    /* creation du champ destination */
    MAJ_version_num(fid,3,0,8);

    EXIT_IF( H5Gmove(fid, _pathi, _pathtmp  ) < 0,"Switch to ",_pathtmp);
    _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
    if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathi); }

    MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0,
		     MED_ERR_CREATE,MED_ERR_FIELD,_pathf);
    EXIT_IF( H5Gmove(fid, _pathi  , _pathf  ) < 0,"Switch to ",_pathf);
    EXIT_IF( H5Gmove(fid, _pathtmp, _pathi  ) < 0,"Switch to ",_pathi);

    MAJ_version_num(fid,2,3,6);

    free(comp);
    free(unit);

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux noeuds "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_CELL,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux mailles "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_FACE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux faces "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_EDGE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE_ELEMENT,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
    }

  }
  _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );

  if (_datasetexist ) {
    EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
    EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathf);
  }


}
コード例 #7
0
ファイル: h5copy.c プロジェクト: ElaraFX/hdf5
int
main (int argc, const char *argv[])
{
    hid_t        fid_src = -1;
    hid_t        fid_dst = -1;
    unsigned     flag = 0;
    unsigned     verbose = 0;
    unsigned     parents = 0;
    hid_t        ocpl_id = (-1);          /* Object copy property list */
    hid_t        lcpl_id = (-1);          /* Link creation property list */
    int          opt;
    int          li_ret;
    h5tool_link_info_t linkinfo;

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* initialize h5tools lib */
    h5tools_init();

    /* init linkinfo struct */
    HDmemset(&linkinfo, 0, sizeof(h5tool_link_info_t));

    /* Check for no command line parameters */
    if(argc == 1) 
    {
        usage();
        leave(EXIT_FAILURE);
    } /* end if */

    /* parse command line options */
    while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF)
    {
        switch ((char)opt)
        {
        case 'd':
            oname_dst = HDstrdup(opt_arg);
            break;

        case 'f':
            /* validate flag */
            if (parse_flag(opt_arg,&flag)<0)
            {
                usage();
                leave(EXIT_FAILURE);
            }
            str_flag = HDstrdup(opt_arg);
            break;

        case 'h':
            usage();
            leave(EXIT_SUCCESS);
            break;

        case 'i':
            fname_src = HDstrdup(opt_arg);
            break;

        case 'o':
            fname_dst = HDstrdup(opt_arg);
            break;

        case 'p':
            parents = 1;
            break;

        case 's':
            oname_src = HDstrdup(opt_arg);
            break;

        case 'V':
            print_version(h5tools_getprogname());
            leave(EXIT_SUCCESS);
            break;

        case 'v':
            verbose = 1;
            break;

        default:
            usage();
            leave(EXIT_FAILURE);
        }
    } /* end of while */

/*-------------------------------------------------------------------------
 * check for missing file/object names
 *-------------------------------------------------------------------------*/

    if (fname_src==NULL)
    {
        error_msg("Input file name missing\n");
        usage();
        leave(EXIT_FAILURE);
    }

    if (fname_dst==NULL)
    {
        error_msg("Output file name missing\n");
        usage();
        leave(EXIT_FAILURE);
    }

    if (oname_src==NULL)
    {
        error_msg("Source object name missing\n");
        usage();
        leave(EXIT_FAILURE);
    }

    if (oname_dst==NULL)
    {
        error_msg("Destination object name missing\n");
        usage();
        leave(EXIT_FAILURE);
    }

   /*-------------------------------------------------------------------------
    * open output file
    *-------------------------------------------------------------------------*/

    /* Attempt to open an existing HDF5 file first. Need to open the dst file
       before the src file just in case that the dst and src are the same file
     */
    fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, H5P_DEFAULT, NULL, NULL, 0);

   /*-------------------------------------------------------------------------
    * open input file
    *-------------------------------------------------------------------------*/

    fid_src = h5tools_fopen(fname_src, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, 0);

   /*-------------------------------------------------------------------------
    * test for error in opening input file
    *-------------------------------------------------------------------------*/
    if (fid_src==-1)
    {
        error_msg("Could not open input file <%s>...Exiting\n", fname_src);
        leave(EXIT_FAILURE);
    }


   /*-------------------------------------------------------------------------
    * create an output file when failed to open it
    *-------------------------------------------------------------------------*/

    /* If we couldn't open an existing file, try creating file */
    /* (use "EXCL" instead of "TRUNC", so we don't blow away existing non-HDF5 file) */
    if(fid_dst < 0)
        fid_dst = H5Fcreate(fname_dst, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);

   /*-------------------------------------------------------------------------
    * test for error in opening output file
    *-------------------------------------------------------------------------*/
    if (fid_dst==-1)
    {
        error_msg("Could not open output file <%s>...Exiting\n", fname_dst);
        leave(EXIT_FAILURE);
    }

   /*-------------------------------------------------------------------------
    * print some info
    *-------------------------------------------------------------------------*/

    if (verbose)
    {
        printf("Copying file <%s> and object <%s> to file <%s> and object <%s>\n",
        fname_src, oname_src, fname_dst, oname_dst);
        if (flag) {
            HDassert(str_flag);
            printf("Using %s flag\n", str_flag);
        }
    }


   /*-------------------------------------------------------------------------
    * create property lists for copy
    *-------------------------------------------------------------------------*/

    /* create property to pass copy options */
    if ( (ocpl_id = H5Pcreate(H5P_OBJECT_COPY)) < 0)
        goto error;

    /* set options for object copy */
    if (flag)
    {
        if ( H5Pset_copy_object(ocpl_id, flag) < 0)
            goto error;
    }

    /* Create link creation property list */
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) < 0) {
        error_msg("Could not create link creation property list\n");
        goto error;
    } /* end if */

    /* Check for creating intermediate groups */
    if(parents) {
        /* Set the intermediate group creation property */
        if(H5Pset_create_intermediate_group(lcpl_id, 1) < 0) {
            error_msg("Could not set property for creating parent groups\n");
            goto error;
        } /* end if */

        /* Display some output if requested */
        if(verbose)
            printf("%s: Creating parent groups\n", h5tools_getprogname());
    } /* end if */
    else /* error, if parent groups doesn't already exist in destination file */
    {
        size_t        i, len;

        len = HDstrlen(oname_dst);        

        /* check if all the parents groups exist. skip root group */
        for (i = 1; i < len; i++)
        {
            if ('/'==oname_dst[i])
            {
                char         *str_ptr;

                str_ptr = (char *)HDcalloc(i + 1, sizeof(char));
                HDstrncpy(str_ptr, oname_dst, i);
                str_ptr[i]='\0';
                if (H5Lexists(fid_dst, str_ptr, H5P_DEFAULT) <= 0)
                {
                    error_msg("group <%s> doesn't exist. Use -p to create parent groups.\n", str_ptr);
                    HDfree(str_ptr);
                    goto error;
                }
                HDfree(str_ptr);
            }
        }
    }

   /*-------------------------------------------------------------------------
    * do the copy
    *-------------------------------------------------------------------------*/
 
    if(verbose)
        linkinfo.opt.msg_mode = 1;
 
    li_ret = H5tools_get_symlink_info(fid_src, oname_src, &linkinfo, 1);
    if (li_ret == 0) /* dangling link */
    {
        if(H5Lcopy(fid_src, oname_src, 
                   fid_dst, oname_dst,
                   H5P_DEFAULT, H5P_DEFAULT) < 0)
            goto error;
    }
    else /* valid link */
    {
        if (H5Ocopy(fid_src,          /* Source file or group identifier */
                  oname_src,        /* Name of the source object to be copied */
                  fid_dst,          /* Destination file or group identifier  */
                  oname_dst,        /* Name of the destination object  */
                  ocpl_id,          /* Object copy property list */
                  lcpl_id)<0)       /* Link creation property list */
            goto error;
    }

    /* free link info path */
    if (linkinfo.trg_path)
        HDfree(linkinfo.trg_path);

    /* close propertis */
    if(H5Pclose(ocpl_id)<0)
        goto error;
    if(H5Pclose(lcpl_id)<0)
        goto error;

    /* close files */
    if (H5Fclose(fid_src)<0)
        goto error;
    if (H5Fclose(fid_dst)<0)
        goto error;

    leave(EXIT_SUCCESS);

error:
    printf("Error in copy...Exiting\n");

    /* free link info path */
    if (linkinfo.trg_path)
        HDfree(linkinfo.trg_path);

 H5E_BEGIN_TRY {
    H5Pclose(ocpl_id);
    H5Pclose(lcpl_id);
    H5Fclose(fid_src);
    H5Fclose(fid_dst);
 } H5E_END_TRY;

 leave(EXIT_FAILURE);
}