initial upload
This commit is contained in:
203
archive/xyzdiff/datafunc.h
Normal file
203
archive/xyzdiff/datafunc.h
Normal file
@@ -0,0 +1,203 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "cmath"
|
||||
#include "string.h"
|
||||
#include "sstream"
|
||||
#include "vector"
|
||||
|
||||
#define ADD "-a"
|
||||
#define MINUS "-m"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define OUTFILE "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define MAX 1e+30
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
|
||||
int xyz_add_minus(char* filename1,
|
||||
char* filename2,
|
||||
char* outname,
|
||||
double* range,
|
||||
double* interval,
|
||||
int caltype)
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double xmin,xmax,ymin,ymax,dx,dy;
|
||||
double x,y,data;
|
||||
|
||||
xmin = *range; xmax = *(range+1);
|
||||
ymin = *(range+2); ymax = *(range+3);
|
||||
dx = *interval; dy = *(interval+1);
|
||||
|
||||
int M = int (xmax - xmin)/dx + 1;
|
||||
int N = int (ymax - ymin)/dy + 1;
|
||||
|
||||
double** data1 = new double* [M];
|
||||
for (int i=0;i<M;i++)
|
||||
data1[i] = new double [N];
|
||||
|
||||
double** data2 = new double* [M];
|
||||
for (int i=0;i<M;i++)
|
||||
data2[i] = new double [N];
|
||||
|
||||
ifstream infile1(filename1);
|
||||
ifstream infile2(filename2);
|
||||
|
||||
if(!infile1||!infile2) return -1;
|
||||
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
getline(infile1,temp_str);
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
if (temp_ss >> x >> y >> data)
|
||||
{
|
||||
data1[int ((x - xmin)/dx)][int ((y - ymin)/dy)] = data;
|
||||
}
|
||||
else cout << "wrong enterence of " << filename1 << ": " << temp_str << endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
getline(infile2,temp_str);
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
if (temp_ss >> x >> y >> data)
|
||||
{
|
||||
data2[int ((x - xmin)/dx)][int ((y - ymin)/dy)] = data;
|
||||
}
|
||||
else cout << "wrong enterence of " << filename2 << ": " << temp_str << endl;
|
||||
}
|
||||
}
|
||||
infile1.close();
|
||||
infile2.close();
|
||||
|
||||
ofstream outfile(outname);
|
||||
if (caltype==1)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile << xmin+dx*i << " " << ymin+dy*j << " " << setprecision(16) << data1[i][j] - data2[i][j] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (caltype==2)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile << xmin+dx*i << " " << ymin+dy*j << " " << setprecision(16) << data1[i][j] + data2[i][j] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"error - wrong caltype"<<endl;
|
||||
return -1;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
for (int i=0;i<M;i++)
|
||||
delete[] data1[i];
|
||||
delete[] data1;
|
||||
for (int i=0;i<M;i++)
|
||||
delete[] data2[i];
|
||||
delete[] data2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xyz_add_minus(char* filename1,
|
||||
char* filename2,
|
||||
char* outname,
|
||||
int caltype)
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
_1dArray x,y,data,data2;
|
||||
double temp_x,temp_y,temp_data;
|
||||
|
||||
ifstream infile1(filename1);
|
||||
ifstream infile2(filename2);
|
||||
|
||||
if(!infile1||!infile2) return -1;
|
||||
|
||||
while(getline(infile1,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
if (temp_ss >> temp_x >> temp_y >> temp_data)
|
||||
{
|
||||
x.push_back(temp_x);
|
||||
y.push_back(temp_y);
|
||||
data.push_back(temp_data);
|
||||
}
|
||||
else cout << "wrong enterence of " << filename1 << ": " << temp_str << endl;
|
||||
}
|
||||
}
|
||||
|
||||
while(getline(infile2,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
if (temp_ss >> temp_x >> temp_y >> temp_data)
|
||||
{
|
||||
x.push_back(temp_x);
|
||||
y.push_back(temp_y);
|
||||
data2.push_back(temp_data);
|
||||
}
|
||||
else cout << "wrong enterence of " << filename2 << ": " << temp_str << endl;
|
||||
}
|
||||
}
|
||||
|
||||
infile1.close();
|
||||
infile2.close();
|
||||
|
||||
ofstream outfile(outname);
|
||||
if (caltype==1)
|
||||
{
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
outfile << x.at(i) << " " << y.at(i) << " " << setprecision(16) << data.at(i) - data2.at(i) << endl;
|
||||
}
|
||||
}
|
||||
else if (caltype==2)
|
||||
{
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
outfile << x.at(i) << " " << y.at(i) << " " << setprecision(16) << data.at(i) + data2.at(i) << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"error - wrong caltype"<<endl;
|
||||
return -1;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
return 0;
|
||||
}
|
96
archive/xyzdiff/main.cpp
Normal file
96
archive/xyzdiff/main.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
void dis_play()
|
||||
{
|
||||
cout<<"xyzdiff 0.2 - simple functions calculating the difference or sum of two xyz data"<<endl<<endl
|
||||
<<"usage: xyzdiff <xyzfile1> <xyzfile2> -a|-m [-r<xmin>/<xmax>/<ymin>/<ymax>] [-i<dx>/<dy>] -o<outfile>"<<endl
|
||||
<<"-a|-m\tadd data and minus data from xyzfile1 and xyzfile2"<<endl
|
||||
<<"-r\tspecify the range of interested"<<endl
|
||||
<<"-i\tspecify intervals of interested"<<endl
|
||||
<<"-o\tspecify outfile name"<<endl<<endl
|
||||
<<"examples: xyzdiff example.xyz example2.xyz -m -r0/100/0/100 -i1/1 -oexample-out.xyz"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char cmd_type[1024] = {0};
|
||||
char filename[1024] = {0};
|
||||
char filename2[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
int caltype = -1;
|
||||
double range[4] = {MAX,MAX,MAX,MAX};
|
||||
double interval[2] = {MAX,MAX};
|
||||
|
||||
if (argc<=3)
|
||||
{
|
||||
dis_play();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(-1==sscanf(argv[1],"%s",filename))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[1]<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(-1==sscanf(argv[2],"%s",filename2))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[2]<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 3; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,ADD)) caltype = 2;
|
||||
else if (!strcmp(cmd_type,MINUS)) caltype = 1;
|
||||
else if (!strcmp(cmd_type,RANGE))
|
||||
{
|
||||
if (4!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3]))
|
||||
{
|
||||
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.0||interval[1]<=0.0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,OUTFILE))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (range[0] == MAX)
|
||||
xyz_add_minus(filename,filename2,outname,caltype);
|
||||
else
|
||||
xyz_add_minus(filename,filename2,outname,range,interval,caltype);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user