Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28652 Discussions

Passing OPTIONAL args b/w VB and Fortran

jond
Novice
483 Views

Hello,

Is it possible to pass OPTIONAL arguments between VB.NET and Fortran (VB calling Fortran)? If it is, how?

Thanks forany help in advance,

Jon

0 Kudos
4 Replies
Lorri_M_Intel
Employee
483 Views

In the Fortran program, you'll have to specify which arguments are OPTIONAL.

In the VB program, you will always have to pass the correct number of arguments for the Fortran routine, but thearguments you are "optionally" passing are passed as a zero by value.

Did that make sense?

- Lorri

0 Kudos
jimdempseyatthecove
Honored Contributor III
483 Views

To rephrase Lorrie's replyfrom theC++ perspective.

The standard FORTRAN argument passing format is by way of reference. i.e. you pass in pointers to the arguments. For a missing optional argument simply pass in a NULL pointer from your C++ calling program.

If you call without pushing the optional args as NULL then the FORTRAN subroutine will use whatever is on the stack in the argument pointer's position. This makes for an interesting debugging session (especially if the missing arguments are output arguments).

Jim Dempsey

0 Kudos
jond
Novice
483 Views

Lorri,

Sorry for the late reply. I just got around trying your suggestion. Yourmethod worked but I ended up passing a value of zero (as you said) to the Fortran routine. But what if zero is a legimate value. How can I tell on the Fortran side if the passed zero value is due to a missing OPTIONAL argument or if it is a legitimate value that was actually passed?

Second, I tried the same method for optional string argument. When I pass an undefined string array form VB to Fortran as the "missing" optional argument, I end up with anargument that is populated by nonsensical characters on the Fortran side. Again, is there a way to check if thepassed string value is due to a missing OPTIONAL argument or a legitimatevalue?

I am using CVF 6.6C with VB.NET.

Thanks for your help,

Jon

0 Kudos
jimdempseyatthecove
Honored Contributor III
483 Views

When multiple calling formats are used organize the arguments such that for all calls have a non-NULL as the last argument. If you are passing a variable number of integer values all of which may be 0 then you must write the inner FORTRAN routine to produce the desired result using all 0 arguments. Generaly, FORTRAN passes the address of the argument instead of the value of the argument. An address of 0 is invalid. Consider passing the address of the arguments in place of the values of the arguments then any arbitrary number of args can be missing (nulls) and in any order.

Jim Dempsey

0 Kudos
Reply