CHAPTER 5 INPUT/OUT FORMAT. Introduction READ (*,*) x WRITE (*,*) x This is free format: the first * is for I/O device number (* = input is keyboard *

Slides:



Advertisements
Similar presentations
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
1 Chapter 2 Basic Elements of Fortran Programming.
CPS120: Introduction to Computer Science INPUT/OUTPUT.
Fortran 4- Reading and Writing from Data Files Chapter 4 of your Fortran book.
More Review, with Some New Chapter 3. Review C++ simple data types – Integral and float – Arithmetic operators Expressions and expression evaluation –
The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
1 Basic I/O Input and Output. 2 The READ Statement Basic Version l Performs a list-directed read from the file (or device) indicated by the unit number.
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
11/06/20151 FORTRAN 77 Programming. Lecture 5 : January 2001 Dr. Andrew Paul Myers.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
Input and output. Input streams n there are two ways of handling I/o n list-directed –done using default settings –PRINT*, num –READ*, num n formatted.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Generalized I/O. Mystery of stars I/O statements took the form read *, x, y,z print *, a,b,c Such I/O is said to be List-directed or in free format user.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Exponents and Scientific Notation Evaluate exponential forms with integer exponents. 2.Write scientific notation in standard form. 3.Write standard.
Numeric precision in SAS. Two aspects of numeric data in SAS The first is how numeric data are stored (how a number is represented in the computer). –
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Exponents and Radicals Digital Lesson. Copyright © by Houghton Mifflin Company, Inc. All rights reserved. 2 Repeated multiplication can be written in.
 Form of notation for writing repeated multiplication using exponents.
Chapter 8 Test Review Exponents and Exponential Functions
6.22 positive exponents, perfect squares, square roots, and for numbers greater than 10, scientific notation. Calculators will be used.
INPUT / OUTPUT STATEMENTS
Powers and roots. Square each number a) 7 b) 12 c) 20 d) 9 e) 40 a) 49 b) 144 c) 400 d) 81 e) 1600.
21 April, 2000 CS1001 Lecture 22 Formatted Input and Output.
Copyright © Curt Hill Formatting Reals Outputs other than normal.
SCIENTIFIC NOTATION. Scientific Notation: a short-hand way of writing large numbers or small numbers without writing all of the zeros.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
CS 1704 Introduction to Data Structures and Software Engineering.
160 as a product of its prime factors is 2 5 x 5 Use this information to show that 160 has 12 factors.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
28 Formatted Output.
Chapter 9 - Formatted Input/Output
Chapter 9 C Formatted Input/Output
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
TMF1414 Introduction to Programming
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Scientific Notation.
Evaluate nth Roots and Use Rational Exponents
Expanded Form = 3, (3 x 1,000) + (5 x 100)
Chapter 9 - Formatted Input/Output
Scientific Notation.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Presentation transcript:

CHAPTER 5 INPUT/OUT FORMAT

Introduction READ (*,*) x WRITE (*,*) x This is free format: the first * is for I/O device number (* = input is keyboard * = output is the screen) The second * means free format Input devices: keyboard, files Output devices: screen, printer, files

Formatting Descriptors (Fields) I field for integers ******************************** Integer :: index=-12,junk=4,number = Write (*,200) index, index+12, junk, number 100 FORMAT (‘ ‘,2I5, I6,I10) **********************OR ********** Integer :: index=-12,junk=4,number = Write (*,’(1x,2I5, I6,I10)’) index,index+12,junk,number ****************************************** READING is similar to WRITING EXCEPT writing is right- justified. In reading the numbers anywhere within the field length are read

F Descriptors (for REAL) REAL:: a =12.3, b =.123, c= WRITE (*,100) a,b,c 100 FORMAT (‘ ‘,3F10.2) ************************************************** READING is similar to writing EXCEPT, writing is right-justified. In reading the numbers anywhere within the field length are read. Also it is important to insert the decimal point for the variable to be read.

