@@ -101,24 +101,42 @@ main(int argc, char **argv)
101101 SUMMARIZE_ERR ;
102102 printf ("*** Checking a HDF5 file with scalar, fixed-length string dataset..." );
103103 {
104- #define VAR_NAME "Marcus_Aurelius "
105- hid_t fcpl_id , fileid , grpid , spaceid , typeid , datasetid , plistid ;
104+ #define VAR_NAME_2 "Gettysburg Address "
105+ hid_t fapl_id , fcpl_id , fileid , grpid , spaceid , typeid , datasetid , plistid ;
106106 int ncid , nvars_in , ndims_in , natts_in , unlimdim_in , type_in ;
107- char * data = "Thou art no dissatisfied, I suppose, because "
108- "thou weighest only so many liters and not three hundred. Be not "
109- "dissatisfied then that thou must live only so many years and not more; "
110- "for as thou art satisfied with the amount of substance which has "
111- "been assigned to thee, so be content with the time." ;
107+ char data [] = "Four score and seven years ago our fathers brought forth on "
108+ "this continent, a new nation, conceived in Liberty, and dedicated to "
109+ "the proposition that all men are created equal. Now we are engaged "
110+ "in a great civil war, testing whether that nation, or any nation so "
111+ "conceived and so dedicated, can long endure. We are met on a great "
112+ "battle-field of that war. We have come to dedicate a portion of that "
113+ "field, as a final resting place for those who here gave their lives "
114+ "that that nation might live. It is altogether fitting and proper that "
115+ "we should do this. But, in a larger sense, we can not dedicate -- we "
116+ "can not consecrate -- we can not hallow -- this ground. The brave men, "
117+ "living and dead, who struggled here, have consecrated it, far above our "
118+ "poor power to add or detract. The world will little note, nor long "
119+ "remember what we say here, but it can never forget what they did here. "
120+ "It is for us the living, rather, to be dedicated here to the unfinished "
121+ "work which they who fought here have thus far so nobly advanced. It is "
122+ "rather for us to be here dedicated to the great task remaining before "
123+ "us -- that from these honored dead we take increased devotion to that "
124+ "cause for which they gave the last full measure of devotion -- that we "
125+ "here highly resolve that these dead shall not have died in vain -- that "
126+ "this nation, under God, shall have a new birth of freedom -- and that "
127+ "government of the people, by the people, for the people, shall not "
128+ "perish from the earth." ;
112129 char name_in [NC_MAX_NAME + 1 ];
113- #if 0
114- size_t size_in ;
115- char * empty = "" ;
116- char * data_in2 ;
117- #endif
130+ char * data_in2 [1 ];
118131
119- /* Create create property list. */
132+ /* Create file access and create property lists. */
133+ if ((fapl_id = H5Pcreate (H5P_FILE_ACCESS )) < 0 ) ERR ;
120134 if ((fcpl_id = H5Pcreate (H5P_FILE_CREATE )) < 0 ) ERR ;
121135
136+ /* Set latest_format in access propertly list. This ensures that
137+ * the latest, greatest, HDF5 versions are used in the file. */
138+ if (H5Pset_libver_bounds (fapl_id , H5F_LIBVER_LATEST , H5F_LIBVER_LATEST ) < 0 ) ERR ;
139+
122140 /* Set H5P_CRT_ORDER_TRACKED in the creation property list. This
123141 * turns on HDF5 creation ordering in the file. */
124142 if (H5Pset_link_creation_order (fcpl_id , (H5P_CRT_ORDER_TRACKED |
@@ -127,8 +145,7 @@ main(int argc, char **argv)
127145 H5P_CRT_ORDER_INDEXED )) < 0 ) ERR ;
128146
129147 /* Create the file, open root group. */
130- if ((fileid = H5Fcreate (FILE_NAME , H5F_ACC_TRUNC , fcpl_id ,
131- H5P_DEFAULT )) < 0 ) ERR ;
148+ if ((fileid = H5Fcreate (FILE_NAME , H5F_ACC_TRUNC , fcpl_id , fapl_id )) < 0 ) ERR ;
132149 if ((grpid = H5Gopen2 (fileid , "/" , H5P_DEFAULT )) < 0 ) ERR ;
133150
134151 /* Create string type. */
@@ -140,120 +157,32 @@ main(int argc, char **argv)
140157
141158 /* Write an scalar dataset of this type. */
142159 if ((plistid = H5Pcreate (H5P_DATASET_CREATE )) < 0 ) ERR ;
143- /* if (H5Pset_fill_value(plistid, typeid, &empty) < 0) ERR;*/
144- if ((datasetid = H5Dcreate2 (grpid , VAR_NAME , typeid , spaceid ,
145- H5P_DEFAULT , plistid , H5P_DEFAULT )) < 0 ) ERR ;
146- if (H5Dwrite (datasetid , typeid , spaceid , spaceid , H5P_DEFAULT ,
147- data ) < 0 ) ERR ;
160+ if ((datasetid = H5Dcreate1 (grpid , VAR_NAME_2 , typeid ,
161+ spaceid , plistid )) < 0 ) ERR ;
162+ if (H5Dwrite (datasetid , typeid , spaceid , spaceid ,
163+ H5P_DEFAULT , data ) < 0 ) ERR ;
148164
149165 /* Close up. */
150166 if (H5Dclose (datasetid ) < 0 ) ERR ;
151- if (H5Pclose (plistid ) < 0 ) ERR ;
167+ if (H5Pclose (fapl_id ) < 0 ) ERR ;
152168 if (H5Pclose (fcpl_id ) < 0 ) ERR ;
169+ if (H5Pclose (plistid ) < 0 ) ERR ;
153170 if (H5Tclose (typeid ) < 0 ) ERR ;
154171 if (H5Gclose (grpid ) < 0 ) ERR ;
155172 if (H5Fclose (fileid ) < 0 ) ERR ;
156173
157174 /* Read the file with netCDF-4. */
158- /* nc_set_log_level(6); */
159175 if (nc_open (FILE_NAME , NC_NOWRITE , & ncid )) ERR ;
160176 if (nc_inq (ncid , & ndims_in , & nvars_in , & natts_in , & unlimdim_in )) ERR ;
161177 if (ndims_in != 0 || nvars_in != 1 || natts_in != 0 || unlimdim_in != -1 ) ERR ;
162178 if (nc_inq_var (ncid , 0 , name_in , & type_in , & ndims_in , NULL , & natts_in )) ERR ;
163- /* if (strcmp(name_in, VAR_NAME ) || type_in != NC_STRING ||
164- ndims_in != 0 || natts_in != 0) ERR;*/
165- /* if (nc_get_var_string(ncid, 0, & data_in2)) ERR;
166- if (strcmp(data_in2, data)) ERR;
167- if (nc_free_string(size_in, & data_in2)) ERR;*/
179+ if (strcmp (name_in , VAR_NAME_2 ) || type_in != NC_STRING ||
180+ ndims_in != 0 || natts_in != 0 ) ERR ;
181+ if (nc_get_var_string (ncid , 0 , data_in2 )) ERR ;
182+ if (strcmp (data_in2 [ 0 ] , data )) ERR ;
183+ if (nc_free_string (1 , data_in2 )) ERR ;
168184 if (nc_close (ncid )) ERR ;
169185 }
170186 SUMMARIZE_ERR ;
171- /* printf("*** Checking a HDF5 file with scalar, fixed-length string dataset..."); */
172- /* { */
173- /* #define VAR_NAME "Gettysburg Address" */
174- /* hid_t fapl_id, fcpl_id, fileid, grpid, spaceid, typeid, datasetid, plistid; */
175- /* int ncid, nvars_in, ndims_in, natts_in, unlimdim_in, type_in; */
176- /* size_t size_in; */
177- /* char data[] = "Four score and seven years ago our fathers brought forth on " */
178- /* "this continent, a new nation, conceived in Liberty, and dedicated to " */
179- /* "the proposition that all men are created equal. Now we are engaged " */
180- /* "in a great civil war, testing whether that nation, or any nation so " */
181- /* "conceived and so dedicated, can long endure. We are met on a great " */
182- /* "battle-field of that war. We have come to dedicate a portion of that " */
183- /* "field, as a final resting place for those who here gave their lives " */
184- /* "that that nation might live. It is altogether fitting and proper that " */
185- /* "we should do this. But, in a larger sense, we can not dedicate -- we " */
186- /* "can not consecrate -- we can not hallow -- this ground. The brave men, " */
187- /* "living and dead, who struggled here, have consecrated it, far above our " */
188- /* "poor power to add or detract. The world will little note, nor long " */
189- /* "remember what we say here, but it can never forget what they did here. " */
190- /* "It is for us the living, rather, to be dedicated here to the unfinished " */
191- /* "work which they who fought here have thus far so nobly advanced. It is " */
192- /* "rather for us to be here dedicated to the great task remaining before " */
193- /* "us -- that from these honored dead we take increased devotion to that " */
194- /* "cause for which they gave the last full measure of devotion -- that we " */
195- /* "here highly resolve that these dead shall not have died in vain -- that " */
196- /* "this nation, under God, shall have a new birth of freedom -- and that " */
197- /* "government of the people, by the people, for the people, shall not " */
198- /* "perish from the earth."; */
199- /* char *empty = ""; */
200- /* char *data_in2, name_in[NC_MAX_NAME + 1]; */
201-
202- /* /\* Create file access and create property lists. *\/ */
203- /* if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR; */
204- /* if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR; */
205-
206- /* /\* Set latest_format in access propertly list. This ensures that */
207- /* * the latest, greatest, HDF5 versions are used in the file. *\/ */
208- /* if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR; */
209-
210- /* /\* Set H5P_CRT_ORDER_TRACKED in the creation property list. This */
211- /* * turns on HDF5 creation ordering in the file. *\/ */
212- /* if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | */
213- /* H5P_CRT_ORDER_INDEXED)) < 0) ERR; */
214- /* if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | */
215- /* H5P_CRT_ORDER_INDEXED)) < 0) ERR; */
216-
217- /* /\* Create the file, open root group. *\/ */
218- /* if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR; */
219- /* if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR; */
220-
221- /* /\* Create string type. *\/ */
222- /* if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR; */
223- /* if (H5Tset_size(typeid, strlen(data) + 1) < 0) ERR; */
224-
225- /* /\* Create a scalar space. *\/ */
226- /* if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR; */
227-
228- /* /\* Write an scalar dataset of this type. *\/ */
229- /* if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR; */
230- /* if (H5Pset_fill_value(plistid, typeid, &empty) < 0) ERR; */
231- /* if ((datasetid = H5Dcreate1(grpid, VAR_NAME, typeid, */
232- /* spaceid, plistid)) < 0) ERR; */
233- /* if (H5Dwrite(datasetid, typeid, spaceid, spaceid, */
234- /* H5P_DEFAULT, data) < 0) ERR; */
235-
236- /* /\* Close up. *\/ */
237- /* if (H5Dclose(datasetid) < 0) ERR; */
238- /* if (H5Pclose(fapl_id) < 0) ERR; */
239- /* if (H5Pclose(fcpl_id) < 0) ERR; */
240- /* if (H5Pclose(plistid) < 0) ERR; */
241- /* if (H5Tclose(typeid) < 0) ERR; */
242- /* if (H5Gclose(grpid) < 0) ERR; */
243- /* if (H5Fclose(fileid) < 0) ERR; */
244-
245- /* /\* Read the file with netCDF-4. *\/ */
246- /* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
247- /* if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdim_in)) ERR; */
248- /* if (ndims_in != 0 || nvars_in != 1 || natts_in != 0 || unlimdim_in != -1) ERR; */
249- /* if (nc_inq_var(ncid, 0, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR; */
250- /* if (strcmp(name_in, VAR_NAME) || type_in != NC_STRING || */
251- /* ndims_in != 0 || natts_in != 0) ERR; */
252- /* if (nc_get_var_string(ncid, 0, &data_in2)) ERR; */
253- /* if (strcmp(data_in2, data)) ERR; */
254- /* if (nc_free_string(size_in, &data_in2)) ERR; */
255- /* if (nc_close(ncid)) ERR; */
256- /* } */
257- /* SUMMARIZE_ERR; */
258187 FINAL_RESULTS ;
259188}
0 commit comments