How to set up Fortran in Xcode 3.2.4

Hello, I am a college-level Physics student. I am regularly assigned Fortran programs by my professors and I am tired of having to go to the computer lab to do them. I'm relatively new to Xcode, and coding in general (I only work with simple command lines in languages like C++, Fortran, or Mathematica) So I'm not entirely sure exactly how everything works. I apologize for my lack of knowledge!

Ok, so I did some research on this topic and have found that Xcode 3.2.4 has multiple versions of Gcc included, and that these may contain fortran binaries (I'm not 100% sure of what all this means, or if it's correct!) and I have tried downloading things like gfortran, and the fortran plug-in for Xcode, but I still have no idea how to set up my program in xcode! Like i said I just want to be able to run simple command lines in fortran (Anyone who's used Force 2.0 knows EXACTLY what I'm expected to do) Can anyone tell me what I need to do and how to set things up in order to make this work? The more specific the better, because as I said, I'm lacking a lot of knowledge in this department!

Info:
Mac OS 10.6.4
Xcode 3.2.4

I will provide any other necessary info when asked! Thanks for your help!

Macbook Pro 4,1, Mac OS X (10.6.4)

Posted on Nov 6, 2010 10:37 PM

Reply
7 replies

Nov 7, 2010 12:19 PM in response to etresoft

I know that... But once again my lack of knowledge prevents me from knowing how to compile or run the programs in terminal... Since I have doen some (limited) work in Xcode before I figured it would be the simplest way to make it work. But maybe not. Can you explain the simplest way to run a program like.. let's say this:

C RJP 2-30
real P, R, T, v, v1, a, b
R = 8.3143E3
P = 1.01325E7
T = 300
a = 366E3
b = .0429
i = 0
v = 0
v1 = 0

OPEN (1, file='data.txt')

write (1, 101)
101 format(22x, 'Table 1', /)

write (1, 103)
103 format('Solution of Van der Waal Equation for v by iteration',/)

write (1, 105)
105 format (11x, 'Iteration', 11x, 'v(M^3/mol)', /)

v = (R*T)/P

write(1, 104) i, v
104 format (11x, I5, 17x, f6.4, /)

DO WHILE (v.gt.0.080)

v1 = ((R T)/(P(a/v*2)))b

i = i + 1

v = v1

write(1, 102) i, v
102 format (11x, I5, 17x, f6.4, /)


End Do

close (1)

end

Any help would be greatly appreciated.

Nov 7, 2010 2:11 PM in response to Cardena2717

Here is what I did. Haven't run Fortran in years.

I'm running on a ppc & in tiger. Pick the correct version.



download from:
http://www.g95.org/downloads.shtml#V0.92
moved download file to ~/g95-powerpc-osx.tgz

scan down, you will eventually find your machine & OS
x86 OSX HTTP FTP
Powerpc OSX HTTP FTP
You download file name may be different. Adjust as needed.
Macintosh-HD -> Applications -> Utilities -> Terminal
created fortran directory
mkdir ~/fortran

cd ~/fortran

tar -zxvf /Users/mac/g95-powerpc-osx.tgz

