11 static int applycontrols(NCZ_FILE_INFO_T* zinfo);
25 ncz_create_dataset(NC_FILE_INFO_T* file, NC_GRP_INFO_T* root,
const char** controls)
28 NCZ_FILE_INFO_T* zinfo = NULL;
29 NCZ_GRP_INFO_T* zgrp = NULL;
35 ZTRACE(3,
"file=%s root=%s controls=%s",file->hdr.name,root->hdr.name,(controls?nczprint_envv(controls):
"null"));
37 nc = (NC*)file->controller;
40 if (!(zinfo = calloc(1,
sizeof(NCZ_FILE_INFO_T))))
42 file->format_file_info = zinfo;
43 zinfo->common.file = file;
46 if (!(zgrp = calloc(1,
sizeof(NCZ_GRP_INFO_T))))
48 root->format_grp_info = zgrp;
49 zgrp->common.file = file;
53 zinfo->common.file = file;
55 if((zinfo->envv_controls=NCZ_clonestringvec(0,controls)) == NULL)
59 zinfo->zarr.zarr_version = atoi(ZARRVERSION);
60 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",
61 &zinfo->zarr.nczarr_version.major,
62 &zinfo->zarr.nczarr_version.minor,
63 &zinfo->zarr.nczarr_version.release);
65 zinfo->default_maxstrlen = NCZ_MAXSTR_DEFAULT;
68 if((stat = applycontrols(zinfo)))
goto done;
71 if((stat = ncuriparse(nc->path,&uri)))
goto done;
73 if((stat = NC_authsetup(&zinfo->auth, uri)))
78 if((stat = nczmap_create(zinfo->controls.mapimpl,nc->path,nc->mode,zinfo->controls.flags,NULL,&zinfo->map)))
85 return ZUNTRACE(stat);
97 ncz_open_dataset(NC_FILE_INFO_T* file,
const char** controls)
101 NC_GRP_INFO_T* root = NULL;
103 void* content = NULL;
105 NCZ_FILE_INFO_T* zinfo = NULL;
107 NClist* modeargs = NULL;
108 char* nczarr_version = NULL;
109 char* zarr_format = NULL;
111 ZTRACE(3,
"file=%s controls=%s",file->hdr.name,(controls?nczprint_envv(controls):
"null"));
114 nc = (NC*)file->controller;
117 root = file->root_grp;
118 assert(root != NULL && root->hdr.sort == NCGRP);
121 if (!(file->format_file_info = calloc(1,
sizeof(NCZ_FILE_INFO_T))))
123 zinfo = file->format_file_info;
127 zinfo->common.file = file;
129 if((zinfo->envv_controls = NCZ_clonestringvec(0,controls))==NULL)
131 zinfo->default_maxstrlen = NCZ_MAXSTR_DEFAULT;
134 if (!(root->format_grp_info = calloc(1,
sizeof(NCZ_GRP_INFO_T))))
136 ((NCZ_GRP_INFO_T*)root->format_grp_info)->common.file = file;
139 if((stat = applycontrols(zinfo)))
goto done;
142 if((stat = nczmap_open(zinfo->controls.mapimpl,nc->path,mode,zinfo->controls.flags,NULL,&zinfo->map)))
145 if((stat = ncz_read_superblock(file,&nczarr_version,&zarr_format)))
goto done;
147 if(nczarr_version == NULL)
148 nczarr_version = strdup(NCZARRVERSION);
149 if(zarr_format == NULL)
150 zarr_format = strdup(ZARRVERSION);
152 if(sscanf(zarr_format,
"%d",&zinfo->zarr.zarr_version)!=1)
154 if(sscanf(nczarr_version,
"%lu.%lu.%lu",
155 &zinfo->zarr.nczarr_version.major,
156 &zinfo->zarr.nczarr_version.minor,
157 &zinfo->zarr.nczarr_version.release) == 0)
161 if((stat = ncuriparse(nc->path,&uri)))
goto done;
163 if((stat = NC_authsetup(&zinfo->auth, uri)))
168 nullfree(zarr_format);
169 nullfree(nczarr_version);
171 nclistfreeall(modeargs);
172 if(json) NCJreclaim(json);
174 return ZUNTRACE(stat);
188 NCZ_isnetcdf4(
struct NC_FILE_INFO* h5)
208 NCZ_get_libversion(
unsigned long* majorp,
unsigned long* minorp,
unsigned long* releasep)
210 unsigned long m0,m1,m2;
211 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",&m0,&m1,&m2);
212 if(majorp) *majorp = m0;
213 if(minorp) *minorp = m1;
214 if(releasep) *releasep = m2;
230 NCZ_get_superblock(NC_FILE_INFO_T* file,
int* superblockp)
232 NCZ_FILE_INFO_T* zinfo = file->format_file_info;
233 if(superblockp) *superblockp = zinfo->zarr.nczarr_version.major;
249 ncz_open_rootgroup(NC_FILE_INFO_T* dataset)
253 NCZ_FILE_INFO_T* zfile = NULL;
254 NC_GRP_INFO_T* root = NULL;
255 void* content = NULL;
256 char* rootpath = NULL;
259 ZTRACE(3,
"dataset=",dataset->hdr.name);
261 zfile = dataset->format_file_info;
264 root = dataset->root_grp;
266 assert(root != NULL);
268 if((stat=nczm_concat(NULL,ZGROUP,&rootpath)))
270 if((stat = NCZ_downloadjson(zfile->map, rootpath, &json)))
273 for(i=0;i<nclistlength(json->contents);i+=2) {
274 const NCjson* key = nclistget(json->contents,i);
275 const NCjson* value = nclistget(json->contents,i+1);
276 if(strcmp(NCJstring(key),
"zarr_format")==0) {
278 if(sscanf(NCJstring(value),
"%d",&zversion)!=1)
281 if(zversion != zfile->zarr.zarr_version)
287 if(json) NCJreclaim(json);
290 return ZUNTRACE(stat);
296 controllookup(
const char** envv_controls,
const char* key)
299 for(p=envv_controls;*p;p+=2) {
300 if(strcasecmp(key,*p)==0) {
309 applycontrols(NCZ_FILE_INFO_T* zinfo)
312 const char* value = NULL;
313 NClist* modelist = nclistnew();
316 if((value = controllookup((
const char**)zinfo->envv_controls,
"mode")) != NULL) {
317 if((stat = NCZ_comma_parse(value,modelist)))
goto done;
320 zinfo->controls.mapimpl = NCZM_DEFAULT;
321 zinfo->controls.flags |= FLAG_XARRAYDIMS;
322 for(i=0;i<nclistlength(modelist);i++) {
323 const char* p = nclistget(modelist,i);
324 if(strcasecmp(p,PUREZARRCONTROL)==0)
325 zinfo->controls.flags |= (FLAG_PUREZARR);
326 else if(strcasecmp(p,XARRAYCONTROL)==0)
327 zinfo->controls.flags |= FLAG_PUREZARR;
328 else if(strcasecmp(p,NOXARRAYCONTROL)==0)
329 noflags |= FLAG_XARRAYDIMS;
330 else if(strcasecmp(p,
"zip")==0) zinfo->controls.mapimpl = NCZM_ZIP;
331 else if(strcasecmp(p,
"file")==0) zinfo->controls.mapimpl = NCZM_FILE;
332 else if(strcasecmp(p,
"s3")==0) zinfo->controls.mapimpl = NCZM_S3;
336 zinfo->controls.flags &= (~noflags);
339 if((value = controllookup((
const char**)zinfo->envv_controls,
"log")) != NULL) {
340 zinfo->controls.flags |= FLAG_LOGGING;
343 if((value = controllookup((
const char**)zinfo->envv_controls,
"show")) != NULL) {
344 if(strcasecmp(value,
"fetch")==0)
345 zinfo->controls.flags |= FLAG_SHOWFETCH;
348 nclistfreeall(modelist);
363 ncz_unload_jatts(NCZ_FILE_INFO_T* zinfo, NC_OBJ* container, NCjson* jattrs, NCjson* jtypes)
366 char* fullpath = NULL;
369 NCZMAP* map = zinfo->map;
371 assert((NCJsort(jattrs) == NCJ_DICT));
372 assert((NCJsort(jtypes) == NCJ_DICT));
374 if(container->sort == NCGRP) {
375 NC_GRP_INFO_T* grp = (NC_GRP_INFO_T*)container;
377 if((stat = NCZ_grpkey(grp,&fullpath)))
380 NC_VAR_INFO_T* var = (NC_VAR_INFO_T*)container;
382 if((stat = NCZ_varkey(var,&fullpath)))
387 if((stat = nczm_concat(fullpath,ZATTRS,&akey)))
396 if(!NCJremove(jattrs,NCZ_V2_ATTRS,1,&k,&v)) {
397 NCJreclaim(k); NCJreclaim(v);
401 if(!(zinfo->controls.flags & FLAG_PUREZARR)) {
403 if((stat = NCJinsert(jattrs,NCZ_V2_ATTRS,jtypes)))
goto done;
407 if((stat=NCZ_uploadjson(map,tkey,jattrs)))
#define NC_ENDIAN_BIG
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_ENOTNC
Not a netcdf file.
#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.