@@ -166,6 +166,7 @@ combine_env_hints(MPI_Info user_info, /* IN */
166166{
167167 char * warn_str = "Warning: skip ill-formed hint set in PNETCDF_HINTS" ;
168168 char * env_str ;
169+ char * hdr_align_val = NULL , * var_align_val = NULL ;
169170
170171 /* take hints from the environment variable PNETCDF_HINTS, a string of
171172 * hints separated by ";" and each hint is in the form of hint=value. E.g.
@@ -182,17 +183,17 @@ combine_env_hints(MPI_Info user_info, /* IN */
182183 if ((env_str = getenv ("PNETCDF_HINTS" )) != NULL ) {
183184#ifdef USE_STRTOK_R
184185 char * env_str_cpy , * env_str_saved , * hint , * key ;
185- env_str_cpy = strdup (env_str );
186+ env_str_cpy = NCI_Strdup (env_str );
186187 env_str_saved = env_str_cpy ;
187188 hint = strtok_r (env_str_cpy , ";" , & env_str_saved );
188189 while (hint != NULL ) {
189- char * hint_saved = strdup (hint );
190+ char * hint_saved = NCI_Strdup (hint );
190191 char * val = strchr (hint , '=' );
191192 if (val == NULL ) { /* ill-formed hint */
192193 if (NULL != strtok (hint , " \t" ))
193194 printf ("%s: '%s'\n" , warn_str , hint_saved );
194195 /* else case: ignore white-spaced hints */
195- free (hint_saved );
196+ NCI_Free (hint_saved );
196197 hint = strtok_r (NULL , ";" , & env_str_saved ); /* get next hint */
197198 continue ;
198199 }
@@ -203,18 +204,24 @@ combine_env_hints(MPI_Info user_info, /* IN */
203204 else {
204205 if (* new_info == MPI_INFO_NULL )
205206 MPI_Info_create (new_info ); /* ignore error */
206- MPI_Info_set (* new_info , key , val ); /* override or add */
207+
208+ if (!strcmp (key , "nc_header_align_size" ))
209+ hdr_align_val = NCI_Strdup (val );
210+ else if (!strcmp (key , "nc_var_align_size" ))
211+ var_align_val = NCI_Strdup (val );
212+ else
213+ MPI_Info_set (* new_info , key , val ); /* override or add */
207214 }
208215 /* printf("env hint: key=%s val=%s\n",key,val); */
209216 hint = strtok_r (NULL , ";" , & env_str_saved );
210- free (hint_saved );
217+ NCI_Free (hint_saved );
211218 }
212- free (env_str_cpy );
219+ NCI_Free (env_str_cpy );
213220#else
214221 char * env_str_cpy , * hint , * next_hint , * key , * val , * deli ;
215222 char * hint_saved = NULL ;
216223
217- env_str_cpy = strdup (env_str );
224+ env_str_cpy = NCI_Strdup (env_str );
218225 next_hint = env_str_cpy ;
219226
220227 do {
@@ -225,14 +232,14 @@ combine_env_hints(MPI_Info user_info, /* IN */
225232 next_hint = deli + 1 ;
226233 }
227234 else next_hint = "\0" ;
228- if (hint_saved != NULL ) free (hint_saved );
235+ if (hint_saved != NULL ) NCI_Free (hint_saved );
229236
230237 /* skip all-blank hint */
231- hint_saved = strdup (hint );
238+ hint_saved = NCI_Strdup (hint );
232239 if (strtok (hint , " \t" ) == NULL ) continue ;
233240
234- free (hint_saved );
235- hint_saved = strdup (hint ); /* save hint for error message */
241+ NCI_Free (hint_saved );
242+ hint_saved = NCI_Strdup (hint ); /* save hint for error message */
236243
237244 deli = strchr (hint , '=' );
238245 if (deli == NULL ) { /* ill-formed hint */
@@ -257,15 +264,35 @@ combine_env_hints(MPI_Info user_info, /* IN */
257264 }
258265 if (* new_info == MPI_INFO_NULL )
259266 MPI_Info_create (new_info ); /* ignore error */
260- MPI_Info_set (* new_info , key , val ); /* override or add */
267+
268+ if (!strcmp (key , "nc_header_align_size" ))
269+ hdr_align_val = NCI_Strdup (val );
270+ else if (!strcmp (key , "nc_var_align_size" ))
271+ var_align_val = NCI_Strdup (val );
272+ else
273+ MPI_Info_set (* new_info , key , val ); /* override or add */
261274
262275 } while (* next_hint != '\0' );
263276
264- if (hint_saved != NULL ) free (hint_saved );
265- free (env_str_cpy );
277+ if (hint_saved != NULL ) NCI_Free (hint_saved );
278+ NCI_Free (env_str_cpy );
266279#endif
280+
281+ /* nc_var_align_size supersedes nc_header_align_size */
282+ if (var_align_val != NULL ) {
283+ MPI_Info_set (* new_info , "nc_var_align_size" , var_align_val );
284+ MPI_Info_set (* new_info , "nc_header_align_size" , var_align_val );
285+ }
286+ else if (hdr_align_val != NULL ) {
287+ MPI_Info_set (* new_info , "nc_var_align_size" , hdr_align_val );
288+ MPI_Info_set (* new_info , "nc_header_align_size" , hdr_align_val );
289+ }
267290 }
268291 /* return no error as all hints are advisory */
292+
293+ if (hdr_align_val != NULL ) NCI_Free (hdr_align_val );
294+ if (var_align_val != NULL ) NCI_Free (var_align_val );
295+
269296}
270297
271298/*----< ncmpi_create() >-----------------------------------------------------*/
0 commit comments