1:write (*,*) "string"; Write (unit=*,fmt=*) "string"; Write (unit=6,fmt=*) "string". The above equivalent, 6 is the default output location, that is, the screen.
2:print*, "string". Print can only be output to the screen.
3:integer (kind=4) a!f90;integer*4 a!f77;integer (4) a!f77. The above equivalence.
Real (kind=4) a!f90;real*4 a!f77;real (4) a!f77. The above equivalence.
4:f77, variable name length 1~6;f90, variable name length 1~31.
5:read (*,*) "string"; Write (unit=*,fmt=*) "string"; Write (unit=5,fmt=*) "string". The above equivalent, 5 is the default input location, that is, the keyboard.
6:format
6.1 Format output The output statement consists of two parts: the output statement and the output format statement. The general form of the output statement is: WRITE (*,l) output table column or: Print L output table column where: * represents the implied output device, and L refers to the label of the output format statement. The general form of the output format statement: L format (1x,s) Where: L output format statement, 1X longitudinal paper characters, S output format, with different "format editor" ("editor") to achieve the specified output format, separated by commas between the formats. The format statement, also called a "form statement", is a non-executable statement that itself does not produce any action, but provides the input or output format. The format statement can appear anywhere in the program (but must precede the programs statement and before the end statement, if you are using the format statement in the subroutine, after the subroutine definition statement). The system finds the appropriate format statement by the statement label specified in the Write statement or print statement, and outputs the data in the format prescribed by the format statement. Note that the "*" can no longer be used in the print statement, and the first identifier in the print statement is the statement label instead of the data to be printed out.
The output format is divided into two basic formats 6.1.1 I format (also called integer format) general form: Iw or: iw.m where: w A data occupies the width of bits (also known as "field width"), m needs to output the minimum number of digits. Example 1:write (*,100) m,n100 FORMAT (1X,I4,I4) If m=40,n=-12, the output is as follows:?? 40-12 Cases 2:write (*, +) i,j,k100 FORMAT (1X,I5.3,I6.3,I4) if i=1234, j=-24, k=24689 the output is:? 1234??? -24 * * * * (1) The number is aligned to the right in the specified area, and the left side is blank if the number of digits is smaller than the specified field width W. The symbol for negative numbers is also included in the field width. (2) If the number of digits exceeds the specified field width W, the valid data is not output, and the field width is filled with the "*" symbol. (3) If the number of digits exceeds m, the output should be the number of digits actually output (but the condition cannot exceed W). M does not include a column with a minus sign.
6.1.2 F Format (also known as decimal format) general form: FW.DW The total number of digits of each value d the number of decimal places of the output data (number of digits after the point). Example 1:write (*,100) a,b,c100 FORMAT (1x,f10.2,f9.3,f8.4) if a=1234.56, b=3456.78,c=234.56789 output:??? 1234.56.3456.780 234.5679 Cases 2:write (*, +) x,y100 FORMAT (1x,f10.4,f10.2) if x=24680135.7, y=0.0012345, then the output is: **********?? ?????. 00 (1) The number is aligned to the right in the specified area, if the number of digits (with decimal and sign bits) is smaller than the specified field width W, the left side is filled with spaces, and if the number of digits exceeds the specified field width W, the valid data is not output and the field width is filled with the "*" symbol.
(2) if the scale of the data is smaller than the specified number of decimal places, 0 is rounded to the right of the decimal to make up the D-bit, and if the number of decimal places is greater than the D-bit, the number of decimal places to be output is given by the "rounding" rule.
(3) Assuming that B is the number of bits in the integer portion of the data, you should make w≥b+d+1 (a decimal point), and if the output is negative, you should ensure that the w≥b+d+2 (the decimal point and the minus sign are one column). (4) When the output in F format should be noted, because it is difficult to estimate the size of the data in advance, it is easy to produce a "wide enough" error when outputting a large number (because W is not large enough), the output of a small number will be lost when the useful numbers (because D is not large enough to take the back of the number), this is "large number of printing errors, fractional printing.
6.1.3 e format (also called exponential format) general form: W.DW The total number of digits, d the scale of the output data (the number of digits after the decimal point). Example 1:write (*,100) x,y100 FORMAT (1x,e12.4, E12.5) such as: x=3.17 y=1234.56 the output is:?? 0.3170E+01? 0.12346E+04. (1) Adopt a standardized exponential form to output a real number, D is the scale of the numeric portion of the data that appears in the form of an exponent. (2) The index portion is generally 4 columns, wherein the letter "E" and the index of the symbol of each column, index 2 column. The fractional part of column D, plus a decimal point and a "0" before the decimal point, so to ensure w≥d+6, output negative when the w≥d+7. (3) Some computer systems allow a larger real range, and FORTRAN77 provides an expanded editor that can output three-bit or four-bit exponents. This type of editor is: Ew.dee, with E specifying the number of digits of the exponent. The Fortran compilation system of some computer systems has automatically changed the number of digits of the exponent to 3-bit or 4-bit according to its allowed real range. You do not have to specify the desired exponent number for some data in the Rormat statement by using the Ew.dee editor alone, just write the Ew.d form, and the system gives the three-bit (or four-bit) exponent when the output is made.
The 6.1.4 G format G format can be output in decimal form (f format) output or exponential form (e format), depending on the real size of the output. When outputting large or small values automatically in e format, when the number of output is in the F format. The general form is: GW.D (1) where the absolute value is less than 0.1 or the absolute value is greater than 10d number in the e format output; the remaining number is output in f format. (2) When the output is in e format, the last 4 is listed as the exponent part, and the last 4 columns are left blank when the F format is output. (3) When outputting in exponential form, Format with EW.D, output in f format, not in the form of FW.D output, D is not the number of decimal places, but the number of digits printed out of the number of digits, according to the size of the value and D, the purpose is to make the integer part of the number of the whole can be preserved, and the proper truncation of the fractional part to ensure the correctness of Because a number less than 10d, its integer portion is a maximum of D bits, so you can output this D-bit integer, the number of decimal places is: D (number of integer digits).
6.1.5 D format general form: DW.A for the output of double-precision data, using the same method as the E format, just replace the letter "E" with "D".
6.1.6L format general form: LW for the output of the logical data, W output the field width of the data. Logical value ". TRUE. "To print a letter T; logical value at output." Flase. ", print a letter F on output. T and F are printed at the right-most end of the field range.
6.1.7 a format general form: Aw or: A for the output of the character data, W is the field width, does not specify W (that is, form: A), by the actual length of the character variable (that is, the program defines the length of the variable) output. The string is aligned to the right in the specified area, and if the string has a smaller number of bits than the specified field width, the left side is blank, and if the number of bits exceeds the specified field width W, only the leftmost w character is output.
The 6.1.8 ' (apostrophe) format is used to insert the desired string, for example: WRITE (*,100) i,j100 format (1X, ' i= ', I3, ' j= ', I4) if i=123,j=2347, then output: i=123j= 2347 if the character that needs to be output includes an apostrophe, the two consecutive apostrophes represent an apostrophe character that is output. For example: CHARACTER *10 studread * studwrite (*,10) STUD10 FORMAT (1x,a, ' is LI ' S STUDENT. ') End If the value entered to stud is ' Zhang Sun ', then the output is: "Zhang Sun is LI's STUDENT."
6.1.9 h format general form: NH < string > is used to output character constants similar to apostrophe formats. n is the number of characters in a string. As the above example (i=123,j=2347), can be rewritten as: WRITE (*,100) i,j100 FORMAT (1X,2HI=,I3,2HJ=,I4) The output is the same as the previous example: i=123j= 2347 you can output a string individually in apostrophe format or H format without requiring the corresponding output entry in the Write statement. such as: WRITE (*,100) (1X, ' ZHANG SUN is LI ' S STUDENT. ') Or: + FORMAT (1x,26hzhang SUN is LI's STUDENT.) The h format must accurately count the number of characters in a string, and the number of errors will cause an error. Therefore, it is best not to use the H-edit character with an apostrophe editor, which does not need a numeric character, easy to use, the string line is clear and correct. Fortran 77 The reason for preserving the H-editor is primarily to be compatible with FORTRAN 66 (FORTRAN 66 can only output a string with the H-edit character without an apostrophe editor).
6.1.10 x Format general form: NX is used to output spaces, n the number of spaces to output. That is, insert n spaces, or the "current position" of the print to move the N column to the right. Example: WRITE (*,100) i,a,b100 FORMAT (1x,i3,2x,f6.2,2x,e11.5) when i=146,a=124.32,b=1247.32, the output is: 146 124.32 0.12473e+ 04 If you do not insert a space in the X format, the data will be connected to one piece, which is difficult to distinguish. Note: Do not use 2X as a format character corresponding to a, the i,a,b in the Write statement corresponds to the i3,f6.2 and E11.5 format characters in the format statement respectively. The x format character cannot be used to provide an output format for integers, real numbers, and other types of data, and it can only insert several spaces. FORTRAN 77 also allows N to be a negative integer that represents the absolute column of n moved from the current position to the left. A FORTRAN subset used on a microcomputer cannot use a format character with negative N.
6.1.11/(slash) format slash (/) the function of the edit character is to end the output of this record and start the output of the next record. For example: WRITE (*,100) i,a,j,b100 FORMAT (1x,i3,f6.1/1x,i3,f6.1) If i=246,a=12.36,j=35,b=173.5, the output is: 246 12.435 173.5 A write statement output prints two lines of information, because there is a slash in the format statement that produces two output records (note that there is also a "1X" after the slash, so that the first character of the second record is "space", which is used as the longitudinal walk character). If there are two consecutive slashes, such as: 1x,i3,f6.1//1x,i3,f6.1 outputs the first line, an empty line, and then the second line. That is: 246 12.4 (empty line) 35 173.5 If a slash appears at the end of the edit, such as: When the second record is output by 1X,I3,F6.1/1X,I3,F6.1/, then a blank line is output. That is: 246 12.435 173.5 (empty line)
6.1.12 repetition coefficient repeated use of the editor can be added in front of a repetition coefficient, in the form of: RIW,RFW.D,REW.D,RGW.D,RAW,RLW, R is the repetition coefficient. The following two format statements are equivalent: 1x,i3,i3,f10.2,f10.2,f10.2 format (1x,2i3,3f10.2) if the following format statement is available: 1x,i4,2x, F10.2,2X,I4,2X,F10.2,2X) where the underlined two groups of editors are the same, they can be written once and reused using the repetition factor: 1x,2 (I4,2X,F10.2,2X)
6.1.13 Longitudinal paper Control if you want our output to be printed from the beginning, you should set a space at the beginning of the line. The original meaning of "1X" is to produce a space, but according to the rules, the first character of the output record is used as the longitudinal paper control, it produces the action is "Walk the paper Line". Therefore, the function of the first "1X" in the format statement is "longitudinal paper control". (1) The printed output line does not wrap, and the "current position of printing" (that is, the pointer) is stopped after the last character of the line's output. (2) As long as the first character of the output record is a space, you can make a line of paper. Therefore, it is also possible to use "1X" instead of "(i.e., spaces) to achieve the same purpose." (3) If you do not pre-prompt a space in the first word of the output record, the first character of the output will be used as the walk-through control, so that the content you want to print is missing a character. (4) If the paper control character "+" means no line break, the bank will overprint a new line of content.
The 6.1.14 write statement's interaction with the format statement outputs the contents of the record to be determined jointly with the write statement and the format statement. The Write statement provides the variable value, which provides a string, a space, and the format of the data output. The content in parentheses in the format statement is called the format description. The relationship between the two statements is described as follows: (1) The number of variables in the write statement and the number of I,f,e,g,d,l,a edit characters in the format statement can be equal or unequal. If the number of variables is less than the number of edit characters above, the extra modifiers do not work. (Note that the above edit characters do not include the X-edit, H-Edit, apostrophe-edit, same as below). When you perform format control, you scan both the variable table column of the write statement and the format description in the format statement to correspond. When the Variable table column ends, and the format statement scans to one of the above modifiers, the scan continues until a non-X, non-H, non-apostrophe editor is encountered. (2) If the number of variables is greater than the number of edit characters in the format specification, that is, the variable table column in the write statement has an element that is not output, and the format description is used up, the format description is reused, but a new record is generated. (3) If the format description contains a repeating group of editors, then when the formatting instructions are exhausted and reused, only the rightmost group of editors (including its repetition factor) and the editor to the right of it are reused. (4) If there is output, but there is no corresponding editor in the format description, the output will never stop. Therefore, if there is one or more output variables in the Write statement, there should be at least one corresponding edit in the format description that is not an X, a non-H (or an apostrophe). (5) During the scanning process, the format description of each editor (refers to i,f,e,g,a,l) must have the corresponding variables to organize the output, and X, H, apostrophe, Slash and other editors do not need to have the corresponding output variable and directly output. (6) There can be an "empty format description", such as format (), used to output a blank line. There should be no output in the write statement at this time. (7) The output of this record is terminated when the closing parenthesis of the format description (that is, the last outer bracket) or the slash "/", but does not mean that all output is stopped. As long as there is no output in the output table column, the format description or the format of the right side of the slash is used to describe the organization output. The right parenthesis has a different effect from the slash: The output ends when you scan to the right bracket and no output variable is in the output table column. The slash only represents the end of the bank output, even if the output variable is output at this time, and the output is not stopped, it restarts a new record until it encounters a closing parenthesis or a non-X, H, apostrophe editor. (8) The format statement can be adjacent to the write statement, or it can be placed anywhere in the program (after the programs statement or subroutine statement, before the end statement), it is customary to put all of the format statements in the program in the first or last place, and give the format statement a larger label (generally execute the statement e and Small label, format statement with a large label, such as more than 100 or more than 1000), to make the program clear. (9) When outputting in a table-controlled format, the output item in the Write statement can contain a string, but if the format statement is used at output, the output string cannot be included in the write statement. Format output, if you want to output a string, you should set it in the format description.
The 7:open statement (Open statement is used to connect the device number to the file name and to specify the properties of the file. The general form of it is:
"Fortran" Fortran in the use of open, Read and write