-1

I have series of time, signal 1 in csv.

DATA_START
Time,29099:ch2
03/06/21 13:54:46.414062500,-0.07945187928089581
03/06/21 13:54:46.421875000,-0.07949399462904694
03/06/21 13:54:46.429687500,-0.07960885466945911

i want to convert like

0.0000000000,-0.07945187928089581
0.0078125000,-0.07949399462904694
0.0156250000,-0.07960885466945911

So the first date time as start zero, next read the date and time and read the interval space as second real*8 before it. How to do it in fortran?

UPDATE: To clear up

So the first data input is the date time, the second is the real*8 accelerometer data.

The output will be interval per each data taken, and the real8 data. so the first output starting zero second. 0.d0 and data first real8 (0.d0 second,-0.07945187928089581) The second line output is the interval between first data time and the second data time 03/06/21 13:54:46.421875000 minus 03/06/21 13:54:46.414062500 and second data (0.0078125000 second, -0.07949399462904694) The third data will be interval 03/06/21 13:54:46.429687500 minus 03/06/21 13:54:46.421875000 (0.015625000,-0.07960885466945911

realbabilu
  • 11
  • 3
  • It is somewhat common to save the integer seconds into a double, and the fractional seconds into another double. One can use a TYPE, structure, or record. Then to get deltas it is just the delta between the whole seconds + the delta to the fractional seconds. You sort of need to take a stab at it with some example code first. Then if there are problems we can use your example to guide into it. Otherwise it can look like a homework service. – Holmz Mar 08 '21 at 08:07
  • Thank you, https://stackoverflow.com/questions/17354100/date-time-difference-in-fortran – realbabilu Mar 08 '21 at 23:43

1 Answers1

0

The following program reads each row.

program main
  implicit none

  character(:), allocatable :: date, time, interval
  double precision          :: x
  integer                   :: funit, stat
  integer                   :: day, mon, y, h, min, s, s_frac

  ! define format strings
  date = 'I2, X, I2, X, I2, X, '
  time = 'I2, X, I2, X, I2, X, I9, X'

  open (newunit=funit, file='times.dat', status='old', action='read')

  ! skip headers
  read (funit, *)
  read (funit, *)

  do while (.true.)
    read (funit, '('//date//time//', D20.17)', iostat=stat) day, mon, y, h, min, s, s_frac, x
    if (stat /= 0) exit
    print *, day, mon, y
    print *, h, min, s, s_frac
    print *, x
    print *
  end do

  close(funit)

end program

The output is as follows

$ gfortran a.f90 && ./a.out 
           3           6          21
          13          54          46   414062500
  -7.9451879280895810E-002

           3           6          21
          13          54          46   421875000
  -7.9493994629046938E-002

           3           6          21
          13          54          46   429687500
  -7.9608854669459106E-002

You only need to save the initial time and compute the difference of the following time stamps w.r.t. the initial time. Note, that I read the second fraction as an integer s.t. one can compute the exact difference without rounding errors.

jack
  • 1,658
  • 1
  • 7
  • 18
  • the 0.0078125000 seconds is 03/06/21 13:54:46.421875000 - 03/06/21 13:54:46.414062500. while -0.07945187928089581 and -0.07949399462904694 is the real*8 data, so 0.0000000000,-0.07945187928089581 is the first mark start 0.0d seconds , with -0.07945187928089581, the second data will be 0.0078125000, -0.07949399462904694. the third data will be 0.015625,-0.07960885466945911 – realbabilu Mar 08 '21 at 09:19
  • Yes to compute the difference of the following time stamps w.r.t. the initial time is what i looking for. since it can be different minutes,hour,days – realbabilu Mar 08 '21 at 09:28