Commit 4216319b authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Merge declaration and initialization.

parent c194fc8d
......@@ -394,9 +394,7 @@ The valid CDI file format types are @func{FILETYPE_GRB}, @func{FILETYPE_GRB2}, @
*/
int streamInqFiletype(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -440,9 +438,7 @@ with the file format type @func{FILETYPE_SRV}, @func{FILETYPE_EXT} or @func{FILE
void streamDefByteorder(int streamID, int byteorder)
{
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -507,9 +503,7 @@ The valid CDI byte order types are @func{CDI_BIGENDIAN} and @func{CDI_LITTLEENDI
*/
int streamInqByteorder(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -532,9 +526,7 @@ char *streamFilesuffix(int filetype)
char *streamFilename(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -546,9 +538,7 @@ int cdiInqTimeSize(int streamID)
{
int ntsteps;
int tsID = 0, nrecs;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -949,7 +939,6 @@ int streamOpenRead(const char *filenames)
int num_fnames = 0;
char *fnames[MAX_FNAMES];
const char *filename;
stream_t *streamptr = NULL;
cdiInitialize();
......@@ -972,7 +961,7 @@ int streamOpenRead(const char *filenames)
if ( streamID >= 0 )
{
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
streamptr->byteorder = byteorder;
if ( num_fnames > 0 )
......@@ -991,21 +980,19 @@ int streamOpenRead(const char *filenames)
int streamOpenAppend(const char *filename)
{
int filetype, byteorder;
int streamID;
stream_t *streamptr;
int byteorder;
cdiInitialize();
filetype = getFiletype(filename, &byteorder);
int filetype = getFiletype(filename, &byteorder);
if ( filetype < 0 ) return (filetype);
streamID = streamOpenA(filename, "a", filetype);
int streamID = streamOpenA(filename, "a", filetype);
if ( streamID >= 0 )
{
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
streamptr->byteorder = byteorder;
}
......@@ -1143,9 +1130,7 @@ void streamClose(int streamID)
{
int index;
int vlistID;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -1267,9 +1252,7 @@ The function @func{streamSync} offers a way to synchronize the disk copy of a da
*/
void streamSync(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -1281,21 +1264,16 @@ void streamSync(int streamID)
int cdiStreamDefTimestep_(stream_t *streamptr, int tsID)
{
int newtsID;
int taxisID;
int vlistID;
int time_is_varying;
taxis_t *taxisptr1;
taxis_t *taxisptr2;
if ( CDI_Debug )
Message("streamID = %d tsID = %d", streamptr->self, tsID);
stream_check_ptr(__func__, streamptr);
vlistID = streamptr->vlistID;
int vlistID = streamptr->vlistID;
time_is_varying = vlistHasTime(vlistID);
int time_is_varying = vlistHasTime(vlistID);
if ( time_is_varying )
{
......@@ -1308,7 +1286,7 @@ int cdiStreamDefTimestep_(stream_t *streamptr, int tsID)
}
}
newtsID = tstepsNewEntry(streamptr);
int newtsID = tstepsNewEntry(streamptr);
if ( tsID != newtsID )
Error("Internal problem: tsID = %d newtsID = %d", tsID, newtsID);
......@@ -1317,8 +1295,8 @@ int cdiStreamDefTimestep_(stream_t *streamptr, int tsID)
if ( time_is_varying )
{
taxisptr1 = taxisPtr(taxisID);
taxisptr2 = &streamptr->tsteps[tsID].taxis;
taxis_t *taxisptr1 = taxisPtr(taxisID);
taxis_t *taxisptr2 = &streamptr->tsteps[tsID].taxis;
ptaxisCopy(taxisptr2, taxisptr1);
if ( tsID == 0 )
{
......@@ -1400,17 +1378,13 @@ The function @func{streamInqTimestep} returns the time step of a stream.
*/
int streamInqTimestep(int streamID, int tsID)
{
int filetype;
int nrecs = 0;
int taxisID;
int vlistID;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
vlistID = streamptr->vlistID;
int vlistID = streamptr->vlistID;
if ( tsID < streamptr->rtsteps )
{
......@@ -1430,7 +1404,7 @@ int streamInqTimestep(int streamID, int tsID)
return (0);
}
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
if ( CDI_Debug )
Message("streamID = %d tsID = %d filetype = %d", streamID, tsID, filetype);
......@@ -1511,19 +1485,16 @@ from an open dataset.
*/
void streamReadVar(int streamID, int varID, double *data, int *nmiss)
{
int filetype;
stream_t *streamptr;
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
check_parg(data);
check_parg(nmiss);
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
*nmiss = 0;
......@@ -1607,21 +1578,18 @@ void
cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data,
int nmiss)
{
int filetype;
stream_t *streamptr;
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
check_parg(data);
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
// check taxis
if ( streamptr->curTsID == CDI_UNDEFID ) streamDefTimestep(streamID, 0);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
switch (filetype)
{
......@@ -1722,19 +1690,16 @@ from an open dataset.
*/
void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss)
{
int filetype;
stream_t *streamptr;
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
check_parg(data);
check_parg(nmiss);
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
*nmiss = 0;
......@@ -1791,21 +1756,18 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
static
void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss)
{
int filetype;
stream_t *streamptr;
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
check_parg(data);
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
// check taxis
if ( streamptr->curTsID == CDI_UNDEFID ) streamDefTimestep(streamID, 0);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
switch (filetype)
{
......@@ -1924,18 +1886,15 @@ void
cdiStreamwriteVarChunk_(int streamID, int varID, int memtype,
const int rect[][2], const void *data, int nmiss)
{
int filetype;
stream_t *streamptr;
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID);
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
// streamDefineTaxis(streamID);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
switch (filetype)
{
......@@ -1975,27 +1934,13 @@ cdiStreamwriteVarChunk_(int streamID, int varID, int memtype,
void streamWriteContents(int streamID, char *cname)
{
FILE *cnp;
int tsID, recID, varID, levelID;
long recsize;
int nrecs, nvars;
int code, gridID, zaxisID, tsteptype, datatype;
int ngrids;
int filetype, gridtype;
int xsize, ysize;
int date, time;
int i;
off_t recpos, position;
int vlistID;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
vlistID = streamptr->vlistID;
int vlistID = streamptr->vlistID;
cnp = fopen(cname, "w");
FILE *cnp = fopen(cname, "w");
if ( cnp == NULL ) SysError(cname);
......@@ -2003,19 +1948,19 @@ void streamWriteContents(int streamID, char *cname)
fprintf(cnp, "#\n");
fprintf(cnp, "filename: %s\n", streamptr->filename);
filetype = streamptr->filetype;
int filetype = streamptr->filetype;
fprintf(cnp, "filetype: %s\n", strfiletype(filetype));
fprintf(cnp, "#\n");
fprintf(cnp, "#grids:\n");
ngrids = vlistNgrids(vlistID);
for ( i = 0; i < ngrids; i++ )
int ngrids = vlistNgrids(vlistID);
for ( int i = 0; i < ngrids; i++ )
{
gridID = vlistGrid(vlistID, i);
gridtype = gridInqType(gridID);
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
int gridID = vlistGrid(vlistID, i);
int gridtype = gridInqType(gridID);
int xsize = gridInqXsize(gridID);
int ysize = gridInqYsize(gridID);
fprintf(cnp, "%4d:%4d:%4d:%4d\n", i+1, gridtype, xsize, ysize);
}
......@@ -2023,14 +1968,14 @@ void streamWriteContents(int streamID, char *cname)
fprintf(cnp, "varID:code:gridID:zaxisID:tsteptype:datatype\n");
nvars = vlistNvars(vlistID);
for ( varID = 0; varID < nvars; varID++ )
int nvars = vlistNvars(vlistID);
for ( int varID = 0; varID < nvars; varID++ )
{
code = vlistInqVarCode(vlistID, varID);
gridID = vlistInqVarGrid(vlistID, varID);
zaxisID = vlistInqVarZaxis(vlistID, varID);
tsteptype = vlistInqVarTsteptype(vlistID, varID);
datatype = vlistInqVarDatatype(vlistID, varID);
int code = vlistInqVarCode(vlistID, varID);
int gridID = vlistInqVarGrid(vlistID, varID);
int zaxisID = vlistInqVarZaxis(vlistID, varID);
int tsteptype = vlistInqVarTsteptype(vlistID, varID);
int datatype = vlistInqVarDatatype(vlistID, varID);
fprintf(cnp, "%4d:%4d:%4d:%4d:%4d:%4d:\n",
varID+1, code, gridID, zaxisID, tsteptype, datatype);
}
......@@ -2039,13 +1984,13 @@ void streamWriteContents(int streamID, char *cname)
fprintf(cnp, "tsID:nrecs:date:time\n");
tsID = 0;
int tsID = 0;
while (1)
{
nrecs = streamptr->tsteps[tsID].nallrecs;
date = streamptr->tsteps[tsID].taxis.vdate;
time = streamptr->tsteps[tsID].taxis.vtime;
position = streamptr->tsteps[tsID].position;
int nrecs = streamptr->tsteps[tsID].nallrecs;
int date = streamptr->tsteps[tsID].taxis.vdate;
int time = streamptr->tsteps[tsID].taxis.vtime;
off_t position = streamptr->tsteps[tsID].position;
fprintf(cnp, "%4d:%4d:%4d:%4d:%ld\n",
tsID, nrecs, date, time, (long) position);
......@@ -2063,13 +2008,13 @@ void streamWriteContents(int streamID, char *cname)
tsID = 0;
while (1)
{
nrecs = streamptr->tsteps[tsID].nallrecs;
for ( recID = 0; recID < nrecs; recID++ )
int nrecs = streamptr->tsteps[tsID].nallrecs;
for ( int recID = 0; recID < nrecs; recID++ )
{
varID = streamptr->tsteps[tsID].records[recID].varID;
levelID = streamptr->tsteps[tsID].records[recID].levelID;
recpos = streamptr->tsteps[tsID].records[recID].position;
recsize = (long)streamptr->tsteps[tsID].records[recID].size;
int varID = streamptr->tsteps[tsID].records[recID].varID;
int levelID = streamptr->tsteps[tsID].records[recID].levelID;
off_t recpos = streamptr->tsteps[tsID].records[recID].position;
long recsize = (long)streamptr->tsteps[tsID].records[recID].size;
fprintf(cnp, "%4d:%4d:%4d:%4d:%4ld:%ld\n",
tsID, recID, varID, levelID, recsize, (long) recpos);
}
......@@ -2086,15 +2031,9 @@ void streamWriteContents(int streamID, char *cname)
void cdiDefTableID(int tableID)
{
int modelID, instID;
cdiDefaultTableID = tableID;
modelID = tableInqModel(tableID);
cdiDefaultModelID = modelID;
instID = modelInqInstitut(modelID);
cdiDefaultInstID = instID;
int modelID = cdiDefaultModelID = tableInqModel(tableID);
cdiDefaultInstID = modelInqInstitut(modelID);
}
......@@ -2128,9 +2067,7 @@ void cdiPrintVersion(void)
int streamNtsteps(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -2140,9 +2077,7 @@ int streamNtsteps(int streamID)
off_t streamNvals(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -2202,9 +2137,7 @@ The function @func{streamInqVlist} returns the variable list of a stream.
*/
int streamInqVlist(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -2214,9 +2147,7 @@ int streamInqVlist(int streamID)
int streamInqVlistIDorig(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -2262,9 +2193,7 @@ void streamDefCompLevel(int streamID, int complevel)
int streamInqCompType(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......@@ -2274,9 +2203,7 @@ int streamInqCompType(int streamID)
int streamInqCompLevel(int streamID)
{
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
......
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