![Content starts here](http://welcome.hp-ww.com/img/s.gif) |
HP Fortran for OpenVMS User Manual
9.5.4 OPTIONS Statement /CONVERT=keyword Method
You can only specify one numeric file format for all unit numbers using
this method, unless you also use the logical name or OPEN statement
CONVERT specifier method.
You specify the numeric format at compile time and must compile all
routines under the same OPTIONS statement CONVERT=keyword
qualifier. You could use one source program and compile it using
different FORTRAN commands to create multiple executable programs that
each read a certain format.
The logical name or OPEN CONVERT specifier methods take precedence over
this method. For instance, you might use the logical name or OPEN
CONVERT specifier method to specify each unit number that will use a
format other than that specified using the FORTRAN command qualifier
method. This method takes precedence over the FORTRAN command /CONVERT
qualifier method.
You can use OPTIONS statements to specify the appropriate
floating-point formats (in memory and in unformatted files) instead of
using the corresponding FORTRAN command qualifiers. For example, to use
G_float as both the memory format and as the unformatted file format,
specify the following OPTIONS statements:
OPTIONS /FLOAT=G_FLOAT
OPTIONS /CONVERT=NATIVE
|
Because this method affects all unit numbers, you cannot read data in
one format and write it in another format using the
FORTRAN/CONVERT=keyword method alone, unless you use it in
combination with the logical name method or the OPEN statement CONVERT
keyword method to specify a different format for a particular unit
number.
For More Information:
On the OPTIONS statement, see the HP Fortran for OpenVMS Language Reference Manual.
9.5.5 FORTRAN Command /CONVERT=keyword Qualifier Method
You can specify only one numeric format for all unit numbers by using
the FORTRAN command qualifier method, unless you also use the logical
name method or CONVERT specifier method. You specify the numeric format
at compile time and must compile all routines under the same
/CONVERT=keyword qualifier (or the equivalent OPTIONS
statement). If needed, you can use one source program and compile it
using different FORTRAN commands to create multiple executable programs
that each read a certain format.
The other methods take precedence over this method. For instance, you
might use the logical name or OPEN CONVERT specifier method to specify
each unit number that will use a format other than that specified using
the FORTRAN command qualifier method.
For example, the following DCL commands compile program FILE.F90 to use
VAX D_float and F_float data. Data is converted between the file format
and the little endian memory format (little endian integers, S_float
and T_float little endian IEEE floating-point format). The created
file, VAXD_CONVERT.EXE, is then run:
$ FORTRAN/FLOAT=IEEE_FLOAT /CONVERT=VAXD/OBJECT=VAXD_CONVERT.OBJ FILE.F90
$ LINK VAXD_CONVERT
$ RUN VAXD_CONVERT
|
Because this method affects all unit numbers, you cannot read or write
data in different formats if you only use the FORTRAN
/CONVERT=keyword method. To specify a different format for a
particular unit number, use the FORTRAN /CONVERT=keyword
method in combination with the logical name method or the OPEN
statement CONVERT specifier method.
9.6 Additional Information on Nonnative Data
The following notes apply to porting nonnative data:
- When porting source code along with the unformatted data, vendors
might use different units for specifying the record length (RECL
specifier, see Section 2.3.7) of unformatted files. While formatted
files are specified in units of characters (bytes), unformatted files
are specified in longword units (unless /ASSUME=BYTERECL is specified)
for Compaq Fortran 77, HP Fortran, and some other vendors. The Fortran
90 standard, in Section 9.3.4.5, states: "If the file is being
connected for unformatted input/output, the length is measured in
processor-dependent units."1
- Certain vendors apply different OPEN statement defaults to
determine the record type. The default record type (RECORDTYPE) with
HP Fortran depends on the values for the ACCESS and FORM specifiers
for the OPEN statement, as described in the HP Fortran for OpenVMS Language Reference Manual.
-
Certain vendors use a different identifier for the logical data types,
such as hex FF instead of 01 to denote "true."
- Source code being ported might be coded specifically for big
endian use.
For More Information:
- On OPEN statement specifiers, see the HP Fortran for OpenVMS Language Reference Manual.
- On HP Fortran file characteristics, see Section 6.5.
- On HP Fortran record types, see Section 6.5.3.
Note
1 American National Standard Fortran
90, ANSI X3.198-1991, and International Standards Organization standard
ISO/IEC 1539:1991
|
Chapter 10 Using HP Fortran in the Common Language Environment
This chapter describes:
- Section 10.1, Overview
- Section 10.2,HP Fortran Procedures and Argument Passing
- Section 10.3, Argument-Passing Mechanisms and Built-In Functions
- Section 10.4, Using the cDEC$ ALIAS and cDEC$ ATTRIBUTES Directives
- Section 10.5, OpenVMS Procedure-Calling Standard
- Section 10.6, OpenVMS System Routines
- Section 10.7, Calling Routines: General Considerations
- Section 10.8, Calling OpenVMS System Services
- Section 10.9, Calling Between Compaq Fortran 77 and HP Fortran
- Section 10.10, Calling Between HP Fortran and HP C
10.1 Overview
HP Fortran provides you with a variety of mechanisms for gaining
access to procedures and system services external to your
HP Fortran programs. By including CALL statements or function
references in your source program, you can use procedures such as
mathematical functions, OpenVMS system services, and routines written
in such languages as Compaq Fortran 77 and HP C.
The HP Fortran compiler operates within the OpenVMS common language
environment, which defines certain calling procedures and guidelines.
These guidelines allow you to use HP Fortran to call OpenVMS system
or library routines and routines written in different languages
(usually called mixed-language programming).
This chapter provides information on the OpenVMS procedure-calling
standard and how to access OpenVMS system services.
For More Information:
About calling and using the RMS (Record Management Services) system
services, see Chapter 11.
10.2 HP Fortran Procedures and Argument Passing
The bounds of the main program are usually defined by using PROGRAM and
END or END PROGRAM statements. Within the main program, you can define
entities related to calling a function or subroutine, including modules
and interface blocks.
A function or subroutine is considered a subprogram.
A subprogram can accept one or more data values passed from the calling
routine; the values are called arguments.
There are two types of arguments:
- Actual arguments are specified in the subprogram
call.
- Dummy arguments are variables within the function
or subroutine that receive the values (from the actual arguments).
The following methods define the interface between procedures:
- Declare and name a function with a FUNCTION statement and terminate
the function definition with an END FUNCTION statement. Set the value
of the data to be returned to the calling routine by using the function
name as a variable in an assignment statement (or by specifying RESULT
in a FUNCTION statement).
Reference a function by using its name in
an expression.
- Declare and name a subroutine with a SUBROUTINE statement and
terminate the subroutine definition with an END SUBROUTINE statement.
No value is returned by a subroutine.
Reference a subroutine by using its name in a CALL statement (or
use a defined assignment statement).
- For an external subprogram, depending on the type
of arguments or function return values, you may need to declare an
explicit interface to the arguments and function return value by using
an interface block.
Declare and name an interface block with an INTERFACE statement and
terminate the interface block definition with an END INTERFACE
statement. The interface body that appears between
these two statements consists of function or subroutine specification
statements.
- You can make data, specifications, definitions,
procedure interfaces, or procedures globally available to the
appropriate parts of your program by using a module
(use association).
Declare a module with a MODULE statement and terminate the module
definition with an END MODULE statement. Include the definitions and
other information contained within the module in appropriate parts of
your program with a USE statement. A module can contain interface
blocks, function and subroutine declarations, data declarations, and
other information.
For More Information:
On the HP Fortran language, including statement functions and
defined assignment statements not described in this manual, see the
HP Fortran for OpenVMS Language Reference Manual.
10.2.1 Explicit and Implicit Interfaces
An explicit interface occurs when the properties of
the subprogram interface are known within the scope of the function or
subroutine reference.
For example, the function reference or CALL statement occurs at a point
where the function or subroutine definition is known through host or
use association. Intrinsic procedures also have an explicit interface.
An implicit interface occurs when the properties of
the subprogram interface are not known within the scope of the function
or subroutine reference. In this case, the procedure data interface is
unknown to the compiler. For example, external routines (EXTERNAL
statement) that have not been defined in an interface block have an
implicit interface.
In most cases, you can use a procedure interface block to make an
implicit interface an explicit one. An explicit interface provides the
following advantages over an implicit interface:
- Better compile-time argument checking and fewer run-time errors
- In some cases, faster run-time performance
- Ease of locating problems in source files since the features help
to make the interface self-documenting
- Allows use of some language features that require an explicit
interface, such as array function return values.
- When passing certain types of arguments between HP Fortran and
non-Fortran languages, an explicit interface may be needed. For
example, detailed information about an assumed-shape array argument can
be obtained from the passed array descriptor. The array descriptor is
generated when an appropriate explicit interface is used for certain
types of array arguments.
For More Information:
On HP Fortran array descriptors, see Section 10.2.7.
10.2.2 Types of HP Fortran Subprograms
There are three major types of subprograms:
- A subprogram might be local to a single program unit (known only
within its host). Since the subprogram definition and all its
references are contained within the same program unit, it is called an
internal subprogram.
An internal subprogram has an explicit interface.
- A subprogram needed in multiple program units should be placed
within a module. To create a module subprogram within
a module, add a CONTAINS statement followed by the subprogram code. A
module subprogram can also contain internal subprograms.
A module
subprogram has an explicit interface in those program units that
reference the module with a USE statement (unless it is declared
PRIVATE).
- External subprograms are needed in multiple
program units but cannot be placed in a module. This makes their
procedure interface unknown in the program unit in which the reference
occurs. Examples of external subprograms include general-purpose
library routines in standard libraries and subprograms written in other
languages, like C or Ada.
Unless an external subprogram has an associated interface block, it has
an implicit interface. To provide an explicit interface for an external
subprogram, create a procedure interface block (see Section 10.2.3).
For subprograms with no explicit interface, declare the subprogram
name as external using the EXTERNAL statement within the program unit
where the external subprogram reference occurs. This allows the linker
to resolve the reference. An external subprogram must not contain
PUBLIC or PRIVATE statements.
10.2.3 Using Procedure Interface Blocks
Procedure interface blocks allow you to specify an explicit interface
for a subprogram as well as to define generic procedure names. This
section limits discussion to those interface blocks used to provide an
explicit subprogram interface. For complete information on interface
blocks, see the HP Fortran for OpenVMS Language Reference Manual.
The components of a procedure interface block follow:
- Begin a procedure interface block with an INTERFACE statement.
Unless you are defining a generic procedure name, user-defined
operator, or user-defined assignment, only the word INTERFACE is needed.
- To provide the interface body, copy the procedure specification
statements from the actual subprogram, including:
- The FUNCTION or SUBROUTINE statements.
- The interface body. For a procedure interface block, this includes
specification (declaration) statements for the dummy arguments and a
function return value (omit data assignment, FORMAT, ENTRY, DATA, and
related statements).
The interface body can include USE statements
to obtain definitions.
- The END FUNCTION or END SUBROUTINE statements.
- Terminate the interface block with an END INTERFACE statement.
- To make the procedure interface block available to multiple program
units, you can do one of the following:
- Place the procedure interface block in a module. Reference the
module with a USE statement in each program unit that references the
subprogram (use association).
- Place the procedure interface block in each program unit that
references the subprogram.
For an example of a module that contains a procedure interface block,
see Section 1.4.
10.2.4 Passing Arguments and Function Return Values
HP Fortran uses the same argument-passing conventions as
Compaq Fortran 77 on OpenVMS Alpha systems for non-pointer scalar
variables and explicit-shape and assumed-size arrays.
When calling HP Fortran subprograms, be aware that HP Fortran
expects to receive arguments the same way it passes them.
The main points about argument passing and function return values are
as follows:
- Arguments are generally passed by reference (arguments contain an
address).
An argument contains the address of the data being
passed, not the data itself (unless explicitly specified otherwise,
such as with the cDEC$ ATTRIBUTES directive or the %VAL built-in
function).
Assumed-shape arrays and deferred-shape arrays are passed by array
descriptor.
Character data is passed by character descriptor.1
Arguments omitted by adding an extra comma (,) are passed as a zero by
immediate value (see Section 10.8.4). Such arguments include OPTIONAL
arguments that are not passed. Any argument specified using the
%DESCR built-in function is also passed by descriptor (see
Section 10.3).
- Function return data is usually passed by immediate value (function
return contains a value). Certain types of data (such as array-valued
functions) are passed by other means.
The value being returned from
a function call usually contains the actual data, not
the address of the data.
- Character variables, explicit-shape character arrays, and
assumed-size character arrays
are passed by a character descriptor (except for character constant
actual arguments when /BY_REF_CALL is used).
Dummy arguments for
character data can use an assumed length.
When passing character arguments to a C routine as strings, the
character argument is not automatically null-terminated by the
compiler. To null-terminate a string from HP Fortran, use the CHAR
intrinsic function (described in the HP Fortran for OpenVMS Language Reference Manual).
The arguments passed from a calling routine must match the dummy
arguments declared in the called function or subroutine (or other
procedure), as follows:
- Arguments must be in the same order, unless argument keywords are
used.
Arguments are kept in the same position as they are specified
by the user. The exception to same position placement is the use of
argument keywords to associate dummy and actual arguments.
- Each corresponding argument or function return value must at least
match in data type, kind, and rank, as follows:
- The primary HP Fortran intrinsic data types are character,
integer, logical, real, and complex.
To convert data from one data
type to another, use the appropriate intrinsic procedures described in
the HP Fortran for OpenVMS Language Reference Manual. Also, certain attributes of a data item may
have to match. For example, if a dummy argument has the POINTER
attribute, its corresponding actual argument must also have the POINTER
attribute (see Section 10.2.6).
- You can use the kind parameter to specify the length of each numeric
intrinsic type, such as INTEGER (KIND=8). For character lengths, use
the LEN specifier, perhaps with an assumed length for dummy character
arguments (LEN=*).
- The rank (number of dimensions) of the actual
argument is usually the same (or less than) the rank of the dummy
argument, unless an assumed-size dummy array is used.
When using an explicit interface, the rank of the actual argument must
be the same as the rank of the dummy argument. For example, when
passing a scalar actual argument to a scalar dummy argument (no more
than one array element or a nonarray variable), the rank of both is 0.
Other rules which apply to passing arrays and pointers are
described in Section 10.2.5, Section 10.2.6, and in the HP Fortran for OpenVMS Language Reference Manual.
- The means by which the argument is passed and received (passing
mechanism) must match.
By default, HP Fortran arguments are
passed by reference. (See Table 10-1 for information about passing
arguments with the C property.) When calling functions or other
routines that are intended to be called from another language (such as
C), be aware that these languages may require data to be passed by
other means, such as by value. Most HP Fortran function return
values are passed by value. Certain types of data (such as array-valued
functions) are passed by other means. In most cases, you can change
the passing mechanism of actual arguments by using the following HP
extensions:
- To explicitly specify the procedure (argument or function return)
interface, provide an explicit interface.
You can use interface
blocks and modules to specify INTENT and other attributes of actual or
dummy arguments.
For More Information:
- On passing arguments, function return values, and the contents of
registers on OpenVMS systems, see the HP OpenVMS Calling Standard.
- On intrinsic data types, see Chapter 8 and the HP Fortran for OpenVMS Language Reference Manual.
- On intrinsic procedures and attributes available for array use, see
the HP Fortran for OpenVMS Language Reference Manual.
- On explicit interfaces and when they are required, see the
HP Fortran for OpenVMS Language Reference Manual.
- On an HP Fortran example program that uses an external
subprogram and a module that contains a procedure interface block, see
Example 1-3.
10.2.5 Passing Arrays as Arguments
Certain arguments or function return values require the use of an
explicit interface, including assumed-shape dummy arguments, pointer
dummy arguments, and function return values that are arrays. This is
discussed in the HP Fortran for OpenVMS Language Reference Manual.
When passing arrays as arguments, the rank and the extents (number of
elements in a dimension) should agree, so the arrays have the same
shape and are conformable. If you use an assumed-shape
array, the rank is specified and extents of the dummy array argument
are taken from the actual array argument.
If the rank and extent (shape) do not agree, the arrays are
not conformable.
The assignment of elements from the actual array to the noncomformable
(assumed-size or explicit-shape) dummy array is done by using array
element sequence association.
Certain combinations of actual and dummy array arguments are disallowed.
For More Information:
- On the types of arrays and passing array arguments, see the
HP Fortran for OpenVMS Language Reference Manual.
- On explicit interfaces and when they are required, see the
HP Fortran for OpenVMS Language Reference Manual.
- On array descriptors, see Section 10.2.7.
Note
1 For compatibility with older
Compaq Fortran 77 OpenVMS VAX programs, character constant actual
arguments (string literals) can be passed by reference if the
HP Fortran program was compiled with the /BY_REF_CALL qualifier
(see Section 2.3.9).
|
|