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

Home » Public Forums » archive » string definition question
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
string definition question [message #33609] Tue, 14 January 2003 07:55
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Hello there,

Although I should probably know the answer to this, since all my IDL reference books have
been borrowed, hope you don't mind me asking here.

I'm a bit anal about argument checking in IDL. After establishing that the correct number
of arguments has been passed using:

n_arguments = 1
IF ( N_PARAMS() LT n_arguments ) THEN $
MESSAGE, 'Invalid number of arguments.', $
/NONAME, /NOPRINT


My standard method for checking string arguments (like filenames to read) is something
like:

IF ( N_ELEMENTS( FileNAME ) EQ 0 ) THEN BEGIN
MESSAGE, 'Input FileNAME argument not defined!', $
/NONAME, /NOPRINT

IF ( STRLEN( FileNAME ) EQ 0 ) THEN $
MESSAGE, 'Input FileNAME argument not defined!', $
/NONAME, /NOPRINT

If I pass a zero-length string, e.g. FileNAME='', the N_ELEMENTS() test passes so I always
test for a non-zero string length (it's happened). If I combine the two tests using AND,
then if the variable is undefined, the STRLEN() function generates an errors (since its
argument must be defined).

The above works great, but I have always felt that it should be unnecessary. Is there a
one-step method to test that the argument is actually defined AND that the string length
is not zero? Would the ARG_PRESENT function be useful here somehow? I read the on-line
manual, but I really don't grok the text.

Thanks for any info,

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7274
Fax:(301)763-8545
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: SPAWN command blocked in 5.3.1
Next Topic: Re: string definition question

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

Current Time: Wed Oct 08 19:14:36 PDT 2025

Total time taken to generate the page: 0.00504 seconds