Learning Fortran

1.- Printing the Hello world

The hello world itself has not much explanation:Then we need to compile it and run it:

gfortran hello.f90 -o hello
./hello
Hello World!

2.- Converting degrees to radians 

In this case we are going to write a module called trig which contains two functions:degtorad and radtodeg. degtorad should be a function which converts angles from degrees to radians,radtodeg should perform the inverse operation. Then to read in 3 angles (in degrees) from the screen. The program should use module trig to convert the 3 angles from degrees to radians and then back to degrees again. Trig.f90:

angleconv.f90:To compile it:

module load intel-compilers-17

ifort trig.f90 angleconv.f90 -o angleconv

./angleconv 

3.- Calculating root squares

Having three inputs: a, b and c, calculate the two root squares considering a determinant

gfortran quadraticeq.f90 -o quadratic

./quadraticeq

4.- Calculating complex square roots

Now we can use subroutines and module called mod_roots.f90

and the main program that will use the module and subroutines

gfortran mod_roots.f90 quadra3b.f90 -o qua

./qua

5.- Solving discontinuous functions like this:

1 ≤ x < 400 : y = x ∗ x ∗ x + C1

400 ≤ x < 1000 : y = x ∗ x + C2

1000 ≤ x ≤ 10000 :y = x

This can be a solution using arrays:

We can use also the structure WHERE to handle arrays:

The game of Life

I can only show the output of this code because involves a challenge we have in the University of Edinburgh. It was compile with gnu and intel. Thanks to my teacher Fiona!

Advertisements

About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. HPC researcher, Leader of LinuXatUNI Community, a simple mortal like you!
This entry was posted in Education, τεχνολογια :: Technology and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s