comp.lang.ada
 help / color / mirror / Atom feed
* Passing Unconstrained Arrays from FORTRAN to an Ada95 subunit
@ 2002-07-20  0:57 Karen Carron
  2002-07-20  2:34 ` tmoran
  2002-07-22  1:48 ` Robert Dewar
  0 siblings, 2 replies; 7+ messages in thread
From: Karen Carron @ 2002-07-20  0:57 UTC (permalink / 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!



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-07-22  1:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-20  0:57 Passing Unconstrained Arrays from FORTRAN to an Ada95 subunit Karen Carron
2002-07-20  2:34 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox