|
|
|
@ -117,7 +117,8 @@ struct gmt_coord: public gmt_struct
|
|
|
|
|
if(isdeg) return (d+(m+s/60.0)/60.0)*(sign?1:-1); |
|
|
|
|
else return r; |
|
|
|
|
} |
|
|
|
|
bool Convert(const std::string& str) |
|
|
|
|
|
|
|
|
|
bool Convert(const std::string& str, std::string& err) |
|
|
|
|
{ |
|
|
|
|
WordList wl; |
|
|
|
|
WordList::const_iterator cw; |
|
|
|
@ -125,34 +126,37 @@ struct gmt_coord: public gmt_struct
|
|
|
|
|
if(1==wl.size()) // No dd:mm
|
|
|
|
|
{ |
|
|
|
|
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; |
|
|
|
|
int64_t res; |
|
|
|
|
|
|
|
|
|
// degrees
|
|
|
|
|
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; |
|
|
|
|
sign=(std::string::npos==cw->find('-')); |
|
|
|
|
d=static_cast<uint16_t>(sign?res:-res); |
|
|
|
|
// minutes
|
|
|
|
|
cw++; |
|
|
|
|
if(!str2int(*cw,&res)) return false; |
|
|
|
|
if(res<0 || res>=60) return false; |
|
|
|
|
if(!str2int(*cw,&res)) {err="Can't convert "+*cw+" to integer"; 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); |
|
|
|
|
s=0; |
|
|
|
|
|
|
|
|
|
// seconds
|
|
|
|
|
cw++; |
|
|
|
|
if(wl.end()==cw) return true; // No seconds
|
|
|
|
|
if(!str2double(*cw,&s) ) return false; |
|
|
|
|
if(s<0.0 || s>=60.0) return false; |
|
|
|
|
if(!str2double(*cw,&s) ) {err="Can't convert "+*cw+" to double"; 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; |
|
|
|
|
} |
|
|
|
|
bool Convert(double num) |
|
|
|
|
|
|
|
|
|
bool Convert(double num, std::string& err) |
|
|
|
|
{ |
|
|
|
|
isdeg=false; |
|
|
|
|
r=num; |
|
|
|
@ -182,24 +186,25 @@ struct gmt_region: public gmt_struct
|
|
|
|
|
|
|
|
|
|
// Only "global", "global180" and "global360"
|
|
|
|
|
// 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; |
|
|
|
|
tolower(str); |
|
|
|
|
if("global180"==str) |
|
|
|
|
{ |
|
|
|
|
type=GLOBAL180; |
|
|
|
|
xb.Convert(-180.0); xe.Convert(180.0); |
|
|
|
|
yb.Convert(-90.0); ye.Convert(90.0); |
|
|
|
|
xb.Convert(-180.0,err); xe.Convert(180.0,err); |
|
|
|
|
yb.Convert(-90.0,err); ye.Convert(90.0,err); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if("global360"==str || "global"==str) |
|
|
|
|
{ |
|
|
|
|
type=GLOBAL360; |
|
|
|
|
xb.Convert(0.0); xe.Convert(360.0); |
|
|
|
|
yb.Convert(-90.0); ye.Convert(90.0); |
|
|
|
|
xb.Convert(0.0,err); xe.Convert(360.0,err); |
|
|
|
|
yb.Convert(-90.0,err); ye.Convert(90.0,err); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
err="Can't convert "+istr+" to region."; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|