|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 | +<html> |
| 3 | +<!-- |
| 4 | +Copyright (C) 2003 Northwertern University and Argonne National |
| 5 | +Laboratory. |
| 6 | +
|
| 7 | +Portions of this software were developed by the Unidata Program at the |
| 8 | +University Corporation for Atmospheric Research. |
| 9 | +
|
| 10 | +Access and use of this software shall impose the following obligations and |
| 11 | +understandings on the user. The user is granted the right, without any fee or |
| 12 | +cost, to use, copy, modify, alter, enhance and distribute this software, and |
| 13 | +any derivative works thereof, and its supporting documentation for any purpose |
| 14 | +whatsoever, provided that this entire notice appears in all copies of the |
| 15 | +software, derivative works and supporting documentation. Further, Northwestern |
| 16 | +University and Argonne National Laboratory request that the user credit |
| 17 | +Northwestern University and Argonne National Laboratory in any publications |
| 18 | +that result from the use of this software or in any product that includes this |
| 19 | +software. The names Northwestern University and Argonne National Laboratory, |
| 20 | +however, may not be used in any advertising or publicity to endorse or promote |
| 21 | +any products or commercial entity unless specific written permission is |
| 22 | +obtained from Northwestern University and Argonne National Laboratory. The user |
| 23 | +also understands that Northwestern University and Argonne National Laboratory |
| 24 | +are not obligated to provide the user with any support, consulting, training or |
| 25 | +assistance of any kind with regard to the use, operation and performance of |
| 26 | +this software nor to provide the user with any updates, revisions, new versions |
| 27 | +or "bug fixes." |
| 28 | +
|
| 29 | +THIS SOFTWARE IS PROVIDED BY NORTHWESTERN UNIVERSITY AND ARGONNE NATIONAL |
| 30 | +LABORATORY "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 31 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 32 | +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NORTHWESTERN UNIVERSITY |
| 33 | +AND ARGONNE NATIONAL LABORATORY BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 34 | +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 35 | +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS |
| 36 | +ACTION, ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USE OR PERFORMANCE OF |
| 37 | +THIS SOFTWARE. |
| 38 | + --> |
| 39 | +<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ --> |
| 40 | +<head> |
| 41 | +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 42 | +<title>Adding (PnetCDF C Interface Guide)</title> |
| 43 | + |
| 44 | +<meta name="description" content="Adding (PnetCDF C Interface Guide)"> |
| 45 | +<meta name="keywords" content="Adding (PnetCDF C Interface Guide)"> |
| 46 | +<meta name="resource-type" content="document"> |
| 47 | +<meta name="distribution" content="global"> |
| 48 | +<meta name="Generator" content="makeinfo"> |
| 49 | +<link href="index.html#Top" rel="start" title="Top"> |
| 50 | +<link href="Combined-Index.html#Combined-Index" rel="index" title="Combined Index"> |
| 51 | +<link href="Use-of-the-PnetCDF-Library.html#Use-of-the-PnetCDF-Library" rel="up" title="Use of the PnetCDF Library"> |
| 52 | +<link href="Nonblocking-Write.html#Nonblocking-Write" rel="next" title="Nonblocking Write"> |
| 53 | +<link href="Reading-Unknown.html#Reading-Unknown" rel="prev" title="Reading Unknown"> |
| 54 | +<style type="text/css"> |
| 55 | +<!-- |
| 56 | +a.summary-letter {text-decoration: none} |
| 57 | +blockquote.indentedblock {margin-right: 0em} |
| 58 | +blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} |
| 59 | +blockquote.smallquotation {font-size: smaller} |
| 60 | +div.display {margin-left: 3.2em} |
| 61 | +div.example {margin-left: 3.2em} |
| 62 | +div.lisp {margin-left: 3.2em} |
| 63 | +div.smalldisplay {margin-left: 3.2em} |
| 64 | +div.smallexample {margin-left: 3.2em} |
| 65 | +div.smalllisp {margin-left: 3.2em} |
| 66 | +kbd {font-style: oblique} |
| 67 | +pre.display {font-family: inherit} |
| 68 | +pre.format {font-family: inherit} |
| 69 | +pre.menu-comment {font-family: serif} |
| 70 | +pre.menu-preformatted {font-family: serif} |
| 71 | +pre.smalldisplay {font-family: inherit; font-size: smaller} |
| 72 | +pre.smallexample {font-size: smaller} |
| 73 | +pre.smallformat {font-family: inherit; font-size: smaller} |
| 74 | +pre.smalllisp {font-size: smaller} |
| 75 | +span.nolinebreak {white-space: nowrap} |
| 76 | +span.roman {font-family: initial; font-weight: normal} |
| 77 | +span.sansserif {font-family: sans-serif; font-weight: normal} |
| 78 | +ul.no-bullet {list-style: none} |
| 79 | +--> |
| 80 | +</style> |
| 81 | + |
| 82 | + |
| 83 | +</head> |
| 84 | + |
| 85 | +<body lang="en"> |
| 86 | +<a name="Adding"></a> |
| 87 | +<div class="header"> |
| 88 | +<p> |
| 89 | +Next: <a href="Nonblocking-Write.html#Nonblocking-Write" accesskey="n" rel="next">Nonblocking Write</a>, Previous: <a href="Reading-Unknown.html#Reading-Unknown" accesskey="p" rel="prev">Reading Unknown</a>, Up: <a href="Use-of-the-PnetCDF-Library.html#Use-of-the-PnetCDF-Library" accesskey="u" rel="up">Use of the PnetCDF Library</a> [<a href="Combined-Index.html#Combined-Index" title="Index" rel="index">Index</a>]</p> |
| 90 | +</div> |
| 91 | +<hr> |
| 92 | +<a name="Adding-New-Dimensions_002c-Variables_002c-Attributes"></a> |
| 93 | +<h3 class="section">1.4 Adding New Dimensions, Variables, Attributes</h3> |
| 94 | +<a name="index-ncmpi_005fredef_002c-typical-use"></a> |
| 95 | +<a name="index-ncmpi_005fdef_005fdim_002c-typical-use-1"></a> |
| 96 | +<a name="index-ncmpi_005fput_005fatt_002c-typical-use-1"></a> |
| 97 | +<a name="index-dimensions_002c-adding"></a> |
| 98 | +<a name="index-variables_002c-adding"></a> |
| 99 | +<a name="index-attributes_002c-adding"></a> |
| 100 | +<a name="index-aborting-define-mode"></a> |
| 101 | +<a name="index-aborting-definitions"></a> |
| 102 | +<a name="index-adding-dimensions"></a> |
| 103 | +<a name="index-adding-attributes"></a> |
| 104 | +<a name="index-adding-variables"></a> |
| 105 | +<a name="index-attributes_002c-deleting_002c-introduction"></a> |
| 106 | + |
| 107 | +<p>An existing netCDF file can be extensively altered. New dimensions, |
| 108 | +variables, and attributes can be added or existing ones renamed, and |
| 109 | +existing attributes can be deleted. Existing dimensions, variables, |
| 110 | +and attributes can be renamed. The following code template lists a |
| 111 | +typical sequence of calls to add new netCDF components to an existing |
| 112 | +file: |
| 113 | +</p> |
| 114 | +<div class="example"> |
| 115 | +<pre class="example"> ncmpi_open /* open existing netCDF file */ |
| 116 | + ... |
| 117 | + ncmpi_redef /* put it into define mode */ |
| 118 | + ... |
| 119 | + ncmpi_def_dim /* define additional dimensions (if any) */ |
| 120 | + ... |
| 121 | + ncmpi_def_var /* define additional variables (if any) */ |
| 122 | + ... |
| 123 | + ncmpi_put_att /* define additional attributes (if any) */ |
| 124 | + ... |
| 125 | + ncmpi_enddef /* check definitions, leave define mode */ |
| 126 | + ... |
| 127 | + ncmpi_put_var /* provide values for new variables */ |
| 128 | + ... |
| 129 | + ncmpi_close /* close netCDF file */ |
| 130 | +</pre></div> |
| 131 | + |
| 132 | +<p>A netCDF file is first opened by the ncmpi_open call. This call puts |
| 133 | +the opened file in data mode, which means existing data values can be |
| 134 | +accessed and changed, existing attributes can be changed (so long as |
| 135 | +they do not grow), but nothing can be added. To add new netCDF |
| 136 | +dimensions, variables, or attributes you must enter define mode, by |
| 137 | +calling ncmpi_redef. In define mode, call ncmpi_def_dim to define new |
| 138 | +dimensions, ncmpi_def_var to define new variables, and a member of the |
| 139 | +ncmpi_put_att family to assign new attributes to variables or enlarge old |
| 140 | +attributes. |
| 141 | +</p> |
| 142 | +<p>You can leave define mode and reenter data mode, checking all the new |
| 143 | +definitions for consistency and committing the changes to disk, by |
| 144 | +calling ncmpi_enddef. If you do not wish to reenter data mode, just call |
| 145 | +ncmpi_close, which will have the effect of first calling ncmpi_enddef. |
| 146 | +</p> |
| 147 | +<p>Until the ncmpi_enddef call, you may back out of all the redefinitions |
| 148 | +made in define mode and restore the previous state of the netCDF |
| 149 | +file by calling ncmpi_abort. You may also use the ncmpi_abort call to |
| 150 | +restore the netCDF file to a consistent state if the call to |
| 151 | +ncmpi_enddef fails. If you have called ncmpi_close from definition mode and |
| 152 | +the implied call to ncmpi_enddef fails, ncmpi_abort will automatically be |
| 153 | +called to close the netCDF file and leave it in its previous |
| 154 | +consistent state (before you entered define mode). |
| 155 | +</p> |
| 156 | +<hr> |
| 157 | +<div class="header"> |
| 158 | +<p> |
| 159 | +Next: <a href="Nonblocking-Write.html#Nonblocking-Write" accesskey="n" rel="next">Nonblocking Write</a>, Previous: <a href="Reading-Unknown.html#Reading-Unknown" accesskey="p" rel="prev">Reading Unknown</a>, Up: <a href="Use-of-the-PnetCDF-Library.html#Use-of-the-PnetCDF-Library" accesskey="u" rel="up">Use of the PnetCDF Library</a> [<a href="Combined-Index.html#Combined-Index" title="Index" rel="index">Index</a>]</p> |
| 160 | +</div> |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | +</body> |
| 165 | +</html> |
0 commit comments