[GRASS-dev] [GRASS GIS] #1685: r.in.ascii -s for SURFER does not work in grass7

#1685: r.in.ascii -s for SURFER does not work in grass7
-----------------------------------+----------------------------------------
Reporter: helena | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 7.0.0
Component: Raster | Version: svn-trunk
Keywords: raster import, Surfer | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------------------+----------------------------------------
r.in.ascii -s for SURFER gives
ERROR: Unable to seek in GRASS7

same file can be imported using r.in.gdal

should we keep the -s flag in r.in.ascii and fix the bug or
leave r.in.ascii for GRASS ascii rasters only?

Helena

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1685&gt;
GRASS GIS <http://grass.osgeo.org>

#1685: r.in.ascii -s for SURFER does not work in grass7
-----------------------------------------------+----------------------------
Reporter: helena | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 7.0.0
Component: Raster | Version: svn-trunk
Keywords: raster import, Surfer, r.in.ascii | Platform: All
      Cpu: OSX/Intel |
-----------------------------------------------+----------------------------
Changes (by hamish):

  * keywords: raster import, Surfer => raster import, Surfer, r.in.ascii
  * platform: MacOSX => All

Comment:

the error message in g7 lib/gis/seek.c is now just "Unable to seek"; it's
not a fundamental limitation just a regular bug AFAICT.

I found a binary Surfer6 grid file sitting on an old drive, and could
convert it to an ascii grid:
{{{
   gdal_translate -of GSAG helens2.grd helens2a.grd
   r.in.ascii -s in=helens2a.grd out=helens2
}}}

and I can reproduce your error. It happens in r.in.ascii/main.c on this
G_fseek(), while processing the last row of the map.

{{{
     for (row = 0; row < nrows; row += 1) {
         fread(rast, Rast_cell_size(data_type), ncols, ft);
         Rast_put_row(cf, rast, data_type);
         G_fseek(ft, sz, SEEK_CUR);
     }
     fclose(ft);
     unlink(temp);

     Rast_close(cf);
}}}

G_ftell(ft) reports the position as 1308 but G_fseek() wants to move
sz=-2616 bytes (negative as surfer ascii grids are stored bottom to top),
and runs past the end (i.e. start) of the file. note 1308*2 = 2616. I
presume the array is off by 1 row and the first line of data is either
repeated or empty.

here is row, nrows, sz, and on the newline G_ftell() position for the last
few rows:
{{{
460 466 -2616
7848
461 466 -2616
6540
462 466 -2616
5232
463 466 -2616
3924
464 466 -2616
2616
465 466 -2616
1308
ERROR: Unable to seek
}}}

The import works fine in grass 6.x.

Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1685#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1685: r.in.ascii -s for SURFER does not work in grass7
-----------------------------------------------+----------------------------
Reporter: helena | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 7.0.0
Component: Raster | Version: svn-trunk
Keywords: raster import, Surfer, r.in.ascii | Platform: All
      Cpu: OSX/Intel |
-----------------------------------------------+----------------------------

Comment(by mmetz):

Replying to [comment:1 hamish]:
> the error message in g7 lib/gis/seek.c is now just "Unable to seek";
it's not a fundamental limitation just a regular bug AFAICT.
>
In GRASS 6.x, r.in.ascii would have the same bug if it would check the
return value of fseek() (it might be a good idea to check the return value
of fread() as well). The attached fix is simply to not fseek after the
last row has been read from the input file, that must fail if direction <
0. For sz == 0, fseek from SEEK_CUR has no effect anyway.

Markus M

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1685#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1685: r.in.ascii -s for SURFER does not work in grass7
-----------------------------------------------+----------------------------
Reporter: helena | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 7.0.0
Component: Raster | Version: svn-trunk
Keywords: raster import, Surfer, r.in.ascii | Platform: All
      Cpu: OSX/Intel |
-----------------------------------------------+----------------------------

Comment(by neteler):

See also #1848 for another G_fseek() ticket.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1685#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1685: r.in.ascii -s for SURFER does not work in grass7
-----------------------------------------------+----------------------------
Reporter: helena | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 7.0.0
Component: Raster | Version: svn-trunk
Keywords: raster import, Surfer, r.in.ascii | Platform: All
      Cpu: OSX/Intel |
-----------------------------------------------+----------------------------

Comment(by wenzeslaus):

I suppose this is still valid, patch was not applied:

  * grass/trunk/raster/r.in.ascii/main.c?rev=63013

Any SURFER file which could be used for a test?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1685#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>