How to add a Unit Conversion

Discuss your code, get questions answered

How to add a Unit Conversion

Postby ebkwall » Wed Apr 06, 2016 8:20 am

First off, I love the app and your vision for it. Very interesting concepts and extremely deep application.

I am having problems with the program editor. For instance I have been using it for viewing apps and can not figure out how to close out of the window.

That aside, I would like to add a unit conversion for geography. Specifically Decimal Degrees (dd) to Degrees:Minutes:Seconds (dms).

How do you recommend going about that?

Thanks,
Brian
ebkwall
 
Posts: 22
Joined: Tue Apr 05, 2016 2:29 pm

Re: How to add a Unit Conversion

Postby oliver » Thu Apr 07, 2016 6:37 pm

Hi Brian,

Thanks for your nice words!

I'll follow up with you on the editor problem offline.

Unit conversion:

Ok, so I trust you saw the Units folder under My Data. All the unit conversions are there.
Most conversions are just factor-based, and it should be easy to see how it works. You can edit any entry and add your own unit and multiplication factor and the unit will become available with the CONVERT (convert) function.

You can also provide RPL programs for conversions. Edit the Temperature entry and look at the definition of Fahrenheit.
It looks like this:
Code: Select all
"Fahrenheit [°F]":{"from":"≪ 32 - 5 * 9 / 273.15 + ≫","to":"≪ 273.15 - 9 * 5 / 32 + ≫"}}


So, for dd to dms you could add something like that to the Angle entry:
Code: Select all
"DegreesMinutesSeconds [dms]":{"from":"≪ ...your code goes here... ≫","to":"≪ ...your code goes here... ≫"}}


Unless I'm missing something, you should be in luck: you don't actually have to write code, because ND1 has the conversion functions you need.

Try
Code: Select all
"DegreesMinutesSeconds [dms]":{"from":"≪ fromHMS ≫","to":"≪ toHMS ≫"}}


To use this you'd put the qty and units on the stack and press the Convert key (long press on "," if you're using the modern interface):
Code: Select all
30.56
°
dms

convert should yield
Code: Select all
30.3336
dms
(30 hrs, 33 mins, 36 secs)


Getting the ° symbol above is a bit non-trivial: You have to go into the String menu go forward 2 pages.

It would be nice to allow typing dd instead of °.

This could be achieved by adding the following to the definition of Angle:
Code: Select all
"DecimalDegrees [dd]": 1


(When editing the definition for Angle, don't forget the comma to separate newly added entries. Things will break without it.)

There's a long-standing dream to use two 1-D pickers for units in a custom calc that ties to convert to make unit conversion prettier/more accessible.
This should be enabled with the update that will enable storing of custom calcs. (You can already build one now.)

Also, a nicer representation for HMS would be nice. Showing the result like a decimal number was the HP way, but it needs modernizing. One could give HMS its own type and rendering in the stack. Something like 30° 33' 36", or even using icons. That too, is possible to do, for someone who wants to dive into types. (There're a bunch of examples for custom types on this site on the MorphEngine side.)

Hope this helps.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: How to add a Unit Conversion

Postby ebkwall » Thu Apr 07, 2016 7:09 pm

This is a great reply. Thank you for putting so much effort into it.

I have been blown away by this app and have been studying the documentation for almost 3 days now. Incredibly rich documentation.
I have come up with a few ideas but think it would be cool to be available as a Convert option.
I also was thinking about formatting it the "modern way" you mentioned.

I am plugging away at the documentation and will revisit this. I have been working in GIS for well over a decade so when I saw how you can execute javascript and hit web resources I of course thought about geographic information and throwing it on a map... not really math, but I thought it would be fun to demonstrate the flexibility of this app.

Thanks,
Brian
ebkwall
 
Posts: 22
Joined: Tue Apr 05, 2016 2:29 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron