comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Solving elliptic equation in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Solving elliptic equation in IDL [message #36102] Sun, 17 August 2003 16:35 Go to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Hi guys

I want to solve an elliptic equation on a rectangular portion of the
(x,y) plane, specifically

L(A) = f(x,y)

where A is an unknown, scalar-valued 2D array, L is the Laplacian
operator (d2/dx2 + d2/dy2) and the RHS (forcing) term is a function of
space only. A is specified at the boundary.

This can be done with an elliptic equation solver, of the type that
can be found in many general-purpose mathematical libraries. However a
Google search has not uncovered any IDL code to do this. So I have two
questions:

- Does anyone have or know of an IDL elliptic equation solver?

- If I choose to solve the equation in Fortran (Compaq Visual
Fortran 6.6B, IMSL Fortran Library,IDL 6.0, Windows 2000), what is the
path of least resistance for passing data between Fortran and IDL? A
DLM? Can I call a Fortran subroutine directly from IDL or will I
need to write glue code in C?

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Solving elliptic equation in IDL [message #36241 is a reply to message #36102] Thu, 28 August 2003 02:31 Go to previous messageGo to next message
dallimor is currently offline  dallimor
Messages: 3
Registered: November 2002
Junior Member
Mark, I just saw this thread and thought I'd make a comment. I did a
bit of interfacing between IDL and Fortran last year but I've just
moved and my code is in transit so I don't have any examples with me.

We did it a little differently but the principle was the same. The
comment I wanted to make was that this method removes any chance of
porting code because the "ATTRIBUTES VALUE" declaration is compiler
and OS specific. Also one other thing that we found was that to link
IDL to Compaq fortran the machine needed to have Visual C++ installed.
I never actually tracked down what libraries were required but I
couldn't get it to work without VC++ installed.

Did you build a dll or a dlm?

Chris Dallimore

Mark Hadfield <m.hadfield@niwa.co.nz> wrote in message news:<bijalf$5ba$1@newsreader.mailgate.org>...
> Mark Hadfield wrote:
>> Hi guys
>>
>> I want to solve an elliptic equation on a rectangular portion of the
>> (x,y) plane, specifically
>>
>> L(A) = f(x,y)
>>
>> where A is an unknown, scalar-valued 2D array, L is the Laplacian
>> operator (d2/dx2 + d2/dy2) and the RHS (forcing) term is a function of
>> space only. A is specified at the boundary.
>>
>> This can be done with an elliptic equation solver, of the type that
>> can be found in many general-purpose mathematical libraries. However a
>> Google search has not uncovered any IDL code to do this. So I have two
>> questions:
>>
>> - Does anyone have or know of an IDL elliptic equation solver?
>>
>> - If I choose to solve the equation in Fortran (Compaq Visual
>> Fortran 6.6B, IMSL Fortran Library,IDL 6.0, Windows 2000), what is the
>> path of least resistance for passing data between Fortran and IDL? A
>> DLM? Can I call a Fortran subroutine directly from IDL or will I
>> need to write glue code in C?
>
> Thanks for the replies. I thought I'd report progress to the group, in
> case it helps someone in future.
>
> I ended up using CALL_EXTERNAL to interface with the NCAR FISHPACK
> Fortran library. On the IDL side I wrote a wrapper routine to check
> arguments before passing them to CALL_EXTERNAL. On the Fortran side I
> wrote a glue routine to convert the "argc, argv" data passed by
> CALL_EXTERNAL to the format required by the FISHPACK routines. For the
> latter I found the following news threads useful:
>
> http://makeashorterlink.com/?G2E1525A5
> http://makeashorterlink.com/?C273235A5
>
> Below is an example of such a glue routine, written. It's similar to
> examples in the above threads, but illustrates one extra trick: using an
> "ATTRIBUTES VALUE" declaration on argc so this can be accessed in the
> Fortran code.
>
> --
> Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
> m.hadfield@niwa.co.nz
> National Institute for Water and Atmospheric Research (NIWA)
>
> --- testadd.f90 ---
>
> function testadd(argc, argv)
>
> !DEC$ ATTRIBUTES DLLEXPORT :: testadd
> !DEC$ ATTRIBUTES VALUE :: argc
>
> integer(kind=4) :: testadd
>
> integer(kind=4), intent(in) :: argc
> integer(kind=4), intent(in) :: argv(argc)
>
> if (argc.eq.4) then
> call add(%val(argv(1)),%val(argv(2)),%val(argv(3)),%val(argv(4)))
> testadd = 1
> else
> testadd = 0
> end if
>
> contains
>
> subroutine add(a, b, c, n)
>
> integer(kind=4), intent(in) :: n
> real(kind=4), intent(in) :: a(n), b(n)
> real(kind=4) :: c(n)
>
> c = a + b
>
> end subroutine add
>
> end function testadd
Re: Solving elliptic equation in IDL [message #36250 is a reply to message #36102] Wed, 27 August 2003 15:17 Go to previous messageGo to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Mark Hadfield wrote:
> Hi guys
>
> I want to solve an elliptic equation on a rectangular portion of the
> (x,y) plane, specifically
>
> L(A) = f(x,y)
>
> where A is an unknown, scalar-valued 2D array, L is the Laplacian
> operator (d2/dx2 + d2/dy2) and the RHS (forcing) term is a function of
> space only. A is specified at the boundary.
>
> This can be done with an elliptic equation solver, of the type that
> can be found in many general-purpose mathematical libraries. However a
> Google search has not uncovered any IDL code to do this. So I have two
> questions:
>
> - Does anyone have or know of an IDL elliptic equation solver?
>
> - If I choose to solve the equation in Fortran (Compaq Visual
> Fortran 6.6B, IMSL Fortran Library,IDL 6.0, Windows 2000), what is the
> path of least resistance for passing data between Fortran and IDL? A
> DLM? Can I call a Fortran subroutine directly from IDL or will I
> need to write glue code in C?

Thanks for the replies. I thought I'd report progress to the group, in
case it helps someone in future.

I ended up using CALL_EXTERNAL to interface with the NCAR FISHPACK
Fortran library. On the IDL side I wrote a wrapper routine to check
arguments before passing them to CALL_EXTERNAL. On the Fortran side I
wrote a glue routine to convert the "argc, argv" data passed by
CALL_EXTERNAL to the format required by the FISHPACK routines. For the
latter I found the following news threads useful:

http://makeashorterlink.com/?G2E1525A5
http://makeashorterlink.com/?C273235A5

Below is an example of such a glue routine, written. It's similar to
examples in the above threads, but illustrates one extra trick: using an
"ATTRIBUTES VALUE" declaration on argc so this can be accessed in the
Fortran code.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)

--- testadd.f90 ---

function testadd(argc, argv)

!DEC$ ATTRIBUTES DLLEXPORT :: testadd
!DEC$ ATTRIBUTES VALUE :: argc

integer(kind=4) :: testadd

integer(kind=4), intent(in) :: argc
integer(kind=4), intent(in) :: argv(argc)

if (argc.eq.4) then
call add(%val(argv(1)),%val(argv(2)),%val(argv(3)),%val(argv(4)))
testadd = 1
else
testadd = 0
end if

contains

subroutine add(a, b, c, n)

integer(kind=4), intent(in) :: n
real(kind=4), intent(in) :: a(n), b(n)
real(kind=4) :: c(n)

c = a + b

end subroutine add

end function testadd
Re: Solving elliptic equation in IDL [message #36317 is a reply to message #36241] Thu, 28 August 2003 13:12 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Chris Dallimore wrote:

> Mark, I just saw this thread and thought I'd make a comment. I did a
> bit of interfacing between IDL and Fortran last year but I've just
> moved and my code is in transit so I don't have any examples with me.
>
> We did it a little differently but the principle was the same. The
> comment I wanted to make was that this method removes any chance of
> porting code because the "ATTRIBUTES VALUE" declaration is compiler
> and OS specific.

Yes. So is the the %VAL function used to dereference the elements of
argv (though I believe the %VAL function is more widely supported than
the ATTRIBUTES VALUE declaration).

If you want to make any sense of the argc argument you do need some way
to tell the Fortran routine that it has been passed by value. If that's
not possible on your compiler, then you can do without. Just declare
your argv array as "argv(*)". Make sure you don't go out of bounds and
don't expect argc to have a meaningful value.

On the other hand you definitely can't do without %VAL (or equivalent).
If your compiler doesn't support that you need to write your glue
routine in C.

The good news is that Fortran 2000 will standardise all this.

> Also one other thing that we found was that to link
> IDL to Compaq fortran the machine needed to have Visual C++ installed.
> I never actually tracked down what libraries were required but I
> couldn't get it to work without VC++ installed.

Hmmm. I don't have any problems there and I have never had VC++
installed on this machine.

> Did you build a dll or a dlm?

DLL.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: working with IDLtoAVI.dlm
Next Topic: Pixmap Problems

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:57:39 PDT 2025

Total time taken to generate the page: 0.00755 seconds