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



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
.



Relevant Pages

  • Re: Unicode Support
    ... > Not knowing much about UTF-8 (my Unicode knowledge extends as far as ... > literal strings of this form as long as the character code for quote ... > can never appear in a MBCS (multibyte character sequence). ... then XP Notepad directly understands UNICODE and you can ...
    (alt.lang.asm)
  • Re: Need help on string manipulation
    ... better to convert strings to UCS-32 before manipulation? ... Characters represented by wchar_t must use one wchar_t per character, ... which may use a multibyte encoding. ... use some newer Unicode characters, if this is a problem for you, then ...
    (comp.lang.c)
  • Re: Copying string to byte array
    ... of Strings and the CryptEncrypt + CryptDecrypt APIs. ... binary data should not be held in String variables. ... a) not all character codes are valid in a given ...
    (microsoft.public.vb.general.discussion)
  • Re: Zero terminated strings
    ... standard library that told you how to encode strings.) ... this redundant terminator as well). ... (Other string libraries like Vstr have ...
    (comp.lang.c)
  • Re: GetOpenFilename()
    ... Specifies that the File Name list box allows multiple selections. ... the directory and file name strings are NULL ... You advance the pointer one character more. ...
    (microsoft.public.vc.language)