I am trying to read a dataset which looks like this
DATE,TIME,val
1/1/2001,1:00:00,0
with the program
program main
implicit none
real :: val
character(len=8) :: date
character(len=7) :: time
open(1,file='data.csv',status='old')
read(1,*) ! header
read(1,fmt=100)date,time,val
100 FORMAT (A,1x,A,1x,F3.1)
end program
This is all fine if the date and time always have 8 or 7 characters but they don’t e.g.
4/21/2001,19:00:00,0
How should I declare the format for fortran to read both the date,time,val lines in the example?
Thank you
You could read all the entire
data, time, valueline into a single string and then process that to extract the individual elements, something along the lines ofNote that this is highly specialised to the example data in the question, but it shouldn’t be too hard to generalise this code.