reading time format [message #92636] |
Thu, 28 January 2016 08:04  |
limiqt
Messages: 27 Registered: October 2013
|
Junior Member |
|
|
Hi everyone,
I was wondering if someone could show me how to read a time in IDL. My orignal data are huge and I have about 200 of those files so using Read_ASCCI funtion is not a option. Only the first column is date and the others columns are numbers.
So I need to read the time (eg. 9/30/2015 22:00)
To simplify I have has this example
datain
9/30/2015 23:00 3 10
9/30/2015 23:30 4 10
10/1/2015 0:00 5 10
10/1/2015 0:30 6 10
And My code looks like:
Pro MyCode
Close, /All
FileIn='data_in'
MyFormat='(C(CMOI2.2,"/",CDI2.2,"/",CYI4,1x,CHI2.2,":",CMI2.2), 1x, 2(I2,1x))'
M=FltArr(3,4)
OPENR, unit, dataIn,/GET_LUN
READF, unit, M, format = MyFormat
PRINT, FORMAT=MyFormat, M
FREE_LUN, unit
Print, 'Done :-)'
End
However, I am getting then message:
% Unable to apply format code CYI to input: "/201".
Does some could tell me what I am doing wrong?
Thanks
Lim
|
|
|
Re: reading time format [message #92644 is a reply to message #92636] |
Mon, 01 February 2016 03:56  |
greg.addr
Messages: 160 Registered: May 2007
|
Senior Member |
|
|
This works...
IDL> s='9/30/2015 23:17 3 10 '
IDL> t=0d
IDL> d[0,0]
IDL> reads,s,t,d,format='(C(CMOI,CDI,x,CYI,x,CHI,x,CMI), 2(I2,1x))'
IDL> caldat,t,mn,dy,yr,hr,mt & print,yr,mn,dy,hr,mt,d
2015 9 30 23 17 3 10
I built up the format code one unit at a time - I'm not sure why CMOI is not follwed by an x, when CDI is. I think the '/' must be behaving as a special char here.
Note that you must use a double to read time with minutes.
cheers,
Greg
|
|
|