For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2005 > Defining new operators









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Defining new operators
Matthew Nobes

2005-05-01, 9:08 pm

I'm trying to write some f90 code which uses new types and operators
that I have defined. In the module which defines these, I have
the following

interface operator (.getint.) ! gets the integer part n_x and n_y
module procedure getint
end interface
private :: getint
....
function getint(k)
type(mom), intent(in) :: k
integer, dimension(2) :: getint
getint(1) = k%comps(1)%mint; getint(2) = k%comps(2)%mint
end function getint

If I use this in my main program, it works fine. A "print *, .getint.k"
returns exactly whats expected. However, when I try to use the same
operator in function in another module I get a complier error.

That is, if I put

complex function gluoncolour2(k1,k2)
use mommod
type(mom), dimension(4), intent(in) :: k1,k2
print *, .getpol.k1
gluoncolour2 = 0.0
end function gluoncolour2

in a module, and try to compile that I get

matt@smedley:~/Projects/fermilabpt/tmp $ ifort -c colourmod.f90
fortcom: Error: colourmod.f90, line 15: A unary defined OPERATOR
definition is missi\ng or incorrect. [GETPOL]
print *, .getpol.k1
--------------^
compilation aborted for colourmod.f90 (code 1)

I'm sure I'm doing something dumb here, but I cannot understand what it
is. The new operator works fine when used in the main program...


--
Matthew Nobes | email: nobes@lepp.cornell.edu
Newman Lab, Cornell University | web: http://lepp.cornell.edu/~nobes/
Ithaca NY 14853, USA |
James Van Buskirk

2005-05-01, 9:08 pm

"Matthew Nobes" <nobes@lepp.cornell.edu> wrote in message
news:slrnd725bg.5em.nobes@localhost.localdomain...

> type(mom), dimension(4), intent(in) :: k1,k2
> print *, .getpol.k1


> in a module, and try to compile that I get


> matt@smedley:~/Projects/fermilabpt/tmp $ ifort -c colourmod.f90
> fortcom: Error: colourmod.f90, line 15: A unary defined OPERATOR
> definition is missi\ng or incorrect. [GETPOL]
> print *, .getpol.k1
> --------------^
> compilation aborted for colourmod.f90 (code 1)


> I'm sure I'm doing something dumb here, but I cannot understand what it
> is. The new operator works fine when used in the main program...


Your problem is that you are attempting to invoke a function
with a rank-1 actual argument associated with a scalar dummy
argument. This only works if the function is elemental, but
yours can't be because it returns a rank-1 result given a
scalar input. You will have to write a version that accepts
a rank-1 dummy and produces a rank-2 result and then include
that function's name in your module procedure statement.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Richard E Maine

2005-05-01, 9:08 pm

In article <cZadnUXIv85BhOzfRVn-pA@comcast.com>,
"James Van Buskirk" <not_valid@comcast.net> wrote:

> Your problem is that you are attempting to invoke a function
> with a rank-1 actual argument associated with a scalar dummy
> argument.


And note (to the OP) that this has nothing to do with being in a main
program vs in a module.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com