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

Even Rouault even.rouault at spatialys.com
Mon Apr 18 11:06:30 PDT 2022


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
> 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/429894fa/attachment.html>


More information about the gdal-dev mailing list