Mercurial > geeqie
comparison src/metadata.c @ 1509:e70bbc97acc5
added metadata_read_GPS_coord
author | nadvornik |
---|---|
date | Sat, 04 Apr 2009 19:10:49 +0000 |
parents | 1e2737565cb7 |
children | 24a12aa0cb54 |
comparison
equal
deleted
inserted
replaced
1508:23d24af93ab0 | 1509:e70bbc97acc5 |
---|---|
513 ret = g_ascii_strtoull(string, &endptr, 10); | 513 ret = g_ascii_strtoull(string, &endptr, 10); |
514 if (string == endptr) ret = fallback; | 514 if (string == endptr) ret = fallback; |
515 g_free(string); | 515 g_free(string); |
516 return ret; | 516 return ret; |
517 } | 517 } |
518 | |
519 gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback) | |
520 { | |
521 gdouble coord; | |
522 gchar *endptr; | |
523 gdouble deg, min, sec; | |
524 gboolean ok = FALSE; | |
525 gchar *string = metadata_read_string(fd, key, METADATA_PLAIN); | |
526 if (!string) return fallback; | |
527 | |
528 deg = g_ascii_strtod(string, &endptr); | |
529 if (*endptr == ',') | |
530 { | |
531 min = g_ascii_strtod(endptr + 1, &endptr); | |
532 if (*endptr == ',') | |
533 sec = g_ascii_strtod(endptr + 1, &endptr); | |
534 else | |
535 sec = 0.0; | |
536 | |
537 | |
538 if (*endptr == 'S' || *endptr == 'W' || *endptr == 'N' || *endptr == 'E') | |
539 { | |
540 coord = deg + min /60.0 + sec / 3600.0; | |
541 ok = TRUE; | |
542 if (*endptr == 'S' || *endptr == 'W') coord = -coord; | |
543 } | |
544 } | |
545 | |
546 if (!ok) | |
547 { | |
548 coord = fallback; | |
549 log_printf("unable to parse GPS coordinate '%s'\n", string); | |
550 } | |
551 | |
552 g_free(string); | |
553 return coord; | |
554 } | |
518 | 555 |
519 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value) | 556 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value) |
520 { | 557 { |
521 gchar *str = metadata_read_string(fd, key, METADATA_PLAIN); | 558 gchar *str = metadata_read_string(fd, key, METADATA_PLAIN); |
522 | 559 |