[GRASS-dev] Re: [GRASS-user] low radiance values after i.atcor and i.topo.corr

Markus Neteler neteler at osgeo.org
Mon Jun 23 15:23:14 EDT 2008


On Mon, Jun 23, 2008 at 7:04 PM, Glynn Clements
<glynn at gclements.plus.com> wrote:
>
> Markus Neteler wrote:
>
> > >> > And i.smap is gibberish; e.g. write_img() calls G_is_c_null_value() on
> > >> > "char"s, so that module probably hasn't worked since 4.x.
> > >>
> > >> i.smap works, I have tested it recently and also others use it regularly.
> > >
> > > Oh, it may produce output, but not necessarily correct output.
> > >
> > > Specifically, write_img() does:
> > >
> > >           if(G_is_c_null_value((CELL *)&img[row][col]))
> > >                   G_set_c_null_value(&files->cellbuf[col], 1);
> > >
> > > But "img" is a "unsigned char **", i.e. a 2D array of bytes. The test
> > > will only succeed if the array contains the sequence 00,00,00,80 (for
> > > little-endian systems) or 80,00,00,00 (big-endian systems). I suspect
> > > that the test was originally against zero, but it was incorrectly
> > > changed when null support was added.
> > >
> > > If that's the case, the net result will be that it writes garbage
> > > where it should be writing nulls, and occasionally writes nulls where
> > > it shouldn't.
> >
> > That sounds quite ugly. But from looking at the code: is a major
> > rewrite needed to fix that? Since we "just" write out classes?
>
> For now, I have just disabled the test:
>
>           if(0 && img[row][col] == 0)
>                G_set_c_null_value(&files->outbuf[col], 1);
>
> so it will never write out nulls. Previously, these would have been
> relatively uncommon anyhow.
>
> I initially suspected that the test should have been against zero, but
> in retrospect, it may have been completely absent (i.e. the change was
> made on the assumption that zero represented null when it actually
> represented zero).
>
> Ultimatly, you would need to look at a pre-5.x version (or to actually
> understand the code) in order to determine what it should be doing.

here is the 4.3 code:
grass4.3src/src/imagery/i.smap/cmd/shapiro/write_img.c

#include "imagery.h"
#include "files.h"
#include "parms.h"

write_img (img, ncols, nrows, S, parms, files)
    unsigned char **img;
    struct SigSet *S;            /* class parameters */
    struct parms *parms;         /* parms: command line parameters */
    struct files *files;         /* files: contains file to output */
{
    int row, col;
    int class;
    if (!parms->quiet) fprintf (stderr, "Writing %s ... ", parms->output_map);

    for (row = 0; row < nrows; row++)
    {
        if (!parms->quiet) G_percent (row, nrows, 2);
        for (col = 0; col < ncols; col++)
        {
                class = (int)img[row][col];
                files->cellbuf[col] = (CELL)S->ClassSig[class].classnum;
        }
        G_put_map_row (files->output_fd, files->cellbuf);
    }
    if (!parms->quiet) G_percent (row, nrows, 2);
}


Markus


More information about the grass-dev mailing list