Re: How to read a csv file when the date comes with /?
- From: e p chandler <epc8@xxxxxxxx>
- Date: Sun, 29 Jun 2008 10:29:11 -0700 (PDT)
On Jun 29, 6:05 am, Ed <emammen...@xxxxxxxxx> wrote:
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
.....
It is not that difficult to pre-process a group of input data files
with the command
gsar -s/ -r- -o *.csv
(available on *nix and Windows)
So that your sample data file looks like:
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
Now you have separate date and time strings separated by a space.
Create additional variables to hold them and adjust the lengths of the
strings to 10 and 8.
---- start text ----
PROGRAM test_file
INTEGER :: ds
character (len=10) :: dh,dhb
character (len=8) :: dh1,dhb1
real(8) :: temp,ocupacao,kw
integer :: ios
OPEN (UNIT=50,FILE='test.csv',STATUS='OLD')
DO
read(unit=50, fmt=*, iostat=ios)
ds,dh,dh1,dhb,dhb1,temp,ocupacao,kw
if (ios /= 0) exit
! Test output
write (unit=*, fmt=*) 'ds= ', ds
write (unit=*, fmt=*) 'dh= ', dh // ' ' // dh1
write (unit=*, fmt=*) 'dhb= ', dhb // ' ' // dhb1
write (unit=*, fmt=*) 'temp= ', temp
write (unit=*, fmt=*) 'ocupacao= ', ocupacao
write (unit=*, fmt=*) 'kw= ', kw
write (unit=*, fmt=*)
END DO
close(50)
END program test_file
---- end text ----
Note:
1. single line IF
2. // for string concatination
3. write(*,*) for blank line
4. no PAUSE
If the output scrolls by too fast, just redirect output to a file from
the command line.
[snip]
- e
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to read a csv file when the date comes with /?
- Next by Date: Re: How to read a csv file when the date comes with /?
- Previous by thread: Re: How to read a csv file when the date comes with /?
- Next by thread: Re: How to read a csv file when the date comes with /?
- Index(es):
Relevant Pages
|