polka129 said:
! here's the function
REAL FUNCTION formula(rad,x,m1)
REAL rad,x,m1
dimension m1(1:4),rad(1:4),theeta(1:4),x1(1:20),x2(1:20),x3(1:20)
F(rad,x,m1)=rad(i)-(6.**(1./2.))*(atan((((x(j))**2.)-1.)/6.)**(1./2.))-((atan((((m1(i))**2.)-1.)/6.)**(1./2.)))+(atan((((x(j))**2.)-1.)**(1./2.))-(atan((((m1(i))**2.)-1.)**(1./2.))))
RETURN
END
In a FUNCTION routine, you need to assign something to the variable whose name is the function name, i.e. you need to write
formula=rad(i)-(6.**(1./2.))*(atan((((x(j))**2.)-1.)/6.)**(1./2.))-((atan((((m1(i))**2.)-1.)/6.)**(1./2.)))+(atan((((x(j))**2.)-1.)**(1./2.))-(atan((((m1(i))**2.)-1.)**(1./2.))))
The compiler has no way of knowing that you mean "F" to be "formula".
And you still have redundant parentheses around
((atan((((m1(i))**2.)-1.)/6.)**(1./2.)))
You understand that "((expression))" is the same as "(expression)", right?
If you'd clean this up, you might notice that within the function routine, you have never defined the variables i and j. So the compiler will assign them values of 0, and you will get a bounds error on execution, assuming you ever get it to compile. You should really use IMPLICIT NONE to catch such errors in compilation instead of execution. IMPLICIT NONE forces you to declare all variables. You would set this up like this:
REAL*4 FUNCTION formula(rad,x,m1)
IMPLICIT NONE
REAL*4 rad(4),m1(4),x
.
.etc.
.
RETURN
END
However, it seems to me that what you actually want to do is pass the array element to the function, not the whole array, so you would invoke the function with
...formula(rad(i),x(j),m1(j))...
and within the function declare these arguments as scalars, not arrays. This allows the function to work on just those elements that you want the result for at that moment.
Also, in the calling routine,
you never assign a value to x in an assignment statement. You use x as an argument to formula() and on the right side of an assignment statement in the function, but you never define it. In the formula itself you use x as a subscripted array but you have never dimensioned it, so as I explained before, the compiler is still looking for a
FUNCTION x() and you will still be getting "unresolved external function" errors.
YOU NEED TO FIX THIS. YOU NEED TO ASSIGN SOMETHING TO X BEFORE YOU USE IT IN A FORMULA. I pointed out in my previous message that this is why you were getting the error message, but you still haven't fixed this. Fix it or you will keep getting the same error message.
What is x supposed to be?
If I strip all the redundant parentheses from your formula, this is what I get:
REAL*4 FUNCTION formula(rad,x,m1)
IMPLICIT NONE
REAL*4 rad,x,m1
formula = rad - SQRT(6.)*SQRT(ATAN((x**2 - 1.)/6.)) - SQRT(ATAN((m1**2 - 1.)/6.)) + ATAN(SQRT(x**2 - 1.)) - ATAN(SQRT(m1**2 - 1.))
RETURN
END
Does that look correct? BTW you can handle line continuations for long lines with an ampersand, e.g.
formula = rad &
- SQRT(6.)*SQRT(ATAN((x**2 - 1.)/6.)) &
- SQRT(ATAN((m1**2 - 1.)/6.)) &
+ ATAN(SQRT(x**2 - 1.)) &
- ATAN(SQRT(m1**2 - 1.))
Is it true that sqrt(6) only applies to the first term? Seems wrong.
BBB