GPSTimeNow.c

Go to the documentation of this file.
00001 /*
00002  * $Id: GPSTimeNow.c,v 1.5 2008/04/29 21:30:15 kipp Exp $
00003  *
00004  * Copyright (C) 2007  Brown, D. A., and Kipp Cannon
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU General Public License as published by the
00008  * Free Software Foundation; either version 2 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
00014  * Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 
00022 #if 0
00023 <lalVerbatim file="GPSTimeNowCV">
00024 Author: Duncan Brown
00025 $Id: GPSTimeNow.c,v 1.5 2008/04/29 21:30:15 kipp Exp $
00026 </lalVerbatim>
00027 
00028 <lalLaTeX>
00029 \subsection{Module \texttt{GPSTimeNow.c}}
00030 \label{ss:GPSTimeNow.c}
00031 
00032 Routine to convert the current unix system clock time into a
00033 \texttt{LIGOTimeGPS} structure.
00034 
00035 \subsection*{Prototypes}
00036 \vspace{0.1in}
00037 \input{GPSTimeNowCP}
00038 \idx{LALGPSTimeNow()}
00039 
00040 \subsubsection*{Description}
00041 
00042 This module contains a single funtion that converts the current unix system
00043 time as returned by the \texttt{time()} function to GPS seconds. The leap
00044 second accuracy is determined by the \texttt{accuracy} argument.
00045 
00046 \subsubsection*{Algorithm}
00047 
00048 \subsubsection*{Uses}
00049 
00050 \subsubsection*{Notes}
00051 
00052 If the system clock time is incorect, the returned GPS time will obviously be
00053 wrong by the same amount.
00054 
00055 \vfill{\footnotesize\input{GPSTimeNowCV}}
00056 </lalLaTeX>
00057 #endif
00058 
00059 #include <time.h>
00060 #include <lal/Date.h>
00061 #include <lal/XLALError.h>
00062 
00063 NRCSID( GPSTIMENOWC, "$Id: GPSTimeNow.c,v 1.5 2008/04/29 21:30:15 kipp Exp $" );
00064 
00065 /* <lalVerbatim file="GPSTimeNowCP"> */
00066 LIGOTimeGPS *
00067 XLALGPSTimeNow (
00068     LIGOTimeGPS *gpstime
00069     )
00070 /* </lalVerbatim> */
00071 {
00072   static const char func[] = "XLALGPSTimeNow";
00073   time_t ticks = time(NULL);
00074 
00075   gpstime->gpsSeconds = XLALUTCToGPS(gmtime(&ticks));
00076   gpstime->gpsNanoSeconds = 0;
00077 
00078   /* XLALUTCToGPS returns < 0 on error, even though of course time did not
00079    * begin at GPS 0 */
00080   if(gpstime->gpsSeconds < 0)
00081     XLAL_ERROR_NULL(func, XLAL_EFUNC);
00082 
00083   return gpstime;
00084 }
00085 
00086 
00087 /* <lalVerbatim file="GPSTimeNowCP"> */
00088 void
00089 LALGPSTimeNow (
00090     LALStatus           *status,
00091     LIGOTimeGPS         *gpstime,
00092     const LALLeapSecAccuracy  *accuracy
00093     )
00094 /* </lalVerbatim> */
00095 {
00096   INITSTATUS( status, "LALGPSTimeNow", GPSTIMENOWC );
00097   ATTATCHSTATUSPTR( status );
00098   ASSERT( gpstime, status, DATEH_ENULLOUTPUT, DATEH_MSGENULLOUTPUT );
00099   ASSERT( accuracy, status, DATEH_ENULLINPUT, DATEH_MSGENULLINPUT );
00100   
00101   ASSERT( XLALGPSTimeNow(gpstime), status, DATEH_EDATETOOEARLY, DATEH_MSGEDATETOOEARLY );
00102 
00103   XLALPrintDeprecationWarning("LALGPSTimeNow", "XLALGPSTimeNow");
00104   
00105   DETATCHSTATUSPTR( status );
00106   RETURN( status );
00107 }

Generated on Sat Sep 6 03:07:01 2008 for LAL by  doxygen 1.5.2