next up previous contents
Next: Implementing Classes in FORTRAN Up: FORTRAN 90 Bindings Previous: Basic Types   Contents

Calling Methods From FORTRAN 90

All SIDL methods are implemented as FORTRAN 90 subroutines regardless of whether they have a return value or not. For object methods, the object or interface pointer is passed as the first argument to the subroutine before all the formally declared arguments. The exception is static methods, where the object or interface pointer does not appear in the argument list at all.

When a method has a return value, a variable to hold the return value should be passed as an argument following the formally declared arguments. When a method can throw an exception (i.e., its SIDL definition has a throws clause), a variable of type INTEGER (SELECTED_INT_KIND(18)) should be passed to hold a SIDL.BaseException pointer if an exception is thrown. The exception argument appears after the return value when both occur in a method. After the call, the client should test this argument. If it is non-zero, an exception was thrown by the method, and the method should respond appropriately. When an exception is thrown, the value of all other arguments is undefined.

The name of the subroutine that FORTRAN 90 clients should call is derived from the fully qualified name of the class and the name(s) of the method. If the method is specified as overloaded (i.e., has a name extension), the method's full name will be used. That is, the concatenation of the short name and the name extension will be used for a unique method name. Hence, to determine the subroutine name for FORTRAN 90, take the fully qualified name, replace all the periods with underscores, append an underscore, append the short method name, append the method name extension (if any) and then append "_m".

For example, to call the deleteRef() method on a SIDL.BaseInterface interface, you would write:

users_guide/f90/code/SIDL_BaseInterface_deleteReference_m.F90

To call the isSame method on a SIDL.BaseInterface, you would write:

users_guide/f90/code/SIDL_BaseInterface_isSame_m.F90

To call the queryInt method on a SIDL.BaseInterface, you would write:

users_guide/f90/code/SIDL_BaseInterface_queryInterface_m.F90

Examples of calls to SIDL overloaded methods are based on the overload_sample.sidl file shown in Section 3.4.4. Recall that the file describes three versions of the getValue method. The first takes no arguments, the second takes an integer argument, and the third takes a boolean. Each is called in the code snippet below:

users_guide/f90/code/overload_sample_test.F90

For interfaces and classes, there is an implicit method called _cast(). Its return type is opaque, and it has one formal argument, a string in addition to the implicit object/interface reference. The _cast() method attempts to cast the object/interface to the named type. It is similar to the queryInt method in SIDL.BaseInterface except it does not increment the reference count of the return object or interface, and it may return an object or an interface pointer. The queryInt() method always returns an interface pointer.

For non-abstract classes, there is an implicit method called _create(). It creates and returns an instance of the class.

Here are examples of the use of these two methods:

users_guide/f90/code/SIDL_BaseClass__cast_m.F90

Please note the presence of two underscores between BaseClass and create and between BaseClass and cast; the extra underscore is there because the first character of the method name is an underscore.

Here is an example call to the addSearchPath() in the SIDL.Loader class:

users_guide/f90/code/SIDL_Loader_addSearchPath_m.F90

Your FORTRAN 90 must manage any object references created by the calls you make.

Here is another example adapted from the BABEL regression tests. Package ExceptionTest has a class named Fib with a method declared in SIDL as follows:

users_guide/f90/code/ExceptionTest_Fib_getFib.sidl

Here is the outline of a FORTRAN 90 code fragment to use this method.

users_guide/f90/code/ExceptionTest_Fib_getFib.F90

Here is how you should invoke BABEL to create the FORTRAN 90 stubs for an IDL file.

% babel -client=f90 file.sidl

This will create a babel.make file, numerous C headers, numerous C source files, and some FORTRAN 90 files. The files ending in _fStub.c are the FORTRAN 90 stubs that allow FORTRAN 90 to call a SIDL method.

You will need to compile and link the files ending in _fStub.c into your application (i.e. STUBSRCS in babel.make). Normally, the IOR files (_IOR.c) are linked together with the implementation file, so you probably don't need to compile them.

If you have some enum's defined in your SIDL file, BABEL will generate FORTRAN 90 include files in the style of DEC FORTRAN (Compaq FORTRAN? (now HP Fortran???)) %INCLUDE. These files are named by taking the fully qualified name of the enum, changing the periods to underscores, and appending .inc . Here is an example of a generated include file.

users_guide/f90/code/enums_car.inc


next up previous contents
Next: Implementing Classes in FORTRAN Up: FORTRAN 90 Bindings Previous: Basic Types   Contents


babel-0.8.0
users_guide Last Modified 2003-01-14

http://www.llnl.gov/CASC/components
components@llnl.gov