[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with relational operators
- Subject: Re: help with relational operators
- From: davidf(at)dfanning.com (David Fanning)
- Date: Thu, 8 Jul 1999 14:55:18 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: Fanning Software Consulting
- References: <FEKIH6.DuI.A.email@example.com>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:15603
Dave (firstname.lastname@example.org) writes:
> I'm getting near wits end.
Yikes! Me, too, but for a completely different reason today. :-)
> repeat begin
> ; get user to input file name
> if fileCheck eq '' then print, 'error: ', dataFName,' file not found'
> endrep until fileCheck ne ''
> % Expression must be a scalar in this context: <BYTE Array>.
> I just want to verify the file exists before opening it.
> This gives my error message if file does not exist, but craps out if file
> does exist.
> help, fileCheck ne ''
> tells me it _is_ a scalar expression. ?
Whoops. What you don't know is that FINDFILE *always*
returns an array, even if there is only a single element
in it, as in this case. What you need in the IF statement
is a scalar not an array. You could do this:
if fileCheck eq '' then print, 'error: ', dataFName,' file not found'
But a better way to handle this is to use the COUNT
keyword to FINDFILE, like this:
IF numFiles EQ 0 THEN print, 'error: ', dataFName,' file not found'
Then you don't have to worry about this quirk in IDL. :-)
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: email@example.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Note: This follow-up was e-mailed to the cited author.]