Commit 7422bdd4 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

change number type complex to datatype complex

parent f58ad0f5
......@@ -112,12 +112,18 @@ void usage(void)
static
void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
int datasize, int number, int nmiss, double missval, const double *data, int vardis)
int datasize, int datatype, int nmiss, double missval, const double *data, int vardis)
{
static int rec = 0;
int i, ivals = 0, imiss = 0;
int number;
double arrmean, arrmin, arrmax;
char vdatestr[32], vtimestr[32];
if ( datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
number = CDI_COMP;
else
number = CDI_REAL;
if ( ! rec )
{
......@@ -234,7 +240,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
char units[128];
double level;
char *modelptr, *instptr;
int prec, number;
int datatype;
int year, month, day, hour, minute, second;
char pstr[4];
char paramstr[32];
......@@ -291,28 +297,21 @@ void printShortinfo(int streamID, int vlistID, int vardis)
else
fprintf(stdout, "var ");
prec = vlistInqVarDatatype(vlistID, varID);
number = vlistInqVarNumber(vlistID, varID);
if ( number == CDI_REAL )
{
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");
}
else
{
if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "C32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "C64");
else strcpy(pstr, "-2");
}
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");
fprintf(stdout, " %-3s", pstr);
......@@ -773,6 +772,7 @@ int main(int argc, char *argv[])
double missval;
double level;
int nmiss;
int datatype;
int datasize = 0;
int streamID1 = CDI_UNDEFID;
int streamID2 = CDI_UNDEFID;
......@@ -783,7 +783,7 @@ int main(int argc, char *argv[])
int nrecs, nvars;
int levelID, levelsize;
int nts = 0;
int gridsize = 0, number;
int gridsize = 0;
int recID;
int tsID;
int ntsteps = 0;
......@@ -892,12 +892,13 @@ int main(int argc, char *argv[])
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, data, &nmiss);
gridID = vlistInqVarGrid(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID);
param = vlistInqVarParam(vlistID1, varID);
code = vlistInqVarCode(vlistID1, varID);
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
datatype = vlistInqVarDatatype(vlistID1, varID);
gridID = vlistInqVarGrid(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID);
param = vlistInqVarParam(vlistID1, varID);
code = vlistInqVarCode(vlistID1, varID);
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(code, tabnum, 255);
param2str(param, paramstr, sizeof(paramstr));
......@@ -911,10 +912,9 @@ int main(int argc, char *argv[])
gridsize = gridInqSize(gridID);
level = zaxisInqLevel(zaxisID, levelID);
missval = vlistInqVarMissval(vlistID1, varID);
number = vlistInqVarNumber(vlistID1, varID);
if ( Info )
printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
printInfo(gridtype, vdate, vtime, varname, level, gridsize, datatype, nmiss, missval, data, Vardis);
if ( fname2 )
{
......@@ -932,11 +932,12 @@ int main(int argc, char *argv[])
{
if ( vlistInqVarTime(vlistID1, varID) == TIME_CONSTANT && tsID > 0 ) continue;
gridID = vlistInqVarGrid(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID);
param = vlistInqVarParam(vlistID1, varID);
code = vlistInqVarCode(vlistID1, varID);
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
datatype = vlistInqVarDatatype(vlistID1, varID);
gridID = vlistInqVarGrid(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID);
param = vlistInqVarParam(vlistID1, varID);
code = vlistInqVarCode(vlistID1, varID);
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(code, tabnum, 255);
param2str(param, paramstr, sizeof(paramstr));
......@@ -951,7 +952,6 @@ int main(int argc, char *argv[])
gridtype = gridInqType(gridID);
gridsize = gridInqSize(gridID);
missval = vlistInqVarMissval(vlistID1, varID);
number = vlistInqVarNumber(vlistID1, varID);
levelsize = zaxisInqSize(zaxisID);
for ( levelID = 0; levelID < levelsize; levelID++ )
......@@ -960,7 +960,7 @@ int main(int argc, char *argv[])
streamReadVarSlice(streamID1, varID, levelID, data, &nmiss);
if ( Info )
printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
printInfo(gridtype, vdate, vtime, varname, level, gridsize, datatype, nmiss, missval, data, Vardis);
if ( fname2 )
streamWriteVarSlice(streamID2, varID, levelID, data, nmiss);
......
......@@ -85,6 +85,8 @@ extern "C" {
#define DATATYPE_PACK30 30
#define DATATYPE_PACK31 31
#define DATATYPE_PACK32 32
#define DATATYPE_CPX32 64
#define DATATYPE_CPX64 128
#define DATATYPE_FLT32 132
#define DATATYPE_FLT64 164
#define DATATYPE_INT8 208
......@@ -99,6 +101,7 @@ extern "C" {
#define DATATYPE_INT 251
#define DATATYPE_FLT 252
#define DATATYPE_TXT 253
#define DATATYPE_CPX 254
/* GRID types */
......@@ -376,12 +379,6 @@ void vlistDefVarDatatype(int vlistID, int varID, int datatype);
/* vlistInqVarDatatype: Get the data type of a Variable */
int vlistInqVarDatatype(int vlistID, int varID);
/* vlistDefVarNumber: Define the number type of a Variable */
void vlistDefVarNumber(int vlistID, int varID, int number);
/* vlistInqVarNumber: Get the number type of a Variable */
int vlistInqVarNumber(int vlistID, int varID);
void vlistDefVarInstitut(int vlistID, int varID, int instID);
int vlistInqVarInstitut(int vlistID, int varID);
void vlistDefVarModel(int vlistID, int varID, int modelID);
......
......@@ -429,7 +429,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
if ( prec < 0 ) prec = DATATYPE_PACK;
varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2,
prec, CDI_REAL, &varID, &levelID, numavg, ISEC1_LevelType, NULL, NULL, NULL);
prec, &varID, &levelID, numavg, ISEC1_LevelType, NULL, NULL, NULL);
(*record).varID = varID;
(*record).levelID = levelID;
......
......@@ -32,28 +32,41 @@ typedef struct {
} extcompvar_t;
static
int extInqDatatype(int prec)
int extInqDatatype(int prec, int number)
{
int datatype;
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
if ( number == 2 )
{
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_CPX64;
else datatype = DATATYPE_CPX32;
}
else
{
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
}
return (datatype);
}
static
int extDefDatatype(int datatype)
void extDefDatatype(int datatype, int *prec, int *number)
{
int prec;
if ( datatype != DATATYPE_FLT32 && datatype != DATATYPE_FLT64 )
if ( datatype != DATATYPE_FLT32 && datatype != DATATYPE_FLT64 &&
datatype != DATATYPE_CPX32 && datatype != DATATYPE_CPX64 )
datatype = DATATYPE_FLT32;
if ( datatype == DATATYPE_FLT64 ) prec = DOUBLE_PRECISION;
else prec = SINGLE_PRECISION;
if ( datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
*number = 2;
else
*number = 1;
return (prec);
if ( datatype == DATATYPE_FLT64 || datatype == DATATYPE_CPX64 )
*prec = DOUBLE_PRECISION;
else
*prec = SINGLE_PRECISION;
}
/* not used
......@@ -219,8 +232,7 @@ int extDefRecord(int streamID)
header[2] = streamptr->record->level;
header[3] = gridInqSize(gridID);
extp->prec = extDefDatatype(streamptr->record->prec);
extp->number = streamptr->record->number;
extDefDatatype(streamptr->record->prec, &extp->prec, &extp->number);
extDefHeader(extp, header);
......@@ -291,7 +303,7 @@ void extAddRecord(int streamID, int param, int level, int xysize,
leveltype = ZAXIS_GENERIC;
varAddRecord(recID, param, gridID, leveltype, 0, level, 0,
extInqDatatype(prec), number, &varID, &levelID, 0, 0, NULL, NULL, NULL);
extInqDatatype(prec, number), &varID, &levelID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID;
(*record).levelID = levelID;
......@@ -974,8 +986,7 @@ void extWriteVarDP(int streamID, int varID, const double *data)
header[1] = pnum;
header[3] = gridInqSize(gridID);
extp->prec = extDefDatatype(vlistInqVarDatatype(vlistID, varID));
extp->number = vlistInqVarNumber(vlistID, varID);
extDefDatatype(vlistInqVarDatatype(vlistID, varID), &extp->prec, &extp->number);
for ( levID = 0; levID < nlevs; levID++ )
{
......@@ -1023,8 +1034,7 @@ void extWriteVarSliceDP(int streamID, int varID, int levID, const double *data)
header[2] = (int) level;
header[3] = gridInqSize(gridID);
extp->prec = extDefDatatype(vlistInqVarDatatype(vlistID, varID));
extp->number = vlistInqVarNumber(vlistID, varID);
extDefDatatype(vlistInqVarDatatype(vlistID, varID), &extp->prec, &extp->number);
extDefHeader(extp, header);
extDefDataDP(extp, data);
......
......@@ -492,7 +492,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh,
// fprintf(stderr, "param %d name %s %s %s\n", param, name, longname, units);
varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2,
prec, CDI_REAL, &varID, &levelID, numavg, leveltype,
prec, &varID, &levelID, numavg, leveltype,
name, longname, units);
(*record).varID = varID;
......
......@@ -763,7 +763,7 @@ void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct,
datatype = iegInqDatatype(prec);
varAddRecord(recID, param, gridID, leveltype, lbounds, level1, level2,
datatype, CDI_REAL, &varID, &levelID, 0, 0, NULL, NULL, NULL);
datatype, &varID, &levelID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID;
(*record).levelID = levelID;
......
......@@ -120,7 +120,6 @@ typedef struct
int levelID;
int recid;
int prec;
int number;
int sec0[2];
int sec1[1024];
int sec2[4096];
......
......@@ -239,7 +239,6 @@ void streamDefRecord(int streamID, int varID, int levelID)
streamptr->record->gridID = gridID;
streamptr->record->zaxisID = zaxisID;
streamptr->record->prec = vlistInqVarDatatype(vlistID, varID);
streamptr->record->number = vlistInqVarNumber(vlistID, varID);
filetype = streamptr->filetype;
......
......@@ -313,7 +313,7 @@ void srvAddRecord(int streamID, int param, int level, int xsize, int ysize,
datatype = srvInqDatatype(prec);
varAddRecord(recID, param, gridID, leveltype, 0, level, 0,
datatype, CDI_REAL, &varID, &levelID, 0, 0, NULL, NULL, NULL);
datatype, &varID, &levelID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID;
(*record).levelID = levelID;
......
......@@ -30,7 +30,6 @@ typedef struct
{
int param;
int prec;
int number;
int timave;
int timaccu;
int gridID;
......@@ -64,7 +63,6 @@ void paramInitEntry(int varID, int param)
{
vartable[varID].param = param;
vartable[varID].prec = 0;
vartable[varID].number = CDI_REAL;
vartable[varID].timave = 0;
vartable[varID].timaccu = 0;
vartable[varID].gridID = UNDEFID;
......@@ -259,7 +257,7 @@ int paramNewEntry (int param)
void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
int level1, int level2, int prec, int number,
int level1, int level2, int prec,
int *pvarID, int *plevelID, int numavg, int ltype,
const char *name, const char *longname, const char *units)
{
......@@ -275,7 +273,6 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
nvars++;
varID = paramNewEntry(param);
if ( prec > vartable[varID].prec ) vartable[varID].prec = prec;
vartable[varID].number = number;
vartable[varID].gridID = gridID;
vartable[varID].zaxistype = zaxistype;
vartable[varID].ltype = ltype;
......@@ -343,7 +340,7 @@ void cdiGenVars(int streamID)
int varID, gridID, zaxisID, levelID;
int instID, modelID, tableID;
int param, nlevels, zaxistype, lindex, ltype;
int prec, number;
int prec;
int timave, timaccu;
int lbounds;
int ztype;
......@@ -369,7 +366,6 @@ void cdiGenVars(int streamID)
zaxistype = cdiDefaultLeveltype;
lbounds = vartable[varID].lbounds;
prec = vartable[varID].prec;
number = vartable[varID].number;
instID = vartable[varID].instID;
modelID = vartable[varID].modelID;
tableID = vartable[varID].tableID;
......@@ -452,7 +448,6 @@ void cdiGenVars(int streamID)
vlistDefVarParam(vlistID, varID, param);
vlistDefVarDatatype(vlistID, varID, prec);
vlistDefVarNumber(vlistID, varID, number);
vlistDefVarTimave(vlistID, varID, timave);
vlistDefVarTimaccu(vlistID, varID, timaccu);
vlistDefVarZtype(vlistID, varID, ztype);
......
......@@ -7,7 +7,7 @@
void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
int level1, int level2, int prec, int number,
int level1, int level2, int prec,
int *pvarID, int *plevelID, int numavg, int ltype,
const char *name, const char *longname, const char *units);
......
......@@ -990,20 +990,33 @@ int vlistNrecs(int vlistID)
int vlistNumber(int vlistID)
{
static char func[] = "vlistNumber";
int varID, number;
int varID, number, number2, datatype;
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlist_check_ptr(func, vlistptr);
number = vlistptr->vars[0].number;
datatype = vlistptr->vars[0].datatype;
if ( datatype== DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
number = CDI_COMP;
else
number = CDI_REAL;
for ( varID = 1; varID < vlistptr->nvars; varID++ )
if ( vlistptr->vars[varID].number != number )
{
number = CDI_BOTH;
break;
}
{
datatype = vlistptr->vars[varID].datatype;
if ( datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
number2 = CDI_COMP;
else
number2 = CDI_REAL;
if ( number2 != number )
{
number = CDI_BOTH;
break;
}
}
return (number);
}
......
......@@ -50,7 +50,6 @@ typedef struct
int zaxisID;
int timeID; /* TIME_VARIABLE or TIME_CONSTANT */
int datatype; /* DATATYPE_PACKX for GRIB data, else DATATYPE_FLT32 or DATATYPE_FLT64 */
int number; /* CDI_REAL_NUMBER or CDI_COMP_NUMBER */
int instID;
int modelID;
int tableID;
......
......@@ -22,7 +22,6 @@ static void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].param = CDI_UNDEFPARAM;
vlistptr->vars[varID].timeID = CDI_UNDEFID;
vlistptr->vars[varID].datatype = CDI_UNDEFID;
vlistptr->vars[varID].number = CDI_REAL;
vlistptr->vars[varID].timave = 0;
vlistptr->vars[varID].timaccu = 0;
vlistptr->vars[varID].gridID = CDI_UNDEFID;
......@@ -825,35 +824,6 @@ void vlistDefVarDatatype(int vlistID, int varID, int datatype)
}
int vlistInqVarNumber(int vlistID, int varID)
{
static char func[] = "vlistInqVarNumber";
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(func, vlistID, varID);
return (vlistptr->vars[varID].number);
}
void vlistDefVarNumber(int vlistID, int varID, int number)
{
static char func[] = "vlistDefVarNumber";
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(func, vlistID, varID);
if ( number != CDI_REAL && number != CDI_COMP )
Error(func, "Argument number = %d not allowed!", number);
vlistptr->vars[varID].number = number;
}
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
vlist_t *vlistptr;
......
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