From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c1bdceb867926fdb X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!open-news-network.org!eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Interfacing Ada with C Date: Mon, 26 Jul 2010 00:21:22 +0100 Organization: A noiseless patient Spider Message-ID: References: <0ee9eec7-6024-4fb8-8df0-f65c146e4b84@i28g2000yqa.googlegroups.com> <143ef70b-7e74-426b-a621-a5fd157849be@x21g2000yqa.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 25 Jul 2010 23:21:22 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="KCXegvZb5vh43D+f3BR6Ew"; logging-data="27256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/T44JzKX785hu2mFR1p2z3F3Unmi8ysQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:ifiqkyxzO/z1KpZqLkwr5Fwyuno= sha1:EsaPTEhpBkgbTMq8HpwLacxv/jA= Xref: g2news1.google.com comp.lang.ada:12567 Date: 2010-07-26T00:21:22+01:00 List-Id: Ada novice writes: > Many thanks for all your inputs. I'll give you an example. Say we want > to compute the eigenvalues of this 3 X 3 matrix. The code in C (using > the IMSL library) is as follows: [...] > What would the best way to interface this with Ada? The elements of my > matrix will be formed in Ada, then the matrix will be passed to C to > calculate the eigenvalues and then the latter passed back to Ada. The > size of my matrix will be fixed say 3 x 3. As a novice in Ada, I would > like to learn good programming practice and the best way is to use > codes and learn from experts here in Ada. I've encoded a general complex eigenvalues function, interfacing to the LAPACK procedure zgeev, starting from a demo at http://www.physics.oregonstate.edu/~rubin/nacphy/lapack/codes/eigen-c.html & copying bits and pieces from within the GNAT implementation of Ada.Numerics.Generic_Complex_Arrays. Find it at http://public.me.com/simon.j.wright (folder numerics). NB1 LAPACK is a Fortran code, hence the need to transpose the matrix. NB2 the compilation gives warnings .. $ gnatmake test_zgeev.adb gcc -c test_zgeev.adb test_zgeev.adb:9:06: warning: "Interfaces.Fortran.BLAS" is an internal GNAT unit test_zgeev.adb:9:06: warning: use of this unit is non-portable and version-dependent test_zgeev.adb:10:06: warning: "Interfaces.Fortran.LAPACK" is an internal GNAT unit test_zgeev.adb:10:06: warning: use of this unit is non-portable and version-dependent gnatbind -x test_zgeev.ali gnatlink test_zgeev.ali $ However, (a) one could always write ones own versions, (b) the results are the same with GNAT GPL 2010 and GCC 4.5.0, (c) the output looks good (from your inputs) .. $ ./test_zgeev 2.00000000000000E+00 4.00000000000000E+00 2.00000000000000E+00 -4.00000000000000E+00 9.99999999999996E-01 2.07319734774360E-16 I get the strong impression that to know what the arguments of the BLAS & LAPACK subprograms are you have to buy the book or read the code! This all worked without any need for additional link-time arguments on Mac OS X, but YMMV on Windows. If not, I *think* that if you with Ada.Numerics.Long_Complex_Arrays (no need to use anything from it) that would be enough to bring in the necessary libraries.