Types, Variables, Constants, OperatorssteemCreated with Sketch.

in #fortran6 years ago

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:

  1. Integer type:

  2. Real type: real type and double precision

  3. Complex type

  4. Logical type: two logical values: .true. and .false. (yes, there are dots defending true and false)

  5. Character type: characters and strings

Consider the following program for the illustration of the concept of variables, constants and types:


1548433263578.png

  • 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


1548433599760.png

integer, dimension(3,3)::matrix  !2-dim. Integer array


1548433615494.png

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”
Sort:  

Congratulations @fortran-guy! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 10 upvotes. Your next target is to reach 50 upvotes.

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:

Carnival Challenge - Collect badge and win 5 STEEM
Vote for @Steemitboard as a witness and get one more award and increased upvotes!

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!

2N61tyyncFaFVtpM8rCsJzDgecVMtkz4jpzBsszXjhqan9qDNWVTTkbDg7TBEtKFRGVqq9uy8RhBrPE45CnCVhb1DKv8GsLv1tMsWuCFZAr3S4zzCcps8hZZw2Z155KRq6yhEZY5CvhC.jpg

Congratulations @fortran-guy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

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!

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.029
BTC 63706.08
ETH 2615.50
USDT 1.00
SBD 2.82