What is FORTRAN?
Contents
- 1 What is FORTRAN?
- 2 State a few advantages of using Fortran
- 3 Explain what arrays are in Fortran
- 4 Explain why Fortran is faster than C
- 5 What is a subroutine in Fortran?
- 6 What is a module in Fortran?
- 7 Explain using examples how variables are declared in Fortran
- 8 What are reserved keywords?
- 9 How do you define a function in Fortran
- 10 What are the basic data types in Fortran
- 11 Fortran Interview Questions and Answer – Obsolescence and deletions
- 12 Code examples of fortran
- 13 What Is The Difference Between If Then And Do While Statements?
- 14 What are the commonly used character functions in Fortran?
- 15 What is DBLE (A) function?
Fortran is an acronym that is derived from Formula Translation. It is one of the early high level programming languages that were used in the 1960s when the computer revolution begun. BASIC is based on Fortran.
Fortran Interview Questions and Answer: Fortran is a general-purpose, compiled imperative programming language that is especially suited to numeric computation and scientific computing. FORTRAN is generally the preferred spelling for discussions of versions of the language prior to the current one (?90?). Fortran is the spelling chosen by X3J3 and WG5. Fortran Interview Questions and Answer: In this document, a feeble effort has been made to capitalize accordingly (e.g. vast existing software … FORTRAN vs. generic Fortran to mean all versions of the standard, and specifically the modern dialect, ISO 1539:1991).
State a few advantages of using Fortran
- It supports numerical analysis and scientific computation.
- It is an Object-Oriented Programing language
- It is readable and easy to understand
Explain what arrays are in Fortran
A collection of data types or variables. In Fortran programmers can include up to 7-dimensional arrays.
Explain why Fortran is faster than C
When mathematical functions are being evaluated, the former handles memory references very well.? C uses pointers that can be challenging to optimize while performing mathematical tasks.
What is a subroutine in Fortran?
A subroutine can modify the arguments of a program although it does not return a value.
What is a module in Fortran?
Functions and subroutines that are stored together so that they can be used in various parts of the entire program. In other words a large program is spliced into modules for simplicity.
Explain using examples how variables are declared in Fortran
The syntax for declaring variables is type-specifier :: list. The type specifier can be INTEGER, REAL, COMPLEX, LOGICAL, AND CHARACTER.
What are reserved keywords?
They are words that cannot be used as identifiers. Fortran does not have reserved words although it has identifiers like END, PROGRAM, and DO.
How do you define a function in Fortran
A function is a type of a procedure that only returns a single quantity. Here is the syntax for a function.
Syntax:-
function name(arg1, arg2, ….)
[declarations, including those for the arguments]
[executable statements]
end function [name]
What are the basic data types in Fortran
Integer type
Real type
Complex type
Logical type
Character type
Fortran Interview Questions and Answer – Obsolescence and deletions
Obsolescent feature | Example | Status/fate in Fortran 95 |
---|---|---|
Arithmetic IF-statement | IF (X) 10, 20, 30
| Deprecated |
Non-integer DO parameters or control variables | DO 9 X= 1.7, 1.6, -0.1
| Deleted |
Shared DO-loop termination or termination with a statement other than END DO or CONTINUE | DO 9 J= 1, 10
DO 9 K= 1, 10
9 L= J + K
| Deprecated |
Branching to END IF from outside a block | 66 GO TO 77 ; . . .
IF (E) THEN ; . . .
77 END IF
| Deleted |
Alternate return | CALL SUBR( X, Y, *100, *200 )
| Deprecated |
PAUSE statement | PAUSE 600
| Deleted |
ASSIGN statement and assigned GO TO statement | 100 . . .
ASSIGN 100 TO H
. . .
GO TO H . . .
| Deleted |
Assigned statement numbers and FORMAT specifiers | ASSIGN 606 TO F ... WRITE ( 6, F )...
| Deleted |
H edit descriptors | 606 FORMAT ( 9H1GOODBYE. )
| Deleted |
Computed GO TO statement | GO TO (10, 20, 30, 40), index
| (obsolete) |
Statement functions | FOIL( X, Y )= X**2 + 2*X*Y + Y**2
| (obsolete) |
DATA statements among executable statements | X= 27.3
DATA A, B, C / 5.0, 12.0, 13.0 /
. . .
| (obsolete) |
CHARACTER* form of CHARACTER declaration | CHARACTER*8 STRING ! Use CHARACTER(8)
| (obsolete) |
Assumed character length functions | CHARACTER*(*) STRING
| (obsolete)[31] |
Fixed form source code | Column 1 contains C or * or?! for comments. Columns 1 through 5 for statement numbers Any character in column 6 for continuation. Columns 73 and up ignored | (obsolete) |
Code examples of fortran
program average ! Read in some numbers and take the average ! As written, if there are no data points, an average of zero is returned ! While this may not be desired behavior, it keeps this example simple implicit none real, dimension(:), allocatable :: points integer :: number_of_points=0.0 real :: average_points=0., positive_average=0., negative_average=0. write (*,*) "Input number of points to average:" read (*,*) number_of_points allocate (points(number_of_points)) write (*,*) "Enter the points to average:" read (*,*) points ! Take the average by summing points and dividing by number_of_points if (number_of_points > 0) average_points = sum(points) / number_of_points ! Now form average over positive and negative points only if (count(points > 0.) > 0) then positive_average = sum(points, points > 0.) / count(points > 0.) end if if (count(points < 0.) > 0) then negative_average = sum(points, points < 0.) / count(points < 0.) end if deallocate (points) ! Print result to terminal write (*,'(a,g12.4)') 'Average = ', average_points write (*,'(a,g12.4)') 'Average of positive points = ', positive_average write (*,'(a,g12.4)') 'Average of negative points = ', negative_average end program average
What Is The Difference Between If Then And Do While Statements?
IF THEN combined with GO TO statements will let you do anything you want. The DO WHILE and other DO constructs allow you to loop through certain portions of code many times without ever writing GO TO statements. This makes coding slightly simpler, definitely clearer.
What are the commonly used character functions in Fortran?
The commonly used character functions in Fortran are:
- len(string)
- index(string,sustring)
- achar(int)
- iachar(c)
- trim(string)
- scan(string, chars)
- verify(string, chars)
- adjustl(string)
- adjustr(string)
- len_trim(string)
- repeat(string,ncopy)
What is DBLE (A) function?
DBLE (A) function:?It is a Numeric Function which is used to convert A to a double precision real number.
Terry White is a professional technical writer, WordPress developer, Web Designer, Software Engineer, and Blogger. He strives for pixel-perfect design, clean robust code, and a user-friendly interface. If you have a project in mind and like his work, feel free to contact him