Home > Archive > Fortran > July 2004 > Newbie question...definition issues.
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 |
Newbie question...definition issues.
|
|
| nye-2@medctr.osu.edu 2004-07-09, 4:00 pm |
| Hello all,
Upon compile of a body of f77 code using g77 (MinGW) I have
come to an impasse as it relates to one error:
surv.for:79: warning:
zzt=rand(1)
1
surv.for:1719: (continued):
double precision function rand(j)
2
Same name `rand' used for global at (2) and intrinsic
at (1)
Does anyone have any tips as to how I might alleviate this
error? I have tried rearranging the syntax and redefining
the function as EXTERNAL at 1719, to no avail.
Thanks in advance.
M
| |
| Dave Seaman 2004-07-09, 4:00 pm |
| On 9 Jul 2004 12:46:07 -0700, nye-2@medctr.osu.edu wrote:
> Hello all,
> Upon compile of a body of f77 code using g77 (MinGW) I have
> come to an impasse as it relates to one error:
> surv.for:79: warning:
> zzt=rand(1)
> 1
> surv.for:1719: (continued):
> double precision function rand(j)
> 2
> Same name `rand' used for global at (2) and intrinsic
> at (1)
> Does anyone have any tips as to how I might alleviate this
> error? I have tried rearranging the syntax and redefining
> the function as EXTERNAL at 1719, to no avail.
Have you tried declaring the function to be EXTERNAL at 79 (or somewhere
before it)?
You probably also should declare it to be double precision.
--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/i...book&bookid=228>
| |
| nye-2@medctr.osu.edu 2004-07-12, 4:03 pm |
| >
> On 9 Jul 2004 12:46:07 -0700, nye-2@medctr.osu.edu wrote:
>
>
>
> avail.
>
> Have you tried declaring the function to be EXTERNAL at 79
> (or somewhere before it)?
>
> You probably also should declare it to be double
> precision.
>
>
> --
> Dave Seaman
> Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
> <http://www.commoncouragepress.com/i...m?action=book&b
> ookid=228>
Thanks for the tip. Line 79 is actually the first instance
of `rand' in the code. I took your advice and changed the
definition in line 79, which appeared to alleviate that
error while generating a new one:
surv2.for: In program `sfpdv1':
surv2.for: Outside of any program unit:
surv2.for:97: warning:
k=int(rand(1)*ns)+1
1
surv2.for:1719: (continued):
double precision function rand (j)
2
Same name `rand' used for global at (2) and intrinsic at (1)
[info -f g77 M INTGLOB]
C:\WINNT\TEMP/ccamaaaa.o(.text+0x4d4):surv2.for: undefined
reference to `externalrand_'
0.55 C:\MinGW\bin/g77.exe surv2.for (return code 1)
Correct me if I'm wrong, but now line 97 is looking to
reference the `rand' function as defined in 79 (EXTERNAL).
I think the problem is with `rand' being defined as global
at 1719, since it should be intrinsic anyway. Is there a
simple way to redefine 1719 to sync with the definition of
`rand' as intrinsic everywhere else in the code?
Here are a few pieces of the code, if anyone cares to have a
look:
78 do n=1,271
79 zzt=rand(1)
80 end do
..
..
..
1719 double precision function rand (j)
1720 double precision dseed,u
1721 save dseed
1722 data dseed /17395/
1723 call lrnd(dseed,u)
1724 rand=u
1725 end
Thanks in advance for your help,
Mark
| |
| Janne Blomqvist 2004-07-12, 4:03 pm |
| nye-2@medctr.osu.edu wrote:
> I think the problem is with `rand' being defined as global
> at 1719, since it should be intrinsic anyway. Is there a
> simple way to redefine 1719 to sync with the definition of
> `rand' as intrinsic everywhere else in the code?
Perhaps I'm missing something, but isn't the problem obviously that
"rand" is an intrinsic, and thus trying to define your own function of
the same name will cause trouble? Possible solutions:
1. Rename your rand function to something like myrand or whatever, and
call myrand when you want to use your own function and rand when you
want to use the intrinsic.
2. Use the -funix-intrinsics-delete switch, which will make g77 forget
rand and a bunch of other intrinsics, thus allowing you to use these
names in your own code.
--
Janne Blomqvist
| |
| Jugoslav Dujic 2004-07-12, 4:03 pm |
| Janne Blomqvist wrote:
| nye-2@medctr.osu.edu wrote:
|| I think the problem is with `rand' being defined as global
|| at 1719, since it should be intrinsic anyway. Is there a
|| simple way to redefine 1719 to sync with the definition of
|| `rand' as intrinsic everywhere else in the code?
|
| Perhaps I'm missing something, but isn't the problem obviously that
| "rand" is an intrinsic, and thus trying to define your own function of
| the same name will cause trouble? Possible solutions:
|
| 1. Rename your rand function to something like myrand or whatever, and
| call myrand when you want to use your own function and rand when you
| want to use the intrinsic.
|
| 2. Use the -funix-intrinsics-delete switch, which will make g77 forget
| rand and a bunch of other intrinsics, thus allowing you to use these
| names in your own code.
But AFAIK it has always been legal to reuse/override names of intrinsic
functions in Fortran (provided that RAND is a g77 intrinsic (as an extension)
rather than kinda "well known library routine").
I have a hunch that Mark didn't define
external rand
double precision rand
in headings of all routines that call rand, but it's hard to say without
seeing the code (which appears to be too long for a usenet post).
--
Jugoslav
___________
www.geocities.com/jdujic
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
| |
| nye-2@medctr.osu.edu 2004-07-12, 4:03 pm |
| > But AFAIK it has always been legal to reuse/override names
> of intrinsic functions in Fortran (provided that RAND is a
> g77 intrinsic (as an extension) rather than kinda "well
> known library routine").
>
> I have a hunch that Mark didn't define
>
> external rand
> double precision rand
>
> in headings of all routines that call rand, but it's hard
> to say without seeing the code (which appears to be too
> long for a usenet post).
>
> --
> Jugoslav
When I attempted to define line 79's `rand' as external, g77
simply referred the error to the next instance of `rand' in
the code (line 97), but maintained that 1719's 'rand' was
global, whereas 79's (afterward, 97's) was intrinsic.
Janne's suggestion worked. I was able to compile with no
errors after redefining 1719's double precision function as
`myrand' instead of `rand'.
Thank you.
| |
| Jugoslav Dujic 2004-07-12, 4:03 pm |
| nye-2@medctr.osu.edu wrote:
|| But AFAIK it has always been legal to reuse/override names
|| of intrinsic functions in Fortran (provided that RAND is a
|| g77 intrinsic (as an extension) rather than kinda "well
|| known library routine").
||
|| I have a hunch that Mark didn't define
||
|| external rand
|| double precision rand
||
|| in headings of all routines that call rand, but it's hard
|| to say without seeing the code (which appears to be too
|| long for a usenet post).
|
| When I attempted to define line 79's `rand' as external, g77
| simply referred the error to the next instance of `rand' in
| the code (line 97), but maintained that 1719's 'rand' was
| global, whereas 79's (afterward, 97's) was intrinsic.
Out of curiosity, are lines 79 and 97 in the same program unit?
Could you paste, say, first 120 lines?
--
Jugoslav
___________
www.geocities.com/jdujic
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
| |
| Richard Maine 2004-07-12, 4:03 pm |
| nye-2@medctr.osu.edu writes:
> C:\WINNT\TEMP/ccamaaaa.o(.text+0x4d4):surv2.for: undefined
> reference to `externalrand_'
This looks like it is looking for a function named externalrand.
I am suspicious of a syntax error in your external statement
causing the "external" to be interprted as part of the function name.
But I don't see the external statement posted. (I might have
missed it, though - skimmed pretty quickly as I have to run off
in a minute).
--
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
| |
| Dave Seaman 2004-07-12, 4:03 pm |
| On 12 Jul 2004 09:07:58 -0700, nye-2@medctr.osu.edu wrote:
And I really did mean "somewhere before" line 79, since line 79 is an
executable statement and you can't declare a function to be EXTERNAL as
part of an executable statement. The declaration would have to come
earlier in the same program unit, before any executable statements.
[color=darkred]
Again, that would be in the declaration section of the same program unit
that contains the function call.
[color=darkred]
> Thanks for the tip. Line 79 is actually the first instance
> of `rand' in the code. I took your advice and changed the
> definition in line 79, which appeared to alleviate that
> error while generating a new one:
You don't show what you changed it to, but I would point out that line 79
is not a definition at all. It's an executable statement. What you
need is something like:
c Add the following two lines to the declaration section
c of any program unit containing a reference to 'rand':
double precision rand
external rand
c ... and later on at what was line 79, now perhaps line 81:
k=int(rand(1)*ns)+1
That is, your executable statement does not need to be changed at all.
You need to add the appropriate declarations earlier in that same program
unit.
> surv2.for: In program `sfpdv1':
> surv2.for: Outside of any program unit:
> surv2.for:97: warning:
> k=int(rand(1)*ns)+1
> 1
> surv2.for:1719: (continued):
> double precision function rand (j)
> 2
> Same name `rand' used for global at (2) and intrinsic at (1)
> [info -f g77 M INTGLOB]
> C:\WINNT\TEMP/ccamaaaa.o(.text+0x4d4):surv2.for: undefined
> reference to `externalrand_'
That looks suspicious. Did you change line 79 to read like this?
k=int(external rand(1)*ns)+1
That would produce exactly the error that you observed, assuming you were
compiling in fixed-format mode (blanks not significant).
> 0.55 C:\MinGW\bin/g77.exe surv2.for (return code 1)
> Correct me if I'm wrong, but now line 97 is looking to
> reference the `rand' function as defined in 79 (EXTERNAL).
Line 79 is not a function definition; it's a function reference. The
definition is at line 1719. Line 97 is evidently another reference to
the same function from a different program unit and therefore needs the
external and double precision declarations in that program unit, as
explained above.
> I think the problem is with `rand' being defined as global
> at 1719, since it should be intrinsic anyway. Is there a
> simple way to redefine 1719 to sync with the definition of
> `rand' as intrinsic everywhere else in the code?
In Fortran 77 all functions are global except statement functions. You
could put the DOUBLE PRECISION and EXTERNAL specifications in a header
file and include it in all the appropriate program units. The Fortran 90
way would be to make use of modules instead.
--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/i...book&bookid=228>
| |
| Dave Seaman 2004-07-12, 4:03 pm |
| On 12 Jul 2004 11:18:25 -0700, nye-2@medctr.osu.edu wrote:
[color=darkred]
> When I attempted to define line 79's `rand' as external, g77
> simply referred the error to the next instance of `rand' in
> the code (line 97), but maintained that 1719's 'rand' was
> global, whereas 79's (afterward, 97's) was intrinsic.
> Janne's suggestion worked. I was able to compile with no
> errors after redefining 1719's double precision function as
> `myrand' instead of `rand'.
Did you also change all references to 'rand' to call 'myrand' instead? If
not, you could have achieved the same effect by just deleting the code
for the 'rand' function beginning at line 1719, and all the references to
'rand' would have used the intrinsic function instead. This solution is
nonportable, however, since 'rand' is not required to be an intrinsic
function according to the standard.
--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/i...book&bookid=228>
| |
| Richard Maine 2004-07-13, 3:57 am |
| nye-2@medctr.osu.edu writes:
> When I attempted to define line 79's `rand' as external, g77
> simply referred the error to the next instance of `rand' in
> the code (line 97), but maintained that 1719's 'rand' was
> global, whereas 79's (afterward, 97's) was intrinsic.
I think you are trying to hard to describe the problem to us
instead of showing it to us. Looking at other data in the
thread, I don't think you are actually managing to do what
you are describing. There is no rand associated with a
particular line - only with a whole scoping unit. The
way to "define line 79's rand as external" is to add
a declation. but *NOT* on line 79. I'm betting that
Dave is right in his guess of what you actually did.
I think you need to show the exact code. If not the whole procedure,
at least the exact lines in question. Don't just tell us that you
"define line 79's rand as external". Instead, show us exactly
what code you did to do that. It will save us all a lot of
guessing....and get us to fixing your problem much more
rapidly.
--
Richard Maine
email: my last name at domain
domain: summertriangle dot net
| |
| Mark N. 2004-07-13, 9:01 am |
| Thanks for all the help. I've worked through the issues.
Mark
|
|
|
|
|