13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>Good programming practice requires the use of the intent attribute for the dummyarguments of procedures, and the use of interface blocks for external procedures.ExercisesChoose any two of exercises 11-13:10. Write a program that, given the xyz coordinates of four atoms, returns the dihedralbetween the atoms. The dihedral (or torsion) angle of four atoms A-B-C-D is definedas the angle between the plane containing the atoms A, B, and C, and the planecontaining B, C, and D.AβDB11. Consider the Fibonacci series:1 1 2 3 5 8 13 …Each number in the series (exceptt the first 2, which are 1) is the sum from the twoprevious numbers. Write a program that computes the nth number in the Fibonacciseries, where n is given by the user. Use a recursive function.12. Bubble sort.Create an unordered data set of integers (for example by reading them in), and writea subroutine to sort them in ascending order. One of the easiest sort algorithms isbubble sort. Start at the lower end of the array. Compare elements 1 and 2, andswap them if necessary. Then proceed to the next 2 elements (2 and 3), and continuethis process through the entire array. Repeat the whole process ndim (dimension ofarray) times. Note that in successive rounds you only have to go through smaller andsmaller sections of the array, because the last element(s) should now already besorted. This process is called “bubble sort” because the larger elements appear tobubble through the array to reach their places.5 More on ArraysDeclaring arraysIn chapter 2 we have seen that we can declare arrays with the dimension attribute:real, dimension (3) :: coordsinteger, dimension (10,10) :: blockUp to seven dimensions are allowed.C! 1-dimensional real array! 2-dimensional integer array35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!