Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: Formula Help Needed  (Read 3716 times)

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Formula Help Needed
« on: March 19, 2012, 02:30:41 PM »

This is not for the faint hearted.
The problem. I need a formula to convert degrees C to degrees F.

I already know the easiest formula of (1.8 *  degrees C) + 32 = degrees F.
I run into a messy formula because I have to apply the above formula to a number that is to be calculated before the above formula is applied.
Now if you are still awake, I only need to apply the formula if an other condition is met otherwise simply multiply the first number is all that is required.

Example to follow.

When condition is met:-

(char *)buffer[0] = raw data.
raw data * 0.1 = degrees C
(degrees C * 1.8) + 32 = degrees F

Otherwise:-

(char *)buffer[0] = raw data.
raw data * 0.1 = degrees C

Can I make this into a simple if(statement) that can be used many times when required.
I am writing this in C++.

OK. I think I have just answered my own question. I have been looking at too long now.  ::)
Thanks anyway.
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43947
  • Penguins CAN fly
    • DSLstats
Re: Formula Help Needed
« Reply #1 on: March 19, 2012, 03:11:59 PM »

Quote
Thanks anyway.

You're welcome. ;D
Logged
  Eric

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5370
Re: Formula Help Needed
« Reply #2 on: March 19, 2012, 03:48:28 PM »

OK. I think I have just answered my own question. I have been looking at too long now.  ::)

Reminds me, have you heard the tale... about a senior manager of a large corporation (usually IBM, in the versions I hear).  He had an 'open door' policy, whereby any employee, no matter how humble, could enter his office and ask questions, or seek guidance at any time.  He also had a cardboard cutout of himself, placed outside his office.

The only condition was that, before approaching the manager in person, the employee first had to ask his/her question of the cardboard cutout.  Nine times out of ten, the process of properly composing the question led them to immediately figure out the answer, leaving the manager in peace.

Apologies if I've mangled that story from it's original version, I thought it was well known but a quick google failed to provide me with any convincing hits  :)
Logged

asbokid

  • Kitizen
  • ****
  • Posts: 1286
    • Hacking the 2Wire
Re: Formula Help Needed
« Reply #3 on: March 19, 2012, 04:09:04 PM »


When condition is met:-

(char *)buffer[0] = raw data.
raw data * 0.1 = degrees C
(degrees C * 1.8 ) + 32 = degrees F

Otherwise:-

(char *)buffer[0] = raw data.
raw data * 0.1 = degrees C

Can I make this into a simple if(statement) that can be used many times when required.
I am writing this in C++.


What about using the ternary operator.. [1] [2]

Code: [Select]
temp = rawdata * 0.1;
output = (condition == true) ? (temp * 1.8) + 32 : temp;

if condition is a simple boolean it can be shortened a little..


Code: [Select]
temp = rawdata * 0.1;
output = (condition) ?  (temp * 1.8) + 32 : temp;

EDIT: or maybe merge the assignment into the operation..

Code: [Select]
output = (condition) ?  (buffer[0] * 0.1 * 1.8) + 32 : buffer[0] * 0.1;

cheers, a

[1] http://stackoverflow.com/questions/758849/the-ternary-conditional-operator-in-c
[2] http://www.cplusplus.com/articles/1AUq5Di1/
« Last Edit: March 19, 2012, 04:13:10 PM by asbokid »
Logged

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Re: Formula Help Needed
« Reply #4 on: March 19, 2012, 04:28:30 PM »

Thank you Asbo, the ternary operator would indeed do the job.
One thing I am trying to do is keep the operations obvious to anyone who may read the code and wish to modify it, should it ever make it as far as offering it to the general public.
I will certainly look to shortening any code that I can in the final production for myself.

@7LM I could certainly do with that cardboard cut out at times. :lol:
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.

UncleUB

  • Helpful
  • Senior Kitizen
  • *
  • Posts: 29544
Re: Formula Help Needed
« Reply #5 on: March 19, 2012, 06:30:15 PM »

I thought this was the chit chat thread........not the open university. :D
Logged

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Re: Formula Help Needed
« Reply #6 on: March 19, 2012, 06:48:02 PM »

I thought you would have been straight in with the solution UncleUB.  ;D
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.

UncleUB

  • Helpful
  • Senior Kitizen
  • *
  • Posts: 29544
Re: Formula Help Needed
« Reply #7 on: March 19, 2012, 07:00:35 PM »

I thought you would have been straight in with the solution UncleUB.  ;D

 :hmm:.........watch out for flying sparks..... :lol:
Logged

broadstairs

  • Kitizen
  • ****
  • Posts: 3717
Re: Formula Help Needed
« Reply #8 on: March 19, 2012, 08:18:15 PM »

OK. I think I have just answered my own question. I have been looking at too long now.  ::)

