Contenu principal

Compare Schemas of HDF5 or NetCDF Files

Since R2026a

You can visually compare the schemas of HDF5 or netCDF files using the Comparison Tool. The schema includes the hierarchical structure of the data as well as attributes and metadata, but it does not include the actual data stored in the file. Open the Comparison Tool using the visdiff function.

Compare Schemas of HDF5 Files

Suppose you have three structurally similar HDF5 files: file_p.h5, file_f.h5, and file_ss.h5. Use the Comparison Tool to compare the schemas of file_p.h5 and file_f.h5. The only differences are in the chunk size, compression filter, and fill value for the DataTwo dataset.

visdiff file_p.h5 file_f.h5

Comparison Tool showing the differences between the schemas of file_p.h5 and file_f.h5

Next, compare the schemas of file_f.h5 and file_ss.h5. These two files have identical schemas.

visdiff file_f.h5 file_ss.h5

Comparison Tool showing that the schemas of file_f.h5 and file_ss.h5 have no differences

The Comparison Tool compares only the schemas of HDF5 files. It does not compare the values in the datasets contained in the files. For example, although the Comparison Tool showed no schematic differences between file_f.h5 and file_ss.h5, the two files have different values in their respective DataOne datasets.

file_f_DataOne = h5read("file_f.h5","/DataOne");
file_ss_DataOne = h5read("file_ss.h5","/DataOne");
f_ss_identical_DataOne = all(file_f_DataOne == file_ss_DataOne)
f_ss_identical_DataOne = logical
   0

To test whether two HDF5 files are identical (meaning they have identical schemas and identical data), use the Comparison Tool in binary mode.

visdiff("file_f.h5","file_ss.h5","binary")

Comparison Tool in binary mode showing that file_f.h5 and file_ss.h5 are different, with a link to show more details

Compare Schemas of NetCDF Files

You can also compare schemas of netCDF files using the Comparison Tool. For example, compare two netCDF files, file_p.nc and file_f.nc. The Comparison Tool shows that they have identical schemas.

visdiff file_p.nc file_f.nc

Comparison Tool showing that the schemas of file_p.nc and file_f.nc have no differences

Compare Schemas Among HDF5, NetCDF, and SOFA Files

In addition, you can compare the schemas of HDF5, netCDF-4, and SOFA files to each other. NetCDF-4 files and SOFA files are special types of HDF5 files, so all three types are comparable as HDF5 files.

For example, compare the schemas of an HDF5 file and a netCDF-4 file. The Comparison Tool shows that the file schemas are similar but that the netCDF-4 file contains additional datasets as well as additional group and dataset attributes.

visdiff file_p.h5 file_p.nc

Comparison Tool showing the differences between the schemas of file_p.h5 and file_p.nc

Compare Schemas of HDF5 Files to MAT Files

Because v7.3 MAT files are special types of HDF5 files, v7.3 MAT files can be compared to HDF5, netCDF-4, and SOFA files. If you use the Comparison Tool to compare a MAT file to a file of one of these types, only the schemas are compared. In contrast, when you use the Comparison Tool to compare two MAT files, the tool compares both the schema and the data within the files.

For example, compare the schemas of file_p.h5 and file_p.mat. The Comparison Tool shows that the file schemas are similar and that the MAT file contains additional dataset attributes.

visdiff file_p.h5 file_p.mat

Comparison Tool showing the differences between the schemas of file_p.h5 and file_p.mat

See Also

| |