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!

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post mixanologos OpenFOAM Running, Solving & CFD 3 October 25, 2011 06:58 gchnhn Main CFD Forum 0 October 3, 2011 03:44 inginer OpenFOAM 4 May 25, 2010 15:10 mactech001 CFX 1 April 21, 2010 16:58 F Main CFD Forum 6 August 9, 2004 05:32

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