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

Added cdf_create() for CDI_FILETYPE_NCZARR.

parent 1ae6bae1
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,19 @@ cdfComment(int ncid)
}
#endif
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;
}
static int
cdfOpenFile(const char *filename, const char *mode, int *filetype)
{
......@@ -128,7 +141,23 @@ cdfOpenFile(const char *filename, const char *mode, int *filetype)
if (*filetype == CDI_FILETYPE_NC4C) writemode |= (NC_NETCDF4 | NC_CLASSIC_MODEL);
if (*filetype == CDI_FILETYPE_NCZARR) writemode |= NC_NETCDF4;
#endif
cdf__create(filename, writemode, &ncid);
if (*filetype == CDI_FILETYPE_NCZARR)
{
if (has_uri(filename))
{
cdf_create(filename, writemode, &ncid);
}
else
{
fprintf(stderr, "URI is missing in NCZarr path!\n");
return CDI_EINVAL;
}
}
else
{
cdf__create(filename, writemode, &ncid);
}
if (CDI_Version_Info) cdfComment(ncid);
cdf_put_att_text(ncid, NC_GLOBAL, "Conventions", 6, "CF-1.6");
break;
......
......@@ -12,17 +12,19 @@
#ifdef HAVE_LIBNETCDF
static bool
has_uri(const char *uri)
void
cdf_create(const char *path, int cmode, int *ncidp)
{
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;
}
int status = nc_create(path, cmode, ncidp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d mode=%d file=%s", *ncidp, cmode, path);
if (status != NC_NOERR) Error("%s: %s", path, nc_strerror(status));
int oldfill;
status = nc_set_fill(*ncidp, NC_NOFILL, &oldfill);
return false;
if (status != NC_NOERR) Error("%s: %s", path, nc_strerror(status));
}
void
......@@ -31,23 +33,16 @@ cdf__create(const char *path, int cmode, int *ncidp)
int status = -1;
size_t chunksizehint = 0;
if (has_uri(path))
{
status = nc_create(path, cmode, ncidp);
}
else
{
size_t initialsz = 0;
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;
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);
......
......@@ -6,6 +6,7 @@
#include <netcdf.h>
void cdf__create(const char *path, int cmode, int *idp);
void cdf_create(const char *path, int cmode, int *idp);
int cdf_open(const char *path, int omode, int *idp);
void cdf_close(int ncid);
......
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