Fortran How to Execute an Nbody Simulation in Fortran Without Prior Experience?

Click For Summary
The discussion revolves around running a Fortran program, specifically the Nbody1 code for an astrophysics course. The user initially faced challenges compiling the code due to using the g77 compiler instead of f77 on a Mac. After modifying the Makefile to use g77, they encountered an error related to the command "O3" not being recognized. The user was unsure how to execute the compiled program with an input file, receiving errors when attempting to run the code. Ultimately, they resolved the issue by making additional changes to the Makefile, allowing the program to run successfully. The thread highlights common issues faced by users new to Fortran, particularly in compiling and executing programs on different operating systems.
trelek2
Messages
86
Reaction score
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
Actually I figured it out, I had to change one more thing in the Makefile. Now everything runs fine!
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
7
Views
1K
  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
3
Views
2K
Replies
1
Views
5K