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

📄 putget.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 5 页
字号:
	{		if(*coord > X_INT_MAX)			return NC_EINVALCOORDS; /* sanity check */		if(NC_readonly(ncp) && *coord >= NC_get_numrecs(ncp))		{			if(!NC_doNsync(ncp))				return NC_EINVALCOORDS;			/* else */			{				/* Update from disk and check again */				const int status = read_numrecs(ncp);				if(status != NC_NOERR)					return status;				if(*coord >= NC_get_numrecs(ncp))					return NC_EINVALCOORDS;			}		}		ip = coord + 1;		up = varp->shape + 1;	}	else	{		ip = coord;		up = varp->shape;	}	#ifdef CDEBUGfprintf(stderr,"	NCcoordck: coord %ld, count %d, ip %ld\n",		coord, varp->ndims, ip );#endif /* CDEBUG */	for(; ip < coord + varp->ndims; ip++, up++)	{#ifdef CDEBUGfprintf(stderr,"	NCcoordck: ip %p, *ip %ld, up %p, *up %lu\n",			ip, *ip, up, *up );#endif /* CDEBUG */		/* cast needed for braindead systems with signed size_t */		if((unsigned long) *ip >= (unsigned long) *up )			return NC_EINVALCOORDS;	}	return NC_NOERR;}/*  * Check whether 'edges' are valid for the variable and 'start' *//*ARGSUSED*/static intNCedgeck(const NC *ncp, const NC_var *varp,	 const size_t *start, const size_t *edges){	const size_t *const end = start + varp->ndims;	const size_t *shp = varp->shape;	if(varp->ndims == 0)		return NC_NOERR;	/* 'scalar' variable */	if(IS_RECVAR(varp))	{		start++;		edges++;		shp++;	}	for(; start < end; start++, edges++, shp++)	{		/* cast needed for braindead systems with signed size_t */		if((unsigned long) *edges > *shp ||			(unsigned long) *start + (unsigned long) *edges > *shp)		{			return(NC_EEDGE);		}	}	return NC_NOERR;}/*  * Translate the (variable, coord) pair into a seek index */static off_tNC_varoffset(const NC *ncp, const NC_var *varp, const size_t *coord){	if(varp->ndims == 0) /* 'scalar' variable */		return varp->begin;	if(varp->ndims == 1)	{		if(IS_RECVAR(varp))			return varp->begin +				 (off_t)(*coord) * (off_t)ncp->recsize;		/* else */		return varp->begin + (off_t)(*coord) * (off_t)varp->xsz;	}	/* else */	{		off_t lcoord = (off_t)coord[varp->ndims -1];		size_t *up = varp->dsizes +1;		const size_t *ip = coord;		const size_t *const end = varp->dsizes + varp->ndims;				if(IS_RECVAR(varp))			up++, ip++;		for(; up < end; up++, ip++)			lcoord += *up * *ip;		lcoord *= varp->xsz;				if(IS_RECVAR(varp))			lcoord += (off_t)(*coord) * ncp->recsize;				lcoord += varp->begin;		return lcoord;	}}static intputNCvx_char_char(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const char *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_char_char(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_schar(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const schar *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_schar(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_uchar(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const uchar *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_uchar(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_short(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const short *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_short(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_int(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const int *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_int(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_long(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const long *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_long(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_float(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const float *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_float(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_schar_double(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const double *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_schar_double(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_short_schar(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const schar *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_short_schar(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_short_uchar(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const uchar *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_short_uchar(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_short_short(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const short *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)		return NC_NOERR;	assert(value != NULL);	for(;;)	{		size_t extent = MIN(remaining, ncp->chunk);		size_t nput = ncx_howmany(varp->type, extent);		int lstatus = ncp->nciop->get(ncp->nciop, offset, extent,				 RGN_WRITE, &xp);			if(lstatus != NC_NOERR)			return lstatus;				lstatus = ncx_putn_short_short(&xp, nput, value);		if(lstatus != NC_NOERR && status == NC_NOERR)		{			/* not fatal to the loop */			status = lstatus;		}		(void) ncp->nciop->rel(ncp->nciop, offset,				 RGN_MODIFIED);			remaining -= extent;		if(remaining == 0)			break; /* normal loop exit */		offset += extent;		value += nput;	}	return status;}static intputNCvx_short_int(NC *ncp, const NC_var *varp,		 const size_t *start, size_t nelems, const int *value){	off_t offset = NC_varoffset(ncp, varp, start);	size_t remaining = varp->xsz * nelems;	int status = NC_NOERR;	void *xp;	if(nelems == 0)

⌨️ 快捷键说明

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