comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: function to convert string to array???

Re: function to convert string to array???
type: item
description: davis@space.mit.edu wrote: > > Hi, > > I was wondering if there is a routine that will read a string and convert > it to an array of floats. ... Have you tried reads? a = 0.d0 & b = 0.d0 & c = 0.d0 reads,'9.32323 24323.233 22.124235555d-14',a,b,c print,c,b,a -chris
creator: Chris McCarthy
date: 1995-03-16T03:00:51-00:00

Re: function to convert string to array???
type: item
description: In article <3k89l3$2ap@news.csus.edu>, Chris McCarthy <chris@quark.sfsu.edu> writes: : davis@space.mit.edu wrote: : > : > Hi, : > : > I was wondering if there is a routine that will read a string and convert : > it to an array of floats. ... : : Have you tried reads? : : a = 0.d0 & b = 0.d0 & c = 0.d0 : reads,'9.32323 24323.233 22.124235555d-14',a,b,c : print,c,b,a The code that I posted uses `reads'. The problem is that you have to determine how many floats the string is composed of and then allocate an array of that size. --John
creator: davis
date: 1995-03-17T04:58:53-00:00

Re: function to convert string to array???
type: item
description: In article <3k89l3$2ap@news.csus.edu>, Chris McCarthy <chris@quark.sfsu.edu> says: > > davis@space.mit.edu wrote: >> >> Hi, >> >> I was wondering if there is a routine that will read a string and convert >> it to an array of floats. ... > > Have you tried reads? > > a = 0.d0 & b = 0.d0 & c = 0.d0 > reads,'9.32323 24323.233 22.124235555d-14',a,b,c > print,c,b,a > > > -chris > Here is another way to do it : wave > a = ' 100. , 200. , 300. , 400. ' wave > a = '[' + a + ']' wave > z = execute('myarray = '+a) wave > info,myarray myarray FLOAT = ARRAY(4) Derrick
creator: dnguyen
date: 1995-03-17T16:24:55-00:00

Re: function to convert string to array???
type: item
description: In article <3kb4ud$jv0@senator-bedfellow.MIT.EDU>, davis@space.mit.edu writes: |> In article <3k89l3$2ap@news.csus.edu>, Chris McCarthy <chris@quark.sfsu.edu> writes: |> : davis@space.mit.edu wrote: |> : > |> : > Hi, |> : > |> : > I was wondering if there is a routine that will read a string and convert |> : > it to an array of floats. ... |> : |> : Have you tried reads? |> : |> : a = 0.d0 & b = 0.d0 & c = 0.d0 |> : reads,'9.32323 24323.233 22.124235555d-14',a,b,c |> : print,c,b,a |> How about, IDL> s = ' 9.32323 24323.233 22.124235555d-14 ' IDL> x = float(splitstr(strcompress(strtrim(s,2)),' ')) Where ;+ ;NAME: ; SPLITSTR ;PURPOSE: ; Split a string into an array at specified character boundary ;CATEGORY: ;CALLING SEQUENCE: ; array = splitstr(string,character) ;INPUTS: ; string = string to be split ; character = character to split string on ;OPTIONAL INPUT PARAMETERS: ;KEYWORD PARAMETERS ;OUTPUTS: ; array = string array ;COMMON BLOCKS: ;SIDE EFFECTS: ;RESTRICTIONS: ; character must be a single character string, e.g. ' ' or 'a' ;PROCEDURE: ;EXAMPLES: ; array = splitstr('Hi There',' ') ; array(0) is 'Hi' ; array(1) is 'There' ;MODIFICATION HISTORY: ; T. Metcalf 1994-11-10 ;- function splitstr,line,char cline = char+string(line(0))+char place = where(byte(cline) eq (byte(char))(0)) nplace = n_elements(place) strarray = strarr(nplace-1L) strarray(0) = strmid(cline,place(0)+1L,place(1)-place(0)-1L) for i = 1L,nplace-2L do begin strarray(i) = strmid(cline,place(i)+1L,place(i+1L)-place(i)-1L) endfor return,strarray end
creator: metcalf
date: 1995-03-17T23:06:49-00:00