コード例 #1
0
ファイル: test_packet.c プロジェクト: ElaraFX/hdf5
/*-------------------------------------------------------------------------
 * test_open
 *
 * Tests opening and closing a FL packet table
 *
 *-------------------------------------------------------------------------
 */
static int test_open(hid_t fid)
{
    herr_t err;
    hid_t table;

    TESTING("H5PTopen");

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

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

    PASSED();
    return SUCCEED;

error:
      if (table > 0) H5PTclose(table);
      H5_FAILED();
      return FAIL;
}
コード例 #2
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_append
 *
 * Tests appending packets to a FL packet table
 *
 *-------------------------------------------------------------------------
 */
static int test_append(hid_t fid)
{
    herr_t err;
    hid_t table;
    hsize_t count;

    TESTING("H5PTappend");

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

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    /* There should be 0 records in the table */
    if( count != 0 )
        goto out;

    /* Append one particle */
    err = H5PTappend(table, (size_t)1, &(testPart[0]));
    if( err < 0)
        goto out;

    /* Append several particles */
    err = H5PTappend(table, (size_t)6, &(testPart[1]));
    if( err < 0)
        goto out;

    /* Append one more particle */
    err = H5PTappend(table, (size_t)1, &(testPart[7]));
    if( err < 0)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    /* There should be 8 records in the table now */
    if( count != 8 )
        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;
}
コード例 #3
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_opaque
 *
 * Tests that the packet table works with an opaque datatype.
 *
 *-------------------------------------------------------------------------
 */
