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->controls=NCZ_clonestringvec(0,controls)) == NULL)
59 zinfo->zarr.zarr_version = 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);
66 if((stat = applycontrols(zinfo)))
goto done;
69 if((stat = ncuriparse(nc->path,&uri)))
goto done;
71 if((stat = NC_authsetup(&zinfo->auth, uri)))
76 if((stat = nczmap_create(zinfo->features.mapimpl,nc->path,nc->mode,zinfo->features.flags,NULL,&zinfo->map)))
83 return ZUNTRACE(stat);
95 ncz_open_dataset(NC_FILE_INFO_T* file,
const char** controls)
99 NC_GRP_INFO_T* root = NULL;
101 void* content = NULL;
103 NCZ_FILE_INFO_T* zinfo = NULL;
105 NClist* modeargs = NULL;
107 ZTRACE(3,
"file=%s controls=%s",file->hdr.name,(controls?nczprint_envv(controls):
"null"));
110 nc = (NC*)file->controller;
113 root = file->root_grp;
114 assert(root != NULL && root->hdr.sort == NCGRP);
117 if (!(file->format_file_info = calloc(1,
sizeof(NCZ_FILE_INFO_T))))
119 zinfo = file->format_file_info;
123 zinfo->common.file = file;
125 if((zinfo->controls = NCZ_clonestringvec(0,controls))==NULL)
129 if (!(root->format_grp_info = calloc(1,
sizeof(NCZ_GRP_INFO_T))))
131 ((NCZ_GRP_INFO_T*)root->format_grp_info)->common.file = file;
134 if((stat = applycontrols(zinfo)))
goto done;
137 if((stat = nczmap_open(zinfo->features.mapimpl,nc->path,mode,zinfo->features.flags,NULL,&zinfo->map)))
140 if(!(zinfo->features.flags & FLAG_PUREZARR)
141 && (stat = NCZ_downloadjson(zinfo->map, NCZMETAROOT, &json)) ==
NC_NOERR) {
143 for(i=0;i<nclistlength(json->contents);i+=2) {
144 const NCjson* key = nclistget(json->contents,i);
145 const NCjson* value = nclistget(json->contents,i+1);
146 if(strcmp(key->value,
"zarr_format")==0) {
147 if(sscanf(value->value,
"%d",&zinfo->zarr.zarr_version)!=1)
149 }
else if(strcmp(key->value,
"nczarr_version")==0) {
150 sscanf(value->value,
"%lu.%lu.%lu",
151 &zinfo->zarr.nczarr_version.major,
152 &zinfo->zarr.nczarr_version.minor,
153 &zinfo->zarr.nczarr_version.release);
157 zinfo->zarr.zarr_version = ZARRVERSION;
158 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",
159 &zinfo->zarr.nczarr_version.major,
160 &zinfo->zarr.nczarr_version.minor,
161 &zinfo->zarr.nczarr_version.release);
165 if((stat = ncuriparse(nc->path,&uri)))
goto done;
167 if((stat = NC_authsetup(&zinfo->auth, uri)))
173 nclistfreeall(modeargs);
174 if(json) NCJreclaim(json);
176 return ZUNTRACE(stat);
191 NCZ_isnetcdf4(
struct NC_FILE_INFO* h5)
211 NCZ_get_libversion(
unsigned long* majorp,
unsigned long* minorp,
unsigned long* releasep)
213 unsigned long m0,m1,m2;
214 sscanf(NCZARRVERSION,
"%lu.%lu.%lu",&m0,&m1,&m2);
215 if(majorp) *majorp = m0;
216 if(minorp) *minorp = m1;
217 if(releasep) *releasep = m2;
233 NCZ_get_superblock(NC_FILE_INFO_T* file,
int* superblockp)
235 NCZ_FILE_INFO_T* zinfo = file->format_file_info;
236 if(superblockp) *superblockp = zinfo->zarr.nczarr_version.major;
252 ncz_open_rootgroup(NC_FILE_INFO_T* dataset)
256 NCZ_FILE_INFO_T* zfile = NULL;
257 NC_GRP_INFO_T* root = NULL;
258 void* content = NULL;
259 char* rootpath = NULL;
262 ZTRACE(3,
"dataset=",dataset->hdr.name);
264 zfile = dataset->format_file_info;
267 root = dataset->root_grp;
269 assert(root != NULL);
271 if((stat=nczm_concat(NULL,ZGROUP,&rootpath)))
273 if((stat = NCZ_downloadjson(zfile->map, rootpath, &json)))
276 for(i=0;i<nclistlength(json->contents);i+=2) {
277 const NCjson* key = nclistget(json->contents,i);
278 const NCjson* value = nclistget(json->contents,i+1);
279 if(strcmp(key->value,
"zarr_format")==0) {
281 if(sscanf(value->value,
"%d",&zversion)!=1)
284 if(zversion != zfile->zarr.zarr_version)
290 if(json) NCJreclaim(json);
293 return ZUNTRACE(stat);
307 ncz_unload_jatts(NCZ_FILE_INFO_T* zinfo, NC_OBJ* container, NCjson* jattrs, NCjson* jtypes)
310 char* fullpath = NULL;
313 NCZMAP* map = zinfo->map;
315 assert((jattrs->sort = NCJ_DICT));
316 assert((jtypes->sort = NCJ_DICT));
318 if(container->sort == NCGRP) {
319 NC_GRP_INFO_T* grp = (NC_GRP_INFO_T*)container;
321 if((stat = NCZ_grpkey(grp,&fullpath)))
324 NC_VAR_INFO_T* var = (NC_VAR_INFO_T*)container;
326 if((stat = NCZ_varkey(var,&fullpath)))
331 if((stat = nczm_concat(fullpath,ZATTRS,&akey)))
335 if((stat=NCZ_uploadjson(map,tkey,jattrs)))
338 if(!(zinfo->features.flags & FLAG_PUREZARR)) {
340 if((stat = nczm_concat(fullpath,NCZATTR,&tkey)))
343 if((stat=NCZ_uploadjson(map,tkey,jtypes)))
359 controllookup(
const char** controls,
const char* key)
362 for(p=controls;*p;p++) {
363 if(strcasecmp(key,*p)==0) {
372 applycontrols(NCZ_FILE_INFO_T* zinfo)
375 const char* value = NULL;
376 NClist* modelist = nclistnew();
378 if((value = controllookup((
const char**)zinfo->controls,
"mode")) != NULL) {
379 if((stat = NCZ_comma_parse(value,modelist)))
goto done;
382 zinfo->features.mapimpl = NCZM_DEFAULT;
383 for(i=0;i<nclistlength(modelist);i++) {
384 const char* p = nclistget(modelist,i);
385 if(strcasecmp(p,PUREZARR)==0) zinfo->features.flags |= FLAG_PUREZARR;
386 else if(strcasecmp(p,
"zip")==0) zinfo->features.mapimpl = NCZM_ZIP;
387 else if(strcasecmp(p,
"file")==0) zinfo->features.mapimpl = NCZM_FILE;
388 else if(strcasecmp(p,
"s3")==0) zinfo->features.mapimpl = NCZM_S3;
391 if((value = controllookup((
const char**)zinfo->controls,
"log")) != NULL) {
392 zinfo->features.flags |= FLAG_LOGGING;
395 if((value = controllookup((
const char**)zinfo->controls,
"show")) != NULL) {
396 if(strcasecmp(value,
"fetch")==0)
397 zinfo->features.flags |= FLAG_SHOWFETCH;
400 nclistfreeall(modelist);