LAL  7.5.0.1-b72065a
H5FileIOVector_source.c
Go to the documentation of this file.
1 #define CONCAT2x(a,b) a##b
2 #define CONCAT2(a,b) CONCAT2x(a,b)
3 #define CONCAT3x(a,b,c) a##b##c
4 #define CONCAT3(a,b,c) CONCAT3x(a,b,c)
5 
6 #define VTYPE CONCAT2(TYPE,Vector)
7 #define TCODE CONCAT3(LAL_,TYPECODE,_TYPE_CODE)
8 
9 #define ALLOCFUNC CONCAT2(XLALH5DatasetAlloc,VTYPE)
10 #define READFUNC CONCAT2(XLALH5DatasetRead,VTYPE)
11 
12 #define CREATEFUNC CONCAT2(XLALCreate,VTYPE)
13 #define DESTROYFUNC CONCAT2(XLALDestroy,VTYPE)
14 
15 LALH5Dataset *ALLOCFUNC(LALH5File *file, const char *name, VTYPE *vector)
16 {
17  LALH5Dataset *dataset;
18  if (!file || !name || !vector)
20  if (!vector->length || !vector->data)
22  dataset = XLALH5DatasetAlloc1D(file, name, TCODE, vector->length);
23  if (!dataset)
25  if (XLALH5DatasetWrite(dataset, vector->data) < 0) {
26  XLALH5DatasetFree(dataset);
28  }
29  return dataset;
30 }
31 
33 {
34  VTYPE *vector;
35  LALTYPECODE type;
36  size_t npoints;
37  int ndim;
38 
39  /* error checking */
40 
41  if (!dset)
43 
44  ndim = XLALH5DatasetQueryNDim(dset);
45  if (ndim != 1)
47 
48  type = XLALH5DatasetQueryType(dset);
49  if (type != TCODE)
51 
52  npoints = XLALH5DatasetQueryNPoints(dset);
53  if (npoints == (size_t)(-1))
55 
56  vector = CREATEFUNC(npoints);
57  if (!vector)
59 
60  if (XLALH5DatasetQueryData(vector->data, dset) == -1) {
61  DESTROYFUNC(vector);
63  }
64 
65  return vector;
66 }
67 
68 #undef CONCAT2x
69 #undef CONCAT2
70 #undef CONCAT3x
71 #undef CONCAT3
72 
73 #undef VTYPE
74 #undef TCODE
75 
76 #undef ALLOCFUNC
77 #undef READFUNC
78 
79 #undef CREATEFUNC
80 #undef DESTROYFUNC
int XLALH5DatasetQueryNDim(LALH5Dataset *dset)
struct tagLALH5File LALH5File
Incomplete type for a HDF5 file.
Definition: H5FileIO.h:93
LALTYPECODE XLALH5DatasetQueryType(LALH5Dataset *dset)
struct tagLALH5Dataset LALH5Dataset
Incomplete type for a HDF5 dataset.
Definition: H5FileIO.h:102
int XLALH5DatasetWrite(LALH5Dataset *dset, void *data)
void XLALH5DatasetFree(LALH5Dataset *dset)
size_t XLALH5DatasetQueryNPoints(LALH5Dataset *dset)
int XLALH5DatasetQueryData(void *data, LALH5Dataset *dset)
LALH5Dataset * XLALH5DatasetAlloc1D(LALH5File *file, const char *name, LALTYPECODE dtype, size_t length)
#define TCODE
#define ALLOCFUNC
#define READFUNC
#define CREATEFUNC
#define VTYPE
#define DESTROYFUNC
const char *const name
type name
Definition: UserInput.c:193
LALTYPECODE
Type codes: use these type codes to identify a LAL atomic data type, see Headers LAL(Atomic)Datatypes...
Definition: LALDatatypes.h:49
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
Definition: XLALError.h:713
@ XLAL_ENOMEM
Memory allocation error.
Definition: XLALError.h:407
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_ETYPE
Wrong or unknown type.
Definition: XLALError.h:422
@ XLAL_EDIMS
Wrong dimensions.
Definition: XLALError.h:421
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409