コード例 #1
0
ファイル: test_vara.c プロジェクト: BJangeofan/netcdf-c
static int check(size_t* start, size_t* count)
{
    int ok = 1;
    Odom* odom = odom_create(RANK);
    float* result = (float*)threeD;
    float* expected = (float*)threeD;
    odom_set(odom,start,count);
    while(odom_more(odom)) {
	size_t offset = odom_count(odom);
	if(floateq(result[offset],expected[offset])) {
	    fprintf(stderr,"fail: result[%lu] = %f ; expected[%lu] = %f\n",
		(long unsigned)offset,result[offset],(long unsigned)offset,expected[offset]);
	    ok=0;
	}
        odom_incr(odom);
    }
    odom_reclaim(odom);
    return ok;
}
コード例 #2
0
ファイル: test_vara.c プロジェクト: gsjaardema/netcdf-c
static int
check(size_t* start, size_t* count)
{
    int ok = 1;
    int index = 0;
    Odom* odom = odom_create(RANK);
    odom_set(odom,start,count);
    float* result = (float*)target;
    float* expected = (float*)target_data;
    for(index=0;odom_more(odom);odom_incr(odom),index++) {
	size_t offset = odom_count(odom);
	if(!floateq(result[index],expected[offset])) {
	    fprintf(stderr,"fail: result[%lu] = %f ; expected[%lu] = %f\n",
		index,result[index],offset,expected[offset]);
	    ok=0;
	}
    }
    odom_reclaim(odom);
    return ok;
}
コード例 #3
0
ファイル: test_partvar.c プロジェクト: UV-CDAT/netcdf-c
static int
check(float* target, size_t* start, size_t* count)
{
    int ok = 1;
    Odom* odom = odom_create(RANK);
    float* result = (float*)target;
    float* expected = (float*)target_content;
    odom_set(odom,start,count);
    while(odom_more(odom)) {
	size_t offset = odom_count(odom);
	int eq = floateq(result[offset],expected[offset]);
	if(eq == 0) {
	    fprintf(stderr,"fail: result[%lu] = %f ; expected[%lu] = %f\n",
		offset,result[offset],offset,expected[offset]);
	    ok=0;
	}
        odom_incr(odom);
    }
    odom_reclaim(odom);
    return ok;
}
コード例 #4
0
ファイル: dvarget.c プロジェクト: bishtgautam/sbetr
/** \internal
\ingroup variables
 Most dispatch tables will use the default procedures
*/
int
NCDEFAULT_get_vars(int ncid, int varid, const size_t * start,
	    const size_t * edges, const ptrdiff_t * stride,
	    void *value0, nc_type memtype)
{
#ifdef VARS_USES_VARM
   NC* ncp;
   int stat = NC_check_id(ncid, &ncp);

   if(stat != NC_NOERR) return stat;
   return ncp->dispatch->get_varm(ncid,varid,start,edges,stride,NULL,value0,memtype);
#else
  /* Rebuilt get_vars code to simplify and avoid use of get_varm */

   int status = NC_NOERR;
   int i,simplestride,isrecvar;
   int rank;
   struct GETodometer odom;
   nc_type vartype = NC_NAT;
   NC* ncp;
   int memtypelen;
   size_t vartypelen;
   char* value = (char*)value0;
   size_t numrecs;
   size_t varshape[NC_MAX_VAR_DIMS];
   size_t mystart[NC_MAX_VAR_DIMS];
   size_t myedges[NC_MAX_VAR_DIMS];
   ptrdiff_t mystride[NC_MAX_VAR_DIMS];
   char *memptr = NULL;

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

   status = nc_inq_vartype(ncid, varid, &vartype);
   if(status != NC_NOERR) return status;

   if(memtype == NC_NAT) memtype = vartype;

   /* compute the variable type size */
   status = nc_inq_type(ncid,vartype,NULL,&vartypelen);
   if(status != NC_NOERR) return status;

   if(memtype > NC_MAX_ATOMIC_TYPE)
	memtypelen = (int)vartypelen;
    else
	memtypelen = nctypelen(memtype);

   /* Check gross internal/external type compatibility */
   if(vartype != memtype) {
      /* If !atomic, the two types must be the same */
      if(vartype > NC_MAX_ATOMIC_TYPE
         || memtype > NC_MAX_ATOMIC_TYPE)
	 return NC_EBADTYPE;
      /* ok, the types differ but both are atomic */
      if(memtype == NC_CHAR || vartype == NC_CHAR)
	 return NC_ECHAR;
   }

   /* Get the variable rank */
   status = nc_inq_varndims(ncid, varid, &rank);
   if(status != NC_NOERR) return status;

   /* Get variable dimension sizes */
   isrecvar = NC_is_recvar(ncid,varid,&numrecs);
   NC_getshape(ncid,varid,rank,varshape);

   /* Optimize out using various checks */
   if (rank == 0) {
      /*
       * The variable is a scalar; consequently,
       * there s only one thing to get and only one place to put it.
       * (Why was I called?)
       */
      size_t edge1[1] = {1};
      return NC_get_vara(ncid, varid, start, edge1, value, memtype);
   }

   /* Do various checks and fixups on start/edges/stride */
   simplestride = 1; /* assume so */
   for(i=0;i<rank;i++) {
	size_t dimlen;
	mystart[i] = (start == NULL ? 0 : start[i]);
	if(edges == NULL) {
	   if(i == 0 && isrecvar)
  	      myedges[i] = numrecs - start[i];
	   else
	      myedges[i] = varshape[i] - mystart[i];
	} else
	    myedges[i] = edges[i];
	if(myedges[i] == 0)
	    return NC_NOERR; /* cannot read anything */
	mystride[i] = (stride == NULL ? 1 : stride[i]);
	if(mystride[i] <= 0
	   /* cast needed for braindead systems with signed size_t */
           || ((unsigned long) mystride[i] >= X_INT_MAX))
           return NC_ESTRIDE;
  	if(mystride[i] != 1) simplestride = 0;
        /* illegal value checks */
	dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
        /* mystart is unsigned, never < 0 */
	if(mystart[i] >= dimlen)
	  return NC_EINVALCOORDS;
        /* myedges is unsigned, never < 0 */
	if(mystart[i] + myedges[i] > dimlen)
	  return NC_EEDGE;
   }
   if(simplestride) {
      return NC_get_vara(ncid, varid, mystart, myedges, value, memtype);
   }

   /* memptr indicates where to store the next value */
   memptr = value;

   odom_init(&odom,rank,mystart,myedges,mystride);

   /* walk the odometer to extract values */
   while(odom_more(&odom)) {
      int localstatus = NC_NOERR;
      /* Read a single value */
      localstatus = NC_get_vara(ncid,varid,odom.index,nc_sizevector1,memptr,memtype);
      /* So it turns out that when get_varm is used, all errors are
         delayed and ERANGE will be overwritten by more serious errors.
      */
      if(localstatus != NC_NOERR) {
	    if(status == NC_NOERR || localstatus != NC_ERANGE)
	       status = localstatus;
      }
      memptr += memtypelen;
      odom_next(&odom);
   }
   return status;
#endif
}