static int    test_opaque(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;
    size_t c;
    particle_t readBuf[NRECORDS];

    TESTING("opaque data");

    /* Create an opaque datatype for the particle struct */
    if ((part_t = H5Tcreate (H5T_OPAQUE, sizeof(particle_t) )) < 0 )
        return -1;

    HDassert(part_t != -1);

    /* Tag the opaque datatype */
    if ( H5Tset_tag(part_t,  "Opaque Particle"  ) < 0)
        return -1;

    /* Create a new table */
    table = H5PTcreate_fl(fid, "Packet Test Dataset3", part_t, (hsize_t)100, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Append several particles, starting at particle 1 */
    err = H5PTappend(table, (size_t)(NRECORDS - 1), &(testPart[1]));
    if( err < 0)
        goto out;

    /* Read the particles back */
    err = H5PTread_packets(table, (hsize_t)0, 7, &(readBuf[0]));
    if( err < 0)
        goto out;

    /* Ensure that particles were read correctly */
    for(c=0; c<NRECORDS - 1; c++)
    {
        if( cmp_par(c+1, c, testPart, readBuf) != 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;
}
コード例 #4
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_read
 *
 * Tests that the packets appended by test_append can be read back.
 *
 *-------------------------------------------------------------------------
 */
static int test_read(hid_t fid)
{
    herr_t err;
    hid_t table;
    particle_t readBuf[NRECORDS];
    size_t c;

    TESTING("H5PTread_packets");

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

    /* Read several particles */
    err = H5PTread_packets(table, (hsize_t)0, 3, &(readBuf[0]));
    if( err < 0)
        goto out;

    /* Read one particle */
    err = H5PTread_packets(table, (hsize_t)3, 1, &(readBuf[3]));
    if( err < 0)
        goto out;

    /* Read several particles */
    err = H5PTread_packets(table, (hsize_t)4, (NRECORDS - 4 ), &(readBuf[4]));
    if( err < 0)
        goto out;

    /* Ensure that particles were read correctly */
    for(c=0; c<NRECORDS; c++)
    {
        if( cmp_par(c%8, c, testPart, readBuf) != 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
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_open
 *
 * Tests opening and closing a FL packet table
 *
 *-------------------------------------------------------------------------
 */
static int test_open(hid_t fid)
{
    herr_t err;
    hid_t table;

    TESTING("H5PTopen");

    /* Open the table */
    table = H5PTopen(fid, PT_NAME);
    if( H5PTis_valid(table) < 0)
        goto out;
#ifdef VLPT_REMOVED
    if( H5PTis_varlen(table) != 0)
        goto out;
#endif /* VLPT_REMOVED */

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

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}
コード例 #6
0
ファイル: H5PT.c プロジェクト: BlackGinger/ExocortexCrate
/*-------------------------------------------------------------------------
 * Function: H5PTcreate_vl
 *
 * Purpose: Creates a dataset containing a table of variable length records
 *          and returns the Identifier of the table.
 *
 * Return: Success: table ID, Failure: Negative
 *
 * Programmer: Nat Furrer, [email protected]
 *             James Laird, [email protected]
 *
 * Date: April 12, 2004
 *
 * Comments: This function does not handle compression or fill data
 *           currently.  Fill data is not necessary because the
 *           table is initially of size 0.
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
hid_t H5PTcreate_vl ( hid_t loc_id,
                                 const char*dset_name,
                                 hsize_t chunk_size)
{
  hid_t ret_value=H5I_BADID;
  hid_t vltype;

  /* Create a variable length type that uses single bytes as its base type */
  vltype = H5Tvlen_create(H5T_NATIVE_UCHAR);
  if(vltype < 0)
    goto out;

  if((ret_value=H5PTcreate_fl(loc_id, dset_name, vltype, chunk_size, 0)) < 0)
    goto out;

  /* close the vltype */
  if(H5Tclose(vltype) < 0)
    goto out;

  return ret_value;

out:
  if(ret_value != H5I_BADID)
    H5PTclose(ret_value);
  return H5I_BADID;
}
コード例 #7
0
ファイル: test_packet.c プロジェクト: ElaraFX/hdf5
static int test_create_close(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;

    TESTING("H5PTcreate_fl and H5PTclose");

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create the table */
    table = H5PTcreate_fl(fid, PT_NAME, part_t, (hsize_t)100, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
	goto error;
    if( H5PTis_varlen(table) != 0)
	goto error;

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

    PASSED();
    return SUCCEED;

error:
      H5_FAILED();
      return FAIL;
}
コード例 #8
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
static int test_create_close(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;

    TESTING("H5PTcreate_fl and H5PTclose");

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create the table */
    table = H5PTcreate_fl(fid, PT_NAME, part_t, (hsize_t)100, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
        goto out;
#ifdef VLPT_REMOVED
    if( H5PTis_varlen(table) != 0)
        goto out;
#endif /* VLPT_REMOVED */

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

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}
コード例 #9
0
ファイル: access_tracing.cpp プロジェクト: Luffy0011/zsim
AccessTraceReader::AccessTraceReader(std::string _fname) : fname(_fname.c_str()) {
    hid_t fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
    if (fid == H5I_INVALID_HID) panic("Could not open HDF5 file %s", fname.c_str());

    // Check that the trace finished
    hid_t fAttr = H5Aopen(fid, "finished", H5P_DEFAULT);
    uint32_t finished;
    H5Aread(fAttr, H5T_NATIVE_UINT, &finished);
    H5Aclose(fAttr);

    if (!finished) panic("Trace file %s unfinished (halted simulation?)", fname.c_str());

    // Populate numRecords & numChildren
    hsize_t nPackets;
    hid_t table = H5PTopen(fid, "accs");
    if (table == H5I_INVALID_HID) panic("Could not open HDF5 packet table");
    H5PTget_num_packets(table, &nPackets);
    numRecords = nPackets;

    hid_t ncAttr = H5Aopen(fid, "numChildren", H5P_DEFAULT);
    H5Aread(ncAttr, H5T_NATIVE_UINT, &numChildren);
    H5Aclose(ncAttr);

    curFrameRecord = 0;
    cur = 0;
    max = MIN(PT_CHUNKSIZE, numRecords);
    buf = max? gm_calloc<PackedAccessRecord>(max) : nullptr;

    if (max) {
        H5PTread_packets(table, 0, max, buf);
    }

    H5PTclose(table);
    H5Fclose(fid);
}
コード例 #10
0
ファイル: sdmf_pt_db.c プロジェクト: rmvanhees/nadc_tools
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_get_pt_jdayIndex
.PURPOSE     obtain indices to last-limb/Sun records for julianDay interval
.INPUT/OUTPUT
  call as    SDMF_get_pt_jdayIndex( locID, jdayRange, &numIndx, metaIndx );
     input:
           hid_t  locID        :  HDF5 identifier of group
	   double jdayRange[2] :  range in julianDay (min,max)
 in/output:
	   size_t *numIndx     :  [input]  dimension of metaIndx
                                  [output] number of indices found
    output:
	   size_t *metaIndx    :  array with requested indices

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_get_pt_jdayIndex( hid_t locID, const double jdayRange[],
			    size_t *numIndx, size_t *metaIndx )
{
     const size_t dimArray = *numIndx;

     register size_t nr;

     hid_t    ptable;
     hsize_t  nrecords;

     double   *jdayList;
/*
 * initialize return values
 */
     *numIndx = 0;
     *metaIndx = 0;
/*
 * check if jdayList exists
 */
     if ( (ptable = H5PTopen( locID, "jdayList" )) == H5I_BADID )
          NADC_RETURN_ERROR( NADC_ERR_HDF_DATA, "jdayList" );

     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( nrecords == 0 ) {
          (void) H5PTclose( ptable );
          return;
     }
/*
 * read list of orbits stored sofar
 */
     jdayList = (double *) malloc( (size_t) nrecords * sizeof(double) );
     if ( jdayList == NULL )
          NADC_GOTO_ERROR( NADC_ERR_ALLOC, "jdayList" );
     (void) H5PTread_packets( ptable, 0, (size_t) nrecords, jdayList );
/*
 * find all matches
 */
     for ( nr = 0; nr < (size_t) nrecords; nr++ ) {
          if ( jdayList[nr] >= jdayRange[0] && jdayList[nr] <= jdayRange[1] ) {
	       metaIndx[*numIndx] = nr;
	       if ( ++(*numIndx) == dimArray ) break;
	  }
     }
     free( jdayList );
done:
     (void) H5PTclose( ptable );
}
コード例 #11
0
ファイル: sdmf_pt_db.c プロジェクト: rmvanhees/nadc_tools
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_get_pt_orbitIndex
.PURPOSE     obtain indices to last-limb/Sun records for given orbit number
.INPUT/OUTPUT
  call as    SDMF_get_pt_orbitIndex( locID, absOrbit, &numIndx, metaIndx );
     input:
           hid_t  locID        :  HDF5 identifier of group
	   int    absOrbit     :  orbit number
 in/output:
	   size_t *numIndx     :  [input]  dimension of metaIndx
                                  [output] number of indices found
    output:
	   size_t *metaIndx    :  array with requested indices

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_get_pt_orbitIndex( hid_t locID, int absOrbit, 
			     size_t *numIndx, size_t *metaIndx )
{
     const size_t dimArray = *numIndx;

     register size_t nr;

     hid_t    ptable;
     hsize_t  nrecords;

     int      *orbitList;
/*
 * initialize return values
 */
     *numIndx = 0;
     *metaIndx = 0;
/*
 * check if orbitList exists
 */
     if ( (ptable = H5PTopen( locID, "orbitList" )) == H5I_BADID )
          NADC_RETURN_ERROR( NADC_ERR_HDF_DATA, "orbitList" );

     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( nrecords == 0 ) {
          (void) H5PTclose( ptable );
          return;
     }
/*
 * read list of orbits stored sofar
 */
     orbitList = (int *) malloc( (size_t) nrecords * sizeof(int) );
     if ( orbitList == NULL )
          NADC_GOTO_ERROR( NADC_ERR_ALLOC, "orbitList" );
     (void) H5PTread_packets( ptable, 0, (size_t) nrecords, orbitList );
/*
 * find all matches
 */
     for ( nr = 0; nr < (size_t) nrecords; nr++ ) {
          if ( orbitList[nr] == absOrbit ) {
	       metaIndx[*numIndx] = nr;
	       if ( ++(*numIndx) == dimArray ) break;
	  }
     }
     free( orbitList );
done:
     (void) H5PTclose( ptable );
}
コード例 #12
0
/* "Open" Constructor
 * Opens an existing variable-length packet table.
 * Fails if the packet table specified is fixed-length.
 */
VL_PacketTable::VL_PacketTable(hid_t fileID, char* name) : PacketTable(fileID, name)
{
    if( H5PTis_varlen(table_id) != 1 )    // If this is not a variable-length table
    {
        H5PTclose(table_id);
        table_id = -1;
    }
}
コード例 #13
0
/* "Open" Constructor
 * Opens an existing fixed-length packet table.
 * Fails if the packet table specified is variable-length.
 */
FL_PacketTable::FL_PacketTable(hid_t fileID, const char* name) : PacketTable(fileID, name)
{
#ifdef VLPT_REMOVED
    if( H5PTis_varlen(table_id) != 0 )    // If this is not a fixed-length table
    {
        H5PTclose(table_id);
        table_id = -1;
    }
#endif /* VLPT_REMOVED */
}
コード例 #14
0
ファイル: sdmf_pt_db.c プロジェクト: rmvanhees/nadc_tools
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_rd_pt_metaTable
.PURPOSE     read metaTable records from SDMF last-limb/Sun databases
.INPUT/OUTPUT
  call as    SDMF_rd_pt_metaTable( locID, &numIndx, metaIndx, &mtbl );
     input:
           hid_t  locID        :  HDF5 identifier of group
	   size_t *metaIndx    :  array with requested indices
 in/output:
	   size_t *numIndx     :  [input]  dimension of metaIndx (or zero)
                                  [output] number of records read
    output:
           struct mtbl_pt_rec **mtbl : last-limb/Sun meta-table records

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_rd_pt_metaTable( hid_t locID, size_t *numIndx, size_t *metaIndx,
			     struct mtbl_pt_rec **mtbl_out )
{
     register size_t nr;

     hid_t   ptable;
     hsize_t nrecords;

     struct mtbl_pt_rec *mtbl;
/*
 * initialize return values 
 */
     if ( ! Use_Extern_Alloc ) *mtbl_out = NULL;
/*
 * does the table already exists?
 */
     if ( (ptable = H5PTopen( locID, "metaTable" )) == H5I_BADID ) return;
/*
 * obtain table info
 */
     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( *numIndx == 0 ) {
	  *numIndx = (size_t) nrecords;
	  for ( nr = 0; nr < nrecords; nr++ ) metaIndx[nr] = nr;
     }
     if ( nrecords == 0 ) {
	  (void) H5PTclose( ptable );
          return;
     }
/*
 * allocate memory to store the metaTable records
 */
     if ( ! Use_Extern_Alloc ) {
	  mtbl = (struct mtbl_pt_rec *) 
	       malloc( (size_t) nrecords * sizeof(struct mtbl_pt_rec));
	  if ( mtbl == NULL )
	       NADC_RETURN_ERROR( NADC_ERR_ALLOC, "mtbl" );
     } else if ( (mtbl = mtbl_out[0]) == NULL )
	  NADC_RETURN_ERROR( NADC_ERR_ALLOC, "mtbl_out[0]" );
/*
 * read table records
 */
     if ( (*numIndx) == (size_t) nrecords ) {
	  (void) H5PTread_packets( ptable, 0, (size_t) nrecords, mtbl );
     } else {
	  nr = 0;
	  do {
	       (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 1, 
					mtbl+nr );
	  } while ( ++nr < (*numIndx) );
     }
     *mtbl_out = mtbl;
}
コード例 #15
0
ファイル: DRHDF5.cpp プロジェクト: carylogan/Trick
/**
@details
-# For each parameter being recorded
   -# Close the HDF5 packet table
-# Close the HDF5 root
-# Close the HDF5 file
*/
int Trick::DRHDF5::format_specific_shutdown() {

#ifdef HDF5
    unsigned int ii ;

    if ( inited ) {
        for (ii = 0; ii < parameters.size(); ii++) {
            HDF5_INFO * hi = parameters[ii] ;
            H5PTclose( hi->dataset );
        }
        H5Gclose(root_group);
        H5Fclose(file);

    }
#endif
    return(0);
}
コード例 #16
0
ファイル: access_tracing.cpp プロジェクト: Luffy0011/zsim
void AccessTraceReader::nextChunk() {
    assert(cur == max);
    curFrameRecord += max;

    if (curFrameRecord < numRecords) {
        cur = 0;
        max = MIN(PT_CHUNKSIZE, numRecords - curFrameRecord);
        hid_t fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
        if (fid == H5I_INVALID_HID) panic("Could not open HDF5 file %s", fname.c_str());
        hid_t table = H5PTopen(fid, "accs");
        if (table == H5I_INVALID_HID) panic("Could not open HDF5 packet table");
        H5PTread_packets(table, curFrameRecord, max, buf);
        H5PTclose(table);
        H5Fclose(fid);
    } else {
        assert_msg(curFrameRecord == numRecords, "%ld %ld", curFrameRecord, numRecords);  // aaand we're done
    }
}
コード例 #17
0
extern int acct_gather_profile_p_node_step_end(void)
{
	int rc = SLURM_SUCCESS;
	size_t i;

	xassert(_run_in_daemon());

	xassert(g_profile_running != ACCT_GATHER_PROFILE_NOT_SET);

	// No check for --profile as we always want to close the HDF5 file
	// if it has been opened.


	if (g_profile_running <= ACCT_GATHER_PROFILE_NONE)
		return rc;

	if (debug_flags & DEBUG_FLAG_PROFILE)
		info("PROFILE: node_step_end (shutdown)");

	/* close tables */
	for (i = 0; i < tables_cur_len; ++i) {
		H5PTclose(tables[i].table_id);
	}
	/* close groups */
	for (i = 0; i < groups_len; ++i) {
		H5Gclose(groups[i]);
	}

	if (gid_totals > 0)
		H5Gclose(gid_totals);
	if (gid_samples > 0)
		H5Gclose(gid_samples);
	if (gid_tasks > 0)
		H5Gclose(gid_tasks);
	if (gid_node > 0)
		H5Gclose(gid_node);
	if (file_id > 0)
		H5Fclose(file_id);
	profile_fini();
	file_id = -1;

	return rc;
}
コード例 #18
0
ファイル: access_tracing.cpp プロジェクト: Luffy0011/zsim
void AccessTraceWriter::dump(bool cont) {
    hid_t fid = H5Fopen(fname.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
    if (fid == H5I_INVALID_HID) panic("Could not open HDF5 file %s", fname.c_str());
    hid_t table = H5PTopen(fid, "accs");
    if (table == H5I_INVALID_HID) panic("Could not open HDF5 packet table");
    herr_t err = H5PTappend(table, cur, buf);
    assert(err >= 0);

    if (!cont) {
        hid_t fAttr = H5Aopen(fid, "finished", H5P_DEFAULT);
        uint32_t finished = 1;
        H5Awrite(fAttr, H5T_NATIVE_UINT, &finished);
        H5Aclose(fAttr);

        gm_free(buf);
        buf = nullptr;
        max = 0;
    }

    cur = 0;
    H5PTclose(table);
    H5Fclose(fid);
}
コード例 #19
0
ファイル: sdmf_pt_db.c プロジェクト: rmvanhees/nadc_tools
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_rd_pt_pointing
.PURPOSE     read pointing infor for cluster records from SDMF database
.INPUT/OUTPUT
  call as    SDMF_rd_pt_pointing( locID, &numIndx, metaIndx, pointing );
     input:
           hid_t  locID          :  HDF5 identifier of group
	   size_t *metaIndx      :  array with requested indices
 in/output:
	   size_t *numIndx       :  [input]  dimension of metaIndx (or zero)
                                    [output] number of records read
    output:
           struct geo_pt_rec *pointing : pointing of cluster records

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_rd_pt_pointing( hid_t locID, size_t *numIndx, size_t *metaIndx,
			    struct geo_pt_rec *pointing )
{
     register size_t  nr;

     unsigned short num_obs;

     hid_t   ptable;
     hsize_t nrecords;
/*
 * does the dataset already exists?
 */
     if ( (ptable = H5PTopen( locID, "pointing" )) == H5I_BADID ) return;
/*
 * obtain table info
 */
     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( *numIndx == 0 ) {
	  *numIndx = (size_t) nrecords;
	  for ( nr = 0; nr < nrecords; nr++ ) metaIndx[nr] = nr;
     }
     if ( nrecords == 0 ) {
	  (void) H5PTclose( ptable );
          return;
     }
     (void) H5LTget_attribute_ushort( locID, "pointing", "numObs", &num_obs );
/*
 * read pointing records
 */
     nr = 0;
     do {
	  if ( nr > 0 ) pointing += num_obs;
	  (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 
				   1, pointing );
     } while ( ++nr < (*numIndx) );
}
コード例 #20
0
int main(void)
{
#ifdef VLPT_REMOVED
 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 */
 hvl_t writeBuffer[5];
 hvl_t readBuffer[5];

    /* This example has two different sizes of "record": longs and shorts */
 long longBuffer[5];
 short shortBuffer[5];

   /* Initialize buffers */
 for(x=0; x<5; x++)
 {
     longBuffer[x] = -x;
     shortBuffer[x] = x;
 }

    /* Fill the write buffer with a mix of longs and shorts */
    /* We need to supply the length of each record and a pointer to */
    /* the beginning of each record. */
 writeBuffer[0].len = sizeof(long);
 writeBuffer[0].p = &(longBuffer[0]);
 writeBuffer[1].len = sizeof(short);
 writeBuffer[1].p = &(shortBuffer[1]);
 writeBuffer[2].len = sizeof(long);
 writeBuffer[2].p = &(longBuffer[2]);
 writeBuffer[3].len = sizeof(long);
 writeBuffer[3].p = &(longBuffer[3]);
 writeBuffer[4].len = sizeof(short);
 writeBuffer[4].p = &(shortBuffer[4]);

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

    /* Create a variable-length packet table within the file */
 ptable = H5PTcreate_vl(fid, "Packet Test Dataset", (hsize_t)1);
 if(ptable == H5I_INVALID_HID)
     goto out;

    /* Write the entire buffer to the packet table */
 err = H5PTappend(ptable, (hsize_t)5, writeBuffer );
 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", count);

    /* Read all five packets back */
 err = H5PTread_packets(ptable, (hsize_t)0, (hsize_t)5, readBuffer );
 if(err < 0)
    goto out;

 for(x=0; x<5; x++)
 {
    printf("Packet %d's length is %d\n", x, readBuffer[x].len);
    if(readBuffer[x].len == sizeof(long))
        printf("Packet %d's value is %d\n", x, *( (long *) readBuffer[x].p) );
    else
        printf("Packet %d's value is %d\n", x, *( (short *) readBuffer[x].p) );
 }

    /* Before we close the packet table, we must free the memory that */
    /* the pointers in readBuffer point to. */
 err = H5PTfree_vlen_readbuff(ptable, (hsize_t)5, readBuffer);
 if(err < 0)
     goto out;

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

    /* Close the file */
 H5Fclose(fid);
#endif /* VLPT_REMOVED */

 return 0;

#ifdef VLPT_REMOVED
 out: /* An error has occurred.  Clean up and exit. */
    fprintf(stderr, "An error has occurred!\n");
    H5PTclose(ptable);
    H5Fclose(fid);
    return -1;
#endif /* VLPT_REMOVED */
}
コード例 #21
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * 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;
}
コード例 #22
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;
}
コード例 #23
0
ファイル: rtxi_hdf_reader.cpp プロジェクト: misterboyle/rtxi
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;
}
コード例 #24
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * 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;
}
コード例 #25
0
/* Destructor
 * Cleans up the packet table
 */
PacketTable::~PacketTable()
{
    H5PTclose( table_id);
}
コード例 #26
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * 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;
}
コード例 #27
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_compress
 *
 * Ensures that a FL packet table can be compressed.
 * This test creates a file named TEST_COMPRESS_FILE
 *
 *-------------------------------------------------------------------------
 */
static int
test_compress(void)
{
    hid_t fid1 = -1;
    herr_t err;
    hid_t table = -1;
    hid_t part_t = -1;
    hid_t dset_id = -1;
    hid_t plist_id = -1;
    size_t c;
    size_t num_elems = 1;
    unsigned filter_vals[1];
    particle_t readPart[1];
    hsize_t count;

    TESTING("packet table compression");

    /* Create a file. */
    if((fid1 = H5Fcreate(TEST_COMPRESS_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create a new table with compression level 8 */
    table = H5PTcreate_fl(fid1, "Compressed Test Dataset", part_t, (hsize_t)80, 8);
    if( H5PTis_valid(table) < 0) TEST_ERROR;

    /* We can now use this table exactly the same way we use a normal uncompressed
     * packet table, and it should pass the same tests. */
    /* Add many particles */
    for(c = 0; c < BIG_TABLE_SIZE ; c+=8)
    {
        /* Append eight particles at once*/
        err = H5PTappend(table, (size_t)8, &(testPart[0]));
        if( err < 0) TEST_ERROR;
    }

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0) TEST_ERROR;
    if( count != BIG_TABLE_SIZE ) TEST_ERROR;

    /* Read particles to ensure that all of them were written correctly  */
    HDmemset(readPart, 0, sizeof(readPart));
    for(c = 0; c < BIG_TABLE_SIZE; c++)
    {
        err = H5PTget_next(table, 1, readPart);
        if(err < 0) TEST_ERROR;

        /* Ensure that particles were read correctly */
        if( cmp_par(c % 8, 0, testPart, readPart) != 0) TEST_ERROR;
    }

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

    /* Open the packet table as a regular dataset and make sure that the
     * compression filter is set.
     */
    dset_id = H5Dopen2(fid1, "Compressed Test Dataset", H5P_DEFAULT);
    if( dset_id < 0) TEST_ERROR;

    plist_id = H5Dget_create_plist(dset_id);
    if( plist_id < 0) TEST_ERROR;

    err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems,
                               filter_vals, 0, NULL, NULL);
    if( err < 0) TEST_ERROR;

    /* The compression level should be 8, the value we passed in */
    if(filter_vals[0] != 8) TEST_ERROR;

    /* Clean up */
    err = H5Pclose(plist_id);
    if( err < 0) TEST_ERROR;
    err = H5Dclose(dset_id);
    if( err < 0) TEST_ERROR;

    /* Create a new table without compression. */
    table = H5PTcreate_fl(fid1, "Uncompressed Dataset", part_t, (hsize_t)80, -1);
    if(table < 0) TEST_ERROR;

    /* Close the packet table */
    err = H5PTclose(table);
    if( err < 0) TEST_ERROR;

    /* Open the packet table as a regular dataset and make sure that the
     * compression filter is not set.
     */
    dset_id = H5Dopen2(fid1, "Uncompressed Dataset", H5P_DEFAULT);
    if( dset_id < 0) TEST_ERROR;

    plist_id = H5Dget_create_plist(dset_id);
    if( plist_id < 0) TEST_ERROR;

    H5E_BEGIN_TRY {
        err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems,
        filter_vals, 0, NULL, NULL);
        if( err >= 0) TEST_ERROR;
    } H5E_END_TRY

    /* Clean up */
    err = H5Pclose(plist_id);
    if( err < 0) TEST_ERROR;
    err = H5Dclose(dset_id);
    if( err < 0) TEST_ERROR;

    /* Close the datatype and the file */
    err = H5Tclose(part_t);
    if( err < 0) TEST_ERROR;
    err = H5Fclose(fid1);
    if( err < 0) TEST_ERROR;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(plist_id);
        H5Dclose(dset_id);
        H5Tclose(part_t);
        H5PTclose(table);
        H5Fclose(fid1);
    } H5E_END_TRY
    H5_FAILED();
    return -1;
}
コード例 #28
0
ファイル: sdmf_pt_db.c プロジェクト: rmvanhees/nadc_tools
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_rd_pt_cluster
.PURPOSE     read cluster records from SDMF last-limb/Sun database
.INPUT/OUTPUT
  call as    SDMF_rd_pt_cluster( locID, clus_id, &numIndx, metaIndx, 
                                   pixel_val );
     input:
           hid_t  locID          :  HDF5 identifier of group
	   unsigned char clus_id :  Cluster ID, range 1 - 40
	   size_t *metaIndx      :  array with requested indices
 in/output:
	   size_t *numIndx       :  [input]  dimension of metaIndx (or zero)
                                    [output] number of records read
    output:
           float *pixel_val      : pixel values of SDMF last-limb/Sun database

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_rd_pt_cluster( hid_t locID, unsigned char clus_id, 
			   size_t *numIndx, size_t *metaIndx,
			   float *pixel_val )
{
     register size_t  nr, np;

     char           clusName[11];
     unsigned char  coaddf;
     unsigned short num_pixels, num_obs, *usbuff;
     unsigned int   *ubuff;

     hid_t   ptable;
     hsize_t nrecords;
     size_t  total_values;
/*
 * does the dataset already exists?
 */
     (void) snprintf( clusName, 11, "cluster_%02hhu", clus_id );
     if ( (ptable = H5PTopen( locID, clusName )) == H5I_BADID ) return;
/*
 * obtain table info
 */
     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( *numIndx == 0 ) {
	  *numIndx = (size_t) nrecords;
	  for ( nr = 0; nr < nrecords; nr++ ) metaIndx[nr] = nr;
     }
     if ( nrecords == 0 ) {
	  (void) H5PTclose( ptable );
          return;
     }
     (void) H5LTget_attribute_uchar( locID, clusName, "coaddf", &coaddf );
     (void) H5LTget_attribute_ushort( locID, clusName, "numObs", &num_obs );
     (void) H5LTget_attribute_ushort( locID, clusName,"numPixels",&num_pixels );
     total_values = (size_t) num_obs * num_pixels;
/*
 * allocate temporary buffer to store cluster data
 */
     if ( coaddf == (unsigned char) 1 ) {
	  usbuff = (unsigned short *) malloc( total_values * sizeof(short) );
	  ubuff = NULL;
     } else {
	  usbuff = NULL;
	  ubuff = (unsigned int *) malloc( total_values * sizeof(int) );
     }
/*
 * read cluster records
 */
     nr = 0;
     do {
	  if ( coaddf == (unsigned char) 1 ) {
	       (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 
					1, usbuff );
	       for ( np = 0; np < total_values; np++ )
		    *pixel_val++ = (float) usbuff[np];
	  } else {
	       (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 
					1, ubuff );
	       for ( np = 0; np < total_values; np++ ) {
		    *pixel_val++ = (float) ubuff[np];
	       }
	  }
     } while ( ++nr < (*numIndx) );

     if ( usbuff != NULL ) free( usbuff );
     if ( ubuff != NULL  ) free( ubuff );
}
コード例 #29
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_varlen
 *
 * Tests creation, opening, closing, writing, reading, etc. on a
 * variable-length packet table.
 *
 *-------------------------------------------------------------------------
 */
static int    test_varlen(hid_t fid)
{
    herr_t err;
    hid_t table=H5I_BADID;
    hsize_t count;

    /* Buffers to hold data */
    hvl_t writeBuffer[NRECORDS];
    hvl_t readBuffer[NRECORDS];

    /* This example has three different sizes of "record": longs, shorts, and particles */
    long longBuffer[NRECORDS];
    short shortBuffer[NRECORDS];
    int x;

    TESTING("variable-length packet tables");

    /* Initialize buffers */
    for(x=0; x<NRECORDS; x++)
    {
        longBuffer[x] = -x;
        shortBuffer[x] = x;
    }

    /* Fill the write buffer with a mix of variable types */
    for(x=0; x<8; x+=4)
    {
        writeBuffer[x].len = sizeof(long);
        writeBuffer[x].p = &(longBuffer[x]);
        writeBuffer[x+1].len = sizeof(short);
        writeBuffer[x+1].p = &(shortBuffer[x+1]);
        writeBuffer[x+2].len = sizeof(long);
        writeBuffer[x+2].p = &(longBuffer[x+2]);
        writeBuffer[x+3].len = sizeof(particle_t);
        writeBuffer[x+3].p = &(testPart[x+3]);
    }

    /* Create the table */
    table = H5PTcreate_vl(fid, VL_TABLE_NAME, (hsize_t)1001);
    if( H5PTis_valid(table) < 0)
        goto out;
    if( H5PTis_varlen(table) != 1)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != 0 )
        goto out;

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

    /* Re-open the table */
    table = H5PTopen(fid, VL_TABLE_NAME);
    if( H5PTis_valid(table) < 0)
        goto out;
    if( H5PTis_varlen(table) != 1)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != 0 )
        goto out;

    /* Add several variable-length packets */
    err = H5PTappend(table, (size_t)8, writeBuffer );
    if(err < 0)
        goto out;

    /* Read them back */
    err = H5PTread_packets(table, (hsize_t)0, 4, &(readBuffer[0]));
    if( err < 0)
        goto out;
    err = H5PTread_packets(table, (hsize_t)4, 1, &(readBuffer[4]));
    if( err < 0)
        goto out;
    err = H5PTread_packets(table, (hsize_t)5, (NRECORDS - 5 ), &(readBuffer[5]));
    if( err < 0)
        goto out;

    /* Ensure that packets were read correctly */
    for(x=0; x<NRECORDS; x++)
    {
        if( readBuffer[x].len != writeBuffer[x%4].len)
            goto out;
        switch(x%4)
        {
        case 0:
        case 2:
            if( *((long*)(readBuffer[x].p)) != *((long*)(writeBuffer[x].p)))
                goto out;
            break;
        case 1:
            if( *((short*)(readBuffer[x].p)) != *((short*)(writeBuffer[x].p)))
                goto out;
            break;
        case 3:
            if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0)
                goto out;
            break;
        default:
            goto out;
        }
    }

    /* Free memory used by read buffer */
    if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0)
        goto out;

    /* Read packets back using get_next */
    for(x=0; x < NRECORDS; x++)
    {
        err = H5PTget_next(table, 1, &readBuffer[x]);
        if(err < 0)
            goto out;
    }

    /* Ensure that packets were read correctly */
    for(x=0; x<NRECORDS; x++)
    {
        if( readBuffer[x].len != writeBuffer[x%4].len)
            goto out;
        switch(x%4)
        {
        case 0:
        case 2:
            if( *((long*)(readBuffer[x].p)) != *((long*)(writeBuffer[x].p)))
                goto out;
            break;
        case 1:
            if( *((short*)(readBuffer[x].p)) != *((short*)(writeBuffer[x].p)))
                goto out;
            break;
        case 3:
            if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0)
                goto out;
            break;
        default:
            goto out;
        }
    }

    /* Free memory used by read buffer */
    if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0)
        goto out;

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

    PASSED();
    return 0;

out:
    H5_FAILED();
    H5E_BEGIN_TRY
    H5PTclose(table);
    H5E_END_TRY
    return -1;
}
コード例 #30
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
/*-------------------------------------------------------------------------
 * test_big_table
 *
 * Ensures that a FL packet table will not break when many (BIG_TABLE_SIZE)
 * packets are used.
 *
 *-------------------------------------------------------------------------
 */
static int    test_big_table(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;
    size_t c;
    particle_t readPart;
    hsize_t count;

    TESTING("large packet table");

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create a new table */
    table = H5PTcreate_fl(fid, "Packet Test Dataset2", part_t, (hsize_t)33, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Add many particles */
    for(c = 0; c < BIG_TABLE_SIZE ; c+=8)
    {
        /* Append eight particles at once*/
        err = H5PTappend(table, (size_t)8, &(testPart[0]));
        if( err < 0)
            goto out;
    }

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != BIG_TABLE_SIZE )
        goto out;

    /* Read particles to ensure that all of them were written correctly  */
    /* Also, ensure that H5PTcreate_fl set the current packet to */
    /* the first packet in the table                                     */
    for(c = 0; c < BIG_TABLE_SIZE; c++)
    {
        err = H5PTget_next(table, 1, &readPart);
        if(err < 0)
            goto out;

        /* Ensure that particles were read correctly */
        if( cmp_par(c % 8, 0, testPart, &readPart) != 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;
}