Re: How to read a csv file when the date comes with /?
- From: Ed <emammendes@xxxxxxxxx>
- Date: Sun, 29 Jun 2008 04:26:46 -0700 (PDT)
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
.
- Follow-Ups:
- Re: How to read a csv file when the date comes with /?
- From: Richard Maine
- Re: How to read a csv file when the date comes with /?
- References:
- How to read a csv file when the date comes with /?
- From: Ed
- Re: How to read a csv file when the date comes with /?
- From: Thomas Koenig
- Re: How to read a csv file when the date comes with /?
- From: Ed
- How to read a csv file when the date comes with /?
- 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
|