How to use Fortran statement labels well?
Asked Answered
H

1

8

I'm working on a model written in Fortran 95, which I am completely new to. The concept of statement labels seems strange, and I've so far only found the explanation that the labels can be arbitrarily decided by the author, usually incrementing by 10's.

Are there any practical uses of these labels, other than picking out more easily where a statement is ending? AND a generally accepted standard on how to label.

Hellgrammite answered 26/9, 2013 at 12:44 Comment(2)
the literal answer to "how to use them well" is "don't". Post a specific example if you have something you cant see how to update to modern standards.Confidante
some interesting history here..#541921 -- and it really is ancient history, by the mid 80s we were not sequentially numbering fortran.Confidante
H
12

The only way I can think of statement labels being useful in modern Fortran is for error control when using gotos (yes, they can be useful sometimes - when handled with care ;-)). Chapman lists them under "obsolescent".

Construct names, on the other hand, might be useful sometimes to help the reader understand your code e.g. for large loops or if statements. Another use for construct names is advanced loop control, e.g. when cycling an outer loop:

outer: do i=1,10
  do ii=1,10
    if ( i == 2 .and. ii == 3 ) cycle outer
    z(ii,i) = 1.d0
  enddo
enddo outer
Hagi answered 26/9, 2013 at 12:59 Comment(2)
"outer" is a construct name, not a label. They are syntactically different beasts.Leyes
Thanks for the clarification, I changed it in the text.Hagi

© 2022 - 2024 — McMap. All rights reserved.