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

app/cdi: added support for DATATYPE_CPX

parent e50f57ff
...@@ -331,7 +331,7 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -331,7 +331,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, "var "); fprintf(stdout, "var ");
datatype = vlistInqVarDatatype(vlistID, varID); datatype = vlistInqVarDatatype(vlistID, varID);
if ( datatype == DATATYPE_PACK ) strcpy(pstr, "P0"); if ( datatype == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( datatype > 0 && datatype <= 32 ) sprintf(pstr, "P%d", datatype); else if ( datatype > 0 && datatype <= 32 ) sprintf(pstr, "P%d", datatype);
else if ( datatype == DATATYPE_CPX32 ) strcpy(pstr, "C32"); else if ( datatype == DATATYPE_CPX32 ) strcpy(pstr, "C32");
...@@ -523,7 +523,7 @@ void setDefaultDataType(char *datatypestr) ...@@ -523,7 +523,7 @@ void setDefaultDataType(char *datatypestr)
{ {
static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1}; static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
int nbits = -1; int nbits = -1;
enum {D_UINT, D_INT, D_FLT}; enum {D_UINT, D_INT, D_FLT, D_CPX};
int dtype = -1; int dtype = -1;
if ( *datatypestr == 'i' || *datatypestr == 'I' ) if ( *datatypestr == 'i' || *datatypestr == 'I' )
...@@ -541,6 +541,11 @@ void setDefaultDataType(char *datatypestr) ...@@ -541,6 +541,11 @@ void setDefaultDataType(char *datatypestr)
dtype = D_FLT; dtype = D_FLT;
datatypestr++; datatypestr++;
} }
else if ( *datatypestr == 'c' || *datatypestr == 'C' )
{
dtype = D_CPX;
datatypestr++;
}
if ( isdigit((int) *datatypestr) ) if ( isdigit((int) *datatypestr) )
{ {
...@@ -564,7 +569,7 @@ void setDefaultDataType(char *datatypestr) ...@@ -564,7 +569,7 @@ void setDefaultDataType(char *datatypestr)
else else
{ {
fprintf(stderr, "Unsupported number of bits %d!\n", nbits); fprintf(stderr, "Unsupported number of bits %d!\n", nbits);
fprintf(stderr, "Use 32/64 for filetype nc, srv, ext, ieg and 1-32 for grb.\n"); fprintf(stderr, "Use I8/I16/I32/F32/F64 for nc/nc2/nc4/nc4c; F32/F64 for grb2/srv/ext/ieg; P1 - P24 for grb/grb2.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
...@@ -602,19 +607,36 @@ void setDefaultDataType(char *datatypestr) ...@@ -602,19 +607,36 @@ void setDefaultDataType(char *datatypestr)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
else if ( dtype == D_CPX )
{
if ( nbits == 32 ) DefaultDataType = DATATYPE_CPX32;
else if ( nbits == 64 ) DefaultDataType = DATATYPE_CPX64;
else
{
fprintf(stderr, "Unsupported number of bits = %d for datatype CPX!\n", nbits);
exit(EXIT_FAILURE);
}
}
} }
} }
if ( *datatypestr == 'l' || *datatypestr == 'L' ) if ( *datatypestr != 0 )
{
if ( IsBigendian() ) DefaultByteorder = CDI_LITTLEENDIAN;
datatypestr++;
}
if ( *datatypestr == 'b' || *datatypestr == 'B' )
{ {
if ( ! IsBigendian() ) DefaultByteorder = CDI_BIGENDIAN; if ( *datatypestr == 'l' || *datatypestr == 'L' )
datatypestr++; {
if ( IsBigendian() ) DefaultByteorder = CDI_LITTLEENDIAN;
datatypestr++;
}
else if ( *datatypestr == 'b' || *datatypestr == 'B' )
{
if ( ! IsBigendian() ) DefaultByteorder = CDI_BIGENDIAN;
datatypestr++;
}
else
{
fprintf(stderr, "Unsupported character in number of bytes: >%s< !\n", datatypestr);
exit(EXIT_FAILURE);
}
} }
} }
...@@ -655,18 +677,18 @@ void setDefaultFileType(char *filetypestr) ...@@ -655,18 +677,18 @@ void setDefaultFileType(char *filetypestr)
fprintf(stderr, "Unexpected character >%c< in file type >%s<!\n", *ftstr, filetypestr); fprintf(stderr, "Unexpected character >%c< in file type >%s<!\n", *ftstr, filetypestr);
fprintf(stderr, "Use format[_nbits] with:\n"); fprintf(stderr, "Use format[_nbits] with:\n");
fprintf(stderr, " format = grb, grb2, nc, nc2, nc4, nc4c, srv, ext or ieg\n"); fprintf(stderr, " format = grb, grb2, nc, nc2, nc4, nc4c, srv, ext or ieg\n");
fprintf(stderr, " nbits = 32/64 for nc/nc2/nc4/nc4c/srv/ext/ieg; 1 - 24 for grb/grb2\n"); fprintf(stderr, " nbits = 32/64 for grb2/nc/nc2/nc4/nc4c/srv/ext/ieg; 1 - 24 for grb/grb2\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} }
} }
static
int handle_error(int cdiErrno, const char *fmt, ...) int handle_error(int cdiErrno, const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printf("\n"); printf("\n");
...@@ -680,7 +702,7 @@ int handle_error(int cdiErrno, const char *fmt, ...) ...@@ -680,7 +702,7 @@ int handle_error(int cdiErrno, const char *fmt, ...)
return (cdiErrno); return (cdiErrno);
} }
static
void defineCompress(const char *arg) void defineCompress(const char *arg)
{ {
size_t len = strlen(arg); size_t len = strlen(arg);
...@@ -788,10 +810,7 @@ int main(int argc, char *argv[]) ...@@ -788,10 +810,7 @@ int main(int argc, char *argv[])
if ( optind < argc ) fname1 = argv[optind++]; if ( optind < argc ) fname1 = argv[optind++];
if ( optind < argc ) fname2 = argv[optind++]; if ( optind < argc ) fname2 = argv[optind++];
if ( optind < argc ) if ( optind < argc ) fprintf(stderr, "optind: %d argc: %d\n", optind, argc);
{
fprintf(stderr, "optind: %d argc: %d\n", optind, argc);
}
if ( Debug || Version ) version(); if ( Debug || Version ) version();
...@@ -859,7 +878,7 @@ int main(int argc, char *argv[]) ...@@ -859,7 +878,7 @@ int main(int argc, char *argv[])
if ( Debug ) fprintf(stderr, "ntsteps = %d\n", ntsteps); if ( Debug ) fprintf(stderr, "ntsteps = %d\n", ntsteps);
if ( fname2 ) vlistID2 = vlistDuplicate(vlistID1); if ( fname2 ) vlistID2 = vlistDuplicate(vlistID1);
for ( varID = 0; varID < nvars; varID++) for ( varID = 0; varID < nvars; varID++)
{ {
gridID = vlistInqVarGrid(vlistID1, varID); gridID = vlistInqVarGrid(vlistID1, varID);
...@@ -897,7 +916,7 @@ int main(int argc, char *argv[]) ...@@ -897,7 +916,7 @@ int main(int argc, char *argv[])
if ( otableID == CDI_UNDEFID ) otableID = itableID; if ( otableID == CDI_UNDEFID ) otableID = itableID;
} }
if ( vlistNumber(vlistID1) != CDI_REAL ) datasize *= 2; if ( vlistNumber(vlistID1) != CDI_REAL ) datasize *= 2;
data = (double *) malloc(datasize*sizeof(double)); data = (double *) malloc(datasize*sizeof(double));
...@@ -940,7 +959,7 @@ int main(int argc, char *argv[]) ...@@ -940,7 +959,7 @@ int main(int argc, char *argv[])
gridID = vlistInqVarGrid(vlistID1, varID); gridID = vlistInqVarGrid(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID); zaxisID = vlistInqVarZaxis(vlistID1, varID);
param = vlistInqVarParam(vlistID1, varID); param = vlistInqVarParam(vlistID1, varID);
cdiParamToString(param, paramstr, sizeof(paramstr)); cdiParamToString(param, paramstr, sizeof(paramstr));
if ( Vardis ) vlistInqVarName(vlistID1, varID, varname); if ( Vardis ) vlistInqVarName(vlistID1, varID, varname);
...@@ -953,7 +972,7 @@ int main(int argc, char *argv[]) ...@@ -953,7 +972,7 @@ int main(int argc, char *argv[])
gridsize = gridInqSize(gridID); gridsize = gridInqSize(gridID);
level = zaxisInqLevel(zaxisID, levelID); level = zaxisInqLevel(zaxisID, levelID);
missval = vlistInqVarMissval(vlistID1, varID); missval = vlistInqVarMissval(vlistID1, varID);
if ( Info ) if ( Info )
printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis); printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
...@@ -1025,12 +1044,3 @@ int main(int argc, char *argv[]) ...@@ -1025,12 +1044,3 @@ int main(int argc, char *argv[])
return (0); return (0);
} }
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
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