Prev: string stuff
Next: distance between points on the earth
From: Geico Caveman on 12 Oct 2009 10:27 Returning to fortran usage after about 4 years, so my skills are a little rusty. Is the following construct legal: module mex implicit none integer, parameter :: mptr=selected_int_kind(9) interface integer(kind=mptr) function mexGetPr(pm) integer(kind=mptr) :: pm end function mexGetPr ... end interface end module mex ? For those of you who recognize this, this is a code fragment used to allow Matlab to access compiled fortran code (Johansson and Roberts). They used an explicit kind value (mptr=8), which just seems fundamentally unportable to me, so I decided to fix that. Neither the original code, nor my modification, compiles. I am using gfortran on MacOSX. The compiler complains that mptr is either undefined or a variable. As you can see, neither of those two are true. Am I missing something basic here ?
From: Geico Caveman on 12 Oct 2009 10:32 On 2009-10-12 07:27:31 -0700, Geico Caveman <spammers-go-here(a)spam.invalid> said: > Returning to fortran usage after about 4 years, so my skills are a > little rusty. > > Is the following construct legal: > > module mex > implicit none > > integer, parameter :: mptr=selected_int_kind(9) > > interface > > integer(kind=mptr) function mexGetPr(pm) > integer(kind=mptr) :: pm > end function mexGetPr > > ... > > end interface > > end module mex > > ? > > For those of you who recognize this, this is a code fragment used to > allow Matlab to access compiled fortran code (Johansson and Roberts). > > They used an explicit kind value (mptr=8), which just seems > fundamentally unportable to me, so I decided to fix that. > > Neither the original code, nor my modification, compiles. I am using > gfortran on MacOSX. The compiler complains that mptr is either > undefined or a variable. > > As you can see, neither of those two are true. Am I missing something > basic here ? Tried this with Intel Fortran Professional (ifort). Now, I get an error stating that a kind type parameter must be a compile-type constant. I think that declaring it as a parameter should make it so, but then I could be wrong. So, this is not a compiler dependent error (or at least not these two compilers). I trusted the free Intel fortran compiler on linux, so I am sure this is my mistake. What is it ?
From: m_b_metcalf on 12 Oct 2009 10:42 On Oct 12, 4:32 pm, Geico Caveman <spammers-go-h...(a)spam.invalid> wrote: > On 2009-10-12 07:27:31 -0700, Geico Caveman > <spammers-go-h...(a)spam.invalid> said: > > > > > > > Returning to fortran usage after about 4 years, so my skills are a > > little rusty. > > > Is the following construct legal: > > > module mex > > implicit none > > > integer, parameter :: mptr=selected_int_kind(9) > > > interface > > > integer(kind=mptr) function mexGetPr(pm) > > integer(kind=mptr) :: pm > > end function mexGetPr > > > ... > > > end interface > > > end module mex > > > ? > > > For those of you who recognize this, this is a code fragment used to > > allow Matlab to access compiled fortran code (Johansson and Roberts). > > > They used an explicit kind value (mptr=8), which just seems > > fundamentally unportable to me, so I decided to fix that. > > > Neither the original code, nor my modification, compiles. I am using > > gfortran on MacOSX. The compiler complains that mptr is either > > undefined or a variable. > > > As you can see, neither of those two are true. Am I missing something > > basic here ? > > Tried this with Intel Fortran Professional (ifort). Now, I get an error > stating that a kind type parameter must be a compile-type constant. I > think that declaring it as a parameter should make it so, but then I > could be wrong. > > So, this is not a compiler dependent error (or at least not these two > compilers). I trusted the free Intel fortran compiler on linux, so I > am sure this is my mistake. > > What is it ?- Hide quoted text - > > - Show quoted text - Your problem is that the interface forms its own scoping unit banging a hole in the scoping unit formed by the module. Thus, it doesn't have access to anything specified in the module. You need to separate the two parts of the module into separate modules, as in : module mex implicit none integer, parameter :: mptr=selected_int_kind(9) end module mex module two interface integer(kind=mptr) function mexGetPr(pm) use mex integer(kind=mptr) :: pm end function mexGetPr end interface end module two See also the recent thread "public declaration isn't visible inside an interface?". HTH Mike Metcalf
From: Ron Shepard on 12 Oct 2009 11:53 In article <2009101207322575249-spammersgohere(a)spaminvalid>, Geico Caveman <spammers-go-here(a)spam.invalid> wrote: > Tried this with Intel Fortran Professional (ifort). Now, I get an error > stating that a kind type parameter must be a compile-type constant. The problem is that the interface block cannot see the mptr parameter through host association. You need to write a separate module that defines the parameter and USE that module within the interface block. Or, just move the parameter definition into the interface block (e.g. if this is the only place it is used). BTW, selected_int_kind(9) is probably not the same precision as the constant kind value 8 (the latter of which is compiler dependent, of course). Is that a typo, or are you trying to extend the precision to 64-bit integers or something? $.02 -Ron Shepard
From: dpb on 12 Oct 2009 12:16
Geico Caveman wrote: ....[second question on interface block inheritance in two days]... As others have noted, it's a scope issue per Standard. Note Bob Corbett's comment in the other thread the information that _IF_ (the proverbial "big if") the compiler you're using supports it, the F2003 IMPORT statement was added to solve the problem. -- |