72#include <lal/LALString.h>
73#include <lal/LALFrameU.h>
75#define FAILURE(...) do { fprintf(stderr, __VA_ARGS__); exit(99); } while (0)
78int readdata(
size_t * ndim,
size_t * size,
double **data,
char ***channames,
char ***chanunits, FILE * fp);
80int main(
int argc,
char *argv[])
83 char *defaultfilev[1] = { stdio };
84 int filec = (argc == 1 ? 1 : argc - 1);
85 char **filev = (argc == 1 ? defaultfilev : &argv[1]);
91 FAILURE(
"could not create output file\n");
93 for (f = 0; f < filec; ++f) {
94 char *fname = filev[f];
97 double srate = 16384.0;
112 if (strcmp(fname,
"-") == 0)
115 fp = fopen(fname,
"r");
117 FAILURE(
"could not open file %s\n", fname);
119 readdata(&ndim, &dimlen, &data, &channames, &chanunits,
fp);
126 floor(0.5 + (dimlen - 1) / (data[(dimlen - 1) * ndim] -
135 for (dim = (ndim == 1 ? 0 : 1); dim < ndim; ++dim) {
146 for (i = 0; i < dimlen; ++i)
147 vect[i] = data[i * ndim + dim];
151 free(channames[dim]);
152 free(chanunits[dim]);
166int readdata(
size_t * ndim,
size_t * dimlen,
double **data,
char ***channames,
char ***chanunits, FILE * fp)
168 char header[LINE_MAX] =
"";
180 if ((c = fgetc(
fp)) ==
'#')
181 fgets(header,
sizeof(header),
fp);
189 while (fgets(line,
sizeof(line),
fp)) {
200 double v = strtod(s, &endp);
202 if (s == endp || *endp ==
'\0')
207 FAILURE(
"format error on input line %zu\n", rows + 1);
213 *data = realloc(*data, bufsz * cols *
sizeof(**data));
215 for (col = 0; col < cols; ++col) {
217 (*data)[rows * cols + col] = strtod(s, &endp);
218 if (s == endp || *endp ==
'\0')
219 FAILURE(
"format error on input line %zu\n", rows + 1);
224 *data = realloc(*data, rows * cols *
sizeof(**data));
227 *channames = calloc(cols,
sizeof(**channames));
228 *chanunits = calloc(cols,
sizeof(**chanunits));
231 for (col = 0; col < cols; ++col) {
232 char name[LINE_MAX] =
"";
233 char unit[LINE_MAX] =
"";
236 n = sscanf(tok,
"%s (%[^)])",
name, unit);
238 snprintf(
name,
sizeof(
name),
"C%02zu", col);
249 size_t len = strlen(str);
250 char *dup = malloc(len + 1);
int main(int argc, char *argv[])
char * mystrdup(const char *s)
int readdata(size_t *ndim, size_t *size, double **data, char ***channames, char ***chanunits, FILE *fp)
LALFrameUFrameH * XLALFrameUFrameHAlloc(const char *name, double start1, double start2, double dt, int frnum)
Allocate memory for a new frame header FrameH structure.
int XLALFrameUFrameHWrite(LALFrameUFrFile *stream, LALFrameUFrameH *frame)
Write a FrameH structure to an output FrFile stream.
void * XLALFrameUFrChanVectorQueryData(const LALFrameUFrChan *channel)
Query FrChan structure for the data pointer in its FrVect structure.
void XLALFrameUFrameHFree(LALFrameUFrameH *frame)
Free a FrameH structure.
void XLALFrameUFrChanFree(LALFrameUFrChan *channel)
Free a FrChan structure.
int XLALFrameUFrChanVectorSetDx(LALFrameUFrChan *channel, double dx)
Set the sampling interval for the data in the FrVect structure contained in a FrChan structure.
int XLALFrameUFrameHFrChanAdd(LALFrameUFrameH *frame, LALFrameUFrChan *channel)
Add a FrChan structure to a FrameH structure.
struct tagLALFrameUFrameH LALFrameUFrameH
Incomplete type for a frame header FrameH structure.
int XLALFrameUFrChanVectorSetUnitY(LALFrameUFrChan *channel, const char *unit)
Set the units of the data in the FrVect structure contained in a FrChan structure.
int XLALFrameUFrChanVectorAlloc(LALFrameUFrChan *channel, int dtype, size_t ndata)
Allocate memory for a FrVect structure within a FrChan structure.
int XLALFrameUFrameHSetRun(LALFrameUFrameH *frame, int run)
Set the run number in a FrameH structure.
LALFrameUFrFile * XLALFrameUFrFileOpen(const char *filename, const char *mode)
Open a frame file FrFile stream.
LALFrameUFrChan * XLALFrameUFrProcChanAlloc(const char *name, int type, int subtype, int dtype, size_t ndata)
Allocate memory for a new FrChan structure of FrAdcData type.
int XLALFrameUFrChanVectorSetName(LALFrameUFrChan *channel, const char *name)
Set the name of the FrVect structure contained in a FrChan structure.
void XLALFrameUFrFileClose(LALFrameUFrFile *stream)
Close a FrFile stream.
int XLALFrameUFrChanVectorSetUnitX(LALFrameUFrChan *channel, const char *unit)
Set the units of the domain of the data in the FrVect structure contained in a FrChan structure.
@ LAL_FRAMEU_FR_PROC_TYPE_TIME_SERIES
Id for time-series data.
@ LAL_FRAMEU_FR_PROC_SUB_TYPE_UNKNOWN
Id for unknown or user-defined data.
@ LAL_FRAMEU_FR_VECT_8R
Id for 64-bit double precision floating point data type.
char * XLALStringToken(char **s, const char *delim, int empty)
void output(int gps_sec, int output_type)