gotoHomeFree Source CodeProgram cocoFact SheetEmail us |
Purple Sage Computing Solutions, Inc. |
|
Home --> Fact Sheet --> Free Source Code --> coco About the Program cocoGo directly to Introduction to coco Go directly to The coco setfile Go directly to Extensions to the Standard coco Go directly to An Example of Using coco The program coco provides preprocessing as per Part 3 of the Fortran Standard (coco stands for "conditional compilation"). It implements the auxiliary third part of ISO/IEC 1539-1:1997 (better known as Fortran 95). (Part 2 is the ISO_VARYING_STRINGS standard, which is sometimes implemented as a module.) A restore program, similar to that described in the standard, is also available for download. Generally, coco programs are interpreted line by line. A line is either a coco directive or a source line. The coco directives start with the characters "??" in columns 1 and 2. Lines are continued by placing an "&" as the last character of the line to be continued. Except for the "??" characters in columns 1 and 2, coco lines follow the same rules as free format lines in Fortran source code. A coco comment is any text following a "!" following the "??" characters. A coco comment may not follow the "&" at the end of a line containing a continued string. The make_processor_model program optionally creates a file of symbol definitions which may be used by coco to control the conditional compilation according to which kinds are present on a particular processor. The programmer may then write programs with code supporting all kinds available on all processors of interest, and use coco and the other software of the Portability Project to select source code suitable for each processor. The coco.inc file contains the symbol definitions written by make_processor_model and may be included in the Fortran source file via the coco include directive, or the programmer may manually copy-and-paste it into the Fortran source. This means that a programmer may base coco's preprocessing decisions automaticly on the processor dependent kinds actually supported by the processor being used. Introduction to cocoA coco program consists of coco lines and source lines. A coco program may have an optional setfile associated with it. The setfile may be used to control what coco does with coco lines or with source lines which are not intended to be effective in the output source file. The setfile may define coco variables, if so, the setfile definitions override the value contained in the program itself. The definitions must match, however, as far as type and whether the symbol is a constant (this keeps a coco program self contained and consistent). The standard coco directives are integer and logical declarations and assignments, if/elseif/else/endif directives, and message and stop directives. An integer or logical variable may be given a value where declared, and may be declared to be a constant. As extensions to the standard, a macro capability is provided, as is the ability to specify directories to be searched for include files not found in the current directory (see below). A further extension is the text & copy mechanism, which is a block of text which may be copied to several places within the source program. A text block may have dummy arguments associated with it, which may be replaced by actual arguments when the text block is copied. The standard coco directives may appear in upper or lower case interchangeably and are summarized on the list below:
The name and name=value forms of the integer and logical declarations may be mixed, a name declared to be a constant, of ocurse, must be supplied with a value. The coco setfileThe programmer may use a separate file, called a setfile, which permits the programmer to change the values of variables and constants outside the coco program, and to specify what happens to elided source text and coco directives. Within the setfile, variable and constant declarations may appear, the values supplied override those (of the same name) appearing in the coco program proper. There must be a definition of the same variable within the coco program proper, only the value may be changed by the setfile. The setfile is appended to the end of the coco program's output (depending on the value of the ALTER directive, see the following). The setfile is named according to the output file name, any ".fpp" or ".f90" suffix is discarded and ".set" is appended to make the setfile name. If a file with that name is not found, a file with the default name of "coco.set" is sought. This allows a programmer to have a default setfile for a project or directory, or to control the output on a file-by-file basis. There is only one setfile read for a multi input file invocation of coco. See Using coco for more on the command line. The fate of source lines not appearing in the coco output and of coco directives is controlled by the ALTER directive. At most one alter directive may appear in a setfile. The -a command line option overrides the alter directive. Examples of alter directives and their effects are described in the following:
Using cocoThe coco program is written in standard Fortran 95, using two extensions from Fortran 2003. These are the get_command_count() procedure to retrieve the number of command line arguments and the get_command_argument() procedure to retrieve the command line arguments themselves. You will have to find a replacement for these routines if your processor does not support them. These procedures are available from I.S.S. Ltd. via the free F2KCLI Module for a very wide variety of compilers. SYNOPSIS:coco -V coco -h coco [[options] [--]] [ basename | output input [...]] The coco program reads its input on stdin and writes its output to stdout if it finds no filename arguments on its command line. The coco program responds to "-V" option by printing its version information and quitting. The coco program responds to the "-h" option by printing a short help message and quitting. Any single filename command line argument has ".fpp" appended to it and used as the single input filename, ".f90" is appended and used as the output filename. If more than one filename argument appears on the command line the first is taken to be the output filename, the rest are treated, in the order of occurrence, as input filenames. Examples follow:
A good default setfile contains the line ?? ALIGN: DELETE, which overrides the standard specified default of SHIFT3. Options coco recognizes the following command line options:
-D rules The following rule applies to the -D option: if the "=" is present, it must be followed by an integer literal and name is defined to be an integer constant with the value specified. There should be an integer constant with the same name defined within the source file. If no "=" is present, then name is defined to be a logical constant with a value of ".true.". There should be a logical constant with the same name defined within the source file. The search rule for directories specified by the -I argument and ??directory directive is that the directories specified by the -I argument are searched first. This way, the command line may override the setfile. Directory directives may not appear in the coco program proper so all include files with the same name are known to come from the same directory, and thus each occurance of any one named include file will be the same file. Since coco doesn't know what kind of operating system is in use, the user must append the appropriate separator (i.e., "/", "\" or ":") after the directory name, whether it appears in the -I argument, or the ??directory directive (see below). Extensions to Standard cocoThis program supports some extensions to standard coco. The string ?file? is replaced in source code by the current input file name and the string ?line? is replaced by the current input file line number. This editing is prevented by the -f or -e command line options. The strings ?date? is replaced by the date of the preprocessing and the string ?time? is replaced by the time of the preprocessing. This editing is prevented by the -d or -e options. The string ?coco? is replaced by the coco version and may be prevented by the -e option. These strings are internally defined and may not be changed. They may appear in either case. If they appear in an assert condition or within a text block, the line number is that of the directive. The string ?name? is checked to see if name is the name of a coco integer or logical. If it is, it is replaced by the value of the coco integer or logical name. The name may be in either case. This editing is prevented by the -i or -e command line options. A directive has been added to allow macro definition. If a ?name? is found which is not an integer or a logical, it is checked to see if it is the name of a macro. If so, it is replaced with the value of the macro. Arguments may be present, if so, they are substituted in the value.
There is one name space for all integers, logicals, macros and text blocks. They are processed in the following order: file, line, date, time, integers and logicals, and lastly, macros. Also, to avoid ambiguity, dummy arguments (to macro or to text blocks) may not have the same name as variables, macros or text blocks. Only the following directives may appear between the text and end text directives: the assert, if, elseif, else, endif, message, stop and assignment directives. While a text block may appear in an include file, an include directive may not appear within a text block. Declaration directives may not appear because each declaration may only occur once per program. Text blocks may not be nested. If coco is being used as part of The Portability Project, the coco.inc file can be used to define coco symbols for the compiler targeted by the coco.inc file. The definitions contained in the coco.inc file match those in the standard_types module, these two files must both refer to the same processor, otherwise, suboptimal or incorrect results may occur. Other directives may appear in the setfile, and are intended to allow the programmer to access extensions to the standard coco otherwise controlled from the command line (in case the program was compiled without the f2kcli module, or other access to the command line). These directives are listed below.
An Example of Using cocoStatement of the problem to be solved: A single source file is to be prepared which will specify a Fortran 95 Module containing a cube root function to support all kinds of reals on any processor at a computer center. Using the programs of the Portability Project, specifically, the standard_types module to provide kind parameters and the coco.inc include file, this module may be written as follows: ?? include 'coco.inc' module cube_root use standard_types implicit none private public cbrt interface cbrt ?? if( single_k )then module procedure single_cbrt ?? endif ?? if( double_k )then module procedure double_cbrt ?? endif ?? if( quad_k )then module procedure quad_cbrt ?? endif end interface contains ?? if( single_k )then elemental real( kind= single_k) function single_cbrt( x) real( kind= single_k), intent( in) :: x single_cbrt = sign( exp( log( abs( x)) / 3.0_single_k), x) end function single_cbrt ?? endif ?? if( double_k )then elemental real( kind= double_k) function double_cbrt( x) real( kind= double_k), intent( in) :: x double_cbrt = sign( exp( log( abs( x)) / 3.0_double_k), x) end function double_cbrt ?? endif ?? if( quad_k )then elemental real( kind= quad_k) function quad_cbrt( x) real( kind= quad_k), intent( in) :: x quad_cbrt = sign( exp( log( abs( x)) / 3.0_quad_k), x) end function quad_cbrt ?? endif end module cube_root Note that the single_k, double_k, and quad_k which appear in the Fortran source proper are the three kind parameters which are defined in the module standard_types. The single_k, double_k and quad_k which appear in the coco if directives are coco logical variables which are defined in the coco.inc coco include file. Both coco.inc and the source code for standard_types are made (semi-)automatically by the make_processor_model program of the Portability Project All the Fortran kind parameters are valid on any processor, because if the kind isn't supported, the corresponding coco logical variable is set to false, thereby preventing the code from being present in the verison of the source for that processor. Solving the same problem, but this time using the text-copy mechanism, is shown below: ?? include 'coco.inc' module cube_root ?? text :: cbrt( kind) elemental real( kind= ?kind?_k) function ?kind?_cbrt( x) real( kind= ?kind?_k), intent( in) :: x ?kind?_cbrt = exp( log( abs( x)) / 3.0_?kind?_k) end function ?kind?_cbrt ?? end text cbrt use standard_types implicit none public cbrt interface cbrt ?? if( single_k )then module procedure single_cbrt ?? endif ?? if( double_k )then module procedure double_cbrt ?? endif ?? if( quad_k )then module procedure quad_cbrt ?? endif end interface contains ?? if( single_k )then ?? copy :: cbrt( single) ?? endif ?? if( double_k )then ?? copy :: cbrt( double) ?? endif ?? if( quad_k )then ?? copy :: cbrt( quad) ?? endif end module cube_root Note that this time, the source for the cbrt() function need be specified only once, the text-copy mechanism performs the copy-paste-substitute operation on demand. A further simplification is to replace the if ... copy ... endif sequences with copyif directives, as shown below: ?? include 'coco.inc' module cube_root ?? text :: cbrt( kind) elemental real( kind= ?kind?_k) function ?kind?_cbrt( x) real( kind= ?kind?_k), intent( in) :: x ?kind?_cbrt = exp( log( abs( x)) / 3.0_?kind?_k) end function ?kind?_cbrt ?? end text cbrt use standard_types implicit none public cbrt interface cbrt ?? if( single_k )then module procedure single_cbrt ?? endif ?? if( double_k )then module procedure double_cbrt ?? endif ?? if( quad_k )then module procedure quad_cbrt ?? endif end interface contains ?? copyif( single_k) cbrt( single) ?? copyif( double_k) cbrt( double) ?? copyif( quad_k) cbrt( quad) end module cube_root DownloadsTo download a source code for the coco program, click coco preprocessor. You will need the free F2KCLI Module from I.S.S. to compile coco program if your compiler doesn"t support the Fortran 2003 command line access intrinsic procedures. Download the restore program which can un-do coco processing under certain circumstances. Coco no longer needs a standard_types module. For more information about the standard_types module, click here. Please see our Fact Sheet, or E-mail us for more information. |
|
| Home - Fact Sheet - Free Source Code - Fortran Links - Email us |