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);
 
   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->controls.mapimpl,nc->path,nc->mode,zinfo->controls.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;
 
  106     char* nczarr_version = NULL;
 
  107     char* zarr_format = NULL;
 
  109     ZTRACE(3,
"file=%s controls=%s",file->hdr.name,(controls?nczprint_envv(controls):
"null"));
 
  112     nc = (NC*)file->controller;
 
  115     root = file->root_grp;
 
  116     assert(root != NULL && root->hdr.sort == NCGRP);
 
  119     if (!(file->format_file_info = calloc(1, 
sizeof(NCZ_FILE_INFO_T))))
 
  121     zinfo = file->format_file_info;
 
  125     zinfo->common.file = file;
 
  127     if((zinfo->envv_controls = NCZ_clonestringvec(0,controls))==NULL) 
 
  131     if (!(root->format_grp_info = calloc(1, 
sizeof(NCZ_GRP_INFO_T))))
 
  133     ((NCZ_GRP_INFO_T*)root->format_grp_info)->common.file = file;
 
  136     if((stat = applycontrols(zinfo))) 
goto done;
 
  139     if((stat = nczmap_open(zinfo->controls.mapimpl,nc->path,mode,zinfo->controls.flags,NULL,&zinfo->map)))
 
  142     if((stat = ncz_read_superblock(file,&nczarr_version,&zarr_format))) 
goto done;
 
  144     if(nczarr_version == NULL) 
 
  145         nczarr_version = strdup(NCZARRVERSION);
 
  146     if(zarr_format == NULL) 
 
  147        zarr_format = strdup(ZARRVERSION);
 
  149     if(sscanf(zarr_format,
"%d",&zinfo->zarr.zarr_version)!=1)
 
  151     if(sscanf(nczarr_version,
"%lu.%lu.%lu",
 
  152             &zinfo->zarr.nczarr_version.major,
 
  153             &zinfo->zarr.nczarr_version.minor,
 
  154             &zinfo->zarr.nczarr_version.release) == 0)
 
  158     if((stat = ncuriparse(nc->path,&uri))) 
