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

29
modules/gmt/modgmt_structs.h

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

Loading…
Cancel
Save