示例#1
0
文件: dim.c 项目: BJangeofan/netcdf-c
int
NC3_rename_dim( int ncid, int dimid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	int existid;
	NC_dim *dimp;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc); 
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
		return NC_EPERM;

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	existid = NC_finddim(&ncp->dims, unewname, &dimp);
	if(existid != -1)
		return NC_ENAMEINUSE;

	dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid);
	if(dimp == NULL)
		return NC_EBADDIM;

	NC_string *old = dimp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		NC_string *newStr = new_NC_string(strlen(newname), newname);
		free(newname);
		if(newStr == NULL)
			return NC_ENOMEM;
		dimp->name = newStr;

		/* Remove old name from hashmap; add new... */
		NC_hashmapRemoveDim(&ncp->dims, old->cp);
		NC_hashmapAddDim(&ncp->dims, dimid, newStr->cp);
		free_NC_string(old);

		return NC_NOERR;
	}

	/* else, not in define mode */

	status = set_NC_string(dimp->name, newname);
	free(newname);
	if(status != NC_NOERR)
		return status;

	/* Remove old name from hashmap; add new... */
	NC_hashmapRemoveDim(&ncp->dims, old->cp);
	NC_hashmapAddDim(&ncp->dims, dimid, dimp->name->cp);

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
int
nc_rename_att( int ncid, int varid, const char *name, const char *newname)
{
  int status;
  NC *ncp;
  NC_attrarray *ncap;
  NC_attr **tmp;
  NC_attr *attrp;
  NC_string *newStr, *old;

      /* sortof inline clone of NC_lookupattr() */
  status = NC_check_id(ncid, &ncp);
  if(status != NC_NOERR)
    return status;

  if(NC_readonly(ncp))
    return NC_EPERM;

  ncap = NC_attrarray0(ncp, varid);
  if(ncap == NULL)
    return NC_ENOTVAR;

  status = NC_check_name(newname);
  if(status != NC_NOERR)
    return status;

  tmp = NC_findattr(ncap, name);
  if(tmp == NULL)
    return NC_ENOTATT;
  attrp = *tmp;
      /* end inline clone NC_lookupattr() */

  if(NC_findattr(ncap, newname) != NULL)
  {
    /* name in use */
    return NC_ENAMEINUSE;
  }

  old = attrp->name;
  if(NC_indef(ncp))
  {
    newStr = new_NC_string(strlen(newname), newname);
    if( newStr == NULL)
      return NC_ENOMEM;
    attrp->name = newStr;
    free_NC_string(old);
    return NC_NOERR;
  }
  /* else */
  status = set_NC_string(old, newname);
  if( status != NC_NOERR)
    return status;

  set_NC_hdirty(ncp);

  if(NC_doHsync(ncp))
  {
    status = NC_sync(ncp);
    if(status != NC_NOERR)
      return status;
  }

  return NC_NOERR;
}
示例#3
0
文件: var.c 项目: SiggyF/netcdf-c
int
NC3_rename_var(int ncid, int varid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_var *varp;
	NC_string *old, *newStr;
	int other;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc); 
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
	{
		return NC_EPERM;
	}

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	/* check for name in use */
	other = NC_findvar(&ncp->vars, unewname, &varp);
	if(other != -1)
	{
		return NC_ENAMEINUSE;
	}
	
	varp = NC_lookupvar(ncp, varid);
	if(varp == NULL)
	{
		/* invalid varid */
		return NC_ENOTVAR; /* TODO: is this the right error code? */
	}

	old = varp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname),newname);
		free(newname);
		if(newStr == NULL)
			return(-1);
		varp->name = newStr;
		varp->hash = hash_fast(newStr->cp, strlen(newStr->cp));
		free_NC_string(old);
		return NC_NOERR;
	}

	/* else, not in define mode */
	status = set_NC_string(varp->name, newname);
	varp->hash = hash_fast(newname, strlen(newname));
	free(newname);
	if(status != NC_NOERR)
		return status;

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
示例#4
0
文件: dim.c 项目: dschwen/libmesh
int
NC3_rename_dim( int ncid, int dimid, const char *unewname)
{
	int status = NC_NOERR;
	NC *nc;
	NC3_INFO* ncp;
	int existid;
	NC_dim *dimp;
	char *newname = NULL; /* normalized */
	NC_string *old = NULL;
 	uintptr_t intdata;


	status = NC_check_id(ncid, &nc);
	if(status != NC_NOERR)
		goto done;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
		{status = NC_EPERM; goto done;}

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		goto done;

	existid = NC_finddim(&ncp->dims, unewname, &dimp);
	if(existid != -1)
		{status = NC_ENAMEINUSE; goto done;}

	dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid);
	if(dimp == NULL)
		{status = NC_EBADDIM; goto done;}

    old = dimp->name;
    status = nc_utf8_normalize((const unsigned char *)unewname,(unsigned char **)&newname);
    if(status != NC_NOERR)
	goto done;
    if(NC_indef(ncp))
	{
		NC_string *newStr = new_NC_string(strlen(newname), newname);
		if(newStr == NULL)
			{status = NC_ENOMEM; goto done;}

		/* Remove old name from hashmap; add new... */
	        NC_hashmapremove(ncp->dims.hashmap, old->cp, strlen(old->cp), NULL);
		dimp->name = newStr;

		intdata = dimid;
		NC_hashmapadd(ncp->dims.hashmap, intdata, newStr->cp, strlen(newStr->cp));
		free_NC_string(old);
		goto done;
	}

	/* else, not in define mode */

	/* If new name is longer than old, then complain,
           but otherwise, no change (test is same as set_NC_string)*/
	if(dimp->name->nchars < strlen(newname)) {
	    {status = NC_ENOTINDEFINE; goto done;}
	}

	/* Remove old name from hashmap; add new... */
	/* WARNING: strlen(NC_string.cp) may be less than NC_string.nchars */
	NC_hashmapremove(ncp->dims.hashmap, old->cp, strlen(old->cp), NULL);

	/* WARNING: strlen(NC_string.cp) may be less than NC_string.nchars */
	status = set_NC_string(dimp->name, newname);
	if(status != NC_NOERR)
		goto done;

        intdata = (uintptr_t)dimid;
	NC_hashmapadd(ncp->dims.hashmap, intdata, dimp->name->cp, strlen(dimp->name->cp));

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			goto done;
	}

