Changeset 25353


Ignore:
Timestamp:
Nov 25, 2007, 3:09:36 AM (17 years ago)
Author:
martinl
Message:

Enable to read numbers given in scientific notation (thanks to Ivan Shmakov <ivan theory.asu.ru>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/vector/v.in.ascii/points.c

    r24032 r25353  
    99#include "local_proto.h"
    1010
    11 
    12 /* Determine if the string is integer, e.g. 123, +123, -123
     11/* Determine if the string is integer, e.g. 123, +123, -123,
    1312 * return 1 if integer, 0 otherwise */
    1413static int is_int(char *str)
    1514{
    16     int i = -1;
    17 
    18     while (str[++i] != '\0') {
    19         if (i == 0 && (str[i] == '+' || str[i] == '-'))
    20             continue;
    21 
    22         if (!isdigit(str[i]))
    23             return 0;
     15    char *tail;
     16
     17    if (strtol (str, &tail, 10),
     18        tail == str || *tail != '\0') {
     19        /* doesn't look like a number,
     20           or has extra characters after what looks to be a number */
     21        return 0;
    2422    }
    2523
     
    2826
    2927
    30 /* Determine if the string is double, e.g. 123.456, +123.456, -123.456
     28/* Determine if the string is double, e.g. 123.456, +123.456, -123.456, 1.23456e2
    3129 * return 1 if double, 0 otherwise */
    3230static int is_double(char *str)
    3331{
    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;
     32    char *tail;
     33
     34    if (strtod (str, &tail),
     35        tail == str || *tail != '\0') {
     36        /* doesn't look like a number,
     37           or has extra characters after what looks to be a number */
     38        return 0;
    5039    }
    5140
    5241    return 1;
    5342}
     43
    5444
    5545
     
    9282    sav_buf = NULL;
    9383
    94     G_message(_("Scanning input for column types ..."));
     84    G_message(_("Scanning input for column types..."));
    9585    /* fetch projection for LatLong test */
    9686    G_get_window(&window);
     
    218208                    row, i, tokens[i], is_int(tokens[i]), is_double(tokens[i]));
    219209
    220             if (is_int(tokens[i]))
     210            if (is_int(tokens[i])) {
    221211                continue;       /* integer */
     212            }
    222213            if (is_double(tokens[i])) { /* double */
    223214                if (coltype[i] == DB_C_TYPE_INT) {
     
    255246
    256247    if (region_flag)
    257         G_message(_("Skipping [%d] of [%d] rows falling outside of current region"),
     248        G_message(_("Skipping %d of %d rows falling outside of current region"),
    258249                  skipped, row-1);
    259250
     
    283274    struct Cell_head window;
    284275
    285     G_message(_("Importing points ..."));
     276    G_message(_("Importing points..."));
    286277    /* fetch projection for LatLong test */
    287278    G_get_window(&window);
     
    395386
    396387            if (db_execute_immediate(driver, &sql) != DB_OK) {
    397                 G_fatal_error(_("Cannot insert values: %s"), db_get_string(&sql));
     388                G_fatal_error(_("Unable to insert new record: %s"),
     389                              db_get_string(&sql));
    398390            }
    399391        }
Note: See TracChangeset for help on using the changeset viewer.