Commit 15e308d9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added datetimelist

parent d65b1599
......@@ -524,6 +524,8 @@ src/commandline.c -text
src/config.h.in -text
src/const.h -text
src/counter.h -text
src/datetimelist.c -text
src/datetimelist.h -text
src/dmemory.h -text
src/dtypes.h -text
src/ecacore.c -text
......
......@@ -65,30 +65,6 @@ void detrend(long nts, double missval1, double *array1, double *array2)
}
void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo)
{
dtinfo->v.date = taxisInqVdate(taxisID);
dtinfo->v.time = taxisInqVtime(taxisID);
if ( taxisHasBounds(taxisID) )
{
taxisInqVdateBounds(taxisID, &(dtinfo->b[0].date), &(dtinfo->b[1].date));
taxisInqVtimeBounds(taxisID, &(dtinfo->b[0].time), &(dtinfo->b[1].time));
}
}
void taxisDefDTinfo(int taxisID, dtinfo_t dtinfo)
{
taxisDefVdate(taxisID, dtinfo.v.date);
taxisDefVtime(taxisID, dtinfo.v.time);
if ( taxisHasBounds(taxisID) )
{
taxisDefVdateBounds(taxisID, dtinfo.b[0].date, dtinfo.b[1].date);
taxisDefVtimeBounds(taxisID, dtinfo.b[0].time, dtinfo.b[1].time);
}
}
void *Detrend(void *argument)
{
int gridsize;
......@@ -104,7 +80,7 @@ void *Detrend(void *argument)
int nvars, nlevel;
double missval;
field_t ***vars = NULL;
dtinfo_t *dtinfo = NULL;
dtlist_type *dtlist = dtlist_new();
typedef struct
{
double *array1;
......@@ -135,11 +111,10 @@ void *Detrend(void *argument)
if ( tsID >= nalloc )
{
nalloc += NALLOC_INC;
dtinfo = (dtinfo_t*) realloc(dtinfo, nalloc*sizeof(dtinfo_t));
vars = (field_t ***) realloc(vars, nalloc*sizeof(field_t **));
}
taxisInqDTinfo(taxisID1, &dtinfo[tsID]);
dtlist_taxisInqTimestep(taxisID1, tsID, dtlist);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
......@@ -200,7 +175,7 @@ void *Detrend(void *argument)
for ( tsID = 0; tsID < nts; tsID++ )
{
taxisDefDTinfo(taxisID2, dtinfo[tsID]);
dtlist_taxisDefTimestep(taxisID2, tsID, dtlist);
streamDefTimestep(streamID2, tsID);
for ( varID = 0; varID < nvars; varID++ )
......@@ -223,7 +198,8 @@ void *Detrend(void *argument)
}
if ( vars ) free(vars);
if ( dtinfo ) free(dtinfo);
dtlist_delete(dtlist);
streamClose(streamID2);
streamClose(streamID1);
......
......@@ -191,6 +191,8 @@ cdo_SOURCES += Adisit.c \
commandline.c \
const.h \
counter.h \
datetimelist.c \
datetimelist.h \
dmemory.h \
dtypes.h \
ecacore.c \
......
......@@ -147,21 +147,21 @@ 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 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 list.h merge_sort2.c \
merge_sort2.h modules.c modules.h namelist.c namelist.h \
normal.c nth_element.c nth_element.h operator_help.h par_io.c \
par_io.h percentiles.c percentiles.h pipe.c pipe.h \
pragma_omp_atomic_update.h printinfo.h process.c process.h \
pstream.c pstream.h pstream_int.h pthread_debug.c \
color.c color.h commandline.c const.h counter.h datetimelist.c \
datetimelist.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 \
list.h merge_sort2.c merge_sort2.h modules.c modules.h \
namelist.c namelist.h normal.c nth_element.c nth_element.h \
operator_help.h par_io.c par_io.h percentiles.c percentiles.h \
pipe.c pipe.h pragma_omp_atomic_update.h printinfo.h process.c \
process.h pstream.c pstream.h pstream_int.h pthread_debug.c \
pthread_debug.h readline.c realtime.c remap.h remaplib.c \
remapsort.c remap_scrip_io.c remap_search_reg2d.c \
remap_search_latbins.c remap_store_link.c remap_store_link.h \
......@@ -274,11 +274,11 @@ 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-ecacore.$(OBJEXT) cdo-ecautil.$(OBJEXT) \
cdo-exception.$(OBJEXT) cdo-expr.$(OBJEXT) \
cdo-expr_lex.$(OBJEXT) cdo-expr_yacc.$(OBJEXT) \
cdo-features.$(OBJEXT) cdo-field.$(OBJEXT) \
cdo-field2.$(OBJEXT) cdo-fieldc.$(OBJEXT) \
cdo-datetimelist.$(OBJEXT) cdo-ecacore.$(OBJEXT) \
cdo-ecautil.$(OBJEXT) cdo-exception.$(OBJEXT) \
cdo-expr.$(OBJEXT) cdo-expr_lex.$(OBJEXT) \
cdo-expr_yacc.$(OBJEXT) cdo-features.$(OBJEXT) \
cdo-field.$(OBJEXT) cdo-field2.$(OBJEXT) cdo-fieldc.$(OBJEXT) \
cdo-fieldmem.$(OBJEXT) cdo-fieldmer.$(OBJEXT) \
cdo-fieldzon.$(OBJEXT) cdo-fouriertrans.$(OBJEXT) \
cdo-gradsdeslib.$(OBJEXT) cdo-grid.$(OBJEXT) \
......@@ -597,21 +597,21 @@ 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 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 list.h merge_sort2.c \
merge_sort2.h modules.c modules.h namelist.c namelist.h \
normal.c nth_element.c nth_element.h operator_help.h par_io.c \
par_io.h percentiles.c percentiles.h pipe.c pipe.h \
pragma_omp_atomic_update.h printinfo.h process.c process.h \
pstream.c pstream.h pstream_int.h pthread_debug.c \
color.c color.h commandline.c const.h counter.h datetimelist.c \
datetimelist.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 \
list.h merge_sort2.c merge_sort2.h modules.c modules.h \
namelist.c namelist.h normal.c nth_element.c nth_element.h \
operator_help.h par_io.c par_io.h percentiles.c percentiles.h \
pipe.c pipe.h pragma_omp_atomic_update.h printinfo.h process.c \
process.h pstream.c pstream.h pstream_int.h pthread_debug.c \
pthread_debug.h readline.c realtime.c remap.h remaplib.c \
remapsort.c remap_scrip_io.c remap_search_reg2d.c \
remap_search_latbins.c remap_store_link.c remap_store_link.h \
......@@ -974,6 +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-datetimelist.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@
......@@ -3639,6 +3640,20 @@ 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-datetimelist.o: datetimelist.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetimelist.o -MD -MP -MF $(DEPDIR)/cdo-datetimelist.Tpo -c -o cdo-datetimelist.o `test -f 'datetimelist.c' || echo '$(srcdir)/'`datetimelist.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetimelist.Tpo $(DEPDIR)/cdo-datetimelist.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetimelist.c' object='cdo-datetimelist.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-datetimelist.o `test -f 'datetimelist.c' || echo '$(srcdir)/'`datetimelist.c
cdo-datetimelist.obj: datetimelist.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-datetimelist.obj -MD -MP -MF $(DEPDIR)/cdo-datetimelist.Tpo -c -o cdo-datetimelist.obj `if test -f 'datetimelist.c'; then $(CYGPATH_W) 'datetimelist.c'; else $(CYGPATH_W) '$(srcdir)/datetimelist.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-datetimelist.Tpo $(DEPDIR)/cdo-datetimelist.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='datetimelist.c' object='cdo-datetimelist.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-datetimelist.obj `if test -f 'datetimelist.c'; then $(CYGPATH_W) 'datetimelist.c'; else $(CYGPATH_W) '$(srcdir)/datetimelist.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
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-ecacore.Tpo $(DEPDIR)/cdo-ecacore.Po
......
......@@ -34,6 +34,7 @@
#include "dmemory.h"
#include "process.h"
#include "const.h"
#include "datetimelist.h"
#define OPENMP4 201307
......@@ -137,17 +138,6 @@ const char * tunit2str(int tunits);
const char * calendar2str(int calendar);
typedef struct {
int date;
int time;
} datetime_t;
typedef struct
{
datetime_t v;
datetime_t b[2];
} dtinfo_t;
typedef struct {
int julday;
int secofday;
......@@ -160,12 +150,6 @@ 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);
void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo);
void taxisDefDTinfo(int taxisID, dtinfo_t dtinfo);
int days_per_month(int calendar, int year, int month);
int days_per_year(int calendar, int year);
int calendar_dpy(int calendar);
......
#include "cdi.h"
#include "dmemory.h"
#include "util.h"
#include "datetimelist.h"
void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo)
{
dtinfo->v.date = taxisInqVdate(taxisID);
dtinfo->v.time = taxisInqVtime(taxisID);
if ( taxisHasBounds(taxisID) )
{
taxisInqVdateBounds(taxisID, &(dtinfo->b[0].date), &(dtinfo->b[1].date));
taxisInqVtimeBounds(taxisID, &(dtinfo->b[0].time), &(dtinfo->b[1].time));
}
}
void taxisDefDTinfo(int taxisID, dtinfo_t dtinfo)
{
taxisDefVdate(taxisID, dtinfo.v.date);
taxisDefVtime(taxisID, dtinfo.v.time);
if ( taxisHasBounds(taxisID) )
{
taxisDefVdateBounds(taxisID, dtinfo.b[0].date, dtinfo.b[1].date);
taxisDefVtimeBounds(taxisID, dtinfo.b[0].time, dtinfo.b[1].time);
}
}
void dtlist_init(dtlist_type *dtlist)
{
dtlist->nalloc = 0;
dtlist->size = 0;
dtlist->timestat_date = TIMESTAT_LAST;
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 )
free(dtlist->dtinfo);
free(dtlist);
}
void dtlist_taxisInqTimestep(int taxisID, int tsID, dtlist_type *dtlist)
{
size_t NALLOC = 512;
if ( (size_t)tsID >= dtlist->nalloc )
{
dtlist->nalloc += NALLOC;
dtlist->dtinfo = (dtinfo_type *) realloc(dtlist->dtinfo, dtlist->nalloc*sizeof(dtinfo_type));
}
dtlist->size += 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));
}
}
void dtlist_taxisDefTimestep(int taxisID, int tsID, const dtlist_type *dtlist)
{
if ( (size_t)tsID >= dtlist->size )
cdoAbort("Internal error; tsID out of bounds!");
taxisDefVdate(taxisID, dtlist->dtinfo[tsID].v.date);
taxisDefVtime(taxisID, dtlist->dtinfo[tsID].v.time);
if ( taxisHasBounds(taxisID) )
{
taxisDefVdateBounds(taxisID, dtlist->dtinfo[tsID].b[0].date, dtlist->dtinfo[tsID].b[1].date);
taxisDefVtimeBounds(taxisID, dtlist->dtinfo[tsID].b[0].time, dtlist->dtinfo[tsID].b[1].time);
}
}
#include <stdio.h>
#define TIMESTAT_FIRST 1
#define TIMESTAT_LAST 2
#define TIMESTAT_MEAN 3
typedef struct {
int date;
int time;
} datetime_t;
typedef struct
{
datetime_t v;
datetime_t b[2];
} dtinfo_t;
typedef struct {
int date;
int time;
} datetime_type;
typedef struct
{
datetime_type v;
datetime_type b[2];
} dtinfo_type;
typedef struct
{
size_t nalloc;
size_t size;
int timestat_date;
dtinfo_type timestat;
dtinfo_type *dtinfo;
} dtlist_type;
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);
void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo);
void taxisDefDTinfo(int taxisID, dtinfo_t dtinfo);
dtlist_type *dtlist_new(void);
void dtlist_delete(dtlist_type *dtlist);
void dtlist_taxisInqTimestep(int taxisID, int tsID, dtlist_type *dtlist);
void dtlist_taxisDefTimestep(int taxisID, int tsID, const dtlist_type *dtlist);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment