Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
ef3f898b
Commit
ef3f898b
authored
2 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
Added cdf_create() for CDI_FILETYPE_NCZARR.
parent
1ae6bae1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cdf.c
+30
-1
30 additions, 1 deletion
src/cdf.c
src/cdf_int.c
+16
-21
16 additions, 21 deletions
src/cdf_int.c
src/cdf_int.h
+1
-0
1 addition, 0 deletions
src/cdf_int.h
with
47 additions
and
22 deletions
src/cdf.c
+
30
−
1
View file @
ef3f898b
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
src/cdf_int.c
+
16
−
21
View file @
ef3f898b
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
src/cdf_int.h
+
1
−
0
View file @
ef3f898b
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment