Browse Source

Gmt module: Using Split instead of manual splitting.

ObjPtr
Michael Uleysky 9 years ago
parent
commit
ff4503585c
  1. 15
      modules/gmt/modgmt_internals.cpp
  2. 31
      modules/gmt/modgmt_structs.h

15
modules/gmt/modgmt_internals.cpp

@ -98,7 +98,8 @@ bool ProjectionRealSize(struct gmt_projection& p, double height)
std::string wh; std::string wh;
double w,h; double w,h;
double sw=p.width; double sw=p.width;
size_t pos; WordList wl;
WordList::const_iterator cw;
gmtapi=GMT_Create_Session("ProjectionRealSize",2,GMTMODE,0); gmtapi=GMT_Create_Session("ProjectionRealSize",2,GMTMODE,0);
if(0==gmtapi) return false; if(0==gmtapi) return false;
@ -108,12 +109,12 @@ bool ProjectionRealSize(struct gmt_projection& p, double height)
GMT_Destroy_Session(gmtapi); GMT_Destroy_Session(gmtapi);
if(0!=ret) return false; if(0!=ret) return false;
pos=wh.find('\n'); wl=Split(wh," \t\n");
if(std::string::npos!=pos) wh.erase(pos); if(2!=wl.size()) return false;
pos=wh.find_first_of(" \t",0,2); cw=wl.begin();
if(std::string::npos==pos) return false; if(!str2double(*cw,&w)) return false;
if(!str2double(std::string(wh.c_str(),wh.c_str()+pos),&w)) return false; cw++;
if(!str2double(wh.substr(pos+1),&h)) return false; if(!str2double(*cw,&h)) return false;
if(height>0.0) if(height>0.0)
{ {
p.width=height/h; p.width=height/h;

31
modules/gmt/modgmt_structs.h

@ -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;
m=static_cast<uint8_t>(res);
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; if(res<0 || res>=60) return false;
m=static_cast<uint8_t>(res); m=static_cast<uint8_t>(res);
s=0;
// 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;
} }

Loading…
Cancel
Save