181 lines
4.6 KiB
C++
181 lines
4.6 KiB
C++
|
#include "datafunc.h"
|
||
|
#include "forward.h"
|
||
|
|
||
|
void disp_help()
|
||
|
{
|
||
|
cout<<"g3d 1.0 - forward modeling of graviational field of 3D regular objects"<<endl<<endl
|
||
|
<<"usage: g3d -g|-x|-y|-z -r<xmin>/<xmax>/<ymin>/<ymax>/<height> -i<dx>/<dy> [-s<posi-x>/<posi-y>/<posi-z>/<r>/<density>] [-c<posi-x1>/<posi-x2>/<posi-y1>/<posi-y2>/<posi-z1>/<posi-z2>/<density>] [-f<para-file>] -o<output-file>"<<endl
|
||
|
<<" -g|-x|-y|-z"<<endl
|
||
|
<<" -r specify calcualtion range"<<endl
|
||
|
<<" -i specify calculation intervals"<<endl
|
||
|
<<" -s sphere parameters"<<endl
|
||
|
<<" -c cube parameters"<<endl
|
||
|
<<" -f specify objects' parameters. you can use this to define a lot of objects instead of struggling with the command line"<<endl
|
||
|
<<" -o specify output file's name"<<endl<<endl
|
||
|
<<"example: g3d -g -r0/1000/0/1000/0 -i10/10 -s500/500/100/50/1.0 -oexample.xyz"<<endl;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
int caltype = 0;
|
||
|
char cmd_type[1024] = {0};
|
||
|
char ob_type[1024] = {0};
|
||
|
const char* oneline;
|
||
|
string oneline_str;
|
||
|
char filename[1024] = {0};
|
||
|
char outname[1024] = {0};
|
||
|
double interval[2];
|
||
|
double range[5];
|
||
|
|
||
|
if (argc==1)
|
||
|
{
|
||
|
disp_help();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sphere s1;
|
||
|
cube c1;
|
||
|
SphereList list_s;
|
||
|
SphereList::iterator is;
|
||
|
CubeList list_c;
|
||
|
CubeList::iterator ic;
|
||
|
|
||
|
interval[0]=interval[1]=MAX;
|
||
|
range[0]=range[1]=range[2]=range[3]=range[4]=MAX;
|
||
|
for (int i = 1; i < argc; i++)
|
||
|
{
|
||
|
sscanf(argv[i],"%2s",cmd_type);
|
||
|
if (!strcmp(cmd_type,GRAV)) caltype = 1;
|
||
|
else if (!strcmp(cmd_type,GRADX)) caltype = 2;
|
||
|
else if (!strcmp(cmd_type,GRADY)) caltype = 3;
|
||
|
else if (!strcmp(cmd_type,GRADZ)) caltype = 4;
|
||
|
else if (!strcmp(cmd_type,RANGE))
|
||
|
{
|
||
|
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3],&range[4]))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (range[0]>range[1]||range[2]>range[3])
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (!strcmp(cmd_type,INTERVAL))
|
||
|
{
|
||
|
if (2!=sscanf(argv[i],"%*2s%lf/%lf",&interval[0],&interval[1]))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (interval[0]<=0||interval[1]<=0)
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (!strcmp(cmd_type,PARAFILE))
|
||
|
{
|
||
|
if (-1==sscanf(argv[i],"%*2s%s",filename))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ifstream parain(filename);
|
||
|
if (!parain)
|
||
|
{
|
||
|
cout<<"file not found: "<<filename<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
while(getline(parain,oneline_str))
|
||
|
{
|
||
|
oneline = oneline_str.c_str();
|
||
|
sscanf(oneline,"%2s",ob_type);
|
||
|
if (!strcmp(ob_type,SPHERE))
|
||
|
{
|
||
|
if (5!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||
|
}
|
||
|
else list_s.push_back(s1);
|
||
|
|
||
|
}
|
||
|
else if (!strcmp(ob_type,CUBE))
|
||
|
{
|
||
|
if (7!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||
|
}
|
||
|
else list_c.push_back(c1);
|
||
|
}
|
||
|
}
|
||
|
parain.close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (!strcmp(cmd_type,OUTPUT))
|
||
|
{
|
||
|
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
else if (!strcmp(cmd_type,SPHERE))
|
||
|
{
|
||
|
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
}
|
||
|
else list_s.push_back(s1);
|
||
|
|
||
|
}
|
||
|
else if (!strcmp(cmd_type,CUBE))
|
||
|
{
|
||
|
if (7!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||
|
{
|
||
|
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||
|
}
|
||
|
else list_c.push_back(c1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (list_c.empty()&&list_s.empty())
|
||
|
{
|
||
|
cout<<"no objects found"<<endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
FD fd1;
|
||
|
fd1.init_res(range,interval);
|
||
|
if (!list_s.empty())
|
||
|
{
|
||
|
for (is=list_s.begin();is!=list_s.end();++is)
|
||
|
{
|
||
|
s1 = *is;
|
||
|
fd1.forward_sphere(s1,caltype);
|
||
|
}
|
||
|
}
|
||
|
if (!list_c.empty())
|
||
|
{
|
||
|
for (ic=list_c.begin();ic!=list_c.end();++ic)
|
||
|
{
|
||
|
c1 = *ic;
|
||
|
fd1.forward_cube(c1,caltype);
|
||
|
}
|
||
|
}
|
||
|
fd1.out_res(outname);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|