Skip to content

Commit 8f583ff

Browse files
committed
silence compile warning: %g for double %s for char
1 parent 8179e42 commit 8f583ff

File tree

1 file changed

+93
-37
lines changed

1 file changed

+93
-37
lines changed

src/utils/ncmpidiff/ncmpidiff.c

Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,63 +60,119 @@
6060
} \
6161
}
6262

63+
#define CHECK_GLOBAL_ATT_DIFF_CHAR { \
64+
int pos; \
65+
char *b1 = (char *)calloc((attlen[0] + 1) * 2, sizeof(char)); \
66+
char *b2 = b1 + attlen[0] + 1; \
67+
if (!b1) OOM_ERROR \
68+
err = ncmpi_get_att_text(ncid[0], NC_GLOBAL, name[0], b1); \
69+
HANDLE_ERROR \
70+
err = ncmpi_get_att_text(ncid[1], NC_GLOBAL, name[0], b2); \
71+
HANDLE_ERROR \
72+
for (pos=0; pos<attlen[0]; pos++) { \
73+
if (b1[pos] != b2[pos]) break; \
74+
} \
75+
if (pos != attlen[0]) { \
76+
char str[128], msg[1024]; \
77+
sprintf(msg, "DIFF: global "); \
78+
sprintf(str, "attribute \"%s\" of type NC_CHAR at element %d of ", \
79+
name[0], pos); \
80+
strcat(msg, str); \
81+
sprintf(str, "value \"%s\" vs \"%s\"\n", b1, b2); \
82+
strcat(msg, str); \
83+
printf("%s", msg); \
84+
numHeadDIFF++; \
85+
} \
86+
else if (verbose) \
87+
printf("\t\tSAME: attribute contents\n"); \
88+
free(b1); \
89+
break; \
90+
}
91+
6392
#define CHECK_GLOBAL_ATT_DIFF(type, func) { \
6493
int pos; \
65-
type *b1, *b2; \
66-
b1 = (type *)calloc((attlen[0] + 1) * 2, sizeof(type)); \
94+
type *b1 = (type *)calloc((attlen[0] + 1) * 2, sizeof(type)); \
95+
type *b2 = b1 + attlen[0] + 1; \
6796
if (!b1) OOM_ERROR \
68-
b2 = b1 + attlen[0] + 1; \
6997
err = func(ncid[0], NC_GLOBAL, name[0], b1); \
7098
HANDLE_ERROR \
7199
err = func(ncid[1], NC_GLOBAL, name[0], b2); \
72100
HANDLE_ERROR \
73101
for (pos=0; pos<attlen[0]; pos++) { \
74-
if (b1[pos] != b2[pos]) { \
75-
char str[128], msg[1024]; \
76-
sprintf(msg, "DIFF: global attribute \"%s\" of type \"%s\" at element %d of value ", \
77-
name[0], get_type(xtype[0]), pos); \
78-
if (xtype[0] == NC_CHAR) \
79-
sprintf(str, "\"%s\" vs \"%s\"\n", b1, b2); \
80-
else \
81-
sprintf(str, "%g vs %g (difference = %e)\n", b1,b2,b1-b2); \
82-
strcat(msg, str); \
83-
printf("%s", msg); \
84-
numHeadDIFF++; \
85-
break; \
86-
} \
102+
if (b1[pos] != b2[pos]) break; \
87103
} \
88-
if (pos == attlen[0] && verbose) \
89-
printf("\tSAME: attribute contents\n"); \
104+
if (pos != attlen[0]) { \
105+
char str[128], msg[1024]; \
106+
sprintf(msg, "DIFF: global "); \
107+
sprintf(str, "attribute \"%s\" of type \"%s\" at element %d of ", \
108+
name[0], get_type(xtype[0]), pos); \
109+
strcat(msg, str); \
110+
sprintf(str, "value %g vs %g (difference = %e)\n", \
111+
(double)b1[pos],(double)b2[pos],(double)(b1[pos]-b2[pos])); \
112+
strcat(msg, str); \
113+
printf("%s", msg); \
114+
numHeadDIFF++; \
115+
} \
116+
else if (verbose) \
117+
printf("\t\tSAME: attribute contents\n"); \
118+
free(b1); \
119+
break; \
120+
}
121+
122+
#define CHECK_VAR_ATT_DIFF_CHAR { \
123+
int pos; \
124+
char *b1 = (char *)calloc((attlen[0] + 1) * 2, sizeof(char)); \
125+
char *b2 = b1 + attlen[0] + 1; \
126+
if (!b1) OOM_ERROR \
127+
err = ncmpi_get_att_text(ncid[0], varid[0], attrname, b1); \
128+
HANDLE_ERROR \
129+
err = ncmpi_get_att_text(ncid[1], varid[1], attrname, b2); \
130+
HANDLE_ERROR \
131+
for (pos=0; pos<attlen[0]; pos++) { \
132+
if (b1[pos] != b2[pos]) break; \
133+
} \
134+
if (pos != attlen[0]) { \
135+
char str[1024], msg[1024]; \
136+
sprintf(msg, "DIFF: variable \"%s\" ", name[0]); \
137+
sprintf(str, "attribute \"%s\" of type NC_CHAR at element %d of ", \
138+
attrname, pos); \
139+
strcat(msg, str); \
140+
sprintf(str, "value \"%s\" vs \"%s\"\n", b1, b2); \
141+
strcat(msg, str); \
142+
printf("%s", msg); \
143+
numHeadDIFF++; \
144+
} \
145+
else if (verbose) \
146+
printf("\t\tSAME: attribute contents\n"); \
90147
free(b1); \
91148
break; \
92149
}
93150

