Manual Reference Pages  - block (7fortran)

NAME

BLOCK(7f) - [EXECUTION CONTROL] block construct

SYNOPSIS

Syntax:

        [block-construct-name:] BLOCK
        [specification-part]
        ENDBLOCK [block-construct-name]

DESCRIPTION

The BLOCK(7F) construct is an executable construct which may contain declarations, and may be exited using the EXIT(7F) statement.

Aside from the following restrictions a block construct is in many ways similiar to a contained procedure without parameters accept it is constructed in-line instead of after the body of the current procedure.

So if you are thinking about making a contained procedure that will be called once it will probably be clearer inlined using a block construct.

The specification-part of a BLOCK(7F) construct cannot contain a COMMON, EQUIVALENCE, IMPLICIT, INTENT, NAMELIST, or OPTIONAL statement.

A SAVE of a common-block-name is not allowed in a BLOCK(7F) construct.

Except for the ASYNCHRONOUS and VOLATILE statements, specifications in a BLOCK(7F) construct declare construct entities whose scope is that of the block construct.

EXAMPLES

Sample programs:

        program demo_block
        implicit none
        integer,parameter :: arr1(*)=[1,2,3,4,5,6,7]
        integer,parameter :: arr2(*)=[0,1,2,3,4,5,6,7]

! so when you want error processing to be skipped ! if you exhaust a series of tries and really hate GOTO ... DEBUG: block integer :: icount do icount=1,100 ! look for answer up to 100 times if(icount.eq.40)exit DEBUG ! found answer, go on enddo ! never get here unless exhausted the DO loop write(*,*)’never found the answer’ stop 3 endblock DEBUG ! call showme(arr1) call showme(arr2) ! contains ! subroutine showme(a) integer,intent(in) :: a(:) integer :: i=-100 integer :: tan tan=20 ! intentionally cause a conflict with intrinsic ! cannot use tan(3f) right here because using name for a variable TESTFORZERO: block integer :: I ! local block variable intrinsic :: tan ! can use the TAN intrinsic in the block now ! as this definition supercedes the one in the ! parent body do i=1,size(a) if(a(i).eq.0) then write(*,*)’found zero at index’,i exit TESTFORZERO endif enddo write(*,*)’Never found a zero, tried ’,i-1,’ times’ return endblock TESTFORZERO ! note the variable I in the block is local to the block write(*,*)’this is the variable back in the main scope, I=’,i end subroutine showme

end program demo_block

Results:

     >  Never found a zero, tried 7  times
     >  found zero at index 1
     >  this is the variable in the main scope of the program, I=-100

SEE ALSO

o DO(3) - construct
o IF(3) - selects a block based on a sequence of logical expressions.
o CYCLE(3) - construct
o EXIT(3) - statement
o ASSOCIATE(3) - associate construct
o BLOCK(3) - construct
o GOTO(3) - jump to target line
o SELECT(3) - select a block based on the value of an expression (a case)
o CASE(3) - select a block based on the value of an expression (a case)
o ENDSELECT(3) - select a block based on the value of an expression (a case)
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 block (7fortran) November 02, 2024
Generated by manServer 1.08 from 04602238-76d9-47e2-ac99-6a45f9614ff9 using man macros.