Hi,
2007/11/25, Hamish <hamish_nospam@yahoo.com>:
Fwd from Ivan, I wonder how G_scan_easting() and G_scan_northing() fit into
I do not fully understand this notation
this problem? (for 1.2345e6 not 123:45:54.321E; 31E needs to be considered
East)
anyway
$ cat pok.txt
123:45:54.321E|80N
1.2376508917e2|80N
$ v.in.ascii in=pok.txt out=pok
$ v.out.ascii pok
123.76508917|80|1
123.76508917|80|2
works for me...
Martin
--Hamish
Note: forwarded message attached.
____________________________________________________________________________________
Be a better sports nut! Let your teams follow you
with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
---------- Messaggio inoltrato ----------
From: Ivan Shmakov <ivan@theory.asu.ru>
To: Hamish <hamish_nospam@yahoo.com>
Date: Sun, 25 Nov 2007 15:36:50 +0600
Subject: Re: [GRASS-user] scientific notation
[...]
>> Can GRASS actualy deal with number written with scientific notation ?
>> Is there a specific way to deal with these numbers ?
> v.in.ascii coulumn scanning code seems to overlook that case.
[...]
Since my message has apparently not reached grass-dev, and since
you're interested in this problem, I'm forwarding it to you.
The problem seems to me somewhat trivial to solve.
---------- Messaggio inoltrato ----------
From: Ivan Shmakov <ivan@theory.asu.ru>
To: Martin Landa <landa.martin@gmail.com>
Date: Sat, 24 Nov 2007 22:35:48 +0600
Subject: Re: scientific notation
>>>>> Martin Landa <landa.martin@gmail.com> writes:
[...]
>> I would like to import points data in GRASS (with v.in.ascii). My
>> data includes number written with the scientific notation (for
>> example 1.2e+23). During the import, I am defining them as double.
>> Unfortunately, it doesn't work...
>> I get the following message :
>> " ERROR: Column 9 defined as double has string values "
>> Can GRASS actualy deal with number written with scientific notation ?
>> Is there a specific way to deal with these numbers ?
> no, it seems, v.in.ascii doesn't support it...
It seems that it's the is_double () function which behaves in a
wrong way:
$ nl -ba grass-6.3.cvs_src_snapshot_2007_11_03/vector/v.in.ascii/points.c
...
30 /* Determine if the string is double, e.g. 123.456, +123.456, -123.456
31 * return 1 if double, 0 otherwise */
32 static int is_double(char *str)
33 {
34 int i = -1, ndots = 0;
35
36 while (str[++i] != '\0') {
37 if (i == 0 && (str[i] == '+' || str[i] == '-'))
38 continue;
39
40 if (str[i] == '.') {
41 if (ndots > 0)
42 return 0; /* > 1 dot */
43
44 ndots++;
45 continue;
46 }
47
48 if (!isdigit(str[i]))
49 return 0;
50 }
51
52 return 1;
53 }
...
$
IIUC, the number is to be converted from its string
representation by atof () later. Since, I assume, atof ()
supports e-notation, there's no necessity in such a strict check
like is_double () currently performs. Therefore, I suggest
is_double () to be reimplemented on top of strtod () instead,
e. g.:
static int
is_double (char *s)
{
char *tail;
if (strtod (s, &tail),
tail == s || *tail != '\0') {
/* doesn't look like a number,
or has extra characters after what looks to be a number */
return 0;
}
return 1;
}
BTW, is_int () could be rewritten as well.
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev
--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *