Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regularize the scoping of dimensions #2012

Merged
merged 4 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release

## 4.8.1 - TBD

* [Bug Fixes] The netcdf-c library was incorrectly determining the scope of dimension; similar to the type scope problem. See [Github #2012](https://github.com/Unidata/netcdf-c/pull/2012) for more information.
* [Bug Fix] Re-enable DAP2 authorization testing. See [Github #2011](https://github.com/Unidata/netcdf-c/issues/2011).
* [Bug Fix] Fix bug with windows version of mkstemp that causes failure to create more than 26 temp files. See [Github #1998](https://github.com/Unidata/netcdf-c/pull/1998).
* [Bug Fix] Fix ncdump bug when printing VLENs with basetype char. See [Github #1986](https://github.com/Unidata/netcdf-c/issues/1986).
Expand Down
2 changes: 1 addition & 1 deletion include/netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ nc_insert_array_compound(int ncid, nc_type xtype, const char *name,
EXTERNL int
nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size);

/* Get the id of a type from the name. */
/* Get the id of a type from the name, which might be a fully qualified name */
EXTERNL int
nc_inq_typeid(int ncid, const char *name, nc_type *typeidp);

Expand Down
1 change: 1 addition & 0 deletions libdispatch/dcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
id = ids[i];
nclistpush(queue,(void*)id);
}
free(ids); ids = NULL;
}
/* Not found */
ret = NC_EBADTYPE;
Expand Down
62 changes: 47 additions & 15 deletions libsrc4/nc4dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp)

/**
* @internal Given dim name, find its id.
*
* Fully qualified names are legal
* @param ncid File and group ID.
* @param name Name of the dimension to find.
* @param idp Pointer that gets dimension ID.
Expand All @@ -85,28 +85,56 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp)
int
NC4_inq_dimid(int ncid, const char *name, int *idp)
{
NC *nc;
NC_GRP_INFO_T *grp, *g;
NC_FILE_INFO_T *h5;
NC_DIM_INFO_T *dim;
NC *nc = NULL;
NC_GRP_INFO_T *grp = NULL;
NC_GRP_INFO_T *g = NULL;
NC_FILE_INFO_T *h5 = NULL;
NC_DIM_INFO_T *dim = NULL;
char norm_name[NC_MAX_NAME + 1];
int retval;
int found;
int retval = NC_NOERR;;
int found = 0;

LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));

/* Check input. */
if (!name)
return NC_EINVAL;
{retval = NC_EINVAL; goto done;}

/* If the first char is a /, this is a fully-qualified
* name. Otherwise, this had better be a local name (i.e. no / in
* the middle). */
if (name[0] != '/' && strstr(name, "/"))
{retval = NC_EINVAL; goto done;}

/* Find metadata for this file. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
return retval;
goto done;
assert(h5 && nc && grp);

/* Normalize name. */
if ((retval = nc4_normalize_name(name, norm_name)))
return retval;
goto done;;

/* If this is a fqn, then walk the sequence of parent groups to the last group
and see if that group has a dimension of the right name */
if(name[0] == '/') { /* FQN */
int rootncid = (grp->nc4_info->root_grp->hdr.id | grp->nc4_info->controller->ext_ncid);
int parent = 0;
char* lastname = strrchr(norm_name,'/'); /* break off the last segment: the type name */
if(lastname == norm_name)
{retval = NC_EINVAL; goto done;}
*lastname++ = '\0'; /* break off the lastsegment */
if((retval = NC4_inq_grp_full_ncid(rootncid,norm_name,&parent)))
goto done;
/* Get parent info */
if((retval=nc4_find_nc4_grp(parent,&grp)))
goto done;
/* See if dim exists in this group */
dim = (NC_DIM_INFO_T*)ncindexlookup(grp->dim,lastname);
if(dim == NULL)
{retval = NC_EBADTYPE; goto done;}
goto done;
}

/* check for a name match in this group and its parents */
found = 0;
Expand All @@ -115,11 +143,15 @@ NC4_inq_dimid(int ncid, const char *name, int *idp)
if(dim != NULL) {found = 1; break;}
}
if(!found)
return NC_EBADDIM;
assert(dim != NULL);
if (idp)
*idp = dim->hdr.id;
return NC_NOERR;
{retval = NC_EBADDIM; goto done;}

done:
if(retval == NC_NOERR) {
assert(dim != NULL);
if (idp)
*idp = dim->hdr.id;
}
return retval;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions libsrc4/nc4grp.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ NC4_inq_ncid(int ncid, const char *name, int *grp_ncid)
return retval;
assert(h5);

/* Short circuit the case of name == NULL => return the root group */
if(name == NULL) {
if(grp_ncid) {
NC_FILE_INFO_T* file = grp->nc4_info;
*grp_ncid = file->controller->ext_ncid | file->root_grp->hdr.id;
}
return NC_NOERR;
}

/* Normalize name. */
if ((retval = nc4_check_name(name, norm_name)))
return retval;
Expand Down
2 changes: 1 addition & 1 deletion libsrc4/nc4type.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ NC4_inq_enum_member(int ncid, nc_type typeid1, int idx, char *identifier,
* @internal Get the id of a type from the name.
*
* @param ncid File and group ID.
* @param name Name of type.
* @param name Name of type; might be fully qualified.
* @param typeidp Pointer that will get the type ID.
*
* @return ::NC_NOERR No error.
Expand Down
37 changes: 37 additions & 0 deletions nc_test4/test_filter_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ buildbaseline(unsigned int testcasenumber)
insert(12,&val8,sizeof(val8)); /* 12 unsigned long long */
break;
case 2:
case 3:
break;
default:
fprintf(stderr,"Unknown testcase number: %d\n",testcasenumber);
Expand Down Expand Up @@ -418,6 +419,41 @@ test_test2(void)
return ok;
}

static int
test_test3(void)
{
int ok = 1;
int stat = NC_NOERR;

reset();

buildbaseline(3);

fprintf(stderr,"test3: dimsize %% chunksize != 0: compress.\n");
create();
setchunking();
setvarfilter();
showparameters();
CHECK(nc_enddef(ncid));

/* Fill in the array */
fill();
/* write array */
stat = nc_put_var(ncid,varid,expected);

fprintf(stderr,"test3: error code = %d\n",stat);

CHECK(nc_close(ncid));

fprintf(stderr,"test3: dimsize %% chunksize != 0: decompress.\n");
reset();
openfile();
CHECK(nc_get_var_float(ncid, varid, array));
ok = compare();
CHECK(nc_close(ncid));
return ok;
}

/**************************************************/
/* Utilities */

Expand Down Expand Up @@ -510,5 +546,6 @@ main(int argc, char **argv)
init(argc,argv);
if(!test_test1()) ERRR;
if(!test_test2()) ERRR;
if(!test_test3()) ERRR;
exit(nerrs > 0?1:0);
}
2 changes: 1 addition & 1 deletion nc_test4/tst_filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ rm -f ./tst_filter.txt
trimleft ./tst_filter2.txt ./tst_filter.txt
rm -f ./tst_filter2.txt
cat >./tst_filter2.txt <<EOF
var:_Filter = "32768,2,239,23,65511,27,77,93,1145389056,3287505826,1097305129,1,2147483648,4294967295,4294967295" ;
var:_Filter = "32768,3,239,23,65511,27,77,93,1145389056,3287505826,1097305129,1,2147483648,4294967295,4294967295" ;
EOF
diff -b -w ./tst_filter.txt ./tst_filter2.txt
echo "*** Pass: parameter passing"
Expand Down
8 changes: 6 additions & 2 deletions ncdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ IF(USE_X_GETOPT)
SET(nccopy_FILES ${nccopy_FILES} XGetopt.c)
SET(ocprint_FILES ${ocprint_FILES} XGetopt.c)
SET(ncvalidator_FILES ${ncvalidator_FILES} XGetopt.c)
ENDIF()
SET(printfqn_FILES ${printfqn_FILES} XGetopt.c)
ENDIF(USE_X_GETOPT)

