I assume that the date string is always 10 characters length.
The number of file records is assumed known at compile time: generalize it as you need.
program cvs_read
implicit none
character(len=10) :: date
integer, parameter :: file_records=11
integer :: year(file_records)
integer :: month(file_records)
integer :: day(file_records)
real :: a1(file_records)
real :: a2(file_records)
real :: a3(file_records)
integer :: file_unit
integer :: i
open(newunit=file_unit, file='input.cvs')
do i=1, file_records
read(file_unit, *) date, a1(i), a2(i), a3(i)
read(date(1:4), *) year(i)
read(date(6:7), *) month(i)
read(date(9:10), *) day(i)
end do
close(file_unit)
do i=1, file_records
print "(I4,1X,I2,1X,I2,1X,3(F5.1,1X))", year(i), month(i), day(i), a1(i), a2(i), a3(i)
end do
stop
end program cvs_read
1935-01-01 -5.5 -0.3 8.5
1935-01-02 -6.0 -1.3 0.5
1935-01-03 -9.0 -3.1 0.0
1935-01-04 -10.7 -2.6 8.8
1935-01-05 -8.1 -4.4 9.0
1935-01-06 -10.9 -5.6 0.2
1935-01-07 -12.3 -6.1 0.4
1935-01-08 -11.8 -9.3 12.8
1935-01-09 -15.3 -11.1 2.3
1935-01-10 -17.2 -11.4 0.1
1935-01-11 -16.6 -7.2 0.0
Compiled with GNU gfortran 5.3 it gives
→ a.out
1935 1 1 -5.5 -0.3 8.5
1935 1 2 -6.0 -1.3 0.5
1935 1 3 -9.0 -3.1 0.0
1935 1 4 -10.7 -2.6 8.8
1935 1 5 -8.1 -4.4 9.0
1935 1 6 -10.9 -5.6 0.2
1935 1 7 -12.3 -6.1 0.4
1935 1 8 -11.8 -9.3 12.8
1935 1 9 -15.3 -11.1 2.3
1935 1 10 -17.2 -11.4 0.1
1935 1 11 -16.6 -7.2 0.0
Seems to work as expected.
New version
As requested by hd
Code
input
Output
→ ifort test.f90 → a.out first line: do with it what you want → cat output.text 1924 01 01 0.0 0.0 0.0 1924 01 02 0.0 0.0 0.0 1924 01 03 0.0 0.0 0.0 1924 01 04 0.0 0.0 7.9 1924 01 05 0.0 0.0 0.0 1924 01 06 0.0 0.0 0.0 1924 01 07 0.0 0.0 0.0 1924 01 08 0.0 0.0 0.0 1924 01 09 0.0 0.0 3.2 1924 01 10 0.0 0.0 0.8 1924 01 11 0.0 0.0 0.0 1924 01 12 0.0 0.0 0.0 1924 01 13 9.0 2.0 0.0 1924 01 14 10.0 2.0 0.0 1924 01 15 10.0 5.0 0.0 1924 01 16 12.0 5.0 0.0 1924 01 17 9.0 5.0 0.0 1924 01 18 12.0 4.0 0.0 1924 01 19 12.0 5.0 0.0 1924 01 20 8.0 3.0 0.0 1924 01 21 4.0 0.0 0.0 1924 01 22 4.0 2.0 0.0
This should be what you want 😄
Note
I have zero-padded month and day integer and I have made general the number of records parsed.