<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2002-2-1 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>4.18 Options for COARDS-compliant netCDF files</TITLE> <META NAME="description" CONTENT="4.18 Options for COARDS-compliant netCDF files"> <META NAME="keywords" CONTENT="GMT_Docs"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="GMT_Docs.css"> <LINK REL="next" HREF="node74.html"> <LINK REL="previous" HREF="node72.html"> <LINK REL="up" HREF="node31.html"> <LINK REL="next" HREF="node74.html"> </HEAD> <BODY bgcolor="#ffffff"> <!--Navigation Panel--> <A NAME="tex2html3582" HREF="node74.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3576" HREF="node31.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3570" HREF="node72.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3578" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3580" HREF="node256.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3583" HREF="node74.html">4.19 The NaN data</A> <B> Up:</B> <A NAME="tex2html3577" HREF="node31.html">4. General features</A> <B> Previous:</B> <A NAME="tex2html3571" HREF="node72.html">4.17 Grid file format</A> <B> <A NAME="tex2html3579" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3581" HREF="node256.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H1><A NAME="SECTION0012180000000000000000"></A> <A NAME="sec:netcdf"></A><A NAME="18574"></A> <A NAME="18575"></A> <BR> 4.18 Options for COARDS-compliant netCDF files </H1> <P> When the netCDF file contains more than one 2-dimensional variable, <A NAME="tex2html1223" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> programs will load the first such variable in the file and ignore all others. Alternatively, the user can select the required variable by adding the suffix ``?<I>varname</I>'' to the file name. For example, to get information on the variable ``slp'' in file <U>file.nc</U>, use: <PRE> grdinfo "file.nc?slp" </PRE> Since COARDS-compliant netCDF files are the default, the additional suffix ``=nf'' can be omitted. <P> In case the named variable is 3-dimensional, <A NAME="tex2html1224" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> will load the first (bottom) layer. If another layer is required, either add ``[<I>index</I>]'' or ``(<I>level</I>)'', where <I>index</I> is the index of the third (depth) variable (starting at 0 for the first layer) and <I>level</I> is the numerical value of the third (depth) variable associated with the requested layer. To indicate the second layer of the 3-D variable ``slp'' use as file name: <U>file.nc?slp[1]</U>. <P> When you supply the numerical value for the third variable using ``(<I>level</I>)'', <A NAME="tex2html1225" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> will pick the layer closest to that value. No interpolation is performed. <P> Note that the question mark, brackets and parentheses have special meanings on Unix-based platforms. Therefore, you will need to either <I>escape</I> these characters, by placing a backslash in front of them, or place the whole file name plus modifiers between single quotes or double quotes. <P> A similar approach is followed for loading 4-dimensional grids. Consider a 4-dimensional grid with the following variables: <PRE> lat(lat): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 lon(lon): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 depth(depth): 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 time(time): 0, 12, 24, 36, 48 pressure(time,depth,lat,lon): (5000 values) </PRE> To get information on the 10<IMG WIDTH="16" HEIGHT="29" ALIGN="MIDDLE" BORDER="0" SRC="img83.png" ALT="$\times$">10 grid of pressure at depth 10 and at time 24, one would use: <PRE> grdinfo "file.nc?pressure[2,1]" </PRE> or (only in case the coordinates increase linearly): <PRE> grdinfo "file.nc?pressure(24,10)" </PRE> <P> The COARDS conventions set restrictions on the names that can be used for the units of the variables and coordinates. For example, the units of longitude and latitude are ``degrees_east'' and ``degrees_north'', respectively. Here is an example of the header of a COARDS compliant netCDF file (to be obtained using <I>ncdump</I><A NAME="19613"></A>): <PRE> netcdf M2_fes2004 { dimensions: lon = 2881 ; lat = 1441 ; variables: float lon(lon) ; lon:long_name = "longitude" ; lon:units = "degrees_east" ; lon:actual_range = 0., 360. ; float lat(lat) ; lat:long_name = "latitude" ; lat:units = "degrees_north" ; lat:actual_range = -90., 90. ; short amp(lat, lon) ; amp:long_name = "amplitude" ; amp:unit = "m" ; amp:scale_factor = 0.0001 ; amp:add_offset = 3. ; amp:_FillValue = -32768s ; short pha(lat, lon) ; pha:long_name = "phase" ; pha:unit = "degrees" ; pha:scale_factor = 0.01 ; pha:_FillValue = -32768s ; </PRE> This file contains two grids, which can be plotted separately using the names <U>M2_fes2004.nc?amp</U> and <U>M2_fes2004.nc?pha</U>. The attributes <code>long_name</code> and <code>unit</code> for each variable are combined in <A NAME="tex2html1226" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> to a single unit string. For example, after reading the grid <code>y_unit</code> equals <code>latitude [degrees_north]</code>. The same method can be used in reverse to set the proper variable names and units when writing a grid. However, when the coordinates are set properly as geographical or time axes, <A NAME="tex2html1227" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> will take care of this. The user is, however, still responsible for setting the variable name and unit of the z-coordinate. The default is simply ``z''. <P> <A NAME="18598"></A> <A NAME="18599"></A> <P> <HR> <!--Navigation Panel--> <A NAME="tex2html3582" HREF="node74.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3576" HREF="node31.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3570" HREF="node72.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3578" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3580" HREF="node256.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3583" HREF="node74.html">4.19 The NaN data</A> <B> Up:</B> <A NAME="tex2html3577" HREF="node31.html">4. General features</A> <B> Previous:</B> <A NAME="tex2html3571" HREF="node72.html">4.17 Grid file format</A> <B> <A NAME="tex2html3579" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3581" HREF="node256.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> Paul Wessel 2010-07-14 </ADDRESS> </BODY> </HTML>