diff --git a/modules/gmt/modgmt_objects.cpp b/modules/gmt/modgmt_objects.cpp index b9ee173..9a4b0e8 100644 --- a/modules/gmt/modgmt_objects.cpp +++ b/modules/gmt/modgmt_objects.cpp @@ -36,41 +36,15 @@ std::map gmt_projection::projnames; void gmt_projection::FillProjNames() { - projnames["x"]=XY; - projnames["xy"]=XY; - projnames["decart"]=XY; - - projnames["q"]=CYL_EQU; - projnames["cyl_equid"]=CYL_EQU; - projnames["cylindrical equidistant"]=CYL_EQU; - - projnames["m"]=MERCATOR; - projnames["merc"]=MERCATOR; + projnames["(xy|decart)"]=XY; + projnames["c[ylindrical][( |_)]equidistant"]=CYL_EQU; projnames["mercator"]=MERCATOR; - - projnames["t"]=TRANSMERCATOR; - projnames["tmerc"]=TRANSMERCATOR; - projnames["transverse mercator"]=TRANSMERCATOR; - - projnames["o"]=OBLIQMERCATOR; - projnames["omerc"]=OBLIQMERCATOR; - projnames["oblique mercator"]=OBLIQMERCATOR; - - projnames["c"]=CASSINI; + projnames["t[ransverse][( |_)]mercator"]=TRANSMERCATOR; + projnames["o[blique][( |_)]mercator"]=OBLIQMERCATOR; projnames["cassini"]=CASSINI; - - projnames["y"]=CYL_EQA; - projnames["cyl_equala"]=CYL_EQA; - projnames["cylindrical equal-area"]=CYL_EQA; - projnames["cylindrical equalarea"]=CYL_EQA; - - projnames["j"]=MILLER; - projnames["cyl_miller"]=MILLER; - projnames["miller"]=MILLER; - projnames["cylindrical miller"]=MILLER; - - projnames["cyl_stere"]=CYL_STERE; - projnames["cylindrical stereographic"]=CYL_STERE; + projnames["c[ylindrical][( |_)]eq[ua(l|l-)]area"]=CYL_EQA; + projnames["[c[ylindrical][( |_)]]miller"]=MILLER; + projnames["c[ylindrical][( |_)]stereographic"]=CYL_STERE; } bool gmt_font::FillFontNames() diff --git a/modules/gmt/modgmt_structs.h b/modules/gmt/modgmt_structs.h index a82280b..a33d58a 100644 --- a/modules/gmt/modgmt_structs.h +++ b/modules/gmt/modgmt_structs.h @@ -6,6 +6,7 @@ #include #include "common.h" #include "modgmt_colornames.h" +#include "modgmt_strcomp.h" // Centimeters to GMT points scale factor // 1 inch = 72 pt = 2.54 cm --> 1 cm = 72/2.54 pt @@ -277,24 +278,58 @@ struct gmt_projection: public gmt_struct case(OType::C): {ret="-JOb"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.polelon.Value()+"/"+o.polelat.Value()+"/"+ToString(width)+"c"; break;} default: return ""; } + break; } case(CASSINI): {ret="-JC"+c.clon.Value()+"/"+c.clat.Value()+"/"+ToString(width)+"c"; break;} - case(CYL_EQA): {ret="-JY"+y.stpar.Value()+"/"+y.cmer.Value()+"/"+ToString(width)+"c"; break;} + case(CYL_EQA): {ret="-JY"+y.cmer.Value()+"/"+y.stpar.Value()+"/"+ToString(width)+"c"; break;} case(MILLER): {ret="-JJ"+j.cmer.Value()+"/"+ToString(width)+"c"; break;} - case(CYL_STERE): {ret="-JCyl_stere"+cyl_stere.stpar.Value()+"/"+cyl_stere.cmer.Value()+"/"+ToString(width)+"c"; break;} + case(CYL_STERE): {ret="-JCyl_stere/"+cyl_stere.stpar.Value()+"/"+cyl_stere.cmer.Value()+"/"+ToString(width)+"c"; break;} default: return ""; } ret+=" "+region.Value(); return ret; } - bool SetType(const std::string& s) + bool SetType(const std::string& s, std::string& err) { proj=NOTDEF; std::string str=s; tolower(str); - if(projnames.end()==projnames.find(str)) return false; - proj=projnames[str]; - return true; + + // Handle one symbol cases + if(str.size()==1) switch(str[0]) + { + case('c'): {proj=CASSINI; return true;} + case('j'): {proj=MILLER; return true;} + case('m'): {proj=MERCATOR; return true;} + case('o'): {proj=OBLIQMERCATOR; return true;} + case('q'): {proj=CYL_EQU; return true;} + case('t'): {proj=TRANSMERCATOR; return true;} + case('x'): {proj=XY; return true;} + case('y'): {proj=CYL_EQA; return true;} + default: break; + } + // Handle long GMT names + if("cyl_stere"==str) {proj=CYL_STERE; return true;} + // Handle common names + std::string t1; + for(const auto& m: projnames) + { + TemplateComparator cmp(m.first); + bool res=cmp.Compare(str); + if(!res) continue; + if(NOTDEF!=proj) // Ambiguos string + { + err="Ambiguous projection definition: did you mean \""+t1+"\" or \""+cmp.Template2Name()+"\"?"; + proj=NOTDEF; + return false; + } + t1=cmp.Template2Name(); + proj=m.second; + } + + if(NOTDEF!=proj) return true; // All Ok + err="Unknown projection: "+s; + return false; } static void FillProjNames();