12static int applycontrols(NCZ_FILE_INFO_T* zinfo);
26ncz_create_dataset(NC_FILE_INFO_T* file, NC_GRP_INFO_T* root, NClist* controls)
29 NCZ_FILE_INFO_T* zinfo = NULL;
30 NCZ_GRP_INFO_T* zgrp = NULL;
36 ZTRACE(3,
"file=%s root=%s controls=%s",file->hdr.name,root->hdr.name,(controls?nczprint_envv(controls):
"null"));
38 nc = (NC*)file->controller;
41 if (!(zinfo = calloc(1,
sizeof(NCZ_FILE_INFO_T))))
43 file->format_file_info = zinfo;
44 zinfo->common.file = file;
47 if (!(zgrp = calloc(1,
sizeof(NCZ_GRP_INFO_T))))
49 root->format_grp_info = zgrp;
50 zgrp->common.file = file;
54 zinfo->common.file = file;
56 if((zinfo->controllist=nclistclone(controls,1)) == NULL)
60 zinfo->zarr.zarr_version = atoi(ZARRVERSION);
61 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",
62 &zinfo->zarr.nczarr_version.major,
63 &zinfo->zarr.nczarr_version.minor,
64 &zinfo->zarr.nczarr_version.release);
66 zinfo->default_maxstrlen = NCZ_MAXSTR_DEFAULT;
69 if((stat = applycontrols(zinfo)))
goto done;
72 if((stat = ncuriparse(nc->path,&uri)))
goto done;
74 if((stat = NC_authsetup(&zinfo->auth, uri)))
79 if((stat = nczmap_create(zinfo->controls.mapimpl,nc->path,nc->mode,zinfo->controls.flags,NULL,&zinfo->map)))
82 if((stat = NCZMD_set_metadata_handler(zinfo))){
90 return ZUNTRACE(stat);
102ncz_open_dataset(NC_FILE_INFO_T* file, NClist* controls)
106 NC_GRP_INFO_T* root = NULL;
108 void* content = NULL;
110 NCZ_FILE_INFO_T* zinfo = NULL;
112 NClist* modeargs = NULL;
113 char* nczarr_version = NULL;
114 char* zarr_format = NULL;
116 ZTRACE(3,
"file=%s controls=%s",file->hdr.name,(controls?nczprint_envv(controls):
"null"));
119 nc = (NC*)file->controller;
122 root = file->root_grp;
123 assert(root != NULL && root->hdr.sort == NCGRP);
126 if (!(file->format_file_info = calloc(1,
sizeof(NCZ_FILE_INFO_T))))
128 zinfo = file->format_file_info;
132 zinfo->common.file = file;
134 if((zinfo->controllist=nclistclone(controls,1)) == NULL)
136 zinfo->default_maxstrlen = NCZ_MAXSTR_DEFAULT;
139 if (!(root->format_grp_info = calloc(1,
sizeof(NCZ_GRP_INFO_T))))
141 ((NCZ_GRP_INFO_T*)root->format_grp_info)->common.file = file;
144 if((stat = applycontrols(zinfo)))
goto done;
147 if((stat = nczmap_open(zinfo->controls.mapimpl,nc->path,mode,zinfo->controls.flags,NULL,&zinfo->map)))
150 if((stat = NCZMD_set_metadata_handler(zinfo))) {
155 if((stat = ncz_read_superblock(file,&nczarr_version,&zarr_format)))
goto done;
157 if(nczarr_version == NULL)
158 nczarr_version = strdup(NCZARRVERSION);
159 if(zarr_format == NULL)
160 zarr_format = strdup(ZARRVERSION);
162 if(sscanf(zarr_format,
"%d",&zinfo->zarr.zarr_version)!=1)
164 if(sscanf(nczarr_version,
"%lu.%lu.%lu",
165 &zinfo->zarr.nczarr_version.major,
166 &zinfo->zarr.nczarr_version.minor,
167 &zinfo->zarr.nczarr_version.release) == 0)
171 if((stat = ncuriparse(nc->path,&uri)))
goto done;
173 if((stat = NC_authsetup(&zinfo->auth, uri)))
178 nullfree(zarr_format);
179 nullfree(nczarr_version);
181 nclistfreeall(modeargs);
182 if(json) NCJreclaim(json);
184 return ZUNTRACE(stat);
198NCZ_isnetcdf4(
struct NC_FILE_INFO* h5)
218NCZ_get_libversion(
unsigned long* majorp,
unsigned long* minorp,
unsigned long* releasep)
220 unsigned long m0,m1,m2;
221 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",&m0,&m1,&m2);
222 if(majorp) *majorp = m0;
223 if(minorp) *minorp = m1;
224 if(releasep) *releasep = m2;
240NCZ_get_superblock(NC_FILE_INFO_T* file,
int* superblockp)
242 NCZ_FILE_INFO_T* zinfo = file->format_file_info;
243 if(superblockp) *superblockp = zinfo->zarr.nczarr_version.major;
251controllookup(NClist* controls,
const char* key)
254 for(i=0;i<nclistlength(controls);i+=2) {
255 const char* p = (
char*)nclistget(controls,i);
256 if(strcasecmp(key,p)==0) {
257 return (
const char*)nclistget(controls,i+1);
265applycontrols(NCZ_FILE_INFO_T* zinfo)
269 const char* value = NULL;
270 NClist* modelist = nclistnew();
271 size64_t noflags = 0;
273 if((value = controllookup(zinfo->controllist,
"mode")) != NULL) {
274 if((stat = NCZ_comma_parse(value,modelist)))
goto done;
277 zinfo->controls.mapimpl = NCZM_DEFAULT;
278 zinfo->controls.flags |= FLAG_XARRAYDIMS;
279 zinfo->controls.flags |= (NCZARR_CONSOLIDATED_DEFAULT ? FLAG_CONSOLIDATED : 0);
280 for(i=0;i<nclistlength(modelist);i++) {
281 const char* p = nclistget(modelist,i);
282 if(strcasecmp(p,PUREZARRCONTROL)==0)
283 zinfo->controls.flags |= (FLAG_PUREZARR);
284 else if(strcasecmp(p,XARRAYCONTROL)==0)
285 zinfo->controls.flags |= FLAG_PUREZARR;
286 else if(strcasecmp(p,NOXARRAYCONTROL)==0)
287 noflags |= FLAG_XARRAYDIMS;
288 else if(strcasecmp(p,
"zip")==0) zinfo->controls.mapimpl = NCZM_ZIP;
289 else if(strcasecmp(p,
"file")==0) zinfo->controls.mapimpl = NCZM_FILE;
290 else if(strcasecmp(p,
"s3")==0) zinfo->controls.mapimpl = NCZM_S3;
291 else if(strcasecmp(p,
"consolidated") == 0)
292 zinfo->controls.flags |= FLAG_CONSOLIDATED;
296 zinfo->controls.flags &= (~noflags);
299 if((value = controllookup(zinfo->controllist,
"log")) != NULL) {
300 zinfo->controls.flags |= FLAG_LOGGING;
301 ncsetloglevel(NCLOGNOTE);
303 if((value = controllookup(zinfo->controllist,
"show")) != NULL) {
304 if(strcasecmp(value,
"fetch")==0)
305 zinfo->controls.flags |= FLAG_SHOWFETCH;
308 nclistfreeall(modelist);
#define NC_ENDIAN_BIG
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_ENCZARR
Error at NCZarr layer.
#define NC_ENDIAN_LITTLE
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_NOERR
No Error.