09FileArrays-handout

09FileArrays-handout - File Input / Output Multidimensional...

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

View Full Document Right Arrow Icon
File Input / Output Multidimensional Arrays Amir Hossein Rabbani Winter 2009
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example X format READ X is equal to 1X which means 1 space The READ statement counts the spaces in the input but does not use them in assigning the variables The READ statement ignores entries as many as nX PROGRAM XFormat IMPLICIT NONE INTEGER :: a,b READ (*, ”(I2,X,I2)” ) a,b WRITE (*,*) “a = “,a,” and b = “,b END PROGRAM XFormat input 12 # 45 12345 # 12 # 45 ## 12 # 45 A=12 B=45 A=12 B=45 A=1 B=4 A=0 B=2 output
Background image of page 2
Example Free format READ Using comma and space one can assign numerous variables with one READ Automatically detects (and verifies) the input type If there is a mismatch between input type and the variable being used, an error message will be printed Multiple spaces between entries are allowed but multiple commas are not. PROGRAM FreeFormat IMPLICIT NONE INTEGER :: a,b READ (*,*) a,b WRITE (*,*) “a = “,a,” and b = “,b END PROGRAM FreeFormat input 123 # 456 123,456 123 #### 456 123,,456 A=123 B=456 A=123 B=456 A=123 B=456 A=123 B= garbage! output
Background image of page 3

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

View Full DocumentRight Arrow Icon
Review Purpose Edit Description Reading / Writing INTEGERS I w Reading / Writing REALs Decimal form F w.d Exponential form E w.d Reading / Writing LOGICALs L w Reading / Writing CHARACTERs A w Positioning Horizontal n X Vertical n /
Background image of page 4
This class Finishing INPUT / OUTPUT Note about precision problem Multidimensional Arrays
Background image of page 5

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

View Full DocumentRight Arrow Icon
Using Files Sometimes we need to read values which are generated by other programs such as spreadsheets or word These values are usually stored in a file This makes reading large data sets easy Likewise, we would like to write processed values to other files to be used by other programs QuickTimeª and a decompressor are needed to see this picture.
Background image of page 6
File INPUT and OUTPUT READ ( * , * ) and WRITE ( * , * ) only reads from / writes to standard input (e.g. keyboard) / output (screen) To read from a file, we have to specify the name of the file and give the program some way of identifying it We use this identification to refer to the file in the program
Background image of page 7

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

View Full DocumentRight Arrow Icon
File INPUT and OUTPUT 3 Steps: 1. Open a file 2. Input / output using READ and WRITE READ : read data from the opened file WRITE : write data to the opened file 3. Close the file
Background image of page 8
OPEN Syntax OPEN (UNIT = N , FILE = “file name” ) An integer between 1 and 99 used as a reference to the file in the program. There are some
Background image of page 9

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

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

Page1 / 31

09FileArrays-handout - File Input / Output Multidimensional...

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

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