From: kcarron@belcan.com (Karen Carron)
Subject: Passing Unconstrained Arrays from FORTRAN to an Ada95 subunit
Date: 19 Jul 2002 17:57:09 -0700
Date: 2002-07-20T00:57:10+00:00 [thread overview]
Message-ID: <5489a352.0207191657.5fac87a8@posting.google.com> (raw)
What I have found is that the offset in referencing individual array
elements in FORTRAN is 1 (ex. the first element is referenced with a
subscript of value 1) but in Ada it is 0. This is causing a problem
since the subscripts are variables in a fortran common.
Here is an example of what I'm trying to do:
FORTRAN calling routine:
program callada
common /subs/ i1,i2,i3
integer a(10)
i1 = 1
i2 = 2
i3 = 3
a(i1) = 10
a(i2) = 20
a(i3) = 30
call adainit
call pass_array(a)
stop
end
...
Ada units:
package type_decl is
type int_array_type is array(integer range <>) of integer;
end type_decl;
...
with type_decl; use type_decl;
package routines is
procedure pass_array (a : in out int_array_type);
pragma export (fortran, pass_array, "pass_array");
end routines;
...
package common_subs is
type subs_rec is
i1, i2, i3 : integer;
end record;
subs : subs_rec;
pragma volatile (subs);
pragma import_object (subs, "subs");
end common_subs;
...
with common_subs;
package body routines is
-- pass_array can be called by more than one unit with varying
-- sizes of arrays
procedure pass_array (a : in out int_array_type) is
var1 : integer;
begin
var1 := a(common_subs.subs.i1) + a(common_subs.subs.i2);
end pass_array;
end routines;
In the fortran equivalent of pass_array, the var1 would be 30. But in
the ada version, var1 is 50. I tried the following but without any
success:
1) I modified type_decl package as follows:
-- added:
with interfaces.fortran; use interfaces.fortran;
package type_decl is
type int_array_type is array(integer range <>) of integer;
-- added:
pragma convention (fortran, int_array_type);
end type_decl;
2) I modified the original type_decl package as follows:
package type_decl is
-- I changed the range to positive from integer
type int_array_type is array(positive range <>) of integer;
end type_decl;
I would very much appreciate any other ideas.
Thanks!
next reply other threads:[~2002-07-20 0:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-20 0:57 Karen Carron [this message]
2002-07-20 2:34 ` Passing Unconstrained Arrays from FORTRAN to an Ada95 subunit tmoran
2002-07-21 13:44 ` Karen Carron
2002-07-21 18:00 ` tmoran
2002-07-21 20:32 ` Dan Nagle
2002-07-22 1:17 ` Karen Carron
2002-07-22 1:48 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox