That is right.
Here is the code
program y_m5
Implicit none
! Variables
Integer :: i,j,z,aa,ab,ac,status,x,y
Integer :: jancount, febcount,marcount,aprcount, maycount, juncount, julcount, augcount, sepcount, octcount, novcount, deccount,jmax
Integer, Parameter :: nd=5000
Real, Dimension(nd) :: value
Real, Dimension(10000000) :: line
Real, Dimension(200) :: janu, febr, marc, apri, mayo, june, july, augu, sept, octo, nove, dece
Character(len=3), Dimension(nd) :: month
Integer, Dimension(nd) :: day
Character(len=20) :: file2
Character(len=20) :: file1
Real :: sumjan, sumfeb, summar, sumapr, summay, sumjun, sumjul, sumaug, sumsep, sumoct, sumnov, sumdec
Real :: janave, febave, marave, aprave, mayave, junave, julave, augave, sepave, octave, novave, decave
Character(len=3) :: input(47) = (/ '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',&
'70', '71', '72', '73', '74', '75', '76', '77', '78', '79',&
'80', '81', '82', '83', '84', '85', '86', '87', '88', '89',&
'90', '91', '92', '93', '94', '95', '96', '97', '98', '99',&
'00', '01', '02', '03', '04', '05', '06' /)
Character(len=4) :: output(47) = (/ '1960', '1961', '1962', '1963', '1964', '1965', '1966', '1967', '1968', '1969',&
'1970', '1971', '1972', '1973', '1974', '1975', '1976', '1977', '1978', '1979',&
'1980', '1981', '1982', '1983', '1984', '1985', '1986', '1987', '1988', '1989',&
'1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999',&
'2000', '2001', '2002', '2003', '2004', '2005', '2006' /)
! Body of y_m
opendo: do x=1,47
file2=input(x)//'.txt'
OPEN (UNIT=3, FILE=file2, STATUS='OLD', IOSTAT=status)
file1 = output(x)//'.txt'
OPEN(UNIT=1,FILE=file1,STATUS='new',FORM='FORMATTED')
openif: if(status==0) then
read(3,*, IOSTAT=status) (day(z), month(z), value(z), z=1,nd)
else openif
write(*,1040) status
end if openif
1040 format (' ', 'Error opening the file: IOSTAT=', I6)
jancount = 0
febcount = 0
marcount = 0
aprcount = 0
maycount = 0
juncount = 0
julcount = 0
augcount = 0
sepcount = 0
octcount = 0
novcount = 0
deccount = 0
do j=1, nd
if (month(j) .eq. 'Jan' ) then
jancount = jancount + 1
janu(jancount) = value(j)
else if (month(j) .eq. 'Feb') then
febcount = febcount + 1
febr(febcount) = value(j)
else if (month(j) .eq. 'Mar') then
marcount = marcount + 1
marc(marcount) = value(j)
else if (month(j) .eq. 'Apr') then
aprcount = aprcount + 1
apri(aprcount) = value(j)
else if (month(j) .eq. 'May') then
maycount = maycount + 1
mayo(maycount) = value(j)
else if (month(j) .eq. 'Jun') then
juncount = juncount + 1
june(juncount) = value(j)
else if (month(j) .eq. 'Jul') then
julcount = julcount + 1
july(julcount) = value(j)
else if (month(j) .eq. 'Aug') then
augcount = augcount + 1
augu(augcount) = value(j)
else if (month(j) .eq. 'Sep') then
sepcount = sepcount + 1
sept(sepcount)=value(j)
else if (month(j) .eq. 'Oct') then
octcount = octcount + 1
octo(octcount) = value(j)
else if (month(j) .eq. 'Nov') then
novcount = novcount + 1
nove(novcount) = value(j)
else if (month(j) .eq. 'Dec') then
deccount = deccount + 1
dece(deccount) = value(j)
end if
end do
! which month has more data
jmax = jancount
if (jmax .lt. febcount) then
jmax = febcount
else if (jmax .lt. marcount) then
jmax = marcount
else if (jmax .lt. aprcount) then
jmax = aprcount
else if (jmax .lt. maycount) then
jmax = maycount
else if (jmax .lt. juncount) then
jmax = juncount
else if (jmax .lt. julcount) then
jmax = julcount
else if (jmax .lt. augcount) then
jmax = augcount
else if (jmax .lt. sepcount) then
jmax = sepcount
else if (jmax .lt. octcount) then
jmax = octcount
else if (jmax .lt. novcount) then
jmax = novcount
else if (jmax .lt. deccount) then
jmax = deccount
end if
Write(1,11)
! print the data
do i=1, 31
do j = 1, jmax-1
if(day(j) .eq. i) then
write (1, '(I2,(12F10.3))') i, janu(j), febr(j), marc(j), apri(j), mayo(j), june(j), july(j), augu(j), sept(j), octo(j), nove(j), dece(j)
else
write(1,'(I2,(12F10.3))') i
end if
end do
end do
11 Format('Nob', 6x,'Jan', 7x,'Feb', 7x,'Mar', 7x,'Apr', 7x,'May', 7x,'Jun', 7x,'Jul', 7x,'Aug', 7x,'Sep', 7x,'Oct', 7x,'Nov', 7x,'Dec')
end do opendo
close(unit=3)
close(unit=1)
end program y_m5