Notasi E dan Format Output dalam FORTRAN
Notasi E dan Format Output dalam FORTRAN
The READ statement in FORTRAN is used for data input, taking in variables from an input list specified by a format-identifier, which can be simple like an asterisk (*) or more defined with line label identifiers. The WRITE statement, on the other hand, is used for data output, capable of more complex operations with control-list options including unit-specifier and format-specifier. Both statements use similar control structures, but WRITE extends functionalities specifically for directing data to output units like files or devices .
The format identifier in WRITE statements specifies how the data output should be formatted, including layout details like width and decimal precision. Both WRITE and PRINT use these identifiers; however, WRITE can be linked to any I/O unit, unlike PRINT, which defaults to the monitor. For instance, 'WRITE (6,30) GRAV, WEIGHT' uses a format identifier for converting data, similar to 'PRINT, GRAV, WEIGHT' but is more decentralized .
Variable output positioning in FORTRAN is achieved by using the FORMAT specifier to precisely define spaces and alignments. For instance, the FORMAT '(1X,A11,3X,A4,2X,I3)' combines output positioning by creating space before text and numbers, aligning the display over several fields. In this arrangement, 'JOHN Q.DOE' is separated by three spaces from 'CPSC', and the integer value, carefully aligned to the right by two spaces, appears aligned for presentation .
A WRITE statement in FORTRAN can print data to the system's default device (usually the monitor) by specifying the unit number as an asterisk (*). For example, "WRITE (*,*) GRAV, WEIGHT" achieves the same as using explicitly numbered device "WRITE (6,*) GRAV, WEIGHT" when 6 is the standard output device in FORTRAN systems. It simplifies the syntax while still directing the output to typical default I/O channels .
Using notations like A (for characters), X (for spaces), and / (for new line breaks) substantially enhances data readability and presentation in a FORTRAN program. 'A' ensures character ordering, 'X' facilitates structured spacing between outputs, and '/' promotes line separation for logical data grouping. This multi-notation application assists in tailoring presentations for clarity, making formatted outputs easily interpretable for end-users .
In FORTRAN, 'X' is used in formats as a positional specifier to insert spaces in a printed output. For example, if you have a variable NUMBER set to 141 and the format 'FORMAT(1X,A11,3X,A4,2X,I3)', the '3X' creates three space positions between 'JOHN Q.DOE' and 'CPSC', and '2X' adds two spaces before NUMBER. Thus, it helps in aligning or spacing items in the output .
In FORTRAN, real numbers are displayed using scientific notation with the format Ew.d, where 'E' signifies the scientific notation, 'w' is the total width of the field including the decimal point, the digits, and the exponent, 'd' is the number of digits after the decimal point. The constraints for Ew.d require that w must be greater than or equal to d + 7 to accommodate the sign, exponent, and other elements of the notation accurately .
In FORTRAN, the slash ('/') is used to create a line break or vertical alignment in the output, essentially allowing information to be displayed starting from the next line. Tthe example 'PRINT 87,'VALUE',N,A,M,B,C,D \ 87 FORMAT (1X,A ///1X,2(I10,F10.2)/1X,2E15.7)' shows that the slashes make 'VALUES' appear at the top line, with N, A, and M on a new line in a specified format, and B, C, and D on subsequent lines .
Programmers may use an asterisk '*' as a format identifier because it allows for minimal constraints and maximum flexibility in formatting, automatically adapting to any variable data type or size. This flexibility is beneficial when input/output formats are indeterminate or when quick prototyping is required, providing a default, safe formatting without explicitly defining dimensions, which can be designed later for optimization .
The format-specifier in FORTRAN is crucial for controlling the appearance of output data by defining how variables are displayed, including numeric formats with defined widths and precisions, right justification, spacing, and line breaks. The format-specifier essentially directs the display formatting of numeric, character, and real data types using defined pattern identifiers, thereby ensuring data is presented as intended by the programmer .