import os import netCDF4 as n4 def is_nc_file(filename,workDir): """ Checks if a file exists and is a NetCDF file. Args: filename: The file name with whole path. Returns: True if the file exists and is a NetCDF file, False otherwise. """ if not os.path.exists(filename): print("Warning: File " + filename + " does not exist") return False try: n4.Dataset(filename) return True except OSError: print("Warning: File " + filename + " is corrupted or unknown file format") with open(workDir + "/obs_log.txt","a") as obs_log: obs_log.write("Warning: File " + filename + " is corrupted or unknown file format\n") return False