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,FREEMAIL_FROM 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!postnews.google.com!x21g2000yqa.googlegroups.com!not-for-mail From: Ada novice Newsgroups: comp.lang.ada Subject: Re: Interfacing Ada with C Date: Sun, 25 Jul 2010 05:21:44 -0700 (PDT) Organization: http://groups.google.com Message-ID: <143ef70b-7e74-426b-a621-a5fd157849be@x21g2000yqa.googlegroups.com> References: <0ee9eec7-6024-4fb8-8df0-f65c146e4b84@i28g2000yqa.googlegroups.com> NNTP-Posting-Host: 193.11.22.91 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1280060505 6122 127.0.0.1 (25 Jul 2010 12:21:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 25 Jul 2010 12:21:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x21g2000yqa.googlegroups.com; posting-host=193.11.22.91; posting-account=Rr9I-QoAAACS-nOzpA-mGxtAlZ46Nb6I User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12540 Date: 2010-07-25T05:21:44-07:00 List-Id: 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: #include int main() { int n = 3; float a[] = {8.0, -1.0, -5.0, -4.0, 4.0, -2.0, 18.0, -5.0, -7.0}; f_complex *eval; /* Compute eigenvalues of A */ eval = imsl_f_eig_gen (n, a, 0); /* Print eigenvalues */ imsl_c_write_matrix ("Eigenvalues", 1, n, eval, 0); } and the output on the screen (with some pretty formatting from imsl_c_write_matrix) is: Eigenvalues 1 2 3 ( 2, 4) ( 2, -4) ( 1, 0) Here, the first eigenvalue is 2 + 4i, the second one is 2 -4i and so on. I found that f_complex (used in the line f_complex *eval) is defined as follows: typedef struct{ float re; float im; } f_complex; and f_complex is for single-precision complex values (d_complex exists for double-precision). I have never worked with structures before and after some "cursing" :), I could access the individual elements as follows: printf(" %g\n", eval[0].re) will give me the real part of the first eigenvalue i.e. 2. 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. Thanks for your very kind help. YC