Jump to content
Server Maintenance This Week. ×

Is it possible to use a loop in a field calculation?


This topic is 6329 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 6329 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.