[gdal-dev] -if netCDF fails to read Matlab .mat files

Joaquim Manuel Freire Luís jluis at ualg.pt
Mon Apr 18 11:54:36 PDT 2022


I think the mail system refused the mat file in my previous mail. Let’s try with it zipped.


From: gdal-dev <gdal-dev-bounces at lists.osgeo.org> On Behalf Of Joaquim Manuel Freire Luís
Sent: Monday, April 18, 2022 7:50 PM
To: Even Rouault <even.rouault at spatialys.com>; gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] -if netCDF fails to read Matlab .mat files

Strange, I don’t see an HDF5 driver in my list of drivers but I do include it in the GDAL build.

$ gdalinfo --formats | grep HDF
  HDF4 -raster,multidimensional raster- (ros): Hierarchical Data Format Release 4
  HDF4Image -raster- (rw+): HDF4 Dataset

Also

$ gdalinfo "NETCDF:"U.mat
ERROR 4: NETCDF:U.mat: No such file or directory
gdalinfo failed - unable to open 'NETCDF:U.mat'.

I’m sending attached the U.mat file

From: Even Rouault <even.rouault at spatialys.com<mailto:even.rouault at spatialys.com>>
Sent: Monday, April 18, 2022 7:07 PM
To: Joaquim Manuel Freire Luís <jluis at ualg.pt<mailto:jluis at ualg.pt>>; gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Subject: Re: [gdal-dev] -if netCDF fails to read Matlab .mat files


Joaquim,

https://www.loc.gov/preservation/digital/formats/fdd/fdd000440.shtml mentions HDF5, but I don't know if it is HDF5-only or the HDF5 profile of netCDF 4.

From my tests trying to simulate the situation (I don't have a .mat file handy),

- if it is netCDF 3 file (non-HDF5), the netCDF driver should be able to open even with the .mat extension

- if it is netCDF 4 file,

    - and the netCDF and HDF5 drivers are present, the HDF5 driver will kick in. The reason is that there's no easy way to recognize a HDF5 file from a netCDF 4 from their header, so the netCDF driver has a white list of extensions (which doesn't include .mat) when it sees the HDF5 driver is there, since it knows it is a potential fallback

    - and only the netCDF driver is present, it will kick in

    - and only the HDF5 driver is present, it will kick in

So basically I don't reproduce your issue.

You should be able to force the NetCDF driver by prefixing "NETCDF:" to the filename (the -if flag only restricts drivers which are probed. it doesn't force a driver to accept a file)

Even


Le 18/04/2022 à 18:31, Joaquim Manuel Freire Luís a écrit :
Hi,

Matlab creates files in what they call the “mat” format (with a .mat extension) but which in fact are files in netCDF/HDF

And indeed we can read them … but only if renamed to .nc

Why is this failing?

$ gdalinfo -if netCDF windaa.mat
ERROR 4: `windaa.mat' not recognized as a supported file format.
gdalinfo failed - unable to open 'windaa.mat'.

But this works

$ gdalinfo windaa.nc
Driver: netCDF/Network Common Data Format
Files: windaa.nc
Size is 512, 512
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"windaa.nc":u
  SUBDATASET_1_DESC=[15x41x35] u (64-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"windaa.nc":v
  SUBDATASET_2_DESC=[15x41x35] v (64-bit floating-point)
…



Joaquim


_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

https://lists.osgeo.org/mailman/listinfo/gdal-dev

--

http://www.spatialys.com

My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220418/93ebbdb9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: U.mat.zip
Type: application/x-zip-compressed
Size: 42149 bytes
Desc: U.mat.zip
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220418/93ebbdb9/attachment-0001.bin>


More information about the gdal-dev mailing list