Intel® Fortran Compiler 16.0 User and Reference Guide

Using IMSL Libraries in a Mixed-Language Environment (Windows* OS)

You can use the IMSL Libraries in a mixed-language development environment with Intel® Visual Fortran and C or C++ native code.

Messages that IMSL routines write to standard output or to error output in a mixed-language application or an application for Windows* can be awkward if they are written to the screen. You can avoid this by calling UMACH from a Fortran routine to remap the output and error units to a file instead of to the screen. For example, the following free-form program writes the standard output from VHSTP to the file STD.TXT, and the error message from AMACH to the file ERR.TXT:

  PROGRAM fileout
!       This program demonstrates how to use the UMACH routine to
!       redirect the standard output and error output from IMSL
!       routines to files instead of to the screen. The routines
!       are declared in the interface modules
!
  USE umach_int
  USE amach_int
  INTEGER STDU, ERRU
  REAL x, frq(10)/3.0,1.0,4.0,1.0,5.0,9.0,2.0,6.0,5.0,3.0/
!
!       Redirect IMSL standard output to STD.TXT at unit 8
!
  CALL umach(-2, STDU)
  OPEN (unit=STDU, file='std.txt')
  CALL vhstp(10,frq,1,'Histogram Plot')
  CLOSE(8)
!
!       Redirect IMSL error output to ERR.TXT at unit 9
!
  CALL umach(-3, ERRU)
  OPEN (unit=ERRU, file='err.txt')
  x = amach(0)   ! Illegal parameter error
  CLOSE(9)  END

The standard output from IMSL routine VHSTP written to STD.TXT is:

1
          Histogram Plot
 Frequency-------------------------
   9  *            I           *
   8  *            I           *
   7  *            I           *
   6  *            I   I       *
   5  *          I I   I I     *
   4  *      I   I I   I I     *
   3  *  I   I   I I   I I I   *
   2  *  I   I   I I I I I I   *
   1  *  I I I I I I I I I I   *
 ----------------------------------
 Class            5        10

The error output from IMSL routine AMACH written to ERR.TXT is:

 *** TERMINAL ERROR 5 from AMACH. The argument must be between 1 and 8
 ***          inclusive. N = 0

Consider the following simple Fortran example that uses the IMSL library:

  USE amach_int
  real rinfp
  rinfp = AMACH(7)
  write(*,*) 'Real positive machine infinity = ',rinfp
  end

The output is:

 Real positive machine infinity = Infinity

The corresponding C example is:

 /* FILE CSAMP0.C */
 #include <stdio.h>
 #include <stdlib.h>
 extern float AMACH(long *);
 main()
 {
   long n;
   float rinfp;
   n = 7;
   rinfp = AMACH(&n);
   printf("Real positive machine infinity = %16E\n", rinfp);
   fflush(stdout);
   _exit(0);
 }

This C language example demonstrates the use of:

The C example can be compiled by the icl or cl command to create an object file that can be linked using the ifort command. Note that the appropriate IMSL libraries must also be linked in. See IMSL Include File and Library Naming Conventions and Redistribution for details.