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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting data in columns instead of a list in FORTRAN

Status
Not open for further replies.

apugalia

Technical User
Sep 17, 2002
1
US
My only experience with FORTRAN has been in school and now I've just begun using it on a job.

One of my first assignments is to change the format of the output data file in an existing program. Currently, the data outputs in a single lengthy, left-justified column. My task is to create 2 or 3 columns, so that it looks better and is easier to read (and fits on fewer pages).

Any help would be appreciated. Thanks!
 
Post a snippet of the code that the program uses to write to the output file and a brief description of the data it is writing. CaKiwi
 
Also tell us which version of Fortran you are using: IV, 77, 90 or 95. The syntax varies quite a bit.
 
What is the data; all numbers?, text?. I'm assuming integer for simplicity.

ios is assigned the error code from the i/o operation. a value of zero means no gliches, this allows you to read to the end of the file with no 'end-of-file encountered during read' errors.
there is probably a far more elegant method to achieve this outcome, but the general jist is here. I suppose you could determine the file length first, allocate an array, read the data into the array, and rewrite the data in whatever way you want - that would probably be more flexible.

cheers,

CPM

integer :: ios
integer :: data

open (file = fname1, unit = 1)
open (file = fname2, unit = 2)

do
read (1, '(I)',iostat = ios) data
if (ios/=0) exit
write (2, '(I)',advance='no') data
!
read (1, '(I)',iostat = ios) data
if (ios/=0) exit
write (2, '(I)',advance='no') data
!
read (1, '(I)',iostat = ios) data
if (ios/=0) exit
write (2, '(I)',advance='yes') data
end do

close(1)
close(2)

end program



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top