(8) Input & Output Formats (Sina)

(8) Input & Output Formats (Sina) - Input and Output...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Input and Output Formats Fall 2009 Sina Meraji
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What happened to * ? WRITE ( * , * ) READ ( * , * ) Target: screen / keyboard, file Format
Background image of page 2
Fortran Formats ± The READ and WRITE statements we have seen so far are called free-format statements. The are easy to use but we have no control over the placement of the input or appearance of the output. ± To control the appearance of the input and output, Fortran allows us to use format specifications .
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Name: Barack Obama Data of Birth: August 4, 1961 Nationality: American Electoral won: 365 Name: Barack Obama Data of Birth: August 4, 1961 Nationality: American Electoral won: 365 Which one is nicer? QuickTime™ and a decompressor are needed to see this picture. QuickTime™ and a decompressor needed to see this picture.
Background image of page 4
Formats ± Allow us to specify the placement of values both in output and input ± Using format descriptors we can control: The appearance of output values Repetition Vertical positioning Horizontal positioning
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Methods of Using Format ( format specifications ) WRITE ( * , ”“ ) WRITE ( * , label ) label FORMAT WRITE ( * , ( F.15 ) ) cost WRITE ( * , 100 ) cost 100 FORMAT ( F.15 ) e.g.
Background image of page 6
Format Codes Most common format letters: F real numbers, fixed point format I integer A text string E real numbers, exponent notation X horizontal space / vertical space e.g. 100 FORMAT ( F 10.4)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Real Values Fixed point notation F w . d Fixed point notation Width Decimal REAL :: X = 1100.1003 WRITE(*, ( F 10 . 4 ) ) X # 1100. 1003 output d = 4 w = 10 including space and ‘.’ # means space
Background image of page 8
Note ± Output is right adjusted, i.e. spaces are added to the left ± Width includes space for : 1. d decimal digits 2. The decimal point 3. The whole number 4. The sign, if the number is negative
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example PROGRAM TestFormat
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course COMP COMP 206 taught by Professor Vybihal during the Spring '04 term at McGill.

Page1 / 35

(8) Input & Output Formats (Sina) - Input and Output...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online