Skip to content
Snippets Groups Projects
Commit 39386d1d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Apply patch from Julian Kunkel (support for ESDM URL).

parent bce6b1c0
No related branches found
No related tags found
1 merge request!7Replaced gridDefDatatype()/gridInqDatatype() by cdiDefKeyInt()/cdiInqKeyInt()...
......@@ -42,42 +42,33 @@ void cdf_create(const char *path, int cmode, int *ncidp)
int cdf_open(const char *path, int omode, int *ncidp)
{
int status = 0;
bool dapfile = false;
#ifdef HAVE_LIBNC_DAP
if ( strncmp(path, "http:", 5) == 0 || strncmp(path, "https:", 6) == 0 ) dapfile = true;
#endif
if ( dapfile )
if (strstr(path, ":/")) // ESDM and DAP
{
status = nc_open(path, omode, ncidp);
}
else
{
struct stat filestat;
if ( stat(path, &filestat) != 0 ) SysError(path);
if (stat(path, &filestat) != 0) SysError(path);
size_t chunksizehint = 0;
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
chunksizehint = (size_t) filestat.st_blksize * 4;
if ( chunksizehint > (size_t) filestat.st_size ) chunksizehint = (size_t) filestat.st_size;
if (chunksizehint > (size_t) filestat.st_size) chunksizehint = (size_t) filestat.st_size;
#endif
/*
if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
*/
if ( cdiNcChunksizehint != CDI_UNDEFID )
chunksizehint = (size_t)cdiNcChunksizehint;
// if (chunksizehint < ChunkSizeMin) chunksizehint = ChunkSizeMin;
if (cdiNcChunksizehint != CDI_UNDEFID) chunksizehint = (size_t)cdiNcChunksizehint;
/* FIXME: parallel part missing */
// FIXME: parallel part missing
status = nc__open(path, omode, &chunksizehint, ncidp);
if ( CDF_Debug ) Message("chunksizehint %zu", chunksizehint);
if (CDF_Debug) Message("chunksizehint %zu", chunksizehint);
}
if ( CDF_Debug )
Message("ncid=%d mode=%d file=%s", *ncidp, omode, path);
if (CDF_Debug) Message("ncid=%d mode=%d file=%s", *ncidp, omode, path);
if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
if (CDF_Debug && status != NC_NOERR) Message("%s", nc_strerror(status));
return status;
}
......
......@@ -71,6 +71,7 @@ int getByteorder(int byteswap)
default:
Error("unhandled endianness");
}
return byteorder;
}
......@@ -82,25 +83,25 @@ int cdiGetFiletype(const char *filename, int *byteorder)
int version;
long recpos;
int fileID = fileOpen(filename, "r");
const int fileID = fileOpen(filename, "r");
if ( fileID == CDI_UNDEFID )
if (fileID == CDI_UNDEFID)
{
if ( strncmp(filename, "http:", 5) == 0 || strncmp(filename, "https:", 6) == 0 )
return CDI_FILETYPE_NC;
if (strstr(filename, ":/"))
return CDI_FILETYPE_NC; // support for NetCDF remote types and ESDM
else
return CDI_ESYSTEM;
}
else if ( fileID == -2 ) return CDI_ETMOF;
else if (fileID == -2) return CDI_ETMOF;
char buffer[8];
if ( fileRead(fileID, buffer, 8) != 8 )
if (fileRead(fileID, buffer, 8) != 8)
{
struct stat buf;
if ( stat(filename, &buf) == 0 )
if (stat(filename, &buf) == 0)
{
if ( buf.st_size == 0 ) return CDI_EISEMPTY;
if ( buf.st_mode&S_IFDIR ) return CDI_EISDIR;
if (buf.st_size == 0) return CDI_EISEMPTY;
if (buf.st_mode&S_IFDIR) return CDI_EISDIR;
}
return CDI_EUFTYPE;
......@@ -108,73 +109,73 @@ int cdiGetFiletype(const char *filename, int *byteorder)
fileRewind(fileID);
if ( memcmp(buffer, "GRIB", 4) == 0 )
if (memcmp(buffer, "GRIB", 4) == 0)
{
version = buffer[7];
if ( version <= 1 )
{
filetype = CDI_FILETYPE_GRB;
if ( CDI_Debug ) Message("found GRIB file = %s, version %d", filename, version);
if (CDI_Debug) Message("found GRIB file = %s, version %d", filename, version);
}
else if ( version == 2 )
else if (version == 2)
{
filetype = CDI_FILETYPE_GRB2;
if ( CDI_Debug ) Message("found GRIB2 file = %s", filename);
if (CDI_Debug) Message("found GRIB2 file = %s", filename);
}
}
else if ( memcmp(buffer, "CDF\001", 4) == 0 )
else if (memcmp(buffer, "CDF\001", 4) == 0)
{
filetype = CDI_FILETYPE_NC;
if ( CDI_Debug ) Message("found CDF1 file = %s", filename);
if (CDI_Debug) Message("found CDF1 file = %s", filename);
}
else if ( memcmp(buffer, "CDF\002", 4) == 0 )
else if (memcmp(buffer, "CDF\002", 4) == 0)
{
filetype = CDI_FILETYPE_NC2;
if ( CDI_Debug ) Message("found CDF2 file = %s", filename);
if (CDI_Debug) Message("found CDF2 file = %s", filename);
}
else if ( memcmp(buffer, "CDF\005", 4) == 0 )
else if (memcmp(buffer, "CDF\005", 4) == 0)
{
filetype = CDI_FILETYPE_NC5;
if ( CDI_Debug ) Message("found CDF5 file = %s", filename);
if (CDI_Debug) Message("found CDF5 file = %s", filename);
}
else if ( memcmp(buffer+1, "HDF", 3) == 0 )
else if (memcmp(buffer+1, "HDF", 3) == 0)
{
filetype = CDI_FILETYPE_NC4;
if ( CDI_Debug ) Message("found HDF file = %s", filename);
if (CDI_Debug) Message("found HDF file = %s", filename);
}
#ifdef HAVE_LIBSERVICE
else if ( srvCheckFiletype(fileID, &swap) )
else if (srvCheckFiletype(fileID, &swap))
{
filetype = CDI_FILETYPE_SRV;
if ( CDI_Debug ) Message("found SRV file = %s", filename);
if (CDI_Debug) Message("found SRV file = %s", filename);
}
#endif
#ifdef HAVE_LIBEXTRA
else if ( extCheckFiletype(fileID, &swap) )
else if (extCheckFiletype(fileID, &swap))
{
filetype = CDI_FILETYPE_EXT;
if ( CDI_Debug ) Message("found EXT file = %s", filename);
if (CDI_Debug) Message("found EXT file = %s", filename);
}
#endif
#ifdef HAVE_LIBIEG
else if ( iegCheckFiletype(fileID, &swap) )
else if (iegCheckFiletype(fileID, &swap))
{
filetype = CDI_FILETYPE_IEG;
if ( CDI_Debug ) Message("found IEG file = %s", filename);
if (CDI_Debug) Message("found IEG file = %s", filename);
}
#endif
#ifdef HAVE_LIBGRIB
else if ( gribCheckSeek(fileID, &recpos, &version) == 0 )
else if (gribCheckSeek(fileID, &recpos, &version) == 0)
{
if ( version <= 1 )
if (version <= 1)
{
filetype = CDI_FILETYPE_GRB;
if ( CDI_Debug ) Message("found seeked GRIB file = %s", filename);
if (CDI_Debug) Message("found seeked GRIB file = %s", filename);
}
else if ( version == 2 )
else if (version == 2)
{
filetype = CDI_FILETYPE_GRB2;
if ( CDI_Debug ) Message("found seeked GRIB2 file = %s", filename);
if (CDI_Debug) Message("found seeked GRIB2 file = %s", filename);
}
}
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment