Commit 525ba45f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added datatype2str()

parent e2c569e8
......@@ -27,6 +27,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "util.h"
static
......@@ -82,7 +83,7 @@ void printAtts(FILE *fp, int vlistID, int varID)
static
void partab(FILE *fp, int vlistID, int option)
{
int varID, code, tabnum, tableID, prec;
int varID, code, tabnum, tableID, datatype = -1;
char pstr[32];
char varname[CDI_MAX_NAME], varlongname[CDI_MAX_NAME], varstdname[CDI_MAX_NAME], varunits[CDI_MAX_NAME];
int natts;
......@@ -102,6 +103,28 @@ void partab(FILE *fp, int vlistID, int option)
}
}
if ( nvars > 1 )
{
datatype = vlistInqVarDatatype(vlistID, 0);
for ( varID = 1; varID < nvars; varID++ )
{
if ( datatype != vlistInqVarDatatype(vlistID, varID) )
{
datatype = -1;
break;
}
}
if ( datatype != -1 )
{
fprintf(fp, "&PARAMETER\n");
fprintf(fp, " name=_default_\n");
if ( datatype2str(datatype, pstr) == 0 )
fprintf(fp, " datatype=%s\n", pstr);
fprintf(fp, "/\n");
}
}
for ( varID = 0; varID < nvars; varID++ )
{
fprintf(fp, "&PARAMETER\n");
......@@ -119,20 +142,7 @@ void partab(FILE *fp, int vlistID, int option)
vlistInqVarLongname(vlistID, varID, varlongname);
/* printf("3>%s<\n", varname); */
vlistInqVarUnits(vlistID, varID, varunits);
prec = vlistInqVarDatatype(vlistID, varID);
if ( prec == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( prec > 0 && prec <= 32 ) sprintf(pstr, "P%d", prec);
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I32");
else if ( prec == DATATYPE_UINT8 ) strcpy(pstr, "U8");
else if ( prec == DATATYPE_UINT16 ) strcpy(pstr, "U16");
else if ( prec == DATATYPE_UINT32 ) strcpy(pstr, "U32");
else strcpy(pstr, "-1");
if ( code > 0 ) fprintf(fp, " code=%d\n", code);
if ( tabnum > 0 ) fprintf(fp, " table=%d\n", tabnum);
fprintf(fp, " name=%s\n", varname);
......@@ -143,7 +153,9 @@ void partab(FILE *fp, int vlistID, int option)
if ( strlen(varunits) )
fprintf(fp, " units=\"%s\"\n", varunits);
fprintf(fp, " datatype=%s\n", pstr);
if ( datatype == -1 )
if ( datatype2str(vlistInqVarDatatype(vlistID, varID), pstr) == 0 )
fprintf(fp, " datatype=%s\n", pstr);
if ( option == 2 ) printAtts(fp, vlistID, varID);
......
......@@ -335,13 +335,13 @@ void *Setpartab(void *argument)
}
if ( nml->entry[nml_datatype]->occ )
{
int dtype = -1;
int datatype = -1;
if ( strlen(datatype) == 3 )
{
if ( memcmp(datatype, "F32", 3) == 0 ) dtype = DATATYPE_FLT32;
else if ( memcmp(datatype, "F64", 3) == 0 ) dtype = DATATYPE_FLT64;
if ( memcmp(datatype, "F32", 3) == 0 ) datatype = DATATYPE_FLT32;
else if ( memcmp(datatype, "F64", 3) == 0 ) datatype = DATATYPE_FLT64;
}
if ( dtype != -1 ) vlistDefVarDatatype(vlistID2, varID, dtype);
if ( datatype != -1 ) vlistDefVarDatatype(vlistID2, varID, datatype);
}
if ( nml->entry[nml_missval]->occ )
{
......
......@@ -25,6 +25,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "util.h"
#include "printinfo.h"
......@@ -133,19 +134,7 @@ void *Sinfo(void *argument)
/* datatype */
datatype = vlistInqVarDatatype(vlistID, varID);
if ( datatype == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( datatype > 0 && datatype <= 32 ) sprintf(pstr, "P%d", datatype);
else if ( datatype == DATATYPE_CPX32 ) strcpy(pstr, "C32");
else if ( datatype == DATATYPE_CPX64 ) strcpy(pstr, "C64");
else if ( datatype == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( datatype == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( datatype == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( datatype == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( datatype == DATATYPE_INT32 ) strcpy(pstr, "I32");
else if ( datatype == DATATYPE_UINT8 ) strcpy(pstr, "U8");
else if ( datatype == DATATYPE_UINT16 ) strcpy(pstr, "U16");
else if ( datatype == DATATYPE_UINT32 ) strcpy(pstr, "U32");
else strcpy(pstr, "-1");
datatype2str(datatype, pstr);
fprintf(stdout, " %-3s", pstr);
......
......@@ -19,11 +19,13 @@
#include <string.h>
#include <ctype.h> /* tolower */
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "modules.h"
#include "util.h"
char *getProgname(char *string)
{
char *progname;
......@@ -311,3 +313,25 @@ void progressStatus(double offset, double refval, double curval)
fflush(stdout);
}
}
int datatype2str(int datatype, char *datatypestr)
{
int status = 0;
if ( datatype == DATATYPE_PACK ) strcpy(datatypestr, "P0");
else if ( datatype > 0 && datatype <= 32 ) sprintf(datatypestr, "P%d", datatype);
else if ( datatype == DATATYPE_CPX32 ) strcpy(datatypestr, "C32");
else if ( datatype == DATATYPE_CPX64 ) strcpy(datatypestr, "C64");
else if ( datatype == DATATYPE_FLT32 ) strcpy(datatypestr, "F32");
else if ( datatype == DATATYPE_FLT64 ) strcpy(datatypestr, "F64");
else if ( datatype == DATATYPE_INT8 ) strcpy(datatypestr, "I8");
else if ( datatype == DATATYPE_INT16 ) strcpy(datatypestr, "I16");
else if ( datatype == DATATYPE_INT32 ) strcpy(datatypestr, "I32");
else if ( datatype == DATATYPE_UINT8 ) strcpy(datatypestr, "U8");
else if ( datatype == DATATYPE_UINT16 ) strcpy(datatypestr, "U16");
else if ( datatype == DATATYPE_UINT32 ) strcpy(datatypestr, "U32");
else { strcpy(datatypestr, "-1"); status = -1;}
return (status);
}
......@@ -37,4 +37,7 @@ void progressStatus(double offset, double refval, double curval);
int fileExist(const char *filename);
int userFileOverwrite(const char *filename);
/* convert a CDI datatype to string */
int datatype2str(int datatype, char *datatypestr);
#endif /* _UTIL_H */
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