160 lines
3.9 KiB
C++
160 lines
3.9 KiB
C++
|
#include "grav1d_cylinder.h"
|
|||
|
|
|||
|
void disp_help()
|
|||
|
{
|
|||
|
cout<<"grav1d-cylinder 1.0 - forwad modeling gravity and its gradient data of a horizontal cylinder"<<endl<<endl
|
|||
|
<<"usage: grav1d-cylinder -p<para1>/<para2>/<para3>/<para4> -d<xmin>/<xmax> -i<x_interval> -a|-h|-v -o<output-file>"<<endl
|
|||
|
<<" -p geometrical and physical properties of the cylinder"<<endl
|
|||
|
<<" para1 central position (m) of the cylinder"<<endl
|
|||
|
<<" para2 central depth (m) of the cylinder"<<endl
|
|||
|
<<" para3 radius (m) of the cylinder"<<endl
|
|||
|
<<" para4 density (g/cm3) of the cylinder"<<endl
|
|||
|
<<" -d calculating range(m)"<<endl
|
|||
|
<<" -i calculating interval(m)"<<endl
|
|||
|
<<" -a forward modeling gravity data"<<endl
|
|||
|
<<" -h forward modeling horizontal gradient of gravity data"<<endl
|
|||
|
<<" -v forward modeling vertical gradient of gravity data"<<endl
|
|||
|
<<" -o specify output-file's name"<<endl<<endl
|
|||
|
<<"example: grav1d_cylinder -p0/100/50/1.0 -d-1000/1000 -i10 -a -otestout.dat"<<endl;
|
|||
|
}
|
|||
|
|
|||
|
int typeget(char *str, const char* str2,string &str3)
|
|||
|
{
|
|||
|
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
|||
|
if (strp == NULL)
|
|||
|
{
|
|||
|
return 0; // 如果没有找到,返回
|
|||
|
}
|
|||
|
string temp = str;
|
|||
|
str3=temp.substr(strlen(str2));//提出除str2外的子句
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
|||
|
{
|
|||
|
int count = 0;
|
|||
|
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
|||
|
if((pos=str.find(old_value,pos))!=string::npos){
|
|||
|
str.replace(pos,old_value.length(),new_value);
|
|||
|
count++;
|
|||
|
}
|
|||
|
else break;
|
|||
|
}
|
|||
|
num = count;
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
int main(int argc, char* argv[])
|
|||
|
{
|
|||
|
string temp;
|
|||
|
stringstream stemp;
|
|||
|
double Para[4];
|
|||
|
double Range[3];
|
|||
|
int space_num;
|
|||
|
int cal_type = 0;
|
|||
|
string outname;
|
|||
|
|
|||
|
Para[0]=Para[1]=Para[2]=Para[3]=1e+20;
|
|||
|
Range[0]=Range[1]=Range[2]=1e+20;
|
|||
|
|
|||
|
if (argc==1)
|
|||
|
{
|
|||
|
disp_help();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
for (int i = 1; i < argc; i++)
|
|||
|
{
|
|||
|
if (!strcmp(argv[i],ANOMOALY)) cal_type = 1;
|
|||
|
else if (!strcmp(argv[i],HORIZATION)) cal_type = 2;
|
|||
|
else if (!strcmp(argv[i],VERTICAL)) cal_type = 3;
|
|||
|
|
|||
|
if (typeget(argv[i],PARAMETER,temp))
|
|||
|
{
|
|||
|
replace_all(temp,"/"," ",space_num);
|
|||
|
stemp.clear();
|
|||
|
stemp.str(temp);
|
|||
|
if (space_num==3)
|
|||
|
{
|
|||
|
stemp>>Para[0]>>Para[1]>>Para[2]>>Para[3];
|
|||
|
if (Para[1]<Para[2])
|
|||
|
{
|
|||
|
cout<<"wrong geometrical properties, program stopped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cout<<"insufficient attributes information, program stoped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (typeget(argv[i],RANGE,temp))
|
|||
|
{
|
|||
|
replace_all(temp,"/"," ",space_num);
|
|||
|
stemp.clear();
|
|||
|
stemp.str(temp);
|
|||
|
if (space_num==1)
|
|||
|
{
|
|||
|
stemp>>Range[0]>>Range[2];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cout<<"wrong attributes information, program stoped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (typeget(argv[i],INTERVAL,temp))
|
|||
|
{
|
|||
|
if (temp=="")
|
|||
|
{
|
|||
|
cout<<"wrong attributes information, program stoped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
stemp.clear();
|
|||
|
stemp.str(temp);
|
|||
|
stemp>>Range[1];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (typeget(argv[i],OUTPUT,temp))
|
|||
|
{
|
|||
|
if (temp=="")
|
|||
|
{
|
|||
|
cout<<"no output name, program stopped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
else outname = temp.c_str();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (cal_type==0||Range[0]==1e+20||Para[0]==1e+20)
|
|||
|
{
|
|||
|
cout<<"wrong commond line, program stopped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
else if (Range[0]>Range[2]||(Range[0]+Range[1])>Range[2]||(Range[0]+2*Range[1])>Range[2])
|
|||
|
{
|
|||
|
cout<<"wrong range, program stopped..."<<endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (cal_type==1)
|
|||
|
{
|
|||
|
cylinder_a(Range,Para,outname);
|
|||
|
}
|
|||
|
else if (cal_type==2)
|
|||
|
{
|
|||
|
cylinder_h(Range,Para,outname);
|
|||
|
}
|
|||
|
else if (cal_type==3)
|
|||
|
{
|
|||
|
cylinder_v(Range,Para,outname);
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|