Reminds me, have you heard the tale... about a senior manager of a large corporation (usually IBM, in the versions I hear).  He had an 'open door' policy, whereby any employee, no matter how humble, could enter his office and ask questions, or seek guidance at any time.  He also had a cardboard cutout of himself, placed outside his office.

The only condition was that, before approaching the manager in person, the employee first had to ask his/her question of the cardboard cutout.  Nine times out of ten, the process of properly composing the question led them to immediately figure out the answer, leaving the manager in peace.

Apologies if I've mangled that story from it's original version, I thought it was well known but a quick google failed to provide me with any convincing hits  :)

I worked for IBM for nearly 40 years and never heard that story, however the open door policy did exist but you had to see each manager in the line first before going to the next one up, so that often solved the problem anyway!

Stuart
Logged
ISP:Vodafone Router:Vodafone Wi-Fi hub FTTP

asbokid

  • Kitizen
  • ****
  • Posts: 1286
    • Hacking the 2Wire
Re: Formula Help Needed
« Reply #9 on: March 19, 2012, 10:11:04 PM »

It sounds interesting. Is it a weather station project?
Logged

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Re: Formula Help Needed
« Reply #10 on: March 20, 2012, 07:31:51 AM »

Now that is a very knowledgeable guess.
Yes it is, its the Fine Offset WH1081, and the application is for the Linux OS.
I know there are some out there but none that do what I want. The only one that holds promise will not compile on my machine. Dependency hell.
So I thought I would put my very rusty c++ programming skills into use again. Re-learning what I had forgotten, and learning much new stuff. Whilst frustrating at times I find it very interesting, and should I finish up with a usable application, quite pleased.
I do use a rather good Windows one via VirtualBox, but it is taking up ram & processing power to have it running.

Wake up at the back there!.

Sorry folks, but my interest has been awakened.
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.

broadstairs

  • Kitizen
  • ****
  • Posts: 3717
Re: Formula Help Needed
« Reply #11 on: March 20, 2012, 08:36:30 AM »

Now that is a very knowledgeable guess.
Yes it is, its the Fine Offset WH1081, and the application is for the Linux OS.
I know there are some out there but none that do what I want. The only one that holds promise will not compile on my machine. Dependency hell.
So I thought I would put my very rusty c++ programming skills into use again. Re-learning what I had forgotten, and learning much new stuff. Whilst frustrating at times I find it very interesting, and should I finish up with a usable application, quite pleased.
I do use a rather good Windows one via VirtualBox, but it is taking up ram & processing power to have it running.

Wake up at the back there!.

Sorry folks, but my interest has been awakened.

Linux does not seem to be well served for weather station applications, my station currently has a dedicated W2K system and I'd love a Linux version which did what I need. My station is a Davis VP btw.

Stuart
Logged
ISP:Vodafone Router:Vodafone Wi-Fi hub FTTP

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Re: Formula Help Needed
« Reply #12 on: March 20, 2012, 09:17:41 AM »

I thought I had seen you posting on a forum about weather stations, Stuart. Nothing wrong in that I may add.
As it is I know nothing about other stations as yet, except for the Fine Offset wh1080 which is very similar to mine.
I feel there must be similarities in quite a number of the stations that use Cumulus otherwise the application would not handle so many different interfaces/protocols. However that is for another day if and when I actually get this program working satisfactorily.
I do have the bare bones gui up and running.
It is designed around the Mageia flavour of Linux, which, as I'm sure you will know is the Mandriva fork. Which in itself is the basis of a couple more releases.
Don't expect to see anything freely available for quite a while (if ever) as there is a lot of work to do yet.
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.

broadstairs

  • Kitizen
  • ****
  • Posts: 3717
Re: Formula Help Needed
« Reply #13 on: March 20, 2012, 03:29:46 PM »

The Davis has its own unique access via either serial, USB or IP depending on what you buy, it also logs data for up to 48 hours which can also be accessed separately. My problem is that my web site is designed around the software I use and so a conversion will not be trivial. I use Weather Display and there is a Linux variant but it is not as fully featured as the Windows version plus the author is not as keen on updating it as he earns very little from it!

Stuart
Logged
ISP:Vodafone Router:Vodafone Wi-Fi hub FTTP

silversurfer44

  • Kitizen
  • ****
  • Posts: 4421
  • Lord Muck
    • Ben Novice Weather
Re: Formula Help Needed
« Reply #14 on: March 20, 2012, 04:04:56 PM »

It sounds like a nice piece of kit you have, Stuart.
I can understand the guy not wishing to upgrade to another OS as it would be the same for me. Apart from the fact I have forgotten all I used to know about Windows. I'm not in this for the money it's just hobby stuff, like my weather station, very amateur.
Logged
Colin II : It's no good being a pessimist, it wouldn't work anyway.