2) to compile the code under FORTRAN 77, simply type on your unix command line from the Terminal window (you'll need to launch a terminal window if one isn't already set up: right click on the background to bring up the windows applications menu, move the mouse to 'Programs' and then click on 'Terminal'), followed by a return key.
Where command line arguments are supported they can be read in via the get_command_argument
intrinsic (introduced in the Fortran 2003 standard). The command_argument_count
intrinsic provides a way to know the number of arguments provided at the command line.
All command-line arguments are read in as strings, so an internal type conversion must be done for numeric data. As an example, this simple code sums the two numbers provided at the command line:
The number argument in get_command_argument
usefully ranges between 0
and the result of command_argument_count
. If the value is 0
then the command name is supplied (if supported).
Many compilers also offer non-standard intrinsics (such as getarg
) to access command line arguments. As these are non-standard, the corresponding compiler documentation should be consulted.
Use of get_command_argument
may be extended beyond the above example with the length
and status
arguments. For example, with
the value of stat
will be -1
if the first argument exists and has length greater than 5. If there is some other difficulty retrieving the argument the value of stat
will be some positive number (and arg
will consist entirely of blanks). Otherwise its value will be 0
.
The length
argument may be combined with a deferred length character variable, such as in the following example.
Force Fortran Compiler and Editor
'Manual ' execution with input or output files
If the program is to accept input data from an existing file or to preserve the output in a file, you must open a Command-Prompt window and execute the compiled program 'manually'.
Some DOC commands
The following commands will be helpful; each command must be typed explicitly and concluded with the ENTER key.
To change from the C-drive to the I-drive, use the command
I:
To see what files are currently available, use the
dir
command. The names of the files are in the last column of the resulting listing. Subordinate directories/folders have <DIR> in the third column.
To 'move into' a subordinate folder (or directory) [e.g., my_stuff], use the command
chdirmy_stuff
To move to the next higher folder (the 'parent' folder), use the command
chdir .
(i.e., move to the double-dot (with no space between the dots) folder which represents the 'parent' of the current folder).
Assuming that the text file named mfp.dat contains the data to be used by the executable file mfp.exe (i.e., the executable file for 'My First Program') and assuming that the output from the program should be preserved in a text file named mfp.out, use the following Command-Prompt command
mfp <mfp.dat >mfp.out
The item <mfp.dat re-directs the input from the keyboard to the existing file named mfp.dat as though its contents were manually entered on the keyboard; each line is one set of data which would be entered manually from the keyboard and concluded by the ENTER key. Omitting this input-redirection item means the executing program will expect the input data to come from the keyboard.
The item >mpf.out re-directs the output from the screen to a file named mfp.out, creating it in the process. Omitting this item means the executing program will send its output to the screen. The order of these two re-direction items is not important. Either or both re-direction items may be omitted.
Input/Output
Unit numbers may range from 1 to 99, inclusive. (Unit zero is used for outputting error messages.) If n is the value of a unit, then the program reads from or writes to a file named fort.n unless the file is explicitly opened with an OPEN statement. However, unit 5 is normally used as standard (or default) input and unit 6 is used as standard output unless an OPEN statement is used to override that association.
Normally, the executing program will create an output file in the same directory/folder as the executable file (i.e., the file with the .EXE suffix). Input files are assume to be in the same directory/folder as the executable file. The OPEN statement can be used to open files in different directories/folders where the path to the desired file must be specified explicitly.
If a program is executed and produces an output file and the program is executed a second time (with the output file now pre-existing), the program will abort and produce an error message indicating that the program cannot create the output file. Either the user must first delete the output file before executing the program or the program itself must detect the existence of the output file and delete it. The following source program creates an output file named test.out but checks to see if the file pre-exists; if it doe pre-exist, the output file is deleted and then re-created.
This program will create an output file named test.out in the same directory/folder as the executable file, probably named testfile.exe. Modifying the source program (to change the test that is output) and re-compiling and re-executing it will re-produce the output file (with different contents) without the programmer/user deleting the output file between executions.
Carriage Control
In formatted output, the first character of each line is the carriage control character (i.e., ccc) which controls the movement of the paper in the printer as indicated in the following table:
CCC | Description |
space Microsoft office zip file. | current line is printed on the next line of the output |
+ | current line is printed on the same line as the previous output; i.e., the line 'overprints' the previously output one |
0 | (zero) a blank line is produced before the current line is output; hence, double spacing |
1 | current line is output at the beginning of the next physical page |
Most printers are not capable of detecting and interpreting the ccc so they merely print it like any other character. However, you can convert the Fortran output file to an HTML file and view it in an Internet browser (like Internet Explorer or Netscape Navigator); you can then print it through that browser. The program f2html converts a standard Fortran output file to an HTML text file suitable for viewing and printing. In a Command Prompt (i.e., DOS) window, enter the command
where project.out is the Fortran output file and project.htm is the HTML equivalent. Since HTML files cannot completely control the placement of individual lines on the screen or divide the image into pages, the following accommodations are made for f2html:
this is fun!
+ fun
would be displayed as
this is fun!
Hence, the word 'fun' is bolded and the introductory blank used as the ccc is not part of the rendered result. The f2html program can accommodate Fortran output files that are approximately 80 characters 'wide'. To display files that are up to 140 characters in width, use the companion program f2htmlw (where the 'w' stands for 'wide'). This latter program is used in exactly the same matter as the f2html program. The resulting file from f2htmlw must be printed in landscape mode.
Compile a program of more than one file
If a complete source program is divided into two or more separate file:
Open all the pertinent files, using the Open tool () to retrieve each one. (Note that the down-arrow will list the files opened recently, but may not be opened now.) Note that all of the files should be in the same directory/folder.
In the Files panel, click the file that contains the main program.
Use Run > Compilation Options. In the Additional Options section and in the Options slot, enter the names of the additional files--including the suffix and separate them from each other by at least one space. Click OK.
Click the Compile tool.
If there are no syntax errors, the complete executable program will begin execution as though all of the source program parts were in in a single file. (The corresponding executable file--with .EXE suffix--can be used later in a DOS/Command Prompt window to associate external input or output files as was indicated earlier.)
Compile and NOT link a single source file
Download subtitle running man. To just compile a single source program file (which may contain a main program or just one subprogram)
Open the appropriate file so that its contents are visible in the source program panel.
Use Run > Compilation Options.
In the Additional Options section and in the Options slot, enter -c -o xxx.exe (i.e., hyphen-C, space, hyphen-O [letter casing does make a difference], space, filename, where xxx is the desired primary name of the file to be created and .EXE is the necessary suffix and click OK. (In the specified option, the -c item indicates to just compile and not also link the associated program unit; the -o item indicates the desired name of the resulting object file. This primary part of the filename must be different from the primary name of the complete executable program when it is assembled) .
Use Run > Compile. Then click OK. The component will be compiled to produce the file xxx.EXE as indicated in the previous step. However, be aware that this file is not an executable file as would be indicated by the file suffix. Strictly speaking, it is an object file would normally have an .O suffix to indicate that.
The resulting non-text/binary file (named xxx.EXE) will be created in the same directory/folder a the source program file but will not appear in the Files panel. Do not try to open the file as such an action will not render the contents for human eyes and will damage the file contents. The resulting compiled file can be linked together with other needed program pats as described in the previous section.