Skip to content

Commit adb191c

Browse files
committed
First commit to github
1 parent 01101e9 commit adb191c

File tree

8 files changed

+617
-51
lines changed

8 files changed

+617
-51
lines changed

.gitignore

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,10 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Object files
1+
tjdtodate
2+
*~
3+
*.1
54
*.o
6-
*.ko
7-
*.obj
8-
*.elf
9-
10-
# Linker output
11-
*.ilk
12-
*.map
13-
*.exp
14-
15-
# Precompiled Headers
16-
*.gch
17-
*.pch
18-
19-
# Libraries
20-
*.lib
21-
*.a
22-
*.la
23-
*.lo
24-
25-
# Shared objects (inc. Windows DLLs)
26-
*.dll
27-
*.so
28-
*.so.*
29-
*.dylib
30-
31-
# Executables
32-
*.exe
33-
*.out
34-
*.app
35-
*.i*86
36-
*.x86_64
37-
*.hex
38-
39-
# Debug files
40-
*.dSYM/
41-
*.su
42-
*.idb
43-
*.pdb
44-
45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
5+
fixxyplots.sh
6+
unixtodate
7+
datetounix
8+
datetomjd
9+
mjdtodate
10+
wintounix

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
PROGRAMS = tjdtodate unixtodate datetounix mjdtodate datetomjd wintounix
3+
4+
OBJECTS = $(PROGRAMS:=.o)
5+
MANPAGES = $(PROGRAMS:=.1)
6+
7+
DESTBIN = $(HOME)/bin
8+
DESTMAN = $(HOME)/man/man1
9+
10+
all: $(PROGRAMS)
11+
$(MAKE) man
12+
13+
man: $(MANPAGES)
14+
15+
$(MANPAGES): $(PROGRAMS)
16+
pod2man -c "Date utilities" $(@:.1=.c) $@
17+
18+
tjdtodate: tjdtodate.c
19+
gcc -o tjdtodate -g -Wall tjdtodate.c
20+
21+
unixtodate: unixtodate.c
22+
gcc -o unixtodate -g -Wall unixtodate.c
23+
24+
datetounix: datetounix.c
25+
gcc -o datetounix -g -Wall datetounix.c
26+
27+
mjdtodate: mjdtodate.c
28+
gcc -o mjdtodate -g -Wall mjdtodate.c
29+
30+
datetomjd: datetomjd.c
31+
gcc -o datetomjd -g -Wall datetomjd.c
32+
33+
wintounix: wintounix.c
34+
gcc -o wintounix -g -Wall wintounix.c
35+
36+
install:
37+
test -d $(DESTBIN) || mkdir -p $(DESTBIN)
38+
cp $(PROGRAMS) $(DESTBIN)
39+
test -f $(DESTMAN) || mkdir -p $(DESTMAN)
40+
cp $(MANPAGES) $(DESTMAN)
41+
42+
clean:
43+
rm -f $(PROGRAMS)
44+
rm -f $(OBJECTS)
45+
rm -f $(MANPAGES)

