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

Home » Public Forums » archive » Re: string definition question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: string definition question [message #33607 is a reply to message #33606] Tue, 14 January 2003 10:13 Go to previous messageGo to previous message
btupper is currently offline  btupper
Messages: 55
Registered: January 2002
Member
On Tue, 14 Jan 2003 10:55:24 -0500, Paul van Delst
<paul.vandelst@noaa.gov> wrote:

> 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).
>
Hi Paul,

I can't think how to get away from the two step test. Usually the
ARG_PRESENT() test is reserved for optional output keywords. I would
stick to N_ELEMENTS() and N_PARAMS()

You could squish the two statements into one - but there are still two
tests involved.

If (n_elements(FileName) NE 0) Then $
If (StrLen(FileName[0]) EQ 0) Then $
Print, "Ain't nuttin here, Paul" Else $
Print, "Here's the string" + fileNAME[0] Else $
Print, "fileNAME argument is required, ya' know"

Ben
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: string definition question
Next Topic: Re: 2-D Density Plots

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

Current Time: Wed Oct 08 19:15:45 PDT 2025

Total time taken to generate the page: 0.00411 seconds