23 +
"d not in [-90d, 90d]");
30 prec =
max(0,
min(
int(maxprec_), prec));
34 ilon =
x * mult1_ / m_,
35 ilat =
y * mult1_ / m_;
36 x -= ilon * m_ / mult1_;
y -= ilat * m_ / mult1_;
39 for (
int c = lonlen_;
c--;) {
40 gars1[
c] = digits_[ ilon % baselon_]; ilon /= baselon_;
42 for (
int c = latlen_;
c--;) {
43 gars1[lonlen_ +
c] = letters_[ilat % baselat_]; ilat /= baselat_;
46 ilon =
x / mult3_; ilat =
y / mult3_;
47 gars1[baselen_] = digits_[mult2_ * (mult2_ - 1 - ilat) + ilon + 1];
49 ilon =
x % mult3_; ilat =
y % mult3_;
50 gars1[baselen_ + 1] = digits_[mult3_ * (mult3_ - 1 - ilat) + ilon + 1];
53 gars.resize(baselen_ + prec);
54 copy(gars1, gars1 + baselen_ + prec, gars.begin());
58 int& prec,
bool centerp) {
59 int len =
int(gars.length());
61 toupper(gars[0]) ==
'I' &&
62 toupper(gars[1]) ==
'N' &&
63 toupper(gars[2]) ==
'V') {
68 throw GeographicErr(
"GARS must have at least 5 characters " + gars);
70 throw GeographicErr(
"GARS can have at most 7 characters " + gars);
71 int prec1 =
len - baselen_;
73 for (
int c = 0;
c < lonlen_; ++
c) {
77 ilon = ilon * baselon_ + k;
79 if (!(ilon >= 1 && ilon <= 720))
80 throw GeographicErr(
"Initial digits in GARS must lie in [1, 720] " +
84 for (
int c = 0;
c < latlen_; ++
c) {
87 throw GeographicErr(
"Illegal letters in GARS " + gars.substr(3,2));
88 ilat = ilat * baselat_ + k;
91 throw GeographicErr(
"GARS letters must lie in [AA, QZ] " + gars);
94 lat1 = ilat + latorig_ * unit,
95 lon1 = ilon + lonorig_ * unit;
98 if (!(k >= 1 && k <= mult2_ * mult2_))
99 throw GeographicErr(
"6th character in GARS must [1, 4] " + gars);
102 lat1 = mult2_ * lat1 + (mult2_ - 1 - k / mult2_);
103 lon1 = mult2_ * lon1 + (k % mult2_);
107 throw GeographicErr(
"7th character in GARS must [1, 9] " + gars);
110 lat1 = mult3_ * lat1 + (mult3_ - 1 - k / mult3_);
111 lon1 = mult3_ * lon1 + (k % mult3_);
115 unit *= 2; lat1 = 2 * lat1 + 1; lon1 = 2 * lon1 + 1;