ln -s $PWD/g95-install/bin/*g95* g95

pico
copy over source. copy & paste will work.
command+v
I'm sure the file requires unix line end. Start with pico.
C comment line didn't work.

save as try.f90

compile

./g95 try.f90

run
./a.out

good luck!

Here is the official installation instructions.
How to install g95:

1) Unpack the downloaded tarball (e.g. g95-x86-linux.tgz) in a directory
of your choice:

tar -zxvf g95-x86-linux.tgz

2) For your convenience, you can create another symbolic link from a
directory in your $PATH (e.g. ~/bin) to the executable

ln -s $PWD/g95-install/bin/*g95* ~/bin/g95

You should now be able to run g95 and create executables.

To get a list of environment variables that control the library, run a
compiled binary with the --g95 option, ie:

./a.out --g95

Have Fun!




------------------

here is the entire terminal log. It's includes all my error. I got your program to run...


in /etc/bashrc
in /Users/mac/.bash_profile but claims to be -bash
in /Users/mac/config/profile.bash claims to be -bash
in . /sw/bin/init.sh
mac $ fortran
-bash: fortran: command not found
mac $ gcc
powerpc-apple-darwin8-gcc-4.0.1: no input files
mac $ man gcc
mac $ cd fortran
/Users/mac/fortran
mac $ pwd
/Users/mac/fortran
mac $ tar -zxvf ~/g95-x86-linux.tgz
tar (child): /Users/mac/g95-x86-linux.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
mac $ tar -zxvf /Users/mac/g95-powerpc-osx.tgz
g95-install
g95-install/bin
g95-install/bin/powerpc-apple-darwin6.8-g95
g95-install/G95Manual.pdf
g95-install/INSTALL
g95-install/lib
g95-install/lib/gcc-lib
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/cc1
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/crt2.o
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/f951
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/libf95.a
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/libgcc.a
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/libgcc_eh.a
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/libgcc_s.1.0.dylib
g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.3/libgcc_s.dylib
mac $ ls
g95-install/
mac $ ls -k
g95-install/
mac $ ls -k
g95-install/
mac $ ls -l
total 0
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
mac $ pico
mac $ echo $PWD
/Users/mac/fortran
mac $ ln -s $PWD/g95-install/bin/*g95* g95
mac $ ls -l
total 16
lrwxr-xr-x 1 mac staff 62 Nov 7 16:29 g95@ -> /Users/mac/fortran/g95-install/bin/powerpc-apple-darwin6.8-g95
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
-rw-r--r-- 1 mac staff 555 Nov 7 16:27 try.f
mac $ g95 try.f
-bash: g95: command not found
mac $ ./g95
g95: no input files
mac $ ./g95 try.f
In file try.f:2

real P, R, T, v, v1, a, b
1
Error: Non-numeric character in statement label at (1)
In file try.f:2

real P, R, T, v, v1, a, b
1
Error: Unclassifiable statement at (1)
In file try.f:3

R = 8.3143E3
1
Error: Non-numeric character in statement label at (1)
In file try.f:3

R = 8.3143E3
1
Error: Unclassifiable statement at (1)
In file try.f:4

P = 1.01325E7
1
Error: Non-numeric character in statement label at (1)
In file try.f:4

P = 1.01325E7
1
Error: Unclassifiable statement at (1)
In file try.f:5

T = 300
1
Error: Non-numeric character in statement label at (1)
In file try.f:5

T = 300
1
Error: Unclassifiable statement at (1)
In file try.f:6

a = 366E3
1
Error: Non-numeric character in statement label at (1)
In file try.f:6

a = 366E3
1
Error: Unclassifiable statement at (1)
In file try.f:7

b = .0429
1
Error: Non-numeric character in statement label at (1)
In file try.f:7

b = .0429
1
Error: Unclassifiable statement at (1)
In file try.f:8

i = 0
1
Error: Non-numeric character in statement label at (1)
In file try.f:8

i = 0
1
Error: Unclassifiable statement at (1)
In file try.f:9

v = 0
1
Error: Non-numeric character in statement label at (1)
In file try.f:9

v = 0
1
Error: Unclassifiable statement at (1)
In file try.f:10

v1 = 0
1
Error: Non-numeric character in statement label at (1)
In file try.f:10

v1 = 0
1
Error: Unclassifiable statement at (1)
In file try.f:12

OPEN (1, file='data.txt')
1
Error: Non-numeric character in statement label at (1)
In file try.f:12

OPEN (1, file='data.txt')
1
Error: Unexpected array reference at (1)
Fatal Error: Too many errors, aborting.
mac $ ls -l
total 16
lrwxr-xr-x 1 mac staff 62 Nov 7 16:29 g95@ -> /Users/mac/fortran/g95-install/bin/powerpc-apple-darwin6.8-g95
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
-rw-r--r-- 1 mac staff 555 Nov 7 16:27 try.f
mac $ mv try.f try.f90
mac $ ls -l
total 16
lrwxr-xr-x 1 mac staff 62 Nov 7 16:29 g95@ -> /Users/mac/fortran/g95-install/bin/powerpc-apple-darwin6.8-g95
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
-rw-r--r-- 1 mac staff 555 Nov 7 16:27 try.f90
mac $ g95 try.f90
-bash: g95: command not found
mac $ ./g95 try.f90
In file try.f90:1

C RJP 2-30
1
Error: Unclassifiable statement at (1)
mac $ pico try.f90
mac $ ./g95 try.f90
mac $ ls -l
total 1024
-rwxr-xr-x 1 mac staff 515192 Nov 7 16:43 a.out*
lrwxr-xr-x 1 mac staff 62 Nov 7 16:29 g95@ -> /Users/mac/fortran/g95-install/bin/powerpc-apple-darwin6.8-g95
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
-rw-r--r-- 1 mac staff 544 Nov 7 16:43 try.f90
mac $ ./a.out
mac $ ls -l
total 1032
-rwxr-xr-x 1 mac staff 515192 Nov 7 16:43 a.out*
-rw-r--r-- 1 mac staff 1399 Nov 7 16:43 data.txt
lrwxr-xr-x 1 mac staff 62 Nov 7 16:29 g95@ -> /Users/mac/fortran/g95-install/bin/powerpc-apple-darwin6.8-g95
drwxr-xr-x 6 mac staff 204 Jun 25 2009 g95-install/
-rw-r--r-- 1 mac staff 544 Nov 7 16:43 try.f90
mac $ cat data.txt
Table 1

Solution of Van der Waal Equation for v by iteration

Iteration v(M^3/mol)

0 0.2462

1 0.1971

2 0.1705

3 0.1527

4 0.1394

5 0.1290

6 0.1206

7 0.1135

8 0.1076

9 0.1027

10 0.0985

11 0.0950

12 0.0921

13 0.0898

14 0.0878

15 0.0862

16 0.0849

17 0.0838

18 0.0830

19 0.0823

20 0.0818

21 0.0814

22 0.0810

23 0.0808

24 0.0806

25 0.0804

26 0.0803

27 0.0802

28 0.0801

29 0.0800

30 0.0800

mac $


Robert

Nov 7, 2010 2:33 PM in response to rccharles

I'm starting to see that this may be over my head... As I understood very little of all that. If anyone has a simpler solution to use Fortran in Xcode, a free fortran IDE I can use, or a simpler way to install g95 and use it in Terminal, let me know. When I have more time I will attempt to do what was just shown to me above. Thank you guys for your help! Sorry im so lost when it comes to mac programming...

Feb 18, 2011 7:45 AM in response to Cardena2717

Speaking as someone who's been where you're at, I will have to say that the best thing for you to do is to invest the time and effort into figuring out how to setup, compile, and run things from the command line. This is something you will most likely be expected to do routinely if you continue as a physicist, and it will be impossible to avoid bigger, complicated programs that require things like Makefiles and linking many files together.

Just my two cents.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to set up Fortran in Xcode 3.2.4

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.