44 typedef struct ExAtts ExAtts;
61 static ExAtts *_ExAtts = (ExAtts *)NULL;
72 static ExAtts *_dsproc_get_exclude_atts(
const char *var_name)
76 for (ex_atts = _ExAtts; ex_atts; ex_atts = ex_atts->next) {
78 if ((var_name == NULL) || (ex_atts->var_name == NULL) ) {
79 if ((var_name == NULL) && (ex_atts->var_name == NULL) ) {
83 else if (strcmp(ex_atts->var_name, var_name) == 0) {
88 return((ExAtts *)NULL);
91 static const char *_DSName;
92 static const char *_Header;
93 static int _NumChanges;
99 #define INIT_METADATA_WARNINGS(warn, ds_name, header) \
100 _dsproc_init_metadata_warnings(warn, ds_name, header)
105 #define METADATA_WARNING(...) \
106 _dsproc_metadata_warning(__func__, __FILE__, __LINE__, __VA_ARGS__)
111 #define FINISH_METADATA_WARNINGS() \
112 _dsproc_finish_metadata_warnings(__func__, __FILE__, __LINE__)
121 static void _dsproc_init_metadata_warnings(
141 static int _dsproc_finish_metadata_warnings(
148 if (_NumChanges && _Warn) {
158 " - number of changes found: %d\n",
177 static void _dsproc_metadata_warning(
181 const char *format, ...)
190 if (_NumChanges == 0) {
205 va_start(args, format);
230 static int _dsproc_compare_atts(
231 const char *var_name,
249 null_string =
"NULL";
250 indent_string = (var_name) ?
" " :
"";
253 int special_att_count = 0;
257 for (ai = 0; ai < curr_natts; ++ai) {
259 curr_att = curr_atts[ai];
261 if (strcmp(curr_att->
name,
"_Format") == 0 ||
262 strcmp(curr_att->
name,
"_DeflateLevel") == 0 ||
263 strcmp(curr_att->
name,
"_ChunkSizes") == 0 ||
264 strcmp(curr_att->
name,
"_Shuffle") == 0 ||
265 strcmp(curr_att->
name,
"_Endianness") == 0 ||
266 strcmp(curr_att->
name,
"_Fletcher32") == 0 ||
267 strcmp(curr_att->
name,
"_NoFill") == 0) {
291 for (xi = 0; xi < ex_atts->natts; ++xi) {
292 if (strcmp(curr_att->
name, ex_atts->att_names[xi]) == 0) {
297 if (xi != ex_atts->natts) {
304 for (aj = 0; aj < prev_natts; ++aj) {
306 prev_att = prev_atts[aj];
308 if (strcmp(curr_att->
name, prev_att->
name) == 0) {
313 if (aj == prev_natts) {
317 if (var_name && !nchanges) {
320 " - %s: variable attribute changes\n",
325 "%s - %s: attribute not found in previous dataset\n",
326 indent_string, curr_att->
name);
351 prev_value = null_string;
352 curr_value = null_string;
376 if (!prev_value || !curr_value) {
379 "Could not generate warning message for attribute change\n"
380 " -> memory allocation error\n");
382 if (prev_value && (prev_value != null_string)) free(prev_value);
383 if (curr_value && (curr_value != null_string)) free(curr_value);
389 if (var_name && !nchanges) {
392 " - %s: variable attribute changes\n",
397 "%s - %s: attribute value changed\n"
400 indent_string, curr_att->
name,
401 indent_string, prev_value,
402 indent_string, curr_value);
404 if (prev_value != null_string) free(prev_value);
405 if (curr_value != null_string) free(curr_value);
417 if (prev_natts != (curr_natts - special_att_count)) {
421 if (var_name && !nchanges) {
424 " - %s: variable attribute changes\n",
429 "%s - number of attributes changed from %d to %d\n",
430 indent_string, prev_natts, curr_natts);
449 void _dsproc_free_exclude_atts(
void)
455 for (ex_atts = _ExAtts; ex_atts; ex_atts = next) {
457 next = ex_atts->next;
459 if (ex_atts->var_name) free(ex_atts->var_name);
460 if (ex_atts->att_names) {
462 for (ai = 0; ai < ex_atts->natts; ai++) {
463 if (ex_atts->att_names[ai]) free(ex_atts->att_names[ai]);
466 free(ex_atts->att_names);
472 _ExAtts = (ExAtts *)NULL;
485 int _dsproc_set_standard_exclude_atts(
void)
489 const char *global_atts[] = {
497 int global_natts =
sizeof(global_atts)/
sizeof(
char *);
505 const char *bt_atts[] = {
508 int bt_natts =
sizeof(bt_atts)/
sizeof(
char *);
516 const char *to_atts[] = {
519 int to_natts =
sizeof(to_atts)/
sizeof(
char *);
527 const char *time_atts[] = {
530 int time_natts =
sizeof(time_atts)/
sizeof(
char *);
538 const char *tb_atts[] = {
541 int tb_natts =
sizeof(tb_atts)/
sizeof(
char *);
569 const char *prev_version;
570 const char *curr_version;
579 if (strcmp(prev_version, curr_version) != 0) {
584 "%s: DOD version changed\n"
587 curr_ds->
name, prev_version, curr_version);
616 for (di = 0; di < curr_ds->
ndims; ++di) {
618 curr_dim = curr_ds->
dims[di];
626 " - %s: dimension not found in previous dataset\n",
641 " - %s: dimension changed from UNLIMITED to %d\n",
647 " - %s: dimension changed from %d to UNLIMITED\n",
660 " - %s: length of dimension changed from %d to %d\n",
673 " - number of dimensions changed from %d to %d\n",
695 ExAtts *ex_atts = _dsproc_get_exclude_atts(NULL);
700 nchanges = _dsproc_compare_atts(
732 size_t prev_sample_size;
733 size_t curr_sample_size;
741 for (vi = 0; vi < curr_ds->
nvars; ++vi) {
744 curr_var = curr_ds->
vars[vi];
752 " - %s: variable not found in previous dataset\n",
760 if (prev_var->
type != curr_var->
type) {
763 " - %s: variable data type changed from %s to %s\n",
778 " - %s: number of variable dimensions changed from %d to %d\n",
787 for (di = 0; di < curr_var->
ndims; ++di) {
789 if (strcmp(curr_var->
dims[di]->
name,
793 " - %s: variable dimension changed from %s to %s\n",
805 ex_atts = _dsproc_get_exclude_atts(curr_var->
name);
807 natt_changes = _dsproc_compare_atts(
808 curr_var->
name, ex_atts,
812 if (natt_changes < 0) {
824 if ((curr_var->
ndims > 0) &&
832 ex_atts->exclude_data) {
860 if (prev_sample_size != curr_sample_size) {
882 memcmp(prev_var->
data.
vp, curr_var->
data.
vp, nbytes) != 0) {
885 " - %s: static variable data changed\n",
896 " - number of variables changed from %d to %d\n",
924 if (status < 0)
return (-1);
929 if (status < 0)
return (-1);
956 const char *var_name,
959 const char **att_names)
961 ExAtts *ex_atts = _dsproc_get_exclude_atts(var_name);
963 char **new_att_names;
970 ex_atts = (ExAtts *)calloc(1,
sizeof(ExAtts));
971 if (!ex_atts)
goto MEMORY_ERROR;
974 ex_atts->var_name = strdup(var_name);
975 if (!ex_atts->var_name) {
981 ex_atts->next = _ExAtts;
987 ex_atts->exclude_data = exclude_data;
991 if (natts && att_names) {
995 new_natts = natts + ex_atts->natts;
996 new_att_names = (
char **)realloc(
997 ex_atts->att_names, new_natts *
sizeof(
char *));
999 if (!new_att_names)
goto MEMORY_ERROR;
1001 ex_atts->att_names = new_att_names;
1005 for (ai = 0; ai < natts; ++ai) {
1009 for (aj = 0; aj < ex_atts->natts; ++aj) {
1010 if (strcmp(att_names[ai], ex_atts->att_names[aj]) == 0) {
1015 if (aj != ex_atts->natts)
continue;
1019 if (!(ex_atts->att_names[ex_atts->natts] = strdup(att_names[ai]))) {
1023 ex_atts->natts += 1;
1033 "Could not exclude variable attributes from dod compare for: %s\n"
1034 " -> memory allocation error\n", var_name);
1038 "Could not exclude global attributes from dod compare\n"
1039 " -> memory allocation error\n");