|
[Sponsors] |
October 23, 2003, 08:14 |
Confused
|
#1 |
Guest
Posts: n/a
|
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! |
|
October 23, 2003, 09:12 |
Re: Confused
|
#2 |
Guest
Posts: n/a
|
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? |
|
October 23, 2003, 10:23 |
Re: Confused
|
#3 |
Guest
Posts: n/a
|
ALWAYS use "implicit none" I would say.
|
|
October 23, 2003, 10:59 |
Still Confused
|
#4 |
Guest
Posts: n/a
|
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! |
|
October 23, 2003, 11:45 |
Re: Still Confused
|
#5 |
Guest
Posts: n/a
|
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). |
|
October 23, 2003, 12:31 |
Still Confused
|
#6 |
Guest
Posts: n/a
|
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'? |
|
October 23, 2003, 12:38 |
Re: Still Confused
|
#7 |
Guest
Posts: n/a
|
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. |
|
October 23, 2003, 13:31 |
Thank you very much
|
#8 |
Guest
Posts: n/a
|
|
|
October 23, 2003, 13:43 |
Re: Thank you very much
|
#9 |
Guest
Posts: n/a
|
CFD - Continuous Fortran Debugging!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Confused with solvers / Radiaton model | mixanologos | OpenFOAM Running, Solving & CFD | 3 | October 25, 2011 07:58 |
Confused about how these variables are used | gchnhn | Main CFD Forum | 0 | October 3, 2011 04:44 |
Questions about tutorial from User Guide :confused: | inginer | OpenFOAM | 4 | May 25, 2010 16:10 |
confused on messages after solver has terminated | mactech001 | CFX | 1 | April 21, 2010 17:58 |
Confused | F | Main CFD Forum | 6 | August 9, 2004 06:32 |