Contained WithinFind More DocumentationFeatured Support Resources | PDF로 이 문서 다운로드 (349 KB)
Appendix C Fortran 90 Features and DifferencesThis appendix shows some of the major features differences between:
FeaturesSun Fortran 90 provides the following features. Tabs in the Sourcef90 allows the tab character in fixed-form source and in free-form source. Standard Fortran 90 does not allow tabs. The tab character is not converted to a blank, so the visual placement of tabbed statements depends on the utility you use to edit or display text. Fixed-Form Source
Free-Form Sourcef90 treats a tab and a blank character as equivalent, except in literal strings. Continuation Line Limitsf90 and f77 allow 99 continuation lines (1 initial and 98 continuation lines). Standard Fortran 90 allows 19 for fixed-form and 39 for free-form. Fixed-Form Source LinesIn fixed-form source, lines can be longer than 72 characters. Columns 73 through 96 are ignored. Standard Fortran 90 allows 72-character lines. Directivesf90 allows directive lines starting with CDIR$, !DIR$, CMIC$, or !MIC$. They look like comments but are not. For full details on directives, see "Directives". Standard Fortran 90 has no directives. Tab FormThe tab form source text is defined as follows:
Example: The tab form source on the left is treated as shown on the right. !^IUses of tabs
^ICHARACTER *3 A = 'A'
^IINTEGER B = 2
^IREAL C = 3.0
^IWRITE(*,9) A, B, C
9^IFORMAT(1X, A3,
^I1 I3,
^I2 F9.1 )
^IEND
! Uses of tabs
CHARACTER *3 A = 'A'
INTEGER B = 2
REAL C = 3.0
WRITE(*,9) A, B, C
9 FORMAT(1X, A3,
1 I3,
2 F9.1 )
END
In the example above, "^I" is a way of indicating the tab character, and the line starting with "1" and "2" are continuation lines. The coding is shown to illustrate various tab situations, and not to advocate any one style. Source Form AssumedThe source form assumed by f90 depends on options, directives, and suffixes. Table C-1 F90 Source Form Command-line options
If the -free or -fixed option is used, that overrides the file name suffix. Table C-2 F90 File name suffixes
If either a FREE or FIXED directive is used, that overrides the option and file name suffix. Mixing FormsSome mixing of source forms is allowed.
CaseSun Fortran 90 is case insensitive. That means that a variable AbcDeF is treated as if it were spelled abcdef, or abcdeF, etc. "Compatibility with FORTRAN 77" Boolean Typef90 supports constants and expressions of Boolean type. There are no Boolean variables or arrays, and there is no Boolean type statement. Miscellaneous Rules Governing Boolean Type
Alternate Forms of Boolean Constantsf90 allows a Boolean constant (octal, hexadecimal, or Hollerith) in the following alternate forms (no binary). Variables cannot be declared Boolean. Standard Fortran does not allow these forms. OctalddddddB, where d is any octal digit
Within an I/O format specification, the letter B indicates binary digits; elsewhere it indicates octal digits. HexadecimalX'ddd' or X"ddd", where d is any hexadecimal digit
HollerithAccepted forms for Hollerith data are:
Above, "..." is a string of characters and n is the character count.
Examples: Octal and hexadecimal constants.
Examples: Octal and hexadecimal in assignment statements.
Use of an octal or hexadecimal constant in an arithmetic expression can produce undefined results and do not generate syntax errors. Alternate Contexts of Boolean Constantsf90 allows BOZ constants in the places other than DATA statements.
If these are assigned to a real variable, no type conversion occurs. Standard Fortran allows these only in DATA statements. Abbreviated Size Notation for Numeric Data Typesf90 allows the following nonstandard type declaration forms in declaration statements, function statements, and IMPLICIT statements. Table C-3 Size Notation for Numeric Data Types
The form in column one is nonstandard Fortran 90, though in common use. The kind numbers in column two can vary by vendor. Cray PointersA Cray pointer is a variable whose value is the address of another entity, which is called the pointee. f90 supports Cray pointers; Standard Fortran 90 does not. SyntaxThe Cray POINTER statement has the following format: POINTER ( pointer_name, pointee_name [array_spec] ), ... Where pointer_name, pointee_name, and array_spec are as follows:
Example: Declare Cray pointers to two pointees. POINTER ( p, b ), ( q, c ) The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c. Example: Declare a Cray pointer to an array. POINTER ( ix, x(n, 0:m) ) The above example declares Cray pointer ix and its pointee x; and declares x to be an array of dimensions n by m-1. Purpose of Cray PointersYou can use pointers to access user-managed storage by dynamically associating variables to particular locations in a block of storage. Cray pointers allow accessing absolute memory locations. Cray pointers do not provide convenient manipulation of linked lists because (for optimization purposes) it is assumed that no two pointers have the same value. Cray Pointers and Fortran PointersCray pointers are declared as follows: POINTER ( pointer_name, pointee_name [array_spec] ) Fortran pointers are declared as follows: POINTER object_name The two kinds of pointers cannot be mixed. Features of Cray Pointers
Restrictions on Cray Pointers
Restrictions on Cray Pointees
Usage of Cray PointersCray pointers can be assigned values as follows:
Example: Use Cray pointers as described above. SUBROUTINE sub ( n ) COMMON pool(100000) INTEGER blk(128), word64 REAL a(1000), b(n), c(100000-n-1000) POINTER ( pblk, blk ), (ia, a ), ( ib, b ), & ( ic, c ), ( address, word64 ) DATA address / 64 / pblk = 0 ia = LOC( pool ) ib = ia + 1000 ic = ib + n ... Remarks about the above example:
Optimization and Cray PointersFor purposes of optimization, f90 assumes the storage of a pointee is never overlaid on the storage of another variable--it assumes that a pointee is not associated with another variable. Such association could occur in either of two ways:
These kinds of association are sometimes done deliberately, such as for equivalencing arrays, but then results can differ depending on whether optimization is turned on or off. Example: b and c have the same pointer. POINTER ( p, b ), ( p, c ) REAL x, b, c p = LOC( x ) b = 1.0 c = 2.0 PRINT *, b ... Above, because b and c have the same pointer, assigning 2.0 to c gives the same value to b. Therefore b prints out as 2.0, even though it was assigned 1.0. Cray Character PointersIf a pointee is declared as a character type, its Cray pointer is a Cray character pointer. Purpose of Cray Character PointersA Cray character pointer is a special data type that allows f90 to maintain character strings by keeping track of the following:
An assignment to a Cray character pointer alters all three. That is, when you change what it points to, all three change. Declaration of Cray Character PointersFor a pointee that has been declared with an assumed length character type, the Cray pointer declaration statement declares the pointer to be a Cray character pointer.
You can use functions CLOC or FCD, both nonstandard intrinsics. Example: Declare Ccp to be a Cray character pointer and use CLOC to make it point to character string s. CHARACTER*(*) a POINTER ( Ccp, a ) CHARACTER*80 :: s = "abcdefgskooterwxyz" Ccp = CLOC( s ) Operations on Cray Character PointersYou can do the following operations with Cray character pointers:
where Ccp1 and Ccp2 are Cray character pointers and i is an integer. Restrictions on Cray Character Pointers and PointeesAll restrictions to Cray pointers also apply to Cray character pointers. In addition, the following apply:
Intrinsicsf90 supports some intrinsic procedures which are extensions beyond the standard. Table C-4 Nonstandard Intrinsics
DirectivesA compiler directive directs the compiler to do some special action. Directives are also called pragmas. A compiler directive is inserted into the source program as one or more lines of text. Each line looks like a comment, but has additional characters that identify it as more than a comment for this compiler. For most other compilers, it is treated as a comment, so there is some code portability. Sun-style directives are the default with f90 (and f77). To switch to Cray-style directives, use the -mp=cray compiler command-line flag. Form of General Directive LinesGeneral directives have the following syntax. !DIR$ d1, d2, ... A general directive line is defined as follows.
The form varies for fixed-form and free-form source as follows. Fixed-Form Source
Free-Form Source
Thus, !DIR$ in columns 1 through 5 works for both free-form source and fixed-form source. FIXED and FREE DirectivesThese directives specify the source form of lines following the directive line. ScopeThey apply to the rest of the file in which they appear, or until the next FREE or FIXED directive is encountered. Uses
RestrictionsThe FREE/FIXED directives:
!DIR$ FREE DO i = 1, n a(i) = b(i) * c(i) END DO Parallelization DirectivesA parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. Currently there is only one parallel directive, DOALL. The DOALL directive tells the compiler to parallelize the next loop it finds, if possible. Form of Parallelization Directive LinesParallel directives have the following syntax. !MIC$ DOALL [general parameters] [scheduling parameter] A parallelization directive line is defined as follows.
The form varies for fixed-form and free-form source as follows. Fixed
Free
Thus, !MIC$ in columns 1 through 5 works for both free and fixed. Example: Directive with continuation lines (DOALL directive and parameters.) C$PAR DOALL !MIC$& SHARED( a, b, c, n ) !MIC$& PRIVATE( i ) DO i = 1, n a(i) = b(i) * c(i) END DO Example: Same directive and parameters, with no continuation lines. C$PAR DOALL SHARED( a, b, c, n ) PRIVATE( i ) DO i = 1, n a(i) = b(i) * c(i) END DO Compatibility with FORTRAN 77SourceStandard-conforming FORTRAN 77 source code is compatible with Sun Fortran 90. Use of non-standard extensions, such as VMS Fortran features, are not compatible and may not compile with Sun Fortran 90. Both f77 and f90 treat all source lines as if they were lowercase (except in quoted character strings. However, unlike f77, f90 has no -U option to force the compiler to be sensitive to both upper and lower case. This may present a problem when mixing f77 and f90 compiled routines. Since a routine compiled by f90 will treat CALL XyZ the same as CALL XYz, and treat them both as if they were CALL xyz, care must be taken to rearrange the way these calls are made. A similar situation will exist when trying to define entry points in f90 compiled routines that are differentiated by case. The clue to potential problems would be the need to use -U with f77. Linking with f77-Compiled Routines
Example: f90 main calls a routine from the FORTRAN 77 library.
demo% cat tdtime.f90
REAL e, dtime, t(2)
e = dtime( t )
DO i = 1, 100000
as = as + cos(sqrt(float(i)))
END DO
e = dtime( t )
PRINT *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
END
demo% f90 tdtime.f90
demo% a.out
elapsed: 0.14 , user: 0.14 , sys: 0.0E+0
demo%
See dtime(3F). I/Of77 and f90 are generally I/O compatible for binary I/O, since f90 links to the f77 compatibility library. Such compatibility includes the following two situations:
The numbers read back in may or may not equal the numbers written out.
IntrinsicsThe Fortran 90 standard supports the following new intrinsic functions that FORTRAN 77 does not have. If you use one of these names in your program, you must add an EXTERNAL statement to make f90 use your function rather than the intrinsic one. Fortran 90 intrinsics: "ADJUSTL,ADJUSTR,ALL,ALLOCATED,ANY,BIT_SIZE,COUNT,CSHIFT, DIGITS,DOT_PRODUCT,EOSHIFT,EPSILON,EXPONENT,HUGE,KIND, LBOUND,LEN_TRIM,MATMUL,MAXEXPONENT,MAXLOC,MAXVAL,MERGE, MINEXPONENT,MINLOC,MINVAL,NEAREST,PACK,PRECISION,PRESENT, PRODUCT,RADIX,RANGE,REPEAT,RESHAPE,RRSPACING,SCALE,SCAN, SELECTED_INT_KIND,SELECTED_REAL_KIND,SET_EXPONENT,SHAPE, SIZE,SPACING,SPREAD,SUM,TINY,TRANSFER,TRANSPOSE,UBOUND, UNPACK,VERIFY" Forward CompatibilityFuture releases of f90 are intended to be source code compatible with this release. Module information files generated by this release of f90 are not guaranteed to be compatible with future releases. Mixing LanguagesOn Solaris systems, routines written in C can be combined with Fortran programs, since these languages have common calling conventions. Module FilesCompiling a file containing a Fortran 90 MODULE generates a module file (.mod file) for every MODULE encountered in the source. The file name is derived from the name of the MODULE; file xyz.mod (all lowercase) will be created for MODULE xyz. By default, such files are usually sought in the current working directory. The -Mdir option allows you to tell f90 to seek them in an additional location. The .mod files cannot be stored into an archive file, or concatenated into a single file. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||