Commit e7d270b6 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

MAX_TAXES: change static size of 4096 to dynamic range of 1024 - 65536

parent 55438a65
......@@ -2,6 +2,7 @@
* MAX_STREAMS: change static size of 4096 to dynamic range of 1024 - 65536
* MAX_VLISTS: change static size of 4096 to dynamic range of 1024 - 65536
* MAX_TAXES: change static size of 4096 to dynamic range of 1024 - 65536
2010-04-13 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......
......@@ -5,13 +5,14 @@
#define MAX_STREAMS 65536 /* maximum number of streams */
#define MIN_VLISTS 1024 /* minimum number of vlists */
#define MAX_VLISTS 65536 /* maximum number of vlists */
#define MAX_TAXIS 4096 /* maximum number of taxis */
#define MAX_ZAXIS 1024 /* maximum number of zaxis */
#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_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 */
#define MAX_ZAXIS_PS 128 /* maximum number of different zaxis per stream */
#define MAX_ZAXES_PS 128 /* maximum number of different zaxes per stream */
#define MAX_ATTRIBUTES 256 /* maximum number of attributes per variable */
#endif /* _CDI_LIMITS_H */
......@@ -157,7 +157,7 @@ int isTimeUnits(const char *timeunits)
}
static
int splitBasetime(const char *timeunits, TAXIS *taxis)
int splitBasetime(const char *timeunits, taxis_t *taxis)
{
static char func[] = "splitBasetime";
int len, i;
......@@ -743,7 +743,7 @@ void cdfDefTimeValue(int streamID, int tsID)
double timevalue;
int ncvarid;
size_t index;
TAXIS *taxis;
taxis_t *taxis;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......@@ -801,7 +801,7 @@ void cdfDefTime(int streamID)
char unitstr[80];
char calstr[80];
size_t len;
TAXIS *taxis;
taxis_t *taxis;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......@@ -5903,7 +5903,7 @@ int cdfInqContents(int streamID)
if ( timehasunits )
{
TAXIS *taxis;
taxis_t *taxis;
taxis = &streamptr->tsteps[0].taxis;
cdfGetAttText(fileID, ncvarid, "units", attstringlen-1, attstring);
......@@ -5952,7 +5952,7 @@ int cdfInqContents(int streamID)
if ( calendar != UNDEFID )
{
TAXIS *taxis;
taxis_t *taxis;
taxis = &streamptr->tsteps[0].taxis;
taxis->calendar = calendar;
......@@ -5960,7 +5960,7 @@ int cdfInqContents(int streamID)
}
else if ( streamptr->tsteps[0].taxis.type == TAXIS_RELATIVE )
{
TAXIS *taxis;
taxis_t *taxis;
calendar = CALENDAR_STANDARD;
......@@ -6001,7 +6001,7 @@ int cdfInqTimestep(int streamID, int tsID)
int nctimeboundsid;
int fileID;
size_t index;
TAXIS *taxis;
taxis_t *taxis;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......
......@@ -596,7 +596,7 @@ void cgribexScanTimestep1(int streamID)
int warn_numavg = TRUE;
int taxisID = -1;
int rdate = 0, rtime = 0, tunit = 0, fcast = 0;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
int ztype;
long unzipsize;
......@@ -835,7 +835,7 @@ int cgribexScanTimestep2(int streamID)
int warn_numavg = TRUE;
int tsteptype;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
long unzipsize;
compvar_t compVar, compVar0;
......@@ -1111,7 +1111,7 @@ int cgribexScanTimestep(int streamID)
int warn_numavg = TRUE;
size_t readsize;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
int rindex, nrecs = 0;
long unzipsize;
......
......@@ -376,7 +376,7 @@ void extScanTimestep1(int streamID)
off_t recpos;
int nrecords, nrecs, recID;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
extcompvar_t compVar, compVar0;
extrec_t *extp;
......@@ -516,7 +516,7 @@ int extScanTimestep2(int streamID)
off_t recpos = 0;
int nrecords, nrecs, recID, rindex;
int nextstep;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
extcompvar_t compVar, compVar0;
extrec_t *extp;
......@@ -704,7 +704,7 @@ int extScanTimestep(int streamID)
long recsize = 0;
off_t recpos = 0;
int recID;
TAXIS *taxis;
taxis_t *taxis;
int rindex, nrecs = 0;
extcompvar_t compVar, compVar0;
extrec_t *extp;
......
......@@ -694,7 +694,7 @@ void gribapiScanTimestep1(int streamID)
int warn_numavg = TRUE;
int taxisID = -1;
int rdate = 0, rtime = 0, tunit = 0, fcast = 0;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
int ztype;
long unzipsize;
......@@ -999,7 +999,7 @@ int gribapiScanTimestep2(int streamID)
int warn_numavg = TRUE;
int tsteptype;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
long unzipsize;
compvar2_t compVar, compVar0;
......@@ -1327,7 +1327,7 @@ int gribapiScanTimestep(int streamID)
int warn_numavg = TRUE;
size_t readsize;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
int rindex, nrecs = 0;
long unzipsize;
......
......@@ -888,7 +888,7 @@ void iegScanTimestep1(int streamID)
off_t recpos;
int nrecords, nrecs, recID;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
IEGCOMPVAR compVar, compVar0;
iegrec_t *iegp;
......@@ -1031,7 +1031,7 @@ int iegScanTimestep2(int streamID)
off_t recpos = 0;
int nrecords, nrecs, recID, rindex;
int nextstep;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
IEGCOMPVAR compVar, compVar0;
iegrec_t *iegp;
......@@ -1223,7 +1223,7 @@ int iegScanTimestep(int streamID)
long recsize = 0;
off_t recpos = 0;
int recID;
TAXIS *taxis;
taxis_t *taxis;
int rindex, nrecs = 0;
IEGCOMPVAR compVar, compVar0;
iegrec_t *iegp;
......
......@@ -209,7 +209,7 @@ static int _stream_init = FALSE;
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
static pthread_once_t _stream_init_thread = PTHREAD_ONCE_INIT;
static pthread_once_t _stream_init_thread = PTHREAD_ONCE_INIT;
static pthread_mutex_t _stream_mutex;
# define STREAM_LOCK() pthread_mutex_lock(&_stream_mutex)
......@@ -408,7 +408,7 @@ void stream_init_entry(stream_t *streamptr)
for ( i = 0; i < MAX_GRIDS_PS; i++ ) streamptr->xdimID[i] = UNDEFID;
for ( i = 0; i < MAX_GRIDS_PS; i++ ) streamptr->ydimID[i] = UNDEFID;
for ( i = 0; i < MAX_ZAXIS_PS; i++ ) streamptr->zaxisID[i] = UNDEFID;
for ( i = 0; i < MAX_ZAXES_PS; i++ ) streamptr->zaxisID[i] = UNDEFID;
for ( i = 0; i < MAX_GRIDS_PS; i++ ) streamptr->ncxvarID[i] = UNDEFID;
for ( i = 0; i < MAX_GRIDS_PS; i++ ) streamptr->ncyvarID[i] = UNDEFID;
for ( i = 0; i < MAX_GRIDS_PS; i++ ) streamptr->ncavarID[i] = UNDEFID;
......
......@@ -165,7 +165,7 @@ typedef struct {
int curRecID; /* current record ID */
long next;
off_t position; /* timestep file position */
TAXIS taxis;
taxis_t taxis;
}
TSTEPS;
......@@ -225,7 +225,7 @@ typedef struct {
int vlistID;
int xdimID[MAX_GRIDS_PS];
int ydimID[MAX_GRIDS_PS];
int zaxisID[MAX_ZAXIS_PS];
int zaxisID[MAX_ZAXES_PS];
int ncxvarID[MAX_GRIDS_PS];
int ncyvarID[MAX_GRIDS_PS];
int ncavarID[MAX_GRIDS_PS];
......
......@@ -379,7 +379,7 @@ void srvScanTimestep1(int streamID)
off_t recpos;
int nrecords, nrecs, recID;
int taxisID = -1;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
SRVCOMPVAR compVar, compVar0;
srvrec_t *srvp;
......@@ -520,7 +520,7 @@ int srvScanTimestep2(int streamID)
off_t recpos = 0;
int nrecords, nrecs, recID, rindex;
int nextstep;
TAXIS *taxis;
taxis_t *taxis;
int vlistID;
SRVCOMPVAR compVar, compVar0;
srvrec_t *srvp;
......@@ -707,7 +707,7 @@ int srvScanTimestep(int streamID)
long recsize = 0;
off_t recpos = 0;
int recID;
TAXIS *taxis;
taxis_t *taxis;
int rindex, nrecs = 0;
SRVCOMPVAR compVar, compVar0;
srvrec_t *srvp;
......
......@@ -77,7 +77,8 @@ void taxis_defaults(void)
static int TAXIS_Debug = 0; /* If set to 1, debugging */
static int _taxis_max = MAX_TAXIS;
static int _taxis_min = MIN_TAXES;
static int _taxis_max = MAX_TAXES;
static void taxis_initialize(void);
......@@ -86,84 +87,115 @@ static int _taxis_init = FALSE;
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
static pthread_once_t _taxis_init_thread = PTHREAD_ONCE_INIT;
static pthread_once_t _taxis_init_thread = PTHREAD_ONCE_INIT;
static pthread_mutex_t _taxis_mutex;
# define TAXIS_LOCK pthread_mutex_lock(&_taxis_mutex);
# define TAXIS_UNLOCK pthread_mutex_unlock(&_taxis_mutex);
# define TAXIS_INIT \
if ( _taxis_init == FALSE ) pthread_once(&_taxis_init_thread, taxis_initialize);
# define TAXIS_LOCK() pthread_mutex_lock(&_taxis_mutex)
# define TAXIS_UNLOCK() pthread_mutex_unlock(&_taxis_mutex)
# define TAXIS_INIT() \
if ( _taxis_init == FALSE ) pthread_once(&_taxis_init_thread, taxis_initialize)
#else
# define TAXIS_LOCK
# define TAXIS_UNLOCK
# define TAXIS_INIT \
if ( _taxis_init == FALSE ) taxis_initialize();
# define TAXIS_LOCK()
# define TAXIS_UNLOCK()
# define TAXIS_INIT() \
if ( _taxis_init == FALSE ) taxis_initialize()
#endif
typedef struct _taxisPtrToIdx {
int idx;
TAXIS *ptr;
struct _taxisPtrToIdx *next;
int idx;
int next;
taxis_t *ptr;
} taxisPtrToIdx;
static taxisPtrToIdx *_taxisList = NULL;
static taxisPtrToIdx *_taxisAvail = NULL;
static int _taxisAvail = -1;
static void taxis_list_new(void)
static
void taxis_list_new(void)
{
static char func[] = "taxis_list_new";
assert(_taxisList == NULL);
_taxisList = (taxisPtrToIdx *) malloc(_taxis_max*sizeof(taxisPtrToIdx));
_taxisList = (taxisPtrToIdx *) malloc(_taxis_min*sizeof(taxisPtrToIdx));
}
static void taxis_list_delete(void)
static
void taxis_list_delete(void)
{
static char func[] = "taxis_list_delete";
if ( _taxisList ) free(_taxisList);
}
static void taxis_init_pointer(void)
static
void taxis_init_pointer(void)
{
int i;
for ( i = 0; i < _taxis_max; i++ )
for ( i = 0; i < _taxis_min; ++i )
{
_taxisList[i].next = _taxisList + i + 1;
_taxisList[i].idx = i;
_taxisList[i].ptr = 0;
_taxisList[i].next = i + 1;
_taxisList[i].ptr = NULL;
}
_taxisList[_taxis_max-1].next = 0;
_taxisList[_taxis_min-1].next = -1;
_taxisAvail = 0;
}
static
void taxis_list_extend(void)
{
static char func[] = "taxis_list_extend";
int ntaxis;
int i;
assert(_taxisList != NULL);
ntaxis = _taxis_min + MIN_TAXES;
if ( ntaxis <= _taxis_max)
{
_taxisList = (taxisPtrToIdx *) realloc(_taxisList, ntaxis*sizeof(taxisPtrToIdx));
for ( i = _taxis_min; i < ntaxis; ++i )
{
_taxisList[i].idx = i;
_taxisList[i].next = i + 1;
_taxisList[i].ptr = NULL;
}
_taxisAvail = _taxisList;
_taxisAvail = _taxis_min;
_taxisList[_taxis_min-1].next = _taxis_min;
_taxis_min = ntaxis;
_taxisList[_taxis_min-1].next = -1;
}
else
Warning(func, "Too many open taxes (limit is %d)!", _taxis_max);
}
TAXIS *taxis_to_pointer(int idx)
taxis_t *taxis_to_pointer(int idx)
{
static char func[] = "taxis_to_pointer";
TAXIS *taxisptr = NULL;
taxis_t *taxisptr = NULL;
TAXIS_INIT
TAXIS_INIT();
if ( idx >= 0 && idx < _taxis_max )
if ( idx >= 0 && idx < _taxis_min )
{
TAXIS_LOCK
TAXIS_LOCK();
taxisptr = _taxisList[idx].ptr;
TAXIS_UNLOCK
TAXIS_UNLOCK();
}
else
Error(func, "taxis index %d undefined!", idx);
......@@ -173,31 +205,33 @@ TAXIS *taxis_to_pointer(int idx)
/* Create an index from a pointer */
static int taxis_from_pointer(TAXIS *ptr)
static
int taxis_from_pointer(taxis_t *ptr)
{
static char func[] = "taxis_from_pointer";
int idx = -1;
taxisPtrToIdx *newptr;
if ( ptr )
{
TAXIS_LOCK
TAXIS_LOCK();
if ( _taxisAvail < 0 ) taxis_list_extend();
if ( _taxisAvail )
if ( _taxisAvail >= 0 )
{
newptr = _taxisAvail;
_taxisAvail = _taxisAvail->next;
newptr->next = 0;
taxisPtrToIdx *newptr;
newptr = &_taxisList[_taxisAvail];
_taxisAvail = newptr->next;
newptr->next = -1;
idx = newptr->idx;
newptr->ptr = ptr;
if ( TAXIS_Debug )
Message(func, "Pointer %p has idx %d from taxis list", ptr, idx);
}
else
Warning(func, "Too many open taxis (limit is %d)!", _taxis_max);
TAXIS_UNLOCK
TAXIS_UNLOCK();
}
else
Error(func, "Internal problem (pointer %p undefined)", ptr);
......@@ -206,7 +240,7 @@ static int taxis_from_pointer(TAXIS *ptr)
}
void taxis_init_ptr(TAXIS *taxisptr)
void taxis_init_ptr(taxis_t *taxisptr)
{
taxisptr->self = -1;
......@@ -227,52 +261,50 @@ void taxis_init_ptr(TAXIS *taxisptr)
}
void taxis_init_entry(TAXIS *taxisptr)
void taxis_init_entry(taxis_t *taxisptr)
{
taxis_init_ptr(taxisptr);
taxisptr->self = taxis_from_pointer(taxisptr);
}
static TAXIS *taxis_new_entry(void)
static
taxis_t *taxis_new_entry(void)
{
static char func[] = "taxis_new_entry";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = (TAXIS *) malloc(sizeof(TAXIS));
taxisptr = (taxis_t *) malloc(sizeof(taxis_t));
if ( taxisptr ) taxis_init_entry(taxisptr);
/* fprintf(stderr, "self: %d %p\n", taxisptr->self, taxisptr); */
return (taxisptr);
}
static void taxis_delete_entry(TAXIS *taxisptr)
static
void taxis_delete_entry(taxis_t *taxisptr)
{
static char func[] = "taxis_delete_entry";
int idx;
idx = taxisptr->self;
TAXIS_LOCK
TAXIS_LOCK();
free(taxisptr);
_taxisList[idx].next = _taxisAvail;
_taxisList[idx].ptr = 0;
_taxisAvail = &_taxisList[idx];
_taxisAvail = idx;
TAXIS_UNLOCK
TAXIS_UNLOCK();
if ( TAXIS_Debug )
Message(func, "Removed idx %d from taxis list", idx);
}
static void taxis_initialize(void)
static
void taxis_initialize(void)
{
char *env;
......@@ -287,29 +319,29 @@ static void taxis_initialize(void)
taxis_list_new();
atexit(taxis_list_delete);
TAXIS_LOCK
TAXIS_LOCK();
taxis_init_pointer();
TAXIS_UNLOCK
TAXIS_UNLOCK()
_taxis_init = TRUE;
taxis_defaults();
}
static void taxis_copy(TAXIS *taxisptr2, TAXIS *taxisptr1)
static
void taxis_copy(taxis_t *taxisptr2, taxis_t *taxisptr1)
{
int taxisID2;
taxisID2 = taxisptr2->self;
memcpy(taxisptr2, taxisptr1, sizeof(TAXIS));
memcpy(taxisptr2, taxisptr1, sizeof(taxis_t));
taxisptr2->self = taxisID2;
}
static void taxis_check_ptr(const char *func, TAXIS *taxisptr)
static
void taxis_check_ptr(const char *func, taxis_t *taxisptr)
{
if ( taxisptr == NULL )
Error(func, "taxis undefined!");
......@@ -352,12 +384,12 @@ int taxisCreate(int taxistype)
{
static char func[] = "taxisCreate";
int taxisID;
TAXIS *taxisptr;
taxis_t *taxisptr;
if ( CDI_Debug )
Message(func, "taxistype: %d", taxistype);
TAXIS_INIT
TAXIS_INIT();
taxisptr = taxis_new_entry();
if ( ! taxisptr ) Error(func, "No memory");
......@@ -385,7 +417,7 @@ int taxisCreate(int taxistype)
void taxisDestroy(int taxisID)
{
static char func[] = "taxisDestroy";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = taxis_to_pointer(taxisID);
......@@ -399,8 +431,8 @@ int taxisDuplicate(int taxisID1)
{
static char func[] = "taxisDuplicate";
int taxisID2;
TAXIS *taxisptr1;
TAXIS *taxisptr2;
taxis_t *taxisptr1;
taxis_t *taxisptr2;
taxisptr1 = taxis_to_pointer(taxisID1);
......@@ -423,7 +455,7 @@ int taxisDuplicate(int taxisID1)
void taxisDefType(int taxisID, int type)
{
static char func[] = "taxisDefType";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = taxis_to_pointer(taxisID);
......@@ -450,7 +482,7 @@ The function @func{taxisDefVdate} defines the verification date of a Time axis.
void taxisDefVdate(int taxisID, int vdate)
{
static char func[] = "taxisDefVdate";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = taxis_to_pointer(taxisID);
......@@ -477,7 +509,7 @@ The function @func{taxisDefVtime} defines the verification time of a Time axis.
void taxisDefVtime(int taxisID, int vtime)
{
static char func[] = "taxisDefVtime";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = taxis_to_pointer(taxisID);
......@@ -504,7 +536,7 @@ The function @func{taxisDefVdate} defines the reference date of a Time axis.
void taxisDefRdate(int taxisID, int rdate)
{
static char func[] = "taxisDefRdate";
TAXIS *taxisptr;
taxis_t *taxisptr;
taxisptr = taxis_to_pointer(taxisID);
......@@ -531,7 +563,7 @@ The function @func{taxisDefVdate} defines the reference time of a Time axis.
void taxisDefRtime(int taxisID, int rtime)
{
static char func[] = "taxisDefRtime";