comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Read ASCII time format question!!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Read ASCII time format question!! [message #89439] Thu, 16 October 2014 10:48 Go to next message
zolile mtumela is currently offline  zolile mtumela
Messages: 50
Registered: September 2011
Member
Hi all,
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.

File = Dialog_PickFile(Filter='*.txt')

nrows =file_lines(file)

Date_array = 0
time_array = 0
Bx_array = 0
By_array = 0
Bz_array = 0

str = ''

openR, Lun, File,/Get_Lun
readf, Lun, str
while~eof(lun) do begin

readf,lun,str
readf,lun,date,time,Bx,By,Bz;
time_str =strsplit(str,'',/extract)
time =strsplit(time_str(1),':',/extract)
hour=FIX(time(0)) & minutes=FIX(time(1)) & seconds=FIX(time(2))

print,hour
stop


;,FORMAT='(A10,1X,A12,3(16X,d0))'

;thabo
;time_str=strsplit(time,':',/extract)


;plittime = STRSPLIT(time[1], ':', /EXTRACT)

;print, splitime
;stop
;str1=strsplit(str,'',/extract)
;time_str =strsplit(str1[1],':',/extract)
;time =float(time_str[0])+float(time_str[1])/60.+float(time_str[2] )/360.
;print,time

;print,date,time,Bx,By,Bz
;time_array =[time_array,time]

Bx_array = [Bx_array, Bx]
By_array = [By_array, By]
Bz_array = [Bz_array, Bz]
endwhile
free_lun,lun

;time_array=time_array[1:*]

Bx_array=Bx_array[1:*]
By_array=By_array[1:*]
Bz_array=Bz_array[1:*]

;print,time_array,Bx_array
;plot,time_array,Bx_array
stop


stop
;Nx = n_elements(Bx_array)
;time = findgen(Nx)
;time = time/(Nx/2)

;Ny = n_elements(By_array)
;time = findgen(Ny)
;time = time/(Ny/2)

;Nz = n_elements(Bz_array)
;time = findgen(Nz)
;time = time/(Nz/2)

Smoothed1 = smooth(Bx_array,3)
Smoothed2 = smooth(By_array,3)
Smoothed3 = smooth(Bz_array,3)

NN1=n_elements(smoothed1)
NN2=n_elements(smoothed2)
NN3=n_elements(smoothed3)
print, smoothed1
print, NN1,NN2,NN3



Data example
23-03-2002 16:11:33.000 1.57100 -8.41400 -4.89800
23-03-2002 16:11:49.000 1.57200 -8.60200 -4.59500
23-03-2002 16:12:05.000 1.00100 -8.48400 -5.06300
23-03-2002 16:12:21.000 0.806000 -8.38700 -5.26600

I would like to print it to file
Time Bx By Bz
16.10 1.57 ... ...
Thankx
Re: Read ASCII time format question!! [message #89442 is a reply to message #89439] Thu, 16 October 2014 14:02 Go to previous messageGo to next message
David Fanning is currently offline  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.")
Re: Read ASCII time format question!! [message #89443 is a reply to message #89439] Thu, 16 October 2014 23:56 Go to previous messageGo to next message
zolile mtumela is currently offline  zolile mtumela
Messages: 50
Registered: September 2011
Member
On Thursday, October 16, 2014 7:48:07 PM UTC+2, zolile...@gmail.com wrote:
> Hi all,
>
> 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.
>
>
>
> File = Dialog_PickFile(Filter='*.txt')
>
>
>
> nrows =file_lines(file)
>
>
>
> Date_array = 0
>
> time_array = 0
>
> Bx_array = 0
>
> By_array = 0
>
> Bz_array = 0
>
>
>
> str = ''
>
>
>
> openR, Lun, File,/Get_Lun
>
> readf, Lun, str
>
> while~eof(lun) do begin
>
>
>
> readf,lun,str
>
> readf,lun,date,time,Bx,By,Bz;
>
> time_str =strsplit(str,'',/extract)
>
> time =strsplit(time_str(1),':',/extract)
>
> hour=FIX(time(0)) & minutes=FIX(time(1)) & seconds=FIX(time(2))
>
>
>
> print,hour
>
> stop
>
>
>
>
>
> ;,FORMAT='(A10,1X,A12,3(16X,d0))'
>
>
>
> ;thabo
>
> ;time_str=strsplit(time,':',/extract)
>
>
>
>
>
> ;plittime = STRSPLIT(time[1], ':', /EXTRACT)
>
>
>
> ;print, splitime
>
> ;stop
>
> ;str1=strsplit(str,'',/extract)
>
> ;time_str =strsplit(str1[1],':',/extract)
>
> ;time =float(time_str[0])+float(time_str[1])/60.+float(time_str[2] )/360.
>
> ;print,time
>
>
>
> ;print,date,time,Bx,By,Bz
>
> ;time_array =[time_array,time]
>
>
>
> Bx_array = [Bx_array, Bx]
>
> By_array = [By_array, By]
>
> Bz_array = [Bz_array, Bz]
>
> endwhile
>
> free_lun,lun
>
>
>
> ;time_array=time_array[1:*]
>
>
>
> Bx_array=Bx_array[1:*]
>
> By_array=By_array[1:*]
>
> Bz_array=Bz_array[1:*]
>
>
>
> ;print,time_array,Bx_array
>
> ;plot,time_array,Bx_array
>
> stop
>
>
>
>
>
> stop
>
> ;Nx = n_elements(Bx_array)
>
> ;time = findgen(Nx)
>
> ;time = time/(Nx/2)
>
>
>
> ;Ny = n_elements(By_array)
>
> ;time = findgen(Ny)
>
> ;time = time/(Ny/2)
>
>
>
> ;Nz = n_elements(Bz_array)
>
> ;time = findgen(Nz)
>
> ;time = time/(Nz/2)
>
>
>
> Smoothed1 = smooth(Bx_array,3)
>
> Smoothed2 = smooth(By_array,3)
>
> Smoothed3 = smooth(Bz_array,3)
>
>
>
> NN1=n_elements(smoothed1)
>
> NN2=n_elements(smoothed2)
>
> NN3=n_elements(smoothed3)
>
> print, smoothed1
>
> print, NN1,NN2,NN3
>
>
>
>
>
>
>
> Data example
>
> 23-03-2002 16:11:33.000 1.57100 -8.41400 -4.89800
>
> 23-03-2002 16:11:49.000 1.57200 -8.60200 -4.59500
>
> 23-03-2002 16:12:05.000 1.00100 -8.48400 -5.06300
>
> 23-03-2002 16:12:21.000 0.806000 -8.38700 -5.26600
>
>
>
> I would like to print it to file
>
> Time Bx By Bz
>
> 16.10 1.57 ... ...
>
> Thankx
Thank you so much, It works, thanks again!!
Re: Read ASCII time format question!! [message #89444 is a reply to message #89439] Fri, 17 October 2014 01:24 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
> 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).

Here's an alternative solution using time format codes:

pro tmp_time
f="d:\mydocs\tmp\time_test.txt"
n=file_lines(f)

t=0d
b=fltarr(3)

print,"Time Bx By Bz"

openr,1,f
for i=0,n-1 do begin
readf,1,t,b,format=("(C(CDI,x,CMOI,x,CYI,x,CHI,x,CMI,x,CSF,x),3g0) ")
print,t,b,format=('(C(CHI2,".",CMI2,x),3(f0.2,x))')
endfor
close,1

end

If you read time like this, you'll also solve your next problem... how to make a plot/calculation using the data.


cheers,
Greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: cgimage - two images on the same window ?
Next Topic: Converting days since 0-01-01 to Julian/Gregorian days - how can IDL recognise 0 AD?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:29:48 PDT 2025

Total time taken to generate the page: 0.76959 seconds