SlideShare a Scribd company logo
A quick guide on how to use Matlab netCDF functions
Prepared by HP Huang (hp.huang@asu.edu), Sept 2009. Revised March 2015. Please email HPH for
any questions/comments.
A netCDF file contains two parts: A "header" that describes the names, dimensions, etc., of the
variables stored in the file, and the main body that contains the real data. To process a netCDF file, we
need to first extract the information in the header and determine what portion/segment of the data we
want to use. This is usually done by using a set of stand-alone tools. This is, in fact, the more tedious
task which we will discuss in Part (A). Once the content of a netCDF file is known, it is rather
straightforward to read the data as will be discussed in Part (B).
(A) Inspect the content of a netCDF file
We will use the netCDF data file, precip.mon.ltm.nc, as an example to explain how the Matlab
functions work. This file, extracted and downloaded from the the NOAA ESRL-PSD web portal
(www.esrl.noaa.gov/psd), contains the CMAP gridded data for the long-term mean of monthly
precipitation for the global domain. It contains the values of precipitation rate on a regular longitude-
latitude grid for the climatological means for January, February, ..., December.
Step 0: Display/check the header of the netCDF file
ncdisp('precip.mon.ltm.nc')
The output is listed in Appendix A.
Remark: The ncdisp command "dumps" out the whole header, which contains the essential information
about the variables and their dimensions in the netCDF file. Running ncdisp is equivalent to running
"ncdump -c" (see Appendix B) on Linux-based platforms. It is strongly recommended that the
information in the header be examined before one uses the data in a netCDF file. In fact, just by
carefully inspecting the header, one can skip many steps discussed in Step 2-4 in this section.
Step 1: Open the file
ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE')
Remark: This command "opens" a netCDF file named precip.mon.ltm.nc and assigns a file number to
it. This file number is the sole output of the function and is put into our variable, ncid1, for later uses.
The option 'NC_NOWRITE' designates that the file is read-only (that is what we need for now).
Steps 2-4 are often not necessary if one has already obtained the needed information about
specific variables by running ncdisp in Step 0.
Step 2: Inspect the number of variables and number of dimensions, etc., in the file
[ndim, nvar, natt, unlim] = netcdf.inq(ncid1)
ndim = 3
1
nvar = 4
natt = 6
unlim = 2
Remark: After opening a file and obtaining its "file number", we next inquire what's in the file. The
output of the function, netcdf.inq, is a four-element array that contains the number of dimension,
number of variable, number of attribute, etc. (Let's focus on the first two elements for now.) From those
outputs, we learned that the file, "precip.mon.ltm.nc", contains 4 variables (nvar = 4) and maximum of
3 dimensions (ndim = 3).
Step 3: Extract further information for each "dimension"
[dimname, dimlength] = netcdf.inqDim(ncid1, 0)
dimname = lon
dimlength = 144
[dimname, dimlength] = netcdf.inqDim(ncid1, 1)
dimname = lat
dimlength = 72
[dimname, dimlength] = netcdf.inqDim(ncid1, 2)
dimname = time
dimlength = 12
Remark: From Step 2, we learned that there can be maximum of three dimensions for any variable
stored in 'precip.mon.ltm.nc'. We then call the function, netcdf.inqDim(ncid, dimid), to ask about the
detail of each dimension, one at a time. Note that the parameter, dimid, runs from 0 to 2 instead of 1
to 3 (dimension number zero, dimid = 0, corresponds to the 1st dimension; dimension number one,
dimid = 1, corresponds to the 2nd dimension, and so on). This is because Matlab netCDF utilities
adopt the convention of C language, in which the counting of numbers often starts from zero instead of
one. Here, we stop at dimension number 2 (or, the 3rd dimension) because from Step 2 we already
determined that the maximum number of dimension is 3. From this step, we know that the coordinate
for the first dimension is stored in an array called "lon" with 144 elements, the 2nd dimension is "lat"
with 72 elements, and the 3rd dimension is "time" with 12 elements.
Step 4: Extract further information for each variable
[varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 0)
varname = lat
2
xtype = 5
dimid = 1
natt = 3
Remark: In this example, we first extract the name, dimension, etc., of the first variable. Again, for this
function, netcdf.inqVar(ncid1, varid), the parameter "varid" starts from 0 instead of 1. This is a
convention adopted from C language; See remarks for Step 3. The outcome tells us that the 1st
variable is named "lat". It is of type "5" which translates to "float" or "real". (The Matlab
documentation provided by mathworks.com does not have the detail on this point, but the definition of
xtype is available from the documentation for the C interface for netCDF; See p. 41 of that
documentation. Some commonly encountered types are 2 = character, 3 = short integer, 4 = integer, 5
= real, and 6 = double.) Note that if one simply reads the header obtained by running ncdisp in Step 0,
one would immediately see that the "lat" variable is of "real" or "float" type.
The "dimid = 1" in the output tells us that the variable "lat" is a one-dimensional array (because
dimid is a single number, not an array) and the coordinate in that dimension is defined by
"dimension number 1". Recall that in Step 3 the comamnd, [dimname, dimlength] =
netcdf.inqDim(ncid1, 1), returned dimname = lat, dimlength = 72. Therefore, the variable "lat" is an
array with 72 elements, and the coordinate for these 72 elements are defined by the dimension, "lat",
which itself has 72 elements. (Here, "lat" is both a variable and a dimension or coordinate. If this
sounds confusing, keep reading and it will clear later.) Let's not worry about the 4th parameter
("attribution") for now.
[varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 1)
varname = lon
xtype = 5
dimid = 0
natt = 3
Remark: We find that the second variable is called "lon". It is of "real" type. It is a one-dimensional
array with its coordinate defined by "dimension number zero", i.e., the 1st dimension or "lon", with 144
elements. Again, "lon" is both a "variable" and a "dimension" (or coordinate).
[varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 2)
varname = time
xtype = 6
dimid = 2
3
natt = 6
Remark: The third variable is called "time". It is of "double" type (xtype = 6). It is a one-dimensional
array with its coordinate defined by "dimension number 2", i.e., the 3rd dimension or "time", with 12
elements. Again, "time" is both a "variable" and a "dimension" (or coordinate). (This is very common
of a netCDF file.)
[varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 3)
varname = precip
xtype = 5
dimid = 0, 1, 2
natt = 14
Remark: We now obtain the information of the 4th and final variable. (We know there are only 4
variables in this file because nvar = 4 in Step 2.) It is named "precip". It is of "real" type. It is a three-
dimensional variable, because dimid = [0, 1, 2], an array with three elements. Moreover, the 1st
dimension corresponds to "dimension number zero" given by Step 3, the 2nd dimension corresponds to
"dimension number 1", and the third dimension corresponds to "dimension number 2". Therefore, the
variable "precip" has the dimension of (144, 72, 12), with total of 144x72x12 elements of real numbers.
The coordinates for the 1st, 2nd, and 3rd dimensions are defined by lon(144), lat(72), and time(12).
Summary
From the above, we learned that there are four variables in the netCDF file, "lon", "lat", "time", and
"precip". The first three are there only to provide the coordinate (or "metadata") for the 4th variable,
which contains the real data that we want to use. Symbolically, the 4th variable is
precip : Pi, j,t k , i = 1-144, j = 1-72, and k = 1-12 ,
and the first three are
lat :  j , j = 1-72 lon : i , i = 1-144 time : tk , k = 1-12
The arrangement of the block of data for "precip" is illustrated in Fig. 1.
4
Fig. 1
Here, we use the "normal" convention with each of the indices, i, j, and k, starting from 1, whereas the
Matlab netCDF functions adopt C convention such that the counting starts from zero. Figure 2 is a
slightly modified diagram that illustrates the actual numbers that we should use to extract the data using
the Matlab functions.
Fig. 2
5
1 2 3 4 144
lon
1
2
3
72
lat
1
2
3
12
tim
e
FebruaryMarch
January
0 1 2 3 143
0
1
71
0
1
2
112
(B) Read a variable from the netCDF file
From Part (A), we now know the content of the netCDF file. We will next use some examples to
illustrate how to read a selected variable, or a "subsection" of a variable, from the file. This is generally
a very straightforward task and only involve calling the function, netcdf.getVar, in a one-line
command. (Read the documentation for that function at mathworks.com. It is useful.)
Example 1: Read the content of the variable "lat" (this is the latitude for the precipitation data)
ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE');
lat1 = netcdf.getVar(ncid1,0,0,72)
Result:
88.7500
86.2500
83.7500
81.2500
78.7500
76.2500
...
...
-81.2500
-83.7500
-86.2500
-88.7500
Remark: The first line of command opens the file and assigns it a file number, which is returned to
ncid1. In the second line, lat1 = netcdf.getVar(ncid1, varid, start, count), we choose
● ncid1 as the outcome from first line of code, so we know that the file we will be using is
"precip.mon.ltm.nc"
● varid = 0, which means we read variable number zero, or the 1st variable, which is "lat", a real array
with 72 elements - see Step 4 in Part A. As always, remember that Matlab netCDF functions adopt the
convention of C language: The counting starts from zero instead of one. See further remark at bottom
of Step 3 in Part A.
● start = 0, which means we read the segment of the variable starting from its 1st element. (Again,
remember that counting starts from zero.)
● count = 72, which means we read total of 72 elements, starting from the 1st element (as defined by
start = 0). In other words, we read the array, [lat(1), lat(2), lat(3), ..., lat(71), lat(72)], and put it into our
own variable, lat1, in the left hand side. As Matlab dumps the content of lat1, we see that the contents
of "lat" in the netCDF file are [88.75, 86.25, 83.75, ..., -86.25, -88.75]. These are the latitude (from
88.75°N to 88.75°S) for the precipitation data.
6
Example 2: Read the full 144 x 72 global precipitation field for time = 1 (i.e., January climatology),
then make a contour plot of it
ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE');
precJanuary = netcdf.getVar(ncid1,3,[0 0 0],[144 72 1]);
lon1 = netcdf.getVar(ncid1,1,0,144);
lat1 = netcdf.getVar(ncid1,0,0,72);
for p = 1:144
for q = 1:72
% -- the following 3 lines provides a quick way to remove missing values --
if abs(precJanuary(p,q)) > 99
precJanuary(p,q) = 0;
end
% ----------------------------------------------------------------
map1(q,p) = precJanuary(p,q);
end
end
contour(lon1,lat1,map1)
Result:
7
Remarks: Only the first 4 lines of the code are related to reading the netCDF file. The rest are
commands for post-processing and plotting the data. In the second line,
PrecJanuary = netcdf.getVar(ncid1, varid, start, count) ,
we choose ncid1 from the outcome of the first line of code, so we know that the file we are using is
"precip.mon.ltm.nc". In addition, varid = 3, which means we read the 4th variable, "precip"; start = [0
0 0], which indicates that we read the 1st, 2nd, and 3rd dimension from i = 0, j = 0, and k = 0 as
illustrated in Fig.2; count = [144 72 1], which indicates that we actually read i = 0-143 (the total count
of grid point is 144), j = 0-71 (total count is 72), and k = 0-0 (total count is 1) in Fig. 2 (which
correspond to i = 1-144, j = 1-72, k = 1-1 in Fig. 1). Essentially, we just cut a 144 x 72 slice of the data
with k = 1.
Example 3: Read the full 144 x 72 global precipitation field for time = 1 (i.e., January climatology),
then make a color+contour plot of it
ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE');
precJanuary = netcdf.getVar(ncid1,3,[0 0 0],[144 72 1],'double');
lon1 = netcdf.getVar(ncid1,1,0,144);
lat1 = netcdf.getVar(ncid1,0,0,72);
for p = 1:144
for q = 1:72
if abs(precJanuary(p,q)) > 99
precJanuary(p,q) = 0;
end
map1(q,p) = precJanuary(p,q);
end
end
pcolor(lon1,lat1,map1)
shading interp
colorbar
hold on
contour(lon1,lat1,map1,'k-')
Result:
8
Remark: This example is almost identical to Example 2, but note that in the second line,
PrecJanuary = netcdf.getVar(ncid1, varid, start, count, output_type),
we have an extra parameter, output_type = 'double'. This helps convert the outcome (which is put
into our variable, PrecJanuary) from "real" to "double" type. This is needed in this example, because
the function, pcolor (for making a color map) requires that its input be of "double" type. [Typically,
for a 32-bit machine, variables of "real" and "double" types contain 4 bytes (or 32 bits) and 8 bytes (or
64 bits), respectively. This detail is not critical.] Without the extra parameter for the conversion, as is
the case with Example 2, Matlab would return the values of the variable in its original type, which is
"real". (We know it from Step 4 in Part (A) that xtype = 5 for this variable.)
Appendix A. The header of a netCDF file as the output from the example in Step 0
Executing the command, ncdisp('precip.mon.ltm.nc'), would produce the following detailed output
which is the header of the netCDF file, precip.mon.ltm.nc.
Source:
m:small_projectprecip.mon.ltm.nc
Format:
classic
Global Attributes:
Conventions = 'COARDS'
title = 'CPC Merged Analysis of Precipitation (excludes NCEP Reanalysis)'
9
history = 'created 12/98 by CASData version v207
'
platform = 'Analyses'
source = 'ftp ftp.cpc.ncep.noaa.gov precip/cmap/monthly'
documentation = 'http://www.cdc.noaa.gov/cdc/data.cmap.html'
Dimensions:
lon = 144
lat = 72
time = 12 (UNLIMITED)
Variables:
lat
Size: 72x1
Dimensions: lat
Datatype: single
Attributes:
units = 'degrees_north'
actual_range = [8.88e+01 -8.88e+01]
long_name = 'Latitude'
lon
Size: 144x1
Dimensions: lon
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'Longitude'
actual_range = [1.25e+00 3.59e+02]
time
Size: 12x1
Dimensions: time
Datatype: double
Attributes:
units = 'hours since 1-1-1 00:00:0.0'
long_name = 'Time'
delta_t = '0000-01-00 00:00:00'
actual_range = [0.00e+00 8.02e+03]
avg_period = '0000-01-00 00:00:00'
ltm_range = [1.73e+07 1.75e+07]
precip
Size: 144x72x12
Dimensions: lon,lat,time
Datatype: single
Attributes:
long_name = 'Average Monthly Rate of Precipitation'
valid_range = [0.00e+00 5.00e+01]
units = 'mm/day'
add_offset = 0
scale_factor = 1
actual_range = [0.00e+00 3.41e+01]
10
missing_value = -9.97e+36
precision = 3.28e+04
least_significant_digit = 2
var_desc = 'Precipitation'
dataset = 'CPC Merged Analysis of Precipitation Standard'
level_desc = 'Surface'
statistic = 'Mean'
parent_stat = 'Mean'
Appendix B: Obtaining the header using Linux-based utilities
The header of a netCDF file can also be extracted by using Linux-based utilities. The most commonly
used tool is "ncdump". The Linux equivalent of running "ncdisp('precip.mon.ltm.nc') is
ncdump -c precip.mon.ltm.nc
Note that the "-c" option is essential. With it, the command only dumps the header. Without it, the
command will dump all data in the netCDF file.
Result:
netcdf precip.mon.ltm {
dimensions:
lon = 144 ;
lat = 72 ;
time = UNLIMITED ; // (12 currently)
variables:
float lat(lat) ;
lat:units = "degrees_north" ;
lat:actual_range = 88.75f, -88.75f ;
lat:long_name = "Latitude" ;
float lon(lon) ;
lon:units = "degrees_east" ;
lon:long_name = "Longitude" ;
lon:actual_range = 1.25f, 358.75f ;
double time(time) ;
time:units = "hours since 1-1-1 00:00:0.0" ;
time:long_name = "Time" ;
time:delta_t = "0000-01-00 00:00:00" ;
time:actual_range = 0., 8016. ;
time:avg_period = "0000-01-00 00:00:00" ;
time:ltm_range = 17338824., 17530944. ;
float precip(time, lat, lon) ;
precip:long_name = "Average Monthly Rate of Precipitation" ;
precip:valid_range = 0.f, 50.f ;
precip:units = "mm/day" ;
precip:add_offset = 0.f ;
precip:scale_factor = 1.f ;
precip:actual_range = 0.f, 34.05118f ;
11
precip:missing_value = -9.96921e+36f ;
precip:precision = 32767s ;
precip:least_significant_digit = 2s ;
precip:var_desc = "Precipitation" ;
precip:dataset = "CPC Merged Analysis of Precipitation Standard" ;
precip:level_desc = "Surface" ;
precip:statistic = "Mean" ;
precip:parent_stat = "Mean" ;
// global attributes:
:Conventions = "COARDS" ;
:title = "CPC Merged Analysis of Precipitation (excludes NCEP Reanalysis)" ;
:history = "created 12/98 by CASData version v207n",
"" ;
:platform = "Analyses" ;
:source = "ftp ftp.cpc.ncep.noaa.gov precip/cmap/monthly" ;
:documentation = "http://www.cdc.noaa.gov/cdc/data.cmap.html" ;
data:
lat = 88.75, 86.25, 83.75, 81.25, 78.75, 76.25, 73.75, 71.25, 68.75, 66.25,
63.75, 61.25, 58.75, 56.25, 53.75, 51.25, 48.75, 46.25, 43.75, 41.25,
38.75, 36.25, 33.75, 31.25, 28.75, 26.25, 23.75, 21.25, 18.75, 16.25,
13.75, 11.25, 8.75, 6.25, 3.75, 1.25, -1.25, -3.75, -6.25, -8.75, -11.25,
-13.75, -16.25, -18.75, -21.25, -23.75, -26.25, -28.75, -31.25, -33.75,
-36.25, -38.75, -41.25, -43.75, -46.25, -48.75, -51.25, -53.75, -56.25,
-58.75, -61.25, -63.75, -66.25, -68.75, -71.25, -73.75, -76.25, -78.75,
-81.25, -83.75, -86.25, -88.75 ;
lon = 1.25, 3.75, 6.25, 8.75, 11.25, 13.75, 16.25, 18.75, 21.25, 23.75,
26.25, 28.75, 31.25, 33.75, 36.25, 38.75, 41.25, 43.75, 46.25, 48.75,
51.25, 53.75, 56.25, 58.75, 61.25, 63.75, 66.25, 68.75, 71.25, 73.75,
76.25, 78.75, 81.25, 83.75, 86.25, 88.75, 91.25, 93.75, 96.25, 98.75,
101.25, 103.75, 106.25, 108.75, 111.25, 113.75, 116.25, 118.75, 121.25,
123.75, 126.25, 128.75, 131.25, 133.75, 136.25, 138.75, 141.25, 143.75,
146.25, 148.75, 151.25, 153.75, 156.25, 158.75, 161.25, 163.75, 166.25,
168.75, 171.25, 173.75, 176.25, 178.75, 181.25, 183.75, 186.25, 188.75,
191.25, 193.75, 196.25, 198.75, 201.25, 203.75, 206.25, 208.75, 211.25,
213.75, 216.25, 218.75, 221.25, 223.75, 226.25, 228.75, 231.25, 233.75,
236.25, 238.75, 241.25, 243.75, 246.25, 248.75, 251.25, 253.75, 256.25,
258.75, 261.25, 263.75, 266.25, 268.75, 271.25, 273.75, 276.25, 278.75,
281.25, 283.75, 286.25, 288.75, 291.25, 293.75, 296.25, 298.75, 301.25,
303.75, 306.25, 308.75, 311.25, 313.75, 316.25, 318.75, 321.25, 323.75,
326.25, 328.75, 331.25, 333.75, 336.25, 338.75, 341.25, 343.75, 346.25,
348.75, 351.25, 353.75, 356.25, 358.75 ;
time = 0, 744, 1416, 2160, 2880, 3624, 4344, 5088, 5832, 6552, 7296, 8016 ;
}
______________________________________
Quick exercise: Based on the CMAP data set, what are the climatological values of the precipitation
rate for January, February, ..., December at the grid point that is closest to (1) Phoenix, AZ, and (2)
Seattle, WA? Make a plot of the results.
12

More Related Content

What's hot

BDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part IIBDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part II
David Lauzon
 
IBM Spark Meetup - RDD & Spark Basics
IBM Spark Meetup - RDD & Spark BasicsIBM Spark Meetup - RDD & Spark Basics
IBM Spark Meetup - RDD & Spark Basics
Satya Narayan
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
Apache spark Intro
Apache spark IntroApache spark Intro
Apache spark Intro
Tudor Lapusan
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
Patrick Wendell
 
Real Time Data Processing Using Spark Streaming
Real Time Data Processing Using Spark StreamingReal Time Data Processing Using Spark Streaming
Real Time Data Processing Using Spark Streaming
Hari Shreedharan
 
Resilient Distributed Datasets
Resilient Distributed DatasetsResilient Distributed Datasets
Resilient Distributed Datasets
Alessandro Menabò
 
Spark 计算模型
Spark 计算模型Spark 计算模型
Spark 计算模型
wang xing
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
Anton Kirillov
 
Large volume data analysis on the Typesafe Reactive Platform
Large volume data analysis on the Typesafe Reactive PlatformLarge volume data analysis on the Typesafe Reactive Platform
Large volume data analysis on the Typesafe Reactive Platform
Martin Zapletal
 
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
Martin Zapletal
 
The Hadoop Ecosystem
The Hadoop EcosystemThe Hadoop Ecosystem
The Hadoop Ecosystem
Mathias Herberts
 
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep diveApache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Sachin Aggarwal
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
Duyhai Doan
 
Apache Spark overview
Apache Spark overviewApache Spark overview
Apache Spark overview
DataArt
 
Advanced goldengate training ⅰ
Advanced goldengate training ⅰAdvanced goldengate training ⅰ
Advanced goldengate training ⅰ
oggers
 
Apache Spark
Apache Spark Apache Spark
Apache Spark
Majid Hajibaba
 
Apache Spark
Apache SparkApache Spark
Apache Spark
Uwe Printz
 
Openstack For Beginners
Openstack For BeginnersOpenstack For Beginners
Openstack For Beginners
cpallares
 
DTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsDTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime Internals
Cheng Lian
 

What's hot (20)

BDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part IIBDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part II
 
IBM Spark Meetup - RDD & Spark Basics
IBM Spark Meetup - RDD & Spark BasicsIBM Spark Meetup - RDD & Spark Basics
IBM Spark Meetup - RDD & Spark Basics
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
 
Apache spark Intro
Apache spark IntroApache spark Intro
Apache spark Intro
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
 
Real Time Data Processing Using Spark Streaming
Real Time Data Processing Using Spark StreamingReal Time Data Processing Using Spark Streaming
Real Time Data Processing Using Spark Streaming
 
Resilient Distributed Datasets
Resilient Distributed DatasetsResilient Distributed Datasets
Resilient Distributed Datasets
 
Spark 计算模型
Spark 计算模型Spark 计算模型
Spark 计算模型
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
 
Large volume data analysis on the Typesafe Reactive Platform
Large volume data analysis on the Typesafe Reactive PlatformLarge volume data analysis on the Typesafe Reactive Platform
Large volume data analysis on the Typesafe Reactive Platform
 
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
Large volume data analysis on the Typesafe Reactive Platform - Big Data Scala...
 
The Hadoop Ecosystem
The Hadoop EcosystemThe Hadoop Ecosystem
The Hadoop Ecosystem
 
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep diveApache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
Apache Spark overview
Apache Spark overviewApache Spark overview
Apache Spark overview
 
Advanced goldengate training ⅰ
Advanced goldengate training ⅰAdvanced goldengate training ⅰ
Advanced goldengate training ⅰ
 
Apache Spark
Apache Spark Apache Spark
Apache Spark
 
Apache Spark
Apache SparkApache Spark
Apache Spark
 
Openstack For Beginners
Openstack For BeginnersOpenstack For Beginners
Openstack For Beginners
 
DTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsDTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime Internals
 

Similar to Matlab netcdf guide

study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
PJS KUMAR
 
Es272 ch1
Es272 ch1Es272 ch1
Extending ns
Extending nsExtending ns
Extending ns
yogiinmood
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
Anil Sagar
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
Ranjan Pal
 
WVKULAK13_submission_14
WVKULAK13_submission_14WVKULAK13_submission_14
WVKULAK13_submission_14
Max De Koninck
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
Barry DeCicco
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
Andrey Skripnikov
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDA
prithan
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
suthi
 
OpenSees: modeling and performing static analysis
OpenSees: modeling and  performing static analysisOpenSees: modeling and  performing static analysis
OpenSees: modeling and performing static analysis
Dhanaji Chavan
 
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in NagiosNagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
Ganesan Narayanasamy
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
 
Lect1.pptx
Lect1.pptxLect1.pptx
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
Oswald Campesato
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
Kumar
 

Similar to Matlab netcdf guide (20)

study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
Es272 ch1
Es272 ch1Es272 ch1
Es272 ch1
 
Extending ns
Extending nsExtending ns
Extending ns
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
WVKULAK13_submission_14
WVKULAK13_submission_14WVKULAK13_submission_14
WVKULAK13_submission_14
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDA
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
 
OpenSees: modeling and performing static analysis
OpenSees: modeling and  performing static analysisOpenSees: modeling and  performing static analysis
OpenSees: modeling and performing static analysis
 
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in NagiosNagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 

More from Gilberto Pimentel

Capítulo 6.2 2014_pos
Capítulo 6.2 2014_posCapítulo 6.2 2014_pos
Capítulo 6.2 2014_pos
Gilberto Pimentel
 
Capítulo 6.1 2014_pos
Capítulo 6.1 2014_posCapítulo 6.1 2014_pos
Capítulo 6.1 2014_pos
Gilberto Pimentel
 
Capítulo 5 2014_pos
Capítulo 5 2014_posCapítulo 5 2014_pos
Capítulo 5 2014_pos
Gilberto Pimentel
 
Capítulo 3 2014_pos
Capítulo 3 2014_posCapítulo 3 2014_pos
Capítulo 3 2014_pos
Gilberto Pimentel
 
Capítulo 3 2014_pos proncipios da radiacao eletromagnetica
Capítulo 3 2014_pos proncipios da radiacao eletromagneticaCapítulo 3 2014_pos proncipios da radiacao eletromagnetica
Capítulo 3 2014_pos proncipios da radiacao eletromagnetica
Gilberto Pimentel
 
Capítulo 1 2014_pos
Capítulo 1 2014_posCapítulo 1 2014_pos
Capítulo 1 2014_pos
Gilberto Pimentel
 
Capítulo 3 2014_pos
Capítulo 3 2014_posCapítulo 3 2014_pos
Capítulo 3 2014_pos
Gilberto Pimentel
 
Atmosfera
AtmosferaAtmosfera

More from Gilberto Pimentel (8)

Capítulo 6.2 2014_pos
Capítulo 6.2 2014_posCapítulo 6.2 2014_pos
Capítulo 6.2 2014_pos
 
Capítulo 6.1 2014_pos
Capítulo 6.1 2014_posCapítulo 6.1 2014_pos
Capítulo 6.1 2014_pos
 
Capítulo 5 2014_pos
Capítulo 5 2014_posCapítulo 5 2014_pos
Capítulo 5 2014_pos
 
Capítulo 3 2014_pos
Capítulo 3 2014_posCapítulo 3 2014_pos
Capítulo 3 2014_pos
 
Capítulo 3 2014_pos proncipios da radiacao eletromagnetica
Capítulo 3 2014_pos proncipios da radiacao eletromagneticaCapítulo 3 2014_pos proncipios da radiacao eletromagnetica
Capítulo 3 2014_pos proncipios da radiacao eletromagnetica
 
Capítulo 1 2014_pos
Capítulo 1 2014_posCapítulo 1 2014_pos
Capítulo 1 2014_pos
 
Capítulo 3 2014_pos
Capítulo 3 2014_posCapítulo 3 2014_pos
Capítulo 3 2014_pos
 
Atmosfera
AtmosferaAtmosfera
Atmosfera
 

Recently uploaded

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 

Recently uploaded (20)

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 

Matlab netcdf guide

  • 1. A quick guide on how to use Matlab netCDF functions Prepared by HP Huang (hp.huang@asu.edu), Sept 2009. Revised March 2015. Please email HPH for any questions/comments. A netCDF file contains two parts: A "header" that describes the names, dimensions, etc., of the variables stored in the file, and the main body that contains the real data. To process a netCDF file, we need to first extract the information in the header and determine what portion/segment of the data we want to use. This is usually done by using a set of stand-alone tools. This is, in fact, the more tedious task which we will discuss in Part (A). Once the content of a netCDF file is known, it is rather straightforward to read the data as will be discussed in Part (B). (A) Inspect the content of a netCDF file We will use the netCDF data file, precip.mon.ltm.nc, as an example to explain how the Matlab functions work. This file, extracted and downloaded from the the NOAA ESRL-PSD web portal (www.esrl.noaa.gov/psd), contains the CMAP gridded data for the long-term mean of monthly precipitation for the global domain. It contains the values of precipitation rate on a regular longitude- latitude grid for the climatological means for January, February, ..., December. Step 0: Display/check the header of the netCDF file ncdisp('precip.mon.ltm.nc') The output is listed in Appendix A. Remark: The ncdisp command "dumps" out the whole header, which contains the essential information about the variables and their dimensions in the netCDF file. Running ncdisp is equivalent to running "ncdump -c" (see Appendix B) on Linux-based platforms. It is strongly recommended that the information in the header be examined before one uses the data in a netCDF file. In fact, just by carefully inspecting the header, one can skip many steps discussed in Step 2-4 in this section. Step 1: Open the file ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE') Remark: This command "opens" a netCDF file named precip.mon.ltm.nc and assigns a file number to it. This file number is the sole output of the function and is put into our variable, ncid1, for later uses. The option 'NC_NOWRITE' designates that the file is read-only (that is what we need for now). Steps 2-4 are often not necessary if one has already obtained the needed information about specific variables by running ncdisp in Step 0. Step 2: Inspect the number of variables and number of dimensions, etc., in the file [ndim, nvar, natt, unlim] = netcdf.inq(ncid1) ndim = 3 1
  • 2. nvar = 4 natt = 6 unlim = 2 Remark: After opening a file and obtaining its "file number", we next inquire what's in the file. The output of the function, netcdf.inq, is a four-element array that contains the number of dimension, number of variable, number of attribute, etc. (Let's focus on the first two elements for now.) From those outputs, we learned that the file, "precip.mon.ltm.nc", contains 4 variables (nvar = 4) and maximum of 3 dimensions (ndim = 3). Step 3: Extract further information for each "dimension" [dimname, dimlength] = netcdf.inqDim(ncid1, 0) dimname = lon dimlength = 144 [dimname, dimlength] = netcdf.inqDim(ncid1, 1) dimname = lat dimlength = 72 [dimname, dimlength] = netcdf.inqDim(ncid1, 2) dimname = time dimlength = 12 Remark: From Step 2, we learned that there can be maximum of three dimensions for any variable stored in 'precip.mon.ltm.nc'. We then call the function, netcdf.inqDim(ncid, dimid), to ask about the detail of each dimension, one at a time. Note that the parameter, dimid, runs from 0 to 2 instead of 1 to 3 (dimension number zero, dimid = 0, corresponds to the 1st dimension; dimension number one, dimid = 1, corresponds to the 2nd dimension, and so on). This is because Matlab netCDF utilities adopt the convention of C language, in which the counting of numbers often starts from zero instead of one. Here, we stop at dimension number 2 (or, the 3rd dimension) because from Step 2 we already determined that the maximum number of dimension is 3. From this step, we know that the coordinate for the first dimension is stored in an array called "lon" with 144 elements, the 2nd dimension is "lat" with 72 elements, and the 3rd dimension is "time" with 12 elements. Step 4: Extract further information for each variable [varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 0) varname = lat 2
  • 3. xtype = 5 dimid = 1 natt = 3 Remark: In this example, we first extract the name, dimension, etc., of the first variable. Again, for this function, netcdf.inqVar(ncid1, varid), the parameter "varid" starts from 0 instead of 1. This is a convention adopted from C language; See remarks for Step 3. The outcome tells us that the 1st variable is named "lat". It is of type "5" which translates to "float" or "real". (The Matlab documentation provided by mathworks.com does not have the detail on this point, but the definition of xtype is available from the documentation for the C interface for netCDF; See p. 41 of that documentation. Some commonly encountered types are 2 = character, 3 = short integer, 4 = integer, 5 = real, and 6 = double.) Note that if one simply reads the header obtained by running ncdisp in Step 0, one would immediately see that the "lat" variable is of "real" or "float" type. The "dimid = 1" in the output tells us that the variable "lat" is a one-dimensional array (because dimid is a single number, not an array) and the coordinate in that dimension is defined by "dimension number 1". Recall that in Step 3 the comamnd, [dimname, dimlength] = netcdf.inqDim(ncid1, 1), returned dimname = lat, dimlength = 72. Therefore, the variable "lat" is an array with 72 elements, and the coordinate for these 72 elements are defined by the dimension, "lat", which itself has 72 elements. (Here, "lat" is both a variable and a dimension or coordinate. If this sounds confusing, keep reading and it will clear later.) Let's not worry about the 4th parameter ("attribution") for now. [varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 1) varname = lon xtype = 5 dimid = 0 natt = 3 Remark: We find that the second variable is called "lon". It is of "real" type. It is a one-dimensional array with its coordinate defined by "dimension number zero", i.e., the 1st dimension or "lon", with 144 elements. Again, "lon" is both a "variable" and a "dimension" (or coordinate). [varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 2) varname = time xtype = 6 dimid = 2 3
  • 4. natt = 6 Remark: The third variable is called "time". It is of "double" type (xtype = 6). It is a one-dimensional array with its coordinate defined by "dimension number 2", i.e., the 3rd dimension or "time", with 12 elements. Again, "time" is both a "variable" and a "dimension" (or coordinate). (This is very common of a netCDF file.) [varname, xtype, dimid, natt] = netcdf.inqVar(ncid1, 3) varname = precip xtype = 5 dimid = 0, 1, 2 natt = 14 Remark: We now obtain the information of the 4th and final variable. (We know there are only 4 variables in this file because nvar = 4 in Step 2.) It is named "precip". It is of "real" type. It is a three- dimensional variable, because dimid = [0, 1, 2], an array with three elements. Moreover, the 1st dimension corresponds to "dimension number zero" given by Step 3, the 2nd dimension corresponds to "dimension number 1", and the third dimension corresponds to "dimension number 2". Therefore, the variable "precip" has the dimension of (144, 72, 12), with total of 144x72x12 elements of real numbers. The coordinates for the 1st, 2nd, and 3rd dimensions are defined by lon(144), lat(72), and time(12). Summary From the above, we learned that there are four variables in the netCDF file, "lon", "lat", "time", and "precip". The first three are there only to provide the coordinate (or "metadata") for the 4th variable, which contains the real data that we want to use. Symbolically, the 4th variable is precip : Pi, j,t k , i = 1-144, j = 1-72, and k = 1-12 , and the first three are lat :  j , j = 1-72 lon : i , i = 1-144 time : tk , k = 1-12 The arrangement of the block of data for "precip" is illustrated in Fig. 1. 4
  • 5. Fig. 1 Here, we use the "normal" convention with each of the indices, i, j, and k, starting from 1, whereas the Matlab netCDF functions adopt C convention such that the counting starts from zero. Figure 2 is a slightly modified diagram that illustrates the actual numbers that we should use to extract the data using the Matlab functions. Fig. 2 5 1 2 3 4 144 lon 1 2 3 72 lat 1 2 3 12 tim e FebruaryMarch January 0 1 2 3 143 0 1 71 0 1 2 112
  • 6. (B) Read a variable from the netCDF file From Part (A), we now know the content of the netCDF file. We will next use some examples to illustrate how to read a selected variable, or a "subsection" of a variable, from the file. This is generally a very straightforward task and only involve calling the function, netcdf.getVar, in a one-line command. (Read the documentation for that function at mathworks.com. It is useful.) Example 1: Read the content of the variable "lat" (this is the latitude for the precipitation data) ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE'); lat1 = netcdf.getVar(ncid1,0,0,72) Result: 88.7500 86.2500 83.7500 81.2500 78.7500 76.2500 ... ... -81.2500 -83.7500 -86.2500 -88.7500 Remark: The first line of command opens the file and assigns it a file number, which is returned to ncid1. In the second line, lat1 = netcdf.getVar(ncid1, varid, start, count), we choose ● ncid1 as the outcome from first line of code, so we know that the file we will be using is "precip.mon.ltm.nc" ● varid = 0, which means we read variable number zero, or the 1st variable, which is "lat", a real array with 72 elements - see Step 4 in Part A. As always, remember that Matlab netCDF functions adopt the convention of C language: The counting starts from zero instead of one. See further remark at bottom of Step 3 in Part A. ● start = 0, which means we read the segment of the variable starting from its 1st element. (Again, remember that counting starts from zero.) ● count = 72, which means we read total of 72 elements, starting from the 1st element (as defined by start = 0). In other words, we read the array, [lat(1), lat(2), lat(3), ..., lat(71), lat(72)], and put it into our own variable, lat1, in the left hand side. As Matlab dumps the content of lat1, we see that the contents of "lat" in the netCDF file are [88.75, 86.25, 83.75, ..., -86.25, -88.75]. These are the latitude (from 88.75°N to 88.75°S) for the precipitation data. 6
  • 7. Example 2: Read the full 144 x 72 global precipitation field for time = 1 (i.e., January climatology), then make a contour plot of it ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE'); precJanuary = netcdf.getVar(ncid1,3,[0 0 0],[144 72 1]); lon1 = netcdf.getVar(ncid1,1,0,144); lat1 = netcdf.getVar(ncid1,0,0,72); for p = 1:144 for q = 1:72 % -- the following 3 lines provides a quick way to remove missing values -- if abs(precJanuary(p,q)) > 99 precJanuary(p,q) = 0; end % ---------------------------------------------------------------- map1(q,p) = precJanuary(p,q); end end contour(lon1,lat1,map1) Result: 7
  • 8. Remarks: Only the first 4 lines of the code are related to reading the netCDF file. The rest are commands for post-processing and plotting the data. In the second line, PrecJanuary = netcdf.getVar(ncid1, varid, start, count) , we choose ncid1 from the outcome of the first line of code, so we know that the file we are using is "precip.mon.ltm.nc". In addition, varid = 3, which means we read the 4th variable, "precip"; start = [0 0 0], which indicates that we read the 1st, 2nd, and 3rd dimension from i = 0, j = 0, and k = 0 as illustrated in Fig.2; count = [144 72 1], which indicates that we actually read i = 0-143 (the total count of grid point is 144), j = 0-71 (total count is 72), and k = 0-0 (total count is 1) in Fig. 2 (which correspond to i = 1-144, j = 1-72, k = 1-1 in Fig. 1). Essentially, we just cut a 144 x 72 slice of the data with k = 1. Example 3: Read the full 144 x 72 global precipitation field for time = 1 (i.e., January climatology), then make a color+contour plot of it ncid1 = netcdf.open('precip.mon.ltm.nc','NC_NOWRITE'); precJanuary = netcdf.getVar(ncid1,3,[0 0 0],[144 72 1],'double'); lon1 = netcdf.getVar(ncid1,1,0,144); lat1 = netcdf.getVar(ncid1,0,0,72); for p = 1:144 for q = 1:72 if abs(precJanuary(p,q)) > 99 precJanuary(p,q) = 0; end map1(q,p) = precJanuary(p,q); end end pcolor(lon1,lat1,map1) shading interp colorbar hold on contour(lon1,lat1,map1,'k-') Result: 8
  • 9. Remark: This example is almost identical to Example 2, but note that in the second line, PrecJanuary = netcdf.getVar(ncid1, varid, start, count, output_type), we have an extra parameter, output_type = 'double'. This helps convert the outcome (which is put into our variable, PrecJanuary) from "real" to "double" type. This is needed in this example, because the function, pcolor (for making a color map) requires that its input be of "double" type. [Typically, for a 32-bit machine, variables of "real" and "double" types contain 4 bytes (or 32 bits) and 8 bytes (or 64 bits), respectively. This detail is not critical.] Without the extra parameter for the conversion, as is the case with Example 2, Matlab would return the values of the variable in its original type, which is "real". (We know it from Step 4 in Part (A) that xtype = 5 for this variable.) Appendix A. The header of a netCDF file as the output from the example in Step 0 Executing the command, ncdisp('precip.mon.ltm.nc'), would produce the following detailed output which is the header of the netCDF file, precip.mon.ltm.nc. Source: m:small_projectprecip.mon.ltm.nc Format: classic Global Attributes: Conventions = 'COARDS' title = 'CPC Merged Analysis of Precipitation (excludes NCEP Reanalysis)' 9
  • 10. history = 'created 12/98 by CASData version v207 ' platform = 'Analyses' source = 'ftp ftp.cpc.ncep.noaa.gov precip/cmap/monthly' documentation = 'http://www.cdc.noaa.gov/cdc/data.cmap.html' Dimensions: lon = 144 lat = 72 time = 12 (UNLIMITED) Variables: lat Size: 72x1 Dimensions: lat Datatype: single Attributes: units = 'degrees_north' actual_range = [8.88e+01 -8.88e+01] long_name = 'Latitude' lon Size: 144x1 Dimensions: lon Datatype: single Attributes: units = 'degrees_east' long_name = 'Longitude' actual_range = [1.25e+00 3.59e+02] time Size: 12x1 Dimensions: time Datatype: double Attributes: units = 'hours since 1-1-1 00:00:0.0' long_name = 'Time' delta_t = '0000-01-00 00:00:00' actual_range = [0.00e+00 8.02e+03] avg_period = '0000-01-00 00:00:00' ltm_range = [1.73e+07 1.75e+07] precip Size: 144x72x12 Dimensions: lon,lat,time Datatype: single Attributes: long_name = 'Average Monthly Rate of Precipitation' valid_range = [0.00e+00 5.00e+01] units = 'mm/day' add_offset = 0 scale_factor = 1 actual_range = [0.00e+00 3.41e+01] 10
  • 11. missing_value = -9.97e+36 precision = 3.28e+04 least_significant_digit = 2 var_desc = 'Precipitation' dataset = 'CPC Merged Analysis of Precipitation Standard' level_desc = 'Surface' statistic = 'Mean' parent_stat = 'Mean' Appendix B: Obtaining the header using Linux-based utilities The header of a netCDF file can also be extracted by using Linux-based utilities. The most commonly used tool is "ncdump". The Linux equivalent of running "ncdisp('precip.mon.ltm.nc') is ncdump -c precip.mon.ltm.nc Note that the "-c" option is essential. With it, the command only dumps the header. Without it, the command will dump all data in the netCDF file. Result: netcdf precip.mon.ltm { dimensions: lon = 144 ; lat = 72 ; time = UNLIMITED ; // (12 currently) variables: float lat(lat) ; lat:units = "degrees_north" ; lat:actual_range = 88.75f, -88.75f ; lat:long_name = "Latitude" ; float lon(lon) ; lon:units = "degrees_east" ; lon:long_name = "Longitude" ; lon:actual_range = 1.25f, 358.75f ; double time(time) ; time:units = "hours since 1-1-1 00:00:0.0" ; time:long_name = "Time" ; time:delta_t = "0000-01-00 00:00:00" ; time:actual_range = 0., 8016. ; time:avg_period = "0000-01-00 00:00:00" ; time:ltm_range = 17338824., 17530944. ; float precip(time, lat, lon) ; precip:long_name = "Average Monthly Rate of Precipitation" ; precip:valid_range = 0.f, 50.f ; precip:units = "mm/day" ; precip:add_offset = 0.f ; precip:scale_factor = 1.f ; precip:actual_range = 0.f, 34.05118f ; 11
  • 12. precip:missing_value = -9.96921e+36f ; precip:precision = 32767s ; precip:least_significant_digit = 2s ; precip:var_desc = "Precipitation" ; precip:dataset = "CPC Merged Analysis of Precipitation Standard" ; precip:level_desc = "Surface" ; precip:statistic = "Mean" ; precip:parent_stat = "Mean" ; // global attributes: :Conventions = "COARDS" ; :title = "CPC Merged Analysis of Precipitation (excludes NCEP Reanalysis)" ; :history = "created 12/98 by CASData version v207n", "" ; :platform = "Analyses" ; :source = "ftp ftp.cpc.ncep.noaa.gov precip/cmap/monthly" ; :documentation = "http://www.cdc.noaa.gov/cdc/data.cmap.html" ; data: lat = 88.75, 86.25, 83.75, 81.25, 78.75, 76.25, 73.75, 71.25, 68.75, 66.25, 63.75, 61.25, 58.75, 56.25, 53.75, 51.25, 48.75, 46.25, 43.75, 41.25, 38.75, 36.25, 33.75, 31.25, 28.75, 26.25, 23.75, 21.25, 18.75, 16.25, 13.75, 11.25, 8.75, 6.25, 3.75, 1.25, -1.25, -3.75, -6.25, -8.75, -11.25, -13.75, -16.25, -18.75, -21.25, -23.75, -26.25, -28.75, -31.25, -33.75, -36.25, -38.75, -41.25, -43.75, -46.25, -48.75, -51.25, -53.75, -56.25, -58.75, -61.25, -63.75, -66.25, -68.75, -71.25, -73.75, -76.25, -78.75, -81.25, -83.75, -86.25, -88.75 ; lon = 1.25, 3.75, 6.25, 8.75, 11.25, 13.75, 16.25, 18.75, 21.25, 23.75, 26.25, 28.75, 31.25, 33.75, 36.25, 38.75, 41.25, 43.75, 46.25, 48.75, 51.25, 53.75, 56.25, 58.75, 61.25, 63.75, 66.25, 68.75, 71.25, 73.75, 76.25, 78.75, 81.25, 83.75, 86.25, 88.75, 91.25, 93.75, 96.25, 98.75, 101.25, 103.75, 106.25, 108.75, 111.25, 113.75, 116.25, 118.75, 121.25, 123.75, 126.25, 128.75, 131.25, 133.75, 136.25, 138.75, 141.25, 143.75, 146.25, 148.75, 151.25, 153.75, 156.25, 158.75, 161.25, 163.75, 166.25, 168.75, 171.25, 173.75, 176.25, 178.75, 181.25, 183.75, 186.25, 188.75, 191.25, 193.75, 196.25, 198.75, 201.25, 203.75, 206.25, 208.75, 211.25, 213.75, 216.25, 218.75, 221.25, 223.75, 226.25, 228.75, 231.25, 233.75, 236.25, 238.75, 241.25, 243.75, 246.25, 248.75, 251.25, 253.75, 256.25, 258.75, 261.25, 263.75, 266.25, 268.75, 271.25, 273.75, 276.25, 278.75, 281.25, 283.75, 286.25, 288.75, 291.25, 293.75, 296.25, 298.75, 301.25, 303.75, 306.25, 308.75, 311.25, 313.75, 316.25, 318.75, 321.25, 323.75, 326.25, 328.75, 331.25, 333.75, 336.25, 338.75, 341.25, 343.75, 346.25, 348.75, 351.25, 353.75, 356.25, 358.75 ; time = 0, 744, 1416, 2160, 2880, 3624, 4344, 5088, 5832, 6552, 7296, 8016 ; } ______________________________________ Quick exercise: Based on the CMAP data set, what are the climatological values of the precipitation rate for January, February, ..., December at the grid point that is closest to (1) Phoenix, AZ, and (2) Seattle, WA? Make a plot of the results. 12