Re: how to read date as structure [message #94844 is a reply to message #94828] |
Fri, 03 November 2017 03:54  |
Markus Schmassmann
Messages: 129 Registered: April 2016
|
Senior Member |
|
|
On 10/30/2017 06:23 PM, Lim wrote:
> I wonder if someone could show me how to read a data with dates as structure.
>
> I need to read thousands of files each with thounsands of lines e like this one:
>
> FileIn1:
>
> 2015-06-01 11:02:28 -17.8620 -34.3080 -12.1940
> 2015-06-01 11:02:29 -12.4835 -24.4790 -8.8535
> 2015-06-01 11:02:30 -10.9240 -22.0480 -7.8587
> 2015-06-01 11:02:31 -11.6355 -22.9650 -8.0603
> 2015-06-01 11:02:32 -12.7080 -26.4340 -8.5855
> 2015-06-01 11:02:33 -12.4525 -24.8820 -8.4100
> 2015-06-01 11:02:34 -11.2980 -23.5610 -7.9932
> 2015-06-01 11:02:44 8.8110 12.8375 4.2657
> 2015-06-01 11:03:00 -5.4033 -10.9245 -3.4665
> 2015-06-01 11:03:01 -9.4730 -19.0120 -5.6915
>
>
> I done this:
>
> ==========
> Pro ReadMyData
>
> FileIn='FileIn1'
> Close, /All
> nlines=File_lines(FileIn)
>
> datastruct={MyDate:' ', MyTime:' ', var1:0.0, var2:0.0, var3:0.0}
> Mydata=Replicate(datastruct, nlines)
> Mydata.MyDate = STRING(Mydata.MyDate, FORMAT = '(A10)')
> Mydata.MyTime = STRING(Mydata.MyTime, FORMAT = '(A10)')
>
> OpenR,lun, FileIn,/Get_Lun
> ReadF,lun, dataw
> Free_Lun, lun
>
> End
> =====
> But i get the error message: READF: Input conversion error. Unit: 100.
I hope this is what you are looking for, Markus
pro ReadMyData
FileIn='FileIn1'
nlines=File_lines(FileIn)
datastruct={MyDate:' ', MyTime:' ', var1:0.0, var2:0.0, var3:0.0}
Mydata=Replicate(datastruct, nlines)
fileStr=strarr(nlines)
OpenR,lun, FileIn,/Get_Lun
ReadF,lun, fileStr
Free_Lun, lun
allStr=(strsplit(fileStr,/extract)).toArray()
Mydata.MyDate= allStr[*,0]
Mydata.myTime= allStr[*,1]
Mydata.var1 =float(allStr[*,2])
Mydata.var2 =float(allStr[*,3])
Mydata.var3 =float(allStr[*,4])
end
|
|
|