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

Added support for attribute type int16 and float32

parent 694fb8bb
......@@ -469,17 +469,17 @@ int vlistInqAtt(int vlistID, int varID, int attrnum, char *name, int *typep,
int vlistDelAtt(int vlistID, int varID, const char *name);
/* vlistDefAttInt: Define an integer attribute */
int vlistDefAttInt(int vlistID, int varID, const char *name, int len, const int *ip_vec);
/* vlistDefAttInt: Define a floating point attribute */
int vlistDefAttFlt(int vlistID, int varID, const char *name, int len, const double *dp_vec);
/* vlistDefAttInt: Define a text attribute */
int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip_vec);
/* vlistDefAttFlt: Define a floating point attribute */
int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp_vec);
/* vlistDefAttTxt: Define a text attribute */
int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp);
/* vlistInqAttInt: Get the value(s) of an integer attribute */
int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip_vec);
/* vlistInqAttInt: Get the value(s) of a floating point attribute */
/* vlistInqAttFlt: Get the value(s) of a floating point attribute */
int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *dp_vec);
/* vlistInqAttInt: Get the value(s) of a text attribute */
/* vlistInqAttTxt: Get the value(s) of a text attribute */
int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, char *tp);
......
......@@ -1034,6 +1034,7 @@
! (INTEGER vlistID,
! INTEGER varID,
! CHARACTER*(*) name,
! INTEGER type,
! INTEGER len,
! INTEGER ip_vec)
EXTERNAL vlistDefAttInt
......@@ -1042,6 +1043,7 @@
! (INTEGER vlistID,
! INTEGER varID,
! CHARACTER*(*) name,
! INTEGER type,
! INTEGER len,
! DOUBLEPRECISION dp_vec)
EXTERNAL vlistDefAttFlt
......@@ -1104,6 +1106,16 @@
! INTEGER mask_vec)
EXTERNAL gridInqMaskGME
! gridDefMask
! (INTEGER gridID,
! INTEGER mask_vec)
EXTERNAL gridDefMask
INTEGER gridInqMask
! (INTEGER gridID,
! INTEGER mask_vec)
EXTERNAL gridInqMask
! gridPrint
! (INTEGER gridID,
! INTEGER opt)
......
......@@ -212,8 +212,8 @@ FCALLSCFUN3 (INT, vlistMergedLevel, VLISTMERGEDLEVEL, vlistmergedlevel, INT, INT
FCALLSCFUN3 (INT, vlistInqNatts, VLISTINQNATTS, vlistinqnatts, INT, INT, PINT)
FCALLSCFUN6 (INT, vlistInqAtt, VLISTINQATT, vlistinqatt, INT, INT, INT, PSTRING, PINT, PINT)
FCALLSCFUN3 (INT, vlistDelAtt, VLISTDELATT, vlistdelatt, INT, INT, STRING)
FCALLSCFUN5 (INT, vlistDefAttInt, VLISTDEFATTINT, vlistdefattint, INT, INT, STRING, INT, PINT)
FCALLSCFUN5 (INT, vlistDefAttFlt, VLISTDEFATTFLT, vlistdefattflt, INT, INT, STRING, INT, PDOUBLE)
FCALLSCFUN6 (INT, vlistDefAttInt, VLISTDEFATTINT, vlistdefattint, INT, INT, STRING, INT, INT, PINT)
FCALLSCFUN6 (INT, vlistDefAttFlt, VLISTDEFATTFLT, vlistdefattflt, INT, INT, STRING, INT, INT, PDOUBLE)
FCALLSCFUN5 (INT, vlistDefAttTxt, VLISTDEFATTTXT, vlistdefatttxt, INT, INT, STRING, INT, STRING)
FCALLSCFUN5 (INT, vlistInqAttInt, VLISTINQATTINT, vlistinqattint, INT, INT, STRING, INT, PINT)
FCALLSCFUN5 (INT, vlistInqAttFlt, VLISTINQATTFLT, vlistinqattflt, INT, INT, STRING, INT, PDOUBLE)
......@@ -226,6 +226,8 @@ FCALLSCFUN1 (STRING, gridNamePtr, GRIDNAMEPTR, gridnameptr, INT)
FCALLSCSUB1 (gridCompress, GRIDCOMPRESS, gridcompress, INT)
FCALLSCSUB2 (gridDefMaskGME, GRIDDEFMASKGME, griddefmaskgme, INT, PINT)
FCALLSCFUN2 (INT, gridInqMaskGME, GRIDINQMASKGME, gridinqmaskgme, INT, PINT)
FCALLSCSUB2 (gridDefMask, GRIDDEFMASK, griddefmask, INT, PINT)
FCALLSCFUN2 (INT, gridInqMask, GRIDINQMASK, gridinqmask, INT, PINT)
FCALLSCSUB2 (gridPrint, GRIDPRINT, gridprint, INT, INT)
FCALLSCFUN0 (INT, gridSize, GRIDSIZE, gridsize)
FCALLSCFUN2 (INT, gridCreate, GRIDCREATE, gridcreate, INT, INT)
......
......@@ -423,22 +423,28 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID)
len = attlen;
cdf_put_att_text(fileID, ncvarID, attname, len, atttxt);
}
else if ( atttype == DATATYPE_INT )
else if ( atttype == DATATYPE_INT16 || atttype == DATATYPE_INT32 )
{
int *attint;
attint = (int *) malloc(attlen*sizeof(int));
vlistInqAttInt(vlistID, varID, attname, attlen, &attint[0]);
len = attlen;
cdf_put_att_int(fileID, ncvarID, attname, NC_INT, len, attint);
if ( atttype == DATATYPE_INT16 )
cdf_put_att_int(fileID, ncvarID, attname, NC_SHORT, len, attint);
else
cdf_put_att_int(fileID, ncvarID, attname, NC_INT, len, attint);
free(attint);
}
else if ( atttype == DATATYPE_FLT )
else if ( atttype == DATATYPE_FLT32 || atttype == DATATYPE_FLT64 )
{
double *attflt;
attflt = (double *) malloc(attlen*sizeof(double));
vlistInqAttFlt(vlistID, varID, attname, attlen, attflt);
len = attlen;
cdf_put_att_double(fileID, ncvarID, attname, NC_DOUBLE, len, attflt);
if ( atttype == DATATYPE_FLT32 )
cdf_put_att_double(fileID, ncvarID, attname, NC_FLOAT, len, attflt);
else
cdf_put_att_double(fileID, ncvarID, attname, NC_DOUBLE, len, attflt);
free(attflt);
}
}
......@@ -4752,12 +4758,15 @@ int cdfInqContents(int streamID)
}
}
}
else if ( xtype == NC_INT || xtype == NC_SHORT )
else if ( xtype == NC_SHORT || xtype == NC_INT )
{
int *attint;
attint = (int *) malloc(attlen*sizeof(int));
cdfGetAttInt(fileID, NC_GLOBAL, attname, attlen, attint);
vlistDefAttInt(vlistID, CDI_GLOBAL, attname, (int)attlen, attint);
if ( xtype == NC_SHORT )
vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT16, (int)attlen, attint);
else
vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT32, (int)attlen, attint);
free(attint);
}
else if ( xtype == NC_FLOAT || xtype == NC_DOUBLE )
......@@ -4765,7 +4774,10 @@ int cdfInqContents(int streamID)
double *attflt;
attflt = (double *) malloc(attlen*sizeof(double));
cdfGetAttDouble(fileID, NC_GLOBAL, attname, attlen, attflt);
vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, (int)attlen, attflt);
if ( xtype == NC_FLOAT )
vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT32, (int)attlen, attflt);
else
vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT64, (int)attlen, attflt);
free(attflt);
}
}
......@@ -5916,12 +5928,15 @@ int cdfInqContents(int streamID)
cdf_inq_attname(fileID, ncvarid, attnum, attname);
cdf_inq_attlen(fileID, ncvarid, attname, &attlen);
cdf_inq_atttype(fileID, ncvarid, attname, &attrtype);
if ( attrtype == NC_INT || attrtype == NC_SHORT )
if ( attrtype == NC_SHORT || attrtype == NC_INT )
{
int *attint;
attint = (int *) malloc(attlen*sizeof(int));
cdfGetAttInt(fileID, ncvarid, attname, attlen, attint);
vlistDefAttInt(vlistID, varID, attname, (int)attlen, attint);
if ( attrtype == NC_SHORT )
vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint);
else
vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT32, (int)attlen, attint);
if ( CDI_Debug )
printf("int: %s.%s = %d\n", ncvars[ncvarid].name, attname, attint[0]);
free(attint);
......@@ -5931,7 +5946,10 @@ int cdfInqContents(int streamID)
double *attflt;
attflt = (double *) malloc(attlen*sizeof(double));
cdfGetAttDouble(fileID, ncvarid, attname, attlen, attflt);
vlistDefAttFlt(vlistID, varID, attname, (int)attlen, attflt);
if ( attrtype == NC_FLOAT )
vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt);
else
vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT64, (int)attlen, attflt);
if ( CDI_Debug )
printf("flt: %s.%s = %g\n", ncvars[ncvarid].name, attname, attflt[0]);
free(attflt);
......
......@@ -10,13 +10,17 @@
* CDI attribute
*/
typedef struct {
size_t xsz; /* amount of space at xvalue */
size_t namesz; /* size of name */
char *name; /* attribute name */
int type; /* data type of xvalue (INT, FLT or TXT) */
int nctype;
size_t nelems; /* number of elements */
void *xvalue; /* the actual data */
size_t xsz; /* amount of space at xvalue */
size_t namesz; /* size of name */
char *name; /* attribute name */
int indtype; /* internal data type of xvalue (INT, FLT or TXT) */
int exdtype; /* external data type */
/* indtype exdtype */
/* TXT TXT */
/* INT INT16, INT32 */
/* FLT FLT32, FLT64 */
size_t nelems; /* number of elements */
void *xvalue; /* the actual data */
} cdi_att_t;
......
......@@ -12,7 +12,7 @@
static
cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
{
static const char *func = "get_attsp";
// static const char *func = "get_attsp";
cdi_atts_t *attsp = NULL;
if ( varID == CDI_GLOBAL )
......@@ -28,7 +28,6 @@ cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
return (attsp);
}
static
cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
{
......@@ -55,7 +54,6 @@ cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
return (NULL);
}
static
cdi_att_t *new_att(cdi_atts_t *attsp, const char *name)
{
......@@ -81,17 +79,17 @@ cdi_att_t *new_att(cdi_atts_t *attsp, const char *name)
return (attp);
}
static
void fill_att(cdi_att_t *attp, int type, size_t nelems, size_t xsz, const void *xvalue)
void fill_att(cdi_att_t *attp, int indtype, int exdtype, size_t nelems, size_t xsz, const void *xvalue)
{
static const char *func = "fill_att";
assert(attp != NULL);
attp->xsz = xsz;
attp->type = type;
attp->nelems = nelems;
attp->indtype = indtype;
attp->exdtype = exdtype;
attp->nelems = nelems;
if ( xsz > 0 )
{
......@@ -100,7 +98,6 @@ void fill_att(cdi_att_t *attp, int type, size_t nelems, size_t xsz, const void *
}
}
/*
@Function vlistInqNatts
@Title Get number of variable attributes
......@@ -118,7 +115,7 @@ The function @func{vlistInqNatts} gets the number of variable attributes assigne
*/
int vlistInqNatts(int vlistID, int varID, int *nattsp)
{
static const char *func = "vlistInqNatts";
// static const char *func = "vlistInqNatts";
int status = CDI_NOERR;
vlist_t *vlistptr;
cdi_atts_t *attsp;
......@@ -133,7 +130,6 @@ int vlistInqNatts(int vlistID, int varID, int *nattsp)
return (status);
}
/*
@Function vlistInqAtt
@Title Get information about an attribute
......@@ -154,7 +150,7 @@ The function @func{vlistInqNatts} gets information about an attribute.
*/
int vlistInqAtt(int vlistID, int varID, int attnum, char *name, int *typep, int *lenp)
{
static const char *func = "vlistInqAtt";
// static const char *func = "vlistInqAtt";
int status = CDI_NOERR;
vlist_t *vlistptr;
cdi_att_t *attp = NULL;
......@@ -173,7 +169,7 @@ int vlistInqAtt(int vlistID, int varID, int attnum, char *name, int *typep, int
if ( attp != NULL ) /* name in use */
{
memcpy(name, attp->name, attp->namesz+1);
*typep = attp->type;
*typep = attp->exdtype;
*lenp = attp->nelems;
}
else
......@@ -223,11 +219,10 @@ int vlistDelAtt(int vlistID, int varID, const char *name)
return (status);
}
static
int vlist_def_att(int type, int vlistID, int varID, const char *name, size_t len, size_t xsz, const void *xp)
int vlist_def_att(int indtype, int exdtype, int vlistID, int varID, const char *name, size_t len, size_t xsz, const void *xp)
{
static const char *func = "vlist_def_att";
// static const char *func = "vlist_def_att";
int status = CDI_NOERR;
vlist_t *vlistptr;
cdi_att_t *attp;
......@@ -248,14 +243,13 @@ int vlist_def_att(int type, int vlistID, int varID, const char *name, size_t len
attp = new_att(attsp, name);
if ( attp != NULL )
fill_att(attp, type, len, xsz, xp);
fill_att(attp, indtype, exdtype, len, xsz, xp);
return (status);
}
static
int vlist_inq_att(int type, int vlistID, int varID, const char *name, size_t mxsz, void *xp)
int vlist_inq_att(int indtype, int vlistID, int varID, const char *name, size_t mxsz, void *xp)
{
static const char *func = "vlist_inq_att";
int status = CDI_NOERR;
......@@ -277,10 +271,17 @@ int vlist_inq_att(int type, int vlistID, int varID, const char *name, size_t mxs
attp = find_att(attsp, name);
if ( attp != NULL ) /* name in use */
{
xsz = attp->xsz;
if ( mxsz < xsz ) xsz = mxsz;
if ( xsz > 0 )
memcpy(xp, attp->xvalue, xsz);
if ( attp->indtype == indtype )
{
xsz = attp->xsz;
if ( mxsz < xsz ) xsz = mxsz;
if ( xsz > 0 )
memcpy(xp, attp->xvalue, xsz);
}
else
{
Warning(func, "Attribute %s has wrong data type!", name);
}
}
else
{
......@@ -293,7 +294,7 @@ int vlist_inq_att(int type, int vlistID, int varID, const char *name, size_t mxs
int vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2)
{
static const char *func = "vlistCopyVarAtts";
// static const char *func = "vlistCopyVarAtts";
int status = CDI_NOERR;
vlist_t *vlistptr1;
cdi_att_t *attp = NULL;
......@@ -308,23 +309,23 @@ int vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2)
for ( attid = 0; attid < (int)attsp1->nelems; attid++ )
{
attp = &(attsp1->value[attid]);
vlist_def_att(attp->type, vlistID2, varID_2, attp->name, attp->nelems, attp->xsz, attp->xvalue);
vlist_def_att(attp->indtype, attp->exdtype, vlistID2, varID_2, attp->name, attp->nelems, attp->xsz, attp->xvalue);
}
return (status);
}
/*
@Function vlistDefAttInt
@Title Define an integer attribute
@Prototype int vlistDefAttInt(int vlistID, int varID, const char *name, int len, const int *ip)
@Prototype int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip)
@Parameter
@Item vlistID Variable list ID, from a previous call to @fref{vlistCreate}
@Item varID Variable identifier, or CDI_GLOBAL for a global attribute
@Item name Attribute name
@Item type External data type (DATATYPE_INT16 or DATATYPE_INT32)
@Item len Number of values provided for the attribute
@Item ip Pointer to one or more integer values
......@@ -333,26 +334,26 @@ The function @func{vlistDefAttInt} defines an integer attribute.
@EndFunction
*/
int vlistDefAttInt(int vlistID, int varID, const char *name, int len, const int *ip)
int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip)
{
int status;
status = vlist_def_att(DATATYPE_INT, vlistID, varID, name, (size_t) len, len*sizeof(int), (const void *) ip);
status = vlist_def_att(DATATYPE_INT, type, vlistID, varID, name, (size_t) len, len*sizeof(int), (const void *) ip);
return (status);
}
/*
@Function vlistDefAttFlt
@Title Define a floating point attribute
@Prototype int vlistDefAttFlt(int vlistID, int varID, const char *name, int len, const double *dp)
@Prototype int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
@Parameter
@Item vlistID Variable list ID, from a previous call to @fref{vlistCreate}
@Item varID Variable identifier, or CDI_GLOBAL for a global attribute
@Item name Attribute name
@Item type External data type (DATATYPE_FLT32 or DATATYPE_FLT64)
@Item len Number of values provided for the attribute
@Item dp Pointer to one or more floating point values
......@@ -361,16 +362,15 @@ The function @func{vlistDefAttFlt} defines a floating point attribute.
@EndFunction
*/
int vlistDefAttFlt(int vlistID, int varID, const char *name, int len, const double *dp)
int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
{
int status;
status = vlist_def_att(DATATYPE_FLT, vlistID, varID, name, (size_t) len, len*sizeof(double), (const void *) dp);
status = vlist_def_att(DATATYPE_FLT, type, vlistID, varID, name, (size_t) len, len*sizeof(double), (const void *) dp);
return (status);
}
/*
@Function vlistDefAttTxt
@Title Define a text attribute
......@@ -393,12 +393,11 @@ int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char
{
int status;
status = vlist_def_att(DATATYPE_TXT, vlistID, varID, name, (size_t) len, len*sizeof(char), (const void *) tp);
status = vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t) len, len*sizeof(char), (const void *) tp);
return (status);
}
/*
@Function vlistInqAttInt
@Title Get the value(s) of an integer attribute
......@@ -425,7 +424,6 @@ int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
return (CDI_NOERR);
}
/*
@Function vlistInqAttFlt
@Title Get the value(s) of a floating point attribute
......@@ -452,7 +450,6 @@ int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *d
return (status);
}
/*
@Function vlistInqAttTxt
@Title Get the value(s) of a text attribute
......
Supports Markdown
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