jedishrfu
Mentor
- 15,555
- 10,294
Some old advice on debugging screwy fortran problems:
(0) if its not your code, make it your code ie reformat it, add comments and debugging print statements at the entry points of subroutines
(1) If it worked reasonably well before then look closely at your changes
(2) Use a debugger and step through your code and take notes as to what is happening
(3) Use an IDE as it may help with debugging, refactoring and reformatting code (Eclipse IDE supports Fortran with GCC)
Where bugs usually crop up:
http://www.fortrantutorial.com/debugging-tips/index.php
In my experience:
(1) Look at your conditionals and make sure they do what you want. Add prints so you know which way the conditional branched and what conditions were true or false.
(2) Are you passing any constants to subroutines which in turn may change the value of the argument?
(4) Are you using any common blocks? Make sure the variables in each block match up with other related blocks in datatype and for your sanity in name.
Create a small set of logging functions instead of using prints or writes as it makes it easier to turn logging on and off.
Lastly, from what I've seen here is that no one can really help you. You have the code, the runtime environment and now you must really dig down deep to find the source of your problem. It may be in your changes, it may be a bug that's been there for ever, it may hidden in a support library that you use or even an odd compiler/runtime issue.
The key here is that until you can isolate it down to one line. We won't be able to really help debug this remotely.
(0) if its not your code, make it your code ie reformat it, add comments and debugging print statements at the entry points of subroutines
(1) If it worked reasonably well before then look closely at your changes
(2) Use a debugger and step through your code and take notes as to what is happening
(3) Use an IDE as it may help with debugging, refactoring and reformatting code (Eclipse IDE supports Fortran with GCC)
Where bugs usually crop up:
http://www.fortrantutorial.com/debugging-tips/index.php
In my experience:
(1) Look at your conditionals and make sure they do what you want. Add prints so you know which way the conditional branched and what conditions were true or false.
(2) Are you passing any constants to subroutines which in turn may change the value of the argument?
(3) Are you using any uninitialized variables? Your strategically placed prints should root these problems out.Years ago I passed an integer 3 into a subroutine and inadvertently changed it to an integer 5 and because argument passing was done as call by reference all numeric 3 constants in my program changed to 5 resulting in a very difficult bug to find. I think this has been fixed in later compiler design to no longer link all literal references back to the same memory location.
(4) Are you using any common blocks? Make sure the variables in each block match up with other related blocks in datatype and for your sanity in name.
One piece of inherited code had changed the names of the block variables and my new code changed the datatype causing a hidden mismatch which took a few days to uncover even though I had searched for all references I didn't make the common block connection and didn't notice the name change.
The key point was that I had to question every aspect of my changes to find the problem.
Create a small set of logging functions instead of using prints or writes as it makes it easier to turn logging on and off.
Lastly, from what I've seen here is that no one can really help you. You have the code, the runtime environment and now you must really dig down deep to find the source of your problem. It may be in your changes, it may be a bug that's been there for ever, it may hidden in a support library that you use or even an odd compiler/runtime issue.
The key here is that until you can isolate it down to one line. We won't be able to really help debug this remotely.
Last edited: