Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.emacs.help > #60677

elisp program nautical - more elegant way?

From Richard Smith <null@void.com>
Newsgroups gnu.emacs.help
Subject elisp program nautical - more elegant way?
Date 2023-03-15 07:47 +0000
Organization BlueWorld Hosting Usenet (https://usenet.blueworldhosting.com)
Message-ID <lybkkupibq.fsf@void.com> (permalink)

Show all headers | View raw


Hi there.
Pardon asking on
gnu.emacs.help
with simple programming question.

Program runs inside emacs, but does a nautical calculation - converts
Google Maps' latitude and longitude in degrees-decimal to the Degrees
Minutes and Seconds of a nautical chart - the human-usable type which
has been around for centuries.

Question is - is there a better way of doing my calculation?
My skills are centred on metals and welding - hence what I have done
which seems to work might be a risible way of doing the task.

I looked on the web, and if I understand rightly those using an "algol
family" eg. BASIC language do something like.

The printed format with zero-padding - that is for the nautical
purpose of reminding you to state the zero's on radio-messages.


;;; When copying-and-pasting "Google Maps" degdeci lat. and long.,
;;; delete the comma between the values !!!


(defun lat-long-degdeci-to-dms (latdeci longdeci)
  (format "%s %s %s"
   (abs-degdeci-to-abs-deg-min-sec (abs latdeci) (if (minusp latdeci) 'S 'N))
   " " ;; easy jdi customisable way to separate lat. and long. output 
   (abs-degdeci-to-abs-deg-min-sec (abs longdeci) (if (minusp longdeci) 'W 'E))))


(defun abs-degdeci-to-abs-deg-min-sec (absdegdeci dirncardinal)
  "Deg-decimal to DMS format output"
  (if (minusp absdegdeci)
      "error - cannot handle negative arguments"
    (let ((decix60 (* (mod absdegdeci 1) 60)))
      (format "%03dd %02d' %04.1f'' %s" (truncate absdegdeci) (truncate decix60) (* (mod decix60 1) 60) dirncardinal))))


;; (lat-long-degdeci-to-dms 50.39954886056384 -3.483553379652956)
;; "050d 23' 58.4'' N   003d 29' 00.8'' W"
;;; 050 23' 58.4" N   003 29' 00.8" W
;;; will go back into Google Maps
;;; Will find you a lighthouse (maritime navigation)

Back to gnu.emacs.help | Previous | NextNext in thread | Find similar


Thread

elisp program nautical - more elegant way? Richard Smith <null@void.com> - 2023-03-15 07:47 +0000
  Re: elisp program nautical - more elegant way? Richard Smith <null@void.com> - 2023-03-17 10:09 +0000

csiph-web