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



On 29 jun, 08:23, Ed <emammen...@xxxxxxxxx> wrote:
On 29 jun, 07:31, Thomas Koenig <tkoe...@xxxxxxxxxxxxx> wrote:





On 2008-06-29, 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
   write (unit=*,FMT=*) line

That doesn't work for the presence of slashes (as you noted yourself).

Here's some sample code that parses a single line.  Once you have the
fields, you can then parse the individual data items with internal
reads.  The idea is to scan the line for the delimiters, save the
delimiter positions in an array, and then use these to determine which
parts of the input line to look at.

A vector-valued equivalent of the INDEX intrinsic would come in handy,
or an equivalent of Perl's 'split' function :-)

program main
  implicit none
  integer, parameter :: ndat = 6
  character(len=80) line
  integer, dimension(0:ndat) :: spos
  integer :: ipos
  integer :: i

  read(*,'(A)') line
  ipos = 0
  spos(ipos) = 0
  do i=1,len(line)
     if (line(i:i) == ',') then
        ipos = ipos + 1
        if (ipos > ndat -1 ) stop 'too many data items'
        spos(ipos) = i
     end if
  end do
  if (ipos + 1 /= ndat) stop 'not enough data items'
  spos(ndat) = len(line)+1
  do i=1,ndat
     print '(A)',line(spos(i-1)+1:spos(i)-1)
  end do
end program main

Mnay many thanks. It worked. The only thing that is missing is how to
attribute the contents of line(spos(i-1)+1:spos(i)-1) (for i=2 and
3,strings with the date and hour) to dh and dhb.

Any ideas?

Ed- Ocultar texto entre aspas -

- Mostrar texto entre aspas -

Never mind! I've got it.

i=2;read(unit=line(spos(i-1)+1:spos(i)-1) ,fmt='(A)')dh
i=3;read(unit=line(spos(i-1)+1:spos(i)-1) ,fmt='(A)')dhb


Many thanks

Regards

Ed
.



Relevant Pages

  • Re: How to read a csv file when the date comes with /?
    ... A vector-valued equivalent of the INDEX intrinsic would come in handy, ...   implicit none ...   integer:: ipos ...
    (comp.lang.fortran)
  • Re: return random value from visible cells
    ...     Function NthCell ...   Dim rArea   As Range ... iPos = iPos + rArea.Count ...   End Sub ...
    (microsoft.public.excel.programming)
  • Re: Toninho Horta
    ...   (I love Toninho's version of Stella by Starlight. ... Carlos Fernando's singing is cool too. ... Iconoclasm kills rock. ... Rock dulls scissors.- Ocultar texto entre aspas - ...
    (rec.music.makers.guitar.jazz)
  • Re: Nocturn Diary
    ... Created By:  Felipe Fiuza ...   1  Therbold Realty ... But, in that way, I'll not win the bonus from Guillaume Giovanni. ... Mostrar texto entre aspas - ...
    (rec.games.trading-cards.jyhad)