Commit 4bbff4c0 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent a7f4cfaf
......@@ -35,12 +35,8 @@
/*
extern int cdoGribDataScanningMode; // -1: not used; allowed modes: <0, 64, 96>; Default is 64
int define_destagered_grid(int gridID_u_stag, int gridID_v_stag, double *destagGridOffsets);
*/
void *DestaggerUV();
void destaggerUorV(double *fu, double *fuOut,
int klev, int nlat, int nlon, int UorV, long int offset);
void destaggerUorV_positiveOrder(double *fu, double *fuOut,
......@@ -66,30 +62,27 @@ int ROTUVNORTH;
int ROTUVN; // Fixed version of rotuvb operator !
int PROJUVLATLON;
static
void *DestaggerUV()
{
int streamID1, streamID2;
int nrecs, nvars;
int tsID, recID, varID, levelID;
int nrecs;
int recID, varID, levelID;
int varID1 = -1, varID2 = -1;
int zaxisID1 = -1, zaxisID2 = -1;
int varID1stg = -1, varID2stg = -1;
int level, gridsize;
int lvar = FALSE;
int i, nch;
int i;
int chcodes[MAXARG];
char *chvars[MAXARG];
char varname[CDI_MAX_NAME];
double destagGridOffsets[MAXARG];
int index, ngrids;
int vlistID1, vlistID2;
int index;
int gridID1 = -1, gridID2 = -1;
int gridID0 = -1;
int gridID;
int nmiss;
int lcopy = FALSE;
int UorV;
int taxisID1, taxisID2;
int nlon = 0, nlat = 0, ntr = -1;
int code, param;
int zaxisID, ltype, nlevs;
......@@ -100,48 +93,46 @@ void *DestaggerUV()
//Note: Already initialized by the caller! Don't call again: cdoInitialize(argument);
operatorInputArg("Pair of u and v in the staggered system:\n\
Usage: uvDestag,u,v -or- uvDestag,33,34 -or- uvDestag,u,v,-0.5,-0.5 -or- uvDestag,33,34,-0.5,-0.5\n\
Destaggered grid offsets <,-/+0.5,-/+0.5> are optional.\n\
Usage: uvDestag,u,v -or- uvDestag,33,34 -or- uvDestag,u,v,-0.5,-0.5 -or- uvDestag,33,34,-0.5,-0.5\n \
Destaggered grid offsets <,-/+0.5,-/+0.5> are optional.\n \
If file contains grid with temperature (name='t' or code=11) then grid_temp will be used for destaggered wind.");
if ( cdoDebugExt ) cdoPrint("UVDESTAG (destaggering) requested)..");
nch = operatorArgc();
int nch = operatorArgc();
if ( nch<2 ) cdoAbort("Number of input arguments < 2; At least 2 arguments needed: uvDestag,33,34<,-0.5,-0.5> optional");
if ( nch>=MAXARG ) cdoAbort("Number of input arguments >= %d", MAXARG);
bool lvar = false;
if ( isdigit(*operatorArgv()[0]) )
{
lvar = FALSE; // We have a list of codes
for ( i = 0; i < nch; i++ )
chcodes[i] = atoi(operatorArgv()[i]);
lvar = false; // We have a list of codes
for ( int i = 0; i < 2; i++ ) chcodes[i] = parameter2int(operatorArgv()[i]);
}
else
{
lvar = TRUE; // We have a list of variables
for ( i = 0; i < nch; i++ )
chvars[i] = operatorArgv()[i];
lvar = true; // We have a list of variables
for ( int i = 0; i < 2; i++ ) chvars[i] = operatorArgv()[i];
}
destagGridOffsets[0] = -0.5;
destagGridOffsets[1] = -0.5;
if ( nch>2 )
if ( nch > 2 )
{
for ( i = 2; i < (2+2); i++ )
destagGridOffsets[i-2] = atof(operatorArgv()[i]);
for ( int i = 2; i < (2+2); i++ )
destagGridOffsets[i-2] = parameter2double(operatorArgv()[i]);
}
if ( cdoDebugExt ) cdoPrint("destagGridOffsets = (%01.1f,%01.1f)", destagGridOffsets[0],destagGridOffsets[1]);
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
// Find the first occurance of staggered U and V variables (for example codes 33,34).
......@@ -191,7 +182,7 @@ void *DestaggerUV()
// NOTE: Variable with codes (3[3,4],105,10) will get from CDO typically a name: "10u", resp. "10v"
// Mostly u & v at level type 105 is not staggered, but test it to be sure..
#define CheckVarIsU(varID,varname,code) {\
#define CheckVarIsU(varID,varname,code) { \
VarIsU = 0;\
if ( lvar ) {\
if ( strcmp((char*)(varname), (char*)(chvars)[0]) == 0 ) VarIsU = 1;\
......@@ -200,7 +191,7 @@ void *DestaggerUV()
} else \
if ( code == chcodes[0] ) VarIsU = 1;\
}
#define CheckVarIsV(varID,varname,code) {\
#define CheckVarIsV(varID,varname,code) { \
VarIsV = 0;\
if ( lvar ) {\
if ( strcmp((char*)(varname), (char*)(chvars)[1]) == 0 ) VarIsV = 1;\
......@@ -209,7 +200,7 @@ void *DestaggerUV()
} else \
if ( code == chcodes[1] ) VarIsV = 1;\
}
#define CheckUVisStaggered(varID1,varID2, zaxisID1, zaxisID2) {\
#define CheckUVisStaggered(varID1,varID2, zaxisID1, zaxisID2) { \
VarsUVareStaggered = 1;\
int gridID1tmp = vlistInqVarGrid(vlistID1, varID1);\
int gridID2tmp = vlistInqVarGrid(vlistID1, varID2);\
......@@ -219,7 +210,7 @@ void *DestaggerUV()
}
// Search for staggered u and v wind:
nvars = vlistNvars(vlistID1);
int nvars = vlistNvars(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
{
param = vlistInqVarParam(vlistID1, varID); /* vlistInqVarParam(int vlistID, int varID): Get the parameter number of a Variable */
......@@ -236,8 +227,7 @@ void *DestaggerUV()
CheckVarIsU(varID,varname,code);
CheckVarIsV(varID,varname,code);
if (VarIsU) { varID1 = varID; zaxisID1 = zaxisID; }
else
if (VarIsV) { varID2 = varID; zaxisID2 = zaxisID; }
else if (VarIsV) { varID2 = varID; zaxisID2 = zaxisID; }
if ( (varID1stg == -1) && (varID2stg == -1) )
if ( (varID1 != -1) && (varID2 != -1) )
......@@ -246,7 +236,7 @@ void *DestaggerUV()
if (VarsUVareStaggered) {
gridID1 = vlistInqVarGrid(vlistID1, varID1);
gridID2 = vlistInqVarGrid(vlistID1, varID2);
if ( cdoDebugExt ) cdoPrint("Found STAGGERED U & V: varID1=%d (gridID1=%d), varID2=%d (gridID2=%d)",varID1,gridID2, varID2, gridID1);
if ( cdoDebugExt ) cdoPrint("Found STAGGERED U & V: varID1=%d (gridID1=%d), varID2=%d (gridID2=%d)",varID1, gridID2, varID2, gridID1);
varID1stg = varID1;
varID2stg = varID2;
}
......@@ -274,14 +264,13 @@ void *DestaggerUV()
gridID0 = gridID1;
}
ngrids = vlistNgrids(vlistID1);
int ngrids = vlistNgrids(vlistID1);
/*
#define GRID_LONLAT 4 // Regular longitude/latitude grid
#define GRID_LCC 11 // Lambert Conformal Conic (GRIB)
#define GRID_GAUSSIAN 2 // Regular Gaussian lon/lat grid
#define GRID_GAUSSIAN_REDUCED 3 // Reduced Gaussian lon/lat grid
*/
double xincU = gridInqXinc(gridID1);
......@@ -363,6 +352,7 @@ void *DestaggerUV()
gridID = vlistGrid(vlistID1, index);
if ( cdoDebugExt>=10 ) cdoPrint("Grid nr. %d is gridtype: %d (%s)", index, gridInqType(gridID), gridNamePtr(gridInqType(gridID)));
}
nvars = vlistNvars(vlistID1);
if (gridID0 == -1)
......@@ -396,11 +386,12 @@ void *DestaggerUV()
//cdoDebugExt = 0;
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
streamDefVlist(streamID2, vlistID2); // from this point the stream is using a different vlistID !!!!!
vlistID2 = streamInqVlist(streamID2); // refresh it
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
......@@ -413,7 +404,6 @@ void *DestaggerUV()
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
param = vlistInqVarParam(vlistID1, varID);
code = vlistInqVarCode(vlistID1, varID);
......@@ -427,8 +417,7 @@ void *DestaggerUV()
CheckVarIsV(varID,varname,code);
UorV = -1; // -1: not U, neither V
if (VarIsU) UorV = 0; // 0: U-wind; 1: V-wind
else
if (VarIsV) UorV = 1;
else if (VarIsV) UorV = 1;
if (UorV>=0)
{
gridID = vlistInqVarGrid(vlistID1, varID);
......@@ -525,7 +514,7 @@ void *DestaggerUV()
cdoFinish();
return (0);
return 0;
}
......@@ -910,8 +899,7 @@ void *TransformUV(int operatorID)
cdoPrint("LAT-LON grid created.");
}// end of if (gridIDcurvl==-1)
}// end of if (operatorID != ROTUVN)
int uvRelativeFlag = gridInqUvRelativeToGrid(gridID);
if (uvRelativeFlag!=1)
if ( gridInqUvRelativeToGrid(gridID) != 1 )
{
cdoPrint("NOTICE: grid with id:%d has NOT uv relative to grid.", gridID);
} else
......@@ -983,7 +971,7 @@ void *TransformUV(int operatorID)
Free(ivar);
cdoFinish();
return (0);
return 0;
}
//grid_t *grid_to_pointer(int idx); // defined in: libcdi/src/grid.c
......
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