0% found this document useful (0 votes)
2 views14 pages

fortran3

The document provides an overview of various programming concepts in FORTRAN IV, including carriage control characters, data initialization, and subprogram structures such as functions and subroutines. It explains how to use statements like DIMENSION, IMPLICIT, COMMON, and EQUIVALENCE to manage data types and storage. Additionally, it discusses the BLOCK DATA subprogram for initializing variables in common blocks and the rules governing these programming constructs.

Uploaded by

yashmohta025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

fortran3

The document provides an overview of various programming concepts in FORTRAN IV, including carriage control characters, data initialization, and subprogram structures such as functions and subroutines. It explains how to use statements like DIMENSION, IMPLICIT, COMMON, and EQUIVALENCE to manage data types and storage. Additionally, it discusses the BLOCK DATA subprogram for initializing variables in common blocks and the rules governing these programming constructs.

Uploaded by

yashmohta025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
7.13 Ca Control: While outputing values by means of line printer a carriage control character is necessary in the FORMAT statement to do specified functions. Carriage Control Character Function 1Hb or '! ‘Advance the page through -one line before printing. Advance the page through two lines before printing. Advance the paper to the first line of the new page before printing. Do not advance the page. Advance the page through three lines before printing. PRINT 10,N 10 FORMAT('1',13) In the above example because of the carriage control character 1 the value of N will be printed in a new page. Eg. PRINT 20,M 20 FORMAT(H ,12) In the above example because of i%e carriage control character blank the value of M will be printed in the next line. Similarly other carriage control characters can also be used suitably. Eg.: PRINT 30,3 30 FORMAT(4X,13) 7.14 } example the first X in the format specification statement contro! character and advances the page to the DATA INITIALISATION statement _ DIMENSION statement IMPLICIT statement TYPE statement DOUBLE PRECISION statement ‘COMMON statement EQUIVALENCE statement SUBPROGRAMS and associated statement EXTERNAL statement BLOCK DATA subprogram ITIALISATION statement: get DATA/AS.6/,B/-77.7/,1/23/,F2M/0.2345/ General form: DATA 1,/e,hlo/ey/ils/ey/v sll e » 1, 18 @ list containing variables, array elements Ty Ip ly names. Cy mn , is @ list of constants which may be integer, real, f, hexadecimal, logical or literal. ‘arguments may not appear in the lst. Eg. DATA A,B,C,D/4*1.5/shJ)M,N/3"0,1/ in the above example any of cy Cy Cy etc., may be pre~ by i* 7.415 where each { is'an unsigned integer constant. When the form:t* appear before a constant it indicates that the constant is to be specified { times. A DATA initialisation statement is used to define initial values of variables, array elements and arrays. There must be one-to-one correspondence between the total number of elements specified or impiled by the list, 1 and the total number of constants specified by the corresponding ¢ after application of any replication factor, i. For real, integer, coniplex anc logical types, each constant must agree tn type with the variable or arry element it ts initializing. Any type of variable or array element may be initialized with a literal or hexadecimal constant. This statement cannot precede any specification statement that refers to the saame variable, array elements or arrays but it can precede ‘specification statements for other variables, array elements or arrays. It also cannot precede an IMPLICIT statement. Otherwise, a DATA statement can appear anywhere in the program since it is non-executable statement. DIMENSION sta Eg. DIMENSION R(30),MAX(5),71(88),MN12(12) General form: DIMENSION n,(Ry N(R pyres, (Ry) where each n is an array name. Bach R is composed of one to seven unsigned integer constants sepa- rated by commas representing the maximum value of each subscript in the array. Each R may contain integer variables of length 4 only when the DIMEN- SION statement in which they appear Is in a subprogram and the corres- Ponding n is a dummy argument of that subprogram. 7.16 jt IMPLICIT COMPLEX*16(A-D,Z)INTEGER(P,Q,R), REAL*8(K,LyN) General form: IMPLICIT type "910 4905 a E type, Oybyby > type g*8(¢ 10 9 gy 3 INTEGER, REAL, COMPLEX or LOGICAL ‘optional and represents one of the permissible length specifi- ite assoctated type. @ isa single alphabetic character or a range of characters drawn he Set Of A,B,C; seen yZ and in that order. je is denoted by the first and last characters of the range by a minus sign. PLICIT specification statement must be first statement in gram and the second statement in a subprogram. ICIT specification statement enables the user to declare of the variables appearing in the program (INTEGER, REAL, or LOGICAL) by specifying that varlables beginning with ignated tetters are of a certain type. the IMPLICIT statement allows the programmer to declare ber of locations (bytes) to be allocated to each in the group g Table shows the types that a variable may assume along length specification: TYPE LENGTH SPECIFICATION. INTEGER 2 or 4 (standard length 4) REAL 4 or 8 (standard length 4) Valf. COMPLEX 6 or 16(standard lenght 8) LOGICAL 1 or 4 (standard length 4) TYPE statement: _ Fast INTEGER*2 NUM,INDEX REAL*8 A1,FOX,2N COMPLEX 21,22,2N General form: Type*s lst or Type list Bach 8 ts optional and represents one of the permissible length specift- cation for its associated type. Type is INTEGER, REAL, LOGICAL or. COMPLEX List is a variable, array or function name If tet fasimys orray tasted arkey cig conssin lnecelOne aeons maximum. . DOUBLE PRECISION statement: g.t DOUBLE PRECISION A(5),Bi1(11),C(5,2) General form: DOUBLE PRECISION ajlkha,kyy a,{k,) where each a represents a variable, array or function name. Each k {s optional and is composed of one to seven unsigned integer constants or integer variables of length 4, separated by commas, that represent. two maximum value of each subscript in the array. Bach DOUBLE PRECISION statement explicitly specifies that each of the variables a is of type DOUBLE PRECISION. ‘Tis statement overrides any specification of a variable made by either the predefined convention or the IMPLICIT statement. ‘The specification is identical to that of type REAL*8 but it cannot be used to define initial values. Eiget COMMON/G/A(15), B(12,35),C(2,3,4,5),M(2;100) General form: COMMON /r j/a 0k 40 fk 0 ge ghyerron lk), PLP YPWflghrmonby igh’ s - : Seg{rglin gf nlm gyn ty) * ‘ - N's are’ varlable ‘names or array names that not a dummy argument. ch ky 4} m'etc., are optional and are composed of one to seven gned integer constants separated by commas, representing the Nalue of each subscript in the array. represents an optional common block name consisting of one ‘sie’ alphanumerte ‘characters; the first of which is an’ alphabet. ames must always be enclosed in slashes. form / / (with no characters except possible blanks between slashes) may be used to denote blank common. T denotes blank common the first two slashes are optional, common statement is used to cause the sharing of storage’ by or more program units and to specify the names of variables ‘arrays that are to occupy this area. ge sharing can he used for two purposes:' one to conserve storage Ny avoiding more than one allocation of storage for variables and uused by several program units and. the other to transfer angii= its {mplicitly between a calling program and subprogram. ts passed in a common areaare subjected to the same rules regard to type, length and so on as arguments passed in an argu- ite, = : given common block name may appear more than onet in.a COMMON. . or tn more than’ one COMMON statement in a program — All entries within such blocks are sting together in the order ‘pearance. EQUIVALENCE statement: Eg.t EQUIVALENCE (A,B),(C,D) = form: EQUIVALENCE G8 4908 y 99h ygoreeeey pry q (p02 gyyrmi) where each a is a variable or arry element and may Rot be a dummy argument. ‘The subscripts of array elemen?s may have etther of two forms. In either case, the subscripts themselves must be integer constants. If the array element has a single subscript quantity it refers to the 2 linear position of the element in the array. If the array element is multisubscripted (with the number of subscript | quantities equal to the number of dimensions of the array) all the \ elements within a single set of parantheses share the same storage tooattons. The BQUIVALENCE ‘statement provides the option of controlling the allocation of data storage within a single program unit. | Jn particular when the logic of the program permits it, the number of storage locations used can be reduced by causing locations to be ‘shared by two or more vaiables of the same or different types. Equivalence between variables implies storage sharing. Mathematical equivalence of variables or array elements 1s tmplted only when they are of the same type, when the value assigned to ‘the storage is of that type. ‘Subprogram : ARITHMETIC it fons: Eg. AREA(R) = 3.14*R*R VOLS(R) = (4./3.)*3.14°R**3 General form: — name(ayAyAyag -4a,,)-expression 7.20 “where name ts the statement function name. "Bach a is a dummy argument. ‘It must be distinct variable (1.e.,. it may appear only once within the lst of arguments). There must be atleast one dummy argument. Expression ts any arithmetic or logical expression that does not contain array elements, Any statement functioin appearing in this expression must have been defined previously. FUNCTION subprogram: Eg.t FUNCTION BESEL(I,X) general form: FUNCTION name(a)0 gyi) or type FUNCTION name*s(a 10. yy00040,) where type is INTEGER, REAL, DOUBLE PRECISION, COMPLEX or LOGICAL. Its inclusion is optional. name is the name of the FUNCTION. | § represents one of the permissible length specifications for its asso- lated type. It may be included optionally only when type ts specified. It must not be used when DOUBLE PRECISION {s specified. Bach a is a dummy argument. It must be distinct variable or-array name (i.e.,it may appear only once within the statement) or dummy name of a SUBROUTINE or other FUNCTION subprogram. There must be atleast one argument in the element. SUBROUTINE subprogram: Eg: SUBROUTINE TEST\T1,F,B) General form: — SUBROUTINE name(a j,4 yyy.) where nameiis the SUBROUTINE name. ~ 7.21 Each a is a distinct dummy argument (ie. it may appear only with the statement. F There need not be any arguments, in which case the parantheses must be omitted. Each argument used must be @ variable or array name, the dummy name of another SUBROUTINE or FUNCTION subprogram, or an aste- risk where the character * denotes a retum point wea raya state ment number in the calling program. The SUBROUTINE subprogran ts similar to the FUNCTION subprogram in many respects. Rules for naming FUNCTION and SUBROUTINE subprograms are similar. They both require an END statement, and they both contain the same sort of dummy argument. Like the FUNCTION subprogram, the SUBROUTINE subprogram is a set of commonly used computations, but it need not return ony results to the calling program, as does the FUNCTION subprogram. It ts referred to by the CALL statement. CALL statement: Eg. CALL TEST(X,Y,Z) General form: CALL name(a j,0.q40g9---0,)) where name is the name of the SUBROUTINE subprogram. Bach a is an actual argument that is being supplied to the SUBROU- TINE subprogram. The argument may be a variable, array element, array name, Uteral or arithmetic or logical expression. Bach may also be of the form &n where n is a statement number. ENTRY statement: Bga ENTRY TESTI(F,Ly7) General form: ENTRY name(a pay grveersd) ‘aa walld symbottc name of an entry point. are dummy arguments permitted in’ a FUNCTION ‘or a SUBROUTINE subprogram. of ENTRY statements may appear in a FUNCTION sub- or a SUBROUTINE subprogram depending upon the inter- | at which entries are required. g.: RETURN or RETURN 5 General form: RETURN or RETURN i ‘where i {s an integer constant or the variable of length 4 whose value, ‘say n, denotes the n*™ statement number in the argument list of a “SUBROUTINE statement. may be specified only in SUBROUTINE subprogram. EXTERNAL statement Bg.t EXTERNAL SIN,FUN,COS General form: EXTERNAL 4y,Qy,Gyy-00-40y “where a is name of subprogram that is passed as an argument to other _ subprograms. Te EXTERNAL statement ts a specification statement and must precede statement function definitions and ail executable statements. OCK DATA mt To initialise variables in a labelle? (named) COMMON block, a separate subprogram must be written. This subprogram’ contains only the BLOCK DATA, DATA, COMMON, DIMENSION, EQUIVALENCE and type state- ments associated with the data being defined. Data may not be initi- alized in untabeited common statements. Eg. BLOCK DATA Generat form: BLOCK DATA The BLOCK DATA subprogram may not contain any executable state- ments, statement function definitions or FORMAT, FUNCTION, SUB- ROUTINE or ENTRY statements. The BLOCK DATA statement must be the first statement in the SUBPROGRAM. If an IMPLICIT statement is used in a BLOCK DATA subprogram tt must immediately follow the BLOCK DATA statement. Statements which provide initial values for data items cannot precede the COMMON statement which define those items. Any main program or subprogram using a common block must contain ‘a common statement defining that block. If initial values to be ‘assigned, a BLOCK DATA subprogram is necessary. All elements of a common block must be listed in the common state- ment eventhough they are not initialised. (elibe) ata sgtat 40) x = oo nieaate “Conversion . double to reat geuteal tol double \gomplex to real — imaginary to real “Seal to! complex integer’ to real real to integer vif terance “Beror | a funet ton. 1E4 Bzponential ‘e% “Largest ask t Value max(ayy.s+60,) “Common Log. Log g(a) 3 Log gamma precision Modulus Rematnd v Smattes 7 Square ering t tue root S Transfer : Truncation Arccosine Aresine Apctangent Hyper Hyper Hyper pare trig. trig. cosine sine Tan Cosine Sine, Tangent tan(a) ay) a,-(aj/02)4p min(ayys+++98q) cos !(a) stn! (a) arctan(a) aretan(a,/a;) cosh(a) sinh(a) tanh(a) cos(a) sin(a) ye th tans ee FORTRAN IV PRINCIPLES AND PRACTICE Dr. V. Ganesan Dept. of Mechanical Engineering Indian Institute of Technology Madras—600 036

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy