コード例 #1
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTread_packets
 *
 * Purpose: Reads packets from anywhere in a packet table
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: March 12, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTread_packets( hid_t table_id,
                         hsize_t start,
                         size_t nrecords,
                         void *data)
{
  htbl_t * table;

  /* find the table struct from its ID */
  table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type);
  if(table == NULL)
    goto out;

  /* If nrecords == 0, do nothing */
  if(nrecords == 0)
    return 0;

  if( H5TB_common_read_records(table->dset_id, table->type_id,
                              start, nrecords, table->size, data) < 0)
    goto out;

  return 0;

out:
  return -1;
}
コード例 #2
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
herr_t H5PTfree_vlen_readbuff( hid_t table_id,
                               size_t _bufflen,
                               void * buff )
{
  hid_t space_id = H5I_BADID;
  htbl_t * table;
  hsize_t bufflen = _bufflen;
  herr_t ret_value;

  /* find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    goto out;

  if((space_id = H5Screate_simple(1, &bufflen, NULL)) < 0)
    goto out;

  /* Free the memory.  If this succeeds, ret_value should be 0. */
  if((ret_value = H5Dvlen_reclaim(table->type_id, space_id, H5P_DEFAULT, buff)) < 0)
    goto out;

  /* If the dataspace cannot be closed, return -2 to indicate that memory */
  /* was freed successfully but an error still occurred. */
  if(H5Sclose(space_id) < 0)
    return -2;

  return ret_value;

out:
  H5E_BEGIN_TRY
    H5Sclose(space_id);
  H5E_END_TRY
  return -1;
}
コード例 #3
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTget_next
 *
 * Purpose: Reads packets starting at the current index and updates
 *          that index
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: March 10, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTget_next( hid_t table_id,
                             size_t nrecords,
                             void * data)
{
  htbl_t * table;

  /* Find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    goto out;

  /* If nrecords == 0, do nothing */
  if(nrecords == 0)
    return 0;

  if((H5TB_common_read_records(table->dset_id, table->type_id,
                              table->current_index, nrecords, table->size, data)) < 0)
    goto out;

  /* Update the current index */
  table->current_index += nrecords;
  return 0;

out:
  return -1;
}
コード例 #4
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTappend
 *
 * Purpose: Appends packets to the end of a packet table
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: March 12, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTappend( hid_t table_id,
                           size_t nrecords,
                           const void * data )
{
  htbl_t * table;

  /* Find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    goto out;

  /* If we are asked to write 0 records, just do nothing */
  if(nrecords == 0)
    return 0;

  if((H5TB_common_append_records(table->dset_id, table->type_id,
  			nrecords, table->size, data)) < 0)
    goto out;

  /* Update table size */
  table->size += nrecords;
  return 0;

out:
  return -1;
}
コード例 #5
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTis_valid
 *
 * Purpose: Validates a table identifier
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: March 12, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTis_valid(hid_t table_id)
{
  /* find the table struct from its ID */
  if(H5Iobject_verify(table_id, H5PT_ptable_id_type) ==NULL)
    return -1;

  return 0;
}
コード例 #6
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
herr_t H5PTget_index(hid_t table_id, hsize_t *pt_index)
{
  htbl_t * table;

  /* find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    return -1;

  return H5PT_get_index(table, pt_index);
}
コード例 #7
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTcreate_index, H5PTset_index, H5PTget_index
 *
 * Purpose: Resets, sets, and gets the current record index for a packet table
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: April 23, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTcreate_index(hid_t table_id)
{
  htbl_t * table;

  /* find the table struct from its ID */
  if((table = (htbl_t *) (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    return -1;

  return H5PT_create_index(table);
}
コード例 #8
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTget_num_packets
 *
 * Purpose: Returns by reference the number of packets in the dataset
 *
 * Return: Success: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: March 12, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTget_num_packets( hid_t table_id, hsize_t *nrecords)
{
  htbl_t * table;

  /* find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    goto out;

  if(nrecords)
    *nrecords = table->size;

  return 0;
out:
  return -1;
}
コード例 #9
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTis_varlen
 *
 * Purpose: Returns 1 if a table_id corresponds to a packet table of variable-
 *          length records or 0 for fixed-length records.
 *
 * Return: True: 1, False: 0, Failure: -1
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: April 14, 2004
 *
 * Comments:
 *
 * Modifications:
 *
 *
 *-------------------------------------------------------------------------
 */
herr_t H5PTis_varlen(hid_t table_id)
{
  H5T_class_t type;
  htbl_t * table;

  /* find the table struct from its ID */
  if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
    goto out;

  if((type = H5Tget_class( table->type_id )) == H5T_NO_CLASS)
    goto out;

  if( type == H5T_VLEN )
    return 1;
  else
    return 0;
out:
  return -1;
}
コード例 #10
0
ファイル: tid.c プロジェクト: asteever/thirdparty_hdf5
/* 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;
}
コード例 #11
0
ファイル: tid.c プロジェクト: asteever/thirdparty_hdf5
/* Ensure that public functions cannot access "predefined" ID types */
static int id_predefined_test(void )
{
    void * testObj;
    hid_t testID;
    hid_t typeID = H5I_INVALID_HID;
    void * testPtr;
    herr_t testErr;

    testObj = HDmalloc(sizeof(int));

    /* Try to perform illegal functions on various predefined types */
    H5E_BEGIN_TRY
    testID = H5Iregister(H5I_FILE, testObj);
    H5E_END_TRY

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

    H5E_BEGIN_TRY
    testPtr = H5Isearch(H5I_GENPROP_LST, (H5I_search_func_t) test_search_func, testObj);
    H5E_END_TRY

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

    H5E_BEGIN_TRY
    testErr = H5Inmembers(H5I_ERROR_STACK, NULL);
    H5E_END_TRY

    VERIFY(testErr, -1, "H5Inmembers");
    if(testErr != -1)
        goto out;

    H5E_BEGIN_TRY
    testErr = H5Iclear_type(H5I_FILE, 0);
    H5E_END_TRY

    VERIFY((testErr >= 0), 0, "H5Iclear_type");
    if(testErr >= 0)
        goto out;

    H5E_BEGIN_TRY
    testErr = H5Idestroy_type(H5I_DATASET);
    H5E_END_TRY

    VERIFY((testErr >= 0), 0, "H5Idestroy_type");
    if(testErr >= 0)
        goto out;

    /* Create a datatype ID and try to perform illegal functions on it */
    typeID = H5Tcreate(H5T_OPAQUE, (size_t)42);
    CHECK(typeID, H5I_INVALID_HID, "H5Tcreate");
    if(typeID == H5I_INVALID_HID)
        goto out;

    H5E_BEGIN_TRY
    testPtr = H5Iremove_verify(typeID, H5I_DATATYPE);
    H5E_END_TRY

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

    H5E_BEGIN_TRY
    testPtr = H5Iobject_verify(typeID, H5I_DATATYPE);
    H5E_END_TRY

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

    H5Tclose(typeID);

    /* testObj was never registered as an atom, so it will not be
         * automatically freed. */
    HDfree(testObj);
    return 0;

out:
    if(typeID != H5I_INVALID_HID)
        H5Tclose(typeID);
    if(testObj != NULL)
        HDfree(testObj);

    return -1;
}