GPStoFloat.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 David Chin, Jolien Creighton, Kipp Cannon, Reinhard Prix
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /* <lalVerbatim file="GPStoFloatCV">
00021    
00022 Author: Berukoff, S.J.  <steveb@aei-potsdam.mpg.de>
00023 $Id: GPStoFloat.c,v 1.12 2008/04/30 19:02:22 kipp Exp $
00024 
00025 </lalVerbatim> */
00026 
00027 /* <lalLaTeX>
00028 
00029 \subsection{Module \texttt{GPStoFloat.c}}
00030 \label{ss:GPStoFloat.c}
00031 
00032 Converts between \texttt{LIGOTimeGPS} and \texttt{REAL8} formats, and also
00033 to/from \texttt{LALTimeInterval} and \texttt{REAL8} formats.
00034 
00035 
00036 \subsection*{Prototypes}
00037 \vspace{0.1in}
00038 \input{GPStoFloatCP}
00039 \idx{LALGPStoFloat()}
00040 \idx{LALFloatToGPS()}
00041 \idx{LALFloatToInterval()}
00042 \idx{LALIntervalToFloat()}
00043 
00044 \subsubsection*{Description}
00045 
00046 This modules contains two routines, one of which converts from 
00047 \texttt{LIGOTimeGPS} to \texttt{REAL8}, and the other, from 
00048 \texttt{REAL8} to \texttt{LIGOTimeGPS}.  Accuracy is on par with what one
00049 expects from a typical IEEE-compliant machine epsilon; thus, conversion 
00050 into the \texttt{REAL8} values incurs an error of approximately 1.e-7.
00051 
00052 \begin{itemize}
00053   \item \texttt{LALGPStoFloat()} converts a \texttt{LIGOTimeGPS} to \texttt{REAK8}
00054   \item \texttt{LALFloatToGPS()} converts a time in \texttt{REAL8} to a \texttt{LIGOTimeGPS}
00055   \item \texttt{LALFloatToInterval()} converts a time interval in \texttt{REAL8} to a \texttt{LALTimeInterval}
00056   \item \texttt{LALIntervalToFloat()} converts a time interval in \texttt{LALTimeInterval} to \texttt{REAL8}
00057 \end{itemize}
00058 
00059 \subsubsection*{Algorithm}
00060 
00061 \subsubsection*{Uses}
00062 
00063 \subsubsection*{Notes}
00064 
00065 \vfill{\footnotesize\input{GPStoFloatCV}}
00066 
00067 </lalLaTeX> */
00068 
00069 #include <math.h>
00070 
00071 #include "Date.h"
00072 
00073 NRCSID(GPSTOFLOATC, "$Id: GPStoFloat.c,v 1.12 2008/04/30 19:02:22 kipp Exp $");
00074 
00075 /* D'oh. rint(3) is not in the ANSI std. Thanks Jolien. */
00076 #define rint(x) floor(0.5 + (x))
00077 
00078 static const INT4 oneBillion = 1000000000;
00079 
00080 /* <lalVerbatim file="GPStoFloatCP"> */
00081 void
00082 LALGPStoFloat( LALStatus         *stat,
00083                REAL8             *p_flt_time, /* output - floating point GPS seconds */
00084                const LIGOTimeGPS *p_gps_time) /* input - GPS seconds */
00085 {  /* </lalVerbatim> */
00086   INITSTATUS(stat, "GPStoFloat", GPSTOFLOATC);
00087   ATTATCHSTATUSPTR(stat);
00088 
00089   ASSERT(p_gps_time != NULL, stat, DATEH_ENULLINPUT,
00090          DATEH_MSGENULLINPUT);
00091 
00092   ASSERT(p_flt_time != NULL, stat, DATEH_ENULLOUTPUT,
00093          DATEH_MSGENULLOUTPUT);
00094 
00095   XLALPrintDeprecationWarning("LALGPStoFloat", "XLALGPSGetREAL8");
00096 
00097   *p_flt_time = XLALGPSGetREAL8(p_gps_time);
00098 
00099   DETATCHSTATUSPTR(stat);  
00100   RETURN(stat);
00101 }  /* END: GPStoFloat() */
00102 
00103 
00104 /* <lalVerbatim file="GPStoFloatCP"> */
00105 void
00106 LALFloatToGPS( LALStatus   *stat,
00107                LIGOTimeGPS *p_gps_time,  /* output - GPS time */
00108                const REAL8 *p_flt_time)  /* input - floating point GPS seconds */
00109 {  /* </lalVerbatim> */
00110   INITSTATUS(stat, "LALFloatToGPS", GPSTOFLOATC);
00111   ATTATCHSTATUSPTR(stat);
00112   
00113   ASSERT(p_flt_time != NULL, stat, DATEH_ENULLINPUT, DATEH_MSGENULLINPUT);
00114   ASSERT(p_gps_time != NULL, stat, DATEH_ENULLINPUT, DATEH_MSGENULLINPUT);
00115 
00116   XLALPrintDeprecationWarning("LALFloatToGPS", "XLALGPSSetREAL8");
00117 
00118   XLALGPSSetREAL8(p_gps_time, *p_flt_time);
00119 
00120   DETATCHSTATUSPTR(stat);
00121   RETURN(stat);
00122 }  /* END: FloatToGPS() */
00123 
00124   
00125 
00126 
00127 /* <lalVerbatim file="GPStoFloatCP"> */
00128 void LALFloatToInterval(LALStatus *status,
00129                         LALTimeInterval *pInterval,  /* output: deltaT in LALTimeInterval format */
00130                         const REAL8 *pDeltaT) /* input: time interval in floating point */
00131 {  /* </lalVerbatim> */
00132   INITSTATUS(status, "LALFloatToInterval", GPSTOFLOATC);
00133   ATTATCHSTATUSPTR(status);
00134 
00135   ASSERT(pInterval, status, DATEH_ENULLOUTPUT, DATEH_MSGENULLOUTPUT);
00136   ASSERT(pDeltaT, status, DATEH_ENULLINPUT, DATEH_MSGENULLINPUT);
00137 
00138   pInterval->seconds     = (INT4)(*pDeltaT);
00139   pInterval->nanoSeconds = (INT4)rint((*pDeltaT -
00140                                        (REAL8)(pInterval->seconds)) *
00141                                       (REAL8)oneBillion);
00142   
00143   
00144   DETATCHSTATUSPTR(status);
00145   RETURN(status);
00146 } /* END: FloatToInterval() */
00147 
00148 
00149 
00150 
00151 /* <lalVerbatim file="GPStoFloatCP"> */
00152 void LALIntervalToFloat(LALStatus *status,
00153                         REAL8 *pDeltaT,    /* output: floating point time interval */
00154                         const LALTimeInterval *pInterval) /* input: LALTimeInterval */
00155 { /* </lalVerbatim> */
00156   INITSTATUS(status, "LALIntervalToFloat", GPSTOFLOATC);
00157   ATTATCHSTATUSPTR(status);
00158 
00159   ASSERT(pDeltaT, status, DATEH_ENULLOUTPUT, DATEH_MSGENULLOUTPUT);
00160   ASSERT(pInterval, status, DATEH_ENULLINPUT, DATEH_MSGENULLINPUT);
00161 
00162   *pDeltaT = (REAL8)(pInterval->seconds) +
00163     ((REAL8)(pInterval->nanoSeconds) / (REAL8)oneBillion);
00164   
00165   DETATCHSTATUSPTR(status);
00166   RETURN(status);
00167 }

Generated on Thu Aug 21 03:12:36 2008 for LAL by  doxygen 1.5.2