initial upload
This commit is contained in:
12
archive/g3d/CMakeLists.txt
Normal file
12
archive/g3d/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
#Uncomment the following two lines to compile the sources as an individual cmake porject. Change the <project_name> as you wanted.
|
||||
#cmake_minimum_required(VERSION 3.15.2)
|
||||
#project(<project_name>)
|
||||
|
||||
#Set executable name here
|
||||
set(name g3d)
|
||||
|
||||
aux_source_directory(. "${name}_src")
|
||||
add_executable(${name} ${${name}_src})
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 11)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
install(TARGETS ${name} RUNTIME DESTINATION sbin)
|
59
archive/g3d/datafunc.h
Normal file
59
archive/g3d/datafunc.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _DATAFUNC_H
|
||||
#define _DATAFUNC_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#include "cmath"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "list"
|
||||
|
||||
#define G0 6.67259e-03
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define MAX 1e+30
|
||||
|
||||
#define GRAV "-g"
|
||||
#define GRADX "-x"
|
||||
#define GRADY "-y"
|
||||
#define GRADZ "-z"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define PARAFILE "-f"
|
||||
#define SPHERE "-s"
|
||||
#define CUBE "-c"
|
||||
#define OUTPUT "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
double arctg(double v)
|
||||
{
|
||||
double ang;
|
||||
if(v>=0)
|
||||
{
|
||||
ang=atan(v);
|
||||
}
|
||||
else if(v<0)
|
||||
{
|
||||
ang=atan(v)+pi;
|
||||
}
|
||||
return ang;
|
||||
}
|
||||
|
||||
struct sphere
|
||||
{
|
||||
double x,y,z,r;
|
||||
double density;
|
||||
};
|
||||
typedef list<sphere> SphereList;
|
||||
|
||||
struct cube
|
||||
{
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double density;
|
||||
};
|
||||
typedef list<cube> CubeList;
|
||||
|
||||
#endif
|
5
archive/g3d/example/example.txt
Normal file
5
archive/g3d/example/example.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
-c450/550/450/550/100/200/1.0
|
||||
-s300/300/100/50/1.0
|
||||
-s300/700/100/50/1.0
|
||||
-s700/700/100/50/1.0
|
||||
-s700/300/100/50/1.0
|
260
archive/g3d/forward.h
Normal file
260
archive/g3d/forward.h
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
class FD
|
||||
{
|
||||
public:
|
||||
FD();
|
||||
~FD();
|
||||
int init_res(double*,double*);
|
||||
int out_res(char*);
|
||||
void forward_sphere(sphere,int);
|
||||
void forward_cube(cube,int);
|
||||
private:
|
||||
double xmin,xmax,ymin,ymax,dx,dy;
|
||||
int M,N;
|
||||
double height;
|
||||
|
||||
double** res;
|
||||
};
|
||||
|
||||
FD::FD()
|
||||
{
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
FD::~FD()
|
||||
{
|
||||
if(res!=NULL)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] res[i];
|
||||
delete[] res;
|
||||
}
|
||||
}
|
||||
|
||||
int FD::init_res(double* range,double* interval)
|
||||
{
|
||||
xmin = *range; xmax = *(range+1); ymin = *(range+2); ymax = *(range+3); height = *(range+4);
|
||||
height *= -1.0;
|
||||
dx = *interval; dy = *(interval+1);
|
||||
|
||||
M = int (xmax - xmin)/dx + 1;
|
||||
N = int (ymax - ymin)/dy + 1;
|
||||
|
||||
xmax = xmin + (M-1)*dx;
|
||||
ymax = ymin + (N-1)*dy;
|
||||
|
||||
res = new double* [M];
|
||||
for (int i=0;i<M;i++)
|
||||
res[i] = new double [N];
|
||||
|
||||
for (int i=0;i<M;i++)
|
||||
for (int j=0;j<N;j++)
|
||||
res[i][j] = 0.0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FD::out_res(char* outname)
|
||||
{
|
||||
ofstream outfile(outname);
|
||||
if(!outfile)
|
||||
{
|
||||
cout<<"can not create file: "<<outname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmin+dx*i<<" "<<ymin+dy*j<<" "<<-1.0*height<<" "<<setprecision(16)<<res[i][j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_sphere(sphere s1,int caltype)
|
||||
{
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),1.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(xmin+dx*i-s1.x)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(ymin+dy*j-s1.y)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += 1e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(2.0*pow(s1.z-height,2)+pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2))/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_cube(cube c1,int caltype)
|
||||
{
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
double x,y;
|
||||
double z = height;
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=(c1.x2-x)*log((c1.y2-y)+R222)+(c1.y2-y)*log((c1.x2-x)+R222)+(c1.z2-z)*arctg((c1.z2-z)*R222/(c1.x2-x)/(c1.y2-y));
|
||||
G122=(c1.x1-x)*log((c1.y2-y)+R122)+(c1.y2-y)*log((c1.x1-x)+R122)+(c1.z2-z)*arctg((c1.z2-z)*R122/(c1.x1-x)/(c1.y2-y));
|
||||
G212=(c1.x2-x)*log((c1.y1-y)+R212)+(c1.y1-y)*log((c1.x2-x)+R212)+(c1.z2-z)*arctg((c1.z2-z)*R212/(c1.x2-x)/(c1.y1-y));
|
||||
G112=(c1.x1-x)*log((c1.y1-y)+R112)+(c1.y1-y)*log((c1.x1-x)+R112)+(c1.z2-z)*arctg((c1.z2-z)*R112/(c1.x1-x)/(c1.y1-y));
|
||||
G221=(c1.x2-x)*log((c1.y2-y)+R221)+(c1.y2-y)*log((c1.x2-x)+R221)+(c1.z1-z)*arctg((c1.z1-z)*R221/(c1.x2-x)/(c1.y2-y));
|
||||
G121=(c1.x1-x)*log((c1.y2-y)+R121)+(c1.y2-y)*log((c1.x1-x)+R121)+(c1.z1-z)*arctg((c1.z1-z)*R121/(c1.x1-x)/(c1.y2-y));
|
||||
G211=(c1.x2-x)*log((c1.y1-y)+R211)+(c1.y1-y)*log((c1.x2-x)+R211)+(c1.z1-z)*arctg((c1.z1-z)*R211/(c1.x2-x)/(c1.y1-y));
|
||||
G111=(c1.x1-x)*log((c1.y1-y)+R111)+(c1.y1-y)*log((c1.x1-x)+R111)+(c1.z1-z)*arctg((c1.z1-z)*R111/(c1.x1-x)/(c1.y1-y));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.y2-y)+R222);
|
||||
G122=log((c1.y2-y)+R122);
|
||||
G212=log((c1.y1-y)+R212);
|
||||
G112=log((c1.y1-y)+R112);
|
||||
G221=log((c1.y2-y)+R221);
|
||||
G121=log((c1.y2-y)+R121);
|
||||
G211=log((c1.y1-y)+R211);
|
||||
G111=log((c1.y1-y)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.x2-x)+R222);
|
||||
G122=log((c1.x1-x)+R122);
|
||||
G212=log((c1.x2-x)+R212);
|
||||
G112=log((c1.x1-x)+R112);
|
||||
G221=log((c1.x2-x)+R221);
|
||||
G121=log((c1.x1-x)+R121);
|
||||
G211=log((c1.x2-x)+R211);
|
||||
G111=log((c1.x1-x)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=atan((c1.x2-x)*(c1.y2-y)/(R222*(c1.z2-z)));
|
||||
G122=atan((c1.x1-x)*(c1.y2-y)/(R122*(c1.z2-z)));
|
||||
G212=atan((c1.x2-x)*(c1.y1-y)/(R212*(c1.z2-z)));
|
||||
G112=atan((c1.x1-x)*(c1.y1-y)/(R112*(c1.z2-z)));
|
||||
G221=atan((c1.x2-x)*(c1.y2-y)/(R221*(c1.z1-z)));
|
||||
G121=atan((c1.x1-x)*(c1.y2-y)/(R121*(c1.z1-z)));
|
||||
G211=atan((c1.x2-x)*(c1.y1-y)/(R211*(c1.z1-z)));
|
||||
G111=atan((c1.x1-x)*(c1.y1-y)/(R111*(c1.z1-z)));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
181
archive/g3d/main.cpp
Normal file
181
archive/g3d/main.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user