variable # arguments in subroutine call 
Author Message
 variable # arguments in subroutine call

I was given a fortran program compiled under Lahey and need to make it
run on my clients computer which uses Digital Fortran.  I have been
successful, but only when I change subroutine calls with a varying
number of arguements to ones with a fixed number of arguments.

I was wondering if there was a compiler option I am missing that allows
multiple calls to the same subroutine each time with a different number
of arguments (always less than the total number of arguments in the
subroutine statement).

TIA

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Wed, 18 Jun 1902 08:00:00 GMT  
 variable # arguments in subroutine call

Quote:

>I was given a Fortran program compiled under Lahey and need to make it
>run on my clients computer which uses Digital Fortran.  I have been
>successful, but only when I change subroutine calls with a varying
>number of arguements to ones with a fixed number of arguments.

>I was wondering if there was a compiler option I am missing that allows
>multiple calls to the same subroutine each time with a different number
>of arguments (always less than the total number of arguments in the
>subroutine statement).

The best way to do this is to add the directive:

!DEC$ ATTRIBUTES C,REFERENCE :: routine-name

to the routine itself and in any routine that calls that routine,  If
you want a "quick and dirty" approach, use the command-line switch
/iface:cref or in Developer Studio,
Project..Settings..Fortran..External Procedures..Argument Passing
Conventions..C, By Reference

Note that what you are doing is non-standard.

--


Fortran Engineering
Compaq Computer Corporation, Nashua NH

Compaq Fortran web site: http://www.compaq.com/fortran
Compaq Fortran Message Board:
   http://forum.compaq.com:80/mb8/system/fortran_login.html



Wed, 18 Jun 1902 08:00:00 GMT  
 variable # arguments in subroutine call

Quote:

> I was given a Fortran program compiled under Lahey and need to make it
> run on my clients computer which uses Digital Fortran.  I have been
> successful, but only when I change subroutine calls with a varying
> number of arguements to ones with a fixed number of arguments.

> I was wondering if there was a compiler option I am missing that allows
> multiple calls to the same subroutine each time with a different number
> of arguments (always less than the total number of arguments in the
> subroutine statement).

Well, in f90, just declare the arguments that might be omitted to
be OPTIONAL.  (And then be sure to check whether they are present
before using them).  As in

  subroutine foo(a, b, c, d)
    real :: a, b
    real, optional :: c, d
    ...
    if (present(c)) then
       !...its ok to reference c
    endif
    ...

(Oh, and the interface to this subroutine will need to be
explicit).

Since the current compilers from both Lahey and Digital (Compaq)
are f90 (actually. I guess they are both up to f95 now, but no
difference for this purpose), this does make sense.  But if you
were using the standard f90 optional arguments, it should have
"just worked".

If you are talking about one of the f77 extensions that allowed
variable-length argument lists, then realize those were non-standard
and varied substantially from compiler to compiler (including plenty
of compilers that didn't support any such thing).

My main recommendation is to use the f90 standard form (assuming
you are using Digital's f90 compiler).  If you are stuck with
f77, then I don't know what form of omitted arguments the
Digital compiler you are using supports, though I'm pretty sure
that DIgital supported some form of such.

--
Richard Maine



Wed, 18 Jun 1902 08:00:00 GMT  
 variable # arguments in subroutine call
Thanks for the help.  I tried the "quick and dirty" by modifying my
makefiles to include the  /iface:cref option in the FFLAGS.  Now I get
an unresolved external for common intrinsic functions (RAND()).  If I
take approach (a) of  !DEC$ ATTRIBUTES C,REFERENCE :: routine-name will
I avoid this problem?



Quote:

> >I was given a Fortran program compiled under Lahey and need to make
it
> >run on my clients computer which uses Digital Fortran.  I have been
> >successful, but only when I change subroutine calls with a varying
> >number of arguements to ones with a fixed number of arguments.

> >I was wondering if there was a compiler option I am missing that
allows
> >multiple calls to the same subroutine each time with a different
number
> >of arguments (always less than the total number of arguments in the
> >subroutine statement).

> The best way to do this is to add the directive:

> !DEC$ ATTRIBUTES C,REFERENCE :: routine-name

> to the routine itself and in any routine that calls that routine,  If
> you want a "quick and dirty" approach, use the command-line switch
> /iface:cref or in Developer Studio,
> Project..Settings..Fortran..External Procedures..Argument Passing
> Conventions..C, By Reference

> Note that what you are doing is non-standard.

> --


> Fortran Engineering
> Compaq Computer Corporation, Nashua NH

> Compaq Fortran web site: http://www.compaq.com/fortran
> Compaq Fortran Message Board:
>    http://forum.compaq.com:80/mb8/system/fortran_login.html

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


Wed, 18 Jun 1902 08:00:00 GMT  
 variable # arguments in subroutine call

Quote:

>Thanks for the help.  I tried the "quick and dirty" by modifying my
>makefiles to include the  /iface:cref option in the FFLAGS.  Now I get
>an unresolved external for common intrinsic functions (RAND()).  If I
>take approach (a) of  !DEC$ ATTRIBUTES C,REFERENCE :: routine-name will
>I avoid this problem?

Yes, or upgrade to DVF 6.0A or later and you won't have to worry about
it.

--


Fortran Engineering
Compaq Computer Corporation, Nashua NH

Compaq Fortran web site: http://www.compaq.com/fortran
Compaq Fortran Message Board:
   http://forum.compaq.com:80/mb8/system/fortran_login.html



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Character variable variable passed as a subroutine argument

2. Subroutine arguments vs module variables

3. one subroutine for variable arguments

4. Variable argument list in subroutines

5. calling a subroutine with null arguments

6. Fortran77 and parenthesized arguments to subroutine calls

7. calling a subroutine with optional arguments

8. How to pas an overloaded subroutine as an argument to another subroutine

9. pass a subroutine (use derived data type) as an argument to another subroutine

10. Detecting uninitialized subroutine argument used as array bound of another argument

11. Calling subroutine with variable

12. Module.Scoping.Subroutine call not initializing variable

 

 
Powered by phpBB® Forum Software