Re: Writing a modified .txt file issue [message #85374 is a reply to message #85370] |
Mon, 29 July 2013 13:55   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
I haven't really tested this, but now STRSPLIT() can operate on a 2-d array and return the values in a list. So you can eliminate loops entirely
mylist = strsplit(word,' ',/extract)
myarr = mylist.toarray()
data.date = myarr[*,0]
data.time = myarr[*,1]
data.latitude = double( myarr[*,2])
data.longitude = double( myarr[*,3])
On Monday, July 29, 2013 4:03:02 PM UTC-4, Phillip Bitzer wrote:
> FOR i=0L, nLines-1 DO BEGIN
>
> this_row = STRSPLIT(word[i], ' ', /extract)
>
> data[i].date = this_row[0]
>
> data[i].time = this_row[1]
>
> data[i].latitude = DOUBLE(this_row[2])
>
> data[i].longitude = DOUBLE(this_row[3])
>
> ....
>
> ENDFOR
>
>
>
> I have been looking for a better/more efficient way of doing this. Can't seem to find a good way, but maybe Coyote has cooked up something :-) ReadCol works about as quickly as my code.
>
>
>
> I should mention that there are several string columns mixed up amongst the numeric columns. Yuck.
>
>
>
> For the output, Hakan, I would say those numbers *do* match, although they might be formatted differently. You'll want to use the FORMAT keyword, however you're writing the file back out if you want to match the numbers/decimal places/etc.
>
>
>
> A simple example:
>
> IDL> a = 13.2
>
> IDL> PRINT, a
>
> 13.2000
>
> IDL> PRINT, a, format='(F5.2)'
>
> 13.20
>
> IDL> PRINT, a, format='(F4.1)'
>
> 13.2
>
>
>
> You would do something similar using PRINTF.
|
|
|