Skip to content

Commit

Permalink
ckp
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisHeimbigner committed Dec 5, 2024
1 parent c6dbbc4 commit fd05809
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 268 deletions.
2 changes: 0 additions & 2 deletions libnczarr/zarr.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ ncz_create_dataset(NC_FILE_INFO_T* file, NC_GRP_INFO_T* root, NClist* urlcontrol
zfile->native_endianness = (NCZ_isLittleEndian() ? NC_ENDIAN_LITTLE : NC_ENDIAN_BIG);
if((zfile->urlcontrols=nclistclone(urlcontrols,1)) == NULL)
{stat = NC_ENOMEM; goto done;}
zsetdfaltstrlen(NCZ_MAXSTR_DFALT,file);

/* Apply client controls */
if((stat = applycontrols(zfile))) goto done;
Expand Down Expand Up @@ -129,7 +128,6 @@ ncz_open_dataset(NC_FILE_INFO_T* file, NClist* urlcontrols)
zfile->native_endianness = (NCZ_isLittleEndian() ? NC_ENDIAN_LITTLE : NC_ENDIAN_BIG);
if((zfile->urlcontrols = nclistclone(urlcontrols,1))==NULL) /*0=>envv style*/
{stat = NC_ENOMEM; goto done;}
zsetdfaltstrlen(NCZ_MAXSTR_DFALT,file);

/* Add struct to hold NCZ-specific group info. */
if (!(root->format_grp_info = calloc(1, sizeof(NCZ_GRP_INFO_T))))
Expand Down
89 changes: 49 additions & 40 deletions libnczarr/zattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,30 +894,30 @@ NCZ_set_dual_obj_data(NC_FILE_INFO_T* file, NC_OBJ* object, const char* name, Du
if(object->sort == NCGRP) {
switch(which) {
case DA_DFALTSTRLEN:
assert(len == 1);
assert(len == 1);
zsetdfaltstrlen((size_t)((int*)data)[0],file);
break;
default: stat = NC_EINVAL; break;
}
default: stat = NC_EINVAL; break;
}
} else {
NC_VAR_INFO_T* var = NULL;
nc_type tid;
NC_VAR_INFO_T* var = NULL;
nc_type tid;
assert(object->sort == NCVAR);
var = (NC_VAR_INFO_T*)object;
tid = var->type_info->hdr.id;
var = (NC_VAR_INFO_T*)object;
tid = var->type_info->hdr.id;
switch(which) {
case DA_FILLVALUE:
assert(len == 1);
assert(len == 1);
if((stat = NC_reclaim_data_all(file->controller,tid,var->fill_value,len))) goto done;
var->fill_value = NULL;
if((stat = NC_copy_data_all(file->controller,tid,data,len,&var->fill_value))) goto done;
break;
case DA_MAXSTRLEN:
assert(len == 1);
assert(len == 1);
zsetmaxstrlen((size_t)((int*)data)[0],var);
break;
case DA_QUANTIZE:
assert(len == 1);
assert(len == 1);
var->nsd = ((int*)data)[0];
break;
default: assert(0);
Expand Down Expand Up @@ -1124,9 +1124,12 @@ NCZ_sync_dual_att(NC_FILE_INFO_T* file, NC_OBJ* container, const char* aname, Du
NC_VAR_INFO_T* var = NULL;
NC_ATT_INFO_T* att = NULL;
int isnew = 0;
NCZ_FILE_INFO_T* zinfo = (NCZ_FILE_INFO_T*)file->format_file_info;
NCZ_VAR_INFO_T* zvar = NULL;

if(container->sort == NCVAR) {
var = (NC_VAR_INFO_T*)container;
zvar = (NCZ_VAR_INFO_T*)var->format_var_info;
}

if(direction == FIXATT) { /* transfer from NC_XXX_INFO_T* to attribute */
Expand All @@ -1146,24 +1149,22 @@ NCZ_sync_dual_att(NC_FILE_INFO_T* file, NC_OBJ* container, const char* aname, Du
if((stat = NCZ_set_att_data(file,att,1,var->fill_value))) goto done;
}
break;
case DA_MAXSTRLEN: {
int maxstrlen;
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
maxstrlen = NCZ_get_maxstrlen((NC_OBJ*)var);
if((stat = NCZ_set_att_data(file,att,1,&maxstrlen))) goto done;
case DA_MAXSTRLEN:
assert(zvar != NULL);
if(zvar->maxstrlen > 0) {
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
if((stat = NCZ_set_att_data(file,att,1,&zvar->maxstrlen))) goto done;
} break;
case DA_DFALTSTRLEN: {
int dfaltstrlen;
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
NCZ_FILE_INFO_T* zinfo = (NCZ_FILE_INFO_T*)file->format_file_info;
dfaltstrlen = zinfo->default_maxstrlen;
if((stat = NCZ_set_att_data(file,att,1,&dfaltstrlen))) goto done;
case DA_DFALTSTRLEN:
assert(zinfo != NULL);
if(zinfo->default_maxstrlen > 0) {
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
if((stat = NCZ_set_att_data(file,att,1,&zinfo->default_maxstrlen))) goto done;
} break;
case DA_QUANTIZE: {
int nsd;
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
nsd = var->nsd;
if((stat = NCZ_set_att_data(file,att,1,&nsd))) goto done;
case DA_QUANTIZE:
if(var->quantize_mode > 0) {
if((stat = NCZ_getattr(file,container,aname,NC_INT,&att,&isnew))) goto done;
if((stat = NCZ_set_att_data(file,att,1,&var->nsd))) goto done;
} break;
default:
stat = NC_ENOTATT;
Expand Down Expand Up @@ -1212,12 +1213,9 @@ int
NCZ_ensure_dual_attributes(NC_FILE_INFO_T* file, NC_OBJ* container)
{
int stat = NC_NOERR;
NC_GRP_INFO_T* grp = NULL;
NC_VAR_INFO_T* var = NULL;

if(container->sort == NCGRP)
grp = (NC_GRP_INFO_T*)container;
else
if(container->sort == NCVAR)
var = (NC_VAR_INFO_T*)container;

/* Some attributes are reflected in var|grp structure so must be sync'd to the attribute */
Expand All @@ -1230,21 +1228,32 @@ NCZ_ensure_dual_attributes(NC_FILE_INFO_T* file, NC_OBJ* container)
if(var->no_fill == NC_NOFILL) {
if((stat = NCZ_disable_fill(file,var))) goto done;
} else { /* var->no_fill == NC_FILL*/
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,NC_FillValue,DA_FILLVALUE,FIXATT))) goto done;
if(var->fill_value != NULL) { /* only update if a fill value is defined */
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,NC_FillValue,DA_FILLVALUE,FIXATT))) goto done;
}
}

/* _nczarr_maxstrlen */
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,NC_NCZARR_MAXSTRLEN_ATTR,DA_MAXSTRLEN,FIXATT))) goto done;

