JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Monospaced Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2003

COMP-FORTRAN-90 2003

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: CONTAINS

From:

Paddy O'Brien <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Mon, 30 Jun 2003 15:04:29 +1000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (155 lines)

Phillip Helbig wrote:
>>How is CONTAINS supposed to work legally. There is no full explanation
>>in my help or manuals.
>
>
> I've used it for years. I think we use the same compiler. :-)
>
You don't just think we do, you know we do :-)


>
>>If I have the situation where SUBROUTINE A calls SUBROUTINE B, and
>>SUBROUTINE B calls subs C and D, since CONTAINS cannot be nested , can I
>>write:
>
>
> Right, CONTAINS cannot be nested.
>
>
>>SUBROUTINE A
>>
>>CALL B
>>
>>CONTAINS
>>
>>SUBROUTINE B
>>CALL C
>>CALL C
>>CALL D
>>END SUBROUTINE
>>SUBROUTINE C
>>END SUBROUTINE
>>SUBROUTINE D
>>END SUBROUTINE
>>END
>
>
> This looks OK on the face of it. (I recommend putting the names of the
> subroutines in the END SUBROUTINE statement, though.)
>
Agreed about the names, just being lazy here.


>
>>Before I contact the vendor, I would like to know the legality of this
>>sequence. It compiles but gives me incorrect results.
>
>
> Does it compile without even a warning when all the compiler options are
> set to produce strict warnings? As to the results, you probably need to
> post a more complete example.
>
Yes, no warnings. We always want to get whatever informationals or
warnings the compiler wants to give us and then eliminate the cause of
the message.

In this case, I eventaully tracked this down with the debugger. And
another case for IMPLICIT NONE. In the sequence above, none of A, B, C
or D had used it and most variables were assuming implicit typing. I
had combined the routines with contains and had not added any explicit
type declarations.

In B, the call to D was within a DO I loop passing subscripts (I) of
arrays into simple variable dummy arguments. D contained a local DO I
loop and somehow, since it presumably thought it inherited I from B,
managed to make a complete mess of the subscripts in the call arguments.

By changing the loop variable name in D, the correct results were
obtained. Since D, according to the annotations, was in-lined to B, I
am reporting this to the vendor as a compiler bug as it should have
given me an error that told me that the loop control variable was
identical to that in an outer loop.

>
>>I also found that if C and D were functions I would get a compilation
>>warning that one of them had been completely wiped out by the compiler.
>
>
> Do you mean "optimised away"?
>
No, I forgot the exact wording while I was writing the above. It was
"F90-W-WARNING, Routine XXX is not called and has been eliminated."
This is obviously not the same as being eliminated. This was a similar
structure to the above code sketch and the function was D being used in
B. Changing the function call to a subroutine with an extra output
argument did not "eliminate" it.

>
>>A debug session shows me that it enters routine C, but seems not to have
>>inherited variables from B. Therefore, a secondary question, should all
>>contained routines only inherit from A, or if called from B do they
>>inherit B's variables too? I get a compilation warning that a variable
>>that I assumed was inherited from B in C is used before a value is set.
>>B always sets the variable before the call.
>
>
> No, just from A. Calling C from B is the same as if these were both
> external subroutines. (If C inherited from B, this would be "implicit
> nesting".)
>
>
Thanks I had guessed that but thought I would confirm.

>>These warnings tend to give me the impression that CONTAINS can only go
>>down one level unless the compiler totally in-lines the code.
>
>
> I don't follow this. It cannot be nested, as you said.
>
Bad phrasing on my part. Sorry to confuse. I was really just
paraphrasing, in what I thought easier language, what I had said in my
previous paragraph :-(

>
>>My compiler inlines B into A and also declares that it has in-lined D
>>into A, but no mention of C, wherein lies my failures.
>
I was wrong, my failures were in D as noted above. It was the nature of
the failures prior to my full investigation that made me think this. C
was calculating the variables correctly, but D was happily overwriting
them was its subscript mix-ups.

>
> Do you see a difference between compiling with and without optimisation?

No, since the debugger showed up the errors, and obviously I had /noopt
for a debug session.

Many thanks,

Regards, Paddy



***********************************************************************

"This electronic message and any attachments may contain privileged
and confidential information intended only for the use of the
addressees named above. If you are not the intended recipient of
this email, please delete the message and any attachment and advise
the sender. You are hereby notified that any use, dissemination,
distribution, reproduction of this email is prohibited.

If you have received the email in error, please notify TransGrid
immediately. Any views expressed in this email are those of the
individual sender except where the sender expressly and with
authority states them to be the views of TransGrid. TransGrid uses
virus scanning software but excludes any liability for viruses
contained in any attachment.

Please note the email address for TransGrid personnel is now
[log in to unmask]"

***********************************************************************

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager