getdate.c   getdate.c 
/* File getdate.c /* File getdate.c
* July 15, 2011 * March 27, 2012
* By Doug Mink, Harvard-Smithsonian Center for Astrophysics * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics
* Send bug reports to dmink@cfa.harvard.edu * Send bug reports to jmink@cfa.harvard.edu
Copyright (C) 1999-2011 Copyright (C) 1999-2012
Smithsonian Astrophysical Observatory, Cambridge, MA USA Smithsonian Astrophysical Observatory, Cambridge, MA USA
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
skipping to change at line 69 skipping to change at line 69
#define DTANG 25 /* Angle in fractional degrees */ #define DTANG 25 /* Angle in fractional degrees */
#define DTHR 26 /* Angle in sexigesimal hours (hh:mm:ss.ss) */ #define DTHR 26 /* Angle in sexigesimal hours (hh:mm:ss.ss) */
#define DTDEG 27 /* Angle in sexigesimal degrees (dd:mm:ss.ss) */ #define DTDEG 27 /* Angle in sexigesimal degrees (dd:mm:ss.ss) */
#define UT 0 #define UT 0
#define ET 1 #define ET 1
#define GST 2 #define GST 2
#define MST 3 #define MST 3
#define LST 4 #define LST 4
static char *RevMsg = "GETDATE WCSTools 3.8.4, 1 September 2011, Doug Mink SAO"; static char *RevMsg = "GETDATE WCSTools 3.8.5, 12 April 2012, Jessica Mink SAO";
static void usage(); static void usage();
static void ConvertDate(); static void ConvertDate();
extern void setdatedec(); extern void setdatedec();
static int verbose = 0; /* Verbose/debugging flag */ static int verbose = 0; /* Verbose/debugging flag */
static int version = 0; /* If 1, print only program name and version */ static int version = 0; /* If 1, print only program name and version */
static int ndec = 5; /* Number of decimal places in output */ static int ndec = 5; /* Number of decimal places in output */
static int dateonly = 0; /* If 1, print date without time */ static int dateonly = 0; /* If 1, print date without time */
static int timeonly = 0; /* If 1, print time without date */ static int timeonly = 0; /* If 1, print time without date */
skipping to change at line 101 skipping to change at line 101
int ac; int ac;
char **av; char **av;
{ {
char *str; char *str;
char *datestring; char *datestring;
char *timestring; char *timestring;
int intype = 0; /* Input date type */ int intype = 0; /* Input date type */
int outtype = 0; /* Output date type */ int outtype = 0; /* Output date type */
int appdate = 0; /* Append date to input file */ int appdate = 0; /* Append date to input file */
int typeset = 0; int typeset = 0;
int ntok = 0;
struct Tokens tokens;
int itok;
int lline; int lline;
char line[82]; char line[82];
FILE *fd; FILE *fd;
datestring = NULL; datestring = NULL;
timestring = NULL; timestring = NULL;
outform0 = NULL; outform0 = NULL;
if (ac == 1) if (ac == 1)
usage (); usage ();
skipping to change at line 250 skipping to change at line 253
outtype = DTET; outtype = DTET;
if (intype > 0 || outtype > 0) { if (intype > 0 || outtype > 0) {
typeset = 1; typeset = 1;
continue; continue;
} }
} }
/* Set RA, Dec, and equinox if WCS-generated argument */ /* Set RA, Dec, and equinox if WCS-generated argument */
if (ac > 3 && if (ac > 3 &&
strsrch (*av,":") != NULL && strsrch (*(av+1),":") != NULL strsrch (*av,":") != NULL && strsrch (*(av+1),":") != NULL &&
&& (strcsrch(*(av+2),"j")!=NULL || strcsrch(*(av+2),"b")!=NULL)) {
(strcsrch(*(av+2),"j")!=NULL || strcsrch(*(av+2),"b")!=NULL ra = str2ra (*av);
)) { ac--;
if (ac < 3) dec = str2dec (*++av);
usage(); ac--;
else { coorsys = wcscsys (*++av);
ra = str2ra (*av);
ac--;
dec = str2dec (*++av);
ac--;
coorsys = wcscsys (*++av);
}
} }
/* Read command line parameters */ /* Read command line parameters */
else if (*(str = *av) == '-' && !isdate(*av) && !isnum(*av)) { else if (*(str = *av) == '-' && !isdate(*av) && !isnum(*av)) {
char c; char c;
while ((c = *++str)) while ((c = *++str))
switch (c) { switch (c) {
case 'a': /* Append date to input file */ case 'a': /* Append date to input file */
appdate++; appdate++;
skipping to change at line 338 skipping to change at line 337
fd = stdin; fd = stdin;
else if (!(fd = fopen (str+1, "r"))) { else if (!(fd = fopen (str+1, "r"))) {
if (verbose) if (verbose)
fprintf (stderr, "*** Cannot read file %s\n", str+1) ; fprintf (stderr, "*** Cannot read file %s\n", str+1) ;
return (-1); return (-1);
} }
datestring = (char *) calloc (80,1); datestring = (char *) calloc (80,1);
timestring = (char *) calloc (80,1); timestring = (char *) calloc (80,1);
while (fgets (line, 80, fd)) { while (fgets (line, 80, fd)) {
lline = strlen (line); lline = strlen (line);
if ((int)line[lline-1] < 32) ntok = setoken (&tokens, line, NULL);
line[lline-1] = (char) 0;
/* Set RA, Dec, and equinox if WCS-generated argument */
if (ntok > 3 &&
strnsrch (tokens.tok1[0],":",tokens.ltok[0])!=NULL &
&
strnsrch (tokens.tok1[1],":",tokens.ltok[1])!=NULL &
&
(strncsrch (tokens.tok1[2],"j",tokens.ltok[1])!=NULL
||
strncsrch (tokens.tok1[2],"b",tokens.ltok[1])!=NULL)
){
ra = str2ra (tokens.tok1[0]);
dec = str2dec (tokens.tok1[1]);
coorsys = wcscsys (tokens.tok1[2]);
itok = 3;
}
else
itok = 0;
if (appdate) if (appdate)
printf ("%s ", line); printf ("%s ", line);
if (nftok > 1) if (nftok > 1) {
sscanf (line, "%s %s", datestring, timestring); strncpy (datestring, tokens.tok1[itok],tokens.ltok[i
else tok]);
sscanf (line, "%s", datestring); datestring[tokens.ltok[itok]] = (char) 0;
itok++;
strncpy (timestring, tokens.tok1[itok],tokens.ltok[i
tok]);
timestring[tokens.ltok[itok]] = (char) 0;
}
else {
strncpy (datestring, tokens.tok1[itok],tokens.ltok[i
tok]);
datestring[tokens.ltok[itok]] = (char) 0;
}
ConvertDate (intype, outtype, datestring, timestring); ConvertDate (intype, outtype, datestring, timestring);
} }
free (datestring); free (datestring);
free (timestring); free (timestring);
} }
} }
else if (datestring == NULL) { else if (datestring == NULL) {
datestring = *av; datestring = *av;
if (ac > 1 && isdate (datestring) == 1) { if (ac > 1 && isdate (datestring) == 1) {
skipping to change at line 402 skipping to change at line 421
} }
static void static void
usage () usage ()
{ {
fprintf (stderr,"%s\n", RevMsg); fprintf (stderr,"%s\n", RevMsg);
if (version) if (version)
exit (-1); exit (-1);
fprintf (stderr,"Convert date and time between various formats\n"); fprintf (stderr,"Convert date and time between various formats\n");
fprintf (stderr,"Usage: [-dv][-n dec][-f format] itype2otype [date and/ or time] [ra dec sys]\n"); fprintf (stderr,"Usage: [-dv][-n dec][-f format] [ra dec sys] itype2oty pe [date and/or time]\n");
fprintf (stderr," [-dv][-n dec][-f format] itype2otype @file\n"); fprintf (stderr," [-dv][-n dec][-f format] itype2otype @file\n");
fprintf(stderr," itype: nfd=ISOFITS fd=FITS, dt=yyyy.mmdd, hr=hh:mm:ss , deg=dd:mm:ss\n"); fprintf(stderr," itype: nfd=ISOFITS fd=FITS, dt=yyyy.mmdd, hr=hh:mm:ss , deg=dd:mm:ss\n");
fprintf(stderr," jd=Julian Date, mjd=Modified Julian Date\n"); fprintf(stderr," jd=Julian Date, mjd=Modified Julian Date\n");
fprintf(stderr," hjd=Heliocentric Julian Date, mhjd=Modified HJ D\n"); fprintf(stderr," hjd=Heliocentric Julian Date, mhjd=Modified HJ D\n");
fprintf(stderr," ep=epoch, epj=Julian epoch, epb=Besselian epoc h\n"); fprintf(stderr," ep=epoch, epj=Julian epoch, epb=Besselian epoc h\n");
fprintf(stderr," lt=local time, ut=UT, ts=seconds since 1950-01 -01\n"); fprintf(stderr," lt=local time, ut=UT, ts=seconds since 1950-01 -01\n");
fprintf(stderr," now=current time, ang=fractional degrees\n"); fprintf(stderr," now=current time, ang=fractional degrees\n");
fprintf(stderr," otype: fd=FITS, dt=yyyy.mmdd, jd=Julian Date, mjd=Mod ified Julian Date\n"); fprintf(stderr," otype: fd=FITS, dt=yyyy.mmdd, jd=Julian Date, mjd=Mod ified Julian Date\n");
fprintf(stderr," hjd=Heliocentric Julian Date, mhjd=Modified HJ D\n"); fprintf(stderr," hjd=Heliocentric Julian Date, mhjd=Modified HJ D\n");
fprintf(stderr," hr=hh:mm:ss, deg=dd:mm:ss, ang=fractional degr ees\n"); fprintf(stderr," hr=hh:mm:ss, deg=dd:mm:ss, ang=fractional degr ees\n");
skipping to change at line 447 skipping to change at line 466
{ {
double vdate, vtime, epoch, jd, ts, jd1, ts1, epoch1; double vdate, vtime, epoch, jd, ts, jd1, ts1, epoch1;
double doy, vdoy; double doy, vdoy;
int year, vyear; int year, vyear;
int lfd, oldfits; int lfd, oldfits;
char outform[16]; char outform[16];
char *fitsdate, *newfdate, *stdate; char *fitsdate, *newfdate, *stdate;
char temp[64]; char temp[64];
char fyear[16]; char fyear[16];
char ts0[8]; char ts0[16];
char *tchar; char *tchar;
int its, its1; int its, its1;
time_t lts; time_t lts;
strcpy (ts0, "00:00:00"); strcpy (ts0, "00:00:00");
if (outform0 == NULL) { if (outform0 == NULL) {
if (outtype == DTUNIX || outtype == DTIRAF) if (outtype == DTUNIX || outtype == DTIRAF)
strcpy (outform,"%d\n"); strcpy (outform,"%d\n");
else else
sprintf (outform,"%%.%df\n",ndec); sprintf (outform,"%%.%df\n",ndec);
skipping to change at line 570 skipping to change at line 589
default: default:
printf ("*** Unknown output type %d\n", outtype); printf ("*** Unknown output type %d\n", outtype);
} }
break; break;
/* Vigesimal date and time (yyyy.mmdd hh.mmssss) */ /* Vigesimal date and time (yyyy.mmdd hh.mmssss) */
case DTVIG: case DTVIG:
if (datestring != NULL) { if (datestring != NULL) {
if (strcmp (datestring, "now")) { if (strcmp (datestring, "now")) {
vdate = atof (datestring); vdate = atof (datestring);
if (vdate > 9999.0)
vdate = floor (vdate) * 0.0001;
if (timestring != NULL) if (timestring != NULL)
vtime = atof (timestring); vtime = atof (timestring);
else { else {
timestring = ts0; timestring = ts0;
vtime = 0.0; vtime = 0.0;
} }
} }
if (verbose) if (verbose)
printf ("%s %s -> ", datestring, timestring); printf ("%s %s -> ", datestring, timestring);
skipping to change at line 2258 skipping to change at line 2279
* Jan 10 2007 Fix unix time output format * Jan 10 2007 Fix unix time output format
* Dec 12 2007 Implement time only output for all 2FD options * Dec 12 2007 Implement time only output for all 2FD options
* *
* Jul 28 2008 Fix file input problems for vigesimal date/time strings * Jul 28 2008 Fix file input problems for vigesimal date/time strings
* Jul 28 2008 Fix time system conversion but for vigesimal date/time strin gs * Jul 28 2008 Fix time system conversion but for vigesimal date/time strin gs
* Sep 8 2008 Add vigesimal hour and degree to fractional degree conversio ns * Sep 8 2008 Add vigesimal hour and degree to fractional degree conversio ns
* Apr 6 2009 Fix bug so positions after FITS ISO dates are read correctly * Apr 6 2009 Fix bug so positions after FITS ISO dates are read correctly
* *
* Jul 14 2011 Print correct help hjd instead of jhd * Jul 14 2011 Print correct help hjd instead of jhd
* Jul 15 2011 Fix bug so ST's print as time only withoug preceding junk * Jul 15 2011 Fix bug so ST's print as time only withoug preceding junk
*
* Jan 24 2012 Add scale factor to convert date RFN's to DT date
* Feb 15 2012 Add option to read ra dec sys before time from file
* Mar 27 2012 Fix bug copying string to ts0 found by Michal Szymanski
*/ */
 End of changes. 11 change blocks. 
26 lines changed or deleted 56 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/