ADD_EXECUTABLE(ncdump ${ncdump_FILES})
ADD_EXECUTABLE(nccopy ${nccopy_FILES})
Expand Down Expand Up @@ -327,14 +328,17 @@ IF(ENABLE_TESTS)
add_sh_test(ncdump test_keywords)
ENDIF()

IF(USE_HDF5)
add_sh_test(ncdump test_scope)
ENDIF()
add_sh_test(ncdump test_rcmerge)

IF(USE_HDF5)
add_sh_test(ncdump test_scope)
ENDIF()

add_sh_test(ncdump test_rcmerge)


ENDIF(ENABLE_TESTS)

#IF(MSVC)
Expand Down
18 changes: 9 additions & 9 deletions ncdump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ XFAIL_TESTS += tst_null_byte_padding.sh
endif

if ! ISCYGWIN
TESTS += test_unicode_directory.sh
TESTS += test_unicode_directory.sh test_unicode_path.sh
endif

if LARGE_FILE_TESTS
Expand Down Expand Up @@ -171,12 +171,12 @@ tst_ncgen4_cycle.sh tst_null_byte_padding.sh \
ref_null_byte_padding_test.nc ref_tst_irish_rover.nc \
ref_provenance_v1.nc ref_tst_radix.cdl tst_radix.cdl test_radix.sh \
ref_nccopy_w.cdl tst_nccopy_w3.sh tst_nccopy_w4.sh \
ref_no_ncproperty.nc test_unicode_directory.sh \
ref_no_ncproperty.nc test_unicode_directory.sh test_unicode_path.sh \
ref_roman_szip_simple.cdl ref_roman_szip_unlim.cdl ref_tst_perdimspecs.cdl \
test_keywords.sh ref_keyword1.cdl ref_keyword2.cdl ref_keyword3.cdl ref_keyword4.cdl \
ref_tst_nofilters.cdl test_scope.sh type_group_only.cdl type_ancestor_only.cdl \
type_ancestor_subgroup.cdl type_preorder.cdl test_unicode_path.sh \
test_rcmerge.sh ref_rcmerge1.txt ref_rcmerge2.txt ref_rcmerge3.txt
ref_tst_nofilters.cdl test_scope.sh \
test_rcmerge.sh ref_rcmerge1.txt ref_rcmerge2.txt ref_rcmerge3.txt \
scope_ancestor_only.cdl scope_ancestor_subgroup.cdl scope_group_only.cdl scope_preorder.cdl

# The L512.bin file is file containing exactly 512 bytes each of value 0.
# It is used for creating hdf5 files with varying offsets for testing.
Expand Down Expand Up @@ -213,11 +213,11 @@ ctest64.c nccopy3_subset_out.nc camrun.c tst_ncf213.cdl tst_ncf213.nc \
tst_radix.nc tmp_radix.cdl ctest_small_3.c ctest_small_4.c \
ctest_special_atts_4.c tst_roman_szip_simple.cdl \
tst_roman_szip_unlim.cdl tst_perdimpspecs.nc tmppds.* \
keyword1.nc keyword2.nc keyword3.nc keyword4.nc \
tmp_keyword1.cdl tmp_keyword2.cdl tmp_keyword3.cdl tmp_keyword4.cdl \
type_*.nc copy_type_*.cdl
keyword1.nc keyword2.nc keyword3.nc keyword4.nc \
tmp_keyword1.cdl tmp_keyword2.cdl tmp_keyword3.cdl tmp_keyword4.cdl \
type_*.nc copy_type_*.cdl \
scope_*.nc copy_scope_*.cdl

# Remove directories
clean-local:
rm -fr rcmergedir

Loading