For Programmers: Free Programming Magazines  


Home > Archive > Fortran > June 2005 > Problem while compiling









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 Problem while compiling
beatdown

2005-06-07, 3:57 am

Hi all. I have a question about fortran77 (I must use it an I cannot
switch to fortran95).

I have the following makefile:

XDIR =3D $(HOME)/ua/cp/pvm3/bin/$(PVM_ARCH)
F77 =3D g77
FFLAGS =3D -O -w
FLIBS =3D -lfpvm3 -lpvm3
LFLAGS =3D -L$(PVM_ROOT)/lib/$(PVM_ARCH)

all: bjacpadre bjachijo

bjacpadre: bjacpadre.o sub.o
$(F77) $(FFLAGS) -o bjacpadre bjacpadre.o sub.o $(LFLAGS)
$(FLIBS)
mv bjacpadre $(XDIR)

bjacpadre.o: bjacpadre.f
$(F77) $(FFLAGS) -c bjacpadre.f

bjachijo: bjachijo.o sub.o
$(F77) $(FFLAGS) -o bjachijo bjachijo.o sub.o $(LFLAGS) $(FLIBS)
mv bjachijo $(XDIR)

bjachijo.o: bjachijo.f
$(F77) $(FFLAGS) -c bjachijo.f

sub.o: sub.f
$(F77) $(FFLAGS) -c sub.f
---------------------------------------------------------------------

In sub.f I have a function as follows:

function norma(x,y,n)
implicit none
integer n,i
real*8 x(n),y(n),norma
norma=3D0.d0
do i=3D1,n
norma=3Dnorma+abs(x(i)-y(i))
enddo
return
end

In this files (sub.f) I have some subroutines too. When I try to use
this function and to compile using the makefile I get the following
error message:

g77 -O -w -c bjachijo.f
bjachijo.f: En el programa `bjachijo':
bjachijo.f:62:
no =3D norma(y,x,n)
^
Declaraci=F3n inv=E1lida de o referencia al s=EDmbolo `norma' en (^)
[observado inicialmente en (^)]
make: *** [bjachijo.o] Error 1

What means in English something like 'Invalid Declaration, ... seen for
the first time in (^)'

Can anyone help me to understand what's happening and to make this
work? Subroutines work fine but not functions. If you need some more
info post here.

Thank you very much.

beliavsky@aol.com

2005-06-07, 3:57 am

beatdown wrote:

<snip>

> In sub.f I have a function as follows:
>
> function norma(x,y,n)
> implicit none
> integer n,i
> real*8 x(n),y(n),norma
> norma=3D0.d0
> do i=3D1,n
> norma=3Dnorma+abs(x(i)-y(i))
> enddo
> return
> end
>
> In this files (sub.f) I have some subroutines too. When I try to use
> this function and to compile using the makefile I get the following
> error message:
>
> g77 -O -w -c bjachijo.f
> bjachijo.f: En el programa `bjachijo':
> bjachijo.f:62:
> no =3D norma(y,x,n)
> ^
> Declaraci=F3n inv=E1lida de o referencia al s=EDmbolo `norma' en (^)
> [observado inicialmente en (^)]
> make: *** [bjachijo.o] Error 1
>
> What means in English something like 'Invalid Declaration, ... seen for
> the first time in (^)'


I think adding the declarations

real*8 norma
external norma

to the codes that use the function norma will solve the problem.

James Van Buskirk

2005-06-07, 3:57 am

"beatdown" <ruben.santacruz@gmail.com> wrote in message
news:1118101293.648261.142600@g49g2000cwa.googlegroups.com...

g77 -O -w -c bjachijo.f
bjachijo.f: En el programa `bjachijo':
bjachijo.f:62:
no = norma(y,x,n)
^
Declaración inválida de o referencia al símbolo `norma' en (^)
[observado inicialmente en (^)]
make: *** [bjachijo.o] Error 1

You must insert the dclaration:

real*8 norma

and optionally:

external norma

in program bjachijo. Simply removing the implicit none
statement from that program will not work because function
norma would then have an inconsistent type between caller
and callee.

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


David Flower

2005-06-07, 8:59 am

The previous posters do not seem to have noticed that norma has been
typed.

Two things to try

1) Change the first line to:
REAL*8 FUNCTION norma(x,y,n)

2) Replace all references (except the FUNCTION statement) to norma with
a local variable, and make the last executable statement :
norma = local

Alois Steindl

2005-06-07, 8:59 am

"David Flower" <DavJFlower@AOL.COM> writes:

> The previous posters do not seem to have noticed that norma has been
> typed.
>
> Two things to try
>
> 1) Change the first line to:
> REAL*8 FUNCTION norma(x,y,n)
>
> 2) Replace all references (except the FUNCTION statement) to norma with
> a local variable, and make the last executable statement :
> norma = local

Hello,
the error doesn't occur in norma, but in bjachijo.f; so I guess your
suggestions will not help much - contrary to the help by beliavsky and
James van Buskirk.
Alois
James Van Buskirk

2005-06-07, 8:59 am

"David Flower" <DavJFlower@AOL.COM> wrote in message
news:1118129554.020172.148710@g49g2000cwa.googlegroups.com...

> The previous posters do not seem to have noticed that norma has been
> typed.


> Two things to try


> 1) Change the first line to:
> REAL*8 FUNCTION norma(x,y,n)


> 2) Replace all references (except the FUNCTION statement) to norma with
> a local variable, and make the last executable statement :
> norma = local


When you post an incorrect followup to one of my posts please at
least have the decency to quote the header line and the part of
my post you erroneously disagree with. The way you post currently,
without attribution or context, forces me to mark your post unread
after reading it, switch to View->Current View->Show all Messages,
then I have to search for the thread that has your mistaken message.
At this point I still don't know whether you followed up to my
message, because it is not possible to distinguish the case where
you might have followed up to a follow-up by a poster whom I have
already killfiled. Afterwards, I will of course have to switch to
View->Current View->Hide Read Messages. If you find a lot of your
messages to be leaf messages, it might be because you may have
found yourself in many killfiles simply due to the annoyance
value of your posting style, and that is disregarding the off-
topic and inaccurate nature of most of your posts.

Having gotten that out of the way, permit me to say that in
this case your suggestion is counterproductive as the function
norma is correct as written by the O.P., modulo the non-standard
usage of REAL*8. The style of declaring the result variable's
type and kind within the function body rather than at the
function statement is preferred by some who have seen that in
many cases the result variable's characteristics can't be
completely specified in the function statement, as for example
if it is an array or has the POINTER attribute, or if it's an
external procedure and its (user-defined) type is defined
within the specification-part of the function or in a module
USEd by the function. Well, this last case may even be OK, I
can't recall, but I don't have to because I always declare the
type, kind, and rank of the result variable within the function
body because it always works there.

I refer you to:

http://h21007.www2.hp.com/dspp/file...m#function_stmt

for a little refresher on the FUNCTION statement.

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


Richard E Maine

2005-06-07, 4:02 pm

In article <1118129554.020172.148710@g49g2000cwa.googlegroups.com>,
"David Flower" <DavJFlower@AOL.COM> wrote:

> The previous posters do not seem to have noticed that norma has been
> typed.


Yes, it has. See the type declaration in it. The type for a function can
be declared either in the function statement, a type declaration
statement in the function, or implicitly. Style preferences vary. I
prefer the style of always using a type declaration statement, for
multiple reasons that I won't bother going into right now, but I do know
people of both other persuasions.

> 2) Replace all references (except the FUNCTION statement) to norma with
> a local variable, and make the last executable statement :
> norma = local


That's not necessary. The language already has such a local variable for
you - the one named norma. There is *ALWAYS* a local variable as part of
a Fortran function. It is called the result variable. By default, it has
the same name as the function, although you can (in f90 or later)
override that default, as you need to do, for example, if you want
direct recursion.

Making a separate local variable is just duplicative.

Others have posted solutions to the OP's problem, so I won't repeat that.

--
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
glen herrmannsfeldt

2005-06-07, 4:02 pm

Richard E Maine wrote:
> In article <1118129554.020172.148710@g49g2000cwa.googlegroups.com>,
> "David Flower" <DavJFlower@AOL.COM> wrote:


[color=darkred]
> Yes, it has. See the type declaration in it. The type for a function can
> be declared either in the function statement, a type declaration
> statement in the function, or implicitly. Style preferences vary. I
> prefer the style of always using a type declaration statement, for
> multiple reasons that I won't bother going into right now, but I do know
> people of both other persuasions.


In this case, though, the type declaration is the third on a REAL*8
statement also declaring the arrays. It might be that I prefer the
declaration on the FUNCTION statement, but if not I would prefer it to
be the only declaration on the first type declaration after the function
statement. It is too easy for a reader to miss the way it is.

-- glen

beatdown

2005-06-07, 8:58 pm

Thank you all very much. What an amount of info for only a simple
question!! :) I have solved it adding a declaration to the bjachijo.f
(where I want to use the 'norma' function):

real*8 norma

Bye :)

Sponsored Links







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

Copyright 2009 codecomments.com