datetomjd.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/****************************************************************************
2+
*
3+
* Copyright (C) 2011 Peter W. Draper ([email protected])
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
****************************************************************************/
20+
/*+
21+
22+
=pod
23+
24+
=head1 NAME
25+
26+
datetomjd
27+
28+
=head1 SYNOPSIS
29+
30+
datetomjd now
31+
32+
datetomjd <date_and_time>
33+
34+
=head1 DESCRIPTION
35+
36+
Converts a UT date and time or the current second ("now") to a Modified Julian
37+
Date.
38+
39+
If given the date and time should be in "YYYY-MM-DD HH:MM:SS.SS" format.
40+
41+
=head1 AUTHOR
42+
43+
Peter W. Draper: 10-JUN-2011
44+
45+
Durham University
46+
47+
=cut
48+
49+
-*/
50+
51+
/* Include files */
52+
#define _GNU_SOURCE
53+
#include <stdio.h>
54+
#include <unistd.h>
55+
#include <time.h>
56+
#include <string.h>
57+
58+
/* Date of the Unix epoch as a Modified Julian Date. */
59+
#define MJD_EPOCH 40587
60+
61+
/* Number of seconds per day. */
62+
#define SECS_PER_DAY (60 * 60 * 24)
63+
64+
/* Maximum length of time string. */
65+
#define BUFLEN 64
66+
67+
/**
68+
* Main routine.
69+
*/
70+
int main( int argc, char *argv[] )
71+
{
72+
double mjd; /* Modified Julian Date */
73+
time_t unixsecs; /* Seconds since the UNIX epoch */
74+
struct tm utc; /* UTC time struct */
75+
76+
/* Get the command-line value. */
77+
if ( argc != 2 ) {
78+
printf( "Usage: %s now\n"
79+
" %s 'YYYY-MM-DD HH:MM:SS.SS'\n", argv[0], argv[0] );
80+
return 1;
81+
}
82+
83+
/* Do we want "now"? */
84+
if ( strncmp( argv[1], "now", 3 ) == 0 ) {
85+
86+
/* Seconds of the UNIX epoch. */
87+
unixsecs = time( NULL );
88+
}
89+
else {
90+
/* Convert formatted time into a struct. */
91+
if ( strptime( argv[1], "%Y-%m-%d %H:%M:%S", &utc ) == NULL ) {
92+
printf( "Failed to convert date (%s)\n", argv[1] );
93+
return 1;
94+
}
95+
96+
/* Seconds since the UNIX epoch. */
97+
unixsecs = timegm( &utc );
98+
}
99+
100+
/* MJD. */
101+
mjd = ( unixsecs / SECS_PER_DAY ) + MJD_EPOCH;
102+
printf( "MJD: %g\n", mjd );
103+
return 1;
104+
}

datetounix.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/****************************************************************************
2+
*
3+
* Copyright (C) 2011 Peter W. Draper ([email protected])
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
****************************************************************************/
20+
/*+
21+
22+
=pod
23+
24+
=head1 NAME
25+
26+
datetounix
27+
28+
=head1 SYNOPSIS
29+
30+
datetounix now
31+
32+
datetounix <date_and_time>
33+
34+
=head1 DESCRIPTION
35+
36+
Converts a UT date and time or the current second ("now") into the number of
37+
seconds in the UNIX epoch.
38+
39+
If given the date and time should be in "YYYY-MM-DD HH:MM:SS.SS" format.
40+
41+
=head1 AUTHOR
42+
43+
Peter W. Draper: 10-JUN-2011
44+
45+
Durham University
46+
47+
=cut
48+
49+
-*/
50+
51+
/* Include files */
52+
#define _GNU_SOURCE
53+
#include <stdio.h>
54+
#include <stdlib.h>
55+
#include <unistd.h>
56+
#include <time.h>
57+
#include <string.h>
58+
59+
/**
60+
* Main routine.
61+
*/
62+
int main( int argc, char *argv[] )
63+
{
64+
time_t unixsecs; /* Seconds since the UNIX epoch */
65+
struct tm utc; /* UTC time struct */
66+
67+
/* Get the command-line value. */
68+
if ( argc != 2 ) {
69+
printf( "Usage: %s now\n"
70+
" %s 'YYYY-MM-DD HH:MM:SS.SS'\n", argv[0], argv[0] );
71+
return 1;
72+
}
73+
74+
/* Do we want "now"? */
75+
if ( strncmp( argv[1], "now", 3 ) == 0 ) {
76+
77+
/* Seconds of the UNIX epoch. */
78+
unixsecs = time( NULL );
79+
}
80+
else {
81+
/* Convert formatted time into a struct. */
82+
if ( strptime( argv[1], "%Y-%m-%d %H:%M:%S", &utc ) == NULL ) {
83+
printf( "Failed to convert date (%s)\n", argv[1] );
84+
return 1;
85+
}
86+
87+
/* Seconds since the UNIX epoch. */
88+
unixsecs = timegm( &utc );
89+
}
90+
91+
/* Get UNIX ticks. */
92+
printf( "Unix ticks = %ld\n", unixsecs );
93+
return 0;
94+
}

0 commit comments

Comments
 (0)