Checks if a supported file exists.
function isfilepresent ( file_path : string ) return_val [dimsizes(file_path)] : logical
A scalar string or a multi-dimensional array of strings containing the full or relative path to supported data files (Unix pathname string) for which to check presence on the filesystem.
The output of isfilepresent is a logical variable with the same dimension sizes as the input.
The function isfilepresent returns True for every element of file_path that is present and a supported file format, and False if not.
Note about backwards-incompatible change: as of NCL V6.2.1, this function will only return True if the file is present and it is a supported format recognized by addfile. To check for the existence of any other kind of file, use the new fileexists function.
The following code will determine if a HDF file named test.hdf exists:
if (isfilepresent("test.hdf")) f = addfile ("test.hdf", "r") end if
The following code will determine if each of a group of files exists.
Note that "xy.asc" actually exists in the "data/asc" directory, but isfilepresent returns False for this file because it is not a supported file. fileexists will return True for this particular file:
; specify data directory and get a list of all nc files in the directory cdfdir = ncargpath("ncarg") + "/data/cdf/" ascdir = ncargpath("ncarg") + "/data/asc/" ; list of files to check filenames = (/cdfdir + "bogus.nc", cdfdir + "ex01B1_uv300.hs.nc", cdfdir + "ocean.nc", \ ascdir + "xy.asc", ascdir + "bogus.asc"/) ; Which of "filenames" is present files_present = isfilepresent(filenames) files_exist = fileexists(filenames) print (files_present) print (files_exist)Output:
Variable: files_present Type: logical Total Size: 20 bytes 5 values Number of Dimensions: 1 Dimensions and sizes:  Coordinates: (0) False (1) True (2) True (3) False (4) False Variable: files_exist Type: logical Total Size: 20 bytes 5 values Number of Dimensions: 1 Dimensions and sizes:  Coordinates: (0) False (1) True (2) True (3) True (4) False
Here's an example that shows how to access a file being served by an OPeNDAP server, and to test if your version of NCL has OPeNDAP capability built into it:
begin ;---Path to file served by OPeNDAP server at NOAA url = "http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.dailyavgs/pressure/" filename = "air.1948.nc" exists = isfilepresent(url+filename) if(.not.exists) then print("OPeNDAP test unsuccessful.") print("Either the file doesn't exist, or NCL does") print("not have OPeNDAP cabilities on this system.") else f = addfile(url + filename,"r") vnames = getfilevarnames(f) print(vnames) ; should be (/"air","time","lon","lat","level"/) end if end