Commit 3169db42 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdiBaseFiletype().

parent cc57fc35
......@@ -501,6 +501,21 @@ double cdiInqGridMissval(void)
return CDI_default_missval;
}
int cdiBaseFiletype(int filetype)
{
switch (filetype)
{
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5: return CDI_FILETYPE_NETCDF;
default: return filetype;
}
return filetype;
}
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -17,7 +17,12 @@
#include "cdi.h"
#include "cdf_config.h"
/* dummy use of unused parameters to silence compiler warnings */
// Base file types
#define CDI_FILETYPE_GRIB 100 // File type GRIB
#define CDI_FILETYPE_NETCDF 101 // File type NetCDF
// dummy use of unused parameters to silence compiler warnings
#ifndef UNUSED
#define UNUSED(x) (void)x
#endif
......@@ -42,7 +47,7 @@ char *strToLower(char *str);
bool strStartsWith(const char *vstr, const char *cstr);
static inline bool
strIsEqual(const char *x, const char *y)
strIsEqual(const char *x, const char *y)
{
return (*x == *y) && strcmp(x, y) == 0;
}
......@@ -511,6 +516,7 @@ void cdi_check_gridsize_int_limit(const char *format, size_t gridsize)
if ( gridsize > INT_MAX ) Error("%s format grid size (%zu) limit exceeded (%zu)!", format, gridsize, INT_MAX);
}
int cdiBaseFiletype(int filetype);
#if defined (__cplusplus)
}
......
......@@ -1107,18 +1107,14 @@ readGetBuffers(size_t streamIdx, const struct cdiPioConf *conf)
int currentDataBufSize = 0;
int filetype = streamInqFiletype(streamID);
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
writeGribStream(streamIdx, map, &data, &currentDataBufSize, conf);
break;
#ifdef HAVE_NETCDF4
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
writeNetCDFStream(streamIdx, map, &data, &currentDataBufSize, conf);
break;
#endif
......@@ -1257,14 +1253,10 @@ cdiPioServerStreamClose(stream_t *streamptr, int recordBufIsToBeDeleted)
Warning("File %s not open!", streamptr->filename);
else
{
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#if defined (HAVE_LIBNETCDF) && ! defined (HAVE_PARALLEL_NC4)
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
int rank, rankOpen = cdiPioSerialOpenFileMap(streamptr->self);
if (commInqIOMode() == PIO_NONE
......
......@@ -333,19 +333,15 @@ const char *streamFilesuffix(int filetype)
static const char *extSuffix = ".ext";
static const char *iegSuffix = ".ieg";
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5: return ncSuffix;
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2: return grbSuffix;
case CDI_FILETYPE_SRV: return srvSuffix;
case CDI_FILETYPE_EXT: return extSuffix;
case CDI_FILETYPE_IEG: return iegSuffix;
default: return noSuffix;
case CDI_FILETYPE_GRB2: return grbSuffix;
case CDI_FILETYPE_SRV: return srvSuffix;
case CDI_FILETYPE_EXT: return extSuffix;
case CDI_FILETYPE_IEG: return iegSuffix;
case CDI_FILETYPE_NETCDF: return ncSuffix;
default: return noSuffix;
}
}
......@@ -376,7 +372,7 @@ int cdiInqContents(stream_t *streamptr)
int status = 0;
int filetype = streamptr->filetype;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -408,11 +404,7 @@ int cdiInqContents(stream_t *streamptr)
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
status = cdfInqContents(streamptr);
break;
......@@ -430,8 +422,7 @@ int cdiInqContents(stream_t *streamptr)
if ( status == 0 )
{
int vlistID = streamptr->vlistID;
int taxisID = vlistInqTaxis(vlistID);
int taxisID = vlistInqTaxis(streamptr->vlistID);
if ( taxisID != CDI_UNDEFID )
{
taxis_t *taxisptr1 = &streamptr->tsteps[0].taxis;
......@@ -951,7 +942,7 @@ void cdiStreamCloseDefaultDelegate(stream_t *streamptr, int recordBufIsToBeDelet
if ( fileID == CDI_UNDEFID )
Warning("File %s not open!", streamptr->filename);
else
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#if defined(HAVE_LIBGRIB) && (defined(HAVE_LIBCGRIBEX) || defined(HAVE_LIBGRIB_API))
case CDI_FILETYPE_GRB:
......@@ -995,11 +986,7 @@ void cdiStreamCloseDefaultDelegate(stream_t *streamptr, int recordBufIsToBeDelet
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
cdfClose(fileID);
if (streamptr->ntsteps == 0)
......@@ -1143,14 +1130,10 @@ void cdiStreamSync_(stream_t *streamptr)
{
if ( streamptr->filemode == 'w' || streamptr->filemode == 'a' )
{
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
void cdf_sync(int ncid);
if ( streamptr->ncmode == 2 ) cdf_sync(fileID);
......@@ -1226,12 +1209,7 @@ int cdiStreamDefTimestep_(stream_t *streamptr, int tsID)
streamptr->ntsteps = tsID + 1;
#ifdef HAVE_LIBNETCDF
if ((streamptr->filetype == CDI_FILETYPE_NC ||
streamptr->filetype == CDI_FILETYPE_NC2 ||
streamptr->filetype == CDI_FILETYPE_NC5 ||
streamptr->filetype == CDI_FILETYPE_NC4 ||
streamptr->filetype == CDI_FILETYPE_NC4C)
&& time_is_varying)
if (cdiBaseFiletype(streamptr->filetype) == CDI_FILETYPE_NETCDF && time_is_varying)
{
void (*myCdfDefTimestep)(stream_t *streamptr, int tsID)
= (void (*)(stream_t *, int))
......@@ -1331,7 +1309,7 @@ int streamInqTimestep(int streamID, int tsID)
if ( CDI_Debug )
Message("streamID = %d tsID = %d filetype = %d", streamID, tsID, filetype);
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -1363,11 +1341,7 @@ int streamInqTimestep(int streamID, int tsID)
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
nrecs = cdfInqTimestep(streamptr, tsID);
break;
......@@ -1654,40 +1628,26 @@ void cdiStreamSetupVlist_(stream_t *streamptr, int vlistID)
vlistDefTaxis(vlistID, taxisID);
}
#ifdef HAVE_LIBNETCDF
if ( taxisInqType(taxisID) == TAXIS_RELATIVE )
switch (streamptr->filetype)
if (cdiBaseFiletype(streamptr->filetype) == CDI_FILETYPE_NETCDF)
{
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
{
taxis_t *taxisptr = taxisPtr(taxisID);
if ( taxisptr->rdate == -1 )
{
int vdate = taxisInqVdate(taxisID);
if ( vdate == 0 ) vdate = 10101;
taxisDefRdate(taxisID, vdate);
}
}
break;
#endif
default:
;
taxis_t *taxisptr = taxisPtr(taxisID);
if ( taxisptr->rdate == -1 )
{
int vdate = taxisInqVdate(taxisID);
if ( vdate == 0 ) vdate = 10101;
taxisDefRdate(taxisID, vdate);
}
}
#endif
ptaxisCopy(&streamptr->tsteps[0].taxis, taxisPtr(taxisID));
}
switch (streamptr->filetype)
switch (cdiBaseFiletype(streamptr->filetype))
{
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
/* calls cdfDefCoordinateVars in serial mode but
* cdiPioClientStreamNOP (i.e. nothing) on client ranks
......
......@@ -30,7 +30,7 @@ int cdiStreamReadVar(int streamID, int varID, int memtype, void *data, size_t *n
*nmiss = 0;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -65,11 +65,7 @@ int cdiStreamReadVar(int streamID, int varID, int memtype, void *data, size_t *n
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
cdf_read_var(streamptr, varID, memtype, data, nmiss);
break;
......@@ -157,7 +153,7 @@ int cdiStreamReadVarSlice(int streamID, int varID, int levelID, int memtype, voi
*nmiss = 0;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -192,11 +188,7 @@ int cdiStreamReadVarSlice(int streamID, int varID, int levelID, int memtype, voi
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
cdf_read_var_slice(streamptr, varID, levelID, memtype, data, nmiss);
break;
......@@ -287,7 +279,7 @@ int stream_read_record(int streamID, int memtype, void *data, size_t *nmiss)
*nmiss = 0;
switch (streamptr->filetype)
switch (cdiBaseFiletype(streamptr->filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -314,11 +306,7 @@ int stream_read_record(int streamID, int memtype, void *data, size_t *nmiss)
break;
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
cdf_read_record(streamptr, memtype, data, nmiss);
break;
#endif
......
......@@ -181,7 +181,7 @@ void streamDefRecord(int streamID, int varID, int levelID)
record->gridID = gridID;
record->prec = vlistInqVarDatatype(vlistID, varID);
switch (streamptr->filetype)
switch (cdiBaseFiletype(streamptr->filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -205,11 +205,7 @@ void streamDefRecord(int streamID, int varID, int levelID)
break;
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
if ( streamptr->accessmode == 0 ) cdfEndDef(streamptr);
cdfDefRecord(streamptr);
break;
......@@ -229,35 +225,12 @@ void streamCopyRecord(int streamID2, int streamID1)
filetype2 = streamptr2->filetype,
filetype = CDI_FILETYPE_UNDEF;
if ( filetype1 == filetype2 ) filetype = filetype2;
else
{
switch (filetype1)
{
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
switch (filetype2)
{
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
// Warning("Streams have different file types (%s -> %s)!", strfiletype(filetype1), strfiletype(filetype2));
filetype = filetype2;
break;
}
break;
}
}
if (cdiBaseFiletype(filetype1) == cdiBaseFiletype(filetype2)) filetype = filetype2;
if ( filetype == CDI_FILETYPE_UNDEF )
Error("Streams have different file types (%s -> %s)!", strfiletype(filetype1), strfiletype(filetype2));
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -281,11 +254,7 @@ void streamCopyRecord(int streamID2, int streamID1)
break;
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
cdfCopyRecord(streamptr2, streamptr1);
break;
#endif
......
......@@ -33,7 +33,7 @@ int cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, s
int filetype = streamptr->filetype;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -68,11 +68,7 @@ int cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, s
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
cdf_write_var(streamptr, varID, memtype, data, nmiss);
break;
......@@ -170,7 +166,7 @@ int cdiStreamWriteVarSlice(int streamID, int varID, int levelID, int memtype, co
int filetype = streamptr->filetype;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -205,11 +201,7 @@ int cdiStreamWriteVarSlice(int streamID, int varID, int levelID, int memtype, co
}
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
cdf_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss);
break;
#endif
......@@ -299,7 +291,7 @@ void cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,
int filetype = streamptr->filetype;
switch (filetype)
switch (cdiBaseFiletype(filetype))
{
#if defined (HAVE_LIBGRIB)
case CDI_FILETYPE_GRB:
......@@ -316,16 +308,11 @@ void cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,
#endif
#if defined (HAVE_LIBGRIB) || defined (HAVE_LIBSERVICE) \
|| defined (HAVE_LIBEXTRA) || defined (HAVE_LIBIEG)
xabort("streamWriteVarChunk not implemented for filetype %s!",
strfiletype(filetype));
xabort("streamWriteVarChunk not implemented for filetype %s!", strfiletype(filetype));
break;
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
cdf_write_var_chunk(streamptr, varID, memtype, rect, data, nmiss);
break;
#endif
......@@ -346,7 +333,7 @@ int stream_write_record(int streamID, int memtype, const void *data, size_t nmis
stream_t *streamptr = stream_to_pointer(streamID);
switch (streamptr->filetype)
switch (cdiBaseFiletype(streamptr->filetype))
{
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
......@@ -373,11 +360,7 @@ int stream_write_record(int streamID, int memtype, const void *data, size_t nmis
break;
#endif
#ifdef HAVE_LIBNETCDF
case CDI_FILETYPE_NC:
case CDI_FILETYPE_NC2:
case CDI_FILETYPE_NC4:
case CDI_FILETYPE_NC4C:
case CDI_FILETYPE_NC5:
case CDI_FILETYPE_NETCDF:
{
cdf_write_record(streamptr, memtype, data, nmiss);
break;
......
Markdown is supported
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