goto done;
 
  160     if((stat = NC_authsetup(&zinfo->auth, uri)))
 
  165     nullfree(zarr_format);
 
  166     nullfree(nczarr_version);
 
  168     nclistfreeall(modeargs);
 
  169     if(json) NCJreclaim(json);
 
  171     return ZUNTRACE(stat);
 
  185 NCZ_isnetcdf4(
struct NC_FILE_INFO* h5)
 
  205 NCZ_get_libversion(
unsigned long* majorp, 
unsigned long* minorp,
unsigned long* releasep)
 
  207     unsigned long m0,m1,m2;
 
  208     sscanf(NCZARRVERSION,
"%lu.%lu.%lu",&m0,&m1,&m2);
 
  209     if(majorp) *majorp = m0;
 
  210     if(minorp) *minorp = m1;
 
  211     if(releasep) *releasep = m2;
 
  227 NCZ_get_superblock(NC_FILE_INFO_T* file, 
int* superblockp)
 
  229     NCZ_FILE_INFO_T* zinfo = file->format_file_info;
 
  230     if(superblockp) *superblockp = zinfo->zarr.nczarr_version.major;
 
  246 ncz_open_rootgroup(NC_FILE_INFO_T* dataset)
 
  250     NCZ_FILE_INFO_T* zfile = NULL;
 
  251     NC_GRP_INFO_T* root = NULL;
 
  252     void* content = NULL;
 
  253     char* rootpath = NULL;
 
  256     ZTRACE(3,
"dataset=",dataset->hdr.name);
 
  258     zfile = dataset->format_file_info;
 
  261     root = dataset->root_grp;
 
  263     assert(root != NULL);
 
  265     if((stat=nczm_concat(NULL,ZGROUP,&rootpath)))
 
  267     if((stat = NCZ_downloadjson(zfile->map, rootpath, &json)))
 
  270     for(i=0;i<nclistlength(json->contents);i+=2) {
 
  271     const NCjson* key = nclistget(json->contents,i);
 
  272     const NCjson* value = nclistget(json->contents,i+1);
 
  273     if(strcmp(NCJstring(key),
"zarr_format")==0) {
 
  275         if(sscanf(NCJstring(value),
"%d",&zversion)!=1)
 
  278         if(zversion != zfile->zarr.zarr_version)
 
  284     if(json) NCJreclaim(json);
 
  287     return ZUNTRACE(stat);
 
  302 ncz_unload_jatts(NCZ_FILE_INFO_T* zinfo, NC_OBJ* container, NCjson* jattrs, NCjson* jtypes)
 
  305     char* fullpath = NULL;
 
  308     NCZMAP* map = zinfo->map;
 
  310     assert((jattrs->sort = NCJ_DICT));
 
  311     assert((jtypes->sort = NCJ_DICT));
 
  313     if(container->sort == NCGRP) {
 
  314         NC_GRP_INFO_T* grp = (NC_GRP_INFO_T*)container;
 
  316         if((stat = NCZ_grpkey(grp,&fullpath)))
 
  319         NC_VAR_INFO_T* var = (NC_VAR_INFO_T*)container;
 
  321         if((stat = NCZ_varkey(var,&fullpath)))
 
  326     if((stat = nczm_concat(fullpath,ZATTRS,&akey)))
 
  335         if(NCJremove(jattrs,NCZ_V2_ATTRS,&k,&v) == 
NC_NOERR) {
 
  336         NCJreclaim(k); NCJreclaim(v);
 
  340     if(!(zinfo->controls.flags & FLAG_PUREZARR)) {
 
  342          if((stat = NCJinsert(jattrs,NCZ_V2_ATTRS,jtypes))) 
goto done;
 
  346     if((stat=NCZ_uploadjson(map,tkey,jattrs)))
 
  362 controllookup(
const char** envv_controls, 
const char* key)
 
  365     for(p=envv_controls;*p;p+=2) {
 
  366     if(strcasecmp(key,*p)==0) {
 
  375 applycontrols(NCZ_FILE_INFO_T* zinfo)
 
  378     const char* value = NULL;
 
  379     NClist* modelist = nclistnew();
 
  382     if((value = controllookup((
const char**)zinfo->envv_controls,
"mode")) != NULL) {
 
  383     if((stat = NCZ_comma_parse(value,modelist))) 
goto done;
 
  386     zinfo->controls.mapimpl = NCZM_DEFAULT;
 
  387     for(i=0;i<nclistlength(modelist);i++) {
 
  388         const char* p = nclistget(modelist,i);
 
  389     if(strcasecmp(p,PUREZARRCONTROL)==0) zinfo->controls.flags |= (FLAG_PUREZARR|FLAG_XARRAYDIMS);
 
  390     else if(strcasecmp(p,XARRAYCONTROL)==0) zinfo->controls.flags |= (FLAG_XARRAYDIMS|FLAG_PUREZARR); 
 
  391     else if(strcasecmp(p,NOXARRAYCONTROL)==0) {
 
  392         noflags |= FLAG_XARRAYDIMS;
 
  393         zinfo->controls.flags |= FLAG_PUREZARR; 
 
  395     else if(strcasecmp(p,
"zip")==0) zinfo->controls.mapimpl = NCZM_ZIP;
 
  396     else if(strcasecmp(p,
"file")==0) zinfo->controls.mapimpl = NCZM_FILE;
 
  397     else if(strcasecmp(p,
"s3")==0) zinfo->controls.mapimpl = NCZM_S3;
 
  401     zinfo->controls.flags &= (~noflags);
 
  404     if((value = controllookup((
const char**)zinfo->envv_controls,
"log")) != NULL) {
 
  405     zinfo->controls.flags |= FLAG_LOGGING;
 
  408     if((value = controllookup((
const char**)zinfo->envv_controls,
"show")) != NULL) {
 
  409     if(strcasecmp(value,
"fetch")==0)
 
  410         zinfo->controls.flags |= FLAG_SHOWFETCH;
 
  413     nclistfreeall(modelist);