Beispiel #1
0
int
DISPNAME(inq_varid)(int ncid, const char *name, int *varid_ptr)
{
	int status;
	NC *ncp;
	NC_var *varp;
	int varid;

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

	varid = NC_findvar(&ncp->vars, name, &varp);
	if(varid == -1)
	{
		return NC_ENOTVAR;
	}

	*varid_ptr = varid;
	return NC_NOERR;
}
Beispiel #2
0
int
NC3_inq_varid(int ncid, const char *name, int *varid_ptr)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_var *varp;
	int varid;

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

	varid = NC_findvar(&ncp->vars, name, &varp);
	if(varid == -1)
	{
		return NC_ENOTVAR;
	}

	*varid_ptr = varid;
	return NC_NOERR;
}
Beispiel #3
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;
	}
	
	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;
}
Beispiel #4
0
int
NC3_def_var( int ncid, const char *name, nc_type type,
	 int ndims, const int *dimids, int *varidp)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	int varid;
	NC_var *varp;

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

	if(!NC_indef(ncp))
	{
		return NC_ENOTINDEFINE;
	}

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

	status = nc_cktype(type);
	if(status != NC_NOERR)
		return status;

		/* cast needed for braindead systems with signed size_t */
	if((unsigned long) ndims > X_INT_MAX) /* Backward compat */
	{
		return NC_EINVAL;
	} 

	if(ncp->vars.nelems >= NC_MAX_VARS)
	{
		return NC_EMAXVARS;
	}

	varid = NC_findvar(&ncp->vars, name, &varp);
	if(varid != -1)
	{
		return NC_ENAMEINUSE;
	}
	
	varp = new_NC_var(name, type, ndims, dimids);
	if(varp == NULL)
		return NC_ENOMEM;

	status = NC_var_shape(varp, &ncp->dims);
	if(status != NC_NOERR)
	{
		free_NC_var(varp);
		return status;
	}

	status = incr_NC_vararray(&ncp->vars, varp);
	if(status != NC_NOERR)
	{
		free_NC_var(varp);
		return status;
	}

	if(varidp != NULL)
		*varidp = (int)ncp->vars.nelems -1; /* varid */
	return NC_NOERR;
}
Beispiel #5
0
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;
}
Beispiel #6
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;
}