Real field Descriptor e this field descriptor takes the form. D where e is the format code for exponential notation, w is the field width, and d is the number of characters to the right of the decimal point. For example: E13.6 reserves 13 spaces, 6 of which are to the right of the decimal point. The signs, the letter e, and the decimal point are counted as one character each (for example, the number -1.23E-02 takes up 9 spaces). Input and output operations for the e field descriptor work in the same way as the f field descriptor (Section A). However, w must exceed d by at least 5 (but better yet 7, see section B) in order to fit, from left to right: the decimal point, the letter e, an exponent sign, a 2-digit exponent, an optional sign, and a possible zero to the. Real Output Processing with e field Descriptor field Descriptor Internal Value external field a e10.2 E10.3 E12.7.
South dakota State University
1234500.00 d f10.3 F13.6 F13.6 F13.6 bb1275E-01 bb123.456E-10 bbb1234567E-7 bb1234567E-07.275E-1.123456E-07.1234567E-06.1234567E-06 More commonly used is real output formatting, where the f field descriptor transfers w characters from an internal value to an external field of w characters, rounded to d decimal positions. The following rules apply: If resume the internal value does not fill the entire external field, leading blanks are inserted in the external field. If the internal value does not fit within the external field, the field overflows and is entirely filled with asterisks ( * ). Note that the character field width w must exceed d by at least 3 in order to fit in the (optional) sign, the decimal point, and at least one digit to the left of the decimal point. Real Output Processing field Descriptor Internal Value external field.220.127.116.11.18.104.22.168 F10.4 F10.6 F10.8.632.63 -32.54 -32.54 1234.56 1234.567.67 -12.34567 -12.34567 -12.34567.6.6 -32.560 1234.567. Example: real field Descriptor c read(5,210) a, b 210. essay format(F10.3 F12,5) write(6,210) a, b 220 format(F12.3, F15.5) This example reads real variables a and B from a file connected to unit 5, according to format 210. Assuming that the values are: A 123.654,.89 The input (external field) should look like this: 123.654 bbb.89 bbbbbbb The output (external field) is then written according to format 220, and would look like this: bbbb123.654 bbbbbbb.89000 Again, notice that the first. Things to keep in mind in formatted input/output of real data using the f field descriptor: With input, always use a decimal point to ex plicitly state its location and avoid having to count columns when entering data. With output, make the field width w large enough to avoid a write overflow. If unsure of how large, use the e field descriptor instead.
The internal value is general zero if the external field contains only blank spaces or a decimal point (see section A below). If the external field includes a decimal point: (a) the location of that decimal point overrides the location specified by the d; and (b) leading and/or trailing blanks are filled with zeros and are not significant (see section B below). If the external field includes neither a decimal point nor an exponent: (a) leading and/or trailing blanks are filled with zeros; (b) the field is treated as a real value of w characters; and (c) d is meaningful, with the rightmost d digits taken. If the external field includes an exponent,. E., the letter E followed by an optional exponent sign and number, that exponent is used to establish the magnitude of the internal value (see section D below). In this case, the characters in the external field should be right-justified. The following examples illustrate real input processing (transfer from external field to internal value). Real Input Processing Section field Descriptor External field Internal Value.1.1 bbbbb 0 0.2.3 F10.3.67 b54.3bbbbb.22.214.171.124 F10.2 F10.2 123456 b1234b bbb-12345. 12345bbbb 1234.56 123.40 -12345.
D where f is the business format code for real values, w is the field width, and d is the number of characters to write the right of the decimal point. For example:.2 specifies a real format occupying up to 7 spaces, of which 2 are to the right of the decimal point. The (optional) sign and decimal point in a real number are counted as one space each. For example, -135.79 would occupy 7 spaces. In an input statement, the f field descriptor transfers w characters from an external field into an internal value. The following rules apply (see real Input Processing on the next page the internal value is positive if the first nonblank character of the external field is a plus sign, or if no sign appears. The internal value is negative if the first nonblank character of the external field is a minus sign.
B bb-200 b-357246 bbbb0 bb Example: Integer field Descriptor c read(5,110) i,j, k 110 format(I3,I5,I8) write(6,120) i,j, k 120 format(I5,I8,I10) This example reads integers i, j, and K from a file connected to unit 5, according to format 110. Assuming that the values are: I 5, j 23, k 367 The input (external field) should look like this: bb 5 bbb 23 bbbbb 367 The output (external field) is then written according to format 120, and would look like this: bbb 5 bbbbbb. This is because the first column of output is never printed, and used instead for the control of carriage return. Specific rules regarding carriage control will be introduced later in this chapter. Things to watch for in formatted input/output of integer data: With input, remember to right-justify the integer values in the external field. Gross errors may occur if you do not follow this rule. With output, make sure to specify an external field large enough to accomodate the largest number. Otherwise, an overflow will occur and the output will instead contain a set of asterisks. Real field Descriptor f this field descriptor takes the form.
San diego State University, wikipedia
E., flushed to the right. The internal value is zero if the entire external field is blank. Leading zeros or leading blank spaces in the external field are ignored. Conversely, trailing zeros or trailing blank spaces in the external field are taken as significant zeros and are made part of the internal value. Integer Input Processing field Descriptor External field Internal Value i3 I5 I4 I6 I10 bb 12345 b-35 bb-20b bbbb Formatting of output is much more common than formating of input. Upon output, the i field descriptor transfers an internal value to an external field of w characters, right-justified.
The following rules apply (see integer Output Processing If the internal value does not fill completely the external field, leading blank spaces are inserted. If the internal value does not fit within the external field because it is too large, the external field overflows ( a write overflow ) and is entirely filled with asterisks ( * ). If the internal value is negative, the external field must be large enough to accomodate the negative sign. If n is present, the external field consists of n digits (not including the sign) and is filled with leading zeros if necessary. The following examples show integer output processing, sophia from internal value to external field. Integer Output Processing field Descriptor Internal Value external field I3 I4 I5 I5 I126.96.36.199.
In output, the integer field descriptor has also the form. Optionally, it may take the form. N where n is the minimum number of characters that must appear within the field. For example:.3 In this case, assume that 27 is the number to be printed. The output is allowed 5 spaces, and a minimum of three digits must be shown.
Since 27 has two digits, an additional leading zero will be printed. Therefore, the output will appear as bb027. (Throughout this chapter, a lower case b represents a blank space). The value of n should be less than. If n is greater than w, it will cause an output error. If n is equal to w, it will cause an output error only if the number is negative. In an input statement, the i field descriptor transfers w characters from an external field into an internal value. The following rules apply (see integer Input Processing The external field must contain an integer constant, and it must not have a decimal point or exponential notation. The characters in the external field must be right- justified within the field,.
San diego State University sdsu )
Field and edit descriptors are specified with format codes, which are listed in Table.1. Regarding input, a data item is the transferred from an external field (on the screen or in an input file) to an internal value (in the computer's memory). As the programmer, you work with and see only the external field. Regarding output, a data item is transferred from an internal value to an external field (to the screen or to an output file). 6.2 field and edit descriptors a field descriptor specifies the size and form of a data item. Table.1 format codes code type function Form field field field field field field field Edit Edit Edit Transfers integer values Transfers real values Transfers real values with e exponent Transfers real values with d exponent Transfers logical values Transfers character values Transfers character constants. D Lw. NX Tn Integer field Descriptor i this field descriptor takes the form Iw where i is the format code for integer values and w is the field width, which is the number of spaces allotted. For example: I5 specifies an integer format occupying up to 5 spaces.
The null record skips one line of input and produces a blank line of output. Hence, 125 format skips one line, and 135 format skips four lines. Alternatively, the repeat slash 135 format(3 will also skip four lines. The following are examples of format statements, described in detail later in this chapter. 150 format(A20,I10,F10.3,E12.5 230 format 8X,2I5,3F12.5,5 The letters a, i, f, and e are format codes of field descriptors, and x is a format code of an edit descriptor. The comma is required as a field or edit descriptor separator. The comma is also required preceding a repeat slash, as in the last example. The comma is optional when restaurant preceding or following one or more slashes, as shown in the following versions of the previous examples: 150 format(A20,I10,F10.3,E12.5 230 format 8X,2I5,3F12.5,5.2 field and edit descriptors a field descriptor specifies the size and form of a data item. An edit descriptor affects the location of the data item in the external field.
a carriage return. The left parenthesis is the record initiator and the right parenthesis is the record terminator. The pair of parentheses causes the transfer of one record according to the format specification enclosed within them. The slash in a format specification is a record separator, which is both a record terminator and initiator. The presence of a slash causes the current record to terminate and the next record to initiate, thereby increasing the number of records transferred by one. The record is transferred according to the format specified within the respective initiator-terminator pair. For example, 105 format(I10,F10.3/E12.5) results in the transfer of two records. 115 results in the transfer of four records, the first and last being empty (null) records.
Unformatted input is easier to work with; formatted output has the advantage that it can be made to look exactly as desired. This chapter deals with formatted input/output. 6.1 format statement, a format statement is a nonexecutable statement linked to a read or write statement, which can be placed anywhere in a program unit after the program statement and before the end statement (refer to fig. It consists of a statement label and the keyword format followed by a format specification enclosed in parentheses. Both statement label and format specification are required. Within one program unit, two format statements cannot have mini the same label. A format statement has the following form: label. Format( f1, f2, f3, f4, f5, f6,., fn ) where label represents the statement label, and f1,.
Please review our policies before your appointment. The Odegaard Writing research Center. Monday - thursday 9am to 9pm, Friday 9am to 4:30pm, sunday 12pm to 9pm in Odegaard Library. The college of Sciences Student council (cssc) is a student-directed organization that promotes scientific careers to all University students, facilitates participation in community events, and strives to improve the academic experience of the students at San diego State University. Cssc is the bridge between the. Government, faculty, student organizations, and students serving as the platform of communication to advance academia in the community. Chapter 6: formatted input/output, the emphasis of Chapter 2 was on unformatted input/output. Generally, most programmers use unformatted input and formatted output, with some shredder exceptions.