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

Home » Public Forums » archive » How Could I read dates(strings) into a structure?
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
How Could I read dates(strings) into a structure? [message #94839] Wed, 01 November 2017 13:07 Go to next message
limiqt is currently offline  limiqt
Messages: 27
Registered: October 2013
Junior Member
Hi,

I wonder if someone could show me how could I read dates (strings) into a structure.

I need to read thousands of files each with thousands of lines 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 have done the following:

==========
Pro ReadMyData
Close, /All

FileIn='FileIn1'
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
=====

However, I get the error message: READF: Input conversion error. Unit: 100.

I will appreciate any assistance.

Thanks
Re: How Could I read dates(strings) into a structure? [message #94841 is a reply to message #94839] Thu, 02 November 2017 01:15 Go to previous messageGo to next message
Helder is currently offline  Helder
Messages: 10
Registered: October 2017
Junior Member
Hi,
the error message you are getting is because IDL does not know what "dataw" in:
ReadF,lun, dataw
is.
That said, if you are reading a text file, you want to read in strings. There are two very similar approaches: in one case you read the file line by line and each time you process the line and in the second case you read the file as a whole and process everything afterwards.
I'm giving you an example of the second type:

;read the data
nlines = FILE_LINES('\theLocation\Of\My\File.txt')
sarr = strarr(nlines)
get_lun, myUnit
openr, myUnit, '\theLocation\Of\My\File.txt'
readf, myUnit, sarr
free_lun, myUnit

datastruct={MyDate:' ', MyTime:' ', var1:0.0, var2:0.0, var3:0.0}
Mydata=Replicate(datastruct, nlines)

;process the data
for i=0,nlines-1 do begin
splitLine = strsplit(sarr[i],/extract)
;process the data
Mydata[i].MyDate = splitLine[0]
Mydata[i].MyTime = splitLine[1]
Mydata[i].var1 = float(splitLine[2])
Mydata[i].var2 = float(splitLine[3])
Mydata[i].var3 = float(splitLine[4])
endfor

I hope this helps.

Cheers,
Helder

On Wednesday, 1 November 2017 21:07:34 UTC+1, Lim wrote:
> Hi,
>
> I wonder if someone could show me how could I read dates (strings) into a structure.
>
> I need to read thousands of files each with thousands of lines 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 have done the following:
>
> ==========
> Pro ReadMyData
> Close, /All
>
> FileIn='FileIn1'
> 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
> =====
>
> However, I get the error message: READF: Input conversion error. Unit: 100.
>
> I will appreciate any assistance.
>
> Thanks
Re: How Could I read dates(strings) into a structure? [message #94842 is a reply to message #94839] Thu, 02 November 2017 08:20 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Wednesday, November 1, 2017 at 9:07:34 PM UTC+1, Lim wrote:

Move the FORMAT to READF:

datastruct={MyDate:' ', MyTime:' ', var1:0.0, var2:0.0, var3:0.0}
Mydata=Replicate(datastruct, nlines)

OpenR,lun, FileIn,/Get_Lun
ReadF,lun, Mydata, format='(A10,3X,A8,3F9.4)'
Free_Lun, lun

regards,
Lajos


> Hi,
>
> I wonder if someone could show me how could I read dates (strings) into a structure.
>
> I need to read thousands of files each with thousands of lines 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 have done the following:
>
> ==========
> Pro ReadMyData
> Close, /All
>
> FileIn='FileIn1'
> 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
> =====
>
> However, I get the error message: READF: Input conversion error. Unit: 100.
>
> I will appreciate any assistance.
>
> Thanks
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: harrisgeospatial unreachable...
Next Topic: mpfit

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

Current Time: Wed Oct 08 11:27:12 PDT 2025

Total time taken to generate the page: 0.00635 seconds