(9) Multidimensional Arrays

(9) Multidimensional Arrays - Environment Canada maintains...

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

View Full Document Right Arrow Icon
1 Nathan Friedman Fall, 2009 Environment Canada maintains data about the climate across Canada in it’s National Climate Data and Information Archive This data can be accessed at: http://climate weatheroffice ec gc ca http://climate.weatheroffice.ec.gc.ca Weather data for Montreal is complete for each year starting from 1942 2009 Multidimensional Arrays 2 A portion of the table for Montreal consists of Column 1. Year 2. Month 3. Mean Maximum Temp for Month 4. Mean Temp for Month 5. Mean Minimum Temp for Month 6. Maximum Temp for Month 7. Minimum Temp for Month 8. Total Rainfall for Month 9. Total Snowfall for Month 10. Total Precipitation for Month 2009 Multidimensional Arrays 3 2007 4 9.9 5.8 1.6 25.8 -5.2 71.3 61.3 139.6 2007 5 19.6 13.6 7.6 30.7 0.3 63.2 0 63.2 2007 6 25.4 19.6 13.8 32.8 5.5 60.4 0 60.4 2007 7 25.1 20.4 15.7 31.1 10.5 106 0 106 2007 8 25.4 20.1 14.7 32.9 7.2 80.4 0 80.4 2007 9 22.5 16.7 10.8 32.4 4.4 47.8 0 47.8 2007 10 16.2 11.4 6.5 25.6 -3.1 113.6 0 113.6 2007 11 4.8 1 -2.8 16.2 -9.5 48.4 29 85.6 2007 12 -3.1 -6.4 -9.6 8.7 -21.3 7 112.8 119.8 2008 1 -2 -6.2 -10.3 11.3 -25 55.6 56.6 98.8 2009 Multidimensional Arrays 4 2008 2 -3.4 -7.7 -11.9 7.4 -23.4 7.4 88 107.2 2008 3 0.3 -4.3 -8.8 7 -15.2 13.6 77.8 121.6 2008 4 13.8 8.1 2.4 25.1 -4.7 63.8 7.2 74.8 2008 5 17.9 12.4 6.9 25.7 1.1 74 0 74 2008 6 24.4 19.9 15.3 31.1 9.8 60.6 0 60.6 2008 7 26 21.4 16.8 33 13.1 118.8 0 118.8 2008 8 24.6 19.7 14.7 29.2 9.3 77.6 0 77.6 2008 9 21.9 16.7 11.5 33.3 4 49.4 0 49.4 2008 10 12.7 8.1 3.4 22.6 -1.8 100 2.6 105 2008 11 5.7 2.4 -1 17.6 -9.8 56.6 13 72.4 2008 12 -2.1 -6.6 -11.2 12 -21.4 61.4 97 151.4 ` What is the total snowfall for a given year? ` What is the minimum temperature reached during the year? ` How many months had snow during the year? ` What was the rainiest month of the year? ` What was the hottest temperature reached? ` What was the coldest? 2009 5 Multidimensional Arrays ` Tables of data can be represented by two dimensional arrays The table itself has a name The rows form one dimension The columns form the second dimension The values in the table are all of the same type ` In our example, each row has the data for a specific month ` Each column has the data values for a specific piece of information (e.g. total precipitation) 2009 Multidimensional Arrays 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 We can represent the data for a specific year using 12 rows, one for each month There are 10 different statistics recorded, each kept in a specific column We can declare this array as: REAL :: year2008(12,10) 2009 7 Multidimensional Arrays The total precipitation in June, 2008 is stored in the cell year2008(6,10) Th lt t t d d i F b The lowest temperature recorded in February, 2008 is stored in the cell year2008(2,7) 2009 8 Multidimensional Arrays ` Now let’s answer some of our questions ` How much precipitation fell in the year? ` How many months had snowfalls? 2009 Multidimensional Arrays 9 real function TotalPrecip (year) real :: year(12,10), sum integer :: month sum = 0.0 do month = 1,12 sum = sum + year(month,10) end do TotalPrecip = sum end function TotalPrecip 2009 10 Multidimensional Arrays integer function Snowy (year) real :: year(12,10) integer :: i, count count = 0 do i = 1,12
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course COMP COMP 206 taught by Professor Vybihal during the Spring '04 term at McGill.

Page1 / 8

(9) Multidimensional Arrays - Environment Canada maintains...

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

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