# Fortran: mistake in writting this formulas

1. Feb 28, 2012

### Petar Mali

Do I made a mistake in writting this formulas. I don't see them. Tnx for your answer.

V1=(Kps*(1-ra**2)*(1-cos(6.2831853*y(1))))/(6.2831853**2*
(1+ra**2+2*ra*
cos(6.2831853*y(1)/2))**2)

V2=(Kps*ra*(1-ra**2)*(1-cos(6.2831853*y(1)))*
sin(6.2831853*y(1)/2))/(6.2831853/2*(1+ra**2+2ra*
cos(6.2831853*y(1)/2))**3)+(Kps*(1-ra**2)*sin(6.2831853*y(1)))/
(6.2831853*(1+ra**2+2*ra*cos(6.2831853*y(1)/2))**2)

2. Mar 1, 2012

### Petar Mali

Fortran says to me that I made syntax error here
V1=(Kps*(1-ra**2)*(1-cos(6.2831853*y(1))))/(6.2831853**2*
(1+ra**2+2*ra*
cos(6.2831853*y(1)/2))**2)

3. Mar 1, 2012

### Staff: Mentor

What was the syntax error?

I'm guessing that you have unbalanced parentheses. If that's the problem, you could print out this line of code on paper, and then connect each left parenthesis with its matching right parenthesis. You shouldn't end up with any unmatched parentheses.

A better way to go would be to break up this complicated assignment statement into at least three or four assignment statements using intermediate variables. The final assigment statement would use only the intermediate variables.

Also, you should use a parameter for 6.2831853. That seems to be 2$\pi$, so a reasonable name for the parameter would be TwoPI.

4. Mar 1, 2012

### Staff: Mentor

If the statement is really spread out over three lines like you wrote it here, your compiler may not be recognizing second (etc.) line as a "continuation" of the first one, but instead is trying to compile each line as a separate statement.

In the old days of fixed-format Fortran, all statements had to start in position 7 of the line. You indicated a continuation line by putting an additional character in position 6. Most people used a + or a * or a digit for this purpose:

Code (Text):

V1=(Kps*(1-ra**2)*(1-cos(6.2831853*y(1))))/(6.2831853**2*
+(1+ra**2+2*ra*
+cos(6.2831853*y(1)/2))**2)

In this example, the + signs at the beginning of lines 2 and 3 are not part of the statement. They simply flag the line as a continuation of the first one.

I haven't used modern versions of Fortran, so I don't know if this is an issue any more.

5. Mar 1, 2012

### AlephZero

If your source code is in "free format", you need an & character at the end of a line to say the next line is a continuation.

You can also put a & character at the start of the continuation line if you want.

IIRC some Fortan compilers assume that if a line that ends with an operator (e.g. + - * / ) or "punctiation" (e.g. a comma), then the next line is a continuation, and you don't need to use the & character. Your code seems to be written using that convention, but that isn't standard fortran, and if your compiler supports it you probably need to do something to switch the option on.

6. Mar 3, 2012

### Petar Mali

I'll try to print code and look for unbalanced brackets, but that looks just fine for me. I put symbol & in the end of some problematic lines and that didn't work neither. And in program I get just one mistake and that mistake is syntax one. Program worked just fine with different shape of functions $$V_1$$ and $$V_2$$. I don't understand where is a problem...

Last edited: Mar 3, 2012
7. Mar 3, 2012

### Staff: Mentor

Did you actually do this?
What is the syntax error? Knowing this would help us diagnose the problem.
I have no idea what you mean by "different shape of functions."
I still recommend that you break up this complicated assignment statement into at least three separate assigment statements using intermediate variables, and then use these intermediate variables for the final assignment statement.