Академический Документы
Профессиональный Документы
Культура Документы
1
ENVIRONMENT
Hint:
A computer program written according to the Syntax of a particular program
language is called a Source Code.
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Library of
Functions
Hint:
A Library is a group of instructions to evaluate common functions, like trigonometric,
logarithmic functions, etc.
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
PROGRAM name
IMPLICIT NONE
[specification part]
[execution part]
[subprogram part]
END PROGRAM name
Hint:
! Means that the line is a comment. It’s recommended to use ! In order to have a
better explanation what the program does.
The Executable is portable ☺
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Hint:
! Means that the line is a comment.
It’s recommended to use ! in order to have a better explanation what the program
does.
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Exercise #1:
• Prepare a flow diagram that
shows if a number is even or odd.
Exercise #2:
• Lets figure out what does these
flow diagrams do!
Exercise #3:
• Prepare a flow diagram that
shows Bisection method.
Hint:
Bisection Method is in the graph!
Source:
http://upload.wikimedia.org/wikipedia/commons/8/8c/Bisection_method.svg
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
START
Yes
Solution for the x%2 == 0
Exercise #1
No
END
Hint:
Even numbers: 2, 4, 6, 8, etc.
Odd numbers: 1, 3, 5, 7, etc.
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Source:
http://people.revoledu.com/kardi/tutorial/BasicMat http://4.bp.blogspot.com/-f6-
h/Prime/image/Algorithm- Oha58oKU/Up76s15y3rI/AAAAAAAAA6I/AIILGpM_Ag8/s1600/FLOWCHA
RT+FOR+CHECKING+WEITHER+A+NUMBER+IS+PRIME+OR+NOT.PNG
PrimeFactor_clip_image002.jpg
Hint:
Prime numbers are numbers that have no additional divisors other than 1 and itself.
Ex: 2 (PRIME) 3 (PRIME) 4 (NOT PRIME)
2 divided by 1 is 2 3 divided by 1 is 3 4 divided by 1 is 4
2 divided by 2 is 1 3 divided by 2 is NOT INTEGER 4 divided by 2 is 2
3 divided by 3 is 1 4 divided by 3 is NOT INTEGER
4 divided by 4 is 1
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
START
Solution for the
Exercise #3 a = x₁
b = x₂
Yes f(a)*f(x)
>0 Decision Shape
No
a=x b=x Update interval
No
Yes
Output:
Root “x”
STOP
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
START Check your
Naval Application background
Input knowledge in
Prepare a flow diagram to i, n Numerical
assign the factor in numerical Yes Analysis! ☺
integration Simpson’s 1st rule.
i = 0 or i = n
No
Subindex goes from 0 to n
Factor=…..
If i=0 and n=3, then Factor=? i = even Factor=…
END
∑ [1f
1
+ 4f1 + 2f2 + 4f3 + 2f4 + ... 2fn −2 + 4fn −1 + 1fn ]
Hint: ∫ f ( x ) dx ≈ h
3
0
Basic Operators
Operator Meaning
+ Addition
- Substraction
/ Division
* Multiplication
Hint:
…
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Intrinsic Functions
Function Meaning
ABS(x) Absolute Value
ACOS(x) Inverse Cosine
ASIN(x) Inverse Sine
ATAN(x) Inverse Tangent
COS(x) Cosine (Remember that this value inside goes in radians)
EXP(x) Exponential function
LOG(x) Natural Logarithm
LOG10(x) Logarithm to base 10
MAX(x1,x2,…) Maximum value in a range
MIN(x1,x2,…) Minimum value in a range
MOD(x1,x2) x1-int(x1/x2)*x2; the same than the remainder
SQRT(x) Square root function
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Conditional Expressions
Data types
program example
! My first program
write(*,*) ’Hello there’
end program example
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Do cycles:
do i=1,n (increment is 1)
…
end do
EXAMPLE
program cycles
implicit none
!define variables
integer :: n
do n = 1, 10
write(*,*) n
end do
end program cycles
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Do while:
do while (condition)
…
end do
EXAMPLE
program cycles1
implicit none
!define variables
integer :: n=10
do while(n.gt.0)
write(*,*) n
n=n-1
end do
end program cycles1
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
General Knowledge
read(stream, label [, end=end][, err=err]) list
• stream is a number previously linked to a file, or a character variable, or *, where * here indicates
the default value, usually the screen of a terminal session. If stream is a character variable, the
result of the write is stored in that variable, and can be manipulated as such within the program.
• label is the number of a format statement, or * for free format.
• list is a list of items to be transferred, separated by commas, possibly including text strings
enclosed in quotation marks.
• The optional items end and err are so that you can provide statement labels end and err to which
control moves in the event that the end of data is reached prematurely (end) , or some error is
encountered (err).
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Do i=1,100
write(*,1) i,i*i,i**3
1 format(i4,i6,i8)
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
nship=“Tanker ship *”
lpp=114,0
breadth=14,8
depth=8,1
dwt=6500,00
nprop=1
write(*,10)nship,lpp,breadth,depth,dwt,nprop
10 format(“ship:”,3x,a30,/,&
(“lpp:”,3x,f10.2,/,&
(“b:”,3x, f10.2,/,&
(“d:”,3x, f10.2,/,&
(“dwt:”,3x, f10.2,/,&
(“number of props:”,3x,i2)
Arrays
TEST YOUR RESULT!
i=1
X=0,0+0,25*0,25
X=0,0625
i=2
X=0,0625+1,2*1,2
X=1,5025
i=3
X=1,5025+0,2*0,2
X=1,5425
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Arrays
Inside of the matrix:
3 # of rows
4 # of columns
Format
4 f 5.2
4 # of columns of information in the matrix
Arrays
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Arrays
Dimension icont(10) Single column with 10 values
Dimension x(0:10)
Data Data x/0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0/ or
Data x/11*0.0/
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
Exercise
Using the data command, assign values to the C constant which is employed in the
DNV formulation, to calculate the effective width of primary elements (girders). In the
following table values of the constant C are presented, taken from the mentioned
classification rules, where r is the number of secondary elements (stiffeners) which
transmit the load from the plate to the primary elements.
The user must input the ratio a/b, and the number of stiffeners, and the program print
on the screen the effective width. For an interpretation of the geometry, see the
following figure, taken from the mentioned reference.
INTRODUCTION TO FORTRAN PROGRAMMING IN THE VISUAL STUDIO
ENVIRONMENT
https://rules.dnvgl.com/docs/pdf/DNV/rulesship/2011-01/ts302.pdf
STRUCTURED PROGRAMMING 2
Functions
Advantages:
Functions
program name
implicit none
[specification part]
[execution part]
contains
[functions]
end program name
Specification part
Execution part
Function #1
Function #2
STRUCTURED PROGRAMMING
Functions
STRUCTURED PROGRAMMING
Exercise