Re: Read ASCII time format question!! [message #89442 is a reply to message #89439] |
Thu, 16 October 2014 14:02   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
zolilemtumela@gmail.com writes:
> I have a problem with the time format, I can plot but When I am print the time I got a float values. I would like to get time like 16:10 (hh:mm).
> I tried to use strsplit for time but I am not winning. My problem is to be able to do time right.
> Any suggestion will be appreciated! thanks in advance.
Here is how I would do it. I put your example data into a file I named
"time_test.txt".
;*********************************************************** ******
filename = 'time_test.txt'
; Read the data in the file into strings.
rows = File_Lines(filename)
data = StrArr(rows)
OpenR, lun, filename, /Get_Lun
ReadF, lun, data
Free_Lun, lun
; Set up output data arrays.
bx_array = FltArr(rows)
by_array = FltArr(rows)
bz_array = FltArr(rows)
hour = IntArr(rows)
minute = IntArr(rows)
; Parse each row and print it out in the correct format.
FOR j=0,rows-1 DO BEGIN
date = StrMid(data[j], 0, 9)
time = StrMid(data[j], 11, 23)
subString = StrMid(data[j], 24)
ReadS, subString, bx, by, bz
parts = StrSplit(time,':', /Extract)
hour[j] = Fix(parts[0])
minute[j] = Fix(parts[1])
bx_array[j] = bx
by_array[j] = by
bz_array[j] = bz
Print, String(hour[j],Format='(I2.2)') + '.' + $
String(minute[j],Format='(I2.2)'), $
bx_array[j], by_array[j], bz_array[j], $
FORMAT='(A5, 2x, 3(F0.5, 2x))'
ENDFOR
END
;*********************************************************** ******
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|