/* * File: ~/numerical/test_nag.c * * Author: Chuck Gartland (6-99) * * C test program for using NAG Library on the HP-UX 10.*, * Linux, and SunOS 4.1 machines on the Kent Math/CS Network. * * Library locations: * * HP-UX: /local/opt/fortran/lib/libnag.a * Linux, Sun: /usr/local/lib/libnag.a * * Compiling alternatives: There are several different ways * to accomplish this, but I believe the easiest path * is to compile the C driver (and any other C programs) separately * and then invoke the linker/loader from Fortran * (in order to get the proper Fortran runtime libraries and load path). * * Note the different naming conventions in the source code below. * You may need to do some commenting/uncommenting to get things to work * properly on your particular platform. * * HP-UX: (the HP Fortran compiler will handle a C program properly) * ----- * 1) directing the loader to search extra directory * * % fort77 test_nag.c -L/local/opt/fortran/lib -lnag * * 2) using full path name or link to the library archive * * % f77 test_nag.c /local/opt/fortran/lib/libnag.a * * or * * % ln -s /local/opt/fortran/lib/libnag.a nag.a * % f77 test_nag.c nag.a * * See man pages for "f77/fort77", "ld", and "ln". * * Linux, Sun: * ---------- * % cc -c test_nag.c * % f77 test_nag.o -lnag * * See man pages for "cc" and "f77". * * NOTE - In calling a Fortran sub-program from C, one must * be attentive to certain language differences. * In particular, Fortran stores arrays by columns * ("column major" order); whereas C stores them by rows * ("row major" order). Also, Fortran passes all arguments * by reference (pointer). * * To see the difference, compare this program with * the companion Fortran version "test_la.f". * * See also the information available through "lrom" * (the HP CD-ROM on-line manual browser) in * * Series 700 10.* Manuals (B, C, & J Class) * HP C Programmer's Guide * Ch 5. Programming for Portability * Calling Other Languages * Calling Fortran * * Test prob: [ 1 2 3 ][x] [ 6] , w/ true sol'n [1] * [ 4 5 6 ][y] = [15] [1] * [ 7 8 0 ][z] [15] [1] * */ #include double A[4][5] = { { 1., 4., 7., 0., 0. }, /* deliberately chosen */ { 2., 5., 8., 0., 0. }, /* larger dimensions */ { 3., 6., 0., 0., 0. }, /* to illustrate the role */ { 0., 0., 0., 0., 0. } } ; /* of 'ia' */ double b[3] = { 6., 15., 15. } ; double wkspce[3] ; extern void f04arf() ; /* HP */ /* extern void f04arf_() ; */ /* Linux, Sun */ main() /* HP, Linux */ /* MAIN_() */ /* Sun */ { int ia = 5, n = 3, ifail = 0 ; /* solve Ax=b system */ f04arf( A, &ia, b, &n, b, wkspce, &ifail ) ; /* HP */ /* f04arf_( A, &ia, b, &n, b, wkspce, &ifail ) ; */ /* Linux, Sun */ printf( " ifail = %2d \n", ifail ) ; printf( " b(1) = %.15e \n", b[0] ) ; printf( " b(2) = %.15e \n", b[1] ) ; printf( " b(3) = %.15e \n", b[2] ) ; } /* * Appended sample output: * * ifail = 0 * b(1) = 9.999999999999996e-01 * b(2) = 1.000000000000000e+00 * b(3) = 1.000000000000000e+00 * */