Skip to content

Commit

Permalink
Added support for 16-bit int and 32-bit float HDF5 files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthc committed Jan 29, 2017
1 parent 25c0557 commit 3cccc0f
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/yapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ int YAPP_ReadHDF5Data(hid_t hDataspace,
hsize_t *hOffset,
hsize_t *hCount,
hid_t hMemDataspace,
hid_t hType,
float *pfBuf,
float fSampSize,
int iTotSampsPerBlock);
Expand Down
34 changes: 28 additions & 6 deletions src/yapp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,7 @@ int YAPP_ReadHDF5Data(hid_t hDataspace,
hsize_t *hOffset,
hsize_t *hCount,
hid_t hMemDataspace,
hid_t hType,
float *pfBuf,
float fSampSize,
int iTotSampsPerBlock)
Expand Down Expand Up @@ -2236,20 +2237,18 @@ int YAPP_ReadHDF5Data(hid_t hDataspace,
hStride,
hCount,
hBlock);
//TODO: check how this behaves with 16-bit and 32-bit data
hStatus = H5Dread(hDataset,
H5T_STD_I8LE,
hType,
hMemDataspace,
hDataspace,
H5P_DEFAULT,
pcBuf);
(void *) pcBuf);
if (hStatus < 0)
{
(void) fprintf(stderr, "ERROR: File read failed!\n");
return YAPP_RET_ERROR;
}
iReadItems = hCount[0] * hCount[1];
iReadItems = (int) ((float) iReadItems / fSampSize);
iReadItems = (int) (hCount[0] * hCount[1]);

if (YAPP_SAMPSIZE_32 == (fSampSize * YAPP_BYTE2BIT_FACTOR))
{
Expand Down Expand Up @@ -2652,6 +2651,7 @@ int YAPP_WriteMetadata(char *pcFileData, int iFormat, YUM_t stYUM)
hid_t hGroup = 0;
hid_t hDataspace = 0;
hid_t hDataset = 0;
hid_t hType = 0;
hsize_t hDims[YAPP_HDF5_DYNSPEC_RANK] = {0};

/* create file */
Expand All @@ -2672,10 +2672,32 @@ int YAPP_WriteMetadata(char *pcFileData, int iFormat, YUM_t stYUM)
hDims[1] = stYUM.iTimeSamps;
hDataspace = H5Screate_simple(YAPP_HDF5_DYNSPEC_RANK, hDims, NULL);

switch (stYUM.iNumBits)
{
case YAPP_SAMPSIZE_8:
hType = H5T_STD_I8LE;
break;

case YAPP_SAMPSIZE_16:
hType = H5T_STD_I16LE;
break;

case YAPP_SAMPSIZE_32:
hType = H5T_IEEE_F32LE;
break;

default:
/* we don't expect this */
assert ((YAPP_SAMPSIZE_8 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_16 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_32 == stYUM.iNumBits));
return YAPP_RET_ERROR;
}

/* create dataset */
hDataset = H5Dcreate(hGroup,
YAPP_HDF5_DYNSPEC_GROUP YAPP_HDF5_DYNSPEC_DATASET,
H5T_STD_I8LE,
hType,
hDataspace,
H5P_DEFAULT,
H5P_DEFAULT,
Expand Down
2 changes: 1 addition & 1 deletion src/yapp_makever.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* TODO: read the path as argument */
#define FILE_VERSRC "src/yapp_version.c"
#define VAR_VER "*g_pcVersion"
#define VER_BUILD_PREFIX "YAPP-REL-3.6.4-beta"
#define VER_BUILD_PREFIX "YAPP-REL-3.6.5-beta"
#define VER_BUILD_DELIM "-"

time_t GetLatestTimestamp(void);
Expand Down
44 changes: 42 additions & 2 deletions src/yapp_viewdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ int main(int argc, char *argv[])
hid_t hDataset = 0;
hid_t hDataspace = 0;
hid_t hMemDataspace = 0;
hid_t hType = 0;
hsize_t hMemDims[YAPP_HDF5_DYNSPEC_RANK] = {0};
hsize_t hOffset[YAPP_HDF5_DYNSPEC_RANK] = {0};
hsize_t hCount[YAPP_HDF5_DYNSPEC_RANK] = {0};
Expand Down Expand Up @@ -667,8 +668,38 @@ int main(int argc, char *argv[])

if (YAPP_FORMAT_HDF5 == iFormat)
{
switch (stYUM.iNumBits)
{
case YAPP_SAMPSIZE_8:
hType = H5T_STD_I8LE;
break;

case YAPP_SAMPSIZE_16:
hType = H5T_STD_I16LE;
break;

case YAPP_SAMPSIZE_32:
hType = H5T_IEEE_F32LE;
break;

default:
/* we don't expect this */
assert ((YAPP_SAMPSIZE_8 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_16 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_32 == stYUM.iNumBits));
return YAPP_RET_ERROR;
}

hMemDims[0] = stYUM.iNumChans;
hMemDims[1] = iTotSampsPerBlock / stYUM.iNumChans;
if (1 == iNumReads)
{
/* there is only one read */
hMemDims[1] = stYUM.iTimeSamps;
}
else
{
hMemDims[1] = iTotSampsPerBlock / stYUM.iNumChans;
}
hMemDataspace = H5Screate_simple(YAPP_HDF5_DYNSPEC_RANK,
hMemDims,
NULL);
Expand All @@ -677,7 +708,15 @@ int main(int argc, char *argv[])
hOffset[0] = 0;
hOffset[1] = 0;
hCount[0] = stYUM.iNumChans;
hCount[1] = iTotSampsPerBlock / stYUM.iNumChans;
if (1 == iNumReads)
{
/* there is only one read */
hCount[1] = stYUM.iTimeSamps;
}
else
{
hCount[1] = iTotSampsPerBlock / stYUM.iNumChans;
}
}

while (iNumReads > 0)
Expand All @@ -692,6 +731,7 @@ int main(int argc, char *argv[])
hOffset,
hCount,
hMemDataspace,
hType,
g_pfBuf,
stYUM.fSampSize,
iTotSampsPerBlock);
Expand Down
72 changes: 44 additions & 28 deletions utilities/yapp_fil2h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int main(int argc, char *argv[])
char *pcFileData = NULL;
char *pcFilename = NULL;
hid_t hFile = 0;
hid_t hType = 0;
char acFileH5[LEN_GENSTRING] = {0};
int iFormat = DEF_FORMAT;
YUM_t stYUM = {{0}};
Expand Down Expand Up @@ -156,12 +157,34 @@ int main(int argc, char *argv[])
return YAPP_RET_ERROR;
}

