1 / 12

Programming For Nuclear Engineers Lecture 5 Basic I/O Concepts

Programming For Nuclear Engineers Lecture 5 Basic I/O Concepts. 1- Formats and Formatted WRITE Statements 2- Output Devices 3- Format Descriptors 3.1- Integer Output- The I descriptor 3.2- Real Output-The F Descriptor 3.3- Real Output- The E Descriptor

arlene
Download Presentation

Programming For Nuclear Engineers Lecture 5 Basic I/O Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming For Nuclear Engineers Lecture 5Basic I/O Concepts

  2. 1- Formats and Formatted WRITE Statements 2- Output Devices 3- Format Descriptors 3.1- Integer Output- The I descriptor 3.2- Real Output-The F Descriptor 3.3- Real Output- The E Descriptor 3.4- True Scientific Notation – The ES Descriptor 3.5- Logical Output – The L descriptor 3.6- Character Output – The A descriptor 3.7- Horizontal Positioning- The X and T Descriptors 3.8- Changing Output Lines- The Slash (/) Descriptor 4- Formatted READ Statements

  3. 1- Formats and Formatted WRITE Statements The word formatmay be used to specify the exact manner in which variables are to be printed out by a program. In general, a format can specify both the horizontal and the vertical position of the variables on the paper, and also the number of significant digits to be printed out. WRITE (*,100) i, result 100 FORMAT (‘The result for iteration’.I3,’is’,F7.3) The above FORMAT statement contains the formatting information used by the WRITE statement. The number 100 that appears within the parentheses in the WRITE statement is the statement label of the FORMAT statement describing how the values contained iniand result are to be printed out.

  4. I3 and F7.3 are the format descriptors associated with variables i and result, respectively. The resulting output line is shown below, compared to the same line printed with free format. The result for iteration 21 is 3.142 (formatted) The result for iteration 21 is 3.141593 (free format) In addition to FORMAT statements, formats may be specified in character constants or variables. WRITE (*,100) i,x ! Format in FORMAT statement 100 FORMAT (1X,I6,F10.2) CHARACTER(len=20)::string ! Format in character variable string=‘(1X,I6,F10.2)’ WRITE (*,string) i,x WRITE (*,’(1X,I6,F10.2)’) i,x ! Format in character constant

  5. 2- Output Devices The output from a FORTRAN program is displayed on an output device. There are many types of output devices that are used with computers. Some output devices produce permanent paper copies of the data, while others just display it temporarily for us to see. 3- Format Descriptors Format descriptors are fall into four categories: Format descriptors that describe the vertical position of a line of text. Format descriptors that describe the horizontal position of data in a line. Format descriptors that describe the output format of a particular value. Format descriptors that control the repetition of portions of a format.

  6. 3.1 Integer Output- The I descriptor The descriptor used to describe the display format of integer data is the I descriptor. It has the general form rIw or rIw.m

  7. Where r, w, and m have the meanings given in the last table. Integers are printed out so that the last digit of the integer occupies the rightmost column of the field. If an integer is too large to fit into the field in which it is to be printed, then the field is filled with asterisks. 3.2 Real Output-The F Descriptor One format descriptor used to describe the display format of real data is the F descriptor. It has the form rFw.d Real values are printed right justified. If a real number is too large to fit into the field in which it is to be printed, then the field is filled with asterisks. 3.3 Real Output- The E Descriptor Real data can also be printed in exponential notation using the E descriptor. The E format descriptor has the form rEw.d Real values displayed in exponential notation with the E descriptor are normalized to a range between 0.1 and 1.0. If a real number cannot fit into the field in which it is to be printed, then the field is filled with asterisks.

  8. 3.4 True Scientific Notation – The ES Descriptor Conventional scientific notation expresses a number as a value between 1.0 and 10.0 times a power of 10, while the E format expresses the number as a value between 0.1 and 1.0 times a power of 10. The ES descriptor is exactly the same as the E descriptor, except that the number to be output will be displayed with a mantissa in the range between 1 and 10. The ES descriptor has the form rESw.d 3.5 Logical Output – The L descriptor The descriptor used to display logical data has the form rLw

  9. The value of a logical variable can only be .TRUE. or .FALSE.. The output of a logical variable is either a T or an F, right justified in the output field. 3.6 Character Output – The A descriptor Character data is displayed by using the A format descriptor. rA or rAw The rA descriptor displays character data in a field whose width is the same as the number of characters being displayed, while the rAw descriptor displays character data in a field of fixed width w. If the width w of the field is longer than the length of the character variable, the variable is printed out right justified in the field. If the width of the field is shorter than the length of the character variable, only the first w characters of the variable will be printed out in the field.

  10. 3.7 Horizontal Positioning- The X and T Descriptors The X descriptor inserts spaces into the buffer, and the T descriptor, taps over to a specific column in the buffer. The X descriptor has the form: nX The T descriptor has the form: Tc The 1X descriptor is commonly used at the beginning of each FORMAT statement to ensure that the control character contains a blank. For example, the following statements: CHARACTER(len=10):: first_name = ‘James’ CHARACTER ::initial = ‘R’ CHARACTER(len=16)::last_name = ‘Johnson’ CHARACTER(len=9) :: class = ‘COSC_2301’ INTEGER :: grade = 92 WRITE (*,100) first_name, initial, last_name, grade, class 100 FORMAT (1X, A10, 1X, A1, 1X, A10, 4X, I3, T51, A9)

  11. Will produce the output James R Johnson 92 COSC 2301 ----│----│----│----│----│----│----│----│----│----│----│----│ 5 10 15 20 25 30 35 40 45 50 55 60 3.8 Changing Output Lines- The Slash (/) Descriptor The slash (/) descriptor causes the current output buffer to be sent to the printer, and a new output buffer to be started. The slash is one of the special descriptors that does not have to be separated from other descriptors by commas.

  12. 4- Formatted READ Statements A READ statement reads one or more data values from the input buffer associated with an input device. It is possible to use a formatted READ statement to specify the exact manner in which the contents of an input buffer are to be interpreted. A typical formatted READ statement is shown below: READ (*,100) increment 100 FORMAT (6X,I5) The descriptors for the READ statements are: 1- Integer Input- The I Descriptor: rIw 2- Real Input- The F Descriptor: rFw.d 3- Logical Input- The L Descriptor: rLw 4- Character Input- The A Descriptor: rA or rAw

More Related