PDA

View Full Version : INQUIRE statement


W.E.T.
04-29-2004, 11:32 AM
Hi,

I was just wondering if anyone knows what is wrong with my following statement. I am trying to see if a file exsists in the current directory:

The declaration of the variables are as follows:


character*20 file
character seq*1, fmt*1
logical ex, opnd
...now here is my source for inquiring:

inquire (file=file,exsist=ex,opened=opnd,
>sequential=seq,formatted=fmt)


if (ex.and..not..opnd) then
if (seq.eq.'y'.and.fmt.eq.'y') then
open (11,file=file,form='formatted',status='old')
endif
endif
... when I compile this, I recieve the following:

Missing or invalid keyword
Thanks

Nick

W.E.T.
04-29-2004, 11:36 AM
Sorry, here is the main bit of coding again:


inquire (file=file,exsist=ex,opened=opnd,
>sequential=seq,formatted=fmt)

if (ex.and..not.opnd) then
if (seq.eq.'y'.and.fmt.eq.'y') then
open (11,file=file,form='formatted',status='old')
endif
endif

Thanks

tzeis
05-05-2004, 10:16 PM
There are some subtleties to using INQUIRE, namely for some inquiries to succeed, the file has to be open. Your first if statement is probably ok, because you can test for existence and open status with the file closed. To test for file characteristics, the file almost always has to be open, and even then, the test only tells you about how you opened it. There is really nothing in a file that identifies it as being "sequential" or "formatted", these characteristics are more associated with how you have attached yourself to the file. I would lose the second if statement, and just go ahead and open the file at that point.