switch (stYUM.iNumBits)
{
case YAPP_SAMPSIZE_8:
hType = H5T_STD_I8LE;
break;

case YAPP_SAMPSIZE_16:
hType = H5T_STD_I16LE;
break;

case YAPP_SAMPSIZE_32:
hType = H5T_IEEE_F32LE;
break;

default:
/* we don't expect this */
assert ((YAPP_SAMPSIZE_8 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_16 == stYUM.iNumBits)
|| (YAPP_SAMPSIZE_32 == stYUM.iNumBits));
return YAPP_RET_ERROR;
}

iRet = YAPP_CopyData(pcFileData,
stYUM.iHeaderLen,
hFile,
stYUM.iNumChans,
stYUM.iTimeSamps,
stYUM.iNumBits);
hType);
if (iRet != YAPP_RET_SUCCESS)
{
fprintf(stderr,
Expand All @@ -181,7 +204,7 @@ int YAPP_CopyData(char *pcFileData,
hid_t hFile,
int iNumChans,
int iTimeSamps,
int iNumBits)
hid_t hType)
{
FILE *pFData = NULL;
struct stat stFileStats = {0};
Expand All @@ -191,7 +214,6 @@ int YAPP_CopyData(char *pcFileData,
hid_t hDataspace = 0;
hid_t hMemDataspace = 0;
hid_t hDataset = 0;
hid_t hType = 0;
hsize_t hMemDims[YAPP_HDF5_DYNSPEC_RANK] = {0};
hsize_t hOffset[YAPP_HDF5_DYNSPEC_RANK] = {0};
hsize_t hStride[YAPP_HDF5_DYNSPEC_RANK] = {0};
Expand Down Expand Up @@ -248,7 +270,15 @@ int YAPP_CopyData(char *pcFileData,

/* create a memory dataspace */
hMemDims[0] = iNumChans;
hMemDims[1] = SIZE_BUF / iNumChans;
if (iTimeSamps < SIZE_BUF / iNumChans)
{
/* there is only one read */
hMemDims[1] = iTimeSamps;
}
else
{
hMemDims[1] = SIZE_BUF / iNumChans;
}
hMemDataspace = H5Screate_simple(YAPP_HDF5_DYNSPEC_RANK, hMemDims, NULL);

/* define stride, count, and block */
Expand All @@ -257,31 +287,17 @@ int YAPP_CopyData(char *pcFileData,
hStride[0] = 1;
hStride[1] = 1;
hCount[0] = iNumChans;
hCount[1] = SIZE_BUF / iNumChans;
hBlock[0] = 1;
hBlock[1] = 1;

switch (iNumBits)
if (iTimeSamps < SIZE_BUF / iNumChans)
{
case YAPP_SAMPSIZE_8:
hType = H5T_STD_I8LE;
break;

case YAPP_SAMPSIZE_16:
hType = H5T_STD_I16LE;
break;

case YAPP_SAMPSIZE_32:
hType = H5T_IEEE_F32LE;
break;

default:
/* we don't expect this */
assert ((YAPP_SAMPSIZE_8 == iNumBits)
|| (YAPP_SAMPSIZE_16 == iNumBits)
|| (YAPP_SAMPSIZE_32 == iNumBits));
return YAPP_RET_ERROR;
/* there is only one read */
hCount[1] = iTimeSamps;
}
else
{
hCount[1] = SIZE_BUF / iNumChans;
}
hBlock[0] = 1;
hBlock[1] = 1;

/* copy data */
do
Expand All @@ -299,7 +315,7 @@ int YAPP_CopyData(char *pcFileData,
hMemDataspace,
hDataspace,
H5P_DEFAULT,
pcBuf);
(const void *) pcBuf);

/* set offset for next copy*/
hOffset[1] += hCount[1];
Expand Down
2 changes: 1 addition & 1 deletion utilities/yapp_fil2h5.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int YAPP_CopyData(char *pcFileData,
hid_t hFileID,
int iNumChans,
int iTimeSamps,
int iNumBits);
hid_t hType);

#endif /* __YAPP_FIL2H5_H__ */

0 comments on commit 3cccc0f

Please sign in to comment.