Fortran 90 language reference manual
All the needed files are packed in one zipped file Fort To compile your program, start a CLI session by launching the command promptprogram, usually in the Accessories group and issue these two commands:These set the environment so that your computer would know where the compilerand its libraries are located.
Note: these two commands must be issued every time you start a CLI session. Youcan optionally automate this step by adding these two variables to the system-wideenvironment using the Control Panel. You can now compile and run your program by typing:If the first command returned an error then the directory was not created ornamed correctly. If the second command was not recognized, or complained that a library is missing, then the environmentvariables were not set correctly you can issue the set command without any arguments to inspect all environment variables.
More information on using the compiler can be found in theon-line Labs at the [email protected] site. If you are already familiar with Fortran then the following points may beall you need to know about this compiler:. Fortran 90 95 Compiler free. We also know it can be confusing sometimes to see unfamiliar terms, so here is a list of straight-forward questions and their answers: Can I produce bit programs with Silverfrost Fortran?
Yes Can I produce bit programs with Silverfrost Fortran? Yes I have some old Fortran 77 code, can I compile this too? A derived type can be initialized with a structure constructor listing all the components, very similar to initializing a struct in C. Groups of equal precedence are shown by color and dividing lines; within a group, precedence is left-to-right.
Parenthesis obviously supersede order of operations. Logical operators can be be short-circuiting, as in C, but apparently are not required to be short-circuiting. See the Fortran 77 standard and Fortran bug bites.
That is, if expression A is false when evaluating A. B , then expression B might not be evaluated. Similarly, if A is true when evaluating A. B , then B might not be evaluated. Particularly it makes some conditional expressions difficult. For instance, in C it is common to check indices before using them: if i but this sometimes fails in Fortran. A nested if-then works, but that may require repeating the else clause. Alternatively, make a function to evaluate particular cases correctly, such as:.
Logical operators operate only on logical expressions, unlike C. Numeric and pointer expressions are not allowed, unlike C, Python, etc. To indicate a range, use lower : to specify lower bound of range i. For example, my schedule might be. The increment may be positive or negative; it defaults to 1.
This is not possible in C without resorting to goto gasp! Perl has similar loop labels. Fortran has 2 types of procedures: functions, which return a value and usually should not modify their arguments , and subroutines, which presumably modify their arguments or have other side effects. A subroutine is like a void function in C. It can also be declared as if it were an argument variable, but I find this counter-intuitive.
Fortran does not have this problem. The reason for all the intents is that Fortran passes everything by reference, so it would be very easy to accidentally modify some scalar variable.
Arguments may also be optional, using the optional keyword. To test whether an optional argument was passed in, use the present argument function.
They must explicitly be tested for being present or not. If not present, an alternate variable may be needed to store the default value. This seems cumbersome to me, but is useful when there is no good default value. To pass arrays into a procedure, use assumed-shape arrays, where a colon : is used in place of the unknown lengths of each dimension. Assumed-shape arrays absolutely require the procedure to be in a module, which generates an implicit interface, or to have an explicit interface.
Without an interface, it will compile but fail at runtime, since the caller doesn't know to use assumed-shape semantics. The size function queries for the total number of elements in an array. The lbound and ubound functions query for the lower and upper bounds for a particular dimension. To return an array, the return type, including its size, must be declared along with the other arguments. It cannot be put before the function keyword.
For instance:. Modules group together related procedures and variables. It can also function similarly to a C header file by listing interfaces of external library functions. Variables declared in the module are global to the entire module. Procedures and variables can be declared public or private. Another program or procedure uses the variables and procedures in a module with the use module command.
You can also limit which variables and procedures to import using the only syntax. This is fine for some purposes, but for resolving name conflicts I find it ugly.
See my wishlist regarding namespaces. Without a name, the interface Note that modules automatically create interfaces, so you need explicit interfaces only for external procedures e. In particular, you should write interfaces for any procedures defined in the same file as your main program.
Thus it behooves you to write everything inside modules. Generic or overloaded procedures are also defined using interface. Specify the generic name for the procedure, then all the interfaces for specific procedures. If a specific procedure is defined in a module, just use 'module procedure name' instead of repeating the interface. This code defines a generic function norm which can be applied to matrices, and real and complex vectors.
The procedures must be differentiated by their argument types, both by position and by name. It is more concise. You can easily overload procedures that are already overloaded. In Fortran you have to repeat the code for each data type. Strings are delimited by either ' Two consecutive commas are a null valuethe variable remains unchanged.
Slash terminates inputall remaining variables are unchanged. User-formatted input uses fixed width fields, specified in formats, which is a comma separated list of the format codes below. List directed output uses default formats to format each expression. The format, particularly field widths for different types, is compiler dependent.
User-formatted output uses fixed width fields, specified in formats, which is a comma separated list of the format codes below. All fields are right aligned. An array name, or array slice, refers to the whole array or slice. So this reads 5 reals into the first row of a matrix, then prints out the first row:. Omit the format specifier. Writes data in a binary format. Must be read back with exactly the same types of variables, on the same computer architecture!!
This list is initially copied from the Queen's University of Belfast intro, but has since been extensively modified. In the following intrinsic function definitions arguments are usually named according to their types I for integer C for character, etc.
Optional arguments are shown in square brackets [ ], and keywords for the argument names are those given. These are features I sorely miss from other languages, or features that really annoy me in Fortran. When distributing, please include the above link and copyright for this original document.
Contents Conventions Basics Variable declaration Arrays Strings Derived Types Operators Conditionals Loops Procedures Modules Interfaces prototypes Interfaces overloading generic procedures Input and Output Intrinsic Functions Wishlist Conventions Syntax highlighting styles keywords keyword operators comments strings types [optional stuff] in brackets expression to fill in in italics The name must be unique, but is otherwise unused.
Variable declaration Variables are declared with their type and a comma separated list of variable names. Arrays Arrays can have up to 7 dimensions, specified within parenthesis. For instance, real :: v 4 , A 4,6 real , dimension 50 :: x, y declares vector v of length 4, matrix A with 4 rows and 6 columns, vectors x and y of length You can also declare the lower and upper bound this is impossible in C and most other languages , like real :: x , y If the length is unknown, use : colon in its place.
For instance, print ' a,a,a ' , "Error opening file '" , trim filename , "'" Derived Types To create a data structure, use type, which is similar to C's struct.
Alternatively, make a function to evaluate particular cases correctly, such as:! So this sometimes fails:! There is also a do loop with no counter.
You must use exit or return to leave the loop. Procedures Fortran has 2 types of procedures: functions, which return a value and usually should not modify their arguments , and subroutines, which presumably modify their arguments or have other side effects.
Subroutine syntax subroutine name args Function syntax type function name args Passing array arguments To pass arrays into a procedure, use assumed-shape arrays, where a colon : is used in place of the unknown lengths of each dimension. User-formatted input read ' formats ' , variables or read label , variables label format formats User-formatted input uses fixed width fields, specified in formats, which is a comma separated list of the format codes below.
Format Description Iw Read w characters as an integer Fw. This is because formatted output is right aligned, so the leading spaces should be lopped off. Lw Read w characters as logical. Text starting with T or. T is true, text starting with F or.
F is false. Format Description Iw Print integer in w characters Fw. Uncategorized mvbits from, frompos, len, to topos copy bits. Optional argument query present x true if argument x is present. Conversion functions aimag z return the imaginary part of complex number z.
Use real x,kind instead.
0コメント