Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
d237e51e
Commit
d237e51e
authored
2 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
datetime2rtimeval(): refactor to JulianDate
parent
a42d2b99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#18333
failed
1 month ago
Stage: external
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/julian_date.c
+37
-1
37 additions, 1 deletion
src/julian_date.c
src/julian_date.h
+2
-1
2 additions, 1 deletion
src/julian_date.h
src/taxis.c
+20
-34
20 additions, 34 deletions
src/taxis.c
with
59 additions
and
36 deletions
src/julian_date.c
+
37
−
1
View file @
d237e51e
#include
"julian_date.h"
JulianDate
julianDate
E
ncode
(
int
calendar
,
CdiDateTime
dt
)
julianDate
_e
ncode
(
int
calendar
,
CdiDateTime
dt
)
{
JulianDate
julianDate
;
...
...
@@ -10,3 +10,39 @@ julianDateEncode(int calendar, CdiDateTime dt)
return
julianDate
;
}
static
void
adjust_seconds
(
int64_t
*
julianDay
,
double
*
secondOfDay
)
{
const
double
SecondsPerDay
=
86400
.
0
;
while
(
*
secondOfDay
>=
SecondsPerDay
)
{
*
secondOfDay
-=
SecondsPerDay
;
(
*
julianDay
)
++
;
}
while
(
*
secondOfDay
<
0
)
{
*
secondOfDay
+=
SecondsPerDay
;
(
*
julianDay
)
--
;
}
}
// subtract jjulianDate1 from julianDate2 and returns the result in seconds
double
julianDate_sub
(
JulianDate
julianDate1
,
JulianDate
julianDate2
,
int64_t
*
days
,
double
*
secs
)
{
*
days
=
julianDate2
.
julianDay
-
julianDate1
.
julianDay
;
*
secs
=
julianDate2
.
secondOfDay
-
julianDate1
.
secondOfDay
;
double
sec_of_day
=
*
secs
;
adjust_seconds
(
days
,
&
sec_of_day
);
*
secs
=
sec_of_day
;
double
seconds
=
(
*
days
)
*
86400
.
0
+
sec_of_day
;
return
seconds
;
}
This diff is collapsed.
Click to expand it.
src/julian_date.h
+
2
−
1
View file @
d237e51e
...
...
@@ -16,7 +16,8 @@ typedef struct
double
secondOfDay
;
}
JulianDate
;
JulianDate
julianDateEncode
(
int
calendar
,
CdiDateTime
dt
);
JulianDate
julianDate_encode
(
int
calendar
,
CdiDateTime
dt
);
double
julianDate_sub
(
JulianDate
julianDate1
,
JulianDate
julianDate2
,
int64_t
*
days
,
double
*
secs
);
#ifdef __cplusplus
}
...
...
This diff is collapsed.
Click to expand it.
src/taxis.c
+
20
−
34
View file @
d237e51e
...
...
@@ -1290,8 +1290,9 @@ datetime2rtimeval(CdiDateTime vdatetime, taxis_t *taxis)
int64_t
days
;
double
secs
;
int
timeunit
=
(
*
taxis
).
unit
;
const
int
calendar
=
(
*
taxis
).
calendar
;
int
timeunits
=
(
*
taxis
).
unit
;
const
int
timeunits0
=
timeunits
;
CdiDateTime
rdatetime
=
(
*
taxis
).
rdatetime
;
...
...
@@ -1299,28 +1300,16 @@ datetime2rtimeval(CdiDateTime vdatetime, taxis_t *taxis)
if
(
cdiDateTime_isNull
(
rdatetime
)
&&
cdiDateTime_isNull
(
vdatetime
))
return
value
;
int
year
=
taxis
->
rdatetime
.
date
.
year
;
int
month
=
taxis
->
rdatetime
.
date
.
month
;
int
day
=
taxis
->
rdatetime
.
date
.
day
;
int
hour
=
taxis
->
rdatetime
.
time
.
hour
;
int
minute
=
taxis
->
rdatetime
.
time
.
minute
;
int
second
=
taxis
->
rdatetime
.
time
.
second
;
int
ms
=
taxis
->
rdatetime
.
time
.
ms
;
const
int
ryear
=
year
;
const
int
rmonth
=
month
;
int64_t
julianDay1
=
encode_calday
(
calendar
,
ryear
,
rmonth
,
day
);
double
secondOfDay1
=
encode_secofday
(
hour
,
minute
,
second
,
ms
);
const
JulianDate
julianDate1
=
julianDate_encode
(
calendar
,
rdatetime
);
cdiDateDecode
(
vdatetime
.
date
,
&
year
,
&
month
,
&
day
);
cdiTimeDecode
(
vdatetime
.
time
,
&
hour
,
&
minute
,
&
second
,
&
ms
);
if
(
timeunits
==
TUNIT_MONTH
&&
calendar
==
CALENDAR_360DAYS
)
timeunits
=
TUNIT_DAY
;
int
timeunit0
=
timeunit
;
if
(
timeunit
==
TUNIT_MONTH
&&
calendar
==
CALENDAR_360DAYS
)
timeunit
=
TUNIT_DAY
;
if
(
timeunit
==
TUNIT_MONTH
||
timeunit
==
TUNIT_YEAR
)
if
(
timeunits
==
TUNIT_MONTH
||
timeunits
==
TUNIT_YEAR
)
{
const
int
ryear
=
rdatetime
.
date
.
year
;
const
int
rmonth
=
rdatetime
.
date
.
month
;
int
year
=
vdatetime
.
date
.
year
;
int
month
=
vdatetime
.
date
.
month
;
value
=
(
year
-
ryear
)
*
12
-
rmonth
+
month
;
int
nmonth
=
(
int
)
value
;
...
...
@@ -1331,28 +1320,25 @@ datetime2rtimeval(CdiDateTime vdatetime, taxis_t *taxis)
while
(
month
<
1
)
{
month
+=
12
;
year
--
;
}
// clang-format on
int
dpm
=
days_per_month
(
calendar
,
year
,
month
);
int64_t
julianDay2
=
encode_calday
(
calendar
,
year
,
month
,
day
);
double
secondOfDay2
=
encode_secofday
(
hour
,
minute
,
second
,
ms
);
const
int
dpm
=
days_per_month
(
calendar
,
year
,
month
);
julday_sub
(
julianDay1
,
secondOfDay1
,
julianDay2
,
secondOfDay2
,
&
days
,
&
secs
);
vdatetime
.
date
.
year
=
year
;
vdatetime
.
date
.
month
=
month
;
const
JulianDate
julianDate2
=
julianDate_encode
(
calendar
,
vdatetime
);
julianDate_sub
(
julianDate1
,
julianDate2
,
&
days
,
&
secs
);
value
+=
(
days
+
secs
/
86400
.
0
)
/
dpm
;
if
(
timeunit
==
TUNIT_YEAR
)
value
=
value
/
12
;
if
(
timeunits
==
TUNIT_YEAR
)
value
=
value
/
12
;
}
else
{
int64_t
julianDay2
=
encode_calday
(
calendar
,
year
,
month
,
day
);
double
secondOfDay2
=
encode_secofday
(
hour
,
minute
,
second
,
ms
);
julday_sub
(
julianDay1
,
secondOfDay1
,
julianDay2
,
secondOfDay2
,
&
days
,
&
secs
);
const
JulianDate
julianDate2
=
julianDate_encode
(
calendar
,
vdatetime
);
julianDate_sub
(
julianDate1
,
julianDate2
,
&
days
,
&
secs
);
value
=
cdi_encode_timevalue
(
days
,
secs
,
timeunit
);
value
=
cdi_encode_timevalue
(
days
,
secs
,
timeunit
s
);
}
if
(
timeunit0
==
TUNIT_MONTH
&&
calendar
==
CALENDAR_360DAYS
)
value
/=
30
.
0
;
if
(
timeunit
s
0
==
TUNIT_MONTH
&&
calendar
==
CALENDAR_360DAYS
)
value
/=
30
.
0
;
return
value
;
}
...
...
@@ -1535,7 +1521,7 @@ cdiSetForecastPeriod(double timevalue, taxis_t *taxis)
(
*
taxis
).
vdatetime
.
date
.
month
=
month
;
}
JulianDate
julianDate
=
julianDate
E
ncode
(
calendar
,
(
*
taxis
).
vdatetime
);
JulianDate
julianDate
=
julianDate
_e
ncode
(
calendar
,
(
*
taxis
).
vdatetime
);
int64_t
days
;
double
secs
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment