# Confused

 Register Blogs Members List Search Today's Posts Mark Forums Read

 October 23, 2003, 07:14 Confused #1 littlelz 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, 08:12 Re: Confused #2 cfd dude 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, 09:23 Re: Confused #3 Bart Prast Guest   Posts: n/a ALWAYS use "implicit none" I would say.

 October 23, 2003, 09:59 Still Confused #4 littlelz 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, 10:45 Re: Still Confused #5 cfd dude 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, 11:31 Still Confused #6 littlelz 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, 11:38 Re: Still Confused #7 cfd dude 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, 12:31 Thank you very much #8 littlelz Guest   Posts: n/a

 October 23, 2003, 12:43 Re: Thank you very much #9 cfd dude Guest   Posts: n/a CFD - Continuous Fortran Debugging!