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!

How do you arrange output data from Fortran into a text file with specified columns widths?

Status
Not open for further replies.

ianphil

Technical User
Jul 11, 2015
1
ZA
Regarding thread214-1609970,
I would like to find out how to arrange the output data from Fortran into a text file with specified column widths?

My code is as follows:
write(3,*)'Model Parameters: '
write(3,*)'Column length :',int(RPAR(2)),' m'
write(3,*)'Mass transfer coeff N2 :',int(RPAR(3)),' 1/s'
write(3,*)'Mass transfer coeff O2 :',int(RPAR(4)),' 1/s'
write(3,*)'Saturation constants :',real(RPAR(7)),' kg/kgs'
write(3,*)'Overall heat transfer coeff:',int(RPAR(13)),' J/m2.s.K'
write(3,*)'Gas heat capacity :',int(RPAR(14)),' J/kg.K'
write(3,*)'Solid heat capacity :',int(RPAR(15)),' J/kg.K'
write(3,*)'Temperature ambient :',int(RPAR(16)),' K'
write(3,*)'Pressure atmospheric :',int(RPAR(29)),' Pa'
write(3,*)'Pressure feed :',int(RPAR(30)),' Pa'
write(3,*)'Heat of Adsorption :',int(RPAR(33)),' J/kg'


My output is not aligned in columns and looks untidy.
Please assist.
 
Please visit any Fortran manual and read about the WRITE statement; in particular what it is that could go in place of the asterisk in "write(3,*)"...try something, experiment...the edit-compile-run cycle should be pretty short in this program.

If you really can't figure it out, show us what you got and then we can help you tweak it.
 
implicit none
integer rpar(33),i

do i=1,33
rpar(i)=i
end do

write(*,900),'Model Parameters: '
write(*,900),'Column length :',int(RPAR(2)),' m'
write(*,900),'Mass transfer coeff N2 :',int(RPAR(3)),' 1/s'
write(*,900),'Mass transfer coeff O2 :',int(RPAR(4)),' 1/s'
write(*,910),'Saturation constants :',real(RPAR(7)),' kg/kgs'
write(*,900),'Overall heat transfer coeff:',int(RPAR(13)),
+' J/m2.s.K'
write(*,900),'Gas heat capacity :',int(RPAR(14)),' J/kg.K'
write(*,900),'Solid heat capacity :',int(RPAR(15)),' J/kg.K'
write(*,900),'Temperature ambient :',int(RPAR(16)),' K'
write(*,900),'Pressure atmospheric :',int(RPAR(29)),' Pa'
write(*,900),'Pressure feed :',int(RPAR(30)),' Pa'
write(*,900),'Heat of Adsorption :',int(RPAR(33)),' J/kg'
900 format (a28,i8,a)
910 format (a28,f8.2,a)
end
 
In particular read about Fortran Format Specifiers.
 
Same program but easier to read:

Code:
      implicit none
      integer rpar(33),i
      
      do i=1,33
        rpar(i)=i
      end do
      
      write(*,900),'Model Parameters: '
      write(*,900),'Column length :',int(RPAR(2)),' m'
      write(*,900),'Mass transfer coeff N2 :',int(RPAR(3)),' 1/s'
      write(*,900),'Mass transfer coeff O2 :',int(RPAR(4)),' 1/s'
      write(*,910),'Saturation constants :',real(RPAR(7)),' kg/kgs'
      write(*,900),'Overall heat transfer coeff:',int(RPAR(13)),
     +' J/m2.s.K'
      write(*,900),'Gas heat capacity :',int(RPAR(14)),' J/kg.K'
      write(*,900),'Solid heat capacity :',int(RPAR(15)),' J/kg.K'
      write(*,900),'Temperature ambient :',int(RPAR(16)),' K'
      write(*,900),'Pressure atmospheric :',int(RPAR(29)),' Pa'
      write(*,900),'Pressure feed :',int(RPAR(30)),' Pa'
      write(*,900),'Heat of Adsorption :',int(RPAR(33)),' J/kg'
  900 format (a28,i8,a)
  910 format (a28,f8.2,a)
      end

Output from th program:

Code:
          Model Parameters:
             Column length :       2 m
    Mass transfer coeff N2 :       3 1/s
    Mass transfer coeff O2 :       4 1/s
      Saturation constants :    7.00 kg/kgs
Overall heat transfer coeff:      13 J/m2.s.K
         Gas heat capacity :      14 J/kg.K
       Solid heat capacity :      15 J/kg.K
       Temperature ambient :      16 K
      Pressure atmospheric :      29 Pa
             Pressure feed :      30 Pa
        Heat of Adsorption :      33 J/kg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top