Roger Bivand wrote:
> just found (obviously) a bug in r.in.ascii/r.out.ascii:
>
> if you export/import the same map several times, it get's
> shifted each time!
>
> r.out.ascii in=dem out=dem0.asc
> r.in.ascii in=dem0.asc out=dem1
>
> r.out.ascii in=dem1 out=dem1.asc
> r.in.ascii in=dem1.asc out=dem2
>
> r.out.ascii in=dem2 out=dem2.asc
> r.in.ascii in=dem2.asc out=dem3
> d.rast dem
> d.rast dem1
> d.rast dem2
> d.rast dem3
>
> As being lack of time today, any volunteers?
Looks to me as if fseek is moving one byte too far back in the buffer on
line 142 in r.in.ascii/cmd/gethead.c, putting the last digit of the number
of columns as the first cell value read. Since it is followed by a
newline, it is treated as value.
fseek(fd, -(len+1), SEEK_CUR);
For me, fseek(fd, -(len), SEEK_CUR); fixes it, but I haven't tried
it with other header fields or command line options.
Suggestion: call ftell() before G_getl() and use fseek(SEEK_SET) to
restore the position. Alternatively, you could use fgetpos() and
fsetpos(); these are more portable, but that probably isn't an issue
here.
--
Glynn Clements <glynn.clements@virgin.net>
From neteler Mon Jul 2 10:16:22 2001
Return-Path: <neteler>
Received: by hgeo02.geog.uni-hannover.de (SMI-8.6/SMI-SVR4)
id KAA04622; Mon, 2 Jul 2001 10:16:22 +0100
Date: Mon, 2 Jul 2001 10:16:22 +0100
From: Markus Neteler <neteler@geog.uni-hannover.de>
To: grass5 developers list <grass5@geog.uni-hannover.de>
Subject: Re: [GRASS5] shift bug in r.in.ascii/r.out.ascii
Message-ID: <20010702101622.N16481@hgeo02.geog.uni-hannover.de>
Mail-Followup-To: grass5 developers list <grass5@geog.uni-hannover.de>
References: <20010629151210.L16481@hgeo02.geog.uni-hannover.de> <Pine.LNX.4.21.0106291928330.2921-100000@reclus.nhh.no> <15164.50234.521459.627900@cerise.nosuchdomain.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5i
In-Reply-To: <15164.50234.521459.627900@cerise.nosuchdomain.co.uk>; from glynn.clements@virgin.net on Fri, Jun 29, 2001 at 07:08:58PM +0100
Sender: grass5-admin@geog.uni-hannover.de
Errors-To: grass5-admin@geog.uni-hannover.de
X-BeenThere: grass5@geog.uni-hannover.de
X-Mailman-Version: 2.0.5
Precedence: bulk
List-Help: <mailto:grass5-request@geog.uni-hannover.de?subject=help>
List-Post: <mailto:grass5@geog.uni-hannover.de>
List-Subscribe: <http://www.geog.uni-hannover.de/mailman/listinfo/grass5>,
<mailto:grass5-request@geog.uni-hannover.de?subject=subscribe>
List-Id: GRASS 5 Developers mailing list <grass5.geog.uni-hannover.de>
List-Unsubscribe: <http://www.geog.uni-hannover.de/mailman/listinfo/grass5>,
<mailto:grass5-request@geog.uni-hannover.de?subject=unsubscribe>
List-Archive: <http://www.geog.uni-hannover.de/pipermail/grass5/>
Status: O
Content-Length: 1579
Lines: 46
On Fri, Jun 29, 2001 at 07:08:58PM +0100, Glynn Clements wrote:
Roger Bivand wrote:
> > just found (obviously) a bug in r.in.ascii/r.out.ascii:
> >
> > if you export/import the same map several times, it get's
> > shifted each time!
> >
> > r.out.ascii in=dem out=dem0.asc
> > r.in.ascii in=dem0.asc out=dem1
> >
> > r.out.ascii in=dem1 out=dem1.asc
> > r.in.ascii in=dem1.asc out=dem2
> >
> > r.out.ascii in=dem2 out=dem2.asc
> > r.in.ascii in=dem2.asc out=dem3
> > d.rast dem
> > d.rast dem1
> > d.rast dem2
> > d.rast dem3
> >
> > As being lack of time today, any volunteers?
>
> Looks to me as if fseek is moving one byte too far back in the buffer on
> line 142 in r.in.ascii/cmd/gethead.c, putting the last digit of the number
> of columns as the first cell value read. Since it is followed by a
> newline, it is treated as value.
> fseek(fd, -(len+1), SEEK_CUR);
>
> For me, fseek(fd, -(len), SEEK_CUR); fixes it, but I haven't tried
> it with other header fields or command line options.
Suggestion: call ftell() before G_getl() and use fseek(SEEK_SET) to
restore the position. Alternatively, you could use fgetpos() and
fsetpos(); these are more portable, but that probably isn't an issue
here.
Thanks for your help! I've tried Roger's suggestion and tested in a
Transverse Mercator and a lat/long location - it seems to work.
This version is uploaded to CVS now.
Glynn, do you think your idea is to be preferred?
Markus
From neteler Mon Jul 2 10:29:08 2001
Return-Path: <neteler>
Received: by hgeo02.geog.uni-hannover.de (SMI-8.6/SMI-SVR4)
id KAA04712; Mon, 2 Jul 2001 10:29:08 +0100
Date: Mon, 2 Jul 2001 10:29:07 +0100
From: Markus Neteler <neteler@geog.uni-hannover.de>
To: Roger Bivand <Roger.Bivand@nhh.no>
Cc: grass5 developers list <grass5@geog.uni-hannover.de>
Subject: Re: [GRASS5] shift bug in r.in.ascii/r.out.ascii
Message-ID: <20010702102907.O16481@hgeo02.geog.uni-hannover.de>
Mail-Followup-To: Roger Bivand <Roger.Bivand@nhh.no>,
grass5 developers list <grass5@geog.uni-hannover.de>
References: <20010629151210.L16481@hgeo02.geog.uni-hannover.de> <Pine.LNX.4.21.0106292127450.2921-200000@reclus.nhh.no>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5i
In-Reply-To: <Pine.LNX.4.21.0106292127450.2921-200000@reclus.nhh.no>; from Roger.Bivand@nhh.no on Fri, Jun 29, 2001 at 09:29:48PM +0200
Sender: grass5-admin@geog.uni-hannover.de
Errors-To: grass5-admin@geog.uni-hannover.de
X-BeenThere: grass5@geog.uni-hannover.de
X-Mailman-Version: 2.0.5
Precedence: bulk
List-Help: <mailto:grass5-request@geog.uni-hannover.de?subject=help>
List-Post: <mailto:grass5@geog.uni-hannover.de>
List-Subscribe: <http://www.geog.uni-hannover.de/mailman/listinfo/grass5>,
<mailto:grass5-request@geog.uni-hannover.de?subject=subscribe>
List-Id: GRASS 5 Developers mailing list <grass5.geog.uni-hannover.de>
List-Unsubscribe: <http://www.geog.uni-hannover.de/mailman/listinfo/grass5>,
<mailto:grass5-request@geog.uni-hannover.de?subject=unsubscribe>
List-Archive: <http://www.geog.uni-hannover.de/pipermail/grass5/>
Status: O
Content-Length: 411
Lines: 13
On Fri, Jun 29, 2001 at 09:29:48PM +0200, Roger Bivand wrote:
Markus:
Herewith the fix with Glynn's suggestion. I still haven't tested it with
more headers than r.out.ascii gives, or with command-line options set, but
this ought to be OK? (???)
Roger
... o.k (have been overlooking this mail). Thanks for sending the file,
I have tested as well, now Glynn's version is in place in CVS.
Markus