{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

09FileArrays-handout

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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 /
Image of page 4
This class Finishing INPUT / OUTPUT Note about precision problem Multidimensional Arrays
Image of page 5

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

View Full Document Right 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.
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
Image of page 7

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

View Full Document Right 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
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
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern