-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
617 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,10 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
tjdtodate | ||
*~ | ||
*.1 | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
fixxyplots.sh | ||
unixtodate | ||
datetounix | ||
datetomjd | ||
mjdtodate | ||
wintounix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
PROGRAMS = tjdtodate unixtodate datetounix mjdtodate datetomjd wintounix | ||
|
||
OBJECTS = $(PROGRAMS:=.o) | ||
MANPAGES = $(PROGRAMS:=.1) | ||
|
||
DESTBIN = $(HOME)/bin | ||
DESTMAN = $(HOME)/man/man1 | ||
|
||
all: $(PROGRAMS) | ||
$(MAKE) man | ||
|
||
man: $(MANPAGES) | ||
|
||
$(MANPAGES): $(PROGRAMS) | ||
pod2man -c "Date utilities" $(@:.1=.c) $@ | ||
|
||
tjdtodate: tjdtodate.c | ||
gcc -o tjdtodate -g -Wall tjdtodate.c | ||
|
||
unixtodate: unixtodate.c | ||
gcc -o unixtodate -g -Wall unixtodate.c | ||
|
||
datetounix: datetounix.c | ||
gcc -o datetounix -g -Wall datetounix.c | ||
|
||
mjdtodate: mjdtodate.c | ||
gcc -o mjdtodate -g -Wall mjdtodate.c | ||
|
||
datetomjd: datetomjd.c | ||
gcc -o datetomjd -g -Wall datetomjd.c | ||
|
||
wintounix: wintounix.c | ||
gcc -o wintounix -g -Wall wintounix.c | ||
|
||
install: | ||
test -d $(DESTBIN) || mkdir -p $(DESTBIN) | ||
cp $(PROGRAMS) $(DESTBIN) | ||
test -f $(DESTMAN) || mkdir -p $(DESTMAN) | ||
cp $(MANPAGES) $(DESTMAN) | ||
|
||
clean: | ||
rm -f $(PROGRAMS) | ||
rm -f $(OBJECTS) | ||
rm -f $(MANPAGES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/**************************************************************************** | ||
* | ||
* Copyright (C) 2011 Peter W. Draper (p.w.draper@durham.ac.uk) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
****************************************************************************/ | ||
/*+ | ||
=pod | ||
=head1 NAME | ||
datetomjd | ||
=head1 SYNOPSIS | ||
datetomjd now | ||
datetomjd <date_and_time> | ||
=head1 DESCRIPTION | ||
Converts a UT date and time or the current second ("now") to a Modified Julian | ||
Date. | ||
If given the date and time should be in "YYYY-MM-DD HH:MM:SS.SS" format. | ||
=head1 AUTHOR | ||
Peter W. Draper: 10-JUN-2011 | ||
Durham University | ||
=cut | ||
-*/ | ||
|
||
/* Include files */ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <time.h> | ||
#include <string.h> | ||
|
||
/* Date of the Unix epoch as a Modified Julian Date. */ | ||
#define MJD_EPOCH 40587 | ||
|
||
/* Number of seconds per day. */ | ||
#define SECS_PER_DAY (60 * 60 * 24) | ||
|
||
/* Maximum length of time string. */ | ||
#define BUFLEN 64 | ||
|
||
/** | ||
* Main routine. | ||
*/ | ||
int main( int argc, char *argv[] ) | ||
{ | ||
double mjd; /* Modified Julian Date */ | ||
time_t unixsecs; /* Seconds since the UNIX epoch */ | ||
struct tm utc; /* UTC time struct */ | ||
|
||
/* Get the command-line value. */ | ||
if ( argc != 2 ) { | ||
printf( "Usage: %s now\n" | ||
" %s 'YYYY-MM-DD HH:MM:SS.SS'\n", argv[0], argv[0] ); | ||
return 1; | ||
} | ||
|
||
/* Do we want "now"? */ | ||
if ( strncmp( argv[1], "now", 3 ) == 0 ) { | ||
|
||
/* Seconds of the UNIX epoch. */ | ||
unixsecs = time( NULL ); | ||
} | ||
else { | ||
/* Convert formatted time into a struct. */ | ||
if ( strptime( argv[1], "%Y-%m-%d %H:%M:%S", &utc ) == NULL ) { | ||
printf( "Failed to convert date (%s)\n", argv[1] ); | ||
return 1; | ||
} | ||
|
||
/* Seconds since the UNIX epoch. */ | ||
unixsecs = timegm( &utc ); | ||
} | ||
|
||
/* MJD. */ | ||
mjd = ( unixsecs / SECS_PER_DAY ) + MJD_EPOCH; | ||
printf( "MJD: %g\n", mjd ); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/**************************************************************************** | ||
* | ||
* Copyright (C) 2011 Peter W. Draper (p.w.draper@durham.ac.uk) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
****************************************************************************/ | ||
/*+ | ||
=pod | ||
=head1 NAME | ||
datetounix | ||
=head1 SYNOPSIS | ||
datetounix now | ||
datetounix <date_and_time> | ||
=head1 DESCRIPTION | ||
Converts a UT date and time or the current second ("now") into the number of | ||
seconds in the UNIX epoch. | ||
If given the date and time should be in "YYYY-MM-DD HH:MM:SS.SS" format. | ||
=head1 AUTHOR | ||
Peter W. Draper: 10-JUN-2011 | ||
Durham University | ||
=cut | ||
-*/ | ||
|
||
/* Include files */ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <time.h> | ||
#include <string.h> | ||
|
||
/** | ||
* Main routine. | ||
*/ | ||
int main( int argc, char *argv[] ) | ||
{ | ||
time_t unixsecs; /* Seconds since the UNIX epoch */ | ||
struct tm utc; /* UTC time struct */ | ||
|
||
/* Get the command-line value. */ | ||
if ( argc != 2 ) { | ||
printf( "Usage: %s now\n" | ||
" %s 'YYYY-MM-DD HH:MM:SS.SS'\n", argv[0], argv[0] ); | ||
return 1; | ||
} | ||
|
||
/* Do we want "now"? */ | ||
if ( strncmp( argv[1], "now", 3 ) == 0 ) { | ||
|
||
/* Seconds of the UNIX epoch. */ | ||
unixsecs = time( NULL ); | ||
} | ||
else { | ||
/* Convert formatted time into a struct. */ | ||
if ( strptime( argv[1], "%Y-%m-%d %H:%M:%S", &utc ) == NULL ) { | ||
printf( "Failed to convert date (%s)\n", argv[1] ); | ||
return 1; | ||
} | ||
|
||
/* Seconds since the UNIX epoch. */ | ||
unixsecs = timegm( &utc ); | ||
} | ||
|
||
/* Get UNIX ticks. */ | ||
printf( "Unix ticks = %ld\n", unixsecs ); | ||
return 0; | ||
} |
Oops, something went wrong.