ARG_PARSE Name
ARG_PARSE Purpose
Parse an argument list into positional and keyword args.
Category
Calling Sequence
arg_parse, txt, out Inputs
txt = Argument list in a scalar text string. in
Keyword Parameters
Keywords
KEYABB=abb Array of minimum allowed length keyword names.
KEYDEF=def Array of keyword default values.
KEYFULL=ful Array of full keyword names.
These 3 optional arrays must be the same size.
/KEYMERGE Merge repeated keywords, concatenate values.
/UNSORT Return keyword names and values in original
unsorted order given. Not allowed with /KEYMERGE.
NPARAMS=n Number of positional parameters to expect.
This is an input value to allow additional checking.
ERROR=err Error flag: 0=ok.
Keywords given in KEYABB and KEYDEF are added to the
returned list if they were not in the arg list.
If KEYFULL is given the names there are used for keytag.
This allows names to be forced to known values.
Arg list keywords not in these lists are not renamed.
KEYABB and KEYDEF must be given to use KEYFULL.
All arguments should be constants, not variables or
expressions, and be separated by commas. Returned values
(positional or keyword) are strings. Multiword string
values may be given, don't use quotes. For example:
txt = '10,20,a b c,30,x=1,y=2,t=oct 16,z=3'
Outputs
out = Returned args in a structure. out
out = { npos:npos, pos:posval, nkeys:nkeys, $
keytag:ktag, keyval:kval }
npos = Number of positional args.
posval = List of positional arg values.
nkeys = Number of keyword args.
ktag = List of keyword names. Sorted by name.
kval = List of keyword values. Sorted by name.
pos, keytag, and kayval are all string arrays.
Common Blocks
Notes
Notes: Flags are considered keywords (with value=1).
Example input arg list:
txt = '0, 100, 50, /int, frame=2, color=255'
In the returned structure out, pos would be the
text array ['0','100','50']. keytag would be the
text array ['color','frame','int']. keyval would be the
text array ['255','2','1'].
Modification History
R. Sterner, 2006 Oct 18
R. Sterner, 2006 Oct 20 --- Added NPARAMS=np, ERROR=err.
R. Sterner, 2006 Oct 24 --- Fixed error in processing keywords.
R. Sterner, 2006 Dec 05 --- Repeated keywords now forced to full name.
R. Sterner, 2006 Dec 05 --- Keyword values now not trimmed, so leading
or trailing spaces are kept.
R. Sterner, 2006 Dec 05 --- Repeated keywords may be merged.
R. Sterner, 2007 Jun 12 --- Added /UNSORT (not allowed with /keymerge).
R. Sterner, 2009 Apr 29 --- Fixed typo in structure for null input.
R. Sterner, 2009 Apr 29 --- Fixed single arg /unsort error.
R. Sterner, 2010 Apr 30 --- Converted arrays from () to [].
R. Sterner, 2010 May 09 --- Added keyword SEP_MERGED=sep.
Copyright (C) 2006, Johns Hopkins University/Applied Physics Laboratory
This software may be used, copied, or redistributed as long as it is not
sold and this copyright notice is reproduced on each copy made. This
routine is provided as is without any express or implied warranties
whatsoever. Other limitations apply as described in the file disclaimer.txt.