-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
b6e0524
commit 5f0b742
Showing
16 changed files
with
284 additions
and
14 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
This file was deleted.
Oops, something went wrong.
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,87 @@ | ||
#include "calendar.hpp" | ||
#include "datetime_write.hpp" | ||
#include <cstdio> | ||
#include <exception> | ||
#include <cstring> | ||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
#include <unistd.h> | ||
#endif | ||
|
||
constexpr const int MAX_ERRORS_ALLOWED = 10; | ||
|
||
/* help message */ | ||
void prhelp() { | ||
printf( | ||
"jd2ydoy: Transform a date from Modified Julian Day to calendar date, " | ||
"i.e.\n\"YYYYdDDD\". The program expects the read a Modified Julian " | ||
"Day string\n(actually an integral value) from STDIN (or multiple MJDs, " | ||
"seperated by\nnewlines) and will print results on STDOUT. The MJD string" | ||
" can be followed by\nany number of remaining characters that will be " | ||
"ignored.\n\nOptions:\n[-h] " | ||
"help message\n\tprint (this) message and exit.\n[-e] " | ||
"MAX_ERRORS_ALLOWED\n\tMaximum number of errors allowed (i.e. date " | ||
"strings that where not\n\tparsed correctly). Default values is %d\n\n" | ||
"\n\nWarnings:\n\t* Command line options are only available on POSIX " | ||
"systems.\n\nDionysos Satellite Observatory\nNational Technical " | ||
"University of " | ||
"Athens\nhttps://github.com/DSOlab/ggdatetime\n", | ||
MAX_ERRORS_ALLOWED); | ||
return; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
char line[124]; | ||
char buf[64]; | ||
int mjd; | ||
char c; | ||
int error = 0, cer = 0; | ||
int max_errors_allowed = MAX_ERRORS_ALLOWED; | ||
|
||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
/* parse command line arguments */ | ||
while ((c = getopt(argc, argv, "he:")) != -1) { | ||
switch (c) { | ||
case 'h': | ||
prhelp(); | ||
return 0; | ||
case 'e': | ||
max_errors_allowed = atoi(optarg); | ||
break; | ||
default: | ||
fprintf(stderr, "Usage: %s [-e MAX_ERRORS_ALLOWED]\n", argv[0]); | ||
return 1; | ||
} /* switch c */ | ||
} | ||
#endif | ||
|
||
while (fgets(line, sizeof(line), stdin) && (error<max_errors_allowed)) { | ||
if (1 == sscanf(line, "%d", &mjd)) { | ||
dso::modified_julian_day m(mjd); | ||
const auto ymd = m.to_ymd(); | ||
try { | ||
if (dso::SpitDate<dso::YMDFormat::YYYYDDD>::spit(ymd, buf) != | ||
dso::SpitDate<dso::YMDFormat::YYYYDDD>::numChars) { | ||
++error; | ||
} else { | ||
printf("%s\n", buf); | ||
} | ||
} catch (std::exception &) { | ||
++error; | ||
} | ||
} else { | ||
++error; | ||
} | ||
|
||
if (error > cer) { | ||
fprintf(stderr, "ERROR. Failed parsing/transforming line: %s\n", line); | ||
++cer; | ||
} | ||
} | ||
|
||
if (error>=max_errors_allowed) { | ||
fprintf(stderr, "Too many errors, giving up!\n"); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
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,87 @@ | ||
#include "calendar.hpp" | ||
#include "datetime_write.hpp" | ||
#include <cstdio> | ||
#include <exception> | ||
#include <cstring> | ||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
#include <unistd.h> | ||
#endif | ||
|
||
constexpr const int MAX_ERRORS_ALLOWED = 10; | ||
|
||
/* help message */ | ||
void prhelp() { | ||
printf( | ||
"jd2ymd: Transform a date from Modified Julian Day to calendar date, " | ||
"i.e.\n\"YYYYdMMdDD\". The program expects the read a Modified Julian " | ||
"Day string\n(actually an integral value) from STDIN (or multiple MJDs, " | ||
"seperated by\nnewlines) and will print results on STDOUT. The MJD string" | ||
" can be followed by\nany number of remaining characters that will be " | ||
"ignored.\n\nOptions:\n[-h] " | ||
"help message\n\tprint (this) message and exit.\n[-e] " | ||
"MAX_ERRORS_ALLOWED\n\tMaximum number of errors allowed (i.e. date " | ||
"strings that where not\n\tparsed correctly). Default values is %d\n\n" | ||
"\n\nWarnings:\n\t* Command line options are only available on POSIX " | ||
"systems.\n\nDionysos Satellite Observatory\nNational Technical " | ||
"University of " | ||
"Athens\nhttps://github.com/DSOlab/ggdatetime\n", | ||
MAX_ERRORS_ALLOWED); | ||
return; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
char line[124]; | ||
char buf[64]; | ||
int mjd; | ||
char c; | ||
int error = 0, cer = 0; | ||
int max_errors_allowed = MAX_ERRORS_ALLOWED; | ||
|
||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
/* parse command line arguments */ | ||
while ((c = getopt(argc, argv, "he:")) != -1) { | ||
switch (c) { | ||
case 'h': | ||
prhelp(); | ||
return 0; | ||
case 'e': | ||
max_errors_allowed = atoi(optarg); | ||
break; | ||
default: | ||
fprintf(stderr, "Usage: %s [-e MAX_ERRORS_ALLOWED]\n", argv[0]); | ||
return 1; | ||
} /* switch c */ | ||
} | ||
#endif | ||
|
||
while (fgets(line, sizeof(line), stdin) && (error<max_errors_allowed)) { | ||
if (1 == sscanf(line, "%d", &mjd)) { | ||
dso::modified_julian_day m(mjd); | ||
const auto ymd = m.to_ymd(); | ||
try { | ||
if (dso::SpitDate<dso::YMDFormat::YYYYMMDD>::spit(ymd, buf) != | ||
dso::SpitDate<dso::YMDFormat::YYYYMMDD>::numChars) { | ||
++error; | ||
} else { | ||
printf("%s\n", buf); | ||
} | ||
} catch (std::exception &) { | ||
++error; | ||
} | ||
} else { | ||
++error; | ||
} | ||
|
||
if (error > cer) { | ||
fprintf(stderr, "ERROR. Failed parsing/transforming line: %s\n", line); | ||
++cer; | ||
} | ||
} | ||
|
||
if (error>=max_errors_allowed) { | ||
fprintf(stderr, "Too many errors, giving up!\n"); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
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,88 @@ | ||
#include "calendar.hpp" | ||
#include <cstdio> | ||
#include <exception> | ||
#include <cstring> | ||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
#include <unistd.h> | ||
#endif | ||
|
||
constexpr const int MAX_ERRORS_ALLOWED = 10; | ||
|
||
/* help message */ | ||
void prhelp() { | ||
printf( | ||
"ymd2mjd: Transform a date given as \"YYYYdMMdDD\" to Modified Julian " | ||
"Day. The\ncharacter \"d\" in the date string can be any character you " | ||
"want,\nexcept from a numeric value. The program expects the read a date " | ||
"string\nfrom STDIN (or multuple date strings, seperated by newlines) " | ||
"and " | ||
"will\nprint results on STDOUT.\nThe date string can be followed by any " | ||
"numberof remaining characters\nthat will be ignored.\n\nExample " | ||
"Usage:\n$>cat " | ||
"dates\n2014:01:09\n2014:01:9\n2014:1:09\n2014:01:08\n2014:01:07\n2014:" | ||
"01:0 // ERROR\n2014:01:1\n2014T01:1\n2014TT01:1 //ERROR\n2014:01:1with " | ||
"some string\n2014/01/1with some string\n$>cat dates | " | ||
"ymd2mjd\n56666\n56666\n56666\n56665\n56664\nERROR. Failed " | ||
"parsing/transforming line: 2014:01:0\n\n56658\n56658\nERROR. Failed " | ||
"parsing/transforming line: 2014TT01:1\n\n56658\n56658\n\nOptions:\n[-h] " | ||
"help message\n\tprint (this) message and exit.\n[-e] " | ||
"MAX_ERRORS_ALLOWED\n\tMaximum number of errors allowed (i.e. date " | ||
"strings that where not\n\tparsed correctly). Default values is %d\n\n" | ||
"\n\nWarnings:\n\t* Command line options are only available on POSIX " | ||
"systems.\n\nDionysos Satellite " | ||
"Observatory\nNational Technical University of " | ||
"Athens\nhttps://github.com/DSOlab/ggdatetime\n", | ||
MAX_ERRORS_ALLOWED); | ||
return; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
char line[124]; | ||
int yr, mn, dm; | ||
char c; | ||
int error = 0, cer = 0; | ||
int max_errors_allowed = MAX_ERRORS_ALLOWED; | ||
|
||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
/* parse command line arguments */ | ||
while ((c = getopt(argc, argv, "he:")) != -1) { | ||
switch (c) { | ||
case 'h': | ||
prhelp(); | ||
return 0; | ||
case 'e': | ||
max_errors_allowed = atoi(optarg); | ||
break; | ||
default: | ||
fprintf(stderr, "Usage: %s [-e MAX_ERRORS_ALLOWED]\n", argv[0]); | ||
return 1; | ||
} /* switch c */ | ||
} | ||
#endif | ||
|
||
while (fgets(line, sizeof(line), stdin) && (error<max_errors_allowed)) { | ||
if (5 == sscanf(line, "%d%c%d%c%d", &yr, &c, &mn, &c, &dm)) { | ||
try { | ||
printf("%d\n", dso::modified_julian_day(dso::year(yr), dso::month(mn), | ||
dso::day_of_month(dm)) | ||
.as_underlying_type()); | ||
} catch (std::exception &) { | ||
++error; | ||
} | ||
} else { | ||
++error; | ||
} | ||
|
||
if (error > cer) { | ||
fprintf(stderr, "ERROR. Failed parsing/transforming line: %s\n", line); | ||
++cer; | ||
} | ||
} | ||
|
||
if (error>=max_errors_allowed) { | ||
fprintf(stderr, "Too many errors, giving up!\n"); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
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,13 @@ | ||
target_sources(datetime | ||
PRIVATE | ||
${CMAKE_SOURCE_DIR}/src/lib/dat.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/datetime_io_core.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/modified_julian_day.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/month.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/strmonth.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/tpdateutc.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/twopartdates.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/utc2tai.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/ydoy_date.cpp | ||
${CMAKE_SOURCE_DIR}/src/lib/ymd_date.cpp | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.