Re: converting strings to float [message #88774 is a reply to message #88754] |
Wed, 18 June 2014 04:18  |
Krishnakumar M.A
Messages: 19 Registered: March 2013
|
Junior Member |
|
|
On Friday, June 13, 2014 11:13:14 PM UTC+5:30, Chris Torrence wrote:
> On Friday, June 13, 2014 7:11:32 AM UTC-6, David Grier wrote:
>
>> On Friday, June 13, 2014 6:38:35 AM UTC-4, Krishnakumar M.A wrote:
>
>>
>
>>> Hi All,
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> I have a huge data file of two columns and a '# header' line in between. I used grep in idl to remove the '# lines'. The resulting output is written as a string, which is actually of 2 columns. I only require the second column for doing a surface plot. 1st column is just integer numbers. As i split the string by giving
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> h=strmid(b,3,10)
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> It will give me the second column but, rows from 0-9 will have huge -ve values. If I do the same with h=strmid(b,2,10), columns >=100 will give junk values. I'm kind of stuck with this.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Is there a better way to split the string and copy to a fltarr than defining the position to read from, as like one can do in C, Fortran etc?
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Thanks,
>
>>
>
>>>
>
>>
>
>>> Krishnakumar
>
>>
>
>>
>
>>
>
>> Have you considered the READ_ASCII function from the standard IDL library?
>
>>
>
>>
>
>>
>
>> All the best,
>
>>
>
>>
>
>>
>
>> David
>
>
>
> Or, as long as you have spaces between the two columns, you can simply read the values into a 2xN float array and just keep the second column.
>
>
>
> x = fltarr(2,n)
>
> reads,stringdata,x
>
> x = reform(x[1,*])
>
>
>
> -Chris
Thanks David and Chris for the reply.
David : I did it in the exact way as you said before itself, but didnt work. I just tweaked something here and there and it start to work. I did something wrong somewhere. Thanks a lot.
Chris : I haven't used read_ascii yet. And didn't get much idea how to use it my current data set. I'll check and try.
Thanks,
Krishnakumar
|
|
|