Commit 606038e3 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

uv2vr_cdf: added variable description.

parent ade4ea16
2017-10-23 Uwe Schulzweida
* Added operator uv2vr_cfd: U and V wind to relative vorticity (interface to NCL)
* Added operator uv2dv_cfd: U and V wind to divergence (interface to NCL)
* gengrid: bug fix
2017-10-20 Uwe Schulzweida
......
......@@ -585,6 +585,7 @@ Operator catalog:
-------------------------------------------------------------
NCL
-------------------------------------------------------------
NCL_wind uv2vr_cfd U and V wind to relative vorticity
NCL_wind uv2dv_cfd U and V wind to divergence
-------------------------------------------------------------
CMOR
......
......@@ -5,14 +5,27 @@
@Section = NCL
@Class = NCL
@Arguments = infile outfile
@Operators = uv2dv_cfd
@Operators = uv2vr_cfd uv2dv_cfd
@BeginDescription
This module contains CDO operators with an interface to NCL functions with the same name.
This module contains CDO operators with an interface to NCL functions.
The corresponding NCL functions have the same name. A more detailed description
of those NCL function can be found on the NCL homepage https://www.ncl.ucar.edu.
@EndDescription
@EndModule
@BeginOperator_uv2vr_cfd
@Title = U and V wind to relative vorticity
@Parameter = [u v boundOpt outMode]
@BeginDescription
Computes relative vorticity for a latitude-longitude grid using centered finite differences.
The grid need not be global and missing values are allowed.
@EndDescription
@EndOperator
@BeginOperator_uv2dv_cfd
@Title = U and V wind to divergence
@Parameter = [u v boundOpt outMode]
......
......@@ -23,11 +23,10 @@
#include "pstream.h"
#include "libncl.h"
static
void uv2dv_cfd_W(double missval, double *u, double *v, double *lon, double *lat, size_t nlon, size_t nlat, size_t nlev, int boundOpt, double *div)
{
int ierror;
size_t nlatnlon = nlat * nlon;
// Test dimension sizes.
if ( (nlon > INT_MAX) || (nlat > INT_MAX) )
......@@ -36,10 +35,7 @@ void uv2dv_cfd_W(double missval, double *u, double *v, double *lon, double *lat,
int inlon = (int) nlon;
int inlat = (int) nlat;
size_t gridsize_uv = nlatnlon;
// Check for missing values.
// coerce_missing(type_u,has_missing_u,&missing_u,&missing_du,&missing_ru);
size_t gridsize_uv = nlat * nlon;
for ( size_t k = 0; k < nlev; ++k )
{
......@@ -57,6 +53,37 @@ void uv2dv_cfd_W(double missval, double *u, double *v, double *lon, double *lat,
}
}
static
void uv2vr_cfd_W(double missval, double *u, double *v, double *lon, double *lat, size_t nlon, size_t nlat, size_t nlev, int boundOpt, double *vort)
{
int ierror;
// Test dimension sizes.
if ( (nlon > INT_MAX) || (nlat > INT_MAX) )
cdoAbort("nlat and/or nlon is greater than INT_MAX!");
int inlon = (int) nlon;
int inlat = (int) nlat;
size_t gridsize_uv = nlat * nlon;
for ( size_t k = 0; k < nlev; ++k )
{
double *tmp_u = u + k*gridsize_uv;
double *tmp_v = v + k*gridsize_uv;
double *tmp_vort = vort + k*gridsize_uv;
// Init output array.
memset(tmp_vort, 0, gridsize_uv*sizeof(double));
// Call the Fortran routine.
#ifdef HAVE_CF_INTERFACE
DVRFIDF(tmp_u, tmp_v, lat, lon, inlon, inlat, missval, boundOpt, tmp_vort, ierror);
#else
cdoAbort("Fortran support not compiled in!");
#endif
}
}
static
int find_name(int vlistID, char *name)
{
char varname[CDI_MAX_NAME];
......@@ -136,6 +163,11 @@ void *NCL_wind(void *argument)
cdoInitialize(argument);
int UV2DV_CFD = cdoOperatorAdd("uv2dv_cfd", 0, 0, "[u, v, boundsOpt, outMode]");
int UV2VR_CFD = cdoOperatorAdd("uv2vr_cfd", 0, 0, "[u, v, boundsOpt, outMode]");
int operatorID = cdoOperatorID();
set_parameter();
int streamID1 = pstreamOpenRead(cdoStreamName(0));
......@@ -184,11 +216,21 @@ void *NCL_wind(void *argument)
double missvalv = vlistInqVarMissval(vlistID1, varIDv);
int timetype = vlistInqVarTimetype(vlistID1, varIDu);
int varIDdiv = vlistDefVar(vlistID2, gridIDu, zaxisIDu, timetype);
vlistDefVarName(vlistID2, varIDdiv, "d");
vlistDefVarLongname(vlistID2, varIDdiv, "divergence");
vlistDefVarUnits(vlistID2, varIDdiv, "1/s");
vlistDefVarMissval(vlistID2, varIDdiv, missvalu);
int varIDo = vlistDefVar(vlistID2, gridIDu, zaxisIDu, timetype);
if ( operatorID == UV2DV_CFD )
{
vlistDefVarName(vlistID2, varIDo, "d");
vlistDefVarLongname(vlistID2, varIDo, "divergence");
vlistDefVarUnits(vlistID2, varIDo, "1/s");
}
else if ( operatorID == UV2VR_CFD )
{
vlistDefVarName(vlistID2, varIDo, "vo");
vlistDefVarLongname(vlistID2, varIDo, "vorticity");
vlistDefVarUnits(vlistID2, varIDo, "1/s");
}
vlistDefVarMissval(vlistID2, varIDo, missvalu);
double *lon = (double*) Malloc(nlon*sizeof(double));
double *lat = (double*) Malloc(nlat*sizeof(double));
......@@ -208,7 +250,7 @@ void *NCL_wind(void *argument)
double *array = (double*) Malloc(gridsizemax*sizeof(double));
double *arrayu = (double*) Malloc(nlev*gridsizeuv*sizeof(double));
double *arrayv = (double*) Malloc(nlev*gridsizeuv*sizeof(double));
double *arrayd = (double*) Malloc(nlev*gridsizeuv*sizeof(double));
double *arrayo = (double*) Malloc(nlev*gridsizeuv*sizeof(double));
int tsID = 0;
while ( (nrecs = pstreamInqTimestep(streamID1, tsID)) )
......@@ -251,16 +293,19 @@ void *NCL_wind(void *argument)
}
}
uv2dv_cfd_W(missvalu, arrayu, arrayv, lon, lat, nlon, nlat, nlev, boundOpt, arrayd);
if ( operatorID == UV2DV_CFD )
uv2dv_cfd_W(missvalu, arrayu, arrayv, lon, lat, nlon, nlat, nlev, boundOpt, arrayo);
else if ( operatorID == UV2VR_CFD )
uv2vr_cfd_W(missvalu, arrayu, arrayv, lon, lat, nlon, nlat, nlev, boundOpt, arrayo);
for ( levelID = 0; levelID < nlev; ++levelID )
{
double *parray = arrayd+levelID*gridsizeuv;
double *parray = arrayo+levelID*gridsizeuv;
nmiss = 0;
for ( size_t i = 0; i < gridsizeuv; ++i )
if ( DBL_IS_EQUAL(parray[i], missvalu) ) nmiss++;
pstreamDefRecord(streamID2, varIDdiv, levelID);
pstreamDefRecord(streamID2, varIDo, levelID);
pstreamWriteRecord(streamID2, parray, nmiss);
}
......@@ -275,7 +320,7 @@ void *NCL_wind(void *argument)
if ( array ) Free(array);
if ( arrayu ) Free(arrayu);
if ( arrayv ) Free(arrayv);
if ( arrayd ) Free(arrayd);
if ( arrayo ) Free(arrayo);
cdoFinish();
......
......@@ -7,9 +7,7 @@ void DCFINDIF(double *,double *,int *,double *,
double *,int *,int *, double *,
double *,int *,double *,int *);
void DVRFIDF(double *,double *,double *,double *,
int *,int *,double *,int *,double *,
int *);
void DVRFIDF(double *, double *, double *, double *, int, int, double, int, double *, int *);
void DDVFIDF(double *, double *, double *, double *, int, int, double, int, double *, int *);
*/
......@@ -20,6 +18,9 @@ void DDVFIDF(double *, double *, double *, double *, int, int, double, int, doub
PROTOCCALLSFSUB10(DDVFIDF, ddvfidf, DOUBLEV, DOUBLEV, DOUBLEV, DOUBLEV, INT, INT, DOUBLE, INT, DOUBLEV, PINT)
#define DDVFIDF(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) CCALLSFSUB10(DDVFIDF, ddvfidf, DOUBLEV, DOUBLEV, DOUBLEV, DOUBLEV, INT, INT, DOUBLE, INT, DOUBLEV, PINT, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)
PROTOCCALLSFSUB10(DVRFIDF, dvrfidf, DOUBLEV, DOUBLEV, DOUBLEV, DOUBLEV, INT, INT, DOUBLE, INT, DOUBLEV, PINT)
#define DVRFIDF(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) CCALLSFSUB10(DVRFIDF, dvrfidf, DOUBLEV, DOUBLEV, DOUBLEV, DOUBLEV, INT, INT, DOUBLE, INT, DOUBLEV, PINT, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)
#endif
#endif
......@@ -377,7 +377,7 @@ void *Samplegrid(void *argument); // "samplegrid", "subgrid"
#define MonarithOperators {"monadd", "monsub", "monmul", "mondiv"}
#define MrotuvOperators {"mrotuv"}
#define MrotuvbOperators {"mrotuvb"}
#define NCL_windOperators {"uv2dv_cfd"}
#define NCL_windOperators {"uv2dv_cfd", "uv2vr_cfd"}
#define NinfoOperators {"nyear", "nmon", "ndate", "ntime", "ncode", "npar", "nlevel", "ngridpoints", "ngrids"}
#define NmldumpOperators {"nmldump", "kvldump"}
#define OutputOperators {"output", "outputint", "outputsrv", "outputext", "outputf", "outputts", \
......@@ -895,7 +895,7 @@ void init_modules()
add_module("Monarith" , {Monarith , MonarithHelp , MonarithOperators , 1 , CDI_REAL , 2 , 1 });
add_module("Mrotuv" , {Mrotuv , {} , MrotuvOperators , 1 , CDI_REAL , 1 , 2 });
add_module("Mrotuvb" , {Mrotuvb , {} , MrotuvbOperators , 1 , CDI_REAL , 2 , 1 });
add_module("NCL_wind" , {NCL_wind , {} , NCL_windOperators , 1 , CDI_REAL , 1 , 1 });
add_module("NCL_wind" , {NCL_wind , NCL_windHelp , NCL_windOperators , 1 , CDI_REAL , 1 , 1 });
add_module("Ninfo" , {Ninfo , NinfoHelp , NinfoOperators , 1 , CDI_BOTH , 1 , 0 });
add_module("Nmldump" , {Nmldump , {} , NmldumpOperators , 0 , CDI_REAL , 0 , 0 });
add_module("Output" , {Output , OutputHelp , OutputOperators , 1 , CDI_REAL , -1 , 0 });
......
......@@ -5148,15 +5148,23 @@ std::vector<std::string> CMORliteHelp = {
std::vector<std::string> NCL_windHelp = {
"NAME",
" uv2dv_cfd - Wind transformation",
" uv2vr_cfd, uv2dv_cfd - Wind transformation",
"",
"SYNOPSIS",
" uv2dv_cfd[,u,v,boundOpt,outMode] infile outfile",
" <operator>[,u,v,boundOpt,outMode] infile outfile",
"",
"DESCRIPTION",
" This module contains CDO operators with an interface to NCL functions with the same name. ",
" Computes divergence for a latitude-longitude grid using centered finite differences.",
" The grid need not be global and missing values are allowed.",
" This module contains CDO operators with an interface to NCL functions.",
" The corresponding NCL functions have the same name. A more detailed description",
" of those NCL function can be found on the NCL homepage https://www.ncl.ucar.edu.",
"",
"OPERATORS",
" uv2vr_cfd U and V wind to relative vorticity",
" Computes relative vorticity for a latitude-longitude grid using centered finite differences.",
" The grid need not be global and missing values are allowed.",
" uv2dv_cfd U and V wind to divergence",
" Computes divergence for a latitude-longitude grid using centered finite differences.",
" The grid need not be global and missing values are allowed.",
"",
"PARAMETER",
" u STRING Name of variable u (default: u)",
......
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