Commit 6eab6f82 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent 6ea83727
......@@ -28,26 +28,19 @@
static
int read_cmor_table(const char *filename)
{
void *kvlist;
int nlists, listID;
int nelements, elemID;
const char *listname;
const char *ename;
const char *evalue;
kvlist = kvlParseFile(filename);
nlists = kvlGetNumLists(kvlist);
void *kvlist = kvlParseFile(filename);
int nlists = kvlGetNumLists(kvlist);
printf("# Number of lists: %d\n", nlists);
for ( listID = 0; listID < nlists; ++listID )
for ( int listID = 0; listID < nlists; ++listID )
{
listname = kvlGetListName(kvlist, listID);
nelements = kvlGetListNumElements(kvlist, listID);
const char *listname = kvlGetListName(kvlist, listID);
int nelements = kvlGetListNumElements(kvlist, listID);
printf("# list ID: %d; Number of elements: %d\n", listID, nelements);
printf("&%s\n", listname);
for ( elemID = 0; elemID < nelements; ++elemID )
for ( int elemID = 0; elemID < nelements; ++elemID )
{
ename = kvlGetListElementName(kvlist, listID, elemID);
evalue = kvlGetListElementValue(kvlist, listID, elemID);
const char *ename = kvlGetListElementName(kvlist, listID, elemID);
const char *evalue = kvlGetListElementValue(kvlist, listID, elemID);
printf(" %s = %s\n", ename, evalue);
}
printf("/\n");
......@@ -61,37 +54,29 @@ int read_cmor_table(const char *filename)
static
int conv_cmor_table(const char *filename)
{
void *kvlist;
int nlists, listID;
int nelements, elemID;
int len;
int hasmissval = FALSE;
bool hasmissval = false;
double missval;
const char *listname;
const char *ename;
const char *evalue;
char *ovalue;
kvlist = kvlParseFile(filename);
nlists = kvlGetNumLists(kvlist);
void *kvlist = kvlParseFile(filename);
int nlists = kvlGetNumLists(kvlist);
//printf("# Number of lists: %d\n", nlists);
for ( listID = 0; listID < nlists; ++listID )
for ( int listID = 0; listID < nlists; ++listID )
{
listname = kvlGetListName(kvlist, listID);
nelements = kvlGetListNumElements(kvlist, listID);
const char *listname = kvlGetListName(kvlist, listID);
int nelements = kvlGetListNumElements(kvlist, listID);
//printf("# list ID: %d; Number of elements: %d\n", listID, nelements);
if ( strncmp("global", listname, strlen(listname)) == 0 )
{
for ( elemID = 0; elemID < nelements; ++elemID )
for ( int elemID = 0; elemID < nelements; ++elemID )
{
ename = kvlGetListElementName(kvlist, listID, elemID);
evalue = kvlGetListElementValue(kvlist, listID, elemID);
len = strlen(ename);
const char *ename = kvlGetListElementName(kvlist, listID, elemID);
const char *evalue = kvlGetListElementValue(kvlist, listID, elemID);
size_t len = strlen(ename);
if ( strncmp("missing_value", ename, len) == 0 )
{
missval = atof(evalue);
hasmissval = TRUE;
hasmissval = true;
}
}
}
......@@ -99,11 +84,11 @@ int conv_cmor_table(const char *filename)
{
int vlen;
printf("&%s\n", "parameter");
for ( elemID = 0; elemID < nelements; ++elemID )
for ( int elemID = 0; elemID < nelements; ++elemID )
{
ename = kvlGetListElementName(kvlist, listID, elemID);
evalue = kvlGetListElementValue(kvlist, listID, elemID);
len = strlen(ename);
const char *ename = kvlGetListElementName(kvlist, listID, elemID);
const char *evalue = kvlGetListElementValue(kvlist, listID, elemID);
int len = strlen(ename);
vlen = strlen(evalue);
if ( vlen > 1 && evalue[0] == '"' && evalue[vlen-1] == '"' )
......@@ -112,7 +97,7 @@ int conv_cmor_table(const char *filename)
evalue++;
}
ovalue = strdup(evalue);
char *ovalue = strdup(evalue);
for ( int i = 1; i < vlen; ++i )
{
if ( ovalue[i-1] == '"' && ovalue[i] == '"' )
......@@ -154,22 +139,18 @@ int conv_cmor_table(const char *filename)
void *Kvl(void *argument)
{
int READ_CMOR_TABLE, CONV_CMOR_TABLE, CONV_PARTAB;
int operatorID;
const char *filename;
cdoInitialize(argument);
READ_CMOR_TABLE = cdoOperatorAdd("read_cmor_table", 0, 0, NULL);
CONV_CMOR_TABLE = cdoOperatorAdd("conv_cmor_table", 0, 0, NULL);
CONV_PARTAB = cdoOperatorAdd("conv_partab", 0, 0, NULL);
int READ_CMOR_TABLE = cdoOperatorAdd("read_cmor_table", 0, 0, NULL);
int CONV_CMOR_TABLE = cdoOperatorAdd("conv_cmor_table", 0, 0, NULL);
int CONV_PARTAB = cdoOperatorAdd("conv_partab", 0, 0, NULL);
operatorID = cdoOperatorID();
int operatorID = cdoOperatorID();
if ( operatorID == READ_CMOR_TABLE )
{
if ( operatorArgc() != 1 ) cdoAbort("Too few arguments!");
filename = operatorArgv()[0];
const char *filename = operatorArgv()[0];
if ( cdoVerbose ) cdoPrint("Parse file: %s", filename);
......@@ -178,7 +159,7 @@ void *Kvl(void *argument)
else if ( operatorID == CONV_CMOR_TABLE )
{
if ( operatorArgc() != 1 ) cdoAbort("Too few arguments!");
filename = operatorArgv()[0];
const char *filename = operatorArgv()[0];
if ( cdoVerbose ) cdoPrint("Parse file: %s", filename);
......@@ -187,7 +168,7 @@ void *Kvl(void *argument)
else if ( operatorID == CONV_PARTAB )
{
if ( operatorArgc() != 1 ) cdoAbort("Too few arguments!");
filename = operatorArgv()[0];
const char *filename = operatorArgv()[0];
if ( cdoVerbose ) cdoPrint("Parse file: %s", filename);
......
......@@ -26,25 +26,21 @@ void dumplogo(const char *logfilename, int dumptype);
void *Log(void *argument)
{
int DUMPLOGS, DAYLOGS, MONLOGS;
int operatorID, operfunc;
int dumptype;
cdoInitialize(argument);
DUMPLOGS = cdoOperatorAdd("dumplogs", 0, 0, NULL);
DAYLOGS = cdoOperatorAdd("daylogs", 0, 0, NULL);
MONLOGS = cdoOperatorAdd("monlogs", 0, 0, NULL);
cdoOperatorAdd("dumplogo", 1, 0, NULL);
cdoOperatorAdd("snamelogo", 1, 1, NULL);
cdoOperatorAdd("scalllogo", 1, 2, NULL);
cdoOperatorAdd("smemlogo", 1, 3, NULL);
cdoOperatorAdd("stimelogo", 1, 4, NULL);
cdoOperatorAdd("sperclogo", 1, 5, NULL);
int DUMPLOGS = cdoOperatorAdd("dumplogs", 0, 0, NULL);
int DAYLOGS = cdoOperatorAdd("daylogs", 0, 0, NULL);
int MONLOGS = cdoOperatorAdd("monlogs", 0, 0, NULL);
cdoOperatorAdd("dumplogo", 1, 0, NULL);
cdoOperatorAdd("snamelogo", 1, 1, NULL);
cdoOperatorAdd("scalllogo", 1, 2, NULL);
cdoOperatorAdd("smemlogo", 1, 3, NULL);
cdoOperatorAdd("stimelogo", 1, 4, NULL);
cdoOperatorAdd("sperclogo", 1, 5, NULL);
operatorID = cdoOperatorID();
operfunc = cdoOperatorF1(operatorID);
dumptype = cdoOperatorF2(operatorID);
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
int dumptype = cdoOperatorF2(operatorID);
if ( cdoStreamName(0)->args[0] == '-' )
cdoAbort("This operator does not work with pipes!");
......
......@@ -71,8 +71,7 @@ int countMask(double *maskField, int gridSize, double falseVal)
void *MapReduce(void *argument)
{
int nrecs;
int tsID;
int varID, levelID, recID;
int varID, levelID;
int nmiss;
int nobounds = FALSE;
int nocoords = FALSE;
......@@ -90,7 +89,6 @@ void *MapReduce(void *argument)
if ( cdoDebug ) cdoPrint("MapReduce: input gridSize:%d", inputGridSize);
/* creata an index list of the relevant locations {{{ */
tsID = 0;
double *inputMaskField = (double*) Malloc(inputGridSize*sizeof(double));
read_first_record(operatorArgv()[0],inputGridSize, inputMaskField);
......@@ -166,13 +164,13 @@ void *MapReduce(void *argument)
double *arrayIn = (double *)Malloc(inputGridSize*sizeof(double));
double *arrayOut = (double *)Malloc(maskSize*sizeof(double));
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
if (TRUE == vars[varID])
......
......@@ -37,15 +37,12 @@
static
int ReadCoords(double *xvals, double *yvals, const char *polyfile, FILE *fp)
{
double xcoord, ycoord;
int z = 0, number = 0, jumpedlines = 0;
int i = 0;
char line[MAX_LINE];
char *linep;
while ( readline(fp, line, MAX_LINE) )
{
i = 0;
int i = 0;
if ( line[0] == '#' )
{
jumpedlines++;
......@@ -58,14 +55,11 @@ int ReadCoords(double *xvals, double *yvals, const char *polyfile, FILE *fp)
}
if ( line[0] == '&' ) break;
linep = &line[0];
char *linep = &line[0];
xcoord = strtod(linep, &linep);
double xcoord = strtod(linep, &linep);
if ( ! (fabs(xcoord) > 0) )
{
jumpedlines++;
}
if ( ! (fabs(xcoord) > 0) ) jumpedlines++;
while( ( ( isdigit( (int) *linep ) == FALSE ) && ( *linep!='-' )) && ( i < 64) )
{
......@@ -82,7 +76,7 @@ int ReadCoords(double *xvals, double *yvals, const char *polyfile, FILE *fp)
}
if ( ( i >= 63 ) && ( number != 0 ) ) cdoAbort( "Wrong value format in file %s at line %d", polyfile, (number+jumpedlines+1) );
ycoord = strtod(linep, NULL);
double ycoord = strtod(linep, NULL);
xvals[number] = xcoord;
yvals[number] = ycoord;
......
......@@ -107,7 +107,7 @@ void mastrfu(int gridID, int zaxisID, double *array1, double *array2, int nmiss,
void *Mastrfu(void *argument)
{
int nrecs;
int recID, varID, levelID;
int varID, levelID;
int offset;
int nmiss, nmiss1;
......@@ -167,7 +167,7 @@ void *Mastrfu(void *argument)
streamDefTimestep(streamID2, tsID);
nmiss = 0;
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
offset = gridsize*levelID;
......@@ -177,7 +177,7 @@ void *Mastrfu(void *argument)
mastrfu(gridID, zaxisID, array1, array2, nmiss, missval);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
varID = 0;
levelID = recID;
......
......@@ -34,30 +34,22 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
{
char vname1[CDI_MAX_NAME], vname2[CDI_MAX_NAME];
int k;
int gridID1, gridID2;
int zaxisID1, zaxisID2;
int varID1, varID2;
int param1, param2;
int ztype1, ztype2;
int gtype1, gtype2;
int nlev1, nlev2;
int gsize1, gsize2;
int mlev1 = 0, mlev2 = 0;
double *lev1 = NULL, *lev2 = NULL;
int nvars1 = vlistNvars(vlistID1);
int nvars2 = vlistNvars(vlistID2);
for ( varID1 = 0; varID1 < nvars1; ++varID1 )
for ( int varID1 = 0; varID1 < nvars1; ++varID1 )
{
vlistInqVarName(vlistID1, varID1, vname1);
param1 = vlistInqVarParam(vlistID1, varID1);
gridID1 = vlistInqVarGrid(vlistID1, varID1);
zaxisID1 = vlistInqVarZaxis(vlistID1, varID1);
gtype1 = gridInqType(gridID1);
gsize1 = gridInqSize(gridID1);
ztype1 = zaxisInqType(zaxisID1);
nlev1 = zaxisInqSize(zaxisID1);
int param1 = vlistInqVarParam(vlistID1, varID1);
int gridID1 = vlistInqVarGrid(vlistID1, varID1);
int zaxisID1 = vlistInqVarZaxis(vlistID1, varID1);
int gtype1 = gridInqType(gridID1);
int gsize1 = gridInqSize(gridID1);
int ztype1 = zaxisInqType(zaxisID1);
int nlev1 = zaxisInqSize(zaxisID1);
if ( nlev1 > mlev1 )
{
mlev1 = nlev1;
......@@ -65,16 +57,16 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
}
zaxisInqLevels(zaxisID1, lev1);
for ( varID2 = 0; varID2 < nvars2; ++varID2 )
for ( int varID2 = 0; varID2 < nvars2; ++varID2 )
{
vlistInqVarName(vlistID2, varID2, vname2);
param2 = vlistInqVarParam(vlistID2, varID2);
gridID2 = vlistInqVarGrid(vlistID2, varID2);
zaxisID2 = vlistInqVarZaxis(vlistID2, varID2);
gtype2 = gridInqType(gridID2);
gsize2 = gridInqSize(gridID2);
ztype2 = zaxisInqType(zaxisID2);
nlev2 = zaxisInqSize(zaxisID2);
int param2 = vlistInqVarParam(vlistID2, varID2);
int gridID2 = vlistInqVarGrid(vlistID2, varID2);
int zaxisID2 = vlistInqVarZaxis(vlistID2, varID2);
int gtype2 = gridInqType(gridID2);
int gsize2 = gridInqSize(gridID2);
int ztype2 = zaxisInqType(zaxisID2);
int nlev2 = zaxisInqSize(zaxisID2);
if ( gtype1 == gtype2 && gsize1 == gsize2 && ztype1 == ztype2 && nlev1 == nlev2 )
{
if ( nlev2 > mlev2 )
......@@ -92,9 +84,7 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
if ( param1 < 0 || param2 < 0 )
{
if ( strcmp(vname1, vname2) == 0 )
{
cdoWarning("Duplicate entry of parameter %s in %s!", vname2, filename);
}
cdoWarning("Duplicate entry of parameter %s in %s!", vname2, filename);
}
else
{
......@@ -131,34 +121,15 @@ void *Merge(void *argument)
int streamID1 = -1;
int varID, varID2;
int nrecs = 0;
int recID, levelID, levelID2;
int levelID, levelID2;
int index;
int gridsize;
int nmiss;
//int skip_same_var = FALSE;
cdoInitialize(argument);
bool lcopy = UNCHANGED_RECORD;
/*
{
char *envstr;
envstr = getenv("SKIP_SAME_VAR");
if ( envstr )
{
int ival;
ival = atoi(envstr);
if ( ival == 1 )
{
skip_same_var = TRUE;
if ( cdoVerbose )
cdoPrint("Set SKIP_SAME_VAR to %d", ival);
}
}
}
*/
int streamCnt = cdoStreamCnt();
int nmerge = streamCnt - 1;
......@@ -310,7 +281,7 @@ void *Merge(void *argument)
if ( vlistID1 == -1 ) continue;
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......
......@@ -31,19 +31,12 @@
static
void gen_index(int gridID1, int gridID2, int *index)
{
int nlat1, nlon1;
int nlat2, nlon2;
int gridtype1, gridtype2;
int gridsize2;
int i, j, k, i1, i2;
int *xindex = NULL, *yindex = NULL;
double *xvals1 = NULL, *yvals1 = NULL;
double *xvals2 = NULL, *yvals2 = NULL;
gridtype1 = gridInqType(gridID1);
gridtype2 = gridInqType(gridID2);
int gridtype1 = gridInqType(gridID1);
int gridtype2 = gridInqType(gridID2);
gridsize2 = gridInqSize(gridID2);
int gridsize2 = gridInqSize(gridID2);
if ( gridtype1 != gridtype2 )
cdoAbort("Input streams have different grid types!");
......@@ -54,11 +47,11 @@ void gen_index(int gridID1, int gridID2, int *index)
if ( gridtype1 == GRID_LONLAT || gridtype1 == GRID_GAUSSIAN )
{
nlon1 = gridInqXsize(gridID1);
nlat1 = gridInqYsize(gridID1);
int nlon1 = gridInqXsize(gridID1);
int nlat1 = gridInqYsize(gridID1);
nlon2 = gridInqXsize(gridID2);
nlat2 = gridInqYsize(gridID2);
int nlon2 = gridInqXsize(gridID2);
int nlat2 = gridInqYsize(gridID2);
if ( ! (gridInqXvals(gridID1, NULL) && gridInqYvals(gridID1, NULL)) )
cdoAbort("Grid 1 has no values!");
......@@ -66,13 +59,13 @@ void gen_index(int gridID1, int gridID2, int *index)
if ( ! (gridInqXvals(gridID2, NULL) && gridInqYvals(gridID2, NULL)) )
cdoAbort("Grid 2 has no values!");
xvals1 = (double*) Malloc(nlon1*sizeof(double));
yvals1 = (double*) Malloc(nlat1*sizeof(double));
xvals2 = (double*) Malloc(nlon2*sizeof(double));
yvals2 = (double*) Malloc(nlat2*sizeof(double));
double *xvals1 = (double*) Malloc(nlon1*sizeof(double));
double *yvals1 = (double*) Malloc(nlat1*sizeof(double));
double *xvals2 = (double*) Malloc(nlon2*sizeof(double));
double *yvals2 = (double*) Malloc(nlat2*sizeof(double));
xindex = (int*) Malloc(nlon2*sizeof(int));
yindex = (int*) Malloc(nlat2*sizeof(int));
int *xindex = (int*) Malloc(nlon2*sizeof(int));
int *yindex = (int*) Malloc(nlat2*sizeof(int));
gridInqXvals(gridID1, xvals1);
gridInqYvals(gridID1, yvals1);
......@@ -165,37 +158,26 @@ void gen_index(int gridID1, int gridID2, int *index)
void *Mergegrid(void *argument)
{
int varID;
int varID, levelID;
int nrecs = 0;
int tsID, recID, levelID;
int nrecs2;
int streamID1, streamID2, streamID3;
int vlistID1 , vlistID2, vlistID3;
int nmiss1, nmiss2;
int gridsize1, gridsize2;
int gridID1, gridID2;
int taxisID1, taxisID3;
int index;
int i, *gindex = NULL;
int ndiffgrids;
double missval1, missval2;
double *array1, *array2;
cdoInitialize(argument);
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID3 = taxisDuplicate(taxisID1);
int vlistID1 = streamInqVlist(streamID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID3 = taxisDuplicate(taxisID1);
streamID2 = streamOpenRead(cdoStreamName(1));
int streamID2 = streamOpenRead(cdoStreamName(1));
vlistID2 = streamInqVlist(streamID2);
int vlistID2 = streamInqVlist(streamID2);
vlistCompare(vlistID1, vlistID2, CMP_NAME | CMP_NLEVEL);
ndiffgrids = 0;
int ndiffgrids = 0;
for ( index = 1; index < vlistNgrids(vlistID1); index++ )
if ( vlistGrid(vlistID1, 0) != vlistGrid(vlistID1, index) )
ndiffgrids++;
......@@ -209,31 +191,31 @@ void *Mergegrid(void *argument)
if ( ndiffgrids > 0 ) cdoAbort("Too many different grids in %s!", cdoStreamName(1)->args);
gridID1 = vlistGrid(vlistID1, 0);
gridID2 = vlistGrid(vlistID2, 0);
int gridID1 = vlistGrid(vlistID1, 0);
int gridID2 = vlistGrid(vlistID2, 0);
gridsize1 = gridInqSize(gridID1);
gridsize2 = gridInqSize(gridID2);
int gridsize1 = gridInqSize(gridID1);
int gridsize2 = gridInqSize(gridID2);
array1 = (double*) Malloc(gridsize1*sizeof(double));
array2 = (double*) Malloc(gridsize2*sizeof(double));
gindex = (int*) Malloc(gridsize2*sizeof(int));
double *array1 = (double*) Malloc(gridsize1*sizeof(double));
double *array2 = (double*) Malloc(gridsize2*sizeof(double));
int *gindex = (int*) Malloc(gridsize2*sizeof(int));
gen_index(gridID1, gridID2, gindex);
vlistID3 = vlistDuplicate(vlistID1);
int vlistID3 = vlistDuplicate(vlistID1);
streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
int streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
vlistDefTaxis(vlistID3, taxisID3);
streamDefVlist(streamID3, vlistID3);
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID3, taxisID1);
nrecs2 = streamInqTimestep(streamID2, tsID);
int nrecs2 = streamInqTimestep(streamID2, tsID);
if ( nrecs2 == 0 )
cdoAbort("Input streams have different number of timesteps!");
......@@ -242,19 +224,19 @@ void *Mergegrid(void *argument)
streamDefTimestep(streamID3, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
streamReadRecord(streamID2, array2, &nmiss2);
missval2 = vlistInqVarMissval(vlistID2, varID);
double missval2 = vlistInqVarMissval(vlistID2, varID);
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, array1, &nmiss1);
missval1 = vlistInqVarMissval(vlistID1, varID);
double missval1 = vlistInqVarMissval(vlistID1, varID);
for ( i = 0; i < gridsize2; i++ )
for ( int i = 0; i < gridsize2; i++ )
{
if ( gindex[i] >= 0 && !DBL_IS_EQUAL(array2[i], missval2) )
{
......@@ -265,7 +247,7 @@ void *Mergegrid(void *argument)
if ( nmiss1 )
{
nmiss1 = 0;
for ( i = 0; i < gridsize1; i++ )
for ( int i = 0; i < gridsize1; i++ )
if ( DBL_IS_EQUAL(array1[i], missval1) ) nmiss1++;
}
......
......@@ -44,9 +44,9 @@ void *Merstat(void *argument)
int wstatus = FALSE;
int index;
int nmiss;
int recID, nrecs;
int nrecs;
int varID, levelID;
int needWeights = FALSE;
bool needWeights = false;
char varname[CDI_MAX_NAME];
cdoInitialize(argument);
......@@ -76,7 +76,7 @@ void *Merstat(void *argument)
if ( operfunc == func_mean || operfunc == func_avg ||
operfunc == func_var || operfunc == func_std ||
operfunc == func_var1 || operfunc == func_std1 )
needWeights = TRUE;
needWeights = true;
int streamID1 = streamOpenRead(cdoStreamName(0));
......@@ -138,7 +138,7 @@ void *Merstat(void *argument)