08InputOutput-handout

08InputOutput-handout - Input and Output Formats Winter...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Input and Output Formats Winter 2009 Amir Hossein Rabbani What happened to * ? WRITE ( * , * ) READ ( * , * ) Target: screen / keyboard, file Format 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 of the input and output, Fortran allows us to use format specifications . 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 are needed to see this picture. 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 Methods of Using Format ( format specifications ) WRITE ( * , ) WRITE ( * , label ) label FORMAT WRITE ( * , ( F.15 ) ) cost WRITE ( * , 100 ) cost 100 FORMAT ( F.15 ) e.g. 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) 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 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 Example PROGRAM TestFormat IMPLICIT NONE REAL :: x = 1.0 REAL :: y = 1200.1003 WRITE (*, 900) x, y 900 FORMAT...
View Full 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

08InputOutput-handout - Input and Output Formats Winter...

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