OSU Navigation Bar

The Ohio State University

Department of Statistics

Cockins Hall
rollover image OSU Statistics
            Home

design element

OSU Statistics

Home

News

Research & Consulting Groups

People

For Visitors

For Prospective Students

For Current Students, Staff & Faculty

Contact Us



rollover image

For Current Students & Faculty

rollover image

Courses

rollover image

Links

rollover image

Computer Support

rollover image

Internal Documents

rollover image

webmail

Remember to run the command imslc before using the IMSL C libraries, and imslf before using the IMSL Fortran libraries. You must type these commands once each login session. (Note: type either imslc or imslf depending on if you are using C or Fortran, but do not type both.)

Calling IMSL Fortran libraries from Fortran 90

The Fortran libraries will only work with Fortran 90, but Fortran 77 programs should compile under Fortran 90.

Example:

mordor> cat > a.f
      program a

      implicit none

      external tdate
      integer day, month, year

      call tdate(day, month, year)

      write(6,101) day, month, year

101   format(i2,'/',i2,'/',i4)

      end

mordor> $F90 $F90FLAGS a.f $LINK_F90
mordor> a.out
18/12/1999
mordor>

Calling C from Fortran and vice-versa

UPDATE: This isn't currently working, please try to find the functions you need in the libraries native to your language, or try GSL

This can be problematic. You need to link to the libraries that each compiler needs. This can be best determined by adding the -v option to the compiler, and searching through the output to find which libraries it's linking to (with -l) and including them on the final compile line. See this page from Chiral Data for more info.

Calling IMSL Fortran libraries from C

Note the addition of underscores after the fortean subroutine names, and the extern statements for them.

mordor> cat > a.c

#include <math.h>
#include <stdio.h>

/*
 *  An example of calling IMSL Fortran subroutine RNNOA from
 *  a C function for unix.
 */


main()
{
    extern void rnnoa_();
    extern float anordf_();
    long int   nr=5;
    float       r[5], p, x;
    float       one=1.0;
    float       zero = 0.0;

    rnnoa_(&nr, r);
    printf ("%f \n", r[0]);
    x = .3;
    p = anordf_ (&x);
    printf ("%f \n", p);

}

mordor> $CC a.c $LINK_F90 -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai
-lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -lm
mordor> a.out
0.446626 
0.617911 
mordor>

Calling IMSL C libraries from Fortran 77

Note, due to underscores required with Fortran subroutines, the C IMSL libraries will only work with the f77 compiler, not f90.

Example:

fox> cat > a.f
      program t

      integer day, month, year
      external imsl_days_to_date !$PRAGMA C(imsl_days_to_date)

      call imsl_days_to_date(%VAL(32850), month, day, year)

      write(6,101) day, month, year
101   format(i2,'/',i2,'/',i4)
      end

fox> f77 a.f $LINK_CNL
fox> a.out
12/10/1989
fox>

Explanation: Since fortran expects subroutines to have an _ after them, we have to add the !$PRAGRMA line. (We can't add an _ to the IMSL function, since we don't have the source.) Also, we have to be pick about calls by value and calls by reference, thus the %VAL for the number argument.

Calling IMSL C libraries from C

Hints:

  1. always pass parameters with &varible never use constants.

  2. use $CC $CFLAGS a.c $LINK_CNL

  3. imsl functions must be in lower case

  4. in C the default return from a function is integer, so if you are calling a double function, like dnordf, you will have to prototype it before the main program by saying: double dnordf();

Example:

mordor> cat > a.c
#include <imsl.h>
main()
{
int day, month, year;

imsl_days_to_date(32850, &day, &month, &year);

printf("%d/%d/%d\n", month, day, year);
}

mordor> $CC $CFLAGS a.c $LINK_CNL
mordor> a.out
12/10/1989
mordor>

Calling IMSL C libraries from C++

Hints:

  1. always follow the prototyping from the IMSL docs

  2. use CC $CFLAGS a.cc $LINK_CNL

  3. use only the C libraries

Example:

fox> cat > a.cc
#include <iostream.h>
#include <imsl.h>

main()
{
int day, month, year;

imsl_days_to_date(35868, &day, &month, &year);
cout << day << '/' << month << '/' << year << '\n';

}

fox> $CC -DANSI -I/usr/local/lib/vni/CTT2.1/include a.cc $LINK_CNL
fox> a.out
16/03/1998
fox>

Calling IMSL Fortran Libraries from Splus

This is not supported by Mathsoft, and will not work. The IMSL C libraries should work though.

Calling IMSL C Libraries from Splus

This might work, some broad hints:

Use:
$CC -c $CFLAGS a.c to compile your program
"-R/usr/local/lib/vni/CTT2.1/lib/lib.solaris -L/usr/local/lib/vni/lib/lib.solaris -limslcmath -limslcmathsup_imsl -limslcstat -lm -lsocket -lnsl" for your userlibs in the dyn.load() function.



If you have trouble accessing this page, or need an alternate format contact webmaster@stat.osu.edu.