Commit d192f272 authored by DeAn Wei's avatar DeAn Wei
Browse files

1. parse list tecplot data

2. add auxiliary data in avraging lines.
parent 3c596330
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ typedef struct {
}Variable_t;

typedef struct {
    string                  T;
    string                  T, F;
    int                     i,j,k;
    double                  solutionTime;
    vector<string>          variables;
@@ -133,6 +133,10 @@ typedef struct {
} Table_t;

typedef struct {
    string                  T, F;
    int                     i,j,k;
    double                  solutionTime;
    map<string, string>     aux;
    vector<string>          variables;
    vector<vector<double> > data;
}LineList_t;
+2 −0
Original line number Diff line number Diff line
@@ -56,5 +56,7 @@ void SpecifyEquations_PLTDATA(InArgs_t *inArgs);
void SpecifyEquations(Table_t &table);
void FormatVector(real8 vec[3], const char *msg);

void InitList(LineList_t &list);
void InitTable(Table_t &table);

#endif
+59 −2
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@ void AverageLines(InArgs_t *inArgs)

    bool        calTau = 0;
    LineList_t  list;
    Curve_t     curve;
    InitList(list);

    Curve_t     curve;
    vector<int>         varID;
    vector<real8>       seq;
    vector<Table_t>     tables(inArgs->inpFiles.size());
@@ -109,10 +110,14 @@ void AverageLines(InArgs_t *inArgs)
    vector<real8>   weightList(inArgs->inpFiles.size());
    real8   totalWeight = 0.0;       
    int     firstReadFile = -1;        
    Table_t auxTable;
    InitTable(auxTable);

    for(i=0; i<inArgs->inpFiles.size(); i++){
        readState = ReadTecplotNormalData(inArgs->inpFiles[i], tables[i], secLine);
        if(!readState){
            weightList[i] = 0.0;
            Fatal("can not read file %s", inArgs->inpFiles[i].c_str());
            continue;
        }else{
            if(firstReadFile < 0){
@@ -180,11 +185,38 @@ void AverageLines(InArgs_t *inArgs)
            min = tables[i].data[0][colX];
            max = tables[i].data[tables[i].data.size()-1][colX];
            firstFile = 0;

            if(!tables[i].aux.empty()){
                auxTable.data.resize(inArgs->inpFiles.size());
                auxTable.i = (int)inArgs->inpFiles.size();
                printf("Auxiliary variables: ");

                auxTable.variables.push_back("file");
                auxTable.data[0].push_back((real8)i);

                for(const auto &pair : tables[i].aux){
                    printf("%s ", pair.first.c_str());
                    auxTable.variables.push_back(pair.first);
                    auxTable.data[0].push_back(atof(pair.second.c_str()));
                }
                printf("\n");
            }

        }else{
            if(min < tables[i].data[0][colX]) min = tables[i].data[0][colX];
            if(max > tables[i].data[tables[i].data.size()-1][colX]){
                max = tables[i].data[tables[i].data.size()-1][colX];
            }

            if(auxTable.variables.size()>0){
                auxTable.data[i].resize(auxTable.variables.size());
                j = 0;
                auxTable.data[i][j++] = (real8)i;

                for(const auto &pair : tables[i].aux){
                    auxTable.data[i][j++] = (atof(pair.second.c_str()));
                }
            }
        }

        printf("File %s(%d): Range is [%f,%f], %d points\n", 
@@ -297,6 +329,31 @@ void AverageLines(InArgs_t *inArgs)
        }
    }

    if(auxTable.data.size() > 0){

        real8 aveAuxVal;
        char  val[50];
        for(i=1; i<auxTable.variables.size(); i++){
            if(auxTable.variables[i] ==  weightCoeff)continue;
            
            aveAuxVal = 0.0;
            for(j=0; j<auxTable.data.size(); j++){
                aveAuxVal += (auxTable.data[j][i]*weightList[j]/totalWeight);
            }
            
            snprintf(val, sizeof(val), "%e", aveAuxVal);
            auxTable.aux[std::string("Ave_")+auxTable.variables[i]] = val;
            list.aux[std::string("Ave_")+auxTable.variables[i]] = val;
        }

        if(inArgs->outFiles.size() < 2){
//            WriteTecplotNormalData(auxTable, std::string("auxTable.plt"), 10);
        }else{
            WriteTecplotNormalData(auxTable,  inArgs->outFiles[1], 10);
        }
    }

    list.i = ((int)list.data[0].size());
    WriteTecplotNormalData(list, inArgs->outFiles[0], 10);

    return;
+6 −12
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
#include "DDD.h"
#include "MD.h"

#define     MAXLINELENGTH 512
#define     MAXLINELENGTH 1024

using namespace std;
const char* strstri(const char* str, const char* subStr)
@@ -43,21 +43,13 @@ int ReadTecplotNormalData(string &file, Table_t &table, string &secLine)
//        printf("Reading tecplot file %s ...\n", file.c_str());
    }

    InitTable(table);
    secLine = "";
    vector<string>().swap(table.variables);
    vector<vector<real8> >().swap(table.data);
    table.aux.clear();
    table.i=1;
    table.j=1;
    table.k=1;
    table.solutionTime = -1;
    table.T="";

    std::regex equation("\\S+\\s*=\\s*[-\"\'+.a-zA-Z0-9]+");
    std::regex aux_equation("AUXDATA\\s+\\S+\\s*=\\s*[-\"\'+.a-zA-Z0-9]+");
    std::regex equation("\\S+\\s*=\\s*[-\"\'+.a-zA-Z0-9]+");
    std::regex var_name("[a-zA-Z]+[a-zA-z0-9_\\-]*");
    std::regex value("[a-zA-z0-9_\\.\\+\\-]+");

    std::smatch equation_match;
    std::smatch v_match;

@@ -114,6 +106,8 @@ int ReadTecplotNormalData(string &file, Table_t &table, string &secLine)
                        if(std::regex_search(buff1, v_match, value)){
                            if(buff2 == "T"){
                                table.T = v_match[0].str(); 
                            }else if (buff2 == "F"){
                                table.F = v_match[0].str(); 
                            }else if (buff2 == "I" || buff2 == "i"){
                                table.i = atoi(v_match[0].str().c_str());
                            }else if (buff2 == "J" || buff2 == "j"){
@@ -185,7 +179,7 @@ int ReadTecplotNormalData(string &file, Table_t &table, string &secLine)
    fclose(fp);

    if((int)table.data.size() != table.i*table.j*table.k)table.i = (int)table.data.size();
//    printf("Finish reading input file %s, %d points\n", file.c_str(), currSize+1);    
    printf("Finish reading input file %s, %d points\n", file.c_str(), currSize+1);    
    return 1;            
}

+25 −0
Original line number Diff line number Diff line
@@ -379,6 +379,31 @@ void FormatVector(real8 vec[3], const char *msg){
	printf("{%.15f,%.15f,%.15f}\n", vec[0], vec[1], vec[2]);
}

void InitList(LineList_t &list){
    vector<string>().swap(list.variables);
    vector<vector<real8> >().swap(list.data);
    list.aux.clear();
    list.i=1;
    list.j=1;
    list.k=1;
    list.solutionTime = -1;
    list.T="";
    list.F = "Point";
    return;
}

void InitTable(Table_t &table){
    vector<string>().swap(table.variables);
    vector<vector<real8> >().swap(table.data);
    table.aux.clear();
    table.i=1;
    table.j=1;
    table.k=1;
    table.solutionTime = -1;
    table.T="";
    table.F = "Point";
    return;
}

bool FindLinearPart(real8 (*line)[3], const int nums, int range[2])
{
Loading