initial upload
This commit is contained in:
33
archive/grad2d/datafunc.h
Normal file
33
archive/grad2d/datafunc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _DATAFUNC_H
|
||||
#define _DATAFUNC_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
#include "fftw3.h"
|
||||
#include "vector"
|
||||
|
||||
#define DATA "-t"
|
||||
#define COLS "-c"
|
||||
#define HORIZATION_X "-x"
|
||||
#define HORIZATION_Y "-y"
|
||||
#define VERTICAL "-z"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define OUTPUT "-o"
|
||||
#define POWER "-w"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define pi (4.0*atan(1.0))
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
|
||||
#endif
|
190
archive/grad2d/grad_hx.h
Normal file
190
archive/grad2d/grad_hx.h
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_hx(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** V= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
V[i] = new double [N_ex];
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_M_ex = M_ex/2;
|
||||
double du = 1.0/((M_ex-1)*dx);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < N_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_M_ex; j++)
|
||||
{
|
||||
k = M_ex - 1 - j;
|
||||
V[j][i] = du*j;
|
||||
V[k][i] = -1*du*j;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][1]*pow(2*pi*V[i][j],power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][0]*pow(2*pi*V[i][j],power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmax-dx*j<<" "<<ymax-dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] V[i];
|
||||
delete[] V;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
189
archive/grad2d/grad_hy.h
Normal file
189
archive/grad2d/grad_hy.h
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_hy(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** U= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
U[i] = new double [N_ex];
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_N_ex = N_ex/2;
|
||||
double dv = 1.0/((N_ex-1)*dy);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_N_ex; j++)
|
||||
{
|
||||
k = N_ex - 1 - j;
|
||||
U[i][j] = dv*j;
|
||||
U[i][k] = -1*dv*j;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][1]*pow(2*pi*U[i][j],power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][0]*pow(2*pi*U[i][j],power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmax-dx*j<<" "<<ymax-dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] U[i];
|
||||
delete[] U;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
207
archive/grad2d/grad_z.h
Normal file
207
archive/grad2d/grad_z.h
Normal file
@@ -0,0 +1,207 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_z(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** U= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
U[i] = new double [N_ex];
|
||||
|
||||
double** V= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
V[i] = new double [N_ex];
|
||||
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_M_ex = M_ex/2;
|
||||
int half_N_ex = N_ex/2;
|
||||
double du = 1.0/((M_ex-1)*dx);
|
||||
double dv = 1.0/((N_ex-1)*dy);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_N_ex; j++)
|
||||
{
|
||||
k = N_ex - 1 - j;
|
||||
V[i][j] = V[i][k] = (dv*j)*(dv*j);
|
||||
}
|
||||
}
|
||||
double u;
|
||||
for (int i = 0; i < N_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_M_ex; j++)
|
||||
{
|
||||
k = M_ex - 1 - j;
|
||||
U[j][i] = U[k][i] = (du*j)*(du*j);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][0]*pow(2*pi*sqrt(U[i][j]+V[i][j]),power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][1]*pow(2*pi*sqrt(U[i][j]+V[i][j]),power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmin+dx*j<<" "<<ymin+dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] U[i];
|
||||
delete[] U;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] V[i];
|
||||
delete[] V;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
156
archive/grad2d/main.cpp
Normal file
156
archive/grad2d/main.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
//计算二维平面数据的三方向导数,因为有很多方法可以得到xyz三列数据文件,所以数据类型为xyz的三列数据文件
|
||||
//数据排列方式: x坐标 y坐标 v数值
|
||||
//坐标方向: z轴向下的右旋坐标系
|
||||
#include "datafunc.h"
|
||||
#include "grad_z.h"
|
||||
#include "grad_hx.h"
|
||||
#include "grad_hy.h"
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grad2d 0.2 - calculate horizontal and vertical gradients for an equal-grid plane data set"<<endl<<endl
|
||||
<<"usage: grad2d -t<input-file> -x|-y|-z -r<xmin>/<xmax>/<ymin>/<ymax> -i<x-spacing>/<y-spacing> -w<power> [-c<col-x>,<col-y>,<col-val>] [-o<output-file>]"<<endl<<endl
|
||||
<<"syntax: " << endl << "-t\tinput table data. The program takes a three-columns table data file. The order of columns are \'x\', \'y\'' and \'point-value\'. lines starts with '#' will be skipped."<<endl
|
||||
<<"-x|-y|-z\tselect calculating objective. Only one objective can be chosen at a time."<<endl
|
||||
<<"-r\tspecify the range of calculating area."<<endl
|
||||
<<"-i\tspecify intervals of the input data."<<endl
|
||||
<<"-c\tset data columns, the default is 0,1,2."<<endl
|
||||
<<"-w\torders of output gradient data."<<endl
|
||||
<<"-o\tspecify output-file's name. \'_gradhx|_gradhy|_gradz\' will be attached at the end of the input-name if \'-o\' is absent."<<endl<<endl
|
||||
<<"example: grad2d -tin.dat -x -r0/100/0/100 -i10/10 -w1 -oout.dat"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
int caltype = 0;
|
||||
int power = 1;
|
||||
char cmd_type[1024] = {0};
|
||||
char filename[1024] = {0};
|
||||
char filetype[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
char colname[1024] = "0,1,2";
|
||||
double range[4] = {1e+30,1e+30,1e+30,1e+30};
|
||||
double interval[2] = {1e+30,1e+30};
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
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])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (range[2]>range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,DATA))
|
||||
{
|
||||
if (2!=sscanf(argv[i],"%*2s%[^.]%s",filename,filetype))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,COLS))
|
||||
{
|
||||
if (1!=sscanf(argv[i],"%*2s%s",colname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,POWER))
|
||||
{
|
||||
if (1!=sscanf(argv[i],"%*2s%d",&power))
|
||||
{
|
||||
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,HORIZATION_X)) caltype = 1;
|
||||
else if (!strcmp(cmd_type,HORIZATION_Y)) caltype = 2;
|
||||
else if (!strcmp(cmd_type,VERTICAL)) caltype = 3;
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(caltype)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradhx.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_hx(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
case 2:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradhy.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_hy(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
case 3:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradz.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_z(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
default:
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad cal_type"<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
16
archive/grad2d/makefile
Normal file
16
archive/grad2d/makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/grad2d
|
||||
CFLAGS = -L /usr/local/Cellar/fftw/3.3.8/lib -lfftw3.3
|
||||
IFLAGS = -I /usr/local/Cellar/fftw/3.3.8/include
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) ${IFLAGS}
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) ${IFLAGS}
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
Reference in New Issue
Block a user