Names in Fortran 90
Names or identifiers must adhere to the following rules:
cannot be longer than 31 characters
must be composed of alphanumeric characters and underscores
first character must be a letter
Good thing: identifiers are case-insensitive
A variable is a data whose values can be changed, unlike constants. They have similarity though, both variables and constants have a type, which can be one of the 5 intrinsic types, or a derived type.
5 intrinsic types:
Integer type:
Real type: real type and double precision
Complex type
Logical type: two logical values: .true. and .false. (yes, there are dots defending true and false)
Character type: characters and strings
Consider the following program for the illustration of the concept of variables, constants and types:
- literal constants: a constant value without a name
- named constants: a constant value with a name, named constants and variables must be declared at the beginning of a program in a so-called type declaration statement. Named constants must be declared with the “parameter” attribute:
Example:
real, parameter:: pi=3.1415927
Variables
Variables should be declared at the beginning of a program in a type declaration statement:
Example:
integer :: total
real::average1, average2 ! this declares 2 real values
complex:: cx
logical :: done
character(len=80):: line ! a string consisting of 80 characters
then after the declaration, this statements can be used as:
Example:
total = 6.7
average1=average2
done=.true.
line = “this is a line” ! characters are enclosed in a double quotes (“)
cx = cmplx(1.0/2.0, -3.0) ! cx = 0.5 – 3.0i, one has to use cmplx it is an intrinsic function
Arrays
Array is a collection of variables of the same type. Arrays can be 1D (like vectors in math), 2D (matrices) up to 7D. Arrays are declared with the dimension attribute:
Examples:
real, dimension(5)::vector ! 1-dim, real array containing 5 elements
integer, dimension(3,3)::matrix !2-dim. Integer array
Elements of an array can be referenced by specifying their subscripts.
Example:
- 1st element of the vector is, vector(1)
- row 1, column 1 of a matrix is matrix(1,1)
Character Strings
- concatenation: character(len=*), parameter :: & state=”Michigan’, name=”tech”
characteract(len=12):: school
school = state // name
! // is used to concatenate state and name producing “michigantech”
Congratulations @fortran-guy! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness and get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @fortran-guy. I see you have not gotten very active here on Steem. I am just checking up on everyone who is followed by the Steem Terminal and just wanted to let you know that if you ever have any questions or need any help we at the Terminal are here for you!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @fortran-guy! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit