Skip to content

Commit

Permalink
run
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisHeimbigner committed Jan 27, 2024
1 parent 4bbbeda commit c85e763
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 21 deletions.
13 changes: 6 additions & 7 deletions libnczarr/zattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ NCZ_computeattrdata(nc_type typehint, nc_type* typeidp, const NCjson* values, si
size_t typelen;
nc_type typeid = NC_NAT;
NCjson* jtext = NULL;
int reclaimvalues = 0;
int isjson = 0; /* 1 => json valued attribute */
int count = 0; /* no. of attribute values */

Expand All @@ -1270,24 +1269,24 @@ NCZ_computeattrdata(nc_type typehint, nc_type* typeidp, const NCjson* values, si
/* Apply the JSON attribute convention and convert to JSON string */
typeid = NC_CHAR;
if((stat = NCZ_json_convention_read(values,&jtext))) goto done;
values = jtext; jtext = NULL;
reclaimvalues = 1;
/* Convert the JSON attribute values to the actual netcdf attribute bytes */
if((stat = NCZ_attr_convert(jtext,typeid,typelen,&count,buf))) goto done;
} else {
/* Convert the JSON attribute values to the actual netcdf attribute bytes */
if((stat = NCZ_attr_convert(values,typeid,typelen,&count,buf))) goto done;
}

if((stat = NC4_inq_atomic_type(typeid, NULL, &typelen)))
goto done;

/* Convert the JSON attribute values to the actual netcdf attribute bytes */
if((stat = NCZ_attr_convert(values,typeid,typelen,&count,buf))) goto done;

if(typelenp) *typelenp = typelen;
if(typeidp) *typeidp = typeid; /* return possibly inferred type */
if(countp) *countp = count;
if(datap) *datap = ncbytesextract(buf);

done:
ncbytesfree(buf);
if(reclaimvalues) NCJreclaim((NCjson*)values); /* we created it */
NCJreclaim(jtext); /* we created it */
return ZUNTRACEX(THROW(stat),"typelen=%d count=%u",(typelenp?*typelenp:0),(countp?*countp:-1));
}

