|
|
@ -33,37 +33,36 @@ struct gmt_coord |
|
|
|
} |
|
|
|
} |
|
|
|
bool Convert(const std::string& str) |
|
|
|
bool Convert(const std::string& str) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t bpos=0,pos=str.find(':'); |
|
|
|
WordList wl; |
|
|
|
if(std::string::npos==pos) |
|
|
|
WordList::const_iterator cw; |
|
|
|
|
|
|
|
wl=Split(str,":",true); |
|
|
|
|
|
|
|
if(1==wl.size()) // No dd:mm
|
|
|
|
{ |
|
|
|
{ |
|
|
|
isdeg=false; |
|
|
|
isdeg=false; |
|
|
|
return str2double(str,&r); |
|
|
|
return str2double(str,&r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(0==wl.size() || wl.size()>3) return false; |
|
|
|
|
|
|
|
|
|
|
|
isdeg=true; |
|
|
|
isdeg=true; |
|
|
|
int64_t res; |
|
|
|
int64_t res; |
|
|
|
|
|
|
|
|
|
|
|
// degrees
|
|
|
|
// degrees
|
|
|
|
if(! str2int(std::string(str.c_str(),str.c_str()+pos),&res) ) return false; |
|
|
|
cw=wl.begin(); |
|
|
|
|
|
|
|
if(!str2int(*cw,&res)) return false; |
|
|
|
if(res>360 || res<-360) res%=360; |
|
|
|
if(res>360 || res<-360) res%=360; |
|
|
|
sign=(std::string::npos==str.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
|
|
|
|
bpos=pos+1; |
|
|
|
cw++; |
|
|
|
pos=str.find(':',bpos); |
|
|
|
if(!str2int(*cw,&res)) return false; |
|
|
|
if(std::string::npos==pos) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!str2int(str.substr(bpos),&res)) return false; |
|
|
|
|
|
|
|
if(res<0 || res>=60) return false; |
|
|
|
if(res<0 || res>=60) return false; |
|
|
|
m=static_cast<uint8_t>(res); |
|
|
|
m=static_cast<uint8_t>(res); |
|
|
|
s=0; |
|
|
|
s=0; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(! str2int(std::string(str.c_str()+bpos,str.c_str()+pos),&res) ) return false; |
|
|
|
|
|
|
|
if(res<0 || res>=60) return false; |
|
|
|
|
|
|
|
m=static_cast<uint8_t>(res); |
|
|
|
|
|
|
|
// seconds
|
|
|
|
// seconds
|
|
|
|
if(! str2double(str.substr(pos+1),&s) ) return false; |
|
|
|
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(s<0.0 || s>=60.0) return false; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|