Re: How to read a csv file when the date comes with /?
- From: Thomas Koenig <tkoenig@xxxxxxxxxxxxx>
- Date: Sun, 29 Jun 2008 10:31:58 +0000 (UTC)
On 2008-06-29, Ed <emammendes@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
.
- Follow-Ups:
- References:
- Prev by Date: 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: 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):