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

Use nc_create() if path contains uri

parent b0346418
No related branches found
No related tags found
No related merge requests found
Pipeline #18970 failed
......@@ -127,7 +127,7 @@ cdfOpenFile(const char *filename, const char *mode, int *filetype)
if (*filetype == CDI_FILETYPE_NC4)
writemode |= NC_NETCDF4;
else if (*filetype == CDI_FILETYPE_NC4C)
writemode |= NC_NETCDF4 | NC_CLASSIC_MODEL;
writemode |= (NC_NETCDF4 | NC_CLASSIC_MODEL);
#endif
cdf_create(filename, writemode, &ncid);
if (CDI_Version_Info) cdfComment(ncid);
......
......@@ -12,19 +12,42 @@
#ifdef HAVE_LIBNETCDF
static bool
has_uri(const char *uri)
{
char *pos = strstr(uri, "://");
if (pos)
{
const int len = pos - uri;
if (strncmp(uri, "file", len) == 0 || strncmp(uri, "https", len) == 0 || strncmp(uri, "s3", len) == 0) return true;
}
return false;
}
void
cdf_create(const char *path, int cmode, int *ncidp)
{
size_t initialsz = 0, chunksizehint = 0;
int status = -1;
size_t chunksizehint = 0;
if (has_uri(path))
{
status = nc_create(path, cmode, ncidp);
}
else
{
size_t initialsz = 0;
#if defined(__SX__) || defined(ES)
chunksizehint = 16777216; /* 16 MB */
chunksizehint = 16777216; // 16 MB
#endif
if (CDI_Netcdf_Chunksizehint != CDI_UNDEFID) chunksizehint = (size_t) CDI_Netcdf_Chunksizehint;
if (CDI_Netcdf_Chunksizehint != CDI_UNDEFID) chunksizehint = (size_t) CDI_Netcdf_Chunksizehint;
cdi_nc__create_funcp my_nc__create = (cdi_nc__create_funcp) namespaceSwitchGet(NSSWITCH_NC__CREATE).func;
int status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
cdi_nc__create_funcp my_nc__create = (cdi_nc__create_funcp) namespaceSwitchGet(NSSWITCH_NC__CREATE).func;
status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
}
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d mode=%d chunksizehint=%zu file=%s", *ncidp, cmode, chunksizehint, path);
......
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