<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — QUADPACK in SF => SIGSEGV error]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=175</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=175&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in QUADPACK in SF => SIGSEGV error.]]></description>
		<lastBuildDate>Fri, 05 Apr 2013 18:30:23 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=704#p704</link>
			<description><![CDATA[<p>There isn&#039;t really a mechanism for anonymous functions ala MATLAB in Fortran.&nbsp; You&#039;d have to use public variables.&nbsp; My usual method for getting around this limitation is to use a module that contains data, set the values in this module prior to calling the integrator, then finally &quot;use&quot;-ing the module in the function to be integrated, providing access to the data.&nbsp; This method keeps the data contained strictly in the module.&nbsp; It might not be ideal, but it might help.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Fri, 05 Apr 2013 18:30:23 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=704#p704</guid>
		</item>
		<item>
			<title><![CDATA[Re: QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=703#p703</link>
			<description><![CDATA[<p>Thank you very much for your help. My experience is mainly from Matlab and Fortran is far more complicated, especially debugging.</p><p>I have one quite general problem concerning external routines, such as integration routines. For example, I want to integrate function f(x,a,b,c,...) over x. Routines like dqag want a function f(x). I have not yet found any good way to tell the function f(x) values for the parameters a,b,c,... Public variables are naturally one option, but are they really the best solution? I should calculate lots of integrals with different values of a,b,c...</p>]]></description>
			<author><![CDATA[null@example.com (akemppin)]]></author>
			<pubDate>Fri, 05 Apr 2013 13:59:49 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=703#p703</guid>
		</item>
		<item>
			<title><![CDATA[Re: QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=702#p702</link>
			<description><![CDATA[<p>It looks like your array dimensions are switched.&nbsp; You should have:</p><div class="codebox"><pre><code>lenw = 400
limit = 100
allocate(iwork(limit))
allocate(work(lenw))</code></pre></div><p>The SIGSEGV is being called because the integration routines were accessing values outside of <strong>work</strong>&#039;s bounds.&nbsp; It only survives by chance.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Fri, 05 Apr 2013 12:50:25 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=702#p702</guid>
		</item>
		<item>
			<title><![CDATA[Re: QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=701#p701</link>
			<description><![CDATA[<p>Thank you for pointing out the stupid mistake by me. Correcting it, however, did not cure the segmentation fault problem. The modified main program is below.</p><p>Sometimes the program manages to calculate the integral, and then the segmentation fault occurs AFTER I have answered the question &quot;continue program?&quot;. If I comment the &quot;call dqag&quot; and &quot;write&quot; lines, then there are no errors. I am a beginner in Fortran, and I do not understand how can it be possible that a program fails after it has executed all the lines? The interface section does not seem to make any difference.</p><p>The dqag instructions say that &quot;testfunction&quot; should be declared as &quot;external&quot;, but that does not seem to be possible, because that is a module function.</p><p>program quadpacktest<br />use testmodule<br />use constants<br />implicit none<br />!interface<br />!&nbsp; &nbsp; subroutine dqag(testfunction,a,b,epsabs,epsrel,key,y,abserr,neval,ier,limit,lenw,last,iwork,work)<br />!&nbsp; &nbsp; &nbsp; &nbsp; use constants<br />!&nbsp; &nbsp; &nbsp; &nbsp; implicit none<br />!&nbsp; &nbsp; &nbsp; &nbsp; real (dp), external :: testfunction<br />!&nbsp; &nbsp; &nbsp; &nbsp; real (dp), intent(in) :: a,b,epsabs,epsrel<br />!&nbsp; &nbsp; &nbsp; &nbsp; integer, intent(in) :: key, limit, lenw<br />!&nbsp; &nbsp; &nbsp; &nbsp; real (dp), intent(out) :: y, abserr<br />!&nbsp; &nbsp; &nbsp; &nbsp; integer, intent(out) :: neval, ier, last<br />!&nbsp; &nbsp; &nbsp; &nbsp; real (dp), intent(out), allocatable :: work(:)<br />!&nbsp; &nbsp; &nbsp; &nbsp; integer, intent(out), allocatable :: iwork(:)<br />!&nbsp; &nbsp; end subroutine dqag<br />!end interface<br />real (dp) :: x, y<br />real (dp) :: a, b, epsabs, epsrel, abserr<br />real (dp), allocatable :: work(:)<br />integer :: key, neval, ier, limit, lenw, last<br />integer, allocatable :: iwork(:)<br />character :: line<br />x=2.0_dp<br />a=0.0_dp<br />b=1.0_dp<br />epsabs=1.0e-3_dp<br />epsrel=1.0e-3_dp<br />key=2<br />limit=100<br />allocate(work(limit))<br />lenw=400<br />allocate(iwork(lenw))<br />!These two lines I sometimes comment:<br />call dqag(testfunction,a,b,epsabs,epsrel,key,y,abserr,neval,ier,limit,lenw,last,iwork,work)<br />write(*,*) y, abserr, neval, ier<br />DO<br />WRITE (*,*) &#039;Continue program (Y,y)?&#039;<br />READ (*,&#039;(A)&#039;) line<br />line = ADJUSTL(line)<br />IF (line(1:1) == &#039;Y&#039; .OR. line(1:1) == &#039;y&#039;) EXIT<br />END DO<br />end program quadpacktest</p>]]></description>
			<author><![CDATA[null@example.com (akemppin)]]></author>
			<pubDate>Fri, 05 Apr 2013 08:44:29 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=701#p701</guid>
		</item>
		<item>
			<title><![CDATA[Re: QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=699#p699</link>
			<description><![CDATA[<p>Looking at the definition of <em>dqag</em>, it looks like <strong>work</strong> should be an array rather than a scalar as you&#039;ve defined it. The invalid memory reference is probably a result of this.&nbsp; &nbsp;Additionally, <strong>iwork</strong> should be an integer array as well.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 02 Apr 2013 12:41:02 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=699#p699</guid>
		</item>
		<item>
			<title><![CDATA[QUADPACK in SF => SIGSEGV error]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=697#p697</link>
			<description><![CDATA[<p>Has anyone tried using QUADPACK integration routines in SF?</p><p>I wrote a simple test program trying to make QUADPACK work. After locating plenty of additional subroutines (for example, reference BLAS and XERROR from Netlib), my program finally compiles okay, but when I try to run it, I obtain the following error message:</p><p>Program received signal SIGSEGV: Segmentation fault - invalid memory reference.<br />Backtrace for this error:<br />#0&nbsp; ffffffff</p><p>My program and modules are below:</p><p>program quadpacktest<br />use testmodule<br />use constants<br />implicit none<br />real (dp) :: x, y<br />real (dp) :: a, b, epsabs, epsrel, abserr, ier, work<br />integer :: neval, key, limit, lenw, last, iwork<br />x=2.0_dp<br />a=0.0_dp<br />b=1.0_dp<br />epsabs=1.0e-3_dp<br />epsrel=1.0e-3_dp<br />key=2<br />limit=100<br />lenw=400<br />iwork=100<br />call dqag(testfunction,a,b,epsabs,epsrel,key,y,abserr,neval,ier,limit,lenw,last,iwork,work)<br />write(*,*) y<br />end program quadpacktest</p><p>module testmodule<br />use constants<br />implicit none<br />contains<br />pure function testfunction(x) result(y)<br />&nbsp; &nbsp; real (dp), intent(in) :: x<br />&nbsp; &nbsp; real (dp) :: y<br />&nbsp; &nbsp; y=x**1.5_dp<br />end function testfunction<br />end module testmodule</p><p>module constants<br />implicit none<br />integer, parameter, public :: dp = kind(0.d0)<br />real (dp), parameter, public :: pi = 3.1415926535897932_dp, e=1.602176462e-19_dp, kb=1.3806503e-23_dp<br />end module constants</p>]]></description>
			<author><![CDATA[null@example.com (akemppin)]]></author>
			<pubDate>Tue, 02 Apr 2013 09:09:26 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=697#p697</guid>
		</item>
	</channel>
</rss>
