Пример #1
0
int main(int argc,char *argv[]) {
    struct options opts = {
        0,
        1,
        0,
        0,
        -1,
        1,
        0,
        -1,
        1,
        NULL,
    };

    getopts(argc,argv,&opts);

    H5Eset_auto2(H5E_DEFAULT,NULL,NULL);

    hid_t fid = H5Fopen(opts.filename,H5F_ACC_RDONLY,H5P_DEFAULT);
    if(fid < 0) {
        fprintf(stderr,"Failed to open %s.\n",opts.filename);
        return fid;
    }

    if(opts.info) {
        // count the number of trials in the file        
        hid_t trial;
        int num_trials = 0;
        std::stringstream trial_name;

        for(;;) {
            trial_name.str("");
            trial_name << "/Trial" << num_trials+1;

            if((trial = H5Gopen(fid,trial_name.str().c_str(),H5P_DEFAULT)) < 0)
                break;
            else {
                print_trial_info(trial,++num_trials);
                H5Gclose(trial);
            }
        }

        H5Fclose(fid);
        return 0;
    }

    std::stringstream data_name;
    data_name << "/Trial" << opts.trial << "/Synchronous Data/Channel Data";

    hid_t table = H5Dopen(fid,data_name.str().c_str(),H5P_DEFAULT);
    if(table < 0) {
        fprintf(stderr,"Requested trial #%d does not exist.\n",opts.trial);
        return table;
    }

    hsize_t ncols = H5Tget_size(H5Dget_type(table))/sizeof(double);
    H5Dclose(table);

    table = H5PTopen(fid,data_name.str().c_str());
    hsize_t nrows;
    H5PTget_num_packets(table,&nrows);

    // validate column and row ranges
    if(opts.cols_end == -1 || opts.cols_end >= ncols)
        opts.cols_end = ncols-1;
    if(opts.rows_end == -1 || opts.rows_end >= nrows)
        opts.rows_end = nrows-1;
    opts.cols_end -= (opts.cols_end-opts.cols_start)%opts.cols_step;
    opts.rows_end -= (opts.rows_end-opts.rows_start)%opts.rows_step;
    if((opts.cols_start-opts.cols_end)*opts.cols_step > 0)
        opts.cols_step *= -1;
    if((opts.rows_start-opts.rows_end)*opts.rows_step > 0)
        opts.rows_step *= -1;

    int row_idx = opts.rows_start;
    do {

        H5PTset_index(table,row_idx);

        double data[ncols];
        H5PTget_next(table,1,data);

        int col_idx = opts.cols_start;
        do {
            if(opts.binary) {
                write(1,data+col_idx,sizeof(double));
            } else {
                printf("%e ",data[col_idx]);
            }

            if(col_idx == opts.cols_end)
                break;
            col_idx += opts.cols_step;
        } while(1);

        if(!opts.binary)
            printf("\n");

        if(row_idx == opts.rows_end)
            break;
        row_idx += opts.rows_step;
    } while(1);

    H5PTclose(table);
    H5Fclose(fid);

    return 0;
}
Пример #2
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;
}
Пример #3
0
/* SetIndex
 * Sets the index to point to the packet specified by index.
 * Returns 0 on success, negative on failure (if index is out of bounds)
 */
int PacketTable::SetIndex(hsize_t index)
{
    return H5PTset_index(table_id, index);
}