Commit a04716b0 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdfDefXaxis/cdfDefXaxis: generate bounds for CDI_cmor_mode

parent 7f41e310
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* Version 1.7.1 released * Version 1.7.1 released
* using CGRIBEX library version 1.7.4 * using CGRIBEX library version 1.7.4
2015-11-25 Uwe Schulzweida
* cdfDefXaxis/cdfDefXaxis: generate bounds for CDI_cmor_mode
2015-11-23 Nathanael Huebbe 2015-11-23 Nathanael Huebbe
* replaced the vlist locked flag by two other flags * replaced the vlist locked flag by two other flags
......
...@@ -26089,17 +26089,49 @@ _ACEOF ...@@ -26089,17 +26089,49 @@ _ACEOF
   
# #
# Check for non-standard builtin # Check for non-standard builtin
ac_fn_c_check_decl "$LINENO" "__builtin_ctz" "ac_cv_have_decl___builtin_ctz" "$ac_includes_default" for builtin in __builtin_ctz
if test "x$ac_cv_have_decl___builtin_ctz" = xyes; then : do :
ac_have_decl=1
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __builtin_ctz is declared" >&5
$as_echo_n "checking whether __builtin_ctz is declared... " >&6; }
if ${acx_cv_have_decl___builtin_ctz+:} false; then :
$as_echo_n "(cached) " >&6
else else
ac_have_decl=0 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
unsigned lbz = __builtin_ctz(56U)
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
acx_cv_have_decl___builtin_ctz=yes
else
acx_cv_have_decl___builtin_ctz=no
fi fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_have_decl___builtin_ctz" >&5
$as_echo "$acx_cv_have_decl___builtin_ctz" >&6; }
if test "x$acx_cv_have_decl___builtin_ctz" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL___BUILTIN_CTZ 1
_ACEOF
   
cat >>confdefs.h <<_ACEOF break
#define HAVE_DECL___BUILTIN_CTZ $ac_have_decl else
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL___BUILTIN_CTZ 0
_ACEOF _ACEOF
   
fi
done
   
