|
|
|
||||||
|
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 90The 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-versaUPDATE: 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 CNote 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 77Note, 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 CHints:
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:
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 SplusThis is not supported by Mathsoft, and will not work. The IMSL C libraries should work though. Calling IMSL C Libraries from SplusThis might work, some broad hints: Use: |
|
If you have trouble accessing this page, or need an alternate format contact webmaster@stat.osu.edu. |