⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attr.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 3 页
字号:
	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_cktype(type);	if(status != NC_NOERR)		return status;	if(type == NC_CHAR)		return NC_ECHAR;		/* cast needed for braindead systems with signed size_t */	if((unsigned long) nelems > X_INT_MAX) /* backward compat */		return NC_EINVAL; /* Invalid nelems */	if(nelems != 0 && value == NULL)		return NC_EINVAL; /* Null arg */	attrpp = NC_findattr(ncap, name);	if(attrpp != NULL) /* name in use */	{		if(!NC_indef(ncp) )		{			const size_t xsz = ncx_len_NC_attrV(type, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = type;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_Ishort(&xp, nelems,					value, type);			}						set_NC_hdirty(ncp);			if(NC_doHsync(ncp))			{				const int lstatus = NC_sync(ncp);				/*				 * N.B.: potentially overrides NC_ERANGE				 * set by ncx_pad_putn_Ishort				 */				if(lstatus != ENOERR)					return lstatus;			}			return status;		}		/* else, redefine using existing array slot */		old = *attrpp;	} 	else	{		if(!NC_indef(ncp))			return NC_ENOTINDEFINE;		if(ncap->nelems >= NC_MAX_ATTRS)			return NC_EMAXATTS;	}	status = NC_check_name(name);	if(status != NC_NOERR)		return status;	attrp = new_NC_attr(name, type, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_Ishort(&xp, nelems,			value, type);	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		const int lstatus = incr_NC_attrarray(ncap, attrp);		/*		 * N.B.: potentially overrides NC_ERANGE		 * set by ncx_pad_putn_Ishort		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_short(int ncid, int varid, const char *name, short *tp){	int status;	NC_attr *attrp;	status = NC_lookupattr(ncid, varid, name, &attrp);	if(status != NC_NOERR)		return status;	if(attrp->nelems == 0)		return NC_NOERR;	if(attrp->type == NC_CHAR)		return NC_ECHAR;	{	const void *xp = attrp->xvalue;	return ncx_pad_getn_Ishort(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_int(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const int *value){	int status;	NC *ncp;	NC_attrarray *ncap;	NC_attr **attrpp;	NC_attr *old = NULL;	NC_attr *attrp;	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_cktype(type);	if(status != NC_NOERR)		return status;	if(type == NC_CHAR)		return NC_ECHAR;		/* cast needed for braindead systems with signed size_t */	if((unsigned long) nelems > X_INT_MAX) /* backward compat */		return NC_EINVAL; /* Invalid nelems */	if(nelems != 0 && value == NULL)		return NC_EINVAL; /* Null arg */	attrpp = NC_findattr(ncap, name);	if(attrpp != NULL) /* name in use */	{		if(!NC_indef(ncp) )		{			const size_t xsz = ncx_len_NC_attrV(type, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = type;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_Iint(&xp, nelems,					value, type);			}						set_NC_hdirty(ncp);			if(NC_doHsync(ncp))			{				const int lstatus = NC_sync(ncp);				/*				 * N.B.: potentially overrides NC_ERANGE				 * set by ncx_pad_putn_Iint				 */				if(lstatus != ENOERR)					return lstatus;			}			return status;		}		/* else, redefine using existing array slot */		old = *attrpp;	} 	else	{		if(!NC_indef(ncp))			return NC_ENOTINDEFINE;		if(ncap->nelems >= NC_MAX_ATTRS)			return NC_EMAXATTS;	}	status = NC_check_name(name);	if(status != NC_NOERR)		return status;	attrp = new_NC_attr(name, type, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_Iint(&xp, nelems,			value, type);	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		const int lstatus = incr_NC_attrarray(ncap, attrp);		/*		 * N.B.: potentially overrides NC_ERANGE		 * set by ncx_pad_putn_Iint		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_int(int ncid, int varid, const char *name, int *tp){	int status;	NC_attr *attrp;	status = NC_lookupattr(ncid, varid, name, &attrp);	if(status != NC_NOERR)		return status;	if(attrp->nelems == 0)		return NC_NOERR;	if(attrp->type == NC_CHAR)		return NC_ECHAR;	{	const void *xp = attrp->xvalue;	return ncx_pad_getn_Iint(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_long(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const long *value){	int status;	NC *ncp;	NC_attrarray *ncap;	NC_attr **attrpp;	NC_attr *old = NULL;	NC_attr *attrp;	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_cktype(type);	if(status != NC_NOERR)		return status;	if(type == NC_CHAR)		return NC_ECHAR;		/* cast needed for braindead systems with signed size_t */	if((unsigned long) nelems > X_INT_MAX) /* backward compat */		return NC_EINVAL; /* Invalid nelems */	if(nelems != 0 && value == NULL)		return NC_EINVAL; /* Null arg */	attrpp = NC_findattr(ncap, name);	if(attrpp != NULL) /* name in use */	{		if(!NC_indef(ncp) )		{			const size_t xsz = ncx_len_NC_attrV(type, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = type;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_Ilong(&xp, nelems,					value, type);			}						set_NC_hdirty(ncp);			if(NC_doHsync(ncp))			{				const int lstatus = NC_sync(ncp);				/*				 * N.B.: potentially overrides NC_ERANGE				 * set by ncx_pad_putn_Ilong				 */				if(lstatus != ENOERR)					return lstatus;			}			return status;		}		/* else, redefine using existing array slot */		old = *attrpp;	} 	else	{		if(!NC_indef(ncp))			return NC_ENOTINDEFINE;		if(ncap->nelems >= NC_MAX_ATTRS)			return NC_EMAXATTS;	}	status = NC_check_name(name);	if(status != NC_NOERR)		return status;	attrp = new_NC_attr(name, type, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_Ilong(&xp, nelems,			value, type);	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		const int lstatus = incr_NC_attrarray(ncap, attrp);		/*		 * N.B.: potentially overrides NC_ERANGE		 * set by ncx_pad_putn_Ilong		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_long(int ncid, int varid, const char *name, long *tp){	int status;	NC_attr *attrp;	status = NC_lookupattr(ncid, varid, name, &attrp);	if(status != NC_NOERR)		return status;	if(attrp->nelems == 0)		return NC_NOERR;	if(attrp->type == NC_CHAR)		return NC_ECHAR;	{	const void *xp = attrp->xvalue;	return ncx_pad_getn_Ilong(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_float(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const float *value){	int status;	NC *ncp;	NC_attrarray *ncap;	NC_attr **attrpp;	NC_attr *old = NULL;	NC_attr *attrp;	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_cktype(type);	if(status != NC_NOERR)		return status;	if(type == NC_CHAR)		return NC_ECHAR;		/* cast needed for braindead systems with signed size_t */	if((unsigned long) nelems > X_INT_MAX) /* backward compat */		return NC_EINVAL; /* Invalid nelems */	if(nelems != 0 && value == NULL)		return NC_EINVAL; /* Null arg */	attrpp = NC_findattr(ncap, name);	if(attrpp != NULL) /* name in use */	{		if(!NC_indef(ncp) )		{			const size_t xsz = ncx_len_NC_attrV(type, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = type;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_Ifloat(&xp, nelems,					value, type);			}						set_NC_hdirty(ncp);			if(NC_doHsync(ncp))			{				const int lstatus = NC_sync(ncp);				/*				 * N.B.: potentially overrides NC_ERANGE				 * set by ncx_pad_putn_Ifloat				 */				if(lstatus != ENOERR)					return lstatus;			}			return status;		}		/* else, redefine using existing array slot */		old = *attrpp;	} 	else	{		if(!NC_indef(ncp))			return NC_ENOTINDEFINE;		if(ncap->nelems >= NC_MAX_ATTRS)			return NC_EMAXATTS;	}	status = NC_check_name(name);	if(status != NC_NOERR)		return status;	attrp = new_NC_attr(name, type, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_Ifloat(&xp, nelems,			value, type);	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		const int lstatus = incr_NC_attrarray(ncap, attrp);		/*		 * N.B.: potentially overrides NC_ERANGE		 * set by ncx_pad_putn_Ifloat		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_float(int ncid, int varid, const char *name, float *tp){	int status;	NC_attr *attrp;	status = NC_lookupattr(ncid, varid, name, &attrp);	if(status != NC_NOERR)		return status;	if(attrp->nelems == 0)		return NC_NOERR;	if(attrp->type == NC_CHAR)		return NC_ECHAR;	{	const void *xp = attrp->xvalue;	return ncx_pad_getn_Ifloat(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_double(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const double *value){	int status;	NC *ncp;	NC_attrarray *ncap;	NC_attr **attrpp;	NC_attr *old = NULL;	NC_attr *attrp;	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_cktype(type);	if(status != NC_NOERR)		return status;	if(type == NC_CHAR)		return NC_ECHAR;		/* cast needed for braindead systems with signed size_t */	if((unsigned long) nelems > X_INT_MAX) /* backward compat */		return NC_EINVAL; /* Invalid nelems */	if(nelems != 0 && value == NULL)		return NC_EINVAL; /* Null arg */	attrpp = NC_findattr(ncap, name);	if(attrpp != NULL) /* name in use */	{		if(!NC_indef(ncp) )		{			const size_t xsz = ncx_len_NC_attrV(type, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = type;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_Idouble(&xp, nelems,					value, type);			}						set_NC_hdirty(ncp);			if(NC_doHsync(ncp))			{				const int lstatus = NC_sync(ncp);				/*				 * N.B.: potentially overrides NC_ERANGE				 * set by ncx_pad_putn_Idouble				 */				if(lstatus != ENOERR)					return lstatus;			}			return status;		}		/* else, redefine using existing array slot */		old = *attrpp;	} 	else	{		if(!NC_indef(ncp))			return NC_ENOTINDEFINE;		if(ncap->nelems >= NC_MAX_ATTRS)			return NC_EMAXATTS;	}	status = NC_check_name(name);	if(status != NC_NOERR)		return status;	attrp = new_NC_attr(name, type, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_Idouble(&xp, nelems,			value, type);	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		const int lstatus = incr_NC_attrarray(ncap, attrp);		/*		 * N.B.: potentially overrides NC_ERANGE		 * set by ncx_pad_putn_Idouble		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_double(int ncid, int varid, const char *name, double *tp){	int status;	NC_attr *attrp;	status = NC_lookupattr(ncid, varid, name, &attrp);	if(status != NC_NOERR)		return status;	if(attrp->nelems == 0)		return NC_NOERR;	if(attrp->type == NC_CHAR)		return NC_ECHAR;	{	const void *xp = attrp->xvalue;	return ncx_pad_getn_Idouble(&xp, attrp->nelems, tp, attrp->type);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -