On Sep 5, 2016, at 11:05 AM, Anton Shterenlikht <[log in to unmask]> wrote:
> Compilers tell me that FORMAT statement
> cannot appear in the specification part of a module.
> Where is this restriction in the standard?
In the subclause on module syntax, this constraint:
C1403 (R1404) A module specification-part shall not contain a stmt-function-stmt, an entry-stmt, or a format-stmt.
is what triggers the error message.
>
> I have a module with a number of routines,
> all of which use the same FORMAT statement.
> I was planning to avoid code replication
> by defining a single FORMAT statement in a module
> and then make it available to all routines via
> host association. This seems prohibited.
> What is the best way to use the same FORMAT
> statement in all routines in a module?
Instead of a FORMAT statement, try a character named constant containing the format, as in
module anton
character(*),parameter :: fmt = "(a)"
contains
subroutine p
write (*,fmt) "Hello from p"
end subroutine p
end module anton
program test
use anton
call p
write (*,fmt) "Hello from main"
end program test
>
Cheers,
Bill
> Thanks
>
> Anton
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
|