public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* error with free format in read/print/write
@ 2011-09-19 14:35 Luciano
  0 siblings, 0 replies; only message in thread
From: Luciano @ 2011-09-19 14:35 UTC (permalink / raw)
  To: gcc-help

Hello, my name is Luciano.
I have Fortran 4:4.5.2-1Ubuntu3       The GNU Fortran 95 compiler installed by
synaptic.
In man gfortran => gcc-4.5.2                         2011-04-18                
      GFORTRAN(1)

When I read one variable in Pmat.prn the variable modify the value if not out is
formated. In original 1 space between numbers.

    <file> Pmat.prn                    <file> Pmatout.prn - out formated
              
1.20    2.31    3.42    4.53           1.20    2.31    3.42    4.53
6.74    7.85    8.96    9.07           6.74    7.85    8.96    9.07
2.28    3.39    4.40    5.51           2.28    3.39    4.40    5.51
6.72    5.43    7.24    4.55           6.72    5.43    7.24    4.55

========================================================================
Free Format in Read and out with PRINT*
 x = line 1    1.2000000       2.3099999       3.4200001       4.5300002    
 x   1  * 2    2.4000001       4.6199999       6.8400002       9.0600004    
 x   1  * 3    3.6000001       6.9299998      10.260000       13.590000    
 x   1  * 4    4.8000002       9.2399998      13.680000       18.120001    

 x = line 2    6.7399998       7.8499999       8.9600000       9.0699997    
 x   2  * 2   13.480000       15.700000       17.920000       18.139999    
 x   2  * 3   20.219999       23.549999       26.880001       27.209999    
 x   2  * 4   26.959999       31.400000       35.840000       36.279999    

 x = line 3    2.2800000       3.3900001       4.4000001       5.5100002    
 x   3  * 2    4.5599999       6.7800002       8.8000002      11.020000    
 x   3  * 3    6.8400002      10.170000       13.200001       16.530001    
 x   3  * 4    9.1199999      13.560000       17.600000       22.040001    

 x = line 4    6.7199998       5.4299998       7.2399998       4.5500002    
 x   4  * 2   13.440000       10.860000       14.480000        9.1000004    
 x   4  * 3   20.160000       16.289999       21.719999       13.650001    
 x   4  * 4   26.879999       21.719999       28.959999       18.200001    

========================================================================  
Formated Format in Read with WRITE

 Line 1 - Out in Screen by Write*,formats (free format)
  L--->   1.20            2.31            3.42            4.53 

 x did read with formated format and print with free format - screen by print
 x     =  1.2000000       2.3099999       3.4200001       4.5300002    
 x * 2 =  2.4000001       4.6199999       6.8400002       9.0600004    
 x * 3 =  3.6000001       6.9299998      10.260000       13.590000    
 x * 4 =  4.8000002       9.2399998      13.680000       18.120001    

 Line 2 - Out in Screen by Write*,formats (free format)
  L--->   6.74            7.85             8.96            9.07

 x did read with formated format and print with free format - screen by print 
 x     =  6.7399998       7.8499999       8.9600000       9.0699997    
 x * 2 = 13.480000       15.700000       17.920000       18.139999    
 x * 3 = 20.219999       23.549999       26.880001       27.209999    
 x * 4 = 26.959999       31.400000       35.840000       36.279999    

 Line 3 - Out in Screen by Write*,formats (free format)
  L--->   2.28            3.39            4.40            5.51

 x did read with formated format and print with free format - screen by print
 x     =  2.2800000       3.3900001       4.4000001       5.5100002    
 x * 2 =  4.5599999       6.7800002       8.8000002      11.020000    
 x * 3 =  6.8400002       10.170000       13.200001      16.530001    
 x * 4 =  9.1199999       13.560000       17.600000      22.040001    

 Line 4 - Out in Screen by Write*,formats (free format)
  L--->   6.72             5.43            7.24            4.55

 x did read with formated format and print with free format - screen by print
 x     =  6.7199998       5.4299998       7.2399998       4.5500002    
 x * 2 = 13.440000       10.860000       14.480000        9.1000004    
 x * 3 = 20.160000       16.289999       21.719999       13.650001    
 x * 4 = 26.879999       21.719999       28.959999       18.200001    

==========================================================================
program abre_aquivo
!
! ARQUIVO LIDO => Pmat.prn
! 1.20 2.31 3.42 4.53
! 6.74 7.85 8.96 9.07
! 2.28 3.39 4.40 5.51
! 6.72 5.43 7.24 4.55
!
! ARQUVIVO GRAVADO COM FORMATAÇÃO Pmatout.prn
! 1.20 2.31 3.42 4.53
! 6.74 7.85 8.96 9.07
! 2.28 3.39 4.40 5.51
! 6.72 5.43 7.24 4.55
!
implicit none
real ::a,b,c,d
integer::i
!
open(1,file='Pmat.prn')
open(2,file='Pmatout.prn')
!
print*,' '
print*,'Leitura livre'
!
do i=1,4
    read(1,*)a,b,c,d
    print*,'x = linha',i,'     ',a,b,c,d
    print*,"x        ",i,' * 2 ', a*2,b*2,c*2,d*2
    print*,"x        ",i,' * 3 ', a*3,b*3,c*3,d*3
    print*,"x        ",i,' * 4 ', a*4,b*4,c*4,d*4
enddo
!
print*,' '
print*,'Leitura formatada'
!
rewind(1)
!
do i = 1,4
    read(1,'(f4.2, 1x, f4.2, 1x, f4.2, 1x, f4.2)')a,b,c,d
    write(*,'(f4.2, 1x, f4.2, 1x, f4.2, 1x, f4.2, 1x, a40)'),a,b,c,d,"<=== Saída
na Tela, via Write*,formatos "
    write(2,'(f4.2, 1x, f4.2, 1x, f4.2, 1x, f4.2)')a,b,c,d
    print*, 'x com leitura  formatada e print formato livre"*" - Tela via
print', a,b,c,d
    print*, 'x * 2  -  com  leitura  formatada  e  print  formato  livre "*"  
',a*2,b*2,c*2,d*2
    print*, 'x * 3  -  com  leitura  formatada  e  print  formato  livre "*"  
',a*3,b*3,c*3,d*3
    print*, 'x * 4  -  com  leitura  formatada  e  print  formato  livre "*"  
',a*4,b*4,c*4,d*4
enddo
close(1); close(2)
end
==========================================================================

Is this a problem with the compiler ? Or my processor can bad ?

My hardware is a Intel Core 2 Quad:
Memory:           2,GiB
Processor 0: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
Processor 1: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
Processor 2: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
Processor 3: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz

System:
11.04(natty) - 64 bits - (Portuguese)
Kernel Linux 2.6.38-11-generic
GNOME 2.32.1

Thank for Gfortran!
Luciano R Ribeiro

-- 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-09-19 14:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-19 14:35 error with free format in read/print/write Luciano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).