ARRAYS !!! MET 50. Arrays ARRAYS allow us to store large amounts of data. Often in Meteorology and Climate Science we need to: Read in large amounts of.

Slides:



Advertisements
Similar presentations
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to arrays
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
FORTRAN PROGRAMMING BASICS (2) MET 50. Programming Basics A few extra things from last week… 1. For a program written in Fortran 90, use the extension.
Vectors A vector is a quantity that has both a magnitude and a direction. In two dimensions, vector A = a 1 i + a 2 j where i and j are unit vectors in.
Systems for locating points on Earth 1. Latitude and Longitude
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Chapter 7 Introduction to Arrays Part I Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Arrays A variable: a named position of memory For example: x1, x2, x3……..x10 An array: a collection of variables of the same type that are referenced by.
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
A BIT MORE ON… REPETITIVE EXECUTION MET 50. The “IF” statement In Meteorology, it is common to use the letters I,J,K to denote counters. “I” is the counter.
REPETITIVE EXECUTION MET 50. FABULOUS “DO LOOPS” MET 50.
C++ for Engineers and Scientists Third Edition
CHARACTER DATA MET 50. Character data We have extensively used REAL and INTEGER data types. There is also: CHARACTER data COMPLEX data LOGICAL data 12/1/2011.
FORTRAN PROGRAMMING BASICS MET 50. Programming Basics The basic layout of all programs is as follows (p.33) PROGRAM name = heading (i.e., title) Specifications.
Fibonacci Problem Solving and Thinking in Engineering Programming H. James de St. Germain.
Canadian Geography Chapter 1 Your Space.
Multidimensional Arrays C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of.
Java Unit 9: Arrays Declaring and Processing Arrays.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Beginning Fortran Fortran (77) Basics 22 October 2009 *Black text on white background provided for easy printing.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Multi-Dimensional Arrays
CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 04.
LATITUDE AND LONGITUDE
chap8 Chapter 8 Arrays (Hanly) chap8 2 Data Structure Simple data types use a simple memory to store a variable. Data Structure: a.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Fall 2001(c)opyright Brent M. Dingle 2001 Arrays Brent M. Dingle Texas A&M University Chapter 9 – Sections 1 and 2 (and some from Mastering Turbo Pascal.
Chapter 17 Pointers and Arrays. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Pointers and Arrays.
Teach A Level Maths Vectors for Mechanics. Volume 4: Mechanics 1 Vectors for Mechanics.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
Mapping Our World Latitude and Longitude Cartography –Science of mapmaking –Uses imaginary grid of parallel lines and vertical lines to locate points on.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Standard 1.h: Read and interpret topographic and geologic maps.
Introduction to ASP.NET Please use speaker notes for additional information!
* * 0 Latitude and Longitude. * * 0 ■ Lines of Latitude and Longitude are imaginary lines that encircle the Earth in either an East- West direction or.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Locating Positions on the Earth’s Surface
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
Multidimensional Arrays Computer and Programming.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
Arrays. Arrays are objects that help us organize large amounts of information.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
Arrays – two dimensional Chapter 14 This chapter explains how to do the following with a two dimensional array: Declare, use indices, obtain size, pass.
Unit: 5 Mapping Earth Why Mapping?. Mapping Earth Whether you think about it or not. Your life (especially this day in age) is effected directly by having.
© University of Reading 2006www.reading.ac.uk09 July 2016 “Mathematicians save the planet”
Department of Computer Science Western Michigan University
Longitude and Latitude
One-Dimensional Array Introduction Lesson xx
Lecture 12 Oct 16, 02.
Functions continued.
Geography Unit One Chapters 1-4.
Presentation transcript:

ARRAYS !!! MET 50

Arrays ARRAYS allow us to store large amounts of data. Often in Meteorology and Climate Science we need to: Read in large amounts of data Perform calculations, statistical analyses etc. using that data. Save the results (often large numbers of results) 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 2

Arrays Also we often need to: Perform calculations relative to a grid of imaginary points superimposed on a region: ction ction html html ARRAYS allow us to store and work with this gridded information 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 3

Arrays Finally – many problems have spatial dimensions! Examples… Information about elevation as we move west to east (1-D problem) Information about surface pressure as we move west to east AND south to north (2-D problem) Information about ozone concentration as we move west to east, south to north AND in the vertical (3-D problem) ARRAYS allow us to store and work with this information 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 4

Arrays Three types of arrays are used extensively in MCS: 1. 1-dimensional arrays 2. 2-dimensional arrays 3. 3-dimensional arrays 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 5

Arrays 1. 1-dimensional arrays Same as vectors in your math classes! Example: We might compute and store values of the Coriolis parameter ( f = 2  sin(latitude)) at every one degree of latitude in a1-D array (180 values!) Faster than re-computing the value every time we need it 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 6

Arrays 2. 2-dimensional arrays Same as matrices in your math classes! Example: We might store and forecast values of surface pressure at every one degree of latitude and every one degree of longitude across the planet in 2-D array (180 values north-south, 360 values west-east) 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 7

Arrays 3. 3-dimensional arrays Example: We might store and forecast values of temperature at every one degree of latitude and every one degree of longitude across the planet and every 1 km in elevation from the surface to 100 km in a 3-D array (180 values north-south, 360 values west-east, 100 values in the vertical) The atmosphere is 3-dimensional!! 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 8

Arrays 4. 4-dimensional arrays? With the 4 th dimension being time? CAN be defined BUT very space-consuming NOT preferred in our science 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 9

Arrays 1. 1-dimensional arrays A 1-D array is just a string of numbers. Example…values of Coriolis parameter At the start of code using arrays, we must set aside or declare 2 things: Names for the arrays Space (memory) for the arrays 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 10

Arrays We do this via the DIMENSION statement. Example: REAL, DIMENSION(180) :: CORIOLIS Says: 1. I am declaring “CORIOLIS” to be the name of a 1-D array 2. The array is real and has 180 elements. 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 11

Arrays Another example: INTEGER, DIMENSION(360) :: LAT Says: 1. I am declaring “LAT” to be the name of a 1-D array 2. The array is integer and has 360 elements. 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 12

Arrays How to access individual array elements… Suppose we have declared: REAL, DIMENSION (10) :: ATEST Then: ATEST(1) refers to the 1 st element of array ATEST ATEST(2) refers to the 2 nd element of array ATEST ATEST(10) refers to the 10 th element of array ATEST ATEST(11) does not exist  error message!! Generally: ATEST(n) refers to the n th element of array ATEST 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 13

Arrays Appearance inside code ??? Given: REAL, DIMENSION (100) :: TIME We might have: OPEN (18, FILE=‘TIMES.DAT’, STATUS=‘OLD’) DO K = 1, 100 READ (18, 80) TIME(K)! Reads in 100 values of TIME ENDDO! Assigns each to an array location 80 FORMAT (1X, F10.4) PRINT*, TIME(1), TIME(100) ! Print start and end times 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 14

Arrays Another example: SUM = 0. AVG = 0. DO J = 1, 100 SUM = SUM + TIME(J)! Adds together values from the ENDDO! Array TIME inside the DO loop AVG = SUM / (100.) PRINT*, SUM, AVG 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 15

Arrays So a 1-D array is a subscripted variable. In Fortran77, we always needed to type the subscript form. e.g., TEMP(I) Could never write just “TEMP” inside the code In Fortran90, we can either use the subscript form - TEMP(I) Or just writing TEMP alone is OK! 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 16

Arrays Suppose we wish to add two arrays, each with temperatures measurements recorded every minute: TEMP_AUG01 and TEMP_AUG02. Fortran90 REAL, DIMENSION(1440) :: TEMP_AUG01, TEMP_AUG02 REAL, DIMENSION(1440) :: SUM SUM = TEMP_AUG01 + TEMP_AUG02 This statement is legal as long as each array is of dimension (1440) 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 17

Arrays Fortran77 version… REAL TEMP_AUG01 (1440), TEMP_AUG02(1440) REAL SUM(1440) DO 10 JJ=1,1440 SUM(JJ) = TEMP_AUG01(JJ) + TEMP_AUG02(JJ) 10 CONTINUE 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 18

Arrays Other things… I) With: REAL, DIMENSION(180) :: CORIOLIS 1. READ (20,10) CORIOLIS 1. reads in all 180 values…no need to put in a DO loop 2. from UNIT # via FORMAT statement # 10 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 19

Arrays II) For an array with unchanging values (such as Coriolis values), we can set values as follows: Example: latitudes every 30 degrees from pole-to-pole INTEGER, DIMENSION(7) :: LAT LAT = (/ -90, -60, -30, 0, 30, 60, 90 /)  note format using ‘/’ or: LAT(1) = -90 DO JJ = 2, 7 LAT(JJ) = LAT(JJ-1) + 30 END DO 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 20

Arrays III) We can access a subset of an array as follows: REAL, DIMENSION(100) :: ARRTST REAL, DIMENSION(11) :: BSUB BSUB = ARRTST(50:60:1) Takes values from ARRTEST elements # 50 – 60 (11 in all) And puts them into array “BSUB”. BSUB = ARRTST(50:60)is enough to do this! 10/27/2011 MET 50, FALL 2011, CHAPTER 8 PART 1 21