If you use Matlab you can use the commands ncdisp and ncread. With the command ncdisp you can obtain information about the file (attributes, variables, dimensions, units, etc.). And with the command ncread you can extract data for a given variable.
I show you an example using Matlab. I downloaded the file ‘pr_day_CNRM-CM5_rcp45_r1i1p1_20260101-20301231.nc’ from the project CMIP5 (precipitation in 2026-2030 according to the RCP4.5 scenario and CNRM-CM5 model).
I save the file name
>> file = ‘pr_day_CNRM-CM5_rcp45_r1i1p1_20260101-20301231.nc’;
Then, to display the file properties:
Then you can know that the variables you are interested in are coded as lat (latitude), lon (longitude), time (time), and pr (precipitation). lat is a 128×1 vector, lon is a 256×1 vector, and time is a 1826×1 vector and pr is a 256x128x1826 array with the dimensions lon, lat, time.
With the following commands you can extract the longitude, latitude and time values of all the grid points:
>> longitude = ncread(file,’lon’);
>> latitude = ncread(file,’lat’);
>> time = ncread(file,’time’);
You can use the same instruction (with some additional input arguments) to extract precipitation data for a selection of coordinates and times:
vardata = ncread(source,varname,start,count,stride)
source is the file name
varname is the variable name
start is from where you want to start to read data for each dimension (in vector form)
count is how many data points do you want to read for each dimension (in vector form)
stride is the frequency of extraction data, i.e. each day, each two days, etc. (in vector form)
So, if you want to extract precipitation every day for the full period 2026-2030 between latitudes 39.9218ºN and 52.5286ºN, and between longitudes 0º and 11.25ºE you would have to type:
Precip = ncread(file,’pr’,[1 93 1], [9 10 Inf], [1 1 1]);
[1 93 1] is start, since longitude(1) = 0, latitude(93) = 39.9218, and you start at the first time measurement
[9 10 Inf] is count, since you want to extract data for 9 longitudes (longitude(9) = 11.25), for 10 latitudes (latitude(102) = 52.5286), and you use Inf to indicate you want all time points
[1 1 1] is stride, since you want to extract each longitude point, each latitude point and each time point
I hope this helps.