{
NCZ_VAR_INFO_T* vinfo = (NCZ_VAR_INFO_T*)var->format_var_info;
if(vinfo->maxstrlen > 0) {
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,NC_NCZARR_MAXSTRLEN_ATTR,DA_MAXSTRLEN,FIXATT))) goto done;
}
}

/* __Quantizexxx */
qname = NC_findquantizeattname(var->quantize_mode);
if(qname == NULL) {stat = NC_ENOTATT; goto done;}
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,qname,DA_QUANTIZE,FIXATT))) goto done;

if(var->quantize_mode > 0) {
qname = NC_findquantizeattname(var->quantize_mode);
if(qname != NULL) {/* quantize_mode was set */
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,qname,DA_QUANTIZE,FIXATT))) goto done;
}
}
} else {
assert(grp != NULL);
/* _nczarr_default_maxstrlen */
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)var,NC_NCZARR_DFALT_MAXSTRLEN_ATTR,DA_DFALTSTRLEN,FIXATT))) goto done;
NCZ_FILE_INFO_T* zinfo = (NCZ_FILE_INFO_T*)file->format_file_info;
assert(file != NULL);
if(zinfo->default_maxstrlen > 0) {
if((stat = NCZ_sync_dual_att(file,(NC_OBJ*)file->root_grp,NC_NCZARR_DFALT_MAXSTRLEN_ATTR,DA_DFALTSTRLEN,FIXATT))) goto done;
}
}

done:
Expand Down
1 change: 1 addition & 0 deletions libnczarr/zincludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern "C" {
}
#endif

#define ncz_find_default_chunksizes2 nc4_find_default_chunksizes2
#endif /* ZINCLUDES_H */


