CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Confused

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 23, 2003, 07:14
Default 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!
  Reply With Quote

Old   October 23, 2003, 08:12
Default 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?

  Reply With Quote

Old   October 23, 2003, 09:23
Default Re: Confused
  #3
Bart Prast
Guest
 
Posts: n/a
ALWAYS use "implicit none" I would say.
  Reply With Quote

Old   October 23, 2003, 09:59
Default 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!
  Reply With Quote

Old   October 23, 2003, 10:45
Default 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).

  Reply With Quote

Old   October 23, 2003, 11:31
Default 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'?
  Reply With Quote

Old   October 23, 2003, 11:38
Default 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.
  Reply With Quote

Old   October 23, 2003, 12:31
Default Thank you very much
  #8
littlelz
Guest
 
Posts: n/a
  Reply With Quote

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

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Confused with solvers / Radiaton model mixanologos OpenFOAM Running, Solving & CFD 3 October 25, 2011 06:58
Confused about how these variables are used gchnhn Main CFD Forum 0 October 3, 2011 03:44
Questions about tutorial from User Guide :confused: inginer OpenFOAM 4 May 25, 2010 15:10
confused on messages after solver has terminated mactech001 CFX 1 April 21, 2010 16:58
Confused F Main CFD Forum 6 August 9, 2004 05:32


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