emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/metar e891727 09/16: [metar] Unify station lat/lon conv


From: Stefan Monnier
Subject: [elpa] externals/metar e891727 09/16: [metar] Unify station lat/lon conversion.
Date: Sat, 28 Nov 2020 23:16:37 -0500 (EST)

branch: externals/metar
commit e89172797470035e6178c39df90276ccb0caad78
Author: Mario Lang <mlang@delysid.org>
Commit: Mario Lang <mlang@delysid.org>

    [metar] Unify station lat/lon conversion.
---
 metar.el | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/metar.el b/metar.el
index 182e805..82b83b7 100644
--- a/metar.el
+++ b/metar.el
@@ -92,39 +92,20 @@
   "Variable containing (cached) METAR station information.
 Use the function `metar-stations' to get the actual station list.")
 
-(defun metar-station-convert-latitude (string)
+(defun metar-station-convert-dms-to-deg (string)
+  "Convert degrees, minutes and optional seconds, to degrees."
   (when (string-match (rx string-start
-                         (group (1+ digit))
-                         ?-
-                         (group (1+ digit))
+                         (group (1+ digit)) ?- (group (1+ digit))
                          (optional ?- (group (1+ digit)))
-                         (group (char ?N ?S))
+                         (group (char ?N ?E ?S ?W))
                          string-end) string)
-    (funcall (if (string= (match-string 4 string) "N") #'+ #'-)
+    (funcall (if (memq (aref (match-string 4 string) 0) '(?N ?E)) #'+ #'-)
             (+ (string-to-number (match-string 1 string))
-               (/ (string-to-number (match-string 2 string))
-                  60.0)
+               (/ (string-to-number (match-string 2 string)) 60.0)
                (if (match-string 3 string)
                    (/ (string-to-number (match-string 3 string)) 3600.0)
                  0)))))
 
-(defun metar-station-convert-longitude (string)
-  (when (string-match (rx string-start
-                         (group (1+ digit))
-                         ?-
-                         (group (1+ digit))
-                         (optional ?- (group (1+ digit)))
-                         (group (char ?E ?W))
-                         string-end) string)
-    (funcall (if (string= (match-string 4 string) "E") #'+ #'-)
-            (+ (string-to-number (match-string 1 string))
-               (/ (string-to-number (match-string 2 string))
-                  60.0)
-               (if (match-string 3 string)
-                   (/ (string-to-number (match-string 3 string))
-                      3600.0)
-                 0)))))
-
 (defun metar-stations ()
   "Retrieve a list of METAR stations.
 Results are cached in variable `metar-stations'.
@@ -147,9 +128,9 @@ If this variable is nil, the information is retrieved from 
the Internet."
                            (cons 'name (nth 3 item))
                            (cons 'country (nth 5 item))
                            (cons 'latitude
-                                 (metar-station-convert-latitude (nth 7 item)))
+                                 (metar-station-convert-dms-to-deg (nth 7 
item)))
                            (cons 'longitude
-                                 (metar-station-convert-longitude (nth 8 
item)))
+                                 (metar-station-convert-dms-to-deg (nth 8 
item)))
                            (cons 'altitude (string-to-number (nth 12 item))))))
                   metar-stations)))
          (setq data (cdr data)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]