Docsity

Character Data - Mechanical Engineering - Lecture Slides, Slides of Mechanical Engineering

Partial preview of the text

Download Character Data - Mechanical Engineering - Lecture Slides and more Slides Mechanical Engineering in PDF only on Docsity!

MET 50

CHARACTER DATA

  • We have extensively used REAL and INTEGER data types.
  • There is also:
  • CHARACTER data
  • COMPLEX data
  • LOGICAL data

Z = X + i Y

  • X is called the real part of Z {denoted Re(Z) }
  • REAL (X) → value
  • Y is called the imaginary part of Z {denoted Im(Z) }
  • AIMAG (X) → value
  • Fortran stores Z as two real numbers: X and Y

When you write

• PRINT*,Z

You get: (12.0, -9.0)

  • Written in code as follows:

“STRING” or ‘STRING’

  • Declared as follows:

CHARACTER ( n ) :: string

  • Where “ n ” is the length = number of characters in the string
  • Other ways to declare:

CHARACTER (LEN= n ) :: string

CHARACTER :: string

⇒ Length in 2 nd^ example is assumed to be ONE!!!

  • Other ways to declare:

CHARACTER :: stringa10, stringb20, stringc*

  • Formatted read/write of a string:
  • In the FORMAT statement, use the descriptor:

“A n ”

As in: format (1x, I5, A20, F10.2)

Options: “I”, “F”, “E”, and now…”A” (also “D”…last slides)

  • Unformatted read/write:

CHARACTER (3) :: MONTH

INTEGER :: NUMBER

READ*,MONTH, NUMBER

You might enter: “JAN” 150

  • If a string is read in that is too short, it is padded with blanks on the right.

CHARACTER (12) :: DAY

DAY = “WEDNESDAY”

DAY is stored as “WEDNESDAY ”

Character data can be “added” !!!

  • The operation is called: concatenation
  • “cat” for short

character :: first5, second6, third* first = ‘minor’ second = ‘ thing’ third = first // second

produces… third = ‘minor thing’

  • DOUBLE PRECISION data…

Suppose you declare:

REAL :: TEMP

and later print a value with PRINT*,TEMP

→ a number with certain number of digits after the decimal.

Instead if you declare:

DOUBLE PRECISION:: TEMP

and later print a value with PRINT*,TEMP

→ a number with DOUBLE the number of digits after the decimal.

→ Double precision!