[GRASS-dev] isnan() in i.atcorr

i.atcorr uses the isnan() function which seems to cause compilation to fail on Windows:

sh-2.04$ make
c++ -I/c/grass/grass7/dist.i686-pc-mingw32/include -I/c/grass/extra/include -O2 -s -I/c/grass/extra/include -DPACKAGE=\""grassmods"\" -I/c/grass/grass7/dist.i686-pc-mingw32/include -o OBJ.i686-pc-mingw32/main.o -c main.cpp
main.cpp: In function `void process_raster(int, InputMask, ScaleRange, int, int, int, bool, ScaleRange, bool)':
main.cpp:309: error: `isnan' was not declared in this scope
make: *** [OBJ.i686-pc-mingw32/main.o] Error 1
sh-2.04$

main.cpp includes <cmath>; I wonder if the problem is due to the fact isnan() is a C99 function? Should it be changed?

Paul

Paul Kelly wrote:

i.atcorr uses the isnan() function which seems to cause compilation to
fail on Windows:

sh-2.04$ make
c++ -I/c/grass/grass7/dist.i686-pc-mingw32/include -I/c/grass/extra/include -O2 -s -I/c/grass/extra/include -DPACKAGE=\""grassmods"\" -I/c/grass/grass7/dist.i686-pc-mingw32/include -o OBJ.i686-pc-mingw32/main.o -c main.cpp
main.cpp: In function `void process_raster(int, InputMask, ScaleRange, int, int, int, bool, ScaleRange, bool)':
main.cpp:309: error: `isnan' was not declared in this scope
make: *** [OBJ.i686-pc-mingw32/main.o] Error 1
sh-2.04$

main.cpp includes <cmath>; I wonder if the problem is due to the fact
isnan() is a C99 function? Should it be changed?

Yes. This came up about a month ago:

  http://lists.osgeo.org/pipermail/grass-dev/2008-September/039910.html

I thought it had been fixed already.

--
Glynn Clements <glynn@gclements.plus.com>

Paul Kelly wrote:

i.atcorr uses the isnan() function which seems to cause
compilation to fail on Windows:

....

main.cpp includes <cmath>; I wonder if the problem is
due to the fact isnan() is a C99 function? Should it be changed?

if it helps, there is a is_nan() in r.in.mat/main.c:

int is_nan(void *p, RASTER_MAP_TYPE dtype)

{
    /* fn to test if incoming data point is either a IEEE NaN or a GRASS CELL null
     *
     * Takes a value of type RASTER_MAP_TYPE stored at memory address "p"
     * Returns 1 if we think it is a null, 0 otherwise
     */

    /* please improve */

....
}

it uses the 'if(a != a)' method.

Hamish

On Tue, 7 Oct 2008, Glynn Clements wrote:

Paul Kelly wrote:

main.cpp includes <cmath>; I wonder if the problem is due to the fact
isnan() is a C99 function? Should it be changed?

Yes. This came up about a month ago:

  http://lists.osgeo.org/pipermail/grass-dev/2008-September/039910.html

I thought it had been fixed already.

On closer inspection (and using a comment in the code as a hint), I think i.atcorr is using isnan() where it wants to be using G_is_f_null_value(), i.e. this:
/* TODO: use G_set_f_null_value()?? */
             if(vis && isnan(vis[col]) || alt && isnan(alt[col]) || isnan(buf[col])) {buf[col] = FP_NAN; continue;}
should really be:
             if(vis && G_is_f_null_value(&vis[col]) ||
                alt && G_is_f_null_value(&alt[col]) ||
                G_is_f_null_value(&buf[col]))
             {
                 G_set_f_null_value(&buf[col], 1);
                 continue;
             }

Any objections to me committing this?

Paul

Paul Kelly wrote:

>> main.cpp includes <cmath>; I wonder if the problem is due to the fact
>> isnan() is a C99 function? Should it be changed?
>
> Yes. This came up about a month ago:
>
> http://lists.osgeo.org/pipermail/grass-dev/2008-September/039910.html
>
> I thought it had been fixed already.

On closer inspection (and using a comment in the code as a hint), I think
i.atcorr is using isnan() where it wants to be using G_is_f_null_value(),
i.e. this:
/* TODO: use G_set_f_null_value()?? */
             if(vis && isnan(vis[col]) || alt && isnan(alt[col]) || isnan(buf[col])) {buf[col] = FP_NAN; continue;}
should really be:
             if(vis && G_is_f_null_value(&vis[col]) ||
                alt && G_is_f_null_value(&alt[col]) ||
                G_is_f_null_value(&buf[col]))
             {
                 G_set_f_null_value(&buf[col], 1);
                 continue;
             }

Any objections to me committing this?

None here.

FWIW, I've changed G_is_[fd]_null_value() to treat all NaNs as nulls,
not just the all-ones bit pattern.

--
Glynn Clements <glynn@gclements.plus.com>