[TEST]UPSTREAM: Pick some source changes from 48080d0a97

* Sync new folder structure
This commit is contained in:
2026-04-23 20:55:40 +08:00
parent c185f99ee3
commit 17109fde9b
211 changed files with 189504 additions and 189280 deletions

View File

@@ -0,0 +1,283 @@
//-----------------------------------------------------------------------
// Read binary files and do fancy things with them...
//-----------------------------------------------------------------------
#ifdef newc
#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <fstream>
using namespace std;
#else
#include <math.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#endif
#include "microdef.fh"
int main(int argc, char *argv[])
{
//
// USE: DataCT flag file1 [ file2 ]
//
// where: - flag can be XY,XZ,YZ
//
void set_fname(char *fname);
if (argc < 3)
{
cout << "\aUsage: DataCT flag binaryfile1 [ binaryfile2 ] \n "
<< " where: - flag can be XY,XZ,YZ"
<< endl;
exit(1);
}
ifstream infile1;
infile1.open(argv[2]);
if (!infile1)
{
cerr << "\a Can't open " << argv[2] << " for input." << endl;
exit(1);
}
/* read properties of the binary file */
double time;
int nx, ny, nz;
double xmin, xmax, ymin, ymax, zmin, zmax;
infile1.seekg(0, ios::beg);
infile1.read((char *)&time, sizeof(double));
infile1.read((char *)&nx, sizeof(int));
infile1.read((char *)&ny, sizeof(int));
infile1.read((char *)&nz, sizeof(int));
infile1.read((char *)&xmin, sizeof(double));
infile1.read((char *)&xmax, sizeof(double));
infile1.read((char *)&ymin, sizeof(double));
infile1.read((char *)&ymax, sizeof(double));
infile1.read((char *)&zmin, sizeof(double));
infile1.read((char *)&zmax, sizeof(double));
/* get rid of any 4 character suffix */
set_fname(argv[2]);
/* sanity check */
if (nx != ny || nx != nz)
{
cout << "\n"
<< endl;
cout << " nx, ny and nz do not agree! Using a symmetry?... ";
cout << "\n"
<< endl;
}
cout << "\n Reading file : " << argv[2] << endl;
cout << "\n Time : " << time << endl;
cout << " Dimensions : " << setw(16) << nx << setw(16) << ny << setw(16) << nz << endl;
cout << " xmin, xmax : " << setw(16) << xmin << setw(16) << xmax << endl;
cout << " ymin, ymax : " << setw(16) << ymin << setw(16) << ymax << endl;
cout << " zmin, zmax : " << setw(16) << zmin << setw(16) << zmax << endl;
cout << "\n";
double *data;
data = new double[nx * ny * nz];
int i = 0, j = 0, k = 0;
infile1.read((char *)data, nx * ny * nz * sizeof(double));
infile1.close();
//
//
// if second file given, open second file and subtract from first one!
//
//
if (argc == 4)
{
infile1.open(argv[3]);
if (!infile1)
{
cerr << "\a Can't open " << argv[3] << " for input." << endl;
exit(1);
}
double *indata;
indata = new double[nx * ny * nz];
// read in header
infile1.seekg(0, ios::beg);
int nxin, nyin, nzin;
infile1.read((char *)&time, sizeof(double));
infile1.read((char *)&nxin, sizeof(int));
infile1.read((char *)&nyin, sizeof(int));
infile1.read((char *)&nzin, sizeof(int));
infile1.read((char *)&xmin, sizeof(double));
infile1.read((char *)&xmax, sizeof(double));
infile1.read((char *)&ymin, sizeof(double));
infile1.read((char *)&ymax, sizeof(double));
infile1.read((char *)&zmin, sizeof(double));
infile1.read((char *)&zmax, sizeof(double));
if (nxin != nx || nyin != ny || nzin != nz)
{
cerr << "\a Number of indices do not agree! " << endl;
exit(1);
}
cout << " Comparing with data at time " << time << "\n"
<< endl;
infile1.read((char *)indata, nx * ny * nz * sizeof(double));
infile1.close();
for (i = 0; i < nx * ny * nz; i++)
data[i] -= indata[i];
}
double *X, *Y, *Z;
X = new double[nx];
Y = new double[ny];
Z = new double[nz];
double dd;
#ifdef Vertex
#ifdef Cell
#error Both Cell and Vertex are defined
#endif
dd = (xmax - xmin) / (nx - 1);
for (i = 0; i < nx; i++)
X[i] = xmin + i * dd;
dd = (ymax - ymin) / (ny - 1);
for (j = 0; j < ny; j++)
Y[j] = ymin + j * dd;
dd = (zmax - zmin) / (nz - 1);
for (k = 0; k < nz; k++)
Z[k] = zmin + k * dd;
#else
#ifdef Cell
dd = (xmax - xmin) / nx;
for (i = 0; i < nx; i++)
X[i] = xmin + (i + 0.5) * dd;
dd = (ymax - ymin) / ny;
for (j = 0; j < ny; j++)
Y[j] = ymin + (j + 0.5) * dd;
dd = (zmax - zmin) / nz;
for (k = 0; k < nz; k++)
Z[k] = zmin + (k + 0.5) * dd;
#else
#error Not define Vertex nor Cell
#endif
#endif
int ext[3];
ext[0] = nx;
ext[1] = ny;
ext[2] = nz;
void writefile(int *ext, double *XX, double *YY, double *ZZ, double *datain,
char *filename, const char *flag);
writefile(ext, X, Y, Z, data, argv[2], argv[1]);
delete[] data;
delete[] X;
delete[] Y;
delete[] Z;
}
/*-----------------------------------*/
/* get rid of any 4 character suffix */
/*-----------------------------------*/
void set_fname(char *fname)
{
int len = strlen(fname) - 4;
char *n_fname;
n_fname = new char[len];
for (int i = 0; i < len; ++i)
{
n_fname[i] = fname[i];
// cout << n_fname[i] << " " << i << endl;
}
n_fname[len] = '\0';
// cout << "n_fname: " << n_fname << " fname: " << fname << ", "
// << len << endl;
strcpy(fname, n_fname); /* Send back the old pointer */
delete n_fname;
}
//|----------------------------------------------------------------------------
// writefile
//|----------------------------------------------------------------------------
void writefile(int *ext, double *XX, double *YY, double *ZZ, double *datain,
char *filename, const char *flag)
{
int nx = ext[0], ny = ext[1], nz = ext[2];
int i, j, k;
char filename_h[50];
//|--->open out put file
ofstream outfile;
if (!strcmp(flag, "YZ"))
{
for (i = 0; i < nx; i++)
{
sprintf(filename_h, "%s_%d.dat", filename, i);
outfile.open(filename_h);
outfile << "# CT along X at " << i << endl;
for (k = 0; k < nz; k++)
{
for (j = 0; j < ny; j++)
{
outfile << setw(10) << setprecision(10) << YY[j] << " "
<< setw(10) << setprecision(10) << ZZ[k] << " "
<< datain[i + j * nx + k * nx * ny] << " "
<< endl;
}
outfile << "\n"; /* blanck line for gnuplot */
}
outfile.close();
}
}
else if (!strcmp(flag, "XZ"))
{
for (j = 0; j < ny; j++)
{
sprintf(filename_h, "%s_%d.dat", filename, j);
outfile.open(filename_h);
outfile << "# CT along Y at " << j << endl;
for (k = 0; k < nz; k++)
{
for (i = 0; i < nx; i++)
{
outfile << setw(10) << setprecision(10) << XX[i] << " "
<< setw(10) << setprecision(10) << ZZ[k] << " "
<< datain[i + j * nx + k * nx * ny] << " "
<< endl;
}
outfile << "\n"; /* blanck line for gnuplot */
}
outfile.close();
}
}
else if (!strcmp(flag, "XY"))
{
for (k = 0; k < nz; k++)
{
sprintf(filename_h, "%s_%d.dat", filename, k);
outfile.open(filename_h);
outfile << "# CT along Z at " << k << endl;
for (j = 0; j < ny; j++)
{
for (i = 0; i < nx; i++)
{
outfile << setw(10) << setprecision(10) << XX[i] << " "
<< setw(10) << setprecision(10) << YY[j] << " "
<< datain[i + j * nx + k * nx * ny] << " "
<< endl;
}
outfile << "\n"; /* blanck line for gnuplot */
}
outfile.close();
}
}
else
{
cout << "In output_data: not recognized flag-->" << flag << endl;
exit(0);
}
}

