Need help with running fortran program

In summary, the user is trying to run a program but is getting errors. He changed one thing in the Makefile and everything worked.
  • #1
trelek2
88
0
Hi!

I've never done any programming in fortran and got stuck trying to test run a program.
Note that I am not learning how to program in fortran, this is for an astrophysics course.

Basically what I need is an instruction how to run a fortran code if I have some .f files and .o files as well as an input file.

The detailed description of what I'm trying to do:

I'm trying to run the code Nbody1 from this http://www.ast.cam.ac.uk/~sverre/web/pages/nbody.htm"
The first problem is making the file. After I download and uncompressed nbody1.tar.Z I can't really make the file since I'm a Mac user and I don't have the f77 compiler (I have g77). So I edited Makefile in dir /nbody1/Real8 by changing line fortran compiler = f77 to FC = g77.
When I make file I then get an error:

O3 nbody1.o block.o bodies.o cmcorr.o check.o cputim.o data.o define.o energy.o escape.o fpoly1.o fpoly2.o frame.o input.o intgrt.o modify.o mydump.o nbint.o output.o ran2.o remove.o scale.o start.o stepi.o steps.o subsys.o verify.o xvpred.o zero.o -o nbody1
make: O3: No such file or directory
make: [nbody1] Error 1 (ignored)

Which might not be relevant since all object files seem to be created. I then try to run nbody1 using "intest" input file. I get really stuck here. In the instructions from the lecturer it says that the command to run is: 3. Run the code (“../Real8/nbody1 < intest”) I have no idea how this should work. If I type the above in I always get bash: no such file or directory. If I indeed have to type that in, which directory should I be in when typing that in?

I tried going to Real8 and typing ./nbody1.o or ./nbody1.f but I always get :

MacBook-Pro-Jan-Zaucha:Real8 janzaucha$ ./nbody1.f < intest
./nbody1.f: line 1: Makefile: command not found
./nbody1.f: line 2: Makefile: command not found
./nbody1.f: line 3: Makefile: command not found
./nbody1.f: line 4: Makefile: command not found
./nbody1.f: line 5: Makefile: command not found
./nbody1.f: line 6: Makefile: command not found
./nbody1.f: line 7: Makefile: command not found
./nbody1.f: line 8: Makefile: command not found
./nbody1.f: line 9: Makefile: command not found
./nbody1.f: line 10: Makefile: command not found
./nbody1.f: line 11: Makefile: command not found
./nbody1.f: line 12: PROGRAM: command not found
./nbody1.f: line 13: Makefile: command not found
./nbody1.f: line 14: INCLUDE: command not found
./nbody1.f: line 15: Makefile: command not found
./nbody1.f: line 16: Makefile: command not found
./nbody1.f: line 17: Makefile: command not found
./nbody1.f: line 18: syntax error near unexpected token `('
./nbody1.f: line 18: ` CALL CPUTIM(CPU0) '

or:

MacBook-Pro-Jan-Zaucha:Real8 janzaucha$ ./nbody1.o < intest
Illegal instruction: 4

Fortran users please help me, I don't have time to learn fortran now, as I'm supposed to perform some Nbody simulations and write a report. If I don't figure out how to make this work quick, I'll run out of time!

Great thanks in advance!
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Actually I figured it out, I had to change one more thing in the Makefile. Now everything runs fine!
 

1. What is Fortran and what is it commonly used for?

Fortran is a high-level programming language commonly used in scientific and engineering applications. It was developed in the 1950s and is still widely used today for its efficient handling of mathematical and scientific computations.

2. How do I run a Fortran program?

To run a Fortran program, you will need a Fortran compiler installed on your computer. Once you have a compiler, you can use a command-line interface to compile and run your program. Alternatively, you can use an integrated development environment (IDE) that supports Fortran programming.

3. What are some common errors when running a Fortran program?

Some common errors when running a Fortran program include syntax errors, logical errors, and runtime errors. Syntax errors occur when the code does not follow the rules of the Fortran language. Logical errors occur when the code produces incorrect results due to a mistake in the logic. Runtime errors occur during program execution and can be caused by issues such as out-of-bounds array access or division by zero.

4. How can I debug a Fortran program?

To debug a Fortran program, you can use a debugger tool provided by your compiler or IDE. This allows you to step through the code and identify any errors or issues that may be causing the program to malfunction. You can also add print statements to your code to track the values of variables at different points during program execution.

5. Are there any resources available for help with Fortran programming?

Yes, there are many resources available for help with Fortran programming. These include online tutorials, forums, and documentation provided by the compiler or IDE you are using. You can also find books and other learning materials specifically focused on Fortran programming.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
1
Views
236
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
878
  • Programming and Computer Science
Replies
5
Views
1K
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
639
Replies
6
Views
623
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
Back
Top