From fa1c08fb64c6af786bc1d5d9b90003bef82cedec Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Mon, 21 Jun 2010 12:13:24 +0000 Subject: [PATCH] added support for timeunit 's' --- src/cdi_limits.h | 2 +- src/stream_cdf.c | 4 ++++ src/taxis.c | 51 ++++++++++++++++++++++++++++-------------------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/cdi_limits.h b/src/cdi_limits.h index c458573e7..5f7be81f2 100644 --- a/src/cdi_limits.h +++ b/src/cdi_limits.h @@ -8,7 +8,7 @@ #define MIN_TAXES 1024 /* minimum number of taxes */ #define MAX_TAXES 65536 /* maximum number of taxes */ #define MAX_ZAXES 1024 /* maximum number of zaxes */ -#define MAX_GRIDS 1024 /* maximum number of grids */ +#define MAX_GRIDS 8192 /* maximum number of grids */ #define MAX_INSTS 1024 /* maximum number of instituts */ #define MAX_MODELS 1024 /* maximum number of models */ #define MAX_GRIDS_PS 128 /* maximum number of different grids per stream */ diff --git a/src/stream_cdf.c b/src/stream_cdf.c index db43c73fc..854f729c8 100644 --- a/src/stream_cdf.c +++ b/src/stream_cdf.c @@ -125,6 +125,10 @@ int get_timeunit(int len, char *ptu) else if ( memcmp(ptu, "calendar_month", 14) == 0 ) timeunit = TUNIT_MONTH; else if ( memcmp(ptu, "year", 4) == 0 ) timeunit = TUNIT_YEAR; } + else if ( len == 1 ) + { + if ( ptu[0] == 's' ) timeunit = TUNIT_SECOND; + } return (timeunit); } diff --git a/src/taxis.c b/src/taxis.c index 6f68907c5..cf2ef71de 100644 --- a/src/taxis.c +++ b/src/taxis.c @@ -1214,6 +1214,28 @@ double vtime2timeval(int vdate, int vtime, taxis_t *taxis) } +void conv_timeval(double timevalue, int *rvdate, int *rvtime) +{ + int vdate = 0, vtime = 0; + int hour, minute, second; + int daysec; + + vdate = (int) timevalue; + if ( vdate < 0 ) + daysec = (int) (-(timevalue - vdate)*86400 + 0.01); + else + daysec = (int) ( (timevalue - vdate)*86400 + 0.01); + + hour = daysec / 3600; + minute = (daysec - hour*3600)/60; + second = daysec - hour*3600 - minute*60; + vtime = cdiEncodeTime(hour, minute, second); + + *rvdate = vdate; + *rvtime = vtime; +} + + void splitTimevalue(double timevalue, int timeunit, int *date, int *time) { static char func[] = "splitTimevalue"; @@ -1223,32 +1245,19 @@ void splitTimevalue(double timevalue, int timeunit, int *date, int *time) int daysec; static int lwarn = TRUE; - if ( timeunit == TUNIT_HOUR ) + if ( timeunit == TUNIT_SECOND ) + { + timevalue /= 86400; + conv_timeval(timevalue, &vdate, &vtime); + } + else if ( timeunit == TUNIT_HOUR ) { timevalue /= 24; - vdate = (int) timevalue; - if ( vdate < 0 ) - daysec = (int) (-(timevalue - vdate)*86400 + 0.01); - else - daysec = (int) ( (timevalue - vdate)*86400 + 0.01); - - hour = daysec / 3600; - minute = (daysec - hour*3600)/60; - second = daysec - hour*3600 - minute*60; - vtime = cdiEncodeTime(hour, minute, second); + conv_timeval(timevalue, &vdate, &vtime); } else if ( timeunit == TUNIT_DAY ) { - vdate = (int) timevalue; - if ( vdate < 0 ) - daysec = (int) (-(timevalue - vdate)*86400 + 0.01); - else - daysec = (int) ( (timevalue - vdate)*86400 + 0.01); - - hour = daysec / 3600; - minute = (daysec - hour*3600)/60; - second = daysec - hour*3600 - minute*60; - vtime = cdiEncodeTime(hour, minute, second); + conv_timeval(timevalue, &vdate, &vtime); } else if ( timeunit == TUNIT_MONTH ) { -- GitLab