Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
65fe1fc5
Commit
65fe1fc5
authored
Dec 12, 2014
by
Uwe Schulzweida
Browse files
renamed datetimelist to datetime
parent
15e308d9
Changes
9
Hide whitespace changes
Inline
Side-by-side
.gitattributes
View file @
65fe1fc5
...
...
@@ -524,8 +524,8 @@ src/commandline.c -text
src/config.h.in -text
src/const.h -text
src/counter.h -text
src/datetime
list
.c -text
src/datetime
list
.h -text
src/datetime.c -text
src/datetime.h -text
src/dmemory.h -text
src/dtypes.h -text
src/ecacore.c -text
...
...
src/Makefile.am
View file @
65fe1fc5
...
...
@@ -191,8 +191,8 @@ cdo_SOURCES += Adisit.c \
commandline.c
\
const.h
\
counter.h
\
datetime
list.c
\
datetime
list.h
\
datetime
.c
\
datetime
.h
\
dmemory.h
\
dtypes.h
\
ecacore.c
\
...
...
src/Makefile.in
View file @
65fe1fc5
...
...
@@ -147,13 +147,13 @@ am__cdo_SOURCES_DIST = cdo.c Adisit.c Arith.c Arithc.c Arithdays.c \
Ydrunpctl.c Ydrunstat.c Yhourarith.c Yhourstat.c Ymonarith.c \
Ymonpctl.c Ymonstat.c Yseaspctl.c Yseasstat.c Zonstat.c cdo.h \
cdo_int.h cdo_pthread.c cdo_vlist.c cdo_getopt.c cdo_getopt.h \
color.c color.h commandline.c const.h counter.h datetime
list
.c \
datetime
list
.h dmemory.h dtypes.h ecacore.c ecacore.h \
ecautil.c
ecautil.h error.h etopo.h temp.h mask.h exception.c \
expr.c
expr.h expr_lex.c expr_yacc.c expr_yacc.h features.c \
field.c
field.h field2.c fieldc.c fieldmem.c fieldmer.c \
fieldzon.c
fouriertrans.c functs.h gradsdeslib.c gradsdeslib.h \
grid.c
grid.h grid_area.c grid_gme.c grid_lcc.c grid_rot.c \
color.c color.h commandline.c const.h counter.h datetime.c \
datetime.h dmemory.h dtypes.h ecacore.c ecacore.h
ecautil.c
\
ecautil.h error.h etopo.h temp.h mask.h exception.c
expr.c
\
expr.h expr_lex.c expr_yacc.c expr_yacc.h features.c
field.c
\
field.h field2.c fieldc.c fieldmem.c fieldmer.c
fieldzon.c
\
fouriertrans.c functs.h gradsdeslib.c gradsdeslib.h
grid.c
\
grid.h grid_area.c grid_gme.c grid_lcc.c grid_rot.c \
gridreference.c griddes.c griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h history.c institution.c interpol.c \
interpol.h job.c juldate.c kvlist.c kvlist.h legendre.c list.c \
...
...
@@ -274,7 +274,7 @@ am_cdo_OBJECTS = cdo-cdo.$(OBJEXT) cdo-Adisit.$(OBJEXT) \
cdo-Zonstat.$(OBJEXT) cdo-cdo_pthread.$(OBJEXT) \
cdo-cdo_vlist.$(OBJEXT) cdo-cdo_getopt.$(OBJEXT) \
cdo-color.$(OBJEXT) cdo-commandline.$(OBJEXT) \
cdo-datetime
list
.$(OBJEXT) cdo-ecacore.$(OBJEXT) \
cdo-datetime.$(OBJEXT) cdo-ecacore.$(OBJEXT) \
cdo-ecautil.$(OBJEXT) cdo-exception.$(OBJEXT) \
cdo-expr.$(OBJEXT) cdo-expr_lex.$(OBJEXT) \
cdo-expr_yacc.$(OBJEXT) cdo-features.$(OBJEXT) \
...
...
@@ -597,13 +597,13 @@ cdo_SOURCES = cdo.c Adisit.c Arith.c Arithc.c Arithdays.c Arithlat.c \
Ydrunpctl.c Ydrunstat.c Yhourarith.c Yhourstat.c Ymonarith.c \
Ymonpctl.c Ymonstat.c Yseaspctl.c Yseasstat.c Zonstat.c cdo.h \
cdo_int.h cdo_pthread.c cdo_vlist.c cdo_getopt.c cdo_getopt.h \
color.c color.h commandline.c const.h counter.h datetime
list
.c \
datetime
list
.h dmemory.h dtypes.h ecacore.c ecacore.h \
ecautil.c
ecautil.h error.h etopo.h temp.h mask.h exception.c \
expr.c
expr.h expr_lex.c expr_yacc.c expr_yacc.h features.c \
field.c
field.h field2.c fieldc.c fieldmem.c fieldmer.c \
fieldzon.c
fouriertrans.c functs.h gradsdeslib.c gradsdeslib.h \
grid.c
grid.h grid_area.c grid_gme.c grid_lcc.c grid_rot.c \
color.c color.h commandline.c const.h counter.h datetime.c \
datetime.h dmemory.h dtypes.h ecacore.c ecacore.h
ecautil.c
\
ecautil.h error.h etopo.h temp.h mask.h exception.c
expr.c
\
expr.h expr_lex.c expr_yacc.c expr_yacc.h features.c
field.c
\
field.h field2.c fieldc.c fieldmem.c fieldmer.c
fieldzon.c
\
fouriertrans.c functs.h gradsdeslib.c gradsdeslib.h
grid.c
\
grid.h grid_area.c grid_gme.c grid_lcc.c grid_rot.c \
gridreference.c griddes.c griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h history.c institution.c interpol.c \
interpol.h job.c juldate.c kvlist.c kvlist.h legendre.c list.c \
...
...
@@ -974,7 +974,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-cdo_vlist.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-color.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-commandline.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-datetime
list
.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-datetime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-ecacore.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-ecautil.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-exception.Po@am__quote@
...
...
@@ -3640,19 +3640,19 @@ cdo-commandline.obj: commandline.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-commandline.obj `if test -f 'commandline.c'; then $(CYGPATH_W) 'commandline.c'; else $(CYGPATH_W) '$(srcdir)/commandline.c'; fi`
cdo-datetime
list
.o: datetime
list
.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetime
list
.o -MD -MP -MF $(DEPDIR)/cdo-datetime
list
.Tpo -c -o cdo-datetime
list
.o `test -f 'datetime
list
.c' || echo '$(srcdir)/'`datetime
list
.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetime
list
.Tpo $(DEPDIR)/cdo-datetime
list
.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetime
list
.c' object='cdo-datetime
list
.o' libtool=no @AMDEPBACKSLASH@
cdo-datetime.o: datetime.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetime.o -MD -MP -MF $(DEPDIR)/cdo-datetime.Tpo -c -o cdo-datetime.o `test -f 'datetime.c' || echo '$(srcdir)/'`datetime.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetime.Tpo $(DEPDIR)/cdo-datetime.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetime.c' object='cdo-datetime.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-datetime
list
.o `test -f 'datetime
list
.c' || echo '$(srcdir)/'`datetime
list
.c
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-datetime.o `test -f 'datetime.c' || echo '$(srcdir)/'`datetime.c
cdo-datetime
list
.obj: datetime
list
.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetime
list
.obj -MD -MP -MF $(DEPDIR)/cdo-datetime
list
.Tpo -c -o cdo-datetime
list
.obj `if test -f 'datetime
list
.c'; then $(CYGPATH_W) 'datetime
list
.c'; else $(CYGPATH_W) '$(srcdir)/datetime
list
.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetime
list
.Tpo $(DEPDIR)/cdo-datetime
list
.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetime
list
.c' object='cdo-datetime
list
.obj' libtool=no @AMDEPBACKSLASH@
cdo-datetime.obj: datetime.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetime.obj -MD -MP -MF $(DEPDIR)/cdo-datetime.Tpo -c -o cdo-datetime.obj `if test -f 'datetime.c'; then $(CYGPATH_W) 'datetime.c'; else $(CYGPATH_W) '$(srcdir)/datetime.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetime.Tpo $(DEPDIR)/cdo-datetime.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetime.c' object='cdo-datetime.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-datetime
list
.obj `if test -f 'datetime
list
.c'; then $(CYGPATH_W) 'datetime
list
.c'; else $(CYGPATH_W) '$(srcdir)/datetime
list
.c'; fi`
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-datetime.obj `if test -f 'datetime.c'; then $(CYGPATH_W) 'datetime.c'; else $(CYGPATH_W) '$(srcdir)/datetime.c'; fi`
cdo-ecacore.o: ecacore.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-ecacore.o -MD -MP -MF $(DEPDIR)/cdo-ecacore.Tpo -c -o cdo-ecacore.o `test -f 'ecacore.c' || echo '$(srcdir)/'`ecacore.c
...
...
src/Runstat.c
View file @
65fe1fc5
...
...
@@ -35,117 +35,6 @@
#include
"pstream.h"
void
datetime_avg_dtinfo
(
int
calendar
,
int
ndates
,
dtinfo_t
*
dtinfo
)
{
int
vdate
,
vtime
;
juldate_t
juldate1
,
juldate2
,
juldatem
;
double
seconds
;
/*
for ( i = 0; i < ndates; i++ )
fprintf(stdout, "%4d %d %d\n", i+1, dtinfo[i].v.date, dtinfo[i].v.time);
*/
if
(
ndates
%
2
==
0
)
{
/*
vdate = dtinfo[ndates-1].v.date;
vtime = dtinfo[ndates-1].v.time;
*/
vdate
=
dtinfo
[
ndates
/
2
-
1
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
-
1
].
v
.
time
;
juldate1
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
vdate
=
dtinfo
[
ndates
/
2
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
].
v
.
time
;
juldate2
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
seconds
=
juldate_to_seconds
(
juldate_sub
(
juldate2
,
juldate1
))
/
2
;
juldatem
=
juldate_add_seconds
((
int
)
lround
(
seconds
),
juldate1
);
juldate_decode
(
calendar
,
juldatem
,
&
vdate
,
&
vtime
);
}
else
{
vdate
=
dtinfo
[
ndates
/
2
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
].
v
.
time
;
}
dtinfo
[
ndates
].
v
.
date
=
vdate
;
dtinfo
[
ndates
].
v
.
time
=
vtime
;
/*
fprintf(stdout, "res: %d %d\n\n", dtinfo[ndates].v.date, dtinfo[ndates].v.time);
*/
}
void
datetime_avg
(
int
calendar
,
int
ndates
,
datetime_t
*
datetime
)
{
int
vdate
,
vtime
;
juldate_t
juldate1
,
juldate2
,
juldatem
;
double
seconds
;
/*
for ( i = 0; i < ndates; i++ )
fprintf(stdout, "%4d %d %d\n", i+1, datetime[i].date, datetime[i].time);
*/
if
(
ndates
%
2
==
0
)
{
/*
vdate = datetime[ndates-1].date;
vtime = datetime[ndates-1].time;
*/
vdate
=
datetime
[
ndates
/
2
-
1
].
date
;
vtime
=
datetime
[
ndates
/
2
-
1
].
time
;
juldate1
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
vdate
=
datetime
[
ndates
/
2
].
date
;
vtime
=
datetime
[
ndates
/
2
].
time
;
juldate2
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
seconds
=
juldate_to_seconds
(
juldate_sub
(
juldate2
,
juldate1
))
/
2
;
juldatem
=
juldate_add_seconds
((
int
)
lround
(
seconds
),
juldate1
);
juldate_decode
(
calendar
,
juldatem
,
&
vdate
,
&
vtime
);
}
else
{
vdate
=
datetime
[
ndates
/
2
].
date
;
vtime
=
datetime
[
ndates
/
2
].
time
;
}
datetime
[
ndates
].
date
=
vdate
;
datetime
[
ndates
].
time
=
vtime
;
/*
fprintf(stdout, "res: %d %d\n\n", datetime[ndates].date, datetime[ndates].time);
*/
}
void
get_timestat_date
(
int
*
tstat_date
)
{
char
*
envstr
;
envstr
=
getenv
(
"TIMESTAT_DATE"
);
if
(
envstr
==
NULL
)
envstr
=
getenv
(
"RUNSTAT_DATE"
);
if
(
envstr
)
{
int
env_date
=
-
1
;
char
envstrl
[
8
];
memcpy
(
envstrl
,
envstr
,
8
);
envstrl
[
7
]
=
0
;
strtolower
(
envstrl
);
if
(
memcmp
(
envstrl
,
"first"
,
5
)
==
0
)
env_date
=
DATE_FIRST
;
else
if
(
memcmp
(
envstrl
,
"last"
,
4
)
==
0
)
env_date
=
DATE_LAST
;
else
if
(
memcmp
(
envstrl
,
"middle"
,
6
)
==
0
)
env_date
=
DATE_MIDDLE
;
if
(
env_date
>=
0
)
{
*
tstat_date
=
env_date
;
if
(
cdoVerbose
)
cdoPrint
(
"Set TIMESTAT_DATE to %s"
,
envstr
);
}
}
}
void
*
Runstat
(
void
*
argument
)
{
int
operatorID
;
...
...
@@ -173,7 +62,7 @@ void *Runstat(void *argument)
int
taxisID1
,
taxisID2
;
int
calendar
;
int
runstat_nomiss
=
0
;
int
timestat_date
=
DATE_MIDDLE
;
int
timestat_date
=
TIMESTAT_MEAN
;
char
*
envstr
;
cdoInitialize
(
argument
);
...
...
@@ -361,9 +250,9 @@ void *Runstat(void *argument)
}
}
if
(
timestat_date
==
DATE_MIDDLE
)
datetime_avg_dtinfo
(
calendar
,
ndates
,
dtinfo
);
else
if
(
timestat_date
==
D
AT
E
_FIRST
)
dtinfo
[
ndates
].
v
=
dtinfo
[
0
].
v
;
else
if
(
timestat_date
==
D
AT
E
_LAST
)
dtinfo
[
ndates
].
v
=
dtinfo
[
ndates
-
1
].
v
;
if
(
timestat_date
==
TIMESTAT_MEAN
)
datetime_avg_dtinfo
(
calendar
,
ndates
,
dtinfo
);
else
if
(
timestat_date
==
TIMEST
AT_FIRST
)
dtinfo
[
ndates
].
v
=
dtinfo
[
0
].
v
;
else
if
(
timestat_date
==
TIMEST
AT_LAST
)
dtinfo
[
ndates
].
v
=
dtinfo
[
ndates
-
1
].
v
;
if
(
taxisHasBounds
(
taxisID2
)
)
{
...
...
src/Yearmonstat.c
View file @
65fe1fc5
...
...
@@ -55,7 +55,7 @@ void *Yearmonstat(void *argument)
char
vdatestr
[
32
],
vtimestr
[
32
];
field_t
**
vars1
=
NULL
,
**
samp1
=
NULL
;
field_t
field
;
int
timestat_date
=
DATE_MIDDLE
;
int
timestat_date
=
TIMESTAT_MEAN
;
dtinfo_t
dtinfo
[
13
];
cdoInitialize
(
argument
);
...
...
@@ -214,9 +214,9 @@ void *Yearmonstat(void *argument)
cdoPrint
(
"%s %s nsets = %d"
,
vdatestr
,
vtimestr
,
nsets
);
}
if
(
timestat_date
==
DATE_MIDDLE
)
datetime_avg_dtinfo
(
calendar
,
nsets
,
dtinfo
);
else
if
(
timestat_date
==
D
AT
E
_FIRST
)
dtinfo
[
nsets
].
v
=
dtinfo
[
0
].
v
;
else
if
(
timestat_date
==
D
AT
E
_LAST
)
dtinfo
[
nsets
].
v
=
dtinfo
[
nsets
-
1
].
v
;
if
(
timestat_date
==
TIMESTAT_MEAN
)
datetime_avg_dtinfo
(
calendar
,
nsets
,
dtinfo
);
else
if
(
timestat_date
==
TIMEST
AT_FIRST
)
dtinfo
[
nsets
].
v
=
dtinfo
[
0
].
v
;
else
if
(
timestat_date
==
TIMEST
AT_LAST
)
dtinfo
[
nsets
].
v
=
dtinfo
[
nsets
-
1
].
v
;
if
(
taxisHasBounds
(
taxisID2
)
)
{
...
...
src/cdo_int.h
View file @
65fe1fc5
...
...
@@ -34,7 +34,8 @@
#include
"dmemory.h"
#include
"process.h"
#include
"const.h"
#include
"datetimelist.h"
#include
"util.h"
#include
"datetime.h"
#define OPENMP4 201307
...
...
@@ -107,11 +108,6 @@ char *strdup(const char *s);
#define CDO_EXP_LOCAL 1
#define CDO_EXP_REMOTE 2
enum
{
DATE_FIRST
,
DATE_LAST
,
DATE_MIDDLE
};
void
strtolower
(
char
*
str
);
void
print_pthread_info
(
void
);
void
cdoProcessTime
(
double
*
utime
,
double
*
stime
);
...
...
@@ -137,19 +133,6 @@ void time2str(int time, char *timestr, int maxlen);
const
char
*
tunit2str
(
int
tunits
);
const
char
*
calendar2str
(
int
calendar
);
typedef
struct
{
int
julday
;
int
secofday
;
}
juldate_t
;
juldate_t
juldate_encode
(
int
calendar
,
int
date
,
int
time
);
void
juldate_decode
(
int
calendar
,
juldate_t
juldate
,
int
*
date
,
int
*
time
);
juldate_t
juldate_sub
(
juldate_t
juldate2
,
juldate_t
juldate1
);
juldate_t
juldate_add_seconds
(
int
seconds
,
juldate_t
juldate
);
double
juldate_to_seconds
(
juldate_t
juldate
);
int
days_per_month
(
int
calendar
,
int
year
,
int
month
);
int
days_per_year
(
int
calendar
,
int
year
);
int
calendar_dpy
(
int
calendar
);
...
...
src/datetime
list
.c
→
src/datetime.c
View file @
65fe1fc5
#include
"cdi.h"
#include
"dmemory.h"
#include
"util.h"
#include
"datetimelist.h"
#include
<string.h>
#include
<math.h>
#include
<cdi.h>
#include
"cdo.h"
#include
"datetime.h"
void
taxisInqDTinfo
(
int
taxisID
,
dtinfo_t
*
dtinfo
)
...
...
@@ -36,15 +38,17 @@ void dtlist_init(dtlist_type *dtlist)
dtlist
->
dtinfo
=
NULL
;
}
dtlist_type
*
dtlist_new
(
void
)
{
dtlist_type
*
dtlist
=
(
dtlist_type
*
)
malloc
(
sizeof
(
dtlist_type
));
printf
(
"init
\n
"
);
dtlist_init
(
dtlist
);
return
dtlist
;
}
void
dtlist_delete
(
dtlist_type
*
dtlist
)
{
if
(
dtlist
->
nalloc
>
0
&&
dtlist
->
dtinfo
)
...
...
@@ -53,6 +57,7 @@ void dtlist_delete(dtlist_type *dtlist)
free
(
dtlist
);
}
void
dtlist_taxisInqTimestep
(
int
taxisID
,
int
tsID
,
dtlist_type
*
dtlist
)
{
size_t
NALLOC
=
512
;
...
...
@@ -63,21 +68,44 @@ void dtlist_taxisInqTimestep(int taxisID, int tsID, dtlist_type *dtlist)
dtlist
->
dtinfo
=
(
dtinfo_type
*
)
realloc
(
dtlist
->
dtinfo
,
dtlist
->
nalloc
*
sizeof
(
dtinfo_type
));
}
dtlist
->
size
+=
1
;
if
(
(
size_t
)
tsID
>=
dtlist
->
size
)
dtlist
->
size
=
(
size_t
)
tsID
+
1
;
dtlist
->
dtinfo
[
tsID
].
v
.
date
=
taxisInqVdate
(
taxisID
);
dtlist
->
dtinfo
[
tsID
].
v
.
time
=
taxisInqVtime
(
taxisID
);
if
(
taxisHasBounds
(
taxisID
)
)
{
taxisInqVdateBounds
(
taxisID
,
&
(
dtlist
->
dtinfo
[
tsID
].
b
[
0
].
date
),
&
(
dtlist
->
dtinfo
[
tsID
].
b
[
1
].
date
));
taxisInqVtimeBounds
(
taxisID
,
&
(
dtlist
->
dtinfo
[
tsID
].
b
[
0
].
time
),
&
(
dtlist
->
dtinfo
[
tsID
].
b
[
1
].
time
));
}
else
{
dtlist
->
dtinfo
[
tsID
].
b
[
0
].
date
=
0
;
dtlist
->
dtinfo
[
tsID
].
b
[
1
].
date
=
0
;
dtlist
->
dtinfo
[
tsID
].
b
[
0
].
time
=
0
;
dtlist
->
dtinfo
[
tsID
].
b
[
1
].
time
=
0
;
}
}
void
dtlist_stat_taxisDefTimestep
(
int
taxisID
,
int
nsteps
,
const
dtlist_type
*
dtlist
)
{
if
(
(
size_t
)
nsteps
!=
dtlist
->
size
)
cdoAbort
(
"Internal error; unexpected nsteps!"
);
taxisDefVdate
(
taxisID
,
dtlist
->
timestat
.
v
.
date
);
taxisDefVtime
(
taxisID
,
dtlist
->
timestat
.
v
.
time
);
if
(
taxisHasBounds
(
taxisID
)
)
{
taxisDefVdateBounds
(
taxisID
,
dtlist
->
timestat
.
b
[
0
].
date
,
dtlist
->
timestat
.
b
[
1
].
date
);
taxisDefVtimeBounds
(
taxisID
,
dtlist
->
timestat
.
b
[
0
].
time
,
dtlist
->
timestat
.
b
[
1
].
time
);
}
}
void
dtlist_taxisDefTimestep
(
int
taxisID
,
int
tsID
,
const
dtlist_type
*
dtlist
)
{
if
(
(
size_t
)
tsID
>=
dtlist
->
size
)
if
(
tsID
<
0
||
(
size_t
)
tsID
>=
dtlist
->
size
)
cdoAbort
(
"Internal error; tsID out of bounds!"
);
taxisDefVdate
(
taxisID
,
dtlist
->
dtinfo
[
tsID
].
v
.
date
);
...
...
@@ -89,3 +117,113 @@ void dtlist_taxisDefTimestep(int taxisID, int tsID, const dtlist_type *dtlist)
}
}
void
datetime_avg_dtinfo
(
int
calendar
,
int
ndates
,
dtinfo_t
*
dtinfo
)
{
int
vdate
,
vtime
;
juldate_t
juldate1
,
juldate2
,
juldatem
;
double
seconds
;
/*
for ( i = 0; i < ndates; i++ )
fprintf(stdout, "%4d %d %d\n", i+1, dtinfo[i].v.date, dtinfo[i].v.time);
*/
if
(
ndates
%
2
==
0
)
{
/*
vdate = dtinfo[ndates-1].v.date;
vtime = dtinfo[ndates-1].v.time;
*/
vdate
=
dtinfo
[
ndates
/
2
-
1
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
-
1
].
v
.
time
;
juldate1
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
vdate
=
dtinfo
[
ndates
/
2
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
].
v
.
time
;
juldate2
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
seconds
=
juldate_to_seconds
(
juldate_sub
(
juldate2
,
juldate1
))
/
2
;
juldatem
=
juldate_add_seconds
((
int
)
lround
(
seconds
),
juldate1
);
juldate_decode
(
calendar
,
juldatem
,
&
vdate
,
&
vtime
);
}
else
{
vdate
=
dtinfo
[
ndates
/
2
].
v
.
date
;
vtime
=
dtinfo
[
ndates
/
2
].
v
.
time
;
}
dtinfo
[
ndates
].
v
.
date
=
vdate
;
dtinfo
[
ndates
].
v
.
time
=
vtime
;
/*
fprintf(stdout, "res: %d %d\n\n", dtinfo[ndates].v.date, dtinfo[ndates].v.time);
*/
}
void
datetime_avg
(
int
calendar
,
int
ndates
,
datetime_t
*
datetime
)
{
int
vdate
,
vtime
;
juldate_t
juldate1
,
juldate2
,
juldatem
;
double
seconds
;
/*
for ( i = 0; i < ndates; i++ )
fprintf(stdout, "%4d %d %d\n", i+1, datetime[i].date, datetime[i].time);
*/
if
(
ndates
%
2
==
0
)
{
/*
vdate = datetime[ndates-1].date;
vtime = datetime[ndates-1].time;
*/
vdate
=
datetime
[
ndates
/
2
-
1
].
date
;
vtime
=
datetime
[
ndates
/
2
-
1
].
time
;
juldate1
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
vdate
=
datetime
[
ndates
/
2
].
date
;
vtime
=
datetime
[
ndates
/
2
].
time
;
juldate2
=
juldate_encode
(
calendar
,
vdate
,
vtime
);
seconds
=
juldate_to_seconds
(
juldate_sub
(
juldate2
,
juldate1
))
/
2
;
juldatem
=
juldate_add_seconds
((
int
)
lround
(
seconds
),
juldate1
);
juldate_decode
(
calendar
,
juldatem
,
&
vdate
,
&
vtime
);
}
else
{
vdate
=
datetime
[
ndates
/
2
].
date
;
vtime
=
datetime
[
ndates
/
2
].
time
;
}
datetime
[
ndates
].
date
=
vdate
;
datetime
[
ndates
].
time
=
vtime
;
/*
fprintf(stdout, "res: %d %d\n\n", datetime[ndates].date, datetime[ndates].time);
*/
}
void
get_timestat_date
(
int
*
tstat_date
)
{
char
*
envstr
;
envstr
=
getenv
(
"TIMESTAT_DATE"
);
if
(
envstr
==
NULL
)
envstr
=
getenv
(
"RUNSTAT_DATE"
);
if
(
envstr
)
{
int
env_date
=
-
1
;
char
envstrl
[
8
];
memcpy
(
envstrl
,
envstr
,
8
);
envstrl
[
7
]
=
0
;
strtolower
(
envstrl
);
if
(
memcmp
(
envstrl
,
"first"
,
5
)
==
0
)
env_date
=
TIMESTAT_FIRST
;
else
if
(
memcmp
(
envstrl
,
"last"
,
4
)
==
0
)
env_date
=
TIMESTAT_LAST
;
else
if
(
memcmp
(
envstrl
,
"middle"
,
6
)
==
0
)
env_date
=
TIMESTAT_MEAN
;
if
(
env_date
>=
0
)
{
*
tstat_date
=
env_date
;
if
(
cdoVerbose
)
cdoPrint
(
"Set TIMESTAT_DATE to %s"
,
envstr
);
}
}
}
src/datetime
list
.h
→
src/datetime.h
View file @
65fe1fc5
...
...
@@ -5,6 +5,12 @@
#define TIMESTAT_MEAN 3
typedef
struct
{
int
julday
;
int
secofday
;
}
juldate_t
;
typedef
struct
{
int
date
;
int
time
;
...
...
@@ -41,6 +47,13 @@ typedef struct
juldate_t
juldate_encode
(
int
calendar
,
int
date
,
int
time
);
void
juldate_decode
(
int
calendar
,
juldate_t
juldate
,
int
*
date
,
int
*
time
);
juldate_t
juldate_sub
(
juldate_t
juldate2
,
juldate_t
juldate1
);
juldate_t
juldate_add_seconds
(
int
seconds
,
juldate_t
juldate
);
double
juldate_to_seconds
(
juldate_t
juldate
);
void
get_timestat_date
(
int
*
tstat_date
);
void
datetime_avg
(
int
dpy
,
int
ndates
,
datetime_t
*
datetime
);
void
datetime_avg_dtinfo
(
int
dpy
,
int
ndates
,
dtinfo_t
*
dtinfo
);
...
...
src/util.h
View file @
65fe1fc5
...
...
@@ -18,6 +18,8 @@
#ifndef _UTIL_H
#define _UTIL_H
void
strtolower
(
char
*
str
);
typedef
struct
{
int
argc
;
int
argl
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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