|
|
@ -117,7 +117,8 @@ struct gmt_coord: public gmt_struct |
|
|
|
if(isdeg) return (d+(m+s/60.0)/60.0)*(sign?1:-1); |
|
|
|
if(isdeg) return (d+(m+s/60.0)/60.0)*(sign?1:-1); |
|
|
|
else return r; |
|
|
|
else return r; |
|
|
|
} |
|
|
|
} |
|
|
|
bool Convert(const std::string& str) |
|
|
|
|
|
|
|
|
|
|
|
bool Convert(const std::string& str, std::string& err) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WordList wl; |
|
|
|
WordList wl; |
|
|
|
WordList::const_iterator cw; |
|
|
|
WordList::const_iterator cw; |
|
|
@ -125,34 +126,37 @@ struct gmt_coord: public gmt_struct |
|
|
|
if(1==wl.size()) // No dd:mm
|
|
|
|
if(1==wl.size()) // No dd:mm
|
|
|
|
{ |
|
|
|
{ |
|
|
|
isdeg=false; |
|
|
|
isdeg=false; |
|
|
|
return str2double(str,&r); |
|
|
|
bool res=str2double(str,&r); |
|
|
|
|
|
|
|
if(!res) err="Can't convert string "+str+" to double value"; |
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
if(0==wl.size() || wl.size()>3) return false; |
|
|
|
if(0==wl.size() || wl.size()>3) {err="String "+str+" have incorrect format for geographic coordinate, must be ddd[:mm[:ss[.fff]]]"; return false;} |
|
|
|
|
|
|
|
|
|
|
|
isdeg=true; |
|
|
|
isdeg=true; |
|
|
|
int64_t res; |
|
|
|
int64_t res; |
|
|
|
|
|
|
|
|
|
|
|
// degrees
|
|
|
|
// degrees
|
|
|
|
cw=wl.begin(); |
|
|
|
cw=wl.begin(); |
|
|
|
if(!str2int(*cw,&res)) return false; |
|
|
|
if(!str2int(*cw,&res)) {err="Can't convert "+*cw+" to integer"; return false;} |
|
|
|
if(res>360 || res<-360) res%=360; |
|
|
|
if(res>360 || res<-360) res%=360; |
|
|
|
sign=(std::string::npos==cw->find('-')); |
|
|
|
sign=(std::string::npos==cw->find('-')); |
|
|
|
d=static_cast<uint16_t>(sign?res:-res); |
|
|
|
d=static_cast<uint16_t>(sign?res:-res); |
|
|
|
// minutes
|
|
|
|
// minutes
|
|
|
|
cw++; |
|
|
|
cw++; |
|
|
|
if(!str2int(*cw,&res)) return false; |
|
|
|
if(!str2int(*cw,&res)) {err="Can't convert "+*cw+" to integer"; return false;} |
|
|
|
if(res<0 || res>=60) return false; |
|
|
|
if(res<0 || res>=60) {err="Minutes must be not lesser then 0 and lesser then 60"; return false;} |
|
|
|
m=static_cast<uint8_t>(res); |
|
|
|
m=static_cast<uint8_t>(res); |
|
|
|
s=0; |
|
|
|
s=0; |
|
|
|
|
|
|
|
|
|
|
|
// seconds
|
|
|
|
// seconds
|
|
|
|
cw++; |
|
|
|
cw++; |
|
|
|
if(wl.end()==cw) return true; // No seconds
|
|
|
|
if(wl.end()==cw) return true; // No seconds
|
|
|
|
if(!str2double(*cw,&s) ) return false; |
|
|
|
if(!str2double(*cw,&s) ) {err="Can't convert "+*cw+" to double"; return false;} |
|
|
|
if(s<0.0 || s>=60.0) return false; |
|
|
|
if(s<0.0 || s>=60.0) {err="Seconds must be not lesser then 0 and lesser then 60"; return false;} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
bool Convert(double num) |
|
|
|
|
|
|
|
|
|
|
|
bool Convert(double num, std::string& err) |
|
|
|
{ |
|
|
|
{ |
|
|
|
isdeg=false; |
|
|
|
isdeg=false; |
|
|
|
r=num; |
|
|
|
r=num; |
|
|
@ -182,24 +186,25 @@ struct gmt_region: public gmt_struct |
|
|
|
|
|
|
|
|
|
|
|
// Only "global", "global180" and "global360"
|
|
|
|
// Only "global", "global180" and "global360"
|
|
|
|
// TODO: add parsing of "-R" strings
|
|
|
|
// TODO: add parsing of "-R" strings
|
|
|
|
bool Convert(const std::string& istr) |
|
|
|
bool Convert(const std::string& istr, std::string& err) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string str=istr; |
|
|
|
std::string str=istr; |
|
|
|
tolower(str); |
|
|
|
tolower(str); |
|
|
|
if("global180"==str) |
|
|
|
if("global180"==str) |
|
|
|
{ |
|
|
|
{ |
|
|
|
type=GLOBAL180; |
|
|
|
type=GLOBAL180; |
|
|
|
xb.Convert(-180.0); xe.Convert(180.0); |
|
|
|
xb.Convert(-180.0,err); xe.Convert(180.0,err); |
|
|
|
yb.Convert(-90.0); ye.Convert(90.0); |
|
|
|
yb.Convert(-90.0,err); ye.Convert(90.0,err); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if("global360"==str || "global"==str) |
|
|
|
if("global360"==str || "global"==str) |
|
|
|
{ |
|
|
|
{ |
|
|
|
type=GLOBAL360; |
|
|
|
type=GLOBAL360; |
|
|
|
xb.Convert(0.0); xe.Convert(360.0); |
|
|
|
xb.Convert(0.0,err); xe.Convert(360.0,err); |
|
|
|
yb.Convert(-90.0); ye.Convert(90.0); |
|
|
|
yb.Convert(-90.0,err); ye.Convert(90.0,err); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
err="Can't convert "+istr+" to region."; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|