LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lunar Phase Calculation / Precision?

Hey guys,
I'm a student and am still learning all this labview stuff so i'm hoping you can help me out.

I need to implement a calculation to find the lunar phase on a particular date using labview, as part of a larger project. I've found and tested a simple C script, and have tried to implement this using both blocks, as well as the formula node. Can someone please look at my C script as well as the formula node version and tell me where i'm going wrong?

Is this maybe due to some precision difference between the two languages or order in which the operations are carried out?

Many thanks

Dan.

C Script:
    int c,e;
int d;
int m;
int y;
double jd;
int b;

d = 10;
m = 04;
y = 2006;

++m;
c = 365.25*y;
e = 30.6*m;
jd = c+e+d-694039.09; /* jd is total days elapsed */
jd /= 29.53; /* divide by the moon cycle (29.53 days) */
b = jd; /* int(jd) -> b, take integer part of jd */
jd -= b; /* subtract integer part to leave fractional part of original jd */
b = jd*8 + 0.5; /* scale fraction from 0-8 and round by adding 0.5 */
b = b & 7; /* 0 and 8 are the same so turn 8 into 0 */
return b;

--- Formula node script d, m, y as integer inputs.

int c;
int e;
float jd;
int b;

++m;
c = 365.25*y;
e = 30.6*m;
jd = c+e+d-694039.09;
jd /= 29.53;
b = int(jd);
b = jd*8 + 0.5;
0 Kudos
Message 1 of 2
(2,884 Views)
I think you have skipped this bit:

jd -= b;      /* subtract integer part to leave fractional part of original jd */

Really, the following 2 lines can be replaced  by using the modulus operator

b = jd;     /* int(jd) -> b, take integer part of jd */
jd -= b; /* subtract integer part to leave fractional part of original jd */
i.e.

b %= 1;

There is also this on the end:
b = b & 7;     /* 0 and 8 are the same so turn 8 into 0 */

Which should work straight in the Formula node.

0 Kudos
Message 2 of 2
(2,870 Views)