Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran Breaking Output Lines Automatically

Status
Not open for further replies.

eleteroboltz

Technical User
Jan 5, 2009
7
BR
I'm using Intel Visual Fortran 11.1 x64 with Microsoft Visual Studio 2008.

I'm having a simple issue that I cannot solve.
When I write a lot of things in a single write(*,*), it just break the output line at certain point.

For Example, when I write the code:

write(11,*) 'aaaaaaaaa ','aaaaaaaaa ','aaaaaaaaa ', 'aaaaaaaaa ',&
& 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ',&
& 'aaaaaaaaa' ,'aaaaaaaaa ', 'aaaaaaaaa'


The output file 'fort.11' is with 2 lines instead of one continuous line.

aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa
aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa

I don't remember this happening with other compilers that I used in the past.
Does any one know how to fix this problem???

This is crucial for making output data tables.

Thanks in advance.



 
Use the file format * only if the form of the result does not matter. Indeed, the compiler is free to selected that final form !

In your case, select a fixed format like, for instance :

Code:
write(11,"(4a)") 'aaaaaaaaa ','aaaaaaaaa ','aaaaaaaaa ', 'aaaaaaaaa ',&
        & 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ',&           
        & 'aaaaaaaaa' ,'aaaaaaaaa ', 'aaaaaaaaa'

"(4a)" means a maximum of four strings by line without space between two strings (only the spaces embedded within the strings are displayed).

Result :

Code:
aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa 
aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa 
aaaaaaaaaaaaaaaaaa aaaaaaaaa

In changing "(4a)" by "(50a)" you get a single output line :

Code:
aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaa


François Jacq
 
Thank you for the answer.

I fixed this issue by Opening a file using record length (RECL) specifier:

Open(1,file='test.txt',RECL=1024)
write(1,*) 'aaaaaaaaa ','aaaaaaaaa ','aaaaaaaaa ', 'aaaaaaaaa ',&
& 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ', 'aaaaaaaaa ',&
& 'aaaaaaaaa' ,'aaaaaaaaa ', 'aaaaaaaaa'

more info at:
 
Sorry but this is not the right correction even if it seems to work with this specific compiler. "*" is called the "free" format for one good reason : the compiler may choose any kind of output format ! So, with another compiler you could get a different result.

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top