How to read a csv file when the date comes with /?



Hello

I know that there is a bunch of threads on the subject but I don't
seem to get the rirght way of coding a specific code for my problem.

Here is the cvs dat format (too many to change format)

5,01/02/2008 15:00:00,01/02/2008 15:00:00, 29.48, 1298, 329.6
5,01/02/2008 16:00:00,01/02/2008 16:00:00, 29.38, 1265, 313.28
5,01/02/2008 17:00:00,01/02/2008 17:00:00, 28.25, 1199, 271.68
5,01/02/2008 18:00:00,01/02/2008 18:00:00, 27.21, 1147, 245.12
5,01/02/2008 19:00:00,01/02/2008 19:00:00, 27.35, 1072, 248
5,01/02/2008 20:00:00,01/02/2008 20:00:00, 26.02, 1071, 240.32
5,01/02/2008 21:00:00,01/02/2008 21:00:00, 25.08, 990, 224.32
5,01/02/2008 22:00:00,01/02/2008 22:00:00, 24.29, 777, 239.36
5,01/02/2008 23:00:00,01/02/2008 23:00:00, 23.45, 697, 230.4
6,02/02/2008 00:00:00,02/02/2008 00:00:00, 23.12, 662, 205.76
6,02/02/2008 01:00:00,02/02/2008 01:00:00, 23.26, 623, 168.64
6,02/02/2008 02:00:00,02/02/2008 02:00:00, 22.71, 620, 163.2
6,02/02/2008 03:00:00,02/02/2008 03:00:00, 22.16, 568, 165.12

......

Here is the code that doesn't work

PROGRAM test_file

INTEGER :: ds
character (len=19) :: dh,dhb
real(8) :: temp,ocupacao,kw

integer :: ios



OPEN (UNIT=50,FILE='test.csv',STATUS='OLD')
DO
temp=0.0D+00;ocupacao=0.0D+00;kw=0.0D+00
ds=0;dh='';dhb=''
read (unit=50, fmt=*, iostat=ios) ds,dh,dhb,temp,ocupacao,kw
if (ios /= 0) then
close(50)
exit
end if
! Test output
write (unit=*, fmt=*) 'ds= ', ds
write (unit=*, fmt=*) 'dh= ', dh
write (unit=*, fmt=*) 'dhb= ', dhb
write (unit=*, fmt=*) 'temp= ', temp
write (unit=*, fmt=*) 'ocupacao= ', ocupacao
write (unit=*, fmt=*) 'kw= ', kw
write (unit=*, fmt='()')
pause
END DO
close(50)
STOP

END program test_file

Here it is another code bsed on the ohter threads on the subject

PROGRAM test_file

INTEGER :: ds
character (len=80) :: line
character (len=19) :: dh,dhb
real(8) :: temp,ocupacao,kw

integer :: ios



OPEN (UNIT=50,FILE='test.csv',STATUS='OLD')
DO
temp=0.0D+00;ocupacao=0.0D+00;kw=0.0D+00
ds=0;dh='';dhb=''
read (unit=50, fmt='(a)', iostat=ios) line
if (ios /= 0) then
close(50)
exit
end if
! Add delimiter at end of line buffer
line = trim(line) // '/'
write (unit=*,FMT=*) line
! Read field values from line buffer
read (unit=line, fmt=*) ds,dh,dhb,temp,ocupacao,kw
! Test output
write (unit=*, fmt=*) 'ds= ', ds
write (unit=*, fmt=*) 'dh= ', dh
write (unit=*, fmt=*) 'dhb= ', dhb
write (unit=*, fmt=*) 'temp= ', temp
write (unit=*, fmt=*) 'ocupacao= ', ocupacao
write (unit=*, fmt=*) 'kw= ', kw
write (unit=*, fmt='()')
pause
END DO
close(50)
STOP

END program test_file

and here it is an output of the programs

ds=5
dh=01
dhb
temp=0.
ocupacao=0.
kw=0.

....

Slash seems to be the problem. The last three fields (real) don't have
a fixed format.

Any help is greatly appreciated.

Many thanks for your time.

Ed


.