mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
ec5b3f9a4f
This is a follow-on to pull request ````https://github.com/Unidata/netcdf-c/pull/1959````, which fixed up type scoping. The primary changes are to _nc\_inq\_dimid()_ and to ncdump. The _nc\_inq\_dimid()_ function is supposed to allow the name to be and FQN, but this apparently never got implemented. So if was modified to support FQNs. The ncdump program is supposed to output fully qualified dimension names in its generated CDL file under certain conditions. Suppose ncdump has a netcdf-4 file F with variable V, and V's parent group is G. For each dimension id D referenced by V, ncdump needs to determine whether to print its name as a simple name or as a fully qualified name (FQN). The algorithm is as follows: 1. Search up the tree of ancestor groups. 2. If one of those ancestor groups contains the dimid, then call it dimgrp. 3. If one of those ancestor groups contains a dim with the same name as the dimid, but with a different dimid, then record that as duplicate=true. 4. If dimgrp is defined and duplicate == false, then we do not need an fqn. 5. If dimgrp is defined and duplicate == true, then we do need an fqn to avoid incorrectly using the duplicate. 6. If dimgrp is undefined, then do a preorder breadth-first search of all the groups looking for the dimid. 7. If found, then use the fqn of the first found such dimension location. 8. If not found, then fail. Test case ncdump/test_scope.sh was modified to test the proper operation of ncdump and _nc\_inq\_dimid()_. Misc. Other Changes: * Fix nc_inq_ncid (NC4_inq_ncid actually) to return root group id if the name argument is NULL. * Modify _ncdump/printfqn_ to print out a dimid FQN; this supports verification that the resulting .nc files were properly created.
56 lines
1.5 KiB
Bash
Executable File
56 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
|
. ../test_common.sh
|
|
|
|
set -e
|
|
|
|
# Test scoping rules for types and dimensions
|
|
|
|
# Type test cases
|
|
# group_only - type defined in same group as var/attr
|
|
# ancestor_only - type defined in some ancestor group of var/attr
|
|
# ancestor_subgroup - type defined in both ancestor group and subgroup
|
|
# preorder - type defined in some preceding, non ancestor group
|
|
|
|
# Dimension test cases
|
|
# group_only - dim defined in same group as var
|
|
# ancestor_only - dim defined in some ancestor group of var
|
|
# ancestor_subgroup - dim defined in both ancestor group and subgroup
|
|
|
|
TSTS="scope_group_only scope_ancestor_only scope_ancestor_subgroup scope_preorder"
|
|
|
|
setup() {
|
|
${NCGEN} -4 -lb ${srcdir}/$1.cdl
|
|
}
|
|
|
|
testcycle() {
|
|
${NCCOPY} ${execdir}/$1.nc ${execdir}/$1_copy.nc
|
|
${NCDUMP} -h -n $1 ${execdir}/$1_copy.nc > copy_$1.cdl
|
|
diff -wB ${srcdir}/$1.cdl ${execdir}/copy_$1.cdl
|
|
}
|
|
|
|
typescope() {
|
|
REFT=`${execdir}/printfqn -f ${execdir}/$1.nc -v test_variable -t`
|
|
COPYT=`${execdir}/printfqn -f ${execdir}/$1_copy.nc -v test_variable -t`
|
|
if test "x$REFT" != "x$COPYT" ; then
|
|
echo "***Fail: ref=${REFT} copy=${COPYT}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
dimscope() {
|
|
REFT=`${execdir}/printfqn -f ${execdir}/$1.nc -v test_variable -d`
|
|
COPYT=`${execdir}/printfqn -f ${execdir}/$1_copy.nc -v test_variable -d`
|
|
if test "x$REFT" != "x$COPYT" ; then
|
|
echo "***Fail: ref=${REFT} copy=${COPYT}"
|
|
fi
|
|
}
|
|
|
|
for t in $TSTS ; do setup $t; done
|
|
for t in $TSTS ; do testcycle $t; done
|
|
for t in $TSTS ; do typescope $t; done
|
|
for t in $TSTS ; do dimscope $t; done
|
|
|
|
exit 0
|