January 5, 200719 yr I have a BASIC program to calculate sunrise and sunset times which I am trying to rewrite for FMA 8.5. So far, I have been able to create fields and global variables for the BASIC subroutines, but the main program calls a loop to evaluate the validity of data for each hour in the day, As far as I can see, the only way to generate a loop is through scripting, and I think the complexity involved will make it quite difficult. Is there a way to create a loop by calculation or custom functions? Here is the BASIC txt file and the code I have written so far. I'm not altogether certain what some of the individual calcs are doing, so I have done quite a bit of literal translation. Sorry it's so messy! The loop can be found in the BASIC from lines 210 to 260. It calls a subroutine which I have not yet written... thanks Steve sunup.txt code.zip
January 5, 200719 yr Hey clive, A partial answer for you: Yes, you can do looping through a custom function, but it's a recursive call instead of an iterative call like you have in your BASIC code. I can't deconstruct your code, but to give you the idea, this is a simple recursive CF that adds the numbers in a specified range: SumRange( from ; to ) = Case(from <= to ; from + SumRange(from + 1 ; to)) Although CFs could be written in an iterative manner, sending loop control variables to each succeeding function call, it's generally preferable to control the loop by reducing the parameter(s) in each succeeding call. You know you're done when the parameter is empty or matches a stopping condition.
January 5, 200719 yr Author This is neat, Ender. Thanks! I'll need to spend some time with it to get my head around it, but it does appear to be what I'm after.
January 5, 200719 yr Author This is superb, Ino. Many thanks, and may I congratulate you on its elegance. I've done some checking, and your calcs give a result very close to the US Naval Observatory times. It's closer than my local newspaper! Certainly better than the 5-6 min error of the program I'd previously relied on. Do you have similar calcs for the Moon and other planets? :D
January 5, 200719 yr Well I thought I had seen most requests but... Do you have similar calcs for the Moon and other planets? is one I never expected to see!! Happy New Year everyone. Phil
January 5, 200719 yr Thanks Also if You can use Shell script in fmp You can grab formally any place (Longitude and Latitude) on The Earth and calculate real Sunset & Sunrise. Not calculations for other planets (You can find it on Javascript examples which you can implemented with HTML sheet and use thru Web Viewer - but I’m not so familiar with HTML & Javascript so ...) , something for moon phase (position of moon for day). If You have some other questions You can call me on Skype (zagino) or send me an e-mail. Pls. don’t forget I am UTC (GMT) +1 Time - CET. regards Ino
Create an account or sign in to comment