Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Format label and Contains block

Sebastien_D_
Beginner
846 Views

Hi all,

i'm working on a main routine with many other subroutine in a contains block. In the main one, I defined some format labels but I can't use them in the contains block : they are no more defined. At the moment, I avoid this problem by redefined format labels in each subroutine in the contains block ; but this solution isn't really suitable. Is there a way to define these labels only once ?

Thanks,

Sebastien.

0 Kudos
5 Replies
IanH
Honored Contributor III
846 Views

Rather than format statements, consider using format specifications in character constants.

[fortran]  CHARACTER(*), PARAMETER :: my_format = "('Here is an example format specification.')"

  PRINT my_format

  END

[/fortran]

The advantage of character constants is that their name can be more descriptive, plus, as they are just "normal" parameters, they can be provided in a module or in a host scope (your situation) or whatever.

0 Kudos
TommyCee
Beginner
846 Views

Very clever, Ian.  In your syntax, it seems that you package the format specification within a "variable".  In that sense, it could be even placed within a Fortran module, which can be accessed by some of the program units Sebastian is using which use this format.  In this way, it might could be defined once and applied to all units in which it's needed via a Use statement.

0 Kudos
jimdempseyatthecove
Honored Contributor III
846 Views

>> it seems that you package the format specification within a "variable".

While the sample snip used PARAMETER you could leave it as a variable. Then at run time you could load up the variable with the desired contents.(you initialize it with default values at compile time)

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
846 Views

A terminology correction - you have contained procedures, not a contained "block". While variables in the parent procedure are visible in the contained procedure, statement labels (and formats) are not. Ian's suggestion of a parameter constant for the format is a good one - there is no performance penalty for that. Just make sure you use PARAMETER so the compiler can see it at compile time.
 

0 Kudos
Sebastien_D_
Beginner
846 Views

Thanks for all your answers, that's exactly what I need. I just try it, and it works very fine.

Sebastien.

0 Kudos
Reply