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

Home » Public Forums » archive » converting strings to float
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
converting strings to float [message #88749] Fri, 13 June 2014 03:38 Go to next message
Krishnakumar M.A is currently offline  Krishnakumar M.A
Messages: 19
Registered: March 2013
Junior Member
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
Re: converting strings to float [message #88750 is a reply to message #88749] Fri, 13 June 2014 06:11 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
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
Re: converting strings to float [message #88754 is a reply to message #88750] Fri, 13 June 2014 10:43 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
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
Re: converting strings to float [message #88774 is a reply to message #88754] Wed, 18 June 2014 04:18 Go to previous message
Krishnakumar M.A is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Error while creating video in IDL
Next Topic: Program caused arithmetic error: Floating underflow

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

Current Time: Wed Oct 08 13:38:54 PDT 2025

Total time taken to generate the page: 0.00698 seconds