View File

@@ -0,0 +1,51 @@
#include <fstream>
#include <string>
// #include<
using namespace std;
/*void printss(int * a,int * b,int *c){
int a1 = *a;
int b1 = *b;
int c1 = *c;
printf("%d,%d,%d\n",1,2,3);
printf("%d,%d,%d\n",a1,b1,c1);
}*/
int main()
{
ifstream fin;
ofstream fout;
fin.open("tool_input.txt");
fout.open("tool_output.txt");
// ifstream fin1;
// fin1.open("input1.txt");
char buf[20];
char buf1[20];
while (fin >> buf)
{
// fin1>>buf1;
// fout<<"if("<<buf<<") cudaFree("<<buf<<");\n";
// cudaMalloc((void**)&(Mh_ #), matrix_size * sizeof(double));
// fout<<"cudaMalloc((void**)&(Mh_"<<buf<<"), matrix_size * sizeof(double));"<<endl;
// cudaMemcpy(Mh_ #, #, matrix_size * sizeof(double), cudaMemcpyHostToDevice);
// fout<<"cudaMemcpy(Mh_ "<<buf<<","<<buf<<", matrix_size * sizeof(double), cudaMemcpyHostToDevice);\n";
// cudaMemcpy(#, Mh_ #, matrix_size * sizeof(double), cudaMemcpyDeviceToHost);
// fout<<"cudaMemcpy("<<buf<<", Mh_ "<<buf<<", matrix_size * sizeof(double), cudaMemcpyDeviceToHost);\n";
// if(cg->[buf][i] != cg_gpu->[buf][i]){is_match = false; break;}
fout << "delta = cg->fgfs[" << buf << "][i] - cg_gpu->fgfs[" << buf << "][i];" << endl;
fout << "if(delta >1e-12 || delta < -1e-12){is_match = false; break;}" << endl;
}
/*int para = 167;
for(int i = para;i<para+68;++i){
fout<<"cg->fgfs["<<i<<"], ";
}*/
/*int array[3] = {0,1,2};
int * p = array;
printss(p++,p++,p++);*/
return 0;
}

