[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function to convert string to array???



In article <3lek18$pm0@reznor.larc.nasa.gov> zawodny@arbd0.larc.nasa.gov (Joseph M Zawodny) writes:
>In article <1995Mar29.192708.17563@alw.nih.gov> cox <cox@colt.cpi.com> writes:
>
>>Here is my routine which converts a string of space or comma-delimited
>>items into a   string array.

>
>Just do this:
>
>	READS,input_string,numbers
>
>Where numbers is an array (intarr(10), or fltarr(12), or whatever)
>or a structure a={f1: 0, f2: 0.0, f3: bytarr(100), ... }
>


I was not sure about the use of a structure in the READS call,
but the following example illustrates my point more completely.

IDL> s='12, 24  36 3.456  2 3 4 5, 6,7'

;                 ^ there is a tab in this string here

IDL> a={f1:0, f2:0, f3:0L, f4:0., f5:intarr(6)}

IDL> help,/str,a
** Structure <4009be08>, 5 tags, length=24, refs=1:
   F1              INT              0
   F2              INT              0
   F3              LONG                 0
   F4              FLOAT           0.00000
   F5              INT       Array(6)

IDL> reads,s,a

IDL> help,/str,a
** Structure <4009be08>, 5 tags, length=24, refs=1:
   F1              INT             12
   F2              INT             24
   F3              LONG                36
   F4              FLOAT           3.45600
   F5              INT       Array(6)
IDL> print,a.f5
       2       3       4       5       6       7

	Have fun,
-- 
 Joseph M. Zawodny   (KO4LW)                    NASA Langley Research Center
 Internet: j.m.zawodny@larc.nasa.gov            MS-475, Hampton VA, 23681-0001
 TCP/IP:   ko4lw@ko4lw.ampr.org			Packet: ko4lw@n4hog.va.usa.na