NetCDF file created in Matlab is read differently by Julia?

I have a NetCDF file that is created using Matlab and it is composed of 'double" values of 1 and 0. I can read the values as they are without any issues inside Matlab.

However, when I tried to read it using Julia, their values all changed to 9.969209968386869e36.

Here is my code to read the nc file:

Using NCDatasets

# get the land mask (NetCDF file)
Path_mask  = "xxx";
FN_mask    = "";
File_mask  = joinpath(Path_mask, FN_mask);

data =
Dataset(File_mask,"r") do ds0
end # ds is closed

Anyone knows what is going one?

Apparently 9.969209968386869e36 has been used in various places as a default “fill value” for when the application hasn’t written data. (Perhaps originating with NCL Language Reference Guide: Variables ?) So this would explain where the value is coming from, but not why reading the file gives different results from Matlab.

You could start debugging by inspecting the structure of the file using
Matlab’s ncdisp and comparing to show(io, ::NCDatasets.Dataset).

If you want more specific help it would be best to post a self-contained example (maybe including the example NetCDF somewhere which can be downloaded) so people can run on their own computers and reproduce the problem.

1 Like

Do you have the ncdump command-line tool? If so, have a look at the file with that.

1 Like

Very strange. Did you make sure to close the NetCDF file inside MATLAB or is the session still running? Data might still be in cache…


Many thanks for the replies, All.

Here is an example nc file:

Many thanks. It turns out to be the cause. After I run netcdf.close(ncid). Things are normal now.

I’m surprised to see that closing the file timely is so important.

Many thanks!