int NC3_get_att( int ncid, int varid, const char *name, void *value, nc_type memtype) { int status; NC_attr *attrp; const void *xp; status = NC_lookupattr(ncid, varid, name, &attrp); if(status != NC_NOERR) return status; if(attrp->nelems == 0) return NC_NOERR; if(memtype == NC_NAT) memtype = attrp->type; if(memtype != NC_CHAR && attrp->type == NC_CHAR) return NC_ECHAR; if(memtype == NC_CHAR && attrp->type != NC_CHAR) return NC_ECHAR; xp = attrp->xvalue; switch (memtype) { case NC_CHAR: return ncx_pad_getn_text(&xp, attrp->nelems , (char *)value); case NC_BYTE: return ncx_pad_getn_Ischar(&xp,attrp->nelems,(schar*)value,attrp->type); case NC_SHORT: return ncx_pad_getn_Ishort(&xp,attrp->nelems,(short*)value,attrp->type); case NC_INT: return ncx_pad_getn_Iint(&xp,attrp->nelems,(int*)value,attrp->type); case NC_FLOAT: return ncx_pad_getn_Ifloat(&xp,attrp->nelems,(float*)value,attrp->type); case NC_DOUBLE: return ncx_pad_getn_Idouble(&xp,attrp->nelems,(double*)value,attrp->type); case NC_INT64: return ncx_pad_getn_Ilonglong(&xp,attrp->nelems,(longlong*)value,attrp->type); case NC_UBYTE: /* Synthetic */ return ncx_pad_getn_Iuchar(&xp, attrp->nelems , (uchar *)value, attrp->type); case NC_USHORT: return ncx_pad_getn_Iushort(&xp,attrp->nelems,(ushort*)value,attrp->type); case NC_UINT: return ncx_pad_getn_Iuint(&xp,attrp->nelems,(uint*)value,attrp->type); case NC_UINT64: return ncx_pad_getn_Iulonglong(&xp,attrp->nelems,(ulonglong*)value,attrp->type); case NC_NAT: return NC_EBADTYPE; default: break; } status = NC_EBADTYPE; return status; }
/* Read a NC_string from the header */ static int v1h_get_NC_string(v1hs *gsp, NC_string **ncstrpp) { int status; size_t nchars = 0; NC_string *ncstrp; status = v1h_get_size_t(gsp, &nchars); if(status != ENOERR) return status; ncstrp = new_NC_string(nchars, NULL); if(ncstrp == NULL) { return NC_ENOMEM; } #if 0 /* assert(ncstrp->nchars == nchars || ncstrp->nchars - nchars < X_ALIGN); */ assert(ncstrp->nchars % X_ALIGN == 0); status = check_v1hs(gsp, ncstrp->nchars); #else status = check_v1hs(gsp, _RNDUP(ncstrp->nchars, X_ALIGN)); #endif if(status != ENOERR) goto unwind_alloc; status = ncx_pad_getn_text((const void **)(&gsp->pos), nchars, ncstrp->cp); if(status != ENOERR) goto unwind_alloc; *ncstrpp = ncstrp; return ENOERR; unwind_alloc: free_NC_string(ncstrp); return status; }
int nc_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); } }
int NC3_get_att( int ncid, int varid, const char *name, void *value, nc_type memtype) { int status; NC *nc; NC3_INFO* ncp; NC_attr *attrp; const void *xp; status = NC_check_id(ncid, &nc); if(status != NC_NOERR) return status; ncp = NC3_DATA(nc); status = NC_lookupattr(ncid, varid, name, &attrp); if(status != NC_NOERR) return status; if(attrp->nelems == 0) return NC_NOERR; if(memtype == NC_NAT) memtype = attrp->type; if(memtype != NC_CHAR && attrp->type == NC_CHAR) return NC_ECHAR; if(memtype == NC_CHAR && attrp->type != NC_CHAR) return NC_ECHAR; xp = attrp->xvalue; switch (memtype) { case NC_CHAR: return ncx_pad_getn_text(&xp, attrp->nelems, (char *)value); case NC_BYTE: return ncx_pad_getn_Ischar(&xp,attrp->nelems,(schar*)value,attrp->type); case NC_SHORT: return ncx_pad_getn_Ishort(&xp,attrp->nelems,(short*)value,attrp->type); case NC_INT: return ncx_pad_getn_Iint(&xp,attrp->nelems,(int*)value,attrp->type); case NC_FLOAT: return ncx_pad_getn_Ifloat(&xp,attrp->nelems,(float*)value,attrp->type); case NC_DOUBLE: return ncx_pad_getn_Idouble(&xp,attrp->nelems,(double*)value,attrp->type); case NC_INT64: return ncx_pad_getn_Ilonglong(&xp,attrp->nelems,(longlong*)value,attrp->type); case NC_UBYTE: /* Synthetic */ /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ if (!fIsSet(ncp->flags,NC_64BIT_DATA) && attrp->type == NC_BYTE) return ncx_pad_getn_Iuchar(&xp, attrp->nelems, (uchar *)value, NC_UBYTE); else return ncx_pad_getn_Iuchar(&xp, attrp->nelems, (uchar *)value, attrp->type); case NC_USHORT: return ncx_pad_getn_Iushort(&xp,attrp->nelems,(ushort*)value,attrp->type); case NC_UINT: return ncx_pad_getn_Iuint(&xp,attrp->nelems,(uint*)value,attrp->type); case NC_UINT64: return ncx_pad_getn_Iulonglong(&xp,attrp->nelems,(ulonglong*)value,attrp->type); case NC_NAT: return NC_EBADTYPE; default: break; } status = NC_EBADTYPE; return status; }