Пример #1
0
/*-------------------------------------------------------------------------
 * test_error
 *
 * ensures that the packet table API throws the correct errors used on
 * objects that are not packet tables.
 *
 *-------------------------------------------------------------------------
 */
static int test_error(hid_t fid)
{
    hid_t id = H5I_BADID;
    int id_open=0;
    particle_t readBuf[1];

    TESTING("error conditions");

    /* Create a HL table */
    if(create_hl_table(fid) < 0)
        goto out;

    /* Try to open things that are not packet tables */
    H5E_BEGIN_TRY
    if(H5PTopen(fid, "Bogus_name") >= 0)
        goto out;
    if(H5PTopen(fid, "group1") >= 0)
        goto out;
    H5E_END_TRY

    /* Try to execute packet table commands on an invalid ID */
    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    /* Open a high-level non-packet (H5TB) table and try to */
    /* execute commands on it. */
    if((id=H5Dopen2(fid, H5TB_TABLE_NAME, H5P_DEFAULT)) <0)
        goto out;
    id_open = 1;

    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    id_open=0;
    if(H5Dclose(id) <0)
        goto out;

    /* Open and close a packet table.  Try to execute */
    /* commands on the closed ID. */
    if((id=H5PTopen(fid, PT_NAME))<0)
        goto out;
    if(H5PTclose(id) <0)
        goto out;

    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    PASSED();
    return 0;

out:
    H5_FAILED();
    if(id_open)
        H5Dclose(id);
    return -1;
}
Пример #2
0
/*-------------------------------------------------------------------------
 * test_rw_non-native_dt
 *
 * test reading and writing packet table using datatypes that are not
 * native.
 *
 *-------------------------------------------------------------------------
 */
static int test_rw_nonnative_dt(hid_t fid)
{
    hid_t          ptable;     /* Packet table identifier */

    herr_t         err;        /* Function return status */
    hsize_t        count;      /* Number of records in the table */

    int            x;          /* Loop variable */

    /* Buffers to hold data */
    int writeBuffer[5];
    int readBuffer[5];

    TESTING("reading/writing non-native packet table");

    /* Initialize buffers */
    for(x=0; x<5; x++) {
        writeBuffer[x]=x;
        readBuffer[x] = -1;
    }

    /* Create a fixed-length packet table within the file */
    /* This table's "packets" will be simple integers and it will use no compression */
    if(H5Tget_order(H5T_NATIVE_INT) == H5T_ORDER_LE) {
        ptable = H5PTcreate_fl(fid, "Packet Test Dataset, Non-native", H5T_STD_I32BE, (hsize_t)100, -1);
    } else {
        ptable = H5PTcreate_fl(fid, "Packet Test Dataset, Non-native", H5T_STD_I32LE, (hsize_t)100, -1);
    }
    if(ptable == H5I_INVALID_HID)
        goto out;

    /* Write one packet to the packet table */
    if( (err = H5PTappend(ptable, (hsize_t)1, &(writeBuffer[0]))) < 0 )
        goto out;

    /* Write several packets to the packet table */
    if( (err = H5PTappend(ptable, (hsize_t)4, &(writeBuffer[1]))) < 0)
        goto out;

    if( (err = H5PTclose(ptable)) < 0)
        goto out;

    /* Open the Packet table */
    if( (ptable = H5PTopen(fid, "Packet Test Dataset, Non-native")) < 0)
        goto out;

    /* Get the number of packets in the packet table.  This should be five. */
    if( (err = H5PTget_num_packets(ptable, &count)) < 0)
        goto out;

    if( (int)count != 5 )
        goto out;

    /* Initialize packet table's "current record" */
    if( (err = H5PTcreate_index(ptable)) < 0)
        goto out;

    /* Iterate through packets, read each one back */
    for(x=0; x<5; x++) {
        if( (err = H5PTget_next(ptable, (hsize_t)1, &(readBuffer[x]))) < 0)
            goto out;
        if( x != readBuffer[x])
            goto out;
    }

    /* Close the packet table */
    if( (err = H5PTclose(ptable)) < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(ptable) < 0)
        H5PTclose(ptable);
    return -1;
}
Пример #3
0
int main(void)
{
 hid_t          fid;        /* File identifier */
 hid_t          ptable;     /* Packet table identifier */

 herr_t         err;        /* Function return status */
 hsize_t        count;      /* Number of records in the table */

 int            x;          /* Loop variable */

    /* Buffers to hold data */
 int writeBuffer[5];
 int readBuffer[5];

   /* Initialize buffers */
 for(x=0; x<5; x++)
 {
     writeBuffer[x]=x;
     readBuffer[x] = -1;
 }

    /* Create a file using default properties */
 fid=H5Fcreate("packet_table_FLexample.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);

    /* Create a fixed-length packet table within the file */
    /* This table's "packets" will be simple integers and it will use compression
     * level 5. */
 ptable = H5PTcreate_fl(fid, "Packet Test Dataset", H5T_NATIVE_INT, (hsize_t)100, 5);
 if(ptable == H5I_INVALID_HID)
     goto out;

    /* Write one packet to the packet table */
 err = H5PTappend(ptable, (hsize_t)1, &(writeBuffer[0]) );
 if(err < 0)
     goto out;

    /* Write several packets to the packet table */
 err = H5PTappend(ptable, (hsize_t)4, &(writeBuffer[1]) );
 if(err < 0)
     goto out;

    /* Get the number of packets in the packet table.  This should be five. */
 err = H5PTget_num_packets(ptable, &count);
 if(err < 0)
     goto out;

 printf("Number of packets in packet table after five appends: %d\n", (int)count);

    /* Initialize packet table's "current record" */
 err = H5PTcreate_index(ptable);
 if(err < 0)
     goto out;

    /* Iterate through packets, read each one back */
 for(x=0; x<5; x++)
 {
    err = H5PTget_next(ptable, (hsize_t)1, &(readBuffer[x]) );
    if(err < 0)
	goto out;

    printf("Packet %d's value is %d\n", x, readBuffer[x]);
 }

    /* Close the packet table */
 err = H5PTclose(ptable);
 if(err < 0)
     goto out;

    /* Close the file */
 H5Fclose(fid);

 return 0;

 out: /* An error has occurred.  Clean up and exit. */
    H5PTclose(ptable);
    H5Fclose(fid);
    return -1;
}
Пример #4
0
/*-------------------------------------------------------------------------
 * test_get_next
 *
 * Tests the packets written by test_append can be read by
 * H5PTget_next().
 *
 *-------------------------------------------------------------------------
 */
static int test_get_next(hid_t fid)
{
    herr_t err;
    hid_t table;
    particle_t readBuf[NRECORDS];
    particle_t readBuf2[NRECORDS];
    size_t c;

    TESTING("H5PTget_next");

    /* Open the table */
    table = H5PTopen(fid, PT_NAME);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Read several particles consecutively */
    for(c=0; c < NRECORDS; c++)
    {
        err = H5PTget_next(table, 1, &readBuf[c]);
        if(err < 0)
            goto out;
    }

    /* Ensure that particles were read correctly */
    for(c=0; c<NRECORDS; c++)
    {
        if( cmp_par(c, c, testPart, readBuf) != 0)
            goto out;
    }

    H5PTcreate_index(table);

    /* Read particles two by two */
    for(c=0; c < NRECORDS / 2; c++)
    {
        err = H5PTget_next(table, 2, &readBuf2[c * 2]);
        if(err < 0)
            goto out;
    }

    /* Ensure that particles were read correctly */
    for(c=0; c<NRECORDS; c++)
    {
        if( cmp_par(c, c, testPart, readBuf2) != 0)
            goto out;
    }

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(table) < 0)
        H5PTclose(table);
    return -1;
}
Пример #5
0
/* ResetIndex
 * Sets the index to point to the first packet in the packet table
 */
void PacketTable::ResetIndex()
{
    H5PTcreate_index(table_id);
}