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

Add function cdf_open_write().

parent 6498a73f
No related branches found
No related tags found
2 merge requests!42Develop,!36M214003/develop
......@@ -81,55 +81,64 @@ cdf_open_read(const char *filename, int *filetype)
#endif
}
#endif
return ncid;
}
static int
cdfOpenFile(const char *filename, const char *mode, int *filetype)
cdf_open_write(const char *filename, int *filetype)
{
int ncid = -1;
int fmode = tolower(*mode);
int writemode = NC_CLOBBER;
int readmode = NC_NOWRITE;
if (filename == NULL)
ncid = CDI_EINVAL;
else
{
switch (fmode)
{
case 'r':
ncid = cdf_open_read(filename, filetype);
break;
case 'w':
#ifdef NC_64BIT_OFFSET
if (*filetype == CDI_FILETYPE_NC2) writemode |= NC_64BIT_OFFSET;
if (*filetype == CDI_FILETYPE_NC2) writemode |= NC_64BIT_OFFSET;
#endif
#ifdef NC_64BIT_DATA
if (*filetype == CDI_FILETYPE_NC5) writemode |= NC_64BIT_DATA;
if (*filetype == CDI_FILETYPE_NC5) writemode |= NC_64BIT_DATA;
#endif
#ifdef HAVE_NETCDF4
if (*filetype == CDI_FILETYPE_NC4C) writemode |= (NC_NETCDF4 | NC_CLASSIC_MODEL);
if (*filetype == CDI_FILETYPE_NC4) writemode |= NC_NETCDF4;
if (*filetype == CDI_FILETYPE_NCZARR) writemode |= NC_NETCDF4;
if (*filetype == CDI_FILETYPE_NC4C) writemode |= (NC_NETCDF4 | NC_CLASSIC_MODEL);
if (*filetype == CDI_FILETYPE_NC4) writemode |= NC_NETCDF4;
if (*filetype == CDI_FILETYPE_NCZARR) writemode |= NC_NETCDF4;
#endif
if (*filetype == CDI_FILETYPE_NCZARR)
{
if (!has_uri_scheme(filename))
{
fprintf(stderr, "URI scheme is missing in NCZarr path!\n");
return CDI_EINVAL;
}
cdf_create(filename, writemode, &ncid);
}
else
{
if (has_uri_scheme(filename)) fprintf(stderr, "URI scheme defined for non NCZarr Data Model!\n");
cdf__create(filename, writemode, &ncid);
}
if (*filetype == CDI_FILETYPE_NCZARR)
{
if (!has_uri_scheme(filename))
{
fprintf(stderr, "URI scheme is missing in NCZarr path!\n");
return CDI_EINVAL;
}
cdf_create(filename, writemode, &ncid);
}
else
{
if (has_uri_scheme(filename)) fprintf(stderr, "URI scheme defined for non NCZarr Data Model!\n");
cdf__create(filename, writemode, &ncid);
}
return ncid;
}
static int
cdfOpenFile(const char *filename, const char *mode, int *filetype)
{
int ncid = -1;
if (filename == NULL)
{
ncid = CDI_EINVAL;
}
else
{
int fmode = tolower(*mode);
switch (fmode)
{
case 'r': ncid = cdf_open_read(filename, filetype); break;
case 'w':
ncid = cdf_open_write(filename, filetype);
if (CDI_Version_Info) cdfComment(ncid);
cdf_put_att_text(ncid, NC_GLOBAL, "Conventions", 6, "CF-1.6");
break;
......
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