2018-01-05 21:01:22 +08:00
|
|
|
/* Copyright 2003-2018, University Corporation for Atmospheric
|
|
|
|
* Research. See the COPYRIGHT file for copying and redistribution
|
|
|
|
* conditions. */
|
2017-12-04 22:07:45 +08:00
|
|
|
/**
|
2018-01-31 00:35:56 +08:00
|
|
|
* @file
|
2017-12-04 22:07:45 +08:00
|
|
|
* @internal This file is part of netcdf-4, a netCDF-like interface
|
|
|
|
* for HDF5, or a HDF5 backend for netCDF, depending on your point of
|
|
|
|
* view.
|
|
|
|
*
|
|
|
|
* This file handles the nc4 dimension functions.
|
|
|
|
*
|
|
|
|
* @author Ed Hartnett
|
2018-01-31 00:35:56 +08:00
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#include "nc4internal.h"
|
2012-12-13 04:05:06 +08:00
|
|
|
#include "nc4dispatch.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2017-12-04 22:07:45 +08:00
|
|
|
/**
|
|
|
|
* @internal Netcdf-4 files might have more than one unlimited
|
|
|
|
* dimension, but return the first one anyway.
|
2018-01-31 00:35:56 +08:00
|
|
|
*
|
|
|
|
* @note that this code is inconsistent with nc_inq
|
2017-12-04 22:07:45 +08:00
|
|
|
*
|
|
|
|
* @param ncid File and group ID.
|
2017-12-05 03:21:14 +08:00
|
|
|
* @param unlimdimidp Pointer that gets ID of first unlimited
|
2017-12-04 22:07:45 +08:00
|
|
|
* dimension, or -1.
|
|
|
|
*
|
|
|
|
* @return ::NC_NOERR No error.
|
|
|
|
* @return ::NC_EBADID Bad ncid.
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2018-01-31 00:35:56 +08:00
|
|
|
int
|
2010-06-03 21:24:43 +08:00
|
|
|
NC4_inq_unlimdim(int ncid, int *unlimdimidp)
|
|
|
|
{
|
2019-02-19 20:55:22 +08:00
|
|
|
NC_GRP_INFO_T *grp, *g;
|
|
|
|
NC_FILE_INFO_T *h5;
|
|
|
|
NC_DIM_INFO_T *dim;
|
|
|
|
int found = 0;
|
|
|
|
int retval;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
LOG((2, "%s: called", __func__));
|
|
|
|
|
|
|
|
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
assert(h5 && grp);
|
|
|
|
|
|
|
|
if (unlimdimidp)
|
|
|
|
{
|
|
|
|
/* According to netcdf-3 manual, return -1 if there is no unlimited
|
|
|
|
dimension. */
|
|
|
|
*unlimdimidp = -1;
|
|
|
|
for (g = grp; g && !found; g = g->parent)
|
|
|
|
{
|
|
|
|
for(i=0;i<ncindexsize(grp->dim);i++)
|
2018-01-31 00:35:56 +08:00
|
|
|
{
|
2019-02-19 20:55:22 +08:00
|
|
|
dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
|
|
|
|
if(dim == NULL) continue;
|
|
|
|
if (dim->unlimited)
|
|
|
|
{
|
|
|
|
*unlimdimidp = dim->hdr.id;
|
|
|
|
found++;
|
|
|
|
break;
|
|
|
|
}
|
2018-01-31 00:35:56 +08:00
|
|
|
}
|
2019-02-19 20:55:22 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2019-02-19 20:55:22 +08:00
|
|
|
return NC_NOERR;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2017-12-04 22:07:45 +08:00
|
|
|
/**
|
|
|
|
* @internal Given dim name, find its id.
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
* Fully qualified names are legal
|
2017-12-04 22:07:45 +08:00
|
|
|
* @param ncid File and group ID.
|
|
|
|
* @param name Name of the dimension to find.
|
|
|
|
* @param idp Pointer that gets dimension ID.
|
|
|
|
*
|
|
|
|
* @return ::NC_NOERR No error.
|
|
|
|
* @return ::NC_EBADID Bad ncid.
|
|
|
|
* @return ::NC_EBADDIM Dimension not found.
|
2018-01-31 00:35:56 +08:00
|
|
|
* @return ::NC_EINVAL Invalid input. Name must be provided.
|
2017-12-04 22:07:45 +08:00
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
|
|
|
NC4_inq_dimid(int ncid, const char *name, int *idp)
|
|
|
|
{
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
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;
|
2019-02-19 20:55:22 +08:00
|
|
|
char norm_name[NC_MAX_NAME + 1];
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
int retval = NC_NOERR;;
|
|
|
|
int found = 0;
|
2019-02-19 20:55:22 +08:00
|
|
|
|
|
|
|
LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
|
|
|
|
|
|
|
|
/* Check input. */
|
|
|
|
if (!name)
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
{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;}
|
2019-02-19 20:55:22 +08:00
|
|
|
|
|
|
|
/* Find metadata for this file. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
goto done;
|
2019-02-19 20:55:22 +08:00
|
|
|
assert(h5 && nc && grp);
|
|
|
|
|
|
|
|
/* Normalize name. */
|
|
|
|
if ((retval = nc4_normalize_name(name, norm_name)))
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
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;
|
|
|
|
}
|
2019-02-19 20:55:22 +08:00
|
|
|
|
|
|
|
/* check for a name match in this group and its parents */
|
|
|
|
found = 0;
|
|
|
|
for (g = grp; g ; g = g->parent) {
|
|
|
|
dim = (NC_DIM_INFO_T*)ncindexlookup(g->dim,norm_name);
|
|
|
|
if(dim != NULL) {found = 1; break;}
|
|
|
|
}
|
|
|
|
if(!found)
|
Regularize the scoping of dimensions
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.
2021-06-01 05:51:12 +08:00
|
|
|
{retval = NC_EBADDIM; goto done;}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if(retval == NC_NOERR) {
|
|
|
|
assert(dim != NULL);
|
|
|
|
if (idp)
|
|
|
|
*idp = dim->hdr.id;
|
|
|
|
}
|
|
|
|
return retval;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2017-12-04 22:07:45 +08:00
|
|
|
/**
|
|
|
|
* @internal Returns an array of unlimited dimension ids.The user can
|
|
|
|
* get the number of unlimited dimensions by first calling this with
|
|
|
|
* NULL for the second pointer.
|
|
|
|
*
|
|
|
|
* @param ncid File and group ID.
|
|
|
|
* @param nunlimdimsp Pointer that gets the number of unlimited
|
|
|
|
* dimensions. Ignored if NULL.
|
|
|
|
* @param unlimdimidsp Pointer that gets arrray of unlimited dimension
|
|
|
|
* ID. Ignored if NULL.
|
|
|
|
*
|
|
|
|
* @return ::NC_NOERR No error.
|
|
|
|
* @return ::NC_EBADID Bad ncid.
|
|
|
|
* @author Ed Hartnett, Dennis Heimbigner
|
|
|
|
*/
|
2018-01-31 00:35:56 +08:00
|
|
|
int
|
|
|
|
NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2019-02-19 20:55:22 +08:00
|
|
|
NC_DIM_INFO_T *dim;
|
|
|
|
NC_GRP_INFO_T *grp;
|
|
|
|
NC *nc;
|
|
|
|
NC_FILE_INFO_T *h5;
|
|
|
|
int num_unlim = 0;
|
|
|
|
int retval;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
LOG((2, "%s: ncid 0x%x", __func__, ncid));
|
|
|
|
|
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
assert(h5 && nc && grp);
|
|
|
|
|
|
|
|
/* Get our dim info. */
|
|
|
|
assert(h5);
|
|
|
|
{
|
|
|
|
for(i=0;i<ncindexsize(grp->dim);i++)
|
|
|
|
{
|
|
|
|
dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
|
|
|
|
if(dim == NULL) continue;
|
|
|
|
if (dim->unlimited)
|
|
|
|
{
|
|
|
|
if (unlimdimidsp)
|
|
|
|
unlimdimidsp[num_unlim] = dim->hdr.id;
|
|
|
|
num_unlim++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give the number if the user wants it. */
|
|
|
|
if (nunlimdimsp)
|
|
|
|
*nunlimdimsp = num_unlim;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|