Commit 12015a1d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent c1488fdc
...@@ -252,9 +252,7 @@ void printInfo(int vdate, int vtime, char *varname, double level, ...@@ -252,9 +252,7 @@ void printInfo(int vdate, int vtime, char *varname, double level,
else else
{ {
int nvals_r = 0, nvals_i = 0; int nvals_r = 0, nvals_i = 0;
double arrsum_r, arrsum_i, arrmean_r = 0, arrmean_i = 0; double arrsum_r = 0, arrsum_i = 0, arrmean_r = 0, arrmean_i = 0;
arrsum_r = 0;
arrsum_i = 0;
for ( i = 0; i < datasize; i++ ) for ( i = 0; i < datasize; i++ )
{ {
...@@ -331,16 +329,8 @@ static ...@@ -331,16 +329,8 @@ static
void printShortinfo(int streamID, int vlistID, int vardis) void printShortinfo(int streamID, int vlistID, int vardis)
{ {
int varID; int varID;
int gridsize = 0;
int gridID, zaxisID, param;
int vdate, vtime;
int ntsteps;
int levelsize;
int tsteptype, taxisID;
char tmpname[CDI_MAX_NAME]; char tmpname[CDI_MAX_NAME];
char varname[CDI_MAX_NAME]; char varname[CDI_MAX_NAME];
const char *modelptr, *instptr;
int datatype;
int year, month, day, hour, minute, second; int year, month, day, hour, minute, second;
char pstr[4]; char pstr[4];
char paramstr[32]; char paramstr[32];
...@@ -365,28 +355,28 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -365,28 +355,28 @@ void printShortinfo(int streamID, int vlistID, int vardis)
for ( varID = 0; varID < nvars; varID++ ) for ( varID = 0; varID < nvars; varID++ )
{ {
param = vlistInqVarParam(vlistID, varID); int param = vlistInqVarParam(vlistID, varID);
gridID = vlistInqVarGrid(vlistID, varID); int gridID = vlistInqVarGrid(vlistID, varID);
zaxisID = vlistInqVarZaxis(vlistID, varID); int zaxisID = vlistInqVarZaxis(vlistID, varID);
fprintf(stdout, "%6d : ", varID + 1); fprintf(stdout, "%6d : ", varID + 1);
/* institute info */ /* institute info */
instptr = institutInqNamePtr(vlistInqVarInstitut(vlistID, varID)); const char *instptr = institutInqNamePtr(vlistInqVarInstitut(vlistID, varID));
strcpy(tmpname, "unknown"); strcpy(tmpname, "unknown");
if ( instptr ) strncpy(tmpname, instptr, CDI_MAX_NAME); if ( instptr ) strncpy(tmpname, instptr, CDI_MAX_NAME);
limit_string_length(tmpname, CDI_MAX_NAME); limit_string_length(tmpname, CDI_MAX_NAME);
fprintf(stdout, "%-8s ", tmpname); fprintf(stdout, "%-8s ", tmpname);
/* source info */ /* source info */
modelptr = modelInqNamePtr(vlistInqVarModel(vlistID, varID)); const char *modelptr = modelInqNamePtr(vlistInqVarModel(vlistID, varID));
strcpy(tmpname, "unknown"); strcpy(tmpname, "unknown");
if ( modelptr ) strncpy(tmpname, modelptr, CDI_MAX_NAME); if ( modelptr ) strncpy(tmpname, modelptr, CDI_MAX_NAME);
limit_string_length(tmpname, CDI_MAX_NAME); limit_string_length(tmpname, CDI_MAX_NAME);
fprintf(stdout, "%-8s ", tmpname); fprintf(stdout, "%-8s ", tmpname);
/* tsteptype */ /* tsteptype */
tsteptype = vlistInqVarTsteptype(vlistID, varID); int tsteptype = vlistInqVarTsteptype(vlistID, varID);
if ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s ", "constant"); if ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s ", "constant");
else if ( tsteptype == TSTEP_INSTANT ) fprintf(stdout, "%-8s ", "instant"); else if ( tsteptype == TSTEP_INSTANT ) fprintf(stdout, "%-8s ", "instant");
else if ( tsteptype == TSTEP_INSTANT2 ) fprintf(stdout, "%-8s ", "instant"); else if ( tsteptype == TSTEP_INSTANT2 ) fprintf(stdout, "%-8s ", "instant");
...@@ -408,17 +398,17 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -408,17 +398,17 @@ void printShortinfo(int streamID, int vlistID, int vardis)
} }
/* layer info */ /* layer info */
levelsize = zaxisInqSize(zaxisID); int levelsize = zaxisInqSize(zaxisID);
fprintf(stdout, "%6d ", levelsize); fprintf(stdout, "%6d ", levelsize);
fprintf(stdout, "%3d ", vlistZaxisIndex(vlistID, zaxisID) + 1); fprintf(stdout, "%3d ", vlistZaxisIndex(vlistID, zaxisID) + 1);
/* grid info */ /* grid info */
gridsize = gridInqSize(gridID); int gridsize = gridInqSize(gridID);
fprintf(stdout, "%9d ", gridsize); fprintf(stdout, "%9d ", gridsize);
fprintf(stdout, "%3d ", vlistGridIndex(vlistID, gridID) + 1); fprintf(stdout, "%3d ", vlistGridIndex(vlistID, gridID) + 1);
/* datatype */ /* datatype */
datatype = vlistInqVarDatatype(vlistID, varID); int datatype = vlistInqVarDatatype(vlistID, varID);
if ( datatype == CDI_DATATYPE_PACK ) strcpy(pstr, "P0"); if ( datatype == CDI_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 == CDI_DATATYPE_CPX32 ) strcpy(pstr, "C32"); else if ( datatype == CDI_DATATYPE_CPX32 ) strcpy(pstr, "C32");
...@@ -445,7 +435,7 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -445,7 +435,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
cdiParamToString(param, paramstr, sizeof(paramstr)); cdiParamToString(param, paramstr, sizeof(paramstr));
if (vardis) if ( vardis )
{ {
vlistInqVarName(vlistID, varID, varname); vlistInqVarName(vlistID, varID, varname);
fprintf(stdout, "%-14s", varname); fprintf(stdout, "%-14s", varname);
...@@ -474,8 +464,8 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -474,8 +464,8 @@ void printShortinfo(int streamID, int vlistID, int vardis)
printSubtypeInfo(vlistID); printSubtypeInfo(vlistID);
} }
taxisID = vlistInqTaxis(vlistID); int taxisID = vlistInqTaxis(vlistID);
ntsteps = vlistNtsteps(vlistID); int ntsteps = vlistNtsteps(vlistID);
if ( ntsteps != 0 ) if ( ntsteps != 0 )
{ {
...@@ -488,10 +478,8 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -488,10 +478,8 @@ void printShortinfo(int streamID, int vlistID, int vardis)
{ {
if ( taxisInqType(taxisID) == TAXIS_RELATIVE ) if ( taxisInqType(taxisID) == TAXIS_RELATIVE )
{ {
int calendar, tunits; int vdate = taxisInqRdate(taxisID);
int vtime = taxisInqRtime(taxisID);
vdate = taxisInqRdate(taxisID);
vtime = taxisInqRtime(taxisID);
cdiDecodeDate(vdate, &year, &month, &day); cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second); cdiDecodeTime(vtime, &hour, &minute, &second);
...@@ -499,10 +487,10 @@ void printShortinfo(int streamID, int vlistID, int vardis) ...@@ -499,10 +487,10 @@ void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, " RefTime = %4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", fprintf(stdout, " RefTime = %4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
year, month, day, hour, minute, second); year, month, day, hour, minute, second);
tunits = taxisInqTunit(taxisID); int tunits = taxisInqTunit(taxisID);
if ( tunits != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(tunits)); if ( tunits != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(tunits));
calendar = taxisInqCalendar(taxisID); int calendar = taxisInqCalendar(taxisID);
if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar)); if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar));
if ( taxisHasBounds(taxisID) ) if ( taxisHasBounds(taxisID) )
...@@ -703,7 +691,7 @@ int handle_error(int cdiErrno, const char *fmt, ...) ...@@ -703,7 +691,7 @@ int handle_error(int cdiErrno, const char *fmt, ...)
fprintf(stderr, "%s\n", cdiStringError(cdiErrno)); fprintf(stderr, "%s\n", cdiStringError(cdiErrno));
return (cdiErrno); return cdiErrno;
} }
static static
...@@ -844,33 +832,25 @@ int main(int argc, char *argv[]) ...@@ -844,33 +832,25 @@ int main(int argc, char *argv[])
if ( fname1 ) if ( fname1 )
{ {
double *data = NULL;
double missval;
double level;
int nmiss; int nmiss;
int number; int number;
int datasize = 0; int datasize = 0;
int streamID1 = CDI_UNDEFID;
int streamID2 = CDI_UNDEFID; int streamID2 = CDI_UNDEFID;
int filetype; int filetype;
int gridID, zaxisID; int gridID, zaxisID;
int param; int param;
int vdate, vtime; int nrecs;
int nrecs, nvars;
int levelID, levelsize; int levelID, levelsize;
int nts = 0; int nts = 0;
int gridsize = 0; int gridsize = 0;
int recID; int recID;
int tsID; int taxisID2 = CDI_UNDEFID;
int ntsteps = 0; int vlistID2 = CDI_UNDEFID;
int taxisID1, taxisID2 = CDI_UNDEFID;
int vlistID1, vlistID2 = CDI_UNDEFID;
streamID1 = streamOpenRead(fname1); int streamID1 = streamOpenRead(fname1);
if ( streamID1 < 0 ) if ( streamID1 < 0 ) return handle_error(streamID1, "Open failed on %s", fname1);
return (handle_error(streamID1, "Open failed on %s", fname1));
vlistID1 = streamInqVlist(streamID1); int vlistID1 = streamInqVlist(streamID1);
if ( Longinfo ) if ( Longinfo )
{ {
...@@ -878,17 +858,16 @@ int main(int argc, char *argv[]) ...@@ -878,17 +858,16 @@ int main(int argc, char *argv[])
vlistPrint(vlistID1); vlistPrint(vlistID1);
ngrids = vlistNgrids(vlistID1); ngrids = vlistNgrids(vlistID1);
nzaxis = vlistNzaxis(vlistID1); nzaxis = vlistNzaxis(vlistID1);
for ( gridID = 0; gridID < ngrids; gridID++ ) gridPrint(gridID, gridID, 1); for ( int index = 0; index < ngrids; index++ ) gridPrint(vlistGrid(vlistID1, index), index, 1);
for ( zaxisID = 0; zaxisID < nzaxis; zaxisID++ ) zaxisPrint(zaxisID, zaxisID); for ( int index = 0; index < nzaxis; index++ ) zaxisPrint(vlistZaxis(vlistID1, index), index);
} }
nvars = vlistNvars(vlistID1); int nvars = vlistNvars(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1); int taxisID1 = vlistInqTaxis(vlistID1);
ntsteps = vlistNtsteps(vlistID1); int ntsteps = vlistNtsteps(vlistID1);
if (Debug) if ( Debug )
fprintf(stderr, "nvars = %d\n" fprintf(stderr, "nvars = %d\nntsteps = %d\n", nvars, ntsteps);
"ntsteps = %d\n", nvars, ntsteps);
if ( fname2 ) if ( fname2 )
{ {
...@@ -919,7 +898,7 @@ int main(int argc, char *argv[]) ...@@ -919,7 +898,7 @@ int main(int argc, char *argv[])
streamID2 = streamOpenWrite(fname2, filetype); streamID2 = streamOpenWrite(fname2, filetype);
if ( streamID2 < 0 ) if ( streamID2 < 0 )
return (handle_error(streamID2, "Open failed on %s", fname2)); return handle_error(streamID2, "Open failed on %s", fname2);
if ( DefaultByteorder != CDI_UNDEFID ) if ( DefaultByteorder != CDI_UNDEFID )
streamDefByteorder(streamID2, DefaultByteorder); streamDefByteorder(streamID2, DefaultByteorder);
...@@ -936,14 +915,13 @@ int main(int argc, char *argv[]) ...@@ -936,14 +915,13 @@ int main(int argc, char *argv[])
} }
if ( vlistNumber(vlistID1) != CDI_REAL ) datasize *= 2; if ( vlistNumber(vlistID1) != CDI_REAL ) datasize *= 2;
data = (double *) malloc((size_t)datasize * sizeof (double)); double *data = (double *) malloc((size_t)datasize * sizeof (double));
/* /*
nts = cdiInqTimeSize(streamID1); nts = cdiInqTimeSize(streamID1);
*/ */
if (Debug) if ( Debug )
printf("nts = %d streamID1 = %d, streamID2 = %d\n", printf("nts = %d streamID1 = %d, streamID2 = %d\n", nts, streamID1, streamID2);
nts, streamID1, streamID2);
if ( Shortinfo ) if ( Shortinfo )
{ {
...@@ -951,7 +929,7 @@ int main(int argc, char *argv[]) ...@@ -951,7 +929,7 @@ int main(int argc, char *argv[])
printShortinfo(streamID1, vlistID1, Vardis); printShortinfo(streamID1, vlistID1, Vardis);
} }
tsID = 0; int tsID = 0;
if ( Info || fname2 ) if ( Info || fname2 )
while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 ) while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 )
{ {
...@@ -960,8 +938,8 @@ int main(int argc, char *argv[]) ...@@ -960,8 +938,8 @@ int main(int argc, char *argv[])
taxisCopyTimestep(taxisID2, taxisID1); taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID); streamDefTimestep(streamID2, tsID);
} }
vdate = taxisInqVdate(taxisID1); int vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1); int vtime = taxisInqVtime(taxisID1);
if ( Debug ) if ( Debug )
fprintf(stdout, "tsID = %d nrecs = %d date = %d time = %d\n", tsID, nrecs, vdate, vtime); fprintf(stdout, "tsID = %d nrecs = %d date = %d time = %d\n", tsID, nrecs, vdate, vtime);
...@@ -987,8 +965,8 @@ int main(int argc, char *argv[]) ...@@ -987,8 +965,8 @@ int main(int argc, char *argv[])
varID, param, gridID, zaxisID, levelID); varID, param, gridID, zaxisID, levelID);
*/ */
gridsize = gridInqSize(gridID); gridsize = gridInqSize(gridID);
level = zaxisInqLevels(zaxisID, NULL) ? zaxisInqLevel(zaxisID, levelID) : levelID+1; double level = zaxisInqLevels(zaxisID, NULL) ? zaxisInqLevel(zaxisID, levelID) : levelID+1;
missval = vlistInqVarMissval(vlistID1, varID); double missval = vlistInqVarMissval(vlistID1, varID);
if ( Info ) if ( Info )
printInfo(vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis); printInfo(vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
...@@ -1024,12 +1002,12 @@ int main(int argc, char *argv[]) ...@@ -1024,12 +1002,12 @@ int main(int argc, char *argv[])
varID, param, gridID, zaxisID); varID, param, gridID, zaxisID);
gridsize = gridInqSize(gridID); gridsize = gridInqSize(gridID);
missval = vlistInqVarMissval(vlistID1, varID); double missval = vlistInqVarMissval(vlistID1, varID);
levelsize = zaxisInqSize(zaxisID); levelsize = zaxisInqSize(zaxisID);
for ( levelID = 0; levelID < levelsize; levelID++ ) for ( levelID = 0; levelID < levelsize; levelID++ )
{ {
level = zaxisInqLevels(zaxisID, NULL) ? zaxisInqLevel(zaxisID, levelID) : levelID+1; double level = zaxisInqLevels(zaxisID, NULL) ? zaxisInqLevel(zaxisID, levelID) : levelID+1;
streamReadVarSlice(streamID1, varID, levelID, data, &nmiss); streamReadVarSlice(streamID1, varID, levelID, data, &nmiss);
if ( Info ) if ( Info )
...@@ -1040,6 +1018,7 @@ int main(int argc, char *argv[]) ...@@ -1040,6 +1018,7 @@ int main(int argc, char *argv[])
} }
} }
} }
tsID++; tsID++;
} }
...@@ -1059,7 +1038,7 @@ int main(int argc, char *argv[]) ...@@ -1059,7 +1038,7 @@ int main(int argc, char *argv[])
if ( wTable ) if ( wTable )
tableWrite(wTable, itableID); tableWrite(wTable, itableID);
return (0); return 0;
} }
/* /*
* Local Variables: * Local Variables:
......
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