CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Confused (http://www.cfd-online.com/Forums/main/6738-confused.html)

littlelz October 23, 2003 07:14

Confused
 
Hi, dear all:

I met a very strange problem today. I was really confused. Please help me!

I am going to define a size distribution function based on maximum entropy formalism model. So, I defined the function's name is Maximum_Entropy. However, you know, it doesn't work right. I check every thing (actually the procedure is very simple), and finally found everything is all right, but the function's name. If I change it, I mean to use any other name except the first letter 'm'(for example, add a letter 'a' in front of the present name), then everything is OK!

Don't you think it's very funny and incredible? But i want to tell you it's really happened! So, who can tell me why?

Many thanks!

cfd dude October 23, 2003 08:12

Re: Confused
 
Just a guess:

In Fortran, unless you explicitly declare otherwise, it's implied that all variables that start with the letters I-N are integers. All variables starting with letters A-H and O-Z are reals.

Therefore as you originally had it, you were trying to return a real value to an integer variable.

Yes?


Bart Prast October 23, 2003 09:23

Re: Confused
 
ALWAYS use "implicit none" I would say.

littlelz October 23, 2003 09:59

Still Confused
 
Hi, Above all:

Thanks a lot for your help!

Hust as you said, the procedure is regarding the function's name as a integal variable. However, after I use "implicit none', the procedure ask me to define its type. When you reference a defined function in your main program, do you need to re-define the type of the functions' name. My answer is 'No'. The defined function just as the system function, such as 'COS', 'SIN' etc. I was confused again!

cfd dude October 23, 2003 10:45

Re: Still Confused
 
When you use implicit none, you must declare every single variable you use! This is by far the safest programming practice.

Declare your function as:

real function max_entropy(args)

... function coding ...

max_entropy = (some result)

return

end function

Then in your main code:

result = max_entropy(args)

With this, the function is declared to return a real variable. You can declare functions to return integers, logicals, etc. in the same manner.

I think if you don't explicitly declare the function it will return whatever the name corresponds to (A-H,O-Z returns real, I-N returns integer).


littlelz October 23, 2003 11:31

Still Confused
 
Hi, thanks a lot! Unfortunately, as I try it as you said, I was still confused!

I declare my function as:

function max_entropy(args)

real max_entropy

... function coding ...

max_entropy = (some result)

return

end function

Then in my main code:

result = max_entropy(args), no any other type definition. Then, the debug told me the function name has no type definition. But in fact, I have define it in the function procedure. I also tried your definition method. The debug still say there is no type definition. It means that I have to define its type explicitly in the main code. Is it 'fair'?

cfd dude October 23, 2003 11:38

Re: Still Confused
 
You must declare in your main code:

real max_entropy

to tell the compiler what type of variable the function returns. Every function that returns a value must be declared in the main routine.

You should also declare the function as:

real function max_entropy(args)

with the "real" definition included, to be explicitly clear.

littlelz October 23, 2003 12:31

Thank you very much
 

cfd dude October 23, 2003 12:43

Re: Thank you very much
 
CFD - Continuous Fortran Debugging!


All times are GMT -4. The time now is 01:01.