[Thread Prev][Thread Next][Index]

Re: [ferret_users] check if a particular file exists



Hi David,
You can use the SPAWN command, see "spawn, string variables" in the Users Guide index.

    yes? LET a = {"dummy", SPAWN:"ls myfile.nc"}
    yes? LET nfiles = `a,RETURN=IEND`
    yes? IF `nfiles EQ 2` THEN SET DATA myfile.nc

If the file exists then nfiles will be 2, otherwise it'll be 1.

Another possibility if you don't mind creating an error condition intentionally, is to SET MODE IGNORE_ERROR, try to open the file, and then check for the existence of the symbol RET_LAST_ERROR; this is described in the Version 6.0 release notes,
http://ferret.pmel.noaa.gov/Ferret/Documentation/Release_Notes/v600.html#fer_last_error

Ansley

David Wang wrote:
Hello Ferreters,

I'd like to make a conditional construct so that if a particular netcdf file exists in the local directory, open it, if not, do something else. this is quite trivial in MATLAB using exist function, but seems nontrivial for me in FERRET. Does anyone have any ideas?

Thanks,
David


-- 

~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~> 

Ansley Manke, NOAA/PMEL   ansley.b.manke@xxxxxxxx
7600 Sand Point Way NE, Seattle WA
Phone 206-526-6246,  FAX 206-526-6744


[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement