Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sorting Data. FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms Program Exercise Resources Quiz Home HOME Arrays.

Similar presentations


Presentation on theme: "Sorting Data. FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms Program Exercise Resources Quiz Home HOME Arrays."— Presentation transcript:

1 Sorting Data

2 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms Program Exercise Resources Quiz Home HOME Arrays Subroutine Subprograms Introduction Programming Exercise Resources Quiz

3 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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 module sorting arrays subroutines

4 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

5 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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 N 2 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/pres sreleases/1999/Jul/spsort_record.html Click Here See the Procedure

6 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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. More...

7 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

8 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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…

9 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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 100CONTINUE  This program would take the vector SQ = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and return the following vector SQ = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

10 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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: 372316 5517854 25763249 (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

11 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

12 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

13 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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: xf(x) 0,20,008 1,0 0,40,064 0,60,216 00 0,80,512 SoSo k ro 0,330,03 0,20 0,820,7 0,530,2 Resources

14 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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 Numerical Recipes In Fortran  Fortran Tutorial Fortran Tutorial  Professional Programmer's Guide to Fortran77 Professional Programmer's Guide to Fortran77  Programming in Fortran77 Programming in Fortran77

15 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

16 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

17 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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

18 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms Program Exercise Resources Quiz References W. H. Preuss, et al., “Numerical Recipes in Fortran”, 2nd edition Cambridge University Press, 1992  References to textbook: Sorting:page 321 (Chapter 8)  The Textbook can also be accessed online: Numerical Recipes in Fortran

19 FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms 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


Download ppt "Sorting Data. FAQReferencesSummaryInfo Learning Objectives Introduction Arrays Subroutine subprograms Program Exercise Resources Quiz Home HOME Arrays."

Similar presentations


Ads by Google