For Programmers: Free Programming Magazines  


Home > Archive > Fortran > February 2005 > Help on use Module and Interface in Fortran 95









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help on use Module and Interface in Fortran 95
D Marty

2005-02-21, 8:59 pm

Hello,

I don't know very well Fortran 95, I would like to have some advise on
the following problem.

I build "file.dll" in view to call it with VBA (MS Excel), and I would
like to do the folowing code:

vba:
Declare Sub TITI Lib "file.dll" (ByRef N As Long, ByRef V As Double)

Sub TOTO()
Dim V() As Double, N As Long
call SUB1(N,V(1))
end


F77:
subroutine SUB1(N,V(N))
integer N
real V()
common N,V(N)
....
end subroutine

In fortran 77 this it is impossible because the array V() must have a
fixed size in the common block.

I don't know if it is possible with Frotran 95 using Module and
Interface to do this. If somebody know, I'am very interested learn how
to do.

I use Gfortran to obtain the "file.dll"

gfortran -o file.dll -s -shared -mrtd file.f95


Thank you very much.

Dominique Marty
Richard E Maine

2005-02-22, 4:01 pm

In article <2cc28924.0502211539.39f12b62@posting.google.com>,
nath.domi@tele2.fr (D Marty) wrote:

> F77:
> subroutine SUB1(N,V(N))
> integer N
> real V()
> common N,V(N)
> ...
> end subroutine
>
> In fortran 77 this it is impossible because the array V() must have a
> fixed size in the common block.


That's not the only thing wrong here. A much more fundamental problem is
that you can't have something both be a dummy argument and in common in
the same subroutine. Those properties contradict each other, since both
the dummy argument and the common tell the compiler where the variable
can be found.... and they tell it different places.

Oh, and there are several smaller syntactic matters. You can't declare
dimensions in the subroutine statement as you are trying. And the
statement
real v()
is invalid. Those matters are simple enough to fix once it is figured
out what you are trying to do.

> I don't know if it is possible with Frotran 95 using Module and
> Interface to do this. If somebody know, I'am very interested learn how
> to do.


I'm a little as to what you are actually trying to do, because
I have the same confusion as the compiler will. If you want a dummy
argument of variable size, that's no problem even in f77. You just need
to fix the syntax (and get rid of the common). For example

subroutine sub1(n,v)
integer n
real v(n)

would do fine.

If you are trying to use something like common instead of a dummy
argument, then yes, f90 provides several ways to support dynamically
sized arrays. You could, as you alluded, use a module with an
allocatable array. Or if you needed to stick with common, you could use
a pointer array. But none of these are compatible with the array also
being a dummy argument; that incompatibility doesn't have anything to do
with arrayness, variable size or not. Code samples deferred to figure
out what the objective here is.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
epc8@juno.com

2005-02-22, 4:01 pm


Richard E Maine wrote:
> In article <2cc28924.0502211539.39f12b62@posting.google.com>,
> nath.domi@tele2.fr (D Marty) wrote:
>
a[color=darkred]
>
> That's not the only thing wrong here. A much more fundamental problem

is
> that you can't have something both be a dummy argument and in common

in
> the same subroutine. Those properties contradict each other, since

both
> the dummy argument and the common tell the compiler where the

variable
> can be found.... and they tell it different places.
>
> Oh, and there are several smaller syntactic matters. You can't

declare
> dimensions in the subroutine statement as you are trying. And the
> statement
> real v()
> is invalid. Those matters are simple enough to fix once it is figured


> out what you are trying to do.
>
how[color=darkred]
>
> I'm a little as to what you are actually trying to do,

because
> I have the same confusion as the compiler will. If you want a dummy
> argument of variable size, that's no problem even in f77. You just

need
> to fix the syntax (and get rid of the common). For example
>
> subroutine sub1(n,v)
> integer n
> real v(n)
>
> would do fine.
>

[snip]

1. In addition, there is a potential type conflict (depending on
compiler options) between the Basic Double and the F77 Real.

2. In case the OP wants to pass part of an array, for example V(3) to
V(7), it works to use 5 and V(3) as the actual arguments (g77 MinGW
2.95 and VBA/Word 97). Flame away if this is bad style, but the OP
wants to interface with VBA so portability is not a real problem.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com