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>The function selected_real_kind can be used in a number of different forms:! if both precision and range are specified, the “p =” and “r =” are not needed! the following two statements are therefore identicalikind = selected_real_kind (p = 7, r = 99)ikind = selected_real_kind (7, 99)! If only the range is specified, the “r = “ is neededikind = selected_real_kind (r = 99)! if only one argument is used, it is the precision! the following two statements are therefore identicalikind = selected_real_kind (p = 7)ikind = selected_real_kind (7)If you want to use the ikind value in a type declaration statement, it has to be a constant(i.e., declared with the parameter attribute). The real variable x declared in thefollowing statement is precise to 7 decimal places, and has a range of at least 10 -99 to10 +99 .integer, parameter :: ikind = selected_real_kind (7, 99)real (kind = ikind) :: xIf the kind value for the required precision or range is not available, a negative integer isreturned.The selected_int_kind function returns the lowest kind value needed for integers withthe specified range:integer, parameter :: ikind = selected_int_kind (10)integer (kind = ikind) :: big_numberThe integer big_number can now represent numbers from 10 -10 to 10 +10 . As forselected_real_kind, if the kind value for the required range is not available, a negativeinteger is returned.Exercises20. Write a program that declares a real with a precision of at least 7 decimal places andan integer that can represent the number 1000000000000.10 Scope and Lifetime of VariablesLocal variables in subroutinesThe scope of an entity is that part of the program in which it is valid. The scope can be aslarge as the whole program, or as small as (part of) a single statement. Variables definedin subroutines are valid only in their subroutine i.e., their scope is the subroutine. Thesevariables are called local variables, and cannot be used outside the subroutine. Thelifetime of a variable defined in a subroutine is as long as this subroutine, or any routinecalled by it, is running.62

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

Saved successfully!

Ooh no, something went wrong!