Sorting Data
-
Upload
kibo-hicks -
Category
Documents
-
view
40 -
download
0
description
Transcript of Sorting Data
Sorting Data
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Home
HOMEArrays Subroutine Subprograms
Introduction
Programming Exercise
Resources
Quiz
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Learning Objectives
Learning objectives in this module
1. Develop problem solution skills using computers and numerical methods
2. Review of methods for sorting of tabular data 3. Develop programming skills using FORTRAN
New FORTRAN elements in this modulesortingarrayssubroutines
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Introduction
Sorting of tabular data may seem trivial, and perhaps not worth spending time learning. After all, most of our needs may be filled by the capabilities of Excel or some other spreadsheet program. Just by marking the data to be sorted, and pressing the Sort-button, and the job is done.
However, frequently we have measured data from the laboratory or the field, or data-sets that have been generated numerically, that we need to input to a computer program that requires that the numbers are sorted in ascending or descending order.
Although we in most cases may easily import the data into Excel and perform sorting of the data before returning it to the input file of the computer program, it will in many cases be convenient to be able to call a subroutine that checks if an input data set is properly sorted, and if not, do a sorting procedure. Next
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Introduction
Several methods for sorting exist, as you may see in the reference above. For our purpose, we will use the Straight insertion method to illustrate sorting of data.
Straight insertion is an N2 routine, and should be used only for small N, say < 20.
The technique is exactly the one used by experienced card players to sort their cards:
Pick out the second card and put it in order with respect to the first; then pick out the third card and insert it into the sequence among the first two; and so on until the last card has been picked out and inserted.
As a curiosity, in 1999 IBM set a world record in sorting of data. In 17
minutes their parallel processing computer RS6000 SP was able to sort
one billion bytes of data (1012 bytes). See
http://www.rs6000.ibm.com/resource/pressreleases/1999/Jul/
spsort_record.html
Click Here See the Procedure
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Procedure
Straight insertion is a simple method which uses simple picking and insertion for sorting one number at a time.
Given an initial sequence of unsorted data, the first run finds the first number (1) that is out of sequence relative to the first number (7), and puts it into sequence.
Then, the next number out of sequence (4) is located and put into it’s right place. In the third run, the third number out of sequence (6) is put in it’s right place, and so on. For this particular table, it takes 6 runs to sort the entire sequence of numbers.Initial order 7 1 8 4 6 3 5 2After 1st run 1 7 8 4 6 3 5 2After 2nd run 1 4 7 8 6 3 5 2After 3rd run 1 4 6 7 8 3 5 2After 4th run 1 3 4 6 7 8 5 2After 5th run 1 3 4 5 6 7 8 2After 6th run 1 2 3 4 5 6 7 8
More...
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Arrays
Many scientific computations use vectors and matrices. The data type Fortran uses for representing such objects is the array.
A one-dimensional array corresponds to a vector,
while a two-dimensional array corresponds to a matrix.
One-dimensional arrays
Two-dimensional arrays
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
One-dimensional arrays
The simplest array is the one-dimensional array, which is just a linear sequence of elements stored consecutively in memory. For example, the declaration:
REAL A(5)
declares A as a real array of length 5 (fx A=[0, 4, 6, 3, 9])
By convention, Fortran arrays are indexed from 1 and up. Thus the first number in the array is denoted by A(1) and the last by A(5).
”I’m beginning to get a hold of it, but I could use some extra information and maybe an example!”
More…
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
One-dimensional arrays
Each element of an array can be thought of as a separate variable. You reference the I'th element of array a by A(I). Here is a code segment that stores the 10 first square numbers in the array SQ:
INTEGER I, SQ(10)
DO 10 I = 1, 10 SQ(I) = I**2
100 CONTINUE
This program would take the vectorSQ = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
and return the following vectorSQ = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Two-dimensional arrays
Matrices are very important in linear algebra. Matrices are usually represented by two-dimensional arrays. For example, the declaration
REAL A(3,5)
defines A as a two-dimensional array of 3*5=15 real numbers. It is useful to think of the first index as the row index, and the second as the column index. Hence we get the graphical picture:
3 7 23 1 6
5 5 17 8 54
2 5 76 32 49
(1,1) (1,2) (1,3) (1,4) (1,5)
(2,1) (2,2) (2,3) (2,4) (2,5)
(3,1) (3,2) (3,3) (3,4) (3,5)
Click on number to view it’s index
Click for more
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Subroutine Subprograms
Subroutine Subprograms will be further discussed in the next module, we will here just have a quick overview of how it works.
Subroutine subprograms is quite similar to Function Subprograms; they are located after the main program, and have syntax much the same as the main program.
As opposed to function subprograms, subroutines are referred to by a call statement followed by the subroutine name and a list of arguments
See the Program
Structure
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Subroutine Subprograms: Structure
subroutine name (list-of-arguments)
declarations
statements
return
end
Program name
Declarations
Statements
call subroutinename (list-of-arguments)
Stop
end
If the subroutine name was sort, you should refer
to it by call sort (list-of-arguments)
Main program
Subprogram
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Program Exercise
Make a MAIN PROGRAM that reads tabular data (N pairs of values of XT and YT) from an input file IN.DAT, and a FORTRAN subroutine, SORT(N,XT,YT), that may be called with the data as input arguments, which sorts the values in ascending order before returning the results to the calling program.
Print the initial data table as well as the sorted table to an output file OUT.DAT
Test the subroutine on the following data:
x f(x)
0,2 0,008
1,0 1,0
0,4 0,064
0,6 0,216
0 0
0,8 0,512
So kro
0,33 0,03
0,2 0
0,82 0,7
0,53 0,2
Resources
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Resources
Introduction to Fortran
Fortran Template here
The whole exercise in a printable format here
Web sites
Numerical Recipes In Fortran
Fortran Tutorial
Professional Programmer's Guide to Fortran77
Programming in Fortran77
Fortran Template
Sorting
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
This section includes a quiz on the topics covered by this module.
The quiz is meant as a control to see if you have learned some of the most important features
Hit object to start quiz (Depending on your connection, this make take a few seconds...)
Quiz
Shockwave Flash Object
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
General information
Title: Sorting Data
Teacher(s): Professor Jon Kleppe
Assistant(s): Per Jørgen Dahl Svendsen
Abstract: Provide a good background for solving problems within petroleum related topics using numerical methods
4 keywords: Sorting, Subroutines, Fortran, Arrays
Topic discipline:
Level: 2
Prerequisites: None
Learning goals: Develop problem solution skills using computers and numerical methods
Size in megabytes: 0.5 MB
Software requirements: MS Power Point 2002 or later, Flash Player 6.0
Estimated time to complete:
Copyright information: The author has copyright to the module and use of the content must be in agreement with the responsible author or in agreement with http://www.learningjournals.net.
About the author
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
FAQ
No questions have been posted yet. However, when questions are asked they will be posted here.
Remember, if something is unclear to you, it is a good chance that there are more people that have the same question
For more general questions and definitions try these
Dataleksikon
Webopedia
Schlumberger Oilfield Glossary
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
References
W. H. Preuss, et al., “Numerical Recipes in Fortran”, 2nd editionCambridge University Press, 1992
References to textbook:
Sorting: page 321 (Chapter 8)
The Textbook can also be accessed online:
Numerical Recipes in Fortran
FAQReferenc
esSummar
yInfo
Learning Objectives
Introduction
Arrays
Subroutinesubprograms
Program Exercise
Resources
Quiz
Summary
Subsequent to this module you should...
be able to construct subroutines write and handle DO loops have a feel for the output format know the conditional statements and use the IF
structure