LALFrame 3.0.7.1-eeff03c
LALFrameL.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2013 Jolien Creighton
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#define _GNU_SOURCE /* for mkstemp() and strdup() */
21
22#include <config.h>
23#include <stdlib.h>
24#include <math.h>
25#include <stdio.h>
26#include <string.h>
27#ifdef HAVE_UNISTD_H
28#include <unistd.h>
29#endif
30
31#include <lal/LALStdlib.h>
32#include <lal/LALString.h>
33#include <lal/Date.h>
34#include <lal/XLALError.h>
35
36#ifndef P_tmpdir
37#define P_tmpdir "/tmp"
38#endif
39
40#include <FrIO.h>
41#include <FrameL.h>
42
43#ifdef __GNUC__
44#define UNUSED __attribute__ ((unused))
45#else
46#define UNUSED
47#endif
48
49/* resolve incomplete types with FrameL structs and custom structs */
50#define tagLALFrameUFrameH FrameH
51#define tagLALFrameUFrTOC FrTOC
52#define tagLALFrameUFrHistory FrHistory
53#include <lal/LALFrameU.h>
54#include "LALFrameUFrameL.h"
55
56static const char * XLALFrameLErrorMessage(FRERROR frerror)
57{
58 switch (frerror) {
59 case FR_OK:
60 return "FR_OK";
61 case FR_ERROR_NO_FRAME:
62 return "FR_ERROR_NO_FRAME";
63 case FR_ERROR_NO_FILE:
64 return "FR_ERROR_NO_FILE";
65 case FR_ERROR_MALLOC_FAILED:
66 return "FR_ERROR_MALLOC_FAILED";
67 case FR_ERROR_BUFF_OVERFLOW:
68 return "FR_ERROR_BUFF_OVERFLOW";
69 case FR_ERROR_WRITE_ERROR:
70 return "FR_ERROR_WRITE_ERROR";
71 case FR_ERROR_READ_ERROR:
72 return "FR_ERROR_READ_ERROR";
73 case FR_ERROR_FRSET:
74 return "FR_ERROR_FRSET";
75 case FR_ERROR_WRONG_CHAR_LENGTH:
76 return "FR_ERROR_WRONG_CHAR_LENGTH";
77 case FR_ERROR_BAD_END_OF_FRAME:
78 return "FR_ERROR_BAD_END_OF_FRAME";
79 case FR_ERROR_OPEN_ERROR:
80 return "FR_ERROR_OPEN_ERROR";
81 case FR_ERROR_CHECKSUM:
82 return "FR_ERROR_CHECKSUM";
83 case FR_ERROR_BAD_NEVENT:
84 return "FR_ERROR_BAD_NEVENT";
85 case FR_ERROR_BAD_NSTAT:
86 return "FR_ERROR_BAD_NSTAT";
87 case FR_ERROR_TOO_LONG_STRING:
88 return "FR_ERROR_TOO_LONG_STRING";
89 default:
90 return "Unrecognized FrameL error code";
91 }
92 return "Invalid FrameL error code";
93}
94
96struct tagLALFrameUFrFile {
97 int mode;
98 FrFile *handle;
99};
100
105 int type;
106 union {
107 FrAdcData *adc;
108 FrProcData *proc;
109 FrSimData *sim;
111};
112
113/* for safety, have a string prefix that is nul-terminated as well */
115 FrDetector *handle;
116 char prefix[3];
117};
118
119/* local helper functions */
120
121/*
122 * Mac OS X 10.9 (Mavericks) displays the following warning regarding
123 * the usage of tempnam():
124 *
125 * warning: 'tempnam' is deprecated: This function is provided for
126 * compatibility reasons only. Due to security concerns inherent in the
127 * design of tempnam(3), it is highly recommended that you use mkstemp(3)
128 * instead. [-Wdeprecated-declarations]
129 *
130 * wrap mkstemp() as a drop in replacement.
131 */
132static int mytmpfd(char *tmpfname)
133{
134 snprintf(tmpfname, L_tmpnam, "%s/tmp.lal.XXXXXX", P_tmpdir);
135 return mkstemp(tmpfname);
136}
137
138/* TODO: get XLAL error macros going! */
139
140/*
141 * FrFile functions
142 */
143
144void XLALFrameUFrFileClose_FrameL_(LALFrameUFrFile * stream)
145{
146 if (stream) {
147 if (stream->mode == XLAL_FRAMEU_FR_FILE_MODE_R)
148 FrFileIEnd(stream->handle);
149 else
150 FrFileOEnd(stream->handle);
151 LALFree(stream);
152 }
153}
154
155LALFrameUFrFile *XLALFrameUFrFileOpen_FrameL_(const char *filename, const char *mode)
156{
157 union {
158 const char *cs;
159 char *s;
160 } fname = {
161 filename};
162 LALFrameUFrFile *stream;
163
164 if (*mode != 'r' && *mode != 'w')
166
167 stream = LALCalloc(1, sizeof(*stream));
168 if (!stream)
170
171 if (*mode == 'r') {
172 if (filename == NULL || strcmp(filename, "-") == 0) {
173 /* hack for reading from stdin: dump to a tmpfile */
174 char tmpfname[L_tmpnam + 1];
175 FILE *tmpfp;
176#define BUFSZ 16384
177 char buf[BUFSZ];
178#undef BUFSZ
179 tmpfp = fdopen(mytmpfd(tmpfname), "w");
180 while (fwrite(buf, 1, fread(buf, 1, sizeof(buf), stdin), tmpfp) == sizeof(buf)) ;
181 fclose(tmpfp);
182 stream->handle = FrFileINew(tmpfname);
183 unlink(tmpfname); /* remove tempfile when closed */
184 } else
185 stream->handle = FrFileINew(fname.s);
186 if (!stream->handle) {
187 LALFree(stream);
188 XLAL_ERROR_NULL(XLAL_EIO, "FrFileINew failed.");
189 }
190 /* turn on structure checksum checking */
191 stream->handle->chkSumFrFlag = FR_YES;
192 stream->mode = XLAL_FRAMEU_FR_FILE_MODE_R;
193 } else {
194 if (filename == NULL || strcmp(filename, "-") == 0) {
195 /* output to stdout */
196 struct FrIO *frfd;
197 frfd = malloc(sizeof(*frfd));
198#ifdef FRIOCFILE
199 frfd->fp = stdout;
200#else
201 frfd->fd = 1;
202#endif
203 stream->handle = FrFileONewFd(frfd, -1); /* -1: don't alter compression */
204 } else
205 stream->handle = FrFileONew(fname.s, -1); /* -1: don't alter compression */
206 if (!stream->handle) {
207 LALFree(stream);
208 XLAL_ERROR_NULL(XLAL_EIO, "FrFileONew failed.");
209 }
210 stream->handle->noTOCts = FR_NO;
211 stream->mode = XLAL_FRAMEU_FR_FILE_MODE_W;
212 }
213
214 return stream;
215}
216
217/* FIXME: WARNING: this value might need to change in the future */
218#define FR_FILE_HEADER_SIZE 40 /* size of frame file header in bytes */
219
220int XLALFrameUFileCksumValid_FrameL_(LALFrameUFrFile * stream)
221{
222 FrameH *frame = NULL;
223 FRBOOL chkSumFiFlag = stream->handle->chkSumFiFlag;
224 FRBOOL chkSumFrFlag = stream->handle->chkSumFrFlag;
225 stream->handle->chkSumFiFlag = FR_YES;
226 stream->handle->chkSumFrFlag = FR_NO;
227
228 /* sequential read */
229
230 /* FIXME: WARNING: HACK:
231 * the following line may need to be updated in future */
232 FrIOSet(stream->handle->frfd, FR_FILE_HEADER_SIZE);
233
234 while ((frame = FrameReadRecycle(stream->handle, frame))) ;
235 stream->handle->chkSumFiFlag = chkSumFiFlag;
236 stream->handle->chkSumFrFlag = chkSumFrFlag;
237 if (stream->handle->error != FR_OK)
238 XLAL_ERROR_VAL(0, XLAL_EFAILED, "%s", FrErrorGetHistory());
239 if (stream->handle->chkTypeFiRead == 0)
240 XLAL_ERROR_VAL(0, XLAL_EFAILED, "Missing checksum");
241 if (stream->handle->chkSumFiRead != stream->handle->chkSumFi)
242 XLAL_ERROR_VAL(0, XLAL_EFAILED, "Bad checksum");
243 FrFileIRewind(stream->handle);
244 return 1;
245}
246
247/*
248 * FrTOC functions
249 */
250
252{
253 /* Note: toc is owned by frame file */
254 return;
255}
256
258{
259 return FrTOCReadFull(stream->handle);
260}
261
263{
264 return toc->nFrame;
265}
266
267double XLALFrameUFrTOCQueryGTimeModf_FrameL_(double *iptr, const LALFrameUFrTOC * toc, size_t pos)
268{
269 if (pos < (size_t) toc->nFrame) {
271 XLALGPSSet(&epoch, toc->GTimeS[pos], toc->GTimeN[pos]);
272 return XLALGPSModf(iptr, &epoch);
273 }
275}
276
277double XLALFrameUFrTOCQueryDt_FrameL_(const LALFrameUFrTOC * toc, size_t pos)
278{
279 if (pos >= (size_t) toc->nFrame)
280 XLAL_ERROR_REAL8(XLAL_EINVAL, "pos = %zu out of range", pos);
281 return toc->dt[pos];
282}
283
285{
286 FrTOCts *ts;
287 size_t nAdc = 0;
288 for (ts = toc->adc; ts != NULL; ts = ts->next)
289 ++nAdc;
290 return nAdc;
291}
292
293/* WARNING: returns pointer to memory that is lost when frame is freed */
294const char *XLALFrameUFrTOCQueryAdcName_FrameL_(const LALFrameUFrTOC * toc, size_t adc)
295{
296 FrTOCts *ts = toc->adc;
297 size_t i = 0;
298 while (ts)
299 if (adc == i++)
300 return ts->name;
301 else
302 ts = ts->next;
303 XLAL_ERROR_NULL(XLAL_EINVAL, "adc = %zu out of range", adc);
304}
305
307{
308 FrTOCts *ts;
309 size_t nSim = 0;
310 for (ts = toc->sim; ts != NULL; ts = ts->next)
311 ++nSim;
312 return nSim;
313}
314
315/* WARNING: returns pointer to memory that is lost when frame is freed */
316const char *XLALFrameUFrTOCQuerySimName_FrameL_(const LALFrameUFrTOC * toc, size_t sim)
317{
318 FrTOCts *ts = toc->sim;
319 size_t i = 0;
320 while (ts)
321 if (sim == i++)
322 return ts->name;
323 else
324 ts = ts->next;
325 XLAL_ERROR_NULL(XLAL_EINVAL, "sim = %zu out of range", sim);
326}
327
329{
330 FrTOCts *ts;
331 int nProc = 0;
332 for (ts = toc->proc; ts != NULL; ts = ts->next)
333 ++nProc;
334 return nProc;
335}
336
337/* WARNING: returns pointer to memory that is lost when frame is freed */
338const char *XLALFrameUFrTOCQueryProcName_FrameL_(const LALFrameUFrTOC * toc, size_t proc)
339{
340 FrTOCts *ts = toc->proc;
341 size_t i = 0;
342 while (ts)
343 if (proc == i++)
344 return ts->name;
345 else
346 ts = ts->next;
347 XLAL_ERROR_NULL(XLAL_EINVAL, "proc = %zu out of range", proc);
348}
349
351{
352 FrTOCdet *d;
353 int nDetector = 0;
354 for (d = toc->detector; d != NULL; d = d->next)
355 ++nDetector;
356 return nDetector;
357}
358
359/* WARNING: returns pointer to memory that is lost when frame is freed */
361{
362 FrTOCdet *d = toc->detector;
363 size_t i = 0;
364 while (d)
365 if (det == i++)
366 return d->name;
367 else
368 d = d->next;
369 XLAL_ERROR_NULL(XLAL_EINVAL, "det = %zu out of range", det);
370}
371
372/*
373 * FrameH functions
374 */
375
377{
378 FrameFree(frame);
379 return;
380}
381
382LALFrameUFrameH *XLALFrameUFrameHAlloc_FrameL_(const char *name, double start1, double start2, double dt, int frnum)
383{
384 double fp, fp1, fp2;
385 double ip, ip1, ip2;
386 LALFrameUFrameH *frame;
387
388 frame = calloc(1, sizeof(*frame));
389 if (!frame)
391
392 /* break start time into integer and fractional parts */
393 fp1 = modf(start1, &ip1);
394 fp2 = modf(start2, &ip2);
395 fp = modf(fp1 + fp2, &ip);
396 ip += ip1 + ip2;
397 if (fp < 0.0) { /* make sure fractional part is positive */
398 fp += 1.0;
399 ip -= 1.0;
400 }
401
402 frame->classe = FrameHDef();
403 frame->name = strdup(name);
404 frame->GTimeS = ip;
405 frame->GTimeN = floor(0.5 + 1e9 * fp);
406 if (frame->GTimeN >= 1000000000) { /* handle round-up corner case */
407 frame->GTimeN -= 1000000000;
408 frame->GTimeS += 1;
409 }
410 frame->frame = frnum;
411 frame->dt = dt;
412 frame->ULeapS = XLALLeapSeconds(frame->GTimeS);
413 return frame;
414}
415
416LALFrameUFrameH *XLALFrameUFrameHRead_FrameL_(LALFrameUFrFile * stream, int pos)
417{
418 LALFrameUFrameH *frame;
419 LALFrameUFrameH *copy;
420
421 /* make sure the TOC is read */
422 if (stream->handle->toc == NULL)
423 if (FrTOCReadFull(stream->handle) == NULL || stream->handle->error != FR_OK)
424 XLAL_ERROR_NULL(XLAL_EIO, "FrTOCReadFull failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error));
425
426 /* go to the right position */
427 if (FrFileIOSet(stream->handle, stream->handle->toc->positionH[pos]) == -1)
428 XLAL_ERROR_NULL(XLAL_EIO, "FrFileIOSet failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error));
429
430 /* get the frame */
431 frame = FrameRead(stream->handle);
432 if (!frame || stream->handle->error != FR_OK)
433 XLAL_ERROR_NULL(XLAL_EIO, "FrameRead failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error));
434
435 copy = FrameHCopy(frame);
436 FrSetIni(stream->handle);
437 stream->handle->curFrame = NULL;
438 FrameFree(frame);
439
440 return copy;
441}
442
443int XLALFrameUFrameHWrite_FrameL_(LALFrameUFrFile * stream, LALFrameUFrameH * frame)
444{
445 if (FrameWrite(frame, stream->handle) != FR_OK)
446 XLAL_ERROR(XLAL_EIO, "FrameWrite failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error));
447 return 0;
448}
449
450/* function to add a channel to a frame */
451
452/* need a bunch of helper routines to copy channels */
453/* note: these use system memory management routines */
454
455static FrHistory *XLALFrHistoryCopy(const FrHistory * original)
456{
457 FrHistory *copy;
458 copy = calloc(1, sizeof(*copy));
459 if (!copy)
461 memcpy(copy, original, sizeof(*copy));
462 /* in case of failure, set to zero/null the things we need
463 * to allocate separately */
464 copy->name = NULL;
465 copy->comment = NULL;
466 copy->next = NULL;
467 if (original->name) {
468 copy->name = strdup(original->name);
469 if (!copy->name)
470 goto failure;
471 }
472 if (original->comment) {
473 copy->comment = strdup(original->comment);
474 if (!copy->comment)
475 goto failure;
476 }
477 if (original->next) {
478 copy->next = XLALFrHistoryCopy(original->next);
479 if (!copy->next)
480 goto failure;
481 }
482 /* successful return */
483 return copy;
484 failure: /* unsuccessful return */
485 FrHistoryFree(copy);
487}
488
489static FrAdcData *XLALFrAdcDataCopy(const FrAdcData * original)
490{
491 FrAdcData *copy;
492 copy = calloc(1, sizeof(*copy));
493 if (!copy)
495 memcpy(copy, original, sizeof(*copy));
496 /* in case of failure, set to zero/null the things we need
497 * to allocate separately */
498 copy->name = NULL;
499 copy->comment = NULL;
500 copy->units = NULL;
501 copy->data = NULL;
502 copy->aux = NULL;
503 copy->next = NULL;
504 if (original->name) {
505 copy->name = strdup(original->name);
506 if (!copy->name)
507 goto failure;
508 }
509 if (original->comment) {
510 copy->comment = strdup(original->comment);
511 if (!copy->comment)
512 goto failure;
513 }
514 if (original->units) {
515 copy->units = strdup(original->units);
516 if (!copy->units)
517 goto failure;
518 }
519 if (original->data) {
520 copy->data = FrVectCopy(original->data);
521 if (!copy->data)
522 goto failure;
523 }
524 if (original->aux) {
525 copy->aux = FrVectCopy(original->aux);
526 if (!copy->aux)
527 goto failure;
528 }
529 if (original->next) {
530 copy->next = XLALFrAdcDataCopy(original->next);
531 if (!copy->next)
532 goto failure;
533 }
534 /* successful return */
535 return copy;
536 failure: /* unsuccessful return */
537 FrAdcDataFree(copy);
539}
540
541static FrProcData *XLALFrProcDataCopy(const FrProcData * original)
542{
543 FrProcData *copy;
544 copy = calloc(1, sizeof(*copy));
545 if (!copy)
547 memcpy(copy, original, sizeof(*copy));
548 /* in case of failure, set to zero/null the things we need
549 * to allocate separately */
550 copy->name = NULL;
551 copy->comment = NULL;
552 copy->nAuxParam = 0;
553 copy->auxParam = NULL;
554 copy->auxParamNames = NULL;
555 copy->data = NULL;
556 copy->aux = NULL;
557 copy->table = NULL;
558 copy->history = NULL;
559 copy->next = NULL;
560 if (original->name) {
561 copy->name = strdup(original->name);
562 if (!copy->name)
563 goto failure;
564 }
565 if (original->comment) {
566 copy->comment = strdup(original->comment);
567 if (!copy->comment)
568 goto failure;
569 }
570 if (original->nAuxParam > 0) {
571 int i;
572 copy->auxParam = calloc(original->nAuxParam, sizeof(*copy->auxParam));
573 copy->auxParamNames = calloc(original->nAuxParam, sizeof(*copy->auxParamNames));
574 if (!copy->auxParam || !copy->auxParamNames)
575 goto failure;
576 copy->nAuxParam = original->nAuxParam; /* now set value of nAuxParam */
577 memcpy(copy->auxParam, original->auxParam, copy->nAuxParam * sizeof(*copy->auxParam));
578 for (i = 0; i < copy->nAuxParam; ++i)
579 copy->auxParamNames[i] = strdup(original->auxParamNames[i]);
580 }
581 if (original->data) {
582 copy->data = FrVectCopy(original->data);
583 if (!copy->data)
584 goto failure;
585 }
586 if (original->aux) {
587 copy->aux = FrVectCopy(original->aux);
588 if (!copy->aux)
589 goto failure;
590 }
591 if (original->table) {
592 copy->table = FrTableCopy(original->table);
593 if (!copy->table)
594 goto failure;
595 }
596 if (original->history) {
597 copy->history = XLALFrHistoryCopy(original->history);
598 if (!copy->history)
599 goto failure;
600 }
601 if (original->next) {
602 copy->next = XLALFrProcDataCopy(original->next);
603 if (!copy->next)
604 goto failure;
605 }
606 /* successful return */
607 return copy;
608 failure: /* unsuccessful return */
609 FrProcDataFree(copy);
611}
612
613static FrSimData *XLALFrSimDataCopy(const FrSimData * original)
614{
615 FrSimData *copy;
616 copy = calloc(1, sizeof(*copy));
617 if (!copy)
619 memcpy(copy, original, sizeof(*copy));
620 /* in case of failure, set to zero/null the things we need
621 * to allocate separately */
622 copy->name = NULL;
623 copy->comment = NULL;
624 copy->data = NULL;
625 copy->input = NULL;
626 copy->table = NULL;
627 copy->next = NULL;
628 if (original->name) {
629 copy->name = strdup(original->name);
630 if (!copy->name)
631 goto failure;
632 }
633 if (original->comment) {
634 copy->comment = strdup(original->comment);
635 if (!copy->comment)
636 goto failure;
637 }
638 if (original->data) {
639 copy->data = FrVectCopy(original->data);
640 if (!copy->data)
641 goto failure;
642 }
643 if (original->input) {
644 copy->input = FrVectCopy(original->input);
645 if (!copy->input)
646 goto failure;
647 }
648 if (original->table) {
649 copy->table = FrTableCopy(original->table);
650 if (!copy->table)
651 goto failure;
652 }
653 if (original->next) {
654 copy->next = XLALFrSimDataCopy(original->next);
655 if (!copy->next)
656 goto failure;
657 }
658 /* successful return */
659 return copy;
660 failure: /* unsuccessful return */
661 FrSimDataFree(copy);
663}
664
666{
667 LALFrameUFrChan copy;
668 switch (channel->type) {
670 copy.handle.adc = XLALFrAdcDataCopy(channel->handle.adc);
671 if (!copy.handle.adc)
673 if (frame->rawData == NULL)
674 FrRawDataNew(frame);
675 copy.handle.adc->next = frame->rawData->firstAdc;
676 frame->rawData->firstAdc = copy.handle.adc;
677 break;
679 copy.handle.proc = XLALFrProcDataCopy(channel->handle.proc);
680 if (!copy.handle.proc)
682 copy.handle.proc->next = frame->procData;
683 frame->procData = copy.handle.proc;
684 break;
686 copy.handle.sim = XLALFrSimDataCopy(channel->handle.sim);
687 if (!copy.handle.sim)
689 copy.handle.sim->next = frame->simData;
690 frame->simData = copy.handle.sim;
691 break;
692 default:
693 XLAL_ERROR(XLAL_EINVAL, "Invalid channel type");
694 }
695 return 0;
696}
697
698int XLALFrameUFrameHFrDetectorAdd_FrameL_(LALFrameUFrameH * frame, LALFrameUFrDetector * detector)
699{
700 FrDetector *copy;
701 copy = calloc(1, sizeof(*copy));
702 if (!copy)
704
705 copy->classe = FrDetectorDef();
706 if (detector->handle->name) {
707 copy->name = strdup(detector->handle->name);
708 if (!copy->name) {
709 free(copy);
711 }
712 }
713 memcpy(copy->prefix, detector->handle->prefix, 2);
714
715 copy->longitude = detector->handle->longitude;
716 copy->latitude = detector->handle->latitude;
717 copy->elevation = detector->handle->elevation;
718 copy->armXazimuth = detector->handle->armXazimuth;
719 copy->armYazimuth = detector->handle->armYazimuth;
720 copy->armXaltitude = detector->handle->armXaltitude;
721 copy->armYaltitude = detector->handle->armYaltitude;
722 copy->armXmidpoint = detector->handle->armXmidpoint;
723 copy->armYmidpoint = detector->handle->armYmidpoint;
724 copy->localTime = detector->handle->localTime;
725
726 /* now affix it to frame */
727 copy->next = frame->detectProc;
728 frame->detectProc = copy;
729 return 0;
730}
731
733{
734 FrHistory *copy;
735 copy = FrHistoryNew(history->name ? history->name : frame->name, history->time, history->comment);
736 if (!copy)
737 XLAL_ERROR(XLAL_EIO, "FrHistoryNew failed.");
738 copy->next = frame->history;
739 frame->history = copy;
740 return 0;
741}
742
743/* WARNING: returns pointer to memory that is lost when frame is freed */
745{
746 return frame->name;
747}
748
750{
751 return frame->run;
752}
753
755{
756 return frame->frame;
757}
758
760{
761 return frame->dataQuality;
762}
763
765{
767 XLALGPSSet(&epoch, frame->GTimeS, frame->GTimeN);
768 return XLALGPSModf(iptr, &epoch);
769}
770
772{
773 return frame->ULeapS;
774}
775
777{
778 return frame->dt;
779}
780
781/* functions to set frame metadata */
782
784{
785 frame->run = run;
786 return 0;
787}
788
789/*
790 * FrChan functions
791 */
792
794{
795 if (channel) {
796 switch (channel->type) {
798 FrAdcDataFree(channel->handle.adc);
799 break;
801 FrProcDataFree(channel->handle.proc);
802 break;
804 FrSimDataFree(channel->handle.sim);
805 break;
806 default:
807 break;
808 }
810 }
811 return;
812}
813
814LALFrameUFrChan *XLALFrameUFrChanRead_FrameL_(LALFrameUFrFile * stream, const char *name, size_t pos)
815{
816 LALFrameUFrChan *channel;
817 FrTOCts *ts;
818 FrTOC *toc;
819 double gtime;
820
821 toc = stream->handle->toc;
822 if (!toc)
823 toc = FrTOCReadFull(stream->handle);
824 if (!toc || stream->handle->error != FR_OK)
825 XLAL_ERROR_NULL(XLAL_EIO, "FrTOCReadFull failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error));
826 if (pos >= (size_t) toc->nFrame)
827 XLAL_ERROR_NULL(XLAL_EINVAL, "pos = %zu out of range", pos);
828
829 /* the gps time of the frame at position pos */
830 gtime = toc->GTimeS[pos] + 1e-9 * toc->GTimeN[pos];
831
832 /* allocate memory for channel */
833 channel = LALCalloc(1, sizeof(*channel));
834 if (!channel)
836
837 /* scan adc channels */
838 stream->handle->relocation = FR_NO;
839 for (ts = toc->adc; ts != NULL; ts = ts->next)
840 if (strcmp(name, ts->name) == 0) {
841 FrAdcData *adc;
842 if (FrTOCSetPos(stream->handle, ts->position[pos]))
843 goto failure;
844 adc = FrAdcDataRead(stream->handle);
845 if (!adc)
846 goto failure;
847 gtime += adc->timeOffset;
848 //adc->next = NULL;
849 adc->data = FrVectReadNext(stream->handle, gtime, adc->name);
850 if (stream->handle->error != FR_OK)
851 goto failure;
852 channel->handle.adc = adc;
854 return channel;
855 }
856
857 /* scan proc channels */
858 for (ts = toc->proc; ts != NULL; ts = ts->next)
859 if (strcmp(name, ts->name) == 0) {
860 FrProcData *proc;
861 if (FrTOCSetPos(stream->handle, ts->position[pos]))
862 goto failure;
863 proc = FrProcDataRead(stream->handle);
864 if (!proc)
865 goto failure;
866 gtime += proc->timeOffset;
867 proc->next = NULL;
868 proc->data = FrVectReadNext(stream->handle, gtime, proc->name);
869 if (stream->handle->error != FR_OK)
870 goto failure;
871 channel->handle.proc = proc;
873 return channel;
874 }
875
876 /* scan sim channels */
877 for (ts = toc->sim; ts != NULL; ts = ts->next)
878 if (strcmp(name, ts->name) == 0) {
879 FrSimData *sim;
880 if (FrTOCSetPos(stream->handle, ts->position[pos]))
881 goto failure;
882 sim = FrSimDataRead(stream->handle);
883 if (!sim)
884 goto failure;
885 gtime += sim->timeOffset;
886 sim->next = NULL;
887 sim->data = FrVectReadNext(stream->handle, gtime, sim->name);
888 if (stream->handle->error != FR_OK)
889 goto failure;
890 channel->handle.sim = sim;
892 return channel;
893 }
894
895 /* couldn't find channel */
896 failure:
898 if (stream->handle->error == FR_OK)
899 XLAL_ERROR_NULL(XLAL_ENAME, "Channel %s not found", name);
900 else
901 XLAL_ERROR_NULL(XLAL_EIO, "Channel %s could not be read: error code %s", name, XLALFrameLErrorMessage(stream->handle->error));
902}
903
904/* stripped-down copy of FrAdcDataNewF */
905static FrAdcData *XLALFrameUFrAdcDataNew(const char *name, int type)
906{
907 FrAdcData *adcData;
908 adcData = calloc(1, sizeof(*adcData));
909 if (!adcData)
911 adcData->classe = FrAdcDataDef();
912 adcData->name = strdup(name);
913 if (!adcData->name) {
914 FrAdcDataFree(adcData);
916 }
917 switch (type) {
918 case FR_VECT_C:
919 case FR_VECT_1U:
920 adcData->nBits = 8;
921 break;
922 case FR_VECT_2S:
923 case FR_VECT_2U:
924 adcData->nBits = 16;
925 break;
926 case FR_VECT_4R:
927 case FR_VECT_4S:
928 case FR_VECT_4U:
929 adcData->nBits = 32;
930 break;
931 case FR_VECT_8C:
932 case FR_VECT_8R:
933 case FR_VECT_8S:
934 case FR_VECT_8U:
935 adcData->nBits = 64;
936 break;
937 case FR_VECT_16C:
938 adcData->nBits = 128;
939 break;
940 default: /* invalid type */
941 FrAdcDataFree(adcData);
943 }
944 return adcData;
945}
946
947/* stripped-down copy of FrSimDataNew */
948static FrSimData *XLALFrameUFrSimDataNew(const char *name)
949{
950 FrSimData *simData;
951 simData = calloc(1, sizeof(*simData));
952 if (!simData)
954 simData->classe = FrSimDataDef();
955 simData->name = strdup(name);
956 if (!simData->name) {
957 FrSimDataFree(simData);
959 }
960 return simData;
961}
962
963/* stripped-down copy of FrProcDataNew */
964static FrProcData *XLALFrameUFrProcDataNew(const char *name)
965{
966 FrProcData *procData;
967 procData = calloc(1, sizeof(*procData));
968 if (!procData)
970 procData->classe = FrProcDataDef();
971 procData->name = strdup(name);
972 if (!procData->name) {
973 FrProcDataFree(procData);
975 }
976 return procData;
977}
978
979/* helper function to create new channel of appropriate type */
980static LALFrameUFrChan *XLALFrameUFrChanAlloc(const char *name, int chanType, int dataType, size_t ndata)
981{
982 LALFrameUFrChan *channel;
983 channel = LALCalloc(1, sizeof(*channel));
984 if (!channel)
986 channel->type = chanType;
987 switch (chanType) {
989 channel->handle.adc = XLALFrameUFrAdcDataNew(name, dataType);
990 if (!channel->handle.adc) {
993 }
994 break;
996 channel->handle.sim = XLALFrameUFrSimDataNew(name);
997 if (!channel->handle.sim) {
1000 }
1001 break;
1003 channel->handle.proc = XLALFrameUFrProcDataNew(name);
1004 if (!channel->handle.proc) {
1007 }
1008 break;
1009 default: /* unrecognized channel type */
1012 }
1013 if (XLALFrameUFrChanVectorAlloc(channel, dataType, ndata) < 0) {
1016 }
1017 return channel;
1018}
1019
1020LALFrameUFrChan *XLALFrameUFrAdcChanAlloc_FrameL_(const char *name, int dtype, size_t ndata)
1021{
1023}
1024
1025LALFrameUFrChan *XLALFrameUFrSimChanAlloc_FrameL_(const char *name, int dtype, size_t ndata)
1026{
1028}
1029
1030LALFrameUFrChan *XLALFrameUFrProcChanAlloc_FrameL_(const char *name, int type, int subtype, int dtype, size_t ndata)
1031{
1032 LALFrameUFrChan *channel;
1034 if (!channel)
1036 /* set type and subtype metadata */
1037 channel->handle.proc->type = type;
1038 channel->handle.proc->subType = subtype;
1039 return channel;
1040}
1041
1042/* WARNING: returns pointer to memory that is lost when frame is freed */
1043const char *XLALFrameUFrChanQueryName_FrameL_(const LALFrameUFrChan * channel)
1044{
1045 switch (channel->type) {
1047 return channel->handle.adc->name;
1048 break;
1050 return channel->handle.sim->name;
1051 break;
1053 return channel->handle.proc->name;
1054 break;
1055 default: /* unrecognized channel type */
1057 }
1058}
1059
1061{
1062 switch (channel->type) {
1064 return channel->handle.adc->timeOffset;
1065 break;
1067 return channel->handle.sim->timeOffset;
1068 break;
1070 return channel->handle.proc->timeOffset;
1071 break;
1072 default: /* unrecognized channel type */
1074 }
1075}
1076
1077int XLALFrameUFrChanSetSampleRate_FrameL_(LALFrameUFrChan * channel, double sampleRate)
1078{
1079 switch (channel->type) {
1081 channel->handle.adc->sampleRate = sampleRate;
1082 return 0;
1084 channel->handle.sim->sampleRate = sampleRate;
1085 return 0;
1086 case XLAL_FRAMEU_FR_CHAN_TYPE_PROC: /* does not support setting sample rate */
1087 default: /* unrecognized channel type */
1089 }
1090}
1091
1092int XLALFrameUFrChanSetTimeOffset_FrameL_(LALFrameUFrChan * channel, double timeOffset)
1093{
1094 if (timeOffset < 0) /* timeOffset must be non-negative */
1095 XLAL_ERROR(XLAL_EINVAL, "Time offset must be non-negative");
1096 switch (channel->type) {
1098 channel->handle.adc->timeOffset = timeOffset;
1099 return 0;
1101 channel->handle.sim->timeOffset = timeOffset;
1102 return 0;
1104 channel->handle.proc->timeOffset = timeOffset;
1105 return 0;
1106 default: /* unrecognized channel type */
1108 }
1109}
1110
1111int XLALFrameUFrChanSetTRange_FrameL_(LALFrameUFrChan * channel, double tRange)
1112{
1113 if (tRange < 0) /* timeOffset must be non-negative */
1114 XLAL_ERROR(XLAL_EINVAL, "Time range must be non-negative");
1115 switch (channel->type) {
1117 channel->handle.proc->tRange = tRange;
1118 return 0;
1119 default: /* unrecognized channel type */
1121 }
1122}
1123
1124/*
1125 * FrVect functions
1126 */
1127
1128/* helper function to allocate vector in channel */
1129int XLALFrameUFrChanVectorAlloc_FrameL_(LALFrameUFrChan * channel, int dtype, size_t ndata)
1130{
1131 /* make sure we're not trying to allocate too much data:
1132 * the frame library is limited to INT_MAX number of bytes */
1133 size_t bytes;
1134 switch (dtype) {
1135 case FR_VECT_C:
1136 case FR_VECT_1U:
1137 bytes = 1;
1138 break;
1139 case FR_VECT_2S:
1140 case FR_VECT_2U:
1141 bytes = 2;
1142 break;
1143 case FR_VECT_4S:
1144 case FR_VECT_4U:
1145 case FR_VECT_4R:
1146 bytes = 4;
1147 break;
1148 case FR_VECT_8S:
1149 case FR_VECT_8U:
1150 case FR_VECT_8R:
1151 case FR_VECT_8C:
1152 bytes = 8;
1153 break;
1154 case FR_VECT_16C:
1155 bytes = 16;
1156 break;
1157 default: /* invalid vector type */
1159 }
1160 if (ndata * bytes > (size_t)INT_MAX)
1161 XLAL_ERROR(XLAL_ESIZE, "FrameL cannot create FrVect of size %zu bytes (max size = %d bytes)", ndata * bytes, INT_MAX);
1162
1163 switch (channel->type) {
1165 /* determine bits */
1166 switch (dtype) {
1167 case FR_VECT_C:
1168 case FR_VECT_1U:
1169 channel->handle.adc->nBits = 8;
1170 break;
1171 case FR_VECT_2S:
1172 case FR_VECT_2U:
1173 channel->handle.adc->nBits = 16;
1174 break;
1175 case FR_VECT_4R:
1176 case FR_VECT_4S:
1177 case FR_VECT_4U:
1178 channel->handle.adc->nBits = 32;
1179 break;
1180 case FR_VECT_8C:
1181 case FR_VECT_8R:
1182 case FR_VECT_8S:
1183 case FR_VECT_8U:
1184 channel->handle.adc->nBits = 64;
1185 break;
1186 case FR_VECT_16C:
1187 channel->handle.adc->nBits = 128;
1188 break;
1189 default: /* invalid vector type for adc data */
1191 }
1192 /* discard old vector (if present) */
1193 FrVectFree(channel->handle.adc->data);
1194 /* create new vector; note negative type means use malloc, not calloc */
1195 channel->handle.adc->data = FrVectNew1D(channel->handle.adc->name, -dtype, ndata, 0.0, NULL, NULL);
1196 if (!channel->handle.adc->data)
1197 XLAL_ERROR(XLAL_EIO, "FrVectNew1D failed");
1198 break;
1200 /* make sure type is allowed */
1201 switch (dtype) {
1202 case FR_VECT_4S:
1203 case FR_VECT_2S:
1204 case FR_VECT_C:
1205 case FR_VECT_4R:
1206 case FR_VECT_8R:
1207 break;
1208 default: /* invalid vector type for sim data */
1210 }
1211 /* discard old vector (if present) */
1212 FrVectFree(channel->handle.sim->data);
1213 /* create new vector; note negative type means use malloc, not calloc */
1214 channel->handle.sim->data = FrVectNew1D(channel->handle.sim->name, -dtype, ndata, 0.0, NULL, NULL);
1215 if (!channel->handle.sim->data)
1216 XLAL_ERROR(XLAL_EIO, "FrVectNew1D failed");
1217 break;
1219 /* discard old vector (if present) */
1220 FrVectFree(channel->handle.proc->data);
1221 /* create new vector; note negative type means use malloc, not calloc */
1222 channel->handle.proc->data = FrVectNew1D(channel->handle.proc->name, -dtype, ndata, 0.0, NULL, NULL);
1223 if (!channel->handle.proc->data)
1224 XLAL_ERROR(XLAL_EIO, "FrVectNew1D failed");
1225 break;
1226 default: /* invalid channel type */
1228 }
1229 return 0;
1230}
1231
1232/* helper function that gets the FrVect structure from a channel */
1233static FrVect *XLALFrameUFrChanVectorPtr(const LALFrameUFrChan * channel)
1234{
1235 switch (channel->type) {
1237 return channel->handle.adc->data;
1239 return channel->handle.sim->data;
1241 return channel->handle.proc->data;
1242 default: /* unrecognized type */
1244 }
1245}
1246
1247int XLALFrameUFrChanVectorCompress_FrameL_(LALFrameUFrChan * channel, int compressLevel)
1248{
1249 FrVect *vect;
1251 if (!vect)
1253 /* gzip level -1 is default compression */
1254 FrVectCompress(vect, compressLevel, -1);
1255 return 0;
1256}
1257
1259{
1260 FrVect *vect;
1262 if (!vect)
1264 FrVectExpand(vect);
1265 return 0;
1266}
1267
1268/* WARNING: returns pointer to memory that is lost when frame is freed */
1269const char *XLALFrameUFrChanVectorQueryName_FrameL_(const LALFrameUFrChan * channel)
1270{
1271 FrVect *vect;
1273 if (!vect)
1275 return vect->name;
1276}
1277
1279{
1280 FrVect *vect;
1282 if (!vect)
1284 return vect->compress;
1285}
1286
1288{
1289 FrVect *vect;
1291 if (!vect)
1293 return vect->type;
1294}
1295
1296/* retrieves a handle to the data vector in the FrVect structure */
1298{
1299 FrVect *vect;
1301 if (!vect)
1303 return vect->data;
1304}
1305
1307{
1308 FrVect *vect;
1310 if (!vect)
1312 return vect->nBytes;
1313}
1314
1316{
1317 FrVect *vect;
1319 if (!vect)
1321 return vect->nData;
1322}
1323
1325{
1326 FrVect *vect;
1328 if (!vect)
1330 return vect->nDim;
1331}
1332
1333size_t XLALFrameUFrChanVectorQueryNx_FrameL_(const LALFrameUFrChan * channel, size_t dim)
1334{
1335 FrVect *vect;
1337 if (!vect)
1339 if (dim >= vect->nDim)
1340 XLAL_ERROR(XLAL_EINVAL, "dim = %zu out of range", dim);
1341 return vect->nx[dim];
1342}
1343
1344double XLALFrameUFrChanVectorQueryDx_FrameL_(const LALFrameUFrChan * channel, size_t dim)
1345{
1346 FrVect *vect;
1348 if (!vect)
1350 if (dim >= vect->nDim)
1351 XLAL_ERROR_REAL8(XLAL_EINVAL, "dim = %zu out of range", dim);
1352 return vect->dx[dim];
1353}
1354
1355double XLALFrameUFrChanVectorQueryStartX_FrameL_(const LALFrameUFrChan * channel, size_t dim)
1356{
1357 FrVect *vect;
1359 if (!vect)
1361 if (dim >= vect->nDim)
1362 XLAL_ERROR_REAL8(XLAL_EINVAL, "dim = %zu out of range", dim);
1363 return vect->startX[dim];
1364}
1365
1366/* WARNING: returns pointer to memory that is lost when frame is freed */
1367const char *XLALFrameUFrChanVectorQueryUnitX_FrameL_(const LALFrameUFrChan * channel, size_t dim)
1368{
1369 FrVect *vect;
1371 if (!vect)
1373 if (dim >= vect->nDim)
1374 XLAL_ERROR_NULL(XLAL_EINVAL, "dim = %zu out of range", dim);
1375 return vect->unitX[dim];
1376}
1377
1378/* WARNING: returns pointer to memory that is lost when frame is freed */
1379const char *XLALFrameUFrChanVectorQueryUnitY_FrameL_(const LALFrameUFrChan * channel)
1380{
1381 FrVect *vect;
1383 if (!vect)
1385 return vect->unitY;
1386}
1387
1388int XLALFrameUFrChanVectorSetName_FrameL_(LALFrameUFrChan * channel, const char *name)
1389{
1390 FrVect *vect;
1392 if (!vect)
1394 vect->name = strdup(name);
1395 return 0;
1396}
1397
1398int XLALFrameUFrChanVectorSetUnitY_FrameL_(LALFrameUFrChan * channel, const char *unit)
1399{
1400 FrVect *vect;
1402 if (!vect)
1404 vect->unitY = strdup(unit);
1405 return 0;
1406}
1407
1408/* NOTE: only support 1-dimensional vectors */
1409
1410int XLALFrameUFrChanVectorSetDx_FrameL_(LALFrameUFrChan * channel, double dx)
1411{
1412 FrVect *vect;
1414 if (!vect)
1416 vect->dx[0] = dx;
1417 return 0;
1418}
1419
1420int XLALFrameUFrChanVectorSetStartX_FrameL_(LALFrameUFrChan * channel, double x0)
1421{
1422 FrVect *vect;
1424 if (!vect)
1426 vect->startX[0] = x0;
1427 return 0;
1428}
1429
1430int XLALFrameUFrChanVectorSetUnitX_FrameL_(LALFrameUFrChan * channel, const char *unit)
1431{
1432 FrVect *vect;
1434 if (!vect)
1436 vect->unitX[0] = strdup(unit);
1437 return 0;
1438}
1439
1440/*
1441 * FrDetector functions
1442 */
1443
1444void XLALFrameUFrDetectorFree_FrameL_(LALFrameUFrDetector * detector)
1445{
1446 if (detector) {
1447 FrDetectorFree(detector->handle);
1448 LALFree(detector);
1449 }
1450 return;
1451}
1452
1453LALFrameUFrDetector *XLALFrameUFrDetectorRead_FrameL_(LALFrameUFrFile * stream, const char *name)
1454{
1455 LALFrameUFrDetector *detector;
1456 FrTOCdet *d;
1457 for (d = stream->handle->toc->detector; d != NULL; d = d->next)
1458 if (strcmp(d->name, name) == 0) {
1459 char prefix[3];
1460 FrDetector *det;
1461 if (FrTOCSetPos(stream->handle, d->position) != 0)
1462 XLAL_ERROR_NULL(XLAL_EIO, "FrTOCSetPos failed");
1463 det = FrDetectorRead(stream->handle);
1464 prefix[0] = det->prefix[0];
1465 prefix[1] = det->prefix[1];
1466 prefix[2] = 0;
1467 detector =
1468 XLALFrameUFrDetectorAlloc(det->name, prefix, det->latitude,
1469 det->longitude, det->elevation, det->armXazimuth,
1470 det->armYazimuth, det->armXaltitude, det->armYaltitude, det->armXmidpoint, det->armYmidpoint, det->localTime);
1471 return detector;
1472 }
1473 /* didn't find a detector of that name */
1474 XLAL_ERROR_NULL(XLAL_ENAME, "Detector %s not found", name);
1475}
1476
1477LALFrameUFrDetector *XLALFrameUFrDetectorAlloc_FrameL_(const char *name,
1478 const char *prefix, double latitude, double longitude, double elevation,
1479 double azimuthX, double azimuthY, double altitudeX, double altitudeY, double midpointX, double midpointY, int localTime)
1480{
1481 LALFrameUFrDetector *detector;
1482 detector = LALCalloc(1, sizeof(*detector));
1483 if (!detector)
1485 detector->handle = calloc(1, sizeof(*detector->handle));
1486 if (!detector->handle)
1488 detector->handle->classe = FrDetectorDef();
1489 detector->handle->name = strdup(name);
1490 if (!detector->handle->name) {
1491 XLALFrameUFrDetectorFree(detector);
1493 }
1494 if (prefix) {
1495 memcpy(detector->prefix, prefix, 2);
1496 memcpy(detector->handle->prefix, prefix, 2);
1497 }
1498
1499 detector->handle->longitude = longitude; /* longitude (east of greenwich) in radians */
1500 detector->handle->latitude = latitude; /* latitude (north of equator) in radians */
1501 detector->handle->elevation = elevation; /* detector altitude (meter) */
1502 detector->handle->armXazimuth = azimuthX; /* orientation of X arm in radians CW from North */
1503 detector->handle->armYazimuth = azimuthY; /* orientation of Y arm in radians CW from North */
1504 /* Azimuth values should be in the range 0 to 2pi */
1505 detector->handle->armXaltitude = altitudeX; /* altitude (pitch) of the X arm */
1506 detector->handle->armYaltitude = altitudeY; /* altitude (pitch) of the Y arm */
1507 detector->handle->armXmidpoint = midpointX; /* vertex to middle of the X arm distance */
1508 detector->handle->armYmidpoint = midpointY; /* vertex to middle of the Y arm distance */
1509 detector->handle->localTime = localTime; /* local time - UTC time (second) */
1510 return detector;
1511}
1512
1513/* WARNING: returns pointer to memory that is lost when frame is freed */
1514const char *XLALFrameUFrDetectorQueryName_FrameL_(const LALFrameUFrDetector * detector)
1515{
1516 return detector->handle->name;
1517}
1518
1519/* WARNING: returns pointer to memory that is lost when frame is freed */
1520const char *XLALFrameUFrDetectorQueryPrefix_FrameL_(const LALFrameUFrDetector * detector)
1521{
1522 return detector->prefix;
1523}
1524
1525double XLALFrameUFrDetectorQueryLongitude_FrameL_(const LALFrameUFrDetector * detector)
1526{
1527 return detector->handle->longitude;
1528}
1529
1530double XLALFrameUFrDetectorQueryLatitude_FrameL_(const LALFrameUFrDetector * detector)
1531{
1532 return detector->handle->latitude;
1533}
1534
1535double XLALFrameUFrDetectorQueryElevation_FrameL_(const LALFrameUFrDetector * detector)
1536{
1537 return detector->handle->elevation;
1538}
1539
1540double XLALFrameUFrDetectorQueryArmXAzimuth_FrameL_(const LALFrameUFrDetector * detector)
1541{
1542 return detector->handle->armXazimuth;
1543}
1544
1545double XLALFrameUFrDetectorQueryArmYAzimuth_FrameL_(const LALFrameUFrDetector * detector)
1546{
1547 return detector->handle->armYazimuth;
1548}
1549
1550double XLALFrameUFrDetectorQueryArmXAltitude_FrameL_(const LALFrameUFrDetector * detector)
1551{
1552 return detector->handle->armXaltitude;
1553}
1554
1555double XLALFrameUFrDetectorQueryArmYAltitude_FrameL_(const LALFrameUFrDetector * detector)
1556{
1557 return detector->handle->armYaltitude;
1558}
1559
1560double XLALFrameUFrDetectorQueryArmXMidpoint_FrameL_(const LALFrameUFrDetector * detector)
1561{
1562 return detector->handle->armXmidpoint;
1563}
1564
1565double XLALFrameUFrDetectorQueryArmYMidpoint_FrameL_(const LALFrameUFrDetector * detector)
1566{
1567 return detector->handle->armYmidpoint;
1568}
1569
1570int XLALFrameUFrDetectorQueryLocalTime_FrameL_(const LALFrameUFrDetector * detector)
1571{
1572 return detector->handle->localTime;
1573}
1574
1575/*
1576 * FrHistory routines
1577 */
1578
1580{
1581 FrHistoryFree(history);
1582 return;
1583}
1584
1585LALFrameUFrHistory *XLALFrameUFrHistoryAlloc_FrameL_(const char *name, double gpssec, const char *comment)
1586{
1587 FrHistory *history;
1588 history = calloc(1, sizeof(*history));
1589 if (!history)
1591 history->classe = FrHistoryDef();
1592 history->time = floor(gpssec);
1593 if (name && !(history->name = strdup(name))) {
1594 XLALFrameUFrHistoryFree(history);
1596 }
1597 if (!(history->comment = strdup(comment))) {
1598 XLALFrameUFrHistoryFree(history);
1600 }
1601 return history;
1602}
int XLALFrameUFrameHFrHistoryAdd_FrameL_(LALFrameUFrameH *frame, LALFrameUFrHistory *history)
Definition: LALFrameL.c:732
int XLALFrameUFrDetectorQueryLocalTime_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1570
#define P_tmpdir
Definition: LALFrameL.c:37
LALFrameUFrameH * XLALFrameUFrameHRead_FrameL_(LALFrameUFrFile *stream, int pos)
Definition: LALFrameL.c:416
const char * XLALFrameUFrDetectorQueryPrefix_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1520
int XLALFrameUFrameHQueryRun_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:749
#define FR_FILE_HEADER_SIZE
Definition: LALFrameL.c:218
size_t XLALFrameUFrTOCQuerySimN_FrameL_(const LALFrameUFrTOC *toc)
Definition: LALFrameL.c:306
LALFrameUFrFile * XLALFrameUFrFileOpen_FrameL_(const char *filename, const char *mode)
Definition: LALFrameL.c:155
int XLALFrameUFrameHQueryDataQuality_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:759
void XLALFrameUFrTOCFree_FrameL_(UNUSED LALFrameUFrTOC *toc)
Definition: LALFrameL.c:251
void XLALFrameUFrHistoryFree_FrameL_(LALFrameUFrHistory *history)
Definition: LALFrameL.c:1579
int XLALFrameUFileCksumValid_FrameL_(LALFrameUFrFile *stream)
Definition: LALFrameL.c:220
static FrSimData * XLALFrameUFrSimDataNew(const char *name)
Definition: LALFrameL.c:948
const char * XLALFrameUFrTOCQuerySimName_FrameL_(const LALFrameUFrTOC *toc, size_t sim)
Definition: LALFrameL.c:316
int XLALFrameUFrChanVectorCompress_FrameL_(LALFrameUFrChan *channel, int compressLevel)
Definition: LALFrameL.c:1247
static FrSimData * XLALFrSimDataCopy(const FrSimData *original)
Definition: LALFrameL.c:613
int XLALFrameUFrChanVectorQueryCompress_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1278
int XLALFrameUFrameHQueryULeapS_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:771
double XLALFrameUFrDetectorQueryLongitude_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1525
const char * XLALFrameUFrTOCQueryDetectorName_FrameL_(const LALFrameUFrTOC *toc, size_t det)
Definition: LALFrameL.c:360
const char * XLALFrameUFrChanVectorQueryUnitY_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1379
LALFrameUFrameH * XLALFrameUFrameHAlloc_FrameL_(const char *name, double start1, double start2, double dt, int frnum)
Definition: LALFrameL.c:382
const char * XLALFrameUFrChanVectorQueryName_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1269
size_t XLALFrameUFrTOCQueryNFrame_FrameL_(const LALFrameUFrTOC *toc)
Definition: LALFrameL.c:262
const char * XLALFrameUFrChanVectorQueryUnitX_FrameL_(const LALFrameUFrChan *channel, size_t dim)
Definition: LALFrameL.c:1367
int XLALFrameUFrChanVectorExpand_FrameL_(LALFrameUFrChan *channel)
Definition: LALFrameL.c:1258
static FrProcData * XLALFrProcDataCopy(const FrProcData *original)
Definition: LALFrameL.c:541
double XLALFrameUFrameHQueryGTimeModf_FrameL_(double *iptr, const LALFrameUFrameH *frame)
Definition: LALFrameL.c:764
LALFrameUFrDetector * XLALFrameUFrDetectorRead_FrameL_(LALFrameUFrFile *stream, const char *name)
Definition: LALFrameL.c:1453
size_t XLALFrameUFrChanVectorQueryNData_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1315
int XLALFrameUFrameHFrDetectorAdd_FrameL_(LALFrameUFrameH *frame, LALFrameUFrDetector *detector)
Definition: LALFrameL.c:698
LALFrameUFrChan * XLALFrameUFrChanRead_FrameL_(LALFrameUFrFile *stream, const char *name, size_t pos)
Definition: LALFrameL.c:814
void * XLALFrameUFrChanVectorQueryData_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1297
void XLALFrameUFrDetectorFree_FrameL_(LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1444
static FrProcData * XLALFrameUFrProcDataNew(const char *name)
Definition: LALFrameL.c:964
size_t XLALFrameUFrTOCQueryDetectorN_FrameL_(const LALFrameUFrTOC *toc)
Definition: LALFrameL.c:350
double XLALFrameUFrDetectorQueryArmXAltitude_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1550
int XLALFrameUFrChanSetTRange_FrameL_(LALFrameUFrChan *channel, double tRange)
Definition: LALFrameL.c:1111
int XLALFrameUFrChanVectorSetUnitY_FrameL_(LALFrameUFrChan *channel, const char *unit)
Definition: LALFrameL.c:1398
size_t XLALFrameUFrChanVectorQueryNBytes_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1306
double XLALFrameUFrChanVectorQueryStartX_FrameL_(const LALFrameUFrChan *channel, size_t dim)
Definition: LALFrameL.c:1355
double XLALFrameUFrTOCQueryDt_FrameL_(const LALFrameUFrTOC *toc, size_t pos)
Definition: LALFrameL.c:277
double XLALFrameUFrDetectorQueryLatitude_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1530
int XLALFrameUFrChanVectorSetName_FrameL_(LALFrameUFrChan *channel, const char *name)
Definition: LALFrameL.c:1388
static FrAdcData * XLALFrAdcDataCopy(const FrAdcData *original)
Definition: LALFrameL.c:489
LALFrameUFrHistory * XLALFrameUFrHistoryAlloc_FrameL_(const char *name, double gpssec, const char *comment)
Definition: LALFrameL.c:1585
static FrVect * XLALFrameUFrChanVectorPtr(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1233
int XLALFrameUFrChanVectorSetStartX_FrameL_(LALFrameUFrChan *channel, double x0)
Definition: LALFrameL.c:1420
LALFrameUFrChan * XLALFrameUFrProcChanAlloc_FrameL_(const char *name, int type, int subtype, int dtype, size_t ndata)
Definition: LALFrameL.c:1030
@ XLAL_FRAMEU_FR_CHAN_TYPE_ADC
Definition: LALFrameL.c:101
@ XLAL_FRAMEU_FR_CHAN_TYPE_PROC
Definition: LALFrameL.c:101
@ XLAL_FRAMEU_FR_CHAN_TYPE_SIM
Definition: LALFrameL.c:102
double XLALFrameUFrTOCQueryGTimeModf_FrameL_(double *iptr, const LALFrameUFrTOC *toc, size_t pos)
Definition: LALFrameL.c:267
static LALFrameUFrChan * XLALFrameUFrChanAlloc(const char *name, int chanType, int dataType, size_t ndata)
Definition: LALFrameL.c:980
static FrAdcData * XLALFrameUFrAdcDataNew(const char *name, int type)
Definition: LALFrameL.c:905
int XLALFrameUFrChanVectorSetDx_FrameL_(LALFrameUFrChan *channel, double dx)
Definition: LALFrameL.c:1410
int XLALFrameUFrameHSetRun_FrameL_(LALFrameUFrameH *frame, int run)
Definition: LALFrameL.c:783
static int mytmpfd(char *tmpfname)
Definition: LALFrameL.c:132
int XLALFrameUFrameHQueryFrame_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:754
LALFrameUFrChan * XLALFrameUFrSimChanAlloc_FrameL_(const char *name, int dtype, size_t ndata)
Definition: LALFrameL.c:1025
const char * XLALFrameUFrDetectorQueryName_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1514
size_t XLALFrameUFrTOCQueryProcN_FrameL_(const LALFrameUFrTOC *toc)
Definition: LALFrameL.c:328
double XLALFrameUFrChanVectorQueryDx_FrameL_(const LALFrameUFrChan *channel, size_t dim)
Definition: LALFrameL.c:1344
int XLALFrameUFrameHFrChanAdd_FrameL_(LALFrameUFrameH *frame, LALFrameUFrChan *channel)
Definition: LALFrameL.c:665
double XLALFrameUFrDetectorQueryArmXMidpoint_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1560
double XLALFrameUFrChanQueryTimeOffset_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1060
double XLALFrameUFrDetectorQueryArmYAzimuth_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1545
#define BUFSZ
size_t XLALFrameUFrChanVectorQueryNDim_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1324
int XLALFrameUFrameHWrite_FrameL_(LALFrameUFrFile *stream, LALFrameUFrameH *frame)
Definition: LALFrameL.c:443
LALFrameUFrDetector * XLALFrameUFrDetectorAlloc_FrameL_(const char *name, const char *prefix, double latitude, double longitude, double elevation, double azimuthX, double azimuthY, double altitudeX, double altitudeY, double midpointX, double midpointY, int localTime)
Definition: LALFrameL.c:1477
int XLALFrameUFrChanVectorQueryType_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1287
int XLALFrameUFrChanSetTimeOffset_FrameL_(LALFrameUFrChan *channel, double timeOffset)
Definition: LALFrameL.c:1092
void XLALFrameUFrFileClose_FrameL_(LALFrameUFrFile *stream)
Definition: LALFrameL.c:144
LALFrameUFrChan * XLALFrameUFrAdcChanAlloc_FrameL_(const char *name, int dtype, size_t ndata)
Definition: LALFrameL.c:1020
LALFrameUFrTOC * XLALFrameUFrTOCRead_FrameL_(LALFrameUFrFile *stream)
Definition: LALFrameL.c:257
double XLALFrameUFrDetectorQueryArmYAltitude_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1555
double XLALFrameUFrDetectorQueryArmYMidpoint_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1565
static const char * XLALFrameLErrorMessage(FRERROR frerror)
Definition: LALFrameL.c:56
const char * XLALFrameUFrameHQueryName_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:744
@ XLAL_FRAMEU_FR_FILE_MODE_W
Definition: LALFrameL.c:95
@ XLAL_FRAMEU_FR_FILE_MODE_R
Definition: LALFrameL.c:95
size_t XLALFrameUFrTOCQueryAdcN_FrameL_(const LALFrameUFrTOC *toc)
Definition: LALFrameL.c:284
double XLALFrameUFrameHQueryDt_FrameL_(const LALFrameUFrameH *frame)
Definition: LALFrameL.c:776
int XLALFrameUFrChanSetSampleRate_FrameL_(LALFrameUFrChan *channel, double sampleRate)
Definition: LALFrameL.c:1077
size_t XLALFrameUFrChanVectorQueryNx_FrameL_(const LALFrameUFrChan *channel, size_t dim)
Definition: LALFrameL.c:1333
static FrHistory * XLALFrHistoryCopy(const FrHistory *original)
Definition: LALFrameL.c:455
const char * XLALFrameUFrChanQueryName_FrameL_(const LALFrameUFrChan *channel)
Definition: LALFrameL.c:1043
void XLALFrameUFrChanFree_FrameL_(LALFrameUFrChan *channel)
Definition: LALFrameL.c:793
const char * XLALFrameUFrTOCQueryProcName_FrameL_(const LALFrameUFrTOC *toc, size_t proc)
Definition: LALFrameL.c:338
double XLALFrameUFrDetectorQueryArmXAzimuth_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1540
double XLALFrameUFrDetectorQueryElevation_FrameL_(const LALFrameUFrDetector *detector)
Definition: LALFrameL.c:1535
int XLALFrameUFrChanVectorAlloc_FrameL_(LALFrameUFrChan *channel, int dtype, size_t ndata)
Definition: LALFrameL.c:1129
int XLALFrameUFrChanVectorSetUnitX_FrameL_(LALFrameUFrChan *channel, const char *unit)
Definition: LALFrameL.c:1430
const char * XLALFrameUFrTOCQueryAdcName_FrameL_(const LALFrameUFrTOC *toc, size_t adc)
Definition: LALFrameL.c:294
void XLALFrameUFrameHFree_FrameL_(LALFrameUFrameH *frame)
Definition: LALFrameL.c:376
#define LALCalloc(m, n)
#define LALFree(p)
const char *const name
LALFrameUFrDetector * XLALFrameUFrDetectorAlloc(const char *name, const char *prefix, double latitude, double longitude, double elevation, double azimuthX, double azimuthY, double altitudeX, double altitudeY, double midpointX, double midpointY, int localTime)
Allocate memory for a new detector FrDetector structure.
Definition: LALFrameU.c:440
void XLALFrameUFrChanFree(LALFrameUFrChan *channel)
Free a FrChan structure.
Definition: LALFrameU.c:280
void XLALFrameUFrHistoryFree(LALFrameUFrHistory *history)
Free a FrHistory structure.
Definition: LALFrameU.c:508
struct tagLALFrameUFrameH LALFrameUFrameH
Incomplete type for a frame header FrameH structure.
Definition: LALFrameU.h:64
int XLALFrameUFrChanVectorAlloc(LALFrameUFrChan *channel, int dtype, size_t ndata)
Allocate memory for a FrVect structure within a FrChan structure.
Definition: LALFrameU.c:330
struct tagLALFrameUFrHistory LALFrameUFrHistory
Incomplete type for a history data FrHistory structure.
Definition: LALFrameU.h:105
void XLALFrameUFrDetectorFree(LALFrameUFrDetector *detector)
Free a FrDetector structure.
Definition: LALFrameU.c:430
struct tagLALFrameUFrTOC LALFrameUFrTOC
Incomplete type for a table of contents FrTOC structure.
Definition: LALFrameU.h:78
int XLALLeapSeconds(INT4 gpssec)
#define XLAL_ERROR_REAL8(...)
#define XLAL_ERROR_VAL(val,...)
#define XLAL_ERROR_NULL(...)
#define XLAL_ERROR(...)
XLAL_ENOMEM
XLAL_ENAME
XLAL_EFUNC
XLAL_ETYPE
XLAL_ESIZE
XLAL_EIO
XLAL_EINVAL
XLAL_EFAILED
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
REAL8 XLALGPSModf(REAL8 *iptr, const LIGOTimeGPS *epoch)
filename
double dt
Definition: stream.c:110
char * channel
Definition: stream.c:108
Incomplete type for a data channel FrChan structure.
Definition: LALFrameL.c:104
union tagLALFrameUFrChan::@3 handle
FrAdcData * adc
Definition: LALFrameL.c:107
FrSimData * sim
Definition: LALFrameL.c:109
FrProcData * proc
Definition: LALFrameL.c:108
Incomplete type for a detector data FrDetector structure.
Definition: LALFrameC.c:91
FrDetector * handle
Definition: LALFrameL.c:115
Incomplete type for a frame file FrFile stream.
Definition: LALFrameC.c:76
FrFile * handle
Definition: LALFrameL.c:98
FILE * fp
enum @1 epoch