Fortran 90 Implicit None and Vector Sorting Methods
Classified in Mathematics
Written at on English with a size of 1.74 KB.
Fortran 90: Implicit None and Vector Management
Implicit None
In Fortran 90, undeclared variables starting with I, J, K, L, or M are treated as integers, while others are treated as real numbers. However, it's best practice to avoid implicit declarations. Use IMPLICIT NONE
right after the program instructions to disable implicit typing. This forces you to explicitly declare all variables, preventing potential errors due to character misuse.
Vector Management Forms
Ordering one-dimensional arrays (vectors) is a common operation. Here are three simple methods: selection, insertion, and bubble sort.
In all cases, we'll assume a one-dimensional array of N elements.
Selection Sort
- Find the smallest element in the vector.
- Swap it with the element in the first position.
- Repeat the process for the rest of the vector (excluding the already sorted first element).
- Continue until only one element remains. This last element will be in the final position and will be the largest.
Insertion Sort
- Assume the first I-1 elements of a vector of N elements are sorted.
- Take the Ith element and insert it into its correct sorted position among the first I elements. Shift elements larger than the Ith element to the right to make space.
- Repeat the process, incrementing I.
- Start with I=2 and end when I=N.
Bubble Sort
- Compare each element with its neighbor to the right. If they are in the wrong order, swap them. Repeat this from the first to the second-to-last element.
- After step 1, the largest element will be at the end of the vector.
- Repeat the process, excluding the last (sorted) element.