mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
move varid check right after ncid
This commit is contained in:
parent
c4a148e136
commit
4725c1484b
@ -42,7 +42,6 @@ nc4_get_att(int ncid, NC *nc, int varid, const char *name,
|
||||
char norm_name[NC_MAX_NAME + 1];
|
||||
int i;
|
||||
int retval = NC_NOERR;
|
||||
const char** sp;
|
||||
|
||||
if (attnum) {
|
||||
my_attnum = *attnum;
|
||||
@ -56,6 +55,19 @@ nc4_get_att(int ncid, NC *nc, int varid, const char *name,
|
||||
if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
||||
BAIL(NC_EBADGRPID);
|
||||
|
||||
/* Check varid */
|
||||
if (varid != NC_GLOBAL) {
|
||||
NC_VAR_INFO_T *var = NULL;
|
||||
for (var = grp->var; var; var = var->l.next)
|
||||
if (var->varid == varid)
|
||||
break;
|
||||
if (!var)
|
||||
BAIL(NC_ENOTVAR);
|
||||
}
|
||||
|
||||
if (name == NULL)
|
||||
BAIL(NC_EBADNAME);
|
||||
|
||||
/* Normalize name. */
|
||||
if ((retval = nc4_normalize_name(name, norm_name)))
|
||||
BAIL(retval);
|
||||
@ -222,18 +234,8 @@ nc4_put_att(int ncid, NC *nc, int varid, const char *name,
|
||||
int i;
|
||||
int res;
|
||||
|
||||
if (!name)
|
||||
return NC_EBADNAME;
|
||||
assert(nc && NC4_DATA(nc));
|
||||
|
||||
LOG((1, "nc4_put_att: ncid 0x%x varid %d name %s "
|
||||
"file_type %d mem_type %d len %d", ncid, varid,
|
||||
name, file_type, mem_type, len));
|
||||
|
||||
/* If len is not zero, then there must be some data. */
|
||||
if (len && !data)
|
||||
return NC_EINVAL;
|
||||
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
h5 = NC4_DATA(nc);
|
||||
if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
||||
@ -243,19 +245,6 @@ nc4_put_att(int ncid, NC *nc, int varid, const char *name,
|
||||
if (h5->no_write)
|
||||
return NC_EPERM;
|
||||
|
||||
/* Check and normalize the name. */
|
||||
if ((retval = nc4_check_name(name, norm_name)))
|
||||
return retval;
|
||||
|
||||
if(nc->ext_ncid == ncid && varid == NC_GLOBAL) {
|
||||
const char** sp;
|
||||
for(sp = NC_RESERVED_SPECIAL_LIST;*sp;sp++) {
|
||||
if(strcmp(name,*sp)==0) {
|
||||
return NC_ENOTATT; /* Not settable */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Find att, if it exists. */
|
||||
if (varid == NC_GLOBAL)
|
||||
attlist = &grp->att;
|
||||
@ -271,10 +260,34 @@ nc4_put_att(int ncid, NC *nc, int varid, const char *name,
|
||||
return NC_ENOTVAR;
|
||||
}
|
||||
|
||||
if (!name)
|
||||
return NC_EBADNAME;
|
||||
|
||||
/* Check and normalize the name. */
|
||||
if ((retval = nc4_check_name(name, norm_name)))
|
||||
return retval;
|
||||
|
||||
if(nc->ext_ncid == ncid && varid == NC_GLOBAL) {
|
||||
const char** sp;
|
||||
for(sp = NC_RESERVED_SPECIAL_LIST;*sp;sp++) {
|
||||
if(strcmp(name,*sp)==0) {
|
||||
return NC_ENOTATT; /* Not settable */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (att = *attlist; att; att = att->l.next)
|
||||
if (!strcmp(att->name, norm_name))
|
||||
break;
|
||||
|
||||
/* If len is not zero, then there must be some data. */
|
||||
if (len && !data)
|
||||
return NC_EINVAL;
|
||||
|
||||
LOG((1, "nc4_put_att: ncid 0x%x varid %d name %s "
|
||||
"file_type %d mem_type %d len %d", ncid, varid,
|
||||
name, file_type, mem_type, len));
|
||||
|
||||
if (!att)
|
||||
{
|
||||
/* If this is a new att, require define mode. */
|
||||
@ -364,7 +377,6 @@ nc4_put_att(int ncid, NC *nc, int varid, const char *name,
|
||||
* attribute). */
|
||||
if (!strcmp(att->name, _FillValue) && varid != NC_GLOBAL)
|
||||
{
|
||||
NC_ATT_INFO_T *varatt;
|
||||
int size;
|
||||
|
||||
/* Fill value must be same type and have exactly one value */
|
||||
@ -831,12 +843,6 @@ nc4_put_att_tc(int ncid, int varid, const char *name, nc_type file_type,
|
||||
NC *nc;
|
||||
NC_HDF5_FILE_INFO_T *h5;
|
||||
|
||||
if (!name || strlen(name) > NC_MAX_NAME)
|
||||
return NC_EBADNAME;
|
||||
|
||||
LOG((3, "nc4_put_att_tc: ncid 0x%x varid %d name %s file_type %d "
|
||||
"mem_type %d len %d", ncid, varid, name, file_type, mem_type, len));
|
||||
|
||||
/* The length needs to be positive (cast needed for braindead
|
||||
systems with signed size_t). */
|
||||
if((unsigned long) len > X_INT_MAX)
|
||||
@ -850,6 +856,26 @@ nc4_put_att_tc(int ncid, int varid, const char *name, nc_type file_type,
|
||||
h5 = NC4_DATA(nc);
|
||||
assert(h5);
|
||||
|
||||
/* Check varid */
|
||||
if (varid != NC_GLOBAL) {
|
||||
NC_GRP_INFO_T *grp;
|
||||
NC_VAR_INFO_T *var = NULL;
|
||||
/* Find info for this file and group, and set pointer to each. */
|
||||
if (!(grp = nc4_rec_find_grp(h5->root_grp, (ncid & GRP_ID_MASK))))
|
||||
return NC_EBADGRPID;
|
||||
for (var = grp->var; var; var = var->l.next)
|
||||
if (var->varid == varid)
|
||||
break;
|
||||
if (!var)
|
||||
return NC_ENOTVAR;
|
||||
}
|
||||
|
||||
if (!name || strlen(name) > NC_MAX_NAME)
|
||||
return NC_EBADNAME;
|
||||
|
||||
LOG((3, "nc4_put_att_tc: ncid 0x%x varid %d name %s file_type %d "
|
||||
"mem_type %d len %d", ncid, varid, name, file_type, mem_type, len));
|
||||
|
||||
if(nc->ext_ncid == ncid && varid == NC_GLOBAL) {
|
||||
const char** reserved = NC_RESERVED_ATT_LIST;
|
||||
for(;*reserved;reserved++) {
|
||||
|
Loading…
Reference in New Issue
Block a user