For Programmers: Free Programming Magazines  


Home > Archive > Fortran > November 2004 > printing two strings generated by internal write









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author printing two strings generated by internal write
beliavsky@aol.com

2004-11-18, 3:56 am

The program below, which prints a string created by an internal write,
is compiled without warnings by Compaq Visual Fortran, Lahey/Fujitsu,
and g95. At run time, however, LF95 and g95 crash, whereas CVF gives
the output of "3" that I expect. Is the code ok? When I store
int_to_string(3) in a character variable and then print that variable,
all three compilers work fine.

module yy
implicit none
contains
pure function int_to_string(i) result(text)
integer, intent(in) :: i
character (len=10) :: text
write (text,"(i6)") i
end function int_to_string
end module yy

program xx
use yy, only: int_to_string
implicit none
print*,int_to_string(3)
end program xx
Greg Lindahl

2004-11-18, 3:56 am

In article <3064b51d.0411171728.79ecfdf5@posting.google.com>,
<beliavsky@aol.com> wrote:

>The program below, which prints a string created by an internal write,


Doesn't it break the "no recursive I/O" rule?

Works OK in PathScale's compiler...

-- greg
James Van Buskirk

2004-11-18, 3:56 am

"Greg Lindahl" <lindahl@pbm.com> wrote in message
news:419bff8a$1@news.meer.net...

> In article <3064b51d.0411171728.79ecfdf5@posting.google.com>,
> <beliavsky@aol.com> wrote:


[color=darkred]
> Doesn't it break the "no recursive I/O" rule?


> Works OK in PathScale's compiler...


Breaks the rule in f95, but not f03. Some of my code did this
and worked in LF95 & CVF but many other compilers didn't like it.
I had to change it so that it would be more widely useable.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Steve Lionel

2004-11-18, 3:59 pm

On 17 Nov 2004 17:28:16 -0800, beliavsky@aol.com wrote:

>The program below, which prints a string created by an internal write,
>is compiled without warnings by Compaq Visual Fortran, Lahey/Fujitsu,
>and g95. At run time, however, LF95 and g95 crash, whereas CVF gives
>the output of "3" that I expect. Is the code ok? When I store
>int_to_string(3) in a character variable and then print that variable,
>all three compilers work fine.


As others have noted, Fortran 95 prohibits starting an I/O operation as a
side-effect of a function call in another I/O operation. F2003 relaxes this.

Compaq and now Intel compilers currently allow nested I/O as long as different
units are used, and internal I/O is always allowed.


Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com