Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
fffe634e
Commit
fffe634e
authored
Feb 20, 2009
by
Uwe Schulzweida
Browse files
change default calendar to CALENDAR_PROLEPTIC
parent
def325f4
Changes
11
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
fffe634e
...
...
@@ -2,6 +2,7 @@
* add support for NaN in DBL_IS_EQUAL
* add support for GRID type LCC2 (LCC PROJ.4 version)
* change default calendar to CALENDAR_PROLEPTIC
* streamOpenAppen: set ncmode to 2 (bug fix)
* Version 1.3.0 released
...
...
app/cdi.c
View file @
fffe634e
...
...
@@ -13,22 +13,21 @@
#include
"cdi.h"
#ifndef DBL_IS_
EQUAL
#if defined (
XXX_
HAVE_ISNAN)
#ifndef DBL_IS_
NAN
#if defined (HAVE_ISNAN)
# define DBL_IS_NAN(x) (isnan(x))
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#elif defined (XXX_FP_NAN)
#elif defined (FP_NAN)
# define DBL_IS_NAN(x) (fpclassify(x) == FP_NAN)
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#else
# define DBL_IS_NAN(x) ((x) != (x))
/*
# define DBL_IS_EQUAL(x,y) (!(x < y || y < x))
*/
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#endif
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#ifndef IS_EQUAL
# define IS_NOT_EQUAL(x,y) (x < y || y < x)
# define IS_EQUAL(x,y) (!IS_NOT_EQUAL(x,y))
...
...
@@ -660,8 +659,8 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
{
if
(
calendar
==
CALENDAR_STANDARD
)
fprintf
(
stdout
,
" Calendar = STANDARD"
);
else
if
(
calendar
==
CALENDAR_
NONE
)
fprintf
(
stdout
,
" Calendar =
NONE
"
);
else
if
(
calendar
==
CALENDAR_
PROLEPTIC
)
fprintf
(
stdout
,
" Calendar =
PROLEPTIC
"
);
else
if
(
calendar
==
CALENDAR_360DAYS
)
fprintf
(
stdout
,
" Calendar = 360DAYS"
);
else
if
(
calendar
==
CALENDAR_365DAYS
)
...
...
src/calendar.c
View file @
fffe634e
...
...
@@ -59,12 +59,22 @@ int days_per_year(int calendar, int year)
if
(
dpy
==
0
)
{
if
(
year
==
1582
)
dpy
=
355
;
else
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
dpy
=
366
;
if
(
calendar
==
CALENDAR_STANDARD
)
{
if
(
year
==
1582
)
dpy
=
355
;
else
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
dpy
=
366
;
else
dpy
=
365
;
}
else
dpy
=
365
;
{
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
dpy
=
366
;
else
dpy
=
365
;
}
}
daysperyear
=
dpy
;
...
...
@@ -128,7 +138,7 @@ int date_to_calday(int calendar, int date)
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
calday
=
encode_day
(
dpy
,
year
,
month
,
day
);
else
calday
=
encode_julday
(
year
,
month
,
day
);
calday
=
encode_julday
(
calendar
,
year
,
month
,
day
);
return
(
calday
);
}
...
...
@@ -145,7 +155,7 @@ int calday_to_date(int calendar, int calday)
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
decode_day
(
dpy
,
calday
,
&
year
,
&
month
,
&
day
);
else
decode_julday
(
calday
,
&
year
,
&
month
,
&
day
);
decode_julday
(
calendar
,
calday
,
&
year
,
&
month
,
&
day
);
date
=
encode_date
(
year
,
month
,
day
);
...
...
@@ -162,7 +172,7 @@ void encode_caldaysec(int calendar, int year, int month, int day, int hour, int
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
*
julday
=
encode_day
(
dpy
,
year
,
month
,
day
);
else
*
julday
=
encode_julday
(
year
,
month
,
day
);
*
julday
=
encode_julday
(
calendar
,
year
,
month
,
day
);
*
secofday
=
(
hour
*
60
+
minute
)
*
60
;
}
...
...
@@ -177,7 +187,7 @@ void decode_caldaysec(int calendar, int julday, int secofday, int *year, int *mo
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
decode_day
(
dpy
,
julday
,
year
,
month
,
day
);
else
decode_julday
(
julday
,
year
,
month
,
day
);
decode_julday
(
calendar
,
julday
,
year
,
month
,
day
);
*
hour
=
secofday
/
3600
;
*
minute
=
secofday
/
60
-
*
hour
*
60
;
...
...
src/cdi.h
View file @
fffe634e
...
...
@@ -149,12 +149,12 @@ extern "C" {
/* CALENDAR types */
#define CALENDAR_STANDARD 0
#define CALENDAR_
NONE
1
#define CALENDAR_STANDARD 0
/* don't change this value (used also in griblib)! */
#define CALENDAR_
PROLEPTIC
1
#define CALENDAR_360DAYS 2
#define CALENDAR_365DAYS 3
#define CALENDAR_366DAYS 4
#define CALENDAR_
PROLEPTIC
5
#define CALENDAR_
NONE
5
/* CDI control routines */
...
...
src/griblib.c
View file @
fffe634e
/* Generated automatically from m214003 on Tue Feb 17 1
1:26:3
3 CET 2009 */
/* Generated automatically from m214003 on Tue Feb 17 1
5:08:4
3 CET 2009 */
/* GRIBLIB_VERSION="1.2.2" */
...
...
@@ -63,22 +63,21 @@
#endif
#ifndef DBL_IS_
EQUAL
#if defined (
XXX_
HAVE_ISNAN)
#ifndef DBL_IS_
NAN
#if defined (HAVE_ISNAN)
# define DBL_IS_NAN(x) (isnan(x))
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#elif defined (XXX_FP_NAN)
#elif defined (FP_NAN)
# define DBL_IS_NAN(x) (fpclassify(x) == FP_NAN)
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#else
# define DBL_IS_NAN(x) ((x) != (x))
/*
# define DBL_IS_EQUAL(x,y) (!(x < y || y < x))
*/
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#endif
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#ifndef IS_EQUAL
# define IS_NOT_EQUAL(x,y) (x < y || y < x)
# define IS_EQUAL(x,y) (!IS_NOT_EQUAL(x,y))
...
...
@@ -1067,7 +1066,7 @@ void gribDateTime(int *isec1, int *date, int *time)
{
if
(
ISEC1_TimeRange
==
0
||
ISEC1_TimeRange
==
10
)
{
encode_juldaysec
(
ryear
,
rmonth
,
rday
,
rhour
,
rminute
,
&
julday
,
&
secofday
);
encode_juldaysec
(
0
,
ryear
,
rmonth
,
rday
,
rhour
,
rminute
,
&
julday
,
&
secofday
);
addsec
=
0
;
switch
(
ISEC1_TimeUnit
)
...
...
@@ -1085,7 +1084,7 @@ void gribDateTime(int *isec1, int *date, int *time)
julday_add_seconds
(
addsec
,
&
julday
,
&
secofday
);
decode_juldaysec
(
julday
,
secofday
,
&
ryear
,
&
rmonth
,
&
rday
,
&
rhour
,
&
rminute
);
decode_juldaysec
(
0
,
julday
,
secofday
,
&
ryear
,
&
rmonth
,
&
rday
,
&
rhour
,
&
rminute
);
}
}
/*
...
...
@@ -8380,7 +8379,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return
(
gribLen
);
}
static
const
char
grb_libvers
[]
=
"1.2.2"
" of ""Feb 17 2009"" ""1
1:26:3
3"
;
static
const
char
grb_libvers
[]
=
"1.2.2"
" of ""Feb 17 2009"" ""1
5:08:4
3"
;
const
char
*
gribLibraryVersion
(
void
)
{
...
...
src/stream_cdf.c
View file @
fffe634e
...
...
@@ -781,11 +781,12 @@ void cdfDefTime(int streamID)
{
calstr
[
0
]
=
0
;
if
(
taxis
->
calendar
==
CALENDAR_NONE
)
strcpy
(
calstr
,
"none"
);
if
(
taxis
->
calendar
==
CALENDAR_STANDARD
)
strcpy
(
calstr
,
"standard"
);
else
if
(
taxis
->
calendar
==
CALENDAR_PROLEPTIC
)
strcpy
(
calstr
,
"proleptic_gregorian"
);
else
if
(
taxis
->
calendar
==
CALENDAR_NONE
)
strcpy
(
calstr
,
"none"
);
else
if
(
taxis
->
calendar
==
CALENDAR_360DAYS
)
strcpy
(
calstr
,
"360_day"
);
else
if
(
taxis
->
calendar
==
CALENDAR_365DAYS
)
strcpy
(
calstr
,
"365_day"
);
else
if
(
taxis
->
calendar
==
CALENDAR_366DAYS
)
strcpy
(
calstr
,
"366_day"
);
else
if
(
taxis
->
calendar
==
CALENDAR_PROLEPTIC
)
strcpy
(
calstr
,
"proleptic_gregorian"
);
len
=
strlen
(
calstr
);
if
(
len
)
...
...
@@ -5466,6 +5467,8 @@ int cdfInqContents(int streamID)
calendar
=
CALENDAR_STANDARD
;
else
if
(
strcmp
(
attstring
,
"none"
)
==
0
)
calendar
=
CALENDAR_NONE
;
else
if
(
strncmp
(
attstring
,
"proleptic"
,
9
)
==
0
)
calendar
=
CALENDAR_PROLEPTIC
;
else
if
(
strncmp
(
attstring
,
"360"
,
3
)
==
0
)
calendar
=
CALENDAR_360DAYS
;
else
if
(
strncmp
(
attstring
,
"365"
,
3
)
==
0
||
...
...
@@ -5474,8 +5477,6 @@ int cdfInqContents(int streamID)
else
if
(
strncmp
(
attstring
,
"366"
,
3
)
==
0
||
strcmp
(
attstring
,
"all_leap"
)
==
0
)
calendar
=
CALENDAR_366DAYS
;
else
if
(
strncmp
(
attstring
,
"proleptic"
,
9
)
==
0
)
calendar
=
CALENDAR_PROLEPTIC
;
else
Warning
(
func
,
"calendar >%s< unsupported!"
,
attstring
);
}
...
...
@@ -5493,6 +5494,17 @@ int cdfInqContents(int streamID)
taxis
->
calendar
=
calendar
;
taxisDefCalendar
(
taxisID
,
calendar
);
}
else
{
/*
printf("cal %d %d %d\n", calendar, streamptr->tsteps[0].taxis.type, TAXIS_RELATIVE);
printf("inq1 %d\n", taxisInqCalendar(taxisID));
*/
if
(
streamptr
->
tsteps
[
0
].
taxis
.
type
==
TAXIS_RELATIVE
)
taxisDefCalendar
(
taxisID
,
CALENDAR_STANDARD
);
/*
printf("inq2 %d\n", taxisInqCalendar(taxisID));
*/
}
vlistDefTaxis
(
vlistID
,
taxisID
);
...
...
src/stream_grb.c
View file @
fffe634e
...
...
@@ -1710,7 +1710,9 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
int
rdate
,
rtime
;
int
julday1
,
secofday1
,
julday2
,
secofday2
,
days
,
secs
;
int
ival
;
int
calendar
;
calendar
=
taxisInqCalendar
(
timeID
);
rdate
=
taxisInqRdate
(
timeID
);
rtime
=
taxisInqRtime
(
timeID
);
decode_date
(
rdate
,
&
year
,
&
month
,
&
day
);
...
...
@@ -1742,7 +1744,7 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
/*
printf("year %d, month %d, day %d, hour %d, minute %d\n", year, month, day, hour, minute);
*/
encode_juldaysec
(
year
,
month
,
day
,
hour
,
minute
,
&
julday1
,
&
secofday1
);
encode_juldaysec
(
calendar
,
year
,
month
,
day
,
hour
,
minute
,
&
julday1
,
&
secofday1
);
switch
(
taxisInqTunit
(
timeID
))
{
...
...
@@ -1757,7 +1759,7 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
printf("date time %d %d\n", date, time);
printf("year %d, month %d, day %d, hour %d, minute %d\n", year, month, day, hour, minute);
*/
encode_juldaysec
(
year
,
month
,
day
,
hour
,
minute
,
&
julday2
,
&
secofday2
);
encode_juldaysec
(
calendar
,
year
,
month
,
day
,
hour
,
minute
,
&
julday2
,
&
secofday2
);
(
void
)
julday_sub
(
julday1
,
secofday1
,
julday2
,
secofday2
,
&
days
,
&
secs
);
/* ival = (int) ((days*86400.0 + secs)/factor); */
...
...
src/stream_int.h
View file @
fffe634e
...
...
@@ -58,22 +58,21 @@ char *strdup(const char *s);
#endif
#ifndef DBL_IS_
EQUAL
#if defined (
XXX_
HAVE_ISNAN)
#ifndef DBL_IS_
NAN
#if defined (HAVE_ISNAN)
# define DBL_IS_NAN(x) (isnan(x))
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#elif defined (XXX_FP_NAN)
#elif defined (FP_NAN)
# define DBL_IS_NAN(x) (fpclassify(x) == FP_NAN)
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#else
# define DBL_IS_NAN(x) ((x) != (x))
/*
# define DBL_IS_EQUAL(x,y) (!(x < y || y < x))
*/
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#endif
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#ifndef IS_EQUAL
# define IS_NOT_EQUAL(x,y) (x < y || y < x)
# define IS_EQUAL(x,y) (!IS_NOT_EQUAL(x,y))
...
...
src/taxis.c
View file @
fffe634e
...
...
@@ -10,9 +10,9 @@
#include
"stream_int.h"
#include
"calendar.h"
int
DefaultTimeType
=
TAXIS_ABSOLUTE
;
int
DefaultTimeUnit
=
TUNIT_HOUR
;
int
DefaultCalendar
=
CALENDAR_
STANDARD
;
static
int
DefaultTimeType
=
TAXIS_ABSOLUTE
;
static
int
DefaultTimeUnit
=
TUNIT_HOUR
;
static
int
DefaultCalendar
=
CALENDAR_
PROLEPTIC
;
char
*
Timeunits
[]
=
{
...
...
@@ -215,6 +215,7 @@ void taxis_init_ptr(TAXIS *taxisptr)
taxisptr
->
vtime_ub
=
0
;
}
void
taxis_init_entry
(
TAXIS
*
taxisptr
)
{
taxis_init_ptr
(
taxisptr
);
...
...
@@ -537,8 +538,8 @@ void taxisDefRtime(int taxisID, int rtime)
@Parameter
@Item taxisID Time axis ID, from a previous call to @fref{taxisCreate}
@Item calendar The type of the calendar, one of the set of predefined CDI calendar types.
The valid CDI calendar types are @func{CALENDAR_STANDARD}, @func{CALENDAR_
360DAYS
},
@func{CALENDAR_365DAYS} and @func{CALENDAR_366DAYS}.
The valid CDI calendar types are @func{CALENDAR_STANDARD}, @func{CALENDAR_
PROLEPTIC
},
@func{CALENDAR_360DAYS},
@func{CALENDAR_365DAYS} and @func{CALENDAR_366DAYS}.
@Description
The function @func{taxisDefCalendar} defines the calendar of a Time axis.
...
...
@@ -843,8 +844,8 @@ The function @func{taxisInqCalendar} returns the calendar of a Time axis.
@Result
@func{taxisInqCalendar} returns the type of the calendar,
one of the set of predefined CDI calendar types.
The valid CDI calendar types are @func{CALENDAR_STANDARD}, @func{CALENDAR_
360DAYS
},
@func{CALENDAR_365DAYS} and @func{CALENDAR_366DAYS}.
The valid CDI calendar types are @func{CALENDAR_STANDARD}, @func{CALENDAR_
PROLEPRIC
},
@func{CALENDAR_360DAYS},
@func{CALENDAR_365DAYS} and @func{CALENDAR_366DAYS}.
@EndFunction
*/
...
...
src/timebase.c
View file @
fffe634e
#include
<stdio.h>
#include
<math.h>
/* for floor() */
#include
"cdi.h"
void
decode_date
(
int
date
,
int
*
year
,
int
*
month
,
int
*
day
)
{
...
...
@@ -46,26 +48,24 @@ int encode_time(int hour, int minute)
/* convert Julian date into year, months, day */
void
decode_julday
(
int
julday
,
/* Julian day number to convert */
int
*
year
,
/* Gregorian year (out) */
int
*
mon
,
/* Gregorian month (1-12) (out) */
int
*
day
/* Gregorian day (1-31) (out) */
)
void
decode_julday
(
int
calendar
,
int
julday
,
/* Julian day number to convert */
int
*
year
,
/* Gregorian year (out) */
int
*
mon
,
/* Gregorian month (1-12) (out) */
int
*
day
)
/* Gregorian day (1-31) (out) */
{
int
a
=
julday
;
double
b
,
c
;
double
d
,
e
,
f
;
if
(
a
<
2299161
)
{
c
=
a
+
1524
;
}
else
{
b
=
floor
((
a
-
1867216
.
25
)
/
36524
.
25
);
c
=
a
+
b
-
floor
(
b
/
4
)
+
1525
;
}
b
=
floor
((
a
-
1867216
.
25
)
/
36524
.
25
);
c
=
a
+
b
-
floor
(
b
/
4
)
+
1525
;
if
(
calendar
==
CALENDAR_STANDARD
)
if
(
a
<
2299161
)
{
c
=
a
+
1524
;
}
d
=
floor
((
c
-
122
.
1
)
/
365
.
25
);
e
=
floor
(
365
.
25
*
d
);
...
...
@@ -76,8 +76,9 @@ void decode_julday(
*
year
=
(
int
)(
d
-
4715
-
floor
((
7
+
*
mon
)
/
10
));
}
/* convert year, month, day into Julian calendar day */
int
encode_julday
(
int
year
,
int
month
,
int
day
)
int
encode_julday
(
int
calendar
,
int
year
,
int
month
,
int
day
)
{
int
iy
;
int
im
;
...
...
@@ -101,18 +102,21 @@ int encode_julday(int year, int month, int day)
else
ib
=
(
int
)(
iy
/
400
)
-
(
int
)(
iy
/
100
);
if
(
year
>
1582
||
(
year
==
1582
&&
(
month
>
10
||
(
month
==
10
&&
day
>=
15
)))
)
if
(
calendar
==
CALENDAR_STANDARD
)
{
/*
** 15th October 1582 AD or later
*/
}
else
{
/*
** 4th October 1582 AD or earlier
*/
ib
=
-
2
;
if
(
year
>
1582
||
(
year
==
1582
&&
(
month
>
10
||
(
month
==
10
&&
day
>=
15
)))
)
{
/*
** 15th October 1582 AD or later
*/
}
else
{
/*
** 4th October 1582 AD or earlier
*/
ib
=
-
2
;
}
}
julday
=
(
int
)
(
floor
(
365
.
25
*
iy
)
+
(
int
)(
30
.
6001
*
(
im
+
1
))
+
ib
+
1720996
.
5
+
day
+
0
.
5
);
...
...
@@ -121,25 +125,25 @@ int encode_julday(int year, int month, int day)
}
int
date_to_julday
(
int
date
)
int
date_to_julday
(
int
calendar
,
int
date
)
{
int
julday
;
int
year
,
month
,
day
;
decode_date
(
date
,
&
year
,
&
month
,
&
day
);
julday
=
encode_julday
(
year
,
month
,
day
);
julday
=
encode_julday
(
calendar
,
year
,
month
,
day
);
return
(
julday
);
}
int
julday_to_date
(
int
julday
)
int
julday_to_date
(
int
calendar
,
int
julday
)
{
int
date
;
int
year
,
month
,
day
;
decode_julday
(
julday
,
&
year
,
&
month
,
&
day
);
decode_julday
(
calendar
,
julday
,
&
year
,
&
month
,
&
day
);
date
=
encode_date
(
year
,
month
,
day
);
...
...
@@ -205,7 +209,7 @@ void julday_add(int days, int secs, int *julday, int *secofday)
}
/* subtract julday1/secofday1 from julday2/secofday2 and returns the result in seconds */
int
julday_sub
(
int
julday1
,
int
secofday1
,
int
julday2
,
int
secofday2
,
int
*
days
,
int
*
secs
)
double
julday_sub
(
int
julday1
,
int
secofday1
,
int
julday2
,
int
secofday2
,
int
*
days
,
int
*
secs
)
{
int
seconds
;
...
...
@@ -218,23 +222,23 @@ int julday_sub(int julday1, int secofday1, int julday2, int secofday2, int *days
*
secs
+=
86400
;
}
seconds
=
*
days
*
86400
+
*
secs
;
seconds
=
*
days
*
86400
.
+
*
secs
;
return
(
seconds
);
}
void
encode_juldaysec
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
*
julday
,
int
*
secofday
)
void
encode_juldaysec
(
int
calendar
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
*
julday
,
int
*
secofday
)
{
*
julday
=
encode_julday
(
year
,
month
,
day
);
*
julday
=
encode_julday
(
calendar
,
year
,
month
,
day
);
*
secofday
=
(
hour
*
60
+
minute
)
*
60
;
}
void
decode_juldaysec
(
int
julday
,
int
secofday
,
int
*
year
,
int
*
month
,
int
*
day
,
int
*
hour
,
int
*
minute
)
void
decode_juldaysec
(
int
calendar
,
int
julday
,
int
secofday
,
int
*
year
,
int
*
month
,
int
*
day
,
int
*
hour
,
int
*
minute
)
{
decode_julday
(
julday
,
year
,
month
,
day
);
decode_julday
(
calendar
,
julday
,
year
,
month
,
day
);
*
hour
=
secofday
/
3600
;
*
minute
=
secofday
/
60
-
*
hour
*
60
;
...
...
@@ -265,10 +269,10 @@ int main(void)
decode_date
(
vdate0
,
&
year
,
&
mon
,
&
day
);
decode_time
(
vtime0
,
&
hour
,
&
min
);
julday
=
date_to_julday
(
vdate0
);
julday
=
date_to_julday
(
calendar
,
vdate0
);
secofday
=
time_to_sec
(
vtime0
);
vdate
=
julday_to_date
(
julday
);
vdate
=
julday_to_date
(
calendar
,
julday
);
vtime
=
sec_to_time
(
secofday
);
if
(
vdate0
!=
vdate
||
vtime0
!=
vtime
)
...
...
@@ -291,7 +295,7 @@ int main(void)
printf
(
"start time: %8d %4d
\n
"
,
vdate0
,
vtime0
);
julday
=
date_to_julday
(
vdate0
);
julday
=
date_to_julday
(
calendar
,
vdate0
);
secofday
=
time_to_sec
(
vtime0
);
for
(
i
=
0
;
i
<
nmin
;
i
++
)
{
...
...
@@ -321,7 +325,7 @@ int main(void)
julday_add_seconds
(
ijulinc
,
&
julday
,
&
secofday
);
vdate
=
julday_to_date
(
julday
);
vdate
=
julday_to_date
(
calendar
,
julday
);
vtime
=
sec_to_time
(
secofday
);
if
(
vdate0
!=
vdate
||
vtime0
!=
vtime
)
printf
(
"%4d %8d %4d %8d %4d %9d %9d
\n
"
,
...
...
@@ -348,15 +352,15 @@ int main(void)
printf
(
"%d/%02d/%02d %02d:%02d
\n
"
,
year
,
month
,
day
,
hour
,
minute
);
encode_juldaysec
(
year
,
month
,
day
,
hour
,
minute
,
&
julday
,
&
secofday
);
encode_juldaysec
(
calendar
,
year
,
month
,
day
,
hour
,
minute
,
&
julday
,
&
secofday
);
decode_juldaysec
(
julday
,
secofday
,
&
year
,
&
month
,
&
day
,
&
hour
,
&
minute
);
decode_juldaysec
(
calendar
,
julday
,
secofday
,
&
year
,
&
month
,
&
day
,
&
hour
,
&
minute
);
printf
(
"%d/%02d/%02d %02d:%02d %d %d
\n
"
,
year
,
month
,
day
,
hour
,
minute
,
julday
,
secofday
);
for
(
i
=
0
;
i
<
420
;
i
++
)
{
decode_juldaysec
(
julday
,
secofday
,
&
year
,
&
month
,
&
day
,
&
hour
,
&
minute
);
decode_juldaysec
(
calendar
,
julday
,
secofday
,
&
year
,
&
month
,
&
day
,
&
hour
,
&
minute
);
printf
(
"%2d %d/%02d/%02d %02d:%02d
\n
"
,
i
,
year
,
month
,
day
,
hour
,
minute
);
julday_add_seconds
(
value
*
factor
,
&
julday
,
&
secofday
);
}
...
...
src/timebase.h
View file @
fffe634e
...
...
@@ -5,25 +5,25 @@
/* time format: hhmm */
void
decode_date
(
int
date
,
int
*
year
,
int
*
month
,
int
*
day
);
int
encode_date
(
int
year
,
int
month
,
int
day
);
int
encode_date
(
int
year
,
int
month
,
int
day
);
void
decode_time
(
int
time
,
int
*
hour
,
int
*
minute
);
int
encode_time
(
int
hour
,
int
minute
);
int
encode_time
(
int
hour
,
int
minute
);
void
decode_julday
(
int
julday
,
int
*
year
,
int
*
mon
,
int
*
day
);
int
encode_julday
(
int
year
,
int
month
,
int
day
);
void
decode_julday
(
int
calendar
,
int
julday
,
int
*
year
,
int
*
mon
,
int
*
day
);
int
encode_julday
(
int
calendar
,
int
year
,
int
month
,
int
day
);
int
date_to_julday
(
int
date
);
int
julday_to_date
(
int
julday
);
int
date_to_julday
(
int
calendar
,
int
date
);
int
julday_to_date
(
int
calendar
,
int
julday
);
int
time_to_sec
(
int
time
);
int
sec_to_time
(
int
secofday
);
void
julday_add_seconds
(
int
seconds
,
int
*
julday
,
int
*
secofday
);
void
julday_add
(
int
days
,
int
secs
,
int
*
julday
,
int
*
secofday
);
int
julday_sub
(
int
julday1
,
int
secofday1
,
int
julday2
,
int
secofday2
,
int
*
days
,
int
*
secs
);
void
julday_add_seconds
(
int
seconds
,
int
*
julday
,
int
*
secofday
);
void
julday_add
(
int
days
,
int
secs
,
int
*
julday
,
int
*
secofday
);
double
julday_sub
(
int
julday1
,
int
secofday1
,
int
julday2
,
int
secofday2
,
int
*
days
,
int
*
secs
);
void
encode_juldaysec
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
*
julday
,
int
*
secofday
);
void
decode_juldaysec
(
int
julday
,
int
secofday
,
int
*
year
,
int
*
month
,
int
*
day
,
int
*
hour
,
int
*
minute
);
void
encode_juldaysec
(
int
calendar
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
*
julday
,
int
*
secofday
);
void
decode_juldaysec
(
int
calendar
,
int
julday
,
int
secofday
,
int
*
year
,
int
*
month
,
int
*
day
,
int
*
hour
,
int
*
minute
);
#endif
/* _TIMEBASE_H */
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment