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

Home » Public Forums » archive » Re: help with relational operators
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
Re: help with relational operators [message #16179] Thu, 08 July 1999 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Dave (dmarshall@ivory.trentu.ca) 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
> ...
> dataFName='somefile.xdr'
> ...
> fileCheck=findfile(dataFName)
> if fileCheck eq '' then print, 'error: ', dataFName,' file not found'
>
> endrep until fileCheck ne ''
>
> % Expression must be a scalar in this context: <BYTE Array[1]>.
>
> 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[0] 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:

fileCheck=findfile(dataFName, Count=numFiles)
IF numFiles EQ 0 THEN print, 'error: ', dataFName,' file not found'

Then you don't have to worry about this quirk in IDL. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.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.]
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: xwindow question
Next Topic: help with relational operators

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

Current Time: Fri Oct 10 13:38:21 PDT 2025

Total time taken to generate the page: 4.00040 seconds