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
c22dc791
Commit
c22dc791
authored
1 year ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
improve support for time units second [Bug #11740]
parent
f540cae5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!79
M214003/develop
Pipeline
#57878
failed
1 year ago
Stage: external
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ChangeLog
+4
-0
4 additions, 0 deletions
ChangeLog
NEWS
+1
-0
1 addition, 0 deletions
NEWS
src/stream_cdf_time.c
+1
-1
1 addition, 1 deletion
src/stream_cdf_time.c
src/taxis.c
+37
-8
37 additions, 8 deletions
src/taxis.c
with
43 additions
and
9 deletions
ChangeLog
+
4
−
0
View file @
c22dc791
...
...
@@ -2,6 +2,10 @@
* Version 2.4.0 released
2024-02-02 Uwe Schulzweida
* improve support for time units second [Bug #11740]
2024-01-10 Uwe Schulzweida
* cgribex: check gridsize when creating the inventory
...
...
This diff is collapsed.
Click to expand it.
NEWS
+
1
−
0
View file @
c22dc791
...
...
@@ -6,6 +6,7 @@ Version 2.4.0 (22 February 2024):
New features:
* Add global option CDI_Threadsafe to lock non thread-safe netCDF4/HDF5 calls
Fixed bugs:
* improve support for time units second [Bug #11740]
* calc_chunk_cache_size: wrong result for 3D data (bug fix)
* netCDF: write of y-coordinates failed for Gaussian reduced grids (bug fix)
...
...
This diff is collapsed.
Click to expand it.
src/stream_cdf_time.c
+
1
−
1
View file @
c22dc791
...
...
@@ -271,7 +271,7 @@ cdfDefTimestep(stream_t *streamptr, int tsID, size_t valCount)
const
size_t
start
[
2
]
=
{
[
0
]
=
(
size_t
)
tsID
,
[
1
]
=
0
},
count
[
2
]
=
{
[
0
]
=
valCount
,
[
1
]
=
2
*
valCount
};
double
timeValue
[
2
]
=
{
cdi_encode_timeval
(
taxis
->
vDateTime
,
&
streamptr
->
tsteps
[
0
].
taxis
)
};
if
(
CDI_Debug
)
Message
(
"tsID = %d timeValue = %f"
,
tsID
,
timeValue
);
if
(
CDI_Debug
)
Message
(
"tsID = %d timeValue = %f"
,
tsID
,
timeValue
[
0
]
);
int
ncvarid
=
streamptr
->
basetime
.
ncvarid
;
cdf_put_vara_double
(
fileID
,
ncvarid
,
start
,
count
,
timeValue
);
...
...
This diff is collapsed.
Click to expand it.
src/taxis.c
+
37
−
8
View file @
c22dc791
...
...
@@ -1089,9 +1089,24 @@ datetime2rtimeval(CdiDateTime vDateTime, const taxis_t *taxis)
return
value
;
}
// convert absolute seconds to CdiDateTime
static
CdiDateTime
seconds2datetime
(
double
timevalue
)
{
int
calendar
=
CALENDAR_STANDARD
;
int64_t
seconds
=
(
int64_t
)
timevalue
;
CdiDateTime
datetime0
;
datetime0
.
date
=
cdiDate_encode
(
1
,
1
,
1
);
datetime0
.
time
=
cdiTime_encode
(
0
,
0
,
0
,
0
);
JulianDate
julianDate
=
julianDate_encode
(
calendar
,
datetime0
);
return
julianDate_decode
(
calendar
,
julianDate_add_seconds
(
julianDate
,
seconds
));
}
// convert absolute time value to CdiDateTime
static
CdiDateTime
a
t
imeval2datetime
(
double
timevalue
)
a
bsT
imeval2datetime
(
double
timevalue
)
{
int64_t
vdate
=
(
int64_t
)
timevalue
;
double
tmpval
=
(
timevalue
-
vdate
)
*
86400
.
0
;
...
...
@@ -1120,17 +1135,16 @@ split_timevalue(double timevalue, int timeunit)
if
(
timeunit
==
TUNIT_SECOND
)
{
timevalue
/=
86400
;
datetime
=
atimeval2datetime
(
timevalue
);
datetime
=
seconds2datetime
(
timevalue
);
}
else
if
(
timeunit
==
TUNIT_HOUR
)
{
timevalue
/=
24
;
datetime
=
a
t
imeval2datetime
(
timevalue
);
datetime
=
a
bsT
imeval2datetime
(
timevalue
);
}
else
if
(
timeunit
==
TUNIT_DAY
)
{
datetime
=
a
t
imeval2datetime
(
timevalue
);
datetime
=
a
bsT
imeval2datetime
(
timevalue
);
}
else
if
(
timeunit
==
TUNIT_MONTH
)
{
...
...
@@ -1267,6 +1281,23 @@ cdi_decode_timeval(double timevalue, const taxis_t *taxis)
return
(
taxis
->
type
==
TAXIS_ABSOLUTE
)
?
split_timevalue
(
timevalue
,
taxis
->
unit
)
:
rtimeval2datetime
(
timevalue
,
taxis
);
}
static
int64_t
datetime2seconds
(
CdiDateTime
datetime
)
{
int
calendar
=
CALENDAR_STANDARD
;
CdiDateTime
datetime0
;
datetime0
.
date
=
cdiDate_encode
(
1
,
1
,
1
);
datetime0
.
time
=
cdiTime_encode
(
0
,
0
,
0
,
0
);
JulianDate
julianDate0
=
julianDate_encode
(
calendar
,
datetime0
);
JulianDate
julianDate
=
julianDate_encode
(
calendar
,
datetime
);
int64_t
days
=
julianDate
.
julianDay
-
julianDate0
.
julianDay
;
int64_t
seconds
=
days
*
86400
+
julianDate
.
secondOfDay
;
return
seconds
;
}
double
cdi_encode_timeval
(
CdiDateTime
datetime
,
taxis_t
*
taxis
)
{
...
...
@@ -1285,9 +1316,7 @@ cdi_encode_timeval(CdiDateTime datetime, taxis_t *taxis)
}
else
if
(
taxis
->
unit
==
TUNIT_SECOND
)
{
int
hour
,
minute
,
second
,
ms
;
cdiTime_decode
(
datetime
.
time
,
&
hour
,
&
minute
,
&
second
,
&
ms
);
timeValue
=
hour
*
3600
+
minute
*
60
+
second
;
timeValue
=
datetime2seconds
(
datetime
);
}
else
{
...
...
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