00001 /* 00002 * Copyright (C) 2007 David Chin, Jolien Creighton 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="SecsToLALDateCV"> 00021 Author: David Chin <dwchin@umich.edu> +1-734-709-9119 00022 $Id: SecsToLALDate.c,v 1.11 2007/06/08 14:41:43 bema Exp $ 00023 </lalVerbatim> */ 00024 00025 /* <lalLaTeX> 00026 00027 \subsection{Module \texttt{SecsToLALDate.c}} 00028 \label{ss:SecsToLALDate.c} 00029 00030 Converts time in seconds to time in an \texttt{LALDate} structure. 00031 00032 \subsection*{Prototypes} 00033 \vspace{0.1in} 00034 00035 \input{SecsToLALDateCP} 00036 \idx{LALSecsToLALDate()} 00037 00038 \subsubsection*{Description} 00039 00040 This routine converts a time of day in decimal seconds since 0h (midnight) 00041 to an LALDate structure. Of course, the date information is not present. 00042 00043 00044 \subsubsection*{Algorithms} 00045 00046 \subsubsection*{Uses} 00047 00048 A simple example: 00049 00050 \begin{verbatim} 00051 #include <stdlib.h> 00052 #include <lal/LALStdlib.h> 00053 #include <lal/Date.h> 00054 00055 INT4 debuglevel = 2; 00056 00057 NRCSID (TESTLMSTC, "Id"); 00058 00059 int 00060 main(int argc, char *argv[]) 00061 { 00062 LALDate date; 00063 LALDate mstdate; 00064 REAL8 gmstsecs; 00065 CHAR timestamp[64], tmpstr[64]; 00066 Status status = {0}; 00067 00068 00069 INITSTATUS(&status, "TestLMST", TESTLMSTC); 00070 00071 printf("TEST of GMST1 routine\n"); 00072 printf("=====================\n"); 00073 00074 date.unixDate.tm_sec = 0; 00075 date.unixDate.tm_min = 0; 00076 date.unixDate.tm_hour = 0; 00077 date.unixDate.tm_mday = 16; 00078 date.unixDate.tm_mon = LALMONTH_NOV; 00079 date.unixDate.tm_year = 94; 00080 00081 GMST1(&status, &gmstsecs, &date, MST_SEC); 00082 SecsToLALDate(&status, &mstdate, gmstsecs); 00083 strftime(timestamp, 64, "%Hh %Mm %S", &(mstdate.unixDate)); 00084 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9); 00085 strcat(timestamp, tmpstr+1); 00086 00087 printf("gmst = %s\n", timestamp); 00088 printf(" expect: 03h 39m 20.6222s \n"); 00089 00090 return(0); 00091 } 00092 00093 \end{verbatim} 00094 00095 \subsubsection*{Notes} 00096 00097 </lalLaTeX> */ 00098 00099 00100 /*----------------------------------------------------------------------- 00101 * 00102 * SYNOPSIS 00103 * 00104 * LALSecsToLALDate(): Converts time in seconds to time in an LALDate 00105 * structure. 00106 * 00107 * DESCRIPTION 00108 * 00109 * LALSecsToLALDate(): 00110 * Inputs: REAL8 seconds -- time in seconds since 0h (midnight) 00111 * 00112 * Outputs: LALDate *date -- time in LALDate structure. Of course, 00113 * only the hour, min, and sec fields are 00114 * set since there is no information on 00115 * the date, timezone, etc. 00116 * 00117 * DIAGNOSTICS 00118 * (Abnormal termination conditions, error and warning codes summarized 00119 * here. More complete descriptions are found in documentation.) 00120 * 00121 * CALLS 00122 * 00123 * NOTES 00124 * 00125 *----------------------------------------------------------------------- */ 00126 00127 #include <lal/LALRCSID.h> 00128 00129 NRCSID (SECSTOLALDATEC, "$Id: SecsToLALDate.c,v 1.11 2007/06/08 14:41:43 bema Exp $"); 00130 00131 #include <math.h> 00132 #include <lal/Date.h> 00133 #include "date_value.h" 00134 00135 /* 00136 * Convert time in seconds to LALDate struct 00137 */ 00138 00139 /* <lalVerbatim file="SecsToLALDateCP"> */ 00140 void 00141 LALSecsToLALDate(LALStatus *status, 00142 LALDate *date, /* output - date */ 00143 REAL8 seconds) /* input - time in seconds since 0h */ 00144 { /* </lalVerbatim> */ 00145 REAL8 hr, min, sec; 00146 REAL8 tmpsec; 00147 REAL8 dum; 00148 00149 INITSTATUS (status, "SECSTOLALDATE", SECSTOLALDATEC); 00150 00151 /* 00152 * Check pointer to output variable 00153 */ 00154 ASSERT (date != (LALDate *)NULL, status, 00155 DATEH_ENULLOUTPUT, DATEH_MSGENULLOUTPUT); 00156 00157 /* 00158 * Make sure time is positive, i.e. seconds == #secs since 0h 00159 */ 00160 tmpsec = fmod(seconds, (REAL8)SECS_PER_DAY); 00161 while (tmpsec < 0) 00162 tmpsec += (REAL8)SECS_PER_DAY; 00163 00164 hr = tmpsec / (REAL8)SECS_PER_HOUR; 00165 min = fmod(hr * (REAL8)MINS_PER_HOUR, (REAL8)MINS_PER_HOUR); 00166 sec = fmod(min * (REAL8)SECS_PER_MIN, (REAL8)SECS_PER_MIN); 00167 00168 /* 00169 * Set the non-required fields to zero 00170 */ 00171 date->unixDate.tm_mday = 0; 00172 date->unixDate.tm_mon = LALMONTH_JAN; 00173 date->unixDate.tm_year = 0; 00174 date->unixDate.tm_wday = 0; 00175 date->unixDate.tm_yday = 0; 00176 date->unixDate.tm_isdst = 0; 00177 00178 00179 /* 00180 * Set the LALDate structure. Only the time fields matter, of course. 00181 * Fractional seconds become "residual". 00182 */ 00183 date->unixDate.tm_hour = (INT4)hr; 00184 date->unixDate.tm_min = (INT4)min; 00185 date->unixDate.tm_sec = (INT4)sec; 00186 date->residualNanoSeconds = modf(sec, &dum) * 1.e+09; 00187 00188 00189 RETURN (status); 00190 } /* END LALSecsToLALDate() */
1.5.2