ten minutes to setup modern fortran 2003-2008 on windows (1)

27
8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1) http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 1/27 Ten Minutes  to Setup Modern Fortran  Compiler  2003/2008 Fortran  Programming Mohammad Rahmani Chemical  Engineering  Department Amirkabir University of  Technology Jan 2012

Upload: tt3340

Post on 05-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 1/27

Ten 

Minutes 

to 

Setup 

Modern 

Fortran 

Compiler 

2003/2008

Fortran 

Programming

Mohammad Rahmani

Chemical Engineering Department

Amirkabir University of  Technology

Jan 2012

Page 2: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 2/27

Outline

  Get the free gfortran compiler 2003/2008

  Get the free IDE, Code::Blocks (CB) for Fortran

  Setup gfortran on Windows

  Setup CB on Windows

  Write your first Fortran program

Jan 27, 20122

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 3: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 3/27

I. Get the gfortran compiler . . .

  Open the following link: gcc.gnu.org/wiki/GFortran

  Click on Binaries

for Windows 

under Download

Jan 27, 20123

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 4: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 4/27

I. Get the gfortran compiler . . .

  Click on windows:

Jan 27, 20124

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 5: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 5/27

I. Get the gfortran compiler . . .

  There are different binaries to download:

□   32 bit

□   64 bit

Jan 27, 20125

For this demo, we 

download the 

latest 32 bit and it 

works both on 64 

and 32 bit 

windows!

You can later  download  other  builds and   follow  the same instructions

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 6: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 6/27

II. Get the IDE

  You can skip this step, if  you don’t need an IDE and use simple editor to code!

  There are two different IDEs you can download  for free:

  Code::Blocks 

(CB) 

for 

Fortran•   Easy to use, syntax highlighting and code completion

•   Support muti‐projects workspace

•   Can create static and dynamic libraries

•   Support debugging

□   Photran

•   A great portable IDE based on Eclipse (need JRE)

•   Refractoring capabilities

•   Support debugging, workspace

•   Can create static and dynamic libraries

  Here, CB is selected as the Fortran IDE

Jan 27, 20126

IDE  stands  for  Integrated  Development  Environment 

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 7: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 7/27

II. Get the CB IDE for Fortran …

  Open the following link: 

http://darmar.vgtu.lt/

  Click on 

download

Jan 27, 20127

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 8: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 8/27

II. Get the CB IDE for Fortran …

  Download the appropriate build

Jan 27, 20128

Here, we download the 32bit 

Windows version!

If  

you 

work 

on 

linux, 

you 

should 

download both gfortran and CB 

for linux!

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 9: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 9/27

III. Setup gfortran …

  Install gfortran on Windows by running the executable downloaded 

in step I

The  file version on the date of  this  presentation is gfortran‐windows‐

20120119.exe

Jan 27, 20129

In this demo, we install  on Windows 7, 64 bit. The instruction is the same under  other  

versions of  Windows!

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 10: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 10/27

III. Setup gfortran …

  Follow the on screen instruction to complete the install!

  By default gfortran will be installed in Windows “Program Files” 

folder. If  you setup a 32 bit version on 64 bit Windows, it will be 

installed in “Program Files (x86)”   I recommend to choose an installation folder separate from windows 

Program Files! But it works fine even you install in “Program Files” 

folder!

Jan 27, 201210

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 11: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 11/27

III. Setup gfortran …

  Here I used “D:\gfortran\compiler” as my installation folder

  Wait to finish installation

Jan 27, 201211

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 12: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 12/27

IV. Setup CB for Fortran …

  CB for Fortran is actually portable

  Just unzip the package into the folder of  your choice

Jan 27, 201212

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 13: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 13/27

IV. Setup CB for Fortran …

  Here we put CB in the same folder as gfortran i.e in our case 

D:\gfortran

  Just unzip the package in the folder of  your choice

Jan 27, 201213

To unzip, you can use the  free utility   7 ‐zip. Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 14: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 14/27

Run CB and Set Options

  Open the CB installation folder and run

codeblocks.exe

  For convenience,

you can make ashortcut on your

desktop!

Jan 27, 201214

You can use CB as  portable. You can consult  the CB help  for  this  purpose!

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

Page 15: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 15/27

Set the Default Compiler

Jan 27, 201215

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  After CB starts, a window appears ask for default compiler

  Select ‘GNU Fortran Compile’

  Click on ‘Set as Default’ and press ‘Ok’ button

Page 16: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 16/27

File associations

Jan 27, 201216

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  CB lets you to associates file types with itself.

  You can skip this step or set some file types to be opened by CB.

Page 17: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 17/27

Set compiler and debugger path …

Jan 27, 201217

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  Click on setting

  Select ‘Compiler and debugger…’

Page 18: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 18/27

Set compiler and debugger path

Jan 27, 201218

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  Click on ‘Toolchain executables’ and set the ptah

  For this demo, the path is as below!

  Correct it (step 2 below) based on your installation

  Click ‘OK’

  That’s all.

1

2

3

Page 19: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 19/27

V. Create a simple Fortran program …

Jan 27, 201219

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  Click on ‘New’ from menubar

  Select ‘Project’

Page 20: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 20/27

Fortran Application

Jan 27, 201220

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  In the window appears, select ‘Fortran Application’

Page 21: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 21/27

Welcome window

Jan 27, 201221

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  Select ‘Next’

Page 22: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 22/27

Select project title and folder

Jan 27, 201222

Fortran Course, Chem Eng Dep

Amirkabir University of  Technology

  Enter a project title

  Select a project folder

Don’t  worry  about  the Project   filename, it  will  be ‘main.f90’ 

1

2

Page 23: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 23/27

Fortran project configuration

Jan 27, 201223

Fortran Course, Chem Eng DepAmirkabir University of  Technology

  By default CB create two build configurations

□   Debug configuration

□   Release configuration

  Make sure ‘Compiler’is set to ‘GNU Fortran

Compiler’

  Click on ‘Finish’

Page 24: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 24/27

The Fortran source file

Jan 27, 201224

Fortran Course, Chem Eng DepAmirkabir University of  Technology

  By default a ‘main.f90’ is created

  You can edit it and put your own code inside ‘main.f90’

  You can also 

rename it, if  you like   …

Page 25: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 25/27

Compile, build and run your first program

Jan 27, 201225

Fortran Course, Chem Eng DepAmirkabir University of  Technology

  Click on ‘build’ button to compile

and build your program (step 1)

  Click on 

‘Run’ 

button 

(step 

2) 1   2

1

Page 26: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 26/27

See the result

Jan 27, 201226

Fortran Course, Chem Eng DepAmirkabir University of  Technology

Page 27: Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

8/16/2019 Ten Minutes to Setup Modern Fortran 2003-2008 on Windows (1)

http://slidepdf.com/reader/full/ten-minutes-to-setup-modern-fortran-2003-2008-on-windows-1 27/27

Some exercises

  Exercises

□   Create a Fortran program with two source files

□   Compile only the source files, one by one using ‘compile current file’ under ‘build’ menu item

□   Rebuild your program by using the toolsbar icon

□   Try debugging capabilities of  CB

•   Add some variables to watch window

•   Step into procedures

□   Try other Fortran projects provided by CB

•   Make a Fortran static library

•   Make a Fortran DLL

□   Try workspace capabilities of  CB

•   Create two projects

•   Make one dependent on the other

Jan 27, 201227

Fortran Course, Chem Eng DepAmirkabir University of  Technology