File: tfitsdateobstime.cpp

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (47 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <aocommon/fits/fitsreader.h>
#include <aocommon/fits/fitswriter.h>

#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>

#include <string>

namespace wsclean {

BOOST_AUTO_TEST_SUITE(fits_date_obs_time)

const std::pair<std::string, long double> timeValues[] = {
    {"2013-08-22T00:00:00.0", 0.0L},
    {"2013-08-22T00:00:00.1", 0.1L / 60.0L / 60.0L / 24.0L},
    {"2013-08-22T00:00:00.9", 0.9L / 60.0L / 60.0L / 24.0L},
    {"2013-08-22T00:00:59.9", 59.9L / 60.0L / 60.0L / 24.0L},
    {"2013-08-22T00:59:59.9", (59.9L / 60.0L + 59.0L) / 60.0L / 24.0L},
    {"2013-08-22T23:59:59.9",
     ((59.9L / 60.0L + 59.0L) / 60.0L + 23.0L) / 24.0L},
    {"2013-08-22T23:59:59.9",
     ((59.99L / 60.0L + 59.0L) / 60.0L + 23.0L) / 24.0L},
    {"2013-08-22T00:00:00.0", 1.0L},
    {"2013-08-22T14:00:16.0",
     (((16.0L - 0.00000000000069L) / 60.0L + 00.0L) / 60.0L + 14.0L) / 24.0L}};

BOOST_DATA_TEST_CASE(functionMJDToHMS,
                     boost::unit_test::data::xrange(std::end(timeValues) -
                                                    std::begin(timeValues))) {
  const std::string& str = timeValues[sample].first;
  long double mjd = timeValues[sample].second;

  int hour, min, sec, dsec;
  aocommon::FitsWriter::MJDToHMS(mjd, hour, min, sec, dsec);
  char dateStrA[40], dateStrB[40];
  std::sprintf(dateStrA, "%02d:%02d:%02d.%01d", hour, min, sec, dsec);
  BOOST_CHECK_EQUAL(str.substr(11), std::string(dateStrA));

  double fMJD = aocommon::FitsReader::ParseFitsDateToMJD(str.c_str());
  aocommon::FitsWriter::MJDToHMS(fMJD, hour, min, sec, dsec);
  std::sprintf(dateStrB, "%02d:%02d:%02d.%01d", hour, min, sec, dsec);
  BOOST_CHECK_EQUAL(str.substr(11), std::string(dateStrB));
}

BOOST_AUTO_TEST_SUITE_END()

}  // namespace wsclean