Sci Prog Atmos Sci
Sci Prog Atmos Sci MSC 321
Popular in Course
Popular in Marine Science
This 4 page Class Notes was uploaded by Rowan Ward on Thursday September 17, 2015. The Class Notes belongs to MSC 321 at University of Miami taught by Staff in Fall. Since its upload, it has received 16 views. For similar materials see /class/205715/msc-321-university-of-miami in Marine Science at University of Miami.
Reviews for Sci Prog Atmos Sci
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/17/15
Chapter 10 Input and Output Computer programs interact with the world by receiving input and delivering out puts through hardware such as keyboards7 displays7 disk drives7 tape drives and network connections FORTRAN programs do these inputoutput IO operations by reading from and writing to logical IO units The actual data transfer is performed by a set of subprograms that are part of FORTRAN7 called the IO library The compiler inserts these lO library calls upon code compilation when ever it encounters lO statement in the code The lO library routines associate the logical lO units mentioned in the code with logical IO devices such as le names and UnixLinux logical devices These logical devices are in turn attached by Unix to the appropriate physical IO devices So far we have used only read and print for lO The statement read accepts input from the logical lO unit named standardin which is normally attached to the keyboard7 and print write to the logical unit named standard out7 which is normally associated with the display Standard in and standard out can both be redirected at run time using uniX pipelines Another important attribute of the read statements is that the value it reads can be in a wide variety of formats Suppose the following statements are encoun tered in a program real C read C and the value that is to be input is 37 Typing one of the following input text strings results in the variable getting that value 37 370 37e1 Because of the variations permitted in the format of the input value7 read is said to do freeformat input Programs receiving data from keyboard input should 65 66 CHAPTER 10 INPUT AND OUTPUT read it using free format so the user can enter the data in reasonable ways In the case of the write we leave it up to the FORTRAN library lO to decide the precise format to use in writing up the results7 and this is referred to as free format output Sometimes however7 it is important to insist that certain date be read in our written out in speci c xed formats7 or in binary form rather than as characters7 and it is often necessary to read from a unit other than standard in and to write to a unit other than standard out 101 read and write statements FORTRAN provides a more general form of the read statement7 and a write statement which is a generalization of print These statements permit the speci cation of a logical unit7 and a data format to be used in the lO operation and have the form readunit format list writeunit format list where 0 unit speci es the logical lO unit to use If is given for the unit7 read uses standard in and write uses standard out if unit is not it is an integer in the range 0 99 specifying the logical unit number Some numbers are refer to speci c units 5 to standard in7 6 corresponds to standard out and 0 corresponds to standarderror Like standard out7 standard error is usually attached to the display 0 format speci es the format of the data If is given for format7 free format is used So read a is the same as read a7 and write a is the same as print a There are two forms for the format statements 7 An integer indicating the label number of a format statement that is speci ed on a separate line7 eg write620 a i A character that inlines the format statement within the write state ment as in write6fmt i2 7 i We will look in more details at either constructs later 0 list is a list of variable names to be read or printed The list can include expressions7 such as 20sqrt X in the case of the write statement 102 UNIT ASSIGNMENTS 67 102 Unit Assignments Associating logical units with external les is done with the open statement There is a minimum number of attributes that must be speci ed in the open statement for it to establish the connection with the les The remaining attributes are optional and the compiler provide default values if none are speci ed in the code The open is an execution statement and may appear anywhere in the program Once executed the connection of the unit to the le is valid in the main program as well as in any subprograms for the remainder of the execution until a Close statement is encountered the latter terminates the connection and a new one can be established to a di ferent le using the same unit number If a le is connected to one unit it may not be connected to a di ferent unit at the same time Like connecting a le to a unit that is already assigned is not permitted The format of the open statement is open listofconnectionspecification where the permissible connection speci cations include o unit an integer expression is the logical unit number associated with the le 0 file scalar character expression is the name of the le to connect to If the le name is a constant enclose the name in single quotes 0 form scalar character expression This keyword can have one of two values formatted indicates that the variables to be printed will be translated from the binary form stored in the computer memory to something humanly readable like decimals and ASCII characters unformatted indicate that the binary form should be written to le no translation take place If large les are being written this is the preferred form for speed and to reduce le size 0 status scalar character expression indicates whether the le exist or not and how to handle it The permissible values are 7 old The le exist the OS should just open it An error message is printed otherwise and the code stops 7 new The le does not exist the OS should create it An error occurs if the le does not exist 7 unknown If the le exist then the OS just opens it otherwise it is created and made available to the program 68 CHAPTER 10 INPUT AND OUTPUT scratch indicates that the le is temporary and should be deleted upon issuing the Close statement 0 action scalar character expression 0 access scalar character expression 0 iostat scalar default integer variable
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'