#include "stdafx.h"
#include "TecplotRW.h"
#include <assert.h>
#include <vector>
#include <stdarg.h>
using namespace std;
CTecplotRW::CTecplotRW(void) : fp(NULL)
{
}
CTecplotRW::~CTecplotRW(void)
{
}
void CTecplotRW::ReadPLT( const char* filename )
{
fp = fopen(filename, "rb");
assert(fp != NULL);
char str[80];
int l;
//char c;
int i;
float f;
double d;
ReadNchar(str, 8);//Version number//10 #!TDV102
i = Readint();//Integer value of 1.
i = Readint();//FileType: 0 = FULL
ReadString(str, &l);//The TITLE.//10 no
i = Readint();//Number of variables (NumVar) in the datafile.
int varnum = i;
for (int it=0; it<varnum; it++)//Variable names
{
ReadString(str, &l);
}
f = Readfloat();//Zone marker. Value = 299.0
ReadString(str, &l);//Zone name.
i = Readint();//ParentZone: Zero-based zone number. Value = -1
i = Readint();//StrandID. Value = -1
d = Readdouble();//Solution time.. Value = 0//10 no
i = Readint();//Zone Color (set to -1 if you want Tecplot to determine). Value = -1
i = Readint();//ZoneType 0=ORDERED,. Value = 0
i = Readint();//DataPacking 0=Block, 1=Point. Value = 0
i = Readint();//Specify Var Location.. Value = 0
i = Readint();//Are raw local 1-to-1 face neighbors supplied? Value = 0
i = Readint();//Number of miscellaneous user-defined face Value = 0
i = Readint();//IMax
i = Readint();//JMax
i = Readint();//KMax
i = Readint();//0=No more Auxiliary name
f = Readfloat();//Geometry marker. Value = 357.0
f = Readfloat();//Zone marker Value = 299.0
for (int it=0; it<varnum; it++)
{
i = Readint();//Variable data format, 1=Float
}
i = Readint();//Has passive variables: 0 = no Value = 0
i = Readint();//Has variable sharing 0 = no Value = 0
i = Readint();//Zero based zone number to share connectivity list with (-1 = no sharing). Value = -1
for (int it=0; it<varnum*2; it++)
{
d = Readdouble();//Min and Max value
}
//从120h开始
while (1)
{
f = Readfloat();//Zone marker Value = 299.0
}
}
char CTecplotRW::Readchar()
{
char t;
fread(&t, sizeof(char), 1, fp);
return t;
}
int CTecplotRW::Readint()
{
int t;
fread(&t, sizeof(int), 1, fp);
return t;
}
float CTecplotRW::Readfloat()
{
float t;
fread(&t, sizeof(float), 1, fp);
return t;
}
double CTecplotRW::Readdouble()
{
double t;
fread(&t, sizeof(double), 1, fp);
return t;
}
void CTecplotRW::ReadNchar( char* chars, int length )
{
fread(chars, sizeof(char), length, fp);
chars[length] = '\0';
}
void CTecplotRW::ReadString( char* str, int* length )
{
int t = 0;
int l=0;
do
{
fread(&t, sizeof(int), 1, fp);
str[l] = t;
l++;
} while(t != 0);
if (length != NULL)
{
(*length) = l;
}
}
void CTecplotRW::ReadPLT10( const char* filename )
{
fp = fopen(filename, "rb");
assert(fp != NULL);
char str[80];
int l;
//char c;
int i;
float f;
double d;
ReadNchar(str, 8);//Version number//10 #!TDV102
i = Readint();//Integer value of 1.
ReadString(str, &l);//The TITLE.
i = Readint();//Number of variables (NumVar) in the datafile.
int varnum = i;
for (int it=0; it<varnum; it++)//Variable names
{
ReadString(str, &l);
}
f = Readfloat();//Zone marker. Value = 299.0
ReadString(str, &l);//Zone name.
i = Readint();//ParentZone: Zero-based zone number. Value = -1
i = Readint();//ZoneType 0=ORDERED,. Value = 0
i = Readint();//DataPacking 0=Block, 1=Point. Value = 0
d = Readdouble();//Solution time.. Value = 0//10 no
i = Readint();//IMax
i = Readint();//JMax
i = Readint();//KMax
i = Readint();//0=No more Auxiliary name
f = Readfloat();//Geometry marker. Value = 357.0
f = Readfloat();//Zone marker Value = 299.0
for (int it=0; it<varnum; it++)
{
i = Readint();//Variable data format, 1=Float,2=Double,3=LongInt,4=ShortInt,5=Byte,6=Bit
}
i = Readint();//Has variable sharing 0 = no Value = 0
i = Readint();//Zero based zone number to share connectivity list with (-1 = no sharing). Value = -1
//for (int it=0; it<varnum*2; it++)
//{
// d = Readdouble();//Min and Max value
//}
//从120h开始
while (1)
{
f = Readfloat();//Zone marker Value = 299.0
}
fclose(fp);
}
void CTecplotRW::ReadFEBin( const char* filename )
{
fp = fopen(filename, "rb");
assert(fp != NULL);
char str[80];
int l;
//char c;
int i;
float f;
double d;
ReadNchar(str, 8);//Version number//10 #!TDV102
i = Readint();//Integer value of 1.
ReadString(str, &l);//The TITLE.
i = Readint();//Number of variables (NumVar) in the datafile.
int varnum = i;
for (int it=0; it<varnum; it++)//Variable names
{
ReadString(str, &l);
}
f = Readfloat();//Zone marker. Value = 299.0
ReadString(str, &l);//Zone name.
i = Readint();//ParentZone: Zero-based zone number. Value = -1
/* ZoneType 0=ORDERED,1=FELINESEG,
2=FETRIANGLE,3=FEQUADRILATERAL,
4=FETETRAHEDRON,5=FEBRICK,
6=FEPOLYGON,7=FEPOLYHEDRON
*/
i = Readint();//ZoneType 0=ORDERED,2=FETRIANGLE. Value = 2
i = Readint();//DataPacking 0=Block, 1=Point. Value = 0
d = Readdouble();//Solution time.. Value = 0
i = Readint();//number of points
int np = i;
i = Readint();//number of elements
int ne = i;
//i = Readint();//KMax
//i = Readint();//0=No more Auxiliary name
i = Readint();//ICellDim,
i = Readint();//JCellDim,
i = Readint();//KCellDim(for future use;set to zero)
i = Readint();//0=No more Auxiliary name
f = Readfloat();//Geometry marker. Value = 357.0
f = Readfloat();//Zone marker Value = 299.0
for (int it=0; it<varnum; it++)
{
i = Readint();//Variable data format, 1=Float,2=Double,3=LongInt,4=ShortInt,5=Byte,6=Bit
}
i = Readint();//Has variable sharing 0 = no Value = 0
i = Readint();//Zero based zone number to share connectivity list with (-1 = no sharing). Value = -1
for (int ip=0; ip<np; ip++)
{
f = Readfloat();//x
}
for (int ip=0; ip<np; ip++)
{
f = Readfloat();//y
}
for (int ip=0; ip<np; ip++)
{
f = Readfloat();//z
}
for (int ie=0; ie<ne; ie++)
{
i = Readint();//1
i = Readint();//2
i = Readint();//3
}
fclose(fp);
}
void CTecplotRW::WritePLT10( const char* filename, float* T, int* mat, int L, int M, int N )
{
int varnum = 5;
fp = fopen(filename, "wb");
assert(fp != NULL);
WriteNchar("#!TDV102", 8);
Writeint(1);
WriteString("");//The TITLE.
Writeint(varnum);//Number of variables (NumVar) in the datafile.
WriteString("I");
WriteString("J");
WriteString("K");
WriteString("T");
WriteString("mat");
Writefloat(299.0);
WriteString("ZONE 001");//Zone name.
Writeint(-1);
Writeint(0);//Zone type: ordered
Writedouble(0.0);
Writefloat(0.0);
Writeint(L);
Writeint(M);
Writeint(N);
Writeint(0);
Writefloat(357.0);
Writefloat(299.0);
for (int it=0; it<varnum; it++)
{
Writeint(1);//Variable data format, 1=Float
}
Writeint(0);
Writeint(-1);
int i, j, k;
for(k=0; k<N; k++) for(j=0; j<M; j++) for(i=0; i<L; i++)
{
Writefloat(i);
}
for(k=0; k<N; k++) for(j=0; j<M; j++) for(i=0; i<L; i++)
{
Writefloat(j);
}
for(k=0; k<N; k++) for(j=0; j<M; j++) for(i=0; i<L; i++)
{
Writefloat(k);
}
for(k=0; k<N; k++) for(j=0; j<M; j++) for(i=0; i<L; i++)
{
int idx = i*M*N+j*N+k;
Writefloat(T[idx]);
}
for(k=0; k<N; k++) for(j=0; j<M; j++) for(i=0; i<L; i++)
{
int idx = i*M*N+j*N+k;
Writefloat(mat[idx]);
}
fclose(fp);
}
void CTecplotRW::Writechar( char t )
{
fwrite(&t, sizeof(char), 1, fp);
}
void CTecplotRW::Writeint( int t )
{
fwrite(&t, sizeof(int), 1, fp);
}
void CTecplotRW::Writeshort( short t )
{
fwrite(&t, sizeof(short), 1, fp);
}
void CTecplotRW::Writefloat(float t)
{
fwrite(&t, sizeof(float), 1, fp);
}
void CTecplotRW::Writedouble(double t)
{
fwrite(&t, sizeof(double), 1, fp);
}
void CTecplotRW::WriteNchar( char* chars, int length )
{
fwrite(chars, sizeof(char),
tem.rar_冷却水_冷却温度场_温度场
版权申诉
150 浏览量
2022-09-20
20:49:05
上传
评论
收藏 5KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+