Commit 16295b34 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

gridGenXvals/gridGenYvals: recheck xinc/yinc if fi(xfirst+(size-1)*inc) > last

parent 45e092a6
......@@ -3,6 +3,7 @@
#endif
#include <string.h>
#include <float.h> /* FLT_EPSILON */
#ifdef USE_MPI
#include <mpi.h>
......@@ -210,22 +211,27 @@ int gridSize(void)
void gridGenXvals(int xsize, double xfirst, double xlast, double xinc, double *xvals)
{
long i;
if ( (! (fabs(xinc) > 0)) && xsize > 1 )
if ( xsize > 1 )
{
if ( xfirst >= xlast )
if ( (fabs(xinc) > 0) && (xlast > xfirst) && (fabs(xinc*1000 - NINT(xinc*1000)) <= FLT_EPSILON) )
{
while ( xfirst >= xlast ) xlast += 360;
xinc = (xlast-xfirst)/(xsize);
if ( (xfirst + (xsize-1)*xinc) > xlast ) xinc = (xlast-xfirst)/(xsize-1);
}
else
{
xinc = (xlast-xfirst)/(xsize-1);
if ( xfirst >= xlast )
{
while ( xfirst >= xlast ) xlast += 360;
xinc = (xlast-xfirst)/(xsize);
}
else
{
xinc = (xlast-xfirst)/(xsize-1);
}
}
}
for ( i = 0; i < xsize; i++ )
for ( int i = 0; i < xsize; ++i )
xvals[i] = xfirst + i*xinc;
}
......@@ -311,9 +317,13 @@ void gridGenYvals(int gridtype, int ysize, double yfirst, double ylast, double y
}
}
/* else if ( gridtype == GRID_LONLAT || gridtype == GRID_GENERIC ) */
else
else if ( ysize > 1 )
{
if ( (! (fabs(yinc) > 0)) && ysize > 1 )
if ( (fabs(yinc) > 0) && (fabs(yinc*1000 - NINT(yinc*1000)) <= FLT_EPSILON) )
{
if ( (yfirst + (ysize-1)*yinc) > ylast ) yinc = (ylast-yfirst)/(ysize-1);
}
else
{
if ( IS_EQUAL(yfirst, ylast) && IS_NOT_EQUAL(yfirst, 0) ) ylast *= -1;
......
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