TestDateString.c

Go to the documentation of this file.
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 #include <stdio.h>
00021 #include <math.h>
00022 #include <stdlib.h>
00023 #ifndef _REENTRANT
00024 #define _REENTRANT
00025 #endif
00026 #ifndef __USE_POSIX
00027 #define __USE_POSIX
00028 #endif
00029 #include <time.h>
00030 
00031 #include <lal/LALStdlib.h>
00032 #include <lal/Date.h>
00033 #include <lal/AVFactories.h>
00034 
00035 INT4 lalDebugLevel = 0;
00036 
00037 NRCSID (LALTESTDATESTRINGC, "$Id: TestDateString.c,v 1.11 2007/06/08 14:41:43 bema Exp $");
00038 
00039 int main(int argc, char **argv)
00040 {
00041     static LALStatus stat;
00042     time_t           tmpsecs;
00043     LALDate          date;
00044     CHAR             refstamp[128];
00045     CHARVector      *timestamp = NULL;
00046 
00047     if (argc > 1)
00048       lalDebugLevel = atoi(argv[1]);
00049 
00050     LALCHARCreateVector(&stat, &timestamp, (UINT4)64);
00051 
00052     if (stat.statusCode && lalDebugLevel > 0)
00053       {
00054         fprintf(stderr,
00055                 "TestDateString: error in LALCHARCreateVector, line %i, %s\n",
00056                 __LINE__, LALTESTDATESTRINGC);
00057         REPORTSTATUS(&stat);
00058         return stat.statusCode;
00059       }
00060     if (lalDebugLevel > 2)
00061       REPORTSTATUS(&stat);
00062         
00063     tmpsecs = (24*365 + 8*366 + 2*31 + 28)*86400 - 1;
00064     gmtime_r(&tmpsecs, &(date.unixDate));
00065 
00066     LALDateString(&stat, timestamp, &date);
00067     
00068     if (stat.statusCode && lalDebugLevel > 0)
00069       {
00070         fprintf(stderr,
00071                 "TestDateString: LALDateString() failed, line %i, %s\n",
00072                 __LINE__, LALTESTDATESTRINGC);
00073         REPORTSTATUS(&stat);
00074         return stat.statusCode;
00075       }
00076 
00077     if (!stat.statusCode)
00078       {
00079         sprintf(refstamp, "2002-03-31 23:59:59 UTC Sun");
00080         if (lalDebugLevel > 2)
00081           {
00082             fprintf(stderr, "refstamp  = %s\n", refstamp);
00083             fprintf(stderr, "timestamp = %s\n", timestamp->data);
00084           }
00085       }
00086 
00087     if (strcmp(refstamp, timestamp->data) == 0)
00088       {
00089         LALCHARDestroyVector(&stat, &timestamp);
00090         if (lalDebugLevel > 2)
00091           REPORTSTATUS(&stat);
00092         LALCheckMemoryLeaks();
00093         return 0;
00094       }
00095     else
00096       {
00097         LALCHARDestroyVector(&stat, &timestamp);
00098         REPORTSTATUS(&stat);
00099         LALCheckMemoryLeaks();
00100         return 1;
00101       }
00102 }

Generated on Fri Aug 29 02:49:29 2008 for LAL by  doxygen 1.5.2