Commit b828f4ac authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdiInqAttType() and cdiDelAtt().

parent 3169db42
2020-02-26 Uwe Schulzweida
* Added function cdiInqAttType() and cdiDelAtt()
2020-02-25 Uwe Schulzweida 2020-02-25 Uwe Schulzweida
* Added function cdiInqAttLen() * Added function cdiInqAttLen()
......
...@@ -684,6 +684,7 @@ int cdiInqNatts(int cdiID, int varID, int *nattsp); ...@@ -684,6 +684,7 @@ int cdiInqNatts(int cdiID, int varID, int *nattsp);
// cdiInqAtt: Get information about an attribute // cdiInqAtt: Get information about an attribute
int cdiInqAtt(int cdiID, int varID, int attrnum, char *name, int *typep, int *lenp); int cdiInqAtt(int cdiID, int varID, int attrnum, char *name, int *typep, int *lenp);
int cdiInqAttLen(int cdiID, int varID, const char *name); int cdiInqAttLen(int cdiID, int varID, const char *name);
int cdiInqAttType(int cdiID, int varID, const char *name);
int cdiDelAtt(int cdiID, int varID, const char *name); int cdiDelAtt(int cdiID, int varID, const char *name);
int cdiCopyAtts(int cdiID1, int varID1, int cdiID2, int varID2); int cdiCopyAtts(int cdiID1, int varID1, int cdiID2, int varID2);
......
...@@ -169,7 +169,7 @@ int cdiInqAtt(int cdiID, int varID, int attnum, char *name, int *typep, int *len ...@@ -169,7 +169,7 @@ int cdiInqAtt(int cdiID, int varID, int attnum, char *name, int *typep, int *len
if ( attnum >= 0 && attnum < (int)attsp->nelems ) if ( attnum >= 0 && attnum < (int)attsp->nelems )
attp = &(attsp->value[attnum]); attp = &(attsp->value[attnum]);
if ( attp != NULL ) /* name in use */ if ( attp != NULL && attp->name ) /* name in use */
{ {
memcpy(name, attp->name, attp->namesz+1); memcpy(name, attp->name, attp->namesz+1);
*typep = attp->exdtype; *typep = attp->exdtype;
...@@ -199,13 +199,32 @@ int cdiInqAttLen(int cdiID, int varID, const char *name) ...@@ -199,13 +199,32 @@ int cdiInqAttLen(int cdiID, int varID, const char *name)
for ( int attid = 0; attid < (int)attsp->nelems; attid++ ) for ( int attid = 0; attid < (int)attsp->nelems; attid++ )
{ {
cdi_att_t *attp = &(attsp->value[attid]); cdi_att_t *attp = &(attsp->value[attid]);
if (strcmp(attp->name, name) == 0) length = (int)attp->nelems; if (attp->name && strcmp(attp->name, name) == 0) length = (int)attp->nelems;
} }
return length; return length;
} }
int cdiInqAttType(int cdiID, int varID, const char *name)
{
int type = -1;
xassert(name != NULL);
cdi_atts_t *attsp = cdi_get_attsp(cdiID, varID);
xassert(attsp != NULL);
for ( int attid = 0; attid < (int)attsp->nelems; attid++ )
{
cdi_att_t *attp = &(attsp->value[attid]);
if (attp->name && strcmp(attp->name, name) == 0) type = attp->exdtype;
}
return type;
}
int cdiDeleteAtts(int cdiID, int varID) int cdiDeleteAtts(int cdiID, int varID)
{ {
int status = CDI_NOERR; int status = CDI_NOERR;
...@@ -216,7 +235,12 @@ int cdiDeleteAtts(int cdiID, int varID) ...@@ -216,7 +235,12 @@ int cdiDeleteAtts(int cdiID, int varID)
for ( int attid = 0; attid < (int)attsp->nelems; attid++ ) for ( int attid = 0; attid < (int)attsp->nelems; attid++ )
{ {
cdi_att_t *attp = &(attsp->value[attid]); cdi_att_t *attp = &(attsp->value[attid]);
if ( attp->name ) Free(attp->name); if ( attp->name )
{
Free(attp->name);
attp->name = NULL;
attp->namesz = 0;
}
if ( attp->xvalue ) Free(attp->xvalue); if ( attp->xvalue ) Free(attp->xvalue);
} }
...@@ -230,11 +254,24 @@ int cdiDelAtt(int cdiID, int varID, const char *name) ...@@ -230,11 +254,24 @@ int cdiDelAtt(int cdiID, int varID, const char *name)
{ {
int status = CDI_NOERR; int status = CDI_NOERR;
UNUSED(cdiID); cdi_atts_t *attsp = cdi_get_attsp(cdiID, varID);
UNUSED(varID); xassert(attsp != NULL);
UNUSED(name);
fprintf(stderr, "cdiDelAtt not implemented!\n"); for ( int attid = 0; attid < (int)attsp->nelems; attid++ )
{
cdi_att_t *attp = &(attsp->value[attid]);
if (attp->name && strcmp(attp->name, name) == 0)
{
Free(attp->name);
attp->name = NULL;
attp->namesz = 0;
if ( attp->xvalue )
{
Free(attp->xvalue);
attp->xvalue = NULL;
}
}
}
return status; return status;
} }
...@@ -466,8 +503,7 @@ int cdiAttTypeLookup(cdi_att_t *attp) ...@@ -466,8 +503,7 @@ int cdiAttTypeLookup(cdi_att_t *attp)
type = attp->indtype; type = attp->indtype;
break; break;
default: default:
xabort("Unknown datatype encountered in attribute %s: %d\n", xabort("Unknown datatype encountered in attribute %s: %d\n", attp->name, attp->indtype);
attp->name, attp->indtype);
} }
return type; return type;
} }
...@@ -481,7 +517,7 @@ int cdi_att_compare(cdi_atts_t *attspa, cdi_atts_t *attspb, int attnum) ...@@ -481,7 +517,7 @@ int cdi_att_compare(cdi_atts_t *attspa, cdi_atts_t *attspb, int attnum)
if (attpa->namesz != attpb->namesz) return 1; if (attpa->namesz != attpb->namesz) return 1;
if (memcmp(attpa->name, attpb->name, attpa->namesz)) return 1; if (attpa->name && attpb->name && memcmp(attpa->name, attpb->name, attpa->namesz)) return 1;
if (attpa->indtype != attpb->indtype if (attpa->indtype != attpb->indtype
|| attpa->exdtype != attpb->exdtype || attpa->exdtype != attpb->exdtype
...@@ -524,12 +560,11 @@ void cdiAttPack(vlist_t *vlistptr, int varID, int attnum, ...@@ -524,12 +560,11 @@ void cdiAttPack(vlist_t *vlistptr, int varID, int attnum,
void *buf, int size, int *position, void *context) void *buf, int size, int *position, void *context)
{ {
cdi_atts_t *attsp; cdi_atts_t *attsp;
cdi_att_t *attp;
int tempbuf[cdi_att_nints]; int tempbuf[cdi_att_nints];
xassert(attsp = get_attsp(vlistptr, varID)); xassert(attsp = get_attsp(vlistptr, varID));
xassert(attnum >= 0 && attnum < (int)attsp->nelems); xassert(attnum >= 0 && attnum < (int)attsp->nelems);
attp = &(attsp->value[attnum]); cdi_att_t *attp = &(attsp->value[attnum]);
tempbuf[0] = (int)attp->namesz; tempbuf[0] = (int)attp->namesz;
tempbuf[1] = attp->exdtype; tempbuf[1] = attp->exdtype;
tempbuf[2] = attp->indtype; tempbuf[2] = attp->indtype;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment