From: Wolfgang Jenkner <wjenkner@inode.at>
To: Mario Lang <mlang@delysid.org>
Cc: Mark Oteiza <mvoteiza@udel.edu>, 19401@debbugs.gnu.org
Subject: bug#19401: 25.0.50; metar.el (metar-convert-temperature) wrong type argument stringp nil
Date: Fri, 19 Feb 2016 19:04:37 +0100 [thread overview]
Message-ID: <85h9h4shje.fsf@iznogoud.viz> (raw)
In-Reply-To: <85387ezbi6.fsf@iznogoud.viz> (Wolfgang Jenkner's message of "Tue, 13 Jan 2015 21:11:45 +0100")
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
On Tue, Jan 13 2015, Wolfgang Jenkner wrote:
> However, it's up to the author to decide if he likes this approach at
> all.
Mario,
Ping :-) Do you mind if I push yesteryear's patch to elpa?
If you want to review it, I'll wait for your approval, of course.
Otherwise, due to popular demand, I'd like to push it in a week or so.
For easier reference, I've also attached it below.
I also proposed a second patch as a work-around for a calc glitch,
however that bug has been fixed in the last emacs release, so I think it
can be omitted.
Wolfgang
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: metar patch --]
[-- Type: text/x-diff, Size: 3816 bytes --]
From bc778d9ac011e1f27cfc85055a8575f39f912d9b Mon Sep 17 00:00:00 2001
From: Wolfgang Jenkner <wjenkner@inode.at>
Date: Sat, 3 Jan 2015 00:34:33 +0100
Subject: [PATCH 1/2] [metar] Fix the case where the metar record contains M01
(bug#19401).
* packages/metar/metar.el (metar-convert-unit): New optional argument.
(metar-convert-temperature): Use it to rewrite this function in terms of
metar-convert-unit.
Pass t as last argument to the underlying calc conversion functions so
that they return only the number, not the unit, thereby fixing the bug
in question.
---
packages/metar/metar.el | 66 ++++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 34 deletions(-)
diff --git a/packages/metar/metar.el b/packages/metar/metar.el
index 7b78f07..9575313 100644
--- a/packages/metar/metar.el
+++ b/packages/metar/metar.el
@@ -239,45 +239,43 @@ If no match if found, nil is returned."
(when station-code
(cons station-code (round best-distance))))))
-(defun metar-convert-unit (value new-unit)
+(defun metar-convert-unit (value new-unit &optional convert-units-function)
"Convert VALUE to NEW-UNIT.
VALUE is a string with the value followed by the unit, like \"5 knot\"
-and NEW-UNIT should be a unit name like \"kph\" or similar."
+and NEW-UNIT should be a unit name like \"kph\" or similar.
+CONVERT-UNITS-FUNCTION designates the function actually doing the conversion.
+It must have the signature of `math-convert-units', which is the default."
(cl-check-type value string)
- (cl-check-type new-unit (or string symbol))
- (cl-multiple-value-bind (value unit)
- (split-string
- (math-format-value
- (math-convert-units (math-simplify (math-read-expr value))
- (math-read-expr
- (cl-etypecase new-unit
- (string new-unit)
- (symbol (symbol-name new-unit))))))
- " ")
- (cons (string-to-number value) (intern unit))))
+ (unless (symbolp new-unit)
+ (setq new-unit (intern new-unit)))
+ (let ((expr (math-simplify (math-read-expr value))))
+ (cl-assert (or (math-zerop expr)
+ (not (memq (math-single-units-in-expr-p expr) '(nil wrong))))
+ nil
+ "Metar: Not exactly one unit in expression: %S" expr)
+ (let ((res (math-simplify-units
+ (funcall (or convert-units-function 'math-convert-units)
+ expr
+ (math-build-var-name new-unit)
+ t))))
+ (cl-assert (math-realp res) nil
+ "Metar: Not a Calc real number: %S" res)
+ (cons (string-to-number (math-format-value (if (integerp res)
+ res
+ (math-float res))))
+ new-unit))))
(defun metar-convert-temperature (string &optional unit)
- (let* ((value (concat (if (= (aref string 0) ?M)
- (concat "-" (substring string 1))
- string)
- "degC"))
- (expr (math-read-expr value))
- (old-unit (math-single-units-in-expr-p expr))
- (new-unit (or unit (cdr (assq 'temperature metar-units)))))
- (if old-unit
- (cl-multiple-value-bind (value unit)
- (split-string
- (math-format-value
- (math-simplify-units
- (math-convert-temperature
- expr
- (list 'var
- (car old-unit)
- (intern (concat "var-" (symbol-name (car old-unit)))))
- (math-read-expr (cl-etypecase new-unit
- (string new-unit)
- (symbol (symbol-name new-unit))))))) " ")
- (cons (string-to-number value) (intern unit))))))
+ (metar-convert-unit (concat (if (= (aref string 0) ?M)
+ (concat "-" (substring string 1))
+ string)
+ "degC")
+ (or unit (cdr (assq 'temperature metar-units)))
+ (lambda (expr new-unit-var pure)
+ (math-convert-temperature expr
+ (math-build-var-name 'degC)
+ new-unit-var
+ pure))))
(defcustom metar-url
"http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT"
--
2.7.0
next prev parent reply other threads:[~2016-02-19 18:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-17 21:15 bug#19401: 25.0.50; metar.el (metar-convert-temperature) wrong type argument stringp nil Mark Oteiza
2014-12-18 14:29 ` Ulf Jasper
2014-12-18 14:51 ` Mark Oteiza
2014-12-18 17:00 ` Ulf Jasper
2015-01-13 14:34 ` Wolfgang Jenkner
2015-01-13 17:57 ` Ulf Jasper
2015-01-13 20:11 ` Wolfgang Jenkner
2016-02-19 18:04 ` Wolfgang Jenkner [this message]
2016-02-26 15:50 ` Wolfgang Jenkner
2016-02-29 19:28 ` Wolfgang Jenkner
2015-01-14 1:47 ` Wolfgang Jenkner
2015-12-29 20:26 ` Mark Oteiza
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85h9h4shje.fsf@iznogoud.viz \
--to=wjenkner@inode.at \
--cc=19401@debbugs.gnu.org \
--cc=mlang@delysid.org \
--cc=mvoteiza@udel.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.