gctl_toolkits/archive/Tesseroid_creater/main.cpp
2024-09-10 20:25:18 +08:00

100 lines
2.9 KiB
C++

#include "command.h"
void disp_help()
{
cout<<"gmsh-tesseroid 1.1 - creater a tesseroid or a set of tesseroids in .geo file"<<endl<<endl
<<"usage: gmsh-tesseroid -o<output-file> -p<name>/<id>/<xmin>/<xmax>/<ymin>/<ymax>/<radius>/<Radius> [-p<name>/<id>/<xmin>/<xmax>/<ymin>/<ymax>/<radius>/<Radius>]..."<<endl
<<" 3-D ranges and physical groups of a tesseroid are defined by a string of statement. "
<<"To create multiple tesseroids, just repeat the commond. xmin and xmax indicate the longitudal range of the tesseroid which are between [-180,180]. "
<<"And ymin and ymax represent the latitudal range between [-90,90]. Then r and R are the inner and outter radiuses of the tesseroid. "
<<"Different tesseroids are idenified by their names. While the id classify tesseroids into different physical groups which could be given different physical properities later."<<endl
<<" -o specify output file's name"<<endl<<endl
<<"example: gmsh-tesseroid -otest.geo -pTone/1/0/20/0/20/800/1000 -pTtwo/2/25/45/0/20/800/1000"<<endl;
}
int main(int argc,const char* argv[])
{
char cmd_type[1024] = {0};
char filename[1024] = {0};
Tess onetess;
Tess* alltess = NULL;
TessList list_tess;
TessList::iterator it;
int tess_num;
if (argc==1)
{
disp_help();
}
else
{
for (int i = 1; i < argc; i++)
{
sscanf(argv[i],"%2s",cmd_type);
if (!strcmp(cmd_type,PARA))
{
if (8!=sscanf(argv[i],"%*2s%[^/]/%d/%lf/%lf/%lf/%lf/%lf/%lf",&onetess.name,&onetess.id,&onetess.xmin,&onetess.xmax,
&onetess.ymin,&onetess.ymax,&onetess.r,&onetess.R))
{
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<BOLDRED<<" ignored!"<<endl;
}
else
{
if (onetess.xmin>=onetess.xmax
||onetess.ymin>=onetess.ymax
||onetess.r>=onetess.R
||onetess.r<=0
||onetess.xmin<-180.0
||onetess.xmax>180.0
||onetess.ymin<-90.0
||onetess.ymax>90.0)
{
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<BOLDRED<<" ignored!"<<endl;
}
else list_tess.push_back(onetess);
}
}
else if (!strcmp(cmd_type,OUTPUT))
{
if (-1==sscanf(argv[i],"%*2s%s",filename))
{
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
return 0;
}
}
else
{
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
return 0;
}
}
}
if (list_tess.empty())
{
cout<<BOLDRED<<"==> "<<RESET<<"Error: No tesseroid found"<<endl;
return 0;
}
else if (!strcmp(filename,""))
{
cout<<BOLDRED<<"==> "<<RESET<<"Error: No filename found"<<endl;
return 0;
}
tess_num = list_tess.size();
alltess = new Tess [tess_num];
int count = 0;
for (it = list_tess.begin(); it != list_tess.end(); ++it)
{
onetess = *it;
alltess[count] = onetess;
count++;
}
run(tess_num,alltess,filename);
if (alltess!=NULL) delete[] alltess;
if (!list_tess.empty()) list_tess.clear();
return 0;
}