1#ifndef REMORA_DateClock_H
2#define REMORA_DateClock_H
9#include <AMReX_Extension.H>
10#include <AMReX_GpuQualifiers.H>
74 const bool leap = (((
year % 4) == 0) && ((
year % 100) != 0)) || ((
year % 400) == 0);
76 return static_cast<int>((275.0 *
month) / 9.0) -
fac * ((
month + 9) / 12) +
day - 30;
93 const int cal =
static_cast<int>(time_ref);
114 }
else if (
cal == -1) {
120 constexpr int offset = 61;
126 static_cast<int>(0.25 *
my_year) -
127 static_cast<int>(0.01 *
my_year) +
128 static_cast<int>(0.0025 *
my_year) +
129 static_cast<int>(0.1 * (
my_month * 306.0 + 5.0)) +
142 double(
hour) / 24.0 +
159 const int cal =
static_cast<int>(time_ref);
164 year = std::max(1,
static_cast<int>(time_ref * 0.0001));
165 month = std::min(12, std::max(1,
static_cast<int>(
166 (time_ref -
double(
year * 10000)) * 0.01)));
167 const double fday = time_ref - std::trunc(time_ref * 0.01) * 100.0;
168 day = std::max(1,
static_cast<int>(
fday));
169 const double sec = (
fday - std::trunc(
fday)) * 86400.0;
170 hour =
static_cast<int>(
sec / 3600.0);
171 minute =
static_cast<int>(std::fmod(
sec, 3600.0) / 60.0);
172 second =
static_cast<int>(std::fmod(
sec, 60.0));
174 }
else if (
cal == -1) {
178 }
else if (
cal == -2) {
199 const int cal =
static_cast<int>(time_ref);
230 const int cal =
static_cast<int>(time_ref);
251 double js = 4.0 *
jr - 1.0;
252 double yy = std::floor(
js / 146097.0);
254 js = std::floor(
jr * 0.25);
256 jr = std::floor(
js / 1461.0);
257 const double dd = std::floor(((
js - 1461.0 *
jr) + 4.0) * 0.25);
259 const double mo = std::floor(
js / 153.0);
263 year =
static_cast<int>(
yy);
264 month =
static_cast<int>(
mo + 3.0);
266 year =
static_cast<int>(
yy + 1.0);
267 month =
static_cast<int>(
mo - 9.0);
269 day =
static_cast<int>(((
js - 153.0 *
mo) + 5.0) * 0.2);
271 }
else if (
cal == -1) {
287 constexpr double offset = 61.0;
300 return static_cast<int>(365.0 *
y) +
static_cast<int>(0.25 *
y) -
301 static_cast<int>(0.01 *
y) +
static_cast<int>(0.0025 *
y);
309 const int my_month =
static_cast<int>((100.0 *
my_day + 52.0) / 3060.0);
339 const int cal =
static_cast<int>(time_ref);
383 return static_cast<int>(time_ref) >= -2;
395 const int cal =
static_cast<int>(time_ref);
403 return "proleptic_gregorian";
422 char buf[6 * 11 + 5 + 1];
423 std::snprintf(
buf,
sizeof(
buf),
"%04d-%02d-%02d %02d:%02d:%02d",
425 return std::string(
buf);
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void remora_ref_clock(double time_ref, int &year, int &month, int &day, int &hour, int &minute, int &second) noexcept
Reference date the model clock counts from, implied by time_ref.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int remora_yearday(int year, int month, int day) noexcept
Day of the year for a calendar date. ROMS yearday.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double remora_datenum(double time_ref, int year, int month, int day, int hour=0, int minutes=0, double seconds=0.0) noexcept
Fractional day number for a calendar date. ROMS datenum.
AMREX_FORCE_INLINE std::string remora_ref_date_string(double time_ref)
Reference date as YYYY-MM-DD hh:mm:ss. ROMS ref_clock's Rclockstring.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void remora_datevec(double time_ref, double date_number, bool is_day_units, int &year, int &month, int &day) noexcept
Calendar date for a day (or second) number. ROMS datevec.
static constexpr int remora_gregorian_daynum
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double remora_ref_datenum(double time_ref) noexcept
Day number of the reference date implied by time_ref.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool remora_time_ref_is_valid(double time_ref) noexcept
Whether time_ref names a calendar this header implements.
AMREX_FORCE_INLINE std::string remora_ref_calendar(double time_ref)
CF calendar name for time_ref. ROMS ref_clock's Rclockcalendar.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void remora_caldate(double time_ref, double current_time_days, int &year, int &month, int &day, double &yday) noexcept
Model time in days to calendar date. ROMS caldate.
mf_h setVal(geomdata.ProbHi(2))