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

📄 attr.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 3 页
字号:
static intncx_pad_getn_Iuchar(const void **xpp, size_t nelems, uchar *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_uchar(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_uchar(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_uchar(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_uchar(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_uchar(xpp, nelems, tp);	}	assert("ncx_pad_getn_Iuchar invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Ischar(void **xpp, size_t nelems, const schar *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_schar(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_schar(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_schar(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_schar(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_schar(xpp, nelems, tp);	}	assert("ncx_pad_putn_Ischar invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Ischar(const void **xpp, size_t nelems, schar *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_schar(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_schar(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_schar(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_schar(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_schar(xpp, nelems, tp);	}	assert("ncx_pad_getn_Ischar invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Ishort(void **xpp, size_t nelems, const short *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_short(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_short(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_short(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_short(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_short(xpp, nelems, tp);	}	assert("ncx_pad_putn_Ishort invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Ishort(const void **xpp, size_t nelems, short *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_short(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_short(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_short(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_short(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_short(xpp, nelems, tp);	}	assert("ncx_pad_getn_Ishort invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Iint(void **xpp, size_t nelems, const int *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_int(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_int(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_int(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_int(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_int(xpp, nelems, tp);	}	assert("ncx_pad_putn_Iint invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Iint(const void **xpp, size_t nelems, int *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_int(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_int(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_int(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_int(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_int(xpp, nelems, tp);	}	assert("ncx_pad_getn_Iint invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Ilong(void **xpp, size_t nelems, const long *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_long(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_long(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_long(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_long(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_long(xpp, nelems, tp);	}	assert("ncx_pad_putn_Ilong invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Ilong(const void **xpp, size_t nelems, long *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_long(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_long(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_long(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_long(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_long(xpp, nelems, tp);	}	assert("ncx_pad_getn_Ilong invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Ifloat(void **xpp, size_t nelems, const float *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_float(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_float(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_float(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_float(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_float(xpp, nelems, tp);	}	assert("ncx_pad_putn_Ifloat invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Ifloat(const void **xpp, size_t nelems, float *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_float(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_float(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_float(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_float(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_float(xpp, nelems, tp);	}	assert("ncx_pad_getn_Ifloat invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_putn_Idouble(void **xpp, size_t nelems, const double *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_putn_schar_double(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_putn_short_double(xpp, nelems, tp);	case NC_INT:		return ncx_putn_int_double(xpp, nelems, tp);	case NC_FLOAT:		return ncx_putn_float_double(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_putn_double_double(xpp, nelems, tp);	}	assert("ncx_pad_putn_Idouble invalid type" == 0);	return NC_EBADTYPE;}static intncx_pad_getn_Idouble(const void **xpp, size_t nelems, double *tp, nc_type type){	switch(type) {	case NC_CHAR:		return NC_ECHAR;	case NC_BYTE:		return ncx_pad_getn_schar_double(xpp, nelems, tp);	case NC_SHORT:		return ncx_pad_getn_short_double(xpp, nelems, tp);	case NC_INT:		return ncx_getn_int_double(xpp, nelems, tp);	case NC_FLOAT:		return ncx_getn_float_double(xpp, nelems, tp);	case NC_DOUBLE:		return ncx_getn_double_double(xpp, nelems, tp);	}	assert("ncx_pad_getn_Idouble invalid type" == 0);	return NC_EBADTYPE;}intnc_put_att_text(int ncid, int varid, const char *name,	size_t nelems, const char *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_check_name(name);	if(status != NC_NOERR)		return status;		/* 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(NC_CHAR, nelems);			attrp = *attrpp; /* convenience */				if(xsz > attrp->xsz)				return NC_ENOTINDEFINE;			/* else, we can reuse existing without redef */						attrp->xsz = xsz;			attrp->type = NC_CHAR;			attrp->nelems = nelems;			if(nelems != 0)			{				void *xp = attrp->xvalue;				status = ncx_pad_putn_text(&xp, nelems, value);				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;		}		/* 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;	}	attrp = new_NC_attr(name, NC_CHAR, nelems);	if(attrp == NULL)		return NC_ENOMEM;	if(nelems != 0)	{		void *xp = attrp->xvalue;		status = ncx_pad_putn_text(&xp, nelems, value);		if(status != NC_NOERR)			return status;	}	if(attrpp != NULL)	{		assert(old != NULL);		*attrpp = attrp;		free_NC_attr(old);	}	else	{		status = incr_NC_attrarray(ncap, attrp);		if(status != NC_NOERR)		{			free_NC_attr(attrp);			return status;		}	}	return NC_NOERR;}intnc_get_att_text(int ncid, int varid, const char *name, char *str){	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;	/* else */	{		const void *xp = attrp->xvalue;		return ncx_pad_getn_text(&xp, attrp->nelems, str);	}}intnc_put_att_schar(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const signed char *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_Ischar(&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_Ischar				 */				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_Ischar(&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_Ischar		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_schar(int ncid, int varid, const char *name, signed char *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_Ischar(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_uchar(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const unsigned char *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_Iuchar(&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_Iuchar				 */				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_Iuchar(&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_Iuchar		 */		if(lstatus != NC_NOERR)		{			free_NC_attr(attrp);			return lstatus;		}	}	return status;}intnc_get_att_uchar(int ncid, int varid, const char *name, unsigned char *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_Iuchar(&xp, attrp->nelems, tp, attrp->type);	}}intnc_put_att_short(int ncid, int varid, const char *name,	nc_type type, size_t nelems, const short *value){	int status;	NC *ncp;	NC_attrarray *ncap;	NC_attr **attrpp;	NC_attr *old = NULL;	NC_attr *attrp;

⌨️ 快捷键说明

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