Fortran_Lecture_7 - Fortran Class Notes Lecture 7 Formatted...

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

View Full Document Right Arrow Icon
Lecture 7 – Formatted Input/Output The first topic for today is formatted input/output in Fortran. Last time, we looked at how Fortran reads and writes external files by replacing that first asterisk with a unit number. The second asterisk is the formatting element, and now we’re going to learn about the difference between unformatted and formatted output. program formatted character s*9 double precision b b=45318.591378d0 n=9830 s='character' i=16832510 j=57463015 write(*,*) b,n,s write(*,*) ' ' write(*,15) b,n,s write(*,16) b,n,s write(*,'(F18.8,1x,I6,1x,A11,/)') b,n,s write(*,17) i,j 15 format(F12.6,1x,I4,1x,A9,/) 16 format(F10.6,1x,I3,1x,A5,/) 17 format(2(1x,I8)) stop end The screen output looks like: 45318.5914 9830character 45318.591378 9830 character ********** *** chara 45318.59137800 9830 character 16832510 57463015 This program writes the same three variables to the screen in four different ways, first unformatted and then formatted in three different ways. Unformatted is quick and easy to use, but it has some distinct disadvantages. It truncates the real number after four decimal places and rounds up, and it doesn’t know to insert a space at the beginning of the character string. When writing tabular data to an external file, you will usually want
Background image of page 1

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

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

Page1 / 2

Fortran_Lecture_7 - Fortran Class Notes Lecture 7 Formatted...

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

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