@@ -78,25 +78,27 @@ static void usage(const char* appName) {
7878 printf (" Copyright (C) 2014 Stichting Mapcode Foundation\n " );
7979 printf (" \n " );
8080 printf (" Usage:\n " );
81- printf (" %s [-d | --decode] <default-territory> <mapcode> [<mapcode> ...]\n " , appName);
81+ printf (" %s [-d| --decode] <default-territory> <mapcode> [<mapcode> ...]\n " , appName);
8282 printf (" \n " );
83- printf (" Decode a Mapcode to a lat/lon. The default territory code is used if\n " );
84- printf (" the Mapcode is a shorthand local code\n " );
83+ printf (" Decode a mapcode to a lat/lon. The default territory code is used if\n " );
84+ printf (" the mapcode is a shorthand local code\n " );
8585 printf (" \n " );
86- printf (" %s [-e | --encode] <lat:-90..90> <lon:-180..180> [territory]>\n " , appName);
86+ printf (" %s [-e[0-2] | --encode[0-2] ] <lat:-90..90> <lon:-180..180> [territory]>\n " , appName);
8787 printf (" \n " );
88- printf (" Encode a lat/lon to a Mapcode . If the territory code is specified, the\n " );
88+ printf (" Encode a lat/lon to a mapcode . If the territory code is specified, the\n " );
8989 printf (" encoding will only succeeed if the lat/lon is located in the territory.\n " );
90+ printf (" You can specify the number of additional digits, 0, 1 or 2 (default 0)\n " );
91+ printf (" for high-precision mapcodes.\n " );
9092 printf (" \n " );
9193 printf (" %s [-b[XYZ] | --boundaries[XYZ]] [<extraDigits>]\n " , appName);
9294 printf (" %s [-g[XYZ] | --grid[XYZ]] <nrOfPoints> [<extraDigits>]\n " , appName);
9395 printf (" %s [-r[XYZ] | --random[XYZ]] <nrOfPoints> [<extraDigits>] [<seed>]\n " , appName);
9496 printf (" \n " );
95- printf (" Create a test set of lat/lon pairs based on the Mapcode boundaries database\n " );
97+ printf (" Create a test set of lat/lon pairs based on the mapcode boundaries database\n " );
9698 printf (" as a fixed 3D grid or random uniformly distributed set of lat/lons with their\n " );
97- printf (" (x, y, z) coordinates and all Mapcode aliases.\n " );
99+ printf (" (x, y, z) coordinates and all mapcode aliases.\n " );
98100 printf (" \n " );
99- printf (" <extraDigits> specifies additional accuracy, use 0 for standard.\n " );
101+ printf (" <extraDigits>: 0, 1, 2; specifies additional accuracy, use 0 for standard.\n " );
100102 printf (" <seed> is an optional random seed, use 0 for arbitrary>.\n " );
101103 printf (" (You may wish to specify a specific seed to regenerate test cases).\n " );
102104 printf (" \n " );
@@ -192,7 +194,7 @@ static void selfCheckLatLonToMapcode(const double lat, double lon, const char* t
192194 const double limitLon = (lon < -180.0 ) ? -180.0 : ((lon > 180.0 ) ? 180.0 : lon);
193195 const int nrResults = encodeLatLonToMapcodes (results, limitLat, limitLon, context, extraDigits);
194196 if (nrResults <= 0 ) {
195- fprintf (stderr, " internal error: encoding lat/lon to Mapcode failure; "
197+ fprintf (stderr, " error: encoding lat/lon to mapcode failure; "
196198 " cannot encode lat=%f, lon=%f (default territory=%s)\n " ,
197199 lat, lon, territory);
198200 if (SELF_CHECK_EXIT) {
@@ -207,8 +209,8 @@ static void selfCheckLatLonToMapcode(const double lat, double lon, const char* t
207209 found = ((strcmp (territory, foundTerritory) == 0 ) && (strcmp (mapcode, foundMapcode) == 0 ));
208210 }
209211 if (!found) {
210- fprintf (stderr, " internal error: encoding lat/lon to Mapcode failure; "
211- " Mapcode '%s %s' decodes to lat=%f(%f), lon=%f(%f), "
212+ fprintf (stderr, " error: encoding lat/lon to mapcode failure; "
213+ " mapcode '%s %s' decodes to lat=%f(%f), lon=%f(%f), "
212214 " which does not encode back to '%s %s'\n " ,
213215 territory, mapcode, lat, limitLat, lon, limitLon, territory, mapcode);
214216 if (SELF_CHECK_EXIT) {
@@ -230,7 +232,7 @@ static void selfCheckMapcodeToLatLon(const char* territory, const char* mapcode,
230232 int foundContext = convertTerritoryIsoNameToCode (territory, 0 );
231233 int err = decodeMapcodeToLatLon (&foundLat, &foundLon, mapcode, foundContext);
232234 if (err != 0 ) {
233- fprintf (stderr, " internal error: decoding Mapcode to lat/lon failure; "
235+ fprintf (stderr, " error: decoding mapcode to lat/lon failure; "
234236 " cannot decode '%s %s')\n " , territory, mapcode);
235237 if (SELF_CHECK_EXIT) {
236238 exit (INTERNAL_ERROR);
@@ -243,8 +245,8 @@ static void selfCheckMapcodeToLatLon(const char* territory, const char* mapcode,
243245 deltaLon = 360.0 - deltaLon;
244246 }
245247 if ((deltaLat > DELTA) || (deltaLon > DELTA)) {
246- fprintf (stderr, " internal error: decoding Mapcode to lat/lon failure; "
247- " lat=%f, lon=%f produces Mapcode %s %s, "
248+ fprintf (stderr, " error: decoding mapcode to lat/lon failure; "
249+ " lat=%f, lon=%f produces mapcode %s %s, "
248250 " which decodes to lat=%f (delta=%f), lon=%f (delta=%f)\n " ,
249251 lat, lon, territory, mapcode, foundLat, deltaLat, foundLon, deltaLon);
250252 if (SELF_CHECK_EXIT) {
@@ -368,10 +370,10 @@ static void resetStatistics(int nrOfPoints) {
368370static void outputStatistics () {
369371 fprintf (stderr, " \n Statistics:\n " );
370372 fprintf (stderr, " Total number of 3D points generated = %d\n " , totalNrOfPoints);
371- fprintf (stderr, " Total number of Mapcodes generated = %d\n " , totalNrOfResults);
372- fprintf (stderr, " Average number of Mapcodes per 3D point = %f\n " ,
373+ fprintf (stderr, " Total number of mapcodes generated = %d\n " , totalNrOfResults);
374+ fprintf (stderr, " Average number of mapcodes per 3D point = %f\n " ,
373375 ((float ) totalNrOfResults) / ((float ) totalNrOfPoints));
374- fprintf (stderr, " Largest number of results for 1 Mapcode = %d at (%f, %f)\n " ,
376+ fprintf (stderr, " Largest number of results for 1 mapcode = %d at (%f, %f)\n " ,
375377 largestNrOfResults, latLargestNrOfResults, lonLargestNrOfResults);
376378}
377379
@@ -381,7 +383,7 @@ static void outputStatistics() {
381383 * This method shows a progress indication.
382384 */
383385static void showProgress (int i) {
384- fprintf (stderr, " [%d%%] Processed %d of %d regions (generated %d Mapcodes )...\r " ,
386+ fprintf (stderr, " [%d%%] Processed %d of %d regions (generated %d mapcodes )...\r " ,
385387 (int ) ((((float ) i / ((float ) totalNrOfPoints)) * 100.0 ) + 0.5 ),
386388 i, totalNrOfPoints, totalNrOfResults);
387389}
@@ -447,10 +449,13 @@ int main(const int argc, const char** argv)
447449 }
448450 }
449451 }
450- else if ((strcmp (cmd, " -e" ) == 0 ) || (strcmp (cmd, " --encode" ) == 0 )) {
452+ else if ((strcmp (cmd, " -e" ) == 0 ) || (strcmp (cmd, " -e0" ) == 0 ) ||
453+ (strcmp (cmd, " -e1" ) == 0 ) || (strcmp (cmd, " -e2" ) == 0 ) ||
454+ (strcmp (cmd, " --encode" ) == 0 ) || (strcmp (cmd, " --encode0" ) == 0 ) ||
455+ (strcmp (cmd, " --encode1" ) == 0 ) || (strcmp (cmd, " --encode2" ) == 0 )) {
451456
452457 // ------------------------------------------------------------------
453- // Encode: [-e | --encode] <lat:-90..90> <lon:-180..180> [territory]>
458+ // Encode: [-e[0-2] | --encode[0-2] ] <lat:-90..90> <lon:-180..180> [territory]>
454459 // ------------------------------------------------------------------
455460 if ((argc != 4 ) && (argc != 5 )) {
456461 fprintf (stderr, " error: incorrect number of arguments\n\n " );
@@ -465,6 +470,16 @@ int main(const int argc, const char** argv)
465470 const double lat = atof (argv[2 ]);
466471 const double lon = atof (argv[3 ]);
467472
473+ if (strstr (cmd, " -e1" ) || strstr (cmd, " --encode1" )) {
474+ extraDigits = 1 ;
475+ }
476+ else if (strstr (cmd, " -e2" ) || strstr (cmd, " --encode2" )) {
477+ extraDigits = 2 ;
478+ }
479+ else {
480+ extraDigits = 0 ;
481+ }
482+
468483 // Get territory context.
469484 int context = 0 ;
470485 const char * defaultTerritory = " AAA" ;
@@ -507,6 +522,11 @@ int main(const int argc, const char** argv)
507522 }
508523 if (argc == 3 ) {
509524 extraDigits = atoi (argv[2 ]);
525+ if ((extraDigits < 0 ) || (extraDigits> 2 )) {
526+ fprintf (stderr, " error: parameter extraDigits must be in [0..2]\n\n " );
527+ usage (appName);
528+ return NORMAL_ERROR;
529+ }
510530 }
511531 useXYZ = (strstr (cmd, " XYZ" ) != 0 );
512532
@@ -595,6 +615,11 @@ int main(const int argc, const char** argv)
595615 else {
596616 if (argc == 4 ) {
597617 extraDigits = atoi (argv[3 ]);
618+ if ((extraDigits < 0 ) || (extraDigits> 2 )) {
619+ fprintf (stderr, " error: parameter extraDigits must be in [0..2]\n\n " );
620+ usage (appName);
621+ return NORMAL_ERROR;
622+ }
598623 }
599624 }
600625 useXYZ = (strstr (cmd, " XYZ" ) != 0 );
0 commit comments