# Check compiler version # Check compiler version
case "$CC" in case "$CC" in
...@@ -58,8 +58,7 @@ ...@@ -58,8 +58,7 @@
don't. */ don't. */
#undef HAVE_DECL__SC_PAGE_SIZE #undef HAVE_DECL__SC_PAGE_SIZE
/* Define to 1 if you have the declaration of `__builtin_ctz', and to 0 if you /* Define to 1 if __builtin_ctz is available, 0 if not */
don't. */
#undef HAVE_DECL___BUILTIN_CTZ #undef HAVE_DECL___BUILTIN_CTZ
/* Define to 1 if you have the <dlfcn.h> header file. */ /* Define to 1 if you have the <dlfcn.h> header file. */
......
...@@ -1251,19 +1251,13 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1251,19 +1251,13 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
if ( streamptr->ncmode == 2 ) cdf_redef(fileID); if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
if ( ndims ) if ( ndims ) cdf_def_dim(fileID, axisname, dimlen, &dimID);
{
cdf_def_dim(fileID, axisname, dimlen, &dimID);
if ( gridInqXboundsPtr(gridID) || gridInqYboundsPtr(gridID) )
{
size_t nvertex = 2;
if ( nc_inq_dimid(fileID, BNDS_NAME, &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, BNDS_NAME, nvertex, &nvdimID);
}
}
if ( gridInqXvalsPtr(gridID) ) int gen_bounds = FALSE;
int grid_is_cyclic = gridIsCircular(gridID);
const double *pvals = gridInqXvalsPtr(gridID);
double *pbounds = NULL;
if ( pvals )
{ {
cdf_def_var(fileID, axisname, xtype, ndims, &dimID, &ncvarid); cdf_def_var(fileID, axisname, xtype, ndims, &dimID, &ncvarid);
...@@ -1276,7 +1270,28 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1276,7 +1270,28 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
cdf_put_att_text(fileID, ncvarid, "axis", 1, "X"); cdf_put_att_text(fileID, ncvarid, "axis", 1, "X");
if ( gridInqXboundsPtr(gridID) && nvdimID != UNDEFID ) if ( gridInqXboundsPtr(gridID) )
pbounds = (double*) gridInqXboundsPtr(gridID);
if ( CDI_cmor_mode && grid_is_cyclic && !pbounds )
{
gen_bounds = TRUE;
pbounds = (double*) malloc(2*dimlen*sizeof(double));
for ( size_t i = 0; i < dimlen-1; ++i )
{
pbounds[i*2+1] = (pvals[i] + pvals[i+1])/2;
pbounds[(i+1)*2] = (pvals[i] + pvals[i+1])/2;
}
pbounds[0] = (pvals[0] + pvals[dimlen-1]-360)/2;
pbounds[2*dimlen-1] = (pvals[dimlen-1] + pvals[0]+360)/2;
}
if ( pbounds )
{
size_t nvertex = 2;
if ( nc_inq_dimid(fileID, BNDS_NAME, &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, BNDS_NAME, nvertex, &nvdimID);
}
if ( pbounds && nvdimID != UNDEFID )
{ {
strcat(axisname, "_"); strcat(axisname, "_");
strcat(axisname, BNDS_NAME); strcat(axisname, BNDS_NAME);
...@@ -1297,8 +1312,9 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1297,8 +1312,9 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
cdf_enddef(fileID); cdf_enddef(fileID);
streamptr->ncmode = 2; streamptr->ncmode = 2;
if ( ncvarid != UNDEFID ) cdf_put_var_double(fileID, ncvarid, gridInqXvalsPtr(gridID)); if ( ncvarid != UNDEFID ) cdf_put_var_double(fileID, ncvarid, pvals);
if ( ncbvarid != UNDEFID ) cdf_put_var_double(fileID, ncbvarid, gridInqXboundsPtr(gridID)); if ( ncbvarid != UNDEFID ) cdf_put_var_double(fileID, ncbvarid, pbounds);
if ( gen_bounds ) Free(pbounds);
if ( ndims == 0 ) streamptr->ncxvarID[gridindex] = ncvarid; if ( ndims == 0 ) streamptr->ncxvarID[gridindex] = ncvarid;
} }
...@@ -1378,19 +1394,13 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1378,19 +1394,13 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
if ( streamptr->ncmode == 2 ) cdf_redef(fileID); if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
if ( ndims ) if ( ndims ) cdf_def_dim(fileID, axisname, dimlen, &dimID);
{
cdf_def_dim(fileID, axisname, dimlen, &dimID);
if ( gridInqXboundsPtr(gridID) || gridInqYboundsPtr(gridID) )
{
size_t nvertex = 2;
if ( nc_inq_dimid(fileID, BNDS_NAME, &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, BNDS_NAME, nvertex, &nvdimID);
}
}
if ( gridInqYvalsPtr(gridID) ) int gen_bounds = FALSE;
int grid_is_cyclic = gridIsCircular(gridID);
const double *pvals = gridInqYvalsPtr(gridID);
double *pbounds = NULL;
if ( pvals )
{ {
cdf_def_var(fileID, axisname, xtype, ndims, &dimID, &ncvarid); cdf_def_var(fileID, axisname, xtype, ndims, &dimID, &ncvarid);
...@@ -1403,7 +1413,28 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1403,7 +1413,28 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
cdf_put_att_text(fileID, ncvarid, "axis", 1, "Y"); cdf_put_att_text(fileID, ncvarid, "axis", 1, "Y");
if ( gridInqYboundsPtr(gridID) && nvdimID != UNDEFID ) if ( gridInqYboundsPtr(gridID) )
pbounds = (double*) gridInqYboundsPtr(gridID);
if ( CDI_cmor_mode && grid_is_cyclic && !pbounds )
{
gen_bounds = TRUE;
pbounds = (double*) malloc(2*dimlen*sizeof(double));
for ( size_t i = 0; i < dimlen-1; ++i )
{
pbounds[i*2+1] = (pvals[i] + pvals[i+1])/2;
pbounds[(i+1)*2] = (pvals[i] + pvals[i+1])/2;
}
pbounds[0] = (pvals[0] < 0) ? -90 : 90;
pbounds[2*dimlen-1] = (pvals[dimlen-1] < 0) ? -90 : 90;
}
if ( pbounds )
{
size_t nvertex = 2;
if ( nc_inq_dimid(fileID, BNDS_NAME, &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, BNDS_NAME, nvertex, &nvdimID);
}
if ( pbounds && nvdimID != UNDEFID )
{ {
strcat(axisname, "_"); strcat(axisname, "_");
strcat(axisname, BNDS_NAME); strcat(axisname, BNDS_NAME);
...@@ -1424,8 +1455,9 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims) ...@@ -1424,8 +1455,9 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
cdf_enddef(fileID); cdf_enddef(fileID);
streamptr->ncmode = 2; streamptr->ncmode = 2;
if ( ncvarid != UNDEFID ) cdf_put_var_double(fileID, ncvarid, gridInqYvalsPtr(gridID)); if ( ncvarid != UNDEFID ) cdf_put_var_double(fileID, ncvarid, pvals);
if ( ncbvarid != UNDEFID ) cdf_put_var_double(fileID, ncbvarid, gridInqYboundsPtr(gridID)); if ( ncbvarid != UNDEFID ) cdf_put_var_double(fileID, ncbvarid, pbounds);
if ( gen_bounds ) Free(pbounds);
if ( ndims == 0 ) streamptr->ncyvarID[gridindex] = ncvarid; if ( ndims == 0 ) streamptr->ncyvarID[gridindex] = ncvarid;
} }
......
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