comp.lang.ada
 help / color / mirror / Atom feed
From: "Jerry" <lanceboyle@qwest.net>
Subject: Re: How to use Annex G.3 Vectors and Matrices in bindings to C arrays
Date: 13 Nov 2006 03:20:02 -0800
Date: 2006-11-13T03:20:02-08:00	[thread overview]
Message-ID: <1163416802.221321.170270@f16g2000cwb.googlegroups.com> (raw)
In-Reply-To: VLK5h.277654$1i1.12158@attbi_s72

Jeffrey R. Carter wrote:
> Jerry wrote:
> >
> > I wonder if I am incorrect in believing that the binding to C-arrays
> > need aliased components. Like I said, the reason for that is a little
> > fuzzy to me right now. But I do know that if I remove the aliased
> > component requirement from Long_Float_Array_1D the binding will not
> > compile.
>
> What is the error message that you get? Are you taking 'access of
> components of such arrays?
>
I'm afraid I'll have to apologize for not being accurate in my initial
post. Indeed, I am not having any problems (as I erroneously claimed)
with 1D arrays. The problem arises with 2D arrays, about which I
pestered the list earlier. With further apologies for posting a bit
more code that I would like, the following is a typical binding that I
made in which it was necessary to gain access to 2D C arrays.



procedure Mesh_3D_Base_Contour
   (x, y           : Long_Float_Array_1D; -- surface definition points
    z              : in out Long_Float_Array_2D; -- height of surface
at definition points
    Options        : Integer;
    Contour_Levels : Long_Float_Array_1D) is -- levels at which to draw
contours

    package PL_Float_Pointers_Local is new Interfaces.C.Pointers
       (Index              => Integer,
        Element            => Long_Float,
        Element_Array      => Long_Float_Array_1D,
        Default_Terminator => 0.0);
    use type PL_Float_Pointers_Local.Pointer; -- as in RM B.3.2
    type PL_Float_Pointer_Array_Local is array (Integer range <>) of
PL_Float_Pointers_Local.Pointer; -- array of pointers to Long_Floats
which represent the first element of each row of z in C-land

    Index_Of_First_Column : Integer := z'First(2);
    z_As_Pointers : PL_Float_Pointer_Array_Local (z'range(1));

    procedure
    plmeshc_local(x : PL_Float_Array; y : PL_Float_Array; z :
PL_Float_Pointer_Array_Local; nx : Integer; ny : Integer; opt :
Integer; clevel : PL_Float_Array; nlevel : PLINT);
    pragma Import(C, plmeshc_local, "c_plmeshc");

begin
    for Index in z'range(1) loop
        z_As_Pointers(Index) := z(Index, Index_Of_First_Column)'access;
    end loop;
    plmeshc_local(x, y, z_As_Pointers, x'Length, y'Length, Options,
Contour_Levels, Contour_Levels'Length); -- pass z_As_Pointers here
rather than z
end Mesh_3D_Base_Contour;



The related array definitions are:
    type Long_Float_Array_1D is array (Integer range <>) of aliased
Long_Float;
    type Long_Float_Array_2D is array (Integer range <>, Integer range
<>) of aliased Long_Float;

The "thin" binding Ada procedure plmeshc is defined:
    procedure plmeshc(x : PL_Float_Array; y : PL_Float_Array; z :
PL_Float_Array_2D; nx : PLINT; ny : PLINT; opt : PLINT;
          clevel : PL_Float_Array; nlevel : PLINT);
    pragma Import(C, plmeshc, "c_plmeshc");


And the original C procedure is defined as here:

http://plplot.sourceforge.net/docbook-manual/plplot-html-5.6.1/plmeshc.html

So it appears that I need to use access variables to mimic the 2D C
arrays, but the Annex G.3 Matrix definitions do not have aliased
elements. So, if you re-read my original post and substitute "2D" for
"1D" my original questions still stand.

Jerry




  parent reply	other threads:[~2006-11-13 11:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-12  3:45 How to use Annex G.3 Vectors and Matrices in bindings to C arrays Jerry
2006-11-12  8:45 ` Yves Bailly
2006-11-13 10:48   ` Jerry
2006-11-12 19:39 ` Jeffrey R. Carter
2006-11-13  7:09   ` tmoran
2006-11-13 11:20   ` Jerry [this message]
2006-11-13 17:42     ` Yves Bailly
2006-11-13 19:50       ` Gautier
2006-11-14  5:28         ` Jerry
2006-11-14  5:18       ` Jerry
2006-11-13 19:09     ` Jeffrey R. Carter
2006-11-14  7:31       ` Jerry
2006-11-14  7:54       ` Jerry
replies disabled

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