{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fortran_Lecture_8 - Fortran Class Notes Lecture 8 Working...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Fortran Class Notes Lecture 8 – Working with Tabular Data Today, we’re going to look at the use of multi-dimensional arrays and how they can be used with loops and file operations to do some very useful things. Let’s say that we have a data file of three rows and three columns. We want to display the same data but with the columns and rows reversed, like a diagonal mirror image. There are a couple of ways to do this operation, but we’ll take a general approach that could be modified for many other possible rearrangements. 1 2 3 9 8 7 4 5 6 barb2right 6 5 4 7 8 9 3 2 1 Since the data is laid out in two dimensions (across and down), we can use a two- dimensional array to store all nine numbers in one array variable which can be controlled entirely in loops. Though you can probably think of an easier way when working with just nine numbers, this approach is extremely useful when working with larger data files. Two-dimensional arrays are declared and referenced in the same way as one-dimensional arrays, but they hold much more data. Unlike MATLAB, Fortran doesn’t have internal means of displaying the contents of an array. That means it’s up to you to keep up with what is being stored in the array, using “write” statements to check often while debugging. It also means that the first dimension can represent rows and the second be columns, or vice-versa. Fortran doesn’t care as long as you are consistent throughout the program. Now let’s look at the program and see how the operation is performed.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}