Selected_int_kind is a INTEGER transformational function.
Depending on the type of machine that one is using, differing numbers of bits are used to represent integer numbers inside the computer. This can cause problems in the accuracy of results when programs are moved from machine to machine. Fortran 90 has attempted to deal with this problem by giving the programmer some ability to choose how many bits that he or she needs to represent INTEGER numbers. This is done by using the selected_int_kind intrinsic function. This function works by passing a number to the function that is the number of decimal digits ( powers of ten ) the programmer needs to represent integer variables. The computer will then return a number that internally corresponds to the bit configuration needed to represent integers with at least the requested number of decimal digits. Programmers can then declare integer variables that have this specific set up by declaring them with that configuration (KIND). However, if the requested range in exponents can not be represented on the machine a value of negative one will be returned by the machine. Unless you are knowledgeable of the details in which your particular system can handle integer variables, it is a good idea to run some sort of test program to make sure that your requested configuration will work before trying it in a real program.
Declaring variable kind with this function is a two step process. First, a variable needs to be created that will contain the required information for the internal variable configuration. This can be done with the use of a parameter statement.
Integer, parameter :: int9 = selected_int_kind(9)
First, take note that this function and selected_real_kind are the only two functions that can be used within a parameter statement. Second, the nine in the parenthesis after selected_int_kind is the number of decimal digits of accuracy that is required. That means in this example the programmer wants to have INTEGER variables with nine decimal digits (range of -999999999 to 999999999). Finally, int9 will contain the information needed to actually declare integer variables with nine decimal digits.
Now, having stored the necessary information in the parameter int9 for making integer variables with a maximum of nine decimal digits, variables can be declared with this configuration. This is done by either writing
lecture twenty one
Written by Jason Wehr : firstname.lastname@example.org and Maintained by John Mahaffy : email@example.com