CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   a strange question about Fortran (https://www.cfd-online.com/Forums/main/7485-strange-question-about-fortran.html)

Hall April 27, 2004 19:10

a strange question about Fortran
 
Hi, guys:

I got a strange problem which I can't figure out. I use a simple 2nd-order center difference scheme to solve a first order oridinary differential equation. When I use default f77 to compile my code and run, I can get the right results compared with analytical solution. And the result is improved when the number of grids changes from 100 to 1000. But beyond 10000, the results is wrong. when I use f77 -i8 option to compile my code which supposed to give me better solution. But I find this is wrong. The result becomes worse. And when I use different grids, 100, 1000 and 10000, the results are almost the same ... so I didn't know what happened. Is something need to be noticed with the -r8 option? My code seems ok with only 80 lines. anyone can give me some suggestion? Thanks in advance!

agg April 29, 2004 18:33

Re: a strange question about Fortran
 
Try to compile the code using all possible debug options (check for array out of bounds...etc) for your compiler (non-optimized) and then run it. You might be able to track some errors.

hall May 3, 2004 18:38

Re: a strange question about Fortran
 
thanks a lot can't log on this forum for two days... can you tell me some details about debugging? or any links? Thank you very much.

matej May 4, 2004 02:59

Re: a strange question about Fortran
 
First, find out where is the manual or user guide coming with the compiler. If it is SGI or GNU or some other compiler, you can google the manuals. have a look for example to http://www.star.le.ac.uk/~cgp/fortran.html

Second, your problem seem pretty much like the misdeclaration or array bounds problem. Try to download and use ftncheck program ( http://www.dsm.fordham.edu/~ftnchek/ ) put the 'implicit none' before the declaration of variables and declare correctly all variables. use compiler switches for checking the code - they're different for different compilers.

debugging: find the info on the web. generally, -g switch of the compiler will put the debugging info to the code and you can cosnequently run the program in the debugger (gdb, dbx on SGI, xfx for ABSOFT .....), it can print the variables and other info.

good luck

matej

hall May 6, 2004 20:34

Re: a strange question about Fortran
 
thanks a lot! I just figureed out the problem.

subhra May 7, 2004 19:13

Re: a strange question about Fortran
 
Can you tell me : What was the problem??? Your discovery might help me a lot.

Hall May 16, 2004 18:56

Re: a strange question about Fortran
 
oh, very sorry, didn't come here for a week

In my code, there is a do loop, the parameter should be 1 (one), but I type a l (letter l) there...... kind of stupid ...... :)

matej May 17, 2004 06:54

Re: a strange question about Fortran
 
to avoid such a stupid typos, put an 'implicit none' statement before declaring variables. It'll give you the error during compilation.

matej

Hall May 17, 2004 14:54

Re: a strange question about Fortran
 
thank you very much! learned another skill :)

Rami May 18, 2004 02:48

Re: a strange question about Fortran
 
It is a good idea to enforce declaration of all variables. However, in this specific case, if there is a declared integer variable l (l.c. L), this trick won't help.


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