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; }
int nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp) { int status; NC_attr *attrp; status = NC_lookupattr(ncid, varid, name, &attrp); if(status != NC_NOERR) return status; if(lenp != NULL) *lenp = attrp->nelems; return NC_NOERR; }
int nc_inq_atttype(int ncid, int varid, const char *name, nc_type *datatypep) { int status; NC_attr *attrp; status = NC_lookupattr(ncid, varid, name, &attrp); if(status != NC_NOERR) return status; if(datatypep != NULL) *datatypep = attrp->type; return NC_NOERR; }
int nc_inq_att(int ncid, int varid, const char *name, /* input, attribute name */ nc_type *datatypep, size_t *lenp) { int status; NC_attr *attrp; status = NC_lookupattr(ncid, varid, name, &attrp); if(status != NC_NOERR) return status; if(datatypep != NULL) *datatypep = attrp->type; if(lenp != NULL) *lenp = attrp->nelems; return NC_NOERR; }
int nc_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); } }
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 nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int ovarid) { int status; NC_attr *iattrp; NC *ncp; NC_attrarray *ncap; NC_attr **attrpp; NC_attr *old = NULL; NC_attr *attrp; status = NC_lookupattr(ncid_in, varid_in, name, &iattrp); if(status != NC_NOERR) return status; status = NC_check_id(ncid_out, &ncp); if(status != NC_NOERR) return status; if(NC_readonly(ncp)) return NC_EPERM; ncap = NC_attrarray0(ncp, ovarid); if(ncap == NULL) return NC_ENOTVAR; attrpp = NC_findattr(ncap, name); if(attrpp != NULL) /* name in use */ { if(!NC_indef(ncp) ) { attrp = *attrpp; /* convenience */ if(iattrp->xsz > attrp->xsz) return NC_ENOTINDEFINE; /* else, we can reuse existing without redef */ attrp->xsz = iattrp->xsz; attrp->type = iattrp->type; attrp->nelems = iattrp->nelems; (void) memcpy(attrp->xvalue, iattrp->xvalue, iattrp->xsz); 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, iattrp->type, iattrp->nelems); if(attrp == NULL) return NC_ENOMEM; (void) memcpy(attrp->xvalue, iattrp->xvalue, iattrp->xsz); 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; }
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; }