NCL Home > Documentation > Functions > File I/O, System tools


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.

Return value

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.

See Also

fileexists isfile


Example 1

The following code will determine if a HDF file named test.hdf exists:

  if (isfilepresent("test.hdf"))
    f = addfile ("test.hdf", "r")
  end if

Example 2

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 + "", cdfdir + "", cdfdir + "", \
                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)

Variable: files_present
Type: logical
Total Size: 20 bytes
            5 values
Number of Dimensions: 1
Dimensions and sizes:   [5]
(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:   [5]
(0)     False
(1)     True
(2)     True
(3)     True
(4)     False

Example 3

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:

;---Path to file served by OPeNDAP server at NOAA
  url      = ""
  filename = ""

  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.")
    f = addfile(url + filename,"r")
    vnames = getfilevarnames(f)
    print(vnames)     ; should be (/"air","time","lon","lat","level"/)
  end if