Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

[IMSL] QDAGI using a module?

ignacio82
Beginner
950 Views

Hi, I'm trying to use QDAGI http://www.roguewave.com/Portals/0/products/imsl-numerical-libraries/fortran-library/docs/6.0/math/default.htm?turl=qdagi.htm

I'm following the example in the webpage but I want to do it in a module.

When I try to compile it I get this error:

[bash]

$ make clean && make
rm -f modulo.X modulo1.o programa.o *.mod
ifort -openmp -I/common/vni/imsl/fnl700/rdhin111x64/include -c modulo1.f90
modulo1.f90(22): error #6632: Keyword arguments are invalid without an explicit interface. [ERRABS]
CALL QDAGI (F, BOUND, INTERV, RESULT, ERRABS=ERRABS, &
--------------------------------------------^
modulo1.f90(23): error #6632: Keyword arguments are invalid without an explicit interface. [ERREST]
ERREST=ERREST)
-----------------^
compilation aborted for modulo1.f90 (code 1)
make: *** [modulo1.o] Error 1

[/bash]

This is the module I wrote:

[fortran]

module modulo1
USE UMACH_INT
USE CONST_INT
IMPLICIT NONE
CONTAINS


SUBROUTINE INTEGRATE (VALUE, LOWER_BOUND)
INTEGER :: INTERV, NOUT
DOUBLE PRECISION :: VALUE, LOWER_BOUND
DOUBLE PRECISION :: ABS, DLOG, BOUND, ERRABS, ERREST, &
ERROR, ERRREL, EXACT, F, PI, RESULT
INTRINSIC :: ABS, DLOG
EXTERNAL :: F
! Get output unit number
CALL UMACH (2, NOUT)
! Set limits of integration
BOUND = 0.0
INTERV = 1
! Set error tolerances
ERRABS = 0.0
CALL QDAGI (F, BOUND, INTERV, RESULT, ERRABS=ERRABS, &
ERREST=ERREST)
! Print results
PI = CONST('PI')
EXACT = -PI*ALOG(10.)/20.
ERROR = ABS(RESULT-EXACT)
VALUE = RESULT
WRITE (NOUT,99999) RESULT, EXACT, ERREST, ERROR
99999 FORMAT (' Computed =', F8.3, 13X, ' Exact =', F8.3//' Error ', &
'estimate =', 1PE10.3, 6X, 'Error =', 1PE10.3)
END SUBROUTINE INTEGRATE


FUNCTION F (X)
DOUBLE PRECISION :: X
DOUBLE PRECISION :: F
DOUBLE PRECISION DLOG
INTRINSIC DLOG
F = DLOG(X)/(1.+(10.*X)**2)
END FUNCTION F
end module modulo1

[/fortran]

Any idea of what I'm doing wrong?

Thanks for the help!

0 Kudos
4 Replies
Ron_Green
Moderator
950 Views
When calling Mathematics and Statistical library routines from a Fortran program, you should use the numerical_libraries module to provide interface blocks and parameter definitions for the routines. Including the following USE statement in your calling program will verify the correct usage of the IMSL routines at compile time: USE numerical_libraries When you add the USE numerical_libraries line to your program, you should not declare the called routines as external with the EXTERNAL statement. When calling Mathematics and Statistical library routines, you do not need to declare the functions or subroutines separately. When also calling Fortran 90 MP library routines, you should instead use the imslf90 module to provide interface blocks and parameter definitions for all the Fortran 90 MP routines and the MATH and STAT library routines. Including the following USE statement in your calling program will verify the correct usage of the IMSL routines at compile time: USE IMSLF90 For more information about calling the Fortran 90 MP routines, see the IMSL Libraries online PDF file. The free-form Fortran 95/90 example program below invokes the function AMACH and the subroutine UMACH from the IMSL Libraries. The AMACH function retrieves real machine constants that define the computer's real arithmetic. A value for positive machine infinity is returned (Infinity). The subprogram UMACH retrieves the output unit number. ! This free-form example demonstrates how to call ! IMSL routines from Visual Fortran. ! ! The module numerical_libraries includes the Math and ! Stat libraries; these contain the type declarations ! and interface statements for the library routines. PROGRAM SHOWIMSL USE NUMERICAL_LIBRARIES INTEGER NOUT REAL RINFP ! The AMACH function and UMACH subroutine are ! declared in the numerical_libraries module CALL UMACH(2,NOUT) RINFP = AMACH(7) WRITE(NOUT,*) 'REAL POSITIVE MACHINE INFINITY = ',RINFP END PROGRAM
0 Kudos
ignacio82
Beginner
950 Views
Thanks for your answer. I'm having some troubles following :_( I understood that I should add "USE numerical_libraries" to my main program. [fortran] PROGRAM programa USE numerical_libraries USE modulo1 implicit none DOUBLE PRECISION :: VALUE, LOWER_BOUND LOWER_BOUND = 0.0D0 CALL INTEGRATE (VALUE, LOWER_BOUND) PRINT *, VALUE END PROGRAM programa [/fortran] I think you also said that I should not declare "F" as external in my module. This is how my module looks like now [fortran] module modulo1 USE UMACH_INT USE CONST_INT IMPLICIT NONE CONTAINS SUBROUTINE INTEGRATE (VALUE, LOWER_BOUND) INTEGER :: INTERV, NOUT DOUBLE PRECISION :: VALUE, LOWER_BOUND DOUBLE PRECISION :: ABS, DLOG, BOUND, ERRABS, ERREST, & ERROR, ERRREL, EXACT, F, PI, RESULT INTRINSIC :: ABS, DLOG ! Get output unit number CALL UMACH (2, NOUT) ! Set limits of integration BOUND = 0.0d0 INTERV = 1 ! Set error tolerances ERRABS = 0.0d0 CALL QDAGI (F, BOUND, INTERV, RESULT, ERRABS, & ERREST) ! Print results PI = CONST('PI') EXACT = -PI*DLOG(10.0d0)/20.0d0 ERROR = ABS(RESULT-EXACT) VALUE = RESULT WRITE (NOUT,99999) RESULT, EXACT, ERREST, ERROR 99999 FORMAT (' Computed =', F8.3, 13X, ' Exact =', F8.3//' Error ', & 'estimate =', 1PE10.3, 6X, 'Error =', 1PE10.3) END SUBROUTINE INTEGRATE FUNCTION F (X) DOUBLE PRECISION :: X DOUBLE PRECISION :: F DOUBLE PRECISION :: DLOG INTRINSIC :: DLOG F = DLOG(X)/(1.0d0+(10.0d0*X)**2) END FUNCTION F end module modulo1 [/fortran] Now when I run the program I get segmentation fault. Could you explain me what I'm doing wrong? [bash] $ ./program.X forrtl: severe (174): SIGSEGV, segmentation fault occurred Image PC Routine Line Source libimsl.so 00002B91327DA38C Unknown Unknown Unknown libimsl.so 00002B91327D0823 Unknown Unknown Unknown libimsl.so 00002B913280DCAE Unknown Unknown Unknown program.X 0000000000400D54 Unknown Unknown Unknown program.X 0000000000400F3C Unknown Unknown Unknown program.X 0000000000400CBC Unknown Unknown Unknown libc.so.6 000000333781D994 Unknown Unknown Unknown program.X 0000000000400BC9 Unknown Unknown Unknown [/bash] Thanks for your help and time!
0 Kudos
mecej4
Honored Contributor III
950 Views
Your source code contains numerous errors, and there are indications that you are not sufficiently familiar with default variable types, declaration scope and calling subprograms with optional arguments.
The attached compressed archive contains two source files that show how to call the IMSL quadrature routine with the integrand function defined in a module, as you required.
The program gives the output [bash] Computed =-0.36169 Exact =-0.36169 Error 3.253E-14 -0.361689220620806 [/bash]
0 Kudos
ignacio82
Beginner
950 Views
Thanks a lot!
0 Kudos
Reply