Skip to content

Commit 7c00d74

Browse files
committed
create_from_cdl.c - add more comments
1 parent 183b62c commit 7c00d74

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

examples/C/create_from_cdl.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
133133
err = ncmpi_create(MPI_COMM_WORLD, outfile, cmode, MPI_INFO_NULL, &ncid);
134134
CHECK_ERR
135135

136-
/* define dimensions */
136+
/* retrieve the number of dimensions defined in the CDL file */
137137
err = cdl_hdr_inq_ndims(hid, &ndims);
138138
CHECK_ERR
139139
if (verbose) printf("Number of dimensions : %d\n", ndims);
@@ -142,14 +142,16 @@ int main(int argc, char **argv)
142142
int dimid;
143143
MPI_Offset dimlen;
144144

145+
/* retrieve metadata of dimension i */
145146
err = cdl_hdr_inq_dim(hid, i, &name, &dimlen);
146-
CHECK_ERR
147+
CHECK_ERR
147148

149+
/* define a new dimension in the new file */
148150
err = ncmpi_def_dim(ncid, name, dimlen, &dimid);
149151
CHECK_ERR
150152
}
151153

152-
/* define variables */
154+
/* retrieve number of variables defined in the CDL file */
153155
err = cdl_hdr_inq_nvars(hid, &nvars);
154156
CHECK_ERR
155157
if (verbose) printf("Number of variables : %d\n", nvars);
@@ -158,13 +160,15 @@ int main(int argc, char **argv)
158160
int varid, *dimids;
159161
nc_type xtype;
160162

163+
/* retrieve metadata of variable i defined in the CDL file */
161164
err = cdl_hdr_inq_var(hid, i, &name, &xtype, &ndims, &dimids);
162165
CHECK_ERR
163166

167+
/* define a new variable in the new file */
164168
err = ncmpi_def_var(ncid, name, xtype, ndims, dimids, &varid);
165169
CHECK_ERR
166170

167-
/* define variable's attributes */
171+
/* retrieve metadata of attribute j associated with variable i */
168172
err = cdl_hdr_inq_nattrs(hid, i, &nattrs);
169173
CHECK_ERR
170174

@@ -173,14 +177,17 @@ int main(int argc, char **argv)
173177
nc_type xtype;
174178
MPI_Offset nelems;
175179

180+
/* retrieve metadata of attribute j associated with variable i */
176181
err = cdl_hdr_inq_attr(hid, i, j, &name, &xtype, &nelems, &value);
177182
CHECK_ERR
183+
184+
/* define a new attribute and associate it to variable, varid */
178185
err = ncmpi_put_att(ncid, varid, name, xtype, nelems, value);
179186
CHECK_ERR
180187
}
181188
}
182189

183-
/* define global attributes */
190+
/* retrieve the number of global attributes */
184191
err = cdl_hdr_inq_nattrs(hid, NC_GLOBAL, &nattrs);
185192
CHECK_ERR
186193
if (verbose) printf("Number of global attributes: %d\n", nattrs);
@@ -190,15 +197,21 @@ int main(int argc, char **argv)
190197
nc_type xtype;
191198
MPI_Offset nelems;
192199

200+
/* retrieve metadata of global attribute i */
193201
err = cdl_hdr_inq_attr(hid, NC_GLOBAL, i, &name, &xtype, &nelems,
194202
&value);
195203
CHECK_ERR
204+
205+
/* define a global attribute in the new file */
196206
err = ncmpi_put_att(ncid, NC_GLOBAL, name, xtype, nelems, value);
197207
CHECK_ERR
198208
}
209+
210+
/* close the NetCDF file */
199211
err = ncmpi_close(ncid);
200212
CHECK_ERR
201213

214+
/* close the CDL file */
202215
err = cdl_hdr_close(hid);
203216
CHECK_ERR
204217

0 commit comments

Comments
 (0)