94151
#define CHECK_VAR_ATT_DIFF(type, func) { \
95152
int pos; \
96-
type *b1, *b2; \
97-
b1 = (type *)calloc(attlen[0] * 2, sizeof(type)); \
153+
type *b1 = (type *)calloc((attlen[0] + 1) * 2, sizeof(type)); \
154+
type *b2 = b1 + attlen[0] + 1; \
98155
if (!b1) OOM_ERROR \
99-
b2 = b1 + attlen[0]; \
100156
err = func(ncid[0], varid[0], attrname, b1); \
101157
HANDLE_ERROR \
102158
err = func(ncid[1], varid[1], attrname, b2); \
103159
HANDLE_ERROR \
104160
for (pos=0; pos<attlen[0]; pos++) { \
105-
if (b1[pos] != b2[pos]) { \
106-
char str[128], msg[1024]; \
107-
sprintf(msg, "DIFF: variable \"%s\" attribute \"%s\" of type \"%s\" at element %d of value ", \
108-
name[0], attrname, get_type(xtype[0]), pos); \
109-
if (xtype[0] == NC_CHAR) \
110-
sprintf(str, "\"%s\" vs \"%s\"\n", b1, b2); \
111-
else \
112-
sprintf(str, "%g vs %g (difference = %e)\n", b1,b2,b1-b2); \
113-
strcat(msg, str); \
114-
printf("%s", msg); \
115-
numHeadDIFF++; \
116-
break; \
117-
} \
161+
if (b1[pos] != b2[pos]) break; \
162+
} \
163+
if (pos != attlen[0]) { \
164+
char str[1024], msg[1024]; \
165+
sprintf(msg, "DIFF: variable \"%s\" ", name[0]); \
166+
sprintf(str, "attribute \"%s\" of type \"%s\" at element %d of ", \
167+
attrname, get_type(xtype[0]), pos); \
168+
strcat(msg, str); \
169+
sprintf(str, "value %g vs %g (difference = %e)\n", \
170+
(double)b1[pos],(double)b2[pos],(double)(b1[pos]-b2[pos])); \
171+
strcat(msg, str); \
172+
printf("%s", msg); \
173+
numHeadDIFF++; \
118174
} \
119-
if (pos == attlen[0] && verbose) \
175+
else if (verbose) \
120176
printf("\t\tSAME: attribute contents\n"); \
121177
free(b1); \
122178
break; \
@@ -520,7 +576,7 @@ int main(int argc, char **argv)
520576

521577
/* compare attribute contents */
522578
switch (xtype[0]) {
523-
case NC_CHAR: CHECK_GLOBAL_ATT_DIFF(char, ncmpi_get_att_text);
579+
case NC_CHAR: CHECK_GLOBAL_ATT_DIFF_CHAR
524580
case NC_SHORT: CHECK_GLOBAL_ATT_DIFF(short, ncmpi_get_att_short);
525581
case NC_INT: CHECK_GLOBAL_ATT_DIFF(int, ncmpi_get_att_int);
526582
case NC_FLOAT: CHECK_GLOBAL_ATT_DIFF(float, ncmpi_get_att_float);
@@ -741,7 +797,7 @@ int main(int argc, char **argv)
741797

742798
/* compare attribute contents */
743799
switch (xtype[0]) {
744-
case NC_CHAR: CHECK_VAR_ATT_DIFF(char, ncmpi_get_att_text);
800+
case NC_CHAR: CHECK_VAR_ATT_DIFF_CHAR
745801
case NC_SHORT: CHECK_VAR_ATT_DIFF(short, ncmpi_get_att_short);
746802
case NC_INT: CHECK_VAR_ATT_DIFF(int, ncmpi_get_att_int);
747803
case NC_FLOAT: CHECK_VAR_ATT_DIFF(float, ncmpi_get_att_float);

0 commit comments

Comments
 (0)