| 1 |
#include <cstdio> |
| 2 |
#include <cstdlib> |
| 3 |
#include <cstdint> |
| 4 |
#include <cmath> |
| 5 |
#include <cstring> |
| 6 |
|
| 7 |
#define ABS 0 |
| 8 |
#define REL 1 |
| 9 |
#define NORM2 2 |
| 10 |
#define PSNR 3 |
| 11 |
|
| 12 |
|
| 13 |
#define LITTLE_ENDIAN_SYSTEM 0 |
| 14 |
#define BIG_ENDIAN_SYSTEM 1 |
| 15 |
#define LITTLE_ENDIAN_DATA 0 |
| 16 |
#define BIG_ENDIAN_DATA 1 |
| 17 |
|
| 18 |
|
| 19 |
int sysEndianType = LITTLE_ENDIAN_SYSTEM; |
| 20 |
int dataEndianType = LITTLE_ENDIAN_DATA; |
| 21 |
|
| 22 |
typedef union ldouble |
| 23 |
{ |
| 24 |
double value; |
| 25 |
uint64_t lvalue; |
| 26 |
unsigned char byte[8]; |
| 27 |
} ldouble; |
| 28 |
|
| 29 |
ldouble buf; |
| 30 |
|
| 31 |
void usage() |
| 32 |
{ |
| 33 |
printf("Usage: print_h5repack_args <options>\n"); |
| 34 |
printf("Options:\n"); |
| 35 |
printf(" -M <error bound mode> : 10 options as follows. \n"); |
| 36 |
printf(" ABS (absolute error bound)\n"); |
| 37 |
printf(" REL (value range based error bound, so a.k.a., VR_REL)\n"); |
| 38 |
printf(" PSNR (peak signal-to-noise ratio)\n"); |
| 39 |
printf(" NORM2 (norm2)\n"); |
| 40 |
printf(" -A <absolute error bound>: specifying absolute error bound\n"); |
| 41 |
printf(" -R <value_range based relative error bound>: specifying relative error bound\n"); |
| 42 |
printf(" -N <norm2>: specifying norm2 error bound\n"); |
| 43 |
printf(" -S <PSNR>: specifying PSNR\n"); |
| 44 |
printf("* examples: \n"); |
| 45 |
printf(" print_h5repack_args -M ABS -A 1E-3 (output: -f UD=32024,0,9,0,1062232653,3539053052,0,0,0,0,0,0)\n"); |
| 46 |
printf(" print_h5repack_args -M REL -R 1E-4 (output: -f UD=32024,0,9,1,0,0,1058682594,3944497965,0,0,0,0)\n"); |
| 47 |
exit(0); |
| 48 |
} |
| 49 |
|
| 50 |
int bytesToInt32_bigEndian(unsigned char* bytes) |
| 51 |
{ |
| 52 |
int temp = 0; |
| 53 |
int res = 0; |
| 54 |
|
| 55 |
res <<= 8; |
| 56 |
temp = bytes[0] & 0xff; |
| 57 |
res |= temp; |
| 58 |
|
| 59 |
res <<= 8; |
| 60 |
temp = bytes[1] & 0xff; |
| 61 |
res |= temp; |
| 62 |
|
| 63 |
res <<= 8; |
| 64 |
temp = bytes[2] & 0xff; |
| 65 |
res |= temp; |
| 66 |
|
| 67 |
res <<= 8; |
| 68 |
temp = bytes[3] & 0xff; |
| 69 |
res |= temp; |
| 70 |
|
| 71 |
return res; |
| 72 |
} |
| 73 |
|
| 74 |
void symTransform_8bytes(unsigned char data[8]) |
| 75 |
{ |
| 76 |
unsigned char tmp = data[0]; |
| 77 |
data[0] = data[7]; |
| 78 |
data[7] = tmp; |
| 79 |
|
| 80 |
tmp = data[1]; |
| 81 |
data[1] = data[6]; |
| 82 |
data[6] = tmp; |
| 83 |
|
| 84 |
tmp = data[2]; |
| 85 |
data[2] = data[5]; |
| 86 |
data[5] = tmp; |
| 87 |
|
| 88 |
tmp = data[3]; |
| 89 |
data[3] = data[4]; |
| 90 |
data[4] = tmp; |
| 91 |
} |
| 92 |
|
| 93 |
void doubleToBytes(unsigned char *b, double num) |
| 94 |
{ |
| 95 |
ldouble buf; |
| 96 |
buf.value = num; |
| 97 |
memcpy(b, buf.byte, 8); |
| 98 |
if(sysEndianType==LITTLE_ENDIAN_SYSTEM) |
| 99 |
symTransform_8bytes(b); |
| 100 |
} |
| 101 |
|
| 102 |
int main(int argc, char* argv[]) |
| 103 |
{ |
| 104 |
char* errBoundMode = NULL; |
| 105 |
char* absErrorBound = NULL; |
| 106 |
char* relErrorBound = NULL; |
| 107 |
char* norm2ErrorBound = NULL; |
| 108 |
char* psnr_ = NULL; |
| 109 |
|
| 110 |
if(argc==1) |
| 111 |
usage(); |
| 112 |
|
| 113 |
int i = 0; |
| 114 |
|
| 115 |
for(i=1;i<argc;i++) |
| 116 |
{ |
| 117 |
if (argv[i][0] != '-' || argv[i][2]) |
| 118 |
usage(); |
| 119 |
switch (argv[i][1]) |
| 120 |
{ |
| 121 |
case 'h': |
| 122 |
usage(); |
| 123 |
exit(0); |
| 124 |
break; |
| 125 |
case 'M': |
| 126 |
if (++i == argc) |
| 127 |
usage(); |
| 128 |
errBoundMode = argv[i]; |
| 129 |
break; |
| 130 |
case 'A': |
| 131 |
if (++i == argc) |
| 132 |
usage(); |
| 133 |
absErrorBound = argv[i]; |
| 134 |
break; |
| 135 |
case 'R': |
| 136 |
if (++i == argc) |
| 137 |
usage(); |
| 138 |
relErrorBound = argv[i]; |
| 139 |
break; |
| 140 |
case 'N': |
| 141 |
if (++i == argc) |
| 142 |
usage(); |
| 143 |
norm2ErrorBound = argv[i]; |
| 144 |
break; |
| 145 |
case 'S': |
| 146 |
if (++i == argc) |
| 147 |
usage(); |
| 148 |
psnr_ = argv[i]; |
| 149 |
break; |
| 150 |
default: |
| 151 |
usage(); |
| 152 |
break; |
| 153 |
} |
| 154 |
} |
| 155 |
unsigned char b[8]; |
| 156 |
unsigned int cd_values[9]; |
| 157 |
if(strcmp(errBoundMode, "ABS")==0) |
| 158 |
{ |
| 159 |
cd_values[0] = ABS; |
| 160 |
doubleToBytes(b, atof(absErrorBound)); |
| 161 |
cd_values[1] = bytesToInt32_bigEndian(b); |
| 162 |
cd_values[2] = bytesToInt32_bigEndian(b+4); |
| 163 |
cd_values[3] = 0; |
| 164 |
cd_values[4] = 0; |
| 165 |
cd_values[5] = 0; |
| 166 |
cd_values[6] = 0; |
| 167 |
cd_values[7] = 0; |
| 168 |
cd_values[8] = 0; |
| 169 |
} |
| 170 |
else if(strcmp(errBoundMode, "REL")==0) |
| 171 |
{ |
| 172 |
cd_values[0] = REL; |
| 173 |
cd_values[1] = 0; |
| 174 |
cd_values[2] = 0; |
| 175 |
doubleToBytes(b, atof(relErrorBound)); |
| 176 |
cd_values[3] = bytesToInt32_bigEndian(b); |
| 177 |
cd_values[4] = bytesToInt32_bigEndian(b+4); |
| 178 |
cd_values[5] = 0; |
| 179 |
cd_values[6] = 0; |
| 180 |
cd_values[7] = 0; |
| 181 |
cd_values[8] = 0; |
| 182 |
} |
| 183 |
else if(strcmp(errBoundMode, "NORM2")==0) |
| 184 |
{ |
| 185 |
cd_values[0] = NORM2; |
| 186 |
cd_values[1] = 0; |
| 187 |
cd_values[2] = 0; |
| 188 |
cd_values[3] = 0; |
| 189 |
cd_values[4] = 0; |
| 190 |
doubleToBytes(b, atof(norm2ErrorBound)); |
| 191 |
cd_values[5] = bytesToInt32_bigEndian(b); |
| 192 |
cd_values[6] = bytesToInt32_bigEndian(b+4); |
| 193 |
cd_values[7] = 0; |
| 194 |
cd_values[8] = 0; |
| 195 |
} |
| 196 |
else if(strcmp(errBoundMode, "PSNR")==0) |
| 197 |
{ |
| 198 |
cd_values[0] = PSNR; |
| 199 |
cd_values[1] = 0; |
| 200 |
cd_values[2] = 0; |
| 201 |
cd_values[3] = 0; |
| 202 |
cd_values[4] = 0; |
| 203 |
cd_values[5] = 0; |
| 204 |
cd_values[6] = 0; |
| 205 |
doubleToBytes(b, atof(psnr_)); |
| 206 |
cd_values[7] = bytesToInt32_bigEndian(b); |
| 207 |
cd_values[8] = bytesToInt32_bigEndian(b+4); |
| 208 |
} |
| 209 |
else |
| 210 |
{ |
| 211 |
printf("Error: wrong errBoundMode setting.\n"); |
| 212 |
exit(0); |
| 213 |
} |
| 214 |
printf("-f UD=32024,0,9"); |
| 215 |
|
| 216 |
for(i=0;i<9;i++) |
| 217 |
printf(",%u",cd_values[i]); |
| 218 |
printf("\n"); |
| 219 |
} |