Fortran issue. HEEEEELP? Not a human error, somethings buggy ?

  • Context: Fortran 
  • Thread starter Thread starter bobbo7410
  • Start date Start date
  • Tags Tags
    Error Fortran Human
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a Fortran programming issue, specifically related to compiling and linking modules and the use of random number generation. Participants explore potential causes of errors encountered during compilation and execution, with a focus on both technical aspects and specific compiler behaviors.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports encountering a strange error when using a random function and a module, expressing confidence that it is not a human error.
  • Another participant suggests that the error may be due to compiling files separately, indicating the need to link object files together.
  • A participant argues that they should be able to compile separately since the module is in the same directory, but they also note a similar error with the random_number function.
  • Another participant proposes setting the project to compile and link multiple source files together, although they admit unfamiliarity with the specific tool being used.
  • One participant clarifies that the errors with random_number and the module are likely from different situations, emphasizing the importance of linking object files.
  • A later reply identifies that the random_number issue was due to passing an integer argument instead of a real argument, suggesting a misunderstanding of the function's requirements.
  • Another participant acknowledges the need to link the files and mentions that the random_number issue was due to not calling random_seed, but questions the necessity of calling random_seed for proper functionality.
  • It is noted that random_number can work without random_seed, but it will produce the same number each time unless random_seed is called.

Areas of Agreement / Disagreement

Participants express varying views on the necessity of linking object files and the role of random_seed in generating random numbers. There is no consensus on the exact nature of the errors encountered, with multiple competing explanations and approaches presented.

Contextual Notes

Participants mention specific compiler behaviors and configurations, such as using different compilers (Windows vs. Unix) and the implications for linking and compiling. There are unresolved assumptions about the setup and the specific code being used.

bobbo7410
Messages
36
Reaction score
0
Fortran issue. HEEEEELP? Not a human error, somethings buggy...?

I have no clue why this is acting like this, I'm getting a strange error. I don't believe this is a human error, I've followed the examples perfectly.

The picture shows it all. I ran it once trying to use a random function and again trying to use a module, both a similar error.

http://img27.imageshack.us/img27/7163/37186177.png

(also, the teacher uses a windows compiler(g95.org), I use a unix one.)
 
Last edited by a moderator:
Technology news on Phys.org


It looks like you have compiled the two files separately, so Randy does not see TestMod and vice versa. Unless you compile and place the object of GetX in an established library, you will need to link them together, usually simply stacking one after in the same file.
Hope that sovles your problem.
 


Well that's the thing, I should be able to compile separately, as the Randy calls to use TestMod, which is in the same directory.

Moreover, when I take out the module in general, Random_Number(x) seems to give a very similar error, and I knowww that should work fine.

THANK YOU SO MUCH THUS FAR!
 


I not familiar with this particular tool, but can't you set the project or batch file to simply compile two source files, then link the two created object files along with any common libraries needed?
 


I believe the errors with the random_number case and the module case are from two different situations.

As Jeff Reid said, you need to link the object files. So if you do want to compile them separately (instead of in one line), you can do something like:

Code:
g95 testmod.f95 -c
g95 randy.f95 -c
g95 -o po testmod.o randy.o

which creates the executable po.exe .

The error with the random_number subroutine appears to be because you gave it an integer argument (r1), but it needs a real argument.
 


THANK YOU!

You're right I don't know what I was thinking, I have to link the two together.

And the random_number issue was because I didn't call "random_seed" before it. Unrelated.

Thanks again for all the help!
 


bobbo7410 said:
THANK YOU!

You're right I don't know what I was thinking, I have to link the two together.

And the random_number issue was because I didn't call "random_seed" before it. Unrelated.

Thanks again for all the help!

Perhaps it's not important, but I don't think the issue with random_number was that, because you are not required to call random_seed in your program. For example, you can have:

Code:
program test
implicit none
real::r1
call random_number(r1)
print*,r1
end program test

and it will compile and run fine (it will just give the same number every time you run the program). Inserting the line "call random_seed()" at the appropriate place will give a different number every time.

However, if r1 is declared as integer (as in your sample program), then it will not compile with g95.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
17K