Skip to content

Commit

Permalink
Conditional compilation for HDF5 support, updated README with HDF5 info.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthc committed Mar 24, 2017
1 parent 581c572 commit 940ca9d
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 19 deletions.
40 changes: 32 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,32 @@ CFLAGS_INC_CFITSIO =# define if needed (as -I[...])
endif

CFLAGS = -std=gnu99 -pedantic -Wall $(CFLAGS_INC_PGPLOT) $(CFLAGS_INC_FFTW3) \
$(CFLAGS_INC_CFITSIO) $(CFLAGS_INC_HDF5)
$(CFLAGS_INC_CFITSIO)
ifeq ($(HDF5), yes)
CFLAGS += $(CFLAGS_INC_HDF5)
endif
CFLAGS_C_DEBUG = $(CFLAGS) -g -c
CFLAGS_C_RELEASE = $(CFLAGS) -O3 -c
ifeq ($(OPT_DEBUG), yes)
ifeq ($(DEBUG), yes)
CFLAGS_C = $(CFLAGS_C_DEBUG)
else
CFLAGS_C = $(CFLAGS_C_RELEASE)
endif
CFLAGS_L_DEBUG = $(CFLAGS) -g
CFLAGS_L_RELEASE = $(CFLAGS) -O3
ifeq ($(OPT_DEBUG), yes)
ifeq ($(DEBUG), yes)
CFLAGS_L = $(CFLAGS_L_DEBUG)
else
CFLAGS_L = $(CFLAGS_L_RELEASE)
endif

# enable/disable HDF5 compilation
ifeq ($(HDF5), yes)
DHDF5 = -DHDF5
endif

# enable/disable the debug flag
ifeq ($(OPT_DEBUG), yes)
ifeq ($(DEBUG), yes)
DDEBUG = -DDEBUG
endif

Expand All @@ -51,15 +59,19 @@ else
LFLAGS_PGPLOT_DIR =# define if not in $PATH (as -L[...])
endif
LFLAGS_FFTW3_DIR =# define if not in $PATH (as -L[...])
ifeq ($(HDF5), yes)
LFLAGS_HDF5_DIR =-L/usr/local/hdf5/lib
endif
ifeq ($(shell uname), Darwin)
LFLAGS_CFITSIO_DIR =-L/opt/local/lib# define if not in $PATH (as -L[...])
else
LFLAGS_CFITSIO_DIR =# define if not in $PATH (as -L[...])
endif
LFLAGS_FFTW3 = $(LFLAGS_FFTW3_DIR) -lfftw3f
LFLAGS_CFITSIO = $(LFLAGS_CFITSIO_DIR) -lcfitsio
ifeq ($(HDF5), yes)
LFLAGS_HDF5 = $(LFLAGS_HDF5_DIR) -lhdf5
endif
# in some cases, linking needs to be done with the X11 library, in which case
# append '-lX11' (and possibly the path to the library) to the line below.
# libgfortran may also be needed in some case, in which case append
Expand Down Expand Up @@ -134,10 +146,10 @@ yapp_erflookup.o: $(SRCDIR)/yapp_erflookup.c $(SRCDIR)/yapp.h
$(CC) $(CFLAGS_C) $< -o $(IDIR)/$@

yapp_common.o: $(SRCDIR)/yapp_common.c $(SRCDIR)/yapp.h
$(CC) $(CFLAGS_C) $(DDEBUG) $< -o $(IDIR)/$@
$(CC) $(CFLAGS_C) $(DDEBUG) $(DHDF5) $< -o $(IDIR)/$@

yapp_viewmetadata.o: $(SRCDIR)/yapp_viewmetadata.c $(SRCDIR)/yapp.h
$(CC) $(CFLAGS_C) $< -o $(IDIR)/$@
$(CC) $(CFLAGS_C) $(DHDF5) $< -o $(IDIR)/$@

yapp_viewmetadata: $(IDIR)/yapp_viewmetadata.o $(IDIR)/yapp_version.o \
$(IDIR)/yapp_erflookup.o $(IDIR)/yapp_common.o
Expand All @@ -148,7 +160,7 @@ colourmap.o: $(SRCDIR)/colourmap.c $(SRCDIR)/colourmap.h

yapp_viewdata.o: $(SRCDIR)/yapp_viewdata.c $(SRCDIR)/yapp.h \
$(SRCDIR)/yapp_erflookup.c
$(CC) $(CFLAGS_C) $(DDEBUG) $< -o $(IDIR)/$@
$(CC) $(CFLAGS_C) $(DDEBUG) $(DHDF5) $< -o $(IDIR)/$@

yapp_viewdata: $(IDIR)/yapp_viewdata.o $(IDIR)/yapp_version.o \
$(IDIR)/yapp_erflookup.o $(IDIR)/yapp_common.o $(IDIR)/colourmap.o
Expand Down Expand Up @@ -233,13 +245,23 @@ yapp_tim2dat: $(UTILDIR)/yapp_tim2dat.o $(SRCDIR)/yapp_version.o \
$(IDIR)/yapp_erflookup.o $(IDIR)/yapp_common.o
$(CC) $^ $(LFLAGS_MATH) $(LFLAGS_CFITSIO) $(LFLAGS_HDF5) -o $(BINDIR)/$@

ifeq ($(HDF5), yes)
yapp_fil2h5.o: $(UTILDIR)/yapp_fil2h5.c $(UTILDIR)/yapp_fil2h5.h \
$(SRCDIR)/yapp.h $(SRCDIR)/yapp_sigproc.h
$(CC) $(CFLAGS_C) -I$(SRCDIR) $(DDEBUG) $< -o $(UTILDIR)/$@
$(CC) $(CFLAGS_C) -I$(SRCDIR) $(DDEBUG) $(DHDF5) $< -o $(UTILDIR)/$@
else
yapp_fil2h5.o:
@echo "WARNING: yapp_fil2h5.o will not be compiled (HDF5=no)"
endif

ifeq ($(HDF5), yes)
yapp_fil2h5: $(UTILDIR)/yapp_fil2h5.o $(SRCDIR)/yapp_version.o \
$(IDIR)/yapp_erflookup.o $(IDIR)/yapp_common.o
$(CC) $^ $(LFLAGS_MATH) $(LFLAGS_CFITSIO) $(LFLAGS_HDF5) -o $(BINDIR)/$@
else
yapp_fil2h5:
@echo "WARNING: yapp_fil2h5 will not be compiled (HDF5=no)"
endif

yapp_siftpulses.o: $(SRCDIR)/yapp_siftpulses.c $(SRCDIR)/yapp.h $(SRCDIR)/yapp_sigproc.h
$(CC) $(CFLAGS_C) $(DDEBUG) $< -o $(IDIR)/$@
Expand Down Expand Up @@ -298,7 +320,9 @@ clean:
$(DELCMD) $(UTILDIR)/yapp_fits2fil.o
$(DELCMD) $(UTILDIR)/yapp_dat2tim.o
$(DELCMD) $(UTILDIR)/yapp_tim2dat.o
ifeq ($(HDF5), yes)
$(DELCMD) $(UTILDIR)/yapp_fil2h5.o
endif
$(DELCMD) $(IDIR)/yapp_subtract.o
$(DELCMD) $(IDIR)/yapp_siftpulses.o
$(DELCMD) $(IDIR)/yapp_stacktim.o
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The YAPP tools available with this release are:
YAPP also comes with the following utilities:

* `yapp_fits2fil` : Converts PSRFITS data to SIGPROC `.fil`
* `yapp_fil2h5` : Converts SIGPROC `.fil` to HDF5.
* `yapp_dat2tim` : Converts PRESTO '.dat' to SIGPROC `.tim`
* `yapp_tim2dat` : Converts SIGPROC '.tim' to PRESTO `.dat`
* `yapp_ym2fil` : Converts YAPP Metadata to SIGPROC filterbank header format.
Expand All @@ -40,9 +41,9 @@ The supported file formats are SIGPROC `.fil` and SIGPROC `.tim`, with limited s

For detailed usage instructions, refer the man pages or online documentation.

System requirements: Linux/OS X, PGPLOT with C binding, FFTW3, CFITSIO, Python with Matplotlib, Ruby, mogrify
System requirements: Linux/OS X, PGPLOT with C binding, FFTW3, CFITSIO, HDF5 (optional), Python with Matplotlib, Ruby, mogrify

