10Arrays-1 - ARRAYS An array is a group of variables all of...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ARRAYS An array is a group of variables all of the same type referred by the same name. The values in the array occupy consecutive locations in computer memory. An individual member of the array is called an array element and is identified by the name of the array together with a subscript pointing to its position in the memory location. ARRAYS One Dimensional (Vector) INTEGER, DIMENSION(12) :: MONTH OR INTEGER :: MONTH(12) 1 2 3 4 5 6 7 8 9 10 11 12 ARRAY DECLARATIONS One Dimensional (Vector) INTEGER :: MONTH(12) ARRAY DECLARATIONS 1 2 3 4 5 6 7 8 9 10 11 12 31 28 31 30 31 30 31 31 30 31 30 31 Two Dimensional (Matrix) INTEGER :: SALES(3,6) OR INTEGER, DIMENSION(3,6) :: SALES FORTRAN stores matrix values in column major order, i.e. first index varies most often . SALES(1,1),SALES(2,1),SALES(3,1),SALES(1,2), SALES(2,2),SALES(3,2),SALES(1,3),SALES(2,3), SALES(3,3),etc. ARRAY DECLARATIONS 2 1 5 4 3 6 1 2 3 SALES (1,1) (2,1) (3,1) (1,2) (2,2) : : : N Dimensional INTEGER :: C(2, 4, 3) ARRAY DECLARATIONS Z X Y Order in memory: C(1,1,1), C(2,1,1), C(1,2,1), C(2,2,1), C(1,3,1), C(2,3,1), C(1,4,1), C(2,4,1), C(1,1,2), C(2,1,2), C(1,2,2), C(2,2,2), ... INTEGER :: MONTHS(12) Each element holds number of days in corresponding month MONTH(1) Days in January MONTH(2) Days in February Array Examples REAL(8) :: EXAM1(200) Stores exam grades for 200 students How many bytes are used for this array? CHARACTER(LEN=20), DIMENSION(50)::name(20) REAL(8) :: GRADES(200,13) Student 198 Student 199 Student 200 Student 1 Student 2 Student 3 Assignment 1 Assignment 13 Array Examples Array Examples South - 3 : 25 West - 4 December - 12 : : East - 2 February 2 1 North - 1 January 1 Products: Regions: Months: REAL, DIMENSION(12,4,25) :: SALES Stores the number of sales made for 25 different products in four different regions in each month What does SALES(6,2,14) indicate? REAL :: Y(52,365,24,60,100) Stores state, day, hour, minute and type 2 billion cells, 8 billion elements REAL (8) :: D(8,25,100,40) How many bytes? Be careful when declaring arrays! Things can get out of hand easily. You may run out of memory if the array is too large. Array Examples Good practice to use Named constants for declaring array size. Examples: INTEGER, PARAMETER :: MAX_SIZE =100 REAL :: ARR1(MAX_SIZE) REAL :: ARR2(MAX_SIZE, MAX_SIZE) NAMED CONSTANTS REAL DIMENSION(lower_bound:upper_bound) 5 elements array REAL DIMENSION(5) :: a REAL DIMENSION(2:6) :: b REAL DIMENSION(-2:2) :: c More on declaration Out of bounds array subscripts are those which have not been declared as part of the array but were...
View Full Document

Page1 / 62

10Arrays-1 - ARRAYS An array is a group of variables all of...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online