4/14/2021 0 Comments Fortran Sort Rows
A two-dimansional(2D) array is an array wholes elements are addressed with two subscripts, and any particular element in the array is selected by simulatneously choosing values for both subscripts.So in contrast to one-dimensional array which represents a colume of data vector, a 2D array can be used to represent a matrix of data with a certain number of rows and columes as shown in Figure 5-5.So how does a 2D array stored in memory In Fortran, 2D arrays are stored in colume major as shown in Figure 5-6.
Notice that the first colume of the 2D array is stored first, then comes the second colume in memory. The opponent to colume major is row major which would store a 2D array row-wise (first row first, then comes the second row, etc). The first value defines the row number, and the second one defines the colume number of the matrix the array can hold. Fortran Sort Rows Code Clean FromThis practice makes the executable code clean from potential bugs. In Fortran, the default indexes of array elements are one-based, meaning that the first row and colume indexes are both 1. In all the examples that we have seen so far, the size of each array was declared as constant number(s). In the case when one cannot determine exactly the size of an array, an assumption has to be make on the potential size, or the program has to limit the user input under the capacity the array can handle. The solution is to use Dynamic Memory Allocation scheme, so that the size of the array can be changed over run-time according to some flexible user-input. Or the number of colon in the dimension declaration statement must match the number of values placed on the ALLOCATE statement. The following example demonstrate using an allocatable array to sort multiple students score record data into descending order according to their average score. Output: sorted records in descending order of each students average score.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |