|
60 | 60 | } \ |
61 | 61 | } |
62 | 62 |
|
| 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 | + |
63 | 92 | #define CHECK_GLOBAL_ATT_DIFF(type, func) { \ |
64 | 93 | 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; \ |
67 | 96 | if (!b1) OOM_ERROR \ |
68 | | - b2 = b1 + attlen[0] + 1; \ |
69 | 97 | err = func(ncid[0], NC_GLOBAL, name[0], b1); \ |
70 | 98 | HANDLE_ERROR \ |
71 | 99 | err = func(ncid[1], NC_GLOBAL, name[0], b2); \ |
72 | 100 | HANDLE_ERROR \ |
73 | 101 | 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; \ |
87 | 103 | } \ |
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"); \ |
90 | 147 | free(b1); \ |
91 | 148 | break; \ |
92 | 149 | } |
93 | 150 |
|
94 | 151 | #define CHECK_VAR_ATT_DIFF(type, func) { \ |
95 | 152 | 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; \ |
98 | 155 | if (!b1) OOM_ERROR \ |
99 | | - b2 = b1 + attlen[0]; \ |
100 | 156 | err = func(ncid[0], varid[0], attrname, b1); \ |
101 | 157 | HANDLE_ERROR \ |
102 | 158 | err = func(ncid[1], varid[1], attrname, b2); \ |
103 | 159 | HANDLE_ERROR \ |
104 | 160 | 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++; \ |
118 | 174 | } \ |
119 | | - if (pos == attlen[0] && verbose) \ |
| 175 | + else if (verbose) \ |
120 | 176 | printf("\t\tSAME: attribute contents\n"); \ |
121 | 177 | free(b1); \ |
122 | 178 | break; \ |
@@ -520,7 +576,7 @@ int main(int argc, char **argv) |
520 | 576 |
|
521 | 577 | /* compare attribute contents */ |
522 | 578 | 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 |
524 | 580 | case NC_SHORT: CHECK_GLOBAL_ATT_DIFF(short, ncmpi_get_att_short); |
525 | 581 | case NC_INT: CHECK_GLOBAL_ATT_DIFF(int, ncmpi_get_att_int); |
526 | 582 | case NC_FLOAT: CHECK_GLOBAL_ATT_DIFF(float, ncmpi_get_att_float); |
@@ -741,7 +797,7 @@ int main(int argc, char **argv) |
741 | 797 |
|
742 | 798 | /* compare attribute contents */ |
743 | 799 | 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 |
745 | 801 | case NC_SHORT: CHECK_VAR_ATT_DIFF(short, ncmpi_get_att_short); |
746 | 802 | case NC_INT: CHECK_VAR_ATT_DIFF(int, ncmpi_get_att_int); |
747 | 803 | case NC_FLOAT: CHECK_VAR_ATT_DIFF(float, ncmpi_get_att_float); |
|
0 commit comments