Table of contents
CSPICE_LPARSE parses from a string, a list of items
delimited by a single character.
Given:
list a string containing a list of items delimited by the character
`delim'.
help, list
STRING = Scalar
delim the character used to delimit items in the string `list'.
help, delim
STRING = Scalar
nmax the maximum number of separate items extracted from `list' to
return.
help, nmax
LONG = Scalar
the call:
cspice_lparse, list, delim, nmax, items
returns:
items a string array containing up-to `nmax' entries where each array
element represents one item from `list'.
help, items
STRING = Array[N]
Note: `items' returns with size of `nmax' or less.
None.
Any numerical results shown for these examples may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Parse a character string to retrieve the words contained
within.
Example code begins here.
PRO lparse_ex1
;;
;; Define the parameters and list of delimited items.
;;
;; Think of a sentence as a list delimited by a space.
;; DELIM is assigned to a space.
;;
N_MAX = 25
LIST = 'Run and find out.'
DELIM = ' '
;;
;; Parse the items from LIST.
;;
cspice_lparse, list, DELIM, N_MAX, items
;;
;; Output our list.
;;
items_size = size( items, /dimension )
for i = 0, (items_size[0] -1 ) do begin
print, 'Item ' + string(i) + ' : ' + items[i]
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Item 0 : Run
Item 1 : and
Item 2 : find
Item 3 : out.
2) Repeat the previous example with different character
delimiting the items in the list and different maximum number
of items to return.
Example code begins here.
PRO lparse_ex2
;;
;; Local constants.
;;
NCASES = 2
;;
;; Define the lists of delimited items, the delimiting
;; character and the maximum number of items to return.
;;
list = [ '//option1//option2/ //', ' ,bob, carol,, ted, alice' ]
delim = [ '/', ',' ]
nmax = [ 20, 4 ]
for i=0, NCASES - 1L do begin
print, format='(A,I2,A)', 'Case', i, ':'
print, format='(3A)', ' String: ''', list[i], ''''
print, format='(3A)', ' DELIM : ''', delim[i], ''''
print, format='(A,I3)', ' NMAX :', nmax[i]
print, format='(A)', ' Output items:'
;;
;; Parse the items from `list'.
;;
cspice_lparse, list[i], delim[i], nmax[i], items
;;
;; Output the `items'.
;;
n = size( items, /dimension )
for j=0, n[0] - 1L do begin
print, format='(A,I3,3A)', ' Item', j, $
':''', items[j], ''''
endfor
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Case 0:
String: '//option1//option2/ //'
DELIM : '/'
NMAX : 20
Output items:
Item 0:''
Item 1:''
Item 2:'option1'
Item 3:''
Item 4:'option2'
Item 5:''
Item 6:''
Item 7:''
Case 1:
String: ' ,bob, carol,, ted, alice'
DELIM : ','
NMAX : 4
Output items:
Item 0:''
Item 1:'bob'
Item 2:'carol'
Item 3:''
IDL native code to perform the same operation:
items = strsplit ( list, delim, /EXTRACT )
1) If any of the input arguments, `list', `delim' or `nmax', is
undefined, an error is signaled by the IDL error handling
system.
2) If any of the input arguments, `list', `delim' or `nmax', is
not of the expected type, or it does not have the expected
dimensions and size, an error is signaled by the Icy
interface.
3) If the output argument `items' is not a named variable, an
error is signaled by the Icy interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.1.0, 10-AUG-2021 (JDR)
Changed the input argument name "n_max" to "nmax" for consistency
with other routines.
Edited the -Examples section to comply with NAIF standard. Added
first example's problem statement and second complete example.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and updated
-Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
parse items from a list
|