I'm starting in Fortran, and I set up the following program to get the 4th column of data from an INMET data file. The calculated mean being 0 (zero). Could someone tell me where the error is in the program?
program inmet
implicit none
integer, parameter :: M=760, N=18 !Há 760 linhas e 18 colunas
character (4) :: id !Diz que o numero da estação é um string, com 4 itens.
real, dimension (M,N) :: dados !Declaração de matriz
integer :: i
real :: media
open(10,file="inmet.txt",status="old",access="sequential",action="read")
open(20,file="inmet_media_out.txt",status="replace",access="sequential",action="write")
do i = 1,M
read(10,*) id, dados(i,:)
end do
media = sum(dados (:,4))/real(M)
write(20,'(a,f6.2)') "A média de temperaturas é", media
end program
An example of the start of the INMET txt file follows (comma-delimited), and the first column is the weather station code:
A250,17/07/2018,23,25.4,26.6,25.4,75,85,73,20.6,23.3,20.3,995.5,995.5,994.8,1.2,81,7.1,-3.09,0.0
A250,17/07/2018,22,26.1,27.6,26.1,84,84,72,23.2,23.4,22.1,994.8,994.8,994.7,0.4,103,2.0,51.86,0.0
A250,17/07/2018,21,27.6,30.0,27.6,73,75,63,22.5,23.8,22.1,994.7,995.1,994.5,0.8,85,5.2,648.0,0.0
A250,17/07/2018,20,30.0,30.5,29.9,63,66,62,22.2,23.1,21.9,995.1,995.1,994.9,2.4,107,5.7,1875.,0.0
A250,17/07/2018,19,30.0,30.3,29.7,64,67,62,22.4,23.3,21.9,995.0,995.7,994.9,2.0,108,5.5,2382.,0.0
A250,17/07/2018,18,29.8,30.3,29.6,66,70,63,22.8,23.7,22.0,995.7,996.6,995.7,2.2,103,5.5,2763.,0.0
A250,17/07/2018,17,30.1,30.4,29.3,67,69,63,23.4,23.9,22.1,996.6,997.5,996.6,2.1,104,6.0,3128.,0.0
A250,17/07/2018,16,29.4,29.7,28.9,67,72,65,22.6,23.5,22.3,997.5,998.1,997.4,2.3,109,6.0,3143.,0.0
And my output (in txt) is coming out like this:
A média de temperaturas é 0.00
From now on I thank anyone who can enlighten me