initial upload

This commit is contained in:
2024-09-10 20:25:18 +08:00
parent b8de03ee4f
commit f1cc876972
377 changed files with 2721267 additions and 34 deletions

View File

@@ -0,0 +1,22 @@
#ifndef _DATA_FUNC_H
#define _DATA_FUNC_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define HORIZATION "-h"
#define VERTICAL "-v"
#define ANOMOALY "-a"
#define OUTPUT "-o"
#define RANGE "-d"
#define INTERVAL "-i"
#define PARAMETER "-p"
#define HELP "--help"
#define pi 3.1415926535897932384626433832795
#define G 6.67191e-3
using namespace std;
#endif

View File

@@ -0,0 +1,160 @@
#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;
}

View File

@@ -0,0 +1,67 @@
#include "data_func.h"
void cylinder_a(double* Range,double* Para,string filename)
{
double xmin,xmax,dx;
double D,r,S,density;
double g;
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
const char* savename = filename.c_str();
int Num = (xmax-xmin)/dx+1;
xmax = xmin + (Num-1)*dx;
ofstream outfile(savename);
for (int i=0;i<Num;i++)
{
g=2*G*D*density*pi*r*r/((xmin+i*dx-S)*(xmin+i*dx-S)+D*D);
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g<<endl;
}
outfile.close();
}
void cylinder_h(double* Range,double* Para,string filename)
{
double xmin,xmax,dx;
double D,r,S,density;
double g;
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
const char* savename = filename.c_str();
int Num = (xmax-xmin)/dx+1;
xmax = xmin + (Num-1)*dx;
ofstream outfile(savename);
for (int i=0;i<Num;i++)
{
g=-4*G*density*pi*r*r*D*(xmin+i*dx-S)/pow(((xmin+i*dx-S)*(xmin+i*dx-S)+D*D),2);
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g*1e+4<<endl;
}
outfile.close();
}
void cylinder_v(double* Range,double* Para,string filename)
{
double xmin,xmax,dx;
double D,r,S,density;
double g;
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
const char* savename = filename.c_str();
int Num = (xmax-xmin)/dx+1;
xmax = xmin + (Num-1)*dx;
ofstream outfile(savename);
for (int i=0;i<Num;i++)
{
g=2*G*density*pi*r*r*(D*D-(xmin+i*dx-S)*(xmin+i*dx-S))/pow((xmin+i*dx-S)*(xmin+i*dx-S)+D*D,2);
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g*1e+4<<endl;
}
outfile.close();
}