14 arrays

44 %
56 %
Information about 14 arrays

Published on March 9, 2014

Author: fyjordan9



Basic Scientific Programming Arrays

Arrays Declaration   type, dimension (l:u):: array_name or type:: array_name l,u: are integer constants. Ex: integer, dimension(40)::grades integer:: grades(40) integer:: grades(0:39), avg(1:40) integer:: final(21:60)

Ex:   To read 6 number from the keyboard. Real, dimension(6):: example integer:: j do j =1,6 print*, ‘Enter a number’ read*, example(j) end do Or print*, ‘please enter 6 numbers’ read*, example

Compile Time & Run Time Arrays     The memory for grades is allocated at compile time. This means that the size of such compile-time arrays is fixed before execution begins. If the data to be stored in the array is too large, it cannot be stored in the array and processed correctly. To deal with this problem, we use run-time arrays for which memory is allocated during execution.

Allocatable Arrays  Integer :: N print*, ‘ how many elements?’ read*, N Real:: Grades(N) THIS IS WRONG !!

Declaration of Allocatable Arrays  Type, dimension, Allocatable:: Array_name the actual bounds of an allocatable array can be specified in an Allocate statement. Form Allocate(array_name) Allocate(array_name,Stat= StatusVariable)

Ex:    Print*, ‘Enter size of arrays A and B:’ read*, N Allocate(A(N),B(0:N+1), stat=allostatus) if(allostatus /= 0) stop “not enough memory” If memory is available, A can store N values and be can store N+2 values Once memory has been allocated, these arrays may be used in the same ways as compile-time arrays.

Deallocate  Memory that is not needed anymore should be cleared so that we can use it for allocating other arrays. Form deallocate(grades) or deallocate(grades,stat=StatusVar) Please read the example in page 530.

Array Constants  An array constant may be constructed as a list of values enclosed between (/ and /) (/ Value1, Value2, … , Value n /) Ex: integer:: A(5) A= (/ 2,4,6,8,10/) A= ( /(2*I, I = 1,5)/ )

Array Expressions   Operators and functions normally applied to simple expressions may also be applied to arrays having the same number of elements. Operations applied to an array are carried out element wise.

  Integer,dimension(4):: A,B,C … A= B + C Do I = 1,4 A(I)= B(I)+ C(I) end do

  A=2*C or Do I = 1,4 A(I)= 2 * C(I) End do C = 0 assigns zeros to all elements of C

Array Sections and Subarrays  In some cases, it is desired to have access to only a part of the array. We can either use Do loops or subarrays. Form array_name(lower:upper:stride) integer:: A(10) A=(/11,22,33,44,55,66,77,88,99,110/) print*, A(2:10:2) prints A(2), A(4), A(6), A(8), A(10)

The WHERE Construct  May be used to assign values to arrays depending on the value of a logical array expression. Form where (logical_array_expr) array_var1= array_expr1 Elsewhere array_var2= array_expr2 End where

Ex:  Integer, dimension(5):: A=(/0,2,5,0,10/) Real:: B(5) Where (A>0) B= 1.0/ Real(A) elsewhere B= -1.0 end where B will store –1.0, 0.5, 0.2, -1.0, 0.1

 Same as Do I=1,5 if (A(I) > 0) then B(I) = 1.0/ Real(A(I)) else B(I) = -1.0 end if end do

Intrinsic Array-Processing Subprograms  Fortran 90 provides several intrinsic functions whose arguments are arrays, some of the useful ones are: Dot_product(A,B) Maxval(A) Maxloc(A) Minval(A) Minloc(A) refer to page 548 and Appendix D.

Programmer-defined Array-Processing Subprograms  The actual array argument must be declared in the calling program unit, and the corresponding formal argument must be declared in the subprogram. … Actual Array Arg. … Formal Array Arg.

Array Valued Functions  A function may return an array as the return argument.

2-Dimensional Arrays     2-D arrays have two indices to indicate rows and columns.(matrix) The first index corresponds to rows, the second to columns. Real:: Matrix(5,3) declares a matrix with 5 rows and 3 columns. Integer, dimension(22:28,1:24):: hours declares a matrix of 7 rows and 24 columns

 2D arrays follow all the rules 1D arrays have. (1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2) (3,3) (4,1) (4,2) (4,3) (5,1) (5,2) (5,3)

Do I=1,5 Do J = 1,5 matrix(I,J) = I * J end do 1 2 3 End do 2 3 4 5 4 4 6 8 6 9 12 8 12 16 10 15 20 5 10 15 20 25

Add a comment

Related presentations

Related pages

14.1. Arrays deklarieren

14.2.1 Gültigkeitsbereich von Arrays Der Gültigkeitsbereich von Arrays richtet sich danach, ob es sich dabei um ein statisches, globales oder ein ...
Read more

Tutorial PHP - Teil 14 - Arrays anlegen und auslesen - PSD ...

PHP - Teil 14 - Arrays anlegen und auslesen. Arrays sind Felder, in denen verschiedene Elemente unterschiedlichen Typs enthalten sein können. In diesem ...
Read more

8.14. Arrays - PostgreSQL: The world's most advanced open ...

8.14.5. Searching in Arrays. To search for a value in an array, each value must be checked. This can be done manually, if you know the size of the array.
Read more

C++ in Hindi -14 Arrays - YouTube

For more go to my blog at This tutorial teaches you about the basics of arrays in C++
Read more

14.7 Dynamische Arrays

14.7 Dynamische Arrays. Wenn mit der Funktion malloc() ein zusammenhängender Speicherbereich reserviert werden kann, dann muss es auch möglich sein ...
Read more

14.11 Zweidimensionale dynamische Arrays - Rheinwerk ...

14.11 Zweidimensionale dynamische Arrays. In Abschnitt 12.9 haben Sie gelesen, dass das Anwendungsgebiet von Zeigern auf Zeiger unter anderem das ...
Read more

Programmierung 1 (Wintersemester 2015/16 ...

Arrays Aufgabe 14.7 (Faltung auf Arrays) (a) SchreibenSieeineProzedurminmax: int array →unit,diedasMinimumundMaximumeinerReihung
Read more

14 Arrays - YouTube

Video 14 GATE Lectures C and Data Structures 2D Array Address Calculation - Duration: 6:03. GATE Lectures Computer Forum NCR 348 views
Read more

Kapitel 8 Arrays

Einführung in die Informatik: Programmierung und Software-Entwicklung, WS 13/14 Kapitel 8 Arrays Arrays 1
Read more

Arrays - C++ Tutorials - - The C++ Resources ...

Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a ...
Read more