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



On 29 jun, 14:29, e p chandler <e...@xxxxxxxx> wrote:
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- Ocultar texto entre aspas -

- Mostrar texto entre aspas -

Great! Many thanks

Ed
.



Relevant Pages

  • Re: How to read a csv file when the date comes with /?
    ... It is not that difficult to pre-process a group of input data files ... Now you have separate date and time strings separated by a space. ... character:: dh1,dhb1 ... integer:: ios ...
    (comp.lang.fortran)
  • Re: importing multiple data files
    ... To read from data files in your folder,use the dir command like this to get all filenames ... f.name is a cell array of strings containing all the txt files. ...
    (comp.soft-sys.matlab)
  • Re: Community help on DB import seeked
    ... to load character data encoded as UTF-8 via dbimport command had ... Habichtsberg, Reinhard schrieb: ... I get an export (schema and data files) according to the ... the same 'dbexport' command as well. ...
    (comp.databases.informix)
  • Re: [SLE] Bat files in Linux
    ... >> Maybe if you described what you do for a backup procedure, ... > These three commands sync files on my Windows disk to my Linux disk, ... > This is the most important command as it syncs/backsup all my data files to ...
    (SuSE)
  • Need automated testing tool for old dos based program
    ... I have an old dos based program that I am using to generate test data files ... I would like to find an automated testing program ... This old dos program isn't command line driven so using bat files won't ...
    (comp.programming)