View File

@@ -0,0 +1,23 @@
subroutine fout3D(ftag,matrix,msize)
implicit none
integer,intent(in ):: ftag,msize(1:3)
double precision,intent(in),dimension(msize(1),msize(2),msize(3))::matrix
integer mat_size
mat_size = msize(1)*msize(2)*msize(3)
call writefile_f(ftag,matrix,mat_size)
return
end subroutine fout3D
subroutine fout1D(ftag,matrix,msize)
implicit none
integer,intent(in ):: ftag,msize
double precision,intent(in),dimension(1:msize)::matrix
call writefile_f(ftag,matrix,msize)
return
end subroutine fout1D

View File

@@ -0,0 +1,53 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "macrodef.h"
extern "C"
{
#ifdef fortran1
void writefile_f
#endif
#ifdef fortran2
void WRITEFILE_F
#endif
#ifdef fortran3
void
writefile_f_
#endif
(int &filetag, double *matrix, int &msize)
{
char fname[32];
char ftag[32];
// itoa(filetag,ftag,10);
sprintf(ftag, "%d", filetag);
strcpy(fname, "matrix_f.out");
strcat(fname, ftag);
/*printf("-------------called-------------");
printf(fname);
printf("\n");
printf("int tag %d\n",filetag);
printf("int msize %d\n",msize);
printf(ftag);*/
printf("int msize %d\n", msize);
FILE *fp;
fp = fopen(fname, "wb");
// char buffer[1024];
// buffer[1023]='\0';
// int bsize;
if (fp == NULL)
{
printf("Open file failed.");
exit(0);
}
// msize = sizeof(double) * msize;
fwrite(matrix, sizeof(double), msize, fp);
fclose(fp);
// return 0;
}
}