Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Fortran statement labels well?

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.

like image 984
ryanjdillon Avatar asked Sep 26 '13 12:09

ryanjdillon


People also ask

What is a statement label in Fortran?

A statement label is a sequence of one to five digits, one of which must be nonzero, that you can use to identify statements in a Fortran scoping unit. In fixed source form, a statement label can appear anywhere in columns 1 through 5 of the initial line of the statement.

What is print * in Fortran?

The PRINT statement writes from a list to stdout .

What is a statement label?

A statement label is a unique identifier for a program line. A statement label consists of a string of characters followed by a colon. The colon is optional when the statement label is completely numeric.


1 Answers

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
like image 150
Alexander Vogt Avatar answered Oct 14 '22 03:10

Alexander Vogt