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

In summary, the programmer is having trouble compiling a program. They are using a different compiler (g95.org vs unix), and when they try to compile it using a module, they get an error. They are also having trouble compiling a program that uses a random number. They are doing everything correctly, but the program still does not work. They are told that they need to link the files together, and are also told that the problem with the random number is because they did not call random_seed().
  • #1
bobbo7410
36
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
  • #2


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.
 
  • #3


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!
 
  • #4


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?
 
  • #5


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.
 
  • #6


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!
 
  • #7


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.
 

1. What is a "Fortran issue" and why is it important?

A "Fortran issue" refers to a problem or bug that occurs in a program written in the programming language Fortran. Fortran is a widely used language in scientific and numerical computing, so addressing and resolving any issues is important for ensuring accurate and reliable results.

2. How can I determine if the issue is due to a human error or a bug in the code?

The best way to determine the cause of the issue is to carefully review the code and its logic. If the issue is due to a human error, it is likely that there will be a mistake in the code or its implementation. If the issue is due to a bug, it may be harder to identify the exact cause, but thorough testing and debugging techniques can help pinpoint the problem.

3. What steps should I take to troubleshoot a Fortran issue?

The first step is to carefully review the code and check for any errors or mistakes. If the issue persists, try running the code with different input values or data to see if the problem is consistent. It can also be helpful to consult the Fortran language documentation or seek assistance from other programmers who are familiar with the language.

4. Is there a specific way to prevent Fortran issues from occurring?

To prevent Fortran issues from occurring, it is important to follow good programming practices such as commenting and organizing code, testing and debugging thoroughly, and regularly updating and optimizing the code. It can also be helpful to stay updated on any new versions or updates of the Fortran language.

5. What resources are available for addressing Fortran issues?

There are many resources available for addressing Fortran issues, including online forums and communities where programmers can seek help and advice from others who are knowledgeable in the language. There are also various books, tutorials, and documentation available for learning and understanding Fortran and its best practices.

Similar threads

  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
9
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
4
Views
15K
  • Programming and Computer Science
Replies
12
Views
3K
Back
Top