cedadev/cf-checker

Wrong detection of CF version when running on multiple files with different CF version

Opened this issue · 0 comments

When running the CF-Checker on multiple files with different CF versions using the auto-detection of the CF version (i.e. cfchecks -v auto file_cf_1_6.nc file_cf_1_7.nc), the CF-Checker will check for compatibility with the CF version of the first file (in this example CF-1.6 ) for all files given.

The issue is related to the following code snippet:

#if 'auto' version, check the CF version in the file
#if none found, use the default
if not self.version:
self.version = self.getFileCFVersion()
if not self.version:
self._add_warn("Cannot determine CF version from the Conventions attribute; checking against latest CF version: %s" % newest_version)
self.version = newest_version

The reason for this is that when the CF-Checker is being run on the first file, self.version is being set to a vaild CF version. For the second file, self.version is already set properly, so the code in the if-statement is not executed, causing the CF version to remain unchanged.

A simple fix would be to put the initialization of the CFChecker class into the file loop inside the main function. In this case, self.version gets reset every time a new file is processed and the CF version will be read from each file, but this could mess up the inst.get_total_counts(), but I haven't looked into it.