done:
	if(newname) free(newname);
	return status;
}
示例#5
0
文件: var.c 项目: hs9906/paraview
int
nc_rename_var(int ncid, int varid, const char *newname)
{
  int status;
  NC *ncp;
  NC_var *varp;
  NC_string *old, *newStr;
  int other;

  status = NC_check_id(ncid, &ncp); 
  if(status != NC_NOERR)
    return status;

  if(NC_readonly(ncp))
  {
    return NC_EPERM;
  }

  status = NC_check_name(newname);
  if(status != NC_NOERR)
    return status;

  /* check for name in use */
  other = NC_findvar(&ncp->vars, newname, &varp);
  if(other != -1)
  {
    return NC_ENAMEINUSE;
  }
  
  varp = NC_lookupvar(ncp, varid);
  if(varp == NULL)
  {
    /* invalid varid */
    return NC_ENOTVAR; /* TODO: is this the right error code? */
  }

  old = varp->name;
  if(NC_indef(ncp))
  {
    newStr = new_NC_string(strlen(newname),newname);
    if(newStr == NULL)
      return(-1);
    varp->name = newStr;
    free_NC_string(old);
    return NC_NOERR;
  }

  /* else, not in define mode */
  status = set_NC_string(varp->name, newname);
  if(status != NC_NOERR)
    return status;

  set_NC_hdirty(ncp);

  if(NC_doHsync(ncp))
  {
    status = NC_sync(ncp);
    if(status != NC_NOERR)
      return status;
  }

  return NC_NOERR;
}
示例#6
0
文件: attr.c 项目: balborian/libmesh
int
NC3_rename_att( int ncid, int varid, const char *name, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_attrarray *ncap;
	NC_attr **tmp;
	NC_attr *attrp;
	NC_string *newStr, *old;
	char *newname;  /* normalized version */

			/* sortof inline clone of NC_lookupattr() */
	status = NC_check_id(ncid, &nc);
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
		return NC_EPERM;

	ncap = NC_attrarray0(ncp, varid);
	if(ncap == NULL)
		return NC_ENOTVAR;

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	tmp = NC_findattr(ncap, name);
	if(tmp == NULL)
		return NC_ENOTATT;
	attrp = *tmp;
			/* end inline clone NC_lookupattr() */

	if(NC_findattr(ncap, unewname) != NULL)
	{
		/* name in use */
		return NC_ENAMEINUSE;
	}

	old = attrp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_EBADNAME;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname), newname);
		free(newname);
		if( newStr == NULL)
			return NC_ENOMEM;
		attrp->name = newStr;
		free_NC_string(old);
		return NC_NOERR;
	}
	/* else */
	status = set_NC_string(old, newname);
	free(newname);
	if( status != NC_NOERR)
		return status;

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
示例#7
0
int
NC3_rename_var(int ncid, int varid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_var *varp;
	NC_string *old, *newStr;
	int other;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc);
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
	{
		return NC_EPERM;
	}

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	/* check for name in use */
	other = NC_findvar(&ncp->vars, unewname, &varp);
	if(other != -1)
	{
		return NC_ENAMEINUSE;
	}

	status = NC_lookupvar(ncp, varid, &varp);
	if(status != NC_NOERR)
	{
		/* invalid varid */
		return status;
	}


	old = varp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname),newname);
		free(newname);
		if(newStr == NULL)
			return(-1);
		varp->name = newStr;

		/* Remove old name from hashmap; add new... */
		NC_hashmapRemoveVar(&ncp->vars, old->cp);
		NC_hashmapAddVar(&ncp->vars, varid, newStr->cp);
		free_NC_string(old);

		return NC_NOERR;
	}

	/* else, not in define mode */
	status = set_NC_string(varp->name, newname);
	free(newname);
	if(status != NC_NOERR)
		return status;

	/* Remove old name from hashmap; add new... */
	NC_hashmapRemoveVar(&ncp->vars, old->cp);
	NC_hashmapAddVar(&ncp->vars, varid, varp->name->cp);

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
示例#8
0
文件: attr.c 项目: Kitware/VTK
int
NC3_rename_att( int ncid, int varid, const char *name, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_attrarray *ncap;
	NC_attr **tmp;
	NC_attr *attrp;
	NC_string *newStr, *old;
	char *newname;  /* normalized version */

			/* sortof inline clone of NC_lookupattr() */
	status = NC_check_id(ncid, &nc);
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
		return NC_EPERM;

	ncap = NC_attrarray0(ncp, varid);
	if(ncap == NULL)
		return NC_ENOTVAR;

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	tmp = NC_findattr(ncap, name);
	if(tmp == NULL)
		return NC_ENOTATT;
	attrp = *tmp;
			/* end inline clone NC_lookupattr() */

	if(NC_findattr(ncap, unewname) != NULL)
	{
		/* name in use */
		return NC_ENAMEINUSE;
	}

	old = attrp->name;
	status = nc_utf8_normalize((const unsigned char *)unewname,(unsigned char**)&newname);
	if(status != NC_NOERR)
	    return status;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname), newname);
		free(newname);
		if( newStr == NULL)
			return NC_ENOMEM;
		attrp->name = newStr;
		free_NC_string(old);
		return NC_NOERR;
	}
	/* else not in define mode */

	/* If new name is longer than old, then complain,
           but otherwise, no change (test is same as set_NC_string)*/
	if(old->nchars < strlen(newname)) {
	    free(newname);
	    return NC_ENOTINDEFINE;
	}

	status = set_NC_string(old, newname);
	free(newname);
	if( status != NC_NOERR)
		return status;

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}