E Descriptors (for exponential REAL) For large and small numbers REAL :: a =1.2346E6, b=0.001, c=-77.7E10 REAL :: d =-77.7E10 WRITE (*,’(1x, 2E14.4,E13.6,E11.6)’)a,b,c,d OUTPUT E E E+12*********** ******************************************* Length of field w at least 7 + number of digits after decimal point 1 for sign of mantissa (e.g e12), 2 for zero and decimal point, 1 for E, 1 for sign of exponent, 2 for exponent itself) *************************************************************************** READING is similar to writing EXCEPT, writing is right-justified. In reading the numbers anywhere within the field length are read. Also it is important to insert the decimal point and show the exponent for the variable to be read.

ES Descriptors (for exponential REAL Using Scientific and Engineering Notations) Similar to E descriptor For large and small numbers REAL :: a =1.2346E6, b=0.001, c=-77.7E10 REAL :: d =-77.7E10 WRITE (*,’(1x, 2ES14.4,ES13.6,ES11.6)’)a,b,c,d OUTPUT E E E+11***********

A Descriptors (for Characters) Character (len = 17)::name=‘this is a mohamed’ Character (len = 17)::name='this is a mohamed' Write (*,10) name Write (*,11)name Write (*,12) name 10 format (' ',A) 11 format (' ',A20) 12 Format (' ',A6) ****************************** this is a mohamed this i **************************************************************

A Descriptors (for Characters) Character (len=10):: string_1, string_2 Character (len=5) :: string_3 ; character (len=15):: string_4,string_5 Read (*,’(A)’)string_1; Read (*,’(A10)’)string_2; Read (*,’(A10)’)string_3 Read (*,’(A10)’)string_4; Read (*,’(A)’)string_5 Write (*,*) string_1,string_2,string_3,string_4,string_5 ******************************************** Input: abcdefghijklmno Abcdefghijklmno ******************************* Output: abcdefghij fghij abcdefghij abcdefghijklmno

Other Descriptors X = for space T = for position / = for new line

Reading from a file OPEN (UNIT=3, FILE=‘input’, STATUS='OLD', ACTION='READ', & IOSTAT=status ) Read (3,*) x CLOSE ( UNIT=3 ) readloop: DO READ (3,*,IOSTAT=status) value ! Get next value IF ( status /= 0 ) EXIT ! EXIT if not valid. nvals = nvals + 1 ! Valid: increase count WRITE (*,1010) nvals, value ! Echo to screen 1010 FORMAT (' ','Line ', I6, ': Value = ',F10.4 ) END DO readloop

Writing to file OPEN (UNIT=4, FILE=‘output’, STATUS=‘NEW', ACTION=‘WRITE', & IOSTAT=status ) Write 4,100) x,y,z 100 format (1x,” x = “, f10.2, “ y = “, f10.2, “ z = “, f10.2)

Example PROGRAM table IMPLICIT NONE INTEGER :: cube ! The cube of i INTEGER :: i ! Index variable INTEGER :: square ! The square of i REAL :: square_root ! The square root of i OPEN(UNIT=10,FILE='table.txt',STATUS='unknown') ! Print the title of the table. WRITE (10,100) 100 FORMAT (1x, T4, 'Table of Square Roots, Squares, and Cubes') ! Print the column headings after skipping one line. WRITE (10,110) 110 FORMAT (1x, T4,'Number',T13,'Square Root',T29,'Square',T39,'Cube') WRITE (10,120) 120 FORMAT (1X,T4,'======',T13,'===========',T29,'======',T39,'===='/) ! Generate the required values, and print them out. DO i = 1, 10 square_root = SQRT ( REAL(i) ) square = i**2 cube = i**3 WRITE (10,130) i, square_root, square, cube 130 FORMAT (1X, T4, I4, T13, F10.6, T27, I6, T37, I6) END DO END PROGRAM table