Expand Down
12 changes: 5 additions & 7 deletions libnczarr/zformat2.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int ZF2_codec2hdf(const NC_FILE_INFO_T* file, const NC_VAR_INFO_T* var, c
static int write_grp(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_GRP_INFO_T* grp);
static int write_var_meta(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_VAR_INFO_T* var);
static int write_var(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_VAR_INFO_T* var);
static int build_atts(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_OBJ* container, NCindex* attlist, NCjson**, NCjson**);
static int build_atts(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_OBJ* container, NCindex* attlist, NCjson**);

static int read_superblock(NC_FILE_INFO_T* file, int* nczarrvp);
static int read_grp(NC_FILE_INFO_T* file, NC_GRP_INFO_T* grp);
Expand Down Expand Up @@ -143,7 +143,6 @@ write_grp(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_GRP_INFO
NCjson* jsuper = NULL;
NCjson* jtmp = NULL;
NCjson* jatts = NULL;
NCjson* jtypes = NULL;

ZTRACE(3,"file=%s grp=%s isclose=%d",file->controller->path,grp->hdr.name,isclose);

Expand Down Expand Up @@ -218,7 +217,7 @@ write_grp(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_GRP_INFO

/* Build and write the Z2ATTRS object */
assert(grp->att);
if((stat = build_atts(file,zfile,map,(NC_OBJ*)grp, grp->att,&jatts,&jtypes)))goto done;
if((stat = build_atts(file,zfile,map,(NC_OBJ*)grp, grp->att,&jatts)))goto done;
/* write .zattrs path */
if((stat = nczm_concat(fullpath,Z2ATTRS,&key))) goto done;
/* Write to map */
Expand Down Expand Up @@ -276,7 +275,6 @@ write_var_meta(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_VAR
NCjson* jtmp = NULL;
NCjson* jfill = NULL;
NCjson* jatts = NULL;
NCjson* jtypes = NULL;
char* dtypename = NULL;
int purezarr = 0;
size64_t shape[NC_MAX_VAR_DIMS];
Expand Down Expand Up @@ -505,7 +503,7 @@ write_var_meta(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_VAR

/* Build and write .zattrs object */
assert(var->att);
if((stat = build_atts(file,zfile,map,(NC_OBJ*)var, var->att,&jatts,&jtypes)))goto done;
if((stat = build_atts(file,zfile,map,(NC_OBJ*)var, var->att,&jatts)))goto done;
/* write .zattrs path */
if((stat = nczm_concat(fullpath,Z2ATTRS,&key))) goto done;
/* Write to map */
Expand Down Expand Up @@ -567,7 +565,7 @@ write_var(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_VAR_INFO
* @author Dennis Heimbigner
*/
static int
build_atts(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_OBJ* container, NCindex* attlist, NCjson** jattsp, NCjson** jtypesp)
build_atts(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_OBJ* container, NCindex* attlist, NCjson** jattsp)
{
int i,stat = NC_NOERR;
NCjson* jatts = NULL;
Expand Down Expand Up @@ -744,7 +742,7 @@ build_atts(NC_FILE_INFO_T* file, NCZ_FILE_INFO_T* zfile, NCZMAP* map, NC_OBJ* co
}

if(jattsp) {*jattsp = jatts; jatts = NULL;}
if(jtypesp) {*jtypesp = jtypes; jtypes = NULL;}
// if(jtypesp) {*jtypesp = jtypes; jtypes = NULL;}
done:
nullfree(fullpath);
nullfree(key);
Expand Down
12 changes: 9 additions & 3 deletions libnczarr/zformat3.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ ZF3_readmeta(NC_FILE_INFO_T* file)
goto done;

done:
NCJreclaim(jrootgrp);
nullfree(rootkey);
nclistfreeall(paths);
return ZUNTRACE(THROW(stat));
Expand Down Expand Up @@ -865,8 +866,8 @@ ZF3_readattrs(NC_FILE_INFO_T* file, NC_OBJ* container, const NCjson* jatts, cons
jkey = NCJdictkey(jatts,i);
assert(jkey != NULL && NCJisatomic(jkey));
jvalue = NCJdictvalue(jatts,i);
ainfo[i].name = NCJstring(jkey);
ainfo[i].values = jvalue;
ainfo[i].name = strdup(NCJstring(jkey));
NCJcheck(NCJclone(jvalue,&ainfo[i].values));
ainfo[i].nctype = NC_NAT; /* not yet known */
}

Expand Down Expand Up @@ -1056,7 +1057,7 @@ read_grp(NC_FILE_INFO_T* file, NC_GRP_INFO_T* grp)
/* Pull out lists about groups and vars */
if(purezarr)
{if((stat = subobjects_pure(zfile,grp,subvars,subgrps))) goto done;}
else
else if(jnczgrp != NULL)
{if((stat = subobjects(zfile,grp,jnczgrp,subvars,subgrps))) goto done;}

/* Define vars */
Expand Down Expand Up @@ -1770,6 +1771,7 @@ subobjects(NCZ_FILE_INFO_T* zfile, NC_GRP_INFO_T* parent, const NCjson* jnczgrp,
const NCjson* jsubgrps = NULL;
const NCjson* jarrays = NULL;

assert(jnczgrp != NULL);
NCJcheck(NCJdictget(jnczgrp,"arrays",&jarrays));
NCJcheck(NCJdictget(jnczgrp,"subgroups",&jsubgrps));

Expand Down Expand Up @@ -2297,16 +2299,20 @@ getnextlevel(NCZ_FILE_INFO_T* zfile, NC_GRP_INFO_T* parent, NClist* varnames, NC
const NCjson* jnodetype;
if(strcmp(name,Z3OBJECT)==0) {continue;}
/* See if name/zarr.json exists */
nullfree(subkey); subkey = NULL;
if((stat = nczm_concat(grpkey,name,&subkey))) goto done;
nullfree(zobject); zobject = NULL;
if((stat = nczm_concat(subkey,Z3OBJECT,&zobject))) goto done;
switch(stat = nczmap_len(zfile->map,zobject,&zjlen)) {
case NC_NOERR: break;
case NC_ENOOBJECT: nclistpush(subgrpnames,name); continue; /* assume a virtual group */
default: goto done;
}
nullfree(content); content = NULL;
if((content = malloc(zjlen))==NULL) {stat = NC_ENOMEM; goto done;}
if((stat = nczmap_read(zfile->map,zobject,0,zjlen,content))) goto done; /* read the zarr.json */
/* parse it */
NCJreclaim(jzarrjson); jzarrjson = NULL;
NCJcheck(NCJparsen((size_t)zjlen,(char*)content,0,&jzarrjson));
if(jzarrjson == NULL) {stat = NC_ENOTZARR; goto done;}
/* See what the node_type says */
Expand Down
2 changes: 2 additions & 0 deletions libsrc4/nc4internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,10 @@ nc4_var_set_ndims(NC_VAR_INFO_T *var, int ndims)
/* Allocate space for dimension information. */
if (ndims)
{
if(var->dim != NULL) free(var->dim);
if (!(var->dim = calloc(ndims, sizeof(NC_DIM_INFO_T *))))
return NC_ENOMEM;
if(var->dimids != NULL) free(var->dimids);
if (!(var->dimids = calloc(ndims, sizeof(int))))
return NC_ENOMEM;

Expand Down
4 changes: 2 additions & 2 deletions nczarr_test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ BUILT_SOURCES =
EXTRA_DIST =
DISTCLEANFILES =
TESTS =
check_PROGRAMS =

include $(top_srcdir)/nczarr_test/Makefile.files

BUILT_SOURCES += ${ALLBUILTSCRIPTS}


# V2 specific files
EXTRA_DIST = CMakeLists.txt Makefile.core Makefile.files ${ALLV2BASELINE} ${ALLV2SCRIPTS}
EXTRA_DIST += CMakeLists.txt Makefile.core Makefile.files ${ALLV2BASELINE} ${ALLV2SCRIPTS}

include $(top_srcdir)/nczarr_test/Makefile.core

Expand Down
16 changes: 16 additions & 0 deletions nczarr_test/ref_tst_nans.dmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
netcdf ref_tst_nans {
dimensions:
dim = 3 ;
variables:
float fvar(dim) ;
fvar:_FillValue = NaNf ;
fvar:att = -Infinityf, NaNf, Infinityf ;
double dvar(dim) ;
dvar:_FillValue = NaN ;
dvar:att = -Infinity, NaN, Infinity ;
data:

fvar = -Infinityf, _, Infinityf ;

dvar = -Infinity, _, Infinity ;
}
2 changes: 1 addition & 1 deletion nczarr_test/run_nan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e

# Location constants
cdl="$srcdir/../ncdump/cdl"
expected="$srcdir/../ncdump/expected"
expected="$srcdir"

# Functions

Expand Down
Loading

0 comments on commit c85e763

Please sign in to comment.