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

115
archive/sph2car/func.h Normal file
View File

@@ -0,0 +1,115 @@
#ifndef _FUNC_H
#define _FUNC_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define OUTPUT "-o"
#define WGS84 "WGS84"
#define RADIUS "-d"
#define RANGE "-r"
#define INSERT "-i"
#define FILE "-f"
#define pole_radius 6356752.3//WGS84椭球极半径
#define equator_radius 6378137//WGS84椭球长半径
#define pi 3.1415926535897932384626433832795
using namespace std;
struct point3d
{
double x,y,z;
};
double WGS84_r(double lati)
{
return pole_radius*equator_radius/sqrt(pow(pole_radius,2)*pow(cos((double) lati*pi/180.0),2)+pow(equator_radius,2)*pow(sin((double) lati*pi/180.0),2));
}
point3d SCS2CCS(double phi,double thet,double radius)
{
point3d v;
v.x = radius*sin((0.5-thet/180.0)*pi)*cos((2.0+phi/180.0)*pi);
v.y = radius*sin((0.5-thet/180.0)*pi)*sin((2.0+phi/180.0)*pi);
v.z = radius*cos((0.5-thet/180.0)*pi);
return v;
}
int create_grid(double radius,int* interval,int* range,string outname)
{
point3d posi;
int d_phi = *interval,d_thet = *(interval+1);
int xmin = *range,xmax = *(range+1),ymin = *(range+2),ymax = *(range+3);
ofstream outfile(outname.c_str());
if (radius==-1.0)
{
for (int i = ymin; i <= ymax; i+=d_thet)
{
for (int j = xmin; j <= xmax; j+=d_phi)
{
posi = SCS2CCS(j,i,WGS84_r(i));
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
}
}
outfile.close();
}
else
{
for (int i = ymin; i <= ymax; i+=d_thet)
{
for (int j = xmin; j <= xmax; j+=d_phi)
{
posi = SCS2CCS(j,i,radius);
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
}
}
outfile.close();
}
return 0;
}
int add_grid(double radius,string input_name,string output_name)
{
point3d posi;
string temp;
stringstream stemp;
double temp_phi,temp_thet,temp_radius;
ifstream infile(input_name.c_str());
ofstream outfile(output_name.c_str());
if (!infile)
{
cout<<input_name<<" not found, program stopped..."<<endl;
return 1;
}
else
{
while(getline(infile,temp)) {
if (temp!="")
{
stemp.clear();
stemp.str(temp);
stemp>>temp_phi>>temp_thet>>temp_radius;
}
if (radius==-1.0)
{
posi = SCS2CCS(temp_phi,temp_thet,WGS84_r(temp_thet)+temp_radius);
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
}
else
{
posi = SCS2CCS(temp_phi,temp_thet,radius+temp_radius);
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
}
}
infile.close();
outfile.close();
}
return 0;
}
#endif

181
archive/sph2car/main.cpp Normal file
View File

@@ -0,0 +1,181 @@
//将球坐标表示的数据(地形等)转换为直角坐标系,或者生成一个直角坐标系下的球面网络
#include "func.h"
int disp_help()
{
cout
<<"sph2car 0.0.1 - create a spherical grid using Cartersian coordinates and add terrain data into it"<<endl<<endl
<<"usage: sph2car [-f<input-file>]|[-i<dx>/<dy> -r<xmin>/<xmax>/<ymin>/<ymax>] -d<radius|WGS84> -o<output-file>"<<endl
<<" -f add an input terrain data into the output grid"<<endl
<<" -d specify the reference raidus of a sphere, type WGS84 to use the earth's ellipsoid"<<endl
<<" -i the interval of output grid"<<endl
<<" -r the range of output grid"<<endl
<<" -o specify the output name"<<endl<<endl
<<"example: sph2car -fexample.dat -d10000 -i1/1 -r30/80/40/60 -otest.dat"<<endl;
return 0;
}
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;
}
int nameget(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(0,strlen(str)-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[])
{
int space_num;
double radius;
int interval[2],range[4];
string temp="";
string input_name="";
string output_name="";
stringstream stemp;
if (argc==1)
{
disp_help();
}
else
{
interval[0]=interval[1]=-1.0;
range[0]=range[1]=range[2]=range[3]=1000;
for (int i = 1; i < argc; i++)
{
if (typeget(argv[i],OUTPUT,temp))
{
if (temp=="")
{
cout<<"no output name, program stopped..."<<endl;
return 0;
}
else
{
output_name = temp;
temp="";
}
}
if (typeget(argv[i],FILE,temp))
{
if (temp=="")
{
cout<<"no input name, program stopped..."<<endl;
return 0;
}
else
{
input_name = temp;
temp="";
}
}
if (typeget(argv[i],INSERT,temp))
{
replace_all(temp,"/"," ",space_num);
stemp.clear();
stemp.str(temp);
if (space_num==1)
{
stemp>>interval[0]>>interval[1];
if (interval[0]<=0||interval[1]<=0)
{
cout<<"wrong intervals, program stopped..."<<endl;
return 0;
}
}
else
{
cout<<"wrong intervals, program stopped..."<<endl;
return 0;
}
}
if (typeget(argv[i],RANGE,temp))
{
replace_all(temp,"/"," ",space_num);
stemp.clear();
stemp.str(temp);
if (space_num==3)
{
stemp>>range[0]>>range[1]>>range[2]>>range[3];
if (range[0]<-180||range[1]>180||range[2]<-90||range[3]>90
||range[0]>range[1]||range[2]>range[3])
{
cout<<"wrong range info, program stopped..."<<endl;
return 0;
}
}
else
{
cout<<"wrong range info, program stopped..."<<endl;
return 0;
}
}
if (typeget(argv[i],RADIUS,temp))
{
if (temp=="")
{
cout<<"no radius info, program stopped..."<<endl;
return 0;
}
else if (!strcmp(temp.c_str(),WGS84))
{
radius = -1.0;
}
else
{
stemp.clear();
stemp.str(temp);
stemp>>radius;
if (radius<0)
{
cout<<"wrong radius info, program stopped..."<<endl;
return 0;
}
}
}
}
if (input_name==""&&interval[0]!=-1&&range[0]!=1000)
{
create_grid(radius,interval,range,output_name);
}
else if (input_name!="")
{
add_grid(radius,input_name,output_name);
}
}
return 0;
}