1 change: 0 additions & 1 deletion libnczarr/zinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ int ncz_gettype(NC_FILE_INFO_T*, NC_GRP_INFO_T*, int xtype, NC_TYPE_INFO_T** typ
int ncz_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
int NCZ_ensure_quantizer(int ncid, NC_VAR_INFO_T* var);
int NCZ_write_var_data(NC_FILE_INFO_T* file, NC_VAR_INFO_T* var);
int NCZ_fillin_var(NC_FILE_INFO_T* h5, NC_VAR_INFO_T* var, NC_TYPE_INFO_T* type, size_t ndims, const int* dimids, size64_t* shape, size64_t* chunksizes, int endianness);
int NCZ_reclaim_dim(NC_DIM_INFO_T* dim);
void zsetmaxstrlen(size_t maxstrlen, NC_VAR_INFO_T* var);
void zsetdfaltstrlen(size_t maxstrlen, NC_FILE_INFO_T* file);
Expand Down
60 changes: 0 additions & 60 deletions libnczarr/znc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,66 +65,6 @@ ncz4_create_var(NC_FILE_INFO_T* file, NC_GRP_INFO_T* parent, const char* name, N
return THROW(stat);
}

#if 0
int
ncz4_build_var(NC_FILE_INFO_T* file, NC_VAR_INFO_T* var,
nc_type nctype,
int storage,
int scalar,
int endianness,
size_t maxstrlen,
int dimsep,
char order,
size_t ndims,
size64_t* shape,
size64_t* chunksizes,
int* dimids,
NClist* filters,
int no_fill,
const void* fillvalue)
{
int stat = NC_NOERR;
NCZ_VAR_INFO_T* zvar = NULL;
NC_TYPE_INFO_T* typ = NULL;
char* dimbasename = NULL;

NC_UNUSED(order);

if(nctype <= NC_NAT || nctype > NC_MAX_ATOMIC_TYPE) {stat = NC_EBADTYPE; goto done;}
/* Locate the NC_TYPE_INFO_T object */
if((stat = ncz_gettype(file,var->container,nctype,&typ))) goto done;

if((stat = NCZ_fillin_var(file, var, typ, ndims, dimids, shape, chunksizes, endianness))) goto done;
zvar = (NCZ_VAR_INFO_T*)var->format_var_info;

/* Overrides */
zvar->dimension_separator = (char)dimsep;
zsetmaxstrlen(maxstrlen,var);

/* Set fill value */
if((stat=NCZ_set_fill_value(file,var,no_fill,fillvalue))) goto done;

#ifdef NETCDF_ENABLE_NCZARR_FILTERS
/* Set the filter list */
{
size_t k, nfilters;
NClist* varfilters = (NClist*)var->filters;
nfilters = nclistlength(filters);
for(k=0;k<nfilters;k++) {
NCZ_Filter* fi = (NCZ_Filter*)nclistremove(filters,0);
assert(fi != NULL);
nclistpush(varfilters,fi);
}
/* At this point, we can finalize the filters */
if((stat = NCZ_filter_setup(file,var))) goto done;
}
#endif /*NETCDF_ENABLE_NCZARR_FILTERS*/

done:
nullfree(dimbasename);
return THROW(stat);
}
#endif

int
ncz4_create_dim(NC_FILE_INFO_T* file, NC_GRP_INFO_T* parent, const struct NCZ_DimInfo* dimdef, NC_DIM_INFO_T** dimp)
Expand Down
6 changes: 4 additions & 2 deletions libnczarr/zsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ ncz_encode_grp(NC_FILE_INFO_T* file, NC_GRP_INFO_T* grp, int isclose)
zinfo = file->format_file_info;
TESTPUREZARR;

/* Create|Update the dual attributes */
if((stat = NCZ_ensure_dual_attributes(file,(NC_OBJ*)grp))) goto done;

if(!purezarr) {
if(grp->parent == NULL) { /* Root group */
if((stat=NCZF_encode_superblock(file,grp,&jsuper))) goto done;
Expand Down Expand Up @@ -193,12 +196,11 @@ ncz_encode_var_meta(NC_FILE_INFO_T* file, NC_VAR_INFO_T* var, int isclose)
if((stat = ncz_create_computed_var_attributes(file,var))) goto done;

/* Create|Update the dual attributes */
if((stat = NCZ_ensure_dual_attributes(file,(NC_OBJ*)var)))
if((stat = NCZ_ensure_dual_attributes(file,(NC_OBJ*)var))) goto done;

/* Convert to JSON */
if((stat=NCZF_encode_attributes(file,(NC_OBJ*)var,&jnczvar,NULL,&zobj.jatts))) goto done;


#ifdef NETCDF_ENABLE_NCZARR_FILTERS
/* Encode the filters */
if((stat=ncz_encode_filters(file,var,filtersj))) goto done;
Expand Down
Loading

0 comments on commit fd05809

Please sign in to comment.