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

Click For Summary
SUMMARY

The discussion centers on executing an Nbody simulation using Fortran, specifically the Nbody1 code from the University of Cambridge. The user initially faced issues compiling the code due to using the g77 compiler instead of f77 and encountered errors related to the Makefile. After modifying the Makefile and resolving the compilation issues, the user successfully ran the simulation using the command "../Real8/nbody1 < intest". This highlights the importance of proper compiler configuration and understanding command-line execution in Fortran.

PREREQUISITES
  • Basic understanding of Fortran programming language
  • Familiarity with command-line interfaces on macOS
  • Knowledge of Makefile structure and usage
  • Experience with compiling and running Fortran programs
NEXT STEPS
  • Learn how to configure Makefiles for different Fortran compilers
  • Explore command-line execution of Fortran programs on macOS
  • Study the Nbody simulation algorithms and their applications in astrophysics
  • Investigate debugging techniques for Fortran programs
USEFUL FOR

This discussion is beneficial for astrophysics students, Fortran programmers, and anyone involved in scientific computing who needs to execute simulations without extensive programming experience.

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!
 

Similar threads

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