Installation instructions: On a typical Ubuntu-based machine in which PGPLOT, FFTW3, and CFITSIO were installed via APT, running `make` followed by `sudo make install` should work, with the binaries being copied to `/usr/local/bin`. For different operating systems and/or different PGPLOT/FFTW3/CFITSIO installation directories and/or a different choice of YAPP installation directory, the makefile may need to be modified by hand. YAPP scripts require YAPP binaries to be in the search path.
Installation instructions: On a typical Ubuntu-based machine in which PGPLOT, FFTW3, and CFITSIO were installed via APT, and the optinal HDF5 was installed in its default location, running `make` (or `make HDF5=yes`) followed by `sudo make install` should work, with the binaries being copied to `/usr/local/bin`. For different operating systems and/or different PGPLOT/FFTW3/CFITSIO/HDF5 installation directories and/or a different choice of YAPP installation directory, the makefile may need to be modified by hand. YAPP scripts require YAPP binaries to be in the search path.

Created by Jayanth Chennamangalam
[http://jayanthc.github.io/yapp/](http://jayanthc.github.io/yapp/)
16 changes: 16 additions & 0 deletions src/yapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#include <float.h>

#include <cpgplot.h>
#ifdef HDF5
#include <hdf5.h>
#endif


/**
Expand Down Expand Up @@ -64,7 +66,9 @@
#define YAPP_FORMATSTR_DTS_DAT "dat"
#define YAPP_FORMATSTR_DTS_DAT_INF "inf"
#define YAPP_FORMATSTR_YM "ym"
#ifdef HDF5
#define YAPP_FORMATSTR_HDF5 "h5"
#endif
/* @} */

#define EXT_PSRFITS ".fits"
Expand All @@ -80,15 +84,19 @@
#define EXT_INF ".inf"
#define EXT_YM ".ym"
#define EXT_YAPP_PROFILE ".yp"
#ifdef HDF5
#define EXT_HDF5 ".h5"
#endif

enum tagFileFormats
{
/* dynamic spectrum formats */
YAPP_FORMAT_SPEC = 0, /* Desh's specfile format */
YAPP_FORMAT_PSRFITS, /* PSRFITS spectrometer data */
YAPP_FORMAT_FIL, /* SIGPROC filterbank file format */
#ifdef HDF5
YAPP_FORMAT_HDF5, /* HDF5 file containing dynamic spectrum */
#endif
/* dedispersed time series formats */
YAPP_FORMAT_DTS_DDS, /* Desh's dedispersed data format */
YAPP_FORMAT_DTS_TIM, /* SIGPROC time series format */
Expand Down Expand Up @@ -290,9 +298,11 @@ enum tagFileFormats

#define YAPP_DEGPERHOUR 15 /* degrees per hour */

#ifdef HDF5
/* HDF5 */
/* dimensionality of dynamic spectrum */
#define YAPP_HDF5_DYNSPEC_RANK 2
#endif

/**
* YAPP Unified Metadata (YUM) definition
Expand Down Expand Up @@ -345,8 +355,10 @@ typedef struct YUM_s
float fMean;
float fMedian;
float fRMS;
#ifdef HDF5
/* for HDF5 chunking */
long int lChunkDims[YAPP_HDF5_DYNSPEC_RANK];
#endif

#if 0
/* DAS configuration information */
Expand Down Expand Up @@ -538,6 +550,7 @@ int YAPP_ReadSIGPROCHeaderFile(char *pcFileSpec, YUM_t *pstYUM);
*/
int YAPP_ReadPRESTOHeaderFile(char *pcFileData, YUM_t *pstYUM);

#ifdef HDF5
/**
* Read configuration information corresponding to an HDF5 ('.h5') file
*
Expand All @@ -546,6 +559,7 @@ int YAPP_ReadPRESTOHeaderFile(char *pcFileData, YUM_t *pstYUM);
* @param[out] pstYUM YUM structure
*/
int YAPP_ReadHDF5Metadata(char *pcFileSpec, int iFormat, YUM_t *pstYUM);
#endif

/**
* Read one block of data from disk
Expand All @@ -559,6 +573,7 @@ int YAPP_ReadData(FILE *pFData,
float fSampSize,
int iTotSampsPerBlock);

#ifdef HDF5
/**
* Read one block of data from HDF5 file on disk
*/
Expand All @@ -571,6 +586,7 @@ int YAPP_ReadHDF5Data(hid_t hDataspace,
float *pfBuf,
float fSampSize,
int iTotSampsPerBlock);
#endif

int YAPP_WriteMetadata(char *pcFileData, int iFormat, YUM_t stYUM);

Expand Down
21 changes: 19 additions & 2 deletions src/yapp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
#include "yapp_sigproc.h"
#include "yapp_psrfits.h"
#include "yapp_presto.h"
#ifdef HDF5
#include "yapp_hdf5.h"
#endif

#include <fitsio.h>
#ifdef HDF5
#include <hdf5.h>
#endif

const char g_aacSP_ObsNames[YAPP_SP_NUMOBS][LEN_GENSTRING] = {
YAPP_SP_OBS_FAKE,
Expand Down Expand Up @@ -85,10 +90,12 @@ int YAPP_GetFileType(char *pcFile)
{
iFormat = YAPP_FORMAT_YM;
}
#ifdef HDF5
else if (0 == strcmp(pcExt, EXT_HDF5))
{
iFormat = YAPP_FORMAT_HDF5;
}
#endif
else
{
(void) fprintf(stderr,
Expand Down Expand Up @@ -356,9 +363,11 @@ int YAPP_GetExtFromFormat(int iFormat, char *pcExt)
(void) strcpy(pcExt, YAPP_FORMATSTR_YM);
break;

#ifdef HDF5
case YAPP_FORMAT_HDF5:
(void) strcpy(pcExt, YAPP_FORMATSTR_HDF5);
break;
#endif

default:
(void) fprintf(stderr,
Expand Down Expand Up @@ -440,6 +449,7 @@ int YAPP_ReadMetadata(char *pcFileSpec, int iFormat, YUM_t *pstYUM)
}
break;

#ifdef HDF5
case YAPP_FORMAT_HDF5:
iRet = YAPP_ReadHDF5Metadata(pcFileSpec, iFormat, pstYUM);
if (iRet != YAPP_RET_SUCCESS)
Expand All @@ -450,6 +460,7 @@ int YAPP_ReadMetadata(char *pcFileSpec, int iFormat, YUM_t *pstYUM)
return YAPP_RET_ERROR;
}
break;
#endif

default:
(void) fprintf(stderr,
Expand Down Expand Up @@ -965,7 +976,7 @@ int YAPP_ReadDASCfg(char *pcFileSpec, YUM_t *pstYUM)
return YAPP_RET_SUCCESS;
}


#ifdef HDF5
int YAPP_ReadHDF5Metadata(char *pcFileSpec, int iFormat, YUM_t *pstYUM)
{
hid_t hFile = 0;
Expand Down Expand Up @@ -1186,6 +1197,7 @@ herr_t YAPP_ReadHDF5Attribute(hid_t hDataset,

return hStatus;
}
#endif

int YAPP_ReadSIGPROCHeader(char *pcFileSpec, int iFormat, YUM_t *pstYUM)
{
Expand Down Expand Up @@ -2187,6 +2199,7 @@ int YAPP_ReadData(FILE *pFData,
}


#ifdef HDF5
/*
* Read HDF5 data.
*/
Expand Down Expand Up @@ -2322,7 +2335,7 @@ int YAPP_ReadHDF5Data(hid_t hDataspace,

return iReadItems;
}

#endif

/*
* Writes header to a data file.
Expand Down Expand Up @@ -2647,6 +2660,7 @@ int YAPP_WriteMetadata(char *pcFileData, int iFormat, YUM_t stYUM)

(void) fclose(pFInf);
}
#ifdef HDF5
else if (YAPP_FORMAT_HDF5 == iFormat)
{
hid_t hFile = 0;
Expand Down Expand Up @@ -2864,11 +2878,13 @@ int YAPP_WriteMetadata(char *pcFileData, int iFormat, YUM_t stYUM)
(void) H5Fclose(hFile);

}
#endif

return YAPP_RET_SUCCESS;
}


#ifdef HDF5
/*
* Write HDF5 string attribute to a dataset
*/
Expand Down Expand Up @@ -3014,6 +3030,7 @@ int YAPP_WriteHDF5CharAttribute(hid_t hDataset,

return YAPP_RET_SUCCESS;
}
#endif


/*
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.7-beta"
#define VER_BUILD_PREFIX "YAPP-REL-3.6.8-beta"
#define VER_BUILD_DELIM "-"

time_t GetLatestTimestamp(void);
Expand Down
Loading

0 comments on commit 940ca9d

Please sign in to comment.